On Thu, May 21, 2020 at 6:15 PM Alexei Starovoitov <alexei.starovoi...@gmail.com> wrote: > > On Sun, May 17, 2020 at 12:57:24PM -0700, Andrii Nakryiko wrote: > > + > > +static inline int roundup_len(__u32 len) > > +{ > > + /* clear out top 2 bits */ > > + len <<= 2; > > + len >>= 2; > > what this is for? > Overflow prevention? > but kernel checked the size already?
No, as comment above says, just clearing upper two bits (busy bit and discard bit). Busy bit should be 0, but discard bit could be set for discarded record. I could have written this equivalently as: len = (len & ~(1 << BPF_RINGBUF_DISCARD_BIT)); But I think compiler won't optimize it to two bit shifts, assuming bit #31 might be set. > > > + /* add length prefix */ > > + len += BPF_RINGBUF_HDR_SZ; > > + /* round up to 8 byte alignment */ > > + return (len + 7) / 8 * 8; > > +} > > +