Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Maurizio Lombardi <mlombard@redhat.com>
Cc: axboe@kernel.dk, hch@lst.de, sagi@grimberg.me,
	linux-nvme@lists.infradead.org
Subject: Re: [PATCH V2] nvme-pci: fix race condition between reset and nvme_dev_disable()
Date: Tue, 15 Oct 2024 11:57:32 -0600	[thread overview]
Message-ID: <Zw6tDKuibIDwCHer@kbusch-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <Zw6l_A742J3iCYLR@kbusch-mbp.dhcp.thefacebook.com>

On Tue, Oct 15, 2024 at 11:27:24AM -0600, Keith Busch wrote:
> On Tue, Oct 15, 2024 at 01:21:00PM +0200, Maurizio Lombardi wrote:
> > -static void nvme_pci_update_nr_queues(struct nvme_dev *dev)
> > +static bool nvme_pci_update_nr_queues(struct nvme_dev *dev)
> >  {
> >  	if (!dev->ctrl.tagset) {
> >  		nvme_alloc_io_tag_set(&dev->ctrl, &dev->tagset, &nvme_mq_ops,
> >  				nvme_pci_nr_maps(dev), sizeof(struct nvme_iod));
> > -		return;
> > +		return true;
> > +	}
> > +
> > +	/* Give up if we are racing with nvme_dev_disable() */
> > +	if (!mutex_trylock(&dev->shutdown_lock))
> > +		return false;
> > +
> > +	/* Check if nvme_dev_disable() has been executed already */
> > +	if (!dev->online_queues) {
> > +		mutex_unlock(&dev->shutdown_lock);
> > +		return false;
> >  	}
> >  
> >  	blk_mq_update_nr_hw_queues(&dev->tagset, dev->online_queues - 1);
> >  	/* free previously allocated queues that are no longer usable */
> >  	nvme_free_queues(dev, dev->online_queues);
> > +	mutex_unlock(&dev->shutdown_lock);
> 
> I believe mutex_unlock needs to be above blk_mq_update_nr_hw_queues().
> That function needs all the queues to be frozen, so any older IO that
> times out is going to need this lock in order to reclaim it.

Oops, unlocking there doesn't solve your problem. I guess your patch
should be safe as-is since the nvme driver already waits for the freeze
prior to updating the hw queues.


  reply	other threads:[~2024-10-15 17:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 11:21 [PATCH V2] nvme-pci: fix race condition between reset and nvme_dev_disable() Maurizio Lombardi
2024-10-15 17:27 ` Keith Busch
2024-10-15 17:57   ` Keith Busch [this message]
2024-10-17 18:08 ` Keith Busch

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=Zw6tDKuibIDwCHer@kbusch-mbp.dhcp.thefacebook.com \
    --to=kbusch@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mlombard@redhat.com \
    --cc=sagi@grimberg.me \
    /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