From nobody Sun Dec 14 21:42:31 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFC1F204C29 for ; Tue, 4 Mar 2025 13:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741096730; cv=none; b=URpJaj0hyeYFcPgKWwZtWo3Ezee6fTQW8wCM67zBGDUrudWtWe6bmtT1ATbgRb5kBdyjajX96kdPkWYAn/lcg8DDrk4wVBFAJq1m3vbRAXahmatFLdKoLIsGxY4QtiXJKHJxy0pqX8wdRjdeb0AYfRvKt1kAeO3jGDYxHvey2RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741096730; c=relaxed/simple; bh=zGmupePrg6X0HyaMkp7BsDdleTUSKa3KpW1HRLcE7Sc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEGdnVTL85IJfS7uo486INagCZGI0CiXAs+y3U+VoZTx8ixbT7ldzDlHpDOc/Z13ctW71rL663B3WrnJFPkFBspvJGqk4NuphNn93Hq0eMSpr9SkEEMln8uMUMK8MtbB5OArWlRuhb9b6MCmEahBFGodHAZ+2Iwn++hb3hF9p6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vF23nCnL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="vF23nCnL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A1BEC4CEE5; Tue, 4 Mar 2025 13:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741096730; bh=zGmupePrg6X0HyaMkp7BsDdleTUSKa3KpW1HRLcE7Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vF23nCnLD/EN0hiNA2S0Dqw90+rhjkP7uGC0lVh/1ZHuOtrBMANtrepOA+aV8+MSg xgQ3p8MST+8/lt1MLO2MGozYt0O0K8QxxfiQwlnoblC+mjaG2PxViOVq2Ey1bn1u1W LST5ksnoIkQCTZetTqtr14iX9Ge96BNiyflO2nZlNIdba3YhxfHu6uorNEOYk8Q1ZN VA4+d0KCUxq25Nf042VOC2jEWSMDGciSFvhrCSNt7DNEHCiNNtyerc8nn3+d0/WKE7 np3qfANNc6IBDPhbUPt2PdJtVlJtsvBd4o0khHeqErwRCkbI7idmpiS3cAkqF1e4yW jzYPtG1e7BX6Q== From: Borislav Petkov To: riel@surriel.com Cc: Manali.Shukla@amd.com, akpm@linux-foundation.org, andrew.cooper3@citrix.com, jackmanb@google.com, jannh@google.com, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhklinux@outlook.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, x86@kernel.org, zhengqi.arch@bytedance.com, Borislav Petkov Subject: [PATCH v15 08/11] x86/mm: Add global ASID process exit helpers Date: Tue, 4 Mar 2025 14:58:13 +0100 Message-ID: <20250304135816.12356-9-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304135816.12356-1-bp@kernel.org> References: <20250304135816.12356-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Rik van Riel A global ASID is allocated for the lifetime of a process. Free the global A= SID at process exit time. [ bp: Massage, create helpers, hide details inside them. ] Signed-off-by: Rik van Riel Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20250226030129.530345-10-riel@surriel.com --- arch/x86/include/asm/mmu_context.h | 8 +++++++- arch/x86/include/asm/tlbflush.h | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_= context.h index a2c70e495b1b..2398058b6e83 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -2,7 +2,6 @@ #ifndef _ASM_X86_MMU_CONTEXT_H #define _ASM_X86_MMU_CONTEXT_H =20 -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include =20 extern atomic64_t last_mm_ctx_id; =20 @@ -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); =20 +#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); =20 /* @@ -163,6 +166,8 @@ static inline int init_new_context(struct task_struct *= tsk, mm->context.execute_only_pkey =3D -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); } =20 extern void switch_mm(struct mm_struct *prev, struct mm_struct *next, diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflus= h.h index 1f61a39a8776..e6c3be06dd21 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -261,6 +261,14 @@ static inline u16 mm_global_asid(struct mm_struct *mm) return asid; } =20 +static inline void mm_init_global_asid(struct mm_struct *mm) +{ + if (cpu_feature_enabled(X86_FEATURE_INVLPGB)) { + mm->context.global_asid =3D 0; + mm->context.asid_transition =3D 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_stru= ct *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 fa= lse; } #endif /* CONFIG_BROADCAST_TLB_FLUSH */ --=20 2.43.0