From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 4560A5A0271 for ; Thu, 16 Nov 2023 06:43:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1700113431; bh=86VF+bEHqp3OdU0aGU04gMlaLcGduDfryuMLVAa84K8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k8EuLLblmMO5J1xvYtq9dSKZZwdM3o4ookYs+DZQRSJYwrADGcpmUpn2W8BhPArsg KXiQzAVWAKY3SYV3Dt8qNmHGWvJGU0WJw7/t5/WYYFOqUhiWGS8n9umZAFFuSrpr25 uPUEYjjsyAuarxMXTydsmVQJgRh8RcgUm47fjpQI= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SW8936myBz4x1R; Thu, 16 Nov 2023 16:43:51 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 1/2] valgrind: Adjust suppression for MSG_TRUNC with NULL buffer Date: Thu, 16 Nov 2023 16:43:49 +1100 Message-ID: <20231116054350.3255485-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231116054350.3255485-1-david@gibson.dropbear.id.au> References: <20231116054350.3255485-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EZT5PQTCJS5YUGJ44RGWX5MGNEMN7XML X-Message-ID-Hash: EZT5PQTCJS5YUGJ44RGWX5MGNEMN7XML 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: valgrind complains if we pass a NULL buffer to recv(), even if we use MSG_TRUNC, in which case it's actually safe. For a long time we've had a valgrind suppression for this. It singles out the recv() in tcp_sock_consume(), the only place we use MSG_TRUNC. However, tcp_sock_consume() only has a single caller, which makes it a prime candidate for inlining. If inlined, it won't appear on the stack and valgrind won't match the correct suppression. It appears that certain compiler versions (for example gcc-13.2.1 in Fedora 39) will inline this function even with the -O0 we use for valgrind builds. This breaks the suppression leading to a spurious failure in the tests. There's not really any way to adjust the suppression itself without making it overly broad (we don't want to match other recv() calls). So, as a hack explicitly prevent inlining of this function when we're making a valgrind build. To accomplish this add an explicit -DVALGRIND when making such a build. Signed-off-by: David Gibson --- Makefile | 2 +- tcp.c | 9 +++++++++ test/valgrind.supp | 3 +-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ff21459..57b2544 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,7 @@ qrap: $(QRAP_SRCS) passt.h valgrind: EXTRA_SYSCALLS += rt_sigprocmask rt_sigtimedwait rt_sigaction \ getpid gettid kill clock_gettime mmap \ munmap open unlink gettimeofday futex -valgrind: FLAGS:=-g -O0 $(filter-out -O%,$(FLAGS)) +valgrind: FLAGS:=-g -O0 $(filter-out -O%,$(FLAGS)) -DVALGRIND valgrind: all .PHONY: clean diff --git a/tcp.c b/tcp.c index cfcd40a..b86d433 100644 --- a/tcp.c +++ b/tcp.c @@ -2097,6 +2097,15 @@ static void tcp_conn_from_tap(struct ctx *c, * * Return: 0 on success, negative error code from recv() on failure */ +#ifdef VALGRIND +/* valgrind doesn't realise that passing a NULL buffer to recv() is ok if using + * MSG_TRUNC. We have a supression for this in the tests, but it relies on + * valgrind being able to see the tcp_sock_consume() stack frame, which it won't + * if this gets inlined. This has a single caller making it a likely inlining + * candidate, and certain compiler versions will do so even at -O0. + */ + __attribute__((noinline)) +#endif /* VALGRIND */ static int tcp_sock_consume(const struct tcp_tap_conn *conn, uint32_t ack_seq) { /* Simply ignore out-of-order ACKs: we already consumed the data we diff --git a/test/valgrind.supp b/test/valgrind.supp index 1228056..a158394 100644 --- a/test/valgrind.supp +++ b/test/valgrind.supp @@ -3,7 +3,6 @@ passt_recv_MSG_TRUNC_into_NULL_buffer Memcheck:Param socketcall.recvfrom(buf) - fun:recv ... - fun:tcp_sock_consume* + fun:tcp_sock_consume } -- 2.41.0