public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Harris, James R" <james.r.harris@intel.com>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	ming.lei@redhat.com
Subject: Re: kernel oops when rmmod'ing ublk_drv w/ missing UBLK_CMD_START_DEV
Date: Thu, 26 Jan 2023 19:33:42 +0800	[thread overview]
Message-ID: <Y9JlFmSgDl3+zy3N@T590> (raw)
In-Reply-To: <d949dbc2-a0cf-c581-c5ca-ddefc592a0a5@kernel.dk>

On Wed, Jan 25, 2023 at 01:05:55PM -0700, Jens Axboe wrote:
> On 1/25/23 12:50?PM, Harris, James R wrote:
> > Hi,
> > 
> > I can reliably hit a kernel oops with ublk_drv using the following abnormal sequence of events (repro .c file at end of this e-mail):
> > 
> > 1) modprobe ublk_drv
> > 2) run test app which basically does:
> >   a) submit UBLK_CMD_ADD_DEV
> >   b) submit UBLK_CMD_SET_PARAMS
> >   c) wait for completions
> >   d) do *not* submit UBLK_CMD_START_DEV
> >   e) exit
> > 3) rmmod ublk_drv
> > 
> > Reproduces on 6.2-rc5, 6.1.5 and 6.1.
> 
> Something like this may do it, but I'll let Ming sort out the details
> on what's the most appropriate fix.

Hi Jens and James,

The ublk char device still needs to be deleted even though START_DEV
isn't called given the char device is added in ADD_DEV's handler, so
the current logic is correct.

The root cause is that 'ublk_chr_class' is destroyed too early, so
the following patch should fix the issue.

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 17b677b5d3b2..e54693204630 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -2092,13 +2092,12 @@ static void __exit ublk_exit(void)
        struct ublk_device *ub;
        int id;

-       class_destroy(ublk_chr_class);
-
-       misc_deregister(&ublk_misc);
-
        idr_for_each_entry(&ublk_index_idr, ub, id)
                ublk_remove(ub);

+       class_destroy(ublk_chr_class);
+       misc_deregister(&ublk_misc);
+
        idr_destroy(&ublk_index_idr);
        unregister_chrdev_region(ublk_chr_devt, UBLK_MINORS);
 }


Thanks, 
Ming


      parent reply	other threads:[~2023-01-26 11:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 19:50 kernel oops when rmmod'ing ublk_drv w/ missing UBLK_CMD_START_DEV Harris, James R
2023-01-25 20:05 ` Jens Axboe
2023-01-25 20:43   ` Harris, James R
2023-01-26 11:33   ` Ming Lei [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=Y9JlFmSgDl3+zy3N@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=james.r.harris@intel.com \
    --cc=linux-block@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