From patchwork Mon Sep 16 11:30:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11146855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5888476 for ; Mon, 16 Sep 2019 11:32:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 340EB2067B for ; Mon, 16 Sep 2019 11:32:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="kwWLrFOa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 340EB2067B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i9pEL-00036z-Ql; Mon, 16 Sep 2019 11:31:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i9pEK-000361-46 for xen-devel@lists.xen.org; Mon, 16 Sep 2019 11:31:40 +0000 X-Inumbo-ID: 8cac5556-d875-11e9-a337-bc764e2007e4 Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8cac5556-d875-11e9-a337-bc764e2007e4; Mon, 16 Sep 2019 11:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1568633499; x=1600169499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=S7Jwy4t3EpCpk7fyUsDPxnKbkiyWUgaXiHUWKRb2soo=; b=kwWLrFOaoAKw6ZYSc78TqPH42eFEeCICXnOh0F/XLnIjD+3wjFh5bPwG /EbC9TEKL1B92gBchI1GNpO8cq3fHsbXaXlaK3eYjaD1X0ZwplcyHiXqK q/ywi/fxgcM/WrqYHkL4CI6KKc4Atz1l2SaLDaXIVhmRafu0N/RjviYdl g=; X-IronPort-AV: E=Sophos;i="5.64,512,1559520000"; d="scan'208";a="415450094" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 16 Sep 2019 11:31:38 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-474bcd9f.us-east-1.amazon.com (Postfix) with ESMTPS id CA4FEA184A; Mon, 16 Sep 2019 11:31:33 +0000 (UTC) Received: from EX13D05EUC003.ant.amazon.com (10.43.164.207) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 16 Sep 2019 11:31:19 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D05EUC003.ant.amazon.com (10.43.164.207) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 16 Sep 2019 11:31:18 +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; Mon, 16 Sep 2019 11:31:15 +0000 From: Pawel Wieczorkiewicz To: , Date: Mon, 16 Sep 2019 11:30:51 +0000 Message-ID: <20190916113056.16592-3-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190916113056.16592-1-wipawel@amazon.de> References: <20190916113056.16592-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v2 2/7] 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: wipawel@amazon.com, Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , mpohlack@amazon.com, Tim Deegan , Pawel Wieczorkiewicz , Julien Grall , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 f01f1da..44f4e6b 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, + }, {}, }; @@ -1465,23 +1481,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); @@ -1497,13 +1534,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) @@ -2292,11 +2333,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");