From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AD2660A262A for ; Mon, 30 Nov 2026 17:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ndZPaJeO; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=IwcX6f8Z DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=Xa20c5T9nf9bBeXM2nt5uKtrgfrQ+RAtPE5zHHiRw9Y=; b=ndZPaJeOvzboJwKilcavpBH4HM bCVkJg7g2vE/B6XeadqfXjKmMLT/JFMMZHg7Rcn9eW7FwzabVIZl9cwEp3OUCzkB8JeM1VrC7vXi4 ZTBbvN7Ww7j+1sINlyqtKqeY5pdDtA2hFmFnH0SPeJpaVzEOU0tWUsg7T+r4ql0okXjEWyYgiFGoQ dIA05nBlvwJmJcpPA0yCclyWIxsZU1g8RCoBJO+xwRJ/eF7CI0936ySau4MemZcnkxr3CbdE2gT9V QVDoS2C3zTq4pHSm1omfU5tidablpCP0RKc7iISdHJxKXS0prF4xYguNojOxfvK1uhJXJU06BJjta vhc+duqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY574-00000005R63-0Yin; Mon, 30 Nov 2026 17:24:26 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY56u-00000005R3a-1lCr for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 17:24:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0418F1595; Mon, 30 Nov 2026 09:24:13 -0800 (PST) Received: from arm.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABFBE3F86F; Mon, 30 Nov 2026 09:24:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796059455; bh=5biLJy+lf0JqGAy0dg5z3SIifkK/WhlUbq8XaVClyqA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IwcX6f8Z/iDRwq1rLZMQJilsZJzUbUr6Cu+D3so/99CnBnsPSbQpzcLCsHt7SHxin sys7bF1AR0EUTCZOVy72QRX2s1q02a2/MZt/fWbJ4kl3AC6ZpAzjHTHVeQTWvEXACV 8B5jyg70mOnqMzuRKeVrR5FBytikjmgSGlZd5Ggg= Date: Mon, 30 Nov 2026 17:24:08 +0000 From: Catalin Marinas To: Arnd Bergmann Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , apais@microsoft.com, Christian Borntraeger , Fuad Tabba , hargar@linux.microsoft.com, Joey Gouly , Marc Zyngier , Mark Rutland , Navneet Singh , Oliver Upton , rlmenge@gmail.com, Siddharth Chintamaneni , Steffen Eiden , Suzuki K Poulose , Sven Schnelle , Will Deacon , Yicong Yang , Zenghui Yu , Zhou Wang , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA Message-ID: References: <20261126155339.1349218-1-arnd@kernel.org> <20261126155339.1349218-2-arnd@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261126155339.1349218-2-arnd@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_092419_255575_0CD3A0F6 X-CRM114-Status: GOOD ( 28.40 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Arnd, (BTW, you dropped all cc from the cover letter in subsequent patches, re-adding them; forgot --cc-cover?) On Thu, Nov 26, 2026 at 04:53:37PM +0100, Arnd Bergmann wrote: > diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h > index 12a500181291..56b4b68407a9 100644 > --- a/arch/arm64/include/asm/el2_setup.h > +++ b/arch/arm64/include/asm/el2_setup.h > @@ -93,6 +93,9 @@ > cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_V > b.lt .Lset_hcrx_\@ > orr x0, x0, #HCRX_EL2_EnASR > + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_ACCDATA > + b.lt .Lset_hcrx_\@ > + orr x0, x0, #HCRX_EL2_EnAS0 As reported by Siddharth (and Sashiko), we need to disable the ACCDATA_EL1 fine-grained traps (HFG{R,W}TR_EL2.nACCDATA_EL1) in __init_el2_fgt, similar to the existing PIE/POE/GCS blocks. Otherwise on an nVHE/pKVM host the ACCDATA_EL1 write in try_enable_st64bv0() traps to EL2 and hits the BUG() in handle_trap(). We should also add a note in booting.rst for cases where the kernel is entered at EL1 (HCRX_EL2.EnAS0 and the nACCDATA_EL1 bits). > diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h > index 803b68758152..1eb171cd546e 100644 > --- a/arch/arm64/include/asm/mmu_context.h > +++ b/arch/arm64/include/asm/mmu_context.h > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -247,6 +248,20 @@ static inline void __switch_mm(struct mm_struct *next) > check_and_switch_context(next); > } > > +/* switch to PASID if new task has enabled st64bv0 */ > +static inline void switch_iommu_mm(struct mm_struct *mm, struct task_struct *tsk) > +{ > + u32 pasid; > + > + if (!IS_ENABLED(CONFIG_IOMMU_SVA) || > + !(tsk->thread.sctlr_user & SCTLR_EL1_EnAS0)) > + return; > + > + pasid = mm_get_enqcmd_pasid(mm); > + if (pasid != IOMMU_PASID_INVALID) > + write_sysreg_s(pasid, SYS_ACCDATA_EL1); > +} > + > static inline void > switch_mm(struct mm_struct *prev, struct mm_struct *next, > struct task_struct *tsk) > @@ -254,6 +269,8 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next, > if (prev != next) > __switch_mm(next); > > + switch_iommu_mm(next, tsk); I don't think switch_mm() is the right place for this. Even if the PASID is per-mm, this function is about per-thread state (EnAS0, ACCDATA_EL1). I'd prefer something like ls64_accdata_thread_switch() called from __switch_to(). > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index d6391ab20db3..b69943bfa297 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -543,6 +544,63 @@ void do_el1_mops(struct pt_regs *regs, unsigned long esr) > kernel_fastforward_single_step(regs); > } > > +/* > + * PASID/ACCDATA is shared by the entire mm, while sctlr_el1 > + * is maintained per thread. Keep things simple and enable > + * ACCDATA dynamically on first access if the feature is > + * available and a valid pasid is set. > + * > + * After exiting back to userspace, the st64bv0 instruction > + * should no longer trap. > + */ > +static bool try_enable_st64bv0(struct pt_regs *regs, unsigned long esr) > +{ > + u32 pasid; > + u64 sctlr; > + > + /* unexpectedly already enabled, signal bus error */ > + if (current->thread.sctlr_user & SCTLR_EL1_EnAS0) > + return false; > + > + /* no PASID set, disallow */ > + pasid = mm_get_enqcmd_pasid(current->mm); > + if (pasid == IOMMU_PASID_INVALID) > + return false; > + > + preempt_disable(); > + write_sysreg_s(pasid, SYS_ACCDATA_EL1); > + sctlr = current->thread.sctlr_user; > + sctlr |= SCTLR_EL1_EnAS0; > + current->thread.sctlr_user = sctlr; > + update_sctlr_el1(sctlr); > + preempt_enable(); > + > + return true; > +} Nit: are regs and esr used in later patches? They are unused here. > + > +void do_el0_other(struct pt_regs *regs, unsigned long esr) > +{ > + switch (ESR_ELx_ISS(esr)) { > + case ESR_ELx_ISS_OTHER_ST64BV0: > + if (!system_supports_ls64_accdata()) > + break; > + > + if (try_enable_st64bv0(regs, esr)) > + return; > + > + force_signal_inject(SIGBUS, BUS_OBJERR, regs->pc, 0); > + break; As mentioned by Sashiko, with this 'break' we end up injecting two signals. So better to just return here. > + > + case ESR_ELx_ISS_OTHER_ST64BV: > + case ESR_ELx_ISS_OTHER_LDST64B: > + default: > + break; > + } > + > + /* Treat all other "other" trapping instructions as illegal opcode */ > + force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0); Prior to this patch, we passed the esr_context to the user signal handler via bad_el0_sync(). You could pass esr as the last argument or just reuse bad_el0_sync(). > diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg > index 28d319e63d8f..7612bacdb018 100644 > --- a/arch/arm64/tools/sysreg > +++ b/arch/arm64/tools/sysreg > @@ -3707,6 +3707,11 @@ Sysreg TPIDR_EL1 3 0 13 0 4 > Field 63:0 ThreadID > EndSysreg > > +Sysreg ACCDATA_EL1 3 0 13 0 5 > +Res0 63:32 > +Field 31:0 ACCDATA > +EndSysreg It makes sense to define this but I think we should remove the equivalent in asm/sysreg.h. -- Catalin