From nobody Sat May 27 19:34:19 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QTBn81yXxz4WhLv; Sat, 27 May 2023 19:34:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QTBn80Kfhz4DZv; Sat, 27 May 2023 19:34:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685216060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cNENaZyuQeOs9eE8aZGz1ED0/1o7fzVaqUKVFoTZx/0=; b=eYxzyQlUal2LM/tcUJ7HQjcqA+wQvWK40yRX7l5z9AJlBltVVmlCbRC2UuMDgzv6cacyRf NUQACPh2zsTP0cFgR+VwQ9/XRmNXSMwE0cPdYXvRpK1dxUzdceJ/lgMM7LrLgywD/KQJqi eznPFLF0HqOHrq8kokXAz8TpckfZ5sbMBuZHn0PT2xYyC2hBrWgqIW067fNkHwCv26bL2c VHuDY02ENPOd5itv8JyNgiI49Ft70cVYuW73o6uu/uK2+hw1TW86KnfM+hm6c0iUWQd1UG SedXSRptGmtovVWSmMuUv+FywMTWADLlfPC/C6DJ4Au+NJCQ4YGlLJfzQcjYpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685216060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cNENaZyuQeOs9eE8aZGz1ED0/1o7fzVaqUKVFoTZx/0=; b=sHMNHEochgrl5PAo8InE/h8OecIJR3S5dNG+HflSzlmzVRc1iT7Sx7jAVG7p2DLxlMouCD dK9ZQiz6r6WHdwV0Kn5D8xnuIzXSTxlecwl98jtnL/x1cM7Fb6a6iRYK0tJOPTApfiK2MS nynhgeVVCkH4syXj/6Ayx40a7FlFgIjks4kbyoFz4HwsmWly9cqg+AvaZdZZHAjivhY+Hc kbC6zsi6J6jI1NSBi+omZIOmTvjHrrefEWeCV6QXHyOZSbIIN4ru0/WZYT9lGPYUW78iuU Bur6niSoX2PAByAw9ampnHOCdX3S7IBcKQjkhSNrSpIPQqHioC+rCFXNI9bzgw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685216060; a=rsa-sha256; cv=none; b=fQEo0PBrDyY0j62Xh3hSY25Im5YNoKIJC53ibfS+m2MSIaGxmQX+mlyqY0bzsqtuAlH0+V Asgs+Kx7ccrSRVRCVmklWXQzYutq0vet80hr7Pe4VEbXnqAUnySXqHO9xH/Gj4AhxqQGWO PPdTaHinqbcq9k1gL/UN2Okuzq8nUKw5WdVzrldtyY4EZjj7/a8LwCL2ZwaewpKnl+hwS/ PSOxMMaBU+k5aQLOQAVrTvcIUhjHZyBxWaG0d6KUrARYfjJOAYMN6FSbT+StselQu3bShS U6sEGed1pms1jNmwnv8zrWwnHNVvevux18D/ZrxoHiykhpdKF563+5UjrR7M+g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QTBn76WPWz11Ws; Sat, 27 May 2023 19:34:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34RJYJkD029274; Sat, 27 May 2023 19:34:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34RJYJxJ029273; Sat, 27 May 2023 19:34:19 GMT (envelope-from git) Date: Sat, 27 May 2023 19:34:19 GMT Message-Id: <202305271934.34RJYJxJ029273@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: fa6603d4a725 - stable/13 - Revert "LinuxKPI: Make FPU sections thread-safe and use the NOCTX flag." List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fa6603d4a7250bef7bc51bd3a2805b0d2ead3541 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=fa6603d4a7250bef7bc51bd3a2805b0d2ead3541 commit fa6603d4a7250bef7bc51bd3a2805b0d2ead3541 Author: John Baldwin AuthorDate: 2023-05-27 19:23:20 +0000 Commit: John Baldwin CommitDate: 2023-05-27 19:23:37 +0000 Revert "LinuxKPI: Make FPU sections thread-safe and use the NOCTX flag." This broke part of the KBI used by drm-kmod. This reverts commit 8ca78eb03fd4b3c9f514ea6c075fc44dc9c02d27. Reported by: manu --- sys/compat/linuxkpi/common/include/asm/fpu/api.h | 40 ++++++++++++++++++---- sys/compat/linuxkpi/common/include/linux/sched.h | 3 +- sys/compat/linuxkpi/common/src/linux_fpu.c | 43 ++++++------------------ sys/conf/files.amd64 | 3 ++ sys/conf/files.arm64 | 4 +++ sys/conf/files.i386 | 3 ++ sys/modules/linuxkpi/Makefile | 3 +- 7 files changed, 56 insertions(+), 43 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/asm/fpu/api.h b/sys/compat/linuxkpi/common/include/asm/fpu/api.h index 133754abdc4b..4b598d88be03 100644 --- a/sys/compat/linuxkpi/common/include/asm/fpu/api.h +++ b/sys/compat/linuxkpi/common/include/asm/fpu/api.h @@ -28,13 +28,41 @@ #ifndef _LINUXKPI_ASM_FPU_API_H_ #define _LINUXKPI_ASM_FPU_API_H_ -#define kernel_fpu_begin() \ - lkpi_kernel_fpu_begin() +#if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) -#define kernel_fpu_end() \ - lkpi_kernel_fpu_end() +#include -extern void lkpi_kernel_fpu_begin(void); -extern void lkpi_kernel_fpu_end(void); +extern struct fpu_kern_ctx *__lkpi_fpu_ctx; +extern unsigned int __lkpi_fpu_ctx_level; + +static inline void +kernel_fpu_begin() +{ + if (__lkpi_fpu_ctx_level++ == 0) { + fpu_kern_enter(curthread, __lkpi_fpu_ctx, FPU_KERN_NORMAL); + } +} + +static inline void +kernel_fpu_end() +{ + if (--__lkpi_fpu_ctx_level == 0) { + fpu_kern_leave(curthread, __lkpi_fpu_ctx); + } +} + +#else + +static inline void +kernel_fpu_begin() +{ +} + +static inline void +kernel_fpu_end() +{ +} + +#endif #endif /* _LINUXKPI_ASM_FPU_API_H_ */ diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h index f895cba0d894..6e0a01aa8466 100644 --- a/sys/compat/linuxkpi/common/include/linux/sched.h +++ b/sys/compat/linuxkpi/common/include/linux/sched.h @@ -89,8 +89,7 @@ struct task_struct { int bsd_interrupt_value; struct work_struct *work; /* current work struct, if set */ struct task_struct *group_leader; - unsigned rcu_section[TS_RCU_TYPE_MAX]; - unsigned int fpu_ctx_level; + unsigned rcu_section[TS_RCU_TYPE_MAX]; }; #define current ({ \ diff --git a/sys/compat/linuxkpi/common/src/linux_fpu.c b/sys/compat/linuxkpi/common/src/linux_fpu.c index 08f7e075d827..976e55e68ca1 100644 --- a/sys/compat/linuxkpi/common/src/linux_fpu.c +++ b/sys/compat/linuxkpi/common/src/linux_fpu.c @@ -30,44 +30,21 @@ #include #include -#include - -#include - -#if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) - #include -/* - * Technically the Linux API isn't supposed to allow nesting sections - * either, but currently used versions of GPU drivers rely on nesting - * working, so we only enter the section on the outermost level. - */ - -void -lkpi_kernel_fpu_begin(void) -{ - if ((current->fpu_ctx_level)++ == 0) - fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); -} - -void -lkpi_kernel_fpu_end(void) -{ - if (--(current->fpu_ctx_level) == 0) - fpu_kern_leave(curthread, NULL); -} - -#else +struct fpu_kern_ctx *__lkpi_fpu_ctx; +unsigned int __lkpi_fpu_ctx_level = 0; -void -lkpi_kernel_fpu_begin(void) +static void +linux_fpu_init(void *arg __unused) { + __lkpi_fpu_ctx = fpu_kern_alloc_ctx(0); } +SYSINIT(linux_fpu, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND, linux_fpu_init, NULL); -void -lkpi_kernel_fpu_end(void) +static void +linux_fpu_uninit(void *arg __unused) { + fpu_kern_free_ctx(__lkpi_fpu_ctx); } - -#endif +SYSUNINIT(linux_fpu, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND, linux_fpu_uninit, NULL); diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 4ae6fc3f33a1..b967a3be2a4f 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -436,6 +436,9 @@ x86/xen/pv.c optional xenhvm x86/xen/pvcpu_enum.c optional xenhvm x86/xen/xen_pci_bus.c optional xenhvm +compat/linuxkpi/common/src/linux_fpu.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" + contrib/openzfs/module/zcommon/zfs_fletcher_avx512.c optional zfs compile-with "${ZFS_C}" contrib/openzfs/module/zcommon/zfs_fletcher_intel.c optional zfs compile-with "${ZFS_C}" contrib/openzfs/module/zcommon/zfs_fletcher_sse.c optional zfs compile-with "${ZFS_C}" diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 3e91db3e22c6..6b96de28128d 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -575,6 +575,10 @@ arm64/rockchip/clk/rk3399_pmucru.c optional fdt soc_rockchip_rk3399 # Xilinx arm/xilinx/uart_dev_cdnc.c optional uart soc_xilinx_zynq +# Linuxkpi +compat/linuxkpi/common/src/linux_fpu.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" + # Cloudabi arm64/cloudabi32/cloudabi32_sysvec.c optional compat_cloudabi32 arm64/cloudabi64/cloudabi64_sysvec.c optional compat_cloudabi64 diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index 89e1d47987c4..4be98810b32e 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -189,6 +189,9 @@ x86/x86/mptable.c optional apic x86/x86/mptable_pci.c optional apic pci x86/x86/msi.c optional apic pci +compat/linuxkpi/common/src/linux_fpu.c optional compat_linuxkpi \ + compile-with "${LINUXKPI_C}" + # Clock calibration subroutine; uses floating-point arithmetic subr_clockcalib.o standard \ dependency "$S/kern/subr_clockcalib.c" \ diff --git a/sys/modules/linuxkpi/Makefile b/sys/modules/linuxkpi/Makefile index 897c86f51733..2ed6cda98b17 100644 --- a/sys/modules/linuxkpi/Makefile +++ b/sys/modules/linuxkpi/Makefile @@ -8,7 +8,6 @@ SRCS= linux_compat.c \ linux_dmi.c \ linux_domain.c \ linux_firmware.c \ - linux_fpu.c \ linux_hrtimer.c \ linux_idr.c \ linux_interrupt.c \ @@ -36,7 +35,7 @@ SRCS= linux_compat.c \ .if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \ ${MACHINE_CPUARCH} == "i386" -SRCS+= opt_acpi.h acpi_if.h linux_acpi.c +SRCS+= opt_acpi.h acpi_if.h linux_acpi.c linux_fpu.c .endif SRCS+= opt_ddb.h