ARM: Remaining PREEMPT_RT bits
Subsystems (2)
Sebastian Andrzej Siewior
maintainerv2 cover ARM: Remaining PREEMPT_RT bits
this is the last batch I have to enable PREEMPT_RT on the ARM architecture.
Last time I posted them there was some discussion about making the branch predictor hardening worse. I redid it hoping it improved now and does not make it worse.
v1…v2: https://lore.kernel.org/all/[email protected]
- Allow to enable jump-labels on UP. The UP build does not involve stop_machine(). Reworked by Arnd.
- Instead of forbidding HAVE_GUP_FAST with HIGHPTE enabled just disable HIGHPTE on PREEMPT_RT. As Arnd explained, HIGHPTE is rarely needed.
- Don't let ARCH_SUPPORTS_RT depend on HAVE_POSIX_CPU_TIMERS_TASK_WORK which in turn depends on !KVM. Since KVM has been removed from ARM it is sufficient to unconditionally allow ARCH_SUPPORTS_RT. Noted by Arnd.
Sebastian Andrzej Siewior (3):
ARM: mm: fault: Move harden_branch_predictor() before interrupts are
enabled
ARM: Disable HIGHPTE on PREEMPT_RT kernels
ARM: Allow to enable RT
Thomas Gleixner (1):
ARM: Disable jump-label on PREEMPT_RT
Yadi.hu (1):
ARM: mm: fault: Enable interrupts before invoking __do_user_fault()
arch/arm/Kconfig | 5 +++-- arch/arm/mm/fault.c | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
2.51.0
Sebastian Andrzej Siewior
maintainerPATCH v2 1/5 ARM: mm: fault: Move harden_branch_predictor() before interrupts are enabled
In the LPAE case, interrupts are enabled early in do_page_fault(). If the user attempts to access a pointer > TASK_SIZE then is invoked harden_branch_predictor(). The function will complain that CPU migration is enabled due to its smp_processor_id() usage.
The intention is invoke harden_branch_predictor() on the CPU which triggered the page fault. It is only invoked for user access of pointer
Quoted 1 line
TASK_SIZE. This always generate a fault for the user because this area
is restricted to the kernel.
Move the invocation of harden_branch_predictor() up in the call chain to the two callers do_bad_area() and do_page_fault().
Invoke it if the user accesses the >= TASK_SIZE area.
--- arch/arm/mm/fault.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
arch/arm/mm/fault.c +9 -6
@@ -183,9 +183,6 @@ __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig, {struct task_struct *tsk = current; -if (addr >TASK_SIZE ) -harden_branch_predictor (); -#ifdef CONFIG_DEBUG_USER if (((user_debug &UDBG_SEGV ) && (sig ==SIGSEGV )) || ((user_debug &UDBG_BUS ) && (sig ==SIGBUS ))) {
@@ -218,10 +215,13 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)* If we are in kernel mode at this point, we * have no context to handle this fault with. */ -if (user_mode (regs)) +if (user_mode (regs)) { +if (addr >=TASK_SIZE ) +harden_branch_predictor ();__do_user_fault (addr, fsr,SIGSEGV ,SEGV_MAPERR , regs); -else + }else {__do_kernel_fault (mm, addr, fsr, regs); + } }#ifdef CONFIG_MMU
@@ -274,8 +274,11 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)/* Enable interrupts if they were enabled in the parent context. */ -if (interrupts_enabled (regs)) +if (interrupts_enabled (regs)) { +if (user_mode (regs) && addr >=TASK_SIZE ) +harden_branch_predictor ();local_irq_enable (); + }/* * If we're in an interrupt or have no user
Signature · 1 line
2.51.0
Sebastian Andrzej Siewior
maintainerPATCH v2 2/5 ARM: mm: fault: Enable interrupts before invoking __do_user_fault()
In reply to Sebastian Andrzej SiewiorFrom: "Yadi.hu" <[email protected]>
In the !LPAE case __do_user_fault() is invoked from do_bad_area(). If a user pointer cause the page fault then a signal is sent.
Sending a signal requires to acquire sighand_struct::siglock which is a spinlock_t. On PREEMPT_RT spinlock_t becomes a sleeping spin lock which requires interrupts to be enabled. Since the calling context is user land, interrupts must have been enabled so it is fine to enable them in this case.
Enable interrupts in do_bad_area() before invoking __do_user_fault().
[bigeasy: Initial patch/ report by Yadi. Maintained the patch and redid
the patch description since]
--- arch/arm/mm/fault.c | 1 + 1 file changed, 1 insertion(+)
arch/arm/mm/fault.c +1 -0
@@ -218,6 +218,7 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)if (user_mode (regs)) {if (addr >=TASK_SIZE )harden_branch_predictor (); +local_irq_enable ();__do_user_fault (addr, fsr,SIGSEGV ,SEGV_MAPERR , regs); }else {__do_kernel_fault (mm, addr, fsr, regs);
Signature · 1 line
2.51.0
Sebastian Andrzej Siewior
maintainerPATCH v2 3/5 ARM: Disable jump-label on PREEMPT_RT
In reply to Sebastian Andrzej SiewiorFrom: Thomas Gleixner <[email protected]>
jump-labels are used to efficiently switch between two possible code paths. To achieve this, stop_machine() is used to keep the CPU in a known state while the opcode is modified. The usage of stop_machine() here leads to large latency spikes which can be observed on PREEMPT_RT.
Jump labels may change the target during runtime and are not restricted to debug or "configuration/ setup" part of a PREEMPT_RT system where high latencies could be defined as acceptable.
On 64-bit Arm, it is possible to use jump labels without the stop_machine() call, which architecturally provides a way to atomically change one 32-bit instruction word while keeping maintaining consistency, but this is not generally the case on 32-bit, in particular in thumb2 mode.
Disable jump-label support on a PREEMPT_RT system when SMP is enabled.
[bigeasy: Patch description.]
[arnd: add !SMP case, extend changelog]
--- arch/arm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Kconfig +1 -1
@@ -80,7 +80,7 @@ config ARM select HAS_IOPORT select HAVE_ARCH_AUDITSYSCALL if AEABI && !OABI_COMPAT select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6 - select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU + select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU && (!PREEMPT_RT || !SMP) select HAVE_ARCH_KFENCE if MMU && !XIP_KERNEL select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
Signature · 1 line
2.51.0
Re: [PATCH v2 3/5] ARM: Disable jump-label on PREEMPT_RT
Quoted 23 lines · Sebastian Andrzej Siewior
From: Thomas Gleixner <[email protected]>
jump-labels are used to efficiently switch between two possible code paths. To achieve this,
stop_machine()is used to keep the CPU in a known state while the opcode is modified. The usage ofstop_machine()here leads to large latency spikes which can be observed onPREEMPT_RT.Jump labels may change the target during runtime and are not restricted to debug or "configuration/ setup" part of a
PREEMPT_RTsystem where high latencies could be defined as acceptable.On 64-bit Arm, it is possible to use jump labels without the
stop_machine()call, which architecturally provides a way to atomically change one 32-bit instruction word while keeping maintaining consistency, but this is not generally the case on 32-bit, in particular in thumb2 mode.Disable jump-label support on a
PREEMPT_RTsystem when SMP is enabled.[bigeasy: Patch description.]
[arnd: add !SMP case, extend changelog]
Quoted 6 lines
Signed-off-by Thomas Gleixner <[email protected]>Cc Mark Rutland <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>Reviewed-by Linus Walleij <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>
Quoted 20 lines
--- arch/arm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/Kconfig +1
-2@@ -80,7 +80,7 @@ config ARM select HAS_IOPORT select HAVE_ARCH_AUDITSYSCALL if AEABI && !OABI_COMPAT select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6 - select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU + select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU && (!PREEMPT_RT || !SMP) select HAVE_ARCH_KFENCE if MMU && !XIP_KERNEL select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL --2.51.0
Sebastian Andrzej Siewior
maintainerPATCH v2 4/5 ARM: Disable HIGHPTE on PREEMPT_RT kernels
In reply to Sebastian Andrzej Siewiorgup_pgd_range() is invoked with disabled interrupts and invokes __kmap_local_page_prot() via pte_offset_map(), gup_p4d_range(). With HIGHPTE enabled, __kmap_local_page_prot() invokes kmap_high_get() which uses a spinlock_t via lock_kmap_any(). This leads to an sleeping-while-atomic error on PREEMPT_RT because spinlock_t becomes a sleeping lock and must not be acquired in atomic context.
The loop in map_new_virtual() uses wait_queue_head_t for wake up which also is using a spinlock_t.
Since HIGHPTE is rarely needed at all, turn it off for PREEMPT_RT to allow the use of get_user_pages_fast().
[arnd: rework patch to turn off HIGHPTE instead of HAVE_PAST_GUP]
--- arch/arm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Kconfig +1 -1
@@ -1213,7 +1213,7 @@ config HIGHMEM config HIGHPTE bool "Allocate 2nd-level pagetables from highmem" if EXPERT - depends on HIGHMEM + depends on HIGHMEM && !PREEMPT_RT default y help The VM uses one page of physical memory for each page table.
Signature · 1 line
2.51.0
Sebastian Andrzej Siewior
maintainerPATCH v2 5/5 ARM: Allow to enable RT
In reply to Sebastian Andrzej SiewiorAll known issues have been adressed.
Allow to select RT.
--- arch/arm/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/Kconfig +1 -0
@@ -41,6 +41,7 @@ config ARM select ARCH_SUPPORTS_CFI select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE select ARCH_SUPPORTS_PER_VMA_LOCK + select ARCH_SUPPORTS_RT select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_MEMTEST
Signature · 1 line
2.51.0
Quoted 10 lines · Sebastian Andrzej Siewior
this is the last batch I have to enable
PREEMPT_RTon the ARM architecture.
Last time I posted them there was some discussion about making the branch predictor hardening worse. I redid it hoping it improved now and does not make it worse.v1…v2: https://lore.kernel.org/all/[email protected]
- Allow to enable jump-labels on UP. The UP build does not involvestop_machine(). Reworked by Arnd.
Quoted 8 lines
- Instead of forbidding
HAVE_GUP_FASTwith HIGHPTE enabled just disable HIGHPTE onPREEMPT_RT. As Arnd explained, HIGHPTE is rarely needed.- Don't let
ARCH_SUPPORTS_RTdepend onHAVE_POSIX_CPU_TIMERS_TASK_WORKwhich in turn depends on !KVM. Since KVM has been removed from ARM it is sufficient to unconditionally allowARCH_SUPPORTS_RT. Noted by Arnd.
Whole series
Looks all good to me. The first two patches may clash with the work on generic entry that I think Linus Walleij (added to Cc) is in the process of rebasing, but I think that is fine:
hopefully the special case that you adding here will just go away after Linus' patches, so everything should be fine regardless of which gets merged first.
Linus, can you have a look and confirm?
Arnd
Linus Walleij
Acked-byQuoted 24 lines · Arnd Bergmann
Quoted 10 lines · Sebastian Andrzej Siewior
this is the last batch I have to enable
PREEMPT_RTon the ARM architecture.
Last time I posted them there was some discussion about making the branch predictor hardening worse. I redid it hoping it improved now and does not make it worse.v1…v2: https://lore.kernel.org/all/[email protected]
- Allow to enable jump-labels on UP. The UP build does not involvestop_machine(). Reworked by Arnd.Quoted 8 lines
- Instead of forbidding
HAVE_GUP_FASTwith HIGHPTE enabled just disable HIGHPTE onPREEMPT_RT. As Arnd explained, HIGHPTE is rarely needed.- Don't let
ARCH_SUPPORTS_RTdepend onHAVE_POSIX_CPU_TIMERS_TASK_WORKwhich in turn depends on !KVM. Since KVM has been removed from ARM it is sufficient to unconditionally allowARCH_SUPPORTS_RT. Noted by Arnd.Whole series
Reviewed-by Arnd Bergmann <[email protected]>
Quoted 8 lines
Looks all good to me. The first two patches may clash with the work on generic entry that I think Linus Walleij (added to Cc) is in the process of rebasing, but I think that is fine:
hopefully the special case that you adding here will just go away after Linus' patches, so everything should be fine regardless of which gets merged first.Linus, can you have a look and confirm?
The patches look fine to me, the series:
(nevermind the kernel.org address on this mail, it's because the mail is not in my other inbox because of something...)
The generic entry is mainly about getting rid of the old RCU context tracker and ridding some lockdep warnings and I am in the process of splitting off the irqentry parts and send separately.
I think these patches are good to go.
Yours,
Linus Walleij