From patchwork Thu Mar 25 15:07:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF21BC433DB for ; Thu, 25 Mar 2021 15:08:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3CA660C3E for ; Thu, 25 Mar 2021 15:08:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3CA660C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRbT-0006bM-VS for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:08:56 -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 X-MC-Unique: mtMwooD0PWSw7_M90LqH7w-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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(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 match. + * @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, true); +} /** * 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 match. + * @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, true); +} /** * 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(MemoryRegion *mr) static bool userspace_eventfd_warning; -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 = { .addr.start = 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 = 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] = mrfd; ioeventfd_update_pending |= mr->enabled; - memory_region_transaction_commit(); + if (transaction) { + memory_region_transaction_commit(); + } } -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 = { .addr.start = 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 = 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 = g_realloc(mr->ioeventfds, sizeof(*mr->ioeventfds)*mr->ioeventfd_nb + 1); ioeventfd_update_pending |= mr->enabled; - memory_region_transaction_commit(); + if (transaction) { + memory_region_transaction_commit(); + } } static void memory_region_update_container_subregions(MemoryRegion *subregion) From patchwork Thu Mar 25 15:07:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BB18C433C1 for ; Thu, 25 Mar 2021 15:08:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 69BF161A16 for ; Thu, 25 Mar 2021 15:08:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69BF161A16 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRbQ-0006SR-8K for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:08:52 -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 X-MC-Unique: ISCFLV-BMp-_l3JNhkOYjg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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_offset, + bool assign); #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); } +static void virtio_bus_unset_and_cleanup_host_notifiers(VirtioBusState *bus, + int nvqs, int n_offset) +{ + int i; + + for (i = 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_offset, + bool assign) +{ + VirtIODevice *vdev = virtio_bus_get_device(bus); + int i; + int rc; + + if (assign) { + for (i = 0; i < nvqs; i++) { + rc = virtio_bus_set_host_notifier(bus, i + n_offset, true); + if (rc != 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_offset); + 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 = qdev_get_parent_bus(dev); From patchwork Thu Mar 25 15:07:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8356C433C1 for ; Thu, 25 Mar 2021 15:12:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C69F61A13 for ; Thu, 25 Mar 2021 15:12:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C69F61A13 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRel-0001ig-As for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:12:19 -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 X-MC-Unique: ShAsmauJOzyVu0eZblyGsg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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; } +static void virtio_bus_set_host_notifier_begin(VirtioBusState *bus) +{ + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(bus); + DeviceState *proxy = 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 = VIRTIO_BUS_GET_CLASS(bus); + DeviceState *proxy = 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 = virtio_bus_get_device(bus); @@ -308,6 +330,7 @@ void virtio_bus_cleanup_host_notifier(VirtioBusState *bus, int n) event_notifier_cleanup(notifier); } +/* virtio_bus_set_host_notifier_begin() must have been called */ static void virtio_bus_unset_and_cleanup_host_notifiers(VirtioBusState *bus, int nvqs, int n_offset) { @@ -315,6 +338,10 @@ static void virtio_bus_unset_and_cleanup_host_notifiers(VirtioBusState *bus, for (i = 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 = 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; if (assign) { + virtio_bus_set_host_notifier_begin(bus); + for (i = 0; i < nvqs; i++) { rc = virtio_bus_set_host_notifier(bus, i + n_offset, true); if (rc != 0) { warn_report_once("%s: Failed to set host notifier (%s).\n", vdev->name, strerror(-rc)); + /* This also calls virtio_bus_set_host_notifier_commit() */ virtio_bus_unset_and_cleanup_host_notifiers(bus, i, n_offset); 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); } From patchwork Thu Mar 25 15:07:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CAB2C433DB for ; Thu, 25 Mar 2021 15:12:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D79E60C3E for ; Thu, 25 Mar 2021 15:12:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D79E60C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRep-0001vX-NS for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:12:23 -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 X-MC-Unique: KZbR3eolNtCh706kudKXGw-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 = virtio_pci_queue_mem_mult(proxy) * virtio_get_queue_index(vq); hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY; + bool transaction = !proxy->ioeventfd_assign_started; 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, transaction); } 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, transaction); } 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, transaction); } } 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, transaction); } 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, transaction); } 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, transaction); } } 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; } +static void virtio_pci_ioeventfd_assign_begin(DeviceState *d) +{ + VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); + + assert(!proxy->ioeventfd_assign_started); + proxy->ioeventfd_assign_started = true; + memory_region_transaction_begin(); +} + +static void virtio_pci_ioeventfd_assign_commit(DeviceState *d) +{ + VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d); + + assert(proxy->ioeventfd_assign_started); + memory_region_transaction_commit(); + proxy->ioeventfd_assign_started = 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 *klass, void *data) k->query_nvectors = virtio_pci_query_nvectors; k->ioeventfd_enabled = virtio_pci_ioeventfd_enabled; k->ioeventfd_assign = virtio_pci_ioeventfd_assign; + k->ioeventfd_assign_begin = virtio_pci_ioeventfd_assign_begin; + k->ioeventfd_assign_commit = virtio_pci_ioeventfd_assign_commit; k->get_dma_as = virtio_pci_get_dma_as; k->queue_enabled = 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 = 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] = mrfd; ioeventfd_update_pending |= mr->enabled; - if (transaction) { + if (!transaction) { memory_region_transaction_commit(); } } From patchwork Thu Mar 25 15:07:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28AB0C433C1 for ; Thu, 25 Mar 2021 15:14:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D3A2561879 for ; Thu, 25 Mar 2021 15:14:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3A2561879 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRhF-0005Y7-UU for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:14:53 -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 X-MC-Unique: L-114PxVOZqapotyjeMfYQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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-blk.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; } } @@ -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; } /* 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; + fail_aio_context: + for (i = 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 From patchwork Thu Mar 25 15:07:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1628FC433E0 for ; Thu, 25 Mar 2021 15:12:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B5A4261A13 for ; Thu, 25 Mar 2021 15:12:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5A4261A13 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRem-0001mK-Og for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:12:20 -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 X-MC-Unique: cOBSHx8IPxaL5CvGhiu-8g-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Stefan Hajnoczi --- 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-blk.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 = vblk->dataplane; BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vblk))); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); + VirtioBusState *bus = VIRTIO_BUS(qbus); AioContext *old_context; unsigned i; unsigned nvqs = s->conf->num_queues; @@ -199,16 +200,9 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) } /* Set up virtqueue notify */ - for (i = 0; i < nvqs; i++) { - r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, true); - if (r != 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 = virtio_bus_set_host_notifiers(bus, nvqs, 0, true); + if (r != 0) { + goto fail_host_notifiers; } s->starting = false; @@ -246,10 +240,7 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) return 0; fail_aio_context: - for (i = 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 = vblk->dataplane; BusState *qbus = qdev_get_parent_bus(DEVICE(vblk)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); - unsigned i; unsigned nvqs = s->conf->num_queues; if (!vblk->dataplane_started || s->stopping) { @@ -312,10 +302,7 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) aio_context_release(s->ctx); - for (i = 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); qemu_bh_cancel(s->bh); notify_guest_bh(s); /* final chance to notify guest */ From patchwork Thu Mar 25 15:07:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EE3EC433DB for ; Thu, 25 Mar 2021 15:14:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB19A61879 for ; Thu, 25 Mar 2021 15:14:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB19A61879 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRgx-0005AV-RY for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:14:35 -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 X-MC-Unique: sjpZN2HYNKWX8Bo56fz2YA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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-dataplane.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(VirtIODevice *vdev, return progress; } -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 = BUS(qdev_get_parent_bus(DEVICE(s))); int rc; @@ -109,10 +108,15 @@ static int virtio_scsi_vring_init(VirtIOSCSI *s, VirtQueue *vq, int n, return rc; } - virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, fn); return 0; } +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; } - aio_context_acquire(s->ctx); - rc = virtio_scsi_vring_init(s, vs->ctrl_vq, 0, - virtio_scsi_data_plane_handle_ctrl); - if (rc) { - goto fail_vrings; + rc = virtio_scsi_set_host_notifier(s, vs->ctrl_vq, 0); + if (rc != 0) { + goto fail_host_notifiers; } vq_init_count++; - rc = virtio_scsi_vring_init(s, vs->event_vq, 1, - virtio_scsi_data_plane_handle_event); - if (rc) { - goto fail_vrings; + rc = virtio_scsi_set_host_notifier(s, vs->event_vq, 1); + if (rc != 0) { + goto fail_host_notifiers; } vq_init_count++; + for (i = 0; i < vs->conf.num_queues; i++) { - rc = virtio_scsi_vring_init(s, vs->cmd_vqs[i], i + 2, - virtio_scsi_data_plane_handle_cmd); + rc = virtio_scsi_set_host_notifier(s, vs->cmd_vqs[i], i + 2); if (rc) { - goto fail_vrings; + goto fail_host_notifiers; } vq_init_count++; } + aio_context_acquire(s->ctx); + virtio_scsi_set_host_notifier_handler(s, vs->ctrl_vq, + virtio_scsi_data_plane_handle_ctrl); + virtio_scsi_set_host_notifier_handler(s, vs->event_vq, + virtio_scsi_data_plane_handle_event); + + for (i = 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 = false; s->dataplane_started = true; aio_context_release(s->ctx); return 0; -fail_vrings: - aio_wait_bh_oneshot(s->ctx, virtio_scsi_dataplane_stop_bh, s); - aio_context_release(s->ctx); +fail_host_notifiers: for (i = 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); From patchwork Thu Mar 25 15:07:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12164269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36C54C433DB for ; Thu, 25 Mar 2021 15:10:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA09B60C3E for ; Thu, 25 Mar 2021 15:10:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA09B60C3E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPRcW-0007nF-Nz for qemu-devel@archiver.kernel.org; Thu, 25 Mar 2021 11:10:00 -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 X-MC-Unique: twC2JRh6MFiUCzDZ8D6sJA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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-dataplane.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 = VIRTIO_BUS_GET_CLASS(qbus); VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); VirtIOSCSI *s = VIRTIO_SCSI(vdev); + VirtioBusState *bus = VIRTIO_BUS(qbus); if (s->dataplane_started || s->dataplane_starting || @@ -171,12 +172,9 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) vq_init_count++; - for (i = 0; i < vs->conf.num_queues; i++) { - rc = virtio_scsi_set_host_notifier(s, vs->cmd_vqs[i], i + 2); - if (rc) { - goto fail_host_notifiers; - } - vq_init_count++; + rc = virtio_bus_set_host_notifiers(bus, vs->conf.num_queues, 2, true); + if (rc) { + goto fail_host_notifiers; } aio_context_acquire(s->ctx); @@ -196,10 +194,13 @@ int virtio_scsi_dataplane_start(VirtIODevice *vdev) return 0; fail_host_notifiers: - for (i = 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 <= 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 = true; @@ -215,7 +216,6 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); VirtIOSCSI *s = VIRTIO_SCSI(vdev); - int i; if (!s->dataplane_started || s->dataplane_stopping) { return; @@ -235,10 +235,8 @@ void virtio_scsi_dataplane_stop(VirtIODevice *vdev) blk_drain_all(); /* ensure there are no in-flight requests */ - for (i = 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); /* Clean up guest notifier (irq) */ k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, false);