From nobody Wed Nov 27 04:41:04 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1701504201; cv=none; d=zohomail.com; s=zohoarc; b=bvADFKkAxzbZvzbz+a5vmuVHQ+1r2Pv4bPXE0Osz2UCns8Yvn5dWNhYY/4o/ZM1LeGtHhCPhglcRmBeyG0qI3fMlFnEyRT+lsPz1H+IJVTJ6pVUZSzECafO+wXXaCXN6rDuKeT/ZN2iGnV3waTEfOYmbtn4/e28zUBx+SiH4onU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701504201; h=Content-Type:Content-Transfer-Encoding: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=nifxH5Ik7WtdTWPOluQ6Dk90tFkOKKIHCCiZQjqggm0=; b=RJNTZDgzql+w9TcYlFf7fn2xJsFHojYmge+0YoM+MaD669uvoKgc2Hf+kevMj7QtX2x/3VNOe/vy/cKH+o7hcrEfOaUF5M9jDVD1VIoc0s/uInlhn1FK5OMbD9jN4EXXG7r0f/81NBytvSBNP8WoXzFjvc3A27PLpAqHQJegvkc= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701504201141324.3189888240248; Sat, 2 Dec 2023 00:03:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9Kvj-0004Jf-H9; Sat, 02 Dec 2023 03:00:51 -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 1r9KvY-0004I8-Id for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:43 -0500 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9KvV-0004wL-Pz for qemu-devel@nongnu.org; Sat, 02 Dec 2023 03:00:40 -0500 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1faf56466baso896786fac.3 for ; Sat, 02 Dec 2023 00:00:37 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id z23-20020a17090a015700b00285be64e529sm404492pje.39.2023.12.02.00.00.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Dec 2023 00:00:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1701504035; x=1702108835; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nifxH5Ik7WtdTWPOluQ6Dk90tFkOKKIHCCiZQjqggm0=; b=tKWyFLVGdx5JF3IoLtjdPuhpXwKcx7LRFR109SjAQ9Mcwxq6WMZ7Ow/RCrEpcsRjB/ D9jQS7n5LzqudmvbtBBcTKKXkvpKUifuQf01ZqHDPpofgGdRGiGHcQo9+mtkjuypcEUI vPTexbgskTqp3Z/ZJ2q2uQO0geiKB1YnIBiPSMQs4oIuS/0GhvGMSCzxmd04LzDQey8j QGR/sMEZbK2Mapxbydh1WaegAr3ip6+nxNNbvEZLZFJpefoSuSxd2/8i4kyS22vohlCO TEP7kDRBacHfVxEGD9WHNBUJKXNtj6Jg4JYXaXfwwphrfX3/mgwjPqxPf8grc1sJ5RO6 cjJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701504035; x=1702108835; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nifxH5Ik7WtdTWPOluQ6Dk90tFkOKKIHCCiZQjqggm0=; b=TdhhrbSVGUEedS4XaxMX5PKqTlGz73uW3qLNsg32c/jiVWyHlIgGpKWaawLA8TxgpF 1yWdkBlidGqL0HrkSfJZwxPFEGkDZ49UWkh7kOGAbJhwI+8r2X61KXF+GHFVFVBNQN9u KbaQ61b8FFQVzc/G5RVeGkVC3RYOSf/cX2zd5f1kUVtQl5sfMMDbWnX32zKnLO92B5Wu vVMRsI9RMVfpV4/e06itNcFuNDeqLURLnuSHONSWtkjAKU91zgzUsh42XHgQUcBAH1F7 6bQtShXpP5t0WhjO5VZINWOHUqbc9t8VMDJJbAvBu08rUU7bLhAVpO3Edptbq5VzIX7t BmaA== X-Gm-Message-State: AOJu0Yw+S4gifJCKsCgRCC/nCQphYHgpPjkNR0lXYs7rmVsI5Qp9dW7u SQRWSK18VS+k5DyZNVbnlBhLVQ== X-Google-Smtp-Source: AGHT+IFvn1mUUHFyNEu1N1UpK1OajUfnJSAZsNIBLWwj+zcI6v2p0dT2kmY8PUL5XcXsJ3Fj8e5EAA== X-Received: by 2002:a05:6870:f78e:b0:1fb:75b:2fb5 with SMTP id fs14-20020a056870f78e00b001fb075b2fb5mr1236316oab.76.1701504035166; Sat, 02 Dec 2023 00:00:35 -0800 (PST) From: Akihiko Odaki Date: Sat, 02 Dec 2023 17:00:24 +0900 Subject: [PATCH 01/14] vfio: Avoid inspecting option QDict for rombar MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231202-sriov-v1-1-32b3570f7bd6@daynix.com> References: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> In-Reply-To: <20231202-sriov-v1-0-32b3570f7bd6@daynix.com> To: "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Jason Wang , Sriram Yagnaraman , Keith Busch , Klaus Jensen Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Yui Washizu , Akihiko Odaki X-Mailer: b4 0.12.4 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: none client-ip=2001:4860:4864:20::2a; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701504202929000003 vfio determines if rombar is explicitly enabled by inspecting QDict. Inspecting QDict is not nice because QDict is untyped and depends on the details on the external interface. Instead of inspecting QDict, inspect PCIDevice::rom_bar. PCIDevice::rom_bar is changed to have -1 by the default to tell rombar is explicitly enabled. It is consistent with other properties like addr and romsize. Signed-off-by: Akihiko Odaki --- include/hw/pci/pci_device.h | 5 +++++ hw/pci/pci.c | 2 +- hw/vfio/pci.c | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index d3dd0f64b2..5b6436992f 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -205,6 +205,11 @@ static inline uint16_t pci_get_bdf(PCIDevice *dev) return PCI_BUILD_BDF(pci_bus_num(pci_get_bus(dev)), dev->devfn); } =20 +static inline bool pci_rom_bar_explicitly_enabled(PCIDevice *dev) +{ + return d->rom_bar && d->rom_bar !=3D -1; +} + uint16_t pci_requester_id(PCIDevice *dev); =20 /* DMA access functions */ diff --git a/hw/pci/pci.c b/hw/pci/pci.c index c49417abb2..53c59a5b9f 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -71,7 +71,7 @@ static Property pci_props[] =3D { DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1), DEFINE_PROP_STRING("romfile", PCIDevice, romfile), DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, -1), - DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), + DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, -1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c62c02f7b6..bc29ce9194 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1008,7 +1008,6 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) { uint32_t orig, size =3D cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK); off_t offset =3D vdev->config_offset + PCI_ROM_ADDRESS; - DeviceState *dev =3D DEVICE(vdev); char *name; int fd =3D vdev->vbasedev.fd; =20 @@ -1042,7 +1041,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) } =20 if (vfio_opt_rom_in_denylist(vdev)) { - if (dev->opts && qdict_haskey(dev->opts, "rombar")) { + if (pci_rom_bar_explicitly_enabled(&vdev->pdev)) { warn_report("Device at %s is known to cause system instability" " issues during option rom execution", vdev->vbasedev.name); --=20 2.43.0