From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 72E483ACA57 for ; Thu, 9 Jul 2026 05:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783575937; cv=none; b=OBVW3OGM2jS+6s/0N1b2lflux5eB1FQxvg03wJQyRLM0uATPfzXb0lPjjBbVNavvXkyTC9Lz4zy8ymmNZSzk04Scf42G7N2zT1Iq8SrtD5VlR+xj1w4P9ziuUnskxzhTWX5XdEiDPYLMjZxvE2v7sfVfLqsZvB2bVG9KGw8FO6U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783575937; c=relaxed/simple; bh=mC3oLMXWAbMD/8ggRenIHpAwU32uiCLRqrKbrmFUo/M=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=RtUsbfUfHPSHpkWN06Ij+tsToHP5KEMVkPM12/nSfWvApfZF8uK00jIVntry/XPgPYIG+RL+XoHJQQ76Ttp5R/h2ts+wJmrCLznefDG0gaclKpSaGqRHEDedS0FkcUEVDnGjJWZjfgQz97RmoDj1guX25OPpv0t/INUPmrXsDJ4= 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.180 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-f180.google.com with SMTP id d9443c01a7336-2cca24023edso7703375ad.1 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=sh2yNQ7B0kDiDPCrAzYvvbLSzAUGDQgty/hc1v+rORRU89Qxf3s8hnqCBQFxWphYLJ n5bYABW2IIsXz9iSISXTdTQk/RHc/NaESnkBUvXP9ItxxlASaYjPDJb6ODhHS6gjQScN 7xcqSO3K7lBH+fXGd5PXvK1Tzjjs2OHTMg5FAoFYB+JXuJ0LTEnliswC4ZP9TLf4nBAN OuTDnuWCAwNFs9WjO6Y9CZSIxZrZKM/DlMfq96/29OQUHmR2+wJha4Spfoy97Ftu88dr CWYFWkyTbKGRmhjeGmdoDi3D/owzSq7bbsoyOWKi+ymEYOohjkJ4f0Xd21/hmJe4SaIh J3Ew== X-Forwarded-Encrypted: i=1; AHgh+RpKnJAnCjauUot2C+3DK8XPHW8tOsvMWYVFAIVmJyTzpwRrBTdHPYrk5EBi1qV8YF/N1Xs=@vger.kernel.org X-Gm-Message-State: AOJu0YwQmYRi3KHChbPx8qiy5/Y2ugQsIkQR6Kx5kZtTa7FQAhgkJyrZ eF9tr8beYTppCFZ/9SYat1pY36FU1Go4DL8hYEUS/6Hw1cXgidKX0T4K X-Gm-Gg: AfdE7clELtUylxfiYgJ9DJvtJC8zOj4J5N50LzYi6DYiditnpj5nQSeuDQChGuT2Acb Wgwub14wE3dysu1jIV1KuKH1HznF12W4JFWGgn5PfsWR+tMjPXvtSC9ErzRSI30RGMTDuCxFy2i /whIcoBOBaSmbVPsph44M9D1lS3YioZcs/TcLVjdsUwqrFRuTIJP3TJQFLa5RKMvYFgFXmc/q3S MyyDRjQMw8anGkffs69ZjNA9fRsIbIhpxXHbmGecD5cpM5rrNr1RVSF2+nHkKAsPskVDlnzuM0u keyqQ05+K2PRV+WXx+oxHpxQ9ENyywY8GryHsx53AAEI5SdxciUn85RRxkRNgh5tsLth58XKjfX +xmZPoeGCdFmo/QWjVnTt6VnO85Z07mlqUdusWS9kjDm7IswewUJqA/ifLGEU891tc03gXu+hpe Onu7LfNcLXFyfvxHzu 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: kvm@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.