From patchwork Tue Oct 4 15:36:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 12998537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35E67C4332F for ; Tue, 4 Oct 2022 15:45:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.415641.660256 (Exim 4.92) (envelope-from ) id 1ofk6J-0000Ey-1V; Tue, 04 Oct 2022 15:44:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 415641.660256; Tue, 04 Oct 2022 15:44:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ofk6I-0000Er-UJ; Tue, 04 Oct 2022 15:44:54 +0000 Received: by outflank-mailman (input) for mailman id 415641; Tue, 04 Oct 2022 15:44:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ofk6G-0000El-VR for xen-devel@lists.xenproject.org; Tue, 04 Oct 2022 15:44:53 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7add891c-43fb-11ed-9377-c1cf23e5d27e; Tue, 04 Oct 2022 17:44:51 +0200 (CEST) Received: from mail-sn1anam02lp2043.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) ([104.47.57.43]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Oct 2022 11:44:46 -0400 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) by MN2PR03MB5069.namprd03.prod.outlook.com (2603:10b6:208:1a2::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Tue, 4 Oct 2022 15:44:42 +0000 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::861e:b46c:1acc:c576]) by SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::861e:b46c:1acc:c576%5]) with mapi id 15.20.5676.031; Tue, 4 Oct 2022 15:44:42 +0000 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" X-Inumbo-ID: 7add891c-43fb-11ed-9377-c1cf23e5d27e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1664898291; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=GxM3JauTJ5kpdlfkv1k63x6Ab+AQz1agpnsqWVvPhSM=; b=aLad+PJ0yQkdfaLUF7nbwK7VlU3ORH/1Wog8d7Xy5idfEVODZu+s9Mti BOhu8MT3Jz8JZFvtB/YNj6Mbr7VR2OxAklh6Zlf+2GLHtrphmA7bNpNU/ YN/7J2ZtP9y+tHvDDJOlM9awBJ+7qv3LcVlH/VCex5ZJo6JENFP1ViOS9 k=; X-IronPort-RemoteIP: 104.47.57.43 X-IronPort-MID: 84475543 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:ICD5UKLu/yT+BhBrFE+RKJQlxSXFcZb7ZxGr2PjKsXjdYENS1WAGy WcfUG+HPf2M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2oU0dLj2DPMpbnnxE40ugYzlLbTgDIaB8OI uX58JBqTblUXMLbv6jDn1Ae+TYvdXEmL/vfBZDXnccmX+zpALtzIS/PwmT3x8YXT8K6bA+8V Ldmwi8wqm4qfm0xjLVymeWxZVLn9nKzMdFGaW3+78oAwSprjztSJVqWrWEsjxwiOaz6GwymN 2JmBskN9Qb0QKjQkiF5T/WnyXw2jcn7HHvjXWCh2H4nMD/TDUmT+JcmINwaHLimgAdleA59J gO83OStpJRAx+Ftj/6/cL0WxZjkVfxiWY+kNQUk2dUXeIlGfRsRLQkjQ9o+ao7bW3HANhNKp ghMCic3ocfTbqiVQGVgoE1q+bcH0jaHX+9Mzg/U4KuonhrdUtCvjUlLfwk7ws9Ha0GOuZ5Dp z/Q8JVfZF1P70rhPFGdZI8aPryLFDxajTxF0/XCWjbNcg8SgPwQtjMkfwI2N0= X-IronPort-AV: E=Sophos;i="5.95,158,1661832000"; d="scan'208";a="84475543" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f7ofW9gwG8Xfe9FztL+AFwhG0lZwrphGSme1sQA02FwASE1Cns/4uwyDv+XQLhejbVW6ZAGVmdX6qXdf3okYEo/mpte8rbQtv+PXBKV8IMaPpJ/ktfp5n82bGp+OiY2yfzjlDA9adBeQbwdj5+rbLTh5NCMEhSTGZBFBB2HqAOnQxJ8b8mrtlQzQTcU52Uz2DXvPxKZpVhmGbZDtb06nAmLcQcjDU/4irEHN7Yk9P3LU18qcNxlhX8vIgxeUswt5hSJ1LzwZhxHX9zjnx8Bf1m1R6N5VCoLWreUuFniEdw6/uB3zhQ8lYl2nrnMIBwtR2uNKiMvY3KZ3A9OiylelPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=FzHhUgUodl6F+UjPZ8S3zyC2KJRK1vQbJC/liYezVJw=; b=JtDaUjoHwKJB8siMXaQW3dcxu8z9CC3WXG1+elbOIoJaFAQZgLvn3TmgYMWmbjKYBsQgR1HdOc1DfJC9OBYIKZDbhwRGwcT2/QXr0Y4iY0zv6B+Gd7PxMX+5t5fzOPBIJCxHULIiTn8hIaOmL+A9GZAT5/UPuQ1L2lnDQNeZ9+MoCoIApn5SezPtQA7QsCG6H1hW8l3hfH+kaKXE76O7KbreFHC0gkLkBTjUi6G7jrKivZW0pQ+SG+T7N9v64ipSz0i3zMtzOrV/O0mDJK8rs/8bUz6YNyY///pV4KLW8E5TuBIooZupb+njUy4syPnRsHmMK+a1MmqJFucgOavQgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FzHhUgUodl6F+UjPZ8S3zyC2KJRK1vQbJC/liYezVJw=; b=ZV+c+d6puHp2Nc+sMUM9PluYcOTn2OWXgYGAUgJF4iOMRX4DLjk/qPEbe7utb8sqJ9QrwwNbsXnXlIqAW01+qvFP2ZN1eiU6uwQVsvQkkmm315VMzHoyRPhLMcRGYP6FQT6/K/83ode08LXdaFRvq4/1xbzoLwW/FfuiNr34KXM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH for-4.17] x86/pci: allow BARs to be positioned on e820 reserved regions Date: Tue, 4 Oct 2022 17:36:45 +0200 Message-Id: <20221004153645.3686-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.37.3 X-ClientProxiedBy: LO2P265CA0173.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::17) To SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6360:EE_|MN2PR03MB5069:EE_ X-MS-Office365-Filtering-Correlation-Id: 91d90215-96df-4a21-2ec5-08daa61f5ab2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iI89q8pOOJ+ROKqvTi5MtcMpVh7gmHeYCHrKL25R0SRGKhhMQxWXKc/QKgzJmBUaEh7V0qNyCIHf8344FeQtJVVJI943l4cSXfNx94bhrISJjLvhrXBoipOfaJTYiWCLYqu0ahQMV4B/rwThAAOELuNbdRLijrPMjECaS6gcNHmf8J5J/a67oIOf4W8N/Z0Ib7ybmBiMGNh6eQjYqTXqkIoDMD9YYMDMbKnBqhC4DWvoE8DpFHRx4qqaoQ8t5zZ+5Hlqsk4Xsx8Q4rFPVhsVbKx0MTBq/+smjtcuu58dbTN/cVKzNjfOlOU5o7byiUzWzrV+7GYiXpzwP7j5v3P+Mzt2UP+pRFmUg48/3m5AkaLeT9oRaypJ6cOqJLJJK1zyJ4qeDcPQNVpVKidGffJI+L9x3vvX/Q+cqlvl3ZUIPpvdQUhVLHPm/T4kUd4Ihy5AE6v8couuTMiKf6Yx2e3jmde8Rh8cyMmiwoSuwCzZ018BRs5sT1A2O9rEmPQDfRxR/T7xusmXibAbsVV1voFN8zYZcHP1pboIrf/Y+P4V2cRxd+0mZ49OiQZfzgj9rOjSGXciGwFnfQ2IbT6sz3XYNPSsCdVrtSDNvm2PIJemD6hxssRC7q67hjUB/o2imjGtKHg66xWhW3hkAV5XAhl7BP0+dSqTjKqzsTmu3EFGB3pWgg8z6EdFHbIws2PQ1SYSsjtXZ9RGCWNIEtnASe3X7Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6360.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(39860400002)(396003)(346002)(366004)(136003)(451199015)(6486002)(5660300002)(38100700002)(2906002)(478600001)(83380400001)(4326008)(86362001)(8676002)(66946007)(66556008)(66476007)(6512007)(54906003)(26005)(6916009)(41300700001)(6506007)(8936002)(82960400001)(316002)(36756003)(1076003)(2616005)(66899015)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XI9RxfYn+q4l2gtEuGcIVmT7oDmQ?= =?utf-8?q?hfeN6JfBPmEbuPPkLjlVBcXB/IWSZa/sTWtadvJbFcVSfjSrrTfUfS30zcvU9BSbj?= =?utf-8?q?2/lb8DUuy4m5I4q77sRA5xeqg4ptpgPwkL1Quzudi5jgwKV2gpeB7193NH4/ZhNO5?= =?utf-8?q?7MZkmY3ouSUqL2qMpfFXg8W7hkrDf1J2wkLqkvzfYYQmBKf2MkE3IkkZYNgA8vUBc?= =?utf-8?q?RrCpueXycfEkbahrVB+A8rmUb8osH7A5vmNQ01a1GAApIEo2a2EVttx3867wSlPie?= =?utf-8?q?jVflMnS4CeyApRy28bhUlDlSxFeBqTkClFsSysFNBOs3ZqnzjxRttmttbA8beSqdj?= =?utf-8?q?JRDGSGZ4vdm5LUF3LWZf5XatAAdBSx/OUrC11Q7CluOsLoTsqHP7l38IIJxohBWWs?= =?utf-8?q?AbOLMSoHqW7Uzds1Z+IBgF3Nyc8hHFtZl/MKbIerKUApJzkTgbXnIkylaI+i2FsW+?= =?utf-8?q?MV90o9U7Cd/7E/fM2MHIvZS5Idiwj6a1PcxfjQwGPbEZrjORqGetBQLI1Nsj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G?= =?utf-8?q?XbH5yd/vHoqNwfxo+CaxxQ2hK727zS44xGyrTNjMOxoOQafEAuljvxqTleDjNzQT/?= =?utf-8?q?cEGdQrsc5QBPSwyt9Tl5EauBGTIzX/FknEPVX7ka8BeIadWXelUerLc1dbzmWyS3I?= =?utf-8?q?ziZ81Iz6kXuEQtixTje3jEytxaNozshWQA=3D=3D?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91d90215-96df-4a21-2ec5-08daa61f5ab2 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6360.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2022 15:44:42.4826 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Fb7t8+62SdOMWZ7QJmvAZ4VulFXcWwFycnxTSLYigjFA3ezGIOJkFIKQ2EenOUv/BWf6n+QDpdEfFhq7WyTuIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB5069 The EFI memory map contains two memory types (EfiMemoryMappedIO and EfiMemoryMappedIOPortSpace) used to describe IO memory areas used by EFI firmware. The current parsing of the EFI memory map is translating EfiMemoryMappedIO to E820_RESERVED on x86. This causes issues on some boxes as the firmware is relying on using those regions to position the BARs of devices being used (possibly during runtime) for the firmware. Xen will disable memory decoding on any device that has BARs positioned over any regions on the e820 memory map, hence the firmware will malfunction after Xen turning off memory decoding for the device(s) that have BARs mapped in EfiMemoryMappedIO regions. The system under which this was observed has: EFI memory map: [...] 00000fd000000-00000fe7fffff type=11 attr=800000000000100d [...] 0000:00:1f.5 disabled: BAR [0xfe010, 0xfe010] overlaps with memory map The device behind this BAR is: 00:1f.5 Serial bus controller [0c80]: Intel Corporation Lewisburg SPI Controller (rev 09) Subsystem: Super Micro Computer Inc Device 091c Flags: fast devsel Memory at fe010000 (32-bit, non-prefetchable) [size=4K]well For the record, the symptom observed in that machine was a hard freeze when attempting to set an EFI variable (XEN_EFI_set_variable). Fix by allowing BARs of PCI devices to be positioned over reserved memory regions, but print a warning message about such overlap. Fixes: 75cc460a1b ('xen/pci: detect when BARs are not suitably positioned') Signed-off-by: Roger Pau Monné --- xen/arch/arm/include/asm/pci.h | 2 -- xen/arch/x86/include/asm/pci.h | 10 ---------- xen/arch/x86/pci.c | 27 +++++++++++++++++++++++++++ xen/include/xen/pci.h | 1 + 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h index 8cb46f6b71..80a2431804 100644 --- a/xen/arch/arm/include/asm/pci.h +++ b/xen/arch/arm/include/asm/pci.h @@ -126,8 +126,6 @@ int pci_host_iterate_bridges_and_count(struct domain *d, int pci_host_bridge_mappings(struct domain *d); -bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end); - #else /*!CONFIG_HAS_PCI*/ struct arch_pci_dev { }; diff --git a/xen/arch/x86/include/asm/pci.h b/xen/arch/x86/include/asm/pci.h index f4a58c8acf..c8e1a9ecdb 100644 --- a/xen/arch/x86/include/asm/pci.h +++ b/xen/arch/x86/include/asm/pci.h @@ -57,14 +57,4 @@ static always_inline bool is_pci_passthrough_enabled(void) void arch_pci_init_pdev(struct pci_dev *pdev); -static inline bool pci_check_bar(const struct pci_dev *pdev, - mfn_t start, mfn_t end) -{ - /* - * Check if BAR is not overlapping with any memory region defined - * in the memory map. - */ - return is_memory_hole(start, end); -} - #endif /* __X86_PCI_H__ */ diff --git a/xen/arch/x86/pci.c b/xen/arch/x86/pci.c index 97b792e578..6920bf2168 100644 --- a/xen/arch/x86/pci.c +++ b/xen/arch/x86/pci.c @@ -98,3 +98,30 @@ int pci_conf_write_intercept(unsigned int seg, unsigned int bdf, return rc; } + +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end) +{ + unsigned long mfn; + + /* + * Check if BAR is not overlapping with any memory region defined + * in the memory map. + */ + if ( is_memory_hole(start, end) ) + return true; + + /* + * Also allow BARs placed on reserved regions in order to deal with EFI + * firmware using EfiMemoryMappedIO regions to place the BARs of devices + * that can be used during runtime. But print a warning when doing so. + */ + for ( mfn = mfn_x(start); mfn <= mfn_x(end); mfn++ ) + if ( !page_is_ram_type(mfn, RAM_TYPE_RESERVED) ) + return false; + + printk(XENLOG_WARNING + "%pp: BAR [%#" PRI_mfn ", %#" PRI_mfn "] overlaps reserved region\n", + &pdev->sbdf, mfn_x(start), mfn_x(end)); + + return true; +} diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 5975ca2f30..64995fc68d 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -211,6 +211,7 @@ unsigned int pci_size_mem_bar(pci_sbdf_t sbdf, unsigned int pos, void pci_intx(const struct pci_dev *, bool enable); bool_t pcie_aer_get_firmware_first(const struct pci_dev *); +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end); struct pirq; int msixtbl_pt_register(struct domain *, struct pirq *, uint64_t gtable);