Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: javierm@redhat.com, iivanov@suse.de, tiwai@suse.de,
	bhelgaas@google.com, dri-devel@lists.freedesktop.org,
	linux-pci@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] video: screen_info: Relocate framebuffers behind PCI bridges
Date: Mon, 5 May 2025 12:53:38 -0500	[thread overview]
Message-ID: <20250505175338.GA986436@bhelgaas> (raw)
In-Reply-To: <14971422-04af-4f0e-8c3b-7aa97e7af2a5@suse.de>

On Mon, May 05, 2025 at 03:05:34PM +0200, Thomas Zimmermann wrote:
> Am 22.04.25 um 23:47 schrieb Bjorn Helgaas:
> > On Tue, Apr 22, 2025 at 09:49:57AM +0200, Thomas Zimmermann wrote:
> > > Apply bridge window offsets to screen_info framebuffers during
> > > relocation. Fixes invalid access to I/O memory.
> > > 
> > > Resources behind a PCI bridge can be located at a certain offset
> > > in the kernel's I/O range. The framebuffer memory range stored in
> > > screen_info refers to the offset as seen during boot (essentialy 0).
> > > During boot up, the kernel may assign a different memory offset to
> > > the bridge device and thereby relocating the framebuffer address of
> > > the PCI graphics device as seen by the kernel. The information in
> > > screen_info must be updated as well.
> > I can't see the bug report below, so I'm not sure what's happening
> > here.  Apparently the platform is one where PCI bus addresses are not
> > identical to CPU physical addresses.  On such platforms, the PCI host
> > bridge applies an offset between CPU and PCI addresses.  There are
> > several systems like that, but I'm not aware of any that change that
> > CPU->PCI bus address offset at runtime.
> > 
> > So I suspect the problem is not that the kernel has assigned a
> > different offset.  I think it's more likely that the hardware or
> > firmware has determined the offset before the kernel starts, and this
> > code just doesn't account for that.
> 
> Right, that's what I'm trying to say. I guess my explanation simply isn't
> clear.

Yeah, the part about the "kernel assigning a different offset" is a
bit misleading because the kernel doesn't actually assign or *change*
that offset; it only *discovers* the offset, typically from an ACPI
_TRA method or from device tree.

> > > Closes: https://bugzilla.suse.com/show_bug.cgi?id=1240696
> > This bug isn't public.  Can it be made public?  Or even better, a
> > report at https://bugzilla.kernel.org?
> 
> Try again, please. I've updated the settings of this bug report.

Works now, thanks!

> > > @@ -69,10 +69,21 @@ static void screen_info_fixup_lfb(struct pci_dev *pdev)
> > >   	for (i = 0; i < numres; ++i) {
> > >   		struct resource *r = &res[i];
> > > +		struct pci_bus_region bus_region = {
> > > +			.start = r->start,
> > > +			.end = r->end,
> > > +		};
> >
> > screen_info_resources() above fills in "struct resource res[]", but
> > that's not quite right.  A struct resource contains CPU addresses, and
> > screen_info_resources() fills in PCI bus addresses (0xa0000, etc).
> > 
> > struct pci_bus_region is meant to hold PCI bus addresses, so this
> > assignment gets them back where they should be.
> > 
> > >   		const struct resource *pr;
> > >   		if (!(r->flags & IORESOURCE_MEM))
> > >   			continue;
> > > +
> > > +		/*
> > > +		 * Translate the address to resource if the framebuffer
> > > +		 * is behind a PCI bridge.
> > > +		 */
> > > +		pcibios_bus_to_resource(pdev->bus, r, &bus_region);
> >
> > And this converts the PCI bus addresses to CPU addresses, so this
> > makes sense.
> > 
> > The comment might be a little misleading, though.  When PCI bus
> > addresses are different from CPU addresses, it's because the PCI host
> > bridge has applied an offset.  This only happens at the host bridge,
> > never at a PCI-PCI bridge (which is what "PCI bridge" usually means).
> > 
> > The commit log and comments could maybe be clarified, but this all
> > looks to me like it's doing the right thing in spite of abusing the
> > use of struct resource.
> 
> Thanks for reviewing. I'll try to clarify on the commit message. Not sure
> how to change the issue with struct pci_bus_region though.

Yeah, I don't know either.  screen_info_resources() takes a struct
resource pointer, but puts bus addresses into it.  That's misleading
at best, but it would be quite a bit more work to fix that.

I'm not sure we have a generic struct for bus addresses.  We have
struct pci_bus_region, but I'm not sure if screen_info is necessarily
specific to PCI.

Bjorn

      reply	other threads:[~2025-05-05 17:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22  7:49 [PATCH v2] video: screen_info: Relocate framebuffers behind PCI bridges Thomas Zimmermann
2025-04-22 21:47 ` Bjorn Helgaas
2025-05-05 13:05   ` Thomas Zimmermann
2025-05-05 17:53     ` Bjorn Helgaas [this message]

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=20250505175338.GA986436@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=iivanov@suse.de \
    --cc=javierm@redhat.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.de \
    --cc=tzimmermann@suse.de \
    /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