From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409189; b=M1tMlzyLe2VUALj8M0wH4xbRSdT0D3pAWgHd1YJJuZZnJ8JkndYucg8S5MnPIBiITCO6 gQjds2I3AvwSnf86o7F+Zf9cnyWuFjzI23qDb2qvs0v3kaQwQ+OTXP10qWT6g4A1FTBV1 RjyF2NMvK7M9CxpK4nv0XnJ3Fl499rDJrV3NuU7L/AAXWxofAtZNF9rgPYr++lpsnK1vZ YFeUQt6us/mvAO9Sz0JRogcqRXcp9Oa7THn5vE6s5Pwvva6bHVZeJF7Yc/iiJI1lVhdKk KBcGJsgxJksxyUafXeToNngCP0w2tRje+eZ0+rdAj0O08eLxVJWH/wBUk8Jl1yk7Htg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409189; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=xT/h5Yq0zii0HdRG5cpM3Njd9fgaRdLBIdEzafr54UA=; b=X+9x6bVJru/5eemYNV+21kGeeTMsnoI4g+rzV/EW0QuKnVNCa8GED1/i2o71xiZ3D6dE WZuiFtgSq73DPNqiHEIcGWk23K7Ega4rhRssHUL28S6vR+W6YI2UrZyXkPgYLRWqepdfP 7ldPQaCyKNuVWX67SAkQX4c4PRFmFvzxH+HokxDclCjx69PmnEBvjI5+UfURFHRNTE8a5 t7uj9OWW/q8giAQyOo1kZw43MSq2mNqdgOCPXbfuwEv0adwGlzA/rlDOY0BGreyYdZJqk Qcd2hyNenNmhr7C7AissImUUb6JNz2ockHV7xR2u92v9SJQGGu2bQeVOqNyOfo7vx2A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="bp1a1/Nf"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3006606A322; Fri, 4 Dec 2026 18:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bp1a1/Nf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02D341F00A07; Fri, 4 Dec 2026 18:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409189; bh=xT/h5Yq0zii0HdRG5cpM3Njd9fgaRdLBIdEzafr54UA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bp1a1/NfcT/w9QNMsqBEFDejSGQrxFfDxSc1KJfmhxff+yp1TDlPADXOcbqIgcOIJ zPqjZxtTYLk4zGHCk9YrusQTl7ZTn97CLhvfzt4EiPln/olJf+Aopko070xtuG8c6i Ysl8PNTMfh23kzs0caCXT3QrgWAGwCtnjg4+RWtmfqAJgOsSkrbtOMSZNBO0AFbI82 QlL2j4MU4xLN1JplnUz71/izdVO3fzyyikPcs7m0H7bPVeaypoMC6C93sldjWUUBee gyK9723v8v+bFGrW9zlIUboHzSbQm0Gy1Cx9O41Noj62QT5lZI9VlWMnZbm+iIk1Ir FXYMz9VYD9s/A== Date: Fri, 4 Dec 2026 18:33:02 +0000 From: "Lorenzo Stoakes (ARM)" To: Alexandru Elisei Cc: maz@kernel.org, oupton@kernel.org, fuad.tabba@linux.dev, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, will@kernel.org, mark.rutland@arm.com, linux-perf-users@vger.kernel.org, catalin.marinas@arm.com, james.clark@linaro.org, Sudeep Holla Subject: Re: [RFC PATCH v7 12/28] KVM: arm64: Add SPE VCPU device attribute to set the interrupt number Message-ID: References: <20260903160623.315525-1-alexandru.elisei@arm.com> <20260903160623.315525-13-alexandru.elisei@arm.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Nov 27, 2026 at 03:06:45PM +0000, Alexandru Elisei wrote: (Thanks for all the above, trimming mail to make it easy to parse :) > > > 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); > > > } > > > > > > +static bool kvm_spe_irq_is_valid(struct kvm *kvm, int irq) > > > +{ > > > + struct kvm_vcpu *vcpu; > > > + struct kvm_vcpu_spe *vcpu_spe; > > > + unsigned long i; > > > + > > > > Maybe worth a small comment: > > > > /* Every vCPU must have either the same or no IRQ set. */ > > I think that's misleading, because someone reading that might get the idea > that it is allowed for a VCPU not to have an interrupt number set. I think > the documentation is enough. Fair point! :) > > > int kvm_spe_set_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; > > > + > > > + lockdep_assert_held(&kvm->arch.config_lock); > > > + > > > + 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 (get_user(irq, uaddr)) > > > + return -EFAULT; > > > + > > > + if (!irq_is_ppi(kvm, irq)) > > > + return -EINVAL; > > > + > > > + if (!kvm_spe_irq_is_valid(kvm, irq)) > > > + return -EINVAL; > > > > What about changing the IRQ for vcpu? kvm_spe_irq_is_valid() will abort > > even if only the current vCPU has an IRQ set. > > kvm_spe_irq_is_valid() aborts if userspace attempts to set a different > interrupt number than the number that has already been set on a VCPU, > including the one on which the ioctl is executing. In particular, if no > VCPU has an SPE interrupt number set, kvm_spe_irq_is_valid() returns true > (success). Right. > > The requirement is that all VCPUs have the same interrupt number configured > because (I would assume that) KVM doesn't want to have to deal with > heterogenous systems. Yeah, makes sense. > > As for why it cannot be changed to a different value once set: I am not > aware of any reason for userspace to do that - I assume that if there was > one, it would also apply to the PMU, and the PMU has a similar behaviour of > rejecting reassignment. Yeah, it doesn't seem sensible to want to change that! > > > > > Also what about the case of setting the current vCPU's IRQ to the same > > value? Should that be -EBUSY? > > > > PMU seems to do something like that, so maybe worth doing that for > > consistency? Not exactly a huge thing, that though! > > Good point. To be on the safe side, I'll just replicate it. I'll also move > irq_is_ppi() into kvm_spe_irq_is_valid(), because being a PPI is a > requirement for a valid interrupt number. Thanks! > > > > > Also looking at PMU there's: > > > > /* On GICv5, the PMUIRQ is architecturally mandated to be PPI 23 */ > > if (vgic_is_v5(kvm) && irq != KVM_ARMV8_PMU_GICV5_IRQ) > > return false; > > > > Is that something you have to worry about for SPE? > > Thanks for pointing it out, didn't know that GICv5 mandates interrupt > number assignments. It's 21 for PMBIRQ, will update accordingly. Thanks! Though I think there's a gotcha here as the GICv5 value seems to encode the IRQ number rather than just having the raw number, e.g. for the PMU value above: /* PPI #23 - architecturally specified for GICv5 */ #define KVM_ARMV8_PMU_GICV5_IRQ 0x20000017 Which is GICV5_HWIRQ_TYPE_PPI in GICV5_HWIRQ_TYPE (bits 31:29) + GICV5_ARCH_PPI_PMUIRQ. So SPE will need the equivalent for GICV5_ARCH_PPI_PMBIRQ (0x15). -- Cheers, Lorenzo