Skip to contentSkip to conversation

Backport PREEMPT-RT support for ARM 32-bit

RFC PATCH Superseded Jan Kiszka 3 participants 19 messages May 5 – May 12 Arm (32-bit)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

cover Backport PREEMPT-RT support for ARM 32-bit

A first attempt to backport the recently merged ARM 32-bit support of PREEMPT-RT from 7.1 to 6.12-cip. Only lightly tested so far, first of all looking for feedback regarding completeness.

This may also be valuable for 6.12-rt as this series should be able to replace all patches tagged with {ARM:,arm:} in v6.12.79-rt17 - adding Daniel.

Jan

Russell King (Oracle) (10):
ARM: group is_permission_fault() with is_translation_fault()
ARM: allow __do_kernel_fault() to report execution of memory faults
ARM: fix hash_name() fault
ARM: fix branch predictor hardening
ARM: ensure interrupts are enabled in __do_user_fault()
ARM: move vmalloc() lazy-page table population
ARM: move is_permission_fault() and is_translation_fault() to fault.h
ARM: use BIT() and GENMASK() for fault status register fields
ARM: move FSR fault status definitions before fsr_fs()
ARM: provide individual is_translation_fault() and
is_permission_fault()

Sebastian Andrzej Siewior (1):
ARM: 9463/1: Allow to enable RT

Thomas Gleixner (1):
ARM: 9459/1: Disable jump-label on PREEMPT_RT

 arch/arm/Kconfig        |   3 +-
 arch/arm/mm/alignment.c |   6 +-
 arch/arm/mm/fault.c     | 222 +++++++++++++++++++++++-----------------
 arch/arm/mm/fault.h     |  42 ++++++--
 4 files changed, 173 insertions(+), 100 deletions(-)
Signature · 1 line
2.47.3
author
#1 lore raw

RFC PATCH 1/12 ARM: group is_permission_fault() with is_translation_fault()

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 29ba26af9a9d43d5dbb8aa8e653adeb159d42587 ]

Group is_permission_fault() with is_translation_fault(), which is needed to use is_permission_fault() in __do_kernel_fault(). As this is static inline, there is no need for this to be under CONFIG_MMU.

---
 arch/arm/mm/fault.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/arm/mm/fault.c +13 -13
index ab01b51de5590..4dca7b75ae5e4 100644
@@ -128,6 +128,19 @@ static inline bool is_translation_fault(unsigned int fsr)
 	return false;
 }
 
+static inline bool is_permission_fault(unsigned int fsr)
+{
+	int fs = fsr_fs(fsr);
+#ifdef CONFIG_ARM_LPAE
+	if ((fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL)
+		return true;
+#else
+	if (fs == FS_L1_PERM || fs == FS_L2_PERM)
+		return true;
+#endif
+	return false;
+}
+
 static void die_kernel_fault(const char *msg, struct mm_struct *mm,
 			     unsigned long addr, unsigned int fsr,
 			     struct pt_regs *regs)
@@ -226,19 +239,6 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 }
 
 #ifdef CONFIG_MMU
-static inline bool is_permission_fault(unsigned int fsr)
-{
-	int fs = fsr_fs(fsr);
-#ifdef CONFIG_ARM_LPAE
-	if ((fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL)
-		return true;
-#else
-	if (fs == FS_L1_PERM || fs == FS_L2_PERM)
-		return true;
-#endif
-	return false;
-}
-
 #ifdef CONFIG_CPU_TTBR0_PAN
 static inline bool ttbr0_usermode_access_allowed(struct pt_regs *regs)
 {
Signature · 1 line
2.47.3
author
#2 lore raw

RFC PATCH 2/12 ARM: allow __do_kernel_fault() to report execution of memory faults

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 40b466db1dffb41f0529035c59c5739636d0e5b8 ]

Allow __do_kernel_fault() to detect the execution of memory, so we can provide the same fault message as do_page_fault() would do. This is required when we split the kernel address fault handling from the main do_page_fault() code path.

---
 arch/arm/mm/fault.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/mm/fault.c +2 -0
index 4dca7b75ae5e4..1d052d3c767d9 100644
@@ -176,6 +176,8 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
 	 */
 	if (addr < PAGE_SIZE) {
 		msg = "NULL pointer dereference";
+	} else if (is_permission_fault(fsr) && fsr & FSR_LNX_PF) {
+		msg = "execution of memory";
 	} else {
 		if (is_translation_fault(fsr) &&
 		    kfence_handle_page_fault(addr, is_write_fault(fsr), regs))
Signature · 1 line
2.47.3
author
#3 lore raw

RFC PATCH 3/12 ARM: fix hash_name() fault

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 7733bc7d299d682f2723dc38fc7f370b9bf973e9 ]

Zizhi Wo reports:

"During the execution of hash_name()->load_unaligned_zeropad(), a
potential memory access beyond the PAGE boundary may occur. For example, when the filename length is near the PAGE_SIZE boundary. This triggers a page fault, which leads to a call to do_page_fault()->mmap_read_trylock(). If we can't acquire the lock, we have to fall back to the mmap_read_lock() path, which calls might_sleep(). This breaks RCU semantics because path lookup occurs under an RCU read-side critical section."

This is seen with CONFIG_DEBUG_ATOMIC_SLEEP=y and CONFIG_KFENCE=y.

Kernel addresses (with the exception of the vectors/kuser helper page) do not have VMAs associated with them. If the vectors/kuser helper page faults, then there are two possibilities:

1. if the fault happened while in kernel mode, then we're basically dead, because the CPU won't be able to vector through this page to handle the fault.
2. if the fault happened while in user mode, that means the page was protected from user access, and we want to fault anyway.

Thus, we can handle kernel addresses from any context entirely separately without going anywhere near the mmap lock. This gives us an entirely non-sleeping path for all kernel mode kernel address faults.

As we handle the kernel address faults before interrupts are enabled, this change has the side effect of improving the branch predictor hardening, but does not completely solve the issue.

---
 arch/arm/mm/fault.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
arch/arm/mm/fault.c +35 -0
index 1d052d3c767d9..8768c70fd885b 100644
@@ -262,6 +262,35 @@ static inline bool ttbr0_usermode_access_allowed(struct pt_regs *regs)
 }
 #endif
 
+static int __kprobes
+do_kernel_address_page_fault(struct mm_struct *mm, unsigned long addr,
+			     unsigned int fsr, struct pt_regs *regs)
+{
+	if (user_mode(regs)) {
+		/*
+		 * Fault from user mode for a kernel space address. User mode
+		 * should not be faulting in kernel space, which includes the
+		 * vector/khelper page. Send a SIGSEGV.
+		 */
+		__do_user_fault(addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
+	} else {
+		/*
+		 * Fault from kernel mode. Enable interrupts if they were
+		 * enabled in the parent context. Section (upper page table)
+		 * translation faults are handled via do_translation_fault(),
+		 * so we will only get here for a non-present kernel space
+		 * PTE or PTE permission fault. This may happen in exceptional
+		 * circumstances and need the fixup tables to be walked.
+		 */
+		if (interrupts_enabled(regs))
+			local_irq_enable();
+
+		__do_kernel_fault(mm, addr, fsr, regs);
+	}
+
+	return 0;
+}
+
 static int __kprobes
 do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 {
@@ -275,6 +304,12 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	if (kprobe_page_fault(regs, fsr))
 		return 0;
 
+	/*
+	 * Handle kernel addresses faults separately, which avoids touching
+	 * the mmap lock from contexts that are not able to sleep.
+	 */
+	if (addr >= TASK_SIZE)
+		return do_kernel_address_page_fault(mm, addr, fsr, regs);
 
 	/* Enable interrupts if they were enabled in the parent context. */
 	if (interrupts_enabled(regs))
Signature · 1 line
2.47.3
author
#4 lore raw

RFC PATCH 4/12 ARM: fix branch predictor hardening

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit fd2dee1c6e2256f726ba33fd3083a7be0efc80d3 ]

__do_user_fault() may be called with indeterminent interrupt enable state, which means we may be preemptive at this point. This causes problems when calling harden_branch_predictor(). For example, when called from a data abort, do_alignment_fault()->do_bad_area().

Move harden_branch_predictor() out of __do_user_fault() and into the calling contexts.

Moving it into do_kernel_address_page_fault(), we can be sure that interrupts will be disabled here.

Converting do_translation_fault() to use do_kernel_address_page_fault() rather than do_bad_area() means that we keep branch predictor handling for translation faults. Interrupts will also be disabled at this call site.

do_sect_fault() needs special handling, so detect user mode accesses to kernel-addresses, and add an explicit call to branch predictor hardening.

Finally, add branch predictor hardening to do_alignment() for the faulting case (user mode accessing kernel addresses) before interrupts are enabled.

This should cover all cases where harden_branch_predictor() is called, ensuring that it is always has interrupts disabled, also ensuring that it is called early in each call path.

---
 arch/arm/mm/alignment.c |  6 +++++-
 arch/arm/mm/fault.c     | 39 ++++++++++++++++++++++++++-------------
 2 files changed, 31 insertions(+), 14 deletions(-)
arch/arm/mm/alignment.c +5 -1
index 3c6ddb1afdc46..812380f30ae36 100644
@@ -19,10 +19,11 @@
 #include <linux/init.h>
 #include <linux/sched/signal.h>
 #include <linux/uaccess.h>
+#include <linux/unaligned.h>
 
 #include <asm/cp15.h>
 #include <asm/system_info.h>
-#include <linux/unaligned.h>
+#include <asm/system_misc.h>
 #include <asm/opcodes.h>
 
 #include "fault.h"
@@ -809,6 +810,9 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	int thumb2_32b = 0;
 	int fault;
 
+	if (addr >= TASK_SIZE && user_mode(regs))
+		harden_branch_predictor();
+
 	if (interrupts_enabled(regs))
 		local_irq_enable();
 
arch/arm/mm/fault.c +26 -13
index 8768c70fd885b..16b5a7d214808 100644
@@ -199,9 +199,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))) {
@@ -270,8 +267,10 @@ do_kernel_address_page_fault(struct mm_struct *mm, unsigned long addr,
 		/*
 		 * Fault from user mode for a kernel space address. User mode
 		 * should not be faulting in kernel space, which includes the
-		 * vector/khelper page. Send a SIGSEGV.
+		 * vector/khelper page. Handle the branch predictor hardening
+		 * while interrupts are still disabled, then send a SIGSEGV.
 		 */
+		harden_branch_predictor();
 		__do_user_fault(addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
 	} else {
 		/*
@@ -486,16 +485,20 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  * We enter here because the first level page table doesn't contain
  * a valid entry for the address.
  *
- * If the address is in kernel space (>= TASK_SIZE), then we are
- * probably faulting in the vmalloc() area.
+ * If this is a user address (addr < TASK_SIZE), we handle this as a
+ * normal page fault. This leaves the remainder of the function to handle
+ * kernel address translation faults.
  *
- * If the init_task's first level page tables contains the relevant
- * entry, we copy the it to this task.  If not, we send the process
- * a signal, fixup the exception, or oops the kernel.
+ * Since user mode is not permitted to access kernel addresses, pass these
+ * directly to do_kernel_address_page_fault() to handle.
  *
- * NOTE! We MUST NOT take any locks for this case. We may be in an
- * interrupt or a critical region, and should only copy the information
- * from the master page table, nothing more.
+ * Otherwise, we're probably faulting in the vmalloc() area, so try to fix
+ * that up. Note that we must not take any locks or enable interrupts in
+ * this case.
+ *
+ * If vmalloc() fixup fails, that means the non-leaf page tables did not
+ * contain an entry for this address, so handle this via
+ * do_kernel_address_page_fault().
  */
 #ifdef CONFIG_MMU
 static int __kprobes
@@ -561,7 +564,8 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
 	return 0;
 
 bad_area:
-	do_bad_area(addr, fsr, regs);
+	do_kernel_address_page_fault(current->mm, addr, fsr, regs);
+
 	return 0;
 }
 #else					/* CONFIG_MMU */
@@ -581,7 +585,16 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
 static int
 do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 {
+	/*
+	 * If this is a kernel address, but from user mode, then userspace
+	 * is trying bad stuff. Invoke the branch predictor handling.
+	 * Interrupts are disabled here.
+	 */
+	if (addr >= TASK_SIZE && user_mode(regs))
+		harden_branch_predictor();
+
 	do_bad_area(addr, fsr, regs);
+
 	return 0;
 }
 #endif /* CONFIG_ARM_LPAE */
Signature · 1 line
2.47.3
author
#5 lore raw

RFC PATCH 5/12 ARM: 9459/1: Disable jump-label on PREEMPT_RT

In reply to Jan Kiszka

From: Thomas Gleixner <[email protected]>

[ Upstream commit 256d97d3587b441630c345ab3d773a9e7dcd964b ]

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
index cc8beccc4e86d..4be68e77b9594 100644
@@ -79,7 +79,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.47.3
author
#6 lore raw

RFC PATCH 6/12 ARM: ensure interrupts are enabled in __do_user_fault()

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 59e4f3b45b96a24fc9b7a89e5f8a2168b30f95af ]

__do_user_fault() may be called from fault handling paths where the interrupts are enabled or disabled. E.g. do_page_fault() calls this with interrupts enabled, whereas do_sect_fault()->do_bad_area() will call this with interrupts disabled. Since this is a userspace fault, we know that interrupts were enabled in the parent context, so call local_irq_enable() here to give a consistent interrupt state.

This is necessary for force_sig_info() when PREEMPT_RT is enabled.

---
 arch/arm/mm/fault.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/mm/fault.c +5 -1
index 16b5a7d214808..dd78cbef87c85 100644
@@ -191,7 +191,8 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
 
 /*
  * Something tried to access memory that isn't in our memory map..
- * User mode accesses just cause a SIGSEGV
+ * User mode accesses just cause a SIGSEGV. Ensure interrupts are enabled
+ * for preempt RT.
  */
 static void
 __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,
@@ -199,6 +200,8 @@ __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,
 {
 	struct task_struct *tsk = current;
 
+	local_irq_enable();
+
 #ifdef CONFIG_DEBUG_USER
 	if (((user_debug & UDBG_SEGV) && (sig == SIGSEGV)) ||
 	    ((user_debug & UDBG_BUS)  && (sig == SIGBUS))) {
@@ -269,6 +272,7 @@ do_kernel_address_page_fault(struct mm_struct *mm, unsigned long addr,
 		 * should not be faulting in kernel space, which includes the
 		 * vector/khelper page. Handle the branch predictor hardening
 		 * while interrupts are still disabled, then send a SIGSEGV.
+		 * Note that __do_user_fault() will enable interrupts.
 		 */
 		harden_branch_predictor();
 		__do_user_fault(addr, fsr, SIGSEGV, SEGV_MAPERR, regs);
Signature · 1 line
2.47.3
author
#7 lore raw

RFC PATCH 7/12 ARM: move vmalloc() lazy-page table population

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 78900204851708bbe761c3acf641ad60f15c922f ]

Split the vmalloc() lazy-page table population from do_translation_fault() into a new vmalloc_fault() function.

---
 arch/arm/mm/fault.c | 126 ++++++++++++++++++++++++--------------------
 1 file changed, 68 insertions(+), 58 deletions(-)
arch/arm/mm/fault.c +68 -58
index dd78cbef87c85..fabaefa26bb1c 100644
@@ -262,6 +262,70 @@ static inline bool ttbr0_usermode_access_allowed(struct pt_regs *regs)
 }
 #endif
 
+/*
+ * Handle a vmalloc fault, copying the non-leaf page table entries from
+ * init_mm.pgd. Any kernel context can trigger this, so we must not sleep
+ * or enable interrupts. Having two CPUs execute this for the same page is
+ * no problem, we'll just copy the same data twice.
+ *
+ * Returns false on failure.
+ */
+static bool __kprobes __maybe_unused vmalloc_fault(unsigned long addr)
+{
+	unsigned int index;
+	pgd_t *pgd, *pgd_k;
+	p4d_t *p4d, *p4d_k;
+	pud_t *pud, *pud_k;
+	pmd_t *pmd, *pmd_k;
+
+	index = pgd_index(addr);
+
+	pgd = cpu_get_pgd() + index;
+	pgd_k = init_mm.pgd + index;
+
+	p4d = p4d_offset(pgd, addr);
+	p4d_k = p4d_offset(pgd_k, addr);
+
+	if (p4d_none(*p4d_k))
+		return false;
+	if (!p4d_present(*p4d))
+		set_p4d(p4d, *p4d_k);
+
+	pud = pud_offset(p4d, addr);
+	pud_k = pud_offset(p4d_k, addr);
+
+	if (pud_none(*pud_k))
+		return false;
+	if (!pud_present(*pud))
+		set_pud(pud, *pud_k);
+
+	pmd = pmd_offset(pud, addr);
+	pmd_k = pmd_offset(pud_k, addr);
+
+#ifdef CONFIG_ARM_LPAE
+	/*
+	 * Only one hardware entry per PMD with LPAE.
+	 */
+	index = 0;
+#else
+	/*
+	 * On ARM one Linux PGD entry contains two hardware entries (see page
+	 * tables layout in pgtable.h). We normally guarantee that we always
+	 * fill both L1 entries. But create_mapping() doesn't follow the rule.
+	 * It can create inidividual L1 entries, so here we have to call
+	 * pmd_none() check for the entry really corresponded to address, not
+	 * for the first of pair.
+	 */
+	index = (addr >> SECTION_SHIFT) & 1;
+#endif
+	if (pmd_none(pmd_k[index]))
+		return false;
+
+	copy_pmd(pmd, pmd_k);
+
+	return true;
+}
+
 static int __kprobes
 do_kernel_address_page_fault(struct mm_struct *mm, unsigned long addr,
 			     unsigned int fsr, struct pt_regs *regs)
@@ -497,10 +561,9 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  * directly to do_kernel_address_page_fault() to handle.
  *
  * Otherwise, we're probably faulting in the vmalloc() area, so try to fix
- * that up. Note that we must not take any locks or enable interrupts in
- * this case.
+ * that up via vmalloc_fault().
  *
- * If vmalloc() fixup fails, that means the non-leaf page tables did not
+ * If vmalloc_fault() fails, that means the non-leaf page tables did not
  * contain an entry for this address, so handle this via
  * do_kernel_address_page_fault().
  */
@@ -509,65 +572,12 @@ static int __kprobes
 do_translation_fault(unsigned long addr, unsigned int fsr,
 		     struct pt_regs *regs)
 {
-	unsigned int index;
-	pgd_t *pgd, *pgd_k;
-	p4d_t *p4d, *p4d_k;
-	pud_t *pud, *pud_k;
-	pmd_t *pmd, *pmd_k;
-
 	if (addr < TASK_SIZE)
 		return do_page_fault(addr, fsr, regs);
 
-	if (user_mode(regs))
-		goto bad_area;
-
-	index = pgd_index(addr);
-
-	pgd = cpu_get_pgd() + index;
-	pgd_k = init_mm.pgd + index;
-
-	p4d = p4d_offset(pgd, addr);
-	p4d_k = p4d_offset(pgd_k, addr);
-
-	if (p4d_none(*p4d_k))
-		goto bad_area;
-	if (!p4d_present(*p4d))
-		set_p4d(p4d, *p4d_k);
-
-	pud = pud_offset(p4d, addr);
-	pud_k = pud_offset(p4d_k, addr);
-
-	if (pud_none(*pud_k))
-		goto bad_area;
-	if (!pud_present(*pud))
-		set_pud(pud, *pud_k);
-
-	pmd = pmd_offset(pud, addr);
-	pmd_k = pmd_offset(pud_k, addr);
-
-#ifdef CONFIG_ARM_LPAE
-	/*
-	 * Only one hardware entry per PMD with LPAE.
-	 */
-	index = 0;
-#else
-	/*
-	 * On ARM one Linux PGD entry contains two hardware entries (see page
-	 * tables layout in pgtable.h). We normally guarantee that we always
-	 * fill both L1 entries. But create_mapping() doesn't follow the rule.
-	 * It can create inidividual L1 entries, so here we have to call
-	 * pmd_none() check for the entry really corresponded to address, not
-	 * for the first of pair.
-	 */
-	index = (addr >> SECTION_SHIFT) & 1;
-#endif
-	if (pmd_none(pmd_k[index]))
-		goto bad_area;
-
-	copy_pmd(pmd, pmd_k);
-	return 0;
+	if (!user_mode(regs) && vmalloc_fault(addr))
+		return 0;
 
-bad_area:
 	do_kernel_address_page_fault(current->mm, addr, fsr, regs);
 
 	return 0;
Signature · 1 line
2.47.3
author
#8 lore raw

RFC PATCH 8/12 ARM: move is_permission_fault() and is_translation_fault() to fault.h

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 9c46fcaf2efa78e814e102c5828cf5c825a133ec ]

is_permission_fault() and is_translation_fault() are both conditional on the FSR encodings, which are dependent on LPAE. We define the constants in fault.h. Move these inline functions to fault.h to be near the FSR definitions.

---
 arch/arm/mm/fault.c | 26 --------------------------
 arch/arm/mm/fault.h | 26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 26 deletions(-)
arch/arm/mm/fault.c +0 -26
index fabaefa26bb1c..04c2b48e02adc 100644
@@ -115,32 +115,6 @@ static inline bool is_write_fault(unsigned int fsr)
 	return (fsr & FSR_WRITE) && !(fsr & FSR_CM);
 }
 
-static inline bool is_translation_fault(unsigned int fsr)
-{
-	int fs = fsr_fs(fsr);
-#ifdef CONFIG_ARM_LPAE
-	if ((fs & FS_MMU_NOLL_MASK) == FS_TRANS_NOLL)
-		return true;
-#else
-	if (fs == FS_L1_TRANS || fs == FS_L2_TRANS)
-		return true;
-#endif
-	return false;
-}
-
-static inline bool is_permission_fault(unsigned int fsr)
-{
-	int fs = fsr_fs(fsr);
-#ifdef CONFIG_ARM_LPAE
-	if ((fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL)
-		return true;
-#else
-	if (fs == FS_L1_PERM || fs == FS_L2_PERM)
-		return true;
-#endif
-	return false;
-}
-
 static void die_kernel_fault(const char *msg, struct mm_struct *mm,
 			     unsigned long addr, unsigned int fsr,
 			     struct pt_regs *regs)
arch/arm/mm/fault.h +26 -0
index e8f8c19025444..e95f44757dc96 100644
@@ -35,6 +35,32 @@ static inline int fsr_fs(unsigned int fsr)
 }
 #endif
 
+static inline bool is_translation_fault(unsigned int fsr)
+{
+	int fs = fsr_fs(fsr);
+#ifdef CONFIG_ARM_LPAE
+	if ((fs & FS_MMU_NOLL_MASK) == FS_TRANS_NOLL)
+		return true;
+#else
+	if (fs == FS_L1_TRANS || fs == FS_L2_TRANS)
+		return true;
+#endif
+	return false;
+}
+
+static inline bool is_permission_fault(unsigned int fsr)
+{
+	int fs = fsr_fs(fsr);
+#ifdef CONFIG_ARM_LPAE
+	if ((fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL)
+		return true;
+#else
+	if (fs == FS_L1_PERM || fs == FS_L2_PERM)
+		return true;
+#endif
+	return false;
+}
+
 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
 void early_abt_enable(void);
 asmlinkage void do_DataAbort(unsigned long addr, unsigned int fsr,
Signature · 1 line
2.47.3
author
#9 lore raw

RFC PATCH 9/12 ARM: use BIT() and GENMASK() for fault status register fields

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit 5548e8a4663d9decc8215c53e4a41c704f183cbb ]

Modernise the fault status field definitions by using BIT() and GENMASK().

---
 arch/arm/mm/fault.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm/mm/fault.h +6 -6
index e95f44757dc96..d2bdedaefe149 100644
@@ -5,12 +5,12 @@
 /*
  * Fault status register encodings.  We steal bit 31 for our own purposes.
  */
-#define FSR_LNX_PF		(1 << 31)
-#define FSR_CM			(1 << 13)
-#define FSR_WRITE		(1 << 11)
-#define FSR_FS4			(1 << 10)
-#define FSR_FS3_0		(15)
-#define FSR_FS5_0		(0x3f)
+#define FSR_LNX_PF		BIT(31)
+#define FSR_CM			BIT(13)
+#define FSR_WRITE		BIT(11)
+#define FSR_FS4			BIT(10)
+#define FSR_FS3_0		GENMASK(3, 0)
+#define FSR_FS5_0		GENMASK(5, 0)
 
 #ifdef CONFIG_ARM_LPAE
 #define FSR_FS_AEA		17
Signature · 1 line
2.47.3
author
#10 lore raw

RFC PATCH 10/12 ARM: move FSR fault status definitions before fsr_fs()

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit a542de4451093f310d20e3d65d62ab4f4d38241f ]

The FSR's fault status bits depend on whether LPAE is enabled. Rather than always exposing both LPAE and non-LPAE to all code, move them inside the ifdef blocks dependent on LPAE to restrict their visibility. No code other than fsr_fs() makes use of these.

---
 arch/arm/mm/fault.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/arm/mm/fault.h +5 -3
index d2bdedaefe149..44c0fad29cce3 100644
@@ -8,9 +8,6 @@
 #define FSR_LNX_PF		BIT(31)
 #define FSR_CM			BIT(13)
 #define FSR_WRITE		BIT(11)
-#define FSR_FS4			BIT(10)
-#define FSR_FS3_0		GENMASK(3, 0)
-#define FSR_FS5_0		GENMASK(5, 0)
 
 #ifdef CONFIG_ARM_LPAE
 #define FSR_FS_AEA		17
@@ -18,6 +15,8 @@
 #define FS_PERM_NOLL		0xC
 #define FS_MMU_NOLL_MASK	0x3C
 
+#define FSR_FS5_0		GENMASK(5, 0)
+
 static inline int fsr_fs(unsigned int fsr)
 {
 	return fsr & FSR_FS5_0;
@@ -29,6 +28,9 @@ static inline int fsr_fs(unsigned int fsr)
 #define FS_L1_PERM		0xD
 #define FS_L2_PERM		0xF
 
+#define FSR_FS4			BIT(10)
+#define FSR_FS3_0		GENMASK(3, 0)
+
 static inline int fsr_fs(unsigned int fsr)
 {
 	return (fsr & FSR_FS3_0) | (fsr & FSR_FS4) >> 6;
Signature · 1 line
2.47.3
author
#11 lore raw

RFC PATCH 11/12 ARM: provide individual is_translation_fault() and is_permission_fault()

In reply to Jan Kiszka

From: Russell King (Oracle) <[email protected]>

[ Upstream commit d1fed2d600905e7f007d8c88c936b768d45c09d6 ]

Provide individual LPAE and non-LPAE definitions for both these functions, rather than having ifdefs inside the function body. This places the functions closer to their associated definitions.

---
 arch/arm/mm/fault.h | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
arch/arm/mm/fault.h +19 -17
index 44c0fad29cce3..207f1b06941de 100644
@@ -21,6 +21,20 @@ static inline int fsr_fs(unsigned int fsr)
 {
 	return fsr & FSR_FS5_0;
 }
+
+static inline bool is_translation_fault(unsigned int fsr)
+{
+	int fs = fsr_fs(fsr);
+
+	return (fs & FS_MMU_NOLL_MASK) == FS_TRANS_NOLL;
+}
+
+static inline bool is_permission_fault(unsigned int fsr)
+{
+	int fs = fsr_fs(fsr);
+
+	return (fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL;
+}
 #else
 #define FSR_FS_AEA		22
 #define FS_L1_TRANS		0x5
@@ -35,33 +49,21 @@ static inline int fsr_fs(unsigned int fsr)
 {
 	return (fsr & FSR_FS3_0) | (fsr & FSR_FS4) >> 6;
 }
-#endif
 
 static inline bool is_translation_fault(unsigned int fsr)
 {
 	int fs = fsr_fs(fsr);
-#ifdef CONFIG_ARM_LPAE
-	if ((fs & FS_MMU_NOLL_MASK) == FS_TRANS_NOLL)
-		return true;
-#else
-	if (fs == FS_L1_TRANS || fs == FS_L2_TRANS)
-		return true;
-#endif
-	return false;
+
+	return fs == FS_L1_TRANS || fs == FS_L2_TRANS;
 }
 
 static inline bool is_permission_fault(unsigned int fsr)
 {
 	int fs = fsr_fs(fsr);
-#ifdef CONFIG_ARM_LPAE
-	if ((fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL)
-		return true;
-#else
-	if (fs == FS_L1_PERM || fs == FS_L2_PERM)
-		return true;
-#endif
-	return false;
+
+	return fs == FS_L1_PERM || fs == FS_L2_PERM;
 }
+#endif
 
 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
 void early_abt_enable(void);
Signature · 1 line
2.47.3
author
#12 lore raw

RFC PATCH 12/12 ARM: 9463/1: Allow to enable RT

In reply to Jan Kiszka

From: Sebastian Andrzej Siewior <[email protected]>

[ Upstream commit c6e61c06d6061750597e79c598acb5dead44c35b ]

All known issues have been adressed.
Allow to select RT.

---
 arch/arm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/Kconfig +1 -0
index 4be68e77b9594..4d09fd4bd9d41 100644
@@ -40,6 +40,7 @@ config ARM
 	select ARCH_SUPPORTS_CFI_CLANG
 	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.47.3
author
#13 lore raw
In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka

A first attempt to backport the recently merged ARM 32-bit support of PREEMPT-RT from 7.1 to 6.12-cip. Only lightly tested so far, first of all looking for feedback regarding completeness.

This may also be valuable for 6.12-rt as this series should be able to replace all patches tagged with {ARM:,arm:} in v6.12.79-rt17 - adding Daniel.

Grrr, CC typos and misconfigurations - at least no overshooting, it seems.

Daniel, Bryan, lost you on CC for this series.

Jan

Quoted 28 lines

Jan

Russell King (Oracle) (10):
ARM: group is_permission_fault() with is_translation_fault()
ARM: allow __do_kernel_fault() to report execution of memory faults
ARM: fix hash_name() fault
ARM: fix branch predictor hardening
ARM: ensure interrupts are enabled in __do_user_fault()
ARM: move vmalloc() lazy-page table population
ARM: move is_permission_fault() and is_translation_fault() to fault.h
ARM: use BIT() and GENMASK() for fault status register fields
ARM: move FSR fault status definitions before fsr_fs()
ARM: provide individual is_translation_fault() and
is_permission_fault()

Sebastian Andrzej Siewior (1):
ARM: 9463/1: Allow to enable RT

Thomas Gleixner (1):
ARM: 9459/1: Disable jump-label on PREEMPT_RT

 arch/arm/Kconfig        |   3 +-
 arch/arm/mm/alignment.c |   6 +-
 arch/arm/mm/fault.c     | 222 +++++++++++++++++++++++-----------------
 arch/arm/mm/fault.h     |  42 ++++++--
 4 files changed, 173 insertions(+), 100 deletions(-)
Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#14 lore raw
Quoted 5 lines · Jan Kiszka
Quoted 4 lines · Jan Kiszka

A first attempt to backport the recently merged ARM 32-bit support of PREEMPT-RT from 7.1 to 6.12-cip. Only lightly tested so far, first of all looking for feedback regarding completeness.

Quoted 7 lines
Quoted 3 lines

This may also be valuable for 6.12-rt as this series should be able to replace all patches tagged with {ARM:,arm:} in v6.12.79-rt17 - adding Daniel.

Grrr, CC typos and misconfigurations - at least no overshooting, it seems.

Daniel, Bryan, lost you on CC for this series.

I made the following:

| ARM: group is_permission_fault() with is_translation_fault()
| ARM: allow __do_kernel_fault() to report execution of memory faults
| ARM: fix hash_name() fault
| ARM: fix branch predictor hardening

up to here for stable

| ARM: ensure interrupts are enabled in __do_user_fault()
| ARM: 9459/1: Disable jump-label on PREEMPT_RT
| ARM: 9463/1: Allow to enable RT

This would go to stable-rt. This does not fix anything !RT as far as I can tell.

The four patches for stable have been sent.

Quoted 1 line

Jan

Sebastian

author
#15 lore raw
Quoted 12 lines · Sebastian Siewior
Quoted 11 lines · Jan Kiszka
Quoted 7 lines · Jan Kiszka

A first attempt to backport the recently merged ARM 32-bit support of PREEMPT-RT from 7.1 to 6.12-cip. Only lightly tested so far, first of all looking for feedback regarding completeness.

This may also be valuable for 6.12-rt as this series should be able to replace all patches tagged with {ARM:,arm:} in v6.12.79-rt17 - adding Daniel.

Grrr, CC typos and misconfigurations - at least no overshooting, it seems.

Quoted 9 lines
Quoted 1 line

Daniel, Bryan, lost you on CC for this series.

I made the following:

| ARM: group is_permission_fault() with is_translation_fault()
| ARM: allow __do_kernel_fault() to report execution of memory faults
| ARM: fix hash_name() fault
| ARM: fix branch predictor hardening

up to here for stable

Great!

Quoted 6 lines
| ARM: ensure interrupts are enabled in __do_user_fault()
| ARM: 9459/1: Disable jump-label on PREEMPT_RT
| ARM: 9463/1: Allow to enable RT

This would go to stable-rt. This does not fix anything !RT as far as I can tell.

Ok, then they would be equivalently relevant for 6.12-cip

Quoted 2 lines

The four patches for stable have been sent.

12-7 = 5. One is "Allow to enable RT", obviously needed in stable-rt and -cip then as well. What about the other 4? Not needed in a backport?

Thanks so far already!
Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#16 lore raw
Quoted 8 lines · Jan Kiszka
Quoted 6 lines
| ARM: ensure interrupts are enabled in __do_user_fault()
| ARM: 9459/1: Disable jump-label on PREEMPT_RT
| ARM: 9463/1: Allow to enable RT

This would go to stable-rt. This does not fix anything !RT as far as I can tell.

Ok, then they would be equivalently relevant for 6.12-cip

Once it goes via stable, I throw it at the stable pile to ease their rebase on top stable.

Quoted 5 lines
Quoted 2 lines

The four patches for stable have been sent.

12-7 = 5. One is "Allow to enable RT", obviously needed in stable-rt and -cip then as well. What about the other 4? Not needed in a backport?

I dropped from your queue:

| ARM: move vmalloc() lazy-page table population
| ARM: move is_permission_fault() and is_translation_fault() to fault.h
| ARM: use BIT() and GENMASK() for fault status register fields
| ARM: move FSR fault status definitions before fsr_fs()
| ARM: provide individual is_translation_fault() and is_permission_fault()

as far as I can tell, it is just shuffling code around. Not strictly needed for the backport. The "grouping" patch that I sent stable@ is also moving code around but the following "fix" needs the forward declaration so it goes in as a requirement.
I don't see the need for these.

Quoted 2 lines

Thanks so far already!
Jan

Sebastian

Reviewed-by on the v1 series
#17 lore raw
In reply to Jan Kiszka

Hi!

Quoted 7 lines

A first attempt to backport the recently merged ARM 32-bit support of PREEMPT-RT from 7.1 to 6.12-cip. Only lightly tested so far, first of all looking for feedback regarding completeness.

This may also be valuable for 6.12-rt as this series should be able to replace all patches tagged with {ARM:,arm:} in v6.12.79-rt17 - adding Daniel.

Patches look okay to me.

You may need to sign them off.

Best regards,
Pavel

author
#18 lore raw
Quoted 10 lines · Pavel Machek

Hi!

Quoted 7 lines

A first attempt to backport the recently merged ARM 32-bit support of PREEMPT-RT from 7.1 to 6.12-cip. Only lightly tested so far, first of all looking for feedback regarding completeness.

This may also be valuable for 6.12-rt as this series should be able to replace all patches tagged with {ARM:,arm:} in v6.12.79-rt17 - adding Daniel.

Quoted 5 lines

Patches look okay to me.

You may need to sign them off.

Let's wait for stable first. For the rest, I'm happy to sign off the final series, of course.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center