From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1599CA0EE4 for ; Wed, 20 Aug 2025 20:34:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uopVV-0000QU-Lh; Wed, 20 Aug 2025 16:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uopVT-0000Q6-P4 for qemu-devel@nongnu.org; Wed, 20 Aug 2025 16:34:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uopVP-0007Cn-9o for qemu-devel@nongnu.org; Wed, 20 Aug 2025 16:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755722037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jovcwANNoyjMqJxEjSq/7M8PDmUHrLrsGlVQN6jkfOs=; b=SWGEH4dUSTZ6c7Q6ax8Me5VSEz4fvbhLAQ3yjITWHukPxN8UkSUn7G2mIbvHm9+M/6nk2k WsM/Ubbv5uKwmtXmIO7Q/MsHQUe3jMLv34T0hqwOiA5KbREGkLes1OkTWSC/lnyTGiTwlq lhRy5qX0nft6uoa/CniIIgcSmkDbwEk= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-YIDE4Ha5ODWVWCiEiOGh4g-1; Wed, 20 Aug 2025 16:33:53 -0400 X-MC-Unique: YIDE4Ha5ODWVWCiEiOGh4g-1 X-Mimecast-MFC-AGG-ID: YIDE4Ha5ODWVWCiEiOGh4g_1755722032 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 35C87180035D; Wed, 20 Aug 2025 20:33:52 +0000 (UTC) Received: from localhost (unknown [10.2.16.103]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 261361800447; Wed, 20 Aug 2025 20:33:49 +0000 (UTC) Date: Wed, 20 Aug 2025 16:33:48 -0400 From: Stefan Hajnoczi To: Albert Esteve Cc: qemu-devel@nongnu.org, david@redhat.com, "Michael S. Tsirkin" , hi@alyssa.is, jasowang@redhat.com, Laurent Vivier , dbassey@redhat.com, Stefano Garzarella , Paolo Bonzini , stevensd@chromium.org, Fabiano Rosas , Alex =?iso-8859-1?Q?Benn=E9e?= , slp@redhat.com Subject: Re: [PATCH v7 6/8] tests/qtest: Add GET_SHMEM validation test Message-ID: <20250820203348.GA131468@fedora> References: <20250818100353.1560655-1-aesteve@redhat.com> <20250818100353.1560655-7-aesteve@redhat.com> <20250818231438.GA30271@fedora> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fwNPydEZ8IKHHnmi" Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org --fwNPydEZ8IKHHnmi Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 19, 2025 at 02:16:47PM +0200, Albert Esteve wrote: > On Tue, Aug 19, 2025 at 12:42=E2=80=AFPM Stefan Hajnoczi wrote: > > > > On Mon, Aug 18, 2025 at 12:03:51PM +0200, Albert Esteve wrote: > > > Improve vhost-user-test to properly validate > > > VHOST_USER_GET_SHMEM_CONFIG message handling by > > > directly simulating the message exchange. > > > > > > The test manually triggers the > > > VHOST_USER_GET_SHMEM_CONFIG message by calling > > > chr_read() with a crafted VhostUserMsg, allowing direct > > > validation of the shmem configuration response handler. > > > > It looks like this test case invokes its own chr_read() function without > > going through QEMU, so I don't understand what this is testing? >=20 > I spent some time trying to test it, but in the end I could not > instatiate vhost-user-device because it is non user_creatable. I did > not find any test for vhost-user-device anywhere else either. But I > had already added most of the infrastructure here so I fallback to > chr_read() communication to avoid having to delete everything. My > though was that once we have other devices that use shared memory, > they could tweak the test to instantiate the proper device and test > this and the map/unmap operations. >=20 > Although after writing this, I think other devices will actually a > specific layout for their shared memory. So > VHOST_USER_GET_SHMEM_CONFIG is only ever going to be used by > vhost-user-device. >=20 > In general, trying to test this patch series has been a headache other > than trying with external device code I have. If you have an idea that > I could try to test this, I can try. Otherwise, probably is best to > remove this commit from the series and wait for another vhost-user > device that uses map/unmap to land to be able to test it. Alex Bennee has renamed vhost-user-device to vhost-user-test-device and set user_creatable =3D true: https://lore.kernel.org/qemu-devel/20250820195632.1956795-1-alex.bennee@lin= aro.org/T/#t >=20 >=20 >=20 > > > > > > > > Added TestServerShmem structure to track shmem > > > configuration state, including nregions_sent and > > > sizes_sent arrays for comprehensive validation. > > > The test verifies that the response contains the expected > > > number of shared memory regions and their corresponding > > > sizes. > > > > > > Signed-off-by: Albert Esteve > > > --- > > > tests/qtest/vhost-user-test.c | 91 +++++++++++++++++++++++++++++++++= ++ > > > 1 file changed, 91 insertions(+) > > > > > > diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-t= est.c > > > index 75cb3e44b2..44a5e90b2e 100644 > > > --- a/tests/qtest/vhost-user-test.c > > > +++ b/tests/qtest/vhost-user-test.c > > > @@ -88,6 +88,7 @@ typedef enum VhostUserRequest { > > > VHOST_USER_SET_VRING_ENABLE =3D 18, > > > VHOST_USER_GET_CONFIG =3D 24, > > > VHOST_USER_SET_CONFIG =3D 25, > > > + VHOST_USER_GET_SHMEM_CONFIG =3D 44, > > > VHOST_USER_MAX > > > } VhostUserRequest; > > > > > > @@ -109,6 +110,20 @@ typedef struct VhostUserLog { > > > uint64_t mmap_offset; > > > } VhostUserLog; > > > > > > +#define VIRTIO_MAX_SHMEM_REGIONS 256 > > > + > > > +typedef struct VhostUserShMemConfig { > > > + uint32_t nregions; > > > + uint32_t padding; > > > + uint64_t memory_sizes[VIRTIO_MAX_SHMEM_REGIONS]; > > > +} VhostUserShMemConfig; > > > + > > > +typedef struct TestServerShmem { > > > + bool test_enabled; > > > + uint32_t nregions_sent; > > > + uint64_t sizes_sent[VIRTIO_MAX_SHMEM_REGIONS]; > > > +} TestServerShmem; > > > + > > > typedef struct VhostUserMsg { > > > VhostUserRequest request; > > > > > > @@ -124,6 +139,7 @@ typedef struct VhostUserMsg { > > > struct vhost_vring_addr addr; > > > VhostUserMemory memory; > > > VhostUserLog log; > > > + VhostUserShMemConfig shmem; > > > } payload; > > > } QEMU_PACKED VhostUserMsg; > > > > > > @@ -170,6 +186,7 @@ typedef struct TestServer { > > > bool test_fail; > > > int test_flags; > > > int queues; > > > + TestServerShmem shmem; > > > struct vhost_user_ops *vu_ops; > > > } TestServer; > > > > > > @@ -513,6 +530,31 @@ static void chr_read(void *opaque, const uint8_t= *buf, int size) > > > qos_printf("set_vring(%d)=3D%s\n", msg.payload.state.index, > > > msg.payload.state.num ? "enabled" : "disabled"); > > > break; > > > + > > > + case VHOST_USER_GET_SHMEM_CONFIG: > > > + if (!s->shmem.test_enabled) { > > > + /* Reply with error if shmem feature not enabled */ > > > + msg.flags |=3D VHOST_USER_REPLY_MASK; > > > + msg.size =3D sizeof(uint64_t); > > > + msg.payload.u64 =3D -1; /* Error */ > > > + qemu_chr_fe_write_all(chr, (uint8_t *) &msg, VHOST_USER_= HDR_SIZE + msg.size); > > > + } else { > > > + /* Reply with test shmem configuration */ > > > + msg.flags |=3D VHOST_USER_REPLY_MASK; > > > + msg.size =3D sizeof(VhostUserShMemConfig); > > > + msg.payload.shmem.nregions =3D 2; /* Test with 2 regions= */ > > > + msg.payload.shmem.padding =3D 0; > > > + msg.payload.shmem.memory_sizes[0] =3D 0x100000; /* 1MB */ > > > + msg.payload.shmem.memory_sizes[1] =3D 0x200000; /* 2MB */ > > > + > > > + /* Record what we're sending for test validation */ > > > + s->shmem.nregions_sent =3D msg.payload.shmem.nregions; > > > + s->shmem.sizes_sent[0] =3D msg.payload.shmem.memory_size= s[0]; > > > + s->shmem.sizes_sent[1] =3D msg.payload.shmem.memory_size= s[1]; > > > + > > > + qemu_chr_fe_write_all(chr, (uint8_t *) &msg, VHOST_USER_= HDR_SIZE + msg.size); > > > + } > > > + break; > > > > > > default: > > > qos_printf("vhost-user: un-handled message: %d\n", msg.reque= st); > > > @@ -809,6 +851,22 @@ static void *vhost_user_test_setup_shm(GString *= cmd_line, void *arg) > > > return server; > > > } > > > > > > +static void *vhost_user_test_setup_shmem_config(GString *cmd_line, v= oid *arg) > > > +{ > > > + TestServer *server =3D test_server_new("vhost-user-test", arg); > > > + test_server_listen(server); > > > + > > > + /* Enable shmem testing for this server */ > > > + server->shmem.test_enabled =3D true; > > > + > > > + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_SHM); > > > + server->vu_ops->append_opts(server, cmd_line, ""); > > > + > > > + g_test_queue_destroy(vhost_user_test_cleanup, server); > > > + > > > + return server; > > > +} > > > + > > > static void test_read_guest_mem(void *obj, void *arg, QGuestAllocato= r *alloc) > > > { > > > TestServer *server =3D arg; > > > @@ -1089,6 +1147,33 @@ static struct vhost_user_ops g_vu_net_ops =3D { > > > .get_protocol_features =3D vu_net_get_protocol_features, > > > }; > > > > > > +/* Test function for VHOST_USER_GET_SHMEM_CONFIG message */ > > > +static void test_shmem_config(void *obj, void *arg, QGuestAllocator = *alloc) > > > +{ > > > + TestServer *s =3D arg; > > > + > > > + g_assert_true(s->shmem.test_enabled); > > > + > > > + g_mutex_lock(&s->data_mutex); > > > + s->shmem.nregions_sent =3D 0; > > > + s->shmem.sizes_sent[0] =3D 0; > > > + s->shmem.sizes_sent[1] =3D 0; > > > + g_mutex_unlock(&s->data_mutex); > > > + > > > + VhostUserMsg msg =3D { > > > + .request =3D VHOST_USER_GET_SHMEM_CONFIG, > > > + .flags =3D VHOST_USER_VERSION, > > > + .size =3D 0, > > > + }; > > > + chr_read(s, (uint8_t *) &msg, VHOST_USER_HDR_SIZE); > > > + > > > + g_mutex_lock(&s->data_mutex); > > > + g_assert_cmpint(s->shmem.nregions_sent, =3D=3D, 2); > > > + g_assert_cmpint(s->shmem.sizes_sent[0], =3D=3D, 0x100000); /* 1M= B */ > > > + g_assert_cmpint(s->shmem.sizes_sent[1], =3D=3D, 0x200000); /* 2M= B */ > > > + g_mutex_unlock(&s->data_mutex); > > > +} > > > + > > > static void register_vhost_user_test(void) > > > { > > > QOSGraphTestOptions opts =3D { > > > @@ -1136,6 +1221,12 @@ static void register_vhost_user_test(void) > > > qos_add_test("vhost-user/multiqueue", > > > "virtio-net", > > > test_multiqueue, &opts); > > > + > > > + opts.before =3D vhost_user_test_setup_shmem_config; > > > + opts.edge.extra_device_opts =3D ""; > > > + qos_add_test("vhost-user/shmem-config", > > > + "virtio-net", > > > + test_shmem_config, &opts); > > > } > > > libqos_init(register_vhost_user_test); > > > > > > -- > > > 2.49.0 > > > >=20 --fwNPydEZ8IKHHnmi Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmimMSwACgkQnKSrs4Gr c8iAywf/QRHoKpH5gqmuSD3yLkeJMy0pIeDKDdkyScbVgCr3Z7pDDQap1PMg8zwK JY7iJY8vchxmevY0ma6MjzgE8UqiJ0NibE2A6OaUSCc64ZktYLOhLzhXJSjiT7uU mcd6DvLWO7CZSpHTUUrN0q6zrb69iL/5h/3NmD9RC0RqUe/yG5mUTXpWgTDbmLiC J3KmiijryQiRCgEz8FY9FfFzUDJFGrazgM8WkgDXPBvygzWlak85ukDdBntCvUKq YOUngLTyNRepQQBaB2gdTbn4sECLM/FMuKuTMi6hj7ky4jvUQr/bHnwby+/poYy/ xoB3tX+BEiDpQh2soTk68hme404SKg== =p0jQ -----END PGP SIGNATURE----- --fwNPydEZ8IKHHnmi--