virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH net-next v3 4/4] vsock/test: MSG_PEEK test for SOCK_SEQPACKET
       [not found] ` <20230725172912.1659970-5-AVKrasnov@sberdevices.ru>
@ 2023-07-26  8:04   ` Stefano Garzarella
  0 siblings, 0 replies; 2+ messages in thread
From: Stefano Garzarella @ 2023-07-26  8:04 UTC (permalink / raw)
  To: Arseniy Krasnov
  Cc: Bobby Eshleman, kvm, Michael S. Tsirkin, netdev, linux-kernel,
	virtualization, oxffffaa, Eric Dumazet, Stefan Hajnoczi, kernel,
	Jakub Kicinski, Paolo Abeni, David S. Miller

On Tue, Jul 25, 2023 at 08:29:12PM +0300, Arseniy Krasnov wrote:
>This adds MSG_PEEK test for SOCK_SEQPACKET. It works in the same way as
>SOCK_STREAM test, except it also tests MSG_TRUNC flag.
>
>Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>---
> tools/testing/vsock/vsock_test.c | 58 +++++++++++++++++++++++++++++---
> 1 file changed, 54 insertions(+), 4 deletions(-)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Thanks,
Stefano

>
>diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
>index 444a3ff0681f..90718c2fd4ea 100644
>--- a/tools/testing/vsock/vsock_test.c
>+++ b/tools/testing/vsock/vsock_test.c
>@@ -257,14 +257,19 @@ static void test_stream_multiconn_server(const struct test_opts *opts)
>
> #define MSG_PEEK_BUF_LEN 64
>
>-static void test_stream_msg_peek_client(const struct test_opts *opts)
>+static void test_msg_peek_client(const struct test_opts *opts,
>+				 bool seqpacket)
> {
> 	unsigned char buf[MSG_PEEK_BUF_LEN];
> 	ssize_t send_size;
> 	int fd;
> 	int i;
>
>-	fd = vsock_stream_connect(opts->peer_cid, 1234);
>+	if (seqpacket)
>+		fd = vsock_seqpacket_connect(opts->peer_cid, 1234);
>+	else
>+		fd = vsock_stream_connect(opts->peer_cid, 1234);
>+
> 	if (fd < 0) {
> 		perror("connect");
> 		exit(EXIT_FAILURE);
>@@ -290,7 +295,8 @@ static void test_stream_msg_peek_client(const struct test_opts *opts)
> 	close(fd);
> }
>
>-static void test_stream_msg_peek_server(const struct test_opts *opts)
>+static void test_msg_peek_server(const struct test_opts *opts,
>+				 bool seqpacket)
> {
> 	unsigned char buf_half[MSG_PEEK_BUF_LEN / 2];
> 	unsigned char buf_normal[MSG_PEEK_BUF_LEN];
>@@ -298,7 +304,11 @@ static void test_stream_msg_peek_server(const struct test_opts *opts)
> 	ssize_t res;
> 	int fd;
>
>-	fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
>+	if (seqpacket)
>+		fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL);
>+	else
>+		fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
>+
> 	if (fd < 0) {
> 		perror("accept");
> 		exit(EXIT_FAILURE);
>@@ -340,6 +350,21 @@ static void test_stream_msg_peek_server(const struct test_opts *opts)
> 		exit(EXIT_FAILURE);
> 	}
>
>+	if (seqpacket) {
>+		/* This type of socket supports MSG_TRUNC flag,
>+		 * so check it with MSG_PEEK. We must get length
>+		 * of the message.
>+		 */
>+		res = recv(fd, buf_half, sizeof(buf_half), MSG_PEEK |
>+			   MSG_TRUNC);
>+		if (res != sizeof(buf_peek)) {
>+			fprintf(stderr,
>+				"recv(2) + MSG_PEEK | MSG_TRUNC, exp %zu, got %zi\n",
>+				sizeof(buf_half), res);
>+			exit(EXIT_FAILURE);
>+		}
>+	}
>+
> 	res = recv(fd, buf_normal, sizeof(buf_normal), 0);
> 	if (res != sizeof(buf_normal)) {
> 		fprintf(stderr, "recv(2), expected %zu, got %zi\n",
>@@ -356,6 +381,16 @@ static void test_stream_msg_peek_server(const struct test_opts *opts)
> 	close(fd);
> }
>
>+static void test_stream_msg_peek_client(const struct test_opts *opts)
>+{
>+	return test_msg_peek_client(opts, false);
>+}
>+
>+static void test_stream_msg_peek_server(const struct test_opts *opts)
>+{
>+	return test_msg_peek_server(opts, false);
>+}
>+
> #define SOCK_BUF_SIZE (2 * 1024 * 1024)
> #define MAX_MSG_SIZE (32 * 1024)
>
>@@ -1125,6 +1160,16 @@ static void test_stream_virtio_skb_merge_server(const struct test_opts *opts)
> 	close(fd);
> }
>
>+static void test_seqpacket_msg_peek_client(const struct test_opts *opts)
>+{
>+	return test_msg_peek_client(opts, true);
>+}
>+
>+static void test_seqpacket_msg_peek_server(const struct test_opts *opts)
>+{
>+	return test_msg_peek_server(opts, true);
>+}
>+
> static struct test_case test_cases[] = {
> 	{
> 		.name = "SOCK_STREAM connection reset",
>@@ -1200,6 +1245,11 @@ static struct test_case test_cases[] = {
> 		.run_client = test_stream_virtio_skb_merge_client,
> 		.run_server = test_stream_virtio_skb_merge_server,
> 	},
>+	{
>+		.name = "SOCK_SEQPACKET MSG_PEEK",
>+		.run_client = test_seqpacket_msg_peek_client,
>+		.run_server = test_seqpacket_msg_peek_server,
>+	},
> 	{},
> };
>
>-- 
>2.25.1
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v3 0/4] virtio/vsock: some updates for MSG_PEEK flag
       [not found] <20230725172912.1659970-1-AVKrasnov@sberdevices.ru>
       [not found] ` <20230725172912.1659970-5-AVKrasnov@sberdevices.ru>
@ 2023-07-26 10:02 ` Michael S. Tsirkin
  1 sibling, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2023-07-26 10:02 UTC (permalink / raw)
  To: Arseniy Krasnov
  Cc: Bobby Eshleman, kvm, netdev, linux-kernel, virtualization,
	oxffffaa, Eric Dumazet, Stefan Hajnoczi, kernel, Jakub Kicinski,
	Paolo Abeni, David S. Miller

On Tue, Jul 25, 2023 at 08:29:08PM +0300, Arseniy Krasnov wrote:
> Hello,
> 
> This patchset does several things around MSG_PEEK flag support. In
> general words it reworks MSG_PEEK test and adds support for this flag
> in SOCK_SEQPACKET logic. Here is per-patch description:
> 
> 1) This is cosmetic change for SOCK_STREAM implementation of MSG_PEEK:
>    1) I think there is no need of "safe" mode walk here as there is no
>       "unlink" of skbs inside loop (it is MSG_PEEK mode - we don't change
>       queue).
>    2) Nested while loop is removed: in case of MSG_PEEK we just walk
>       over skbs and copy data from each one. I guess this nested loop
>       even didn't behave as loop - it always executed just for single
>       iteration.
> 
> 2) This adds MSG_PEEK support for SOCK_SEQPACKET. It could be implemented
>    be reworking MSG_PEEK callback for SOCK_STREAM to support SOCK_SEQPACKET
>    also, but I think it will be more simple and clear from potential
>    bugs to implemented it as separate function thus not mixing logics
>    for both types of socket. So I've added it as dedicated function.
> 
> 3) This is reworked MSG_PEEK test for SOCK_STREAM. Previous version just
>    sent single byte, then tried to read it with MSG_PEEK flag, then read
>    it in normal way. New version is more complex: now sender uses buffer
>    instead of single byte and this buffer is initialized with random
>    values. Receiver tests several things:
>    1) Read empty socket with MSG_PEEK flag.
>    2) Read part of buffer with MSG_PEEK flag.
>    3) Read whole buffer with MSG_PEEK flag, then checks that it is same
>       as buffer from 2) (limited by size of buffer from 2) of course).
>    4) Read whole buffer without any flags, then checks that it is same
>       as buffer from 3).
> 
> 4) This is MSG_PEEK test for SOCK_SEQPACKET. It works in the same way
>    as for SOCK_STREAM, except it also checks combination of MSG_TRUNC
>    and MSG_PEEK.

Acked-by: Michael S. Tsirkin <mst@redhat.com>



> Head is:
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=a5a91f546444940f3d75e2edf3c53b4d235f0557
> 
> Link to v1:
> https://lore.kernel.org/netdev/20230618062451.79980-1-AVKrasnov@sberdevices.ru/
> Link to v2:
> https://lore.kernel.org/netdev/20230719192708.1775162-1-AVKrasnov@sberdevices.ru/
> 
> Changelog:
>  v1 -> v2:
>  * Patchset is rebased on the new HEAD of net-next.
>  * 0001: R-b tag added.
>  * 0003: check return value of 'send()' call. 
>  v2 -> v3:
>  * Patchset is rebased (and tested) on the new HEAD of net-next.
>  * 'RFC' tag is replaced with 'net-next'.
>  * Small refactoring in 0004:
>    '__test_msg_peek_client()' -> 'test_msg_peek_client()'.
>    '__test_msg_peek_server()' -> 'test_msg_peek_server()'.
> 
> Arseniy Krasnov (4):
>   virtio/vsock: rework MSG_PEEK for SOCK_STREAM
>   virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET
>   vsock/test: rework MSG_PEEK test for SOCK_STREAM
>   vsock/test: MSG_PEEK test for SOCK_SEQPACKET
> 
>  net/vmw_vsock/virtio_transport_common.c | 104 +++++++++++++-----
>  tools/testing/vsock/vsock_test.c        | 136 ++++++++++++++++++++++--
>  2 files changed, 208 insertions(+), 32 deletions(-)
> 
> -- 
> 2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-26 10:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20230725172912.1659970-1-AVKrasnov@sberdevices.ru>
     [not found] ` <20230725172912.1659970-5-AVKrasnov@sberdevices.ru>
2023-07-26  8:04   ` [PATCH net-next v3 4/4] vsock/test: MSG_PEEK test for SOCK_SEQPACKET Stefano Garzarella
2023-07-26 10:02 ` [PATCH net-next v3 0/4] virtio/vsock: some updates for MSG_PEEK flag Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).