* __sk_buff->delivery_time_type: This patch adds __sk_buff->delivery_time_type. It tells if the delivery_time is stored in __sk_buff->tstamp or not. It will be most useful for ingress to tell if the __sk_buff->tstamp has the (rcv) timestamp or delivery_time. If delivery_time_type is 0 (BPF_SKB_DELIVERY_TIME_NONE), it has the (rcv) timestamp. Two non-zero types are defined for the delivery_time_type, BPF_SKB_DELIVERY_TIME_MONO and BPF_SKB_DELIVERY_TIME_UNSPEC. For UNSPEC, it can only happen in egress because only mono delivery_time can be forwarded to ingress now. The clock of UNSPEC delivery_time can be deduced from the skb->sk->sk_clockid which is how the sch_etf doing it also. * Provide forwarded delivery_time to tc-bpf@ingress: With the help of the new delivery_time_type, the tc-bpf has a way to tell if the __sk_buff->tstamp has the (rcv) timestamp or the delivery_time. During bpf load time, the verifier will learn if the bpf prog has accessed the new __sk_buff->delivery_time_type. If it does, it means the tc-bpf@ingress is expecting the skb->tstamp could have the delivery_time. The kernel will then read the skb->tstamp as-is during bpf insn rewrite without checking the skb->mono_delivery_time. This is done by adding a new prog->delivery_time_access bit. The same goes for writing skb->tstamp. * bpf_skb_set_delivery_time(): The bpf_skb_set_delivery_time() helper is added to allow setting both delivery_time and the delivery_time_type at the same time. If the tc-bpf does not need to change the delivery_time_type, it can directly write to the __sk_buff->tstamp as the existing tc-bpf has already been doing. It will be most useful at ingress to change the __sk_buff->tstamp from the (rcv) timestamp to a mono delivery_time and then bpf_redirect_*(). bpf only has mono clock helper (bpf_ktime_get_ns), and the current known use case is the mono EDT for fq, and only mono delivery time can be kept during forward now, so bpf_skb_set_delivery_time() only supports setting BPF_SKB_DELIVERY_TIME_MONO. It can be extended later when use cases come up and the forwarding path also supports other clock bases.
Showing the changes to include/uapi (1 of 4 files). Show all
Unified · Split
| @@ -5086,6 +5086,37 @@ union bpf_attr { · 5085 unmodified lines | |||
| 5086 | * Return | 5086 | * Return |
| 5087 | * 0 on success, or a negative error in case of failure. On error | 5087 | * 0 on success, or a negative error in case of failure. On error |
| 5088 | * *dst* buffer is zeroed out. | 5088 | * *dst* buffer is zeroed out. |
| 5089 | * | ||
| 5090 | * long bpf_skb_set_delivery_time(struct sk_buff *skb, u64 dtime, u32 dtime_type) | ||
| 5091 | * Description | ||
| 5092 | * Set a *dtime* (delivery time) to the __sk_buff->tstamp and also | ||
| 5093 | * change the __sk_buff->delivery_time_type to *dtime_type*. | ||
| 5094 | * | ||
| 5095 | * When setting a delivery time (non zero *dtime*) to | ||
| 5096 | * __sk_buff->tstamp, only BPF_SKB_DELIVERY_TIME_MONO *dtime_type* | ||
| 5097 | * is supported. It is the only delivery_time_type that will be | ||
| 5098 | * kept after bpf_redirect_*(). | ||
| 5099 | * | ||
| 5100 | * If there is no need to change the __sk_buff->delivery_time_type, | ||
| 5101 | * the delivery time can be directly written to __sk_buff->tstamp | ||
| 5102 | * instead. | ||
| 5103 | * | ||
| 5104 | * *dtime* 0 and *dtime_type* BPF_SKB_DELIVERY_TIME_NONE | ||
| 5105 | * can be used to clear any delivery time stored in | ||
| 5106 | * __sk_buff->tstamp. | ||
| 5107 | * | ||
| 5108 | * Only IPv4 and IPv6 skb->protocol are supported. | ||
| 5109 | * | ||
| 5110 | * This function is most useful when it needs to set a | ||
| 5111 | * mono delivery time to __sk_buff->tstamp and then | ||
| 5112 | * bpf_redirect_*() to the egress of an iface. For example, | ||
| 5113 | * changing the (rcv) timestamp in __sk_buff->tstamp at | ||
| 5114 | * ingress to a mono delivery time and then bpf_redirect_*() | ||
| 5115 | * to sch_fq@phy-dev. | ||
| 5116 | * Return | ||
| 5117 | * 0 on success. | ||
| 5118 | * **-EINVAL** for invalid input | ||
| 5119 | * **-EOPNOTSUPP** for unsupported delivery_time_type and protocol | ||
| 5089 | */ | 5120 | */ |
| 5090 | #define __BPF_FUNC_MAPPER(FN) \ | 5121 | #define __BPF_FUNC_MAPPER(FN) \ |
| 5091 | FN(unspec), \ | 5122 | FN(unspec), \ |
| @@ -5280,6 +5311,7 @@ union bpf_attr { · 188 unmodified lines | |||
| 5280 | FN(xdp_load_bytes), \ | 5311 | FN(xdp_load_bytes), \ |
| 5281 | FN(xdp_store_bytes), \ | 5312 | FN(xdp_store_bytes), \ |
| 5282 | FN(copy_from_user_task), \ | 5313 | FN(copy_from_user_task), \ |
| 5314 | FN(skb_set_delivery_time), \ | ||
| 5283 | /* */ | 5315 | /* */ |
| 5284 | 5316 | ||
| 5285 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper | 5317 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper |
| @@ -5469,6 +5501,12 @@ union { \ · 183 unmodified lines | |||
| 5469 | __u64 :64; \ | 5501 | __u64 :64; \ |
| 5470 | } __attribute__((aligned(8))) | 5502 | } __attribute__((aligned(8))) |
| 5471 | 5503 | ||
| 5504 | enum { | ||
| 5505 | BPF_SKB_DELIVERY_TIME_NONE, | ||
| 5506 | BPF_SKB_DELIVERY_TIME_UNSPEC, | ||
| 5507 | BPF_SKB_DELIVERY_TIME_MONO, | ||
| 5508 | }; | ||
| 5509 | |||
| 5472 | /* user accessible mirror of in-kernel sk_buff. | 5510 | /* user accessible mirror of in-kernel sk_buff. |
| 5473 | * new fields can only be added to the end of this structure | 5511 | * new fields can only be added to the end of this structure |
| 5474 | */ | 5512 | */ |
| @@ -5509,7 +5547,8 @@ struct __sk_buff { · 34 unmodified lines | |||
| 5509 | __u32 gso_segs; | 5547 | __u32 gso_segs; |
| 5510 | __bpf_md_ptr(struct bpf_sock *, sk); | 5548 | __bpf_md_ptr(struct bpf_sock *, sk); |
| 5511 | __u32 gso_size; | 5549 | __u32 gso_size; |
| 5512 | __u32 :32; /* Padding, future use. */ | 5550 | __u8 delivery_time_type; |
| 5551 | __u32 :24; /* Padding, future use. */ | ||
| 5513 | __u64 hwtstamp; | 5552 | __u64 hwtstamp; |
| 5514 | }; | 5553 | }; |
| 5515 | 5554 | ||