From: Kris Van Hees <kris.van.hees@oracle.com>
To: eugene.loh@oracle.com
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH] Set lockmem limit before checking BPF helper functions
Date: Wed, 15 Oct 2025 01:01:05 -0400 [thread overview]
Message-ID: <aO8qkXagh4JYW6C9@oracle.com> (raw)
In-Reply-To: <20251015044752.3919-1-eugene.loh@oracle.com>
On Wed, Oct 15, 2025 at 12:47:52AM -0400, eugene.loh@oracle.com wrote:
> 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>
Reviewed-by: Kris Van Hees <kris.van.hees@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
>
prev parent reply other threads:[~2025-10-15 5:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 4:47 [PATCH] Set lockmem limit before checking BPF helper functions eugene.loh
2025-10-15 5:01 ` Kris Van Hees [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=aO8qkXagh4JYW6C9@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
--cc=eugene.loh@oracle.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