All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: joro@8bytes.org, will@kernel.org, iommu@lists.linux.dev,
	baolu.lu@linux.intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/7] iommu: Switch __iommu_domain_alloc() to device ops
Date: Mon, 2 Oct 2023 16:36:09 -0300	[thread overview]
Message-ID: <20231002193609.GB650762@nvidia.com> (raw)
In-Reply-To: <a4078085-4061-2b52-daba-1cd642f0cf9d@arm.com>

On Mon, Oct 02, 2023 at 08:02:23PM +0100, Robin Murphy wrote:
> On 02/10/2023 3:16 pm, Jason Gunthorpe wrote:
> > On Mon, Oct 02, 2023 at 02:49:12PM +0100, Robin Murphy wrote:
> > > @@ -2120,20 +2120,30 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
> > >   	return domain;
> > >   }
> > > -static struct iommu_domain *
> > > -__iommu_group_domain_alloc(struct iommu_group *group, unsigned int type)
> > > +static int __iommu_domain_alloc_dev(struct device *dev, void *data)
> > >   {
> > 
> > Why?
> 
> Because out of 3 callsites, two were in a context which now needed to
> make the iommu_group_first_dev() call itself anyway,

I don't see it. Why not just do this?

static int __iommu_domain_alloc_dev(struct device *dev, void *data)
{
	/* FIXME: This is not correctly locked */
	struct iommu_group *group = iommu_group_get(dev);
	struct group **alloc_group = data;

	if (!group)
		return 0;

	mutex_lock(&group->mutex);
	/* Theoretically we could have raced against release */
	if (list_empty(&group->devices)) {
		mutex_unlock(&group->mutex);
		iommu_group_put(group);
		return 0;
	}

	*alloc_group = group;
	return 1;
}

struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
{
	struct iommu_group *alloc_group;
	struct iommu_domain *dom;

	/* Only one driver is supported with this interface */
	if (WARN_ON(iommu_num_drivers > 1))
		return NULL;

	bus_for_each_dev(bus, NULL, &alloc_group, __iommu_domain_alloc_dev);
	if (!alloc_group)
		return NULL;
	dom = __iommu_group_domain_alloc(alloc_group, IOMMU_DOMAIN_UNMANAGED);
	mutex_unlock(&alloc_group->mutex);
	iommu_group_put(alloc_group);
	return dom;
}
EXPORT_SYMBOL_GPL(iommu_domain_alloc);

(and ++/-- iommu_num_drivers in iommu_device_register)

One patch, it's pretty easy???

> Um... Good? I mean in 3/4 cases it's literally the exact same code just
> factored out again, while the one I've added picks some arbitrary device
> in a different way.

Sure, but the whole point was to make it obvious that there was no
direct linkage from the various dev parameters we have in places and
what dev will be passed by the driver. Everything passes through
__iommu_group_domain_alloc() and at the end of the day that should be
the only allocation API.

Jason

  reply	other threads:[~2023-10-02 19:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02 13:49 [PATCH v4 0/7] iommu: Retire bus ops Robin Murphy
2023-10-02 13:49 ` [PATCH v4 1/7] iommu: Factor out some helpers Robin Murphy
2023-10-02 13:49 ` [PATCH v4 2/7] iommu: Decouple iommu_present() from bus ops Robin Murphy
2023-10-02 14:17   ` Jason Gunthorpe
2023-10-02 14:32     ` Robin Murphy
2023-10-02 13:49 ` [PATCH v4 3/7] iommu: Validate that devices match domains Robin Murphy
2023-10-02 13:49 ` [PATCH v4 4/7] iommu: Switch __iommu_domain_alloc() to device ops Robin Murphy
2023-10-02 14:16   ` Jason Gunthorpe
2023-10-02 19:02     ` Robin Murphy
2023-10-02 19:36       ` Jason Gunthorpe [this message]
2023-10-04 17:23         ` Robin Murphy
2023-10-04 21:35           ` Jason Gunthorpe
2023-10-02 13:49 ` [PATCH v4 5/7] iommu/arm-smmu: Don't register fwnode for legacy binding Robin Murphy
2023-10-02 13:49 ` [PATCH v4 6/7] iommu: Retire bus ops Robin Murphy
2023-10-02 13:49 ` [PATCH v4 7/7] iommu: Clean up open-coded ownership checks Robin Murphy

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=20231002193609.GB650762@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.