mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: x86@kernel.org, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, shuah@kernel.org,
	chang.seok.bae@intel.com
Subject: [PATCH 2/6] selftests/x86/xstate: Pre-allocate ptracee XSAVE buffer
Date: Tue, 10 Nov 2026 03:15:59 +0000	[thread overview]
Message-ID: <20261110031603.698635-3-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20261110031603.698635-1-chang.seok.bae@intel.com>

Currently, the ptrace test does not handle XSAVE buffer allocation
failures in the child process. But such a failure can lead to an
unexpected exit path, complicating error handling.

Instead, allocate the buffer in the parent process so that
allocation and error handling are handled before forking the child.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
---
 tools/testing/selftests/x86/xstate.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/x86/xstate.c b/tools/testing/selftests/x86/xstate.c
index c26dbe33622f..240567e79e96 100644
--- a/tools/testing/selftests/x86/xstate.c
+++ b/tools/testing/selftests/x86/xstate.c
@@ -236,6 +236,8 @@ static void test_context_switch(void)
 	free(finfo);
 }
 
+static struct xsave_buffer *stashed_xbuf;
+
 /*
  * Ptrace test for the ABI format as described in arch/x86/include/asm/user.h
  */
@@ -247,14 +249,8 @@ static void test_context_switch(void)
  */
 static inline void ptracee_touch_xstate(void)
 {
-	struct xsave_buffer *xbuf;
-
-	xbuf = alloc_xbuf();
-
-	load_rand_xstate(&xstate, xbuf);
-	load_init_xstate(&xstate, xbuf);
-
-	free(xbuf);
+	load_rand_xstate(&xstate, stashed_xbuf);
+	load_init_xstate(&xstate, stashed_xbuf);
 }
 
 static bool validate_ptracer_xstate(pid_t target, struct iovec iov,
@@ -335,6 +331,10 @@ static void test_ptrace(void)
 	pid_t child;
 	int status;
 
+	stashed_xbuf = alloc_xbuf();
+	if (!stashed_xbuf)
+		ksft_exit_fail_msg("unable to allocate XSAVE buffer\n");
+
 	child = fork();
 	if (child < 0) {
 		ksft_exit_fail_msg("fork() failed\n");
@@ -358,6 +358,8 @@ static void test_ptrace(void)
 	wait(&status);
 	if (!WIFEXITED(status) || WEXITSTATUS(status))
 		ksft_exit_fail_msg("ptracee exit error\n");
+
+	free(stashed_xbuf);
 }
 
 /*
@@ -391,8 +393,6 @@ static inline void sig_print_fail(char *msg)
 	sig_print(msg);
 }
 
-static struct xsave_buffer *stashed_xbuf;
-
 static void validate_sigfpstate(int sig, siginfo_t *si, void *ctx_void)
 {
 	ucontext_t *ctx = (ucontext_t *)ctx_void;
-- 
2.53.0


  parent reply	other threads:[~2026-11-10  3:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  3:15 [PATCH 0/6] selftests/x86/xstate: more test cases for coredump and ptrace Chang S. Bae
2026-11-10  3:15 ` [PATCH 1/6] selftests/x86/xstate: Track testing status by kselftest API Chang S. Bae
2026-11-10  3:15 ` Chang S. Bae [this message]
2026-11-10  3:16 ` [PATCH 3/6] selftests/x86/xstate: Validate XSTATE_BV in ptrace test Chang S. Bae
2026-11-10  3:16 ` [PATCH 4/6] selftests/x86/xstate: Validate state reset " Chang S. Bae
2026-11-10  3:16 ` [PATCH 5/6] selftests/x86/xstate: Add coredump test Chang S. Bae
2026-11-10  3:16 ` [PATCH 6/6] selftests/mm: Add coredump test for x86 Chang S. Bae

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=20261110031603.698635-3-chang.seok.bae@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®