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>, Shuah Khan <shuah@kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] selftests/x86/amx: Test dynamic fpstate cleanup across exec()
Date: Wed, 14 Oct 2026 17:19:16 -0700 [thread overview]
Message-ID: <1c19df7c-76b2-4dd3-b280-d6ab8bb45d4e@intel.com> (raw)
In-Reply-To: <11ea12962bda75b3e8ef845084546647f79eca38.1791428412.git.weiguixiong@bytedance.com>
On 10/7/2026 10:59 PM, Guixiong Wei wrote:
>
> -int main(void)
> +static int count_dynamic_fpstates(void)
> +{
> + char *line = NULL;
> + size_t line_size = 0;
> + FILE *fp;
> + int count = 0;
> +
> + fp = fopen("/proc/vmallocinfo", "r");
> + if (!fp)
> + return -errno;
The call site doesn't interprete the error code. Instead, you can simply
call fatal_error() here and below on an IO error.
> +
> + while (getline(&line, &line_size, fp) >= 0) {
> + if (strstr(line, "__xfd_enable_feature") ||
> + strstr(line, "fpstate_realloc"))
> + count++;
> + }
> +
> + if (ferror(fp))
> + count = -EIO;
> +
> + free(line);
> + fclose(fp);
> + return count;
> +}
> +static void test_exec(void)
> +{
> + char iterations_arg[16];
> + char baseline_arg[16];
> + int before, after, delta;
> + pid_t child;
> + int status;
> +
> + printf("[RUN]\tCheck dynamic fpstate cleanup across exec().\n");
> +
> + before = count_dynamic_fpstates();
> + if (before < 0) {
> + printf("[SKIP]\tCannot read /proc/vmallocinfo: %s\n",
> + strerror(-before));
> + return;
> + }
> +
> + child = fork();
> + if (child < 0)
> + fatal_error("fork");
> + if (!child) {
> + snprintf(iterations_arg, sizeof(iterations_arg), "%d",
> + EXEC_TEST_ITERS);
> + snprintf(baseline_arg, sizeof(baseline_arg), "%d", before);
> + execl("/proc/self/exe", "amx", EXEC_TEST_ARG, iterations_arg,
> + baseline_arg, NULL);
> + fatal_error("exec");
> + }
This nested exec() with passing numbers via arguments looks more
complicate than necessary.
Instead, you could put the fork()/exec() sequence in a loop. Before each
exec(), call load_rand_tiledata(), and adjust main() to return
immediately from the exec test. I found this also reproduces the
increase in /proc/vmallocinfo.
> +
> + if (waitpid(child, &status, 0) != child)
> + fatal_error("waitpid");
> + if (WIFEXITED(status) && WEXITSTATUS(status) == KSFT_SKIP) {
> + printf("[SKIP]\tDynamic fpstate allocation was not isolated.\n");
> + return;
> + }
> + if (!WIFEXITED(status) || WEXITSTATUS(status))
> + fatal_error("exec test child");
> +
> + after = count_dynamic_fpstates();
> + if (after < 0) {
> + printf("[SKIP]\tCannot read /proc/vmallocinfo after exec(): %s\n",
> + strerror(-after));
> + return;
> + }
> +
> + delta = after - before;
> + if (!delta) {
> + printf("[OK]\tDynamic fpstate allocations were freed across exec().\n");
> + return;
> + }
> +
> + if (delta == EXEC_TEST_ITERS)
> + errx(1, "[FAIL]\texec() leaked %d dynamic fpstate allocations",
> + delta);
errx() terminates the entire test, preventing subsequent tests from
running. Unless this failure makes it unsafe or meaningless to continue,
why not report the failure with printf() and let the remaining tests run?
> +
> + printf("[SKIP]\tDynamic fpstate vmalloc usage changed concurrently.\n");
> +}
Thanks,
Chang
prev parent reply other threads:[~2026-10-15 0:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 5:59 [PATCH v2 0/2] x86/fpu: Fix dynamic fpstate leak on exec() Guixiong Wei
2026-10-08 5:59 ` [PATCH v2 2/2] selftests/x86/amx: Test dynamic fpstate cleanup across exec() Guixiong Wei
2026-10-15 0:19 ` Chang S. Bae [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=1c19df7c-76b2-4dd3-b280-d6ab8bb45d4e@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.