From: Sasha Levin <sashal@kernel.org>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>
Cc: Fuad Tabba <fuad.tabba@linux.dev>,
Paolo Bonzini <pbonzini@redhat.com>,
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>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Sasha Levin <sashal@kernel.org>
Subject: [PATCH] KVM: arm64: Take a protected vCPU's TWI and TWE only at vCPU load
Date: Sat, 17 Oct 2026 12:52:04 -0400 [thread overview]
Message-ID: <20261017165204.3343275-1-sashal@kernel.org> (raw)
In-Reply-To: <20261014162126.964330-1-maz@kernel.org>
Commit 06499de8f998 ("KVM: arm64: Skip fixed-feature state flush for
protected vCPUs") moved the copy of the host's TWI and TWE in
flush_hyp_vcpu() into the non-protected branch: a protected vCPU takes
them in __pkvm_vcpu_load() instead, and only VSE comes from the host on
each entry.
Commit 04447b95c62b ("KVM: arm64: Use the host's HCR_EL2 for
non-protected VMs in pKVM") was written against the old code, where
both VM types took TWI, TWE and VSE on each entry, and kept that for a
protected VM as PKVM_HCR_EL2_HOST_PVM. The merge of the two applies
PKVM_HCR_EL2_HOST_PVM in the common path, so a protected vCPU takes TWI
and TWE from the host's vCPU on every entry again.
That doesn't change what a protected guest runs with today: once the
vCPU is initialised, the host only changes TWI and TWE in
vcpu_set_wfx_traps(), which pkvm_vcpu_load() calls right before
__pkvm_vcpu_load(). But it undoes part of 06499de8f998, and has EL2
read a protected vCPU's trap configuration from host memory on every
entry, which nothing needs.
Make PKVM_HCR_EL2_HOST_PVM VSE alone and add TWI and TWE to
PKVM_HCR_EL2_HOST_NPVM, so that each mask again lists what EL2 takes
from the host on each entry for its VM type. A non-protected VM takes
the same bits as before. Say in the comments that a protected vCPU's
TWI and TWE come at vCPU load.
llminus, an LLM-assisted merge conflict resolution tool, found the
difference while resolving the same conflict in an integration tree.
Fixes: 439d8f9cb01c ("Merge tag 'kvmarm-7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD")
Assisted-by: LLM
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
With KVM's own host code this changes nothing a guest can observe: the
per-entry copy writes back the TWI/TWE value __pkvm_vcpu_load() already
set. It restores the split 06499de8f998 made.
Marc's resolution in kvmarm/fixes, aca73c1d23f1 ("Merge branch
kvmarm-7.4 into kvmarm-master/fixes"), is the same as the one in
kvm/next, so this applies to both.
Build-tested only: arm64 defconfig with gcc and clang, W=1, no new
warnings. The only code generation change is the protected vCPU's
per-entry mask, 0x6100 to 0x100. Not runtime-tested, as the in-tree
selftests can't create protected VMs.
arch/arm64/kvm/hyp/include/nvhe/pkvm.h | 13 +++++++------
arch/arm64/kvm/hyp/nvhe/pkvm.c | 5 ++++-
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
index 4373e9b63e87f..0261b2bc681f7 100644
--- a/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
+++ b/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
@@ -14,13 +14,14 @@
#include <nvhe/spinlock.h>
/*
- * HCR_EL2 bits EL2 takes from the host on each entry, per VM type. The rest
- * are EL2's own and nothing the host sets there reaches the guest.
+ * HCR_EL2 bits EL2 takes from the host on each entry, per VM type. A protected
+ * VM also takes TWI and TWE, at vCPU load. The rest are EL2's own and nothing
+ * the host sets there reaches the guest.
*/
-#define PKVM_HCR_EL2_HOST_PVM (HCR_EL2_TWI | HCR_EL2_TWE | HCR_EL2_VSE)
-#define PKVM_HCR_EL2_HOST_NPVM (PKVM_HCR_EL2_HOST_PVM | HCR_EL2_VI | HCR_EL2_VF | \
- HCR_EL2_TVM | HCR_EL2_TID2 | HCR_EL2_TID4 | \
- HCR_EL2_TID5 | HCR_EL2_TTLBOS)
+#define PKVM_HCR_EL2_HOST_PVM HCR_EL2_VSE
+#define PKVM_HCR_EL2_HOST_NPVM (PKVM_HCR_EL2_HOST_PVM | HCR_EL2_TWI | HCR_EL2_TWE | \
+ HCR_EL2_VI | HCR_EL2_VF | HCR_EL2_TVM | HCR_EL2_TID2 | \
+ HCR_EL2_TID4 | HCR_EL2_TID5 | HCR_EL2_TTLBOS)
/*
* Holds the relevant data for maintaining the vcpu state completely at hyp.
diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
index 237483d2442a5..fc0475f0877d1 100644
--- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
+++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
@@ -38,7 +38,10 @@ unsigned int kvm_host_sve_max_vl;
*/
static DEFINE_PER_CPU(struct pkvm_hyp_vcpu *, loaded_hyp_vcpu);
-/* The PKVM_HCR_EL2_HOST_{PVM,NPVM} bits of this value come from the host on each entry. */
+/*
+ * The PKVM_HCR_EL2_HOST_{PVM,NPVM} bits of this value come from the host on
+ * each entry, and a protected vCPU's TWI and TWE at vCPU load.
+ */
static void pkvm_vcpu_reset_hcr(struct kvm_vcpu *vcpu)
{
vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
base-commit: 2ea3a929fe01ec5ae7313a94badaf9b70a8c69b1
--
2.53.0
prev parent reply other threads:[~2026-10-17 16:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 16:21 [GIT PULL] KVM/arm64 updates for Linux 7.4 Marc Zyngier
2026-10-14 16:30 ` Paolo Bonzini
2026-10-14 16:52 ` Marc Zyngier
2026-10-14 16:56 ` Paolo Bonzini
2026-10-14 17:05 ` Marc Zyngier
2026-10-17 16:52 ` Sasha Levin [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=20261017165204.3343275-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--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=pbonzini@redhat.com \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.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