From nobody Mon Feb 9 15:10:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1681990726; cv=none; d=zohomail.com; s=zohoarc; b=Qv+Ipzh9J66Mkuak3qZS7yKLnecAEVyuUJ4LmXhAE0vUQynGmdHT0EOfig+ViAM5f3+uajYP1U9cCQC42NikuVDC29vZu/qa3DYMTRDgg3+ttfPfyOWb5qb6r70kk67JU0Chk17WTLFZv840WBXXz/JxQBOv9IlyACsMTNr0lwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681990726; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mEUiDYhTGG6/grGbCAPXx5jwh+m436EKZLWWN7O6BQM=; b=XfU12CqDC8ugX5KoHaWeuJ/fuxmU27kaDuGXrkGoUXpBp9nYqtlGpN92meeHI7m4RMnic9nmc7GfprZ8kvt9mDiwRbTmVwfl14siC8YcfjTI+v4bdL4vcgJNX5BAakAy55L/hRQEVPHkGsJjrUVB2F5ZKg+fRwRUQEZOjFy74Lg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681990726148170.04088376592813; Thu, 20 Apr 2023 04:38:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.524131.814788 (Exim 4.92) (envelope-from ) id 1ppScN-0002cq-KO; Thu, 20 Apr 2023 11:38:27 +0000 Received: by outflank-mailman (output) from mailman id 524131.814788; Thu, 20 Apr 2023 11:38:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppScN-0002cj-HH; Thu, 20 Apr 2023 11:38:27 +0000 Received: by outflank-mailman (input) for mailman id 524131; Thu, 20 Apr 2023 11:38:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ppScM-0002cJ-Cw for xen-devel@lists.xenproject.org; Thu, 20 Apr 2023 11:38:26 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dc04e1c9-df6f-11ed-b21f-6b7b168915f2; Thu, 20 Apr 2023 13:38:25 +0200 (CEST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-i8H5la--OhiNA-YvKIl4IA-1; Thu, 20 Apr 2023 07:38:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1588A1C08982; Thu, 20 Apr 2023 11:38:20 +0000 (UTC) Received: from localhost (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00AB92026D16; Thu, 20 Apr 2023 11:37:42 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dc04e1c9-df6f-11ed-b21f-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681990704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mEUiDYhTGG6/grGbCAPXx5jwh+m436EKZLWWN7O6BQM=; b=WokIk7Sd4qauXqXo/HxBQkO6cavPsbyX9Z/3pt7RvwHMs5Q8OqfFxhlmo9oVddy7cvRI+w enHK4QXeKlDVJo8FxheFYR2v2SB+vT45SSSSKjUlT3Vz/B/finNbQiokyajldsPi317VD4 AhalpofJu/UkzA38X5qfpThJeJj3tYM= X-MC-Unique: i8H5la--OhiNA-YvKIl4IA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Peter Lieven , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Xie Yongji , Juan Quintela , qemu-block@nongnu.org, Eduardo Habkost , Richard Henderson , David Woodhouse , Stefan Weil , Fam Zheng , Julia Suvorova , Ronnie Sahlberg , xen-devel@lists.xenproject.org, Hanna Reitz , "Dr. David Alan Gilbert" , eesposit@redhat.com, Kevin Wolf , Marcel Apfelbaum , Stefano Stabellini , Paul Durrant , Aarushi Mehta , "Michael S. Tsirkin" , Anthony Perard , "Richard W.M. Jones" , Coiby Xu , Stefano Garzarella , Zhengui Li , Daniil Tatianin Subject: [PATCH v3 03/20] virtio-scsi: stop using aio_disable_external() during unplug Date: Thu, 20 Apr 2023 07:37:15 -0400 Message-Id: <20230420113732.336620-4-stefanha@redhat.com> In-Reply-To: <20230420113732.336620-1-stefanha@redhat.com> References: <20230420113732.336620-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1681990728611100002 Content-Type: text/plain; charset="utf-8" This patch is part of an effort to remove the aio_disable_external() API because it does not fit in a multi-queue block layer world where many AioContexts may be submitting requests to the same disk. The SCSI emulation code is already in good shape to stop using aio_disable_external(). It was only used by commit 9c5aad84da1c ("virtio-scsi: fixed virtio_scsi_ctx_check failed when detaching scsi disk") to ensure that virtio_scsi_hotunplug() works while the guest driver is submitting I/O. Ensure virtio_scsi_hotunplug() is safe as follows: 1. qdev_simple_device_unplug_cb() -> qdev_unrealize() -> device_set_realized() calls qatomic_set(&dev->realized, false) so that future scsi_device_get() calls return NULL because they exclude SCSIDevices with realized=3Dfalse. That means virtio-scsi will reject new I/O requests to this SCSIDevice with VIRTIO_SCSI_S_BAD_TARGET even while virtio_scsi_hotunplug() is still executing. We are protected against new requests! 2. Add a call to scsi_device_purge_requests() from scsi_unrealize() so that in-flight requests are cancelled synchronously. This ensures that no in-flight requests remain once qdev_simple_device_unplug_cb() returns. Thanks to these two conditions we don't need aio_disable_external() anymore. Cc: Zhengui Li Reviewed-by: Paolo Bonzini Reviewed-by: Daniil Tatianin Signed-off-by: Stefan Hajnoczi --- hw/scsi/scsi-disk.c | 1 + hw/scsi/virtio-scsi.c | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 97c9b1c8cd..e01bd84541 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2522,6 +2522,7 @@ static void scsi_realize(SCSIDevice *dev, Error **err= p) =20 static void scsi_unrealize(SCSIDevice *dev) { + scsi_device_purge_requests(dev, SENSE_CODE(RESET)); del_boot_device_lchs(&dev->qdev, NULL); } =20 diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 000961446c..a02f9233ec 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -1061,11 +1061,8 @@ static void virtio_scsi_hotunplug(HotplugHandler *ho= tplug_dev, DeviceState *dev, VirtIODevice *vdev =3D VIRTIO_DEVICE(hotplug_dev); VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); SCSIDevice *sd =3D SCSI_DEVICE(dev); - AioContext *ctx =3D s->ctx ?: qemu_get_aio_context(); =20 - aio_disable_external(ctx); qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); - aio_enable_external(ctx); =20 if (s->ctx) { virtio_scsi_acquire(s); --=20 2.39.2