From nobody Fri Dec 29 23:09:02 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 4T21KB5cTHz55TN4; Fri, 29 Dec 2023 23:09:02 +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 4T21KB4Gwmz4HDK; Fri, 29 Dec 2023 23:09:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703891342; 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=lPqKeQlsKMOit9Twa+/+DY8dHT4GFxhw2K311pqqvAw=; b=TjdhqEOh4b024v6vpkkkvrhKrmX6rqwwWFT7MyDPp9q85SNyIhnpA+vKwHMCsApFZrnSCi 279ZzPge8D9JoXqIrsvLmQmbDls6OGhalBzy6qAjfuWrSAsqZmMIsaI1HXv/pbg+504Y36 CxCKI10rrnwuTidImNfy/r9jddV0tY0/4QlHiGPT8dR6nQy9ZTGlM2PIRWpsdO/+f9QLL6 hVTyyUIEgRtBnNrcPxAkg+w7dgCrZA8TZWH0RFDndU5YdfzCjGqMjgcoiMRNrE5hVR4RLw yNkx1P7VnK4cIgbYcmtWa4PdntqNzSDt4ClGfKufjI/oq9uvmeEF9K+CSt/w0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703891342; a=rsa-sha256; cv=none; b=hpYJh0UMOsz5tKuyuMpXXtHQYfMVTNIyfJRWLJHS5iHZLYrUsbyOrkZe936E3x+U8JKA1C l1+BhkPjy0rJ4ECQUdWaBS/mnqvepFnrV6FZt/Vn9O/Xtm2MhEOXsZiVSo+It8Ao/4EXYl u7UHxqyR+XbPotYQoR8EkS4QnWRcVnvo+i0Mgd3705Fc3YCaB8MlOYnG41fqM4aFAt48OS SuoA8FrNJYcFvOe5X9WZA8AYOkoiVBIbfS+4QBKJvf6cHZW3u+NDQsn8Uc2Q7jygRCzdiU pdzzzYYaInnCwXAtfSeeLxwncdfErQu50w9fY1+jbp5e4tsRCn4RNiS854NbmA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703891342; 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=lPqKeQlsKMOit9Twa+/+DY8dHT4GFxhw2K311pqqvAw=; b=srKV5x2Aud779BcDZgtTVOdkKrf5OpvWH/D0qHHIRSCi03vD7axG1KvQWkMHX6BcIPZlii xiXdtnFw1ZQ6zY7bjXtbIXadZHxkWgSlY1An5QY4mgqqz4+fg15yRzvzlG1H1f3o2/NVTC E5xUc9gqkoq9dAVm7sR5b1f4dqt1vryI/5l04Ka7BQRKBMS9v2uShMQ52efDawfx7VTs5b ImM04FD0K+/7O4PSQy1Br7jVCwElruJ9qFTnb+sRFbCGW2egUzgcbSG7zA2BX2FouvKiyj zec/Fsr0Hd6dnSlBEjwnnSCMnAJUimIwVY/mOTl9w9asv7QBRUu3OsQIsFWi1A== 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 4T21KB3LcPz9rJ; Fri, 29 Dec 2023 23:09:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BTN92Zn075818; Fri, 29 Dec 2023 23:09:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BTN92WE075815; Fri, 29 Dec 2023 23:09:02 GMT (envelope-from git) Date: Fri, 29 Dec 2023 23:09:02 GMT Message-Id: <202312292309.3BTN92WE075815@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: f27c8ff817a6 - stable/14 - x86: Rename {stop,start}_emulating to fpu_{enable,disable} 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/14 X-Git-Reftype: branch X-Git-Commit: f27c8ff817a6f6b00ba37a6794e5b9f5d8db31b1 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f27c8ff817a6f6b00ba37a6794e5b9f5d8db31b1 commit f27c8ff817a6f6b00ba37a6794e5b9f5d8db31b1 Author: John Baldwin AuthorDate: 2023-10-11 21:32:06 +0000 Commit: John Baldwin CommitDate: 2023-12-29 21:49:42 +0000 x86: Rename {stop,start}_emulating to fpu_{enable,disable} While here, centralize the macros in . Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D42135 (cherry picked from commit cc1cb9ea0c5607931fa9b7ecf786468d38fb8491) --- sys/amd64/amd64/fpu.c | 31 ++++++++++++++----------------- sys/amd64/vmm/vmm.c | 15 ++++++--------- sys/i386/i386/npx.c | 35 ++++++++++++++++------------------- sys/x86/include/fpu.h | 9 +++++++++ 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index c5b84d035d91..3432e62bf7f8 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -142,9 +142,6 @@ xsaveopt64(char *addr, uint64_t mask) "memory"); } -#define start_emulating() load_cr0(rcr0() | CR0_TS) -#define stop_emulating() clts() - CTASSERT(sizeof(struct savefpu) == 512); CTASSERT(sizeof(struct xstate_hdr) == 64); CTASSERT(sizeof(struct savefpu_ymm) == 832); @@ -263,7 +260,7 @@ fpususpend(void *addr) u_long cr0; cr0 = rcr0(); - stop_emulating(); + fpu_enable(); fpusave(addr); load_cr0(cr0); } @@ -274,7 +271,7 @@ fpuresume(void *addr) u_long cr0; cr0 = rcr0(); - stop_emulating(); + fpu_enable(); fninit(); if (use_xsave) load_xcr(XCR0, xsave_mask); @@ -393,13 +390,13 @@ fpuinit(void) * It is too early for critical_enter() to work on AP. */ saveintr = intr_disable(); - stop_emulating(); + fpu_enable(); fninit(); control = __INITIAL_FPUCW__; fldcw(control); mxcsr = __INITIAL_MXCSR__; ldmxcsr(mxcsr); - start_emulating(); + fpu_disable(); intr_restore(saveintr); TSEXIT(); } @@ -430,7 +427,7 @@ fpuinitstate(void *arg __unused) cpu_thread_alloc(&thread0); saveintr = intr_disable(); - stop_emulating(); + fpu_enable(); fpusave_fxsave(fpu_initialstate); if (fpu_initialstate->sv_env.en_mxcsr_mask) @@ -473,7 +470,7 @@ fpuinitstate(void *arg __unused) } } - start_emulating(); + fpu_disable(); intr_restore(saveintr); } /* EFIRT needs this to be initialized before we can enter our EFI environment */ @@ -488,9 +485,9 @@ fpuexit(struct thread *td) critical_enter(); if (curthread == PCPU_GET(fpcurthread)) { - stop_emulating(); + fpu_enable(); fpusave(curpcb->pcb_save); - start_emulating(); + fpu_disable(); PCPU_SET(fpcurthread, NULL); } critical_exit(); @@ -741,7 +738,7 @@ restore_fpu_curthread(struct thread *td) */ PCPU_SET(fpcurthread, td); - stop_emulating(); + fpu_enable(); fpu_clean_state(); pcb = td->td_pcb; @@ -803,7 +800,7 @@ fpudna(void) * regardless of the eager/lazy FPU context switch * mode. */ - stop_emulating(); + fpu_enable(); } else { if (__predict_false(PCPU_GET(fpcurthread) != NULL)) { panic( @@ -823,7 +820,7 @@ fpu_activate_sw(struct thread *td) if ((td->td_pflags & TDP_KTHREAD) != 0 || !PCB_USER_FPU(td->td_pcb)) { PCPU_SET(fpcurthread, NULL); - start_emulating(); + fpu_disable(); } else if (PCPU_GET(fpcurthread) != td) { restore_fpu_curthread(td); } @@ -839,7 +836,7 @@ fpudrop(void) CRITICAL_ASSERT(td); PCPU_SET(fpcurthread, NULL); clear_pcb_flags(td->td_pcb, PCB_FPUINITDONE); - start_emulating(); + fpu_disable(); } /* @@ -1139,7 +1136,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags) if ((flags & FPU_KERN_NOCTX) != 0) { critical_enter(); - stop_emulating(); + fpu_enable(); if (curthread == PCPU_GET(fpcurthread)) { fpusave(curpcb->pcb_save); PCPU_SET(fpcurthread, NULL); @@ -1190,7 +1187,7 @@ fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx) CRITICAL_ASSERT(td); clear_pcb_flags(pcb, PCB_FPUNOSAVE | PCB_FPUINITDONE); - start_emulating(); + fpu_disable(); } else { KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) != 0, ("leaving not inuse ctx")); diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index d44adc86252d..74fa83ea18d9 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -256,9 +256,6 @@ DEFINE_VMMOPS_IFUNC(int, vcpu_snapshot, (void *vcpui, DEFINE_VMMOPS_IFUNC(int, restore_tsc, (void *vcpui, uint64_t now)) #endif -#define fpu_start_emulating() load_cr0(rcr0() | CR0_TS) -#define fpu_stop_emulating() clts() - SDT_PROVIDER_DEFINE(vmm); static MALLOC_DEFINE(M_VM, "vm", "vm"); @@ -1310,7 +1307,7 @@ restore_guest_fpustate(struct vcpu *vcpu) fpuexit(curthread); /* restore guest FPU state */ - fpu_stop_emulating(); + fpu_enable(); fpurestore(vcpu->guestfpu); /* restore guest XCR0 if XSAVE is enabled in the host */ @@ -1318,10 +1315,10 @@ restore_guest_fpustate(struct vcpu *vcpu) load_xcr(0, vcpu->guest_xcr0); /* - * The FPU is now "dirty" with the guest's state so turn on emulation - * to trap any access to the FPU by the host. + * The FPU is now "dirty" with the guest's state so disable + * the FPU to trap any access by the host. */ - fpu_start_emulating(); + fpu_disable(); } static void @@ -1338,9 +1335,9 @@ save_guest_fpustate(struct vcpu *vcpu) } /* save guest FPU state */ - fpu_stop_emulating(); + fpu_enable(); fpusave(vcpu->guestfpu); - fpu_start_emulating(); + fpu_disable(); } static VMM_STAT(VCPU_IDLE_TICKS, "number of ticks vcpu was idle"); diff --git a/sys/i386/i386/npx.c b/sys/i386/i386/npx.c index 689796821d80..26def3f433f1 100644 --- a/sys/i386/i386/npx.c +++ b/sys/i386/i386/npx.c @@ -123,9 +123,6 @@ xsaveopt(char *addr, uint64_t mask) "memory"); } -#define start_emulating() load_cr0(rcr0() | CR0_TS) -#define stop_emulating() clts() - #define GET_FPU_CW(thread) \ (cpu_fxsr ? \ (thread)->td_pcb->pcb_save->sv_xmm.sv_env.en_cw : \ @@ -224,7 +221,7 @@ npx_probe(void) /* * Don't trap while we're probing. */ - stop_emulating(); + fpu_enable(); /* * Finish resetting the coprocessor, if any. If there is an error @@ -413,7 +410,7 @@ npxinit(bool bsp) * It is too early for critical_enter() to work on AP. */ saveintr = intr_disable(); - stop_emulating(); + fpu_enable(); if (cpu_fxsr) fninit(); else @@ -424,7 +421,7 @@ npxinit(bool bsp) mxcsr = __INITIAL_MXCSR__; ldmxcsr(mxcsr); } - start_emulating(); + fpu_disable(); intr_restore(saveintr); } @@ -458,7 +455,7 @@ npxinitstate(void *arg __unused) } saveintr = intr_disable(); - stop_emulating(); + fpu_enable(); if (cpu_fxsr) fpusave_fxsave(npx_initialstate); @@ -515,7 +512,7 @@ npxinitstate(void *arg __unused) } } - start_emulating(); + fpu_disable(); intr_restore(saveintr); } SYSINIT(npxinitstate, SI_SUB_CPU, SI_ORDER_ANY, npxinitstate, NULL); @@ -529,9 +526,9 @@ npxexit(struct thread *td) critical_enter(); if (curthread == PCPU_GET(fpcurthread)) { - stop_emulating(); + fpu_enable(); fpusave(curpcb->pcb_save); - start_emulating(); + fpu_disable(); PCPU_SET(fpcurthread, NULL); } critical_exit(); @@ -810,7 +807,7 @@ restore_npx_curthread(struct thread *td, struct pcb *pcb) */ PCPU_SET(fpcurthread, td); - stop_emulating(); + fpu_enable(); if (cpu_fxsr) fpu_clean_state(); @@ -863,7 +860,7 @@ npxdna(void) * regardless of the eager/lazy FPU context switch * mode. */ - stop_emulating(); + fpu_enable(); } else { if (__predict_false(PCPU_GET(fpcurthread) != NULL)) { printf( @@ -891,7 +888,7 @@ void npxsave(union savefpu *addr) { - stop_emulating(); + fpu_enable(); fpusave(addr); } @@ -902,7 +899,7 @@ npxswitch(struct thread *td, struct pcb *pcb) if (lazy_fpu_switch || (td->td_pflags & TDP_KTHREAD) != 0 || !PCB_USER_FPU(pcb)) { - start_emulating(); + fpu_disable(); PCPU_SET(fpcurthread, NULL); } else if (PCPU_GET(fpcurthread) != td) { restore_npx_curthread(td, pcb); @@ -925,7 +922,7 @@ npxsuspend(union savefpu *addr) return; } cr0 = rcr0(); - stop_emulating(); + fpu_enable(); fpusave(addr); load_cr0(cr0); } @@ -940,7 +937,7 @@ npxresume(union savefpu *addr) cr0 = rcr0(); npxinit(false); - stop_emulating(); + fpu_enable(); fpurstor(addr); load_cr0(cr0); } @@ -962,7 +959,7 @@ npxdrop(void) CRITICAL_ASSERT(td); PCPU_SET(fpcurthread, NULL); td->td_pcb->pcb_flags &= ~PCB_NPXINITDONE; - start_emulating(); + fpu_disable(); } /* @@ -1397,7 +1394,7 @@ fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags) if ((flags & FPU_KERN_NOCTX) != 0) { critical_enter(); - stop_emulating(); + fpu_enable(); if (curthread == PCPU_GET(fpcurthread)) { fpusave(curpcb->pcb_save); PCPU_SET(fpcurthread, NULL); @@ -1448,7 +1445,7 @@ fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx) CRITICAL_ASSERT(td); pcb->pcb_flags &= ~(PCB_NPXNOSAVE | PCB_NPXINITDONE); - start_emulating(); + fpu_disable(); } else { KASSERT((ctx->flags & FPU_KERN_CTX_INUSE) != 0, ("leaving not inuse ctx")); diff --git a/sys/x86/include/fpu.h b/sys/x86/include/fpu.h index e1ec6a592d21..0debf65d6fb9 100644 --- a/sys/x86/include/fpu.h +++ b/sys/x86/include/fpu.h @@ -213,4 +213,13 @@ struct savefpu_ymm { */ #define X86_XSTATE_XCR0_OFFSET 464 +#ifdef _KERNEL +/* + * CR0_MP and CR0_EM are always set. Use CR0_TS to force traps when + * FPU access is disabled. + */ +#define fpu_enable() clts() +#define fpu_disable() load_cr0(rcr0() | CR0_TS) +#endif + #endif /* !_X86_FPU_H_ */