From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 3EEF35A0272 for ; Tue, 7 Nov 2023 03:43:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1699324975; bh=iWZ8ZxXcmKpYx5jORQo40HZXQ5Zct1/CWN8hMWYr3B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iFzk1bR4ocFrrQ7WZeUoeyscLZZGxCBivtQFLNjZ0w1gL43uHWNntzHfNpSlzKYUc fCv5HacrabmO9wiQJl4jndDDX5LQLcbS+Cdc9B0N/VBRYPb3HkyInCQ+3tT9KHjSNe YsNMbuBRa+5ABpxGJcdS8fOvrAQ6vNWiaVTL/TmA= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SPXZR278sz4xWB; Tue, 7 Nov 2023 13:42:55 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 05/11] tcp_splice: Avoid awkward temporaries in tcp_splice_epoll_ctl() Date: Tue, 7 Nov 2023 13:42:44 +1100 Message-ID: <20231107024250.2290959-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231107024250.2290959-1-david@gibson.dropbear.id.au> References: <20231107024250.2290959-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 7DR6C7OFCYJGZXB7NUU2ER5OTCJZZLJZ X-Message-ID-Hash: 7DR6C7OFCYJGZXB7NUU2ER5OTCJZZLJZ X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: We initialise the events_a and events_b variables with tcp_splice_conn_epoll_events() function, then immediately copy the values into ev_a.events and ev_b.events. We can't simply pass &ev_[ab].events to tcp_splice_conn_epoll_events(), because struct epoll_event is packed, leading to 'pointer may be unaligned' warnings if we attempt that. We can, however, make tcp_splice_conn_epoll_events() take struct epoll_event pointers rather than raw u32 pointers, avoiding the awkward temporaries. Signed-off-by: David Gibson --- tcp_splice.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 44d1e4a..a706ebb 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -95,25 +95,26 @@ static int tcp_sock_refill_ns(void *arg); /** * tcp_splice_conn_epoll_events() - epoll events masks for given state * @events: Connection event flags - * @a: Event mask for socket with accepted connection, set on return - * @b: Event mask for connection target socket, set on return + * @a: Event for socket with accepted connection, set on return + * @b: Event for connection target socket, set on return */ static void tcp_splice_conn_epoll_events(uint16_t events, - uint32_t *a, uint32_t *b) + struct epoll_event *a, + struct epoll_event *b) { - *a = *b = 0; + a->events = b->events = 0; if (events & SPLICE_ESTABLISHED) { if (!(events & B_FIN_SENT)) - *a = EPOLLIN | EPOLLRDHUP; + a->events = EPOLLIN | EPOLLRDHUP; if (!(events & A_FIN_SENT)) - *b = EPOLLIN | EPOLLRDHUP; + b->events = EPOLLIN | EPOLLRDHUP; } else if (events & SPLICE_CONNECT) { - *b = EPOLLOUT; + b->events = EPOLLOUT; } - *a |= (events & A_OUT_WAIT) ? EPOLLOUT : 0; - *b |= (events & B_OUT_WAIT) ? EPOLLOUT : 0; + a->events |= (events & A_OUT_WAIT) ? EPOLLOUT : 0; + b->events |= (events & B_OUT_WAIT) ? EPOLLOUT : 0; } /** @@ -133,11 +134,8 @@ static int tcp_splice_epoll_ctl(const struct ctx *c, .tcp.index = CONN_IDX(conn) }; struct epoll_event ev_a = { .data.u64 = ref_a.u64 }; struct epoll_event ev_b = { .data.u64 = ref_b.u64 }; - uint32_t events_a, events_b; - tcp_splice_conn_epoll_events(conn->events, &events_a, &events_b); - ev_a.events = events_a; - ev_b.events = events_b; + tcp_splice_conn_epoll_events(conn->events, &ev_a, &ev_b); if (epoll_ctl(c->epollfd, m, conn->a, &ev_a) || epoll_ctl(c->epollfd, m, conn->b, &ev_b)) { -- 2.41.0