From patchwork Fri Oct 20 12:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430658 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26D841A70B for ; Fri, 20 Oct 2023 12:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MR9dz9hZ" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE108D52 for ; Fri, 20 Oct 2023 05:57:52 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a836d49eeaso10603037b3.0 for ; Fri, 20 Oct 2023 05:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806672; x=1698411472; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2XPRWmyC7uRIMaPtxuf1nocd3dRXmBXuIJstIek5lcg=; b=MR9dz9hZVE1XZThStT2iL5p4p/wk4Pk7BRLbwyudXjjdJOxx5qjnAgOeXh1bw3bgfs 9XI4vyqSNZjz/1WqgAp/N2ZdxRwHqXg/Wtr4DutE0Ny3ghfIhUVJ4hE9QATu11wku+Eo XE1Xa8LAtEuTsQnte3HRcceds9vbKWAoB3BS5NDhWTuNlKikYsgrQMvuU76KFES/Ki65 LtnR8yGOjGU4iB+LE02ZJJkOVMUTaDsvXq7EDBsa7S31wJ7vOPgqGP5i5FhtBOH7A7NM OaxDlJpOC8ZuQCY/cInILXwZu8Qo9c1eDRUulrArDgQeLHRfgeKVmEV7847cOHnm2T+e HMcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806672; x=1698411472; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2XPRWmyC7uRIMaPtxuf1nocd3dRXmBXuIJstIek5lcg=; b=EesbrifOdUTg2QJnpebFpUHT6lYBhCcCj60PKgukTp7h36yPUkz11656k+5bJUziCl gNQHeQ1u/0rsT/DraSJ0HFEiwV12hoq1/VerTwXJEtl2qhvP/T3Xw5LcKrecnAPOBlX8 EqmP6RO2K79EUpacqFnS4lBb68EKE0QubNbqlKJCFZq24fyYRH5QAk5wTypUan/LKXuH EJdkMyKLaF6QTZprkuKlwDEp8gZqhMdc9o1NVf/ik75vYgN3PBwZMAFF3UQPaEKlPMLT ag1knTCC4bKqs0x0rQoi+24gRu8XH2QeqmmUMjQ5YLk/meF7GwEu307smgTSzQYYZups uWrw== X-Gm-Message-State: AOJu0YyJ5xepz9kqiIr8eC0CBie5vlO8bMbk8csIIhp0xGLUy2jWYO5r 16pv2Ckmk9EWw7ubBnDm6K0Hmk8X4VFzyQ== X-Google-Smtp-Source: AGHT+IGX02mPrUbkQeP0Qxe8vcFuLIcvfLm6CTVtnbaOYYmVbiohV5bywm5nj9bD8SLQfzMptjwcUGIQJMtvVg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:d644:0:b0:5a7:f73d:e69 with SMTP id y65-20020a0dd644000000b005a7f73d0e69mr38225ywd.4.1697806671982; Fri, 20 Oct 2023 05:57:51 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:36 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-2-edumazet@google.com> Subject: [PATCH net-next 01/13] chtls: fix tp->rcv_tstamp initialization From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet , Ayush Sawal X-Patchwork-Delegate: kuba@kernel.org tp->rcv_tstamp should be set to tcp_jiffies, not tcp_time_stamp(). Fixes: cc35c88ae4db ("crypto : chtls - CPL handler definition") Signed-off-by: Eric Dumazet Cc: Ayush Sawal --- drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c index 7750702900fa60b3405992e6c6c465b43abff116..6f6525983130e7701e9c6530afbecb9ae374d7ee 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c @@ -2259,7 +2259,7 @@ static void chtls_rx_ack(struct sock *sk, struct sk_buff *skb) if (tp->snd_una != snd_una) { tp->snd_una = snd_una; - tp->rcv_tstamp = tcp_time_stamp(tp); + tp->rcv_tstamp = tcp_jiffies32; if (tp->snd_una == tp->snd_nxt && !csk_flag_nochk(csk, CSK_TX_FAILOVER)) csk_reset_flag(csk, CSK_TX_WAIT_IDLE); From patchwork Fri Oct 20 12:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430657 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37D041A70E for ; Fri, 20 Oct 2023 12:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E1LhfcVQ" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79DAD9F for ; Fri, 20 Oct 2023 05:57:54 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7cf717bacso10778717b3.1 for ; Fri, 20 Oct 2023 05:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806673; x=1698411473; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=INi1WHrAHQ3lQVzZfN0QdK8/QFfP7fv6wbxwAUUDHOc=; b=E1LhfcVQBVBVi6sYZeCZQCjZr8picpfsGfIdOKNnJ6HMZmmT9Q5u3RK0U0nEuiy/uK 9VFN5W2SMxaor760mOPnlr7zGVqI737Df6y3IvD4gGcSYt26pv79xYi0ytw2KSGrYXum fuAun/caTh7o5h9TM6iy3STVwxsOeAl0Lm2scHQ/z5APqiSz6NnorGPoq2whjasFRMMv E/s0icD0sx/ifrGOHoG1G0UwNH8tGGk7TBmi0sFu2WyVXTV8m6xF4YWUBdjeN20VKMPT QjASrPu5j6bouY5iNONHM3py/evhSF7/ddihHwUmUSSZf6A83MBO0RwxBhOG1OhbsVBk L21g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806673; x=1698411473; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=INi1WHrAHQ3lQVzZfN0QdK8/QFfP7fv6wbxwAUUDHOc=; b=eEQlqKWCqZku0GGKhVM/QpbSsj0dfnLfjGJDHrQ7l3mCUSaDiZiwGgC7Dk4enCYcDq qkVlGHJFRlfpJTiXz7YxGyl90hPG0y2HqI4TIdUmOp2dtR3ZE9eG2nB9iiCQehFeXqWe k7Qr0NMsUfAzoAOT08I5OyDic7tkk6FgRiCjXUN4MirXNfmvtwfSb8UmeSqH55hdcOVE gVPD3mYQawLYXIyIfqdT5DWzkIcoDeiNoiVFeE+TTsQO714+2ZmuXRnQ5pprmz2S6XFO F6B+ycX2y0INBs6uu9NxIPcV2EMY50dMt/EkIs7BPPq9DPL8ovdCxPzybnYNDVsRVvB9 FwGQ== X-Gm-Message-State: AOJu0YxVqAmE12mmX/MKI+qQj2+JxHULopXiwoimhU3DUW9sHv2SK8nP /F436YbGdige9ZDM4ZW1lf0tZwcMKoalgg== X-Google-Smtp-Source: AGHT+IHRyRiwyWEoA6G+ZjEjGiskDX3zpONRlrFvtFeOhBjLz+AP/tRmyLOKUc9Bdc/DO+1khy4JXI31lXpiOg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d055:0:b0:d9a:bc94:8bf with SMTP id h82-20020a25d055000000b00d9abc9408bfmr38121ybg.12.1697806673765; Fri, 20 Oct 2023 05:57:53 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:37 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-3-edumazet@google.com> Subject: [PATCH net-next 02/13] tcp: fix cookie_init_timestamp() overflows From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org cookie_init_timestamp() is supposed to return a 64bit timestamp suitable for both TSval determination and setting of skb->tstamp. Unfortunately it uses 32bit fields and overflows after 2^32 * 10^6 nsec (~49 days) of uptime. Generated TSval are still correct, but skb->tstamp might be set far away in the past, potentially confusing other layers. tcp_ns_to_ts() is changed to return a full 64bit value, ts and ts_now variables are changed to u64 type, and TSMASK is removed in favor of shifts operations. While we are at it, change this sequence: ts >>= TSBITS; ts--; ts <<= TSBITS; ts |= options; to: ts -= (1UL << TSBITS); Fixes: 9a568de4818d ("tcp: switch TCP TS option (RFC 7323) to 1ms clock") Signed-off-by: Eric Dumazet --- include/net/tcp.h | 2 +- net/ipv4/syncookies.c | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index bad304d173a56c768e1f87fa740e8e568d220f00..d47a57a47b50b4bbc7ff45c76371d39cf6207c54 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -805,7 +805,7 @@ static inline u32 tcp_time_stamp(const struct tcp_sock *tp) } /* Convert a nsec timestamp into TCP TSval timestamp (ms based currently) */ -static inline u32 tcp_ns_to_ts(u64 ns) +static inline u64 tcp_ns_to_ts(u64 ns) { return div_u64(ns, NSEC_PER_SEC / TCP_TS_HZ); } diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index dc478a0574cbe71d392522ed4a690f12654f3e08..3b4dafefb4b036c661bf52f5e7e304b943a4fd5e 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -41,7 +41,6 @@ static siphash_aligned_key_t syncookie_secret[2]; * requested/supported by the syn/synack exchange. */ #define TSBITS 6 -#define TSMASK (((__u32)1 << TSBITS) - 1) static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, u32 count, int c) @@ -62,27 +61,22 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, */ u64 cookie_init_timestamp(struct request_sock *req, u64 now) { - struct inet_request_sock *ireq; - u32 ts, ts_now = tcp_ns_to_ts(now); + const struct inet_request_sock *ireq = inet_rsk(req); + u64 ts, ts_now = tcp_ns_to_ts(now); u32 options = 0; - ireq = inet_rsk(req); - options = ireq->wscale_ok ? ireq->snd_wscale : TS_OPT_WSCALE_MASK; if (ireq->sack_ok) options |= TS_OPT_SACK; if (ireq->ecn_ok) options |= TS_OPT_ECN; - ts = ts_now & ~TSMASK; + ts = (ts_now >> TSBITS) << TSBITS; ts |= options; - if (ts > ts_now) { - ts >>= TSBITS; - ts--; - ts <<= TSBITS; - ts |= options; - } - return (u64)ts * (NSEC_PER_SEC / TCP_TS_HZ); + if (ts > ts_now) + ts -= (1UL << TSBITS); + + return ts * (NSEC_PER_SEC / TCP_TS_HZ); } From patchwork Fri Oct 20 12:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430659 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 528EA1A70F for ; Fri, 20 Oct 2023 12:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vrrDYhnM" Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 168EFD57 for ; Fri, 20 Oct 2023 05:57:56 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cb79eb417so925159276.2 for ; Fri, 20 Oct 2023 05:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806675; x=1698411475; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UzzMk4FpgrpMXYF9vsm1NsquU/PucyXUOOW/Z+ImApo=; b=vrrDYhnMlSkxwkmG99RwjgWFZsmwARkI8mVNeUyXz7sqEConKDdxeSzZ5dOIuXUMAf +9DYTAGiMJJvVMgGRpuu71kfoUFLpRtqFWkvz0KMvIvceUfG3MZdH2OpegQ7h4oAq0ex wGFz9Ptz/6ayvPQvFCDhds+0KQEvQsFxlFXBouR6Ba4P/SsmrbzpJsmr/W85jUGQk4Mq nAcEt1gRQGy7kbhs3PvRtvy7Rwq52efLCHIGNoJLJdaRcL7HKwF2Zadupo1WlB7u1qEL 8ZWKdoUIDbHVtVWAdKVVOsun5rm4w9mLi+xE3tbqFL9qaWG2lNm/28S/Tx8NRzj4RLpZ EEvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806675; x=1698411475; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UzzMk4FpgrpMXYF9vsm1NsquU/PucyXUOOW/Z+ImApo=; b=RdbMQKrFz0bBpgHaM75xpCKXd8EifghI821feV1BspF5p2uZqRPJSitzKciyVdPaZA vKaf5+OkD03Z78CN6xuIbp6i/gBIHhqsWr8DFny6lKU9hYHH0ioZQP21lt57Ev6LSi5j w+hGsWiC6ogBL5P6Vdiv9FMFFiVLbpOL+qmWHnNCUbpoFH6ttTCjm0Y9GoCUNB75PuIQ 4QUJRF2AbiTsD9/ADlfCBEldb8iXYCyztvK2GvEYoy0lRXfgkSGYNEJzGetFRKKAxtIt eA7FFy0EAV9P2R6zBABgubzz43PI377LV9ZrEDZjQKpINdD7TaLsJ+M9oqfJ7Yc8nowU 1a5A== X-Gm-Message-State: AOJu0YxC/FrV+rXzyEbb9wTwKlaHSsZlRWQhEGqkk6zmJyqF5cJCkjhT mvrFowJ+lL1IXny7IGgxDHon2oc4ACp8jQ== X-Google-Smtp-Source: AGHT+IF9hh2zM1qc8FzaSLKipZM81Ch2kPo8ErRXHRijaoL1udJdNQPl7FusrVX7aRy9vTt03U+4+vbPiFpc7w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:938d:0:b0:d9a:61d2:38ca with SMTP id a13-20020a25938d000000b00d9a61d238camr33305ybm.10.1697806675342; Fri, 20 Oct 2023 05:57:55 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:38 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-4-edumazet@google.com> Subject: [PATCH net-next 03/13] tcp: add tcp_time_stamp_ms() helper From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org In preparation of adding usec TCP TS values, add tcp_time_stamp_ms() for contexts needing ms based values. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 5 +++++ net/ipv4/tcp_input.c | 2 +- net/ipv4/tcp_timer.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index d47a57a47b50b4bbc7ff45c76371d39cf6207c54..9fc6dc4ba9e2e2be44318d4495ceb19523395b18 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -804,6 +804,11 @@ static inline u32 tcp_time_stamp(const struct tcp_sock *tp) return div_u64(tp->tcp_mstamp, USEC_PER_SEC / TCP_TS_HZ); } +static inline u32 tcp_time_stamp_ms(const struct tcp_sock *tp) +{ + return div_u64(tp->tcp_mstamp, USEC_PER_MSEC); +} + /* Convert a nsec timestamp into TCP TSval timestamp (ms based currently) */ static inline u64 tcp_ns_to_ts(u64 ns) { diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index ab87f0285b728f3829f1e409833ed4feebd7920e..ffce17545b62c78595c5dd569665a6ebe6a29bbc 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -2856,7 +2856,7 @@ void tcp_enter_recovery(struct sock *sk, bool ece_ack) static void tcp_update_rto_time(struct tcp_sock *tp) { if (tp->rto_stamp) { - tp->total_rto_time += tcp_time_stamp(tp) - tp->rto_stamp; + tp->total_rto_time += tcp_time_stamp_ms(tp) - tp->rto_stamp; tp->rto_stamp = 0; } } diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 0862b73dd3b5299d2b201e9e93dbef8a0617f75b..63247c78dc13d445c1e1c5cf24e7ffd7a1faa403 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -422,7 +422,7 @@ static void tcp_update_rto_stats(struct sock *sk) if (!icsk->icsk_retransmits) { tp->total_rto_recoveries++; - tp->rto_stamp = tcp_time_stamp(tp); + tp->rto_stamp = tcp_time_stamp_ms(tp); } icsk->icsk_retransmits++; tp->total_rto++; From patchwork Fri Oct 20 12:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430660 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 162BF1A72F for ; Fri, 20 Oct 2023 12:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="x5tDgOvx" Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED0269F for ; Fri, 20 Oct 2023 05:57:57 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id af79cd13be357-778ac2308e6so57178385a.3 for ; Fri, 20 Oct 2023 05:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806677; x=1698411477; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UTpsbJ07nSayV69jTdmjwmIWvQszRH1HsCpqj2/5XfA=; b=x5tDgOvx8kndY3oagKewk3b8QmAgVWVLK+zUkTAEsVF4g1rCjzlRQk/W9eXWiw0J1k k/9NTDRqctqadKiQO3F+3BT7Onck55g/qhxQs8krjzC7pUvgbYuPt1uIveKtHpC3CbuF 7Hzjg4IxS2ReRT+hmghGyFR9skATRAy2khCsk5vn2J+fqT5uPHiS7DcLo8ylEX6o2Jxe AFxk7pX290HUeVgV7yuuYuWTfThpnZ4x0B42JLE35sTI3ZGKdIkgZ8BuIspxLESFy4I5 SUQ6fpNLqnUcMlRobkPfGYXnNQakk5pi0y8HZ5/KfgNj/amBoX/gZtC0FdeKBRLH7jyb Xfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806677; x=1698411477; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UTpsbJ07nSayV69jTdmjwmIWvQszRH1HsCpqj2/5XfA=; b=OUAqeaNiG3HaNuiJnodYgQToDtgN5GEGcdUj6k+6w5FH3rjJQNrXsngE9OZyYIar31 iXp0SPqIuFdrs0xuVOgKSxMSbL4h1v6xPQz++jOf8mnBxhYhNkBAnY2oLstZ/p24kqo4 3a1SjykJj+Rj9qqaR/5qoMi/ZeqJZImayiyxO15QWBgTvPXe0hhXnDZqjz8BVLK9p5L7 0E8X0GGsslSkjv4o1m5UFHBfrBJn+WM12wBDrZSeSquqFv30qp4tz95sS3ir9p5z63o5 rMqG0HaX6FR3ri6gkdmJFq/6dNyl/O18uWRNO3H/fNksNwNqnD/dYKlk/OYidVbYDH8i txJw== X-Gm-Message-State: AOJu0YywZ/D0tPELvP28DZl+uF1UqR6x1vzxmA36xujv3iWt6uC9yjTI HAhfdaCC94gdhA0cLQLZxUXbGrOZemDvoA== X-Google-Smtp-Source: AGHT+IHb6PkM9GgIk0VpcNbqYhljfTvLDziTaumRXsFjKYH/t6RUhcmY5Oprdj82HWKnuyQq5zuEEX6EFXrfYA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:620a:ec2:b0:76d:8404:f17f with SMTP id x2-20020a05620a0ec200b0076d8404f17fmr30322qkm.2.1697806677128; Fri, 20 Oct 2023 05:57:57 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:39 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-5-edumazet@google.com> Subject: [PATCH net-next 04/13] tcp: introduce tcp_clock_ms() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org It delivers current TCP time stamp in ms unit, and is used in place of confusing tcp_time_stamp_raw() It is the same family than tcp_clock_ns() and tcp_clock_ms(). tcp_time_stamp_raw() will be replaced later for TSval contexts with a more descriptive name. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 5 +++++ net/ipv4/tcp.c | 6 ++---- net/ipv4/tcp_minisocks.c | 4 ++-- net/netfilter/nf_synproxy_core.c | 2 +- tools/testing/selftests/bpf/progs/xdp_synproxy_kern.c | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 9fc6dc4ba9e2e2be44318d4495ceb19523395b18..3bdf1141f5a2c11e30ad85c68aafd062e7bf548c 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -798,6 +798,11 @@ static inline u64 tcp_clock_us(void) return div_u64(tcp_clock_ns(), NSEC_PER_USEC); } +static inline u64 tcp_clock_ms(void) +{ + return div_u64(tcp_clock_ns(), NSEC_PER_MSEC); +} + /* This should only be used in contexts where tp->tcp_mstamp is up to date */ static inline u32 tcp_time_stamp(const struct tcp_sock *tp) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 56a8d936000f610566e46694fec5ddd1dccd7102..5b034b0356ecbd2b7d2dcafd9caac2b8de5886f1 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3817,10 +3817,8 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_total_rto = tp->total_rto; info->tcpi_total_rto_recoveries = tp->total_rto_recoveries; info->tcpi_total_rto_time = tp->total_rto_time; - if (tp->rto_stamp) { - info->tcpi_total_rto_time += tcp_time_stamp_raw() - - tp->rto_stamp; - } + if (tp->rto_stamp) + info->tcpi_total_rto_time += tcp_clock_ms() - tp->rto_stamp; unlock_sock_fast(sk, slow); } diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 3f87611077ef21edb61f3d6c751c88c515bb4b5b..a9fdba897a28f3a5835a1bd1426f82de0e81a633 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -567,8 +567,8 @@ struct sock *tcp_create_openreq_child(const struct sock *sk, USEC_PER_SEC / TCP_TS_HZ); newtp->total_rto = req->num_timeout; newtp->total_rto_recoveries = 1; - newtp->total_rto_time = tcp_time_stamp_raw() - - newtp->retrans_stamp; + newtp->total_rto_time = tcp_clock_ms() - + newtp->retrans_stamp; } newtp->tsoffset = treq->ts_off; #ifdef CONFIG_TCP_MD5SIG diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index 16915f8eef2b16eec7da7ecaaf8b4a4af5dd94e2..467671f2d42f742554d95b017738aaa4ea4c9121 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -153,7 +153,7 @@ void synproxy_init_timestamp_cookie(const struct nf_synproxy_info *info, struct synproxy_options *opts) { opts->tsecr = opts->tsval; - opts->tsval = tcp_time_stamp_raw() & ~0x3f; + opts->tsval = tcp_clock_ms() & ~0x3f; if (opts->options & NF_SYNPROXY_OPT_WSCALE) { opts->tsval |= opts->wscale; diff --git a/tools/testing/selftests/bpf/progs/xdp_synproxy_kern.c b/tools/testing/selftests/bpf/progs/xdp_synproxy_kern.c index 07d786329105da371dd280868981e8e19ac5f6a8..e959336c7a7304be409ffac7d3a34f64538d5f74 100644 --- a/tools/testing/selftests/bpf/progs/xdp_synproxy_kern.c +++ b/tools/testing/selftests/bpf/progs/xdp_synproxy_kern.c @@ -177,7 +177,7 @@ static __always_inline __u32 tcp_ns_to_ts(__u64 ns) return ns / (NSEC_PER_SEC / TCP_TS_HZ); } -static __always_inline __u32 tcp_time_stamp_raw(void) +static __always_inline __u32 tcp_clock_ms(void) { return tcp_ns_to_ts(tcp_clock_ns()); } @@ -274,7 +274,7 @@ static __always_inline bool tscookie_init(struct tcphdr *tcp_header, if (!loop_ctx.option_timestamp) return false; - cookie = tcp_time_stamp_raw() & ~TSMASK; + cookie = tcp_clock_ms() & ~TSMASK; cookie |= loop_ctx.wscale & TS_OPT_WSCALE_MASK; if (loop_ctx.option_sack) cookie |= TS_OPT_SACK; From patchwork Fri Oct 20 12:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430661 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0264D1A5BF for ; Fri, 20 Oct 2023 12:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QG2QFXRJ" Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9997D52 for ; Fri, 20 Oct 2023 05:57:59 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id 6a1803df08f44-66cffe51b07so9928876d6.3 for ; Fri, 20 Oct 2023 05:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806679; x=1698411479; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YyLbbYLzNp5nrq8dHpNdkBkvl1SP5QTsaaqb8mwCJ78=; b=QG2QFXRJlM+xh/ey3gTPARj2IoPyAuSafTnbV5TotzLuE0ThV/gr2U4Y9yz1VKo1j0 EnKiIDzhL21U5EXtxCx0V9XSucJRg86gmi2YTmX8HWb1uGcFDXUMe8wnb/E1svbU1orp azRm82kmrhTuartDybxq7UaqqB9WpJzGEPAO6UWyRdrtcBhVHJi2gyTdtQuWRy9emW7W pz5bk3NSAcWjy8PLMSw6c1R2LNPHeP3CoPbBOBHv+wxaq6I5ULD8MZc+cdyOLpX3lE6D E0Dp+/EU+FKxv6XSlbELx9A8F5tyNYYS836nLyiUauaLz3vBkmOpVaCf79mODNYWeKV2 vucQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806679; x=1698411479; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YyLbbYLzNp5nrq8dHpNdkBkvl1SP5QTsaaqb8mwCJ78=; b=D61YBZ/paOfc6VsutdmSWMbEGYEpf/XMUEMVvj43HFQS7465k/EK5vhio5/t1tlD1W x6iPp9a0h55n9dwZQCfY7t/HrkP3gsVd+zhjcRb1QJE+06lpSS0wYOHkEKL4iPDVa0RO UqSZF5/Py/DHHqgvBepE8AsM34yjYj6035X/nzf0VZWH75F5kGL54KpNs8t4RKL1gCCs fBDXSuFnfSuOUh3+yWmeTNRFiSyIRdErwgmu0MiZ8WRRBvgsOWzOJNzZlyyRWE9//8DK nkEtlZ3BTCChA3evIbCDLiBXDlS6Hm/P1H9DZEB3LS4CnHE7X87MbHupRxrROVD7mLgk JNUQ== X-Gm-Message-State: AOJu0YwRzfN18vkgy7xvFmnu/1lBXMQPw0hzldU7QBWZrWPrpRsBaswC awdlOCg1hYYd/0CVwtSgmNE8fvq4iB9KWA== X-Google-Smtp-Source: AGHT+IGG/m4CurYn4/FfdKNhYDnXeFtCFgmcDTIN/quPak4/NQ9g+xHqMPTT1yCvr1doETuXhVwORq9iiS+1Dg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6214:4a89:b0:66d:51f:c1a9 with SMTP id pi9-20020a0562144a8900b0066d051fc1a9mr38213qvb.9.1697806678824; Fri, 20 Oct 2023 05:57:58 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:40 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-6-edumazet@google.com> Subject: [PATCH net-next 05/13] tcp: replace tcp_time_stamp_raw() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org In preparation of usec TCP TS support, remove tcp_time_stamp_raw() in favor of tcp_clock_ts() helper. This helper will return a suitable 32bit result to feed TS values, depending on a socket field. Also add tcp_tw_tsval() and tcp_rsk_tsval() helpers to factorize the details. We do not yet support usec timestamps. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 25 +++++++++++++++++++------ net/ipv4/tcp.c | 4 ++-- net/ipv4/tcp_ipv4.c | 4 ++-- net/ipv6/tcp_ipv6.c | 4 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 3bdf1141f5a2c11e30ad85c68aafd062e7bf548c..0534526a535da7cee7d8d49fd556fe4d7a4eefb6 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -803,6 +803,16 @@ static inline u64 tcp_clock_ms(void) return div_u64(tcp_clock_ns(), NSEC_PER_MSEC); } +/* TCP Timestamp included in TS option (RFC 1323) can either use ms + * or usec resolution. Each socket carries a flag to select one or other + * resolution, as the route attribute could change anytime. + * Each flow must stick to initial resolution. + */ +static inline u32 tcp_clock_ts(bool usec_ts) +{ + return usec_ts ? tcp_clock_us() : tcp_clock_ms(); +} + /* This should only be used in contexts where tp->tcp_mstamp is up to date */ static inline u32 tcp_time_stamp(const struct tcp_sock *tp) { @@ -820,12 +830,6 @@ static inline u64 tcp_ns_to_ts(u64 ns) return div_u64(ns, NSEC_PER_SEC / TCP_TS_HZ); } -/* Could use tcp_clock_us() / 1000, but this version uses a single divide */ -static inline u32 tcp_time_stamp_raw(void) -{ - return tcp_ns_to_ts(tcp_clock_ns()); -} - void tcp_mstamp_refresh(struct tcp_sock *tp); static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0) @@ -844,6 +848,15 @@ static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb) return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC); } +static inline u32 tcp_tw_tsval(const struct tcp_timewait_sock *tcptw) +{ + return tcp_clock_ts(false) + tcptw->tw_ts_offset; +} + +static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq) +{ + return tcp_clock_ts(false) + treq->ts_off; +} #define tcp_flag_byte(th) (((u_int8_t *)th)[13]) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5b034b0356ecbd2b7d2dcafd9caac2b8de5886f1..805f8341064fec4fe0504e14c579185cfe11d896 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3632,7 +3632,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, if (!tp->repair) err = -EPERM; else - WRITE_ONCE(tp->tsoffset, val - tcp_time_stamp_raw()); + WRITE_ONCE(tp->tsoffset, val - tcp_clock_ts(false)); break; case TCP_REPAIR_WINDOW: err = tcp_repair_set_window(tp, optval, optlen); @@ -4143,7 +4143,7 @@ int do_tcp_getsockopt(struct sock *sk, int level, break; case TCP_TIMESTAMP: - val = tcp_time_stamp_raw() + READ_ONCE(tp->tsoffset); + val = tcp_clock_ts(false) + READ_ONCE(tp->tsoffset); break; case TCP_NOTSENT_LOWAT: val = READ_ONCE(tp->notsent_lowat); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a67a5de86253ba40e38154e81ffef11f68a55a3a..cdd65cc594bc4571fa5793bc14d6e9ab892dfd2a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -954,7 +954,7 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb) tcp_v4_send_ack(sk, skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt, tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale, - tcp_time_stamp_raw() + tcptw->tw_ts_offset, + tcp_tw_tsval(tcptw), tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw), @@ -988,7 +988,7 @@ static void tcp_v4_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, tcp_v4_send_ack(sk, skb, seq, tcp_rsk(req)->rcv_nxt, req->rsk_rcv_wnd >> inet_rsk(req)->rcv_wscale, - tcp_time_stamp_raw() + tcp_rsk(req)->ts_off, + tcp_rsk_tsval(tcp_rsk(req)), READ_ONCE(req->ts_recent), 0, tcp_md5_do_lookup(sk, l3index, addr, AF_INET), diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index d410703bb5a1e483848104e7e4cb379e45d7b216..1ee6517e9b2f9d549268dea240a725976a9e2720 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1096,7 +1096,7 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb) tcp_v6_send_ack(sk, skb, tcptw->tw_snd_nxt, tcptw->tw_rcv_nxt, tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale, - tcp_time_stamp_raw() + tcptw->tw_ts_offset, + tcp_tw_tsval(tcptw), tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw), tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel), tw->tw_priority, tw->tw_txhash); @@ -1123,7 +1123,7 @@ static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, tcp_rsk(req)->snt_isn + 1 : tcp_sk(sk)->snd_nxt, tcp_rsk(req)->rcv_nxt, req->rsk_rcv_wnd >> inet_rsk(req)->rcv_wscale, - tcp_time_stamp_raw() + tcp_rsk(req)->ts_off, + tcp_rsk_tsval(tcp_rsk(req)), READ_ONCE(req->ts_recent), sk->sk_bound_dev_if, tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->saddr, l3index), ipv6_get_dsfield(ipv6_hdr(skb)), 0, From patchwork Fri Oct 20 12:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430662 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04A3F1A706 for ; Fri, 20 Oct 2023 12:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sH+7V8U2" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F3139F for ; Fri, 20 Oct 2023 05:58:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a8ebc70d33so10900317b3.1 for ; Fri, 20 Oct 2023 05:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806680; x=1698411480; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YXlmdGoUA3/OHMacQpvAI4M9eHXnfU3t+DEkdejpF6c=; b=sH+7V8U2Xvys/LjlLvwBYYN3kirijXmQAemgwNqoCXTAitTjAY+RTElaHfY6xcH3fl 8/JVVP1RFYMwRUVsBttZG2nzZ4oGWKI6KwrhJ5j5t2rPgyl7G4e52UG188jEA2QUC1if I/l73sCQCCvFoPAib+PO+uUjINeQ0v8FRY9hOxV/hAAt5GwYTVzUeOtmkpDt5tnTZckH mYwsUWVaUATQOwZvFtBYWn6E93ocUOlPKTYJHbyDWTwB/hWP7Yhps7oaw/IxEek8RI5U ab/FlceN15Fjfp4ne7XQfjHui0kL1qEhmXLibRe7qE5RadObHeaKMUsTgsXq/argXq7b Av2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806680; x=1698411480; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YXlmdGoUA3/OHMacQpvAI4M9eHXnfU3t+DEkdejpF6c=; b=toiluOJ1w6NQrZpmCQCDH+v+TMryNkXVtbmIcPR3XxB2SI09BqE3Tu/HzeT8dX2br0 KxJIo4qeDrUftG7PC3EF2q4S5o8aW7izfM7Yf8dB7qsMQnjk3G/pJB+tlW3Uf7UOxOod KkxBjEz8foV4dWhwa2I9FCZu486F1asup5U1MJb+QhnAbjkUkcEhXG7S1cXMybYQAzW2 MoZdGsiSJJBJgt3fuTb9jm/ImGRhhKp2LHo5hKzqOZLBPpAhKwNSxugzVyufFBNumROQ sEOehOemVEjvnMAkwfUlkPoOijZKzYnVYyitZQ/65hLDGToVw5e5KgaXCcaey9IHx7X/ SyDQ== X-Gm-Message-State: AOJu0YxJ/UXPAfWDM369f3y6rMCFOSGQY8taUpz/Fia11PtHiQW5XxD+ Rua1l3XliffZF3QXo/UWfRRUCRmJ7WFoyQ== X-Google-Smtp-Source: AGHT+IHnNuhMMnBgVZjS6MOYxY9RGBswEJGspl2wv6c5Lf1W5YPIzh2LORVu2E/tjaTL9C9meP6Nj4Ydg5+Ncw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1083:b0:d9a:6007:223a with SMTP id v3-20020a056902108300b00d9a6007223amr54369ybu.8.1697806680622; Fri, 20 Oct 2023 05:58:00 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:41 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-7-edumazet@google.com> Subject: [PATCH net-next 06/13] tcp: rename tcp_skb_timestamp() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org This helper returns a 32bit TCP TSval from skb->tstamp. As we are going to support usec or ms units soon, rename it to tcp_skb_timestamp_ts() and add a boolean to select the unit. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 14 +++++++++----- net/ipv4/tcp_input.c | 2 +- net/ipv4/tcp_output.c | 8 ++++---- net/ipv4/tcp_timer.c | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 0534526a535da7cee7d8d49fd556fe4d7a4eefb6..493f8550055bca09b69a9d3129d6ba781a1233f8 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -837,17 +837,21 @@ static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0) return max_t(s64, t1 - t0, 0); } -static inline u32 tcp_skb_timestamp(const struct sk_buff *skb) -{ - return tcp_ns_to_ts(skb->skb_mstamp_ns); -} - /* provide the departure time in us unit */ static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb) { return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC); } +/* Provide skb TSval in usec or ms unit */ +static inline u32 tcp_skb_timestamp_ts(bool usec_ts, const struct sk_buff *skb) +{ + if (usec_ts) + return tcp_skb_timestamp_us(skb); + + return div_u64(skb->skb_mstamp_ns, NSEC_PER_MSEC); +} + static inline u32 tcp_tw_tsval(const struct tcp_timewait_sock *tcptw) { return tcp_clock_ts(false) + tcptw->tw_ts_offset; diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index ffce17545b62c78595c5dd569665a6ebe6a29bbc..de68cad82d19e37171deadc45c5acc0cfd90c315 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -2442,7 +2442,7 @@ static bool tcp_skb_spurious_retrans(const struct tcp_sock *tp, const struct sk_buff *skb) { return (TCP_SKB_CB(skb)->sacked & TCPCB_RETRANS) && - tcp_tsopt_ecr_before(tp, tcp_skb_timestamp(skb)); + tcp_tsopt_ecr_before(tp, tcp_skb_timestamp_ts(false, skb)); } /* Nothing was retransmitted or returned timestamp is less diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 909f85aefd7401aeffcd098356c5e3823bffd89e..03a2a9fc0dc191d7066d679913d41bd2ef2d685a 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -799,7 +799,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb, if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps) && !*md5)) { opts->options |= OPTION_TS; - opts->tsval = tcp_skb_timestamp(skb) + tp->tsoffset; + opts->tsval = tcp_skb_timestamp_ts(false, skb) + tp->tsoffset; opts->tsecr = tp->rx_opt.ts_recent; remaining -= TCPOLEN_TSTAMP_ALIGNED; } @@ -884,7 +884,7 @@ static unsigned int tcp_synack_options(const struct sock *sk, } if (likely(ireq->tstamp_ok)) { opts->options |= OPTION_TS; - opts->tsval = tcp_skb_timestamp(skb) + tcp_rsk(req)->ts_off; + opts->tsval = tcp_skb_timestamp_ts(false, skb) + tcp_rsk(req)->ts_off; opts->tsecr = READ_ONCE(req->ts_recent); remaining -= TCPOLEN_TSTAMP_ALIGNED; } @@ -943,7 +943,7 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb if (likely(tp->rx_opt.tstamp_ok)) { opts->options |= OPTION_TS; - opts->tsval = skb ? tcp_skb_timestamp(skb) + tp->tsoffset : 0; + opts->tsval = skb ? tcp_skb_timestamp_ts(false, skb) + tp->tsoffset : 0; opts->tsecr = tp->rx_opt.ts_recent; size += TCPOLEN_TSTAMP_ALIGNED; } @@ -3379,7 +3379,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) /* Save stamp of the first (attempted) retransmit. */ if (!tp->retrans_stamp) - tp->retrans_stamp = tcp_skb_timestamp(skb); + tp->retrans_stamp = tcp_skb_timestamp_ts(false, skb); if (tp->undo_retrans < 0) tp->undo_retrans = 0; diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 63247c78dc13d445c1e1c5cf24e7ffd7a1faa403..8764a9a2dc213f648ffc64f79950037b1f44ee99 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -479,7 +479,7 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk, return false; rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp(tp) - - (tp->retrans_stamp ?: tcp_skb_timestamp(skb))); + (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb))); return rtx_delta > timeout; } @@ -534,7 +534,7 @@ void tcp_retransmit_timer(struct sock *sk) struct inet_sock *inet = inet_sk(sk); u32 rtx_delta; - rtx_delta = tcp_time_stamp(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp(skb)); + rtx_delta = tcp_time_stamp(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb)); if (sk->sk_family == AF_INET) { net_dbg_ratelimited("Probing zero-window on %pI4:%u/%u, seq=%u:%u, recv %ums ago, lasting %ums\n", &inet->inet_daddr, ntohs(inet->inet_dport), From patchwork Fri Oct 20 12:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430663 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3B191A710 for ; Fri, 20 Oct 2023 12:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GBfQ5+wy" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1083ED63 for ; Fri, 20 Oct 2023 05:58:03 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7ba10cb90so10469097b3.3 for ; Fri, 20 Oct 2023 05:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806682; x=1698411482; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IGEMW0yNQTDPUrumdf0Qda7iyiVP01CEwTBL110uSOg=; b=GBfQ5+wyfvVd/tdpGR1ZrYG4zINybYKAwBc6fOdoT5Ga2GSfu8OqxX4UedZ+xfjEil 7iEtyi862NFw9iTq9n1gRENeEgA2CI+06ddpCgABqNPlyRrYLJ8LSCUsyWlVsRRFBQ4K kGNkDgFFIE7NPilq2IHzEoCEQAlwQ9twJIVSS+O6izRmVdVoCEHotR+8xu9X6aEjiMw2 XIQZ+op2HXmVvD82I2Q5p8Z/75snUYwN2ds/D+gyo2v3ugZP20/MbPPiUSkmq3HVwW3n 9BnvM9c3BqvcjohJvmYfuVjWcnb+kfJz0T2DhxkYBDOK/qM/2filasv+Jwmh1Rmidk1r FtPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806682; x=1698411482; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IGEMW0yNQTDPUrumdf0Qda7iyiVP01CEwTBL110uSOg=; b=xRWhW/nMmZnJeWB/PWvciRpxNKBbtcO45O+2fO2JpE4RPo6Y9RoKV4WpwWqXbSXyBp Q92mmpzW4Pgb2KXidGe2N70ADzqe2WpaVYHLQPRRlKgoo6WfL2AMZuJLTHpmrYKcvKTB y2r/YuxOm2JugZ5Vet4sQxDqK7AI34Tb9elgydRnp5DYHbcvJRccYQ5eo3wRTVf2sBiJ ST4PGZ5kCM6gDN8boUOEKPNYbOIunk9XWrs1J27d6eJ2O7JkgN1Rbdv/YDC48axQ2KMm lRWtUR54R6541SxZVfmZ//qQweOuvU5+tKDzJtq83nxXsPY5zsR/Xl49yPu4VM58Kdgr 4NBQ== X-Gm-Message-State: AOJu0Yxlx476fcSyP4gSYahFZpH2lcFb8917DcgJpr4nrPmq2HK//MZa F4nuGaPyFED1qKJn/Atqh0ZeWzEwpqvV3A== X-Google-Smtp-Source: AGHT+IHXRmfM3z+gEY2yIJdpMTmRIEHah4dQ8QUvVFUZGicvM4rP51XSlCIRQyHdfgexPuIBGWfZUWbf7Hlm/g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:4e42:0:b0:59b:db15:498c with SMTP id c63-20020a814e42000000b0059bdb15498cmr44137ywb.10.1697806682267; Fri, 20 Oct 2023 05:58:02 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:42 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-8-edumazet@google.com> Subject: [PATCH net-next 07/13] tcp: move tcp_ns_to_ts() to net/ipv4/syncookies.c From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org tcp_ns_to_ts() is only used once from cookie_init_timestamp(). Also add the 'bool usec_ts' parameter to enable usec TS later. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 6 ------ net/ipv4/syncookies.c | 10 +++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 493f8550055bca09b69a9d3129d6ba781a1233f8..b86abf1fbe46061a00dbd202323792f01a307969 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -824,12 +824,6 @@ static inline u32 tcp_time_stamp_ms(const struct tcp_sock *tp) return div_u64(tp->tcp_mstamp, USEC_PER_MSEC); } -/* Convert a nsec timestamp into TCP TSval timestamp (ms based currently) */ -static inline u64 tcp_ns_to_ts(u64 ns) -{ - return div_u64(ns, NSEC_PER_SEC / TCP_TS_HZ); -} - void tcp_mstamp_refresh(struct tcp_sock *tp); static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 3b4dafefb4b036c661bf52f5e7e304b943a4fd5e..62395fdb0ca557caee78d84ae70273eb42a837b9 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -51,6 +51,14 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, count, &syncookie_secret[c]); } +/* Convert one nsec 64bit timestamp to ts (ms or usec resolution) */ +static u64 tcp_ns_to_ts(bool usec_ts, u64 val) +{ + if (usec_ts) + return div_u64(val, NSEC_PER_USEC); + + return div_u64(val, NSEC_PER_MSEC); +} /* * when syncookies are in effect and tcp timestamps are enabled we encode @@ -62,7 +70,7 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport, u64 cookie_init_timestamp(struct request_sock *req, u64 now) { const struct inet_request_sock *ireq = inet_rsk(req); - u64 ts, ts_now = tcp_ns_to_ts(now); + u64 ts, ts_now = tcp_ns_to_ts(false, now); u32 options = 0; options = ireq->wscale_ok ? ireq->snd_wscale : TS_OPT_WSCALE_MASK; From patchwork Fri Oct 20 12:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430664 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 005121B29C for ; Fri, 20 Oct 2023 12:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rHUoTFr1" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00D4D5F for ; Fri, 20 Oct 2023 05:58:04 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a81a80097fso10130157b3.3 for ; Fri, 20 Oct 2023 05:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806684; x=1698411484; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ksUeEywK/bpvjP7ZVaoHGPKQBLrGKqJL+2b6PPJOsIM=; b=rHUoTFr1bD92yLtcrMOW2nM/he3N2hmvkK7bv7RMRWahceU6BDbcbp6Ak/Cn+Za0yY g3tCkucFp3Ebui4kkYjjFJHNQ4C+8aKfJFvCELGQooiNiSYbaZPuoXNZo0nLNpj9UBNn NXek1eGfh3qBXGrcUjjit2vASjUhH+bzNu5y8QfkeS0utJc0hy9FyjcazCYpapPchcdp rxaZl6IVazRk2hErF5Fw5dq2aY4nbn5oXZ7i0InGTiKE8t2XmoWqK8+cCPySkP/G4j/O 9HpFRZ6o2LDqD1IRFt3ybx/Zr42J0HJRDsf6lyihI8xW+EQDUWkkXYEv3X+sKJP9SN/a QWKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806684; x=1698411484; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ksUeEywK/bpvjP7ZVaoHGPKQBLrGKqJL+2b6PPJOsIM=; b=Lv6QB5jowekJefnOFn8BRSWUoBA2wIYyqcw9I1tiyHeFTZa330ee6ejoj1lpON9ZsO cthtRBLblQAwpLb9XNeuXMxJwjTgIE3V0ktR+YHPZdr5Y8OXMheVraz6BXCBxsnq2JhX TVebnER4EBh7GnwA6pdYvtEXfLYOSkfJSYzQPYFVwNJi1xcjSBUmhoeCJqflKSf5/+6g sZ7eY/QOJc0errgV4oZeWeQTAzGVTI8T4gT/9z4k4rxXvTfO7wL/O90XbCbymF8Hl6ex S5ydKOHOVT5MXxfUm1eWX0GbW8nBM2/Id6iop5SeITSacNXdqhBDacux+nxl+6jk2eYn yaTw== X-Gm-Message-State: AOJu0YyZgKfHsViUbEJl+4xsOV44X+ZCq9wrfmaeOyGo0/APiLEat5wE 93QmverMDyHbqXfhIZjIZmTZul4SyBvaVQ== X-Google-Smtp-Source: AGHT+IEBR+HhQSfthMjm1WvsedRsJ5TFDPWx5K9ERRhe/PSNdIZWUl1x107UxcMU0/s9LLEJU2U/iQmmM15nuw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:2584:0:b0:d9a:ca58:b32c with SMTP id l126-20020a252584000000b00d9aca58b32cmr36064ybl.1.1697806683876; Fri, 20 Oct 2023 05:58:03 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:43 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-9-edumazet@google.com> Subject: [PATCH net-next 08/13] tcp: rename tcp_time_stamp() to tcp_time_stamp_ts() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org This helper returns a TSval from a TCP socket. It currently calls tcp_time_stamp_ms() but will soon be able to return a usec based TSval, depending on an upcoming tp->tcp_usec_ts field. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 9 ++++----- net/ipv4/tcp_input.c | 6 +++--- net/ipv4/tcp_lp.c | 2 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 10 +++++----- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index b86abf1fbe46061a00dbd202323792f01a307969..af72c1dc37f3dd4cd6858e9c8f6aa7ef31541652 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -813,15 +813,14 @@ static inline u32 tcp_clock_ts(bool usec_ts) return usec_ts ? tcp_clock_us() : tcp_clock_ms(); } -/* This should only be used in contexts where tp->tcp_mstamp is up to date */ -static inline u32 tcp_time_stamp(const struct tcp_sock *tp) +static inline u32 tcp_time_stamp_ms(const struct tcp_sock *tp) { - return div_u64(tp->tcp_mstamp, USEC_PER_SEC / TCP_TS_HZ); + return div_u64(tp->tcp_mstamp, USEC_PER_MSEC); } -static inline u32 tcp_time_stamp_ms(const struct tcp_sock *tp) +static inline u32 tcp_time_stamp_ts(const struct tcp_sock *tp) { - return div_u64(tp->tcp_mstamp, USEC_PER_MSEC); + return tcp_time_stamp_ms(tp); } void tcp_mstamp_refresh(struct tcp_sock *tp); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index de68cad82d19e37171deadc45c5acc0cfd90c315..e7e38fc1d62ff16d7afd7f2ba58a1990f01e17b6 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -704,7 +704,7 @@ static inline void tcp_rcv_rtt_measure_ts(struct sock *sk, if (TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq >= inet_csk(sk)->icsk_ack.rcv_mss) { - u32 delta = tcp_time_stamp(tp) - tp->rx_opt.rcv_tsecr; + u32 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; u32 delta_us; if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { @@ -3148,7 +3148,7 @@ static bool tcp_ack_update_rtt(struct sock *sk, const int flag, */ if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && flag & FLAG_ACKED) { - u32 delta = tcp_time_stamp(tp) - tp->rx_opt.rcv_tsecr; + u32 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { if (!delta) @@ -6293,7 +6293,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && !between(tp->rx_opt.rcv_tsecr, tp->retrans_stamp, - tcp_time_stamp(tp))) { + tcp_time_stamp_ts(tp))) { NET_INC_STATS(sock_net(sk), LINUX_MIB_PAWSACTIVEREJECTED); goto reset_and_undo; diff --git a/net/ipv4/tcp_lp.c b/net/ipv4/tcp_lp.c index ae36780977d2762066cdd59e40116d1240492b90..52fe17167460fc433ec84434795f7cbef8144767 100644 --- a/net/ipv4/tcp_lp.c +++ b/net/ipv4/tcp_lp.c @@ -272,7 +272,7 @@ static void tcp_lp_pkts_acked(struct sock *sk, const struct ack_sample *sample) { struct tcp_sock *tp = tcp_sk(sk); struct lp *lp = inet_csk_ca(sk); - u32 now = tcp_time_stamp(tp); + u32 now = tcp_time_stamp_ts(tp); u32 delta; if (sample->rtt_us > 0) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 03a2a9fc0dc191d7066d679913d41bd2ef2d685a..a1fec8be9ac36c67022c90b08b0a5faa935725f0 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3961,7 +3961,7 @@ int tcp_connect(struct sock *sk) tcp_init_nondata_skb(buff, tp->write_seq++, TCPHDR_SYN); tcp_mstamp_refresh(tp); - tp->retrans_stamp = tcp_time_stamp(tp); + tp->retrans_stamp = tcp_time_stamp_ts(tp); tcp_connect_queue_skb(sk, buff); tcp_ecn_send_syn(sk, buff); tcp_rbtree_insert(&sk->tcp_rtx_queue, buff); diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 8764a9a2dc213f648ffc64f79950037b1f44ee99..bfcf3fe44c72427eccb37376bec15fb71b594c56 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -33,7 +33,7 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) user_timeout = READ_ONCE(icsk->icsk_user_timeout); if (!user_timeout) return icsk->icsk_rto; - elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts; + elapsed = tcp_time_stamp_ts(tcp_sk(sk)) - start_ts; remaining = user_timeout - elapsed; if (remaining <= 0) return 1; /* user timeout has passed; fire ASAP */ @@ -226,7 +226,7 @@ static bool retransmits_timed_out(struct sock *sk, timeout = tcp_model_timeout(sk, boundary, rto_base); } - return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0; + return (s32)(tcp_time_stamp_ts(tcp_sk(sk)) - start_ts - timeout) >= 0; } /* A write timeout has occurred. Process the after effects. */ @@ -462,7 +462,7 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req) req->num_timeout++; tcp_update_rto_stats(sk); if (!tp->retrans_stamp) - tp->retrans_stamp = tcp_time_stamp(tp); + tp->retrans_stamp = tcp_time_stamp_ts(tp); inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, req->timeout << req->num_timeout, TCP_RTO_MAX); } @@ -478,7 +478,7 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk, if (rcv_delta <= timeout) return false; - rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp(tp) - + rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp_ts(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb))); return rtx_delta > timeout; @@ -534,7 +534,7 @@ void tcp_retransmit_timer(struct sock *sk) struct inet_sock *inet = inet_sk(sk); u32 rtx_delta; - rtx_delta = tcp_time_stamp(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb)); + rtx_delta = tcp_time_stamp_ts(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb)); if (sk->sk_family == AF_INET) { net_dbg_ratelimited("Probing zero-window on %pI4:%u/%u, seq=%u:%u, recv %ums ago, lasting %ums\n", &inet->inet_daddr, ntohs(inet->inet_dport), From patchwork Fri Oct 20 12:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430665 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47A121C2A4 for ; Fri, 20 Oct 2023 12:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z0kZRhHV" Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E2C99F for ; Fri, 20 Oct 2023 05:58:06 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9cfec5e73dso184847276.2 for ; Fri, 20 Oct 2023 05:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806685; x=1698411485; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=02DDzjYqg6linF5vGARgW5m1vaLNWs9el4aSYve3p2U=; b=Z0kZRhHV6hAoo7NprhqXZGA3+tAL9onC3xyNANtGo+LAQG/mJZbANiBrsXbY+xndWH OMz7irIZDusmIza+TyfBw216sxwQkwMhohPIUQZ4+eyz78bXpAF9CDUgQnklmVrVVchm fMqJiHVFYP1vu4egXvpK3P9gQskmak8XtMB00CSyR7FDY0G5grfS56RXWI7QqrC+tNEB NvOq1ToWHbFIvX4BlPF41PoXXluDRQ00ABqBzMuaQWth7FO4VUVr7eYtMML0ymS7QZwm Jmlekihgk3lpASLxOREOzwLlPyXUNVehzdI2CKdV18Mo0Dri6tl9sVX53sBDoXPUmHR9 irYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806685; x=1698411485; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=02DDzjYqg6linF5vGARgW5m1vaLNWs9el4aSYve3p2U=; b=r3aIVhD+MLeCwqJ9yDJPLw+6jsfCQpM3Zheyv3NoaXb5trcChCpqFajsCaoDhmBFSN KRPSc8+AaQfD9Zyha49GBYXgYGY+oluaQpKwKa8djCa8a5hhx2UB5VINEf7W3PZu0Mx3 /l6IODKwKUU77POx5BC/LmLdNYqAXWEb2fJydGH3PJULiYejLmG4vUQ77mU17RWXlnOD syfqfbwMJU1FcPyA4UoOj8Un2Vy1SU6j3CEH6bnIrAnMDrWORgbORviVSTtZ55Y/11WI mrYlkD6MvY6G1YzsaV19BbredC9VexITsGd9QY+ckMwjY2ZiMYF39I0axSsRkFqEHs1s GmUg== X-Gm-Message-State: AOJu0YzrquXonFoYv5KQi5RIwksCun5gug6/n8UVBNmcHfBMS92+kyCo 3hdv7NEo758jhZppu8mONNe1pFLin//opg== X-Google-Smtp-Source: AGHT+IHXcIiD/t/mEQg/IjAuSYIeOtJe8Rap1fB7N6OSEOL/LnSYZZMrK4rgBkIycNRyIRHFFjrDVebbgrJ61w== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1083:b0:d9a:47ea:69a5 with SMTP id v3-20020a056902108300b00d9a47ea69a5mr50083ybu.1.1697806685440; Fri, 20 Oct 2023 05:58:05 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:44 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-10-edumazet@google.com> Subject: [PATCH net-next 09/13] tcp: add tcp_rtt_tsopt_us() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Before adding usec TS support, add tcp_rtt_tsopt_us() helper to factorize code. Signed-off-by: Eric Dumazet --- net/ipv4/tcp_input.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e7e38fc1d62ff16d7afd7f2ba58a1990f01e17b6..5666f61371678ce1c7bf466e0d54c0b7a396841b 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -693,6 +693,21 @@ static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp) tp->rcv_rtt_est.time = tp->tcp_mstamp; } +static s32 tcp_rtt_tsopt_us(const struct tcp_sock *tp) +{ + u32 delta, delta_us; + + delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; + + if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { + if (!delta) + delta = 1; + delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ); + return delta_us; + } + return -1; +} + static inline void tcp_rcv_rtt_measure_ts(struct sock *sk, const struct sk_buff *skb) { @@ -704,15 +719,10 @@ static inline void tcp_rcv_rtt_measure_ts(struct sock *sk, if (TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq >= inet_csk(sk)->icsk_ack.rcv_mss) { - u32 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; - u32 delta_us; - - if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { - if (!delta) - delta = 1; - delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ); - tcp_rcv_rtt_update(tp, delta_us, 0); - } + s32 delta = tcp_rtt_tsopt_us(tp); + + if (delta >= 0) + tcp_rcv_rtt_update(tp, delta, 0); } } @@ -3146,17 +3156,10 @@ static bool tcp_ack_update_rtt(struct sock *sk, const int flag, * left edge of the send window. * See draft-ietf-tcplw-high-performance-00, section 3.3. */ - if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && - flag & FLAG_ACKED) { - u32 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; - - if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { - if (!delta) - delta = 1; - seq_rtt_us = delta * (USEC_PER_SEC / TCP_TS_HZ); - ca_rtt_us = seq_rtt_us; - } - } + if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp && + tp->rx_opt.rcv_tsecr && flag & FLAG_ACKED) + seq_rtt_us = ca_rtt_us = tcp_rtt_tsopt_us(tp); + rs->rtt_us = ca_rtt_us; /* RTT of last (S)ACKed packet (or -1) */ if (seq_rtt_us < 0) return false; From patchwork Fri Oct 20 12:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430666 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A607F1C6A0 for ; Fri, 20 Oct 2023 12:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i3DrCm2J" Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98414D60 for ; Fri, 20 Oct 2023 05:58:07 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9c4ae201e0so663612276.1 for ; Fri, 20 Oct 2023 05:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806687; x=1698411487; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hPzcKzNKeRtADYBalFzrHOn+FGjL6+SKDGFbdLmUVao=; b=i3DrCm2JOkOl0gtkhdoUpP1m7j0yw5sU7khEbEeVk3y3xbk/Ucw6xuXn0hH8UbisHO K4ZhypsTOPd3LBwXa2zopyW2zbhjoxhA6xRCX9sh1Vtjxnf4mwtDM1GzUkB17JYCHV4D g2RUHssAQYkSOZOyAoc/Vp4viUu8by7BTtmY3YsnZ6JRtNrvUepOycVcCQE/bqywW3Ki hWN5uc4iDOYwWz9DhC/9RhywDbccIkYroqAfV9SAF6lE9WdG3i9rsUa3gWKy7atp7xtn ko2qyGWGZgVHzPwYysl1JUxrIUejtbdv8uzGu8UM4pdav2v5W6Qxv401V8BOwZ9Z8Aa5 sT2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806687; x=1698411487; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hPzcKzNKeRtADYBalFzrHOn+FGjL6+SKDGFbdLmUVao=; b=sxQXu37Rq0ZfQHYMGJBZC5R3JXdZUfkhqMhNmYPLVg3GMDmsLQSSkXbqmXjvUDdTVU N4qZKuzoGsMctnELRrt5mtX54fA9rnbuLCA+SCW1aRtosHzP76KqBKvyTadeMA+tbulB yzWlskO5hV52FBzOsY/RgOrzRU1MCjDl154ywZruyLOwcCLCgccHmVNQm0E+sBVaZk8U wmc/2orVCO8gWzXNDwd/b6wJ/tFPz4h6srFcZEZQpWPZ2Mt7oXrNmZ0BaJjamupvl+yV +SbaCOMkX38YzeLlaOATMfRSp2QGuKGrfkX4kaRp7H1Qbx6SeYae9o4Znr+ZzKvG2yi+ iAMw== X-Gm-Message-State: AOJu0YyTzV3i+3hVmCJoF8cIcvzBWI068xoWyppBmrrSbWmS+++3XL8k WY4RVFdwkmNUb7ULfIPuNdZgdiJQO8Db0g== X-Google-Smtp-Source: AGHT+IGTNlhV33w2QK6cB7va6YLxcKPSiH8SvXYqYJT6KbMokk/cci6UoxWTyo7RT1AlAWSRi9J+eLNwLs/QJw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:34d1:0:b0:d9a:6360:485b with SMTP id b200-20020a2534d1000000b00d9a6360485bmr121530yba.2.1697806686863; Fri, 20 Oct 2023 05:58:06 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:45 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-11-edumazet@google.com> Subject: [PATCH net-next 10/13] tcp: add RTAX_FEATURE_TCP_USEC_TS From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org This new dst feature flag will be used to allow TCP to use usec based timestamps instead of msec ones. ip route .... feature tcp_usec_ts Also document that RTAX_FEATURE_SACK and RTAX_FEATURE_TIMESTAMP are unused. RTAX_FEATURE_ALLFRAG is also going away soon. Signed-off-by: Eric Dumazet --- include/linux/tcp.h | 5 +++++ include/uapi/linux/rtnetlink.h | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index e15452df9804f6d5badddaed3445c5586b1fcea3..04a0e647ef747e5c83520cd1b1c2156d3a315ba5 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -576,4 +576,9 @@ void tcp_sock_set_quickack(struct sock *sk, int val); int tcp_sock_set_syncnt(struct sock *sk, int val); int tcp_sock_set_user_timeout(struct sock *sk, int val); +static inline bool dst_tcp_usec_ts(const struct dst_entry *dst) +{ + return dst_feature(dst, RTAX_FEATURE_TCP_USEC_TS); +} + #endif /* _LINUX_TCP_H */ diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index 51c13cf9c5aee4a2d1ab33c1a89043383d67b9cf..aa2482a0614aa685590fcc73819cbe1baac63d66 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -502,13 +502,17 @@ enum { #define RTAX_MAX (__RTAX_MAX - 1) -#define RTAX_FEATURE_ECN (1 << 0) -#define RTAX_FEATURE_SACK (1 << 1) -#define RTAX_FEATURE_TIMESTAMP (1 << 2) -#define RTAX_FEATURE_ALLFRAG (1 << 3) - -#define RTAX_FEATURE_MASK (RTAX_FEATURE_ECN | RTAX_FEATURE_SACK | \ - RTAX_FEATURE_TIMESTAMP | RTAX_FEATURE_ALLFRAG) +#define RTAX_FEATURE_ECN (1 << 0) +#define RTAX_FEATURE_SACK (1 << 1) /* unused */ +#define RTAX_FEATURE_TIMESTAMP (1 << 2) /* unused */ +#define RTAX_FEATURE_ALLFRAG (1 << 3) +#define RTAX_FEATURE_TCP_USEC_TS (1 << 4) + +#define RTAX_FEATURE_MASK (RTAX_FEATURE_ECN | \ + RTAX_FEATURE_SACK | \ + RTAX_FEATURE_TIMESTAMP | \ + RTAX_FEATURE_ALLFRAG | \ + RTAX_FEATURE_TCP_USEC_TS) struct rta_session { __u8 proto; From patchwork Fri Oct 20 12:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430667 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD7791CF9E for ; Fri, 20 Oct 2023 12:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rH18xUSq" Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 592D19F for ; Fri, 20 Oct 2023 05:58:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a8ead739c3so10382847b3.3 for ; Fri, 20 Oct 2023 05:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806688; x=1698411488; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mLjUl2aLCrBiziD+kk4oN1wvnlfj1PdIazDKJ7fmS4k=; b=rH18xUSqTCqCeATyO5XxCtTVlepQIixFmpw0fnqmmhgzqeUoTBmrvepstpsKwZsYIf RAoLVycBIEH8iJVo8R9tqFbFE1g0P9nAlY8s5tXOhGHYgKZCX0BEVIe/biNfAzNtOVZ5 YpBKou1b82vaXQVwG/bI3CD9ztKfCobiNL2ZB/p+iPTRnw72Li3+8Jfd9v0wqnOlFFNS BPF0BceWNOxSjrjJ8Xy020HFkUvgOweCDOcXxbhLcVvUpbq96mKCk9XKsumU0KCS6uih CQAHrRcqFt8N8QyjBD4LYhiQEjL32YRxN9dlvJz40bRVGV3UCZQz6/H0tpPAm3pamkJz NYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806688; x=1698411488; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mLjUl2aLCrBiziD+kk4oN1wvnlfj1PdIazDKJ7fmS4k=; b=xTk41K4yyS9YqYoNn6oYsyfQhw3vxFpWLlyOYow9VJyR++oCvc1uNaKljApAYThnv7 A1Qq9y/iCt+aImL+/FDVJk8UtB5nH8ZItjOKZT0bj/m/oqfNEyD+o3NNaO3O6XCMj/Jj 45hvc5xH2zmtJbgGpiMDmPN3zbatbpNgR+TxoeBnBZBHkWQuL/DTEvr4ynvZ/35oZ6pl rz2S03MXeJFjL+sgobc7cv0upv16VWB5kRv8Yar6lNGI3UnaXP9gIe4/puBBHekK5OCE jsn4E9IU9WYwx4hEBEClYITWUq9dfe6TqcpsbADDq51U9PNNeyLuYVr/DipAg/lvT8yT eBpA== X-Gm-Message-State: AOJu0Yw8YM9AsJ+w1FxTeGLTdOlOgLYFQj/LJCfcU/jt5wqPLEmbxCtm c0glrkqobtydiRqlxrsfRb5D2h+E0Prucg== X-Google-Smtp-Source: AGHT+IHwTN+xExcqGxom4btXgP/Q3udX3wplmnVefAwlEWDoTbSqZTiv162iIYjgJHBM0PgoA7H7LupPox2KPg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:dd02:0:b0:579:f832:74b with SMTP id g2-20020a0ddd02000000b00579f832074bmr41771ywe.10.1697806688543; Fri, 20 Oct 2023 05:58:08 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:46 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-12-edumazet@google.com> Subject: [PATCH net-next 11/13] tcp: introduce TCP_PAWS_WRAP From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org tcp_paws_check() uses TCP_PAWS_24DAYS constant to detect if TCP TS values might have wrapped after a long idle period. This mechanism is described in RFC 7323 5.5 (Outdated Timestamps) TCP_PAWS_24DAYS value was based on the assumption of a clock of 1 Khz. As we want to adopt a 1 Mhz clock in the future, we reduce this constant. Signed-off-by: Eric Dumazet --- include/net/tcp.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index af72c1dc37f3dd4cd6858e9c8f6aa7ef31541652..0ab577869d7ac61c5c3b687e98068a16b69bb3af 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -166,7 +166,12 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX); #define MAX_TCP_KEEPCNT 127 #define MAX_TCP_SYNCNT 127 -#define TCP_PAWS_24DAYS (60 * 60 * 24 * 24) +/* Ensure that TCP PAWS checks are relaxed after ~2147 seconds + * to avoid overflows. This assumes a clock smaller than 1 Mhz. + * Default clock is 1 Khz, tcp_usec_ts uses 1 Mhz. + */ +#define TCP_PAWS_WRAP (INT_MAX / USEC_PER_SEC) + #define TCP_PAWS_MSL 60 /* Per-host timestamps are invalidated * after this time. It should be equal * (or greater than) TCP_TIMEWAIT_LEN @@ -1619,7 +1624,7 @@ static inline bool tcp_paws_check(const struct tcp_options_received *rx_opt, if ((s32)(rx_opt->ts_recent - rx_opt->rcv_tsval) <= paws_win) return true; if (unlikely(!time_before32(ktime_get_seconds(), - rx_opt->ts_recent_stamp + TCP_PAWS_24DAYS))) + rx_opt->ts_recent_stamp + TCP_PAWS_WRAP))) return true; /* * Some OSes send SYN and SYNACK messages with tsval=0 tsecr=0, From patchwork Fri Oct 20 12:57:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430669 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1A9F1CFA6 for ; Fri, 20 Oct 2023 12:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KS+JcXwz" Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEE8FD52 for ; Fri, 20 Oct 2023 05:58:10 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d86dac81f8fso1040862276.1 for ; Fri, 20 Oct 2023 05:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806690; x=1698411490; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QiZy2MDzl8F3JktwSR5t+fl55CZZReZ2QqUWVgjfgzA=; b=KS+JcXwzTKK2/IvLt9dwdJIpVEP+0ONphimwksQLkdnFFcG2lCK2O6OSvmeozeEUTt FjkuJWLKHgzcBhwEHd3hj2R0gZ2hbgccG4BF2u4fU+7hkUZMeCoP0n+YF6hIkIPWH4sq y840ONLRQY9+oSNjxc9P18x1eesNpyvts3q6jo2rwDdefeew8Zg9gPFrbAMMSJGxASMB A1wtvXUe3u+DJXSM49YFQtps2TvgBoR3PnG+JcG+aGhuMb3mtk5a3TQFH1HBz7e1DKHR 1xvk5ROMgCTOAk8j6pLx+sJa2BfeFmjkSezJ3OBbLTQcaCVAiOFbKQdT+zFxFg77gtnE 2CUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806690; x=1698411490; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QiZy2MDzl8F3JktwSR5t+fl55CZZReZ2QqUWVgjfgzA=; b=qOJgbkRUHU4mt8MeK8usSU0uQF8e+FqID+FMBZ2qh67LBebNDMyydhPemzFgqcht3V JxTgmVdXE1noMGVoZ8XNc3XC9GhLcsYvgADF4mL8uh5Q4nWZ/3z81BRM1Kbgwn2pOsgl JmMlaVk/cS0D7ssZRGsOd29m6x1S5qKNxANudtLnGcnJSdlIVNpGBunn1yFY7kpanbQq HFkLmlTMW87iuj/FNPTJ5OXSwM9iAvJXaSrlQokpVDRHI7derQXxxRk1QD4CZOJoKSdO nDOGwPqyyZKnMAUl/6PmPA1gXWgjlcVXvT+KNw7UumqCT03rMlwPXhScF0pW3nxl6weT B1fA== X-Gm-Message-State: AOJu0YwkEuouOhhoTvYFf4H5x+YDzjnzDkGxQ94/otYGdL6U7/p/pYcN SJywoIVNSqgxBJzX7AJ9p7eVOnNHv1YL+Q== X-Google-Smtp-Source: AGHT+IGNjvzzmQwPvcnZH+roO5HtVV5va3neu3WzLZHMDt+UHcbMXl3+cK7nsorS9vZvqGKMOtGCHg9wnS4X1A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:bccc:0:b0:d9a:c218:8177 with SMTP id l12-20020a25bccc000000b00d9ac2188177mr40653ybm.8.1697806690149; Fri, 20 Oct 2023 05:58:10 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:47 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-13-edumazet@google.com> Subject: [PATCH net-next 12/13] tcp: add support for usec resolution in TCP TS values From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Back in 2015, Van Jacobson suggested to use usec resolution in TCP TS values. This has been implemented in our private kernels. Goals were : 1) better observability of delays in networking stacks. 2) better disambiguation of events based on TSval/ecr values. 3) building block for congestion control modules needing usec resolution. Back then we implemented a schem based on private SYN options to negotiate the feature. For upstream submission, we chose to use a route attribute, because this feature is probably going to be used in private networks [1] [2]. ip route add 10/8 ... features tcp_usec_ts Note that RFC 7323 recommends a "timestamp clock frequency in the range 1 ms to 1 sec per tick.", but also mentions "the maximum acceptable clock frequency is one tick every 59 ns." [1] Unfortunately RFC 7323 5.5 (Outdated Timestamps) suggests to invalidate TS.Recent values after a flow was idle for more than 24 days. This is the part making usec_ts a problem for peers following this recommendation for long living idle flows. [2] Attempts to standardize usec ts went nowhere: https://www.ietf.org/proceedings/97/slides/slides-97-tcpm-tcp-options-for-low-latency-00.pdf https://datatracker.ietf.org/doc/draft-wang-tcpm-low-latency-opt/ Signed-off-by: Eric Dumazet --- include/linux/tcp.h | 4 +++- include/net/inet_timewait_sock.h | 3 ++- include/net/tcp.h | 6 +++-- net/ipv4/syncookies.c | 6 ++++- net/ipv4/tcp.c | 18 ++++++++++---- net/ipv4/tcp_input.c | 5 +++- net/ipv4/tcp_ipv4.c | 1 + net/ipv4/tcp_minisocks.c | 19 +++++++++++---- net/ipv4/tcp_output.c | 12 ++++++---- net/ipv4/tcp_timer.c | 40 +++++++++++++++++++++----------- net/ipv6/tcp_ipv6.c | 1 + 11 files changed, 82 insertions(+), 33 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 04a0e647ef747e5c83520cd1b1c2156d3a315ba5..6df715b6e51d4420d8835146a75d0655e71dea5b 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -152,6 +152,7 @@ struct tcp_request_sock { u64 snt_synack; /* first SYNACK sent time */ bool tfo_listener; bool is_mptcp; + s8 req_usec_ts; #if IS_ENABLED(CONFIG_MPTCP) bool drop_req; #endif @@ -257,7 +258,8 @@ struct tcp_sock { u8 compressed_ack; u8 dup_ack_counter:2, tlp_retrans:1, /* TLP is a retransmission */ - unused:5; + tcp_usec_ts:1, /* TSval values in usec */ + unused:4; u32 chrono_start; /* Start time in jiffies of a TCP chrono */ u32 chrono_stat[3]; /* Time in jiffies for chrono_stat stats */ u8 chrono_type:2, /* current chronograph type */ diff --git a/include/net/inet_timewait_sock.h b/include/net/inet_timewait_sock.h index 4a8e578405cb37856f07dac6ad0f1809f786682a..b14999ff55db1be505f371be48c26ff946062e83 100644 --- a/include/net/inet_timewait_sock.h +++ b/include/net/inet_timewait_sock.h @@ -67,7 +67,8 @@ struct inet_timewait_sock { /* And these are ours. */ unsigned int tw_transparent : 1, tw_flowlabel : 20, - tw_pad : 3, /* 3 bits hole */ + tw_usec_ts : 1, + tw_pad : 2, /* 2 bits hole */ tw_tos : 8; u32 tw_txhash; u32 tw_priority; diff --git a/include/net/tcp.h b/include/net/tcp.h index 0ab577869d7ac61c5c3b687e98068a16b69bb3af..39b731c900dd53fa2683f316fcd779e8e16ec7e2 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -825,6 +825,8 @@ static inline u32 tcp_time_stamp_ms(const struct tcp_sock *tp) static inline u32 tcp_time_stamp_ts(const struct tcp_sock *tp) { + if (tp->tcp_usec_ts) + return tp->tcp_mstamp; return tcp_time_stamp_ms(tp); } @@ -852,12 +854,12 @@ static inline u32 tcp_skb_timestamp_ts(bool usec_ts, const struct sk_buff *skb) static inline u32 tcp_tw_tsval(const struct tcp_timewait_sock *tcptw) { - return tcp_clock_ts(false) + tcptw->tw_ts_offset; + return tcp_clock_ts(tcptw->tw_sk.tw_usec_ts) + tcptw->tw_ts_offset; } static inline u32 tcp_rsk_tsval(const struct tcp_request_sock *treq) { - return tcp_clock_ts(false) + treq->ts_off; + return tcp_clock_ts(treq->req_usec_ts) + treq->ts_off; } #define tcp_flag_byte(th) (((u_int8_t *)th)[13]) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 62395fdb0ca557caee78d84ae70273eb42a837b9..c6433436323096fe0e63f89e889687f74b57e387 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -84,7 +84,9 @@ u64 cookie_init_timestamp(struct request_sock *req, u64 now) if (ts > ts_now) ts -= (1UL << TSBITS); - return ts * (NSEC_PER_SEC / TCP_TS_HZ); + if (tcp_rsk(req)->req_usec_ts) + return ts * NSEC_PER_USEC; + return ts * NSEC_PER_MSEC; } @@ -304,6 +306,8 @@ struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops, treq->af_specific = af_ops; treq->syn_tos = TCP_SKB_CB(skb)->ip_dsfield; + treq->req_usec_ts = -1; + #if IS_ENABLED(CONFIG_MPTCP) treq->is_mptcp = sk_is_mptcp(sk); if (treq->is_mptcp) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 805f8341064fec4fe0504e14c579185cfe11d896..b961364b4961c5f6fada9b2f6828413dfc8307ed 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3629,10 +3629,16 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname, tp->fastopen_no_cookie = val; break; case TCP_TIMESTAMP: - if (!tp->repair) + if (!tp->repair) { err = -EPERM; - else - WRITE_ONCE(tp->tsoffset, val - tcp_clock_ts(false)); + break; + } + /* val is an opaque field, + * and low order bit contains usec_ts enable bit. + * Its a best effort, and we do not care if user makes an error. + */ + tp->tcp_usec_ts = val & 1; + WRITE_ONCE(tp->tsoffset, val - tcp_clock_ts(tp->tcp_usec_ts)); break; case TCP_REPAIR_WINDOW: err = tcp_repair_set_window(tp, optval, optlen); @@ -4143,7 +4149,11 @@ int do_tcp_getsockopt(struct sock *sk, int level, break; case TCP_TIMESTAMP: - val = tcp_clock_ts(false) + READ_ONCE(tp->tsoffset); + val = tcp_clock_ts(tp->tcp_usec_ts) + READ_ONCE(tp->tsoffset); + if (tp->tcp_usec_ts) + val |= 1; + else + val &= ~1; break; case TCP_NOTSENT_LOWAT: val = READ_ONCE(tp->notsent_lowat); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 5666f61371678ce1c7bf466e0d54c0b7a396841b..18b858597af4ef62248f7c759cddf7224a681fc8 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -698,6 +698,8 @@ static s32 tcp_rtt_tsopt_us(const struct tcp_sock *tp) u32 delta, delta_us; delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; + if (tp->tcp_usec_ts) + return delta; if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) { if (!delta) @@ -2452,7 +2454,7 @@ static bool tcp_skb_spurious_retrans(const struct tcp_sock *tp, const struct sk_buff *skb) { return (TCP_SKB_CB(skb)->sacked & TCPCB_RETRANS) && - tcp_tsopt_ecr_before(tp, tcp_skb_timestamp_ts(false, skb)); + tcp_tsopt_ecr_before(tp, tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb)); } /* Nothing was retransmitted or returned timestamp is less @@ -7045,6 +7047,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, req->syncookie = want_cookie; tcp_rsk(req)->af_specific = af_ops; tcp_rsk(req)->ts_off = 0; + tcp_rsk(req)->req_usec_ts = -1; #if IS_ENABLED(CONFIG_MPTCP) tcp_rsk(req)->is_mptcp = 0; #endif diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index cdd65cc594bc4571fa5793bc14d6e9ab892dfd2a..7583d4e34c8c5fedaf29177f458f7aa39ca0519a 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -296,6 +296,7 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) rt = NULL; goto failure; } + tp->tcp_usec_ts = dst_tcp_usec_ts(&rt->dst); /* OK, now commit destination to socket. */ sk->sk_gso_type = SKB_GSO_TCPV4; sk_setup_caps(sk, &rt->dst); diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index a9fdba897a28f3a5835a1bd1426f82de0e81a633..ace806c5bd0cdc2ec79eca5065e125418dd0c5b1 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -300,6 +300,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo) tcptw->tw_ts_recent = tp->rx_opt.ts_recent; tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp; tcptw->tw_ts_offset = tp->tsoffset; + tw->tw_usec_ts = tp->tcp_usec_ts; tcptw->tw_last_oow_ack_time = 0; tcptw->tw_tx_delay = tp->tcp_tx_delay; tw->tw_txhash = sk->sk_txhash; @@ -554,21 +555,29 @@ struct sock *tcp_create_openreq_child(const struct sock *sk, newtp->max_window = newtp->snd_wnd; if (newtp->rx_opt.tstamp_ok) { + newtp->tcp_usec_ts = treq->req_usec_ts; newtp->rx_opt.ts_recent = READ_ONCE(req->ts_recent); newtp->rx_opt.ts_recent_stamp = ktime_get_seconds(); newtp->tcp_header_len = sizeof(struct tcphdr) + TCPOLEN_TSTAMP_ALIGNED; } else { + newtp->tcp_usec_ts = 0; newtp->rx_opt.ts_recent_stamp = 0; newtp->tcp_header_len = sizeof(struct tcphdr); } if (req->num_timeout) { - newtp->undo_marker = treq->snt_isn; - newtp->retrans_stamp = div_u64(treq->snt_synack, - USEC_PER_SEC / TCP_TS_HZ); newtp->total_rto = req->num_timeout; + newtp->undo_marker = treq->snt_isn; + if (newtp->tcp_usec_ts) { + newtp->retrans_stamp = treq->snt_synack; + newtp->total_rto_time = (u32)(tcp_clock_us() - + newtp->retrans_stamp) / USEC_PER_MSEC; + } else { + newtp->retrans_stamp = div_u64(treq->snt_synack, + USEC_PER_SEC / TCP_TS_HZ); + newtp->total_rto_time = tcp_clock_ms() - + newtp->retrans_stamp; + } newtp->total_rto_recoveries = 1; - newtp->total_rto_time = tcp_clock_ms() - - newtp->retrans_stamp; } newtp->tsoffset = treq->ts_off; #ifdef CONFIG_TCP_MD5SIG diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index a1fec8be9ac36c67022c90b08b0a5faa935725f0..2866ccbccde073bff26182a0ad52446e84f789de 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -799,7 +799,7 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb, if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps) && !*md5)) { opts->options |= OPTION_TS; - opts->tsval = tcp_skb_timestamp_ts(false, skb) + tp->tsoffset; + opts->tsval = tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb) + tp->tsoffset; opts->tsecr = tp->rx_opt.ts_recent; remaining -= TCPOLEN_TSTAMP_ALIGNED; } @@ -884,7 +884,8 @@ static unsigned int tcp_synack_options(const struct sock *sk, } if (likely(ireq->tstamp_ok)) { opts->options |= OPTION_TS; - opts->tsval = tcp_skb_timestamp_ts(false, skb) + tcp_rsk(req)->ts_off; + opts->tsval = tcp_skb_timestamp_ts(tcp_rsk(req)->req_usec_ts, skb) + + tcp_rsk(req)->ts_off; opts->tsecr = READ_ONCE(req->ts_recent); remaining -= TCPOLEN_TSTAMP_ALIGNED; } @@ -943,7 +944,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb if (likely(tp->rx_opt.tstamp_ok)) { opts->options |= OPTION_TS; - opts->tsval = skb ? tcp_skb_timestamp_ts(false, skb) + tp->tsoffset : 0; + opts->tsval = skb ? tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb) + + tp->tsoffset : 0; opts->tsecr = tp->rx_opt.ts_recent; size += TCPOLEN_TSTAMP_ALIGNED; } @@ -3379,7 +3381,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) /* Save stamp of the first (attempted) retransmit. */ if (!tp->retrans_stamp) - tp->retrans_stamp = tcp_skb_timestamp_ts(false, skb); + tp->retrans_stamp = tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb); if (tp->undo_retrans < 0) tp->undo_retrans = 0; @@ -3665,6 +3667,8 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst, mss = tcp_mss_clamp(tp, dst_metric_advmss(dst)); memset(&opts, 0, sizeof(opts)); + if (tcp_rsk(req)->req_usec_ts < 0) + tcp_rsk(req)->req_usec_ts = dst_tcp_usec_ts(dst); now = tcp_clock_ns(); #ifdef CONFIG_SYN_COOKIES if (unlikely(synack_type == TCP_SYNACK_COOKIE && ireq->tstamp_ok)) diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index bfcf3fe44c72427eccb37376bec15fb71b594c56..1f9f6c1c196b2de35b0bc2f734484f09ba90541a 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -26,14 +26,18 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); - u32 elapsed, start_ts, user_timeout; + const struct tcp_sock *tp = tcp_sk(sk); + u32 elapsed, user_timeout; s32 remaining; - start_ts = tcp_sk(sk)->retrans_stamp; user_timeout = READ_ONCE(icsk->icsk_user_timeout); if (!user_timeout) return icsk->icsk_rto; - elapsed = tcp_time_stamp_ts(tcp_sk(sk)) - start_ts; + + elapsed = tcp_time_stamp_ts(tp) - tp->retrans_stamp; + if (tp->tcp_usec_ts) + elapsed /= USEC_PER_MSEC; + remaining = user_timeout - elapsed; if (remaining <= 0) return 1; /* user timeout has passed; fire ASAP */ @@ -212,12 +216,13 @@ static bool retransmits_timed_out(struct sock *sk, unsigned int boundary, unsigned int timeout) { - unsigned int start_ts; + struct tcp_sock *tp = tcp_sk(sk); + unsigned int start_ts, delta; if (!inet_csk(sk)->icsk_retransmits) return false; - start_ts = tcp_sk(sk)->retrans_stamp; + start_ts = tp->retrans_stamp; if (likely(timeout == 0)) { unsigned int rto_base = TCP_RTO_MIN; @@ -226,7 +231,12 @@ static bool retransmits_timed_out(struct sock *sk, timeout = tcp_model_timeout(sk, boundary, rto_base); } - return (s32)(tcp_time_stamp_ts(tcp_sk(sk)) - start_ts - timeout) >= 0; + if (tp->tcp_usec_ts) { + /* delta maybe off up to a jiffy due to timer granularity. */ + delta = tp->tcp_mstamp - start_ts + jiffies_to_usecs(1); + return (s32)(delta - timeout * USEC_PER_MSEC) >= 0; + } + return (s32)(tcp_time_stamp_ts(tp) - start_ts - timeout) >= 0; } /* A write timeout has occurred. Process the after effects. */ @@ -468,20 +478,18 @@ static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req) } static bool tcp_rtx_probe0_timed_out(const struct sock *sk, - const struct sk_buff *skb) + const struct sk_buff *skb, + u32 rtx_delta) { const struct tcp_sock *tp = tcp_sk(sk); const int timeout = TCP_RTO_MAX * 2; - u32 rcv_delta, rtx_delta; + u32 rcv_delta; rcv_delta = inet_csk(sk)->icsk_timeout - tp->rcv_tstamp; if (rcv_delta <= timeout) return false; - rtx_delta = (u32)msecs_to_jiffies(tcp_time_stamp_ts(tp) - - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb))); - - return rtx_delta > timeout; + return msecs_to_jiffies(rtx_delta) > timeout; } /** @@ -534,7 +542,11 @@ void tcp_retransmit_timer(struct sock *sk) struct inet_sock *inet = inet_sk(sk); u32 rtx_delta; - rtx_delta = tcp_time_stamp_ts(tp) - (tp->retrans_stamp ?: tcp_skb_timestamp_ts(false, skb)); + rtx_delta = tcp_time_stamp_ts(tp) - (tp->retrans_stamp ?: + tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb)); + if (tp->tcp_usec_ts) + rtx_delta /= USEC_PER_MSEC; + if (sk->sk_family == AF_INET) { net_dbg_ratelimited("Probing zero-window on %pI4:%u/%u, seq=%u:%u, recv %ums ago, lasting %ums\n", &inet->inet_daddr, ntohs(inet->inet_dport), @@ -551,7 +563,7 @@ void tcp_retransmit_timer(struct sock *sk) rtx_delta); } #endif - if (tcp_rtx_probe0_timed_out(sk, skb)) { + if (tcp_rtx_probe0_timed_out(sk, skb, rtx_delta)) { tcp_write_err(sk); goto out; } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 1ee6517e9b2f9d549268dea240a725976a9e2720..0c8a14ba104f29877a17beae0c378313e2b206b3 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -286,6 +286,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, goto failure; } + tp->tcp_usec_ts = dst_tcp_usec_ts(dst); tcp_death_row = &sock_net(sk)->ipv4.tcp_death_row; if (!saddr) { From patchwork Fri Oct 20 12:57:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13430668 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CA681CFBB for ; Fri, 20 Oct 2023 12:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HGWmxMGv" Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 713C19F for ; Fri, 20 Oct 2023 05:58:12 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cad450d5fso976249276.1 for ; Fri, 20 Oct 2023 05:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697806691; x=1698411491; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qAN9QE6I9dE0JsECENUlQr6m9rIHVhfMuyc8Wyi3QCI=; b=HGWmxMGv8o5Ng3JlehD80Ewp3o+gAA6vXe0mCOWdukiJt0Vcd41/luKoeTnar+YK4K Pt9UqJjuoariOy/7sNTCEwKW4RNYt8PKR/eqXjoZFVxU2chsA08SbOWGy3Fm13J7nsNp wqvD39m2lwtXxIHlDaOV+pQdKS62ESc9GCNoP1u+qlFlIGyPW3K/cKANGs24jO1TENXu r9lTiDFvTFyyGTt4x9EneAfvhaRyA5kJNr4QA1lrbLr706u2U2cZMk78M/tpQdn3f5uX SEIb4sAlCxpV5QQ6Y0t75FyxEYzWhzPLer4BFYqGvoXNifdl7aBxxis4Cj8a5/sDA2Fq z8bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697806691; x=1698411491; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qAN9QE6I9dE0JsECENUlQr6m9rIHVhfMuyc8Wyi3QCI=; b=Q8USRxFMHZJcp6i7HZBBaRq/ZVAd00/6GegQQ2yGrjQYTP6nm2aGBJEIrnVDeULUDz KGb0DpLYyWUiCW4UeaSAxJ0gb0BlLVP0GUVltrBOZUshuCVpG2Tu5I98a93ITzdX778Q tL8pAVfM4IruFqSFT2jmjBLis2dT5EnhZldLwPxxhTdctIp3MuSt+CJ8/l0CkjHz/nUz xfQYr2hUv+UF1FuDLdXQbquLhH7XS2qcJoeCT1NuG4zY47/lAdAAJzP7I9D1Lb+8V6aI JGetrElqe7PX9pf94xIB9E6k7TH0pD1cgHbHNSQ+2e+X4M5H60cul3YIi9OYZmm+CZUg G1lg== X-Gm-Message-State: AOJu0Yx3QX9HKPomuwFtILVbxlBNdc6H3hF8/RJGAbVUTM/LffGPWk7f 6qYYiI4Z66LcfvdTzyeDtGT9xFA9UPbnVg== X-Google-Smtp-Source: AGHT+IF4IML+MEWvkv9PmP1gjYo0wQdFABbJgfn4tE10HAfH0pUHCXEIPe6OvU6wllvAAswel+824UqZFOYvVg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:d34e:0:b0:d9a:e3d9:99bd with SMTP id e75-20020a25d34e000000b00d9ae3d999bdmr31309ybf.5.1697806691721; Fri, 20 Oct 2023 05:58:11 -0700 (PDT) Date: Fri, 20 Oct 2023 12:57:48 +0000 In-Reply-To: <20231020125748.122792-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231020125748.122792-1-edumazet@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231020125748.122792-14-edumazet@google.com> Subject: [PATCH net-next 13/13] tcp: add TCPI_OPT_USEC_TS From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Neal Cardwell , Yuchung Cheng , Kevin Yang , Soheil Hassas Yeganeh , Wei Wang , Van Jacobson , Florian Westphal , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Add the ability to report in tcp_info.tcpi_options if a flow is using usec resolution in TCP TS val. Signed-off-by: Eric Dumazet --- include/uapi/linux/tcp.h | 1 + net/ipv4/tcp.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h index d1d08da6331ab5e1f07baacd7057c7a2207229e6..8aa3916e14f6d09322a2a7e90402129d2aaa40b8 100644 --- a/include/uapi/linux/tcp.h +++ b/include/uapi/linux/tcp.h @@ -170,6 +170,7 @@ enum tcp_fastopen_client_fail { #define TCPI_OPT_ECN 8 /* ECN was negociated at TCP session init */ #define TCPI_OPT_ECN_SEEN 16 /* we received at least one packet with ECT */ #define TCPI_OPT_SYN_DATA 32 /* SYN-ACK acked data in SYN sent or rcvd */ +#define TCPI_OPT_USEC_TS 64 /* usec timestamps */ /* * Sender's congestion state indicating normal or abnormal situations diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index b961364b4961c5f6fada9b2f6828413dfc8307ed..a86d8200a1e861b7c1292f480013c97eea141126 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3760,6 +3760,8 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) info->tcpi_options |= TCPI_OPT_ECN_SEEN; if (tp->syn_data_acked) info->tcpi_options |= TCPI_OPT_SYN_DATA; + if (tp->tcp_usec_ts) + info->tcpi_options |= TCPI_OPT_USEC_TS; info->tcpi_rto = jiffies_to_usecs(icsk->icsk_rto); info->tcpi_ato = jiffies_to_usecs(min_t(u32, icsk->icsk_ack.ato,