iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Jacob Pan <jacob.jun.pan@linux.intel.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
	Raj Ashok <ashok.raj@intel.com>,
	David Woodhouse <dwmw2@infradead.org>,
	iommu@lists.linux-foundation.org,
	LKML <linux-kernel@vger.kernel.org>,
	Alex Williamson <alex.williamson@redhat.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.com>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH v2 3/4] iommu/ioasid: Add custom allocators
Date: Wed, 2 Oct 2019 10:20:44 -0700	[thread overview]
Message-ID: <20191002102044.6ed3ad56@jacob-builder> (raw)
In-Reply-To: <20191002161825.GA626133@lophozonia>

On Wed, 2 Oct 2019 18:18:25 +0200
Jean-Philippe Brucker <jean-philippe@linaro.org> wrote:

> Hi Jacob,
> 
> I have four tiny comments below but the patch looks great otherwise,
> no major concern from me.
> 
> On Sat, Sep 21, 2019 at 05:07:49PM -0700, Jacob Pan wrote:
> > +/*
> > + * struct ioasid_allocator_data - Internal data structure to hold
> > information
> > + * about an allocator. There are two types of allocators:
> > + *
> > + * - Default allocator always has its own XArray to track the
> > IOASIDs allocated.
> > + * - Custom allocators may share allocation helpers with different
> > private data.
> > + *   Custom allocators that share the same helper functions also
> > share the same
> > + *   XArray.
> > + * Rules:
> > + * 1. Default allocator is always available, not dynamically
> > registered. This is
> > + *    to prevent race conditions with early boot code that want to
> > register
> > + *    custom allocators or allocate IOASIDs.
> > + * 2. Custom allocators take precedence over the default allocator.
> > + * 3. When all custom allocators sharing the same helper functions
> > are
> > + *    unregistered (e.g. due to hotplug), all outstanding IOASIDs
> > must be
> > + *    freed. Otherwise, outstand IOASIDs will be lost and
> > orphaned.  
> 
>                            outstanding
> 
> [...]
> >  ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min,
> > ioasid_t max, void *private)
> >  {
> > -	ioasid_t id;
> >  	struct ioasid_data *data;
> > +	void *adata;
> > +	ioasid_t id;  
> 
> nit: changing the location of id could be in patch 2/4.
> 
will do.

> > -	data = kzalloc(sizeof(*data), GFP_KERNEL);
> > +	data = kzalloc(sizeof(*data), GFP_ATOMIC);  
> 
> I don't think that one needs to be GFP_ATOMIC. Otherwise it should
> probably be done from the start, by patch 2/4.
> 
I was thinking since we are making this API usable in atomic context,
we need to use GFP_ATOMIC and spinlock throughout the code. I agree it
should be moved to 2/4.
> >  	if (!data)
> >  		return INVALID_IOASID;
> >  
> >  	data->set = set;
> >  	data->private = private;
> >  
> > -	if (xa_alloc(&ioasid_xa, &id, data, XA_LIMIT(min, max),
> > GFP_KERNEL)) {
> > -		pr_err("Failed to alloc ioasid from %d to %d\n",
> > min, max);
> > +	/*
> > +	 * Custom allocator needs allocator data to perform
> > platform specific
> > +	 * operations.
> > +	 */
> > +	spin_lock(&ioasid_allocator_lock);
> > +	adata = active_allocator->flags &
> > IOASID_ALLOCATOR_CUSTOM ? active_allocator->ops->pdata : data;
> > +	id = active_allocator->ops->alloc(min, max, adata);
> > +	if (id == INVALID_IOASID) {
> > +		pr_err("Failed ASID allocation %lu\n",
> > active_allocator->flags);
> > +		goto exit_free;
> > +	}
> > +
> > +	if ((active_allocator->flags & IOASID_ALLOCATOR_CUSTOM) &&
> > +		xa_alloc(&active_allocator->xa, &id, data,
> > XA_LIMIT(id, id), GFP_ATOMIC)) {  
> 
> nit: aligning at the "if (" would make this block more readable.
> 
sounds good. I need to change my editor :)
> > +		/* Custom allocator needs framework to store and
> > track allocation results */
> > +		pr_err("Failed to alloc ioasid from %d\n", id);
> > +		active_allocator->ops->free(id,
> > active_allocator->ops->pdata); goto exit_free;
> >  	}  
> 
> Thanks,
> Jean

[Jacob Pan]
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2019-10-02 17:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-22  0:07 [PATCH v2 0/4] User API for nested shared virtual address (SVA) Jacob Pan
2019-09-22  0:07 ` [PATCH v2 1/4] iommu: Introduce cache_invalidate API Jacob Pan
2019-09-22  0:07 ` [PATCH v2 2/4] iommu: Add I/O ASID allocator Jacob Pan
2019-09-22  1:45   ` kbuild test robot
2019-09-22  0:07 ` [PATCH v2 3/4] iommu/ioasid: Add custom allocators Jacob Pan
2019-10-02 16:18   ` Jean-Philippe Brucker
2019-10-02 17:20     ` Jacob Pan [this message]
2019-09-22  0:07 ` [PATCH v2 4/4] iommu: Introduce guest PASID bind function Jacob Pan

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=20191002102044.6ed3ad56@jacob-builder \
    --to=jacob.jun.pan@linux.intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jean-philippe@linaro.com \
    --cc=jean-philippe@linaro.org \
    --cc=jic23@kernel.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.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).