Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp916131lqh; Fri, 29 Mar 2024 00:30:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXR768Mv2TUalEnBuj9paUB7hHkAplbV4jTVKRSJ2wdZNylL0+pQQ+5In0bK+Z1H4XrNvCIyOuIPcylSPzXdllvOG7WzUZTHKYr8NACYw== X-Google-Smtp-Source: AGHT+IFNYHOTotp5FT5N4yITrUAbqjDs60bPCI2BFIO3G4fZSL9VjJbc8W2+z6Jnu05lH/wdoDS+ X-Received: by 2002:a17:90a:d310:b0:2a1:fc53:e016 with SMTP id p16-20020a17090ad31000b002a1fc53e016mr1504199pju.7.1711697432135; Fri, 29 Mar 2024 00:30:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711697432; cv=pass; d=google.com; s=arc-20160816; b=nnKzp4oD1+p7Omzppqk6lMu2yXrAGTvZ5D6smXGkHls58lITwxzY0Do4Iavc50Ke3I v5NEBi33NDw5+n3k43zongB+5TYRSI725E/qF9OjelAP56BjgdLiRJb4t6PXSBUC8ZJs 7VEVp/7VFw6innxE33QDe9N/5aFucX8AKJ7S72blzxgABQnPM2jRowb8+66x7DQuYssX IQZ+jtB22ITWXgvZDeHG/QfbAyZshJADn/0McZvvuQqeHd2Gi4fgTMGp3oe5/DqNv1CR B/BkqQWRUnIDYB0A87H6y8oS5leXbgjmK19NMpCrP0O8gsIXL09QtBOfGLa+TRaVUVc6 ohDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1ZUya0v8Oh5iLzX7Kw5hO2ocqVWj9tNi/iu8yR8eYow=; fh=VMmPWWmAfrFhg+H1C0/kZBztsUjpAvVOhu9TBq6n2zQ=; b=gXbS1FNDZsCQOlORCIYJnN1SurbYMtSdjrg/CAOlct5KIqHMmxLdz6n13UMmZhMmLf VJId/MTRqUgN/iL0HPaKe0Z8gASxGAOhQjjq95OtDlVAe3jm40n/4EzN7lUIqK25S12w gtBIbbQRT66QJbJT2OWyhXl68/Or7vl/gZcONIAJ/MVW76zRcRK+mUsaVrc8oMBMiRuN p8JyrdhHrDkfSo05zYhWlOoMWjEXHuqIU0mqb0m2zClQQ1TSuGSxBBzSyx5JMSvTATHD bdAl3UvAHyWL8GMt2EnTFTrF4bo1iMudPlYCNbVsaBMH6SqANZXyx5HfzGDpWt+zxp1E oIbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=kRKoUdUb; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-124237-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124237-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a2-20020a17090a8c0200b002a2000fbad8si2999673pjo.190.2024.03.29.00.30.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 00:30:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124237-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=kRKoUdUb; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-124237-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124237-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A47C4B23A47 for ; Fri, 29 Mar 2024 07:27:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 760355466C; Fri, 29 Mar 2024 07:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="kRKoUdUb" Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 1B4CA52F61 for ; Fri, 29 Mar 2024 07:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711697103; cv=none; b=GW1d7yhbaAI4ILiLuVK3o4i0PGfUnfHm3hhX57eD90ADxPQrbvQqBIUPvgjj3DtDPUJANnAQG6KyK7QdsD3I1ts2r44MsPMCq9wwC+04KunXslKngsNQOMlz0Zf4Rr9pNCjaJSTrZ7UoQLWBq5lANdRHnzTvkTmPx3i6C3yDAUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711697103; c=relaxed/simple; bh=3Jxdlw0MxGrCtqcQU2OdpgNfa0UAfuPKsYPLtYGhH+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d2AbGy3HdPb/TQdg/NqyZcqt/7RIVMKWKJYB7FOEotx1YNDDGgO1Yh884fn/kFc8GDQ4mxH2nx97HJ1S5n4FbaysjYe1MV3h2f1kSAhQ3nX7yXeRUB2YlDNN2hPz3vgGy7mcS+PLW1Xz8HZ2HjY+caYLOeoaTh5LFITekZPKvOw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=kRKoUdUb; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-29c75e348afso1379347a91.2 for ; Fri, 29 Mar 2024 00:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711697101; x=1712301901; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1ZUya0v8Oh5iLzX7Kw5hO2ocqVWj9tNi/iu8yR8eYow=; b=kRKoUdUb5DKxUUPJAvbU2/4hQ+E/oXSY0LBXlgydG8sxeauznurMwd1pglgfOv2qLt 5yf/dkmCvaDbG7KD8WCrOlK36TSxx1gxWAwPo/+Dg5GYKvagT03vY0zYsbf+Qe2/fUQR a7YtQ/wjEizRohXrTGipik8PM2A845dP//p4whryxZtt/QjlMZbBuX36uSwDIRRVQvzz +e4e4kVFuQVbdBFMnWE8zKwIWFvepXDxwsB0fq8Y+YYlXpquH2LevRpeOVLL1nEhPG/W sI8AToK7DW+eUIkRQXLxgCDLBwEj/2lQkEqHtU/oV8qxFhtO5e1NXyEE06o8kcx7Ws8V JzNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711697101; x=1712301901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1ZUya0v8Oh5iLzX7Kw5hO2ocqVWj9tNi/iu8yR8eYow=; b=KTWSWoQti67a7tdGYe/TRhnjDEUiADU4TMmoWC6Kj0be37qUlpbrWdbJG3Kz1sOW+c 8Hzkdm6LrOqEfPNnrGTL7tPRI4byrztV5sftvsfiik38dvo0LS1KNGVOTb4xJ0pYMSsR Fqis14qcOj1SlnSXhlaxFZUt79h0mk1oEOgYwkcSueagsiWMARs637Um/VlXGnkhfTmE YiYLDIPhibjqQ8cIaZP2DLBDna7kZXHgofmpNSWXq2Z1wchDIL0pSywgTRNw9GLKdBmQ tju6LBbG5s6pbtZAqCfEh8lESkMtZiufXTVruH/Wx2JE2N0gbAr0gG0cwCfJfK3aElIq hPKA== X-Gm-Message-State: AOJu0YwulNyti/aDy3Hojlkp7cG6etcWoMYvzFOdztw14LRjbpHdt2HI Fd6JndTGY/17loVzjHnETDVyEY2QdbEixG3lwE7AG/9VsjXns5lhsdBu2ER2d+Y= X-Received: by 2002:a17:90a:b008:b0:2a0:5339:7751 with SMTP id x8-20020a17090ab00800b002a053397751mr1529473pjq.37.1711697101571; Fri, 29 Mar 2024 00:25:01 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id b8-20020a17090a010800b0029ddac03effsm4971798pjb.11.2024.03.29.00.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 00:25:01 -0700 (PDT) From: Samuel Holland To: Andrew Morton , linux-arm-kernel@lists.infradead.org, x86@kernel.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, Christoph Hellwig , loongarch@lists.linux.dev, amd-gfx@lists.freedesktop.org, Samuel Holland , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner Subject: [PATCH v4 10/15] x86: Implement ARCH_HAS_KERNEL_FPU_SUPPORT Date: Fri, 29 Mar 2024 00:18:25 -0700 Message-ID: <20240329072441.591471-11-samuel.holland@sifive.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240329072441.591471-1-samuel.holland@sifive.com> References: <20240329072441.591471-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit x86 already provides kernel_fpu_begin() and kernel_fpu_end(), but in a different header. Add a wrapper header, and export the CFLAGS adjustments as found in lib/Makefile. Reviewed-by: Christoph Hellwig Signed-off-by: Samuel Holland --- (no changes since v1) arch/x86/Kconfig | 1 + arch/x86/Makefile | 20 ++++++++++++++++++++ arch/x86/include/asm/fpu.h | 13 +++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 arch/x86/include/asm/fpu.h diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 39886bab943a..7c9d032ee675 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -83,6 +83,7 @@ config X86 select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_KCOV if X86_64 + select ARCH_HAS_KERNEL_FPU_SUPPORT select ARCH_HAS_MEM_ENCRYPT select ARCH_HAS_MEMBARRIER_SYNC_CORE select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 662d9d4033e6..5a5f5999c505 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -74,6 +74,26 @@ KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx KBUILD_RUSTFLAGS += --target=$(objtree)/scripts/target.json KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2 +# +# CFLAGS for compiling floating point code inside the kernel. +# +CC_FLAGS_FPU := -msse -msse2 +ifdef CONFIG_CC_IS_GCC +# Stack alignment mismatch, proceed with caution. +# GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3 +# (8B stack alignment). +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383 +# +# The "-msse" in the first argument is there so that the +# -mpreferred-stack-boundary=3 build error: +# +# -mpreferred-stack-boundary=3 is not between 4 and 12 +# +# can be triggered. Otherwise gcc doesn't complain. +CC_FLAGS_FPU += -mhard-float +CC_FLAGS_FPU += $(call cc-option,-msse -mpreferred-stack-boundary=3,-mpreferred-stack-boundary=4) +endif + ifeq ($(CONFIG_X86_KERNEL_IBT),y) # # Kernel IBT has S_CET.NOTRACK_EN=0, as such the compilers must not generate diff --git a/arch/x86/include/asm/fpu.h b/arch/x86/include/asm/fpu.h new file mode 100644 index 000000000000..b2743fe19339 --- /dev/null +++ b/arch/x86/include/asm/fpu.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2023 SiFive + */ + +#ifndef _ASM_X86_FPU_H +#define _ASM_X86_FPU_H + +#include + +#define kernel_fpu_available() true + +#endif /* ! _ASM_X86_FPU_H */ -- 2.44.0