Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3869092imm; Mon, 15 Oct 2018 05:38:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV60xD3mnPixqlj/MbgqB4FYq3Doao7J9S5reKYKB+YxwUoRKjM6mzVb1cnIlwRqdgUV3fJWj X-Received: by 2002:a17:902:24e7:: with SMTP id l36-v6mr16958139plg.234.1539607103329; Mon, 15 Oct 2018 05:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539607103; cv=none; d=google.com; s=arc-20160816; b=FwMTWKoIantxDEYqSh3nk3MYQw91XpR/B0JyGvTbePBaarRfRox4QpHPLqgbk77x42 JHfh67ccg0O1k13lnyMepuWT+Knr0Md4f/QPQTQ1fzsVfLwQ7lDwOXMP2N7XAc4OQPeE cJfDjPn3GChuP0XpO67NguS6oFN+Mc+ICQt6czk1h8i0Q/UqjZwP4Jras34tPlPsNgDJ k8wLty7SVPiXAu9EddREOyaHdQtDOuFD+0/8BfiOeammcUCsXAszMRkqBAqlyUo0EEu2 EUsxm0tUZsr5EB4uXN1MSx0fIIG2jQkkZTefNr5GgZSTvY62TuKoPK9E9t/4Gd0Fr6o0 ID6A== 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; bh=etAJ1qJN6ptLwSokXVgbIVaNv1bMTlc2iGZ1DikpYXQ=; b=NkpBeVxNW5dZuXzlL0fr74+8SBPbWbxOGlC58uRE+yP9ON0d7hP4lAUzgFERWZ2tsZ Z7dIF3gPM2+1PMxItieIpDmpH7PBINxW9I87F2NWrQNBWGiz/qL4isZu9AcWfV5KqyJw Hy8MPSpMO79Qq4drRiN67HTSWgamoKncn9PjVjs6xASsZAM4BJ+/bfbvvq/nd0B7Rulm +xs43T4Eae6F3foC9K4Ii5SFspyoId0DdHZc1CtitxQtKITgYVB8NQ8jBBTYNc9pntbz VcYHZvSEF43/6+PIMZHzbxGHaVp4Fojdhcojv8aAhFM8JfC8s24OyGmBJgx6Lp/76cR6 KMwg== 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 z4-v6si9423838pgj.39.2018.10.15.05.38.08; Mon, 15 Oct 2018 05:38:23 -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 S1726649AbeJOUWg (ORCPT + 99 others); Mon, 15 Oct 2018 16:22:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:52264 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726400AbeJOUWf (ORCPT ); Mon, 15 Oct 2018 16:22:35 -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 0A91AAE15; Mon, 15 Oct 2018 12:37:25 +0000 (UTC) From: Petr Mladek To: Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Jason Baron , Joe Lawrence , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v13 01/12] livepatch: Change void *new_func -> unsigned long new_addr in struct klp_func Date: Mon, 15 Oct 2018 14:37:02 +0200 Message-Id: <20181015123713.25868-2-pmladek@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181015123713.25868-1-pmladek@suse.com> References: <20181015123713.25868-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