Skip to content

Commit 3f36ee2

Browse files
Konstantin ShkolnyyPaolo Abeni
authored andcommitted
vsock/test: fix parameter types in SO_VM_SOCKETS_* calls
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]>
1 parent 7ce1c09 commit 3f36ee2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tools/testing/vsock/vsock_perf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
static unsigned int port = DEFAULT_PORT;
3535
static unsigned long buf_size_bytes = DEFAULT_BUF_SIZE_BYTES;
36-
static unsigned long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES;
36+
static unsigned long long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES;
3737
static bool zerocopy;
3838

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

168168
fd = socket(AF_VSOCK, SOCK_STREAM, 0);

tools/testing/vsock/vsock_test.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
429429

430430
static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
431431
{
432-
unsigned long sock_buf_size;
432+
unsigned long long sock_buf_size;
433433
unsigned long remote_hash;
434434
unsigned long curr_hash;
435435
int fd;
@@ -634,7 +634,8 @@ static void test_seqpacket_timeout_server(const struct test_opts *opts)
634634

635635
static void test_seqpacket_bigmsg_client(const struct test_opts *opts)
636636
{
637-
unsigned long sock_buf_size;
637+
unsigned long long sock_buf_size;
638+
size_t buf_size;
638639
socklen_t len;
639640
void *data;
640641
int fd;
@@ -655,13 +656,20 @@ static void test_seqpacket_bigmsg_client(const struct test_opts *opts)
655656

656657
sock_buf_size++;
657658

658-
data = malloc(sock_buf_size);
659+
/* size_t can be < unsigned long long */
660+
buf_size = (size_t)sock_buf_size;
661+
if (buf_size != sock_buf_size) {
662+
fprintf(stderr, "Returned BUFFER_SIZE too large\n");
663+
exit(EXIT_FAILURE);
664+
}
665+
666+
data = malloc(buf_size);
659667
if (!data) {
660668
perror("malloc");
661669
exit(EXIT_FAILURE);
662670
}
663671

664-
send_buf(fd, data, sock_buf_size, 0, -EMSGSIZE);
672+
send_buf(fd, data, buf_size, 0, -EMSGSIZE);
665673

666674
control_writeln("CLISENT");
667675

@@ -1360,6 +1368,7 @@ static void test_stream_credit_update_test(const struct test_opts *opts,
13601368
int recv_buf_size;
13611369
struct pollfd fds;
13621370
size_t buf_size;
1371+
unsigned long long sock_buf_size;
13631372
void *buf;
13641373
int fd;
13651374

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

13721381
buf_size = RCVLOWAT_CREDIT_UPD_BUF_SIZE;
13731382

1383+
/* size_t can be < unsigned long long */
1384+
sock_buf_size = buf_size;
1385+
13741386
if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE,
1375-
&buf_size, sizeof(buf_size))) {
1387+
&sock_buf_size, sizeof(sock_buf_size))) {
13761388
perror("setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)");
13771389
exit(EXIT_FAILURE);
13781390
}

0 commit comments

Comments
 (0)