SCSI patches for kernel v4.14
Subsystems (4)
cover SCSI patches for kernel v4.14
Hello Martin,
The patches in this series fall into two categories:
- Two patches are related to using blk_mq_rq_to_pdu() instead of struct request.special.
- Seventeen patches suppress warnings reported by static analysis tools. These tools are very useful but unfortunately the current code base makes these tools report a significant number of false positives.
Please consider these patches for kernel v4.14.
Thanks,
Bart.
Bart Van Assche (19):
Remove an obsolete function declaration
Avoid sign extension of scsi_device.type
Suppress gcc 7 fall-through warnings reported with W=1 Convert a strncmp() call into a strcmp() call scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it Document which queue type a function is intended for
Fix RCU handling of scsi_device.vpd_pg8[03]
Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer sd, sr: Convert two assignments into warning statements
sd: Fix indentation
sd: Remove a useless comparison
sg: Fix type of last blk_trace_setup() argument
libiscsi: Fix indentation
libsas: Remove a set-but-not-used variable
libsas: Annotate fall-through in a switch statement scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value
scsi_transport_srp: Suppress a W=1 compiler warning
scsi_debug: Remove a set-but-not-used variable
iscsi_tcp: Remove a set-but-not-used variable
drivers/scsi/iscsi_tcp.c | 2 -- drivers/scsi/libiscsi.c | 2 +- drivers/scsi/libsas/sas_ata.c | 1 + drivers/scsi/libsas/sas_scsi_host.c | 3 --- drivers/scsi/scsi.c | 6 +++--- drivers/scsi/scsi_debug.c | 3 +-- drivers/scsi/scsi_error.c | 10 ++++++++-- drivers/scsi/scsi_ioctl.c | 4 +++- drivers/scsi/scsi_lib.c | 36 +++++++++++++++++++++--------------- drivers/scsi/scsi_sysfs.c | 9 ++++++--- drivers/scsi/scsi_transport_sas.c | 3 +++ drivers/scsi/scsi_transport_srp.c | 2 +- drivers/scsi/sd.c | 6 +++--- drivers/scsi/sg.c | 3 +-- drivers/scsi/sr.c | 2 +- include/scsi/scsi_cmnd.h | 1 - include/scsi/scsi_device.h | 2 +- include/scsi/scsi_tcq.h | 2 +- 18 files changed, 55 insertions(+), 42 deletions(-)
Signature · 1 line
2.14.0
PATCH 1/19 Remove an obsolete function declaration
Commit e9c787e65c0c ("scsi: allocate scsi_cmnd structures as part of struct request") removed the scsi_get_command() function. Hence also remove the declaration of that function.
--- include/scsi/scsi_cmnd.h | 1 - 1 file changed, 1 deletion(-)
include/scsi/scsi_cmnd.h +0 -1
@@ -158,7 +158,6 @@ static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)return *(struct scsi_driver **)cmd->request->rq_disk->private_data; } -extern struct scsi_cmnd *scsi_get_command (struct scsi_device *,gfp_t );extern void scsi_put_command (struct scsi_cmnd *);extern void scsi_finish_command (struct scsi_cmnd *cmd);
Signature · 1 line
2.14.0
Re: [PATCH 01/19] Remove an obsolete function declaration
Looks good,
PATCH 2/19 Avoid sign extension of scsi_device.type
In reply to Bart Van AsscheThis patch avoids that smatch reports the following:
drivers/scsi/scsi_sysfs.c:506 scsi_bus_uevent() warn: argument 3 to %02x specifier has type 'char' drivers/scsi/scsi_sysfs.c:872 sdev_show_modalias() warn: argument 4 to %02x specifier has type 'char'
--- include/scsi/scsi_device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/scsi/scsi_device.h +1 -1
@@ -111,7 +111,7 @@ struct scsi_device {unsigned sector_size;/* size in bytes */ void *hostdata;/* available to low-level driver */ -char type; +unsigned char type;char scsi_level;char inq_periph_qual;/* PQ from INQUIRY data */ struct mutex inquiry_mutex;
Signature · 1 line
2.14.0
Re: [PATCH 02/19] Avoid sign extension of scsi_device.type
Quoted 19 lines · Bart Van Assche
This patch avoids that smatch reports the following:
drivers/scsi/scsi_sysfs.c:506scsi_bus_uevent()warn: argument 3 to %02x specifier has type 'char'drivers/scsi/scsi_sysfs.c:872sdev_show_modalias()warn: argument 4 to %02x specifier has type 'char'Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- include/scsi/scsi_device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/scsi/scsi_device.h +0
-0
include/scsi/scsi_device.h struct scsi_device { · line 117
Quoted 8 lines
include/scsi/scsi_device.h +1
-1@@ -111,7 +111,7 @@ struct scsi_device {unsigned sector_size;/* size in bytes */ void *hostdata;/* available to low-level driver */ -char type; +unsigned char type;char scsi_level;char inq_periph_qual;/* PQ from INQUIRY data */ struct mutex inquiry_mutex;
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
Re: [PATCH 02/19] Avoid sign extension of scsi_device.type
In reply to Bart Van AsscheLooks fine,
PATCH 3/19 Suppress gcc 7 fall-through warnings reported with W=1
In reply to Bart Van AsscheThe conclusion of a recent discussion about the new warnings reported by gcc 7 is that the new warnings reported when building with W=1 should be suppressed. However, gcc 7 still warns about fall-through in switch statements when building with W=1. Suppress these warnings by annotating the SCSI core properly.
See also Linus Torvalds, Lots of new warnings with gcc-7.1.1, 11
July 2017 (https://www.mail-archive.com/[email protected]/msg115428.html).
References: commit bd664f6b3e37 ("disable new gcc-7.1.1 warnings for now")
--- drivers/scsi/scsi_error.c | 8 +++++++- drivers/scsi/scsi_ioctl.c | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/scsi/scsi_error.c +7 -1
@@ -552,6 +552,7 @@ int scsi_check_sense(struct scsi_cmnd *scmd)set_host_byte (scmd,DID_ALLOC_FAILURE );return SUCCESS ; } +/* FALLTHROUGH */ case COPY_ABORTED :case VOLUME_OVERFLOW :case MISCOMPARE :
@@ -573,6 +574,7 @@ int scsi_check_sense(struct scsi_cmnd *scmd)return ADD_TO_MLQUEUE ; elseset_host_byte (scmd ,DID_TARGET_FAILURE ); +/* FALLTHROUGH */ case ILLEGAL_REQUEST : if (sshdr.asc == 0x20 || /* Invalid command operation code */
@@ -683,6 +685,7 @@ static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)switch (status_byte (scmd->result)) {case GOOD :scsi_handle_queue_ramp_up (scmd->device); +/* FALLTHROUGH */ case COMMAND_TERMINATED :return SUCCESS ;case CHECK_CONDITION :
@@ -1734,6 +1737,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)set_host_byte (scmd,DID_TIME_OUT );return SUCCESS ; } +/* FALLTHROUGH */ case DID_NO_CONNECT :case DID_BAD_TARGET :/*
@@ -1819,6 +1823,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)* the case of trying to send too many commands to a * tagged queueing device. */ +/* FALLTHROUGH */ case BUSY :/* * device can't talk to us at the moment. Should only
@@ -1831,6 +1836,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)if (scmd->cmnd[0 ] ==REPORT_LUNS ) scmd->device->sdev_target->expecting_lun_change =0 ;scsi_handle_queue_ramp_up (scmd->device); +/* FALLTHROUGH */ case COMMAND_TERMINATED :return SUCCESS ;case TASK_ABORTED :
@@ -2320,8 +2326,8 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg) rtn =scsi_try_host_reset (scmd);if (rtn ==SUCCESS )break ; -default :/* FALLTHROUGH */ +default : rtn =FAILED ;break ; }
drivers/scsi/scsi_ioctl.c +3 -1
@@ -116,13 +116,15 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,case NOT_READY :/* This happens if there is no disc in drive */ if (sdev->removable)break ; +/* FALLTHROUGH */ case UNIT_ATTENTION :if (sdev->removable) { sdev->changed =1 ; result =0 ;/* This is no longer considered an error */ break ; } -default :/* Fall through for non-removable media */ +/* FALLTHROUGH -- for non-removable media */ +default :sdev_printk (KERN_INFO , sdev,"ioctl_internal_command return code = %x\n" , result);
Signature · 1 line
2.14.0
Re: [PATCH 03/19] Suppress gcc 7 fall-through warnings reported with W=1
Looks fine,
PATCH 4/19 Convert a strncmp() call into a strcmp() call
In reply to Bart Van AsscheThis patch avoids that smatch reports the following warning:
drivers/scsi/scsi_sysfs.c:117: check_set() error: strncmp() '"-"' too small (2 vs 20)
--- drivers/scsi/scsi_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_sysfs.c +1 -1
@@ -114,7 +114,7 @@ static int check_set(unsigned long long *val, char *src) {char *last; -if (strncmp (src,"-" ,20 ) ==0 ) { +if (strcmp (src,"-" ) ==0 ) { *val =SCAN_WILD_CARD ; }else {/*
Signature · 1 line
2.14.0
Re: [PATCH 04/19] Convert a strncmp() call into a strcmp() call
Looks fine,
Re: [PATCH 04/19] Convert a strncmp() call into a strcmp() call
In reply to Bart Van AsscheQuoted 18 lines · Bart Van Assche
This patch avoids that smatch reports the following warning:
drivers/scsi/scsi_sysfs.c:117:check_set()error:strncmp()'"-"' too small (2 vs 20)Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/scsi_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/scsi_sysfs.c +0
-0
drivers/scsi/scsi_sysfs.c static int check_set(unsigned long long *val, char *src) · line 120
Quoted 8 lines
drivers/scsi/scsi_sysfs.c +1
-1@@ -114,7 +114,7 @@ static int check_set(unsigned long long *val, char *src) {char *last; -if (strncmp (src,"-" ,20 ) ==0 ) { +if (strcmp (src,"-" ) ==0 ) { *val =SCAN_WILD_CARD ; }else {/*
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 5/19 scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it
In reply to Bart Van AsscheThe functional changes in this patch for scsi_setup_fs_cmnd() are:
- scsi_request.sense_len is cleared. This is OK since it is the responsibility of the LLD to set .sense_len before calling .scsi_done().
- scsi_request.cmd_len is changed to BLK_MAX_CDB. This is fine since scsi_driver.init_command() must overwrite this member for FS commands.
--- drivers/scsi/scsi_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_lib.c +2 -2
@@ -1215,8 +1215,8 @@ static int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)return ret; } - cmd->cmnd =scsi_req (req)->cmd =scsi_req (req)->__cmd; -memset (cmd->cmnd,0 ,BLK_MAX_CDB ); +scsi_req_init (&cmd->req); + cmd->cmnd = cmd->req.cmd;return scsi_cmd_to_driver (cmd)->init_command (cmd); }
Signature · 1 line
2.14.0
Re: [PATCH 05/19] scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it
I don't really see the point of doing more work in exactly the same amount of code here, especially given that this is the fast path.
Do you need this for any future patches?
Re: [PATCH 05/19] scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it
Quoted 4 lines · Christoph Hellwig
I don't really see the point of doing more work in exactly the same amount of code here, especially given that this is the fast path.
Do you need this for any future patches?
Hello Christoph,
I will drop this patch.
Bart.
PATCH 6/19 Document which queue type a function is intended for
In reply to Bart Van AsscheDocument which queue type a function is intended for if this is not easy to derive from the function name.
--- drivers/scsi/scsi_lib.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/scsi/scsi_lib.c +6 -0
@@ -2006,6 +2006,7 @@ static enum blk_eh_timer_return scsi_timeout(struct request *req,return scsi_times_out (req); } +/* scsi-mq */ static int scsi_init_request (struct blk_mq_tag_set *set,struct request *rq,unsigned int hctx_idx,unsigned int numa_node) {
@@ -2031,6 +2032,7 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,return 0 ; } +/* scsi-mq */ static void scsi_exit_request (struct blk_mq_tag_set *set,struct request *rq,unsigned int hctx_idx) {
@@ -2070,6 +2072,7 @@ static u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)return bounce_limit; } +/* scsi-sq and scsi-mq */ void __scsi_init_queue (struct Scsi_Host *shost,struct request_queue *q) {struct device *dev = shost->dma_dev;
@@ -2109,6 +2112,7 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) }EXPORT_SYMBOL_GPL (__scsi_init_queue); +/* scsi-sq */ static int scsi_init_rq (struct request_queue *q,struct request *rq,gfp_t gfp) {struct Scsi_Host *shost = q->rq_alloc_data;
@@ -2139,6 +2143,7 @@ static int scsi_init_rq(struct request_queue *q, struct request *rq, gfp_t gfp)return -ENOMEM ; } +/* scsi-sq */ static void scsi_exit_rq (struct request_queue *q,struct request *rq) {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq);
@@ -2149,6 +2154,7 @@ static void scsi_exit_rq(struct request_queue *q, struct request *rq) cmd->sense_buffer); } +/* scsi-sq */ struct request_queue *scsi_alloc_queue (struct scsi_device *sdev) {struct Scsi_Host *shost = sdev->host;
Signature · 1 line
2.14.0
Re: [PATCH 06/19] Document which queue type a function is intended for
Quoted 2 lines · Bart Van Assche
Document which queue type a function is intended for if this is not easy to derive from the function name.
How about adding mq and legacy to the function names instead?
Re: [PATCH 06/19] Document which queue type a function is intended for
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Bart Van Assche
Document which queue type a function is intended for if this is not easy to derive from the function name.
How about adding mq and legacy to the function names instead?
Hello Christoph,
Is something like the patch below perhaps what you had in mind?
[PATCH] Document which queue type a function is intended for
Rename several functions to make it easy to see which queue type a function is intended for.
--- drivers/scsi/scsi_lib.c | 23 ++++++++++++----------- drivers/scsi/scsi_priv.h | 2 +- drivers/scsi/scsi_scan.c | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-)
drivers/scsi/scsi_lib.c +12 -11
@@ -2006,8 +2006,8 @@ static enum blk_eh_timer_return scsi_timeout(struct request *req,return scsi_times_out (req); } -static int scsi_init_request (struct blk_mq_tag_set *set,struct request *rq, -unsigned int hctx_idx,unsigned int numa_node) +static int scsi_mq_init_request (struct blk_mq_tag_set *set,struct request *rq, +unsigned int hctx_idx,unsigned int numa_node) {struct Scsi_Host *shost = set->driver_data;const bool unchecked_isa_dma = shost->unchecked_isa_dma;
@@ -2031,8 +2031,8 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,return 0 ; } -static void scsi_exit_request (struct blk_mq_tag_set *set,struct request *rq, -unsigned int hctx_idx) +static void scsi_mq_exit_request (struct blk_mq_tag_set *set,struct request *rq, +unsigned int hctx_idx) {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq);
@@ -2109,7 +2109,8 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) }EXPORT_SYMBOL_GPL (__scsi_init_queue); -static int scsi_init_rq (struct request_queue *q,struct request *rq,gfp_t gfp) +static int scsi_sq_init_rq (struct request_queue *q,struct request *rq, +gfp_t gfp) {struct Scsi_Host *shost = q->rq_alloc_data;const bool unchecked_isa_dma = shost->unchecked_isa_dma;
@@ -2139,7 +2140,7 @@ static int scsi_init_rq(struct request_queue *q, struct request *rq, gfp_t gfp)return -ENOMEM ; } -static void scsi_exit_rq (struct request_queue *q,struct request *rq) +static void scsi_sq_exit_rq (struct request_queue *q,struct request *rq) {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq);
@@ -2149,7 +2150,7 @@ static void scsi_exit_rq(struct request_queue *q, struct request *rq) cmd->sense_buffer); } -struct request_queue *scsi_alloc_queue (struct scsi_device *sdev) +struct request_queue *scsi_sq_alloc_queue (struct scsi_device *sdev) {struct Scsi_Host *shost = sdev->host;struct request_queue *q;
@@ -2160,8 +2161,8 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev) q->cmd_size =sizeof (struct scsi_cmnd ) + shost->hostt->cmd_size; q->rq_alloc_data = shost; q->request_fn = scsi_request_fn; - q->init_rq_fn = scsi_init_rq; - q->exit_rq_fn = scsi_exit_rq; + q->init_rq_fn = scsi_sq_init_rq; + q->exit_rq_fn = scsi_sq_exit_rq; q->initialize_rq_fn = scsi_initialize_rq;if (blk_init_allocated_queue (q) <0 ) {
@@ -2185,8 +2186,8 @@ static const struct blk_mq_ops scsi_mq_ops = {#ifdef CONFIG_BLK_DEBUG_FS .show_rq = scsi_show_rq, #endif - .init_request = scsi_init_request, - .exit_request = scsi_exit_request, + .init_request = scsi_mq_init_request, + .exit_request = scsi_mq_exit_request, .initialize_rq_fn = scsi_initialize_rq, .map_queues = scsi_map_queues, };
drivers/scsi/scsi_priv.h +1 -1
@@ -88,7 +88,7 @@ extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason);extern void scsi_io_completion (struct scsi_cmnd *,unsigned int );extern void scsi_run_host_queues (struct Scsi_Host *shost);extern void scsi_requeue_run_queue (struct work_struct *work); -extern struct request_queue *scsi_alloc_queue (struct scsi_device *sdev); +extern struct request_queue *scsi_sq_alloc_queue (struct scsi_device *sdev);extern struct request_queue *scsi_mq_alloc_queue (struct scsi_device *sdev);extern void scsi_start_queue (struct scsi_device *sdev);extern int scsi_mq_setup_tags (struct Scsi_Host *shost);
drivers/scsi/scsi_scan.c +1 -1
@@ -268,7 +268,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,if (shost_use_blk_mq (shost)) sdev->request_queue =scsi_mq_alloc_queue (sdev);else - sdev->request_queue =scsi_alloc_queue (sdev); + sdev->request_queue =scsi_sq_alloc_queue (sdev);if (!sdev->request_queue) {/* release fn is set up in scsi_sysfs_device_initialise, so * have to free and put manually here */
Signature · 1 line
2.14.0
Re: [PATCH 06/19] Document which queue type a function is intended for
Quoted 1 line · Bart Van Assche
Is something like the patch below perhaps what you had in mind?
Yes. Except that I really don't like the sq naming - blk-mq can also be used for single queues, so it's a rather confusing name Something like legacy or old seems to be more suitable.
Re: [PATCH 06/19] Document which queue type a function is intended for
Quoted 6 lines · On Thu, 2017-08-24 at 18:58 +0200, [email protected] wrote:
Quoted 1 line · Bart Van Assche
Is something like the patch below perhaps what you had in mind?
Yes. Except that I really don't like the sq naming - blk-mq can also be used for single queues, so it's a rather confusing name Something like legacy or old seems to be more suitable.
Hello Christoph,
Unless anyone prefers otherwise I will use "old" because the same word is already used in the device mapper to refer to legacy request processing code.
Bart.
Re: [PATCH 06/19] Document which queue type a function is intended for
In reply to Bart Van AsscheQuoted 11 lines · Bart Van Assche
Document which queue type a function is intended for if this is not easy to derive from the function name.
Signed-off-by Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/scsi_lib.c | 6 ++++++ 1 file changed, 6 insertions(+)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 7/19 Fix RCU handling of scsi_device.vpd_pg8[03]
In reply to Bart Van AsscheOnly annotate pointers that are shared across threads with __rcu. Use rcu_dereference() when dereferencing an RCU pointer. Protect also the RCU pointer dereferences when freeing RCU pointers. This patch suppresses about twenty sparse complaints about the vpd_pg8[03] pointers.
--- drivers/scsi/scsi.c | 6 +++--- drivers/scsi/scsi_lib.c | 8 ++++---- drivers/scsi/scsi_sysfs.c | 7 +++++-- 3 files changed, 12 insertions(+), 9 deletions(-)
drivers/scsi/scsi.c +3 -3
@@ -426,7 +426,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)int vpd_len =SCSI_VPD_PG_LEN ;int pg80_supported =0 ;int pg83_supported =0 ; -unsigned char __rcu *vpd_buf, *orig_vpd_buf =NULL ; +unsigned char *vpd_buf, *orig_vpd_buf =NULL ;if (!scsi_device_supports_vpd (sdev))return ;
@@ -474,7 +474,7 @@ void scsi_attach_vpd(struct scsi_device *sdev) goto retry_pg80; }mutex_lock (&sdev->inquiry_mutex); - orig_vpd_buf = sdev->vpd_pg80; + orig_vpd_buf =rcu_dereference (sdev->vpd_pg80); sdev->vpd_pg80_len = result;rcu_assign_pointer (sdev->vpd_pg80, vpd_buf);mutex_unlock (&sdev->inquiry_mutex);
@@ -503,7 +503,7 @@ void scsi_attach_vpd(struct scsi_device *sdev) goto retry_pg83; }mutex_lock (&sdev->inquiry_mutex); - orig_vpd_buf = sdev->vpd_pg83; + orig_vpd_buf =rcu_dereference (sdev->vpd_pg83); sdev->vpd_pg83_len = result;rcu_assign_pointer (sdev->vpd_pg83, vpd_buf);mutex_unlock (&sdev->inquiry_mutex);
drivers/scsi/scsi_lib.c +4 -4
@@ -3282,7 +3282,7 @@ int scsi_vpd_lun_id(struct scsi_device *sdev, char *id, size_t id_len)u8 cur_id_type =0xff ;u8 cur_id_size =0 ;unsigned char *d, *cur_id_str; -unsigned char __rcu *vpd_pg83; +unsigned char *vpd_pg83;int id_size = -EINVAL ;rcu_read_lock ();
@@ -3431,7 +3431,7 @@ EXPORT_SYMBOL(scsi_vpd_lun_id);int scsi_vpd_tpg_id (struct scsi_device *sdev,int *rel_id) {unsigned char *d; -unsigned char __rcu *vpd_pg83; +unsigned char *vpd_pg83;int group_id = -EAGAIN , rel_port =-1 ;rcu_read_lock ();
@@ -3441,8 +3441,8 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)return -ENXIO ; } - d = sdev->vpd_pg83 +4 ; -while (d < sdev->vpd_pg83 + sdev->vpd_pg83_len) { + d = vpd_pg83 +4 ; +while (d < vpd_pg83 + sdev->vpd_pg83_len) {switch (d[1 ] &0xf ) {case 0x4 :/* Relative target port */
drivers/scsi/scsi_sysfs.c +5 -2
@@ -456,8 +456,11 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)/* NULL queue means the device can't be used */ sdev->request_queue =NULL ; -kfree (sdev->vpd_pg83); -kfree (sdev->vpd_pg80); +mutex_lock (&sdev->inquiry_mutex); +kfree (rcu_dereference (sdev->vpd_pg83)); +kfree (rcu_dereference (sdev->vpd_pg80)); +mutex_unlock (&sdev->inquiry_mutex); +kfree (sdev->inquiry);kfree (sdev);
Signature · 1 line
2.14.0
Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Quoted 5 lines · Bart Van Assche
Only annotate pointers that are shared across threads with
__rcu. Usercu_dereference()when dereferencing an RCU pointer. Protect also the RCU pointer dereferences when freeing RCU pointers. This patch suppresses about twenty sparse complaints about the vpd_pg8[03] pointers.
Shouldn't the kfrees be kfree_rcu? or where else is the rcu protection for them?
Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Bart Van Assche
Only annotate pointers that are shared across threads with
__rcu. Usercu_dereference()when dereferencing an RCU pointer. Protect also the RCU pointer dereferences when freeing RCU pointers. This patch suppresses about twenty sparse complaints about the vpd_pg8[03] pointers.Shouldn't the kfrees be
kfree_rcu? or where else is the rcu protection for them?
Hello Christoph,
My understanding of the SCSI VPD code is as follows:
* rcu_read_lock() / rcu_read_unlock() is used to prevent that another thread updates a VPD buffer while it is being read.
* All code that either updates or reads a VPD buffer holds a reference on the SCSI device that buffer is associated with. That is why I think it is not needed to use kfree_rcu() in scsi_device_dev_release_usercontext().
Bart.
RE: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Quoted 17 lines
-----Original Message-----
From: Bart Van Assche [mailto:[email protected]]
Sent: Friday, August 25, 2017 2:54 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Seymour, Shane M <[email protected]>
Subject: Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Bart Van Assche
Only annotate pointers that are shared across threads with
__rcu. Usercu_dereference()when dereferencing an RCU pointer. Protect also the RCU pointer dereferences when freeing RCU pointers. This patch suppresses about twenty sparse complaints about the vpd_pg8[03] pointers.
Quoted 5 lines
Quoted 2 lines
Shouldn't the kfrees be
kfree_rcu? or where else is the rcu protection for them?Hello Christoph,
Hi Bart,
Quoted 3 lines
My understanding of the SCSI VPD code is as follows:
*rcu_read_lock()/rcu_read_unlock()is used to prevent that another thread updates a VPD buffer while it is being read.
My understanding is that it doesn't do that - you can update an RCU pointer with rcu_assign_pointer() after someone has called rcu_read_lock() and before they call rcu_read_unlock().
What rcu_read_lock() / rcu_read_unlock() do is mark a read-side critical section when accessing an RCU data item. If you have 2 CPUs in a read-side critical section and a 3rd CPU replacing the pointer using rcu_assign_pointer() one CPU could potentially end up with the old pointer and the other one with the new pointer or both old or both new (the only guarantee you have is that the pointer won't be partially updated with bits of old and the new pointer). To free the old pointer directly you have to call synchronize_rcu() after which you can call kfree() or if you don't call synchronize_rcu() you have to use a delayed freeing mechanism like kfree_rcu() so you can guarantee that the old pointer is still valid while used in a read-side critical section. Using something like kfree_rcu() means that you also don’t have to wait like I believe you can do if you call synchronize_rcu() since you could be forced to wait for a RCU grace period to end before you can call kfree().
So what they really do is ensure that someone updating the pointer can't free the old pointer (in case someone is using it) until everyone has left their read-side critical section (if the read-side critical section started before synchronize_rcu() was called).
You'll find a good example here that uses synchronize_rcu():
https://www.kernel.org/doc/Documentation/RCU/whatisRCU.txt
Search for " WHAT ARE SOME EXAMPLE USES OF CORE RCU API?" - it has a lot of other information about RCU.
Quoted 3 lines
* All code that either updates or reads a VPD buffer holds a reference on the SCSI device that buffer is associated with. That is why I think it is not needed to use
kfree_rcu()inscsi_device_dev_release_usercontext().
The only counter argument I'd put up into why it shouldn't be done the way you want to is that if someone else sees that code and doesn't understand the context and can't guarantee similar to this situation where all references to the structure should have already been dropped and think that it's ok to directly kfree something returned from rcu_dereference() when it's something that they really shouldn't do. The only real difference is that kfree_rcu will return the memory for reuse when RCU processing gets done in softirq and what you're doing will do it immediately. It's easier to use kfree_rcu() from what I can see.
It is possible I may be being too picky (it's a personal failing sometimes) but is it really that a large overhead to free the RCU pointers in a way that RCU pointers are expected to work even if the pointers shouldn't be accessible to anything?
Shane
Quoted 3 lines
Bart.
Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Quoted 7 lines · Shane M
Quoted 3 lines
My understanding of the SCSI VPD code is as follows:
*rcu_read_lock()/rcu_read_unlock()is used to prevent that another thread updates a VPD buffer while it is being read.My understanding is that it doesn't do that - you can update an RCU pointer with
rcu_assign_pointer()after someone has calledrcu_read_lock()and before they callrcu_read_unlock().
Indeed.
Quoted 7 lines
What
rcu_read_lock()/rcu_read_unlock()do is mark a read-side critical section when accessing an RCU data item. If you have 2 CPUs in a read-side critical section and a 3rd CPU replacing the pointer usingrcu_assign_pointer()one CPU could potentially end up with the old pointer and the other one with the new pointer or both old or both new (the only guarantee you have is that the pointer won't be partially updated with bits of old and the new pointer).
Exactly.
Quoted 3 lines
To free the old pointer directly you have to call
synchronize_rcu()after which you can callkfree()or if you don't callsynchronize_rcu()you have to use a delayed freeing mechanism likekfree_rcu()
(or call_rcu for the more general case)
Quoted 5 lines
so you can guarantee that the old pointer is still valid while used in a read-side critical section. Using something like
kfree_rcu()means that you also don’t have to wait like I believe you can do if you callsynchronize_rcu()since you could be forced to wait for a RCU grace period to end before you can callkfree().
Yes, call_rcu (including the kfree_rcu helper) schedules a delayed action after the grace period, synchronize_rcu synchronously waits for the end of the grace period.
Quoted 3 lines
Quoted 3 lines
* All code that either updates or reads a VPD buffer holds a reference on the SCSI device that buffer is associated with. That is why I think it is not needed to use
kfree_rcu()inscsi_device_dev_release_usercontext().
But a reference could be dropped during the grace period. We'll need to either wait for the grace period after NULLing out the vpd pointers or before freeing the allocations for them. Currently the only rcu synchronization in the scsi code is after assining the vpd pointers (in which case we'd only need it whe replacing the previous one, which should not happen in practice anyway), but I can't find anything in the free path.
Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
In reply to Seymour, Shane MQuoted 9 lines · Shane M
Quoted 5 lines
From: Bart Van Assche [mailto:[email protected]]
[ ... ]
My understanding of the SCSI VPD code is as follows:
*rcu_read_lock()/rcu_read_unlock()is used to prevent that another thread updates a VPD buffer while it is being read.My understanding is that it doesn't do that - you can update an RCU pointer with
rcu_assign_pointer()after someone has calledrcu_read_lock()and before they callrcu_read_unlock().
Hello Shane,
You have either misinterpret my statement or the SCSI VPD handling code. If you have a look at the SCSI VPD handling code you will see that an rcu_read_lock() / rcu_read_unlock() pair is sufficient to prevent that the VPD buffer rcu_dereference() points at is being modified as long as the RCU read lock is held, at least if rcu_dereference() is only called once. The update side namely does not modify the VPD buffer after the pointer to that buffer has been published.
Quoted 4 lines
It is possible I may be being too picky (it's a personal failing sometimes) but is it really that a large overhead to free the RCU pointers in a way that RCU pointers are expected to work even if the pointers shouldn't be accessible to anything?
Switching to kfree_rcu() requires more changes because all unsigned char pointers to VPD data have to be converted into pointers to a structure that contains the VPD data and the RCU head. Anyway, I will convert the kfree() calls to RCU pointers into kfree_rcu() pointers.
Bart.
RE: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Quoted 10 lines
Hello Shane,
You have either misinterpret my statement or the SCSI VPD handling code. If you have a look at the SCSI VPD handling code you will see that an
rcu_read_lock()/rcu_read_unlock()pair is sufficient to prevent that the VPD bufferrcu_dereference()points at is being modified as long as the RCU read lock is held, at least ifrcu_dereference()is only called once. The update side namely does not modify the VPD buffer after the pointer to that buffer has been published.
Hi Bart,
I'm pretty sure I understood the code. My main point was that the only thing that RCU guarantees with code in between rcu_read_lock()/rcu_read_unlock() if you dereference an RCU pointer using rcu_dereference() is that the memory that the pointer returned points to won't be freed and will be valid regardless of if you get the new or old pointer. Anything related to the actual contents of what the pointer points to is code specific in regard to what happens to it.
As Christoph pointed out (which I failed to consider fully) by doing a direct kfree in scsi_device_dev_release_usercontext() without a call to synchronize_rcu() if you had some code that that got one of the RCU pointers in a read-side critical section and for some reason scsi_device_dev_release_usercontext() got called you could now have an invalid pointer when RCU makes a guarantee that it must be valid. That's what I believe Christoph was discussing in his reply to my email.
Quoted 5 lines
Switching to
kfree_rcu()requires more changes because all unsigned char pointers to VPD data have to be converted into pointers to a structure that contains the VPD data and the RCU head. Anyway, I will convert thekfree()calls to RCU pointers intokfree_rcu()pointers.
Thanks, I appreciate you taking the comments onboard. I've been looking at the new patches today and should post something back by the end of my day today.
Shane
Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
In reply to Bart Van AsscheQuoted 23 lines · Bart Van Assche
Only annotate pointers that are shared across threads with
__rcu. Usercu_dereference()when dereferencing an RCU pointer. Protect also the RCU pointer dereferences when freeing RCU pointers. This patch suppresses about twenty sparse complaints about the vpd_pg8[03] pointers.Fixes commit 09e2b0b14690 ("scsi: rescan VPD attributes")Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>Cc Shane Seymour <[email protected]>--- drivers/scsi/scsi.c | 6 +++--- drivers/scsi/scsi_lib.c | 8 ++++---- drivers/scsi/scsi_sysfs.c | 7 +++++-- 3 files changed, 12 insertions(+), 9 deletions(-)drivers/scsi/scsi.c +0
-0
drivers/scsi/scsi.c void scsi_attach_vpd(struct scsi_device *sdev) · line 432
Quoted 8 lines
drivers/scsi/scsi.c +1
-1@@ -426,7 +426,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)int vpd_len =SCSI_VPD_PG_LEN ;int pg80_supported =0 ;int pg83_supported =0 ; -unsigned char __rcu *vpd_buf, *orig_vpd_buf =NULL ; +unsigned char *vpd_buf, *orig_vpd_buf =NULL ;if (!scsi_device_supports_vpd (sdev))return ;
Why drop the __rcu annotation here?vpd_buf and orig_vpd_buf should always be accessed via rcu pointers. Did I misunderstood the meaning of the __rcu annotation?
drivers/scsi/scsi.c void scsi_attach_vpd(struct scsi_device *sdev) · line 480
Quoted 9 lines
drivers/scsi/scsi.c +1
-1@@ -474,7 +474,7 @@ void scsi_attach_vpd(struct scsi_device *sdev) goto retry_pg80; }mutex_lock (&sdev->inquiry_mutex); - orig_vpd_buf = sdev->vpd_pg80; + orig_vpd_buf =rcu_dereference (sdev->vpd_pg80); sdev->vpd_pg80_len = result;rcu_assign_pointer (sdev->vpd_pg80, vpd_buf);mutex_unlock (&sdev->inquiry_mutex);
Yeah, I wasn't quite sure if I need to use rcu_dereference here.
drivers/scsi/scsi.c void scsi_attach_vpd(struct scsi_device *sdev) · line 509
Quoted 9 lines
drivers/scsi/scsi.c +1
-1@@ -503,7 +503,7 @@ void scsi_attach_vpd(struct scsi_device *sdev) goto retry_pg83; }mutex_lock (&sdev->inquiry_mutex); - orig_vpd_buf = sdev->vpd_pg83; + orig_vpd_buf =rcu_dereference (sdev->vpd_pg83); sdev->vpd_pg83_len = result;rcu_assign_pointer (sdev->vpd_pg83, vpd_buf);mutex_unlock (&sdev->inquiry_mutex);
Same here.
Quoted 23 lines
drivers/scsi/scsi_lib.c +2
-2@@ -3282,7 +3282,7 @@ int scsi_vpd_lun_id(struct scsi_device *sdev, char *id, size_t id_len)u8 cur_id_type =0xff ;u8 cur_id_size =0 ;unsigned char *d, *cur_id_str; -unsigned char __rcu *vpd_pg83; +unsigned char *vpd_pg83;int id_size = -EINVAL ;rcu_read_lock ();@@ -3431,7 +3431,7 @@ EXPORT_SYMBOL(scsi_vpd_lun_id);int scsi_vpd_tpg_id (struct scsi_device *sdev,int *rel_id) {unsigned char *d; -unsigned char __rcu *vpd_pg83; +unsigned char *vpd_pg83;int group_id = -EAGAIN , rel_port =-1 ;rcu_read_lock ();
drivers/scsi/scsi_lib.c int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id) · line 3448
Quoted 10 lines
drivers/scsi/scsi_lib.c +2
-2@@ -3441,8 +3441,8 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)return -ENXIO ; } - d = sdev->vpd_pg83 +4 ; -while (d < sdev->vpd_pg83 + sdev->vpd_pg83_len) { + d = vpd_pg83 +4 ; +while (d < vpd_pg83 + sdev->vpd_pg83_len) {switch (d[1 ] &0xf ) {case 0x4 :/* Relative target port */
Bah. Yeah, of course.
Quoted 9 lines
drivers/scsi/scsi_sysfs.c +0
-0@@ -456,8 +456,11 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)/* NULL queue means the device can't be used */ sdev->request_queue =NULL ;
drivers/scsi/scsi_sysfs.c static void scsi_device_dev_release_usercontext(struct work_struct *work) · line 466
Quoted 10 lines
drivers/scsi/scsi_sysfs.c +5
-2-kfree (sdev->vpd_pg83); -kfree (sdev->vpd_pg80); +mutex_lock (&sdev->inquiry_mutex); +kfree (rcu_dereference (sdev->vpd_pg83)); +kfree (rcu_dereference (sdev->vpd_pg80)); +mutex_unlock (&sdev->inquiry_mutex); +kfree (sdev->inquiry);kfree (sdev);
As indicated by Shane, I think using 'kfree_rcu()' here might not be a bad idea. You never know ...
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
Re: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Quoted 12 lines · Hannes Reinecke
Quoted 11 lines · Bart Van Assche
drivers/scsi/scsi.c +1
-1@@ -426,7 +426,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)int vpd_len =SCSI_VPD_PG_LEN ;int pg80_supported =0 ;int pg83_supported =0 ; -unsigned char __rcu *vpd_buf, *orig_vpd_buf =NULL ; +unsigned char *vpd_buf, *orig_vpd_buf =NULL ;
Quoted 6 lines
drivers/scsi/scsi.c void scsi_attach_vpd(struct scsi_device *sdev) · line 432
Quoted 2 lines
drivers/scsi/scsi.c +0
-0if (!scsi_device_supports_vpd (sdev))return ;Why drop the
__rcuannotation here?vpd_bufandorig_vpd_bufshould always be accessed via rcu pointers. Did I misunderstood the meaning of the__rcuannotation?
Hello Hannes,
The __rcu annotation must only be used for pointers that are accessed from multiple threads. The vpd_buf pointer is a local variable that is only used from a single context. The family of rcu_dereference() functions expects an __rcu-annotated pointer as argument and returns a regular pointer. See e.g. the example in Documentation/RCU/whatisRCU.txt.
Quoted 8 lines
Quoted 8 lines
drivers/scsi/scsi_sysfs.c +0
-0@@ -456,8 +456,11 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)/* NULL queue means the device can't be used */ sdev->request_queue =NULL ;
Quoted 12 lines
drivers/scsi/scsi_sysfs.c static void scsi_device_dev_release_usercontext(struct work_struct *work) · line 465
Quoted 9 lines
drivers/scsi/scsi_sysfs.c +5
-2-kfree (sdev->vpd_pg83); -kfree (sdev->vpd_pg80); +mutex_lock (&sdev->inquiry_mutex); +kfree (rcu_dereference (sdev->vpd_pg83)); +kfree (rcu_dereference (sdev->vpd_pg80)); +mutex_unlock (&sdev->inquiry_mutex); +kfree (sdev->inquiry);kfree (sdev);As indicated by Shane, I think using '
kfree_rcu()' here might not be a bad idea. You never know ...
I will make that change. Thanks for the reviews!
Bart.
PATCH 8/19 Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer
In reply to Bart Van AsscheSince commit e9c787e65c0c ("scsi: allocate scsi_cmnd structures as part of struct request") struct request and struct scsi_cmnd are adjacent. This means that there is now an alternative to reading req->special to convert a pointer to a prepared request into a SCSI command pointer, namely by using blk_mq_rq_to_pdu(). Make this change where appropriate. Although this patch does not change any functionality, it slightly improves performance and slightly improves readability.
--- drivers/scsi/scsi_error.c | 2 +- drivers/scsi/scsi_lib.c | 18 +++++++++--------- include/scsi/scsi_tcq.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-)
drivers/scsi/scsi_error.c +1 -1
@@ -259,7 +259,7 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scmd)*/ enum blk_eh_timer_return scsi_times_out (struct request *req) { -struct scsi_cmnd *scmd = req->special; +struct scsi_cmnd *scmd =blk_mq_rq_to_pdu (req);enum blk_eh_timer_return rtn =BLK_EH_NOT_HANDLED ;struct Scsi_Host *host = scmd->device->host;
drivers/scsi/scsi_lib.c +9 -9
@@ -627,7 +627,7 @@ static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)static bool scsi_end_request (struct request *req,blk_status_t error,unsigned int bytes,unsigned int bidi_bytes) { -struct scsi_cmnd *cmd = req->special; +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);struct scsi_device *sdev = cmd->device;struct request_queue *q = sdev->request_queue;
@@ -1176,7 +1176,7 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)static int scsi_setup_scsi_cmnd (struct scsi_device *sdev,struct request *req) { -struct scsi_cmnd *cmd = req->special; +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);/* * Passthrough requests may transfer data, in which case they must
@@ -1207,7 +1207,7 @@ static int scsi_setup_scsi_cmnd(struct scsi_device *sdev, struct request *req)*/ static int scsi_setup_fs_cmnd (struct scsi_device *sdev,struct request *req) { -struct scsi_cmnd *cmd = req->special; +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);if (unlikely (sdev->handler && sdev->handler->prep_fn)) {int ret = sdev->handler->prep_fn (sdev, req);
@@ -1222,7 +1222,7 @@ static int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)static int scsi_setup_cmnd (struct scsi_device *sdev,struct request *req) { -struct scsi_cmnd *cmd = req->special; +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);if (!blk_rq_bytes (req)) cmd->sc_data_direction =DMA_NONE ;
@@ -1359,7 +1359,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)static void scsi_unprep_fn (struct request_queue *q,struct request *req) { -scsi_uninit_cmd (req->special); +scsi_uninit_cmd (blk_mq_rq_to_pdu (req)); }/*
@@ -1550,7 +1550,7 @@ static int scsi_lld_busy(struct request_queue *q)*/ static void scsi_kill_request (struct request *req,struct request_queue *q) { -struct scsi_cmnd *cmd = req->special; +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);struct scsi_device *sdev;struct scsi_target *starget;struct Scsi_Host *shost;
@@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)static void scsi_softirq_done (struct request *rq) { -struct scsi_cmnd *cmd = rq->special; +struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq);unsigned long wait_for = (cmd->allowed +1 ) * rq->timeout;int disposition;
@@ -1769,8 +1769,8 @@ static void scsi_request_fn(struct request_queue *q)blk_start_request (req);spin_unlock_irq (q->queue_lock); - cmd = req->special; -if (unlikely (cmd ==NULL )) { + cmd =blk_mq_rq_to_pdu (req); +if (cmd != req->special) { printk(KERN_CRIT "impossible request in %s.\n" "please mail a stack trace to " "[email protected]\n",
include/scsi/scsi_tcq.h +1 -1
@@ -39,7 +39,7 @@ static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,if (!req)return NULL ; - return req->special; + return blk_mq_rq_to_pdu(req); }#endif /* CONFIG_BLOCK */
Signature · 1 line
2.14.0
Re: [PATCH 08/19] Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer
Looks good,
PATCH 9/19 sd, sr: Convert two assignments into warning statements
In reply to Bart Van AsscheBefore scsi_prep_fn() calls the ULP .init_command() callback function it stores the SCSI command pointer in request.special. This means that the SCpnt = rq->special assignments in the sd and sr drivers assign a pointer to itself. Hence convert these two assignment statements into warning statements.
--- drivers/scsi/sd.c | 2 +- drivers/scsi/sr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/sd.c +1 -1
@@ -1013,7 +1013,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) ret =scsi_init_io (SCpnt);if (ret !=BLKPREP_OK ) goto out; - SCpnt = rq->special; +WARN_ON_ONCE (SCpnt != rq->special);/* from here on until we're complete, any goto out * is used for a killable error condition */
drivers/scsi/sr.c +1 -1
@@ -393,7 +393,7 @@ static int sr_init_command(struct scsi_cmnd *SCpnt) ret =scsi_init_io (SCpnt);if (ret !=BLKPREP_OK ) goto out; - SCpnt = rq->special; +WARN_ON_ONCE (SCpnt != rq->special); cd =scsi_cd (rq->rq_disk);/* from here on until we're complete, any goto out
Signature · 1 line
2.14.0
Re: [PATCH 09/19] sd, sr: Convert two assignments into warning statements
Quoted 5 lines · Bart Van Assche
Before
scsi_prep_fn()calls the ULP .init_command() callback function it stores the SCSI command pointer in request.special. This means that the SCpnt =rq->specialassignments in the sd and sr drivers assign a pointer to itself. Hence convert these two assignment statements into warning statements.
Looks good.
Btw, in the longer run we should aim to kill the special pointer in struct request entirely.
PATCH 10/19 sd: Fix indentation
In reply to Bart Van AsscheThis patch avoids that smatch reports the following:
drivers/scsi/sd.c:3540: sd_suspend_common() warn: inconsistent indenting
--- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sd.c +1 -1
@@ -3537,7 +3537,7 @@ static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)* doesn't support sync. There's not much to do and * suspend shouldn't fail. */ - ret =0 ; + ret =0 ; } }
Signature · 1 line
2.14.0
Re: [PATCH 10/19] sd: Fix indentation
Looks good,
Re: [PATCH 10/19] sd: Fix indentation
In reply to Bart Van AsscheQuoted 18 lines · Bart Van Assche
This patch avoids that smatch reports the following:
drivers/scsi/sd.c:3540:sd_suspend_common()warn: inconsistent indentingSigned-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/sd.c +0
-0
drivers/scsi/sd.c static int sd_suspend_common(struct device *dev, bool ignore_stop_errors) · line 3543
Quoted 8 lines
drivers/scsi/sd.c +1
-1@@ -3537,7 +3537,7 @@ static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)* doesn't support sync. There's not much to do and * suspend shouldn't fail. */ - ret =0 ; + ret =0 ; } }
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 11/19 sd: Remove a useless comparison
In reply to Bart Van AsscheThis patch avoids that gcc reports the following warning when building with W=1:
drivers/scsi/sd.c:315:10: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
if (val >= 0 && val <= T10_PI_TYPE3_PROTECTION)
--- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sd.c +1 -1
@@ -312,7 +312,7 @@ protection_type_store(struct device *dev, struct device_attribute *attr,if (err)return err; -if (val >=0 && val <=T10_PI_TYPE3_PROTECTION ) +if (val <=T10_PI_TYPE3_PROTECTION ) sdkp->protection_type = val;return count;
Signature · 1 line
2.14.0
Re: [PATCH 11/19] sd: Remove a useless comparison
Quoted 17 lines · Bart Van Assche
This patch avoids that gcc reports the following warning when building with W=1:
drivers/scsi/sd.c:315:10: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
if (val >= 0 && val <=T10_PI_TYPE3_PROTECTION)Signed-off-by Bart Van Assche <[email protected]>--- drivers/scsi/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/sd.c +0
-0
drivers/scsi/sd.c protection_type_store(struct device *dev, struct device_attribute *attr, · line 318
Quoted 8 lines
drivers/scsi/sd.c +1
-1@@ -312,7 +312,7 @@ protection_type_store(struct device *dev, struct device_attribute *attr,if (err)return err; -if (val >=0 && val <=T10_PI_TYPE3_PROTECTION ) +if (val <=T10_PI_TYPE3_PROTECTION ) sdkp->protection_type = val;return count;
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 12/19 sg: Fix type of last blk_trace_setup() argument
In reply to Bart Van AsscheAvoid that sparse reports the following:
drivers/scsi/sg.c:1114:41: warning: incorrect type in argument 5 (different address spaces)drivers/scsi/sg.c:1114:41: expected char [noderef] <asn:1>*argdrivers/scsi/sg.c:1114:41: got char *<noident>
This patch does not change any functionality.
--- drivers/scsi/sg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/sg.c +1 -2
@@ -1110,8 +1110,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)return blk_trace_setup (sdp->device->request_queue, sdp->disk->disk_name,MKDEV (SCSI_GENERIC_MAJOR , sdp->index), -NULL , - (char *)arg); +NULL , p);case BLKTRACESTART :return blk_trace_startstop (sdp->device->request_queue,1 );case BLKTRACESTOP :
Signature · 1 line
2.14.0
Re: [PATCH 12/19] sg: Fix type of last blk_trace_setup() argument
Looks good,
Re: [PATCH 12/19] sg: Fix type of last blk_trace_setup() argument
In reply to Bart Van AsscheQuoted 22 lines · Bart Van Assche
Avoid that sparse reports the following:
drivers/scsi/sg.c:1114:41: warning: incorrect type in argument 5 (different address spaces)drivers/scsi/sg.c:1114:41: expected char [noderef] <asn:1>*argdrivers/scsi/sg.c:1114:41: got char *<noident>This patch does not change any functionality.
Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/sg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/scsi/sg.c +0
-0
drivers/scsi/sg.c sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) · line 1116
Quoted 9 lines
drivers/scsi/sg.c +1
-2@@ -1110,8 +1110,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)return blk_trace_setup (sdp->device->request_queue, sdp->disk->disk_name,MKDEV (SCSI_GENERIC_MAJOR , sdp->index), -NULL , - (char *)arg); +NULL , p);case BLKTRACESTART :return blk_trace_startstop (sdp->device->request_queue,1 );case BLKTRACESTOP :
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 13/19 libiscsi: Fix indentation
In reply to Bart Van AsscheThis patch avoids that smatch reports the following:
drivers/scsi/libiscsi.c:1081: iscsi_handle_reject() warn: inconsistent indenting
--- drivers/scsi/libiscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/libiscsi.c +1 -1
@@ -1078,7 +1078,7 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,if (opcode !=ISCSI_OP_NOOP_OUT )return 0 ; -if (rejected_pdu.itt ==cpu_to_be32 (ISCSI_RESERVED_TAG )) { +if (rejected_pdu.itt ==cpu_to_be32 (ISCSI_RESERVED_TAG )) {/* * nop-out in response to target's nop-out rejected. * Just resend.
Signature · 1 line
2.14.0
Re: [PATCH 13/19] libiscsi: Fix indentation
Looks good,
Re: [PATCH 13/19] libiscsi: Fix indentation
In reply to Bart Van AsscheQuoted 18 lines · Bart Van Assche
This patch avoids that smatch reports the following:
drivers/scsi/libiscsi.c:1081:iscsi_handle_reject()warn: inconsistent indentingSigned-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/libiscsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/libiscsi.c +0
-0
drivers/scsi/libiscsi.c static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr, · line 1084
Quoted 8 lines
drivers/scsi/libiscsi.c +1
-1@@ -1078,7 +1078,7 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,if (opcode !=ISCSI_OP_NOOP_OUT )return 0 ; -if (rejected_pdu.itt ==cpu_to_be32 (ISCSI_RESERVED_TAG )) { +if (rejected_pdu.itt ==cpu_to_be32 (ISCSI_RESERVED_TAG )) {/* * nop-out in response to target's nop-out rejected. * Just resend.
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 14/19 libsas: Remove a set-but-not-used variable
In reply to Bart Van AsscheThis was detected by building with W=1.
--- drivers/scsi/libsas/sas_scsi_host.c | 3 --- 1 file changed, 3 deletions(-)
drivers/scsi/libsas/sas_scsi_host.c +0 -3
@@ -855,7 +855,6 @@ int sas_target_alloc(struct scsi_target *starget)int sas_slave_configure (struct scsi_device *scsi_dev) {struct domain_device *dev =sdev_to_domain_dev (scsi_dev); -struct sas_ha_struct *sas_ha;BUG_ON (dev->rphy->identify.device_type !=SAS_END_DEVICE );
@@ -864,8 +863,6 @@ int sas_slave_configure(struct scsi_device *scsi_dev)return 0 ; } - sas_ha = dev->port->ha; -sas_read_port_mode_page (scsi_dev);if (scsi_dev->tagged_supported) {
Signature · 1 line
2.14.0
Re: [PATCH 14/19] libsas: Remove a set-but-not-used variable
Looks good,
Re: [PATCH 14/19] libsas: Remove a set-but-not-used variable
In reply to Bart Van AsscheQuoted 24 lines · Bart Van Assche
This was detected by building with W=1.
Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/libsas/sas_scsi_host.c | 3 --- 1 file changed, 3 deletions(-)drivers/scsi/libsas/sas_scsi_host.c +0
-1@@ -855,7 +855,6 @@ int sas_target_alloc(struct scsi_target *starget)int sas_slave_configure (struct scsi_device *scsi_dev) {struct domain_device *dev =sdev_to_domain_dev (scsi_dev); -struct sas_ha_struct *sas_ha;BUG_ON (dev->rphy->identify.device_type !=SAS_END_DEVICE );
drivers/scsi/libsas/sas_scsi_host.c int sas_slave_configure(struct scsi_device *scsi_dev) · line 868
Quoted 8 lines
drivers/scsi/libsas/sas_scsi_host.c +0
-2@@ -864,8 +863,6 @@ int sas_slave_configure(struct scsi_device *scsi_dev)return 0 ; } - sas_ha = dev->port->ha; -sas_read_port_mode_page (scsi_dev);if (scsi_dev->tagged_supported) {
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 15/19 libsas: Annotate fall-through in a switch statement
In reply to Bart Van Assche--- drivers/scsi/libsas/sas_ata.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/libsas/sas_ata.c +1 -0
@@ -343,6 +343,7 @@ static int smp_ata_check_ready(struct ata_link *link)case SAS_END_DEVICE :if (ex_phy->attached_sata_dev)return sas_ata_clear_pending (dev, ex_phy); +/* fall through */ default :return -ENODEV ; }
Signature · 1 line
2.14.0
Re: [PATCH 15/19] libsas: Annotate fall-through in a switch statement
Looks good,
Re: [PATCH 15/19] libsas: Annotate fall-through in a switch statement
In reply to Bart Van AsscheQuoted 14 lines · Bart Van Assche
Signed-off-by Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/libsas/sas_ata.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/libsas/sas_ata.c +0
-0
drivers/scsi/libsas/sas_ata.c static int smp_ata_check_ready(struct ata_link *link) · line 349
Quoted 7 lines
drivers/scsi/libsas/sas_ata.c +1
-0@@ -343,6 +343,7 @@ static int smp_ata_check_ready(struct ata_link *link)case SAS_END_DEVICE :if (ex_phy->attached_sata_dev)return sas_ata_clear_pending (dev, ex_phy); +/* fall through */ default :return -ENODEV ; }
We should be coming to a consensus on how 'fallthrough' is spelled... Other than that:
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 16/19 scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value
In reply to Bart Van AsscheCheck whether memory allocation succeeded before dereferencing the pointer to the allocated memory.
--- drivers/scsi/scsi_transport_sas.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/scsi_transport_sas.c +3 -0
@@ -423,6 +423,9 @@ sas_tlr_supported(struct scsi_device *sdev)char *buffer =kzalloc (vpd_len,GFP_KERNEL );int ret =0 ; +if (!buffer) + goto out; +if (scsi_get_vpd_page (sdev,0x90 , buffer, vpd_len)) goto out;
Signature · 1 line
2.14.0
Re: [PATCH 16/19] scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value
Looks good,
Re: [PATCH 16/19] scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value
In reply to Bart Van AsscheQuoted 17 lines · Bart Van Assche
Check whether memory allocation succeeded before dereferencing the pointer to the allocated memory.
Signed-off-by Bart Van Assche <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/scsi_transport_sas.c | 3 +++ 1 file changed, 3 insertions(+)drivers/scsi/scsi_transport_sas.c +0
-0
drivers/scsi/scsi_transport_sas.c sas_tlr_supported(struct scsi_device *sdev) · line 431
Quoted 9 lines
drivers/scsi/scsi_transport_sas.c +3
-0@@ -423,6 +423,9 @@ sas_tlr_supported(struct scsi_device *sdev)char *buffer =kzalloc (vpd_len,GFP_KERNEL );int ret =0 ; +if (!buffer) + goto out; +if (scsi_get_vpd_page (sdev,0x90 , buffer, vpd_len)) goto out;
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 17/19 scsi_transport_srp: Suppress a W=1 compiler warning
In reply to Bart Van AsscheAvoid that the following compiler warning is reported when building with W=1:
drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false due to limited range of data type [-Wtype-limits]
--- drivers/scsi/scsi_transport_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_transport_srp.c +1 -1
@@ -89,7 +89,7 @@ int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)if (fast_io_fail_tmo <0 && dev_loss_tmo >SCSI_DEVICE_BLOCK_MAX_TIMEOUT )return -EINVAL ; -if (dev_loss_tmo >=LONG_MAX /HZ ) +if (dev_loss_tmo +0UL >=LONG_MAX /HZ )return -EINVAL ;if (fast_io_fail_tmo >=0 && dev_loss_tmo >=0 && fast_io_fail_tmo >= dev_loss_tmo)
Signature · 1 line
2.14.0
Re: [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning
Quoted 18 lines · Bart Van Assche
Avoid that the following compiler warning is reported when building with W=1:
drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false due to limited range of data type [-Wtype-limits]Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/scsi_transport_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/scsi_transport_srp.c +0
-0
drivers/scsi/scsi_transport_srp.c int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo) · line 93
Quoted 6 lines
drivers/scsi/scsi_transport_srp.c +1
-1@@ -89,7 +89,7 @@ int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)if (fast_io_fail_tmo <0 && dev_loss_tmo >SCSI_DEVICE_BLOCK_MAX_TIMEOUT )return -EINVAL ; -if (dev_loss_tmo >=LONG_MAX /HZ ) +if (dev_loss_tmo +0UL >=LONG_MAX /HZ )return -EINVAL ;
That's a weird change.. If we can to promote dev_loss_tmo to long we should just cast it. And of course we should always ask us why we got this warning. If long is 64-bit and int is 32-bit the warning makes sense, as for every reasonable comparism the 32-bit timeout can't be larger than LONG_MAX divided by 100 or 100.
But for 32-bit longs it can, so we should keep it, maybe with a comment.
Re: [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning
Quoted 32 lines · Christoph Hellwig
Quoted 18 lines · Bart Van Assche
Avoid that the following compiler warning is reported when building with W=1:
drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false due to limited range of data type [-Wtype-limits]Signed-off-by Bart Van Assche <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/scsi_transport_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/scsi_transport_srp.c +0
-0drivers/scsi/scsi_transport_srp.c int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo) · line 93
Quoted 6 lines
drivers/scsi/scsi_transport_srp.c +1
-1@@ -89,7 +89,7 @@ int srp_tmo_valid(int reconnect_delay, int fast_io_fail_tmo, int dev_loss_tmo)if (fast_io_fail_tmo <0 && dev_loss_tmo >SCSI_DEVICE_BLOCK_MAX_TIMEOUT )return -EINVAL ; -if (dev_loss_tmo >=LONG_MAX /HZ ) +if (dev_loss_tmo +0UL >=LONG_MAX /HZ )return -EINVAL ;That's a weird change.. If we can to promote
dev_loss_tmoto long we should just cast it. And of course we should always ask us why we got this warning. If long is 64-bit and int is 32-bit the warning makes sense, as for every reasonable comparism the 32-bit timeout can't be larger thanLONG_MAXdivided by 100 or 100.
Quoted 1 line
But for 32-bit longs it can, so we should keep it, maybe with a comment.
Hello Christoph,
The purpose of that check is to avoid that dev_loss_tmo * HZ can overflow. That check is only needed on 32-bit systems since only on these systems sizeof(long) == sizeof(int). How about changing the type of the dev_loss_tmo argument from int to long such that no explicit cast is needed?
Thanks,
Bart.
Re: [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning
Quoted 5 lines · Bart Van Assche
The purpose of that check is to avoid that
dev_loss_tmo* HZ can overflow. That check is only needed on 32-bit systems since only on these systems sizeof(long) == sizeof(int). How about changing the type of thedev_loss_tmoargument from int to long such that no explicit cast is needed?
Yes, switching the timeout to long sounds useful as that's our normal type for timeouts. But it will spread through a lot of the SRP code.
Re: [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning
Quoted 9 lines · On Fri, 2017-08-25 at 17:29 +0200, [email protected] wrote:
Quoted 5 lines · Bart Van Assche
The purpose of that check is to avoid that
dev_loss_tmo* HZ can overflow. That check is only needed on 32-bit systems since only on these systems sizeof(long) == sizeof(int). How about changing the type of thedev_loss_tmoargument from int to long such that no explicit cast is needed?Yes, switching the timeout to long sounds useful as that's our normal type for timeouts. But it will spread through a lot of the SRP code.
Hello Christoph,
Do you agree with the patch below? It seems to be sufficient to suppress the compiler warning.
Thanks,
Bart.
[PATCH] scsi_transport_srp: Suppress a W=1 compiler warning
Avoid that the following compiler warning is reported when building with W=1:
drivers/scsi/scsi_transport_srp.c:92:19: warning: comparison is always false due to limited range of data type [-Wtype-limits]
--- drivers/scsi/scsi_transport_srp.c | 2 +- include/scsi/scsi_transport_srp.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_srp.c +1 -1
@@ -78,7 +78,7 @@ static inline struct srp_rport *shost_to_rport(struct Scsi_Host *shost)* parameters must be such that multipath can detect failed paths timely. * Hence do not allow all three parameters to be disabled simultaneously. */ -int srp_tmo_valid (int reconnect_delay,int fast_io_fail_tmo,int dev_loss_tmo) +int srp_tmo_valid (int reconnect_delay,int fast_io_fail_tmo,long dev_loss_tmo) {if (reconnect_delay <0 && fast_io_fail_tmo <0 && dev_loss_tmo <0 )return -EINVAL ;
include/scsi/scsi_transport_srp.h +1 -1
@@ -111,7 +111,7 @@ extern struct srp_rport *srp_rport_add(struct Scsi_Host *, struct srp_rport_identifiers *);extern void srp_rport_del (struct srp_rport *);extern int srp_tmo_valid (int reconnect_delay,int fast_io_fail_tmo, -int dev_loss_tmo); +long dev_loss_tmo);int srp_parse_tmo (int *tmo,const char *buf);extern int srp_reconnect_rport (struct srp_rport *rport);extern void srp_start_tl_fail_timers (struct srp_rport *rport);
[email protected]
Reviewed-byRe: [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning
This looks good to me:
PATCH 18/19 scsi_debug: Remove a set-but-not-used variable
In reply to Bart Van AsscheThis patch avoids that gcc reports the following warning when building with W=1:
drivers/scsi/scsi_debug.c:2264:15: warning: variable ?pcontrol? set but not used [-Wunused-but-set-variable]
--- drivers/scsi/scsi_debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/scsi_debug.c +1 -2
@@ -2261,7 +2261,7 @@ static int resp_ie_l_pg(unsigned char * arr)static int resp_log_sense (struct scsi_cmnd * scp,struct sdebug_dev_info * devip) { -int ppc, sp, pcontrol, pcode, subpcode, alloc_len, len, n; +int ppc, sp, pcode, subpcode, alloc_len, len, n;unsigned char arr[SDEBUG_MAX_LSENSE_SZ ];unsigned char *cmd = scp->cmnd;
@@ -2272,7 +2272,6 @@ static int resp_log_sense(struct scsi_cmnd * scp,mk_sense_invalid_fld (scp,SDEB_IN_CDB ,1 , ppc ?1 :0 );return check_condition_result; } - pcontrol = (cmd[2 ] &0xc0 ) >>6 ; pcode = cmd[2 ] &0x3f ; subpcode = cmd[3 ] &0xff ; alloc_len =get_unaligned_be16 (cmd +7 );
Signature · 1 line
2.14.0
Re: [PATCH 18/19] scsi_debug: Remove a set-but-not-used variable
Looks fine,
Re: [PATCH 18/19] scsi_debug: Remove a set-but-not-used variable
In reply to Bart Van AsscheQuoted 29 lines · Bart Van Assche
This patch avoids that gcc reports the following warning when building with W=1:
drivers/scsi/scsi_debug.c:2264:15: warning: variable ?pcontrol? set but not used [-Wunused-but-set-variable]Signed-off-by Bart Van Assche <[email protected]>Cc Douglas Gilbert <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/scsi_debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/scsi/scsi_debug.c +1
-1@@ -2261,7 +2261,7 @@ static int resp_ie_l_pg(unsigned char * arr)static int resp_log_sense (struct scsi_cmnd * scp,struct sdebug_dev_info * devip) { -int ppc, sp, pcontrol, pcode, subpcode, alloc_len, len, n; +int ppc, sp, pcode, subpcode, alloc_len, len, n;unsigned char arr[SDEBUG_MAX_LSENSE_SZ ];unsigned char *cmd = scp->cmnd;
drivers/scsi/scsi_debug.c static int resp_log_sense(struct scsi_cmnd * scp, · line 2277
Quoted 7 lines
drivers/scsi/scsi_debug.c +0
-1@@ -2272,7 +2272,6 @@ static int resp_log_sense(struct scsi_cmnd * scp,mk_sense_invalid_fld (scp,SDEB_IN_CDB ,1 , ppc ?1 :0 );return check_condition_result; } - pcontrol = (cmd[2 ] &0xc0 ) >>6 ; pcode = cmd[2 ] &0x3f ; subpcode = cmd[3 ] &0xff ; alloc_len =get_unaligned_be16 (cmd +7 );
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)
PATCH 19/19 iscsi_tcp: Remove a set-but-not-used variable
In reply to Bart Van AsscheThis patch avoids that gcc reports the following warning when building with W=1:
drivers/scsi/iscsi_tcp.c:166:24: warning: variable ?session? set but not used [-Wunused-but-set-variable]
--- drivers/scsi/iscsi_tcp.c | 2 -- 1 file changed, 2 deletions(-)
drivers/scsi/iscsi_tcp.c +0 -2
@@ -163,7 +163,6 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)struct iscsi_tcp_conn *tcp_conn;struct iscsi_sw_tcp_conn *tcp_sw_conn;struct iscsi_conn *conn; -struct iscsi_session *session;void (*old_state_change)(struct sock *);read_lock_bh (&sk->sk_callback_lock);
@@ -172,7 +171,6 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)read_unlock_bh (&sk->sk_callback_lock);return ; } - session = conn->session;iscsi_sw_sk_state_check (sk);
Signature · 1 line
2.14.0
Re: [PATCH 19/19] iscsi_tcp: Remove a set-but-not-used variable
Looks fine,
Re: [PATCH 19/19] iscsi_tcp: Remove a set-but-not-used variable
In reply to Bart Van AsscheQuoted 28 lines · Bart Van Assche
This patch avoids that gcc reports the following warning when building with W=1:
drivers/scsi/iscsi_tcp.c:166:24: warning: variable ?session? set but not used [-Wunused-but-set-variable]Signed-off-by Bart Van Assche <[email protected]>Cc Lee Duncan <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/scsi/iscsi_tcp.c | 2 -- 1 file changed, 2 deletions(-)drivers/scsi/iscsi_tcp.c +0
-1@@ -163,7 +163,6 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)struct iscsi_tcp_conn *tcp_conn;struct iscsi_sw_tcp_conn *tcp_sw_conn;struct iscsi_conn *conn; -struct iscsi_session *session;void (*old_state_change)(struct sock *);read_lock_bh (&sk->sk_callback_lock);
drivers/scsi/iscsi_tcp.c static void iscsi_sw_tcp_state_change(struct sock *sk) · line 176
Quoted 7 lines
drivers/scsi/iscsi_tcp.c +0
-1@@ -172,7 +171,6 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)read_unlock_bh (&sk->sk_callback_lock);return ; } - session = conn->session;iscsi_sw_sk_state_check (sk);
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg)