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: 175594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5263148vqy; Thu, 7 Dec 2023 21:55:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBu7qRXU9bgcZMFb9p3pxPTxkO+xU47P5dV02rr2gyQ4gy1AIN2HOW46LpQohjbnCbY8WZ X-Received: by 2002:a05:6a20:3c91:b0:190:86b:ccf2 with SMTP id b17-20020a056a203c9100b00190086bccf2mr2011646pzj.59.1702014941701; Thu, 07 Dec 2023 21:55:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702014941; cv=none; d=google.com; s=arc-20160816; b=eGdKs6XLQ1WgHaCj0hWiVO6E2lWHLBL0TAjRk1pBjvkOEPIUTYkik6WwiCFbWiWqq2 QwUs6F2dvit6IesKmP8VgX9pVPiF1/bW+j+k9DvixyAayZkw5g3OBDsO+dNz73LWbgqI NM27+qRzhpTuhPoRsMXApTZMQgAKX5PDPw+ndUEPNelSxabmiFYNrRsppnENhVOWvi1Z r2Y4yXQkE5kffYvG5KvosJogFtXmtrtH+wWRdiAZBYckjy7YiRNfE5fb6x/RhYT3FD7l YJ6N1mX6dc7pxRUjfaPRwfMWg0MGl0V37JQjTdAPScv7RIsHw2ZNjd0rnmXyrVNdXP3q 8CKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wOdH6gQ2/kSr11qF6anDkZP04y2oGGJwChsMHemqfok=; fh=GWiN7/yH5ZaeB7dNf34H6takS9oI70VVB29etA3Fg9Y=; b=qkUUrjcL16dyXRyJc2MumAKtOzxLQliNeTlajLWIY9ggJyVhwNW5KNoPeKROWonYQy RY+6hXZqnmOsMYwTGUHnrvgrdiPl4h/8vRvqiHMQdznH4/5wCNYj5frCvBf6GcAOpeg/ e4BgrW5QXD+U12cncruq8oRhMXgYLM6JxTBG1ruM0EoLPVXOwGcCeBaUOkrMBNWP6nxV 4pDP0YaxIFWLwnZuyxWnu/JK4VWhWyIFEZp1W7gVSkDjfYttc3mqpZuxCplfsPUOT7z2 yjet3MaimNWWtQXGem8iOLnM01HMFaCISwMI7tAHWZtGmHGiwCEkQa8LwdEqwHb4KoEr fU5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=T4LqkHlr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d3-20020a17090ab30300b0028a37b59930si239101pjr.175.2023.12.07.21.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 21:55:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=T4LqkHlr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id F218E805D5FE; Thu, 7 Dec 2023 21:55:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233276AbjLHFz1 (ORCPT + 99 others); Fri, 8 Dec 2023 00:55:27 -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-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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 07 Dec 2023 21:55:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784692019087727558 X-GMAIL-MSGID: 1784692019087727558 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 */