From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: Guixiong Wei <weiguixiong@bytedance.com>, <x86@kernel.org>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Shuah Khan <shuah@kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v4 2/2] selftests/x86/amx: Test dynamic fpstate cleanup across exec()
Date: Fri, 6 Nov 2026 08:40:24 -0800 [thread overview]
Message-ID: <ab483f3d-e036-452e-bf58-6c87e59ae3bb@intel.com> (raw)
In-Reply-To: <4f21cadf18325a5829a27a8cd7107240e8e92c7a.1793604327.git.weiguixiong@bytedance.com>
[-- Attachment #1: Type: text/plain, Size: 570 bytes --]
On 11/2/26 02:30, Guixiong Wei wrote:
> ---
> tools/testing/selftests/x86/amx.c | 251 +++++++++++++++++++++++++++++-
> 1 file changed, 249 insertions(+), 2 deletions(-)
>
The code looks an overkill to me. I also considered using kmemleak, but
this vmallocinfo looks to be efficient.
The other way would be adding a script on top of a small change to amx.c
file. See the attachment.
Can you please try running this on your side and see if it works?
PS: I sent this yesterday but it didn't go through. I switched *.sh to
*.txt in the attachment.
Thanks,
Chang
[-- Attachment #2: amx_exec.txt --]
[-- Type: text/plain, Size: 1500 bytes --]
#!/usr/bin/env bash
NUM_ITERATION=10
if [ "$EUID" -ne 0 ]; then
echo "Error: Please run as root (sudo) to access /proc/vmallocinfo."
exit 1
fi
TMP_BEFORE=$(mktemp)
TMP_AFTER=$(mktemp)
# Function to parse and aggregate vmallocinfo by caller/module
parse_vmalloc() {
# Typical format: 0xffffc90000000000-0xffffc90000002000 8192 pcpu_alloc_alloc+0x3b/0x240 vmalloc
# We aggregate the size (column 2) grouped by the caller function (column 3)
awk '
{
# Remove offset details like +0x3b/0x240 to group by base function name
split($3, caller, "+")
# Keep track of caller type if present (e.g. vmalloc, ioremap)
type = $4 ? " (" $4 ")" : ""
key = caller[1] type
sum[key] += $2
}
END {
for (k in sum) {
print k "," sum[k]
}
}' /proc/vmallocinfo
}
parse_vmalloc > "$TMP_BEFORE"
./amx_64 --exec-test $NUM_ITERATION
parse_vmalloc > "$TMP_AFTER"
# Join both files on the caller name and compute the differences
LEAKED=$(awk -F, '
NR == FNR {
before[$1] = $2
next
}
{
after[$1] = $2
diff = $2 - before[$1]
if ($1 ~ /__xfd_enable_feature/ && diff > 1024*4*3*$NUM_ITERATION) {
found=1
#print "%-40s %+15d\n", $1, diff
}
delete before[$1] # Mark as processed
} END {
print found+0
}' "$TMP_BEFORE" "$TMP_AFTER")
if [ "$LEAKED" == "1" ]; then
echo "[FAIL] memory leak"
else
echo "[OK] no memory leak"
fi
rm -f "$TMP_BEFORE" "$TMP_AFTER"
[-- Attachment #3: temp.diff --]
[-- Type: text/x-patch, Size: 1890 bytes --]
diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index 40769c16de1b..58bbeac3a023 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -5,6 +5,7 @@
#include <errno.h>
#include <setjmp.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
@@ -30,6 +31,9 @@
#define XFEATURE_MASK_XTILEDATA (1 << XFEATURE_XTILEDATA)
#define XFEATURE_MASK_XTILE (XFEATURE_MASK_XTILECFG | XFEATURE_MASK_XTILEDATA)
+#define EXEC_TEST_ARG "--exec-test"
+#define EXEC_TEST_CHILD_ARG "--exec-test-child"
+
struct xstate_info xtiledata;
/* The helpers for managing XSAVE buffer and tile states: */
@@ -478,11 +482,44 @@ static void test_fork(void)
_exit(0);
}
-int main(void)
+static int test_exec(int argc, char **argv)
+{
+ int i, times = atoi(argv[2]);
+
+ req_xtiledata_perm();
+
+ for (i = 0; i < times; i++) {
+ pid_t child;
+ int status;
+
+ child = fork();
+ if (child < 0)
+ fatal_error("fork");
+ if (!child) {
+ char *args[] = {argv[0], EXEC_TEST_CHILD_ARG, NULL};
+
+ if (!load_rand_tiledata(stashed_xsave))
+ fatal_error("failed to load tiledata");
+
+ execv(args[0], args);
+ fatal_error("exec");
+ }
+
+ if (waitpid(child, &status, 0) != child)
+ fatal_error("waitpid");
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
{
unsigned long features;
long rc;
+ if (argc == 2 && !strcmp(argv[1], EXEC_TEST_CHILD_ARG))
+ return 0;
+
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
ksft_print_msg("no AMX support\n");
@@ -496,6 +533,10 @@ int main(void)
}
init_stashed_xsave();
+
+ if (argc == 3 && !strcmp(argv[1], EXEC_TEST_ARG))
+ return test_exec(argc, argv);
+
sethandler(SIGILL, handle_noperm, 0);
test_dynamic_state();
next prev parent reply other threads:[~2026-11-06 16:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 10:08 [PATCH v4 0/2] x86/fpu: Fix dynamic fpstate leak on exec() Guixiong Wei
2026-11-02 10:10 ` [PATCH v4 1/2] x86/fpu: Fix memory leak with dynamic fpstate and exec() Guixiong Wei
2026-11-02 10:32 ` Guixiong Wei
2026-11-02 10:30 ` [PATCH v4 2/2] selftests/x86/amx: Test dynamic fpstate cleanup across exec() Guixiong Wei
2026-11-06 16:40 ` Chang S. Bae [this message]
2026-11-08 13:19 ` Guixiong Wei
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=ab483f3d-e036-452e-bf58-6c87e59ae3bb@intel.com \
--to=chang.seok.bae@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=weiguixiong@bytedance.com \
--cc=x86@kernel.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.