From patchwork Mon Sep 19 09:00:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avik Sil X-Patchwork-Id: 4177 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 6539723F98 for ; Mon, 19 Sep 2011 09:00:23 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 55355A180FC for ; Mon, 19 Sep 2011 09:00:23 +0000 (UTC) Received: by fxe23 with SMTP id 23so5220974fxe.11 for ; Mon, 19 Sep 2011 02:00:23 -0700 (PDT) Received: by 10.223.33.19 with SMTP id f19mr4670234fad.122.1316422822945; Mon, 19 Sep 2011 02:00:22 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.18.198 with SMTP id y6cs28867lad; Mon, 19 Sep 2011 02:00:22 -0700 (PDT) Received: by 10.236.173.131 with SMTP id v3mr11919389yhl.112.1316422821713; Mon, 19 Sep 2011 02:00:21 -0700 (PDT) Received: from mail-gw0-f50.google.com (mail-gw0-f50.google.com [74.125.83.50]) by mx.google.com with ESMTPS id a21si16767524yhm.34.2011.09.19.02.00.20 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Sep 2011 02:00:21 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.50 is neither permitted nor denied by best guess record for domain of avik.sil@linaro.org) client-ip=74.125.83.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.83.50 is neither permitted nor denied by best guess record for domain of avik.sil@linaro.org) smtp.mail=avik.sil@linaro.org Received: by gwj16 with SMTP id 16so5569944gwj.37 for ; Mon, 19 Sep 2011 02:00:20 -0700 (PDT) Received: by 10.100.237.15 with SMTP id k15mr60662anh.83.1316422820586; Mon, 19 Sep 2011 02:00:20 -0700 (PDT) Received: from localhost.localdomain ([122.248.161.59]) by mx.google.com with ESMTPS id f24sm57800ann.5.2011.09.19.02.00.18 (version=SSLv3 cipher=OTHER); Mon, 19 Sep 2011 02:00:20 -0700 (PDT) From: Avik Sil To: ltt-dev@lists.casi.polymtl.ca Cc: dave.martin@linaro.org, jon.medhurst@linaro.org, patches@linaro.org Subject: [PATCH V1] ARM: Set bit 0 for thumb mode in kallsyms_lookup_name returned address Date: Mon, 19 Sep 2011 14:30:04 +0530 Message-Id: <1316422804-32562-1-git-send-email-avik.sil@linaro.org> X-Mailer: git-send-email 1.7.0.4 This patch fixes the undefined instruction oops due to execution of thumb-2 code in ARM mode. The zero bit in the symbol address returned by kallsyms_lookup_name is not set, leading to switching to ARM mode that generates oops while executing thumb-2 code. For detailed discussion, see [1]. [1] http://lists.casi.polymtl.ca/pipermail/ltt-dev/2011-September/005176.html v1: - include wrapper function kallsyms_lookup_funcptr as suggested by Dave Martin Signed-off-by: Avik Sil --- lttng-context-prio.c | 3 ++- wrapper/ftrace.h | 5 +++-- wrapper/kallsyms.h | 28 ++++++++++++++++++++++++++++ wrapper/splice.c | 3 ++- wrapper/vmalloc.h | 3 ++- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 wrapper/kallsyms.h diff --git a/lttng-context-prio.c b/lttng-context-prio.c index ad1c42f..1ee3a54 100644 --- a/lttng-context-prio.c +++ b/lttng-context-prio.c @@ -13,6 +13,7 @@ #include "ltt-events.h" #include "wrapper/ringbuffer/frontend_types.h" #include "wrapper/vmalloc.h" +#include "wrapper/kallsyms.h" #include "ltt-tracer.h" static @@ -20,7 +21,7 @@ int (*wrapper_task_prio_sym)(struct task_struct *t); int wrapper_task_prio_init(void) { - wrapper_task_prio_sym = (void *) kallsyms_lookup_name("task_prio"); + wrapper_task_prio_sym = (void *) kallsyms_lookup_funcptr("task_prio"); if (!wrapper_task_prio_sym) { printk(KERN_WARNING "LTTng: task_prio symbol lookup failed.\n"); return -EINVAL; diff --git a/wrapper/ftrace.h b/wrapper/ftrace.h index 9c18cc5..ace33c5 100644 --- a/wrapper/ftrace.h +++ b/wrapper/ftrace.h @@ -16,6 +16,7 @@ #ifdef CONFIG_KALLSYMS #include +#include "kallsyms.h" static inline int wrapper_register_ftrace_function_probe(char *glob, @@ -24,7 +25,7 @@ int wrapper_register_ftrace_function_probe(char *glob, int (*register_ftrace_function_probe_sym)(char *glob, struct ftrace_probe_ops *ops, void *data); - register_ftrace_function_probe_sym = (void *) kallsyms_lookup_name("register_ftrace_function_probe"); + register_ftrace_function_probe_sym = (void *) kallsyms_lookup_funcptr("register_ftrace_function_probe"); if (register_ftrace_function_probe_sym) { return register_ftrace_function_probe_sym(glob, ops, data); } else { @@ -40,7 +41,7 @@ void wrapper_unregister_ftrace_function_probe(char *glob, void (*unregister_ftrace_function_probe_sym)(char *glob, struct ftrace_probe_ops *ops, void *data); - unregister_ftrace_function_probe_sym = (void *) kallsyms_lookup_name("unregister_ftrace_function_probe"); + unregister_ftrace_function_probe_sym = (void *) kallsyms_lookup_funcptr("unregister_ftrace_function_probe"); if (unregister_ftrace_function_probe_sym) { unregister_ftrace_function_probe_sym(glob, ops, data); } else { diff --git a/wrapper/kallsyms.h b/wrapper/kallsyms.h new file mode 100644 index 0000000..bb45f38 --- /dev/null +++ b/wrapper/kallsyms.h @@ -0,0 +1,28 @@ +#ifndef _LTT_WRAPPER_KALLSYMS_H +#define _LTT_WRAPPER_KALLSYMS_H + +/* + * Copyright (C) 2011 Avik Sil (avik.sil@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 /* _LTT_WRAPPER_KALLSYMS_H */ diff --git a/wrapper/splice.c b/wrapper/splice.c index edc499c..ba224ee 100644 --- a/wrapper/splice.c +++ b/wrapper/splice.c @@ -13,6 +13,7 @@ #include #include #include +#include "kallsyms.h" static ssize_t (*splice_to_pipe_sym)(struct pipe_inode_info *pipe, @@ -22,7 +23,7 @@ ssize_t wrapper_splice_to_pipe(struct pipe_inode_info *pipe, struct splice_pipe_desc *spd) { if (!splice_to_pipe_sym) - splice_to_pipe_sym = (void *) kallsyms_lookup_name("splice_to_pipe"); + splice_to_pipe_sym = (void *) kallsyms_lookup_funcptr("splice_to_pipe"); if (splice_to_pipe_sym) { return splice_to_pipe_sym(pipe, spd); } else { diff --git a/wrapper/vmalloc.h b/wrapper/vmalloc.h index 7d87855..765f2ad 100644 --- a/wrapper/vmalloc.h +++ b/wrapper/vmalloc.h @@ -14,13 +14,14 @@ #ifdef CONFIG_KALLSYMS #include +#include "kallsyms.h" static inline void wrapper_vmalloc_sync_all(void) { void (*vmalloc_sync_all_sym)(void); - vmalloc_sync_all_sym = (void *) kallsyms_lookup_name("vmalloc_sync_all"); + vmalloc_sync_all_sym = (void *) kallsyms_lookup_funcptr("vmalloc_sync_all"); if (vmalloc_sync_all_sym) { vmalloc_sync_all_sym(); } else {