From nobody Mon Feb 9 16:12:51 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=1625670382; cv=none; d=zohomail.com; s=zohoarc; b=Ld8S56q1i37eWqo82fGb9r69C0n4fqGrZcaFsKlRK1IGBTWqrTczMDK+FT1My1ZlmUR9Qdb8wckVwdAQg6xk2zz31/xyXBx2DzaL+PrizXXRtIcFUHkom0s6QPCTy4/+d71q6DYZ/9OV58qekNhEfF8ASdmbSOG2XeIe7GoIpx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625670382; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r8YtJo3PAzaP/cJrC4HQaYAbQLl82vsk2k1/IS5JPV8=; b=kUdQ7NwYki7aNzEmMq5qyzL3NUti2XRYHrtF3qp64kKUitguM2vVS3J0LkywzIcQJf3tMhijHZzdRaRIenBc4zBNkuShVQIW8fwPPuL84vvAPwVbkLre4MeLGJqEWC04AYo/FlyKVqUThCFsDpdlJIb6/eN1TZRLwfsMlmCC6i0= 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 1625670382593951.5702120713985; Wed, 7 Jul 2021 08:06:22 -0700 (PDT) Received: from localhost ([::1]:33532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1981-0000Mb-Fq for importer@patchew.org; Wed, 07 Jul 2021 11:06:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1954-0000iz-R2 for qemu-devel@nongnu.org; Wed, 07 Jul 2021 11:03:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1953-0006bq-81 for qemu-devel@nongnu.org; Wed, 07 Jul 2021 11:03:18 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-6rZL2uGyOTOetLOfy6tB1w-1; Wed, 07 Jul 2021 11:03:15 -0400 Received: by mail-wr1-f71.google.com with SMTP id h104-20020adf90710000b029010de8455a3aso874446wrh.12 for ; Wed, 07 Jul 2021 08:03:15 -0700 (PDT) Received: from redhat.com ([2.55.150.102]) by smtp.gmail.com with ESMTPSA id h15sm19984573wrq.88.2021.07.07.08.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 08:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625670196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r8YtJo3PAzaP/cJrC4HQaYAbQLl82vsk2k1/IS5JPV8=; b=M4zCMrBwpYXonMN3yrsVgiy7VzUzgS9ggcRLBnMC2ao+MQOBEk5h7l1/HmC0IQyCEookZv bHjtfYjmtdYNW/QRf8gPocNcN7Ia8XPc/6yN6O4QQoPJR44wt4cYKxKiPVKI1ufFOkNe6O jq+p00iHBNFn4fVGk5GLXR3OK+lQlbg= X-MC-Unique: 6rZL2uGyOTOetLOfy6tB1w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=r8YtJo3PAzaP/cJrC4HQaYAbQLl82vsk2k1/IS5JPV8=; b=VGyMmQAH7M6GjPaEFqIRqeDf0w9r3dP1ZR7+EDSPea/RqUBR0cvZ2LfWDYzRswtfTA OHWmjqku6iDqnDF/r5aIhdMaE+YPvaSjnkAOt855+WmAKHXn6WBVbmwKvl5G7GPx8Xk4 Z5v6/jKL68vr4zuwOTFX2SIyRiLfIQhMKvOCmVroyMO1ld1GLrbf5HYHbefCw473z+2R vtlB7olv+4Lk2GXXbeYWNl1nGYKz+YmTUhSfBT9qunuFJih2CcP551a78rjw3TQQ/OSt jHnpgsIKw2zHTTWPAU3I5380E74QKzh99tYDnvJoc1FChh0mwXphjCahonVVahnRSd9A Xz9g== X-Gm-Message-State: AOAM532c69yVSw237FiZD2M8jvSLcmZ0WzVD1YXlx4IYk+a3ZEzkvyFv Cg0ZMuN64ekdsiyWg5Othjq3q9swpf1o2KZmdrEQhuh8wRuaVLlTaOZdx4vhCoIx+ETzWbKOUkE hYgyTJp9mLi+HoCpelzgi7eL/H+CQC2W9b/bWQYmHe0/1I2l8B+T5K2dDdeZo X-Received: by 2002:adf:eb82:: with SMTP id t2mr28360113wrn.337.1625670193964; Wed, 07 Jul 2021 08:03:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3YbU1uyMgKlXwm1wvne+ZvzCa8rn8EYiuLKM7Ph+PG2lZE7ckG9xkeuKVwmoMf1uy0/qHuQ== X-Received: by 2002:adf:eb82:: with SMTP id t2mr28360091wrn.337.1625670193767; Wed, 07 Jul 2021 08:03:13 -0700 (PDT) Date: Wed, 7 Jul 2021 11:03:09 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 05/13] virtio-pci: Added check for virtio device in PCI config cbs. Message-ID: <20210707150157.52328-6-mst@redhat.com> References: <20210707150157.52328-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210707150157.52328-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.439, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: Peter Maydell , Andrew Melnychenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1625670383547100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Andrew Melnychenko Now, if virtio device is not present on virtio-bus - pci config callbacks will not lead to possible crush. The read will return "-1" which should be interpreted by a driver that pci device may be unplugged. Signed-off-by: Andrew Melnychenko Message-Id: <20210609095843.141378-3-andrew@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-pci.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 1bef7a2be8..c0d9c47df7 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -424,6 +424,11 @@ static uint64_t virtio_pci_config_read(void *opaque, h= waddr addr, VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); uint32_t config =3D VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev); uint64_t val =3D 0; + + if (vdev =3D=3D NULL) { + return UINT64_MAX; + } + if (addr < config) { return virtio_ioport_read(proxy, addr); } @@ -455,6 +460,11 @@ static void virtio_pci_config_write(void *opaque, hwad= dr addr, VirtIOPCIProxy *proxy =3D opaque; uint32_t config =3D VIRTIO_PCI_CONFIG_SIZE(&proxy->pci_dev); VirtIODevice *vdev =3D virtio_bus_get_device(&proxy->bus); + + if (vdev =3D=3D NULL) { + return; + } + if (addr < config) { virtio_ioport_write(proxy, addr, val); return; --=20 MST