From: Fuad Tabba <fuad.tabba@linux.dev>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Vincent Donnefort <vdonnefort@google.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Fuad Tabba <tabba@google.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] KVM: arm64: Don't run a pVM with firmware Spectre-v4 mitigation disabled
Date: Tue, 17 Nov 2026 16:37:01 +0000 [thread overview]
Message-ID: <20261117163702.1678277-3-fuad.tabba@linux.dev> (raw)
In-Reply-To: <20261117163702.1678277-1-fuad.tabba@linux.dev>
EL2 handles a protected guest's ARM_SMCCC_ARCH_WORKAROUND_2 discovery
query using a copy of the host's Spectre-v4 state taken at init. If the
system is mitigated and the guest doesn't have SSBS, EL2 returns
NOT_REQUIRED, which indicates to the guest that firmware mitigation is
permanently enabled. However, EL2 forwards the host's
ARM_SMCCC_ARCH_WORKAROUND_2 calls to firmware, so the host can disable
the mitigation and then run a protected vCPU.
On a mitigated system, the host kernel disables the mitigation only
while its own userspace runs, so a host that runs a vCPU with it
disabled is misbehaving, whatever the guest was told. Track the
mitigation state per CPU from the host's calls, and don't run a
protected vCPU on a CPU where it's disabled. Forward the calls without
hints, so that firmware decodes the same function ID as EL2.
Firmware enables the mitigation when a CPU powers up (SMCCC DEN0028,
7.6.4), so the tracked state doesn't have to be reset on CPU_ON or
resume. When an SDEI event completes, firmware also restores the
mitigation state of the interrupted context. EL2 can't track that, so
this fix relies on the host's SDEI calls not being forwarded.
Fixes: fe40ff87ead5c ("KVM: arm64: Implement HVC handling for protected guests at EL2")
Reported-by: Ryan Roberts <ryan.roberts@arm.com>
Closes: https://lore.kernel.org/all/5fa8a1fb-4e2c-4746-8a70-a47f387ef0d6@arm.com/
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
---
arch/arm64/include/asm/kvm_host.h | 1 +
arch/arm64/kvm/hyp/nvhe/hyp-main.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 97332ffcb1300..80d0665b93f25 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -839,6 +839,7 @@ struct kvm_host_data {
#define KVM_HOST_DATA_FLAG_VCPU_IN_HYP_CONTEXT 4
#define KVM_HOST_DATA_FLAG_L1_VNCR_MAPPED 5
#define KVM_HOST_DATA_FLAG_HAS_BRBE 6
+#define KVM_HOST_DATA_FLAG_SSBD_DISABLED 7
unsigned long flags;
struct kvm_cpu_context host_ctxt;
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 37fb9896ba3ad..8cc541e6e521b 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -925,6 +925,15 @@ DEFINE_KVM_HOST_HCALL(int, __kvm_vcpu_run, struct kvm_vcpu __kern *, vcpu)
if (unlikely(system_supports_sme() && read_sysreg_s(SYS_SVCR)))
return ret;
+ /*
+ * Firmware Spectre-v4 mitigation can be advertised to a
+ * protected guest as permanent. The host kernel runs with it
+ * enabled, so if it's disabled the host is misbehaving.
+ */
+ if (pkvm_hyp_vcpu_is_protected(hyp_vcpu) && spectre_v4_state == SPECTRE_MITIGATED &&
+ host_data_test_flag(SSBD_DISABLED))
+ return ret;
+
/*
* ON has a single writer, pkvm_reset_vcpu() on this CPU, so
* READ_ONCE suffices. ON_PENDING takes the reset; -ECANCELED
@@ -1656,6 +1665,16 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt, u64 func
return;
}
+ if (func_id == ARM_SMCCC_ARCH_WORKAROUND_2) {
+ /* Drop the hints, so that firmware decodes the ID as EL2 did. */
+ cpu_reg(host_ctxt, 0) = func_id;
+
+ if (lower_32_bits(cpu_reg(host_ctxt, 1)))
+ host_data_clear_flag(SSBD_DISABLED);
+ else
+ host_data_set_flag(SSBD_DISABLED);
+ }
+
trace_hyp_exit(host_ctxt, HYP_REASON_SMC);
__kvm_hyp_host_forward_smc(host_ctxt);
trace_hyp_enter(host_ctxt, HYP_REASON_SMC);
--
2.47.3
prev parent reply other threads:[~2026-11-17 16:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 16:36 [PATCH v2 0/2] KVM: arm64: Fixes for the host SMCs that pKVM forwards to firmware Fuad Tabba
2026-11-17 16:37 ` [PATCH v2 1/2] KVM: arm64: Don't forward the host's SDEI calls " Fuad Tabba
2026-11-17 16:37 ` Fuad Tabba [this message]
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=20261117163702.1678277-3-fuad.tabba@linux.dev \
--to=fuad.tabba@linux.dev \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--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=oupton@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--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
all inboxes | Powered by JetHome®