Skip to content

Commit

Permalink
vsock/test: fix parameter types in SO_VM_SOCKETS_* calls
Browse files Browse the repository at this point in the history
Change parameters of SO_VM_SOCKETS_* to unsigned long long as documented
in the vm_sockets.h, because the corresponding kernel code requires them
to be at least 64-bit, no matter what architecture. Otherwise they are
too small on 32-bit machines.

Fixes: 5c33811 ("test/vsock: rework message bounds test")
Fixes: 685a21c ("test/vsock: add big message test")
Fixes: 542e893 ("vsock/test: two tests to check credit update logic")
Fixes: 8abbffd ("test/vsock: vsock_perf utility")
Signed-off-by: Konstantin Shkolnyy <[email protected]>
Reviewed-by: Stefano Garzarella <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Konstantin Shkolnyy authored and Paolo Abeni committed Dec 5, 2024
1 parent 7ce1c09 commit 3f36ee2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tools/testing/vsock/vsock_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

static unsigned int port = DEFAULT_PORT;
static unsigned long buf_size_bytes = DEFAULT_BUF_SIZE_BYTES;
static unsigned long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES;
static unsigned long long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES;
static bool zerocopy;

static void error(const char *s)
Expand Down Expand Up @@ -162,7 +162,7 @@ static void run_receiver(int rcvlowat_bytes)
printf("Run as receiver\n");
printf("Listen port %u\n", port);
printf("RX buffer %lu bytes\n", buf_size_bytes);
printf("vsock buffer %lu bytes\n", vsock_buf_bytes);
printf("vsock buffer %llu bytes\n", vsock_buf_bytes);
printf("SO_RCVLOWAT %d bytes\n", rcvlowat_bytes);

fd = socket(AF_VSOCK, SOCK_STREAM, 0);
Expand Down
22 changes: 17 additions & 5 deletions tools/testing/vsock/vsock_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)

static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
{
unsigned long sock_buf_size;
unsigned long long sock_buf_size;
unsigned long remote_hash;
unsigned long curr_hash;
int fd;
Expand Down Expand Up @@ -634,7 +634,8 @@ static void test_seqpacket_timeout_server(const struct test_opts *opts)

static void test_seqpacket_bigmsg_client(const struct test_opts *opts)
{
unsigned long sock_buf_size;
unsigned long long sock_buf_size;
size_t buf_size;
socklen_t len;
void *data;
int fd;
Expand All @@ -655,13 +656,20 @@ static void test_seqpacket_bigmsg_client(const struct test_opts *opts)

sock_buf_size++;

data = malloc(sock_buf_size);
/* size_t can be < unsigned long long */
buf_size = (size_t)sock_buf_size;
if (buf_size != sock_buf_size) {
fprintf(stderr, "Returned BUFFER_SIZE too large\n");
exit(EXIT_FAILURE);
}

data = malloc(buf_size);
if (!data) {
perror("malloc");
exit(EXIT_FAILURE);
}

send_buf(fd, data, sock_buf_size, 0, -EMSGSIZE);
send_buf(fd, data, buf_size, 0, -EMSGSIZE);

control_writeln("CLISENT");

Expand Down Expand Up @@ -1360,6 +1368,7 @@ static void test_stream_credit_update_test(const struct test_opts *opts,
int recv_buf_size;
struct pollfd fds;
size_t buf_size;
unsigned long long sock_buf_size;
void *buf;
int fd;

Expand All @@ -1371,8 +1380,11 @@ static void test_stream_credit_update_test(const struct test_opts *opts,

buf_size = RCVLOWAT_CREDIT_UPD_BUF_SIZE;

/* size_t can be < unsigned long long */
sock_buf_size = buf_size;

if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE,
&buf_size, sizeof(buf_size))) {
&sock_buf_size, sizeof(sock_buf_size))) {
perror("setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)");
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit 3f36ee2

Please sign in to comment.