From: Julia Zhang <julia.zhang@amd.com>
To: David Airlie <airlied@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Gurchetan Singh <gurchetansingh@chromium.org>,
Chia-I Wu <olvaffe@gmail.com>, <dri-devel@lists.freedesktop.org>,
<virtualization@lists.linux-foundation.org>,
Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
<xen-devel@lists.xenproject.org>
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Chen Jiqian" <Jiqian.Chen@amd.com>,
"Huang Rui" <ray.huang@amd.com>,
"Penny Zheng" <penny.zheng@amd.com>,
"Zhu Lingshan" <Lingshan.Zhu@amd.com>,
"Anthony PERARD" <anthony.perard@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Jan Beulich" <jbeulich@suse.com>, "Paul Durrant" <paul@xen.org>,
"Julia Zhang" <julia.zhang@amd.com>
Subject: [PATCH 1/3] xen:get p2pdma_distance
Date: Sat, 7 Dec 2024 18:50:22 +0800 [thread overview]
Message-ID: <20241207105023.542399-2-julia.zhang@amd.com> (raw)
In-Reply-To: <20241207105023.542399-1-julia.zhang@amd.com>
To get the p2pdma_distance, this create a new privcmd ioctl to calculate
p2pdma_distance for two pci devices on the host with pci notations sent
from guest virtgpu driver.
Signed-off-by: Julia Zhang <julia.zhang@amd.com>
---
drivers/xen/privcmd.c | 42 ++++++++++++++++++++++++++++++++++++++
include/uapi/xen/privcmd.h | 12 +++++++++++
2 files changed, 54 insertions(+)
diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
index 72c161e94731..95f67815a2ef 100644
--- a/drivers/xen/privcmd.c
+++ b/drivers/xen/privcmd.c
@@ -31,6 +31,9 @@
#include <linux/miscdevice.h>
#include <linux/moduleparam.h>
#include <linux/virtio_mmio.h>
+#include <linux/pci.h>
+#include <linux/pci-p2pdma.h>
+#include <linux/dma-map-ops.h>
#include <asm/xen/hypervisor.h>
#include <asm/xen/hypercall.h>
@@ -977,6 +980,42 @@ static long privcmd_ioctl_map_hva_to_gpfns(struct file *file, void __user *udata
return ret;
}
+static int privcmd_ioctl_p2pdma_distance(struct file *file, void __user *udata)
+{
+ struct privcmd_p2pdma_distance kdata;
+ struct pci_dev *provider = NULL;
+ struct pci_dev *client = NULL;
+ struct pci_dev *dev = NULL;
+ enum pci_p2pdma_map_type map;
+
+ if (copy_from_user(&kdata, udata, sizeof(kdata)))
+ return -EFAULT;
+
+ for_each_pci_dev(dev) {
+ if (dev->bus->number == kdata.provider_bus &&
+ dev->devfn == PCI_DEVFN(kdata.provider_slot, kdata.provider_func)) {
+ provider = dev;
+ } else if (dev->bus->number == kdata.client_bus &&
+ dev->devfn == PCI_DEVFN(kdata.client_slot, kdata.client_func)) {
+ client = dev;
+ } else {
+ continue;
+ }
+ }
+
+ if (!provider || !client) {
+ pr_err("%s fail to get provider or client.\n", __func__);
+ return -EINVAL;
+ }
+
+ kdata.distance = pci_p2pdma_distance(provider, &client->dev, false);
+
+ if (copy_to_user(udata, &kdata, sizeof(kdata)))
+ return -EFAULT;
+
+ return 0;
+}
+
#ifdef CONFIG_XEN_PRIVCMD_EVENTFD
/* Irqfd support */
static struct workqueue_struct *irqfd_cleanup_wq;
@@ -1684,6 +1723,9 @@ static long privcmd_ioctl(struct file *file,
ret = privcmd_ioctl_map_hva_to_gpfns(file, udata);
break;
+ case IOCTL_PRIVCMD_P2PDMA_DISTANCE:
+ ret = privcmd_ioctl_p2pdma_distance(file, udata);
+ break;
default:
break;
diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h
index d131002dd48f..a7ec3704519f 100644
--- a/include/uapi/xen/privcmd.h
+++ b/include/uapi/xen/privcmd.h
@@ -141,6 +141,16 @@ struct privcmd_map_hva_to_gpfns {
int add_mapping;
};
+struct privcmd_p2pdma_distance {
+ __u32 provider_bus;
+ __u32 provider_slot;
+ __u32 provider_func;
+ __u32 client_bus;
+ __u32 client_slot;
+ __u32 client_func;
+ __u32 distance;
+};
+
/*
* @cmd: IOCTL_PRIVCMD_HYPERCALL
* @arg: &privcmd_hypercall_t
@@ -174,6 +184,8 @@ struct privcmd_map_hva_to_gpfns {
_IOW('P', 9, struct privcmd_ioeventfd)
#define IOCTL_PRIVCMD_PCIDEV_GET_GSI \
_IOC(_IOC_NONE, 'P', 10, sizeof(struct privcmd_pcidev_get_gsi))
+#define IOCTL_PRIVCMD_P2PDMA_DISTANCE \
+ _IOC(_IOC_NONE, 'P', 11, sizeof(struct privcmd_p2pdma_distance))
#define IOCTL_PRIVCMD_MAP_HVA_TO_GPFNS \
_IOC(_IOC_NONE, 'P', 13, sizeof(struct privcmd_map_hva_to_gpfns))
--
2.34.1
next prev parent reply other threads:[~2024-12-07 10:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-07 10:50 [PATCH 0/3] virtgpu: check if P2P is possiable or not Julia Zhang
2024-12-07 10:50 ` Julia Zhang [this message]
2024-12-07 10:50 ` [PATCH 2/3] virtgpu: get p2pdma_distance Julia Zhang
2024-12-07 10:50 ` [PATCH 3/3] drm/virtio: Implement device_attach Julia Zhang
2024-12-09 12:28 ` Christian König
2024-12-12 7:43 ` [PATCH 0/3] virtgpu: check if P2P is possiable or not Juergen Gross
2024-12-13 9:58 ` Zhang, Julia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241207105023.542399-2-julia.zhang@amd.com \
--to=julia.zhang@amd.com \
--cc=Jiqian.Chen@amd.com \
--cc=Lingshan.Zhu@amd.com \
--cc=airlied@redhat.com \
--cc=alexander.deucher@amd.com \
--cc=anthony.perard@citrix.com \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=gurchetansingh@chromium.org \
--cc=jbeulich@suse.com \
--cc=jgross@suse.com \
--cc=kraxel@redhat.com \
--cc=oleksandr_tyshchenko@epam.com \
--cc=olvaffe@gmail.com \
--cc=paul@xen.org \
--cc=penny.zheng@amd.com \
--cc=ray.huang@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox