@@ -587,8 +587,11 @@ static int prepare_payload(struct payload *payload,
LIVEPATCH_ASSIGN_MULTI_HOOK(elf, payload->unload_funcs, payload->n_unload_funcs, ".livepatch.hooks.unload");
LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.apply.pre, ".livepatch.hooks.preapply");
+ LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.apply.action, ".livepatch.hooks.apply");
LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.apply.post, ".livepatch.hooks.postapply");
+
LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.revert.pre, ".livepatch.hooks.prerevert");
+ LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.revert.action, ".livepatch.hooks.revert");
LIVEPATCH_ASSIGN_SINGLE_HOOK(elf, payload->hooks.revert.post, ".livepatch.hooks.postrevert");
sec = livepatch_elf_sec_by_name(elf, ELF_BUILD_ID_NOTE);
@@ -1114,6 +1117,11 @@ static int apply_payload(struct payload *data)
arch_livepatch_revive();
+ return 0;
+}
+
+static inline void apply_payload_tail(struct payload *data)
+{
/*
* We need RCU variant (which has barriers) in case we crash here.
* The applied_list is iterated by the trap code.
@@ -1121,7 +1129,7 @@ static int apply_payload(struct payload *data)
list_add_tail_rcu(&data->applied_list, &applied_list);
register_virtual_region(&data->region);
- return 0;
+ data->state = LIVEPATCH_STATE_APPLIED;
}
static int revert_payload(struct payload *data)
@@ -1154,6 +1162,11 @@ static int revert_payload(struct payload *data)
ASSERT(!local_irq_is_enabled());
arch_livepatch_revive();
+ return 0;
+}
+
+static inline void revert_payload_tail(struct payload *data)
+{
/*
* We need RCU variant (which has barriers) in case we crash here.
@@ -1163,7 +1176,7 @@ static int revert_payload(struct payload *data)
unregister_virtual_region(&data->region);
data->reverted = true;
- return 0;
+ data->state = LIVEPATCH_STATE_CHECKED;
}
/*
@@ -1183,15 +1196,31 @@ static void livepatch_do_action(void)
switch ( livepatch_work.cmd )
{
case LIVEPATCH_ACTION_APPLY:
- rc = apply_payload(data);
+ if ( is_hook_enabled(data->hooks.apply.action) )
+ {
+ printk(XENLOG_INFO LIVEPATCH "%s: Calling apply action hook function\n", data->name);
+
+ rc = (*data->hooks.apply.action)(data);
+ }
+ else
+ rc = apply_payload(data);
+
if ( rc == 0 )
- data->state = LIVEPATCH_STATE_APPLIED;
+ apply_payload_tail(data);
break;
case LIVEPATCH_ACTION_REVERT:
- rc = revert_payload(data);
+ if ( is_hook_enabled(data->hooks.revert.action) )
+ {
+ printk(XENLOG_INFO LIVEPATCH "%s: Calling revert action hook function\n", data->name);
+
+ rc = (*data->hooks.revert.action)(data);
+ }
+ else
+ rc = revert_payload(data);
+
if ( rc == 0 )
- data->state = LIVEPATCH_STATE_CHECKED;
+ revert_payload_tail(data);
break;
case LIVEPATCH_ACTION_REPLACE:
@@ -1202,9 +1231,18 @@ static void livepatch_do_action(void)
*/
list_for_each_entry_safe_reverse ( other, tmp, &applied_list, applied_list )
{
- other->rc = revert_payload(other);
+ if ( is_hook_enabled(other->hooks.revert.action) )
+ {
+ printk(XENLOG_INFO LIVEPATCH "%s: Calling revert action hook function\n", other->name);
+
+ other->rc = (*other->hooks.revert.action)(other);
+ }
+ else
+ other->rc = revert_payload(other);
+
+
if ( other->rc == 0 )
- other->state = LIVEPATCH_STATE_CHECKED;
+ revert_payload_tail(other);
else
{
rc = -EINVAL;
@@ -1214,9 +1252,17 @@ static void livepatch_do_action(void)
if ( rc == 0 )
{
- rc = apply_payload(data);
+ if ( is_hook_enabled(data->hooks.apply.action) )
+ {
+ printk(XENLOG_INFO LIVEPATCH "%s: Calling apply action hook function\n", data->name);
+
+ rc = (*data->hooks.apply.action)(data);
+ }
+ else
+ rc = apply_payload(data);
+
if ( rc == 0 )
- data->state = LIVEPATCH_STATE_APPLIED;
+ apply_payload_tail(data);
}
break;
@@ -22,11 +22,13 @@ typedef void livepatch_loadcall_t(void);
typedef void livepatch_unloadcall_t(void);
typedef int livepatch_precall_t(livepatch_payload_t *arg);
+typedef int livepatch_actioncall_t(livepatch_payload_t *arg);
typedef void livepatch_postcall_t(livepatch_payload_t *arg);
struct livepatch_hooks {
struct {
livepatch_precall_t *const *pre;
+ livepatch_actioncall_t *const *action;
livepatch_postcall_t *const *post;
} apply, revert;
};
@@ -91,6 +93,10 @@ struct payload {
livepatch_precall_t *__attribute__((weak, used)) \
const livepatch_preapply_data_##_fn __section(".livepatch.hooks.preapply") = _fn;
+#define LIVEPATCH_APPLY_HOOK(_fn) \
+ livepatch_actioncall_t *__attribute__((weak, used)) \
+ const livepatch_apply_data_##_fn __section(".livepatch.hooks.apply") = _fn;
+
#define LIVEPATCH_POSTAPPLY_HOOK(_fn) \
livepatch_postcall_t *__attribute__((weak, used)) \
const livepatch_postapply_data_##_fn __section(".livepatch.hooks.postapply") = _fn;
@@ -99,6 +105,10 @@ struct payload {
livepatch_precall_t *__attribute__((weak, used)) \
const livepatch_prerevert_data_##_fn __section(".livepatch.hooks.prerevert") = _fn;
+#define LIVEPATCH_REVERT_HOOK(_fn) \
+ livepatch_actioncall_t *__attribute__((weak, used)) \
+ const livepatch_revert_data_##_fn __section(".livepatch.hooks.revert") = _fn;
+
#define LIVEPATCH_POSTREVERT_HOOK(_fn) \
livepatch_postcall_t *__attribute__((weak, used)) \
const livepatch_postrevert_data_##_fn __section(".livepatch.hooks.postrevert") = _fn;