linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Raghavendra Rao Ananta <rananta@google.com>
Cc: Oliver Upton <oliver.upton@linux.dev>,
	Mingwei Zhang <mizhang@google.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/4] KVM: arm64: Introduce attribute to control GICD_TYPER2.nASSGIcap
Date: Sat, 21 Jun 2025 09:50:48 +0100	[thread overview]
Message-ID: <87frftfpg7.wl-maz@kernel.org> (raw)
In-Reply-To: <20250613155239.2029059-4-rananta@google.com>

On Fri, 13 Jun 2025 16:52:37 +0100,
Raghavendra Rao Ananta <rananta@google.com> wrote:
> 
> KVM unconditionally advertises GICD_TYPER2.nASSGIcap (which internally
> implies vSGIs) on GICv4.1 systems. Allow userspace to change whether a
> VM supports the feature. Only allow changes prior to VGIC initialization
> as at that point vPEs need to be allocated for the VM.
> 
> For convenience, bundle support for vLPIs and vSGIs behind this feature,
> allowing userspace to control vPE allocation for VMs in environments
> that may be constrained on vPE IDs.
> 
> Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
>  .../virt/kvm/devices/arm-vgic-v3.rst          | 29 +++++++++++++++
>  arch/arm64/include/uapi/asm/kvm.h             |  3 ++
>  arch/arm64/kvm/vgic/vgic-init.c               |  3 ++
>  arch/arm64/kvm/vgic/vgic-kvm-device.c         | 37 +++++++++++++++++++
>  arch/arm64/kvm/vgic/vgic-mmio-v3.c            | 10 ++++-
>  arch/arm64/kvm/vgic/vgic-v3.c                 |  5 ++-
>  arch/arm64/kvm/vgic/vgic-v4.c                 |  2 +-
>  include/kvm/arm_vgic.h                        |  3 ++
>  8 files changed, 88 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/virt/kvm/devices/arm-vgic-v3.rst b/Documentation/virt/kvm/devices/arm-vgic-v3.rst
> index e860498b1e35..049d77eae591 100644
> --- a/Documentation/virt/kvm/devices/arm-vgic-v3.rst
> +++ b/Documentation/virt/kvm/devices/arm-vgic-v3.rst
> @@ -306,3 +306,32 @@ Groups:
>  
>      The vINTID specifies which interrupt is generated when the vGIC
>      must generate a maintenance interrupt. This must be a PPI.
> +
> +  KVM_DEV_ARM_VGIC_GRP_FEATURES
> +   Attributes:
> +
> +    KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap
> +      Control whether support for SGIs without an active state is exposed
> +      to the VM. attr->addr points to a __u8 value which indicates whether
> +      he feature is enabled / disabled.

s/he/the/

> +
> +      A value of 0 indicates that the feature is disabled. A nonzero value
> +      indicates that the feature is enabled.
> +
> +      This attribute can only be set prior to initializing the VGIC (i.e.
> +      KVM_DEV_ARM_VGIC_CTRL_INIT).
> +
> +      Support for SGIs without an active state depends on hardware support.
> +      Userspace can discover support for the feature by reading the
> +      attribute after creating a VGICv3. It is possible that
> +      KVM_DEV_ARM_VGIC_CTRL_INIT can later fail if this feature is enabled
> +      and KVM is unable to allocate GIC vPEs for the VM.

Can you please add a sentence about the default behaviour? We
currently rely on the GICv4.1 capabilities to be available by default,
and it'd be important to capture this.

> +
> +  Errors:
> +
> +    =======  ========================================================
> +    -ENXIO   Invalid attribute in attr->attr
> +    -EFAULT  Invalid user address in attr->addr
> +    -EBUSY   The VGIC has already been initialized
> +    -EINVAL  KVM doesn't support the requested feature setting
> +    =======  ========================================================
> diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
> index ed5f3892674c..41e9ce412afd 100644
> --- a/arch/arm64/include/uapi/asm/kvm.h
> +++ b/arch/arm64/include/uapi/asm/kvm.h
> @@ -417,6 +417,7 @@ enum {
>  #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO  7
>  #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8
>  #define KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ  9
> +#define KVM_DEV_ARM_VGIC_GRP_FEATURES 10
>  #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT	10
>  #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \
>  			(0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)
> @@ -429,6 +430,8 @@ enum {
>  #define   KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES	3
>  #define   KVM_DEV_ARM_ITS_CTRL_RESET		4
>  
> +#define   KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap	0
> +
>  /* Device Control API on vcpu fd */
>  #define KVM_ARM_VCPU_PMU_V3_CTRL	0
>  #define   KVM_ARM_VCPU_PMU_V3_IRQ		0
> diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
> index 5e0e4559004b..944e24750ac4 100644
> --- a/arch/arm64/kvm/vgic/vgic-init.c
> +++ b/arch/arm64/kvm/vgic/vgic-init.c
> @@ -157,6 +157,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
>  
>  	kvm->arch.vgic.in_kernel = true;
>  	kvm->arch.vgic.vgic_model = type;
> +	if (type == KVM_DEV_TYPE_ARM_VGIC_V3)
> +		kvm->arch.vgic.nassgicap = kvm_vgic_global_state.has_gicv4_1 &&
> +					   gic_cpuif_has_vsgi();
>  
>  	kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;
>  
> diff --git a/arch/arm64/kvm/vgic/vgic-kvm-device.c b/arch/arm64/kvm/vgic/vgic-kvm-device.c
> index e28cf68a49c3..629f56063a13 100644
> --- a/arch/arm64/kvm/vgic/vgic-kvm-device.c
> +++ b/arch/arm64/kvm/vgic/vgic-kvm-device.c
> @@ -626,6 +626,26 @@ static int vgic_v3_set_attr(struct kvm_device *dev,
>  		dev->kvm->arch.vgic.mi_intid = val;
>  		return 0;
>  	}
> +	case KVM_DEV_ARM_VGIC_GRP_FEATURES: {
> +		u8 __user *uaddr = (u8 __user *)attr->addr;
> +		u8 val;
> +
> +		if (attr->attr != KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap)
> +			return -ENXIO;
> +
> +		if (get_user(val, uaddr))
> +			return -EFAULT;
> +
> +		guard(mutex)(&dev->kvm->arch.config_lock);
> +		if (vgic_initialized(dev->kvm))
> +			return -EBUSY;
> +
> +		if (!(kvm_vgic_global_state.has_gicv4_1 && gic_cpuif_has_vsgi()) && val)
> +			return -EINVAL;
> +
> +		dev->kvm->arch.vgic.nassgicap = val;
> +		return 0;
> +	}
>  	default:
>  		return vgic_set_common_attr(dev, attr);
>  	}
> @@ -646,6 +666,17 @@ static int vgic_v3_get_attr(struct kvm_device *dev,
>  		guard(mutex)(&dev->kvm->arch.config_lock);
>  		return put_user(dev->kvm->arch.vgic.mi_intid, uaddr);
>  	}
> +	case KVM_DEV_ARM_VGIC_GRP_FEATURES: {
> +		u8 __user *uaddr = (u8 __user *)attr->addr;
> +		u8 val;
> +
> +		if (attr->attr != KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap)
> +			return -ENXIO;
> +
> +		guard(mutex)(&dev->kvm->arch.config_lock);
> +		val = dev->kvm->arch.vgic.nassgicap;
> +		return put_user(val, uaddr);
> +	}
>  	default:
>  		return vgic_get_common_attr(dev, attr);
>  	}
> @@ -683,8 +714,14 @@ static int vgic_v3_has_attr(struct kvm_device *dev,
>  			return 0;
>  		case KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES:
>  			return 0;
> +		default:
> +			return -ENXIO;
>  		}
> +	case KVM_DEV_ARM_VGIC_GRP_FEATURES:
> +		return attr->attr != KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap ?
> +		       -ENXIO : 0;

Do we really want to advertise KVM_DEV_ARM_VGIC_FEATURE_nASSGIcap even
when we don't have GICv4.1? This seems rather odd. My take on this API
is that this should report whether the feature is configurable, making
it backward compatible with older versions of KVM.

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.


  reply	other threads:[~2025-06-21  8:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-13 15:52 [PATCH v3 0/4] KVM: arm64: Add attribute to control GICD_TYPER2.nASSGIcap Raghavendra Rao Ananta
2025-06-13 15:52 ` [PATCH v3 1/4] KVM: arm64: Disambiguate support for vSGIs v. vLPIs Raghavendra Rao Ananta
2025-06-13 15:52 ` [PATCH v3 2/4] KVM: arm64: vgic-v3: Consolidate MAINT_IRQ handling Raghavendra Rao Ananta
2025-06-13 15:52 ` [PATCH v3 3/4] KVM: arm64: Introduce attribute to control GICD_TYPER2.nASSGIcap Raghavendra Rao Ananta
2025-06-21  8:50   ` Marc Zyngier [this message]
2025-06-23  8:40     ` Oliver Upton
2025-06-23  9:05       ` Marc Zyngier
2025-06-23  9:25         ` Oliver Upton
2025-06-23 14:37           ` Marc Zyngier
2025-06-13 15:52 ` [PATCH v3 4/4] KVM: arm64: selftests: Add test for nASSGIcap attribute Raghavendra Rao Ananta
2025-06-13 20:53 ` [PATCH v3 0/4] KVM: arm64: Add attribute to control GICD_TYPER2.nASSGIcap Oliver Upton
2025-06-13 21:25   ` Raghavendra Rao Ananta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87frftfpg7.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mizhang@google.com \
    --cc=oliver.upton@linux.dev \
    --cc=rananta@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).