[PATCH v3 1/4] arm64: kvm: save and restore ACCDATA_EL1 if used by host

From: Arnd Bergmann

Date: Thu Dec 03 2026 - 04:57:46 EST


From: Arnd Bergmann <arnd@xxxxxxxx>

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@xxxxxxxx>
---
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