[PATCH 3/6] selftests/x86/xstate: Validate XSTATE_BV in ptrace test

From: Chang S. Bae

Date: Mon Nov 09 2026 - 22:44:13 EST


The ptrace test does not currently validate XSTATE_BV in the XSAVE
header. Add a check for it.

The component bit may legitimately be clear when testing a reset state.
So, ensure the expected bit setting first and then compare the component
bit directly.

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

diff --git a/tools/testing/selftests/x86/xstate.c b/tools/testing/selftests/x86/xstate.c
index 240567e79e96..93ba4b5f1a08 100644
--- a/tools/testing/selftests/x86/xstate.c
+++ b/tools/testing/selftests/x86/xstate.c
@@ -62,6 +62,7 @@ static inline void load_init_xstate(struct xstate_info *xstate, struct xsave_buf

static inline void copy_xstate(struct xsave_buffer *xbuf_dst, struct xsave_buffer *xbuf_src)
{
+ memcpy(xbuf_dst->header, xbuf_src->header, XSAVE_HDR_SIZE);
memcpy(&xbuf_dst->bytes[xstate.xbuf_offset],
&xbuf_src->bytes[xstate.xbuf_offset],
xstate.size);
@@ -277,6 +278,13 @@ static bool validate_ptracer_xstate(pid_t target, struct iovec iov,
failed++;
}

+ if ((xstate.mask & get_xstatebv(xbuf)) == (xstate.mask & get_xstatebv(expected))) {
+ printf("#\tok\tXSTATE_BV\n");
+ } else {
+ printf("#\tnot ok\tXSTATE_BV\n");
+ failed++;
+ }
+
if (validate_xstate_same(xbuf, expected)) {
printf("#\tok\txstate area\n");
} else {
--
2.53.0