On Thu, Nov 2, 2017 at 10:07 PM, Y Song <[email protected]> wrote:
>
>    if (len > 0 && len < ...)
>       bpf_perf_event_output(..., len)
>
> Today it may not work in some cases. You can try.
>

Also, one more thing I forgot to add, and perhaps it wasn't clear in
my original message: this suggestion above will not work in this case.
In fact, from a compiler point of view there is no difference between

if (len > 0 && len < SCRATCH_SIZE)
        bpf_perf_event_output(..., len)

and my original

len &= SCRATCH_SIZE;
++len;
bpf_perf_event_output(..., len);

The compiler knows for a fact that len is always less than
SCRATCH_SIZE (because there is a previous more restrictive check done
before the spilling), so it will generate the exact same BPF code I
posted below, without doing any range check at all:

// checks, whether &= or if(), are removed by the compiler:
149:       r6 = *(u64 *)(r10 - 80)
...
157:       r5 = r6
158:       call 25

And I couldn't find a way to force the compiler into emitting those
instructions.

Thanks
_______________________________________________
iovisor-dev mailing list
[email protected]
https://lists.iovisor.org/mailman/listinfo/iovisor-dev

Reply via email to