net/i40e: fix return value of close operation
PATCH 1/2 net/i40e: fix return value of close operation
rte_intr_callback_unregister() returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value of i40e_dev_close(), so applications checking rte_eth_dev_close() != 0 treat a successful close as a failure.
--- drivers/net/intel/i40e/i40e_ethdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/intel/i40e/i40e_ethdev.c +1 -0
@@ -2764,6 +2764,7 @@ i40e_dev_close(struct rte_eth_dev *dev) ret =rte_intr_callback_unregister (intr_handle, i40e_dev_interrupt_handler, dev);if (ret >=0 || ret == -ENOENT ) { + ret =0 ;break ; }else if (ret != -EAGAIN ) { PMD_INIT_LOG(ERR,
Signature · 1 line
2.34.1
PATCH 2/2 net/ixgbe: fix return value of close operation
rte_intr_callback_unregister() returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value of ixgbe_dev_close(), so applications checking rte_eth_dev_close() != 0 treat a successful close as a failure.
--- drivers/net/intel/ixgbe/ixgbe_ethdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/intel/ixgbe/ixgbe_ethdev.c +1 -0
@@ -3121,6 +3121,7 @@ ixgbe_dev_close(struct rte_eth_dev *dev) ret =rte_intr_callback_unregister (intr_handle, ixgbe_dev_interrupt_handler, dev);if (ret >=0 || ret == -ENOENT ) { + ret =0 ;break ; }else if (ret != -EAGAIN ) { PMD_INIT_LOG(ERR,
Signature · 1 line
2.34.1
Re: [PATCH 2/2] net/ixgbe: fix return value of close operation
Quoted 18 lines · SidAli CHERRATI
rte_intr_callback_unregister()returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value ofixgbe_dev_close(), so applications checkingrte_eth_dev_close()!= 0 treat a successful close as a failure.Fixes 62024eb82756 ("ethdev: change stop operation callback to return int")Signed-off-by SidAli CHERRATI <[email protected]>--- drivers/net/intel/ixgbe/ixgbe_ethdev.c | 1 + 1 file changed, 1 insertion(+)drivers/net/intel/ixgbe/ixgbe_ethdev.c +0
-0
drivers/net/intel/ixgbe/ixgbe_ethdev.c ixgbe_dev_close(struct rte_eth_dev *dev) · line 3125
Quoted 5 lines
drivers/net/intel/ixgbe/ixgbe_ethdev.c +1
-0@@ -3121,6 +3121,7 @@ ixgbe_dev_close(struct rte_eth_dev *dev) ret =rte_intr_callback_unregister (intr_handle, ixgbe_dev_interrupt_handler, dev);if (ret >=0 || ret == -ENOENT ) { + ret =0 ;break ;
This fixes the issue of returning an invalid value from the interrupt unregister, but it also means losing the previous value of ret from the stop call above. I'm therefore wondering if a better fix is to use a new temporary variable inside the do{ }while loop, and assign that to ret in the case of an actual error, otherwise leaving ret unmodified. In that case, we probably want to stop retries on an error too, right?
do {
int cb_ret = rte_intr_callback_unregister(intr_handle,
ixgbe_dev_interrupt_handler, dev);
if (cb_ret >= 0 || cb_ret == -ENOENT) {
break;
} else if (cb_ret != -EAGAIN) {
PMD_INIT_LOG(ERR,
"intr callback unregister failed: %d",
cb_ret);
ret = cb_ret;
break; /* on error, don't retry */
}
rte_delay_ms(100);
} while (retries++ < (10 + IXGBE_LINK_UP_TIME));IF we do need to retry on error, then this approach won't work. Maybe a modified version of your suggestion might do instead - rather than assigning 0 to ret on success, we assign a saved off version of it from before the loop?
What do you think?
/Bruce
PATCH v2 1/2 net/i40e: fix return value of close operation
In reply to SidAli CHERRATIrte_intr_callback_unregister() returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value of i40e_dev_close(), so applications checking rte_eth_dev_close() != 0 treat a successful close as a failure.
Use a separate cb_ret variable for the unregister return value so a successful unregister never clobbers an earlier error stored in ret, and stop retrying once unregister fails with anything other than -EAGAIN, since those errors are not transient.
---
v2: use a temporary cb_ret variable instead of unconditionally zeroing
ret, and stop retrying on a non-transient unregister error, so an earlier error is not lost or masked by a successful/failed unregister
drivers/net/intel/i40e/i40e_ethdev.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/intel/i40e/i40e_ethdev.c +8 -4
@@ -2693,6 +2693,7 @@ i40e_dev_close(struct rte_eth_dev *dev)uint32_t reg;int i;int ret; +int cb_ret;uint8_t aq_fail =0 ;int retries =0 ;
@@ -2761,14 +2762,17 @@ i40e_dev_close(struct rte_eth_dev *dev)i40e_pf_host_uninit (dev);do { - ret =rte_intr_callback_unregister (intr_handle, + cb_ret =rte_intr_callback_unregister (intr_handle, i40e_dev_interrupt_handler, dev); -if (ret >=0 || ret == -ENOENT ) { +if (cb_ret >=0 || cb_ret == -ENOENT ) {break ; - }else if (ret != -EAGAIN ) { + }else if (cb_ret != -EAGAIN ) {PMD_INIT_LOG (ERR ,"intr callback unregister failed: %d" , - ret); + cb_ret); +if (ret ==0 ) + ret = cb_ret; +break ; }i40e_msec_delay (500 ); }while (retries++ <5 );
Signature · 1 line
2.34.1
PATCH v2 2/2 net/ixgbe: fix return value of close operation
rte_intr_callback_unregister() returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value of ixgbe_dev_close(), so applications checking rte_eth_dev_close() != 0 treat a successful close as a failure.
Use a separate cb_ret variable for the unregister return value so a successful unregister never clobbers the dev_stop() error already stored in ret, and stop retrying once unregister fails with anything other than -EAGAIN, since those errors are not transient.
---
v2: use a temporary cb_ret variable instead of unconditionally zeroing
ret, and stop retrying on a non-transient unregister error, so an earlier error is not lost or masked by a successful/failed unregister
drivers/net/intel/ixgbe/ixgbe_ethdev.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/intel/ixgbe/ixgbe_ethdev.c +8 -4
@@ -3095,6 +3095,7 @@ ixgbe_dev_close(struct rte_eth_dev *dev)struct rte_intr_handle *intr_handle = pci_dev->intr_handle;int retries =0 ;int ret; +int cb_ret;PMD_INIT_FUNC_TRACE ();if (rte_eal_process_type () !=RTE_PROC_PRIMARY )
@@ -3118,14 +3119,17 @@ ixgbe_dev_close(struct rte_eth_dev *dev)rte_intr_disable (intr_handle);do { - ret =rte_intr_callback_unregister (intr_handle, + cb_ret =rte_intr_callback_unregister (intr_handle, ixgbe_dev_interrupt_handler, dev); -if (ret >=0 || ret == -ENOENT ) { +if (cb_ret >=0 || cb_ret == -ENOENT ) {break ; - }else if (ret != -EAGAIN ) { + }else if (cb_ret != -EAGAIN ) {PMD_INIT_LOG (ERR ,"intr callback unregister failed: %d" , - ret); + cb_ret); +if (ret ==0 ) + ret = cb_ret; +break ; }rte_delay_ms (100 ); }while (retries++ < (10 +IXGBE_LINK_UP_TIME ));
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] net/ixgbe: fix return value of close operation
Quoted 15 lines · Sid Ali Cherrati
rte_intr_callback_unregister()returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value ofixgbe_dev_close(), so applications checkingrte_eth_dev_close()!= 0 treat a successful close as a failure.Use a separate
cb_retvariable for the unregister return value so a successful unregister never clobbers thedev_stop()error already stored in ret, and stop retrying once unregister fails with anything other than-EAGAIN, since those errors are not transient.Fixes 62024eb82756 ("ethdev: change stop operation callback to return int")Signed-off-by Sid Ali Cherrati <[email protected]>
Quoted 9 lines
---
v2: use a temporarycb_retvariable instead of unconditionally zeroing
ret, and stop retrying on a non-transient unregister error, so an earlier error is not lost or masked by a successful/failed unregisterdrivers/net/intel/ixgbe/ixgbe_ethdev.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
Quoted 11 lines · Sid Ali Cherrati
rte_intr_callback_unregister()returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value ofi40e_dev_close(), so applications checkingrte_eth_dev_close()!= 0 treat a successful close as a failure.Use a separate
cb_retvariable for the unregister return value so a successful unregister never clobbers an earlier error stored in ret, and stop retrying once unregister fails with anything other than-EAGAIN, since those errors are not transient.
Quoted 4 lines
Fixes 62024eb82756 ("ethdev: change stop operation callback to return int")Signed-off-by Sid Ali Cherrati <[email protected]>
Quoted 14 lines
---
v2: use a temporarycb_retvariable instead of unconditionally zeroing
ret, and stop retrying on a non-transient unregister error, so an earlier error is not lost or masked by a successful/failed unregisterdrivers/net/intel/i40e/i40e_ethdev.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/net/intel/i40e/i40e_ethdev.c +0
-0
drivers/net/intel/i40e/i40e_ethdev.c i40e_dev_close(struct rte_eth_dev *dev) · line 2696
Quoted 4 lines
drivers/net/intel/i40e/i40e_ethdev.c +1
-0@@ -2693,6 +2693,7 @@ i40e_dev_close(struct rte_eth_dev *dev)uint32_t reg;int i;int ret; +int cb_ret;
Since this value is only used inside do { } while, I think it's best to just declare it there. Will adjust on apply unless there are objections.
Quoted 28 lines
drivers/net/intel/i40e/i40e_ethdev.c +7
-4uint8_t aq_fail =0 ;int retries =0 ;@@ -2761,14 +2762,17 @@ i40e_dev_close(struct rte_eth_dev *dev)i40e_pf_host_uninit (dev);do { - ret =rte_intr_callback_unregister (intr_handle, + cb_ret =rte_intr_callback_unregister (intr_handle, i40e_dev_interrupt_handler, dev); -if (ret >=0 || ret == -ENOENT ) { +if (cb_ret >=0 || cb_ret == -ENOENT ) {break ; - }else if (ret != -EAGAIN ) { + }else if (cb_ret != -EAGAIN ) {PMD_INIT_LOG (ERR ,"intr callback unregister failed: %d" , - ret); + cb_ret); +if (ret ==0 ) + ret = cb_ret; +break ; }i40e_msec_delay (500 ); }while (retries++ <5 );Signature · 1 line
2.34.1
Quoted 12 lines · Bruce Richardson
Quoted 11 lines · Sid Ali Cherrati
rte_intr_callback_unregister()returns the number of unregistered callbacks on success. Since the close operation started returning the ret variable instead of 0, this positive value leaks as the return value ofi40e_dev_close(), so applications checkingrte_eth_dev_close()!= 0 treat a successful close as a failure.Use a separate
cb_retvariable for the unregister return value so a successful unregister never clobbers an earlier error stored in ret, and stop retrying once unregister fails with anything other than-EAGAIN, since those errors are not transient.
Quoted 6 lines
Quoted 4 lines
Fixes 62024eb82756 ("ethdev: change stop operation callback to return int")Signed-off-by Sid Ali Cherrati <[email protected]>Acked-by Bruce Richardson <[email protected]>Quoted 1 line
---
Both patches applied to dpdk-next-net-intel.
Thanks,
/Bruce