From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEF68C19F32 for ; Sun, 2 Mar 2025 12:39:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC2A26B0082; Sun, 2 Mar 2025 07:39:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B4C326B0083; Sun, 2 Mar 2025 07:39:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EABD6B0085; Sun, 2 Mar 2025 07:39:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 808356B0082 for ; Sun, 2 Mar 2025 07:39:15 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1EF4F1CD4E4 for ; Sun, 2 Mar 2025 12:39:15 +0000 (UTC) X-FDA: 83176566270.17.0EBA253 Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) by imf11.hostedemail.com (Postfix) with ESMTP id 8CC184000F for ; Sun, 2 Mar 2025 12:39:12 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=alien8.de header.s=alien8 header.b=LaTpfNMt; spf=pass (imf11.hostedemail.com: domain of bp@alien8.de designates 65.109.113.108 as permitted sender) smtp.mailfrom=bp@alien8.de; dmarc=pass (policy=none) header.from=alien8.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740919153; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YqpmSp/8nDQKww323mMJ1c1TGuRr+68wTo8FomD32pU=; b=t4JDwbVR1GIrnNdze7iqNBpDkZ7eh9YcaVGSjxqsAA58QsQNjTXj3v4TS7svbA4/Dqgger 4L8ZHCoyeo4cV6Q5v9ebUV+PG4TUBh359act07vjrROKtU6II6hslEbFUlsMfd3tmyE/rA faSe9o+LOtClqLlFCJ4c/uL+H565aPg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740919153; a=rsa-sha256; cv=none; b=LIJ7h0GFTxWRAUIsfNoAAwH74Md3RwtCpQn2rpqxWAiWAg099pe02jKAIEty2idI69EvM5 Yi+ovzVSikGF1Mri0MttvxS5MpaOFF2FoD/48kSizxpzDuO1bP5q3x1Q0yufuF3iUaJnRC KdQWiYp0y2o/VpFKn3ZSsaY6LrYiLf0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=alien8.de header.s=alien8 header.b=LaTpfNMt; spf=pass (imf11.hostedemail.com: domain of bp@alien8.de designates 65.109.113.108 as permitted sender) smtp.mailfrom=bp@alien8.de; dmarc=pass (policy=none) header.from=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 9717340E0173; Sun, 2 Mar 2025 12:39:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id B2qApUVk9KQI; Sun, 2 Mar 2025 12:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1740919142; bh=YqpmSp/8nDQKww323mMJ1c1TGuRr+68wTo8FomD32pU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LaTpfNMtmFGHxlGMTdWV8zk9bBy7zNdaQXA2QwRaCfQhx/r7jY8VRaGp0vlXYN64e R9dhi06wuFr5UufJSsebzgOtpTK8vA972WtjoZUgLQfgH7ac9+XqdJbuZ1FUCizXTt rbqMS6F+zm4TFBAuXsRUTScMsHOJuR+lqjpIlLKMSrdMGuAuiGxHzt5NcAZic1zUs1 H3k48TyRV8eb32lNziF82wdl/SnWLqJIb7i+9ate1+HMrIDR2+/JCIi8NCpjuNH2zR ariWtoiTxcnZXCPzcRir0xKxIylIn+WigL1GaSkY+Ar/fl6xu681Sp0P6jWZ1How3Q Rn/AjUhwd85Wlvm2HGmuAMhMyI9Qv8WDijcg3bm9D6GXd6m9tgmSpSMrDdHgdKO6KV mXffLhmGgMCo0KClwUaIc69nFtVIRRM9pGQxa0/1ZUlRX2lifMW+Lq57kovMgKlj3R QCVaxDl5vpWr6GBOrMjte0QnOLl5i4OUYlF8gpldT3cdkQnzd70G0v13cayEgzYyyz Yc3ojXvbABdFkDXR/wgmt+ZBj6oFHhAmuEaRYE3jScASe+q5MPRUMHjf6t8c8aJNWs lW1HyE6HE2sKc0QpA63qcjI/8vz0E5upSO+n0tJ72QUnYgaybcIhai1SbTKhuxi1sm nT1z6MCrqBhg/A2w+9iRiB44= Received: from zn.tnic (pd95303ce.dip0.t-ipconnect.de [217.83.3.206]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5FBF440E0028; Sun, 2 Mar 2025 12:38:45 +0000 (UTC) Date: Sun, 2 Mar 2025 13:38:38 +0100 From: Borislav Petkov To: Rik van Riel Cc: x86@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, dave.hansen@linux.intel.com, zhengqi.arch@bytedance.com, nadav.amit@gmail.com, thomas.lendacky@amd.com, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, jackmanb@google.com, jannh@google.com, mhklinux@outlook.com, andrew.cooper3@citrix.com, Manali.Shukla@amd.com, mingo@kernel.org Subject: Re: [PATCH v14 09/13] x86/mm: global ASID process exit helpers Message-ID: <20250302123838.GKZ8RRTgRxvBSry6mk@fat_crate.local> References: <20250226030129.530345-1-riel@surriel.com> <20250226030129.530345-10-riel@surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20250226030129.530345-10-riel@surriel.com> X-Stat-Signature: 5zwtmwkgqx4aiwjcqm8dhaitnyrcwhfx X-Rspamd-Queue-Id: 8CC184000F X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1740919152-375134 X-HE-Meta: U2FsdGVkX1/+nHNF45+zkmqfV2L7MzTZGVJ91lRwNI7/g6buL1eoOy1UGmXBb7iHBwJVJGBdbcKdE5VGkwyuGkfLgHMRF3wsHwRwbgUnHCgh3/NQRIs+mvu8CvGQUkMoowRE8E9BkT2N4KxvjSSoU2c8O5wTG02F7MckRk1CxQjlgbVQ8RrcDZ6HVOs1vwZvxyZ3WD1RJn2IUbZA+x7kDUsiwcde2PoY1BjYSHyon0Wa4IYcfnEc/iHmqQLgU1tP4Hv62M+O/eiYpy6k9E0jJu+V6FLWyW1Fs/zeu3x9XR5ew/m6vHm8ycXK9bgT3OOijDTrrP0YaO23Y2iLatvDaVx1YP18libhTkU3DfRZHJEonIRvphVvrSFrKXhNAOcTfrxnXU0mzQXAw1YXBeeiaaFQduG+2+xyybH/Kk5DWcVdrj9gYROUirX70gq6lrPkO3oUTmPWJEktbSXuKOd4ki81hgknTTkX20XmOi4F1oBWLV8E42/AG/yL3aCYKag02olJ42LPqesyftVyxBxoQUbSuNDsBAxQsCzx54ib1ueHuCxThwNxJuzcoV+FnbGFj0uK4zAblryWvAOqVg+oClVwimjve3Uye10rA7bgTaC7PUxiqaZwLvR2tT1nDy3mq/eEFgX4Cu/MfBxdyh4m8ZY/TF18qfZOFANoPKHj1rN/sOx9upVSN0r7zHl37NtCp0bgv3PeNRHdGjO8Sr+HnW51iV2ITF/TayNX0noUi968qSz++DtL9Qd+X+K3iLFANSHH3mA4K5Xde8NRtKRd3p4+V3gRvhokcVblhZBGa38WOvLc78Pe+IRDzKTDVkSx3g8aj8UbAdSb5wxJ2kzyaC0gG7IljAP3UwNDJpRRvLM1m4XcCNxKbUimVD5UI4GZNfc2+0B2uQsj9aDRVEfZ+GKrz1LUbSkC9enKG067y6Euqzkz1kqPa240nS7ZunY+FP0/SCTExpvW7Mtw7Oi GhWWxRNb hZ/QMMGUlIiF9irilX7beezwT7vxDWucnpDob65+rnuECaP+UD3FExoHOtU5iXU821eHM6G3HwcELHaTon9UvRcxQAunM8McSrljF6P/MhPVJu+w2ahKifo9pE2ZnYEU8Rr2/5ZzgWSn5AMaHMcFXq+nDjS2ulseDbs2EWg94xMVm/kZfDQNN1vS854NZ1yW6J0oPMYWzUH4azK7a5NTODbEhOH3LwV6tz21IE61Ph0rnU2f1lXKUskx0/2/VJPOI8INa4PWywVpnOjJDqELsib4USjyJ+mS6lUEoiTbNEXVA7/DzpTRNwmsxgNZcUoRe5EH+PXL2gJtNj49u7N98X5FAF+qzlrGWO4jNHxe6D8A38A9kT0bd7hoFbc4AxdjfiuwIa6ogSYSZ3ZESjFtfHLvNKw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Feb 25, 2025 at 10:00:44PM -0500, Rik van Riel wrote: > A global ASID is allocated for the lifetime of a process. > > Free the global ASID at process exit time. > > Signed-off-by: Rik van Riel > --- > arch/x86/include/asm/mmu_context.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) So I don't like the ifdeffery and tried removing it, see below. So I added helpers. Then I entered the include hell. And then I caught a bug with the DISABLED_FEATURE stuff. Anyway, see below. It builds the allno-, defconfig and mine I use on this machine so more testing is definitely needed. But the end result looks a lot better now. I'll integrate the other changes into the respective patches and I probably should push my branch somewhere as we have accumulated a lot of changes by now so tracking them over mail is getting not that easy anymore. Will do so on Monday. diff --git a/arch/x86/Kconfig.cpufeatures b/arch/x86/Kconfig.cpufeatures index f9af51205f07..3207e5546438 100644 --- a/arch/x86/Kconfig.cpufeatures +++ b/arch/x86/Kconfig.cpufeatures @@ -196,6 +196,6 @@ config X86_DISABLED_FEATURE_SEV_SNP def_bool y depends on !KVM_AMD_SEV -config X86_DISABLED_FEATURE_BROADCAST_TLB_FLUSH +config X86_DISABLED_FEATURE_INVLPGB def_bool y depends on !X86_BROADCAST_TLB_FLUSH 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 -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include 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, diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index 37b735dcf025..01d8a152f04a 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; } +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) { /* @@ -272,7 +280,7 @@ static inline void mm_assign_global_asid(struct mm_struct *mm, u16 asid) smp_store_release(&mm->context.global_asid, asid); } -static inline bool in_asid_transition(struct mm_struct *mm) +static inline bool mm_in_asid_transition(struct mm_struct *mm) { if (!cpu_feature_enabled(X86_FEATURE_INVLPGB)) return false; @@ -280,19 +288,10 @@ static inline bool in_asid_transition(struct mm_struct *mm) return mm && READ_ONCE(mm->context.asid_transition); } #else -static inline u16 mm_global_asid(struct mm_struct *mm) -{ - return 0; -} - -static inline void mm_assign_global_asid(struct mm_struct *mm, u16 asid) -{ -} - -static inline bool in_asid_transition(struct mm_struct *mm) -{ - return false; -} +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 #ifdef CONFIG_PARAVIRT diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index cb43ab08ea4a..c2167b331bbe 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -396,6 +396,9 @@ static void use_global_asid(struct mm_struct *mm) void mm_free_global_asid(struct mm_struct *mm) { + if (!cpu_feature_enabled(X86_FEATURE_INVLPGB)) + return; + if (!mm_global_asid(mm)) return; @@ -1161,7 +1164,7 @@ STATIC_NOPV void native_flush_tlb_multi(const struct cpumask *cpumask, * up on the new contents of what used to be page tables, while * doing a speculative memory access. */ - if (info->freed_tables || in_asid_transition(info->mm)) + if (info->freed_tables || mm_in_asid_transition(info->mm)) on_each_cpu_mask(cpumask, flush_tlb_func, (void *)info, true); else on_each_cpu_cond_mask(should_flush_tlb, flush_tlb_func, -- 2.43.0 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette