public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Nam Cao <namcao@linutronix.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	Gabriele Monaco <gmonaco@redhat.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	john.ogness@linutronix.de,
	Catalin Marinas <catalin.marinas@arm.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6 17/22] arm64: mm: Add page fault trace points
Date: Tue, 20 May 2025 13:32:19 +0100	[thread overview]
Message-ID: <20250520123219.GA18565@willie-the-truck> (raw)
In-Reply-To: <aCtZfiU8bgkSAgLh@J2N7QTR9R3>

On Mon, May 19, 2025 at 05:17:02PM +0100, Mark Rutland wrote:
> On Fri, May 16, 2025 at 03:04:50PM +0100, Will Deacon wrote:
> > On Wed, Apr 30, 2025 at 01:02:32PM +0200, Nam Cao wrote:
> > > Add page fault trace points, which are useful to implement RV monitor which
> > > watches page faults.
> > > 
> > > Signed-off-by: Nam Cao <namcao@linutronix.de>
> > > ---
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: linux-arm-kernel@lists.infradead.org
> > > ---
> > >  arch/arm64/mm/fault.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > > 
> > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> > > index ef63651099a9..e3f096b0dffd 100644
> > > --- a/arch/arm64/mm/fault.c
> > > +++ b/arch/arm64/mm/fault.c
> > > @@ -44,6 +44,9 @@
> > >  #include <asm/tlbflush.h>
> > >  #include <asm/traps.h>
> > >  
> > > +#define CREATE_TRACE_POINTS
> > > +#include <trace/events/exceptions.h>
> > > +
> > >  struct fault_info {
> > >  	int	(*fn)(unsigned long far, unsigned long esr,
> > >  		      struct pt_regs *regs);
> > > @@ -559,6 +562,11 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
> > >  	if (kprobe_page_fault(regs, esr))
> > >  		return 0;
> > >  
> > > +	if (user_mode(regs))
> > > +		trace_page_fault_user(addr, regs, esr);
> > > +	else
> > > +		trace_page_fault_kernel(addr, regs, esr);
> > 
> > Why is this after kprobe_page_fault()?
> 
> The kprobe_page_fault() gunk is doing something quite different, and is
> poorly named. That's trying to fixup the PC (and some other state) to
> hide kprobe details from the fault handling logic when an out-of-line
> copy of an instruction somehow triggers a fault.
> 
> Logically, that *should* happen before the tracepoints, and shouldn't be
> moved later. For other reasons it needs to be even earlier in the fault
> handling flow, and is currently far too late, but that only ends up
> mattering int he presence of other kernel bugs. For now I think it
> should stay where it is.

I thought these tracepoints were intended to be used by RV, in which
case I'd have thought we'd want as much coverage as possible to reason
about what the kernel is actually doing.

> More details below, for the curious and/or deranged.
> 
> The kprobe_page_fault() gunk is trying to fix up the case where an
> instruction has been kprobed, an out-of-line copy of that instruction is
> being stepped, and the out-of-line instruction has triggered a fault.
> When that happens, kprobe_page_fault() tries to reset the faulting PC
> and DAIF such that it looks like the fault was taken from the original
> PC of the probed instruction.
> 
> The real logic for that happens in kprobe_fault_handler(), which adjusts
> the values in pt_regs, but does not handle the live DAIF value. It also
> doesn't handle the PMR when pNMI is in use. Due to this, the fault
> handler can run with DAIF bits masked unexpectedly, and a subsequent
> exception return *could* go wrong.
> 
> Luckily all code with an extable entry has been blacklisted for kprobes
> since commit:
> 
>   888b3c8720e0a403 ("arm64: Treat all entry code as non-kprobe-able")
> 
> ... so we should only get here if there's another kernel bug that causes
> an unmarked dereference of a faulting address, in which case we're
> likely to BUG() anyway.
> 
> The real fix would be to hoist this out to the arm64 entry code (and
> handle similar for other EL1 exceptions), and get rid of all the
> __kprobes annotations inthe fault code.

This seems to be an argument for removing kprobe_page_fault() entirely,
which is fine, but while it exists it's not obvious to me how it's
supposed to interact with RV.

I suppose the pragmatic thing to do would be to align as closely as
possible with x86, but any documentation/guidance/tests to help us
maintain that would be really helpful. Otherwise, this feels like we're
going to have a repeat of the syscall entry mess where the interaction
with ptrace, audit, seccomp etc was perpetually broken in user-visible
ways.

Will

  reply	other threads:[~2025-05-20 12:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-30 11:02 [PATCH v6 00/22] RV: Linear temporal logic monitors for RT application Nam Cao
2025-04-30 11:02 ` [PATCH v6 01/22] rv: Add #undef TRACE_INCLUDE_FILE Nam Cao
2025-04-30 11:02 ` [PATCH v6 02/22] printk: Make vprintk_deferred() public Nam Cao
2025-04-30 11:02 ` [PATCH v6 03/22] panic: Add vpanic() Nam Cao
2025-05-05 12:24   ` Petr Mladek
2025-04-30 11:02 ` [PATCH v6 04/22] rv: Let the reactors take care of buffers Nam Cao
2025-05-05 12:25   ` Petr Mladek
2025-04-30 11:02 ` [PATCH v6 05/22] verification/dot2k: Make a separate dot2k_templates/Kconfig_container Nam Cao
2025-04-30 11:02 ` [PATCH v6 06/22] verification/dot2k: Remove __buff_to_string() Nam Cao
2025-04-30 11:02 ` [PATCH v6 07/22] verification/dot2k: Replace is_container() hack with subparsers Nam Cao
2025-04-30 11:02 ` [PATCH v6 08/22] rv: rename CONFIG_DA_MON_EVENTS to CONFIG_RV_MON_EVENTS Nam Cao
2025-04-30 11:02 ` [PATCH v6 09/22] verification/dot2k: Prepare the frontend for LTL inclusion Nam Cao
2025-04-30 11:02 ` [PATCH v6 10/22] Documentation/rv: Prepare monitor synthesis document " Nam Cao
2025-04-30 11:02 ` [PATCH v6 11/22] verification/rvgen: Restructure the templates files Nam Cao
2025-04-30 11:02 ` [PATCH v6 12/22] verification/rvgen: Restructure the classes to prepare for LTL inclusion Nam Cao
2025-04-30 11:02 ` [PATCH v6 13/22] rv: Add support for LTL monitors Nam Cao
2025-05-07 21:00   ` Steven Rostedt
2025-04-30 11:02 ` [PATCH v6 14/22] rv: Add rtapp container monitor Nam Cao
2025-04-30 11:02 ` [PATCH v6 15/22] x86/tracing: Remove redundant trace_pagefault_key Nam Cao
2025-04-30 11:02 ` [PATCH v6 16/22] x86/tracing: Move page fault trace points to generic Nam Cao
2025-05-07 21:03   ` Steven Rostedt
2025-04-30 11:02 ` [PATCH v6 17/22] arm64: mm: Add page fault trace points Nam Cao
2025-05-07 21:23   ` Steven Rostedt
2025-05-16 14:04   ` Will Deacon
2025-05-16 14:42     ` Steven Rostedt
2025-05-19 15:12       ` Will Deacon
2025-05-19 16:08         ` Steven Rostedt
2025-05-20 14:04           ` Will Deacon
2025-05-16 15:09     ` Nam Cao
2025-05-19 16:17     ` Mark Rutland
2025-05-20 12:32       ` Will Deacon [this message]
2025-04-30 11:02 ` [PATCH v6 18/22] riscv: " Nam Cao
2025-04-30 11:02 ` [PATCH v6 19/22] rv: Add rtapp_pagefault monitor Nam Cao
2025-04-30 11:02 ` [PATCH v6 20/22] rv: Add rtapp_sleep monitor Nam Cao
2025-04-30 11:02 ` [PATCH v6 21/22] rv: Add documentation for rtapp monitor Nam Cao
2025-04-30 11:02 ` [PATCH v6 22/22] rv: Allow to configure the number of per-task monitor Nam Cao
2025-04-30 12:17 ` [PATCH v6 00/22] RV: Linear temporal logic monitors for RT application Gabriele Monaco
2025-04-30 19:18   ` Steven Rostedt
2025-08-10 21:12 ` patchwork-bot+linux-riscv

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=20250520123219.GA18565@willie-the-truck \
    --to=will@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=gmonaco@redhat.com \
    --cc=john.ogness@linutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=namcao@linutronix.de \
    --cc=rostedt@goodmis.org \
    /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