loongarch.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Huacai Chen <chenhuacai@kernel.org>
To: Lorenz Hetterich <lorenz.hetterich@cispa.de>
Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] LoongArch: Set FAULT_FLAG_INSTRUCTION in __do_page_fault()
Date: Thu, 19 Mar 2026 16:30:50 +0800	[thread overview]
Message-ID: <CAAhV-H42kvs79-bTR+E-89Lthb9F=o8P4_q7ZYwMgEyjywT+kw@mail.gmail.com> (raw)
In-Reply-To: <20260318151821.190439-3-lorenz.hetterich@cispa.de>

Hi, Lorenz,

On Wed, Mar 18, 2026 at 11:18 PM Lorenz Hetterich
<lorenz.hetterich@cispa.de> wrote:
>
> 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 */
Needn't, you can use EXCCODE_TLBI/EXCCODE_TLBNX in loongarch.h directly.


Huacai

> +
>  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
>

      reply	other threads:[~2026-03-19  8:30 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 ` [PATCH 2/2] LoongArch: Set FAULT_FLAG_INSTRUCTION " Lorenz Hetterich
2026-03-19  8:30   ` Huacai Chen [this message]

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='CAAhV-H42kvs79-bTR+E-89Lthb9F=o8P4_q7ZYwMgEyjywT+kw@mail.gmail.com' \
    --to=chenhuacai@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=lorenz.hetterich@cispa.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).