From patchwork Mon Oct 28 11:05:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853290 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0795D1DF24A; Mon, 28 Oct 2024 11:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113576; cv=none; b=pu64mGOYegNzQbVaKYShTYfIN9xY5fhIntbTdpOOoWyS1mPoXhUUuJLvHqpn3vl92TBv1e42BsBetFU6I/t1X5u51zQ0r7iSQxyypcSJ4HOTJrYQstNt1iFG+acUxwODkPp12liL780aZXFXkhLwuK+HzT3dO0alENQVhWMC3sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113576; c=relaxed/simple; bh=62HK8H2mMs+dN3ji2VLsJY2q1xrmdVQuqXAUCKWSZGY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jAD7N4P1IKb7yceRtkuNHwOA1mBvJGrdIDzKeUiovZsjuHdcFjop7y54tjnq2sqrNC9F5cXvZxpXkoZK4YTqTIg/UXg7xKf43Mpoxzimjs1k+Cz5GzqlavutAzTRYfm1GvujlezA8L2jTfCD4SQ1Wtlb+HwM1ZI8po+VWofCtMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AiDkd6fh; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AiDkd6fh" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20cb7139d9dso35829175ad.1; Mon, 28 Oct 2024 04:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113574; x=1730718374; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7wWRn1rcALp58jystE9RjEhjL8+m9tZaufvSsaBQQlA=; b=AiDkd6fhJ8mLZ338OPFlilaRc/uB2otLK20dC4JOzHFmhiUrYQp+gbDREVDpscnTLO VK47KEc3dK/WDLg0Lo6LIeh8THZWzaukZ6Er+Rn3bN/4ik7iG/CY2DAr3I6m1BL01nU2 Fv1kUUbE2aqhdxOeS+Nohnw1744t100JZ4vUBNUuNUBCpAWeOlD4Tye7kpnmXuyJGdsZ v7z7ObHFHamr96NU7QlcQytmDLlCenkrRWdG0qvocsZWVwpMvAgolLfqGC1bFam7YRHl Ro2XUiGdk2oTf8pUveuGYmnLDzWALWbhx2R6ObQ6ix+eqh73hVrceATvvqtWRr3jBA7N SzbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113574; x=1730718374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7wWRn1rcALp58jystE9RjEhjL8+m9tZaufvSsaBQQlA=; b=uz+EjC46t9o/rSnM1e5ClH7s8eZHNcV/hTEKNGXBTuiPHKIOWJWi1NO0TDAQE3C4IP bnKd6DY6iaB9rrecI7otBPQl1tRwKPAmuA57mqW3cCR04ItegJ3TBKmTFUYHgTrQElXq 09VwrH8Y943LVjCyoyWKStSPzf9pWTyzTD3Bm1V9XfZC3SJgmuWbCkJkG3djvqh+iBAp SNslksGREgVyKSqDB1IpbhhwjjjIR4FEhCIaohqVHSKOtjHm7KwFv7qTp04WQHiENxzC BwjAL0YAXCA8KFJx9fNQ/WSFkzFfmmq1b2khIBjLvIb9ha0ray2xg1W01vZ1q7PEqtva uf+A== X-Forwarded-Encrypted: i=1; AJvYcCVfydQ0EIgof6T6ykOyrK/jXxqObpQan0b8VpDir5CigxdMzOAGwav+XofpIdiXotABsdWYfDo=@vger.kernel.org X-Gm-Message-State: AOJu0YyKn6uMvUtXZouIwDqkJsBDlMvL3t4ECgs3o3bNFcu2QzGXgjoM Zq/ES4o2yB3Lh8PhKalT98tbthQmtp06QA7fxFpKP/mfkcLVy7ti X-Google-Smtp-Source: AGHT+IG8vJ7e1Oljyqg6Zq+5+sPx2T/5w9lZDnqrQexJ+MJoh0leVkWZVxJiWYqZTF1B3VZBtTKODw== X-Received: by 2002:a17:902:cecd:b0:20c:a97d:cc7f with SMTP id d9443c01a7336-210c6c3ec78mr112080825ad.41.1730113574171; Mon, 28 Oct 2024 04:06:14 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:13 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 01/14] net-timestamp: reorganize in skb_tstamp_tx_output() Date: Mon, 28 Oct 2024 19:05:22 +0800 Message-Id: <20241028110535.82999-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing It's a prep for bpf print function later. This patch only puts the original generating logic into one function, so that we integrate bpf print easily. No functional changes here. Signed-off-by: Jason Xing --- net/core/skbuff.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 00afeb90c23a..1cf8416f4123 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5539,18 +5539,15 @@ void skb_complete_tx_timestamp(struct sk_buff *skb, } EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp); -void __skb_tstamp_tx(struct sk_buff *orig_skb, - const struct sk_buff *ack_skb, - struct skb_shared_hwtstamps *hwtstamps, - struct sock *sk, int tstype) +static void skb_tstamp_tx_output(struct sk_buff *orig_skb, + const struct sk_buff *ack_skb, + struct skb_shared_hwtstamps *hwtstamps, + struct sock *sk, int tstype) { struct sk_buff *skb; bool tsonly, opt_stats = false; u32 tsflags; - if (!sk) - return; - tsflags = READ_ONCE(sk->sk_tsflags); if (!hwtstamps && !(tsflags & SOF_TIMESTAMPING_OPT_TX_SWHW) && skb_shinfo(orig_skb)->tx_flags & SKBTX_IN_PROGRESS) @@ -5594,6 +5591,17 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, __skb_complete_tx_timestamp(skb, sk, tstype, opt_stats); } + +void __skb_tstamp_tx(struct sk_buff *orig_skb, + const struct sk_buff *ack_skb, + struct skb_shared_hwtstamps *hwtstamps, + struct sock *sk, int tstype) +{ + if (!sk) + return; + + skb_tstamp_tx_output(orig_skb, ack_skb, hwtstamps, sk, tstype); +} EXPORT_SYMBOL_GPL(__skb_tstamp_tx); void skb_tstamp_tx(struct sk_buff *orig_skb, From patchwork Mon Oct 28 11:05:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853291 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D4731D934C; Mon, 28 Oct 2024 11:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113582; cv=none; b=jMXNLJKAytmamnWVBJtNqKzf37z+nlEdAZ7cY/YN48y8rGT67Ei+PL7S7XMEFF3j0IkK0E9QymPhp1A9D2B89Y6oTKqHLzQwLJARNtlqcmJ2bZvJDbRiz4Bmy72tl23wsTjNy4NiA4zIIQde27m/P/TKOXPlDla0/ADVn9M72Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113582; c=relaxed/simple; bh=PuZIRkUQ8K4Nbm3rnLNZvyqyKXl0Mb7338tg/MZoXI0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VBJl0IdNV0mn1DTpW+g51EKJWdKniYP/gnU2cfjSnSeMtwczdUgjZCuylTRTXdrvq7Y4ADpcgTbAPY0bwyNJcctwpNTfJKY/+QUO2UHeftx+YyjXWQeES3MUcLIx1uMkUf7l4Z9Awc5PcqSDJIu49Di1f5LhffK2pGbCngLnKsU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TeoUdT3I; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TeoUdT3I" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20cd76c513cso36271005ad.3; Mon, 28 Oct 2024 04:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113580; x=1730718380; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CVgQ8n9shhywkNLwNDFzDUD4fM/nq8q7zXQRUAnSVLE=; b=TeoUdT3IcDFJe7u7tveqNBWnmBxLSHaTdu1YIKoSVIkW7SqlHtLy7vGhjhFfdBooYH BjR3iE4uF9/m5isjuYsOsxKFNXhYISVNDCNfBa+hLqlKgXikqyYe1mMaB85eRX1fQ/Ks +8gTbw/NI3/90CVVjh1GbrhPME7SdU2T7ZMjHGzhT84wYYyQ4b+JxSe+TDOVBkB2IO7F ip9MfcVPiR7xJV9gONm/z49l5EtuQDnGDRyEJsf0KLglFa0IS4WrdeompTscUTe3uf7T qRQv71gBSNL210FW+YmmEn05om7oiQtZKA6Rbe/2vk/xj8K5kN8sg3M/1gxDE1G751RH lWjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113580; x=1730718380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CVgQ8n9shhywkNLwNDFzDUD4fM/nq8q7zXQRUAnSVLE=; b=Oy+vCNqZt+4b8YCkSnIJlrf4QCHfxpleQlFvAo2vYoVGww5+s58T3nCM4fpgjXMDf9 3UObz466+2VOY1diJ1vXoLp+D0gEDL7RoY4fCp+dP6CM34NKHIUo7wD7xPWNAhBBkTBi PGh08uJJnNd2+1GMtO4uSUuI63N5DjV/vFB6nRN0OGKsvgVe9rrSNh/FrCBqv9TlKwFz SJ5z19VWGIb7sGkgjIFScVaz7nGpc/Dle+GfWHimH0y1s3c3fLUEeqH+mRTXkduCzwQh utDAINN2A3HpxjjtPxgBXt2wjoNNML9dlsfqYOCr/72SrII7EFJbMYTMB+TglyZHNztM H7Dg== X-Forwarded-Encrypted: i=1; AJvYcCWViIC8rk4lgP2pPg2WrxyWOmEPPkZAgHdGb5JxN65F0j8Exjah15kAOYiXVbcBSpYW9RwjCUY=@vger.kernel.org X-Gm-Message-State: AOJu0YzDvJe5g3QQlDt+2zTjuV1pLyehULPOD6qvZz7njc+aiUaMpra/ G3hCWI2ZqvJH3ifhJWhlEqkld+wwbIbvFTapcE61B6oa9ijGObHV X-Google-Smtp-Source: AGHT+IGlgNB91QL9FotI+bnG6jfjoA8j9fo7eaWaJjJKUApuUYxeq0SvnK4qviKm36X7aLqaj4lZkg== X-Received: by 2002:a17:903:41c3:b0:20c:b606:d014 with SMTP id d9443c01a7336-210c6c7351amr88597595ad.44.1730113579592; Mon, 28 Oct 2024 04:06:19 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:19 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 02/14] net-timestamp: allow two features to work parallelly Date: Mon, 28 Oct 2024 19:05:23 +0800 Message-Id: <20241028110535.82999-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing This patch has introduced a separate sk_tsflags_bpf for bpf extension, which helps us let two feature work nearly at the same time. Each feature will finally take effect on skb_shinfo(skb)->tx_flags, say, tcp_tx_timestamp() for TCP or skb_setup_tx_timestamp() for other types, so in __skb_tstamp_tx() we are unable to know which feature is turned on, unless we check each feature's own socket flag field. Signed-off-by: Jason Xing --- include/net/sock.h | 1 + net/core/skbuff.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/net/sock.h b/include/net/sock.h index 7464e9f9f47c..5384f1e49f5c 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -445,6 +445,7 @@ struct sock { u32 sk_reserved_mem; int sk_forward_alloc; u32 sk_tsflags; + u32 sk_tsflags_bpf; __cacheline_group_end(sock_write_rxtx); __cacheline_group_begin(sock_write_tx); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1cf8416f4123..39309f75e105 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5539,6 +5539,32 @@ void skb_complete_tx_timestamp(struct sk_buff *skb, } EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp); +/* This function is used to test if application SO_TIMESTAMPING feature + * or bpf SO_TIMESTAMPING feature is loaded by checking its own socket flags. + */ +static bool sk_tstamp_tx_flags(struct sock *sk, u32 tsflags, int tstype) +{ + u32 testflag; + + switch (tstype) { + case SCM_TSTAMP_SCHED: + testflag = SOF_TIMESTAMPING_TX_SCHED; + break; + case SCM_TSTAMP_SND: + testflag = SOF_TIMESTAMPING_TX_SOFTWARE; + break; + case SCM_TSTAMP_ACK: + testflag = SOF_TIMESTAMPING_TX_ACK; + break; + default: + return false; + } + if (tsflags & testflag) + return true; + + return false; +} + static void skb_tstamp_tx_output(struct sk_buff *orig_skb, const struct sk_buff *ack_skb, struct skb_shared_hwtstamps *hwtstamps, @@ -5549,6 +5575,9 @@ static void skb_tstamp_tx_output(struct sk_buff *orig_skb, u32 tsflags; tsflags = READ_ONCE(sk->sk_tsflags); + if (!sk_tstamp_tx_flags(sk, tsflags, tstype)) + return; + if (!hwtstamps && !(tsflags & SOF_TIMESTAMPING_OPT_TX_SWHW) && skb_shinfo(orig_skb)->tx_flags & SKBTX_IN_PROGRESS) return; @@ -5592,6 +5621,15 @@ static void skb_tstamp_tx_output(struct sk_buff *orig_skb, __skb_complete_tx_timestamp(skb, sk, tstype, opt_stats); } +static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype) +{ + u32 tsflags; + + tsflags = READ_ONCE(sk->sk_tsflags_bpf); + if (!sk_tstamp_tx_flags(sk, tsflags, tstype)) + return; +} + void __skb_tstamp_tx(struct sk_buff *orig_skb, const struct sk_buff *ack_skb, struct skb_shared_hwtstamps *hwtstamps, @@ -5600,6 +5638,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, if (!sk) return; + skb_tstamp_tx_output_bpf(sk, tstype); skb_tstamp_tx_output(orig_skb, ack_skb, hwtstamps, sk, tstype); } EXPORT_SYMBOL_GPL(__skb_tstamp_tx); From patchwork Mon Oct 28 11:05:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853292 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FE431DF26F; Mon, 28 Oct 2024 11:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113589; cv=none; b=uEPRoZZ/RBMVfP90S2OV2VZZRx4QSuigGQG/zrrB0ublGirg0Jl7G8VP9jDSyijLdqeMyVMc7EWR0LIf/FXdO2KhmzTbXzaCAR2piNoA5NXwAHQ7j/uhTC9d73OO3VvghmF9ycRAhKeYo0REROg6WoveWHkaT6nHD+uSpP84IMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113589; c=relaxed/simple; bh=k9HmVYeawBX2SpeoxCKJ+InFGLGRTQOaV1sixDaj740=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fQ4C33otGlVBuE5nq3BbqWRVqfppwDT68fUAYfz64dQRQMjpLxqOYFFehSFr8qnAdva5ihMOwrtuzE0UmIpLUf1QKAS7OLeGG6wktcRe1KLM9C5rHbkfcC1VExObAIYkUSYx2ngrWdKDw6KBdO0gv5Th5bwCWThiy3ceqZWvCtk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dYue9x+M; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dYue9x+M" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20cdb889222so38151905ad.3; Mon, 28 Oct 2024 04:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113587; x=1730718387; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=20KkNWOP/RO5bujtzpUiEeBLs9+BSyXwQMtz9AwS0TQ=; b=dYue9x+MWOM/65gFhtyaBpa9nIjF+rT7e1IC+wbrCgYbKZ6eXrqDUbuciXYE7SPEwq 9rMof2pdFq5/tZ7amWBMm/FvVIeA4Yj0oDoXPb5bzjaA4RnwO77OEG3cGsa9Q0aPHxtF hq5XtYbFqlcdxczOZBMQd4CzXnAZsHVBN0qL8P9hw0tFaLvD+Y7PU7WN6032OXd98IiK +EJKupIehekdOrh7UCJfbq83cUDDNOFGS2jU9kcIq1UE1wXoOCnBVTRSq4LVhjK+4cyb X0vcA0dg0logvQCoCwM45P8seuviduhifmGufIp3x7XphMRd6e1UL/9ukHrjEyz0HAqd WhRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113587; x=1730718387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=20KkNWOP/RO5bujtzpUiEeBLs9+BSyXwQMtz9AwS0TQ=; b=K+RXeyUI4dxb5xZvFA9cDtXfeRFgb+AdQPp+wSIqoeWLHtQvcOAW1Cp/fsJBAHdICp oMPSlIw1JHtf3GtnJeQu2rgvVNqKa72QEUYpfCHYmXmrnwVOx4qybIO1LfyyNQ7c1338 8E8tdAazp8BVOt7lt8PvbT1a9UY0a+sJIhqYcVh8Yl/fGpXtOMTzZQIUXJ/6Z2/LmMqn KV3zlxVHl8aQrybwkaUbpOagmVtD/z8K/47OoebGrIJGRwbwHjZv3v4+JywGp0vE/Vdk r5HEDoNEEFpGPLIB5XiBH3yWbzJeyofpzfZ224twptl65B14E7X/+x4kEIOwRMPla97o 0QjA== X-Forwarded-Encrypted: i=1; AJvYcCX28F2i8QLAv4o11/Fhbs85t5y9x5LGoOrLATYFnlhTFN9e19y0z2O9mkhOEwlMYqrxbLJpPUA=@vger.kernel.org X-Gm-Message-State: AOJu0YyqKPejUMpyw3aRWAX/23/m2DiC2UFZZo3S7tNiTqojk3ugzSpm QdCgpS1/O4qW2G8nk8p1pUcyzU2Ke/sHiQik2gkCP2xtFcMeWJNp X-Google-Smtp-Source: AGHT+IFgKZm+dERnFZZKprmu12eDj4bD6GHUf8cRczBLzTYPbF1J/YPhYMMtsPtV70x7RrHEbcFWFw== X-Received: by 2002:a17:902:f54e:b0:20b:5439:f194 with SMTP id d9443c01a7336-210c6898707mr98507135ad.16.1730113585157; Mon, 28 Oct 2024 04:06:25 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:24 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 03/14] net-timestamp: open gate for bpf_setsockopt/_getsockopt Date: Mon, 28 Oct 2024 19:05:24 +0800 Message-Id: <20241028110535.82999-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing For now, we support bpf_setsockopt to set or clear timestamps flags. Users can use something like this in bpf program to turn on the feature: flags = SOF_TIMESTAMPING_TX_SCHED; bpf_setsockopt(skops, SOL_SOCKET, SO_TIMESTAMPING, &flags, sizeof(flags)); The specific use cases can be seen in the bpf selftest in this series. Later, I will support each flags one by one based on this. Signed-off-by: Jason Xing --- include/net/sock.h | 4 ++-- include/uapi/linux/net_tstamp.h | 7 +++++++ net/core/filter.c | 7 +++++-- net/core/sock.c | 34 ++++++++++++++++++++++++++------- net/ipv4/udp.c | 2 +- net/mptcp/sockopt.c | 2 +- net/socket.c | 2 +- 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 5384f1e49f5c..062f405c744e 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1775,7 +1775,7 @@ static inline void skb_set_owner_edemux(struct sk_buff *skb, struct sock *sk) #endif int sk_setsockopt(struct sock *sk, int level, int optname, - sockptr_t optval, unsigned int optlen); + sockptr_t optval, unsigned int optlen, bool bpf_timetamping); int sock_setsockopt(struct socket *sock, int level, int op, sockptr_t optval, unsigned int optlen); int do_sock_setsockopt(struct socket *sock, bool compat, int level, @@ -1784,7 +1784,7 @@ int do_sock_getsockopt(struct socket *sock, bool compat, int level, int optname, sockptr_t optval, sockptr_t optlen); int sk_getsockopt(struct sock *sk, int level, int optname, - sockptr_t optval, sockptr_t optlen); + sockptr_t optval, sockptr_t optlen, bool bpf_timetamping); int sock_gettstamp(struct socket *sock, void __user *userstamp, bool timeval, bool time32); struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len, diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h index 858339d1c1c4..0696699cf964 100644 --- a/include/uapi/linux/net_tstamp.h +++ b/include/uapi/linux/net_tstamp.h @@ -49,6 +49,13 @@ enum { SOF_TIMESTAMPING_TX_SCHED | \ SOF_TIMESTAMPING_TX_ACK) +#define SOF_TIMESTAMPING_BPF_SUPPPORTED_MASK (SOF_TIMESTAMPING_SOFTWARE | \ + SOF_TIMESTAMPING_TX_SCHED | \ + SOF_TIMESTAMPING_TX_SOFTWARE | \ + SOF_TIMESTAMPING_TX_ACK | \ + SOF_TIMESTAMPING_OPT_ID | \ + SOF_TIMESTAMPING_OPT_ID_TCP) + /** * struct so_timestamping - SO_TIMESTAMPING parameter * diff --git a/net/core/filter.c b/net/core/filter.c index 58761263176c..dc8ecf899ced 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5238,6 +5238,9 @@ static int sol_socket_sockopt(struct sock *sk, int optname, break; case SO_BINDTODEVICE: break; + case SO_TIMESTAMPING_NEW: + case SO_TIMESTAMPING_OLD: + break; default: return -EINVAL; } @@ -5247,11 +5250,11 @@ static int sol_socket_sockopt(struct sock *sk, int optname, return -EINVAL; return sk_getsockopt(sk, SOL_SOCKET, optname, KERNEL_SOCKPTR(optval), - KERNEL_SOCKPTR(optlen)); + KERNEL_SOCKPTR(optlen), true); } return sk_setsockopt(sk, SOL_SOCKET, optname, - KERNEL_SOCKPTR(optval), *optlen); + KERNEL_SOCKPTR(optval), *optlen, true); } static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname, diff --git a/net/core/sock.c b/net/core/sock.c index 7f398bd07fb7..7e05748b1a06 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -941,6 +941,19 @@ int sock_set_timestamping(struct sock *sk, int optname, return 0; } +static int sock_set_timestamping_bpf(struct sock *sk, + struct so_timestamping timestamping) +{ + u32 flags = timestamping.flags; + + if (flags & ~SOF_TIMESTAMPING_BPF_SUPPPORTED_MASK) + return -EINVAL; + + WRITE_ONCE(sk->sk_tsflags_bpf, flags); + + return 0; +} + void sock_set_keepalive(struct sock *sk) { lock_sock(sk); @@ -1159,7 +1172,7 @@ static int sockopt_validate_clockid(__kernel_clockid_t value) */ int sk_setsockopt(struct sock *sk, int level, int optname, - sockptr_t optval, unsigned int optlen) + sockptr_t optval, unsigned int optlen, bool bpf_timetamping) { struct so_timestamping timestamping; struct socket *sock = sk->sk_socket; @@ -1409,7 +1422,10 @@ int sk_setsockopt(struct sock *sk, int level, int optname, memset(×tamping, 0, sizeof(timestamping)); timestamping.flags = val; } - ret = sock_set_timestamping(sk, optname, timestamping); + if (!bpf_timetamping) + ret = sock_set_timestamping(sk, optname, timestamping); + else + ret = sock_set_timestamping_bpf(sk, timestamping); break; case SO_RCVLOWAT: @@ -1626,7 +1642,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, unsigned int optlen) { return sk_setsockopt(sock->sk, level, optname, - optval, optlen); + optval, optlen, false); } EXPORT_SYMBOL(sock_setsockopt); @@ -1670,7 +1686,7 @@ static int groups_to_user(sockptr_t dst, const struct group_info *src) } int sk_getsockopt(struct sock *sk, int level, int optname, - sockptr_t optval, sockptr_t optlen) + sockptr_t optval, sockptr_t optlen, bool bpf_timetamping) { struct socket *sock = sk->sk_socket; @@ -1793,9 +1809,13 @@ int sk_getsockopt(struct sock *sk, int level, int optname, * returning the flags when they were set through the same option. * Don't change the beviour for the old case SO_TIMESTAMPING_OLD. */ - if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) { - v.timestamping.flags = READ_ONCE(sk->sk_tsflags); - v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); + if (!bpf_timetamping) { + if (optname == SO_TIMESTAMPING_OLD || sock_flag(sk, SOCK_TSTAMP_NEW)) { + v.timestamping.flags = READ_ONCE(sk->sk_tsflags); + v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); + } + } else { + v.timestamping.flags = READ_ONCE(sk->sk_tsflags_bpf); } break; diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 0e24916b39d4..9a20af41e272 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2679,7 +2679,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname, int is_udplite = IS_UDPLITE(sk); if (level == SOL_SOCKET) { - err = sk_setsockopt(sk, level, optname, optval, optlen); + err = sk_setsockopt(sk, level, optname, optval, optlen, false); if (optname == SO_RCVBUF || optname == SO_RCVBUFFORCE) { sockopt_lock_sock(sk); diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 505445a9598f..7b12cc2db136 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -306,7 +306,7 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname, return PTR_ERR(ssk); } - ret = sk_setsockopt(ssk, SOL_SOCKET, optname, optval, optlen); + ret = sk_setsockopt(ssk, SOL_SOCKET, optname, optval, optlen, false); if (ret == 0) { if (optname == SO_REUSEPORT) sk->sk_reuseport = ssk->sk_reuseport; diff --git a/net/socket.c b/net/socket.c index 9a8e4452b9b2..4bdca39685a6 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2385,7 +2385,7 @@ int do_sock_getsockopt(struct socket *sock, bool compat, int level, ops = READ_ONCE(sock->ops); if (level == SOL_SOCKET) { - err = sk_getsockopt(sock->sk, level, optname, optval, optlen); + err = sk_getsockopt(sock->sk, level, optname, optval, optlen, false); } else if (unlikely(!ops->getsockopt)) { err = -EOPNOTSUPP; } else { From patchwork Mon Oct 28 11:05:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853293 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7251D1DF720; Mon, 28 Oct 2024 11:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113593; cv=none; b=QMpe7Hk7pLcA7yhJAfh2e3SygOMt2DZANaemn/+QEK2uv2DDz6UE8r9KDF/QMW2YMBK9RYZ/vGW30bmO7qNDboYMoDaBqgL/hh5bGomapW5d8w33Wmbg2qMku8ro6r+DMh0INC0D++0Tc8DIHb8vVoVhU/PX/8j13THK1h2aVGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113593; c=relaxed/simple; bh=CB6K3j14X/CVRq/52BsIc7pB+5IDgpJbM+3S14LdwXg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dUQ+2ukfjwzIllehPm5ZE1B567w6Lj/3/TkjU/dNqbWde3css6Aqt3yRaKqOAUsjvq7yLl37cYBFrSSx6yIZ+P8O4yBGQWYNyajx2omYgiYBr3GvrI1jwp0osc5aA+lGmVt/oKadktIEVuLkQK2mFXYEJpKmNM9Jj95SJzW4Eic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BDNTsp66; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BDNTsp66" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20c803787abso32082475ad.0; Mon, 28 Oct 2024 04:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113591; x=1730718391; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YDr+6JoYtBk0XGAFGCg5P5S3RT7qdV0GMOwN8CvM128=; b=BDNTsp660AW2mVHgMHmYEzvEJcpt3EzfNl79TZioFt0Z24L8ijpo7IbMLUGY79kydk Tz+NmFQ1p3r+UESICqoH5oz5WekzbyQ/KmtkyZ1JXthSOEvK2C+ymlGs1DzFirkBP2sO QocEjiS/noKSBQGD5Zs83mOcpYri1o8uJ9mvkOj/i8ZxDAsYmvfviH2nPQyYbsulZI7/ fYWpoIN0NbbHbfZYt0CRHdspod9FwpdnhinSRlmEEIJZM3bo9XMALx6l2cf2XRxXjeRZ u3m8QOC8rOcjLEPm5zpW2EgA8+FDYO84X+B8skQl4YSJH/XOEnOQv4Gp33b0cixIJi1D lCKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113591; x=1730718391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YDr+6JoYtBk0XGAFGCg5P5S3RT7qdV0GMOwN8CvM128=; b=XQMi1VP9zZkzAaF4eExE5HJZBNBWtXS1ub/kfe1iCZe35d0uFdXOXVec1LtrrtxgCi 0eHR4GVzVR659RAdj3/YSWbK2ZuAki5h3i7u3rA3Yb1QCgSZyBFCphlqrzBXDDkzhCTW wACnlDe/QZUX0Kb8FE5/Qa7f208LGhFYb9T9FgtozLu2gIp4ZYdWy/BQz95rwDyPAfO0 ta80zh1tdBZLdaKQdZEq6kz4BQgYqb2GfazLZcGPhY2LFazBKOCjk00JX/ePUypP+++J R2oVyihZW/4NLtWbcGbh7gAekfnZPv5ku3xMfs7J+vUXUJCOyNj6tpJf9/quvEN1oT7T GZtQ== X-Forwarded-Encrypted: i=1; AJvYcCV8c1k5VTQ1YnjEJbEGGc5xx+LcCWg8VKVhpwGdzLYyaA/gVn0lSBuX/RcrANijltVz9QyRuew=@vger.kernel.org X-Gm-Message-State: AOJu0YxGFOyk3ZrR+qtayX4BQNF8JxfDm7/q+YTtcrrML2fqzyiM6tKp UbfLKmRhRMDO9sdqNc2BIkZwDEiysfvezLxJLGD0WMDSYv4mDe20 X-Google-Smtp-Source: AGHT+IF+R8X+uwB2+p0Vvvzq/sZs3Il35XvlUuXZGeFT7V3j7FWeE7kn5FAAK4fYAsBr/aokW9fX3w== X-Received: by 2002:a17:902:da8f:b0:20b:a41f:6e4d with SMTP id d9443c01a7336-210c59c6353mr103488775ad.15.1730113590619; Mon, 28 Oct 2024 04:06:30 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:30 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 04/14] net-timestamp: introduce TS_SCHED_OPT_CB to generate dev xmit timestamp Date: Mon, 28 Oct 2024 19:05:25 +0800 Message-Id: <20241028110535.82999-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Introduce BPF_SOCK_OPS_TS_SCHED_OPT_CB flag so that we can decide to print timestamps when the skb just passes the dev layer. Signed-off-by: Jason Xing --- include/uapi/linux/bpf.h | 5 +++++ net/core/skbuff.c | 31 ++++++++++++++++++++++++++++++- tools/include/uapi/linux/bpf.h | 5 +++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index e8241b320c6d..324e9e40969c 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7013,6 +7013,11 @@ enum { * by the kernel or the * earlier bpf-progs. */ + BPF_SOCK_OPS_TS_SCHED_OPT_CB, /* Called when skb is passing through + * dev layer when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 39309f75e105..e6a5c883bdc6 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -5621,13 +5622,41 @@ static void skb_tstamp_tx_output(struct sk_buff *orig_skb, __skb_complete_tx_timestamp(skb, sk, tstype, opt_stats); } +static void timestamp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) +{ + struct bpf_sock_ops_kern sock_ops; + + memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp)); + if (sk_fullsock(sk)) { + sock_ops.is_fullsock = 1; + sock_owned_by_me(sk); + } + + sock_ops.sk = sk; + sock_ops.op = op; + if (nargs > 0) + memcpy(sock_ops.args, args, nargs * sizeof(*args)); + + BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk); +} + static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype) { - u32 tsflags; + u32 tsflags, cb_flag; tsflags = READ_ONCE(sk->sk_tsflags_bpf); if (!sk_tstamp_tx_flags(sk, tsflags, tstype)) return; + + switch (tstype) { + case SCM_TSTAMP_SCHED: + cb_flag = BPF_SOCK_OPS_TS_SCHED_OPT_CB; + break; + default: + return; + } + + timestamp_call_bpf(sk, cb_flag, 0, NULL); } void __skb_tstamp_tx(struct sk_buff *orig_skb, diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index e8241b320c6d..324e9e40969c 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -7013,6 +7013,11 @@ enum { * by the kernel or the * earlier bpf-progs. */ + BPF_SOCK_OPS_TS_SCHED_OPT_CB, /* Called when skb is passing through + * dev layer when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From patchwork Mon Oct 28 11:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853294 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F02E1D63C2; Mon, 28 Oct 2024 11:06:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113600; cv=none; b=SZwMJp14DySZDfAUFgMmZ0mTafPBuGce9dW4g+D4NKiv3k7fZRMx5/kIECSMc1O2SGEsWriqCuYomARgB/pUY3NcwnH19ZMfNWAaVEfF9wZOnBba1DN9NB34MP4COybCcZBhwLIdUwXDpFE3AcLvljgBnPEbz2uz6DCF2NttYds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113600; c=relaxed/simple; bh=ySuwdMV87AWtr1VxqSWLwcOLY8k1uhHE9g6jUBh91QA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mU4xC/gJ0k20VcCnnacBbilU+QsOagrVQyxg5goA9z84H4oUfZUyOwc4sFLYIkvZrvNMhlQ1e3lAI8vtchU4D+r+4qUrYqR6WM4A+cH3nqInz7PLPin1JGRMMKqLGTx4+fKSdR7Q6joKsF5rNHEPpZ0mRbm2FfURJRsox7L90bk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CU9eSi+b; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CU9eSi+b" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20c8b557f91so36789365ad.2; Mon, 28 Oct 2024 04:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113598; x=1730718398; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+BDPPLPrw1/fTqchv4EoQofqTfNJuNEjYPrOv25d2dU=; b=CU9eSi+bAoHQHv7SiTAXR2VSZhHRWpN0a2S5DwcRHkexDSG7zWktMtvJcbn0T7bOl4 sKPwhNKmc1f91A+rADqrOR1V78qC/7I0TUc+LoUifBe7Xi1tpBPFmS72RL+Xup2fwcIx FlwHFHbtKENbHZGyVhplkxXW6pC1RNI5WGA4AycnT7POct3oF+7YoDL7XwzicSSoeDWU AnN70ixrgy1RHNBGbgSLL0dMxtake05zTo2wlX/uk3YH+VAJpd8uQgf6+/baKkg0nsED TvjRclO45ali82HVEQt0ag1ytThntZIvS/bz5gmbTdICiwaIw95gMVIBcWZ+qyKus299 TyJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113598; x=1730718398; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+BDPPLPrw1/fTqchv4EoQofqTfNJuNEjYPrOv25d2dU=; b=lPQIw0VbU87g0mGeSHYVksuFOMbERaejfTfMnQELy2wRVPFWfjuUqOwDO6hUa13UoP TD+xuYR/vYxpOlHhR0jdx6r6EoDj39Zv6BMJJTMOgJLcjcH3eqSjQ6sLGzXvwLvUn+zl 3SQxm8b78UV23boiEVA19K8b12kREjufkpXcHslO4o+Ghvd0gMiboRkcP1as7Zvc+ENA AJA2+KLA+w6ute84TaqFR4qy7GmFqIkxvMOZceBJUrzxbJmzH4EXV8IAEauKkCR6nnLI pjKD3OAX5oJYABXsY9xm9QPEflBYFnkD6R+m/axTIf6kcF57OKT3kceG7tC1RVoECqzI 695Q== X-Forwarded-Encrypted: i=1; AJvYcCUmHBkLlLzwO1Rbw013lafK2m0L0ONc0hmFRF0IpjfmwJzCji1CN9v4pOxZCoUz0aSPby08DUw=@vger.kernel.org X-Gm-Message-State: AOJu0YzTX8Qu/SYV/wPbaizkzmURG4UBRoI9rViynJMVyxM1aRUuvcdE tqLIAmxdAJolRfsB50WzoW7qViY2FT5k7+UECfD/hlSxUExewnyF X-Google-Smtp-Source: AGHT+IHTG6q/BJ3iOrUGFVqhqIVWDERZQa46oRt9o8vCvmkSqWx+Ttgv+5uXqa2GjVxyW+NniTIs0w== X-Received: by 2002:a17:902:ea12:b0:20c:c9db:7c45 with SMTP id d9443c01a7336-210c68dd56amr104043585ad.20.1730113596119; Mon, 28 Oct 2024 04:06:36 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:35 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 05/14] net-timestamp: introduce TS_SW_OPT_CB to generate driver timestamp Date: Mon, 28 Oct 2024 19:05:26 +0800 Message-Id: <20241028110535.82999-6-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing When the skb is about to send from driver to nic, we can print timestamp by setting BPF_SOCK_OPS_TS_SW_OPT_CB in bpf program. Signed-off-by: Jason Xing --- include/uapi/linux/bpf.h | 5 +++++ net/core/skbuff.c | 19 ++++++++++++++++--- tools/include/uapi/linux/bpf.h | 5 +++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 324e9e40969c..b0032e173e65 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7018,6 +7018,11 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_SW_OPT_CB, /* Called when skb is about to send + * to the nic when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect diff --git a/net/core/skbuff.c b/net/core/skbuff.c index e6a5c883bdc6..e29ab3e45213 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5640,8 +5640,10 @@ static void timestamp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk); } -static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype) +static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype, + struct skb_shared_hwtstamps *hwtstamps) { + u32 args[2] = {0, 0}; u32 tsflags, cb_flag; tsflags = READ_ONCE(sk->sk_tsflags_bpf); @@ -5652,11 +5654,22 @@ static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype) case SCM_TSTAMP_SCHED: cb_flag = BPF_SOCK_OPS_TS_SCHED_OPT_CB; break; + case SCM_TSTAMP_SND: + cb_flag = BPF_SOCK_OPS_TS_SW_OPT_CB; + break; default: return; } - timestamp_call_bpf(sk, cb_flag, 0, NULL); + if (hwtstamps) { + struct timespec64 ts; + + ts = ktime_to_timespec64(hwtstamps->hwtstamp); + args[0] = ts.tv_sec; + args[1] = ts.tv_nsec; + } + + timestamp_call_bpf(sk, cb_flag, 2, args); } void __skb_tstamp_tx(struct sk_buff *orig_skb, @@ -5667,7 +5680,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, if (!sk) return; - skb_tstamp_tx_output_bpf(sk, tstype); + skb_tstamp_tx_output_bpf(sk, tstype, hwtstamps); skb_tstamp_tx_output(orig_skb, ack_skb, hwtstamps, sk, tstype); } EXPORT_SYMBOL_GPL(__skb_tstamp_tx); diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 324e9e40969c..b0032e173e65 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -7018,6 +7018,11 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_SW_OPT_CB, /* Called when skb is about to send + * to the nic when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From patchwork Mon Oct 28 11:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853295 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AF511D63C2; Mon, 28 Oct 2024 11:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113604; cv=none; b=QkOg/VQymySRi76VjA+b7GB4ADbnc67fu3s6NFn9WOhISX5Gy5dYtEfKulwdGlcUeZCkZgZ+CSrsz7J4hG/zSoIE944cWoMaXEzxg4tJxryx6TS9I2AtgIsnze4W6mJnusBqM8qlCICF0/uEJAAHYzZZ5t4PVZL7WuzClktClVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113604; c=relaxed/simple; bh=jSZyduiEaojae0Ui1uMVkgmozaMx8yHbh+MrDS/FCwI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kjbe83muabw0o5KA4xKxNq1pbvV3huGc1YFdTeeTZTId7LqTC4shL3QeOY30TZZw+WLHCzKGz9BI/EGU/KGIkGfWD01+0ijYIEhGa09TBhc//0ykSpffDw3wSSJt+JDVgbWbXEafQkayoKj6KboUVmbpPhlvUkYWK1GbwRrKkZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XQO8C8yD; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XQO8C8yD" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7ea7e2ff5ceso2826470a12.2; Mon, 28 Oct 2024 04:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113601; x=1730718401; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+2lvZp9BQ0jH1Q0pNlMCfDLNO2tabFVRH+VT4zsGqEo=; b=XQO8C8yDWQCDlwC/Bjjm2gIRD4dAZ8/f9KGakm5JAth7P8az5vLD2ATnkpEAiiDEUF 3uMnIQFYjBqCAgdwBxbPL4Ratc9D0zwNepIWnc0DgUOGoAC7UjKACsuVdwzJmfStUlLd TNixwzLrKnIgwoVyTJ+1nXrzb2xSuQS9FpLlqswtElmhbum8THhC5lsxAO3hlYmjzyAj ZR7pL17ZhBMUFPN06j1SS4OOqYAFcgxgOZyFjqUzcgvlXXm4nm0GERMvlEahiPuL2VFw oN6cxcF9/QiInK7mce/p4f2C8Jx69ZmXs9Uf/8H+siW8fueASiYhWUZlgzZn7vka0si6 8fGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113601; x=1730718401; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+2lvZp9BQ0jH1Q0pNlMCfDLNO2tabFVRH+VT4zsGqEo=; b=cPuGDQoeW3vzXA0J8IZnhrR5NGkLJtD9ZklqgEIqtRfO4kkGXvfeYMxJ1A/51BCtaQ jI9bVn7Mk2Ttw/uaZGWLtKj5vi3KS4fUx0oXFMTvT1eEfayrnbM5hKBJiaww0WQsHH01 5R/sxJ74yJct/E6ThlH44OsUDuzpX3B/Qi2wlh1XLZdNt7Isw5JS2L6HDGQT7Zlk1ftR Qmf5tjd3e/NNOhXqSe4jemWM/DULJDjMEfEjO9yfdk9F3yxknA4OwTavnt/W093Usikq 9TaSKemU0AhwCKFt5U3blG2x6f5Gex4FWF0OslwFGPtUsBIT+vX62ElsFqb2U3FuZuam yM+w== X-Forwarded-Encrypted: i=1; AJvYcCXUvew4dghSBHjjD7lo0xVqs4aNQ+BgHLV31XO4QUcelUNHpicvux4tsh0l9FQRqmoy9jK7/w8=@vger.kernel.org X-Gm-Message-State: AOJu0YxpbaEiD0AF2cL7UT9gwxywzEILV36NDGxXkatjwGK9sARvnmjz gDgS2JY2d9b6DpmTHIYsJyGrKfWHNHxCYvcXO8m6HczjVsS9RsKY X-Google-Smtp-Source: AGHT+IGvZknUgZg1xEurGkZQWusHqdpyrPtQhOIKiuiWyHOcZpWZlBQTeUhHfMkthjQgrodESvotjg== X-Received: by 2002:a05:6a20:e608:b0:1d9:18e2:e0aa with SMTP id adf61e73a8af0-1d9a855ef95mr9901147637.44.1730113601384; Mon, 28 Oct 2024 04:06:41 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:41 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 06/14] net-timestamp: introduce TS_ACK_OPT_CB to generate tcp acked timestamp Date: Mon, 28 Oct 2024 19:05:27 +0800 Message-Id: <20241028110535.82999-7-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing When the last sent skb in each sendmsg() is acknowledged in TCP layer, we can print timestamp by setting BPF_SOCK_OPS_TS_ACK_OPT_CB in bpf program. Signed-off-by: Jason Xing --- include/uapi/linux/bpf.h | 5 +++++ net/core/skbuff.c | 3 +++ tools/include/uapi/linux/bpf.h | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index b0032e173e65..6fc3bd12b650 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7023,6 +7023,11 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_ACK_OPT_CB, /* Called when all the skbs are + * acknowledged when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect diff --git a/net/core/skbuff.c b/net/core/skbuff.c index e29ab3e45213..8b2a79c0fe1c 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5657,6 +5657,9 @@ static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype, case SCM_TSTAMP_SND: cb_flag = BPF_SOCK_OPS_TS_SW_OPT_CB; break; + case SCM_TSTAMP_ACK: + cb_flag = BPF_SOCK_OPS_TS_ACK_OPT_CB; + break; default: return; } diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index b0032e173e65..6fc3bd12b650 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -7023,6 +7023,11 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_ACK_OPT_CB, /* Called when all the skbs are + * acknowledged when SO_TIMESTAMPING + * feature is on. It indicates the + * recorded timestamp. + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From patchwork Mon Oct 28 11:05:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853296 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1E21DF96B; Mon, 28 Oct 2024 11:06:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113609; cv=none; b=HKn/r2zjTDYqubKRT2vUYcnk0gNSLdr2+D8zcxKISH0O+IP7070EsFUJpnj2f3ZPNn+dpMUCRx1qbsvknF9Z6XX6FVo7KkRvrOWsyM1l0vZpAKe/bHua73OKwZsCZIn/sVj+GkQSWMz0TqZcu5BDiTuaSfMw9O0qFPYeHOXilCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113609; c=relaxed/simple; bh=RWx2cq8Cr0BPhZZ/C99Z5w3kmuS5XcUTo9ioPrVfges=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jGMznzsCSI6G0w7fFjBKzeTgCxPGepYZV+auzyQIgQKd6GLyqU4lTmy3xQHqQGdUoOGC1h8MhiqvqQzFkZ05VfNLN4PPdjZB0MQwgrJrnPiAhUbj/9Syjy9bxlnFcRSFYb3eRaIkh53M3Q2QsWrrEWZ+DWUoYH4JkbICE/7QExU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FhzQqzMj; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FhzQqzMj" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20cf3e36a76so39704355ad.0; Mon, 28 Oct 2024 04:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113607; x=1730718407; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qyOUNRXsLlQkNpP9ouZlfMLDHIlRndz2Tp+MnGE5vek=; b=FhzQqzMjQAOAmFYjW+Ztwd9mTWhKhP8CIFTM6f64Cn6hKz597/11h9nhrEU+oGYDB1 5Z+tgarZOr36icOec0ij5Xmv6FNoxvGAehn94knO9sod1hwQESs5uJXeJ/3E8vQ9NC9S da89f00N68AUeuJUSLMNzhWce1XO8hpEj0nJlOXVLo5/3yLhALDGDzfub8i4MjlU/q2j C7Kc2KEn0nmS4AOvV/MbgTHn3yfarXEH7Fq5hjdvgtymP047aD2lxfQOPNquTjk/LJAF JHTtmIN4zaYSyxLIibLWWk+VVNe459fzODDeg8e5qCg44pIcHV4JoLFK8uUtN1EogGP4 cEnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113607; x=1730718407; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qyOUNRXsLlQkNpP9ouZlfMLDHIlRndz2Tp+MnGE5vek=; b=tf+ORDBO0OmnDxIDU9f4jcm19mH+YTCL9F8XHFrbQVtWPztqP+QQGQux7Xckc958bh PbS/V6j3acy8tjK/ZK9ptgWHvPnRroOeFsqLguk7m7vJBnnNNQf6kfszReix9WK5VOQU znjmC1TFAbrBsaOYRkKAOEGfXxK7t5RwViidZsA3irdJTF4OjBq3Wq8HARtHg7iiJq5z CfTJu/cNemwJnJedP1VPcjSkQNdkY3OW59qMIoyqaiPbSrbj7jb+dMFTEd5VaFBWmVjb NQodeXp0JTtc/OYhcgs+GNls68fBqThw8Blik5yPSb/3adeqewkeYnRWZ+aZG98UlczF IqZA== X-Forwarded-Encrypted: i=1; AJvYcCUi/p/Yx4cN5aOQ+f8xXz3GXKStyvK9ZPoMZsHBElvmDtcbaG4r640Mu0f+gj9NxZcppjCRVkc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+/g2K9Jusy9tWm34fOKsLfBZarBbQUiBuwIe9HTYHmdsrYgCL f1qxukt0wdKK8odz2AVYDdSKET+N3VC8sAO9V6Xi+cj1xmz5ZicK X-Google-Smtp-Source: AGHT+IGS1bzg/gwvpIdRydLEL7OGdevQ3AmJX3ezBAQa0c7ed8W99f0SVn6zCMpst662e6jTTxfIAg== X-Received: by 2002:a17:903:1c6:b0:20e:5777:1b8d with SMTP id d9443c01a7336-210c6ccf10dmr108030805ad.57.1730113606759; Mon, 28 Oct 2024 04:06:46 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:46 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 07/14] net-timestamp: add a new triggered point to set sk_tsflags_bpf in UDP layer Date: Mon, 28 Oct 2024 19:05:28 +0800 Message-Id: <20241028110535.82999-8-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing This patch behaves like how cmsg feature works, that is to say, check and set on each call of udp_sendmsg before passing sk_tsflags_bpf to cork tsflags. Signed-off-by: Jason Xing --- include/net/sock.h | 1 + include/uapi/linux/bpf.h | 3 +++ net/core/skbuff.c | 2 +- net/ipv4/udp.c | 1 + tools/include/uapi/linux/bpf.h | 3 +++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/net/sock.h b/include/net/sock.h index 062f405c744e..cf7fea456455 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2828,6 +2828,7 @@ static inline bool sk_listener_or_tw(const struct sock *sk) } void sock_enable_timestamp(struct sock *sk, enum sock_flags flag); +void timestamp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args); int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, int level, int type); diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 6fc3bd12b650..055ffa7c965c 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -7028,6 +7028,9 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_UDP_SND_CB, /* Called when every udp_sendmsg + * syscall is triggered + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 8b2a79c0fe1c..0b571306f7ea 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5622,7 +5622,7 @@ static void skb_tstamp_tx_output(struct sk_buff *orig_skb, __skb_complete_tx_timestamp(skb, sk, tstype, opt_stats); } -static void timestamp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) +void timestamp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) { struct bpf_sock_ops_kern sock_ops; diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 9a20af41e272..e768421abc37 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1264,6 +1264,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (!corkreq) { struct inet_cork cork; + timestamp_call_bpf(sk, BPF_SOCK_OPS_TS_UDP_SND_CB, 0, NULL); skb = ip_make_skb(sk, fl4, getfrag, msg, ulen, sizeof(struct udphdr), &ipc, &rt, &cork, msg->msg_flags); diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 6fc3bd12b650..055ffa7c965c 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -7028,6 +7028,9 @@ enum { * feature is on. It indicates the * recorded timestamp. */ + BPF_SOCK_OPS_TS_UDP_SND_CB, /* Called when every udp_sendmsg + * syscall is triggered + */ }; /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect From patchwork Mon Oct 28 11:05:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853297 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 112401DF98B; Mon, 28 Oct 2024 11:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113615; cv=none; b=otBwYbomv6JXXkU+8EiWmd8nkS7zkywqWdgjJ0/AhIs2Zbysr1r6y3fju0DCjJxtmPldt/JSbRvZJCn8wWcN9zrOLbzj+2u/JjJtyLyNlcZHP13ggzHzwqla8x2GhtgsCknvmcdEDCt3gwHt4kSHliS+8ovCSxVFSGTu5gadw7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113615; c=relaxed/simple; bh=n59BzMmHj6QmEvAChM4e1p/F3ui3YNRam2jhSBSZ950=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BIEqrcEwm8+BXzgwZsE1N6isR3ug8lRCrDLpOGwdxTvp3lcyQ7EkjPE4M36F0cRaNmCpMiFjK1W4bVwKqu9Hxcmu41rixJiZTohGTWXRD/7CBgpnvu6GfvtJCJX8EIeVRZWUBxmylFq7OIFMf3pg/+ngNU3UCXmjKQQN+MMauNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rwxkoph8; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rwxkoph8" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20c6f492d2dso45409825ad.0; Mon, 28 Oct 2024 04:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113612; x=1730718412; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FeswT7sbfdIj+jdoLx1KrvMNiLwQSxPjrFinnXgTtJw=; b=Rwxkoph86Ygw5UhminZPJ31N2oikEO6GSeswkKZVrd7b6Ah7P49Ei7MwbcGXP/3uCe 3S+WpWLMwrz4X7J846MkueCnWZmJapaK+b0dXaLWh/Kq6/T9I6i1k8X+B783h/OS7Qkq LHb8uDhEyaZtoVatJpeYYze3zz1cn5W2ZpNreNtuYYnbc2sE7QMOwoRJ4q1AsDafwa9K g5CPEAl0DBl3/LIW0ZE8KYJvr2veBeRkKM+7Dn855n7spYNR0t63oH4qYWaqb5CweIYc S9rtb5Ambq6ecqt/V2BtT6QIrgT+zuLiDhtcR5JRGzWwSNT+7ukjB7IxRgmpmv4nFHKN y0XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113612; x=1730718412; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FeswT7sbfdIj+jdoLx1KrvMNiLwQSxPjrFinnXgTtJw=; b=lYkAcr+GVO7Nr5OWPf39Z/EXl0wyOJNNmpkqsRyfAmkJ+Q+WxpFEe5nCbHTiCpUMfG 1Uo5KHffsi/yKJ11hSl/cQCBlqD6g9Gr7xGyP20maJzlvUDVZqU7e/q+FBx0GNxfperF Plht7Q5tQWuc4Of3fm7EEuwM2Nv1dusv9O7G86eQNpP0F9Z7Ldp3PgHCuJorp1ED8wqH UmQmek2ksm6RvArFyaex0tMJVE4fVGcG1pp+RQj8hk8aqs+v6rdChbod90zYQSSxQkNB tzqOqw3NhAZmrc44wbai+QkpRMsgkonIbFk/fpr8BNbmB75ACTbaYdPJ4/YbGoWBToxf 8psA== X-Forwarded-Encrypted: i=1; AJvYcCW54t+arW0WIccSTcoZUK3UPw9WWjvFGOUSzQXy2FU0b0agVGhuJHqZJFDoTVVhGlcE/B+nvHQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzz4kaRTUqFG22pyKjbMw6qX98KPTm1rCX2N5QS/0xuziSgG0B9 2NaW937pVglLXvmBjwkiaIemZ5kfty3z9e49I4JLcDrcyk+RXQVB X-Google-Smtp-Source: AGHT+IF6d/W4Yo2LrkrguO1XU3nDvMacgFTgK8CP9HvoWsXbWN+cimFoOuYgDT/rUCCpozdXxpbsZg== X-Received: by 2002:a17:903:2283:b0:20c:8331:cb6e with SMTP id d9443c01a7336-210c68c951cmr122758555ad.19.1730113612271; Mon, 28 Oct 2024 04:06:52 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:51 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 08/14] net-timestamp: make bpf for tx timestamp work Date: Mon, 28 Oct 2024 19:05:29 +0800 Message-Id: <20241028110535.82999-9-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Until now, we've already prepared the generation related work, so it's time to let it work finally for both TCP and UDP protos. This is how I use in bpf program: 1) for UDP case BPF_SOCK_OPS_TS_UDP_SND_CB: bpf_setsockopt(...); 2) for TCP case BPF_SOCK_OPS_TCP_CONNECT_CB: bpf_setsockopt(...) 3) common part used to report the timestamp case BPF_SOCK_OPS_TS_SCHED_OPT_CB: dport = bpf_ntohl(skops->remote_port); sport = skops->local_port; bpf_printk(...); Signed-off-by: Jason Xing --- include/net/sock.h | 6 ++++++ net/ipv4/ip_output.c | 1 + net/ipv4/tcp.c | 16 ++++++++++++++++ net/ipv6/ip6_output.c | 1 + 4 files changed, 24 insertions(+) diff --git a/include/net/sock.h b/include/net/sock.h index cf7fea456455..cf687efbea9f 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2710,6 +2710,12 @@ static inline void sock_tx_timestamp(struct sock *sk, _sock_tx_timestamp(sk, sockc, tx_flags, NULL); } +static inline void sock_tx_timestamp_bpf(u32 tsflags, __u8 *tx_flags) +{ + if (tsflags) + __sock_tx_timestamp(tsflags, tx_flags); +} + static inline void skb_setup_tx_timestamp(struct sk_buff *skb, const struct sockcm_cookie *sockc) { diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 0065b1996c94..9d94a209057b 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1332,6 +1332,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->transmit_time = ipc->sockc.transmit_time; cork->tx_flags = 0; sock_tx_timestamp(sk, &ipc->sockc, &cork->tx_flags); + sock_tx_timestamp_bpf(READ_ONCE(sk->sk_tsflags_bpf), &cork->tx_flags); if (ipc->sockc.tsflags & SOCKCM_FLAG_TS_OPT_ID) { cork->flags |= IPCORK_TS_OPT_ID; cork->ts_opt_id = ipc->sockc.ts_opt_id; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 82cc4a5633ce..6b23b4aa3c91 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -477,6 +477,20 @@ void tcp_init_sock(struct sock *sk) } EXPORT_SYMBOL(tcp_init_sock); +static void tcp_tx_timestamp_bpf(struct sock *sk, struct sk_buff *skb) +{ + u32 tsflags = READ_ONCE(sk->sk_tsflags_bpf); + + if (tsflags && skb) { + struct skb_shared_info *shinfo = skb_shinfo(skb); + struct tcp_skb_cb *tcb = TCP_SKB_CB(skb); + + sock_tx_timestamp_bpf(tsflags, &shinfo->tx_flags); + if (tsflags & SOF_TIMESTAMPING_TX_ACK) + tcb->txstamp_ack = 1; + } +} + static void tcp_tx_timestamp(struct sock *sk, struct sockcm_cookie *sockc) { struct sk_buff *skb = tcp_write_queue_tail(sk); @@ -492,6 +506,8 @@ static void tcp_tx_timestamp(struct sock *sk, struct sockcm_cookie *sockc) if (tsflags & SOF_TIMESTAMPING_TX_RECORD_MASK) shinfo->tskey = TCP_SKB_CB(skb)->seq + skb->len - 1; } + + tcp_tx_timestamp_bpf(sk, skb); } static bool tcp_stream_is_readable(struct sock *sk, int target) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index f7b4608bb316..230e8d5a792c 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1402,6 +1402,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, cork->base.tx_flags = 0; cork->base.mark = ipc6->sockc.mark; sock_tx_timestamp(sk, &ipc6->sockc, &cork->base.tx_flags); + sock_tx_timestamp_bpf(READ_ONCE(sk->sk_tsflags_bpf), &cork->base.tx_flags); if (ipc6->sockc.tsflags & SOCKCM_FLAG_TS_OPT_ID) { cork->base.flags |= IPCORK_TS_OPT_ID; cork->base.ts_opt_id = ipc6->sockc.ts_opt_id; From patchwork Mon Oct 28 11:05:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853298 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F18F1DFD84; Mon, 28 Oct 2024 11:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113620; cv=none; b=ZFeprlvQtAnqiPcdwY1Ux9Kb4x+q01mxuyo97dT6tphytc/RGXo5gZ9QRxqpyUSO7Hk49yrVXlZDGWQ4Kyxs1hb+R80d7clQvy9xLV30E3iVeoZpuDi8mG8b3j4udIt4zedutLT4d+jVurp/yFoArDxkVfWqZio7AGbZA+hUU9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113620; c=relaxed/simple; bh=aD8o6D6tpOQIg0naivN5cjlg8DZcm+4tt6wdIAfz4G0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UJaJ+EKhrm2tql+YgELpcLIff3IxwzvC8KmIgXHZXC6FfTY2RPIJm00BHSGmGzpFrTbkQQbPh8aftRznHzdYS6Ii3UwtN3qIa+O/cJwQzcEzesEvI2Dlm1ZGnV0ENvIDGYgNPTtGuQcTUOBgztSCJGcnoinnSS2TmlTJmlFZ1Tk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aitjkq6u; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aitjkq6u" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20c805a0753so39199945ad.0; Mon, 28 Oct 2024 04:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113618; x=1730718418; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ukuau26fm7NhiMm7nIX1EbwJfdgYGVl0CZ73swdUhhE=; b=aitjkq6uHxXgVck+fte4z9fnmTRth8+/64DrXwQuOdWvbhjYXYK/hD3howY55nk8gT 4ntqaFbDfVNnVMA3A3TU/aMbECEMSq3uYEZMUzm5WmwNcMkH4Aq4b69FcAHoT/YTVFEm wDO0IP0sxTwUnJpXvWrUx4ZPnKi9uJM/1Yx7TwaLDb5Qlkc6AJdw6oTOwkReMqByrf3D WxgLMTy0pGfiqSWjskfMjwqs5SZ35gfbTcTnfKlor9zlHpLryrGsVq0tQ1QFW4vtekTb QL27+5XJ/mH5IKkfi/C80pX4Vt0DSAox1N9zvDrRQ7Es5AvIwH9w2T/87QPBAgKmg++n uyNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113618; x=1730718418; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ukuau26fm7NhiMm7nIX1EbwJfdgYGVl0CZ73swdUhhE=; b=jcVZoBLvczP2MBDKlKLNWfyMy7GjRfpu784iNc/X9/dlo4wyFIdlsZPXnxNira8CZo CGlhY2DDgD4Vb8vstDv4GurCjMtouOSuFBCH9VTC9/cw4HKF6lXt6psUlCoMu4JyKeLT IE57XWQeSmGcngrKdHr25+b1XhOYk3UB5ndvFcv35ESfC+bNC29OKxZtXLN87hJ/hp/6 IevQObO4EZo0QlihjWXpGQ5T2/l5cNv+WjJuZ6YwUz4uAE6sFYKo3Lm42cp4K2sfbVon uKIPnGsdCWyD5gzsfk/7MQqvakuipGBBtbTI4Zl94o03kOzeHV39cpnATLr7eX0O4Hb/ Pa6w== X-Forwarded-Encrypted: i=1; AJvYcCXcO+xSd2Mb0FOjMQKc98vhM4Jv7I+rvgDqX1oNozESiEJltoBy5RTu4zB66z+rvKRwGy3IbDo=@vger.kernel.org X-Gm-Message-State: AOJu0YyO0iRfJA1ciVf7mO01QfF3QXQE3Kf5FQ6kgwq0E+cftuEs8UKq Vc880B0UFtEem2SMcFy2hD//PtWYAp86tpkY0wz+Y12eCZvR5b6P X-Google-Smtp-Source: AGHT+IHuT40DF3jXyYd7kyC2EEpbUG70WNYus2IT3/sZAMWa5gXHVdLZPt/ZTkEvlPDqBHUhdb8VZg== X-Received: by 2002:a17:902:d50c:b0:20c:9eb3:c1ff with SMTP id d9443c01a7336-210c6cc5afbmr111461965ad.59.1730113617680; Mon, 28 Oct 2024 04:06:57 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:06:57 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 09/14] net-timestamp: add a common helper to set tskey Date: Mon, 28 Oct 2024 19:05:30 +0800 Message-Id: <20241028110535.82999-10-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing No functional changes here. Only add a common helper so that we can use it later for bpf extension easily. Signed-off-by: Jason Xing --- include/net/sock.h | 1 + net/core/sock.c | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index cf687efbea9f..91398b20a4a3 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2917,6 +2917,7 @@ void sock_def_readable(struct sock *sk); int sock_bindtoindex(struct sock *sk, int ifindex, bool lock_sk); void sock_set_timestamp(struct sock *sk, int optname, bool valbool); +int sock_set_tskey(struct sock *sk, int val, int bpf_type); int sock_set_timestamping(struct sock *sk, int optname, struct so_timestamping timestamping); diff --git a/net/core/sock.c b/net/core/sock.c index 7e05748b1a06..42c1aba0b3fe 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -891,21 +891,16 @@ static int sock_timestamping_bind_phc(struct sock *sk, int phc_index) return 0; } -int sock_set_timestamping(struct sock *sk, int optname, - struct so_timestamping timestamping) +int sock_set_tskey(struct sock *sk, int val, int bpf_type) { - int val = timestamping.flags; - int ret; - - if (val & ~SOF_TIMESTAMPING_MASK) - return -EINVAL; + u32 tsflags = bpf_type ? sk->sk_tsflags_bpf : sk->sk_tsflags; if (val & SOF_TIMESTAMPING_OPT_ID_TCP && !(val & SOF_TIMESTAMPING_OPT_ID)) return -EINVAL; if (val & SOF_TIMESTAMPING_OPT_ID && - !(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)) { + !(tsflags & SOF_TIMESTAMPING_OPT_ID)) { if (sk_is_tcp(sk)) { if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) @@ -919,6 +914,22 @@ int sock_set_timestamping(struct sock *sk, int optname, } } + return 0; +} + +int sock_set_timestamping(struct sock *sk, int optname, + struct so_timestamping timestamping) +{ + int val = timestamping.flags; + int ret; + + if (val & ~SOF_TIMESTAMPING_MASK) + return -EINVAL; + + ret = sock_set_tskey(sk, val, 0); + if (ret) + return ret; + if (val & SOF_TIMESTAMPING_OPT_STATS && !(val & SOF_TIMESTAMPING_OPT_TSONLY)) return -EINVAL; From patchwork Mon Oct 28 11:05:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853299 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D6EA1DFE01; Mon, 28 Oct 2024 11:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113626; cv=none; b=Jy7ju3ncUUstJBN28pOseAiO7owJxGUz9F82/O6ZdkwfNjEobTg9/PEgJp194wHeoHprw8dM4OSGpesjj4a+fLyrWSiMv62/qIJ3DgKFz19gRDRY6Byj6+iKzKzGGJLveo407gVDs9je3Sz+iF4FXaV7VeVsQryM1q8UC1DOFQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113626; c=relaxed/simple; bh=XBmnYsSBTTPrzwxBBYJMcNlST4Xeejiqpv4MDPTBvk0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T9eLHFl4tZnRzaBtbj1V9uM99MnxOYbO7Wn8qcEv1af28FfXlihj0/TZh68zsmgV+gaRpP6JmIxBXyj+vpB9UTzDHh6AIakE/pYaY9N15z3x2asoaGCIf+AmU0gE2Cj/tD50HzEhlenETReivPFV93yPzutf/8+KvDe7ifAP5vE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f+AHA0EC; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f+AHA0EC" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20ca388d242so35729195ad.2; Mon, 28 Oct 2024 04:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113623; x=1730718423; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NC5GVXGcuS1Kp7TK5CceZH6IPo60SK9yqzbyaAVCeVs=; b=f+AHA0ECXEilttliZCNzRAXUNhxQUFH16owIb5C1aUPzjcsyZoXty8qFSsZ+6PEk7d C8GiO5yeYTJS3mTQ8X/9qzN5FBJAblrug4D6Qpe0jpOXt7g34qv+VDJgRw31wQvBONvw AHo4OIpL7Pra+zjXPpLsog1pRuhqChW3rWXX6IHIZ0A8DNlSCqoerId8oG8unsTmO/gD viWZ+amxuHjQ/1cn5SYV07JLtvCLdIxs1YcZhmdeJcCrfAAHpjanzgRm4TjGdtpATsTG y2fw6B4FcmcLsZq5uN+Tm88U0PBIrlb4VuyylKl3YxSRWtyh5qDb49dJiriwYx2pxCr7 Moxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113623; x=1730718423; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NC5GVXGcuS1Kp7TK5CceZH6IPo60SK9yqzbyaAVCeVs=; b=NtHBrAW8JMlR1aOwyTPDHWNGDhMX5V0Y3xLsnuHCrnDmTG8D4W+NEKtFYovQN5fuIR CieTUnaLfMdHcu9tvtA08RtsiG5Z62UfIQlNOuoETJi4CtIW2P7wsucNRHF9VCC155nR 95EInozB56phN/zyCj/CpuHMmtzBlEaF0N/I5lB4Y+7mhC657kR4Afeo2DduX4/0RKBh APwCzKSqW6oepadM3n/ji/Jr3MhCm5bS2Y74iukdS3/Pwa0w045EKwvVl0gEL2zNMDkZ hhsQsvCq9OvxowSfJMpTdCqh0t53hyKWrbcVXXLh1VzAMsgZzBCcQCCSnsGCN8rlXZmp 2Ldg== X-Forwarded-Encrypted: i=1; AJvYcCWeUVRbjElAqGxk8Bvv+J5Zs2HHhHzaeZMCdXaJU2CKOaHMsBLE2fnozAb0ckAjrj6baJm2/3k=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2wBiDuI5oNSu/OEvvdd23CUuAPYQSGvgUiwiRAo2ije+4OYsu aqsuJ2d1rzh2DWRg2Bk1dX8y+rfUnJVNbgoFrqMZ+5DO/C0VRqFF X-Google-Smtp-Source: AGHT+IHq1X9Osaq2l+2tjGe7AdiNaCtB4n4/lzINaZx0TA89RREj1vdGgXgen8nPjGcJeYeewvFSAw== X-Received: by 2002:a17:902:d4c9:b0:20b:7e1e:7337 with SMTP id d9443c01a7336-210c689ab32mr122394515ad.13.1730113623150; Mon, 28 Oct 2024 04:07:03 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:07:02 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 10/14] net-timestamp: add basic support with tskey offset Date: Mon, 28 Oct 2024 19:05:31 +0800 Message-Id: <20241028110535.82999-11-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Use the offset to record the delta value between current socket key and bpf socket key. 1. If there is only bpf feature running, the socket key is bpf socket key and the offset is zero; 2. If there is only traditional feature running, and then bpf feature is turned on, the socket key is still used by the former while the offset is the delta between them; 3. if there is only bpf feature running, and then application uses it, the socket key would be re-init for application and the offset is the delta. Signed-off-by: Jason Xing --- include/net/sock.h | 1 + net/core/skbuff.c | 15 ++++++++--- net/core/sock.c | 66 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 91398b20a4a3..41c6c6f78e55 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -469,6 +469,7 @@ struct sock { unsigned long sk_pacing_rate; /* bytes per second */ atomic_t sk_zckey; atomic_t sk_tskey; + u32 sk_tskey_bpf_offset; __cacheline_group_end(sock_write_tx); __cacheline_group_begin(sock_read_tx); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 0b571306f7ea..d1739317b97d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5641,9 +5641,10 @@ void timestamp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) } static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype, + struct sk_buff *skb, struct skb_shared_hwtstamps *hwtstamps) { - u32 args[2] = {0, 0}; + u32 args[3] = {0, 0, 0}; u32 tsflags, cb_flag; tsflags = READ_ONCE(sk->sk_tsflags_bpf); @@ -5672,7 +5673,15 @@ static void skb_tstamp_tx_output_bpf(struct sock *sk, int tstype, args[1] = ts.tv_nsec; } - timestamp_call_bpf(sk, cb_flag, 2, args); + if (tsflags & SOF_TIMESTAMPING_OPT_ID) { + args[2] = skb_shinfo(skb)->tskey; + if (sk_is_tcp(sk)) + args[2] -= atomic_read(&sk->sk_tskey); + if (sk->sk_tskey_bpf_offset) + args[2] += sk->sk_tskey_bpf_offset; + } + + timestamp_call_bpf(sk, cb_flag, 3, args); } void __skb_tstamp_tx(struct sk_buff *orig_skb, @@ -5683,7 +5692,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, if (!sk) return; - skb_tstamp_tx_output_bpf(sk, tstype, hwtstamps); + skb_tstamp_tx_output_bpf(sk, tstype, orig_skb, hwtstamps); skb_tstamp_tx_output(orig_skb, ack_skb, hwtstamps, sk, tstype); } EXPORT_SYMBOL_GPL(__skb_tstamp_tx); diff --git a/net/core/sock.c b/net/core/sock.c index 42c1aba0b3fe..914ec8046f86 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -891,6 +891,49 @@ static int sock_timestamping_bind_phc(struct sock *sk, int phc_index) return 0; } +/* Used to track the tskey for bpf extension + * + * @sk_tskey: bpf extension can use it only when no application uses. + * Application can use it directly regardless of bpf extension. + * + * There are three strategies: + * 1) If we've already set through setsockopt() and here we're going to set + * OPT_ID for bpf use, we will not re-initialize the @sk_tskey and will + * keep the record of delta between the current "key" and previous key. + * 2) If we've already set through bpf_setsockopt() and here we're going to + * set for application use, we will record the delta first and then + * override/initialize the @sk_tskey. + * 3) other cases, which means only either of them takes effect, so initialize + * everything simplely. + */ +static long int sock_calculate_tskey_offset(struct sock *sk, int val, int bpf_type) +{ + u32 tskey; + + if (sk_is_tcp(sk)) { + if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) + return -EINVAL; + + if (val & SOF_TIMESTAMPING_OPT_ID_TCP) + tskey = tcp_sk(sk)->write_seq; + else + tskey = tcp_sk(sk)->snd_una; + } else { + tskey = 0; + } + + if (bpf_type && (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)) { + sk->sk_tskey_bpf_offset = tskey - atomic_read(&sk->sk_tskey); + return 0; + } else if (!bpf_type && (sk->sk_tsflags_bpf & SOF_TIMESTAMPING_OPT_ID)) { + sk->sk_tskey_bpf_offset = atomic_read(&sk->sk_tskey) - tskey; + } else { + sk->sk_tskey_bpf_offset = 0; + } + + return tskey; +} + int sock_set_tskey(struct sock *sk, int val, int bpf_type) { u32 tsflags = bpf_type ? sk->sk_tsflags_bpf : sk->sk_tsflags; @@ -901,17 +944,13 @@ int sock_set_tskey(struct sock *sk, int val, int bpf_type) if (val & SOF_TIMESTAMPING_OPT_ID && !(tsflags & SOF_TIMESTAMPING_OPT_ID)) { - if (sk_is_tcp(sk)) { - if ((1 << sk->sk_state) & - (TCPF_CLOSE | TCPF_LISTEN)) - return -EINVAL; - if (val & SOF_TIMESTAMPING_OPT_ID_TCP) - atomic_set(&sk->sk_tskey, tcp_sk(sk)->write_seq); - else - atomic_set(&sk->sk_tskey, tcp_sk(sk)->snd_una); - } else { - atomic_set(&sk->sk_tskey, 0); - } + long int ret; + + ret = sock_calculate_tskey_offset(sk, val, bpf_type); + if (ret <= 0) + return ret; + + atomic_set(&sk->sk_tskey, ret); } return 0; @@ -956,10 +995,15 @@ static int sock_set_timestamping_bpf(struct sock *sk, struct so_timestamping timestamping) { u32 flags = timestamping.flags; + int ret; if (flags & ~SOF_TIMESTAMPING_BPF_SUPPPORTED_MASK) return -EINVAL; + ret = sock_set_tskey(sk, flags, 1); + if (ret) + return ret; + WRITE_ONCE(sk->sk_tsflags_bpf, flags); return 0; From patchwork Mon Oct 28 11:05:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853300 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65FEB1DFE1A; Mon, 28 Oct 2024 11:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113631; cv=none; b=KUrF+79BeujOM/FxxBucoqAbNpf4bJwJmpL75SlCHeAHQYL3Zu/8vhP8+FEuJaINAy8w/l5Sn43h5CwVyXzZs7wbqk+32ejbfKjmfX2aFpc1w6nwmZh6S0BJUW4ORBWx6HO0an30hN9P3Wp9m7Io6fNqyua7VAcrK/mpOuue0tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113631; c=relaxed/simple; bh=naY7CtjoB9IrV3TEwv/nvbhSAmGOWFPsJ+ZuPtYqdQw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bU09kE0EBbaLrqj7aFrBnlvxkyhGe0P79xO3GwOzgMFX7pU0PpedC/tmGr1XKKqwyqFBEH3j3RWKW4deP+H+4M5hPFmDfWzyaRigQCzXAIXPqyQ2fBR/0f9URkVuXs93sAoEsALaUmNP3xX+pbqJiIVhR8tzlPvayfzlFCSwSro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ijrkOPfr; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ijrkOPfr" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20c77459558so33377955ad.0; Mon, 28 Oct 2024 04:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113629; x=1730718429; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Gr+4i8cCzp+FuMOnay9glCuPHx7TEpMQfkeXjRl7GDE=; b=ijrkOPfr2pxVJ8Cgzd+I+LGqETlKyuECJR4cQe3OriLHws5e50U+YAT3cWQ/999G+u B39AYDToe8ZF+0UN4s2mixiQJOnKe2syUBo/5dH/6MtnlhhwXWoI9tuhcnFeNa+CK/fA qdxT/txd6XFV02Lji+hRHJqHrvwPvRuFQbEJfR0esvwWmUOEKYMoSYP6qRLNj8rAgBfU 075mOt6AE6nS3lU/yv22lSr1YOrLFJPCnLTA4HsRm99dcDm4MhFPqRngI77XfH3u3RI9 e/1GUVYcBGE4BQTutALXGn0yMuqaGJSM+LlOj6zDLBUMrC7mPrab7s6ChPFCpOtCYzgv 1+fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113629; x=1730718429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gr+4i8cCzp+FuMOnay9glCuPHx7TEpMQfkeXjRl7GDE=; b=BuqvWsiG5SF21wYaCs1tj1rCD3JF640WOCxYaMrGF+VgVR3mezISH7LCaGqaUMThjP +jTACEy8X/6xsdHDjCSfvnENM1RJ/goE+Lt4cv5WH55cCAhCYhIfNzd4ASCwDwjaZv/6 vnFwcm0Buvdj3nSGZivsmsw8l+vCx9IlUoDcLSjZ95qsKiW+ItdnumqWCUVtlMp4Qyoe 2EPUAMnjXxGPxkaOdlVkj6GUlu80lQ4g+RbMOFFopGJhLtyd+VybhFzOhuhiXCu2ZlZ3 vIIUAAwn/wIputSlEUYgZ75mvwLWKmcQ6P+3WkmVxaFfHEY7STHnY+3akov7QE80VMP9 TcYw== X-Forwarded-Encrypted: i=1; AJvYcCV9smphzBuLPHyc4yutsBbjbHi1H8oLokB1k8GLCVh21SzGEJ7rLbER5NzTiZ53PXoMsIZkEd0=@vger.kernel.org X-Gm-Message-State: AOJu0YyQlMI62G3DvsAKxj0S+B2VhT1UzqYkYiM5NvMHZ4MxxVQNHwnd yOVc+veVDXi+eygo1X5kdYo0uOgAZxPgfBACgTuo+Ki7uCVvJHCf X-Google-Smtp-Source: AGHT+IEKqIt3nLqhQYbdKR3ljfkcQ++BF5w592JEqClSOBZZwOvZpPnDgOmOCPGp+4Rd1PgQDZQYvg== X-Received: by 2002:a17:902:e54f:b0:20b:7731:e3df with SMTP id d9443c01a7336-210c6c6a143mr129792015ad.43.1730113628700; Mon, 28 Oct 2024 04:07:08 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:07:08 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 11/14] net-timestamp: support OPT_ID for TCP proto Date: Mon, 28 Oct 2024 19:05:32 +0800 Message-Id: <20241028110535.82999-12-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Let it work for TCP proto. Signed-off-by: Jason Xing --- net/ipv4/tcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 6b23b4aa3c91..f77dc7a4a98e 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -488,6 +488,8 @@ static void tcp_tx_timestamp_bpf(struct sock *sk, struct sk_buff *skb) sock_tx_timestamp_bpf(tsflags, &shinfo->tx_flags); if (tsflags & SOF_TIMESTAMPING_TX_ACK) tcb->txstamp_ack = 1; + if (tsflags & SOF_TIMESTAMPING_TX_RECORD_MASK) + shinfo->tskey = TCP_SKB_CB(skb)->seq + skb->len - 1; } } From patchwork Mon Oct 28 11:05:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853301 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF8661DFE2C; Mon, 28 Oct 2024 11:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113636; cv=none; b=Y4Qp7BSMBbHVxcEOonVdGELHDDvZSyMqmT0VP5E3L1/HG75DIfwr67zD7JdmFIRy8IIYBvCMnTMYI6Dup+53qMoA7y2wGIvqFdYlUyTQlMB29NcO2CgLjed0/klMF9TF04STwwjNxPU90XfX8k4KE3/w7EA0+NBjSjK/QXf4Fis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113636; c=relaxed/simple; bh=QC4G63ZJPFcAP98wAsnrPRmB23FMfRqCIbeY5agxrv8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D1u3u9sy25v42sucotlUFUVI7CYQtZaMmnzd+NA/+bc9Wpmp55v6KYkBpj82yZ4xXUoYPSxuDNxQ0rAXsZ+SVwbxZQ6KXchXX7zVrTF6rePYbbKjmAxE5Cog/HcCYDuaYIn4FiPBRaSNDEAyPpmPJFXmLH2Wq4UtAVwfob9ZAU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y+cxGWcR; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y+cxGWcR" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20c7ee8fe6bso34189815ad.2; Mon, 28 Oct 2024 04:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113634; x=1730718434; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jXbOExaDu/uQUw8FjeUjOu713YfQRhW5kS8sH0/9U3A=; b=Y+cxGWcR3K12hp2Zq5BRsYOp8urEdJTJmqYBDMsYLnVQx0SFH2iV7hsYZFgtDsH0mA 3KoZ0IxFaTkoYw55o2F/mhmMCKsvGcFiZ5rxlHBcSP7ubBJLXuGdej9IXQdZZJOuJo5l dq0wXdtc+HW8jv+KZ+q0htttx7MqN7A3Xhh34wv/MK/fh/Kwdpo99M6CHij1MEEboVQg lSjUe1mRgAazcfiGjEGyORY7aN0SAQwO1BYnmb4X7a9KIJeWTnV2+EbLY8/qXrCtqbrs OUKGQOHzaZLg5cXmdDwhvXvSMFCKpEvfIi59sFY/UK4jxD7SPSarSJRQTWwcqVmK/mzi kgXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113634; x=1730718434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jXbOExaDu/uQUw8FjeUjOu713YfQRhW5kS8sH0/9U3A=; b=UoDdUy5CxqEyLnbjrDrdksdAZn/sW3D4swzlJghKHm3Ca5PTctoMAxZzz9A9oi5n+X CTUhOJ41uWGFZWEgHfrFHoiCHhzvm4F9VnFpBsKTPcCVrBpUGf5svTu33MFGNrij3zEP LQTLA2iVc2TyKUQobwn3zVLe2aDaD8cZ2mdSNjUaF7JczNLVju2rQzlhxdh1Qa8MJtAk VrkWil/QkDiuQeYtrnGRHormQbYtyNhy5+kwkd8jy3Oje177DEP3opGnkSDOz2WcEOd+ vbac8OYeA/wMWMWBF6Dkxc5HhkwsrjbB9pze0wwFkeRG6I2um4M6NcLAeZDIxf8TOpwA fyWA== X-Forwarded-Encrypted: i=1; AJvYcCX2LYBFhGEm/ReqOlIK0uGvssLrivS4e+YCIUNx2wIJH68K4jBW8W4khTHs4Fji595fh/ivlC0=@vger.kernel.org X-Gm-Message-State: AOJu0YzklLOw0xm74kUCOh6xdnBa4CpFfGGNmDVTIRlVKOwjY09Ppzuu Kgwd3LBTQeRw9ajf22epZprnqv0J2FI6XMibj1/+efa3F2IrTr05 X-Google-Smtp-Source: AGHT+IEzjIQnm8EWERYCUyT2PumNk8MQlsb8zqcZOIOZiJBGPDqo0VE/PsAuBpYThzrSsiI1ldwtvQ== X-Received: by 2002:a17:902:c945:b0:20c:cd23:449d with SMTP id d9443c01a7336-210c6c43228mr98899525ad.46.1730113633959; Mon, 28 Oct 2024 04:07:13 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:07:13 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 12/14] net-timestamp: add OPT_ID for UDP proto Date: Mon, 28 Oct 2024 19:05:33 +0800 Message-Id: <20241028110535.82999-13-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Let it work for UDP proto. Signed-off-by: Jason Xing --- net/ipv4/ip_output.c | 16 +++++++++++----- net/ipv6/ip6_output.c | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 9d94a209057b..45033105b34c 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1049,11 +1049,17 @@ static int __ip_append_data(struct sock *sk, cork->length += length; - if (cork->tx_flags & SKBTX_ANY_TSTAMP && - READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_OPT_ID) { - if (cork->flags & IPCORK_TS_OPT_ID) { - tskey = cork->ts_opt_id; - } else { + if (cork->tx_flags & SKBTX_ANY_TSTAMP) { + if (READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_OPT_ID) { + if (cork->flags & IPCORK_TS_OPT_ID) { + tskey = cork->ts_opt_id; + } else { + tskey = atomic_inc_return(&sk->sk_tskey) - 1; + hold_tskey = true; + } + } + if (!hold_tskey && + READ_ONCE(sk->sk_tsflags_bpf) & SOF_TIMESTAMPING_OPT_ID) { tskey = atomic_inc_return(&sk->sk_tskey) - 1; hold_tskey = true; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 230e8d5a792c..ec956ada7179 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1547,11 +1547,17 @@ static int __ip6_append_data(struct sock *sk, flags &= ~MSG_SPLICE_PAGES; } - if (cork->tx_flags & SKBTX_ANY_TSTAMP && - READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_OPT_ID) { - if (cork->flags & IPCORK_TS_OPT_ID) { - tskey = cork->ts_opt_id; - } else { + if (cork->tx_flags & SKBTX_ANY_TSTAMP) { + if (READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_OPT_ID) { + if (cork->flags & IPCORK_TS_OPT_ID) { + tskey = cork->ts_opt_id; + } else { + tskey = atomic_inc_return(&sk->sk_tskey) - 1; + hold_tskey = true; + } + } + if (!hold_tskey && + READ_ONCE(sk->sk_tsflags_bpf) & SOF_TIMESTAMPING_OPT_ID) { tskey = atomic_inc_return(&sk->sk_tskey) - 1; hold_tskey = true; } From patchwork Mon Oct 28 11:05:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853302 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D1031DB34C; Mon, 28 Oct 2024 11:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113643; cv=none; b=XzrENGb1MV91mASA4qcj9wg/oLePwJJVzmJY6pR6iVpJvee5VioClX2f51+BB8JYQYgL9hac1+W8EStnvbuw5K5kXqjH+kSWFClH90pT9Obd502ZNQGyUJx/cGcqRU9oDuthxvlMTJF6fu/vejWPJOJllRFUnftlB/zYkkUiRqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113643; c=relaxed/simple; bh=gc7sMEz8w/SdDhyc4WhS0XzsJ2M2y6Jr99bjT9PW+ic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sbO5Sw25ZQk3UjahPtXHNfAfEKP5eBy+zBKdOPXM6ObZbVKfx4MmXTM8kopKAxjtPW4jZepcpojT5knM7R4uQPyYjpgqlIPY4nkluGSJer0FZbafClnM3BQvS4f8L6H+qr9rhfruUcrjRegidZSRWKaOFix5x7ALgtDvO2PHomM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IxLZRzFB; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IxLZRzFB" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20cceb8d8b4so22915025ad.1; Mon, 28 Oct 2024 04:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113639; x=1730718439; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9N78hzla9PU2zrMdQqV/v5ebIzT/i06+c8vQHZBaPa0=; b=IxLZRzFBSffgGJXG+BBarnjeEZWzTjCOZjpnxPY0R3nJPPLYgXgUSeF/ghYfuaJy2N JzgxVudgmoeZszQrbU9kw9GbuJdXMmCNs7mbCKOGZ9NDUWF1fq7/NZigAPgtdMgl8i2H sg7l1NiJWlFaUMS4cE1zYDFAPFGqci9A74M0a34QTJ3omAGKxlExzFaf9DcK+mJv9jl4 GtohWDdujhS0031ILkHVWx5ClQ9wKeHN0v7M4Y/vNhVNamimoSviWNAAP3lNQMWBxwk4 8tZtiA0chNmpeoXb/q59B8DlWCqlGBQSx7gbBEbZAFVDqhz4+eEsoBXN9NucgqAy1PP4 V9Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113639; x=1730718439; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9N78hzla9PU2zrMdQqV/v5ebIzT/i06+c8vQHZBaPa0=; b=NP5m72Iwq/0ux5ksKiA8GTb8qJoJR7YgGuj/kuBbKnr8+UwiMUvx0gbyhGbNlkTKR5 MLFtt7Fri4MP6sTSHvXw+ca6qaRNvi3ZgjOZgc3DYpo/3itLei61ZA0fTu229I0UzcSO SHz2P+S9ONxYp0Bw0HrBDG0XMVsdOmwTRDOyHvfxcvke1A4zB/dCDqJWS1ytdPRooG0p 0uS44+hy23hdkWYuZSqsMXRYzbLaHbREjLdKZ0tGTYREOcz3H0iscHAXrN1EgyxvZ8Dp jJq/6ExFUIXDjf7AjI8M00Q0x9Z7o1vnD1FweWPwkMIAFC9YrAP+EbAQBmIT6VZd1Z2c D25A== X-Forwarded-Encrypted: i=1; AJvYcCUrjZ5a7DNq+x1IjFAwfNqiwj5VzW2ocWpuy0gxwNZaj3N7feQyLVOvm8ZUtVFbeSoa7ko6rOE=@vger.kernel.org X-Gm-Message-State: AOJu0YxTj+MBM6MPv2qiwFocTMM793JJ/qbbOMhoy25tGA9OrPcyed0t f5iXYq1JVdYVqdvIgdGIZhDeQTQ0tniM9AAdi1lXKbiBA8W339pU X-Google-Smtp-Source: AGHT+IEi0jG3733tXMr2ugBFpzIwkxw5XaKqvZSLsUv2FMo5X/asabPguZMw8sVyHWIf0UjjoSfWVA== X-Received: by 2002:a17:902:ec88:b0:20c:6bff:fcb1 with SMTP id d9443c01a7336-210c5937885mr118446405ad.1.1730113639404; Mon, 28 Oct 2024 04:07:19 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:07:19 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 13/14] net-timestamp: use static key to control bpf extension Date: Mon, 28 Oct 2024 19:05:34 +0800 Message-Id: <20241028110535.82999-14-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Using the existing cgroup static key to control every possible call in bpf extension. Signed-off-by: Jason Xing --- net/core/skbuff.c | 3 ++- net/core/sock.c | 4 ++-- net/ipv4/ip_output.c | 5 +++-- net/ipv4/tcp.c | 3 ++- net/ipv4/udp.c | 3 ++- net/ipv6/ip6_output.c | 5 +++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d1739317b97d..2e5af24802ee 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5692,7 +5692,8 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, if (!sk) return; - skb_tstamp_tx_output_bpf(sk, tstype, orig_skb, hwtstamps); + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) + skb_tstamp_tx_output_bpf(sk, tstype, orig_skb, hwtstamps); skb_tstamp_tx_output(orig_skb, ack_skb, hwtstamps, sk, tstype); } EXPORT_SYMBOL_GPL(__skb_tstamp_tx); diff --git a/net/core/sock.c b/net/core/sock.c index 914ec8046f86..3a6f7c9b6459 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1479,7 +1479,7 @@ int sk_setsockopt(struct sock *sk, int level, int optname, } if (!bpf_timetamping) ret = sock_set_timestamping(sk, optname, timestamping); - else + else if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) ret = sock_set_timestamping_bpf(sk, timestamping); break; @@ -1869,7 +1869,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname, v.timestamping.flags = READ_ONCE(sk->sk_tsflags); v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc); } - } else { + } else if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) { v.timestamping.flags = READ_ONCE(sk->sk_tsflags_bpf); } break; diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 45033105b34c..9678a88714e5 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1058,7 +1058,7 @@ static int __ip_append_data(struct sock *sk, hold_tskey = true; } } - if (!hold_tskey && + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) && !hold_tskey && READ_ONCE(sk->sk_tsflags_bpf) & SOF_TIMESTAMPING_OPT_ID) { tskey = atomic_inc_return(&sk->sk_tskey) - 1; hold_tskey = true; @@ -1338,7 +1338,8 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->transmit_time = ipc->sockc.transmit_time; cork->tx_flags = 0; sock_tx_timestamp(sk, &ipc->sockc, &cork->tx_flags); - sock_tx_timestamp_bpf(READ_ONCE(sk->sk_tsflags_bpf), &cork->tx_flags); + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) + sock_tx_timestamp_bpf(READ_ONCE(sk->sk_tsflags_bpf), &cork->tx_flags); if (ipc->sockc.tsflags & SOCKCM_FLAG_TS_OPT_ID) { cork->flags |= IPCORK_TS_OPT_ID; cork->ts_opt_id = ipc->sockc.ts_opt_id; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f77dc7a4a98e..8f42c254bc7e 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -509,7 +509,8 @@ static void tcp_tx_timestamp(struct sock *sk, struct sockcm_cookie *sockc) shinfo->tskey = TCP_SKB_CB(skb)->seq + skb->len - 1; } - tcp_tx_timestamp_bpf(sk, skb); + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) + tcp_tx_timestamp_bpf(sk, skb); } static bool tcp_stream_is_readable(struct sock *sk, int target) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index e768421abc37..27cf2f8a9409 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1264,7 +1264,8 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (!corkreq) { struct inet_cork cork; - timestamp_call_bpf(sk, BPF_SOCK_OPS_TS_UDP_SND_CB, 0, NULL); + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) + timestamp_call_bpf(sk, BPF_SOCK_OPS_TS_UDP_SND_CB, 0, NULL); skb = ip_make_skb(sk, fl4, getfrag, msg, ulen, sizeof(struct udphdr), &ipc, &rt, &cork, msg->msg_flags); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index ec956ada7179..3a96fb09f068 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1402,7 +1402,8 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, cork->base.tx_flags = 0; cork->base.mark = ipc6->sockc.mark; sock_tx_timestamp(sk, &ipc6->sockc, &cork->base.tx_flags); - sock_tx_timestamp_bpf(READ_ONCE(sk->sk_tsflags_bpf), &cork->base.tx_flags); + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) + sock_tx_timestamp_bpf(READ_ONCE(sk->sk_tsflags_bpf), &cork->base.tx_flags); if (ipc6->sockc.tsflags & SOCKCM_FLAG_TS_OPT_ID) { cork->base.flags |= IPCORK_TS_OPT_ID; cork->base.ts_opt_id = ipc6->sockc.ts_opt_id; @@ -1556,7 +1557,7 @@ static int __ip6_append_data(struct sock *sk, hold_tskey = true; } } - if (!hold_tskey && + if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) && !hold_tskey && READ_ONCE(sk->sk_tsflags_bpf) & SOF_TIMESTAMPING_OPT_ID) { tskey = atomic_inc_return(&sk->sk_tskey) - 1; hold_tskey = true; From patchwork Mon Oct 28 11:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13853303 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D3761DFE37; Mon, 28 Oct 2024 11:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113647; cv=none; b=GHsxB894Rto2aAmJJXCDBbcBVnZ3AqitdtTsFtfG1jXrF3qrv2XPUqlUPvP5yzLYUSByx3MuzILutxf/B4QdIsB11mPoVufknShYpeXUGSggXACBZJa+cjFgk36YJv6vgoWLC7+J3LvVhMzEkM6duUO+ItAPOC52UtSlk4tR95k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730113647; c=relaxed/simple; bh=1+7fJFm/WoUOYEe4hnI20HbseEwTxTSjEVJEfPkt8eI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J3mUkF6tRfxqXUr9YWFRqYlLNeO5nXQTca/N6eJikd1IQUyokB9QC6iSSstBeeek+MKHce6jQO8Fe7tbv3HnKY3jqbs3JJOqc6gcc+GR6iPcQp6bHnzkHGbYJAepacZfu6PZv7Rpd1Uf88fL/SAHJc91eak/L+Kk4NcePszX74c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EBaFzwDw; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EBaFzwDw" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-20ca388d242so35732675ad.2; Mon, 28 Oct 2024 04:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730113645; x=1730718445; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g8LljQEp1G0JwNkGMQ7KCHMGGWnguu0SHPLITgEM4cM=; b=EBaFzwDwTaMF14/Z1+edRnyUoDPJKgr6p5dDq24/CwIvAEOdfpaSDVbTiHsob76Y5A MwrevyN0YPr+wjpeyDGr8m8wZzbCQogFVJALwKb3G8QHYoqIb+50wVMLrwsOXm4bzvIh eroznvdRFnkU6Bjx2SAwxahQeG1wQ8GKbGT2tIGhPajVxE2HyUmfbbu4fr+2PoRboudU p3rxOHe7cxBdhZK6C8XosSZa9GYOa4OBydNIywEREgUTLc1hd2+Y/vfQKPm58hD+E6ad 9NMuqwdEUGsgKuV8rIJuMVhu/uTyKYl+YeM8yG488kRdsOSPYFYzREUTZ61KBTcpyhhA PYBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730113645; x=1730718445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g8LljQEp1G0JwNkGMQ7KCHMGGWnguu0SHPLITgEM4cM=; b=etaXFepTa51AV/8S2nsqTT5CkEvGidOc9wO3YAgITYAG5ZidzkNAsB8MW/+PhBO5eq Aq6qIa0RZZ9eQ8ozvoDi4ZEfNGg4AVP761Z2ZtA/Ht5JEED0O/z8H6WlkjEfJuwsKFxF A7aWhVOlCjgkUmRMC1BIlCF2ZIx9kuQ7EqPyAnFtko+jB5MW2dUKYCqjV2wyA6UcHhnk s1qKLDRt+obhLCQgOq13t/DMU/jRW2u+L/cRlP8HIbuXTwyJM6DINWwkFqcMhNUAM5pe Qdg5JqEANA9NqJp4TUohTKtpJ8u9j65Ba5ZaMDE4lFFTvM0r/nZjxkSVo6eWIU+NJpDy 5sLQ== X-Forwarded-Encrypted: i=1; AJvYcCV3fJGXxLhWc6CQNe9nCHOHF3iyXYxy5xZ2IcuIn9yYd7GmdiB9cqHH8kwauvwSt7r06Hgcg98=@vger.kernel.org X-Gm-Message-State: AOJu0YxQunQHk9SMLSUQbHZIQVxokfMQwrC2BwWn6iae+aECZeQvcjNY 7KQM2q5PUs/CAdSfliQiB92Ei+HdeUVVo5ZtHxi3Gpp9DyEuVNAO X-Google-Smtp-Source: AGHT+IE2QnZZq1TnagujvGe5bzFXg1gaxEsnAyYVOZdbTJl659nRCT/T+nSVtKwMnR+t7aLwoPZH6Q== X-Received: by 2002:a17:902:fc4c:b0:20c:aa41:9968 with SMTP id d9443c01a7336-210c6c83057mr101119875ad.53.1730113644888; Mon, 28 Oct 2024 04:07:24 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bc04bdb6sm48130905ad.255.2024.10.28.04.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 04:07:24 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, willemb@google.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, ykolal@fb.com Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v3 14/14] bpf: add simple bpf tests in the tx path for so_timstamping feature Date: Mon, 28 Oct 2024 19:05:35 +0800 Message-Id: <20241028110535.82999-15-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241028110535.82999-1-kerneljasonxing@gmail.com> References: <20241028110535.82999-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Jason Xing Only check if we pass those three key points after we enable the bpf extension for so_timestamping. During each point, we can choose whether to print the current timestamp. Signed-off-by: Jason Xing --- .../bpf/prog_tests/so_timestamping.c | 98 ++++++++++++++ .../selftests/bpf/progs/so_timestamping.c | 123 ++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/so_timestamping.c create mode 100644 tools/testing/selftests/bpf/progs/so_timestamping.c diff --git a/tools/testing/selftests/bpf/prog_tests/so_timestamping.c b/tools/testing/selftests/bpf/prog_tests/so_timestamping.c new file mode 100644 index 000000000000..dfb7588c246d --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/so_timestamping.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Tencent */ + +#define _GNU_SOURCE +#include +#include +#include +#include + +#include "test_progs.h" +#include "cgroup_helpers.h" +#include "network_helpers.h" + +#include "so_timestamping.skel.h" + +#define CG_NAME "/so-timestamping-test" + +static const char addr4_str[] = "127.0.0.1"; +static const char addr6_str[] = "::1"; +static struct so_timestamping *skel; +static int cg_fd; + +static int create_netns(void) +{ + if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns")) + return -1; + + if (!ASSERT_OK(system("ip link set dev lo up"), "set lo up")) + return -1; + + return 0; +} + +static void test_tcp(int family) +{ + struct so_timestamping__bss *bss = skel->bss; + char buf[] = "testing testing"; + int sfd = -1, cfd = -1; + int n; + + memset(bss, 0, sizeof(*bss)); + + sfd = start_server(family, SOCK_STREAM, + family == AF_INET6 ? addr6_str : addr4_str, 0, 0); + if (!ASSERT_GE(sfd, 0, "start_server")) + goto out; + + cfd = connect_to_fd(sfd, 0); + if (!ASSERT_GE(cfd, 0, "connect_to_fd_server")) { + close(sfd); + goto out; + } + + n = write(cfd, buf, sizeof(buf)); + if (!ASSERT_EQ(n, sizeof(buf), "send to server")) + goto out; + + ASSERT_EQ(bss->nr_active, 1, "nr_active"); + ASSERT_EQ(bss->nr_passive, 1, "nr_passive"); + ASSERT_EQ(bss->nr_sched, 1, "nr_sched"); + ASSERT_EQ(bss->nr_txsw, 1, "nr_txsw"); + ASSERT_EQ(bss->nr_ack, 1, "nr_ack"); + +out: + if (sfd >= 0) + close(sfd); + if (cfd >= 0) + close(cfd); +} + +void test_so_timestamping(void) +{ + cg_fd = test__join_cgroup(CG_NAME); + if (cg_fd < 0) + return; + + if (create_netns()) + goto done; + + skel = so_timestamping__open(); + if (!ASSERT_OK_PTR(skel, "open skel")) + goto done; + + if (!ASSERT_OK(so_timestamping__load(skel), "load skel")) + goto done; + + skel->links.skops_sockopt = + bpf_program__attach_cgroup(skel->progs.skops_sockopt, cg_fd); + if (!ASSERT_OK_PTR(skel->links.skops_sockopt, "attach cgroup")) + goto done; + + test_tcp(AF_INET6); + test_tcp(AF_INET); + +done: + so_timestamping__destroy(skel); + close(cg_fd); +} diff --git a/tools/testing/selftests/bpf/progs/so_timestamping.c b/tools/testing/selftests/bpf/progs/so_timestamping.c new file mode 100644 index 000000000000..a15317951786 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/so_timestamping.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Tencent */ + +#include "vmlinux.h" +#include "bpf_tracing_net.h" +#include +#include +#include +#include "bpf_misc.h" + +#define SO_TIMESTAMPING 37 +#define SOF_TIMESTAMPING_BPF_SUPPPORTED_MASK (SOF_TIMESTAMPING_SOFTWARE | \ + SOF_TIMESTAMPING_TX_SCHED | \ + SOF_TIMESTAMPING_TX_SOFTWARE | \ + SOF_TIMESTAMPING_TX_ACK | \ + SOF_TIMESTAMPING_OPT_ID | \ + SOF_TIMESTAMPING_OPT_ID_TCP) + +extern unsigned long CONFIG_HZ __kconfig; + +int nr_active; +int nr_passive; +int nr_sched; +int nr_txsw; +int nr_ack; + +struct sockopt_test { + int opt; + int new; + int expected; +}; + +static const struct sockopt_test sol_socket_tests[] = { + { .opt = SO_TIMESTAMPING, .new = SOF_TIMESTAMPING_TX_SCHED, .expected = 256, }, + { .opt = SO_TIMESTAMPING, .new = SOF_TIMESTAMPING_BPF_SUPPPORTED_MASK, .expected = 66450, }, + { .opt = 0, }, +}; + +struct loop_ctx { + void *ctx; + struct sock *sk; +}; + +static int bpf_test_sockopt_int(void *ctx, struct sock *sk, + const struct sockopt_test *t, + int level) +{ + int tmp, new, expected, opt; + + opt = t->opt; + new = t->new; + expected = t->expected; + + if (bpf_setsockopt(ctx, level, opt, &new, sizeof(new))) + return 1; + if (bpf_getsockopt(ctx, level, opt, &tmp, sizeof(tmp)) || + tmp != expected) + return 1; + + return 0; +} + +static int bpf_test_socket_sockopt(__u32 i, struct loop_ctx *lc) +{ + const struct sockopt_test *t; + + if (i >= ARRAY_SIZE(sol_socket_tests)) + return 1; + + t = &sol_socket_tests[i]; + if (!t->opt) + return 1; + + return bpf_test_sockopt_int(lc->ctx, lc->sk, t, SOL_SOCKET); +} + +static int bpf_test_sockopt(void *ctx, struct sock *sk) +{ + struct loop_ctx lc = { .ctx = ctx, .sk = sk, }; + int n; + + n = bpf_loop(ARRAY_SIZE(sol_socket_tests), bpf_test_socket_sockopt, &lc, 0); + if (n != ARRAY_SIZE(sol_socket_tests)) + return -1; + + return 0; +} + +SEC("sockops") +int skops_sockopt(struct bpf_sock_ops *skops) +{ + struct bpf_sock *bpf_sk = skops->sk; + struct sock *sk; + + if (!bpf_sk) + return 1; + + sk = (struct sock *)bpf_skc_to_tcp_sock(bpf_sk); + if (!sk) + return 1; + + switch (skops->op) { + case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB: + nr_active += !bpf_test_sockopt(skops, sk); + break; + case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: + nr_passive += !bpf_test_sockopt(skops, sk); + break; + case BPF_SOCK_OPS_TS_SCHED_OPT_CB: + nr_sched += 1; + break; + case BPF_SOCK_OPS_TS_SW_OPT_CB: + nr_txsw += 1; + break; + case BPF_SOCK_OPS_TS_ACK_OPT_CB: + nr_ack += 1; + break; + } + + return 1; +} + +char _license[] SEC("license") = "GPL";