From: leixiang <leenollei@gmail.com>
To: Sean Christopherson <seanjc@google.com>
Cc: stable@vger.kernel.org, Madhavan Srinivasan <maddy@linux.ibm.com>,
Nicholas Piggin <npiggin@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Paul Mackerras <paulus@ozlabs.org>,
Suresh Warrier <warrier@linux.vnet.ibm.com>,
linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, leixiang <leixiang@kylinos.cn>
Subject: Re: [PATCH] KVM: Nullify irqfd->producer when add_producer() fails
Date: Thu, 9 Jul 2026 13:45:23 +0800 [thread overview]
Message-ID: <c12700ab-7f0c-452d-b8de-8e23ca48f1bd@gmail.com> (raw)
In-Reply-To: <ak59frQUBl9Gs3Qn@google.com>
On 7/9/26 00:40, Sean Christopherson wrote:
> On Mon, Jun 22, 2026, leixiang wrote:
>> The x86 and powerpc add_producer() callbacks set irqfd->producer before the
>> fallible setup and never clear it on error. The bypass manager doesn't
>> register a producer whose add_producer() failed -- producer->eventfd is
>> left NULL, so the later unregister early-returns and del_producer() is
>> never called -- so nothing ever drops the pointer.
>>
>> For VFIO PCI the producer is embedded in struct vfio_pci_irq_ctx and freed
>> when the vector is disabled, after which a routing update dereferences the
>> dangling pointer via kvm_arch_update_irqfd_routing().
>>
>> Nullify irqfd->producer on the error paths.
>>
>> Fixes: 77e1b8332d1d ("KVM: x86: Decouple device assignment from IRQ bypass")
>> Fixes: c57875f5f9be ("KVM: PPC: Book3S HV: Enable IRQ bypass")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: leixiang <leixiang@kylinos.cn>
>
> Please post the PPC patch as a separate patch. x86 and PPC are separate maintainer
> domains and the backports will likely need to go to different LTS kernels.
>
> I'll grab/extract the x86 change from here (and I'll massage the changelog as
> appropriate).
Thank you for the review and guidance. I will submit a separate PPC patch.
>> ---
>> arch/powerpc/kvm/book3s_hv.c | 4 +++-
>> arch/x86/kvm/irq.c | 4 +++-
>> 2 files changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>> index 61dbeea317f3..14919b76fb32 100644
>> --- a/arch/powerpc/kvm/book3s_hv.c
>> +++ b/arch/powerpc/kvm/book3s_hv.c
>> @@ -6114,9 +6114,11 @@ static int kvmppc_irq_bypass_add_producer_hv(struct irq_bypass_consumer *cons,
>> irqfd->producer = prod;
>>
>> ret = kvmppc_set_passthru_irq(irqfd->kvm, prod->irq, irqfd->gsi);
>> - if (ret)
>> + if (ret) {
>> pr_info("kvmppc_set_passthru_irq (irq %d, gsi %d) fails: %d\n",
>> prod->irq, irqfd->gsi, ret);
>> + irqfd->producer = NULL;
>> + }
>
> Unlike x86, AFAICT there's no need to set irqfd->producer before configuring
> the passthru/bypass stuff. So I think that fix could be this?
>
> diff --git arch/powerpc/kvm/book3s_hv.c arch/powerpc/kvm/book3s_hv.c
> index 61dbeea317f3..ff7b25629125 100644
> --- arch/powerpc/kvm/book3s_hv.c
> +++ arch/powerpc/kvm/book3s_hv.c
> @@ -6111,12 +6111,12 @@ static int kvmppc_irq_bypass_add_producer_hv(struct irq_bypass_consumer *cons,
> struct kvm_kernel_irqfd *irqfd =
> container_of(cons, struct kvm_kernel_irqfd, consumer);
>
> - irqfd->producer = prod;
> -
> ret = kvmppc_set_passthru_irq(irqfd->kvm, prod->irq, irqfd->gsi);
> if (ret)
> pr_info("kvmppc_set_passthru_irq (irq %d, gsi %d) fails: %d\n",
> prod->irq, irqfd->gsi, ret);
> + else
> + irqfd->producer = prod;
>
> return ret;
> }
Agreed. Your approach is cleaner.
next prev parent reply other threads:[~2026-07-09 5:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 7:51 [PATCH] KVM: Nullify irqfd->producer when add_producer() fails leixiang
2026-07-08 16:40 ` Sean Christopherson
2026-07-09 5:45 ` leixiang [this message]
2026-07-09 5:57 ` [PATCH] KVM: PPC: Book3S HV: Set irqfd->producer only on success leixiang
2026-07-09 7:39 ` Vaibhav Jain
2026-07-09 9:39 ` Amit Machhiwal
-- strict thread matches above, loose matches on Subject: below --
2026-06-22 7:51 [PATCH] KVM: Nullify irqfd->producer when add_producer() fails leixiang
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=c12700ab-7f0c-452d-b8de-8e23ca48f1bd@gmail.com \
--to=leenollei@gmail.com \
--cc=bp@alien8.de \
--cc=chleroy@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=leixiang@kylinos.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=paulus@ozlabs.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=warrier@linux.vnet.ibm.com \
--cc=x86@kernel.org \
/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