From: Mostafa Saleh <smostafa@google.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
Cc: kvm@vger.kernel.org, Suzuki K Poulose <Suzuki.Poulose@arm.com>,
Steven Price <steven.price@arm.com>,
Will Deacon <will@kernel.org>,
Julien Thierry <julien.thierry.kdev@gmail.com>
Subject: Re: [RFC PATCH kvmtool 08/10] vfio/iommufd: Move the hwpt allocation to helper
Date: Sun, 27 Jul 2025 18:32:48 +0000 [thread overview]
Message-ID: <aIZw0DnAniP5G6KG@google.com> (raw)
In-Reply-To: <20250525074917.150332-8-aneesh.kumar@kernel.org>
On Sun, May 25, 2025 at 01:19:14PM +0530, Aneesh Kumar K.V (Arm) wrote:
> alloc_hwpt.flags = 0; implies we prefer stage1 translation. Hence name
> the helper iommufd_alloc_s2bypass_hwpt().
This patch moves the recently added code into a new function,
can't this be squashed?
Also, I believe that with “IOMMU_HWPT_DATA_NONE”, we shouldn’t make
any assumptions in userspace about which stage is used.
The only guarantee is that IOMMU_IOAS_MAP/IOMMU_IOAS_UNMAP works.
So, I believe the naming for "s2bypass" is not accurate.
>
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> ---
> vfio/iommufd.c | 86 +++++++++++++++++++++++++++++---------------------
> 1 file changed, 50 insertions(+), 36 deletions(-)
>
> diff --git a/vfio/iommufd.c b/vfio/iommufd.c
> index 3728a06cb318..742550705746 100644
> --- a/vfio/iommufd.c
> +++ b/vfio/iommufd.c
> @@ -60,6 +60,54 @@ err_close_device:
> return ret;
> }
>
> +static int iommufd_alloc_s2bypass_hwpt(struct vfio_device *vdev)
> +{
> + int ret;
> + struct iommu_hwpt_alloc alloc_hwpt;
> + struct vfio_device_bind_iommufd bind;
> + struct vfio_device_attach_iommufd_pt attach_data;
> +
> + bind.argsz = sizeof(bind);
> + bind.flags = 0;
> + bind.iommufd = iommu_fd;
> +
> + /* now bind the iommufd */
> + if (ioctl(vdev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) {
> + ret = -errno;
> + vfio_dev_err(vdev, "failed to get info");
> + goto err_out;
> + }
> +
> + alloc_hwpt.size = sizeof(struct iommu_hwpt_alloc);
> + /* stage1 translate stage 2 bypass table if stage1 is supported */
> + alloc_hwpt.flags = 0;
> + alloc_hwpt.dev_id = bind.out_devid;
> + alloc_hwpt.pt_id = ioas_id;
> + alloc_hwpt.data_type = IOMMU_HWPT_DATA_NONE;
> + alloc_hwpt.data_len = 0;
> + alloc_hwpt.data_uptr = 0;
> +
> + if (ioctl(iommu_fd, IOMMU_HWPT_ALLOC, &alloc_hwpt)) {
> + ret = -errno;
> + pr_err("Failed to allocate HWPT");
> + goto err_out;
> + }
> +
> + attach_data.argsz = sizeof(attach_data);
> + attach_data.flags = 0;
> + attach_data.pt_id = alloc_hwpt.out_hwpt_id;
> +
> + if (ioctl(vdev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data)) {
> + ret = -errno;
> + vfio_dev_err(vdev, "failed to attach to IOAS ");
> + goto err_out;
> + }
> + return 0;
> +
> +err_out:
> + return ret;
> +}
> +
> static int iommufd_configure_device(struct kvm *kvm, struct vfio_device *vdev)
> {
> int ret;
> @@ -68,9 +116,6 @@ static int iommufd_configure_device(struct kvm *kvm, struct vfio_device *vdev)
> bool found_dev = false;
> char pci_dev_path[PATH_MAX];
> char vfio_dev_path[PATH_MAX];
> - struct iommu_hwpt_alloc alloc_hwpt;
> - struct vfio_device_bind_iommufd bind;
> - struct vfio_device_attach_iommufd_pt attach_data;
>
> ret = snprintf(pci_dev_path, PATH_MAX, "%s/vfio-dev/", vdev->sysfs_path);
> if (ret < 0 || ret == PATH_MAX)
> @@ -115,40 +160,9 @@ static int iommufd_configure_device(struct kvm *kvm, struct vfio_device *vdev)
> goto err_close_device;
> }
>
> - bind.argsz = sizeof(bind);
> - bind.flags = 0;
> - bind.iommufd = iommu_fd;
> -
> - /* now bind the iommufd */
> - if (ioctl(vdev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) {
> - ret = -errno;
> - vfio_dev_err(vdev, "failed to get info");
> - goto err_close_device;
> - }
> -
> - alloc_hwpt.size = sizeof(struct iommu_hwpt_alloc);
> - alloc_hwpt.flags = 0;
> - alloc_hwpt.dev_id = bind.out_devid;
> - alloc_hwpt.pt_id = ioas_id;
> - alloc_hwpt.data_type = IOMMU_HWPT_DATA_NONE;
> - alloc_hwpt.data_len = 0;
> - alloc_hwpt.data_uptr = 0;
> -
> - if (ioctl(iommu_fd, IOMMU_HWPT_ALLOC, &alloc_hwpt)) {
> - ret = -errno;
> - pr_err("Failed to allocate HWPT");
> - goto err_close_device;
> - }
> -
> - attach_data.argsz = sizeof(attach_data);
> - attach_data.flags = 0;
> - attach_data.pt_id = alloc_hwpt.out_hwpt_id;
> -
> - if (ioctl(vdev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data)) {
> - ret = -errno;
> - vfio_dev_err(vdev, "failed to attach to IOAS ");
> + ret = iommufd_alloc_s2bypass_hwpt(vdev);
> + if (ret)
> goto err_close_device;
> - }
>
> closedir(dir);
> return __iommufd_configure_device(kvm, vdev);
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-07-27 18:32 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-25 7:49 [RFC PATCH kvmtool 01/10] vfio: Associate vm instance with vfio fd Aneesh Kumar K.V (Arm)
2025-05-25 7:49 ` [RFC PATCH kvmtool 02/10] vfio: Rename some functions Aneesh Kumar K.V (Arm)
2025-07-27 18:20 ` Mostafa Saleh
2025-07-29 4:53 ` Aneesh Kumar K.V
2025-05-25 7:49 ` [RFC PATCH kvmtool 03/10] vfio: Create new file legacy.c Aneesh Kumar K.V (Arm)
2025-07-27 18:23 ` Mostafa Saleh
2025-07-29 4:59 ` Aneesh Kumar K.V
2025-05-25 7:49 ` [RFC PATCH kvmtool 04/10] vfio: Update vfio header from linux kernel Aneesh Kumar K.V (Arm)
2025-07-27 18:23 ` Mostafa Saleh
2025-05-25 7:49 ` [RFC PATCH kvmtool 05/10] vfio: Add dma map/unmap handlers Aneesh Kumar K.V (Arm)
2025-07-27 18:25 ` Mostafa Saleh
2025-07-29 5:03 ` Aneesh Kumar K.V
2025-05-25 7:49 ` [RFC PATCH kvmtool 06/10] vfio/iommufd: Import iommufd header from kernel Aneesh Kumar K.V (Arm)
2025-07-27 18:25 ` Mostafa Saleh
2025-05-25 7:49 ` [RFC PATCH kvmtool 07/10] vfio/iommufd: Add basic iommufd support Aneesh Kumar K.V (Arm)
2025-07-27 18:31 ` Mostafa Saleh
2025-07-29 5:12 ` Aneesh Kumar K.V
2025-07-29 9:38 ` Mostafa Saleh
2025-05-25 7:49 ` [RFC PATCH kvmtool 08/10] vfio/iommufd: Move the hwpt allocation to helper Aneesh Kumar K.V (Arm)
2025-07-27 18:32 ` Mostafa Saleh [this message]
2025-07-29 5:14 ` Aneesh Kumar K.V
2025-07-29 9:43 ` Mostafa Saleh
2025-05-25 7:49 ` [RFC PATCH kvmtool 09/10] vfio/iommufd: Add viommu and vdevice objects Aneesh Kumar K.V (Arm)
2025-07-21 12:27 ` Will Deacon
2025-07-24 14:09 ` Aneesh Kumar K.V
2025-08-04 22:33 ` Suzuki K Poulose
2025-08-08 13:00 ` Will Deacon
2025-08-11 6:16 ` Aneesh Kumar K.V
2025-07-27 18:35 ` Mostafa Saleh
2025-07-29 5:19 ` Aneesh Kumar K.V
2025-07-29 9:41 ` Mostafa Saleh
2025-07-30 8:13 ` Aneesh Kumar K.V
2025-07-30 14:15 ` Mostafa Saleh
2025-07-31 4:39 ` Aneesh Kumar K.V
2025-08-04 15:07 ` Mostafa Saleh
2025-05-25 7:49 ` [RFC PATCH kvmtool 10/10] util/update_headers: Add vfio related header files to update list Aneesh Kumar K.V (Arm)
2025-07-27 18:35 ` Mostafa Saleh
2025-07-27 18:19 ` [RFC PATCH kvmtool 01/10] vfio: Associate vm instance with vfio fd Mostafa Saleh
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=aIZw0DnAniP5G6KG@google.com \
--to=smostafa@google.com \
--cc=Suzuki.Poulose@arm.com \
--cc=aneesh.kumar@kernel.org \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=steven.price@arm.com \
--cc=will@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).