Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>,
	 Will Deacon <will@kernel.org>, Marc Zyngier <maz@kernel.org>,
	 Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	 Shuah Khan <shuah@kernel.org>, Oliver Upton <oupton@kernel.org>,
	 Fuad Tabba <fuad.tabba@linux.dev>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	 Leonardo Bras <leo.bras@arm.com>,
	Wei-Lin Chang <weilin.chang@arm.com>,
	 Yao Yuan <yaoyuan@linux.alibaba.com>,
	linux-arm-kernel@lists.infradead.org,  linux-doc@vger.kernel.org,
	kvmarm@lists.linux.dev,  linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Mark Brown <broonie@kernel.org>
Subject: [PATCH v22 08/16] KVM: arm64: Preserve ISS2.GCS when injecting a Data Abort
Date: Mon, 30 Nov 2026 16:35:49 +0000	[thread overview]
Message-ID: <20261130-arm64-gcs-v22-8-80454edf47ea@kernel.org> (raw)
In-Reply-To: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org>

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



  parent reply	other threads:[~2026-11-30 17:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
2026-11-30 16:35 ` [PATCH v22 01/16] arm64/gcs: Ensure FGTs for EL1 GCS instructions are disabled Mark Brown
2026-11-30 16:35 ` [PATCH v22 02/16] KVM: arm64: Drop the SPSR_EL1 and ELR_EL1 trap accessors Mark Brown
2026-11-30 16:35 ` [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests Mark Brown
2026-11-30 16:49   ` Leonardo Bras
2026-11-30 16:59     ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible Mark Brown
2026-11-30 16:35 ` [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception Mark Brown
2026-11-30 16:35 ` [PATCH v22 06/16] KVM: arm64: Validate GCS exception lock when emulating ERET Mark Brown
2026-11-30 16:35 ` [PATCH v22 07/16] KVM: arm64: Forward GCS exceptions to nested guests Mark Brown
2026-11-30 16:35 ` Mark Brown [this message]
2026-11-30 16:35 ` [PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker Mark Brown
2026-11-30 16:35 ` [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests Mark Brown
2026-11-30 16:35 ` [PATCH v22 11/16] KVM: selftests: arm64: Check invalid feature combination handling Mark Brown
2026-11-30 16:35 ` [PATCH v22 12/16] KVM: selftests: arm64: Add GCS registers to get-reg-list Mark Brown
2026-11-30 16:35 ` [PATCH v22 13/16] KVM: selftests: arm64: Add GCS to set_id_regs Mark Brown
2026-11-30 16:35 ` [PATCH v22 14/16] KVM: selftests: arm64: Only restore SPSR_EL1 and ELR_EL1 if they change Mark Brown
2026-11-30 16:35 ` [PATCH v22 15/16] tools: Synchronise the kernel esr.h Mark Brown
2026-11-30 16:35 ` [PATCH v22 16/16] KVM: selftests: arm64: Add GCS EXLOCK exception emulation test Mark Brown

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=20261130-arm64-gcs-v22-8-80454edf47ea@kernel.org \
    --to=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=leo.bras@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=peter.maydell@linaro.org \
    --cc=shuah@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=weilin.chang@arm.com \
    --cc=will@kernel.org \
    --cc=yaoyuan@linux.alibaba.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