Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / mm / percpu.c
index c7206d0..63e24fb 100644 (file)
@@ -473,9 +473,11 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int size, int align)
                 * uncommon for percpu allocations.
                 */
                if (head && (head < sizeof(int) || !(p[-1] & 1))) {
+                       *p = off += head;
                        if (p[-1] & 1)
                                chunk->free_size -= head;
-                       *p = off += head;
+                       else
+                               max_contig = max(*p - p[-1], max_contig);
                        this_size -= head;
                        head = 0;
                }
@@ -713,11 +715,14 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved)
 
        /*
         * We want the lowest bit of offset available for in-use/free
-        * indicator.
+        * indicator, so force >= 16bit alignment and make size even.
         */
        if (unlikely(align < 2))
                align = 2;
 
+       if (unlikely(size & 1))
+               size++;
+
        if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) {
                WARN(true, "illegal size (%zu) or align (%zu) for "
                     "percpu allocation\n", size, align);