From: Alex Williamson <alex@shazbot.org>
To: Omar Elghoul <oelghoul@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, hca@linux.ibm.com, gor@linux.ibm.com,
agordeev@linux.ibm.com, borntraeger@linux.ibm.com,
svens@linux.ibm.com, schnelle@linux.ibm.com,
mjrosato@linux.ibm.com, alifm@linux.ibm.com,
farman@linux.ibm.com, gbayer@linux.ibm.com, alex@shazbot.org
Subject: Re: [PATCH v2 2/3] vfio-pci/zdev: Add VFIO FMB device feature
Date: Tue, 2 Jun 2026 16:24:09 -0600 [thread overview]
Message-ID: <20260602162409.1ca3c765@shazbot.org> (raw)
In-Reply-To: <20260519224204.19154-3-oelghoul@linux.ibm.com>
On Tue, 19 May 2026 18:42:03 -0400
Omar Elghoul <oelghoul@linux.ibm.com> wrote:
> diff --git a/drivers/vfio/pci/vfio_pci_zdev.c b/drivers/vfio/pci/vfio_pci_zdev.c
> index 0990fdb146b7..1e9efe2bee69 100644
> --- a/drivers/vfio/pci/vfio_pci_zdev.c
> +++ b/drivers/vfio/pci/vfio_pci_zdev.c
> @@ -167,3 +167,80 @@ void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev)
> if (zpci_kvm_hook.kvm_unregister)
> zpci_kvm_hook.kvm_unregister(zdev);
> }
> +
> +int vfio_pci_zdev_feature_fmb(struct vfio_pci_core_device *vdev, u32 flags,
> + void __user *arg, size_t argsz)
> +{
> + struct zpci_dev *zdev;
> + struct vfio_device_feature_zpci_fmb fmb = {0};
> + u32 ops = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_SET;
Somewhat gratuitous variable usage.
> + int ret;
> +
> + ret = vfio_check_feature(flags, argsz, ops, sizeof(fmb));
> + if (ret != 1)
> + return ret;
> +
> + zdev = to_zpci(vdev->pdev);
> + if (!zdev)
> + return -ENODEV;
> +
> + mutex_lock(&zdev->fmb_lock);
Use a guard and avoid the release_lock gotos.
> + if (flags & VFIO_DEVICE_FEATURE_SET) {
> + if (copy_from_user(&fmb, arg, sizeof(fmb))) {
> + ret = -EFAULT;
> + goto release_lock;
> + }
> +
> + if (fmb.flags & VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED)
> + ret = zpci_fmb_reenable_device(zdev);
> + else
> + ret = zpci_fmb_disable_device(zdev);
> + goto release_lock;
Remaining flag bits are not tested, breaks any future expanded use of
flags.
Why does the user need to be able to control these?
Doesn't allowing the user to disable FMB remove guaranteed host-based
monitoring?
Since this is already provided via debugfs, why not make this a
userspace problem to interact with the existing interface?
Alternatively, couldn't the existing zpci mediation be extended to
support the guest registering a fmb buffer to be written at regular
intervals (the interface here seems to drop the reporting interval).
> + }
> +
> + ret = 0;
> + if (zdev->fmb) {
> + fmb.flags |= VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED;
> + } else {
> + fmb.flags &= ~VFIO_DEVICE_FEATURE_ZPCI_FMB_FLAGS_ENABLED;
> + goto release_lock;
> + }
Flag bit is cleared, goto skips copy-to-user, returns success...
Regardless of what's documented in the header, the buffer should be
assumed to be userspace garbage. Failing to set or clear the entire
flags field precludes any future use.
Why do we need to use flags to indicate the enable state? Couldn't we
just as easily have success indicate enabled and -ENOMSG indicate
disabled? Thanks,
Alex
next prev parent reply other threads:[~2026-06-02 22:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 22:42 [PATCH v2 0/3] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
2026-05-19 22:42 ` [PATCH v2 1/3] s390/pci: Preserve FMB state in device re-enablement Omar Elghoul
2026-06-03 10:50 ` Niklas Schnelle
2026-06-03 12:52 ` Omar Elghoul
2026-05-19 22:42 ` [PATCH v2 2/3] vfio-pci/zdev: Add VFIO FMB device feature Omar Elghoul
2026-06-02 22:24 ` Alex Williamson [this message]
2026-06-03 12:35 ` Omar Elghoul
2026-06-03 13:56 ` Niklas Schnelle
2026-06-03 15:55 ` Alex Williamson
2026-06-03 18:26 ` Omar Elghoul
2026-06-03 19:24 ` Alex Williamson
2026-06-03 21:20 ` Omar Elghoul
2026-05-19 22:42 ` [PATCH v2 3/3] s390/pci: Fence FMB enable/disable via sysfs for passthrough devices Omar Elghoul
2026-06-03 12:15 ` Niklas Schnelle
2026-06-03 13:02 ` Omar Elghoul
2026-06-02 19:36 ` [PATCH v2 0/3] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
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=20260602162409.1ca3c765@shazbot.org \
--to=alex@shazbot.org \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=farman@linux.ibm.com \
--cc=gbayer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=oelghoul@linux.ibm.com \
--cc=schnelle@linux.ibm.com \
--cc=svens@linux.ibm.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
all inboxes | Powered by JetHome®