[PATCH v22 08/16] KVM: arm64: Preserve ISS2.GCS when injecting a Data Abort

Mark Brown broonie at kernel.org
Mon Nov 30 08:35:49 PST 2026


A Data Abort caused by a guarded control stack access sets bit 40 in
ESR_ELx. KVM loses this bit when it forwards a nested stage-2 fault
using the walk result, or when it constructs a fresh syndrome for an
external abort. The guest then sees an ordinary data access.

Recover ISS2.GCS from the original Data Abort when injecting the fault
into a guest that exposes GCS. Take only that bit from ISS2 so that
other host syndrome fields do not leak into the synthesized exception.

Signed-off-by: Mark Brown <broonie at kernel.org>
---
 arch/arm64/include/asm/kvm_emulate.h | 10 ++++++++++
 arch/arm64/kvm/emulate-nested.c      |  2 ++
 arch/arm64/kvm/inject_fault.c        |  6 ++++--
 arch/arm64/kvm/nested.c              |  3 +++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index f5b0b0393f9c..09d16ea97d08 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -367,6 +367,16 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
 	return vcpu->arch.fault.esr_el2;
 }
 
+static inline u64 kvm_vcpu_dabt_iss2(const struct kvm_vcpu *vcpu)
+{
+	u64 esr = kvm_vcpu_get_esr(vcpu);
+
+	if (esr_is_data_abort(esr) && kvm_has_gcs(vcpu->kvm))
+		return esr & (ESR_ELx_GCS << ESR_ELx_ISS2_SHIFT);
+
+	return 0;
+}
+
 static inline bool guest_hyp_wfx_traps_enabled(const struct kvm_vcpu *vcpu)
 {
 	u64 esr = kvm_vcpu_get_esr(vcpu);
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index c4a33f1f6ad4..c6ebb557ed9b 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -2969,6 +2969,8 @@ int kvm_inject_nested_sea(struct kvm_vcpu *vcpu, bool iabt, u64 addr)
 	u64 esr = FIELD_PREP(ESR_ELx_EC_MASK,
 			     iabt ? ESR_ELx_EC_IABT_LOW : ESR_ELx_EC_DABT_LOW);
 	esr |= ESR_ELx_FSC_EXTABT | ESR_ELx_IL;
+	if (!iabt)
+		esr |= kvm_vcpu_dabt_iss2(vcpu);
 
 	vcpu_write_sys_reg(vcpu, addr, FAR_EL2);
 
diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
index aa2011cc0d5a..108b76373bd2 100644
--- a/arch/arm64/kvm/inject_fault.c
+++ b/arch/arm64/kvm/inject_fault.c
@@ -152,8 +152,10 @@ static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr
 	else
 		esr |= (ESR_ELx_EC_IABT_CUR << ESR_ELx_EC_SHIFT);
 
-	if (!is_iabt)
+	if (!is_iabt) {
 		esr |= ESR_ELx_EC_DABT_LOW << ESR_ELx_EC_SHIFT;
+		esr |= kvm_vcpu_dabt_iss2(vcpu);
+	}
 
 	esr |= fsc;
 
@@ -253,7 +255,7 @@ static int kvm_inject_nested_excl_atomic(struct kvm_vcpu *vcpu, u64 addr)
 {
 	u64 esr = FIELD_PREP(ESR_ELx_EC_MASK, ESR_ELx_EC_DABT_LOW) |
 		  FIELD_PREP(ESR_ELx_FSC, ESR_ELx_FSC_EXCL_ATOMIC) |
-		  ESR_ELx_IL;
+		  ESR_ELx_IL | kvm_vcpu_dabt_iss2(vcpu);
 
 	vcpu_write_sys_reg(vcpu, addr, FAR_EL2);
 	return kvm_inject_nested_sync(vcpu, esr);
diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index 78d5b18dbd2d..ed10c8b41cc8 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -1081,6 +1081,9 @@ int kvm_s2_handle_perm_fault(struct kvm_vcpu *vcpu, struct kvm_s2_trans *trans)
 
 int kvm_inject_s2_fault(struct kvm_vcpu *vcpu, u64 esr_el2)
 {
+	/* The stage-2 walker supplies EC and ISS. Recover ISS2 from the fault. */
+	esr_el2 |= kvm_vcpu_dabt_iss2(vcpu);
+
 	vcpu_write_sys_reg(vcpu, vcpu->arch.fault.far_el2, FAR_EL2);
 	vcpu_write_sys_reg(vcpu, vcpu->arch.fault.hpfar_el2, HPFAR_EL2);
 

-- 
2.47.3




More information about the linux-arm-kernel mailing list