From: Marc Zyngier <maz@kernel.org>
To: Zenghui Yu <yuzenghui@huawei.com>
Cc: <kvmarm@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>,
<kvm@vger.kernel.org>, James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Joey Gouly <joey.gouly@arm.com>,
Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>,
Xu Zhao <zhaoxu.35@bytedance.com>,
Eric Auger <eric.auger@redhat.com>
Subject: Re: [PATCH v2 01/11] KVM: arm64: vgic: Make kvm_vgic_inject_irq() take a vcpu pointer
Date: Thu, 21 Sep 2023 12:20:02 +0100 [thread overview]
Message-ID: <8634z7pycd.wl-maz@kernel.org> (raw)
In-Reply-To: <c511ff67-fd8c-6edd-8239-2bacc3ad16f6@huawei.com>
On Thu, 21 Sep 2023 10:11:00 +0100,
Zenghui Yu <yuzenghui@huawei.com> wrote:
>
> On 2023/9/21 2:17, Marc Zyngier wrote:
> > Passing a vcpu_id to kvm_vgic_inject_irq() is silly for two reasons:
> >
> > - we often confuse vcpu_id and vcpu_idx
> > - we eventually have to convert it back to a vcpu
> > - we can't count
> >
> > Instead, pass a vcpu pointer, which is unambiguous. A NULL vcpu
> > is also allowed for interrupts that are not private to a vcpu
> > (such as SPIs).
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > arch/arm64/kvm/arch_timer.c | 2 +-
> > arch/arm64/kvm/arm.c | 20 ++++++++++----------
> > arch/arm64/kvm/pmu-emul.c | 2 +-
> > arch/arm64/kvm/vgic/vgic-irqfd.c | 2 +-
> > arch/arm64/kvm/vgic/vgic.c | 12 +++++-------
> > include/kvm/arm_vgic.h | 4 ++--
> > 6 files changed, 20 insertions(+), 22 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> > index 6dcdae4d38cb..1f828f3b854c 100644
> > --- a/arch/arm64/kvm/arch_timer.c
> > +++ b/arch/arm64/kvm/arch_timer.c
> > @@ -458,7 +458,7 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
> > timer_ctx->irq.level);
> > if (!userspace_irqchip(vcpu->kvm)) {
> > - ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu->vcpu_id,
> > + ret = kvm_vgic_inject_irq(vcpu->kvm, vcpu,
> > timer_irq(timer_ctx),
> > timer_ctx->irq.level,
> > timer_ctx);
> > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > index 4866b3f7b4ea..872679a0cbd7 100644
> > --- a/arch/arm64/kvm/arm.c
> > +++ b/arch/arm64/kvm/arm.c
> > @@ -1134,27 +1134,27 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
> > bool line_status)
> > {
> > u32 irq = irq_level->irq;
> > - unsigned int irq_type, vcpu_idx, irq_num;
> > + unsigned int irq_type, vcpu_id, irq_num;
> > int nrcpus = atomic_read(&kvm->online_vcpus);
> > struct kvm_vcpu *vcpu = NULL;
> > bool level = irq_level->level;
> > irq_type = (irq >> KVM_ARM_IRQ_TYPE_SHIFT) &
> > KVM_ARM_IRQ_TYPE_MASK;
> > - vcpu_idx = (irq >> KVM_ARM_IRQ_VCPU_SHIFT) & KVM_ARM_IRQ_VCPU_MASK;
> > - vcpu_idx += ((irq >> KVM_ARM_IRQ_VCPU2_SHIFT) & KVM_ARM_IRQ_VCPU2_MASK) * (KVM_ARM_IRQ_VCPU_MASK + 1);
> > + vcpu_id = (irq >> KVM_ARM_IRQ_VCPU_SHIFT) & KVM_ARM_IRQ_VCPU_MASK;
> > + vcpu_id += ((irq >> KVM_ARM_IRQ_VCPU2_SHIFT) & KVM_ARM_IRQ_VCPU2_MASK) * (KVM_ARM_IRQ_VCPU_MASK + 1);
> > irq_num = (irq >> KVM_ARM_IRQ_NUM_SHIFT) & KVM_ARM_IRQ_NUM_MASK;
> > - trace_kvm_irq_line(irq_type, vcpu_idx, irq_num,
> > irq_level->level);
> > + trace_kvm_irq_line(irq_type, vcpu_id, irq_num, irq_level->level);
> > switch (irq_type) {
> > case KVM_ARM_IRQ_TYPE_CPU:
> > if (irqchip_in_kernel(kvm))
> > return -ENXIO;
> > - if (vcpu_idx >= nrcpus)
> > + if (vcpu_id >= nrcpus)
> > return -EINVAL;
>
> What we actually need to check is 'vcpu->vcpu_idx >= nrcpus' and this is
> covered by the 'if (!vcpu)' statement below. Let's just drop this
> _incorrect_ checking?
Good point. Let me fix this.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-09-21 11:20 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-20 18:17 [PATCH v2 00/11] KVM: arm64: Accelerate lookup of vcpus by MPIDR values (and other fixes) Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 01/11] KVM: arm64: vgic: Make kvm_vgic_inject_irq() take a vcpu pointer Marc Zyngier
2023-09-21 9:11 ` Zenghui Yu
2023-09-21 11:20 ` Marc Zyngier [this message]
2023-09-20 18:17 ` [PATCH v2 02/11] KVM: arm64: vgic-its: Treat the collection target address as a vcpu_id Marc Zyngier
2023-09-21 9:14 ` Zenghui Yu
2023-09-21 11:46 ` Marc Zyngier
2023-09-21 13:12 ` Zenghui Yu
2023-09-20 18:17 ` [PATCH v2 03/11] KVM: arm64: vgic-v3: Refactor GICv3 SGI generation Marc Zyngier
2023-09-21 9:42 ` Joey Gouly
2023-09-21 11:13 ` Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 04/11] KVM: arm64: vgic-v2: Use cpuid from userspace as vcpu_id Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 05/11] KVM: arm64: vgic: Use vcpu_idx for the debug information Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 06/11] KVM: arm64: Use vcpu_idx for invalidation tracking Marc Zyngier
2023-09-21 9:16 ` Zenghui Yu
2023-09-21 12:58 ` Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 07/11] KVM: arm64: Simplify kvm_vcpu_get_mpidr_aff() Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 08/11] KVM: arm64: Build MPIDR to vcpu index cache at runtime Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 09/11] KVM: arm64: Fast-track kvm_mpidr_to_vcpu() when mpidr_data is available Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 10/11] KVM: arm64: vgic-v3: Optimize affinity-based SGI injection Marc Zyngier
2023-09-21 9:32 ` Zenghui Yu
2023-09-20 18:17 ` [PATCH v2 11/11] KVM: arm64: Clarify the ordering requirements for vcpu/RD creation Marc Zyngier
2023-09-21 2:11 ` [PATCH v2 00/11] KVM: arm64: Accelerate lookup of vcpus by MPIDR values (and other fixes) Oliver Upton
2023-09-21 9:39 ` Zenghui Yu
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=8634z7pycd.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=eric.auger@redhat.com \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oliver.upton@linux.dev \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
--cc=zhaoxu.35@bytedance.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).