mbuf: allow dynamic flags to be used by secondary process
PATCH 1/1 mbuf: allow dynamic flags to be used by secondary process
The dynamic flag management is broken for multi-process environment. All calls to lookup dynamic flags or fields will fail in secondary process. This is because the local pointer to the memzone is not ever initialized.
Fix it by using the same checks as dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.
--- lib/librte_mbuf/rte_mbuf_dyn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.c +2 -2
@@ -185,7 +185,7 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { +if (shm ==NULL &&init_shared_mem () <0 ) { rte_errno =ENOENT ;return -1 ; }
@@ -384,7 +384,7 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { +if (shm ==NULL &&init_shared_mem () <0 ) { rte_errno =ENOENT ;return -1 ; }
Signature · 1 line
2.27.0
Hi Stephen,
Quoted 1 line · Stephen Hemminger
mbuf: allow dynamic flags to be used by secondary process
Suggested title:
mbuf: fix dynamic flags lookup from secondary process
Quoted 5 lines
The dynamic flag management is broken for multi-process environment. All calls to lookup dynamic flags or fields will fail in secondary process. This is because the local pointer to the memzone is not ever initialized.
Quoted 7 lines
Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")Signed-off-by Stephen Hemminger <[email protected]>
Good catch, please Cc stable for v2.
Quoted 9 lines
--- lib/librte_mbuf/rte_mbuf_dyn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)lib/librte_mbuf/rte_mbuf_dyn.c +0
-0
lib/librte_mbuf/rte_mbuf_dyn.c rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) · line 191
Quoted 8 lines
lib/librte_mbuf/rte_mbuf_dyn.c +1
-1@@ -185,7 +185,7 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { +if (shm ==NULL &&init_shared_mem () <0 ) { rte_errno =ENOENT ;return -1 ; }
init_shared_mem() is supposed to be called with tailq lock held.
I think the test (shm == NULL && init_shared_mem() < 0) should be moved in __mbuf_dynfield_lookup().
lib/librte_mbuf/rte_mbuf_dyn.c rte_mbuf_dynflag_lookup(const char *name, · line 390
Quoted 9 lines
lib/librte_mbuf/rte_mbuf_dyn.c +1
-1@@ -384,7 +384,7 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { +if (shm ==NULL &&init_shared_mem () <0 ) { rte_errno =ENOENT ;return -1 ; }
Same here
Thanks,
Olivier
PATCH v2 1/1 mbuf: allow dynamic flags to be used by secondary process
In reply to Stephen HemmingerThe dynamic flag management is broken if rte_mbuf_dynflag_lookup() is done in a secondary process because the local pointer to the memzone is not ever initialized.
Fix it by using the same checks as dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.
---
v2 - move check to inside locked region
lib/librte_mbuf/rte_mbuf_dyn.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.c +8 -12
@@ -185,13 +185,11 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynfield ==NULL ) {
@@ -384,13 +382,11 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynflag =__mbuf_dynflag_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynflag =NULL ; +else + mbuf_dynflag =__mbuf_dynflag_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynflag ==NULL ) {
Signature · 1 line
2.27.0
PATCH v3 1/1 mbuf: fix dynamic flags lookup from secondary process
In reply to Stephen HemmingerThe dynamic flag management is broken if rte_mbuf_dynflag_lookup() is done in a secondary process because the local pointer to the memzone is not ever initialized.
Fix it by using the same checks as dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.
---
v3 - change title, fix one extra whitespace
lib/librte_mbuf/rte_mbuf_dyn.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.c +8 -12
@@ -185,13 +185,11 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynfield ==NULL ) {
@@ -384,13 +382,11 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynflag =__mbuf_dynflag_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynflag =NULL ; +else + mbuf_dynflag =__mbuf_dynflag_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynflag ==NULL ) {
Signature · 1 line
2.27.0
Re: [dpdk-dev] [PATCH v3] mbuf: fix dynamic flags lookup from secondary process
Hi Stephen,
Quoted 40 lines · Stephen Hemminger
The dynamic flag management is broken if
rte_mbuf_dynflag_lookup()is done in a secondary process because the local pointer to the memzone is not ever initialized.Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")Signed-off-by Stephen Hemminger <[email protected]>---
v3 - change title, fix one extra whitespace
lib/librte_mbuf/rte_mbuf_dyn.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)lib/librte_mbuf/rte_mbuf_dyn.c +4
-6@@ -185,13 +185,11 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynfield ==NULL ) {
lib/librte_mbuf/rte_mbuf_dyn.c
Quoted 2 lines
lib/librte_mbuf/rte_mbuf_dyn.c +0
-0rte_errno =ENOENT ;return -1 ;
There is still a small corner case here: on a primary process, init_shared_mem() can return -1 in case rte_memzone_reserve_aligned() returns a NULL memzone. In this situation, rte_errno is set by the memzone layer by overriden to ENOENT.
Maybe something like this is better, what do you think?
@@ -172,7 +172,7 @@ __mbuf_dynfield_lookup(const char *name)
break;
}
- if (te == NULL) {
+ if (te == NULL || mbuf_dynfield == NULL) {
rte_errno = ENOENT;
return NULL;
}
@@ -185,19 +185,15 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params)
{
struct mbuf_dynfield_elt *mbuf_dynfield;
- if (shm == NULL) {
- rte_errno = ENOENT;
- return -1;
- }
-
rte_mcfg_tailq_read_lock();
- mbuf_dynfield = __mbuf_dynfield_lookup(name);
+ if (shm == NULL && init_shared_mem() < 0)
+ mbuf_dynfield = NULL;
+ else
+ mbuf_dynfield = __mbuf_dynfield_lookup(name);
rte_mcfg_tailq_read_unlock();
- if (mbuf_dynfield == NULL) {
- rte_errno = ENOENT;
+ if (mbuf_dynfield == NULL)
return -1;
- }
if (params != NULL)
memcpy(params, &mbuf_dynfield->params, sizeof(*params));
Thanks,
Olivier
Quoted 21 lines
lib/librte_mbuf/rte_mbuf_dyn.c +4
-6@@ -384,13 +382,11 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynflag =__mbuf_dynflag_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynflag =NULL ; +else + mbuf_dynflag =__mbuf_dynflag_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynflag ==NULL ) {Signature · 1 line
2.27.0
Re: [dpdk-dev] [PATCH v3] mbuf: fix dynamic flags lookup from secondary process
Quoted 51 lines · On Mon, 26 Oct 2020 11:39:35 +0100 Olivier Matz <[email protected]> wrote:
Hi Stephen,
Quoted 40 lines · Stephen Hemminger
The dynamic flag management is broken if
rte_mbuf_dynflag_lookup()is done in a secondary process because the local pointer to the memzone is not ever initialized.Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")Signed-off-by Stephen Hemminger <[email protected]>---
v3 - change title, fix one extra whitespace
lib/librte_mbuf/rte_mbuf_dyn.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)lib/librte_mbuf/rte_mbuf_dyn.c +4
-6@@ -185,13 +185,11 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynfield ==NULL ) {lib/librte_mbuf/rte_mbuf_dyn.c
Quoted 2 lines
lib/librte_mbuf/rte_mbuf_dyn.c +0
-0rte_errno =ENOENT ;return -1 ;There is still a small corner case here: on a primary process,
init_shared_mem()can return -1 in caserte_memzone_reserve_aligned()returns a NULL memzone. In this situation,rte_errnois set by the memzone layer by overriden to ENOENT.
Quoted 1 line
Maybe something like this is better, what do you think?
Sure, for what I was using rte_errno was not important. And since it was previously broken lets get it fixed.
Re: [dpdk-dev] [PATCH v3] mbuf: fix dynamic flags lookup from secondary process
Stephen, we are waiting for a v4 please.
26/10/2020 15:49, Stephen Hemminger:
Quoted 59 lines
Quoted 51 lines · On Mon, 26 Oct 2020 11:39:35 +0100 Olivier Matz <[email protected]> wrote:
Hi Stephen,
Quoted 40 lines · Stephen Hemminger
The dynamic flag management is broken if
rte_mbuf_dynflag_lookup()is done in a secondary process because the local pointer to the memzone is not ever initialized.Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")Signed-off-by Stephen Hemminger <[email protected]>---
v3 - change title, fix one extra whitespace
lib/librte_mbuf/rte_mbuf_dyn.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)lib/librte_mbuf/rte_mbuf_dyn.c +4
-6@@ -185,13 +185,11 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynfield ==NULL ) {lib/librte_mbuf/rte_mbuf_dyn.c
Quoted 2 lines
lib/librte_mbuf/rte_mbuf_dyn.c +0
-0rte_errno =ENOENT ;return -1 ;There is still a small corner case here: on a primary process,
init_shared_mem()can return -1 in caserte_memzone_reserve_aligned()returns a NULL memzone. In this situation,rte_errnois set by the memzone layer by overriden to ENOENT.Quoted 1 line
Maybe something like this is better, what do you think?
Sure, for what I was using
rte_errnowas not important. And since it was previously broken lets get it fixed.
PATCH v4 1/1 mbuf: allow dynamic flags to be used by secondary process
In reply to Stephen HemmingerThe dynamic flag management is broken if rte_mbuf_dynflag_lookup() is done in a secondary process because the local pointer to the memzone is not ever initialized.
Fix it by using the same checks as dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.
---
v4 - incorporate Oliver's fix for rte_errno
lib/librte_mbuf/rte_mbuf_dyn.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.c +10 -16
@@ -172,7 +172,7 @@ __mbuf_dynfield_lookup(const char *name)break ; } -if (te ==NULL ) { +if (te ==NULL || mbuf_dynfield ==NULL ) { rte_errno =ENOENT ;return NULL ; }
@@ -185,19 +185,15 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock (); -if (mbuf_dynfield ==NULL ) { - rte_errno =ENOENT ; +if (mbuf_dynfield ==NULL )return -1 ; - }if (params !=NULL )memcpy (params, &mbuf_dynfield->params,sizeof (*params));
@@ -384,13 +380,11 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynflag =__mbuf_dynflag_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynflag =NULL ; +else + mbuf_dynflag =__mbuf_dynflag_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynflag ==NULL ) {
Signature · 1 line
2.27.0
Hi Stephen,
Quoted 63 lines · Stephen Hemminger
The dynamic flag management is broken if
rte_mbuf_dynflag_lookup()is done in a secondary process because the local pointer to the memzone is not ever initialized.Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")Signed-off-by Stephen Hemminger <[email protected]>---
v4 - incorporate Oliver's fix forrte_errnolib/librte_mbuf/rte_mbuf_dyn.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)lib/librte_mbuf/rte_mbuf_dyn.c +6
-14@@ -172,7 +172,7 @@ __mbuf_dynfield_lookup(const char *name)break ; } -if (te ==NULL ) { +if (te ==NULL || mbuf_dynfield ==NULL ) { rte_errno =ENOENT ;return NULL ; }@@ -185,19 +185,15 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock (); -if (mbuf_dynfield ==NULL ) { - rte_errno =ENOENT ; +if (mbuf_dynfield ==NULL )return -1 ; - }if (params !=NULL )memcpy (params, &mbuf_dynfield->params,sizeof (*params));@@ -384,13 +380,11 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - }
lib/librte_mbuf/rte_mbuf_dyn.c rte_mbuf_dynflag_lookup(const char *name, · line 390
Quoted 10 lines
lib/librte_mbuf/rte_mbuf_dyn.c +4
-2-rte_mcfg_tailq_read_lock (); - mbuf_dynflag =__mbuf_dynflag_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynflag =NULL ; +else + mbuf_dynflag =__mbuf_dynflag_lookup (name);rte_mcfg_tailq_read_unlock ();if (mbuf_dynflag ==NULL ) {
The v4 change is missing for flags:
- if (mbuf_dynflag == NULL) {
- rte_errno = ENOENT;
+ if (mbuf_dynflag == NULL)
return -1;
- }PATCH v5 1/1 mbuf: allow dynamic flags to be used by secondary process
In reply to Stephen HemmingerThe dynamic flag management is broken if rte_mbuf_dynflag_lookup() is done in a secondary process because the local pointer to the memzone is not ever initialized.
Fix it by using the same checks as dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.
---
v5 - fix additional rte_errno overwrite
lib/librte_mbuf/rte_mbuf_dyn.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.c +11 -19
@@ -172,7 +172,7 @@ __mbuf_dynfield_lookup(const char *name)break ; } -if (te ==NULL ) { +if (te ==NULL || mbuf_dynfield ==NULL ) { rte_errno =ENOENT ;return NULL ; }
@@ -185,19 +185,15 @@ rte_mbuf_dynfield_lookup(const char *name, struct rte_mbuf_dynfield *params) {struct mbuf_dynfield_elt *mbuf_dynfield; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynfield =__mbuf_dynfield_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynfield =NULL ; +else + mbuf_dynfield =__mbuf_dynfield_lookup (name);rte_mcfg_tailq_read_unlock (); -if (mbuf_dynfield ==NULL ) { - rte_errno =ENOENT ; +if (mbuf_dynfield ==NULL )return -1 ; - }if (params !=NULL )memcpy (params, &mbuf_dynfield->params,sizeof (*params));
@@ -384,19 +380,15 @@ rte_mbuf_dynflag_lookup(const char *name, {struct mbuf_dynflag_elt *mbuf_dynflag; -if (shm ==NULL ) { - rte_errno =ENOENT ; -return -1 ; - } -rte_mcfg_tailq_read_lock (); - mbuf_dynflag =__mbuf_dynflag_lookup (name); +if (shm ==NULL &&init_shared_mem () <0 ) + mbuf_dynflag =NULL ; +else + mbuf_dynflag =__mbuf_dynflag_lookup (name);rte_mcfg_tailq_read_unlock (); -if (mbuf_dynflag ==NULL ) { - rte_errno =ENOENT ; +if (mbuf_dynflag ==NULL )return -1 ; - }if (params !=NULL )memcpy (params, &mbuf_dynflag->params,sizeof (*params));
Signature · 1 line
2.27.0
Quoted 11 lines · Stephen Hemminger
The dynamic flag management is broken if
rte_mbuf_dynflag_lookup()is done in a secondary process because the local pointer to the memzone is not ever initialized.Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")Signed-off-by Stephen Hemminger <[email protected]>
Thanks!
David Marchand
AppliedQuoted 10 lines · Olivier Matz
Quoted 9 lines · Stephen Hemminger
The dynamic flag management is broken if
rte_mbuf_dynflag_lookup()is done in a secondary process because the local pointer to the memzone is not ever initialized.Fix it by using the same checks as
dynfield_register(). I.e if shared memory zone has not been looked up already, then discover it.Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")
Quoted 2 lines
Quoted 1 line
Signed-off-by Stephen Hemminger <[email protected]>Acked-by Olivier Matz <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand