From nobody Tue Feb 10 22:08:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1686512432; cv=none; d=zohomail.com; s=zohoarc; b=XkZiivC93ktD0h9ZQDQHtgGzFrb7PeXKzuv9qNHKYWrNLTfJqqDlvXavQ1Acz3aXSnZ1H45UzE6vZ6CFwI2k1jkkSNwEChRH/SIRgCtCc3QMQ952pCcHnTilhxTnSg7nX7MMAwqXIoyftZ5MQj1aprqoAhhf17aflXUjKsQdY3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686512432; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=+n8G6yTzwrEyBmx0c+esTTD24rSyG19DzYuods5UpVY=; b=GcFDwHXWT8cWbSB87xCRVjikByeXe8aK/4/Q2kSs6IbBuRpUe4CoQgU3+ppRzr6PgJlk9AgrKTXMiF2UrTa2+YgHtk8TMW2yJURHr33Z5eQvNRp8MpbAU80G8NOk9eNsKZ2pL1mA4Cl2K0/G+0wI1/i+h5Qh2644MX9toCAXGJI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168651243264813.552556943815489; Sun, 11 Jun 2023 12:40:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q8QuW-00016e-Ez; Sun, 11 Jun 2023 15:39:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q8QuV-000167-4g for qemu-devel@nongnu.org; Sun, 11 Jun 2023 15:39:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q8QuT-0008Lk-ME for qemu-devel@nongnu.org; Sun, 11 Jun 2023 15:39:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-38-kHVYPRAoPoiI5ftOZ4r3hA-1; Sun, 11 Jun 2023 15:39:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD83F811E78; Sun, 11 Jun 2023 19:39:27 +0000 (UTC) Received: from localhost (unknown [10.39.192.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id C402B2166B25; Sun, 11 Jun 2023 19:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686512371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=+n8G6yTzwrEyBmx0c+esTTD24rSyG19DzYuods5UpVY=; b=UtuCZzkEXS8A/K/L9ZMah17ibXZ853oP3yub6TLd5ePGeG1CDQoU/qqk9y6nCs8T6JW2Ga ZfTCHsAiYYIn0ecmKR2t+is2AQT0+doabF6KSwziImLgScTlk/girXE5mF6iphJS6BgngY gnoG/njn9SAI53oIq+gKuPQwYd7Rzy8= X-MC-Unique: kHVYPRAoPoiI5ftOZ4r3hA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , kwolf@redhat.com, Paolo Bonzini , , Fam Zheng , Stefan Hajnoczi , Jean-Louis Dupond Subject: [PATCH] virtio-scsi: avoid dangling host notifier in ->ioeventfd_stop() Date: Sun, 11 Jun 2023 15:39:24 -0400 Message-Id: <20230611193924.2444914-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1686512434713100001 Content-Type: text/plain; charset="utf-8" virtio_scsi_dataplane_stop() calls blk_drain_all(), which invokes ->drained_begin()/->drained_end() after we've already detached the host notifier. virtio_scsi_drained_end() currently attaches the host notifier again and leaves it dangling after dataplane has stopped. This results in the following assertion failure because virtio_scsi_defer_to_dataplane() is called from the IOThread instead of the main loop thread: qemu-system-x86_64: ../softmmu/memory.c:1111: memory_region_transaction_c= ommit: Assertion `qemu_mutex_iothread_locked()' failed. Reported-by: Jean-Louis Dupond Signed-off-by: Stefan Hajnoczi --- hw/scsi/virtio-scsi.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 9c8ef0aaa6..45b95ea070 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -1125,7 +1125,16 @@ static void virtio_scsi_drained_begin(SCSIBus *bus) uint32_t total_queues =3D VIRTIO_SCSI_VQ_NUM_FIXED + s->parent_obj.conf.num_queues; =20 - if (!s->dataplane_started) { + /* + * Drain is called when stopping dataplane but the host notifier has + * already been detached. Detaching multiple times is a no-op if nothi= ng + * else is using the monitoring same file descriptor, but avoid it jus= t in + * case. + * + * Also, don't detach if dataplane has not even been started yet becau= se + * the host notifier isn't attached. + */ + if (s->dataplane_stopping || !s->dataplane_started) { return; } =20 @@ -1143,7 +1152,14 @@ static void virtio_scsi_drained_end(SCSIBus *bus) uint32_t total_queues =3D VIRTIO_SCSI_VQ_NUM_FIXED + s->parent_obj.conf.num_queues; =20 - if (!s->dataplane_started) { + /* + * Drain is called when stopping dataplane. Keep the host notifier det= ached + * so it's not left dangling after dataplane is stopped. + * + * Also, don't attach if dataplane has not even been started yet. We'r= e not + * ready. + */ + if (s->dataplane_stopping || !s->dataplane_started) { return; } =20 --=20 2.40.1