History

bpf: Remove BPF_SKB_DELIVERY_TIME_NONE and rename s/delivery_time_/tstamp_/

This patch is to simplify the uapi bpf.h regarding to the tstamp type and use a similar way as the kernel to describe the value stored in __sk_buff->tstamp. My earlier thought was to avoid describing the semantic and clock base for the rcv timestamp until there is more clarity on the use case, so the __sk_buff->delivery_time_type naming instead of __sk_buff->tstamp_type. With some thoughts, it can reuse the UNSPEC naming. This patch first removes BPF_SKB_DELIVERY_TIME_NONE and also rename BPF_SKB_DELIVERY_TIME_UNSPEC to BPF_SKB_TSTAMP_UNSPEC and BPF_SKB_DELIVERY_TIME_MONO to BPF_SKB_TSTAMP_DELIVERY_MONO. The semantic of BPF_SKB_TSTAMP_DELIVERY_MONO is the same: __sk_buff->tstamp has delivery time in mono clock base. BPF_SKB_TSTAMP_UNSPEC means __sk_buff->tstamp has the (rcv) tstamp at ingress and the delivery time at egress. At egress, the clock base could be found from skb->sk->sk_clockid. __sk_buff->tstamp == 0 naturally means NONE, so NONE is not needed. With BPF_SKB_TSTAMP_UNSPEC for the rcv tstamp at ingress, the __sk_buff->delivery_time_type is also renamed to __sk_buff->tstamp_type which was also suggested in the earlier discussion: https://lore.kernel.org/bpf/b181acbe-caf8-502d-4b7b-7d96b9fc5d55@iogearbox.net/ The above will then make __sk_buff->tstamp and __sk_buff->tstamp_type the same as its kernel skb->tstamp and skb->mono_delivery_time counter part. The internal kernel function bpf_skb_convert_dtime_type_read() is then renamed to bpf_skb_convert_tstamp_type_read() and it can be simplified with the BPF_SKB_DELIVERY_TIME_NONE gone. A BPF_ALU32_IMM(BPF_AND) insn is also saved by using BPF_JMP32_IMM(BPF_JSET). The bpf helper bpf_skb_set_delivery_time() is also renamed to bpf_skb_set_tstamp(). The arg name is changed from dtime to tstamp also. It only allows setting tstamp 0 for BPF_SKB_TSTAMP_UNSPEC and it could be relaxed later if there is use case to change mono delivery time to non mono. prog->delivery_time_access is also renamed to prog->tstamp_type_access.

Martin KaFai Lau committed 4 years ago

Commit 9bb984f1 parent 9d90db94 files · +77 −93Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/bpf.h+21−19
@@ -5090,23 +5090,22 @@ union bpf_attr { · 5089 unmodified lines
50905090 * 0 on success, or a negative error in case of failure. On error
50915091 * *dst* buffer is zeroed out.
50925092 *
5093− * long bpf_skb_set_delivery_time(struct sk_buff *skb, u64 dtime, u32 dtime_type)
5093+ * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)
50945094 * Description
5095− * Set a *dtime* (delivery time) to the __sk_buff->tstamp and also
5096− * change the __sk_buff->delivery_time_type to *dtime_type*.
5095+ * Change the __sk_buff->tstamp_type to *tstamp_type*
5096+ * and set *tstamp* to the __sk_buff->tstamp together.
50975097 *
5098− * When setting a delivery time (non zero *dtime*) to
5099− * __sk_buff->tstamp, only BPF_SKB_DELIVERY_TIME_MONO *dtime_type*
5100− * is supported. It is the only delivery_time_type that will be
5101− * kept after bpf_redirect_*().
5102− *
5103− * If there is no need to change the __sk_buff->delivery_time_type,
5104− * the delivery time can be directly written to __sk_buff->tstamp
5098+ * If there is no need to change the __sk_buff->tstamp_type,
5099+ * the tstamp value can be directly written to __sk_buff->tstamp
51055100 * instead.
51065101 *
5107− * *dtime* 0 and *dtime_type* BPF_SKB_DELIVERY_TIME_NONE
5108− * can be used to clear any delivery time stored in
5109− * __sk_buff->tstamp.
5102+ * BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
5103+ * will be kept during bpf_redirect_*(). A non zero
5104+ * *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
5105+ * *tstamp_type*.
5106+ *
5107+ * A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
5108+ * with a zero *tstamp*.
51105109 *
51115110 * Only IPv4 and IPv6 skb->protocol are supported.
51125111 *
@@ -5119,7 +5118,7 @@ union bpf_attr { · 6 unmodified lines
51195118 * Return
51205119 * 0 on success.
51215120 * **-EINVAL** for invalid input
5122− * **-EOPNOTSUPP** for unsupported delivery_time_type and protocol
5121+ * **-EOPNOTSUPP** for unsupported protocol
51235122 */
51245123 #define __BPF_FUNC_MAPPER(FN) \
51255124 FN(unspec), \
@@ -5314,7 +5313,7 @@ union bpf_attr { · 188 unmodified lines
53145313 FN(xdp_load_bytes), \
53155314 FN(xdp_store_bytes), \
53165315 FN(copy_from_user_task), \
5317− FN(skb_set_delivery_time), \
5316+ FN(skb_set_tstamp), \
53185317 /* */
53195318
53205319 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
@@ -5505,9 +5504,12 @@ union { \ · 184 unmodified lines
55055504 } __attribute__((aligned(8)))
55065505
55075506 enum {
5508− BPF_SKB_DELIVERY_TIME_NONE,
5509− BPF_SKB_DELIVERY_TIME_UNSPEC,
5510− BPF_SKB_DELIVERY_TIME_MONO,
5507+ BPF_SKB_TSTAMP_UNSPEC,
5508+ BPF_SKB_TSTAMP_DELIVERY_MONO, /* tstamp has mono delivery time */
5509+ /* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle,
5510+ * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC
5511+ * and try to deduce it by ingress, egress or skb->sk->sk_clockid.
5512+ */
55115513 };
55125514
55135515 /* user accessible mirror of in-kernel sk_buff.
@@ -5550,7 +5552,7 @@ struct __sk_buff { · 36 unmodified lines
55505552 __u32 gso_segs;
55515553 __bpf_md_ptr(struct bpf_sock *, sk);
55525554 __u32 gso_size;
5553− __u8 delivery_time_type;
5555+ __u8 tstamp_type;
55545556 __u32 :24; /* Padding, future use. */
55555557 __u64 hwtstamp;
55565558 };