diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1113,9 +1113,7 @@ MLINKS+=fpu_kern.9 fpu_kern_alloc_ctx.9 \ fpu_kern.9 fpu_kern_free_ctx.9 \ fpu_kern.9 fpu_kern_enter.9 \ - fpu_kern.9 fpu_kern_leave.9 \ - fpu_kern.9 fpu_kern_thread.9 \ - fpu_kern.9 is_fpu_kern_thread.9 + fpu_kern.9 fpu_kern_leave.9 MLINKS+=g_attach.9 g_detach.9 MLINKS+=g_bio.9 bio.9 \ g_bio.9 g_alloc_bio.9 \ diff --git a/share/man/man9/fpu_kern.9 b/share/man/man9/fpu_kern.9 --- a/share/man/man9/fpu_kern.9 +++ b/share/man/man9/fpu_kern.9 @@ -21,7 +21,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 13, 2020 +.Dd September 15, 2023 .Dt FPU_KERN 9 .Os .Sh NAME @@ -37,10 +37,6 @@ .Fn fpu_kern_enter "struct thread *td" "struct fpu_kern_ctx *ctx" "u_int flags" .Ft int .Fn fpu_kern_leave "struct thread *td" "struct fpu_kern_ctx *ctx" -.Ft int -.Fn fpu_kern_thread "u_int flags" -.Ft int -.Fn is_fpu_kern_thread "u_int flags" .Sh DESCRIPTION The .Nm @@ -109,16 +105,6 @@ .It Dv FPU_KERN_NORMAL Indicates that the caller intends to access the full FPU state. Must be specified currently. -.It Dv FPU_KERN_KTHR -Indicates that no saving of the current FPU state should be performed, -if the thread called -.Xr fpu_kern_thread 9 -function. -This is intended to minimize code duplication in callers which -could be used from both kernel thread and syscall contexts. -The -.Fn fpu_kern_leave -function correctly handles such contexts. .It Dv FPU_KERN_NOCTX Avoid nesting save area. If the flag is specified, the @@ -159,29 +145,6 @@ by another invocation of .Fn fpu_kern_enter . The function always returns 0. -.Pp -The -.Fn fpu_kern_thread -function enables an optimization for threads which never leave to -the usermode. -The current thread will reuse the usermode save area for the kernel FPU state -instead of requiring an explicitly allocated context. -There are no flags defined for the function, and no error states -that the function returns. -Once this function has been called, neither -.Fn fpu_kern_enter -nor -.Fn fpu_kern_leave -is required to be called and the fpu is available for use in the calling thread. -.Pp -The -.Fn is_fpu_kern_thread -function returns the boolean indicating whether the current thread -entered the mode enabled by -.Fn fpu_kern_thread . -There is currently no flags defined for the function, the return -value is true if the current thread have the permanent FPU save area, -and false otherwise. .Sh NOTES The .Nm diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -1158,10 +1158,6 @@ PCB_FPUINITDONE); return; } - if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) { - ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE; - return; - } critical_enter(); KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save == get_pcb_user_save_pcb(pcb), ("mangled pcb_save")); @@ -1196,9 +1192,6 @@ ("leaving not inuse ctx")); ctx->flags &= ~FPU_KERN_CTX_INUSE; - if (is_fpu_kern_thread(0) && - (ctx->flags & FPU_KERN_CTX_DUMMY) != 0) - return (0); KASSERT((ctx->flags & FPU_KERN_CTX_DUMMY) == 0, ("dummy ctx")); critical_enter(); @@ -1210,9 +1203,8 @@ if (pcb->pcb_save == get_pcb_user_save_pcb(pcb)) { if ((pcb->pcb_flags & PCB_USERFPUINITDONE) != 0) { set_pcb_flags(pcb, PCB_FPUINITDONE); - if ((pcb->pcb_flags & PCB_KERNFPU_THR) == 0) - clear_pcb_flags(pcb, PCB_KERNFPU); - } else if ((pcb->pcb_flags & PCB_KERNFPU_THR) == 0) + clear_pcb_flags(pcb, PCB_KERNFPU); + } else clear_pcb_flags(pcb, PCB_FPUINITDONE | PCB_KERNFPU); } else { if ((ctx->flags & FPU_KERN_CTX_FPUINITDONE) != 0) @@ -1225,29 +1217,6 @@ return (0); } -int -fpu_kern_thread(u_int flags) -{ - - KASSERT((curthread->td_pflags & TDP_KTHREAD) != 0, - ("Only kthread may use fpu_kern_thread")); - KASSERT(curpcb->pcb_save == get_pcb_user_save_pcb(curpcb), - ("mangled pcb_save")); - KASSERT(PCB_USER_FPU(curpcb), ("recursive call")); - - set_pcb_flags(curpcb, PCB_KERNFPU | PCB_KERNFPU_THR); - return (0); -} - -int -is_fpu_kern_thread(u_int flags) -{ - - if ((curthread->td_pflags & TDP_KTHREAD) == 0) - return (0); - return ((curpcb->pcb_flags & PCB_KERNFPU_THR) != 0); -} - /* * FPU save area alloc/free/init utility routines */ diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c --- a/sys/amd64/amd64/vm_machdep.c +++ b/sys/amd64/amd64/vm_machdep.c @@ -161,9 +161,9 @@ pcb2->pcb_fsbase = 0; pcb2->pcb_gsbase = 0; clear_pcb_flags(pcb2, PCB_FPUINITDONE | PCB_USERFPUINITDONE | - PCB_KERNFPU | PCB_KERNFPU_THR); + PCB_KERNFPU); } else { - MPASS((pcb2->pcb_flags & (PCB_KERNFPU | PCB_KERNFPU_THR)) == 0); + MPASS((pcb2->pcb_flags & (PCB_KERNFPU)) == 0); bcopy(get_pcb_user_save_td(td1), get_pcb_user_save_pcb(pcb2), cpu_max_ext_state_size); } diff --git a/sys/amd64/include/fpu.h b/sys/amd64/include/fpu.h --- a/sys/amd64/include/fpu.h +++ b/sys/amd64/include/fpu.h @@ -75,19 +75,16 @@ void fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags); int fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx); -int fpu_kern_thread(u_int flags); -int is_fpu_kern_thread(u_int flags); struct savefpu *fpu_save_area_alloc(void); void fpu_save_area_free(struct savefpu *fsa); void fpu_save_area_reset(struct savefpu *fsa); /* - * Flags for fpu_kern_alloc_ctx(), fpu_kern_enter() and fpu_kern_thread(). + * Flags for fpu_kern_alloc_ctx() and fpu_kern_enter(). */ #define FPU_KERN_NORMAL 0x0000 #define FPU_KERN_NOWAIT 0x0001 -#define FPU_KERN_KTHR 0x0002 #define FPU_KERN_NOCTX 0x0004 #endif diff --git a/sys/amd64/include/pcb.h b/sys/amd64/include/pcb.h --- a/sys/amd64/include/pcb.h +++ b/sys/amd64/include/pcb.h @@ -83,7 +83,6 @@ #define PCB_KERNFPU 0x04 /* kernel uses fpu */ #define PCB_FPUINITDONE 0x08 /* fpu state is initialized */ #define PCB_USERFPUINITDONE 0x10 /* fpu user state is initialized */ -#define PCB_KERNFPU_THR 0x20 /* fpu_kern_thread() */ #define PCB_32BIT 0x40 /* process has 32 bit context (segs etc) */ #define PCB_FPUNOSAVE 0x80 /* no save area for current FPU ctx */ diff --git a/sys/arm/arm/vfp.c b/sys/arm/arm/vfp.c --- a/sys/arm/arm/vfp.c +++ b/sys/arm/arm/vfp.c @@ -435,10 +435,6 @@ return; } - if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) { - ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE; - return; - } /* * Check either we are already using the VFP in the kernel, or * the the saved state points to the default user space. @@ -478,9 +474,6 @@ ("FPU context not inuse")); ctx->flags &= ~FPU_KERN_CTX_INUSE; - if (is_fpu_kern_thread(0) && - (ctx->flags & FPU_KERN_CTX_DUMMY) != 0) - return (0); KASSERT((ctx->flags & FPU_KERN_CTX_DUMMY) == 0, ("dummy ctx")); critical_enter(); vfp_discard(td); @@ -499,30 +492,4 @@ return (0); } -int -fpu_kern_thread(u_int flags __unused) -{ - struct pcb *pcb = curthread->td_pcb; - - KASSERT((curthread->td_pflags & TDP_KTHREAD) != 0, - ("Only kthread may use fpu_kern_thread")); - KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate, - ("Mangled pcb_vfpsaved")); - KASSERT((pcb->pcb_fpflags & PCB_FP_KERN) == 0, - ("Thread already setup for the VFP")); - pcb->pcb_fpflags |= PCB_FP_KERN; - return (0); -} - -int -is_fpu_kern_thread(u_int flags __unused) -{ - struct pcb *curpcb; - - if ((curthread->td_pflags & TDP_KTHREAD) == 0) - return (0); - curpcb = curthread->td_pcb; - return ((curpcb->pcb_fpflags & PCB_FP_KERN) != 0); -} - #endif diff --git a/sys/arm/include/vfp.h b/sys/arm/include/vfp.h --- a/sys/arm/include/vfp.h +++ b/sys/arm/include/vfp.h @@ -140,7 +140,6 @@ #define FPU_KERN_NORMAL 0x0000 #define FPU_KERN_NOWAIT 0x0001 -#define FPU_KERN_KTHR 0x0002 #define FPU_KERN_NOCTX 0x0004 #ifndef LOCORE @@ -168,8 +167,6 @@ void fpu_kern_free_ctx(struct fpu_kern_ctx *); void fpu_kern_enter(struct thread *, struct fpu_kern_ctx *, u_int); int fpu_kern_leave(struct thread *, struct fpu_kern_ctx *); -int fpu_kern_thread(u_int); -int is_fpu_kern_thread(u_int); #endif /* _KERNEL */ #endif /* LOCORE */ diff --git a/sys/arm64/arm64/vfp.c b/sys/arm64/arm64/vfp.c --- a/sys/arm64/arm64/vfp.c +++ b/sys/arm64/arm64/vfp.c @@ -373,10 +373,6 @@ return; } - if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) { - ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE; - return; - } /* * Check either we are already using the VFP in the kernel, or * the saved state points to the default user space. @@ -415,9 +411,6 @@ ("FPU context not inuse")); ctx->flags &= ~FPU_KERN_CTX_INUSE; - if (is_fpu_kern_thread(0) && - (ctx->flags & FPU_KERN_CTX_DUMMY) != 0) - return (0); KASSERT((ctx->flags & FPU_KERN_CTX_DUMMY) == 0, ("dummy ctx")); critical_enter(); vfp_discard(td); @@ -436,32 +429,6 @@ return (0); } -int -fpu_kern_thread(u_int flags __unused) -{ - struct pcb *pcb = curthread->td_pcb; - - KASSERT((curthread->td_pflags & TDP_KTHREAD) != 0, - ("Only kthread may use fpu_kern_thread")); - KASSERT(pcb->pcb_fpusaved == &pcb->pcb_fpustate, - ("Mangled pcb_fpusaved")); - KASSERT((pcb->pcb_fpflags & PCB_FP_KERN) == 0, - ("Thread already setup for the VFP")); - pcb->pcb_fpflags |= PCB_FP_KERN; - return (0); -} - -int -is_fpu_kern_thread(u_int flags __unused) -{ - struct pcb *curpcb; - - if ((curthread->td_pflags & TDP_KTHREAD) == 0) - return (0); - curpcb = curthread->td_pcb; - return ((curpcb->pcb_fpflags & PCB_FP_KERN) != 0); -} - /* * FPU save area alloc/free/init utility routines */ diff --git a/sys/arm64/include/vfp.h b/sys/arm64/include/vfp.h --- a/sys/arm64/include/vfp.h +++ b/sys/arm64/include/vfp.h @@ -82,19 +82,16 @@ struct fpu_kern_ctx; /* - * Flags for fpu_kern_alloc_ctx(), fpu_kern_enter() and fpu_kern_thread(). + * Flags for fpu_kern_alloc_ctx() and fpu_kern_enter() */ #define FPU_KERN_NORMAL 0x0000 #define FPU_KERN_NOWAIT 0x0001 -#define FPU_KERN_KTHR 0x0002 #define FPU_KERN_NOCTX 0x0004 struct fpu_kern_ctx *fpu_kern_alloc_ctx(u_int); void fpu_kern_free_ctx(struct fpu_kern_ctx *); void fpu_kern_enter(struct thread *, struct fpu_kern_ctx *, u_int); int fpu_kern_leave(struct thread *, struct fpu_kern_ctx *); -int fpu_kern_thread(u_int); -int is_fpu_kern_thread(u_int); struct vfpstate *fpu_save_area_alloc(void); void fpu_save_area_free(struct vfpstate *fsa); diff --git a/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_aarch64.h b/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_aarch64.h --- a/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_aarch64.h +++ b/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_aarch64.h @@ -60,13 +60,11 @@ #define kfpu_allowed() 1 #define kfpu_begin() do { \ - if (__predict_false(!is_fpu_kern_thread(0))) \ - fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); \ + fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); \ } while (0) #define kfpu_end() do { \ - if (__predict_false(curthread->td_pcb->pcb_fpflags & PCB_FP_NOSAVE)) \ - fpu_kern_leave(curthread, NULL); \ + fpu_kern_leave(curthread, NULL); \ } while (0) #endif diff --git a/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_x86.h b/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_x86.h --- a/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_x86.h +++ b/sys/contrib/openzfs/include/os/freebsd/spl/sys/simd_x86.h @@ -42,8 +42,7 @@ #define kfpu_begin() { \ - if (__predict_false(!is_fpu_kern_thread(0))) \ - fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX);\ + fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX);\ } #ifndef PCB_FPUNOSAVE @@ -51,8 +50,7 @@ #endif #define kfpu_end() { \ - if (__predict_false(curpcb->pcb_flags & PCB_FPUNOSAVE)) \ - fpu_kern_leave(curthread, NULL); \ + fpu_kern_leave(curthread, NULL); \ } /* diff --git a/sys/contrib/openzfs/module/os/freebsd/spl/spl_taskq.c b/sys/contrib/openzfs/module/os/freebsd/spl/spl_taskq.c --- a/sys/contrib/openzfs/module/os/freebsd/spl/spl_taskq.c +++ b/sys/contrib/openzfs/module/os/freebsd/spl/spl_taskq.c @@ -206,10 +206,6 @@ { taskq_t *tq = context; -#if defined(__amd64__) || defined(__aarch64__) - if (context != NULL && tsd_get(taskq_tsd) == NULL) - fpu_kern_thread(FPU_KERN_NORMAL); -#endif tsd_set(taskq_tsd, tq); } diff --git a/sys/crypto/openssl/ossl.c b/sys/crypto/openssl/ossl.c --- a/sys/crypto/openssl/ossl.c +++ b/sys/crypto/openssl/ossl.c @@ -423,17 +423,11 @@ const struct crypto_session_params *csp; struct ossl_session *s; int error; - bool fpu_entered; s = crypto_get_driver_session(crp->crp_session); csp = crypto_get_params(crp->crp_session); - if (is_fpu_kern_thread(0)) { - fpu_entered = false; - } else { - fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); - fpu_entered = true; - } + fpu_kern_enter(curthread, NULL, FPU_KERN_NOCTX); switch (csp->csp_mode) { case CSP_MODE_DIGEST: @@ -452,8 +446,7 @@ __assert_unreachable(); } - if (fpu_entered) - fpu_kern_leave(curthread, NULL); + fpu_kern_leave(curthread, NULL); crp->crp_etype = error; crypto_done(crp); diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c --- a/sys/i386/i386/npx.c +++ b/sys/i386/i386/npx.c @@ -1415,10 +1415,6 @@ pcb->pcb_flags |= PCB_KERNNPX | PCB_NPXNOSAVE | PCB_NPXINITDONE; return; } - if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) { - ctx->flags = FPU_KERN_CTX_DUMMY | FPU_KERN_CTX_INUSE; - return; - } pcb = td->td_pcb; critical_enter(); KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save == @@ -1454,9 +1450,6 @@ ("leaving not inuse ctx")); ctx->flags &= ~FPU_KERN_CTX_INUSE; - if (is_fpu_kern_thread(0) && - (ctx->flags & FPU_KERN_CTX_DUMMY) != 0) - return (0); KASSERT((ctx->flags & FPU_KERN_CTX_DUMMY) == 0, ("dummy ctx")); critical_enter(); @@ -1468,9 +1461,8 @@ if (pcb->pcb_save == get_pcb_user_save_pcb(pcb)) { if ((pcb->pcb_flags & PCB_NPXUSERINITDONE) != 0) { pcb->pcb_flags |= PCB_NPXINITDONE; - if ((pcb->pcb_flags & PCB_KERNNPX_THR) == 0) - pcb->pcb_flags &= ~PCB_KERNNPX; - } else if ((pcb->pcb_flags & PCB_KERNNPX_THR) == 0) + pcb->pcb_flags &= ~PCB_KERNNPX; + } else pcb->pcb_flags &= ~(PCB_NPXINITDONE | PCB_KERNNPX); } else { if ((ctx->flags & FPU_KERN_CTX_NPXINITDONE) != 0) @@ -1483,29 +1475,6 @@ return (0); } -int -fpu_kern_thread(u_int flags) -{ - - KASSERT((curthread->td_pflags & TDP_KTHREAD) != 0, - ("Only kthread may use fpu_kern_thread")); - KASSERT(curpcb->pcb_save == get_pcb_user_save_pcb(curpcb), - ("mangled pcb_save")); - KASSERT(PCB_USER_FPU(curpcb), ("recursive call")); - - curpcb->pcb_flags |= PCB_KERNNPX | PCB_KERNNPX_THR; - return (0); -} - -int -is_fpu_kern_thread(u_int flags) -{ - - if ((curthread->td_pflags & TDP_KTHREAD) == 0) - return (0); - return ((curpcb->pcb_flags & PCB_KERNNPX_THR) != 0); -} - /* * FPU save area alloc/free/init utility routines */ diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -165,9 +165,9 @@ set_fsbase(td2, 0); set_gsbase(td2, 0); pcb2->pcb_flags &= ~(PCB_NPXINITDONE | PCB_NPXUSERINITDONE | - PCB_KERNNPX | PCB_KERNNPX_THR); + PCB_KERNNPX); } else { - MPASS((pcb2->pcb_flags & (PCB_KERNNPX | PCB_KERNNPX_THR)) == 0); + MPASS((pcb2->pcb_flags & (PCB_KERNNPX)) == 0); bcopy(get_pcb_user_save_td(td1), get_pcb_user_save_pcb(pcb2), cpu_max_ext_state_size); } diff --git a/sys/i386/include/npx.h b/sys/i386/include/npx.h --- a/sys/i386/include/npx.h +++ b/sys/i386/include/npx.h @@ -78,19 +78,16 @@ void fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags); int fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx); -int fpu_kern_thread(u_int flags); -int is_fpu_kern_thread(u_int flags); union savefpu *fpu_save_area_alloc(void); void fpu_save_area_free(union savefpu *fsa); void fpu_save_area_reset(union savefpu *fsa); /* - * Flags for fpu_kern_alloc_ctx(), fpu_kern_enter() and fpu_kern_thread(). + * Flags for fpu_kern_alloc_ctx() and fpu_kern_enter(). */ #define FPU_KERN_NORMAL 0x0000 #define FPU_KERN_NOWAIT 0x0001 -#define FPU_KERN_KTHR 0x0002 #define FPU_KERN_NOCTX 0x0004 #endif diff --git a/sys/i386/include/pcb.h b/sys/i386/include/pcb.h --- a/sys/i386/include/pcb.h +++ b/sys/i386/include/pcb.h @@ -81,7 +81,6 @@ u_int pcb_flags; #define PCB_DBREGS 0x02 /* process using debug registers */ -#define PCB_KERNNPX_THR 0x04 /* fpu_kern_thread() */ #define PCB_NPXINITDONE 0x08 /* fpu state is initialized */ #define PCB_VM86CALL 0x10 /* in vm86 call */ #define PCB_NPXUSERINITDONE 0x20 /* user fpu state is initialized */ diff --git a/sys/kern/uipc_ktls.c b/sys/kern/uipc_ktls.c --- a/sys/kern/uipc_ktls.c +++ b/sys/kern/uipc_ktls.c @@ -3205,9 +3205,6 @@ printf("Unable to bind KTLS worker thread for CPU %d: error %d\n", cpu, error); } -#if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) - fpu_kern_thread(0); -#endif for (;;) { mtx_lock(&wq->mtx); while (STAILQ_EMPTY(&wq->m_head) && diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -1769,10 +1769,6 @@ struct cryptocap *cap; int result, hint; -#if defined(__i386__) || defined(__amd64__) || defined(__aarch64__) - fpu_kern_thread(FPU_KERN_NORMAL); -#endif - CRYPTO_Q_LOCK(); for (;;) { /*