From nobody Sat Oct 25 23:37:40 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516216930891101.5827932647187; Wed, 17 Jan 2018 11:22:10 -0800 (PST) Received: from localhost ([::1]:56309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebtHl-0000xH-Uv for importer@patchew.org; Wed, 17 Jan 2018 14:22:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebtFx-0008HO-4s for qemu-devel@nongnu.org; Wed, 17 Jan 2018 14:20:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebtFs-0000mx-78 for qemu-devel@nongnu.org; Wed, 17 Jan 2018 14:20:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33542) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebtFr-0000mE-U7; Wed, 17 Jan 2018 14:20:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F37B85F7B2; Wed, 17 Jan 2018 19:20:10 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B613A4BF; Wed, 17 Jan 2018 19:19:50 +0000 (UTC) From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 21:19:47 +0200 Message-Id: <20180117191947.14082-1-marcel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 17 Jan 2018 19:20:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] hw/pci-bridge: fix pcie root port's IO hints capability 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: marcel@redhat.com, qemu-stable@nongnu.org, zuban32s@gmail.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The gen_pcie_root_port mem-reserve and pref32-reserve properties are defined as size (so uint64_t), but passed as uint32_t when building the 'IO hints' vendor specific capability. Passing 4G (or more) gets truncated and passed as a zero reservation. Is not a huge issue since the guest firmware will always compare the hints with the default value and take the maximum. Fix it by passing the values as uint64_t and failing to init the gen_pcie_root_port id invalid values are used. Signed-off-by: Marcel Apfelbaum --- hw/pci/pci_bridge.c | 24 +++++++++++++++++++----- include/hw/pci/pci_bridge.h | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index b2e50c36a0..40a39f57cb 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -412,22 +412,36 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bu= s_name, =20 int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, uint32_t bus_reserve, uint64_t io_res= erve, - uint32_t mem_non_pref_reserve, - uint32_t mem_pref_32_reserve, + uint64_t mem_non_pref_reserve, + uint64_t mem_pref_32_reserve, uint64_t mem_pref_64_reserve, Error **errp) { - if (mem_pref_32_reserve !=3D (uint32_t)-1 && + if (mem_pref_32_reserve !=3D (uint64_t)-1 && mem_pref_64_reserve !=3D (uint64_t)-1) { error_setg(errp, "PCI resource reserve cap: PREF32 and PREF64 conflict"); return -EINVAL; } =20 + if (mem_non_pref_reserve !=3D (uint64_t)-1 && + mem_non_pref_reserve >=3D (1ULL << 32)) { + error_setg(errp, + "PCI resource reserve cap: mem-reserve must be less tha= n 4G"); + return -EINVAL; + } + + if (mem_pref_32_reserve !=3D (uint64_t)-1 && + mem_pref_32_reserve >=3D (1ULL << 32)) { + error_setg(errp, + "PCI resource reserve cap: pref32-reserve must be less= than 4G"); + return -EINVAL; + } + if (bus_reserve =3D=3D (uint32_t)-1 && io_reserve =3D=3D (uint64_t)-1 && - mem_non_pref_reserve =3D=3D (uint32_t)-1 && - mem_pref_32_reserve =3D=3D (uint32_t)-1 && + mem_non_pref_reserve =3D=3D (uint64_t)-1 && + mem_pref_32_reserve =3D=3D (uint64_t)-1 && mem_pref_64_reserve =3D=3D (uint64_t)-1) { return 0; } diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h index 9b44ffd22a..0347da52d2 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -135,8 +135,8 @@ typedef struct PCIBridgeQemuCap { =20 int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, uint32_t bus_reserve, uint64_t io_reserve, - uint32_t mem_non_pref_reserve, - uint32_t mem_pref_32_reserve, + uint64_t mem_non_pref_reserve, + uint64_t mem_pref_32_reserve, uint64_t mem_pref_64_reserve, Error **errp); =20 --=20 2.13.5