[v3] net/iavf: fix virtual channel return value error

Message ID 20191224041313.85175-1-yahui.cao@intel.com (mailing list archive)
State Accepted, archived
Delegated to: xiaolong ye
Headers
Series [v3] net/iavf: fix virtual channel return value error |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Cao, Yahui Dec. 24, 2019, 4:13 a.m. UTC
  In iavf_handle_virtchnl_msg(), it is not appropriate for _clear_cmd()
to be used as a notification to forground thread. So introduce
_notify_cmd() to fix this error. In addition, since _notify_cmd()
contains rte_wmb(), rte_compiler_barrier() is not necessary.

Sending msg from VF to PF is mainly by calling iavf_execute_vf_cmd(),
the whole virtchnl msg process is like,

iavf_execute_vf_cmd() will call iavf_aq_send_msg_to_pf() to send
msg and then polling the cmd done flag as "if (vf->pend_cmd ==
VIRTCHNL_OP_UNKNOWN)"

When reply msg is returned by pf, iavf_handle_virtchnl_msg() in
isr will read msg return value by "vf->cmd_retval = msg_ret" and
immediately set the cmd done flag by calling _clear_cmd() to
notify the iavf_execute_vf_cmd().

iavf_execute_vf_cmd() find the cmd done flag is set and then
check whether command return value vf->cmd_retval is success or
not.

However _clear_cmd() also resets the vf->cmd_retval to success,
overwriting the actual return value which is used for diagnosis.
So iavf_execute_vf_cmd() will always find vf->cmd_retval is
success and then return success.

Fixes: 22b123a36d07 ("net/avf: initialize PMD")
Cc: stable@dpdk.org

Signed-off-by: Yahui Cao <yahui.cao@intel.com>
---
 drivers/net/iavf/iavf.h       | 11 +++++++++++
 drivers/net/iavf/iavf_vchnl.c |  9 +++------
 2 files changed, 14 insertions(+), 6 deletions(-)
  

Comments

Qi Zhang Dec. 24, 2019, 5:16 a.m. UTC | #1
> -----Original Message-----
> From: Cao, Yahui <yahui.cao@intel.com>
> Sent: Tuesday, December 24, 2019 12:13 PM
> To: Wu, Jingjing <jingjing.wu@intel.com>; Lu, Wenzhuo
> <wenzhuo.lu@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>; Cao,
> Yahui <yahui.cao@intel.com>; Ye, Xiaolong <xiaolong.ye@intel.com>; Su,
> Simei <simei.su@intel.com>
> Subject: [PATCH v3] net/iavf: fix virtual channel return value error
> 
> In iavf_handle_virtchnl_msg(), it is not appropriate for _clear_cmd() to be used
> as a notification to forground thread. So introduce
> _notify_cmd() to fix this error. In addition, since _notify_cmd() contains
> rte_wmb(), rte_compiler_barrier() is not necessary.
> 
> Sending msg from VF to PF is mainly by calling iavf_execute_vf_cmd(), the
> whole virtchnl msg process is like,
> 
> iavf_execute_vf_cmd() will call iavf_aq_send_msg_to_pf() to send msg and
> then polling the cmd done flag as "if (vf->pend_cmd ==
> VIRTCHNL_OP_UNKNOWN)"
> 
> When reply msg is returned by pf, iavf_handle_virtchnl_msg() in isr will read
> msg return value by "vf->cmd_retval = msg_ret" and immediately set the cmd
> done flag by calling _clear_cmd() to notify the iavf_execute_vf_cmd().
> 
> iavf_execute_vf_cmd() find the cmd done flag is set and then check whether
> command return value vf->cmd_retval is success or not.
> 
> However _clear_cmd() also resets the vf->cmd_retval to success, overwriting
> the actual return value which is used for diagnosis.
> So iavf_execute_vf_cmd() will always find vf->cmd_retval is success and then
> return success.
> 
> Fixes: 22b123a36d07 ("net/avf: initialize PMD")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yahui Cao <yahui.cao@intel.com>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>
  
Xiaolong Ye Jan. 4, 2020, 10:20 a.m. UTC | #2
On 12/24, Zhang, Qi Z wrote:
>
>
>> -----Original Message-----
>> From: Cao, Yahui <yahui.cao@intel.com>
>> Sent: Tuesday, December 24, 2019 12:13 PM
>> To: Wu, Jingjing <jingjing.wu@intel.com>; Lu, Wenzhuo
>> <wenzhuo.lu@intel.com>
>> Cc: dev@dpdk.org; stable@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>; Cao,
>> Yahui <yahui.cao@intel.com>; Ye, Xiaolong <xiaolong.ye@intel.com>; Su,
>> Simei <simei.su@intel.com>
>> Subject: [PATCH v3] net/iavf: fix virtual channel return value error
>> 
>> In iavf_handle_virtchnl_msg(), it is not appropriate for _clear_cmd() to be used
>> as a notification to forground thread. So introduce
>> _notify_cmd() to fix this error. In addition, since _notify_cmd() contains
>> rte_wmb(), rte_compiler_barrier() is not necessary.
>> 
>> Sending msg from VF to PF is mainly by calling iavf_execute_vf_cmd(), the
>> whole virtchnl msg process is like,
>> 
>> iavf_execute_vf_cmd() will call iavf_aq_send_msg_to_pf() to send msg and
>> then polling the cmd done flag as "if (vf->pend_cmd ==
>> VIRTCHNL_OP_UNKNOWN)"
>> 
>> When reply msg is returned by pf, iavf_handle_virtchnl_msg() in isr will read
>> msg return value by "vf->cmd_retval = msg_ret" and immediately set the cmd
>> done flag by calling _clear_cmd() to notify the iavf_execute_vf_cmd().
>> 
>> iavf_execute_vf_cmd() find the cmd done flag is set and then check whether
>> command return value vf->cmd_retval is success or not.
>> 
>> However _clear_cmd() also resets the vf->cmd_retval to success, overwriting
>> the actual return value which is used for diagnosis.
>> So iavf_execute_vf_cmd() will always find vf->cmd_retval is success and then
>> return success.
>> 
>> Fixes: 22b123a36d07 ("net/avf: initialize PMD")
>> Cc: stable@dpdk.org
>> 
>> Signed-off-by: Yahui Cao <yahui.cao@intel.com>
>
>Acked-by: Qi Zhang <qi.z.zhang@intel.com>
>

Acked-by: Xiaolong Ye <xiaolong.ye@intel.com>

Applied to dpdk-next-net-intel, Thanks.
  

Patch

diff --git a/drivers/net/iavf/iavf.h b/drivers/net/iavf/iavf.h
index bbd4d75d0..84f821354 100644
--- a/drivers/net/iavf/iavf.h
+++ b/drivers/net/iavf/iavf.h
@@ -173,6 +173,17 @@  struct iavf_cmd_info {
 	uint32_t out_size;      /* buffer size for response */
 };
 
+/* notify current command done. Only call in case execute
+ * _atomic_set_cmd successfully.
+ */
+static inline void
+_notify_cmd(struct iavf_info *vf, uint32_t msg_ret)
+{
+	vf->cmd_retval = msg_ret;
+	rte_wmb();
+	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
+}
+
 /* clear current command. Only call in case execute
  * _atomic_set_cmd successfully.
  */
diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c
index 14395fed3..cf0f6458e 100644
--- a/drivers/net/iavf/iavf_vchnl.c
+++ b/drivers/net/iavf/iavf_vchnl.c
@@ -210,12 +210,9 @@  iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
 							info.msg_len);
 			} else {
 				/* read message and it's expected one */
-				if (msg_opc == vf->pend_cmd) {
-					vf->cmd_retval = msg_ret;
-					/* prevent compiler reordering */
-					rte_compiler_barrier();
-					_clear_cmd(vf);
-				} else
+				if (msg_opc == vf->pend_cmd)
+					_notify_cmd(vf, msg_ret);
+				else
 					PMD_DRV_LOG(ERR, "command mismatch,"
 						    "expect %u, get %u",
 						    vf->pend_cmd, msg_opc);