mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c
@ 2025-09-25 10:40 Yaxing Guo
  2025-09-25 10:40 ` [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes Yaxing Guo
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Yaxing Guo @ 2025-09-25 10:40 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, wangran, zhangjian, anxu, guoyaxing

This patch introduces a new UIO driver, uio_pci_generic_sva, which
extends the functionality of uio_pci_generic by adding support for
Shared Virtual Addressing (SVA) when IOMMU is enabled in the system.

The key enhancement allows PCI devices to directly use user-space virtual
addresses for DMA operations, eliminating the need for bounce buffers or
explicit IOVA mapping. This is achieved by leveraging the kernel's IOMMU-SVA
subsystem, including process address space attachment, page fault handling,
and shared context management between CPU and device.

With this driver, userspace applications can perform zero-copy DMA using
native pointers:

    void *addr = malloc(N);
    set_dma_addr((uint64_t)addr);  // Pass user VA directly
    start_dma();

The device can now access 'addr' through the IOMMU's PASID-based translation,
provided that the underlying IOMMU hardware (e.g., Intel VT-d 3.1+, AMD-Vi,
ARM SMMU, RISCV IOMMU) and platform support SVA.

Dependencies:
- CONFIG_IOMMU_SVA must be enabled.
- The platform must support PRI (Page Request Interface) and PASID.
- Device drivers/userspace must handle page faults if demand-paging is used.

The implementation reuses core logic from uio_pci_generic.c while adding
PASID setting, and integration with the IOMMU SVA APIs.

Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
---
Changes in v2:
  -- Use sysfs_emit() instead of sprintf in pasid_show()
  -- Use the default attribute list instead of sysfs_create_file
  -- Add MODULE_DESCRIPTION
  -- Modify "2024" to "2025" in copyright

 drivers/uio/uio_pci_generic_sva.c | 192 ++++++++++++++++++++++++++++++
 1 file changed, 192 insertions(+)
 create mode 100644 drivers/uio/uio_pci_generic_sva.c

diff --git a/drivers/uio/uio_pci_generic_sva.c b/drivers/uio/uio_pci_generic_sva.c
new file mode 100644
index 000000000000..97e9ab9a081a
--- /dev/null
+++ b/drivers/uio/uio_pci_generic_sva.c
@@ -0,0 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * UIO PCI Express sva driver
+ *
+ * Copyright (c) 2025 Beijing Institute of Open Source Chip (BOSC)
+ */
+
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/uio_driver.h>
+#include <linux/iommu.h>
+
+struct uio_pci_sva_dev {
+	struct pci_dev *pdev;
+	struct uio_info info;
+	struct iommu_sva *sva_handle;
+	int pasid;
+};
+
+static irqreturn_t irq_handler(int irq, struct uio_info *dev_info)
+{
+	return IRQ_HANDLED;
+}
+
+static int uio_pci_sva_open(struct uio_info *info, struct inode *inode)
+{
+	struct iommu_sva *handle;
+	struct uio_pci_sva_dev *udev = info->priv;
+	struct iommu_domain *domain;
+
+	if (!udev && !udev->pdev)
+		return -ENODEV;
+
+	domain = iommu_get_domain_for_dev(&udev->pdev->dev);
+	if (domain)
+		iommu_detach_device(domain, &udev->pdev->dev);
+
+	handle = iommu_sva_bind_device(&udev->pdev->dev, current->mm);
+	if (IS_ERR(handle))
+		return -EINVAL;
+
+	udev->pasid = iommu_sva_get_pasid(handle);
+
+	udev->sva_handle = handle;
+
+	return 0;
+}
+
+static int uio_pci_sva_release(struct uio_info *info, struct inode *inode)
+{
+	struct uio_pci_sva_dev *udev = info->priv;
+
+	if (!udev && !udev->pdev)
+		return -ENODEV;
+
+	iommu_sva_unbind_device(udev->sva_handle);
+
+	return 0;
+}
+
+static int probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct uio_pci_sva_dev *udev;
+	int ret, i, irq = 0;
+
+	ret = pci_enable_device(pdev);
+	if (ret) {
+		dev_err(&pdev->dev, "pci_enable_device failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+	if (ret)
+		goto out_disable;
+
+	pci_set_master(pdev);
+
+	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSIX | PCI_IRQ_MSI);
+	if (ret > 0) {
+		irq = pci_irq_vector(pdev, 0);
+		if (irq < 0) {
+			dev_err(&pdev->dev, "Failed to get MSI vector\n");
+			ret = irq;
+			goto out_disable;
+		}
+	} else
+		dev_warn(&pdev->dev,
+			 "No IRQ vectors available (%d), using polling\n", ret);
+
+	udev = devm_kzalloc(&pdev->dev, sizeof(struct uio_pci_sva_dev),
+			    GFP_KERNEL);
+	if (!udev) {
+		ret =  -ENOMEM;
+		goto out_disable;
+	}
+
+	udev->pdev = pdev;
+	udev->info.name = "uio_pci_sva";
+	udev->info.version = "0.0.1";
+	udev->info.open = uio_pci_sva_open;
+	udev->info.release = uio_pci_sva_release;
+	udev->info.irq = irq;
+	udev->info.handler = irq_handler;
+	udev->info.priv = udev;
+
+	for (i = 0; i < MAX_UIO_MAPS; i++) {
+		struct resource *r = &pdev->resource[i];
+		struct uio_mem *uiomem = &udev->info.mem[i];
+
+		if (r->flags != (IORESOURCE_SIZEALIGN | IORESOURCE_MEM))
+			continue;
+
+		if (uiomem >= &udev->info.mem[MAX_UIO_MAPS]) {
+			dev_warn(&pdev->dev, "Do not support more than %d iomem\n",
+				 MAX_UIO_MAPS);
+			break;
+		}
+
+		uiomem->memtype = UIO_MEM_PHYS;
+		uiomem->addr = r->start & PAGE_MASK;
+		uiomem->offs = r->start & ~PAGE_MASK;
+		uiomem->size =
+			(uiomem->offs + resource_size(r) + PAGE_SIZE - 1) &
+			PAGE_MASK;
+		uiomem->name = r->name;
+	}
+
+	ret = devm_uio_register_device(&pdev->dev, &udev->info);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to register uio device\n");
+		goto out_free;
+	}
+
+	pci_set_drvdata(pdev, udev);
+
+	return 0;
+
+out_free:
+	kfree(udev);
+out_disable:
+	pci_disable_device(pdev);
+
+	return ret;
+}
+
+static void remove(struct pci_dev *pdev)
+{
+	struct uio_pci_sva_dev *udev = pci_get_drvdata(pdev);
+
+	pci_release_regions(pdev);
+	pci_disable_device(pdev);
+	kfree(udev);
+}
+
+static ssize_t pasid_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct uio_pci_sva_dev *udev = pci_get_drvdata(pdev);
+
+	return sysfs_emit(buf, "%d\n", udev->pasid);
+}
+static DEVICE_ATTR_RO(pasid);
+
+static struct attribute *uio_pci_sva_attrs[] = {
+	&dev_attr_pasid.attr,
+	NULL
+};
+
+static const struct attribute_group uio_pci_sva_attr_group = {
+	.attrs = uio_pci_sva_attrs,
+};
+
+static const struct attribute_group *uio_pci_sva_attr_groups[] = {
+	&uio_pci_sva_attr_group,
+	NULL
+};
+
+static struct pci_driver uio_pci_generic_sva_driver = {
+	.name = "uio_pci_sva",
+	.dev_groups = uio_pci_sva_attr_groups,
+	.id_table = NULL,
+	.probe = probe,
+	.remove = remove,
+};
+
+module_pci_driver(uio_pci_generic_sva_driver);
+MODULE_VERSION("0.0.01");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Yaxing Guo <guoyaxing@bosc.ac.cn>");
+MODULE_DESCRIPTION("Generic UIO sva driver for PCI");
-- 
2.34.1


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

* [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes
  2025-09-25 10:40 [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c Yaxing Guo
@ 2025-09-25 10:40 ` Yaxing Guo
  2025-09-25 12:32   ` Greg KH
  2025-09-25 12:29 ` [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c Greg KH
       [not found] ` <20250925104018.57053-2-guoyaxing@bosc.ac.cn>
  2 siblings, 1 reply; 8+ messages in thread
From: Yaxing Guo @ 2025-09-25 10:40 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, wangran, zhangjian, anxu, guoyaxing

Add ABI documentation for the sysfs interface provided by the
uio_pci_sva driver, specifically the 'pasid' attribute.

The 'pasid' attribute exposes the Process Address Space ID (PASID)
assigned by the IOMMU to the device for use with Shared Virtual
Addressing (SVA). User-space UIO applications read this attribute
to obtain the PASID and program it into the device's configuration
registers, enabling the device to perform DMA using user-space
virtual addresses.

This attribute appears under:
/sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid

Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
---
 .../ABI/testing/sysfs-driver-uio_pci_sva-pasid    | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid

diff --git a/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
new file mode 100644
index 000000000000..a6afa8c2775c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
@@ -0,0 +1,15 @@
+What:		/sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
+Date:		September 2025
+Contact:	Yaxing Guo <guoyaxing@bosc.ac.cn>
+Description:
+		Process Address Space ID (PASID) assigned by IOMMU driver to
+		the device for use witch Shared Virtual Addressing (SVA).
+
+		This read-only attribute exposes the PASID allocated by the
+		IOMMU driver during sva device binding.
+
+		User-space UIO applications must read this attribute to
+		obtain the PASID and program it into the device's configuration
+		registers. This enables the device to perform DMA using
+		user-space virtual address, with address translation handled
+		by IOMMU.
-- 
2.34.1


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

* Re: [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c
  2025-09-25 10:40 [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c Yaxing Guo
  2025-09-25 10:40 ` [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes Yaxing Guo
@ 2025-09-25 12:29 ` Greg KH
       [not found] ` <20250925104018.57053-2-guoyaxing@bosc.ac.cn>
  2 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2025-09-25 12:29 UTC (permalink / raw)
  To: Yaxing Guo; +Cc: linux-kernel, wangran, zhangjian, anxu

On Thu, Sep 25, 2025 at 06:40:16PM +0800, Yaxing Guo wrote:
> This patch introduces a new UIO driver, uio_pci_generic_sva, which
> extends the functionality of uio_pci_generic by adding support for
> Shared Virtual Addressing (SVA) when IOMMU is enabled in the system.
> 
> The key enhancement allows PCI devices to directly use user-space virtual
> addresses for DMA operations, eliminating the need for bounce buffers or
> explicit IOVA mapping. This is achieved by leveraging the kernel's IOMMU-SVA
> subsystem, including process address space attachment, page fault handling,
> and shared context management between CPU and device.
> 
> With this driver, userspace applications can perform zero-copy DMA using
> native pointers:
> 
>     void *addr = malloc(N);
>     set_dma_addr((uint64_t)addr);  // Pass user VA directly
>     start_dma();
> 
> The device can now access 'addr' through the IOMMU's PASID-based translation,
> provided that the underlying IOMMU hardware (e.g., Intel VT-d 3.1+, AMD-Vi,
> ARM SMMU, RISCV IOMMU) and platform support SVA.
> 
> Dependencies:
> - CONFIG_IOMMU_SVA must be enabled.
> - The platform must support PRI (Page Request Interface) and PASID.
> - Device drivers/userspace must handle page faults if demand-paging is used.
> 
> The implementation reuses core logic from uio_pci_generic.c while adding
> PASID setting, and integration with the IOMMU SVA APIs.
> 
> Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
> ---
> Changes in v2:
>   -- Use sysfs_emit() instead of sprintf in pasid_show()
>   -- Use the default attribute list instead of sysfs_create_file
>   -- Add MODULE_DESCRIPTION
>   -- Modify "2024" to "2025" in copyright
> 
>  drivers/uio/uio_pci_generic_sva.c | 192 ++++++++++++++++++++++++++++++
>  1 file changed, 192 insertions(+)
>  create mode 100644 drivers/uio/uio_pci_generic_sva.c
> 
> diff --git a/drivers/uio/uio_pci_generic_sva.c b/drivers/uio/uio_pci_generic_sva.c
> new file mode 100644
> index 000000000000..97e9ab9a081a
> --- /dev/null
> +++ b/drivers/uio/uio_pci_generic_sva.c
> @@ -0,0 +1,192 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * UIO PCI Express sva driver
> + *
> + * Copyright (c) 2025 Beijing Institute of Open Source Chip (BOSC)

Shouldn't that be 2024-2025 if work happened on this in 2024?


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

* Re: [PATCH v2 2/3] uio: Add Kconfig and Makefile support for UIO_PCI_GENERIC_SVA
       [not found] ` <20250925104018.57053-2-guoyaxing@bosc.ac.cn>
@ 2025-09-25 12:30   ` Greg KH
  2025-09-25 12:30   ` Greg KH
  1 sibling, 0 replies; 8+ messages in thread
From: Greg KH @ 2025-09-25 12:30 UTC (permalink / raw)
  To: Yaxing Guo; +Cc: linux-kernel, wangran, zhangjian, anxu

On Thu, Sep 25, 2025 at 06:40:17PM +0800, Yaxing Guo wrote:
> Add config symbol and build infrastructure for the UIO PCI generic
> driver with SVA (Shared Virtual Addressing) support.
> 
> This introduces:
> - A new tristate config option 'UIO_PCI_GENERIC_SVA' in Kconfig,
>   dependent on PCI and IOMMU_SVA.
> - Build rule in Makefile to compile uio_pci_generic_sva.o when enabled.
> 
> Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
> ---
> Changes in v2:
>   -- Add help info in Kconfig
> 
>  drivers/uio/Kconfig  | 12 ++++++++++++
>  drivers/uio/Makefile |  1 +
>  2 files changed, 13 insertions(+)

Again, this should be part of the first commit, why make it a
stand-alone one?

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

* Re: [PATCH v2 2/3] uio: Add Kconfig and Makefile support for UIO_PCI_GENERIC_SVA
       [not found] ` <20250925104018.57053-2-guoyaxing@bosc.ac.cn>
  2025-09-25 12:30   ` [PATCH v2 2/3] uio: Add Kconfig and Makefile support for UIO_PCI_GENERIC_SVA Greg KH
@ 2025-09-25 12:30   ` Greg KH
  1 sibling, 0 replies; 8+ messages in thread
From: Greg KH @ 2025-09-25 12:30 UTC (permalink / raw)
  To: Yaxing Guo; +Cc: linux-kernel, wangran, zhangjian, anxu

On Thu, Sep 25, 2025 at 06:40:17PM +0800, Yaxing Guo wrote:
> Add config symbol and build infrastructure for the UIO PCI generic
> driver with SVA (Shared Virtual Addressing) support.
> 
> This introduces:
> - A new tristate config option 'UIO_PCI_GENERIC_SVA' in Kconfig,
>   dependent on PCI and IOMMU_SVA.
> - Build rule in Makefile to compile uio_pci_generic_sva.o when enabled.
> 
> Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
> ---
> Changes in v2:
>   -- Add help info in Kconfig
> 
>  drivers/uio/Kconfig  | 12 ++++++++++++
>  drivers/uio/Makefile |  1 +
>  2 files changed, 13 insertions(+)
> 
> diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
> index b060dcd7c635..ae59e3d8a99b 100644
> --- a/drivers/uio/Kconfig
> +++ b/drivers/uio/Kconfig
> @@ -164,4 +164,16 @@ config UIO_DFL
>  	    opae-sdk/tools/libopaeuio/
>  
>  	  If you compile this as a module, it will be called uio_dfl.
> +
> +config UIO_PCI_GENERIC_SVA
> +	tristate "Generic driver for PCI Express that supports sva"
> +	depends on PCI && IOMMU_SVA
> +	help
> +	  Userspace I/O driver for PCI devices that support Shared Virtual
> +          Addressing (SVA), enabling direct use of user-space virtual
> +          addresses in device DMA operations via IOMMU hardware.
> +
> +          This driver binds to PCI devices and exposes them to userspace
> +          via the UIO framework.

What is the module name?

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

* Re: [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes
  2025-09-25 10:40 ` [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes Yaxing Guo
@ 2025-09-25 12:32   ` Greg KH
  2025-09-26  5:57     ` yaxing guo
  0 siblings, 1 reply; 8+ messages in thread
From: Greg KH @ 2025-09-25 12:32 UTC (permalink / raw)
  To: Yaxing Guo; +Cc: linux-kernel, wangran, zhangjian, anxu

On Thu, Sep 25, 2025 at 06:40:18PM +0800, Yaxing Guo wrote:
> Add ABI documentation for the sysfs interface provided by the
> uio_pci_sva driver, specifically the 'pasid' attribute.
> 
> The 'pasid' attribute exposes the Process Address Space ID (PASID)
> assigned by the IOMMU to the device for use with Shared Virtual
> Addressing (SVA). User-space UIO applications read this attribute
> to obtain the PASID and program it into the device's configuration
> registers, enabling the device to perform DMA using user-space
> virtual addresses.
> 
> This attribute appears under:
> /sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
> 
> Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
> ---
>  .../ABI/testing/sysfs-driver-uio_pci_sva-pasid    | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
> 
> diff --git a/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
> new file mode 100644
> index 000000000000..a6afa8c2775c
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
> @@ -0,0 +1,15 @@
> +What:		/sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
> +Date:		September 2025
> +Contact:	Yaxing Guo <guoyaxing@bosc.ac.cn>
> +Description:
> +		Process Address Space ID (PASID) assigned by IOMMU driver to
> +		the device for use witch Shared Virtual Addressing (SVA).

"with", not "witch", right?

> +
> +		This read-only attribute exposes the PASID allocated by the
> +		IOMMU driver during sva device binding.
> +
> +		User-space UIO applications must read this attribute to
> +		obtain the PASID and program it into the device's configuration
> +		registers. This enables the device to perform DMA using
> +		user-space virtual address, with address translation handled
> +		by IOMMU.

What is a PASID?  What format is it in?

How can it then be used in userspace?  What is a "device configuration
register" and what api uses it?

And where is the userspace code that interacts with all of this?

And finally, this too can be part of the first commit.

thanks,

greg k-h

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

* Re: [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes
  2025-09-25 12:32   ` Greg KH
@ 2025-09-26  5:57     ` yaxing guo
  2025-09-26  6:03       ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: yaxing guo @ 2025-09-26  5:57 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, wangran, zhangjian, anxu

Hi, Greg,

Thank you for your feedback.

On 9/25/2025 8:32 PM, Greg KH wrote:
> On Thu, Sep 25, 2025 at 06:40:18PM +0800, Yaxing Guo wrote:
>> Add ABI documentation for the sysfs interface provided by the
>> uio_pci_sva driver, specifically the 'pasid' attribute.
>>
>> The 'pasid' attribute exposes the Process Address Space ID (PASID)
>> assigned by the IOMMU to the device for use with Shared Virtual
>> Addressing (SVA). User-space UIO applications read this attribute
>> to obtain the PASID and program it into the device's configuration
>> registers, enabling the device to perform DMA using user-space
>> virtual addresses.
>>
>> This attribute appears under:
>> /sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
>>
>> Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
>> ---
>>   .../ABI/testing/sysfs-driver-uio_pci_sva-pasid    | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
>>   create mode 100644 Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
>>
>> diff --git a/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
>> new file mode 100644
>> index 000000000000..a6afa8c2775c
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
>> @@ -0,0 +1,15 @@
>> +What:		/sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
>> +Date:		September 2025
>> +Contact:	Yaxing Guo <guoyaxing@bosc.ac.cn>
>> +Description:
>> +		Process Address Space ID (PASID) assigned by IOMMU driver to
>> +		the device for use witch Shared Virtual Addressing (SVA).
> 
> "with", not "witch", right?
> 
>> +
>> +		This read-only attribute exposes the PASID allocated by the
>> +		IOMMU driver during sva device binding.
>> +
>> +		User-space UIO applications must read this attribute to
>> +		obtain the PASID and program it into the device's configuration
>> +		registers. This enables the device to perform DMA using
>> +		user-space virtual address, with address translation handled
>> +		by IOMMU.
> 
> What is a PASID?  What format is it in?
> 
> How can it then be used in userspace?  What is a "device configuration
> register" and what api uses it?
> 
> And where is the userspace code that interacts with all of this?
> 

The UIO userspace code is inherently tied to the hardware and its
register layout. Therefore, there isn't a single open-source userspace
implementation(In my job, this is for a simple FPAG-based test device 
used for iommu-sva functionality validation).

However, to help users understand how to use the interface, I can add a
**code example in this ABI documentation** that demonstrates:

- Reading the PASID from sysfs
- Mapping the device's register space via /dev/uioX
- Writing the PASID to a device-specific register (with example offset)

The code maybe like this:

map = mmap(..., "/dev/uio0", ...);

f = fopen("/sys/.../pasid", "r");
fscanf(f, "%d", &pasid);

map[REG_PASID_OFFSET] = pasid;

Would you prefer that I include such an example directly in the ABI doc, 
or is there another way you'd like this to be documented?

> And finally, this too can be part of the first commit.
> 
> thanks,
> 
> greg k-h

Best regards,
Yaxing Guo


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

* Re: [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes
  2025-09-26  5:57     ` yaxing guo
@ 2025-09-26  6:03       ` Greg KH
  0 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2025-09-26  6:03 UTC (permalink / raw)
  To: yaxing guo; +Cc: linux-kernel, wangran, zhangjian, anxu

On Fri, Sep 26, 2025 at 01:57:58PM +0800, yaxing guo wrote:
> Hi, Greg,
> 
> Thank you for your feedback.
> 
> On 9/25/2025 8:32 PM, Greg KH wrote:
> > On Thu, Sep 25, 2025 at 06:40:18PM +0800, Yaxing Guo wrote:
> > > Add ABI documentation for the sysfs interface provided by the
> > > uio_pci_sva driver, specifically the 'pasid' attribute.
> > > 
> > > The 'pasid' attribute exposes the Process Address Space ID (PASID)
> > > assigned by the IOMMU to the device for use with Shared Virtual
> > > Addressing (SVA). User-space UIO applications read this attribute
> > > to obtain the PASID and program it into the device's configuration
> > > registers, enabling the device to perform DMA using user-space
> > > virtual addresses.
> > > 
> > > This attribute appears under:
> > > /sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
> > > 
> > > Signed-off-by: Yaxing Guo <guoyaxing@bosc.ac.cn>
> > > ---
> > >   .../ABI/testing/sysfs-driver-uio_pci_sva-pasid    | 15 +++++++++++++++
> > >   1 file changed, 15 insertions(+)
> > >   create mode 100644 Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
> > > 
> > > diff --git a/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
> > > new file mode 100644
> > > index 000000000000..a6afa8c2775c
> > > --- /dev/null
> > > +++ b/Documentation/ABI/testing/sysfs-driver-uio_pci_sva-pasid
> > > @@ -0,0 +1,15 @@
> > > +What:		/sys/bus/pci/drivers/uio_pci_sva/<pci_dev>/pasid
> > > +Date:		September 2025
> > > +Contact:	Yaxing Guo <guoyaxing@bosc.ac.cn>
> > > +Description:
> > > +		Process Address Space ID (PASID) assigned by IOMMU driver to
> > > +		the device for use witch Shared Virtual Addressing (SVA).
> > 
> > "with", not "witch", right?
> > 
> > > +
> > > +		This read-only attribute exposes the PASID allocated by the
> > > +		IOMMU driver during sva device binding.
> > > +
> > > +		User-space UIO applications must read this attribute to
> > > +		obtain the PASID and program it into the device's configuration
> > > +		registers. This enables the device to perform DMA using
> > > +		user-space virtual address, with address translation handled
> > > +		by IOMMU.
> > 
> > What is a PASID?  What format is it in?
> > 
> > How can it then be used in userspace?  What is a "device configuration
> > register" and what api uses it?
> > 
> > And where is the userspace code that interacts with all of this?
> > 
> 
> The UIO userspace code is inherently tied to the hardware and its
> register layout. Therefore, there isn't a single open-source userspace
> implementation(In my job, this is for a simple FPAG-based test device used
> for iommu-sva functionality validation).

That's ok to publish it, userspace UIO drivers need to also be released
under an open license as they are explicitly tied to the kernel
interface.  Without that, it's hard to judge if the api is correct or
not.

thanks,

greg k-h

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

end of thread, other threads:[~2025-09-26  6:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-25 10:40 [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c Yaxing Guo
2025-09-25 10:40 ` [PATCH v2 3/3] doc: Add ABI documentation for uio_pci_sva driver sysfs attributes Yaxing Guo
2025-09-25 12:32   ` Greg KH
2025-09-26  5:57     ` yaxing guo
2025-09-26  6:03       ` Greg KH
2025-09-25 12:29 ` [PATCH v2 1/3] uio: Add SVA support for PCI devices via uio_pci_generic_sva.c Greg KH
     [not found] ` <20250925104018.57053-2-guoyaxing@bosc.ac.cn>
2025-09-25 12:30   ` [PATCH v2 2/3] uio: Add Kconfig and Makefile support for UIO_PCI_GENERIC_SVA Greg KH
2025-09-25 12:30   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®