Re: [RFC] How to fix an async scan - 'rmmod --wait' race?

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

 



On Thu, 2012-05-17 at 16:51 +0200, Tomas Henzl wrote:
> >>> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> >>> index 3ec3896..246e652 100644
> >>> --- a/drivers/base/driver.c
> >>> +++ b/drivers/base/driver.c
> >>> @@ -10,6 +10,7 @@
> >>>   *
> >>>   */
> >>>  
> >>> +#include <linux/async.h>
> >>>  #include <linux/device.h>
> >>>  #include <linux/module.h>
> >>>  #include <linux/errno.h>
> >>> @@ -199,6 +200,13 @@ EXPORT_SYMBOL_GPL(driver_register);
> >>>   */
> >>>  void driver_unregister(struct device_driver *drv)
> >>>  {
> >>> +	/*
> >>> +	 * make sure all async bits that may be running have completed the way
> >>> +	 * this works is that try_module_get() now fails, so new async work
> >>> +	 * should take a reference to the module which now fails, so it should
> >>> +	 * be safe to remove the driver.
> >>> +	 */
> >>> +	async_synchronize_full();
> >>>  	if (!drv || !drv->p) {
> >>>  		WARN(1, "Unexpected driver unregister!\n");
> >>>  		return;
> Is this safe? I mean, is it possible that a new scan starts after the
> async_synchronize_full() ends?

Not really, because the module is now removing, so the try module get
guard fails

> I wish this were fixed by fixing the real root of this problem which lies
> in scssi_device_get:
> int scsi_device_get(struct scsi_device *sdev)
> {
>         if (sdev->sdev_state == SDEV_DEL)
>                 return -ENXIO;
>         if (!get_device(&sdev->sdev_gendev))
>                 return -ENXIO;
>         /* We can fail this if we're doing SCSI operations
>          * from module exit (like cache flush) */
>         try_module_get(sdev->host->hostt->module);
> here  ^ by ignoring the return value. This is why rmmod --wait causes the problem
> and likely every other process which calls scsi_device_get would show the same bug.

I'm not sure how ... this has to be usable in the teardown path by which
point try_module_get will fail (as the comment says).  What do you
propose?

James



--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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