From patchwork Thu Aug 10 18:27:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 109842 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2748868qge; Thu, 10 Aug 2017 11:28:09 -0700 (PDT) X-Received: by 10.84.174.67 with SMTP id q61mr14933454plb.469.1502389689283; Thu, 10 Aug 2017 11:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502389689; cv=none; d=google.com; s=arc-20160816; b=b+eBtE6rlo+1RZQkiBFm96tNxALdj08Zi75I5wIJnfF5TxCsSLmjKMlLwrNZKCxRCN R2YpLWsZ477pxDJAY8KS1Fz+fDJ73/NeV3miREOIaDjvN2Awy7G6EhpVPzEKJvq8s+ey n5MmdOj6r+PKa5U1l9XpTkeKZh14PKzEV4sMbCTaN+XbfqxxjI3r7q7NRsdp51Ak7Upl sT9MtDQAbbOOZ8DBYDUdcw6dXzfawpJsKF2Wn3QY9oU1pXOuDZM99qL0iIFHiPT1lFDx 8PyVFUVAV8DbTz/e6Jbh/npeju1WGxkMjbaPPp1s9Scg0doINdDbzcUhvzTQ8NOCCRXA Tcpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=F/2/KpGL+rw33Djh5nGOuZD0fXi2i/PObc+Um7hTSUY=; b=V8X8qws2KMvsAtNdPdGV8EUguBOOtVdaBpsoPKIG84HMlcXUdjvJc9AXmKYi6A6CB7 wD7M/Ly99+NSSxc1EUpBoao3mv9X9yQyNh7pfhZXddqwCVknB5Y2rR4lLXy4M9BDbln+ XUBKQzcn5C3S6/BLa1du/NuszYgNLwbcso4cD1XCvWVIgQEV2JVGp4FUGlWakAVT4wv/ u4DBWjkMNvwf/eUsqrboirHEsDG73Yomro3ORIjoBV+c5duZzkPMd9tbYUFhciX6nfQ4 2Jx0YmyvC6hbHf/YmpCpaSVoIsHEjuPemb5+hW/VbnSJ2JIejS+3QOgcE9r5yfOcUgko 1YTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=boJbEJPM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f84si4500974pfa.170.2017.08.10.11.28.08; Thu, 10 Aug 2017 11:28:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=boJbEJPM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753254AbdHJS2G (ORCPT + 25 others); Thu, 10 Aug 2017 14:28:06 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:37453 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753145AbdHJS1u (ORCPT ); Thu, 10 Aug 2017 14:27:50 -0400 Received: by mail-oi0-f68.google.com with SMTP id j194so1355770oib.4 for ; Thu, 10 Aug 2017 11:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=F/2/KpGL+rw33Djh5nGOuZD0fXi2i/PObc+Um7hTSUY=; b=boJbEJPMqPm/ARWZQPI9IEKcVqv2tbKfuaRQ3Px5QhPrkBqJ29WghuoHzbgnRtfojt MsMejWG5baShaNB2TdjYRyEEP+7IWu5gQanqZiec9Xa9gJ9hXcFVKDNlPptqcEyrpIaE mxrDpRFlAmnPou7NjsXDBtxoMp8ApfABMngfy3M8YhwnCsqx8XK84B4OtT9q9t0u4A5X XsLoLFqOruSnsQhhAH7eOUZghZuTOD3rjd5YAmMsAje5lRlZ2qPW0T38cHoQjc5JECLu FiDlAQa3pDFSfmQW2+2P18+fX0k6XbjSloTjLFuhdp7VVv7pMTKIFT1f4CJTlh1xJpqy Kbvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=F/2/KpGL+rw33Djh5nGOuZD0fXi2i/PObc+Um7hTSUY=; b=MN//5UZvHA/8r4U2b2T/qCmWTGXJ0CrG6777H5GIe7/4DgK4n+onptSS8AOWX0UoxL CoalXfo/+/YA5exIrw4vg3x4EoJlII+Ud8MdYYQBalZNRDkjz/yeK4mvjyHrm/IfSmmv mNmFjzV7DTyLiK8EbCbsep9AJT8dcCpMB/hVRIY1cILbr3b5v1843EseW6SkGUYcWqfI 7YjYQqK9YCNQNOB/JFA1w/KSzYlb03uVdvsXXghzlQH0eO+wrC1KbzJWld9vurrAqL0b 1PWLG2CQw1jsB9GHu5B9Z281par7Tqk4UikJepiVZYxf+p1p7bGi/Ds5mcmpsUA1U5NI H47Q== X-Gm-Message-State: AHYfb5i6D72lX1VcbM7MHMqH2xHxraIboi5OaMDiaJ/ahuw8p4auh403 ds3Datm3LA4tOg== X-Received: by 10.202.175.74 with SMTP id y71mr16122124oie.132.1502389669359; Thu, 10 Aug 2017 11:27:49 -0700 (PDT) Received: from serve.minyard.net ([47.184.154.34]) by smtp.gmail.com with ESMTPSA id k128sm8199990oih.50.2017.08.10.11.27.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Aug 2017 11:27:47 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 9BC66900; Thu, 10 Aug 2017 13:27:43 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 2A073300DFD; Thu, 10 Aug 2017 13:27:41 -0500 (CDT) From: minyard@acm.org To: linux-mips@linux-mips.org, ralf@linux-mips.org, linux-kernel@vger.kernel.org Cc: Corey Minyard Subject: [PATCH 1/4] mips: Fix issues in backtraces Date: Thu, 10 Aug 2017 13:27:37 -0500 Message-Id: <1502389660-8969-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502389660-8969-1-git-send-email-minyard@acm.org> References: <1502389660-8969-1-git-send-email-minyard@acm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard I saw two problems when doing backtraces: The compiler was putting a "fast return" at the top of some functions, before it set up the frame. The backtrace code would stop when it saw a jump instruction, so it would never get to the stack frame setup and would thus misinterpret it. To fix this, don't look for jump instructions until the frame setup has been seen. The assembly code here is: ffffffff80b885a0 : ffffffff80b885a0: c8a00003 bbit0 a1,0x0,ffffffff80b885b0 ffffffff80b885a4: 0000102d move v0,zero ffffffff80b885a8: 03e00008 jr ra ffffffff80b885ac: 00000000 nop ffffffff80b885b0: 67bdffd0 daddiu sp,sp,-48 ffffffff80b885b4: ffb00008 sd s0,8(sp) The second problem was the compiler was putting the last instruction of the frame save in the delay slot of the jump instruction. If it saved the RA in there, the backtrace could would miss it and misinterpret the frame. To fix this, make sure to process the instruction after the first jump seen. The assembly code for this is: ffffffff80806fd0 : ffffffff80806fd0: 67bdffd0 daddiu sp,sp,-48 ffffffff80806fd4: ffb30020 sd s3,32(sp) ffffffff80806fd8: 24130018 li s3,24 ffffffff80806fdc: ffb20018 sd s2,24(sp) ffffffff80806fe0: 3c12811c lui s2,0x811c ffffffff80806fe4: ffb10010 sd s1,16(sp) ffffffff80806fe8: 3c11811c lui s1,0x811c ffffffff80806fec: ffb00008 sd s0,8(sp) ffffffff80806ff0: 3c10811c lui s0,0x811c ffffffff80806ff4: 08201c03 j ffffffff8080700c ffffffff80806ff8: ffbf0028 sd ra,40(sp) Signed-off-by: Corey Minyard --- arch/mips/kernel/process.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index 5351e1f..a1d930a 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -349,6 +349,7 @@ static int get_frame_info(struct mips_frame_info *info) union mips_instruction insn, *ip, *ip_end; const unsigned int max_insns = 128; unsigned int i; + bool saw_jump = false; info->pc_offset = -1; info->frame_size = 0; @@ -370,9 +371,6 @@ static int get_frame_info(struct mips_frame_info *info) insn.word = ip->word; } - if (is_jump_ins(&insn)) - break; - if (!info->frame_size) { if (is_sp_move_ins(&insn)) { @@ -396,10 +394,28 @@ static int get_frame_info(struct mips_frame_info *info) info->frame_size = - ip->i_format.simmediate; } continue; + } else if (!saw_jump && is_jump_ins(ip)) { + /* + * If we see a jump instruction, we are finished + * with the frame save. + * + * Some functions can have a shortcut return at + * the beginning of the function, so don't start + * looking for jump instruction until we see the + * frame setup. + * + * The RA save instruction can get put into the + * delay slot of the jump instruction, so look + * at the next instruction, too. + */ + saw_jump = true; + continue; } if (info->pc_offset == -1 && is_ra_save_ins(&insn, &info->pc_offset)) break; + if (saw_jump) + break; } if (info->frame_size && info->pc_offset >= 0) /* nested */ return 0;