public inbox for dtrace@lists.linux.dev
 help / color / mirror / Atom feed
From: eugene.loh@oracle.com
To: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: [PATCH] Set lockmem limit before checking BPF helper functions
Date: Wed, 15 Oct 2025 00:47:52 -0400	[thread overview]
Message-ID: <20251015044752.3919-1-eugene.loh@oracle.com> (raw)

From: Eugene Loh <eugene.loh@oracle.com>

In dtrace_init(), we set the locked-memory limit, either to the
user-specified value (if any) or to unlimited (by default).  We also check
to make sure that certain BPF helper functions are available, falling
over to alternatives or indicating they are not available in case of
problems.

It is possible, however, that the limit is too low when dtrace starts,
causing problems with the helper-function tests before dtrace_init()
even has a chance to reset the limit.

Switch the order to set the limit before checking the helper functions.

A test is added.  The underlying problem, however, depends on kernel
version, how locked memory is handled, the behavior of fallback
functions, and so on.  So the test could easily pass on some systems
even if the fix is not employed.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
---
 libdtrace/dt_open.c                    | 14 +++++++-------
 test/unittest/misc/tst.lockmem-init.r  |  3 +++
 test/unittest/misc/tst.lockmem-init.sh | 20 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 7 deletions(-)
 create mode 100644 test/unittest/misc/tst.lockmem-init.r
 create mode 100755 test/unittest/misc/tst.lockmem-init.sh

diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
index 17dfbf9a6..54adec02a 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -1213,13 +1213,6 @@ dtrace_init(dtrace_hdl_t *dtp)
 		return dt_set_errno(dtp, EDT_CTF);
 	}
 
-	/*
-	 * Initialize the BPF library handling.
-	 */
-	dt_bpf_init(dtp);
-	dt_btf_get_module_ids(dtp);
-	dt_dlib_init(dtp);
-
 	/*
 	 * Set the locked-memory limit.
 	 */
@@ -1228,6 +1221,13 @@ dtrace_init(dtrace_hdl_t *dtp)
 	rl.rlim_cur = rl.rlim_max = lockmem;
 	setrlimit(RLIMIT_MEMLOCK, &rl);
 
+	/*
+	 * Initialize the BPF library handling.
+	 */
+	dt_bpf_init(dtp);
+	dt_btf_get_module_ids(dtp);
+	dt_dlib_init(dtp);
+
 	/*
 	 * Initialize consume handling.
 	 */
diff --git a/test/unittest/misc/tst.lockmem-init.r b/test/unittest/misc/tst.lockmem-init.r
new file mode 100644
index 000000000..da8b2a5f9
--- /dev/null
+++ b/test/unittest/misc/tst.lockmem-init.r
@@ -0,0 +1,3 @@
+|Delay in ns needed in delay env|
+-- @@stderr --
+Delay in ns needed in delay env var.
diff --git a/test/unittest/misc/tst.lockmem-init.sh b/test/unittest/misc/tst.lockmem-init.sh
new file mode 100755
index 000000000..1b4dcdeea
--- /dev/null
+++ b/test/unittest/misc/tst.lockmem-init.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+
+dtrace=$1
+
+# Check that dtrace runs by default even if ulimit -l is very low.
+ulimit -l 1
+
+$dtrace $dt_flags -c test/triggers/delaydie -qn '
+syscall::write:entry
+/pid == $target/
+{
+	printf("|%s|", copyinstr(arg1, 32));
+}'
+
+exit $?
-- 
2.47.3


             reply	other threads:[~2025-10-15  4:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15  4:47 eugene.loh [this message]
2025-10-15  5:01 ` [PATCH] Set lockmem limit before checking BPF helper functions Kris Van Hees

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=20251015044752.3919-1-eugene.loh@oracle.com \
    --to=eugene.loh@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    /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