]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/mm: Add global ASID process exit helpers
authorRik van Riel <riel@surriel.com>
Wed, 26 Feb 2025 03:00:44 +0000 (22:00 -0500)
committerIngo Molnar <mingo@kernel.org>
Wed, 19 Mar 2025 10:12:29 +0000 (11:12 +0100)
A global ASID is allocated for the lifetime of a process. Free the global ASID
at process exit time.

  [ bp: Massage, create helpers, hide details inside them. ]

Signed-off-by: Rik van Riel <riel@surriel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250226030129.530345-10-riel@surriel.com
arch/x86/include/asm/mmu_context.h
arch/x86/include/asm/tlbflush.h

index a2c70e495b1b184fdc925f793fdabf877e751b7b..2398058b6e83cba9bc720f83a09512011326220e 100644 (file)
@@ -2,7 +2,6 @@
 #ifndef _ASM_X86_MMU_CONTEXT_H
 #define _ASM_X86_MMU_CONTEXT_H
 
-#include <asm/desc.h>
 #include <linux/atomic.h>
 #include <linux/mm_types.h>
 #include <linux/pkeys.h>
@@ -13,6 +12,7 @@
 #include <asm/paravirt.h>
 #include <asm/debugreg.h>
 #include <asm/gsseg.h>
+#include <asm/desc.h>
 
 extern atomic64_t last_mm_ctx_id;
 
@@ -139,6 +139,9 @@ static inline void mm_reset_untag_mask(struct mm_struct *mm)
 #define enter_lazy_tlb enter_lazy_tlb
 extern void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk);
 
+#define mm_init_global_asid mm_init_global_asid
+extern void mm_init_global_asid(struct mm_struct *mm);
+
 extern void mm_free_global_asid(struct mm_struct *mm);
 
 /*
@@ -163,6 +166,8 @@ static inline int init_new_context(struct task_struct *tsk,
                mm->context.execute_only_pkey = -1;
        }
 #endif
+
+       mm_init_global_asid(mm);
        mm_reset_untag_mask(mm);
        init_new_context_ldt(mm);
        return 0;
@@ -172,6 +177,7 @@ static inline int init_new_context(struct task_struct *tsk,
 static inline void destroy_context(struct mm_struct *mm)
 {
        destroy_context_ldt(mm);
+       mm_free_global_asid(mm);
 }
 
 extern void switch_mm(struct mm_struct *prev, struct mm_struct *next,
index 1f61a39a87769e1a5cba7f38a533fb1f7d9ccfe1..e6c3be06dd21cb90ab48e430f36fe0413da1d914 100644 (file)
@@ -261,6 +261,14 @@ static inline u16 mm_global_asid(struct mm_struct *mm)
        return asid;
 }
 
+static inline void mm_init_global_asid(struct mm_struct *mm)
+{
+       if (cpu_feature_enabled(X86_FEATURE_INVLPGB)) {
+               mm->context.global_asid = 0;
+               mm->context.asid_transition = false;
+       }
+}
+
 static inline void mm_assign_global_asid(struct mm_struct *mm, u16 asid)
 {
        /*
@@ -281,6 +289,7 @@ static inline bool mm_in_asid_transition(struct mm_struct *mm)
 }
 #else
 static inline u16 mm_global_asid(struct mm_struct *mm) { return 0; }
+static inline void mm_init_global_asid(struct mm_struct *mm) { }
 static inline void mm_assign_global_asid(struct mm_struct *mm, u16 asid) { }
 static inline bool mm_in_asid_transition(struct mm_struct *mm) { return false; }
 #endif /* CONFIG_BROADCAST_TLB_FLUSH */