Re: [[linux-yocto][linux-yocto v5.4/standard/preempt-rt/intel-x86] x86/alternatives: Acquire pte lock with interrupts enabled

2021-04-07 Thread Bruce Ashfield
Since this isn't rt-only, and is part of the upstream kernel (but
apparently not nomiated for 5.4-stable backporting), I'd prefer
to merge this to all branches, versus just the intel-x86 preempt-rt.

I'll do that tomorrow, unless I hear objections.

Bruce


In message: [[linux-yocto][linux-yocto v5.4/standard/preempt-rt/intel-x86] 
x86/alternatives: Acquire pte lock with interrupts enabled
on 07/04/2021 Jun Miao wrote:

> From: Sebastian Andrzej Siewior 
> 
> commit a6d996cbd38b42341ad3fce74506b9fdc280e395 upstream
> 
> pte lock is never acquired in-IRQ context so it does not require interrupts
> to be disabled. The lock is a regular spinlock which cannot be acquired
> with interrupts disabled on RT.
> 
> RT complains about pte_lock() in __text_poke() because it's invoked after
> disabling interrupts.
> 
> __text_poke() has to disable interrupts as 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 
> Signed-off-by: Thomas Gleixner 
> Acked-by; Peter Zijlstra (Intel) 
> Link: https://lore.kernel.org/r/20200813105026.bvugytmsso6mu...@linutronix.de
> Signed-off-by: Jun Miao 
> ---
>  arch/x86/kernel/alternative.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index c826cddae157..34a1b8562c31 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -874,8 +874,6 @@ static void *__text_poke(void *addr, const void *opcode, 
> size_t len)
>*/
>   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.
> @@ -892,6 +890,8 @@ static void *__text_poke(void *addr, const void *opcode, 
> size_t len)
>*/
>   VM_BUG_ON(!ptep);
>  
> + local_irq_save(flags);
> +
>   pte = mk_pte(pages[0], pgprot);
>   set_pte_at(poking_mm, poking_addr, ptep, pte);
>  
> @@ -941,8 +941,8 @@ static void *__text_poke(void *addr, const void *opcode, 
> size_t len)
>*/
>   BUG_ON(memcmp(addr, opcode, len));
>  
> - pte_unmap_unlock(ptep, ptl);
>   local_irq_restore(flags);
> + pte_unmap_unlock(ptep, ptl);
>   return addr;
>  }
>  
> -- 
> 2.25.1
> 

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#9716): 
https://lists.yoctoproject.org/g/linux-yocto/message/9716
Mute This Topic: https://lists.yoctoproject.org/mt/81911651/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[[linux-yocto][linux-yocto v5.4/standard/preempt-rt/intel-x86] x86/alternatives: Acquire pte lock with interrupts enabled

2021-04-07 Thread jmiao1
From: Sebastian Andrzej Siewior 

commit a6d996cbd38b42341ad3fce74506b9fdc280e395 upstream

pte lock is never acquired in-IRQ context so it does not require interrupts
to be disabled. The lock is a regular spinlock which cannot be acquired
with interrupts disabled on RT.

RT complains about pte_lock() in __text_poke() because it's invoked after
disabling interrupts.

__text_poke() has to disable interrupts as 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 
Signed-off-by: Thomas Gleixner 
Acked-by; Peter Zijlstra (Intel) 
Link: https://lore.kernel.org/r/20200813105026.bvugytmsso6mu...@linutronix.de
Signed-off-by: Jun Miao 
---
 arch/x86/kernel/alternative.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index c826cddae157..34a1b8562c31 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -874,8 +874,6 @@ static void *__text_poke(void *addr, const void *opcode, 
size_t len)
 */
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.
@@ -892,6 +890,8 @@ static void *__text_poke(void *addr, const void *opcode, 
size_t len)
 */
VM_BUG_ON(!ptep);
 
+   local_irq_save(flags);
+
pte = mk_pte(pages[0], pgprot);
set_pte_at(poking_mm, poking_addr, ptep, pte);
 
@@ -941,8 +941,8 @@ static void *__text_poke(void *addr, const void *opcode, 
size_t len)
 */
BUG_ON(memcmp(addr, opcode, len));
 
-   pte_unmap_unlock(ptep, ptl);
local_irq_restore(flags);
+   pte_unmap_unlock(ptep, ptl);
return addr;
 }
 
-- 
2.25.1


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#9706): 
https://lists.yoctoproject.org/g/linux-yocto/message/9706
Mute This Topic: https://lists.yoctoproject.org/mt/81911651/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-