From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id EAA6A5A02C8 for ; Tue, 30 Apr 2024 20:48:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714502905; 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=j1sv8QOpJq+42qEqt56ZAWufVpETErLwAhs90/5FwuM=; b=ap0BRi7aeuaqB1KWPHKinIF9hw9jQOvup+r5edTTTfcoBuqJHWneJagMMKDhoID1NefaDp EB9gAduYasgUvQbkLYdd1qodjp1xYilYZXq/tGXGChywEIWlIi+juBcazVeS1ss9GofDBc iOB25A/iyzT9ReYnHF/psgK66Ir/rVI= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-mqSzZpasPpeWprOHlgsh7A-1; Tue, 30 Apr 2024 14:48:23 -0400 X-MC-Unique: mqSzZpasPpeWprOHlgsh7A-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a590fa4a117so110715966b.1 for ; Tue, 30 Apr 2024 11:48:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714502902; x=1715107702; 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=j1sv8QOpJq+42qEqt56ZAWufVpETErLwAhs90/5FwuM=; b=Hd5if6R3/sxpxotiVEOOuzYMFkye7XEPidUU1a2jOIrfU/Hb1VFqGqV4Bq7wM4haaG UMMn7KnEIiiCORZ21jeZtSScU8QiieOoyaudOt5dI6aX22Q/h+13r3XhVIiKBQ65HwLR 4+HOsTYmdAgj1CfY/YBdCcv+oi1pokNjZpmtodyJSDDE95OdhVdeTxqQSjACN/PMILIy qVyhu+B65nJzEUYH8dB22t5XugV+3hVRZyaEfg26/2MzhPor7NmnMSBttfPbPj9bgeIQ jwOuh8gr48j7oHVJdwV26KgXbIF/YRl76BA5hno+NY2LXYJzip4ll9yVj2X5M4Y2zGQv JdZA== X-Gm-Message-State: AOJu0Yy0N9CcrgsIufF0yMJvIjhiavRXNbnML9UEIueQ2yPYtbposRf2 CUYdJOan6O+2EiNI431V8R99Ts7szkWCd9tVBU63cQ6Cv9JE9yz+whsfoPNbIEWCAGPosHIrs3C IHJAe4KCsE7IqpIsWzOvHP5ZiElABctDE0hQRvsucgQ42uNqmwYIgsxkAoDmY X-Received: by 2002:a17:906:e219:b0:a58:f186:192 with SMTP id gf25-20020a170906e21900b00a58f1860192mr490081ejb.0.1714502901720; Tue, 30 Apr 2024 11:48:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqejeiX/OtaZIPt9hRqP/hC17fwTLbBylo9nxROH2qxblVZ84/lJJ7nBYpcXsqqpxcr0qUkA== X-Received: by 2002:a17:906:e219:b0:a58:f186:192 with SMTP id gf25-20020a170906e21900b00a58f1860192mr490062ejb.0.1714502901066; Tue, 30 Apr 2024 11:48:21 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id 16-20020a170906319000b00a5544063372sm15324174ejy.162.2024.04.30.11.48.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2024 11:48:20 -0700 (PDT) Date: Tue, 30 Apr 2024 20:47:46 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 6/7] iov: Helper macro to construct iovs covering existing variables or fields Message-ID: <20240430204746.6441f86b@elisabeth> In-Reply-To: <20240429070933.1366881-7-david@gibson.dropbear.id.au> References: <20240429070933.1366881-1-david@gibson.dropbear.id.au> <20240429070933.1366881-7-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; 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: TA24QBFCDB3HLFEIKWZFUP4XJXGQEMOX X-Message-ID-Hash: TA24QBFCDB3HLFEIKWZFUP4XJXGQEMOX 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, Laurent Vivier 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 Mon, 29 Apr 2024 17:09:32 +1000 David Gibson wrote: > Laurent's recent changes mean we use IO vectors much more heavily in the > TCP code. In many of those cases, and few others around the code base, > individual iovs of these vectors are constructed to exactly cover existing > variables or fields. We can make initializing such iovs shorter and > clearer with a macro for the purpose. > > Signed-off-by: David Gibson > --- > iov.h | 3 +++ > tap.c | 3 +-- > tcp.c | 24 +++++++++--------------- > udp.c | 7 +++---- > 4 files changed, 16 insertions(+), 21 deletions(-) > > diff --git a/iov.h b/iov.h > index 6058af77..5668ca5f 100644 > --- a/iov.h > +++ b/iov.h > @@ -18,6 +18,9 @@ > #include > #include > > +#define IOV_OF_LVALUE(lval) \ > + (struct iovec){ .iov_base = &(lval), .iov_len = sizeof(lval) } I'm not sure if IOV_OF_LVALUE() is much clearer than IOV_FROM() or IOV_OF(). No strong preference though. > + > size_t iov_skip_bytes(const struct iovec *iov, size_t n, > size_t skip, size_t *offset); > size_t iov_from_buf(const struct iovec *iov, size_t iov_cnt, > diff --git a/tap.c b/tap.c > index 6a08cca6..5db7b169 100644 > --- a/tap.c > +++ b/tap.c > @@ -79,8 +79,7 @@ void tap_send_single(const struct ctx *c, const void *data, size_t len) > size_t iovcnt = 0; > > if (c->mode == MODE_PASST) { > - iov[iovcnt].iov_base = &vnet_len; > - iov[iovcnt].iov_len = sizeof(vnet_len); > + iov[iovcnt] = IOV_OF_LVALUE(vnet_len); > iovcnt++; > } > > diff --git a/tcp.c b/tcp.c > index ad409fc5..27c06958 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -290,6 +290,7 @@ > > #include "checksum.h" > #include "util.h" > +#include "iov.h" > #include "ip.h" > #include "passt.h" > #include "tap.h" > @@ -954,10 +955,8 @@ static void tcp_sock4_iov_init(const struct ctx *c) > iov = tcp4_l2_iov[i]; > > iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp4_payload_tap_hdr[i]); > - iov[TCP_IOV_ETH].iov_base = &tcp4_eth_src; > - iov[TCP_IOV_ETH].iov_len = sizeof(tcp4_eth_src); > - iov[TCP_IOV_IP].iov_base = &tcp4_payload_ip[i]; > - iov[TCP_IOV_IP].iov_len = sizeof(tcp4_payload_ip[i]); > + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp4_eth_src); > + iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp4_payload_ip[i]); > iov[TCP_IOV_PAYLOAD].iov_base = &tcp4_payload[i]; > } > > @@ -966,9 +965,8 @@ static void tcp_sock4_iov_init(const struct ctx *c) > > iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp4_flags_tap_hdr[i]); > iov[TCP_IOV_ETH].iov_base = &tcp4_eth_src; > - iov[TCP_IOV_ETH].iov_len = sizeof(tcp4_eth_src); > - iov[TCP_IOV_IP].iov_base = &tcp4_flags_ip[i]; > - iov[TCP_IOV_IP].iov_len = sizeof(tcp4_flags_ip[i]); > + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp4_eth_src); > + iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp4_flags_ip[i]); > iov[TCP_IOV_PAYLOAD].iov_base = &tcp4_flags[i]; > } > } > @@ -1001,10 +999,8 @@ static void tcp_sock6_iov_init(const struct ctx *c) > iov = tcp6_l2_iov[i]; > > iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp6_payload_tap_hdr[i]); > - iov[TCP_IOV_ETH].iov_base = &tcp6_eth_src; > - iov[TCP_IOV_ETH].iov_len = sizeof(tcp6_eth_src); > - iov[TCP_IOV_IP].iov_base = &tcp6_payload_ip[i]; > - iov[TCP_IOV_IP].iov_len = sizeof(tcp6_payload_ip[i]); > + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp6_eth_src); > + iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp6_payload_ip[i]); > iov[TCP_IOV_PAYLOAD].iov_base = &tcp6_payload[i]; > } > > @@ -1012,10 +1008,8 @@ static void tcp_sock6_iov_init(const struct ctx *c) > iov = tcp6_l2_flags_iov[i]; > > iov[TCP_IOV_TAP] = tap_hdr_iov(c, &tcp6_flags_tap_hdr[i]); > - iov[TCP_IOV_ETH].iov_base = &tcp6_eth_src; > - iov[TCP_IOV_ETH].iov_len = sizeof(tcp6_eth_src); > - iov[TCP_IOV_IP].iov_base = &tcp6_flags_ip[i]; > - iov[TCP_IOV_IP].iov_len = sizeof(tcp6_flags_ip[i]); > + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp6_eth_src); > + iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp6_flags_ip[i]); > iov[TCP_IOV_PAYLOAD].iov_base = &tcp6_flags[i]; > } > } > diff --git a/udp.c b/udp.c > index 1a4c02f4..545212c5 100644 > --- a/udp.c > +++ b/udp.c > @@ -113,6 +113,7 @@ > > #include "checksum.h" > #include "util.h" > +#include "iov.h" > #include "ip.h" > #include "siphash.h" > #include "inany.h" > @@ -315,8 +316,7 @@ static void udp_sock4_iov_init_one(const struct ctx *c, size_t i) > .iph = L2_BUF_IP4_INIT(IPPROTO_UDP) > }; > > - siov->iov_base = buf->data; > - siov->iov_len = sizeof(buf->data); > + *siov = IOV_OF_LVALUE(buf->data); > > mh->msg_name = &buf->s_in; > mh->msg_namelen = sizeof(buf->s_in); > @@ -343,8 +343,7 @@ static void udp_sock6_iov_init_one(const struct ctx *c, size_t i) > .ip6h = L2_BUF_IP6_INIT(IPPROTO_UDP) > }; > > - siov->iov_base = buf->data; > - siov->iov_len = sizeof(buf->data); > + *siov = IOV_OF_LVALUE(buf->data); Extra whitespace between tabs and =. -- Stefano