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: 6266301 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A9675BF4A7 for ; Fri, 24 Apr 2015 02:48:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF26220256 for ; Fri, 24 Apr 2015 02:48:09 +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 7327920251 for ; Fri, 24 Apr 2015 02:48:08 +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 1YlTcf-0003br-3n; Fri, 24 Apr 2015 02:45:45 +0000 Received: from mail-pd0-f175.google.com ([209.85.192.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YlTcL-0002zx-Tj for linux-arm-kernel@lists.infradead.org; Fri, 24 Apr 2015 02:45:27 +0000 Received: by pdbnk13 with SMTP id nk13so35477650pdb.0 for ; Thu, 23 Apr 2015 19:45:04 -0700 (PDT) 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=fRXNR1y7mOuUGCf1f303KAhfVgKwDMd9FN9bh7Cray0=; b=mIiTVYgBKedkWQYWdFcgW+akmqXavZ5+o93DRpx561s39+84AAZE4V14nnte9z4etE 0dJQ9cda463ffie70stLM+34+e0tKFdxhp1vZnfLSJ5TCtIaIpZPbccm9x/FLpTK7mWW i0gRLbDsivtdpFRqAo4C+ILhFZYyhFWjJHmHKA1qYGUZWM3CLD6DJD6b1G13JIkRTzCo IMKaA3BvNwPPS+W568i3eTAXI8hpvZVEw1zAMzUT/M6ROoa4j8/i+Ntjeq+jfD4fMfiM Q62HOdrTrXHqAi0B5nR+OfHUSPc73u7zj82ge816/nX0+AiF1aVe43HDWn+uhDwCPEYi kh6A== X-Gm-Message-State: ALoCoQlXAT3pEhXfH08r6XCNOEuMaBNLwyKfeph0AJTVtYhPV8+DB8i2a253m39XxZFsKwG5bw5B 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150423_194526_002674_F400EFB4 X-CRM114-Status: GOOD ( 14.02 ) X-Spam-Score: -0.9 (/) Cc: linaro-kernel@lists.linaro.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , broonie@kernel.org, masami.hiramatsu.pt@hitachi.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: , 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.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 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);