From patchwork Sat Sep 24 11:44:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12987586 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7F81C07E9D for ; Sat, 24 Sep 2022 11:55:03 +0000 (UTC) Received: from localhost ([::1]:48916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oc3kM-0003er-6X for qemu-devel@archiver.kernel.org; Sat, 24 Sep 2022 07:55:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oc3at-0004Lo-SU for qemu-devel@nongnu.org; Sat, 24 Sep 2022 07:45:15 -0400 Received: from mout.gmx.net ([212.227.15.15]:48391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oc3an-0003Qq-1L for qemu-devel@nongnu.org; Sat, 24 Sep 2022 07:45:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1664019904; bh=ljqkKXznJzX9TgABKStdjkw7mBu4gZIwRnYEMPdc0Nk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ck2J9vX8ol5SL4sOEDcmi2dz0MjgVnUT6Htm/95nbbJSgwn4Dx/PnhZHGRu/Y8N+T 2lqVXev2p27Ot7P3JyAeLBwE+97PHm87xmhnlfL+XGFgeqy32sEEbbiH6lVdXl9vNH fmgHvaWYTHjtEt7A7FfcVpvApVFAc3pwNlcxzXvw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.155.187]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mk0Ne-1p04gS2y7M-00kMAg; Sat, 24 Sep 2022 13:45:04 +0200 From: Helge Deller To: Richard Henderson , Laurent Vivier , qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 3/7] linux-user/hppa: Add signal trampoline for hppa target Date: Sat, 24 Sep 2022 13:44:57 +0200 Message-Id: <20220924114501.21767-4-deller@gmx.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220924114501.21767-1-deller@gmx.de> References: <20220924114501.21767-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:SjGi00umzcJqHOb6307zBG9ZrpcKPI9HaJY5CHtU0YpqINJCVHi 9o2D/fPR4DuIMLP65UVo1V/ZVZ8wCGobWV1UWrKNfTaPNNRT2EPtvEGneqVX1LX/a0jbysz 0u5GMDgLV3qTUM6pKwc3zZHV4E/KRLacPVKGfEQkIwe4V3oJmBWw545kL+2IAOvbVK9yY1n Nz5Nj2el2Dz0iW+P23fQQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:DlWbEM4nQG8=:JaHedRlZpoii9TAb074rlI s6XuSHAoq7Jv2a3aAmImtLPOzYSLjgwdc/x3EK3Quy5tAGiG3nBOR+JZGTQgiKPgiMYEnLgVg t36kb4Ay3o4q2RInrFD/14SM5SdMhjpJNP8WdT6FU5rhv+DBuNlmtPU4C1iO+25lpLJBf044w cnT7BGJb6PJWuqOXwkUhYgWGvTo8wMzKPB/BZMOj0hMtE+9P15YfThszHbHYl7g7ULyimfciq 4fPZYDAY/yMypJt/5Vl5HcXtdtvYuHiew3jpO3cLCfQDalZslAsOFbxNADI/YXPVW0KTErcxG BK0nTaAXCVz8IBC9gZrImATLYQJR5ZNDnMGsmSI/CXXsP85nO4Pg3DEgR3r0RGw4ky1Sn2Ifb q1VGAYSwaPrFCT0vq90REXTs83mq9X0KDoBo+rtwKCWwmVxZwBuukv6w3WOMh204dujXdo8fV I0QGqQrzJEBSxN6NVmWeV1REhjDRNolYJ9dTEPtw9LaVW26cTtH7hPHetCBlYxDO+elyOv6RX SEuYa2GeQEMO5xmihsm7R+6oLcRd/dTlRLp2vJg3GVBOdLWglyCEjT18Iy11mXqdPD+wqBLny FXn7lEABeyPhK1x/3OuY8AIbiqYLR6tp+U94zbdMcUb92wyBbs5qzUNzvlij/R06XOGM2J+Yq Z24ugFIJ5c5IRIlJBKUJYyXzavBAfDtDMOh7eGKcCKocKmsbz5icynXr08cd9DwdBiQpp9SeR BMrFYdbkyMNbauCfyh2MQXWs691rZiUqebyZz0rOBZLl5S+p0GjEAOKPygqHZvRNvNKOzY3GZ RyYkzZ3gwe4/jsrY+2uQCxzUHX34oLz/U2uRJ7tjjtT+wY2IMWP66QWtGvDupflCmEKlOSiMn Xdvlif+sk+lNzeCM/gAXaOtHTefKPhuISHt50IUsgSUiis+Y8//jQzZMb6HnvZGfAScJ2V9jg T4QwbIY6Ja0U00rHp7l9J6vtQk0vMu7hW/S7TaC5IiAgLPBGi+B6wRrdBYGiIS1cQmDgcQNeX 0Y/4tiaMKJGtALBfzXuunWXz6S/Eq57iWr5ufPVbUA3xqc5cWMzVhE306K1wBa4Kl4PTp1Lk0 L+U1NpU+iFWdKU21BltuJlFvHjbeRbdm/dMee/mfzN+hGbj+hEyMG8gRx8DvFnw3bTjjNMO/6 puT3UZQJ/HghzQMS6eLosYh6j5 Received-SPF: pass client-ip=212.227.15.15; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In Linux kernel v5.18 the vDSO for signal trampoline was added. This code mimiks the bare minimum of this vDSO and thus avoids that the parisc emulation needs executable stacks. Signed-off-by: Helge Deller --- linux-user/hppa/signal.c | 41 +++++++++++++++++++++++++-------- linux-user/hppa/target_signal.h | 14 +---------- 2 files changed, 32 insertions(+), 23 deletions(-) -- 2.37.3 diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index 962f551c04..396e310dc9 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -41,7 +41,7 @@ struct target_ucontext { }; struct target_rt_sigframe { - abi_uint tramp[9]; + abi_uint tramp[2]; /* syscall restart return address */ target_siginfo_t info; struct target_ucontext uc; /* hidden location of upper halves of pa2.0 64-bit gregs */ @@ -101,9 +101,15 @@ static void restore_sigcontext(CPUArchState *env, struct target_sigcontext *sc) __get_user(env->cr[CR_SAR], &sc->sc_sar); } -/* No, this doesn't look right, but it's copied straight from the kernel. */ +#if TARGET_ABI_BITS == 32 +#define SIGFRAME 64 +#define FUNCTIONCALLFRAME 48 +#else +#define SIGFRAME 128 +#define FUNCTIONCALLFRAME 96 +#endif #define PARISC_RT_SIGFRAME_SIZE32 \ - ((sizeof(struct target_rt_sigframe) + 48 + 64) & -64) + ((sizeof(struct target_rt_sigframe) + FUNCTIONCALLFRAME + SIGFRAME) & -SIGFRAME) void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, @@ -118,7 +124,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, if ((ka->sa_flags & TARGET_SA_ONSTACK) && !sas_ss_flags(sp)) { sp = (ts->sigaltstack_used.ss_sp + 0x7f) & ~0x3f; } - frame_addr = QEMU_ALIGN_UP(sp, 64); + frame_addr = QEMU_ALIGN_UP(sp, SIGFRAME); sp = frame_addr + PARISC_RT_SIGFRAME_SIZE32; trace_user_setup_rt_frame(env, frame_addr); @@ -139,14 +145,9 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, setup_sigcontext(&frame->uc.tuc_mcontext, env); - __put_user(0x34190000, frame->tramp + 0); /* ldi 0,%r25 */ - __put_user(0x3414015a, frame->tramp + 1); /* ldi __NR_rt_sigreturn,%r20 */ - __put_user(0xe4008200, frame->tramp + 2); /* be,l 0x100(%sr2,%r0) */ - __put_user(0x08000240, frame->tramp + 3); /* nop */ - unlock_user_struct(frame, frame_addr, 1); - env->gr[2] = h2g(frame->tramp); + env->gr[2] = default_rt_sigreturn; env->gr[30] = sp; env->gr[26] = sig; env->gr[25] = h2g(&frame->info); @@ -197,3 +198,23 @@ long do_rt_sigreturn(CPUArchState *env) force_sig(TARGET_SIGSEGV); return -QEMU_ESIGRETURN; } + +void setup_sigtramp(abi_ulong sigtramp_page) +{ + uint32_t *tramp = lock_user(VERIFY_WRITE, sigtramp_page, 6*4, 0); + abi_ulong SIGFRAME_CONTEXT_REGS32; + assert(tramp != NULL); + + SIGFRAME_CONTEXT_REGS32 = offsetof(struct target_rt_sigframe, uc.tuc_mcontext); + SIGFRAME_CONTEXT_REGS32 -= PARISC_RT_SIGFRAME_SIZE32; + + __put_user(SIGFRAME_CONTEXT_REGS32, tramp + 0); + __put_user(0x08000240, tramp + 1); /* nop - b/c dwarf2 unwind routines */ + __put_user(0x34190000, tramp + 2); /* ldi 0, %r25 (in_syscall=0) */ + __put_user(0x3414015a, tramp + 3); /* ldi __NR_rt_sigreturn, %r20 */ + __put_user(0xe4008200, tramp + 4); /* ble 0x100(%sr2, %r0) */ + __put_user(0x08000240, tramp + 5); /* nop */ + + default_rt_sigreturn = (sigtramp_page + 8) | 3; + unlock_user(tramp, sigtramp_page, 6*4); +} diff --git a/linux-user/hppa/target_signal.h b/linux-user/hppa/target_signal.h index af6c2fce58..190bb3d653 100644 --- a/linux-user/hppa/target_signal.h +++ b/linux-user/hppa/target_signal.h @@ -70,18 +70,6 @@ typedef struct target_sigaltstack { /* mask for all SS_xxx flags */ #define TARGET_SS_FLAG_BITS TARGET_SS_AUTODISARM -/* - * We cannot use a bare sigtramp page for hppa-linux. - * - * Unlike other guests where we use the instructions at PC to validate - * an offset from SP, the hppa libgcc signal frame fallback unwinding uses - * the PC address itself to find the frame. This is due to the fact that - * the hppa grows the stack upward, and the frame is of unknown size. - * - * TODO: We should be able to use a VDSO to address this, by providing - * proper unwind info for the sigtramp code, at which point the fallback - * unwinder will not be used. - */ -#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 1 #endif /* HPPA_TARGET_SIGNAL_H */