From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796057016; b=q3e2B9XI9Ei6Tq5KlvaCI5R9XTi2YsdHdSDn8I1lzMQVCR/ACCfRttbgP/3KVQlI1av8 tfzzqt33wDycNiRG+wkIQZXkwh4HsuuiRpaxrvm83Cyl5kgdvxSEyZDIMeDsclKj0oi3r kpwtwjXIe5FFM6jqN/vPF9qpn2qZXOjrvZqtbHjECImztPzKRktgzqwgBD/TC6OpqbpgE 6DH0i75P4K2do73zHhDbcU0VO6ae2BPAvSNDs4xqBCxfMbaQuyFrmbj4ppuKgQuJCfjUl ZQQiIpWZgh00JVo4JRoj5G34b8VlykEByPsJUJ/d1qAHKAPqaV23gtJxuU4OM5K/CyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796057016; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=JITttlNzBDjJ5Cmsi8+pvTKcsXY+uIfiEDjXf0S4sCI=; b=2apCDN+oMzajH2vBKRbimUGrUPXx38dVF9aDTeCp/PexUCTAFzqlN1fk6QE2DL9fO6Xy SbE+xj+A7UGXntt+19qHnbHTBRNqdYtmsaZ86juw6Kr43kLxtkixHsMiT2bAGBjowelDE TlwnS4WB0F0UlV3kqawJhTpuUd3EHfsERZsrLVw9VuEBfrIaEKwB4+1u1lAruMzg/dZkn 5tckyVJ/ncfGUQzdkXJa4lC12Ee1SScYWTDgXngugRbZJqLg7V0tbogt4vVp02LcsC8TZ Cy4ra6aX+576eTmgh4hgGY5gFH7EyFACCKrGS4GXe0rhQsSVlf3yQ5luCehZoIrMM0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ufmm5vh5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06281606A31C; Mon, 30 Nov 2026 16:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ufmm5vh5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57FB61F00898; Mon, 30 Nov 2026 16:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796057015; bh=JITttlNzBDjJ5Cmsi8+pvTKcsXY+uIfiEDjXf0S4sCI=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Ufmm5vh5NJVwUc9bS5yYbsoJlS8M/Sr5wfHesQslbrZibzBmOwGwClRwCQwP/HUas 66p8W2944vJF03tLQtr6BtabMeuiIElM7FizDGGb5Q51GFkTolTt0oG4QHUzSQ44R2 JLXjNrM11KSeexcp/PfjwIdGFdogQ66MrIP2Ztgd3UJ12C6i+xpM9Hzr7L8nUqDcZ5 XPwvkild8nSJ8w/sm0GVnfFKvUCu2buAfs6lc4miG6rhzWqRE89QoTDP6xsIphPlrB hbADMUjTGDip0r+sKKgilfWCZcYg/voAHYFqBEG5fyJlPmfNs0RyJzelXiD1Xkvl/e tYXXkX7FgMS5w== From: Mark Brown Date: Mon, 30 Nov 2026 16:35:49 +0000 Subject: [PATCH v22 08/16] KVM: arm64: Preserve ISS2.GCS when injecting a Data Abort X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-arm64-gcs-v22-8-80454edf47ea@kernel.org> References: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org> In-Reply-To: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org> To: Catalin Marinas , Will Deacon , Marc Zyngier , Joey Gouly , Suzuki K Poulose , Shuah Khan , Oliver Upton , Fuad Tabba Cc: Peter Maydell , Leonardo Bras , Wei-Lin Chang , Yao Yuan , 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 X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3551; i=broonie@kernel.org; h=from:subject:message-id; bh=V2uKZ2GmB3h46U15UFl0al7YiPpjvhN+QGKT9wZscpk=; b=owGbwMvMwCWm/754w+YLFp2Mp9WSGLJ5l7dvviUTmPGzIv1Ni++sxEd3W1Z0HAjU9F535GVvm 0iRddKKjlIWBjEuBlkxRZa4LO6X9SWv1/AdXNgGM4eVCWQIAxenAEzk4iOG3yw3eOW/71jY+7xl Je+BlldeAWaJX1j5/jzM+a7/vUNy8hlGhrdMX92Xf5tV5py9R134inPhy8D2s7eXtHQZO7G1tt9 dyw4A X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB 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 --- 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