From nobody Mon Sep 16 18:58:30 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1719369930; cv=none; d=zohomail.com; s=zohoarc; b=nWCTZBddFga3Nvdf+FiBv+AuO3hf0FXn1q4nHELWuMhOSAs+nqidY92yptF5qoSuAWMtB0LsEUWCqZvOz8SDew7x+64ykzPvjz5PsuM0qDmTrBSuITZ/Avz6prN9NJqLhogjA5MmGQQ0lubYkdmIF4/GU2xv+Q2Rhn2bbEhRB7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719369930; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3HsaTu0rEaLzrUEaPgROf/HqkAPij43XcgXV00m5wDo=; b=BfuXkZFZrjo5wAQNM+g0RAHrt3q2h5VUW34G05V+PSTnxjTAulTy50rLelDQBSUcGwOI3AJwNN5Y6ZRgE81kYU+tJaXtC8ctlntX8WPAXkJOSGvKrvhUvRme5a1M7jNKFxqrCL3BTd/58+GwEQvedCznSMMa2c+IZS7u8+TnJN0= 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+importer2=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 1719369930584828.7333539382314; Tue, 25 Jun 2024 19:45:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMIeZ-0007Kc-9g; Tue, 25 Jun 2024 22:44:59 -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 1sMIeX-0007HY-K8 for qemu-devel@nongnu.org; Tue, 25 Jun 2024 22:44:57 -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 1sMIeV-0001wX-4M for qemu-devel@nongnu.org; Tue, 25 Jun 2024 22:44:57 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-5q0BYMoxMKeaYOqYW6OEGg-1; Tue, 25 Jun 2024 22:44:45 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DEAE41956095; Wed, 26 Jun 2024 02:44:42 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.114]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 961511955F2D; Wed, 26 Jun 2024 02:44:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719369892; 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=3HsaTu0rEaLzrUEaPgROf/HqkAPij43XcgXV00m5wDo=; b=WyJ0ptGuV0g/mh4bmTyiCcD1QLhf/ymuBENX6HGJcJdxrxoDHKu2SUh/6KQidPeRN3Z5rk QjCJZMdBo2NydVMRM5hiDpkULauLAcKpDU4VBb8HEZHIZ8BifXsY8fYeSgl81/1jJ77GVH NU3RTE40ec/x/TFNLXRFP2K/jL9ownA= X-MC-Unique: 5q0BYMoxMKeaYOqYW6OEGg-1 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org, philmd@linaro.org Cc: qemu-stable@nongnu.org Subject: [PATCH v3] virtio-pci: Fix the use of an uninitialized irqfd Date: Wed, 26 Jun 2024 10:44:31 +0800 Message-ID: <20240626024434.10523-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=lulu@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1719369932625100003 Content-Type: text/plain; charset="utf-8" The crash was reported in MAC OS and NixOS, here is the link for this bug https://gitlab.com/qemu-project/qemu/-/issues/2334 https://gitlab.com/qemu-project/qemu/-/issues/2321 The root cause is the function virtio_pci_set_guest_notifiers() was not cal= led in the virtio_input device.So the vector_irqfd was not initialized So the fix is add the check for vector_irqfd. Change in V3 1) Move the vector_irqfd check to virtio_pci_get_notifier(). The function virtio_pci_get_notifier() can also be used while vdev->status is not VIRTIO_CONFIG_S_DRIVER_OK. In that case, the vector_irqfd could be N= ULL, so also add the status check here. 2) Add the return value check for kvm_virtio_pci_vector_use_one(). Since the return value of function virtio_pci_set_vector() is void, just add the error message here. This fix is verified in vyatta,MacOS,NixOS,fedora system. The bt tree for this bug is: Thread 6 "CPU 0/KVM" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7c817be006c0 (LWP 1269146)] kvm_virtio_pci_vq_vector_use () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:817 817 if (irqfd->users =3D=3D 0) { (gdb) thread apply all bt ... Thread 6 (Thread 0x7c817be006c0 (LWP 1269146) "CPU 0/KVM"): 0 kvm_virtio_pci_vq_vector_use () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:= 817 1 kvm_virtio_pci_vector_use_one () at ../qemu-9.0.0/hw/virtio/virtio-pci.c= :893 2 0x00005983657045e2 in memory_region_write_accessor () at ../qemu-9.0.0/s= ystem/memory.c:497 3 0x0000598365704ba6 in access_with_adjusted_size () at ../qemu-9.0.0/syst= em/memory.c:573 4 0x0000598365705059 in memory_region_dispatch_write () at ../qemu-9.0.0/s= ystem/memory.c:1528 5 0x00005983659b8e1f in flatview_write_continue_step.isra.0 () at ../qemu-= 9.0.0/system/physmem.c:2713 6 0x000059836570ba7d in flatview_write_continue () at ../qemu-9.0.0/system= /physmem.c:2743 7 flatview_write () at ../qemu-9.0.0/system/physmem.c:2774 8 0x000059836570bb76 in address_space_write () at ../qemu-9.0.0/system/phy= smem.c:2894 9 0x0000598365763afe in address_space_rw () at ../qemu-9.0.0/system/physme= m.c:2904 10 kvm_cpu_exec () at ../qemu-9.0.0/accel/kvm/kvm-all.c:2917 11 0x000059836576656e in kvm_vcpu_thread_fn () at ../qemu-9.0.0/accel/kvm/k= vm-accel-ops.c:50 12 0x0000598365926ca8 in qemu_thread_start () at ../qemu-9.0.0/util/qemu-th= read-posix.c:541 13 0x00007c8185bcd1cf in ??? () at /usr/lib/libc.so.6 14 0x00007c8185c4e504 in clone () at /usr/lib/libc.so.6 Fixes: 2ce6cff94d ("virtio-pci: fix use of a released vector") Cc: qemu-stable@nongnu.org Signed-off-by: Cindy Lu --- hw/virtio/virtio-pci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b1d02f4b3d..87307b9061 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -860,6 +860,11 @@ static int virtio_pci_get_notifier(VirtIOPCIProxy *pro= xy, int queue_no, VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); VirtQueue *vq; =20 + if ((proxy->vector_irqfd =3D=3D NULL) && + (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { + return -1; + } + if (queue_no =3D=3D VIRTIO_CONFIG_IRQ_IDX) { *n =3D virtio_config_get_guest_notifier(vdev); *vector =3D vdev->config_vector; @@ -1452,7 +1457,9 @@ static void virtio_pci_set_vector(VirtIODevice *vdev, } /* If the new vector changed need to set it up. */ if (kvm_irqfd && new_vector !=3D VIRTIO_NO_VECTOR) { - kvm_virtio_pci_vector_use_one(proxy, queue_no); + if (kvm_virtio_pci_vector_use_one(proxy, queue_no)) { + virtio_error(vdev, "fail to set the vector %d", new_vector); + } } } =20 --=20 2.45.0