From: Will Deacon <will@kernel.org>
To: Doug Anderson <dianders@chromium.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Marc Zyngier <maz@kernel.org>,
Misono Tomohiro <misono.tomohiro@fujitsu.com>,
Chen-Yu Tsai <wens@csie.org>, Stephen Boyd <swboyd@chromium.org>,
Daniel Thompson <daniel.thompson@linaro.org>,
Sumit Garg <sumit.garg@linaro.org>,
Frederic Weisbecker <frederic@kernel.org>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Kees Cook <keescook@chromium.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Tony Luck <tony.luck@intel.com>,
Valentin Schneider <vschneid@redhat.com>,
linux-arm-kernel@lists.infradead.org,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arm64: smp: smp_send_stop() and crash_smp_send_stop() should try non-NMI first
Date: Mon, 24 Jun 2024 14:49:43 +0100 [thread overview]
Message-ID: <20240624134943.GA8616@willie-the-truck> (raw)
In-Reply-To: <CAD=FV=X8-E-9Qhzdp1L_3g_P_fGmYVUh6zDoFMb7=pzN+cHg=A@mail.gmail.com>
On Fri, May 17, 2024 at 01:01:51PM -0700, Doug Anderson wrote:
> On Fri, Apr 12, 2024 at 6:55 AM Will Deacon <will@kernel.org> wrote:
> > On Thu, Dec 07, 2023 at 05:02:56PM -0800, Douglas Anderson wrote:
> > > In order to do this we also need a slight change in the way we keep
> > > track of which CPUs still need to be stopped. We need to know
> > > specifically which CPUs haven't stopped yet when we fall back to NMI
> > > but in the "crash stop" case the "cpu_online_mask" isn't updated as
> > > CPUs go down. This is why that code path had an atomic of the number
> > > of CPUs left. We'll solve this by making the cpumask into a
> > > global. This has a potential memory implication--with NR_CPUs = 4096
> > > this is 4096/8 = 512 bytes of globals. On the upside in that same case
> > > we take 512 bytes off the stack which could potentially have made the
> > > stop code less reliable. It can be noted that the NMI backtrace code
> > > (lib/nmi_backtrace.c) uses the same approach and that use also
> > > confirms that updating the mask is safe from NMI.
> >
> > Updating the global masks without any synchronisation feels broken though:
> >
> > > @@ -1085,77 +1080,75 @@ void smp_send_stop(void)
> > > {
> > > unsigned long timeout;
> > >
> > > - if (num_other_online_cpus()) {
> > > - cpumask_t mask;
> > > + /*
> > > + * If this cpu is the only one alive at this point in time, online or
> > > + * not, there are no stop messages to be sent around, so just back out.
> > > + */
> > > + if (num_other_online_cpus() == 0)
> > > + goto skip_ipi;
> > >
> > > - cpumask_copy(&mask, cpu_online_mask);
> > > - cpumask_clear_cpu(smp_processor_id(), &mask);
> > > + cpumask_copy(to_cpumask(stop_mask), cpu_online_mask);
> > > + cpumask_clear_cpu(smp_processor_id(), to_cpumask(stop_mask));
> >
> > I don't see what prevents multiple CPUs getting in here concurrently and
> > tripping over the masks. x86 seems to avoid that with an atomic
> > 'stopping_cpu' variable in native_stop_other_cpus(). Do we need something
> > similar?
>
> Good point. nmi_trigger_cpumask_backtrace(), which my code was based
> on, has a test_and_set() for this and that seems simpler than the
> atomic_try_cmpxchg() from the x86 code.
>
> If we run into that case, what do you think we should do? I guess x86
> just does a "return", though it feels like at least a warning should
> be printed since we're not doing what the function asked us to do.
> When we return there will be other CPUs running.
>
> In theory, we could try to help the other processor along? I don't
> know how much complexity to handle here and I could imagine that
> testing some of the corner cases would be extremely hard. I could
> imagine that this might work but maybe it's too complex?
>
> --
>
> void smp_send_stop(void)
> {
> unsigned long timeout;
> static unsigned long stop_in_progress;
>
> /*
> * If this cpu is the only one alive at this point in time, online or
> * not, there are no stop messages to be sent around, so just back out.
> */
> if (num_other_online_cpus() == 0)
> goto skip_ipi;
>
> /*
> * If another is already trying to stop and we're here then either the
> * other CPU hasn't sent us the IPI yet or we have interrupts disabled.
> * Let's help the other CPU by stopping ourselves.
> */
> if (test_and_set_bit(0, &stop_in_progress)) {
> /* Wait until the other inits stop_mask */
> while (!test_bit(1, &stop_in_progress)) {
> cpu_relax();
> smp_rmb();
> }
> do_handle_IPI(IPI_CPU_STOP);
> }
>
> cpumask_copy(to_cpumask(stop_mask), cpu_online_mask);
> cpumask_clear_cpu(smp_processor_id(), to_cpumask(stop_mask));
>
> /* Indicate that we've initted stop_mask */
> set_bit(1, &stop_in_progress);
> smp_wmb();
> ...
> ...
>
> --
>
> Opinions?
I think following the x86 behaviour is probably the best place to start:
the CPU that ends up doing the IPI will spin anyway, so I don't think
there's much to gain by being pro-active on the recipient.
> > Apart from that, I'm fine with the gist of the patch.
>
> Great. Ironically as I reviewed this patch with fresh eyes and looking
> at the things you brought up, I also found a few issues, I'll respond
> to my post myself so I have context to respond to.
Ok.
> One other question: what did you think about Daniel's suggestion to go
> straight to NMI for crash_stop? I don't feel like I have enough
> experience with crash_stop to have intuition here, but it feels like
> trying IRQ first is still better in that case, but I'm happy to go
> either way.
I don't have a strong preference, but I think I'd prefer a non-NMI first
as it feels like things ought to be more robust in that case and it
should work most of the time.
Will
next prev parent reply other threads:[~2024-06-24 13:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 1:02 [PATCH] arm64: smp: smp_send_stop() and crash_smp_send_stop() should try non-NMI first Douglas Anderson
2024-01-09 0:54 ` Doug Anderson
2024-02-28 0:57 ` Doug Anderson
2024-02-28 13:11 ` Daniel Thompson
2024-02-29 18:34 ` Doug Anderson
2024-03-01 11:42 ` Daniel Thompson
2024-03-01 16:05 ` Mark Rutland
2024-03-04 17:34 ` Doug Anderson
2024-04-12 13:55 ` Will Deacon
2024-05-17 20:01 ` Doug Anderson
2024-06-24 13:49 ` Will Deacon [this message]
2024-05-17 20:01 ` Doug Anderson
2024-06-24 13:54 ` Will Deacon
2024-06-25 23:08 ` Doug Anderson
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=20240624134943.GA8616@willie-the-truck \
--to=will@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel.thompson@linaro.org \
--cc=dianders@chromium.org \
--cc=frederic@kernel.org \
--cc=gpiccoli@igalia.com \
--cc=jpoimboe@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=misono.tomohiro@fujitsu.com \
--cc=peterz@infradead.org \
--cc=sumit.garg@linaro.org \
--cc=swboyd@chromium.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vschneid@redhat.com \
--cc=wens@csie.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox