From owner-dev-commits-src-all@freebsd.org Fri Mar 12 17:49:26 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6BD0D57FA2E; Fri, 12 Mar 2021 17:49:26 +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 4Dxtc572Sgz4c9L; Fri, 12 Mar 2021 17:49:25 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C44C71B96D; Fri, 12 Mar 2021 17:49:25 +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 12CHnPaT066673; Fri, 12 Mar 2021 17:49:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12CHnPuc066672; Fri, 12 Mar 2021 17:49:25 GMT (envelope-from git) Date: Fri, 12 Mar 2021 17:49:25 GMT Message-Id: <202103121749.12CHnPuc066672@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: 755efb8d8fca - main - x86: Copy the FPU/XSAVE state from the creating thread to new threads. 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: 755efb8d8fcacc6607bc46469750d78497f89378 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2021 17:49:26 -0000 The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=755efb8d8fcacc6607bc46469750d78497f89378 commit 755efb8d8fcacc6607bc46469750d78497f89378 Author: John Baldwin AuthorDate: 2021-03-12 17:47:41 +0000 Commit: John Baldwin CommitDate: 2021-03-12 17:47:41 +0000 x86: Copy the FPU/XSAVE state from the creating thread to new threads. POSIX states that new threads created via pthread_create() should inherit the "floating point environment" from the creating thread. Discussed with: kib MFC after: 1 week Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D29204 --- sys/amd64/amd64/vm_machdep.c | 10 ++++++---- sys/i386/i386/vm_machdep.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/sys/amd64/amd64/vm_machdep.c b/sys/amd64/amd64/vm_machdep.c index 76f7f400dd9c..f10d0339a65a 100644 --- a/sys/amd64/amd64/vm_machdep.c +++ b/sys/amd64/amd64/vm_machdep.c @@ -564,16 +564,18 @@ cpu_copy_thread(struct thread *td, struct thread *td0) pcb2 = td->td_pcb; + /* Ensure that td0's pcb is up to date. */ + fpuexit(td0); + if (td0 == curthread) + update_pcb_bases(td0->td_pcb); + /* * Copy the upcall pcb. This loads kernel regs. * Those not loaded individually below get their default * values here. */ - if (td0 == curthread) - update_pcb_bases(td0->td_pcb); bcopy(td0->td_pcb, pcb2, sizeof(*pcb2)); - clear_pcb_flags(pcb2, PCB_FPUINITDONE | PCB_USERFPUINITDONE | - PCB_KERNFPU); + clear_pcb_flags(pcb2, PCB_KERNFPU); pcb2->pcb_save = get_pcb_user_save_pcb(pcb2); bcopy(get_pcb_user_save_td(td0), pcb2->pcb_save, cpu_max_ext_state_size); diff --git a/sys/i386/i386/vm_machdep.c b/sys/i386/i386/vm_machdep.c index d3182cb224bf..502de6e7f38f 100644 --- a/sys/i386/i386/vm_machdep.c +++ b/sys/i386/i386/vm_machdep.c @@ -428,14 +428,21 @@ cpu_copy_thread(struct thread *td, struct thread *td0) /* Point the pcb to the top of the stack. */ pcb2 = td->td_pcb; + /* Ensure that td0's pcb is up to date. */ + if (td0 == curthread) + td0->td_pcb->pcb_gs = rgs(); + critical_enter(); + if (PCPU_GET(fpcurthread) == td0) + npxsave(td0->td_pcb->pcb_save); + critical_exit(); + /* * Copy the upcall pcb. This loads kernel regs. * Those not loaded individually below get their default * values here. */ bcopy(td0->td_pcb, pcb2, sizeof(*pcb2)); - pcb2->pcb_flags &= ~(PCB_NPXINITDONE | PCB_NPXUSERINITDONE | - PCB_KERNNPX); + pcb2->pcb_flags &= ~PCB_KERNNPX; pcb2->pcb_save = get_pcb_user_save_pcb(pcb2); bcopy(get_pcb_user_save_td(td0), pcb2->pcb_save, cpu_max_ext_state_size); @@ -463,7 +470,6 @@ cpu_copy_thread(struct thread *td, struct thread *td0) pcb2->pcb_esp = (int)td->td_frame - sizeof(void *); /* trampoline arg */ pcb2->pcb_ebx = (int)td; /* trampoline arg */ pcb2->pcb_eip = (int)fork_trampoline + setidt_disp; - pcb2->pcb_gs = rgs(); /* * If we didn't copy the pcb, we'd need to do the following registers: * pcb2->pcb_cr3: cloned above.