lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YR6dreGQSe4oQFBr@hirez.programming.kicks-ass.net>
Date:   Thu, 19 Aug 2021 20:06:37 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Song Liu <songliubraving@...com>
Cc:     "open list:BPF (Safe dynamic programs and tools)" 
        <bpf@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "acme@...nel.org" <acme@...nel.org>,
        "mingo@...hat.com" <mingo@...hat.com>,
        Kernel Team <Kernel-team@...com>,
        Kan Liang <kan.liang@...ux.intel.com>,
        Like Xu <like.xu@...ux.intel.com>,
        Alexey Budankov <alexey.budankov@...ux.intel.com>
Subject: Re: [RFC] bpf: lbr: enable reading LBR from tracing bpf programs

On Thu, Aug 19, 2021 at 04:46:20PM +0000, Song Liu wrote:
> > void perf_inject_event(struct perf_event *event, struct pt_regs *regs)
> > {
> > 	struct perf_sample_data data;
> > 	struct pmu *pmu = event->pmu;
> > 	unsigned long flags;
> > 
> > 	local_irq_save(flags);
> > 	perf_pmu_disable(pmu);
> > 
> > 	perf_sample_data_init(&data, 0, 0);
> > 	/*
> > 	 * XXX or a variant with more _ that starts at the overflow
> > 	 * handler...
> > 	 */
> > 	__perf_event_overflow(event, 0, &data, regs);
> > 
> > 	perf_pmu_enable(pmu);
> > 	local_irq_restore(flags);
> > }
> > 
> > But please consider carefully, I haven't...
> 
> Hmm... This is a little weird to me. 
> IIUC, we need to call perf_inject_event() after the software event, say
> a kretprobe, triggers. So it gonna look like:
> 
>   1. kretprobe trigger;
>   2. handler calls perf_inject_event();
>   3. PMI kicks in, and saves LBR;

This doesn't actually happen. I overlooked the fact that we need the PMI
to fill out @data for us.

>   4. after the PMI, consumer of LBR uses the saved data;

Normal overflow handler will have data->br_stack set, but I now realize
that the 'psuedo' code above will not get that. We need to somehow get
the arch bits involved; again :/

> However, given perf_inject_event() disables PMU, we can just save the LBR
> right there? And it should be a lot easier? Something like:
> 
>   1. kretprobe triggers;
>   2. handler calls perf_snapshot_lbr();
>      2.1 perf_pmu_disable(pmu);
>      2.2 saves LBR 
>      2.3 perf_pmu_enable(pmu);
>   3. consumer of LBR uses the saved data;
> 
> What is the downside of this approach? 

It would be perf_snapshot_branch_stack() and would require a new
(optional) pmu::method to set up the branch stack.

And if we're going to be adding new pmu::methods then I figure one that
does the whole sample state might be more useful.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ