Re: [PATCH 8/8] selftests/x86: Add a sigframe insufficient xstate_size test
From: Chang S. Bae
Date: Wed Sep 02 2026 - 17:23:44 EST
On 8/16/2026 9:20 PM, Andrei Vagin wrote:
/*
- * This test verifies the FPU portability of the signal frame.
- * It verifies that the kernel correctly restores the xstate context even
- * if the frame size has been manually reduced (shrunk), as long as the
- * FP_XSTATE_MAGIC2 marker is correctly placed.
+ * This test verifies the FPU portability and consistency of the signal frame.
+ *
+ * - test_shrunk_xstate_size:
+ * Verifies that the kernel restores state from a frame with xstate_size
+ * shrunk to only include active features.
+ *
+ * - test_insufficient_xstate_size:
+ * Verifies that the kernel rejects a frame if xstate_size is too small for
+ * the features enabled in xfeatures.
*/
...
+static void handle_insufficient_xstate_size(int sig, siginfo_t *si, void *ucp)
+{
+ ucontext_t *uc = ucp;
+ void *fp = uc->uc_mcontext.fpregs;
+ struct _fpx_sw_bytes *sw;
+
+ if (!fp) {
+ sig_print("fpregs is NULL\n");
+ return;
+ }
+
+ sw = get_fpx_sw_bytes(fp);
+ if (sw->magic1 != FP_XSTATE_MAGIC1) {
+ sig_print("magic1 is not valid\n");
+ return;
+ }
+
+ /* The origin frame contains an AVX state. */
+ sw->xstate_size = XSTATE_SSE_ONLY_SIZE;
+
+ *(uint32_t *)(fp + sw->xstate_size) = FP_XSTATE_MAGIC2;
+}
I think one of the main differences between the two tests is whether
sw->xstate_size is updated with a valid value or not. If that's the essential piece to differentiate them, would it better to highlight the delta in code?
Right now, they look like two tests that validate orthogonal behaviors at glance.
Thanks,
Chang