Re: [PATCH v14 07/13] x86/mm: add global ASID allocation helper functions

From: Borislav Petkov
Date: Sun Mar 02 2025 - 02:24:33 EST


On Tue, Feb 25, 2025 at 10:00:42PM -0500, Rik van Riel wrote:
> Add functions to manage global ASID space. Multithreaded processes that
> are simultaneously active on 4 or more CPUs can get a global ASID,
> resulting in the same PCID being used for that process on every CPU.
>
> This in turn will allow the kernel to use hardware-assisted TLB flushing
> through AMD INVLPGB or Intel RAR for these processes.
>
> Signed-off-by: Rik van Riel <riel@xxxxxxxxxxx>
> Tested-by: Manali Shukla <Manali.Shukla@xxxxxxx>
> Tested-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
> Tested-by: Michael Kelley <mhklinux@xxxxxxxxxxx>
> ---
> arch/x86/include/asm/mmu.h | 11 +++
> arch/x86/include/asm/mmu_context.h | 2 +
> arch/x86/include/asm/tlbflush.h | 43 +++++++++
> arch/x86/mm/tlb.c | 146 ++++++++++++++++++++++++++++-
> 4 files changed, 199 insertions(+), 3 deletions(-)

Some small touchups ontop:

--- /tmp/current.patch 2025-03-02 07:33:13.913105249 +0100
+++ /tmp/0001-x86-mm-Add-global-ASID-allocation-helper-functions.patch 2025-03-02 08:05:23.613262232 +0100
diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
-index 3b496cdcb74b..edb5942d4829 100644
+index 3b496cdcb74b..7fbefea5fdae 100644
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -35,6 +38,7 @@ index 3b496cdcb74b..edb5942d4829 100644
+ * hardware-assisted remote TLB invalidation like AMD INVLPGB.
+ */
+ u16 global_asid;
++
+ /* The process is transitioning to a new global ASID number. */
+ bool asid_transition;
+#endif
@@ -251,7 +255,12 @@ index 1cc25e83bd34..9b1652c02452 100644
+ if (mm_global_asid(mm))
+ return;
+
-+ /* The last global ASID was consumed while waiting for the lock. */
++ /*
++ * The last global ASID was consumed while waiting for the lock.
++ *
++ * If this fires, a more aggressive ASID reuse scheme might be
++ * needed.
++ */
+ if (!global_asid_available) {
+ VM_WARN_ONCE(1, "Ran out of global ASIDs\n");
+ return;
@@ -284,5 +293,5 @@ index 1cc25e83bd34..9b1652c02452 100644
* Given an ASID, flush the corresponding user ASID. We can delay this
* until the next time we switch to it.
--

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette