[PATCH] more for_each_cpu() conversions
When we stop allocating percpu memory for not-possible CPUs we must not touch the percpu data for not-possible CPUs at all. The correct way of doing this is to test cpu_possible() or to use for_each_cpu(). This patch is a kernel-wide sweep of all instances of NR_CPUS. I found very few instances of this bug, if any. But the patch converts lots of open-coded test to use the preferred helper macros. Cc: Mikael Starvik <starvik@axis.com> Cc: David Howells <dhowells@redhat.com> Acked-by: Kyle McMartin <kyle@parisc-linux.org> Cc: Anton Blanchard <anton@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: William Lee Irwin III <wli@holomorphy.com> Cc: Andi Kleen <ak@muc.de> Cc: Christian Zankel <chris@zankel.net> Cc: Philippe Elie <phil.el@wanadoo.fr> Cc: Nathan Scott <nathans@sgi.com> Cc: Jens Axboe <axboe@suse.de> Cc: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
committed by
Linus Torvalds
parent
63872f87a1
commit
394e3902c5
@@ -231,9 +231,8 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NR_CPUS; i++)
|
||||
if (cpu_online(i))
|
||||
mm->context[i] = 0;
|
||||
for_each_online_cpu(i)
|
||||
mm->context[i] = 0;
|
||||
if (tsk != current)
|
||||
task_thread_info(tsk)->pcb.ptbr
|
||||
= ((unsigned long)mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
|
||||
|
||||
@@ -27,8 +27,8 @@ static inline cpumask_t node_to_cpumask(int node)
|
||||
cpumask_t node_cpu_mask = CPU_MASK_NONE;
|
||||
int cpu;
|
||||
|
||||
for(cpu = 0; cpu < NR_CPUS; cpu++) {
|
||||
if (cpu_online(cpu) && (cpu_to_node(cpu) == node))
|
||||
for_each_online_cpu(cpu) {
|
||||
if (cpu_to_node(cpu) == node)
|
||||
cpu_set(cpu, node_cpu_mask);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,9 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
|
||||
#define percpu_modcopy(pcpudst, src, size) \
|
||||
do { \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < NR_CPUS; __i++) \
|
||||
if (cpu_possible(__i)) \
|
||||
memcpy((pcpudst)+__per_cpu_offset[__i], \
|
||||
(src), (size)); \
|
||||
for_each_cpu(__i) \
|
||||
memcpy((pcpudst)+__per_cpu_offset[__i], \
|
||||
(src), (size)); \
|
||||
} while (0)
|
||||
#else /* ! SMP */
|
||||
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
#define percpu_modcopy(pcpudst, src, size) \
|
||||
do { \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < NR_CPUS; __i++) \
|
||||
if (cpu_possible(__i)) \
|
||||
memcpy((pcpudst)+__per_cpu_offset(__i), \
|
||||
(src), (size)); \
|
||||
for_each_cpu(__i) \
|
||||
memcpy((pcpudst)+__per_cpu_offset(__i), \
|
||||
(src), (size)); \
|
||||
} while (0)
|
||||
|
||||
extern void setup_per_cpu_areas(void);
|
||||
|
||||
@@ -46,10 +46,9 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
|
||||
#define percpu_modcopy(pcpudst, src, size) \
|
||||
do { \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < NR_CPUS; __i++) \
|
||||
if (cpu_possible(__i)) \
|
||||
memcpy((pcpudst)+__per_cpu_offset[__i], \
|
||||
(src), (size)); \
|
||||
for_each_cpu(__i) \
|
||||
memcpy((pcpudst)+__per_cpu_offset[__i], \
|
||||
(src), (size)); \
|
||||
} while (0)
|
||||
|
||||
#else /* ! SMP */
|
||||
|
||||
@@ -26,10 +26,9 @@ register unsigned long __local_per_cpu_offset asm("g5");
|
||||
#define percpu_modcopy(pcpudst, src, size) \
|
||||
do { \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < NR_CPUS; __i++) \
|
||||
if (cpu_possible(__i)) \
|
||||
memcpy((pcpudst)+__per_cpu_offset(__i), \
|
||||
(src), (size)); \
|
||||
for_each_cpu(__i) \
|
||||
memcpy((pcpudst)+__per_cpu_offset(__i), \
|
||||
(src), (size)); \
|
||||
} while (0)
|
||||
#else /* ! SMP */
|
||||
|
||||
|
||||
@@ -26,10 +26,9 @@
|
||||
#define percpu_modcopy(pcpudst, src, size) \
|
||||
do { \
|
||||
unsigned int __i; \
|
||||
for (__i = 0; __i < NR_CPUS; __i++) \
|
||||
if (cpu_possible(__i)) \
|
||||
memcpy((pcpudst)+__per_cpu_offset(__i), \
|
||||
(src), (size)); \
|
||||
for_each_cpu(__i) \
|
||||
memcpy((pcpudst)+__per_cpu_offset(__i), \
|
||||
(src), (size)); \
|
||||
} while (0)
|
||||
|
||||
extern void setup_per_cpu_areas(void);
|
||||
|
||||
+4
-10
@@ -149,22 +149,16 @@ struct disk_attribute {
|
||||
({ \
|
||||
typeof(gendiskp->dkstats->field) res = 0; \
|
||||
int i; \
|
||||
for (i=0; i < NR_CPUS; i++) { \
|
||||
if (!cpu_possible(i)) \
|
||||
continue; \
|
||||
for_each_cpu(i) \
|
||||
res += per_cpu_ptr(gendiskp->dkstats, i)->field; \
|
||||
} \
|
||||
res; \
|
||||
})
|
||||
|
||||
static inline void disk_stat_set_all(struct gendisk *gendiskp, int value) {
|
||||
int i;
|
||||
for (i=0; i < NR_CPUS; i++) {
|
||||
if (cpu_possible(i)) {
|
||||
memset(per_cpu_ptr(gendiskp->dkstats, i), value,
|
||||
sizeof (struct disk_stats));
|
||||
}
|
||||
}
|
||||
for_each_cpu(i)
|
||||
memset(per_cpu_ptr(gendiskp->dkstats, i), value,
|
||||
sizeof (struct disk_stats));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user