From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NUPsZtNj; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 957935A004C for ; Wed, 23 Oct 2024 09:41:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729669312; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8y7C1ci5IO17U0oy44FskwFIWhvwsp6q5o+YjCkokks=; b=NUPsZtNjvCl6L0GE8uHAd/QZ5rgurE0wKtwZmR3gZGBUOLu+NeoCcFz6mkP+sjmhLNQK1P 4Cx0ykuEs3EVyhaqKwRtXTQZ7dc/UM4hV+lJdRnEcwoWQcIKBjL8O6jdpHACHKYNU5Sflf Lmw73f0rjwLjLclsx+uW3JzlQJXtxJE= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-154-0OQQ0QlyMRS1j59736DyDg-1; Wed, 23 Oct 2024 03:41:48 -0400 X-MC-Unique: 0OQQ0QlyMRS1j59736DyDg-1 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-20c748ad236so71123065ad.3 for ; Wed, 23 Oct 2024 00:41:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729669307; x=1730274107; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8y7C1ci5IO17U0oy44FskwFIWhvwsp6q5o+YjCkokks=; b=oRbmRWGu3g/freWqQKfbVbYRpBD4T9fkXLjSuHkU8A9n+N06UamIsgQJGfwXO22vRS LzOoyLO24Heyu2tWS5xMpIYfhTEKZMabnBpEivvDfYU3GMpTxes9awSJnA1e7YB4m4si SW/GByDN55AlcRLkf59hUDBGET8dSXfLEMYtEB/rjzVNhc8Fzrob3W/KnPrmiuwRO64j FsA7iOjsV1W9H9G0ZUuHb2DKDi4hzlTqdU6XXqgL8LMWw8d19jmYRv97WH1oe4q1ESHc nmViNBZWgmTuSWV/eVb9LbGUA6FOJLV/BfjHOy6QlJaxT860iJR5HOUOHRV9t1fcxTPA nGTQ== X-Gm-Message-State: AOJu0YylwFh7eW7PHWJQNwTE+O1wh3fSw8JGM7kfUe5xq/faDofhc+zR kLwW3kmd3hVtq+Q6YxoHgDucoVbzXXxnY0UPM4+1MA9D5KDEhmajVo7prERGATPQ/1B7ctNaF42 veRNKwc6eWGFmcrkbKkVP06k1eyDSw6+sRea0WjBX39uSCjz3Nw== X-Received: by 2002:a17:902:f547:b0:20c:dc32:b5d0 with SMTP id d9443c01a7336-20fab2fe237mr21068905ad.58.1729669306498; Wed, 23 Oct 2024 00:41:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwGwWYsl3aJ2JzMVTK+wpha2xVb0cY0Xxd6TkjWZK9aEp5H07K0cdB5U6XNfYu2D+Gck5MkQ== X-Received: by 2002:a17:902:f547:b0:20c:dc32:b5d0 with SMTP id d9443c01a7336-20fab2fe237mr21068665ad.58.1729669305851; Wed, 23 Oct 2024 00:41:45 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7ef0d671sm52699675ad.98.2024.10.23.00.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 00:41:45 -0700 (PDT) Date: Wed, 23 Oct 2024 09:41:39 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/2] tcp: Use runtime tests for TCP_INFO fields Message-ID: <20241023094139.4e94b322@elisabeth> In-Reply-To: <20241023004253.1729124-3-david@gibson.dropbear.id.au> References: <20241023004253.1729124-1-david@gibson.dropbear.id.au> <20241023004253.1729124-3-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6LGW73AJHUNBRFC6OHMI4ATTINLH6CVD X-Message-ID-Hash: 6LGW73AJHUNBRFC6OHMI4ATTINLH6CVD X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Wed, 23 Oct 2024 11:42:53 +1100 David Gibson wrote: > In order to use particular fields from the TCP_INFO getsockopt() we > need them to be in the version of the structure we have defined. We > test this in the Makefile, setting HAS_BYTES_ACKED and HAS_MIN_RTT > accordingly. > > However, we also need the fields to be present in the runtime kernel > we're using, which we don't currently check for those fields. Add > logic similar to that for tcpi_snd_wnd to check for these fields too > instead of just using the compile time check. > > Signed-off-by: David Gibson > --- > tcp.c | 65 +++++++++++++++++++++++++++++++++++------------------------ > 1 file changed, 39 insertions(+), 26 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 3cca5c6..b5ef1f1 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -380,6 +380,19 @@ socklen_t tcp_info_size; > #else > #define snd_wnd_cap (false) > #endif > +#ifdef HAS_BYTES_ACKED > +/* Does the kernel report bytes acked in TCP_INFO (kernel commit 0df48c26d84) */ > +#define bytes_acked_cap tcp_info_cap(bytes_acked) > +#else > +#define bytes_acked_cap (false) > +#endif > +#ifdef HAS_MIN_RTT > +/* Does the kernel report minimum RTT TCP_INFO (kernel commit cd9b266095f4) */ Nit: "in TCP_INFO". This becomes too long, but perhaps: /* Kernel reports minimum RTT in TCP_INFO (kernel commit cd9b266095f4) */ (and similar above) is just as informative. > +#define min_rtt_cap tcp_info_cap(min_rtt) > +#else > +#define min_rtt_cap (false) > +#endif > + > > /* sendmsg() to socket */ > static struct iovec tcp_iov [UIO_MAXIOV]; > @@ -687,11 +700,10 @@ static int tcp_rtt_dst_low(const struct tcp_tap_conn *conn) > static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn, > const struct tcp_info *tinfo) > { > -#ifdef HAS_MIN_RTT I think we should keep those conditionals as well, because if tcpi_min_rtt is not defined in the headers: > const struct flowside *tapside = TAPFLOW(conn); > int i, hole = -1; > > - if (!tinfo->tcpi_min_rtt || > + if (!min_rtt_cap || > (int)tinfo->tcpi_min_rtt > LOW_RTT_THRESHOLD) ...this won't build. > return; > > @@ -712,10 +724,6 @@ static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn, > if (hole == LOW_RTT_TABLE_SIZE) > hole = 0; > inany_from_af(low_rtt_dst + hole, AF_INET6, &in6addr_any); > -#else > - (void)conn; > - (void)tinfo; > -#endif /* HAS_MIN_RTT */ > } > > /** > @@ -1131,30 +1139,29 @@ int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, > uint32_t new_wnd_to_tap = prev_wnd_to_tap; > int s = conn->sock; > > -#ifndef HAS_BYTES_ACKED Same here: > - (void)force_seq; > - > - conn->seq_ack_to_tap = conn->seq_from_tap; > - if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap)) > - conn->seq_ack_to_tap = prev_ack_to_tap; > -#else > - if ((unsigned)SNDBUF_GET(conn) < SNDBUF_SMALL || tcp_rtt_dst_low(conn) > - || CONN_IS_CLOSING(conn) || (conn->flags & LOCAL) || force_seq) { > + if (!bytes_acked_cap) { > conn->seq_ack_to_tap = conn->seq_from_tap; > - } else if (conn->seq_ack_to_tap != conn->seq_from_tap) { > - if (!tinfo) { > - tinfo = &tinfo_new; > - if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) > - return 0; > - } > - > - conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked + > - conn->seq_init_from_tap; > - > if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap)) > conn->seq_ack_to_tap = prev_ack_to_tap; > + } else { > + if ((unsigned)SNDBUF_GET(conn) < SNDBUF_SMALL || > + tcp_rtt_dst_low(conn) || CONN_IS_CLOSING(conn) || > + (conn->flags & LOCAL) || force_seq) { > + conn->seq_ack_to_tap = conn->seq_from_tap; > + } else if (conn->seq_ack_to_tap != conn->seq_from_tap) { > + if (!tinfo) { > + tinfo = &tinfo_new; > + if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) > + return 0; > + } > + > + conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked + ...this won't build. > + conn->seq_init_from_tap; > + > + if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap)) > + conn->seq_ack_to_tap = prev_ack_to_tap; > + } > } > -#endif /* !HAS_BYTES_ACKED */ > > if (!snd_wnd_cap) { > tcp_get_sndbuf(conn); > @@ -2653,6 +2660,12 @@ int tcp_init(struct ctx *c) > #ifdef HAS_SND_WND > dbg_tcpi(snd_wnd); > #endif > +#ifdef HAS_BYTES_ACKED > + dbg_tcpi(bytes_acked); > +#endif > +#ifdef HAS_MIN_RTT > + dbg_tcpi(min_rtt); > +#endif > #undef dbg_tcpi > > return 0; Everything else looks good to me. -- Stefano