From nobody Wed Mar 23 20:33:18 2022 X-Original-To: dev-commits-src-main@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 239AF1A29CCB; Wed, 23 Mar 2022 20:33:19 +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 4KP0Rf5SQcz4fnp; Wed, 23 Mar 2022 20:33:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648067598; 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=ne499iwcw0IftrjGYHhjIB0BgHmsa8N4Kx4VtxHfq2c=; b=Ww5WAQSf2zS95frKXSAgYdB1+kkSPiVah1SNuwiGISpIdPzMBp0Mg+SujaHcHr/4tyOIr/ NtVkXLdcHxVbRDNNwoun/+NKQRdD+BEenWgsds+4KPhSHQ1SiVeMhnIyvJtJdnYCEaQaAC Gz6+4f0sh3AKLHZDJXSAAv/gpFS3fbGiX1UP8HiVSl4FpprBccxiC6dRhPHjPBK9JzBCrG qEvFUizkruJIM117G+A2oMYXhH2taqs6W2x+MNfhPYWHO62aimA7VUd754gAi7QdwKI4yo MZapyfvEFMOWcKani77OGmYCOfZvYZOt00yRp8+vBkYatTqsePGuMo3l5jcBSg== 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 272BE268D; Wed, 23 Mar 2022 20:33:18 +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 22NKXIlH075688; Wed, 23 Mar 2022 20:33:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22NKXIEP075687; Wed, 23 Mar 2022 20:33:18 GMT (envelope-from git) Date: Wed, 23 Mar 2022 20:33:18 GMT Message-Id: <202203232033.22NKXIEP075687@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: a47fd6929fe2 - main - aarch64: Fix get_fpcontext32() to work on non-curthread. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: a47fd6929fe2008e28e3e697e449fb0904258d04 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648067598; 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=ne499iwcw0IftrjGYHhjIB0BgHmsa8N4Kx4VtxHfq2c=; b=h0CpeDJ1lKnuoKvLZJXnZQajYQFKx6CFh77ybkZtKvXYgeuQO0aDTOfeLyUqr7LQ/5y94m kjTqolSfVbFsG6qvhFWAIu+ZL112QdYTQLJishxI17Dk7+ElWMJLFeHwps2wqepEWLgbMw Q7RhFPpFBMOrVvYkJpFgMovU6xIjuvYTSaiJlf5NKXoDM93xdH06pHPuEfPrCi8sDQ1eEf 4Yy2I2PSEQFXBSRfSXiE9HvC1A8aFVcoD4LH2ZCnQmaGFDVXUKVj3aFSiTkCNL4/VpmwsP qDSCXw69u+bud1trIlfWk4v6jwfO1liMPD5TTy+i2orljIjDhlYh39fDIkonrA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648067598; a=rsa-sha256; cv=none; b=Yvd6nVYoDl3TyaJ419sqkxWG5S5UE94fWMqGmhJAYOBrBJhS336WPU3xy+D9wO91/sKyVF mWo9HGa+FTjOVLWzWLn3UvaUDpWE+TgjxRDIRwvLQw3nUo1D+R1s3QcS0WgQJOWEBeTjpX cO8qh2tucfTXMzem0NhIRxiiKhlCUWQugybaeuzM6c48VVAINXq28GMfOm56LryEdmFqf4 Du1odOXeL1fmhklaAbzkIdbXg47VDfchURaYCzDS/o+1mDJHwl23K0nbG6FkNZk0OBJjrL JwIWfnzqqgAWj8ioqmez68hj6cPNKxNHO1epvm5SWXxYfoh872RZEy6aHhTbjg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a47fd6929fe2008e28e3e697e449fb0904258d04 commit a47fd6929fe2008e28e3e697e449fb0904258d04 Author: John Baldwin AuthorDate: 2022-03-23 20:33:06 +0000 Commit: John Baldwin CommitDate: 2022-03-23 20:33:06 +0000 aarch64: Fix get_fpcontext32() to work on non-curthread. Similar to fill_fpregs(), only invoke vfp_save_state() for curthread. While here, zero the buffer if FP hasn't been started to avoid leaking kernel stack memory. Reviewed by: andrew, markj Sponsored by: University of Cambridge, Google, Inc. Differential Revision: https://reviews.freebsd.org/D34525 --- sys/arm64/arm64/freebsd32_machdep.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/sys/arm64/arm64/freebsd32_machdep.c b/sys/arm64/arm64/freebsd32_machdep.c index 98f0bf784326..c4bb515becf7 100644 --- a/sys/arm64/arm64/freebsd32_machdep.c +++ b/sys/arm64/arm64/freebsd32_machdep.c @@ -130,29 +130,33 @@ freebsd32_sysarch(struct thread *td, struct freebsd32_sysarch_args *uap) static void get_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp) { - struct pcb *curpcb; + struct pcb *pcb; int i; - critical_enter(); - curpcb = curthread->td_pcb; + KASSERT(td == curthread || TD_IS_SUSPENDED(td) || + P_SHOULDSTOP(td->td_proc), + ("not suspended thread %p", td)); + + memset(mcp, 0, sizeof(*mcp)); + pcb = td->td_pcb; - if ((curpcb->pcb_fpflags & PCB_FP_STARTED) != 0) { + if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) { /* * If we have just been running VFP instructions we will * need to save the state to memcpy it below. */ - vfp_save_state(td, curpcb); + if (td == curthread) + vfp_save_state(td, pcb); - KASSERT(curpcb->pcb_fpusaved == &curpcb->pcb_fpustate, - ("Called get_fpcontext while the kernel is using the VFP")); - KASSERT((curpcb->pcb_fpflags & ~PCB_FP_USERMASK) == 0, - ("Non-userspace FPU flags set in get_fpcontext")); + KASSERT(pcb->pcb_fpusaved == &pcb->pcb_fpustate, + ("Called get_fpcontext32 while the kernel is using the VFP")); + KASSERT((pcb->pcb_fpflags & ~PCB_FP_USERMASK) == 0, + ("Non-userspace FPU flags set in get_fpcontext32")); for (i = 0; i < 32; i++) - mcp->mcv_reg[i] = (uint64_t)curpcb->pcb_fpustate.vfp_regs[i]; - mcp->mcv_fpscr = VFP_FPSCR_FROM_SRCR(curpcb->pcb_fpustate.vfp_fpcr, - curpcb->pcb_fpustate.vfp_fpsr); + mcp->mcv_reg[i] = (uint64_t)pcb->pcb_fpustate.vfp_regs[i]; + mcp->mcv_fpscr = VFP_FPSCR_FROM_SRCR(pcb->pcb_fpustate.vfp_fpcr, + pcb->pcb_fpustate.vfp_fpsr); } - critical_exit(); } static void