From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (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 C71554CC604 for ; Thu, 24 Sep 2026 21:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790283690; cv=none; b=nvBIS5NlIX9j4Jk1hgj96H4suSDX8Sy5yX1s3tZwByl9fpJ4yF5/BbpdvdTKqrqg70V6hz6oCUoWK5yiWz35Q6OsoVxQIfSXsPk2V5PY1dW62yfcfffQeFPGUz10ceYjS26lWaufaHiZ2v0svH3JMLJiBkPROElHUt73SadAATk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790283690; c=relaxed/simple; bh=+akfvf/2L6+wROOVIeYyALD35Eq+t0R3V1wVbYA7uAQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=R/DRtVj2neQfZtXlxqAKJNRUsdGF2rOfxq/TJGAQjThS3GvP0j4a8+KF0GH7ptSBZA/HecaDr/osazglZU8vkfJW6J7R7NXZB0R+ehY6u5CUlWuxxEGDqCxav5+2MCSwHRZns9n+6mLkTO+3y77Q2uF1quyl2nGuiRuSLfYqyfQ= 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=GTpBad3e; arc=none smtp.client-ip=209.85.167.199 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="GTpBad3e" Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-4a7de733fa9so579887b6e.3 for ; Thu, 24 Sep 2026 14:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790283684; x=1790888484; 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=gm00+Wasm053LlmEKI95Bv/4aOHMNCH9NV7fJ5dy5wc=; b=GTpBad3eyTUTp58LBkE8wf3iJ38ZjIBEIYOOC26ugC1g3GWksXPnSwrYmiSfgaatX2 zjmxPvjj5b9MTw3OwdOS1q5u95u+DVrzjjcoKtpwsTNDHfhsHL6MnTu1w2BMkI01AnfU K+BZt6Meju6fzjR/Eklmgem/aLK8edN1Edmn12HDZd2qoXFYdTdUxmLiaSzDxwMKx5ky yJU/GEoDa9Ttkq5CzL62zbze6yTz4t4hKjzUUPU1v8siTakYBK6Vja49kwVCTZIMoUT4 maGnfdH76jg9O8XovQkzh+eULXIvFHCFXetlauamtYDKVK9MXZkaZ7V5dGKBsP540m3s U4zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790283684; x=1790888484; 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=gm00+Wasm053LlmEKI95Bv/4aOHMNCH9NV7fJ5dy5wc=; b=yDxANLeOOrL7Odn+4TM6MlNxl1h/6cFhMvhN0lLY8kpNtrBPo3C0/fEWM8UotzXoJJ 9vge7q3H71du6YnRXTG/adRbUjUbIvpmGCRLVN1XZ2QeO9Q616iZbkvSkWNI9cXKyWaO 5/rQLk9iMBpfn7dLR1jb1JKxqhtDUrbNIiJTFd0s1Bjvj7ajQs0f8N69sq+Mzaph/mAL 7THJ87uA3jv05fCYSkq1wt7rWilUYkVUCnLQmx5VqqLjY4EC88yafJ9snHUmemYx+J5V 7zCjIjhAOPljvZsym7MLM2zEcwmzKAFvf3RUeLeMHVAQ13CCpwPM2e/U34005r/Lihd2 ReXA== X-Forwarded-Encrypted: i=1; AKwUvBxfcJgS56Z20fRmOyo4XDirbal53+GSKtC44phX2CpwMvvgFvzBUjch9rmrmtI16vtYxDgj@lists.linux.dev X-Gm-Message-State: AFuF++mFYpC1MafnnwPissJy5qekUuXvP2jBPJrSE/4TYIyfmoD+7mui 9graG16qa5MqUFS4UXm4/X3rXIxtUqH2ZUQYd4nMv9jUmvhDCcaiLqwn5XqEjl4PpNnKFo39kaa iFs/AyQ== X-Received: from iofh3.prod.google.com ([2002:a05:6602:6fc3:b0:9c4:a4f8:640]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1a06:b0:4b9:a829:f010 with SMTP id 5614622812f47-4d72cb3e29fmr3569902b6e.28.1790283684138; Thu, 24 Sep 2026 14:01:24 -0700 (PDT) Date: Thu, 24 Sep 2026 21:01:14 +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.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20260924210121.87032-1-avagin@google.com> Subject: [PATCH v8 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. v8: Address Sashiko's comments: - Combine %ymm0 load/store and syscall into a single inline assembly block. v7: Address Borislav's comments: - Replace #ifdefs and stub for restore_from_ia32_fxstate() with an early return using IS_ENABLED(). - Use reverse fir tree variable declaration ordering in check_xstate_in_sigframe(). 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 | 54 +++++ arch/x86/include/uapi/asm/sigcontext.h | 15 ++ arch/x86/kernel/fpu/signal.c | 127 +++++++---- arch/x86/kernel/fpu/xstate.c | 7 +- arch/x86/kernel/fpu/xstate.h | 2 + tools/testing/selftests/x86/Makefile | 5 +- .../selftests/x86/sigframe_fpu_portability.c | 235 +++++++++++++++++++++ tools/testing/selftests/x86/xstate.c | 12 -- tools/testing/selftests/x86/xstate.h | 20 ++ 9 files changed, 417 insertions(+), 60 deletions(-) create mode 100644 tools/testing/selftests/x86/sigframe_fpu_portability.c -- 2.55.0.979.g7e5102b832-goog