From nobody Sat Nov 15 22:35:18 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747827437; cv=none; d=zohomail.com; s=zohoarc; b=REdvrM2WmLzTRNY92UpbuSLlpCpUQ5eBLlEH4VczKf/jdFixCiBDPExAbBubAigiZ1SDQA5e48RdL26o1heRPby8vDgIr8Sn3H9lUyhc223ZphoFFgIGgngSpThqVPAI6KkG7G6CR5n5XK60Y/pKQ+WZgt2Lo/7Sxn+OqUKG8UA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747827437; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+5RrZ8gaODIz2f20pZnxWw3ECS5vPxsdWXWwTpC9Sgo=; b=Sl1sckkk/Gnk5FbNHSHdC7ebgaArBMx7dxR/BhKoLLpALf3RyFjrsKubFOCcvQGiqlOHjeY7evSFZ1gCssFDTOMnEKG3UR9lWT+GBPfMrKp7m9GeOXSfmScRpH5whm7s8y0h5VJyJZhfzvFek7bK2sMydu3n2QgdhWSYG9Zi9Jc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174782743709428.385667208169593; Wed, 21 May 2025 04:37:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHhjz-0003dd-8L; Wed, 21 May 2025 07:36:12 -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 1uHhjV-0003bS-Ni for qemu-devel@nongnu.org; Wed, 21 May 2025 07:35:38 -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 1uHhjP-00012r-OY for qemu-devel@nongnu.org; Wed, 21 May 2025 07:35:37 -0400 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-384-XsHL_GJgP4KFnk6LM6jHdw-1; Wed, 21 May 2025 07:35:23 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 ED15C1801A33; Wed, 21 May 2025 11:35:20 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.224.39]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F32F19560B7; Wed, 21 May 2025 11:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747827327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+5RrZ8gaODIz2f20pZnxWw3ECS5vPxsdWXWwTpC9Sgo=; b=gezD3u/WKK7grMpb0CjXEMm7AxNgWFZ7fK48lepiu7aIQJ7zLrKqL30J2fZZ2fIGXQB92I 5LA3mdwbCO9dJ7ADIocyYhTR5vGowLWWYMBn9Kjd38hn1aV0jtAeXDABjDsQ1B49//C6fl feS9VsEbR93498SlGtE3WHFMbXhBJfg= X-MC-Unique: XsHL_GJgP4KFnk6LM6jHdw-1 X-Mimecast-MFC-AGG-ID: XsHL_GJgP4KFnk6LM6jHdw_1747827321 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Peter Xu , Fabiano Rosas , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC 04/16] virtio: serialize extended features state Date: Wed, 21 May 2025 13:33:58 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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_NONE=0.001, T_SPF_TEMPERROR=0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747827439668116600 Content-Type: text/plain; charset="utf-8" If the host supports 128 bit-wide features, and the driver use any of them, serialize the full features range leveraging newly introduced 128bits integer helpers. Signed-off-by: Paolo Abeni --- hw/virtio/virtio.c | 76 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 701f59884d..ef15a1835e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2982,6 +2982,26 @@ static const VMStateDescription vmstate_virtio_disab= led =3D { } }; =20 +#ifdef CONFIG_INT128 +static bool virtio_128bit_features_needed(void *opaque) +{ + VirtIODevice *vdev =3D opaque; + + return (vdev->host_features_ex >> 64) !=3D 0; +} + +static const VMStateDescription vmstate_virtio_128bit_features =3D { + .name =3D "virtio/128bit_features", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D &virtio_128bit_features_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT128(guest_features_ex, VirtIODevice), + VMSTATE_END_OF_LIST() + } +}; +#endif + static const VMStateDescription vmstate_virtio =3D { .name =3D "virtio", .version_id =3D 1, @@ -2991,6 +3011,9 @@ static const VMStateDescription vmstate_virtio =3D { }, .subsections =3D (const VMStateDescription * const []) { &vmstate_virtio_device_endian, +#ifdef CONFIG_INT128 + &vmstate_virtio_128bit_features, +#endif &vmstate_virtio_64bit_features, &vmstate_virtio_virtqueues, &vmstate_virtio_ringsize, @@ -3087,7 +3110,8 @@ const VMStateInfo virtio_vmstate_info =3D { .put =3D virtio_device_put, }; =20 -static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val) +static int virtio_set_features_nocheck(VirtIODevice *vdev, + virtio_features_t val) { VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); bool bad =3D (val & ~(vdev->host_features)) !=3D 0; @@ -3133,6 +3157,42 @@ virtio_set_features_nocheck_maybe_co(VirtIODevice *v= dev, uint64_t val) } } =20 +#ifdef CONFIG_INT128 +typedef struct VirtioSetFeaturesExNocheckData { + Coroutine *co; + VirtIODevice *vdev; + __uint128_t val; + int ret; +} VirtioSetFeaturesExNocheckData; + +static void virtio_set_features_ex_nocheck_bh(void *opaque) +{ + VirtioSetFeaturesExNocheckData *data =3D opaque; + + data->ret =3D virtio_set_features_nocheck(data->vdev, data->val); + aio_co_wake(data->co); +} + +static int coroutine_mixed_fn +virtio_set_features_ex_nocheck_maybe_co(VirtIODevice *vdev, __uint128_t va= l) +{ + if (qemu_in_coroutine()) { + VirtioSetFeaturesExNocheckData data =3D { + .co =3D qemu_coroutine_self(), + .vdev =3D vdev, + .val =3D val, + }; + aio_bh_schedule_oneshot(qemu_get_current_aio_context(), + virtio_set_features_ex_nocheck_bh, &data); + qemu_coroutine_yield(); + return data.ret; + } else { + return virtio_set_features_nocheck(vdev, val); + } +} + +#endif + int virtio_set_features(VirtIODevice *vdev, uint64_t val) { int ret; @@ -3318,6 +3378,20 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ver= sion_id) vdev->device_endian =3D virtio_default_endian(); } =20 +#ifdef CONFIG_INT128 + if (virtio_128bit_features_needed(vdev)) { + __int128_t features128 =3D vdev->guest_features_ex; + if (virtio_set_features_ex_nocheck_maybe_co(vdev, features128) < 0= ) { + error_report("Features 0x" VIRTIO_FEATURES_FMT " unsupported. " + "Allowed features: 0x" VIRTIO_FEATURES_FMT, + VIRTIO_FEATURES_HI(features128), + VIRTIO_FEATURES_LOW(features128), + VIRTIO_FEATURES_HI(vdev->host_features_ex), + VIRTIO_FEATURES_LOW(vdev->host_features_ex)); + return -1; + } + } else +#endif if (virtio_64bit_features_needed(vdev)) { /* * Subsection load filled vdev->guest_features. Run them --=20 2.49.0