Re: [PATCH 5/5] perf/x86: Relax privilege filter restriction on AMD IBS

From: Namhyung Kim
Date: Tue Oct 22 2024 - 18:24:38 EST


Hello,

On Mon, Sep 23, 2024 at 04:03:47PM +0530, Ravi Bangoria wrote:
> Hi Namhyung,
>
> > While IBS is available for per-thread profiling, still regular users
> > cannot open an event due to the default paranoid setting (2) which
> > doesn't allow unprivileged users to get kernel samples. That means
> > it needs to set exclude_kernel bit in the attribute but IBS driver
> > would reject it since it has PERF_PMU_CAP_NO_EXCLUDE. This is not what
> > we want and I've been getting requests to fix this issue.
>
> I'm working on some IBS improvements that impacts this change as well.
> Is it be possible to hold off this patch for some time. I'll try to
> post my patches soon.
>
> > @@ -1111,6 +1127,12 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
> > regs.flags |= PERF_EFLAGS_EXACT;
> > }
> >
> > + if ((event->attr.config2 & IBS_SW_FILTER_MASK) &&
> > + perf_exclude_event(event, &regs)) {
> > + throttle = perf_event_account_interrupt(event);
> > + goto out;
> > + }
>
> Throttling can give surprises when the sample period is very small.
> For ex,
>
> $ ./perf record -e cycles:uh -c 192 -- make
> [ perf record: Woken up 52 times to write data ]
> [ perf record: Captured and wrote 23.016 MB perf.data (705634 samples) ]
>
> $ ./perf record -e ibs_op/swfilt=1/uh -c 192 -- make
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 1.608 MB perf.data (19 samples) ]
>
> It seems like the IBS event gets throttled (and disabled) before the
> cpu get a chance to go back to userspace), hence we end up with very
> few samples.

Thanks for raising this issue. This indeed looks like a surprising
result. Not sure what we can do here other than adding a documentation
to refrain from using such a small period. I don't think we want to
skip the throttling logic for the filtered samples. Otherwise it can be
used for DoS-like attacks IMHO.

Thanks,
Namhyung