Skip to contentSkip to conversation

scsi: fixup kernel warning during rmmod()

PATCH Applied Hannes Reinecke 5 participants 5 messages Oct 4, 2017 – Oct 6, 2017 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: fixup kernel warning during rmmod()

Calling rmmod() on a FC driver will results in warnings like

WARNING: CPU: 60 PID: 14640 at fs/sysfs/group.c:237 device_del+0x54/0x240()

sysfs group ffffffff81eff140 not found for kobject '3:0:0:3'

The problem here is that during scsi_remove_target() we will iterate over all devices, but fail to remove any of those as the call to scsi_device_get() fails the check to module_is_live(). Hence the devices will not be removed at this point, but all intermediate structures like fc rport etc. will be.
Later on during scsi_forget_host() the devices are removed for real, but the device parent is already removed and causes this warning.

---
 drivers/scsi/scsi_sysfs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +8 -2
index 1889761..995539f 100644
@@ -1336,13 +1336,19 @@ static void __scsi_remove_target(struct scsi_target *starget)
 	spin_lock_irqsave(shost->host_lock, flags);
  restart:
 	list_for_each_entry(sdev, &shost->__devices, siblings) {
+		/*
+		 * We cannot call scsi_device_get() here, as
+		 * we might've been called from rmmod() causing
+		 * scsi_device_get() to fail the module_is_live()
+		 * check.
+		 */
 		if (sdev->channel != starget->channel ||
 		    sdev->id != starget->id ||
-		    scsi_device_get(sdev))
+		    !get_device(&sdev->sdev_gendev))
 			continue;
 		spin_unlock_irqrestore(shost->host_lock, flags);
 		scsi_remove_device(sdev);
-		scsi_device_put(sdev);
+		put_device(&sdev->sdev_gendev);
 		spin_lock_irqsave(shost->host_lock, flags);
 		goto restart;
 	}
Signature · 1 line
1.8.5.6
Tested-by on v1 1/1
#3 lore raw
In reply to Hannes Reinecke
Quoted 28 lines

-----Original Message-----
From: [email protected] [mailto:linux-scsi- [email protected]] On Behalf Of Hannes Reinecke
Sent: Wednesday, October 04, 2017 3:29 AM
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Hannes Reinecke <[email protected]>
Subject: [PATCH] scsi: fixup kernel warning during rmmod()

EXTERNAL EMAIL

Calling rmmod() on a FC driver will results in warnings like

WARNING: CPU: 60 PID: 14640 at fs/sysfs/group.c:237
device_del+0x54/0x240()

sysfs group ffffffff81eff140 not found for kobject '3:0:0:3'

The problem here is that during scsi_remove_target() we will iterate over all devices, but fail to remove any of those as the call to scsi_device_get() fails the check to module_is_live(). Hence the devices will not be removed at this point, but all intermediate structures like fc rport etc. will be.
Later on during scsi_forget_host() the devices are removed for real, but the device parent is already removed and causes this warning.

Quoted 1 line

Using the smartpqi driver.
Thanks for your effort.

Thanks,
Don Brace
ESC - Smart Storage
Microsemi Corporation

Quoted 33 lines
---
 drivers/scsi/scsi_sysfs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/scsi_sysfs.c +8 -2
index 1889761..995539f 100644
@@ -1336,13 +1336,19 @@ static void __scsi_remove_target(struct
 scsi_target *starget)
        spin_lock_irqsave(shost->host_lock, flags);
  restart:
        list_for_each_entry(sdev, &shost->__devices, siblings) {
+               /*
+                * We cannot call scsi_device_get() here, as
+                * we might've been called from rmmod() causing
+                * scsi_device_get() to fail the module_is_live()
+                * check.
+                */
                if (sdev->channel != starget->channel ||
                    sdev->id != starget->id ||
-                   scsi_device_get(sdev))
+                   !get_device(&sdev->sdev_gendev))
                        continue;
                spin_unlock_irqrestore(shost->host_lock, flags);
                scsi_remove_device(sdev);
-               scsi_device_put(sdev);
+               put_device(&sdev->sdev_gendev);
                spin_lock_irqsave(shost->host_lock, flags);
                goto restart;
        }

--
1.8.5.6

#4 lore raw
In reply to Hannes Reinecke

Hannes,

Quoted 1 line

Calling rmmod() on a FC driver will results in warnings like

Applied to 4.14/scsi-fixes. Thank you!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering