]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
qed: Fix possible race when reading firmware return code.
authorManish Chopra <manish.chopra@caviumnetworks.com>
Fri, 14 Oct 2016 09:19:23 +0000 (05:19 -0400)
committerChuck Anderson <chuck.anderson@oracle.com>
Mon, 6 Mar 2017 04:59:59 +0000 (20:59 -0800)
Orabug: 25477939

While handling SPQ ramrod completion, there is a possible race
where driver might not read updated fw return code based on
ramrod completion done. This patch ensures that fw return code
is written first and then completion done flag is updated
using appropriate memory barriers.

Signed-off-by: Manish Chopra <manish.chopra@caviumnetworks.com>
Signed-off-by: Yuval Mintz <Yuval.Mintz@caviumnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit d5df7688b6a36dbb5611a58229a5e294cd978999)
Signed-off-by: Brian Maly <brian.maly@oracle.com>
drivers/net/ethernet/qlogic/qed/qed_sp.h
drivers/net/ethernet/qlogic/qed/qed_spq.c

index b2c08e4d2a9b9de9c2042bc2afa22c6bd51c3618..9c897bc68d05545a88cfddf582ef19616042ce89 100644 (file)
@@ -110,8 +110,8 @@ union qed_spq_req_comp {
 };
 
 struct qed_spq_comp_done {
-       u64     done;
-       u8      fw_return_code;
+       unsigned int    done;
+       u8              fw_return_code;
 };
 
 struct qed_spq_entry {
index d5b611f8858609c4b5d3fad9c43902b3dbd8e6c0..019960b7855a9162a6c2fe75262bcc63551cac74 100644 (file)
@@ -52,11 +52,10 @@ static void qed_spq_blocking_cb(struct qed_hwfn *p_hwfn,
 
        comp_done = (struct qed_spq_comp_done *)cookie;
 
-       comp_done->done                 = 0x1;
-       comp_done->fw_return_code       = fw_return_code;
+       comp_done->fw_return_code = fw_return_code;
 
-       /* make update visible to waiting thread */
-       smp_wmb();
+       /* Make sure completion done is visible on waiting thread */
+       smp_store_release(&comp_done->done, 0x1);
 }
 
 static int __qed_spq_block(struct qed_hwfn *p_hwfn,
@@ -72,8 +71,9 @@ static int __qed_spq_block(struct qed_hwfn *p_hwfn,
 
        while (iter_cnt--) {
                /* Validate we receive completion update */
-               smp_rmb();
-               if (comp_done->done == 1) {
+               if (READ_ONCE(comp_done->done) == 1) {
+                       /* Read updated FW return value */
+                       smp_read_barrier_depends();
                        if (p_fw_ret)
                                *p_fw_ret = comp_done->fw_return_code;
                        return 0;