Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] Unified cross-architecture kernel-mode FPU API #971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 24, 2025

Conversation

Avenger-285714
Copy link
Collaborator

@Avenger-285714 Avenger-285714 commented Jul 24, 2025

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.

Link: https://lore.kernel.org/all/20240329072441.591471-2-samuel.holland@sifive.com/T/#u

Summary by Sourcery

Unify and centralize the kernel-mode floating-point API and build flags across all architectures by introducing consistent kernel_fpu_begin/end/available interfaces, consolidating FPU-related CFLAGS into CC_FLAGS_FPU and CC_FLAGS_NO_FPU, implementing the new API on RISC-V, LoongArch, PowerPC, ARM, ARM64, and x86, and converting existing FPU users (the AMDGPU DRM driver and the FPU self-test) to the new interface; add core documentation for floating-point usage and split the FPU self-test into glue and implementation modules.

New Features:

  • Define a unified kernel-mode FPU API (kernel_fpu_begin, kernel_fpu_end, kernel_fpu_available) with a common header
  • Introduce CC_FLAGS_FPU and CC_FLAGS_NO_FPU build variables for enabling or disabling FPU support project-wide
  • Implement the new FPU API on RISC-V, LoongArch, PowerPC, ARM, ARM64, and x86 architectures
  • Convert the AMDGPU DRM driver and the FPU self-test to use the unified FPU API
  • Refactor the FPU self-test into separate glue and implementation files, guarded by kernel_fpu_available

Enhancements:

  • Remove per-architecture conditional FPU flags in scattered Makefiles and apply centralized flags consistently
  • Add include/linux/fpu.h as an umbrella header and update existing consumers to use it

Documentation:

  • Add Documentation/core-api/floating-point.rst describing floating-point compilation and usage

Tests:

  • Modify the FPU self-test to only initialize when kernel_fpu_available returns true

Copy link

sourcery-ai bot commented Jul 24, 2025

Reviewer's Guide

This series centralizes and unifies kernel-mode FPU support across architectures by defining a common API and build flags, providing per-architecture implementations, migrating existing drivers and tests to the new interface, and documenting floating-point compilation requirements.

Class diagram for the unified kernel-mode FPU API

classDiagram
    class FPU_API {
        +bool kernel_fpu_available()
        +void kernel_fpu_begin()
        +void kernel_fpu_end()
    }
    class arch_x86_fpu_h {
        +bool kernel_fpu_available() = true
        +void kernel_fpu_begin() (from asm/fpu/api.h)
        +void kernel_fpu_end() (from asm/fpu/api.h)
    }
    class arch_arm_fpu_h {
        +bool kernel_fpu_available() = cpu_has_neon()
        +void kernel_fpu_begin() = kernel_neon_begin()
        +void kernel_fpu_end() = kernel_neon_end()
    }
    class arch_arm64_fpu_h {
        +bool kernel_fpu_available() = cpu_has_neon()
        +void kernel_fpu_begin() = kernel_neon_begin()
        +void kernel_fpu_end() = kernel_neon_end()
    }
    class arch_loongarch_fpu_h {
        +bool kernel_fpu_available() = cpu_has_fpu
        +void kernel_fpu_begin()
        +void kernel_fpu_end()
    }
    class arch_powerpc_fpu_h {
        +bool kernel_fpu_available() = !cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)
        +void kernel_fpu_begin()
        +void kernel_fpu_end()
    }
    class arch_riscv_fpu_h {
        +bool kernel_fpu_available() = has_fpu()
        +void kernel_fpu_begin()
        +void kernel_fpu_end()
    }
    FPU_API <|.. arch_x86_fpu_h
    FPU_API <|.. arch_arm_fpu_h
    FPU_API <|.. arch_arm64_fpu_h
    FPU_API <|.. arch_loongarch_fpu_h
    FPU_API <|.. arch_powerpc_fpu_h
    FPU_API <|.. arch_riscv_fpu_h
Loading

Class diagram for updated AMDGPU FPU usage

classDiagram
    class dc_fpu {
        +void dc_fpu_begin(const char *function_name, int line)
        +void dc_fpu_end(const char *function_name, int line)
    }
    class FPU_API {
        +bool kernel_fpu_available()
        +void kernel_fpu_begin()
        +void kernel_fpu_end()
    }
    dc_fpu ..> FPU_API : uses
Loading

Class diagram for FPU self-test refactor

classDiagram
    class test_fpu_glue {
        <<file>>
    }
    class test_fpu_impl {
        <<file>>
    }
    class FPU_API {
        +bool kernel_fpu_available()
        +void kernel_fpu_begin()
        +void kernel_fpu_end()
    }
    test_fpu_glue ..> test_fpu_impl : delegates
    test_fpu_impl ..> FPU_API : uses
Loading

File-Level Changes

Change Details Files
Introduce a unified kernel-mode FPU API header and architecture-specific wrappers
  • Added include/linux/fpu.h as the generic API entry point
  • Created arch/{x86,arm,arm64,loongarch,powerpc,riscv}/include/asm/fpu.h to define kernel_fpu_*
  • Replaced arch-specific #includes in user code with <linux/fpu.h>
include/linux/fpu.h
arch/x86/include/asm/fpu.h
arch/arm/include/asm/fpu.h
arch/arm64/include/asm/fpu.h
arch/loongarch/include/asm/fpu.h
arch/powerpc/include/asm/fpu.h
arch/riscv/include/asm/fpu.h
drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.c
lib/test_fpu_glue.c
Define and apply CC_FLAGS_FPU and CC_FLAGS_NO_FPU build flags
  • Export CC_FLAGS_FPU and CC_FLAGS_NO_FPU in the top-level Makefile
  • Replaced scattered per-architecture FPU flag logic with CC_FLAGS_FPU/NO_FPU
  • Adjusted Makefiles for drivers/gpu, lib/raid6, lib, and multiple arch subdirs
Makefile
drivers/gpu/drm/amd/display/dc/dml/Makefile
lib/raid6/Makefile
lib/Makefile
arch/x86/Makefile
arch/arm/Makefile
arch/arm64/Makefile
arch/loongarch/Makefile
arch/powerpc/Makefile
arch/arm/lib/Makefile
arch/arm64/lib/Makefile
Implement per-architecture kernel-mode FPU routines for RISC-V
  • Created arch/riscv/kernel/kernel_mode_fpu.c with begin/end definitions
  • Updated arch/riscv/kernel/Makefile to build kernel_mode_fpu.o
  • Removed inline kernel_fpu_* definitions from arch/riscv/include/asm/switch_to.h
arch/riscv/kernel/kernel_mode_fpu.c
arch/riscv/kernel/Makefile
arch/riscv/include/asm/switch_to.h
Migrate existing FPU users to the unified API
  • Updated AMDGPU dc_fpu.c to call kernel_fpu_available(), kernel_fpu_begin()/end()
  • Split test_fpu into glue and implementation files using the new API
  • Added lib/test_fpu_impl.c and header lib/test_fpu.h
drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.c
lib/test_fpu_glue.c
lib/test_fpu_impl.c
lib/test_fpu.h
Document floating-point compilation requirements
  • Added Documentation/core-api/floating-point.rst describing CC_FLAGS_FPU/NO_FPU usage
Documentation/core-api/floating-point.rst

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a unified cross-architecture kernel-mode FPU API to standardize floating-point operations across different CPU architectures. The series replaces architecture-specific FPU handling with a consistent API defined in linux/fpu.h, enabling better code reuse and simplifying FPU-dependent code compilation.

  • Unified FPU API across x86, ARM, ARM64, PowerPC, LoongArch, and RISC-V architectures
  • Standardized compilation flags (CC_FLAGS_FPU/CC_FLAGS_NO_FPU) for FPU code
  • Updated AMD GPU driver and FPU self-test to use the new common API

Reviewed Changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
include/linux/fpu.h New unified FPU header with compilation unit check
arch/*/include/asm/fpu.h Architecture-specific FPU API implementations
arch/*/Makefile Standardized FPU compilation flags definitions
arch/*/Kconfig Added ARCH_HAS_KERNEL_FPU_SUPPORT configuration
drivers/gpu/drm/amd/display/ Updated AMD GPU driver to use unified FPU API
lib/test_fpu* Refactored FPU self-test with separated implementation
lib/raid6/Makefile Updated to use standardized FPU compilation flags
arch/Kconfig Added new kernel FPU support configuration option
Documentation/core-api/floating-point.rst New documentation for FPU API usage

#define _LINUX_FPU_H

#ifdef _LINUX_FPU_COMPILATION_UNIT
#error FP code must be compiled separately. See Documentation/core-api/floating-point.rst.
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should use 'FPU' instead of 'FP' for consistency with the rest of the codebase and the filename.

Suggested change
#error FP code must be compiled separately. See Documentation/core-api/floating-point.rst.
#error FPU code must be compiled separately. See Documentation/core-api/floating-point.rst.

Copilot uses AI. Check for mistakes.

void kernel_fpu_begin(void)
{
preempt_disable();
fstate_save(current, task_pt_regs(current));
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling task_pt_regs(current) twice (here and in kernel_fpu_end) is inefficient. Consider storing the result in a local variable.

Suggested change
fstate_save(current, task_pt_regs(current));
struct pt_regs *regs = task_pt_regs(current);
fstate_save(current, regs);

Copilot uses AI. Check for mistakes.

if (*pcpu == 1) {
#if defined(CONFIG_X86) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV)
BUG_ON(!kernel_fpu_available());
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using BUG_ON() in this context may be too harsh as it crashes the kernel. Consider using WARN_ON_ONCE() and returning early, or checking kernel_fpu_available() at module initialization time instead.

Suggested change
BUG_ON(!kernel_fpu_available());
if (WARN_ON_ONCE(!kernel_fpu_available())) {
put_cpu_ptr(&fpu_recursion_depth);
return;
}

Copilot uses AI. Check for mistakes.

@@ -68,6 +38,9 @@ static struct dentry *selftest_dir;

static int __init test_fpu_init(void)
{
if (!kernel_fpu_available())
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The availability check in test_fpu_init() should be moved earlier, before creating debugfs entries, to avoid creating debugfs files when FPU is not available.

Copilot uses AI. Check for mistakes.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Avenger-285714 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `arch/arm/include/asm/fpu.h:11` </location>
<code_context>
+
+#include <asm/neon.h>
+
+#define kernel_fpu_available()	cpu_has_neon()
+#define kernel_fpu_begin()	kernel_neon_begin()
+#define kernel_fpu_end()	kernel_neon_end()
</code_context>

<issue_to_address>
kernel_fpu_available() is tied to NEON; may not cover all ARM FPU cases.

cpu_has_neon() may not accurately reflect FPU support on all ARM CPUs, potentially leading to incorrect detection of FPU availability.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


#include <asm/neon.h>

#define kernel_fpu_available() cpu_has_neon()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): kernel_fpu_available() is tied to NEON; may not cover all ARM FPU cases.

cpu_has_neon() may not accurately reflect FPU support on all ARM CPUs, potentially leading to incorrect detection of FPU availability.

SiFiveHolland and others added 15 commits July 24, 2025 16:27
[ Upstream commit b11b998 ]

Patch series "Unified cross-architecture kernel-mode FPU API", v4.

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.

This patch (of 15):

The include guard should match the filename, or it will conflict with
the newly-added asm/fpu.h.

Link: https://lkml.kernel.org/r/20240329072441.591471-1-samuel.holland@sifive.com
Link: https://lkml.kernel.org/r/20240329072441.591471-10-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: WANG Xuerui <git@xen0n.name>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 6cbd1d6 ]

Several architectures provide an API to enable the FPU and run
floating-point SIMD code in kernel space.  However, the function names,
header locations, and semantics are inconsistent across architectures, and
FPU support may be gated behind other Kconfig options.

provide a standard way for architectures to declare that kernel space
FPU support is available. Architectures selecting this option must
implement what is currently the most common API (kernel_fpu_begin() and
kernel_fpu_end(), plus a new function kernel_fpu_available()) and
provide the appropriate CFLAGS for compiling floating-point C code.

Link: https://lkml.kernel.org/r/20240329072441.591471-2-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Suggested-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit cb2b7b7 ]

ARM provides an equivalent to the common kernel-mode FPU API, but in a
different header and using different function names.  Add a wrapper
header, and export CFLAGS adjustments as found in lib/raid6/Makefile.

[samuel.holland@sifive.com: ARM: do not select ARCH_HAS_KERNEL_FPU_SUPPORT]
  Link: https://lkml.kernel.org/r/20240509013727.648600-1-samuel.holland@sifive.com
Link: https://lkml.kernel.org/r/20240329072441.591471-3-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Cc: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit  c416243 ]

Now that CC_FLAGS_FPU is exported and can be used anywhere in the source
tree, use it instead of duplicating the flags here.

Link: https://lkml.kernel.org/r/20240329072441.591471-4-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit  71883ae ]

arm64 provides an equivalent to the common kernel-mode FPU API, but in a
different header and using different function names.  Add a wrapper
header, and export CFLAGS adjustments as found in lib/raid6/Makefile.

Link: https://lkml.kernel.org/r/20240329072441.591471-5-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit  7177089 ]

Now that CC_FLAGS_FPU is exported and can be used anywhere in the source
tree, use it instead of duplicating the flags here.

Link: https://lkml.kernel.org/r/20240329072441.591471-6-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 4be0739 ]

Now that CC_FLAGS_FPU is exported and can be used anywhere in the source
tree, use it instead of duplicating the flags here.

Link: https://lkml.kernel.org/r/20240329072441.591471-7-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 372f662 ]

LoongArch already provides kernel_fpu_begin() and kernel_fpu_end() in
asm/fpu.h, so it only needs to add kernel_fpu_available() and export the
CFLAGS adjustments.

Link: https://lkml.kernel.org/r/20240329072441.591471-8-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit  01db473 ]

PowerPC provides an equivalent to the common kernel-mode FPU API, but in a
different header and using different function names.  The PowerPC API also
requires a non-preemptible context.  Add a wrapper header, and export the
CFLAGS adjustments.

Link: https://lkml.kernel.org/r/20240329072441.591471-9-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit b0b8a15 ]

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.

Link: https://lkml.kernel.org/r/20240329072441.591471-11-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 77acc6b ]

This is motivated by the amdgpu DRM driver, which needs floating-point
code to support recent hardware.  That code is not performance-critical,
so only provide a minimal non-preemptible implementation for now.

Support is limited to riscv64 because riscv32 requires runtime (libgcc)
assistance to convert between doubles and 64-bit integers.

Link: https://lkml.kernel.org/r/20240329072441.591471-12-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
[ deepin: Fix 172570c ("riscv: Add support for kernel-mode FPU") ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 06a990b ]

The compiler flags enable altivec, but that is not required; hard-float is
sufficient for the code to build and function.

Drop altivec from the compiler flags and adjust the enable/disable code to
only enable FPU use.

Link: https://lkml.kernel.org/r/20240329072441.591471-13-samuel.holland@sifive.com
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit  a28e4b6 ]

Now that all previously-supported architectures select
ARCH_HAS_KERNEL_FPU_SUPPORT, this code can depend on that symbol instead
of the existing list of architectures.  It can also take advantage of the
common kernel-mode FPU API and method of adjusting CFLAGS.

Link: https://lkml.kernel.org/r/20240329072441.591471-14-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 9613736 ]

This ensures no compiler-generated floating-point code can appear outside
kernel_fpu_{begin,end}() sections, and some architectures enforce this
separation.

Link: https://lkml.kernel.org/r/20240329072441.591471-15-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit 790a4a3 ]

Now that ARCH_HAS_KERNEL_FPU_SUPPORT provides a common way to compile and
run floating-point code, this test is no longer x86-specific.

Link: https://lkml.kernel.org/r/20240329072441.591471-16-samuel.holland@sifive.com
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: WANG Xuerui <git@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[ Backport from v6.10 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: opsiff

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@opsiff opsiff merged commit 0ab89aa into deepin-community:linux-6.6.y Jul 24, 2025
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants