From nobody Sun Dec 08 13:37:47 2024 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 4Y5mJq6lzpz5ghGc; Sun, 08 Dec 2024 13:37:47 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y5mJq5NH9z4q2r; Sun, 8 Dec 2024 13:37:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733665067; 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=t7luUoRXN1WXZT2RaxjQJs2BGFNQ3R0bF1lRLVCYxys=; b=ZR4KX79gWJcJey7N48hN6/KVO0JRepcj/g6yN8bvf0dLUQ1cGMkl4lkhWqR3t0TvFj4au/ jUtOZROmhunW/JsjaBKzXGwSWWb5qah0GTFVaNorEZbKG7D8xwbDKT00jCBNoiu/ipswar ENtOGzXqb32jwkHryz+tzwQ29LMl3+YjBpOI8m3m95pClznMC9DVwfsoIFKa/fNtQu6U+n BUR6/XJTnIUV8I7B2PVjxORPmfIRn2yAzOj6AQQRgXi1kBsXQ5/UnaXyasDOhXX9xHElPD f3XgsCZUSaxPDOvw0zkCJiirm6nstsZexdzd+snxwHdKAQoJZoPgUEJrb6Xaeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733665067; 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=t7luUoRXN1WXZT2RaxjQJs2BGFNQ3R0bF1lRLVCYxys=; b=FjCMVR/lrFzWg0OYAwWUYnhqyTJS01u2zlFJe2bmAIUcNSuDCFuTUzaBSsiV4KbXXUTgn6 5poz19jgXtMZxat8mUk44t2VLxAIW3dcOn9nxNz+f8P7C34v4kzkBdkkBwIANeMBtGNw1s uMUJ4/FNmO0rnGp2zHqDMe5qGJZDUNqE5ZFGX2yQGEioXQtAz1jKWznEb+dcD5XyRpMwq2 ViX4BJPPiCIbdGaDOGgRU612q1srvmDlq1ekI2CRcxRgwS2OfG7hZSHn1VUMaIQRHgpoLK ajXFDSqt5tmn3B+unH/0+k5v/n+Mu3IwRw2saqkR7banaEK0PQWUzQP6w30IYw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733665067; a=rsa-sha256; cv=none; b=dyJ5oQtcmSiyNp15K7rYGEWYLo5UEkep8YbLZAq/G7xUG5CWMYcy2g/mfz/9rUedll8CDE +4Kijjfs9TIe4QAFmKwaSgUicK+m9dZJ+ZwCx8I8Jcug97WdIg6j8ue0s3Op/dXKe4+JSV 7BdfLjyxUOR/aalNnP+f+ptG7i3sHIIvDU1OXEBfT24lAxmZSSxFZnm2KuKqcHrmLhvD+8 lviyyAOOFZ1ETlNHHe3vp6tfgdCzbo7Jq8oXW2KbrpwdtSIeFGOkXGq2SGWOlsESYz9atp qnU0dDepBBnz96jjUsvu2gvxeVO7tSurXnDrS9jiMHuAr9ktsiXw6K2ZIHWa+w== 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 4Y5mJq4sgHzvR8; Sun, 8 Dec 2024 13:37:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4B8DblO0039221; Sun, 8 Dec 2024 13:37:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B8Dbl7d039218; Sun, 8 Dec 2024 13:37:47 GMT (envelope-from git) Date: Sun, 8 Dec 2024 13:37:47 GMT Message-Id: <202412081337.4B8Dbl7d039218@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michal Meloun Subject: git: d94ff663b6a6 - stable/14 - arm: Fix VFP state corruption during signal delivery 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mmel X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d94ff663b6a6e208af2bc27474e00d96659fcb41 Auto-Submitted: auto-generated The branch stable/14 has been updated by mmel: URL: https://cgit.FreeBSD.org/src/commit/?id=d94ff663b6a6e208af2bc27474e00d96659fcb41 commit d94ff663b6a6e208af2bc27474e00d96659fcb41 Author: Michal Meloun AuthorDate: 2024-11-26 11:08:21 +0000 Commit: Michal Meloun CommitDate: 2024-12-08 10:36:38 +0000 arm: Fix VFP state corruption during signal delivery D37419 corrupts VFP context store on signal delivery and D38696 corrupts PCB because it performs a binary copy between structures with different layouts. Revert the problematic parts of these commits to have signals delivery working. Unfortunately, there are more problems with these revisions and more fixes need to be developed. Fixes: 6926e2699ae55080f860488895a2a9aa6e6d9b4d Fixes: 4d2427f2c4451babe1bad600ae02c8a7c66031fe MFC after: 4 weeks (cherry picked from commit 3abef90c325dc9badc51cc0e195db3fd5548ff53) --- sys/arm/arm/exec_machdep.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/sys/arm/arm/exec_machdep.c b/sys/arm/arm/exec_machdep.c index 6f52e1724a5c..258526d03ff5 100644 --- a/sys/arm/arm/exec_machdep.c +++ b/sys/arm/arm/exec_machdep.c @@ -102,14 +102,19 @@ get_vfpcontext(struct thread *td, mcontext_vfp_t *vfp) P_SHOULDSTOP(td->td_proc)); pcb = td->td_pcb; - if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0 && td == curthread) { + if (td == curthread) { critical_enter(); vfp_store(&pcb->pcb_vfpstate, false); critical_exit(); } KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate, ("Called get_vfpcontext while the kernel is using the VFP")); - memcpy(vfp, &pcb->pcb_vfpstate, sizeof(*vfp)); + + memset(vfp, 0, sizeof(*vfp)); + memcpy(vfp->mcv_reg, pcb->pcb_vfpstate.reg, + sizeof(vfp->mcv_reg)); + vfp->mcv_fpscr = pcb->pcb_vfpstate.fpscr; + } /* @@ -128,7 +133,10 @@ set_vfpcontext(struct thread *td, mcontext_vfp_t *vfp) } KASSERT(pcb->pcb_vfpsaved == &pcb->pcb_vfpstate, ("Called set_vfpcontext while the kernel is using the VFP")); - memcpy(&pcb->pcb_vfpstate, vfp, sizeof(*vfp)); + memcpy(pcb->pcb_vfpstate.reg, vfp->mcv_reg, + sizeof(pcb->pcb_vfpstate.reg)); + pcb->pcb_vfpstate.fpscr = vfp->mcv_fpscr; + } #endif @@ -164,8 +172,6 @@ get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret) { struct trapframe *tf = td->td_frame; __greg_t *gr = mcp->__gregs; - mcontext_vfp_t mcontext_vfp; - int rv; if (clear_ret & GET_MC_CLEAR_RET) { gr[_REG_R0] = 0; @@ -190,19 +196,9 @@ get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret) gr[_REG_LR] = tf->tf_usr_lr; gr[_REG_PC] = tf->tf_pc; -#ifdef VFP - if (mcp->mc_vfp_size != sizeof(mcontext_vfp_t)) - return (EINVAL); - get_vfpcontext(td, &mcontext_vfp); -#else - bzero(&mcontext_vfp, sizeof(mcontext_vfp)); -#endif - - if (mcp->mc_vfp_ptr != NULL) { - rv = copyout(&mcontext_vfp, mcp->mc_vfp_ptr, sizeof(mcontext_vfp)); - if (rv != 0) - return (rv); - } + mcp->mc_vfp_size = 0; + mcp->mc_vfp_ptr = NULL; + memset(&mcp->mc_spare, 0, sizeof(mcp->mc_spare)); return (0); } @@ -316,6 +312,16 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) /* Populate the siginfo frame. */ bzero(&frame, sizeof(frame)); get_mcontext(td, &frame.sf_uc.uc_mcontext, 0); + +#ifdef VFP + get_vfpcontext(td, &frame.sf_vfp); + frame.sf_uc.uc_mcontext.mc_vfp_size = sizeof(fp->sf_vfp); + frame.sf_uc.uc_mcontext.mc_vfp_ptr = &fp->sf_vfp; +#else + frame.sf_uc.uc_mcontext.mc_vfp_size = 0; + frame.sf_uc.uc_mcontext.mc_vfp_ptr = NULL; +#endif + frame.sf_si = ksi->ksi_info; frame.sf_uc.uc_sigmask = *mask; frame.sf_uc.uc_stack = td->td_sigstk;