[LTP] [PATCH] pidns32: fix PID namespace nesting depth off-by-one

Cyril Hrubis chrubis@suse.cz
Mon Mar 30 16:42:21 CEST 2026


Hi!
> > The 2023 refactor used tst_atomic_inc() before clone with a zero-initial
> > counter, which only performed 31 CLONE_NEWPID nests while still expecting
> > MAXNEST (32). Compare the level to MAXNEST first, then increment and clone,
> > so the shared counter runs 0..32 and the chain reaches 32 nested namespaces
> > again.
> 
> Indeed, good catch.
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

Given that we no longer have to implement atomic operations in assembly
and can rely on compiler we can easily add post increment as well.

Should be as easy as:

diff --git a/include/tst_atomic.h b/include/tst_atomic.h
index 9d255bc44..9433291ca 100644
--- a/include/tst_atomic.h
+++ b/include/tst_atomic.h
@@ -30,6 +30,11 @@ static inline void tst_atomic_store(int32_t i, tst_atomic_t *v)
        __atomic_store_n(v, i, __ATOMIC_SEQ_CST);
 }
 
+static inline tst_atomic_return_add(int32_t i, tst_atomic_t *v)
+{
+       return __atomic_fetch_add(v, i, __ATOMIC_SEQ_CST);
+}
+
 #elif HAVE_SYNC_ADD_AND_FETCH == 1
 
 /* Use __sync built-ins (GCC >= 4.1), with explicit memory barriers. */
@@ -39,6 +44,11 @@ static inline int tst_atomic_add_return(int32_t i, tst_atomic_t *v)
        return __sync_add_and_fetch(v, i);
 }
 
+static inline tst_atomic_return_add(int32_t i, tst_atomic_t *v)
+{
+       return __sync_fetch_and_add(v, i);
+}


Then we can do tst_atomic_return_add(1, &level) instead of two different
atomic operations.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list