From nobody Wed Oct 11 21:32:33 2023 X-Original-To: dev-commits-src-all@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 4S5QwK3wnvz4wkqD; Wed, 11 Oct 2023 21:32:33 +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 4S5QwK3Rbtz3RB8; Wed, 11 Oct 2023 21:32:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697059953; 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=eXXBxGBzFkZI4CZBT+F61SNOuaid6bhr/q/KlfQTGsA=; b=r4Vh85vV9eyKYfC0uoPKzg6gxn7imeROAwTdp9KG7kn/2FwfuS+R6bJSd40pVmnrhhwAM8 tjuSGZhnNtPZcAYcsNCLqx7NzCm5g0ov7YWvuI6fVZvwlfsfj9qEK8ganb9OVozxyRF4lC nKajRdo5imn60t70l9yrflpEN3MgmVWpIiv3DxeEDT5EJFWR/EBaY4nOE0tJtqQ6pEw081 WNlxu/apTzZINklFrq9e2uHqTGH49o/zkvpwfztUp4I4MimV/RHwzoFT8oGilSz14UyJeq NHcJ5ea7diVpHKOUjzkJpJaRFOHk/Td0m+BXqO8TJBV7SVR6wMY2C0EL2f0Jew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697059953; a=rsa-sha256; cv=none; b=wKJNdhBy0AFk0cwoC933TFZuNvXu72AZKkADBs8p+ZAhRFpnZtnW30dpxEIop6umuiwqTE YL1rUg77N3b8iD9raD8U6BCPhxJUZaGqAAXBnTzNNqusdsxn7Kp8iHHuMuJx4qGAj0RC1w ZGFdz8PzpKru+vWc+iOyIjPsWr3C8RHeaYhu+Mf24hAhR7R5Nr72aWANxNpxMQqhUQNuMJ HTL6JWQOkFGpwStnvmS2nZQNv790BSqwqpF2Z0Pfw5S5l3j3moiAvImY4Sc4DO/YfLDmgI DWblZtGKV2lERoGsMflvh8FziWNUew/+wnKE2Q5X2wPePEIXRudBqDKKZGjJFw== 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=1697059953; 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=eXXBxGBzFkZI4CZBT+F61SNOuaid6bhr/q/KlfQTGsA=; b=W2NbNko5cq95Wbc52Yroths9MKron+YLKMvTNwFrQt3/oNtRaXGHy1OoyNYBXQIDmpIBME 994r70ezQdV5OAPxrW5a7MKIjfU+zZmLbY8Paai90Eh4f30Dl5BnhkMx+QfvFmHwstfwg/ OSIB6s3QgRGqBuIA1CQvqVW2duZtr0A93sPGZ2m6W9cgLTPovcr1n0G7PVYpc94JDRg/a/ Gowcg7/gMcRJlhfhmfbaFWmhIlwh8wkr7QpPiz4xD0TqnKYNh+sOYm5ElldeUAE0cFXyzf xDQWbahvdK7L8vBRVXLlsyE+pkgJaXqYvXVlYHZNCe+fBWZYdwBBpDLWZkiscQ== 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 4S5QwK2Y0mzctb; Wed, 11 Oct 2023 21:32:33 +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 39BLWXGt007513; Wed, 11 Oct 2023 21:32:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39BLWXu8007510; Wed, 11 Oct 2023 21:32:33 GMT (envelope-from git) Date: Wed, 11 Oct 2023 21:32:33 GMT Message-Id: <202310112132.39BLWXu8007510@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: cc1cb9ea0c56 - main - x86: Rename {stop,start}_emulating to fpu_{enable,disable} List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: cc1cb9ea0c5607931fa9b7ecf786468d38fb8491 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=cc1cb9ea0c5607931fa9b7ecf786468d38fb8491 commit cc1cb9ea0c5607931fa9b7ecf786468d38fb8491 Author: John Baldwin AuthorDate: 2023-10-11 21:32:06 +0000 Commit: John Baldwin CommitDate: 2023-10-11 21:32:06 +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 --- 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 bf5173d9d592..64ba16cc8969 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"); @@ -1291,7 +1288,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 */ @@ -1299,10 +1296,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 @@ -1319,9 +1316,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_ */