From patchwork Thu May 28 05:51:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Bin X-Patchwork-Id: 6496181 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E4DF39F38C for ; Thu, 28 May 2015 05:58:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B2D8206A1 for ; Thu, 28 May 2015 05:58:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 26CB620671 for ; Thu, 28 May 2015 05:58:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yxqnl-00089x-TI; Thu, 28 May 2015 05:56:21 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YxqnV-00082q-7J for linux-arm-kernel@lists.infradead.org; Thu, 28 May 2015 05:56:06 +0000 Received: from 172.24.2.119 (EHLO szxeml433-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CMA38394; Thu, 28 May 2015 13:54:56 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.158.1; Thu, 28 May 2015 13:54:46 +0800 From: Li Bin To: , , , , , , , , Subject: [RFC PATCH 2/5] livepatch: ftrace: add ftrace_function_stub_ip function Date: Thu, 28 May 2015 13:51:02 +0800 Message-ID: <1432792265-24076-3-git-send-email-huawei.libin@huawei.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1432792265-24076-1-git-send-email-huawei.libin@huawei.com> References: <1432792265-24076-1-git-send-email-huawei.libin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150527_225605_653212_C07D9778 X-CRM114-Status: GOOD ( 13.51 ) X-Spam-Score: -2.3 (--) Cc: huawei.libin@huawei.com, xiexiuqi@huawei.com, linux-kernel@vger.kernel.org, lizefan@huawei.com, felix.yang@huawei.com, guohanjun@huawei.com, live-patching@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 The function of ftrace_function_stub_ip is to convert the function address to the ftrace stub calling instruction address. This is needed for the platform that the complier does not support "profile before prologue" feature and the profile calling instruction is not at begin of the function. EXAMPLES: ... stub_ip = ftrace_function_stub_ip(func_addr); ftrace_set_filter_ip(&ftrace_ops, stub_ip, 0, 0); register_ftrace_function(&ftrace_ops); ... Signed-off-by: Li Bin --- include/linux/ftrace.h | 1 + kernel/trace/ftrace.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 1da6029..38a2811 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -360,6 +360,7 @@ struct dyn_ftrace { int ftrace_force_update(void); int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip, int remove, int reset); +unsigned long ftrace_function_stub_ip(unsigned long addr); int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf, int len, int reset); int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf, diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 02bece4..4d8692c 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4161,6 +4161,38 @@ int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip, } EXPORT_SYMBOL_GPL(ftrace_set_filter_ip); +/** + * ftrace_function_stub_ip - get the profile stub calling location by the + * function address. It is useful for the platform that doesn't place the + * function profiling call at the start of the function. + * @addr - the function address to get the stub ip + * + * It returns the corresponding profile stub calling location if founded, else + * return zero. + */ +unsigned long ftrace_function_stub_ip(unsigned long addr) +{ + struct ftrace_page *pg; + struct dyn_ftrace *rec; + unsigned long ret = 0; + + mutex_lock(&ftrace_lock); + + do_for_each_ftrace_rec(pg, rec) { + unsigned long offset; + + if (kallsyms_lookup_size_offset(rec->ip, NULL, &offset) + && addr + offset == rec->ip) { + ret = rec->ip; + goto out_unlock; + } + } while_for_each_ftrace_rec() +out_unlock: + mutex_unlock(&ftrace_lock); + return ret; +} +EXPORT_SYMBOL_GPL(ftrace_function_stub_ip); + static int ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len, int reset, int enable)