[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2c54d502-2766-6132-121c-0b1f2e32ff88@iogearbox.net>
Date: Tue, 2 Jun 2020 19:43:51 +0200
From: Daniel Borkmann <daniel@...earbox.net>
To: Alan Maguire <alan.maguire@...cle.com>
Cc: Lorenz Bauer <lmb@...udflare.com>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf 2/3] bpf: Add csum_level helper for fixing up csum
levels
On 6/2/20 6:41 PM, Alan Maguire wrote:
> On Tue, 2 Jun 2020, Daniel Borkmann wrote:
>> On 6/2/20 5:19 PM, Lorenz Bauer wrote:
>>> On Tue, 2 Jun 2020 at 15:58, Daniel Borkmann <daniel@...earbox.net> wrote:
>>>>
>>>> Add a bpf_csum_level() helper which BPF programs can use in combination
>>>> with bpf_skb_adjust_room() when they pass in BPF_F_ADJ_ROOM_NO_CSUM_RESET
>>>> flag to the latter to avoid falling back to CHECKSUM_NONE.
>>>>
>>>> The bpf_csum_level() allows to adjust CHECKSUM_UNNECESSARY skb->csum_levels
>>>> via BPF_CSUM_LEVEL_{INC,DEC} which calls
>>>> __skb_{incr,decr}_checksum_unnecessary()
>>>> on the skb. The helper also allows a BPF_CSUM_LEVEL_RESET which sets the
>>>> skb's
>>>> csum to CHECKSUM_NONE as well as a BPF_CSUM_LEVEL_QUERY to just return the
>>>> current level. Without this helper, there is no way to otherwise adjust the
>>>> skb->csum_level. I did not add an extra dummy flags as there is plenty of
>>>> free
>>>> bitspace in level argument itself iff ever needed in future.
>>>>
>>>> Signed-off-by: Daniel Borkmann <daniel@...earbox.net>
>>>> ---
>>>> include/uapi/linux/bpf.h | 43 +++++++++++++++++++++++++++++++++-
>>>> net/core/filter.c | 38 ++++++++++++++++++++++++++++++
>>>> tools/include/uapi/linux/bpf.h | 43 +++++++++++++++++++++++++++++++++-
>>>> 3 files changed, 122 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>>>> index 3ba2bbbed80c..46622901cba7 100644
>>>> --- a/include/uapi/linux/bpf.h
>>>> +++ b/include/uapi/linux/bpf.h
>>>> @@ -3220,6 +3220,38 @@ union bpf_attr {
>>>> * calculation.
>>>> * Return
>>>> * Requested value, or 0, if flags are not recognized.
>>>> + *
>>>> + * int bpf_csum_level(struct sk_buff *skb, u64 level)
>>>
>>> u64 flags? We can also stuff things into level I guess.
>>
>> Yeah, I did mention it in the commit log. There is plenty of bit space to
>> extend
>> with flags in there iff ever needed. Originally, helper was called
>> bpf_csum_adjust()
>> but then renamed into bpf_csum_level() to be more 'topic specific' (aka do one
>> thing
>> and do it well...) and avoid future api overloading, so if necessary level can
>> be
>> used since I don't think the enum will be extended much further from what we
>> have
>> here anyway.
>>
>> [...]
>>>
>>> Acked-by: Lorenz Bauer <lmb@...udflare.com>
>
> Looks great! The only thing that gave me pause was
> the -EACCES return value for the case where we query
> and the skb is not subject to CHECKSUM_UNNECESSESARY ;
> -ENOENT ("no such level") feels slightly closer to the
> situation to me but either is a reasonable choice I think.
My thinking was in the line of 'error since we cannot access skb->csum_level
for the given skb->ip_summed'. I don't feel strong about which code it is either
way though; important thing is that it is documented & distinguishable from
other errors, so that the program has a way to make sense of the data returned
by BPF_CSUM_LEVEL_QUERY.
> Reviewed-by: Alan Maguire <alan.maguire@...cle.com>
Thanks!
Daniel
Powered by blists - more mailing lists