target: Make transport_lookup_cmd_lun() locking IRQ-safe
Subsystems (2)
PATCH 1/1 target: Make transport_lookup_cmd_lun() locking IRQ-safe
From: Roland Dreier <[email protected]>
transport_lookup_cmd_lun() may be called from interrupt context (eg tcm_loop_allocate_core_cmd() calls it, and it has a comment that says, "Can be called from interrupt context"), so it needs to use spin_lock_irqsave() instead of spin_lock_irq() to avoid enabling interrupts at the wrong time.
(And indeed the last set of lock operations, on lun_cmd_lock, were already using spin_lock_irqsave(), so we just need to fix the other two locks we take)
---
Not sure if this is causing anything other than lockdep reports at the moment, so I don't think it's worth trying to get into 3.0.0-rc...
drivers/target/target_core_device.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/target/target_core_device.c +5 -5
@@ -72,7 +72,7 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)return -ENODEV ; } -spin_lock_irq (&se_sess->se_node_acl->device_list_lock); +spin_lock_irqsave (&se_sess->se_node_acl->device_list_lock, flags); se_cmd->se_deve = &se_sess->se_node_acl->device_list[unpacked_lun];if (se_cmd->se_deve->lun_flags &TRANSPORT_LUNFLAGS_INITIATOR_ACCESS ) {
@@ -89,7 +89,7 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)" Access for 0x%08x\n" , se_cmd->se_tfo->get_fabric_name (), unpacked_lun); -spin_unlock_irq (&se_sess->se_node_acl->device_list_lock); +spin_unlock_irqrestore (&se_sess->se_node_acl->device_list_lock, flags);return -EACCES ; }
@@ -107,7 +107,7 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun) se_cmd->se_orig_obj_ptr = se_cmd->se_lun->lun_se_dev; se_cmd->se_cmd_flags |=SCF_SE_LUN_CMD ; } -spin_unlock_irq (&se_sess->se_node_acl->device_list_lock); +spin_unlock_irqrestore (&se_sess->se_node_acl->device_list_lock, flags);if (!se_lun) {/*
@@ -156,13 +156,13 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)/* TODO: get rid of this and use atomics for stats */ dev = se_lun->lun_se_dev; -spin_lock_irq (&dev->stats_lock); +spin_lock_irqsave (&dev->stats_lock, flags); dev->num_cmds++;if (se_cmd->data_direction ==DMA_TO_DEVICE ) dev->write_bytes += se_cmd->data_length;else if (se_cmd->data_direction ==DMA_FROM_DEVICE ) dev->read_bytes += se_cmd->data_length; -spin_unlock_irq (&dev->stats_lock); +spin_unlock_irqrestore (&dev->stats_lock, flags);/* * Add the iscsi_cmd_t to the struct se_lun's cmd list. This list is used
Quoted 11 lines · Roland Dreier
From: Roland Dreier <[email protected]>
transport_lookup_cmd_lun()may be called from interrupt context (egtcm_loop_allocate_core_cmd()calls it, and it has a comment that says, "Can be called from interrupt context"), so it needs to usespin_lock_irqsave()instead ofspin_lock_irq()to avoid enabling interrupts at the wrong time.(And indeed the last set of lock operations, on
lun_cmd_lock, were already usingspin_lock_irqsave(), so we just need to fix the other two locks we take)
It currently is, but I think we'd better be off stopping to call it from IRQ context. Soon after we offload the work to thread context anyway. By moving the point of offloading a little earlier we can simply the calling conventions a lot, and keep the amount of code that needs IRQ-safe locking minimal.
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines
transport_lookup_cmd_lun()may be called from interrupt context (egtcm_loop_allocate_core_cmd()calls it, and it has a comment that says, "Can be called from interrupt context"), so it needs to usespin_lock_irqsave()instead ofspin_lock_irq()to avoid enabling interrupts at the wrong time.It currently is, but I think we'd better be off stopping to call it from IRQ context. Soon after we offload the work to thread context anyway. By moving the point of offloading a little earlier we can simply the calling conventions a lot, and keep the amount of code that needs IRQ-safe locking minimal.
Fair enough... however that seems like a much more major project, as eg the qla2xxx code does a fair bit from interrupt context.
Also it seems even if we are running from thread context it would be legitimate for a target driver to do
spin_lock_irq(&internal_target_lock);
...
transport_lookup_cmd_lun();
...
spin_unlock_irqand so transport_lookup_cmd_lun() shouldn't be reenabling IRQs unconditionally.
Thanks,
Roland
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Roland Dreier
Fair enough... however that seems like a much more major project, as eg the qla2xxx code does a fair bit from interrupt context.
Yes, just pointing out in which direction it should go eventually.
Quoted 4 lines
Also it seems even if we are running from thread context it would be legitimate for a target driver to do
Quoted 8 lines
spin_lock_irq(&internal_target_lock); ... transport_lookup_cmd_lun(); ... spin_unlock_irqand so
transport_lookup_cmd_lun()shouldn't be reenabling IRQs unconditionally.
Yes. At that point we shouldn't require any irq locking, making life even easier.
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Roland Dreier
From: Roland Dreier <[email protected]>
transport_lookup_cmd_lun()may be called from interrupt context (egtcm_loop_allocate_core_cmd()calls it, and it has a comment that says, "Can be called from interrupt context"), so it needs to usespin_lock_irqsave()instead ofspin_lock_irq()to avoid enabling interrupts at the wrong time.(And indeed the last set of lock operations, on
lun_cmd_lock, were already usingspin_lock_irqsave(), so we just need to fix the other two locks we take)
Quoted 6 lines
It currently is, but I think we'd better be off stopping to call it from IRQ context. Soon after we offload the work to thread context anyway. By moving the point of offloading a little earlier we can simply the calling conventions a lot, and keep the amount of code that needs IRQ-safe locking minimal.
The thing here is that the new descriptor can't be offloaded into thread context for TFO->new_cmd_map() processing until the se_cmd->se_dev assignment has occured, because we don't know which backend it's destined for.
So, I think we at least need this patch..
--nab
Quoted 11 lines · Nicholas A. Bellinger
Quoted 6 lines
It currently is, but I think we'd better be off stopping to call it from IRQ context. Soon after we offload the work to thread context anyway. By moving the point of offloading a little earlier we can simply the calling conventions a lot, and keep the amount of code that needs IRQ-safe locking minimal.
The thing here is that the new descriptor can't be offloaded into thread context for
TFO->new_cmd_map()processing until these_cmd->se_devassignment has occured, because we don't know which backend it's destined for.
The actual backend is pretty irrelevant. What matters with the current code is which se_dev it is for, but once switched to the concurrency managed workqueues that becomes irrelevant, too.
Quoted 8 lines · Roland Dreier
From: Roland Dreier <[email protected]>
transport_lookup_cmd_lun()may be called from interrupt context (egtcm_loop_allocate_core_cmd()calls it, and it has a comment that says, "Can be called from interrupt context"), so it needs to usespin_lock_irqsave()instead ofspin_lock_irq()to avoid enabling interrupts at the wrong time.
Quoted 9 lines
(And indeed the last set of lock operations, on
lun_cmd_lock, were already usingspin_lock_irqsave(), so we just need to fix the other two locks we take)Signed-off-by Roland Dreier <[email protected]>---
Not sure if this is causing anything other than lockdep reports at the moment, so I don't think it's worth trying to get into 3.0.0-rc...
<nod> Committed as f39cc7c3da62.
Btw, I think the same type of conversion may need to happen for transport_lookup_tmr_lun() as well, as I believe qla_target.c can call this directly from interrupt context in certain situations.
--nab
Quoted 54 lines
drivers/target/target_core_device.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)drivers/target/target_core_device.c +5
-6@@ -72,7 +72,7 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)return -ENODEV ; } -spin_lock_irq (&se_sess->se_node_acl->device_list_lock); +spin_lock_irqsave (&se_sess->se_node_acl->device_list_lock, flags); se_cmd->se_deve = &se_sess->se_node_acl->device_list[unpacked_lun];if (se_cmd->se_deve->lun_flags &TRANSPORT_LUNFLAGS_INITIATOR_ACCESS ) {@@ -89,7 +89,7 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)" Access for 0x%08x\n" , se_cmd->se_tfo->get_fabric_name (), unpacked_lun); -spin_unlock_irq (&se_sess->se_node_acl->device_list_lock); +spin_unlock_irqrestore (&se_sess->se_node_acl->device_list_lock, flags);return -EACCES ; }@@ -107,7 +107,7 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun) se_cmd->se_orig_obj_ptr = se_cmd->se_lun->lun_se_dev; se_cmd->se_cmd_flags |=SCF_SE_LUN_CMD ; } -spin_unlock_irq (&se_sess->se_node_acl->device_list_lock); +spin_unlock_irqrestore (&se_sess->se_node_acl->device_list_lock, flags);if (!se_lun) {/* @@ -156,13 +156,13 @@ int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun)/* TODO: get rid of this and use atomics for stats */ dev = se_lun->lun_se_dev; -spin_lock_irq (&dev->stats_lock); +spin_lock_irqsave (&dev->stats_lock, flags); dev->num_cmds++;if (se_cmd->data_direction ==DMA_TO_DEVICE ) dev->write_bytes += se_cmd->data_length;else if (se_cmd->data_direction ==DMA_FROM_DEVICE ) dev->read_bytes += se_cmd->data_length; -spin_unlock_irq (&dev->stats_lock); +spin_unlock_irqrestore (&dev->stats_lock, flags);/* * Add the iscsi_cmd_t to the struct se_lun's cmd list. This list is used -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Nicholas A. Bellinger
Btw, I think the same type of conversion may need to happen for
transport_lookup_tmr_lun()as well, as I believeqla_target.ccan call this directly from interrupt context in certain situations.
Yes, I think I sent another mail about this... the reason I didn't just send a patch is that transport_lookup_tmr_lun() ends with:
spin_lock(&se_tmr->tmr_dev->se_tmr_lock);
list_add_tail(&se_tmr->tmr_list, &se_tmr->tmr_dev->dev_tmr_list);
spin_unlock(&se_tmr->tmr_dev->se_tmr_lock);and indeed se_tmr_lock looks like it is taken with bare spin_lock() in lots of places.
Presumably se_tmr_lock is taken from process context sometimes? So we would need to convert all those spin_lock()s to spin_lock_irq() (or irqsave I guess).
- R.
Quoted 9 lines · Roland Dreier
Quoted 3 lines · Nicholas A. Bellinger
Btw, I think the same type of conversion may need to happen for
transport_lookup_tmr_lun()as well, as I believeqla_target.ccan call this directly from interrupt context in certain situations.Yes, I think I sent another mail about this... the reason I didn't just send a patch is that
transport_lookup_tmr_lun()ends with:
Quoted 7 lines
spin_lock(&se_tmr->tmr_dev->se_tmr_lock); list_add_tail(&se_tmr->tmr_list, &se_tmr->tmr_dev->dev_tmr_list); spin_unlock(&se_tmr->tmr_dev->se_tmr_lock);and indeed
se_tmr_locklooks like it is taken with barespin_lock()in lots of places.
Actually, it's only two places: core_tmr_release_req() and core_tmr_lun_reset()
Quoted 4 lines
Presumably
se_tmr_lockis taken from process context sometimes? So we would need to convert all those spin_lock()s tospin_lock_irq()(or irqsave I guess).
Correct, both of the above are only every called from process context, so a simple conversion to spin_lock_irq() for these two, and spin_lock_irqsave() in transport_lookup_tmr_lun() should by sufficent..
--nab
Quoted 19 lines · Nicholas A. Bellinger
Quoted 8 lines · Roland Dreier
Quoted 3 lines · Nicholas A. Bellinger
Btw, I think the same type of conversion may need to happen for
transport_lookup_tmr_lun()as well, as I believeqla_target.ccan call this directly from interrupt context in certain situations.Yes, I think I sent another mail about this... the reason I didn't just send a patch is that
transport_lookup_tmr_lun()ends with:Quoted 7 lines
spin_lock(&se_tmr->tmr_dev->se_tmr_lock); list_add_tail(&se_tmr->tmr_list,&se_tmr->tmr_dev->dev_tmr_list); spin_unlock(&se_tmr->tmr_dev->se_tmr_lock);and indeed
se_tmr_locklooks like it is taken with barespin_lock()in lots of places.Actually, it's only two places:
core_tmr_release_req()andcore_tmr_lun_reset()
Quoted 7 lines
Quoted 4 lines
Presumably
se_tmr_lockis taken from process context sometimes? So we would need to convert all those spin_lock()s tospin_lock_irq()(or irqsave I guess).Correct, both of the above are only every called from process context, so a simple conversion to
spin_lock_irq()for these two, andspin_lock_irqsave()intransport_lookup_tmr_lun()should by sufficent..
Likewise, we need to do same change in function "transport_get_lun_for_tmr", specifically for tmr_lock. Please correct me if I am missing anything.
Quoted 6 lines
--nab
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Thanks,
-- Kiran P.
Quoted 2 lines · Kiran Patil
Likewise, we need to do same change in function "
transport_get_lun_for_tmr", specifically fortmr_lock. Please correct me if I am missing anything.
Yes, that's right... in fact that is what we were discussing now, isn't it? Or is there something different I'm missing?
(BTW transport_get_lun_for_tmr is renamed to transport_lookup_tmr_lun in the latest tree)
- R.
Quoted 10 lines · Roland Dreier
Quoted 2 lines · Kiran Patil
Likewise, we need to do same change in function "
transport_get_lun_for_tmr", specifically fortmr_lock. Please correct me if I am missing anything.Yes, that's right... in fact that is what we were discussing now, isn't it? Or is there something different I'm missing?
(BTW
transport_get_lun_for_tmris renamed totransport_lookup_tmr_lunin the latest tree)- R.
Cool. Then we are referring to same function. Looks like I am using old tree which has function name "transport_get_lun_for_tmr"
Thanks,
-- Kiran P,
Quoted 10 lines · Nicholas A. Bellinger
Actually, it's only two places: core_tmr_release_req() and
core_tmr_lun_reset()Quoted 3 lines
Presumably
se_tmr_lockis taken from process context sometimes? So we would need to convert all those spin_lock()s tospin_lock_irq()(or irqsave I guess).Correct, both of the above are only every called from process context, so a simple conversion to
spin_lock_irq()for these two, andspin_lock_irqsave()intransport_lookup_tmr_lun()should by sufficent..
Looking at this...
core_tmr_lun_reset() uses _irqsave locking for cmd->t_state_lock... is that not needed, or can it actually be called from a context where we can't just use spin_lock_irq? (eg because some caller might have already disabled interrupts)
- R.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html