Re: [PATCH] smp: Add memory barrier before many-CPU IPIs

From: Lorenzo Stoakes (ARM)

Date: Tue Dec 01 2026 - 09:24:35 EST


On Fri, Nov 20, 2026 at 02:47:58PM -0800, Dave Hansen wrote:
> diff -puN include/linux/mm_types.h~ipi-mb2-generic include/linux/mm_types.h

(Not sure what all this ~xxx stuff is not seen it before? Some quirk of
git-format-patch or such?)

> --- a/include/linux/mm_types.h~ipi-mb2-generic 2026-11-20 11:28:32.779744056 -0800
> +++ b/include/linux/mm_types.h 2026-11-20 11:28:32.785744556 -0800
> @@ -1514,7 +1514,19 @@ static inline void mm_init_cpumask(struc
> cpumask_clear((struct cpumask *)cpu_bitmap);
> }
>
> -/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
> +/*
> + * mm_cpumask() - CPUs that may hold state derived from @mm (TLB entries,
> + * cached per-mm context). Code that updates per-mm state and then notifies
> + * the CPUs in the mask relies on:
> + *
> + * - A CPU sets its bit, then a full barrier, then reads that state or
> + * loads @mm's page tables.

Slight grammar tweaks (should read as 'relies on ...'):

- A CPU setting its bit, then taking a full barrier, then reading that
state or loading @mm's page tables.

> + * - The updater has a full barrier between the update and reading the
> + * mask. on_each_cpu_mask() and smp_call_function_many() provide it;
> + * open-coded mask tests (e.g. "only this CPU?") must do it themselves.

I think this can be tweaked for clarity as well as grammar fixed:

- The updater taking a full barrier between the update and reading
the mask. Some functions (e.g. on_each_cpu_mask() and
smp_call_function_many()) do this for you, open-coded mask tests
(e.g. only-this-CPU) must do this manually.

> + * - An architecture that clears bits must revalidate that state when the
> + * CPU sets its bit again.

Similarly:

- An architecture that clears bits revalidating that state when the
CPU sets its bit again.

> + */
> static inline cpumask_t *mm_cpumask(struct mm_struct *mm)
> {
> return (struct cpumask *)&mm->flexible_array;

FWIW though adding a comment here is nice so with the tweaks:

Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> # mm bit

--
Cheers, Lorenzo