Skip to content

Commit

Permalink
Merge branch 'for-4.14-fixes' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/git/tj/percpu

Pull percpu fixes from Tejun Heo:
 "Rather important fixes this time.

   - The new percpu area allocator had a subtle bug in how it iterates
     the memory regions and could skip viable areas, which led to
     allocation failures for module static percpu variables. Dennis
     fixed the bug and another non-critical one in stat calculation.

   - Mark noticed that the generic implementations of percpu local
     atomic reads aren't properly protected against irqs and there's a
     (slim) chance for split reads on some 32bit systems. Generic
     implementations are updated to disable irq when read size is larger
     than ulong size. This may have made some 32bit archs which can do
     atomic local 64bit accesses generate sub-optimal code. We need to
     find them out and implement arch-specific overrides"

* 'for-4.14-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu:
  percpu: fix iteration to prevent skipping over block
  percpu: fix starting offset for chunk statistics traversal
  percpu: make this_cpu_generic_read() atomic w.r.t. interrupts
  • Loading branch information
torvalds committed Oct 3, 2017
2 parents c1de159 + 1fa4df3 commit ff93026
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
24 changes: 22 additions & 2 deletions include/asm-generic/percpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,35 @@ do { \
(__ret); \
})

#define this_cpu_generic_read(pcp) \
#define __this_cpu_generic_read_nopreempt(pcp) \
({ \
typeof(pcp) __ret; \
preempt_disable_notrace(); \
__ret = raw_cpu_generic_read(pcp); \
__ret = READ_ONCE(*raw_cpu_ptr(&(pcp))); \
preempt_enable_notrace(); \
__ret; \
})

#define __this_cpu_generic_read_noirq(pcp) \
({ \
typeof(pcp) __ret; \
unsigned long __flags; \
raw_local_irq_save(__flags); \
__ret = raw_cpu_generic_read(pcp); \
raw_local_irq_restore(__flags); \
__ret; \
})

#define this_cpu_generic_read(pcp) \
({ \
typeof(pcp) __ret; \
if (__native_word(pcp)) \
__ret = __this_cpu_generic_read_nopreempt(pcp); \
else \
__ret = __this_cpu_generic_read_noirq(pcp); \
__ret; \
})

#define this_cpu_generic_to_op(pcp, val, op) \
do { \
unsigned long __flags; \
Expand Down
2 changes: 1 addition & 1 deletion mm/percpu-stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void chunk_map_stats(struct seq_file *m, struct pcpu_chunk *chunk,
last_alloc + 1 : 0;

as_len = 0;
start = chunk->start_offset;
start = chunk->start_offset / PCPU_MIN_ALLOC_SIZE;

/*
* If a bit is set in the allocation map, the bound_map identifies
Expand Down
4 changes: 4 additions & 0 deletions mm/percpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ static void pcpu_next_md_free_region(struct pcpu_chunk *chunk, int *bit_off,
block->contig_hint_start);
return;
}
/* reset to satisfy the second predicate above */
block_off = 0;

*bits = block->right_free;
*bit_off = (i + 1) * PCPU_BITMAP_BLOCK_BITS - block->right_free;
Expand Down Expand Up @@ -407,6 +409,8 @@ static void pcpu_next_fit_region(struct pcpu_chunk *chunk, int alloc_bits,
*bit_off = pcpu_block_off_to_off(i, block->first_free);
return;
}
/* reset to satisfy the second predicate above */
block_off = 0;

*bit_off = ALIGN(PCPU_BITMAP_BLOCK_BITS - block->right_free,
align);
Expand Down

0 comments on commit ff93026

Please sign in to comment.