Message ID | 20190311133122.11417-2-s.miroshnichenko@yadro.com (mailing list archive) |
---|---|
State | New, archived |
Delegated to: | Bjorn Helgaas |
Headers | show |
Series | PCI: Allow BAR movement during hotplug | expand |
Hi Sergey, Thanks for all your work here. This is a long-standing problem, and I'm glad you're working on it. On Mon, Mar 11, 2019 at 04:31:02PM +0300, Sergey Miroshnichenko wrote: > If BAR movement has happened (due to PCIe hotplug) after pci_save_state(), > the saved addresses will become outdated. Restore them the most recently > calculated values, not the ones stored in an arbitrary moment. Maybe pci_save_state() should not even save BAR values, since we have no mechanism to determine whether those saved values are valid? > Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com> > --- > drivers/pci/pci.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 7c1b362f599a..f006068be209 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -1376,7 +1376,7 @@ static void pci_restore_config_space(struct pci_dev *pdev) > if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) { > pci_restore_config_space_range(pdev, 10, 15, 0, false); > /* Restore BARs before the command register. */ > - pci_restore_config_space_range(pdev, 4, 9, 10, false); > + pci_restore_bars(pdev); pci_restore_bars() is a much longer call path than pci_restore_config_space_range(), so it's a little bit scary just from the complexity point of view, but I think this does make sense. But I am concerned that we don't handle bridge BARs the same way (this is an existing problem, not something you're introducing). Bridge BARs (if implemented) are dwords 4 and 5, so they are currently restored as part of this range: pci_restore_config_space_range(pdev, 0, 8, 0, false); If we followed the same pattern as for type 0 devices, this would look like: pci_restore_config_space_range(pdev, 6, 8, 0, false); pci_restore_config_space_range(pdev, 4, 5, 10, false); /* BARs */ pci_restore_config_space_range(pdev, 0, 3, 0, false); And after your patch, it would look like: pci_restore_config_space_range(pdev, 6, 8, 0, false); pci_restore_bars(pdev); pci_restore_config_space_range(pdev, 0, 3, 0, false); I think this would require a little enhancement in pci_restore_bars() to filter the BAR range based on the hdr_type. I would propose - adding a new patch to split up the bridge restore so the (0, 8) range is split into (6, 8); (4, 5); (0, 3), so it matches the type 0 restore. - adding another new patch to filter the BAR range in pci_restore_bars(). - updating this patch to use pci_restore_bars() in both the type 0 and type 1 paths. - possibly adding a patch to make pci_save_state() not save BAR values in dev->saved_config_space, and any other changes needed to stop reading BARs from that area. What do you think? > pci_restore_config_space_range(pdev, 0, 3, 0, false); > } else if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { > pci_restore_config_space_range(pdev, 12, 15, 0, false); > -- > 2.20.1 >
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7c1b362f599a..f006068be209 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1376,7 +1376,7 @@ static void pci_restore_config_space(struct pci_dev *pdev) if (pdev->hdr_type == PCI_HEADER_TYPE_NORMAL) { pci_restore_config_space_range(pdev, 10, 15, 0, false); /* Restore BARs before the command register. */ - pci_restore_config_space_range(pdev, 4, 9, 10, false); + pci_restore_bars(pdev); pci_restore_config_space_range(pdev, 0, 3, 0, false); } else if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { pci_restore_config_space_range(pdev, 12, 15, 0, false);
If BAR movement has happened (due to PCIe hotplug) after pci_save_state(), the saved addresses will become outdated. Restore them the most recently calculated values, not the ones stored in an arbitrary moment. Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com> --- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)