Commit ecec1887 authored by Martin KaFai Lau's avatar Martin KaFai Lau
Browse files

Merge branch 'Replace mono_delivery_time with tstamp_type'



Abhishek Chauhan says:

====================
Patch 1 :- This patch takes care of only renaming the mono delivery
timestamp to tstamp_type with no change in functionality of
existing available code in kernel also
Starts assigning tstamp_type with either mono or real and
introduces a new enum in the skbuff.h, again no change in functionality
of the existing available code in kernel , just making the code scalable.

Patch 2 :- Additional bit was added to support tai timestamp type to
avoid tstamp drops in the forwarding path when testing TC-ETF.
Patch is also updating bpf filter.c
Some updates to bpf header files with introduction to BPF_SKB_CLOCK_TAI
and documentation updates stating deprecation of BPF_SKB_TSTAMP_UNSPEC
and BPF_SKB_TSTAMP_DELIVERY_MONO

Patch 3:- Handles forwarding of UDP packets with TAI clock id tstamp_type
type with supported changes for tc_redirect/tc_redirect_dtime
to handle forwarding of UDP packets with TAI tstamp_type
====================

Signed-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parents a87f34e7 c34e3ab2
Loading
Loading
Loading
Loading
+50 −18
Original line number Diff line number Diff line
@@ -706,6 +706,13 @@ typedef unsigned int sk_buff_data_t;
typedef unsigned char *sk_buff_data_t;
#endif

enum skb_tstamp_type {
	SKB_CLOCK_REALTIME,
	SKB_CLOCK_MONOTONIC,
	SKB_CLOCK_TAI,
	__SKB_CLOCK_MAX = SKB_CLOCK_TAI,
};

/**
 * DOC: Basic sk_buff geometry
 *
@@ -823,10 +830,8 @@ typedef unsigned char *sk_buff_data_t;
 *	@dst_pending_confirm: need to confirm neighbour
 *	@decrypted: Decrypted SKB
 *	@slow_gro: state present at GRO time, slower prepare step required
 *	@mono_delivery_time: When set, skb->tstamp has the
 *		delivery_time in mono clock base (i.e. EDT).  Otherwise, the
 *		skb->tstamp has the (rcv) timestamp at ingress and
 *		delivery_time at egress.
 *	@tstamp_type: When set, skb->tstamp has the
 *		delivery_time clock base of skb->tstamp.
 *	@napi_id: id of the NAPI struct this skb came from
 *	@sender_cpu: (aka @napi_id) source CPU in XPS
 *	@alloc_cpu: CPU which did the skb allocation.
@@ -954,7 +959,7 @@ struct sk_buff {
	/* private: */
	__u8			__mono_tc_offset[0];
	/* public: */
	__u8			mono_delivery_time:1;	/* See SKB_MONO_DELIVERY_TIME_MASK */
	__u8			tstamp_type:2;	/* See skb_tstamp_type */
#ifdef CONFIG_NET_XGRESS
	__u8			tc_at_ingress:1;	/* See TC_AT_INGRESS_MASK */
	__u8			tc_skip_classify:1;
@@ -1084,15 +1089,16 @@ struct sk_buff {
#endif
#define PKT_TYPE_OFFSET		offsetof(struct sk_buff, __pkt_type_offset)

/* if you move tc_at_ingress or mono_delivery_time
/* if you move tc_at_ingress or tstamp_type
 * around, you also must adapt these constants.
 */
#ifdef __BIG_ENDIAN_BITFIELD
#define SKB_MONO_DELIVERY_TIME_MASK	(1 << 7)
#define TC_AT_INGRESS_MASK		(1 << 6)
#define SKB_TSTAMP_TYPE_MASK		(3 << 6)
#define SKB_TSTAMP_TYPE_RSHIFT		(6)
#define TC_AT_INGRESS_MASK		(1 << 5)
#else
#define SKB_MONO_DELIVERY_TIME_MASK	(1 << 0)
#define TC_AT_INGRESS_MASK		(1 << 1)
#define SKB_TSTAMP_TYPE_MASK		(3)
#define TC_AT_INGRESS_MASK		(1 << 2)
#endif
#define SKB_BF_MONO_TC_OFFSET		offsetof(struct sk_buff, __mono_tc_offset)

@@ -4183,7 +4189,7 @@ static inline void skb_get_new_timestampns(const struct sk_buff *skb,
static inline void __net_timestamp(struct sk_buff *skb)
{
	skb->tstamp = ktime_get_real();
	skb->mono_delivery_time = 0;
	skb->tstamp_type = SKB_CLOCK_REALTIME;
}

static inline ktime_t net_timedelta(ktime_t t)
@@ -4192,10 +4198,36 @@ static inline ktime_t net_timedelta(ktime_t t)
}

static inline void skb_set_delivery_time(struct sk_buff *skb, ktime_t kt,
					 bool mono)
					 u8 tstamp_type)
{
	skb->tstamp = kt;
	skb->mono_delivery_time = kt && mono;

	if (kt)
		skb->tstamp_type = tstamp_type;
	else
		skb->tstamp_type = SKB_CLOCK_REALTIME;
}

static inline void skb_set_delivery_type_by_clockid(struct sk_buff *skb,
						    ktime_t kt, clockid_t clockid)
{
	u8 tstamp_type = SKB_CLOCK_REALTIME;

	switch (clockid) {
	case CLOCK_REALTIME:
		break;
	case CLOCK_MONOTONIC:
		tstamp_type = SKB_CLOCK_MONOTONIC;
		break;
	case CLOCK_TAI:
		tstamp_type = SKB_CLOCK_TAI;
		break;
	default:
		WARN_ON_ONCE(1);
		kt = 0;
	}

	skb_set_delivery_time(skb, kt, tstamp_type);
}

DECLARE_STATIC_KEY_FALSE(netstamp_needed_key);
@@ -4205,8 +4237,8 @@ DECLARE_STATIC_KEY_FALSE(netstamp_needed_key);
 */
static inline void skb_clear_delivery_time(struct sk_buff *skb)
{
	if (skb->mono_delivery_time) {
		skb->mono_delivery_time = 0;
	if (skb->tstamp_type) {
		skb->tstamp_type = SKB_CLOCK_REALTIME;
		if (static_branch_unlikely(&netstamp_needed_key))
			skb->tstamp = ktime_get_real();
		else
@@ -4216,7 +4248,7 @@ static inline void skb_clear_delivery_time(struct sk_buff *skb)

static inline void skb_clear_tstamp(struct sk_buff *skb)
{
	if (skb->mono_delivery_time)
	if (skb->tstamp_type)
		return;

	skb->tstamp = 0;
@@ -4224,7 +4256,7 @@ static inline void skb_clear_tstamp(struct sk_buff *skb)

static inline ktime_t skb_tstamp(const struct sk_buff *skb)
{
	if (skb->mono_delivery_time)
	if (skb->tstamp_type)
		return 0;

	return skb->tstamp;
@@ -4232,7 +4264,7 @@ static inline ktime_t skb_tstamp(const struct sk_buff *skb)

static inline ktime_t skb_tstamp_cond(const struct sk_buff *skb, bool cond)
{
	if (!skb->mono_delivery_time && skb->tstamp)
	if (skb->tstamp_type != SKB_CLOCK_MONOTONIC && skb->tstamp)
		return skb->tstamp;

	if (static_branch_unlikely(&netstamp_needed_key) || cond)
+2 −2
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ struct frag_v6_compare_key {
 * @stamp: timestamp of the last received fragment
 * @len: total length of the original datagram
 * @meat: length of received fragments so far
 * @mono_delivery_time: stamp has a mono delivery time (EDT)
 * @tstamp_type: stamp has a mono delivery time (EDT)
 * @flags: fragment queue flags
 * @max_size: maximum received fragment size
 * @fqdir: pointer to struct fqdir
@@ -97,7 +97,7 @@ struct inet_frag_queue {
	ktime_t			stamp;
	int			len;
	int			meat;
	u8			mono_delivery_time;
	u8			tstamp_type;
	__u8			flags;
	u16			max_size;
	struct fqdir		*fqdir;
+10 −5
Original line number Diff line number Diff line
@@ -6207,12 +6207,17 @@ union { \
	__u64 :64;			\
} __attribute__((aligned(8)))

/* The enum used in skb->tstamp_type. It specifies the clock type
 * of the time stored in the skb->tstamp.
 */
enum {
	BPF_SKB_TSTAMP_UNSPEC,
	BPF_SKB_TSTAMP_DELIVERY_MONO,	/* tstamp has mono delivery time */
	/* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle,
	 * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC
	 * and try to deduce it by ingress, egress or skb->sk->sk_clockid.
	BPF_SKB_TSTAMP_UNSPEC = 0,		/* DEPRECATED */
	BPF_SKB_TSTAMP_DELIVERY_MONO = 1,	/* DEPRECATED */
	BPF_SKB_CLOCK_REALTIME = 0,
	BPF_SKB_CLOCK_MONOTONIC = 1,
	BPF_SKB_CLOCK_TAI = 2,
	/* For any future BPF_SKB_CLOCK_* that the bpf prog cannot handle,
	 * the bpf prog can try to deduce it by ingress/egress/skb->sk->sk_clockid.
	 */
};

+3 −3
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
					   struct sk_buff *))
{
	int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
	bool mono_delivery_time = skb->mono_delivery_time;
	u8 tstamp_type = skb->tstamp_type;
	unsigned int hlen, ll_rs, mtu;
	ktime_t tstamp = skb->tstamp;
	struct ip_frag_state state;
@@ -82,7 +82,7 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
			if (iter.frag)
				ip_fraglist_prepare(skb, &iter);

			skb_set_delivery_time(skb, tstamp, mono_delivery_time);
			skb_set_delivery_time(skb, tstamp, tstamp_type);
			err = output(net, sk, data, skb);
			if (err || !iter.frag)
				break;
@@ -113,7 +113,7 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
			goto blackhole;
		}

		skb_set_delivery_time(skb2, tstamp, mono_delivery_time);
		skb_set_delivery_time(skb2, tstamp, tstamp_type);
		err = output(net, sk, data, skb2);
		if (err)
			goto blackhole;
+1 −1
Original line number Diff line number Diff line
@@ -2160,7 +2160,7 @@ EXPORT_SYMBOL(net_disable_timestamp);
static inline void net_timestamp_set(struct sk_buff *skb)
{
	skb->tstamp = 0;
	skb->mono_delivery_time = 0;
	skb->tstamp_type = SKB_CLOCK_REALTIME;
	if (static_branch_unlikely(&netstamp_needed_key))
		skb->tstamp = ktime_get_real();
}
Loading