[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen: add privcmd ioctl to get p2pdma_distance


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Julia Zhang <julia.zhang@xxxxxxx>
  • Date: Sat, 7 Dec 2024 18:59:46 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ijr4V8vm1YJGIO6GrqqHeyIQQ8oHc1GLvuA8nvRmTjY=; b=bjFUJH2jcoLL7qQB5r3Fu6w0KTG4UkOoVFLoURLRZ+PZY9bP0j5vj9tbzOaP/vhSM5ODzJHzfQCvkidFmi2oSCK6kG4mLQOILjfuN3qWIP5s/DLd47FHmkNJ6rbcddOTX01qYcAmU9pFKDxtv+6Tj4dSxIDG+hdldijtjIP5XLh1jR44vuoK6vmlU/er3OfNVXoiefFQg5lT3B5DGz0qNavsISwWlgAh035Nh/MjJW1qIngz58Q2bPwlyrZe0Gy+MWToUgc1/6UL/6qTZSqumqm2rU3k2l35aNj+zij3U28mY1YDS8VE4X4mvvndKbNgD+VG1+8rmlAjHMpRhZrNsg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Er3g1LeEd+tDUQkY1k7rKlLf4GN/8cRHuiX3o1svnMQT53x4+jZyfivH4HcFVJMmFMGmbVBVfDJ2H210sgY9OG7EDIfgg2myOQI+CVg78p7C1EDdaaxCSzDbB7ZvUQ3E4gnVadzk8/Svsg4EQJMAU3Gasa1UYJ+ey2injg4oHHHJStJysK5cPj7O7Z5pNQHeIS69ViGJ/mSvqERP9iZ3B3VSmfUZDDqG4dWwpMs5M5goqaWxfLhsTYOcH0BaaDjJEiCX8irv2q3QEU9eL0RfC6kbgJWHkjJihc+qtH8P4DJ+eiutYBtWikwN307gON0XAN21Xl4GVkb3gL5zvfcTvA==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Alex Deucher <alexander.deucher@xxxxxxx>, Christian König <christian.koenig@xxxxxxx>, Xenia Ragiadakou <burzalodowa@xxxxxxxxx>, "Julia Zhang" <julia.zhang@xxxxxxx>, Chen Jiqian <Jiqian.Chen@xxxxxxx>, Huang Rui <ray.huang@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Zhu Lingshan <Lingshan.Zhu@xxxxxxx>, Paul Durrant <paul@xxxxxxx>, "Edgar E . Iglesias" <edgar.iglesias@xxxxxxxxx>, "Michael S . Tsirkin" <mst@xxxxxxxxxx>, "Marcel Apfelbaum" <marcel.apfelbaum@xxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
  • Delivery-date: Sat, 07 Dec 2024 11:00:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

To implement dGPU prime feature, virtgpu driver need to get
p2pdma_distance of two GPU from host side.

This adds a new privcmd ioctl to get the real p2pdma_distance of two pci
devices in the host with pci notations sent from guest side.

Signed-off-by: Julia Zhang <julia.zhang@xxxxxxx>
---
 tools/include/xen-sys/Linux/privcmd.h | 12 ++++++++++++
 tools/include/xenctrl.h               | 17 +++++++++++++++++
 tools/libs/ctrl/xc_freebsd.c          | 11 +++++++++++
 tools/libs/ctrl/xc_linux.c            | 24 ++++++++++++++++++++++++
 tools/libs/ctrl/xc_minios.c           | 11 +++++++++++
 tools/libs/ctrl/xc_netbsd.c           | 11 +++++++++++
 tools/libs/ctrl/xc_physdev.c          | 12 ++++++++++++
 tools/libs/ctrl/xc_solaris.c          | 11 +++++++++++
 8 files changed, 109 insertions(+)

diff --git a/tools/include/xen-sys/Linux/privcmd.h 
b/tools/include/xen-sys/Linux/privcmd.h
index 5071ebcc8b..fbdc9aa927 100644
--- a/tools/include/xen-sys/Linux/privcmd.h
+++ b/tools/include/xen-sys/Linux/privcmd.h
@@ -110,6 +110,16 @@ typedef struct privcmd_map_hva_to_gpfns {
        int add_mapping;
 } privcmd_map_hva_to_gpfns_t;
 
+typedef struct privcmd_p2pdma_distance {
+       __u32 provider_bus;
+       __u32 provider_slot;
+       __u32 provider_func;
+       __u32 client_bus;
+       __u32 client_slot;
+       __u32 client_func;
+       __u32 distance;
+} privcmd_p2pdma_distance_t;
+
 /*
  * @cmd: IOCTL_PRIVCMD_HYPERCALL
  * @arg: &privcmd_hypercall_t
@@ -131,6 +141,8 @@ typedef struct privcmd_map_hva_to_gpfns {
        _IOC(_IOC_NONE, 'P', 7, sizeof(privcmd_mmap_resource_t))
 #define IOCTL_PRIVCMD_PCIDEV_GET_GSI                   \
        _IOC(_IOC_NONE, 'P', 10, sizeof(privcmd_pcidev_get_gsi_t))
+#define IOCTL_PRIVCMD_P2PDMA_DISTANCE                          \
+       _IOC(_IOC_NONE, 'P', 11, sizeof(privcmd_p2pdma_distance_t))
 #define IOCTL_PRIVCMD_MAP_HVA_TO_GPFNS                         \
        _IOC(_IOC_NONE, 'P', 13, sizeof(privcmd_map_hva_to_gpfns_t))
 #define IOCTL_PRIVCMD_UNIMPLEMENTED                            \
diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 29617585c5..42d15a22b8 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -1654,6 +1654,23 @@ int xc_physdev_unmap_pirq(xc_interface *xch,
 
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf);
 
+int xc_physdev_p2pdma_distance(xc_interface *xch,
+                               uint32_t bus,
+                               uint32_t slot,
+                               uint32_t func,
+                               uint32_t c_bus,
+                               uint32_t c_slot,
+                               uint32_t c_func);
+
+int xc_pcidev_p2pdma_distance(xc_interface *xch,
+                              uint32_t bus,
+                              uint32_t slot,
+                              uint32_t func,
+                              uint32_t c_bus,
+                              uint32_t c_slot,
+                              uint32_t c_func);
+
+
 /*
  *  LOGGING AND ERROR REPORTING
  */
diff --git a/tools/libs/ctrl/xc_freebsd.c b/tools/libs/ctrl/xc_freebsd.c
index 9019fc6633..4e0df06b7c 100644
--- a/tools/libs/ctrl/xc_freebsd.c
+++ b/tools/libs/ctrl/xc_freebsd.c
@@ -60,6 +60,17 @@ void *xc_memalign(xc_interface *xch, size_t alignment, 
size_t size)
     return ptr;
 }
 
+int xc_pcidev_p2pdma_distance(xc_interface *xch,
+                              uint32_t bus,
+                              uint32_t slot,
+                              uint32_t func,
+                              uint32_t c_bus,
+                              uint32_t c_slot,
+                              uint32_t c_func)
+{
+    return -1;
+}
+
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
 {
     errno = ENOSYS;
diff --git a/tools/libs/ctrl/xc_linux.c b/tools/libs/ctrl/xc_linux.c
index 92591e49a1..9aeff2328f 100644
--- a/tools/libs/ctrl/xc_linux.c
+++ b/tools/libs/ctrl/xc_linux.c
@@ -66,6 +66,30 @@ void *xc_memalign(xc_interface *xch, size_t alignment, 
size_t size)
     return ptr;
 }
 
+int xc_pcidev_p2pdma_distance(xc_interface *xch,
+                              uint32_t bus,
+                              uint32_t slot,
+                              uint32_t func,
+                              uint32_t c_bus,
+                              uint32_t c_slot,
+                              uint32_t c_func)
+{
+    privcmd_p2pdma_distance_t p2pdma_distance = {
+        .provider_bus = bus,
+        .provider_slot = slot,
+        .provider_func = func,
+        .client_bus = c_bus,
+        .client_slot = c_slot,
+        .client_func = c_func,
+        .distance = -1,
+    };
+    if (!ioctl(xencall_fd(xch->xcall), IOCTL_PRIVCMD_P2PDMA_DISTANCE, 
&p2pdma_distance)) {
+       return p2pdma_distance.distance;
+    }
+
+    return -1;
+}
+
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
 {
     int ret;
diff --git a/tools/libs/ctrl/xc_minios.c b/tools/libs/ctrl/xc_minios.c
index 462af827b3..4698cca5ea 100644
--- a/tools/libs/ctrl/xc_minios.c
+++ b/tools/libs/ctrl/xc_minios.c
@@ -47,6 +47,17 @@ void *xc_memalign(xc_interface *xch, size_t alignment, 
size_t size)
     return memalign(alignment, size);
 }
 
+int  xc_pcidev_p2pdma_distance(xc_interface *xch,
+                               uint32_t bus,
+                               uint32_t slot,
+                               uint32_t func,
+                               uint32_t c_bus,
+                               uint32_t c_slot,
+                               uint32_t c_func)
+{
+    return -1;
+}
+
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
 {
     errno = ENOSYS;
diff --git a/tools/libs/ctrl/xc_netbsd.c b/tools/libs/ctrl/xc_netbsd.c
index 1318d4d906..7e0ee8417e 100644
--- a/tools/libs/ctrl/xc_netbsd.c
+++ b/tools/libs/ctrl/xc_netbsd.c
@@ -63,6 +63,17 @@ void *xc_memalign(xc_interface *xch, size_t alignment, 
size_t size)
     return valloc(size);
 }
 
+int xc_pcidev_p2pdma_distance(xc_interface *xch,
+                              uint32_t bus,
+                              uint32_t slot,
+                              uint32_t func,
+                              uint32_t c_bus,
+                              uint32_t c_slot,
+                              uint32_t c_func)
+{
+    return -1;
+}
+
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
 {
     errno = ENOSYS;
diff --git a/tools/libs/ctrl/xc_physdev.c b/tools/libs/ctrl/xc_physdev.c
index 25e686d7b3..4ee8f39e09 100644
--- a/tools/libs/ctrl/xc_physdev.c
+++ b/tools/libs/ctrl/xc_physdev.c
@@ -138,3 +138,15 @@ int xc_physdev_unmap_pirq(xc_interface *xch,
     return rc;
 }
 
+int xc_physdev_p2pdma_distance(xc_interface *xch,
+                               uint32_t bus,
+                               uint32_t slot,
+                               uint32_t func,
+                               uint32_t c_bus,
+                               uint32_t c_slot,
+                               uint32_t c_func)
+{
+    return xc_pcidev_p2pdma_distance(xch, bus, slot, func,
+                                     c_bus, c_slot, c_func);
+}
+
diff --git a/tools/libs/ctrl/xc_solaris.c b/tools/libs/ctrl/xc_solaris.c
index 049e28d55c..a054b40b31 100644
--- a/tools/libs/ctrl/xc_solaris.c
+++ b/tools/libs/ctrl/xc_solaris.c
@@ -32,6 +32,17 @@ void *xc_memalign(xc_interface *xch, size_t alignment, 
size_t size)
     return memalign(alignment, size);
 }
 
+int xc_pcidev_p2pdma_distance(xc_interface *xch,
+                              uint32_t bus,
+                              uint32_t slot,
+                              uint32_t func,
+                              uint32_t c_bus,
+                              uint32_t c_slot,
+                              uint32_t c_func)
+{
+    return -1;
+}
+
 int xc_pcidev_get_gsi(xc_interface *xch, uint32_t sbdf)
 {
     errno = ENOSYS;
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.