From patchwork Fri Dec 8 05:54:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13484863 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B04C5C10F07 for ; Fri, 8 Dec 2023 05:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LI9z/Ogex6hXWEpCpNgljA3ydO/DHhYEc/iEycOvX0U=; b=HVtBAXT+hT+TM3 m8csaFqFomoI6hASFAPvvf+ENMVQSGx1bpl3dsJ4FKrzs8xRxT3VpebtSHNaE9zAOLgRZe2y201Dg tvZhIbJc9ijNXZrPrZweuRNtv4KYrYnck20ukip3Bn2maC+ZF44z1aipkr3R2/v2XSqAmBfVhA/Ip NlYS8m0ffBZ+oBtjyEuyDJqJl6n2gAR3I6UlzVAelP//Z4UKrxlXB3Fotcfs+sYJOyTc/ezp3iz8l dAkwf3esZYXJT6Of6iA2eptQITXAB+xCBEdVmj/tl1028eWDWuvy7+7dvl3jyLJHwrfemXchVNJLa 066/JfzOpg229S+vfxhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBTpk-00EnsI-2S; Fri, 08 Dec 2023 05:55:32 +0000 Received: from mail-pl1-f170.google.com ([209.85.214.170]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBTpR-00EnX1-33 for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2023 05:55:18 +0000 Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d076ebf79cso13241855ad.1 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=1702014913; x=1702619713; darn=lists.infradead.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=IaFp8F9+mFxvVuFc7NVEbd6RlGzKzTm0buK6UFviPqpmbkQNZbT16xwN2kcH6e5YcO Lp5Jv8ai0LCfTZGOkTw7LAiCil8TfCGYGeJouFXZ0X2+L4juhBojeOEQJqmf1miS+qh5 2L5F2EaZnkT2W2PIz/74804fP+3al1sxnHs37v+Ww+L3Ojh64Dy1l83v0a5CebpThA6W QHUjzkbbDENw1VGcR0FcWiH74lQ7hU7gE52p+kso+G76Sfa4ewkYZEcC1/3+cL461lTJ skWdrJKLMdvTwt/VKL+W+NHJOQggZ8en+VQ6Jd4OcuB+opSdTOeaCAwcZ5Zlbf7AQ/Y7 oJLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702014913; x=1702619713; 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=S8xVeaOKwsigNMthkstRgJ1fGv0ji84kcNzAXr4LILUvNkeyFI1ywTinJjAQXitxfw H5ffG9enpf12CF+1N7aC9fKTzuQcog2mTQ2kGMPD81yhS7lZWq2ohCpJhgCSq7kQ2ghL rK1ZS2N+iDNtSdj4I7ekwfOK0ARLSYx5XWqJnf8TQfc6pcmNhs95LIpNSOQc5Pl6Z6Kb KLsu/1hSM8yLf616MA9dUOj/VnX4TuEJTD8qQ/m2ByrRkWSF/RhPLqnegcrSzjitLMcC PoB8B7XjLHZfUdSYltc50l28wE8Y/WsfC/GSB3Qt/6+i4SGzYeHUj28FhwEFR2Mh+YGg 6y4A== X-Gm-Message-State: AOJu0YytXjbWS8LrmGnL5J/e5HFKWEZR4uUAejDv7qDHjSGg6GwwMVaw uPUBfAfqOhQG3nu51J+0DDvBMBlfN1RU7/PMARoE+NNRrDqrUPR4Er8rP9grKFKOE9QQyd/tgOl tYm0ymwmJ/lTj4G3dpMaOdzMGDJ+LYjp9FQvcRpSAbWxkjejLRkM1MYAJvaDNePkuOaSQfBYQUF uotFzZo3Q31KaD3RXGNvgGyvVTfg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_215514_006619_C38B90E0 X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx 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 */