Thread (30 messages) 30 messages, 3 authors, 2026-06-18

Re: [PATCH v1 10/11] KVM: arm64: Add primitives to flush/sync the VGIC state at EL2

From: Fuad Tabba <tabba@google.com>
Date: 2026-06-18 10:18:35
Also in: kvmarm, lkml

On Thu, 18 Jun 2026 at 11:10, Marc Zyngier [off-list ref] wrote:
On Fri, 12 Jun 2026 07:59:24 +0100,
tabba@google.com wrote:
quoted
From: Marc Zyngier <maz@kernel.org>

pKVM performs its own world switch for protected VMs but has no
primitives to move the per-vCPU VGIC state between the host and
hypervisor vCPU contexts.

Add flush_hyp_vgic_state() and sync_hyp_vgic_state(). Flush copies
vgic_hcr, the in-use list registers and used_lrs from the host into the
hyp vCPU and pins vgic_sre to a fixed value; sync copies vgic_hcr,
vgic_vmcr and the in-use list registers back. The active priority
registers are handled separately by the save/restore-aprs path.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Co-developed-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
 arch/arm64/kvm/hyp/nvhe/hyp-main.c | 50 +++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
index 2f165b6c7b07..23e644c24a03 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
@@ -99,6 +99,46 @@ static void fpsimd_sve_sync(struct kvm_vcpu *vcpu)
      *host_data_ptr(fp_owner) = FP_STATE_HOST_OWNED;
 }

+static void flush_hyp_vgic_state(struct pkvm_hyp_vcpu *hyp_vcpu)
+{
+     struct kvm_vcpu *host_vcpu = hyp_vcpu->host_vcpu;
+     struct vgic_v3_cpu_if *host_cpu_if, *hyp_cpu_if;
+     unsigned int used_lrs, max_lrs, i;
+
+     host_cpu_if     = &host_vcpu->arch.vgic_cpu.vgic_v3;
+     hyp_cpu_if      = &hyp_vcpu->vcpu.arch.vgic_cpu.vgic_v3;
+
+     max_lrs         = (read_gicreg(ICH_VTR_EL2) & ICH_VTR_EL2_ListRegs) + 1;
This really needs to be rebased on the current state of kvmarm/next,
particularly 8cc8bbbfab14c ("KVM: arm64: Bound used_lrs when flushing
the pKVM hyp vCPU").

I really want to avoid using ICH_VTR_EL2 on each and every entry to
the guest, as this has really bad performance impacts when running
this under NV (which is the only way I run pKVM).
Will do.

Thanks,
/fuad
Thanks,

        M.

--
Without deviation from the norm, progress is not possible.
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help