PCI: tegra: limit MSI target address to 32-bit
Subsystems (2)
PATCH 1/1 PCI: tegra: limit MSI target address to 32-bit
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controller
--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/host/pci-tegra.c +1 -1
@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );
Signature · 1 line
2.7.4
[+cc Michal, Sören, Simon]
Quoted 15 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/host/pci-tegra.c +0
-0
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1535
Quoted 6 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);
Should this be GFP_DMA32? See the comment above the GFP_DMA definition.
Should we be using virt_to_phys() here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something like pcibios_resource_to_bus().
Do rcar_pcie_enable_msi() and xilinx_pcie_enable_msi() have a similar problem? They both use GFP_KERNEL, then virt_to_phys(), then write the result of virt_to_phys() using a 32-bit register write.
Quoted 4 lines
drivers/pci/host/pci-tegra.c +0
-0afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );Signature · 1 line
2.7.4
Quoted 13 lines · Bjorn Helgaas
[+cc Michal, S=C3=B6ren, Simon]
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie=
Quoted 5 lines
drivers/pci/host/pci-tegra.c +0
-0@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie=
*pcie)
Quoted 8 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie= · line 1535
Quoted 6 lines
drivers/pci/host/pci-tegra.c +1
-1} =20/* setup AFI/FPCI range */ - msi->pages =3D __get_free_pages(GFP_KERNEL, 0); + msi->pages =3D __get_free_pages(GFP_DMA, 0); msi->phys =3D virt_to_phys((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.
looking at the comments for both GFP_DMA32 and GFP_DMA, I thought GFP_DMA32 is the correct one to use, but, even with that I got >32-bit addresses. GFP_DMA always gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().
This address is written to two places.
First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of=20 forwarding it to
memory subsystem.
Second, into 'Message Address' field of 'Message Address Register for=20 MSI' register in
end point's configuration space (this is done by MSI framework) for end=20 point to know
which address to be used to generate MSI interrupt.
Quoted 3 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.
Well, if those systems deal with 64-bit addresses and when an end point=20 is connected which supports
only 32-bit MSI addresses, this problem will surface when=20 __get_free_pages() returns an address that
translates to a >32-bit address after virt_to_phys() call on it.
Quoted 2 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie= · line 1536
Quoted 2 lines
drivers/pci/host/pci-tegra.c +0
-0afi_writel(pcie, msi->phys >> soc->msi_base_shift, AFI_MSI_FPCI_BAR_S=
T);
Quoted 3 lines
Quoted 3 lines
drivers/pci/host/pci-tegra.c +0
-1--=202.7.4
[+cc Lorenzo]
Quoted 26 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.
Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.
This sounds worth looking into (but maybe we don't need the __get_free_pages() at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:
Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff]
DMA32 [mem 0x0000000001000000-0x00000000ffffffff]
Normal [mem 0x0000000100000000-0x00000004217fffff]
Device emptyWhat does your machine show?
Quoted 5 lines
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().
Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the __get_free_pages()?
Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.
I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.
If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than __get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.
Quoted 1 line
Quoted 1 line
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1537
Quoted 1 line
drivers/pci/host/pci-tegra.c +0
-0afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );
[1] https://lkml.kernel.org/r/20170824134451.GA31858-1RhO1Y9PlrlHTL0Zs8A6p5iNqAH0jzoTYJqu5kTmcBRl57MIdRCFDg@public.gmane.org
[2] https://lkml.kernel.org/r/[email protected]
[3] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d7bd554f27c9
Quoted 10 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 7 lines · Vidya Sagar
Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controller
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/pci/host/pci-tegra=
Quoted 6 lines
Signed-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/host/pci-tegra= renamed from drivers/pci/host/pci-tegra.c +0
-0
.c
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pc=
Quoted 4 lines
index
1987fec1f126..03d3dcdd06c2100644drivers/pci/host/pci-tegra.c +0
-0@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pc=
ie *pcie)
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pc= · line 1534
Quoted 5 lines
drivers/pci/host/pci-tegra.c +1
-1}/* setup AFI/FPCI range */ - msi->pages =3D __get_free_pages(GFP_KERNEL, 0); + msi->pages =3D __get_free_pages(GFP_DMA, 0); msi->phys =3D virt_to_phys((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.looking at the comments for both
GFP_DMA32andGFP_DMA, I thought GFP_DM=
A32
Quoted 7 lines
Quoted 3 lines
is the correct one to use, but, even with that I got >32-bit addresses.
GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:
Quoted 7 lines
Zone ranges: DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
I see following in my linux box
=C2=A0Zone ranges:
=C2=A0=C2=A0 DMA=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [mem 0x0000000000001000-0x0= 000000000ffffff]
=C2=A0=C2=A0 DMA32=C2=A0=C2=A0=C2=A0 [mem 0x0000000001000000-0x00000000fff= fffff]
=C2=A0=C2=A0 Normal=C2=A0=C2=A0 [mem 0x0000000100000000-0x000000106effffff= ]
=C2=A0=C2=A0 Device=C2=A0=C2=A0 empty
and following in my T210 Tegra platform
Zone ranges:
=C2=A0 DMA=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [mem 0x0000000080000000-0x0000000= 0ffffffff]
=C2=A0 Normal=C2=A0=C2=A0 [mem 0x0000000100000000-0x000000017fffffff]
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Quoted 3 lines
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?
It is the same system where MSI memory writes don't really make it to system memory. But, the addresses mentioned in that patch don't work. we are working with hardware folks on understanding the issue better. Meanwhile, using GFP_DMA is giving consistent results and thought this can be used as a stop gap solution before we figure out a better bus address to be used as MSI target address.
Quoted 13 lines
Quoted 8 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.
Quoted 6 lines
If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/pci/host/pci-tegra.c +0
-0afi_writel(pcie, msi->phys >> soc->msi_base_shift, AFI_MSI_FPCI_BAR=
_ST);
Quoted 1 line
m.corp.google.com
Quoted 2 lines
[2] https://lkml.kernel.org/r/[email protected]
[3] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit=
/?id=3Dd7bd554f27c9
Quoted 52 lines · Vidya Sagar
Quoted 35 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 24 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Quoted 7 lines
Zone ranges: DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
I see following in my linux box
Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x000000106effffff] Device empty
Quoted 4 lines
and following in my T210 Tegra platform
Zone ranges:
DMA [mem 0x0000000080000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x000000017fffffff]
This seems to be happening because 64-bit ARM doesn't have the ZONE_DMA32 Kconfig option, which seems to cause the DMA32 zone to default to the normal zone (see include/linux/gfp.h).
That's very confusing in conjunction with the kerneldoc comment for GFP_DMA32 because it isn't actually guaranteed to give you 32-bit addresses for !ZONE_DMA32.
Cc'ing Arnd who knows about these things.
Thierry
Quoted 59 lines · Thierry Reding
Quoted 49 lines · Vidya Sagar
Quoted 34 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 24 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Quoted 7 lines
Zone ranges: DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
I see following in my linux box
Zone ranges:DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x000000106effffff] Device emptyQuoted 4 lines
and following in my T210 Tegra platform
Zone ranges:
DMA [mem 0x0000000080000000-0x00000000ffffffff]
Normal [mem 0x0000000100000000-0x000000017fffffff]This seems to be happening because 64-bit ARM doesn't have the
ZONE_DMA32Kconfigoption, which seems to cause the DMA32 zone to default to the normal zone (seeinclude/linux/gfp.h).
Quoted 5 lines
That's very confusing in conjunction with the kerneldoc comment for
GFP_DMA32because it isn't actually guaranteed to give you 32-bit addresses for !ZONE_DMA32.Cc'ing Arnd who knows about these things.
I don't have a good answer unfortunately, but I agree there is clearly something wrong with the behavior, AFAICT, ZONE_DMA32 should really do what the name says.
When you look at the commit that introduced ZONE_DMA32, you see that it used to be different, see commit a2f1b4249007 ("[PATCH] x86_64: Add 4GB DMA32 zone"). ZONE_DMA32 used to fall back to ZONE_DMA, but this got changed shortly after, still in 2006.
Arnd
RnJvbTogVmlkeWEgU2FnYXINCj4gU2VudDogMDkgTm92ZW1iZXIgMjAxNyAxODo0MQ0KLi4uDQo+ ID4gQW5kIHRoaXMgY29tbWl0IFszXSBzb3VuZHMgbGlrZSBpdCBkZXNjcmliZXMgYSBzaW1pbGFy IGhhcmR3YXJlDQo+ID4gc2l0dWF0aW9uIHdpdGggVGVncmEgd2hlcmUgdGhlIGhvc3QgYnJpZGdl IGludGVyY2VwdHMgdGhlIE1TSSB0YXJnZXQNCj4gPiBhZGRyZXNzLCBzbyB3cml0ZXMgdG8gaXQg bmV2ZXIgcmVhY2ggc3lzdGVtIG1lbW9yeS4gIFRoYXQgbWVhbnMgdGhhdA0KPiA+IFRlZ3JhIGRv ZXNuJ3QgbmVlZCB0byBhbGxvY2F0ZSBzeXN0ZW0gbWVtb3J5IGF0IGFsbC4NCj4gPg0KPiA+IElz IHlvdXIgc3lzdGVtIHNpbWlsYXI/ICBDYW4geW91IGp1c3Qgc3RhdGljYWxseSBhbGxvY2F0ZSBh IGxpdHRsZSBidXMNCj4gPiBhZGRyZXNzIHNwYWNlLCB1c2UgdGhhdCBmb3IgdGhlIE1TSSB0YXJn ZXQgYWRkcmVzcywgYW5kIHNraXAgdGhlDQo+ID4gX19nZXRfZnJlZV9wYWdlcygpPw0KPg0KPiBJ dCBpcyB0aGUgc2FtZSBzeXN0ZW0gd2hlcmUgTVNJIG1lbW9yeSB3cml0ZXMgZG9uJ3QgcmVhbGx5 IG1ha2UgaXQgdG8NCj4gc3lzdGVtIG1lbW9yeS4gQnV0LCB0aGUgYWRkcmVzc2VzIG1lbnRpb25l ZCBpbiB0aGF0IHBhdGNoIGRvbid0IHdvcmsuDQo+IHdlIGFyZSB3b3JraW5nIHdpdGggaGFyZHdh cmUgZm9sa3Mgb24gdW5kZXJzdGFuZGluZyB0aGUgaXNzdWUgYmV0dGVyLg0KLi4uDQoNCllvdSBk byBuZWVkIHRvIG1ha2Ugc3VyZSB0aGF0IHRoZSBhZGRyZXNzIHlvdSBwaWNrIHdpbGwgbmV2ZXIN CmJlIHVzZWQgZm9yIGEgJ2RtYScgdHJhbnNmZXIuDQpJZiB0aGUgYWRkcmVzcyBuZWVkcyB0byBi ZSBpbnNpZGUgdGhlIChwY2llKSBwaHlzaWNhbCBhZGRyZXNzZXMNCmZvciBzeXN0ZW0gbWVtb3J5 IHRoZW4gYWxsb2NhdGluZyBhIHBoeXNpY2FsIHBhZ2UgbWF5IGJlIHRoZQ0Kc2FmZXN0IHdheSB0 byBlbnN1cmUgdGhpcyBkb2Vzbid0IGhhcHBlbi4NCg0KCURhdmlkDQoNCg0K
On Fri, Nov 10, 2017 at 12:11:05AM +0530, Vidya Sagar wrote:
[...]
Quoted 58 lines
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 8 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Quoted 7 lines
Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
I see following in my linux box
Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x000000106effffff] Device emptyand following in my T210 Tegra platform
Zone ranges:
DMA [mem 0x0000000080000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x000000017fffffff]Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Quoted 3 lines
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?
Quoted 6 lines
It is the same system where MSI memory writes don't really make it to system memory. But, the addresses mentioned in that patch don't work. we are working with hardware folks on understanding the issue better. Meanwhile, using
GFP_DMAis giving consistent results and thought this can be used as a stop gap solution before we figure out a better bus address to be used as MSI target address.
Vidya,
I will mark this as superseded - by Thierry's patch:
https://patchwork.ozlabs.org/patch/848569/
even though we have not reached a real conclusion yet on that patch - we should take this discussion from the thread above.
Thank you,
Lorenzo
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.Quoted 1 line
Quoted 1 line
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1537
Quoted 1 line
drivers/pci/host/pci-tegra.c +0
-0afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d7bd554f27c9
Bjorn,
Quoted 79 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 26 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
Quoted 5 lines
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.
Quoted 5 lines
I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.
it is so, at least drivers/pci/host/pcie-xilinx.c driver, MSI data is never read from the msi_pages physical
memory allocated, data is always intercepted, caught and fed from one of the HW FIFO register XILINX_PCIE_REG_RPIFR2. Here too __get_free_pages was used to allocate msi_pages just to get a real memory address to program in the MSI address in PCIe endpoints config register.
MSI handling code from pcie-xilinx.c
if (status & (XILINX_PCIE_INTR_INTX | XILINX_PCIE_INTR_MSI)) {
.
.
/* Decode the IRQ number */
if (val & XILINX_PCIE_RPIFR1_MSI_INTR) {
val = pcie_read(port, XILINX_PCIE_REG_RPIFR2) &
XILINX_PCIE_RPIFR2_MSG_DATA;
} else {
val = (val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
XILINX_PCIE_RPIFR1_INTR_SHIFT;
val = irq_find_mapping(port->leg_domain, val);
}
.
.
/* Handle the interrupt */
if (IS_ENABLED(CONFIG_PCI_MSI) ||
!(val & XILINX_PCIE_RPIFR1_MSI_INTR))
generic_handle_irq(val);
}Quoted 11 lines
If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.Quoted 1 line
Quoted 1 line
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1537
Quoted 1 line
drivers/pci/host/pci-tegra.c +0
-0afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d7bd554f27c9
Quoted 111 lines · subrahmanya_lingappa
Bjorn,
Quoted 79 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 26 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
Quoted 5 lines
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.Quoted 5 lines
I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.it is so, at least
drivers/pci/host/pcie-xilinx.cdriver, MSI data is never read from themsi_pagesphysical
memory allocated, data is always intercepted, caught and fed from one of the HW FIFO registerXILINX_PCIE_REG_RPIFR2. Here too__get_free_pageswas used to allocatemsi_pagesjust to get a real memory address to program in the MSI address in PCIe endpoints config register.MSI handling code from
pcie-xilinx.cif (status & (XILINX_PCIE_INTR_INTX | XILINX_PCIE_INTR_MSI)) { . . /* Decode the IRQ number */ if (val & XILINX_PCIE_RPIFR1_MSI_INTR) { val = pcie_read(port, XILINX_PCIE_REG_RPIFR2) & XILINX_PCIE_RPIFR2_MSG_DATA; } else { val = (val & XILINX_PCIE_RPIFR1_INTR_MASK) >> XILINX_PCIE_RPIFR1_INTR_SHIFT; val = irq_find_mapping(port->leg_domain, val); }
Quoted 8 lines
. . /* Handle the interrupt */ if (IS_ENABLED(CONFIG_PCI_MSI) || !(val & XILINX_PCIE_RPIFR1_MSI_INTR)) generic_handle_irq(val); }
A side-note: this looks like a bug to me. In case of an MSI, the val variable will have been overwritten by the MSI decode branch above, so it seems to me like the conditional down here isn't guaranteed to work and depends on what MSI was actually received?
Don't you need to store the interrupt status in a variable separate from the value that you're using to find which interrupt was received?
Thierry
[+Robin]
Quoted 38 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 26 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:
Quoted 12 lines
Zone ranges:
DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
Quoted 4 lines
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().
I had a quick chat with Robin (CC'ed, who has dealt/is dealing with most of the work this thread relates to) and I think that as things stand, for MSI physical addresses, an offset between PCI->host address shift is not really contemplated (ie 1:1 host<->pci is assumed).
Quoted 14 lines
Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Quoted 3 lines
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?
IIUC, all these host bridges need is a physical address that is routed upstream to the host bridge by the PCIe tree (ie it is not part of the host bridge windows), as long as the host bridge intercepts it (and endpoints do _not_ reuse it for something else) that should be fine, as it has been pointed out in this thread, allocating a page is a solution
- there may be others (which are likely to be platform specific).
Quoted 15 lines
Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.
Quoted 4 lines
If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.
I will look into this with Robin's help.
Thanks,
Lorenzo
Quoted 5 lines
Quoted 1 line
Quoted 1 line
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1537
Quoted 1 line
drivers/pci/host/pci-tegra.c +0
-0afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d7bd554f27c9
Quoted 48 lines · Lorenzo Pieralisi
[+Robin]
Quoted 45 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 26 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Zone ranges: DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
The great thing about ZONE_DMA is that it has completely different meanings per platform. ZONE_DMA32 is even worse as it's more or less just an x86 thing, and isn't implemented (thus does nothing) on most other architectures, including ARM/arm64 where Tegra is relevant.
Fun.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().I had a quick chat with Robin (CC'ed, who has dealt/is dealing with most of the work this thread relates to) and I think that as things stand, for MSI physical addresses, an offset between
PCI->hostaddress shift is not really contemplated (ie 1:1 host<->pci is assumed).
I think the most correct way to generate an address would actually be via the DMA mapping API (i.e. dma_map_page() with the host bridge's PCI device), which would take any relevant offsets into account. It's a bit funky, but there's some method in the madness.
Quoted 18 lines
Quoted 14 lines
Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Quoted 3 lines
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?
Quoted 26 lines
IIUC, all these host bridges need is a physical address that is routed upstream to the host bridge by the PCIe tree (ie it is not part of the host bridge windows), as long as the host bridge intercepts it (and endpoints do _not_ reuse it for something else) that should be fine, as it has been pointed out in this thread, allocating a page is a solution
- there may be others (which are likely to be platform specific).Quoted 19 lines
Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.
The really neat version is to take a known non-memory physical address like the host controller's own MMIO region, which has no legitimate reason to ever be used as a DMA address. pcie-mediatek almost gets this right, but by using virt_to_phys() on an ioremapped address they end up with nonsense rather than the correct address (although realistically you would have to be extremely unlucky for said nonsense to collide with a real DMA address given to a PCI endpoint later). Following on from above, dma_map_resource() would be the foolproof way to get that right.
Robin.
Quoted 11 lines
I will look into this with Robin's help.
Thanks,
LorenzoQuoted 5 lines
Quoted 1 line
Quoted 1 line
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1537
Quoted 1 line
drivers/pci/host/pci-tegra.c +0
-0afi_writel (pcie, msi->phys >> soc->msi_base_shift,AFI_MSI_FPCI_BAR_ST );[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d7bd554f27c9
Quoted 117 lines · Robin Murphy
Quoted 48 lines · Lorenzo Pieralisi
[+Robin]
Quoted 45 lines · Bjorn Helgaas
[+cc Lorenzo]
Quoted 26 lines · Vidya Sagar
Quoted 11 lines · Bjorn Helgaas
Quoted 10 lines · Vidya Sagar
limits MSI target address to only 32-bit region to enable some of the PCIe end points where only 32-bit MSIs are supported work properly.
One example being Marvel SATA controllerSigned-off-by Vidya Sagar <[email protected]>--- drivers/pci/host/pci-tegra.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
drivers/pci/host/pci-tegra.c static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) · line 1534
Quoted 10 lines
drivers/pci/host/pci-tegra.c +1
-1@@ -1531,7 +1531,7 @@ static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) }/* setup AFI/FPCI range */ - msi->pages =__get_free_pages (GFP_KERNEL ,0 ); + msi->pages =__get_free_pages (GFP_DMA ,0 ); msi->phys =virt_to_phys ((void *)msi->pages);Should this be
GFP_DMA32? See the comment above theGFP_DMAdefinition.Quoted 4 lines
looking at the comments for both
GFP_DMA32andGFP_DMA, I thoughtGFP_DMA32is the correct one to use, but, even with that I got >32-bit addresses.GFP_DMAalways gives addresses in <4GB boundary (i.e. 32-bit). I didn't dig into it to find out why is this the case.This sounds worth looking into (but maybe we don't need the
__get_free_pages()at all; see below). Maybe there's some underlying bug. My laptop shows this, which looks like it might be related:Zone ranges: DMA [mem 0x0000000000001000-0x0000000000ffffff] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] Normal [mem 0x0000000100000000-0x00000004217fffff] Device emptyWhat does your machine show?
The great thing about
ZONE_DMAis that it has completely different meanings per platform.ZONE_DMA32is even worse as it's more or less just an x86 thing, and isn't implemented (thus does nothing) on most other architectures, including ARM/arm64 where Tegra is relevant.Fun.
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Should we be using
virt_to_phys()here? Where exactly is the result ("msi->phys") used, i.e., what bus will that address appear on? If it appears on the PCI side, this should probably use something likepcibios_resource_to_bus().I had a quick chat with Robin (CC'ed, who has dealt/is dealing with most of the work this thread relates to) and I think that as things stand, for MSI physical addresses, an offset between
PCI->hostaddress shift is not really contemplated (ie 1:1 host<->pci is assumed).I think the most correct way to generate an address would actually be via the DMA mapping API (i.e.
dma_map_page()with the host bridge's PCI device), which would take any relevant offsets into account. It's a bit funky, but there's some method in the madness.Quoted 18 lines
Quoted 14 lines
Quoted 7 lines
This address is written to two places. First, into host's internal register to let it know that when an incoming memory write comes with this address, raise an MSI interrupt instead of forwarding it to memory subsystem. Second, into 'Message Address' field of 'Message Address Register for MSI' register in end point's configuration space (this is done by MSI framework) for end point to know which address to be used to generate MSI interrupt.
Hmmm, ISTR some past discussion about this. Here's a little: [1, 2]. And this commit [3] sounds like it describes a similar hardware situation with Tegra where the host bridge intercepts the MSI target address, so writes to it never reach system memory. That means that Tegra doesn't need to allocate system memory at all.
Quoted 3 lines
Is your system similar? Can you just statically allocate a little bus address space, use that for the MSI target address, and skip the
__get_free_pages()?Quoted 26 lines
IIUC, all these host bridges need is a physical address that is routed upstream to the host bridge by the PCIe tree (ie it is not part of the host bridge windows), as long as the host bridge intercepts it (and endpoints do _not_ reuse it for something else) that should be fine, as it has been pointed out in this thread, allocating a page is a solution
- there may be others (which are likely to be platform specific).Quoted 19 lines
Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.
Quoted 8 lines
The really neat version is to take a known non-memory physical address like the host controller's own MMIO region, which has no legitimate reason to ever be used as a DMA address. pcie-mediatek almost gets this right, but by using
virt_to_phys()on an ioremapped address they end up with nonsense rather than the correct address (although realistically you would have to be extremely unlucky for said nonsense to collide with a real DMA address given to a PCI endpoint later). Following on from above,dma_map_resource()would be the foolproof way to get that right.
Yes, that was our intention as well. Our initial plan was to use an address from the PCI aperture within Tegra that wasn't being used for any other purpose. However, we ran into some odd corner cases where this wasn't working as expected. As a temporary solution we wanted to move to GFP_DMA32 (or GFP_DMA) in order to support 32-bit only MSI endpoints.
Eventually we'll want to get rid of the allocation altogether, we just need to find a set of values that work reliably. In the meantime, it looks as though GFP_DMA would be the right solution as long as we have to stick with __get_free_pages().
Alternatively, since we've already verified that the MSI writes are never committed to memory, we could choose some random address pointing to system memory as well, but I'm reluctant to do that because it could end up being confusing for users (and developers) to see some random address showing up somewhere. A physical address such as the beginning of system memory should always work and might be unique enough to indicate that it is special.
Thierry
[+ryder]
On Fri, Nov 10, 2017 at 02:07:05PM +0100, Thierry Reding wrote:
[...]
Quoted 9 lines
Quoted 8 lines
The really neat version is to take a known non-memory physical address like the host controller's own MMIO region, which has no legitimate reason to ever be used as a DMA address. pcie-mediatek almost gets this right, but by using
virt_to_phys()on an ioremapped address they end up with nonsense rather than the correct address (although realistically you would have to be extremely unlucky for said nonsense to collide with a real DMA address given to a PCI endpoint later). Following on from above,dma_map_resource()would be the foolproof way to get that right.
Quoted 3 lines
Yes, that was our intention as well. Our initial plan was to use an address from the PCI aperture within Tegra that wasn't being used for any other purpose.
Hi Thierry,
to wrap up this thread, why an address from the PCI aperture and not a host bridge register ?
I CC'ed Ryder so that he can explain to me please what:
PCIE_MSI_VECTOR and PCIE_IMSI_ADDR offsets in:
register space represent (IIUC the driver uses:
virt_to_phys(port->base + PCIE_MSI_VECTOR);
as MSI doorbell address, which is wrong anyway as Robin explained, just want to understand how that register was chosen - it is never written or read in the driver so it is hard to figure that out) to understand whether the approach can be replicated instead of relying on GFP_DMA for pages allocation.
Thanks,
Lorenzo
Quoted 18 lines
However, we ran into some odd corner cases where this wasn't working as expected. As a temporary solution we wanted to move to
GFP_DMA32(orGFP_DMA) in order to support 32-bit only MSI endpoints.Eventually we'll want to get rid of the allocation altogether, we just need to find a set of values that work reliably. In the meantime, it looks as though
GFP_DMAwould be the right solution as long as we have to stick with__get_free_pages().Alternatively, since we've already verified that the MSI writes are never committed to memory, we could choose some random address pointing to system memory as well, but I'm reluctant to do that because it could end up being confusing for users (and developers) to see some random address showing up somewhere. A physical address such as the beginning of system memory should always work and might be unique enough to indicate that it is special.
Thierry
On Fri, Nov 10, 2017 at 12:04:21PM +0000, Robin Murphy wrote:
[...]
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 9 lines
Quoted 4 lines
Do
rcar_pcie_enable_msi()andxilinx_pcie_enable_msi()have a similar problem? They both useGFP_KERNEL, thenvirt_to_phys(), then write the result ofvirt_to_phys()using a 32-bit register write.Well, if those systems deal with 64-bit addresses and when an end point is connected which supports only 32-bit MSI addresses, this problem will surface when
__get_free_pages()returns an address that translates to a >32-bit address aftervirt_to_phys()call on it.I'd like to hear from the R-Car and Xilinx folks about (1) whether there's a potential issue with truncating a 64-bit address, and
(2) whether that hardware works like Tegra, where the MSI write never reaches memory so we don't actually need to allocate a page.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
If all we need is to allocate a little bus address space for the MSI target, I'd like to figure out a better way to do that than
__get_free_pages(). The current code seems a little buggy, and it's getting propagated through several drivers.The really neat version is to take a known non-memory physical address like the host controller's own MMIO region, which has no legitimate reason to ever be used as a DMA address.
True - that could be safe enough.
What about IOVAs though ? I suspect we should reserve the MSI address range - it looks like there is something missing here.
Quoted 3 lines
pcie-mediatek almost gets this right, but by using
virt_to_phys()on an ioremapped address they end up with nonsense rather than the correct address
That definitely needs fixing given that it works by chance.
Quoted 4 lines
(although realistically you would have to be extremely unlucky for said nonsense to collide with a real DMA address given to a PCI endpoint later). Following on from above,
dma_map_resource()would be the foolproof way to get that right.
That's how it should be done then lest it trickles into other drivers requiring a similar set-up.
Thanks,
Lorenzo