From: Lorenz Hetterich <lorenz.hetterich@cispa.de>
To: <chenhuacai@kernel.org>
Cc: <loongarch@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
Lorenz Hetterich <lorenz.hetterich@cispa.de>
Subject: [PATCH 2/2] LoongArch: Set FAULT_FLAG_INSTRUCTION in __do_page_fault()
Date: Wed, 18 Mar 2026 16:18:21 +0100 [thread overview]
Message-ID: <20260318151821.190439-3-lorenz.hetterich@cispa.de> (raw)
In-Reply-To: <20260318151821.190439-1-lorenz.hetterich@cispa.de>
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@cispa.de>
---
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
next prev parent reply other threads:[~2026-03-18 15:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 15:18 [PATCH 0/2] Fix issues in LoongArch page fault handling Lorenz Hetterich
2026-03-18 15:18 ` [PATCH 1/2] Loongarch: Fix stale value in __do_page_fault() Lorenz Hetterich
2026-03-19 8:30 ` Huacai Chen
2026-03-18 15:18 ` Lorenz Hetterich [this message]
2026-03-19 8:30 ` [PATCH 2/2] LoongArch: Set FAULT_FLAG_INSTRUCTION " Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260318151821.190439-3-lorenz.hetterich@cispa.de \
--to=lorenz.hetterich@cispa.de \
--cc=chenhuacai@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®