2023-10-27 04:55:54

by Stephen Rothwell

[permalink] [raw]
Subject: linux-next: manual merge of the iommufd tree with the iommu tree

Hi all,

Today's linux-next merge of the iommufd tree got a conflict in:

drivers/iommu/iommufd/selftest.c

between commits:

1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
13fbceb1b8e9 ("iommufd: Convert to alloc_domain_paging()")

from the iommu tree and commits:

408663619fcf ("iommufd/selftest: Add domain_alloc_user() support in iommu mock")
266ce58989ba ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING")
7adf267d66d1 ("iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING")
a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
0795b305da89 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag")
65fe32f7a447 ("iommufd/selftest: Add nested domain allocation for mock domain")

from the iommufd tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging. You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

--
Cheers,
Stephen Rothwell

diff --cc drivers/iommu/iommufd/selftest.c
index ee6079847091,6684ab4cdc7a..000000000000
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@@ -272,9 -435,28 +430,20 @@@ static phys_addr_t mock_domain_iova_to_

static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
{
- return cap == IOMMU_CAP_CACHE_COHERENCY;
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+
+ switch (cap) {
+ case IOMMU_CAP_CACHE_COHERENCY:
+ return true;
+ case IOMMU_CAP_DIRTY_TRACKING:
+ return !(mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY);
+ default:
+ break;
+ }
+
+ return false;
}

-static void mock_domain_set_plaform_dma_ops(struct device *dev)
-{
- /*
- * mock doesn't setup default domains because we can't hook into the
- * normal probe path
- */
-}
-
static struct iommu_device mock_iommu_device = {
};

@@@ -293,8 -469,10 +462,9 @@@ static const struct iommu_ops mock_ops
.owner = THIS_MODULE,
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
.hw_info = mock_domain_hw_info,
- .domain_alloc = mock_domain_alloc,
+ .domain_alloc_paging = mock_domain_alloc_paging,
+ .domain_alloc_user = mock_domain_alloc_user,
.capable = mock_domain_capable,
- .set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
.device_group = generic_device_group,
.probe_device = mock_probe_device,
.default_domain_ops =


Attachments:
(No filename) (499.00 B)
OpenPGP digital signature

2023-10-27 06:15:56

by Stephen Rothwell

[permalink] [raw]
Subject: Re: linux-next: manual merge of the iommufd tree with the iommu tree

Hi all,

On Fri, 27 Oct 2023 15:55:22 +1100 Stephen Rothwell <[email protected]> wrote:
>
> Today's linux-next merge of the iommufd tree got a conflict in:
>
> drivers/iommu/iommufd/selftest.c
>
> between commits:
>
> 1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
> 13fbceb1b8e9 ("iommufd: Convert to alloc_domain_paging()")
>
> from the iommu tree and commits:
>
> 408663619fcf ("iommufd/selftest: Add domain_alloc_user() support in iommu mock")
> 266ce58989ba ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING")
> 7adf267d66d1 ("iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING")
> a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
> 0795b305da89 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag")
> 65fe32f7a447 ("iommufd/selftest: Add nested domain allocation for mock domain")
>
> from the iommufd tree.
>
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging. You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.

The resolution should have been as below (I think).

--
Cheers,
Stephen Rothwell

diff --cc drivers/iommu/iommufd/selftest.c
index ee6079847091,6684ab4cdc7a..7d28ff9a278e
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@@ -155,6 -244,80 +239,76 @@@ __mock_domain_alloc_paging(unsigned in
return &mock->domain;
}

+ static struct iommu_domain *
+ __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent,
+ const struct iommu_hwpt_selftest *user_cfg)
+ {
+ struct mock_iommu_domain_nested *mock_nested;
+ int i;
+
+ mock_nested = kzalloc(sizeof(*mock_nested), GFP_KERNEL);
+ if (!mock_nested)
+ return ERR_PTR(-ENOMEM);
+ mock_nested->parent = mock_parent;
+ mock_nested->domain.ops = &domain_nested_ops;
+ mock_nested->domain.type = IOMMU_DOMAIN_NESTED;
+ for (i = 0; i < MOCK_NESTED_DOMAIN_IOTLB_NUM; i++)
+ mock_nested->iotlb[i] = user_cfg->iotlb;
+ return &mock_nested->domain;
+ }
+
-static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
++static struct iommu_domain *mock_domain_alloc_paging(struct device *dev)
+ {
+ 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);
++ domain = __mock_domain_alloc_paging(IOMMU_DOMAIN_UNMANAGED, false);
+ if (IS_ERR(domain))
+ domain = NULL;
+ return domain;
+ }
+
+ static struct iommu_domain *
+ mock_domain_alloc_user(struct device *dev, u32 flags,
+ struct iommu_domain *parent,
+ const struct iommu_user_data *user_data)
+ {
+ struct mock_iommu_domain *mock_parent;
+ struct iommu_hwpt_selftest user_cfg;
+ int rc;
+
+ /* must be mock_domain */
+ if (!parent) {
+ 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;
+
+ 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);
+ }
+
+ /* must be mock_domain_nested */
+ if (user_data->type != IOMMU_HWPT_DATA_SELFTEST || flags)
+ return ERR_PTR(-EOPNOTSUPP);
+ if (!parent || parent->ops != mock_ops.default_domain_ops)
+ return ERR_PTR(-EINVAL);
+
+ mock_parent = container_of(parent, struct mock_iommu_domain, domain);
+ if (!mock_parent)
+ return ERR_PTR(-EINVAL);
+
+ rc = iommu_copy_struct_from_user(&user_cfg, user_data,
+ IOMMU_HWPT_DATA_SELFTEST, iotlb);
+ if (rc)
+ return ERR_PTR(rc);
+
+ return __mock_domain_alloc_nested(mock_parent, &user_cfg);
+ }
+
static void mock_domain_free(struct iommu_domain *domain)
{
struct mock_iommu_domain *mock =
@@@ -272,9 -435,28 +426,20 @@@ static phys_addr_t mock_domain_iova_to_

static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
{
- return cap == IOMMU_CAP_CACHE_COHERENCY;
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+
+ switch (cap) {
+ case IOMMU_CAP_CACHE_COHERENCY:
+ return true;
+ case IOMMU_CAP_DIRTY_TRACKING:
+ return !(mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY);
+ default:
+ break;
+ }
+
+ return false;
}

-static void mock_domain_set_plaform_dma_ops(struct device *dev)
-{
- /*
- * mock doesn't setup default domains because we can't hook into the
- * normal probe path
- */
-}
-
static struct iommu_device mock_iommu_device = {
};

@@@ -293,8 -469,10 +458,9 @@@ static const struct iommu_ops mock_ops
.owner = THIS_MODULE,
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
.hw_info = mock_domain_hw_info,
- .domain_alloc = mock_domain_alloc,
+ .domain_alloc_paging = mock_domain_alloc_paging,
+ .domain_alloc_user = mock_domain_alloc_user,
.capable = mock_domain_capable,
- .set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
.device_group = generic_device_group,
.probe_device = mock_probe_device,
.default_domain_ops =


Attachments:
(No filename) (499.00 B)
OpenPGP digital signature

2023-10-30 18:26:54

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: linux-next: manual merge of the iommufd tree with the iommu tree

On Fri, Oct 27, 2023 at 05:15:22PM +1100, Stephen Rothwell wrote:
> Hi all,
>
> On Fri, 27 Oct 2023 15:55:22 +1100 Stephen Rothwell <[email protected]> wrote:
> >
> > Today's linux-next merge of the iommufd tree got a conflict in:
> >
> > drivers/iommu/iommufd/selftest.c
> >
> > between commits:
> >
> > 1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
> > 13fbceb1b8e9 ("iommufd: Convert to alloc_domain_paging()")
> >
> > from the iommu tree and commits:
> >
> > 408663619fcf ("iommufd/selftest: Add domain_alloc_user() support in iommu mock")
> > 266ce58989ba ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING")
> > 7adf267d66d1 ("iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING")
> > a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
> > 0795b305da89 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag")
> > 65fe32f7a447 ("iommufd/selftest: Add nested domain allocation for mock domain")
> >
> > from the iommufd tree.
> >
> > I fixed it up (see below) and can carry the fix as necessary. This
> > is now fixed as far as linux-next is concerned, but any non trivial
> > conflicts should be mentioned to your upstream maintainer when your tree
> > is submitted for merging. You may also want to consider cooperating
> > with the maintainer of the conflicting tree to minimise any particularly
> > complex conflicts.
>
> The resolution should have been as below (I think).

This was too horrible, I pushed a patch to reorganize the new iommufd side
code to more closely match how the domain_alloc_paging stuff is
supposed to work

Thanks,
Jason

2023-10-31 05:12:59

by Stephen Rothwell

[permalink] [raw]
Subject: Re: linux-next: manual merge of the iommufd tree with the iommu tree

Hi all,

On Mon, 30 Oct 2023 15:26:21 -0300 Jason Gunthorpe <[email protected]> wrote:
>
> On Fri, Oct 27, 2023 at 05:15:22PM +1100, Stephen Rothwell wrote:
> >
> > On Fri, 27 Oct 2023 15:55:22 +1100 Stephen Rothwell <[email protected]> wrote:
> > >
> > > Today's linux-next merge of the iommufd tree got a conflict in:
> > >
> > > drivers/iommu/iommufd/selftest.c
> > >
> > > between commits:
> > >
> > > 1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
> > > 13fbceb1b8e9 ("iommufd: Convert to alloc_domain_paging()")
> > >
> > > from the iommu tree and commits:
> > >
> > > 408663619fcf ("iommufd/selftest: Add domain_alloc_user() support in iommu mock")
> > > 266ce58989ba ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING")
> > > 7adf267d66d1 ("iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING")
> > > a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
> > > 0795b305da89 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag")
> > > 65fe32f7a447 ("iommufd/selftest: Add nested domain allocation for mock domain")
> > >
> > > from the iommufd tree.
> > >
> > > I fixed it up (see below) and can carry the fix as necessary. This
> > > is now fixed as far as linux-next is concerned, but any non trivial
> > > conflicts should be mentioned to your upstream maintainer when your tree
> > > is submitted for merging. You may also want to consider cooperating
> > > with the maintainer of the conflicting tree to minimise any particularly
> > > complex conflicts.
> >
> > The resolution should have been as below (I think).
>
> This was too horrible, I pushed a patch to reorganize the new iommufd side
> code to more closely match how the domain_alloc_paging stuff is
> supposed to work

I have used the conflict resolution below now.

--
Cheers,
Stephen Rothwell

diff --cc drivers/iommu/iommufd/selftest.c
index ee6079847091,d43a87737c1e..5d93434003d8
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@@ -155,6 -240,81 +235,72 @@@ static struct iommu_domain *mock_domain
return &mock->domain;
}

+ static struct iommu_domain *
+ __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent,
+ const struct iommu_hwpt_selftest *user_cfg)
+ {
+ struct mock_iommu_domain_nested *mock_nested;
+ int i;
+
+ mock_nested = kzalloc(sizeof(*mock_nested), GFP_KERNEL);
+ if (!mock_nested)
+ return ERR_PTR(-ENOMEM);
+ mock_nested->parent = mock_parent;
+ mock_nested->domain.ops = &domain_nested_ops;
+ mock_nested->domain.type = IOMMU_DOMAIN_NESTED;
+ for (i = 0; i < MOCK_NESTED_DOMAIN_IOTLB_NUM; i++)
+ mock_nested->iotlb[i] = user_cfg->iotlb;
+ return &mock_nested->domain;
+ }
+
-static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
-{
- if (iommu_domain_type == IOMMU_DOMAIN_BLOCKED)
- return &mock_blocking_domain;
- if (iommu_domain_type == IOMMU_DOMAIN_UNMANAGED)
- return mock_domain_alloc_paging(NULL);
- return NULL;
-}
-
+ static struct iommu_domain *
+ mock_domain_alloc_user(struct device *dev, u32 flags,
+ struct iommu_domain *parent,
+ const struct iommu_user_data *user_data)
+ {
+ struct mock_iommu_domain *mock_parent;
+ struct iommu_hwpt_selftest user_cfg;
+ int rc;
+
+ /* must be mock_domain */
+ if (!parent) {
+ 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);
+ 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 */
+ if (user_data->type != IOMMU_HWPT_DATA_SELFTEST || flags)
+ return ERR_PTR(-EOPNOTSUPP);
+ if (!parent || parent->ops != mock_ops.default_domain_ops)
+ return ERR_PTR(-EINVAL);
+
+ mock_parent = container_of(parent, struct mock_iommu_domain, domain);
+ if (!mock_parent)
+ return ERR_PTR(-EINVAL);
+
+ rc = iommu_copy_struct_from_user(&user_cfg, user_data,
+ IOMMU_HWPT_DATA_SELFTEST, iotlb);
+ if (rc)
+ return ERR_PTR(rc);
+
+ return __mock_domain_alloc_nested(mock_parent, &user_cfg);
+ }
+
static void mock_domain_free(struct iommu_domain *domain)
{
struct mock_iommu_domain *mock =
@@@ -272,9 -432,28 +418,20 @@@ static phys_addr_t mock_domain_iova_to_

static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
{
- return cap == IOMMU_CAP_CACHE_COHERENCY;
+ struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
+
+ switch (cap) {
+ case IOMMU_CAP_CACHE_COHERENCY:
+ return true;
+ case IOMMU_CAP_DIRTY_TRACKING:
+ return !(mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY);
+ default:
+ break;
+ }
+
+ return false;
}

-static void mock_domain_set_plaform_dma_ops(struct device *dev)
-{
- /*
- * mock doesn't setup default domains because we can't hook into the
- * normal probe path
- */
-}
-
static struct iommu_device mock_iommu_device = {
};

@@@ -293,8 -466,10 +450,9 @@@ static const struct iommu_ops mock_ops
.owner = THIS_MODULE,
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
.hw_info = mock_domain_hw_info,
- .domain_alloc = mock_domain_alloc,
+ .domain_alloc_paging = mock_domain_alloc_paging,
+ .domain_alloc_user = mock_domain_alloc_user,
.capable = mock_domain_capable,
- .set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
.device_group = generic_device_group,
.probe_device = mock_probe_device,
.default_domain_ops =


Attachments:
(No filename) (499.00 B)
OpenPGP digital signature

2023-10-31 11:32:16

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: linux-next: manual merge of the iommufd tree with the iommu tree

On Tue, Oct 31, 2023 at 04:12:14PM +1100, Stephen Rothwell wrote:
> Hi all,
>
> On Mon, 30 Oct 2023 15:26:21 -0300 Jason Gunthorpe <[email protected]> wrote:
> >
> > On Fri, Oct 27, 2023 at 05:15:22PM +1100, Stephen Rothwell wrote:
> > >
> > > On Fri, 27 Oct 2023 15:55:22 +1100 Stephen Rothwell <[email protected]> wrote:
> > > >
> > > > Today's linux-next merge of the iommufd tree got a conflict in:
> > > >
> > > > drivers/iommu/iommufd/selftest.c
> > > >
> > > > between commits:
> > > >
> > > > 1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
> > > > 13fbceb1b8e9 ("iommufd: Convert to alloc_domain_paging()")
> > > >
> > > > from the iommu tree and commits:
> > > >
> > > > 408663619fcf ("iommufd/selftest: Add domain_alloc_user() support in iommu mock")
> > > > 266ce58989ba ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING")
> > > > 7adf267d66d1 ("iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING")
> > > > a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
> > > > 0795b305da89 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag")
> > > > 65fe32f7a447 ("iommufd/selftest: Add nested domain allocation for mock domain")
> > > >
> > > > from the iommufd tree.
> > > >
> > > > I fixed it up (see below) and can carry the fix as necessary. This
> > > > is now fixed as far as linux-next is concerned, but any non trivial
> > > > conflicts should be mentioned to your upstream maintainer when your tree
> > > > is submitted for merging. You may also want to consider cooperating
> > > > with the maintainer of the conflicting tree to minimise any particularly
> > > > complex conflicts.
> > >
> > > The resolution should have been as below (I think).
> >
> > This was too horrible, I pushed a patch to reorganize the new iommufd side
> > code to more closely match how the domain_alloc_paging stuff is
> > supposed to work
>
> I have used the conflict resolution below now.

Yep!

Thanks,
Jason

2023-11-02 23:53:31

by Stephen Rothwell

[permalink] [raw]
Subject: Re: linux-next: manual merge of the iommufd tree with the iommu tree

Hi all,

On Tue, 31 Oct 2023 16:12:14 +1100 Stephen Rothwell <[email protected]> wrote:
>
> On Mon, 30 Oct 2023 15:26:21 -0300 Jason Gunthorpe <[email protected]> wrote:
> >
> > On Fri, Oct 27, 2023 at 05:15:22PM +1100, Stephen Rothwell wrote:
> > >
> > > On Fri, 27 Oct 2023 15:55:22 +1100 Stephen Rothwell <[email protected]> wrote:
> > > >
> > > > Today's linux-next merge of the iommufd tree got a conflict in:
> > > >
> > > > drivers/iommu/iommufd/selftest.c
> > > >
> > > > between commits:
> > > >
> > > > 1c68cbc64fe6 ("iommu: Add IOMMU_DOMAIN_PLATFORM")
> > > > 13fbceb1b8e9 ("iommufd: Convert to alloc_domain_paging()")
> > > >
> > > > from the iommu tree and commits:
> > > >
> > > > 408663619fcf ("iommufd/selftest: Add domain_alloc_user() support in iommu mock")
> > > > 266ce58989ba ("iommufd/selftest: Test IOMMU_HWPT_ALLOC_DIRTY_TRACKING")
> > > > 7adf267d66d1 ("iommufd/selftest: Test IOMMU_HWPT_SET_DIRTY_TRACKING")
> > > > a9af47e382a4 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
> > > > 0795b305da89 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR flag")
> > > > 65fe32f7a447 ("iommufd/selftest: Add nested domain allocation for mock domain")
> > > >
> > > > from the iommufd tree.
> > > >
> > > > I fixed it up (see below) and can carry the fix as necessary. This
> > > > is now fixed as far as linux-next is concerned, but any non trivial
> > > > conflicts should be mentioned to your upstream maintainer when your tree
> > > > is submitted for merging. You may also want to consider cooperating
> > > > with the maintainer of the conflicting tree to minimise any particularly
> > > > complex conflicts.
> > >
> > > The resolution should have been as below (I think).
> >
> > This was too horrible, I pushed a patch to reorganize the new iommufd side
> > code to more closely match how the domain_alloc_paging stuff is
> > supposed to work
>
> I have used the conflict resolution below now.
>
> --
> Cheers,
> Stephen Rothwell
>
> diff --cc drivers/iommu/iommufd/selftest.c
> index ee6079847091,d43a87737c1e..5d93434003d8
> --- a/drivers/iommu/iommufd/selftest.c
> +++ b/drivers/iommu/iommufd/selftest.c
> @@@ -155,6 -240,81 +235,72 @@@ static struct iommu_domain *mock_domain
> return &mock->domain;
> }
>
> + static struct iommu_domain *
> + __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent,
> + const struct iommu_hwpt_selftest *user_cfg)
> + {
> + struct mock_iommu_domain_nested *mock_nested;
> + int i;
> +
> + mock_nested = kzalloc(sizeof(*mock_nested), GFP_KERNEL);
> + if (!mock_nested)
> + return ERR_PTR(-ENOMEM);
> + mock_nested->parent = mock_parent;
> + mock_nested->domain.ops = &domain_nested_ops;
> + mock_nested->domain.type = IOMMU_DOMAIN_NESTED;
> + for (i = 0; i < MOCK_NESTED_DOMAIN_IOTLB_NUM; i++)
> + mock_nested->iotlb[i] = user_cfg->iotlb;
> + return &mock_nested->domain;
> + }
> +
> -static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
> -{
> - if (iommu_domain_type == IOMMU_DOMAIN_BLOCKED)
> - return &mock_blocking_domain;
> - if (iommu_domain_type == IOMMU_DOMAIN_UNMANAGED)
> - return mock_domain_alloc_paging(NULL);
> - return NULL;
> -}
> -
> + static struct iommu_domain *
> + mock_domain_alloc_user(struct device *dev, u32 flags,
> + struct iommu_domain *parent,
> + const struct iommu_user_data *user_data)
> + {
> + struct mock_iommu_domain *mock_parent;
> + struct iommu_hwpt_selftest user_cfg;
> + int rc;
> +
> + /* must be mock_domain */
> + if (!parent) {
> + 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);
> + 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 */
> + if (user_data->type != IOMMU_HWPT_DATA_SELFTEST || flags)
> + return ERR_PTR(-EOPNOTSUPP);
> + if (!parent || parent->ops != mock_ops.default_domain_ops)
> + return ERR_PTR(-EINVAL);
> +
> + mock_parent = container_of(parent, struct mock_iommu_domain, domain);
> + if (!mock_parent)
> + return ERR_PTR(-EINVAL);
> +
> + rc = iommu_copy_struct_from_user(&user_cfg, user_data,
> + IOMMU_HWPT_DATA_SELFTEST, iotlb);
> + if (rc)
> + return ERR_PTR(rc);
> +
> + return __mock_domain_alloc_nested(mock_parent, &user_cfg);
> + }
> +
> static void mock_domain_free(struct iommu_domain *domain)
> {
> struct mock_iommu_domain *mock =
> @@@ -272,9 -432,28 +418,20 @@@ static phys_addr_t mock_domain_iova_to_
>
> static bool mock_domain_capable(struct device *dev, enum iommu_cap cap)
> {
> - return cap == IOMMU_CAP_CACHE_COHERENCY;
> + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev);
> +
> + switch (cap) {
> + case IOMMU_CAP_CACHE_COHERENCY:
> + return true;
> + case IOMMU_CAP_DIRTY_TRACKING:
> + return !(mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY);
> + default:
> + break;
> + }
> +
> + return false;
> }
>
> -static void mock_domain_set_plaform_dma_ops(struct device *dev)
> -{
> - /*
> - * mock doesn't setup default domains because we can't hook into the
> - * normal probe path
> - */
> -}
> -
> static struct iommu_device mock_iommu_device = {
> };
>
> @@@ -293,8 -466,10 +450,9 @@@ static const struct iommu_ops mock_ops
> .owner = THIS_MODULE,
> .pgsize_bitmap = MOCK_IO_PAGE_SIZE,
> .hw_info = mock_domain_hw_info,
> - .domain_alloc = mock_domain_alloc,
> + .domain_alloc_paging = mock_domain_alloc_paging,
> + .domain_alloc_user = mock_domain_alloc_user,
> .capable = mock_domain_capable,
> - .set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
> .device_group = generic_device_group,
> .probe_device = mock_probe_device,
> .default_domain_ops =

This is now a conflict between the iommu tree and Linus' tree.

--
Cheers,
Stephen Rothwell


Attachments:
(No filename) (499.00 B)
OpenPGP digital signature

2023-11-03 00:34:06

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: linux-next: manual merge of the iommufd tree with the iommu tree

On Fri, Nov 03, 2023 at 10:53:12AM +1100, Stephen Rothwell wrote:
> > I have used the conflict resolution below now.
>
> This is now a conflict between the iommu tree and Linus' tree.

My PR has instructions for the resolution to both:

https://lore.kernel.org/linux-iommu/[email protected]/

Thanks,
Jason