public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: Helen Koike <helen.koike@collabora.com>
Cc: dm-devel@redhat.com, kernel@collabora.com,
	linux-kernel@vger.kernel.org, Alasdair Kergon <agk@redhat.com>
Subject: Re: dm ioctl: fix hang in early create error condition
Date: Wed, 15 May 2019 12:20:54 -0400	[thread overview]
Message-ID: <20190515162054.GA14934@redhat.com> (raw)
In-Reply-To: <78dda04b-925f-49eb-f88a-6d940bcc4754@collabora.com>

On Wed, May 15 2019 at 12:12pm -0400,
Helen Koike <helen.koike@collabora.com> wrote:

> Hi,
> 
> On 5/13/19 10:37 PM, Mike Snitzer wrote:
> > On Mon, May 13 2019 at  3:25P -0400,
> > Helen Koike <helen.koike@collabora.com> wrote:
> > 
> >> The dm_early_create() function (which deals with "dm-mod.create=" kernel
> >> command line option) calls dm_hash_insert() who gets an extra reference
> >> to the md object.
> >>
> >> In case of failure, this reference wasn't being released, causing
> >> dm_destroy() to hang, thus hanging the whole boot process.
> >>
> >> Fix this by calling __hash_remove() in the error path.
> >>
> >> Fixes: 6bbc923dfcf57d ("dm: add support to directly boot to a mapped device")
> >> Cc: stable@vger.kernel.org
> >> Signed-off-by: Helen Koike <helen.koike@collabora.com>
> >>
> >> ---
> >> Hi,
> >>
> >> I tested this patch by adding a new test case in the following test
> >> script:
> >>
> >> https://gitlab.collabora.com/koike/dm-cmdline-test/commit/d2d7a0ee4a49931cdb59f08a837b516c2d5d743d
> >>
> >> This test was failing, but with this patch it works correctly.
> >>
> >> Thanks
> >> Helen
> > 
> > Thanks for the patch but I'd prefer the following simpler fix.  What do
> > you think?
> > 
> > That said, I can provide a follow-on patch (inspired by the patch you
> > provided) that encourages more code sharing between dm_early_create()
> > and dev_create() by factoring out __dev_create().
> 
> Sounds great.
> 
> > 
> > diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
> > index c740153b4e52..0eb0b462c736 100644
> > --- a/drivers/md/dm-ioctl.c
> > +++ b/drivers/md/dm-ioctl.c
> > @@ -2117,6 +2117,7 @@ int __init dm_early_create(struct dm_ioctl *dmi,
> >  err_destroy_table:
> >  	dm_table_destroy(t);
> >  err_destroy_dm:
> > +	(void) __hash_remove(__find_device_hash_cell(dmi));
> >  	dm_put(md);
> >  	dm_destroy(md);
> >  	return r;
> > 
> 
> This doesn't really work for two reasons:
> 
> 1) __find_device_hash_cell() requires a mutual exclusivity between name,
> uuid and dev. In dm_early_create(), dmi can have more then one of these.

__find_device_hash_cell's exclusivity requirements are strange; I'll try
to understand what requires this.

> 2) I can fix (1) by calling __get_name_cell(), as the name is mandatory
> anyway, but this function also grabs another reference to the md object,
> so I need to add an extra dm_put(md) there:
> 
>  err_destroy_table:
>         dm_table_destroy(t);
> +err_hash_remove:
> +       (void) __hash_remove(__get_name_cell(dmi->name));
> +       dm_put(md);
>  err_destroy_dm:
>         dm_put(md);
>         dm_destroy(md);
> 
> 
> What do you think? Is this ok?

I think so.  Please submit a v2 and I'll rebase my followon patch
accordingly and will get it posted.

Thanks,
Mike

      reply	other threads:[~2019-05-15 16:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-13 19:25 [PATCH] dm ioctl: fix hang in early create error condition Helen Koike
2019-05-14  1:37 ` Mike Snitzer
2019-05-15 16:12   ` Helen Koike
2019-05-15 16:20     ` Mike Snitzer [this message]

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=20190515162054.GA14934@redhat.com \
    --to=snitzer@redhat.com \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=helen.koike@collabora.com \
    --cc=kernel@collabora.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