From nobody Wed Dec 17 00:17:01 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3496C10F09 for ; Fri, 8 Dec 2023 05:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573251AbjLHFz3 (ORCPT ); Fri, 8 Dec 2023 00:55:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573221AbjLHFzI (ORCPT ); Fri, 8 Dec 2023 00:55:08 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35DF41734 for ; Thu, 7 Dec 2023 21:55:13 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d04d286bc0so13129585ad.3 for ; Thu, 07 Dec 2023 21:55:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702014912; x=1702619712; 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=wOdH6gQ2/kSr11qF6anDkZP04y2oGGJwChsMHemqfok=; b=T4LqkHlraVGMzq4C9tWiv8BniomaaUN0FsEXm/RKku0Y5B7y0fPRi1ZQycLzyVP+0T IHZ0KKRXegLktdCL8wQpOigg1hzXyG0Fz4BXDxfWLPffxhqCHZEDogY/hO8fn9bAbLb7 x8VUn4CTv6a21gYTRxMoTNw2CY7FvLNyba3L4EdLCEgxUZSRQGsnS1jKsSHvZh9OQYTG YRmz1T4U+c+XzwmhOgwFh4Io9cyrrIiEUf7TjeDEPiRsKpJ5PyQ5p8GJ1DwZwOWN8Okk PsdM4+U3fxLvx7l35UejxLDN9Xm98edMr5ZgoYi70LOXuLMtEUpdG6zNBUri8pNK+SQM iDkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702014912; x=1702619712; 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=wOdH6gQ2/kSr11qF6anDkZP04y2oGGJwChsMHemqfok=; b=wO6KAk4usKap7zcH1GI30EBEjMdsoTfvLFdcQJVNyn4QUpGr9lDkiBL8dUJ6u1m58k yY0hLr6PChM44Pwk3BEEYz/4gJfWaLnRbgnBt2EJu1X2FlBC91CO3J6HcHhB60CKL8im pXqmEWf6y7xkwSexMS0rALVawY0BgkWH1x6B7suhSVJxyCYz3mntEI3vPBEh5WY+Annd 156oS8hYcULEWXHjftS56K8db76pIZGxxKzLSlGK7sppWdlo/rwQ5CwI60VL+6kdTlXo jh15Cs58U+/aCNM3YL5WaZonQee75xfXpDpBwf9HMJ69+dfNVbjd2VsEoN517zms5KmA y/XQ== X-Gm-Message-State: AOJu0YywjgxLTUzingKrJnJfu1Ie3uLFiqVn2PX903BGsj1HhqYi0KK6 YrFZS4Ik4k4wS0RXFcGp1BFm2iIt/sz5jHgpTh0= X-Google-Smtp-Source: AGHT+IF6KW8xi8WlWkg/kkkF64YaWdAU9w8XTSDFOxfj/W9T6fcHp2B4VJ43fwnOYGHYYluHTLhnIQ== X-Received: by 2002:a17:902:64d0:b0:1d2:eea4:a7d7 with SMTP id y16-20020a17090264d000b001d2eea4a7d7mr180399pli.5.1702014912711; Thu, 07 Dec 2023 21:55:12 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id s22-20020a170902989600b001ce5b859a59sm786250plp.305.2023.12.07.21.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 21:55:12 -0800 (PST) From: Samuel Holland To: linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-riscv@lists.infradead.org, Christoph Hellwig Cc: linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arch@vger.kernel.org, Samuel Holland Subject: [RFC PATCH 08/12] x86: Implement ARCH_HAS_KERNEL_FPU_SUPPORT Date: Thu, 7 Dec 2023 21:54:38 -0800 Message-ID: <20231208055501.2916202-9-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231208055501.2916202-1-samuel.holland@sifive.com> References: <20231208055501.2916202-1-samuel.holland@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Samuel Holland Reviewed-by: Christoph Hellwig --- 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 3762f41bb092..1fe7f2d8d017 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -81,6 +81,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 1a068de12a56..71576c8dbe79 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -70,6 +70,26 @@ export BITS KBUILD_CFLAGS +=3D -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx KBUILD_RUSTFLAGS +=3D -Ctarget-feature=3D-sse,-sse2,-sse3,-ssse3,-sse4.1,-= sse4.2,-avx,-avx2 =20 +# +# CFLAGS for compiling floating point code inside the kernel. +# +CC_FLAGS_FPU :=3D -msse -msse2 +ifdef CONFIG_CC_IS_GCC +# Stack alignment mismatch, proceed with caution. +# GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-bound= ary=3D3 +# (8B stack alignment). +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D53383 +# +# The "-msse" in the first argument is there so that the +# -mpreferred-stack-boundary=3D3 build error: +# +# -mpreferred-stack-boundary=3D3 is not between 4 and 12 +# +# can be triggered. Otherwise gcc doesn't complain. +CC_FLAGS_FPU +=3D -mhard-float +CC_FLAGS_FPU +=3D $(call cc-option,-msse -mpreferred-stack-boundary=3D3,-m= preferred-stack-boundary=3D4) +endif + ifeq ($(CONFIG_X86_KERNEL_IBT),y) # # Kernel IBT has S_CET.NOTRACK_EN=3D0, as such the compilers must not gene= rate 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 */ --=20 2.42.0