[RFC PATCH v7 12/28] KVM: arm64: Add SPE VCPU device attribute to set the interrupt number

Alexandru Elisei alexandru.elisei at arm.com
Fri Nov 27 07:07:15 PST 2026


Hi Suzuki,

On Wed, Oct 28, 2026 at 04:52:53PM +0000, Suzuki K Poulose wrote:
> On 03/09/2026 17:06, Alexandru Elisei wrote:
> > From: Sudeep Holla <sudeep.holla at arm.com>
> > 
> > Add KVM_ARM_VCPU_SPE_CTRL(KVM_ARM_VCPU_SPE_IRQ) to allow the user to set
> > the interrupt number for the buffer management interrupt.
> > 
> > [ Alexandru E: Split from "KVM: arm64: Add a new VCPU device control group
> >                 for SPE" ]
> > 
> > Signed-off-by: Sudeep Holla <sudeep.holla at arm.com>
> > Signed-off-by: Alexandru Elisei <alexandru.elisei at arm.com>
> > ---
> 
> ...
> 
> > diff --git a/arch/arm64/kvm/spe.c b/arch/arm64/kvm/spe.c
> > index fe45ad4c703a..dd5f80318ba4 100644
> > --- a/arch/arm64/kvm/spe.c
> > +++ b/arch/arm64/kvm/spe.c
> > @@ -59,17 +59,99 @@ bool kvm_supports_spe(void)
> >   	return !list_empty(&spe_pmus);
> >   }
> 
> ...
> 
> >   int kvm_spe_get_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
> >   {
> > +	struct kvm_vcpu_spe *vcpu_spe = &vcpu->arch.vcpu_spe;
> > +	struct kvm *kvm = vcpu->kvm;
> > +
> > +	if (!vcpu_has_spe(vcpu))
> > +		return -ENODEV;
> > +
> > +	switch (attr->attr) {
> > +	case KVM_ARM_VCPU_SPE_IRQ: {
> > +		int __user *uaddr = (int __user *)(long)attr->addr;
> > +		int irq;
> > +
> > +		if (!irqchip_in_kernel(kvm))
> > +			return -EINVAL;
> > +
> > +		if (!vcpu_spe->irq_num)
> > +			return -ENXIO;
> > +
> > +		irq = vcpu_spe->irq_num;
> > +		if (put_user(irq, uaddr))
> > +			return -EFAULT;
> > +
> > +		return 0;
> > +	}
> > +	}
> > +
> >   	return -ENXIO;
> >   }
> >   int kvm_spe_has_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
> >   {
> > +	if (!vcpu_has_spe(vcpu))
> > +		return -ENODEV;
> > +
> > +	switch(attr->attr) {
> > +	case KVM_ARM_VCPU_SPE_IRQ:
> > +		return 0;
> 
> Should we gate this too on irqchip_in_kernel(vcpu->kvm) ? Otherwise
> we would advertise to the userspace that it has the SPE_IRQ, but
> would return -EINVAL when we try get_attr if the irqchip is not
> in kernel.

>From Documentation/virt/kvm/api.rst:

4.81 KVM_HAS_DEVICE_ATTR
------------------------
[..]
A successful return indicates the attribute is implemented.  It does not
necessarily indicate that the attribute can be read or written in the
device's current state.  "addr" is ignored.

I think my implementation adheres to the documentation? Unless you have a
specific use case in mind?

> 
> Also, do we need to mandate the ordering of the SPE configuration on
> VGIC ?

That doesn't seem to be an issue for the PMU?

Thanks,
Alex



More information about the linux-arm-kernel mailing list