linux/arch/arm64/kvm
Fuad Tabba bce3847f7c KVM: arm64: Fix ID register initialization for non-protected pKVM guests
[ Upstream commit 7e7c2cf002 ]

In protected mode, the hypervisor maintains a separate instance of
the `kvm` structure for each VM. For non-protected VMs, this structure is
initialized from the host's `kvm` state.

Currently, `pkvm_init_features_from_host()` copies the
`KVM_ARCH_FLAG_ID_REGS_INITIALIZED` flag from the host without the
underlying `id_regs` data being initialized. This results in the
hypervisor seeing the flag as set while the ID registers remain zeroed.

Consequently, `kvm_has_feat()` checks at EL2 fail (return 0) for
non-protected VMs. This breaks logic that relies on feature detection,
such as `ctxt_has_tcrx()` for TCR2_EL1 support. As a result, certain
system registers (e.g., TCR2_EL1, PIR_EL1, POR_EL1) are not
saved/restored during the world switch, which could lead to state
corruption.

Fix this by explicitly copying the ID registers from the host `kvm` to
the hypervisor `kvm` for non-protected VMs during initialization, since
we trust the host with its non-protected guests' features. Also ensure
`KVM_ARCH_FLAG_ID_REGS_INITIALIZED` is cleared initially in
`pkvm_init_features_from_host` so that `vm_copy_id_regs` can properly
initialize them and set the flag once done.

Fixes: 41d6028e28 ("KVM: arm64: Convert the SVE guest vcpu flag to a vm flag")
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260213143815.1732675-4-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-03-12 07:09:08 -04:00
..
hyp KVM: arm64: Fix ID register initialization for non-protected pKVM guests 2026-03-12 07:09:08 -04:00
vgic KVM: arm64: vgic-v3: Release reserved slot outside of lpi_xa's lock 2025-11-08 11:19:32 +00:00
.gitignore KVM: arm64: Generate hyp_constants.h for the host 2021-12-06 08:37:03 +00:00
arch_timer.c KVM: arm64: Kill leftovers of ad-hoc timer userspace access 2025-10-13 14:42:41 +01:00
arm.c KVM: arm64: VHE: Compute fgt traps before activating them 2025-11-12 10:52:58 +00:00
at.c KVM: arm64: Remove unreachable break after return 2025-10-13 14:17:03 +01:00
config.c KVM: arm64: nv: Use FGT write trap of MDSCR_EL1 when available 2025-10-13 14:44:37 +01:00
debug.c KVM: arm64: Guard PMSCR_EL1 initialization with SPE presence check 2025-10-13 14:26:36 +01:00
emulate-nested.c KVM: arm64: nv: Return correct RES0 bits for FGT registers 2026-03-04 07:21:12 -05:00
fpsimd.c KVM: arm64: Remove kvm_arch_vcpu_run_map_fp() 2025-07-03 10:39:24 +01:00
guest.c KVM: arm64: Kill leftovers of ad-hoc timer userspace access 2025-10-13 14:42:41 +01:00
handle_exit.c KVM: arm64: Fix WFxT handling of nested virt 2025-10-13 14:42:41 +01:00
hypercalls.c arm64: kvm, smccc: Introduce and use API for getting hypervisor UUID 2025-05-23 16:30:55 +00:00
inject_fault.c KVM: arm64: Populate level on S1PTW SEA injection 2025-09-20 11:05:14 +01:00
Kconfig hyperv-next for v6.18 2025-10-07 08:40:15 -07:00
Makefile KVM: arm64: gic-v5: Probe for GICv5 2025-07-08 14:41:06 -07:00
mmio.c KVM: arm64: Don't retire MMIO instruction w/ pending (emulated) SError 2025-07-08 11:36:36 -07:00
mmu.c KVM/arm64 updates for 6.18 2025-09-30 13:23:28 -04:00
nested.c KVM: arm64: nv: Use FGT write trap of MDSCR_EL1 when available 2025-10-13 14:44:37 +01:00
pauth.c KVM: arm64: nv: Work around lack of pauth support in old toolchains 2024-04-23 19:27:11 +01:00
pkvm.c KVM/arm64 updates for 6.18 2025-09-30 13:23:28 -04:00
pmu-emul.c KVM: arm64: Add RMW specific sysreg accessor 2025-06-05 14:18:01 +01:00
pmu.c KVM: arm64: Use a cpucap to determine if system supports FEAT_PMUv3 2025-03-11 12:54:23 -07:00
psci.c KVM: arm64: Add support for PSCI v1.2 and v1.3 2024-10-24 16:38:07 -07:00
ptdump.c KVM: arm64: ptdump: Don't test PTE_VALID alongside other attributes 2025-09-08 20:01:21 +01:00
pvtime.c KVM: MMU: Make the definition of 'INVALID_GPA' common 2023-01-19 21:48:38 +00:00
reset.c KVM: arm64: nv: Add pseudo-TLB backing VNCR_EL2 2025-05-19 07:59:46 +01:00
stacktrace.c arm64: kvm: Introduce nvhe stack size constants 2025-01-08 11:25:28 +00:00
sys_regs.c KVM: arm64: Hide S1POE from guests when not supported by the host 2026-03-12 07:09:08 -04:00
sys_regs.h KVM: arm64: Add timer UAPI workaround to sysreg infrastructure 2025-10-13 14:42:40 +01:00
trace.h KVM: arm64: Move virt/kvm/arm to arch/arm64 2020-05-16 15:03:59 +01:00
trace_arm.h KVM: arm64: Replace ternary flags with str_on_off() helper 2025-05-06 09:38:37 +01:00
trace_handle_exit.h arm64: kvm: trace_handle_exit: use string choices helper 2025-07-23 23:36:55 -07:00
trng.c KVM: arm64: Implement the TRNG hypervisor call 2021-01-25 22:19:31 +00:00
va_layout.c arm64: alternatives: kvm: prepare for cap changes 2022-09-16 17:15:02 +01:00
vgic-sys-reg-v3.c KVM: arm64: Enforce the sorting of the GICv3 system register table 2025-07-26 08:36:58 -07:00
vmid.c KVM: arm64: Ensure a VMID is allocated before programming VTTBR_EL2 2025-02-20 16:29:28 +00:00