From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Qais Yousef <qais.yousef@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Jiri Kosina <jkosina@suse.cz>,
Nicholas Piggin <npiggin@gmail.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Ingo Molnar <mingo@kernel.org>,
Eiichi Tsukata <devel@etsukata.com>,
Zhenzhong Duan <zhenzhong.duan@oracle.com>,
Nadav Amit <namit@vmware.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Tony Luck <tony.luck@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 01/14] smp: Create a new function to shutdown nonboot cpus
Date: Tue, 21 Jan 2020 18:09:30 +0000 [thread overview]
Message-ID: <20200121180930.GJ25745@shell.armlinux.org.uk> (raw)
In-Reply-To: <20200121174751.5opyyjwxfnwdgcev@e107158-lin.cambridge.arm.com>
On Tue, Jan 21, 2020 at 05:47:52PM +0000, Qais Yousef wrote:
> On 01/21/20 17:03, Russell King - ARM Linux admin wrote:
> > On Mon, Nov 25, 2019 at 11:27:41AM +0000, Qais Yousef wrote:
> > > +void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
> > > +{
> > > + unsigned int cpu;
> > > +
> > > + if (!cpu_online(primary_cpu)) {
> > > + pr_info("Attempting to shutdodwn nonboot cpus while boot cpu is offline!\n");
> > > + cpu_online(primary_cpu);
>
> Eh, that should be cpu_up(primary_cpu)!
>
> Which I have to say I'm not if is the right thing to do.
> migrate_to_reboot_cpu() picks the first online cpu if reboot_cpu (assumed 0) is
> offline
>
> migrate_to_reboot_cpu():
> 225 /* Make certain the cpu I'm about to reboot on is online */
> 226 if (!cpu_online(cpu))
> 227 cpu = cpumask_first(cpu_online_mask);
>
> > > + }
> > > +
> > > + for_each_present_cpu(cpu) {
> > > + if (cpu = primary_cpu)
> > > + continue;
> > > + if (cpu_online(cpu))
> > > + cpu_down(cpu);
> > > + }
> >
> > How does this avoid racing with userspace attempting to restart CPUs
> > that have already been taken down by this function?
>
> This is meant to be called from machine_shutdown() only.
>
> But you've got a point.
>
> The previous logic that used disable_nonboot_cpus(), which in turn called
> freeze_secondary_cpus() didn't hold hotplug lock. So I assumed the higher level
> logic of machine_shutdown() ensures that hotplug lock is held to synchronize
> with potential other hotplug operations.
freeze_secondary_cpus() takes the CPU maps lock while it takes CPUs
down, and then disables cpu hotplug by incrementing
cpu_hotplug_disabled. Incrementing that prevents cpu_up() and
cpu_down() being used, thereby preventing userspace from changing the
online state of any CPU in the system.
> But I can see now that it doesn't.
>
> With this series that migrates users to use device_{online,offline}, holding
> the lock_device_hotplug() should protect against such races.
>
> Worth noting that this an existing problem in the code and not something
> I introduced, of course it makes sense to fix it properly as part of this
> series.
>
> I'm not sure how the other archs deal with this TBH.
>
> Thanks for having a look!
>
> Cheers
>
> --
> Qais Yousef
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
WARNING: multiple messages have this Message-ID (diff)
From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Qais Yousef <qais.yousef@arm.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Catalin Marinas <catalin.marinas@arm.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Tony Luck <tony.luck@intel.com>,
"Peter Zijlstra \(Intel\)" <peterz@infradead.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Zhenzhong Duan <zhenzhong.duan@oracle.com>,
Nicholas Piggin <npiggin@gmail.com>,
linux-kernel@vger.kernel.org, Eiichi Tsukata <devel@etsukata.com>,
Nadav Amit <namit@vmware.com>, Jiri Kosina <jkosina@suse.cz>,
linux-ia64@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
Will Deacon <will@kernel.org>, Ingo Molnar <mingo@kernel.org>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 01/14] smp: Create a new function to shutdown nonboot cpus
Date: Tue, 21 Jan 2020 18:09:30 +0000 [thread overview]
Message-ID: <20200121180930.GJ25745@shell.armlinux.org.uk> (raw)
In-Reply-To: <20200121174751.5opyyjwxfnwdgcev@e107158-lin.cambridge.arm.com>
On Tue, Jan 21, 2020 at 05:47:52PM +0000, Qais Yousef wrote:
> On 01/21/20 17:03, Russell King - ARM Linux admin wrote:
> > On Mon, Nov 25, 2019 at 11:27:41AM +0000, Qais Yousef wrote:
> > > +void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
> > > +{
> > > + unsigned int cpu;
> > > +
> > > + if (!cpu_online(primary_cpu)) {
> > > + pr_info("Attempting to shutdodwn nonboot cpus while boot cpu is offline!\n");
> > > + cpu_online(primary_cpu);
>
> Eh, that should be cpu_up(primary_cpu)!
>
> Which I have to say I'm not if is the right thing to do.
> migrate_to_reboot_cpu() picks the first online cpu if reboot_cpu (assumed 0) is
> offline
>
> migrate_to_reboot_cpu():
> 225 /* Make certain the cpu I'm about to reboot on is online */
> 226 if (!cpu_online(cpu))
> 227 cpu = cpumask_first(cpu_online_mask);
>
> > > + }
> > > +
> > > + for_each_present_cpu(cpu) {
> > > + if (cpu == primary_cpu)
> > > + continue;
> > > + if (cpu_online(cpu))
> > > + cpu_down(cpu);
> > > + }
> >
> > How does this avoid racing with userspace attempting to restart CPUs
> > that have already been taken down by this function?
>
> This is meant to be called from machine_shutdown() only.
>
> But you've got a point.
>
> The previous logic that used disable_nonboot_cpus(), which in turn called
> freeze_secondary_cpus() didn't hold hotplug lock. So I assumed the higher level
> logic of machine_shutdown() ensures that hotplug lock is held to synchronize
> with potential other hotplug operations.
freeze_secondary_cpus() takes the CPU maps lock while it takes CPUs
down, and then disables cpu hotplug by incrementing
cpu_hotplug_disabled. Incrementing that prevents cpu_up() and
cpu_down() being used, thereby preventing userspace from changing the
online state of any CPU in the system.
> But I can see now that it doesn't.
>
> With this series that migrates users to use device_{online,offline}, holding
> the lock_device_hotplug() should protect against such races.
>
> Worth noting that this an existing problem in the code and not something
> I introduced, of course it makes sense to fix it properly as part of this
> series.
>
> I'm not sure how the other archs deal with this TBH.
>
> Thanks for having a look!
>
> Cheers
>
> --
> Qais Yousef
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Qais Yousef <qais.yousef@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Jiri Kosina <jkosina@suse.cz>,
Nicholas Piggin <npiggin@gmail.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Ingo Molnar <mingo@kernel.org>,
Eiichi Tsukata <devel@etsukata.com>,
Zhenzhong Duan <zhenzhong.duan@oracle.com>,
Nadav Amit <namit@vmware.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Tony Luck <tony.luck@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 01/14] smp: Create a new function to shutdown nonboot cpus
Date: Tue, 21 Jan 2020 18:09:30 +0000 [thread overview]
Message-ID: <20200121180930.GJ25745@shell.armlinux.org.uk> (raw)
In-Reply-To: <20200121174751.5opyyjwxfnwdgcev@e107158-lin.cambridge.arm.com>
On Tue, Jan 21, 2020 at 05:47:52PM +0000, Qais Yousef wrote:
> On 01/21/20 17:03, Russell King - ARM Linux admin wrote:
> > On Mon, Nov 25, 2019 at 11:27:41AM +0000, Qais Yousef wrote:
> > > +void smp_shutdown_nonboot_cpus(unsigned int primary_cpu)
> > > +{
> > > + unsigned int cpu;
> > > +
> > > + if (!cpu_online(primary_cpu)) {
> > > + pr_info("Attempting to shutdodwn nonboot cpus while boot cpu is offline!\n");
> > > + cpu_online(primary_cpu);
>
> Eh, that should be cpu_up(primary_cpu)!
>
> Which I have to say I'm not if is the right thing to do.
> migrate_to_reboot_cpu() picks the first online cpu if reboot_cpu (assumed 0) is
> offline
>
> migrate_to_reboot_cpu():
> 225 /* Make certain the cpu I'm about to reboot on is online */
> 226 if (!cpu_online(cpu))
> 227 cpu = cpumask_first(cpu_online_mask);
>
> > > + }
> > > +
> > > + for_each_present_cpu(cpu) {
> > > + if (cpu == primary_cpu)
> > > + continue;
> > > + if (cpu_online(cpu))
> > > + cpu_down(cpu);
> > > + }
> >
> > How does this avoid racing with userspace attempting to restart CPUs
> > that have already been taken down by this function?
>
> This is meant to be called from machine_shutdown() only.
>
> But you've got a point.
>
> The previous logic that used disable_nonboot_cpus(), which in turn called
> freeze_secondary_cpus() didn't hold hotplug lock. So I assumed the higher level
> logic of machine_shutdown() ensures that hotplug lock is held to synchronize
> with potential other hotplug operations.
freeze_secondary_cpus() takes the CPU maps lock while it takes CPUs
down, and then disables cpu hotplug by incrementing
cpu_hotplug_disabled. Incrementing that prevents cpu_up() and
cpu_down() being used, thereby preventing userspace from changing the
online state of any CPU in the system.
> But I can see now that it doesn't.
>
> With this series that migrates users to use device_{online,offline}, holding
> the lock_device_hotplug() should protect against such races.
>
> Worth noting that this an existing problem in the code and not something
> I introduced, of course it makes sense to fix it properly as part of this
> series.
>
> I'm not sure how the other archs deal with this TBH.
>
> Thanks for having a look!
>
> Cheers
>
> --
> Qais Yousef
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
next prev parent reply other threads:[~2020-01-21 18:09 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-25 11:27 [PATCH v2 00/14] Convert cpu_up/down to device_online/offline Qais Yousef
2019-11-25 11:27 ` [Xen-devel] " Qais Yousef
2019-11-25 11:27 ` [PATCH v2 01/14] smp: Create a new function to shutdown nonboot cpus Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2020-01-21 17:03 ` Russell King - ARM Linux admin
2020-01-21 17:03 ` Russell King - ARM Linux admin
2020-01-21 17:03 ` Russell King - ARM Linux admin
2020-01-21 17:47 ` Qais Yousef
2020-01-21 17:47 ` Qais Yousef
2020-01-21 17:47 ` Qais Yousef
2020-01-21 18:09 ` Russell King - ARM Linux admin [this message]
2020-01-21 18:09 ` Russell King - ARM Linux admin
2020-01-21 18:09 ` Russell King - ARM Linux admin
2020-01-22 10:32 ` Qais Yousef
2020-01-22 10:32 ` Qais Yousef
2020-01-22 10:32 ` Qais Yousef
2019-11-25 11:27 ` [PATCH v2 02/14] ia64: Replace cpu_down with smp_shutdown_nonboot_cpus() Qais Yousef
2019-11-25 11:27 ` [PATCH v2 03/14] arm: arm64: Don't use disable_nonboot_cpus() Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2020-01-21 16:50 ` Qais Yousef
2020-01-21 16:50 ` Qais Yousef
2020-01-21 16:53 ` Russell King - ARM Linux admin
2020-01-21 16:53 ` Russell King - ARM Linux admin
2020-01-21 16:58 ` Qais Yousef
2020-01-21 16:58 ` Qais Yousef
2020-01-21 17:05 ` Russell King - ARM Linux admin
2020-01-21 17:05 ` Russell King - ARM Linux admin
2019-11-25 11:27 ` [PATCH v2 04/14] arm64: hibernate.c: Create a new function to handle cpu_up(sleep_cpu) Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2019-11-25 11:27 ` [PATCH v2 05/14] x86: Replace cpu_up/down with devcie_online/offline Qais Yousef
2019-11-25 11:27 ` [PATCH v2 06/14] powerpc: Replace cpu_up/down with device_online/offline Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2019-11-25 11:27 ` [PATCH v2 07/14] sparc: " Qais Yousef
2019-11-25 11:27 ` [PATCH v2 08/14] parisc: " Qais Yousef
2019-11-25 11:27 ` [PATCH v2 09/14] driver: base: cpu: Export device_online/offline Qais Yousef
2019-11-25 11:27 ` [Xen-devel] [PATCH v2 10/14] driver: xen: Replace cpu_up/down with device_online/offline Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2019-12-09 6:25 ` [Xen-devel] " Jürgen Groß
2019-12-09 6:25 ` Jürgen Groß
2019-11-25 11:27 ` [PATCH v2 11/14] firmware: psci: " Qais Yousef
2019-11-25 11:27 ` Qais Yousef
2019-11-25 11:27 ` [PATCH v2 12/14] torture: " Qais Yousef
2019-11-27 21:47 ` Paul E. McKenney
2019-11-28 16:56 ` Qais Yousef
2019-11-28 17:00 ` Qais Yousef
2019-11-28 21:02 ` Paul E. McKenney
2019-11-29 9:13 ` Qais Yousef
2019-11-29 20:38 ` Paul E. McKenney
2020-02-20 15:31 ` Qais Yousef
2020-02-21 0:26 ` Paul E. McKenney
2020-02-21 9:35 ` Qais Yousef
2020-02-21 20:39 ` Paul E. McKenney
2019-11-25 11:27 ` [PATCH v2 13/14] smp: Create a new function to bringup nonboot cpus online Qais Yousef
2019-11-25 11:27 ` [PATCH v2 14/14] cpu: Hide cpu_up/down Qais Yousef
2020-02-05 15:35 ` [PATCH v2 00/14] Convert cpu_up/down to device_online/offline Qais Yousef
2020-02-05 15:35 ` [Xen-devel] " Qais Yousef
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=20200121180930.GJ25745@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=catalin.marinas@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=devel@etsukata.com \
--cc=fenghua.yu@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jkosina@suse.cz \
--cc=jpoimboe@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namit@vmware.com \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=qais.yousef@arm.com \
--cc=rafael.j.wysocki@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=will@kernel.org \
--cc=zhenzhong.duan@oracle.com \
/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.