From nobody Tue Feb 10 20:28:23 2026 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674071304; cv=none; d=zohomail.com; s=zohoarc; b=NEJT3PGpQkzBowTi/ozEpZaHCP1lCG2cKHP7WL70nlT98/JKlLCoHJP4U/K0mIaXfgLB9dnhM/rgNTG5uvsm91RflJg8LQ6riDr2KPPzFgQk1MAFOpw6HsMcpHNfUipXO/rk6VNMN9cKUJLKbhyj2EsgCF0s+gc5J3vuAsPPpQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674071304; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K6bqAuqOMKjHHYbIvIDoBonaoMQyPqF/T5JIdhlQRQ0=; b=JFhhDoNt27b52HhS29UOFjg5KlbqXDiBjH69iZIVzKwNWoFNOXS7uEg5SIVW4d1Nj0cET8vAJJQoF9oF67MGM8yD0U1MojQXSZUB0OLjBAyS9CFMLikw5CL9YDjKboGGFSQRJV7lMjS04ccqR98u9tZW04GLxd5724LolZp1v0U= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674071304497588.2136084546003; Wed, 18 Jan 2023 11:48:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIEPU-0002ep-FQ; Wed, 18 Jan 2023 14:47:48 -0500 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 1pIEPT-0002eG-3I for qemu-devel@nongnu.org; Wed, 18 Jan 2023 14:47:47 -0500 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 1pIEPR-0000ov-HY for qemu-devel@nongnu.org; Wed, 18 Jan 2023 14:47:46 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-lWTLAecRNOaYvz01pz48hQ-1; Wed, 18 Jan 2023 14:47:41 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71F5F1C0513C; Wed, 18 Jan 2023 19:47:41 +0000 (UTC) Received: from localhost (unknown [10.39.192.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA33A40C6EC4; Wed, 18 Jan 2023 19:47:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674071265; 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=K6bqAuqOMKjHHYbIvIDoBonaoMQyPqF/T5JIdhlQRQ0=; b=KOOGp4SAiY2E9ClMpJ6wXzkVPcvhKQzWl82qmocacDaItODY7rHzbcmlmsEePCALShwidC mIvPnMfGlbiPds2Q3w9JKlNpqj6L3elzjDLmNuxAaiR9EpSyMTggEnpSSb2w1JBX9Qc7ow biAR0bA0IuQ4vdkoh6AY2Ubr9nbhDWs= X-MC-Unique: lWTLAecRNOaYvz01pz48hQ-1 From: Stefan Hajnoczi To: Cc: Kevin Wolf , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Hanna Reitz , Markus Armbruster , Paolo Bonzini , Emanuele Giuseppe Esposito , qemu-block@nongnu.org, Eric Blake , Stefan Hajnoczi , "Michael S. Tsirkin" , Michal Privoznik Subject: [RFC 3/3] virtio-blk: add iothread-vq-mapping parameter Date: Wed, 18 Jan 2023 14:47:32 -0500 Message-Id: <20230118194732.1258208-4-stefanha@redhat.com> In-Reply-To: <20230118194732.1258208-1-stefanha@redhat.com> References: <20230118194732.1258208-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1674071305717100001 Content-Type: text/plain; charset="utf-8" Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Note that this commit simply adds the VirtIOBlock->iothread_vq_mapping_list field but does not use it yet. The block layer doesn't support multi-queue yet, so we cannot safely process virtqueues from multiple IOThreads at this time. Signed-off-by: Stefan Hajnoczi --- include/hw/virtio/virtio-blk.h | 2 + hw/block/virtio-blk.c | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 7f589b4146..7324f4468f 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -21,6 +21,7 @@ #include "sysemu/block-backend.h" #include "sysemu/block-ram-registrar.h" #include "qom/object.h" +#include "qapi/qapi-types-virtio.h" =20 #define TYPE_VIRTIO_BLK "virtio-blk-device" OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock, VIRTIO_BLK) @@ -37,6 +38,7 @@ struct VirtIOBlkConf { BlockConf conf; IOThread *iothread; + IOThreadVirtQueueMappingList *iothread_vq_mapping_list; char *serial; uint32_t request_merging; uint16_t num_queues; diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f717550fdc..ed53dc3686 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1098,6 +1098,68 @@ static int virtio_blk_load_device(VirtIODevice *vdev= , QEMUFile *f, return 0; } =20 +static bool +validate_iothread_vq_mapping_list(IOThreadVirtQueueMappingList *list, + uint16_t num_queues, Error **errp) +{ + g_autofree unsigned long *vqs =3D bitmap_new(num_queues); + g_autoptr(GHashTable) iothreads =3D + g_hash_table_new(g_str_hash, g_str_equal); + + for (IOThreadVirtQueueMappingList *node =3D list; node; node =3D node-= >next) { + const char *name =3D node->value->iothread; + uint16List *vq; + + if (!iothread_by_id(name)) { + error_setg(errp, "IOThread \"%s\" object does not exist", name= ); + return false; + } + + if (!g_hash_table_add(iothreads, (gpointer)name)) { + error_setg(errp, + "duplicate IOThread name \"%s\" in iothread-vq-mapping= ", + name); + return false; + } + + if (node !=3D list) { + if (!!node->value->vqs !=3D !!list->value->vqs) { + error_setg(errp, "either all items in iothread-vq-mapping " + "must have vqs or none of them must have = it"); + return false; + } + } + + for (vq =3D node->value->vqs; vq; vq =3D vq->next) { + if (vq->value >=3D num_queues) { + error_setg(errp, "vq index %u for IOThread \"%s\" must be " + "less than num_queues %u in iothread-vq-mapping", + vq->value, name, num_queues); + return false; + } + + if (test_and_set_bit(vq->value, vqs)) { + error_setg(errp, "cannot assign vq %u to IOThread \"%s\" " + "because it is already assigned", vq->value, name); + return false; + } + } + } + + if (list->value->vqs) { + for (uint16_t i =3D 0; i < num_queues; i++) { + if (!test_bit(i, vqs)) { + error_setg(errp, + "missing vq %u IOThread assignment in iothread-vq-= mapping", + i); + return false; + } + } + } + + return true; +} + static void virtio_resize_cb(void *opaque) { VirtIODevice *vdev =3D opaque; @@ -1191,6 +1253,19 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (s->conf.iothread_vq_mapping_list) { + if (s->conf.iothread) { + error_setg(errp, "iothread and iothread-vq-mapping properties " + "cannot be set at the same time"); + return; + } + + if (!validate_iothread_vq_mapping_list(s->conf.iothread_vq_mapping= _list, + s->conf.num_queues, errp)) { + return; + } + } + s->config_size =3D virtio_get_config_size(&virtio_blk_cfg_size_params, s->host_features); virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size); @@ -1203,6 +1278,7 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) virtio_add_queue(vdev, conf->queue_size, virtio_blk_handle_output); } qemu_coroutine_inc_pool_size(conf->num_queues * conf->queue_size / 2); + /* TODO use iothread_vq_mapping_list */ virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err); if (err !=3D NULL) { error_propagate(errp, err); @@ -1284,6 +1360,8 @@ static Property virtio_blk_properties[] =3D { DEFINE_PROP_BOOL("seg-max-adjust", VirtIOBlock, conf.seg_max_adjust, t= rue), DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, IOThread *), + DEFINE_PROP_IOTHREAD_VQ_MAPPING_LIST("iothread-vq-mapping", VirtIOBloc= k, + conf.iothread_vq_mapping_list), DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features, VIRTIO_BLK_F_DISCARD, true), DEFINE_PROP_BOOL("report-discard-granularity", VirtIOBlock, --=20 2.39.0