linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Ming Lei <ming.lei@redhat.com>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, Changhui Zhong <czhong@redhat.com>,
	Yi Zhang <yi.zhang@redhat.com>
Subject: Re: [PATCH V3] scsi: core: put LLD module refcnt after SCSI device is released
Date: Thu, 7 Oct 2021 09:19:25 +0200	[thread overview]
Message-ID: <YV6ffTjVBJgDIgtG@kroah.com> (raw)
In-Reply-To: <YV6d9OmLt1w5d9Qp@T590>

On Thu, Oct 07, 2021 at 03:12:52PM +0800, Ming Lei wrote:
> On Tue, Oct 05, 2021 at 03:35:40PM +0200, Greg Kroah-Hartman wrote:
> > On Thu, Sep 30, 2021 at 08:44:15PM +0800, Ming Lei wrote:
> > > SCSI host release is triggered when SCSI device is freed, and we have to
> > > make sure that LLD module won't be unloaded before SCSI host instance is
> > > released because shost->hostt is required in host release handler.
> > > 
> > > So make sure to put LLD module refcnt after SCSI device is released.
> > 
> > What is a "LLD"?
> 
> Lower level driver, which is used often as one scsi term.
> 
> > 
> > > Fix one kernel panic of 'BUG: unable to handle page fault for address'
> > > reported by Changhui and Yi.
> > > 
> > > Reported-by: Changhui Zhong <czhong@redhat.com>
> > > Reported-by: Yi Zhang <yi.zhang@redhat.com>
> > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > > ---
> > >  drivers/scsi/scsi.c        |  4 +++-
> > >  drivers/scsi/scsi_sysfs.c  | 12 ++++++++++++
> > >  include/scsi/scsi_device.h |  1 +
> > >  3 files changed, 16 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
> > > index b241f9e3885c..291ecc33b1fe 100644
> > > --- a/drivers/scsi/scsi.c
> > > +++ b/drivers/scsi/scsi.c
> > > @@ -553,8 +553,10 @@ EXPORT_SYMBOL(scsi_device_get);
> > >   */
> > >  void scsi_device_put(struct scsi_device *sdev)
> > >  {
> > > -	module_put(sdev->host->hostt->module);
> > > +	struct module *mod = sdev->host->hostt->module;
> > > +
> > >  	put_device(&sdev->sdev_gendev);
> > > +	module_put(mod);
> > >  }
> > >  EXPORT_SYMBOL(scsi_device_put);
> > >  
> > > diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> > > index 86793259e541..9ada26814011 100644
> > > --- a/drivers/scsi/scsi_sysfs.c
> > > +++ b/drivers/scsi/scsi_sysfs.c
> > > @@ -449,9 +449,16 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
> > >  	struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL;
> > >  	struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL;
> > >  	unsigned long flags;
> > > +	struct module *mod;
> > > +	bool put_mod = false;
> > >  
> > >  	sdev = container_of(work, struct scsi_device, ew.work);
> > >  
> > > +	if (sdev->put_lld_mod_ref) {
> > 
> > Why do you need this flag at all?
> > 
> > Shouldn't you just always grab/release the module?  Why would you not
> > want to?
> 
> try_module_get() may fail in scsi_device_dev_release() in case that
> unloading is started, then we don't need to put it in
> scsi_device_dev_release_usercontext(), so this flag is required.

If grabing the module reference failed then you CAN NOT call into it so
you have a problem here that you seem to be papering over.  Just set the
module pointer to NULL and then you don't need to test it when calling
module_put, right?

thanks,

greg k-h

  reply	other threads:[~2021-10-07  7:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 12:44 [PATCH V3] scsi: core: put LLD module refcnt after SCSI device is released Ming Lei
2021-10-05  3:07 ` Yi Zhang
2021-10-05 13:35 ` Greg Kroah-Hartman
2021-10-07  7:12   ` Ming Lei
2021-10-07  7:19     ` Greg Kroah-Hartman [this message]
2021-10-08  3:03       ` Ming Lei

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=YV6ffTjVBJgDIgtG@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=czhong@redhat.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=ming.lei@redhat.com \
    --cc=yi.zhang@redhat.com \
    /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).