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 1C95BC35FFC for ; Wed, 19 Mar 2025 17:31:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02B0B280002; Wed, 19 Mar 2025 13:31:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF59B280001; Wed, 19 Mar 2025 13:31:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFA21280002; Wed, 19 Mar 2025 13:31:43 -0400 (EDT) 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 B3082280001 for ; Wed, 19 Mar 2025 13:31:43 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9A41C5515C for ; Wed, 19 Mar 2025 17:31:44 +0000 (UTC) X-FDA: 83238992928.11.D1BCA5D Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) by imf03.hostedemail.com (Postfix) with ESMTP id 8678C20013 for ; Wed, 19 Mar 2025 17:31:39 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=alien8.de header.s=alien8 header.b=OPuKnj8n; dmarc=pass (policy=none) header.from=alien8.de; spf=pass (imf03.hostedemail.com: domain of bp@alien8.de designates 65.109.113.108 as permitted sender) smtp.mailfrom=bp@alien8.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742405501; a=rsa-sha256; cv=none; b=62sM9CIGeVGQo4T3eX4JGz1/UhxYtxf0w4v/5QWHOenYIlSjfUQBIHVrW1T68q4YxzAhmQ jx+UlJ8odl3giPBtqdwskErI+nXlYPkF14N8VNU+cqFKvALQCYG0VqEZ9IBbYfkuIHG/6I tvRxrXc0VBtpCQjYd0wb1wDKgqcR0gA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=alien8.de header.s=alien8 header.b=OPuKnj8n; dmarc=pass (policy=none) header.from=alien8.de; spf=pass (imf03.hostedemail.com: domain of bp@alien8.de designates 65.109.113.108 as permitted sender) smtp.mailfrom=bp@alien8.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742405501; 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=y4IueNFhKFDuJLhg35AaumVxylQHY1jpwsFPITe81G8=; b=SuZRbXQjzG3XI3Ix1az4KD+AwQBIyMMi577q3pU4uN0m1sds2/MRyeKmU+yKpXBOqccATX 6yUi0JjEr5Wb0LpDhufN3ekYO4z+v/Iaeb2GbA05pqSOyigWGG/GHQ/NzrSZsMivyEMhaD 6jSzBj4Lr1i5aiDBLnq1BdTRR2g6xxk= Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 7F69540E0215; Wed, 19 Mar 2025 17:31:34 +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 Ph_TIAj9eZXD; Wed, 19 Mar 2025 17:31:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1742405488; bh=y4IueNFhKFDuJLhg35AaumVxylQHY1jpwsFPITe81G8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OPuKnj8nSqrVhz24YDL81CfCg2gKR9pIWbtbaHWonnfkdzAOYbC52VlJf5R+D42NL p+FEyIidvNStF1js+JfxT0C7rZGoAMoejdM1WgsnqZOgssxdFq7zcrdehkdBOhwBCf 6qn9py1y7c1kbXSMeviUQDURN49OG5fv/WjXQdW5IkqHVFOA0DbDKfAETmttIs75Qp okPexPU9CehnEmaY3d7p6wh5PbiGuNMNTVx27sDHmdjIb3Dtjbu4HRwbY4Q14i4bwJ dsbkbZltr+kVU6ilR9D0zZyxFpO/sh1scDlcoWBs6e/bo71ONMVPvUCTlG7i2ceeA5 wLaaxTPNfgLMm+60LsvQKf3f4DtxJ37YimbXvOnTV9Uiwo+mADi/UxAjzpM0rP7ZL9 wo6QkkCKHUim+f+duFQ3p6m3NNZfUI/OdPhNo3Vh4zPkc4ReJUxDq/sHn7PoTceDKC dFHviztK56ka7KdDhZc4xg9gEecFpX/b8YeeHYnRAAy42UF9NNurT+CJRgEvMwDn9o EmwYWflsznK/wu6GRntJJGeTc65/wswB2vmGe19QbC0B8PxXLmDLJ6Gvkm3RlzDUX4 /qN979SHOM73h+ayNLsjM9Jni661c+WpiCH3Ao/36bsD+FjghQdcQsWiSHsw8vbL4o RjebWhOYASgWk0sBPvsbIbnY= 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 73B2040E015E; Wed, 19 Mar 2025 17:29:43 +0000 (UTC) Date: Wed, 19 Mar 2025 18:29:35 +0100 From: Borislav Petkov To: Brendan Jackman Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Richard Henderson , Matt Turner , Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Brian Cain , Huacai Chen , WANG Xuerui , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , Dinh Nguyen , Jonas Bonn , Stefan Kristiansson , Stafford Horne , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Richard Weinberger , Anton Ivanov , Johannes Berg , Chris Zankel , Max Filippov , Arnd Bergmann , Andrew Morton , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Uladzislau Rezki , Christoph Hellwig , Masami Hiramatsu , Mathieu Desnoyers , Mike Rapoport , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Dennis Zhou , Tejun Heo , Christoph Lameter , Sean Christopherson , Paolo Bonzini , Ard Biesheuvel , Josh Poimboeuf , Pawan Gupta , x86@kernel.org, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, Junaid Shahid , Yosry Ahmed Subject: Re: [PATCH RFC v2 04/29] mm: asi: Add infrastructure for boot-time enablement Message-ID: <20250319172935.GMZ9r-_zzXhyhHBLfj@fat_crate.local> References: <20250110-asi-rfc-v2-v2-0-8419288bc805@google.com> <20250110-asi-rfc-v2-v2-4-8419288bc805@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20250110-asi-rfc-v2-v2-4-8419288bc805@google.com> X-Rspamd-Server: rspam07 X-Rspam-User: X-Stat-Signature: t4tir3yowh6ru4s7yj49gpffj5517t7y X-Rspamd-Queue-Id: 8678C20013 X-HE-Tag: 1742405499-632364 X-HE-Meta: U2FsdGVkX1+AUccZNY8YgEkvGyXlYu1YgUtFJMN0bv8+tL1jRGaiC/AUc9Y6DBshO6yJIpWCjzURPAr53PtWThHOHLVqFck5lK2qUXN0iWvsY8XTYFSqcs06Dpq3RFDEFBhArhQiPltsCPGDfLUOfYWysO6DfAXTy+uoGhmb4TBDfeVGcD5xniobUbsi5nVlNIdkpljq4tJpGDY4X9gEgwG/FDuiHzVF6UomS9m2ZUDZa8caxwJWH9iEquA6Qsu5v5n+EEeck9Suyz2WFQczEkSd5gmL5uKJaUxgSjIkmj1vHGdB55hOHHcbWIxYORs2WYu0J2PkFJIUCA+dWVA1T+fr6YI800XUbcv3pUOo1Hm6ZxXEPbi0mCQ6YI5iEsiMA0kofJVQMxqQ5HJwpBbQg1xyAdEE63sTxliJvI6DDkN2413XkZRZulZJDij/GVys/5Ifq8crzfDVJzUS6xOmZEvsJnGCBHAJx7DLiLZbwyYWaym3Yj2QVAWB1hZt0GK8BzNCDScFpnWba9ccpORwuCLcoNOE4yYhwubZA4MI4Hsqhhf2I48Hha/wFCLDQkmpYZ6qPYOEu33LRJ5ved9iLQ2Kp7ASWcj3yJNhtcTaq2cglVkJKmSKbp12G11XaWbgTR4HrSUSiO7L7TLMYykCTv5Zl/s58YsJnB6Tvpe4BuWxWNZb8CsbCWWHP08JzkidO6BtFXln5gw/AZTpZ98dR3e6XFjaiKYtDm8T/sU9cQOF/pov9qc67MKAk6BCtnJucodOldEK6vEDiDnkIdcmxj8r8UzcnpSaPB5+EJ0lpkbPEeY9JE7sGqbxo8vjdlKokwv8zBpbRytD7/3Neh1Gu6r74JXsXhvsoxjAADrizBLuu/N2iw5WXwLQ3uaDEyxuLgVYLiH0iTg7MgT7Ais83wffAdxh5oqgPp5ANvVfhoa8YCE7H9JLDe+9T617QsLe4/TXKuImGxRlG8V3PQE fYQXmasN 8Fwpu8rYDQPB72jpZ261RR6qVh13tgMrmuEZg/uptwf/n7UUT+mDdcehDjI3I8iJRfWhDaH5XX/KKsZfq6iTMc2LUXruN14jDyjoAp98euYN/oOMaxHNnIDF+50DeWqOXdVlpF7sqBpFW9FLL09rKhgZB+pDkKyfNP1MBCk5F/RE39sggkiw1koZNEjA4q4dIcaCeb5ogNKBTYlCcb2k4sOFcNVMij43uOXyv0X/ymlX8W4QtHdhcpKlwVNvEU2hRV8CGtGq9B9+d8bkmdSVUc0BGbiAZAcDJVHX/QaIglE9tViY= 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 Fri, Jan 10, 2025 at 06:40:30PM +0000, Brendan Jackman wrote: > Add a boot time parameter to control the newly added X86_FEATURE_ASI. > "asi=on" or "asi=off" can be used in the kernel command line to enable > or disable ASI at boot time. If not specified, ASI enablement depends > on CONFIG_ADDRESS_SPACE_ISOLATION_DEFAULT_ON, which is off by default. I don't know yet why we need this default-on thing... > asi_check_boottime_disable() is modeled after > pti_check_boottime_disable(). > > The boot parameter is currently ignored until ASI is fully functional. > > Once we have a set of ASI features checked in that we have actually > tested, we will stop ignoring the flag. But for now let's just add the > infrastructure so we can implement the usage code. > > Ignoring checkpatch.pl CONFIG_DESCRIPTION because the _DEFAULT_ON > Kconfig is trivial to explain. Those last two paragraphs go... > Checkpatch-args: --ignore CONFIG_DESCRIPTION > Co-developed-by: Junaid Shahid > Signed-off-by: Junaid Shahid > Co-developed-by: Yosry Ahmed > Signed-off-by: Yosry Ahmed > Signed-off-by: Brendan Jackman > --- ... here as that's text not really pertaining to the contents of the patch. > arch/x86/Kconfig | 9 +++++ > arch/x86/include/asm/asi.h | 19 ++++++++-- > arch/x86/include/asm/cpufeatures.h | 1 + > arch/x86/include/asm/disabled-features.h | 8 ++++- > arch/x86/mm/asi.c | 61 +++++++++++++++++++++++++++----- > arch/x86/mm/init.c | 4 ++- > include/asm-generic/asi.h | 4 +++ > 7 files changed, 92 insertions(+), 14 deletions(-) ... > * the N ASI classes. > */ > > +#define static_asi_enabled() cpu_feature_enabled(X86_FEATURE_ASI) Yeah, as already mentioned somewhere else, whack that thing pls. > + > /* > * ASI uses a per-CPU tainting model to track what mitigation actions are > * required on domain transitions. Taints exist along two dimensions: > @@ -131,6 +134,8 @@ struct asi { > > DECLARE_PER_CPU_ALIGNED(struct asi *, curr_asi); > > +void asi_check_boottime_disable(void); > + > void asi_init_mm_state(struct mm_struct *mm); > > int asi_init_class(enum asi_class_id class_id, struct asi_taint_policy *taint_policy); > @@ -155,7 +160,9 @@ void asi_exit(void); > /* The target is the domain we'll enter when returning to process context. */ > static __always_inline struct asi *asi_get_target(struct task_struct *p) > { > - return p->thread.asi_state.target; > + return static_asi_enabled() > + ? p->thread.asi_state.target > + : NULL; Waaay too fancy for old people: if () return... else return NULL; :-) The others too pls. > static __always_inline void asi_set_target(struct task_struct *p, > @@ -166,7 +173,9 @@ static __always_inline void asi_set_target(struct task_struct *p, > > static __always_inline struct asi *asi_get_current(void) > { > - return this_cpu_read(curr_asi); > + return static_asi_enabled() > + ? this_cpu_read(curr_asi) > + : NULL; > } > > /* Are we currently in a restricted address space? */ > @@ -175,7 +184,11 @@ static __always_inline bool asi_is_restricted(void) > return (bool)asi_get_current(); > } > > -/* If we exit/have exited, can we stay that way until the next asi_enter? */ > +/* > + * If we exit/have exited, can we stay that way until the next asi_enter? What is that supposed to mean here? > + * > + * When ASI is disabled, this returns true. > + */ > static __always_inline bool asi_is_relaxed(void) > { > return !asi_get_target(current); > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index 913fd3a7bac6506141de65f33b9ee61c615c7d7d..d6a808d10c3b8900d190ea01c66fc248863f05e2 100644 > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -474,6 +474,7 @@ > #define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3) /* BHI_DIS_S HW control enabled */ > #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4) /* Clear branch history at vmexit using SW loop */ > #define X86_FEATURE_FAST_CPPC (21*32 + 5) /* AMD Fast CPPC */ > +#define X86_FEATURE_ASI (21*32+6) /* Kernel Address Space Isolation */ > > /* > * BUG word(s) > diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h > index c492bdc97b0595ec77f89dc9b0cefe5e3e64be41..c7964ed4fef8b9441e1c0453da587787d8008d9d 100644 > --- a/arch/x86/include/asm/disabled-features.h > +++ b/arch/x86/include/asm/disabled-features.h > @@ -50,6 +50,12 @@ > # define DISABLE_PTI (1 << (X86_FEATURE_PTI & 31)) > #endif > > +#ifdef CONFIG_MITIGATION_ADDRESS_SPACE_ISOLATION > +# define DISABLE_ASI 0 > +#else > +# define DISABLE_ASI (1 << (X86_FEATURE_ASI & 31)) > +#endif > + > #ifdef CONFIG_MITIGATION_RETPOLINE > # define DISABLE_RETPOLINE 0 > #else > @@ -154,7 +160,7 @@ > #define DISABLED_MASK17 0 > #define DISABLED_MASK18 (DISABLE_IBT) > #define DISABLED_MASK19 (DISABLE_SEV_SNP) > -#define DISABLED_MASK20 0 > +#define DISABLED_MASK20 (DISABLE_ASI) > #define DISABLED_MASK21 0 > #define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 22) > Right, that hunk is done this way now: diff --git a/arch/x86/Kconfig.cpufeatures b/arch/x86/Kconfig.cpufeatures index e12d5b7e39a2..f219eaf664fb 100644 --- a/arch/x86/Kconfig.cpufeatures +++ b/arch/x86/Kconfig.cpufeatures @@ -199,3 +199,7 @@ config X86_DISABLED_FEATURE_SEV_SNP config X86_DISABLED_FEATURE_INVLPGB def_bool y depends on !BROADCAST_TLB_FLUSH + +config X86_DISABLED_FEATURE_ASI + def_bool y + depends on !MITIGATION_ADDRESS_SPACE_ISOLATION > diff --git a/arch/x86/mm/asi.c b/arch/x86/mm/asi.c > index 105cd8b43eaf5c20acc80d4916b761559fb95d74..5baf563a078f5b3a6cd4b9f5e92baaf81b0774c4 100644 > --- a/arch/x86/mm/asi.c > +++ b/arch/x86/mm/asi.c > @@ -4,6 +4,7 @@ > #include > #include > > +#include > #include > #include > #include > @@ -29,6 +30,9 @@ static inline bool asi_class_id_valid(enum asi_class_id class_id) > > static inline bool asi_class_initialized(enum asi_class_id class_id) > { > + if (!boot_cpu_has(X86_FEATURE_ASI)) check_for_deprecated_apis: WARNING: arch/x86/mm/asi.c:33: Do not use boot_cpu_has() - use cpu_feature_enabled() instead. Check your whole set pls. > + return 0; > + > if (WARN_ON(!asi_class_id_valid(class_id))) > return false; > > @@ -51,6 +55,9 @@ EXPORT_SYMBOL_GPL(asi_init_class); > > void asi_uninit_class(enum asi_class_id class_id) > { > + if (!boot_cpu_has(X86_FEATURE_ASI)) > + return; > + > if (!asi_class_initialized(class_id)) > return; > > @@ -66,10 +73,36 @@ const char *asi_class_name(enum asi_class_id class_id) > return asi_class_names[class_id]; > } > > +void __init asi_check_boottime_disable(void) > +{ > + bool enabled = IS_ENABLED(CONFIG_MITIGATION_ADDRESS_SPACE_ISOLATION_DEFAULT_ON); > + char arg[4]; > + int ret; > + > + ret = cmdline_find_option(boot_command_line, "asi", arg, sizeof(arg)); > + if (ret == 3 && !strncmp(arg, "off", 3)) { > + enabled = false; > + pr_info("ASI disabled through kernel command line.\n"); > + } else if (ret == 2 && !strncmp(arg, "on", 2)) { > + enabled = true; > + pr_info("Ignoring asi=on param while ASI implementation is incomplete.\n"); > + } else { > + pr_info("ASI %s by default.\n", > + enabled ? "enabled" : "disabled"); > + } > + > + if (enabled) > + pr_info("ASI enablement ignored due to incomplete implementation.\n"); Incomplete how? > +} > + > static void __asi_destroy(struct asi *asi) > { > - lockdep_assert_held(&asi->mm->asi_init_lock); > + WARN_ON_ONCE(asi->ref_count <= 0); > + if (--(asi->ref_count) > 0) Switch that to include/linux/kref.h It gives you a sanity-checking functionality too so you don't need the WARN... > + return; > > + free_pages((ulong)asi->pgd, PGD_ALLOCATION_ORDER); > + memset(asi, 0, sizeof(struct asi)); And then you can do: if (kref_put()) free_pages... and so on. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette