提交 5259a06e 编写于 作者: N Nicholas Bellinger

target: Fix percpu_ref_put race in transport_lun_remove_cmd

This patch fixes a percpu_ref_put race for se_lun->lun_ref in
transport_lun_remove_cmd() where ->lun_ref could end up being
put more than once per command via different target completion
and fabric release contexts.

It adds a cmpxchg() for se_cmd->lun_ref_active to ensure that
percpu_ref_put() is only ever called once per se_cmd.

This bug was manifesting itself as a LUN shutdown regression
bug in >= v3.13 code, where percpu_ref_kill() would end up
hanging indefinately due to the incorrect percpu_ref count.

(Change se_cmd->lun_ref_active from bool -> int to force at
 least a 4-byte cmpxchg with MIPS ll/sc ins. - Fengguang)
Reported-by: NTommy Apel <tommyapeldk@gmail.com>
Cc: Tommy Apel <tommyapeldk@gmail.com>
Cc: <stable@vger.kernel.org> #3.13+
Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
上级 ee291e63
...@@ -594,9 +594,10 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd) ...@@ -594,9 +594,10 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd)
{ {
struct se_lun *lun = cmd->se_lun; struct se_lun *lun = cmd->se_lun;
if (!lun || !cmd->lun_ref_active) if (!lun)
return; return;
if (cmpxchg(&cmd->lun_ref_active, true, false))
percpu_ref_put(&lun->lun_ref); percpu_ref_put(&lun->lun_ref);
} }
......
...@@ -552,7 +552,7 @@ struct se_cmd { ...@@ -552,7 +552,7 @@ struct se_cmd {
void *priv; void *priv;
/* Used for lun->lun_ref counting */ /* Used for lun->lun_ref counting */
bool lun_ref_active; int lun_ref_active;
/* DIF related members */ /* DIF related members */
enum target_prot_op prot_op; enum target_prot_op prot_op;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册