[PATCH v2] x86/alternatives: Let __text_poke() acquire the pte lock with enabled interrupts

From: Sebastian Andrzej Siewior
Date: Thu Aug 13 2020 - 06:50:31 EST


The pte lock is never acquired in-IRQ context so it does not require the
interrupts to be disabled.

RT complains here because the spinlock_t must not be acquired with
disabled interrupts.

use_temporary_mm() expects interrupts to be off because it invokes
switch_mm_irqs_off() and uses per-CPU (current active mm) data.

Move the PTE lock handling outside the interrupt disabled region.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
v1…v2: Reword the patch description.

arch/x86/kernel/alternative.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -875,8 +875,6 @@ static void *__text_poke(void *addr, con
*/
BUG_ON(!pages[0] || (cross_page_boundary && !pages[1]));

- local_irq_save(flags);
-
/*
* Map the page without the global bit, as TLB flushing is done with
* flush_tlb_mm_range(), which is intended for non-global PTEs.
@@ -893,6 +891,8 @@ static void *__text_poke(void *addr, con
*/
VM_BUG_ON(!ptep);

+ local_irq_save(flags);
+
pte = mk_pte(pages[0], pgprot);
set_pte_at(poking_mm, poking_addr, ptep, pte);

@@ -942,8 +942,8 @@ static void *__text_poke(void *addr, con
*/
BUG_ON(memcmp(addr, opcode, len));

- pte_unmap_unlock(ptep, ptl);
local_irq_restore(flags);
+ pte_unmap_unlock(ptep, ptl);
return addr;
}