diff mbox series

[bpf-next,1/2] bpf: add hardware timestamp field to __sk_buff

Message ID 20210902221551.15566-2-vfedorenko@novek.ru (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series add hwtstamp to __sk_buff | expand

Checks

Context Check Description
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 9 maintainers not CCed: joe@cilium.io andrii@kernel.org daniel@iogearbox.net kpsingh@kernel.org haoluo@google.com jackmanb@google.com davem@davemloft.net brouer@redhat.com quentin@isovalent.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 11795 this patch: 11795
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 83 exceeds 80 columns WARNING: line length of 87 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 11418 this patch: 11418
netdev/header_inline success Link

Commit Message

Vadim Fedorenko Sept. 2, 2021, 10:15 p.m. UTC
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(+)

Comments

Daniel Borkmann Sept. 3, 2021, 8:22 a.m. UTC | #1
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.

> +	__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 {
>
Vadim Fedorenko Sept. 3, 2021, 8:35 a.m. UTC | #2
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 {
>>
>
diff mbox series

Patch

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. */
+	__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 {