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

scsi: target: core: Remove in_interrupt() check in transport_handle_cdb_direct()

transport_handle_cdb_direct() uses in_interrupt() to detect if it is safe
to sleep. It produces a stack trace and returns with an error which is
clearly for debugging.

The usage of in_interrupt() in drivers is phased out and Linus clearly
requested that code which changes behaviour depending on context should
either be separated or the context be conveyed in an argument passed by the
caller, which usually knows the context.

transport_handle_cdb_direct() has a comment saying that it may only be
invoked from process context. It invokes transport_generic_new_cmd() which
performs GFP_KERNEL memory allocations. in_interrupt() does not detect all
the contexts where it is invalid to sleep (for the blocking GFP_KERNEL
allocation) as it fails to detect sections with disabled preemption.

Replace the in_interrupt() based check with a might_sleep() annotation.

Link: https://lore.kernel.org/r/20201220203638.43615-7-bigeasy@linutronix.de
Signed-off-by: Ahmed S. Darwish <a.darwish@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Ahmed S. Darwish and committed by
Martin K. Petersen
bbb08767 513e2994

+3 -6
+3 -6
drivers/target/target_core_transport.c
··· 1512 1512 { 1513 1513 sense_reason_t ret; 1514 1514 1515 + might_sleep(); 1516 + 1515 1517 if (!cmd->se_lun) { 1516 1518 dump_stack(); 1517 1519 pr_err("cmd->se_lun is NULL\n"); 1518 1520 return -EINVAL; 1519 1521 } 1520 - if (in_interrupt()) { 1521 - dump_stack(); 1522 - pr_err("transport_generic_handle_cdb cannot be called" 1523 - " from interrupt context\n"); 1524 - return -EINVAL; 1525 - } 1522 + 1526 1523 /* 1527 1524 * Set TRANSPORT_NEW_CMD state and CMD_T_ACTIVE to ensure that 1528 1525 * outstanding descriptors are handled correctly during shutdown via