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, pasic@linux.ibm.com,
frankja@linux.ibm.com, imbrenda@linux.ibm.com, alex@shazbot.org
Subject: Re: [PATCH v7 4/4] vfio-pci/zdev: Add VFIO FMB device features
Date: Wed, 30 Sep 2026 14:03:19 -0600 [thread overview]
Message-ID: <20260930140319.66a27f1c@shazbot.org> (raw)
In-Reply-To: <53c94059-fe7f-48e9-9588-ee07a40d45de@linux.ibm.com>
On Wed, 30 Sep 2026 15:40:40 -0400
Omar Elghoul <oelghoul@linux.ibm.com> wrote:
> On 9/30/26 2:57 PM, Alex Williamson wrote:
> > On Tue, 22 Sep 2026 15:51:41 -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 f47f36314a1c..b028de8e08a4 100644
> >> --- a/drivers/vfio/pci/vfio_pci_zdev.c
> >> +++ b/drivers/vfio/pci/vfio_pci_zdev.c
> >> @@ -219,3 +219,63 @@ 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_enable(struct vfio_pci_core_device *vdev, u32 flags,
> >> + void __user *arg, size_t argsz)
> >> +{
> >> + struct zpci_dev *zdev;
> >> + struct vfio_device_feature_zpci_fmb_enable fmb_enable;
> >> + int ret;
> >> +
> >> + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, sizeof(fmb_enable));
> >> + if (ret != 1)
> >> + return ret;
> >> +
> >> + zdev = to_zpci(vdev->pdev);
> >> + if (!zdev)
> >> + return -ENODEV;
> >> +
> >> + if (copy_from_user(&fmb_enable, arg, sizeof(fmb_enable)))
> >> + return -EFAULT;
> >> +
> >> + guard(mutex)(&zdev->fmb_lock);
> >> +
> >> + if (fmb_enable.enabled)
> >> + return zpci_fmb_reenable_device(zdev);
> >> + return zpci_fmb_disable_device(zdev);
> >> +}
> >> +
> >> +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;
> >> +
> >> + mutex_lock(&zdev->fmb_lock);
> >> + if (!zdev->fmb_enabled) {
> >> + mutex_unlock(&zdev->fmb_lock);
> >> + return -ENOMSG;
> >> + }
> >> +
> >> + memcpy(&fmb_bounce, zdev->fmb, zdev->fmb_length);
> >> + mutex_unlock(&zdev->fmb_lock);
> >
> > A scoped guard would be preferable for consistency with the enable
> > path.
>
> I thought of that too, but then we'd do copy_to_user() while holding the
> mutex for longer than is necessary, which I think was pointed out in an
> earlier version.
Depends how you use it:
scoped_guard(mutex, &zdev->fmb_lock) {
if (!zdev->fmb_enabled)
return -ENOMSG;
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;
Thanks,
Alex
next prev parent reply other threads:[~2026-09-30 20:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 19:51 [PATCH v7 0/4] vfio-pci/zdev: Improved zPCI Function Measurement Support Omar Elghoul
2026-09-22 19:51 ` [PATCH v7 1/4] s390/pci: Hold fmb_lock when enabling or disabling PCI devices Omar Elghoul
2026-09-22 19:51 ` [PATCH v7 2/4] s390/pci: Reuse FMB buffer and preserve state in device re-enablement Omar Elghoul
2026-09-23 15:09 ` Gerd Bayer
2026-09-23 16:37 ` Omar Elghoul
2026-09-24 15:55 ` Gerd Bayer
2026-09-24 16:47 ` Omar Elghoul
2026-09-23 22:20 ` Matthew Rosato
2026-09-24 14:27 ` Omar Elghoul
2026-09-30 18:57 ` Alex Williamson
2026-09-30 19:36 ` Omar Elghoul
2026-09-22 19:51 ` [PATCH v7 3/4] s390/pci: Fence FMB enable/disable via debugfs for passthrough devices Omar Elghoul
2026-09-22 19:51 ` [PATCH v7 4/4] vfio-pci/zdev: Add VFIO FMB device features Omar Elghoul
2026-09-30 18:57 ` Alex Williamson
2026-09-30 19:17 ` Matthew Rosato
2026-09-30 19:40 ` Omar Elghoul
2026-09-30 20:03 ` Alex Williamson [this message]
2026-09-30 17:48 ` [PATCH v7 0/4] 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=20260930140319.66a27f1c@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=frankja@linux.ibm.com \
--cc=gbayer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@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=pasic@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®