Skip to contentSkip to conversation

IOMMU Groups + VFIO

PATCH In review Alex Williamson 2 participants 24 messages May 22, 2012 – May 25, 2012

Subsystems (7)
Documentation KVM PCI Driver core +3 more subsystems
lore
Share & tools
lore
#0 lore raw

v2 cover IOMMU Groups + VFIO

Version 2 incorporating acks and feedback from v1. The PCI DMA quirk and ACS check are reworked, sysfs iommu groups ABI Documentation added as well as numerous other fixes, including patches from Alexey Kardashevskiy towards supporting POWER usage of VFIO and IOMMU groups.

This series can be found here on top of 3.4:

git://github.com/awilliam/linux-vfio.git iommu-group-vfio-20120521

The Qemu tree has also been updated to Qemu 1.1 and can be found here:

git://github.com/awilliam/qemu-vfio.git iommu-group-vfio

I'd really like to make a push to get this in for 3.5, so let's talk about how to do that across iommu, pci, and new driver. Joerg, are you sufficiently happy with the IOMMU group concept and code? We'll also need David Woodhouse buyin on the intel-iommu changes in patches 3 & 6. Who needs to approve VFIO as a new driver, GregKH? Bjorn, I'd be happy to send the PCI changes as a series for you, but I wonder if it makes sense to collect acks for them if you approve and bundle them in with the associated code that needs them so you're not left with unused code. Let me know which you prefer. If there are better ways to do it, please let me know. Thanks,

Alex

---

Alex Williamson (13):
vfio: Add PCI device driver
pci: Misc pci_reg additions
pci: Create common pcibios_err_to_errno
pci: export pci_user functions for use by other drivers
vfio: x86 IOMMU implementation
vfio: Add documentation
vfio: VFIO core
iommu: Make use of DMA quirking and ACS enabled check for groups
pci: Add ACS validation utility
pci: Add PCI DMA source ID quirk
iommu: IOMMU groups for VT-d and AMD-Vi
iommu: IOMMU Groups
driver core: Add iommu_group tracking to struct device

 .../ABI/testing/sysfs-kernel-iommu_groups          |   14 
 Documentation/ioctl/ioctl-number.txt               |    1 
 Documentation/vfio.txt                             |  315 ++++
 MAINTAINERS                                        |    8 
 drivers/Kconfig                                    |    2 
 drivers/Makefile                                   |    1 
 drivers/iommu/amd_iommu.c                          |   67 +
 drivers/iommu/intel-iommu.c                        |   87 +
 drivers/iommu/iommu.c                              |  578 +++++++-
 drivers/pci/access.c                               |    6 
 drivers/pci/pci.c                                  |   76 +
 drivers/pci/pci.h                                  |    7 
 drivers/pci/quirks.c                               |   69 +
 drivers/vfio/Kconfig                               |   16 
 drivers/vfio/Makefile                              |    3 
 drivers/vfio/pci/Kconfig                           |    8 
 drivers/vfio/pci/Makefile                          |    4 
 drivers/vfio/pci/vfio_pci.c                        |  557 +++++++
 drivers/vfio/pci/vfio_pci_config.c                 | 1522 ++++++++++++++++++++
 drivers/vfio/pci/vfio_pci_intrs.c                  |  724 ++++++++++
 drivers/vfio/pci/vfio_pci_private.h                |   91 +
 drivers/vfio/pci/vfio_pci_rdwr.c                   |  269 ++++
 drivers/vfio/vfio.c                                | 1413 +++++++++++++++++++
 drivers/vfio/vfio_iommu_x86.c                      |  743 ++++++++++
 drivers/xen/xen-pciback/conf_space.c               |    6 
 include/linux/device.h                             |    2 
 include/linux/iommu.h                              |  104 +
 include/linux/pci.h                                |   49 +
 include/linux/pci_regs.h                           |  112 +
 include/linux/vfio.h                               |  444 ++++++
 30 files changed, 7182 insertions(+), 116 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-iommu_groups
 create mode 100644 Documentation/vfio.txt
 create mode 100644 drivers/vfio/Kconfig
 create mode 100644 drivers/vfio/Makefile
 create mode 100644 drivers/vfio/pci/Kconfig
 create mode 100644 drivers/vfio/pci/Makefile
 create mode 100644 drivers/vfio/pci/vfio_pci.c
 create mode 100644 drivers/vfio/pci/vfio_pci_config.c
 create mode 100644 drivers/vfio/pci/vfio_pci_intrs.c
 create mode 100644 drivers/vfio/pci/vfio_pci_private.h
 create mode 100644 drivers/vfio/pci/vfio_pci_rdwr.c
 create mode 100644 drivers/vfio/vfio.c
 create mode 100644 drivers/vfio/vfio_iommu_x86.c
 create mode 100644 include/linux/vfio.h
#1 lore raw

PATCH v2 1/13 driver core: Add iommu_group tracking to struct device

IOMMU groups allow IOMMU drivers to represent DMA visibility and isolation of devices. Multiple devices may be grouped together for the purposes of DMA. Placing a pointer on struct device enable easy access for things like streaming DMA programming and drivers like VFIO.

---

 include/linux/device.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/device.h +2 -0
index 5ad17cc..13dd26b 100644
@@ -35,6 +35,7 @@ struct subsys_private;
 struct bus_type;
 struct device_node;
 struct iommu_ops;
+struct iommu_group;
 
 struct bus_attribute {
 	struct attribute	attr;
@@ -677,6 +678,7 @@ struct device {
 	const struct attribute_group **groups;	/* optional groups */
 
 	void	(*release)(struct device *dev);
+	struct iommu_group	*iommu_group;
 };
 
 /* Get the wakeup routines, which depend on struct device */
#2 lore raw

PATCH v2 2/13 iommu: IOMMU Groups

In reply to Alex Williamson

IOMMU device groups are currently a rather vague associative notion with assembly required by the user or user level driver provider to do anything useful. This patch intends to grow the IOMMU group concept into something a bit more consumable.

To do this, we first create an object representing the group, struct iommu_group. This structure is allocated (iommu_group_alloc) and filled (iommu_group_add_device) by the iommu driver. The iommu driver is free to add devices to the group using it's own set of policies. This allows inclusion of devices based on physical hardware or topology limitations of the platform, as well as soft requirements, such as multi-function trust levels or peer-to-peer protection of the interconnects. Each device may only belong to a single iommu group, which is linked from struct device.iommu_group. IOMMU groups are maintained using kobject reference counting, allowing for automatic removal of empty, unreferenced groups. It is the responsibility of the iommu driver to remove devices from the group (iommu_group_remove_device).

IOMMU groups also include a userspace representation in sysfs under /sys/kernel/iommu_groups. When allocated, each group is given a dynamically assign ID (int). The ID is managed by the core IOMMU group code to support multiple heterogeneous iommu drivers, which could potentially collide in group naming/numbering. This also keeps group IDs to small, easily managed values. A directory is created under /sys/kernel/iommu_groups for each group. A further subdirectory named "devices" contains links to each device within the group. The iommu_group file in the device's sysfs directory, which formerly contained a group number when read, is now a link to the iommu group. Example:

$ ls -l /sys/kernel/iommu_groups/26/devices/
total 0
lrwxrwxrwx. 1 root root 0 Apr 17 12:57 0000:00:1e.0 ->
		../../../../devices/pci0000:00/0000:00:1e.0
lrwxrwxrwx. 1 root root 0 Apr 17 12:57 0000:06:0d.0 ->
		../../../../devices/pci0000:00/0000:00:1e.0/0000:06:0d.0
lrwxrwxrwx. 1 root root 0 Apr 17 12:57 0000:06:0d.1 ->
		../../../../devices/pci0000:00/0000:00:1e.0/0000:06:0d.1
$ ls -l  /sys/kernel/iommu_groups/26/devices/*/iommu_group
[truncating perms/owner/timestamp]
/sys/kernel/iommu_groups/26/devices/0000:00:1e.0/iommu_group ->
					../../../kernel/iommu_groups/26
/sys/kernel/iommu_groups/26/devices/0000:06:0d.0/iommu_group ->
					../../../../kernel/iommu_groups/26
/sys/kernel/iommu_groups/26/devices/0000:06:0d.1/iommu_group ->
					../../../../kernel/iommu_groups/26

Groups also include several exported functions for use by user level driver providers, for example VFIO. These include:

iommu_group_get(): Acquires a reference to a group from a device iommu_group_put(): Releases reference iommu_group_for_each_dev(): Iterates over group devices using callback iommu_group_[un]register_notifier(): Allows notification of device add
and remove operations relevant to the group
iommu_group_id(): Return the group number

This patch also extends the IOMMU API to allow attaching groups to domains. This is currently a simple wrapper for iterating through devices within a group, but it's expected that the IOMMU API may eventually make groups a more integral part of domains.

Groups intentionally do not try to manage group ownership. A user level driver provider must independently acquire ownership for each device within a group before making use of the group as a whole. This may change in the future if group usage becomes more pervasive across both DMA and IOMMU ops.

Groups intentionally do not provide a mechanism for driver locking or otherwise manipulating driver matching/probing of devices within the group. Such interfaces are generic to devices and beyond the scope of IOMMU groups. If implemented, user level providers have ready access via iommu_group_for_each_dev and group notifiers.

iommu_device_group() is removed here as it has no users. The replacement is:

	group = iommu_group_get(dev);
	id = iommu_group_id(group);
	iommu_group_put(group);

AMD-Vi & Intel VT-d support re-added in following patches.

---

 .../ABI/testing/sysfs-kernel-iommu_groups          |   14 
 drivers/iommu/amd_iommu.c                          |   21 -
 drivers/iommu/intel-iommu.c                        |   49 --
 drivers/iommu/iommu.c                              |  578 +++++++++++++++++++-
 include/linux/iommu.h                              |  104 +++-
 5 files changed, 663 insertions(+), 103 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-iommu_groups
Documentation/ABI/testing/sysfs-kernel-iommu_groups new file +14 -0
new file mode 100644
index 0000000..9b31556
@@ -0,0 +1,14 @@
+What:		/sys/kernel/iommu_groups/
+Date:		May 2012
+KernelVersion:	v3.5
+Contact:	Alex Williamson <[email protected]>
+Description:	/sys/kernel/iommu_groups/ contains a number of sub-
+		directories, each representing an IOMMU group.  The
+		name of the sub-directory matches the iommu_group_id()
+		for the group, which is an integer value.  Within each
+		subdirectory is another directory named "devices" with
+		links to the sysfs devices contained in this group.
+		The group directory also optionally contains a "name"
+		file if the IOMMU driver has chosen to register a more
+		common name for the group.
+Users:
drivers/iommu/amd_iommu.c +0 -21
index a5bee8e..32c00cd 100644
@@ -3193,26 +3193,6 @@ static int amd_iommu_domain_has_cap(struct iommu_domain *domain,
 	return 0;
 }
 
-static int amd_iommu_device_group(struct device *dev, unsigned int *groupid)
-{
-	struct iommu_dev_data *dev_data = dev->archdata.iommu;
-	struct pci_dev *pdev = to_pci_dev(dev);
-	u16 devid;
-
-	if (!dev_data)
-		return -ENODEV;
-
-	if (pdev->is_virtfn || !iommu_group_mf)
-		devid = dev_data->devid;
-	else
-		devid = calc_devid(pdev->bus->number,
-				   PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
-
-	*groupid = amd_iommu_alias_table[devid];
-
-	return 0;
-}
-
 static struct iommu_ops amd_iommu_ops = {
 	.domain_init = amd_iommu_domain_init,
 	.domain_destroy = amd_iommu_domain_destroy,
@@ -3222,7 +3202,6 @@ static struct iommu_ops amd_iommu_ops = {
 	.unmap = amd_iommu_unmap,
 	.iova_to_phys = amd_iommu_iova_to_phys,
 	.domain_has_cap = amd_iommu_domain_has_cap,
-	.device_group = amd_iommu_device_group,
 	.pgsize_bitmap	= AMD_IOMMU_PGSIZES,
 };
 
drivers/iommu/intel-iommu.c +0 -49

61 lines not on this page · raw message

drivers/iommu/iommu.c +548 -30

625 lines not on this page · raw message

include/linux/iommu.h +101 -3

147 lines not on this page · raw message

#3 lore raw

PATCH v2 3/13 iommu: IOMMU groups for VT-d and AMD-Vi

In reply to Alex Williamson

Add back group support for AMD & Intel. amd_iommu already tracks devices and has init and uninit routines to manage groups. intel-iommu does this on the fly, so we make use of the notifier support built into iommu groups to create and remove groups.

---

 drivers/iommu/amd_iommu.c   |   28 +++++++++++++++++++++++++-
 drivers/iommu/intel-iommu.c |   46 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletions(-)
drivers/iommu/amd_iommu.c +27 -1
index 32c00cd..b7e5ddf 100644
@@ -256,9 +256,11 @@ static bool check_device(struct device *dev)
 
 static int iommu_init_device(struct device *dev)
 {
-	struct pci_dev *pdev = to_pci_dev(dev);
+	struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev);
 	struct iommu_dev_data *dev_data;
+	struct iommu_group *group;
 	u16 alias;
+	int ret;
 
 	if (dev->archdata.iommu)
 		return 0;
@@ -279,8 +281,30 @@ static int iommu_init_device(struct device *dev)
 			return -ENOTSUPP;
 		}
 		dev_data->alias_data = alias_data;
+
+		dma_pdev = pci_get_bus_and_slot(alias >> 8, alias & 0xff);
+	} else
+		dma_pdev = pdev;
+
+	if (!pdev->is_virtfn && PCI_FUNC(pdev->devfn) && iommu_group_mf &&
+	    pdev->hdr_type == PCI_HEADER_TYPE_NORMAL)
+		dma_pdev = pci_get_slot(pdev->bus,
+					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
+
+	group = iommu_group_get(&dma_pdev->dev);
+	if (!group) {
+		group = iommu_group_alloc();
+		if (IS_ERR(group))
+			return PTR_ERR(group);
 	}
 
+	ret = iommu_group_add_device(group, dev);
+
+	iommu_group_put(group);
+
+	if (ret)
+		return ret;
+
 	if (pci_iommuv2_capable(pdev)) {
 		struct amd_iommu *iommu;
 
@@ -309,6 +333,8 @@ static void iommu_ignore_device(struct device *dev)
 
 static void iommu_uninit_device(struct device *dev)
 {
+	iommu_group_remove_device(dev);
+
 	/*
 	 * Nothing to do here - we keep dev_data around for unplugged devices
 	 * and reuse it when the device is re-plugged - not doing so would
drivers/iommu/intel-iommu.c +46 -0

57 lines not on this page · raw message

#4 lore raw

Re: [PATCH v2 03/13] iommu: IOMMU groups for VT-d and AMD-Vi

Quoted 44 lines · Alex Williamson

Add back group support for AMD& Intel. amd_iommu already tracks devices and has init and uninit routines to manage groups. intel-iommu does this on the fly, so we make use of the notifier support built into iommu groups to create and remove groups.

---

  drivers/iommu/amd_iommu.c   |   28 +++++++++++++++++++++++++-
  drivers/iommu/intel-iommu.c |   46 +++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 73 insertions(+), 1 deletions(-)
drivers/iommu/amd_iommu.c +14 -1
index 32c00cd..b7e5ddf 100644
@@ -256,9 +256,11 @@ static bool check_device(struct device *dev)
 
  static int iommu_init_device(struct device *dev)
  {
-	struct pci_dev *pdev = to_pci_dev(dev);
+	struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev);
  	struct iommu_dev_data *dev_data;
+	struct iommu_group *group;
  	u16 alias;
+	int ret;
 
  	if (dev->archdata.iommu)
  		return 0;
@@ -279,8 +281,30 @@ static int iommu_init_device(struct device *dev)
  			return -ENOTSUPP;
  		}
  		dev_data->alias_data = alias_data;
+
+		dma_pdev = pci_get_bus_and_slot(alias>>  8, alias&  0xff);
+	} else
+		dma_pdev = pdev;
+
+	if (!pdev->is_virtfn&&  PCI_FUNC(pdev->devfn)&&  iommu_group_mf&&
+	    pdev->hdr_type == PCI_HEADER_TYPE_NORMAL)
+		dma_pdev = pci_get_slot(pdev->bus,
+					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
+
+	group = iommu_group_get(&dma_pdev->dev);

drivers/iommu/amd_iommu.c static int iommu_init_device(struct device *dev) · line 304

Quoted 10 lines
drivers/iommu/amd_iommu.c +8 -0
+	if (!group) {
+		group = iommu_group_alloc();
+		if (IS_ERR(group))
+			return PTR_ERR(group);
  	}
 
+	ret = iommu_group_add_device(group, dev);
+
+	iommu_group_put(group);
+

do you want to do a put if there is a failure in the iommu_group_add_device()?

Quoted 48 lines
drivers/iommu/amd_iommu.c +5 -0
+	if (ret)
+		return ret;
+
  	if (pci_iommuv2_capable(pdev)) {
  		struct amd_iommu *iommu;
 
@@ -309,6 +333,8 @@ static void iommu_ignore_device(struct device *dev)
 
  static void iommu_uninit_device(struct device *dev)
  {
+	iommu_group_remove_device(dev);
+
  	/*
  	 * Nothing to do here - we keep dev_data around for unplugged devices
  	 * and reuse it when the device is re-plugged - not doing so would
drivers/iommu/intel-iommu.c +25 -0
index d4a0ff7..e63b33b 100644
@@ -4087,6 +4087,50 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain,
  	return 0;
  }
 
+static int intel_iommu_add_device(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct pci_dev *bridge, *dma_pdev = pdev;
+	struct iommu_group *group;
+	int ret;
+
+	if (!device_to_iommu(pci_domain_nr(pdev->bus),
+			     pdev->bus->number, pdev->devfn))
+		return -ENODEV;
+
+	bridge = pci_find_upstream_pcie_bridge(pdev);
+	if (bridge) {
+		if (pci_is_pcie(bridge))
+			dma_pdev = pci_get_domain_bus_and_slot(
+						pci_domain_nr(pdev->bus),
+						bridge->subordinate->number, 0);
+		else
+			dma_pdev = bridge;
+	}
+
+	if (!pdev->is_virtfn&&  PCI_FUNC(pdev->devfn)&&  iommu_group_mf&&
+	    pdev->hdr_type == PCI_HEADER_TYPE_NORMAL)
+		dma_pdev = pci_get_slot(pdev->bus,
+					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));

drivers/iommu/intel-iommu.c static int intel_iommu_domain_has_cap(struct iommu_domain *domain, · line 4124

Quoted 10 lines
drivers/iommu/intel-iommu.c +10 -0
+
+	group = iommu_group_get(&dma_pdev->dev);
+	if (!group) {
+		group = iommu_group_alloc();
+		if (IS_ERR(group))
+			return PTR_ERR(group);
+	}
+
+	ret = iommu_group_add_device(group, dev);
+

ditto.

Quoted 22 lines
drivers/iommu/intel-iommu.c +11 -0
+	iommu_group_put(group);
+	return ret;
+}
+
+static void intel_iommu_remove_device(struct device *dev)
+{
+	iommu_group_remove_device(dev);
+}
+
  static struct iommu_ops intel_iommu_ops = {
  	.domain_init	= intel_iommu_domain_init,
  	.domain_destroy = intel_iommu_domain_destroy,
@@ -4096,6 +4140,8 @@ static struct iommu_ops intel_iommu_ops = {
  	.unmap		= intel_iommu_unmap,
  	.iova_to_phys	= intel_iommu_iova_to_phys,
  	.domain_has_cap = intel_iommu_domain_has_cap,
+	.add_device	= intel_iommu_add_device,
+	.remove_device	= intel_iommu_remove_device,
  	.pgsize_bitmap	= INTEL_IOMMU_PGSIZES,
  };
 
#5 lore raw

Re: [PATCH v2 03/13] iommu: IOMMU groups for VT-d and AMD-Vi

Quoted 51 lines · Don Dutile
Quoted 50 lines · Alex Williamson

Add back group support for AMD& Intel. amd_iommu already tracks devices and has init and uninit routines to manage groups. intel-iommu does this on the fly, so we make use of the notifier support built into iommu groups to create and remove groups.

---

  drivers/iommu/amd_iommu.c   |   28 +++++++++++++++++++++++++-
  drivers/iommu/intel-iommu.c |   46 +++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 73 insertions(+), 1 deletions(-)
drivers/iommu/amd_iommu.c +18 -1
index 32c00cd..b7e5ddf 100644
@@ -256,9 +256,11 @@ static bool check_device(struct device *dev)
 
  static int iommu_init_device(struct device *dev)
  {
-	struct pci_dev *pdev = to_pci_dev(dev);
+	struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev);
  	struct iommu_dev_data *dev_data;
+	struct iommu_group *group;
  	u16 alias;
+	int ret;
 
  	if (dev->archdata.iommu)
  		return 0;
@@ -279,8 +281,30 @@ static int iommu_init_device(struct device *dev)
  			return -ENOTSUPP;
  		}
  		dev_data->alias_data = alias_data;
+
+		dma_pdev = pci_get_bus_and_slot(alias>>  8, alias&  0xff);
+	} else
+		dma_pdev = pdev;
+
+	if (!pdev->is_virtfn&&  PCI_FUNC(pdev->devfn)&&  iommu_group_mf&&
+	    pdev->hdr_type == PCI_HEADER_TYPE_NORMAL)
+		dma_pdev = pci_get_slot(pdev->bus,
+					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
+
+	group = iommu_group_get(&dma_pdev->dev);
+	if (!group) {
+		group = iommu_group_alloc();
+		if (IS_ERR(group))
+			return PTR_ERR(group);
  	}
 
Quoted 5 lines

drivers/iommu/amd_iommu.c static int iommu_init_device(struct device *dev) · line 304

Quoted 4 lines
drivers/iommu/amd_iommu.c +4 -0
+	ret = iommu_group_add_device(group, dev);
+
+	iommu_group_put(group);
+

do you want to do a put if there is a failure in the iommu_group_add_device()?

Yes, this was intentional. iommu_group_alloc() adds a reference to the group it returns so that it doesn't disappear while we're working on it (documented in iommu.c). iommu_group_get() also gets a reference. So this put will free the group if it was new or just drop the reference if existing. Thanks,

Alex

Quoted 82 lines
Quoted 48 lines
drivers/iommu/amd_iommu.c +5 -0
+	if (ret)
+		return ret;
+
  	if (pci_iommuv2_capable(pdev)) {
  		struct amd_iommu *iommu;
 
@@ -309,6 +333,8 @@ static void iommu_ignore_device(struct device *dev)
 
  static void iommu_uninit_device(struct device *dev)
  {
+	iommu_group_remove_device(dev);
+
  	/*
  	 * Nothing to do here - we keep dev_data around for unplugged devices
  	 * and reuse it when the device is re-plugged - not doing so would
drivers/iommu/intel-iommu.c +25 -0
index d4a0ff7..e63b33b 100644
@@ -4087,6 +4087,50 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain,
  	return 0;
  }
 
+static int intel_iommu_add_device(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct pci_dev *bridge, *dma_pdev = pdev;
+	struct iommu_group *group;
+	int ret;
+
+	if (!device_to_iommu(pci_domain_nr(pdev->bus),
+			     pdev->bus->number, pdev->devfn))
+		return -ENODEV;
+
+	bridge = pci_find_upstream_pcie_bridge(pdev);
+	if (bridge) {
+		if (pci_is_pcie(bridge))
+			dma_pdev = pci_get_domain_bus_and_slot(
+						pci_domain_nr(pdev->bus),
+						bridge->subordinate->number, 0);
+		else
+			dma_pdev = bridge;
+	}
+
+	if (!pdev->is_virtfn&&  PCI_FUNC(pdev->devfn)&&  iommu_group_mf&&
+	    pdev->hdr_type == PCI_HEADER_TYPE_NORMAL)
+		dma_pdev = pci_get_slot(pdev->bus,
+					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));

drivers/iommu/intel-iommu.c static int intel_iommu_domain_has_cap(struct iommu_domain *domain, · line 4124

Quoted 10 lines
drivers/iommu/intel-iommu.c +10 -0
+
+	group = iommu_group_get(&dma_pdev->dev);
+	if (!group) {
+		group = iommu_group_alloc();
+		if (IS_ERR(group))
+			return PTR_ERR(group);
+	}
+
+	ret = iommu_group_add_device(group, dev);
+

ditto.

Quoted 22 lines
drivers/iommu/intel-iommu.c +11 -0
+	iommu_group_put(group);
+	return ret;
+}
+
+static void intel_iommu_remove_device(struct device *dev)
+{
+	iommu_group_remove_device(dev);
+}
+
  static struct iommu_ops intel_iommu_ops = {
  	.domain_init	= intel_iommu_domain_init,
  	.domain_destroy = intel_iommu_domain_destroy,
@@ -4096,6 +4140,8 @@ static struct iommu_ops intel_iommu_ops = {
  	.unmap		= intel_iommu_unmap,
  	.iova_to_phys	= intel_iommu_iova_to_phys,
  	.domain_has_cap = intel_iommu_domain_has_cap,
+	.add_device	= intel_iommu_add_device,
+	.remove_device	= intel_iommu_remove_device,
  	.pgsize_bitmap	= INTEL_IOMMU_PGSIZES,
  };
 
#6 lore raw

PATCH v2 4/13 pci: Add PCI DMA source ID quirk

In reply to Alex Williamson

DMA transactions are tagged with the source ID of the device making the request. Occasionally hardware screws this up and uses the source ID of a different device (often the wrong function number of a multifunction device). A specific Ricoh multifunction device is a prime example of this problem and included in this patch. The purpose of this function is that given a pci_dev, return the pci_dev to use as the source ID for DMA. When hardware works correctly, this returns the input device. For the components of the Ricoh multifunction device, return the pci_dev for function 0.

This will be used by IOMMU drivers for determining the boundaries of IOMMU groups as multiple devices using the same source ID must be contained within the same group. This can also be used by existing streaming DMA paths for the same purpose.

---

 drivers/pci/quirks.c |   40 ++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h  |    5 +++++
 2 files changed, 45 insertions(+), 0 deletions(-)
drivers/pci/quirks.c +40 -0
index 4bf7102..a2dd77f 100644
@@ -3109,3 +3109,43 @@ int pci_dev_specific_reset(struct pci_dev *dev, int probe)
 
 	return -ENOTTY;
 }
+
+static struct pci_dev *pci_func_0_dma_source(struct pci_dev *dev)
+{
+	return pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
+}
+
+static const struct pci_dev_dma_source {
+	u16 vendor;
+	u16 device;
+	struct pci_dev *(*dma_source)(struct pci_dev *dev);
+} pci_dev_dma_source[] = {
+	/*
+	 * https://bugzilla.redhat.com/show_bug.cgi?id=605888
+	 *
+	 * Some Ricoh devices use the function 0 source ID for DMA on
+	 * other functions of a multifunction device.  The DMA devices
+	 * is therefore function 0, which will have implications of the
+	 * iommu grouping of these devices.
+	 */
+	{ PCI_VENDOR_ID_RICOH, 0xe822, pci_func_0_dma_source },
+	{ PCI_VENDOR_ID_RICOH, 0xe230, pci_func_0_dma_source },
+	{ PCI_VENDOR_ID_RICOH, 0xe832, pci_func_0_dma_source },
+	{ PCI_VENDOR_ID_RICOH, 0xe832, pci_func_0_dma_source },
+	{ 0 }
+};
+
+struct pci_dev *pci_dma_source(struct pci_dev *dev)
+{
+	const struct pci_dev_dma_source *i;
+
+	for (i = pci_dev_dma_source; i->dma_source; i++) {
+		if ((i->vendor == dev->vendor ||
+		     i->vendor == (u16)PCI_ANY_ID) &&
+		    (i->device == dev->device ||
+		     i->device == (u16)PCI_ANY_ID))
+			return i->dma_source(dev);
+	}
+
+	return dev;
+}
include/linux/pci.h +5 -0
index e444f5b..02dbfed 100644
@@ -1479,9 +1479,14 @@ enum pci_fixup_pass {
 
 #ifdef CONFIG_PCI_QUIRKS
 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
+struct pci_dev *pci_dma_source(struct pci_dev *dev);
 #else
 static inline void pci_fixup_device(enum pci_fixup_pass pass,
 				    struct pci_dev *dev) {}
+static inline struct pci_dev *pci_dma_source(struct pci_dev *dev)
+{
+	return dev;
+}
 #endif
 
 void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
#7 lore raw

PATCH v2 5/13 pci: Add ACS validation utility

In reply to Alex Williamson

In a PCI environment, transactions aren't always required to reach the root bus before being re-routed. Intermediate switches between an endpoint and the root bus can redirect DMA back downstream before things like IOMMUs have a chance to intervene. Legacy PCI is always susceptible to this as it operates on a shared bus. PCIe added a new capability to describe and control this behavior, Access Control Services, or ACS. The utility function pci_acs_enabled() allows us to test the ACS capabilities of an individual devices against a set of flags while pci_acs_path_enabled() tests a complete path from a given downstream device up to the specified upstream device. We also include the ability to add device specific tests as it's likely we'll see devices that do no implement ACS, but want to indicate support for various capabilities in this space.

---

 drivers/pci/pci.c    |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/quirks.c |   29 +++++++++++++++++++
 include/linux/pci.h  |   10 ++++++-
 3 files changed, 114 insertions(+), 1 deletions(-)
drivers/pci/pci.c +76 -0
index 111569c..ab6c2a6 100644
@@ -2359,6 +2359,82 @@ void pci_enable_acs(struct pci_dev *dev)
 }
 
 /**
+ * pci_acs_enable - test ACS against required flags for a given device
+ * @pdev: device to test
+ * @acs_flags: required PCI ACS flags
+ *
+ * Return true if the device supports the provided flags.  Automatically
+ * filters out flags that are not implemented on multifunction devices.
+ */
+bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
+{
+	int pos;
+	u16 ctrl;
+
+	if (pci_dev_specific_acs_enabled(pdev, acs_flags))
+		return true;
+
+	if (!pci_is_pcie(pdev))
+		return false;
+
+	if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM ||
+	    pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
+		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+		if (!pos)
+			return false;
+
+		pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
+		if ((ctrl & acs_flags) != acs_flags)
+			return false;
+	} else if (pdev->multifunction) {
+		/* Filter out flags not applicable to multifunction */
+		acs_flags &= (PCI_ACS_RR | PCI_ACS_CR |
+			      PCI_ACS_EC | PCI_ACS_DT);
+
+		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+		if (!pos)
+			return false;
+
+		pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
+		if ((ctrl & acs_flags) != acs_flags)
+			return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(pci_acs_enabled);
+
+/**
+ * pci_acs_path_enable - test ACS flags from start to end in a hierarchy
+ * @start: starting downstream device
+ * @end: ending upstream device or NULL to search to the root bus
+ * @acs_flags: required flags
+ *
+ * Walk up a device tree from start to end testing PCI ACS support.  If
+ * any step along the way does not support the required flags, return false.
+ */
+bool pci_acs_path_enabled(struct pci_dev *start,
+			  struct pci_dev *end, u16 acs_flags)
+{
+	struct pci_dev *pdev, *parent = start;
+
+	do {
+		pdev = parent;
+
+		if (!pci_acs_enabled(pdev, acs_flags))
+			return false;
+
+		if (pci_is_root_bus(pdev->bus))
+			return (end == NULL);
+
+		parent = pdev->bus->self;
+	} while (pdev != end);
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(pci_acs_path_enabled);
+
+/**
  * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge
  * @dev: the PCI device
  * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD)
drivers/pci/quirks.c +29 -0
index a2dd77f..4ed6aa6 100644
@@ -3149,3 +3149,32 @@ struct pci_dev *pci_dma_source(struct pci_dev *dev)
 
 	return dev;
 }
+
+static const struct pci_dev_acs_enabled {
+	u16 vendor;
+	u16 device;
+	bool (*acs_enabled)(struct pci_dev *dev, u16 acs_flags);
+} pci_dev_acs_enabled[] = {
+	{ 0 }
+};
+
+bool pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags)
+{
+	const struct pci_dev_acs_enabled *i;
+
+	/*
+	 * Allow devices that do not expose standard PCI ACS capabilities
+	 * or control to indicate their support here.  Multi-function devices
+	 * which do not allow internal peer-to-peer between functions, but
+	 * do not implement PCI ACS may wish to return true here.
+	 */
+	for (i = pci_dev_acs_enabled; i->acs_enabled; i++) {
+		if ((i->vendor == dev->vendor ||
+		     i->vendor == (u16)PCI_ANY_ID) &&
+		    (i->device == dev->device ||
+		     i->device == (u16)PCI_ANY_ID))
+			return i->acs_enabled(dev, acs_flags);
+	}
+
+	return false;
+}
include/linux/pci.h +9 -1
index 02dbfed..2559735 100644
@@ -1480,6 +1480,7 @@ enum pci_fixup_pass {
 #ifdef CONFIG_PCI_QUIRKS
 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
 struct pci_dev *pci_dma_source(struct pci_dev *dev);
+bool pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
 #else
 static inline void pci_fixup_device(enum pci_fixup_pass pass,
 				    struct pci_dev *dev) {}
@@ -1487,6 +1488,11 @@ static inline struct pci_dev *pci_dma_source(struct pci_dev *dev)
 {
 	return dev;
 }
+static inline bool pci_dev_specific_acs_enabled(struct pci_dev *dev,
+						u16 acs_flags)
+{
+	return false;
+}
 #endif
 
 void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
@@ -1589,7 +1595,9 @@ static inline bool pci_is_pcie(struct pci_dev *dev)
 }
 
 void pci_request_acs(void);
-
+bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
+bool pci_acs_path_enabled(struct pci_dev *start,
+			  struct pci_dev *end, u16 acs_flags);
 
 #define PCI_VPD_LRDT			0x80	/* Large Resource Data Type */
 #define PCI_VPD_LRDT_ID(x)		(x | PCI_VPD_LRDT)
#8 lore raw

Re: [PATCH v2 05/13] pci: Add ACS validation utility

Quoted 27 lines · Alex Williamson

In a PCI environment, transactions aren't always required to reach the root bus before being re-routed. Intermediate switches between an endpoint and the root bus can redirect DMA back downstream before things like IOMMUs have a chance to intervene. Legacy PCI is always susceptible to this as it operates on a shared bus. PCIe added a new capability to describe and control this behavior, Access Control Services, or ACS. The utility function pci_acs_enabled() allows us to test the ACS capabilities of an individual devices against a set of flags while pci_acs_path_enabled() tests a complete path from a given downstream device up to the specified upstream device. We also include the ability to add device specific tests as it's likely we'll see devices that do no implement ACS, but want to indicate support for various capabilities in this space.

---

  drivers/pci/pci.c    |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++
  drivers/pci/quirks.c |   29 +++++++++++++++++++
  include/linux/pci.h  |   10 ++++++-
  3 files changed, 114 insertions(+), 1 deletions(-)
drivers/pci/pci.c +0 -0
index 111569c..ab6c2a6 100644

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2362

Quoted 4 lines
drivers/pci/pci.c +1 -0
@@ -2359,6 +2359,82 @@ void pci_enable_acs(struct pci_dev *dev)
  }
 
  /**
+ * pci_acs_enable - test ACS against required flags for a given device

typo: ^^^ missing 'd'

Quoted 31 lines
drivers/pci/pci.c +31 -0
+ * @pdev: device to test
+ * @acs_flags: required PCI ACS flags
+ *
+ * Return true if the device supports the provided flags.  Automatically
+ * filters out flags that are not implemented on multifunction devices.
+ */
+bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
+{
+	int pos;
+	u16 ctrl;
+
+	if (pci_dev_specific_acs_enabled(pdev, acs_flags))
+		return true;
+
+	if (!pci_is_pcie(pdev))
+		return false;
+
+	if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM ||
+	    pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
+		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+		if (!pos)
+			return false;
+
+		pci_read_config_word(pdev, pos + PCI_ACS_CTRL,&ctrl);
+		if ((ctrl&  acs_flags) != acs_flags)
+			return false;
+	} else if (pdev->multifunction) {
+		/* Filter out flags not applicable to multifunction */
+		acs_flags&= (PCI_ACS_RR | PCI_ACS_CR |
+			      PCI_ACS_EC | PCI_ACS_DT);
+

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2403

Quoted 10 lines
drivers/pci/pci.c +10 -0
+		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+		if (!pos)
+			return false;
+
+		pci_read_config_word(pdev, pos + PCI_ACS_CTRL,&ctrl);
+		if ((ctrl&  acs_flags) != acs_flags)
+			return false;
+	}
+
+	return true;

or, to reduce duplicated code (which compiler may do?):

	/* Filter out flags not applicable to multifunction */
	if (pdev->multifunction)
		acs_flags &= (PCI_ACS_RR | PCI_ACS_CR |
			      PCI_ACS_EC | PCI_ACS_DT);

	if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM ||
	    pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
            pdev->multifunction) {
		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
		if (!pos)
			return false;
		pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
		if ((ctrl & acs_flags) != acs_flags)
			return false;
	}

	return true;

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2404

Quoted 1 line
drivers/pci/pci.c +1 -0
+}

But the above doesn't handle the case where the RC does not do peer-to-peer btwn root ports. Per ACS spec, such a RC's root ports don't need to provide an ACS cap, since peer-to-peer port xfers aren't allowed/enabled/supported, so by design, the root port is ACS compliant. ATM, an IOMMU-capable system is a pre-req for VFIO,
and all such systems have an ACS cap, but they may not always be true.

Quoted 14 lines
drivers/pci/pci.c +14 -0
+EXPORT_SYMBOL_GPL(pci_acs_enabled);
+
+/**
+ * pci_acs_path_enable - test ACS flags from start to end in a hierarchy
+ * @start: starting downstream device
+ * @end: ending upstream device or NULL to search to the root bus
+ * @acs_flags: required flags
+ *
+ * Walk up a device tree from start to end testing PCI ACS support.  If
+ * any step along the way does not support the required flags, return false.
+ */
+bool pci_acs_path_enabled(struct pci_dev *start,
+			  struct pci_dev *end, u16 acs_flags)
+{

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2428

Quoted 10 lines
drivers/pci/pci.c +10 -0
+	struct pci_dev *pdev, *parent = start;
+
+	do {
+		pdev = parent;
+
+		if (!pci_acs_enabled(pdev, acs_flags))
+			return false;
+
+		if (pci_is_root_bus(pdev->bus))
+			return (end == NULL);

doesn't this mean that a caller can't pass the pdev of the root port? I would think that is a valid call, albeit not the common one. Also worried that the above code may be true on Intel machines, but not on AMD machines (the latter reps its IOMMU as a pdev of root bus, doesn't it?)

Quoted 39 lines
drivers/pci/pci.c +9 -0
+
+		parent = pdev->bus->self;
+	} while (pdev != end);
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(pci_acs_path_enabled);
+
+/**
   * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge
   * @dev: the PCI device
   * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD)
drivers/pci/quirks.c +19 -0
index a2dd77f..4ed6aa6 100644
@@ -3149,3 +3149,32 @@ struct pci_dev *pci_dma_source(struct pci_dev *dev)
 
  	return dev;
  }
+
+static const struct pci_dev_acs_enabled {
+	u16 vendor;
+	u16 device;
+	bool (*acs_enabled)(struct pci_dev *dev, u16 acs_flags);
+} pci_dev_acs_enabled[] = {
+	{ 0 }
+};
+
+bool pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags)
+{
+	const struct pci_dev_acs_enabled *i;
+
+	/*
+	 * Allow devices that do not expose standard PCI ACS capabilities
+	 * or control to indicate their support here.  Multi-function devices
+	 * which do not allow internal peer-to-peer between functions, but
+	 * do not implement PCI ACS may wish to return true here.
+	 */

drivers/pci/quirks.c struct pci_dev *pci_dma_source(struct pci_dev *dev) · line 3180

Quoted 10 lines
drivers/pci/quirks.c +10 -0
+	for (i = pci_dev_acs_enabled; i->acs_enabled; i++) {
+		if ((i->vendor == dev->vendor ||
+		     i->vendor == (u16)PCI_ANY_ID)&&
+		    (i->device == dev->device ||
+		     i->device == (u16)PCI_ANY_ID))
+			return i->acs_enabled(dev, acs_flags);
+	}
+
+	return false;
+}

I can't wait until these quirks are filled in! :)

Quoted 36 lines
include/linux/pci.h +9 -1
index 02dbfed..2559735 100644
@@ -1480,6 +1480,7 @@ enum pci_fixup_pass {
  #ifdef CONFIG_PCI_QUIRKS
  void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
  struct pci_dev *pci_dma_source(struct pci_dev *dev);
+bool pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
  #else
  static inline void pci_fixup_device(enum pci_fixup_pass pass,
  				    struct pci_dev *dev) {}
@@ -1487,6 +1488,11 @@ static inline struct pci_dev *pci_dma_source(struct pci_dev *dev)
  {
  	return dev;
  }
+static inline bool pci_dev_specific_acs_enabled(struct pci_dev *dev,
+						u16 acs_flags)
+{
+	return false;
+}
  #endif
 
  void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
@@ -1589,7 +1595,9 @@ static inline bool pci_is_pcie(struct pci_dev *dev)
  }
 
  void pci_request_acs(void);
-
+bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
+bool pci_acs_path_enabled(struct pci_dev *start,
+			  struct pci_dev *end, u16 acs_flags);
 
  #define PCI_VPD_LRDT			0x80	/* Large Resource Data Type */
  #define PCI_VPD_LRDT_ID(x)		(x | PCI_VPD_LRDT)
#9 lore raw

Re: [PATCH v2 05/13] pci: Add ACS validation utility

Quoted 30 lines · Don Dutile
Quoted 29 lines · Alex Williamson

In a PCI environment, transactions aren't always required to reach the root bus before being re-routed. Intermediate switches between an endpoint and the root bus can redirect DMA back downstream before things like IOMMUs have a chance to intervene. Legacy PCI is always susceptible to this as it operates on a shared bus. PCIe added a new capability to describe and control this behavior, Access Control Services, or ACS. The utility function pci_acs_enabled() allows us to test the ACS capabilities of an individual devices against a set of flags while pci_acs_path_enabled() tests a complete path from a given downstream device up to the specified upstream device. We also include the ability to add device specific tests as it's likely we'll see devices that do no implement ACS, but want to indicate support for various capabilities in this space.

---

  drivers/pci/pci.c    |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++
  drivers/pci/quirks.c |   29 +++++++++++++++++++
  include/linux/pci.h  |   10 ++++++-
  3 files changed, 114 insertions(+), 1 deletions(-)
drivers/pci/pci.c +0 -0
index 111569c..ab6c2a6 100644
@@ -2359,6 +2359,82 @@ void pci_enable_acs(struct pci_dev *dev)
  }
 
Quoted 3 lines

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2362

Quoted 2 lines
drivers/pci/pci.c +1 -0
  /**
+ * pci_acs_enable - test ACS against required flags for a given device

typo: ^^^ missing 'd'

d'oh. fixed

Quoted 52 lines
Quoted 31 lines
drivers/pci/pci.c +31 -0
+ * @pdev: device to test
+ * @acs_flags: required PCI ACS flags
+ *
+ * Return true if the device supports the provided flags.  Automatically
+ * filters out flags that are not implemented on multifunction devices.
+ */
+bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
+{
+	int pos;
+	u16 ctrl;
+
+	if (pci_dev_specific_acs_enabled(pdev, acs_flags))
+		return true;
+
+	if (!pci_is_pcie(pdev))
+		return false;
+
+	if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM ||
+	    pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
+		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+		if (!pos)
+			return false;
+
+		pci_read_config_word(pdev, pos + PCI_ACS_CTRL,&ctrl);
+		if ((ctrl&  acs_flags) != acs_flags)
+			return false;
+	} else if (pdev->multifunction) {
+		/* Filter out flags not applicable to multifunction */
+		acs_flags&= (PCI_ACS_RR | PCI_ACS_CR |
+			      PCI_ACS_EC | PCI_ACS_DT);
+

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2403

Quoted 10 lines
drivers/pci/pci.c +10 -0
+		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
+		if (!pos)
+			return false;
+
+		pci_read_config_word(pdev, pos + PCI_ACS_CTRL,&ctrl);
+		if ((ctrl&  acs_flags) != acs_flags)
+			return false;
+	}
+
+	return true;

or, to reduce duplicated code (which compiler may do?):

	/* Filter out flags not applicable to multifunction */
	if (pdev->multifunction)
		acs_flags &= (PCI_ACS_RR | PCI_ACS_CR |
			      PCI_ACS_EC | PCI_ACS_DT);

	if (pdev->pcie_type == PCI_EXP_TYPE_DOWNSTREAM ||
	    pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
             pdev->multifunction) {
		pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
Quoted 8 lines
		if (!pos)
			return false;
		pci_read_config_word(pdev, pos + PCI_ACS_CTRL, &ctrl);
		if ((ctrl & acs_flags) != acs_flags)
			return false;
	}

	return true;

Good suggestion

Quoted 8 lines

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2404

Quoted 1 line
drivers/pci/pci.c +1 -0
+}

But the above doesn't handle the case where the RC does not do peer-to-peer btwn root ports. Per ACS spec, such a RC's root ports don't need to provide an ACS cap, since peer-to-peer port xfers aren't allowed/enabled/supported, so by design, the root port is ACS compliant. ATM, an IOMMU-capable system is a pre-req for VFIO,
and all such systems have an ACS cap, but they may not always be true.

How do we know the behavior of the RC? This is why I allowed the NULL bailout below so we don't have to check the RC and can assume the iommu driver knows something about it.

Quoted 18 lines
Quoted 18 lines
drivers/pci/pci.c +18 -0
+EXPORT_SYMBOL_GPL(pci_acs_enabled);
+
+/**
+ * pci_acs_path_enable - test ACS flags from start to end in a hierarchy
+ * @start: starting downstream device
+ * @end: ending upstream device or NULL to search to the root bus
+ * @acs_flags: required flags
+ *
+ * Walk up a device tree from start to end testing PCI ACS support.  If
+ * any step along the way does not support the required flags, return false.
+ */
+bool pci_acs_path_enabled(struct pci_dev *start,
+			  struct pci_dev *end, u16 acs_flags)
+{
+	struct pci_dev *pdev, *parent = start;
+
+	do {
+		pdev = parent;
Quoted 8 lines

drivers/pci/pci.c void pci_enable_acs(struct pci_dev *dev) · line 2428

Quoted 6 lines
drivers/pci/pci.c +6 -0
+
+		if (!pci_acs_enabled(pdev, acs_flags))
+			return false;
+
+		if (pci_is_root_bus(pdev->bus))
+			return (end == NULL);

doesn't this mean that a caller can't pass the pdev of the root port? I would think that is a valid call, albeit not the common one.

I think there's nothing to step up to after this point, IIRC pdev->bus->self segfaults from here. So if we reach the end and you didn't ask for the end and haven't found your end device, we're done either way. Is that not true?

Quoted 2 lines

Also worried that the above code may be true on Intel machines, but not on AMD machines (the latter reps its IOMMU as a pdev of root bus, doesn't it?)

I hope it would be the usage in the respective iommu drivers that would need to account for this. I've designed this code to not care. Patch 06/13 does a search to NULL for both AMD and Intel, which seems to work. AMD does expose the IOMMU as a PCI device, but it's just a peer device of everything else on the root bus, not a parent, so we can't search with it as the end device.

Quoted 42 lines
Quoted 42 lines
drivers/pci/pci.c +9 -0
+
+		parent = pdev->bus->self;
+	} while (pdev != end);
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(pci_acs_path_enabled);
+
+/**
   * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge
   * @dev: the PCI device
   * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD)
drivers/pci/quirks.c +22 -0
index a2dd77f..4ed6aa6 100644
@@ -3149,3 +3149,32 @@ struct pci_dev *pci_dma_source(struct pci_dev *dev)
 
  	return dev;
  }
+
+static const struct pci_dev_acs_enabled {
+	u16 vendor;
+	u16 device;
+	bool (*acs_enabled)(struct pci_dev *dev, u16 acs_flags);
+} pci_dev_acs_enabled[] = {
+	{ 0 }
+};
+
+bool pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags)
+{
+	const struct pci_dev_acs_enabled *i;
+
+	/*
+	 * Allow devices that do not expose standard PCI ACS capabilities
+	 * or control to indicate their support here.  Multi-function devices
+	 * which do not allow internal peer-to-peer between functions, but
+	 * do not implement PCI ACS may wish to return true here.
+	 */
+	for (i = pci_dev_acs_enabled; i->acs_enabled; i++) {
+		if ((i->vendor == dev->vendor ||
+		     i->vendor == (u16)PCI_ANY_ID)&&
Quoted 8 lines

drivers/pci/quirks.c struct pci_dev *pci_dma_source(struct pci_dev *dev) · line 3180

Quoted 7 lines
drivers/pci/quirks.c +7 -0
+		    (i->device == dev->device ||
+		     i->device == (u16)PCI_ANY_ID))
+			return i->acs_enabled(dev, acs_flags);
+	}
+
+	return false;
+}

I can't wait until these quirks are filled in! :)

The list could get long...

Thanks,
Alex

#10 lore raw

PATCH v2 6/13 iommu: Make use of DMA quirking and ACS enabled check for groups

In reply to Alex Williamson

Incorporate DMA quirking and ACS checking into amd_iommu and intel-iommu. Note that IOMMU groups are not yet used for streaming DMA, so this doesn't immediately solve the problems with broken Ricoh devices. This a very strict implementation of ACS checking, which will often result in multifunction devices being grouped together. This is actually a good thing as we generally have no reason to trust isolation between functions, but I won't be surprised if we later add a boot option to relax this if a user wants to opt-in to a less secure grouping.

---

 drivers/iommu/amd_iommu.c   |   18 ++++++++++++++++++
 drivers/iommu/intel-iommu.c |   18 ++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
drivers/iommu/amd_iommu.c +18 -0
index b7e5ddf..be72d6d 100644
@@ -254,6 +254,8 @@ static bool check_device(struct device *dev)
 	return true;
 }
 
+#define PCI_ACS_ENABLED	(PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)
+
 static int iommu_init_device(struct device *dev)
 {
 	struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev);
@@ -291,6 +293,22 @@ static int iommu_init_device(struct device *dev)
 		dma_pdev = pci_get_slot(pdev->bus,
 					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
 
+	dma_pdev = pci_dma_source(dma_pdev);
+
+	if (dma_pdev->multifunction &&
+	    !pci_acs_enabled(dma_pdev, PCI_ACS_ENABLED))
+		dma_pdev = pci_get_slot(dma_pdev->bus,
+					PCI_DEVFN(PCI_SLOT(dma_pdev->devfn),
+					0));
+
+	while (!pci_is_root_bus(dma_pdev->bus)) {
+		if (pci_acs_path_enabled(dma_pdev->bus->self,
+					 NULL, PCI_ACS_ENABLED))
+			break;
+
+		dma_pdev = dma_pdev->bus->self;
+	}
+
 	group = iommu_group_get(&dma_pdev->dev);
 	if (!group) {
 		group = iommu_group_alloc();
drivers/iommu/intel-iommu.c +18 -0
index e63b33b..cf2a650 100644
@@ -4087,6 +4087,8 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain,
 	return 0;
 }
 
+#define PCI_ACS_ENABLED	(PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)
+
 static int intel_iommu_add_device(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -4113,6 +4115,22 @@ static int intel_iommu_add_device(struct device *dev)
 		dma_pdev = pci_get_slot(pdev->bus,
 					PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
 
+	dma_pdev = pci_dma_source(dma_pdev);
+
+	if (dma_pdev->multifunction &&
+	    !pci_acs_enabled(dma_pdev, PCI_ACS_ENABLED))
+		dma_pdev = pci_get_slot(dma_pdev->bus,
+					PCI_DEVFN(PCI_SLOT(dma_pdev->devfn),
+					0));
+
+	while (!pci_is_root_bus(dma_pdev->bus)) {
+		if (pci_acs_path_enabled(dma_pdev->bus->self,
+					 NULL, PCI_ACS_ENABLED))
+			break;
+
+		dma_pdev = dma_pdev->bus->self;
+	}
+
 	group = iommu_group_get(&dma_pdev->dev);
 	if (!group) {
 		group = iommu_group_alloc();
#11 lore raw

PATCH v2 7/13 vfio: VFIO core

In reply to Alex Williamson

VFIO is a secure user level driver for use with both virtual machines and user level drivers. VFIO makes use of IOMMU groups to ensure the isolation of devices in use, allowing unprivileged user access. It's intended that VFIO will replace KVM device assignment and UIO drivers (in cases where the target platform includes a sufficiently capable IOMMU).

New in this version of VFIO is support for IOMMU groups managed through the IOMMU core as well as a rework of the API, removing the group merge interface. We now go back to a model more similar to original VFIO with UIOMMU support where the file descriptor obtained from /dev/vfio/vfio allows access to the IOMMU, but only after a group is added, avoiding the previous privilege issues with this type of model. IOMMU support is also now fully modular as IOMMUs have vastly different interface requirements on different platforms. VFIO users are able to query and initialize the IOMMU model of their choice.

Please see the follow-on Documentation commit for further description and usage example.

---

 Documentation/ioctl/ioctl-number.txt |    1 
 MAINTAINERS                          |    8 
 drivers/Kconfig                      |    2 
 drivers/Makefile                     |    1 
 drivers/vfio/Kconfig                 |    8 
 drivers/vfio/Makefile                |    1 
 drivers/vfio/vfio.c                  | 1406 ++++++++++++++++++++++++++++++++++
 include/linux/vfio.h                 |  366 +++++++++
 8 files changed, 1793 insertions(+), 0 deletions(-)
 create mode 100644 drivers/vfio/Kconfig
 create mode 100644 drivers/vfio/Makefile
 create mode 100644 drivers/vfio/vfio.c
 create mode 100644 include/linux/vfio.h
Documentation/ioctl/ioctl-number.txt +1 -0
index e34b531..111e30a 100644
@@ -88,6 +88,7 @@ Code  Seq#(hex)	Include File		Comments
 		and kernel/power/user.c
 '8'	all				SNP8023 advanced NIC card
 					<mailto:[email protected]>
+';'	64-6F	linux/vfio.h
 '@'	00-0F	linux/radeonfb.h	conflict!
 '@'	00-0F	drivers/video/aty/aty128fb.c	conflict!
 'A'	00-1F	linux/apm_bios.h	conflict!
MAINTAINERS +8 -0
index b362709..5aca4ff 100644
@@ -7229,6 +7229,14 @@ S:	Maintained
 F:	Documentation/filesystems/vfat.txt
 F:	fs/fat/
 
+VFIO DRIVER
+M:	Alex Williamson <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/vfio.txt
+F:	drivers/vfio/
+F:	include/linux/vfio.h
+
 VIDEOBUF2 FRAMEWORK
 M:	Pawel Osciak <pawel-FA/[email protected]>
 M:	Marek Szyprowski <[email protected]>
drivers/Kconfig +2 -0
index d236aef..46eb115 100644
@@ -112,6 +112,8 @@ source "drivers/auxdisplay/Kconfig"
 
 source "drivers/uio/Kconfig"
 
+source "drivers/vfio/Kconfig"
+
 source "drivers/vlynq/Kconfig"
 
 source "drivers/virtio/Kconfig"
drivers/Makefile +1 -0
index 95952c8..fe1880a 100644
@@ -59,6 +59,7 @@ obj-$(CONFIG_ATM)		+= atm/
 obj-$(CONFIG_FUSION)		+= message/
 obj-y				+= firewire/
 obj-$(CONFIG_UIO)		+= uio/
+obj-$(CONFIG_VFIO)		+= vfio/
 obj-y				+= cdrom/
 obj-y				+= auxdisplay/
 obj-$(CONFIG_PCCARD)		+= pcmcia/
drivers/vfio/Kconfig new file +8 -0
new file mode 100644
index 0000000..9acb1e7
@@ -0,0 +1,8 @@
+menuconfig VFIO
+	tristate "VFIO Non-Privileged userspace driver framework"
+	depends on IOMMU_API
+	help
+	  VFIO provides a framework for secure userspace device drivers.
+	  See Documentation/vfio.txt for more details.
+
+	  If you don't know what to do here, say N.
drivers/vfio/Makefile new file +1 -0
new file mode 100644
index 0000000..7500a67
@@ -0,0 +1 @@
+obj-$(CONFIG_VFIO) += vfio.o
drivers/vfio/vfio.c new file +1406 -0

1,406 lines not on this page · raw message

include/linux/vfio.h new file +366 -0

366 lines not on this page · raw message

#12 lore raw

PATCH v2 8/13 vfio: Add documentation

In reply to Alex Williamson

---

 Documentation/vfio.txt |  315 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 315 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/vfio.txt
Documentation/vfio.txt new file +315 -0
new file mode 100644
index 0000000..1240874
@@ -0,0 +1,315 @@
+VFIO - "Virtual Function I/O"[1]
+-------------------------------------------------------------------------------
+Many modern system now provide DMA and interrupt remapping facilities
+to help ensure I/O devices behave within the boundaries they've been
+allotted.  This includes x86 hardware with AMD-Vi and Intel VT-d,
+POWER systems with Partitionable Endpoints (PEs) and embedded PowerPC
+systems such as Freescale PAMU.  The VFIO driver is an IOMMU/device
+agnostic framework for exposing direct device access to userspace, in
+a secure, IOMMU protected environment.  In other words, this allows
+safe[2], non-privileged, userspace drivers.
+
+Why do we want that?  Virtual machines often make use of direct device
+access ("device assignment") when configured for the highest possible
+I/O performance.  From a device and host perspective, this simply
+turns the VM into a userspace driver, with the benefits of
+significantly reduced latency, higher bandwidth, and direct use of
+bare-metal device drivers[3].
+
+Some applications, particularly in the high performance computing
+field, also benefit from low-overhead, direct device access from
+userspace.  Examples include network adapters (often non-TCP/IP based)
+and compute accelerators.  Prior to VFIO, these drivers had to either
+go through the full development cycle to become proper upstream
+driver, be maintained out of tree, or make use of the UIO framework,
+which has no notion of IOMMU protection, limited interrupt support,
+and requires root privileges to access things like PCI configuration
+space.
+
+The VFIO driver framework intends to unify these, replacing both the
+KVM PCI specific device assignment code as well as provide a more
+secure, more featureful userspace driver environment than UIO.
+
+Groups, Devices, and IOMMUs
+-------------------------------------------------------------------------------
+
+Devices are the main target of any I/O driver.  Devices typically
+create a programming interface made up of I/O access, interrupts,
+and DMA.  Without going into the details of each of these, DMA is
+by far the most critical aspect for maintaining a secure environment
+as allowing a device read-write access to system memory imposes the
+greatest risk to the overall system integrity.
+
+To help mitigate this risk, many modern IOMMUs now incorporate
+isolation properties into what was, in many cases, an interface only
+meant for translation (ie. solving the addressing problems of devices
+with limited address spaces).  With this, devices can now be isolated
+from each other and from arbitrary memory access, thus allowing
+things like secure direct assignment of devices into virtual machines.
+
+This isolation is not always at the granularity of a single device
+though.  Even when an IOMMU is capable of this, properties of devices,
+interconnects, and IOMMU topologies can each reduce this isolation.
+For instance, an individual device may be part of a larger multi-
+function enclosure.  While the IOMMU may be able to distinguish
+between devices within the enclosure, the enclosure may not require
+transactions between devices to reach the IOMMU.  Examples of this
+could be anything from a multi-function PCI device with backdoors
+between functions to a non-PCI-ACS (Access Control Services) capable
+bridge allowing redirection without reaching the IOMMU.  Topology
+can also play a factor in terms of hiding devices.  A PCIe-to-PCI
+bridge masks the devices behind it, making transaction appear as if
+from the bridge itself.  Obviously IOMMU design plays a major factor
+as well.
+
+Therefore, while for the most part an IOMMU may have device level
+granularity, any system is susceptible to reduced granularity.  The
+IOMMU API therefore supports a notion of IOMMU groups.  A group is
+a set of devices which is isolatable from all other devices in the
+system.  Groups are therefore the unit of ownership used by VFIO.
+
+While the group is the minimum granularity that must be used to
+ensure secure user access, it's not necessarily the preferred
+granularity.  In IOMMUs which make use of page tables, it may be
+possible to share a set of page tables between different groups,
+reducing the overhead both to the platform (reduced TLB thrashing,
+reduced duplicate page tables), and to the user (programming only
+a single set of translations).  For this reason, VFIO makes use of
+a container class, which may hold one or more groups.  A container
+is created by simply opening the /dev/vfio/vfio character device.
+
+On its own, the container provides little functionality, with all
+but a couple version and extension query interfaces locked away.
+The user needs to add a group into the container for the next level
+of functionality.  To do this, the user first needs to identify the
+group associated with the desired device.  This can be done using
+the sysfs links described in the example below.  By unbinding the
+device from the host driver and binding it to a VFIO driver, a new
+VFIO group will appear for the group as /dev/vfio/$GROUP, where
+$GROUP is the IOMMU group number of which the device is a member.
+If the IOMMU group contains multiple devices, each will need to
+be bound to a VFIO driver before operations on the VFIO group
+are allowed (it's also sufficient to only unbind the device from
+host drivers if a VFIO driver is unavailable; this will make the
+group available, but not that particular device).  TBD - interface
+for disabling driver probing/locking a device.
+
+Once the group is ready, it may be added to the container by opening
+the VFIO group character device (/dev/vfio/$GROUP) and using the
+VFIO_GROUP_SET_CONTAINER ioctl, passing the file descriptor of the
+previously opened container file.  If desired and if the IOMMU driver
+supports sharing the IOMMU context between groups, multiple groups may
+be set to the same container.  If a group fails to set to a container
+with existing groups, a new empty container will need to be used
+instead.
+
+With a group (or groups) attached to a container, the remaining
+ioctls become available, enabling access to the VFIO IOMMU interfaces.
+Additionally, it now becomes possible to get file descriptors for each
+device within a group using an ioctl on the VFIO group file descriptor.
+
+The VFIO device API includes ioctls for describing the device, the I/O
+regions and their read/write/mmap offsets on the device descriptor, as
+well as mechanisms for describing and registering interrupt
+notifications.
+
+VFIO Usage Example
+-------------------------------------------------------------------------------
+
+Assume user wants to access PCI device 0000:06:0d.0
+
+$ readlink /sys/bus/pci/devices/0000:06:0d.0/iommu_group
+../../../../kernel/iommu_groups/26
+
+This device is therefore in IOMMU group 26.  This device is on the
+pci bus, therefore the user will make use of vfio-pci to manage the
+group:
+
+# modprobe vfio-pci
+
+Binding this device to the vfio-pci driver creates the VFIO group
+character devices for this group:
+
+$ lspci -n -s 0000:06:0d.0
+06:0d.0 0401: 1102:0002 (rev 08)
+# echo 0000:06:0d.0 > /sys/bus/pci/devices/0000:06:0d.0/driver/unbind
+# echo 1102 0002 > /sys/bus/pci/drivers/vfio/new_id
+# echo 0000:06:0d.0 > /sys/bus/pci/drivers/vfio/bind
+
+Now we need to look at what other devices are in the group to free
+it for use by VFIO:
+
+$ ls -l /sys/bus/pci/devices/0000:06:0d.0/iommu_group/devices
+total 0
+lrwxrwxrwx. 1 root root 0 Apr 23 16:13 0000:00:1e.0 ->
+	../../../../devices/pci0000:00/0000:00:1e.0
+lrwxrwxrwx. 1 root root 0 Apr 23 16:13 0000:06:0d.0 ->
+	../../../../devices/pci0000:00/0000:00:1e.0/0000:06:0d.0
+lrwxrwxrwx. 1 root root 0 Apr 23 16:13 0000:06:0d.1 ->
+	../../../../devices/pci0000:00/0000:00:1e.0/0000:06:0d.1
+
+This device is behind a PCIe-to-PCI bridge[4], therefore we also
+need to add device 0000:06:0d.1 to the group following the same
+procedure as above.  Device 0000:00:1e.0 is a bridge that does
+not currently have a host driver, therefore it's not required to
+bind this device to the vfio-pci driver (vfio-pci does not currently
+support PCI bridges).
+
+The final step is to provide the user with access to the group if
+unprivileged operation is desired (note that /dev/vfio/vfio provides
+no capabilities on its own and is therefore expected to be set to
+mode 0666 by the system).
+
+# chown user:user /dev/vfio/26
+
+The user now has full access to all the devices and the iommu for this
+group and can access them as follows:
+
+	int container, group, device, i;
+	struct vfio_group_status group_status =
+					{ .argsz = sizeof(group_status) };
+	struct vfio_iommu_x86_info iommu_info = { .argsz = sizeof(iommu_info) };
+	struct vfio_iommu_x86_dma_map dma_map = { .argsz = sizeof(dma_map) };
+	struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
+
+	/* Create a new container */
+	container = open("/dev/vfio/vfio, O_RDWR);
+
+	if (ioctl(container, VFIO_GET_API_VERSION) != VFIO_API_VERSION)
+		/* Unknown API version */
+
+	if (!ioctl(container, VFIO_CHECK_EXTENSION, VFIO_X86_IOMMU))
+		/* Doesn't support the IOMMU driver we want. */
+
+	/* Open the group */
+	group = open("/dev/vfio/26", O_RDWR);
+
+	/* Test the group is viable and available */
+	ioctl(group, VFIO_GROUP_GET_STATUS, &group_status);
+
+	if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE))
+		/* Group is not viable (ie, not all devices bound for vfio) */
+
+	/* Add the group to the container */
+	ioctl(group, VFIO_GROUP_SET_CONTAINER, &container);
+
+	/* Enable the IOMMU model we want */
+	ioctl(container, VFIO_SET_IOMMU, VFIO_X86_IOMMU)
+
+	/* Get addition IOMMU info */
+	ioctl(container, VFIO_IOMMU_GET_INFO, &iommu_info);
+
+	/* Allocate some space and setup a DMA mapping */
+	dma_map.vaddr = mmap(0, 1024 * 1024, PROT_READ | PROT_WRITE,
+			     MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	dma_map.size = 1024 * 1024;
+	dma_map.iova = 0; /* 1MB starting at 0x0 from device view */
+	dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
+
+	ioctl(container, VFIO_IOMMU_MAP_DMA, &dma_map);
+
+	/* Get a file descriptor for the device */
+	device = ioctl(group, VFIO_GROUP_GET_DEVICE_FD, "0000:06:0d.0");
+
+	/* Test and setup the device */
+	ioctl(device, VFIO_DEVICE_GET_INFO, &device_info);
+
+	for (i = 0; i < device_info.num_regions; i++) {
+		struct vfio_region_info reg = { .argsz = sizeof(reg) };
+
+		reg.index = i;
+
+		ioctl(device, VFIO_DEVICE_GET_REGION_INFO, &reg);
+
+		/* Setup mappings... read/write offsets, mmaps
+		 * For PCI devices, config space is a region */
+	}
+
+	for (i = 0; i < device_info.num_irqs; i++) {
+		struct vfio_irq_info irq = { .argsz = sizeof(irq) };
+
+		irq.index = i;
+
+		ioctl(device, VFIO_DEVICE_GET_IRQ_INFO, &reg);
+
+		/* Setup IRQs... eventfds, VFIO_DEVICE_SET_IRQS */
+	}
+
+	/* Gratuitous device reset and go... */
+	ioctl(device, VFIO_DEVICE_RESET);
+
+VFIO User API
+-------------------------------------------------------------------------------
+
+Please see include/linux/vfio.h for complete API documentation.
+
+VFIO bus driver API
+-------------------------------------------------------------------------------
+
+VFIO bus drivers, such as vfio-pci make use of only a few interfaces
+into VFIO core.  When devices are bound and unbound to the driver,
+the driver should call vfio_add_group_dev() and vfio_del_group_dev()
+respectively:
+
+extern int vfio_add_group_dev(struct iommu_group *iommu_group,
+                              struct device *dev,
+                              const struct vfio_device_ops *ops,
+                              void *device_data);
+
+extern void *vfio_del_group_dev(struct device *dev);
+
+vfio_add_group_dev() indicates to the core to begin tracking the
+specified iommu_group and register the specified dev as owned by
+a VFIO bus driver.  The driver provides an ops structure for callbacks
+similar to a file operations structure:
+
+struct vfio_device_ops {
+	int	(*open)(void *device_data);
+	void	(*release)(void *device_data);
+	ssize_t	(*read)(void *device_data, char __user *buf,
+			size_t count, loff_t *ppos);
+	ssize_t	(*write)(void *device_data, const char __user *buf,
+			 size_t size, loff_t *ppos);
+	long	(*ioctl)(void *device_data, unsigned int cmd,
+			 unsigned long arg);
+	int	(*mmap)(void *device_data, struct vm_area_struct *vma);
+};
+
+Each function is passed the device_data that was originally registered
+in the vfio_add_group_dev() call above.  This allows the bus driver
+an easy place to store its opaque, private data.  The open/release
+callbacks are issued when a new file descriptor is created for a
+device (via VFIO_GROUP_GET_DEVICE_FD).  The ioctl interface provides
+a direct pass through for VFIO_DEVICE_* ioctls.  The read/write/mmap
+interfaces implement the device region access defined by the device's
+own VFIO_DEVICE_GET_REGION_INFO ioctl.
+
+-------------------------------------------------------------------------------
+
+[1] VFIO was originally an acronym for "Virtual Function I/O" in its
+initial implementation by Tom Lyon while as Cisco.  We've since
+outgrown the acronym, but it's catchy.
+
+[2] "safe" also depends upon a device being "well behaved".  It's
+possible for multi-function devices to have backdoors between
+functions and even for single function devices to have alternative
+access to things like PCI config space through MMIO registers.  To
+guard against the former we can include additional precautions in the
+IOMMU driver to group multi-function PCI devices together
+(iommu=group_mf).  The latter we can't prevent, but the IOMMU should
+still provide isolation.  For PCI, SR-IOV Virtual Functions are the
+best indicator of "well behaved", as these are designed for
+virtualization usage models.
+
+[3] As always there are trade-offs to virtual machine device
+assignment that are beyond the scope of VFIO.  It's expected that
+future IOMMU technologies will reduce some, but maybe not all, of
+these trade-offs.
+
+[4] In this case the device is below a PCI bridge, so transactions
+from either function of the device are indistinguishable to the iommu:
+
+-[0000:00]-+-1e.0-[06]--+-0d.0
+                        \-0d.1
+
+00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev 90)
#13 lore raw

PATCH v2 9/13 vfio: x86 IOMMU implementation

In reply to Alex Williamson

x86 is probably the wrong name for this VFIO IOMMU driver, but x86 is the primary target for it. This driver support a very simple usage model using the existing IOMMU API. The IOMMU is expected to support the full host address space with no special IOVA windows, number of mappings restrictions, or unique processor target options.

---

 Documentation/ioctl/ioctl-number.txt |    2 
 drivers/vfio/Kconfig                 |    6 
 drivers/vfio/Makefile                |    2 
 drivers/vfio/vfio.c                  |    7 
 drivers/vfio/vfio_iommu_x86.c        |  743 ++++++++++++++++++++++++++++++++++
 include/linux/vfio.h                 |   52 ++
 6 files changed, 811 insertions(+), 1 deletions(-)
 create mode 100644 drivers/vfio/vfio_iommu_x86.c
Documentation/ioctl/ioctl-number.txt +1 -1
index 111e30a..9d1694e 100644
@@ -88,7 +88,7 @@ Code  Seq#(hex)	Include File		Comments
 		and kernel/power/user.c
 '8'	all				SNP8023 advanced NIC card
 					<mailto:[email protected]>
-';'	64-6F	linux/vfio.h
+';'	64-72	linux/vfio.h
 '@'	00-0F	linux/radeonfb.h	conflict!
 '@'	00-0F	drivers/video/aty/aty128fb.c	conflict!
 'A'	00-1F	linux/apm_bios.h	conflict!
drivers/vfio/Kconfig +6 -0
index 9acb1e7..bd88a30 100644
@@ -1,6 +1,12 @@
+config VFIO_IOMMU_X86
+	tristate
+	depends on VFIO && X86
+	default n
+
 menuconfig VFIO
 	tristate "VFIO Non-Privileged userspace driver framework"
 	depends on IOMMU_API
+	select VFIO_IOMMU_X86 if X86
 	help
 	  VFIO provides a framework for secure userspace device drivers.
 	  See Documentation/vfio.txt for more details.
drivers/vfio/Makefile +2 -0
index 7500a67..1f1abee 100644
@@ -1 +1,3 @@
 obj-$(CONFIG_VFIO) += vfio.o
+obj-$(CONFIG_VFIO_IOMMU_X86) += vfio_iommu_x86.o
+obj-$(CONFIG_VFIO_PCI) += pci/
drivers/vfio/vfio.c +7 -0
index 6558eef..89899a8 100644
@@ -1369,6 +1369,13 @@ static int __init vfio_init(void)
 
 	pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
 
+	/*
+	 * Attempt to load known iommu-drivers.  This gives us a working
+	 * environment without the user needing to explicitly load iommu
+	 * drivers.
+	 */
+	request_module_nowait("vfio_iommu_x86");
+
 	return 0;
 
 err_groups_cdev:
drivers/vfio/vfio_iommu_x86.c new file +743 -0

743 lines not on this page · raw message

include/linux/vfio.h +52 -0

56 lines not on this page · raw message

#14 lore raw

Re: [PATCH v2 09/13] vfio: x86 IOMMU implementation

Quoted 38 lines · Alex Williamson

x86 is probably the wrong name for this VFIO IOMMU driver, but x86 is the primary target for it. This driver support a very simple usage model using the existing IOMMU API. The IOMMU is expected to support the full host address space with no special IOVA windows, number of mappings restrictions, or unique processor target options.

---

  Documentation/ioctl/ioctl-number.txt |    2
  drivers/vfio/Kconfig                 |    6
  drivers/vfio/Makefile                |    2
  drivers/vfio/vfio.c                  |    7
  drivers/vfio/vfio_iommu_x86.c        |  743 ++++++++++++++++++++++++++++++++++
  include/linux/vfio.h                 |   52 ++
  6 files changed, 811 insertions(+), 1 deletions(-)

create mode 100644 drivers/vfio/vfio_iommu_x86.c

Documentation/ioctl/ioctl-number.txt +1 -1
index 111e30a..9d1694e 100644
@@ -88,7 +88,7 @@ Code  Seq#(hex)	Include File		Comments
  		and kernel/power/user.c
  '8'	all				SNP8023 advanced NIC card
  					<mailto:[email protected]>
-';'	64-6F	linux/vfio.h
+';'	64-72	linux/vfio.h
  '@'	00-0F	linux/radeonfb.h	conflict!
  '@'	00-0F	drivers/video/aty/aty128fb.c	conflict!
  'A'	00-1F	linux/apm_bios.h	conflict!
drivers/vfio/Kconfig +2 -0
index 9acb1e7..bd88a30 100644
@@ -1,6 +1,12 @@
+config VFIO_IOMMU_X86
+	tristate

drivers/vfio/Kconfig line 12

Quoted 10 lines
drivers/vfio/Kconfig +4 -0
+	depends on VFIO&&  X86
+	default n
+
  menuconfig VFIO
  	tristate "VFIO Non-Privileged userspace driver framework"
  	depends on IOMMU_API
+	select VFIO_IOMMU_X86 if X86
  	help
  	  VFIO provides a framework for secure userspace device drivers.
  	  See Documentation/vfio.txt for more details.

So a future refactoring that uses some chunk of this support on a non-x86 machine could be a lot of useless renaming.

Why not rename vfio_iommu_x86 to something like vfio_iommu_no_iova
and just make it conditionally compiled on X86 (as you've done above in Kconfig's)? Then if another arch can use it, or refactors the file to use
some of it, and split x86 vs <other-arch> into separate per-arch files, or per-iova schemes, it's more descriptive and less disruptive?

Quoted 10 lines
drivers/vfio/Makefile +2 -0
index 7500a67..1f1abee 100644
@@ -1 +1,3 @@
  obj-$(CONFIG_VFIO) += vfio.o
+obj-$(CONFIG_VFIO_IOMMU_X86) += vfio_iommu_x86.o
+obj-$(CONFIG_VFIO_PCI) += pci/
drivers/vfio/vfio.c +0 -0
index 6558eef..89899a8 100644
#15 lore raw

Re: [PATCH v2 09/13] vfio: x86 IOMMU implementation

Quoted 53 lines · Don Dutile
Quoted 38 lines · Alex Williamson

x86 is probably the wrong name for this VFIO IOMMU driver, but x86 is the primary target for it. This driver support a very simple usage model using the existing IOMMU API. The IOMMU is expected to support the full host address space with no special IOVA windows, number of mappings restrictions, or unique processor target options.

---

  Documentation/ioctl/ioctl-number.txt |    2
  drivers/vfio/Kconfig                 |    6
  drivers/vfio/Makefile                |    2
  drivers/vfio/vfio.c                  |    7
  drivers/vfio/vfio_iommu_x86.c        |  743 ++++++++++++++++++++++++++++++++++
  include/linux/vfio.h                 |   52 ++
  6 files changed, 811 insertions(+), 1 deletions(-)

create mode 100644 drivers/vfio/vfio_iommu_x86.c

Documentation/ioctl/ioctl-number.txt +1 -1
index 111e30a..9d1694e 100644
@@ -88,7 +88,7 @@ Code  Seq#(hex)	Include File		Comments
  		and kernel/power/user.c
  '8'	all				SNP8023 advanced NIC card
  					<mailto:[email protected]>
-';'	64-6F	linux/vfio.h
+';'	64-72	linux/vfio.h
  '@'	00-0F	linux/radeonfb.h	conflict!
  '@'	00-0F	drivers/video/aty/aty128fb.c	conflict!
  'A'	00-1F	linux/apm_bios.h	conflict!
drivers/vfio/Kconfig +2 -0
index 9acb1e7..bd88a30 100644
@@ -1,6 +1,12 @@
+config VFIO_IOMMU_X86
+	tristate

drivers/vfio/Kconfig line 12

Quoted 10 lines
drivers/vfio/Kconfig +4 -0
+	depends on VFIO&&  X86
+	default n
+
  menuconfig VFIO
  	tristate "VFIO Non-Privileged userspace driver framework"
  	depends on IOMMU_API
+	select VFIO_IOMMU_X86 if X86
  	help
  	  VFIO provides a framework for secure userspace device drivers.
  	  See Documentation/vfio.txt for more details.

So a future refactoring that uses some chunk of this support on a non-x86 machine could be a lot of useless renaming.

Quoted 5 lines

Why not rename vfio_iommu_x86 to something like vfio_iommu_no_iova
and just make it conditionally compiled on X86 (as you've done above in Kconfig's)? Then if another arch can use it, or refactors the file to use
some of it, and split x86 vs <other-arch> into separate per-arch files, or per-iova schemes, it's more descriptive and less disruptive?

Yep, the problem is how to concisely describe what we expect to support here. This file supports IOMMU API based usage of an IOMMU with effectively no DMA window or mapping constraints, optimized for static mapping of an address space. What's a good name for that? Maybe I should follow the example of others and just call it a Type 1 IOMMU implementation so the marketing material looks better! ;-P That may honestly be better than calling it x86. Thoughts? Thanks,

Alex

#16 lore raw

Re: [PATCH v2 09/13] vfio: x86 IOMMU implementation

Quoted 68 lines · Alex Williamson
Quoted 53 lines · Don Dutile
Quoted 38 lines · Alex Williamson

x86 is probably the wrong name for this VFIO IOMMU driver, but x86 is the primary target for it. This driver support a very simple usage model using the existing IOMMU API. The IOMMU is expected to support the full host address space with no special IOVA windows, number of mappings restrictions, or unique processor target options.

---

   Documentation/ioctl/ioctl-number.txt |    2
   drivers/vfio/Kconfig                 |    6
   drivers/vfio/Makefile                |    2
   drivers/vfio/vfio.c                  |    7
   drivers/vfio/vfio_iommu_x86.c        |  743 ++++++++++++++++++++++++++++++++++
   include/linux/vfio.h                 |   52 ++
   6 files changed, 811 insertions(+), 1 deletions(-)

create mode 100644 drivers/vfio/vfio_iommu_x86.c

Documentation/ioctl/ioctl-number.txt +1 -1
index 111e30a..9d1694e 100644
@@ -88,7 +88,7 @@ Code  Seq#(hex)	Include File		Comments
   		and kernel/power/user.c
   '8'	all				SNP8023 advanced NIC card
   					<mailto:[email protected]>
-';'	64-6F	linux/vfio.h
+';'	64-72	linux/vfio.h
   '@'	00-0F	linux/radeonfb.h	conflict!
   '@'	00-0F	drivers/video/aty/aty128fb.c	conflict!
   'A'	00-1F	linux/apm_bios.h	conflict!
drivers/vfio/Kconfig +2 -0
index 9acb1e7..bd88a30 100644
@@ -1,6 +1,12 @@
+config VFIO_IOMMU_X86
+	tristate

drivers/vfio/Kconfig line 12

Quoted 10 lines
drivers/vfio/Kconfig +4 -0
+	depends on VFIO&&   X86
+	default n
+
   menuconfig VFIO
   	tristate "VFIO Non-Privileged userspace driver framework"
   	depends on IOMMU_API
+	select VFIO_IOMMU_X86 if X86
   	help
   	  VFIO provides a framework for secure userspace device drivers.
   	  See Documentation/vfio.txt for more details.

So a future refactoring that uses some chunk of this support on a non-x86 machine could be a lot of useless renaming.

Quoted 5 lines

Why not rename vfio_iommu_x86 to something like vfio_iommu_no_iova
and just make it conditionally compiled on X86 (as you've done above in Kconfig's)? Then if another arch can use it, or refactors the file to use
some of it, and split x86 vs<other-arch> into separate per-arch files, or per-iova schemes, it's more descriptive and less disruptive?

Yep, the problem is how to concisely describe what we expect to support here. This file supports IOMMU API based usage of an IOMMU with effectively no DMA window or mapping constraints, optimized for static mapping of an address space. What's a good name for that? Maybe I should follow the example of others and just call it a Type 1 IOMMU implementation so the marketing material looks better! ;-P That may honestly be better than calling it x86. Thoughts? Thanks,

Quoted 2 lines

Alex

I'll vote for 'type1' over 'x86' ....
Add a comment in the file what a 'type1 IOMMU' is. Then others can dupe format for typeX.

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw

PATCH v2 10/13 pci: export pci_user functions for use by other drivers

In reply to Alex Williamson

VFIO PCI support will make use of these for user initiated PCI config accesses.

---

 drivers/pci/access.c |    6 ++++--
 drivers/pci/pci.h    |    7 -------
 include/linux/pci.h  |    8 ++++++++
 3 files changed, 12 insertions(+), 9 deletions(-)
drivers/pci/access.c +4 -2
index 2a58164..ba91a7e 100644
@@ -162,7 +162,8 @@ int pci_user_read_config_##size						\
 	if (ret > 0)							\
 		ret = -EINVAL;						\
 	return ret;							\
-}
+}									\
+EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
 
 /* Returns 0 on success, negative values indicate error. */
 #define PCI_USER_WRITE_CONFIG(size,type)				\
@@ -181,7 +182,8 @@ int pci_user_write_config_##size					\
 	if (ret > 0)							\
 		ret = -EINVAL;						\
 	return ret;							\
-}
+}									\
+EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
 
 PCI_USER_READ_CONFIG(byte, u8)
 PCI_USER_READ_CONFIG(word, u16)
drivers/pci/pci.h +0 -7
index e494347..f2dcc46 100644
@@ -86,13 +86,6 @@ static inline bool pci_is_bridge(struct pci_dev *pci_dev)
 	return !!(pci_dev->subordinate);
 }
 
-extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
-extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
-extern int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
-extern int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
-extern int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
-extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
-
 struct pci_vpd_ops {
 	ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
 	ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
include/linux/pci.h +8 -0
index 2559735..0cf57d5 100644
@@ -770,6 +770,14 @@ static inline int pci_write_config_dword(const struct pci_dev *dev, int where,
 	return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
 }
 
+/* user-space driven config access */
+int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
+int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
+int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
+int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
+int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
+int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
+
 int __must_check pci_enable_device(struct pci_dev *dev);
 int __must_check pci_enable_device_io(struct pci_dev *dev);
 int __must_check pci_enable_device_mem(struct pci_dev *dev);
#18 lore raw

PATCH v2 11/13 pci: Create common pcibios_err_to_errno

In reply to Alex Williamson

For returning errors out to non-PCI code. Re-name xen's version.

---

 drivers/xen/xen-pciback/conf_space.c |    6 +++---
 include/linux/pci.h                  |   26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
drivers/xen/xen-pciback/conf_space.c +3 -3
index 30d7be0..46ae0f9 100644
@@ -124,7 +124,7 @@ static inline u32 merge_value(u32 val, u32 new_val, u32 new_val_mask,
 	return val;
 }
 
-static int pcibios_err_to_errno(int err)
+static int xen_pcibios_err_to_errno(int err)
 {
 	switch (err) {
 	case PCIBIOS_SUCCESSFUL:
@@ -202,7 +202,7 @@ out:
 		       pci_name(dev), size, offset, value);
 
 	*ret_val = value;
-	return pcibios_err_to_errno(err);
+	return xen_pcibios_err_to_errno(err);
 }
 
 int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size, u32 value)
@@ -290,7 +290,7 @@ int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size, u32 value)
 		}
 	}
 
-	return pcibios_err_to_errno(err);
+	return xen_pcibios_err_to_errno(err);
 }
 
 void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev)
include/linux/pci.h +26 -0
index 0cf57d5..b0f79b3 100644
@@ -467,6 +467,32 @@ static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev) { return false;
 #define PCIBIOS_SET_FAILED		0x88
 #define PCIBIOS_BUFFER_TOO_SMALL	0x89
 
+/*
+ * Translate above to generic errno for passing back through non-pci.
+ */
+static inline int pcibios_err_to_errno(int err)
+{
+	if (err <= PCIBIOS_SUCCESSFUL)
+		return err; /* Assume already errno */
+
+	switch (err) {
+	case PCIBIOS_FUNC_NOT_SUPPORTED:
+		return -ENOENT;
+	case PCIBIOS_BAD_VENDOR_ID:
+		return -EINVAL;
+	case PCIBIOS_DEVICE_NOT_FOUND:
+		return -ENODEV;
+	case PCIBIOS_BAD_REGISTER_NUMBER:
+		return -EFAULT;
+	case PCIBIOS_SET_FAILED:
+		return -EIO;
+	case PCIBIOS_BUFFER_TOO_SMALL:
+		return -ENOSPC;
+	}
+
+	return -ENOTTY;
+}
+
 /* Low-level architecture-dependent routines */
 
 struct pci_ops {
#19 lore raw

PATCH v2 12/13 pci: Misc pci_reg additions

In reply to Alex Williamson

Fill in many missing definitions and add sizeof fields for many sections allowing for more extensive config parsing.

---

 include/linux/pci_regs.h |  112 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 100 insertions(+), 12 deletions(-)
include/linux/pci_regs.h +100 -12
index 4b608f5..379be84 100644
@@ -26,6 +26,7 @@
  * Under PCI, each device has 256 bytes of configuration address space,
  * of which the first 64 bytes are standardized as follows:
  */
+#define PCI_STD_HEADER_SIZEOF	64
 #define PCI_VENDOR_ID		0x00	/* 16 bits */
 #define PCI_DEVICE_ID		0x02	/* 16 bits */
 #define PCI_COMMAND		0x04	/* 16 bits */
@@ -209,9 +210,12 @@
 #define  PCI_CAP_ID_SHPC 	0x0C	/* PCI Standard Hot-Plug Controller */
 #define  PCI_CAP_ID_SSVID	0x0D	/* Bridge subsystem vendor/device ID */
 #define  PCI_CAP_ID_AGP3	0x0E	/* AGP Target PCI-PCI bridge */
+#define  PCI_CAP_ID_SECDEV	0x0F	/* Secure Device */
 #define  PCI_CAP_ID_EXP 	0x10	/* PCI Express */
 #define  PCI_CAP_ID_MSIX	0x11	/* MSI-X */
+#define  PCI_CAP_ID_SATA	0x12	/* SATA Data/Index Conf. */
 #define  PCI_CAP_ID_AF		0x13	/* PCI Advanced Features */
+#define  PCI_CAP_ID_MAX		PCI_CAP_ID_AF
 #define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
 #define PCI_CAP_FLAGS		2	/* Capability defined flags (16 bits) */
 #define PCI_CAP_SIZEOF		4
@@ -276,6 +280,7 @@
 #define  PCI_VPD_ADDR_MASK	0x7fff	/* Address mask */
 #define  PCI_VPD_ADDR_F		0x8000	/* Write 0, 1 indicates completion */
 #define PCI_VPD_DATA		4	/* 32-bits of data returned here */
+#define PCI_CAP_VPD_SIZEOF	8
 
 /* Slot Identification */
 
@@ -297,8 +302,10 @@
 #define PCI_MSI_ADDRESS_HI	8	/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
 #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
 #define PCI_MSI_MASK_32		12	/* Mask bits register for 32-bit devices */
+#define PCI_MSI_PENDING_32	16	/* Pending intrs for 32-bit devices */
 #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
 #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
+#define PCI_MSI_PENDING_64	20	/* Pending intrs for 64-bit devices */
 
 /* MSI-X registers */
 #define PCI_MSIX_FLAGS		2
@@ -308,6 +315,7 @@
 #define PCI_MSIX_TABLE		4
 #define PCI_MSIX_PBA		8
 #define  PCI_MSIX_FLAGS_BIRMASK	(7 << 0)
+#define PCI_CAP_MSIX_SIZEOF	12	/* size of MSIX registers */
 
 /* MSI-X entry's format */
 #define PCI_MSIX_ENTRY_SIZE		16
@@ -338,6 +346,7 @@
 #define  PCI_AF_CTRL_FLR	0x01
 #define PCI_AF_STATUS		5
 #define  PCI_AF_STATUS_TP	0x01
+#define PCI_CAP_AF_SIZEOF	6	/* size of AF registers */
 
 /* PCI-X registers */
 
@@ -374,6 +383,9 @@
 #define  PCI_X_STATUS_SPL_ERR	0x20000000	/* Rcvd Split Completion Error Msg */
 #define  PCI_X_STATUS_266MHZ	0x40000000	/* 266 MHz capable */
 #define  PCI_X_STATUS_533MHZ	0x80000000	/* 533 MHz capable */
+#define PCI_X_ECC_CSR		8	/* ECC control and status */
+#define PCI_CAP_PCIX_SIZEOF_V0	8	/* size of registers for Version 0 */
+#define PCI_CAP_PCIX_SIZEOF_V12	24	/* size for Version 1 & 2 */
 
 /* PCI Bridge Subsystem ID registers */
 
@@ -462,6 +474,7 @@
 #define  PCI_EXP_LNKSTA_DLLLA	0x2000	/* Data Link Layer Link Active */
 #define  PCI_EXP_LNKSTA_LBMS	0x4000	/* Link Bandwidth Management Status */
 #define  PCI_EXP_LNKSTA_LABS	0x8000	/* Link Autonomous Bandwidth Status */
+#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V1	20	/* v1 endpoints end here */
 #define PCI_EXP_SLTCAP		20	/* Slot Capabilities */
 #define  PCI_EXP_SLTCAP_ABP	0x00000001 /* Attention Button Present */
 #define  PCI_EXP_SLTCAP_PCP	0x00000002 /* Power Controller Present */
@@ -521,6 +534,7 @@
 #define  PCI_EXP_OBFF_MSGA_EN	0x2000	/* OBFF enable with Message type A */
 #define  PCI_EXP_OBFF_MSGB_EN	0x4000	/* OBFF enable with Message type B */
 #define  PCI_EXP_OBFF_WAKE_EN	0x6000	/* OBFF using WAKE# signaling */
+#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2	44	/* v2 endpoints end here */
 #define PCI_EXP_LNKCTL2		48	/* Link Control 2 */
 #define PCI_EXP_SLTCTL2		56	/* Slot Control 2 */
 
@@ -529,23 +543,43 @@
 #define PCI_EXT_CAP_VER(header)		((header >> 16) & 0xf)
 #define PCI_EXT_CAP_NEXT(header)	((header >> 20) & 0xffc)
 
-#define PCI_EXT_CAP_ID_ERR	1
-#define PCI_EXT_CAP_ID_VC	2
-#define PCI_EXT_CAP_ID_DSN	3
-#define PCI_EXT_CAP_ID_PWR	4
-#define PCI_EXT_CAP_ID_VNDR	11
-#define PCI_EXT_CAP_ID_ACS	13
-#define PCI_EXT_CAP_ID_ARI	14
-#define PCI_EXT_CAP_ID_ATS	15
-#define PCI_EXT_CAP_ID_SRIOV	16
-#define PCI_EXT_CAP_ID_PRI	19
-#define PCI_EXT_CAP_ID_LTR	24
-#define PCI_EXT_CAP_ID_PASID	27
+#define PCI_EXT_CAP_ID_ERR	0x01	/* Advanced Error Reporting */
+#define PCI_EXT_CAP_ID_VC	0x02	/* Virtual Channel Capability */
+#define PCI_EXT_CAP_ID_DSN	0x03	/* Device Serial Number */
+#define PCI_EXT_CAP_ID_PWR	0x04	/* Power Budgeting */
+#define PCI_EXT_CAP_ID_RCLD	0x05	/* Root Complex Link Declaration */
+#define PCI_EXT_CAP_ID_RCILC	0x06	/* Root Complex Internal Link Control */
+#define PCI_EXT_CAP_ID_RCEC	0x07	/* Root Complex Event Collector */
+#define PCI_EXT_CAP_ID_MFVC	0x08	/* Multi-Function VC Capability */
+#define PCI_EXT_CAP_ID_VC9	0x09	/* same as _VC */
+#define PCI_EXT_CAP_ID_RCRB	0x0A	/* Root Complex RB? */
+#define PCI_EXT_CAP_ID_VNDR	0x0B	/* Vendor Specific */
+#define PCI_EXT_CAP_ID_CAC	0x0C	/* Config Access - obsolete */
+#define PCI_EXT_CAP_ID_ACS	0x0D	/* Access Control Services */
+#define PCI_EXT_CAP_ID_ARI	0x0E	/* Alternate Routing ID */
+#define PCI_EXT_CAP_ID_ATS	0x0F	/* Address Translation Services */
+#define PCI_EXT_CAP_ID_SRIOV	0x10	/* Single Root I/O Virtualization */
+#define PCI_EXT_CAP_ID_MRIOV	0x11	/* Multi Root I/O Virtualization */
+#define PCI_EXT_CAP_ID_MCAST	0x12	/* Multicast */
+#define PCI_EXT_CAP_ID_PRI	0x13	/* Page Request Interface */
+#define PCI_EXT_CAP_ID_AMD_XXX	0x14	/* reserved for AMD */
+#define PCI_EXT_CAP_ID_REBAR	0x15	/* resizable BAR */
+#define PCI_EXT_CAP_ID_DPA	0x16	/* dynamic power alloc */
+#define PCI_EXT_CAP_ID_TPH	0x17	/* TPH request */
+#define PCI_EXT_CAP_ID_LTR	0x18	/* latency tolerance reporting */
+#define PCI_EXT_CAP_ID_SECPCI	0x19	/* Secondary PCIe */
+#define PCI_EXT_CAP_ID_PMUX	0x1A	/* Protocol Multiplexing */
+#define PCI_EXT_CAP_ID_PASID	0x1B	/* Process Address Space ID */
+#define PCI_EXT_CAP_ID_MAX	PCI_EXT_CAP_ID_PASID
+
+#define PCI_EXT_CAP_DSN_SIZEOF	12
+#define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
 
 /* Advanced Error Reporting */
 #define PCI_ERR_UNCOR_STATUS	4	/* Uncorrectable Error Status */
 #define  PCI_ERR_UNC_TRAIN	0x00000001	/* Training */
 #define  PCI_ERR_UNC_DLP	0x00000010	/* Data Link Protocol */
+#define  PCI_ERR_UNC_SURPDN	0x00000020	/* Surprise Down */
 #define  PCI_ERR_UNC_POISON_TLP	0x00001000	/* Poisoned TLP */
 #define  PCI_ERR_UNC_FCP	0x00002000	/* Flow Control Protocol */
 #define  PCI_ERR_UNC_COMP_TIME	0x00004000	/* Completion Timeout */
@@ -555,6 +589,11 @@
 #define  PCI_ERR_UNC_MALF_TLP	0x00040000	/* Malformed TLP */
 #define  PCI_ERR_UNC_ECRC	0x00080000	/* ECRC Error Status */
 #define  PCI_ERR_UNC_UNSUP	0x00100000	/* Unsupported Request */
+#define  PCI_ERR_UNC_ACSV	0x00200000	/* ACS Violation */
+#define  PCI_ERR_UNC_INTN	0x00400000	/* internal error */
+#define  PCI_ERR_UNC_MCBTLP	0x00800000	/* MC blocked TLP */
+#define  PCI_ERR_UNC_ATOMEG	0x01000000	/* Atomic egress blocked */
+#define  PCI_ERR_UNC_TLPPRE	0x02000000	/* TLP prefix blocked */
 #define PCI_ERR_UNCOR_MASK	8	/* Uncorrectable Error Mask */
 	/* Same bits as above */
 #define PCI_ERR_UNCOR_SEVER	12	/* Uncorrectable Error Severity */
@@ -565,6 +604,9 @@
 #define  PCI_ERR_COR_BAD_DLLP	0x00000080	/* Bad DLLP Status */
 #define  PCI_ERR_COR_REP_ROLL	0x00000100	/* REPLAY_NUM Rollover */
 #define  PCI_ERR_COR_REP_TIMER	0x00001000	/* Replay Timer Timeout */
+#define  PCI_ERR_COR_ADV_NFAT	0x00002000	/* Advisory Non-Fatal */
+#define  PCI_ERR_COR_INTERNAL	0x00004000	/* Corrected Internal */
+#define  PCI_ERR_COR_LOG_OVER	0x00008000	/* Header Log Overflow */
 #define PCI_ERR_COR_MASK	20	/* Correctable Error Mask */
 	/* Same bits as above */
 #define PCI_ERR_CAP		24	/* Advanced Error Capabilities */
@@ -596,12 +638,18 @@
 
 /* Virtual Channel */
 #define PCI_VC_PORT_REG1	4
+#define  PCI_VC_REG1_EVCC	0x7	/* extended vc count */
 #define PCI_VC_PORT_REG2	8
+#define  PCI_VC_REG2_32_PHASE	0x2
+#define  PCI_VC_REG2_64_PHASE	0x4
+#define  PCI_VC_REG2_128_PHASE	0x8
 #define PCI_VC_PORT_CTRL	12
 #define PCI_VC_PORT_STATUS	14
 #define PCI_VC_RES_CAP		16
 #define PCI_VC_RES_CTRL		20
 #define PCI_VC_RES_STATUS	26
+#define PCI_CAP_VC_BASE_SIZEOF		0x10
+#define PCI_CAP_VC_PER_VC_SIZEOF	0x0C
 
 /* Power Budgeting */
 #define PCI_PWR_DSR		4	/* Data Select Register */
@@ -614,6 +662,7 @@
 #define  PCI_PWR_DATA_RAIL(x)	(((x) >> 18) & 7)   /* Power Rail */
 #define PCI_PWR_CAP		12	/* Capability */
 #define  PCI_PWR_CAP_BUDGET(x)	((x) & 1)	/* Included in system budget */
+#define PCI_EXT_CAP_PWR_SIZEOF	16
 
 /*
  * Hypertransport sub capability types
@@ -646,6 +695,8 @@
 #define HT_CAPTYPE_ERROR_RETRY	0xC0	/* Retry on error configuration */
 #define HT_CAPTYPE_GEN3		0xD0	/* Generation 3 hypertransport configuration */
 #define HT_CAPTYPE_PM		0xE0	/* Hypertransport powermanagement configuration */
+#define HT_CAP_SIZEOF_LONG	28	/* slave & primary */
+#define HT_CAP_SIZEOF_SHORT	24	/* host & secondary */
 
 /* Alternative Routing-ID Interpretation */
 #define PCI_ARI_CAP		0x04	/* ARI Capability Register */
@@ -656,6 +707,7 @@
 #define  PCI_ARI_CTRL_MFVC	0x0001	/* MFVC Function Groups Enable */
 #define  PCI_ARI_CTRL_ACS	0x0002	/* ACS Function Groups Enable */
 #define  PCI_ARI_CTRL_FG(x)	(((x) >> 4) & 7) /* Function Group */
+#define PCI_EXT_CAP_ARI_SIZEOF	8
 
 /* Address Translation Service */
 #define PCI_ATS_CAP		0x04	/* ATS Capability Register */
@@ -665,6 +717,7 @@
 #define  PCI_ATS_CTRL_ENABLE	0x8000	/* ATS Enable */
 #define  PCI_ATS_CTRL_STU(x)	((x) & 0x1f)	/* Smallest Translation Unit */
 #define  PCI_ATS_MIN_STU	12	/* shift of minimum STU block */
+#define PCI_EXT_CAP_ATS_SIZEOF	8
 
 /* Page Request Interface */
 #define PCI_PRI_CTRL		0x04	/* PRI control register */
@@ -676,6 +729,7 @@
 #define  PCI_PRI_STATUS_STOPPED	0x100	/* PRI Stopped */
 #define PCI_PRI_MAX_REQ		0x08	/* PRI max reqs supported */
 #define PCI_PRI_ALLOC_REQ	0x0c	/* PRI max reqs allowed */
+#define PCI_EXT_CAP_PRI_SIZEOF	16
 
 /* PASID capability */
 #define PCI_PASID_CAP		0x04    /* PASID feature register */
@@ -685,6 +739,7 @@
 #define  PCI_PASID_CTRL_ENABLE	0x01	/* Enable bit */
 #define  PCI_PASID_CTRL_EXEC	0x02	/* Exec permissions Enable */
 #define  PCI_PASID_CTRL_PRIV	0x04	/* Priviledge Mode Enable */
+#define PCI_EXT_CAP_PASID_SIZEOF	8
 
 /* Single Root I/O Virtualization */
 #define PCI_SRIOV_CAP		0x04	/* SR-IOV Capabilities */
@@ -716,12 +771,14 @@
 #define  PCI_SRIOV_VFM_MI	0x1	/* Dormant.MigrateIn */
 #define  PCI_SRIOV_VFM_MO	0x2	/* Active.MigrateOut */
 #define  PCI_SRIOV_VFM_AV	0x3	/* Active.Available */
+#define PCI_EXT_CAP_SRIOV_SIZEOF 64
 
 #define PCI_LTR_MAX_SNOOP_LAT	0x4
 #define PCI_LTR_MAX_NOSNOOP_LAT	0x6
 #define  PCI_LTR_VALUE_MASK	0x000003ff
 #define  PCI_LTR_SCALE_MASK	0x00001c00
 #define  PCI_LTR_SCALE_SHIFT	10
+#define PCI_EXT_CAP_LTR_SIZEOF	8
 
 /* Access Control Service */
 #define PCI_ACS_CAP		0x04	/* ACS Capability Register */
@@ -732,7 +789,38 @@
 #define  PCI_ACS_UF		0x10	/* Upstream Forwarding */
 #define  PCI_ACS_EC		0x20	/* P2P Egress Control */
 #define  PCI_ACS_DT		0x40	/* Direct Translated P2P */
+#define PCI_ACS_EGRESS_BITS	0x05	/* ACS Egress Control Vector Size */
 #define PCI_ACS_CTRL		0x06	/* ACS Control Register */
 #define PCI_ACS_EGRESS_CTL_V	0x08	/* ACS Egress Control Vector */
 
+#define PCI_VSEC_HDR		4	/* extended cap - vendor specific */
+#define  PCI_VSEC_HDR_LEN_SHIFT	20	/* shift for length field */
+
+/* sata capability */
+#define PCI_SATA_REGS		4	/* SATA REGs specifier */
+#define  PCI_SATA_REGS_MASK	0xF	/* location - BAR#/inline */
+#define  PCI_SATA_REGS_INLINE	0xF	/* REGS in config space */
+#define PCI_SATA_SIZEOF_SHORT	8
+#define PCI_SATA_SIZEOF_LONG	16
+
+/* resizable BARs */
+#define PCI_REBAR_CTRL		8	/* control register */
+#define  PCI_REBAR_CTRL_NBAR_MASK	(7 << 5)	/* mask for # bars */
+#define  PCI_REBAR_CTRL_NBAR_SHIFT	5	/* shift for # bars */
+
+/* dynamic power allocation */
+#define PCI_DPA_CAP		4	/* capability register */
+#define  PCI_DPA_CAP_SUBSTATE_MASK	0x1F	/* # substates - 1 */
+#define PCI_DPA_BASE_SIZEOF	16	/* size with 0 substates */
+
+/* TPH Requester */
+#define PCI_TPH_CAP		4	/* capability register */
+#define  PCI_TPH_CAP_LOC_MASK	0x600	/* location mask */
+#define   PCI_TPH_LOC_NONE	0x000	/* no location */
+#define   PCI_TPH_LOC_CAP	0x200	/* in capability */
+#define   PCI_TPH_LOC_MSIX	0x400	/* in MSI-X */
+#define PCI_TPH_CAP_ST_MASK	0x07FF0000	/* st table mask */
+#define PCI_TPH_CAP_ST_SHIFT	16	/* st table shift */
+#define PCI_TPH_BASE_SIZEOF	12	/* size with no st table */
+
 #endif /* LINUX_PCI_REGS_H */
#20 lore raw

Re: [PATCH v2 12/13] pci: Misc pci_reg additions

Quoted 6 lines · Alex Williamson

Fill in many missing definitions and add sizeof fields for many sections allowing for more extensive config parsing.

---

overall, i'm very glad to see defines instead of hardcoded numbers in the code, but....

Quoted 64 lines
  include/linux/pci_regs.h |  112 +++++++++++++++++++++++++++++++++++++++++-----
  1 files changed, 100 insertions(+), 12 deletions(-)
include/linux/pci_regs.h +9 -0
index 4b608f5..379be84 100644
@@ -26,6 +26,7 @@
   * Under PCI, each device has 256 bytes of configuration address space,
   * of which the first 64 bytes are standardized as follows:
   */
+#define PCI_STD_HEADER_SIZEOF	64
  #define PCI_VENDOR_ID		0x00	/* 16 bits */
  #define PCI_DEVICE_ID		0x02	/* 16 bits */
  #define PCI_COMMAND		0x04	/* 16 bits */
@@ -209,9 +210,12 @@
  #define  PCI_CAP_ID_SHPC 	0x0C	/* PCI Standard Hot-Plug Controller */
  #define  PCI_CAP_ID_SSVID	0x0D	/* Bridge subsystem vendor/device ID */
  #define  PCI_CAP_ID_AGP3	0x0E	/* AGP Target PCI-PCI bridge */
+#define  PCI_CAP_ID_SECDEV	0x0F	/* Secure Device */
  #define  PCI_CAP_ID_EXP 	0x10	/* PCI Express */
  #define  PCI_CAP_ID_MSIX	0x11	/* MSI-X */
+#define  PCI_CAP_ID_SATA	0x12	/* SATA Data/Index Conf. */
  #define  PCI_CAP_ID_AF		0x13	/* PCI Advanced Features */
+#define  PCI_CAP_ID_MAX		PCI_CAP_ID_AF
  #define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
  #define PCI_CAP_FLAGS		2	/* Capability defined flags (16 bits) */
  #define PCI_CAP_SIZEOF		4
@@ -276,6 +280,7 @@
  #define  PCI_VPD_ADDR_MASK	0x7fff	/* Address mask */
  #define  PCI_VPD_ADDR_F		0x8000	/* Write 0, 1 indicates completion */
  #define PCI_VPD_DATA		4	/* 32-bits of data returned here */
+#define PCI_CAP_VPD_SIZEOF	8
 
  /* Slot Identification */
 
@@ -297,8 +302,10 @@
  #define PCI_MSI_ADDRESS_HI	8	/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
  #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
  #define PCI_MSI_MASK_32		12	/* Mask bits register for 32-bit devices */
+#define PCI_MSI_PENDING_32	16	/* Pending intrs for 32-bit devices */
  #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
  #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
+#define PCI_MSI_PENDING_64	20	/* Pending intrs for 64-bit devices */
 
  /* MSI-X registers */
  #define PCI_MSIX_FLAGS		2
@@ -308,6 +315,7 @@
  #define PCI_MSIX_TABLE		4
  #define PCI_MSIX_PBA		8
  #define  PCI_MSIX_FLAGS_BIRMASK	(7<<  0)
+#define PCI_CAP_MSIX_SIZEOF	12	/* size of MSIX registers */
 
  /* MSI-X entry's format */
  #define PCI_MSIX_ENTRY_SIZE		16
@@ -338,6 +346,7 @@
  #define  PCI_AF_CTRL_FLR	0x01
  #define PCI_AF_STATUS		5
  #define  PCI_AF_STATUS_TP	0x01
+#define PCI_CAP_AF_SIZEOF	6	/* size of AF registers */
 
  /* PCI-X registers */
 

include/linux/pci_regs.h line 388

Quoted 6 lines
include/linux/pci_regs.h +3 -0
@@ -374,6 +383,9 @@
  #define  PCI_X_STATUS_SPL_ERR	0x20000000	/* Rcvd Split Completion Error Msg */
  #define  PCI_X_STATUS_266MHZ	0x40000000	/* 266 MHz capable */
  #define  PCI_X_STATUS_533MHZ	0x80000000	/* 533 MHz capable */
+#define PCI_X_ECC_CSR		8	/* ECC control and status */
+#define PCI_CAP_PCIX_SIZEOF_V0	8	/* size of registers for Version 0 */
+#define PCI_CAP_PCIX_SIZEOF_V12	24	/* size for Version 1&  2 */

ew!
unlikely that version 12 will ever exist, but why not:
#define PCI_CAP_PCIX_SIZEOF_V1 24
#define PCI_CAP_PCIX_SIZEOF_V2 PCI_CAP_PCIX_SIZEOF_V1

Quoted 220 lines
include/linux/pci_regs.h +88 -12
  /* PCI Bridge Subsystem ID registers */
 
@@ -462,6 +474,7 @@
  #define  PCI_EXP_LNKSTA_DLLLA	0x2000	/* Data Link Layer Link Active */
  #define  PCI_EXP_LNKSTA_LBMS	0x4000	/* Link Bandwidth Management Status */
  #define  PCI_EXP_LNKSTA_LABS	0x8000	/* Link Autonomous Bandwidth Status */
+#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V1	20	/* v1 endpoints end here */
  #define PCI_EXP_SLTCAP		20	/* Slot Capabilities */
  #define  PCI_EXP_SLTCAP_ABP	0x00000001 /* Attention Button Present */
  #define  PCI_EXP_SLTCAP_PCP	0x00000002 /* Power Controller Present */
@@ -521,6 +534,7 @@
  #define  PCI_EXP_OBFF_MSGA_EN	0x2000	/* OBFF enable with Message type A */
  #define  PCI_EXP_OBFF_MSGB_EN	0x4000	/* OBFF enable with Message type B */
  #define  PCI_EXP_OBFF_WAKE_EN	0x6000	/* OBFF using WAKE# signaling */
+#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2	44	/* v2 endpoints end here */
  #define PCI_EXP_LNKCTL2		48	/* Link Control 2 */
  #define PCI_EXP_SLTCTL2		56	/* Slot Control 2 */
 
@@ -529,23 +543,43 @@
  #define PCI_EXT_CAP_VER(header)		((header>>  16)&  0xf)
  #define PCI_EXT_CAP_NEXT(header)	((header>>  20)&  0xffc)
 
-#define PCI_EXT_CAP_ID_ERR	1
-#define PCI_EXT_CAP_ID_VC	2
-#define PCI_EXT_CAP_ID_DSN	3
-#define PCI_EXT_CAP_ID_PWR	4
-#define PCI_EXT_CAP_ID_VNDR	11
-#define PCI_EXT_CAP_ID_ACS	13
-#define PCI_EXT_CAP_ID_ARI	14
-#define PCI_EXT_CAP_ID_ATS	15
-#define PCI_EXT_CAP_ID_SRIOV	16
-#define PCI_EXT_CAP_ID_PRI	19
-#define PCI_EXT_CAP_ID_LTR	24
-#define PCI_EXT_CAP_ID_PASID	27
+#define PCI_EXT_CAP_ID_ERR	0x01	/* Advanced Error Reporting */
+#define PCI_EXT_CAP_ID_VC	0x02	/* Virtual Channel Capability */
+#define PCI_EXT_CAP_ID_DSN	0x03	/* Device Serial Number */
+#define PCI_EXT_CAP_ID_PWR	0x04	/* Power Budgeting */
+#define PCI_EXT_CAP_ID_RCLD	0x05	/* Root Complex Link Declaration */
+#define PCI_EXT_CAP_ID_RCILC	0x06	/* Root Complex Internal Link Control */
+#define PCI_EXT_CAP_ID_RCEC	0x07	/* Root Complex Event Collector */
+#define PCI_EXT_CAP_ID_MFVC	0x08	/* Multi-Function VC Capability */
+#define PCI_EXT_CAP_ID_VC9	0x09	/* same as _VC */
+#define PCI_EXT_CAP_ID_RCRB	0x0A	/* Root Complex RB? */
+#define PCI_EXT_CAP_ID_VNDR	0x0B	/* Vendor Specific */
+#define PCI_EXT_CAP_ID_CAC	0x0C	/* Config Access - obsolete */
+#define PCI_EXT_CAP_ID_ACS	0x0D	/* Access Control Services */
+#define PCI_EXT_CAP_ID_ARI	0x0E	/* Alternate Routing ID */
+#define PCI_EXT_CAP_ID_ATS	0x0F	/* Address Translation Services */
+#define PCI_EXT_CAP_ID_SRIOV	0x10	/* Single Root I/O Virtualization */
+#define PCI_EXT_CAP_ID_MRIOV	0x11	/* Multi Root I/O Virtualization */
+#define PCI_EXT_CAP_ID_MCAST	0x12	/* Multicast */
+#define PCI_EXT_CAP_ID_PRI	0x13	/* Page Request Interface */
+#define PCI_EXT_CAP_ID_AMD_XXX	0x14	/* reserved for AMD */
+#define PCI_EXT_CAP_ID_REBAR	0x15	/* resizable BAR */
+#define PCI_EXT_CAP_ID_DPA	0x16	/* dynamic power alloc */
+#define PCI_EXT_CAP_ID_TPH	0x17	/* TPH request */
+#define PCI_EXT_CAP_ID_LTR	0x18	/* latency tolerance reporting */
+#define PCI_EXT_CAP_ID_SECPCI	0x19	/* Secondary PCIe */
+#define PCI_EXT_CAP_ID_PMUX	0x1A	/* Protocol Multiplexing */
+#define PCI_EXT_CAP_ID_PASID	0x1B	/* Process Address Space ID */
+#define PCI_EXT_CAP_ID_MAX	PCI_EXT_CAP_ID_PASID
+
+#define PCI_EXT_CAP_DSN_SIZEOF	12
+#define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
 
  /* Advanced Error Reporting */
  #define PCI_ERR_UNCOR_STATUS	4	/* Uncorrectable Error Status */
  #define  PCI_ERR_UNC_TRAIN	0x00000001	/* Training */
  #define  PCI_ERR_UNC_DLP	0x00000010	/* Data Link Protocol */
+#define  PCI_ERR_UNC_SURPDN	0x00000020	/* Surprise Down */
  #define  PCI_ERR_UNC_POISON_TLP	0x00001000	/* Poisoned TLP */
  #define  PCI_ERR_UNC_FCP	0x00002000	/* Flow Control Protocol */
  #define  PCI_ERR_UNC_COMP_TIME	0x00004000	/* Completion Timeout */
@@ -555,6 +589,11 @@
  #define  PCI_ERR_UNC_MALF_TLP	0x00040000	/* Malformed TLP */
  #define  PCI_ERR_UNC_ECRC	0x00080000	/* ECRC Error Status */
  #define  PCI_ERR_UNC_UNSUP	0x00100000	/* Unsupported Request */
+#define  PCI_ERR_UNC_ACSV	0x00200000	/* ACS Violation */
+#define  PCI_ERR_UNC_INTN	0x00400000	/* internal error */
+#define  PCI_ERR_UNC_MCBTLP	0x00800000	/* MC blocked TLP */
+#define  PCI_ERR_UNC_ATOMEG	0x01000000	/* Atomic egress blocked */
+#define  PCI_ERR_UNC_TLPPRE	0x02000000	/* TLP prefix blocked */
  #define PCI_ERR_UNCOR_MASK	8	/* Uncorrectable Error Mask */
  	/* Same bits as above */
  #define PCI_ERR_UNCOR_SEVER	12	/* Uncorrectable Error Severity */
@@ -565,6 +604,9 @@
  #define  PCI_ERR_COR_BAD_DLLP	0x00000080	/* Bad DLLP Status */
  #define  PCI_ERR_COR_REP_ROLL	0x00000100	/* REPLAY_NUM Rollover */
  #define  PCI_ERR_COR_REP_TIMER	0x00001000	/* Replay Timer Timeout */
+#define  PCI_ERR_COR_ADV_NFAT	0x00002000	/* Advisory Non-Fatal */
+#define  PCI_ERR_COR_INTERNAL	0x00004000	/* Corrected Internal */
+#define  PCI_ERR_COR_LOG_OVER	0x00008000	/* Header Log Overflow */
  #define PCI_ERR_COR_MASK	20	/* Correctable Error Mask */
  	/* Same bits as above */
  #define PCI_ERR_CAP		24	/* Advanced Error Capabilities */
@@ -596,12 +638,18 @@
 
  /* Virtual Channel */
  #define PCI_VC_PORT_REG1	4
+#define  PCI_VC_REG1_EVCC	0x7	/* extended vc count */
  #define PCI_VC_PORT_REG2	8
+#define  PCI_VC_REG2_32_PHASE	0x2
+#define  PCI_VC_REG2_64_PHASE	0x4
+#define  PCI_VC_REG2_128_PHASE	0x8
  #define PCI_VC_PORT_CTRL	12
  #define PCI_VC_PORT_STATUS	14
  #define PCI_VC_RES_CAP		16
  #define PCI_VC_RES_CTRL		20
  #define PCI_VC_RES_STATUS	26
+#define PCI_CAP_VC_BASE_SIZEOF		0x10
+#define PCI_CAP_VC_PER_VC_SIZEOF	0x0C
 
  /* Power Budgeting */
  #define PCI_PWR_DSR		4	/* Data Select Register */
@@ -614,6 +662,7 @@
  #define  PCI_PWR_DATA_RAIL(x)	(((x)>>  18)&  7)   /* Power Rail */
  #define PCI_PWR_CAP		12	/* Capability */
  #define  PCI_PWR_CAP_BUDGET(x)	((x)&  1)	/* Included in system budget */
+#define PCI_EXT_CAP_PWR_SIZEOF	16
 
  /*
   * Hypertransport sub capability types
@@ -646,6 +695,8 @@
  #define HT_CAPTYPE_ERROR_RETRY	0xC0	/* Retry on error configuration */
  #define HT_CAPTYPE_GEN3		0xD0	/* Generation 3 hypertransport configuration */
  #define HT_CAPTYPE_PM		0xE0	/* Hypertransport powermanagement configuration */
+#define HT_CAP_SIZEOF_LONG	28	/* slave&  primary */
+#define HT_CAP_SIZEOF_SHORT	24	/* host&  secondary */
 
  /* Alternative Routing-ID Interpretation */
  #define PCI_ARI_CAP		0x04	/* ARI Capability Register */
@@ -656,6 +707,7 @@
  #define  PCI_ARI_CTRL_MFVC	0x0001	/* MFVC Function Groups Enable */
  #define  PCI_ARI_CTRL_ACS	0x0002	/* ACS Function Groups Enable */
  #define  PCI_ARI_CTRL_FG(x)	(((x)>>  4)&  7) /* Function Group */
+#define PCI_EXT_CAP_ARI_SIZEOF	8
 
  /* Address Translation Service */
  #define PCI_ATS_CAP		0x04	/* ATS Capability Register */
@@ -665,6 +717,7 @@
  #define  PCI_ATS_CTRL_ENABLE	0x8000	/* ATS Enable */
  #define  PCI_ATS_CTRL_STU(x)	((x)&  0x1f)	/* Smallest Translation Unit */
  #define  PCI_ATS_MIN_STU	12	/* shift of minimum STU block */
+#define PCI_EXT_CAP_ATS_SIZEOF	8
 
  /* Page Request Interface */
  #define PCI_PRI_CTRL		0x04	/* PRI control register */
@@ -676,6 +729,7 @@
  #define  PCI_PRI_STATUS_STOPPED	0x100	/* PRI Stopped */
  #define PCI_PRI_MAX_REQ		0x08	/* PRI max reqs supported */
  #define PCI_PRI_ALLOC_REQ	0x0c	/* PRI max reqs allowed */
+#define PCI_EXT_CAP_PRI_SIZEOF	16
 
  /* PASID capability */
  #define PCI_PASID_CAP		0x04    /* PASID feature register */
@@ -685,6 +739,7 @@
  #define  PCI_PASID_CTRL_ENABLE	0x01	/* Enable bit */
  #define  PCI_PASID_CTRL_EXEC	0x02	/* Exec permissions Enable */
  #define  PCI_PASID_CTRL_PRIV	0x04	/* Priviledge Mode Enable */
+#define PCI_EXT_CAP_PASID_SIZEOF	8
 
  /* Single Root I/O Virtualization */
  #define PCI_SRIOV_CAP		0x04	/* SR-IOV Capabilities */
@@ -716,12 +771,14 @@
  #define  PCI_SRIOV_VFM_MI	0x1	/* Dormant.MigrateIn */
  #define  PCI_SRIOV_VFM_MO	0x2	/* Active.MigrateOut */
  #define  PCI_SRIOV_VFM_AV	0x3	/* Active.Available */
+#define PCI_EXT_CAP_SRIOV_SIZEOF 64
 
  #define PCI_LTR_MAX_SNOOP_LAT	0x4
  #define PCI_LTR_MAX_NOSNOOP_LAT	0x6
  #define  PCI_LTR_VALUE_MASK	0x000003ff
  #define  PCI_LTR_SCALE_MASK	0x00001c00
  #define  PCI_LTR_SCALE_SHIFT	10
+#define PCI_EXT_CAP_LTR_SIZEOF	8
 
  /* Access Control Service */
  #define PCI_ACS_CAP		0x04	/* ACS Capability Register */
@@ -732,7 +789,38 @@
  #define  PCI_ACS_UF		0x10	/* Upstream Forwarding */
  #define  PCI_ACS_EC		0x20	/* P2P Egress Control */
  #define  PCI_ACS_DT		0x40	/* Direct Translated P2P */
+#define PCI_ACS_EGRESS_BITS	0x05	/* ACS Egress Control Vector Size */
  #define PCI_ACS_CTRL		0x06	/* ACS Control Register */
  #define PCI_ACS_EGRESS_CTL_V	0x08	/* ACS Egress Control Vector */
 
+#define PCI_VSEC_HDR		4	/* extended cap - vendor specific */
+#define  PCI_VSEC_HDR_LEN_SHIFT	20	/* shift for length field */
+
+/* sata capability */
+#define PCI_SATA_REGS		4	/* SATA REGs specifier */
+#define  PCI_SATA_REGS_MASK	0xF	/* location - BAR#/inline */
+#define  PCI_SATA_REGS_INLINE	0xF	/* REGS in config space */
+#define PCI_SATA_SIZEOF_SHORT	8
+#define PCI_SATA_SIZEOF_LONG	16
+
+/* resizable BARs */
+#define PCI_REBAR_CTRL		8	/* control register */
+#define  PCI_REBAR_CTRL_NBAR_MASK	(7<<  5)	/* mask for # bars */
+#define  PCI_REBAR_CTRL_NBAR_SHIFT	5	/* shift for # bars */
+
+/* dynamic power allocation */
+#define PCI_DPA_CAP		4	/* capability register */
+#define  PCI_DPA_CAP_SUBSTATE_MASK	0x1F	/* # substates - 1 */
+#define PCI_DPA_BASE_SIZEOF	16	/* size with 0 substates */
+
+/* TPH Requester */
+#define PCI_TPH_CAP		4	/* capability register */
+#define  PCI_TPH_CAP_LOC_MASK	0x600	/* location mask */
+#define   PCI_TPH_LOC_NONE	0x000	/* no location */
+#define   PCI_TPH_LOC_CAP	0x200	/* in capability */
+#define   PCI_TPH_LOC_MSIX	0x400	/* in MSI-X */
+#define PCI_TPH_CAP_ST_MASK	0x07FF0000	/* st table mask */
+#define PCI_TPH_CAP_ST_SHIFT	16	/* st table shift */
+#define PCI_TPH_BASE_SIZEOF	12	/* size with no st table */
+
  #endif /* LINUX_PCI_REGS_H */
#21 lore raw

Re: [PATCH v2 12/13] pci: Misc pci_reg additions

Quoted 72 lines · Don Dutile
Quoted 6 lines · Alex Williamson

Fill in many missing definitions and add sizeof fields for many sections allowing for more extensive config parsing.

---

overall, i'm very glad to see defines instead of hardcoded numbers in the code, but....

Quoted 63 lines
  include/linux/pci_regs.h |  112 +++++++++++++++++++++++++++++++++++++++++-----
  1 files changed, 100 insertions(+), 12 deletions(-)
include/linux/pci_regs.h +9 -0
index 4b608f5..379be84 100644
@@ -26,6 +26,7 @@
   * Under PCI, each device has 256 bytes of configuration address space,
   * of which the first 64 bytes are standardized as follows:
   */
+#define PCI_STD_HEADER_SIZEOF	64
  #define PCI_VENDOR_ID		0x00	/* 16 bits */
  #define PCI_DEVICE_ID		0x02	/* 16 bits */
  #define PCI_COMMAND		0x04	/* 16 bits */
@@ -209,9 +210,12 @@
  #define  PCI_CAP_ID_SHPC 	0x0C	/* PCI Standard Hot-Plug Controller */
  #define  PCI_CAP_ID_SSVID	0x0D	/* Bridge subsystem vendor/device ID */
  #define  PCI_CAP_ID_AGP3	0x0E	/* AGP Target PCI-PCI bridge */
+#define  PCI_CAP_ID_SECDEV	0x0F	/* Secure Device */
  #define  PCI_CAP_ID_EXP 	0x10	/* PCI Express */
  #define  PCI_CAP_ID_MSIX	0x11	/* MSI-X */
+#define  PCI_CAP_ID_SATA	0x12	/* SATA Data/Index Conf. */
  #define  PCI_CAP_ID_AF		0x13	/* PCI Advanced Features */
+#define  PCI_CAP_ID_MAX		PCI_CAP_ID_AF
  #define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
  #define PCI_CAP_FLAGS		2	/* Capability defined flags (16 bits) */
  #define PCI_CAP_SIZEOF		4
@@ -276,6 +280,7 @@
  #define  PCI_VPD_ADDR_MASK	0x7fff	/* Address mask */
  #define  PCI_VPD_ADDR_F		0x8000	/* Write 0, 1 indicates completion */
  #define PCI_VPD_DATA		4	/* 32-bits of data returned here */
+#define PCI_CAP_VPD_SIZEOF	8
 
  /* Slot Identification */
 
@@ -297,8 +302,10 @@
  #define PCI_MSI_ADDRESS_HI	8	/* Upper 32 bits (if PCI_MSI_FLAGS_64BIT set) */
  #define PCI_MSI_DATA_32		8	/* 16 bits of data for 32-bit devices */
  #define PCI_MSI_MASK_32		12	/* Mask bits register for 32-bit devices */
+#define PCI_MSI_PENDING_32	16	/* Pending intrs for 32-bit devices */
  #define PCI_MSI_DATA_64		12	/* 16 bits of data for 64-bit devices */
  #define PCI_MSI_MASK_64		16	/* Mask bits register for 64-bit devices */
+#define PCI_MSI_PENDING_64	20	/* Pending intrs for 64-bit devices */
 
  /* MSI-X registers */
  #define PCI_MSIX_FLAGS		2
@@ -308,6 +315,7 @@
  #define PCI_MSIX_TABLE		4
  #define PCI_MSIX_PBA		8
  #define  PCI_MSIX_FLAGS_BIRMASK	(7<<  0)
+#define PCI_CAP_MSIX_SIZEOF	12	/* size of MSIX registers */
 
  /* MSI-X entry's format */
  #define PCI_MSIX_ENTRY_SIZE		16
@@ -338,6 +346,7 @@
  #define  PCI_AF_CTRL_FLR	0x01
  #define PCI_AF_STATUS		5
  #define  PCI_AF_STATUS_TP	0x01
+#define PCI_CAP_AF_SIZEOF	6	/* size of AF registers */
 
  /* PCI-X registers */
 
Quoted 11 lines

include/linux/pci_regs.h line 388

Quoted 7 lines
include/linux/pci_regs.h +3 -0
@@ -374,6 +383,9 @@
  #define  PCI_X_STATUS_SPL_ERR	0x20000000	/* Rcvd Split Completion Error Msg */
  #define  PCI_X_STATUS_266MHZ	0x40000000	/* 266 MHz capable */
  #define  PCI_X_STATUS_533MHZ	0x80000000	/* 533 MHz capable */
+#define PCI_X_ECC_CSR		8	/* ECC control and status */
+#define PCI_CAP_PCIX_SIZEOF_V0	8	/* size of registers for Version 0 */
+#define PCI_CAP_PCIX_SIZEOF_V12	24	/* size for Version 1&  2 */

ew!
unlikely that version 12 will ever exist, but why not:
#define PCI_CAP_PCIX_SIZEOF_V1 24
#define PCI_CAP_PCIX_SIZEOF_V2 PCI_CAP_PCIX_SIZEOF_V1

Works for me, will fix. Thanks,

Alex

#22 lore raw

PATCH v2 13/13 vfio: Add PCI device driver

In reply to Alex Williamson

Add PCI device support for VFIO. PCI devices expose regions for accessing config space, I/O port space, and MMIO areas of the device. PCI config access is virtualized in the kernel, allowing us to ensure the integrity of the system, by preventing various accesses while reducing duplicate support across various userspace drivers. I/O port supports read/write access while MMIO also supports mmap of sufficiently sized regions. Support for INTx, MSI, and MSI-X interrupts are provided using eventfds to userspace.

---

 drivers/vfio/Kconfig                |    2 
 drivers/vfio/pci/Kconfig            |    8 
 drivers/vfio/pci/Makefile           |    4 
 drivers/vfio/pci/vfio_pci.c         |  557 +++++++++++++
 drivers/vfio/pci/vfio_pci_config.c  | 1522 +++++++++++++++++++++++++++++++++++
 drivers/vfio/pci/vfio_pci_intrs.c   |  724 +++++++++++++++++
 drivers/vfio/pci/vfio_pci_private.h |   91 ++
 drivers/vfio/pci/vfio_pci_rdwr.c    |  269 ++++++
 include/linux/vfio.h                |   26 +
 9 files changed, 3203 insertions(+), 0 deletions(-)
 create mode 100644 drivers/vfio/pci/Kconfig
 create mode 100644 drivers/vfio/pci/Makefile
 create mode 100644 drivers/vfio/pci/vfio_pci.c
 create mode 100644 drivers/vfio/pci/vfio_pci_config.c
 create mode 100644 drivers/vfio/pci/vfio_pci_intrs.c
 create mode 100644 drivers/vfio/pci/vfio_pci_private.h
 create mode 100644 drivers/vfio/pci/vfio_pci_rdwr.c
drivers/vfio/Kconfig +2 -0
index bd88a30..77b754c 100644
@@ -12,3 +12,5 @@ menuconfig VFIO
 	  See Documentation/vfio.txt for more details.
 
 	  If you don't know what to do here, say N.
+
+source "drivers/vfio/pci/Kconfig"
drivers/vfio/pci/Kconfig new file +8 -0
new file mode 100644
index 0000000..cc7db62
@@ -0,0 +1,8 @@
+config VFIO_PCI
+	tristate "VFIO support for PCI devices"
+	depends on VFIO && PCI
+	help
+	  Support for the PCI VFIO bus driver.  This is required to make
+	  use of PCI drivers using the VFIO framework.
+
+	  If you don't know what to do here, say N.
drivers/vfio/pci/Makefile new file +4 -0
new file mode 100644
index 0000000..1310792
@@ -0,0 +1,4 @@
+
+vfio-pci-y := vfio_pci.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o
+
+obj-$(CONFIG_VFIO_PCI) += vfio-pci.o
drivers/vfio/pci/vfio_pci.c new file +557 -0

557 lines not on this page · raw message

drivers/vfio/pci/vfio_pci_config.c new file +1522 -0

1,522 lines not on this page · raw message

drivers/vfio/pci/vfio_pci_intrs.c new file +724 -0

724 lines not on this page · raw message

drivers/vfio/pci/vfio_pci_private.h new file +91 -0

91 lines not on this page · raw message

drivers/vfio/pci/vfio_pci_rdwr.c new file +269 -0

89 lines not on this page · raw message

include/linux/vfio.h +26 -0
index b3e4583..3c2deac 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#23 lore raw
In reply to Alex Williamson
Quoted 24 lines · Alex Williamson

Version 2 incorporating acks and feedback from v1. The PCI DMA quirk and ACS check are reworked, sysfs iommu groups ABI Documentation added as well as numerous other fixes, including patches from Alexey Kardashevskiy towards supporting POWER usage of VFIO and IOMMU groups.

This series can be found here on top of 3.4:

git://github.com/awilliam/linux-vfio.git iommu-group-vfio-20120521

The Qemu tree has also been updated to Qemu 1.1 and can be found here:

git://github.com/awilliam/qemu-vfio.git iommu-group-vfio

I'd really like to make a push to get this in for 3.5, so let's talk about how to do that across iommu, pci, and new driver. Joerg, are you sufficiently happy with the IOMMU group concept and code? We'll also need David Woodhouse buyin on the intel-iommu changes in patches 3& 6. Who needs to approve VFIO as a new driver, GregKH? Bjorn, I'd be happy to send the PCI changes as a series for you, but I wonder if it makes sense to collect acks for them if you approve and bundle them in with the associated code that needs them so you're not left with unused code. Let me know which you prefer. If there are better ways to do it, please let me know. Thanks,

Quoted 3 lines

Alex

---

ack to 1,2,4,6,8,10 & 11.
provided some minor feedback on 3,9,&12.
have to do final review of the big stuff, 7 & 13.

Quoted 62 lines

Alex Williamson (13):
vfio: Add PCI device driver
pci: Misc pci_reg additions
pci: Create common pcibios_err_to_errno
pci: export pci_user functions for use by other drivers
vfio: x86 IOMMU implementation
vfio: Add documentation
vfio: VFIO core
iommu: Make use of DMA quirking and ACS enabled check for groups
pci: Add ACS validation utility
pci: Add PCI DMA source ID quirk
iommu: IOMMU groups for VT-d and AMD-Vi
iommu: IOMMU Groups
driver core: Add iommu_group tracking to struct device

  .../ABI/testing/sysfs-kernel-iommu_groups          |   14
  Documentation/ioctl/ioctl-number.txt               |    1
  Documentation/vfio.txt                             |  315 ++++
  MAINTAINERS                                        |    8
  drivers/Kconfig                                    |    2
  drivers/Makefile                                   |    1
  drivers/iommu/amd_iommu.c                          |   67 +
  drivers/iommu/intel-iommu.c                        |   87 +
  drivers/iommu/iommu.c                              |  578 +++++++-
  drivers/pci/access.c                               |    6
  drivers/pci/pci.c                                  |   76 +
  drivers/pci/pci.h                                  |    7
  drivers/pci/quirks.c                               |   69 +
  drivers/vfio/Kconfig                               |   16
  drivers/vfio/Makefile                              |    3
  drivers/vfio/pci/Kconfig                           |    8
  drivers/vfio/pci/Makefile                          |    4
  drivers/vfio/pci/vfio_pci.c                        |  557 +++++++
  drivers/vfio/pci/vfio_pci_config.c                 | 1522 ++++++++++++++++++++
  drivers/vfio/pci/vfio_pci_intrs.c                  |  724 ++++++++++
  drivers/vfio/pci/vfio_pci_private.h                |   91 +
  drivers/vfio/pci/vfio_pci_rdwr.c                   |  269 ++++
  drivers/vfio/vfio.c                                | 1413 +++++++++++++++++++
  drivers/vfio/vfio_iommu_x86.c                      |  743 ++++++++++
  drivers/xen/xen-pciback/conf_space.c               |    6
  include/linux/device.h                             |    2
  include/linux/iommu.h                              |  104 +
  include/linux/pci.h                                |   49 +
  include/linux/pci_regs.h                           |  112 +
  include/linux/vfio.h                               |  444 ++++++
  30 files changed, 7182 insertions(+), 116 deletions(-)

create mode 100644 Documentation/ABI/testing/sysfs-kernel-iommu_groups create mode 100644 Documentation/vfio.txt
create mode 100644 drivers/vfio/Kconfig
create mode 100644 drivers/vfio/Makefile
create mode 100644 drivers/vfio/pci/Kconfig
create mode 100644 drivers/vfio/pci/Makefile
create mode 100644 drivers/vfio/pci/vfio_pci.c
create mode 100644 drivers/vfio/pci/vfio_pci_config.c create mode 100644 drivers/vfio/pci/vfio_pci_intrs.c create mode 100644 drivers/vfio/pci/vfio_pci_private.h create mode 100644 drivers/vfio/pci/vfio_pci_rdwr.c
create mode 100644 drivers/vfio/vfio.c
create mode 100644 drivers/vfio/vfio_iommu_x86.c
create mode 100644 include/linux/vfio.h