From patchwork Thu Jan 14 17:23:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 8034651 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 42654BEEE5 for ; Thu, 14 Jan 2016 17:33:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2083B2044B for ; Thu, 14 Jan 2016 17:33:54 +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 DAC9420430 for ; Thu, 14 Jan 2016 17:33:52 +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 1aJlkp-00037e-G0; Thu, 14 Jan 2016 17:32:11 +0000 Received: from mail-bn1on0088.outbound.protection.outlook.com ([157.56.110.88] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aJlh3-0006pH-VW for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2016 17:28:54 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@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.361.13; Thu, 14 Jan 2016 17:27:55 +0000 From: Yury Norov To: , , , Subject: [PATCH v6 17/21] arm64: ilp32: introduce ilp32-specific handlers for sigframe Date: Thu, 14 Jan 2016 20:23:14 +0300 Message-ID: <1452792198-10718-18-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452792198-10718-1-git-send-email-ynorov@caviumnetworks.com> References: <1452792198-10718-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: DB5PR02CA0027.eurprd02.prod.outlook.com (25.161.237.37) To BY2PR07MB615.namprd07.prod.outlook.com (10.141.222.150) X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 2:x/JXMQg994JwJBOIwsX0NHTwCvUjtqubqjA9KMAPFPgYwGkvooBaFs56ZXSgoHXpWKCKhXJmwaK8FDoxsnMjekltie1hf+6dx7QO3BefAruk3z4nO8msDEnfxBEzEvWs2KfE38KWE7umkmEZ1mjX7g==; 3:4GbfNRlsmb3gx6bZAoiSkhrvKOyg3TAJiPGruGp2qOARnatBA7iZQ4WbhGgnTYgVShuHzsamuOHPgi74y63YGfvq4yW5PxFIKlD+KMvO1y+3zuRSsWpPm9G1jgAwVTsF; 25:xCzHzjV+zwoE94AxOWKAJPOLKvNbWQ/oJ8mAM7T30V0nIYhSDO5SRl+k09KuoE7UyZDsnTxBL5Mc/74/wm+gz+J28bE4eiTSBfy1ITXbvkQLq/qILhgxOrL8m0fQSbSLk8YDO4ddJ0aCB/D7cPm2USLF7apg515IXKK38FOc4/E7QkUHDL0EHte5/3tQVfPxYIX9hjTc4VbUO9drhsY0e+uKkEybwQff7JP6ziG/evmLzNVG6Xh9XfExRC6q7Euf X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR07MB615; X-MS-Office365-Filtering-Correlation-Id: c8ed9e04-a850-4487-4b5d-08d31d080a32 X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 20:DkXA1/pfo3pVuk7XU0cDUpQ7s4t1S6ts3i8/iInDZyv3tbNprl9gQ5n3XTuelG7tluzeGFeYErVpdyRSctKDS56n5PHEXb6DW8cuoE48fVMppy9ZYqSM2m231MVWRFyXnyLPTF4ML6vpjBmGyiOElwRt0v/Qu2CqXzxfPPXh8xj6myOHOGDZUP3Cqzs1hfuhXYXw7hRYeBzusB/5ekhTPJ4d7zCP+5I0QAUZqaLCqmQHspy0R5Thmj9fU7b7yCYS4Z3534GIfDZ9WAPNvKBJ2RsowAYzZIiXf1Q4PuGWJkXTwy1+UmS8vSMDYDCHEtvtr14zpsi9sqfg5qr+iNgHyLSHNJypt9ZFV+lJlnlPeNLfaWOKm5gDKSOvXSCjAWog9qGrk3q+jp5iWayCQ4ZVl9yAf8FpeKJLIVBTmxySOarJmEfpdPGbq8hF6hlkEH+f8Sr/vV61WMCbAG305k7kH6wYiZ1kJqogR9tc2m4dFWVvEEVSCBleAjTOxtuKVLCx3vkbf8KWcs2o/GAR9/kiIwAxtNvqpe190eLdUG7GPC6b1xUBkscFIXTsGK0doZo+fA9TUAPAChGH0srPkO7/Nvq+1kBYyCT+vBJuM4uhN4s= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(236414709691187); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001); SRVR:BY2PR07MB615; BCL:0; PCL:0; RULEID:; SRVR:BY2PR07MB615; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 4:hzjSlW5+Cwa3YOMIyDooPMTPZIhrpSAEL8es9bgqZ6Wts9MIhJR+ox0lTxju3OJgFGnSN8bvweugM8Rxd1xQD/C2KrMIePW1hUvekzTNTezFN5j3jF/YmwSMCF7l0uo2qNNdZ66zeOmVO7yxHwe2zqmx95FV0iRZPiCFi2HqL3Kl110JaEdiJ1vRJrdD8OrSOUj+Q7kjRh9QwSQlVnIKskrT4JnD6yaNrAtRhn1U/dfEcQabZW3tleVg/ewYHwXcSBnKbnAFnTCI6AWOZh5gHOXMSbYouHSGqXk6zRdm27CivJaTqet28W8fAvSI8V6YEoULx0oItJkexHM2oE3qjhwMgr68oIp7+vselUnSu3bmZhCYLNBWcmEStsXg0RGIsebz0Ca3V0QI7ZxAel4ttQHG5n3mpJTRtTkUnNUljIPgPNJ17dHBXu/RJdzrAlXB X-Forefront-PRVS: 08213D42D3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(6009001)(43544003)(189002)(199003)(76176999)(81156007)(19580405001)(15975445007)(4326007)(122386002)(40100003)(97736004)(50986999)(47776003)(6116002)(586003)(1096002)(5001770100001)(19580395003)(3846002)(2950100001)(36756003)(2906002)(5001960100002)(50226001)(5008740100001)(66066001)(189998001)(87976001)(42186005)(48376002)(50466002)(33646002)(77096005)(229853001)(101416001)(92566002)(105586002)(106356001)(5003940100001)(76506005)(2201001)(5004730100002)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR07MB615; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR07MB615; 23:r0z70xS02P2ZDAv+7IHkB6nfZJkdyUnuzhF0h8hnKa?= =?us-ascii?Q?tmFrLZHhF8lxlfBAY92WZhAi6p7mb4V8sz4Y7p7GgJaOPE0VYVt2WVIiqqtw?= =?us-ascii?Q?2r4vveglogeQwLoMftMl8pa3fvPdDMUQ9oJ2+G3TIP1kq9VtUCKYo+2kg/zy?= =?us-ascii?Q?IhUR6FnCUNC1GvunbY2B2IXBa63/DbFZOvECQ2wCZ/Yks5BxGpVlJXaShVGJ?= =?us-ascii?Q?AdD3QMcF+0IWizOTVjEB1jJDZKNT1oJ0p2vYWxTYvwcwTi+1RO65sY2CxEd+?= =?us-ascii?Q?Q0V3eQ0NdiugM3aPDrts4c1mYiKox3bjkHlDBfgTqhdZL8+JXAFmrlKS68BL?= =?us-ascii?Q?dfrVe8lDv70CIOpc6qm+GAbTnT2LwJzn4TmKWeTQGkFNmfvX7kIAsOfExATL?= =?us-ascii?Q?/gebMYZyVlOU07gZ1LAPCuaw0cnxJ5DIH5U51i7klKsOKnByOSCkHzntmoGB?= =?us-ascii?Q?2+3MHFVCCtk6fTW9fGYsfx/IUQD70rvpRV4ppbJmxycxPbRj1v9vCPgUdDsF?= =?us-ascii?Q?/OWtkiNCKkckNWzyjQ4TgiMnFEtb/1BByoIoSCupQegOWIlb8M1AeqLwiOij?= =?us-ascii?Q?cLUhRMIazj0SBocQ1rLFIbz4KXQF+gbWkyVkB5CTAPz43heCnlEq+unMoaMX?= =?us-ascii?Q?p+7nXW9nc8KnGIZM5fI3xc2IZSTh6S4j7xI6wlsHP6o9X032+ufgQ1T9xwEs?= =?us-ascii?Q?9KgfPJpIOg2so/pVILGq+Xi6NKgv7URebCahb3Y7hkpZ/n/8+b12Z7GurxG7?= =?us-ascii?Q?tpV82mjuxM+yMOGWRM/SNYPrPDhRIgv5cTiMrAQhsXkcfgO7Xenw9o+TAImr?= =?us-ascii?Q?sHkZjkeHLejmQWnhA9Q5MlSsZ9CKVLsfC/4x37CMqA9XcLLlKazdwrNYrPjy?= =?us-ascii?Q?fJE/RwEYeh/z77U2jTr86ZeOrXR+BEqsgvp2Cr6c1IvrNi7DjtwWo2wJVhKj?= =?us-ascii?Q?tdbkufHtKH9xVZSrskyY3OrDwSkZ7UhpmiWoAXY8aTFkQXkAQf89Smfg0SBw?= =?us-ascii?Q?pD7PQSaJRQVNPzXn8xeooUzfs70EQj9pdvAVnOCf/diBc3ZswYjpoM/acGdX?= =?us-ascii?Q?ECjykWZUEumzA5naCE5Z3+T4h1HYYHBgyjxDpuoVPe2MNrkiqY54en/5l1ew?= =?us-ascii?Q?JEoXSUuilpwtQhyfbEd+v/3SJEvxTVxkn9bioHy/vW8o9IwivBboROapv0co?= =?us-ascii?Q?h3zjPZwhh5fjg=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB615; 5:NJaidIXO5hgnovhdldUaIR+HW672ezxgYbooPqddV4HNM/dLs+vDhSWmHO4Fz/vomZh88OvTgg7UZUzxvHRRbZ3ATA8ObzixUOkbTpnWrmP9JJEf9/TbcFtWCoTHcui1HNEQxEnkhR3OWrQZj9i+ng==; 24:Fltg5pRFd8orb8LZMOY4KGX09xyvSlKmno/VkqdZ9wccMSoMdnNQPBPWpETqO0MIFQLIJWweYg4E3YB6B3dWJbUDjg1YFVduBkdtBFSApSc= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2016 17:27:55.2071 (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-20160114_092819_002472_4EF3B01D X-CRM114-Status: GOOD ( 17.78 ) 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: pinskia@gmail.com, Prasun.Kapoor@caviumnetworks.com, schwab@suse.de, broonie@kernel.org, heiko.carstens@de.ibm.com, agraf@suse.de, klimov.linux@gmail.com, ynorov@caviumnetworks.com, jan.dakinevich@gmail.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=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 ILP32 uses AARCH32 compat structures and syscall handlers for signals. But ILP32 struct rt_sigframe differs from both LP64 and AARCH32. So some specific mechanism is needed to take care of it. Signed-off-by: Yury Norov --- arch/arm64/include/asm/signal_ilp32.h | 34 +++++++++ arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/entry_ilp32.S | 23 ++++++ arch/arm64/kernel/signal.c | 3 + arch/arm64/kernel/signal_ilp32.c | 128 ++++++++++++++++++++++++++++++++++ arch/arm64/kernel/sys_ilp32.c | 3 + 6 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/signal_ilp32.h create mode 100644 arch/arm64/kernel/entry_ilp32.S create mode 100644 arch/arm64/kernel/signal_ilp32.c diff --git a/arch/arm64/include/asm/signal_ilp32.h b/arch/arm64/include/asm/signal_ilp32.h new file mode 100644 index 0000000..30eff23 --- /dev/null +++ b/arch/arm64/include/asm/signal_ilp32.h @@ -0,0 +1,34 @@ +/* + * 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_ILP32_H +#define __ASM_SIGNAL_ILP32_H + +#ifdef CONFIG_ARM64_ILP32 + +#include + +int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, + struct pt_regs *regs); + +#else + +static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, + struct pt_regs *regs) +{ + return -ENOSYS; +} + +#endif /* CONFIG_ARM64_ILP32 */ + +#endif /* __ASM_SIGNAL_ILP32_H */ diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 4981933..c846626 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -28,7 +28,8 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE arm64-obj-$(CONFIG_AARCH32_EL0) += sys32.o kuser32.o signal32.o \ sys_compat.o entry32.o \ ../../arm/kernel/opcodes.o binfmt_elf32.o -arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o sys_ilp32.o +arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o sys_ilp32.o \ + signal_ilp32.o entry_ilp32.o arm64-obj-$(CONFIG_COMPAT) += signal32_common.o arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o diff --git a/arch/arm64/kernel/entry_ilp32.S b/arch/arm64/kernel/entry_ilp32.S new file mode 100644 index 0000000..5063172 --- /dev/null +++ b/arch/arm64/kernel/entry_ilp32.S @@ -0,0 +1,23 @@ +/* + * ILP32 system call wrappers + * + * 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 . + */ + +#include + +ENTRY(ilp32_sys_rt_sigreturn_wrapper) + mov x0, sp + b ilp32_sys_rt_sigreturn +ENDPROC(ilp32_sys_rt_sigreturn_wrapper) + diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index a742a61..f8d4c92 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -35,6 +35,7 @@ #include #include #include +#include /* * Do a signal return; undo the signal stack. These are aligned to 128-bit. @@ -300,6 +301,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) ret = compat_setup_rt_frame(usig, ksig, oldset, regs); else ret = compat_setup_frame(usig, ksig, oldset, regs); + } else if (is_ilp32_compat_task()) { + ret = ilp32_setup_rt_frame(usig, ksig, oldset, regs); } else { ret = setup_rt_frame(usig, ksig, oldset, regs); } diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c new file mode 100644 index 0000000..b635a21 --- /dev/null +++ b/arch/arm64/kernel/signal_ilp32.c @@ -0,0 +1,128 @@ +/* + * Based on arch/arm/kernel/signal.c + * + * Copyright (C) 1995-2009 Russell King + * Copyright (C) 2012 ARM Ltd. + * Copyright (C) 2016 Cavium Networks. + * Yury Norov + * + * 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 . + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +struct ilp32_rt_sigframe { + struct compat_siginfo info; + struct sigframe sig; +}; + +asmlinkage int ilp32_sys_rt_sigreturn(struct pt_regs *regs) +{ + struct ilp32_rt_sigframe __user *frame; + + /* Always make any pending restarted system calls return -EINTR */ + current->restart_block.fn = do_no_restart_syscall; + + /* + * Since we stacked the signal on a 128-bit boundary, + * then 'sp' should be word aligned here. If it's + * not, then the user is trying to mess with us. + */ + if (regs->sp & 15) + goto badframe; + + frame = (struct ilp32_rt_sigframe __user *)regs->sp; + + if (!access_ok(VERIFY_READ, frame, sizeof (*frame))) + goto badframe; + + if (restore_sigframe(regs, &frame->sig)) + goto badframe; + + if (restore_altstack(&frame->sig.uc.uc_stack)) + goto badframe; + + return regs->regs[0]; + +badframe: + if (show_unhandled_signals) + pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n", + current->comm, task_pid_nr(current), __func__, + regs->pc, regs->compat_sp); + force_sig(SIGSEGV, current); + return 0; +} + +static struct ilp32_rt_sigframe __user *ilp32_get_sigframe(struct ksignal *ksig, + struct pt_regs *regs) +{ + unsigned long sp, sp_top; + struct ilp32_rt_sigframe __user *frame; + + sp = sp_top = sigsp(regs->sp, ksig); + + sp = (sp - sizeof(struct ilp32_rt_sigframe)) & ~15; + frame = (struct ilp32_rt_sigframe __user *)sp; + + /* + * Check that we can actually write to the signal frame. + */ + if (!access_ok(VERIFY_WRITE, frame, sp_top - sp)) + frame = NULL; + + return frame; +} + +/* + * ILP32 signal handling routines called from signal.c + */ +int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, + sigset_t *set, struct pt_regs *regs) +{ + struct ilp32_rt_sigframe __user *frame; + int err = 0; + + frame = ilp32_get_sigframe(ksig, regs); + + if (!frame) + return 1; + + __put_user_error(0, &frame->sig.uc.uc_flags, err); + __put_user_error(NULL, &frame->sig.uc.uc_link, err); + + 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, + offsetof(struct ilp32_rt_sigframe, sig), usig); + if (ksig->ka.sa.sa_flags & SA_SIGINFO) { + err |= copy_siginfo_to_user32(&frame->info, &ksig->info); + regs->regs[1] = (unsigned long)&frame->info; + regs->regs[2] = (unsigned long)&frame->sig.uc; + } + } + + return err; +} + diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c index 0659b89..bed308c 100644 --- a/arch/arm64/kernel/sys_ilp32.c +++ b/arch/arm64/kernel/sys_ilp32.c @@ -43,6 +43,9 @@ #define sys_llseek sys_lseek #define sys_mmap2 sys_mmap +asmlinkage long ilp32_sys_rt_sigreturn_wrapper(void); +#define compat_sys_rt_sigreturn ilp32_sys_rt_sigreturn_wrapper + #include #undef __SYSCALL