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

Marc Zyngier maz at kernel.org
Thu Jun 18 03:10:11 PDT 2026


On Fri, 12 Jun 2026 07:59:24 +0100,
tabba at google.com wrote:
> 
> From: Marc Zyngier <maz at 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 at kernel.org>
> Co-developed-by: Fuad Tabba <tabba at google.com>
> Signed-off-by: Fuad Tabba <tabba at 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).

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list