From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC65131AABF for ; Wed, 10 Jun 2026 15:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781104739; cv=none; b=rOoRm8qQS77+FILhohi7L3lrUTBa1iod9OaaIcyij2NtPeMlZ7VCNnzJVVGmwZ2PD31lSnHJTjUguKm6HlMnchfApYJMRn/ppxSGI7Q6mVUxbGkuIvrXAmaawm8sakVPDn+L9MQMqKnePsc/3fjlE/tuaeLGr2/WSzXkyAl0rPI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781104739; c=relaxed/simple; bh=2FikaBR52j14eG2q4c7uEh8VobH/ZwHZeG2IeNzY9To=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=sUxGWGabOk1uFiRHn+QeD29QObm410QsuGcKF8m4P8iaV8BTAK58Yxk4WEUJNL4296OtGUUSSh59iIz9OPA5THbh0ZC9Nw/BkdYIOBDECqxk6EEL3YCyaowhM+r3D+b1UXzqGkX3mfQIz4vK+oHAwj2CPWCKi5YutBMol40SmCk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--praan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uodRyeWq; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--praan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uodRyeWq" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-36d6389bbf4so6786298a91.3 for ; Wed, 10 Jun 2026 08:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781104736; x=1781709536; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=B3ufllk0o8kYPSdIZb3vpcLex8ZiEWODUNKVQWpmUYY=; b=uodRyeWqx2qrn/F7GC1FiUjPsxT03DAhr3png2dsGvE7wx+70Bas4NcySYhlrvHCtL fUTUbhhzf7eSbrdwYSROX1gKLQ63Zy2Vd71phl3g7T1Sm/goljIb1PEB72lz12D2a8gW wZys+OFE3hAkmhoWiBGRTtLuU8esUzGTL4cDbLy5RePE7smh/ncALvRLoHYHM3aqTcgP IPGBjDkzHptgODU2keotgcYYDyvDP/PD/aQ6r63+IFpDWk7Ws6D30uDrkwLWetUnngaR bkBcqyBHJ66BqX7cmRg0OErac6jhL8FGJOcmz+iPweX68Xa7J9V4mdiCZ23RFZhlYtHL DEtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781104736; x=1781709536; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=B3ufllk0o8kYPSdIZb3vpcLex8ZiEWODUNKVQWpmUYY=; b=f5XGHf2MEYUOcEIXX3tFQbr2iZ/UzerRpv7ZuRaephMv5PHgMgO6MNWy+7NfqnLArF 3Hz29CvmByq+kI2HNX2IWzPVJCQNjwsD1UBmGj7b5+/P+7XThnAbN1C5t60+o2wv5MAW W2+LZ/BgmXEIG2MRWIHUMIIBnX7HiHdsgIn43gAwtIBM4wLwSKI5dpeDksH2BdbbAf/j wCGtDotp0vFGsRFR8S3DnNVEU8hZhr18zH4i8IpCkddbIKzsdXAJaw1LZUr875I8DAIz o7DWA57hXolL9DSK7mCtrv5H7uMSLkzsFrfRO1Fp96QEHZQH7F0CEuD/jtn0zHWHB3GQ LY7g== X-Forwarded-Encrypted: i=1; AFNElJ9QTDQWW5HocalWPvlDcXFljue+Qu9Mxb5Z1sdDVs/7ZsZA6A5rXfCaPMKD6yDL+U5q5d/Vry97OgoLDrI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8gqGE+z5GuCqwoeNj8TEOhqrxR0iEEBjXC39ch64XNE+IWXL+ JIuqw1Wicb3OGF5anpaVGhhoXnoKEcq758hJS8RyR2aJWByJNT73om6XsKfXW2zmYNmsl8I1NDH 8Cg== X-Received: from plbkn13.prod.google.com ([2002:a17:903:78d:b0:2b9:6a4a:141]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a46:b0:36d:bbe0:de7c with SMTP id 98e67ed59e1d1-370eeff19bamr24652982a91.12.1781104735720; Wed, 10 Jun 2026 08:18:55 -0700 (PDT) Date: Wed, 10 Jun 2026 15:18:48 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.1099.g489fc7bff1-goog Message-ID: <20260610151853.3608948-1-praan@google.com> Subject: [RFC PATCH 0/5] vfio/pci: Support ZONE_DEVICE-backed P2P Registration From: Pranjal Shrivastava To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Bjorn Helgaas , Logan Gunthorpe , Alex Williamson , Jason Gunthorpe , Kevin Tian , Pranjal Shrivastava , Ankit Agrawal , Matt Evans , Vivek Kasireddy , Leon Romanovsky , Shivaji Kant , Samiullah Khawaja Content-Type: text/plain; charset="UTF-8" Introduce ZONE_DEVICE backing for VFIO-exposed PCIe BARs. Currently, kernel drivers can register their BARs with the P2PDMA subsystem to enable high-performance, page-backed P2P DMA. However, when a device is bound to vfio-pci, this capability is missing. As a framework, VFIO should support the same set of capabilities available to kernel drivers, provided appropriate isolation and lifecycles are maintained. This series adds support for VFIO to register BARs as page-backed P2P providers, enabling userspace drivers to perform zero-copy P2P DMA via standard POSIX APIs (e.g., O_DIRECT) which require struct page metadata. Design ====== The proposed design enables VFIO to leverage the kernel's pci-p2pdma infrastructure, delegating memory management and slicing to the managed P2P pool. 1. ZONE_DEVICE Registration A new feature, VFIO_DEVICE_FEATURE_P2P_REGISTER, is introduced to trigger pci_p2pdma_add_resource() for a target BAR which creates the ZONE_DEVICE struct pages and registers the BAR as a standard P2P provider. 2. Mutual Exclusivity Policy A strict mutual exclusion policy is enforced: - Registered BARs: Standard mmap() and DMABUF export are blocked. - Exported BARs: Native P2P registration is blocked. Users utilize the standard sysfs p2pmem/allocate interface for managing memory slices once a BAR is registered. 3. Lifecycle and Resource Reclamation A new helper is introduced: pci_p2pdma_remove_resource(), is implemented to support manual teardown of the P2P pool. VFIO invokes this helper during device reset or session termination to ensure the pool is destroyed and the ZONE_DEVICE pages are unmapped. This is on github: https://github.com/pran005/linux/tree/vfio-p2p Alternative Approach: Page-backed DMABUF Export ================================================ An alternative implementation has been explored which integrates with the ongoing VFIO DMABUF-mmap refactor [1]. In that approach, rather than registering a BAR as a system-wide P2P provider, VFIO optionally allocates ZONE_DEVICE pages only for specifically exported DMABUFs via a new VFIO_DMA_BUF_FLAG_ALLOC_STRUCT_PAGES flag. A proof-of-concept of this approach is available at: https://github.com/pran005/linux/tree/vfio-p2p-alt [1] https://lore.kernel.org/all/20260527102319.100128-1-mattev@meta.com/ Pranjal Shrivastava (5): vfio: Add UAPI for ZONE_DEVICE-backed P2P registration vfio/pci: Implement ZONE_DEVICE-backed P2P registration vfio/pci: Block mmap & dmabuf export for ZONE_DEVICE-registered BARs vfio/pci: Block ZONE_DEVICE registration for BARs with active DMABUFs PCI/P2PDMA: Introduce a helper to release P2P resources drivers/pci/p2pdma.c | 38 ++++++++++++++++++++ drivers/vfio/pci/vfio_pci_core.c | 57 ++++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_dmabuf.c | 22 ++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 6 ++++ include/linux/pci-p2pdma.h | 1 + include/linux/vfio_pci_core.h | 1 + include/uapi/linux/vfio.h | 15 ++++++++ 7 files changed, 140 insertions(+) -- 2.54.0.1099.g489fc7bff1-goog