public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>,
	ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] pidns32: fix PID namespace nesting depth off-by-one
Date: Mon, 30 Mar 2026 16:42:21 +0200	[thread overview]
Message-ID: <acqLzcXEo0uU0aSD@yuki.lan> (raw)
In-Reply-To: <20260330133304.GA93779@pevik>

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2026-03-30 14:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 10:07 [LTP] [PATCH] pidns32: fix PID namespace nesting depth off-by-one Vasileios Almpanis via ltp
2026-03-30 10:23 ` Andrea Cervesato via ltp
2026-03-30 13:33 ` Petr Vorel
2026-03-30 14:42   ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=acqLzcXEo0uU0aSD@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    --cc=vasileios.almpanis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox