Skip to contentSkip to conversation

add VFIO mdev support for DFL devices

PATCH In review Xu Yilun 3 participants 10 messages Sep 8, 2020 – Sep 11, 2020

Subsystems (4)
lore
Share & tools
lore

Xu Yilun

author maintainer
#0 lore raw

cover add VFIO mdev support for DFL devices

These patches depend on the patchset: "Modularization of DFL private feature drivers" & "add dfl bus support to MODULE_DEVICE_TABLE()"

https://lore.kernel.org/linux-fpga/[email protected]/

This patchset provides an VFIO Mdev driver for dfl devices. It makes possible for dfl devices be direct accessed from userspace.

Xu Yilun (3):
fpga: dfl: add driver_override support
fpga: dfl: VFIO mdev support for DFL devices
Documentation: fpga: dfl: Add description for VFIO Mdev support

 Documentation/ABI/testing/sysfs-bus-dfl |  20 ++
 Documentation/fpga/dfl.rst              |  20 ++
 drivers/fpga/Kconfig                    |   9 +
 drivers/fpga/Makefile                   |   1 +
 drivers/fpga/dfl.c                      |  54 ++++-
 drivers/fpga/vfio-mdev-dfl.c            | 391 ++++++++++++++++++++++++++++++++
 include/linux/fpga/dfl-bus.h            |   2 +
 7 files changed, 496 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/vfio-mdev-dfl.c
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 1/3 fpga: dfl: add driver_override support

Add support for overriding the default matching of a dfl device to a dfl driver. It follows the same way that can be used for PCI and platform devices. This patch adds the 'driver_override' sysfs file. It can be used by VFIO to bind dfl devices for user accessing.

---
 Documentation/ABI/testing/sysfs-bus-dfl | 20 ++++++++++++
 drivers/fpga/dfl.c                      | 54 ++++++++++++++++++++++++++++++++-
 include/linux/fpga/dfl-bus.h            |  2 ++
 3 files changed, 75 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-dfl +20 -0
index 23543be..cf1357a 100644
@@ -13,3 +13,23 @@ Contact:	Xu Yilun <[email protected]>
 Description:	Read-only. It returns feature identifier local to its DFL FIU
 		type.
 		Format: 0x%x
+
+What:		/sys/bus/dfl/devices/.../driver_override
+Date:		Sep 2020
+KernelVersion:	5.10
+Contact:	Xu Yilun <[email protected]>
+Description:	This file allows the driver for a device to be specified. When
+		specified, only a driver with a name matching the value written
+		to driver_override will have an opportunity to bind to the
+		device. The override is specified by writing a string to the
+		driver_override file (echo vfio-mdev-dfl > driver_override) and
+		may be cleared with an empty string (echo > driver_override).
+		This returns the device to standard matching rules binding.
+		Writing to driver_override does not automatically unbind the
+		device from its current driver or make any attempt to
+		automatically load the specified driver.  If no driver with a
+		matching name is currently loaded in the kernel, the device
+		will not bind to any driver.  This also allows devices to
+		opt-out of driver binding using a driver_override name such as
+		"none".  Only a single driver may be specified in the override,
+		there is no support for parsing delimiters.
drivers/fpga/dfl.c +53 -1

78 lines not on this page · raw message

include/linux/fpga/dfl-bus.h +2 -0
index 2a2b283..09a9ee1 100644
@@ -43,6 +43,8 @@ struct dfl_device {
 	unsigned int num_irqs;
 	struct dfl_fpga_cdev *cdev;
 	const struct dfl_device_id *id_entry;
+
+	char *driver_override;
 };
 
 /**
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH 2/3 fpga: dfl: VFIO mdev support for DFL devices

In reply to Xu Yilun

This patch is to provide VFIO support to DFL devices. When bound this driver to a dfl device, it registers a set of callbacks to the mediated device framework to enable mediated device creation. When a mediated device is created by user via mdev interfaces, it will be exposed to user as a VFIO platform device.

---
 drivers/fpga/Kconfig         |   9 +
 drivers/fpga/Makefile        |   1 +
 drivers/fpga/vfio-mdev-dfl.c | 391 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 401 insertions(+)
 create mode 100644 drivers/fpga/vfio-mdev-dfl.c
drivers/fpga/Kconfig +9 -0
index 38c7130..88f64fb 100644
@@ -202,6 +202,15 @@ config FPGA_DFL_NIOS_INTEL_PAC_N3000
 	  the card. It also instantiates the SPI master (spi-altera) for
 	  the card's BMC (Board Management Controller) control.
 
+config FPGA_VFIO_MDEV_DFL
+        tristate "VFIO Mdev support for DFL devices"
+        depends on FPGA_DFL && VFIO_MDEV
+        help
+	  Support for DFL devices with VFIO Mdev. This is required to make use
+	  of DFL devices present on the system using the VFIO Mdev framework.
+
+	  If you don't know what to do here, say N.
+
 config FPGA_DFL_PCI
 	tristate "FPGA DFL PCIe Device Driver"
 	depends on PCI && FPGA_DFL
drivers/fpga/Makefile +1 -0
index 18dc9885..c69bfc9 100644
@@ -45,6 +45,7 @@ dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o
 dfl-afu-objs += dfl-afu-error.o
 
 obj-$(CONFIG_FPGA_DFL_NIOS_INTEL_PAC_N3000)	+= dfl-n3000-nios.o
+obj-$(CONFIG_FPGA_VFIO_MDEV_DFL)	+= vfio-mdev-dfl.o
 
 # Drivers for FPGAs which implement DFL
 obj-$(CONFIG_FPGA_DFL_PCI)		+= dfl-pci.o
drivers/fpga/vfio-mdev-dfl.c new file +391 -0

391 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#3 lore raw

PATCH 3/3 Documentation: fpga: dfl: Add description for VFIO Mdev support

In reply to Xu Yilun

This patch adds description for VFIO Mdev support for dfl devices on dfl bus.

---
 Documentation/fpga/dfl.rst | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/fpga/dfl.rst +20 -0
index 0404fe6..f077754 100644
@@ -502,6 +502,26 @@ FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
 could be a reference.
 
 
+VFIO Mdev support for DFL devices
+=================================
+As we introduced a dfl bus for private features, they could be added to dfl bus
+as independent dfl devices. There is a requirement to handle these devices
+either by kernel drivers or by direct access from userspace. Usually we bind
+the kernel drivers to devices which provide board management functions, and
+gives user direct access to devices which cooperate closely with user
+controlled Accelerated Function Unit (AFU). We realize this with a VFIO Mdev
+implementation. When we bind the vfio-mdev-dfl driver to a dfl device, it
+realizes a group of callbacks and registers to the Mdev framework as a
+parent (physical) device. It could then create one (available_instances == 1)
+mdev device.
+Since dfl devices are sub devices of FPGA DFL physical devices (e.g. PCIE
+device), which provide no DMA isolation for each sub device, this may leads to
+DMA isolation problem if a private feature is designed to be capable of DMA.
+The AFU user could potentially access the whole device addressing space and
+impact the private feature. So now the general HW design rule is, no DMA
+capability for private features. It eliminates the DMA isolation problem.
+
+
 Open discussion
 ===============
 FME driver exports one ioctl (DFL_FPGA_FME_PORT_PR) for partial reconfiguration
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH 3/3] Documentation: fpga: dfl: Add description for VFIO Mdev support

Quoted 25 lines · On Tue, 8 Sep 2020 15:13:32 +0800 Xu Yilun <[email protected]> wrote:

This patch adds description for VFIO Mdev support for dfl devices on dfl bus.

---
 Documentation/fpga/dfl.rst | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/fpga/dfl.rst +8 -0
index 0404fe6..f077754 100644
@@ -502,6 +502,26 @@ FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
 could be a reference.
 
 
+VFIO Mdev support for DFL devices
+=================================
+As we introduced a dfl bus for private features, they could be added to dfl bus
+as independent dfl devices. There is a requirement to handle these devices
+either by kernel drivers or by direct access from userspace. Usually we bind
+the kernel drivers to devices which provide board management functions, and
+gives user direct access to devices which cooperate closely with user
+controlled Accelerated Function Unit (AFU). We realize this with a VFIO Mdev

Documentation/fpga/dfl.rst FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c) · line 522

Quoted 10 lines
Documentation/fpga/dfl.rst +10 -0
+implementation. When we bind the vfio-mdev-dfl driver to a dfl device, it
+realizes a group of callbacks and registers to the Mdev framework as a
+parent (physical) device. It could then create one (available_instances == 1)
+mdev device.
+Since dfl devices are sub devices of FPGA DFL physical devices (e.g. PCIE
+device), which provide no DMA isolation for each sub device, this may leads to
+DMA isolation problem if a private feature is designed to be capable of DMA.
+The AFU user could potentially access the whole device addressing space and
+impact the private feature. So now the general HW design rule is, no DMA
+capability for private features. It eliminates the DMA isolation problem.

What's the advantage of entangling mdev/vfio in this approach versus simply exposing the MMIO region of the device via sysfs (similar to a resource file in pci-sysfs)? This implementation doesn't support interrupts, it doesn't support multiplexing of a device, it doesn't perform any degree of mediation, it seems to simply say "please don't do DMA". I don't think that's acceptable for an mdev driver. If you want to play loose with isolation, do it somewhere else. Thanks,

Alex

author maintainer
#5 lore raw

Re: [PATCH 3/3] Documentation: fpga: dfl: Add description for VFIO Mdev support

Hi Alex:

Thanks for your quick response and is helpful to me. I did some more investigation and some comments inline.

Quoted 39 lines · Alex Williamson
Quoted 25 lines · On Tue, 8 Sep 2020 15:13:32 +0800 Xu Yilun <[email protected]> wrote:

This patch adds description for VFIO Mdev support for dfl devices on dfl bus.

---
 Documentation/fpga/dfl.rst | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/fpga/dfl.rst +8 -0
index 0404fe6..f077754 100644
@@ -502,6 +502,26 @@ FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
 could be a reference.
 
 
+VFIO Mdev support for DFL devices
+=================================
+As we introduced a dfl bus for private features, they could be added to dfl bus
+as independent dfl devices. There is a requirement to handle these devices
+either by kernel drivers or by direct access from userspace. Usually we bind
+the kernel drivers to devices which provide board management functions, and
+gives user direct access to devices which cooperate closely with user
+controlled Accelerated Function Unit (AFU). We realize this with a VFIO Mdev

Documentation/fpga/dfl.rst FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c) · line 522

Quoted 10 lines
Documentation/fpga/dfl.rst +10 -0
+implementation. When we bind the vfio-mdev-dfl driver to a dfl device, it
+realizes a group of callbacks and registers to the Mdev framework as a
+parent (physical) device. It could then create one (available_instances == 1)
+mdev device.
+Since dfl devices are sub devices of FPGA DFL physical devices (e.g. PCIE
+device), which provide no DMA isolation for each sub device, this may leads to
+DMA isolation problem if a private feature is designed to be capable of DMA.
+The AFU user could potentially access the whole device addressing space and
+impact the private feature. So now the general HW design rule is, no DMA
+capability for private features. It eliminates the DMA isolation problem.
Quoted 7 lines

What's the advantage of entangling mdev/vfio in this approach versus simply exposing the MMIO region of the device via sysfs (similar to a resource file in pci-sysfs)? This implementation doesn't support interrupts, it doesn't support multiplexing of a device, it doesn't perform any degree of mediation, it seems to simply say "please don't do DMA". I don't think that's acceptable for an mdev driver. If you want to play loose with isolation, do it somewhere else. Thanks,

The intention of the patchset is to enable the userspace drivers for dfl devices. The dfl devices are actually different IP blocks integrated in FPGA to support different board functionalities. They are sub devices of the FPGA PCIe device. Their mmio blocks are in PCIE bar regions. And we want some of the dfl devices handled by the userspace drivers.

Some dfl devices are capable of interrupt. I didn't add interrupt code in this patch cause now the IRQ capable dfl devices are all handled by kernel drivers. But as a generic FPGA platform, IRQ handling for userspace drivers should be supported.

And I can see there are several ways to enable the userspace driver.

1. Some specific sysfs like pci do. But seems it is not the common way for userspace driver. It does't support interrupt. And potentially users operate on the same mmio region together with kernel driver at the same time.

2. VFIO driver with NOIOMMU enabled. I think it meets our needs. Do you think it is good we implement an VFIO driver for dfl devices?

3. VFIO mdev. I implemented it because it will not block us from lacking of valid iommu group. And since the driver didn't perform any mediation, I should give up.

4. UIO driver. It should work. I'm wondering if option 2 covers the functionalities of UIO and has more enhancement. So option 2 may be better?

Thanks again for your time, and I really appreciate you would give some guide on it.

Yilun.

Quoted 2 lines

Alex

#6 lore raw

Re: [PATCH 3/3] Documentation: fpga: dfl: Add description for VFIO Mdev support

Quoted 78 lines · On Thu, 10 Sep 2020 16:32:30 +0800 Xu Yilun <[email protected]> wrote:

Hi Alex:

Thanks for your quick response and is helpful to me. I did some more investigation and some comments inline.

Quoted 39 lines · Alex Williamson
Quoted 25 lines · On Tue, 8 Sep 2020 15:13:32 +0800 Xu Yilun <[email protected]> wrote:

This patch adds description for VFIO Mdev support for dfl devices on dfl bus.

---
 Documentation/fpga/dfl.rst | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/fpga/dfl.rst +8 -0
index 0404fe6..f077754 100644
@@ -502,6 +502,26 @@ FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
 could be a reference.
 
 
+VFIO Mdev support for DFL devices
+=================================
+As we introduced a dfl bus for private features, they could be added to dfl bus
+as independent dfl devices. There is a requirement to handle these devices
+either by kernel drivers or by direct access from userspace. Usually we bind
+the kernel drivers to devices which provide board management functions, and
+gives user direct access to devices which cooperate closely with user
+controlled Accelerated Function Unit (AFU). We realize this with a VFIO Mdev

Documentation/fpga/dfl.rst FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c) · line 522

Quoted 10 lines
Documentation/fpga/dfl.rst +10 -0
+implementation. When we bind the vfio-mdev-dfl driver to a dfl device, it
+realizes a group of callbacks and registers to the Mdev framework as a
+parent (physical) device. It could then create one (available_instances == 1)
+mdev device.
+Since dfl devices are sub devices of FPGA DFL physical devices (e.g. PCIE
+device), which provide no DMA isolation for each sub device, this may leads to
+DMA isolation problem if a private feature is designed to be capable of DMA.
+The AFU user could potentially access the whole device addressing space and
+impact the private feature. So now the general HW design rule is, no DMA
+capability for private features. It eliminates the DMA isolation problem.  
Quoted 7 lines

What's the advantage of entangling mdev/vfio in this approach versus simply exposing the MMIO region of the device via sysfs (similar to a resource file in pci-sysfs)? This implementation doesn't support interrupts, it doesn't support multiplexing of a device, it doesn't perform any degree of mediation, it seems to simply say "please don't do DMA". I don't think that's acceptable for an mdev driver. If you want to play loose with isolation, do it somewhere else. Thanks,

The intention of the patchset is to enable the userspace drivers for dfl devices. The dfl devices are actually different IP blocks integrated in FPGA to support different board functionalities. They are sub devices of the FPGA PCIe device. Their mmio blocks are in PCIE bar regions. And we want some of the dfl devices handled by the userspace drivers.

Some dfl devices are capable of interrupt. I didn't add interrupt code in this patch cause now the IRQ capable dfl devices are all handled by kernel drivers. But as a generic FPGA platform, IRQ handling for userspace drivers should be supported.

And I can see there are several ways to enable the userspace driver.

1. Some specific sysfs like pci do. But seems it is not the common way for userspace driver. It does't support interrupt. And potentially users operate on the same mmio region together with kernel driver at the same time.

2. VFIO driver with NOIOMMU enabled. I think it meets our needs. Do you think it is good we implement an VFIO driver for dfl devices?

3. VFIO mdev. I implemented it because it will not block us from lacking of valid iommu group. And since the driver didn't perform any mediation, I should give up.

Quoted 6 lines

4. UIO driver. It should work. I'm wondering if option 2 covers the functionalities of UIO and has more enhancement. So option 2 may be better?

Thanks again for your time, and I really appreciate you would give some guide on it.

VFIO no-iommu was intended as a transition helper for platforms that do not support an IOMMU, particularly running within a VM where we use regular, IOMMU protected devices within the host, but allow no-iommu within the guest such that the host is still protected from the guest sandbox. There should be no new use cases of no-iommu, it's unsafe, it taints the kernel where it's used (guest in the above intended use case). If you intend long term distribution support of a solution, VFIO no-iommu should not be considered an option.

VFIO mdev requires that the mdev vendor driver mediates access to the device in order to provide isolation. In the initial vGPU use cases, we expect that isolation to be provided via devices specific means, ex. GPU GART, but we've since included system level components like IOMMU backing devices and auxiliary domains, the latter to make use of IOMMU PASID support.

As implemented in this proposal, mdev is being used only to subvert the IOMMU grouping requirements of VFIO in order to order to expose a device that is potentially fully capable of DMA to userspace with no isolation whatsoever. If not for the IOMMU grouping, this driver could simply be a VFIO bus driver making use of the vfio-platform interface. Either way, without isolation, this does not belong in the realm of VFIO.

Given your architecture, the only potentially valid mdev use case I can see would be if the mdev vendor driver binds to the PCIe device, allowing multiplexing of the parent device by carving out fpga functional blocks from MMIO BAR space, and providing isolation by enforcing that the parent device never enables bus master, assuming that would prevent any of the fpga sub-components from performing DMA.

Are there worthwhile use cases of these fpga devices without DMA?

If you need DMA (or the device is potentially capable of DMA and cannot be audited to prevent it) and cannot provide isolation then please don't use VFIO or mdev, doing so would violate the notion of secure userspace device access that we've worked to achieve in this ecosystem.

If you choose another route, pci-sysfs already provides full BAR access via the resource files in sysfs, but you could also expose individual sysfs files with the same capabilities per fpga functional unit to resolve the conflict between kernel and userspace "ownership". UIO might also be a solution. This proposal to restrict userspace usage to devices that don't perform DMA is akin to uio_pci_generic, where the user is not expected to enable bus master, but nothing prevents them from doing so and as a result it's a gateway for all sorts of unsupportable drivers. mdev should not be used to follow that example. Thanks,

Alex

author maintainer
#7 lore raw

Re: [PATCH 3/3] Documentation: fpga: dfl: Add description for VFIO Mdev support

Quoted 113 lines · Alex Williamson
Quoted 78 lines · On Thu, 10 Sep 2020 16:32:30 +0800 Xu Yilun <[email protected]> wrote:

Hi Alex:

Thanks for your quick response and is helpful to me. I did some more investigation and some comments inline.

Quoted 39 lines · Alex Williamson
Quoted 25 lines · On Tue, 8 Sep 2020 15:13:32 +0800 Xu Yilun <[email protected]> wrote:

This patch adds description for VFIO Mdev support for dfl devices on dfl bus.

---
 Documentation/fpga/dfl.rst | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Documentation/fpga/dfl.rst +8 -0
index 0404fe6..f077754 100644
@@ -502,6 +502,26 @@ FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c)
 could be a reference.
 
 
+VFIO Mdev support for DFL devices
+=================================
+As we introduced a dfl bus for private features, they could be added to dfl bus
+as independent dfl devices. There is a requirement to handle these devices
+either by kernel drivers or by direct access from userspace. Usually we bind
+the kernel drivers to devices which provide board management functions, and
+gives user direct access to devices which cooperate closely with user
+controlled Accelerated Function Unit (AFU). We realize this with a VFIO Mdev

Documentation/fpga/dfl.rst FME Partial Reconfiguration Sub Feature driver (see drivers/fpga/dfl-fme-pr.c) · line 522

Quoted 10 lines
Documentation/fpga/dfl.rst +10 -0
+implementation. When we bind the vfio-mdev-dfl driver to a dfl device, it
+realizes a group of callbacks and registers to the Mdev framework as a
+parent (physical) device. It could then create one (available_instances == 1)
+mdev device.
+Since dfl devices are sub devices of FPGA DFL physical devices (e.g. PCIE
+device), which provide no DMA isolation for each sub device, this may leads to
+DMA isolation problem if a private feature is designed to be capable of DMA.
+The AFU user could potentially access the whole device addressing space and
+impact the private feature. So now the general HW design rule is, no DMA
+capability for private features. It eliminates the DMA isolation problem.  
Quoted 7 lines

What's the advantage of entangling mdev/vfio in this approach versus simply exposing the MMIO region of the device via sysfs (similar to a resource file in pci-sysfs)? This implementation doesn't support interrupts, it doesn't support multiplexing of a device, it doesn't perform any degree of mediation, it seems to simply say "please don't do DMA". I don't think that's acceptable for an mdev driver. If you want to play loose with isolation, do it somewhere else. Thanks,

The intention of the patchset is to enable the userspace drivers for dfl devices. The dfl devices are actually different IP blocks integrated in FPGA to support different board functionalities. They are sub devices of the FPGA PCIe device. Their mmio blocks are in PCIE bar regions. And we want some of the dfl devices handled by the userspace drivers.

Some dfl devices are capable of interrupt. I didn't add interrupt code in this patch cause now the IRQ capable dfl devices are all handled by kernel drivers. But as a generic FPGA platform, IRQ handling for userspace drivers should be supported.

And I can see there are several ways to enable the userspace driver.

1. Some specific sysfs like pci do. But seems it is not the common way for userspace driver. It does't support interrupt. And potentially users operate on the same mmio region together with kernel driver at the same time.

2. VFIO driver with NOIOMMU enabled. I think it meets our needs. Do you think it is good we implement an VFIO driver for dfl devices?

3. VFIO mdev. I implemented it because it will not block us from lacking of valid iommu group. And since the driver didn't perform any mediation, I should give up.

Quoted 6 lines

4. UIO driver. It should work. I'm wondering if option 2 covers the functionalities of UIO and has more enhancement. So option 2 may be better?

Thanks again for your time, and I really appreciate you would give some guide on it.

VFIO no-iommu was intended as a transition helper for platforms that do not support an IOMMU, particularly running within a VM where we use regular, IOMMU protected devices within the host, but allow no-iommu within the guest such that the host is still protected from the guest sandbox. There should be no new use cases of no-iommu, it's unsafe, it taints the kernel where it's used (guest in the above intended use case). If you intend long term distribution support of a solution, VFIO no-iommu should not be considered an option.

VFIO mdev requires that the mdev vendor driver mediates access to the device in order to provide isolation. In the initial vGPU use cases, we expect that isolation to be provided via devices specific means, ex. GPU GART, but we've since included system level components like IOMMU backing devices and auxiliary domains, the latter to make use of IOMMU PASID support.

As implemented in this proposal, mdev is being used only to subvert the IOMMU grouping requirements of VFIO in order to order to expose a device that is potentially fully capable of DMA to userspace with no isolation whatsoever. If not for the IOMMU grouping, this driver could simply be a VFIO bus driver making use of the vfio-platform interface. Either way, without isolation, this does not belong in the realm of VFIO.

Quoted 8 lines

Given your architecture, the only potentially valid mdev use case I can see would be if the mdev vendor driver binds to the PCIe device, allowing multiplexing of the parent device by carving out fpga functional blocks from MMIO BAR space, and providing isolation by enforcing that the parent device never enables bus master, assuming that would prevent any of the fpga sub-components from performing DMA.

Are there worthwhile use cases of these fpga devices without DMA?

The board (Intel PAC N3000) we want to support is a Smart NIC. The FPGA part is responsible for the various MAC layer offloading. The software for FPGA usually doesn't touch the network data stream (they are all handled by FPGA logic), it does some configurations and link status reading so no DMA is required. These configurations are sometimes very specific to dynamic RTL logic developed by user, so this is the purpose we handle them in userspace.

There are some other usercases, which use FPGA to do some dedicated algorithm like for deep learning. They need to perform memory in and memory out. For these cases, it seems possible we carving out the related part as the mdev, leaving management part in parent device driver.

Quoted 7 lines

If you need DMA (or the device is potentially capable of DMA and cannot be audited to prevent it) and cannot provide isolation then please don't use VFIO or mdev, doing so would violate the notion of secure userspace device access that we've worked to achieve in this ecosystem.

Quoted 7 lines

If you choose another route, pci-sysfs already provides full BAR access via the resource files in sysfs, but you could also expose individual sysfs files with the same capabilities per fpga functional unit to resolve the conflict between kernel and userspace "ownership". UIO might also be a solution. This proposal to restrict userspace usage to devices that don't perform DMA is akin to uio_pci_generic, where the user is not expected to enable bus master, but nothing prevents them

We are going to exposes these devices not capable of DMA, so seems UIO is the right way to go.

Quoted 2 lines

from doing so and as a result it's a gateway for all sorts of unsupportable drivers. mdev should not be used to follow that example.

I should thank you again for the detail explanation.

Yilun

Quoted 3 lines

Thanks,

Alex

reviewer
#8 lore raw
In reply to Xu Yilun

This is a new interface, the documentation needs to go

into greater detail. I am particularly interested in the user workflow.

This seems like it would work only for kernel modules.

Please describe both in the documentation.

A sample of a user mode driver would be helpful.

Is putting driver_override using sysfs for each device scalable ? would a list sets of {feature id,files}'s the vfio driver respond to better ?

To be consistent the mdev driver file name should be dfl-vfio-mdev.c

There should be an opt-in flag for drivers being overridden instead of blanket approval of all drivers.

Tom

Quoted 23 lines · Xu Yilun

These patches depend on the patchset: "Modularization of DFL private feature drivers" & "add dfl bus support to MODULE_DEVICE_TABLE()"

https://lore.kernel.org/linux-fpga/[email protected]/

This patchset provides an VFIO Mdev driver for dfl devices. It makes possible for dfl devices be direct accessed from userspace.

Xu Yilun (3):
fpga: dfl: add driver_override support
fpga: dfl: VFIO mdev support for DFL devices
Documentation: fpga: dfl: Add description for VFIO Mdev support

 Documentation/ABI/testing/sysfs-bus-dfl |  20 ++
 Documentation/fpga/dfl.rst              |  20 ++
 drivers/fpga/Kconfig                    |   9 +
 drivers/fpga/Makefile                   |   1 +
 drivers/fpga/dfl.c                      |  54 ++++-
 drivers/fpga/vfio-mdev-dfl.c            | 391 ++++++++++++++++++++++++++++++++
 include/linux/fpga/dfl-bus.h            |   2 +
 7 files changed, 496 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/vfio-mdev-dfl.c
author maintainer
#9 lore raw

Hi tom:

The generic workflow of mdev is described in Documentation/driver-api/vfio-mediated-device.rst, I could also share some code offline.

But now I got the comments from Alex that it may not suitable we implement the mdev for dfl devices. I think we need to first of all reconsider the design.

Thanks,
Yilun

Quoted 42 lines · Tom Rix

This is a new interface, the documentation needs to go

into greater detail. I am particularly interested in the user workflow.

This seems like it would work only for kernel modules.

Please describe both in the documentation.

A sample of a user mode driver would be helpful.

Is putting driver_override using sysfs for each device scalable ? would a list sets of {feature id,files}'s the vfio driver respond to better ?

To be consistent the mdev driver file name should be dfl-vfio-mdev.c

There should be an opt-in flag for drivers being overridden instead of blanket approval of all drivers.

Tom

Quoted 23 lines · Xu Yilun

These patches depend on the patchset: "Modularization of DFL private feature drivers" & "add dfl bus support to MODULE_DEVICE_TABLE()"

https://lore.kernel.org/linux-fpga/[email protected]/

This patchset provides an VFIO Mdev driver for dfl devices. It makes possible for dfl devices be direct accessed from userspace.

Xu Yilun (3):
fpga: dfl: add driver_override support
fpga: dfl: VFIO mdev support for DFL devices
Documentation: fpga: dfl: Add description for VFIO Mdev support

 Documentation/ABI/testing/sysfs-bus-dfl |  20 ++
 Documentation/fpga/dfl.rst              |  20 ++
 drivers/fpga/Kconfig                    |   9 +
 drivers/fpga/Makefile                   |   1 +
 drivers/fpga/dfl.c                      |  54 ++++-
 drivers/fpga/vfio-mdev-dfl.c            | 391 ++++++++++++++++++++++++++++++++
 include/linux/fpga/dfl-bus.h            |   2 +
 7 files changed, 496 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/vfio-mdev-dfl.c