Skip to contentSkip to conversation

PCI: hv: New paravirtual PCI front-end driver

PATCH RESEND Applied [email protected] 2 participants 5 messages Feb 16, 2016 – Feb 17, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover PCI: hv: New paravirtual PCI front-end driver

From: Jake Oshins <[email protected]>

This version incorporates more feedback from Bjorn Helgaas. Most notably, I removed some debugging code and I consistently used architectural means for getting the PCI domain instead of just reaching into the sysdata.

This is a resend of patches that enable PCI pass-through within Hyper-V VMs. This patch series only includes those which were deemed appropriate for being incorportated via the PCI tree. All other patches in previous patch series have gone through other trees and are now in mainline.

The first two patches modify PCI so that new root PCI buses can be marked with an associated fwnode_handle, and so that root PCI buses can look up their associated IRQ domain by that handle.

The last patch, introduces a new driver, hv_pcifront, which exposes root PCI buses in a Hyper-V VM. These root PCI buses expose real PCIe devices, or PCI Virtual Functions.

Jake Oshins (3):
PCI: Add fwnode_handle to pci_sysdata
PCI: irqdomain: Look up IRQ domain by fwnode_handle
PCI: hv: New paravirtual PCI front-end for Hyper-V VMs

 MAINTAINERS                   |    1 +
 arch/x86/include/asm/pci.h    |   15 +
 drivers/pci/Kconfig           |    7 +
 drivers/pci/host/Makefile     |    1 +
 drivers/pci/host/pci-hyperv.c | 2359 +++++++++++++++++++++++++++++++++++++++++
 drivers/pci/probe.c           |   15 +
 include/linux/pci.h           |    4 +
 7 files changed, 2402 insertions(+)
 create mode 100644 drivers/pci/host/pci-hyperv.c

--
1.9.1

#1 lore raw

PATCH RESEND v3 1/3 PCI: Add fwnode_handle to pci_sysdata

From: Jake Oshins <[email protected]>

This patch adds an fwnode_handle to struct pci_sysdata, which is used by the next patch in the series when trying to locate an IRQ domain associated with a root PCI bus.

---
 arch/x86/include/asm/pci.h | 15 +++++++++++++++
 include/linux/pci.h        |  4 ++++
 2 files changed, 19 insertions(+)
arch/x86/include/asm/pci.h +15 -0
index 4625943..6fc3c7c 100644
@@ -20,6 +20,9 @@ struct pci_sysdata {
 #ifdef CONFIG_X86_64
 	void		*iommu;		/* IOMMU private data */
 #endif
+#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
+	void		*fwnode;	/* IRQ domain for MSI assignment */
+#endif
 };
 
 extern int pci_routeirq;
@@ -32,6 +35,7 @@ extern int noioapicreroute;
 static inline int pci_domain_nr(struct pci_bus *bus)
 {
 	struct pci_sysdata *sd = bus->sysdata;
+
 	return sd->domain;
 }
 
@@ -41,6 +45,17 @@ static inline int pci_proc_domain(struct pci_bus *bus)
 }
 #endif
 
+#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
+static inline void *_pci_root_bus_fwnode(struct pci_bus *bus)
+{
+	struct pci_sysdata *sd = bus->sysdata;
+
+	return sd->fwnode;
+}
+
+#define pci_root_bus_fwnode	_pci_root_bus_fwnode
+#endif
+
 /* Can be used to override the logic in pci_scan_bus for skipping
    already-configured bus numbers - to be used for buggy BIOSes
    or architectures with incomplete PCI setup by the loader */
include/linux/pci.h +4 -0
index 27df4a6..1bb44af 100644
@@ -1515,6 +1515,10 @@ static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
 
 #include <asm/pci.h>
 
+#ifndef pci_root_bus_fwnode
+#define pci_root_bus_fwnode(bus)	NULL
+#endif
+
 /* these helpers provide future and backwards compatibility
  * for accessing popular PCI BAR info */
 #define pci_resource_start(dev, bar)	((dev)->resource[(bar)].start)
Signature · 1 line
1.9.1
#2 lore raw

PATCH RESEND v3 2/3 PCI: irqdomain: Look up IRQ domain by fwnode_handle

In reply to [email protected]

From: Jake Oshins <[email protected]>

This patch adds a second way of finding an IRQ domain associated with a root PCI bus. After looking to see if one can be found through the OF tree, it attempts to look up the IRQ domain through an fwnode_handle stored in the pci_sysdata struct.

---
 drivers/pci/probe.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/pci/probe.c +15 -0
index 6d7ab9b..1e34d21 100644
@@ -15,6 +15,7 @@
 #include <linux/pci-aspm.h>
 #include <linux/aer.h>
 #include <linux/acpi.h>
+#include <linux/irqdomain.h>
 #include <asm-generic/pci-bridge.h>
 #include "pci.h"
 
@@ -675,6 +676,20 @@ static struct irq_domain *pci_host_bridge_msi_domain(struct pci_bus *bus)
 	if (!d)
 		d = pci_host_bridge_acpi_msi_domain(bus);
 
+#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
+	/*
+	 * If no IRQ domain was found via the OF tree, try looking it up
+	 * directly through the fwnode_handle.
+	 */
+	if (!d) {
+		struct fwnode_handle *fwnode = pci_root_bus_fwnode(bus);
+
+		if (fwnode)
+			d = irq_find_matching_fwnode(fwnode,
+						     DOMAIN_BUS_PCI_MSI);
+	}
+#endif
+
 	return d;
 }
 
Signature · 1 line
1.9.1
#3 lore raw

PATCH RESEND v3 3/3 PCI: hv: New paravirtual PCI front-end for Hyper-V VMs

In reply to [email protected]

From: Jake Oshins <[email protected]>

This patch introduces a new driver which exposes a root PCI bus whenever a PCI Express device is passed through to a guest VM under Hyper-V. The device can be single- or multi-function. The interrupts for the devices are managed by an IRQ domain, implemented within the driver.

---
 MAINTAINERS                   |    1 +
 drivers/pci/Kconfig           |    7 +
 drivers/pci/host/Makefile     |    1 +
 drivers/pci/host/pci-hyperv.c | 2359 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 2368 insertions(+)
 create mode 100644 drivers/pci/host/pci-hyperv.c
MAINTAINERS +1 -0
index 30aca4a..b68c015 100644
@@ -5193,6 +5193,7 @@ F:	arch/x86/kernel/cpu/mshyperv.c
 F:	drivers/hid/hid-hyperv.c
 F:	drivers/hv/
 F:	drivers/input/serio/hyperv-keyboard.c
+F:	drivers/pci/host/pci-hyperv.c
 F:	drivers/net/hyperv/
 F:	drivers/scsi/storvsc_drv.c
 F:	drivers/video/fbdev/hyperv_fb.c
drivers/pci/Kconfig +7 -0
index 73de4ef..54a5441 100644
@@ -118,4 +118,11 @@ config PCI_LABEL
 	def_bool y if (DMI || ACPI)
 	select NLS
 
+config PCI_HYPERV
+        tristate "Hyper-V PCI Frontend"
+        depends on PCI && X86 && HYPERV && PCI_MSI && PCI_MSI_IRQ_DOMAIN && X86_64
+        help
+          The PCI device frontend driver allows the kernel to import arbitrary
+          PCI devices from a PCI backend to support PCI driver domains.
+
 source "drivers/pci/host/Kconfig"
drivers/pci/host/Makefile +1 -0
index 7b2f20c..152daf9 100644
@@ -2,6 +2,7 @@ obj-$(CONFIG_PCIE_DW) += pcie-designware.o
 obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o
 obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
 obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
+obj-$(CONFIG_PCI_HYPERV) += pci-hyperv.o
 obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
 obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
 obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o
drivers/pci/host/pci-hyperv.c new file +2359 -0

2,359 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw
In reply to [email protected]
Quoted 24 lines · On Tue, Feb 16, 2016 at 09:56:20PM +0000, [email protected] wrote:

From: Jake Oshins <[email protected]>

This version incorporates more feedback from Bjorn Helgaas. Most notably, I removed some debugging code and I consistently used architectural means for getting the PCI domain instead of just reaching into the sysdata.

This is a resend of patches that enable PCI pass-through within Hyper-V VMs. This patch series only includes those which were deemed appropriate for being incorportated via the PCI tree. All other patches in previous patch series have gone through other trees and are now in mainline.

The first two patches modify PCI so that new root PCI buses can be marked with an associated fwnode_handle, and so that root PCI buses can look up their associated IRQ domain by that handle.

The last patch, introduces a new driver, hv_pcifront, which exposes root PCI buses in a Hyper-V VM. These root PCI buses expose real PCIe devices, or PCI Virtual Functions.

Jake Oshins (3):
PCI: Add fwnode_handle to pci_sysdata
PCI: irqdomain: Look up IRQ domain by fwnode_handle
PCI: hv: New paravirtual PCI front-end for Hyper-V VMs

Quoted 9 lines
 MAINTAINERS                   |    1 +
 arch/x86/include/asm/pci.h    |   15 +
 drivers/pci/Kconfig           |    7 +
 drivers/pci/host/Makefile     |    1 +
 drivers/pci/host/pci-hyperv.c | 2359 +++++++++++++++++++++++++++++++++++++++++
 drivers/pci/probe.c           |   15 +
 include/linux/pci.h           |    4 +
 7 files changed, 2402 insertions(+)
 create mode 100644 drivers/pci/host/pci-hyperv.c

Applied to pci/host-hv, thanks, Jake!

This is a new driver, and I don't think there's any risk of breaking anything, so I think we should still be able to merge this for v4.5.

Bjorn