lkml.org 
[lkml]   [2022]   [Aug]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [RFC PATCH v1 1/3] bpf: Make ring buffer overwritable.
On Tue, 16 Aug 2022 at 04:22, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Aug 10, 2022 at 10:18 AM Francis Laniel
> <flaniel@linux.microsoft.com> wrote:
> >
> > By default, BPF ring buffer are size bounded, when producers already filled the
> > buffer, they need to wait for the consumer to get those data before adding new
> > ones.
> > In terms of API, bpf_ringbuf_reserve() returns NULL if the buffer is full.
> >
> > This patch permits making BPF ring buffer overwritable.
> > When producers already wrote as many data as the buffer size, they will begin to
> > over write existing data, so the oldest will be replaced.
> > As a result, bpf_ringbuf_reserve() never returns NULL.
> >
>
> Part of BPF ringbuf record (first 8 bytes) stores information like
> record size and offset in pages to the beginning of ringbuf map
> metadata. This is used by consumer to know how much data belongs to
> data record, but also for making sure that
> bpf_ringbuf_reserve()/bpf_ringbuf_submit() work correctly and don't
> corrupt kernel memory.
>
> If we simply allow overwriting this information (and no, spinlock
> doesn't protect from that, you can have multiple producers writing to
> different parts of ringbuf data area in parallel after "reserving"
> their respective records), it completely breaks any sort of
> correctness, both for user-space consumer and kernel-side producers.

The perf ring buffer solved this issue by adding an option to write
data backward with commit 9ecda41acb97 ("perf/core: Add
::write_backward attribute to perf event"). I'd like to see the BPF
ring buffer have a backward option as well to make overwrites work
without corruption. It's not completely clear to me if that will work
but I'd like to explore this with Francis. (Francis and I work in the
same team and we would like to use this for
https://github.com/kinvolk/traceloop).

Best regards,
Alban

\
 
 \ /
  Last update: 2022-08-16 14:29    [W:1.181 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site