From nobody Sun Apr 5 16:32:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1774321572; cv=pass; d=zohomail.com; s=zohoarc; b=PN+umCAVCK16FUmjB1iakBwNrIFb9XMF/nltzhif+Dnfb6ez9ae73FWuhDffBsoDBzziw7bAF8MCgUHKIwAMum8XNqzIElCOy55AUP9bhrOBAL7ewOcY+18BbNJYErzQrV7BoBDGol4AIHnPQRByQnCg+qM39XKddHBlgsNnQQY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774321572; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QSf/Y6hBGzyirIB8wL+Tv2JZc0KdiMNKBUOutJwXS6A=; b=D2/E8G9WnBhxV4umydmp5aRsPgb5x/PQwF7GDvb54ael9wPbRS0FblK4l+nilowDxP70k3Xo+Ua8zWbfqR//c2fQTMOicUFyYbkWN62iHl65OhuN2B0D1/PbetSyYYaE3vXa9HVDw+Sd+LxXDXfM+4OdE3dqxugxKFXRJ2/NuVw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774321572964336.0229054129542; Mon, 23 Mar 2026 20:06:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1260003.1553349 (Exim 4.92) (envelope-from ) id 1w4s5a-0005xP-WA; Tue, 24 Mar 2026 03:05:54 +0000 Received: by outflank-mailman (output) from mailman id 1260003.1553349; Tue, 24 Mar 2026 03:05:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4s5a-0005xI-TS; Tue, 24 Mar 2026 03:05:54 +0000 Received: by outflank-mailman (input) for mailman id 1260003; Tue, 24 Mar 2026 03:05:53 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4s5Y-0005rx-Tj for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 03:05:53 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w4s5W-0073ow-O2 for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 04:05:52 +0100 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c1ff6b-bab6-0a2a0a5309dd-0a2a4504edec-36 for ; Tue, 24 Mar 2026 04:05:51 +0100 Received: from [52.101.53.48] (helo=BL0PR03CU003.outbound.protection.outlook.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c1ff8e-c823-0a2a45040019-346535307b5b-3 for ; Tue, 24 Mar 2026 04:05:51 +0100 Received: from CH5P223CA0021.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::22) by LV2PR12MB5989.namprd12.prod.outlook.com (2603:10b6:408:171::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9745.20; Tue, 24 Mar 2026 03:05:47 +0000 Received: from CH1PEPF0000A34B.namprd04.prod.outlook.com (2603:10b6:610:1f3:cafe::5c) by CH5P223CA0021.outlook.office365.com (2603:10b6:610:1f3::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9723.31 via Frontend Transport; Tue, 24 Mar 2026 03:05:42 +0000 Received: from satlexmb08.amd.com (165.204.84.17) by CH1PEPF0000A34B.mail.protection.outlook.com (10.167.244.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.19 via Frontend Transport; Tue, 24 Mar 2026 03:05:45 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.17; Mon, 23 Mar 2026 22:05:45 -0500 Received: from satlexmb08.amd.com (10.181.42.217) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 23 Mar 2026 22:05:45 -0500 Received: from ubuntu (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Mon, 23 Mar 2026 22:05:44 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fBWYCrztVbacYgALLFzAoFrtSd7diFq16O9xyAjjysgqj3aGwVvSVI1OuCp/V7bmcl1QTXYtuWnbuO1AGP44jQi4WZwnstimzC070LB7C8H4Cohe/62lURpKQdNvuLl77335JIjVWCk6/hRrl2T/LiSxRXVl+/PjeVlYqKVaEHoXZqunfa/r5qMH7IEdRO89MtvGZgOYynOvArtLGxZQCr0eo1x1EKDAU5DqKRDyAuBa8vcHufzjYSYlBeprntvtzHHChNQjhpyWnB4yWzvtAXU9FXeUTYbwW6mtsP3rm8ZW/lVVLGEVjFNBxzIFbCU/3L81bz8LIW2QYmhjAxLP+g== 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=QSf/Y6hBGzyirIB8wL+Tv2JZc0KdiMNKBUOutJwXS6A=; b=JrbzySqIyWd1xL0qglXI3FD9FJJMq8FsYBequF9FzfUzCmQ7hgHByw4PaMftxNpwn66qFZPh2LTPj7N9wCfLXTSlZlHbsBekY5JDDavuurb/jQDbX2BfTwNanUii3MI90AYgAE6TuiFFdqHpFAa+5Utc7+Dk6PZaQUiJDaalqwN3aiTenhCuWqfhtj7VZcZBASTQOFEZPyEnN1Bh93a2JU/tiiR7KSZ1K7LENXeq2PUk0+OG1SvubEJLXoaTsCWsYdKUwxHma8EL6o3KQFA7PK4gvBZskrkbFjKUG19a5ffHniQ/gG7cmq//BrAYLKSJ0/NAypMtddo0SDPFrKahdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QSf/Y6hBGzyirIB8wL+Tv2JZc0KdiMNKBUOutJwXS6A=; b=17MujKDVT6B7UfYc/w/K4pMI4uKWwZsYOoXbEcqfzEfyEjMd8CR06zGZCf8FZzX6hAZ8io/QUTCFtKCCMSr3PgDCWiQVHCyX0arleqeGpaB6vttzmm2vYqc6xz4W8unmZh6rQ2lpRk5spt4jMoFQY70Ou42IwbyMkQF6o/LPZDg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb08.amd.com; pr=C From: Stewart Hildebrand To: CC: Stewart Hildebrand , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 4/4] vpci: allow 32-bit BAR writes with memory decoding enabled Date: Mon, 23 Mar 2026 23:05:01 -0400 Message-ID: <20260324030513.700217-5-stewart.hildebrand@amd.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260324030513.700217-1-stewart.hildebrand@amd.com> References: <20260324030513.700217-1-stewart.hildebrand@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB03.amd.com: stewart.hildebrand@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000A34B:EE_|LV2PR12MB5989:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c3906ae-c441-4881-a403-08de89523e5b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|376014|13003099007|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: 3lnNFZnNczC6zi1wJttteuNOPSdKpTuSe6flfxYZMeVDb+5oVVZfkg9KkWO84TW83H56gXFkVS2PPYAlMDfF7KpVvhHhDMYO4edlmTqYpPgvOrzCLl+d/wQwF/7ivHXquIXiz5nUmnjeHY3SIHjwXpTtT/3KljQmdg7R2VfeeEm0SZpda2CzsFb8kZNAj2M7CspnMchSeUPbaA9kUmkEZD42O+o9Gn7oYvq0sw+DCdwE7OBzg+qZxI2CM9y6fTEHSwLn/1jA+dwFAmUTgY7xIYy4tbTchW+xtwB/letkap+3jWdUnpL+P0BX62sjEA9/L7ab0HZMzHMCFgCWWlcMg5RPYdVRMCUluZBSsqaPLCtGMnpRkuuj6ZuBqfcheMb4BfNkSduBAH7JuXzIM9KBAI6hSvwwb8Nf+Kp5KDd4MZHYWoTPQMUbI7jtahQt0jFzJGHdZ1OtCyEFU7YHX9Tdmm6eCWkUdOlvwQZ1d915yXbRXdPgbvb1mG/T05GdfcUrbrfblezO0ELG1YHf4SzPgh/NL6jyJqKgKehDxNSfKavu0a8LN+/IkytTXv6JdldlU79hT+ONjofpCGJAiGscNz7VmC7iFNyrkf3XHkLryXvD90JTbqT6rIL1KaWS+Lo2qbtKP4h3HIX6F4HDQpJJHSCSI94Y72fX/YcpaqdcSwmbyi0A1I0cYlCytjWIEhaLxpgoj5DIktZh5lJK0mcfIVQmp86ZDcSUyjlnmdVF2MusFwVYztmlVeatkRiOIxgLd2B0kZN8KV+DH60dj8bfAw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700016)(376014)(13003099007)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1622F/nCeCDomiFjtGhBVgyHtrx1HBTfXQBEVyW/doLbGMNv/hwpGpOHJGgwGOcAOK6qOSvQlczNvuHTh7NZzgwNvIqsvGFBJm/CaJ4zfIQMg2d986w4TthFkgEY6cxTT2AAUSxDqcB57O8P/FBRdAd/ceCnE95g0RHNds/iTW6l8eH4XocyXUQNIyT7M0yCn56HbxIvi1zDEzFnxMjrTX533Km/MroOSeVUcN+yhhyUJomRMHudRQ+3CUpkJsQnAnh43Y6Luxy2cJ03ylM8aMzZF/cfaiiHcWOWVA6nV+HERsJ58jZN5V4udF8aitEeu2PDVxWnS56g4CqKdz8U99OoHrLBwH7zT85zSKQW2bXmA7w6CeCrxOtFZLPdhhu7FPBwtuI+Dm7cdQYX8YJ2uRkbUDQ7uH6y3nLQF8PMzXhA2yrYMbtauJqLWpAMp+LS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2026 03:05:45.9169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c3906ae-c441-4881-a403-08de89523e5b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000A34B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5989 X-purgate-ID: tlsNG-ebf023/1774321551-B249D9D1-6C2F1D6C/0/0 X-purgate-type: clean X-purgate-size: 3882 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1774321575203154100 Content-Type: text/plain; charset="utf-8" Currently, Xen vPCI refuses BAR writes if the BAR is mapped in p2m. If firmware initializes a 32-bit BAR to a bad address, Linux may try to write a new address to the 32-bit BAR without disabling memory decoding. Since Xen refuses such writes, the BAR (and thus PCI device) will be non-functional. Allow the hardware domain to issue 32-bit BAR writes with memory decoding enabled. This increases the compatibility of PVH dom0 with more hardware. Note that Linux aims at disabling memory decoding before writing 64-bit BARs. Continue to refuse 64-bit BAR writes in Xen while those BARs are mapped for now to avoid mapping half-updated BARs in p2m. Increase number of unmap/map slots to 2. Resolves: https://gitlab.com/xen-project/xen/-/issues/197 Signed-off-by: Stewart Hildebrand --- v2->v3: * minor tweaks for fixed number of map/unmap slots v1->v2: * rework on top of queued BAR map/unmap operation machinery RFC->v1: * keep memory decoding enabled in hardware * allow write while memory decoding is enabled for 32-bit BARs only * rework BAR mapping machinery to support unmap-then-map operation --- xen/drivers/vpci/header.c | 33 ++++++++++++++++++++++++--------- xen/include/xen/vpci.h | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 9856840c3c87..2df992468383 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -605,6 +605,8 @@ static void cf_check bar_write( { struct vpci_bar *bar =3D data; bool hi =3D false; + uint16_t cmd =3D 0; + unsigned int map_slot =3D 0; =20 ASSERT(is_hardware_domain(pdev->domain)); =20 @@ -618,19 +620,29 @@ static void cf_check bar_write( val &=3D PCI_BASE_ADDRESS_MEM_MASK; =20 /* - * Xen only cares whether the BAR is mapped into the p2m, so allow BAR - * writes as long as the BAR is not mapped into the p2m. + * Allow 64-bit BAR writes only when the BAR is not mapped in p2m. Alw= ays + * allow 32-bit BAR writes. */ if ( bar->enabled ) { - /* If the value written is the current one avoid printing a warnin= g. */ - if ( val !=3D (uint32_t)(bar->addr >> (hi ? 32 : 0)) ) - gprintk(XENLOG_WARNING, - "%pp: ignored BAR %zu write while mapped\n", - &pdev->sbdf, bar - pdev->vpci->header.bars + hi); - return; - } + if ( bar->type =3D=3D VPCI_BAR_MEM32 ) + { + if ( val =3D=3D bar->addr ) + return; =20 + cmd =3D pci_conf_read16(pdev->sbdf, PCI_COMMAND); + modify_bars(pdev, cmd, false, false, map_slot++); + } + else + { + /* If the value written is the same avoid printing a warning. = */ + if ( val !=3D (uint32_t)(bar->addr >> (hi ? 32 : 0)) ) + gprintk(XENLOG_WARNING, + "%pp: ignored BAR %zu write while mapped\n", + &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + return; + } + } =20 /* * Update the cached address, so that when memory decoding is enabled @@ -650,6 +662,9 @@ static void cf_check bar_write( } =20 pci_conf_write32(pdev->sbdf, reg, val); + + if ( bar->enabled ) + modify_bars(pdev, cmd, false, true, map_slot++); } =20 static void cf_check guest_mem_bar_write(const struct pci_dev *pdev, diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index a6f8cb67dcac..a458b722cea6 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -168,7 +168,7 @@ struct vpci_vcpu { bool rom_only : 1; bool map : 1; bool pending : 1; - } task[1]; + } task[2]; }; =20 void vpci_dump_msi(void); --=20 2.53.0