From patchwork Tue Apr 5 22:08:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 8756151 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CFAEF9F3D1 for ; Tue, 5 Apr 2016 22:21:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A89192021F for ; Tue, 5 Apr 2016 22:21:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 77DF6201FA for ; Tue, 5 Apr 2016 22:21:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1anZJe-0007FQ-UQ; Tue, 05 Apr 2016 22:19:19 +0000 Received: from mail-bn1bon0069.outbound.protection.outlook.com ([157.56.111.69] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1anZDk-00005u-TV for linux-arm-kernel@lists.infradead.org; Tue, 05 Apr 2016 22:13:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=V6hQv7+SqRMlE9+gejajJDLdPiRcYKQf4Qs1oOE3uOM=; b=RwnxIR3hYEFa2lME2dggtG9Cw1c1euc9kGYR2r5DO9+CSSjFpH4wyyd4qXV1tIV2KjNr426x9yuRsgiXpCEp96vzfYR61Eos8RfRGfLhFEidgJzNOh7CTaMXsKSDkhQL8NXSUgucI0WBAuHwnmtv79VT/c1At/thMSlTiI5Rrfo= Authentication-Results: arndb.de; dkim=none (message not signed) header.d=none;arndb.de; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost (95.143.213.121) by BY2PR07MB615.namprd07.prod.outlook.com (10.141.222.150) with Microsoft SMTP Server (TLS) id 15.1.447.15; Tue, 5 Apr 2016 22:12:50 +0000 From: Yury Norov To: , , , Subject: [PATCH 21/25] arm64: signal: share lp64 signal routines to ilp32 Date: Wed, 6 Apr 2016 01:08:43 +0300 Message-ID: <1459894127-17698-22-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459894127-17698-1-git-send-email-ynorov@caviumnetworks.com> References: <1459894127-17698-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM2PR03CA0018.eurprd03.prod.outlook.com (10.160.207.28) To BY2PR07MB615.namprd07.prod.outlook.com (10.141.222.150) X-MS-Office365-Filtering-Correlation-Id: 238da9c3-95ca-457a-5ed5-08d35d9f6d82 X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 2:uQefOznhTTZ0W8u7rsi3wSxNqTpsAC8EXK+ejewb2d7zoXYdBh7zuU4jMEUhiCI8qCKgcsE+9RnAsQi5ZvqyG202eAmu9LvCaX22kdf2aYgDl8z356pSjXZQrpX/LQLyd3Dw1IRe4pVeYjP2m4mcjF6TDojPOEmBOOJjV1Isj8lpzFINQvCdW8Fs2hR4W7ul; 3:9WXrVXwlCyC9nOwSGdROF4myrA7f0kwwCegjcRN/v2u8vraBU0BeoPW1ldCyC+FZMeCkTd3+VuxN6q8WFYERRaoLmaLtsC5Dh8FCVY5xfIJHVP8sA91HB3ranWvZLBJf; 25:IQZnJxU52b2N3zOwVe2BAi1Zdg41yXcMVHBZxf//ona/OrosLLek29It3MIoAklEfxZHzNKtNk7LreBlrJcXrspMyJkHlJMKQoAblraQP1ZC1Flb45D4ShywIAg2IpeBbiOtRWwj3tLQ0SZil0j0+lYnlNsepBqwv8upgXwxK075MCKGhMcHFfFJrehkBp3XqfGp6eTxegsPCZpLHqXud/QdO9/D2JIM73PCxO6YiTrJ0pg4XIVjLmD5wCaCrjQfciWDaqiL1XH4jyEiYwbqGOH3YSLQD/28dDi/SqqsoYqm8TmUNRtoyHaJeMpLM8Dt4c7I59gHVW0gacn/QBhZbi/SArA545Cj0HCU3XHAAH0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR07MB615; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 20:OqHqAI7RxaXGQl4zA91yuMbPajRVAqDQwYfEFDvwix1mYAJwCpM+mwQPozB4CjPi6XXqxvoAxjJEbfJl2sB8wNDDG9MsvZnw6BlGBdmR2Ip4dGAj9XMnFq0efUO654briuYR6VflpO3YjCdct7J0sjMAlyJeOfDM0KdbPdf0jNhr6OvzBcq2R11PeQMQTUUpbgF3VIQKZhK/uhLIAKkGqBLIrreJtqfSdzIfRDjJ6Y5RbTxdRT8p/AzjvKi6w/jmXH4BKt8Dc9SQrcqyZzt7HtQFVxLJjvVdYflIEvmNY2xMyR/UXR8yY5DSjuW7L4zunQuUisbu4Z2PqKc0tqMTxFqaGe72aSrabOSkx2V+qHqltLneAINhM090GxJsD2mGVUTxakH9+fc4uI1xObOjqBMDCE4JogiEvIGCqs46Z8p2AdYsGQ84XileTdy6aozRlP/d3XlGE+b/jqBn4/hmkp1r0RUM//eCrvmQrCNsiuzqXYLZW53v++YTmTYiW5xgGjoQ4DkRhIUCQWeRh7xprHBWYBlUC0itwvZKr9L5HeinmxLlxo3jt40dnykzZd9fxWXm1w0Xh5gxCuEeTA5kIcMOOEJLl61j4Ag0NdqLFzQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BY2PR07MB615; BCL:0; PCL:0; RULEID:; SRVR:BY2PR07MB615; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 4:vbnzdL/74ryE4J7pi5ZfQxjgbro+3J6QphpdtvQiTvvdKfs+0/CjPYYYJk8RQop379AruWHfM0IuzsoLvMCBdMk0wh3nRobjGmVtViN1FoEpQPZy3GvCcsfrddsDWBd+pyYRbN9gO/M4DvArpHvqujhTSS6MnOxtlxYeDq3/NkjOcrjvpgQ5gDH5Ob/DW5NYmhks3nmWdEqRn1ORoQ/8wzW93L/KOUA52SJo1MEBnReHre0flnq1JR4r83uhMKY6Eal+sN/RMvJEJ5hO7hfpd819EzFm3T6gS1peyQA9DEZU6GGDnprv/oFWAMnyzG3ztD9GlssIynyPWaa6wGxgYPqevLBk2ZGxB82abDqAWKoNOrDwkzDeF5n8zT1uEIqA X-Forefront-PRVS: 0903DD1D85 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(48376002)(66066001)(47776003)(42186005)(33646002)(77096005)(3846002)(15975445007)(1096002)(6116002)(19580395003)(19580405001)(36756003)(5001770100001)(2201001)(189998001)(2950100001)(50466002)(76506005)(50226001)(92566002)(76176999)(50986999)(5008740100001)(229853001)(5003940100001)(4326007)(81166005)(5004730100002)(586003)(2906002)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR07MB615; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR07MB615; 23:VoEBJjqracrppkSR948Pz2TFNX3/YTtIFjdbB51TcR?= =?us-ascii?Q?N1oYppPm4Vdv/FmKDIOCo3M4YZi+350oGkt9RcPZ8Z6VkuhXlbJzHYVv02Uh?= =?us-ascii?Q?AnlMZ1hu3UeAZbmFeVfgx7OTAZWAOFmWIPkyGoN9TajqcXAtAVUyufMSDnR+?= =?us-ascii?Q?w0ERtoYhEr5MelZUFSQ9raUzEAEexM3SPzhQwVBwGDCi0scAJUxdqB9aH3Eb?= =?us-ascii?Q?XXwWWXT67AoYdejhpb+k2dNuN1Y1LmlIstOpFFHUs6isbuTJvT4EHO80JrNo?= =?us-ascii?Q?JPJoweGdbytXKy/ll08QSrn9X9PgK0qWTDELgzt6Z/QsCrsrgheI+9Ji0UW5?= =?us-ascii?Q?u73AqEL35XeHlxsi6b8V8ldHDDvftEcTQWIsRr5OBq8TGbICSouF6kqygU0r?= =?us-ascii?Q?rshCnHztyvNztKxIXwJkHHjiFceBgJbx92FEdNar4Z1ewpNMCvJczfo4zfSy?= =?us-ascii?Q?2TcLmQTiwtQokXzg6LEmnjt/qc6B3Yu25IMLP1GzNxkDl6vmywIkizFogISZ?= =?us-ascii?Q?a6YyO3yRl1coaCxgk6OLWfRw1Gii/e2niuyidMbQLEo5ygl1RWLfDboXpE6B?= =?us-ascii?Q?FnEmcEsO3uUOb2wX6CGHMqj7q1w7vlEtY2OPi11rJtyhbUcw1WFltMsOQliw?= =?us-ascii?Q?8onc85qLt+l7Ahc6xtNJdjrqvtDk97p8+JkLIfd56zVaD7axSLm78hMMjfa2?= =?us-ascii?Q?FcIFlolemrwWLFfYfAR4s3NFToRud1i3ItDvrFxGs2b/2sD78LbuWQOMPL1f?= =?us-ascii?Q?dXpKmOcruVN5OxFrs6qtEyPrx5aJJip9BMqDQnMHRbEAIqhpHJ+zYj/GqIc3?= =?us-ascii?Q?qvAWkGQyGsGPp5i0W7diKLXUn0xLsMu3NADsH5mFyg5HTVkql/yUKhNFsygA?= =?us-ascii?Q?UU6mLKI/ZJnv7zT4vp5wIND4aBRyKzq8dabC6AfhihlyvihzqTyPxp8qLtcJ?= =?us-ascii?Q?uRQM/wu4+9ZiYDWtj/p1IQJOAloy4g4qSI6eyp1ew4a98/QS91hW4SVqn8e4?= =?us-ascii?Q?U=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 5:omoQBWRBjPKg3bP4EowOGr3BybKpJneZamQEnX15yUCnBJ1iRorJ56ck3xRPMQU1lzI6q9W8u+98JpIHAPsm1ne0EN07E43APSoy+iL/CqX8YCG6fpD6CUMkivletggF0AEdX1X3kqmXpnJ6z6I+vA==; 24:SskcgCHSQng+zZpquqBzweVUE8C1ZqeQQuyEAvPuMGtKHuGGbWBiP8yIj5YdqicPdHIsR/z7BIRkUgykaLT+UU9AMz4HaJzdFr2wOGQWo1w= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2016 22:12:50.3753 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB615 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160405_151314_300774_106DBF1B X-CRM114-Status: GOOD ( 16.92 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, pinskia@gmail.com, Prasun.Kapoor@caviumnetworks.com, schwab@suse.de, broonie@kernel.org, linux-doc@vger.kernel.org, heiko.carstens@de.ibm.com, agraf@suse.de, klimov.linux@gmail.com, ynorov@caviumnetworks.com, bamvor.zhangjian@huawei.com, schwidefsky@de.ibm.com, Nathan_Lynch@mentor.com, joseph@codesourcery.com, christoph.muellner@theobroma-systems.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After that, it will be possible to reuse it in ilp32. Signed-off-by: Yury Norov --- arch/arm64/include/asm/signal_common.h | 33 ++++++++++++ arch/arm64/kernel/signal.c | 91 +++++++++++++++++++++------------- 2 files changed, 90 insertions(+), 34 deletions(-) create mode 100644 arch/arm64/include/asm/signal_common.h diff --git a/arch/arm64/include/asm/signal_common.h b/arch/arm64/include/asm/signal_common.h new file mode 100644 index 0000000..756ed2c --- /dev/null +++ b/arch/arm64/include/asm/signal_common.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 1995-2009 Russell King + * Copyright (C) 2012 ARM Ltd. + * Copyright (C) 2016 Cavium Networks. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __ASM_SIGNAL_COMMON_H +#define __ASM_SIGNAL_COMMON_H + +#include +#include +#include + +int preserve_fpsimd_context(struct fpsimd_context __user *ctx); +int restore_fpsimd_context(struct fpsimd_context __user *ctx); +int setup_sigcontext(struct sigcontext __user *uc_mcontext, struct pt_regs *regs); +int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf); +void setup_return(struct pt_regs *regs, struct k_sigaction *ka, + void __user *frame, off_t sigframe_off, int usig); + +#endif /* __ASM_SIGNAL_COMMON_H */ diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index be02f65..f9fbf8a 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -34,18 +34,23 @@ #include #include #include +#include + +struct sigframe { + struct ucontext uc; + u64 fp; + u64 lr; +}; /* * Do a signal return; undo the signal stack. These are aligned to 128-bit. */ struct rt_sigframe { struct siginfo info; - struct ucontext uc; - u64 fp; - u64 lr; + struct sigframe sig; }; -static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) +int preserve_fpsimd_context(struct fpsimd_context __user *ctx) { struct fpsimd_state *fpsimd = ¤t->thread.fpsimd_state; int err; @@ -65,7 +70,7 @@ static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) return err ? -EFAULT : 0; } -static int restore_fpsimd_context(struct fpsimd_context __user *ctx) +int restore_fpsimd_context(struct fpsimd_context __user *ctx) { struct fpsimd_state fpsimd; __u32 magic, size; @@ -93,22 +98,30 @@ static int restore_fpsimd_context(struct fpsimd_context __user *ctx) } static int restore_sigframe(struct pt_regs *regs, - struct rt_sigframe __user *sf) + struct sigframe __user *sf) { sigset_t set; - int i, err; - void *aux = sf->uc.uc_mcontext.__reserved; - + int err; err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); if (err == 0) set_current_blocked(&set); + err |= restore_sigcontext(regs, &sf->uc.uc_mcontext); + return err; +} + + +int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *uc_mcontext) +{ + int i, err = 0; + void *aux = uc_mcontext->__reserved; + for (i = 0; i < 31; i++) - __get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], + __get_user_error(regs->regs[i], &uc_mcontext->regs[i], err); - __get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); - __get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); - __get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); + __get_user_error(regs->sp, &uc_mcontext->sp, err); + __get_user_error(regs->pc, &uc_mcontext->pc, err); + __get_user_error(regs->pstate, &uc_mcontext->pstate, err); /* * Avoid sys_rt_sigreturn() restarting. @@ -145,10 +158,10 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) if (!access_ok(VERIFY_READ, frame, sizeof (*frame))) goto badframe; - if (restore_sigframe(regs, frame)) + if (restore_sigframe(regs, &frame->sig)) goto badframe; - if (restore_altstack(&frame->uc.uc_stack)) + if (restore_altstack(&frame->sig.uc.uc_stack)) goto badframe; return regs->regs[0]; @@ -162,27 +175,36 @@ badframe: return 0; } -static int setup_sigframe(struct rt_sigframe __user *sf, +static int setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set) { - int i, err = 0; - void *aux = sf->uc.uc_mcontext.__reserved; - struct _aarch64_ctx *end; + int err = 0; /* set up the stack frame for unwinding */ __put_user_error(regs->regs[29], &sf->fp, err); __put_user_error(regs->regs[30], &sf->lr, err); + err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); + err |= setup_sigcontext(&sf->uc.uc_mcontext, regs); + + return err; +} + +int setup_sigcontext(struct sigcontext __user *uc_mcontext, + struct pt_regs *regs) +{ + void *aux = uc_mcontext->__reserved; + struct _aarch64_ctx *end; + int i, err = 0; for (i = 0; i < 31; i++) - __put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], + __put_user_error(regs->regs[i], &uc_mcontext->regs[i], err); - __put_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); - __put_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); - __put_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); - __put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err); + __put_user_error(regs->sp, &uc_mcontext->sp, err); + __put_user_error(regs->pc, &uc_mcontext->pc, err); + __put_user_error(regs->pstate, &uc_mcontext->pstate, err); - err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); + __put_user_error(current->thread.fault_address, &uc_mcontext->fault_address, err); if (err == 0) { struct fpsimd_context *fpsimd_ctx = @@ -229,14 +251,14 @@ static struct rt_sigframe __user *get_sigframe(struct ksignal *ksig, return frame; } -static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, - void __user *frame, int usig) +void setup_return(struct pt_regs *regs, struct k_sigaction *ka, + void __user *frame, off_t sigframe_off, int usig) { __sigrestore_t sigtramp; regs->regs[0] = usig; regs->sp = (unsigned long)frame; - regs->regs[29] = regs->sp + offsetof(struct rt_sigframe, fp); + regs->regs[29] = regs->sp + sigframe_off + offsetof(struct sigframe, fp); regs->pc = (unsigned long)ka->sa.sa_handler; if (ka->sa.sa_flags & SA_RESTORER) @@ -257,17 +279,18 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, if (!frame) return 1; - __put_user_error(0, &frame->uc.uc_flags, err); - __put_user_error(NULL, &frame->uc.uc_link, err); + __put_user_error(0, &frame->sig.uc.uc_flags, err); + __put_user_error(NULL, &frame->sig.uc.uc_link, err); - err |= __save_altstack(&frame->uc.uc_stack, regs->sp); - err |= setup_sigframe(frame, regs, set); + err |= __save_altstack(&frame->sig.uc.uc_stack, regs->sp); + err |= setup_sigframe(&frame->sig, regs, set); if (err == 0) { - setup_return(regs, &ksig->ka, frame, usig); + setup_return(regs, &ksig->ka, frame, + offsetof(struct rt_sigframe, sig), usig); if (ksig->ka.sa.sa_flags & SA_SIGINFO) { err |= copy_siginfo_to_user(&frame->info, &ksig->info); regs->regs[1] = (unsigned long)&frame->info; - regs->regs[2] = (unsigned long)&frame->uc; + regs->regs[2] = (unsigned long)&frame->sig.uc; } }