Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibor Pechacek <lpechacek@suse.com>2017-07-12 11:14:40 +0200
committerMiroslav Benes <mbenes@suse.cz>2017-12-08 13:03:27 +0100
commit7e20201cdcb88e7a236fe9f86f36f2e72f95c121 (patch)
tree307fa62bdf321284cb2c05f3ecadbdc34a6b22c0
parent28a04a2be97498a9c227c83aa37a45306d165424 (diff)
kGraft to livepatch migration. API change.
Change from kGraft API to livepatch API. Note: error handling in _init() function is broken and fixed later. Automatic generation of klp_objects is not present at all. Added later. References: fate#323682 Signed-off-by: Libor Pechacek <lpechacek@suse.com> [ mb: changelog, patch split, whitespace errors ] Signed-off-by: Miroslav Benes <mbenes@suse.cz>
-rw-r--r--livepatch_main.c45
-rw-r--r--rpm/kgraft-patch.spec2
-rwxr-xr-xscripts/register-patches.sh1
3 files changed, 34 insertions, 14 deletions
diff --git a/livepatch_main.c b/livepatch_main.c
index d88fc2d..4a4e7be 100644
--- a/livepatch_main.c
+++ b/livepatch_main.c
@@ -18,7 +18,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include <linux/kgraft.h>
+#include <linux/livepatch.h>
#include <linux/module.h>
#include <linux/types.h>
@@ -26,15 +26,27 @@
@@KLP_PATCHES_INCLUDES@@
-static struct kgr_patch patch = {
- .name = "kgraft-patch-@@RPMRELEASE@@",
- .owner = THIS_MODULE,
- .replace_all = true,
- .patches = {
- KGR_PATCH(SyS_newuname, klp_sys_newuname),
- @@KLP_PATCHES_FUNCS@@,
- KGR_PATCH_END
- }
+static struct klp_func vmlinux_funcs[] = {
+ {
+ .old_name = "SyS_newuname",
+ .new_func = klp_sys_newuname,
+ }, { }
+};
+
+@@KLP_PATCHES_FUNCS@@;
+
+static struct klp_object objs[] = {
+ {
+ .name = NULL, /* vmlinux */
+ .funcs = vmlinux_funcs,
+ },
+ @@KLP_PATCHES_OBJS@@,
+ { }
+};
+
+static struct klp_patch patch = {
+ .mod = THIS_MODULE,
+ .objs = objs,
};
static int __init klp_patch_init(void)
@@ -49,12 +61,18 @@ static int __init klp_patch_init(void)
@@KLP_PATCHES_INIT_CALLS@@;
- retval = kgr_patch_kernel(&patch);
- if (!retval)
+ retval = klp_register_patch(&patch);
+ if (retval)
return retval;
+ retval = klp_enable_patch(&patch);
+ if (retval) {
+ WARN_ON(klp_unregister_patch(&patch));
+ return retval;
+ }
/* jumped to from expanded KLP_PATCHES_INIT_CALLS on failure */
@@KLP_PATCHES_INIT_ERR_HANDLERS@@:
+ return retval;
}
static void __exit klp_patch_cleanup(void)
@@ -63,10 +81,11 @@ static void __exit klp_patch_cleanup(void)
@@KLP_PATCHES_CLEANUP_CALLS@@;
- kgr_patch_remove(&patch);
+ WARN_ON(klp_unregister_patch(&patch));
}
module_init(klp_patch_init);
module_exit(klp_patch_cleanup);
MODULE_LICENSE("GPL");
+MODULE_INFO(livepatch, "Y");
diff --git a/rpm/kgraft-patch.spec b/rpm/kgraft-patch.spec
index f080e95..8fbd419 100644
--- a/rpm/kgraft-patch.spec
+++ b/rpm/kgraft-patch.spec
@@ -32,7 +32,7 @@ Source4: source-timestamp
Source5: shadow.c
Source6: shadow.h
@@KLP_PATCHES_SOURCES@@
-BuildRequires: kernel-syms kgraft-devel
+BuildRequires: kernel-syms kgraft-devel libelf-devel
ExclusiveArch: @@EXCARCH@@
%kgraft_module_package
diff --git a/scripts/register-patches.sh b/scripts/register-patches.sh
index 42fc916..f0cf7a0 100755
--- a/scripts/register-patches.sh
+++ b/scripts/register-patches.sh
@@ -116,6 +116,7 @@ KLP_PATCHES_CLEANUP_CALLS=$(
sed -i -f - "$livepatch_main_file" <<EOF
s%@@KLP_PATCHES_INCLUDES@@%$KLP_PATCHES_INCLUDES%;
s%\s*@@KLP_PATCHES_FUNCS@@,\?%$KLP_PATCHES_FUNCS%;
+s%\s*@@KLP_PATCHES_OBJS@@,\?%%;
s%\s*@@KLP_PATCHES_INIT_CALLS@@;\?%$KLP_PATCHES_INIT_CALLS%;
s%\s*@@KLP_PATCHES_INIT_ERR_HANDLERS@@:\?%$KLP_PATCHES_INIT_ERR_HANDLERS%;
s%\s*@@KLP_PATCHES_CLEANUP_CALLS@@;\?%$KLP_PATCHES_CLEANUP_CALLS%;