Commit 1e7de68c authored by Nicholas Bellinger's avatar Nicholas Bellinger

[SCSI] target: Fix interrupt context bug with stats_lock and core_tmr_alloc_req

This patch fixes two bugs wrt to the interrupt context usage of target
core with HW target mode drivers.  It first converts the usage of struct
se_device->stats_lock in transport_get_lun_for_cmd() and core_tmr_lun_reset()
to properly use spin_lock_irq() to address an BUG with CONFIG_LOCKDEP_SUPPORT=y
enabled.

This patch also adds a 'in_interrupt()' check to allow GFP_ATOMIC usage from
core_tmr_alloc_req() to fix a 'sleeping in interrupt context' BUG with HW
target fabrics that require this logic to function.
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
Cc: stable@kernel.org
Signed-off-by: default avatarJames Bottomley <jbottomley@parallels.com>
parent 4a8fcc2c
...@@ -150,13 +150,13 @@ int transport_get_lun_for_cmd( ...@@ -150,13 +150,13 @@ int transport_get_lun_for_cmd(
{ {
struct se_device *dev = se_lun->lun_se_dev; struct se_device *dev = se_lun->lun_se_dev;
spin_lock(&dev->stats_lock); spin_lock_irq(&dev->stats_lock);
dev->num_cmds++; dev->num_cmds++;
if (se_cmd->data_direction == DMA_TO_DEVICE) if (se_cmd->data_direction == DMA_TO_DEVICE)
dev->write_bytes += se_cmd->data_length; dev->write_bytes += se_cmd->data_length;
else if (se_cmd->data_direction == DMA_FROM_DEVICE) else if (se_cmd->data_direction == DMA_FROM_DEVICE)
dev->read_bytes += se_cmd->data_length; dev->read_bytes += se_cmd->data_length;
spin_unlock(&dev->stats_lock); spin_unlock_irq(&dev->stats_lock);
} }
/* /*
......
...@@ -55,7 +55,8 @@ struct se_tmr_req *core_tmr_alloc_req( ...@@ -55,7 +55,8 @@ struct se_tmr_req *core_tmr_alloc_req(
{ {
struct se_tmr_req *tmr; struct se_tmr_req *tmr;
tmr = kmem_cache_zalloc(se_tmr_req_cache, GFP_KERNEL); tmr = kmem_cache_zalloc(se_tmr_req_cache, (in_interrupt()) ?
GFP_ATOMIC : GFP_KERNEL);
if (!(tmr)) { if (!(tmr)) {
printk(KERN_ERR "Unable to allocate struct se_tmr_req\n"); printk(KERN_ERR "Unable to allocate struct se_tmr_req\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -398,9 +399,9 @@ int core_tmr_lun_reset( ...@@ -398,9 +399,9 @@ int core_tmr_lun_reset(
printk(KERN_INFO "LUN_RESET: SCSI-2 Released reservation\n"); printk(KERN_INFO "LUN_RESET: SCSI-2 Released reservation\n");
} }
spin_lock(&dev->stats_lock); spin_lock_irq(&dev->stats_lock);
dev->num_resets++; dev->num_resets++;
spin_unlock(&dev->stats_lock); spin_unlock_irq(&dev->stats_lock);
DEBUG_LR("LUN_RESET: %s for [%s] Complete\n", DEBUG_LR("LUN_RESET: %s for [%s] Complete\n",
(preempt_and_abort_list) ? "Preempt" : "TMR", (preempt_and_abort_list) ? "Preempt" : "TMR",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment