From: Joao Moreira <jmoreira@suse.de>
To: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: mbenes@suse.cz, mmarek@suse.cz, pmladek@suse.com, jikos@suse.cz,
nstange@suse.de, jroedel@suse.de, matz@suse.de,
jpoimboe@redhat.com, khlebnikov@yandex-team.ru, jeyu@kernel.org,
jmoreira@suse.de
Subject: [PATCH 6/8] modpost: Add modinfo flag to livepatch modules
Date: Tue, 29 Aug 2017 16:01:38 -0300 [thread overview]
Message-ID: <20170829190140.401-7-jmoreira@suse.de> (raw)
In-Reply-To: <20170829190140.401-1-jmoreira@suse.de>
From: Miroslav Benes <mbenes@suse.cz>
Currently, livepatch infrastructure in the kernel relies on
MODULE_INFO(livepatch, "Y") statement in a livepatch module. Then the
kernel module loader knows a module is indeed livepatch module and can
behave accordingly.
klp-convert, on the other hand relies on LIVEPATCH_* statement in the
module's Makefile for exactly the same reason.
Remove dependency on modinfo and generate MODULE_INFO flag
automatically in modpost when LIVEPATCH_* is defined in the module's
Makefile. Generate a list of all built livepatch modules based on
the .livepatch file and store it in (MODVERDIR)/livepatchmods. Give
this list as an argument for modpost which will use it to identify
livepatch modules.
As MODULE_INFO is no longer needed in the sample, remove it.
[jmoreira:
* fix modpost.c (add_livepatch_flag) to update module structure with
livepatch flag and prevent modpost from breaking due to unresolved
symbols
* remove MODULE_INFO statement
]
Signed-off-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Joao Moreira <jmoreira@suse.de>
---
samples/livepatch/livepatch-sample.c | 1 -
scripts/Makefile.modpost | 8 +++-
scripts/mod/modpost.c | 82 +++++++++++++++++++++++++++++++++---
3 files changed, 84 insertions(+), 7 deletions(-)
diff --git a/samples/livepatch/livepatch-sample.c b/samples/livepatch/livepatch-sample.c
index 84795223f15f..8bc6c4f37d77 100644
--- a/samples/livepatch/livepatch-sample.c
+++ b/samples/livepatch/livepatch-sample.c
@@ -105,4 +105,3 @@ static void livepatch_exit(void)
module_init(livepatch_init);
module_exit(livepatch_exit);
MODULE_LICENSE("GPL");
-MODULE_INFO(livepatch, "Y");
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 52264ce1b883..d87464084c44 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -64,6 +64,11 @@ MODLISTCMD := find $(MODVERDIR) -name '*.mod' | xargs -r grep -h '\.ko$$' | sort
__modules := $(shell $(MODLISTCMD))
modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
+# find all .livepatch files listed in $(MODVERDIR)/
+ifdef CONFIG_LIVEPATCH
+$(shell find $(MODVERDIR) -name '*.livepatch' | xargs -r -I{} basename {} .livepatch > $(MODVERDIR)/livepatchmods)
+endif
+
# Stop after building .o files if NOFINAL is set. Makes compile tests quicker
_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
@@ -78,7 +83,8 @@ modpost = scripts/mod/modpost \
$(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
$(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
$(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \
- $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
+ $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \
+ $(if $(CONFIG_LIVEPATCH),-l $(MODVERDIR)/livepatchmods)
MODPOST_OPT=$(subst -i,-n,$(filter -i,$(MAKEFLAGS)))
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index d9fe972ed92e..416737056bc3 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1977,10 +1977,6 @@ static void read_symbols(char *modname)
"license", license);
}
- /* Livepatch modules have unresolved symbols resolved by klp-convert */
- if (get_modinfo(info.modinfo, info.modinfo_len, "livepatch"))
- mod->livepatch = 1;
-
for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
symname = remove_dot(info.strtab + sym->st_name);
@@ -2395,6 +2391,76 @@ static void write_dump(const char *fname)
free(buf.p);
}
+struct livepatch_mod_list {
+ struct livepatch_mod_list *next;
+ char *livepatch_mod;
+};
+
+static struct livepatch_mod_list *load_livepatch_mods(const char *fname)
+{
+ struct livepatch_mod_list *list_iter, *list_start = NULL;
+ unsigned long size, pos = 0;
+ void *file = grab_file(fname, &size);
+ char *line;
+
+ if (!file)
+ return NULL;
+
+ while ((line = get_next_line(&pos, file, size))) {
+ list_iter = NOFAIL(malloc(sizeof(*list_iter)));
+ list_iter->next = list_start;
+ list_iter->livepatch_mod = NOFAIL(strdup(line));
+ list_start = list_iter;
+ }
+ release_file(file, size);
+
+ return list_start;
+}
+
+static void free_livepatch_mods(struct livepatch_mod_list *list_start)
+{
+ struct livepatch_mod_list *list_iter;
+
+ while (list_start) {
+ list_iter = list_start->next;
+ free(list_start->livepatch_mod);
+ free(list_start);
+ list_start = list_iter;
+ }
+}
+
+static int is_livepatch_mod(const char *modname,
+ struct livepatch_mod_list *list)
+{
+ const char *myname;
+
+ if (!list)
+ return 0;
+
+ myname = strrchr(modname, '/');
+ if (myname)
+ myname++;
+ else
+ myname = modname;
+
+ while (list) {
+ if (!strcmp(myname, list->livepatch_mod))
+ return 1;
+ list = list->next;
+ }
+ return 0;
+}
+
+static void add_livepatch_flag(struct buffer *b, struct module *mod,
+ struct livepatch_mod_list *list)
+{
+ if (is_livepatch_mod(mod->name, list)) {
+ buf_printf(b, "\nMODULE_INFO(livepatch, \"Y\");\n");
+ mod->livepatch = 1;
+ }
+}
+
+
struct ext_sym_list {
struct ext_sym_list *next;
const char *file;
@@ -2410,8 +2476,9 @@ int main(int argc, char **argv)
int err;
struct ext_sym_list *extsym_iter;
struct ext_sym_list *extsym_start = NULL;
+ struct livepatch_mod_list *livepatch_mods = NULL;
- while ((opt = getopt(argc, argv, "i:I:e:mnsST:o:awM:K:E")) != -1) {
+ while ((opt = getopt(argc, argv, "i:I:e:l:mnsST:o:awM:K:E")) != -1) {
switch (opt) {
case 'i':
kernel_read = optarg;
@@ -2428,6 +2495,9 @@ int main(int argc, char **argv)
extsym_iter->file = optarg;
extsym_start = extsym_iter;
break;
+ case 'l':
+ livepatch_mods = load_livepatch_mods(optarg);
+ break;
case 'm':
modversions = 1;
break;
@@ -2496,6 +2566,7 @@ int main(int argc, char **argv)
add_header(&buf, mod);
add_intree_flag(&buf, !external_module);
add_staging_flag(&buf, mod->name);
+ add_livepatch_flag(&buf, mod, livepatch_mods);
err |= add_versions(&buf, mod);
add_depends(&buf, mod, modules);
add_moddevtable(&buf, mod);
@@ -2518,6 +2589,7 @@ int main(int argc, char **argv)
"Set CONFIG_SECTION_MISMATCH_WARN_ONLY=y to allow them.\n");
}
}
+ free_livepatch_mods(livepatch_mods);
free(buf.p);
return err;
--
2.12.0
next prev parent reply other threads:[~2017-08-29 19:02 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-29 19:01 [PATCH 0/8] livepatch: klp-convert tool Joao Moreira
2017-08-29 19:01 ` [PATCH 1/8] livepatch: Create and include UAPI headers Joao Moreira
2017-08-29 19:01 ` [PATCH 2/8] kbuild: Support for Symbols.list creation Joao Moreira
2017-08-31 15:24 ` Joe Lawrence
2017-08-31 17:34 ` Josh Poimboeuf
2017-09-04 7:23 ` Joao Moreira
2017-08-29 19:01 ` [PATCH 3/8] livepatch: Add klp-convert tool Joao Moreira
2017-08-30 20:03 ` Joao Moreira
2017-08-29 19:01 ` [PATCH 4/8] livepatch: Add klp-convert annotation helpers Joao Moreira
2017-08-29 19:01 ` [PATCH 5/8] modpost: Integrate klp-convert Joao Moreira
2017-08-29 19:01 ` Joao Moreira [this message]
2017-08-29 19:01 ` [PATCH 7/8] livepatch: Add sample livepatch module Joao Moreira
2017-08-29 19:01 ` [PATCH 8/8] documentation: Update on livepatch elf format Joao Moreira
2017-08-30 18:00 ` [PATCH 0/8] livepatch: klp-convert tool Josh Poimboeuf
2017-10-10 14:17 ` Miroslav Benes
2017-10-11 2:46 ` Josh Poimboeuf
2017-10-11 12:42 ` Joao Moreira
2017-10-19 13:01 ` Josh Poimboeuf
2017-10-19 13:24 ` Miroslav Benes
2017-10-19 14:03 ` Josh Poimboeuf
2017-10-19 14:27 ` Miroslav Benes
2017-10-19 15:15 ` Josh Poimboeuf
2017-10-19 16:00 ` Miroslav Benes
2017-10-19 16:20 ` Josh Poimboeuf
2017-10-20 8:51 ` Miroslav Benes
2017-10-20 12:03 ` Josh Poimboeuf
2017-10-20 12:44 ` Torsten Duwe
2017-10-20 13:24 ` Josh Poimboeuf
2017-10-20 13:39 ` Miroslav Benes
2017-10-20 13:44 ` Torsten Duwe
2017-10-20 14:20 ` Josh Poimboeuf
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=20170829190140.401-7-jmoreira@suse.de \
--to=jmoreira@suse.de \
--cc=jeyu@kernel.org \
--cc=jikos@suse.cz \
--cc=jpoimboe@redhat.com \
--cc=jroedel@suse.de \
--cc=khlebnikov@yandex-team.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=matz@suse.de \
--cc=mbenes@suse.cz \
--cc=mmarek@suse.cz \
--cc=nstange@suse.de \
--cc=pmladek@suse.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome