From patchwork Tue Aug 29 23:19:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369802 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 CB7E9C83F19 for ; Tue, 29 Aug 2023 23:20:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592522.925357 (Exim 4.92) (envelope-from ) id 1qb80H-0001nM-U7; Tue, 29 Aug 2023 23:20:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592522.925357; Tue, 29 Aug 2023 23:20:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80H-0001ix-9z; Tue, 29 Aug 2023 23:20:09 +0000 Received: by outflank-mailman (input) for mailman id 592522; Tue, 29 Aug 2023 23:20:07 +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 1qb80F-0006kQ-7C for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:07 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 95a0de5e-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:20:05 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9h021983; Tue, 29 Aug 2023 23:19:49 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:49 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:43 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19: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: 95a0de5e-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SaCwnb7DqXkGDSkPtJwPgLIRI55FRZy8DDj6du446NbjqSLu8ic5YDKlN7CJIEs1mk5sN4ZAMAQENSVyilwOnE4xE6cxIy0iO/QjcPpYsilk4i0kSfFfH32xA57F+DGCRxS3AZuFJFALbVuEXh6nx5D/KeU6lB0zzNptdPBQuJeMLyC5RiQJhbsPsu5SNkDCsjJp3jaWwU1CkozjYP3RnkxMBrmM3Nv2PD/Bapu6hyQ12KHQzBDIUFvdlthlY3DfqHBte1Rof+RYFInGNt65zU8Nce/WaQDBS3jxrTvmlpzImqD217wuVVnmCmF8YGi1CqPs+3RapunW80Gs+O3Sug== 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=d2+SjNS5ON5irHRUHXgAVHRcgI+kAagi6t5CcHlMjAs=; b=fztmfChJYRwAU++IwyQPmcllo5Gj3MTwECUuGjkZHv8UVBl6VvhvfQt/zJMuBzS75VDymuLbA8xrnGAccg/zrp4swySmYBTfLFVwU4adSKX333kYTya8dmwmJNrIjXFcLIVnf7x63E2NW6RpTXEn9lus3l80+hSzDUwx8xx6Pet4Jwpr5jrz64C6w9V+S0SMMrkIPyX5YhTB7ml2T+l4k+ltQmawwBs+iOnXpU2ezAiK5iPBrDhL6mf1tSHvBEKoGzul/+UqVRU6VJE18ce39L2o03W22rXCshx9U3YElCcdNrBWyKiIWPybEma597O1uzGePwvahP/9dHDoYsMtSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d2+SjNS5ON5irHRUHXgAVHRcgI+kAagi6t5CcHlMjAs=; b=igPIi1XHHt6eETC7O7H+lDkTeTDGPPEOlu+X1/ZEGFiBs6G+p3D/KkuEBZodx0RAh0GSaj7ErnqDT1z0UN3bkTkceJWpKdMynCnCM3jQTC/wFeyQuDPjyipaMmWlLB4vs5jjQBSmxmLcVcdgopjqvFdGaYKJ30Z3QffBjqH3/wwSOZEE+0misjeAc7gcryVY53TeUTO8qdq1Z81aZ5uLo3I78ysX14yS++HvKCWkmxLJfYwB0heL5bXB1FeUqjWKo1RlgdWk8WL3aLyDUFeScXPbHPaVLpufj8aUmZMyAJvWnaIa0Z1E4SdoTsFfABLmlv1SI3iZ9rPsCk3We9oCzw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Paul Durrant , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Kevin Tian Subject: [PATCH v9 01/16] pci: introduce per-domain PCI rwlock Thread-Topic: [PATCH v9 01/16] pci: introduce per-domain PCI rwlock Thread-Index: AQHZ2s9KWF3JKCAv4U2Fm0C+oJYn+A== Date: Tue, 29 Aug 2023 23:19:42 +0000 Message-ID: <20230829231912.4091958-2-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 13aee429-ce8d-4786-1bb8-08dba8e66d44 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EQYMY+iTNTd9gXBaIqovB0YzB/J8TZeQjhbvIbE4PHamUP4oOWwG1VA759p4DBucu6lfsVsnrsc2HxWCZO1k74r5Yod9wsbHMkZYjilkNjauiDvuUd8tHuaspsaSr64Yd0K3c2P3v1fhpkxcmcdqnFHJWbZRae6QT1sHiFUXziWIqexKCizLWqyxQdqvlEw/TlIfbLe7DpmoaI4Y8zffrK1IgqgLGqbG8ZcT1ORRWevqwoE20cervkRzLORc4YwpPKkeVLhrtVSuI+ndBavL3Ukeb1YQK8nVwi3IKbw21royAWYqMS6KkEJIBFcSFj0zTdcYikeCycmmdvomvU3JKG3tnrDkxv8saIjftKC1ok9mjMlI4vc7+GkVUScJ7mifcFYNdUNbqigexLy4BZBDYnnq9Zguf8RDkhiofxUrfCmC29eYEXXMmIdxnfXt1wioqHNNh32EPhaX/QmBIouaukXLPcVCvet3kolggfFbtx+MR0XuxWz4svHDf61u3CGL0hsPC39QPHxZgF0z3iWI2pGr8C9dvy+rS4Hx3NndFnySWj1EZfCcR5Smlsl3VpJPfD/5fHSJJg88+SaUfehEMwQnnKzvcu4OTgdsbosSXOncPqTsA2x5jih46QYZt8oe x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(7416002)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?1vI8rJ5J4wNIAagk2NXcK6FHbJdq?= =?utf-8?q?TMY1Tj/bHM4UyO7a0XQHFqK3qjK7ClxC11FXS9mGDrIdVFqolIkn6k0W4xaVb64+z?= =?utf-8?q?zN2J7+akQW7QjM0mW/Dzra9ud1zrVq9vWRHJc8fW5H+qLYqYLAgbPYlsQryl2cxgE?= =?utf-8?q?1rUeKkPOdM9jEaWM1dIRuhAEaEGJUCzmgxemQlDSL47CcC7YjtabAhEjjqFVpMAUf?= =?utf-8?q?vqZ63ya61DPeWUaT8tEdN88GCQi8UjEDkeo6I62AywF2YUsIHBC4POVewsSEKl+SZ?= =?utf-8?q?EaFW/EY0Nui2LcrOd5lqtl4eLj80C8W6E7II8bS5TJ3vTAO+aFq1qK3qPNZvwpvC5?= =?utf-8?q?L31h8Xav/LdhcJaO35sQfZShKGM8x6J443zGR4IgYlXlsbFaz4DhN2ZsX0M851nYt?= =?utf-8?q?Ax2FYbN0OaxIe/CDwuGe9I1sRvNU/NxtZCXP47xTNUnBfBHFBFcqcjD2z2393o468?= =?utf-8?q?ajvUPW16ZFrIb4JMEJAXmpl5UADMVYlxz9ZN7k8/MDsgu+RPv9LJvqHi5TPTTuBkJ?= =?utf-8?q?zvzpDVxmVT0F5O3cKMOG+/+Rk7Cb3QiKSITlA/AJ0rRsyNaiqKEu1Fh9PWV+RqsB0?= =?utf-8?q?NCuFxJEgf1+Gf/PfpbFUfw79o8aLBnuIpy+aFzx1kgxXyI7FoiZbvfLcHRG8oybRf?= =?utf-8?q?9cm5XixNtM0+dg/yTCBKBi9+bU85QRpbdsfyWpdcExYQqy2g8mRF92mv8+TDWed8f?= =?utf-8?q?KHTCQrAiaqhYa5JWRZ/A3R9nv2sMIHt0phmk+7zKTjkk8++vSrvh69p4kYjhNI9Eb?= =?utf-8?q?Dl0XikExebFFNOCLgoyzzy5A79pfIyzk3nhOHkBN1ggeWlOe4FLSv30zCev+I9CVU?= =?utf-8?q?/VYzBC4+m8w9iN87KIzVV1YZX1Rn7k2XCs+t9EgUV5YsBlWN2tqICvg3xGIrYs8YB?= =?utf-8?q?llIrGLbRAnhh9asO3nmQEGk0BT7ITds14RbLIjOyYw8n36oo8IS07XaKy5JK++Q0n?= =?utf-8?q?MdDhMB6F83Ex5IrRDgN7nWCl9Bgxd8skuIj67fpXRUKNmeglI4m7kEOccgxd+m1Gf?= =?utf-8?q?+fqH2yuqRROI6XNb2a5k2YR9X7ZOiPrjWcPlNNJME/j2ahZeYXJaWho4ObGSBgAUV?= =?utf-8?q?v1QmncwlSSJgwdFbn2QyrIvp/TfwHC0FCTLCUZfqzgNvKwxhe4BTnGiaY+3CrlZ3p?= =?utf-8?q?x/XRGpKUOw8lo1mbrg8L8MZhZXFSKQgWVwvUa0+lhOhLnOMQsHVTWjvYBDaw59BLq?= =?utf-8?q?5pfNaAPsCcktqzt5kOwsYYaW9su5g+JsogFwx/EjnOQXuZkzk3P1NKJDVInfuTr8Z?= =?utf-8?q?YsGRmKUHXPPRdyx4yIDtQJMNLy3WVkixRz7UDPC3S6is3V35tdM4NgtUA6Tt0SX1C?= =?utf-8?q?2wBeErL32W0pGXs25W8nRRXig8K/iXWm1vdwwXTN43bhLRxAEK1TBqxxfxHeQ/EVL?= =?utf-8?q?o0JmhfRy4ijySerZpI5G7ZthWiNI0Iyp0kXiLsoMRTKCHkxc8jCRXso0m9CEvIix/?= =?utf-8?q?39Nj2PpI9lQWw277HrJ/PsPBkwOpPTPe5CmHnugmMXVnEqZMrxBonH1UNdH8/zOIB?= =?utf-8?q?ZCU8RiIGuLtngKFinUWwSxkjfJPiHvYbmw=3D=3D?= Content-ID: <77E6C311CA0A814AA5B5E49E976390A3@eurprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13aee429-ce8d-4786-1bb8-08dba8e66d44 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:42.1113 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1sr2BEAmCzL7Q2pEEbokTFEdlPRV+3ZkNdmeMwKh5gUgQnaXZg7VUVqWlJQLN6jJbBWksvWkrzVgGYhMVAk6kJAvyej4oXDy4FITDnorjII= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: ycFgeegD8pR__ThYRAgrZ-974DDffhRk X-Proofpoint-GUID: ycFgeegD8pR__ThYRAgrZ-974DDffhRk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 Add per-domain d->pci_lock that protects access to d->pdev_list. Purpose of this lock is to give guarantees to VPCI code that underlying pdev will not disappear under feet. This is a rw-lock, but this patch adds only write_lock()s. There will be read_lock() users in the next patches. This lock should be taken in write mode every time d->pdev_list is altered. This covers both accesses to d->pdev_list and accesses to pdev->domain_list fields. All write accesses also should be protected by pcidevs_lock() as well. Idea is that any user that wants read access to the list or to the devices stored in the list should use either this new d->pci_lock or old pcidevs_lock(). Usage of any of this two locks will ensure only that pdev of interest will not disappear from under feet and that the pdev still will be assigned to the same domain. Of course, any new users should use pcidevs_lock() when it is appropriate (e.g. when accessing any other state that is protected by the said lock). In case both the newly introduced per-domain rwlock and the pcidevs lock is taken, the later must be acquired first. Any write access to pdev->domain_list should be protected by both pcidevs_lock() and d->pci_lock in the write mode. Suggested-by: Roger Pau Monné Suggested-by: Jan Beulich Signed-off-by: Volodymyr Babchuk --- Changes in v9: - returned back "pdev->domain = target;" in AMD IOMMU code - used "source" instead of pdev->domain in IOMMU functions - added comment about lock ordering in the commit message - reduced locked regions - minor changes non-functional changes in various places Changes in v8: - New patch Changes in v8 vs RFC: - Removed all read_locks after discussion with Roger in #xendevel - pci_release_devices() now returns the first error code - extended commit message - added missing lock in pci_remove_device() - extended locked region in pci_add_device() to protect list_del() calls --- xen/common/domain.c | 1 + xen/drivers/passthrough/amd/pci_amd_iommu.c | 9 ++- xen/drivers/passthrough/pci.c | 71 +++++++++++++++++---- xen/drivers/passthrough/vtd/iommu.c | 9 ++- xen/include/xen/sched.h | 1 + 5 files changed, 78 insertions(+), 13 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 304aa04fa6..9b04a20160 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -651,6 +651,7 @@ struct domain *domain_create(domid_t domid, #ifdef CONFIG_HAS_PCI INIT_LIST_HEAD(&d->pdev_list); + rwlock_init(&d->pci_lock); #endif /* All error paths can depend on the above setup. */ diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index bea70db4b7..d219bd9453 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -476,7 +476,14 @@ static int cf_check reassign_device( if ( devfn == pdev->devfn && pdev->domain != target ) { - list_move(&pdev->domain_list, &target->pdev_list); + write_lock(&source->pci_lock); + list_del(&pdev->domain_list); + write_unlock(&source->pci_lock); + + write_lock(&target->pci_lock); + list_add(&pdev->domain_list, &target->pdev_list); + write_unlock(&target->pci_lock); + pdev->domain = target; } diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 33452791a8..79ca928672 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -454,7 +454,9 @@ static void __init _pci_hide_device(struct pci_dev *pdev) if ( pdev->domain ) return; pdev->domain = dom_xen; + write_lock(&dom_xen->pci_lock); list_add(&pdev->domain_list, &dom_xen->pdev_list); + write_unlock(&dom_xen->pci_lock); } int __init pci_hide_device(unsigned int seg, unsigned int bus, @@ -748,7 +750,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( !pdev->domain ) { pdev->domain = hardware_domain; + write_lock(&hardware_domain->pci_lock); list_add(&pdev->domain_list, &hardware_domain->pdev_list); + write_unlock(&hardware_domain->pci_lock); /* * For devices not discovered by Xen during boot, add vPCI handlers @@ -758,7 +762,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + write_lock(&hardware_domain->pci_lock); list_del(&pdev->domain_list); + write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; goto out; } @@ -766,7 +772,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { vpci_remove_device(pdev); + write_lock(&hardware_domain->pci_lock); list_del(&pdev->domain_list); + write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; goto out; } @@ -816,7 +824,11 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) pci_cleanup_msi(pdev); ret = iommu_remove_device(pdev); if ( pdev->domain ) + { + write_lock(&pdev->domain->pci_lock); list_del(&pdev->domain_list); + write_unlock(&pdev->domain->pci_lock); + } printk(XENLOG_DEBUG "PCI remove device %pp\n", &pdev->sbdf); free_pdev(pseg, pdev); break; @@ -887,26 +899,61 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, int pci_release_devices(struct domain *d) { - struct pci_dev *pdev, *tmp; - u8 bus, devfn; - int ret; + int combined_ret; + LIST_HEAD(failed_pdevs); pcidevs_lock(); - ret = arch_pci_clean_pirqs(d); - if ( ret ) + + combined_ret = arch_pci_clean_pirqs(d); + if ( combined_ret ) { pcidevs_unlock(); - return ret; + return combined_ret; } - list_for_each_entry_safe ( pdev, tmp, &d->pdev_list, domain_list ) + + write_lock(&d->pci_lock); + + while ( !list_empty(&d->pdev_list) ) { - bus = pdev->bus; - devfn = pdev->devfn; - ret = deassign_device(d, pdev->seg, bus, devfn) ?: ret; + struct pci_dev *pdev = list_first_entry(&d->pdev_list, + struct pci_dev, + domain_list); + uint16_t seg = pdev->seg; + uint8_t bus = pdev->bus; + uint8_t devfn = pdev->devfn; + int ret; + + write_unlock(&d->pci_lock); + ret = deassign_device(d, seg, bus, devfn); + write_lock(&d->pci_lock); + if ( ret ) + { + const struct pci_dev *tmp; + + /* + * We need to check if deassign_device() left our pdev in + * domain's list. As we dropped the lock, we can't be sure + * that list wasn't permutated in some random way, so we + * need to traverse the whole list. + */ + for_each_pdev ( d, tmp ) + { + if ( tmp == pdev ) + { + list_move_tail(&pdev->domain_list, &failed_pdevs); + break; + } + } + + combined_ret = combined_ret ?: ret; + } } + + list_splice(&failed_pdevs, &d->pdev_list); + write_unlock(&d->pci_lock); pcidevs_unlock(); - return ret; + return combined_ret; } #define PCI_CLASS_BRIDGE_HOST 0x0600 @@ -1125,7 +1172,9 @@ static int __hwdom_init cf_check _setup_hwdom_pci_devices( if ( !pdev->domain ) { pdev->domain = ctxt->d; + write_lock(&ctxt->d->pci_lock); list_add(&pdev->domain_list, &ctxt->d->pdev_list); + write_unlock(&ctxt->d->pci_lock); setup_one_hwdom_device(ctxt, pdev); } else if ( pdev->domain == dom_xen ) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index 0e3062c820..3228900c97 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2806,7 +2806,14 @@ static int cf_check reassign_device_ownership( if ( devfn == pdev->devfn && pdev->domain != target ) { - list_move(&pdev->domain_list, &target->pdev_list); + write_lock(&source->pci_lock); + list_del(&pdev->domain_list); + write_unlock(&source->pci_lock); + + write_lock(&target->pci_lock); + list_add(&pdev->domain_list, &target->pdev_list); + write_unlock(&target->pci_lock); + pdev->domain = target; } diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index b4f43cd410..535a81fe90 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -460,6 +460,7 @@ struct domain #ifdef CONFIG_HAS_PCI struct list_head pdev_list; + rwlock_t pci_lock; #endif #ifdef CONFIG_HAS_PASSTHROUGH From patchwork Tue Aug 29 23:19:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369789 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 A8FEAC83F18 for ; Tue, 29 Aug 2023 23:20:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592511.925264 (Exim 4.92) (envelope-from ) id 1qb808-0007V4-53; Tue, 29 Aug 2023 23:20:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592511.925264; Tue, 29 Aug 2023 23:20:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb808-0007Uw-0V; Tue, 29 Aug 2023 23:20:00 +0000 Received: by outflank-mailman (input) for mailman id 592511; Tue, 29 Aug 2023 23:19:58 +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 1qb806-0006kQ-7h for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:58 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8febe2ce-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:19:55 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9j021983; Tue, 29 Aug 2023 23:19:51 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:51 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:43 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19: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: 8febe2ce-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SypQwkUbvN/L1vdbszievjyluja2bV3l0pj0lkLyfo7W5ADzSahuX8raESuYvVnBjrIyAaB62hSA+3eri8gGBWCj2ebqwAsjtwJ6qBa62QLpi2/SsKd7y68qqajf+s4U7r/RMe05D/KmjmefKQkMPyv+lxMp2NKBfkQfs0B2iErIr7wg22hdhmoCnZrwOZipoidhESYihesOs2s8YB/0p0il/mU9UTJ7IGJ81SumylzQ7XGwIRxhWOjMu3CbUXFUvqwV+E9jpaqOLdSuIdZlkD00WRKGCJJCwQt3B/bpMeP3ophYOJUzhkHhkTAiYDa3WBGdyCiUu+RKgs2kWt59Nw== 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=imFiRlRgcy7VyVgiEylGKNGZs2FbczvBHx5r958a0tE=; b=RAxX74TuSGGpWvvyFGflCn+Rl8o+Q13OMUlV5l93h6eLn4miLk9MSves1fp8BF4sIrrsBX/Hju81X1s3yIVh4FX5M2Hh4curz9RmQmtD7KFkdeQxnm7nVCXsYTrFbTat/WfT+yPAaJS+oCYJe5A9I9EaoJgftVU776zitQVw8fMExjnzGm/wKBLrzUWt6UPMD5SVZbUZqyZzVCxRgWJlmwFhhA5ocCuw4ypwezecMflqJwcuZhKG7RDGLYpDE/niqDVkfYJB4CKgkIdFm0Q+h5jfNuIQnqWp2cnN0JJl/OgQPBBHWnOOT3LY/yO7OvpAkEE3KYqvntz8U/bmT6GM6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=imFiRlRgcy7VyVgiEylGKNGZs2FbczvBHx5r958a0tE=; b=RGYMcy2eytKPGBT5BQ7jLhlcxY5nIFpgLUdjZTM7592fp2FZJuMLFpBf0cBczqUDT2oq9MFhBDiYm3/lZUvdFHTAEyGuXHw0ifl8zHFviPM8WwiHHyZX6je20qX5jML9WKhMS4/S2+z7GaLXof34F6XpU5+MxjiOhediTQG1aCxl3ZDjZu9MtWlXs9H/x1TPxlB4kZvdvsVWOOrAykJy3YfwPbqafRXTJTKEbi4C/Z2De7G5NU4WFki+3cuPlQzwn3FcYaOoDfBrknIL8lCnlP2GGMhpJne6yclNv1wkYJtDdaQllXZIN3HPt9Jcll9V286kXP9t94fcANKOd7JYow== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , Paul Durrant , Volodymyr Babchuk Subject: [PATCH v9 02/16] vpci: use per-domain PCI lock to protect vpci structure Thread-Topic: [PATCH v9 02/16] vpci: use per-domain PCI lock to protect vpci structure Thread-Index: AQHZ2s9KfUsugiaE80OWAJ/SuT82fA== Date: Tue, 29 Aug 2023 23:19:42 +0000 Message-ID: <20230829231912.4091958-3-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 3c7aa324-2cd4-4e57-048c-08dba8e66d6f x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: s6ra7aw/SB+PYiz/jSl5rWWLCyYH4QM5wxKab9OVD0s3YVy/MCmCY+Zm8/wORY2/r//0VRUTM8lEx+5HehtUkJn9PpAZvdwl0P7J5PJQv7b7ybGZ7jOZBxFlvz8O7jg7+JqT97xybz7bmnNj+FmMXwA/k9U8UTJcv50rNU0sa4RiSpz/LYYCKISdiVRV/jR59piEhqsh50yIfMRMHj9BHyW1NPh25FvHslh+oY2D6e2g1dCp0tYR7TAPyuonSOJ4dDEFzrXADzcM7gDYMu+lDcjYFez23JvM0yVBItrpP6LmurMjtxCBfGmO44j/b2bMhzR+5BAOJLO3axrrGPqHL3fTlJsSdgI8gzp8rKulD6rpAJqDgrwz0c+m7dnX5h+evKlRDl75ezgVMGtj6Mfk+E5tnJOWoDwp4X5OzVqVgTIzMh3J0sYBWst1EvId8qILvumi4En/F3Z8Vn4kNioH2KbNyZAXe6+hEDQoNN661m1876huYgdTLVeRjE34pzfwkZhbZhWp7wlTesoNI3EgsfRT2JuvPrWU/9FNaBITjcZdtnNvOUfTVgF7TbAyNyvZsMcfmF+ffbIlumTWn16IRR6knTIBJsZo5Z7fcsHG21976OvNgZwW94qb2IjWcNj/AX0DFl0dKxRku7wllZgcug== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(107886003)(26005)(30864003)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001)(579004)(559001)(309714004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?9KKw/NdKso0T6oYdqHjyqkfiM/+D?= =?utf-8?q?4fcOWKNyN4ZTW8CmivQKqtedYyG2/jMhbHg4UY6ZJjpHKThVS3fFeGpD7kxQkED/l?= =?utf-8?q?x2h+GFPiZG6kthkd9SE/XtMaSKSvGUsp3DNWMKcK8UKyQ5T7YKMRdB0x23EAzL+uh?= =?utf-8?q?Z0XEMjzuTpv0+bYg37dH9tlKX8jg79b9GB8goRGgRpPNaDf2/hK1TEavE2Vk6dvV1?= =?utf-8?q?8X7QGC7ddGTJJ16KK74Uz7F0L/Ilv2ErWrE4LPsCm/Bu+ojV/HOJEL7MlfNas/L0Q?= =?utf-8?q?QmUu3oMDUQsfgwCcW2309SRe1UWI7Cnc37klMpRTiahaLDSCFPyNzpuBJXbuYy8aA?= =?utf-8?q?Mpj8bGfoPuGCUUJU/XfCt8Zuaj2fR/NjSQxl9kmBR9n9NBisN6K17V7d/1s3HL151?= =?utf-8?q?gD/a++1zArAtWi5RL/6BlOcubtBQb71mSNnYIXUyVwoT32PJjwnli9s8ZQzvq2qZs?= =?utf-8?q?7OkHvDrl8hViSM0mH/40WWURAIQ4senqq5UPIQeYSsp+cJQsRdGu34bj2ZOtX/YTZ?= =?utf-8?q?eFku/kOpALj7i8MNTHthWKTC3mquD9ks8f7p2208xQBKHSLvZHWl1Vv3RNIvbBQYx?= =?utf-8?q?UqC+AELlMQDZMAbVP/RxDP+EJEUY4BaMUxyVAEjD/1phkLpFG37TV8oK8e3BTQq9E?= =?utf-8?q?82F5b+5LT9SvgHn3oDn4jjj64VXwiXyyLIL/qCt1F46gviB7/aJ+ZIV2TBPXLgouV?= =?utf-8?q?auWG/D8jwHa5lc78/nVIgbMVwRDpbXaiBOTNiY36B/LnW/ENtISBeHomYxEny0H5y?= =?utf-8?q?cututqi16QXhFab+xKVX1IyvJUfbvvG0M5Fv/Wb4I/gd6ESN1XsKYqlJWorVPSiDS?= =?utf-8?q?LM+3dIF6pkxLEoktt+LTURZY8xbuXxTIHztInEca16pn4LxAYADrra2divy5zN1G1?= =?utf-8?q?Tm0agWaySxChmPmWAm0edkT5TOoCuuHBh5bJ1nGTtHQnU+yVyAnuUSsENmSYNFAhm?= =?utf-8?q?+gLD47a5Kid8lJMq7yhhWKJj75PQJL7mt9gShY/2HyNqrJv7wWi18BJURkKaP3TdJ?= =?utf-8?q?c3t/WjtxRYiUSvPIX58HgtgzBnA7WsTdcd6FSlPEqtS7R3sM0maDcjwjKjse2Lkc/?= =?utf-8?q?k9pJKGW05HamVn3fK/tsADx4qsnV3NUyOmkCyAAIa9wje304g2DY0ZAhE1ys9XWlP?= =?utf-8?q?V262q9xGg9EfuUJNwGln8eL7f7NGez6JQ2GdUXJHdwQxWwl3OHEfLUowv4SEMiION?= =?utf-8?q?YmyQMxyQ56Sazpy2mDOeO4l/QBISToJm+h/IJPfqFUOmC3DyPw8qc1Qw8XMV83+cc?= =?utf-8?q?1+uGlIIepRIyqlok1tgiKkQHCnJdvQYrzgYvtFF+bs0MyCDZZU2ZPd9FYpVwid8QK?= =?utf-8?q?fu+PSiksQJRKfrTgmimzyrLtbRV32GXGOPiQcQp6I5cmPIeLtcKTfaSWvJC5it+lA?= =?utf-8?q?zltjnGS39260F9oTD7+qEIjnemJRzKjV3GN3z4tIbwJ8lzsgxX8flUEpJIDqyQI+b?= =?utf-8?q?UR7BgrWrsEilbSt+9tOjARpuuKqUs+KYbO84MTQHF8CjKmc0H2R9DJ1ISW92e4Jjg?= =?utf-8?q?Ur/JeekjXZ7EzyQxys4LrRbTIeXk2ZuDNQ=3D=3D?= Content-ID: <90ED5F819900094BAF58E78EF2256F4A@eurprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c7aa324-2cd4-4e57-048c-08dba8e66d6f X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:42.5516 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: vYSH1s2xuPIdaVuLe+AZfChUxr3GblPmZEdl9oNHRY9+lhuut82wBQ7spWRfwIKWAtulSDQJfmbg1/2xq7Tgob03b/0woHQtpMtyO0gUwfo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: -ghOakbpgbfx8hINmWIrtmmpUk9Z7vWS X-Proofpoint-GUID: -ghOakbpgbfx8hINmWIrtmmpUk9Z7vWS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Use a previously introduced per-domain read/write lock to check whether vpci is present, so we are sure there are no accesses to the contents of the vpci struct if not. This lock can be used (and in a few cases is used right away) so that vpci removal can be performed while holding the lock in write mode. Previously such removal could race with vpci_read for example. When taking both d->pci_lock and pdev->vpci->lock they are should be taken in this exact order: d->pci_lock then pdev->vpci->lock to avoid possible deadlock situations. 1. Per-domain's pci_rwlock is used to protect pdev->vpci structure from being removed. 2. Writing the command register and ROM BAR register may trigger modify_bars to run, which in turn may access multiple pdevs while checking for the existing BAR's overlap. The overlapping check, if done under the read lock, requires vpci->lock to be acquired on both devices being compared, which may produce a deadlock. It is not possible to upgrade read lock to write lock in such a case. So, in order to prevent the deadlock, use d->pci_lock instead. To prevent deadlock while locking both hwdom->pci_lock and dom_xen->pci_lock, always lock hwdom first. All other code, which doesn't lead to pdev->vpci destruction and does not access multiple pdevs at the same time, can still use a combination of the read lock and pdev->vpci->lock. 3. Drop const qualifier where the new rwlock is used and this is appropriate. 4. Do not call process_pending_softirqs with any locks held. For that unlock prior the call and re-acquire the locks after. After re-acquiring the lock there is no need to check if pdev->vpci exists: - in apply_map because of the context it is called (no race condition possible) - for MSI/MSI-X debug code because it is called at the end of pdev->vpci access and no further access to pdev->vpci is made 5. Use d->pci_lock around for_each_pdev and pci_get_pdev_by_domain while accessing pdevs in vpci code. There is a possible lock inversion in MSI code, as some parts of it acquire pcidevs_lock() while already holding d->pci_lock. Suggested-by: Roger Pau Monné Suggested-by: Jan Beulich Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- Changes in v9: - extended locked region to protect vpci_remove_device and vpci_add_handlers() calls - vpci_write() takes lock in the write mode to protect potential call to modify_bars() - renamed lock releasing function - removed ASSERT()s from msi code - added trylock in vpci_dump_msi Changes in v8: - changed d->vpci_lock to d->pci_lock - introducing d->pci_lock in a separate patch - extended locked region in vpci_process_pending - removed pcidevs_lockis vpci_dump_msi() - removed some changes as they are not needed with the new locking scheme - added handling for hwdom && dom_xen case --- xen/arch/x86/hvm/vmsi.c | 24 ++++++++-------- xen/arch/x86/hvm/vmx/vmx.c | 2 -- xen/arch/x86/irq.c | 15 +++++++--- xen/arch/x86/msi.c | 8 ++---- xen/drivers/passthrough/pci.c | 7 +++-- xen/drivers/vpci/header.c | 18 ++++++++++++ xen/drivers/vpci/msi.c | 22 +++++++++++++-- xen/drivers/vpci/msix.c | 52 ++++++++++++++++++++++++++++++----- xen/drivers/vpci/vpci.c | 46 +++++++++++++++++++++++++++++-- 9 files changed, 154 insertions(+), 40 deletions(-) diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index 128f236362..fde76cc6b4 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -468,7 +468,7 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable) struct msixtbl_entry *entry, *new_entry; int r = -EINVAL; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ASSERT(rw_is_write_locked(&d->event_lock)); if ( !msixtbl_initialised(d) ) @@ -538,7 +538,7 @@ void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq) struct pci_dev *pdev; struct msixtbl_entry *entry; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ASSERT(rw_is_write_locked(&d->event_lock)); if ( !msixtbl_initialised(d) ) @@ -684,7 +684,7 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data, { unsigned int i; - ASSERT(pcidevs_locked()); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); if ( (address & MSI_ADDR_BASE_MASK) != MSI_ADDR_HEADER ) { @@ -725,8 +725,8 @@ void vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev) int rc; ASSERT(msi->arch.pirq != INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); - pcidevs_lock(); for ( i = 0; i < msi->vectors && msi->arch.bound; i++ ) { struct xen_domctl_bind_pt_irq unbind = { @@ -745,7 +745,6 @@ void vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev) msi->arch.bound = !vpci_msi_update(pdev, msi->data, msi->address, msi->vectors, msi->arch.pirq, msi->mask); - pcidevs_unlock(); } static int vpci_msi_enable(const struct pci_dev *pdev, unsigned int nr, @@ -778,15 +777,13 @@ int vpci_msi_arch_enable(struct vpci_msi *msi, const struct pci_dev *pdev, int rc; ASSERT(msi->arch.pirq == INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); rc = vpci_msi_enable(pdev, vectors, 0); if ( rc < 0 ) return rc; msi->arch.pirq = rc; - - pcidevs_lock(); msi->arch.bound = !vpci_msi_update(pdev, msi->data, msi->address, vectors, msi->arch.pirq, msi->mask); - pcidevs_unlock(); return 0; } @@ -797,8 +794,8 @@ static void vpci_msi_disable(const struct pci_dev *pdev, int pirq, unsigned int i; ASSERT(pirq != INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); - pcidevs_lock(); for ( i = 0; i < nr && bound; i++ ) { struct xen_domctl_bind_pt_irq bind = { @@ -814,7 +811,6 @@ static void vpci_msi_disable(const struct pci_dev *pdev, int pirq, write_lock(&pdev->domain->event_lock); unmap_domain_pirq(pdev->domain, pirq); write_unlock(&pdev->domain->event_lock); - pcidevs_unlock(); } void vpci_msi_arch_disable(struct vpci_msi *msi, const struct pci_dev *pdev) @@ -854,6 +850,8 @@ int vpci_msix_arch_enable_entry(struct vpci_msix_entry *entry, int rc; ASSERT(entry->arch.pirq == INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); + rc = vpci_msi_enable(pdev, vmsix_entry_nr(pdev->vpci->msix, entry), table_base); if ( rc < 0 ) @@ -861,7 +859,6 @@ int vpci_msix_arch_enable_entry(struct vpci_msix_entry *entry, entry->arch.pirq = rc; - pcidevs_lock(); rc = vpci_msi_update(pdev, entry->data, entry->addr, 1, entry->arch.pirq, entry->masked); if ( rc ) @@ -869,7 +866,6 @@ int vpci_msix_arch_enable_entry(struct vpci_msix_entry *entry, vpci_msi_disable(pdev, entry->arch.pirq, 1, false); entry->arch.pirq = INVALID_PIRQ; } - pcidevs_unlock(); return rc; } @@ -895,6 +891,8 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) { unsigned int i; + ASSERT(rw_is_locked(&msix->pdev->domain->pci_lock)); + for ( i = 0; i < msix->max_entries; i++ ) { const struct vpci_msix_entry *entry = &msix->entries[i]; @@ -913,7 +911,9 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) struct pci_dev *pdev = msix->pdev; spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&pdev->domain->pci_lock); process_pending_softirqs(); + read_lock(&pdev->domain->pci_lock); /* NB: we assume that pdev cannot go away for an alive domain. */ if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) ) return -EBUSY; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 1edc7f1e91..545a27796e 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -413,8 +413,6 @@ static int cf_check vmx_pi_update_irte(const struct vcpu *v, spin_unlock_irq(&desc->lock); - ASSERT(pcidevs_locked()); - return iommu_update_ire_from_msi(msi_desc, &msi_desc->msg); unlock_out: diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 6abfd81621..cb99ae5392 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -2157,7 +2157,7 @@ int map_domain_pirq( struct pci_dev *pdev; unsigned int nr = 0; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ret = -ENODEV; if ( !cpu_has_apic ) @@ -2314,7 +2314,7 @@ int unmap_domain_pirq(struct domain *d, int pirq) if ( (pirq < 0) || (pirq >= d->nr_pirqs) ) return -EINVAL; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ASSERT(rw_is_write_locked(&d->event_lock)); info = pirq_info(d, pirq); @@ -2908,7 +2908,13 @@ int allocate_and_map_msi_pirq(struct domain *d, int index, int *pirq_p, msi->irq = irq; - pcidevs_lock(); + /* + * If we are called via vPCI->vMSI path, we already are holding + * d->pci_lock so there is no need to take pcidevs_lock, as it + * will cause lock inversion. + */ + if ( !rw_is_locked(&d->pci_lock) ) + pcidevs_lock(); /* Verify or get pirq. */ write_lock(&d->event_lock); pirq = allocate_pirq(d, index, *pirq_p, irq, type, &msi->entry_nr); @@ -2924,7 +2930,8 @@ int allocate_and_map_msi_pirq(struct domain *d, int index, int *pirq_p, done: write_unlock(&d->event_lock); - pcidevs_unlock(); + if ( !rw_is_locked(&d->pci_lock) ) + pcidevs_unlock(); if ( ret ) { switch ( type ) diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index d0bf63df1d..ba2963b7d2 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -613,7 +613,7 @@ static int msi_capability_init(struct pci_dev *dev, u8 slot = PCI_SLOT(dev->devfn); u8 func = PCI_FUNC(dev->devfn); - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&dev->domain->pci_lock)); pos = pci_find_cap_offset(seg, bus, slot, func, PCI_CAP_ID_MSI); if ( !pos ) return -ENODEV; @@ -783,7 +783,7 @@ static int msix_capability_init(struct pci_dev *dev, if ( !pos ) return -ENODEV; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&dev->domain->pci_lock)); control = pci_conf_read16(dev->sbdf, msix_control_reg(pos)); /* @@ -1000,7 +1000,6 @@ static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc) struct pci_dev *pdev; struct msi_desc *old_desc; - ASSERT(pcidevs_locked()); pdev = pci_get_pdev(NULL, msi->sbdf); if ( !pdev ) return -ENODEV; @@ -1055,7 +1054,6 @@ static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc) struct pci_dev *pdev; struct msi_desc *old_desc; - ASSERT(pcidevs_locked()); pdev = pci_get_pdev(NULL, msi->sbdf); if ( !pdev || !pdev->msix ) return -ENODEV; @@ -1170,8 +1168,6 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off) */ int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc) { - ASSERT(pcidevs_locked()); - if ( !use_msi ) return -EPERM; diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 79ca928672..4f18293900 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -752,7 +752,6 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain = hardware_domain; write_lock(&hardware_domain->pci_lock); list_add(&pdev->domain_list, &hardware_domain->pdev_list); - write_unlock(&hardware_domain->pci_lock); /* * For devices not discovered by Xen during boot, add vPCI handlers @@ -762,17 +761,17 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); - write_lock(&hardware_domain->pci_lock); list_del(&pdev->domain_list); write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; goto out; } + write_unlock(&hardware_domain->pci_lock); ret = iommu_add_device(pdev); if ( ret ) { - vpci_remove_device(pdev); write_lock(&hardware_domain->pci_lock); + vpci_remove_device(pdev); list_del(&pdev->domain_list); write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; @@ -1147,7 +1146,9 @@ static void __hwdom_init setup_one_hwdom_device(const struct setup_hwdom *ctxt, } while ( devfn != pdev->devfn && PCI_SLOT(devfn) == PCI_SLOT(pdev->devfn) ); + write_lock(&ctxt->d->pci_lock); err = vpci_add_handlers(pdev); + write_unlock(&ctxt->d->pci_lock); if ( err ) printk(XENLOG_ERR "setup of vPCI for d%d failed: %d\n", ctxt->d->domain_id, err); diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 60f7049e34..177a6b57a5 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -172,6 +172,7 @@ bool vpci_process_pending(struct vcpu *v) if ( rc == -ERESTART ) return true; + write_lock(&v->domain->pci_lock); spin_lock(&v->vpci.pdev->vpci->lock); /* Disable memory decoding unconditionally on failure. */ modify_decoding(v->vpci.pdev, @@ -190,6 +191,7 @@ bool vpci_process_pending(struct vcpu *v) * failure. */ vpci_remove_device(v->vpci.pdev); + write_unlock(&v->domain->pci_lock); } return false; @@ -201,8 +203,20 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, struct map_data data = { .d = d, .map = true }; int rc; + ASSERT(rw_is_locked(&d->pci_lock)); + while ( (rc = rangeset_consume_ranges(mem, map_range, &data)) == -ERESTART ) + { + /* + * It's safe to drop and reacquire the lock in this context + * without risking pdev disappearing because devices cannot be + * removed until the initial domain has been started. + */ + read_unlock(&d->pci_lock); process_pending_softirqs(); + read_lock(&d->pci_lock); + } + rangeset_destroy(mem); if ( !rc ) modify_decoding(pdev, cmd, false); @@ -243,6 +257,8 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) unsigned int i; int rc; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + if ( !mem ) return -ENOMEM; @@ -522,6 +538,8 @@ static int cf_check init_bars(struct pci_dev *pdev) struct vpci_bar *bars = header->bars; int rc; + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); + switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f ) { case PCI_HEADER_TYPE_NORMAL: diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index 8f2b59e61a..a0733bb2cb 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -265,7 +265,7 @@ REGISTER_VPCI_INIT(init_msi, VPCI_PRIORITY_LOW); void vpci_dump_msi(void) { - const struct domain *d; + struct domain *d; rcu_read_lock(&domlist_read_lock); for_each_domain ( d ) @@ -277,6 +277,9 @@ void vpci_dump_msi(void) printk("vPCI MSI/MSI-X d%d\n", d->domain_id); + if ( !read_trylock(&d->pci_lock) ) + continue; + for_each_pdev ( d, pdev ) { const struct vpci_msi *msi; @@ -318,15 +321,28 @@ void vpci_dump_msi(void) * holding the lock. */ printk("unable to print all MSI-X entries: %d\n", rc); - process_pending_softirqs(); - continue; + goto pdev_done; } } spin_unlock(&pdev->vpci->lock); + pdev_done: + /* + * Unlock lock to process pending softirqs. This is + * potentially unsafe, as d->pdev_list can be changed in + * meantime. + */ + read_unlock(&d->pci_lock); process_pending_softirqs(); + if ( !read_trylock(&d->pci_lock) ) + { + printk("unable to access other devices for the domain\n"); + goto domain_done; + } } + read_unlock(&d->pci_lock); } + domain_done: rcu_read_unlock(&domlist_read_lock); } diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index f9df506f29..f8c5bd393b 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -147,6 +147,8 @@ static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr) { struct vpci_msix *msix; + ASSERT(rw_is_locked(&d->pci_lock)); + list_for_each_entry ( msix, &d->arch.hvm.msix_tables, next ) { const struct vpci_bar *bars = msix->pdev->vpci->header.bars; @@ -163,7 +165,13 @@ static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr) static int cf_check msix_accept(struct vcpu *v, unsigned long addr) { - return !!msix_find(v->domain, addr); + int rc; + + read_lock(&v->domain->pci_lock); + rc = !!msix_find(v->domain, addr); + read_unlock(&v->domain->pci_lock); + + return rc; } static bool access_allowed(const struct pci_dev *pdev, unsigned long addr, @@ -358,21 +366,35 @@ static int adjacent_read(const struct domain *d, const struct vpci_msix *msix, static int cf_check msix_read( struct vcpu *v, unsigned long addr, unsigned int len, unsigned long *data) { - const struct domain *d = v->domain; - struct vpci_msix *msix = msix_find(d, addr); + struct domain *d = v->domain; + struct vpci_msix *msix; const struct vpci_msix_entry *entry; unsigned int offset; *data = ~0ul; + read_lock(&d->pci_lock); + + msix = msix_find(d, addr); if ( !msix ) + { + read_unlock(&d->pci_lock); return X86EMUL_RETRY; + } if ( adjacent_handle(msix, addr) ) - return adjacent_read(d, msix, addr, len, data); + { + int rc = adjacent_read(d, msix, addr, len, data); + + read_unlock(&d->pci_lock); + return rc; + } if ( !access_allowed(msix->pdev, addr, len) ) + { + read_unlock(&d->pci_lock); return X86EMUL_OKAY; + } spin_lock(&msix->pdev->vpci->lock); entry = get_entry(msix, addr); @@ -404,6 +426,7 @@ static int cf_check msix_read( break; } spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&d->pci_lock); return X86EMUL_OKAY; } @@ -491,19 +514,33 @@ static int adjacent_write(const struct domain *d, const struct vpci_msix *msix, static int cf_check msix_write( struct vcpu *v, unsigned long addr, unsigned int len, unsigned long data) { - const struct domain *d = v->domain; - struct vpci_msix *msix = msix_find(d, addr); + struct domain *d = v->domain; + struct vpci_msix *msix; struct vpci_msix_entry *entry; unsigned int offset; + read_lock(&d->pci_lock); + + msix = msix_find(d, addr); if ( !msix ) + { + read_unlock(&d->pci_lock); return X86EMUL_RETRY; + } if ( adjacent_handle(msix, addr) ) - return adjacent_write(d, msix, addr, len, data); + { + int rc = adjacent_write(d, msix, addr, len, data); + + read_unlock(&d->pci_lock); + return rc; + } if ( !access_allowed(msix->pdev, addr, len) ) + { + read_unlock(&d->pci_lock); return X86EMUL_OKAY; + } spin_lock(&msix->pdev->vpci->lock); entry = get_entry(msix, addr); @@ -579,6 +616,7 @@ static int cf_check msix_write( break; } spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&d->pci_lock); return X86EMUL_OKAY; } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index d73fa76302..34fff2ef2d 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -38,6 +38,8 @@ extern vpci_register_init_t *const __end_vpci_array[]; void vpci_remove_device(struct pci_dev *pdev) { + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + if ( !has_vpci(pdev->domain) || !pdev->vpci ) return; @@ -73,6 +75,8 @@ int vpci_add_handlers(struct pci_dev *pdev) const unsigned long *ro_map; int rc = 0; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + if ( !has_vpci(pdev->domain) ) return 0; @@ -326,11 +330,12 @@ static uint32_t merge_result(uint32_t data, uint32_t new, unsigned int size, uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) { - const struct domain *d = current->domain; + struct domain *d = current->domain; const struct pci_dev *pdev; const struct vpci_register *r; unsigned int data_offset = 0; uint32_t data = ~(uint32_t)0; + rwlock_t *lock; if ( !size ) { @@ -342,11 +347,21 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) * Find the PCI dev matching the address, which for hwdom also requires * consulting DomXEN. Passthrough everything that's not trapped. */ + lock = &d->pci_lock; + read_lock(lock); pdev = pci_get_pdev(d, sbdf); if ( !pdev && is_hardware_domain(d) ) + { + read_unlock(lock); + lock = &dom_xen->pci_lock; + read_lock(lock); pdev = pci_get_pdev(dom_xen, sbdf); + } if ( !pdev || !pdev->vpci ) + { + read_unlock(lock); return vpci_read_hw(sbdf, reg, size); + } spin_lock(&pdev->vpci->lock); @@ -392,6 +407,7 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) ASSERT(data_offset < size); } spin_unlock(&pdev->vpci->lock); + read_unlock(lock); if ( data_offset < size ) { @@ -431,10 +447,23 @@ static void vpci_write_helper(const struct pci_dev *pdev, r->private); } +/* Helper function to unlock locks taken by vpci_write in proper order */ +static void release_domain_locks(struct domain *d) +{ + ASSERT(rw_is_write_locked(&d->pci_lock)); + + if ( is_hardware_domain(d) ) + { + ASSERT(rw_is_write_locked(&dom_xen->pci_lock)); + write_unlock(&dom_xen->pci_lock); + } + write_unlock(&d->pci_lock); +} + void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, uint32_t data) { - const struct domain *d = current->domain; + struct domain *d = current->domain; const struct pci_dev *pdev; const struct vpci_register *r; unsigned int data_offset = 0; @@ -447,8 +476,16 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, /* * Find the PCI dev matching the address, which for hwdom also requires - * consulting DomXEN. Passthrough everything that's not trapped. + * consulting DomXEN. Passthrough everything that's not trapped. + * If this is hwdom, we need to hold locks for both domain in case if + * modify_bars() is called */ + write_lock(&d->pci_lock); + + /* dom_xen->pci_lock always should be taken second to prevent deadlock */ + if ( is_hardware_domain(d) ) + write_lock(&dom_xen->pci_lock); + pdev = pci_get_pdev(d, sbdf); if ( !pdev && is_hardware_domain(d) ) pdev = pci_get_pdev(dom_xen, sbdf); @@ -459,6 +496,8 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, if ( !ro_map || !test_bit(sbdf.bdf, ro_map) ) vpci_write_hw(sbdf, reg, size, data); + + release_domain_locks(d); return; } @@ -498,6 +537,7 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, ASSERT(data_offset < size); } spin_unlock(&pdev->vpci->lock); + release_domain_locks(d); if ( data_offset < size ) /* Tailing gap, write the remaining. */ From patchwork Tue Aug 29 23:19:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369798 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 E0F22C83F19 for ; Tue, 29 Aug 2023 23:20:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592508.925234 (Exim 4.92) (envelope-from ) id 1qb804-0006ki-3h; Tue, 29 Aug 2023 23:19:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592508.925234; Tue, 29 Aug 2023 23:19:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb804-0006kb-06; Tue, 29 Aug 2023 23:19:56 +0000 Received: by outflank-mailman (input) for mailman id 592508; Tue, 29 Aug 2023 23:19:55 +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 1qb803-0006kQ-0T for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:55 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8d570ca5-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:19:51 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9f021983; Tue, 29 Aug 2023 23:19:48 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:47 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:43 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19: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: 8d570ca5-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yb8bctkTG9C4wzoqZGcx3fQI+wXfN/+KWBTmmJxhRIuZ3FdpPAlOmiJy2fDW7D9lBpYzbuCxhIMOAk6d5BvilBRaY/SqtejXPoBBJprm2nvpznvi8RO4bIn+KMAC+qJrh49Q9w9FWF0yCEUZw9nSSMAOzRe+8N4B/xqv7WFXpTwyCPYeFNR4F/+dXASebDvBmCSPi/mBhPw1xbk9jX1rus0ZUsfgei3XwzdiDwSs9/sUcQ/EENbOiRL/mC5+6+b4FiBaE5uJ2DGyWQDC7uq1Q7vjn2Qf7auqFaRdk22IgoceP89jFL98zXQTZffexwnzS2j7QK0ACP1mUArJ1qFN2w== 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=u1exkS/uweIgKXeUpBvInyadEJMzoYayUA8BpUFSFtw=; b=iberMZOBsXwU5e/SktgmXy6EbrCeDNwLmSYhzfp+GgT3yKZWtQTu6db9clo10ldpNCP0qjNn+9PXUhKMvyEERDEHthSNK2ZTpUrLOX16IuDxDyMdIO1l+ynKEAzbklVn+PVSJHHdAY2W3bd3cdVzKt/QMpYHs5qNOj0vF5kvLO/JeJ7MMJSM+JMxGaTXeihJ6w0mz6dvz+1OIqFzF7wGdWzQGAXsl2fhLzFX0aUlU73rPqfPsv3Wd4FF6uQdiDMovluUICbUFIWqOlTvviwj1hQxaBIEcnicOXcktTulijxcjmeEO6C2ggXMg6iTEm/KpraXi4Bk8VoUPhSkg38sLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=u1exkS/uweIgKXeUpBvInyadEJMzoYayUA8BpUFSFtw=; b=LdIXVIEuPdohj4F/EpfidYzR6m1UWIkmFljEkD0WmvPqDivdYXE5wQh0EDDbGVbpNzB4wuFLh2D9kokeqygkBqgT/cHUnybONT2PM0fKMjseeLAL6jLYox3A5/nXH+RWcD3UAb3bSOLdIQSpmMxgnJ/QignQMiKDqJL0aoOPVxKfrau+uuBG0HKymMsu5Csan8ZM92XFyQFgPYRCqRKjufPAinH/hJhtlBdnqPZuluDCvupWjYJo8K/oQmjVJnV7gmCaNo67J3ZfraVsC/VuztsK1K6DkSSCzeh4M3O//AgC59WBsM4RjfD7KmD1AuJUWn5fljRJ3yaeZ53Qiaqz5A== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?utf-8?q?Roger?= =?utf-8?q?_Pau_Monn=C3=A9?= Subject: [PATCH v9 03/16] vpci: restrict unhandled read/write operations for guests Thread-Topic: [PATCH v9 03/16] vpci: restrict unhandled read/write operations for guests Thread-Index: AQHZ2s9K3uXHQsaiPESKImIi9IiKlw== Date: Tue, 29 Aug 2023 23:19:42 +0000 Message-ID: <20230829231912.4091958-4-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 3f6a034c-0eed-42d7-ee2a-08dba8e66d99 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: WxIQjI0a68yrnUfjB039J8OX5mdq6t9zWgtZQQs0+EylFXk0E7ALFlTKMnUt9rynIrt8UfpqSWj9OCAPEFSDmwuoBc+afygSTSKaK7AraR5DrCql9ZfineZRW4a2Lo17RR4i0+mRGqFPvUqVaCYd9q6TNfNpE8jOpkoMG4HThBE3k2gywICJcgEoA5Deb1EhN/l8M6i/JYtHOaKkg20Vb29eB/LY7JPqx3eAVTRek9x0BXIsiPJpFUnLD9Y5g2+zMSobWHn8Sw7LzP4Wfa8Fo6urI951yPGr9ao1Qv9thf5ojSp0nlv4h+0LqFcdkf+5GkH47aWJzcFWr7HpNJNjmnVBhRmIsBULmFRj+JfJFCg98jjOQNHCJze4InVjYaZPLtj0W4kM5ptc4XlpxoCMtXghEpeoelRPD9xdOEtJ3fJSic8OGJEqitquyXNxzqST6AnC1mzofsinXVGke/fQ1ghBhuBsQvrGLwQ5tniWfqMPm7jrpSQjW9LYYr65Ae4l9ecHRrIOpcSaeLYadAdYGxGsV4b72yRTW8IRLhqFuELGtShV/zLTHdzM0a5cf0TCOr9XSgjizVLe1b2JPdrsscy89FuVqa7SPHn8IorgNWr5nX6G6r5J7xAV/8SibqzJ x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?mjGhz6XsrJXIpoTIFunoECrhwMae?= =?utf-8?q?XHDht1Wu8+J4oocUBlJU4eFpnYR9JHOaLTR/kSdX+/Vksk7mzkQ2vF+xdE2tujIOK?= =?utf-8?q?q0fINwEBEvXwyHRsgMzQaJAIPEz64o5941Xv4jWYPc9nAUnVQKy3FKPuqyyBze3Cx?= =?utf-8?q?kzlQLuTPX3eqFiGoHur5DoRGtvWrNFPmIaTzYDNFuesCMDlvedeNIIfCiv45UmMCT?= =?utf-8?q?cQtACzia8X/8RViCP7Pb5MKqU21UMtBnt50dvcsMOQwCcz/UtnSMR8FhaO0J+zkAr?= =?utf-8?q?VG9dXACY1uJiTPLQ/dPB6QIc6OjwYkrNG/h4yX/TzVl7CJaRWS23uZVqYj2O7Orrb?= =?utf-8?q?Dp7RFBY04xghVlmfMZLD/lRJo9HdCctKbsftxxdrd8cTpFinb8SJE+WDLD66XhkAs?= =?utf-8?q?zX0CIuMmDcmRtvWZhJaWUFrwwyPtk+mUnqgJ+A+MFGUDLRo9g4d9pOR9hgQNffWhn?= =?utf-8?q?0CYeDN3PHj5YGv0i4ux/uPAd63A4hocOOipNXjhnzRTg9KbsZC38IxJiZJMfwGHg/?= =?utf-8?q?UClX2824l2W/pljTvP3PIwTQnr09bPfg5/gjp715qD87rDVZ2SzC064rBq682/Ahq?= =?utf-8?q?EvfTVOLkw2c+Gm5i50X/Rc0m1XyLzBn3tzbfdtpewu8dlxcjGH576Uerks2iNJRNs?= =?utf-8?q?xVGQPySNb/PHqNJcCsevmyl7HWfSV32EV19oB4Vz5mdzcweQoz7au3kJtL/qPj7sn?= =?utf-8?q?jRGDIpqYVFZrGhNd0kJm1VpAF2FUvypWy6okvS3/+FUkM0qur0f5Fl5c2tQQgqNcM?= =?utf-8?q?LbvJj/hcPNhD0mziH9N9nv0hURQHw1Ln/7puRjBAFjxrNU7mdrafO+jQZnreUcYZ8?= =?utf-8?q?jKDxnP33t1QabUw99euL7sdj5cY1h8Xv6HYpliXgvpt3ZG8Y23bSubD3ngdscuf1Z?= =?utf-8?q?rsljK9i8W/cFONDauS6nwFV1bbKPpEHmohwxan3KifemwNCEAU5R7qXUviVoy2hjO?= =?utf-8?q?r+Qp0hBob0NOwG8QMqWBROCQ3iShYB34wAru0x0YgNQ7svwXk2CMpyTeOXxHSdN1U?= =?utf-8?q?yv6ltGJ2/JpO7PyqmlsIq4o4hVV69N6g+lMh09BJhS98gUltOAUa5mW8/ICJjJkn3?= =?utf-8?q?e7MEULJds471Xk2Wd+h/l9zwHZoqa+aPLBqQyFdoKQ0wgY9ghaAvnAvT20OhXXr98?= =?utf-8?q?5ftXN1LdDoG6zzNRMM1q+tpG8UnIU7ST12AlSugqwTBLeKam8JexreHM/Xf81XAWv?= =?utf-8?q?Rq3ewRWPxOh+L6RzYMPPSkn762tRiCjblyvcPterS44Eyema8wslAERkgnt/LYBSN?= =?utf-8?q?1XmAAB78W0R67BHRBc2ZHheoaC+l4KA3D9fyKqw3yWsKbH7Zm5d0BFiRSELYs6eZT?= =?utf-8?q?rAoVq+iYHhDJG8URjOHZureFFM1RrvaQR8Qz5coyR0mlbGNEi5BRAY9hGojShWFcU?= =?utf-8?q?7bv56wPS2IHPYxRqcddPkHH5pHh1usubWTaBgVsIJIPMhJU44fzEDwWULNRlwFm48?= =?utf-8?q?76xjzTTVJ7sMoYkNCXHklFY9fipINQHNMiNdF6ixVx9fOJF9Er1qwQekne5ay0qGo?= =?utf-8?q?OsaiFg3sLK6nvTa+R50I/PxRtDGB/lZ2fg=3D=3D?= Content-ID: <13D18B520035FB468CB752BA33A6723A@eurprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f6a034c-0eed-42d7-ee2a-08dba8e66d99 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:42.8503 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: vRtRiv9Nf+xw0DSm16Nkle+MfmvvAE8nMhVtKiCBsm4J5bz4B987p4hUc0tkYeebI9UOdNpwfckiK3tI09ATupeaJJziSAXyq2w8rvXRJfM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: at9ngLsWyGyG-BiUSJp1Xd_7n9ZHX1Dy X-Proofpoint-GUID: at9ngLsWyGyG-BiUSJp1Xd_7n9ZHX1Dy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko A guest would be able to read and write those registers which are not emulated and have no respective vPCI handlers, so it will be possible for it to access the hardware directly. In order to prevent a guest from reads and writes from/to the unhandled registers make sure only hardware domain can access the hardware directly and restrict guests from doing so. Suggested-by: Roger Pau Monné Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Roger Pau Monné --- Since v9: - removed stray formatting change - added Roger's R-b tag Since v6: - do not use is_hwdom parameter for vpci_{read|write}_hw and use current->domain internally - update commit message New in v6 --- xen/drivers/vpci/vpci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 34fff2ef2d..cb45904114 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -233,6 +233,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, { uint32_t data; + /* Guest domains are not allowed to read real hardware. */ + if ( !is_hardware_domain(current->domain) ) + return ~(uint32_t)0; + switch ( size ) { case 4: @@ -276,6 +280,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, uint32_t data) { + /* Guest domains are not allowed to write real hardware. */ + if ( !is_hardware_domain(current->domain) ) + return; + switch ( size ) { case 4: From patchwork Tue Aug 29 23:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369793 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 E6F5AC83F19 for ; Tue, 29 Aug 2023 23:20:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592519.925335 (Exim 4.92) (envelope-from ) id 1qb80F-00018B-27; Tue, 29 Aug 2023 23:20:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592519.925335; Tue, 29 Aug 2023 23:20:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80E-00016J-PB; Tue, 29 Aug 2023 23:20:06 +0000 Received: by outflank-mailman (input) for mailman id 592519; Tue, 29 Aug 2023 23:20:05 +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 1qb80C-0006kQ-T5 for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:05 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 939c97f0-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:20:02 +0200 (CEST) Received: from pps.filterd (m0174677.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TKDecl030691; Tue, 29 Aug 2023 23:19:51 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3sshtetfcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:51 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:44 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:44 +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: 939c97f0-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hQ5wXgSC1jc1h74EM/5aGLLfDLosKF0g/GeKmNf6VJv6a0VWOCtBOsk9Gcdc/daJIqGKTkpPSjAbhBbyAE2/E1cLGkOx7OkqDKp3ExYOm0co8BWl8IDx3Ztp1Ujs1dl2OAOX+msO7mI3URHMKUxL0DDpyptiq0nZ8KddStUm0xwQ78ToFXhVoeYE0vSvVZUjq90dVORw4PQpwow8MNp9RJle9PrCPSs+Tip84Q8hOel3iE8S5UE86DEfAs2qFrfvwLLEAgHv/t6HGzj7i2BJ9nMe4G4f4DeeGlEzl4CJ3na+H3hosR56EvqPoTal4BZHoT37Zh4gUaP1UVA97iY9pg== 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=Zqo0lIpyoeqKdrOeyKISSpFZaUk68QMHC1iBCANdCXU=; b=ZDGwcHy3wWuCx2U02CGAsS1IGHxgUMtgEaRSfxtoowRKIsJoeSgdpdBLbpUNxLogGRtkHg2I2SYAO1px9uxTW7j3SMW3e2yO/Pi2VXXrKoTVTTm6OTAnttvGhfXt+2d77DEgv/EIKoZTOM+CzkDiXboNqp88Mvg8U6d8kEPL0pdwcS+honJot9r6bAIF+FRnednt6qrjg4ZCnHCs1mHnqNUsfDwVY1v2ydmXbkv55mpiarfVWV8njMtD/K2Tr8rbvTjc905s1DeDxeJnPx0D9l8onss+AXnewTUGGJzlkKVhajkzNAfcDIOgMkm+57ywtPHo+XTIrPbZb44ZZgpRqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zqo0lIpyoeqKdrOeyKISSpFZaUk68QMHC1iBCANdCXU=; b=shg+Na9RPMWawWNUvPfvqTOZIIf02DwYdHjtquPDHxHbSW4HGfSRb2qeOuGfMARcYC4uSSWFigTYH4ZVRjhepBKKHRq0Dk4P1l+1GZrTk+gGl1FeL3A70r055600FSwXR5V8iPjx+epHOKD0OdsS/TD9Pw9zINnkamMYrcxrw4daE3psMvhVITOq8jCFA28VQvx7gLKjcVVMLnZ7WUhKB7Qq2CMCDorhzYCuaez4xF1Mj2Om3UGLyxyNDFVXqHu12y2E1hnilr9Ajte870deG0mO9D02qRyshLqq+f7Iycicg+d9tY5yoayI01aJjMgNCTrAz2JggT7cwQi8GucNFA== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Paul Durrant , =?iso-8859-1?q?Roger_Pau?= =?iso-8859-1?q?_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v9 04/16] vpci: add hooks for PCI device assign/de-assign Thread-Topic: [PATCH v9 04/16] vpci: add hooks for PCI device assign/de-assign Thread-Index: AQHZ2s9Kc9kNunOnfUurMYypVVbdQw== Date: Tue, 29 Aug 2023 23:19:43 +0000 Message-ID: <20230829231912.4091958-5-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 81ba55c1-be66-41dd-3a21-08dba8e66dc7 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: El8avuJZNZmNg3xcD1dBgxgN5MFuNoMAfPBWQdGbypZvCKNgmaBFyLJAIcgH/bQZzqg+paXKyKhyDF3PI1Nmx6HeWS98k/Lc8HJEM1g9V+aQtcfWl2pY027b4HdUTgP4r+rL9ZaPtGB8cWgxKCUqn5TNNfpkJFoZNbbX/Nw97ACqvEgZt4IY5gB2hLrqZXiSND1eruG54HWqS48cD7TnOH8CnX6GrojEbpmRLK6SfjkklgS7lu9ZLpc+J5cvJuy+ONV0ZHYVOJo0PP6mbN1Dga0idOd80xV4vKJGnS8JmgyNxIfpnFhQKbVp1iFwezF7z4reYkjrkmSJZkg6h+88qzyRNR/B/y0nG/A5ZCbKb41H4uQjbbXyEsqbLHDEQgNFgY4b3QYz9kP4jL5pnKb2EeufDsEJSkrGYDvg64BomIYk3slE8aLc5DsT3zvXRmEOSjml5GB4jjdOQv4Yx7U4a1XMbWVIhmWKXDb5kKF4vuuBnh/6v9EC+qVJD+0GjGl2mxRrRt1u0AnKislMjAhLFN0qypKCSRpk++m5fhUcK76mfcHTaNUkj2Yi0TieuUAZoaWQj/Iy3T5i1lAXq+bfM1lIDgD5xqXoT42wl0NXAVzXeClZV1ON5CyKQwEw15bF x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(107886003)(26005)(2906002)(6916009)(64756008)(7416002)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?36grGadin6qj2+yeifNDUNP?= =?iso-8859-1?q?lqt7KRPx6oAFjqqp8dIbqkGX+w4O5N4lBqPd34XcWbjMFwsUUR+6bf58fnzQ?= =?iso-8859-1?q?xpWgMyErPicYbA+eywZfYuqItUzVGkSb/dKoGrBOgR8G5Yxk7WrMz2oyvaed?= =?iso-8859-1?q?0xGFase4mbnj6V2JMN1Zvk1aUgf7cVCM7RXJOoqrMSvUfdrMse6beRXI1m8j?= =?iso-8859-1?q?aezMY6S6lzNEHLEI/6fKu3MBy7fw0bfhS7DjH6inDAvO8EDEzTsaxuaNH6ga?= =?iso-8859-1?q?EGZ55Om43i/xw1W4xuLVqwEWNxD84RQQ8E22VoqrnzuXnbW49V3XMNQoq/aJ?= =?iso-8859-1?q?898X+ukPRFS/vpSg5KxVLPMNi4cQS+z0jYYRUrzdcWfEh/VlIP3m5kOFBiCt?= =?iso-8859-1?q?iUl4Ui0ebE8BR6a6Kb1r/o8e9tlTpJDQyL56VljSvWvy27J8hFdmFapk2RiY?= =?iso-8859-1?q?HPYaAUnOohxlY/ITmJeedKEZLmxmjGWHTrisUJtRbb/6KET0khlrFiZBEtR+?= =?iso-8859-1?q?vqMFMXKEFrICXeQoz+bU9knEBDkUd1eztVtl+Jt4dHZmU5MWpQIhRk242EPA?= =?iso-8859-1?q?QWQKSsTuNOoDQ3oqVFzgf6JiYU8+xK7NxNVY/c68okFZ4gtdWDLVOS64f9EM?= =?iso-8859-1?q?j0W+MfFGKgCxlXQWGK1dADr40mEodgGsCwm8rxJA8JMBcE5R570tT1LJ2Af4?= =?iso-8859-1?q?XPNc4zpPqtYf1shJ/Idu2B5ezTbBgRX0s+1bL9lDeVVBQqRrRw7uz9SKxnG0?= =?iso-8859-1?q?2l7hjxIkNpXJFSxq86USPciX0JJ2sRWxxx4GULxXOcVi9gb0j6ajBlfCd55y?= =?iso-8859-1?q?EY/YrKZdqKjbmzxUpQP1Xm/VwA7d2k6xe9itzI3E3peb39eDgxTOV1mxp3zG?= =?iso-8859-1?q?DwN7UtvSQVtU/A85kjWqUDCJkCH56NWcb+FxflN9hWU1UZ9y8aTkn9XcyqKA?= =?iso-8859-1?q?yDCNDKIIytFpTIGzVLj8MEMK1rPpCm3/+j1aKf5DWzPLvrurSNVpDi8gZok+?= =?iso-8859-1?q?QSozd2LXJm8SlTeKWguruUnV1R/tj8Pdw7bMHXv0mcuuC/jsmuJxpAmQbIEq?= =?iso-8859-1?q?kX/fWrR1MDS0m9jZ+tNTcw8U/nE1iQotTYeDALHriZbELgpfvQzco6DamAkZ?= =?iso-8859-1?q?08Svd0lcvwVbqxgRBZKxA/1DU45JZqGBmN1G2OADaykGQq2S0Z1gj3QkoDSl?= =?iso-8859-1?q?5k5WDpPY6XZeEzLnzi6bnJlIUXLZRNRvo16ABiA+wV8AnZ0vGU7m68ZyZZBN?= =?iso-8859-1?q?X2Simvkk3f6BbYnt3vatYO8QGNy01dxRyFuBVr5b2oEBQieIXopByS7iuHsu?= =?iso-8859-1?q?lwK/FlmBNo/YR884/BC8UlxP3lyS73889PejASVODG73zyspaa1dnUehFmeK?= =?iso-8859-1?q?vs6Me2SesY/PRQGXA0QGWM00i/OpbNvlGFd3K2pqRsUUgajxLtLFca5dj4xk?= =?iso-8859-1?q?i/EyBG+N4wNzwu5VPkhfBScVNim2AA+wvUwTX+lq+frRI0DaG1Yr8HjL32jX?= =?iso-8859-1?q?UxX27H1+rxt4LsteKZY7EBvzVDvzXNqSa9QhZQYBnZW3DvfTQv139e3c1gPi?= =?iso-8859-1?q?gLTKGad+61kWxo05Vt86hsixiof4PrNDDtsyqsC/lYb5k1AIL607R3ra5yl3?= =?iso-8859-1?q?EYoaK3TFlBJaVszFrd62Q1HQCpUhQ9nNx6aeB0A=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81ba55c1-be66-41dd-3a21-08dba8e66dc7 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:43.1413 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Ecf9w9tlXYTNeCIHHZGeQ4LnsaJezbdJtoWgvGLedK45HgRTIrMwaW4HIi0VlLaCpg7r64AN0vMiq7Sbhihbi/7Y/ENPO4va51BdY1GUxDA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: coPqyw37LHHegyecz7JU3l-gbNxPbmBI X-Proofpoint-GUID: coPqyw37LHHegyecz7JU3l-gbNxPbmBI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=735 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko When a PCI device gets assigned/de-assigned we need to initialize/de-initialize vPCI state for the device. Also, rename vpci_add_handlers() to vpci_assign_device() and vpci_remove_device() to vpci_deassign_device() to better reflect role of the functions. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- Since v9: - removed previous vpci_[de]assign_device function and renamed existing handlers - dropped attempts to handle errors in assign_device() function - do not call vpci_assign_device for dom_io - use d instead of pdev->domain - use IS_ENABLED macro Since v8: - removed vpci_deassign_device Since v6: - do not pass struct domain to vpci_{assign|deassign}_device as pdev->domain can be used - do not leave the device assigned (pdev->domain == new domain) in case vpci_assign_device fails: try to de-assign and if this also fails, then crash the domain Since v5: - do not split code into run_vpci_init - do not check for is_system_domain in vpci_{de}assign_device - do not use vpci_remove_device_handlers_locked and re-allocate pdev->vpci completely - make vpci_deassign_device void Since v4: - de-assign vPCI from the previous domain on device assignment - do not remove handlers in vpci_assign_device as those must not exist at that point Since v3: - remove toolstack roll-back description from the commit message as error are to be handled with proper cleanup in Xen itself - remove __must_check - remove redundant rc check while assigning devices - fix redundant CONFIG_HAS_VPCI check for CONFIG_HAS_VPCI_GUEST_SUPPORT - use REGISTER_VPCI_INIT machinery to run required steps on device init/assign: add run_vpci_init helper Since v2: - define CONFIG_HAS_VPCI_GUEST_SUPPORT so dead code is not compiled for x86 Since v1: - constify struct pci_dev where possible - do not open code is_system_domain() - extended the commit message --- xen/drivers/Kconfig | 4 ++++ xen/drivers/passthrough/pci.c | 31 +++++++++++++++++++++++++++---- xen/drivers/vpci/header.c | 2 +- xen/drivers/vpci/vpci.c | 6 +++--- xen/include/xen/vpci.h | 10 +++++----- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/xen/drivers/Kconfig b/xen/drivers/Kconfig index db94393f47..780490cf8e 100644 --- a/xen/drivers/Kconfig +++ b/xen/drivers/Kconfig @@ -15,4 +15,8 @@ source "drivers/video/Kconfig" config HAS_VPCI bool +config HAS_VPCI_GUEST_SUPPORT + bool + depends on HAS_VPCI + endmenu diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 4f18293900..64281f2d5e 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -757,7 +757,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, * For devices not discovered by Xen during boot, add vPCI handlers * when Dom0 first informs Xen about such devices. */ - ret = vpci_add_handlers(pdev); + ret = vpci_assign_device(pdev); if ( ret ) { printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); @@ -771,7 +771,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { write_lock(&hardware_domain->pci_lock); - vpci_remove_device(pdev); + vpci_deassign_device(pdev); list_del(&pdev->domain_list); write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; @@ -819,7 +819,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) if ( pdev->bus == bus && pdev->devfn == devfn ) { - vpci_remove_device(pdev); + vpci_deassign_device(pdev); pci_cleanup_msi(pdev); ret = iommu_remove_device(pdev); if ( pdev->domain ) @@ -877,6 +877,13 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, goto out; } + if ( IS_ENABLED(CONFIG_HAS_VPCI_GUEST_SUPPORT) ) + { + write_lock(&d->pci_lock); + vpci_deassign_device(pdev); + write_unlock(&d->pci_lock); + } + devfn = pdev->devfn; ret = iommu_call(hd->platform_ops, reassign_device, d, target, devfn, pci_to_dev(pdev)); @@ -1147,7 +1154,7 @@ static void __hwdom_init setup_one_hwdom_device(const struct setup_hwdom *ctxt, PCI_SLOT(devfn) == PCI_SLOT(pdev->devfn) ); write_lock(&ctxt->d->pci_lock); - err = vpci_add_handlers(pdev); + err = vpci_assign_device(pdev); write_unlock(&ctxt->d->pci_lock); if ( err ) printk(XENLOG_ERR "setup of vPCI for d%d failed: %d\n", @@ -1481,6 +1488,13 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) if ( pdev->broken && d != hardware_domain && d != dom_io ) goto done; + if ( IS_ENABLED(CONFIG_HAS_VPCI_GUEST_SUPPORT) ) + { + write_lock(&pdev->domain->pci_lock); + vpci_deassign_device(pdev); + write_unlock(&pdev->domain->pci_lock); + } + rc = pdev_msix_assign(d, pdev); if ( rc ) goto done; @@ -1506,6 +1520,15 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) rc = iommu_call(hd->platform_ops, assign_device, d, devfn, pci_to_dev(pdev), flag); } + if ( rc ) + goto done; + + if ( IS_ENABLED(CONFIG_HAS_VPCI_GUEST_SUPPORT) && d != dom_io) + { + write_lock(&d->pci_lock); + rc = vpci_assign_device(pdev); + write_unlock(&d->pci_lock); + } done: if ( rc ) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 177a6b57a5..3b797df82f 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -190,7 +190,7 @@ bool vpci_process_pending(struct vcpu *v) * killed in order to avoid leaking stale p2m mappings on * failure. */ - vpci_remove_device(v->vpci.pdev); + vpci_deassign_device(v->vpci.pdev); write_unlock(&v->domain->pci_lock); } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index cb45904114..135d390218 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -36,7 +36,7 @@ extern vpci_register_init_t *const __start_vpci_array[]; extern vpci_register_init_t *const __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) -void vpci_remove_device(struct pci_dev *pdev) +void vpci_deassign_device(struct pci_dev *pdev) { ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); @@ -69,7 +69,7 @@ void vpci_remove_device(struct pci_dev *pdev) pdev->vpci = NULL; } -int vpci_add_handlers(struct pci_dev *pdev) +int vpci_assign_device(struct pci_dev *pdev) { unsigned int i; const unsigned long *ro_map; @@ -103,7 +103,7 @@ int vpci_add_handlers(struct pci_dev *pdev) } if ( rc ) - vpci_remove_device(pdev); + vpci_deassign_device(pdev); return rc; } diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 0b8a2a3c74..2a0ae34500 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -25,11 +25,11 @@ typedef int vpci_register_init_t(struct pci_dev *dev); static vpci_register_init_t *const x##_entry \ __used_section(".data.vpci." p) = x -/* Add vPCI handlers to device. */ -int __must_check vpci_add_handlers(struct pci_dev *dev); +/* Assign vPCI to device by adding handlers to device. */ +int __must_check vpci_assign_device(struct pci_dev *dev); /* Remove all handlers and free vpci related structures. */ -void vpci_remove_device(struct pci_dev *pdev); +void vpci_deassign_device(struct pci_dev *pdev); /* Add/remove a register handler. */ int __must_check vpci_add_register(struct vpci *vpci, @@ -235,12 +235,12 @@ bool vpci_ecam_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int len, #else /* !CONFIG_HAS_VPCI */ struct vpci_vcpu {}; -static inline int vpci_add_handlers(struct pci_dev *pdev) +static inline int vpci_assign_device(struct pci_dev *pdev) { return 0; } -static inline void vpci_remove_device(struct pci_dev *pdev) { } +static inline void vpci_deassign_device(struct pci_dev *pdev) { } static inline void vpci_dump_msi(void) { } From patchwork Tue Aug 29 23:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369787 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 94152C83F12 for ; Tue, 29 Aug 2023 23:20:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592509.925240 (Exim 4.92) (envelope-from ) id 1qb804-0006nl-DO; Tue, 29 Aug 2023 23:19:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592509.925240; Tue, 29 Aug 2023 23:19:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb804-0006nB-7v; Tue, 29 Aug 2023 23:19:56 +0000 Received: by outflank-mailman (input) for mailman id 592509; Tue, 29 Aug 2023 23:19:55 +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 1qb803-0006kQ-EA for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:55 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8e3a94bf-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:19:52 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9i021983; Tue, 29 Aug 2023 23:19:50 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:50 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:44 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:44 +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: 8e3a94bf-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B4d+f4pv70rXV2sw928uvv07hADPv1MUOhzWAB1MNwYbqKoyCLC3iIn+IQ3gFjEV8S8aSMV2UjgD0M5pgUq07Wkom8VK3iNM+p4gkiKGvLqI7CaM8CQ87O2+V1y7P5HSczFLNUTxKj3UxuKBCbJIz9B/Be+YETf/2v1djj988jn0IRyr8/eT1GohhFuDHQtHGkpgO8RyD1yWl+SXRnKuabWoeu/86xvWxL2c5eYat17+7Y8A6Iha5au+GEYa5heljSXgAjU3gt9sR/zovieOMeiv25eBWECF41Lf9QCxSYTxuulfXc2KCTHZQ7duInlbyDSweXR2PLKiBxQFlfpfRw== 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=N2ERcj6JUMizs9Szx0x2ffT7vSpYcqMvosqrwubMiSw=; b=I3CG+YRWH+GFCXOjVWR5Vg72nYWBzGZMC8NaNMBzwB6RHcFaRmK3gyhpezHNnZ2C8uN4+o1Dat51/SOZnO4I1ymKnhECg2x8CNmM/aY9Ogjhh1XHB3RFO5T4zduAPatn2Rt+rrritzw0I+qm/SlqzrfHif4/BcBmWu//gmKgcPf2//IPxu5y1y7Pbc0elHynSJS4hPV62ELtmamzG4Da+1xq8PzdYRD3hbcim6lR0GpWs251H02EVvwRIe6qo1zyk5cIi7MGe0bRgIjqXkwhq1iZa5BbS1aaV7bSsUcpxjY9bwRtiw8gyAFf0TQRk91dydmQQt3+rYBSpTjZYW971w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N2ERcj6JUMizs9Szx0x2ffT7vSpYcqMvosqrwubMiSw=; b=GnDZx+c94Y9G2T4CTrSVpsuEGF1HqqXFMbBF/J3NSvSdZmAAKR7WrHIlb7zAWyccCFaMtGSMbmaAjI81I+bH0FHstNaftvLt+C3MhlhKI0OHDX+jJPoOnp3nd4PQgV0Cbs7Uk0buOgMgIvD+VeM4xhZyDfshhzyD9VtuiTj9VGfGndWVeUWamc9WlPUcl0jyObgkxR/khD7MM0rv6BzDfSHwqmVdGvdkvFN+6QRIbw1ggfzZPPdg64oOdFT90/WwrTJ8KpIXU3egldsWMcDvFj2mOZCR6cBFN00ae3dq9cfzRGzzFQHC/Wd3hcsvEFmJSfCAz7ShS72RZkDmruLZXg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Subject: [PATCH v9 05/16] vpci/header: rework exit path in init_bars Thread-Topic: [PATCH v9 05/16] vpci/header: rework exit path in init_bars Thread-Index: AQHZ2s9KQBAEWRsQM0+8e3gDHK2mZA== Date: Tue, 29 Aug 2023 23:19:43 +0000 Message-ID: <20230829231912.4091958-6-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 342a1b83-df3f-48ba-e858-08dba8e66df6 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Fdb6/HI8nrT3tUV5/f0SskdHhznmf7e6jDU+2B89BajbLy2lE+lOaSBOmdJnJh6RUrp5qorP+o1adyUOPrPuST1wpAW9TzoU2Rp43pMJ9tzy/54X1GcVirDYbCVT3Vx3XZDboB7IJeqr1597tR8icC/sZTOlyaZSHWozuC3VTe+0H5ZdC+gkChBcRfCxC3WuLMgxN+nWM76yuYk5EBHXNdbHTKbT7rDTzxgJHb2TJlrVqQ0xCuhxjw6egfq0PCI44wPn0LCCeNofl4Nk2kOZcfh6st4NfiO8HI620EiVpUYtGYVg6CLFLnN1T3EHUSverJzhegRqErrFBZ7FaCgG6M+Ua1KhNWBY0BcNJHQDuMPrmm1Enb8+81rsWob4EO3wh8ZY8KSGfP2kuwgbE5LoJFvv7ArxPAECie4nOV/S01j7e837avsrFDguw8/xMu//MFSwCLQnHZbf6A+Z4w51GFWqHNTuKWA7OnnUUnKVqzmuJxbftWbjjCaXYekucCRD7gWbLe1jI2mE/h9V+jhPUXRHxyXVJB9YPUilAmtVAJBcKjrK6f1YbRzPJRb7ABU+0J5lXSwUYMzEkmYQUA9hxxD6it0GBUzFnx+7CQpaEDn2F2jueqcB7pCOshJozPtk x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?fgP9NKyRSA9l8IBLLsgpnfFJaT5/?= =?utf-8?q?usttCQMlPXRKU33KLqvvQyIHuzfDGuYJj3R/UuF9vbtHHuS3oPnd8XzeLZsqdoWCs?= =?utf-8?q?35uF6d7Y7ThV1TD1za70ihSm6EQPwWbfyjRZxa51fpADuVi6tI9eoSsXgMedGURZS?= =?utf-8?q?AmvXCTuJ49Zd4i8es3su3ZTdNZ9DanyxmmeKfEs+fWmhJP2PXJ3lDFO878qoEwnKi?= =?utf-8?q?4DliErOmmrP52f55PMoSKk5yxKVqoLORenAGf7RE7Pki7mfJRm1v0zq0Fdvy1CUwZ?= =?utf-8?q?CWFtWFsjmHuafn+lVGBCDTqmRMxABDzRA7cPOXwQfqlWjPGXkoLBNjjn4P963WfH8?= =?utf-8?q?2plDQ5eCUydNGXuDPtox03C2Jk6RTQyIPQbdkqyHS8Yc2whDVEFv6wZ6Ujkqwtljc?= =?utf-8?q?MxDRGALOHqC76+hJYl8jZCIACqap6Rbmwoh7ows9smokQuGp+lnzEDMEP/o0BXOdG?= =?utf-8?q?eHenx29aRkA6+qklU+klKprnjhm61ee30jxJpvcHy8WBJZrZFXStzMyi6bhXZ0fpZ?= =?utf-8?q?GmJdtkj+5kUzQtoghXgx8PcfdvkobfJwb82lHAgO/BuTQ0cItRrTui7Zm0zhdJ7n/?= =?utf-8?q?0p1v7tnxjq7Wm8aj/t3BF/jlaT2off6o0fJWBtXGYmO6KlXCBwtnImAGc0y/eoyei?= =?utf-8?q?4tO7XVwhZZqAFUos9jr0RPKyVgxA+Qxhq185VVJDXNWFXBYxaHLaPtIo5dhElS1jl?= =?utf-8?q?4vmXRwML8XzB3OYGjHw4eJ2KU4miQnC+umMowtyuVA6zQVxVDx/Woyo7TdhMO6+5d?= =?utf-8?q?6mOU6AX5xGsf1zJnoStbYe8Wt6K6cNUrKZpE5xaUARB6CWa0jqZhWThKO51fXlWkB?= =?utf-8?q?JVljBmecen31b9cAY56Byci7r9xSpyJvoG+x/E3ZTubzMPjqTnQe81x4uldVMg7oo?= =?utf-8?q?Us1FDDIU6UZyIOpOW8UaOhjfNr1s+4wqmFX4i68L5Nsu3hn87i4F6AAL9SpCDZiCx?= =?utf-8?q?1ba6vV7Aya9IybfdSuQgSJdnoOk34LwveOnfT/LsmFeXehqnLvoQZwwXF2BeWsKBW?= =?utf-8?q?X37ihQmWL3htqqyBtomE6pmd16W41smUF7PVRclEdggp2oWAL69ZVr3y7f9JAwvt4?= =?utf-8?q?YRz0EXUqJE6treXt2Dt6YMYKaLftoiuVN4A0d6FXgfrtXSoj2TM5Lu6lAPXYItXqZ?= =?utf-8?q?X2aIAoTlfL4c5BYQPQq7bcl/fLKQpW9r+Qe+zm056aFEU58HC2tvoCg1kpYLKHWGP?= =?utf-8?q?dpgY80G/xxBpZlvrvcTJzjI7JKKjatTOLp2i/zPBhXRakgLcfL/THAfBVqGlvCNlm?= =?utf-8?q?w5O8cBv0Ns/AS44lge9iLa/5VKLfogS+a1CDhwUbHsVwyfYgN5BWoL7Q9GCjqb1R+?= =?utf-8?q?kcj2QUmdy1e2LcyEQM+zvMDYWVLZU7cVbgEzlIqG3Hkaaf1hBr+BXshznqJvnBwrr?= =?utf-8?q?joqNn4iBgtuYqrkdU56xYUzDuUe/JRXOo5PaZiTOUWtc4feV3NHBOPNk3BsEa0dCZ?= =?utf-8?q?qhLQGdj1wUKpt9k8faqIvZLxyFVdFr/KT8t3xFvy0TsytQUPbBabdME9KizqLRBgd?= =?utf-8?q?05E10dFn4eVqp+HqLhB6zjl7TEFeQTpGbg=3D=3D?= Content-ID: <482FCAA8E5EBBC409D3C030B985467DC@eurprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 342a1b83-df3f-48ba-e858-08dba8e66df6 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:43.4011 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: g5LzW0cjsghHCCxmKErmsNXkcP8/ruZmWQPdPdYXJzaeM9hbTJXs0+VLNzvIIeTTmqMOTybsnKdp7r6zVc474E4iJLcLiygE51ZioFHnon8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: cFxyDfDyErvBYbpIwdkUT0NTCeuXyww6 X-Proofpoint-GUID: cFxyDfDyErvBYbpIwdkUT0NTCeuXyww6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=943 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 Introduce "fail" label in init_bars() function to have the centralized error return path. This is the pre-requirement for the future changes in this function. This patch does not introduce functional changes. Signed-off-by: Volodymyr Babchuk Suggested-by: Roger Pau Monné Acked-by: Roger Pau Monné --- Since v9: - New in v9 --- xen/drivers/vpci/header.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 3b797df82f..e58bbdf68d 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -581,11 +581,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, 4, &bars[i]); if ( rc ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } - + goto fail; continue; } @@ -604,10 +600,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rc = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size, (i == num_bars - 1) ? PCI_BAR_LAST : 0); if ( rc < 0 ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } + goto fail; if ( size == 0 ) { @@ -622,10 +615,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, 4, &bars[i]); if ( rc ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } + goto fail; } /* Check expansion ROM. */ @@ -647,6 +637,10 @@ static int cf_check init_bars(struct pci_dev *pdev) } return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0; + + fail: + pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); + return rc; } REGISTER_VPCI_INIT(init_bars, VPCI_PRIORITY_MIDDLE); From patchwork Tue Aug 29 23:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369792 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 BE932C6FA8F for ; Tue, 29 Aug 2023 23:20:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592513.925277 (Exim 4.92) (envelope-from ) id 1qb809-0007kq-1R; Tue, 29 Aug 2023 23:20:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592513.925277; Tue, 29 Aug 2023 23:20:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb808-0007gi-Qu; Tue, 29 Aug 2023 23:20:00 +0000 Received: by outflank-mailman (input) for mailman id 592513; Tue, 29 Aug 2023 23:19:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb806-0007EX-W5 for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:59 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 903eb835-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:19:56 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9k021983; Tue, 29 Aug 2023 23:19:52 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:51 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:45 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:45 +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: 903eb835-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fdd2Kl8r5lBbeG35vSYlKDlTAIzK01RDH34HSfLYDBh6po2NQZsyrCqgF4IUtz9CRFedlTUA5TWWTPFW6jefCrAMgOZCbFS8xyupKIgUYUovB7T2GqgwVTQHFIAvteq845ONyst0FlVJtsNg/F89M7rvyyfuTU7dqhpTFLzW1Dcaakuh9k8seIquQ+ZnUfZQUlQ0Z0TBHXTpFkDFrEa7mSin5zf+Q7PoEYxGbFSZatIr24EB9803FnQWYaJX1Lc9ENFV6clDXB+d6vAIPsic7NS+kZY2z1vLxCoKlGGeuL8HvjAoWPJWv5KYu0vnAj3h7nPyTRd/YI+NdRb71+D6pA== 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=Ytiz30TI3pdTe8KMnSkIj6r0rNKRFbzYIExzPrIlfn8=; b=kUHirDJ+jsvrRb8dG/zfopIIbAcnkFPB5IdIvsfxmx0MNWsncwHLjLiWxgdQfcmBO3zdna34bpwPDVlXIOg9jrqTFr54oNY31jtwVquHErygdVrsX9yhZtdyjpvkQDgmVuh/BUf2uv2e9DU6Uf0QATkdNabh0tZ4CdNEzZKuRG9uYGCr8f8yP8qIzSNRtCKiIEcKf/AdnnDeZgxpBh9ZD6uEzKGs+lBBujNUBHY0/9KAvJCFzTWC9PL0/QDRP9v5D9n/A9+C+5fWfv+9pQay8bPOhRfZQ/JeG7CTvbxPZCXbaPZ36hnlNZT7xi7VnfHPlN/LaadLswh3VfJ1f940iQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ytiz30TI3pdTe8KMnSkIj6r0rNKRFbzYIExzPrIlfn8=; b=RPqYCLQyYx3czkeI1ZYP9teZ2lgNnT4eJFIz/8yajiSxlrhRlFU/WoeToScpwQnkBuPG1NKzbgsjccRD+Ah1P3pfzqgezsKTThjaiHlmjLiqYTu87wBR2Lh/7Ov3L4lOaCo86D+2zPAlrchfJswuKAXbeyhrSF22IUc22XA4kcF3JY6UWTU5gf7TS/aWxto45PQg21KauwWw0IiP6r549eVvzuWUpg5exzgMZipESd1vC1Vdsi5GrTbx7ovxSYsCNOx8CzQQI82VesRQmYmi0qSEWuN58RDJZUwByhmL8Ji1vMMYRVST+6fFQrVCn3aJHFwV9dCzrm4pvPueuvKX9A== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v9 06/16] vpci/header: implement guest BAR register handlers Thread-Topic: [PATCH v9 06/16] vpci/header: implement guest BAR register handlers Thread-Index: AQHZ2s9L0mQJgo9Th0GLfB+1u63ugw== Date: Tue, 29 Aug 2023 23:19:43 +0000 Message-ID: <20230829231912.4091958-7-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: f2790ca2-6735-4168-ce1d-08dba8e66e5f x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YA0UtcvrDnRq4h2UOHet3TTD5Xbn4+94++jrRIIwrNc1hQvpzSzDRSqVUrNTE4FoXJPROikm+pG7JPmD49vWj0a+y0RmGTn793zJYOEoBGJSIb+4KH7rkHvT7cBYfYIiwfhopXyU1b6w/sMAXHNtARmc6LuvTP2beQiBogdU/Y0FYesAPxt5GNSxHX5RMWork33ggpv4ZlkqYKB9aUxHsJwxIhpQGQ94+09D0IN0HhhrqiFArvur/ntfaF3WaBKEGDkMaAbeKiI0nxRp5+Mqak12g+7qFzpe9QewevJuCTubAmAgSAwp9UGpPz7PkGlT227qGMjHSf2QX8rJYCukNkhlZxsEQtu2YP0GCUN2sG1YfV6Bk0G3ROYTYMt1Fz9qefmijDV1ijHqOjTE4v/DwDrCr67lwtfQ8QgCDvWj1GESdHLrudTISSDlP/2P+qYnk4bHx+9IHPUzy9S75TF9i8hZ8ITNoln3ZS8dU5s8NgU6A9r104zd7Om5Bo/mVncZXmyjczZEsHJ8PXSekMWb3d0UPQMhQBFnw/WKr3kjrV2W1mL3bvLPnxdNekghNE/eSJUr+s2H2TF8SSDOyGdoy0QDJ2ycQ51LKhdAZTkblf9Hjv+DF8F1xt0hpfQbRT24 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?7Ys3b/N92/oWj818Bl5/Q5a?= =?iso-8859-1?q?OnrVpenxyAnI/rddun9vIqvUzs9EM6sRWJ5Nfm8yKyGPdeVR5Js5gXCvd/48?= =?iso-8859-1?q?Tcp3Tmr8PdfLQheeuKuFpfG4dVt/4mRgXumFhgkNl3OAC/XSW461VUx2XCM9?= =?iso-8859-1?q?o/1xnCde1W9fNK4+o8G7ucV23H7tSec18xDYcP3wh+fsnZKI3zg2XTE7yd6V?= =?iso-8859-1?q?10EgJjBPmOwVSY5XMlWZ5UOOySZTIJBTszOTJ5EvK1CsIUBTeVKFEe4qdkEr?= =?iso-8859-1?q?gjFGNeWeXthl0CFFmwlNoKQI+GGh4ovHA5/YQUeHxOuK0v06u9B/WE4ccbeO?= =?iso-8859-1?q?Jt/YEHzISkzlI5gMMlIag1RR+AkEUEZxoeY8kGdxNoZVf71kVPb/m2/kHs0b?= =?iso-8859-1?q?5Ptcr8cbVJRzNlYMaOx25YrLuBaA8hm63Y00R3+x2eYOVlV45M3kbMELV5bf?= =?iso-8859-1?q?y58a0NNtY8/+d5JK1QAn0V1WaJb3CROqpYIQG+lgXgI2r3xl52QOJlU4SX0c?= =?iso-8859-1?q?u+T5VKxXMU6jYQQcuEIcZju4Y5lDo5Zipsz3srZzoY+Wlv1vXkoaohz05Hfm?= =?iso-8859-1?q?6Dnbj+2ao5Kq/mNl85H5raWt/B5FNlAJJrGwa/WK4hYrTOCxmEGwyNLGqyKe?= =?iso-8859-1?q?Q9ocxVO5EaHUIHlUuM/2sgnesyfu6YuC7StjpL4i9ySVMNFj9q6zT/BMsDUQ?= =?iso-8859-1?q?YX7rco1EI7ql5yBRxYeylDSl4v24Wxg07GOLWTNL0aT7DoSQCfbNoKAz4bAH?= =?iso-8859-1?q?DEIQsE9iO4x7r8RuEhB7u/W57XN6XeIYgG/ph4J85F4cRG75x/UXgDZACu37?= =?iso-8859-1?q?VSDHG3xjDD2OMKPJlru3WBf5VOwLYOXo+bPDieFOHGWzh6dIzwZ8uV71tLPT?= =?iso-8859-1?q?/AIc84iVQGOta383n/adYFqykNrMH7M8fWFqjEO34sYTW2WBV4HD5ZXNmPbU?= =?iso-8859-1?q?YHwQX7j9q0vm+Owi3N8n5M+YAd09OsQeyzJ8UWJBFC9dA/AC7YHjNp6qm5NK?= =?iso-8859-1?q?/745Xu0OQWZqh+lNUmRTD8YI0a/184b0TSyk8haeYc6HutTT5hTvQiWPebJX?= =?iso-8859-1?q?zcvdeo0YQgVmFkXqSp1AjKaIZa9L4iXbZDoC8KMLFn0KZpG76wqKEYxuM0kB?= =?iso-8859-1?q?OXdXPMeuQaCBFWOXQMHQOtyaYOMpw+IGxLoYT10A1XYdviaBxHKmIUm5jFBj?= =?iso-8859-1?q?cDvo6K1ecjrw37mQhVRJAPIV2jkJYGPa7wUjTPd7sjzYkxJL82X6P/xPkHXi?= =?iso-8859-1?q?nj6u/jZ67kCNnaBQbxOqCivLt3Hv1P1ErIvcehRPSDH4mnv2jtTi6ob37sX5?= =?iso-8859-1?q?UcnJzN2PVPxydYQlgcz3LLEjCsrVditTVa45Q6NG6eR1aVr7seFcIcDqHG/s?= =?iso-8859-1?q?P/PL1/9zS0iWO0jOq6jSxbZ7ex0+zD/YR5J1bxDwA76XE891T1Ks3J/DF91a?= =?iso-8859-1?q?9c2O4BwzBR+MQNEyEiAC7VDSABkFNDGSAId35mhMklzklraDTZZHFw/iDukY?= =?iso-8859-1?q?lJu9RTtHvBOxZuSOyBTgFsyIoG7ExD8H/a/36Pf6QdZ3714Kg//fWp4Yz2bJ?= =?iso-8859-1?q?mjoh9e5UESRvMYC6CQadnkjexZ0uB5hc74v0alpIT17udkHoBxOrOsVQ81GJ?= =?iso-8859-1?q?1nbDqC5uPO76eXV48uPWcX0t8gKJiwhQey3W/zA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2790ca2-6735-4168-ce1d-08dba8e66e5f X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:43.7178 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Qz6DX931uvrXlGo6wN6xfhm6UH2s3W0ecozu8XFcggKLh03+4pqASHQCW9SUhn/ehChurxwekuvW4n5H3rAH/ghGL0/pVClPkW0QyJS/PfA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: vc7BuCmWsMSMmfFadpYjsbGBBk9Eq77M X-Proofpoint-GUID: vc7BuCmWsMSMmfFadpYjsbGBBk9Eq77M X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Add relevant vpci register handlers when assigning PCI device to a domain and remove those when de-assigning. This allows having different handlers for different domains, e.g. hwdom and other guests. Emulate guest BAR register values: this allows creating a guest view of the registers and emulates size and properties probe as it is done during PCI device enumeration by the guest. All empty, IO and ROM BARs for guests are emulated by returning 0 on reads and ignoring writes: this BARs are special with this respect as their lower bits have special meaning, so returning default ~0 on read may confuse guest OS. Signed-off-by: Oleksandr Andrushchenko --- Since v9: - factored-out "fail" label introduction in init_bars() - replaced #ifdef CONFIG_X86 with IS_ENABLED() - do not pass bars[i] to empty_bar_read() handler - store guest's BAR address instead of guests BAR register view Since v6: - unify the writing of the PCI_COMMAND register on the error path into a label - do not introduce bar_ignore_access helper and open code - s/guest_bar_ignore_read/empty_bar_read - update error message in guest_bar_write - only setup empty_bar_read for IO if !x86 Since v5: - make sure that the guest set address has the same page offset as the physical address on the host - remove guest_rom_{read|write} as those just implement the default behaviour of the registers not being handled - adjusted comment for struct vpci.addr field - add guest handlers for BARs which are not handled and will otherwise return ~0 on read and ignore writes. The BARs are special with this respect as their lower bits have special meaning, so returning ~0 doesn't seem to be right Since v4: - updated commit message - s/guest_addr/guest_reg Since v3: - squashed two patches: dynamic add/remove handlers and guest BAR handler implementation - fix guest BAR read of the high part of a 64bit BAR (Roger) - add error handling to vpci_assign_device - s/dom%pd/%pd - blank line before return Since v2: - remove unneeded ifdefs for CONFIG_HAS_VPCI_GUEST_SUPPORT as more code has been eliminated from being built on x86 Since v1: - constify struct pci_dev where possible - do not open code is_system_domain() - simplify some code3. simplify - use gdprintk + error code instead of gprintk - gate vpci_bar_{add|remove}_handlers with CONFIG_HAS_VPCI_GUEST_SUPPORT, so these do not get compiled for x86 - removed unneeded is_system_domain check - re-work guest read/write to be much simpler and do more work on write than read which is expected to be called more frequently - removed one too obvious comment --- xen/drivers/vpci/header.c | 131 +++++++++++++++++++++++++++++++++----- xen/include/xen/vpci.h | 3 + 2 files changed, 118 insertions(+), 16 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index e58bbdf68d..e96d7b2b37 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -477,6 +477,72 @@ static void cf_check bar_write( pci_conf_write32(pdev->sbdf, reg, val); } +static void cf_check guest_bar_write(const struct pci_dev *pdev, + unsigned int reg, uint32_t val, void *data) +{ + struct vpci_bar *bar = data; + bool hi = false; + uint64_t guest_addr = bar->guest_addr; + + if ( bar->type == VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + bar--; + hi = true; + } + else + { + val &= PCI_BASE_ADDRESS_MEM_MASK; + } + + guest_addr &= ~(0xffffffffull << (hi ? 32 : 0)); + guest_addr |= (uint64_t)val << (hi ? 32 : 0); + + guest_addr &= ~(bar->size - 1) | ~PCI_BASE_ADDRESS_MEM_MASK; + + /* + * Make sure that the guest set address has the same page offset + * as the physical address on the host or otherwise things won't work as + * expected. + */ + if ( (guest_addr & (~PAGE_MASK)) != (bar->addr & ~PAGE_MASK) ) + { + gprintk(XENLOG_WARNING, + "%pp: ignored BAR %zu write attempting to change page offset\n", + &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + return; + } + + bar->guest_addr = guest_addr; +} + +static uint32_t cf_check guest_bar_read(const struct pci_dev *pdev, + unsigned int reg, void *data) +{ + const struct vpci_bar *bar = data; + uint32_t reg_val; + + if ( bar->type == VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + bar--; + return bar->guest_addr >> 32; + } + + reg_val = bar->guest_addr; + reg_val |= bar->type == VPCI_BAR_MEM32 ? PCI_BASE_ADDRESS_MEM_TYPE_32 : + PCI_BASE_ADDRESS_MEM_TYPE_64; + reg_val |= bar->prefetchable ? PCI_BASE_ADDRESS_MEM_PREFETCH : 0; + + return reg_val; +} + +static uint32_t cf_check empty_bar_read(const struct pci_dev *pdev, + unsigned int reg, void *data) +{ + return 0; +} + static void cf_check rom_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -537,6 +603,7 @@ static int cf_check init_bars(struct pci_dev *pdev) struct vpci_header *header = &pdev->vpci->header; struct vpci_bar *bars = header->bars; int rc; + bool is_hwdom = is_hardware_domain(pdev->domain); ASSERT(rw_is_locked(&pdev->domain->pci_lock)); @@ -578,8 +645,10 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( i && bars[i - 1].type == VPCI_BAR_MEM64_LO ) { bars[i].type = VPCI_BAR_MEM64_HI; - rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, - 4, &bars[i]); + rc = vpci_add_register(pdev->vpci, + is_hwdom ? vpci_hw_read32 : guest_bar_read, + is_hwdom ? bar_write : guest_bar_write, + reg, 4, &bars[i]); if ( rc ) goto fail; continue; @@ -589,6 +658,15 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( (val & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO ) { bars[i].type = VPCI_BAR_IO; + + if ( !IS_ENABLED(CONFIG_X86) && !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + reg, 4, NULL); + if ( rc ) + goto fail; + } + continue; } if ( (val & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == @@ -605,6 +683,15 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( size == 0 ) { bars[i].type = VPCI_BAR_EMPTY; + + if ( !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + reg, 4, NULL); + if ( rc ) + goto fail; + } + continue; } @@ -612,28 +699,40 @@ static int cf_check init_bars(struct pci_dev *pdev) bars[i].size = size; bars[i].prefetchable = val & PCI_BASE_ADDRESS_MEM_PREFETCH; - rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, 4, - &bars[i]); + rc = vpci_add_register(pdev->vpci, + is_hwdom ? vpci_hw_read32 : guest_bar_read, + is_hwdom ? bar_write : guest_bar_write, + reg, 4, &bars[i]); if ( rc ) goto fail; } - /* Check expansion ROM. */ - rc = pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size, PCI_BAR_ROM); - if ( rc > 0 && size ) + /* TODO: Check expansion ROM, we do not handle ROM for guests for now. */ + if ( is_hwdom ) { - struct vpci_bar *rom = &header->bars[num_bars]; + rc = pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size, PCI_BAR_ROM); + if ( rc > 0 && size ) + { + struct vpci_bar *rom = &header->bars[num_bars]; - rom->type = VPCI_BAR_ROM; - rom->size = size; - rom->addr = addr; - header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) & - PCI_ROM_ADDRESS_ENABLE; + rom->type = VPCI_BAR_ROM; + rom->size = size; + rom->addr = addr; + header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) & + PCI_ROM_ADDRESS_ENABLE; - rc = vpci_add_register(pdev->vpci, vpci_hw_read32, rom_write, rom_reg, - 4, rom); + rc = vpci_add_register(pdev->vpci, vpci_hw_read32, rom_write, + rom_reg, 4, rom); + if ( rc ) + rom->type = VPCI_BAR_EMPTY; + } + } + else + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + rom_reg, 4, NULL); if ( rc ) - rom->type = VPCI_BAR_EMPTY; + goto fail; } return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 2a0ae34500..89f1e27f4f 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -67,7 +67,10 @@ struct vpci { struct vpci_header { /* Information about the PCI BARs of this device. */ struct vpci_bar { + /* Physical (host) address. */ uint64_t addr; + /* Guest address. */ + uint64_t guest_addr; uint64_t size; enum { VPCI_BAR_EMPTY, From patchwork Tue Aug 29 23:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369788 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 93C5EC83F17 for ; Tue, 29 Aug 2023 23:20:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592517.925324 (Exim 4.92) (envelope-from ) id 1qb80D-0000rk-Kn; Tue, 29 Aug 2023 23:20:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592517.925324; Tue, 29 Aug 2023 23:20:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80D-0000rG-Fd; Tue, 29 Aug 2023 23:20:05 +0000 Received: by outflank-mailman (input) for mailman id 592517; Tue, 29 Aug 2023 23:20:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80B-0007EX-F9 for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:03 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 93f9ed1d-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:20:02 +0200 (CEST) Received: from pps.filterd (m0174677.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TKDecm030691; Tue, 29 Aug 2023 23:19:52 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3sshtetfcp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:52 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:45 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:45 +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: 93f9ed1d-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Icmb26UvD1z+KWlMUVemiuBpEtTYvaSNQp3kEVorW1qDpwi8uAjXlH5RUgTvJsIiXvI/kyfrax+hO9o3MxQyoGKMi5eEMInmiYt6VQctTAZ1X5U0KO6YQnigHIjTA41jP8cbpIYhxvp67zi4BySnfI8Aj3F4ZIVUWa5Bl2uw41rXZYRwOvgqDvpE/kTKX9KnaMFEzF3ydTpKpxeEGsUDW16pr+GRikRlgYrv7Z2Nbz7rPytGSPzZkGsMFb06jkW2dD3AWcMFLNhFBacwBuULat1zCwA2ZhW29yBom9eCIiwJcB0es3AgVrTC/VEZ0nIy/++LWUBD0PwelNIepABoJg== 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=jjS0nFuqFuSdf3gFcW5nJsYmqeDtBC3mtmNRbovyY70=; b=Ziex8bShAWZYMFItYPTilQGCa0ODoINaSB0WQnA64C700hGGjnM6tYOHb3u9n24Z60FIZStAnRTeicxc+eQksfsxuXBngCQU0iwS6mOV8MZgtr8/vEZnLrCJQtpKM09rAiDeK3ShuVmMtqYwNx3u07lQWIKxhs+dWlLDeTEVEiE/u7E9d4MvyzExYDHnnXtuU8uQA+hX9p1Z1WMMdkukc0SIbD9i9BgA4t8M9T8p+jbjxWY/Z4K2mRGljwaKRCzAqHFBftgf8spxl6znICtv5SqTvWwyDmhpY9z8gAW3Ktu0ZyKEAOAus45fA0WA00nRqMNNAfvGxvfzFp30EOS8Lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jjS0nFuqFuSdf3gFcW5nJsYmqeDtBC3mtmNRbovyY70=; b=f/b2FGT43zNP2gXa1t+OzlJMFdUSSxaT5mhTmllAggFLCnYZh45BHPzK9A2W7TwQ/uBGCPNgVsi7XkBn9MTSImZL4roYTfQzL/OvoY5ZibzS54GFhQDXpKmi8JIAtPXziWLvnRLw5jM6Ie3BY/7rNcurcfmPmjdnhUAtYmjzuZLxGAoUR7nzn+nEnzp6rwJOdYSJJc1NIUHM758jtJrdSr2Rpof97+6ZaY3KNNJjz/Co/JPlrgjha6VfuYBRoc/m1ESZpV3cqpMW8sc/CdJfEwpb2selKXACnTlUEPjm71zlk/y68lvDuLa5NTkU/8DrNvO6CMpEYGmUOmMz8MMakw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v9 07/16] rangeset: add RANGESETF_no_print flag Thread-Topic: [PATCH v9 07/16] rangeset: add RANGESETF_no_print flag Thread-Index: AQHZ2s9LxSREsqGkPUWRRkHWekAfhA== Date: Tue, 29 Aug 2023 23:19:43 +0000 Message-ID: <20230829231912.4091958-8-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: adf7c655-f039-41a8-0595-08dba8e66e99 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KgVX92iPgIByspsHr9hFTisn4c7Z+2+BcslYMswnbeedK4t2VW+WLsl94qjgdyw1RY32ecQCd3YAW8rPnZ7oA7CEupq4WsYSwNjkXcgNtpCAQbkWL+jDnKB1kIvjm9R3sy1wenCzxMUgfG0ERllcazBf4oT47zR5KFO25Fz9vazPx3z3GDFK8cnvEuY/FcOWOV/1C0eod9Cnf+9It0LHlzStke7Sl3dhbNWZQjD5RrE2KdRuVNL3VjgANehQmrGMIeCbCBdxIuFcLtZ8V6Lck/scNu+2pKapQXlXJkSc7RhhIv/L1H7jq6/12iFIXPXbkiIuxOGlRo7OZamAw8FNC2uPRVsa9MtO4ijXW8hsCavGgAwLue4lqQSpHgBOpdtv4C7Hods5VLrU8ADex7FhDU+a37iYdoH2bpAxC3XxtYcmXTTOKMtcU1KINOVQpiP2SL/GQhXiJkv0Ssb6L4F4ijZ1SiA7NzUM626BsuWQElD4buQl9lqpwC9ja/a8tq11y9b6ILT2fmB/01NVfmDKll6QVLrhZohQU6jSKsroaRhkl8WQVvg8zeirxc8eA8cg/z2LIWJcY9as4sxB9uSDFyKM0SKE46zwgyv8J7XycNZX0zLP62uLdEZIBswE5Jao x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?2/qme8rgsetRaGl4VbBjMRw?= =?iso-8859-1?q?8phHCEvzFd1ZSJMX/I3gsCQvCU+Yu3Vmp/xh800mVJXBignmogGzFyG1uxrb?= =?iso-8859-1?q?k6j7nKMItX2KQ2YnyxlsQD1ASkTWCaoarHFi/pEGY9wW3XDTHIA/lpJmQNsR?= =?iso-8859-1?q?6iqngL3Wp3guwyITT+1fvZ6Fm5boMpkH9LWDgfUUuNHLgPF9E0WT5FZ4ik3V?= =?iso-8859-1?q?13CLHkXkfmiyO77eVg7CQw+kcMmMiHoRB5dHl0r7v/cOfajFd6QY/QwpV9aV?= =?iso-8859-1?q?o4Lm1gcYeBL/TX/3jhvmvW0rsdtQ62JPBNDSDviVVM0UTtY4iI8pHZIUuFVu?= =?iso-8859-1?q?bJTdrkgktliKbtBgnSv+Ksp9cjjhmGYM7sECd3vLgbVbVYa2vb9rBEwfJ4Aj?= =?iso-8859-1?q?+4OH/ERkJwPlxGZGLfC1bcDINLr9w8SluZHEVvqkz9aoZwUJGUGcCbvu6Rfb?= =?iso-8859-1?q?EGizjRe6sLR45DN32EmZvs5SuK/lq1IBqf4eiUXn1Wk4/k8UFRHZQovQbr48?= =?iso-8859-1?q?UM8rtagLh5FC13qLVxUSkPYhSpVLHTbJSYYFq5w16aEwY/cEV0ajUQspLoCn?= =?iso-8859-1?q?jetXClBOdmeWZ8JciHOjDbPg6x+0tYb4+Ld/Y1ntZSH2hux7xU6iIjA9M2W7?= =?iso-8859-1?q?elbB/YcPeweCZMJsRXCIzcT79Me3dH7eJHWXoJ7nXmslg1L62NpXqmV5KGO6?= =?iso-8859-1?q?xiPtkVKhdBdEStqb21LvTk9YO5mBR1cdyAm18bK7mPL8W/bBws22aeNCnVBv?= =?iso-8859-1?q?GBKrQtSCZ/VuICre19axwz/+cVdD4MQEWrTwKutXwuE0faVdG1AAZhjkGwh8?= =?iso-8859-1?q?YIY4bTSKG5pIpJsFzSa9jv9nt8DKmcIcC+QwUa0tYZi18Bf4WpFHUUV5vKJz?= =?iso-8859-1?q?tM11rQzdaw7X/yeP8zlyRqeY0uBLTYv5IiLWzUkWZ19/XbRTObYNsuLZnRAU?= =?iso-8859-1?q?VV5qV/TiB7HkOCfabS28iWLpMRd8jjwnoUXSk4kWKO3buSICpWnwsXKydg6Y?= =?iso-8859-1?q?zQgtUsWYyNzMRCqK2HkelWpc30AP+CH1eNbg6OKShAhqX/tCUIKO5WKIFzOu?= =?iso-8859-1?q?aSzaJORjPcxhObhf1UBHTIm6alYdt40YHOv/VzC2wn+74ggRsvdmXBeuToFF?= =?iso-8859-1?q?gwH1xPvwMij0fyTwvNXxbbnzsXsZPQmdRQpjDwCDMXHrhe2sPnJP4v+33tGz?= =?iso-8859-1?q?ax+ecRDkiwqCiYxqQXToWNdRDl4rirO/oDZ4q8V9GuZ6f0FMGJxnWZh9PQjh?= =?iso-8859-1?q?5vmB1/CcxnYjaTn+30sUquLfO+kEVz0l0nXQ9VxrhUPsFYeSXg1DEl5FfvLq?= =?iso-8859-1?q?mSda/G99qDLHr8Xt75MZ56yahT4vDpc/E0V46aBUxEYr4BRloTO7eZYHv5P7?= =?iso-8859-1?q?JdKvMkOljYg9NaHjCdZlo9oefbVKMcBL9RxmRisEFSk8JKlCBCIduvpNAyRa?= =?iso-8859-1?q?nSNIdbC6GAbDKJvBXpILvwJIpv5T8Lb4zuGNNMHvnLAsEP+GB9zFzCN0cued?= =?iso-8859-1?q?1/wmUJ5RMFHI1cTBqhLOsS+j/ZT57KY+wWxgxA4QU72NkUvfB2MfoX2Eyd76?= =?iso-8859-1?q?uximD7ouc0ZkRQBk3XS7LTrSCnf3eATB1BClund35M8uPKOiW6aWDAWmDiP7?= =?iso-8859-1?q?VwvGSth5gTyyfTEJWa5h5eBm8eLPGj5BlvwAzbw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: adf7c655-f039-41a8-0595-08dba8e66e99 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:43.9995 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: lHGgbFX6fwHUGgQlP8fjXDF/Xa7c9e2fgZ1sYi6st461q9y+zA+OY1nRTbGijdpyq5dFAqCcmlShldztNfcFs3ILo8Q92rRNr/3FYKTp+rs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: 8qJZuI2FK85W5VOYOAUcscNkg3AgoQFz X-Proofpoint-GUID: 8qJZuI2FK85W5VOYOAUcscNkg3AgoQFz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko There are range sets which should not be printed, so introduce a flag which allows marking those as such. Implement relevant logic to skip such entries while printing. While at it also simplify the definition of the flags by directly defining those without helpers. Suggested-by: Jan Beulich Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Jan Beulich --- Since v5: - comment indentation (Jan) Since v1: - update BUG_ON with new flag - simplify the definition of the flags --- xen/common/rangeset.c | 5 ++++- xen/include/xen/rangeset.h | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index f3baf52ab6..35c3420885 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -433,7 +433,7 @@ struct rangeset *rangeset_new( INIT_LIST_HEAD(&r->range_list); r->nr_ranges = -1; - BUG_ON(flags & ~RANGESETF_prettyprint_hex); + BUG_ON(flags & ~(RANGESETF_prettyprint_hex | RANGESETF_no_print)); r->flags = flags; safe_strcpy(r->name, name ?: "(no name)"); @@ -575,6 +575,9 @@ void rangeset_domain_printk( list_for_each_entry ( r, &d->rangesets, rangeset_list ) { + if ( r->flags & RANGESETF_no_print ) + continue; + printk(" "); rangeset_printk(r); printk("\n"); diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h index 135f33f606..f7c69394d6 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -49,8 +49,9 @@ void rangeset_limit( /* Flags for passing to rangeset_new(). */ /* Pretty-print range limits in hexadecimal. */ -#define _RANGESETF_prettyprint_hex 0 -#define RANGESETF_prettyprint_hex (1U << _RANGESETF_prettyprint_hex) +#define RANGESETF_prettyprint_hex (1U << 0) + /* Do not print entries marked with this flag. */ +#define RANGESETF_no_print (1U << 1) bool_t __must_check rangeset_is_empty( const struct rangeset *r); From patchwork Tue Aug 29 23:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369799 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 DCF1DC6FA8F for ; Tue, 29 Aug 2023 23:20:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592510.925254 (Exim 4.92) (envelope-from ) id 1qb806-0007Ez-Q0; Tue, 29 Aug 2023 23:19:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592510.925254; Tue, 29 Aug 2023 23:19:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb806-0007Eq-N1; Tue, 29 Aug 2023 23:19:58 +0000 Received: by outflank-mailman (input) for mailman id 592510; Tue, 29 Aug 2023 23:19:57 +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 1qb805-0006kQ-AE for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:57 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8f99a568-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:19:54 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9l021983; Tue, 29 Aug 2023 23:19:53 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:52 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:45 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:45 +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: 8f99a568-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FV3H8rZYXDYTzPS4fqPmNKu4UiDH88cmvzJfganFHNcaJVxsLWju/ssNqgImIEtggf1zJT271dGCtRGxG5AclA10mKqURanAW4rjNP+qsS81qA99k/sWFHMiAMkZIvvaXp7Zuge8WXGGhigQOWMBDwPJyIpXyTncymlzxxET2MeqtuSMLRWIOeJZH1DixiwaWjWMB60JBOHFTrWUNmxCwTr7DBJKTSkLW3YX9ijPVWQwM4vG710/qqP9QTYTdH2goy2pksfYPFdwScJztsItu3QyztmFKyPaQmFPbNG9aJH3/IwPmK6nQKuDmbf/VoUUyy3azCODyOgdkgZi5WGCkw== 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=X1T2UJXkQjdsdtIQpkDJsKMdD2XLW/kPWKtbqM3Lrtc=; b=PMceko1KiTM0MD+7fjqEzTzoYyLXzxSOVNO0vDSkQAoD5r9flpU8i7BqsMxDti4p1YUscPA4pZ+7qiVAJJIV7aakb/ZjzOzuhFOBAF02fr4/9Vqe6jgwx1adShqGQNhv91W9Zw+zqhbNWTnw38d6fyFRY2HXxuJu6a0wbG73zughqWKDwn30k1Ok1dwL1F8IH4QYHSD7wAuvIySv+JH+YxAjxTPZdij+oLpgzjBd2RJexwZJpggUGP4tp7jbUp1cikXWK+o6t5qOZV0gt/S3mXSPGf5AlVsR6P8wd6QCIHY0oXDwT5XQr+/0WZGvk8SDS2q0PddiBBJoCFbTk1EL0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X1T2UJXkQjdsdtIQpkDJsKMdD2XLW/kPWKtbqM3Lrtc=; b=o6eaGIYaRBzqMURQipCCq1FWuqmy8xx4McVRNSbC2kteHiDmB/Dm+BvL7b3HtxIzPo7zPY9X9HzFXtC0a/5DuMmocvY+gDShjrpl+txgw6oKGHKYr2NB99KASmynFSyca4GfLszs+PF1I/RotbpV6Hpa1eExcb9tmpmJwHLvXumNlCn5kqQx6ag/12vfdKDIqS1UvVkzpdDcgTOm0+Yw5MBIQg2WE0wwzjalPC7u5zssQg/BvzzgN9bdzHB+nlnW22o6YfFtydSAb0tLy3J2Fju4OL0zHM0yCvc6oLYfA0maAQ1pal2AZprh46TmlRsKWdVEHN3X8DwKB5XM8uTWig== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v9 08/16] vpci/header: handle p2m range sets per BAR Thread-Topic: [PATCH v9 08/16] vpci/header: handle p2m range sets per BAR Thread-Index: AQHZ2s9Ln5ZnmFXk3EWGqNE8Hf9gXg== Date: Tue, 29 Aug 2023 23:19:44 +0000 Message-ID: <20230829231912.4091958-9-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: c1561186-e07b-4bac-dade-08dba8e66ecf x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KesU/7wVavgKYkVrseutGKfHbdscHa0FNs5OybRl7QonSLJklJ1V4sEiDO78JhLCechojgmiyp+mO1gojiF3VAu0paTZfH9O1F5Dd6xH/2Shzfqaf/ibJbM6/inlMRp+w1gpnlwBqn+5NFbuTWtj2VP+ZHB3m6moLBDalVSzyKgUioT0PxOqzHo2MtP5Vdr2OS8RN31raxi9EkjsC5P8bkjaosCDYgvT1ZsK5oKlURjph+B2ZZyXE7LpQY/S8o1mCX1GX2BIui7TXoafXHNpI7PrBWM35IvhxVnPeYDp+Mz8+INJmhC3614trKBtLo9tDWM9a4BlD1cu7Hpo7KXYbmv94heaUYqzcmmjeBP10/adJRKLcsOR8ja9fQG8UiyHO/JGxdarqP9O/GndMtclPiwsp2AWxyqNtqrumFivXE39Bah/jNS+8qlAdiMMbPtVGBCJraiIDKPT2dZg6sR+P3478CuCpq4jLsxzS6xNFD9ixO6GYnc6G0paPykSoXOoxy5coixzFjDtvt0svbbBSS9+h0nzMqswes2czKbn5hv0TI0Blp56qpcFukvHwbETPQM5upN79YC2+EbyirBW7piQeQz9XNiY9NAHvAPe1WJJUKWEzdikgPVJCSJls+cc x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(30864003)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?79rNKUuXOIB3QABFAfib10C?= =?iso-8859-1?q?2rC012XnASAHNBR5SUl31wpVu3KablOjZZ10X8fuRDe68ygdipt6pYU7dlg0?= =?iso-8859-1?q?kpcoOXnH/319Sa48zO8q108kdL/VdipLFxZ27pUrW+Fo9qmw08jzxhBQFyND?= =?iso-8859-1?q?YB5Rs6K7PphYlee1kU3XjNpOndSgoYheZ69a9G/b6ruRypRo214lZlbzkGyw?= =?iso-8859-1?q?AvTlnNkU4OIAHPQB+glDSmVYlc02YqiKXRNfkL2EysmipY/E8I7Jz8ajoMQy?= =?iso-8859-1?q?ozsDavpLCMxsIZCysVqeQdvjqYPureea8PWO88sK/l7Loch5ZujXLqFVBYr0?= =?iso-8859-1?q?gJrOSHiuvuKX8CvC0HYWj9ry26xe0S9W8fcLxbciZUMZG0USI56VvPkRuXc8?= =?iso-8859-1?q?XN31/ahr9H0LsQ6fYB4AqFKPIBKYMD+gxcXRQiefiXeLEH4qRgn+wpbrMO4p?= =?iso-8859-1?q?GSHXJGGRF8NyfPL0OeKWZxCWqsYeS6aXOkNTjpybpHbGAhfqx6jrI1rVit89?= =?iso-8859-1?q?RU70aHMASdryfpIlZyVyIGAGxWu+V6vP4CzPcxszufTCFcA/jW10wiOzjKQ4?= =?iso-8859-1?q?JDJ/m7dRtw/mVHlMGkUY8Pqf1pA+zPGznGZZ7lRS9DZss6BDcEQsUruWUz6k?= =?iso-8859-1?q?IeYAKzzZS/gKyHl63ZeKwrKYqFdqqE9oF/nAJ+47acqBY95ESY0zrVmUPwci?= =?iso-8859-1?q?hFxi0UaLCAQvmcerGxOOh/25jW0gjTzNVW3YH5+1CXk7gsw2gajoXg591dFz?= =?iso-8859-1?q?4yHPUKIbqAvLWn1MR2h3u/Ld1yB2l4l7CYP/YUP0ekcnNYJ5zFUXe2wK2WKQ?= =?iso-8859-1?q?0pZeCmNS2LZoJFiFVXFeWfNNPhqCwPt/depKKHZtic8yZLuoPgkNSyeBPJzS?= =?iso-8859-1?q?bUE8xuT8PmujVJ6V/O2XaXTTpLXzR1IVJORA1fsJgaCzqtxP/V0eNW6SxLnP?= =?iso-8859-1?q?SuKUOvdnxL0/WFR2e3yWPJeYQkcYmE/vY8v+NEZG9IRuXgNiDosTYZk9sTYs?= =?iso-8859-1?q?xxGJ41Hy1+50Yj0SOUHUoGYCl4Pi4YrKev39snfFqfkDC6H4zA0s6jrR7lXP?= =?iso-8859-1?q?ZNH7upyVLogNrBJbj4S6fqsOmmc4I1L6Ed7sdmpfqdVUibyAwQGJnh6txSxj?= =?iso-8859-1?q?Bp7GQYjwuuYQmz1GjZysXoudi9GoNNOxdANl1fvejwDzMp2wDve1VPOr/q8P?= =?iso-8859-1?q?xD2Dy9LpuS32F4KZ3EGVFwGwYjgRnefZDNtuzlHhBORqN2L/zgWEYsCE4YKE?= =?iso-8859-1?q?QnCn7N+noc628uMcjRiZAEkCPdAunrhnLcQv4L/jUsMQNrbYJM2B5zb5sMfe?= =?iso-8859-1?q?uQc65ZRaxUHjK8A4TNb4QYIH/CvGcigtKPxCls5EzkBojtlpCt+QVw1pGc4Q?= =?iso-8859-1?q?Dkf1T0q2GxeHcpMXG7KTcb1g/PqU5wWuR+v+qSoQCfvZsQ8IYJy1imU4Mt/q?= =?iso-8859-1?q?juIKwpwpQZePcaauM/UaDe8vL+NJF4G4AMR8XL1lwDYmzeGtp70F5xsA/zAr?= =?iso-8859-1?q?lLuaSb5eSg71pI7VgkbG9O8ti5i+T/vBki+9oqqyB+DT18QN/ve72KObqvAU?= =?iso-8859-1?q?roS3hSmPw6782SQU8C0AhvCp3+P8z43LmRC45BO0I+gbX4HZWip3g437Vzpy?= =?iso-8859-1?q?58hMmDo7tGQiKImIvQ3yqza0jUbhuktVo5h7KlA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1561186-e07b-4bac-dade-08dba8e66ecf X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:44.3700 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SxMJXhYHRNSmyv2zdedX9zTxqM7n9BBXPdT+WHU7q5IlyEon13baRwK5I/AHHJppkxTjY9IdQVem//aiW5v0JiWR8U6qgWT1lWT4kAqdXxM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: 51EHbfHAcAxSSBGUCrGxQHmnYd4IRMog X-Proofpoint-GUID: 51EHbfHAcAxSSBGUCrGxQHmnYd4IRMog X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Instead of handling a single range set, that contains all the memory regions of all the BARs and ROM, have them per BAR. As the range sets are now created when a PCI device is added and destroyed when it is removed so make them named and accounted. Note that rangesets were chosen here despite there being only up to 3 separate ranges in each set (typically just 1). But rangeset per BAR was chosen for the ease of implementation and existing code re-usability. This is in preparation of making non-identity mappings in p2m for the MMIOs. Signed-off-by: Oleksandr Andrushchenko --- Since v9: - removed d->vpci.map_pending in favor of checking v->vpci.pdev != NULL - printk -> gprintk - renamed bar variable to fix shadowing - fixed bug with iterating on remote device's BARs - relaxed lock in vpci_process_pending - removed stale comment Since v6: - update according to the new locking scheme - remove odd fail label in modify_bars Since v5: - fix comments - move rangeset allocation to init_bars and only allocate for MAPPABLE BARs - check for overlap with the already setup BAR ranges Since v4: - use named range sets for BARs (Jan) - changes required by the new locking scheme - updated commit message (Jan) Since v3: - re-work vpci_cancel_pending accordingly to the per-BAR handling - s/num_mem_ranges/map_pending and s/uint8_t/bool - ASSERT(bar->mem) in modify_bars - create and destroy the rangesets on add/remove --- xen/drivers/vpci/header.c | 252 ++++++++++++++++++++++++++------------ xen/drivers/vpci/vpci.c | 6 + xen/include/xen/vpci.h | 2 +- 3 files changed, 180 insertions(+), 80 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index e96d7b2b37..3cc6a96849 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -161,63 +161,101 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, bool vpci_process_pending(struct vcpu *v) { - if ( v->vpci.mem ) + struct pci_dev *pdev = v->vpci.pdev; + struct map_data data = { + .d = v->domain, + .map = v->vpci.cmd & PCI_COMMAND_MEMORY, + }; + struct vpci_header *header = NULL; + unsigned int i; + + if ( !pdev ) + return false; + + read_lock(&v->domain->pci_lock); + header = &pdev->vpci->header; + for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { - struct map_data data = { - .d = v->domain, - .map = v->vpci.cmd & PCI_COMMAND_MEMORY, - }; - int rc = rangeset_consume_ranges(v->vpci.mem, map_range, &data); + struct vpci_bar *bar = &header->bars[i]; + int rc; + + if ( rangeset_is_empty(bar->mem) ) + continue; + + rc = rangeset_consume_ranges(bar->mem, map_range, &data); if ( rc == -ERESTART ) + { + read_unlock(&v->domain->pci_lock); return true; + } - write_lock(&v->domain->pci_lock); - spin_lock(&v->vpci.pdev->vpci->lock); - /* Disable memory decoding unconditionally on failure. */ - modify_decoding(v->vpci.pdev, - rc ? v->vpci.cmd & ~PCI_COMMAND_MEMORY : v->vpci.cmd, - !rc && v->vpci.rom_only); - spin_unlock(&v->vpci.pdev->vpci->lock); - - rangeset_destroy(v->vpci.mem); - v->vpci.mem = NULL; if ( rc ) - /* - * FIXME: in case of failure remove the device from the domain. - * Note that there might still be leftover mappings. While this is - * safe for Dom0, for DomUs the domain will likely need to be - * killed in order to avoid leaking stale p2m mappings on - * failure. - */ - vpci_deassign_device(v->vpci.pdev); - write_unlock(&v->domain->pci_lock); + { + spin_lock(&pdev->vpci->lock); + /* Disable memory decoding unconditionally on failure. */ + modify_decoding(pdev, v->vpci.cmd & ~PCI_COMMAND_MEMORY, + false); + spin_unlock(&pdev->vpci->lock); + + v->vpci.pdev = NULL; + + read_unlock(&v->domain->pci_lock); + + if ( is_hardware_domain(v->domain) ) + { + write_lock(&v->domain->pci_lock); + vpci_deassign_device(v->vpci.pdev); + write_unlock(&v->domain->pci_lock); + } + else + { + domain_crash(v->domain); + } + return false; + } } + read_unlock(&v->domain->pci_lock); + + v->vpci.pdev = NULL; + + spin_lock(&pdev->vpci->lock); + modify_decoding(pdev, v->vpci.cmd, v->vpci.rom_only); + spin_unlock(&pdev->vpci->lock); return false; } static int __init apply_map(struct domain *d, const struct pci_dev *pdev, - struct rangeset *mem, uint16_t cmd) + uint16_t cmd) { struct map_data data = { .d = d, .map = true }; - int rc; + struct vpci_header *header = &pdev->vpci->header; + int rc = 0; + unsigned int i; ASSERT(rw_is_locked(&d->pci_lock)); - while ( (rc = rangeset_consume_ranges(mem, map_range, &data)) == -ERESTART ) + for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { - /* - * It's safe to drop and reacquire the lock in this context - * without risking pdev disappearing because devices cannot be - * removed until the initial domain has been started. - */ - read_unlock(&d->pci_lock); - process_pending_softirqs(); - read_lock(&d->pci_lock); - } + struct vpci_bar *bar = &header->bars[i]; - rangeset_destroy(mem); + if ( rangeset_is_empty(bar->mem) ) + continue; + + while ( (rc = rangeset_consume_ranges(bar->mem, map_range, + &data)) == -ERESTART ) + { + /* + * It's safe to drop and reacquire the lock in this context + * without risking pdev disappearing because devices cannot be + * removed until the initial domain has been started. + */ + write_unlock(&d->pci_lock); + process_pending_softirqs(); + write_lock(&d->pci_lock); + } + } if ( !rc ) modify_decoding(pdev, cmd, false); @@ -225,10 +263,12 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, } static void defer_map(struct domain *d, struct pci_dev *pdev, - struct rangeset *mem, uint16_t cmd, bool rom_only) + uint16_t cmd, bool rom_only) { struct vcpu *curr = current; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + /* * FIXME: when deferring the {un}map the state of the device should not * be trusted. For example the enable bit is toggled after the device @@ -236,7 +276,6 @@ static void defer_map(struct domain *d, struct pci_dev *pdev, * started for the same device if the domain is not well-behaved. */ curr->vpci.pdev = pdev; - curr->vpci.mem = mem; curr->vpci.cmd = cmd; curr->vpci.rom_only = rom_only; /* @@ -250,33 +289,33 @@ static void defer_map(struct domain *d, struct pci_dev *pdev, static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) { struct vpci_header *header = &pdev->vpci->header; - struct rangeset *mem = rangeset_new(NULL, NULL, 0); struct pci_dev *tmp, *dev = NULL; const struct domain *d; const struct vpci_msix *msix = pdev->vpci->msix; - unsigned int i; + unsigned int i, j; int rc; ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); - if ( !mem ) - return -ENOMEM; - /* - * Create a rangeset that represents the current device BARs memory region - * and compare it against all the currently active BAR memory regions. If - * an overlap is found, subtract it from the region to be mapped/unmapped. + * Create a rangeset per BAR that represents the current device memory + * region and compare it against all the currently active BAR memory + * regions. If an overlap is found, subtract it from the region to be + * mapped/unmapped. * - * First fill the rangeset with all the BARs of this device or with the ROM + * First fill the rangesets with the BAR of this device or with the ROM * BAR only, depending on whether the guest is toggling the memory decode * bit of the command register, or the enable bit of the ROM BAR register. */ for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { - const struct vpci_bar *bar = &header->bars[i]; + struct vpci_bar *bar = &header->bars[i]; unsigned long start = PFN_DOWN(bar->addr); unsigned long end = PFN_DOWN(bar->addr + bar->size - 1); + if ( !bar->mem ) + continue; + if ( !MAPPABLE_BAR(bar) || (rom_only ? bar->type != VPCI_BAR_ROM : (bar->type == VPCI_BAR_ROM && !header->rom_enabled)) || @@ -292,14 +331,31 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) continue; } - rc = rangeset_add_range(mem, start, end); + rc = rangeset_add_range(bar->mem, start, end); if ( rc ) { printk(XENLOG_G_WARNING "Failed to add [%lx, %lx]: %d\n", start, end, rc); - rangeset_destroy(mem); return rc; } + + /* Check for overlap with the already setup BAR ranges. */ + for ( j = 0; j < i; j++ ) + { + struct vpci_bar *prev_bar = &header->bars[j]; + + if ( rangeset_is_empty(prev_bar->mem) ) + continue; + + rc = rangeset_remove_range(prev_bar->mem, start, end); + if ( rc ) + { + gprintk(XENLOG_WARNING, + "%pp: failed to remove overlapping range [%lx, %lx]: %d\n", + &pdev->sbdf, start, end, rc); + return rc; + } + } } /* Remove any MSIX regions if present. */ @@ -309,14 +365,21 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) unsigned long end = PFN_DOWN(vmsix_table_addr(pdev->vpci, i) + vmsix_table_size(pdev->vpci, i) - 1); - rc = rangeset_remove_range(mem, start, end); - if ( rc ) + for ( j = 0; j < ARRAY_SIZE(header->bars); j++ ) { - printk(XENLOG_G_WARNING - "Failed to remove MSIX table [%lx, %lx]: %d\n", - start, end, rc); - rangeset_destroy(mem); - return rc; + const struct vpci_bar *bar = &header->bars[j]; + + if ( rangeset_is_empty(bar->mem) ) + continue; + + rc = rangeset_remove_range(bar->mem, start, end); + if ( rc ) + { + gprintk(XENLOG_WARNING, + "%pp: failed to remove MSIX table [%lx, %lx]: %d\n", + &pdev->sbdf, start, end, rc); + return rc; + } } } @@ -356,27 +419,34 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) for ( i = 0; i < ARRAY_SIZE(tmp->vpci->header.bars); i++ ) { - const struct vpci_bar *bar = &tmp->vpci->header.bars[i]; - unsigned long start = PFN_DOWN(bar->addr); - unsigned long end = PFN_DOWN(bar->addr + bar->size - 1); - - if ( !bar->enabled || - !rangeset_overlaps_range(mem, start, end) || - /* - * If only the ROM enable bit is toggled check against - * other BARs in the same device for overlaps, but not - * against the same ROM BAR. - */ - (rom_only && tmp == pdev && bar->type == VPCI_BAR_ROM) ) + const struct vpci_bar *remote_bar = &tmp->vpci->header.bars[i]; + unsigned long start = PFN_DOWN(remote_bar->addr); + unsigned long end = PFN_DOWN(remote_bar->addr + + remote_bar->size - 1); + + if ( !remote_bar->enabled ) continue; - rc = rangeset_remove_range(mem, start, end); - if ( rc ) + for ( j = 0; j < ARRAY_SIZE(header->bars); j++) { - printk(XENLOG_G_WARNING "Failed to remove [%lx, %lx]: %d\n", - start, end, rc); - rangeset_destroy(mem); - return rc; + const struct vpci_bar *bar = &header->bars[j]; + if ( !rangeset_overlaps_range(bar->mem, start, end) || + /* + * If only the ROM enable bit is toggled check against + * other BARs in the same device for overlaps, but not + * against the same ROM BAR. + */ + (rom_only && tmp == pdev && bar->type == VPCI_BAR_ROM) ) + continue; + + rc = rangeset_remove_range(bar->mem, start, end); + if ( rc ) + { + gprintk(XENLOG_WARNING, + "%pp: failed to remove [%lx, %lx]: %d\n", + &pdev->sbdf, start, end, rc); + return rc; + } } } } @@ -400,10 +470,10 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) * will always be to establish mappings and process all the BARs. */ ASSERT((cmd & PCI_COMMAND_MEMORY) && !rom_only); - return apply_map(pdev->domain, pdev, mem, cmd); + return apply_map(pdev->domain, pdev, cmd); } - defer_map(dev->domain, dev, mem, cmd, rom_only); + defer_map(dev->domain, dev, cmd, rom_only); return 0; } @@ -595,6 +665,20 @@ static void cf_check rom_write( rom->addr = val & PCI_ROM_ADDRESS_MASK; } +static int bar_add_rangeset(const struct pci_dev *pdev, struct vpci_bar *bar, + unsigned int i) +{ + char str[32]; + + snprintf(str, sizeof(str), "%pp:BAR%d", &pdev->sbdf, i); + + bar->mem = rangeset_new(pdev->domain, str, RANGESETF_no_print); + if ( !bar->mem ) + return -ENOMEM; + + return 0; +} + static int cf_check init_bars(struct pci_dev *pdev) { uint16_t cmd; @@ -675,6 +759,10 @@ static int cf_check init_bars(struct pci_dev *pdev) else bars[i].type = VPCI_BAR_MEM32; + rc = bar_add_rangeset(pdev, &bars[i], i); + if ( rc ) + return rc; + rc = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size, (i == num_bars - 1) ? PCI_BAR_LAST : 0); if ( rc < 0 ) @@ -725,6 +813,12 @@ static int cf_check init_bars(struct pci_dev *pdev) rom_reg, 4, rom); if ( rc ) rom->type = VPCI_BAR_EMPTY; + else + { + rc = bar_add_rangeset(pdev, rom, i); + if ( rc ) + return rc; + } } } else diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 135d390218..412685f41d 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -38,6 +38,8 @@ extern vpci_register_init_t *const __end_vpci_array[]; void vpci_deassign_device(struct pci_dev *pdev) { + unsigned int i; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); if ( !has_vpci(pdev->domain) || !pdev->vpci ) @@ -63,6 +65,10 @@ void vpci_deassign_device(struct pci_dev *pdev) if ( pdev->vpci->msix->table[i] ) iounmap(pdev->vpci->msix->table[i]); } + + for ( i = 0; i < ARRAY_SIZE(pdev->vpci->header.bars); i++ ) + rangeset_destroy(pdev->vpci->header.bars[i].mem); + xfree(pdev->vpci->msix); xfree(pdev->vpci->msi); xfree(pdev->vpci); diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 89f1e27f4f..d77a6f9506 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -72,6 +72,7 @@ struct vpci { /* Guest address. */ uint64_t guest_addr; uint64_t size; + struct rangeset *mem; enum { VPCI_BAR_EMPTY, VPCI_BAR_IO, @@ -156,7 +157,6 @@ struct vpci { struct vpci_vcpu { /* Per-vcpu structure to store state while {un}mapping of PCI BARs. */ - struct rangeset *mem; struct pci_dev *pdev; uint16_t cmd; bool rom_only : 1; From patchwork Tue Aug 29 23:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369800 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 C3570C83F18 for ; Tue, 29 Aug 2023 23:20:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592516.925301 (Exim 4.92) (envelope-from ) id 1qb80B-0008Rh-1I; Tue, 29 Aug 2023 23:20:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592516.925301; Tue, 29 Aug 2023 23:20:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80A-0008KK-Ow; Tue, 29 Aug 2023 23:20:02 +0000 Received: by outflank-mailman (input) for mailman id 592516; Tue, 29 Aug 2023 23:20:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb808-0007EX-Qh for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:00 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 90f7682f-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:19:57 +0200 (CEST) Received: from pps.filterd (m0174677.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TKDecn030691; Tue, 29 Aug 2023 23:19:53 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3sshtetfcp-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:53 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:46 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:46 +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: 90f7682f-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OSs1iU1bICm52I2iQaMAh65m6EkaSWqIcwr8PG0Arg+X2YXFnVui+h6WKIoJ2Yr2BSGtk6UA0ratFHotlG2DiK2W01yamuyx+cvtpU49qmq4mPpnyMRAeLIwsJa1V1lw3jfM7y6/uxOk/pEIk41J8U5143sg4bIusQP7gBIs3q6ipAc5+bwJ9u6z+wIhfD8xbqRpljh3kQsDWZe/wi5P3HOgtKeoAz62kaIAiz7nRhxwD8rWXgRDkwFvOGUHNNzZooDqQ2/euAVDQkpjL2vJyJnGSEHzbpSF8KqJPyAuIofz4schPikcuIfkX57lLqSGIgF+mKzXqHLL++dV40rWEA== 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=+865b/wWNj0EWFhzOYa954eDivbVLOrScndgP/Dydu4=; b=khrAN9NxYaNMj+uPA2BLMfvKVIi+qmmJTw3vjcU9iXpvz7s/zzD0n5fjVkTiJGYn2YSI2jsNogTSp2p/XOyjHcRS5OJNJJXeNxMWU1xHwPc/hWcUj1ioJfGP4TD0kd5cuUTNmK3bvqSwl/XouD8syX4Ff59mH5a91LX5fkrcn9wK+cGZYfpPkhPOIBhmgK9Wqip6rIMYS5Ttb6numMcwL5vIBOJxUOHrs5xDW3W8iW8vEqPIQB0lX3IZqMuVJOkhjBhbQvkhehX4aNqCarAxt2RHlBDLv79vhdvMB0bSZPmOhuvcKiYoQ2bjrLU+vNkyuC+P84rzFTCVf8zbemNwJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+865b/wWNj0EWFhzOYa954eDivbVLOrScndgP/Dydu4=; b=czxCblDCsHIDI4y4BTYFyTU/I5zNmWYlDcJ57wEHfUVu4nTlX0d8eLEK9Es8a7/pyiUqaQYgu73ehxXYKZhhLEWB3mjpTyDbj9OiZPp/pnCvzQdklhgjCNmIa5PurcBgcnORVi6qYN2/4kYZT+ZrnS3dA/4wNZwNeLgcJ0FOfjdTtakRlHBnyi2e9B0Jq/imoHFddiK5GGtnHW1Yz9X22xqFH2atQmx5ddv13Gkz3AlosMTTr56MvP8xmvnkk/Gj3mo3YKr7pkt3Gh8Z8caFKPeZAMMvAS5UMsTqkZ7McFBk2pp8x23FPiVRT/FMBlDIXstua0yExWMnakpeS3+T4Q== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v9 09/16] vpci/header: program p2m with guest BAR view Thread-Topic: [PATCH v9 09/16] vpci/header: program p2m with guest BAR view Thread-Index: AQHZ2s9LsI9X1QGM2Uq0tBcOyguChw== Date: Tue, 29 Aug 2023 23:19:44 +0000 Message-ID: <20230829231912.4091958-10-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: f4d9b8d0-52ee-471a-affc-08dba8e66f06 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YW4QNAEyqGD25G/0nRrSv3u7AlwWV1aerxJXyo4moO7ctf/IapAMmKXL+6UabMo3AcsVdeCU2GMraKGDPtmw7emclujwjTIOFLhz00Xodm+sqdknXRlYLLAm4kYwZs88U8yn7JQWNt16bEIHVph+lw9VjU2kD/3QSPvi7TF5Bq4p7Ak51+IOReKHoPJ114JwOyK/2CeGy93al/upfIIOVd1uIiCzSScVddVfqfXFoUJMvcA+ul+TE6SYavAmu2ZS8C9ZkQZYIupIRVtVkixERIBAFK/CMAj8N49UZI5ZPDQxHUMQwZWV7hSk/6ghaCRiEMyHeabfQcCuRXpoDo1rHNvjA9FJroRVseIGKnA9JLQW+mUoRUp+wmxEQUThQdXEMJGVgZh7nHTBQjTML3HasEWf9Hevy82d01SvazqrxQizHT2jqLS9KKTakslCh8+Xo6S58XDHV/hIchlYzVRdjUhDmsWHaqYAO4TrM1BNHM4tETSCdicOTyXHhro/uednz29VWwwjAR0j9ChK2YGZk5DW3Ur4dhjVEhHPcphoFUgIkcVbIcHN043qePC0S+WigOAcB16cb50PawnOs5BIKx+bT8LtxCFRu4/aPntaz9dcz2JMUmvW8x7CQkikVn1g x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(107886003)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?eY4JkfDnITWXPdQcsv+YiWN?= =?iso-8859-1?q?w8UwDVaYKE/wV1gGXFp+HMhVWF3BcMGscyoKjE9wIK2oFVexxveX/Ln0jDwE?= =?iso-8859-1?q?VqpWZ4ibSv7s9PoXj+ZonS923IeDK5UCeKrhILFeaxLEhCo9ldmDnnugHDjZ?= =?iso-8859-1?q?81xjBtHg+BRbnDyq+IRZ+nR/NTsMAdvphj1OTKV3zXhIiUNb3dZlvTz+jGMx?= =?iso-8859-1?q?FukIM/h6WaSpe/EuF+TNQrk1Rc821lKwvoOsu/rfZt8XLHEHHiHedOIkHwVH?= =?iso-8859-1?q?nMEvvWy3uyNr1M2zlmUL9AaVQSjyTfFM2Au0kyvLDiicYI+qBuSBgBSb91jx?= =?iso-8859-1?q?9frhyN2UZOim42JUh8pwKjIGzlqqFsdRR+GeBm2CQKKYFqyplUXMEzLEQMSK?= =?iso-8859-1?q?RxXHyvAjO+4YsWmFLJIPYWVidbzx8YUuNuydh4qvJRpEqWY6b7PtIEdIxjEY?= =?iso-8859-1?q?ibwCEQgRz7P1rJAnfLaCUBPF9g03QLPswrHLXjJHIy7VGAaBmRRgfj7pUGiS?= =?iso-8859-1?q?Ia6aVwFDjXupEFR4VwqGPrSDzNrMu/q/FQC5LZiu/6/3A+gdL9/qf4soxfsX?= =?iso-8859-1?q?4t2jUsBF18t6p7jQkCGtFtTTVeLlr5BOJOfm38aEXwvIMoPFP/uTCfuRfv9E?= =?iso-8859-1?q?Wxhl3XYk9+KdUd3jj5IWa+2FoJe7pnp1gOUQIPbKFesflNxlXh/L5itJhDKJ?= =?iso-8859-1?q?ASaILTQvRzspewBLqGN+aVt8HEtjPjxnt8aDRr8lpWjY9PuAHMJ9Yrp4qpwz?= =?iso-8859-1?q?nYNQIjpSNzyCNqlyYffbjN+VYiaeD5nF4o4G+XskF5xKg3s+CCJH3cCJpnLY?= =?iso-8859-1?q?rNZMcjuOTjll0xGpdcyDYT08fWY3UMoFByQFyJuytubcWl5cUv3Dj1JuyTl8?= =?iso-8859-1?q?IZGaczB2/RKhHtt5Oi84o0Oi6e7Nkq1lGB0SW7bKzigh+KW/2iG14GZlPEUQ?= =?iso-8859-1?q?hVOVpVZdlVYPVBo94lxC16Pqcvb9hyd3decEKPjuVyVTQQjZiZYz99kzS4aW?= =?iso-8859-1?q?IrCgP6vVr7aPvlLP/WNiPDP9eCbqv/D8iX8MQF+nAUDAOEYWXs0JSdB2+ISm?= =?iso-8859-1?q?vWOP1BHANUOxa+FuNimVGAtK/YbYUOtISjE1bqjYuiTM35/opjhudPceii0L?= =?iso-8859-1?q?FPrxPWaQmF144P9Jft9QL+zG2ej0gCwEtGemAEPl7Mff4L0Jzi6iSUb0khn4?= =?iso-8859-1?q?M/HbXkOy1alrcUFj1yKU8jm3eY+0hxMimhKZMOhagQi5cVeDnE4Tq4cV1EST?= =?iso-8859-1?q?e3jTbLjPelkmswFCiBm713OhDl1WwkSFe+Mw6+/kcJ3ulU06/EXlDNiOtuSM?= =?iso-8859-1?q?QevOJo2h+A291GMqOqjdSCYLRzUlIQGHJ6dgacc5ZnJ5z6f2ESN3Zt/sHy+i?= =?iso-8859-1?q?3MTlISlJLnsLEYOAj5AHEpcQYwAw0j2bi7Wia/TCGEq08etRnBNaiGQ41tTi?= =?iso-8859-1?q?PnhBw6sP+NFKpM0Ay3l53VhWumF/qBfiolxGYw5/E4Yell5yoIkAiDrpc43H?= =?iso-8859-1?q?hDYPAzd05AJV21U/jfGv5SH+PI5A4Ge5MnnHFuaDm9yTQzg57iegdP2p4/GA?= =?iso-8859-1?q?eH0usl7cliyb2vIlCscmNbiWoH3p8i5udHaQeaEl0AXkkQoGV1ZCMomM2G6w?= =?iso-8859-1?q?TnD1cMX7/QpvgrMlxXI8Rv+dLx/1bnXZ/iplnoA=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4d9b8d0-52ee-471a-affc-08dba8e66f06 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:44.6371 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: bHeXT79Li8+nP0oKS63u0m826gne51eMqkKhDEzOOgBd9ZKFSTi/UG2q2n6ZDw7H2jJknlD+9lgT7drUmRydVvZwKlag2BcPsooEsWiluNs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: ceyT-8jLF7Qk1-FSkN6pMMDVOko9niTd X-Proofpoint-GUID: ceyT-8jLF7Qk1-FSkN6pMMDVOko9niTd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Take into account guest's BAR view and program its p2m accordingly: gfn is guest's view of the BAR and mfn is the physical BAR value. This way hardware domain sees physical BAR values and guest sees emulated ones. Hardware domain continues getting the BARs identity mapped, while for domUs the BARs are mapped at the requested guest address without modifying the BAR address in the device PCI config space. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- Since v9: - Extended the commit message - Use bar->guest_addr in modify_bars - Extended printk error message in map_range - Moved map_data initialization so .bar can be initialized during declaration Since v5: - remove debug print in map_range callback - remove "identity" from the debug print Since v4: - moved start_{gfn|mfn} calculation into map_range - pass vpci_bar in the map_data instead of start_{gfn|mfn} - s/guest_addr/guest_reg Since v3: - updated comment (Roger) - removed gfn_add(map->start_gfn, rc); which is wrong - use v->domain instead of v->vpci.pdev->domain - removed odd e.g. in comment - s/d%d/%pd in altered code - use gdprintk for map/unmap logs Since v2: - improve readability for data.start_gfn and restructure ?: construct Since v1: - s/MSI/MSI-X in comments --- xen/drivers/vpci/header.c | 52 ++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 3cc6a96849..1e82217200 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -33,6 +33,7 @@ struct map_data { struct domain *d; + const struct vpci_bar *bar; bool map; }; @@ -44,6 +45,12 @@ static int cf_check map_range( for ( ; ; ) { + /* Start address of the BAR as seen by the guest. */ + gfn_t start_gfn = _gfn(PFN_DOWN(is_hardware_domain(map->d) + ? map->bar->addr + : map->bar->guest_addr)); + /* Physical start address of the BAR. */ + mfn_t start_mfn = _mfn(PFN_DOWN(map->bar->addr)); unsigned long size = e - s + 1; if ( !iomem_access_permitted(map->d, s, e) ) @@ -63,6 +70,13 @@ static int cf_check map_range( return rc; } + /* + * Ranges to be mapped don't always start at the BAR start address, as + * there can be holes or partially consumed ranges. Account for the + * offset of the current address from the BAR start. + */ + start_mfn = mfn_add(start_mfn, s - gfn_x(start_gfn)); + /* * ARM TODOs: * - On ARM whether the memory is prefetchable or not should be passed @@ -72,8 +86,8 @@ static int cf_check map_range( * - {un}map_mmio_regions doesn't support preemption. */ - rc = map->map ? map_mmio_regions(map->d, _gfn(s), size, _mfn(s)) - : unmap_mmio_regions(map->d, _gfn(s), size, _mfn(s)); + rc = map->map ? map_mmio_regions(map->d, _gfn(s), size, start_mfn) + : unmap_mmio_regions(map->d, _gfn(s), size, start_mfn); if ( rc == 0 ) { *c += size; @@ -82,8 +96,9 @@ static int cf_check map_range( if ( rc < 0 ) { printk(XENLOG_G_WARNING - "Failed to identity %smap [%lx, %lx] for d%d: %d\n", - map->map ? "" : "un", s, e, map->d->domain_id, rc); + "Failed to %smap [%lx (%lx), %lx (%lx)] for %pd: %d\n", + map->map ? "" : "un", s, mfn_x(start_mfn), e, + mfn_x(start_mfn) + size, map->d, rc); break; } ASSERT(rc < size); @@ -162,10 +177,6 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, bool vpci_process_pending(struct vcpu *v) { struct pci_dev *pdev = v->vpci.pdev; - struct map_data data = { - .d = v->domain, - .map = v->vpci.cmd & PCI_COMMAND_MEMORY, - }; struct vpci_header *header = NULL; unsigned int i; @@ -177,6 +188,11 @@ bool vpci_process_pending(struct vcpu *v) for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar = &header->bars[i]; + struct map_data data = { + .d = v->domain, + .map = v->vpci.cmd & PCI_COMMAND_MEMORY, + .bar = bar, + }; int rc; if ( rangeset_is_empty(bar->mem) ) @@ -229,7 +245,6 @@ bool vpci_process_pending(struct vcpu *v) static int __init apply_map(struct domain *d, const struct pci_dev *pdev, uint16_t cmd) { - struct map_data data = { .d = d, .map = true }; struct vpci_header *header = &pdev->vpci->header; int rc = 0; unsigned int i; @@ -239,6 +254,7 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar = &header->bars[i]; + struct map_data data = { .d = d, .map = true, .bar = bar }; if ( rangeset_is_empty(bar->mem) ) continue; @@ -306,12 +322,18 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) * First fill the rangesets with the BAR of this device or with the ROM * BAR only, depending on whether the guest is toggling the memory decode * bit of the command register, or the enable bit of the ROM BAR register. + * + * For non-hardware domain we use guest physical addresses. */ for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar = &header->bars[i]; unsigned long start = PFN_DOWN(bar->addr); unsigned long end = PFN_DOWN(bar->addr + bar->size - 1); + unsigned long start_guest = PFN_DOWN(is_hardware_domain(pdev->domain) ? + bar->addr : bar->guest_addr); + unsigned long end_guest = PFN_DOWN((is_hardware_domain(pdev->domain) ? + bar->addr : bar->guest_addr) + bar->size - 1); if ( !bar->mem ) continue; @@ -331,11 +353,11 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) continue; } - rc = rangeset_add_range(bar->mem, start, end); + rc = rangeset_add_range(bar->mem, start_guest, end_guest); if ( rc ) { printk(XENLOG_G_WARNING "Failed to add [%lx, %lx]: %d\n", - start, end, rc); + start_guest, end_guest, rc); return rc; } @@ -352,7 +374,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) { gprintk(XENLOG_WARNING, "%pp: failed to remove overlapping range [%lx, %lx]: %d\n", - &pdev->sbdf, start, end, rc); + &pdev->sbdf, start_guest, end_guest, rc); return rc; } } @@ -420,8 +442,10 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) for ( i = 0; i < ARRAY_SIZE(tmp->vpci->header.bars); i++ ) { const struct vpci_bar *remote_bar = &tmp->vpci->header.bars[i]; - unsigned long start = PFN_DOWN(remote_bar->addr); - unsigned long end = PFN_DOWN(remote_bar->addr + + unsigned long start = PFN_DOWN(is_hardware_domain(pdev->domain) ? + remote_bar->addr : remote_bar->guest_addr); + unsigned long end = PFN_DOWN(is_hardware_domain(pdev->domain) ? + remote_bar->addr : remote_bar->guest_addr + remote_bar->size - 1); if ( !remote_bar->enabled ) From patchwork Tue Aug 29 23:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369790 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 D34FDC83F12 for ; Tue, 29 Aug 2023 23:20:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592515.925292 (Exim 4.92) (envelope-from ) id 1qb80A-00082p-0b; Tue, 29 Aug 2023 23:20:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592515.925292; Tue, 29 Aug 2023 23:20:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb809-0007z6-Nb; Tue, 29 Aug 2023 23:20:01 +0000 Received: by outflank-mailman (input) for mailman id 592515; Tue, 29 Aug 2023 23:19:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb807-0007EX-QZ for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:59 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 90309ff7-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:19:56 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9m021983; Tue, 29 Aug 2023 23:19:53 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:53 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:46 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:46 +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: 90309ff7-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c9UUKEApCYiwql8lTUWXWKAUuaIz7NU8X+t5szptPC5c+Q8yBXmLciSGb9Ef3PjuyoAvdkgMHj3oN0PNWj78smzl4cm1AY1q67nnyW3vp8Q4FbZmkWcZjPSshy6DycWJx1jc2AP+SJQ7IlXLcomKRGOfMfjv2uLNnUpuIwjQUNbY14lm5zO73Ja2NuoRCpsDeo5fGuOZH9uxu4rsH9GWp7Q/3xaGUdTk/d2Fmp/UxHuV4biv23Q5eNmpCit1P/qW5bBTY5EkrYO2bnGITS6Pmf4QjX9NEgb+jHpRgn7t6Sr9xdEKnWKh1O2toe9DZxWO6MpLkmF3pnpONdJRVgepvA== 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=Q1RqGs20J0sl0wDwsS7HPEyH9aAe+auhvvKSc58OLsk=; b=CMt142aESfrpOKZiayOpG3qBmSB6i3PkscmQOWnkvD/z3hqDeE3EGzwmXDiiB0GfuEoostgn1lSQK57s1KejjVH/c8+1fbbhQIjZERnYFyxq9RFSkdFWabLPIIeQ0L4lXxkQbjUzTmjsZmgHLhmAZtiHNknJHuqWFYiLwTDq1/GSJ8stVVc2mSOGDeg6+Pfe3uZTCrQSXPtMTYF2++zvlwBlMq1GUllImyeoivQP/4Cmt1WA2sxTouxmJdDRJl6tqn1Ibmc8zx0jD4EmbvURLo06PPjKPjdxlIPd4kLTWK8Yxxmt6aIMVcwxnK1seXBDP/EBoVfl6Pghq3DPptj49g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q1RqGs20J0sl0wDwsS7HPEyH9aAe+auhvvKSc58OLsk=; b=RRvh1NnLsKlJeo3AA7dCmUwDkAnqubY9K+Ixz2jFpPLvVxmdijclT3axfZS+2fuf6DVpssjQXwxDyFjg5pqUs3HqnBnw8nCu11BVfRyaw5OcxhK7HYXVkdYaZ2i0+pkeNbA996YmwMIMchl09IRopo+u3lTs4ZDycc6pYSjJh7NFipoH2s0r0U9l6KXkPJqWliTN+8B+TgeW+/kQaYJetnHY7GwJ0XS/c7ReDmdP/UjQY5CjwOG6y5JJKqDqeZpnfii2qL2OCSu9rUW0lwPIzo86KO7IWWx6W97YnjkOc/sZfpCIlfgF25jga/MD99IF9BcGskX3IdwB8gMft9lVEA== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v9 10/16] vpci/header: emulate PCI_COMMAND register for guests Thread-Topic: [PATCH v9 10/16] vpci/header: emulate PCI_COMMAND register for guests Thread-Index: AQHZ2s9LnsJWfZzJukybwnoLXaXA0g== Date: Tue, 29 Aug 2023 23:19:44 +0000 Message-ID: <20230829231912.4091958-11-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: b95024b4-e3e7-4761-70b4-08dba8e66f49 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0H8MtiKi35+65igUTXRWmr0abA8I4xS+xGE1oMFmAEYwd5y3CiNgKdDApjlXzQsCCROVpq6hnu6QIXVMnn2Uy8C5VgTjYPtYx0cXcFhLSbcLp8OEQvE7mo7X5Hyqv46Wr0juH06bD/XIRRvWogI4SwIT96KQd/vzldZ+weo2qOHb3Yzo28T40xSgoetEClyS4WjIQPGS5P3uZSaKT24wclz0VhW1fltCJ7/ueLDYMtWO3mZi6ZnrmzPxEtDRyybm2hMaI1xFR7oeFa1+cM3HNITUENSFkjHXlqZmQSFAlnGI0kiyFiLtAQAIP75UeO87dfObwviGoVMdXeLmib9rif6PGLaaeBOBwzj5Vv84QFJNO9P3lL7WcrAC5oebDO5sElJXTO1NMsr3DPD40YsDPDlhLLXVqfMTZmtHLREcB0FS8rQl+LCVYioLLVlX71SsqHDufbXrnln4nBD/ywLUlvUpj7mCh5gMDbSh+snr/Zz0CPwp34AE4v98m6jmjoBXXZ+qXb9W9Pt/D9zL7olz4QW7ccZC4uLga0/SNiCnyGBSJefZ3TQy/AYOodYLQVCS5h3MD834PCo0ur8nqalETDSAHmgHAKpm55etKD59Nw2ODTFQuJLdRIHgyyUmN3Fu x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(107886003)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?nkJq/1JY300LwirFR1h/kwh?= =?iso-8859-1?q?hTXUCigEMKTyh6gASctXV2euwAJ8u15RT9UOJ6xVMk67gF8khI7epCuHnlYT?= =?iso-8859-1?q?93WYlf4cEyjuSIuH2xK572EwvRe9CBcadtZ5nA4pfhmjCkclAnX/K0DmC3ko?= =?iso-8859-1?q?eyOQNdSJBPr+wDAVBhhY6R3rbxhKjaG+cz7T1Z+PXFaQBSv7wIgsHXsEotUW?= =?iso-8859-1?q?Tv45y7Xb055h5NWQnOY5tOmsZQHAH5jOVb+4F2BOnqm8DAg6bRiY+0Jmoqu2?= =?iso-8859-1?q?y4TKw73dD2+LcRh30cu6BWXfs0zFCdf/x6JFjesVeu88OIc+hekI4qK5JnZl?= =?iso-8859-1?q?q0pRxKxRJJwtnOuarW8s6pzv9WXi9W+7jGP4SqW12n0nBIL0EbtWlHW9Nu7v?= =?iso-8859-1?q?c/9AWf12/XbX60NHck3Pa6rk9ek1lYGl/3tmfdthIpQRRSpAs8+hKXzn3ISY?= =?iso-8859-1?q?WpZfb6V8XZA+C0djJEsE97ciKjhgGPEOlQKPY4qKNJlcRJtR+934ekFe3BoC?= =?iso-8859-1?q?em0hUEbS7xjCgPBGkYcbVpKRPhS6ei90SIHakdQIoQm2OE8qmlSyoQa1bIGm?= =?iso-8859-1?q?4wpqaXwsijAIAI1XCs2nKXSDFupPVKL99aNOFeVdCPTwwOlW8VljHKnflk93?= =?iso-8859-1?q?9mxHwwsjOZb8X3UYsVKaki5LLwjSmj0kiWiHPHm6fJNJsv94nf6E7xpXnvXq?= =?iso-8859-1?q?YhCbNxe3jPJ0VNAP7C6dplljuCj4ggPSm29xSvboMKWtSrbjNgz5vz2whb+i?= =?iso-8859-1?q?gFbVDafgOOHe+LnzDnBTmb7W/fHk48VgE4QnjFg4B8YGKDeLLv0Lr1B3RVho?= =?iso-8859-1?q?XSXYyz+g4ebbNKSj5pqLp1tPcERteT3Hk3uxzZ9Yj0JRF7fzIO3/u2i6+4Dt?= =?iso-8859-1?q?Mlbn/YGL/Q9J4T6RqItzK7MSnUZrzx0ZLzaPTuS6dFQ/QXVSnDiIx+YyxsII?= =?iso-8859-1?q?yAHch0R1SoC1kYlGZDaBiy3cduLmPnUxRSXb5wHGGJDz7FKuLViLBd9NvwWN?= =?iso-8859-1?q?LYR93/4MmZbjVvYP0rQHpn3U3daOtSKQNHR0B+khSf1xmmTxcB6OYW+JxZoL?= =?iso-8859-1?q?y3mNUJ57y1UtM6Vj2P4Lp3LQp4kdeWtbG8DlpzKj03YuoiCWgPPUKeroxDAX?= =?iso-8859-1?q?lGwBfT64QfHbzgW5fRoSllJkM8zR1gM6eHgE5sdi/vtysGNggoTZdrxin6xK?= =?iso-8859-1?q?9jIr+lZcpdakpWm5TqkqBCmvNG/xb1bBBQAtlMvQ+n6OP82uEo4NJiJxoOFL?= =?iso-8859-1?q?DUQlj5LvtpQKPv5DHwhF2PACXX7LaGp/c9xKj/cPsa7jIIlq83KNchrs3nu1?= =?iso-8859-1?q?0gwNCDVEIR6ZPVz46QTeOs+XiuCf6pHeYF7Uif2JAZWVXpq312rimjRkYVCA?= =?iso-8859-1?q?dFZi4B0RucHFknHD65LzPq3alPRP3j5ky/bPC8Xn6gb+h8IdpSwxAZy7YGNn?= =?iso-8859-1?q?9NwFELeOdd0t74LDyeGVViLXkAlrjrHnWVrcEqc/FgK69lpDdAmZY2xxVLYz?= =?iso-8859-1?q?Zg6WQ0VWcXB+RpC7c1oSocVhiBhc+Atim61e7q/cPTPcra67uVH18yEeu2uU?= =?iso-8859-1?q?ZP0LDQfjrLFBhAmfZhc/UZPqGYqO5zscYqtTkIRFJ46cSx/OngbmBUYLn47P?= =?iso-8859-1?q?mzuYFKjoPS8Xm8YsSsxA8EOTgcJmmmDBkMwTPYQ=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b95024b4-e3e7-4761-70b4-08dba8e66f49 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:44.9820 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: f/k3Xb32J1XaaKVsrs/XVjlpzoQZmW3fOgEoHr4A8moveTnaXHgTvZB0cjHHilS89Bzn2Lvs85DALruECUAUuXognKMXxE3L834HZIThW/U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: 6UMa9LcDeC2G7H2Odn-1F9XCLs63wV6Q X-Proofpoint-GUID: 6UMa9LcDeC2G7H2Odn-1F9XCLs63wV6Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Xen and/or Dom0 may have put values in PCI_COMMAND which they expect to remain unaltered. PCI_COMMAND_SERR bit is a good example: while the guest's view of this will want to be zero initially, the host having set it to 1 may not easily be overwritten with 0, or else we'd effectively imply giving the guest control of the bit. Thus, PCI_COMMAND register needs proper emulation in order to honor host's settings. According to "PCI LOCAL BUS SPECIFICATION, REV. 3.0", section "6.2.2 Device Control" the reset state of the command register is typically 0, so when assigning a PCI device use 0 as the initial state for the guest's view of the command register. Here is the full list of command register bits with notes about emulation: PCI_COMMAND_IO - Allow guest to control it. PCI_COMMAND_MEMORY - Already handled. PCI_COMMAND_MASTER - Allow guest to control it. PCI_COMMAND_SPECIAL - Guest can generate special cycles only if it has access to host bridge that supports software generation of special cycles. In our case guest has no access to host bridges at all. Value after reset is 0. PCI_COMMAND_INVALIDATE - Allows "Memory Write and Invalidate" commands to be generated. It requires additional configuration via Cacheline Size register. We are not emulating this register right now and we can't expect guest to properly configure it. PCI_COMMAND_VGA_PALETTE - Enable VGA palette snooping. This bit is set by firmware and we want to leave it as is. PCI_COMMAND_PARITY - Controls how device response to parity errors. We want this bit to be set by a hardware domain. PCI_COMMAND_WAIT - Reserved. Should be 0. PCI_COMMAND_SERR - Controls if device can assert SERR. The same as for COMMAND_PARITY. PCI_COMMAND_FAST_BACK - Optional bit that allows fast back-to-back transactions. It is configured by firmware, so we don't want guest to control it. PCI_COMMAND_INTX_DISABLE - Disables INTx signals. If MSI(X) is enabled, device is prohibited from asserting INTx. Value after reset is 0. Guest can control it freely. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- Since v9: - Reworked guest_cmd_read - Added handling for more bits Since v6: - fold guest's logic into cmd_write - implement cmd_read, so we can report emulated INTx state to guests - introduce header->guest_cmd to hold the emulated state of the PCI_COMMAND register for guests Since v5: - add additional check for MSI-X enabled while altering INTX bit - make sure INTx disabled while guests enable MSI/MSI-X Since v3: - gate more code on CONFIG_HAS_MSI - removed logic for the case when MSI/MSI-X not enabled --- xen/drivers/vpci/header.c | 54 ++++++++++++++++++++++++++++++++++++--- xen/drivers/vpci/msi.c | 10 ++++++++ xen/drivers/vpci/msix.c | 4 +++ xen/include/xen/vpci.h | 3 +++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 1e82217200..e351db4620 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -502,14 +502,37 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) return 0; } +/* TODO: Add proper emulation for all bits of the command register. */ static void cf_check cmd_write( const struct pci_dev *pdev, unsigned int reg, uint32_t cmd, void *data) { struct vpci_header *header = data; + if ( !is_hardware_domain(pdev->domain) ) + { + if ( IS_ENABLED(CONFIG_HAS_PCI_MSI) ) + { + /* Tell guest that device does not support this */ + cmd &= ~PCI_COMMAND_FAST_BACK; + } + + header->guest_cmd = cmd; + + if ( IS_ENABLED(CONFIG_HAS_PCI_MSI) ) + { + /* Do not touch INVALIDATE, PARITY and SERR */ + const uint16_t excluded = PCI_COMMAND_INVALIDATE | + PCI_COMMAND_PARITY | PCI_COMMAND_SERR; + + cmd &= ~excluded; + cmd |= pci_conf_read16(pdev->sbdf, reg) & excluded; + } + } + /* - * Let Dom0 play with all the bits directly except for the memory - * decoding one. + * Let guest play with all the bits directly except for the memory + * decoding one. Bits that are not allowed for DomU are already + * handled above. */ if ( header->bars_mapped != !!(cmd & PCI_COMMAND_MEMORY) ) /* @@ -523,6 +546,14 @@ static void cf_check cmd_write( pci_conf_write16(pdev->sbdf, reg, cmd); } +static uint32_t guest_cmd_read(const struct pci_dev *pdev, unsigned int reg, + void *data) +{ + const struct vpci_header *header = data; + + return header->guest_cmd; +} + static void cf_check bar_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -732,8 +763,12 @@ static int cf_check init_bars(struct pci_dev *pdev) } /* Setup a handler for the command register. */ - rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND, - 2, header); + if ( is_hwdom ) + rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND, + 2, header); + else + rc = vpci_add_register(pdev->vpci, guest_cmd_read, cmd_write, PCI_COMMAND, + 2, header); if ( rc ) return rc; @@ -745,6 +780,17 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( cmd & PCI_COMMAND_MEMORY ) pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY); + header->guest_cmd = cmd & ~PCI_COMMAND_MEMORY; + + /* + * According to "PCI LOCAL BUS SPECIFICATION, REV. 3.0", section "6.2.2 + * Device Control" the reset state of the command register is + * typically all 0's, so this is used as initial value for the guests. + */ + if ( header->guest_cmd != 0 ) + gprintk(XENLOG_WARNING, "%pp: CMD is not zero: %x", &pdev->sbdf, + header->guest_cmd); + for ( i = 0; i < num_bars; i++ ) { uint8_t reg = PCI_BASE_ADDRESS_0 + i * 4; diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index a0733bb2cb..df0f0199b8 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -70,6 +70,16 @@ static void cf_check control_write( if ( vpci_msi_arch_enable(msi, pdev, vectors) ) return; + + /* + * Make sure guest doesn't enable INTx while enabling MSI. + * Opposite action (enabling INTx) will be performed in + * vpci_msi_arch_disable call path. + */ + if ( !is_hardware_domain(pdev->domain) ) + { + pci_intx(pdev, false); + } } else vpci_msi_arch_disable(msi, pdev); diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index f8c5bd393b..300c671384 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -97,6 +97,10 @@ static void cf_check control_write( for ( i = 0; i < msix->max_entries; i++ ) if ( !msix->entries[i].masked && msix->entries[i].updated ) update_entry(&msix->entries[i], pdev, i); + + /* Make sure guest doesn't enable INTx while enabling MSI-X. */ + if ( !is_hardware_domain(pdev->domain) ) + pci_intx(pdev, false); } else if ( !new_enabled && msix->enabled ) { diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index d77a6f9506..f67d848616 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -87,6 +87,9 @@ struct vpci { } bars[PCI_HEADER_NORMAL_NR_BARS + 1]; /* At most 6 BARS + 1 expansion ROM BAR. */ + /* Guest view of the PCI_COMMAND register. */ + uint16_t guest_cmd; + /* * Store whether the ROM enable bit is set (doesn't imply ROM BAR * is mapped into guest p2m) if there's a ROM BAR on the device. From patchwork Tue Aug 29 23:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369796 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 36FA4C83F1A for ; Tue, 29 Aug 2023 23:20:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592512.925269 (Exim 4.92) (envelope-from ) id 1qb808-0007XZ-Do; Tue, 29 Aug 2023 23:20:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592512.925269; Tue, 29 Aug 2023 23:20:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb808-0007Wf-8m; Tue, 29 Aug 2023 23:20:00 +0000 Received: by outflank-mailman (input) for mailman id 592512; Tue, 29 Aug 2023 23:19:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb806-0007EX-Ou for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:58 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 906de3b4-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:19:56 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9n021983; Tue, 29 Aug 2023 23:19:54 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:54 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:47 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:47 +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: 906de3b4-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NFNvxgSYc7546OdTijmQX44mWvoH4tcLfFaU9etjqk16saqG/2vvNZuHwPYOFNxVYYZiavhrGkXxfHcHy9C8+xMgyoFoUIs0GmrFJFs4akMsUyjoL/F6BSDYO2R/C0v2ieE2SZA6sNkq0Kue3i1s3ZwcaUxswZPbcwkv/ht7z0ebblhGsA9JEgTIQibsviN7uptXXVcelUqHuKNFW1xhI4yEjRwy/E2GQuGgpiybbMKPAUw+vz245GjFk4uL2a97oHoXf+/Nh1hLGhMyZTjmea0iLtTbi9u5TETjCFgqwt0SvBZWzHOUJJrlvJPhiD0vaNP6iDIEr5pBCzunYR4VvQ== 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=9RSd6gDogowC6YhVNDeraATH9brdfi3Ahv2ppWZqTGA=; b=atcBiMjCfxvymrQ4SJ0twGA54cS7eYzAlura4+BMruMC4SzahHXr/fdCX7aSgfU6NNo9H8R0J8khXoTTqgMbgBig7HojyEjLAM78Yna6hIhv6IEmQT5uXNWSTZqr3n22rxNYPle+Cltp5YIaWiJJG8Y0R0DCkqEzA5K9d/41jY2DlGnfNuo59tT2EmBFFAqHkW45ncO9GNrklrPHrBYZIO5o8D5DoI3FvYmrywwYe2pNZaJmU7/HOkGHC/YBNl+6KRIugZUBN08Y1OrbHUySa7Dwc/9fu53GXQfmRWZ9TCPBbqktSBuUHj8DtaPc/rabrPx1BsQxjkFR1vcUno4JTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9RSd6gDogowC6YhVNDeraATH9brdfi3Ahv2ppWZqTGA=; b=I2jgfL5DnVKAf1ygP4cdznYC0z/K09yDnV7bNh+A/HYc3CTIugtY8EDQzwojAEMr/n9XQVWAeThbpAH37OpxRK7iKjVf2UkR5LM/oMV9yCOv1dGHtKYgoqaVb+mvE5vjeBwuAxnRYSZtCQxycKtODT/aaO3VDDYAiXDXH9vla63VubOMt3hMiidJ8t9uLKpKAt458y/YszA+mN+oHDxrYt7LKEkXslgQn+5/Fwq6qiDBb/YOLBgvl6NNP2bB3Ml1SC1Vbjb/EIFykcZebaZbmZvYL0G04UzZgQkggTiBXOKpmLHX+2+lPEIpW2JbbuOv/sL90lef01kXJMabnsIiHQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v9 11/16] vpci/header: reset the command register when adding devices Thread-Topic: [PATCH v9 11/16] vpci/header: reset the command register when adding devices Thread-Index: AQHZ2s9MXPBeWfv85UCGprRCw+JOTA== Date: Tue, 29 Aug 2023 23:19:45 +0000 Message-ID: <20230829231912.4091958-12-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 7fe41a12-c778-4505-0a99-08dba8e66f85 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Khx25rAAxPb5tewtTg56lJepyiILqmxKrWLWqy1AYR0tEnVJ8xZCAS1jhafIpaREn3Ew5AIlLHe91+AESZf8v4LdHZx97VRUqs39kpyGuEBNvXRjehvU3+ausJWkdHFDYkfjMxLFqiQxkVrGWhjE0BuoyiUmiA1YG6EpXnHG32YBsXNLgbii3orGellZlL6dyrKcV0xzJpalZThVjI/uKfHJPlb8/Th0WQSJiDZZM0fmNsMVWHJ2TCF+IUyb6s+C9jdT950dkYdAOJUu8blbERcNXD6rRfiW8rN1lnRKjXoASp5S2FJLFbDwx5S3mJ+lkGWliRB7D1ury6uTKcxkSErYVagUI9GSJ24HPYpXOm9wa6uKJ09zBYtB512KQcAyoFdS9tNgaYlzzV4WNZKrYpGtoxBNPt43lHE4hEXVoG5idE+o40Voi3XdfKUvOzJjtuI1hjub/JWUaSwvp4GtXUVvuhUzwnwdmax6WUA6snzfsoUIXX/32kpvywTb+K+Vp9ZIzMMeR2yRn1BhHlknQ+eVqLHEhCru8GpaeGeGaWgZBOBmP9G5q1qOmQCpHzu6TJ9kPJKDBFKrWC2nH3BD2qhQVUEMbu6hJZ4KhSfE3+OYJBRo8g2Il3bB2e+WtSU3 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(107886003)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?kKVjg2jz1fMVhMkci3qaTCO?= =?iso-8859-1?q?5RXnT2hxuIhVQVDTpnRumPOqtHX7kqcRZNz4gBLGbNp8yAtUFdIWd7Rg8x8O?= =?iso-8859-1?q?QBMxrHkYYVR01e9RlSMwMoBFkQZqAW3a1P03ycvzU4SAzOf43q+fNaabmA9m?= =?iso-8859-1?q?iI6CAH6SBx3xPyRoSdJ68A/FIbGwfqtJ/jAqzMg5ujnSz3Y51IJ5l3hmw0+l?= =?iso-8859-1?q?1onCDwPT63IqEFwRY7wA71aMfy2sogGgcnmeyb8LxoyB4xE8pddHkT3IIaLT?= =?iso-8859-1?q?nHL2TYqTmUwsVgk/Qvaf0/v6clK1RgG2VfmXVU9tf0mCGl2EfFlWIWs+tA1T?= =?iso-8859-1?q?Y2GoNHyMiUtdVbzDHL252mlqLYgd4XvikyDNLVG2EgoVrfv7e8ug8XpblP7a?= =?iso-8859-1?q?wshlXY1Fu02gyUaRglYV4qammXgw2REaGF/m7XKrgF4ocqxRsGfplMk1E8B3?= =?iso-8859-1?q?XDRhyPPZgE2BtyNWQ4I5q/rtze5125XmP9ptNL4M3fu1THndUxBapgUnMFeS?= =?iso-8859-1?q?OgCmTxnabmZIzyU9au+LBvISciGyHLHrZ7GH6tQL3zBhKTHjM4SLR1ZiSQg9?= =?iso-8859-1?q?TAxhLLvddwlpvYXm34XSStH2KOlEFkLEbewaVBbezTvmKWOUvMOc/KfmO//W?= =?iso-8859-1?q?S8myBXd9V+ZoAWajw6qOPxB+RLQEoQHNIuUWDvOjONkx9MxSnFG5Hifv8nFR?= =?iso-8859-1?q?1otuQpk1xGiDIRGeHyzRgcpwYr1y9NLtkZvRssXF1VqFqLGilZ9XR0sz9fOW?= =?iso-8859-1?q?pA4WxY+wwQlHVcHSpf45TMMdnlgL/BsEcZmETjG3BlJ4dlTSLPS9hhJ2Mph3?= =?iso-8859-1?q?RC4kV/1GSf73mTCjFZ0aXKKgfUlz/1nUAOkYiz9Lc3U++TolGtIU20uEiohk?= =?iso-8859-1?q?q4tQy/0Uk2a9YtQ1PslPgEp/FKtPjcd1BphV4oZ/ZQH+hMOCbODmvp1fb+B/?= =?iso-8859-1?q?L5nCW1W/Qmn2ViJF2Mp1LgWQNlJ9pqXMzvExY9xshwDfmpGBJzT6kNvYnHm6?= =?iso-8859-1?q?gM0OLHD9O3zJ/GcjuwxLQ6zQCQeTxBjKzh82wJ4DdZlzuGR/ZLpJdFgEkazH?= =?iso-8859-1?q?6ij4jKZqzfX4t5jkhWpRL4o02M26hR/FWWXm9XQkA/nJWpSocqx16CLtiqZC?= =?iso-8859-1?q?gflUHkNNoOUfgpkPVrX6dCFSlELztZIXUstcH819Tls7Pc9kMvsGnf65+yDB?= =?iso-8859-1?q?i2W/ASMkg36nZYvsAzwesvTWyNObxy3im2u4DRYOqSvAI90QNwifIIfs4PL6?= =?iso-8859-1?q?DPK3qyd5o9rcIoqm9rnoXUGSw5D+M3IleAVfSMQ+A/PoSYG/bKEP/+QmGVG/?= =?iso-8859-1?q?CGKApwUxI0d/4X7x/JVMLp6mkrpt3jofixwWOUVJ0/YrQCUbxALHZEjf6mz6?= =?iso-8859-1?q?E/XaPZUT8aGHUMpe9Z93zB+X///CyNlC/uIozEVTygdUIut83aL68tYSg9j5?= =?iso-8859-1?q?EPk3CQzWC2eVNAdAfuNLUoWEM1soyrXVsMoVhsxMxIKdyW6ddeZMpzQ5WJ+p?= =?iso-8859-1?q?eu3qXzlgrN9u0bQw8yauh5Mc5JPP7W59bmbX6FI0WEWIXJfBnKRbXxsWNfSv?= =?iso-8859-1?q?M05o33+q79+VNK0j035b8MOqguIUO/EBTp3/W90qLOZJ8q49OuKkVonlqV0p?= =?iso-8859-1?q?jFvTQajEqVSBd+bgEEyNC4hy/HUZqreFwKN5gdg=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fe41a12-c778-4505-0a99-08dba8e66f85 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:45.7988 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: bZCU0z54kkWGdCZrSNmr86fffomPYbPYVxkN/dRFcei4yxubJXWfxl/MwisPI2rSQVtN3JntZKSrwBx8d1ekNhoH5fjzOo4W9eN4zVcHkwM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: MQgBqpkbI7iOVGkXuVffYd7iKFg8BBkZ X-Proofpoint-GUID: MQgBqpkbI7iOVGkXuVffYd7iKFg8BBkZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Reset the command register when assigning a PCI device to a guest: according to the PCI spec the PCI_COMMAND register is typically all 0's after reset, but this might not be true for the guest as it needs to respect host's settings. For that reason, do not write 0 to the PCI_COMMAND register directly, but go through the corresponding emulation layer (cmd_write), which will take care about the actual bits written. Also, honor value of PCI_COMMAND_VGA_PALETTE value, which is set by firmware. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- Since v9: - Honor PCI_COMMAND_VGA_PALETTE bit Since v6: - use cmd_write directly without introducing emulate_cmd_reg - update commit message with more description on all 0's in PCI_COMMAND Since v5: - updated commit message Since v1: - do not write 0 to the command register, but respect host settings. --- xen/drivers/vpci/header.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index e351db4620..1d243eeaf9 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -762,6 +762,12 @@ static int cf_check init_bars(struct pci_dev *pdev) return -EOPNOTSUPP; } + /* Reset the command register for guests. We want to preserve only + * PCI_COMMAND_VGA_PALETTE as it is configured by firmware */ + cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND); + if ( !is_hwdom ) + cmd_write(pdev, PCI_COMMAND, cmd & PCI_COMMAND_VGA_PALETTE, header); + /* Setup a handler for the command register. */ if ( is_hwdom ) rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND, @@ -776,7 +782,6 @@ static int cf_check init_bars(struct pci_dev *pdev) return 0; /* Disable memory decoding before sizing. */ - cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND); if ( cmd & PCI_COMMAND_MEMORY ) pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY); From patchwork Tue Aug 29 23:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369801 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 C598FC83F17 for ; Tue, 29 Aug 2023 23:20:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592520.925344 (Exim 4.92) (envelope-from ) id 1qb80G-0001Pr-6M; Tue, 29 Aug 2023 23:20:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592520.925344; Tue, 29 Aug 2023 23:20:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80F-0001Nm-PN; Tue, 29 Aug 2023 23:20:07 +0000 Received: by outflank-mailman (input) for mailman id 592520; Tue, 29 Aug 2023 23:20:06 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80D-0007EX-O5 for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:05 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 95442fdb-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:20:04 +0200 (CEST) Received: from pps.filterd (m0174677.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TKDeco030691; Tue, 29 Aug 2023 23:19:54 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3sshtetfcp-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:54 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:47 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:47 +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: 95442fdb-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fCDDyckIZHJuVh8M/CbAYACcSF4uilv401AzvHpyMM8VwF9o95XEJfZOQpCZTKMI1baH1noUIBD8kkePxNLBi2i4KliBhMQ+p5bRv9J6C2KjKwbWu5mNHxgA8mypdQ8lcf/Gm6CF4HaT4eXZxXjoA15BI1+z8XRAstt87ALEcFWrT8uiXdkrGH7MAqOyLZvjvyI2vFBaxVp+2pEFzULX2+EeJS5FZog6UuBBjtnkD8Zpz/OUMpeHMv1TGxHwt0FsdtGJFO2i3jM+W73S9hUy9YLK7rZCpFYobEtmph6oYD9Zz8oDch3gWyO2NHPRJIwYfKo/y1qdUP6J60WQD0qrQw== 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=2Ue+npJ59xH3XrannJE1/DsrXyaqa3rixPlEc99NrgY=; b=PNgWw7yQys9I2vSYPrba1YL440v7TbnMDJqCCdGTWDMkHlyg56bK/PGcbE445tiRxNZXg4Cjs08ct/JOl+bkca7yyeNaE7GmHnA01A9WnXdAPveicnsvE+zv7xchl5sqER7Uaw+MBSwSjFIyvwEC4Zbqb0CkIyYFmjl5M3pY+fgE68XCynsbMRkuTv/VrqdIlYzl5wwGqKbiV+DX2BseI2L2pKG3o3X5ZHTIOnaR/t4ut8KqGjLZhC8+R477IweC8aqTl2GLXT3QyQGRIkRKxsmUfhPuZyD8oKMDfSDGhlc/ZM4R0+QtbyH7WlCFcKZlXPyiGaNM7AgW3aYsJsDfnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2Ue+npJ59xH3XrannJE1/DsrXyaqa3rixPlEc99NrgY=; b=SFusgAwxqELY5JTmQkJcc9uk7n+zddzUiNuqzksUNk8F1WjM/abXvSq74gwPd8QNyFXqbllamZSrFPtHF29nWGjotJ5t8u0vCC1ViGPp64bu2fqVV2kq3z+d6DbK3FxUt98jHDkR7NXfuzP1i06Gu6QjNevowMR7RMNMK5Rk5QHmuSho2mE0Rc9v2tD9HdSaApz8i6Hkr4UNFYuXxmsgePMR2AVbX4PG5BJPl8VhFSjlTeYfnygGuhhHSgV9Embp37nixv96OaSxw7ge2YvGO5fxd0xOt0Fl15H/aZDCfGU+n+kMYEwttg926SQa3DnbDK4z2Z85+wr+RDYrjcBGNg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v9 12/16] vpci: add initial support for virtual PCI bus topology Thread-Topic: [PATCH v9 12/16] vpci: add initial support for virtual PCI bus topology Thread-Index: AQHZ2s9MKcW5IJI1REe00zENuWVyEw== Date: Tue, 29 Aug 2023 23:19:46 +0000 Message-ID: <20230829231912.4091958-13-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 174136b3-4192-41d7-7d6a-08dba8e66fb9 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ohl8yXn1LS45JBQcKlnlM0ASHOChDvy1KDW2UPmvzSKkrhwiRJ4kotlmUrzjlwfzeyxAgtNU3xbjjye/heqpk4xMg8n1jHIGouTFYmY2MEiLDJ88ANuzgtljJQE2FtT4mOZVxNkl3IyPK3WA0KM1Tx9fmzIcrooGzbZPNZrMrK86eNDXVJOGAUhwCozZfRjRFKZIYYHCezVCfES+EqT3w4+SKvTvCdSF3AZ+Aj2FXaVbPjWbfb1tMRfdK+5FLgk3IQjjUj8caZQEa4d2ZhXfwgbdgzxFjGhpa9VuaFguWsjQy1EX/d0wD8R6xOXu4y8iG4BGjQwKvobruZcfSd/SqKYA+cuoMgIW9tGl7+W96MMduF2lIYe9QwR7zyLeKAZo42D+1lqfHH9ncH3x/I9nmBE7AvcIAqKvjR2a2kV5TwvYaUNWAIjPVTVPbFAgpeXK33tc8kcn2VjzO+vb5Rpqm9Xdl3+MZBA/n4lLZiMN+CKo8TEg/wp20HK1/sQm1Y2Fjpva6xkMSVZcUFkNrMa/fxnrObvOuVmUKU1QfVtOzPLyjF10EZi9y2hYKzpN4HrJN6rQny1Mt//bbIKA2q8nX+tmi4iShwn7SaNT7wmkfwK4dDC5UIhXxLN1f8tVgRr+ x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?QwySOMC2dz7T4WsyM25a1nk?= =?iso-8859-1?q?0bTOdRGhj6QhxIaCkjOECz3SzzYP9ca76x70Hde2V/VP3wVVbhHrWehFXrLT?= =?iso-8859-1?q?ZVgcXi/yNV1tOlNwm340hFsYTltsOdZZlyq+8NpnQ2hZ7ELqMYwXg4MfaasN?= =?iso-8859-1?q?PviByHNmclwmKdQ+lKS2eq5Ep9p259nFQhkh0g9rc5by9kRTlKCf6V8EF9kC?= =?iso-8859-1?q?idzY2Zd6mlHjaSiW6T0o43zdOvcDGwz8IRqTGV4pgoDn17rbkSZ6nA2clg+j?= =?iso-8859-1?q?VKEMxPJt6dBBG1C71wd5LRrpdGfCTwptTAk4eYoT4fHeE0nBsep9Bgr+YJTk?= =?iso-8859-1?q?2rqmtxR6ZWNqDmYcKCG0nXfvXG8InKk7WlXHuFJyMxmsYFnXHJV9M9kTWv6i?= =?iso-8859-1?q?6rrf7NZiTngOP0mbWcZOrL5azcYCso99ZWrDQaJco/ZFTVoqPIVPvLgP6ZRs?= =?iso-8859-1?q?zBnr4HaD6z+v7TshL/McusgzmPka7QHT0/ZH3pt5i+jmV0823h1vgNgbA4QK?= =?iso-8859-1?q?7ZITfOlUiOQpSoJp4v8ahhQQZzOVwiVzteKPKFBCgGLjReoPH5gtBerAytL1?= =?iso-8859-1?q?DHw005QNH60hEmEYQWHAgkUFusCgiuX/cfizr9DhdpW6jIDljcUnR9BI8C2j?= =?iso-8859-1?q?i1Ci87q3lzGNh/3tE1xm5aFqT+pySt1jncvQhDUMw9UhIK5RAL2hqp2mYqyg?= =?iso-8859-1?q?4uXdUw9aoTWm8bQU0LH5zAbit5OpGBCnPqgusOv+1w6fwMAU+ezVa0UCXWdA?= =?iso-8859-1?q?L+cBRbSz8kCJSqPWdmiywLJESMhvon+yVsF3t390nBV3jgwbqs9lUcefwDgS?= =?iso-8859-1?q?SpiYrztW3SBVjNDCqtZEYVxJoUuEZJJaO6xkRS277N4cTqAGccYMavBZEYtP?= =?iso-8859-1?q?MqUyYq8GFdAA96Ifn7PYuES0iEeDoxjrwTmQ/4Du7wqA6THzH/A1oDooA+BN?= =?iso-8859-1?q?0aR4NYPoZ5wSdwtepVmKW7fG2ost2449rRPzjMGlUzwmhRT3ini2dVcn9PQt?= =?iso-8859-1?q?ND7jIi1cp3r6Or5JTuqsK8YM4ACQwyb9eJ2VxTyIZdWfrKRpaBaXaEjayLUS?= =?iso-8859-1?q?VfucVrJiRmEI59y0gk+X7uN7RFXhQIJ3Su9X5CSlNbgD1pNRzMeVjyTRCHZB?= =?iso-8859-1?q?IqMTqklZs6HU/1Jz1hUsJWfec4XYvQQZ+C7jvQjIC+9n/9lOhMrXgzAM9nY+?= =?iso-8859-1?q?yU6Tdq0176Q2KXbxtK2xnL8k4OSAwyJo+nNIYJi1fIlw7Psgb7H05sJIZWh5?= =?iso-8859-1?q?zmjyGLumskPq4ZhjWedOTKHP8bzPdmLMsdoYD7mQxJ6jMJItnQ9ahM3PJSoL?= =?iso-8859-1?q?qnYs1q1tzBPvCznElb7L1+SSefMpIjIRe6H+TjeT1NDuukTiD/9XwAwGVtRX?= =?iso-8859-1?q?OBvEwefX6MzhUMyOKmXV/9YyJjiUloGER//TUIq3rBALaC5rTIAv8Yy1j6r9?= =?iso-8859-1?q?oH8sqt4B05kwsckUWnECk0a9ymSpZxoJkWZtliXIlRR0JJuFvqKQLbiJLyT2?= =?iso-8859-1?q?RnunaUkTgFieJ4Ei7M65WnBKbokwxx7RRLwQx/S943MKNi+V05jiWn2Ly81w?= =?iso-8859-1?q?hMyzawG0Qv2rloEqGs8Dv18yZk6+OuheOdawhrzBqO/CrtVQwf07W4+kDNWi?= =?iso-8859-1?q?MDT0xLCSAKHnudiQBzmOH8P0soBTDhGj2ChJ9qw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 174136b3-4192-41d7-7d6a-08dba8e66fb9 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:46.1274 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: slKXMZaGVjpyWr8NhRBaReTT3hBE1e39R4oGQUpv6+QW+paWtyx1a9DO08QcJ7huiEjvWkXdsVr1HP7j7rUGM7twlvU75cbBjco16Wd+qPI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: Vcv_aM5FLTxJo9cslBCVwmmcGSpcZPed X-Proofpoint-GUID: Vcv_aM5FLTxJo9cslBCVwmmcGSpcZPed X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko Assign SBDF to the PCI devices being passed through with bus 0. The resulting topology is where PCIe devices reside on the bus 0 of the root complex itself (embedded endpoints). This implementation is limited to 32 devices which are allowed on a single PCI bus. Please note, that at the moment only function 0 of a multifunction device can be passed through. Signed-off-by: Oleksandr Andrushchenko --- Since v9: - Lock in add_virtual_device() replaced with ASSERT (thanks, Stewart) Since v8: - Added write lock in add_virtual_device Since v6: - re-work wrt new locking scheme - OT: add ASSERT(pcidevs_write_locked()); to add_virtual_device() Since v5: - s/vpci_add_virtual_device/add_virtual_device and make it static - call add_virtual_device from vpci_assign_device and do not use REGISTER_VPCI_INIT machinery - add pcidevs_locked ASSERT - use DECLARE_BITMAP for vpci_dev_assigned_map Since v4: - moved and re-worked guest sbdf initializers - s/set_bit/__set_bit - s/clear_bit/__clear_bit - minor comment fix s/Virtual/Guest/ - added VPCI_MAX_VIRT_DEV constant (PCI_SLOT(~0) + 1) which will be used later for counting the number of MMIO handlers required for a guest (Julien) Since v3: - make use of VPCI_INIT - moved all new code to vpci.c which belongs to it - changed open-coded 31 to PCI_SLOT(~0) - added comments and code to reject multifunction devices with functions other than 0 - updated comment about vpci_dev_next and made it unsigned int - implement roll back in case of error while assigning/deassigning devices - s/dom%pd/%pd Since v2: - remove casts that are (a) malformed and (b) unnecessary - add new line for better readability - remove CONFIG_HAS_VPCI_GUEST_SUPPORT ifdef's as the relevant vPCI functions are now completely gated with this config - gate common code with CONFIG_HAS_VPCI_GUEST_SUPPORT New in v2 --- xen/drivers/vpci/vpci.c | 69 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 8 +++++ xen/include/xen/vpci.h | 11 +++++++ 3 files changed, 88 insertions(+) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 412685f41d..b284f95e05 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -36,6 +36,54 @@ extern vpci_register_init_t *const __start_vpci_array[]; extern vpci_register_init_t *const __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +static int add_virtual_device(struct pci_dev *pdev) +{ + struct domain *d = pdev->domain; + pci_sbdf_t sbdf = { 0 }; + unsigned long new_dev_number; + + if ( is_hardware_domain(d) ) + return 0; + + ASSERT(pcidevs_locked() && rw_is_write_locked(&pdev->domain->pci_lock)); + + /* + * Each PCI bus supports 32 devices/slots at max or up to 256 when + * there are multi-function ones which are not yet supported. + */ + if ( pdev->info.is_extfn ) + { + gdprintk(XENLOG_ERR, "%pp: only function 0 passthrough supported\n", + &pdev->sbdf); + return -EOPNOTSUPP; + } + new_dev_number = find_first_zero_bit(d->vpci_dev_assigned_map, + VPCI_MAX_VIRT_DEV); + if ( new_dev_number >= VPCI_MAX_VIRT_DEV ) + { + write_unlock(&pdev->domain->pci_lock); + return -ENOSPC; + } + + __set_bit(new_dev_number, &d->vpci_dev_assigned_map); + + /* + * Both segment and bus number are 0: + * - we emulate a single host bridge for the guest, e.g. segment 0 + * - with bus 0 the virtual devices are seen as embedded + * endpoints behind the root complex + * + * TODO: add support for multi-function devices. + */ + sbdf.devfn = PCI_DEVFN(new_dev_number, 0); + pdev->vpci->guest_sbdf = sbdf; + + return 0; +} + +#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ + void vpci_deassign_device(struct pci_dev *pdev) { unsigned int i; @@ -46,6 +94,16 @@ void vpci_deassign_device(struct pci_dev *pdev) return; spin_lock(&pdev->vpci->lock); + +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + if ( pdev->vpci->guest_sbdf.sbdf != ~0 ) + { + __clear_bit(pdev->vpci->guest_sbdf.dev, + &pdev->domain->vpci_dev_assigned_map); + pdev->vpci->guest_sbdf.sbdf = ~0; + } +#endif + while ( !list_empty(&pdev->vpci->handlers) ) { struct vpci_register *r = list_first_entry(&pdev->vpci->handlers, @@ -101,6 +159,13 @@ int vpci_assign_device(struct pci_dev *pdev) INIT_LIST_HEAD(&pdev->vpci->handlers); spin_lock_init(&pdev->vpci->lock); +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + pdev->vpci->guest_sbdf.sbdf = ~0; + rc = add_virtual_device(pdev); + if ( rc ) + goto out; +#endif + for ( i = 0; i < NUM_VPCI_INIT; i++ ) { rc = __start_vpci_array[i](pdev); @@ -108,11 +173,15 @@ int vpci_assign_device(struct pci_dev *pdev) break; } +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + out: +#endif if ( rc ) vpci_deassign_device(pdev); return rc; } + #endif /* __XEN__ */ static int vpci_register_cmp(const struct vpci_register *r1, diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 535a81fe90..0aafe19a51 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -461,6 +461,14 @@ struct domain #ifdef CONFIG_HAS_PCI struct list_head pdev_list; rwlock_t pci_lock; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* + * The bitmap which shows which device numbers are already used by the + * virtual PCI bus topology and is used to assign a unique SBDF to the + * next passed through virtual PCI device. + */ + DECLARE_BITMAP(vpci_dev_assigned_map, VPCI_MAX_VIRT_DEV); +#endif #endif #ifdef CONFIG_HAS_PASSTHROUGH diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index f67d848616..58304523ab 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -21,6 +21,13 @@ typedef int vpci_register_init_t(struct pci_dev *dev); #define VPCI_ECAM_BDF(addr) (((addr) & 0x0ffff000) >> 12) +/* + * Maximum number of devices supported by the virtual bus topology: + * each PCI bus supports 32 devices/slots at max or up to 256 when + * there are multi-function ones which are not yet supported. + */ +#define VPCI_MAX_VIRT_DEV (PCI_SLOT(~0) + 1) + #define REGISTER_VPCI_INIT(x, p) \ static vpci_register_init_t *const x##_entry \ __used_section(".data.vpci." p) = x @@ -155,6 +162,10 @@ struct vpci { struct vpci_arch_msix_entry arch; } entries[]; } *msix; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* Guest SBDF of the device. */ + pci_sbdf_t guest_sbdf; +#endif #endif }; From patchwork Tue Aug 29 23:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369794 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 16B7BC83F17 for ; Tue, 29 Aug 2023 23:20:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592523.925369 (Exim 4.92) (envelope-from ) id 1qb80K-0002Hq-Dl; Tue, 29 Aug 2023 23:20:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592523.925369; Tue, 29 Aug 2023 23:20:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80J-0002Ed-JT; Tue, 29 Aug 2023 23:20:11 +0000 Received: by outflank-mailman (input) for mailman id 592523; Tue, 29 Aug 2023 23:20:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80H-0007EX-7W for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:09 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 979983bf-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:20:08 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9o021983; Tue, 29 Aug 2023 23:19:55 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:54 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:47 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:47 +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: 979983bf-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZxKFKczdE4Ax4QZdoyCTwmawnW92pEgafLwtv3nNG231C+6wXqkB7hmcaXIiZf5kfjg3j9GnKOFQbVUUl2V8a1FxDPI/OuZLMFWdGfSv/fGHOrcDI4J1VBLtev6ZxZlXS4sUrpyecHyaRkpAzbL7d1NNfZrltZj+vAnAoTWgojd6r9TrclOFL/vmd1ueF9prBwQ0kvbvPbWUGz5WU7ZuoI+29C3Sw+5Q/Ktp65EeowBlSi3p2JrfOkEUW2t5UAtKQdoNA0TrHCs5yH3Z8216og4/esbNNO2+9em2qk3ZRoK8BEdWQVXuQRxCFsEfbOf8gAxV5cbwYsYBW0xZpA6b7w== 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=tHS1N91i3tWS5LH97lRofiQwO8GsJ0yTSCwV8j1YJug=; b=UC9nFOS/rjstrdv3pHplV/iZBURT/W6yPVSYa3HIU6iHXqo9+EyJ/wz9uZBgQtq5mwT/L3gkOE43Zd/rjgHDvAcP9iXtMUqhgDRAVPt7lFGfGT3uRgzwUId8fMqYBlbA51mIeJj1wT8F3m7OsOC0Bk7r6lsfeEbvrBQAdLJFne0rlCFTicN0GKjke96OwRc6u6bG9KIs4Q4LZyfZXXdqNSaaLs7yJ5k3WLwN5yC/NEjLdRncgv1A75lQ5T8gMD3syV5GzcJHogvmJ8v1M5qXbRAcQKPaFJr5PXOdcwuW0mgjhH2k4Q0ovjA61Tez90MAIRl9/+51Cs4DpxJD/T7NHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tHS1N91i3tWS5LH97lRofiQwO8GsJ0yTSCwV8j1YJug=; b=BzFNq4sGttW7hCuH7/jdTRljjt/R79QsQ3sbH/iycgC22hIbTXUEVtU21KcUj/Ip5iK58ZyAx2xOh3MJT6aMsPE1hjUkZi1Klfxq+65UrIW74MXAmjDJ0azxzopMk3Tm0lTEEJXb4GDRvDCUMZN5h2r72CYdoQA/IFADs2zUFtTZ90ismgu5nZYzxwLluTPqXK9cCivKMJfV3RTA+tU6DsagVrpTLIGGyNigaRDUi4z6tCmxC20cGPwaSY9R/c0Rdh0I3cf1JwgJHayjfo/uw+v8bj43G5uaC1/OBNCl9zjGhAxrjpSKmkc5ddGNHSuB/rP6qP0gxfD/P22u2/u+IA== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , =?iso-8859-1?q?Roger_Pau_Mo?= =?iso-8859-1?q?nn=E9?= Subject: [PATCH v9 13/16] xen/arm: translate virtual PCI bus topology for guests Thread-Topic: [PATCH v9 13/16] xen/arm: translate virtual PCI bus topology for guests Thread-Index: AQHZ2s9Molv+Wh+IUEiui1Q0tNeNzg== Date: Tue, 29 Aug 2023 23:19:46 +0000 Message-ID: <20230829231912.4091958-14-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: ec4cec94-98f0-4cce-66fa-08dba8e66fe4 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: sgwt81SyObsKSdoMauM94TyzUifygSgwInkEctsS2rzD5qpLdg62CNUVqOKfkFFEYoP0u2QwY8hvDKcJplir2dM1iTtmapRFQUNXLf/8zdClPNDg9aBGhnNCsvzNI6yNtz507f45QlMe3pSwuSqxduU9nlOTN5Yxxav9xvc4UsUebrUs6+DFUCFUkMmJvmUeAMOqDCodkLpLSXWPxr0FgGNwHI0wmQzdf9zEvpmy9iIU8kKfPbxtAqn56LoX2dBvGQ8Mi6CuvkLXRVwU/M9Ie0UrS0nfv+u9KhKIXVn9ddvWEQhHw3/J8W/0D315GU38TU5fHvp/G4hZssLI5CiuCEoOEKzS5NHg0t4yU/9Yr88/W5w99vfoJu5bIDhINPyj1ozzkF5jWbEOCdZRp7otmS/yUYXG9zFZzCkcjE6X0m2BpDYVmOJxameyoPVl9qtdlp6pXYDqkpAtbjH1pQP8TwwEy8AzuJIMNJj3rMbQiUv/JxTXEeN9/lRkO9uYFTALQqfMrEQX9+Wd8FDcCLDnNGiTihJa/r9fE+Qh89/Pv6KKxC6jNN5q7ywfw3BoWtWolRou63AG9qHFUy4Wz0z47zDoHuJj2oxTm+st8dJRoiwz1JTMNEo5pEliFlf+X7ls x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?kEVgs04aHsq3toCh0fqO5mp?= =?iso-8859-1?q?/jo3qCaLWbQBv42PuICyFvS1Yh4OI2KDCLsj/6BWf4vjvc8rYknFZirehLUh?= =?iso-8859-1?q?MKfpRba3Etb1rfjJlo5cTrdqSNRloJOsqobX76TC9Rzadhqj3BedNsD1o4GN?= =?iso-8859-1?q?M8NaMtMMWkYFA76geFUKOvSUeqUbmp0TeFTbfQGfbNAzj79yv2nHi3aqG2cU?= =?iso-8859-1?q?67D+gVqoqRQ7N8k36uOd9w8nTlh7p7IXKBriyl06Vr/MAfEsy8qwVC7WzDKB?= =?iso-8859-1?q?bZ6eogOUC7T21nY3mXhUzMEnZi6y+/6ogHPOCe1+9Nra7Svg7fzYv5gDSfP4?= =?iso-8859-1?q?9K6iKWd9JEyYbi1bk86kK05Cw/NG+FXtriwlSZnM7JQRuIPUHf+rPivyvGPE?= =?iso-8859-1?q?ccN9HwZj+aJAyk170TrMb7TD+SVsdgdIKRQAejkoZ23E1N8NR4yjXukjgysl?= =?iso-8859-1?q?svFIX3c9rcuJY+MvkGhb72ZCHkDou99qtAt7g8ri6iPlGpXBJkO34rrDMsBB?= =?iso-8859-1?q?T2LNJYPgMjRJskFcEG6CoyF5glKcHG9mi7qjPNNECe4QyLCu1Cp+lLewhNEF?= =?iso-8859-1?q?Yzj0uayvFFklFx68kiydHGE8FzhGjtD9WLC3XLC4LzlsLfYsdT8kWwg9l+ca?= =?iso-8859-1?q?zc6g7lfJS+jmM6ZvKqQbt5hkRsjHMvh5qNW4EhvVtuTqZWsr8kS5EyK73mZL?= =?iso-8859-1?q?HBm/qAwdoiQKXVklZkCZ54iKKMErtopByi8AOsyz27vjmPqE9eaMqgSE5kXK?= =?iso-8859-1?q?k/bg82+26qiRpAwpdlHCfmVRNi7lX3e47o4Es2nRRLuiMzPAnaCaXkMjJ5wS?= =?iso-8859-1?q?0pguo6Mly5oEjS+m7CkYbmtuHWXlCqr9Ucs1ZomhD03KboI9jNyVHlo09G93?= =?iso-8859-1?q?HEiutkFIBRVJz+HseTXTzQeSOcIIJtZLc6fnAR7wgOZRcs/zei1wngXxoQ1c?= =?iso-8859-1?q?v1yEoYlEDayIlNDeGn25nOF851dexly9xU733WE5T0oC1J/Jh9Kkid+VFPs2?= =?iso-8859-1?q?SHAwtZPfUhEqZ1yUl7/EzQ8WpnRnBe/vRi7jaWrV8R9ivkSw2byDwJ+9/rNt?= =?iso-8859-1?q?3KVd/kxJ7vsF4D9KzNEnA3hq8M07TRlVorWGzdvfS9J+6rBNPbR0KaSuGnuv?= =?iso-8859-1?q?9cCg0JfBSmrXoc6bPP+eoginI+3msQR40S5Wppz5j/joq7QlD2L3A56xiTJX?= =?iso-8859-1?q?N+mfxdaNJk7tBTxI/4qoY3BoK4dFwGPwYPokzb+NIwpVv4sJ2xOfEzsN6z41?= =?iso-8859-1?q?pfeWDkJhp9u/rTg6yMONNmeONuvxVTpCfx+xxcKADz0Ud8qOPjDawg42Ig02?= =?iso-8859-1?q?MgdltWD/g61IewT42xOyyGbDCjgzdrxOn7bwBqQ5CkuYgrMaAKVBt1B4e1su?= =?iso-8859-1?q?c2pOHc86o3WwIaLyHdV0u8t7hJbLXU0/2EAc3z0VVJ2bKe/c3zmiTGcew7Vt?= =?iso-8859-1?q?drPiZ/h9/q0b1l8YSzYg5COez3FNyJ5BX2fSIK7mEsJJM0jwu9jyKArdexJL?= =?iso-8859-1?q?aHUiOXr3cZcL0gcvEcwrPEYHwWkw92vXQ4R7kWQH4QWQIyjX0WjI0Aath9CC?= =?iso-8859-1?q?W79Kk3DGMwAwP7xzLpn/3ZUKEqtGVnIOse9L/33CemA7zvxJpdF6z9sWAdpa?= =?iso-8859-1?q?hAZygZbOP0Qc11MyVUgv94N7oTdMVGZczru50Ig=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec4cec94-98f0-4cce-66fa-08dba8e66fe4 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:46.5786 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PKDCx7Dw896ItdRlZvtWYxEDdZczHxxPDF2gWvudVyav0u1l0TRqFg/3FNzREVqMt7xXkahzFF9MMbja+h7BDIfzdqiXLhutmG8wIdU0x3w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: rCJrE3s5XWWDEIfTuhdB4gLtIPBIRa8A X-Proofpoint-GUID: rCJrE3s5XWWDEIfTuhdB4gLtIPBIRa8A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko There are three originators for the PCI configuration space access: 1. The domain that owns physical host bridge: MMIO handlers are there so we can update vPCI register handlers with the values written by the hardware domain, e.g. physical view of the registers vs guest's view on the configuration space. 2. Guest access to the passed through PCI devices: we need to properly map virtual bus topology to the physical one, e.g. pass the configuration space access to the corresponding physical devices. 3. Emulated host PCI bridge access. It doesn't exist in the physical topology, e.g. it can't be mapped to some physical host bridge. So, all access to the host bridge itself needs to be trapped and emulated. Signed-off-by: Oleksandr Andrushchenko --- Since v9: - Commend about required lock replaced with ASSERT() - Style fixes - call to vpci_translate_virtual_device folded into vpci_sbdf_from_gpa Since v8: - locks moved out of vpci_translate_virtual_device() Since v6: - add pcidevs locking to vpci_translate_virtual_device - update wrt to the new locking scheme Since v5: - add vpci_translate_virtual_device for #ifndef CONFIG_HAS_VPCI_GUEST_SUPPORT case to simplify ifdefery - add ASSERT(!is_hardware_domain(d)); to vpci_translate_virtual_device - reset output register on failed virtual SBDF translation Since v4: - indentation fixes - constify struct domain - updated commit message - updates to the new locking scheme (pdev->vpci_lock) Since v3: - revisit locking - move code to vpci.c Since v2: - pass struct domain instead of struct vcpu - constify arguments where possible - gate relevant code with CONFIG_HAS_VPCI_GUEST_SUPPORT New in v2 --- xen/arch/arm/vpci.c | 51 ++++++++++++++++++++++++++++++++--------- xen/drivers/vpci/vpci.c | 25 +++++++++++++++++++- xen/include/xen/vpci.h | 10 ++++++++ 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3bc4bb5508..58e2a20135 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -7,31 +7,55 @@ #include -static pci_sbdf_t vpci_sbdf_from_gpa(const struct pci_host_bridge *bridge, - paddr_t gpa) +static bool_t vpci_sbdf_from_gpa(struct domain *d, + const struct pci_host_bridge *bridge, + paddr_t gpa, pci_sbdf_t *sbdf) { - pci_sbdf_t sbdf; + ASSERT(sbdf); if ( bridge ) { - sbdf.sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); - sbdf.seg = bridge->segment; - sbdf.bus += bridge->cfg->busn_start; + sbdf->sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); + sbdf->seg = bridge->segment; + sbdf->bus += bridge->cfg->busn_start; } else - sbdf.sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); - - return sbdf; + { + bool translated; + + /* + * For the passed through devices we need to map their virtual SBDF + * to the physical PCI device being passed through. + */ + sbdf->sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); + read_lock(&d->pci_lock); + translated = vpci_translate_virtual_device(d, sbdf); + read_unlock(&d->pci_lock); + + if ( !translated ) + { + return false; + } + } + return true; } static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, register_t *r, void *p) { struct pci_host_bridge *bridge = p; - pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + pci_sbdf_t sbdf; /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; + ASSERT(!bridge == !is_hardware_domain(v->domain)); + + if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) + { + *r = ~0ul; + return 1; + } + if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) { @@ -48,7 +72,12 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info, register_t r, void *p) { struct pci_host_bridge *bridge = p; - pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + pci_sbdf_t sbdf; + + ASSERT(!bridge == !is_hardware_domain(v->domain)); + + if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) + return 1; return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, r); diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index b284f95e05..b8df8e3265 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -82,6 +82,30 @@ static int add_virtual_device(struct pci_dev *pdev) return 0; } +/* + * Find the physical device which is mapped to the virtual device + * and translate virtual SBDF to the physical one. + */ +bool vpci_translate_virtual_device(const struct domain *d, pci_sbdf_t *sbdf) +{ + const struct pci_dev *pdev; + + ASSERT(!is_hardware_domain(d)); + ASSERT(rw_is_locked(&d->pci_lock)); + + for_each_pdev ( d, pdev ) + { + if ( pdev->vpci && (pdev->vpci->guest_sbdf.sbdf == sbdf->sbdf) ) + { + /* Replace guest SBDF with the physical one. */ + *sbdf = pdev->sbdf; + return true; + } + } + + return false; +} + #endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ void vpci_deassign_device(struct pci_dev *pdev) @@ -181,7 +205,6 @@ int vpci_assign_device(struct pci_dev *pdev) return rc; } - #endif /* __XEN__ */ static int vpci_register_cmp(const struct vpci_register *r1, diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 58304523ab..e278fc8b69 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -281,6 +281,16 @@ static inline bool __must_check vpci_process_pending(struct vcpu *v) } #endif +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +bool vpci_translate_virtual_device(const struct domain *d, pci_sbdf_t *sbdf); +#else +static inline bool vpci_translate_virtual_device(const struct domain *d, + pci_sbdf_t *sbdf) +{ + return false; +} +#endif + #endif /* From patchwork Tue Aug 29 23:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369795 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 92607C83F12 for ; Tue, 29 Aug 2023 23:20:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592518.925328 (Exim 4.92) (envelope-from ) id 1qb80E-0000zU-C0; Tue, 29 Aug 2023 23:20:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592518.925328; Tue, 29 Aug 2023 23:20:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80E-0000yp-4O; Tue, 29 Aug 2023 23:20:06 +0000 Received: by outflank-mailman (input) for mailman id 592518; Tue, 29 Aug 2023 23:20:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80C-0007EX-0X for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:04 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 94564d5e-46c2-11ee-8783-cb3800f73035; Wed, 30 Aug 2023 01:20:03 +0200 (CEST) Received: from pps.filterd (m0174677.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TKDecp030691; Tue, 29 Aug 2023 23:19:55 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3sshtetfcp-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:55 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:48 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:48 +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: 94564d5e-46c2-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NlAOaI2TKockDGVytM7PMphHd0wtYNZgqK38rsmUqoyh0IJtwb5WEPwML9CfBwjGbW3XimHjHpJCeOf1ECdcpbP28P7kKqvYYfc8YrAq6uqypi6rvMQrKAMFqzkoVZ8fDHw2scx5QrFIn88nAl2esMUhvdBfHPPjqcstMNHCOnDIL1qzU4FWzc7+S2M/b2G5v/m2vJWLfIp77gQ+JrQ0av/mS9VWNY5CNlZEmzP1769SwNaXAwFhyyLNNR7gFPCWhB3AcBMCEn8UkVO6AP6WLzhEKpJfqxA9pV2F7gqJNtRsXg6eCJ+7sOk62eaujIcEfExr08BT0Nd44Sxi8VD+Kw== 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=FTPldD6+q4SM1yUJw2n6MueChQx31PeEONHRMx/GHEQ=; b=ns9wTHOEpWCTuKo7mx/SJ1d8NZS7aF2vHjxBZVQsOnN+Sll7V8kL7hxM2aJXpobdWlLvhpy+MZOdgc/3Ge7xWiqmTJtV5uXuKKBGzyKf+ZPW+CU/m8iY04+M4cgewOuWfGKqXhw/h7CZNxd5n5/V7BT5N0R9O1xsHZ1ubjDQAsY3Q76D8gLaM48GCqionVMEE9IvC/cUBzk9qzvqUBKoM9adl2E+fzPZe/dikwBTyCfi5MtEfaUgTepztBJow4ND3V++S/zQCLldUltdNtX2VvrPMke+Ul77SSKX5UyOKtI4xGN/cDzcqs3F932Q9YED8IsauTmvn9MGMGUNGwH/BA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FTPldD6+q4SM1yUJw2n6MueChQx31PeEONHRMx/GHEQ=; b=niyaL3Mm9g02eJ93dAFOT0n7cMFgB1HEU6HsPb0Ovi+KiJmUtagKkeAknmz+i1Y1LoD414vhCSSA7hy7GZp5notBv6zqcuK31+9K3cDAxk2L4pHjJQtNY6rWUPRQqVnYrU68uPEot+CtF9dCQCIdtPqy9FW6JTTuWRGG4WsUW2PwEQIC53HVqjwP0zdtG9PHabwOUfIyIgac/ZARzmSinEP8216AXCD16rM/6vTJopR4GYWnp0KzvTAH0s3PA9LIu/p0FnYhYhz6h1x7x5AEkvAExiUcS5GR1oZuad1QL63aXuTwlf/MpBthSamPJo0fFWZfRQY/CFgKRFEmLoOe3Q== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Julien Grall , Stefano Stabellini Subject: [PATCH v9 14/16] xen/arm: account IO handlers for emulated PCI MSI-X Thread-Topic: [PATCH v9 14/16] xen/arm: account IO handlers for emulated PCI MSI-X Thread-Index: AQHZ2s9M8h1s1RnmZka4sXTrGcJzww== Date: Tue, 29 Aug 2023 23:19:46 +0000 Message-ID: <20230829231912.4091958-15-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: 2f46da6d-bf4b-43bd-3c25-08dba8e6701b x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: vcrXzueR9fOn2HtPu0TeyLXrBJ1CVdpSJRw0S46uirXAsUrg5ToNthym6dxsqcwkt19UyPtQRIqSTn5H8LntgzRU+LPw2HLjXZ7aTbVdlNQh7+edaza4Ywab6sUr6263DWvNxtboGSwIcakp1P/u6InjA++I9785zhtd6OIEz4Y7sVkwFMy3uZhy5FMLnbrSM0Novj7LYoPG55WaJlg2gpcBI9hb8vfIT4azXE7DoHO6bPchBbD67RUvImymi8bQxjiUBiaXe/SOYxIH5df9T17oN4LykHGvxF9DwdOaUUlMmhUF1H5o74vijjHLPjhYH7SBWMm8/j2ZWdm8RgQotfHI0kk30OJrLbS72XwvguTL5IFsL0gOieP7TLH5cqYgPJNgz3gkhxsSyluAqa8N9CIqpK+ZyIkd/58dNmGHtrBVIgPJ6g+eIwNd/XpJIoE61nrJBQ888d3Hd77ujqHezyLScqWrWRMSnUuxGTuYpaMMvXICsEFFcUUHl7nc/SY/8wi6EwaTuJq1XR3LYMw88hKMlpySOA8eEHWTbvtu32btU/948BDnNPtDe6KKctCnnCsYKBucK43rB4/XMhHENNqjlyYnPm7KOb4/DUljSU866fS1ANau9HTjL4Y55JFU x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(15650500001)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001)(66899024);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?RsL5X7O99kteXP6EECEDnlW?= =?iso-8859-1?q?60FL3SNm1mj6HNqYnF00Ww6isuVQV0LLW/JGjupCT65AoodBPoqdGzIMZ8HZ?= =?iso-8859-1?q?/BQ8d01Ufxv0FYv8BNU0Q9kzzizGpaRTHrEZGHgCWQCEdYLkxPnfEBiIC07q?= =?iso-8859-1?q?OvEzEc5tG/uH4IVT+Hj6KHu8W1SQOgyW5hU3DREOYhlqjoQzaRJXtWYmnNSF?= =?iso-8859-1?q?q2uoq/sTk67GsDh+RDPNxvC6ul9N890K3WvDM16Ba6ROy/oQTzABVLhkj5KA?= =?iso-8859-1?q?ItgF4PafaY5qUF6Vm24lfZ2VOZptMSjRIii1Cg+bcowDfZLpvW9J2bvsMbBh?= =?iso-8859-1?q?IfDHSeJRv1FM5C44N0KGQ50npNUGS44dTMqBTlaqLkmjTF2XNZqbuwwcGxdc?= =?iso-8859-1?q?hJk/B0olzkIGr+3TcfeCQBC+JSH5Q9aUvIJ0wl7/Arwk9hlVoio/2y4N02bn?= =?iso-8859-1?q?12920lIq0wGoa88yk1p+yIDVK0hrh6e0X7KWyLfPUPCm72c1F5yqJKUZ91Gj?= =?iso-8859-1?q?LYRoe7z6ifIdbiB0UT/UVreew+JYcKBdDoazQ8WfXSb6sX6h5dEMxFlyB2nV?= =?iso-8859-1?q?acksPEJV7MEFrkh9QFO3K/sTglkt9uud1ZmviaTr6EScM0ziqxFqhiRwl1gm?= =?iso-8859-1?q?cJFNpx66UWcEBhpnfVVM4ERPHvfLlLh43GGw4nYN8PITPQN77VKJFQr2aKQ8?= =?iso-8859-1?q?62K34yggVtfPauC1Sknyut/gH1mluNvioLG4zF5hEGTrHY1YeuVDg6VSJqCn?= =?iso-8859-1?q?x/YMApzljBYrk+y0r7PoNwwMWVbBAzPF+wNPzDrsOu9keO6K4gZeAqWiQEG+?= =?iso-8859-1?q?/yEc+K4vS8CCIcte2WiJdjTmTXUHKBKvPkUoppg5Vk9x+GZYVMiG9NnMcd5w?= =?iso-8859-1?q?DyBAXFd2WCreSNWCsACff6+w3Yqeby8aLac28Wyp4xnV2qz5dWiJHnvPRtOD?= =?iso-8859-1?q?+t3O+hXtXezxXCwmUARS7R+aO4IOVZZtx7AhbOd+v28fyE3Bu5l1UnOlO4lv?= =?iso-8859-1?q?uH7wJ4PaTv9s/QKfmDg46ikQLRvZTEa+avjf9mwe6YXCmfHTj4a1IH13/KmM?= =?iso-8859-1?q?CIpzpXpA832lFg0LxcxM67On7K6jrbUyptd2Wg15e9DB+8xBrAVGmpMpt3pX?= =?iso-8859-1?q?nYfyHmaYxSKde62aLLHeaq2vnfAN48G3r8dn00Z0RX9CxiLORsYyaPr/tT63?= =?iso-8859-1?q?eOloB/NigQSPYFuW4YgCuZ3oIYayKg/BvwWDKGkRwGmcMdhD88/3T1bdBzZK?= =?iso-8859-1?q?WyO3/574ZGfG4A2Vh3FwZdlnfqQsCAzTy+ZB1rv638zVM2sAnu86bApHajLI?= =?iso-8859-1?q?t3NYeYeeYgVCE3ggd3RJOs4BwaK/EG01N8iNX4ZRsm4eGM54N5UEQSzuX5P2?= =?iso-8859-1?q?VJtXYRr7BcvF1pwoapnpdUHEvcrguq6EaIiH2ZWFhGF8TPu8vdmiCBh/WAoz?= =?iso-8859-1?q?+AiquEInftaqcQrJb/cKvRNiPcBbssPpSv8254xdfQnmZlKNsAbIDiujjjfa?= =?iso-8859-1?q?BW5MsToyMg6eGc1EdI16RJMfMO434CI4C4aBSCN6RD5QyoBFs+amkEIL3eG1?= =?iso-8859-1?q?55skkTmRdMrCHCmvYPdXEIi0b0pUJPcBRqmBQcpVZXnb+LU1iFKOQhCUnBjy?= =?iso-8859-1?q?7FxI5/2eFV1LRx/soF5FudRORfii+fy2pV3EQrw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f46da6d-bf4b-43bd-3c25-08dba8e6701b X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:46.8628 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: sMG2FR4uIZERRiJySHDNJpikulw1DnF346PNfhvEzjFdHy5ze9RzgtzDAqBCbzatb4RsYazeggkoRPI0XaqfXG/MvUUgtrRymmpWT4+oTHA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: uSonXfIrHQm1ofF3MJmApvPSbfwKS93t X-Proofpoint-GUID: uSonXfIrHQm1ofF3MJmApvPSbfwKS93t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=449 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1011 malwarescore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Oleksandr Andrushchenko At the moment, we always allocate an extra 16 slots for IO handlers (see MAX_IO_HANDLER). So while adding IO trap handlers for the emulated MSI-X registers we need to explicitly tell that we have additional IO handlers, so those are accounted. Signed-off-by: Oleksandr Andrushchenko Acked-by: Julien Grall --- Cc: Julien Grall Cc: Stefano Stabellini --- This actually moved here from the part 2 of the prep work for PCI passthrough on Arm as it seems to be the proper place for it. Since v5: - optimize with IS_ENABLED(CONFIG_HAS_PCI_MSI) since VPCI_MAX_VIRT_DEV is defined unconditionally New in v5 --- xen/arch/arm/vpci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 58e2a20135..01b50d435e 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -134,6 +134,8 @@ static int vpci_get_num_handlers_cb(struct domain *d, unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) { + unsigned int count; + if ( !has_vpci(d) ) return 0; @@ -154,7 +156,17 @@ unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) * For guests each host bridge requires one region to cover the * configuration space. At the moment, we only expose a single host bridge. */ - return 1; + count = 1; + + /* + * There's a single MSI-X MMIO handler that deals with both PBA + * and MSI-X tables per each PCI device being passed through. + * Maximum number of emulated virtual devices is VPCI_MAX_VIRT_DEV. + */ + if ( IS_ENABLED(CONFIG_HAS_PCI_MSI) ) + count += VPCI_MAX_VIRT_DEV; + + return count; } /* From patchwork Tue Aug 29 23:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369797 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 4DC8AC83F1B for ; Tue, 29 Aug 2023 23:20:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592514.925285 (Exim 4.92) (envelope-from ) id 1qb809-0007sM-Hm; Tue, 29 Aug 2023 23:20:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592514.925285; Tue, 29 Aug 2023 23:20:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb809-0007qB-7M; Tue, 29 Aug 2023 23:20:01 +0000 Received: by outflank-mailman (input) for mailman id 592514; Tue, 29 Aug 2023 23:19:59 +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 1qb807-0006kQ-CO for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:19:59 +0000 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 91395310-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:19:57 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TFMk9p021983; Tue, 29 Aug 2023 23:19:55 GMT Received: from eur05-db8-obe.outbound.protection.outlook.com (mail-db8eur05lp2108.outbound.protection.outlook.com [104.47.17.108]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3ssdvpbm4f-11 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:55 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:48 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:48 +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: 91395310-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+E0+htBOuRqUkOXEOH0PhRZYcgmKQUqttJGKIJRnaonfSlB02lCzplD+ZVXLVVL6442sA88tyBwDqB8OZZvD4wgT5TO3TGh9dLiTXqX5mEgYQ2/U76z9NDfuGavqGNXlEzxa8S0DVT3wETa/fhWAZOenuf776bGcVu9nCHGxjcgjzqLhfzezm9A88DlViR14zIaS0sJAk3hYyaZQ2JI5pg+ifS1negLstRxRMEh7471ye6biLql1UOkbPTXZINFy6v9zeXfJ+ZoAyCivOVoyK668iTuE7CzgRQKqC7VceYFovtBuQl6epUHRCjPWnFYJ42MuZFddX2ZRVJhSBAvQA== 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=yi13S8hn57H9+SZArk4saLc0rRHuoOULjXT1oxZYZRk=; b=moR5GxUVlhOgAP5lHmGfUM2ihkIhSTVWebcDAvvxgrsDHQGia/sMr/unYTTnpqcEZn6esviCuw+c7x3Pv3lzvfurVADpXaxXWTp+ouaBILzx1hSmwY2A14Jnz1RAaQKZCGVn3IIKlEpW9eOJMFE3w+SFkWlBd/gzIoe2i40LzY1zywSwA2dvI7Lut4HPEq2RvqP4p3uyOHkwVag2lmKY6N0gqOC7J4yKDq4EZ1X2xTA6Cn/YWNALWWXRtjmPtbFhJhzD4MHszRLK5Q0jSPSFE1AQQevaIdDmCsp82BwJb0oGL66gLoDuqV7JkaoRW6KGs93TPIJf1dDgyUcZIAz80A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yi13S8hn57H9+SZArk4saLc0rRHuoOULjXT1oxZYZRk=; b=dX3UFhNJRTa68AjCy+w5L8tncG354AUvN5Vye+BsFdWpgjSaadLPtv5AarUOQqldyDh2kuc4NpGgzomx+0rGODc3ZlGxWHJzjx+7xw4c5w5Bxgzq3NZumaJqZCSFOXb/SGWMFymm+8DThMZo1tjuzIAukjS9rY8gZkVMEU0fjrlWDI4xMOiGhEkn1ga2tPqyPJCyn9PI8sAymZK+hclvcNdYboMovXtRvhTV306J5eydca02mvPajSRmHnWp6sDDwSh3dhdwO3bhfkco0eX0Xr2PbYdp5oASyrdbHrwZiuFYgqyBH5ZHfinnCQPJhf944O5T5KoWbY5Syi1+sqSSkg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , =?iso-8859-1?q?Roger_Pa?= =?iso-8859-1?q?u_Monn=E9?= Subject: [PATCH v9 15/16] xen/arm: vpci: check guest range Thread-Topic: [PATCH v9 15/16] xen/arm: vpci: check guest range Thread-Index: AQHZ2s9NAWcA6L4O6U+PqFV61kFyWA== Date: Tue, 29 Aug 2023 23:19:47 +0000 Message-ID: <20230829231912.4091958-16-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: c40aa71a-dea3-465e-8813-08dba8e67048 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nce5vjY9Bj7S0RfJjidE5Ey36FrFrSjWBJ8HsoJgONqTUkX/GHNCLXztGOelXZfj7CzMzS24tETH4OD22SWHCIG+dkzxR2yY2JaRHrVvmpbFcTnCJyu/lOIOWfTpT5UpSJPJI06M8u0k8wwLiFZ/fN8g+rkwoEO9VvXyTn/jGc63Gl90gRleaWpPPqvIqjmn5tSk97+XbruNOG3L+tr/rIA2Pq4ixWUufp5+lYrhnnEaoCijuefXRlNIvcZuJZRX0FRcJ5SOnNF3ZQzyxFWNS4+2JBD3o6tpUyKrKqFPCBIjje7I7G+qT1OuiTxz9DjF1yfMuUUjDQAHBAY0UZFDON6nIQOskLgcga5ExiY3SPOugMNLAIy9GVuO6vl5CbkLupL+s+YYZjtKk0+irr5lmmf7GEwypd43K2QPOqjx4byjezu+KBNDj1i71WNNtCeKODHmrCqZdpnaITwiIGl6wq8sUefuXuvSByy6HqAHypsrXpuMWXdi4M0yvTBQ1HB3hTiXZ0E5vKomV/Md1k2yCArLvk2dmodgvwYEfWlTesScw+xXUDiCteeLozbnYzSt/RAv+aJs03jkXg1jyikCsHau6WuOy/A/Q8/Yboo5CBkHz8zTGRdRuJyzBZNqJYg1 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(4744005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?v3AAlS0/O+hVoALSrmYskDy?= =?iso-8859-1?q?zgHKG9tnCFfK0g1fMGoPPYIkL4OEv/qZIQLwWWvRuQrxj0j8tRA0LbxiPavB?= =?iso-8859-1?q?lCGPuRBvW002OhWolk6Lszxk4emN5vqlrKXP8MxjgW2OxJLA8iVG64VzjaBQ?= =?iso-8859-1?q?c/cznAcMm+347uUm7spITSMvo1Bb+XKquKxk3WeGhCbSlT0hOiK0kDQ6mceU?= =?iso-8859-1?q?sRGW8rCSeI7+R70YVxXbTlAdikQFkHZ+Rimd1ksco6RPpfXHyUlc9KdRwv0D?= =?iso-8859-1?q?q5j4Y9ctmtXgKG1p8i0OUjglD5KhZ03M0Kt8iVwuCF/97m9Sd0ajDtynQN8j?= =?iso-8859-1?q?97LH632EcP7+aao4MD7+ugHgER2XQmuED2K32MkxcB+BQ6+OpLMIT7UkRte8?= =?iso-8859-1?q?mlgbanf0lQyV15bWyJ/uaxue8KEQ02EI9w04g+lEBdk2OANAKU4kKPO7e8zX?= =?iso-8859-1?q?y+bpVf2thlAttQCl5BbqLl5/WSX9Eu8AS31TETJSdb3BMqDL5ALaOP1tF3Yi?= =?iso-8859-1?q?9tuXyCJ0c34uKti6UUPlJrHFzMYt4pU/p5tkdvD88dqM5MN/3uSNjz3EIuaY?= =?iso-8859-1?q?KZ5Gjak8VDk1jvtUnm8IAcB0it0W2vTlKTgS/kWPKDhYth6ME/abS7nLo6Wm?= =?iso-8859-1?q?CdvGe6BUpabUC8Jx08I85BdPzAOH8pW12EaTPDFW5Mjkn/ugqeuACRt3KlcJ?= =?iso-8859-1?q?uKPtK8uUWM/6ss+LqNSbJXOkCFF32IbYrpUA4RC7wgO3xPZpjQhWxwMQmJkR?= =?iso-8859-1?q?hdUx0fAhqU0JgSP9kdgB2USpGttJ3HtnrvIBNM0MmhsXO6Vs6FHW7x42FWrY?= =?iso-8859-1?q?B2R13mLm8OVKCFE77BH65BCM/XS6gdRKHy88LhEtk3SVMMhbYaSHAAmU1/O7?= =?iso-8859-1?q?VtB7+aoD8Tvq0o1FFpauF8YdOOwYn9HtY/fc5Ww1MK/eQM+3YRrq1MG47kc5?= =?iso-8859-1?q?qC4G3FLhKF9nVVdFrGloOANaxVnOkVE0CeCr2MV7G87SgbnIwyo+SBHg3FdC?= =?iso-8859-1?q?fIu3XCrZ0zF/pqRMhVocRRhWg3xIaiNuIwmgu50kElRUkxyyHKEySUaMJRL5?= =?iso-8859-1?q?H8c2PGJN8FWu8wH3ZMIahLY59TOcIxuX2AIkYHGpJ73j6LCgnOg5VKnVYgmw?= =?iso-8859-1?q?3t99Rk62Rnf22im7DktL6rdnOB0jI5LOVppJ4m///LudZ9qf90u9G1QUo0VI?= =?iso-8859-1?q?kZkwxkJQXYhlrDyRvqp079r7OxXHztSBmkq8FhbSUvB9IzstcsUmaS6GCUW8?= =?iso-8859-1?q?AxM20W7dauiD8PkRyAxcnVacLy+LXnPPiO4W+TB3MnxRL2e2ca0TZT9/JvIX?= =?iso-8859-1?q?Y4+F8PuR/3ltZv8ywDqHlhc8QFUcqu5t7n8GPvLWUmYSwahn1tx7dHNbDrU+?= =?iso-8859-1?q?ls+uziWB1x0RnklyO17ltZAXsXsvFWF8Rb6r0gq3tWgnwZGiR7xWL0C7dN1g?= =?iso-8859-1?q?sRfdU5mdh6/5b/+csNkMIDXxkZsIKWcU3aKgx1jtrhrcxsNBUNtsJ78qwFhC?= =?iso-8859-1?q?8xS3WhIx3uyJXNNJH6MgiAGEo813WHVdhzLlOKbtkEH5LL18HOywf6FH1KiU?= =?iso-8859-1?q?K0N7SBk3NXneB7ZOoMP8h/pjxWKgJb/iiGmxUZIljUBI/H1GkgM5jtazSyFZ?= =?iso-8859-1?q?ErIiMYGIG807/lINN75Qw5MQwG4Vvj6Az1SzW2A=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c40aa71a-dea3-465e-8813-08dba8e67048 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:47.1794 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: gytcEUZUjVKHGaY2dSVtG+1lgSDsEAeVWo0uaQpqp8wFJWoLkVSXTPav+fygCR/hXkPL4DzN+11mZhDA/mfmu96o/FrtL23coUBEB+OFbUo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: aFHW6Lc_ErMGQ8h4n_X-XZDPu2KyqPqd X-Proofpoint-GUID: aFHW6Lc_ErMGQ8h4n_X-XZDPu2KyqPqd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Stewart Hildebrand Skip mapping the BAR if it is not in a valid range. Signed-off-by: Stewart Hildebrand --- xen/drivers/vpci/header.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 1d243eeaf9..dbabdcbed2 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -345,6 +345,15 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) bar->enabled == !!(cmd & PCI_COMMAND_MEMORY) ) continue; +#ifdef CONFIG_ARM + if ( !is_hardware_domain(pdev->domain) ) + { + if ( (start_guest < PFN_DOWN(GUEST_VPCI_MEM_ADDR)) || + (end_guest >= PFN_DOWN(GUEST_VPCI_MEM_ADDR + GUEST_VPCI_MEM_SIZE)) ) + continue; + } +#endif + if ( !pci_check_bar(pdev, _mfn(start), _mfn(end)) ) { printk(XENLOG_G_WARNING From patchwork Tue Aug 29 23:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13369791 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 AE58CC83F1A for ; Tue, 29 Aug 2023 23:20:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.592521.925351 (Exim 4.92) (envelope-from ) id 1qb80H-0001bK-4P; Tue, 29 Aug 2023 23:20:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 592521.925351; Tue, 29 Aug 2023 23:20:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qb80G-0001WU-J9; Tue, 29 Aug 2023 23:20:08 +0000 Received: by outflank-mailman (input) for mailman id 592521; Tue, 29 Aug 2023 23:20:06 +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 1qb80D-0006kQ-TF for xen-devel@lists.xenproject.org; Tue, 29 Aug 2023 23:20:05 +0000 Received: from mx0a-0039f301.pphosted.com (mx0a-0039f301.pphosted.com [148.163.133.242]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 94825af5-46c2-11ee-9b0d-b553b5be7939; Wed, 30 Aug 2023 01:20:03 +0200 (CEST) Received: from pps.filterd (m0174677.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TKDecq030691; Tue, 29 Aug 2023 23:19:56 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3sshtetfcp-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 23:19:56 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AM7PR03MB6371.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Tue, 29 Aug 2023 23:19:48 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::9d42:8444:f00d:7895%4]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 23:19:48 +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: 94825af5-46c2-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=InF9Vra4KEmrtfxMliPMa31i+AhiWoPQUOQB2KkTpiqA9EotOZoN5+qO6ISjBPI1bkXHG3OKu3py6fix3C+ajg+JSsVJGpG1vH7xR7QyTZkxou/RZeDjdlsWh2YSKFW4F51zj5pyThKfG8Gq8IO3IdIDUFHTqDRa/DxjdDbHuRYdqLdUnDsK0Ram0TGBYnUxjW8uyyQyd+B8nsccUdqQa40z4QhLfo7e91b0DeW1LusbTSRsBSsAjiTHE+NrmsMSCPSb3suAl/MFcbzpj+ZQ2+/aFrrf+8Lz1OPv2VQmx7/FFjrvDHCiyZO7qgcLQEwf7HIoYqeQtQ4WBYhN/1XocQ== 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=OnW6xmOMSUh88tcDS5xktaqBw+mFQg2UICEpESoViDY=; b=g+3rxJAGjDtfGmIANR04W3wZOtgKciMD1je3u/NYIhyKQnfxL5snKYiD7tXMtSsLubQVaegJ29FZllrzu4W4YH4xoJvVdaqwSriY7+8ZXOgJr3ZMQIDG75b1vKDpXLnvpwRXHp8VDdYpkxb+532/t14WLG9tpoOsiWXV8tzSGz705kPUGiL3gi4Sknajh4nsegzQkRcsLcWOBFMgQPCjGit0DfT+E6BLCu0MOnJvD2JiiRnCkIPLfCuy7p7gmFONxHkmB8t2hUq5YjDV7iACbS0nR6ZGxtBlE0A/8mhtA7fBNHt0cNaAiX8B0qGvijXH6lt00j1AQPSkLGFK1j/1pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OnW6xmOMSUh88tcDS5xktaqBw+mFQg2UICEpESoViDY=; b=BZ7g1fCRysNlZV9OfTLAMXjMjxXm2nGMlkmePoodgE3lmp1gSAhmlWwzqFfxvOD545iqFJ2h0ysZGuXnLmFZm2Yruy+ncfSAGPbOYqBgBXq0b+EUAceG2R262olph70WKnj7aJOhULh32Os4QvqYOsGR5GvvERlk/xNyKIePnLdnZ+GnXVIvwkxhNqbBzkGdTSflpSvwhF2iWKG4NENVp3CXv18MZlgSvdZ86uhrYF4Nyakw7dr3gEO1Uytb72iMPiEJTkcWwtkPFpzt0Auk9o2ZBvZs4e4KmDV7QQb0j21D0gyNkEQUxAcGernHNdEubZG7zogo9dPh8aFurKY/Ew== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH v9 16/16] xen/arm: vpci: permit access to guest vpci space Thread-Topic: [PATCH v9 16/16] xen/arm: vpci: permit access to guest vpci space Thread-Index: AQHZ2s9N0IXatP2juE67AItmuC0joQ== Date: Tue, 29 Aug 2023 23:19:47 +0000 Message-ID: <20230829231912.4091958-17-volodymyr_babchuk@epam.com> References: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230829231912.4091958-1-volodymyr_babchuk@epam.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.41.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AM7PR03MB6371:EE_ x-ms-office365-filtering-correlation-id: e1c6d29c-9dcc-4624-21e0-08dba8e67084 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pxusuRWnvPareZAG67Fu5l8gr/HBomI6/Uz6t/jywZN795YPMDjkTRBp+3xB5iFB9HC/Y30qB3gGkoyXjCNRovYPkqdKynZfODcQWTS+8NWdpOf37Y6n0657yEy6pU5y6Y7FLmY7wwvhOCCBwITU0uUktTjPCkEnF3xC1ZBu9qOQuLbeByPkubHp787yfoCxs4XvIewUE9AG7ryi18j3HBlVy3OYVkN4ltSPjLw0XDVunDD5WlbnB+MpwCZtrk+aNfbLUK3XxPlSu/OkGh7OtrGwmD8Jlu9Vqc0g1BOPCLwlRMgzivG3hD+aCRZP0aJ2ilVXluzn5ghXgykbQQJVA81PvqnybXWxd2LMKjX9yM6eU6RlMapJ7h9mqNUe8jG9neSGG8/hvPwIoQTm4pQ7TUZ3+sLrYMRL+0E/VIgAWAyxDCq+BlhKu7dL+LoXdJ6gmRdfnF4+JjUcHKU48bWj0p4tEF1GLodRV3ygrVcZ0xGi4PxUWy+JsdvgP2PttQpIonElwgEaRRleH30DuYvdj+l2I9cwcMxUxFnS/tk0J0bh63iwkIihQirQSRW0/4qbIHxeRfZO5/IO/0wlsgXGxfyPdimYmxviYAmXQ945jicZb0Wo1itLeeVh0nR/NvbI x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(376002)(396003)(136003)(366004)(451199024)(1800799009)(186009)(71200400001)(6512007)(6506007)(6486002)(478600001)(55236004)(76116006)(1076003)(2616005)(26005)(2906002)(6916009)(64756008)(66446008)(54906003)(316002)(5660300002)(66476007)(66556008)(91956017)(66946007)(41300700001)(83380400001)(8936002)(4326008)(8676002)(36756003)(38070700005)(38100700002)(86362001)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?m+wU+ofam8Mx3Ygq2nb9XHy?= =?iso-8859-1?q?e4pi8rzRXNk3KlqTwRk2XvJ23Ev0x3Dhs+nDs4DAzYobaPAudJH07lGRHeFz?= =?iso-8859-1?q?LT+uQJWN7nNRP46F+bKNz8QLOTmvIyTA2wCPbboACWzlqDCKQ6VuNdAEJEPJ?= =?iso-8859-1?q?igJ9Xm8pOa98hR7vNeM1ojUgRt43/q6IxVILKEj4IQrwYXc5QHOLvC6tjc8p?= =?iso-8859-1?q?jKRWI92RWiRk36eiEgZYGsPbk1ri9+eJu340+dK9PpP2JG5v+Vwul5OprrxN?= =?iso-8859-1?q?QOXyIPWfMpohhljQuow0kL7QwtnKjb4tfmrN7QzgJkzejxwyYfJIZO+lmI8h?= =?iso-8859-1?q?TCQsx7DM1JWujNtnvqnuyfw+ST8dJu0RKUsq/P1GIqPUPtWIrHEGjZqdQzOU?= =?iso-8859-1?q?T33n/6S4un315H6wRaj2A20CD3vYNy9PC3djr3dZRkq8kTsg0YEjpbhtK8Z3?= =?iso-8859-1?q?vb7Ca9K2O0KzyCNMOnhU6YNMlXxqK8rReveIDsBpkZCKPMEctP8NOTXnTy5m?= =?iso-8859-1?q?HJyW5jQMgp0/LUJrsbU7ng03NLvN/EkPtgLgBZMmhEqM3ugf7ucB/rhst3v1?= =?iso-8859-1?q?qyhAXKtMWjz7/fB/pke+270dUK8MSz5ISeD3oyfEAu+/lrvc2107S2RbeIJo?= =?iso-8859-1?q?aR87GSKUUzIvBI9lslIA0984V6WWNioIh0gyUTglm4EshJ8G6ElZ8on9ZOYb?= =?iso-8859-1?q?J/26XnOipK03SM3g6DktcEgMyeZHCkA9cnrz0G7LcZUekzcI/x6oEW25P/f/?= =?iso-8859-1?q?9BPCN1BvqiIlFgMDeXeG+J0Yxl6fu33bFjH6Vwnha4BjSsT4jd3P9x7YJ3V0?= =?iso-8859-1?q?EdrRuFtgnODtK9XrW70A8DChmnnfJck1DBVmMVVpQFEj/oJRr44kA2Zv3QWp?= =?iso-8859-1?q?k7NsJq6/FBg3FwOvl9QpQJat6CIK4EJzwc71ADJfin6vLjj6qkCXLfel7gqQ?= =?iso-8859-1?q?fqX92sUoaUiqlXD8gUD1oJo7WorO4DUcOakDnhzNml5Ahn5ES8PGq8LSZuN5?= =?iso-8859-1?q?fXjaEwgCs65y38A/ORrPEiyZsnSsm6kN58e+mohOzlabSea3YNQgj3PW5PnR?= =?iso-8859-1?q?9YUzTcIET9dGA/sO3ZlkIAXhg01nC+lM/qXecF7kxksjF1CFiNwyVRQtIFJ7?= =?iso-8859-1?q?HAyGlpsIZDeVZ4ecTtpue0u5/vTsah0djH2LrwtO15GyxYEQ3WCTrixlj9zX?= =?iso-8859-1?q?0Gyft5Y9VQ7VQTDD8lyTzCfYz/HGWfoT7ipchQT+utQpcdhP68lRVgjBZ5H7?= =?iso-8859-1?q?vK/u8YuKlPEp/mMvZhCh1IoTFPxCponAy6IQcpKvE0HHudIMoWI61utFjTMV?= =?iso-8859-1?q?V8X0OfVxCwXSfVD/khwTR3M/eeEkEELez+5m+YrrS4QOxOLtvcw3VLtDo3Oe?= =?iso-8859-1?q?QSiiguj7Q5tJAlVzaO5YrAD0q9pjzXRA4snNtqqccoJ9Ro8Scsvjlfi8uf94?= =?iso-8859-1?q?qnNG6zT7neIMf8Ft6tYH1iYahMzENU9GKPLBVSxL8/DlMaudCu7+NFvZjmip?= =?iso-8859-1?q?MqjJE5GVXjhZjobWiSMRAz2Qg4rc8G586aNRq0Cf9/hbfu/IvTq1AcBUtGdL?= =?iso-8859-1?q?72nLb0P5T/1iNRJUj6a8kL0wmYPl3U3gW29Nkffa0DoMvrMKKsSvSz0PPmi+?= =?iso-8859-1?q?gcLCBYn92Dnshfn8anfoYGZ9M4rpMUvi0Dll8FQ=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1c6d29c-9dcc-4624-21e0-08dba8e67084 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Aug 2023 23:19:47.4844 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0y5od2v5nnt/4cF8+ydKP0W2f4maeaYSljDZSkcWf/w8CeCfkzDtR4zw0/T2iKLgYb3h6URHUH4MlSbtwQU25iUwCHJKmhusowcENE8Ulq0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6371 X-Proofpoint-ORIG-GUID: 5iZcSRwQWU66i7bMuleoEiMpKeMA3mIG X-Proofpoint-GUID: 5iZcSRwQWU66i7bMuleoEiMpKeMA3mIG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=686 priorityscore=1501 mlxscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290202 From: Stewart Hildebrand Move iomem_caps initialization earlier (before arch_domain_create()). Signed-off-by: Stewart Hildebrand --- This is sort of a follow-up to: baa6ea700386 ("vpci: add permission checks to map_range()") I don't believe we need a fixes tag since this depends on the vPCI p2m BAR patches. --- xen/arch/arm/vpci.c | 6 ++++++ xen/common/domain.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 01b50d435e..fb5361276f 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -2,6 +2,7 @@ /* * xen/arch/arm/vpci.c */ +#include #include #include @@ -119,8 +120,13 @@ int domain_vpci_init(struct domain *d) return ret; } else + { register_mmio_handler(d, &vpci_mmio_handler, GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL); + iomem_permit_access(d, paddr_to_pfn(GUEST_VPCI_MEM_ADDR), + paddr_to_pfn(PAGE_ALIGN(GUEST_VPCI_MEM_ADDR + + GUEST_VPCI_MEM_SIZE - 1))); + } return 0; } diff --git a/xen/common/domain.c b/xen/common/domain.c index 9b04a20160..11a48ba7e4 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -695,6 +695,9 @@ struct domain *domain_create(domid_t domid, radix_tree_init(&d->pirq_tree); } + if ( !is_idle_domain(d) ) + d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex); + if ( (err = arch_domain_create(d, config, flags)) != 0 ) goto fail; init_status |= INIT_arch; @@ -704,7 +707,6 @@ struct domain *domain_create(domid_t domid, watchdog_domain_init(d); init_status |= INIT_watchdog; - d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex); d->irq_caps = rangeset_new(d, "Interrupts", 0); if ( !d->iomem_caps || !d->irq_caps ) goto fail;