On Wed, Sep 28, 2022 at 10:58:37PM +0200, Stefano Brivio wrote:
On Wed, 28 Sep 2022 14:33:32 +1000 David Gibson
wrote: Recent versions of cppcheck give a warning due to the NULL buffer passed to recv() in tcp_sock_consume(). Since this apparently works, I assume it's actually valid,
Yes, given that we use MSG_TRUNC to discard socket buffers, I thought it's cleaner to avoid supplying a data buffer altogether.
POSIX doesn't specify MSG_TRUNC, and whether the buffer can be NULL isn't specified in Linux documentation, but it works reliably (the kernel won't even look at it).
Ah, interesting. I've update the comment and commit message with this detail.
This was actually the first step of a long-overdue plan: if you observe this through perf(1), you'll see some overhead in the kernel, which looks a bit more than a reasonable expectation for pure syscall overhead.
So, I planned to check if we can simplify the kernel path if no buffer is passed. I'll track this somewhere next week.
Even the day we add a vhost-user back-end, this overhead is still going to be there, as that wouldn't change anything host-side.
but cppcheck doesn't know that recv() can take a NULL buffer. So, use a suppression to get rid of the error.
valgrind didn't know either, by the way -- see the corresponding suppression in test/valgrind.supp.
-- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson