From patchwork Tue Apr 8 07:04:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 28022 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f200.google.com (mail-ig0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 070BE20447 for ; Tue, 8 Apr 2014 15:37:42 +0000 (UTC) Received: by mail-ig0-f200.google.com with SMTP id l13sf3276879iga.11 for ; Tue, 08 Apr 2014 08:37:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=1tVsWHj2DxvypVok/7yl6zzVp+pAL6xohaiwaEN2Suw=; b=bNfSomXDcebuXxZ5wC7s6vhEoOSP/PiVAQAARM1oaVeo5b3fY11v/g9NQO9fxUNLUY oBCacA0IR036/zVQwLJ3Aq8xenFcqw+hps3/sMomf6GbhRttL/3uHD1Q2ljcWEJY3y8N TO+m2xqtWWnVx/rsljSLOkQhHYXj6jyN3ZAzgouin1s9P+RI0z0YUJmXaCY+qx0ptBLs Hij4sUqKs7PMQ21NeVd6Bmrvuto67KME5lmGM4C6P+F8Vb1FcrE1erUJ8YqF91SW58Iu YUC8G/s/aq8U+iArwwIV7T6eWqySHgyBsv8LB/gCccSXo/BhbcG1WzqzuxBRFPGFuXsH NSxw== X-Gm-Message-State: ALoCoQkwQUUVs/4P3Jh4JtCFjF9gdcZ7X5v15WpDDYOKFl2xnMSGfC49vuKRzhooA8wcb/0ciBrZ X-Received: by 10.182.45.131 with SMTP id n3mr626253obm.20.1396971462459; Tue, 08 Apr 2014 08:37:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.27.138 with SMTP id 10ls265035qgx.52.gmail; Tue, 08 Apr 2014 08:37:42 -0700 (PDT) X-Received: by 10.220.198.197 with SMTP id ep5mr3750018vcb.21.1396971462292; Tue, 08 Apr 2014 08:37:42 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id xt10si455962veb.166.2014.04.08.08.37.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 08:37:42 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.173 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.173; Received: by mail-vc0-f173.google.com with SMTP id il7so944879vcb.32 for ; Tue, 08 Apr 2014 08:37:42 -0700 (PDT) X-Received: by 10.220.11.208 with SMTP id u16mr3730844vcu.19.1396971462201; Tue, 08 Apr 2014 08:37:42 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp255887vcv; Tue, 8 Apr 2014 08:37:41 -0700 (PDT) X-Received: by 10.194.189.116 with SMTP id gh20mr4439359wjc.41.1396971461126; Tue, 08 Apr 2014 08:37:41 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id ew1si1042892wjd.18.2014.04.08.08.37.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2014 08:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXY2C-0002x5-TQ; Tue, 08 Apr 2014 15:34:01 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXY21-0006Xc-K9; Tue, 08 Apr 2014 15:33:49 +0000 Received: from bombadil.infradead.org ([2001:1868:205::9]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXXk8-0003gg-4w for linux-arm-kernel@merlin.infradead.org; Tue, 08 Apr 2014 15:15:20 +0000 Received: from mail-pd0-f170.google.com ([209.85.192.170]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WXQ5f-0002ls-7P for linux-arm-kernel@lists.infradead.org; Tue, 08 Apr 2014 07:05:04 +0000 Received: by mail-pd0-f170.google.com with SMTP id v10so602656pde.29 for ; Tue, 08 Apr 2014 00:04:36 -0700 (PDT) X-Received: by 10.68.244.229 with SMTP id xj5mr2555840pbc.108.1396940676525; Tue, 08 Apr 2014 00:04:36 -0700 (PDT) Received: from kamensky-w530.cisco.com (128-107-239-233.cisco.com. [128.107.239.233]) by mx.google.com with ESMTPSA id tu3sm5921675pab.1.2014.04.08.00.04.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2014 00:04:35 -0700 (PDT) From: Victor Kamensky To: systemtap@sourceware.org, Dave.Martin@arm.com Subject: [PATCH] systemtap: need to use kallsyms_lookup_funcptr with arm thumb2 kernel Date: Tue, 8 Apr 2014 00:04:11 -0700 Message-Id: <1396940651-19013-2-git-send-email-victor.kamensky@linaro.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1396940651-19013-1-git-send-email-victor.kamensky@linaro.org> References: <1396940651-19013-1-git-send-email-victor.kamensky@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140408_000503_312011_4A88B945 X-CRM114-Status: GOOD ( 15.72 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.192.170 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record Cc: tixy@linaro.org, taras.kondratiuk@linaro.org, dave.long@linaro.org, linux-arm-kernel@lists.infradead.org, Victor Kamensky 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: victor.kamensky@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.173 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Thumb2 function pointer should have bit 0 set when called, even if function text is aligned with 2 or 4 bytes. Current systemtap runtime uses kallsyms_lookup_name to get function pointer, cast it, and calls it. It does not work in case of arm CONFIG_THUMB2_KERNEL. The patch add simple wrapper on top of kallsyms_lookup_name, which in case of CONFIG_THUMB2_KERNEL set bit 0 of returned function address. In all other case it just returns result of kallsyms_lookup_name call. In case if/when kernel will provide similar to kallsyms_lookup_funcptr functionality in kernel itself remove/rework this change. Signed-off-by: Victor Kamensky --- runtime/linux/kallsyms_wrapper.h | 28 ++++++++++++++++++++++++++++ runtime/linux/runtime.h | 2 ++ runtime/stp_task_work.c | 4 ++-- runtime/stp_utrace.c | 6 +++--- runtime/transport/transport.c | 12 ++++++------ 5 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 runtime/linux/kallsyms_wrapper.h diff --git a/runtime/linux/kallsyms_wrapper.h b/runtime/linux/kallsyms_wrapper.h new file mode 100644 index 0000000..9e698ab --- /dev/null +++ b/runtime/linux/kallsyms_wrapper.h @@ -0,0 +1,28 @@ +#ifndef _KALLSYMS_WRAPPER_H +#define _KALLSYMS_WRAPPER_H + +/* + * Copyright (C) 2011 Avik Sil (avik.sil at linaro.org) + * + * wrapper around kallsyms_lookup_name. Implements arch-dependent code for + * arches where the address of the start of the function body is different + * from the pointer which can be used to call the function, e.g. ARM THUMB2. + * + * Dual LGPL v2.1/GPL v2 license. +*/ + +static inline +unsigned long kallsyms_lookup_funcptr(const char *name) +{ + unsigned long addr; + + addr = kallsyms_lookup_name(name); +#ifdef CONFIG_ARM +#ifdef CONFIG_THUMB2_KERNEL + if (addr) + addr |= 1; /* set bit 0 in address for thumb mode */ +#endif +#endif + return addr; +} +#endif /* _KALLSYMS_WRAPPER_H */ diff --git a/runtime/linux/runtime.h b/runtime/linux/runtime.h index 76dbea4..0ae1ffa 100644 --- a/runtime/linux/runtime.h +++ b/runtime/linux/runtime.h @@ -190,6 +190,8 @@ static void *kallsyms_signal_wake_up; static void *kallsyms___lock_task_sighand; #endif +#include "kallsyms_wrapper.h" + #include "access_process_vm.h" #include "loc2c-runtime.h" diff --git a/runtime/stp_task_work.c b/runtime/stp_task_work.c index 93f56a5..246d648 100644 --- a/runtime/stp_task_work.c +++ b/runtime/stp_task_work.c @@ -25,12 +25,12 @@ stp_task_work_init(void) #if !defined(STAPCONF_TASK_WORK_ADD_EXPORTED) /* The task_work_add()/task_work_cancel() functions aren't * exported. Look up those function addresses. */ - kallsyms_task_work_add = (void *)kallsyms_lookup_name("task_work_add"); + kallsyms_task_work_add = (void *)kallsyms_lookup_funcptr("task_work_add"); if (kallsyms_task_work_add == NULL) { _stp_error("Can't resolve task_work_add!"); return -ENOENT; } - kallsyms_task_work_cancel = (void *)kallsyms_lookup_name("task_work_cancel"); + kallsyms_task_work_cancel = (void *)kallsyms_lookup_funcptr("task_work_cancel"); if (kallsyms_task_work_cancel == NULL) { _stp_error("Can't resolve task_work_cancel!"); return -ENOENT; diff --git a/runtime/stp_utrace.c b/runtime/stp_utrace.c index a6f363d..056f1ab 100644 --- a/runtime/stp_utrace.c +++ b/runtime/stp_utrace.c @@ -191,12 +191,12 @@ static int utrace_init(void) /* The signal_wake_up_state() function (which replaces * signal_wake_up() in newer kernels) isn't exported. Look up * that function address. */ - kallsyms_signal_wake_up_state = (void *)kallsyms_lookup_name("signal_wake_up_state"); + kallsyms_signal_wake_up_state = (void *)kallsyms_lookup_funcptr("signal_wake_up_state"); #endif #if !defined(STAPCONF_SIGNAL_WAKE_UP_EXPORTED) /* The signal_wake_up() function isn't exported. Look up that * function address. */ - kallsyms_signal_wake_up = (void *)kallsyms_lookup_name("signal_wake_up"); + kallsyms_signal_wake_up = (void *)kallsyms_lookup_funcptr("signal_wake_up"); #endif #if (!defined(STAPCONF_SIGNAL_WAKE_UP_STATE_EXPORTED) \ && !defined(STAPCONF_SIGNAL_WAKE_UP_EXPORTED)) @@ -209,7 +209,7 @@ static int utrace_init(void) #if !defined(STAPCONF___LOCK_TASK_SIGHAND_EXPORTED) /* The __lock_task_sighand() function isn't exported. Look up * that function address. */ - kallsyms___lock_task_sighand = (void *)kallsyms_lookup_name("__lock_task_sighand"); + kallsyms___lock_task_sighand = (void *)kallsyms_lookup_funcptr("__lock_task_sighand"); if (kallsyms___lock_task_sighand == NULL) { _stp_error("Can't resolve __lock_task_sighand!"); goto error; diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c index 0ddf514..bbad89e 100644 --- a/runtime/transport/transport.c +++ b/runtime/transport/transport.c @@ -352,7 +352,7 @@ static int _stp_transport_init(void) /* PR13489, missing inode-uprobes symbol-export workaround */ #if !defined(STAPCONF_TASK_USER_REGSET_VIEW_EXPORTED) && !defined(STAPCONF_UTRACE_REGSET) /* RHEL5 era utrace */ - kallsyms_task_user_regset_view = (void*) kallsyms_lookup_name ("task_user_regset_view"); + kallsyms_task_user_regset_view = (void*) kallsyms_lookup_funcptr ("task_user_regset_view"); /* There exist interesting kernel versions without task_user_regset_view(), like ARM before 3.0. For these kernels, uprobes etc. are out of the question, but plain kernel stap works fine. All we have to accomplish is have the loc2c runtime code compile. For that, it's enough @@ -363,9 +363,9 @@ static int _stp_transport_init(void) #endif #if defined(CONFIG_UPROBES) // i.e., kernel-embedded uprobes #if !defined(STAPCONF_UPROBE_REGISTER_EXPORTED) - kallsyms_uprobe_register = (void*) kallsyms_lookup_name ("uprobe_register"); + kallsyms_uprobe_register = (void*) kallsyms_lookup_funcptr ("uprobe_register"); if (kallsyms_uprobe_register == NULL) { - kallsyms_uprobe_register = (void*) kallsyms_lookup_name ("register_uprobe"); + kallsyms_uprobe_register = (void*) kallsyms_lookup_funcptr ("register_uprobe"); } if (kallsyms_uprobe_register == NULL) { printk(KERN_ERR "%s can't resolve uprobe_register!", THIS_MODULE->name); @@ -373,9 +373,9 @@ static int _stp_transport_init(void) } #endif #if !defined(STAPCONF_UPROBE_UNREGISTER_EXPORTED) - kallsyms_uprobe_unregister = (void*) kallsyms_lookup_name ("uprobe_unregister"); + kallsyms_uprobe_unregister = (void*) kallsyms_lookup_funcptr ("uprobe_unregister"); if (kallsyms_uprobe_unregister == NULL) { - kallsyms_uprobe_unregister = (void*) kallsyms_lookup_name ("unregister_uprobe"); + kallsyms_uprobe_unregister = (void*) kallsyms_lookup_funcptr ("unregister_uprobe"); } if (kallsyms_uprobe_unregister == NULL) { printk(KERN_ERR "%s can't resolve uprobe_unregister!", THIS_MODULE->name); @@ -383,7 +383,7 @@ static int _stp_transport_init(void) } #endif #if !defined(STAPCONF_UPROBE_GET_SWBP_ADDR_EXPORTED) - kallsyms_uprobe_get_swbp_addr = (void*) kallsyms_lookup_name ("uprobe_get_swbp_addr"); + kallsyms_uprobe_get_swbp_addr = (void*) kallsyms_lookup_funcptr ("uprobe_get_swbp_addr"); if (kallsyms_uprobe_get_swbp_addr == NULL) { printk(KERN_ERR "%s can't resolve uprobe_get_swbp_addr!", THIS_MODULE->name); goto err0;