All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pawel Wieczorkiewicz <wipawel@amazon.de>
To: <xen-devel@lists.xenproject.org>
Cc: Pawel Wieczorkiewicz <wipawel@amazon.de>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	mpohlack@amazon.com,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [Xen-devel] [PATCH v3 2/7] create-diff-object: Handle extra pre-|post- hooks
Date: Tue, 26 Nov 2019 12:25:06 +0000	[thread overview]
Message-ID: <20191126122511.7409-3-wipawel@amazon.de> (raw)
In-Reply-To: <20191126122511.7409-1-wipawel@amazon.de>

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 <wipawel@amazon.de>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
 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 8d63940..7ff56c7 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)
@@ -2298,11 +2339,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");
-- 
2.16.5




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-11-26 12:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26 12:25 [Xen-devel] [PATCH v3 0/7] livepatch-build-tools: new features and fixes Pawel Wieczorkiewicz
2019-11-26 12:25 ` [Xen-devel] [PATCH v3 1/7] livepatch-build: Embed hypervisor build id into every hotpatch Pawel Wieczorkiewicz
2019-11-26 12:25 ` Pawel Wieczorkiewicz [this message]
2019-11-26 12:25 ` [Xen-devel] [PATCH v3 3/7] create-diff-object: Handle optional apply|revert hooks Pawel Wieczorkiewicz
2019-11-26 12:25 ` [Xen-devel] [PATCH v3 4/7] create-diff-object: Add support for applied/reverted marker Pawel Wieczorkiewicz
2019-11-26 12:25 ` [Xen-devel] [PATCH v3 5/7] create-diff-object: Add support for expectations Pawel Wieczorkiewicz
2019-11-26 12:25 ` [Xen-devel] [PATCH v3 6/7] livepatch-build: Strip transient or unneeded symbols Pawel Wieczorkiewicz
2019-11-26 14:33   ` Ross Lagerwall
2019-11-26 12:25 ` [Xen-devel] [PATCH v3 7/7] livepatch-build: Strip all metadata symbols from hotpatch modules Pawel Wieczorkiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191126122511.7409-3-wipawel@amazon.de \
    --to=wipawel@amazon.de \
    --cc=konrad.wilk@oracle.com \
    --cc=mpohlack@amazon.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.