All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix IOMMU setup for hotplugged devices on pseries
@ 2019-09-05  4:22 ` Shawn Anastasio
  0 siblings, 0 replies; 13+ messages in thread
From: Shawn Anastasio @ 2019-09-05  4:22 UTC (permalink / raw)
  To: linux-pci, linuxppc-dev; +Cc: bhelgaas, mpe, aik, benh, sbobroff, oohall

On pseries QEMU guests, IOMMU setup for hotplugged PCI devices is currently
broken for all but the first device on a given bus. The culprit is an ordering
issue in the pseries hotplug path (via pci_rescan_bus()) which results in IOMMU
group assigment occuring before device registration in sysfs. This triggers
the following check in arch/powerpc/kernel/iommu.c:

/*
 * The sysfs entries should be populated before
 * binding IOMMU group. If sysfs entries isn't
 * ready, we simply bail.
 */
if (!device_is_registered(dev))
	return -ENOENT;

This fails for hotplugged devices since the pcibios_add_device() call in the
pseries hotplug path (in pci_device_add()) occurs before device_add().
Since the IOMMU groups are set up in pcibios_add_device(), this means that a
sysfs entry will not yet be present and it will fail.

There is a special case that allows the first hotplugged device on a bus to
succeed, though. The powerpc pcibios_add_device() implementation will skip
initializing the device if bus setup is not yet complete.
Later, the pci core will call pcibios_fixup_bus() which will perform setup
for the first (and only) device on the bus and since it has already been
registered in sysfs, the IOMMU setup will succeed.

My current solution is to introduce another pcibios function, pcibios_fixup_dev,
which is called after device_add() in pci_device_add(). Then in powerpc code,
pcibios_setup_device() was moved from pcibios_add_device() to this new function
which will occur after sysfs registration so IOMMU assignment will succeed.

I added a new pcibios function rather than moving the pcibios_add_device() call
to after the device_add() call in pci_add_device() because there are other
architectures that use it and it wasn't immediately clear to me whether moving
it would break them.

If anybody has more insight or a better way to fix this, please let me know.

Shawn Anastasio (2):
  PCI: Introduce pcibios_fixup_dev()
  powerpc/pci: Fix IOMMU setup for hotplugged devices on pseries

 arch/powerpc/kernel/pci-common.c | 13 ++++++-------
 drivers/pci/probe.c              | 14 ++++++++++++++
 include/linux/pci.h              |  1 +
 3 files changed, 21 insertions(+), 7 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-09-05 18:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05  4:22 [PATCH 0/2] Fix IOMMU setup for hotplugged devices on pseries Shawn Anastasio
2019-09-05  4:22 ` Shawn Anastasio
2019-09-05  4:22 ` [PATCH 1/2] PCI: Introduce pcibios_fixup_dev() Shawn Anastasio
2019-09-05  4:22   ` Shawn Anastasio
2019-09-05  4:22 ` [PATCH 2/2] powerpc/pci: Fix IOMMU setup for hotplugged devices on pseries Shawn Anastasio
2019-09-05  4:22   ` Shawn Anastasio
2019-09-05  9:08 ` [PATCH 0/2] " Alexey Kardashevskiy
2019-09-05  9:08   ` Alexey Kardashevskiy
2019-09-05 17:59   ` Shawn Anastasio
2019-09-05 17:59     ` Shawn Anastasio
2019-09-05  9:38 ` Lukas Wunner
2019-09-05 18:42   ` Shawn Anastasio
2019-09-05 18:42     ` Shawn Anastasio

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.