From patchwork Thu Oct 27 13:23:14 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: 13022145 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 67CAEECAAA1 for ; Thu, 27 Oct 2022 13:24:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.431049.683535 (Exim 4.92) (envelope-from ) id 1oo2rO-0002Ne-Sd; Thu, 27 Oct 2022 13:23:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 431049.683535; Thu, 27 Oct 2022 13:23:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oo2rO-0002NX-PQ; Thu, 27 Oct 2022 13:23:50 +0000 Received: by outflank-mailman (input) for mailman id 431049; Thu, 27 Oct 2022 13:23:49 +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 1oo2rN-0002NC-MV for xen-devel@lists.xenproject.org; Thu, 27 Oct 2022 13:23:49 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 88e0cb3d-55fa-11ed-8fd0-01056ac49cbb; Thu, 27 Oct 2022 15:23:27 +0200 (CEST) Received: from mail-mw2nam10lp2109.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.109]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Oct 2022 09:23:44 -0400 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) by MW4PR03MB6377.namprd03.prod.outlook.com (2603:10b6:303:11c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.23; Thu, 27 Oct 2022 13:23:43 +0000 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::9f90:6ba5:5b44:c254]) by SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::9f90:6ba5:5b44:c254%3]) with mapi id 15.20.5746.028; Thu, 27 Oct 2022 13:23:31 +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: 88e0cb3d-55fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1666877028; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=U/sFfRACaJY77fr7H33N73W/nGnZ1foREkrO0xbsYcw=; b=AQDlK/WWKoguwTwvgYOQSev8b9mrPYLlJWjHJ47O9LFvDWMA5COgFCa2 rq/Wea/ZuyoS4A5+oOW1tr0piEZuHdC/Qfbtes7Zf+Xs8IlcNr/BJy9tz Kcgb2bVHJBBPDnwcf4oOJ5GI611t60eYvFYZQprFHGTqkuL8+SWlBW20H A=; X-IronPort-RemoteIP: 104.47.55.109 X-IronPort-MID: 83623811 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:mVcLZ67jPFFH3V3oSgSrQwxRtAnGchMFZxGqfqrLsTDasY5as4F+v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CzMu9QHL1FqTmfbHOind+i1bfyJEwL8k/2 SAuwvl5p+7u/X+7hPHzWfc47lfhdOk4NpeA86njNQTN1zX+0+VTbUkf4fHkCE+oemp5lpvuN 7Qoy04N8A20H/VdnHdm2qZ5yDQlBIVr1Pyw16RhnXu5ebjQighNsZHjYVFNjPE9ksJprhHoe 529lPck6ASIQLLnSz76dSNfQptjFCIrX0rlvNWp2BDULEZdKRaoeUkjQ5o+a87bWzHAb0cYa hT5Jm23ocXTbraVQGSgoBX+q3iYpxpdS32AXTruaSuokprdT5CvgklLfck7wc9HaIGOud5Dt v/Q9VVfcl1P6krhIJGdZM8qJiMexvwaCOJFl6uCnLaM4xCE07xivfMkcYIDaeRCdc18Kc= X-IronPort-AV: E=Sophos;i="5.95,217,1661832000"; d="scan'208";a="83623811" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PI51BFXkQ/fWwzzghTpKMQtPfY196xMt/RSSlTSCyKWAMbvwh9k06aPMklfQlL4nTnaGQk1F4/AHOpicDkeU11kSAwp3JL7YqcPBzk6GdS72ZNND29Lz/sigdDR48v6kr/nSfQSVsZyniRZEf6T0vF3g2vOfvFPt5t7+HpxWqzj/ogEijsJulasOld0W+NEblUTx6xsu8JfyfEU/QNwEKolN2BisM5kX6qg9aemcw64w9odg5kUfVoWPJF/Zy3CuVGYdVCgeHOjisF+i1V4smzXYkTxr/VHXGzmf77DocKdPmrlsQy5GxDuLvzqNF/vhqeI32x/YGJM9HbCiimTSXw== 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=igYZqg1x/g0JshDU5Yx+sFod6AtAlB0SWplM18oXcQY=; b=ePXEJWPUALfOAtr0jpMY8ar8PoBwM+cVeGx1G6egtPlxkggxdJGoXVS8573cy9sFNeCnn4riF2dDFXXWL1qFW9uc4le/ImD4Djn3yfZw5+6xh5bUVDswvMY//egfv0Uj+UxH/YiKec9nDPSIFHoaoly9Yyb9mr6cTCIuu/Ab8WWRSQ3jGw3DvIRCf8aOdhyNf12vzPVWEEgYwu8U6UxXyr5MK6m+FVFMVHxDttKH+dHVKJJb8WA5ugFykutm89iUFR8pdGDu0McPR+Lv8vK7r40GWxl3/9m3ogEJJlPhT9nTIGhu+ltAwmkU4dZjKpH2I4xJhQ5/dJqSOpc6LlvYLg== 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=igYZqg1x/g0JshDU5Yx+sFod6AtAlB0SWplM18oXcQY=; b=w3cQV+vIadfMOTS7BjMsU5iZt5W918svDLOiNiqHL4UKoKSuyMfSkarcxQsf3rlaq67enNorVv+fj9/mo0GX89izFVM0ea24/+9FnFbfVA2lJSuOpfC/EcLt16GOkBCcFH8VXCQoEZF/46MrnWBQLnqb13OWLx0ZBoQvqlOlfGs= 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: Henry.Wang@arm.com, Roger Pau Monne , Jan Beulich , Paul Durrant Subject: [PATCH for-4.17 v3 1/2] pci: do not disable memory decoding for devices Date: Thu, 27 Oct 2022 15:23:14 +0200 Message-Id: <20221027132315.80592-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027132315.80592-1-roger.pau@citrix.com> References: <20221027132315.80592-1-roger.pau@citrix.com> X-ClientProxiedBy: BN8PR12CA0002.namprd12.prod.outlook.com (2603:10b6:408:60::15) To SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6360:EE_|MW4PR03MB6377:EE_ X-MS-Office365-Filtering-Correlation-Id: d7a7e494-5121-4657-c5a5-08dab81e7064 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /PjSTZePNQwqz5obKwcH9L5IQ67iJdKUw3K5CMmgGVSRgEGkkHdTD4xLxrxkXMV6BS0s/jE3P85ZZA951NyX/kaZo0cpt30JKeVF+csunYqj0taiSfF2XfE2sv32KSNfSKQxNdJ6NvvWOWRCTQjxptk11IlcqpgAN15+VpcScdXTAEKNjQWO9eKU91mXMiHwuqzlleJogY0TBd1ajhyRjiVo89SEC5I/Fbgmy1W11XkZsKqrXFOkzMExblinHAj8FhUYLee8a1773z0Xdtm3P+BqikeJfnDD4inNo1LIZhXlblVYUnI4DxeBN6Gl4YnBXKzurw5RQFXTJKyDMf1FiXaS9JdiL5Sldm46//neUBn8ejIJ3wUILYu/IGLNwJVVx7rNnsVeD/+Srg4fZwdK06ifBCtvHXldxUirFaeYYOOq0KZ3o0V/ga+Ef6QECzhds/vqp4NAkqV7kmJdmpUUTUSn0fTEQ5HTQmVRLL8fkAxYqrqgTVYLxDMK19+IzpKEpAiyuAC9KNJDHVHgTRlYQ0xkekBjgbqN1WUq6cPMllN/N/1/e/xhd6UjPjNTECsMwy3cmmXz1EV0oosuPI1Hg2pAJEc6fYxKR27Fq6xwQHVQ3RBA9xAE1a1q+iRKCKQnB/WrWlTZYlfTKkl7HN4jly37FpuG93J1py14bpYCuBF+LGcX/RwaJod41m4Gp+PmLKF7l3ab6SpkZ9kGCy0QDw== 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)(346002)(39860400002)(136003)(396003)(366004)(451199015)(478600001)(83380400001)(6486002)(54906003)(6916009)(6666004)(82960400001)(1076003)(4326008)(8676002)(36756003)(186003)(66476007)(26005)(6506007)(8936002)(41300700001)(38100700002)(66946007)(66556008)(2906002)(316002)(6512007)(86362001)(5660300002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?uY3c8H8cyuhL49B6Zu7zS+EooTC3?= =?utf-8?q?W7rwF2nSA9XVoGFozHCcF6DK2MLZsAAYJ12cImuZBjnBwb+DkKP9jaYbFqPPe7Ghv?= =?utf-8?q?u299oafwBS0QeftjF3RMzsuQS8G0mn2QOpAqNmul7H7TvZ3RB5BGRgD0KdaHvbLSZ?= =?utf-8?q?85FF4nqahOZCNSmuQaW3DabF2YYjjIGvVMHA85F9L2ETyZNkFmqGcUFxTn/rBE8Zz?= =?utf-8?q?4t9x2ScOkYIwsYeNuwObHROolkPexUZ7hEyCQ0MnvaLK9fqX46CJAsL1Ap+8Se7F3?= =?utf-8?q?VK2CUN1X4ilUrvh6yqSs7O5mXie9PQBRlVDCAJTwQQwv3dNI63ZKaCFQPhTt7wzwh?= =?utf-8?q?QupWK3+9nxPZEd+gJuGoNRWRrDzl0TKTQiefQRHND4E6qg4d9l73/ExCQsMFfm+k8?= =?utf-8?q?563HKpRvSKjszAF1mOMXHSuI2UMUh29TcEtu9NLDT+jQyBluwpC83tLiO7/LUE9q1?= =?utf-8?q?WtPa96tQHdJmF5boUAs5/7MI+msHh2ue1QHpVH1IdfFSl7tuaKtB7DdEwqVtglGkw?= =?utf-8?q?aGpxpGlXNccifbFqJQCHixFVHIrOpZI1GUnK8fIMV4K0JQcMYjRvg0EwvnurxLkJR?= =?utf-8?q?sBReks7lHB95xyGJC01uQHwwD5KcFe+E821gI4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cJdMJBJGX5TVke?= =?utf-8?q?hB8DZuNQ6ayi?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7a7e494-5121-4657-c5a5-08dab81e7064 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6360.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2022 13:23:30.9433 (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: Nct6zTIZ3s8McLRjy6ij7GbimV40vd/j0mCPwHOg+fAj669J+L+aDukV8CqDUFJUTDiwjQEHCNC2V2AJ0IlBZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR03MB6377 Commit 75cc460a1b added checks to ensure the position of the BARs from PCI devices don't overlap with regions defined on the memory map. When there's a collision memory decoding is left disabled for the device, assuming that dom0 will reposition the BAR if necessary and enable memory decoding. While this would be the case for devices being used by dom0, devices being used by the firmware itself that have no driver would usually be left with memory decoding disabled by dom0 if that's the state dom0 found them in, and thus firmware trying to make use of them will not function correctly. The initial intent of 75cc460a1b was to prevent vPCI from creating MMIO mappings on the dom0 p2m over regions that would otherwise already have mappings established. It's my view now that we likely went too far with 75cc460a1b, and Xen disabling memory decoding of devices (as buggy as they might be) is harmful, and reduces the set of hardware on which Xen works. This commits reverts most of 75cc460a1b, and instead adds checks to vPCI in order to prevent misplaced BARs from being added to the hardware domain p2m. Signaling on whether BARs are mapped is tracked in the vpci structure, so that misplaced BARs are not mapped, and thus Xen won't attempt to unmap them when memory decoding is disabled. This restores the behavior of Xen for PV dom0 to the state it was previous to 75cc460a1b, while also introducing a more contained fix for the vPCI BAR mapping issues. Fixes: 75cc460a1b ('xen/pci: detect when BARs are not suitably positioned') Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Also check ROM in modify_decoding. - Do the checks for all domains, regardless of their privilege. --- xen/drivers/passthrough/pci.c | 69 ----------------------------------- xen/drivers/vpci/header.c | 21 +++++++++-- 2 files changed, 18 insertions(+), 72 deletions(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 149f68bb6e..b42acb8d7c 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -233,9 +233,6 @@ static void check_pdev(const struct pci_dev *pdev) PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_REC_MASTER_ABORT | \ PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY) u16 val; - unsigned int nbars = 0, rom_pos = 0, i; - static const char warn[] = XENLOG_WARNING - "%pp disabled: %sBAR [%#lx, %#lx] overlaps with memory map\n"; if ( command_mask ) { @@ -254,8 +251,6 @@ static void check_pdev(const struct pci_dev *pdev) switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f ) { case PCI_HEADER_TYPE_BRIDGE: - nbars = PCI_HEADER_BRIDGE_NR_BARS; - rom_pos = PCI_ROM_ADDRESS1; if ( !bridge_ctl_mask ) break; val = pci_conf_read16(pdev->sbdf, PCI_BRIDGE_CONTROL); @@ -272,75 +267,11 @@ static void check_pdev(const struct pci_dev *pdev) } break; - case PCI_HEADER_TYPE_NORMAL: - nbars = PCI_HEADER_NORMAL_NR_BARS; - rom_pos = PCI_ROM_ADDRESS; - break; - case PCI_HEADER_TYPE_CARDBUS: /* TODO */ break; } #undef PCI_STATUS_CHECK - - /* Check if BARs overlap with other memory regions. */ - val = pci_conf_read16(pdev->sbdf, PCI_COMMAND); - if ( !(val & PCI_COMMAND_MEMORY) || pdev->ignore_bars ) - return; - - pci_conf_write16(pdev->sbdf, PCI_COMMAND, val & ~PCI_COMMAND_MEMORY); - for ( i = 0; i < nbars; ) - { - uint64_t addr, size; - unsigned int reg = PCI_BASE_ADDRESS_0 + i * 4; - int rc = 1; - - if ( (pci_conf_read32(pdev->sbdf, reg) & PCI_BASE_ADDRESS_SPACE) != - PCI_BASE_ADDRESS_SPACE_MEMORY ) - goto next; - - rc = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size, - (i == nbars - 1) ? PCI_BAR_LAST : 0); - if ( rc < 0 ) - /* Unable to size, better leave memory decoding disabled. */ - return; - if ( size && !pci_check_bar(pdev, maddr_to_mfn(addr), - maddr_to_mfn(addr + size - 1)) ) - { - /* - * Return without enabling memory decoding if BAR position is not - * in IO suitable memory. Let the hardware domain re-position the - * BAR. - */ - printk(warn, - &pdev->sbdf, "", PFN_DOWN(addr), PFN_DOWN(addr + size - 1)); - return; - } - - next: - ASSERT(rc > 0); - i += rc; - } - - if ( rom_pos && - (pci_conf_read32(pdev->sbdf, rom_pos) & PCI_ROM_ADDRESS_ENABLE) ) - { - uint64_t addr, size; - int rc = pci_size_mem_bar(pdev->sbdf, rom_pos, &addr, &size, - PCI_BAR_ROM); - - if ( rc < 0 ) - return; - if ( size && !pci_check_bar(pdev, maddr_to_mfn(addr), - maddr_to_mfn(addr + size - 1)) ) - { - printk(warn, &pdev->sbdf, "ROM ", PFN_DOWN(addr), - PFN_DOWN(addr + size - 1)); - return; - } - } - - pci_conf_write16(pdev->sbdf, PCI_COMMAND, val); } static void apply_quirks(struct pci_dev *pdev) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index eb9219a49a..d272b3f343 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -115,13 +115,18 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, uint32_t val = bar->addr | (map ? PCI_ROM_ADDRESS_ENABLE : 0); - bar->enabled = header->rom_enabled = map; + if ( pci_check_bar(pdev, _mfn(PFN_DOWN(bar->addr)), + _mfn(PFN_DOWN(bar->addr + bar->size - 1))) ) + bar->enabled = map; + header->rom_enabled = map; pci_conf_write32(pdev->sbdf, rom_pos, val); return; } if ( !rom_only && - (bar->type != VPCI_BAR_ROM || header->rom_enabled) ) + (bar->type != VPCI_BAR_ROM || header->rom_enabled) && + pci_check_bar(pdev, _mfn(PFN_DOWN(bar->addr)), + _mfn(PFN_DOWN(bar->addr + bar->size - 1))) ) bar->enabled = map; } @@ -234,9 +239,19 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) if ( !MAPPABLE_BAR(bar) || (rom_only ? bar->type != VPCI_BAR_ROM - : (bar->type == VPCI_BAR_ROM && !header->rom_enabled)) ) + : (bar->type == VPCI_BAR_ROM && !header->rom_enabled)) || + /* Skip BARs already in the requested state. */ + bar->enabled == !!(cmd & PCI_COMMAND_MEMORY) ) continue; + if ( !pci_check_bar(pdev, _mfn(start), _mfn(end)) ) + { + printk(XENLOG_G_WARNING + "%pp: not mapping BAR [%lx, %lx] invalid position\n", + &pdev->sbdf, start, end); + continue; + } + rc = rangeset_add_range(mem, start, end); if ( rc ) { From patchwork Thu Oct 27 13:23:15 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: 13022144 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 C4F13FA3740 for ; Thu, 27 Oct 2022 13:24:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.431050.683546 (Exim 4.92) (envelope-from ) id 1oo2rQ-0002dq-77; Thu, 27 Oct 2022 13:23:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 431050.683546; Thu, 27 Oct 2022 13:23:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oo2rQ-0002dh-4E; Thu, 27 Oct 2022 13:23:52 +0000 Received: by outflank-mailman (input) for mailman id 431050; Thu, 27 Oct 2022 13:23:51 +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 1oo2rO-0002NC-Px for xen-devel@lists.xenproject.org; Thu, 27 Oct 2022 13:23:51 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b19e53f-55fa-11ed-8fd0-01056ac49cbb; Thu, 27 Oct 2022 15:23:28 +0200 (CEST) Received: from mail-mw2nam10lp2100.outbound.protection.outlook.com (HELO NAM10-MW2-obe.outbound.protection.outlook.com) ([104.47.55.100]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Oct 2022 09:23:45 -0400 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) by MW4PR03MB6377.namprd03.prod.outlook.com (2603:10b6:303:11c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.23; Thu, 27 Oct 2022 13:23:43 +0000 Received: from SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::9f90:6ba5:5b44:c254]) by SJ0PR03MB6360.namprd03.prod.outlook.com ([fe80::9f90:6ba5:5b44:c254%3]) with mapi id 15.20.5746.028; Thu, 27 Oct 2022 13:23:43 +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: 8b19e53f-55fa-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1666877029; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=VYmDNmKt0p2+CEpXe0jIDJH4snfwphrxsB4ACulM+Yo=; b=Q0seDADDHnt5xZEDzDodyaju4Rz0vaUkwKQ1NfjEXQ5094elUe19UrDp nTtt2d7gCVdxJHHeJUv4ZJzJa/zLPSZKUar3pUXZ49GJEcuow26JqkGtF Qy6p8PqVDSJt/WuJd9fxpyZzJCc3cQYb0HKaQrQjUeBEG4trO1ayeAYM0 A=; X-IronPort-RemoteIP: 104.47.55.100 X-IronPort-MID: 83623812 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:MZ69WqrCQjw+OG8nF8Hm9nDpaUReBmIOZBIvgKrLsJaIsI4StFCzt garIBmBM/yJMzCkLYgkbIjlp08D75LUmtcwHVBuri4yRn4X+JuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYGYpLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9VU+4ZwehBtC5gZkPKgR4weH/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5ms sYGAxwpfhq/h/OYwIK8cbVjg98NFZy+VG8fkikIITDxK98DGMiGZpqQoNhS0XE3m9xEGuvYa 4wBcz1zYR/cYhpJfFAKFJY5m+TujX76G9FagAvN+exrvC6OkUooiOCF3Nn9I7RmQe1PmUmVv CTe9nnRCRAGLt2PjzGC9xpAg8efxn2hA9JLTtVU8NZXrAfIxGA6KiEvfnmxoPiU1WiZZMBQf hl8Fi0G6PJaGFaQZsnwWVi0rWCJujYYWsFMCKsq5QeV0K3W7g2FQG8eQVZpSNEgrt5wejUs2 XeAhdavDjtq2IB5UlqY/7aQ6DatYy4cKDZaYTdeFFNdpd7+vIs0kxTDCM55F7K4hcH0Hje2x C2WqC85hPMYistjO7iHwG0rSgmE/vDhJjPZLC2ONo55xmuVvLKYWrE= IronPort-HdrOrdr: A9a23:1HBjl67Bf+7s+UpEKgPXwVOBI+orL9Y04lQ7vn2ZFiY5TiXIra qTdaogviMc6Ax/ZJjvo6HjBEDmewKnyXcV2/hrAV7GZmXbUQSTXeVfBOfZowEIXheOj9K1tp 0QDJSWdueAamSS5PySiGfYLz9j+qj+zEnBv5aj854Hd3AOV0gP1XYbNu7NeXcGOTWuSKBJYq a0145inX6NaH4XZsO0Cj0sWPXCncTCkNbDbQQdDxAqxQGShXfwgYSKWySw71M7aXdi0L0i+W /Kn0jQ4biiieiyzlv523XI55pbtdP9wp9oBdCKiOISNjLw4zzYLbhJavmnhnQYseuv4FElnJ 3lpAohBd167zfrcmS8sXLWqnzd+Qdrz0Wn5U6TgHPlr8C8bik9EdB9iYVQdQacw1Y8vflnuZ g7k16xht5yN1ftjS7979/HW1VBjUyvu0cvluYVkjh2TZYeUrlMtoYSlXklXavoJBiKprzPLd MeTf01vJ1tABOnhjHizyNSKeWXLzsO9kzseDlAhiSXuwIm7kyRgXFohvD3pU1whK7Ve6M0md gsDZ4Y5Y2mNvVmC56VJN1xNfdfWVa9Ni7kASa1HWnNMp0hFjbkl6PXiY9Fl91CPqZ4h6cPpA == X-IronPort-AV: E=Sophos;i="5.95,217,1661832000"; d="scan'208";a="83623812" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EFiqBxu7t0B66oqHnTcgM5NQR/J7XC249WtwBEioBU8e97nDIZ97BeMQNO+UTbl5z/6R12JqzJB8GSmt6wX8zCEfBQyVXMcbUvejAUXfoM67OnMOla9gXn/fX3QNtxXmVbPF8oBuqgBLe4FPzP2QjIUN5P08pgKSVufgyf8pzUN5p9Ssj5XcOwa7x7lGSTG9rzRwWQRjMMYqlkPdLzKFFdUd+z9bMRXtjOB49Mifc1qbOy1qPYlPoOWTOAjXvZLoM1dNv+sKcS3A6xsuXcwuEAeTU9QbDvoyY1KuF5EXuTzNxkRXp+0UCGbxukazRQwJGHBGEfQ6kY4R4EikmIokrA== 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=yUXzzGq4VSx8sBvqH8bPi1ynt4HYx3T9gdXKxYW08cM=; b=MN0WSZ5gvCcQcQnfdz/to5x4nI+blQoqnKlp6AtQKuL7oCOdG3/ss2TPxwk859BGwH3+DEh0Eqnv9aAAfSPnKsOoSyDyvOJDyy9VDXMvBJ0MDF4DzM1clwK1MvR30jYvVtGLmCiORS1Q6gi3PVj05a6AP/IEvoGeHuRLyNI4te9zDksefohSUQ7tAJoB68WxYAAuWQMc1yP8OLMNOvmdEJeAcPfdyxm3/499oP4hNB4PKpti3KXhGdLMUaQnVS9M7RvaX1D/ZjuJOzgKbzQgh96+Qqg2nn2nmFKsQSPh294TMYQlFLV9j5VT1Fl1VPXRtD+ZzxlnydRTkRqw4FXsJA== 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=yUXzzGq4VSx8sBvqH8bPi1ynt4HYx3T9gdXKxYW08cM=; b=Hx4Q3l31+rI+hhwH7MNwC39WD8e14BWkHe4rqgKkCC9zIghtMfQYmx4hA3F/Gkjzeugcg8kHjrqhlTMkOungTyWen++T7vOtitCqNKb3fKcZDc+BFZqnPMA1Y66MKPiIoFBCohilPbCdFKQ15XLS01sVkJ+IUhtdAtJYA/y4WDM= 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: Henry.Wang@arm.com, Roger Pau Monne Subject: [PATCH for-4.17 v3 2/2] vpci: refuse BAR writes only if the BAR is mapped Date: Thu, 27 Oct 2022 15:23:15 +0200 Message-Id: <20221027132315.80592-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221027132315.80592-1-roger.pau@citrix.com> References: <20221027132315.80592-1-roger.pau@citrix.com> X-ClientProxiedBy: BN0PR04CA0058.namprd04.prod.outlook.com (2603:10b6:408:e8::33) To SJ0PR03MB6360.namprd03.prod.outlook.com (2603:10b6:a03:395::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6360:EE_|MW4PR03MB6377:EE_ X-MS-Office365-Filtering-Correlation-Id: 924ec5d8-de00-48d6-ea62-08dab81e7337 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L0iRnEDQzbWMdKqqAdjBuKN65W11XdBwfoYYu/Wy6uagVJOkVU5+sjjh36Hn9Gp7t09JlVEfxMQ+ChpYs0FGS9l09ZJJeYz540t+qS67mNmIVZwmLCrAzcM34PAdBz8X6mTHOFvJl2vnCkM9oACXSe4TgGmOiP0RlxSbn4qp/it1oV0rWLXH7LDJId+f+pRrqg5AWkCNIlED+sScKX1VTHH0v69kNOvmiHK5evaLCNTpymMa2bbrbV4kFmVUBSgljuWXE6C0JcSPnkdJ6wJeGKydrRpIbZMI2rnPEWwyXYFHXuezRkDB6UelXd6bfkJt6JzaFhSkUdliOhtpxR+EW5JruBLDjXAV7LL0o9TTR5ywAwDvjPvamYpv8PEAC1NejDMoM4kG+SOU/rg2rGjNbEc5W0zie6TIJrrfzBHVmmlB20NkwPlPxrK5ovI9gH1aOCj5RJKgCM0QXXKH3POM94QsiiNjhroKGvpv341YJ3iL1Y9/vJj7IYG27gZJGG8C3N7iA/yvR7hLvv61/DLodmXtFe+KDlxeGIiF9xg8K0Z9CkCD2eZvQxD9xn8Iae81c/ugaVeoSD0zJYkfMDaBLSmxNEo2yqn+Z/Pd6WV+XEsr6ji+HTK0Y/xrn8Kek2qU7X29NaOStqPzHS4nM3ak3Haftil5m6b/HtkNtUrn4BqSJfIrW9QOpbPHEfpu5apQhccb3CUUF0HEDAqsg0RPFA== 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)(346002)(39860400002)(136003)(396003)(366004)(451199015)(478600001)(83380400001)(6486002)(6916009)(107886003)(6666004)(82960400001)(1076003)(4326008)(8676002)(36756003)(186003)(66476007)(26005)(6506007)(8936002)(41300700001)(38100700002)(66946007)(66556008)(2906002)(316002)(6512007)(86362001)(5660300002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Gs/AWMtv0aOrRZ285FgAm+PFKmzt?= =?utf-8?q?HSFL66OF1m/eSyhJEaCmkVd0EBngUELczlzAr4hxWELVwfON/3C60EFnQL9ue7CuU?= =?utf-8?q?oXYkB3f+tI0Vlj4U2Ty++PkHdheiG0sVFVFc+sdmoV15c8208BBFmNOS7kOcgsU2Z?= =?utf-8?q?q5jifcm7aiefFcaW73bz9DiyprjiCUMVr5lq/CcwPsH90bEwr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eYdwyCmpyg9pqRbSY?= =?utf-8?q?ou5Yazb3I4UI5NFhF70gUK1hKjmr3V3ma42f8nNRtvtEao/mXLdwzmNeLTAaAz5eH?= =?utf-8?q?L1FDbx4MBq0asjLe0X7ny1sZtQC1v/CCeQgFy9ND+he2zNotkEx2qODbdOGI4JDD5?= =?utf-8?q?1gIjV/AFjuRD30FAiJxCt0y0yembxPqGsJoi/iawvUhHMsPdoetLd7vYmYmlDUcMP?= =?utf-8?q?3lYozYQCd/Or4uNxjj07R2yfPAngh8b1h7gVenpKNZIxtYuvPYzF8bqZtAyU983Nb?= =?utf-8?q?geTdd1FufjyjEoqnL+DlRc/IVQd/QMOC+p10uMaAhdoEyuwY11ahDsFG1zXDHvcfW?= =?utf-8?q?7HMXqQIGgdEGeGz+iVfIYBwFqljMjEPMbAiPyqFZWFWPZIPKW4CRRuPb3/hOqJdwo?= =?utf-8?q?0tg9Qk9yVeDmiN0TBrR6q0tLK/Fv2nGtxWbWfcYPgdDWoSU+hvbHwjJaWrnohwuNp?= =?utf-8?q?hUABHisJXbV7?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 924ec5d8-de00-48d6-ea62-08dab81e7337 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6360.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2022 13:23:35.0732 (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: 4K7Wc/XwjOl/pjwrR7athEAG16ev81WQ9kD0V+i5p1OhlWbsnNJ+KNBwOy0TfjFhPLssljKiEl2k3PJlJnLliw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR03MB6377 Writes to the BARs are ignored if memory decoding is enabled for the device, and the same happen with ROM BARs if the write is an attempt to change the position of the BAR without disabling it first. The reason of ignoring such writes is a limitation in Xen, as it would need to unmap the BAR, change the address, and remap the BAR at the new position, which the current logic doesn't support. Some devices however seem to (wrongly) have the memory decoding bit hardcoded to enabled, and attempts to disable it don't get reflected on the command register. This causes issues for well behaved domains that disable memory decoding and then try to size the BARs, as vPCI will think memory decoding is still enabled and ignore the write. Since vPCI doesn't explicitly care about whether the memory decoding bit is disabled as long as the BAR is not mapped in the domain p2m use the information in the vpci_bar to check whether the BAR is mapped, and refuse writes only based on that information. This workarounds the issue, and allows domains to size and reposition the BARs properly. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- Changes since v2: - Use domains instead of guests in the commit log. - Add comment about ignoring {ROM,} BAR writes. - Use rom->enabled in rom_write(). Changes since v1: - Cache setting of memory decoding in command register. - Reword some log messages. --- xen/drivers/vpci/header.c | 31 +++++++++++++++++++++---------- xen/include/xen/vpci.h | 6 ++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index d272b3f343..ec2e978a4e 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -131,7 +131,10 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, } if ( !rom_only ) + { pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); + header->bars_mapped = map; + } else ASSERT_UNREACHABLE(); } @@ -352,13 +355,13 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) static void cf_check cmd_write( const struct pci_dev *pdev, unsigned int reg, uint32_t cmd, void *data) { - uint16_t current_cmd = pci_conf_read16(pdev->sbdf, reg); + struct vpci_header *header = data; /* * Let Dom0 play with all the bits directly except for the memory * decoding one. */ - if ( (cmd ^ current_cmd) & PCI_COMMAND_MEMORY ) + if ( header->bars_mapped != !!(cmd & PCI_COMMAND_MEMORY) ) /* * Ignore the error. No memory has been added or removed from the p2m * (because the actual p2m changes are deferred in defer_map) and the @@ -385,12 +388,16 @@ static void cf_check bar_write( else val &= PCI_BASE_ADDRESS_MEM_MASK; - if ( pci_conf_read16(pdev->sbdf, PCI_COMMAND) & PCI_COMMAND_MEMORY ) + /* + * 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. + */ + if ( bar->enabled ) { /* If the value written is the current one avoid printing a warning. */ if ( val != (uint32_t)(bar->addr >> (hi ? 32 : 0)) ) gprintk(XENLOG_WARNING, - "%pp: ignored BAR %zu write with memory decoding enabled\n", + "%pp: ignored BAR %zu write while mapped\n", &pdev->sbdf, bar - pdev->vpci->header.bars + hi); return; } @@ -419,25 +426,29 @@ static void cf_check rom_write( { struct vpci_header *header = &pdev->vpci->header; struct vpci_bar *rom = data; - uint16_t cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND); bool new_enabled = val & PCI_ROM_ADDRESS_ENABLE; - if ( (cmd & PCI_COMMAND_MEMORY) && header->rom_enabled && new_enabled ) + /* + * See comment in bar_write(). Additionally since the ROM BAR has an enable + * bit some writes are allowed while the BAR is mapped, as long as the + * write is to unmap the ROM BAR. + */ + if ( rom->enabled && new_enabled ) { gprintk(XENLOG_WARNING, - "%pp: ignored ROM BAR write with memory decoding enabled\n", + "%pp: ignored ROM BAR write while mapped\n", &pdev->sbdf); return; } - if ( !header->rom_enabled ) + if ( !rom->enabled ) /* - * If the ROM BAR is not enabled update the address field so the + * If the ROM BAR is not mapped update the address field so the * correct address is mapped into the p2m. */ rom->addr = val & PCI_ROM_ADDRESS_MASK; - if ( !(cmd & PCI_COMMAND_MEMORY) || header->rom_enabled == new_enabled ) + if ( !header->bars_mapped || rom->enabled == new_enabled ) { /* Just update the ROM BAR field. */ header->rom_enabled = new_enabled; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 67c9a0c631..d8acfeba8a 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -88,6 +88,12 @@ struct vpci { * is mapped into guest p2m) if there's a ROM BAR on the device. */ bool rom_enabled : 1; + /* + * Cache whether memory decoding is enabled from our PoV. + * Some devices have a sticky memory decoding so that can't be relied + * upon to know whether BARs are mapped into the guest p2m. + */ + bool bars_mapped : 1; /* FIXME: currently there's no support for SR-IOV. */ } header;