From patchwork Mon Dec 16 16:54:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 3355811 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DC3EA9F32E for ; Mon, 16 Dec 2013 16:56:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AA84520204 for ; Mon, 16 Dec 2013 16:56:38 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4FA0220203 for ; Mon, 16 Dec 2013 16:56:37 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VsbSP-0005yN-SN; Mon, 16 Dec 2013 16:55:50 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VsbSF-0000FS-JT; Mon, 16 Dec 2013 16:55:39 +0000 Received: from mail-ee0-f42.google.com ([74.125.83.42]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VsbRn-0000Bx-M1 for linux-arm-kernel@lists.infradead.org; Mon, 16 Dec 2013 16:55:14 +0000 Received: by mail-ee0-f42.google.com with SMTP id e53so2377670eek.1 for ; Mon, 16 Dec 2013 08:54:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WlKGP/ZBnO18T60X1ocPoY6TLpPJCCSqWlE9KbbG4nI=; b=A+y89mej2G3zUAS7viR9AYJMN7OthN/s1SQpqnpAENUNTyHURD08rTNM0Hgecou3cm /G8mT72n8qJDk3G24cpWiKJBOTmhKv4GXwbBpEyTBDVrKysabt5ocp9xi3gdbtu7LCF+ XJqe/vowNKlS5iJ2VYkpxDyXuSGj9cA6Tv3Pz/gmZxhVB246cizIrwPQH1DBz8Rxxj+h 9KewGXGLgBK1CS4wV/a2oMXdLpXdmnW/3maQs6Bo6psExN6lq8nkqrrAQlZ27Qzjdq17 +xfK+xNcSObjwqh2MQ9dAUM88UI4xQhpsyOmTw7T7LtyAVqWGsnoQSXzojdCwRpI7MqJ B8Rg== X-Gm-Message-State: ALoCoQk6M5T9tiG5C7lZcs5UiJnHcZ0bpqAmQRMLCAc0K9KGlTFZdfHFvckMI1Cd4dYhPM8oVGUe X-Received: by 10.14.5.194 with SMTP id 42mr9899384eel.100.1387212888342; Mon, 16 Dec 2013 08:54:48 -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 4sm44259975eed.14.2013.12.16.08.54.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Dec 2013 08:54:47 -0800 (PST) From: Jean Pihet To: linux-arm-kernel@lists.infradead.org, Will Deacon Subject: [PATCH 3/3] ARM64: perf: add support for frame pointer unwinding in compat mode Date: Mon, 16 Dec 2013 17:54:33 +0100 Message-Id: <1387212873-8248-4-git-send-email-jean.pihet@linaro.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1387212873-8248-1-git-send-email-jean.pihet@linaro.org> References: <1387212873-8248-1-git-send-email-jean.pihet@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131216_115511_862086_C0B7B6F2 X-CRM114-Status: GOOD ( 15.88 ) X-Spam-Score: -2.6 (--) Cc: Jean Pihet X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); }