Re: [PATCH v1 1/2] perf sched: Avoid segv if tp_handler not set

From: Ian Rogers

Date: Wed May 06 2026 - 13:14:51 EST


On Wed, May 6, 2026 at 9:17 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> On Wed, May 06, 2026 at 10:10:15AM -0300, Arnaldo Carvalho de Melo wrote:
> > On Tue, May 05, 2026 at 02:56:02PM -0700, Ian Rogers wrote:
> > > On Mon, Apr 6, 2026 at 10:53 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > > > On Fri, Apr 03, 2026 at 08:29:25AM -0700, Ian Rogers wrote:
> > > > > On Thu, Apr 2, 2026 at 7:42 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > > > > > On Tue, Mar 31, 2026 at 10:59:52PM -0700, Ian Rogers wrote:
> > > > > > > On Thu, Mar 26, 2026 at 4:20 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > > > > > > > On Fri, Mar 20, 2026 at 11:14:47PM -0700, Ian Rogers wrote:
> > > > > > > > > Doing a `perf sched record` then `perf sched stats report` crashes as
> > > > > > > > > the tp_handler isn't set. Add extra checks that tp_handler is set
> > > > > > > > > before accessing through it.
> >
> > > > > > > > Oh.. unintended use case. :) Probably better to add a dummy handler
> > > > > > > > for `perf sched stats report`.
> >
> > > > > > > Perhaps. I'd prefer to land the simpler change as-is.
> >
> > > > > > Well.. I guess the dummy handler approach would be simpler and perform
> > > > > > better. :)
> >
> > > > > > +++ b/tools/perf/builtin-sched.c
> > > > > > @@ -4955,6 +4955,7 @@ int cmd_sched(int argc, const char **argv)
> > > > > > .switch_event = replay_switch_event,
> > > > > > .fork_event = replay_fork_event,
> > > > > > };
> > > > > > + struct trace_sched_handler stats_ops = {};
> > > > >
> > > > > Oh, because there's an existing null test on the function pointer we
> > > > > don't need dummy functions, which is what I thought you were asking
> > > > > for. I'm still not convinced this is very intention revealing, but if
> > > > > it works for you then you can have my reviewed-by tag.
> >
> > > > Applied this and the patch 2 to perf-tools-next, thanks!
> >
> > > Thanks Namhyung. Did this get accidentally dropped? I'm not seeing it
> > > in perf-tools-next.
>
> I think I've applied my approach and test fix.

Ok, that wasn't clear. I think it is good to post such changes to the
list. For example, just sync-ing the header files prompted sashiko to
point out a bug in our beauty scripts:
https://lore.kernel.org/linux-perf-users/20260504193334.9F978C2BCB8@xxxxxxxxxxxxxxx/

Thanks,
Ian

> Thanks,
> Namhyung
>