From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EA033ACA54 for ; Thu, 9 Jul 2026 05:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783575936; cv=none; b=qWQlMC5owuaxYq4GcwHatdS7ot7OR8LU16vTH4kCli/YhKDa+Poa9iTNOFf985wUeoJx89028xmKBlZDi7+rs5PkAvktg7gAdbCsBVqP1t4mVtYwEYQKo9AMC8l+ZxpKD+13pxzJA1lycBSIiGP20gArMnx0c5dst64zcvouBPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783575936; c=relaxed/simple; bh=mC3oLMXWAbMD/8ggRenIHpAwU32uiCLRqrKbrmFUo/M=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=aXi157ephSRcFKB2UFNJC1zzDVRs85XDOPvPQ3/D6p/DF7OvqZU/+PB2D8oCNVuiXlc81fDa8qJjRie/WrKAepTXteH9gHunh1HhU+intjeFiQddeoC7OsNIZjwPlBysiGA8oPctNuSVok307TNfVAbZjZ6vGuzPAPWwmuF4PoA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b+/b1Msi; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b+/b1Msi" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2c6b67d5fa1so5779695ad.2 for ; Wed, 08 Jul 2026 22:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783575934; x=1784180734; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=yNOQxL4FXDmHyD0Kjq23REAu9LFdCtb3Pm7cOHC959s=; b=b+/b1MsiXghrnUV3jqlmzuR/k6mUQp0JeeNf+pMXneovULfK1MmbMw9Pav8g4QyA3s SUk72b7KiLJjspcYlpJGiAFIUTNv8uSLFrpo38MNo7NFDioiBLVqBqTR3K1nUs55dQO6 x/aJ4qN3auxmyhY0KtTQjjLyDw5F9L4tfdcTUvQfNgFCIOJGQO1m8XZ86GHJBefMPa/1 rkRqpDf4CvA41z0NQA/+Mcrg1YpsYpehU7+WiA/GKmoltRuHVT9XQUs2wUoy+t0FX0Qi QOs8yf0Bmr/+5ukmOGlwc5V3X8j6/VKVnHn1Ule6cQtX26m9KwiBwV+IiPQo7hOe/1cx BIMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783575934; x=1784180734; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yNOQxL4FXDmHyD0Kjq23REAu9LFdCtb3Pm7cOHC959s=; b=Fm8K1mDFYPFfAMy7dlDcgtAurGxcn3BYypJaooc1cMME/1XEmY9jGlAt1a572KAoOx ZgJRZlZoNc3z70fTA7xC5fVqRe57aA2dCi0yg9pQd5x2RpgGPvTvJG5CyMdlmokfvUQ1 niesN6dcDF7dTvcUCeL/H+5VpWiBAZpkYCgTQG8G4tih7uQa0PaRQXmMg08UyLeI70QP ueQV6ctbpIBr5mH8VGZ02Mnwo1+kZjlySGFf81keEEzHlZ7xvU0ounnzvWaG2CBr/aL2 iWiWwHswv7CLdgDQevhQOZcYJiDjoIZE6HeVIisGR/lkGwQh/jMq8Xmd1rM1DGP4XHmH V0Vg== X-Forwarded-Encrypted: i=1; AHgh+Rq8lhmX/c3ouv15lGxak7V2V6panOlkHeZDYe+vDFqhIYuZgb/jfYWdkFG0XLS1iTyhPdnoh5acd675lPQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yytl0uPgtDiSQ8o1ysQHGNpAOjkHr4oqfcPvuU2PMJUvYAEuAhX iZhNaSQINH4bO9FVu2PZ0U++bdGWdvar7Z4dJe6UnJ5fs6H+aJN/N1lqTcFeer8M X-Gm-Gg: AfdE7cmnm1SbJpI9JyqHa2s9BtyF483zbks9H94yRZ0uOixvnbQG8/7IW56tnMxKqHU L2/Jn43Nz16Jjp7iXnTzacdVO2liDUeBsRe9616ba2SXvYlcy/NnCm3eiuw4K++akr/0Lj5cksf VUQBRCqIjSkosQtQhUBOAi3FeGAv6xrxUtS1vBgKxkrm9UH4wHXWu81ahQX99YrYpCBZFcBu+Ir uNNZYemQjdv5rReZSs9NPoNmEmyZ5YDDW0asZ2M12c5LyNIws91zjJKHqcL2RaPd3SfN3gCo49h 44D7D4lXAiM8Up25C2L6i279jGM69ovTKMFUHmazrb0N535aRWrYm8M+Wir60F35W2ueeREi5sY 5EqvbDphR5BdLYxzXlhiJ+Vo3V58fxSAUlBFVDP3x5wkQltT/Tj96E02ST+J8cn5uSrl0fbNgWj W+lIo2ju2i/zIVLZnf X-Received: by 2002:a17:903:3903:b0:2cb:14b3:4cfe with SMTP id d9443c01a7336-2ccea582ae2mr60334915ad.45.1783575933576; Wed, 08 Jul 2026 22:45:33 -0700 (PDT) Received: from [10.42.12.77] ([116.128.244.169]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc99cc5aasm38156905ad.0.2026.07.08.22.45.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jul 2026 22:45:32 -0700 (PDT) Message-ID: Date: Thu, 9 Jul 2026 13:45:23 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: leixiang Subject: Re: [PATCH] KVM: Nullify irqfd->producer when add_producer() fails To: Sean Christopherson Cc: stable@vger.kernel.org, Madhavan Srinivasan , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Paul Mackerras , Suresh Warrier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, leixiang References: <1782119051448443.14545.seg@mailgw.kylinos.cn> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > > 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.