]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
vsock/test: fix MSG_PEEK handling in recv_buf()
authorLuigi Leonardi <leonardi@redhat.com>
Wed, 15 Apr 2026 15:09:29 +0000 (17:09 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 17 Apr 2026 02:34:22 +0000 (19:34 -0700)
commita3f77afbf67d5ddbc8938fd5627a11221d8a3368
treeecf2e43649a3040ddd0e0a6333720d8cd4e2af43
parent080f22f5d30233faf3d83be3098f35b8be9b7a00
vsock/test: fix MSG_PEEK handling in recv_buf()

`recv_buf` does not handle the MSG_PEEK flag correctly: it keeps calling
`recv` until all requested bytes are available or an error occurs.

The problem is how it calculates the number of bytes read: MSG_PEEK
doesn't consume any bytes and will re-read the same bytes from the buffer
head, so summing the return value every time is wrong.

Moreover, MSG_PEEK doesn't consume the bytes in the buffer, so if more
bytes are requested than are available, the loop will never terminate,
because `recv` will never return EOF. For this reason, we need to compare
the number of bytes read with the number of bytes expected.

Add a check: if the MSG_PEEK flag is present, update the byte counter and
break out of the loop only after at least the expected number of bytes
have been received; otherwise, retry after a short delay to avoid
consuming too many CPU cycles.

This allows us to simplify the `test_stream_credit_update_test` by
reusing `recv_buf`, like some other tests already do.

Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://patch.msgid.link/20260415-fix_peek-v4-2-8207e872759e@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/vsock/util.c
tools/testing/vsock/vsock_test.c