From nobody Mon Nov 23 04:26:16 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1793643264; cv=pass; d=zohomail.com; s=zohoarc; b=MiVEaQIo0J9K3bBvAueqGsLvlbzqdfcggqAmmzq+xaevPIqAFdDsdK+Ty7gMqjrhf/oTh5TYJUmnRk1i4xJw8byBpphyz2mSwVaHbHkxKwFd8K1qNvjLFG5ANlvAOcUnRAsxzMjk18N3pcwDVG6MF0XvezelvCB7vpm+GACEz6U= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793643264; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ad487xinjB6pLt2nzkmVd9lN0ap/UJ4uHyCssk0HV7k=; b=LZ3HBCG2O3qSrE/P5M/riXWFd4tt11zXTg6+LQ9jpZWZBwb97LgwyLqccBIy4OaxxIf5iNGBtLqD5nvIbnumF3suhWuyMYFhl00ec4No9qwSRPhCvrOvXs5P590olYhCrwEUMhOAbxvdfcHxDAEyA/MiEVutlGM965KqRdyq7gA= ARC-Authentication-Results: i=2; 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=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793643264488573.360407570174; Mon, 2 Nov 2026 10:14:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNwXS-0004zd-Pk; Mon, 02 Nov 2026 13:13:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwXH-0004vy-MG; Mon, 02 Nov 2026 13:13:39 -0500 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwXE-0003Yr-QM; Mon, 02 Nov 2026 13:13:35 -0500 Received: from IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) by BL1PR12MB5993.namprd12.prod.outlook.com (2603:10b6:208:399::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.569.12; Mon, 2 Nov 2026 18:13:02 +0000 Received: from IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1]) by IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1%5]) with mapi id 15.21.0569.011; Mon, 2 Nov 2026 18:13:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sWQzH/8CILD/Qrevh1t8af+VxUxALp7D6DZ5CqyERrnnZK/JZu+WkfZ/xlnWnwsHciaQayiInZlDDJNP7+5Yuf61touo3KgKuegtdHBDyTwlFxGNtT/F4d1+1H1MVQdbG9ZxC5IakEP7m71TvOok0eXcU89suhJ69sDjUr99XgiYDCB9KM5ytl8XM9oYrf14AtUjPzhNYjT3MiJZHhLA2fXJSVIP21Tigkn5fbBza6qDi+nIbalhOUzYAK0yfKp8fS0Izslwb2xxGsbBNuj0SQNtte4wPYLQFhBcGObND8pVQtI3trrgKoN1BK7TaWrgyZAEcRyY/YC3DC4SS8y1/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ad487xinjB6pLt2nzkmVd9lN0ap/UJ4uHyCssk0HV7k=; b=RB9LlIyPU2A/7PzBNd2GH1+PaCiWdrV7e5zN4w3TYQ9G7Hg6LIk2CxUicintkJdc/7zISyY/5ytc/yGZt/fUdtlx4UF9VnleJ9X5ru8pqtiVlLx4zpW4qaLiSqSGHyQc2Alsud06w0ClvzwxCyxOSG3BqKzNLgok0Lq+/GXFdRoQeKtwdB1poWaBh3eTadfwQrGBq9DS/oIUMDByMyiTppnFuL/oNXTM3rOyai+X4c+nuc77PceT7l1k07310vr/FTeVmj6OBb9u23ed+bj3Glacn21YncCu36F2hfgBTmuvp7fEykyUtCWLAtA0nRCcNIPdOY6wC3GNmvG17hwBsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ad487xinjB6pLt2nzkmVd9lN0ap/UJ4uHyCssk0HV7k=; b=rXAm1vztyLA1Un08Z/DT0Ddi9hleUWf995Up7fpj2VY7RmqkEUhUu5I+fe7TIjwEv9kFQwU3ZVpz5nr6BZp5jP4mlRh2Mv5zKj+m3zNkzyTpunt0KGP3K/545cY3x9jOI0somNS1XXFJK4KFGJz53t3WXhUjrAxNC7/ywr9cZISg8HsrOhCUXFaYV5kBkIHZd4OA/AV3utUmej0JL+hqS0aOPPApz8C67AU3KEfvzmSZGyGCXvXezKkqojCLJ5/igJW2UU7Kud+wexkVDDZ4hMnOC+c1wn3x80FmrhJEP05dgSH+M8QoPoSyr5ST1K1sbAiIYdvR3d+VARMuqBZmNw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; From: Tushar Dave To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, marcel@redhat.com, devel@edk2.groups.io, alwilliamson@nvidia.com, jgg@nvidia.com, skolothumtho@nvidia.com, ardb@kernel.org, kraxel@redhat.com, tdave@nvidia.com Subject: [PATCH v2 1/5] hw/pci: introduce PCI fixed BAR properties Date: Mon, 2 Nov 2026 12:12:37 -0600 Message-Id: <20261102181241.3077981-2-tdave@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261102181241.3077981-1-tdave@nvidia.com> References: <20261102181241.3077981-1-tdave@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR04CA0034.namprd04.prod.outlook.com (2603:10b6:610:77::9) To IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR12MB923065:EE_|BL1PR12MB5993:EE_ X-MS-Office365-Filtering-Correlation-Id: f7f99946-b002-4019-fc31-08df390ced14 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|23010399003|376014|11063799006|56012099006|261009223027099003|261028144727099003|261021121427099003|261026140227099003|261022075727099003|261026121527099003|261022105027099003|10067099003|22082099003|18002099003|261102123227099003|6133799003; X-Microsoft-Antispam-Message-Info: nRFucZTMSoMvjnWC8ZQFCEBC4WSol1OKGI2UZeDHZIwo2BKVM4g4VSbQOEXqi7cQhgmJCg30mxRhJp1etYDCHFyNb1rdiBK6M3VddmSucMmtgreKD+Lj885OvBXXBEsgjOm8XTCMTJRf47JlS3m0EPabU5t/NcX5HeoeID0Ar3juSRZ6qgiO1QO87BCMJXZZYCZuKUmfmWYqpFERmWvV3oWT05PVvM4EZEdeo+ifqEly3OlDnmfwYGYthAS/12eDRCvYW5xF84CKQpR7gRVgVO/JqZp3RZyzgsvaAlFib6pDXJp41Cw+A7iL58JPY/PvGVmNrBrNRBlibuLKWrXUqzuj5A9jDQgY3vTp/PaCXoO0QNFRVJE3S9HZ5s40I1Y8fCLHvKdM/ArIeVYWe6/62CvXL77vLFnRs7MgwrDSiiQovdMSuFvIb5IlVpFiYTn/6glQ9tQGTIkShuhPTp14vt2UIiSeDYDZmYd7gGji2WOKaYgyiFe4sN9lcQ//ctFaZtCjBqqLbTZKvhE6HfFBtiEtTuLr9bGqTjQGSHlgMd6hh5xdCltXwWVy4m8rSyKJw184i2Jk4krd95n9hPCNhlvrxj/ki19hIaCOs10JZ1RGV+6V+GGyx5H2oonSce7JEUu3jkDvkTt4kQhuCRdqqOpBfJt04ZN9dTTTP+d80u8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:IA3PR12MB923065.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(11063799006)(56012099006)(261009223027099003)(261028144727099003)(261021121427099003)(261026140227099003)(261022075727099003)(261026121527099003)(261022105027099003)(10067099003)(22082099003)(18002099003)(261102123227099003)(6133799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kp1UF+lXhD7Nf4EIxWdmzxbTqfESHc4HCRrQw1ZKw1liFdJiBRgJzTCtyhp/?= =?us-ascii?Q?A8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GOwfk0?= =?us-ascii?Q?8erJ9fudqPxvo32SbfF4lJbxk2/EDnYRfOwChKzcXnGBgLb0prIk0voQTgJO?= =?us-ascii?Q?c9pX3SFYih35qOi2Q7CG/7gq9MxIQw2MEJ6RIalHaWmzegu/1kurghsLyDnm?= =?us-ascii?Q?qKZ3njMDhkx4tW5gxncZ4y/ByMlLcvkf9x+Sw7bzqywn3KCBecx4+sYgIQ/i?= =?us-ascii?Q?PA1ECpr5Er0J64prvUZtYoTn8REowIbY9yow5ZQM6CKlJc/tQMB1yIrmP5pB?= =?us-ascii?Q?yCJgRsKXfaWShAGSIu94eFR7wFKEZyqrburEL4CMgfdjIUsJ7vJReKqKicp1?= =?us-ascii?Q?QM/5IKHrMF3SSYCy5AaNPqoyYK9oWphYbIEXfUkZ067wTw57HFqzz2/q2e2I?= =?us-ascii?Q?qidMLyamraO1pgOkAJ5Q+CnqI9wNJarqr3K2ziPldx7lHTJppXWK9OHBLdoW?= =?us-ascii?Q?mCPP3w9UK79Ls37N9g9mpsTM5wzqrsW5jdg7gZ+9+4F7rbGjM7PbVYpFGAko?= =?us-ascii?Q?D4Vc9JxVmAMJoldKtS3dUGXgG2T6i1jibbPm+aBHdzDXIizJPxV2pgtAg6E2?= =?us-ascii?Q?mfhmKomnzvXUk2hbf/Domxv7sG6yZ5sObQtju9N06uWoP8+rjWK9P4qRNw4x?= =?us-ascii?Q?QAl59TvTBQdy/8hRyE6/LKtpUo5/3sOJzLl/O5uoonu4+/NLVjbazIpAO4KS?= =?us-ascii?Q?VHNBKIZaLwL+U5GnlYX9903N/gWfncrXavfjQCc/xRQZGxNf111IgxMBfDgs?= =?us-ascii?Q?r5Zg6DOvAsvvyBCHUKCXiZwxlHoWTqt8N2anYdKQIJ7FpukN?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7f99946-b002-4019-fc31-08df390ced14 X-MS-Exchange-CrossTenant-AuthSource: IA3PR12MB923065.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2026 18:12:59.0799 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 34vMiL8OMW4m/7zV5228qvDCJ9R3IRlo0Rs/320Es6kZjj0XjI6dsdkrJnE3bkZ7dhN+FuLKUme1Thm4MbnECA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5993 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:c10d::1; envelope-from=tdave@nvidia.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, SPF_NONE=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: 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 @Nvidia.com) X-ZM-MESSAGEID: 1793643265204158500 Content-Type: text/plain; charset="utf-8" Add fixed-bar-N properties to PCIDevice to allow the guest address of an individual PCI BAR to be explicitly specified. The properties are available for PCI BARs 0 through 5 and accept QEMU size values, for example fixed-bar-0=3D0x40000000 or fixed-bar-0=3D64G. e.g. -device some-device,fixed-bar-0=3D[,fixed-bar-1=3D]... During realize, validate that each specified BAR exists and is a memory BAR, and reject fixed BAR configuration for hot-plugged devices. The fixed BAR properties are only supported on machine types that implement fixed BAR placement. Add the `pci_fixed_bar_supported` MachineClass flag to advertise this support, and reject fixed BAR properties on machine types that do not set it. Signed-off-by: Tushar Dave Acked-by: Gerd Hoffmann --- hw/pci/pci.c | 71 +++++++++++++++++++++++++++++++++++++ include/hw/core/boards.h | 3 ++ include/hw/pci/pci_device.h | 7 ++++ 3 files changed, 81 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2d2fe02c68..e9ae0d5648 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -89,6 +89,18 @@ static const Property pci_props[] =3D { DEFINE_PROP_STRING("romfile", PCIDevice, romfile), DEFINE_PROP_UINT32("romsize", PCIDevice, romsize, UINT32_MAX), DEFINE_PROP_INT32("rombar", PCIDevice, rom_bar, -1), + DEFINE_PROP_SIZE("fixed-bar-0", PCIDevice, fixed_bar_addr[0], + PCI_BAR_UNMAPPED), + DEFINE_PROP_SIZE("fixed-bar-1", PCIDevice, fixed_bar_addr[1], + PCI_BAR_UNMAPPED), + DEFINE_PROP_SIZE("fixed-bar-2", PCIDevice, fixed_bar_addr[2], + PCI_BAR_UNMAPPED), + DEFINE_PROP_SIZE("fixed-bar-3", PCIDevice, fixed_bar_addr[3], + PCI_BAR_UNMAPPED), + DEFINE_PROP_SIZE("fixed-bar-4", PCIDevice, fixed_bar_addr[4], + PCI_BAR_UNMAPPED), + DEFINE_PROP_SIZE("fixed-bar-5", PCIDevice, fixed_bar_addr[5], + PCI_BAR_UNMAPPED), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, @@ -228,6 +240,58 @@ static void pci_bus_unrealize(BusState *qbus) vmstate_unregister(NULL, &vmstate_pcibus, bus); } =20 +static bool pci_dev_has_fixed_bar(PCIDevice *pci_dev) +{ + int i; + + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + if (pci_dev->fixed_bar_addr[i] !=3D PCI_BAR_UNMAPPED) { + return true; + } + } + return false; +} + +static void pci_check_fixed_bars(PCIDevice *pci_dev, Error **errp) +{ + PCIIORegion *r; + int i; + + if (!pci_dev_has_fixed_bar(pci_dev)) { + return; + } + + if (!MACHINE_GET_CLASS(qdev_get_machine())->pci_fixed_bar_supported) { + error_setg(errp, "fixed BAR placement is not supported by this " + "machine type"); + return; + } + + if (DEVICE(pci_dev)->hotplugged) { + error_setg(errp, "fixed BAR placement is not supported on " + "hot-plugged devices"); + return; + } + + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + if (pci_dev->fixed_bar_addr[i] =3D=3D PCI_BAR_UNMAPPED) { + continue; + } + + r =3D &pci_dev->io_regions[i]; + if (!r->size) { + error_setg(errp, "fixed-bar-%d: bar%d does not exist on %s", + i, i, pci_dev->name); + return; + } + if (r->type & PCI_BASE_ADDRESS_SPACE_IO) { + error_setg(errp, "fixed-bar-%d: bar%d on %s is an I/O BAR, " + "not a memory BAR", i, i, pci_dev->name); + return; + } + } +} + static int pcibus_num(PCIBus *bus) { if (pci_bus_is_root(bus)) { @@ -2399,6 +2463,13 @@ static void pci_qdev_realize(DeviceState *qdev, Erro= r **errp) is_default_rom =3D true; } =20 + pci_check_fixed_bars(pci_dev, &local_err); + if (local_err) { + error_propagate(errp, local_err); + pci_qdev_unrealize(DEVICE(pci_dev)); + return; + } + pci_add_option_rom(pci_dev, is_default_rom, &local_err); if (local_err) { error_propagate(errp, local_err); diff --git a/include/hw/core/boards.h b/include/hw/core/boards.h index d0e4ad9820..8092634eb3 100644 --- a/include/hw/core/boards.h +++ b/include/hw/core/boards.h @@ -242,6 +242,8 @@ typedef struct { * is not needed. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise + * @pci_fixed_bar_supported: + * true if the machine supports fixed PCI BAR placement and false other= wise * @hotplug_allowed: * If the hook is provided, then it'll be called for each device * hotplug to check whether the device hotplug is allowed. Return @@ -317,6 +319,7 @@ struct MachineClass { bool ignore_boot_device_suffixes; bool nvdimm_supported; bool numa_mem_supported; + bool pci_fixed_bar_supported; bool auto_enable_numa; bool cpu_cluster_has_numa_boundary; SMPCompatProps smp_props; diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 5cac6e1688..db4a003ae3 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -187,6 +187,13 @@ struct PCIDevice { uint32_t max_bounce_buffer_size; =20 char *sriov_pf; + + /* + * fixed_bar_addr[N] holds the guest address configured via the + * fixed-bar-N property for memory BAR N. PCI_BAR_UNMAPPED means + * the BAR's address is not fixed. + */ + uint64_t fixed_bar_addr[PCI_NUM_REGIONS - 1]; }; =20 static inline int pci_intx(PCIDevice *pci_dev) --=20 2.34.1 From nobody Mon Nov 23 04:26:16 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1793643232; cv=pass; d=zohomail.com; s=zohoarc; b=mvhNURYFIPNY83HwzJnQqp7ep5xPozNL38QeYaiK7Kxwp3dwxr/ozGCqw2C4hTxO1wTyDNLWWo/W/QtSocwO1DISqbhElgJ5oV0SgwD9yZokEwcuaSOVLG5dh94I5TeaxChyQXlMBqWIQQNW7CjSTsoPY6etj/rBBawJxAPefjE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793643232; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aubpBettuI0SALPn0lzCAzDsbe0oC3dChyHdfmHl4z8=; b=APl192shh2RDYvdAx/RrC8WRgI2FagdhAH15QFl4n590qyFOnMykmDVY3pboRs/x8XIhkpoOMg0AMncLNuEgmO6b/sBs8A7giJjONHQo4m1lxKJB3KSIj9ntnxV+ItX09nSCcKCBEjTxBFexTDBloztUHM43gOxG9s0zk7TOMno= ARC-Authentication-Results: i=2; 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=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793643232442194.55726538862245; Mon, 2 Nov 2026 10:13:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNwXL-0004vR-5O; Mon, 02 Nov 2026 13:13:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwX2-0004t3-SD; Mon, 02 Nov 2026 13:13:22 -0500 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwX0-0003Yr-72; Mon, 02 Nov 2026 13:13:20 -0500 Received: from IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) by BL1PR12MB5993.namprd12.prod.outlook.com (2603:10b6:208:399::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.569.12; Mon, 2 Nov 2026 18:13:05 +0000 Received: from IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1]) by IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1%5]) with mapi id 15.21.0569.011; Mon, 2 Nov 2026 18:13:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b/2iRBULsLUvQwSFPRPFMPl0nO/n2s6rxy9TUo9/+vG5/NwuTDoL9AcMd+njSKfZoqZI+2j4pLQDcXWZqzrzk6MDWJcNUGMsKxw/IXNbtB+4Zhm8Ub/lh/3KGLaWPX0Evp7767MTDKDqdH3ANt9QvIEKJnZGNciQqzwHnUEdKDjh8SrSesxPOzXPCXny5tBtJpAvcja9bl+23Ek5jRJqm6v9WjAGM5cft90QxRN4yLnBizkxu4ivuexAyQwDCf1BzgAbeFu1fNObH15PBmtwPeGSLQFrSGmbRNoHXqwxItNJAh6yN4ogCfG3e1f3aZh3E6y9UrSDP7GnXwEqQFD6Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aubpBettuI0SALPn0lzCAzDsbe0oC3dChyHdfmHl4z8=; b=arOkO/MftbB0vwcj8TB9/mtKpFc+V1F3Kt3EPmV7R1VwM3ka+5fk7jAOSbNtfxWyex7/cTmHBYuI2Rf0Y8kljpEGlcGs4g9PDsmsogiPAcPfQ4M5N35DUIRFmtZW1G6GwtbMO670tfBs3JSraS+Us31o2Cl1HH5sF0ocpaQ/zggKfViQbcOucspshoq6FvgdhUWa8kyFzqKE2Ww+H+nobiobOT/KoeO4nksvOlcEHPS6bU80s6BlarJGPsnfTPvxBQx9DI9KTQiUwYZzIrFcsoQPJpU18rdQJlMaVgly9pYYAFQkD8SzyzxJnJ3G+iRLfHSDSxYfg1cTm/GzvlBCkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aubpBettuI0SALPn0lzCAzDsbe0oC3dChyHdfmHl4z8=; b=hwMgXQRbXb/x8/W0K9VTQ+lq58TOewYTo/ifUeOkbG5xvBrucDgj7IoAn6KxMvh77T2jcIwEeVmePqpgHKmtOWNzLHcAf8H6gS90uiESwguV/6AJf7dcvL/POnd5NKIGeRK2O7Zz9cX+MAHbltjkilaS4rRZnii98NQ5sb5ltNh4ecHdd84c12+dOHSqQRwJqaOZzyNfreHNe8sP5RNKHNg1iolSFfdBrEdchYqtwRel/F9s7CBOL93PkjhjUsNjIRj5SGjxv/GC6x80yY5aLyL2SD5WmJNJfkUnQKb9cVsYjlKk8iWwdMryvxyG9h+lAeOhbljOJ7fEu4EdSS25qQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; From: Tushar Dave To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, marcel@redhat.com, devel@edk2.groups.io, alwilliamson@nvidia.com, jgg@nvidia.com, skolothumtho@nvidia.com, ardb@kernel.org, kraxel@redhat.com, tdave@nvidia.com Subject: [PATCH v2 2/5] hw/pci: add validation for fixed BAR configuration Date: Mon, 2 Nov 2026 12:12:38 -0600 Message-Id: <20261102181241.3077981-3-tdave@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261102181241.3077981-1-tdave@nvidia.com> References: <20261102181241.3077981-1-tdave@nvidia.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR04CA0039.namprd04.prod.outlook.com (2603:10b6:610:77::14) To IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR12MB923065:EE_|BL1PR12MB5993:EE_ X-MS-Office365-Filtering-Correlation-Id: a7308672-ab2a-45ca-f0b0-08df390cee04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|23010399003|376014|260925021311599003|260925021911599003|260925022911599003|5023799004|11063799006|56012099006|261009223027099003|261028144727099003|261021121427099003|261026140227099003|261022075727099003|261026121527099003|261022113327099003|261022105027099003|10067099003|22082099003|18002099003|261102123227099003|6133799003; X-Microsoft-Antispam-Message-Info: q5db6S6nRWXPf6bPjMZ8lzECA7Pcw3kGmIGk9I4JHINktZi2kvkGa1O/w+7Ey40aA41mpSzLg8qOIVLLETQt79x3NWXIQxjdgvHBNNWGYqKqTWIRo5ffslg5PWsUqao/FSIJRCUyuGn7WcAGfZM1vzuUKIgoIj8qAXdtss+fMIy1ZuifADAcvgd1dsdCwng/kpucI1nYzABmExAzgPaNHRLuyiV4/qIckOzverBu7YdH3se6v1fJdmXieV0jrEd3TBl/jVCTbjo/UwDeBzyGWRdv6GJY0z4iB4AggB1K/clD3hCQQ+0K6dVobtb4kuU9iNV6DsfgBgM+Sdq5zd6515dK9sQrzReRJo9N1VcE+hUwG91O6zBFRuPVlQ/AaPSzJ5B+Kr0GATbvR5b7sV4GZTbcYG8nICBl+8XKSpsx/JWPwjQ3VU3M5DazfVgbwz0iAA+a6b6HPOtDNAEae7ZKgkHwUEYJ/4D+N8k7Lv7oAG6yr5AIIg1tTX4lKaC2sYMpRBuX0bTb7IspSlMIJICDdbpxt1zmGq5n0MkC9GbrWEyopRBBqbyKcLqxoLkxz2kNKRLbt7mv1SrA5BFSbvTwqkYZzLau41AmpBlkxP8w/JfInfx9LOio5tR69VAwPpZ8ybtpoFBYO5dZiml+Dpvp4xHjgWuyF/yPvld1bNZgO9Q= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:IA3PR12MB923065.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(260925021311599003)(260925021911599003)(260925022911599003)(5023799004)(11063799006)(56012099006)(261009223027099003)(261028144727099003)(261021121427099003)(261026140227099003)(261022075727099003)(261026121527099003)(261022113327099003)(261022105027099003)(10067099003)(22082099003)(18002099003)(261102123227099003)(6133799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Sm9wa294cHovVTBZVDlObmYrWk5hZGpEdS90UmYxTGJubUZ3bzl5TDNSWG5O?= =?utf-8?B?QXh6ZDFDbXpZS0wvZlRDby9vMFh5ejJCMVN2VFY2eHpLRjIwVHQ0ZEZsUjVK?= =?utf-8?B?M2VOMUVRZlZYMGpaem9BTHNHaXk2bVBvSG5FSENzYlUzYzBsK0VkSGduQnBP?= =?utf-8?B?dk1TZ0dsc0hiRVhUUVB0OWRYRTJJREV2a1NaWnNIc0pQSDFiK0dCYnZncVJE?= =?utf-8?B?THJrYU9RZzlldDNJZFlEd01nM0xJbjNEVStmTlNyUDR0amVlbjVtQm1YU1kr?= =?utf-8?B?YThqOG1GUVpVbC9teTJURExPS0VpYWpoSit6ZEtEQ05HSVJ3dWZzWFprNVRV?= =?utf-8?B?NUNQcWVoeXdEY1JyRmRUNlhkUnNXNVd5NlhoOEQ3eXNMWFF3L0xlWkdnODN4?= =?utf-8?B?cFAwdWx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WN4bU5LQWREcDZHbnBCZ3NId3Q0?= =?utf-8?B?c3NBWVo2Y2FvUWVGNjN0RzMxczFLeFJNbERvVHlnZXBUUGc1WkxsM0hRMUZB?= =?utf-8?Q?kr0G2tJWLgsT3b6evl?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7308672-ab2a-45ca-f0b0-08df390cee04 X-MS-Exchange-CrossTenant-AuthSource: IA3PR12MB923065.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2026 18:13:00.6254 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dZZFkBBmVnGnslR4ZKgXVICnIn7WpumgSTmd+J14MvaN0d5OpOJeMRYzDLAU5REvv6kIbY+gPn+Mu4knY2e3gA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5993 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:c10d::1; envelope-from=tdave@nvidia.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, SPF_NONE=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: 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 @Nvidia.com) X-ZM-MESSAGEID: 1793643234947158500 Validate the fixed BAR configuration specified through the fixed-bar-N properties on PCI endpoint devices. Configuring any fixed-bar-N property on an endpoint device requires every memory BAR on that device to have a fixed address. Validate that each assigned address: - is aligned to its BAR size; - is within the appropriate PCIe MMIO aperture; and - does not overlap any other fixed BAR. A 32-bit BAR must lie in the 32-bit aperture. A prefetchable 64-bit BAR must lie in the 64-bit aperture so that all prefetchable BARs can be accommodated in a single 64-bit prefetchable bridge window. A non-prefetchable 64-bit BAR may lie in either aperture when attached directly to the host bridge, but must lie below 4GiB when placed behind a PCI bridge. Under a PCIe topology with a root port, fixed BAR placement is all-or-nothing within that root port's subtree. If any one endpoint device below the root port has a fixed BAR, every other endpoint device below that same root port with a memory BAR must have all of its memory BARs fixed too. Endpoint devices with no root port in their ancestry, such as those attached directly to the host bridge, are not required to match their sibling devices. One such device may use fixed-bar-N for all of its memory BARs while another sibling device on the same host bridge uses none at all. Per-device completeness still applies regardless of ancestry. Once any fixed-bar-N property is set on a device, every memory BAR on that device must be fixed. Report a validation failure through the Error ** argument and leave it to the caller to decide how to handle it. Signed-off-by: Tushar Dave Acked-by: Gerd Hoffmann --- hw/pci/meson.build | 1 + hw/pci/pci-fixed-bar-validate.c | 365 ++++++++++++++++++++++++++++++++ hw/pci/pci-fixed-bar-validate.h | 22 ++ 3 files changed, 388 insertions(+) create mode 100644 hw/pci/pci-fixed-bar-validate.c create mode 100644 hw/pci/pci-fixed-bar-validate.h diff --git a/hw/pci/meson.build b/hw/pci/meson.build index 984c7327e5..150085c997 100644 --- a/hw/pci/meson.build +++ b/hw/pci/meson.build @@ -19,6 +19,7 @@ endif pci_ss.add(files('pcie.c', 'pcie_aer.c')) pci_ss.add(files('pcie_doe.c')) system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'p= cie_host.c')) +system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-va= lidate.c')) system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss) =20 stub_ss.add(files('pci-stub.c')) diff --git a/hw/pci/pci-fixed-bar-validate.c b/hw/pci/pci-fixed-bar-validat= e.c new file mode 100644 index 0000000000..522d879113 --- /dev/null +++ b/hw/pci/pci-fixed-bar-validate.c @@ -0,0 +1,365 @@ +/* + * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved + * BAR address validation for fixed-BAR placement. + * + * Written by Tushar Dave + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/pci_host.h" +#include "hw/pci/pcie_port.h" +#include "qapi/error.h" +#include "qemu/range.h" +#include "qemu/units.h" +#include "pci-internal.h" +#include "pci-fixed-bar-validate.h" + +/* + * Claimed BAR ranges =E2=80=94 detect inter-device and inter-hierarchy ov= erlaps + * across all fixed BARs system-wide. + */ + +typedef struct { + uint64_t start; + uint64_t end; + const char *owner; /* device name, for error messages */ + int bar; +} FixedClaim; + +static void fixed_claims_init(FixedBarsInfo *info) +{ + info->claims =3D g_array_new(false, true, sizeof(FixedClaim)); +} + +static void fixed_claims_free(FixedBarsInfo *info) +{ + g_array_free(info->claims, true); + info->claims =3D NULL; +} + +static bool fixed_claims_overlap(FixedBarsInfo *info, + uint64_t start, uint64_t end, + const char **owner_out, int *bar_out, + uint64_t *start_out, uint64_t *end_out) +{ + FixedClaim *c; + guint i; + + for (i =3D 0; i < info->claims->len; i++) { + c =3D &g_array_index(info->claims, FixedClaim, i); + if (ranges_overlap(start, end - start + 1, + c->start, c->end - c->start + 1)) { + *owner_out =3D c->owner; + *bar_out =3D c->bar; + *start_out =3D c->start; + *end_out =3D c->end; + return true; + } + } + return false; +} + +static void fixed_claims_add(FixedBarsInfo *info, + uint64_t start, uint64_t end, + const char *owner, int bar) +{ + FixedClaim cl; + + cl.start =3D start; + cl.end =3D end; + cl.owner =3D owner; + cl.bar =3D bar; + g_array_append_val(info->claims, cl); +} + +/* + * Check that the BAR [start..end] fits in the window [base..limit]. + * Both ranges are inclusive. + */ +static bool bar_in_window(uint64_t start, uint64_t end, + uint64_t base, uint64_t limit) +{ + return start >=3D base && end <=3D limit; +} + +static bool validate_bars(PCIDevice *pdev, FixedBarsInfo *info, + bool is_fixed_subtree, Error **errp) +{ + const char *devname =3D DEVICE(pdev)->id ? DEVICE(pdev)->id : pdev->n= ame; + const char *overlap_owner; + bool has_fixed_bars =3D false; + bool is_64bit; + uint64_t addr, end, overlap_start, overlap_end; + PCIIORegion *r; + int overlap_bar; + int i; + + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + if (pdev->fixed_bar_addr[i] !=3D PCI_BAR_UNMAPPED) { + has_fixed_bars =3D true; + break; + } + } + + if (is_fixed_subtree && !has_fixed_bars) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] under fixed-bar roo= t " + "port has memory BARs but no fixed-bar-N=3D specified", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + return false; + } + + if (!has_fixed_bars) { + return true; + } + + /* Completeness: every memory BAR must have an address. */ + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + r =3D &pdev->io_regions[i]; + if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) { + continue; + } + if (pdev->fixed_bar_addr[i] =3D=3D PCI_BAR_UNMAPPED) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "missing a fixed-bar-N=3D value", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i); + return false; + } + } + + /* Per-BAR checks: alignment, MMIO window, overlap. */ + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + r =3D &pdev->io_regions[i]; + if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) { + continue; + } + + is_64bit =3D !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64); + addr =3D (uint64_t)pdev->fixed_bar_addr[i]; + + if (r->size - 1 > UINT64_MAX - addr) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "addr=3D0x%"PRIx64" + size=3D0x%"PRIx64" overflows", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + i, addr, r->size); + return false; + } + end =3D addr + r->size - 1; + + if (is_64bit && !(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH) && + !pci_bus_is_root(pci_get_bus(pdev)) && end >=3D 4 * GiB) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d is a " + "non-prefetchable 64-bit BAR behind a PCI bridge " + "and cannot be placed above 4GB", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i); + return false; + } + + if (addr & (r->size - 1)) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "addr=3D0x%"PRIx64" not aligned to size=3D0x%"PRIx6= 4, + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + i, addr, r->size); + return false; + } + + /* + * A 32-bit BAR must fit in the 32-bit window; a 64-bit BAR in eit= her, + * except a prefetchable one, which must be above 4GiB. + */ + if (is_64bit && (r->type & PCI_BASE_ADDRESS_MEM_PREFETCH)) { + if (!bar_in_window(addr, end, + info->mmio64_base, info->mmio64_limit)) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "[0x%"PRIx64"..0x%"PRIx64"] outside the 64-bit " + "window [0x%"PRIx64"..0x%"PRIx64"]", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + i, addr, end, + info->mmio64_base, info->mmio64_limit); + return false; + } + } else if (is_64bit) { + if (!bar_in_window(addr, end, + info->mmio32_base, info->mmio32_limit) && + !bar_in_window(addr, end, + info->mmio64_base, info->mmio64_limit)) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "[0x%"PRIx64"..0x%"PRIx64"] outside both the " + "32-bit window [0x%"PRIx64"..0x%"PRIx64"] and " + "the 64-bit window [0x%"PRIx64"..0x%"PRIx64"]", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + i, addr, end, + info->mmio32_base, info->mmio32_limit, + info->mmio64_base, info->mmio64_limit); + return false; + } + } else if (!bar_in_window(addr, end, + info->mmio32_base, info->mmio32_limit)) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "[0x%"PRIx64"..0x%"PRIx64"] outside the 32-bit " + "window [0x%"PRIx64"..0x%"PRIx64"]", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + i, addr, end, + info->mmio32_base, info->mmio32_limit); + return false; + } + + if (fixed_claims_overlap(info, addr, end, &overlap_owner, + &overlap_bar, &overlap_start, &overlap_en= d)) { + error_setg(errp, "fixed-bar: %s [%02x:%02x.%x] BAR%d " + "[0x%"PRIx64"..0x%"PRIx64"] overlaps %s BAR%d " + "[0x%"PRIx64"..0x%"PRIx64"]", + devname, pci_dev_bus_num(pdev), + PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), + i, addr, end, overlap_owner, overlap_bar, + overlap_start, overlap_end); + return false; + } + + fixed_claims_add(info, addr, end, devname, i); + } + + info->any_fixed =3D true; + return true; +} + +typedef struct { + FixedBarsInfo *info; + bool is_fixed_subtree; + Error **errp; +} ScanState; + +static void scan_bus(PCIBus *bus, ScanState *state); + +static void mark_if_fixed(PCIBus *bus, PCIDevice *pdev, void *opaque) +{ + bool *found =3D opaque; + PCIBus *sec; + int i; + + if (*found) { + return; + } + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + if (pdev->fixed_bar_addr[i] !=3D PCI_BAR_UNMAPPED) { + *found =3D true; + return; + } + } + if (object_dynamic_cast(OBJECT(pdev), TYPE_PCI_BRIDGE)) { + sec =3D pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); + if (sec) { + pci_for_each_device_under_bus(sec, mark_if_fixed, found); + } + } +} + +/* + * True if any device in rp_bus's subtree (the bus behind a root port) + * has a fixed BAR. + */ +static bool root_port_subtree_has_fixed_bar(PCIBus *rp_bus) +{ + bool found =3D false; + + pci_for_each_device_under_bus(rp_bus, mark_if_fixed, &found); + return found; +} + +static void scan_bus_device(PCIBus *bus, PCIDevice *pdev, void *opaque) +{ + ScanState *state =3D opaque; + bool has_mem_bar =3D false; + PCIIORegion *r; + PCIBus *sec; + int i; + + if (*state->errp) { + return; + } + + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + r =3D &pdev->io_regions[i]; + if (r->size && !(r->type & PCI_BASE_ADDRESS_SPACE_IO)) { + has_mem_bar =3D true; + break; + } + } + + if (has_mem_bar && + !validate_bars(pdev, state->info, state->is_fixed_subtree, + state->errp)) { + return; + } + + if (!object_dynamic_cast(OBJECT(pdev), TYPE_PCI_BRIDGE)) { + return; + } + sec =3D pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); + if (!sec) { + return; + } + + if (object_dynamic_cast(OBJECT(pdev), TYPE_PCIE_ROOT_PORT)) { + ScanState child =3D { + .info =3D state->info, + .is_fixed_subtree =3D root_port_subtree_has_fixed_bar(sec), + .errp =3D state->errp, + }; + scan_bus(sec, &child); + } else { + scan_bus(sec, state); + } +} + +static void scan_bus(PCIBus *bus, ScanState *state) +{ + pci_for_each_device_under_bus(bus, scan_bus_device, state); +} + +static void scan_all_host_bridges(FixedBarsInfo *info, Error **errp) +{ + PCIHostState *hb; + ScanState state =3D { + .info =3D info, + .is_fixed_subtree =3D false, + .errp =3D errp, + }; + + fixed_claims_init(info); + QLIST_FOREACH(hb, &pci_host_bridges, next) { + if (hb->bus) { + scan_bus(hb->bus, &state); + } + } + fixed_claims_free(info); +} + +/* + * fixed_bars_validate - scan all PCI devices, validate fixed BAR addresse= s. + * + * @info: carries MMIO window bounds for validation. + * @errp: set on a validation error. + * + * Returns true if every BAR validated, false with @errp set otherwise. + * Whether any fixed BAR device was found is left in info->any_fixed. + */ +bool fixed_bars_validate(FixedBarsInfo *info, Error **errp) +{ + ERRP_GUARD(); + + info->any_fixed =3D false; + scan_all_host_bridges(info, errp); + return !*errp; +} diff --git a/hw/pci/pci-fixed-bar-validate.h b/hw/pci/pci-fixed-bar-validat= e.h new file mode 100644 index 0000000000..f4996f27d9 --- /dev/null +++ b/hw/pci/pci-fixed-bar-validate.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved + * + * Written by Tushar Dave + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef HW_PCI_FIXED_BAR_VALIDATE_H +#define HW_PCI_FIXED_BAR_VALIDATE_H + +typedef struct { + bool any_fixed; + uint64_t mmio32_base; + uint64_t mmio32_limit; + uint64_t mmio64_base; + uint64_t mmio64_limit; + GArray *claims; +} FixedBarsInfo; + +bool fixed_bars_validate(FixedBarsInfo *info, Error **errp); + +#endif /* HW_PCI_FIXED_BAR_VALIDATE_H */ --=20 2.34.1 From nobody Mon Nov 23 04:26:16 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1793643270; cv=pass; d=zohomail.com; s=zohoarc; b=avj3KlI3aq+D3MzEDxRv2FRxgIVqUrw5I5B91Hy/JFYQHN8PrxmJK8Nz5ZUwF6QTGTSSaqal/uoNYm2Z7tGo4usmjs3MIwYVHiMohwG/iJt89HjYb7t3bSN2V6r2iC2z5mc5DpOyN7Uz9uxhMHUvtX0o93qC9Q6gzY3v7iP+NL0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793643270; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BdBh7qEPaosmkVuXl4SCo6IOUmSBfPREroHerGR4Fio=; b=NFwce7hI5b+toVCr0XXPPg58NcRF24zN4LOYl/kvuVjjHjuyx7+9NilsZBfGED8MR5NH9pzSPJcZgiWKxXt3pXFVhCrwPESD/Zmkr2E1limbwwVdJ87HfamhyXdMCFfKf8Ttmu7w8RmBBnccu3OAp7nliPhXvLvopjogaOuIWuY= ARC-Authentication-Results: i=2; 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=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793643270645620.1523151255781; Mon, 2 Nov 2026 10:14:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNwXR-0004yl-Tk; Mon, 02 Nov 2026 13:13:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwXD-0004vf-ID; Mon, 02 Nov 2026 13:13:39 -0500 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwX9-0003Yr-Hs; Mon, 02 Nov 2026 13:13:31 -0500 Received: from IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) by BL1PR12MB5993.namprd12.prod.outlook.com (2603:10b6:208:399::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.569.12; Mon, 2 Nov 2026 18:13:05 +0000 Received: from IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1]) by IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1%5]) with mapi id 15.21.0569.011; Mon, 2 Nov 2026 18:13:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IZK+cLvk91NTdwB45fB54fdvYcbNDjtNIrttqaYlhf8XPjPNM6/VDZ+Jd5MmZIwSaVmQiU3OObQoScudSf7opMVzGADfjQc84Kke924RRzISivDPWRdE+8hHhE+tLex2CSJem6c8ANbLVrUjBpq3Umf3l82VKEPNCBQ6BKjK7wGUkmfblbhLGo9yrMec0+jtrTesIpZq0sg7DB/Fhr5EtFQPyM7qDn6Edr7nVqX8FuRiACPSdt6kBQNp8bFkJK3PgQ1z7wdhqT1p2g3B7ix51T3WXyz3mxZYtwZOZsoTsXIHWN65PJv7bEAdPlRrtEehmMd6IRRYZXFI6tJuzo+2eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BdBh7qEPaosmkVuXl4SCo6IOUmSBfPREroHerGR4Fio=; b=Jgyws37YxghiLt5l5q6Pd/w+kxrUy1PQXVXYzv5oslI5WtOg/ZUgKsgFXNgWRfrjAMyuOmKYHcTkBXXj29J5ZhrspXmpHIIU8yLhSrUF3ZOcPkuLNp2BcDAh0X00bNCPIsjNGS5JCBXXwuliMwEeBccJiFNpFgrqM2j7GSGtA2HRCje2uCcPJIGrJP8eb3wwKmo4j2HFHUrc3SL2vxJAsyLQyY1JYkkYjB+39u8Tc5PC7N4q7vsF7AIvOWpSvngEtpw2R7mvZ6dK204A6uyYZRuwrS0dY52kHEzQRdAGii6jR4pQk6epkOjJ7Bxc6pLGBuF1QXW+h0Iu2Fz6YYPYZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BdBh7qEPaosmkVuXl4SCo6IOUmSBfPREroHerGR4Fio=; b=hkUyYwgYfijYCSAKlgnzENDX/bkBiLhjI3gBnoaCC3ZhMI3Iz7Lf+nXvAktv1mBeYd4K78txoRLhr2A4NN6tQpa9f0MwCK2+9p6As05mNshuoJTbMJ3NhewonB+R1dIngxguVEaCywa6d6EbCyeRWjjwainy3dGjjFf70muoPZTFALE+aSNTFLxg0H4EbqQ35goQUw/s0CdXa1AU2mFowbpKRE5q0SqmPtTxDisTY9wdHXfO78/ww3hXrMEGgT7VnYz9QOoi+CqDTTjRQuJjP5unZh2zHkWV2cD67JOO7X14/Cvcs6YS8np/B5v4DnU+LBCp2HeJbqGdftNrJwqAMA== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; From: Tushar Dave To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, marcel@redhat.com, devel@edk2.groups.io, alwilliamson@nvidia.com, jgg@nvidia.com, skolothumtho@nvidia.com, ardb@kernel.org, kraxel@redhat.com, tdave@nvidia.com Subject: [PATCH v2 3/5] hw/pci: add fixed BAR fw_cfg blob export Date: Mon, 2 Nov 2026 12:12:39 -0600 Message-Id: <20261102181241.3077981-4-tdave@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261102181241.3077981-1-tdave@nvidia.com> References: <20261102181241.3077981-1-tdave@nvidia.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR04CA0044.namprd04.prod.outlook.com (2603:10b6:610:77::19) To IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR12MB923065:EE_|BL1PR12MB5993:EE_ X-MS-Office365-Filtering-Correlation-Id: 6405cb2e-b1b4-45fd-4bc4-08df390ceede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|23010399003|376014|261021123027099003|260925021311599003|260925021911599003|260925022911599003|5023799004|261026130827099003|11063799006|261021133027099003|56012099006|261021135927099003|261009223027099003|261028144727099003|261026135527099003|261021121427099003|261022115727099003|261026140227099003|261022075727099003|261021130227099003|261026121527099003|261022113327099003|261022105027099003|10067099003|22082099003|18002099003|261102123227099003|6133799003|3023799007|261102130727099003; X-Microsoft-Antispam-Message-Info: Ce3mfS/QTVmkStTA1H75gDvhFvQEATf64/qojBi+QxbLChRKXE8SCUgXiTp74AbNt4kf7pTHgns6IHj29RCK4On3788+oa7w2K5WhmTsqbSa/zUt57rPuZpvQBQ+OJPImRToHaQra9k9SHZ97PCo1k9XGQswhOFvi9B98E6e0DcAfcKiLo0YcqjRVieWGVke5qHb6qGzuws0fuAME+dBvJmu3RUBy+PuHdCDczjuk2NF2rHdZG44iIbUNKGfmDH+FmoKi24EGK1iUWyfB3EVzJpenGJX7HaPPRz93ftLPMy3p7KHrUjAaYe5oi6OHFOJhxe4x191p9/zCywu+eNtU1T5D12McaI5Nqmj1/kbIp8rUrj8rBHFTOc0J3B2n51DGStasYTzm/vt9cez64WIpntu0m1DZUGTw4aBIabwhSk42caE2xL7pv6vkKsDPJEVn9qUNKhKgGRR3y9VqZ7hBOQIUX3EX763f9bQdMBlcnlIJyXJN5OydRD+PoVd90NWUTQqOzmnES0kujhJgYTb72+DSgv9pzXhh8wRZtZUKirxINy75MsQh7dvMIoQ3l3zxyrq9lX7SeXCyiQsaQusakBgbYqnnY22f4c/q10IIQlKdeVPjGGWl0d637nOhT460gvpP4kTeFot/BR8gj046B19jsZcLrjPZtByHz9Q2PI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:IA3PR12MB923065.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(261021123027099003)(260925021311599003)(260925021911599003)(260925022911599003)(5023799004)(261026130827099003)(11063799006)(261021133027099003)(56012099006)(261021135927099003)(261009223027099003)(261028144727099003)(261026135527099003)(261021121427099003)(261022115727099003)(261026140227099003)(261022075727099003)(261021130227099003)(261026121527099003)(261022113327099003)(261022105027099003)(10067099003)(22082099003)(18002099003)(261102123227099003)(6133799003)(3023799007)(261102130727099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MHBmaWg5dWR5cnphQVZOdGtzWndudFowcUU4Z0pOMnI4c3pCVzBIWjFlYWpU?= =?utf-8?B?bFQ3YmhNLzZLU1Z4M2ZIVmRRVjl4OERxS2VxMlhoNWtTc0lMdGl5NDQ0cXJV?= =?utf-8?B?YWZYL25ibnJQMThhWUk3Sk1RR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lA5a2Q2?= =?utf-8?B?ZG1BUnFSTGxCSjk1dnVlN0NIOGJJRW1rT2o3aEZkdEs4NTYwNnBVRm9WazFV?= =?utf-8?B?VjFTSnl5endRRWUyQWRQa2Y1L3R0bEtPSG95YlFMMVhoWmxuMi9IdHlieENo?= =?utf-8?B?R0dqcGZLYWZmUThiQSt6dnJBSmcyZE03STZTdW5TbDZuTE9YOGtIMGQ4KzhF?= =?utf-8?B?TmJwWC9YQ2p3RjlaVzcwa1hUZkxDa2VBWDFGNkhoSHhSaklZQnEyMXFwWlVs?= =?utf-8?B?Q0dMQnJrdGJSZjc2VUJtLzZRQzVFeW5zQ2JWdmMrV3UvSC9oWVNMeWV2Umcz?= =?utf-8?B?T3hWMFVsd3hWRHdQNXh5ZmpHWVdmU2VZVlliT1NHMDdhV0FsaEpnQ3pqbUZV?= =?utf-8?Q?bBbn0PIeGQ05sz5X/2?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6405cb2e-b1b4-45fd-4bc4-08df390ceede X-MS-Exchange-CrossTenant-AuthSource: IA3PR12MB923065.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2026 18:13:02.0684 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 293nHCGNYAxJevbUAjPIWBtkIVB89K/lq2F+4Mek7ufrhUoXMG+EBmB9EFXJGC30PeX6T+RDA5a+gUtnofzmLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5993 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:c10d::1; envelope-from=tdave@nvidia.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, SPF_NONE=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: 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 @Nvidia.com) X-ZM-MESSAGEID: 1793643271319158500 Introduce a fixed BAR fw_cfg blob exporter that serializes PCI device and BAR information into the "etc/fixed-bars" fw_cfg file. The blob contains an entry for every PCI function with memory BARs. Each entry carries the device's vendor and device ID, whether it has a fixed BAR configuration, and its firmware device path. Fixed BAR entries also include the configured BAR address, size, and type information for each BAR. Document the format in docs/specs/pci-fixed-bars.rst. Signed-off-by: Tushar Dave Acked-by: Gerd Hoffmann --- docs/specs/index.rst | 1 + docs/specs/pci-fixed-bars.rst | 75 ++++++++ hw/pci/meson.build | 1 + hw/pci/pci-fixed-bar-blob.c | 308 +++++++++++++++++++++++++++++++++ include/hw/pci/pci-fixed-bar.h | 63 +++++++ 5 files changed, 448 insertions(+) create mode 100644 docs/specs/pci-fixed-bars.rst create mode 100644 hw/pci/pci-fixed-bar-blob.c create mode 100644 include/hw/pci/pci-fixed-bar.h diff --git a/docs/specs/index.rst b/docs/specs/index.rst index 44e108db02..15cdf4698b 100644 --- a/docs/specs/index.rst +++ b/docs/specs/index.rst @@ -11,6 +11,7 @@ guest hardware that is specific to QEMU. pci-ids pci-serial pci-testdev + pci-fixed-bars ppc-xive ppc-spapr-xive ppc-spapr-numa diff --git a/docs/specs/pci-fixed-bars.rst b/docs/specs/pci-fixed-bars.rst new file mode 100644 index 0000000000..708566550e --- /dev/null +++ b/docs/specs/pci-fixed-bars.rst @@ -0,0 +1,75 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +.. + Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved + +PCI fixed BAR fw_cfg +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +A PCI device can be given a fixed guest address for each of its memory BARs +with the ``fixed-bar-N`` device properties, where ``N`` is the BAR number, +for example ``-device e1000,fixed-bar-0=3D0x20000000``. A machine that +supports this validates the addresses and passes them to the firmware in t= he +``etc/fixed-bars`` fw_cfg file, so that the firmware can place each BAR at +the requested address instead of assigning one. + +The file is present only when at least one device has a fixed BAR. All +fields are little-endian and the structures are packed. + +Layout +------ + +The file is a header followed by one device record for every PCI function +that has a memory BAR, fixed or not. A device record is followed by one BAR +record for each of its fixed BARs. A device with any fixed BAR has all of = its +memory BARs fixed, so it has a BAR record for each of them. + +The device records are in the order in which the firmware discovers the +devices. Host bridges come in ascending bus number order, the devices of a +bus in devfn order, and the devices behind a bridge follow the bridge. + +Header +~~~~~~ + +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Offset Size Description +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +0 4 ``version``, currently 1 +4 4 ``num_devices``, the number of device records +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Device record +~~~~~~~~~~~~~ + +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Offset Size Description +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +0 2 ``vendor_id`` +2 2 ``device_id`` +4 1 ``dev_flags``, bit 0 is set if the device has fixed BARs +5 1 ``rp_bus``, the primary bus number of the root port the + device is under, or the bus number of its host bridge + if it is not under a root port +6 1 ``num_bars``, the number of BAR records that follow, + 0 if the device has no fixed BARs +7 1 reserved, 0 +8 128 ``fw_path``, the firmware device path of the device, + NUL-terminated +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +BAR record +~~~~~~~~~~ + +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Offset Size Description +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +0 1 ``bar``, the BAR number +1 3 reserved, 0 +4 4 ``flags``, bit 0 indicates the BAR type (0 for 32-bit, + 1 for 64-bit), and bit 1 indicates whether the BAR is + prefetchable (0 for non-prefetchable, 1 for + prefetchable). All other bits are reserved and must + be zero. +8 8 ``address``, the fixed guest address of the BAR +16 8 ``size``, the size of the BAR +=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/hw/pci/meson.build b/hw/pci/meson.build index 150085c997..b81cc056c0 100644 --- a/hw/pci/meson.build +++ b/hw/pci/meson.build @@ -20,6 +20,7 @@ pci_ss.add(files('pcie.c', 'pcie_aer.c')) pci_ss.add(files('pcie_doe.c')) system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'p= cie_host.c')) system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-va= lidate.c')) +system_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pci-fixed-bar-bl= ob.c')) system_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss) =20 stub_ss.add(files('pci-stub.c')) diff --git a/hw/pci/pci-fixed-bar-blob.c b/hw/pci/pci-fixed-bar-blob.c new file mode 100644 index 0000000000..dc94debfad --- /dev/null +++ b/hw/pci/pci-fixed-bar-blob.c @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved + * Write validated fixed-BAR device info to the etc/fixed-bars fw_cfg blob. + * + * Written by Tushar Dave + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/nvram/fw_cfg.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/pci_host.h" +#include "hw/pci/pcie_port.h" +#include "hw/core/qdev.h" +#include "qemu/error-report.h" +#include "pci-internal.h" +#include "hw/pci/pci-fixed-bar.h" +#include "pci-fixed-bar-validate.h" + +typedef struct { + uint8_t bar; + uint32_t flags; + uint64_t addr; + uint64_t size; +} BarInfo; + +/* One PCI function entry to be written to the blob. */ +typedef struct { + uint8_t rp_bus; /* primary bus of the root port this device is un= der */ + uint16_t vendor_id; + uint16_t device_id; + bool is_fixed; + char fw_path[QEMU_FIXED_BARS_MAX_PATH]; + GArray *bars; /* array of BarInfo */ +} DeviceInfo; + +typedef struct { + GArray *devices; + PCIBus *root_bus; +} CollectCtx; + +static void collect_device(PCIBus *bus, PCIDevice *pdev, void *opaque); + +/* Visit every device on this bus, in devfn order. */ +static void collect_bus(PCIBus *bus, void *opaque) +{ + pci_for_each_device_under_bus(bus, collect_device, opaque); +} + +/* + * Primary bus number of the nearest TYPE_PCIE_ROOT_PORT ancestor of bus + * =E2=80=94 i.e. the bus the root port device itself lives on, not its + * secondary bus. Falls back to the host bridge's own bus number if bus + * isn't under any root port (e.g. a device directly on the host + * bridge's primary bus). + */ +static uint8_t find_root_port_bus(PCIBus *bus, PCIBus *host_bus) +{ + PCIDevice *parent; + + while (bus) { + parent =3D bus->parent_dev; + if (!parent) { + break; + } + if (object_dynamic_cast(OBJECT(parent), TYPE_PCIE_ROOT_PORT)) { + return pci_bus_num(pci_get_bus(parent)); + } + bus =3D pci_get_bus(parent); + } + return pci_bus_num(host_bus); +} + +static void collect_device(PCIBus *bus, PCIDevice *pdev, void *opaque) +{ + CollectCtx *ctx =3D opaque; + bool has_mem_bar =3D false; + bool is_64bit, is_pref; + DeviceInfo dev; + PCIIORegion *r; + PCIBus *sec; + BarInfo bi; + int i; + + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + r =3D &pdev->io_regions[i]; + if (r->size && !(r->type & PCI_BASE_ADDRESS_SPACE_IO)) { + has_mem_bar =3D true; + break; + } + } + + /* + * Every device with a memory BAR gets an entry, fixed or not =E2=80= =94 not + * just ones with fixed-bar-N=3D set. This preserves the exact device + * sequence CheckDevice() needs for positional VID:DID matching (see + * collect_all_host_bridges()); only fixed devices carry BAR records + * (dev.bars stays empty, dev.is_fixed false, otherwise). + */ + if (has_mem_bar) { + g_autofree char *fw_path =3D qdev_get_fw_dev_path(DEVICE(pdev)); + + memset(&dev, 0, sizeof(dev)); + dev.rp_bus =3D find_root_port_bus(bus, ctx->root_bus); + dev.vendor_id =3D pci_get_word(pdev->config + PCI_VENDOR_ID); + dev.device_id =3D pci_get_word(pdev->config + PCI_DEVICE_ID); + dev.is_fixed =3D false; + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + if (pdev->fixed_bar_addr[i] !=3D PCI_BAR_UNMAPPED) { + dev.is_fixed =3D true; + break; + } + } + if (fw_path) { + g_strlcpy(dev.fw_path, fw_path, sizeof(dev.fw_path)); + } + dev.bars =3D g_array_new(false, true, sizeof(BarInfo)); + + if (dev.is_fixed) { + for (i =3D 0; i < PCI_NUM_REGIONS - 1; i++) { + r =3D &pdev->io_regions[i]; + if (!r->size || (r->type & PCI_BASE_ADDRESS_SPACE_IO)) { + continue; + } + is_64bit =3D !!(r->type & PCI_BASE_ADDRESS_MEM_TYPE_64); + is_pref =3D !!(r->type & PCI_BASE_ADDRESS_MEM_PREFETCH); + + memset(&bi, 0, sizeof(bi)); + bi.bar =3D i; + bi.addr =3D (uint64_t)pdev->fixed_bar_addr[i]; + bi.size =3D r->size; + bi.flags =3D (is_64bit ? QEMU_FIXED_BAR_F_MEM64 : 0) | + (is_pref ? QEMU_FIXED_BAR_F_PREF : 0); + g_array_append_val(dev.bars, bi); + } + } + g_array_append_val(ctx->devices, dev); + } + + if (!object_dynamic_cast(OBJECT(pdev), TYPE_PCI_BRIDGE)) { + return; + } + sec =3D pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); + if (sec) { + collect_bus(sec, opaque); + } +} + +static gint cmp_host_bus_num(gconstpointer a, gconstpointer b) +{ + PCIHostState *ha =3D *(PCIHostState **)a; + PCIHostState *hb =3D *(PCIHostState **)b; + return (gint)pci_bus_num(ha->bus) - (gint)pci_bus_num(hb->bus); +} + +/* + * EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL's CheckDevice interface + * (UEFI PI Spec 1.2 Vol 5) only passes VendorId/DeviceId/RevisionId/ + * SubsystemVendorId/SubsystemDeviceId, no BDF =E2=80=94 so in EDK2 we can= 't + * match a blob entry to a specific device directly using BDF. To work + * around that, we prepare the blob entries in the same order PciBusDxe + * discovers devices, so matching by VID:DID inherently works. Each entry + * also carries the firmware device path. The CheckDevice interface cannot + * use it today, but it could if the interface is extended. + */ +static void collect_all_host_bridges(CollectCtx *ctx) +{ + PCIHostState *hb; + GPtrArray *sorted; + guint i; + + sorted =3D g_ptr_array_new(); + QLIST_FOREACH(hb, &pci_host_bridges, next) { + if (hb->bus) { + g_ptr_array_add(sorted, hb); + } + } + g_ptr_array_sort(sorted, cmp_host_bus_num); + + for (i =3D 0; i < sorted->len; i++) { + hb =3D g_ptr_array_index(sorted, i); + ctx->root_bus =3D hb->bus; + collect_bus(hb->bus, ctx); + } + + g_ptr_array_free(sorted, true); +} + +static uint8_t *create_blob(CollectCtx *ctx, size_t *blob_size) +{ + QemuFixedBarsDevice *dout; + QemuFixedBarsBar *bout; + QemuFixedBarsHdr *hdr; + DeviceInfo *dev; + uint8_t *blob; + uint8_t *ptr; + BarInfo *bi; + size_t sz; + guint d, b; + + sz =3D sizeof(QemuFixedBarsHdr); + for (d =3D 0; d < ctx->devices->len; d++) { + dev =3D &g_array_index(ctx->devices, DeviceInfo, d); + sz +=3D sizeof(QemuFixedBarsDevice); + sz +=3D dev->bars->len * sizeof(QemuFixedBarsBar); + } + + blob =3D g_malloc0(sz); + hdr =3D (QemuFixedBarsHdr *)blob; + hdr->version =3D cpu_to_le32(QEMU_FIXED_BARS_VERSION); + hdr->num_devices =3D cpu_to_le32(ctx->devices->len); + + ptr =3D blob + sizeof(*hdr); + for (d =3D 0; d < ctx->devices->len; d++) { + dev =3D &g_array_index(ctx->devices, DeviceInfo, d); + dout =3D (QemuFixedBarsDevice *)ptr; + + dout->vendor_id =3D cpu_to_le16(dev->vendor_id); + dout->device_id =3D cpu_to_le16(dev->device_id); + dout->dev_flags =3D dev->is_fixed ? QEMU_FIXED_BARS_DEV_F_FIXED : = 0; + dout->rp_bus =3D dev->rp_bus; + dout->num_bars =3D dev->bars->len; + dout->reserved =3D 0; + memcpy(dout->fw_path, dev->fw_path, sizeof(dout->fw_path)); + ptr +=3D sizeof(QemuFixedBarsDevice); + + for (b =3D 0; b < dev->bars->len; b++) { + bi =3D &g_array_index(dev->bars, BarInfo, b); + bout =3D (QemuFixedBarsBar *)ptr; + + bout->bar =3D bi->bar; + bout->flags =3D cpu_to_le32(bi->flags); + bout->address =3D cpu_to_le64(bi->addr); + bout->size =3D cpu_to_le64(bi->size); + ptr +=3D sizeof(QemuFixedBarsBar); + } + } + + *blob_size =3D sz; + return blob; +} + +/* + * fixed_bars_write_blob - validate fixed BAR addresses and write fw_cfg b= lob. + * + * @fw_cfg: fw_cfg state to write the etc/fixed-bars blob into. + * @mmio32_base: base of the machine's 32-bit PCIe MMIO aperture. + * @mmio32_size: size of the machine's 32-bit PCIe MMIO aperture. + * @mmio64_base: base of the machine's 64-bit PCIe MMIO aperture. + * @mmio64_size: size of the machine's 64-bit PCIe MMIO aperture, or 0 + * if the machine has none. + * @errp: set if the apertures or any BAR address fail validation. + * + * Returns true if any fixed BAR device was found and the blob was + * written, false if there was nothing to do or on error. + */ +bool fixed_bars_write_blob(FWCfgState *fw_cfg, + uint64_t mmio32_base, + uint64_t mmio32_size, + uint64_t mmio64_base, + uint64_t mmio64_size, + Error **errp) +{ + FixedBarsInfo info; + CollectCtx ctx; + uint8_t *blob; + size_t blob_size; + guint d; + + if (!mmio32_size) { + error_setg(errp, "fixed-bar: zero-size 32-bit PCIe MMIO aperture"); + return false; + } + if (mmio32_size - 1 > UINT64_MAX - mmio32_base || + (mmio64_size && mmio64_size - 1 > UINT64_MAX - mmio64_base)) { + error_setg(errp, "fixed-bar: PCIe MMIO aperture base+size overflow= s " + "(32-bit base=3D0x%"PRIx64" size=3D0x%"PRIx64", " + "64-bit base=3D0x%"PRIx64" size=3D0x%"PRIx64")", + mmio32_base, mmio32_size, mmio64_base, mmio64_size); + return false; + } + + info.mmio32_base =3D mmio32_base; + info.mmio32_limit =3D mmio32_base + mmio32_size - 1; + /* An absent 64-bit aperture is an empty window, no BAR fits in it. */ + info.mmio64_base =3D mmio64_size ? mmio64_base : 1; + info.mmio64_limit =3D mmio64_size ? mmio64_base + mmio64_size - 1 : 0; + + if (!fixed_bars_validate(&info, errp) || !info.any_fixed) { + return false; + } + + ctx.devices =3D g_array_new(false, true, sizeof(DeviceInfo)); + ctx.root_bus =3D NULL; + collect_all_host_bridges(&ctx); + + blob =3D create_blob(&ctx, &blob_size); + fw_cfg_add_file(fw_cfg, FW_CFG_FIXED_BARS, blob, blob_size); + + for (d =3D 0; d < ctx.devices->len; d++) { + g_array_free(g_array_index(ctx.devices, DeviceInfo, d).bars, true); + } + g_array_free(ctx.devices, true); + + return true; +} diff --git a/include/hw/pci/pci-fixed-bar.h b/include/hw/pci/pci-fixed-bar.h new file mode 100644 index 0000000000..2c5af536dc --- /dev/null +++ b/include/hw/pci/pci-fixed-bar.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved + * Fixed-BAR =E2=80=94 QEMU side declarations. + * + * Written by Tushar Dave + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef HW_PCI_FIXED_BAR_H +#define HW_PCI_FIXED_BAR_H + +#include "hw/nvram/fw_cfg.h" + +#define FW_CFG_FIXED_BARS "etc/fixed-bars" +#define QEMU_FIXED_BARS_VERSION 1 +#define QEMU_FIXED_BARS_MAX_PATH 128 + +/* + * On-wire layout (little-endian, packed): + * + * QemuFixedBarsHdr + * + * For each device (num_devices total): + * QemuFixedBarsDevice -- device header + * QemuFixedBarsBar[num_bars] -- one record per BAR (FIXED only) + */ + +typedef struct { + uint32_t version; /* QEMU_FIXED_BARS_VERSION */ + uint32_t num_devices; +} QEMU_PACKED QemuFixedBarsHdr; /* 8 bytes */ + +typedef struct { + uint16_t vendor_id; + uint16_t device_id; + uint8_t dev_flags; /* QEMU_FIXED_BARS_DEV_F_* */ + uint8_t rp_bus; /* primary bus of the root port this device is un= der */ + uint8_t num_bars; + uint8_t reserved; + /* qdev_get_fw_dev_path(), NUL-terminated */ + char fw_path[QEMU_FIXED_BARS_MAX_PATH]; +} QEMU_PACKED QemuFixedBarsDevice; /* 8 + QEMU_FIXED_BARS_MAX_PATH bytes = */ + +typedef struct { + uint8_t bar; + uint8_t reserved[3]; + uint32_t flags; /* QEMU_FIXED_BAR_F_* */ + uint64_t address; + uint64_t size; +} QEMU_PACKED QemuFixedBarsBar; /* 24 bytes */ + +#define QEMU_FIXED_BAR_F_MEM64 (1u << 0) +#define QEMU_FIXED_BAR_F_PREF (1u << 1) +#define QEMU_FIXED_BARS_DEV_F_FIXED (1u << 0) + +bool fixed_bars_write_blob(FWCfgState *fw_cfg, + uint64_t mmio32_base, + uint64_t mmio32_size, + uint64_t mmio64_base, + uint64_t mmio64_size, + Error **errp); + +#endif /* HW_PCI_FIXED_BAR_H */ --=20 2.34.1 From nobody Mon Nov 23 04:26:16 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1793643232; cv=pass; d=zohomail.com; s=zohoarc; b=iHK0a6xqs9akNo2ae7rZ43+7yyixYsyL85zcRewyYl6m1BYPswYapqezffD/obICehvsCYVLobPhk6FFadh4+qiR612YjvQXmHdX88rZ27F5vQcPlP18royPHUry9PgxCTLRWKStKCVJyfJzBmnHemvJR8+UtiaoAgU8t9Kfaxk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793643232; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aeiQmhkMoH7ycEGOuCk2VLtswxGQw/HGPDstG3BE+Io=; b=BIYx23lcBKvXoUG9gFNzSTFxSCDJfyeY+cLV9llqu29PbMUXmkvCNinZs0lMgzxofNIfEDQ+dehFV/tJq4Gvskbst5Gyn5gbNuTH47Os1/jWOmfDNHvuObY4KdIUcFITRc5+6YrFRboha3tZjUVlAh/DPmGYsb1oaShshSApRDk= ARC-Authentication-Results: i=2; 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=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793643232301712.9113865744347; Mon, 2 Nov 2026 10:13:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNwX0-0004sj-LO; Mon, 02 Nov 2026 13:13:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwWz-0004sA-Fl; Mon, 02 Nov 2026 13:13:17 -0500 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwWx-0003Yr-LH; Mon, 02 Nov 2026 13:13:17 -0500 Received: from IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) by BL1PR12MB5993.namprd12.prod.outlook.com (2603:10b6:208:399::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.569.12; Mon, 2 Nov 2026 18:13:05 +0000 Received: from IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1]) by IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1%5]) with mapi id 15.21.0569.011; Mon, 2 Nov 2026 18:13:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b+Ie+nYA61OndrrSlzRyqst7FW/PSdqxLBBcmfnIm0x0xIjsVPYmAPecvrJtkt39cMm70ZsgyE25S/CNQj2ubbMjF7MkT/Kf1SwtnWCgc47lZzWpPyOlRIy2mTpjEZuf6XbACmCXN62RDocfP7OZE3ocBBr5njR+hrgxojd7sQHvIM1Wb0zy+CTuahmlEZcESImhwV2jEW5+bd7p8W489XmFtfEU11JiIzud0llSaV5O8t5mfgbzckB4YAqDQ8veHMpwCVOhIod3d6DdyQG3OHExJ0tZEp7smslaEI7HgdrhSHKDPb6QKXIypaOyVf6bvdhCSynoTsicyCZMPf20sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aeiQmhkMoH7ycEGOuCk2VLtswxGQw/HGPDstG3BE+Io=; b=dikNeV3BcfBd+3c63jhEh0wuP1M6j4yaFF89Yg+4hrrVFUYB87fJPXcbKXVTfvVn44KbYfKMuyxnO6xyh/oFQQQ+6jHvi54u7aYhw/dWsADGvJQS3vfw/InFevyynGd6yROHtafntS0jeoOFNKhwBcO1TAIrCvw7hzxZ10x33sXpM05RG9yriCxy0scbcAW9Mt58FB9xqONPTX5umd670ZJJdKW6tzo17/KvOOAJeP+jRYi1jWukM22lml+Ydm6YeqTfFfpbRuc6f0Zb22IqafV0IUG+z1Z2o+70s5futW5JVq901vR6I32Y1vpH2IwXgz4MnJsYgFdxrG+y570mBg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aeiQmhkMoH7ycEGOuCk2VLtswxGQw/HGPDstG3BE+Io=; b=A7159ig07Oj8ydrjNPvLuzq5nn87HxlVWMHtmi+JcWuTNo39+luj/wlEAEqoQklUnK3/ORqa29Dch7CIIVPMm9K1BX1+CgczbOMLjyfwfcnoRMsaAl4JO2ZluhhWB8Zsu9WzDvWo84Ty426ZtsURWbedXiALNn6XjPIvHJrtcLiKCG710l1Fww779oVJOMUflQkcRYPd3NvnfdaGrLzjVO8nL8mMkvFzHkVvacydKkzaOqpGM3+bm1WYntLz8TdLNv0N7VqMHLC0/c2SEa8jdbFyi3kZc+WQZ4bbqMfY61YnYrU4C6rjlwnqQGZ5UIoHEfz8ovjKexJITgLr8GPcrA== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; From: Tushar Dave To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, marcel@redhat.com, devel@edk2.groups.io, alwilliamson@nvidia.com, jgg@nvidia.com, skolothumtho@nvidia.com, ardb@kernel.org, kraxel@redhat.com, tdave@nvidia.com Subject: [PATCH v2 4/5] hw/arm/virt: export fixed BAR metadata via fw_cfg Date: Mon, 2 Nov 2026 12:12:40 -0600 Message-Id: <20261102181241.3077981-5-tdave@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261102181241.3077981-1-tdave@nvidia.com> References: <20261102181241.3077981-1-tdave@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH0PR04CA0031.namprd04.prod.outlook.com (2603:10b6:610:77::6) To IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR12MB923065:EE_|BL1PR12MB5993:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b7a9ece-4975-4c91-5557-08df390cefa1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|23010399003|376014|11063799006|56012099006|261009223027099003|261021121427099003|261022075727099003|261026121527099003|10067099003|22082099003|18002099003|261102123227099003|6133799003|261102130727099003; X-Microsoft-Antispam-Message-Info: WV8iBx5IkuEB5Ml1dJK96U1IOHb2c6qN78TnBnBFb+ExLVRE3eLh5jIfeQbsBeHY4CdZO6qh8vhbq58ftxAoTODKqPeypUwDt242aOV5iS5tYCz5BSyzYKZ9+4QxuN2Z63eU4ll3LbByYpvlbJjW4wg5HNBQ92NegMaI5krJbtsYCOoLKOGa+C/VFdZ3o4LY2KBPlvW2DvomMgkdQkMgrKAky0x5WLVEGIjh048qxhrUG+AQZNwzsyv9wwXE66gPUaX2YAfSrljdh5uAl8Y8Isd18N+mQ59n6gMwKXlMscEVBuc9h9wgIz3TnXbYASvI0iMaBq13SAO14ZgFdaPqVRujvl6T1NtRzk9uzIQKyx44KAC7EiWOICmSLrjKdjxyTTdwr1m8oZmcdBvvzlVPvOHcpJRgvpCG+rtm8XHOPR6xeR6ktPeN6mhGq3JDdn8YiK7Vv1ZcM2rxBpoMBIMi9fzbaub3/pxsy1mcrEIq8DHDWW3RlHSq24bEY1zr9KUWUvHN+bgnevqXVMZHFtOMqF/ICRW2/WEN4H0Ebaeb6yQpUtsFDWgMvwsyX0t7pRewOOvH5EJ7iytGyDUNLguHoc3dwq0hzm4dAuNBQzvPCUHJDLMToQxUy/cYMKaf6pjTRBuEsJU6Jg4ECC+5jTJSDHtc7Xg5i0Do0UHAulvP6rU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:IA3PR12MB923065.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(11063799006)(56012099006)(261009223027099003)(261021121427099003)(261022075727099003)(261026121527099003)(10067099003)(22082099003)(18002099003)(261102123227099003)(6133799003)(261102130727099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?sPPZLGNMwaCOUMYhXXmRGxeEpYU7dJHoPc6DebMbeALPoSe41EVwiSnctAmG?= =?us-ascii?Q?QWp/1IkU4olwwUtHeS4Rvy/BpeskzDTNUDwgW2icTJ6OazvZmVz1m4PzffXK?= =?us-ascii?Q?a4oT7AqBzpjF8/LNuP+e3g1XOFOukRRj58yL/UqF73EgJGUJolU7fC+c5cxR?= =?us-ascii?Q?lxZpuJp7PYsiiMKLHBk6ssVjLyXGXnrQmNs8a9qtJkEgzOBKkISooew7RDxz?= =?us-ascii?Q?nJ59pZoNDz2oT2j9Y9DCSZdki5a6VA3U5NM0ZGwTJ1zkNo8NHR/2OjgFDTWj?= =?us-ascii?Q?gNboWfoMqvClePUp8ANPNg4Yd/JenXtK5ZD1OGYSRxXXIztS3N/jNPo3VmMI?= =?us-ascii?Q?AT/Pj+m4PPGvPfkWrYrysQ0Y8Ja616m5mgLcCN9ft/CExG6OccZ484KcnIrC?= =?us-ascii?Q?sWxX4Il6Sgrce8nzD6e/Gug1rf47F7uYA7SzNZf4qX/1ChAJL2b3B0v83ovX?= =?us-ascii?Q?jINj3Dd/Bu3ZOcTsbrF7Cd8DXGMFgbsidIcI1r7wzBVbMNowYxaiuJIxNLRD?= =?us-ascii?Q?ov1vg6ff6vYvbiccqlE3aYRV9JjxcAAGUafa4jQSQ4DCecUTrH+AdQpYyAJG?= =?us-ascii?Q?HTZKohaZ69plIUgtnzIpvZLhcEGt+6xRmsQXR3TiSWffPVQa1+9XmQWcL9oo?= =?us-ascii?Q?agQYXv3gBAGIC7QEx5uVxgxV6ayEnWjYpF3oTa/qp2Rp3aofDeSXuh2yduCN?= =?us-ascii?Q?eyCNkrHO5zQLuGZEm6oTZ2zjzmyzkie8GjbpO6wPXvDTgDkDaQZMxpur/EmC?=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ZY0jDKU65aeFWkv4Jw?= =?us-ascii?Q?KOHBi2c3Zq6W3rs/+1qN10Knja7OQGyWuR01Eszk0rE7aoXJ?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b7a9ece-4975-4c91-5557-08df390cefa1 X-MS-Exchange-CrossTenant-AuthSource: IA3PR12MB923065.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2026 18:13:03.3198 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0YQELaaWrj2n+8mg2ABgPcSzzUzCUOZsTyyXSALNEnBKgeJ+464xFBn1yfJN4+8r7WmGaJwu6AaIGSGGY9ESPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5993 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:c10d::1; envelope-from=tdave@nvidia.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, SPF_NONE=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: 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 @Nvidia.com) X-ZM-MESSAGEID: 1793643234755158500 Content-Type: text/plain; charset="utf-8" Export fixed BAR metadata through the "etc/fixed-bars" fw_cfg file and set pci_fixed_bar_supported to allow the fixed-bar-N properties on the virt machine. Fixed BAR placement requires the guest to preserve the PCI resource configuration established by firmware, preventing the fixed BAR addresses from being reassigned during guest boot. ACPI provides this through the PCI boot configuration preservation mechanism (_DSM function 5). Reject fixed BAR configuration if firmware is not loaded or ACPI is disabled, since PCI boot configuration preservation cannot otherwise be guaranteed. Signed-off-by: Tushar Dave Acked-by: Gerd Hoffmann --- hw/arm/virt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 3ab3ad8c3b..4bacb57770 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -94,6 +94,7 @@ #include "hw/cxl/cxl_host.h" #include "qemu/guest-random.h" #include "hw/watchdog/sbsa_gwdt.h" +#include "hw/pci/pci-fixed-bar.h" =20 static GlobalProperty arm_virt_compat_defaults[] =3D { { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "48" }, @@ -2435,6 +2436,23 @@ void virt_machine_done(Notifier *notifier, void *dat= a) vms->memmap[VIRT_PLATFORM_BUS].size, vms->irqmap[VIRT_PLATFORM_BUS]); } + if (fixed_bars_write_blob(vms->fw_cfg, + vms->memmap[VIRT_PCIE_MMIO].base, + vms->memmap[VIRT_PCIE_MMIO].size, + vms->memmap[VIRT_HIGH_PCIE_MMIO].base, + vms->highmem_mmio ? + vms->memmap[VIRT_HIGH_PCIE_MMIO].size : 0, + &error_fatal)) { + if (!(vms->bootinfo.firmware_loaded && virt_is_acpi_enabled(vms)))= { + error_report("fixed-bar: fixed BAR placement requires firmware= " + "and ACPI to preserve the PCI boot configuration,= " + "otherwise these BAR assignments could be " + "reassigned later with no protection"); + exit(1); + } + vms->pci_preserve_config =3D true; + } + if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms, cpu) = < 0) { exit(1); } @@ -4192,6 +4210,7 @@ static void virt_machine_class_init(ObjectClass *oc, = const void *data) hc->unplug_request =3D virt_machine_device_unplug_request_cb; hc->unplug =3D virt_machine_device_unplug_cb; mc->nvdimm_supported =3D true; + mc->pci_fixed_bar_supported =3D true; mc->smp_props.clusters_supported =3D true; =20 /* Supported caches */ --=20 2.34.1 From nobody Mon Nov 23 04:26:16 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; arc=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass(p=reject dis=none) header.from=nvidia.com ARC-Seal: i=2; a=rsa-sha256; t=1793643268; cv=pass; d=zohomail.com; s=zohoarc; b=ftMlZ7NqwKi2xE0aGDlcNwUTSc5nVB4AndVK8LYOlFvibbZKrzzrxeeIemEyN/iuWaCmZFq+B+PB8VQEMz9hmfjTvGNPqgfwsblJxlTbjAqwiWqn8j6ktxwyocVSPVayVNKqIw0dVdKSLMAW9clrius6JgdhvhWA/k4EVFdQl7c= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793643268; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HU7Thv1/lEOXmAbC7QqHSlICafqpjGDvpVz29Sva7f8=; b=L197bzqblox7eFTuP8vwgio/E6qgnbZD8twXgVbX3Ofte4sVG6/iITAkcre/U9PPxV4UM/K0vLs81XwNtQAlUJQ5AIrDlYkIuSXX2oj6trc0jNBg68vMPi9oFTgMGBrMQbHjZP+nERqTduFM9SUsDnwM1t7v9Y6yYsqgMP0sCmk= ARC-Authentication-Results: i=2; 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=pass (i=1 dmarc=pass fromdomain=nvidia.com); dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793643268014951.9460480543077; Mon, 2 Nov 2026 10:14:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNwXN-0004wN-0m; Mon, 02 Nov 2026 13:13:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwX6-0004u8-FD; Mon, 02 Nov 2026 13:13:25 -0500 Received: from mail-southcentralusazlp170120001.outbound.protection.outlook.com ([2a01:111:f403:c10d::1] helo=SN4PR2101CU001.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNwX4-0003Yr-3P; Mon, 02 Nov 2026 13:13:23 -0500 Received: from IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) by BL1PR12MB5993.namprd12.prod.outlook.com (2603:10b6:208:399::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.569.12; Mon, 2 Nov 2026 18:13:05 +0000 Received: from IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1]) by IA3PR12MB923065.namprd12.prod.outlook.com ([fe80::1c83:bf47:4202:50b1%5]) with mapi id 15.21.0569.011; Mon, 2 Nov 2026 18:13:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j8Aa5yzjs/7hZMmV5QAHZW0byDH+7dxPhJFtKyD2Q3ZTB9hBe1J5YlzYRrAjfd6ddP0yIa7P/OfwCWSk21YAeIBG8vG0G2j/m2QLUO0cztWCV0q/9RJpZpd7mHssXLgfrkaz5y4suP9jT26W6Ba+cX/BTZwDRkbPStZmHX2ZOzD9xxqajexhIu9bUqKfTW6dUK7XoWjHhErCkzDJmaE1OSAf8+Sj0BAXJ8d3yxBynIuJGuoejbiqXCQfzxRLoWSGLyRcZvB1TRobjd8W9YwlX2poa2xeK8U8UbfOIO7y75QfJJPVf3W66HaHenjSucjT8PaACsuZYqwTQeQLGYkdyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HU7Thv1/lEOXmAbC7QqHSlICafqpjGDvpVz29Sva7f8=; b=GjLvh4/oWxrXgj4wN8Eb3OJxPDjPHmkw44jNDLdeFccLUwfZuSlIOJZE//6qBkq9K2Vf/m1FeC2stl0TDsBHQpxdxzxIA0ni5IuuVKhFJjf2SEJq1CUM+39FeJGeBjno1gGM2XBEktKqayC+7RpMFr7AvtthPpEqT+5mEmAi1mlKYr1x8go6CCv4lPqVm4y4iNGunaL/qxB5TJoh2ZjF49INAxkAIcYzSJEjItOZ3pSrXv7hgKsrD+JLso+22rmOr7BLfKvH1KF7EEZ80DIVC5onFh1JxqPnYRi9FYnnS0CtYz/OtgpFVJ68rLOrH5e6MnygVzKw5LLdaMr2yqmZlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HU7Thv1/lEOXmAbC7QqHSlICafqpjGDvpVz29Sva7f8=; b=gdHB2HQIB4eHvcoexDCC1nFVnvnw/a7U1h14I6HB+AoO3brC8VcS7nO4LvyJA5ylMcWSoAT/GbyZS+IYe6+875rKf0Df29/jgFi6sY24iLoXlFw0k0v4u6l4K0lv3ZqPCw7hy63MvEJrTxvqP8o9z37o6a5OtA9hJSycOA+U7zpw+47J6wLrY98XDl15SXX5zqN4qVanhfzAIKGxxfNsCaNiKqpVNF+kTlWfOk3ngOh1mUVm7rl8nb2lHc+miKWKPQl3GvfpW/Owg2qNhQYYcj8GSKI9I7qH0bZnUSxwrk3mSCqHzIwQLyjDlvCW39XfqFHvBgIwB+RWIRNu7BhpnA== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; From: Tushar Dave To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, mst@redhat.com, marcel@redhat.com, devel@edk2.groups.io, alwilliamson@nvidia.com, jgg@nvidia.com, skolothumtho@nvidia.com, ardb@kernel.org, kraxel@redhat.com, tdave@nvidia.com Subject: [PATCH v2 5/5] hw/arm/virt: add highmem-mmio-base property Date: Mon, 2 Nov 2026 12:12:41 -0600 Message-Id: <20261102181241.3077981-6-tdave@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261102181241.3077981-1-tdave@nvidia.com> References: <20261102181241.3077981-1-tdave@nvidia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CH5PR04CA0006.namprd04.prod.outlook.com (2603:10b6:610:1f4::11) To IA3PR12MB923065.namprd12.prod.outlook.com (2603:10b6:208:627::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA3PR12MB923065:EE_|BL1PR12MB5993:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dd80238-8f12-4a03-2ea4-08df390cf07b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|366016|23010399003|376014|261021123027099003|11063799006|56012099006|261009223027099003|261021121427099003|261026121527099003|10067099003|22082099003|18002099003|261102123227099003|3023799007; X-Microsoft-Antispam-Message-Info: S3EyFKnzQwTK32otn4x2Cyrtrv50Kb+fVwhKpvlF9MtBMRm0Xk9fAO4DG5k6CXN1Il4b/y/wIq3CeCSrx4Utj73f5ct7T2o2OaZtYDZgQQZSFw8Dp0fnv/8xFlUl4KSpjRQlauvqb2K9OyCynv1IWU8qyKzyboEYG/mZjnRyDMvLDTL3d0iiSfP3y+TDi9fynqT0HkPvfVXuyHN5iushOO52jQOwzEE4vVYsNeq8lo8e+QgpQJlrYxA32ocTqKhDdiR9+SknH41exoordcvAU8Zf/6rn+LfBfhzTPgAtQD8e6wpT1CFdndypr7cVJJFeVS0pwsfSBm1+04rDBncv6Pe3cIiXnsj9EqgUrHCK0MGiOvQPs5takRNXPDFrUPOdFgIAzF83O7+hPWhX/yBG/MbfxuGVAJzqXsmKLIJJJyeaDI6C3F2mm/BUYM9rg/Rwl0ji033qiOw3ciaaCZN5EPyG3R/ymr2FiYvsLG9n4B3e9r0Nw/jxlQ3i2jTg2TtlIGjyEGQTiME4EDH4MV1m0xrjBqnkqR1FRNulWPPwwcUIUjP67jPOlc0j6aOTROefb6md0ZessmdT5+8RJN0sfc8MVJjGTjmIehFCV/tlUypcvRugPWMtnFhv/v+ygadKEHiD4I9laXoj92SO+KEAM2QKsdoGNj5TzDLA6HoEDz0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:IA3PR12MB923065.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(261021123027099003)(11063799006)(56012099006)(261009223027099003)(261021121427099003)(261026121527099003)(10067099003)(22082099003)(18002099003)(261102123227099003)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?v/OsAzjrCWBO5lwxhLN+fag9+32fYjM1YI7peq0DFW48h22q4gxYRCd3LLoI?= =?us-ascii?Q?rrS6KLFAjs5BPfMy+XvEPrq4mrD3ywsXtA4FTuVnDuNEsxpCdeOSCqoBB3Zx?= =?us-ascii?Q?/dwlNklcIf/pQnMTKOUzxcbUkVtc8t7ZK6Hnt6xOWphmWo+1OTulExBWeliW?= =?us-ascii?Q?QEkLvJFQ12RCLbS1UBcZZi0YHchnvrkm4iOHbvDhha0RwmrQuLR5c5t/gcny?= =?us-ascii?Q?NwgWUeJaKlYaAn/jQrsWqer/tr41a/yw08iGfJfFz2YJq5HtDiUy5hWQGcXz?= =?us-ascii?Q?nQiOiWn17/UTjkldp+sKzNSvap56e7cTCtAmI0fg4SxijNbUN+4qJu+oBIy2?= =?us-ascii?Q?vWsczOe7+sbJKDhq3TgWmsltyzKXUoDCbqWsJmnxgHLe1vMwIHmJeAo0ZPvh?= =?us-ascii?Q?EqBs0X3K7fdCj1lfrwtxRgdgS7KjxaxWL+nIefvaakhZivp1lxDHDdVaHuSg?= =?us-ascii?Q?7X6KdjwuSHJPzadcgvDAoIkn95JWIGB7hnwiMUpX2DasNULiGnaZnlNTcKRb?= =?us-ascii?Q?+7lhGLD15/h6oSdfygFvQ5E46V7AVF/wmNu1+BlNOiULpj+vesYlb2jJc9gR?= =?us-ascii?Q?gxvNEzEIfFdWyBNzNgU/24TV+tOBM4WPzWeF6ilQhKb2u6uPTnMXzPNsnqaW?= =?us-ascii?Q?m4JkxxNrSWEN4l99BDvhiyvMxc1iLhKlvRX0vZEoPYUGy69dFV2Horuamws2?= =?us-ascii?Q?XuQzs6WEfUiJsrtSAGW1tv4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ascii?Q?T6aMYXCy/uiQXsxFJfoLYFf1/LxseMgoaHpHZzcx4tsJxscZHolmAHzo3gLs?= =?us-ascii?Q?6sfL/TFz4ei1InFUx3FJQfwmhiTOUxvTPAAu0DP4qWgHjA3I?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dd80238-8f12-4a03-2ea4-08df390cf07b X-MS-Exchange-CrossTenant-AuthSource: IA3PR12MB923065.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2026 18:13:04.7503 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +wKOwHmFnbSS/g+sgfPEGebwvpr2lda93zylrzLwICbG9DFQNszKM3N8z4qkYwGHIRPD5FWQB70Rss4/Kw1cnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5993 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:c10d::1; envelope-from=tdave@nvidia.com; helo=SN4PR2101CU001.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, SPF_NONE=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: 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 @Nvidia.com) X-ZM-MESSAGEID: 1793643271021154101 Content-Type: text/plain; charset="utf-8" Add a highmem-mmio-base property to override the base of the virt machine's high PCIe MMIO window, alongside the existing highmem-mmio-size: -machine virt,highmem-mmio-base=3D,highmem-mmio-size=3D Some PCI devices require MMIO resources to be placed within a specific address range that cannot be satisfied by the default placement. The configured base is validated to be non-zero, aligned to highmem-mmio-size, non-overlapping with the existing high memory layout, and within the configured physical address space. Document the property in docs/system/arm/virt.rst. Signed-off-by: Tushar Dave Acked-by: Gerd Hoffmann --- docs/system/arm/virt.rst | 4 +++ hw/arm/virt.c | 63 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst index 5f6dd17978..7ae51bee13 100644 --- a/docs/system/arm/virt.rst +++ b/docs/system/arm/virt.rst @@ -152,6 +152,10 @@ highmem-mmio-size Set the high memory region size for PCI MMIO. Must be a power of 2 and greater than or equal to the default size (512G). =20 +highmem-mmio-base + Set the high memory region base for PCI MMIO. Must be non-zero and + aligned to ``highmem-mmio-size``. + gic-version Specify the version of the Generic Interrupt Controller (GIC) to provide. Valid values are: diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 4bacb57770..c04aadb92f 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2507,14 +2507,40 @@ static void virt_set_high_memmap(VirtMachineState *= vms, hwaddr base, int pa_bits) { hwaddr region_base, region_size; + hwaddr pa_limit =3D BIT_ULL(pa_bits); bool *region_enabled, fits; int i; =20 for (i =3D VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { region_enabled =3D virt_get_high_memmap_enabled(vms, i); - region_base =3D ROUND_UP(base, extended_memmap[i].size); region_size =3D extended_memmap[i].size; =20 + if (i =3D=3D VIRT_HIGH_PCIE_MMIO && extended_memmap[i].base) { + region_base =3D extended_memmap[i].base; + + if (region_base < base) { + error_report("highmem-mmio-base 0x%"PRIx64" overlaps prior= " + "high memory layout (must be >=3D 0x%"PRIx64"= )", + region_base, base); + exit(1); + } + if (region_base % region_size !=3D 0) { + error_report("highmem-mmio-base 0x%"PRIx64" must be " + "aligned to highmem-mmio-size 0x%"PRIx64, + region_base, region_size); + exit(1); + } + if (region_base >=3D pa_limit || + region_size > pa_limit - region_base) { + error_report("highmem-mmio-base 0x%"PRIx64" + " + "highmem-mmio-size 0x%"PRIx64" exceeds %d-bit= " + "PA space", region_base, region_size, pa_bits= ); + exit(1); + } + } else { + region_base =3D ROUND_UP(base, region_size); + } + vms->memmap[i].base =3D region_base; vms->memmap[i].size =3D region_size; =20 @@ -3415,6 +3441,33 @@ static void virt_set_highmem_mmio_size(Object *obj, = Visitor *v, extended_memmap[VIRT_HIGH_PCIE_MMIO].size =3D size; } =20 +static void virt_get_highmem_mmio_base(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + uint64_t base =3D extended_memmap[VIRT_HIGH_PCIE_MMIO].base; + + visit_type_size(v, name, &base, errp); +} + +static void virt_set_highmem_mmio_base(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + uint64_t base; + + if (!visit_type_size(v, name, &base, errp)) { + return; + } + + if (base =3D=3D 0) { + error_setg(errp, "highmem-mmio-base cannot be 0"); + return; + } + + extended_memmap[VIRT_HIGH_PCIE_MMIO].base =3D base; +} + static char *virt_get_msi(Object *obj, Error **errp) { VirtMachineState *vms =3D VIRT_MACHINE(obj); @@ -4286,6 +4339,14 @@ static void virt_machine_class_init(ObjectClass *oc,= const void *data) "Set the high memory region size= " "for PCI MMIO"); =20 + object_class_property_add(oc, "highmem-mmio-base", "size", + virt_get_highmem_mmio_base, + virt_set_highmem_mmio_base, + NULL, NULL); + object_class_property_set_description(oc, "highmem-mmio-base", + "Set the high memory region base= " + "for PCI MMIO"); + object_class_property_add(oc, "virtio-mmio-transports", "uint8", virt_get_virtio_transports, virt_set_virtio_transports, --=20 2.34.1