Skip to contentSkip to conversation

scsi: fix module reference mismatch for scsi host

PATCH Superseded Akinobu Mita 5 participants 18 messages Jan 18, 2015 – Jan 22, 2015 2 messages not in the archive

Subsystems (9)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover scsi: fix module reference mismatch 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 drivers which consist with the core driver and the actual LLDDs and scsi_host_template is defined in the core driver. In these cases, the actual LLDDs can be unloaded even if the scsi_device is being accessed.

This patch series fixes the module reference mismatch problem for ufs, usb-storage, esp_scsi, ahci_platform, and pata_platform drivers by moving owner module reference field from struct scsi_host_template to struct Scsi_Host and allowing the LLDDs to set their correct module reference.

* v4:
- Patch series is almost rewritten as module reference field in struct scsi_host_template has been unused anymore. So Acked-by: and
Reviewed-by: tags that have been received are deleted.

* v3:
- Add fix for ESP SCSI drivers

* v2:
- Pass correct module reference to usb_stor_probe1() instead of touching all ums-* drivers, suggested by Alan Stern

Akinobu Mita (11):
ata: prepare to move module reference from scsi_host_template to
Scsi_Host
iscsi: prepare to move module reference from scsi_host_template to
Scsi_Host
cxgbi: prepare to move module reference from scsi_host_template to
Scsi_Host
libfc: prepare to move module reference from scsi_host_template to
Scsi_Host
53c700: prepare move module reference from scsi_host_template to
Scsi_Host
scsi: legacy: prepare to move module reference from scsi_host_template
to Scsi_Host
scsi: move module reference from scsi_host_template to Scsi_Host
scsi: ufs: adjust module reference for scsi host
usb: storage: adjust module reference for scsi host
ata: ahci_platform: adjust module reference for scsi host
ata: pata_of_platform: adjust module reference for scsi host

 drivers/ata/libahci_platform.c | 14 +++++-----
 drivers/ata/libata-core.c      | 22 ++++++++-------
 drivers/ata/libata-scsi.c      |  2 +-
 drivers/ata/libata-sff.c       | 61 +++++++++++++++++++++++-------------------
 drivers/ata/pata_platform.c    | 18 +++++++------
 drivers/scsi/53c700.c          |  9 ++++---
 drivers/scsi/53c700.h          |  7 +++--
 drivers/scsi/cxgbi/libcxgbi.c  |  8 +++---
 drivers/scsi/cxgbi/libcxgbi.h  |  6 +++--
 drivers/scsi/hosts.c           | 16 ++++++-----
 drivers/scsi/libfc/fc_lport.c  | 26 ++++++++++++++++++
 drivers/scsi/libfc/fc_npiv.c   |  2 +-
 drivers/scsi/libiscsi.c        | 12 +++++----
 drivers/scsi/scsi.c            |  4 +--
 drivers/scsi/ufs/ufshcd.c      | 13 ++++-----
 drivers/scsi/ufs/ufshcd.h      |  5 +++-
 drivers/usb/storage/scsiglue.c |  3 ---
 drivers/usb/storage/usb.c      |  9 ++++---
 drivers/usb/storage/usb.h      |  7 +++--
 include/linux/ahci_platform.h  |  9 ++++---
 include/linux/ata_platform.h   | 16 ++++++-----
 include/linux/libata.h         | 52 ++++++++++++++++++++++++-----------
 include/scsi/libfc.h           | 27 +++----------------
 include/scsi/libiscsi.h        |  9 ++++---
 include/scsi/scsi_host.h       | 13 +++++++--
 25 files changed, 224 insertions(+), 146 deletions(-)
Cc Vinayak Holikatti <[email protected]>
Cc Dolev Raviv <[email protected]>
Cc Sujit Reddy Thumma <[email protected]>
Cc Subhash Jadavani <[email protected]>
Cc Matthew Dharm <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Alan Stern <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Mike Christie <[email protected]>
Cc Karen Xie <[email protected]>
Cc Robert Love <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/11 ata: prepare to move module reference from scsi_host_template to Scsi_Host

In preparation for moving owner module reference field from struct scsi_host_template to struct Scsi_Host, this converts the following functions into macros so that LLDDs can pass THIS_MODULE to scsi_host_alloc() through them instead of scsi_host_template->module.

ata_host_alloc()
ata_host_alloc_pinfo()
ata_pci_sff_prepare_host()
ata_pci_sff_init_one()
ata_pci_bmdma_prepare_host()
ata_pci_bmdma_init_one()

Cc Hans de Goede <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/ata/libata-core.c | 22 ++++++++++-------
 drivers/ata/libata-sff.c  | 61 +++++++++++++++++++++++++----------------------
 include/linux/libata.h    | 52 ++++++++++++++++++++++++++++------------
 3 files changed, 83 insertions(+), 52 deletions(-)
drivers/ata/libata-core.c +13 -9
index 5c84fb5..a3cc0e3 100644
@@ -5700,9 +5700,10 @@ static void ata_host_release(struct device *gendev, void *res)
 }
 
 /**
- *	ata_host_alloc - allocate and init basic ATA host resources
+ *	__ata_host_alloc - allocate and init basic ATA host resources
  *	@dev: generic device this host is associated with
  *	@max_ports: maximum number of ATA ports associated with this host
+ *	@owner: module which will be the owner of the ATA host
  *
  *	Allocate and initialize basic ATA host resources.  LLD calls
  *	this function to allocate a host, initializes it fully and
@@ -5719,7 +5720,8 @@ static void ata_host_release(struct device *gendev, void *res)
  *	LOCKING:
  *	Inherited from calling layer (may sleep).
  */
-struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
+struct ata_host *__ata_host_alloc(struct device *dev, int max_ports,
+				  struct module *owner)
 {
 	struct ata_host *host;
 	size_t sz;
@@ -5744,6 +5746,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
 	mutex_init(&host->eh_mutex);
 	host->dev = dev;
 	host->n_ports = max_ports;
+	host->module = owner;
 
 	/* allocate ports bound to this host */
 	for (i = 0; i < max_ports; i++) {
@@ -5766,10 +5769,11 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
 }
 
 /**
- *	ata_host_alloc_pinfo - alloc host and init with port_info array
+ *	__ata_host_alloc_pinfo - alloc host and init with port_info array
  *	@dev: generic device this host is associated with
  *	@ppi: array of ATA port_info to initialize host with
  *	@n_ports: number of ATA ports attached to this host
+ *	@owner: module which will be the owner of the ATA host
  *
  *	Allocate ATA host and initialize with info from @ppi.  If NULL
  *	terminated, @ppi may contain fewer entries than @n_ports.  The
@@ -5781,15 +5785,15 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
  *	LOCKING:
  *	Inherited from calling layer (may sleep).
  */
-struct ata_host *ata_host_alloc_pinfo(struct device *dev,
-				      const struct ata_port_info * const * ppi,
-				      int n_ports)
+struct ata_host *__ata_host_alloc_pinfo(struct device *dev,
+					const struct ata_port_info * const *ppi,
+					int n_ports, struct module *owner)
 {
 	const struct ata_port_info *pi;
 	struct ata_host *host;
 	int i, j;
 
-	host = ata_host_alloc(dev, n_ports);
+	host = __ata_host_alloc(dev, n_ports, owner);
 	if (!host)
 		return NULL;
 
@@ -6862,8 +6866,8 @@ EXPORT_SYMBOL_GPL(ata_dev_next);
 EXPORT_SYMBOL_GPL(ata_std_bios_param);
 EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity);
 EXPORT_SYMBOL_GPL(ata_host_init);
-EXPORT_SYMBOL_GPL(ata_host_alloc);
-EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
+EXPORT_SYMBOL_GPL(__ata_host_alloc);
+EXPORT_SYMBOL_GPL(__ata_host_alloc_pinfo);
 EXPORT_SYMBOL_GPL(ata_slave_link_init);
 EXPORT_SYMBOL_GPL(ata_host_start);
 EXPORT_SYMBOL_GPL(ata_host_register);
drivers/ata/libata-sff.c +33 -28

161 lines not on this page · raw message

include/linux/libata.h +37 -15

80 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/11 iscsi: prepare to move module reference from scsi_host_template to Scsi_Host

In reply to Akinobu Mita

In preparation for moving owner module reference field from struct scsi_host_template to struct Scsi_Host, this converts iscsi_host_alloc() into macro so that LLDDs can pass THIS_MODULE to scsi_host_alloc() through it instead of scsi_host_template->module.

Cc Mike Christie <[email protected]>
Cc Karen Xie <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/libiscsi.c | 10 ++++++----
 include/scsi/libiscsi.h |  9 ++++++---
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/scsi/libiscsi.c +6 -4
index 8053f24..4c5be6b 100644
@@ -2593,16 +2593,18 @@ int iscsi_host_add(struct Scsi_Host *shost, struct device *pdev)
 EXPORT_SYMBOL_GPL(iscsi_host_add);
 
 /**
- * iscsi_host_alloc - allocate a host and driver data
+ * __iscsi_host_alloc - allocate a host and driver data
  * @sht: scsi host template
  * @dd_data_size: driver host data size
  * @xmit_can_sleep: bool indicating if LLD will queue IO from a work queue
+ * @owner: module which will be the owner of the scsi host
  *
  * This should be called by partial offload and software iscsi drivers.
  * To access the driver specific memory use the iscsi_host_priv() macro.
  */
-struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht,
-				   int dd_data_size, bool xmit_can_sleep)
+struct Scsi_Host *__iscsi_host_alloc(struct scsi_host_template *sht,
+				     int dd_data_size, bool xmit_can_sleep,
+				     struct module *owner)
 {
 	struct Scsi_Host *shost;
 	struct iscsi_host *ihost;
@@ -2630,7 +2632,7 @@ free_host:
 	scsi_host_put(shost);
 	return NULL;
 }
-EXPORT_SYMBOL_GPL(iscsi_host_alloc);
+EXPORT_SYMBOL_GPL(__iscsi_host_alloc);
 
 static void iscsi_notify_host_removed(struct iscsi_cls_session *cls_session)
 {
include/scsi/libiscsi.h +6 -3
index 4d1c46a..c95d957 100644
@@ -396,9 +396,12 @@ extern int iscsi_host_set_param(struct Scsi_Host *shost,
 extern int iscsi_host_get_param(struct Scsi_Host *shost,
 				enum iscsi_host_param param, char *buf);
 extern int iscsi_host_add(struct Scsi_Host *shost, struct device *pdev);
-extern struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht,
-					  int dd_data_size,
-					  bool xmit_can_sleep);
+extern struct Scsi_Host *__iscsi_host_alloc(struct scsi_host_template *sht,
+					    int dd_data_size,
+					    bool xmit_can_sleep,
+					    struct module *owner);
+#define iscsi_host_alloc(sht, dd_data_size, xmit_can_sleep) \
+	__iscsi_host_alloc(sht, dd_data_size, xmit_can_sleep, THIS_MODULE)
 extern void iscsi_host_remove(struct Scsi_Host *shost);
 extern void iscsi_host_free(struct Scsi_Host *shost);
 extern int iscsi_target_alloc(struct scsi_target *starget);
Signature · 1 line
1.9.1
#3 lore raw

PATCH v4 3/11 cxgbi: prepare to move module reference from scsi_host_template to Scsi_Host

In reply to Akinobu Mita

In preparation for moving owner module reference field from struct scsi_host_template to struct Scsi_Host, this converts cxgbi_hbas_add() into macro so that LLDDs can pass THIS_MODULE to __iscsi_host_alloc() through it instead of scsi_host_template->module.

Cc Mike Christie <[email protected]>
Cc Karen Xie <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/cxgbi/libcxgbi.c | 8 ++++----
 drivers/scsi/cxgbi/libcxgbi.h | 6 ++++--
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/scsi/cxgbi/libcxgbi.c +4 -4
index eb58afc..f090d63 100644
@@ -330,9 +330,9 @@ void cxgbi_hbas_remove(struct cxgbi_device *cdev)
 }
 EXPORT_SYMBOL_GPL(cxgbi_hbas_remove);
 
-int cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun,
+int __cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun,
 		unsigned int max_id, struct scsi_host_template *sht,
-		struct scsi_transport_template *stt)
+		struct scsi_transport_template *stt, struct module *owner)
 {
 	struct cxgbi_hba *chba;
 	struct Scsi_Host *shost;
@@ -341,7 +341,7 @@ int cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun,
 	log_debug(1 << CXGBI_DBG_DEV, "cdev 0x%p, p#%u.\n", cdev, cdev->nports);
 
 	for (i = 0; i < cdev->nports; i++) {
-		shost = iscsi_host_alloc(sht, sizeof(*chba), 1);
+		shost = __iscsi_host_alloc(sht, sizeof(*chba), 1, owner);
 		if (!shost) {
 			pr_info("0x%p, p%d, %s, host alloc failed.\n",
 				cdev, i, cdev->ports[i]->name);
@@ -383,7 +383,7 @@ err_out:
 	cxgbi_hbas_remove(cdev);
 	return err;
 }
-EXPORT_SYMBOL_GPL(cxgbi_hbas_add);
+EXPORT_SYMBOL_GPL(__cxgbi_hbas_add);
 
 /*
  * iSCSI offload
drivers/scsi/cxgbi/libcxgbi.h +4 -2
index aba1af7..26c8bf7 100644
@@ -707,9 +707,11 @@ struct cxgbi_device *cxgbi_device_find_by_lldev(void *);
 struct cxgbi_device *cxgbi_device_find_by_netdev(struct net_device *, int *);
 struct cxgbi_device *cxgbi_device_find_by_netdev_rcu(struct net_device *,
 						     int *);
-int cxgbi_hbas_add(struct cxgbi_device *, u64, unsigned int,
+int __cxgbi_hbas_add(struct cxgbi_device *, u64, unsigned int,
 			struct scsi_host_template *,
-			struct scsi_transport_template *);
+			struct scsi_transport_template *, struct module *);
+#define cxgbi_hbas_add(cdev, max_lun, max_id, sht, stt) \
+	__cxgbi_hbas_add(cdev, max_lun, max_id, sht, stt, THIS_MODULE)
 void cxgbi_hbas_remove(struct cxgbi_device *);
 
 int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base,
Signature · 1 line
1.9.1
#4 lore raw

PATCH v4 4/11 libfc: prepare to move module reference from scsi_host_template to Scsi_Host

In reply to Akinobu Mita

In preparation for moving owner module reference field from struct scsi_host_template to struct Scsi_Host, this enables libfc_vport_create() to allocate Scsi_Host with correct module reference through __libfc_host_alloc() which is introduced while changing libfc_host_alloc() from inline function to macro and it takes module reference explicitly.

Cc Robert Love <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/libfc/fc_lport.c | 26 ++++++++++++++++++++++++++
 drivers/scsi/libfc/fc_npiv.c  |  3 ++-
 include/scsi/libfc.h          | 27 ++++-----------------------
 3 files changed, 32 insertions(+), 24 deletions(-)
drivers/scsi/libfc/fc_lport.c +26 -0
index e01a298..d931e69 100644
@@ -2142,3 +2142,29 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
 	return rc;
 }
 EXPORT_SYMBOL(fc_lport_bsg_request);
+
+/**
+ * __libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
+ *                      LLD private data
+ * @sht:       The SCSI host template
+ * @priv_size: Size of private data
+ * @owner: module which will be the owner of the scsi host
+ *
+ * Returns: libfc lport
+ */
+struct fc_lport *__libfc_host_alloc(struct scsi_host_template *sht,
+				    int priv_size, struct module *owner)
+{
+	struct fc_lport *lport;
+	struct Scsi_Host *shost;
+
+	shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
+	if (!shost)
+		return NULL;
+	lport = shost_priv(shost);
+	lport->host = shost;
+	INIT_LIST_HEAD(&lport->ema_list);
+	INIT_LIST_HEAD(&lport->vports);
+	return lport;
+}
+EXPORT_SYMBOL(__libfc_host_alloc);
drivers/scsi/libfc/fc_npiv.c +2 -1
index 9fbf78e..86133f9 100644
@@ -36,7 +36,8 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
 	struct fc_lport *n_port = shost_priv(shost);
 	struct fc_lport *vn_port;
 
-	vn_port = libfc_host_alloc(shost->hostt, privsize);
+	vn_port = __libfc_host_alloc(shost->hostt, privsize,
+				     shost->hostt->module);
 	if (!vn_port)
 		return vn_port;
 
include/scsi/libfc.h +4 -23
index 93d14da..b4fbfc2 100644
@@ -1018,29 +1018,10 @@ static inline void *lport_priv(const struct fc_lport *lport)
 	return (void *)(lport + 1);
 }
 
-/**
- * libfc_host_alloc() - Allocate a Scsi_Host with room for a local port and
- *                      LLD private data
- * @sht:       The SCSI host template
- * @priv_size: Size of private data
- *
- * Returns: libfc lport
- */
-static inline struct fc_lport *
-libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
-{
-	struct fc_lport *lport;
-	struct Scsi_Host *shost;
-
-	shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
-	if (!shost)
-		return NULL;
-	lport = shost_priv(shost);
-	lport->host = shost;
-	INIT_LIST_HEAD(&lport->ema_list);
-	INIT_LIST_HEAD(&lport->vports);
-	return lport;
-}
+struct fc_lport *__libfc_host_alloc(struct scsi_host_template *sht,
+				    int priv_size, struct module *owner);
+#define libfc_host_alloc(sht, priv_size) \
+	__libfc_host_alloc(sht, priv_size, THIS_MODULE)
 
 /*
  * FC_FCP HELPER FUNCTIONS
Signature · 1 line
1.9.1
#5 lore raw

PATCH v4 5/11 53c700: prepare move module reference from scsi_host_template to Scsi_Host

In reply to Akinobu Mita

In preparation for moving owner module reference field from struct scsi_host_template to struct Scsi_Host, this converts NCR_700_detect() into macro so that LLDDs can pass THIS_MODULE to scsi_host_alloc() through it instead of scsi_host_template->module.

Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/53c700.c | 7 ++++---
 drivers/scsi/53c700.h | 7 +++++--
 2 files changed, 9 insertions(+), 5 deletions(-)
drivers/scsi/53c700.c +4 -3
index 82abfce..e70fd05 100644
@@ -283,8 +283,9 @@ NCR_700_get_SXFER(struct scsi_device *SDp)
 }
 
 struct Scsi_Host *
-NCR_700_detect(struct scsi_host_template *tpnt,
-	       struct NCR_700_Host_Parameters *hostdata, struct device *dev)
+__NCR_700_detect(struct scsi_host_template *tpnt,
+		 struct NCR_700_Host_Parameters *hostdata, struct device *dev,
+		 struct module *owner)
 {
 	dma_addr_t pScript, pSlots;
 	__u8 *memory;
@@ -2101,7 +2102,7 @@ STATIC struct device_attribute *NCR_700_dev_attrs[] = {
 	NULL,
 };
 
-EXPORT_SYMBOL(NCR_700_detect);
+EXPORT_SYMBOL(__NCR_700_detect);
 EXPORT_SYMBOL(NCR_700_release);
 EXPORT_SYMBOL(NCR_700_intr);
 
drivers/scsi/53c700.h +5 -2
index e06bdfe..4555958 100644
@@ -54,8 +54,11 @@
 struct NCR_700_Host_Parameters;
 
 /* These are the externally used routines */
-struct Scsi_Host *NCR_700_detect(struct scsi_host_template *,
-		struct NCR_700_Host_Parameters *, struct device *);
+struct Scsi_Host *__NCR_700_detect(struct scsi_host_template *,
+		struct NCR_700_Host_Parameters *, struct device *,
+		struct module *);
+#define NCR_700_detect(tpnt, hostdata, dev) \
+	__NCR_700_detect(tpnt, hostdata, dev, THIS_MODULE)
 int NCR_700_release(struct Scsi_Host *host);
 irqreturn_t NCR_700_intr(int, void *);
 
Signature · 1 line
1.9.1
#6 lore raw

PATCH v4 6/11 scsi: legacy: prepare to move module reference from scsi_host_template to Scsi_Host

In reply to Akinobu Mita

In preparation for moving owner module reference field from struct scsi_host_template to struct Scsi_Host, this converts scsi_register() into macro so that legacy LLDDs can pass THIS_MODULE to scsi_host_alloc() through it instead of scsi_host_template->module.

Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/hosts.c     | 5 +++--
 include/scsi/scsi_host.h | 5 ++++-
 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/scsi/hosts.c +3 -2
index 8bb173e..eb324f1 100644
@@ -499,7 +499,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
 }
 EXPORT_SYMBOL(scsi_host_alloc);
 
-struct Scsi_Host *scsi_register(struct scsi_host_template *sht, int privsize)
+struct Scsi_Host *__scsi_register(struct scsi_host_template *sht, int privsize,
+				  struct module *owner)
 {
 	struct Scsi_Host *shost = scsi_host_alloc(sht, privsize);
 
@@ -513,7 +514,7 @@ struct Scsi_Host *scsi_register(struct scsi_host_template *sht, int privsize)
 		list_add_tail(&shost->sht_legacy_list, &sht->legacy_hosts);
 	return shost;
 }
-EXPORT_SYMBOL(scsi_register);
+EXPORT_SYMBOL(__scsi_register);
 
 void scsi_unregister(struct Scsi_Host *shost)
 {
include/scsi/scsi_host.h +4 -1
index 019e668..0369b4e 100644
@@ -926,7 +926,10 @@ static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)
 }
 
 /* legacy interfaces */
-extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
+extern struct Scsi_Host *__scsi_register(struct scsi_host_template *, int,
+					 struct module *);
+#define scsi_register(sht, privsize) \
+	__scsi_register(sht, privsize, THIS_MODULE)
 extern void scsi_unregister(struct Scsi_Host *);
 extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);
 
Signature · 1 line
1.9.1
#7 lore raw

PATCH v4 7/11 scsi: move module reference from scsi_host_template to Scsi_Host

In reply to Akinobu Mita

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 drivers which consist with the core driver and the actual LLDDs and scsi_host_template is defined in the core driver. In these cases, the actual LLDDs can be unloaded even if the scsi_device is being accessed.

This moves owner module reference from struct scsi_host_template to struct Scsi_Host, and it is passed through scsi_host_alloc(). Some drivers which have the module reference mismatch problem described above can pass their correct module reference by using __scsi_host_alloc() which takes module reference argument.

Sub drivers of esp_scsi (mac_esp, am53c974, sun_esp, jazz_esp, sun3x_esp) use a single scsi_host_template defined in esp_scsi module, so these had module reference mismatch problem, but this change implicitly fixes it. Because sub drivers directly call scsi_host_alloc() and THIS_MODULE is used for the module reference instead of scsi_host_template->module.

Cc Vinayak Holikatti <[email protected]>
Cc Dolev Raviv <[email protected]>
Cc Sujit Reddy Thumma <[email protected]>
Cc Subhash Jadavani <[email protected]>
Cc Matthew Dharm <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Alan Stern <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Mike Christie <[email protected]>
Cc Karen Xie <[email protected]>
Cc Robert Love <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/ata/libata-scsi.c     |  2 +-
 drivers/scsi/53c700.c         |  2 +-
 drivers/scsi/hosts.c          | 11 +++++++----
 drivers/scsi/libfc/fc_lport.c |  2 +-
 drivers/scsi/libfc/fc_npiv.c  |  3 +--
 drivers/scsi/libiscsi.c       |  2 +-
 drivers/scsi/scsi.c           |  4 ++--
 include/scsi/scsi_host.h      |  8 +++++++-
 8 files changed, 21 insertions(+), 13 deletions(-)
drivers/ata/libata-scsi.c +1 -1
index e364e86..20a963c 100644
@@ -3643,7 +3643,7 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
 		struct Scsi_Host *shost;
 
 		rc = -ENOMEM;
-		shost = scsi_host_alloc(sht, sizeof(struct ata_port *));
+		shost = __scsi_host_alloc(sht, sizeof(ap), host->module);
 		if (!shost)
 			goto err_alloc;
 
drivers/scsi/53c700.c +1 -1
index e70fd05..a5777f8 100644
@@ -333,7 +333,7 @@ __NCR_700_detect(struct scsi_host_template *tpnt,
 	if(tpnt->proc_name == NULL)
 		tpnt->proc_name = "53c700";
 
-	host = scsi_host_alloc(tpnt, 4);
+	host = __scsi_host_alloc(tpnt, sizeof(hostdata), owner);
 	if (!host)
 		return NULL;
 	memset(hostdata->slots, 0, sizeof(struct NCR_700_command_slot)
drivers/scsi/hosts.c +7 -4
index eb324f1..90c109e 100644
@@ -354,9 +354,10 @@ static struct device_type scsi_host_type = {
 };
 
 /**
- * scsi_host_alloc - register a scsi host adapter instance.
+ * __scsi_host_alloc - register a scsi host adapter instance.
  * @sht:	pointer to scsi host template
  * @privsize:	extra bytes to allocate for driver
+ * @owner:	module which will be the owner of the scsi host
  *
  * Note:
  * 	Allocate a new Scsi_Host and perform basic initialization.
@@ -366,7 +367,8 @@ static struct device_type scsi_host_type = {
  * Return value:
  * 	Pointer to a new Scsi_Host
  **/
-struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
+struct Scsi_Host *__scsi_host_alloc(struct scsi_host_template *sht,
+				    int privsize, struct module *owner)
 {
 	struct Scsi_Host *shost;
 	gfp_t gfp_mask = GFP_KERNEL;
@@ -411,6 +413,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
 	 */
 	shost->max_cmd_len = 12;
 	shost->hostt = sht;
+	shost->module = owner;
 	shost->this_id = sht->this_id;
 	shost->can_queue = sht->can_queue;
 	shost->sg_tablesize = sht->sg_tablesize;
@@ -497,12 +500,12 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
 	kfree(shost);
 	return NULL;
 }
-EXPORT_SYMBOL(scsi_host_alloc);
+EXPORT_SYMBOL(__scsi_host_alloc);
 
 struct Scsi_Host *__scsi_register(struct scsi_host_template *sht, int privsize,
 				  struct module *owner)
 {
-	struct Scsi_Host *shost = scsi_host_alloc(sht, privsize);
+	struct Scsi_Host *shost = __scsi_host_alloc(sht, privsize, owner);
 
 	if (!sht->detect) {
 		printk(KERN_WARNING "scsi_register() called on new-style "
drivers/scsi/libfc/fc_lport.c +1 -1
index d931e69..54ef1c4 100644
@@ -2158,7 +2158,7 @@ struct fc_lport *__libfc_host_alloc(struct scsi_host_template *sht,
 	struct fc_lport *lport;
 	struct Scsi_Host *shost;
 
-	shost = scsi_host_alloc(sht, sizeof(*lport) + priv_size);
+	shost = __scsi_host_alloc(sht, sizeof(*lport) + priv_size, owner);
 	if (!shost)
 		return NULL;
 	lport = shost_priv(shost);
drivers/scsi/libfc/fc_npiv.c +1 -2
index 86133f9..1cf2abb 100644
@@ -36,8 +36,7 @@ struct fc_lport *libfc_vport_create(struct fc_vport *vport, int privsize)
 	struct fc_lport *n_port = shost_priv(shost);
 	struct fc_lport *vn_port;
 
-	vn_port = __libfc_host_alloc(shost->hostt, privsize,
-				     shost->hostt->module);
+	vn_port = __libfc_host_alloc(shost->hostt, privsize, shost->module);
 	if (!vn_port)
 		return vn_port;
 
drivers/scsi/libiscsi.c +1 -1
index 4c5be6b..6c2ebf3 100644
@@ -2609,7 +2609,7 @@ struct Scsi_Host *__iscsi_host_alloc(struct scsi_host_template *sht,
 	struct Scsi_Host *shost;
 	struct iscsi_host *ihost;
 
-	shost = scsi_host_alloc(sht, sizeof(struct iscsi_host) + dd_data_size);
+	shost = __scsi_host_alloc(sht, sizeof(*ihost) + dd_data_size, owner);
 	if (!shost)
 		return NULL;
 	ihost = shost_priv(shost);
drivers/scsi/scsi.c +2 -2
index e028854..5905b83 100644
@@ -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 +7 -1
index 0369b4e..acdf828 100644
@@ -47,6 +47,7 @@ struct blk_queue_tags;
 #define ENABLE_CLUSTERING 1
 
 struct scsi_host_template {
+	/* This is unused and will be removed after mass conversion */
 	struct module *module;
 	const char *name;
 
@@ -617,6 +618,7 @@ struct Scsi_Host {
 	 */
 	unsigned short max_cmd_len;
 
+	struct module *module;
 	int this_id;
 	int can_queue;
 	short cmd_per_lun;
@@ -783,7 +785,11 @@ static inline bool shost_use_blk_mq(struct Scsi_Host *shost)
 extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
 extern void scsi_flush_work(struct Scsi_Host *);
 
-extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
+extern struct Scsi_Host *__scsi_host_alloc(struct scsi_host_template *, int,
+					struct module *);
+#define scsi_host_alloc(sht, privsize) \
+	__scsi_host_alloc(sht, privsize, THIS_MODULE)
+
 extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,
 					       struct device *,
 					       struct device *);
Signature · 1 line
1.9.1
#8 lore raw

PATCH v4 8/11 scsi: ufs: adjust module reference for scsi host

In reply to Akinobu Mita

The ufs support consists with the core driver (ufshcd) and the actual glue driver (ufshcd-pci or ufshcd-pltfrm). The module reference of this scsi host is initialized to the core driver's one. Because the glue drivers use ufshcd_alloc_host() which is defined in ufshcd module and calls scsi_host_alloc(). So the glue drivers can be unloaded even if the scsi device is being accessed.

This fixes it by converting ufshcd_alloc_host() into macro so that the glue drivers can pass their correct module reference through __scsi_host_alloc().

Cc Vinayak Holikatti <[email protected]>
Cc Dolev Raviv <[email protected]>
Cc Sujit Reddy Thumma <[email protected]>
Cc Subhash Jadavani <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 13 +++++++------
 drivers/scsi/ufs/ufshcd.h |  5 ++++-
 2 files changed, 11 insertions(+), 7 deletions(-)
drivers/scsi/ufs/ufshcd.c +7 -6
index 2e26025..59a4855 100644
@@ -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,
@@ -5256,12 +5255,14 @@ static int ufshcd_set_dma_mask(struct ufs_hba *hba)
 }
 
 /**
- * ufshcd_alloc_host - allocate Host Bus Adapter (HBA)
+ * __ufshcd_alloc_host - allocate Host Bus Adapter (HBA)
  * @dev: pointer to device handle
  * @hba_handle: driver private handle
+ * @owner: module which will be the owner of the scsi host
  * Returns 0 on success, non-zero value on failure
  */
-int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle)
+int __ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle,
+			struct module *owner)
 {
 	struct Scsi_Host *host;
 	struct ufs_hba *hba;
@@ -5274,8 +5275,8 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle)
 		goto out_error;
 	}
 
-	host = scsi_host_alloc(&ufshcd_driver_template,
-				sizeof(struct ufs_hba));
+	host = __scsi_host_alloc(&ufshcd_driver_template,
+				sizeof(struct ufs_hba), owner);
 	if (!host) {
 		dev_err(dev, "scsi_host_alloc failed\n");
 		err = -ENOMEM;
@@ -5289,7 +5290,7 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle)
 out_error:
 	return err;
 }
-EXPORT_SYMBOL(ufshcd_alloc_host);
+EXPORT_SYMBOL(__ufshcd_alloc_host);
 
 static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
 {
drivers/scsi/ufs/ufshcd.h +4 -1
index 4a574aa..ac7d72f 100644
@@ -515,7 +515,10 @@ static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)
 	ufshcd_writel(hba, tmp, reg);
 }
 
-int ufshcd_alloc_host(struct device *, struct ufs_hba **);
+int __ufshcd_alloc_host(struct device *, struct ufs_hba **,
+			struct module *owner);
+#define ufshcd_alloc_host(dev, hba_handle) \
+	__ufshcd_alloc_host(dev, hba_handle, THIS_MODULE)
 int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int);
 void ufshcd_remove(struct ufs_hba *);
 
Signature · 1 line
1.9.1
#9 lore raw

PATCH v4 9/11 usb: storage: adjust module reference for scsi host

In reply to Akinobu Mita

The unusual usb storage drivers (ums-alauda, ums-cypress, ...) depend on usb-storage module. The module reference of these scsi host is initialized to usb-storage's one. Because these drivers use usb_stor_probe1() which is defined in usb-storage module and calls scsi_host_alloc(). So these drivers can be unloaded even if the scsi device is being accessed.

This fixes it by converting usb_stor_probe1() into macro so that these drivers can pass their correct module reference through __scsi_host_alloc().

Cc Matthew Dharm <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Alan Stern <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/usb/storage/scsiglue.c | 3 ---
 drivers/usb/storage/usb.c      | 9 +++++----
 drivers/usb/storage/usb.h      | 7 +++++--
 3 files changed, 10 insertions(+), 9 deletions(-)
drivers/usb/storage/scsiglue.c +0 -3
index 0e400f3..04fab36 100644
@@ -587,9 +587,6 @@ struct scsi_host_template usb_stor_host_template = {
 
 	/* sysfs device attributes */
 	.sdev_attrs =			sysfs_device_attr_list,
-
-	/* module management */
-	.module =			THIS_MODULE
 };
 
 /* To Report "Illegal Request: Invalid Field in CDB */
drivers/usb/storage/usb.c +5 -4
index d468d02..768413f0 100644
@@ -911,10 +911,11 @@ static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf)
 }
 
 /* First part of general USB mass-storage probing */
-int usb_stor_probe1(struct us_data **pus,
+int __usb_stor_probe1(struct us_data **pus,
 		struct usb_interface *intf,
 		const struct usb_device_id *id,
-		struct us_unusual_dev *unusual_dev)
+		struct us_unusual_dev *unusual_dev,
+		struct module *owner)
 {
 	struct Scsi_Host *host;
 	struct us_data *us;
@@ -926,7 +927,7 @@ int usb_stor_probe1(struct us_data **pus,
 	 * Ask the SCSI layer to allocate a host structure, with extra
 	 * space at the end for our private us_data structure.
 	 */
-	host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
+	host = __scsi_host_alloc(&usb_stor_host_template, sizeof(*us), owner);
 	if (!host) {
 		dev_warn(&intf->dev, "Unable to allocate the scsi host\n");
 		return -ENOMEM;
@@ -969,7 +970,7 @@ BadDevice:
 	release_everything(us);
 	return result;
 }
-EXPORT_SYMBOL_GPL(usb_stor_probe1);
+EXPORT_SYMBOL_GPL(__usb_stor_probe1);
 
 /* Second part of general USB mass-storage probing */
 int usb_stor_probe2(struct us_data *us)
drivers/usb/storage/usb.h +5 -2
index 307e339..0cb74ba 100644
@@ -194,10 +194,13 @@ extern int usb_stor_reset_resume(struct usb_interface *iface);
 extern int usb_stor_pre_reset(struct usb_interface *iface);
 extern int usb_stor_post_reset(struct usb_interface *iface);
 
-extern int usb_stor_probe1(struct us_data **pus,
+extern int __usb_stor_probe1(struct us_data **pus,
 		struct usb_interface *intf,
 		const struct usb_device_id *id,
-		struct us_unusual_dev *unusual_dev);
+		struct us_unusual_dev *unusual_dev,
+		struct module *owner);
+#define usb_stor_probe1(pus, intf, id, unusual_dev) \
+	__usb_stor_probe1(pus, intf, id, unusual_dev, THIS_MODULE)
 extern int usb_stor_probe2(struct us_data *us);
 extern void usb_stor_disconnect(struct usb_interface *intf);
 
Signature · 1 line
1.9.1
#10 lore raw

PATCH v4 10/11 ata: ahci_platform: adjust module reference for scsi host

In reply to Akinobu Mita

The ahci platform drivers depend on libahci_platform module. The module reference of these scsi host is initialized to libahci_platform's one. Because these drivers use ahci_platform_init_host() which is defined in libahci_platform module and calls scsi_host_alloc() internally. So these drivers can be unloaded even if the scsi device is being accessed.

This fixes it by converting into ahci_platform_init_host() macro so that these drivers can pass their correct module reference through __ata_host_alloc_pinfo().

Cc Hans de Goede <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/ata/libahci_platform.c | 14 ++++++++------
 include/linux/ahci_platform.h  |  9 ++++++---
 2 files changed, 14 insertions(+), 9 deletions(-)
drivers/ata/libahci_platform.c +8 -6
index 0b03f90..ea75416 100644
@@ -395,10 +395,11 @@ err_out:
 EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
 
 /**
- * ahci_platform_init_host - Bring up an ahci-platform host
+ * __ahci_platform_init_host - Bring up an ahci-platform host
  * @pdev: platform device pointer for the host
  * @hpriv: ahci-host private data for the host
  * @pi_template: template for the ata_port_info to use
+ * @owner: module which will be the owner of the ahci-platform host
  *
  * This function does all the usual steps needed to bring up an
  * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
@@ -407,9 +408,10 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
  * RETURNS:
  * 0 on success otherwise a negative error code
  */
-int ahci_platform_init_host(struct platform_device *pdev,
-			    struct ahci_host_priv *hpriv,
-			    const struct ata_port_info *pi_template)
+int __ahci_platform_init_host(struct platform_device *pdev,
+			      struct ahci_host_priv *hpriv,
+			      const struct ata_port_info *pi_template,
+			      struct module *owner)
 {
 	struct device *dev = &pdev->dev;
 	struct ata_port_info pi = *pi_template;
@@ -443,7 +445,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
 	 */
 	n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
 
-	host = ata_host_alloc_pinfo(dev, ppi, n_ports);
+	host = __ata_host_alloc_pinfo(dev, ppi, n_ports, owner);
 	if (!host)
 		return -ENOMEM;
 
@@ -495,7 +497,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
 
 	return ahci_host_activate(host, irq, &ahci_platform_sht);
 }
-EXPORT_SYMBOL_GPL(ahci_platform_init_host);
+EXPORT_SYMBOL_GPL(__ahci_platform_init_host);
 
 static void ahci_host_stop(struct ata_host *host)
 {
include/linux/ahci_platform.h +6 -3
index 642d6ae..0dcac84 100644
@@ -28,9 +28,12 @@ int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);
 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv);
 struct ahci_host_priv *ahci_platform_get_resources(
 	struct platform_device *pdev);
-int ahci_platform_init_host(struct platform_device *pdev,
-			    struct ahci_host_priv *hpriv,
-			    const struct ata_port_info *pi_template);
+int __ahci_platform_init_host(struct platform_device *pdev,
+			      struct ahci_host_priv *hpriv,
+			      const struct ata_port_info *pi_template,
+			      struct module *owner);
+#define ahci_platform_init_host(pdev, hpriv, pi_template) \
+	__ahci_platform_init_host(pdev, hpriv, pi_template, THIS_MODULE)
 
 int ahci_platform_suspend_host(struct device *dev);
 int ahci_platform_resume_host(struct device *dev);
Signature · 1 line
1.9.1
Acked-by on v4 10/11
#11 lore raw

Re: [PATCH v4 10/11] ata: ahci_platform: adjust module reference for scsi host

Hi,

Quoted 11 lines · Akinobu Mita

The ahci platform drivers depend on libahci_platform module. The module reference of these scsi host is initialized to libahci_platform's one. Because these drivers use ahci_platform_init_host() which is defined in libahci_platform module and calls scsi_host_alloc() internally. So these drivers can be unloaded even if the scsi device is being accessed.

This fixes it by converting into ahci_platform_init_host() macro so that these drivers can pass their correct module reference through __ata_host_alloc_pinfo().

Quoted 7 lines
Cc Hans de Goede <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>

Looks good to me:

Regards,

Hans

Quoted 75 lines
---
  drivers/ata/libahci_platform.c | 14 ++++++++------
  include/linux/ahci_platform.h  |  9 ++++++---
  2 files changed, 14 insertions(+), 9 deletions(-)
drivers/ata/libahci_platform.c +8 -6
index 0b03f90..ea75416 100644
@@ -395,10 +395,11 @@ err_out:
  EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
 
  /**
- * ahci_platform_init_host - Bring up an ahci-platform host
+ * __ahci_platform_init_host - Bring up an ahci-platform host
   * @pdev: platform device pointer for the host
   * @hpriv: ahci-host private data for the host
   * @pi_template: template for the ata_port_info to use
+ * @owner: module which will be the owner of the ahci-platform host
   *
   * This function does all the usual steps needed to bring up an
   * ahci-platform host, note any necessary resources (ie clks, phys, etc.)
@@ -407,9 +408,10 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
   * RETURNS:
   * 0 on success otherwise a negative error code
   */
-int ahci_platform_init_host(struct platform_device *pdev,
-			    struct ahci_host_priv *hpriv,
-			    const struct ata_port_info *pi_template)
+int __ahci_platform_init_host(struct platform_device *pdev,
+			      struct ahci_host_priv *hpriv,
+			      const struct ata_port_info *pi_template,
+			      struct module *owner)
  {
  	struct device *dev = &pdev->dev;
  	struct ata_port_info pi = *pi_template;
@@ -443,7 +445,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
  	 */
  	n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
 
-	host = ata_host_alloc_pinfo(dev, ppi, n_ports);
+	host = __ata_host_alloc_pinfo(dev, ppi, n_ports, owner);
  	if (!host)
  		return -ENOMEM;
 
@@ -495,7 +497,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
 
  	return ahci_host_activate(host, irq, &ahci_platform_sht);
  }
-EXPORT_SYMBOL_GPL(ahci_platform_init_host);
+EXPORT_SYMBOL_GPL(__ahci_platform_init_host);
 
  static void ahci_host_stop(struct ata_host *host)
  {
include/linux/ahci_platform.h +6 -3
index 642d6ae..0dcac84 100644
@@ -28,9 +28,12 @@ int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);
  void ahci_platform_disable_resources(struct ahci_host_priv *hpriv);
  struct ahci_host_priv *ahci_platform_get_resources(
  	struct platform_device *pdev);
-int ahci_platform_init_host(struct platform_device *pdev,
-			    struct ahci_host_priv *hpriv,
-			    const struct ata_port_info *pi_template);
+int __ahci_platform_init_host(struct platform_device *pdev,
+			      struct ahci_host_priv *hpriv,
+			      const struct ata_port_info *pi_template,
+			      struct module *owner);
+#define ahci_platform_init_host(pdev, hpriv, pi_template) \
+	__ahci_platform_init_host(pdev, hpriv, pi_template, THIS_MODULE)
 
  int ahci_platform_suspend_host(struct device *dev);
  int ahci_platform_resume_host(struct device *dev);
#12 lore raw

PATCH v4 11/11 ata: pata_of_platform: adjust module reference for scsi host

In reply to Akinobu Mita

The pata_of_platform driver depends on pata_platform module. The module reference of this scsi host is initialized to pata_platform's one. Because this drivers use __pata_platform_probe() which is defined in pata_platform module and calls scsi_host_alloc() internally. So these drivers can be unloaded even if the scsi device is being accessed.

This fixes it by converting into __pata_platform_probe() macro so that these drivers can pass their correct module reference through __ata_host_alloc().

Cc Tejun Heo <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/ata/pata_platform.c  | 18 ++++++++++--------
 include/linux/ata_platform.h | 16 ++++++++++------
 2 files changed, 20 insertions(+), 14 deletions(-)
drivers/ata/pata_platform.c +10 -8
index 1eedfe4..c84e834 100644
@@ -71,13 +71,14 @@ static void pata_platform_setup_port(struct ata_ioports *ioaddr,
 }
 
 /**
- *	__pata_platform_probe		-	attach a platform interface
+ *	___pata_platform_probe		-	attach a platform interface
  *	@dev: device
  *	@io_res: Resource representing I/O base
  *	@ctl_res: Resource representing CTL base
  *	@irq_res: Resource representing IRQ and its flags
  *	@ioport_shift: I/O port shift
  *	@__pio_mask: PIO mask
+ *	@owner: module which will be the owner of the ATA host
  *
  *	Register a platform bus IDE interface. Such interfaces are PIO and we
  *	assume do not support IRQ sharing.
@@ -97,9 +98,10 @@ static void pata_platform_setup_port(struct ata_ioports *ioaddr,
  *
  *	If no IRQ resource is present, PIO polling mode is used instead.
  */
-int __pata_platform_probe(struct device *dev, struct resource *io_res,
-			  struct resource *ctl_res, struct resource *irq_res,
-			  unsigned int ioport_shift, int __pio_mask)
+int ___pata_platform_probe(struct device *dev, struct resource *io_res,
+			   struct resource *ctl_res, struct resource *irq_res,
+			   unsigned int ioport_shift, int __pio_mask,
+			   struct module *owner)
 {
 	struct ata_host *host;
 	struct ata_port *ap;
@@ -124,7 +126,7 @@ int __pata_platform_probe(struct device *dev, struct resource *io_res,
 	/*
 	 * Now that that's out of the way, wire up the port..
 	 */
-	host = ata_host_alloc(dev, 1);
+	host = __ata_host_alloc(dev, 1, owner);
 	if (!host)
 		return -ENOMEM;
 	ap = host->ports[0];
@@ -172,7 +174,7 @@ int __pata_platform_probe(struct device *dev, struct resource *io_res,
 	return ata_host_activate(host, irq, irq ? ata_sff_interrupt : NULL,
 				 irq_flags, &pata_platform_sht);
 }
-EXPORT_SYMBOL_GPL(__pata_platform_probe);
+EXPORT_SYMBOL_GPL(___pata_platform_probe);
 
 static int pata_platform_probe(struct platform_device *pdev)
 {
@@ -215,8 +217,8 @@ static int pata_platform_probe(struct platform_device *pdev)
 	irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 
 	return __pata_platform_probe(&pdev->dev, io_res, ctl_res, irq_res,
-				     pp_info ? pp_info->ioport_shift : 0,
-				     pio_mask);
+				   pp_info ? pp_info->ioport_shift : 0,
+				   pio_mask);
 }
 
 static struct platform_driver pata_platform_driver = {
include/linux/ata_platform.h +10 -6
index 5c618a0..20bca38 100644
@@ -10,12 +10,16 @@ struct pata_platform_info {
 	unsigned int ioport_shift;
 };
 
-extern int __pata_platform_probe(struct device *dev,
-				 struct resource *io_res,
-				 struct resource *ctl_res,
-				 struct resource *irq_res,
-				 unsigned int ioport_shift,
-				 int __pio_mask);
+extern int ___pata_platform_probe(struct device *dev,
+				  struct resource *io_res,
+				  struct resource *ctl_res,
+				  struct resource *irq_res,
+				  unsigned int ioport_shift,
+				  int __pio_mask, struct module *owner);
+#define __pata_platform_probe(dev, io_res, ctl_res, irq_res,		\
+			      ioport_shift, __pio_mask)			\
+	___pata_platform_probe(dev, io_res, ctl_res, irq_res,		\
+			       ioport_shift, __pio_mask, THIS_MODULE)
 
 /*
  * Marvell SATA private data
Signature · 1 line
1.9.1
#13 lore raw
In reply to Akinobu Mita
Quoted 10 lines · Akinobu Mita

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 drivers which consist with the core driver and the actual LLDDs and scsi_host_template is defined in the core driver. In these cases, the actual LLDDs can be unloaded even if the scsi_device is being accessed.

Quoted 5 lines

This patch series fixes the module reference mismatch problem for ufs, usb-storage, esp_scsi, ahci_platform, and pata_platform drivers by moving owner module reference field from struct scsi_host_template to struct Scsi_Host and allowing the LLDDs to set their correct module reference.

Hmmm, can't we just move sht definitions to actual LLDDs? libata can do that easily. sht, as its name implies, is the template for creating the scsi_hosts of a given type. We're now just moving module ownership from sht definition site to whatever callsite the actual instance is being created which can also be wrapped in a separate layer requiring explicit propagation. Why not just propagate sht's directly? What's the difference?

Thanks.

Signature · 1 line
tejun

A message that is not in the archive (sent off-list or not yet received): 20150119142206.GE8140-Gd/HAXX7CRxy/[email protected]

#15 lore raw

2015-01-19 23:22 GMT+09:00 Tejun Heo <[email protected]>:

Quoted 17 lines · Akinobu Mita
Quoted 10 lines

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 drivers which consist with the core driver and the actual LLDDs and scsi_host_template is defined in the core driver. In these cases, the actual LLDDs can be unloaded even if the scsi_device is being accessed.

Quoted 5 lines

This patch series fixes the module reference mismatch problem for ufs, usb-storage, esp_scsi, ahci_platform, and pata_platform drivers by moving owner module reference field from struct scsi_host_template to struct Scsi_Host and allowing the LLDDs to set their correct module reference.

Quoted 7 lines

Hmmm, can't we just move sht definitions to actual LLDDs? libata can do that easily. sht, as its name implies, is the template for creating the scsi_hosts of a given type. We're now just moving module ownership from sht definition site to whatever callsite the actual instance is being created which can also be wrapped in a separate layer requiring explicit propagation. Why not just propagate sht's directly? What's the difference?

The reason I didn't move sht from the core driver to the LLDDs for fixing ufs and ums-* in the first place is to avoid exporting many symbols for callbacks in sht. But I realized that we can do it without that many exported symbols by creating a single function that returns a kmemdup()ed sht with a few change including ->module.

So there are three options we can take for fixing this problem. I would like to know the opinions which one should be taken.

(1) Add owner module field to Scsi_Host for allowing LLDDs to adjust it after scsi host allocation. This approach is used by v1,2,3 of this patch series and the scsi midlayer change is minimum.

(2) Move owner module field from scsi_host_template to Scsi_Host. The owner module reference is retrieved from the callsite of scsi_host_alloc() by passing THIS_MODULE to the extra argument. The scsi midlayer change is small, but we need the same macro trick for each scsi_host_alloc() wrapper and these changes are relatively large (required by libata, libiscsi, libfc, cxgbi, 53c700, legacy). This approach is used by v4 of this patch series.

(3) Allocate scsi host template for each module. No scsi midlayer change is required. Instead of sharing a single scsi host template defined in the core, create a single function that returns a kmemdup()ed sht with a few change including ->module so that the sub modules can use it as their sht.

Signature · 5 lines
You received this message because you are subscribed to the Google Groups "open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at http://groups.google.com/group/open-iscsi.
For more options, visit https://groups.google.com/d/optout.
#16 lore raw

Hello, Akinobu.

Quoted 5 lines · Akinobu Mita

The reason I didn't move sht from the core driver to the LLDDs for fixing ufs and ums-* in the first place is to avoid exporting many symbols for callbacks in sht. But I realized that we can do it without that many exported symbols by creating a single function that returns a kmemdup()ed sht with a few change including ->module.

Hmmm, libata already exports most of the necessary symbols. libahci or platform drivers might have to export more but that shouldn't be much. For libata, pushing sht's to the leaf drivers would make far more sense as sht's already get inherited and modified along the hierarchy.

Thanks.

Signature · 1 line
tejun
maintainer
#17 lore raw
In reply to Akinobu Mita
Quoted 47 lines · Akinobu Mita

2015-01-19 23:22 GMT+09:00 Tejun Heo <[email protected]>:

Quoted 17 lines · Akinobu Mita
Quoted 10 lines

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 drivers which consist with the core driver and the actual LLDDs and scsi_host_template is defined in the core driver. In these cases, the actual LLDDs can be unloaded even if the scsi_device is being accessed.

Quoted 5 lines

This patch series fixes the module reference mismatch problem for ufs, usb-storage, esp_scsi, ahci_platform, and pata_platform drivers by moving owner module reference field from struct scsi_host_template to struct Scsi_Host and allowing the LLDDs to set their correct module reference.

Quoted 7 lines

Hmmm, can't we just move sht definitions to actual LLDDs? libata can do that easily. sht, as its name implies, is the template for creating the scsi_hosts of a given type. We're now just moving module ownership from sht definition site to whatever callsite the actual instance is being created which can also be wrapped in a separate layer requiring explicit propagation. Why not just propagate sht's directly? What's the difference?

The reason I didn't move sht from the core driver to the LLDDs for fixing ufs and ums-* in the first place is to avoid exporting many symbols for callbacks in sht. But I realized that we can do it without that many exported symbols by creating a single function that returns a kmemdup()ed sht with a few change including ->module.

So there are three options we can take for fixing this problem. I would like to know the opinions which one should be taken.

(1) Add owner module field to Scsi_Host for allowing LLDDs to adjust it after scsi host allocation. This approach is used by v1,2,3 of this patch series and the scsi midlayer change is minimum.

(2) Move owner module field from scsi_host_template to Scsi_Host. The owner module reference is retrieved from the callsite of scsi_host_alloc() by passing THIS_MODULE to the extra argument. The scsi midlayer change is small, but we need the same macro trick for each scsi_host_alloc() wrapper and these changes are relatively large (required by libata, libiscsi, libfc, cxgbi, 53c700, legacy). This approach is used by v4 of this patch series.

Quoted 5 lines

(3) Allocate scsi host template for each module. No scsi midlayer change is required. Instead of sharing a single scsi host template defined in the core, create a single function that returns a kmemdup()ed sht with a few change including ->module so that the sub modules can use it as their sht.

(3) means duplicating a reasonably large data structure in order to alter just one field. It also means changing all the subdrivers to make them call the new function.

(1) is the simplest. Since the use of subdrivers in general tends to be a special case (most SCSI drivers don't do it), I prefer to keep the code optimized for it. In other words, I prefer option (1). If people think (2) is better, it can always be layered on top of (1).

Alan Stern

A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.44L0.1501201013440.1150-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org

#19 lore raw

2015-01-21 0:20 GMT+09:00 Alan Stern <stern-nwvwT67g6+6dFdvTe/[email protected]>:

Quoted 55 lines · Akinobu Mita
Quoted 48 lines

2015-01-19 23:22 GMT+09:00 Tejun Heo <[email protected]>:

Quoted 17 lines · Akinobu Mita
Quoted 10 lines

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 drivers which consist with the core driver and the actual LLDDs and scsi_host_template is defined in the core driver. In these cases, the actual LLDDs can be unloaded even if the scsi_device is being accessed.

Quoted 5 lines

This patch series fixes the module reference mismatch problem for ufs, usb-storage, esp_scsi, ahci_platform, and pata_platform drivers by moving owner module reference field from struct scsi_host_template to struct Scsi_Host and allowing the LLDDs to set their correct module reference.

Quoted 7 lines

Hmmm, can't we just move sht definitions to actual LLDDs? libata can do that easily. sht, as its name implies, is the template for creating the scsi_hosts of a given type. We're now just moving module ownership from sht definition site to whatever callsite the actual instance is being created which can also be wrapped in a separate layer requiring explicit propagation. Why not just propagate sht's directly? What's the difference?

The reason I didn't move sht from the core driver to the LLDDs for fixing ufs and ums-* in the first place is to avoid exporting many symbols for callbacks in sht. But I realized that we can do it without that many exported symbols by creating a single function that returns a kmemdup()ed sht with a few change including ->module.

So there are three options we can take for fixing this problem. I would like to know the opinions which one should be taken.

(1) Add owner module field to Scsi_Host for allowing LLDDs to adjust it after scsi host allocation. This approach is used by v1,2,3 of this patch series and the scsi midlayer change is minimum.

(2) Move owner module field from scsi_host_template to Scsi_Host. The owner module reference is retrieved from the callsite of scsi_host_alloc() by passing THIS_MODULE to the extra argument. The scsi midlayer change is small, but we need the same macro trick for each scsi_host_alloc() wrapper and these changes are relatively large (required by libata, libiscsi, libfc, cxgbi, 53c700, legacy). This approach is used by v4 of this patch series.

Quoted 5 lines

(3) Allocate scsi host template for each module. No scsi midlayer change is required. Instead of sharing a single scsi host template defined in the core, create a single function that returns a kmemdup()ed sht with a few change including ->module so that the sub modules can use it as their sht.

Quoted 8 lines

(3) means duplicating a reasonably large data structure in order to alter just one field. It also means changing all the subdrivers to make them call the new function.

(1) is the simplest. Since the use of subdrivers in general tends to be a special case (most SCSI drivers don't do it), I prefer to keep the code optimized for it. In other words, I prefer option (1). If people think (2) is better, it can always be layered on top of (1).

OK, I agree that (1) is the simplest.

Christoph,

Option (2) required a lot of changes as this v4 shows that scsi_host_alloc() is used by several libraries on scsi mid level in various forms. It is a bit different from pci_register_driver() or similar registration interfaces. Although they also use the same macro trick to get a module reference, but they are called directly or through thin and straightforward wrapper interfaces by lower level drivers.

So, option (1) seems to be a better choice than (2), (3) for fixing ufs, ums-*, and esp_scsi drivers. For ahci_platform and pata_platform, they can be fixed easily by moving sht definision to LLDDs as Tejun suggested. Do you think it is ok to prepare v5 of series in this way?

Signature · 5 lines
You received this message because you are subscribed to the Google Groups "open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at http://groups.google.com/group/open-iscsi.
For more options, visit https://groups.google.com/d/optout.