Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Vadim Fedorenko <vfedorenko@novek.ru>
To: Daniel Borkmann <daniel@iogearbox.net>, Martin KaFai Lau <kafai@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org, willemb@google.com
Subject: Re: [PATCH bpf-next 1/2] bpf: add hardware timestamp field to __sk_buff
Date: Fri, 3 Sep 2021 09:35:07 +0100	[thread overview]
Message-ID: <f4616fe5-6850-1182-dc23-2a6d6375244a@novek.ru> (raw)
In-Reply-To: <fd2e2457-b3c2-81a4-481a-27555e4473dc@iogearbox.net>

On 03.09.2021 09:22, Daniel Borkmann wrote:
> On 9/3/21 12:15 AM, Vadim Fedorenko wrote:
>> BPF programs may want to know hardware timestamps if NIC supports
>> such timestamping.
>>
>> Expose this data as hwtstamp field of __sk_buff the same way as
>> gso_segs/gso_size.
>>
>> Also update BPF_PROG_TEST_RUN tests of the feature.
>>
>> Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
>> ---
>>   include/uapi/linux/bpf.h       |  2 ++
>>   net/core/filter.c              | 11 +++++++++++
>>   tools/include/uapi/linux/bpf.h |  2 ++
>>   3 files changed, 15 insertions(+)
>>
>> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
>> index 791f31dd0abe..c7d05b49f557 100644
>> --- a/include/uapi/linux/bpf.h
>> +++ b/include/uapi/linux/bpf.h
>> @@ -5284,6 +5284,8 @@ struct __sk_buff {
>>       __u32 gso_segs;
>>       __bpf_md_ptr(struct bpf_sock *, sk);
>>       __u32 gso_size;
>> +    __u32 padding;        /* Padding, future use. */
> 
> nit, instead of explicit padding field, just use: __u32 :32;
> 
> Also please add test_verifier coverage for this in BPF selftests, meaning,
> the expectation would be in case someone tries to access the padding field
> with this patch that we get a 'bpf verifier is misconfigured' error given
> it would have no bpf_convert_ctx_access() translation. But it would be overall
> better to add this to bpf_skb_is_valid_access(), so we can reject access to
> the padding area right there instead.

Thanks Daniel, I will update it in v2

>> +    __u64 hwtstamp;
>>   };
>>   struct bpf_tunnel_key {
>> diff --git a/net/core/filter.c b/net/core/filter.c
>> index 2e32cee2c469..1d8f8494d325 100644
>> --- a/net/core/filter.c
>> +++ b/net/core/filter.c
>> @@ -8884,6 +8884,17 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type 
>> type,
>>                         si->dst_reg, si->src_reg,
>>                         offsetof(struct sk_buff, sk));
>>           break;
>> +    case offsetof(struct __sk_buff, hwtstamp):
>> +        BUILD_BUG_ON(sizeof_field(struct skb_shared_hwtstamps, hwtstamp) != 8);
>> +        BUILD_BUG_ON(offsetof(struct skb_shared_hwtstamps, hwtstamp) != 0);
>> +
>> +        insn = bpf_convert_shinfo_access(si, insn);
>> +        *insn++ = BPF_LDX_MEM(BPF_DW,
>> +                      si->dst_reg, si->dst_reg,
>> +                      bpf_target_off(struct skb_shared_info,
>> +                             hwtstamps, 8,
>> +                             target_size));
>> +        break;
>>       }
>>       return insn - insn_buf;
>> diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
>> index 791f31dd0abe..c7d05b49f557 100644
>> --- a/tools/include/uapi/linux/bpf.h
>> +++ b/tools/include/uapi/linux/bpf.h
>> @@ -5284,6 +5284,8 @@ struct __sk_buff {
>>       __u32 gso_segs;
>>       __bpf_md_ptr(struct bpf_sock *, sk);
>>       __u32 gso_size;
>> +    __u32 padding;        /* Padding, future use. */
>> +    __u64 hwtstamp;
>>   };
>>   struct bpf_tunnel_key {
>>
> 


  reply	other threads:[~2021-09-03  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 22:15 [PATCH bpf-next 0/2] add hwtstamp " Vadim Fedorenko
2021-09-02 22:15 ` [PATCH bpf-next 1/2] bpf: add hardware timestamp field " Vadim Fedorenko
2021-09-03  8:22   ` Daniel Borkmann
2021-09-03  8:35     ` Vadim Fedorenko [this message]
2021-09-02 22:15 ` [PATCH bpf-next 2/2] selftests/bpf: test new __sk_buff field hwtstamp Vadim Fedorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f4616fe5-6850-1182-dc23-2a6d6375244a@novek.ru \
    --to=vfedorenko@novek.ru \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=willemb@google.com \
    --cc=yhs@fb.com \
    --subject='Re: [PATCH bpf-next 1/2] bpf: add hardware timestamp field to __sk_buff' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).