linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Christoph Hellwig <hch@lst.de>
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] char_dev: replace cdev_map with an xarray
Date: Mon, 11 Jan 2021 17:35:00 +0000	[thread overview]
Message-ID: <20210111173500.GG35215@casper.infradead.org> (raw)
In-Reply-To: <20210111170513.1526780-1-hch@lst.de>

On Mon, Jan 11, 2021 at 06:05:13PM +0100, Christoph Hellwig wrote:
> None of the complicated overlapping regions bits of the kobj_map are
> required for the character device lookup, so just a trivial xarray
> instead.

Thanks for doing this.  We could make it more efficient for chardevs
that occupy 64 or more consecutive/aligned devices -- is it worth doing?

> +static struct cdev *cdev_lookup(dev_t dev)
> +{
> +	struct cdev *cdev;
> +
> +	mutex_lock(&chrdevs_lock);
> +	cdev = xa_load(&cdev_map, dev);
> +	if (!cdev) {
> +		mutex_unlock(&chrdevs_lock);
> +		if (request_module("char-major-%d-%d",
> +				   MAJOR(dev), MINOR(dev)) > 0)
> +			/* Make old-style 2.4 aliases work */
> +			request_module("char-major-%d", MAJOR(dev));
> +		mutex_lock(&chrdevs_lock);
> +
> +		cdev = xa_load(&cdev_map, dev);
> +	}
> +	if (cdev && !cdev_get(cdev))
> +		cdev = NULL;
> +	mutex_unlock(&chrdevs_lock);
> +	return cdev;

What does the mutex protect here?  Is it cdev being freed?

> @@ -593,11 +601,16 @@ static void cdev_unmap(dev_t dev, unsigned count)
>   */
>  void cdev_del(struct cdev *p)
>  {
> -	cdev_unmap(p->dev, p->count);
> +	int i;
> +
> +	mutex_lock(&chrdevs_lock);
> +	for (i = 0; i < p->count; i++)
> +		xa_erase(&cdev_map, p->dev + i);
> +	mutex_unlock(&chrdevs_lock);

I don't understand what it's protecting here.  It's clearly not cdev_get
as that could happen before we acquire the mutex.  This also suggests
I should add an xa_erase_range() to the API.

But there's nothing wrong here, just some places that maybe could be
better, so:

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>

  reply	other threads:[~2021-01-11 17:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 17:05 [PATCH] char_dev: replace cdev_map with an xarray Christoph Hellwig
2021-01-11 17:35 ` Matthew Wilcox [this message]
2021-01-11 18:11   ` Greg KH
2021-01-11 18:20     ` Matthew Wilcox
2021-01-11 18:33       ` Greg KH
2021-01-11 18:51         ` Matthew Wilcox
2021-01-11 18:10 ` Greg KH
2021-01-11 20:58 ` Matthew Wilcox
2021-01-12  9:35   ` Greg KH
2021-01-12 10:00     ` David Laight
2021-01-12 10:25       ` 'Greg KH'

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=20210111173500.GG35215@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --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).