Re: [PATCH] mm/mmu_gather: send tlb_remove_table_smp_sync IPI only to MM CPUs

From: Andrew Morton
Date: Sun Mar 12 2023 - 16:26:10 EST


On Sun, 12 Mar 2023 10:09:45 +0200 Yair Podemsky <ypodemsk@xxxxxxxxxx> wrote:

> Currently the tlb_remove_table_smp_sync IPI is sent to all CPUs
> indiscriminately, this causes unnecessary work and delays notable in
> real-time use-cases and isolated cpus, this patch will limit this IPI to
> only be sent to cpus referencing the effected mm and are currently in
> kernel space.
>
> ...
>
> --- a/mm/mmu_gather.c
> +++ b/mm/mmu_gather.c
> @@ -191,7 +192,15 @@ static void tlb_remove_table_smp_sync(void *arg)
> /* Simply deliver the interrupt */
> }
>
> -void tlb_remove_table_sync_one(void)
> +static bool cpu_in_kernel(int cpu, void *info)
> +{
> + struct context_tracking *ct = per_cpu_ptr(&context_tracking, cpu);
> + int statue = atomic_read(&ct->state);

Strange identifier. Should be "state"?

> + //will return true only for cpu's in kernel space

Please use /* */ style comments

And use "cpus" rather than "cpu's" - plural, not possessive.

> + return !(statue & CT_STATE_MASK);

Using

return state & CT_STATE_MASK == CONTEXT_KERNEL;

would more clearly express the intent.

> +}

And... surely this function is racy. ct->state can change value one
nanosecond after cpu_in_kernel() reads it, so cpu_in_kernel()'s return
value is now wrong?