scsi: ufs & ums-*: fix module reference counting
Subsystems (3)
cover scsi: ufs & ums-*: fix module reference counting
While accessing a scsi_device, the use count of the underlying LLDD module is incremented. The module reference is retrieved through .module field of struct scsi_host_template.
This mapping between scsi_device and underlying LLDD module works well except some scsi drivers (ufs and unusual usb storage drivers). These drivers consist with core driver and actual LLDDs, and scsi_host_template is defined in the core driver. So the actual LLDDs can be unloaded even if the scsi_device is being accessed.
This patch series first adds ability to adjust module reference for scsi host by LLDDs and then fixes ufs and unusual usb storage drivers by adjusting module reference after scsi host allocation.
Akinobu Mita (3):
scsi: add ability to adjust module reference for scsi host
scsi: ufs: adjust module reference for scsi host
usb: storage: adjust module reference for scsi host
drivers/scsi/hosts.c | 1 + drivers/scsi/scsi.c | 4 ++-- drivers/scsi/ufs/ufshcd-pci.c | 1 + drivers/scsi/ufs/ufshcd-pltfrm.c | 1 + drivers/scsi/ufs/ufshcd.c | 1 - drivers/usb/storage/alauda.c | 1 + drivers/usb/storage/cypress_atacb.c | 2 ++ drivers/usb/storage/datafab.c | 1 + drivers/usb/storage/ene_ub6250.c | 1 + drivers/usb/storage/freecom.c | 1 + drivers/usb/storage/isd200.c | 1 + drivers/usb/storage/jumpshot.c | 1 + drivers/usb/storage/karma.c | 1 + drivers/usb/storage/onetouch.c | 2 ++ drivers/usb/storage/realtek_cr.c | 2 ++ drivers/usb/storage/sddr09.c | 2 ++ drivers/usb/storage/sddr55.c | 1 + drivers/usb/storage/shuttle_usbat.c | 1 + include/scsi/scsi_host.h | 1 + 19 files changed, 23 insertions(+), 3 deletions(-)
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1420468479-4508-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 1/3 scsi: add ability to adjust module reference for scsi host
While accessing a scsi_device, the use count of the underlying LLDD module is incremented. The module reference is retrieved through .module field of struct scsi_host_template.
This mapping between scsi_device and underlying LLDD module works well except some scsi drivers (ufs and unusual usb storage drivers). These drivers consist with core driver and actual LLDDs, and scsi_host_template is defined in the core driver. So the actual LLDDs can be unloaded even if the scsi_device is being accessed.
This adds .module field in struct Scsi_Host and let the module reference be retrieved though it instead of struct scsi_host_template. This allows the actual LLDDs adjust module reference.
--- drivers/scsi/hosts.c | 1 + drivers/scsi/scsi.c | 4 ++-- include/scsi/scsi_host.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/hosts.c +1 -0
@@ -411,6 +411,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)*/ shost->max_cmd_len =12 ; shost->hostt = sht; + shost->module = sht->module; shost->this_id = sht->this_id; shost->can_queue = sht->can_queue; shost->sg_tablesize = sht->sg_tablesize;
drivers/scsi/scsi.c +2 -2
@@ -988,7 +988,7 @@ int scsi_device_get(struct scsi_device *sdev)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); +try_module_get (sdev->host->module);return 0 ; }
@@ -1005,7 +1005,7 @@ EXPORT_SYMBOL(scsi_device_get);void scsi_device_put (struct scsi_device *sdev) {#ifdef CONFIG_MODULE_UNLOAD -struct module *module = sdev->host->hostt->module; +struct module *module = sdev->host->module;/* The module refcount will be zero if scsi_device_get() * was called from a module removal routine */
include/scsi/scsi_host.h +1 -0
@@ -617,6 +617,7 @@ struct Scsi_Host {*/ unsigned short max_cmd_len; +struct module *module;int this_id;int can_queue;short cmd_per_lun;
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/3 scsi: ufs: adjust module reference for scsi host
In reply to Akinobu MitaWhile accessing a UFS device, the module reference count for core driver (ufshcd) is incremented but not incremented for the actual glue driver (ufshcd-pci or ufshcd-pltfrm). Because these drivers allocate scsi hosts with scsi_host_template defined in ufshcd module. So these drivers always can be unloaded.
This fixes it by adjusting module reference after scsi host allocation.
--- drivers/scsi/ufs/ufshcd-pci.c | 1 + drivers/scsi/ufs/ufshcd-pltfrm.c | 1 + drivers/scsi/ufs/ufshcd.c | 1 - 3 files changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufshcd-pci.c +1 -0
@@ -142,6 +142,7 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)return err; } + hba->host->module =THIS_MODULE ;INIT_LIST_HEAD (&hba->clk_list_head); err =ufshcd_init (hba, mmio_base, pdev->irq);
drivers/scsi/ufs/ufshcd-pltfrm.c +1 -0
@@ -322,6 +322,7 @@ static int ufshcd_pltfrm_probe(struct platform_device *pdev) goto out; } + hba->host->module =THIS_MODULE ; hba->vops =get_variant_ops (&pdev->dev); err =ufshcd_parse_clock_info (hba);
drivers/scsi/ufs/ufshcd.c +0 -1
@@ -4202,7 +4202,6 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) }static struct scsi_host_template ufshcd_driver_template = { - .module =THIS_MODULE , .name =UFSHCD , .proc_name =UFSHCD , .queuecommand = ufshcd_queuecommand,
Signature · 1 line
1.9.1
PATCH 3/3 usb: storage: adjust module reference for scsi host
In reply to Akinobu MitaWhile accessing a unusual usb storage (ums-alauda, ums-cypress, ...), the module reference count is not incremented. Because these drivers allocate scsi hosts with usb_stor_host_template defined in usb-storage module. So these drivers always can be unloaded.
This fixes it by adjusting module reference after scsi host allocation.
--- drivers/usb/storage/alauda.c | 1 + drivers/usb/storage/cypress_atacb.c | 2 ++ drivers/usb/storage/datafab.c | 1 + drivers/usb/storage/ene_ub6250.c | 1 + drivers/usb/storage/freecom.c | 1 + drivers/usb/storage/isd200.c | 1 + drivers/usb/storage/jumpshot.c | 1 + drivers/usb/storage/karma.c | 1 + drivers/usb/storage/onetouch.c | 2 ++ drivers/usb/storage/realtek_cr.c | 2 ++ drivers/usb/storage/sddr09.c | 2 ++ drivers/usb/storage/sddr55.c | 1 + drivers/usb/storage/shuttle_usbat.c | 1 + 13 files changed, 17 insertions(+)
drivers/usb/storage/alauda.c +1 -0
@@ -1242,6 +1242,7 @@ static int alauda_probe(struct usb_interface *intf, us->transport = alauda_transport; us->transport_reset = usb_stor_Bulk_reset; us->max_lun =1 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/cypress_atacb.c +2 -0
@@ -255,6 +255,8 @@ static int cypress_probe(struct usb_interface *intf,if (result)return result; +us_to_host (us)->module =THIS_MODULE ; +/* Among CY7C68300 chips, the A revision does not support Cypress ATACB * Filter out this revision from EEPROM default descriptor values */
drivers/usb/storage/datafab.c +1 -0
@@ -736,6 +736,7 @@ static int datafab_probe(struct usb_interface *intf, us->transport = datafab_transport; us->transport_reset = usb_stor_Bulk_reset; us->max_lun =1 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/ene_ub6250.c +1 -0
@@ -2331,6 +2331,7 @@ static int ene_ub6250_probe(struct usb_interface *intf, us->transport_name ="ene_ub6250" ; us->transport = ene_transport; us->max_lun =0 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);if (result)
drivers/usb/storage/freecom.c +1 -0
@@ -538,6 +538,7 @@ static int freecom_probe(struct usb_interface *intf, us->transport = freecom_transport; us->transport_reset = usb_stor_freecom_reset; us->max_lun =0 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/isd200.c +1 -0
@@ -1550,6 +1550,7 @@ static int isd200_probe(struct usb_interface *intf, us->protocol_name ="ISD200 ATA/ATAPI" ; us->proto_handler = isd200_ata_command; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/jumpshot.c +1 -0
@@ -662,6 +662,7 @@ static int jumpshot_probe(struct usb_interface *intf, us->transport = jumpshot_transport; us->transport_reset = usb_stor_Bulk_reset; us->max_lun =1 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/karma.c +1 -0
@@ -214,6 +214,7 @@ static int karma_probe(struct usb_interface *intf, us->transport_name ="Rio Karma/Bulk" ; us->transport = rio_karma_transport; us->transport_reset = usb_stor_Bulk_reset; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/onetouch.c +2 -0
@@ -296,6 +296,8 @@ static int onetouch_probe(struct usb_interface *intf,/* Use default transport and protocol */ +us_to_host (us)->module =THIS_MODULE ; + result =usb_stor_probe2 (us);return result; }
drivers/usb/storage/realtek_cr.c +2 -0
@@ -1048,6 +1048,8 @@ static int realtek_cr_probe(struct usb_interface *intf,if (result)return result; +us_to_host (us)->module =THIS_MODULE ; + result =usb_stor_probe2 (us);return result;
drivers/usb/storage/sddr09.c +2 -0
@@ -1761,6 +1761,8 @@ static int sddr09_probe(struct usb_interface *intf, us->max_lun =0 ; } +us_to_host (us)->module =THIS_MODULE ; + result =usb_stor_probe2 (us);return result; }
drivers/usb/storage/sddr55.c +1 -0
@@ -984,6 +984,7 @@ static int sddr55_probe(struct usb_interface *intf, us->transport = sddr55_transport; us->transport_reset = sddr55_reset; us->max_lun =0 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
drivers/usb/storage/shuttle_usbat.c +1 -0
@@ -1852,6 +1852,7 @@ static int usbat_probe(struct usb_interface *intf, us->transport = usbat_flash_transport; us->transport_reset = usb_stor_CB_reset; us->max_lun =0 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
Signature · 1 line
1.9.1
Alan Stern
maintainerRe: [PATCH 3/3] usb: storage: adjust module reference for scsi host
Quoted 12 lines · Akinobu Mita
While accessing a unusual usb storage (ums-alauda, ums-cypress, ...), the module reference count is not incremented. Because these drivers allocate scsi hosts with
usb_stor_host_templatedefined in usb-storage module. So these drivers always can be unloaded.This fixes it by adjusting module reference after scsi host allocation.
drivers/usb/storage/alauda.c +0
-0
drivers/usb/storage/alauda.c static int alauda_probe(struct usb_interface *intf, · line 1248
Quoted 7 lines
drivers/usb/storage/alauda.c +1
-0@@ -1242,6 +1242,7 @@ static int alauda_probe(struct usb_interface *intf, us->transport = alauda_transport; us->transport_reset = usb_stor_Bulk_reset; us->max_lun =1 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;
... etc.
An easier and more foolproof approach would be to change usb_store_probe2 to take an extra argument for the owner:
int _usb_stor_probe2(struct us_data *us, struct module *owner)
...
us_to_host(us)->module = owner;
...
Then in usb.h:
extern int _usb_stor_probe2(struct us_data *us, struct module *owner);
#define usb_stor_probe2(us) _usb_stor_probe2(us, THIS_MODULE)
This pattern is already used in several other places in the kernel.
Alan Stern
A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.44L0.1501051021370.1485-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org
Re: [PATCH 3/3] usb: storage: adjust module reference for scsi host
2015-01-06 0:27 GMT+09:00 Alan Stern <stern-nwvwT67g6+6dFdvTe/[email protected]>:
Quoted 30 lines · Akinobu Mita
Quoted 13 lines
While accessing a unusual usb storage (ums-alauda, ums-cypress, ...), the module reference count is not incremented. Because these drivers allocate scsi hosts with
usb_stor_host_templatedefined in usb-storage module. So these drivers always can be unloaded.This fixes it by adjusting module reference after scsi host allocation.
drivers/usb/storage/alauda.c +0
-0drivers/usb/storage/alauda.c static int alauda_probe(struct usb_interface *intf, · line 1248
Quoted 7 lines
drivers/usb/storage/alauda.c +1
-0@@ -1242,6 +1242,7 @@ static int alauda_probe(struct usb_interface *intf, us->transport = alauda_transport; us->transport_reset = usb_stor_Bulk_reset; us->max_lun =1 ; +us_to_host (us)->module =THIS_MODULE ; result =usb_stor_probe2 (us);return result;... etc.
An easier and more foolproof approach would be to change
usb_store_probe2to take an extra argument for the owner:int
_usb_stor_probe2(struct us_data *us, struct module *owner)
...us_to_host(us)->module = owner;
Quoted 8 lines
...
Then in
usb.h:extern int
_usb_stor_probe2(struct us_data *us, struct module *owner);
#defineusb_stor_probe2(us)_usb_stor_probe2(us, THIS_MODULE)This pattern is already used in several other places in the kernel.
Sounds good. I'll take this idea and update this patch.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html