From nobody Wed Dec 11 23:52:44 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A669D40849; Tue, 3 Dec 2024 01:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733189858; cv=none; b=R0VkDeWjERKZXTpkYCHlVBXNwqsrXFQEloVQ7/Q3txEpnGp4gjP6Bb32Qq6MrNvkiFFIWgax3WmQhw8n6aDwgNeYpIw+Eby1jwwo+0o8Xnau5elpBMbEBmsAZyz4hkPqXcgSk1SjsgJltfjsvTczmnd/dkQRH4gd6g0S6Xeu96Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733189858; c=relaxed/simple; bh=icntjnGysQ+hEHpDE9l/ljFz9vl8wA8BHuRskt5DZkM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PF8A6g1qfA9ehrscr0sbdiDG4pMbHRsIqyfspee2BMgBUQbovTqCLxBT+tcMnGREfX3J21tKQpGpDtSG+XT+YPMeYn7Zzl1jQ8nwigPxF2yYEy2txrM4dAb4+4UC2bVbCL6uMr8FJO0CyAz14elMuE8WVjNQD6QjutnooYJWnZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=kVGY5V5h; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="kVGY5V5h" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B2LJ8OI005883; Tue, 3 Dec 2024 01:37:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=zQ0K3g3G6sAWCVQAB OYxVi1Yu2obe6oJxQWPuvuV0RI=; b=kVGY5V5hBSRsVEBe6pRxLa+TXAQFLH5j9 nZC+smqPwGz1IbQ7B0zRIKgN5wiHar5mnnyIZKbdv67TPZk/tQHup/+7R6bHpZAj Vdkdu+m1JLmKcHWyOCtMx8YwpRX5JqMHltTaFwWFHGDUGAENVdaIVkchFFsnEvQP Rmd7PRqqQKnwrQro/+9AI/5OPSdbdhO0/qb+62mCUCI6XgGB10hvtAGF7dVWa83j 5Wv41yTn+liiQFNh96ZynBcPmSNpWudB89DAZNLmg3FN5BDI02U+TFeN9Q+eudAQ 3WR22hkwRU0G+rA2qzpDhSLOgKMKJv1+5VJ63U7rTCelVyMejvlzQ== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 437tbxbg5k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 01:37:32 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B30SNS2007214; Tue, 3 Dec 2024 01:37:31 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 438ehkk19v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 01:37:31 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B31bUCM3474012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Dec 2024 01:37:30 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F1AC5805A; Tue, 3 Dec 2024 01:37:30 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD30558051; Tue, 3 Dec 2024 01:37:29 +0000 (GMT) Received: from WIN-DU0DFC9G5VV.ibm.com (unknown [9.61.255.118]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 3 Dec 2024 01:37:29 +0000 (GMT) From: Konstantin Shkolnyy To: sgarzare@redhat.com Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mjrosato@linux.ibm.com, Konstantin Shkolnyy Subject: [PATCH net v7 1/3] vsock/test: fix failures due to wrong SO_RCVLOWAT parameter Date: Mon, 2 Dec 2024 19:37:07 -0600 Message-Id: <20241203013709.232045-2-kshk@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203013709.232045-1-kshk@linux.ibm.com> References: <20241203013709.232045-1-kshk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: qhUqt_zKeezgmwF_HKJ4dQby9aYQmADM X-Proofpoint-GUID: qhUqt_zKeezgmwF_HKJ4dQby9aYQmADM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412030011 Content-Type: text/plain; charset="utf-8" This happens on 64-bit big-endian machines. SO_RCVLOWAT requires an int parameter. However, instead of int, the test uses unsigned long in one place and size_t in another. Both are 8 bytes long on 64-bit machines. The kernel, having received the 8 bytes, doesn't test for the exact size of the parameter, it only cares that it's >=3D sizeof(int), and casts the 4 lower-addressed bytes to an int, which, on a big-endian machine, contains 0. 0 doesn't trigger an error, SO_RCVLOWAT returns with success and the socket stays with the default SO_RCVLOWAT =3D = 1, which results in vsock_test failures, while vsock_perf doesn't even notice that it's failed to change it. Fixes: b1346338fbae ("vsock_test: POLLIN + SO_RCVLOWAT test") Fixes: 542e893fbadc ("vsock/test: two tests to check credit update logic") Fixes: 8abbffd27ced ("test/vsock: vsock_perf utility") Signed-off-by: Konstantin Shkolnyy Reviewed-by: Stefano Garzarella --- tools/testing/vsock/vsock_perf.c | 6 +++--- tools/testing/vsock/vsock_test.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/vsock/vsock_perf.c b/tools/testing/vsock/vsock_p= erf.c index 4e8578f815e0..22633c2848cc 100644 --- a/tools/testing/vsock/vsock_perf.c +++ b/tools/testing/vsock/vsock_perf.c @@ -133,7 +133,7 @@ static float get_gbps(unsigned long bits, time_t ns_del= ta) ((float)ns_delta / NSEC_PER_SEC); } =20 -static void run_receiver(unsigned long rcvlowat_bytes) +static void run_receiver(int rcvlowat_bytes) { unsigned int read_cnt; time_t rx_begin_ns; @@ -163,7 +163,7 @@ static void run_receiver(unsigned long rcvlowat_bytes) 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("SO_RCVLOWAT %lu bytes\n", rcvlowat_bytes); + printf("SO_RCVLOWAT %d bytes\n", rcvlowat_bytes); =20 fd =3D socket(AF_VSOCK, SOCK_STREAM, 0); =20 @@ -439,7 +439,7 @@ static long strtolx(const char *arg) int main(int argc, char **argv) { unsigned long to_send_bytes =3D DEFAULT_TO_SEND_BYTES; - unsigned long rcvlowat_bytes =3D DEFAULT_RCVLOWAT_BYTES; + int rcvlowat_bytes =3D DEFAULT_RCVLOWAT_BYTES; int peer_cid =3D -1; bool sender =3D false; =20 diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index 8d38dbf8f41f..7fd25b814b4b 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -835,7 +835,7 @@ static void test_stream_poll_rcvlowat_server(const stru= ct test_opts *opts) =20 static void test_stream_poll_rcvlowat_client(const struct test_opts *opts) { - unsigned long lowat_val =3D RCVLOWAT_BUF_SIZE; + int lowat_val =3D RCVLOWAT_BUF_SIZE; char buf[RCVLOWAT_BUF_SIZE]; struct pollfd fds; short poll_flags; @@ -1357,7 +1357,7 @@ static void test_stream_rcvlowat_def_cred_upd_client(= const struct test_opts *opt static void test_stream_credit_update_test(const struct test_opts *opts, bool low_rx_bytes_test) { - size_t recv_buf_size; + int recv_buf_size; struct pollfd fds; size_t buf_size; void *buf; --=20 2.34.1 From nobody Wed Dec 11 23:52:44 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71E996BFC0; Tue, 3 Dec 2024 01:37:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733189859; cv=none; b=fwnyeAG6lSjUVsF+Tfz5BtCgYiX0SsbF8/lMWG63Z56xgDEsuDvZyugp4rE9IOntm9Akc/tdhRRmbAo8wcJDP0zfHHKwo2k2rDkhNeHRSjHDP0X1HLFOcFXH85NtPLEq1p030UBhtMF4VHtvOH/M+rztrv/ND+1DYU9sjhFJ2JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733189859; c=relaxed/simple; bh=zqfEmR3ZxE5BBErtEyisFCyCuhq30Yd4C9NzyKLX/xo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=busdEeJr19UiiJMNKA9kn2r+Ny68JYzXQ8XltBh8CjPdTxrresScJeIj7hP3cq1uipb/R7zGZ10IC6cgvDmxgnTybKXmqP/LtpJAWJA1SW5xW3vXihyP10iFTgmNdjtGhckNdmDoROoUSthVpN/fl2vNFppnkEUWVHX7ztlxBdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=gmWjpcIR; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="gmWjpcIR" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B2IIh0Y007659; Tue, 3 Dec 2024 01:37:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=1WXvViyc/ejbVc3ul mZ9A8tGjSjwOxM5hvFojVOsH5M=; b=gmWjpcIRM6rLKAapIBbDOBMuuPWMs5evG JNApkb/tYPgnSvANeZn90s6RC90qEQi18eHv+fPCm55nZhJoG2z8tNDqDjXNCo19 sE8pTTDVA1Nlc8t8+TqJDwB4TyxqAO9ylokapSA+G9Q80esEQVgUlZkJ+8/oaWnk qZFhShYTp9/+9et+pchTpnLZGYRBeouV/DOz+eFPrUSeEv/SA3Pc+BBodutua4o+ bCoFpqc72x79MI7+c7xgcUwkQ56SiUB9aY3sDC8OJV6k1Af2smPkYfOYH0h3l5So 46bE54FTAatfd3yginrdREARZy7LIpshFwcMZ/BH0NGpQPLRcXKvg== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 437tbxbg5m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 01:37:33 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B318A48029483; Tue, 3 Dec 2024 01:37:32 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 438ddybj18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 01:37:32 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B31bVI926149420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Dec 2024 01:37:31 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F0A255805A; Tue, 3 Dec 2024 01:37:30 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB9165805E; Tue, 3 Dec 2024 01:37:30 +0000 (GMT) Received: from WIN-DU0DFC9G5VV.ibm.com (unknown [9.61.255.118]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 3 Dec 2024 01:37:30 +0000 (GMT) From: Konstantin Shkolnyy To: sgarzare@redhat.com Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mjrosato@linux.ibm.com, Konstantin Shkolnyy Subject: [PATCH net v7 2/3] vsock/test: fix parameter types in SO_VM_SOCKETS_* calls Date: Mon, 2 Dec 2024 19:37:08 -0600 Message-Id: <20241203013709.232045-3-kshk@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203013709.232045-1-kshk@linux.ibm.com> References: <20241203013709.232045-1-kshk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: R96gyRBexlHrr0d4gFdQaP2930_KIM6E X-Proofpoint-GUID: R96gyRBexlHrr0d4gFdQaP2930_KIM6E X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412030011 Content-Type: text/plain; charset="utf-8" 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: 5c338112e48a ("test/vsock: rework message bounds test") Fixes: 685a21c314a8 ("test/vsock: add big message test") Fixes: 542e893fbadc ("vsock/test: two tests to check credit update logic") Fixes: 8abbffd27ced ("test/vsock: vsock_perf utility") Signed-off-by: Konstantin Shkolnyy Reviewed-by: Stefano Garzarella --- tools/testing/vsock/vsock_perf.c | 4 ++-- tools/testing/vsock/vsock_test.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/testing/vsock/vsock_perf.c b/tools/testing/vsock/vsock_p= erf.c index 22633c2848cc..8e0a6c0770d3 100644 --- a/tools/testing/vsock/vsock_perf.c +++ b/tools/testing/vsock/vsock_perf.c @@ -33,7 +33,7 @@ =20 static unsigned int port =3D DEFAULT_PORT; static unsigned long buf_size_bytes =3D DEFAULT_BUF_SIZE_BYTES; -static unsigned long vsock_buf_bytes =3D DEFAULT_VSOCK_BUF_BYTES; +static unsigned long long vsock_buf_bytes =3D DEFAULT_VSOCK_BUF_BYTES; static bool zerocopy; =20 static void error(const char *s) @@ -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); =20 fd =3D socket(AF_VSOCK, SOCK_STREAM, 0); diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index 7fd25b814b4b..c7af23332e57 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -429,7 +429,7 @@ static void test_seqpacket_msg_bounds_client(const stru= ct test_opts *opts) =20 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; @@ -634,7 +634,8 @@ static void test_seqpacket_timeout_server(const struct = test_opts *opts) =20 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; @@ -655,13 +656,20 @@ static void test_seqpacket_bigmsg_client(const struct= test_opts *opts) =20 sock_buf_size++; =20 - data =3D malloc(sock_buf_size); + /* size_t can be < unsigned long long */ + buf_size =3D (size_t) sock_buf_size; + if (buf_size !=3D sock_buf_size) { + fprintf(stderr, "Returned BUFFER_SIZE too large\n"); + exit(EXIT_FAILURE); + } + + data =3D malloc(buf_size); if (!data) { perror("malloc"); exit(EXIT_FAILURE); } =20 - send_buf(fd, data, sock_buf_size, 0, -EMSGSIZE); + send_buf(fd, data, buf_size, 0, -EMSGSIZE); =20 control_writeln("CLISENT"); =20 @@ -1360,6 +1368,7 @@ static void test_stream_credit_update_test(const stru= ct test_opts *opts, int recv_buf_size; struct pollfd fds; size_t buf_size; + unsigned long long sock_buf_size; void *buf; int fd; =20 @@ -1371,8 +1380,11 @@ static void test_stream_credit_update_test(const str= uct test_opts *opts, =20 buf_size =3D RCVLOWAT_CREDIT_UPD_BUF_SIZE; =20 + /* size_t can be < unsigned long long */ + sock_buf_size =3D 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); } --=20 2.34.1 From nobody Wed Dec 11 23:52:44 2024 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5083013CA99; Tue, 3 Dec 2024 01:37:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733189861; cv=none; b=VBefHP0EMhCdN+pDoomZRHWt8cN/YAOYofzvg2dK2G/0OzGgMAUZ5aYXG9e4Fmvh0rmq6uMzph7p7rplB+ivhDyMiZ64IROx4yV2p18ziHbTWiRL+drfLExfaxO/jmbdF5GeWZugKXReN845xRDCvErjtd7YDtCdw3yLPsk43oM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733189861; c=relaxed/simple; bh=q1Bu8EgavZfOPLmlTzctDFnHeqoFr1v3VG7Dkgv/gcg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EJk/3R8dTEkpy0pqiFzasZnA+5H8fE1vujoIIpy1gS/D73wipGqbZB3Te7S1UGcR/PTCyG+rxNNa6jVkYQoZHcU3sx9cbdBtwREwM8mDRgljIZvLYgERA4CHney+iCUP0kGJijIff5QaxtwR5PNKrCzXH1a0Zq3Wje/tKZmMC9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=TlGIYTN1; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="TlGIYTN1" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B2LaMNc002570; Tue, 3 Dec 2024 01:37:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=LYNIwsfPamPOlVEPJ kO6MBAqxhgjkkcJATSFQHd2Pwc=; b=TlGIYTN1q/ehMYOeKNZU09ApB1LBWDuvn L6umun0RVoWZMn5omXH3Sruu1MC+5gMdeLUx4kJOkc3cTc/iY75yqMT769+weNfO +9NFTp+sDI+RXK0GvgHGhJv2lqTDhPCbHYyd21RKvV1gnXyShcYMVdRvK/ImhYAe QAx1mit4KaONvqkKg4Ub0eoB7dMbOmV1P2g3g9BW21uo6PuxFXdvyW/Rfs6sfh+P U9C9gX9E7addhQXvCd9gxydPEh2TGtCA23+AlAN6uZ0LIF+yimxEpPYSEuOJKJ7J H0RgxczuPAlWqFil1hq8yt0nLxCycUpAXElh7p5QJ1fDNwYgKz5Qg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 437r4pbrdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 01:37:34 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 4B2Hgq0K012745; Tue, 3 Dec 2024 01:37:33 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 438d1s3aqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 01:37:33 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4B31bWUn58261996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Dec 2024 01:37:32 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D8A6D5805A; Tue, 3 Dec 2024 01:37:31 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9A9455805F; Tue, 3 Dec 2024 01:37:31 +0000 (GMT) Received: from WIN-DU0DFC9G5VV.ibm.com (unknown [9.61.255.118]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 3 Dec 2024 01:37:31 +0000 (GMT) From: Konstantin Shkolnyy To: sgarzare@redhat.com Cc: virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mjrosato@linux.ibm.com, Konstantin Shkolnyy Subject: [PATCH net v7 3/3] vsock/test: verify socket options after setting them Date: Mon, 2 Dec 2024 19:37:09 -0600 Message-Id: <20241203013709.232045-4-kshk@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241203013709.232045-1-kshk@linux.ibm.com> References: <20241203013709.232045-1-kshk@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YdJQ8PL7_M2lRtcBrJq1_QHpCwy-XROH X-Proofpoint-ORIG-GUID: YdJQ8PL7_M2lRtcBrJq1_QHpCwy-XROH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 clxscore=1015 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412030011 Content-Type: text/plain; charset="utf-8" Replace setsockopt() calls with calls to functions that follow setsockopt() with getsockopt() and check that the returned value and its size are the same as have been set. (Except in vsock_perf.) Signed-off-by: Konstantin Shkolnyy Reviewed-by: Stefano Garzarella --- tools/testing/vsock/control.c | 9 +- tools/testing/vsock/msg_zerocopy_common.c | 10 -- tools/testing/vsock/msg_zerocopy_common.h | 1 - tools/testing/vsock/util.c | 144 ++++++++++++++++++++++ tools/testing/vsock/util.h | 7 ++ tools/testing/vsock/vsock_perf.c | 10 ++ tools/testing/vsock/vsock_test.c | 49 +++----- tools/testing/vsock/vsock_test_zerocopy.c | 2 +- tools/testing/vsock/vsock_uring_test.c | 2 +- 9 files changed, 181 insertions(+), 53 deletions(-) diff --git a/tools/testing/vsock/control.c b/tools/testing/vsock/control.c index d2deb4b15b94..875ef0cfa415 100644 --- a/tools/testing/vsock/control.c +++ b/tools/testing/vsock/control.c @@ -27,6 +27,7 @@ =20 #include "timeout.h" #include "control.h" +#include "util.h" =20 static int control_fd =3D -1; =20 @@ -50,7 +51,6 @@ void control_init(const char *control_host, =20 for (ai =3D result; ai; ai =3D ai->ai_next) { int fd; - int val =3D 1; =20 fd =3D socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (fd < 0) @@ -65,11 +65,8 @@ void control_init(const char *control_host, break; } =20 - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - &val, sizeof(val)) < 0) { - perror("setsockopt"); - exit(EXIT_FAILURE); - } + setsockopt_int_check(fd, SOL_SOCKET, SO_REUSEADDR, 1, + "setsockopt SO_REUSEADDR"); =20 if (bind(fd, ai->ai_addr, ai->ai_addrlen) < 0) goto next; diff --git a/tools/testing/vsock/msg_zerocopy_common.c b/tools/testing/vsoc= k/msg_zerocopy_common.c index 5a4bdf7b5132..8622e5a0f8b7 100644 --- a/tools/testing/vsock/msg_zerocopy_common.c +++ b/tools/testing/vsock/msg_zerocopy_common.c @@ -14,16 +14,6 @@ =20 #include "msg_zerocopy_common.h" =20 -void enable_so_zerocopy(int fd) -{ - int val =3D 1; - - if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val))) { - perror("setsockopt"); - exit(EXIT_FAILURE); - } -} - void vsock_recv_completion(int fd, const bool *zerocopied) { struct sock_extended_err *serr; diff --git a/tools/testing/vsock/msg_zerocopy_common.h b/tools/testing/vsoc= k/msg_zerocopy_common.h index 3763c5ccedb9..ad14139e93ca 100644 --- a/tools/testing/vsock/msg_zerocopy_common.h +++ b/tools/testing/vsock/msg_zerocopy_common.h @@ -12,7 +12,6 @@ #define VSOCK_RECVERR 1 #endif =20 -void enable_so_zerocopy(int fd); void vsock_recv_completion(int fd, const bool *zerocopied); =20 #endif /* MSG_ZEROCOPY_COMMON_H */ diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index a3d448a075e3..e79534b52477 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -651,3 +651,147 @@ void free_test_iovec(const struct iovec *test_iovec, =20 free(iovec); } + +/* Set "unsigned long long" socket option and check that it's indeed set */ +void setsockopt_ull_check(int fd, int level, int optname, + unsigned long long val, char const *errmsg) +{ + unsigned long long chkval; + socklen_t chklen; + int err; + + err =3D setsockopt(fd, level, optname, &val, sizeof(val)); + if (err) { + fprintf(stderr, "setsockopt err: %s (%d)\n", + strerror(errno), errno); + goto fail; + } + + chkval =3D ~val; /* just make storage !=3D val */ + chklen =3D sizeof(chkval); + + err =3D getsockopt(fd, level, optname, &chkval, &chklen); + if (err) { + fprintf(stderr, "getsockopt err: %s (%d)\n", + strerror(errno), errno); + goto fail; + } + + if (chklen !=3D sizeof(chkval)) { + fprintf(stderr, "size mismatch: set %zu got %d\n", sizeof(val), + chklen); + goto fail; + } + + if (chkval !=3D val) { + fprintf(stderr, "value mismatch: set %llu got %llu\n", val, + chkval); + goto fail; + } + return; +fail: + fprintf(stderr, "%s val %llu\n", errmsg, val); + exit(EXIT_FAILURE); +; +} + +/* Set "int" socket option and check that it's indeed set */ +void setsockopt_int_check(int fd, int level, int optname, int val, + char const *errmsg) +{ + int chkval; + socklen_t chklen; + int err; + + err =3D setsockopt(fd, level, optname, &val, sizeof(val)); + if (err) { + fprintf(stderr, "setsockopt err: %s (%d)\n", + strerror(errno), errno); + goto fail; + } + + chkval =3D ~val; /* just make storage !=3D val */ + chklen =3D sizeof(chkval); + + err =3D getsockopt(fd, level, optname, &chkval, &chklen); + if (err) { + fprintf(stderr, "getsockopt err: %s (%d)\n", + strerror(errno), errno); + goto fail; + } + + if (chklen !=3D sizeof(chkval)) { + fprintf(stderr, "size mismatch: set %zu got %d\n", sizeof(val), + chklen); + goto fail; + } + + if (chkval !=3D val) { + fprintf(stderr, "value mismatch: set %d got %d\n", + val, chkval); + goto fail; + } + return; +fail: + fprintf(stderr, "%s val %d\n", errmsg, val); + exit(EXIT_FAILURE); +} + +static void mem_invert(unsigned char *mem, size_t size) +{ + size_t i; + + for (i =3D 0; i < size; i++) + mem[i] =3D ~mem[i]; +} + +/* Set "timeval" socket option and check that it's indeed set */ +void setsockopt_timeval_check(int fd, int level, int optname, + struct timeval val, char const *errmsg) +{ + struct timeval chkval; + socklen_t chklen; + int err; + + err =3D setsockopt(fd, level, optname, &val, sizeof(val)); + if (err) { + fprintf(stderr, "setsockopt err: %s (%d)\n", + strerror(errno), errno); + goto fail; + } + + /* just make storage !=3D val */ + chkval =3D val; + mem_invert((unsigned char *) &chkval, sizeof(chkval)); + chklen =3D sizeof(chkval); + + err =3D getsockopt(fd, level, optname, &chkval, &chklen); + if (err) { + fprintf(stderr, "getsockopt err: %s (%d)\n", + strerror(errno), errno); + goto fail; + } + + if (chklen !=3D sizeof(chkval)) { + fprintf(stderr, "size mismatch: set %zu got %d\n", sizeof(val), + chklen); + goto fail; + } + + if (memcmp(&chkval, &val, sizeof(val)) !=3D 0) { + fprintf(stderr, "value mismatch: set %ld:%ld got %ld:%ld\n", + val.tv_sec, val.tv_usec, + chkval.tv_sec, chkval.tv_usec); + goto fail; + } + return; +fail: + fprintf(stderr, "%s val %ld:%ld\n", errmsg, val.tv_sec, val.tv_usec); + exit(EXIT_FAILURE); +} + +void enable_so_zerocopy_check(int fd) +{ + setsockopt_int_check(fd, SOL_SOCKET, SO_ZEROCOPY, 1, + "setsockopt SO_ZEROCOPY"); +} diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index fff22d4a14c0..f189334591df 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -68,4 +68,11 @@ unsigned long iovec_hash_djb2(const struct iovec *iov, s= ize_t iovnum); struct iovec *alloc_test_iovec(const struct iovec *test_iovec, int iovnum); void free_test_iovec(const struct iovec *test_iovec, struct iovec *iovec, int iovnum); +void setsockopt_ull_check(int fd, int level, int optname, + unsigned long long val, char const *errmsg); +void setsockopt_int_check(int fd, int level, int optname, int val, + char const *errmsg); +void setsockopt_timeval_check(int fd, int level, int optname, + struct timeval val, char const *errmsg); +void enable_so_zerocopy_check(int fd); #endif /* UTIL_H */ diff --git a/tools/testing/vsock/vsock_perf.c b/tools/testing/vsock/vsock_p= erf.c index 8e0a6c0770d3..75971ac708c9 100644 --- a/tools/testing/vsock/vsock_perf.c +++ b/tools/testing/vsock/vsock_perf.c @@ -251,6 +251,16 @@ static void run_receiver(int rcvlowat_bytes) close(fd); } =20 +static void enable_so_zerocopy(int fd) +{ + int val =3D 1; + + if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val))) { + perror("setsockopt"); + exit(EXIT_FAILURE); + } +} + static void run_sender(int peer_cid, unsigned long to_send_bytes) { time_t tx_begin_ns; diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index c7af23332e57..0b514643a9a5 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -444,17 +444,12 @@ static void test_seqpacket_msg_bounds_server(const st= ruct test_opts *opts) =20 sock_buf_size =3D SOCK_BUF_SIZE; =20 - if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_MAX_SIZE, - &sock_buf_size, sizeof(sock_buf_size))) { - perror("setsockopt(SO_VM_SOCKETS_BUFFER_MAX_SIZE)"); - exit(EXIT_FAILURE); - } + setsockopt_ull_check(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_MAX_SIZE, + sock_buf_size, + "setsockopt(SO_VM_SOCKETS_BUFFER_MAX_SIZE)"); =20 - if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE, - &sock_buf_size, sizeof(sock_buf_size))) { - perror("setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)"); - exit(EXIT_FAILURE); - } + setsockopt_ull_check(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE, + sock_buf_size, "setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)"); =20 /* Ready to receive data. */ control_writeln("SRVREADY"); @@ -586,10 +581,8 @@ static void test_seqpacket_timeout_client(const struct= test_opts *opts) tv.tv_sec =3D RCVTIMEO_TIMEOUT_SEC; tv.tv_usec =3D 0; =20 - if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv)) =3D= =3D -1) { - perror("setsockopt(SO_RCVTIMEO)"); - exit(EXIT_FAILURE); - } + setsockopt_timeval_check(fd, SOL_SOCKET, SO_RCVTIMEO, tv, + "setsockopt(SO_RCVTIMEO)"); =20 read_enter_ns =3D current_nsec(); =20 @@ -855,11 +848,8 @@ static void test_stream_poll_rcvlowat_client(const str= uct test_opts *opts) exit(EXIT_FAILURE); } =20 - if (setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, - &lowat_val, sizeof(lowat_val))) { - perror("setsockopt(SO_RCVLOWAT)"); - exit(EXIT_FAILURE); - } + setsockopt_int_check(fd, SOL_SOCKET, SO_RCVLOWAT, + lowat_val, "setsockopt(SO_RCVLOWAT)"); =20 control_expectln("SRVSENT"); =20 @@ -1383,11 +1373,8 @@ static void test_stream_credit_update_test(const str= uct test_opts *opts, /* size_t can be < unsigned long long */ sock_buf_size =3D buf_size; =20 - if (setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE, - &sock_buf_size, sizeof(sock_buf_size))) { - perror("setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)"); - exit(EXIT_FAILURE); - } + setsockopt_ull_check(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE, + sock_buf_size, "setsockopt(SO_VM_SOCKETS_BUFFER_SIZE)"); =20 if (low_rx_bytes_test) { /* Set new SO_RCVLOWAT here. This enables sending credit @@ -1396,11 +1383,8 @@ static void test_stream_credit_update_test(const str= uct test_opts *opts, */ recv_buf_size =3D 1 + VIRTIO_VSOCK_MAX_PKT_BUF_SIZE; =20 - if (setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, - &recv_buf_size, sizeof(recv_buf_size))) { - perror("setsockopt(SO_RCVLOWAT)"); - exit(EXIT_FAILURE); - } + setsockopt_int_check(fd, SOL_SOCKET, SO_RCVLOWAT, + recv_buf_size, "setsockopt(SO_RCVLOWAT)"); } =20 /* Send one dummy byte here, because 'setsockopt()' above also @@ -1442,11 +1426,8 @@ static void test_stream_credit_update_test(const str= uct test_opts *opts, recv_buf_size++; =20 /* Updating SO_RCVLOWAT will send credit update. */ - if (setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT, - &recv_buf_size, sizeof(recv_buf_size))) { - perror("setsockopt(SO_RCVLOWAT)"); - exit(EXIT_FAILURE); - } + setsockopt_int_check(fd, SOL_SOCKET, SO_RCVLOWAT, + recv_buf_size, "setsockopt(SO_RCVLOWAT)"); } =20 fds.fd =3D fd; diff --git a/tools/testing/vsock/vsock_test_zerocopy.c b/tools/testing/vsoc= k/vsock_test_zerocopy.c index 04c376b6937f..9d9a6cb9614a 100644 --- a/tools/testing/vsock/vsock_test_zerocopy.c +++ b/tools/testing/vsock/vsock_test_zerocopy.c @@ -162,7 +162,7 @@ static void test_client(const struct test_opts *opts, } =20 if (test_data->so_zerocopy) - enable_so_zerocopy(fd); + enable_so_zerocopy_check(fd); =20 iovec =3D alloc_test_iovec(test_data->vecs, test_data->vecs_cnt); =20 diff --git a/tools/testing/vsock/vsock_uring_test.c b/tools/testing/vsock/v= sock_uring_test.c index 6c3e6f70c457..5c3078969659 100644 --- a/tools/testing/vsock/vsock_uring_test.c +++ b/tools/testing/vsock/vsock_uring_test.c @@ -73,7 +73,7 @@ static void vsock_io_uring_client(const struct test_opts = *opts, } =20 if (msg_zerocopy) - enable_so_zerocopy(fd); + enable_so_zerocopy_check(fd); =20 iovec =3D alloc_test_iovec(test_data->vecs, test_data->vecs_cnt); =20 --=20 2.34.1