From nobody Fri May 17 07:08:01 2024 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=1703080119; cv=none; d=zohomail.com; s=zohoarc; b=not7BVL5s9Ho+eui1Jw4zDCYecucms19MyUMC7s6M3yPYI7d4eLVBRt6D+FzT6dQf/VMz1Tt3AgZa5Q3KuEzwKGdEivVW+A46YibRQFKzJSc7xX28JTMNXiKnVLMJcORka0A5fv908sUO1KDON75sBM/I0ckIoeyDuxOvRGVQzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703080119; 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=aJp28RWD0Bmd2/0WGTsegmzATzRz3IZpSu80iClxoG4=; b=P5gJCYgp6JgkQKjtAX9CoIVLsLkGHF1kmb9q1Tg1IWO1yfmS3RSJkPsTlxp3Jy+10W18r2CZ6cY+ENEvvk+ic8iiIpadUGCdFqSVvuvNx2hjkgysTCm98405mB/kSPOakHhNpWZMXSTfgqXtXA+55iq6RYYhYLvVzzQvYnGHilI= 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 1703080119875227.262304677746; Wed, 20 Dec 2023 05:48:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFwvf-0003Un-Td; Wed, 20 Dec 2023 08:48:07 -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 1rFwve-0003U7-Ke for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:06 -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 1rFwvc-00064n-Nj for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:06 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-176-EwxXrXhINqK04qDAxKOoDQ-1; Wed, 20 Dec 2023 08:48:00 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 99EB085A58C; Wed, 20 Dec 2023 13:48:00 +0000 (UTC) Received: from localhost (unknown [10.39.192.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id F39DD40C6EBC; Wed, 20 Dec 2023 13:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703080084; 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=aJp28RWD0Bmd2/0WGTsegmzATzRz3IZpSu80iClxoG4=; b=YJatt6FamN8hp9AYRfYmENHYxJF1RmjJ+m/jj7M0hJiBVkmAaKfxLxqBxQa+yIjegZGG9G xw3jbaoEZht8TVQlH2SelnyvoPK1kD3EzxlrQAEOK4PkIBi+f3FUEt50F3P81T9nnspNE8 eIy+y++pmU0FsnRHXCT13OstTZs6H1w= X-MC-Unique: EwxXrXhINqK04qDAxKOoDQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Michal Privoznik , Kevin Wolf , Hanna Reitz , , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Michael Roth , Eduardo Habkost , Eric Blake , Markus Armbruster , Paolo Bonzini Subject: [PATCH v4 1/4] qdev-properties: alias all object class properties Date: Wed, 20 Dec 2023 08:47:52 -0500 Message-ID: <20231220134755.814917-2-stefanha@redhat.com> In-Reply-To: <20231220134755.814917-1-stefanha@redhat.com> References: <20231220134755.814917-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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: 1703080121061100002 Content-Type: text/plain; charset="utf-8" qdev_alias_all_properties() aliases a DeviceState's qdev properties onto an Object. This is used for VirtioPCIProxy types so that --device virtio-blk-pci has properties of its embedded --device virtio-blk-device object. Currently this function is implemented using qdev properties. Change the function to use QOM object class properties instead. This works because qdev properties create QOM object class properties, but it also catches any QOM object class-only properties that have no qdev properties. This change ensures that properties of devices are shown with --device foo,\? even if they are QOM object class properties. Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- hw/core/qdev-properties.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 840006e953..7d6fa726fd 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1076,16 +1076,18 @@ void device_class_set_props(DeviceClass *dc, Proper= ty *props) void qdev_alias_all_properties(DeviceState *target, Object *source) { ObjectClass *class; - Property *prop; + ObjectPropertyIterator iter; + ObjectProperty *prop; =20 class =3D object_get_class(OBJECT(target)); - do { - DeviceClass *dc =3D DEVICE_CLASS(class); =20 - for (prop =3D dc->props_; prop && prop->name; prop++) { - object_property_add_alias(source, prop->name, - OBJECT(target), prop->name); + object_class_property_iter_init(&iter, class); + while ((prop =3D object_property_iter_next(&iter))) { + if (object_property_find(source, prop->name)) { + continue; /* skip duplicate properties */ } - class =3D object_class_get_parent(class); - } while (class !=3D object_class_by_name(TYPE_DEVICE)); + + object_property_add_alias(source, prop->name, + OBJECT(target), prop->name); + } } --=20 2.43.0 From nobody Fri May 17 07:08:01 2024 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=1703080165; cv=none; d=zohomail.com; s=zohoarc; b=cmnyszTrVpI5JJPkVa36Yd6WvYVuwupzvQyvE7xQ9CBDUoEZRqCIEr5cnAjpuDXMFaEFCPYa3YuaxduNVK+pPx9qI4/ePa2SPN56mYso2U4fL4usAw7ilYZeLtr5HMwrGpJR1z41yYFCAtvgP1KM4x7uZ/OHgprqUp3T4KhayhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703080165; 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=dIrNM1TF5I8ezOLSZGY6F1DG1/wLrSeiRqVigxRxAvs=; b=g3LvQ3/U02kEzFSeR2IOmlQmZeRIM+uXEEXqjyWI5wiaa8V+6/oMkhseRofFax/OEhH8hXAPsU6IQsMpJqG8rU4suK03bNWzp7tbH9020OSgs//eQS98ulYK9PHDpCNlJgAE5tnkOB9Mtlk5yA/jlZFGXUa+mg5pptSlrW1Bg50= 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 1703080165374126.4112837492388; Wed, 20 Dec 2023 05:49:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFwvj-0003WG-Pr; Wed, 20 Dec 2023 08:48:11 -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 1rFwvg-0003Va-Tx for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:08 -0500 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 1rFwvf-00066X-9H for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:08 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-MX3PdRdCOXCNQARMfilMkg-1; Wed, 20 Dec 2023 08:48:03 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0676B3C32066; Wed, 20 Dec 2023 13:48:03 +0000 (UTC) Received: from localhost (unknown [10.39.192.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D6BF2166B34; Wed, 20 Dec 2023 13:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703080086; 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=dIrNM1TF5I8ezOLSZGY6F1DG1/wLrSeiRqVigxRxAvs=; b=QvFFaRUoMRVVDapFLAzFooX4tv6zKvkcxndgGOmxCjZHHbsnXSFl1LeNKKWPiuXHx6KXtd zvaXUrh9AbOL4R73mj6hRvQMOBMaHHm/qfCAP63hezJsTYiSdxx2w5v+EGBIxglM4jShZn N81igw9qh5EYwnzxVgEuB/JE7ZPQJ2A= X-MC-Unique: MX3PdRdCOXCNQARMfilMkg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Michal Privoznik , Kevin Wolf , Hanna Reitz , , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Michael Roth , Eduardo Habkost , Eric Blake , Markus Armbruster , Paolo Bonzini Subject: [PATCH v4 2/4] string-output-visitor: show structs as "" Date: Wed, 20 Dec 2023 08:47:53 -0500 Message-ID: <20231220134755.814917-3-stefanha@redhat.com> In-Reply-To: <20231220134755.814917-1-stefanha@redhat.com> References: <20231220134755.814917-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1703080167371100007 Content-Type: text/plain; charset="utf-8" StringOutputVisitor crashes when it visits a struct because ->start_struct() is NULL. Show "" instead of crashing. This is necessary because the virtio-blk-pci iothread-vq-mapping parameter that I'd like to introduce soon is a list of IOThreadMapping structs. This patch is a quick fix to solve the crash, but the long-term solution is replacing StringOutputVisitor with something that can handle the full gamut of values in QEMU. Reviewed-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi --- include/qapi/string-output-visitor.h | 6 +++--- qapi/string-output-visitor.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/qapi/string-output-visitor.h b/include/qapi/string-out= put-visitor.h index 268dfe9986..b1ee473b30 100644 --- a/include/qapi/string-output-visitor.h +++ b/include/qapi/string-output-visitor.h @@ -26,9 +26,9 @@ typedef struct StringOutputVisitor StringOutputVisitor; * If everything else succeeds, pass @result to visit_complete() to * collect the result of the visit. * - * The string output visitor does not implement support for visiting - * QAPI structs, alternates, null, or arbitrary QTypes. It also - * requires a non-null list argument to visit_start_list(). + * The string output visitor does not implement support for alternates, nu= ll, + * or arbitrary QTypes. Struct fields are not shown. It also requires a + * non-null list argument to visit_start_list(). */ Visitor *string_output_visitor_new(bool human, char **result); =20 diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index c0cb72dbe4..f0c1dea89e 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -292,6 +292,20 @@ static bool print_type_null(Visitor *v, const char *na= me, QNull **obj, return true; } =20 +static bool start_struct(Visitor *v, const char *name, void **obj, + size_t size, Error **errp) +{ + return true; +} + +static void end_struct(Visitor *v, void **obj) +{ + StringOutputVisitor *sov =3D to_sov(v); + + /* TODO actually print struct fields */ + string_output_set(sov, g_strdup("")); +} + static bool start_list(Visitor *v, const char *name, GenericList **list, size_t size, Error **errp) @@ -379,6 +393,8 @@ Visitor *string_output_visitor_new(bool human, char **r= esult) v->visitor.type_str =3D print_type_str; v->visitor.type_number =3D print_type_number; v->visitor.type_null =3D print_type_null; + v->visitor.start_struct =3D start_struct; + v->visitor.end_struct =3D end_struct; v->visitor.start_list =3D start_list; v->visitor.next_list =3D next_list; v->visitor.end_list =3D end_list; --=20 2.43.0 From nobody Fri May 17 07:08:01 2024 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=1703080133; cv=none; d=zohomail.com; s=zohoarc; b=jnrE0FVFjE5iPzwK+RGlU9B6wy52vxHeE9L/vHG21ZqA0HrUI8tlY2Ab27gfvF1j5xQSoQ6tciFhJoIUY1RVoM1QoKZ63JeoTdnyE9QpIxc/BU5fcMMbsAAClLsqXofF0sDhn8AqgC+wokT3ebiAgat0B6pzDlhLhOYfJFffytE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703080133; 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=8WphHss/lK1vl0Sn+vcq2/xrKctuCv/0iQ7zUFek6Xs=; b=eVh77siJaeuUsktngG+IJV9q78eNF3eOxgzmfJbeiK3gqoHbeIuXVX5HO14rJKlSFikVEqOZC0a12704lfELJEWh3Lghcxtg9wYWJQyOBGQsAjyBnDwuhxVfMbOo28l+V9/CXvwbD/ZixBn7pj35ms/exbb3l9COohoLmISScGY= 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 1703080133093981.3310000608776; Wed, 20 Dec 2023 05:48:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFwvn-0003X2-1V; Wed, 20 Dec 2023 08:48:15 -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 1rFwvj-0003WF-Mb for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:11 -0500 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 1rFwvh-000671-U4 for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:11 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-307-Tfga9LQVNt-lTjuBeDKg-w-1; Wed, 20 Dec 2023 08:48:05 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 84EAD101A52A; Wed, 20 Dec 2023 13:48:05 +0000 (UTC) Received: from localhost (unknown [10.39.192.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01CBA2166B34; Wed, 20 Dec 2023 13:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703080089; 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=8WphHss/lK1vl0Sn+vcq2/xrKctuCv/0iQ7zUFek6Xs=; b=ApXdwmgdE9wcF+ltpqn0l368uG2EpRmSdLkS9Vjc5SCBOc0qOgqSqXq7pJOjYrVRisLWrS gXOemHONC8ZqakADX1zKNbpDJk7T8jbk8Wqadkxg7fbRneTa9ssqwsJfsnJRoLRJMPwr6k E9pVukjEEBcJnyRaiwseKD4YMm5eN1c= X-MC-Unique: Tfga9LQVNt-lTjuBeDKg-w-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Michal Privoznik , Kevin Wolf , Hanna Reitz , , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Michael Roth , Eduardo Habkost , Eric Blake , Markus Armbruster , Paolo Bonzini Subject: [PATCH v4 3/4] qdev: add IOThreadVirtQueueMappingList property type Date: Wed, 20 Dec 2023 08:47:54 -0500 Message-ID: <20231220134755.814917-4-stefanha@redhat.com> In-Reply-To: <20231220134755.814917-1-stefanha@redhat.com> References: <20231220134755.814917-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 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=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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: 1703080135058100003 Content-Type: text/plain; charset="utf-8" virtio-blk and virtio-scsi devices will need a way to specify the mapping between IOThreads and virtqueues. At the moment all virtqueues are assigned to a single IOThread or the main loop. This single thread can be a CPU bottleneck, so it is necessary to allow finer-grained assignment to spread the load. Introduce DEFINE_PROP_IOTHREAD_VQ_MAPPING_LIST() so devices can take a parameter that maps virtqueues to IOThreads. The command-line syntax for this new property is as follows: --device '{"driver":"foo","iothread-vq-mapping":[{"iothread":"iothread0",= "vqs":[0,1,2]},...]}' IOThreads are specified by name and virtqueues are specified by 0-based index. It will be common to simply assign virtqueues round-robin across a set of IOThreads. A convenient syntax that does not require specifying individual virtqueue indices is available: --device '{"driver":"foo","iothread-vq-mapping":[{"iothread":"iothread0"}= ,{"iothread":"iothread1"},...]}' Signed-off-by: Stefan Hajnoczi --- qapi/virtio.json | 29 ++++++++++++++++++ include/hw/qdev-properties-system.h | 5 ++++ hw/core/qdev-properties-system.c | 46 +++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/qapi/virtio.json b/qapi/virtio.json index e6dcee7b83..19c7c36e36 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -928,3 +928,32 @@ 'data': { 'path': 'str', 'queue': 'uint16', '*index': 'uint16' }, 'returns': 'VirtioQueueElement', 'features': [ 'unstable' ] } + +## +# @IOThreadVirtQueueMapping: +# +# Describes the subset of virtqueues assigned to an IOThread. +# +# @iothread: the id of IOThread object +# +# @vqs: an optional array of virtqueue indices that will be handled by this +# IOThread. When absent, virtqueues are assigned round-robin across a= ll +# IOThreadVirtQueueMappings provided. Either all IOThreadVirtQueueMap= pings +# must have @vqs or none of them must have it. +# +# Since: 9.0 +## + +{ 'struct': 'IOThreadVirtQueueMapping', + 'data': { 'iothread': 'str', '*vqs': ['uint16'] } } + +## +# @DummyVirtioForceArrays: +# +# Not used by QMP; hack to let us use IOThreadVirtQueueMappingList interna= lly +# +# Since: 9.0 +## + +{ 'struct': 'DummyVirtioForceArrays', + 'data': { 'unused-iothread-vq-mapping': ['IOThreadVirtQueueMapping'] } } diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properti= es-system.h index 91f7a2452d..06c359c190 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -24,6 +24,7 @@ extern const PropertyInfo qdev_prop_off_auto_pcibar; extern const PropertyInfo qdev_prop_pcie_link_speed; extern const PropertyInfo qdev_prop_pcie_link_width; extern const PropertyInfo qdev_prop_cpus390entitlement; +extern const PropertyInfo qdev_prop_iothread_vq_mapping_list; =20 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) @@ -82,4 +83,8 @@ extern const PropertyInfo qdev_prop_cpus390entitlement; DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_cpus390entitlement, \ CpuS390Entitlement) =20 +#define DEFINE_PROP_IOTHREAD_VQ_MAPPING_LIST(_name, _state, _field) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_iothread_vq_mapping_list,= \ + IOThreadVirtQueueMappingList *) + #endif diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 73cced4626..1a396521d5 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -18,6 +18,7 @@ #include "qapi/qapi-types-block.h" #include "qapi/qapi-types-machine.h" #include "qapi/qapi-types-migration.h" +#include "qapi/qapi-visit-virtio.h" #include "qapi/qmp/qerror.h" #include "qemu/ctype.h" #include "qemu/cutils.h" @@ -1160,3 +1161,48 @@ const PropertyInfo qdev_prop_cpus390entitlement =3D { .set =3D qdev_propinfo_set_enum, .set_default_value =3D qdev_propinfo_set_default_value_enum, }; + +/* --- IOThreadVirtQueueMappingList --- */ + +static void get_iothread_vq_mapping_list(Object *obj, Visitor *v, + const char *name, void *opaque, Error **errp) +{ + IOThreadVirtQueueMappingList **prop_ptr =3D + object_field_prop_ptr(obj, opaque); + + visit_type_IOThreadVirtQueueMappingList(v, name, prop_ptr, errp); +} + +static void set_iothread_vq_mapping_list(Object *obj, Visitor *v, + const char *name, void *opaque, Error **errp) +{ + IOThreadVirtQueueMappingList **prop_ptr =3D + object_field_prop_ptr(obj, opaque); + IOThreadVirtQueueMappingList *list; + + if (!visit_type_IOThreadVirtQueueMappingList(v, name, &list, errp)) { + return; + } + + qapi_free_IOThreadVirtQueueMappingList(*prop_ptr); + *prop_ptr =3D list; +} + +static void release_iothread_vq_mapping_list(Object *obj, + const char *name, void *opaque) +{ + IOThreadVirtQueueMappingList **prop_ptr =3D + object_field_prop_ptr(obj, opaque); + + qapi_free_IOThreadVirtQueueMappingList(*prop_ptr); + *prop_ptr =3D NULL; +} + +const PropertyInfo qdev_prop_iothread_vq_mapping_list =3D { + .name =3D "IOThreadVirtQueueMappingList", + .description =3D "IOThread virtqueue mapping list [{\"iothread\":\"\", " + "\"vqs\":[1,2,3,...]},...]", + .get =3D get_iothread_vq_mapping_list, + .set =3D set_iothread_vq_mapping_list, + .release =3D release_iothread_vq_mapping_list, +}; --=20 2.43.0 From nobody Fri May 17 07:08:01 2024 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=1703080120; cv=none; d=zohomail.com; s=zohoarc; b=IEwHHcHKqHJYo0vnnblCT6z4ix8TzTOAML2aibZd5vGSlCuxJWHGsZya12fUompNacbREsMxhBmcRmba3XajkQ/Q90I9xsN2+zLs+uzSkrMCBDX5G20DlDKDCxgYHbYTlPj1oTg21SNSdvbT+egc2+esfG2ZiWPFb78cVx3gUbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703080120; 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=iSTl8r7MCUEEVF2GX0KDPa3mjieQwODaKzWcob/iH4g=; b=PsjwnpncrihjR5TzvTDIZiqudVOirNEud+euRqtmduUfnmtppJrimkeBsKFJsq0J6NvIyCoPJoV33M0lTHX+0jqo0jIl6ZU2FtyjjyzgtMLLINK7vIbEiNVXf0ZPcx8vQB9Odib9wWEvGIkNC5qgbJ2ujQ/1mdRzDZUYxZ6FClA= 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 1703080120378746.2424660639889; Wed, 20 Dec 2023 05:48:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFwvp-0003Xh-0R; Wed, 20 Dec 2023 08:48:17 -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 1rFwvl-0003Wl-RY for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:13 -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 1rFwvj-00067T-Fz for qemu-devel@nongnu.org; Wed, 20 Dec 2023 08:48:13 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-fByQAsoMOqCu--va_fGIhg-1; Wed, 20 Dec 2023 08:48:08 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id D8FB81C3EA61; Wed, 20 Dec 2023 13:48:07 +0000 (UTC) Received: from localhost (unknown [10.39.192.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11EA751D5; Wed, 20 Dec 2023 13:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703080090; 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=iSTl8r7MCUEEVF2GX0KDPa3mjieQwODaKzWcob/iH4g=; b=Jm9m0mhD9NyktceKBLP3u5sRPyh2LfzYpqPq/j7Lgt73ixnuclTezmux00F/xSxD4T9eVD 9mOqYrZxOp+DK4Tp5bDDqElp8tL9eGcUaSF7FO17r2AiIq4qkRnOw864q2yIXl3EN4oE6G 87mlZvLEFPskyvcCjSkgZlwh45e9XdI= X-MC-Unique: fByQAsoMOqCu--va_fGIhg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Michal Privoznik , Kevin Wolf , Hanna Reitz , , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi , Michael Roth , Eduardo Habkost , Eric Blake , Markus Armbruster , Paolo Bonzini Subject: [PATCH v4 4/4] virtio-blk: add iothread-vq-mapping parameter Date: Wed, 20 Dec 2023 08:47:55 -0500 Message-ID: <20231220134755.814917-5-stefanha@redhat.com> In-Reply-To: <20231220134755.814917-1-stefanha@redhat.com> References: <20231220134755.814917-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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: 1703080121059100001 Content-Type: text/plain; charset="utf-8" Add the iothread-vq-mapping parameter to assign virtqueues to IOThreads. Store the vq:AioContext mapping in the new struct VirtIOBlockDataPlane->vq_aio_context[] field and refactor the code to use the per-vq AioContext instead of the BlockDriverState's AioContext. Reimplement --device virtio-blk-pci,iothread=3D and non-IOThread mode by assigning all virtqueues to the IOThread and main loop's AioContext in vq_aio_context[], respectively. The comment in struct VirtIOBlockDataPlane about EventNotifiers is stale. Remove it. Signed-off-by: Stefan Hajnoczi --- hw/block/dataplane/virtio-blk.h | 3 + include/hw/virtio/virtio-blk.h | 2 + hw/block/dataplane/virtio-blk.c | 155 ++++++++++++++++++++++++-------- hw/block/virtio-blk.c | 92 ++++++++++++++++--- 4 files changed, 202 insertions(+), 50 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.h b/hw/block/dataplane/virtio-bl= k.h index 5e18bb99ae..1a806fe447 100644 --- a/hw/block/dataplane/virtio-blk.h +++ b/hw/block/dataplane/virtio-blk.h @@ -28,4 +28,7 @@ void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *s= , VirtQueue *vq); int virtio_blk_data_plane_start(VirtIODevice *vdev); void virtio_blk_data_plane_stop(VirtIODevice *vdev); =20 +void virtio_blk_data_plane_detach(VirtIOBlockDataPlane *s); +void virtio_blk_data_plane_attach(VirtIOBlockDataPlane *s); + #endif /* HW_DATAPLANE_VIRTIO_BLK_H */ diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 9881009c22..5e4091e4da 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/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 7bbbd981ad..6debd4401e 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -32,13 +32,11 @@ struct VirtIOBlockDataPlane { VirtIOBlkConf *conf; VirtIODevice *vdev; =20 - /* Note that these EventNotifiers are assigned by value. This is - * fine as long as you do not call event_notifier_cleanup on them - * (because you don't own the file descriptor or handle; you just - * use it). + /* + * The AioContext for each virtqueue. The BlockDriverState will use the + * first element as its AioContext. */ - IOThread *iothread; - AioContext *ctx; + AioContext **vq_aio_context; }; =20 /* Raise an interrupt to signal guest, if necessary */ @@ -47,6 +45,45 @@ void virtio_blk_data_plane_notify(VirtIOBlockDataPlane *= s, VirtQueue *vq) virtio_notify_irqfd(s->vdev, vq); } =20 +/* Generate vq:AioContext mappings from a validated iothread-vq-mapping li= st */ +static void +apply_vq_mapping(IOThreadVirtQueueMappingList *iothread_vq_mapping_list, + AioContext **vq_aio_context, uint16_t num_queues) +{ + IOThreadVirtQueueMappingList *node; + size_t num_iothreads =3D 0; + size_t cur_iothread =3D 0; + + for (node =3D iothread_vq_mapping_list; node; node =3D node->next) { + num_iothreads++; + } + + for (node =3D iothread_vq_mapping_list; node; node =3D node->next) { + IOThread *iothread =3D iothread_by_id(node->value->iothread); + AioContext *ctx =3D iothread_get_aio_context(iothread); + + /* Released in virtio_blk_data_plane_destroy() */ + object_ref(OBJECT(iothread)); + + if (node->value->vqs) { + uint16List *vq; + + /* Explicit vq:IOThread assignment */ + for (vq =3D node->value->vqs; vq; vq =3D vq->next) { + vq_aio_context[vq->value] =3D ctx; + } + } else { + /* Round-robin vq:IOThread assignment */ + for (unsigned i =3D cur_iothread; i < num_queues; + i +=3D num_iothreads) { + vq_aio_context[i] =3D ctx; + } + } + + cur_iothread++; + } +} + /* Context: QEMU global mutex held */ bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, VirtIOBlockDataPlane **dataplane, @@ -58,7 +95,7 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, Vir= tIOBlkConf *conf, =20 *dataplane =3D NULL; =20 - if (conf->iothread) { + if (conf->iothread || conf->iothread_vq_mapping_list) { if (!k->set_guest_notifiers || !k->ioeventfd_assign) { error_setg(errp, "device is incompatible with iothread " @@ -86,13 +123,24 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, = VirtIOBlkConf *conf, s =3D g_new0(VirtIOBlockDataPlane, 1); s->vdev =3D vdev; s->conf =3D conf; + s->vq_aio_context =3D g_new(AioContext *, conf->num_queues); =20 - if (conf->iothread) { - s->iothread =3D conf->iothread; - object_ref(OBJECT(s->iothread)); - s->ctx =3D iothread_get_aio_context(s->iothread); + if (conf->iothread_vq_mapping_list) { + apply_vq_mapping(conf->iothread_vq_mapping_list, s->vq_aio_context, + conf->num_queues); + } else if (conf->iothread) { + AioContext *ctx =3D iothread_get_aio_context(conf->iothread); + for (unsigned i =3D 0; i < conf->num_queues; i++) { + s->vq_aio_context[i] =3D ctx; + } + + /* Released in virtio_blk_data_plane_destroy() */ + object_ref(OBJECT(conf->iothread)); } else { - s->ctx =3D qemu_get_aio_context(); + AioContext *ctx =3D qemu_get_aio_context(); + for (unsigned i =3D 0; i < conf->num_queues; i++) { + s->vq_aio_context[i] =3D ctx; + } } =20 *dataplane =3D s; @@ -104,6 +152,7 @@ bool virtio_blk_data_plane_create(VirtIODevice *vdev, V= irtIOBlkConf *conf, void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s) { VirtIOBlock *vblk; + VirtIOBlkConf *conf =3D s->conf; =20 if (!s) { return; @@ -111,9 +160,21 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlan= e *s) =20 vblk =3D VIRTIO_BLK(s->vdev); assert(!vblk->dataplane_started); - if (s->iothread) { - object_unref(OBJECT(s->iothread)); + + if (conf->iothread_vq_mapping_list) { + IOThreadVirtQueueMappingList *node; + + for (node =3D conf->iothread_vq_mapping_list; node; node =3D node-= >next) { + IOThread *iothread =3D iothread_by_id(node->value->iothread); + object_unref(OBJECT(iothread)); + } } + + if (conf->iothread) { + object_unref(OBJECT(conf->iothread)); + } + + g_free(s->vq_aio_context); g_free(s); } =20 @@ -177,19 +238,13 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) =20 trace_virtio_blk_data_plane_start(s); =20 - r =3D blk_set_aio_context(s->conf->conf.blk, s->ctx, &local_err); + r =3D blk_set_aio_context(s->conf->conf.blk, s->vq_aio_context[0], + &local_err); if (r < 0) { error_report_err(local_err); goto fail_aio_context; } =20 - /* Kick right away to begin processing requests already in vring */ - for (i =3D 0; i < nvqs; i++) { - VirtQueue *vq =3D virtio_get_queue(s->vdev, i); - - event_notifier_set(virtio_queue_get_host_notifier(vq)); - } - /* * These fields must be visible to the IOThread when it processes the * virtqueue, otherwise it will think dataplane has not started yet. @@ -206,8 +261,12 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) if (!blk_in_drain(s->conf->conf.blk)) { for (i =3D 0; i < nvqs; i++) { VirtQueue *vq =3D virtio_get_queue(s->vdev, i); + AioContext *ctx =3D s->vq_aio_context[i]; =20 - virtio_queue_aio_attach_host_notifier(vq, s->ctx); + /* Kick right away to begin processing requests already in vri= ng */ + event_notifier_set(virtio_queue_get_host_notifier(vq)); + + virtio_queue_aio_attach_host_notifier(vq, ctx); } } return 0; @@ -236,23 +295,18 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) * * Context: BH in IOThread */ -static void virtio_blk_data_plane_stop_bh(void *opaque) +static void virtio_blk_data_plane_stop_vq_bh(void *opaque) { - VirtIOBlockDataPlane *s =3D opaque; - unsigned i; + VirtQueue *vq =3D opaque; + EventNotifier *host_notifier =3D virtio_queue_get_host_notifier(vq); =20 - for (i =3D 0; i < s->conf->num_queues; i++) { - VirtQueue *vq =3D virtio_get_queue(s->vdev, i); - EventNotifier *host_notifier =3D virtio_queue_get_host_notifier(vq= ); + virtio_queue_aio_detach_host_notifier(vq, qemu_get_current_aio_context= ()); =20 - virtio_queue_aio_detach_host_notifier(vq, s->ctx); - - /* - * Test and clear notifier after disabling event, in case poll cal= lback - * didn't have time to run. - */ - virtio_queue_host_notifier_read(host_notifier); - } + /* + * Test and clear notifier after disabling event, in case poll callback + * didn't have time to run. + */ + virtio_queue_host_notifier_read(host_notifier); } =20 /* Context: QEMU global mutex held */ @@ -279,7 +333,12 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) trace_virtio_blk_data_plane_stop(s); =20 if (!blk_in_drain(s->conf->conf.blk)) { - aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s); + for (i =3D 0; i < nvqs; i++) { + VirtQueue *vq =3D virtio_get_queue(s->vdev, i); + AioContext *ctx =3D s->vq_aio_context[i]; + + aio_wait_bh_oneshot(ctx, virtio_blk_data_plane_stop_vq_bh, vq); + } } =20 /* @@ -322,3 +381,23 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) =20 s->stopping =3D false; } + +void virtio_blk_data_plane_detach(VirtIOBlockDataPlane *s) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(s->vdev); + + for (uint16_t i =3D 0; i < s->conf->num_queues; i++) { + VirtQueue *vq =3D virtio_get_queue(vdev, i); + virtio_queue_aio_detach_host_notifier(vq, s->vq_aio_context[i]); + } +} + +void virtio_blk_data_plane_attach(VirtIOBlockDataPlane *s) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(s->vdev); + + for (uint16_t i =3D 0; i < s->conf->num_queues; i++) { + VirtQueue *vq =3D virtio_get_queue(vdev, i); + virtio_queue_aio_attach_host_notifier(vq, s->vq_aio_context[i]); + } +} diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index ec9ed09a6a..46e73b2c96 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1151,6 +1151,7 @@ static void virtio_blk_handle_output(VirtIODevice *vd= ev, VirtQueue *vq) return; } } + virtio_blk_handle_vq(s, vq); } =20 @@ -1463,6 +1464,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; @@ -1487,34 +1550,24 @@ static void virtio_blk_resize(void *opaque) static void virtio_blk_drained_begin(void *opaque) { VirtIOBlock *s =3D opaque; - VirtIODevice *vdev =3D VIRTIO_DEVICE(opaque); - AioContext *ctx =3D blk_get_aio_context(s->conf.conf.blk); =20 if (!s->dataplane || !s->dataplane_started) { return; } =20 - for (uint16_t i =3D 0; i < s->conf.num_queues; i++) { - VirtQueue *vq =3D virtio_get_queue(vdev, i); - virtio_queue_aio_detach_host_notifier(vq, ctx); - } + virtio_blk_data_plane_detach(s->dataplane); } =20 /* Resume virtqueue ioeventfd processing after drain */ static void virtio_blk_drained_end(void *opaque) { VirtIOBlock *s =3D opaque; - VirtIODevice *vdev =3D VIRTIO_DEVICE(opaque); - AioContext *ctx =3D blk_get_aio_context(s->conf.conf.blk); =20 if (!s->dataplane || !s->dataplane_started) { return; } =20 - for (uint16_t i =3D 0; i < s->conf.num_queues; i++) { - VirtQueue *vq =3D virtio_get_queue(vdev, i); - virtio_queue_aio_attach_host_notifier(vq, ctx); - } + virtio_blk_data_plane_attach(s->dataplane); } =20 static const BlockDevOps virtio_block_ops =3D { @@ -1600,6 +1653,19 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (conf->iothread_vq_mapping_list) { + if (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(conf->iothread_vq_mapping_l= ist, + 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); @@ -1702,6 +1768,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.43.0