From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616684940; cv=none; d=zohomail.com; s=zohoarc; b=P1CGterEHPxYL/sqjJtSBZeqFD77oKK0Iozme8p02EcE8YcxujTRTi8vU/MA+RR1SbWGbG+wMYQV/Mb8Ex2P/Kl+W5drNGxypqSDmxJYp/w/dhtDzvq6sIMY0w3Ri0B5Kd3l0RZXzEGhz1fYeSqv+J+kvaE8Xs+VtO0ZAWB7MbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616684940; h=Content-Type: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=zL9taoRaV8xVTH4iqt6e2U/tkQsyJAlEXDkv+7qsWjo=; b=T4L9a16Gre31V21UxUjXyydN8sF8kNQC0GOVXGhJPC6UzPrK1UZ0lICAiVBfL0MImBrs0/+Y5OwU3YC4E+4Uj35Wp8QFVQNA8zIMH7st3RR1n9iQ0jTOR4hi88VO4kG4g8o45z+8L2YBrM+VgHdnmqzD4g0ScgZvlP9y+DXa6oQ= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616684940282473.76542017343183; Thu, 25 Mar 2021 08:09:00 -0700 (PDT) Received: from localhost ([::1]:33458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRbX-0006bM-HB for importer@patchew.org; Thu, 25 Mar 2021 11:08:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaV-0004gg-2t for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:07:55 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:48246) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaT-0007dw-6f for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:07:54 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-mtMwooD0PWSw7_M90LqH7w-1; Thu, 25 Mar 2021 11:07:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A874A1005D57; Thu, 25 Mar 2021 15:07:48 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADFAA5C649; Thu, 25 Mar 2021 15:07:46 +0000 (UTC) X-MC-Unique: mtMwooD0PWSw7_M90LqH7w-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 1/8] memory: Allow eventfd add/del without starting a transaction Date: Thu, 25 Mar 2021 16:07:28 +0100 Message-Id: <20210325150735.1098387-2-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Each addition or deletion of an eventfd happens in its own MR transaction. This doesn't scale well with multiqueue devices that do 1:1 queue:vCPU mapping (e.g. virtio-scsi-pci or virtio-blk-pci) : these devices typically create at least one eventfd per queue and memory_region_transaction_commit(), which is called during commit, also loops on eventfds, resulting in a quadratic time complexity. This calls for batching : a device should be able to add or delete its eventfds in a single transaction. Prepare ground for this by introducing extended versions of memory_region_add_eventfd() and memory_region_del_eventfd() that take an extra bool argument to control if a transaction should be started or not. No behavior change at this point. Signed-off-by: Greg Kurz --- include/exec/memory.h | 48 ++++++++++++++++++++++++++++++++----------- softmmu/memory.c | 42 ++++++++++++++++++++++--------------- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5728a681b27d..98ed552e001c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1848,13 +1848,25 @@ void memory_region_clear_flush_coalesced(MemoryRegi= on *mr); * @match_data: whether to match against @data, instead of just @addr * @data: the data to match against the guest write * @e: event notifier to be triggered when @addr, @size, and @data all mat= ch. + * @transaction: whether to start a transaction for the change **/ -void memory_region_add_eventfd(MemoryRegion *mr, - hwaddr addr, - unsigned size, - bool match_data, - uint64_t data, - EventNotifier *e); +void memory_region_add_eventfd_full(MemoryRegion *mr, + hwaddr addr, + unsigned size, + bool match_data, + uint64_t data, + EventNotifier *e, + bool transaction); + +static inline void memory_region_add_eventfd(MemoryRegion *mr, + hwaddr addr, + unsigned size, + bool match_data, + uint64_t data, + EventNotifier *e) +{ + memory_region_add_eventfd_full(mr, addr, size, match_data, data, e, tr= ue); +} =20 /** * memory_region_del_eventfd: Cancel an eventfd. @@ -1868,13 +1880,25 @@ void memory_region_add_eventfd(MemoryRegion *mr, * @match_data: whether to match against @data, instead of just @addr * @data: the data to match against the guest write * @e: event notifier to be triggered when @addr, @size, and @data all mat= ch. + * @transaction: whether to start a transaction for the change */ -void memory_region_del_eventfd(MemoryRegion *mr, - hwaddr addr, - unsigned size, - bool match_data, - uint64_t data, - EventNotifier *e); +void memory_region_del_eventfd_full(MemoryRegion *mr, + hwaddr addr, + unsigned size, + bool match_data, + uint64_t data, + EventNotifier *e, + bool transaction); + +static inline void memory_region_del_eventfd(MemoryRegion *mr, + hwaddr addr, + unsigned size, + bool match_data, + uint64_t data, + EventNotifier *e) +{ + memory_region_del_eventfd_full(mr, addr, size, match_data, data, e, tr= ue); +} =20 /** * memory_region_add_subregion: Add a subregion to a container. diff --git a/softmmu/memory.c b/softmmu/memory.c index d4493ef9e430..1b1942d521cc 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2341,12 +2341,13 @@ void memory_region_clear_flush_coalesced(MemoryRegi= on *mr) =20 static bool userspace_eventfd_warning; =20 -void memory_region_add_eventfd(MemoryRegion *mr, - hwaddr addr, - unsigned size, - bool match_data, - uint64_t data, - EventNotifier *e) +void memory_region_add_eventfd_full(MemoryRegion *mr, + hwaddr addr, + unsigned size, + bool match_data, + uint64_t data, + EventNotifier *e, + bool transaction) { MemoryRegionIoeventfd mrfd =3D { .addr.start =3D int128_make64(addr), @@ -2367,7 +2368,9 @@ void memory_region_add_eventfd(MemoryRegion *mr, if (size) { adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE); } - memory_region_transaction_begin(); + if (transaction) { + memory_region_transaction_begin(); + } for (i =3D 0; i < mr->ioeventfd_nb; ++i) { if (memory_region_ioeventfd_before(&mrfd, &mr->ioeventfds[i])) { break; @@ -2380,15 +2383,18 @@ void memory_region_add_eventfd(MemoryRegion *mr, sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb-1 - i)); mr->ioeventfds[i] =3D mrfd; ioeventfd_update_pending |=3D mr->enabled; - memory_region_transaction_commit(); + if (transaction) { + memory_region_transaction_commit(); + } } =20 -void memory_region_del_eventfd(MemoryRegion *mr, - hwaddr addr, - unsigned size, - bool match_data, - uint64_t data, - EventNotifier *e) +void memory_region_del_eventfd_full(MemoryRegion *mr, + hwaddr addr, + unsigned size, + bool match_data, + uint64_t data, + EventNotifier *e, + bool transaction) { MemoryRegionIoeventfd mrfd =3D { .addr.start =3D int128_make64(addr), @@ -2402,7 +2408,9 @@ void memory_region_del_eventfd(MemoryRegion *mr, if (size) { adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE); } - memory_region_transaction_begin(); + if (transaction) { + memory_region_transaction_begin(); + } for (i =3D 0; i < mr->ioeventfd_nb; ++i) { if (memory_region_ioeventfd_equal(&mrfd, &mr->ioeventfds[i])) { break; @@ -2415,7 +2423,9 @@ void memory_region_del_eventfd(MemoryRegion *mr, mr->ioeventfds =3D g_realloc(mr->ioeventfds, sizeof(*mr->ioeventfds)*mr->ioeventfd_nb= + 1); ioeventfd_update_pending |=3D mr->enabled; - memory_region_transaction_commit(); + if (transaction) { + memory_region_transaction_commit(); + } } =20 static void memory_region_update_container_subregions(MemoryRegion *subreg= ion) --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616684937; cv=none; d=zohomail.com; s=zohoarc; b=EGaTGkyrsVV0CVSwHcWOAzyMPWpoKN+HoTc7WAPucLsqDoBpPpEfMV4Ochy76MgG8GxRcmiANwC8MKogzBegnL5diR4F3W+AI3xQQfQkWvm38wB35KwicEHAoBVTPtS4FhI3+WmH4EYbTSKri+n+Ja91eeK8EaRYdgjYfE5pIhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616684937; h=Content-Type: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=NomxrL6QJUGcySKKXHvHsGRllyWXgYubYQs+kjZYAEo=; b=PVwi3l0p7t709ikM93dG/Wh44ywqeh8ghNDCpbtLQLWIw9BwPvTURskfNM/R5gPHHMTeodf51yyvC5Zui5EwcAAEdVtAhnOtDiKUzLjd0+31RI6apYhikiPdcpqZlt/y1eBYhgZw/VEqFRkG5Dih+0iVGw5ky6BODw9QcY2KXz4= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616684937489641.4201661517676; Thu, 25 Mar 2021 08:08:57 -0700 (PDT) Received: from localhost ([::1]:33094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRbU-0006SR-3q for importer@patchew.org; Thu, 25 Mar 2021 11:08:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaX-0004mB-Vy for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:07:57 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:42467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaW-0007ht-Go for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:07:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-302-ISCFLV-BMp-_l3JNhkOYjg-1; Thu, 25 Mar 2021 11:07:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF0D380BCA6; Thu, 25 Mar 2021 15:07:50 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id F076E5C241; Thu, 25 Mar 2021 15:07:48 +0000 (UTC) X-MC-Unique: ISCFLV-BMp-_l3JNhkOYjg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 2/8] virtio: Introduce virtio_bus_set_host_notifiers() Date: Thu, 25 Mar 2021 16:07:29 +0100 Message-Id: <20210325150735.1098387-3-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Multiqueue devices such as virtio-scsi or virtio-blk, all open-code the same pattern to setup/tear down host notifiers of the request virtqueues. Consolidate the pattern in a new virtio_bus_set_host_notifiers() API. Since virtio-scsi and virtio-blk both fallback to userspace if host notifiers can't be set, e.g. file descriptor exhaustion, go for a warning rather than an error. Also make it oneshot to avoid flooding the logs since the message would be very likely the same for all virtqueues. Devices will be converted to use virtio_bus_set_host_notifiers() in separate patches. Signed-off-by: Greg Kurz Reviewed-by: Stefan Hajnoczi --- include/hw/virtio/virtio-bus.h | 3 +++ hw/virtio/virtio-bus.c | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index ef8abe49c5a1..6d1e4ee3e886 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -154,5 +154,8 @@ void virtio_bus_release_ioeventfd(VirtioBusState *bus); int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign); /* Tell the bus that the ioeventfd handler is no longer required. */ void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n); +/* Call virtio_bus_set_host_notifier() for several consecutive vqs */ +int virtio_bus_set_host_notifiers(VirtioBusState *bus, int nvqs, int n_off= set, + bool assign); =20 #endif /* VIRTIO_BUS_H */ diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index d6332d45c3b2..c9e7cdb5c161 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -308,6 +308,42 @@ void virtio_bus_cleanup_host_notifier(VirtioBusState *= bus, int n) event_notifier_cleanup(notifier); } =20 +static void virtio_bus_unset_and_cleanup_host_notifiers(VirtioBusState *bu= s, + int nvqs, int n_of= fset) +{ + int i; + + for (i =3D 0; i < nvqs; i++) { + virtio_bus_set_host_notifier(bus, i + n_offset, false); + virtio_bus_cleanup_host_notifier(bus, i + n_offset); + } +} + +int virtio_bus_set_host_notifiers(VirtioBusState *bus, int nvqs, int n_off= set, + bool assign) +{ + VirtIODevice *vdev =3D virtio_bus_get_device(bus); + int i; + int rc; + + if (assign) { + for (i =3D 0; i < nvqs; i++) { + rc =3D virtio_bus_set_host_notifier(bus, i + n_offset, true); + if (rc !=3D 0) { + warn_report_once("%s: Failed to set host notifier (%s).\n", + vdev->name, strerror(-rc)); + + virtio_bus_unset_and_cleanup_host_notifiers(bus, i, n_offs= et); + return rc; + } + } + } else { + virtio_bus_unset_and_cleanup_host_notifiers(bus, nvqs, n_offset); + } + + return 0; +} + static char *virtio_bus_get_dev_path(DeviceState *dev) { BusState *bus =3D qdev_get_parent_bus(dev); --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616685144; cv=none; d=zohomail.com; s=zohoarc; b=gk6dvk7L/9TWa1mGeSlYbGozKMU8+1wZW+9hfKDix66Us7u1rSIfDIaQM6D7ipzE/7AY3/ysMmTr9ECwn5u6lzfcnpauBQh+twyKmGpaP6A1u2rsMD/lQIB2Aks5j2gcj2qj3SI7OCUo9JTcX8EsxK/6z5H7hXfMQerlICTVaDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685144; h=Content-Type: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=9oQOHTVIeuS0pyryoURt6Gimk6FD2aLZ1p7htx3jFAg=; b=kD7478HaX9jr/mXw+6fKVYIiB+E+u/XHJkQb6m+rpmJSX4q94SUicVOpHp7pcEcQlGpL/EaNRzR6J6fsay6+XqKR3Xmr2HdKD4VdfN2cVU7ocy4/gCPwVwjNEymZd+g0VbBGt/YKQRqX24oKeQVxwQB+YMDc7gUyHv1OQg1K2JE= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616685144046208.24526108673433; Thu, 25 Mar 2021 08:12:24 -0700 (PDT) Received: from localhost ([::1]:41656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPReo-0001ig-Mu for importer@patchew.org; Thu, 25 Mar 2021 11:12:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaZ-0004p6-J5 for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:07:59 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:58453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaY-0007ij-2S for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:07:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-ShAsmauJOzyVu0eZblyGsg-1; Thu, 25 Mar 2021 11:07:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3E13380BCA6; Thu, 25 Mar 2021 15:07:53 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42ECB5C649; Thu, 25 Mar 2021 15:07:51 +0000 (UTC) X-MC-Unique: ShAsmauJOzyVu0eZblyGsg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 3/8] virtio: Add API to batch set host notifiers Date: Thu, 25 Mar 2021 16:07:30 +0100 Message-Id: <20210325150735.1098387-4-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Introduce VirtioBusClass methods to begin and commit a transaction of setting/unsetting host notifiers. These handlers will be implemented by virtio-pci to batch addition and deletion of ioeventfds for multiqueue devices like virtio-scsi-pci or virtio-blk-pci. Convert virtio_bus_set_host_notifiers() to use these handlers. Note that virtio_bus_cleanup_host_notifier() closes eventfds, which could still be passed to the KVM_IOEVENTFD ioctl() when the transaction ends and fail with EBADF. The cleanup of the host notifiers is thus pushed to a separate loop in virtio_bus_unset_and_cleanup_host_notifiers(), after transaction commit. Signed-off-by: Greg Kurz --- include/hw/virtio/virtio-bus.h | 4 ++++ hw/virtio/virtio-bus.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index 6d1e4ee3e886..99704b2c090a 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -82,6 +82,10 @@ struct VirtioBusClass { */ int (*ioeventfd_assign)(DeviceState *d, EventNotifier *notifier, int n, bool assign); + + void (*ioeventfd_assign_begin)(DeviceState *d); + void (*ioeventfd_assign_commit)(DeviceState *d); + /* * Whether queue number n is enabled. */ diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index c9e7cdb5c161..156484c4ca14 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -295,6 +295,28 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, = int n, bool assign) return r; } =20 +static void virtio_bus_set_host_notifier_begin(VirtioBusState *bus) +{ + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(bus); + DeviceState *proxy =3D DEVICE(BUS(bus)->parent); + + if (k->ioeventfd_assign_begin) { + assert(k->ioeventfd_assign_commit); + k->ioeventfd_assign_begin(proxy); + } +} + +static void virtio_bus_set_host_notifier_commit(VirtioBusState *bus) +{ + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(bus); + DeviceState *proxy =3D DEVICE(BUS(bus)->parent); + + if (k->ioeventfd_assign_commit) { + assert(k->ioeventfd_assign_begin); + k->ioeventfd_assign_commit(proxy); + } +} + void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n) { VirtIODevice *vdev =3D virtio_bus_get_device(bus); @@ -308,6 +330,7 @@ void virtio_bus_cleanup_host_notifier(VirtioBusState *b= us, int n) event_notifier_cleanup(notifier); } =20 +/* virtio_bus_set_host_notifier_begin() must have been called */ static void virtio_bus_unset_and_cleanup_host_notifiers(VirtioBusState *bu= s, int nvqs, int n_of= fset) { @@ -315,6 +338,10 @@ static void virtio_bus_unset_and_cleanup_host_notifier= s(VirtioBusState *bus, =20 for (i =3D 0; i < nvqs; i++) { virtio_bus_set_host_notifier(bus, i + n_offset, false); + } + /* Let address_space_update_ioeventfds() run before closing ioeventfds= */ + virtio_bus_set_host_notifier_commit(bus); + for (i =3D 0; i < nvqs; i++) { virtio_bus_cleanup_host_notifier(bus, i + n_offset); } } @@ -327,17 +354,24 @@ int virtio_bus_set_host_notifiers(VirtioBusState *bus= , int nvqs, int n_offset, int rc; =20 if (assign) { + virtio_bus_set_host_notifier_begin(bus); + for (i =3D 0; i < nvqs; i++) { rc =3D virtio_bus_set_host_notifier(bus, i + n_offset, true); if (rc !=3D 0) { warn_report_once("%s: Failed to set host notifier (%s).\n", vdev->name, strerror(-rc)); =20 + /* This also calls virtio_bus_set_host_notifier_commit() */ virtio_bus_unset_and_cleanup_host_notifiers(bus, i, n_offs= et); return rc; } } + + virtio_bus_set_host_notifier_commit(bus); } else { + virtio_bus_set_host_notifier_begin(bus); + /* This also calls virtio_bus_set_host_notifier_commit() */ virtio_bus_unset_and_cleanup_host_notifiers(bus, nvqs, n_offset); } =20 --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616685148; cv=none; d=zohomail.com; s=zohoarc; b=EwR7lP9PmC/7pdlNW26MgR45IT6bYu+SmVcZpN3Ngn9RB1DDG1IlAB7PiHLabeUXGFHVayX9xdrdrhEZEofOCumSFOXIdUk4xKPEOcGdyJwIuyLStsQG7w5xKeWGE5OCooeO7pYAJ8oX+FTfNdQ0+pknWFzwt7XAB3FMvrDNYKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685148; h=Content-Type: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=3VQeI2rdaTfR628nIQPvVFfzSji54BpcIY0oXNTUOEo=; b=aeT7ZxbSW/N6hS/gyaF5ugMHxfA44s8687LJx4E5OiUqVuuAQeQ27JqXbWmO7Mm3lHmYRDPWdPBHU94Q8gXCXsmuD1jaNZRimOXaFmmm4L5/vj8+ZIX676CFbpK8vwZSXtSkFZFwhqEmjWFKNj654gNInb51S31v1V4LudIt5nE= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616685148169933.7874089999225; Thu, 25 Mar 2021 08:12:28 -0700 (PDT) Received: from localhost ([::1]:42160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRet-0001vX-9o for importer@patchew.org; Thu, 25 Mar 2021 11:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRab-0004tB-9O for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:01 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:49931) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaY-0007k2-Sa for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-188-KZbR3eolNtCh706kudKXGw-1; Thu, 25 Mar 2021 11:07:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 873D51005D58; Thu, 25 Mar 2021 15:07:55 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 889645C5E1; Thu, 25 Mar 2021 15:07:53 +0000 (UTC) X-MC-Unique: KZbR3eolNtCh706kudKXGw-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 4/8] virtio-pci: Batch add/del ioeventfds in a single MR transaction Date: Thu, 25 Mar 2021 16:07:31 +0100 Message-Id: <20210325150735.1098387-5-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Implement the ioeventfd_assign_begin() and ioeventfd_assign_commit() handlers of VirtioBusClass. Basically track that a transaction was already requested by the device and use this information to prevent the memory code to generate a transaction for each individual eventfd. Devices that want to benefit of this batching feature must be converted to use the virtio_bus_set_host_notifiers() API. Signed-off-by: Greg Kurz --- hw/virtio/virtio-pci.h | 1 + hw/virtio/virtio-pci.c | 53 +++++++++++++++++++++++++++++------------- softmmu/memory.c | 4 ++-- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index d7d5d403a948..a1b3f1bc45c9 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -141,6 +141,7 @@ struct VirtIOPCIProxy { bool disable_modern; bool ignore_backend_features; OnOffAuto disable_legacy; + bool ioeventfd_assign_started; uint32_t class_code; uint32_t nvectors; uint32_t dfselect; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 883045a22354..0a8738c69541 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -243,47 +243,66 @@ static int virtio_pci_ioeventfd_assign(DeviceState *d= , EventNotifier *notifier, hwaddr modern_addr =3D virtio_pci_queue_mem_mult(proxy) * virtio_get_queue_index(vq); hwaddr legacy_addr =3D VIRTIO_PCI_QUEUE_NOTIFY; + bool transaction =3D !proxy->ioeventfd_assign_started; =20 if (assign) { if (modern) { if (fast_mmio) { - memory_region_add_eventfd(modern_mr, modern_addr, 0, - false, n, notifier); + memory_region_add_eventfd_full(modern_mr, modern_addr, 0, + false, n, notifier, transac= tion); } else { - memory_region_add_eventfd(modern_mr, modern_addr, 2, - false, n, notifier); + memory_region_add_eventfd_full(modern_mr, modern_addr, 2, + false, n, notifier, transac= tion); } if (modern_pio) { - memory_region_add_eventfd(modern_notify_mr, 0, 2, - true, n, notifier); + memory_region_add_eventfd_full(modern_notify_mr, 0, 2, + true, n, notifier, transact= ion); } } if (legacy) { - memory_region_add_eventfd(legacy_mr, legacy_addr, 2, - true, n, notifier); + memory_region_add_eventfd_full(legacy_mr, legacy_addr, 2, + true, n, notifier, transaction); } } else { if (modern) { if (fast_mmio) { - memory_region_del_eventfd(modern_mr, modern_addr, 0, - false, n, notifier); + memory_region_del_eventfd_full(modern_mr, modern_addr, 0, + false, n, notifier, transac= tion); } else { - memory_region_del_eventfd(modern_mr, modern_addr, 2, - false, n, notifier); + memory_region_del_eventfd_full(modern_mr, modern_addr, 2, + false, n, notifier, transac= tion); } if (modern_pio) { - memory_region_del_eventfd(modern_notify_mr, 0, 2, - true, n, notifier); + memory_region_del_eventfd_full(modern_notify_mr, 0, 2, + true, n, notifier, transact= ion); } } if (legacy) { - memory_region_del_eventfd(legacy_mr, legacy_addr, 2, - true, n, notifier); + memory_region_del_eventfd_full(legacy_mr, legacy_addr, 2, + true, n, notifier, transaction); } } return 0; } =20 +static void virtio_pci_ioeventfd_assign_begin(DeviceState *d) +{ + VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); + + assert(!proxy->ioeventfd_assign_started); + proxy->ioeventfd_assign_started =3D true; + memory_region_transaction_begin(); +} + +static void virtio_pci_ioeventfd_assign_commit(DeviceState *d) +{ + VirtIOPCIProxy *proxy =3D to_virtio_pci_proxy(d); + + assert(proxy->ioeventfd_assign_started); + memory_region_transaction_commit(); + proxy->ioeventfd_assign_started =3D false; +} + static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy) { virtio_bus_start_ioeventfd(&proxy->bus); @@ -2161,6 +2180,8 @@ static void virtio_pci_bus_class_init(ObjectClass *kl= ass, void *data) k->query_nvectors =3D virtio_pci_query_nvectors; k->ioeventfd_enabled =3D virtio_pci_ioeventfd_enabled; k->ioeventfd_assign =3D virtio_pci_ioeventfd_assign; + k->ioeventfd_assign_begin =3D virtio_pci_ioeventfd_assign_begin; + k->ioeventfd_assign_commit =3D virtio_pci_ioeventfd_assign_commit; k->get_dma_as =3D virtio_pci_get_dma_as; k->queue_enabled =3D virtio_pci_queue_enabled; } diff --git a/softmmu/memory.c b/softmmu/memory.c index 1b1942d521cc..0279e5671bcb 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2368,7 +2368,7 @@ void memory_region_add_eventfd_full(MemoryRegion *mr, if (size) { adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE); } - if (transaction) { + if (!transaction) { memory_region_transaction_begin(); } for (i =3D 0; i < mr->ioeventfd_nb; ++i) { @@ -2383,7 +2383,7 @@ void memory_region_add_eventfd_full(MemoryRegion *mr, sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb-1 - i)); mr->ioeventfds[i] =3D mrfd; ioeventfd_update_pending |=3D mr->enabled; - if (transaction) { + if (!transaction) { memory_region_transaction_commit(); } } --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616685302; cv=none; d=zohomail.com; s=zohoarc; b=eC/4cL9Q8Y4QcNvkJ8ewC0Iq2skS+xz1V4Bqn8dExL29i7v28LMXzjq6zQWtLFfTb328TKHbuW8QWEeeaw8IHD+05wExyLfrB6X02/KK58KNlD8EilFhjoEGEmKfkABmG/auN1lDIgx8yKaJHsFvGlBxDFSFfAmk32WaeqSdo+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685302; h=Content-Type: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=qXcEYorXxtg3WVAD3LGWLNffHT7AqY/ns1u8vWa0e08=; b=UTDJmB+Z1EfO1IRnlt+LQnIcw/25WYW1oBBTugWjCI6ucW8umE5oyLHNpCLVSXI3JTgLs0bCZu0lVsfC2BySaCa/uIOETv3Ul50sb2619mak+IlGMvEBqbsyGbZ7mYYYXQ7D+YyJXVZIxM134K4heOXH/48siD1WFNjroFLfUhA= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616685302504330.983414522427; Thu, 25 Mar 2021 08:15:02 -0700 (PDT) Received: from localhost ([::1]:50922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRhM-0005Y7-Iz for importer@patchew.org; Thu, 25 Mar 2021 11:15:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaf-00055A-VK for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:05 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:56710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRae-0007nD-Dg for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-L-114PxVOZqapotyjeMfYQ-1; Thu, 25 Mar 2021 11:07:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7A618189C7; Thu, 25 Mar 2021 15:07:57 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC16A5C241; Thu, 25 Mar 2021 15:07:55 +0000 (UTC) X-MC-Unique: L-114PxVOZqapotyjeMfYQ-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 5/8] virtio-blk: Fix rollback path in virtio_blk_data_plane_start() Date: Thu, 25 Mar 2021 16:07:32 +0100 Message-Id: <20210325150735.1098387-6-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When dataplane multiqueue support was added in QEMU 2.7, the path that would rollback guest notifiers assignment in case of error simply got dropped. Later on, when Error was added to blk_set_aio_context() in QEMU 4.1, another error path was introduced, but it ommits to rollback both host and guest notifiers. It seems cleaner to fix the rollback path in one go. The patch is simple enough that it can be adjusted if backported to a pre-4.1 QEMU. Fixes: 51b04ac5c6a6 ("virtio-blk: dataplane multiqueue support") Cc: stefanha@redhat.com Fixes: 97896a4887a0 ("block: Add Error to blk_set_aio_context()") Cc: kwolf@redhat.com Signed-off-by: Greg Kurz Reviewed-by: Stefan Hajnoczi --- hw/block/dataplane/virtio-blk.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index e9050c8987e7..d7b5c95d26d9 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -207,7 +207,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); } - goto fail_guest_notifiers; + goto fail_host_notifiers; } } =20 @@ -221,7 +221,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) aio_context_release(old_context); if (r < 0) { error_report_err(local_err); - goto fail_guest_notifiers; + goto fail_aio_context; } =20 /* Process queued requests before the ones in vring */ @@ -245,6 +245,13 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) aio_context_release(s->ctx); return 0; =20 + fail_aio_context: + for (i =3D 0; i < nvqs; i++) { + virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); + } + fail_host_notifiers: + k->set_guest_notifiers(qbus->parent, nvqs, false); fail_guest_notifiers: /* * If we failed to set up the guest notifiers queued requests will be --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616685144; cv=none; d=zohomail.com; s=zohoarc; b=jMiI4GvXUrpu9Imhg3GroHESEbLSsSn7/VcVlLh2l83C40ZhRmIupUXCjpSWxjANshaQ8ZfGYsMibDLtuX3D/M3kr9wRqUAPYLpAkS7LxS/iUg89POlILAuIUd7t4PzqLHcP3qVyIdfTYRSHQLjvlNTco6/4wvpPst+Ep464pms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685144; h=Content-Type: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=9k6z3fJXbP0VK+usFjd1Qyy2I3Z6TrzWO6mr1ABUgs8=; b=YZ4Yhk4SREcZOPgbveC4l5K2zUNPN65+oTmn6v1383XdRV08/NwEC1nhbWR+G745+K/JaYCVclss5Iq+CoNb5TekElrYwfEACGCYNaHycfm5jZv5Py0POtiXk/rxbV0/gsBVUPHCOc9Hp4BQ2bMilalXvKERzbfGGWaTJiAJZc0= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616685144985893.1727531042717; Thu, 25 Mar 2021 08:12:24 -0700 (PDT) Received: from localhost ([::1]:41802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPReq-0001mK-9K for importer@patchew.org; Thu, 25 Mar 2021 11:12:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRaq-0005YP-EL for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:16 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:27659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRao-0007t2-O2 for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-cOBSHx8IPxaL5CvGhiu-8g-1; Thu, 25 Mar 2021 11:08:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2DFE1005D54; Thu, 25 Mar 2021 15:08:06 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4099E5C241; Thu, 25 Mar 2021 15:07:58 +0000 (UTC) X-MC-Unique: cOBSHx8IPxaL5CvGhiu-8g-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 6/8] virtio-blk: Use virtio_bus_set_host_notifiers() Date: Thu, 25 Mar 2021 16:07:33 +0100 Message-Id: <20210325150735.1098387-7-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This allows the virtio-blk-pci device to batch additions and deletions of host notifiers. This significantly improves boot time of VMs with a high number of vCPUs, e.g. from 3m26.408s down to 0m59.923s for a pseries machine with 384 vCPUs. Signed-off-by: Greg Kurz --- hw/block/dataplane/virtio-blk.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index d7b5c95d26d9..fd2a60010285 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -172,6 +172,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) VirtIOBlockDataPlane *s =3D vblk->dataplane; BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vblk))); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + VirtioBusState *bus =3D VIRTIO_BUS(qbus); AioContext *old_context; unsigned i; unsigned nvqs =3D s->conf->num_queues; @@ -199,16 +200,9 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) } =20 /* Set up virtqueue notify */ - for (i =3D 0; i < nvqs; i++) { - r =3D virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, true); - if (r !=3D 0) { - fprintf(stderr, "virtio-blk failed to set host notifier (%d)\n= ", r); - while (i--) { - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); - } - goto fail_host_notifiers; - } + r =3D virtio_bus_set_host_notifiers(bus, nvqs, 0, true); + if (r !=3D 0) { + goto fail_host_notifiers; } =20 s->starting =3D false; @@ -246,10 +240,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) return 0; =20 fail_aio_context: - for (i =3D 0; i < nvqs; i++) { - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); - } + virtio_bus_set_host_notifiers(bus, nvqs, 0, false); fail_host_notifiers: k->set_guest_notifiers(qbus->parent, nvqs, false); fail_guest_notifiers: @@ -287,7 +278,6 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) VirtIOBlockDataPlane *s =3D vblk->dataplane; BusState *qbus =3D qdev_get_parent_bus(DEVICE(vblk)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); - unsigned i; unsigned nvqs =3D s->conf->num_queues; =20 if (!vblk->dataplane_started || s->stopping) { @@ -312,10 +302,7 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) =20 aio_context_release(s->ctx); =20 - for (i =3D 0; i < nvqs; i++) { - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); - } + virtio_bus_set_host_notifiers(VIRTIO_BUS(qbus), nvqs, 0, false); =20 qemu_bh_cancel(s->bh); notify_guest_bh(s); /* final chance to notify guest */ --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616685280; cv=none; d=zohomail.com; s=zohoarc; b=BCKZ3sisTCjxRf8hxgjXixCYSZo1fFGoZXhaMAmFbOmeV5zAHdGN97s1jVBsDYnvjTj76Y3v/OdKri0hCkfNdahtgjCKJFEnlhUF1nvj5PbY6wEY/nJztUKsRGY7MZb7UrXNHRXHqsz+MJSyHbw1C+CPZdaRMWZ05THdcXjeqss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685280; h=Content-Type: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=NDoy8VXhh3zbzmFhsT3jc3Nl01GnihJC66wb7Pnt/ok=; b=XT32ZoGl4b+B9nTI0wZXbfFr898uLNR6CSghIWe1XCSQNLmj4v2BkFLAwqIl8pUt1L44otGRd9nPXxluKmrmtF4T9//+rXXNnTyHrR4Og0+LCvxPiULSM9r02V5CpyF20UVR12ekU0wSDJefajiTR8JfOyn16Ee4nFRLL4vgRP0= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616685280893691.2036366520199; Thu, 25 Mar 2021 08:14:40 -0700 (PDT) Received: from localhost ([::1]:49968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRh1-0005AV-JB for importer@patchew.org; Thu, 25 Mar 2021 11:14:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRat-0005ed-0I for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:19 -0400 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:49473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRar-0007up-3U for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-468-sjpZN2HYNKWX8Bo56fz2YA-1; Thu, 25 Mar 2021 11:08:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C7D3801817; Thu, 25 Mar 2021 15:08:09 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 379895C5E1; Thu, 25 Mar 2021 15:08:07 +0000 (UTC) X-MC-Unique: sjpZN2HYNKWX8Bo56fz2YA-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 7/8] virtio-scsi: Set host notifiers and callbacks separately Date: Thu, 25 Mar 2021 16:07:34 +0100 Message-Id: <20210325150735.1098387-8-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Host notifiers are guaranteed to be idle until the callbacks are hooked up with virtio_queue_aio_set_host_notifier_handler(). They thus don't need to be set or unset with the AioContext lock held. Do this outside the critical section, like virtio-blk already does : basically splitting virtio_scsi_vring_init() in two functions, one to set/unset the host notifier and one for the aio handler. Further improvement is to convert virtio-scsi-pci to use the virtio_bus_set_host_notifiers() API in order to batch setup and tear down of ioeventfds. This is expected to significantly reduce boot time of VMs with high number of vCPUs. Signed-off-by: Greg Kurz --- hw/scsi/virtio-scsi-dataplane.c | 46 ++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 4ad879340645..11b53ab767be 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -94,8 +94,7 @@ static bool virtio_scsi_data_plane_handle_event(VirtIODev= ice *vdev, return progress; } =20 -static int virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, int n, - VirtIOHandleAIOOutput fn) +static int virtio_scsi_set_host_notifier(VirtIOSCSI *s, VirtQueue *vq, int= n) { BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(s))); int rc; @@ -109,10 +108,15 @@ static int virtio_scsi_vring_init(VirtIOSCSI *s, Virt= Queue *vq, int n, return rc; } =20 - virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, fn); return 0; } =20 +static void virtio_scsi_set_host_notifier_handler(VirtIOSCSI *s, VirtQueue= *vq, + VirtIOHandleAIOOutput fn) +{ + virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, fn); +} + /* Context: BH in IOThread */ static void virtio_scsi_dataplane_stop_bh(void *opaque) { @@ -154,38 +158,44 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) goto fail_guest_notifiers; } =20 - aio_context_acquire(s->ctx); - rc =3D virtio_scsi_vring_init(s, vs->ctrl_vq, 0, - virtio_scsi_data_plane_handle_ctrl); - if (rc) { - goto fail_vrings; + rc =3D virtio_scsi_set_host_notifier(s, vs->ctrl_vq, 0); + if (rc !=3D 0) { + goto fail_host_notifiers; } =20 vq_init_count++; - rc =3D virtio_scsi_vring_init(s, vs->event_vq, 1, - virtio_scsi_data_plane_handle_event); - if (rc) { - goto fail_vrings; + rc =3D virtio_scsi_set_host_notifier(s, vs->event_vq, 1); + if (rc !=3D 0) { + goto fail_host_notifiers; } =20 vq_init_count++; + for (i =3D 0; i < vs->conf.num_queues; i++) { - rc =3D virtio_scsi_vring_init(s, vs->cmd_vqs[i], i + 2, - virtio_scsi_data_plane_handle_cmd); + rc =3D virtio_scsi_set_host_notifier(s, vs->cmd_vqs[i], i + 2); if (rc) { - goto fail_vrings; + goto fail_host_notifiers; } vq_init_count++; } =20 + aio_context_acquire(s->ctx); + virtio_scsi_set_host_notifier_handler(s, vs->ctrl_vq, + virtio_scsi_data_plane_handle_ct= rl); + virtio_scsi_set_host_notifier_handler(s, vs->event_vq, + virtio_scsi_data_plane_handle_ev= ent); + + for (i =3D 0; i < vs->conf.num_queues; i++) { + virtio_scsi_set_host_notifier_handler(s, vs->cmd_vqs[i], + virtio_scsi_data_plane_handle= _cmd); + } + s->dataplane_starting =3D false; s->dataplane_started =3D true; aio_context_release(s->ctx); return 0; =20 -fail_vrings: - aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s); - aio_context_release(s->ctx); +fail_host_notifiers: for (i =3D 0; i < vq_init_count; i++) { virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); --=20 2.26.3 From nobody Mon Apr 29 04:38:11 2024 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@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1616685006; cv=none; d=zohomail.com; s=zohoarc; b=gzf9L+SEaE2CH1BJqZn4Q/81aSCjC1I/6yOen06SbFWr5WoCasuFdMYz+4/RP8MEKBZ7NRJbCr4HWD6KHYaCLRrJlReOIwKSIaoXJlsT9WkiAZ/SLuH1ObOWO24s0G1U346zIhvwErhYrqQ5xWPnFhLDERl8y1DJfAIisDyfRI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616685006; h=Content-Type: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=8g6wTdY/Ecbr/NQayAsbjdA8uNFs8B4NsLRg/Xcs75M=; b=EhSOQy5wDKsjSGleKbQpSBHV2e+G2hdStkvrbDYIoQ8yZ22Tujbjtf4GCSQ6KgZq+7xvEodjbpolS6oYNu/3f0ZC8k4ybj++qXeO0YiXgNgOm52uiInQUNeMQY5ImpQJXx4AyPnEaJCwzQC4b5+7oLssTT4Dp+ouWFKGGYPG5Lc= ARC-Authentication-Results: i=1; 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@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616685006544494.3456019053199; Thu, 25 Mar 2021 08:10:06 -0700 (PDT) Received: from localhost ([::1]:36338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRcb-0007nF-Kk for importer@patchew.org; Thu, 25 Mar 2021 11:10:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRau-0005hJ-0D for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:20 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:27207) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPRar-0007ux-GN for qemu-devel@nongnu.org; Thu, 25 Mar 2021 11:08:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-twC2JRh6MFiUCzDZ8D6sJA-1; Thu, 25 Mar 2021 11:08:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 909C1107ACCD; Thu, 25 Mar 2021 15:08:11 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8673A5C3DF; Thu, 25 Mar 2021 15:08:09 +0000 (UTC) X-MC-Unique: twC2JRh6MFiUCzDZ8D6sJA-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [RFC 8/8] virtio-scsi: Use virtio_bus_set_host_notifiers() Date: Thu, 25 Mar 2021 16:07:35 +0100 Message-Id: <20210325150735.1098387-9-groug@kaod.org> In-Reply-To: <20210325150735.1098387-1-groug@kaod.org> References: <20210325150735.1098387-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org 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@nongnu.org; helo=lists.gnu.org; Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, "Michael S. Tsirkin" , Greg Kurz , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This allows the virtio-scsi-pci device to batch additions and deletions of host notifiers. This significantly improves boot time of VMs with a high number of vCPUs, e.g. from 6m13.969s down to 1m4.268s for a pseries machine with 384 vCPUs. Signed-off-by: Greg Kurz Reviewed-by: Stefan Hajnoczi --- hw/scsi/virtio-scsi-dataplane.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 11b53ab767be..eec2b6e19a5b 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -141,6 +141,7 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); + VirtioBusState *bus =3D VIRTIO_BUS(qbus); =20 if (s->dataplane_started || s->dataplane_starting || @@ -171,12 +172,9 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) =20 vq_init_count++; =20 - for (i =3D 0; i < vs->conf.num_queues; i++) { - rc =3D virtio_scsi_set_host_notifier(s, vs->cmd_vqs[i], i + 2); - if (rc) { - goto fail_host_notifiers; - } - vq_init_count++; + rc =3D virtio_bus_set_host_notifiers(bus, vs->conf.num_queues, 2, true= ); + if (rc) { + goto fail_host_notifiers; } =20 aio_context_acquire(s->ctx); @@ -196,10 +194,13 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) return 0; =20 fail_host_notifiers: - for (i =3D 0; i < vq_init_count; i++) { - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); - } + /* + * Only host notifiers for ctrl_vq and event_vq can be set at + * this point. Notifiers for cmd_vqs[] have been reverted by + * virtio_bus_set_host_notifiers() already. + */ + assert(vq_init_count <=3D 2); + virtio_bus_set_host_notifiers(bus, vq_init_count, 0, false); k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false); fail_guest_notifiers: s->dataplane_fenced =3D true; @@ -215,7 +216,6 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); - int i; =20 if (!s->dataplane_started || s->dataplane_stopping) { return; @@ -235,10 +235,8 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) =20 blk_drain_all(); /* ensure there are no in-flight requests */ =20 - for (i =3D 0; i < vs->conf.num_queues + 2; i++) { - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); - } + virtio_bus_set_host_notifiers(VIRTIO_BUS(qbus), vs->conf.num_queues + = 2, 0, + false); =20 /* Clean up guest notifier (irq) */ k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false); --=20 2.26.3