From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1B3C472521 for ; Wed, 16 Sep 2026 23:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789601003; cv=none; b=tsbMy2JwpU4/U6Ce0tV5JYuebigqRDKUfsQoaaXWf5IufOC1GKjxMlA44aeB5QnrJEklRIbfp3AJc285OxvCfPYImF1sR/CAuFEvnJiHS5jjREO/rcPV6CBXGNgNDkKr6KkOcb+X3qez8NoDi7+uUqHaVsptdMQbQo54vldgiG4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789601003; c=relaxed/simple; bh=4UixqbcbSfOrTAup4aEOXt8/JXKgEGIcTBf3BEhG1p0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Jf9be+rhaooO8EmF3ijVhtLiipxu64Tv5OImz241PltSQM59q7P9tB3nTc16AsHTlzGcjq8ipgT0LXm5JO0YEA+CovOyRKjkaWq37sIpf1E+lbHX9Xa2GDSTbRSKfff8J1hVlFEycR8GPLKOoxbHz9zfwMqCb9k14k5kwsquM4A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BPJlh6xe; arc=none smtp.client-ip=209.85.167.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--avagin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BPJlh6xe" Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-4b28db3a47aso382254b6e.2 for ; Wed, 16 Sep 2026 16:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789601000; x=1790205800; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SvbJdnrVvb+cd4Qa4kJl3M9EGMjCcAwlbnHa1T82/fI=; b=BPJlh6xevAXBn+VZIrQyRdcjRTup7TZSH3XKbwT9teNzKGgZo0M+y+hX3gIVe1oD9i HbJBguIKvRmS9vfBKxGq9pBqmqVEGSBddlddprSuwd4aAxwTaJDJTuieZ9l8XIaaLeQz wv7Nk85gafMl4wZdgguJ+bTTPS3TGHcwfKx7eA8go9ZQadA4/i4m13TUGcHq4yhAcLyp UGP7vNQYHPeQHi8s0KOBDWMJaBvUiB5I1VSokRspj6s5srQ2z1oY5+/I2JGRPHMEI0Cn n7ILVfVdwIOjEXK5DoQDJtrns2Q+0zTE3rQYVgvXTxw247LuX7n+w386ShHQBxRIOjGc yYNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789601000; x=1790205800; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SvbJdnrVvb+cd4Qa4kJl3M9EGMjCcAwlbnHa1T82/fI=; b=DGcGDtYo7FJF4Ft/OUz/HPreTP+bHVoH08rT95V7xIzFhwnpTo/VoMCJLYyug22kke Ze2JzSO35bCiJhqdW/0Kat0wkA2vkV6OHgAj9hBKxr/qZyaAIDETfrps2wfNaX4gdCRX 1XzjQaxA5Y568WwhV8YJIyabV9cvnW5U8FKGynkYv5/zALnrLtFP8fbYq8xqUMjbp1wO awOtbFULvMrIMZVx928/qvZy4Rpnu0M6+PXAjjfXIdi8rUygd4jDaA7CGDr+xew1E4CU mjORF7v1x3xXFqSnURYMC0bkb8wuCtBjF+eSpq6yUfhb21XPcF3+8PqnUuREawEENusf gJJg== X-Forwarded-Encrypted: i=1; AKwUvBwa6/ZT2EGkBD4Ec5tF/1mfOh0zFnFHPdYyUGbS6phYnSLO8pExNRob2RoVYFM8xZREfmeq@lists.linux.dev X-Gm-Message-State: AFuF++l31KI+si6Jcu5FmF+GNBzu8+avw601c2+hV9Qam5eUljjJkrh2 aca0WL5PC4jz+7ZE0HVLBl2CG2T2YTUIPPK43fN9xapWFTFYfqAVWnOLh5wDwTA2ps6TcERCBLm rVDXDqg== X-Received: from iovb21.prod.google.com ([2002:a05:6602:2495:b0:9ab:11c4:e042]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:152a:b0:4b3:7a14:6b25 with SMTP id 5614622812f47-4ca4d20d961mr8897025b6e.14.1789601000269; Wed, 16 Sep 2026 16:23:20 -0700 (PDT) Date: Wed, 16 Sep 2026 23:23:03 +0000 Precedence: bulk X-Mailing-List: criu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.1082.g2b9226bbc0-goog Message-ID: <20260916232310.490786-1-avagin@google.com> Subject: [PATCH v6 0/7] x86/fpu: Restore and reinforce signal frame portability From: Andrei Vagin To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Chang S. Bae" Cc: linux-kernel@vger.kernel.org, criu@lists.linux.dev, Dave Hansen , x86@kernel.org, Andrei Vagin , Alexander Mikhalitsyn , "H. Peter Anvin" Content-Type: text/plain; charset="UTF-8" The x86 signal frame is designed to be self-describing. The xstate_size field in the software-reserved bytes indicates the actual size of the xstate context and is used by the kernel to locate the FP_XSTATE_MAGIC2 marker during signal return. This design is required to provide portability of signal frames across different machines. For example, a process checkpointed on a system with fewer xstate features and restored on a system with more features will have a signal frame on its stack that is smaller than the destination host's default. By relying on the frame's internal xstate_size, the kernel can correctly validate and restore such frames. This series restores and improves signal frame portability. The goal is to allow process migration across CPUs with heterogeneous FPU capabilities, as long as the process only uses features supported by both systems. This version addresses the original issues by pre-faulting only the required size of the xstate buffer (rather than the default task size), and includes cleanups requested by Ingo Molnar. v6: - Clarify struct _fpstate_32 layout and reformat documentation per Borislav comments. - Add Reviewed-by tags from Chang S. Bae. v5: Address Chang's comments: - Documentation: - Expanded Documentation/arch/x86/xstate.rst with a dedicated section describing struct _fpx_sw_bytes, 32-bit vs 64-bit frame layout differences, and architectural portability constraints. - Trimmed the comment in and added a reference to xstate.rst. - x86/fpu core: - Renamed the 32-bit helper to restore_from_ia32_fxstate() and inlined the remaining native path directly into fpu__restore_sig(). - Selftests: - Consolidated the shrunk-frame and insufficient-size test cases. v4: - Update documentation to describe architectural XSAVE layout constraints and feature repurposing (e.g. MPX vs APX). - The patch "x86/fpu: Allow restoring signal frames with larger xstate_size" will be sent in a separate series. - Address sashiko comments. v3: - Include cleanups and refactoring of signal frame handling code as requested by Ingo Molnar. - Fix potential underflow in xstate_calculate_size() v2: - Address sashiko comments. - 44eeff9bc467 ("Revert "x86/fpu: Refine and simplify the magic number check during signal return"") has been merged. Cc: Alexander Mikhalitsyn Cc: Borislav Petkov Cc: "Chang S. Bae" Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Thomas Gleixner Andrei Vagin (7): x86/fpu: Document signal frame layout and portability x86/fpu: Clean up and rename variables in signal frame handling x86/fpu: Extract restore_from_ia32_fxstate() and clean up fpu__restore_sig() x86/fpu: Document reasoning of FX-only fallback x86/fpu: Fix potential underflow in xstate_calculate_size() x86/fpu: Pre-fault only required size of xstate buffer selftests/x86: Add tests for signal frame FPU portability Documentation/arch/x86/xstate.rst | 57 +++++ arch/x86/include/uapi/asm/sigcontext.h | 15 ++ arch/x86/kernel/fpu/signal.c | 134 +++++++---- arch/x86/kernel/fpu/xstate.c | 9 +- arch/x86/kernel/fpu/xstate.h | 2 + tools/testing/selftests/x86/Makefile | 5 +- .../selftests/x86/sigframe_fpu_portability.c | 245 +++++++++++++++++++++ tools/testing/selftests/x86/xstate.c | 12 - tools/testing/selftests/x86/xstate.h | 20 ++ 9 files changed, 437 insertions(+), 62 deletions(-) create mode 100644 tools/testing/selftests/x86/sigframe_fpu_portability.c -- 2.55.0.979.g7e5102b832-goog