[PATCH 2/2] LoongArch: Set FAULT_FLAG_INSTRUCTION in __do_page_fault()
From: Lorenz Hetterich
Date: Wed Mar 18 2026 - 11:34:11 EST
The page-fault handler never sets the FAULT_FLAG_INSTRUCTION flag.
Set FAULT_FLAG_INSTRUCTION for faults related to instruction fetches.
Signed-off-by: Lorenz Hetterich <lorenz.hetterich@xxxxxxxx>
---
arch/loongarch/include/asm/exception.h | 3 +++
arch/loongarch/mm/fault.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/arch/loongarch/include/asm/exception.h b/arch/loongarch/include/asm/exception.h
index c6d20736fd92..7305b7065a43 100644
--- a/arch/loongarch/include/asm/exception.h
+++ b/arch/loongarch/include/asm/exception.h
@@ -6,6 +6,9 @@
#include <asm/ptrace.h>
#include <linux/kprobes.h>
+#define EXC_PIF 3 /* Page Invalid Fetch */
+#define EXC_PNX 6 /* Page Non-eXecutable */
+
extern void *exception_table[];
void show_registers(struct pt_regs *regs);
diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index c7703bdec4fc..7cd422c1224e 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -215,6 +215,9 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
if (user_mode(regs))
flags |= FAULT_FLAG_USER;
+ if (current->thread.trap_nr == EXC_PIF || current->thread.trap_nr == EXC_PNX)
+ flags |= FAULT_FLAG_INSTRUCTION;
+
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
if (!(flags & FAULT_FLAG_USER))
--
2.43.0