[DTrace-devel] [PATCH v2] test: account for member name change in mm_struct
Kris Van Hees
kris.van.hees at oracle.com
Tue Feb 10 17:26:34 UTC 2026
Woops, forgot to add the change to dtrace.spec. v3 coming
On Tue, Feb 10, 2026 at 11:48:51AM -0500, Kris Van Hees 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.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> .../arrays/tst.ctf-dynsized-bounds-runtime.d | 25 -----------
> .../arrays/tst.ctf-dynsized-bounds-runtime.sh | 43 +++++++++++++++++++
> 2 files changed, 43 insertions(+), 25 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/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
> +# test will need a new structure to work with.
> +# are out of luck.
> +
> +# 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; }'`
> +
> +
> +# 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 $?
> --
> 2.51.0
>
More information about the DTrace-devel
mailing list