Merge branch 'for-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 13 Dec 2016 20:34:47 +0000 (12:34 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 13 Dec 2016 20:34:47 +0000 (12:34 -0800)
Pull percpu update from Tejun Heo:
 "This includes just one patch to reject non-power-of-2 alignments and
  trigger warning. Interestingly, this actually caught a bug in XEN
  ARM64"

* 'for-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu:
  percpu: ensure the requested alignment is power of two

1  2 
include/linux/kernel.h
mm/percpu.c

diff --combined include/linux/kernel.h
  
  #define REPEAT_BYTE(x)        ((~0ul / 0xff) * (x))
  
+ /* @a is a power of 2 value */
  #define ALIGN(x, a)           __ALIGN_KERNEL((x), (a))
  #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask))
  #define PTR_ALIGN(p, a)               ((typeof(p))ALIGN((unsigned long)(p), (a)))
  #define IS_ALIGNED(x, a)              (((x) & ((typeof(x))(a) - 1)) == 0)
  
 +/* generic data direction definitions */
 +#define READ                  0
 +#define WRITE                 1
 +
  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
  
  #define u64_to_user_ptr(x) (          \
diff --combined mm/percpu.c
@@@ -886,7 -886,8 +886,8 @@@ static void __percpu *pcpu_alloc(size_
  
        size = ALIGN(size, 2);
  
-       if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) {
+       if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE ||
+                    !is_power_of_2(align))) {
                WARN(true, "illegal size (%zu) or align (%zu) for percpu allocation\n",
                     size, align);
                return NULL;
@@@ -2093,8 -2094,6 +2094,8 @@@ int __init pcpu_page_first_chunk(size_
        size_t pages_size;
        struct page **pages;
        int unit, i, j, rc;
 +      int upa;
 +      int nr_g0_units;
  
        snprintf(psize_str, sizeof(psize_str), "%luK", PAGE_SIZE >> 10);
  
        if (IS_ERR(ai))
                return PTR_ERR(ai);
        BUG_ON(ai->nr_groups != 1);
 -      BUG_ON(ai->groups[0].nr_units != num_possible_cpus());
 +      upa = ai->alloc_size/ai->unit_size;
 +      nr_g0_units = roundup(num_possible_cpus(), upa);
 +      if (unlikely(WARN_ON(ai->groups[0].nr_units != nr_g0_units))) {
 +              pcpu_free_alloc_info(ai);
 +              return -EINVAL;
 +      }
  
        unit_pages = ai->unit_size >> PAGE_SHIFT;
  
  
        /* allocate pages */
        j = 0;
 -      for (unit = 0; unit < num_possible_cpus(); unit++)
 +      for (unit = 0; unit < num_possible_cpus(); unit++) {
 +              unsigned int cpu = ai->groups[0].cpu_map[unit];
                for (i = 0; i < unit_pages; i++) {
 -                      unsigned int cpu = ai->groups[0].cpu_map[unit];
                        void *ptr;
  
                        ptr = alloc_fn(cpu, PAGE_SIZE, PAGE_SIZE);
                        if (!ptr) {
                                pr_warn("failed to allocate %s page for cpu%u\n",
 -                                      psize_str, cpu);
 +                                              psize_str, cpu);
                                goto enomem;
                        }
                        /* kmemleak tracks the percpu allocations separately */
                        kmemleak_free(ptr);
                        pages[j++] = virt_to_page(ptr);
                }
 +      }
  
        /* allocate vm area, map the pages and copy static data */
        vm.flags = VM_ALLOC;