[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [livepatch-hooks-1 PATCH 1/3] create-diff-object: Handle extra pre-|post- hooks



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@xxxxxxxxx>
---
 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");
-- 
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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.