From: "Gupta, Nipun" <nipun.gupta@amd.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
git@amd.com, pieter.jansen-van-vuuren@amd.com,
nikhil.agarwal@amd.com, michal.simek@amd.com,
abhijit.gangurde@amd.com, Shubham Rohila <shubham.rohila@amd.com>
Subject: Re: [PATCH v5 3/3] vfio-cdx: add bus mastering device feature support
Date: Tue, 8 Aug 2023 16:19:10 +0530 [thread overview]
Message-ID: <3921846a-5560-44fd-c4ce-329acad454c0@amd.com> (raw)
In-Reply-To: <20230803161736.52dd2d33.alex.williamson@redhat.com>
On 8/4/2023 3:47 AM, Alex Williamson wrote:
> On Thu, 3 Aug 2023 20:02:53 +0530
> Nipun Gupta <nipun.gupta@amd.com> wrote:
>
>> Support Bus master enable and disable on VFIO-CDX devices using
>> VFIO_DEVICE_FEATURE_BUS_MASTER flag over VFIO_DEVICE_FEATURE IOCTL.
>>
>> Co-developed-by: Shubham Rohila <shubham.rohila@amd.com>
>> Signed-off-by: Shubham Rohila <shubham.rohila@amd.com>
>> Signed-off-by: Nipun Gupta <nipun.gupta@amd.com>
>> ---
>>
>> Changes v4->v5:
>> - Use device feature IOCTL instead of adding a new VFIO IOCTL
>> for bus master feature.
>>
>> Changes in v4:
>> - This patch is newly added which uses cdx_set_master() and
>> cdx_clear_master() APIs.
>>
>> drivers/vfio/cdx/main.c | 40 ++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 40 insertions(+)
>>
>> diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c
>> index c376a69d2db2..6420cf6eb2f9 100644
>> --- a/drivers/vfio/cdx/main.c
>> +++ b/drivers/vfio/cdx/main.c
>> @@ -52,6 +52,45 @@ static void vfio_cdx_close_device(struct vfio_device *core_vdev)
>> cdx_dev_reset(core_vdev->dev);
>> }
>>
>> +static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags,
>> + void __user *arg, size_t argsz)
>> +{
>> + size_t minsz =
>> + offsetofend(struct vfio_device_feature_bus_master, op);
>> + struct cdx_device *cdx_dev = to_cdx_device(core_vdev->dev);
>> + struct vfio_device_feature_bus_master ops;
>> + int ret;
>> +
>> + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET,
>> + sizeof(ops));
>> + if (ret != 1)
>> + return ret;
>> +
>> + if (copy_from_user(&ops, arg, minsz))
>> + return -EFAULT;
>> +
>> + switch (ops.op) {
>> + case VFIO_DEVICE_FEATURE_CLEAR_MASTER:
>> + cdx_clear_master(cdx_dev);
>> + return 0;
>> + case VFIO_DEVICE_FEATURE_SET_MASTER:
>> + return cdx_set_master(cdx_dev);
>
> It's curious that the implementation of set and clear in CDX call
> through to functions with non-void returns, but we simply ignore the
> return in cdx_clear_master(). Does something prevent clear from
> failing?
Would update cdx_clear_master() with non-void return.
>
> I also note internally that true is used for enabling and false for
> disabling, which is effectively opposite of the proposed uAPI in the
> previous patch.
Yes, will fix in the uAPI.
>
> If the idea here is that the user should assume bus master is disabled
> when opening the device, what happens if the user closes the device
> with bus master enabled? What would cleanup that state for the next
> user?
cdx_dev_reset() clears the bus mastering and user would enable bus
mastering once ready for DMA. Probably we also need to add reset in
device open. So user should assume that bus master is disabled when
opening the device, and close would also clear the bus mastering (by
calling reset).
>
> Is there a use case for the GET operation in userspace?
There is no use-case for get operation in CDX as of now.
Thanks,
Nipun
> Thanks,
>
> Alex
>
>> + default:
>> + return -EINVAL;
>> + }
>> +}
>> +
>> +static int vfio_cdx_ioctl_feature(struct vfio_device *device, u32 flags,
>> + void __user *arg, size_t argsz)
>> +{
>> + switch (flags & VFIO_DEVICE_FEATURE_MASK) {
>> + case VFIO_DEVICE_FEATURE_BUS_MASTER:
>> + return vfio_cdx_bm_ctrl(device, flags, arg, argsz);
>> + default:
>> + return -ENOTTY;
>> + }
>> +}
>> +
>> static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev,
>> struct vfio_device_info __user *arg)
>> {
>> @@ -169,6 +208,7 @@ static const struct vfio_device_ops vfio_cdx_ops = {
>> .open_device = vfio_cdx_open_device,
>> .close_device = vfio_cdx_close_device,
>> .ioctl = vfio_cdx_ioctl,
>> + .device_feature = vfio_cdx_ioctl_feature,
>> .mmap = vfio_cdx_mmap,
>> .bind_iommufd = vfio_iommufd_physical_bind,
>> .unbind_iommufd = vfio_iommufd_physical_unbind,
>
prev parent reply other threads:[~2023-08-08 16:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 14:32 [PATCH v5 1/3] cdx: add support for bus mastering Nipun Gupta
2023-08-03 14:32 ` [PATCH v5 2/3] vfio: add bus master feature to device feature ioctl Nipun Gupta
2023-08-03 22:00 ` Alex Williamson
2023-08-08 10:39 ` Gupta, Nipun
2023-08-03 14:32 ` [PATCH v5 3/3] vfio-cdx: add bus mastering device feature support Nipun Gupta
2023-08-03 22:17 ` Alex Williamson
2023-08-08 10:49 ` Gupta, Nipun [this message]
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=3921846a-5560-44fd-c4ce-329acad454c0@amd.com \
--to=nipun.gupta@amd.com \
--cc=abhijit.gangurde@amd.com \
--cc=alex.williamson@redhat.com \
--cc=git@amd.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=nikhil.agarwal@amd.com \
--cc=pieter.jansen-van-vuuren@amd.com \
--cc=shubham.rohila@amd.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®