Re: [RFC PATCH 7/9] x86/mm: Introduce Remote Action Request

Nadav Amit
2025-05-06T15:50:34Z

> On 6 May 2025, at 18:16, Rik van Riel <riel@surriel.com> wrote:
>
> It gets better. Page 8 of the RAR whitepaper tells
> us that we can simply use RAR to have a CPU send
> itself TLB flush instructions, and the microcode
> will do the flush at the same time the other CPUs
> handle theirs.
>
> "At this point, the ILP may invalidate its own TLB by
> signaling RAR to itself in order to invoke the RAR handler
> locally as well"
>
> I tried this, but things blew up very early in
> boot, presumably due to the CPU trying to send
> itself a RAR before it was fully configured to
> handle them.
>
> The code may need a better decision point than
> cpu_feature_enabled(X86_FEATURE_RAR) to decide
> whether or not to use RAR.
>
> Probably something that indicates RAR is actually
> ready to use on all CPUs.
>

Once you get something working (perhaps with a branch for
now) you can take the static-key/static-call path, presumably.
I would first try to get something working properly.

BTW: I suspect that the RAR approach might not handle TLB
storms worse than the IPI approach, in which once the handler
sees such a storm, it does full TLB flush and skips flushes of
“older” generations. You may want to benchmark this scenario
(IIRC one of the will-it-scale does something similar).

> I think we have 3 cases here:
>
> 1) Only the local TLB needs to be flushed.
> In this case we can INVPCID locally, and skip any
> potential contention on the RAR payload table.

More like INVLPG (and INVPCID to the user PTI). AFAIK, Andy said
INVLPG performs better than INVPCID for a single entry. But yes,
this is a simple and hot scenario that should have a separate
code-path.

>
> 2) Only one remote CPU needs to be flushed (no local).
> This can use the arch_rar_send_single_ipi() thing.
>
> 3) Multiple CPUs need to be flushed. This could include
> the local CPU, or be only multiple remote CPUs.
> For this case we could just use arch_send_rar_ipi_mask(),
> including sending a RAR request to the local CPU, which
> should handle it concurrently with the other CPUs.
>
> Does that seem like a reasonable way to handle things?

It it. It is just that code-wise, I think the 2nd and 3rd cases
are similar, and it can be better to distinguish the differences
between them without creating two completely separate code-paths.
This makes maintenance and reasoning more simple, I think.

Consider having a look at smp_call_function_many_cond(). I think
it handles the 2nd and 3rd cases nicely in the manner I just
described. Admittedly, I am a bit biased…