From nobody Sat Nov 15 10:38:40 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=1753299334; cv=none; d=zohomail.com; s=zohoarc; b=I5kNchHGxfYFDXWsFDJfTfE9+hL+jmZakU7Byu9EG3oqc4YybPQijSjFFppJcqoL+UJR9eWCrQUSRZR8g3f7zSLeU1zR4n0DttHJIyCH4zMMorQctXGZlrtvemV+5j4O7DXuSqZOQpdXRo4N+hezwG03Va5ry9SV4Poz98Yzzbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753299334; 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=oKI0iXRj64UYtvBrRKpLSbTw04ZaavYBd41R6tNYV/I=; b=D1osHuSBEDYmm2+4a/htpTujApzNEE33/d5Cw+oWi0E5kXb8dq66A25H+n9Dxdex3Lei/mnPz3+0RpR1z/8o3AFH001koSj5ealpMYzXV+LiFAoFqsZRUklWW1jP83b7hVWb7gd5FE07mFxxu439kbi8S9K8nlqhveMLQ05ZCJo= 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 1753299334543195.92254247645474; Wed, 23 Jul 2025 12:35:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uefF1-0004Cz-Ns; Wed, 23 Jul 2025 15:35:03 -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 1uefCn-0001zn-DR for qemu-devel@nongnu.org; Wed, 23 Jul 2025 15:32:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uefCl-0005sN-7j for qemu-devel@nongnu.org; Wed, 23 Jul 2025 15:32:45 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-TlcXkp8QNdOF9rwjJ4Q1xQ-1; Wed, 23 Jul 2025 15:32:38 -0400 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 881AA1956046; Wed, 23 Jul 2025 19:32:37 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.32.60]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4FBCC18004AD; Wed, 23 Jul 2025 19:32:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753299162; 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=oKI0iXRj64UYtvBrRKpLSbTw04ZaavYBd41R6tNYV/I=; b=KfSiSCEx/SviZYU+AptPqytkc0gpS1qRc7MAy1Iv7gDFwpFWYOug2xPxg/BM7JmpjrzCGu r8rRBudczr2sbstm8RBfbxfgPwy5RoqmSuKN81KJ4D4y7uweMaICqvyEhxEXftla1zNg9c PR9H5vzbxuB6qV3ztqhZNqnCEpNzxJE= X-MC-Unique: TlcXkp8QNdOF9rwjJ4Q1xQ-1 X-Mimecast-MFC-AGG-ID: TlcXkp8QNdOF9rwjJ4Q1xQ_1753299157 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [RFC PATCH v4 06/14] virtio: add support for negotiating extended features Date: Wed, 23 Jul 2025 21:31:26 +0200 Message-ID: <9c09cad354aaeda4a4925650c782ff7642da593e.1753297661.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.377, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1753299336397116600 Content-Type: text/plain; charset="utf-8" The virtio specifications allows for up to 128 bits for the device features. Soon we are going to use some of the 'extended' bits features for the virtio net driver. Add support to allow extended features negotiation on a per devices basis. Devices willing to negotiated extended features need to implemented a new pair of features getter/setter, the core will conditionally use them instead of the basic one. Note that 'bad_features' don't need to be extended, as they are bound to the 64 bits limit. Signed-off-by: Paolo Abeni --- v3 -> v4: - use new virtio_features macro names v2 -> v3: - _array -> _ex v1 -> v2: - uint128_t -> uint64_t[] --- hw/virtio/virtio-bus.c | 11 ++++++++--- hw/virtio/virtio.c | 18 +++++++++++++----- include/hw/virtio/virtio.h | 4 ++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 11adfbf3ab..cef944e015 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -62,9 +62,14 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error= **errp) } =20 /* Get the features of the plugged device. */ - assert(vdc->get_features !=3D NULL); - vdev->host_features =3D vdc->get_features(vdev, vdev->host_features, - &local_err); + if (vdc->get_features_ex) { + vdc->get_features_ex(vdev, vdev->host_features_ex, &local_err); + } else { + assert(vdc->get_features !=3D NULL); + virtio_features_from_u64(vdev->host_features_ex, + vdc->get_features(vdev, vdev->host_featur= es, + &local_err)); + } if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index c6896e000c..a7c695f633 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3093,7 +3093,9 @@ static int virtio_set_features_nocheck(VirtIODevice *= vdev, const uint64_t *val) bad =3D virtio_features_andnot(tmp, val, vdev->host_features_ex); virtio_features_and(tmp, val, vdev->host_features_ex); =20 - if (k->set_features) { + if (k->set_features_ex) { + k->set_features_ex(vdev, val); + } else if (k->set_features) { bad =3D bad || virtio_features_use_ex(tmp); k->set_features(vdev, tmp[0]); } @@ -3136,9 +3138,8 @@ virtio_set_features_nocheck_maybe_co(VirtIODevice *vd= ev, } } =20 -int virtio_set_features(VirtIODevice *vdev, uint64_t val) +int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *features) { - uint64_t features[VIRTIO_FEATURES_NU64S]; int ret; /* * The driver must not attempt to set features after feature negotiati= on @@ -3148,13 +3149,12 @@ int virtio_set_features(VirtIODevice *vdev, uint64_= t val) return -EINVAL; } =20 - if (val & (1ull << VIRTIO_F_BAD_FEATURE)) { + if (features[0] & (1ull << VIRTIO_F_BAD_FEATURE)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: guest driver for %s has enabled UNUSED(30) feat= ure bit!\n", __func__, vdev->name); } =20 - virtio_features_from_u64(features, val); ret =3D virtio_set_features_nocheck(vdev, features); if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ @@ -3174,6 +3174,14 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t= val) return ret; } =20 +int virtio_set_features(VirtIODevice *vdev, uint64_t val) +{ + uint64_t features[VIRTIO_FEATURES_NU64S]; + + virtio_features_from_u64(features, val); + return virtio_set_features_ex(vdev, features); +} + void virtio_reset(void *opaque) { VirtIODevice *vdev =3D opaque; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 39e4059a66..2aeb021fb3 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -178,6 +178,9 @@ struct VirtioDeviceClass { /* This is what a VirtioDevice must implement */ DeviceRealize realize; DeviceUnrealize unrealize; + void (*get_features_ex)(VirtIODevice *vdev, uint64_t *requested_featur= es, + Error **errp); + void (*set_features_ex)(VirtIODevice *vdev, const uint64_t *val); uint64_t (*get_features)(VirtIODevice *vdev, uint64_t requested_features, Error **errp); @@ -373,6 +376,7 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t qu= eue_index); void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index); void virtio_update_irq(VirtIODevice *vdev); int virtio_set_features(VirtIODevice *vdev, uint64_t val); +int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *val); =20 /* Base devices. */ typedef struct VirtIOBlkConf VirtIOBlkConf; --=20 2.50.0