Re: [PATCH v2] scsi: add non-sleeping variant of scsi_device_put() and use it in alua

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2023-01-24 at 22:49 -0800, Christoph Hellwig wrote:
> On Tue, Jan 24, 2023 at 03:30:25PM +0100, mwilck@xxxxxxxx wrote:
> > From: Martin Wilck <mwilck@xxxxxxxx>
> > 
> > Since the might_sleep() annotation was added in scsi_device_put()
> > and
> > alua_rtpg_queue(), we have seen repeated reports of "BUG: sleeping
> > function
> > called from invalid context" [1], [2]. alua_rtpg_queue() is always
> > called
> > from contexts where the caller must hold at least one reference to
> > the scsi
> > device in question. This means that the reference taken by
> > alua_rtpg_queue() itself can't be the last one, and thus can be
> > dropped
> > without entering the code path in which scsi_device_put() might
> > actually
> > sleep.
> 
> If there is always guaranteed to be another reference, why does this
> code even grab one?  The pattern of dropping a reference that can't
> be
> the last is pretty nonsensical.
> 

It's because the sdev is passed to the work queue to execute the RTPG.
To my understanding, the rationale is that the caller's ref may be
given up before the workqueue starts running, thus an additional ref is
needed to make sure the sdev isn't freed before the workqueue accesses
it. But if queue_delayed_work() fails (e.g. because the item is already
queued) this additional ref must be given up.

Regards,
Martin




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux