From: Jason Gunthorpe <jgg@nvidia.com>
To: Yi Liu <yi.l.liu@intel.com>
Cc: joro@8bytes.org, alex.williamson@redhat.com,
kevin.tian@intel.com, robin.murphy@arm.com,
baolu.lu@linux.intel.com, cohuck@redhat.com,
eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org,
mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com,
yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com,
shameerali.kolothum.thodi@huawei.com, lulu@redhat.com,
suravee.suthikulpanit@amd.com, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
zhenzhong.duan@intel.com
Subject: Re: [PATCH v3 08/17] iommufd: IOMMU_HWPT_ALLOC allocation with user data
Date: Fri, 28 Jul 2023 14:55:57 -0300 [thread overview]
Message-ID: <ZMQBLTm+U+5bgC/Z@nvidia.com> (raw)
In-Reply-To: <20230724110406.107212-9-yi.l.liu@intel.com>
On Mon, Jul 24, 2023 at 04:03:57AM -0700, Yi Liu wrote:
> + switch (pt_obj->type) {
> + case IOMMUFD_OBJ_IOAS:
> + ioas = container_of(pt_obj, struct iommufd_ioas, obj);
> + break;
> + case IOMMUFD_OBJ_HW_PAGETABLE:
> + /* pt_id points HWPT only when hwpt_type is !IOMMU_HWPT_TYPE_DEFAULT */
> + if (cmd->hwpt_type == IOMMU_HWPT_TYPE_DEFAULT) {
> + rc = -EINVAL;
> + goto out_put_pt;
> + }
> +
> + parent = container_of(pt_obj, struct iommufd_hw_pagetable, obj);
> + /*
> + * Cannot allocate user-managed hwpt linking to auto_created
> + * hwpt. If the parent hwpt is already a user-managed hwpt,
> + * don't allocate another user-managed hwpt linking to it.
> + */
> + if (parent->auto_domain || parent->parent) {
> + rc = -EINVAL;
> + goto out_put_pt;
> + }
> + ioas = parent->ioas;
Why do we set ioas here? I would think it should be NULL.
I think it is looking like a mistake to try and re-use
iommufd_hw_pagetable_alloc() directly for the nested case. It should
not have a IOAS argument, it should not do enforce_cc, or iopt_*
functions
So must of the function is removed. Probably better to make a new
ioas-less function for the nesting case.
> diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
> index 510db114fc61..5f4420626421 100644
> --- a/drivers/iommu/iommufd/main.c
> +++ b/drivers/iommu/iommufd/main.c
> @@ -426,7 +426,7 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = {
> IOCTL_OP(IOMMU_GET_HW_INFO, iommufd_get_hw_info, struct iommu_hw_info,
> __reserved),
> IOCTL_OP(IOMMU_HWPT_ALLOC, iommufd_hwpt_alloc, struct iommu_hwpt_alloc,
> - __reserved),
> + data_uptr),
Nono, these can never change once we put them it. It specifies the
hard minimum size that userspace must provide. If userspace gives less
than this then the ioctl always fails. Changing it breaks all the
existing software.
The core code ensures that the trailing part of the cmd struct is
zero'd the extended implementation must cope with Zero'd values, which
this does.
> diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
> index f2026cde2d64..73bf9af91e99 100644
> --- a/include/uapi/linux/iommufd.h
> +++ b/include/uapi/linux/iommufd.h
> @@ -364,12 +364,27 @@ enum iommu_hwpt_type {
> * @pt_id: The IOAS to connect this HWPT to
> * @out_hwpt_id: The ID of the new HWPT
> * @__reserved: Must be 0
> + * @hwpt_type: One of enum iommu_hwpt_type
> + * @data_len: Length of the type specific data
> + * @data_uptr: User pointer to the type specific data
> *
> * Explicitly allocate a hardware page table object. This is the same object
> * type that is returned by iommufd_device_attach() and represents the
> * underlying iommu driver's iommu_domain kernel object.
> *
> - * A HWPT will be created with the IOVA mappings from the given IOAS.
> + * A kernel-managed HWPT will be created with the mappings from the given
> + * IOAS via the @pt_id. The @hwpt_type for this allocation can be set to
> + * either IOMMU_HWPT_TYPE_DEFAULT or a pre-defined type corresponding to
> + * an I/O page table type supported by the underlying IOMMU hardware.
> + * A user-managed HWPT will be created from a given parent HWPT via the
> + * @pt_id, in which the parent HWPT must be allocated previously via the
> + * same ioctl from a given IOAS (@pt_id). In this case, the @hwpt_type
> + * must be set to a pre-defined type corresponding to an I/O page table
> + * type supported by the underlying IOMMU hardware.
> + *
> + * If the @hwpt_type is set to IOMMU_HWPT_TYPE_DEFAULT, both the @data_len
> + * and the @data_uptr will be ignored. Otherwise, both must be
> given.
If the @hwpt_type is set to IOMMU_HWPT_TYPE_DEFAULT then @data_len
must be zero.
Jason
next prev parent reply other threads:[~2023-07-28 17:56 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 11:03 [PATCH v3 00/17] iommufd: Add nesting infrastructure Yi Liu
2023-07-24 11:03 ` [PATCH v3 01/17] iommu: Add new iommu op to create domains owned by userspace Yi Liu
2023-07-28 9:37 ` Tian, Kevin
2023-07-28 16:56 ` Jason Gunthorpe
2023-07-31 12:44 ` Liu, Yi L
2023-07-31 13:19 ` Jason Gunthorpe
2023-08-03 2:28 ` Nicolin Chen
2023-07-24 11:03 ` [PATCH v3 02/17] iommu: Add nested domain support Yi Liu
2023-07-28 9:38 ` Tian, Kevin
2023-07-28 16:59 ` Jason Gunthorpe
2023-08-03 2:36 ` Nicolin Chen
2023-08-03 2:53 ` Liu, Yi L
2023-08-03 3:04 ` Nicolin Chen
2023-07-24 11:03 ` [PATCH v3 03/17] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Yi Liu
2023-07-28 9:39 ` Tian, Kevin
2023-07-24 11:03 ` [PATCH v3 04/17] iommufd: Pass in hwpt_type/parent/user_data to iommufd_hw_pagetable_alloc() Yi Liu
2023-07-28 9:49 ` Tian, Kevin
2023-07-24 11:03 ` [PATCH v3 05/17] iommufd/hw_pagetable: Do not populate user-managed hw_pagetables Yi Liu
2023-07-28 9:51 ` Tian, Kevin
2023-07-24 11:03 ` [PATCH v3 06/17] iommufd: Only enforce IOMMU_RESV_SW_MSI when attaching user-managed HWPT Yi Liu
2023-07-28 10:02 ` Tian, Kevin
2023-07-28 17:06 ` Jason Gunthorpe
2023-07-24 11:03 ` [PATCH v3 07/17] iommufd: Add IOMMU_RESV_IOVA_RANGES Yi Liu
2023-07-28 10:07 ` Tian, Kevin
2023-07-28 17:16 ` Jason Gunthorpe
2023-07-31 6:14 ` Tian, Kevin
2023-07-31 13:12 ` Jason Gunthorpe
2023-07-28 17:44 ` Jason Gunthorpe
2023-07-31 6:21 ` Tian, Kevin
2023-07-31 9:53 ` Liu, Yi L
2023-07-31 13:23 ` Jason Gunthorpe
2023-08-01 2:40 ` Tian, Kevin
2023-08-01 18:22 ` Jason Gunthorpe
2023-08-02 1:09 ` Tian, Kevin
2023-08-02 12:22 ` Jason Gunthorpe
2023-08-03 1:23 ` Nicolin Chen
2023-08-03 1:25 ` Tian, Kevin
2023-08-03 2:17 ` Nicolin Chen
2023-07-24 11:03 ` [PATCH v3 08/17] iommufd: IOMMU_HWPT_ALLOC allocation with user data Yi Liu
2023-07-28 17:55 ` Jason Gunthorpe [this message]
2023-07-28 19:10 ` Nicolin Chen
2023-07-31 7:22 ` Liu, Yi L
2023-07-31 6:31 ` Tian, Kevin
2023-07-31 13:16 ` Jason Gunthorpe
2023-08-01 2:35 ` Tian, Kevin
2023-08-02 23:42 ` Nicolin Chen
2023-08-02 23:43 ` Jason Gunthorpe
2023-08-03 0:53 ` Nicolin Chen
2023-08-03 16:47 ` Jason Gunthorpe
2023-07-24 11:03 ` [PATCH v3 09/17] iommufd: Add IOMMU_HWPT_INVALIDATE Yi Liu
2023-07-28 18:02 ` Jason Gunthorpe
2023-07-31 10:07 ` Liu, Yi L
2023-07-31 13:19 ` Jason Gunthorpe
2023-08-03 2:16 ` Nicolin Chen
2023-08-03 3:07 ` Liu, Yi L
2023-08-03 3:13 ` Nicolin Chen
2023-08-03 2:56 ` Liu, Yi L
2023-08-03 2:07 ` Nicolin Chen
2023-07-24 11:03 ` [PATCH v3 10/17] iommufd/selftest: Add a helper to get test device Yi Liu
2023-07-24 11:04 ` [PATCH v3 11/17] iommufd/selftest: Add IOMMU_TEST_OP_DEV_[ADD|DEL]_RESERVED to add/del reserved regions to selftest device Yi Liu
2023-07-24 11:04 ` [PATCH v3 12/17] iommufd/selftest: Add .get_resv_regions() for mock_dev Yi Liu
2023-07-24 11:04 ` [PATCH v3 13/17] iommufd/selftest: Add coverage for IOMMU_RESV_IOVA_RANGES Yi Liu
2023-07-24 11:04 ` [PATCH v3 14/17] iommufd/selftest: Add domain_alloc_user() support in iommu mock Yi Liu
2023-07-24 11:04 ` [PATCH v3 15/17] iommufd/selftest: Add coverage for IOMMU_HWPT_ALLOC with user data Yi Liu
2023-07-24 11:04 ` [PATCH v3 16/17] iommufd/selftest: Add IOMMU_TEST_OP_MD_CHECK_IOTLB test op Yi Liu
2023-07-24 11:04 ` [PATCH v3 17/17] iommufd/selftest: Add coverage for IOMMU_HWPT_INVALIDATE ioctl Yi Liu
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=ZMQBLTm+U+5bgC/Z@nvidia.com \
--to=jgg@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=chao.p.peng@linux.intel.com \
--cc=cohuck@redhat.com \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jasowang@redhat.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lulu@redhat.com \
--cc=mjrosato@linux.ibm.com \
--cc=nicolinc@nvidia.com \
--cc=peterx@redhat.com \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@linux.intel.com \
--cc=zhenzhong.duan@intel.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