[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACT4Y+aKmdsXhRZi2f3LsX3m=krdY4kPsEUcieSugO2wY=xA-Q@mail.gmail.com>
Date: Wed, 24 Mar 2021 15:12:56 +0100
From: Dmitry Vyukov <dvyukov@...gle.com>
To: Marco Elver <elver@...gle.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Ingo Molnar <mingo@...hat.com>, Jiri Olsa <jolsa@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Namhyung Kim <namhyung@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Alexander Potapenko <glider@...gle.com>,
Al Viro <viro@...iv.linux.org.uk>,
Arnd Bergmann <arnd@...db.de>,
Christian Brauner <christian@...uner.io>,
Jann Horn <jannh@...gle.com>, Jens Axboe <axboe@...nel.dk>,
Matt Morehouse <mascasa@...gle.com>,
Peter Collingbourne <pcc@...gle.com>,
Ian Rogers <irogers@...gle.com>,
kasan-dev <kasan-dev@...glegroups.com>,
linux-arch <linux-arch@...r.kernel.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
"the arch/x86 maintainers" <x86@...nel.org>,
"open list:KERNEL SELFTEST FRAMEWORK"
<linux-kselftest@...r.kernel.org>
Subject: Re: [PATCH v3 07/11] perf: Add breakpoint information to siginfo on SIGTRAP
On Wed, Mar 24, 2021 at 3:05 PM Marco Elver <elver@...gle.com> wrote:
>
> On Wed, 24 Mar 2021 at 15:01, Peter Zijlstra <peterz@...radead.org> wrote:
> >
> > One last try, I'll leave it alone now, I promise :-)
>
> This looks like it does what you suggested, thanks! :-)
>
> I'll still need to think about it, because of the potential problem
> with modify-signal-races and what the user's synchronization story
> would look like then.
I agree that this looks inherently racy. The attr can't be allocated
on stack, user synchronization may be tricky and expensive. The API
may provoke bugs and some users may not even realize the race problem.
One potential alternative is use of an opaque u64 context (if we could
shove it into the attr). A user can pass a pointer to the attr in
there (makes it equivalent to this proposal), or bit-pack size/type
(as we want), pass some sequence number or whatever.
> > --- a/include/linux/perf_event.h
> > +++ b/include/linux/perf_event.h
> > @@ -778,6 +778,9 @@ struct perf_event {
> > void *security;
> > #endif
> > struct list_head sb_list;
> > +
> > + unsigned long si_uattr;
> > + unsigned long si_data;
> > #endif /* CONFIG_PERF_EVENTS */
> > };
> >
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -5652,13 +5652,17 @@ static long _perf_ioctl(struct perf_even
> > return perf_event_query_prog_array(event, (void __user *)arg);
> >
> > case PERF_EVENT_IOC_MODIFY_ATTRIBUTES: {
> > + struct perf_event_attr __user *uattr;
> > struct perf_event_attr new_attr;
> > - int err = perf_copy_attr((struct perf_event_attr __user *)arg,
> > - &new_attr);
> > + int err;
> >
> > + uattr = (struct perf_event_attr __user *)arg;
> > + err = perf_copy_attr(uattr, &new_attr);
> > if (err)
> > return err;
> >
> > + event->si_uattr = (unsigned long)uattr;
> > +
> > return perf_event_modify_attr(event, &new_attr);
> > }
> > default:
> > @@ -6399,7 +6403,12 @@ static void perf_sigtrap(struct perf_eve
> > clear_siginfo(&info);
> > info.si_signo = SIGTRAP;
> > info.si_code = TRAP_PERF;
> > - info.si_errno = event->attr.type;
> > + info.si_addr = (void *)event->si_data;
> > +
> > + info.si_perf = event->si_uattr;
> > + if (event->parent)
> > + info.si_perf = event->parent->si_uattr;
> > +
> > force_sig_info(&info);
> > }
> >
> > @@ -6414,8 +6423,8 @@ static void perf_pending_event_disable(s
> > WRITE_ONCE(event->pending_disable, -1);
> >
> > if (event->attr.sigtrap) {
> > - atomic_set(&event->event_limit, 1); /* rearm event */
> > perf_sigtrap(event);
> > + atomic_set_release(&event->event_limit, 1); /* rearm event */
> > return;
> > }
> >
> > @@ -9121,6 +9130,7 @@ static int __perf_event_overflow(struct
> > if (events && atomic_dec_and_test(&event->event_limit)) {
> > ret = 1;
> > event->pending_kill = POLL_HUP;
> > + event->si_data = data->addr;
> >
> > perf_event_disable_inatomic(event);
> > }
> > @@ -12011,6 +12021,8 @@ SYSCALL_DEFINE5(perf_event_open,
> > goto err_task;
> > }
> >
> > + event->si_uattr = (unsigned long)attr_uptr;
> > +
> > if (is_sampling_event(event)) {
> > if (event->pmu->capabilities & PERF_PMU_CAP_NO_INTERRUPT) {
> > err = -EOPNOTSUPP;
Powered by blists - more mailing lists