From patchwork Fri Apr 24 02:44:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 47482 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8DCB22121F for ; Fri, 24 Apr 2015 02:45:28 +0000 (UTC) Received: by wiun10 with SMTP id n10sf1002879wiu.1 for ; Thu, 23 Apr 2015 19:45:27 -0700 (PDT) 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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=eThY0Lvm+n0KzWKkDhXAA/WGHtg92pSyDOyZy95eS0k=; b=cZuqbMqwtocBRuMCQ4j55HOtTU2amgaZGRbLz79ZOeYIOhiJ0KJvZC73m36cPNoJPj 8XYkyKp1d1OLemIgNh2bSpxZ4RF42vNbNi3cdLNCH+90tUEl9CpT6507IHndxkxfkvzp lMUjYkqmRXt5BwaAT79OC1JJf70u60K0aNcJnRnt3Aakfctch4B092tLrlt2keT7pnaD 7VpelP4R12SoXiCO11UqLUfDg0OXUNPhukWV1DOt4XpVs0qyL/1CwSfv9QgZOBZw4WM6 nTiwW5w4R+tt0bNo3zAUxZYIncvj4NUKklFvCFPuG2hi/uJDtL4v35kqsj8tbFwCSYrJ pDFw== X-Gm-Message-State: ALoCoQkfLIIBAhyLlUdgmXE4Nb/b6vAqz5T3BYrrJofzQ7y35V0vQ+YVYUA7a4fkNDMurCdXcNqd X-Received: by 10.112.162.228 with SMTP id yd4mr2863905lbb.8.1429843527687; Thu, 23 Apr 2015 19:45:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.162 with SMTP id z2ls396199laj.75.gmail; Thu, 23 Apr 2015 19:45:27 -0700 (PDT) X-Received: by 10.112.143.137 with SMTP id se9mr4988888lbb.60.1429843527520; Thu, 23 Apr 2015 19:45:27 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id un5si7252105lbc.53.2015.04.23.19.45.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 19:45:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by lagv1 with SMTP id v1so25764070lag.3 for ; Thu, 23 Apr 2015 19:45:27 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr5033201laj.88.1429843527222; Thu, 23 Apr 2015 19:45:27 -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.112.67.65 with SMTP id l1csp922835lbt; Thu, 23 Apr 2015 19:45:25 -0700 (PDT) X-Received: by 10.68.221.102 with SMTP id qd6mr10451004pbc.119.1429843524342; Thu, 23 Apr 2015 19:45:24 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fp4si15294737pdb.113.2015.04.23.19.45.23; Thu, 23 Apr 2015 19:45:24 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754027AbbDXCpK (ORCPT + 27 others); Thu, 23 Apr 2015 22:45:10 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:33311 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753955AbbDXCpF (ORCPT ); Thu, 23 Apr 2015 22:45:05 -0400 Received: by pdbnk13 with SMTP id nk13so35477620pdb.0 for ; Thu, 23 Apr 2015 19:45:04 -0700 (PDT) X-Received: by 10.66.62.137 with SMTP id y9mr4012438par.71.1429843504405; Thu, 23 Apr 2015 19:45:04 -0700 (PDT) Received: from localhost.localdomain (61-205-1-167m5.grp1.mineo.jp. [61.205.1.167]) by mx.google.com with ESMTPSA id do16sm9488624pac.15.2015.04.23.19.44.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Apr 2015 19:45:03 -0700 (PDT) From: AKASHI Takahiro To: rostedt@goodmis.org, mingo@kernel.org, jpoimboe@redhat.com, sjenning@redhat.com, jkosina@suse.cz, vojtech@suse.cz, catalin.marinas@arm.com, will.deacon@arm.com Cc: broonie@kernel.org, masami.hiramatsu.pt@hitachi.com, live-patching@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, AKASHI Takahiro Subject: [RFC 2/4] livepatch: adjust a patched function's address Date: Fri, 24 Apr 2015 11:44:07 +0900 Message-Id: <1429843449-7388-3-git-send-email-takahiro.akashi@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429843449-7388-1-git-send-email-takahiro.akashi@linaro.org> References: <1429843449-7388-1-git-send-email-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: takahiro.akashi@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The existing livepatch code assumes that a fentry call is inserted before a function prolog by -mfentry option of gcc. But the location of mcount() can be identified by using ftrace_lookup_mcount(), and which eventually allows arch's which don't support -mfentry option, like arm64, to support livepatch. This patch modifies core and x86 code before adding livepatch support for arm64. Signed-off-by: AKASHI Takahiro --- arch/x86/include/asm/livepatch.h | 5 +++++ include/linux/livepatch.h | 2 ++ kernel/livepatch/core.c | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/livepatch.h b/arch/x86/include/asm/livepatch.h index a455a53..914954a 100644 --- a/arch/x86/include/asm/livepatch.h +++ b/arch/x86/include/asm/livepatch.h @@ -39,6 +39,11 @@ static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) { regs->ip = ip; } + +static inline unsigned long klp_arch_lookup_mcount(unsigned long addr) +{ + return addr; +} #else #error Live patching support is disabled; check CONFIG_LIVEPATCH #endif diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index 95023fd..fec7800 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -47,6 +47,7 @@ struct klp_func { /* external */ const char *old_name; void *new_func; + unsigned long new_func_mcount; /* * The old_addr field is optional and can be used to resolve * duplicate symbol names in the vmlinux object. If this @@ -56,6 +57,7 @@ struct klp_func { * way to resolve the ambiguity. */ unsigned long old_addr; + unsigned long old_addr_mcount; /* internal */ struct kobject kobj; diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 3f9f1d6..3c7c8070 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -245,6 +245,9 @@ static int klp_find_verify_func_addr(struct klp_object *obj, ret = klp_verify_vmlinux_symbol(func->old_name, func->old_addr); + if (func->old_addr && !ret) + func->old_addr_mcount = klp_arch_lookup_mcount(func->old_addr); + return ret; } @@ -330,7 +333,7 @@ static void notrace klp_ftrace_handler(unsigned long ip, if (WARN_ON_ONCE(!func)) goto unlock; - klp_arch_set_pc(regs, (unsigned long)func->new_func); + klp_arch_set_pc(regs, func->new_func_mcount); unlock: rcu_read_unlock(); } @@ -358,7 +361,8 @@ static int klp_disable_func(struct klp_func *func) return ret; } - ret = ftrace_set_filter_ip(&ops->fops, func->old_addr, 1, 0); + ret = ftrace_set_filter_ip(&ops->fops, + func->old_addr_mcount, 1, 0); if (ret) pr_warn("function unregister succeeded but failed to clear the filter\n"); @@ -401,7 +405,8 @@ static int klp_enable_func(struct klp_func *func) INIT_LIST_HEAD(&ops->func_stack); list_add_rcu(&func->stack_node, &ops->func_stack); - ret = ftrace_set_filter_ip(&ops->fops, func->old_addr, 0, 0); + ret = ftrace_set_filter_ip(&ops->fops, + func->old_addr_mcount, 0, 0); if (ret) { pr_err("failed to set ftrace filter for function '%s' (%d)\n", func->old_name, ret); @@ -412,7 +417,8 @@ static int klp_enable_func(struct klp_func *func) if (ret) { pr_err("failed to register ftrace handler for function '%s' (%d)\n", func->old_name, ret); - ftrace_set_filter_ip(&ops->fops, func->old_addr, 1, 0); + ftrace_set_filter_ip(&ops->fops, + func->old_addr_mcount, 1, 0); goto err; } @@ -742,6 +748,8 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func) { INIT_LIST_HEAD(&func->stack_node); func->state = KLP_DISABLED; + func->new_func_mcount = + klp_arch_lookup_mcount((unsigned long)func->new_func); return kobject_init_and_add(&func->kobj, &klp_ktype_func, obj->kobj, "%s", func->old_name);