public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 1/2] valgrind: Adjust suppression for MSG_TRUNC with NULL buffer
Date: Thu, 16 Nov 2023 08:21:34 +0100	[thread overview]
Message-ID: <20231116082134.378f74c1@elisabeth> (raw)
In-Reply-To: <20231116054350.3255485-2-david@gibson.dropbear.id.au>

On Thu, 16 Nov 2023 16:43:49 +1100
David Gibson <david@gibson.dropbear.id.au> 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 <david@gibson.dropbear.id.au>
> ---
>  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


  reply	other threads:[~2023-11-16  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-16  5:43 [PATCH v2 0/2] Some fixes for valgrind suppressions David Gibson
2023-11-16  5:43 ` [PATCH v2 1/2] valgrind: Adjust suppression for MSG_TRUNC with NULL buffer David Gibson
2023-11-16  7:21   ` Stefano Brivio [this message]
2023-11-16  9:16     ` David Gibson
2023-11-16  5:43 ` [PATCH v2 2/2] valgrind: Don't disable optimizations for valgrind builds David Gibson

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=20231116082134.378f74c1@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).