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.133.124]) by passt.top (Postfix) with ESMTP id B32215A026F for ; Thu, 16 Nov 2023 08:23:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700119426; 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=frxUGldSyC3WsJR4x4rDch8OUkmJfHYpLFKdFatPeLw=; b=e9aasDTSs6MjEhhMcpL4VZ/8rQUePxffanJRqrO3hsPm9Qq5XELaS7/QxcLUfRtBwDGQnS mBJPKHNv0fFbvv9cJ9wQKERb5vKTEXRi8eReAjqnLz+8+xPJVVl5IIi3KDjKpicCb3UnxN E3hYTczj06Rx9WIziHE1gvvAu52IGyY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-272-uCQ5hSOrPAOCBOQLZdzN2g-1; Thu, 16 Nov 2023 02:23:45 -0500 X-MC-Unique: uCQ5hSOrPAOCBOQLZdzN2g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF0A7811E7B; Thu, 16 Nov 2023 07:23:44 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 37EC41121306; Thu, 16 Nov 2023 07:23:43 +0000 (UTC) Date: Thu, 16 Nov 2023 08:21:34 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 1/2] valgrind: Adjust suppression for MSG_TRUNC with NULL buffer Message-ID: <20231116082134.378f74c1@elisabeth> In-Reply-To: <20231116054350.3255485-2-david@gibson.dropbear.id.au> References: <20231116054350.3255485-1-david@gibson.dropbear.id.au> <20231116054350.3255485-2-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QG2YHEZVTN422AWRK6XLSWOMZUOPZXDR X-Message-ID-Hash: QG2YHEZVTN422AWRK6XLSWOMZUOPZXDR 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 Thu, 16 Nov 2023 16:43:49 +1100 David Gibson wrote: > 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 ^ pp (I can fix it up on merge but I guess you prefer to repost). Rest of the series looks good to me. -- Stefano