Skip to contentSkip to conversation

ethdev: avoid unregistering a non-allocated callback

PATCH In review Thomas Monjalon 4 participants 8 messages Jul 13, 2021 – Sep 26, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethdev: avoid unregistering a non-allocated callback

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all ports")
---
 lib/ethdev/rte_ethdev.c | 2 --
 1 file changed, 2 deletions(-)
lib/ethdev/rte_ethdev.c +0 -2
index 9d95cd11e1..1731854628 100644
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t port_id,
 						  user_cb, next);
 			} else {
 				rte_spinlock_unlock(&eth_dev_cb_lock);
-				rte_eth_dev_callback_unregister(port_id, event,
-								cb_fn, cb_arg);
 				return -ENOMEM;
 			}
 
Signature · 1 line
2.31.1
#2 lore raw
In reply to Thomas Monjalon

Hi Thomas

From: Thomas Monjalon

Quoted 16 lines

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all ports")
---
 lib/ethdev/rte_ethdev.c | 2 --
 1 file changed, 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1731854628 100644

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t port_id, · line 4653

Quoted 5 lines
lib/ethdev/rte_ethdev.c +0 -2
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t port_id,
                                                  user_cb, next);
                        } else {
                                rte_spinlock_unlock(&eth_dev_cb_lock);
-                               rte_eth_dev_callback_unregister(port_id, event,
-                                                               cb_fn, cb_arg);

Please pay attention to the case of port_id=RTE_ETH_ALL where the user wants to register the event for all the ports.

In this case, when a failure happens for one of the ports, this unregister call cleans the callback from all the ports.

Quoted 5 lines
lib/ethdev/rte_ethdev.c +0 -1
                                return -ENOMEM;
                        }
 
--

2.31.1

#3 lore raw

13/07/2021 15:42, Matan Azrad:

Quoted 27 lines

Hi Thomas

From: Thomas Monjalon

Quoted 16 lines

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all ports")
---
 lib/ethdev/rte_ethdev.c | 2 --
 1 file changed, 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1731854628 100644

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t port_id, · line 4653

Quoted 5 lines
lib/ethdev/rte_ethdev.c +0 -2
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t port_id,
                                                  user_cb, next);
                        } else {
                                rte_spinlock_unlock(&eth_dev_cb_lock);
-                               rte_eth_dev_callback_unregister(port_id, event,
-                                                               cb_fn, cb_arg);

Please pay attention to the case of port_id=RTE_ETH_ALL where the user wants to register the event for all the ports.

Quoted 1 line

In this case, when a failure happens for one of the ports, this unregister call cleans the callback from all the ports.

Yes I missed it. Now I better understand the intent, thanks.

Next question: do we really want to rollback already registered ports? Anyway, if we are out of memory, I think it is better not doing more operations. There can be various opinions on this topic, please give yours.

#4 lore raw

From: Thomas Monjalon

Quoted 32 lines

13/07/2021 15:42, Matan Azrad:

Quoted 15 lines

Hi Thomas

From: Thomas Monjalon

Quoted 12 lines

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all

ports")
Cc: [email protected]

---
 lib/ethdev/rte_ethdev.c | 2 --
 1 file changed, 2 deletions(-)
Quoted 5 lines

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t

Quoted 5 lines
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1731854628 100644

lib/ethdev/rte_ethdev.c +0 -0
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t

port_id,

Quoted 7 lines

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t port_id, · line 4653

Quoted 5 lines
lib/ethdev/rte_ethdev.c +0 -2
                                                  user_cb, next);
                        } else {
                                rte_spinlock_unlock(&eth_dev_cb_lock);
-                               rte_eth_dev_callback_unregister(port_id, event,
-                                                               cb_fn, cb_arg);

Please pay attention to the case of port_id=RTE_ETH_ALL where the user

wants to register the event for all the ports.

Quoted 2 lines

In this case, when a failure happens for one of the ports, this unregister call

Quoted 8 lines

cleans the callback from all the ports.

Yes I missed it. Now I better understand the intent, thanks.

Next question: do we really want to rollback already registered ports? Anyway, if we are out of memory, I think it is better not doing more operations.
There can be various opinions on this topic, please give yours.

Sure,
I understand that memory error is serious,
Do you think it is a fatal error? If so, maybe we should use rte_exit?

That way or others, I think the behavior should be a convention for all the file functions(at least).

I tend to do cleanup on any error.

Matan

#5 lore raw

14/07/2021 16:16, Matan Azrad:

Quoted 28 lines

From: Thomas Monjalon

Quoted 27 lines

13/07/2021 15:42, Matan Azrad:

Quoted 8 lines

From: Thomas Monjalon

Quoted 7 lines

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all

ports")
Cc: [email protected]

Quoted 11 lines

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t · line 4652

Quoted 9 lines

---

lib/ethdev/rte_ethdev.c +0 -2
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t
                        } else {
                                rte_spinlock_unlock(&eth_dev_cb_lock);
-                               rte_eth_dev_callback_unregister(port_id, event,
-                                                               cb_fn, cb_arg);

Please pay attention to the case of port_id=RTE_ETH_ALL where the user

wants to register the event for all the ports.

Quoted 2 lines

In this case, when a failure happens for one of the ports, this unregister call

cleans the callback from all the ports.

Yes I missed it. Now I better understand the intent, thanks.

Quoted 8 lines
Quoted 4 lines

Next question: do we really want to rollback already registered ports? Anyway, if we are out of memory, I think it is better not doing more operations.
There can be various opinions on this topic, please give yours.

Sure,
I understand that memory error is serious,
Do you think it is a fatal error? If so, maybe we should use rte_exit?

We don't call rte_exit in the lib, so the app can do whatever it wants.

Quoted 1 line

That way or others, I think the behavior should be a convention for all the file functions(at least).

What do you mean "all the file functions"?

Quoted 1 line

I tend to do cleanup on any error.

I would like to hear opinions from others as well.

#6 lore raw
Quoted 34 lines · Thomas Monjalon

14/07/2021 16:16, Matan Azrad:

Quoted 33 lines

From: Thomas Monjalon

Quoted 31 lines

13/07/2021 15:42, Matan Azrad:

Quoted 8 lines

From: Thomas Monjalon

Quoted 7 lines

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all

ports")
Cc: [email protected]

Quoted 11 lines

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t · line 4652

Quoted 9 lines

---

lib/ethdev/rte_ethdev.c +0 -2
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t
                        } else {
                                rte_spinlock_unlock(&eth_dev_cb_lock);
-                               rte_eth_dev_callback_unregister(port_id, event,
-                                                               cb_fn, cb_arg);

Please pay attention to the case of port_id=RTE_ETH_ALL where the user

wants to register the event for all the ports.

Quoted 2 lines

In this case, when a failure happens for one of the ports, this unregister call

cleans the callback from all the ports.

Yes I missed it. Now I better understand the intent, thanks.

Next question: do we really want to rollback already registered ports? Anyway, if we are out of memory, I think it is better not doing more operations.
There can be various opinions on this topic, please give yours.

Quoted 6 lines
Quoted 3 lines

Sure,
I understand that memory error is serious,
Do you think it is a fatal error? If so, maybe we should use rte_exit?

We don't call rte_exit in the lib, so the app can do whatever it wants.

+1

Quoted 8 lines
Quoted 1 line

That way or others, I think the behavior should be a convention for all the file functions(at least).

What do you mean "all the file functions"?

Quoted 1 line

I tend to do cleanup on any error.

I would like to hear opinions from others as well.

I also tend to do the cleanup, since API returns error I think application will be right to think that no callback registered, partially registered callbacks on error can be confusing.

#7 lore raw

This patch is abandoned. Current behaviour is kept.

15/07/2021 11:06, Ferruh Yigit:

Quoted 56 lines · Thomas Monjalon
Quoted 34 lines

14/07/2021 16:16, Matan Azrad:

Quoted 33 lines

From: Thomas Monjalon

Quoted 31 lines

13/07/2021 15:42, Matan Azrad:

Quoted 8 lines

From: Thomas Monjalon

Quoted 7 lines

When registering a new event callback, if allocation fails, there is no need for unregistering the callback, because it is not registered.

Fixes 9ec0b3869d8d ("ethdev: allow event registration for all

ports")
Cc: [email protected]

Quoted 11 lines

lib/ethdev/rte_ethdev.c rte_eth_dev_callback_register(uint16_t · line 4652

Quoted 9 lines

---

lib/ethdev/rte_ethdev.c +0 -2
@@ -4649,8 +4649,6 @@ rte_eth_dev_callback_register(uint16_t
                        } else {
                                rte_spinlock_unlock(&eth_dev_cb_lock);
-                               rte_eth_dev_callback_unregister(port_id, event,
-                                                               cb_fn, cb_arg);

Please pay attention to the case of port_id=RTE_ETH_ALL where the user

wants to register the event for all the ports.

Quoted 2 lines

In this case, when a failure happens for one of the ports, this unregister call

cleans the callback from all the ports.

Yes I missed it. Now I better understand the intent, thanks.

Next question: do we really want to rollback already registered ports? Anyway, if we are out of memory, I think it is better not doing more operations.
There can be various opinions on this topic, please give yours.

Quoted 6 lines
Quoted 3 lines

Sure,
I understand that memory error is serious,
Do you think it is a fatal error? If so, maybe we should use rte_exit?

We don't call rte_exit in the lib, so the app can do whatever it wants.

+1

Quoted 8 lines
Quoted 1 line

That way or others, I think the behavior should be a convention for all the file functions(at least).

What do you mean "all the file functions"?

Quoted 1 line

I tend to do cleanup on any error.

I would like to hear opinions from others as well.

I also tend to do the cleanup, since API returns error I think application will be right to think that no callback registered, partially registered callbacks on error can be confusing.