Commit d5df7688 authored by Manish Chopra's avatar Manish Chopra Committed by David S. Miller

qed: Fix possible race when reading firmware return code.

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: default avatarManish Chopra <manish.chopra@caviumnetworks.com>
Signed-off-by: default avatarYuval Mintz <Yuval.Mintz@caviumnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7eff82b0
...@@ -111,7 +111,7 @@ union qed_spq_req_comp { ...@@ -111,7 +111,7 @@ union qed_spq_req_comp {
}; };
struct qed_spq_comp_done { struct qed_spq_comp_done {
u64 done; unsigned int done;
u8 fw_return_code; u8 fw_return_code;
}; };
......
...@@ -54,11 +54,10 @@ static void qed_spq_blocking_cb(struct qed_hwfn *p_hwfn, ...@@ -54,11 +54,10 @@ static void qed_spq_blocking_cb(struct qed_hwfn *p_hwfn,
comp_done = (struct qed_spq_comp_done *)cookie; 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 */ /* Make sure completion done is visible on waiting thread */
smp_wmb(); smp_store_release(&comp_done->done, 0x1);
} }
static int __qed_spq_block(struct qed_hwfn *p_hwfn, static int __qed_spq_block(struct qed_hwfn *p_hwfn,
...@@ -74,8 +73,9 @@ static int __qed_spq_block(struct qed_hwfn *p_hwfn, ...@@ -74,8 +73,9 @@ static int __qed_spq_block(struct qed_hwfn *p_hwfn,
while (iter_cnt--) { while (iter_cnt--) {
/* Validate we receive completion update */ /* Validate we receive completion update */
smp_rmb(); if (READ_ONCE(comp_done->done) == 1) {
if (comp_done->done == 1) { /* Read updated FW return value */
smp_read_barrier_depends();
if (p_fw_ret) if (p_fw_ret)
*p_fw_ret = comp_done->fw_return_code; *p_fw_ret = comp_done->fw_return_code;
return 0; return 0;
......
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