Re: [PATCH v12 5/5] vfio-pci/zdev: Add VFIO FMB device features
From: Niklas Schnelle
Date: Tue Nov 03 2026 - 16:10:07 EST
On Tue, 2026-11-03 at 10:01 -0500, Omar Elghoul wrote:
> Introduce new VFIO features for zPCI devices to provide FMB passthrough to
> userspace.
>
> Allow the user to enable or disable the FMB using the SET-only feature
> VFIO_DEVICE_FEATURE_ZPCI_FMB_ENABLE. Likewise allow the user to read the
> latest FMB using the GET-only feature VFIO_DEVICE_FEATURE_ZPCI_FMB_READ
> in the case when the FMB is enabled.
>
> Signed-off-by: Omar Elghoul <oelghoul@xxxxxxxxxxxxx>
> Acked-by: Alex Williamson <alex@xxxxxxxxxxx>
> ---
> drivers/vfio/pci/vfio_pci_core.c | 4 ++
> drivers/vfio/pci/vfio_pci_priv.h | 18 +++++++++
> drivers/vfio/pci/vfio_pci_zdev.c | 64 ++++++++++++++++++++++++++++++++
> include/uapi/linux/vfio.h | 30 +++++++++++++++
> 4 files changed, 116 insertions(+)
>
--- snip ---
> +
> +int vfio_pci_zdev_feature_fmb_read(struct vfio_pci_core_device *vdev, u32 flags,
> + void __user *arg, size_t argsz)
> +{
> + struct zpci_dev *zdev;
> + struct vfio_device_feature_zpci_fmb_read fmb_read;
> + struct zpci_fmb fmb_bounce;
> + int ret;
> +
> + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET, sizeof(fmb_read));
> + if (ret != 1)
> + return ret;
> +
> + zdev = to_zpci(vdev->pdev);
> + if (!zdev)
> + return -ENODEV;
> +
> + if (copy_from_user(&fmb_read, arg, sizeof(fmb_read)))
> + return -EFAULT;
> + if (!fmb_read.data)
> + return -EINVAL;
> +
> + scoped_guard(mutex, &zdev->fmb_lock) {
> + if (!zdev->fmb_enabled)
> + return -ENOMSG;
For those who were also wondering what would happen if the zdev has an
FMB length too large for this kernel's version of struct zpci_fmb. In
that case zpci_fmb_enable() fails the FMB enablement leaving zdev-
>fmb_enabled false and then the check above also covers the memcpy()
here even if user-space ignores that the FMB is not enabled.
> + memcpy(&fmb_bounce, zdev->fmb, zdev->fmb_length);
> + }
> +
> + if (copy_to_user(u64_to_user_ptr(fmb_read.data), &fmb_bounce, zdev->fmb_length))
> + return -EFAULT;
> +
> + return 0;
> +}
Looks good, looking forward to having function measurement in KVM
guests.
Reviewed-by: Niklas Schnelle <schnelle@xxxxxxxxxxxxx>