Skip to content

Commit 9222f60

Browse files
Jiri KosinaKAGA-KOKO
authored andcommitted
x86/alternatives: Lockdep-enforce text_mutex in text_poke*()
text_poke() and text_poke_bp() must be called with text_mutex held. Put proper lockdep anotation in place instead of just mentioning the requirement in a comment. Reported-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Andy Lutomirski <luto@kernel.org> Link: https://lkml.kernel.org/r/nycvar.YFH.7.76.1808280853520.25787@cbobk.fhfr.pm
1 parent f12d11c commit 9222f60

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/x86/kernel/alternative.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,6 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
684684
* It means the size must be writable atomically and the address must be aligned
685685
* in a way that permits an atomic write. It also makes sure we fit on a single
686686
* page.
687-
*
688-
* Note: Must be called under text_mutex.
689687
*/
690688
void *text_poke(void *addr, const void *opcode, size_t len)
691689
{
@@ -700,6 +698,8 @@ void *text_poke(void *addr, const void *opcode, size_t len)
700698
*/
701699
BUG_ON(!after_bootmem);
702700

701+
lockdep_assert_held(&text_mutex);
702+
703703
if (!core_kernel_text((unsigned long)addr)) {
704704
pages[0] = vmalloc_to_page(addr);
705705
pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
@@ -782,8 +782,6 @@ int poke_int3_handler(struct pt_regs *regs)
782782
* - replace the first byte (int3) by the first byte of
783783
* replacing opcode
784784
* - sync cores
785-
*
786-
* Note: must be called under text_mutex.
787785
*/
788786
void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
789787
{
@@ -792,6 +790,9 @@ void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
792790
bp_int3_handler = handler;
793791
bp_int3_addr = (u8 *)addr + sizeof(int3);
794792
bp_patching_in_progress = true;
793+
794+
lockdep_assert_held(&text_mutex);
795+
795796
/*
796797
* Corresponding read barrier in int3 notifier for making sure the
797798
* in_progress and handler are correctly ordered wrt. patching.

0 commit comments

Comments
 (0)