Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge patch series "Improve the code for showing commands in debugfs"

Bart Van Assche <bvanassche@acm.org> says:

Hi Martin,

The SCSI debugfs code may show information in debugfs that is invalid.
Hence this patch series that makes sure only valid information is shown
in debugfs. Please consider this patch series for the next merge window.

Thanks,

Bart.

Link: https://lore.kernel.org/r/20240325224755.1477910-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

+31 -25
+31 -25
drivers/scsi/scsi_debugfs.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/bitops.h> 3 + #include <linux/cleanup.h> 3 4 #include <linux/seq_file.h> 4 5 #include <scsi/scsi_cmnd.h> 5 6 #include <scsi/scsi_dbg.h> ··· 33 32 return 0; 34 33 } 35 34 35 + static const char *scsi_cmd_list_info(struct scsi_cmnd *cmd) 36 + { 37 + struct Scsi_Host *shost = cmd->device->host; 38 + struct scsi_cmnd *cmd2; 39 + 40 + guard(spinlock_irq)(shost->host_lock); 41 + 42 + list_for_each_entry(cmd2, &shost->eh_abort_list, eh_entry) 43 + if (cmd == cmd2) 44 + return "on eh_abort_list"; 45 + 46 + list_for_each_entry(cmd2, &shost->eh_cmd_q, eh_entry) 47 + if (cmd == cmd2) 48 + return "on eh_cmd_q"; 49 + 50 + return NULL; 51 + } 52 + 36 53 void scsi_show_rq(struct seq_file *m, struct request *rq) 37 54 { 38 - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq), *cmd2; 39 - struct Scsi_Host *shost = cmd->device->host; 55 + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 40 56 int alloc_ms = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc); 41 57 int timeout_ms = jiffies_to_msecs(rq->timeout); 42 - const char *list_info = NULL; 43 58 char buf[80] = "(?)"; 44 59 45 - spin_lock_irq(shost->host_lock); 46 - list_for_each_entry(cmd2, &shost->eh_abort_list, eh_entry) { 47 - if (cmd == cmd2) { 48 - list_info = "on eh_abort_list"; 49 - goto unlock; 50 - } 51 - } 52 - list_for_each_entry(cmd2, &shost->eh_cmd_q, eh_entry) { 53 - if (cmd == cmd2) { 54 - list_info = "on eh_cmd_q"; 55 - goto unlock; 56 - } 57 - } 58 - unlock: 59 - spin_unlock_irq(shost->host_lock); 60 + if (cmd->flags & SCMD_INITIALIZED) { 61 + const char *list_info = scsi_cmd_list_info(cmd); 60 62 61 - __scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len); 62 - seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x, %s%s.flags=", 63 - buf, cmd->retries, cmd->allowed, cmd->result, 64 - list_info ? : "", list_info ? ", " : ""); 63 + __scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len); 64 + seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x%s%s", 65 + buf, cmd->retries, cmd->allowed, cmd->result, 66 + list_info ? ", " : "", list_info ? : ""); 67 + seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", 68 + timeout_ms / 1000, timeout_ms % 1000, 69 + alloc_ms / 1000, alloc_ms % 1000); 70 + } 71 + seq_printf(m, ", .flags="); 65 72 scsi_flags_show(m, cmd->flags, scsi_cmd_flags, 66 73 ARRAY_SIZE(scsi_cmd_flags)); 67 - seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", 68 - timeout_ms / 1000, timeout_ms % 1000, 69 - alloc_ms / 1000, alloc_ms % 1000); 70 74 }