From: Josh Poimboeuf <jpoimboe@redhat.com>
To: live-patching@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Jessica Yu <jeyu@kernel.org>,
Joe Lawrence <joe.lawrence@redhat.com>,
Miroslav Benes <mbenes@suse.cz>
Subject: [PATCH v4 10/11] x86/module: Use text_mutex in apply_relocate_add()
Date: Wed, 29 Apr 2020 10:24:52 -0500 [thread overview]
Message-ID: <506017e7d3e0d86a1c6409418c87516d8baeaa5e.1588173720.git.jpoimboe@redhat.com> (raw)
In-Reply-To: <cover.1588173720.git.jpoimboe@redhat.com>
Now that the livepatch code no longer needs the text_mutex for changing
module permissions, move its usage down to apply_relocate_add().
Note the s390 version of apply_relocate_add() doesn't need to use the
text_mutex because it already uses s390_kernel_write_lock, which
accomplishes the same task.
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
---
arch/x86/kernel/module.c | 9 +++++++--
kernel/livepatch/core.c | 6 ------
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 7614f478fd7a..23c95a53d20e 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -18,6 +18,7 @@
#include <linux/gfp.h>
#include <linux/jump_label.h>
#include <linux/random.h>
+#include <linux/memory.h>
#include <asm/text-patching.h>
#include <asm/page.h>
@@ -227,14 +228,18 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
bool early = me->state == MODULE_STATE_UNFORMED;
void *(*write)(void *, const void *, size_t) = memcpy;
- if (!early)
+ if (!early) {
write = text_poke;
+ mutex_lock(&text_mutex);
+ }
ret = __apply_relocate_add(sechdrs, strtab, symindex, relsec, me,
write);
- if (!early)
+ if (!early) {
text_poke_sync();
+ mutex_unlock(&text_mutex);
+ }
return ret;
}
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 6b8b3c067be0..96d2da14eb0d 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -775,9 +775,6 @@ static int klp_init_object_loaded(struct klp_patch *patch,
int ret;
if (klp_is_module(obj)) {
-
- mutex_lock(&text_mutex);
-
/*
* Only write module-specific relocations here
* (.klp.rela.{module}.*). vmlinux-specific relocations were
@@ -785,9 +782,6 @@ static int klp_init_object_loaded(struct klp_patch *patch,
* itself.
*/
ret = klp_apply_object_relocs(patch, obj);
-
- mutex_unlock(&text_mutex);
-
if (ret)
return ret;
}
--
2.21.1
next prev parent reply other threads:[~2020-04-29 15:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 15:24 [PATCH v4 00/11] livepatch,module: Remove .klp.arch and module_disable_ro() Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 01/11] livepatch: Disallow vmlinux.ko Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 02/11] livepatch: Apply vmlinux-specific KLP relocations early Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 03/11] livepatch: Remove .klp.arch Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 04/11] livepatch: Prevent module-specific KLP rela sections from referencing vmlinux symbols Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 05/11] s390: Change s390_kernel_write() return type to match memcpy() Josh Poimboeuf
2020-05-07 13:36 ` Jiri Kosina
2020-05-07 16:01 ` Gerald Schaefer
2020-04-29 15:24 ` [PATCH v4 06/11] s390/module: Use s390_kernel_write() for late relocations Josh Poimboeuf
2020-05-07 10:00 ` Jiri Kosina
2020-05-07 12:27 ` Gerald Schaefer
2020-04-29 15:24 ` [PATCH v4 07/11] x86/module: Use text_poke() " Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 08/11] livepatch: Remove module_disable_ro() usage Josh Poimboeuf
2020-04-29 15:24 ` [PATCH v4 09/11] module: Remove module_disable_ro() Josh Poimboeuf
2020-04-29 15:24 ` Josh Poimboeuf [this message]
2020-04-29 15:24 ` [PATCH v4 11/11] module: Make module_enable_ro() static again Josh Poimboeuf
2020-04-30 11:10 ` Jessica Yu
2020-04-30 11:35 ` Miroslav Benes
2020-04-30 11:40 ` Jessica Yu
2020-04-30 12:23 ` Jessica Yu
2020-06-05 13:24 ` Guenter Roeck
2020-06-05 14:20 ` Jessica Yu
2020-06-05 14:39 ` Josh Poimboeuf
2020-04-30 11:33 ` [PATCH v4 00/11] livepatch,module: Remove .klp.arch and module_disable_ro() Jessica Yu
2020-05-04 22:20 ` Jiri Kosina
2020-05-07 22:17 ` Jiri Kosina
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=506017e7d3e0d86a1c6409418c87516d8baeaa5e.1588173720.git.jpoimboe@redhat.com \
--to=jpoimboe@redhat.com \
--cc=jeyu@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).