bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [POC 5/5] x86_64: invoke SFrame based stack tracer for user space
       [not found]     ` <20230502112720.0c0d011b@gandalf.local.home>
@ 2023-05-16 17:25       ` Andrii Nakryiko
  2023-05-16 17:38         ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2023-05-16 17:25 UTC (permalink / raw)
  To: Steven Rostedt, bpf
  Cc: Peter Zijlstra, Indu Bhagat, linux-toolchains, daandemeyer,
	andrii, kris.van.hees, elena.zannoni, nick.alcock

adding bpf@

On Tue, May 2, 2023 at 8:27 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Tue, 2 May 2023 12:53:53 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
>
> > >     while (entry->nr < entry->max_stack) {
> > >             if (!valid_user_frame(fp, sizeof(frame)))
> > >                     break;
> >
> > This is broken, the sframe stuff is not NMI safe. First you need to
> > change perf to emit a forward reference to a 'next' user trace and then
> > emit the user trace on return-to-user.
> >
> > As is, perf does everything in-place from NMI context.
>
> Exactly. What I would like to see with the new sframe infrastructure is
> just a way to tell it "I want a user stack trace before going back to user
> space". Then all the work can be done in the ptrace path, where it's safe
> to memory map in the sframe section. It's not like the user space stack
> frame will change before going back to user space.
>
> This will allow for asking for the user space stack trace at any context,
> because the work will not be done until later. Of course, this may also
> require user space tooling to be updated to handle this case. Perf may
> already do that.
>
> It would also mean that even if you take multiple profiling hits in one
> system call, you will only get one user space stack trace. But that's a
> good thing. As the stack trace doesn't change, and you don't waste ring
> buffer space with unneeded duplicate stacks.

As discussed in the halls of LSF/MM2023, such lazily mapped .sframe in
approach won't work with BPF's bpf_get_stack() approach, which expects
stack trace to be grabbed and returned synchronously from NMI context.
But we can probably retrofit it into bpf_get_stackid()+STACK_TRACE BPF
map API.

Indu, please cc bpf@vger.kernel.org for future revisions so we can
track and plan accordingly. Thank you!

>
> -- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [POC 5/5] x86_64: invoke SFrame based stack tracer for user space
  2023-05-16 17:25       ` [POC 5/5] x86_64: invoke SFrame based stack tracer for user space Andrii Nakryiko
@ 2023-05-16 17:38         ` Steven Rostedt
  2023-05-16 17:51           ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2023-05-16 17:38 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Peter Zijlstra, Indu Bhagat, linux-toolchains, daandemeyer,
	andrii, kris.van.hees, elena.zannoni, nick.alcock

On Tue, 16 May 2023 10:25:52 -0700
Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:

> As discussed in the halls of LSF/MM2023, such lazily mapped .sframe in
> approach won't work with BPF's bpf_get_stack() approach, which expects
> stack trace to be grabbed and returned synchronously from NMI context.
> But we can probably retrofit it into bpf_get_stackid()+STACK_TRACE BPF
> map API.

Note that we will likely not be able to use sframe in NMI context, and if
that's a requirement, then BPF will need to continue using the method it is
currently using.

The best way to access sframe reliable is in normal context. NMI is
special, and really should never had been used to access user space
addresses. That was just a simple solution but not a good one. There's a
lot of hacks just to allow a page fault in NMI context.
See https://lwn.net/Articles/484932/

> 
> Indu, please cc bpf@vger.kernel.org for future revisions so we can
> track and plan accordingly. Thank you!

I'll likely be taking over the kernel side of sframes. I'll be happy to
Cc that work to the bpf mailing list.

-- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [POC 5/5] x86_64: invoke SFrame based stack tracer for user space
  2023-05-16 17:38         ` Steven Rostedt
@ 2023-05-16 17:51           ` Andrii Nakryiko
  0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2023-05-16 17:51 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: bpf, Peter Zijlstra, Indu Bhagat, linux-toolchains, daandemeyer,
	andrii, kris.van.hees, elena.zannoni, nick.alcock

On Tue, May 16, 2023 at 10:38 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Tue, 16 May 2023 10:25:52 -0700
> Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> > As discussed in the halls of LSF/MM2023, such lazily mapped .sframe in
> > approach won't work with BPF's bpf_get_stack() approach, which expects
> > stack trace to be grabbed and returned synchronously from NMI context.
> > But we can probably retrofit it into bpf_get_stackid()+STACK_TRACE BPF
> > map API.
>
> Note that we will likely not be able to use sframe in NMI context, and if
> that's a requirement, then BPF will need to continue using the method it is
> currently using.

Yes, unfortunately. We should give users a way to use sframes, but
transition might be slow.

>
> The best way to access sframe reliable is in normal context. NMI is
> special, and really should never had been used to access user space
> addresses. That was just a simple solution but not a good one. There's a
> lot of hacks just to allow a page fault in NMI context.
> See https://lwn.net/Articles/484932/
>
> >
> > Indu, please cc bpf@vger.kernel.org for future revisions so we can
> > track and plan accordingly. Thank you!
>
> I'll likely be taking over the kernel side of sframes. I'll be happy to
> Cc that work to the bpf mailing list.

Thanks!


>
> -- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-16 17:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230501200410.3973453-1-indu.bhagat@oracle.com>
     [not found] ` <20230501200410.3973453-6-indu.bhagat@oracle.com>
     [not found]   ` <20230502105353.GO1597476@hirez.programming.kicks-ass.net>
     [not found]     ` <20230502112720.0c0d011b@gandalf.local.home>
2023-05-16 17:25       ` [POC 5/5] x86_64: invoke SFrame based stack tracer for user space Andrii Nakryiko
2023-05-16 17:38         ` Steven Rostedt
2023-05-16 17:51           ` Andrii Nakryiko

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 NNTP newsgroup(s).