Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Lukas Wunner <lukas@wunner.de>,
	Chris Chiu <chris.chiu@canonical.com>,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 1/2] PCI: Take multifunction devices into account when distributing resources
Date: Fri, 18 Nov 2022 06:29:51 -0600	[thread overview]
Message-ID: <20221118122951.GA1263043@bhelgaas> (raw)
In-Reply-To: <Y3dI6K8o+j1nE4Lf@black.fi.intel.com>

Hi Mika,

On Fri, Nov 18, 2022 at 10:57:12AM +0200, Mika Westerberg wrote:
> On Thu, Nov 17, 2022 at 05:10:34PM -0600, Bjorn Helgaas wrote:
> > On Mon, Nov 14, 2022 at 01:59:52PM +0200, Mika Westerberg wrote:
> > > PCIe switch upstream port may be one of the functions of a multifunction
> > > device.
> > 
> > I don't think this is specific to PCIe, is it?  Can't we have a
> > multi-function device where one function is a conventional PCI bridge?
> > Actually, I don't think "multi-function" is relevant at all -- you
> > iterate over all the devices on the bus below.  For PCIe, that likely
> > means multiple functions of the same device, but it could be separate
> > devices in conventional PCI.
> 
> Yes it can be but I was trying to explain the problem we encountered and
> that's related to PCIe.
> 
> I can leave this out if you think it is better that way.

Not necessarily, I'm just hoping this change is generic enough for all
PCI and PCIe topologies.

> > > The resource distribution code does not take this into account
> > > properly and therefore it expands the upstream port resource windows too
> > > much, not leaving space for the other functions (in the multifunction
> > > device)
> > 
> > I guess the window expansion here is done by adjust_bridge_window()?
> 
> Yes but the resources are distributed in
> pci_bus_distribute_available_resources().

Yep, sounds good, I was just confirming my understanding of the code.
The main point of this patch is to *reduce* the size of the windows to
leave room for peers of the bridge, so I had to look a bit to figure
out where they got expanded.

> > >  	if (hotplug_bridges + normal_bridges == 1) {
> > > -		dev = list_first_entry(&bus->devices, struct pci_dev, bus_list);
> > > -		if (dev->subordinate)
> > > -			pci_bus_distribute_available_resources(dev->subordinate,
> > > -				add_list, io, mmio, mmio_pref);
> > > +		/* Upstream port must be the first */
> > > +		bridge = list_first_entry(&bus->devices, struct pci_dev, bus_list);
> > > +		if (!bridge->subordinate)
> > > +			return;
> > > +
> > > +		/*
> > > +		 * It is possible to have switch upstream port as a part of a
> > > +		 * multifunction device. For this reason reduce the space
> > > +		 * available for distribution by the amount required by the
> > > +		 * peers of the upstream port.
> > > +		 */
> > > +		list_for_each_entry(dev, &bus->devices, bus_list) {
> > 
> > It seems like maybe we ought to do this regardless of how many bridges
> > there are on the bus.  Don't we always want to assign space to devices
> > on this bus before distributing the leftovers to downstream buses?
> 
> Yes we do.
> 
> > E.g., maybe this should be done before the adjust_bridge_window()
> > calls?
> 
> With the current code it is clear that we deal with the upstream port.
> At least in PCIe it is not allowed to have anything else than downstream
> ports on that internal bus so the only case we would need to do this is
> the switch upstream port.
> 
> Let me know if you still want me to move this before adjust_bridge_window()
> I can do that in v3. Probably needs a comment too.

Hmm, I don't know exactly how to do this, but I don't think this code
should be PCIe-specific, which I think means it shouldn't depend on
how many bridges are on the bus.

I guess the existing assumption that a bridge must be the first device
on the bus is a hidden assumption that this is PCIe.  That might be a
mistake from the past.

I haven't tried it, but I wonder if we could reproduce the same
problem in a conventional PCI topology with qemu.

Bjorn

  reply	other threads:[~2022-11-18 12:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 11:59 [PATCH v2 1/2] PCI: Take multifunction devices into account when distributing resources Mika Westerberg
2022-11-14 11:59 ` [PATCH v2 2/2] Revert "Revert "PCI: Distribute available resources for root buses, too"" Mika Westerberg
2022-11-16  9:47   ` Jonathan Cameron
2022-11-14 18:34 ` [PATCH v2 1/2] PCI: Take multifunction devices into account when distributing resources Rafael J. Wysocki
2022-11-16  9:46 ` Jonathan Cameron
2022-11-17 23:10 ` Bjorn Helgaas
2022-11-18  8:57   ` Mika Westerberg
2022-11-18 12:29     ` Bjorn Helgaas [this message]
2022-11-21 11:47       ` Mika Westerberg
2022-11-21 22:45         ` Bjorn Helgaas
2022-11-22  6:42           ` Mika Westerberg
2022-11-22 11:45             ` Jonathan Cameron
2022-11-22 12:21               ` Mika Westerberg
2022-11-22 17:26               ` Bjorn Helgaas

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=20221118122951.GA1263043@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=chris.chiu@canonical.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rafael.j.wysocki@intel.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