[PATCH v2 10/16] KVM: arm64: gic-v5: Add ITS userspace register access

Wei-Lin Chang weilin.chang at arm.com
Thu Nov 5 21:00:07 PST 2026


On Mon, Nov 02, 2026 at 07:44:48PM +0000, Sascha Bischoff wrote:
> Userspace needs access to the emulated GICv5 ITS MMIO state in order
> to inspect and restore the device state around VM reset and migration.
> Expose the GICv5 ITS register frame through KVM_DEV_ARM_VGIC_GRP_ITS_REGS.
> 
> Reuse the same MMIO register descriptors used by the guest-facing
> IODEV, but apply the usual userspace access constraints: the ITS base
> address must have been configured, the register offset must map to an
> emulated ITS register, and userspace accesses must use the natural
> 32-bit or 64-bit register alignment.
> 
> Add control handling for KVM_DEV_ARM_ITS_CTRL_RESET. The reset is
> performed while all vCPUs are stopped and while holding the ITS lock,
> so it cannot race with guest MMIO updates or translation lookups. The
> reset clears guest-programmed state and cached translations while
> preserving the advertised ITS capability defaults.
> 
> Do not expose GICv5 ITS SAVE_TABLES or RESTORE_TABLES controls. For
> GICv5, the guest-owned DT and ITTs are the authoritative translation
> state, and the KVM translation cache is disposable state that can be
> rebuilt from guest memory.
> 
> Restore guest read-only IDR0-IDR2 through dedicated userspace writes,
> validating the advertised capabilities before changing them. Also
> allow userspace to restore READ_EVENT_DATAR while keeping guest writes
> to that result register ignored.
> 
> Signed-off-by: Sascha Bischoff <sascha.bischoff at arm.com>
> ---
>  arch/arm64/kvm/vgic/vgic-its-v5.c | 371 ++++++++++++++++++++++++++----
>  1 file changed, 322 insertions(+), 49 deletions(-)
> 
> diff --git a/arch/arm64/kvm/vgic/vgic-its-v5.c b/arch/arm64/kvm/vgic/vgic-its-v5.c
> index b69a1d107c0ae..638ee47f6e27d 100644
> --- a/arch/arm64/kvm/vgic/vgic-its-v5.c
> +++ b/arch/arm64/kvm/vgic/vgic-its-v5.c
> @@ -688,6 +688,70 @@ static void vgic_v5_mmio_write_its_misc(struct kvm *kvm, void *dev, gpa_t addr,
>  	}
>  }
>  
> +static int vgic_v5_uaccess_write_its_idr(struct kvm *kvm, void *dev,
> +					gpa_t addr, unsigned int len,
> +					unsigned long val)
> +{
> +	struct vgic_v5_its *its = dev;
> +	size_t offset = addr & (SZ_64K - 1);
> +	u64 mmfr0;
> +
> +	guard(mutex)(&its->its_lock);
> +
> +	switch (offset) {
> +	case GICV5_ITS_IDR0:
> +		if (FIELD_GET(GICV5_ITS_IDR0_DOM, val) !=
> +		    GICV5_ITS_IDR0_DOMAIN_NON_SECURE ||
> +		    (val & ~(GICV5_ITS_IDR0_ITSID |
> +			     GICV5_ITS_IDR0_PA_RANGE | GICV5_ITS_IDR0_DOM)))
> +			return -EINVAL;
> +
> +		mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
> +		if (FIELD_GET(GICV5_ITS_IDR0_PA_RANGE, val) >
> +		    cpuid_feature_extract_unsigned_field(mmfr0,
> +					ID_AA64MMFR0_EL1_PARANGE_SHIFT))
> +			return -EINVAL;
> +
> +		its->idr0.pa_range = FIELD_GET(GICV5_ITS_IDR0_PA_RANGE, val);

In addition to what Sashiko said, a pa_range change can also affect the
translation table walk, so I believe we should also invalidate the cache
here.

Thanks,
Wei-Lin Chang

> +		its->idr0.its_id = FIELD_GET(GICV5_ITS_IDR0_ITSID, val);
> +		return 0;
> +	case GICV5_ITS_IDR1:
> +		if ((val & ~(GICV5_ITS_IDR1_L2SZ |
> +			     GICV5_ITS_IDR1_ITT_LEVELS |
> +			     GICV5_ITS_IDR1_DT_LEVELS |
> +			     GICV5_ITS_IDR1_DEVICEID_BITS)) ||
> +		    FIELD_GET(GICV5_ITS_IDR1_DEVICEID_BITS, val) >
> +		    VITS_V5_DEVICE_ID_BITS)
> +			return -EINVAL;
> +
> +		/*
> +		 * Userspace can change the DeviceID limit after translations have
> +		 * been cached. Drop them so the old limit cannot remain in effect.
> +		 */
> +		if (its->idr1.device_id_bits !=
> +		    FIELD_GET(GICV5_ITS_IDR1_DEVICEID_BITS, val))
> +			its_cache_clear_translations(its);
> +
> +		its->idr1.device_id_bits = FIELD_GET(GICV5_ITS_IDR1_DEVICEID_BITS,
> +							 val);
> +		its->idr1.dt_levels = !!(val & GICV5_ITS_IDR1_DT_LEVELS);
> +		its->idr1.itt_levels = !!(val & GICV5_ITS_IDR1_ITT_LEVELS);
> +		its->idr1.l2sz = FIELD_GET(GICV5_ITS_IDR1_L2SZ, val);
> +		return 0;
> +	case GICV5_ITS_IDR2:
> +		if ((val & ~GICV5_ITS_IDR2_EVENTID_BITS) ||
> +		    FIELD_GET(GICV5_ITS_IDR2_EVENTID_BITS, val) >
> +		    VITS_V5_EVENT_ID_BITS)
> +			return -EINVAL;
> +
> +		its->idr2.event_id_bits = FIELD_GET(GICV5_ITS_IDR2_EVENTID_BITS,
> +							 val);
> +		return 0;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>  static void vgic_v5_write_its_dt_reg(struct vgic_v5_its *its, size_t offset,
>  				     unsigned long val)
>  {

[...]



More information about the linux-arm-kernel mailing list