From patchwork Mon Dec 30 16:25:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 22814 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 22BCC218FF for ; Mon, 30 Dec 2013 16:25:52 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id i4sf58323545oah.10 for ; Mon, 30 Dec 2013 08:25:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=uNM5ZOacPGaVpB8Iyq/kpQ7b9QmRTwWCwAFAoq/m2Wg=; b=HcM4cV8Li3weP/8+HfvumRA8/dlhtQVKN04vR1AhVs7GMuFVievrjocvemqSt7r7sX ws/pjRlJH4oesjI2U0Po7LXSxGNXUHyqQBsNpnD0HQdid+H74xCk08KR3Gm/tD034brJ XDkwkQa6KAl3BUQ3vFkRJnf1NGgpUI/R4t4/S6TvDnUzLi4xfGI2mBcNJ8ZmoLdFvwcO g5s2SRhWP0IS4HL2LzrES2dGw+kO48DuX/ZLHUnnlsO0hmW6ZASiUA+j53a4adtR7m6x PiI1Iz9U+XcLUGRohzJnEES4nCLNQyV+BGapAur3PAnecyeC4AFBBd5uoQ7BtPfFLTlI wtwg== X-Gm-Message-State: ALoCoQkUIPFFxHiI4FOcwZMbs0laBYfPowKyXP4NJ7LrX+B+EyWfROlTAmyAi7ZxsfHRc703yFCL X-Received: by 10.42.122.140 with SMTP id n12mr14421941icr.25.1388420751246; Mon, 30 Dec 2013 08:25:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.127.175 with SMTP id nh15ls3720919qeb.9.gmail; Mon, 30 Dec 2013 08:25:51 -0800 (PST) X-Received: by 10.220.193.70 with SMTP id dt6mr3381313vcb.17.1388420751136; Mon, 30 Dec 2013 08:25:51 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id vq3si17366373veb.141.2013.12.30.08.25.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Dec 2013 08:25:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.54; Received: by mail-vb0-f54.google.com with SMTP id g10so5989916vbg.13 for ; Mon, 30 Dec 2013 08:25:51 -0800 (PST) X-Received: by 10.52.240.201 with SMTP id wc9mr2477370vdc.60.1388420751043; Mon, 30 Dec 2013 08:25:51 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp616188ved; Mon, 30 Dec 2013 08:25:50 -0800 (PST) X-Received: by 10.14.184.66 with SMTP id r42mr2463291eem.86.1388420750081; Mon, 30 Dec 2013 08:25:50 -0800 (PST) Received: from mail-ee0-f42.google.com (mail-ee0-f42.google.com [74.125.83.42]) by mx.google.com with ESMTPS id p9si53258941eew.34.2013.12.30.08.25.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Dec 2013 08:25:50 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.42 is neither permitted nor denied by best guess record for domain of jean.pihet@linaro.org) client-ip=74.125.83.42; Received: by mail-ee0-f42.google.com with SMTP id e53so5185653eek.29 for ; Mon, 30 Dec 2013 08:25:49 -0800 (PST) X-Received: by 10.15.49.193 with SMTP id j41mr54847565eew.10.1388420749555; Mon, 30 Dec 2013 08:25:49 -0800 (PST) Received: from localhost.localdomain (19.48-241-81.adsl-dyn.isp.belgacom.be. [81.241.48.19]) by mx.google.com with ESMTPSA id g47sm110063155eeo.19.2013.12.30.08.25.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Dec 2013 08:25:48 -0800 (PST) From: Jean Pihet To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, Jiri Olsa , Ingo Molnar , Arnaldo , Will Deacon Cc: patches@linaro.org, Jean Pihet Subject: [PATCH 3/3] ARM64: perf: add support for frame pointer unwinding in compat mode Date: Mon, 30 Dec 2013 17:25:32 +0100 Message-Id: <1388420732-13961-4-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1388420732-13961-1-git-send-email-jean.pihet@linaro.org> References: <1388420732-13961-1-git-send-email-jean.pihet@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jean.pihet@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , When profiling a 32-bit application, user space callchain unwinding using the frame pointer is performed in compat mode. The code is taken over from the AARCH32 code and adapted to work on AARCH64. Signed-off-by: Jean Pihet --- arch/arm64/kernel/perf_event.c | 75 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 0e63c98..ac055be 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -1300,8 +1300,8 @@ early_initcall(init_hw_perf_events); * Callchain handling code. */ struct frame_tail { - struct frame_tail __user *fp; - unsigned long lr; + struct frame_tail __user *fp; + unsigned long lr; } __attribute__((packed)); /* @@ -1338,22 +1338,80 @@ user_backtrace(struct frame_tail __user *tail, return buftail.fp; } +/* + * The registers we're interested in are at the end of the variable + * length saved register structure. The fp points at the end of this + * structure so the address of this struct is: + * (struct compat_frame_tail *)(xxx->fp)-1 + * + * This code has been adapted from the ARM OProfile support. + */ +struct compat_frame_tail { + compat_uptr_t fp; /* a (struct compat_frame_tail *) in compat mode */ + u32 sp; + u32 lr; +} __attribute__((packed)); + +static struct compat_frame_tail __user * +compat_user_backtrace(struct compat_frame_tail __user *tail, + struct perf_callchain_entry *entry) +{ + struct compat_frame_tail buftail; + unsigned long err; + + /* Also check accessibility of one struct frame_tail beyond */ + if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) + return NULL; + + pagefault_disable(); + err = __copy_from_user_inatomic(&buftail, tail, sizeof(buftail)); + pagefault_enable(); + + if (err) + return NULL; + + perf_callchain_store(entry, buftail.lr); + + /* + * Frame pointers should strictly progress back up the stack + * (towards higher addresses). + */ + if (tail + 1 >= (struct compat_frame_tail __user *) + compat_ptr(buftail.fp)) + return NULL; + + return (struct compat_frame_tail __user *)compat_ptr(buftail.fp) - 1; +} + void perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs) { - struct frame_tail __user *tail; - if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { /* We don't support guest os callchain now */ return; } perf_callchain_store(entry, regs->pc); - tail = (struct frame_tail __user *)regs->regs[29]; - while (entry->nr < PERF_MAX_STACK_DEPTH && - tail && !((unsigned long)tail & 0xf)) - tail = user_backtrace(tail, entry); + if (!compat_user_mode(regs)) { + /* AARCH64 mode */ + struct frame_tail __user *tail; + + tail = (struct frame_tail __user *)regs->regs[29]; + + while (entry->nr < PERF_MAX_STACK_DEPTH && + tail && !((unsigned long)tail & 0xf)) + tail = user_backtrace(tail, entry); + } else { + /* AARCH32 compat mode */ + struct compat_frame_tail __user *tail; + + tail = (struct compat_frame_tail __user *)regs->compat_fp - 1; + + while ((entry->nr < PERF_MAX_STACK_DEPTH) && + tail && !((unsigned long)tail & 0x3)) + tail = compat_user_backtrace(tail, entry); + } } /* @@ -1381,6 +1439,7 @@ void perf_callchain_kernel(struct perf_callchain_entry *entry, frame.fp = regs->regs[29]; frame.sp = regs->sp; frame.pc = regs->pc; + walk_stackframe(&frame, callchain_trace, entry); }