Re: [PATCH v2 bpf-next 4/7] libbpf: add BPF ring buffer support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 21, 2020 at 6:15 PM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> 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;
> > +}
> > +



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux