* [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs
@ 2025-08-07 12:01 Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 1/3] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host " Fuad Tabba
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Fuad Tabba @ 2025-08-07 12:01 UTC (permalink / raw)
To: kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, will, joey.gouly, suzuki.poulose, yuzenghui,
catalin.marinas, vdonnefort, qperret, sebastianene, keirf,
smostafa, tabba
This patch series mainly fixes issues we've encountered in pKVM (in
downstream Android code), related to the handling of protected VM access
to restricted registers and injecting undefined exceptions into a
protected guest.
The last patch in this series isn't pKVM specific, but a fix to the
vgic-v2 code encountered while fixing the issues in this series. The
issue it fixes was indirectly introduced into the code with hVHE.
Changes from v1 [1]:
- Dropped the refactoring patch.
- Added Reported-by tags.
Based on Linux 6.16.
Cheers,
/fuad
[1] https://lore.kernel.org/all/20250805135617.831971-1-tabba@google.com/
Fuad Tabba (3):
KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host for protected VMs
KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef
exception
arm64: vgic-v2: Fix guest endianness check in hVHE mode
arch/arm64/kvm/hyp/nvhe/sys_regs.c | 5 +++++
arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
base-commit: 038d61fd642278bab63ee8ef722c50d10ab01e8f
--
2.50.1.565.gc32cd1483b-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host for protected VMs
2025-08-07 12:01 [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Fuad Tabba
@ 2025-08-07 12:01 ` Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 2/3] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception Fuad Tabba
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Fuad Tabba @ 2025-08-07 12:01 UTC (permalink / raw)
To: kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, will, joey.gouly, suzuki.poulose, yuzenghui,
catalin.marinas, vdonnefort, qperret, sebastianene, keirf,
smostafa, tabba
Since commit 17efc1acee62 ("arm64: Expose AIDR_EL1 via sysfs"), AIDR_EL1
is read early during boot. Therefore, a guest running as a protected VM
will fail to boot because when it attempts to access AIDR_EL1, access to
that register is restricted in pKVM for protected guests.
Similar to how MIDR_EL1 is handled by the host for protected VMs, let
the host handle accesses to AIDR_EL1 as well as REVIDR_EL1. However note
that, unlike MIDR_EL1, AIDR_EL1 and REVIDR_EL1 are trapped by
HCR_EL2.TID1. Therefore, explicitly mark them as handled by the host for
protected VMs. TID1 is always set in pKVM, because it needs to restrict
access to SMIDR_EL1, which is also trapped by that bit.
Reported-by: Will Deacon <will@kernel.org>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
arch/arm64/kvm/hyp/nvhe/sys_regs.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
index 1ddd9ed3cbb3..bbd60013cf9e 100644
--- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c
+++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
@@ -372,6 +372,9 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {
/* Debug and Trace Registers are restricted. */
+ /* Group 1 ID registers */
+ HOST_HANDLED(SYS_REVIDR_EL1),
+
/* AArch64 mappings of the AArch32 ID registers */
/* CRm=1 */
AARCH32(SYS_ID_PFR0_EL1),
@@ -460,6 +463,7 @@ static const struct sys_reg_desc pvm_sys_reg_descs[] = {
HOST_HANDLED(SYS_CCSIDR_EL1),
HOST_HANDLED(SYS_CLIDR_EL1),
+ HOST_HANDLED(SYS_AIDR_EL1),
HOST_HANDLED(SYS_CSSELR_EL1),
HOST_HANDLED(SYS_CTR_EL0),
--
2.50.1.565.gc32cd1483b-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception
2025-08-07 12:01 [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 1/3] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host " Fuad Tabba
@ 2025-08-07 12:01 ` Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 3/3] arm64: vgic-v2: Fix guest endianness check in hVHE mode Fuad Tabba
2025-08-08 17:51 ` [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Oliver Upton
3 siblings, 0 replies; 5+ messages in thread
From: Fuad Tabba @ 2025-08-07 12:01 UTC (permalink / raw)
To: kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, will, joey.gouly, suzuki.poulose, yuzenghui,
catalin.marinas, vdonnefort, qperret, sebastianene, keirf,
smostafa, tabba
In pKVM, a race condition can occur if a guest updates its VBAR_EL1
register and, before a vCPU exit synchronizes this change, the
hypervisor needs to inject an undefined exception into a protected
guest.
In this scenario, the vCPU still holds the stale VBAR_EL1 value from
before the guest's update. When pKVM injects the exception, it ends up
using the stale value.
Explicitly read the live value of VBAR_EL1 from the guest and update the
vCPU value immediately before pending the exception. This ensures the
vCPU's value is the same as the guest's and that the exception will be
handled at the correct address upon resuming the guest.
Reported-by: Keir Fraser <keirf@google.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
arch/arm64/kvm/hyp/nvhe/sys_regs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
index bbd60013cf9e..71d2fc97f004 100644
--- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c
+++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c
@@ -253,6 +253,7 @@ static void inject_undef64(struct kvm_vcpu *vcpu)
*vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
*vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR);
+ __vcpu_assign_sys_reg(vcpu, read_sysreg_el1(SYS_VBAR), VBAR_EL1);
kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
--
2.50.1.565.gc32cd1483b-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] arm64: vgic-v2: Fix guest endianness check in hVHE mode
2025-08-07 12:01 [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 1/3] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host " Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 2/3] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception Fuad Tabba
@ 2025-08-07 12:01 ` Fuad Tabba
2025-08-08 17:51 ` [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Oliver Upton
3 siblings, 0 replies; 5+ messages in thread
From: Fuad Tabba @ 2025-08-07 12:01 UTC (permalink / raw)
To: kvmarm, linux-arm-kernel
Cc: maz, oliver.upton, will, joey.gouly, suzuki.poulose, yuzenghui,
catalin.marinas, vdonnefort, qperret, sebastianene, keirf,
smostafa, tabba
In hVHE when running at the hypervisor, SCTLR_EL1 refers to the
hypervisor's System Control Register rather than the guest's. Make sure
to access the guest's register to determine its endianness.
Reported-by: Will Deacon <will@kernel.org>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c b/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
index 87a54375bd6e..78579b31a420 100644
--- a/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
+++ b/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
@@ -20,7 +20,7 @@ static bool __is_be(struct kvm_vcpu *vcpu)
if (vcpu_mode_is_32bit(vcpu))
return !!(read_sysreg_el2(SYS_SPSR) & PSR_AA32_E_BIT);
- return !!(read_sysreg(SCTLR_EL1) & SCTLR_ELx_EE);
+ return !!(read_sysreg_el1(SYS_SCTLR) & SCTLR_ELx_EE);
}
/*
--
2.50.1.565.gc32cd1483b-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs
2025-08-07 12:01 [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Fuad Tabba
` (2 preceding siblings ...)
2025-08-07 12:01 ` [PATCH v2 3/3] arm64: vgic-v2: Fix guest endianness check in hVHE mode Fuad Tabba
@ 2025-08-08 17:51 ` Oliver Upton
3 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2025-08-08 17:51 UTC (permalink / raw)
To: kvmarm, linux-arm-kernel, Fuad Tabba
Cc: Oliver Upton, maz, will, joey.gouly, suzuki.poulose, yuzenghui,
catalin.marinas, vdonnefort, qperret, sebastianene, keirf,
smostafa
On Thu, 07 Aug 2025 13:01:30 +0100, Fuad Tabba wrote:
> This patch series mainly fixes issues we've encountered in pKVM (in
> downstream Android code), related to the handling of protected VM access
> to restricted registers and injecting undefined exceptions into a
> protected guest.
>
> The last patch in this series isn't pKVM specific, but a fix to the
> vgic-v2 code encountered while fixing the issues in this series. The
> issue it fixes was indirectly introduced into the code with hVHE.
>
> [...]
Applied to fixes, thanks!
[1/3] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host for protected VMs
https://git.kernel.org/kvmarm/kvmarm/c/eaa43934b412
[2/3] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception
https://git.kernel.org/kvmarm/kvmarm/c/798eb5978700
[3/3] arm64: vgic-v2: Fix guest endianness check in hVHE mode
https://git.kernel.org/kvmarm/kvmarm/c/f1edb159200a
--
Best,
Oliver
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-08 17:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 12:01 [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 1/3] KVM: arm64: Handle AIDR_EL1 and REVIDR_EL1 in host " Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 2/3] KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception Fuad Tabba
2025-08-07 12:01 ` [PATCH v2 3/3] arm64: vgic-v2: Fix guest endianness check in hVHE mode Fuad Tabba
2025-08-08 17:51 ` [PATCH v2 0/3] KVM: arm64: Fixes to handling of restricted registers for protected VMs Oliver Upton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox