Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3701383rdb; Wed, 27 Dec 2023 17:42:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV83oP3OywuOczXFEpjuNc2UHLOtnrAQpmlx2Wrkel4r/+vKPAidCpybvCBwclxTHPh2EJ X-Received: by 2002:a17:906:51cf:b0:a23:5010:faa9 with SMTP id v15-20020a17090651cf00b00a235010faa9mr2384703ejk.129.1703727760094; Wed, 27 Dec 2023 17:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703727760; cv=none; d=google.com; s=arc-20160816; b=0defMR8T4oLfFe3s0+Jpi3bNgu8PJjEEGsLoyCB4bGL9g4t5KGIr68LkKH1IbaBpc1 5YHKgKJjtRQlzwIcU+jMgE/EhYnx9m2EToIsMQ7NKZvuJYywLqhNk32wQ14RF+5Dw+f2 ADHd23C1mBHJgX3GddZQMf9Ov8+66Pb0tXQkDyqikbVfnMS4tfgBAu+b0KBymHwNRn5g 6YUMch8ktYeXQa8sGI72Dps2Hhrivw4xszyvGv3IMjO2dcndO3TNSxrqxACrSxjF1lBW CZBnb5OxkT6Tyzx24B3wvitgoHVEsvWyDmZK/dbuaDXgBuQsuKp3o5uUkN8WEC2viKH+ Pjvw== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=LKYKCC0iAyjtmcl9i3gxZmi/p+HZhZfirGb7twXi050=; fh=94uOV5sWmRw3BrY72TFM31lKigqzeHCm+E+w2ZFcL9E=; b=M/KD2PSPIMCq0MfYA2A7B9hqgE03pH7EMk73CRRUDZrTJEY2TCVEL0OtyrxrhNrPqz 8EgPsX3OgAbi6OKVqUOcgbZicboQ3yRcA581gIQaHz6WPmhHi6xcbieY53xWKH0aVcta csI2DlFAVtRQsZemr2G35NV2CMKxKOL+VPYUSVuEARTbsYPJ5o2AAAALo4ei4NPcyW49 GVK3XJV2C/Cn2NF80Nz4Vnyf7uqn9zIRwQD7h+0dJ26zGoZOisK8vWrNk6dIdNTEGNWb SaIDSQQYlcuzTsAsmvrrBdRKaYBB4QSSMoR4atpV4m0RdFB1yQychm7GLt/82ZpB8JRs mzGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=TyU0wwBE; spf=pass (google.com: domain of linux-kernel+bounces-12367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12367-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v19-20020a170906339300b00a236c4a0a9esi6325581eja.785.2023.12.27.17.42.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:42:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=TyU0wwBE; spf=pass (google.com: domain of linux-kernel+bounces-12367-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12367-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A35D01F210F4 for ; Thu, 28 Dec 2023 01:42:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AB3817F3; Thu, 28 Dec 2023 01:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="TyU0wwBE" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 3B2B610EF for ; Thu, 28 Dec 2023 01:42:23 +0000 (UTC) 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-pf1-f180.google.com with SMTP id d2e1a72fcca58-6d9f94b9186so1002829b3a.0 for ; Wed, 27 Dec 2023 17:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1703727742; x=1704332542; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LKYKCC0iAyjtmcl9i3gxZmi/p+HZhZfirGb7twXi050=; b=TyU0wwBEJk10kuzvLRKAnyS/3SvkcZORHlzRCbc5fwcKB6QmEeNMdNQn3j8lsh5aBH 6xunCqHitRqAJP/UPZI5ZmG1fEjxmRVygq9Ur76fdQugnUXlSPfqPfLdb9aZUExVWV3J 3kSAwrJK9AU8zVAns6HcJymsFI+rYEtOYWtMWgB2RMzQqcV+10tuc5AVWtpmMjwoPuBd shB22BF2X6Ti0z5MdjifyZZsKlqtE8Ld/JxrKUXun94Auq4Pm/2zBoxDeeDOxN1SZ1aU 1uLS+Mv73RsrB44zYWH9BcrgPiet4v+ewXvJZCw3HY+ktHY2A3DO6MfNXKMld3vAJZ90 0AIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703727742; x=1704332542; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LKYKCC0iAyjtmcl9i3gxZmi/p+HZhZfirGb7twXi050=; b=SbeaH+alpIHd99XIj5elsQuauY6TBwY+sqktkesInhBBmxbcNRBMRI4KKmvRNC3dhK o7g7Mq9Wz0CUO0HZvG86Wy0y3NQxyk5Oih2l7U/GCxorFsy7pITqlV08FAaHrKS2Fj1Y Sr1qIO1m+OQGblpgQ3Z86J2/toCWNvliLdC04xNvjBte/xGZYBXtNFHEa9SA/qGTM+iE 834Q9Le5A84Dbzv4cdYZDX7Li+fSiv+jtps3Cn8JVIJwNa3+9dFmXa3Q/EnSSuUrAGPn 5Bd4cwiUiMvrcRklaEnlpn7yOp/7fzerQ5WcU+WHbmw5MDKjKrM0YWKpaUTJDpWVGdiR rE4Q== X-Gm-Message-State: AOJu0Yy/+aA2RIgDP+vy/xtSfq3Rj3b81k6R4ryQqDscPVlWLGSGrJyA /RDUikdTbpA94Kn4RZRxaesIy0/Ox1Tw9Q== X-Received: by 2002:a05:6a00:1d05:b0:6d9:bfb8:e37c with SMTP id a5-20020a056a001d0500b006d9bfb8e37cmr6112797pfx.41.1703727742547; Wed, 27 Dec 2023 17:42:22 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id g24-20020aa78758000000b006d49ed3effasm7335440pfo.63.2023.12.27.17.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:42:22 -0800 (PST) From: Samuel Holland To: linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-riscv@lists.infradead.org, Christoph Hellwig Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-arch@vger.kernel.org, Samuel Holland , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH v2 00/14] Unified cross-architecture kernel-mode FPU API Date: Wed, 27 Dec 2023 17:41:50 -0800 Message-ID: <20231228014220.3562640-1-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series unifies the kernel-mode FPU API across several architectures by wrapping the existing functions (where needed) in consistently-named functions placed in a consistent header location, with mostly the same semantics: they can be called from preemptible or non-preemptible task context, and are not assumed to be reentrant. Architectures are also expected to provide CFLAGS adjustments for compiling FPU-dependent code. For the moment, SIMD/vector units are out of scope for this common API. This allows us to remove the ifdeffery and duplicated Makefile logic at each FPU user. It then implements the common API on RISC-V, and converts a couple of users to the new API: the AMDGPU DRM driver, and the FPU self test. The underlying goal of this series is to allow using newer AMD GPUs (e.g. Navi) on RISC-V boards such as SiFive's HiFive Unmatched. Those GPUs need CONFIG_DRM_AMD_DC_FP to initialize, which requires kernel-mode FPU support. Previous versions: v1: https://lore.kernel.org/linux-kernel/20231208055501.2916202-1-samuel.holland@sifive.com/ v0: https://lore.kernel.org/linux-kernel/20231122030621.3759313-1-samuel.holland@sifive.com/ Changes in v2: - Add documentation explaining the built-time and runtime APIs - Add a linux/fpu.h header for generic isolation enforcement - Remove file name from header comment - Clean up arch/arm64/lib/Makefile, like for arch/arm - Remove RISC-V architecture-specific preprocessor check - Split altivec removal to a separate patch - Use linux/fpu.h instead of asm/fpu.h in consumers - Declare test_fpu() in a header Michael Ellerman (1): drm/amd/display: Only use hard-float, not altivec on powerpc Samuel Holland (13): arch: Add ARCH_HAS_KERNEL_FPU_SUPPORT ARM: Implement ARCH_HAS_KERNEL_FPU_SUPPORT ARM: crypto: Use CC_FLAGS_FPU for NEON CFLAGS arm64: Implement ARCH_HAS_KERNEL_FPU_SUPPORT arm64: crypto: Use CC_FLAGS_FPU for NEON CFLAGS lib/raid6: Use CC_FLAGS_FPU for NEON CFLAGS LoongArch: Implement ARCH_HAS_KERNEL_FPU_SUPPORT powerpc: Implement ARCH_HAS_KERNEL_FPU_SUPPORT x86: Implement ARCH_HAS_KERNEL_FPU_SUPPORT riscv: Add support for kernel-mode FPU drm/amd/display: Use ARCH_HAS_KERNEL_FPU_SUPPORT selftests/fpu: Move FP code to a separate translation unit selftests/fpu: Allow building on other architectures Documentation/core-api/floating-point.rst | 78 +++++++++++++++++++ Documentation/core-api/index.rst | 1 + Makefile | 5 ++ arch/Kconfig | 6 ++ arch/arm/Kconfig | 1 + arch/arm/Makefile | 7 ++ arch/arm/include/asm/fpu.h | 15 ++++ arch/arm/lib/Makefile | 3 +- arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 9 ++- arch/arm64/include/asm/fpu.h | 15 ++++ arch/arm64/lib/Makefile | 6 +- arch/loongarch/Kconfig | 1 + arch/loongarch/Makefile | 5 +- arch/loongarch/include/asm/fpu.h | 1 + arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 5 +- arch/powerpc/include/asm/fpu.h | 28 +++++++ arch/riscv/Kconfig | 1 + arch/riscv/Makefile | 3 + arch/riscv/include/asm/fpu.h | 16 ++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/kernel_mode_fpu.c | 28 +++++++ arch/x86/Kconfig | 1 + arch/x86/Makefile | 20 +++++ arch/x86/include/asm/fpu.h | 13 ++++ drivers/gpu/drm/amd/display/Kconfig | 2 +- .../gpu/drm/amd/display/amdgpu_dm/dc_fpu.c | 35 +-------- drivers/gpu/drm/amd/display/dc/dml/Makefile | 36 +-------- drivers/gpu/drm/amd/display/dc/dml2/Makefile | 36 +-------- include/linux/fpu.h | 12 +++ lib/Kconfig.debug | 2 +- lib/Makefile | 26 +------ lib/raid6/Makefile | 31 ++------ lib/test_fpu.h | 8 ++ lib/{test_fpu.c => test_fpu_glue.c} | 37 ++------- lib/test_fpu_impl.c | 37 +++++++++ 37 files changed, 343 insertions(+), 190 deletions(-) create mode 100644 Documentation/core-api/floating-point.rst create mode 100644 arch/arm/include/asm/fpu.h create mode 100644 arch/arm64/include/asm/fpu.h create mode 100644 arch/powerpc/include/asm/fpu.h create mode 100644 arch/riscv/include/asm/fpu.h create mode 100644 arch/riscv/kernel/kernel_mode_fpu.c create mode 100644 arch/x86/include/asm/fpu.h create mode 100644 include/linux/fpu.h create mode 100644 lib/test_fpu.h rename lib/{test_fpu.c => test_fpu_glue.c} (71%) create mode 100644 lib/test_fpu_impl.c -- 2.42.0