From patchwork Wed Aug 14 07:55:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11093463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 681BF6C5 for ; Wed, 14 Aug 2019 07:57:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 560A128737 for ; Wed, 14 Aug 2019 07:57:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4772328797; Wed, 14 Aug 2019 07:57:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97F1428737 for ; Wed, 14 Aug 2019 07:57:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxo8K-0001EI-Hc; Wed, 14 Aug 2019 07:55:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxo8J-0001EC-Td for xen-devel@lists.xen.org; Wed, 14 Aug 2019 07:55:47 +0000 X-Inumbo-ID: eca4b358-be68-11e9-aac1-bf0143fad4e2 Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eca4b358-be68-11e9-aac1-bf0143fad4e2; Wed, 14 Aug 2019 07:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1565769346; x=1597305346; h=from:to:cc:subject:date:message-id:mime-version; bh=A170r0IWzzOpIg/PBJzQr4TMLCLBtpdSJyiI6Mxk8Ak=; b=jaCIa3Ou1uQDjJws741o7gjj0pHdJQ/yPMLizZh9Kij66v/2vC6SIMHs 5iQnHtcAS3xfIvXEV/ARNIvAP2j0Icnp89ZsAGqN1WLd0c9TOcHDj90Ql tZJKNMUvPG8ZEPQX5hNDFi3nBvDaOEeWIZn1qKvMdBSGhuNxiFkDolxs9 8=; X-IronPort-AV: E=Sophos;i="5.64,384,1559520000"; d="scan'208";a="779187480" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-69849ee2.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 14 Aug 2019 07:55:45 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-69849ee2.us-west-2.amazon.com (Postfix) with ESMTPS id E5343A250F; Wed, 14 Aug 2019 07:55:44 +0000 (UTC) Received: from EX13D03EUA003.ant.amazon.com (10.43.165.89) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 14 Aug 2019 07:55:44 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D03EUA003.ant.amazon.com (10.43.165.89) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 14 Aug 2019 07:55:43 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 14 Aug 2019 07:55:41 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 14 Aug 2019 07:55:25 +0000 Message-ID: <20190814075525.83191-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-hooks-1 PATCH 1/3] create-diff-object: Handle extra pre-|post- hooks X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: mpohlack@amazon.de, ross.lagerwall@citrix.com, wipawel@amazon.de, konrad.wilk@oracle.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Include new sections containing optional pre-, post- action hooks. The following new section names are supported: - .livepatch.hooks.preapply - .livepatch.hooks.postapply - .livepatch.hooks.prerevert - .livepatch.hooks.postrevert Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Ross Lagerwall --- create-diff-object.c | 67 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index f352704..3493fe1 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1102,6 +1102,22 @@ static struct special_section special_sections[] = { .name = ".livepatch.hooks.unload", .group_size = livepatch_hooks_group_size, }, + { + .name = ".livepatch.hooks.preapply", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.postapply", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.prerevert", + .group_size = livepatch_hooks_group_size, + }, + { + .name = ".livepatch.hooks.postrevert", + .group_size = livepatch_hooks_group_size, + }, {}, }; @@ -1460,23 +1476,44 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf) } } -static void kpatch_include_hook_elements(struct kpatch_elf *kelf) +#define IS_HOOK_SECTION(section, hook) ({ \ + !strcmp(((section))->name, ".livepatch.hooks." hook) || \ + !strcmp(((section))->name, ".rela.livepatch.hooks." hook); \ +}) + +#define IS_ACTION_HOOK_SECTION(section, action) ({ \ + IS_HOOK_SECTION(section, "pre" action) || \ + IS_HOOK_SECTION(section, "post" action); \ +}) + +#define IS_HOOK_SYM_NAME(symbol, hook) ({ \ + !strcmp(((symbol))->name, "livepatch_" hook "_data"); \ +}) + +#define IS_ACTION_HOOK_SYM_NAME(symbol, action) ({ \ + IS_HOOK_SYM_NAME(symbol, "pre" action) || \ + IS_HOOK_SYM_NAME(symbol, "post" action); \ +}) + +static int kpatch_include_hook_elements(struct kpatch_elf *kelf) { struct section *sec; struct symbol *sym; struct rela *rela; + int num_new_functions = 0; - /* include load/unload sections */ + /* include all supported hooks sections */ list_for_each_entry(sec, &kelf->sections, list) { - if (!strcmp(sec->name, ".livepatch.hooks.load") || - !strcmp(sec->name, ".livepatch.hooks.unload") || - !strcmp(sec->name, ".rela.livepatch.hooks.load") || - !strcmp(sec->name, ".rela.livepatch.hooks.unload")) { + if (IS_HOOK_SECTION(sec, "load") || + IS_HOOK_SECTION(sec, "unload") || + IS_ACTION_HOOK_SECTION(sec, "apply") || + IS_ACTION_HOOK_SECTION(sec, "revert")) { sec->include = 1; + num_new_functions++; if (is_rela_section(sec)) { /* include hook dependencies */ rela = list_entry(sec->relas.next, - struct rela, list); + struct rela, list); sym = rela->sym; log_normal("found hook: %s\n",sym->name); kpatch_include_symbol(sym, 0); @@ -1492,13 +1529,17 @@ static void kpatch_include_hook_elements(struct kpatch_elf *kelf) } /* - * Strip temporary global load/unload function pointer objects - * used by the kpatch_[load|unload]() macros. + * Strip temporary global function pointer objects for all + * supported hooks, used by the kpatch_[load|unload]() macros. */ list_for_each_entry(sym, &kelf->symbols, list) - if (!strcmp(sym->name, "livepatch_load_data") || - !strcmp(sym->name, "livepatch_unload_data")) + if (IS_HOOK_SYM_NAME(sym, "load") || + IS_HOOK_SYM_NAME(sym, "unload") || + IS_ACTION_HOOK_SYM_NAME(sym, "apply") || + IS_ACTION_HOOK_SYM_NAME(sym, "revert")) sym->include = 0; + + return num_new_functions; } static int kpatch_include_new_globals(struct kpatch_elf *kelf) @@ -2287,11 +2328,11 @@ int main(int argc, char *argv[]) kpatch_include_standard_elements(kelf_patched); log_debug("Include changed functions\n"); num_changed = kpatch_include_changed_functions(kelf_patched); - log_debug("num_changed = %d\n", num_changed); log_debug("Include debug sections\n"); kpatch_include_debug_sections(kelf_patched); log_debug("Include hook elements\n"); - kpatch_include_hook_elements(kelf_patched); + num_changed += kpatch_include_hook_elements(kelf_patched); + log_debug("num_changed = %d\n", num_changed); log_debug("Include standard string elements\n"); kpatch_include_standard_string_elements(kelf_patched); log_debug("Include new globals\n");