Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7177794imm; Tue, 28 Aug 2018 07:38:19 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdayvl7puAe9cygpLe/EHvuFV3G65j4NrXwEzkmFvs7Y0uJu/Jjv46j6cNDIHON9ZjoZQNTC X-Received: by 2002:a63:e0e:: with SMTP id d14-v6mr1898863pgl.38.1535467099224; Tue, 28 Aug 2018 07:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535467099; cv=none; d=google.com; s=arc-20160816; b=GwAAAw1JuFQnVG7Wv6ZK7HWcf1BeMkLcdE4ykGdTEC5OcsmzcCqmrbcmVFzKMxCRuK ontY2n34Oygz7ecD5a8chdaHwmA422jSClbLJjVeqJm4LTZqB+axUD2afzqMfGCgYVIl n7AGZO2kp6s9E9mdk6gwX+ed4Z5QSIz7rZHbfDkQ7BifglicBcxrTYs/JJjtwLnWRtK7 6zSs6jWtmtRkrW62jtCWJF4cFDwbC3fSPnYbm6klSbIiunk+ANxdQ8n9lRBUtp0jZ3l6 nlo/BW3Jp/i0aRpHLgzcu4cy1ejPQoBpY01M0ALcSmqRItKzw7ACH7aN8HQoP2KYhwTN aMYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=etAJ1qJN6ptLwSokXVgbIVaNv1bMTlc2iGZ1DikpYXQ=; b=VZOGrJXnZ/QNswGycRE1qsRcRyyuFwXDh9ZjAry4gadIO7yIPgaDUUy+M10K1ElQnC D+j2d59y7oOj3fGRrKSRwhLeezKUqDb+N2nq7oVhHFBzgESNUFxBFbaBCrcZOFJzRZVE u5PECDCP5U9BFZBN6x0a59eP2+jMVFpXCF88LwjfwRNBJJ45DcLlYCjc8xCb1ftZwA19 CNSkFG8retGPfLEMusKwnIu2p65/IGUtNEpAFFKCCPyiARpRHTYuPZzAsQGMleBGhWHT H4RV7bhOjwJkrOnikb69iAlqVEuwK2UMNalE/pugFbphicucV8auZoAMeywEIo3XrqG6 +Ykw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r14-v6si1095283pfa.44.2018.08.28.07.38.03; Tue, 28 Aug 2018 07:38:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728306AbeH1S2h (ORCPT + 99 others); Tue, 28 Aug 2018 14:28:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:38912 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726120AbeH1S2h (ORCPT ); Tue, 28 Aug 2018 14:28:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E4E8CAFD5; Tue, 28 Aug 2018 14:36:37 +0000 (UTC) From: Petr Mladek To: Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Jason Baron , Joe Lawrence , Jessica Yu , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v12 01/12] livepatch: Change void *new_func -> unsigned long new_addr in struct klp_func Date: Tue, 28 Aug 2018 16:35:52 +0200 Message-Id: <20180828143603.4442-2-pmladek@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180828143603.4442-1-pmladek@suse.com> References: <20180828143603.4442-1-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The address of the to be patched function and new function is stored in struct klp_func as: void *new_func; unsigned long old_addr; The different naming scheme and type is derived from the way how the addresses are set. @old_addr is assigned at runtime using kallsyms-based search. @new_func is statically initialized, for example: static struct klp_func funcs[] = { { .old_name = "cmdline_proc_show", .new_func = livepatch_cmdline_proc_show, }, { } }; This patch changes void *new_func -> unsigned long new_addr. It removes some confusion when these address are later used in the code. It is motivated by a followup patch that adds special NOP struct klp_func where we want to assign func->new_func = func->old_addr respectively func->new_addr = func->old_addr. This patch does not modify the existing behavior. IMPORTANT: This patch modifies ABI. The patches will need to use, for example: static struct klp_func funcs[] = { { .old_name = "cmdline_proc_show", .new_addr = (unsigned long)livepatch_cmdline_proc_show, }, { } }; Suggested-by: Josh Poimboeuf Signed-off-by: Petr Mladek --- include/linux/livepatch.h | 6 +++--- kernel/livepatch/core.c | 4 ++-- kernel/livepatch/patch.c | 2 +- kernel/livepatch/transition.c | 4 ++-- samples/livepatch/livepatch-callbacks-demo.c | 2 +- samples/livepatch/livepatch-sample.c | 2 +- samples/livepatch/livepatch-shadow-fix1.c | 4 ++-- samples/livepatch/livepatch-shadow-fix2.c | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index aec44b1d9582..817a737b49e8 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -37,7 +37,7 @@ /** * struct klp_func - function structure for live patching * @old_name: name of the function to be patched - * @new_func: pointer to the patched function code + * @new_addr: address of the new function (function pointer) * @old_sympos: a hint indicating which symbol position the old function * can be found (optional) * @old_addr: the address of the function being patched @@ -66,7 +66,7 @@ struct klp_func { /* external */ const char *old_name; - void *new_func; + unsigned long new_addr; /* * The old_sympos field is optional and can be used to resolve * duplicate symbol names in livepatch objects. If this field is zero, @@ -157,7 +157,7 @@ struct klp_patch { #define klp_for_each_func(obj, func) \ for (func = obj->funcs; \ - func->old_name || func->new_func || func->old_sympos; \ + func->old_name || func->new_addr || func->old_sympos; \ func++) int klp_register_patch(struct klp_patch *); diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 5b77a7314e01..577ebeb43024 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -675,7 +675,7 @@ static void klp_free_patch(struct klp_patch *patch) static int klp_init_func(struct klp_object *obj, struct klp_func *func) { - if (!func->old_name || !func->new_func) + if (!func->old_name || !func->new_addr) return -EINVAL; if (strlen(func->old_name) >= KSYM_NAME_LEN) @@ -733,7 +733,7 @@ static int klp_init_object_loaded(struct klp_patch *patch, return -ENOENT; } - ret = kallsyms_lookup_size_offset((unsigned long)func->new_func, + ret = kallsyms_lookup_size_offset(func->new_addr, &func->new_size, NULL); if (!ret) { pr_err("kallsyms size lookup failed for '%s' replacement\n", diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c index 82d584225dc6..82927f59d3ff 100644 --- a/kernel/livepatch/patch.c +++ b/kernel/livepatch/patch.c @@ -118,7 +118,7 @@ static void notrace klp_ftrace_handler(unsigned long ip, } } - klp_arch_set_pc(regs, (unsigned long)func->new_func); + klp_arch_set_pc(regs, func->new_addr); unlock: preempt_enable_notrace(); } diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index 5bc349805e03..982a2e4c6120 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -217,7 +217,7 @@ static int klp_check_stack_func(struct klp_func *func, * Check for the to-be-unpatched function * (the func itself). */ - func_addr = (unsigned long)func->new_func; + func_addr = func->new_addr; func_size = func->new_size; } else { /* @@ -235,7 +235,7 @@ static int klp_check_stack_func(struct klp_func *func, struct klp_func *prev; prev = list_next_entry(func, stack_node); - func_addr = (unsigned long)prev->new_func; + func_addr = prev->new_addr; func_size = prev->new_size; } } diff --git a/samples/livepatch/livepatch-callbacks-demo.c b/samples/livepatch/livepatch-callbacks-demo.c index 72f9e6d1387b..4b1aec474bb7 100644 --- a/samples/livepatch/livepatch-callbacks-demo.c +++ b/samples/livepatch/livepatch-callbacks-demo.c @@ -153,7 +153,7 @@ static struct klp_func no_funcs[] = { static struct klp_func busymod_funcs[] = { { .old_name = "busymod_work_func", - .new_func = patched_work_func, + .new_addr = (unsigned long)patched_work_func, }, { } }; diff --git a/samples/livepatch/livepatch-sample.c b/samples/livepatch/livepatch-sample.c index 2d554dd930e2..e470a052fb77 100644 --- a/samples/livepatch/livepatch-sample.c +++ b/samples/livepatch/livepatch-sample.c @@ -51,7 +51,7 @@ static int livepatch_cmdline_proc_show(struct seq_file *m, void *v) static struct klp_func funcs[] = { { .old_name = "cmdline_proc_show", - .new_func = livepatch_cmdline_proc_show, + .new_addr = (unsigned long)livepatch_cmdline_proc_show, }, { } }; diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c index 49b13553eaae..ede0de7abe40 100644 --- a/samples/livepatch/livepatch-shadow-fix1.c +++ b/samples/livepatch/livepatch-shadow-fix1.c @@ -130,11 +130,11 @@ void livepatch_fix1_dummy_free(struct dummy *d) static struct klp_func funcs[] = { { .old_name = "dummy_alloc", - .new_func = livepatch_fix1_dummy_alloc, + .new_addr = (unsigned long)livepatch_fix1_dummy_alloc, }, { .old_name = "dummy_free", - .new_func = livepatch_fix1_dummy_free, + .new_addr = (unsigned long)livepatch_fix1_dummy_free, }, { } }; diff --git a/samples/livepatch/livepatch-shadow-fix2.c b/samples/livepatch/livepatch-shadow-fix2.c index b34c7bf83356..035ee0ef387f 100644 --- a/samples/livepatch/livepatch-shadow-fix2.c +++ b/samples/livepatch/livepatch-shadow-fix2.c @@ -107,11 +107,11 @@ void livepatch_fix2_dummy_free(struct dummy *d) static struct klp_func funcs[] = { { .old_name = "dummy_check", - .new_func = livepatch_fix2_dummy_check, + .new_addr = (unsigned long)livepatch_fix2_dummy_check, }, { .old_name = "dummy_free", - .new_func = livepatch_fix2_dummy_free, + .new_addr = (unsigned long)livepatch_fix2_dummy_free, }, { } }; -- 2.13.7