Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Will Deacon <will@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	apais@microsoft.com,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	hargar@linux.microsoft.com, Joey Gouly <joey.gouly@arm.com>,
	Marc Zyngier <maz@kernel.org>,
	Navneet Singh <navneetsingh@microsoft.com>,
	Oliver Upton <oupton@kernel.org>,
	rlmenge@gmail.com,
	Siddharth Chintamaneni <sidchintamaneni@gmail.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Sven Schnelle <sven@linux.ibm.com>,
	Yicong Yang <yangyicong@hisilicon.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Zhou Wang <wangzhou1@hisilicon.com>,
	kvmarm@lists.linux.dev, kvm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 1/4] arm64: kvm: save and restore ACCDATA_EL1 if used by host
Date: Thu,  3 Dec 2026 10:57:00 +0100	[thread overview]
Message-ID: <20261203095703.655796-2-arnd@kernel.org> (raw)
In-Reply-To: <20261203095703.655796-1-arnd@kernel.org>

From: Arnd Bergmann <arnd@arndb.de>

On machines running KVM guests, KVM already handles saving and restoring
ACCDATA now. If the same process uses SVA itself, the context is restored
upon guest access.  This only really makes sense if the host device using
SVA is attached to the same SMMU using a single stage translation, and
another device is assigned to the guest VMID for stage2 so it can use
the stage1 translation inside of the guest using ACCDATA as PASID.

Assume that the host context needs to be saved and restored whenever
both the kernel and the hardware support the feature. This assumes
it is cheaper to access the register unconditionally than to
check for 'current->thread.sctlr_user & SCTLR_EL1_EnAS0'.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index 4a008c8a696b..43c020ca3d8d 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -143,10 +143,14 @@ static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt)
 {
 	struct kvm_vcpu *vcpu;
 
-	/* The host never uses ACCDATA_EL1 */
-	if (!cpus_have_final_cap(ARM64_HAS_LS64_ACCDATA) || !ctxt_is_guest(ctxt))
+	/* The hardware does not support ACCDATA_EL1 */
+	if (!cpus_have_final_cap(ARM64_HAS_LS64_ACCDATA))
 		return false;
 
+	/* host only cares if SVA is enabled */
+	if (!ctxt_is_guest(ctxt))
+		return IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA);
+
 	vcpu = ctxt_to_vcpu(ctxt);
 	return kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA);
 }
-- 
2.53.0



  reply	other threads:[~2026-12-03  9:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:56 [PATCH v3 0/4] st64bv0 support in iommu-sva Arnd Bergmann
2026-12-03  9:57 ` Arnd Bergmann [this message]
2026-12-03  9:57 ` [PATCH v3 2/4] arm64: dynamically enable st64bv0 for SVA Arnd Bergmann
2026-12-03  9:57 ` [PATCH v3 3/4] arm64: add HWCAP3_LS64_ACCDATA Arnd Bergmann
2026-12-03  9:57 ` [PATCH v3 4/4] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203095703.655796-2-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=apais@microsoft.com \
    --cc=arnd@arndb.de \
    --cc=borntraeger@linux.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=hargar@linux.microsoft.com \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=navneetsingh@microsoft.com \
    --cc=oupton@kernel.org \
    --cc=rlmenge@gmail.com \
    --cc=seiden@linux.ibm.com \
    --cc=sidchintamaneni@gmail.com \
    --cc=suzuki.poulose@arm.com \
    --cc=sven@linux.ibm.com \
    --cc=wangzhou1@hisilicon.com \
    --cc=will@kernel.org \
    --cc=yangyicong@hisilicon.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox