From nobody Fri Jun 17 19:37:01 2022 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 4DD1085A4D6; Fri, 17 Jun 2022 19:37: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 4LPq7168mjz3PHW; Fri, 17 Jun 2022 19:37:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494622; 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=XOq9zol+zVvJY19IqSc04qkh8kyPidaVNkebWvGWIfg=; b=Fl8Mtvdx0/yZJ2qGpCLTgtuX2Rxhf+rC2KLS63AE3EWqf15gD9nFpy1zYywU556FSzkuHT OUlZMw/CXS8masTBYstq9F5D06nsO6aV89D4C/ledmwbVsSMXBIEi1XDbSnv5RI7N6NeQ3 uE9w25SU3FrFvxhitMEoZHtK8U37UKhHfSlW7pVo50CqmwhcfJUMT6JXifUu4N0rHjmYZi /7G9xGDsAJ/LCXbyO6JtWj2cia+uKYgTZ0PKax0NiLHzN/8vJnFmWPWk8mmZZ2BZfM1cBS L5CMKwPaeAePg0Df4icg4HKKb/PmID0tFdtiNwLyupNXcAIWq5vX+JsW8nQy6A== 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 A69A225674; Fri, 17 Jun 2022 19:37:01 +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 25HJb1Vs012805; Fri, 17 Jun 2022 19:37:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJb1WC012804; Fri, 17 Jun 2022 19:37:01 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:37:01 GMT Message-Id: <202206171937.25HJb1WC012804@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 0b82c544de58 - stable/13 - linux: implement signal delivery on arm64 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0b82c544de5882a6df23167f112f2a70fb12fb26 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494622; 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=XOq9zol+zVvJY19IqSc04qkh8kyPidaVNkebWvGWIfg=; b=SmWNVvSz2L/6SRoqm352HVicXzbDl+1KY8GWaqO+VOrb0DVOH7wM118oudjrmJAnrU/we3 pJzSJA8iWk2aT+NrcUPqjunPvltlotCgiaUOFAdmQP9EyXyOFNVhOcleQ506Y2UOCQRcgf agS9ENJNxTUzXVAoZY9pBQRPJnaUHKSUCqkIQU5tmbAolpW3KsAaxUTiC7s3JRGTJcjICp xNlf4uXkCdWsbO9sr6KaL/AOq/n5qcYwLNF0WPw9DmLDP87TK2w8YbTH1QgLHRzrBqGb+g wsmkYiCANWohjKKCdeiKJ+G3Cfx/k+joZNctsjDvJQyaLs/Tf8oCfL2tZSh8Mg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494622; a=rsa-sha256; cv=none; b=l0BvZvU7HX6m2B60JSCPEb+2JtGKif0yXoPiy/kbHMxcxV2hQDhE9yZShKqPy0WaLv8cFp xFC5PjWQzXQncV78E+0KN9Nubzo5FBOjOGFTsogEvfOEJ0wrP5xjLxl4kn9BFqbrZBWclp pGjegSkq+xGxGUyLCp1XAyejCCKh84gordz/NAobrEPYFNYSBx2SA4nxPboBDHn554M8pz ypuLd19audhfjLth3+8FKvaOBPp2CI9/ppZRlfPhVkXsheaMEIb5uS218CF+h/5lO9SfYh +YssbfMrySUTraLzYxp/EayqzmZtkTfUHeQ6Ng0ho+EaBDKCD0Ta3XhevdypeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=0b82c544de5882a6df23167f112f2a70fb12fb26 commit 0b82c544de5882a6df23167f112f2a70fb12fb26 Author: Edward Tomasz Napierala AuthorDate: 2021-07-25 06:22:47 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:33:09 +0000 linux: implement signal delivery on arm64 Note that this still uses FreeBSD-style sigframe; this will be addressed later. Reviewed By: dchagin Sponsored By: EPSRC Differential Revision: https://reviews.freebsd.org/D31258 (cherry picked from commit ccc510b46340da563e21549a1a0cb99915d8d623) --- sys/arm64/linux/linux.h | 10 ++++ sys/arm64/linux/linux_locore.asm | 4 +- sys/arm64/linux/linux_sysvec.c | 98 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 106 insertions(+), 6 deletions(-) diff --git a/sys/arm64/linux/linux.h b/sys/arm64/linux/linux.h index ab3bab8264f4..7ea169b962b4 100644 --- a/sys/arm64/linux/linux.h +++ b/sys/arm64/linux/linux.h @@ -243,6 +243,16 @@ typedef struct l_siginfo { #define lsi_band _sifields._sigpoll._band #define lsi_fd _sifields._sigpoll._fd +/* + * This structure is different from the one used by Linux, + * but it doesn't matter - it's not user-accessible. We need + * it instead of the native one because of l_siginfo. + */ +struct l_sigframe { + struct l_siginfo sf_si; + ucontext_t sf_uc; +}; + union l_semun { l_int val; l_uintptr_t buf; diff --git a/sys/arm64/linux/linux_locore.asm b/sys/arm64/linux/linux_locore.asm index 24a48d74f7b5..0311c2e7e7e9 100644 --- a/sys/arm64/linux/linux_locore.asm +++ b/sys/arm64/linux/linux_locore.asm @@ -44,7 +44,9 @@ linux_platform: .text + nop /* This is what Linux calls a "Mysterious NOP". */ ENTRY(__kernel_rt_sigreturn) - brk #0 /* LINUXTODO: implement __kernel_rt_sigreturn */ + mov x8, #LINUX_SYS_linux_rt_sigreturn + svc #0 ret END(__kernel_rt_sigreturn) diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index 20a993046b0c..63438cb62ec4 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -37,12 +37,14 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -61,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -401,18 +404,103 @@ linux_exec_setregs(struct thread *td, struct image_params *imgp, int linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) { + struct l_sigframe frame; + struct trapframe *tf; + int error; + + tf = td->td_frame; + + if (copyin((void *)tf->tf_sp, &frame, sizeof(frame))) + return (EFAULT); - /* LINUXTODO: implement */ - LIN_SDT_PROBE0(sysvec, linux_rt_sigreturn, todo); - return (EDOOFUS); + error = set_mcontext(td, &frame.sf_uc.uc_mcontext); + if (error != 0) + return (error); + + /* Restore signal mask. */ + kern_sigprocmask(td, SIG_SETMASK, &frame.sf_uc.uc_sigmask, NULL, 0); + + return (EJUSTRETURN); } static void linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) { + struct thread *td; + struct proc *p; + struct trapframe *tf; + struct l_sigframe *fp, frame; + struct sigacts *psp; + int onstack, sig; + uint32_t spsr; + + td = curthread; + p = td->td_proc; + PROC_LOCK_ASSERT(p, MA_OWNED); + + sig = ksi->ksi_signo; + psp = p->p_sigacts; + mtx_assert(&psp->ps_mtx, MA_OWNED); + + tf = td->td_frame; + onstack = sigonstack(tf->tf_sp); + + CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm, + catcher, sig); + + /* Allocate and validate space for the signal handler context. */ + if ((td->td_pflags & TDP_ALTSTACK) != 0 && !onstack && + SIGISMEMBER(psp->ps_sigonstack, sig)) { + fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp + + td->td_sigstk.ss_size); +#if defined(COMPAT_43) + td->td_sigstk.ss_flags |= SS_ONSTACK; +#endif + } else { + fp = (struct l_sigframe *)td->td_frame->tf_sp; + } + + /* Make room, keeping the stack aligned */ + fp--; + fp = (struct l_sigframe *)STACKALIGN(fp); + + /* Fill in the frame to copy out */ + bzero(&frame, sizeof(frame)); + get_mcontext(td, &frame.sf_uc.uc_mcontext, 0); + spsr = frame.sf_uc.uc_mcontext.mc_gpregs.gp_spsr; + + /* Translate the signal. */ + sig = bsd_to_linux_signal(sig); + + siginfo_to_lsiginfo(&ksi->ksi_info, &frame.sf_si, sig); + frame.sf_uc.uc_sigmask = *mask; + frame.sf_uc.uc_stack = td->td_sigstk; + frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ? + (onstack ? SS_ONSTACK : 0) : SS_DISABLE; + mtx_unlock(&psp->ps_mtx); + PROC_UNLOCK(td->td_proc); + + /* Copy the sigframe out to the user's stack. */ + if (copyout(&frame, fp, sizeof(*fp)) != 0) { + /* Process has trashed its stack. Kill it. */ + CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp); + PROC_LOCK(p); + sigexit(td, SIGILL); + } + + tf->tf_x[0]= sig; + tf->tf_x[1] = (register_t)&fp->sf_si; + tf->tf_x[2] = (register_t)&fp->sf_uc; + + tf->tf_elr = (register_t)catcher; + tf->tf_sp = (register_t)fp; + tf->tf_lr = (register_t)__kernel_rt_sigreturn; + + CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_elr, + tf->tf_sp); - /* LINUXTODO: implement */ - LIN_SDT_PROBE0(sysvec, linux_rt_sendsig, todo); + PROC_LOCK(p); + mtx_lock(&psp->ps_mtx); } struct sysentvec elf_linux_sysvec = {