All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Oleg Drokin <green@linuxhacker.ru>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 05/16] staging/lustre: fix up obsolete cpu function usage.
Date: Tue, 03 Mar 2015 13:42:29 +1030	[thread overview]
Message-ID: <87oaoakc4i.fsf@rustcorp.com.au> (raw)
In-Reply-To: <2CED6DE1-CF72-42D7-AEB6-247E4FB20539@linuxhacker.ru>

Oleg Drokin <green@linuxhacker.ru> writes:
> So there are 7 more users like this outside of Lustre in the kernel then, I'll try for a patch:

I can squash these if you want...

> ./drivers/scsi/hpsa.c:	for (i = 0; i < num_online_cpus(); i++) { -- this one seems to be just opencoding for_each_cpu, though

Yeah, that's easy to fix.

> ./arch/um/kernel/smp.c:	for (i = 0; i < num_online_cpus(); i++) { -- I wonder if UML is able to have discontiguous cpus up?
>
> ./arch/sh/include/asm/mmu_context.h:	for (i = 0; i < num_online_cpus(); i++) -- this seems to be the same bug we have.
>
> ./arch/sh/kernel/smp.c:		for (i = 0; i < num_online_cpus(); i++) -- this and the two below it too
> ./arch/sh/kernel/smp.c:		for (i = 0; i < num_online_cpus(); i++)
> ./arch/sh/kernel/smp.c:		for (i = 0; i < num_online_cpus(); i++)
>
> ./arch/m32r/kernel/smpboot.c:	for (cpu_id = 0 ; cpu_id < num_online_cpus() ; cpu_id++) -- this also is buggy, though it's just an info print.

These are arch code, and while they should be fixed (because people may
copy them), those archs probably don't support hotplug cpus.

Thanks!
Rusty.

Subject: Fix weird uses of num_online_cpus().

This may be OK in archs with contiguous CPU numbers and without
hotplug CPUs, but it sets a terrible example.

And open-coding it like drivers/scsi/hpsa.c is just weird.

BTRFS has a weird comparison with num_online_cpus() too, but since
BTRFS just screwed up my test machines' root partition, I'm not
touching it :)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reported-by: Oleg Drokin <green@linuxhacker.ru>

diff --git a/arch/m32r/kernel/smpboot.c b/arch/m32r/kernel/smpboot.c
index bb21f4f63170..a468467542f4 100644
--- a/arch/m32r/kernel/smpboot.c
+++ b/arch/m32r/kernel/smpboot.c
@@ -376,7 +376,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
 	if (!cpumask_equal(&cpu_callin_map, cpu_online_mask))
 		BUG();
 
-	for (cpu_id = 0 ; cpu_id < num_online_cpus() ; cpu_id++)
+	for_each_online_cpu(cpu_id)
 		show_cpu_info(cpu_id);
 
 	/*
diff --git a/arch/sh/include/asm/mmu_context.h b/arch/sh/include/asm/mmu_context.h
index b9d9489a5012..9f417feaf6e8 100644
--- a/arch/sh/include/asm/mmu_context.h
+++ b/arch/sh/include/asm/mmu_context.h
@@ -99,7 +99,7 @@ static inline int init_new_context(struct task_struct *tsk,
 {
 	int i;
 
-	for (i = 0; i < num_online_cpus(); i++)
+	for_each_online_cpu(i)
 		cpu_context(i, mm) = NO_CONTEXT;
 
 	return 0;
diff --git a/arch/sh/kernel/smp.c b/arch/sh/kernel/smp.c
index fc5acfc93c92..de6be008fc01 100644
--- a/arch/sh/kernel/smp.c
+++ b/arch/sh/kernel/smp.c
@@ -363,7 +363,7 @@ void flush_tlb_mm(struct mm_struct *mm)
 		smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
 	} else {
 		int i;
-		for (i = 0; i < num_online_cpus(); i++)
+		for_each_online_cpu(i)
 			if (smp_processor_id() != i)
 				cpu_context(i, mm) = 0;
 	}
@@ -400,7 +400,7 @@ void flush_tlb_range(struct vm_area_struct *vma,
 		smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
 	} else {
 		int i;
-		for (i = 0; i < num_online_cpus(); i++)
+		for_each_online_cpu(i)
 			if (smp_processor_id() != i)
 				cpu_context(i, mm) = 0;
 	}
@@ -443,7 +443,7 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
 		smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
 	} else {
 		int i;
-		for (i = 0; i < num_online_cpus(); i++)
+		for_each_online_cpu(i)
 			if (smp_processor_id() != i)
 				cpu_context(i, vma->vm_mm) = 0;
 	}
diff --git a/arch/um/kernel/smp.c b/arch/um/kernel/smp.c
index 74077892b34a..525c3657a6af 100644
--- a/arch/um/kernel/smp.c
+++ b/arch/um/kernel/smp.c
@@ -45,7 +45,7 @@ void smp_send_stop(void)
 	int i;
 
 	printk(KERN_INFO "Stopping all CPUs...");
-	for (i = 0; i < num_online_cpus(); i++) {
+	for_each_online_cpu(i) {
 		if (i == current_thread->cpu)
 			continue;
 		os_write_file(cpu_data[i].ipi_pipe[1], "S", 1);
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index a1cfbd3dda47..8eab107b53fb 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -6632,14 +6632,12 @@ static void fail_all_outstanding_cmds(struct ctlr_info *h)
 
 static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value)
 {
-	int i, cpu;
+	int cpu;
 
-	cpu = cpumask_first(cpu_online_mask);
-	for (i = 0; i < num_online_cpus(); i++) {
+	for_each_online_cpu(cpu) {
 		u32 *lockup_detected;
 		lockup_detected = per_cpu_ptr(h->lockup_detected, cpu);
 		*lockup_detected = value;
-		cpu = cpumask_next(cpu, cpu_online_mask);
 	}
 	wmb(); /* be sure the per-cpu variables are out to memory */
 }

  reply	other threads:[~2015-03-03  3:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 11:35 [PATCH 01/16] CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS: set if CPUMASK_OFFSTACK Rusty Russell
2015-03-02 11:35 ` [PATCH 02/16] cpumask: fix cpu-hotplug documentation Rusty Russell
2015-03-02 11:35 ` [PATCH 03/16] ia64: Use for_each_cpu_and() and cpumask_any_and() instead of temp var Rusty Russell
2015-03-02 11:47   ` Rusty Russell
2015-03-02 11:35 ` [PATCH 04/16] drivers: fix up obsolete cpu function usage Rusty Russell
2015-03-02 22:23   ` Rafael J. Wysocki
2015-03-02 11:35 ` [PATCH 05/16] staging/lustre: " Rusty Russell
2015-03-02 17:50   ` Oleg Drokin
2015-03-02 23:39     ` Rusty Russell
2015-03-03  1:16       ` Oleg Drokin
2015-03-03  3:12         ` Rusty Russell [this message]
2015-03-02 11:35 ` [PATCH 06/16] ia64: " Rusty Russell
2015-03-02 11:47   ` Rusty Russell
2015-05-26 20:45   ` Tony Luck
2015-05-26 20:45     ` Tony Luck
2015-05-27  1:18     ` Rusty Russell
2015-05-27  1:30       ` Rusty Russell
2015-05-27 17:37       ` Tony Luck
2015-05-27 17:37         ` Tony Luck
2015-05-28  3:44         ` Rusty Russell
2015-05-28  3:56           ` Rusty Russell
2015-03-02 11:35 ` [uml-devel] [PATCH 07/16] um: " Rusty Russell
2015-03-02 11:35   ` Rusty Russell
2015-03-02 11:35 ` [PATCH 08/16] x86: " Rusty Russell
2015-03-02 13:36   ` [tip:x86/cleanups] x86: Fix up obsolete __cpu_set() " tip-bot for Rusty Russell
2015-03-02 11:35 ` [PATCH 09/16] mips: fix up obsolete cpu " Rusty Russell
2015-03-02 12:34 ` [PATCH 01/16] CONFIG_DISABLE_OBSOLETE_CPUMASK_FUNCTIONS: set if CPUMASK_OFFSTACK Paul Bolle
2015-03-02 23:40   ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oaoakc4i.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=green@linuxhacker.ru \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.