From: Niklas Cassel <cassel@kernel.org>
To: Koichiro Den <den@valinux.co.jp>
Cc: mani@kernel.org, kwilczynski@kernel.org, kishon@kernel.org,
bhelgaas@google.com, jdmason@kudzu.us, dave.jiang@intel.com,
allenbh@gmail.com, Frank.Li@nxp.com, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, ntb@lists.linux.dev
Subject: Re: [PATCH 2/4] PCI: endpoint: pci-epf-test: Sanity-check doorbell offset within BAR
Date: Mon, 16 Feb 2026 14:14:14 +0100 [thread overview]
Message-ID: <aZMYJsjpqPR9uNqp@ryzen> (raw)
In-Reply-To: <20260215150914.3392479-3-den@valinux.co.jp>
On Mon, Feb 16, 2026 at 12:09:12AM +0900, Koichiro Den wrote:
> pci-epf-test advertises the doorbell target to the RC as a BAR number
> and an offset. The RC rings the doorbell with a single DWORD MMIO write
> to BAR + offset.
>
> For MSI/MSI-X-based doorbells, the message address is required to be
> DWORD-aligned, so the computed offset should not straddle a BAR boundary
> in normal operation.
>
> However, with support for doorbells based on mechanisms other than
> MSI/MSI-X (via pci_epf_alloc_doorbell()), the returned message address
> may not necessarily be DWORD-aligned. In such a case, offset plus the
> 32-bit write width could cross the end of the BAR aperture. The offset
> returned by pci_epf_align_inbound_addr() is guaranteed to be within the
> BAR size, but this alone does not ensure that a 32-bit write starting at
> that offset stays within the BAR.
>
> Add a bounds check to ensure that the 32-bit doorbell write always stays
> within the BAR aperture. While this should not trigger for
> spec-compliant MSI/MSI-X addresses, it provides a defensive guard
> against unexpected offsets from future doorbell implementations.
I think everything you write is true,
and I know that I suggested this...
But for the MMIO address, will it ever not be 32-bit aligned?
Even in the eDMA case, the eDMA registers are 32-bit aligned.
Did I perhaps have a brain fart and overthink this?
I guess theoretically, some future pci_epf_alloc_doorbell() implementation
could return something that is not 32-bit aligned...
But if we really want to add a safety check for that... perhaps a 32-bit
alignment check would be better suited to have in pci_epf_alloc_doorbell() ?
Perhaps this check is better added in pci_epf_alloc_doorbell() or
pci_epf_alloc_doorbell_embedded(), in the series that adds support for
embedded doorbells ?
Kind regards,
Niklas
next prev parent reply other threads:[~2026-02-16 13:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-15 15:09 [PATCH 0/4] PCI: endpoint: Doorbell-related fixes Koichiro Den
2026-02-15 15:09 ` [PATCH 1/4] PCI: endpoint: pci-epf-vntb: Fix MSI doorbell IRQ unwind Koichiro Den
2026-02-16 11:56 ` Niklas Cassel
2026-02-16 14:02 ` Koichiro Den
2026-02-16 14:08 ` Niklas Cassel
2026-02-15 15:09 ` [PATCH 2/4] PCI: endpoint: pci-epf-test: Sanity-check doorbell offset within BAR Koichiro Den
2026-02-16 13:14 ` Niklas Cassel [this message]
2026-02-16 14:17 ` Koichiro Den
2026-02-15 15:09 ` [PATCH 3/4] PCI: endpoint: pci-epf-test: Don't free doorbell IRQ unless requested Koichiro Den
2026-02-16 11:35 ` Niklas Cassel
2026-02-16 14:30 ` Koichiro Den
2026-02-17 2:49 ` Koichiro Den
2026-02-15 15:09 ` [PATCH 4/4] PCI: endpoint: pci-ep-msi: Fix error unwind and prevent double alloc Koichiro Den
2026-02-16 11:57 ` Niklas Cassel
2026-02-16 11:51 ` [PATCH 0/4] PCI: endpoint: Doorbell-related fixes Niklas Cassel
2026-02-16 13:48 ` 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=aZMYJsjpqPR9uNqp@ryzen \
--to=cassel@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=allenbh@gmail.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=den@valinux.co.jp \
--cc=jdmason@kudzu.us \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=ntb@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.