Linux IOMMU Development
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>, <iommu@lists.linux.dev>,
	Kevin Tian <kevin.tian@intel.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: [PATCH] iommufd: Organize the mock domain alloc functions closer to Joerg's tree
Date: Tue, 31 Oct 2023 12:13:50 +0800	[thread overview]
Message-ID: <10a2d6ca-80a3-423c-9795-2b330fbfb558@intel.com> (raw)
In-Reply-To: <0-v1-90a855762c96+19de-mock_merge_jgg@nvidia.com>

On 2023/10/31 06:53, Jason Gunthorpe wrote:
> Patches in Joerg's iommu tree to convert the mock driver to use
> domain_alloc_paging() that clash badly with the way the selftest changes
> for nesting were structured.
> 
> Massage the selftest so that it looks closer the code after the
> domain_alloc_paging() conversion to ease the merge. Change
> __mock_domain_alloc_paging() into mock_domain_alloc_paging() in the same
> way as the iommu tree. The merge resolution then trivially takes both and
> deletes mock_domain_alloc().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/iommufd/selftest.c | 35 +++++++++++++++-----------------
>   1 file changed, 16 insertions(+), 19 deletions(-)
> 
> The merge conflict is a mess, this helps alot.
> 
> diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
> index a11d29f368ff82..d43a87737c1e88 100644
> --- a/drivers/iommu/iommufd/selftest.c
> +++ b/drivers/iommu/iommufd/selftest.c
> @@ -20,6 +20,8 @@
>   static DECLARE_FAULT_ATTR(fail_iommufd);
>   static struct dentry *dbgfs_root;
>   static struct platform_device *selftest_iommu_dev;
> +static const struct iommu_ops mock_ops;
> +static struct iommu_domain_ops domain_nested_ops;
>   
>   size_t iommufd_test_memory_limit = 65536;
>   
> @@ -222,24 +224,18 @@ const struct iommu_dirty_ops dirty_ops = {
>   	.read_and_clear_dirty = mock_domain_read_and_clear_dirty,
>   };
>   
> -static const struct iommu_ops mock_ops;
> -static struct iommu_domain_ops domain_nested_ops;
> -
> -static struct iommu_domain *
> -__mock_domain_alloc_paging(unsigned int iommu_domain_type, bool needs_dirty_ops)
> +static struct iommu_domain *mock_domain_alloc_paging(struct device *dev)
>   {
>   	struct mock_iommu_domain *mock;
>   
>   	mock = kzalloc(sizeof(*mock), GFP_KERNEL);
>   	if (!mock)
> -		return ERR_PTR(-ENOMEM);
> +		return NULL;
>   	mock->domain.geometry.aperture_start = MOCK_APERTURE_START;
>   	mock->domain.geometry.aperture_end = MOCK_APERTURE_LAST;
>   	mock->domain.pgsize_bitmap = MOCK_IO_PAGE_SIZE;
>   	mock->domain.ops = mock_ops.default_domain_ops;
> -	if (needs_dirty_ops)
> -		mock->domain.dirty_ops = &dirty_ops;
> -	mock->domain.type = iommu_domain_type;
> +	mock->domain.type = IOMMU_DOMAIN_UNMANAGED;
>   	xa_init(&mock->pfns);
>   	return &mock->domain;
>   }
> @@ -264,16 +260,11 @@ __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent,
>   
>   static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
>   {
> -	struct iommu_domain *domain;
> -
>   	if (iommu_domain_type == IOMMU_DOMAIN_BLOCKED)
>   		return &mock_blocking_domain;
> -	if (iommu_domain_type != IOMMU_DOMAIN_UNMANAGED)
> -		return NULL;
> -	domain = __mock_domain_alloc_paging(iommu_domain_type, false);
> -	if (IS_ERR(domain))
> -		domain = NULL;
> -	return domain;
> +	if (iommu_domain_type == IOMMU_DOMAIN_UNMANAGED)
> +		return mock_domain_alloc_paging(NULL);
> +	return NULL;

a nit, will success oriented better suit here? if otherwise looks good to me.

Reviewed-by: Yi Liu <yi.l.liu@intel.com>

>   }
>   
>   static struct iommu_domain *
> @@ -290,14 +281,20 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
>   		struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
>   		bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
>   		bool no_dirty_ops = mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY;
> +		struct iommu_domain *domain;
>   
>   		if (flags & (~(IOMMU_HWPT_ALLOC_NEST_PARENT |
>   			       IOMMU_HWPT_ALLOC_DIRTY_TRACKING)))
>   			return ERR_PTR(-EOPNOTSUPP);
>   		if (user_data || (has_dirty_flag && no_dirty_ops))
>   			return ERR_PTR(-EOPNOTSUPP);
> -		return __mock_domain_alloc_paging(IOMMU_DOMAIN_UNMANAGED,
> -						  has_dirty_flag);
> +		domain = mock_domain_alloc_paging(NULL);
> +		if (!domain)
> +			return ERR_PTR(-ENOMEM);
> +		if (has_dirty_flag)
> +			container_of(domain, struct mock_iommu_domain, domain)
> +				->domain.dirty_ops = &dirty_ops;
> +		return domain;
>   	}
>   
>   	/* must be mock_domain_nested */
> 
> base-commit: 2e22aac3ea9cfc0ec3209c96644f60c1806a8117

-- 
Regards,
Yi Liu

  parent reply	other threads:[~2023-10-31  4:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-30 22:53 [PATCH] iommufd: Organize the mock domain alloc functions closer to Joerg's tree Jason Gunthorpe
2023-10-31  0:26 ` Nicolin Chen
2023-10-31  2:14 ` Tian, Kevin
2023-10-31  4:13 ` Yi Liu [this message]
2023-10-31 11:30   ` Jason Gunthorpe

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=10a2d6ca-80a3-423c-9795-2b330fbfb558@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=nicolinc@nvidia.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