From nobody Thu Nov 6 01:19:36 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538295537148347.6994347404137; Sun, 30 Sep 2018 01:18:57 -0700 (PDT) Received: from localhost ([::1]:54229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WwK-0006ez-2V for importer@patchew.org; Sun, 30 Sep 2018 04:18:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41102) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6Wr2-00023K-Hx for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6Wr1-0008LL-Cv for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:28 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:34293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6Wr0-0008Bk-HU for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:27 -0400 Received: by mail-wr1-x444.google.com with SMTP id z4-v6so9103720wrb.1 for ; Sun, 30 Sep 2018 01:13:21 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.13.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=TEiJ69TlT1ABYM+gQLROSYSRA0nNW0Ldw9frKoU5DY4=; b=l5TRK0/+8dVXkkdRnoqiDExvSzPMaM/c05dvpm2/ZBiFXFPvFNs/UOb/w0sgoHUgH0 6sdF3TTOrpfS+AOjH+ZksX+C9q5wbLRUZCJW3hTjDORWn0ucsW4/ps3tN2sIexvGWmnQ FFIvvsE2qNg5mGn0uoRkAa0WFtd5NCvmtiRhX4Z2VSBxeJhocsMXODaWh7H/qdgYM7Eh GiLDKvUMLYLpR01lqEOWGzeQRgi/vw7QBwMIVTt9amnvc3L2dEx9E8z01DbvmzKFv7pN WfpR8ScXNFDn9TrcwXXwn6GJFR77hNNwczuwLTbros751zzVPdBBbkL1ck9253N0eKd+ SSqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=TEiJ69TlT1ABYM+gQLROSYSRA0nNW0Ldw9frKoU5DY4=; b=G8cinUqkD2agmdxJPcf9AlXDWIT2v3fzn0GR+uml1lRnVA3o/tgdgCIxSbAST838Dw QLA8Fm7+4W7v1tKsXot0yaDvF8fCGapK4UF29m4V05exjl5bmSvNH8d6j7n5TJfCZvCv dcE9uxyejpR07NVtiFRkScDqBT0yuDQ8SFtvDLao5uJ9kx/r+Z7G0igvb7KpLUDgWXok Nhu5AQrGULA2j/YjS0z+PywemyWn31b9gB73VWnMHz/vh8egiaNtQ+DeaHmKkcgkipUt lPmNheY/7RkiMG3au5JBo2+JY8aZJftQ2cLLk0GJKeOc9co+Kj2n/qSbvQXWVAhltXIy g06A== X-Gm-Message-State: ABuFfojHyWsitV/QUpDmlwKHkKjnts3YkIc09e+h5E6O+7608uop6Teu JC3DFhheQE+bgtHTO7IvBhRxCQB9 X-Google-Smtp-Source: ACcGV62WV6RwqSFhb4P4Bf9JS7qZsTlAWDD4sv0vjXCMVdDarCzFn8zLRfhidxXodTatZyJWd9m74A== X-Received: by 2002:a5d:4a12:: with SMTP id m18-v6mr3717176wrq.278.1538295200337; Sun, 30 Sep 2018 01:13:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:11:59 +0200 Message-Id: <1538295197-23704-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PULL 01/79] virtio: Return true from virtio_queue_empty if broken X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Both virtio-blk and virtio-scsi use virtio_queue_empty() as the loop condition in VQ handlers (virtio_blk_handle_vq, virtio_scsi_handle_cmd_vq). When a device is marked broken in virtqueue_pop, for example if a vIOMMU address translation failed, we want to break out of the loop. This fixes a hanging problem when booting a CentOS 3.10.0-862.el7.x86_64 kernel with ATS enabled: $ qemu-system-x86_64 \ ... \ -device intel-iommu,intremap=3Don,caching-mode=3Don,eim=3Don,device-iot= lb=3Don \ -device virtio-scsi-pci,iommu_platform=3Don,ats=3Don,id=3Dscsi0,bus=3Dp= ci.4,addr=3D0x0 The dead loop happens immediately when the kernel boots and initializes the device, where virtio_scsi_data_plane_handle_cmd will not return: > ... > #13 0x00005586602b7793 in virtio_scsi_handle_cmd_vq > #14 0x00005586602b8d66 in virtio_scsi_data_plane_handle_cmd > #15 0x00005586602ddab7 in virtio_queue_notify_aio_vq > #16 0x00005586602dfc9f in virtio_queue_host_notifier_aio_poll > #17 0x00005586607885da in run_poll_handlers_once > #18 0x000055866078880e in try_poll_mode > #19 0x00005586607888eb in aio_poll > #20 0x0000558660784561 in aio_wait_bh_oneshot > #21 0x00005586602b9582 in virtio_scsi_dataplane_stop > #22 0x00005586605a7110 in virtio_bus_stop_ioeventfd > #23 0x00005586605a9426 in virtio_pci_stop_ioeventfd > #24 0x00005586605ab808 in virtio_pci_common_write > #25 0x0000558660242396 in memory_region_write_accessor > #26 0x00005586602425ab in access_with_adjusted_size > #27 0x0000558660245281 in memory_region_dispatch_write > #28 0x00005586601e008e in flatview_write_continue > #29 0x00005586601e01d8 in flatview_write > #30 0x00005586601e04de in address_space_write > #31 0x00005586601e052f in address_space_rw > #32 0x00005586602607f2 in kvm_cpu_exec > #33 0x0000558660227148 in qemu_kvm_cpu_thread_fn > #34 0x000055866078bde7 in qemu_thread_start > #35 0x00007f5784906594 in start_thread > #36 0x00007f5784639e6f in clone With this patch, virtio_queue_empty will now return 1 as soon as the vdev is marked as broken, after a "virtio: zero sized buffers are not allowed" error. To be consistent, update virtio_queue_empty_rcu as well. Signed-off-by: Fam Zheng Message-Id: <20180910145616.8598-2-famz@redhat.com> Signed-off-by: Paolo Bonzini --- hw/virtio/virtio.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index f6a588a..94f5c8e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -358,6 +358,10 @@ int virtio_queue_ready(VirtQueue *vq) * Called within rcu_read_lock(). */ static int virtio_queue_empty_rcu(VirtQueue *vq) { + if (unlikely(vq->vdev->broken)) { + return 1; + } + if (unlikely(!vq->vring.avail)) { return 1; } @@ -373,6 +377,10 @@ int virtio_queue_empty(VirtQueue *vq) { bool empty; =20 + if (unlikely(vq->vdev->broken)) { + return 1; + } + if (unlikely(!vq->vring.avail)) { return 1; } --=20 1.8.3.1