From patchwork Wed Jan 22 14:11:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 23527 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 415DF218CB for ; Wed, 22 Jan 2014 14:11:42 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id e14sf37335681iej.4 for ; Wed, 22 Jan 2014 06:11:41 -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=wfIUPnOLBnHvHPMvtGyNoUD0tnx2AHwy9041tfujAuU=; b=F3kYYPcZD2f1FXF98ocPkJLpGl0+Ar9o/bbL0w3pjh+tgHOot4wIFU6gE4WB39j7rA cgc33nUxbTXAY0TfIziBcfDpuR5/ziWyAiL/q7oS02IkbwxapFhDuYgNwg9iQm70lVMs 1gztDDoBFKPNeJ/42H8jTUlBWqp+X/h7y5gahsmxDQB2NlYupbmDcbVvA4TMY3j00Gwl n6uP78bDj11gObwRQ4mGqaysKQIFG0oIHOrPmwwzSTJdhIjG+h96T1znS8wGHxB/riww 940yaLZQ5D+7g6ew8ncnzWKi0e3qO6uzLELCxd+y9C54kkLpg+ADDb3A7sfBh4889WOV m86A== X-Gm-Message-State: ALoCoQnhAbRH7s7uWtpF5/bZ+I8geqRMxokJpo84ODUld7vXyr/IMZGUFGhoNChWwTF1Vqm1GMij X-Received: by 10.50.124.9 with SMTP id me9mr9778741igb.4.1390399901551; Wed, 22 Jan 2014 06:11:41 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.48.165 with SMTP id m5ls66329qen.52.gmail; Wed, 22 Jan 2014 06:11:41 -0800 (PST) X-Received: by 10.58.248.198 with SMTP id yo6mr190367vec.40.1390399901446; Wed, 22 Jan 2014 06:11:41 -0800 (PST) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id x3si4617169vcn.9.2014.01.22.06.11.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Jan 2014 06:11:41 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so239278vcb.14 for ; Wed, 22 Jan 2014 06:11:41 -0800 (PST) X-Received: by 10.221.26.10 with SMTP id rk10mr1098125vcb.0.1390399901351; Wed, 22 Jan 2014 06:11:41 -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.220.174.196 with SMTP id u4csp187099vcz; Wed, 22 Jan 2014 06:11:40 -0800 (PST) X-Received: by 10.14.204.135 with SMTP id h7mr205692eeo.104.1390399900261; Wed, 22 Jan 2014 06:11:40 -0800 (PST) Received: from mail-ee0-f50.google.com (mail-ee0-f50.google.com [74.125.83.50]) by mx.google.com with ESMTPS id d8si17662643eeh.179.2014.01.22.06.11.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Jan 2014 06:11:40 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.50 is neither permitted nor denied by best guess record for domain of jean.pihet@linaro.org) client-ip=74.125.83.50; Received: by mail-ee0-f50.google.com with SMTP id d17so4883669eek.23 for ; Wed, 22 Jan 2014 06:11:39 -0800 (PST) X-Received: by 10.14.201.68 with SMTP id a44mr1779687eeo.46.1390399899796; Wed, 22 Jan 2014 06:11:39 -0800 (PST) Received: from localhost.localdomain (80.58-241-81.adsl-dyn.isp.belgacom.be. [81.241.58.80]) by mx.google.com with ESMTPSA id d43sm27572324eeo.12.2014.01.22.06.11.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 22 Jan 2014 06:11:38 -0800 (PST) From: Jean Pihet To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Arnaldo , Ingo Molnar , Jiri Olsa , Will Deacon Cc: patches@linaro.org, Jean Pihet Subject: [PATCH 3/4] ARM64: perf: add support for frame pointer unwinding in compat mode Date: Wed, 22 Jan 2014 15:11:18 +0100 Message-Id: <1390399879-5109-4-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1390399879-5109-1-git-send-email-jean.pihet@linaro.org> References: <1390399879-5109-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.220.169 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 5b1cd79..e868c72 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -1348,8 +1348,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)); /* @@ -1386,22 +1386,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); + } } /* @@ -1429,6 +1487,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); }