From nobody Mon Feb 9 09:54:03 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1770231982; cv=none; d=zohomail.com; s=zohoarc; b=ZFtRLEary2373aj7pSY3uRYBLc5lx9COcHdxC5eRM7rcMjHxYB3JLiMHCFVfU+xBWA+ufjSdDlk6T5pPFAPQ7Vj168qh5q2fIF386aQIQke3sA7sHAuhuy9TNwqJ0HWUMqWNvEtIEHEd+H4arXSUJkAHxJqtelsodVC/TMvdtmA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770231982; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MiaTbqhOE9vPSks7gTjD35BsK/E0RnS5hv86ySxDrko=; b=cM2RXRT/uoJq6sEor63701PfS4FfsX7zSjWhQA8BRYiyAYAqlShnMfeHsPIBqOwG/wpm90IxAmgd65l6AAoyETewsk/MxWbXTx6vVVaLRHZieXvWng1ne4Qz2AgNLiU1Ln1SGwkWSDiEzyq5HgeHGKMfw5oYYsRkFiin7Bz79b4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177023198266570.26380786625566; Wed, 4 Feb 2026 11:06:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vniAi-0001WG-Cd; Wed, 04 Feb 2026 14:04:16 -0500 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 1vniAg-0001C5-1I for qemu-devel@nongnu.org; Wed, 04 Feb 2026 14:04:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vniAd-00083X-8x for qemu-devel@nongnu.org; Wed, 04 Feb 2026 14:04:13 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-gwvebeLeMPW4vTBGF3RtXA-1; Wed, 04 Feb 2026 14:04:09 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4325b81081aso149821f8f.3 for ; Wed, 04 Feb 2026 11:04:09 -0800 (PST) Received: from redhat.com (IGLD-80-230-34-155.inter.net.il. [80.230.34.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4361805faf7sm8232731f8f.30.2026.02.04.11.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Feb 2026 11:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770231850; 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=MiaTbqhOE9vPSks7gTjD35BsK/E0RnS5hv86ySxDrko=; b=H3DYliCMEonbhWn64QQ2Lx4W1oE/0xPUu0vRXHPhaLHnHSw73JyanCvMuZsN2k1xjuMEyC 1Is79y3h02EwWndY/KP7q20qVyR6IQr/CWrKyAQKBCGaE2yzcgxigFty3xHh9tsDyJI34a Kl59vEegp5/MLBbttxoUW+3ClhIYoUs= X-MC-Unique: gwvebeLeMPW4vTBGF3RtXA-1 X-Mimecast-MFC-AGG-ID: gwvebeLeMPW4vTBGF3RtXA_1770231848 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770231848; x=1770836648; darn=nongnu.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=MiaTbqhOE9vPSks7gTjD35BsK/E0RnS5hv86ySxDrko=; b=L3GED1Asaou1AlnqIrwg90KYFaRCpjF4jIH1bptMAsm76W3FXWw1QEmHZKsm7syLYE a6dvUD/EDMXPt7KPTydN3OAFPEzbXgNFsE7DFaQXCPKuC4ciW3vb+XL5C5k6yjiNZQMR 9VGnJ7Q/pngzYNvlmX2hsQsb06nTXCdimsLy69TSxPnDnKnKNz8i3W85JLwa9EhhwY28 1YuTLucCXrtCa3OaaKhARSXPxhInNNrru2GXqIhVarZy3UPkUA2v0E8tUAfc7kBRq84I mq37H2PCaYDRyBPAUEKQ864oHL6pZf6ivOBd2QljoB5ggbTId1MXB0g3D3ZnFJDlHz+0 5P7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770231848; x=1770836648; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MiaTbqhOE9vPSks7gTjD35BsK/E0RnS5hv86ySxDrko=; b=ZPc0f1GuYzGQisJ5sKteZRL7HOPvBtXIxqlyo9dilVU0SlxASPz8OhhAyoDF18y/ea 7/npigJTENGIsdy1g1ikZ19SwyUrUtM0e48ip3tUoyMlkf1/KQkUKByQK5mIm5tjfdUi 2Wn3YAdjXDOvDUf+4+HessU2ZGcGfgdNwBnqoaUNSfTqb0LtvhTgysXIDqESBN15sq9j 67l0uFFSwAIbchJCkpMgCfQYJxnT7KJSLmaIdZU7hpn7WQ5ArkmpOSeGuiZvdG3ocOl3 ENRXhVuOJPY0E2alzba1/MEC3AMFlO9agBE0I+twihgN8p4fF0oketeCbaaDghV2GJex dKsA== X-Gm-Message-State: AOJu0YxCbAw/1qHUu0yBZ8sv9hgcfuzkpP+1GmuNb5XXJb4vylvTWxZo TlNaR2uv6spHE5svf6UwT3aRPtSmzwsGO71GbeghSULO8su0qom7fDtIeGl+10eQwo9GTaxNxKW qatrQ48YhNZLSGMcUw5UVXc4NUaNFu6hoo7HfGeJaHGoIVwkKqTIqkd4yLQKrPQKGhRIs0Wm2kC RFrK4IWCkSKlAD0fS0x93RNyfg+Liec2Utjg== X-Gm-Gg: AZuq6aJ4YqVchHkkehuGEpi1pqeexE64t980cWAMSjf1MIRbhbrZtCkxIee794eLBpU AFR93pW9hFqkRHypxboyOmARfM3jO6VfxhQ2JpkEMPkP/ZGsT/XDin7MYN8HBRiwVXcO7yJvdWH oLRcDmbylKW25NEtccNno5SEgSAJDEUK9Z0T1iTD0TbRPiIggmggrKa8Kqkyn/RT6uyIKNdQuYp rLr2FXNK8yuyql+kMsydxVl9JK4eBuIj6rqvMwi/KcwV8fTJKBX98iYG7QU8YEg/2Idg5ORnABF gO0sG6paLLezNITSyYTYNB6JtHKtjgKSe+ueDyq2QZYjCZQSInbyNljOrDghbT64ukggT/MOH71 JecF5Q/N4z6H6ZI8IGU0gZyFJHYwiso053Q== X-Received: by 2002:a05:6000:2311:b0:435:9bf5:b336 with SMTP id ffacd0b85a97d-43617e3c6f3mr6205298f8f.19.1770231847783; Wed, 04 Feb 2026 11:04:07 -0800 (PST) X-Received: by 2002:a05:6000:2311:b0:435:9bf5:b336 with SMTP id ffacd0b85a97d-43617e3c6f3mr6205235f8f.19.1770231847229; Wed, 04 Feb 2026 11:04:07 -0800 (PST) Date: Wed, 4 Feb 2026 14:04:05 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Kevin Wolf , qemu-stable@nongnu.org, Stefan Hajnoczi Subject: [PULL 33/51] virtio: Fix crash when sriov-pf is set for non-PCI-Express device Message-ID: <0f5b6103768b1e09ada8c06f105f5e167715dbf1.1770231744.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1770231983870158500 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kevin Wolf Setting the sriov-pf property on devices that aren't PCI Express causes an assertion failure: $ qemu-system-x86_64 \ -blockdev null-co,node-name=3Dnull \ -blockdev null-co,node-name=3Dnull2 \ -device virtio-blk,drive=3Dnull,id=3Dpf \ -device virtio-blk,sriov-pf=3Dpf,drive=3Dnull2 qemu-system-x86_64: ../hw/pci/pcie.c:1062: void pcie_add_capability(PCI= Device *, uint16_t, uint8_t, uint16_t, uint16_t): Assertion `offset >=3D PC= I_CONFIG_SPACE_SIZE' failed. This is because proxy->last_pcie_cap_offset is only initialised to a non-zero value in virtio_pci_realize() if it's a PCI Express device, and then virtio_pci_device_plugged() still tries to use it. To fix this, just skip the SR-IOV code for !pci_is_express(). Then the next thing pci_qdev_realize() does is call pcie_sriov_register_device(), which returns the appropriate error. Cc: qemu-stable@nongnu.org Fixes: d0c280d3fac6 ('pcie_sriov: Make a PCI device with user-created VF AR= I-capable') Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Message-Id: <20251204172657.174391-1-kwolf@redhat.com> --- hw/virtio/virtio-pci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index b273eb2691..1e8f90df34 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2183,15 +2183,17 @@ static void virtio_pci_device_plugged(DeviceState *= d, Error **errp) PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar); } =20 - if (pci_is_vf(&proxy->pci_dev)) { - pcie_ari_init(&proxy->pci_dev, proxy->last_pcie_cap_offset); - proxy->last_pcie_cap_offset +=3D PCI_ARI_SIZEOF; - } else { - res =3D pcie_sriov_pf_init_from_user_created_vfs( - &proxy->pci_dev, proxy->last_pcie_cap_offset, errp); - if (res > 0) { - proxy->last_pcie_cap_offset +=3D res; - virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV); + if (pci_is_express(&proxy->pci_dev)) { + if (pci_is_vf(&proxy->pci_dev)) { + pcie_ari_init(&proxy->pci_dev, proxy->last_pcie_cap_offset); + proxy->last_pcie_cap_offset +=3D PCI_ARI_SIZEOF; + } else { + res =3D pcie_sriov_pf_init_from_user_created_vfs( + &proxy->pci_dev, proxy->last_pcie_cap_offset, errp); + if (res > 0) { + proxy->last_pcie_cap_offset +=3D res; + virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV); + } } } } --=20 MST