[RFC PATCH v7 13/28] KVM: arm64: Add SPE VCPU device attribute to set the SPE device
Alexandru Elisei
alexandru.elisei at arm.com
Tue Dec 1 09:36:05 PST 2026
Hi,
While I was refactoring the patch, I reconsidered some things, below.
On Fri, Nov 27, 2026 at 03:10:28PM +0000, Alexandru Elisei wrote:
> Hi Lorenzo,
>
> On Wed, Oct 28, 2026 at 01:11:54PM +0000, Lorenzo Stoakes (ARM) wrote:
> > On Thu, Sep 03, 2026 at 05:06:08PM +0100, Alexandru Elisei wrote:
> > > [..]
> > > diff --git a/arch/arm64/include/asm/kvm_spe.h b/arch/arm64/include/asm/kvm_spe.h
> > > index 8ded2d821bff..b8afb419c851 100644
> > > --- a/arch/arm64/include/asm/kvm_spe.h
> > > +++ b/arch/arm64/include/asm/kvm_spe.h
> > > @@ -11,6 +11,11 @@ struct kvm_vcpu;
> > > struct kvm_device_attr;
> > >
> > > #ifdef CONFIG_KVM_ARM_SPE
> > > +struct arm_spe_pmu;
> > > +struct kvm_spe {
> > > + struct arm_spe_pmu *spe_pmu;
> >
> > I feel like 'spe_pmu' as a name is pretty confusing as there is PMU as
> > regards the perf driver thing, which SPE is implemented as, and also the
> > general PMUv3 architecture :)
> >
> > Maybe the _pmu suffix makes sense then on the type (which has to be a
> > performance monitoring unit driver), but could we replace '_pmu' with
> > '_instance' in the field, etc. names?
>
> The driver that KVM depends on calls it a spe_pmu, and this comes directly from
> the driver. I think the name is appropriate.
I have settled on calling it spe_dev and started replacing all references to SPE
'instance' with 'device': that's what it is from the kernel's point of view, and
the device lives under /sys/devices, where userspace interacts with it.
> > > [..]
> > > diff --git a/arch/arm64/kvm/spe.c b/arch/arm64/kvm/spe.c
> > > index dd5f80318ba4..87fcdbbcbd67 100644
> > > --- a/arch/arm64/kvm/spe.c
> > > +++ b/arch/arm64/kvm/spe.c
> > > +static int kvm_spe_set_spe_id(struct kvm_vcpu *vcpu, int spe_id)
> > > +{
> > > + struct kvm *kvm = vcpu->kvm;
> > > + struct kvm_spe *kvm_spe = &kvm->arch.kvm_spe;
> > > + struct arm_spe_pmu *existing_spe_pmu, *spe_pmu = NULL;
> > > + struct spe_pmu_entry *entry;
> > > +
> > > + if (kvm_vm_has_ran_once(kvm))
> > > + return -EBUSY;
> > > +
> > > + guard(mutex)(&spe_pmus_lock);
> > > +
> > > + list_for_each_entry(entry, &spe_pmus, link) {
> > > + if (entry->spe_pmu->pmu.type == spe_id) {
> > > + spe_pmu = entry->spe_pmu;
> > > + break;
> > > + }
> > > + }
> > > +
> > > + if (!spe_pmu)
> > > + return -ENXIO;
> > > +
> > > + existing_spe_pmu = kvm_spe->spe_pmu;
> > > + if (existing_spe_pmu) {
> > > + if (existing_spe_pmu != spe_pmu)
> > > + return -EINVAL;
> > > + return 0;
> > > + }
> > > +
> > > + if (!try_module_get(spe_pmu->pmu.module))
> > > + return -ENXIO;
> > > +
> > > + if (kvm_spe_update_supported_cpus(kvm, &spe_pmu->supported_cpus)) {
> >
> > You're ignoring the error here, better to do:
>
> I'm not ignoring the error, I am deliberately choosing to return -EINVAL to
> userspace, as per the documentation, instead of propagating the error code from
> the internal function.
I reconsidered this, and documented -ENOMEM as a possible return return code for
the ioctl.
Thanks,
Alex
More information about the linux-arm-kernel
mailing list