From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (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 6312F3859F3 for ; Mon, 15 Jun 2026 19:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552244; cv=none; b=JIwi0n0acgxlYRLny5wBVAkHHGU2YzhZE5D2Xw5sozKnY9Rwo54ObgLQjB+ZZowA9j4ZdhCLa58RDOMcC0Ny51Ktqcftgi4QFaanbw7yyUcn/IzN3plhT7BP7db9PweKghs1Lz0cA1D0/cg4sdwCMzqCkl3IS2ejmPExV40T6YA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781552244; c=relaxed/simple; bh=0Uh32Z84jAaWUbe/B7iFkDeUA0emys6kQtli/o7N2wY=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=u7n0DnfrIuuv8sh5QKuiAE0BFmG+GohK6TLoDC4sH82atdFt/CuPWg8t5Y31Aj886rHj/ARD6+ixVWuc+KdEJ0coMuNCp9SAVCnVzLwY3f98TjUtOTl+0CwsJZEXVfNpE9TlPTAak7/M4Qvuzsvzu4VqIzLVRtnZQ4rtatVC/jw= 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=ePVn7bPt; arc=none smtp.client-ip=209.85.160.74 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="ePVn7bPt" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-440f84a2f62so5214013fac.3 for ; Mon, 15 Jun 2026 12:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781552242; x=1782157042; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=IAufCONdB4S418e+Qv1fSYNL826oe/BmVRUV+6GzhF8=; b=ePVn7bPtstB8S/kL0XxGsfoAgrKgDpGMjHEH4M2P7PUx4Itu5ttu2hZKWqo/erynWq 1CLXCAcviGWQKX5XxGxXbo5kMqoyFIU5dksytJLlKE6B1ftCtTJ1DKuEZwci49135zIj ZMw86rBYJZq9tXUM8y5LNb9Dm4bsjJEKzG5c0cIp1MbNqD89uNo06YxYRdw2VIDEGarN M7OeEP7hyc2Rrpj5Y4fwRNz+6vFIuFCnMNa+BS9Atzv2s9TEutRBnyMYDnrdKiX4y60B Vi2xgKsUhNPPDUJsrJUUj/EvCtDwf9WtQRQ0cr1Z2H2B93hpKHs7rFZ3QGYvQeabyYMo GsTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781552242; x=1782157042; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IAufCONdB4S418e+Qv1fSYNL826oe/BmVRUV+6GzhF8=; b=L5vFrOsJ++2kWB3OuYsb18Z+rZr1Gaa/H5AS8xf+z8kWIYbCBaoEfZTX4fvM0qxrOd CaymlzIDoVnxjUMFVH9GHErCw3+gmJQs9wpnk5kKt5CJLx7mNVWS/r6PmkI0b/6KXkpc kVdYo4bHotguzFQtO2UQm1ck517ECXI1dEFXwtufr0qoa+oHP9td9D1UnXjr5W2ByDjH oSuZfIZiGO+J69wFIXop2RkbMY6p9EuXdjCiC2g/FsvWAR+3tVnKyWefSO7mYg+1sfrZ iIdoK23p8g7eNHU9o53NeJ6MVLJAMIJtvF47zP8DNaLsT0WND4QN9vaEraC/ZZrWJQv9 oL6w== X-Gm-Message-State: AOJu0Yyemc0SRCmde4MLQkLgKm+1sM9ckkeiHL2SLm8li9Z5liOmkObs Z9ZC/rGlIi86+YQe2XreOKI82Z2eCyi3zjPWwkHyuqdJ8AaPJjsNMBeL/6n84u8994kIJ6c6JUG wDoj0FA== X-Received: from iobp3-n2.prod.google.com ([2002:a05:6602:8683:20b0:96a:7dac:9ef2]) (user=avagin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:80c5:b0:69e:8afe:e994 with SMTP id 006d021491bc7-69edc6ea0e8mr9569363eaf.32.1781552241953; Mon, 15 Jun 2026 12:37:21 -0700 (PDT) Date: Mon, 15 Jun 2026 19:37:06 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.1189.g8c84645362-goog Message-ID: <20260615193716.1843340-1-avagin@google.com> Subject: [PATCH v3 0/10] 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 , "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. 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: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: "Chang S. Bae" Andrei Vagin (10): x86/fpu: Document signal frame portability x86/fpu: Clean up and rename variables in signal frame handling x86/fpu: Split __fpu_restore_sig to extract compat path x86/fpu: Document reasoning of FX-only fallback x86/fpu: Fix potential underflow in xstate_calculate_size() selftests/x86: Add a test for signal frame FPU portability x86/fpu: Pre-fault only required size of xstate buffer selftests/x86: Add a sigframe insufficient xstate_size test x86/fpu: Allow restoring signal frames with larger xstate_size selftests/x86: Check restoring FPU state with larger xstate_size Documentation/arch/x86/xstate.rst | 13 + arch/x86/include/uapi/asm/sigcontext.h | 13 + arch/x86/kernel/fpu/signal.c | 141 +++++-- 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 | 345 ++++++++++++++++++ tools/testing/selftests/x86/xstate.c | 5 - tools/testing/selftests/x86/xstate.h | 12 + 9 files changed, 497 insertions(+), 48 deletions(-) create mode 100644 tools/testing/selftests/x86/sigframe_fpu_portability.c -- 2.54.0.1189.g8c84645362-goog