From patchwork Mon Dec 16 16:49:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 22527 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 130FC23FC7 for ; Mon, 16 Dec 2013 16:49:47 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id z6sf9880370yhz.3 for ; Mon, 16 Dec 2013 08:49:46 -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=jf7FK65ucEn5CFvAwR/kiAskJe9SG/ziPzrdThqmupw=; b=kg0Rxi7GQhj7YWSOkKYeX3dL0KxHCN+cI4mzvKYTLE/lzqRPkef49pdPMffFJI9V9t DFkbjtpUFO59KTOQRlPFUOAJdWZ25uY2k2m76BYHxed+G9SIkGHPN6oTkgf0lIw8IJsS B5SLsGKY0LJ2BTTNewz0bF3S+5NfIjGrzdSeKtp8u0UTTf6Nig9sgZKh52FwHt8IsYw9 ChsYom7C1/teYvFXOQFS4QMzhAY/jfjC09rnjsutQ1uNi1yWLVXvjhpeM4QGMCe8kkp1 oIqgFulO7TzgI4EfLRKhWujuU6S/5ZTS9WkGZpLEsPcx+ZNIsnvFcebbYqlKMgZM83lh qAyw== X-Gm-Message-State: ALoCoQmuCLW499CvsZRhqhTKvH2GWzznlfLm+ShBAw0N3eaXzb3oZmCXIkDjWCNCCorUfLlEf4QM X-Received: by 10.58.118.231 with SMTP id kp7mr915310veb.36.1387212586888; Mon, 16 Dec 2013 08:49:46 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.131.4 with SMTP id oi4ls2040287qeb.76.gmail; Mon, 16 Dec 2013 08:49:46 -0800 (PST) X-Received: by 10.221.16.200 with SMTP id pz8mr1103296vcb.53.1387212586778; Mon, 16 Dec 2013 08:49:46 -0800 (PST) Received: from mail-vb0-f49.google.com (mail-vb0-f49.google.com [209.85.212.49]) by mx.google.com with ESMTPS id cp3si4129535vcb.58.2013.12.16.08.49.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:49:46 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.49 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.49; Received: by mail-vb0-f49.google.com with SMTP id x11so3256936vbb.8 for ; Mon, 16 Dec 2013 08:49:46 -0800 (PST) X-Received: by 10.58.50.194 with SMTP id e2mr1074632veo.54.1387212586683; Mon, 16 Dec 2013 08:49:46 -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 u4csp2776vcz; Mon, 16 Dec 2013 08:49:46 -0800 (PST) X-Received: by 10.15.74.200 with SMTP id j48mr9770857eey.102.1387212585544; Mon, 16 Dec 2013 08:49:45 -0800 (PST) Received: from mail-ea0-f170.google.com (mail-ea0-f170.google.com [209.85.215.170]) by mx.google.com with ESMTPS id l44si143499eem.229.2013.12.16.08.49.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:49:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.170 is neither permitted nor denied by best guess record for domain of jean.pihet@linaro.org) client-ip=209.85.215.170; Received: by mail-ea0-f170.google.com with SMTP id k10so2380254eaj.29 for ; Mon, 16 Dec 2013 08:49:44 -0800 (PST) X-Received: by 10.14.105.7 with SMTP id j7mr9786416eeg.95.1387212584826; Mon, 16 Dec 2013 08:49:44 -0800 (PST) Received: from localhost.localdomain (243.102-241-81.adsl-dyn.isp.belgacom.be. [81.241.102.243]) by mx.google.com with ESMTPSA id b41sm44206937eef.16.2013.12.16.08.49.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:49:44 -0800 (PST) From: jean.pihet@linaro.org To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, Arnaldo , Will Deacon Cc: patches@linaro.org, Jiri Olsa , Ingo Molnar , Jean Pihet Subject: [PATCH 3/3] ARM64: perf: add support for frame pointer unwinding in compat mode Date: Mon, 16 Dec 2013 17:49:22 +0100 Message-Id: <52af2f28.41590e0a.0251.ffffd957@mx.google.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1387212562-8128-1-git-send-email-y> References: <1387212562-8128-1-git-send-email-y> 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.49 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: , From: Jean Pihet 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; // Is 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); }