From: Pranjal Shrivastava <praan@google.com>
To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Logan Gunthorpe <logang@deltatee.com>,
Alex Williamson <alex@shazbot.org>,
Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Pranjal Shrivastava <praan@google.com>,
Ankit Agrawal <ankita@nvidia.com>, Matt Evans <mattev@meta.com>,
Vivek Kasireddy <vivek.kasireddy@intel.com>,
Leon Romanovsky <leon@kernel.org>,
Shivaji Kant <shivajikant@google.com>,
Samiullah Khawaja <skhawaja@google.com>
Subject: [RFC PATCH 2/5] vfio/pci: Implement ZONE_DEVICE-backed P2P registration
Date: Wed, 10 Jun 2026 15:18:50 +0000 [thread overview]
Message-ID: <20260610151853.3608948-3-praan@google.com> (raw)
In-Reply-To: <20260610151853.3608948-1-praan@google.com>
Implement the VFIO_DEVICE_FEATURE_P2P_REGISTER. A bitmask is added to
track the registered regions.
Post-registration, the BAR is added to the device's P2P pool and is
available to be used with standard page-based APIs.
Signed-off-by: Pranjal Shrivastava <praan@google.com>
---
drivers/vfio/pci/vfio_pci_core.c | 39 ++++++++++++++++++++++++++++++++
include/linux/vfio_pci_core.h | 1 +
2 files changed, 40 insertions(+)
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index a28f1e99362c..1e922e3aaeb3 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1554,6 +1554,43 @@ static int vfio_pci_core_feature_token(struct vfio_pci_core_device *vdev,
return 0;
}
+static int vfio_pci_core_feature_p2p_register(struct vfio_pci_core_device *vdev,
+ u32 flags, u32 __user *arg,
+ size_t argsz)
+{
+ u32 bar_index;
+ int ret;
+
+ ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,
+ sizeof(bar_index));
+ if (ret != 1)
+ return ret;
+
+ if (copy_from_user(&bar_index, arg, sizeof(bar_index)))
+ return -EFAULT;
+
+ if (bar_index >= PCI_STD_NUM_BARS)
+ return -EINVAL;
+
+ if (!(pci_resource_flags(vdev->pdev, bar_index) & IORESOURCE_MEM))
+ return -EINVAL;
+
+ /* Already registered */
+ if (vdev->p2p_registered_bars & (1 << bar_index))
+ return 0;
+
+ ret = pci_p2pdma_add_resource(vdev->pdev, bar_index, 0, 0);
+ if (ret && ret != -EEXIST)
+ return ret;
+
+ vdev->p2p_registered_bars |= (1 << bar_index);
+
+ pci_info(vdev->pdev, "BAR %d registered for ZONE_DEVICE P2P\n",
+ bar_index);
+
+ return 0;
+}
+
int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
void __user *arg, size_t argsz)
{
@@ -1572,6 +1609,8 @@ int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
return vfio_pci_core_feature_token(vdev, flags, arg, argsz);
case VFIO_DEVICE_FEATURE_DMA_BUF:
return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz);
+ case VFIO_DEVICE_FEATURE_P2P_REGISTER:
+ return vfio_pci_core_feature_p2p_register(vdev, flags, arg, argsz);
default:
return -ENOTTY;
}
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 5fc6ce4dd786..cae7f069e5b6 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -112,6 +112,7 @@ struct vfio_pci_core_device {
struct vfio_pci_region *region;
u8 msi_qmax;
u8 msix_bar;
+ u8 p2p_registered_bars;
u16 msix_size;
u32 msix_offset;
u32 rbar[7];
--
2.54.0.1099.g489fc7bff1-goog
next prev parent reply other threads:[~2026-06-10 15:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 15:18 [RFC PATCH 0/5] vfio/pci: Support ZONE_DEVICE-backed P2P Registration Pranjal Shrivastava
2026-06-10 15:18 ` [RFC PATCH 1/5] vfio: Add UAPI for ZONE_DEVICE-backed P2P registration Pranjal Shrivastava
2026-06-10 15:18 ` Pranjal Shrivastava [this message]
2026-06-10 15:18 ` [RFC PATCH 3/5] vfio/pci: Block mmap & dmabuf export for ZONE_DEVICE-registered BARs Pranjal Shrivastava
2026-06-10 15:18 ` [RFC PATCH 4/5] vfio/pci: Block ZONE_DEVICE registration for BARs with active DMABUFs Pranjal Shrivastava
2026-06-10 15:18 ` [RFC PATCH 5/5] PCI/P2PDMA: Introduce a helper to release P2P resources Pranjal Shrivastava
2026-06-10 16:28 ` [RFC PATCH 0/5] vfio/pci: Support ZONE_DEVICE-backed P2P Registration Jason Gunthorpe
2026-06-10 18:32 ` Leon Romanovsky
2026-06-11 14:40 ` Pranjal Shrivastava
2026-06-11 14:43 ` Pranjal Shrivastava
2026-06-11 22:14 ` Jason Gunthorpe
2026-06-12 14:50 ` Pranjal Shrivastava
2026-06-16 0:42 ` Samiullah Khawaja
2026-06-16 6:38 ` Pranjal Shrivastava
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=20260610151853.3608948-3-praan@google.com \
--to=praan@google.com \
--cc=alex@shazbot.org \
--cc=ankita@nvidia.com \
--cc=bhelgaas@google.com \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=mattev@meta.com \
--cc=shivajikant@google.com \
--cc=skhawaja@google.com \
--cc=vivek.kasireddy@intel.com \
/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
Powered by JetHome