[PATCH v6 00/29] context_tracking,x86: Defer some IPIs until a user->kernel transition
Valentin Schneider
vschneid at redhat.com
Wed Nov 5 08:24:29 PST 2025
On 29/10/25 18:15, Frederic Weisbecker wrote:
> Le Wed, Oct 29, 2025 at 11:32:58AM +0100, Valentin Schneider a écrit :
>> I need to have a think about that one; one pain point I see is the context
>> tracking work has to be NMI safe since e.g. an NMI can take us out of
>> userspace. Another is that NOHZ-full CPUs need to be special cased in the
>> stop machine queueing / completion.
>>
>> /me goes fetch a new notebook
>
> Something like the below (untested) ?
>
Some minor nits below but otherwise that looks promising.
One problem I'm having however is reasoning about the danger zone; what
forbidden actions could a NO_HZ_FULL CPU take when entering the kernel
while take_cpu_down() is happening?
I'm actually not familiar with why we actually use stop_machine() for CPU
hotplug; I see things like CPUHP_AP_SMPCFD_DYING::smpcfd_dying_cpu() or
CPUHP_AP_TICK_DYING::tick_cpu_dying() expect other CPUs to be patiently
spinning in multi_cpu_stop(), and I *think* nothing in the entry code up to
context_tracking entry would disrupt that, but it's not a small thing to
reason about.
AFAICT we need to reason about every .teardown callback from
CPUHP_TEARDOWN_CPU to CPUHP_AP_OFFLINE and their explicit & implicit
dependencies on other CPUs being STOP'd.
> @@ -176,6 +177,68 @@ struct multi_stop_data {
> atomic_t thread_ack;
> };
>
> +static DEFINE_PER_CPU(int, stop_machine_poll);
> +
> +void stop_machine_poll_wait(void)
That needs to be noinstr, and AFAICT there's no problem with doing just that.
> +{
> + int *poll = this_cpu_ptr(&stop_machine_poll);
> +
> + while (*poll)
> + cpu_relax();
> + /* Enforce the work in stop machine to be visible */
> + smp_mb();
> +}
> +
> +static void stop_machine_poll_start(struct multi_stop_data *msdata)
> +{
> + int cpu;
> +
> + if (housekeeping_enabled(HK_TYPE_KERNEL_NOISE))
I think that wants a negation
> + return;
> +
> + /* Random target can't be known in advance */
> + if (!msdata->active_cpus)
> + return;
More information about the linux-riscv
mailing list