From patchwork Sat Jun 4 11:34:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bamvor Jian Zhang X-Patchwork-Id: 630157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rMJms13txz9t80 for ; Sat, 4 Jun 2016 21:35:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=XQi0D8UU; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:cc:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=hq2GkCEymozkzVau 6LvgayHrMOrrokLrq04ZmOoY4UDTzPddZC5BEiW7OPYZmkTLi/4O8tElPkMLiH8j +u773p8RbQDrKP3ewAGOLkBmcIyuQBcI84hW16NggFoFfDMBZPbSzmCOSB7FS/SR Pzzsa6CUEb6pFBwTyYRVCny+Z3I= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:cc:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=oPx0YQOkagjQgeRyrucKgo VJ72s=; b=XQi0D8UUZlWmfP3kl3ngB3DXQ3bOvmGx7m3XTx22VNsLfQm1zKqdQq ZoUPbwO/jOcXnv5i+luAHp8hWkF9BHd9y1CeohfH5srVC0b57DKHQUFZgkXm/ppi oOZmhO8u5WVFg2hSuwkw0NuSEr6RQgpQ0t7Wj0sE4zCcjYCWjU10A= Received: (qmail 41202 invoked by alias); 4 Jun 2016 11:35:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 41189 invoked by uid 89); 4 Jun 2016 11:35:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, KAM_MANYTO, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=zhang, Zhang, H*Ad:D*huawei.com, HTo:D*lists.infradead.org X-HELO: szxga05-in.huawei.com Subject: Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext To: Yury Norov , , , , , , , , References: <1464048292-30136-1-git-send-email-ynorov@caviumnetworks.com> <1464048292-30136-22-git-send-email-ynorov@caviumnetworks.com> CC: , , , , , , , , , , , , , , "Andrew Pinski" , Andrew Pinski , Hanjun Guo , "Zhangjian (Bamvor)" From: "Zhangjian (Bamvor)" Message-ID: <5752BCC8.7080205@huawei.com> Date: Sat, 4 Jun 2016 19:34:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1464048292-30136-22-git-send-email-ynorov@caviumnetworks.com> X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.5752BCE6.0038, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 557a03b21d7f8a6874efd96c9e673120 Hi, I found an issue of unwind with the following code. The correct backtrace should be: (gdb) where #0 0x004004d0 in my_sig (sig=11) at test_force3.c:16 #1 #2 func2 (num=0) at test_force3.c:22 #3 0x00400540 in func1 (num=1) at test_force3.c:28 #4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33 Without my patch, the backtrace is: (gdb) where #0 0x00400490 in my_sig (sig=11) at test_force3.c:16 #1 #2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33 With my patch which fix the wrong frame pointer(setup_return calculate the offset of fp through ilp32_sigframe instead of sigfreame), the backtrace is: (gdb) where #0 0x00400490 in my_sig (sig=11) at test_force3.c:16 #1 #2 func1 () at test_force3.c:28 #3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33 I am not sure there is still some issue in kernel. But it seem that the gdb of ilp32 does not work correctly when unwind without framepointer. The test code is: #include #include #include #include void my_sig(int sig) { printf("sig=%d\n", sig); *(int *)0 = 0x0; } void func2() { *(int *)0 = 0x0; } void func1() { func2(); } int main(int argc, char **argv) { signal(11, my_sig); func1(); return 0; } The full patch is as follows: From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001 From: Bamvor Jian Zhang Date: Sat, 4 Jun 2016 14:30:05 +0800 Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the new fp ILP32 define its own sigframe(ilp32_sigframe) because of the difference uc_context. setup_return do not use ilp32 specific sigframe to calculate the new offset of fp which lead to wrong fp in signal handler. At this circumstance, gdb backtrace will miss one item: (gdb) where It should be: (gdb) where The test code is as follows: void my_sig(int sig) { printf("sig=%d\n", sig); *(int *)0 = 0x0; } void func2(int num) { printf("%s: %d\n", __FUNCTION__, num); *(int *)0 = 0x0; func2(num-1); } void func1(int num) { printf("%s\n", __FUNCTION__); func2(num - 1); } int main(int argc, char **argv) { signal(11, my_sig); func1(argc); return 0; } This patch fix this by passing the correct offset of fp to setup_return. Test pass on both ILP32 and LP64 in aarch64 EE. Signed-off-by: Bamvor Jian Zhang --- arch/arm64/include/asm/signal_common.h | 3 ++- arch/arm64/kernel/signal.c | 9 +++++---- arch/arm64/kernel/signal_ilp32.c | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/signal_common.h b/arch/arm64/include/asm/signal_common.h index de93c71..a5d7b63 100644 --- a/arch/arm64/include/asm/signal_common.h +++ b/arch/arm64/include/asm/signal_common.h @@ -29,6 +29,7 @@ int setup_sigcontex(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); + void __user *frame, off_t sigframe_off, off_t fp_off, + int usig); #endif /* __ASM_SIGNAL_COMMON_H */ diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 038bebe..e66a6e9 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct ksignal *ksig, } void setup_return(struct pt_regs *regs, struct k_sigaction *ka, - void __user *frame, off_t sigframe_off, int usig) + void __user *frame, off_t sigframe_off, off_t fp_off, + int usig) { __sigrestore_t sigtramp; regs->regs[0] = usig; regs->sp = (unsigned long)frame; - regs->regs[29] = regs->sp + sigframe_off + - offsetof(struct sigframe, fp); + regs->regs[29] = regs->sp + sigframe_off + fp_off; regs->pc = (unsigned long)ka->sa.sa_handler; if (ka->sa.sa_flags & SA_RESTORER) @@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, err |= setup_sigframe(&frame->sig, regs, set); if (err == 0) { setup_return(regs, &ksig->ka, frame, - offsetof(struct rt_sigframe, sig), usig); + offsetof(struct rt_sigframe, sig), + offsetof(struct sigframe, fp), 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; diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c index a8ea73e..9030f14 100644 --- a/arch/arm64/kernel/signal_ilp32.c +++ b/arch/arm64/kernel/signal_ilp32.c @@ -147,7 +147,6 @@ static struct ilp32_rt_sigframe __user *ilp32_get_sigframe(struct ksignal *ksig, 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; @@ -183,7 +182,8 @@ int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, err |= setup_ilp32_sigframe(&frame->sig, regs, set); if (err == 0) { setup_return(regs, &ksig->ka, frame, - offsetof(struct ilp32_rt_sigframe, sig), usig); + offsetof(struct ilp32_rt_sigframe, sig), + offsetof(struct ilp32_sigframe, fp), usig); regs->regs[1] = (unsigned long)&frame->info; regs->regs[2] = (unsigned long)&frame->sig.uc; }