Skip to contentSkip to conversation

net/iavf: fix virtual channel return value error

PATCH Superseded Yahui Cao 3 participants 5 messages Dec 19, 2019 – Jan 4, 2020 Network drivers

lore
Share & tools
lore

Yahui Cao

author
#0 lore raw

PATCH 1/1 net/iavf: fix virtual channel return value error

Original virtual channel return value is overwritten by _clear_cmd().

Fixes 22b123a36d07 ("net/avf: initialize PMD")
---
 drivers/net/iavf/iavf.h | 1 -
 1 file changed, 1 deletion(-)
drivers/net/iavf/iavf.h +0 -1
index bbd4d75d0..b12ad4119 100644
@@ -181,7 +181,6 @@ _clear_cmd(struct iavf_info *vf)
 {
 	rte_wmb();
 	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
-	vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
 }
 
 /* Check there is pending cmd in execution. If none, set new command. */
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/1 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.

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")
---
 drivers/net/iavf/iavf.h       | 10 ++++++++++
 drivers/net/iavf/iavf_vchnl.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/net/iavf/iavf.h +10 -0
index bbd4d75d0..215a1f28f 100644
@@ -173,6 +173,16 @@ 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)
+{
+	rte_wmb();
+	vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
+}
+
 /* clear current command. Only call in case execute
  * _atomic_set_cmd successfully.
  */
drivers/net/iavf/iavf_vchnl.c +1 -1
index 14395fed3..285b1fc97 100644
@@ -214,7 +214,7 @@ iavf_handle_virtchnl_msg(struct rte_eth_dev *dev)
 					vf->cmd_retval = msg_ret;
 					/* prevent compiler reordering */
 					rte_compiler_barrier();
-					_clear_cmd(vf);
+					_notify_cmd(vf);
 				} else
 					PMD_DRV_LOG(ERR, "command mismatch,"
 						    "expect %u, get %u",
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v3 1/1 net/iavf: fix virtual channel return value error

In reply to Yahui Cao

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")
---
 drivers/net/iavf/iavf.h       | 11 +++++++++++
 drivers/net/iavf/iavf_vchnl.c |  9 +++------
 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/net/iavf/iavf.h +11 -0
index bbd4d75d0..84f821354 100644
@@ -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.
  */
drivers/net/iavf/iavf_vchnl.c +3 -6
index 14395fed3..cf0f6458e 100644
@@ -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);
Signature · 1 line
2.17.1
Acked-by on v3 1/1
#3 lore raw
Quoted 36 lines

-----Original Message-----
From: Cao, Yahui <[email protected]>
Sent: Tuesday, December 24, 2019 12:13 PM
To: Wu, Jingjing <[email protected]>; Lu, Wenzhuo <[email protected]>
Cc: [email protected]; [email protected]; Zhang, Qi Z <[email protected]>; Cao, Yahui <[email protected]>; Ye, Xiaolong <[email protected]>; Su, Simei <[email protected]>
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.

Quoted 4 lines
Fixes 22b123a36d07 ("net/avf: initialize PMD")
Acked-by Applied
#4 lore raw
Quoted 36 lines · Qi Z
Quoted 36 lines

-----Original Message-----
From: Cao, Yahui <[email protected]>
Sent: Tuesday, December 24, 2019 12:13 PM
To: Wu, Jingjing <[email protected]>; Lu, Wenzhuo <[email protected]>
Cc: [email protected]; [email protected]; Zhang, Qi Z <[email protected]>; Cao, Yahui <[email protected]>; Ye, Xiaolong <[email protected]>; Su, Simei <[email protected]>
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.

Quoted 7 lines
Quoted 4 lines
Fixes 22b123a36d07 ("net/avf: initialize PMD")

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