pci: avoid bridge feature re-probing on hotplug
Subsystems (2)
PATCH 1/1 pci: avoid bridge feature re-probing on hotplug
commit 1f82de10d6 ("PCI/x86: don't assume prefetchable ranges are 64bit") added probing of bridge support for 64 bit memory each time bridge is re-enumerated.
Unfortunately this probing is destructive if any device behind the bridge is in use at this time.
There's no real need to re-probe the bridge features as the regiters in question never change - detect that using
the memory flag being set and skip the probing.
Avoiding repeated calls to pci_bridge_check_ranges might be even nicer would be a bigger patch and probably not appropriate on stable.
---
This issue has been reported on upstream Linux and Centos.
drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/pci/setup-bus.c +7 -0
@@ -741,6 +741,13 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)struct resource *b_res; b_res = &bridge->resource[PCI_BRIDGE_RESOURCES ]; + +/* Don't re-check after this was called once already: +* important since bridge might be in use. +*/ +if (b_res[1 ].flags &IORESOURCE_MEM ) +return ; + b_res[1 ].flags |=IORESOURCE_MEM ;pci_read_config_word (bridge,PCI_IO_BASE , &io);
Signature · 1 line
MST
Quoted 24 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, December 11, 2018 10:19 AM
To: [email protected]
Cc: xuyandong <[email protected]>; [email protected]; Yinghai Lu <[email protected]>; Jesse Barnes <[email protected]>; Bjorn Helgaas <[email protected]>; [email protected]
Subject: [PATCH] pci: avoid bridge feature re-probing on hotplugcommit
1f82de10d6("PCI/x86: don't assume prefetchable ranges are 64bit") added probing of bridge support for 64 bit memory each time bridge is re-enumerated.Unfortunately this probing is destructive if any device behind the bridge is in use at this time.
There's no real need to re-probe the bridge features as the regiters in question never change - detect that using the memory flag being set and skip the probing.
Avoiding repeated calls topci_bridge_check_rangesmight be even nicer would be a bigger patch and probably not appropriate on stable.
Quoted 5 lines
Reported-by xuyandong <[email protected]>Cc Yinghai Lu <[email protected]>Cc Jesse Barnes <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>
Quoted 28 lines
---
This issue has been reported on upstream Linux and Centos.
drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/pci/setup-bus.c index renamed from drivers/pci/setup-bus.c +0
-0
ed960436df5e..7ab42f76579e100644drivers/pci/setup-bus.c +7
-0@@ -741,6 +741,13 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)struct resource *b_res; b_res = &bridge->resource[PCI_BRIDGE_RESOURCES ]; + +/* Don't re-check after this was called once already: +* important since bridge might be in use. +*/ +if (b_res[1 ].flags &IORESOURCE_MEM ) +return ; + b_res[1 ].flags |=IORESOURCE_MEM ;
pci_read_config_word(bridge, PCI_IO_BASE, &io);
--
MST
Quoted 24 lines · xuyandong
Quoted 24 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, December 11, 2018 10:19 AM
To: [email protected]
Cc: xuyandong <[email protected]>; [email protected]; Yinghai Lu <[email protected]>; Jesse Barnes <[email protected]>; Bjorn Helgaas <[email protected]>; [email protected]
Subject: [PATCH] pci: avoid bridge feature re-probing on hotplugcommit
1f82de10d6("PCI/x86: don't assume prefetchable ranges are 64bit") added probing of bridge support for 64 bit memory each time bridge is re-enumerated.Unfortunately this probing is destructive if any device behind the bridge is in use at this time.
There's no real need to re-probe the bridge features as the regiters in question never change - detect that using the memory flag being set and skip the probing.
Avoiding repeated calls topci_bridge_check_rangesmight be even nicer would be a bigger patch and probably not appropriate on stable.
Quoted 7 lines
Quoted 5 lines
Reported-by xuyandong <[email protected]>Cc Yinghai Lu <[email protected]>Cc Jesse Barnes <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>Tested-by xuyandong <[email protected]>
Bjorn could you queue this for this release?
Quoted 28 lines
Quoted 28 lines
---
This issue has been reported on upstream Linux and Centos.
drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/pci/setup-bus.c index renamed from drivers/pci/setup-bus.c +0
-0
ed960436df5e..7ab42f76579e100644drivers/pci/setup-bus.c +7
-0@@ -741,6 +741,13 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)struct resource *b_res; b_res = &bridge->resource[PCI_BRIDGE_RESOURCES ]; + +/* Don't re-check after this was called once already: +* important since bridge might be in use. +*/ +if (b_res[1 ].flags &IORESOURCE_MEM ) +return ; + b_res[1 ].flags |=IORESOURCE_MEM ;
pci_read_config_word(bridge, PCI_IO_BASE, &io);
--
MST
Hi Michael,
Please run "git log --oneline drivers/pci/setup-bus.c" and follow the usual style.
Quoted 3 lines · Michael S. Tsirkin
commit
1f82de10d6("PCI/x86: don't assume prefetchable ranges are 64bit") added probing of bridge support for 64 bit memory each time bridge is re-enumerated.
Use conventional SHA1 reference (12-char SHA1).
Quoted 2 lines
Unfortunately this probing is destructive if any device behind the bridge is in use at this time.
Agreed, this sounds like a problem.
Quoted 3 lines
There's no real need to re-probe the bridge features as the regiters in question never change - detect that using the memory flag being set and skip the probing.
s/regiters/registers/
Quoted 2 lines
Avoiding repeated calls to
pci_bridge_check_rangesmight be even nicer would be a bigger patch and probably not appropriate on stable.
Maybe so. The ideal thing might be to have a trivial patch like this that can be marked for stable, immediately followed by the nicer patch. Trivial band-aids tend to accumulate and make things harder in the future.
I'd have to take a much harder look at the problem to understand 1f82de10d6b1. The comment about "double check" seems misleading -- as you say, the hardware doesn't change and checking once should be enough. And if we're calling pci_bridge_check_ranges() more than necessary, that sounds like a problem, too.
Quoted 8 lines
Reported-by xuyandong <[email protected]>Cc Yinghai Lu <[email protected]>Cc Jesse Barnes <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
This issue has been reported on upstream Linux and Centos.
Are there URLs to these reports that we could include in the changelog?
Quoted 8 lines
drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/pci/setup-bus.c +0
-0
drivers/pci/setup-bus.c static void pci_bridge_check_ranges(struct pci_bus *bus) · line 749
Quoted 9 lines
drivers/pci/setup-bus.c +6
-0@@ -741,6 +741,13 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)struct resource *b_res; b_res = &bridge->resource[PCI_BRIDGE_RESOURCES ]; + +/* Don't re-check after this was called once already: +* important since bridge might be in use. +*/ +if (b_res[1 ].flags &IORESOURCE_MEM ) +return ;
Use conventional multi-line comment style.
This test isn't 100%: devices below the bridge could be using only IO, or theoretically could be even using just config space.
If it's safe to bail out if the bridge is in use, why isn't it safe to bail out *always*?
Quoted 5 lines
drivers/pci/setup-bus.c +0
-0b_res[1 ].flags |=IORESOURCE_MEM ;pci_read_config_word (bridge,PCI_IO_BASE , &io);Signature · 1 line
MST
Quoted 15 lines · Bjorn Helgaas
Hi Michael,
Please run "git log --oneline
drivers/pci/setup-bus.c" and follow the usual style.Quoted 3 lines · Michael S. Tsirkin
commit
1f82de10d6("PCI/x86: don't assume prefetchable ranges are 64bit") added probing of bridge support for 64 bit memory each time bridge is re-enumerated.Use conventional SHA1 reference (12-char SHA1).
Quoted 2 lines
Unfortunately this probing is destructive if any device behind the bridge is in use at this time.
Quoted 7 lines
Agreed, this sounds like a problem.
Quoted 3 lines
There's no real need to re-probe the bridge features as the regiters in question never change - detect that using the memory flag being set and skip the probing.
s/regiters/registers/
Will address above.
Quoted 7 lines
Quoted 2 lines
Avoiding repeated calls to
pci_bridge_check_rangesmight be even nicer would be a bigger patch and probably not appropriate on stable.Maybe so. The ideal thing might be to have a trivial patch like this that can be marked for stable, immediately followed by the nicer patch. Trivial band-aids tend to accumulate and make things harder in the future.
I understand, and I looked at it briefly, but it's not a simple change, with probing taking detours through acpi etc.
I plan to look at it some more but should we release another linux with this bug?
Quoted 5 lines
I'd have to take a much harder look at the problem to understand
1f82de10d6b1. The comment about "double check" seems misleading -- as you say, the hardware doesn't change and checking once should be enough. And if we're callingpci_bridge_check_ranges()more than necessary, that sounds like a problem, too.
So that will kind of make it a non issue. Should we still worry?
Quoted 10 lines
Quoted 8 lines
Reported-by xuyandong <[email protected]>Cc Yinghai Lu <[email protected]>Cc Jesse Barnes <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
This issue has been reported on upstream Linux and Centos.
Are there URLs to these reports that we could include in the changelog?
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg01711.html
and specifically
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg02082.html
Quoted 31 lines
Quoted 8 lines
drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/pci/setup-bus.c +0
-0drivers/pci/setup-bus.c static void pci_bridge_check_ranges(struct pci_bus *bus) · line 749
Quoted 9 lines
drivers/pci/setup-bus.c +6
-0@@ -741,6 +741,13 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)struct resource *b_res; b_res = &bridge->resource[PCI_BRIDGE_RESOURCES ]; + +/* Don't re-check after this was called once already: +* important since bridge might be in use. +*/ +if (b_res[1 ].flags &IORESOURCE_MEM ) +return ;Use conventional multi-line comment style.
This test isn't 100%: devices below the bridge could be using only IO, or theoretically could be even using just config space.
If it's safe to bail out if the bridge is in use, why isn't it safe to bail out *always*?
Quoted 5 lines
drivers/pci/setup-bus.c +0
-0b_res[1 ].flags |=IORESOURCE_MEM ;pci_read_config_word (bridge,PCI_IO_BASE , &io);Signature · 1 line
MST
Quoted 58 lines · Bjorn Helgaas
Hi Michael,
Please run "git log --oneline
drivers/pci/setup-bus.c" and follow the usual style.Quoted 3 lines · Michael S. Tsirkin
commit
1f82de10d6("PCI/x86: don't assume prefetchable ranges are 64bit") added probing of bridge support for 64 bit memory each time bridge is re-enumerated.Use conventional SHA1 reference (12-char SHA1).
Quoted 2 lines
Unfortunately this probing is destructive if any device behind the bridge is in use at this time.
Agreed, this sounds like a problem.
Quoted 3 lines
There's no real need to re-probe the bridge features as the regiters in question never change - detect that using the memory flag being set and skip the probing.
s/regiters/registers/
Quoted 2 lines
Avoiding repeated calls to
pci_bridge_check_rangesmight be even nicer would be a bigger patch and probably not appropriate on stable.Maybe so. The ideal thing might be to have a trivial patch like this that can be marked for stable, immediately followed by the nicer patch. Trivial band-aids tend to accumulate and make things harder in the future.
I'd have to take a much harder look at the problem to understand
1f82de10d6b1. The comment about "double check" seems misleading -- as you say, the hardware doesn't change and checking once should be enough. And if we're callingpci_bridge_check_ranges()more than necessary, that sounds like a problem, too.Quoted 8 lines
Reported-by xuyandong <[email protected]>Cc Yinghai Lu <[email protected]>Cc Jesse Barnes <[email protected]>Signed-off-by Michael S. Tsirkin <[email protected]>---
This issue has been reported on upstream Linux and Centos.
Are there URLs to these reports that we could include in the changelog?
Quoted 10 lines
drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/pci/setup-bus.c +0
-0@@ -741,6 +741,13 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)struct resource *b_res;
Quoted 9 lines
drivers/pci/setup-bus.c static void pci_bridge_check_ranges(struct pci_bus *bus) · line 749
Quoted 7 lines
drivers/pci/setup-bus.c +6
-0b_res = &bridge->resource[PCI_BRIDGE_RESOURCES ]; + +/* Don't re-check after this was called once already: +* important since bridge might be in use. +*/ +if (b_res[1 ].flags &IORESOURCE_MEM ) +return ;Use conventional multi-line comment style.
Will fix.
Quoted 2 lines
This test isn't 100%: devices below the bridge could be using only IO, or theoretically could be even using just config space.
Right but
1. memory is not an optional capability for bridges. All pci bridges support memory bridging (unlike e.g. IO).
2. the line below accordingly sets IORESOURCE_MEM unconditionally even if devices below the bridge only use IO for now.
So IIUC this really results in bailing out if bridge has already been configured. Did I miss something?
Quoted 2 lines
If it's safe to bail out if the bridge is in use, why isn't it safe to bail out *always*?
Well IIUC we need to probe support for optional capabilities such as IO and 64 bit bridging.
this is what this function does, doesn't it?
Quoted 5 lines
Quoted 5 lines
drivers/pci/setup-bus.c +0
-0b_res[1 ].flags |=IORESOURCE_MEM ;pci_read_config_word (bridge,PCI_IO_BASE , &io);Signature · 1 line
MST