public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Jerome Brunet <jbrunet@baylibre.com>
Cc: "Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Jon Mason" <jdmason@kudzu.us>,
	"Dave Jiang" <dave.jiang@intel.com>,
	"Allen Hubbe" <allenbh@gmail.com>,
	"Marek Vasut" <marek.vasut+renesas@gmail.com>,
	"Yoshihiro Shimoda" <yoshihiro.shimoda.uh@renesas.com>,
	"Yuya Hamamachi" <yuya.hamamachi.sx@renesas.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	ntb@lists.linux.dev, dlemoal@kernel.org
Subject: Re: [PATCH 1/2] PCI: endpoint: strictly apply bar fixed size to allocate space
Date: Tue, 1 Apr 2025 11:25:56 +0200	[thread overview]
Message-ID: <Z-uxJKMQFY8eX1iw@ryzen> (raw)
In-Reply-To: <1jwmc5tgbe.fsf@starbuckisacylon.baylibre.com>

On Mon, Mar 31, 2025 at 04:39:33PM +0200, Jerome Brunet wrote:
> On Mon 31 Mar 2025 at 10:14, Niklas Cassel <cassel@kernel.org> wrote:
> >
> > Perhaps the solution is to add another struct member to struct pci_epf_bar,
> > size (meaning actual BAR size, which will be written to the BAR mask register)
> > and backing_mem_size.
> >
> > Or.. we modify pci_epf_alloc_space() to allocate an aligned size, but the
> > size that we store in (struct pci_epf_bar).size is the unaligned size.
> 
> I tried this and it works. As pointed above, as long as pci_epc_set_bar() is
> happy, it will work for me since the dwc-ep driver does not really care for
> the size given with fixed BARs.
> 
> However, when doing so, it gets a bit trick to properly call
> dma_free_coherent() as we don't have the size actually allocated
> anymore. It is possible to compute it again but it is rather ugly.

You are right.


> 
> It would probably be best to add a parameter indeed, to track the size
> allocated with dma_alloc_coherent(). What about .aligned_size ? Keeping
> .size to track the actual bar size requires less modification I think.

Your problem should be able to be reproducible also for BAR type
BAR_PROGRAMMABLE, when sending in a size smaller than epc_features.align
to pci_epf_alloc_space(), which will then modify epf_bar.size to be aligned.

The call to set_bar() will then use the aligned size instead of the
"BAR size" when writing the BAR mask register, which is wrong.
(This means that the BAR size seen by the host is the aligned size and not
"BAR size".)

So yes, I think having both size and aligned_size (or whatever name) is the
way to go.


Kind regards,
Niklas

  reply	other threads:[~2025-04-01  9:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-28 14:53 [PATCH 0/2] PCI: endpoint: space allocation fixups Jerome Brunet
2025-03-28 14:53 ` [PATCH 1/2] PCI: endpoint: strictly apply bar fixed size to allocate space Jerome Brunet
2025-03-31  8:14   ` Niklas Cassel
2025-03-31 14:39     ` Jerome Brunet
2025-04-01  9:25       ` Niklas Cassel [this message]
2025-03-28 14:53 ` [PATCH 2/2] PCI: endpoint: pci-epf-vntb: simplify ctrl/spad space allocation Jerome Brunet
2025-03-31 14:48   ` Frank Li
2025-04-01  7:39     ` Jerome Brunet
2025-04-01 14:55       ` Frank Li
2025-04-02 13:44         ` Jerome Brunet

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=Z-uxJKMQFY8eX1iw@ryzen \
    --to=cassel@kernel.org \
    --cc=allenbh@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=dave.jiang@intel.com \
    --cc=dlemoal@kernel.org \
    --cc=jbrunet@baylibre.com \
    --cc=jdmason@kudzu.us \
    --cc=kishon@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=ntb@lists.linux.dev \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    --cc=yuya.hamamachi.sx@renesas.com \
    /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