From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 08/32] tcp: Add connection union type
Date: Sat, 19 Nov 2022 09:39:38 +0100 [thread overview]
Message-ID: <20221119093938.4b5b4b73@elisabeth> (raw)
In-Reply-To: <Y3bblx6HAv6B5aAQ@yekko>
On Fri, 18 Nov 2022 12:10:47 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:
> On Fri, Nov 18, 2022 at 01:25:18AM +0100, Stefano Brivio wrote:
> >
> > [...]
> >
> > It also confuses Coverity Scan, because in tcp_table_compact() we have:
> >
> > memset(hole, 0, sizeof(*hole));
> >
> > and while the prototype is:
> >
> > void tcp_table_compact(struct ctx *c, union tcp_conn *hole)
> >
> > it sees that we're passing, from tcp_splice_destroy(), something
> > smaller than that (48 bytes), but we're zeroing the whole thing.
>
> Bother.
>
> > Of course, it's not a real issue, that space is reserved for a
> > connection slot anyway, but given there are no other issues reported,
> > I'd try to keep Coverity happy if possible.
> >
> > First try, failed: check hole->c.spliced and, if set, zero only
> > sizeof(struct tcp_splice_conn) bytes. This looks like a false
> > positive.
> >
> > Another try, which should probably work (I just hit the daily build
> > submission quota, grr): explicitly pass the union tcp_conn containing
> > our struct tcp_splice_conn. This patch does it:
> >
> > ---
> > diff --git a/tcp.c b/tcp.c
> > index 8874789..d635a8e 100644
> > --- a/tcp.c
> > +++ b/tcp.c
> > @@ -591,7 +591,7 @@ static size_t tcp6_l2_flags_buf_bytes;
> > union tcp_conn tc[TCP_MAX_CONNS];
> >
> > #define CONN(index) (&tc[(index)].tap)
> > -#define CONN_IDX(conn) ((union tcp_conn *)(conn) - tc)
> > +#define CONN_IDX(conn) (TCP_TAP_TO_COMMON(conn) - tc)
> >
> > /** conn_at_idx() - Find a connection by index, if present
> > * @index: Index of connection to lookup
> > @@ -1385,7 +1385,7 @@ static void tcp_conn_destroy(struct ctx *c, struct tcp_tap_conn *conn)
> > close(conn->timer);
> >
> > tcp_hash_remove(c, conn);
> > - tcp_table_compact(c, (union tcp_conn *)conn);
> > + tcp_table_compact(c, TCP_TAP_TO_COMMON(conn));
> > }
> >
> > static void tcp_rst_do(struct ctx *c, struct tcp_tap_conn *conn);
> > diff --git a/tcp_conn.h b/tcp_conn.h
> > index 4a8be29..fa407ad 100644
> > --- a/tcp_conn.h
> > +++ b/tcp_conn.h
> > @@ -176,6 +176,12 @@ union tcp_conn {
> > struct tcp_splice_conn splice;
> > };
> >
> > +#define TCP_TAP_TO_COMMON(x) \
> > + ((union tcp_conn *)((char *)(x) - offsetof(union tcp_conn, tap)))
> > +
> > +#define TCP_SPLICE_TO_COMMON(x) \
> > + ((union tcp_conn *)((char *)(x) - offsetof(union tcp_conn, splice)))
> > +
> > /* TCP connections */
> > extern union tcp_conn tc[];
> >
> > diff --git a/tcp_splice.c b/tcp_splice.c
> > index e2f0ce1..7d3f17e 100644
> > --- a/tcp_splice.c
> > +++ b/tcp_splice.c
> > @@ -37,6 +37,7 @@
> > #include <limits.h>
> > #include <stdint.h>
> > #include <stdbool.h>
> > +#include <stddef.h>
> > #include <string.h>
> > #include <time.h>
> > #include <unistd.h>
> > @@ -74,7 +75,7 @@ static int splice_pipe_pool [TCP_SPLICE_PIPE_POOL_SIZE][2][2];
> > #define CONN_V4(x) (!CONN_V6(x))
> > #define CONN_HAS(conn, set) ((conn->events & (set)) == (set))
> > #define CONN(index) (&tc[(index)].splice)
> > -#define CONN_IDX(conn) ((union tcp_conn *)(conn) - tc)
> > +#define CONN_IDX(conn) (TCP_SPLICE_TO_COMMON(conn) - tc)
> >
> > /* Display strings for connection events */
> > static const char *tcp_splice_event_str[] __attribute((__unused__)) = {
> > @@ -283,7 +284,7 @@ void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn)
> > debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn));
> >
> > c->tcp.splice_conn_count--;
> > - tcp_table_compact(c, (union tcp_conn *)conn);
> > + tcp_table_compact(c, TCP_SPLICE_TO_COMMON(conn));
> > }
>
> Hmm.. so TAP_TO_COMMON and SPLICE_TO_COMMON don't actually change the
> pointer any more than the cast does, but you're hoping that will be
> enough to convince coverity? I'm a bit skeptical, but I guess we can
> try it.
Right, that didn't actually work.
> I wonder if an explicit coverity lint override might be a better
> option here. Or, we could add padding to tcp_splice_conn so it has
> the same size as tcp_tap_conn. I think that would probably convince
> coverity.
Padding needs to be calculated manually, and a specific override might
need some specific maintenance, with references to proprietary code.
I'm not really fond of either.
Given that we already have the pointers to the container union in the
callers, we could just pass those instead, and then in splice or "tap"
specific logic, and just there, use struct tcp_{tap,splice}_conn. I
just posted a patch doing this.
--
Stefano
next prev parent reply other threads:[~2022-11-19 8:39 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-17 5:58 [PATCH v2 00/32] Use dual stack sockets to listen for inbound TCP connections David Gibson
2022-11-17 5:58 ` [PATCH v2 01/32] clang-tidy: Suppress warning about assignments in if statements David Gibson
2022-11-17 5:58 ` [PATCH v2 02/32] style: Minor corrections to function comments David Gibson
2022-11-17 5:58 ` [PATCH v2 03/32] tcp_splice: #include tcp_splice.h in tcp_splice.c David Gibson
2022-11-17 5:58 ` [PATCH v2 04/32] tcp: Remove unused TCP_MAX_SOCKS constant David Gibson
2022-11-17 5:58 ` [PATCH v2 05/32] tcp: Better helpers for converting between connection pointer and index David Gibson
2022-11-17 5:58 ` [PATCH v2 06/32] tcp_splice: Helpers for converting from index to/from tcp_splice_conn David Gibson
2022-11-17 5:58 ` [PATCH v2 07/32] tcp: Move connection state structures into a shared header David Gibson
2022-11-17 5:58 ` [PATCH v2 08/32] tcp: Add connection union type David Gibson
2022-11-18 0:25 ` Stefano Brivio
2022-11-18 1:10 ` David Gibson
2022-11-19 8:39 ` Stefano Brivio [this message]
2022-11-17 5:58 ` [PATCH v2 09/32] tcp: Improved helpers to update connections after moving David Gibson
2022-11-17 5:58 ` [PATCH v2 10/32] tcp: Unify spliced and non-spliced connection tables David Gibson
2022-11-17 5:58 ` [PATCH v2 11/32] tcp: Unify tcp_defer_handler and tcp_splice_defer_handler() David Gibson
2022-11-17 5:58 ` [PATCH v2 12/32] tcp: Partially unify tcp_timer() and tcp_splice_timer() David Gibson
2022-11-17 5:58 ` [PATCH v2 13/32] tcp: Unify the IN_EPOLL flag David Gibson
2022-11-17 5:58 ` [PATCH v2 14/32] tcp: Separate helpers to create ns listening sockets David Gibson
2022-11-17 5:58 ` [PATCH v2 15/32] tcp: Unify part of spliced and non-spliced conn_from_sock path David Gibson
2022-11-17 5:58 ` [PATCH v2 16/32] tcp: Use the same sockets to listen for spliced and non-spliced connections David Gibson
2022-11-17 5:58 ` [PATCH v2 17/32] tcp: Remove splice from tcp_epoll_ref David Gibson
2022-11-17 5:58 ` [PATCH v2 18/32] tcp: Don't store hash bucket in connection structures David Gibson
2022-11-17 5:58 ` [PATCH v2 19/32] inany: Helper functions for handling addresses which could be IPv4 or IPv6 David Gibson
2022-11-17 5:58 ` [PATCH v2 20/32] tcp: Hash IPv4 and IPv4-mapped-IPv6 addresses the same David Gibson
2022-11-17 5:58 ` [PATCH v2 21/32] tcp: Take tcp_hash_insert() address from struct tcp_conn David Gibson
2022-11-17 5:58 ` [PATCH v2 22/32] tcp: Simplify tcp_hash_match() to take an inany_addr David Gibson
2022-11-17 5:58 ` [PATCH v2 23/32] tcp: Unify initial sequence number calculation for IPv4 and IPv6 David Gibson
2022-11-17 5:59 ` [PATCH v2 24/32] tcp: Have tcp_seq_init() take its parameters from struct tcp_conn David Gibson
2022-11-17 5:59 ` [PATCH v2 25/32] tcp: Fix small errors in tcp_seq_init() time handling David Gibson
2022-11-17 5:59 ` [PATCH v2 26/32] tcp: Remove v6 flag from tcp_epoll_ref David Gibson
2022-11-17 5:59 ` [PATCH v2 27/32] tcp: NAT IPv4-mapped IPv6 addresses like IPv4 addresses David Gibson
2022-11-17 5:59 ` [PATCH v2 28/32] tcp_splice: Allow splicing of connections from IPv4-mapped loopback David Gibson
2022-11-17 5:59 ` [PATCH v2 29/32] tcp: Consolidate tcp_sock_init[46] David Gibson
2022-11-17 5:59 ` [PATCH v2 30/32] util: Allow sock_l4() to open dual stack sockets David Gibson
2022-11-17 5:59 ` [PATCH v2 31/32] util: Always return -1 on error in sock_l4() David Gibson
2022-11-17 5:59 ` [PATCH v2 32/32] tcp: Use dual stack sockets for port forwarding when possible David Gibson
2022-11-25 9:22 ` [PATCH v2 00/32] Use dual stack sockets to listen for inbound TCP connections Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221119093938.4b5b4b73@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).