[DTrace-devel] [PATCH v3] test: account for member name change in mm_struct
Eugene Loh
eugene.loh at oracle.com
Tue Feb 10 18:39:25 UTC 2026
A few minor comments:
On 2/10/26 12:35, Kris Van Hees via DTrace-devel wrote:
> The flexible array at the end of the mm_struct has changed name in newer
> kernels. Rather than depending on a particular name, we can simply get
> the name of the last member (since that is there the flexible array is
> always found) and try to use that.
>
> The testsuite gains a dependency on bpftool for this test.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> dtrace.spec | 2 +-
> .../arrays/tst.ctf-dynsized-bounds-runtime.d | 25 -----------
> .../arrays/tst.ctf-dynsized-bounds-runtime.sh | 43 +++++++++++++++++++
> 3 files changed, 44 insertions(+), 26 deletions(-)
> delete mode 100644 test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.d
> create mode 100755 test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.sh
>
> diff --git a/dtrace.spec b/dtrace.spec
> index d6af5a80..e0d832ac 100644
> --- a/dtrace.spec
> +++ b/dtrace.spec
> @@ -115,7 +115,7 @@ Requires: %{name}-devel = %{version}-%{release} perl gcc java
> Requires: java-devel perl-IO-Socket-IP perl-Net-Ping xfsprogs
> Requires: exportfs vim-minimal %{name}%{?_isa} = %{version}-%{release}
> Requires: coreutils wireshark %{glibc32}
> -Requires: time bc nfs-utils
> +Requires: time bc nfs-utils bpftool
> Suggests: kernel-uek-tools
> Autoreq: 0
> Group: Development/System
> diff --git a/test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.d b/test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.d
> deleted file mode 100644
> index f3801454..00000000
> --- a/test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.d
> +++ /dev/null
> @@ -1,25 +0,0 @@
> -/*
> - * Oracle Linux DTrace.
> - * Copyright (c) 2023, 2024, 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.
> - */
> -
> -/*
> - * ASSERTION: Array accesses work for CTF-declared arrays of dynamic size
> - * (ensuring the bounds checking is also bypassed at runtime).
> - *
> - * SECTION: Pointers and Arrays/Array Declarations and Storage
> - */
> -
> -BEGIN
> -{
> - i = pid - pid; /* Non-constant 0 value. */
> - trace(curthread->mm->cpu_bitmap[i]);
> - exit(0);
> -}
> -
> -ERROR
> -{
> - exit(1);
> -}
> diff --git a/test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.sh b/test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.sh
> new file mode 100755
> index 00000000..60fe6afc
> --- /dev/null
> +++ b/test/unittest/arrays/tst.ctf-dynsized-bounds-runtime.sh
> @@ -0,0 +1,43 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, 2026, 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.
> +
> +# ASSERTION: Array accesses work for CTF-declared arrays of dynamic size
> +# (ensuring the bounds checking is also bypassed at runtime).
> +#
> +# SECTION: Pointers and Arrays/Array Declarations and Storage
> +
> +dtrace=$1
> +
> +# The mm_struct 'cpu_bitmap' was renamed to 'flexible_array', so we need to
> +# see which member name the current kernel uses. Since it is always the last
> +# member of mm_struct, we just use that member name, and hope for the best.
> +# If mm_struct ever gets changed to not have a flesible array at its end, this
s/flesible/flexible/
> +# test will need a new structure to work with.
> +# are out of luck.
/are out of luck/d
> +
> +# Determine the member name we should use.
> +member=`bpftool btf dump id 1 | \
> + awk '/^\[[0-9]+\] STRUCT \047mm_struct\047/ { in_mm = 1; next; }
> + /^\t/ && in_mm { fld = $1; gsub(/\047/, "", fld); next }
> + /^\[[0-9]+\] [A-Z]+ \047/ && in_mm { print fld; exit; }'`
The search for the end of STRUCT looks for [A-Z]+, but could there be a
'_' in there? E.g., for "FUNC_PROTO"?
> +
> +
> +# Try to access the flexible array.
> +$dtrace $dt_flags -qn "
> +BEGIN
> +{
> + i = pid - pid; /* non-constant 0 value */
> + v = curthread->mm->$member[i];
> + exit(0);
> +}
> +
> +ERROR
> +{
> + exit(1);
> +}"
> +
> +echo $?
More information about the DTrace-devel
mailing list