From nobody Mon Feb 9 19:09:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166723323522967.58312374247146; Mon, 31 Oct 2022 09:20:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVg-0006dI-Lv; Mon, 31 Oct 2022 12:19:40 -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 1opXVZ-0006X9-29 for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:33 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opXVT-0001Mt-IK for qemu-devel@nongnu.org; Mon, 31 Oct 2022 12:19:25 -0400 Received: from clientip-182.138.180.88 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id F1C012800EB; Tue, 1 Nov 2022 00:19:19 +0800 (CST) Received: from ([182.138.180.88]) by app0025 with ESMTP id 12140b2b8d884782bed90ebce6c67986 for qemu-devel@nongnu.org; Tue, 01 Nov 2022 00:19:21 CST HMM_SOURCE_IP: 172.18.0.218:50162.1127588867 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 12140b2b8d884782bed90ebce6c67986 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 182.138.180.88 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: "Michael S . Tsirkin" , Jason Wang , Eric Blake , Markus Armbruster , "Dr. David Alan Gilbert" , Thomas Huth , Laurent Vivier , Paolo Bonzini , Stefano Garzarella , Raphael Norwitz , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH RFC 4/4] vhost-user-test: Add negotiated features check Date: Tue, 1 Nov 2022 00:19:02 +0800 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1667233238039100010 From: Hyman Huang(=E9=BB=84=E5=8B=87) For vhost-user network device, Qemu backup the final features as acked_features internally after guest acknowledging features during virtio-net driver initialization, so the acked_features could be used as input of VHOST_USER_SET_FEATURES command when slave device restore from an unexpected failure. Negotiated features check just assert if the acked_features in Qemu is exactly the same as features in vhost slave device, which checks if features are negotiated correctly via vhost user protocol. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- tests/qtest/vhost-user-test.c | 67 +++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 67 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index bf9f7c4..f8bf2fa 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -29,6 +29,9 @@ #include "libqos/qgraph_internal.h" #include "hw/virtio/virtio-net.h" =20 +#include "migration-helpers.h" +#include "qapi/qmp/qlist.h" + #include "standard-headers/linux/vhost_types.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_net.h" @@ -167,6 +170,7 @@ typedef struct TestServer { int test_flags; int queues; struct vhost_user_ops *vu_ops; + uint64_t features; } TestServer; =20 struct vhost_user_ops { @@ -796,6 +800,64 @@ static void test_read_guest_mem(void *obj, void *arg, = QGuestAllocator *alloc) read_guest_mem_server(global_qtest, server); } =20 +static QDict *query_netdev(QTestState *who) +{ + QDict *rsp; + + rsp =3D qtest_qmp(who, "{ 'execute': 'query-netdev' }"); + g_assert(!qdict_haskey(rsp, "error")); + g_assert(qdict_haskey(rsp, "return")); + + return rsp; +} + +static uint64_t get_acked_features(QTestState *who) +{ + QDict *rsp_return; + QList *info_list; + const QListEntry *entry; + QDict *info; + uint64_t acked_features; + + rsp_return =3D query_netdev(who); + g_assert(rsp_return); + + info_list =3D qdict_get_qlist(rsp_return, "return"); + g_assert(info_list && !qlist_empty(info_list)); + + entry =3D qlist_first(info_list); + g_assert(entry); + + info =3D qobject_to(QDict, qlist_entry_obj(entry)); + g_assert(info); + + acked_features =3D qdict_get_try_int(info, "acked-features", 0); + + qobject_unref(rsp_return); + return acked_features; +} + +static void read_acked_features(QTestState *qts, TestServer *s) +{ + uint64_t acked_features; + + acked_features =3D get_acked_features(qts); + g_assert_cmpint(acked_features, =3D=3D, s->features); +} + +static void test_read_acked_features(void *obj, + void *arg, + QGuestAllocator *alloc) +{ + TestServer *server =3D arg; + + if (!wait_for_fds(server)) { + return; + } + + read_acked_features(global_qtest, server); +} + static void test_migrate(void *obj, void *arg, QGuestAllocator *alloc) { TestServer *s =3D arg; @@ -1037,6 +1099,7 @@ static void vu_net_set_features(TestServer *s, CharBa= ckend *chr, qemu_chr_fe_disconnect(chr); s->test_flags =3D TEST_FLAGS_BAD; } + s->features =3D msg->payload.u64; } =20 static void vu_net_get_protocol_features(TestServer *s, CharBackend *chr, @@ -1078,6 +1141,10 @@ static void register_vhost_user_test(void) "virtio-net", test_read_guest_mem, &opts); =20 + qos_add_test("vhost-user/read_acked_features", + "virtio-net", + test_read_acked_features, &opts); + if (qemu_memfd_check(MFD_ALLOW_SEALING)) { opts.before =3D vhost_user_test_setup_memfd; qos_add_test("vhost-user/read-guest-mem/memfd", --=20 1.8.3.1