]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
target: Fix percpu_ref_put race in transport_lun_remove_cmd
authorNicholas Bellinger <nab@linux-iscsi.org>
Wed, 29 Jan 2014 01:56:30 +0000 (17:56 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Feb 2014 21:55:41 +0000 (13:55 -0800)
commit 5259a06ef97068b710f45d092a587e8d740f750f upstream.

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: Tommy Apel <tommyapeldk@gmail.com>
Cc: Tommy Apel <tommyapeldk@gmail.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/target/target_core_transport.c
include/target/target_core_base.h

index 91953da0f62329af488a91eaa1d83be6fda68f08..dee2be1f9171b87f8d90d2b4586016bbdf212a03 100644 (file)
@@ -568,10 +568,11 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd)
 {
        struct se_lun *lun = cmd->se_lun;
 
-       if (!lun || !cmd->lun_ref_active)
+       if (!lun)
                return;
 
-       percpu_ref_put(&lun->lun_ref);
+       if (cmpxchg(&cmd->lun_ref_active, true, false))
+               percpu_ref_put(&lun->lun_ref);
 }
 
 void transport_cmd_finish_abort(struct se_cmd *cmd, int remove)
index 321301c0a643bfb32303b3f48cecae720f3fad87..e3569f829f7eeb9e2c59bd4eb52e2ecd25566984 100644 (file)
@@ -497,7 +497,7 @@ struct se_cmd {
        void                    *priv;
 
        /* Used for lun->lun_ref counting */
-       bool                    lun_ref_active;
+       int                     lun_ref_active;
 };
 
 struct se_ua {