Skip to contentSkip to conversation

misc: vmw_zerocopy: VMware zero-copy buffer sharing driver

PATCH In review Rishi Chhibber 2 participants 7 messages Sep 14 – Oct 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover misc: vmw_zerocopy: VMware zero-copy buffer sharing driver

Summary of changes:
- 1/4 reserves a VMCI datagram resource id for the hypervisor-side zero-copy service
- 2/4 adds the vmw_zerocopy driver: /dev/vmw_zc, a single ioctl, page pinning and the VMCI datagram transport
- 3/4 documents the userspace interface
- 4/4 adds a kselftest covering the ioctl input-validation paths

This series adds a misc character device, /dev/vmw_zc, that lets guest userspace hand a buffer to a VMware hypervisor-side peer without copying it. The driver pins the user pages, collects their guest physical frame numbers and sends that list over a VMCI datagram; the hypervisor then reads the buffer directly out of guest memory. An optional metadata buffer is pinned writable so the peer can return a result through the same mechanism.

Why not vsock or virtio: this is not paravirtual I/O. The guest is not sending data to a virtual device; it hands page frame numbers to the hypervisor and reads the results back inline in those same pages, with no copy and no ring buffer. Two properties have no mapping onto an existing virtio device type:

- PFN-level zero copy without ownership transfer. virtio-vsock copies through the virtqueue ring. virtio-mem and virtio-balloon transfer page ownership to the host; here the guest keeps its pages and unpins them when the ioctl returns.
- Per-ioctl synchronous feedback. The metadata pages are pinned writable and the peer stores status directly into them, so userspace reads the result on ioctl return. storvsc and hv_balloon return status in a separate ring packet instead; Xen gntdev's writable grants and UNMAP_NOTIFY_CLEAR_BYTE serve persistent ring lifecycles, not per-call results.

The established upstream shape for this is a thin guest driver over the vendor's native transport: Hyper-V builds a PFN list for the host with vmbus_establish_gpadl(), Xen shares frames through the grant table and exposes that to userspace in gntdev, and VMware already has vmxnet3, vmw_pvscsi and vmw_balloon on its own protocols. This driver is the VMCI equivalent. Discussed in full in the v2 thread (linked below); 2/4 carries the short form.

v2 was posted as a single patch and is split here into a reviewable series along file boundaries: every file belongs entirely to one patch, so each commit builds on its own. 1/4 comes first because 2/4 sends to the resource id it reserves, and because it has a different maintainer set. vmw_zerocopy_core.c and vmw_zerocopy_vmci.c stay in one patch as they form a single module and reference each other.

Changes since v2:
- Split the single patch into this four-patch series
- The destination is now owned by the kernel: the userspace-supplied peer_id is gone, and that word is a reserved field that must be zero
- Dropped VMW_ZC_MSG_INIT and struct vmw_zc_ioctl_config; the device needs no configuration step
- Release metadata pages with unpin_user_pages_dirty_lock(..., true); the peer stores through the physical frame, so nothing else marks those pages dirty
- Split the VMCI transport out behind a small transport ops struct
- Dropped the out-of-tree KBUILD_EXTMOD build logic from drivers/misc/Makefile (Greg Kroah-Hartman)
- Removed __user from struct vmw_zc_guest_raw_buffer; it has no place in an ioctl structure (Greg Kroah-Hartman)
- Registered ioctl magic 0xDC in ioctl-number.rst
- Added driver documentation (3/4) and a selftest (4/4)
- Rebased onto v7.3-rc3

Userspace built against the v2 header must be rebuilt: the peer_id field and the configuration ioctl it used no longer exist. Nothing is merged upstream, so no stable ABI is affected.

Testing:
- Every commit builds on x86_64 with CONFIG_VMW_ZC=m, and make headers_install succeeds at each one
- checkpatch.pl --strict reports nothing on 1/4 and 2/4; on 3/4 and 4/4 only the MAINTAINERS advisory for newly added files
- The selftest builds, and skips cleanly when /dev/vmw_zc is absent

Link to v2:
https://lore.kernel.org/lkml/[email protected]/

Transport choice, discussed in the v2 thread:
https://lore.kernel.org/lkml/CABJwUKKCwGxYB0is-U84EgAm6Co9_bfxbkZi56jZNLkzihDRyw@mail.gmail.com/

Rishi Chhibber (4):
misc: vmw_vmci: Reserve a datagram resource id for zero-copy buffer
sharing
misc: vmw_zerocopy: Add VMware zero-copy buffer sharing driver
Documentation: misc: Add vmw_zerocopy driver documentation
selftests: misc: Add vmw_zerocopy selftest

 Documentation/misc-devices/index.rst          |   1 +
 Documentation/misc-devices/vmw_zerocopy.rst   | 278 ++++++++++++++++++
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |  10 +
 drivers/misc/Kconfig                          |  23 ++
 drivers/misc/Makefile                         |   2 +
 drivers/misc/vmw_zerocopy_core.c              | 267 +++++++++++++++++
 drivers/misc/vmw_zerocopy_priv.h              |  66 +++++
 drivers/misc/vmw_zerocopy_vmci.c              | 132 +++++++++
 include/linux/vmw_vmci_defs.h                 |   3 +-
 include/uapi/linux/vmw_zerocopy.h             |  67 +++++
 tools/testing/selftests/Makefile              |   1 +
 .../drivers/misc/vmw_zerocopy/.gitignore      |   1 +
 .../drivers/misc/vmw_zerocopy/Makefile        |  20 ++
 .../drivers/misc/vmw_zerocopy/config          |   2 +
 .../misc/vmw_zerocopy/test_vmw_zerocopy.c     | 276 +++++++++++++++++
 16 files changed, 1149 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/misc-devices/vmw_zerocopy.rst
 create mode 100644 drivers/misc/vmw_zerocopy_core.c
 create mode 100644 drivers/misc/vmw_zerocopy_priv.h
 create mode 100644 drivers/misc/vmw_zerocopy_vmci.c
 create mode 100644 include/uapi/linux/vmw_zerocopy.h
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/.gitignore
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/Makefile
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/config
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/test_vmw_zerocopy.c

base-commit: fd73f4a6659897191fa0d40695fe370925dd3780

Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/4 misc: vmw_vmci: Reserve a datagram resource id for zero-copy buffer sharing

Summary of changes:
- Add VMCI_VMWZC_DST_RID to the reserved hypervisor datagram resource id enum and bump VMCI_RESOURCE_MAX accordingly

The hypervisor-side zero-copy buffer sharing service occupies its own resource id in the hypervisor datagram namespace. Reserve a name for it alongside the existing entries rather than leaving callers to open-code the number, following the procedure described in that enum's own comment: the set of resource ids available in the hypervisor is fixed and statically known, and a new caller extends it by incrementing the maximum.

VMCI_RESOURCE_MAX has no in-tree users, so the bump does not affect existing code. The new entry likewise has no in-tree user until the vmw_zerocopy driver, added later in this series, references it.

---
 include/linux/vmw_vmci_defs.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/vmw_vmci_defs.h +2 -1
index 60c9eacd2cf3..4435d2ff1241 100644
@@ -179,7 +179,8 @@ enum {
 	VMCI_UNITY_PBRPC_REGISTER = 14,
 	VMCI_RPC_PRIVILEGED = 15,
 	VMCI_RPC_UNPRIVILEGED = 16,
-	VMCI_RESOURCE_MAX = 17,
+	VMCI_VMWZC_DST_RID = 17,
+	VMCI_RESOURCE_MAX = 18,
 };
 
 /*
Signature · 1 line
2.52.0
#2 lore raw

PATCH v3 2/4 misc: vmw_zerocopy: Add VMware zero-copy buffer sharing driver

In reply to Rishi Chhibber

Summary of changes:
- Add drivers/misc/vmw_zerocopy_core.c: the misc character device /dev/vmw_zc, its single ioctl, page pinning and PFN collection
- Add drivers/misc/vmw_zerocopy_vmci.c: the VMCI datagram transport backend
- Add drivers/misc/vmw_zerocopy_priv.h: the wire-format message structs and the struct vmw_zc_transport_ops interface that joins the two
- Add include/uapi/linux/vmw_zerocopy.h: struct vmw_zc_guest_message and VMW_ZC_IOCTL_MSG
- Register ioctl magic 0xDC in Documentation/userspace-api/ioctl/ioctl-number.rst
- Add the VMW_ZC Kconfig symbol and a MAINTAINERS entry

This driver implements a misc character device (/dev/vmw_zc) that pins guest userspace pages and transmits their physical frame numbers (PFNs) to a VMware hypervisor-side peer.

The payload itself is never transferred. What crosses to the hypervisor is a list of guest physical frame numbers for pages pinned in place, so the hypervisor reads the buffer directly out of guest memory. vsock and virtio are copying transports: both move the bytes through a ring or a socket buffer, which is precisely the copy this interface exists to avoid. The VMCI datagram carries only the PFN descriptor and never the data, which is why an existing standard transport cannot serve this purpose.

The destination is deliberately not part of the UAPI. It is a VMCI resource id in the hypervisor context, and that namespace belongs to the platform:
the low ids are the hypervisor's own control entry points, and vmci_datagram_send() dispatches from an in-kernel sender, so the check that stops userspace from addressing the hypervisor does not apply here. A device node that unprivileged userspace can open must therefore not let userspace name a destination, or it becomes an unfiltered writer onto the hypervisor's control namespace. Fixing the destination in the driver removes that reachability by construction rather than by validation.

Delivery is abstracted behind a small transport interface so that VMCI, the only backend today, is not depended on directly by the ioctl path.

The metadata buffer is released with unpin_user_pages_dirty_lock(..., true). The hypervisor stores its result through the physical frame, so neither the guest page table nor the folio records the write and the result can be lost to writeback or reclaim; this is the same fix as commit 779055842da5 ("xen/gntdev.c: Mark pages as dirty") and the pattern used by drivers/xen/privcmd.c. The read-only data buffer keeps the plain path.

---
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |  10 +
 drivers/misc/Kconfig                          |  23 ++
 drivers/misc/Makefile                         |   2 +
 drivers/misc/vmw_zerocopy_core.c              | 267 ++++++++++++++++++
 drivers/misc/vmw_zerocopy_priv.h              |  66 +++++
 drivers/misc/vmw_zerocopy_vmci.c              | 132 +++++++++
 include/uapi/linux/vmw_zerocopy.h             |  67 +++++
 8 files changed, 568 insertions(+)
 create mode 100644 drivers/misc/vmw_zerocopy_core.c
 create mode 100644 drivers/misc/vmw_zerocopy_priv.h
 create mode 100644 drivers/misc/vmw_zerocopy_vmci.c
 create mode 100644 include/uapi/linux/vmw_zerocopy.h
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
index 2fc53093752d..f55998d5e270 100644
@@ -396,6 +396,7 @@ Code  Seq#    Include File                                             Comments
 0xCD  01     linux/reiserfs_fs.h                                       Dead since 6.13
 0xCE  01-02  uapi/linux/cxl_mem.h                                      Compute Express Link Memory Devices
 0xCF  02     fs/smb/client/cifs_ioctl.h
+0xDC  01     uapi/linux/vmw_zerocopy.h                                 VMware zero-copy buffer sharing
 0xDD  00-3F                                                            ZFCP device driver see drivers/s390/scsi/
                                                                        <mailto:[email protected]>
 0xE5  00-3F  linux/fuse.h
MAINTAINERS +10 -0
index c2414447892c..d683336b30d8 100644
@@ -29228,6 +29228,16 @@ L:	[email protected]
 S:	Supported
 F:	net/vmw_vsock/vmci_transport*
 
+VMWARE ZEROCOPY DRIVER
+M:	Rishi Chhibber <[email protected]>
+R:	Broadcom internal kernel review list <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/misc-devices/vmw_zerocopy.rst
+F:	drivers/misc/vmw_zerocopy*
+F:	include/uapi/linux/vmw_zerocopy.h
+F:	tools/testing/selftests/drivers/misc/vmw_zerocopy/
+
 VOCORE VOCORE2 BOARD
 M:	Harvey Hunt <[email protected]>
 L:	[email protected]
drivers/misc/Kconfig +23 -0
index 7364931dad3a..cf48c29db35e 100644
@@ -359,6 +359,29 @@ config VMWARE_BALLOON
 	  To compile this driver as a module, choose M here: the
 	  module will be called vmw_balloon.
 
+config VMW_ZC
+	tristate "VMware zero-copy buffer sharing device"
+	depends on VMWARE_VMCI && HYPERVISOR_GUEST && !X86_MEM_ENCRYPT
+	help
+	  This driver implements a character device (/dev/vmw_zc) that
+	  allows guest userspace applications to share pinned memory
+	  buffers with a VMware hypervisor-side peer using the VMCI
+	  datagram interface.
+
+	  Applications submit buffers via ioctl(). The driver pins the
+	  user pages and transmits their physical page frame numbers to
+	  the peer, enabling zero-copy data transfer between the guest
+	  and the hypervisor without an intermediate copy.
+
+	  This driver is not compatible with guests that use memory
+	  encryption (AMD SEV-SNP or Intel TDX), as the hypervisor
+	  cannot read encrypted guest physical memory.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called vmw_zerocopy.
+
 config PCH_PHUB
 	tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB"
 	select GENERIC_NET_UTILS
drivers/misc/Makefile +2 -0
index e8d8d5d88c0d..eda927fd68dd 100644
@@ -62,6 +62,8 @@ obj-$(CONFIG_TMR_MANAGER)      += xilinx_tmr_manager.o
 obj-$(CONFIG_TMR_INJECT)	+= xilinx_tmr_inject.o
 obj-$(CONFIG_TPS6594_ESM)	+= tps6594-esm.o
 obj-$(CONFIG_TPS6594_PFSM)	+= tps6594-pfsm.o
+obj-$(CONFIG_VMW_ZC)		+= vmw_zerocopy.o
+vmw_zerocopy-y			:= vmw_zerocopy_core.o vmw_zerocopy_vmci.o
 obj-$(CONFIG_NSM)		+= nsm.o
 obj-$(CONFIG_MARVELL_CN10K_DPI)	+= mrvl_cn10k_dpi.o
 lan966x-pci-objs		:= lan966x_pci.o
drivers/misc/vmw_zerocopy_core.c new file +267 -0

267 lines not on this page · raw message

drivers/misc/vmw_zerocopy_priv.h new file +66 -0

66 lines not on this page · raw message

drivers/misc/vmw_zerocopy_vmci.c new file +132 -0

132 lines not on this page · raw message

include/uapi/linux/vmw_zerocopy.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.52.0
#4 lore raw

PATCH v3 3/4 Documentation: misc: Add vmw_zerocopy driver documentation

In reply to Rishi Chhibber

Summary of changes:
- Add Documentation/misc-devices/vmw_zerocopy.rst describing the device node, the ioctl interface, the message types and the buffer limits
- Link it from Documentation/misc-devices/index.rst

Document the userspace interface of the vmw_zerocopy driver added earlier in this series: the /dev/vmw_zc device node, the VMW_ZC_IOCTL_MSG ioctl and its message types, the data and metadata size limits, and an example call sequence.

The prose also covers the parts of the design that are not apparent from the interface alone: how a PFN list replaces a data copy, the metadata feedback path and why those pages need different release handling from the data pages, the atomic submission semantics of placing both PFN lists in a single datagram, the transport abstraction, and why the destination resource id is owned by the kernel rather than selectable by userspace.

---
 Documentation/misc-devices/index.rst        |   1 +
 Documentation/misc-devices/vmw_zerocopy.rst | 278 ++++++++++++++++++++
 2 files changed, 279 insertions(+)
 create mode 100644 Documentation/misc-devices/vmw_zerocopy.rst
Documentation/misc-devices/index.rst +1 -0
index f911edaecbfa..8d1687a2d566 100644
@@ -27,4 +27,5 @@ fit into other categories.
    spear-pcie-gadget
    tps6594-pfsm
    uacce
+   vmw_zerocopy
    xilinx_sdfec
Documentation/misc-devices/vmw_zerocopy.rst new file +278 -0

278 lines not on this page · raw message

Signature · 1 line
2.52.0
#5 lore raw

PATCH v3 4/4 selftests: misc: Add vmw_zerocopy selftest

In reply to Rishi Chhibber

Summary of changes:
- Add tools/testing/selftests/drivers/misc/vmw_zerocopy: a kselftest_harness test covering the ioctl input-validation paths, plus its Makefile and config fragment
- Add the target to tools/testing/selftests/Makefile

Cover the input-validation paths of the vmw_zerocopy ioctl added earlier in this series: an unknown ioctl number, a bad message pointer, an unknown message type, a non-zero reserved word, neither buffer supplied, zero-length and oversized data and metadata buffers, a wrapping address+length, a wrapping PAGE_ALIGN() of the end address, an unmapped buffer, and zero-length and oversized raw payloads.

These are all rejected before any datagram is sent, so they need no hypervisor peer. Two further tests submit a well-formed message and assert only that any failure is not a validation error, which holds whether or not a peer is listening; they also check that repeated sends do not depend on per-call setup surviving. The whole test therefore runs on any guest where the module loads, and skips cleanly when /dev/vmw_zc is absent so it does not fail on kernels built without CONFIG_VMW_ZC.

---
 tools/testing/selftests/Makefile              |   1 +
 .../drivers/misc/vmw_zerocopy/.gitignore      |   1 +
 .../drivers/misc/vmw_zerocopy/Makefile        |  20 ++
 .../drivers/misc/vmw_zerocopy/config          |   2 +
 .../misc/vmw_zerocopy/test_vmw_zerocopy.c     | 276 ++++++++++++++++++
 5 files changed, 300 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/.gitignore
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/Makefile
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/config
 create mode 100644 tools/testing/selftests/drivers/misc/vmw_zerocopy/test_vmw_zerocopy.c
tools/testing/selftests/Makefile +1 -0
index 2d960626750e..325723e92bf3 100644
@@ -20,6 +20,7 @@ TARGETS += devices/error_logs
 TARGETS += devices/probe
 TARGETS += dmabuf-heaps
 TARGETS += drivers/dma-buf
+TARGETS += drivers/misc/vmw_zerocopy
 TARGETS += drivers/ntsync
 TARGETS += drivers/s390x/uvdevice
 TARGETS += drivers/net
tools/testing/selftests/drivers/misc/vmw_zerocopy/.gitignore new file +1 -0
new file mode 100644
index 000000000000..68941a8c0553
@@ -0,0 +1 @@
+test_vmw_zerocopy
tools/testing/selftests/drivers/misc/vmw_zerocopy/Makefile new file +20 -0
new file mode 100644
index 000000000000..195826f72f9c
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+include ../../../../../build/Build.include
+
+UNAME_M := $(shell uname -m)
+
+ifeq ($(filter $(UNAME_M),x86_64 i686 i386),)
+nothing:
+.PHONY: all clean run_tests install
+.SILENT:
+else
+
+TEST_GEN_PROGS := test_vmw_zerocopy
+
+top_srcdir ?= ../../../../../..
+
+CFLAGS += -Wall -Werror $(KHDR_INCLUDES)
+
+include ../../../lib.mk
+
+endif
tools/testing/selftests/drivers/misc/vmw_zerocopy/config new file +2 -0
new file mode 100644
index 000000000000..03e4a430c5ff
@@ -0,0 +1,2 @@
+CONFIG_VMWARE_VMCI=m
+CONFIG_VMW_ZC=m
tools/testing/selftests/drivers/misc/vmw_zerocopy/test_vmw_zerocopy.c new file +276 -0

276 lines not on this page · raw message

Signature · 1 line
2.52.0
maintainer
#3 lore raw

Re: [PATCH v3 2/4] misc: vmw_zerocopy: Add VMware zero-copy buffer sharing driver

In reply to Rishi Chhibber
Quoted 11 lines · Rishi Chhibber

Summary of changes:
- Add drivers/misc/vmw_zerocopy_core.c: the misc character device /dev/vmw_zc, its single ioctl, page pinning and PFN collection
- Add drivers/misc/vmw_zerocopy_vmci.c: the VMCI datagram transport backend
- Add drivers/misc/vmw_zerocopy_priv.h: the wire-format message structs and the struct vmw_zc_transport_ops interface that joins the two
- Add include/uapi/linux/vmw_zerocopy.h: struct vmw_zc_guest_message and VMW_ZC_IOCTL_MSG
- Register ioctl magic 0xDC in Documentation/userspace-api/ioctl/ioctl-number.rst
- Add the VMW_ZC Kconfig symbol and a MAINTAINERS entry

This all goes below the --- line, right? Otherwise it would show up in the changelog which doesn't make sense :(

The kernel documentation should explain all of this, how did this pass internal review?

thanks,

greg k-h

maintainer
#6 lore raw
In reply to Rishi Chhibber
Quoted 8 lines · Rishi Chhibber

Summary of changes:
- 1/4 reserves a VMCI datagram resource id for the hypervisor-side zero-copy service
- 2/4 adds the vmw_zerocopy driver: /dev/vmw_zc, a single ioctl, page pinning and the VMCI datagram transport
- 3/4 documents the userspace interface
- 4/4 adds a kselftest covering the ioctl input-validation paths

Quoted 7 lines

This series adds a misc character device, /dev/vmw_zc, that lets guest userspace hand a buffer to a VMware hypervisor-side peer without copying it. The driver pins the user pages, collects their guest physical frame numbers and sends that list over a VMCI datagram; the hypervisor then reads the buffer directly out of guest memory. An optional metadata buffer is pinned writable so the peer can return a result through the same mechanism.

You are going to need to get the -mm maintainers/developers to sign off on this thing before I can accept it due to your "fun" use of memory buffers in here.

thanks,

greg k-h