From: Mark Hatle <mark.hatle@kernel.crashing.org>
To: yocto-patches@lists.yoctoproject.org
Subject: [pseudo][PATCH 33/34] wrappers: Don't re-block signals in nested wrapper calls
Date: Tue, 10 Nov 2026 22:21:01 -0600 [thread overview]
Message-ID: <1794370862-30908-34-git-send-email-mark.hatle@kernel.crashing.org> (raw)
In-Reply-To: <1794370862-30908-1-git-send-email-mark.hatle@kernel.crashing.org>
From: Mark Hatle <mark.hatle@amd.com>
pseudo's own calls to wrapped functions, such as fcntl() for the path
lock, go through the full wrapper and block and restore signals again,
although the outer wrapper already blocked them. Skip that when this
thread already holds the pseudo lock, and keep the outer wrapper's
saved mask for exec*().
On a tar/chown/find/ls/rm workload of 40,000 files this halves the
rt_sigprocmask calls, from 3.1M to 1.5M.
AI-Generated: Uses GitHub Copilot
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
doc/program_flow | 4 ++--
pseudo_wrappers.c | 6 ++++++
templates/wrapfuncs.c | 21 ++++++++++++++++-----
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/doc/program_flow b/doc/program_flow
index 4137cf0..5fbdb5d 100644
--- a/doc/program_flow
+++ b/doc/program_flow
@@ -62,7 +62,7 @@ libpseudo execution flow:
return enosys
variadic setup (if necessary)
if pseudo_disabled return real_*()
- pseudo_sigblock
+ pseudo_sigblock (unless this thread already holds the lock)
pseudo_getlock
if antimagic rc = real_*()
else
@@ -74,7 +74,7 @@ libpseudo execution flow:
drop path lock
variadic end (if necessary)
pseudo_droplock
- unmask signals
+ unmask signals (if they were blocked above)
return rc
pseudo execution flow:
diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c
index a4e9015..13d7ede 100644
--- a/pseudo_wrappers.c
+++ b/pseudo_wrappers.c
@@ -58,6 +58,7 @@ static pthread_t pseudo_mutex_holder;
static int pseudo_mutex_recursion = 0;
static int pseudo_getlock(void);
static void pseudo_droplock(void);
+static int pseudo_lock_held(void);
static size_t pseudo_dechroot(char *, size_t);
static void pseudo_sigblock(sigset_t *);
@@ -226,6 +227,11 @@ pseudo_getlock(void) {
}
}
+static int
+pseudo_lock_held(void) {
+ return pthread_equal(pseudo_mutex_holder, pthread_self());
+}
+
static void
pseudo_droplock(void) {
if (--pseudo_mutex_recursion == 0) {
diff --git a/templates/wrapfuncs.c b/templates/wrapfuncs.c
index d7fb548..2fa4212 100644
--- a/templates/wrapfuncs.c
+++ b/templates/wrapfuncs.c
@@ -20,6 +20,7 @@ ${maybe_skip}
${type}
${name}(${decl_args}) {
sigset_t saved;
+ int nested;
${variadic_decl}
${rc_decl}
${paths_decl}
@@ -44,11 +45,17 @@ ${maybe_async_skip}
}
pseudo_debug(PDBGF_WRAPPER, "wrapper called: ${name}\n");
- pseudo_sigblock(&saved);
+ /* If this thread already holds the lock, an outer wrapper has
+ * already blocked signals, so don't block and restore them again.
+ */
+ nested = pseudo_lock_held();
+ if (!nested)
+ pseudo_sigblock(&saved);
pseudo_debug(PDBGF_WRAPPER | PDBGF_VERBOSE, "${name} - signals blocked, obtaining lock\n");
if (pseudo_getlock()) {
errno = EBUSY;
- sigprocmask(SIG_SETMASK, &saved, NULL);
+ if (!nested)
+ sigprocmask(SIG_SETMASK, &saved, NULL);
pseudo_debug(PDBGF_WRAPPER, "${name} failed to get lock, giving EBUSY.\n");
PROFILE_DONE;
${def_return}
@@ -66,8 +73,11 @@ ${maybe_async_skip}
pseudo_debug(PDBGF_SYSCALL, "${name} ignored path, calling real syscall.\n");
${rc_assign} (*real_${name})(${call_args});
} else {
- /* exec*() use this to restore the sig mask */
- pseudo_saved_sigmask = saved;
+ /* exec*() use this to restore the sig mask; a
+ * nested call keeps the outer wrapper's mask.
+ */
+ if (!nested)
+ pseudo_saved_sigmask = saved;
${path_lock_begin}${rc_assign} wrap_$name(${call_args});${path_lock_end}
}
}
@@ -76,7 +86,8 @@ quick_exit:
__attribute__((unused));
save_errno = errno;
pseudo_droplock();
- sigprocmask(SIG_SETMASK, &saved, NULL);
+ if (!nested)
+ sigprocmask(SIG_SETMASK, &saved, NULL);
pseudo_debug(PDBGF_WRAPPER | PDBGF_VERBOSE, "${name} - yielded lock, restored signals\n");
/* not strerror(), which can hang on systems using locale data for it */
pseudo_debug(PDBGF_WRAPPER, "wrapper completed: ${name} returns ${rc_format} (errno: %d)\n", ${rc_value}, save_errno);
--
1.8.3.1
next prev parent reply other threads:[~2026-11-11 4:21 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 4:20 [pseudo][PATCH 00/34] Various fixes Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 01/34] pseudo_client: serialize path changes across clients Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 02/34] ports: hold the path lock in create and metadata wrappers Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 03/34] ports: check created files under the path lock before recording them Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 04/34] test-parallel-ops: Add a parallel create/rename/link/chmod test Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 05/34] ports: Remove PSEUDO_NO_REAL_AT_FUNCTIONS Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 06/34] ports/unix: Remove guts overridden by the Linux port Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 07/34] ports: Let the port define how pseudo stats files Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 08/34] patches/yocto-older-glibc-symbols.patch: Update to latest YP version Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 09/34] Remove unused #if 0 debug code Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 10/34] Replace #if 0 strerror() debug messages with a comment Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 11/34] pseudo_util: Remove stale with_libpseudo() comment Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 12/34] ports/common/subports: Show the unknown OS name in the error Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 13/34] ports/linux: Drop redundant PSEUDO_LINK_SYMLINK_BEHAVIOR override Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 14/34] pseudo_server: Skip events for clients closed earlier in the batch Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 15/34] pseudo_server: Drop an idle client when out of file descriptors Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 16/34] pseudo_server: Always use epoll Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 17/34] configure: Fix --disable-* options Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 18/34] pseudo_server: Lower highest_client when the highest client closes Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 19/34] pseudo_server: Set highest_client to the new client when growing Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 20/34] pseudo_util: Store PSEUDO_SEVERITY as severity names Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 21/34] pseudo: Fix the -k severity option Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 22/34] pseudo_util: Make -v and numeric PSEUDO_DEBUG add debug flags Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 23/34] AGENTS.md: Add to assist future developers Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 24/34] pseudo_util: Fix the date format in the event log dump Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 25/34] pseudo: List -p in the usage message Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 26/34] pseudo_util: Write the event log to PSEUDO_EVLOG_FILE Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 27/34] pseudo.1: Update to match the current code Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 28/34] ports/linux: Don't require <linux/mount.h> Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 29/34] configure: Require GCC 5 or later Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 30/34] doc: Update README and doc/ to match the code Mark Hatle
2026-11-11 4:20 ` [pseudo][PATCH 31/34] configure: Fix the --enable-profiling default Mark Hatle
2026-11-11 4:21 ` [pseudo][PATCH 32/34] pseudo_util: Skip unneeded lstat calls when canonicalizing paths Mark Hatle
2026-11-11 4:21 ` Mark Hatle [this message]
2026-11-11 4:21 ` [pseudo][PATCH 34/34] Wrap execvpe(), fexecve() and execveat() Mark Hatle
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=1794370862-30908-34-git-send-email-mark.hatle@kernel.crashing.org \
--to=mark.hatle@kernel.crashing.org \
--cc=yocto-patches@lists.yoctoproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.