public inbox for dmaengine@vger.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Koichiro Den <den@valinux.co.jp>
Cc: vkoul@kernel.org, mani@kernel.org, Frank.Li@nxp.com,
	jingoohan1@gmail.com, lpieralisi@kernel.org,
	kwilczynski@kernel.org, robh@kernel.org, bhelgaas@google.com,
	kishon@kernel.org, jdmason@kudzu.us, allenbh@gmail.com,
	dmaengine@vger.kernel.org, linux-pci@vger.kernel.org,
	ntb@lists.linux.dev, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 6/8] PCI: endpoint: pci-epf-test: Don't free doorbell IRQ unless requested
Date: Tue, 10 Feb 2026 17:38:19 +0100	[thread overview]
Message-ID: <aYte-7hTxb7kXNlQ@ryzen> (raw)
In-Reply-To: <uvuugqkiaravp6gmn6o7x5koyvo5zkmbwwbhdq6ctvvdtdhoyd@rnxwhlysqs7d>

On Tue, Feb 10, 2026 at 10:54:20PM +0900, Koichiro Den wrote:
> On Tue, Feb 10, 2026 at 01:36:29PM +0100, Niklas Cassel wrote:
> > On Mon, Feb 09, 2026 at 09:53:14PM +0900, Koichiro Den wrote:
> > > pci_epf_test_enable_doorbell() allocates a doorbell and then installs
> > > the interrupt handler with request_threaded_irq(). On failures before
> > > the IRQ is successfully requested (e.g. no free BAR,
> > > request_threaded_irq() failure), the error path jumps to
> > > err_doorbell_cleanup and calls pci_epf_test_doorbell_cleanup().
> > > 
> > > pci_epf_test_doorbell_cleanup() unconditionally calls free_irq() for the
> > > doorbell virq, which can trigger "Trying to free already-free IRQ"
> > > warnings when the IRQ was never requested.
> > > 
> > > Track whether the doorbell IRQ has been successfully requested and only
> > > call free_irq() when it has.
> > > 
> > > Fixes: eff0c286aa91 ("PCI: endpoint: pci-epf-test: Add doorbell test support")
> > > Signed-off-by: Koichiro Den <den@valinux.co.jp>
> > > ---
> > >  drivers/pci/endpoint/functions/pci-epf-test.c | 9 ++++++++-
> > >  1 file changed, 8 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
> > > index 6952ee418622..23034f548c90 100644
> > > --- a/drivers/pci/endpoint/functions/pci-epf-test.c
> > > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c
> > > @@ -86,6 +86,7 @@ struct pci_epf_test {
> > >  	bool			dma_private;
> > >  	const struct pci_epc_features *epc_features;
> > >  	struct pci_epf_bar	db_bar;
> > > +	bool			db_irq_requested;
> > >  	size_t			bar_size[PCI_STD_NUM_BARS];
> > >  };
> > >  
> > > @@ -715,7 +716,10 @@ static void pci_epf_test_doorbell_cleanup(struct pci_epf_test *epf_test)
> > >  	struct pci_epf_test_reg *reg = epf_test->reg[epf_test->test_reg_bar];
> > >  	struct pci_epf *epf = epf_test->epf;
> > >  
> > > -	free_irq(epf->db_msg[0].virq, epf_test);
> > > +	if (epf_test->db_irq_requested && epf->db_msg) {
> > > +		free_irq(epf->db_msg[0].virq, epf_test);
> > > +		epf_test->db_irq_requested = false;
> > > +	}
> > >  	reg->doorbell_bar = cpu_to_le32(NO_BAR);
> > >  
> > >  	pci_epf_free_doorbell(epf);
> > > @@ -741,6 +745,8 @@ static void pci_epf_test_enable_doorbell(struct pci_epf_test *epf_test,
> > >  	if (bar < BAR_0)
> > >  		goto err_doorbell_cleanup;
> > >  
> > > +	epf_test->db_irq_requested = false;
> > > +
> > >  	ret = request_threaded_irq(epf->db_msg[0].virq, NULL,
> > >  				   pci_epf_test_doorbell_handler, IRQF_ONESHOT,
> > >  				   "pci-ep-test-doorbell", epf_test);
> > 
> > Another bug in pci_epf_test_enable_doorbell():
> > 
> > Since we reuse the BAR size, and use dynamic inbound mapping,
> > what if the returned DB offset is larger than epf->bar[bar].size ?
> > 
> > I think we need something like this before calling pci_epc_set_bar():
> > 
> > if (reg->doorbell_offset >= epf->bar[bar].size)
> >     goto err_doorbell_cleanup;
> 
> Right, I remember this coming up in another thread.
> 
> If there are no objections from either of you, I'm happy to include a fix
> patch for this in v7.

No objection from me.


Ideally I would also like:

	if (!(test->ep_caps & CAP_DYNAMIC_INBOUND_MAPPING))
		return -EOPNOTSUPP;

and that the pci_endpoint_test selftest would return skip on -EOPNOTSUPP,
since the doorbell test currently relies on CAP_DYNAMIC_INBOUND_MAPPING,
but that might make your series too big.


Thus, I'm happy if you add a safety check for:
reg->doorbell_offset >= epf->bar[bar].size


Kind regards,
Niklas

  reply	other threads:[~2026-02-10 16:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-09 12:53 [PATCH v6 0/8] PCI: endpoint: pci-ep-msi: Add embedded doorbell fallback Koichiro Den
2026-02-09 12:53 ` [PATCH v6 1/8] dmaengine: dw-edma: Deassert emulated interrupts in the IRQ handler Koichiro Den
2026-02-09 16:05   ` Frank Li
2026-02-09 12:53 ` [PATCH v6 2/8] dmaengine: dw-edma: Cache per-channel IRQ and emulation doorbell offset Koichiro Den
2026-02-09 16:13   ` Frank Li
2026-02-10  1:48     ` Koichiro Den
2026-02-09 12:53 ` [PATCH v6 3/8] PCI: endpoint: Add auxiliary resource query API Koichiro Den
2026-02-09 15:59   ` Frank Li
2026-02-09 12:53 ` [PATCH v6 4/8] PCI: dwc: Record integrated eDMA register window Koichiro Den
2026-02-09 12:53 ` [PATCH v6 5/8] PCI: dwc: ep: Report integrated eDMA resources via EPC aux-resource API Koichiro Den
2026-02-09 12:53 ` [PATCH v6 6/8] PCI: endpoint: pci-epf-test: Don't free doorbell IRQ unless requested Koichiro Den
2026-02-09 15:57   ` Frank Li
2026-02-10  1:54     ` Koichiro Den
2026-02-10 12:36   ` Niklas Cassel
2026-02-10 13:54     ` Koichiro Den
2026-02-10 16:38       ` Niklas Cassel [this message]
2026-02-11 16:08         ` Koichiro Den
2026-02-09 12:53 ` [PATCH v6 7/8] PCI: endpoint: pci-ep-msi: Fix error unwind and prevent double alloc Koichiro Den
2026-02-09 15:53   ` Frank Li
2026-02-09 12:53 ` [PATCH v6 8/8] PCI: endpoint: pci-ep-msi: Add embedded doorbell fallback Koichiro Den
2026-02-09 15:51   ` Frank Li
2026-02-10  2:10     ` Koichiro Den
2026-02-10 15:16       ` Frank Li
2026-02-10 12:24 ` [PATCH v6 0/8] " Niklas Cassel
2026-02-10 14:07   ` Koichiro Den
2026-02-10 16:30     ` Niklas Cassel
2026-02-11 15:57       ` Koichiro Den
2026-02-11 16:52         ` Niklas Cassel
2026-02-12  3:26           ` Koichiro Den
2026-02-12 10:26             ` Niklas Cassel
2026-02-12 15:14               ` Koichiro Den
2026-02-12 15:38                 ` Niklas Cassel
2026-02-12 16:31         ` Koichiro Den

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=aYte-7hTxb7kXNlQ@ryzen \
    --to=cassel@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=allenbh@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=den@valinux.co.jp \
    --cc=dmaengine@vger.kernel.org \
    --cc=jdmason@kudzu.us \
    --cc=jingoohan1@gmail.com \
    --cc=kishon@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=ntb@lists.linux.dev \
    --cc=robh@kernel.org \
    --cc=vkoul@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