Skip to contentSkip to conversation

vfio, platform: add HIDMA and ACPI support

PATCH Superseded Sinan Kaya 2 participants 10 messages Mar 28, 2016 – May 1, 2016

Subsystems (4)

v3 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

v3 cover vfio, platform: add HIDMA and ACPI support

The patchset makes three different changes.
1. Add support for probing ACPI platform reset drivers.
2. Make reset driver a requirement by default with an optional kernel command line override
3. Add support for HIDMA reset driver.

Specific changes:

vfio, platform: make reset driver a requirement Changes from V2: (https://lkml.org/lkml/2016/3/11/463)
* add reset_required kernel command line option to override the requirement.

Sinan Kaya (3):
vfio, platform: add support for ACPI while detecting the reset driver vfio, platform: make reset driver a requirement by default vfio, platform: add QTI HIDMA reset driver

 drivers/vfio/platform/reset/Kconfig                |   9 ++
 drivers/vfio/platform/reset/Makefile               |   2 +
 .../vfio/platform/reset/vfio_platform_amdxgbe.c    |   4 +-
 .../platform/reset/vfio_platform_calxedaxgmac.c    |   4 +-
 .../vfio/platform/reset/vfio_platform_qcomhidma.c  | 101 ++++++++++++++++++
 drivers/vfio/platform/vfio_amba.c                  |   5 +
 drivers/vfio/platform/vfio_platform.c              |   5 +
 drivers/vfio/platform/vfio_platform_common.c       | 115 +++++++++++++++++----
 drivers/vfio/platform/vfio_platform_private.h      |  44 ++++----
 9 files changed, 250 insertions(+), 39 deletions(-)
 create mode 100644 drivers/vfio/platform/reset/vfio_platform_qcomhidma.c
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH v3 1/3 vfio, platform: add support for ACPI while detecting the reset driver

The code is using the compatible DT string to associate a reset driver with the actual device itself. The compatible string does not exist on ACPI based systems. HID is the unique identifier for a device driver instead. The change allows a driver to register with DT compatible string or ACPI HID and then match the object with one of these conditions.

Rules for loading the reset driver are as follow:
- ACPI HID needs match for ACPI systems
- DT compat needs to match for OF systems

---
 .../vfio/platform/reset/vfio_platform_amdxgbe.c    |   4 +-
 .../platform/reset/vfio_platform_calxedaxgmac.c    |   4 +-
 drivers/vfio/platform/vfio_platform_common.c       | 107 +++++++++++++++++----
 drivers/vfio/platform/vfio_platform_private.h      |  43 +++++----
 4 files changed, 120 insertions(+), 38 deletions(-)
drivers/vfio/platform/reset/vfio_platform_amdxgbe.c +3 -1
index d4030d0..6d87442 100644
@@ -119,7 +119,9 @@ int vfio_platform_amdxgbe_reset(struct vfio_platform_device *vdev)
 	return 0;
 }
 
-module_vfio_reset_handler("amd,xgbe-seattle-v1a", vfio_platform_amdxgbe_reset);
+module_vfio_reset_handler("amd,xgbe-seattle-v1a", NULL,
+			  vfio_platform_amdxgbe_reset);
+MODULE_ALIAS_VFIO_PLATFORM_RESET("amd,xgbe-seattle-v1a");
 
 MODULE_VERSION("0.1");
 MODULE_LICENSE("GPL v2");
drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c +3 -1
index e3d3d94..952dd55 100644
@@ -77,7 +77,9 @@ int vfio_platform_calxedaxgmac_reset(struct vfio_platform_device *vdev)
 	return 0;
 }
 
-module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_reset);
+module_vfio_reset_handler("calxeda,hb-xgmac", NULL,
+			  vfio_platform_calxedaxgmac_reset);
+MODULE_ALIAS_VFIO_PLATFORM_RESET("calxeda,hb-xgmac");
 
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_LICENSE("GPL v2");
drivers/vfio/platform/vfio_platform_common.c +89 -18

164 lines not on this page · raw message

drivers/vfio/platform/vfio_platform_private.h +25 -18

64 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#2 lore raw

Re: [PATCH V3 1/3] vfio, platform: add support for ACPI while detecting the reset driver

Quoted 6 lines · On Monday 28 March 2016 09:35:22 Sinan Kaya wrote:

The code is using the compatible DT string to associate a reset driver with the actual device itself. The compatible string does not exist on ACPI based systems. HID is the unique identifier for a device driver instead. The change allows a driver to register with DT compatible string or ACPI HID and then match the object with one of these conditions.

Quoted 8 lines

Rules for loading the reset driver are as follow:
- ACPI HID needs match for ACPI systems
- DT compat needs to match for OF systems

This really feels wrong for two reasons:

* device assignment of non-PCI devices is really special and doesn't seem to make sense on general purpose servers that would be the target for ACPI normally

* If there is indeed a requirement for ACPI to handle something like this, it should be part of the ACPI spec, with a well-defined method of handling reset, rather than having to add a device specific hack for each device separately.

Arnd

#3 lore raw

Re: [PATCH V3 1/3] vfio, platform: add support for ACPI while detecting the reset driver

Quoted 17 lines · Arnd Bergmann
Quoted 6 lines · On Monday 28 March 2016 09:35:22 Sinan Kaya wrote:

The code is using the compatible DT string to associate a reset driver with the actual device itself. The compatible string does not exist on ACPI based systems. HID is the unique identifier for a device driver instead. The change allows a driver to register with DT compatible string or ACPI HID and then match the object with one of these conditions.

Quoted 8 lines

Rules for loading the reset driver are as follow:
- ACPI HID needs match for ACPI systems
- DT compat needs to match for OF systems

Quoted 6 lines

This really feels wrong for two reasons:

* device assignment of non-PCI devices is really special and doesn't seem to make sense on general purpose servers that would be the
target
for ACPI normally

Why is it special? Acpi is not equal to pci. Platform devices are first class devices too. Especially, _cls was introduced for this reason.

Quoted 7 lines

* If there is indeed a requirement for ACPI to handle something like this, it should be part of the ACPI spec, with a well-defined method of
handling
reset, rather than having to add a device specific hack for each device separately.

I see. Normally, this is done by calling _rst method. AFAIK, Linux doesn’t support _rst. I can check its presence and call it if it is there.

Quoted 1 line

Arnd

#4 lore raw

Re: [PATCH V3 1/3] vfio, platform: add support for ACPI while detecting the reset driver

Quoted 23 lines · On Tuesday 29 March 2016 06:59:15 [email protected] wrote:
Quoted 22 lines · Arnd Bergmann
Quoted 9 lines · On Monday 28 March 2016 09:35:22 Sinan Kaya wrote:

The code is using the compatible DT string to associate a reset driver with
the actual device itself. The compatible string does not exist on ACPI based systems. HID is the unique identifier for a device driver instead.
The change allows a driver to register with DT compatible string or ACPI
HID and then match the object with one of these conditions.

Quoted 8 lines

Rules for loading the reset driver are as follow:
- ACPI HID needs match for ACPI systems
- DT compat needs to match for OF systems

This really feels wrong for two reasons:

Quoted 8 lines
Quoted 4 lines

* device assignment of non-PCI devices is really special and doesn't seem to make sense on general purpose servers that would be the
target
for ACPI normally

Why is it special? Acpi is not equal to pci. Platform devices are first class devices too. Especially, _cls was introduced for this reason.

It still feels like a hack. The normal design for a server is to have all internal devices show up on the PCI host bridge, next to the PCIe ports, to have a simple way to manage any device, both internal and off-chip. Putting a device on random MMIO registers outside of the discoverable buses and have the firmware work around the lack of discoverability will always be inferior.

Quoted 9 lines
Quoted 8 lines

* If there is indeed a requirement for ACPI to handle something like this,
it should be part of the ACPI spec, with a well-defined method of
handling
reset, rather than having to add a device specific hack for each device separately.

Quoted 3 lines

I see. Normally, this is done by calling _rst method. AFAIK, Linux doesn’t support _rst. I can check its presence and call it if it is there.

Yes, that sounds reasonable: In patch 2 where you check for the presence of the reset method, just keep the existing logic for DT based systems, and use _rst on ACPI based systems instead, then you can drop both patches 1 and 3.

Arnd

#5 lore raw

Re: [PATCH V3 1/3] vfio, platform: add support for ACPI while detecting the reset driver

Quoted 33 lines · Arnd Bergmann
Quoted 23 lines · On Tuesday 29 March 2016 06:59:15 [email protected]…
Quoted 22 lines · Arnd Bergmann
Quoted 9 lines · On Monday 28 March 2016 09:35:22 Sinan Kaya wrote:

The code is using the compatible DT string to associate a reset driver with
the actual device itself. The compatible string does not exist on ACPI based systems. HID is the unique identifier for a device driver instead.
The change allows a driver to register with DT compatible string or ACPI
HID and then match the object with one of these conditions.

Quoted 8 lines

Rules for loading the reset driver are as follow:
- ACPI HID needs match for ACPI systems
- DT compat needs to match for OF systems

This really feels wrong for two reasons:

Quoted 8 lines
Quoted 4 lines

* device assignment of non-PCI devices is really special and doesn't seem to make sense on general purpose servers that would be the
target
for ACPI normally

Why is it special? Acpi is not equal to pci. Platform devices are first class devices too. Especially, _cls was introduced for this reason.

Quoted 7 lines

It still feels like a hack. The normal design for a server is to have all internal devices show up on the PCI host bridge, next to the PCIe ports, to have a simple way to manage any device, both internal and off-chip. Putting a device on random MMIO registers outside of the discoverable buses and have the firmware work around the lack of discoverability will always be inferior.

It is a HW implementation choice. Having everything as pci problem has been already solved. I would vote for it when we had SW pci bridge layer just to use usb and sata. Not anymore. Especially, _cls solves this problem

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

* If there is indeed a requirement for ACPI to handle something like this,
it should be part of the ACPI spec, with a well-defined method of
handling
reset, rather than having to add a device specific hack for each device separately.

Quoted 9 lines
Quoted 3 lines

I see. Normally, this is done by calling _rst method. AFAIK, Linux doesn’t support _rst. I can check its presence and call it if it is there.

Yes, that sounds reasonable: In patch 2 where you check for the presence of the reset method, just keep the existing logic for DT based systems, and use _rst on ACPI based systems instead, then you can drop both patches 1 and 3.

I can certainly drop patch #3 and push the reset responsibility to acpi.

I never liked having a fragmented sw design across multiple drivers.

I need something for patch #1. Compatible is a DT property not ACPI.but then, I won't have a reset driver anymore.

If we think about how vfio pci works, we pass the pci vendor and device id to new_id file to find out which pci device needs to be pass thru.

I can go to a similar route. This time we pass the object id through new_id and I call reset method on this object.

Let me know what you think?

Quoted 1 line

Arnd

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

#6 lore raw

Re: [PATCH V3 1/3] vfio, platform: add support for ACPI while detecting the reset driver

Quoted 26 lines · On Tuesday 29 March 2016 08:15:42 [email protected] wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

* If there is indeed a requirement for ACPI to handle something like this,
it should be part of the ACPI spec, with a well-defined method of
handling
reset, rather than having to add a device specific hack for each device separately.

Quoted 9 lines
Quoted 3 lines

I see. Normally, this is done by calling _rst method. AFAIK, Linux doesn’t support _rst. I can check its presence and call it if it is there.

Yes, that sounds reasonable: In patch 2 where you check for the presence of the reset method, just keep the existing logic for DT based systems, and use _rst on ACPI based systems instead, then you can drop both patches 1 and 3.

I can certainly drop patch #3 and push the reset responsibility to acpi.

I never liked having a fragmented sw design across multiple drivers.

I need something for patch #1. Compatible is a DT property not ACPI.but then, I won't have a reset driver anymore.

Quoted 7 lines

If we think about how vfio pci works, we pass the pci vendor and device id to new_id file to find out which pci device needs to be pass thru.

I can go to a similar route. This time we pass the object id through new_id and I call reset method on this object.

Let me know what you think?

It would certainly be nice to make it work more like PCI VFIO does here, where you can assign any device as long as it has an IOMMU (and a _rst method in this case).

Arnd

author
#7 lore raw

Re: [PATCH V3 1/3] vfio, platform: add support for ACPI while detecting the reset driver

Quoted 13 lines · Arnd Bergmann
Quoted 13 lines

can certainly drop patch #3 and push the reset responsibility to acpi.

Quoted 12 lines

I never liked having a fragmented sw design across multiple drivers.

I need something for patch #1. Compatible is a DT property not ACPI.but then, I won't have a reset driver anymore.

If we think about how vfio pci works, we pass the pci vendor and device id to new_id file to find out which pci device needs to be pass thru.

I can go to a similar route. This time we pass the object id through new_id and I call reset method on this object.

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Let me know what you think?

It would certainly be nice to make it work more like PCI VFIO does here, where you can assign any device as long as it has an IOMMU (and a _rst method in this case).

Arnd

I looked at the code today. This doesn't have to be as convoluted as PCI is. The VFIO platform driver already has a pointer to the actual object in vdev->pdev.dev.

This is really as simple as calling _RST method on the passed oject at the last step below. We don't need to create a dynamic list like PCI does.

This is how the driver gets called.

echo vfio-platform | tee -a /sys/bus/platform/devices/QCOM8061:00/driver_override echo QCOM8061:00 | tee -a /sys/bus/platform/devices/QCOM8061:00/driver/unbind echo QCOM8061:00 |tee -a /sys/bus/platform/drivers_probe

I'll post a patch as soon as I test it.

Signature · 3 lines
Sinan Kaya
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
author
#8 lore raw

PATCH v3 2/3 vfio, platform: make reset driver a requirement by default

In reply to Sinan Kaya

The code was allowing platform devices to be used without a supporting VFIO reset driver. The hardware can be left in some inconsistent state after a guest machine abort.

The reset driver will put the hardware back to safe state and disable interrupts before returning the control back to the host machine.

---
 drivers/vfio/platform/vfio_amba.c             | 5 +++++
 drivers/vfio/platform/vfio_platform.c         | 5 +++++
 drivers/vfio/platform/vfio_platform_common.c  | 8 +++++++-
 drivers/vfio/platform/vfio_platform_private.h | 1 +
 4 files changed, 18 insertions(+), 1 deletion(-)
drivers/vfio/platform/vfio_amba.c +5 -0
index a66479b..7585902 100644
@@ -23,6 +23,10 @@
 #define DRIVER_AUTHOR   "Antonios Motakis <[email protected]>"
 #define DRIVER_DESC     "VFIO for AMBA devices - User Level meta-driver"
 
+static bool reset_required = true;
+module_param(reset_required, bool, 0644);
+MODULE_PARM_DESC(reset_required, "override reset requirement (default: 1)");
+
 /* probing devices from the AMBA bus */
 
 static struct resource *get_amba_resource(struct vfio_platform_device *vdev,
@@ -68,6 +72,7 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id)
 	vdev->get_resource = get_amba_resource;
 	vdev->get_irq = get_amba_irq;
 	vdev->parent_module = THIS_MODULE;
+	vdev->reset_required = reset_required;
 
 	ret = vfio_platform_probe_common(vdev, &adev->dev);
 	if (ret) {
drivers/vfio/platform/vfio_platform.c +5 -0
index b1cc3a7..ef89146 100644
@@ -23,6 +23,10 @@
 #define DRIVER_AUTHOR   "Antonios Motakis <[email protected]>"
 #define DRIVER_DESC     "VFIO for platform devices - User Level meta-driver"
 
+static bool reset_required = true;
+module_param(reset_required, bool, 0644);
+MODULE_PARM_DESC(reset_required, "override reset requirement (default: 1)");
+
 /* probing devices from the linux platform bus */
 
 static struct resource *get_platform_resource(struct vfio_platform_device *vdev,
@@ -66,6 +70,7 @@ static int vfio_platform_probe(struct platform_device *pdev)
 	vdev->get_resource = get_platform_resource;
 	vdev->get_irq = get_platform_irq;
 	vdev->parent_module = THIS_MODULE;
+	vdev->reset_required = reset_required;
 
 	ret = vfio_platform_probe_common(vdev, &pdev->dev);
 	if (ret)
drivers/vfio/platform/vfio_platform_common.c +7 -1
index c28883a..67a3163 100644
@@ -637,7 +637,13 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev,
 		return ret;
 	}
 
-	vfio_platform_get_reset(vdev);
+	ret = vfio_platform_get_reset(vdev);
+	if (ret && vdev->reset_required) {
+		pr_err("vfio: no reset function found for device %s\n",
+		       vdev->name);
+		iommu_group_put(group);
+		return ret;
+	}
 	mutex_init(&vdev->igate);
 
 	return 0;
drivers/vfio/platform/vfio_platform_private.h +1 -0
index 1b95adf..b5a699a 100644
@@ -50,6 +50,7 @@ struct vfio_platform_region {
 };
 
 struct vfio_platform_device {
+	bool				reset_required;
 	struct vfio_platform_region	*regions;
 	u32				num_regions;
 	struct vfio_platform_irq	*irqs;
Signature · 1 line
1.8.2.1
author
#9 lore raw

PATCH v3 3/3 vfio, platform: add QTI HIDMA reset driver

In reply to Sinan Kaya

In situations where the userspace driver is stopped abnormally and the VFIO platform device is released, the assigned HW device currently is left running. As a consequence the HW device might continue issuing IRQs and performing DMA accesses.

This patch is implementing a reset driver for HIDMA platform driver. This gets called by the VFIO platform reset interface.

---
 drivers/vfio/platform/reset/Kconfig                |   9 ++
 drivers/vfio/platform/reset/Makefile               |   2 +
 .../vfio/platform/reset/vfio_platform_qcomhidma.c  | 101 +++++++++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100644 drivers/vfio/platform/reset/vfio_platform_qcomhidma.c
drivers/vfio/platform/reset/Kconfig +9 -0
index 70cccc5..d02b3b5 100644
@@ -13,3 +13,12 @@ config VFIO_PLATFORM_AMDXGBE_RESET
 	  Enables the VFIO platform driver to handle reset for AMD XGBE
 
 	  If you don't know what to do here, say N.
+
+config VFIO_PLATFORM_QCOMHIDMA_RESET
+	tristate "VFIO support for Qualcomm Technologies HIDMA reset"
+	depends on VFIO_PLATFORM
+	help
+	  Enables the VFIO platform driver to handle reset for Qualcomm Technologies
+	  HIDMA Channel.
+
+	  If you don't know what to do here, say N.
drivers/vfio/platform/reset/Makefile +2 -0
index 93f4e23..ec7748a 100644
@@ -1,7 +1,9 @@
 vfio-platform-calxedaxgmac-y := vfio_platform_calxedaxgmac.o
 vfio-platform-amdxgbe-y := vfio_platform_amdxgbe.o
+vfio-platform-qcomhidma-y := vfio_platform_qcomhidma.o
 
 ccflags-y += -Idrivers/vfio/platform
 
 obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) += vfio-platform-calxedaxgmac.o
+obj-$(CONFIG_VFIO_PLATFORM_QCOMHIDMA_RESET) += vfio-platform-qcomhidma.o
 obj-$(CONFIG_VFIO_PLATFORM_AMDXGBE_RESET) += vfio-platform-amdxgbe.o
drivers/vfio/platform/reset/vfio_platform_qcomhidma.c new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
1.8.2.1