From patchwork Tue Jun 13 10:32:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278337 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 0849EC88CB6 for ; Tue, 13 Jun 2023 10:33:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548007.855788 (Exim 4.92) (envelope-from ) id 1q91KW-0003pi-Af; Tue, 13 Jun 2023 10:32:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548007.855788; Tue, 13 Jun 2023 10:32:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KV-0003mg-Sz; Tue, 13 Jun 2023 10:32:51 +0000 Received: by outflank-mailman (input) for mailman id 548007; Tue, 13 Jun 2023 10:32:50 +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 1q91KT-0001im-Vp for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:50 +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 a354493f-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:47 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5KZ019280; Tue, 13 Jun 2023 10:32:34 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:27 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:27 +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: a354493f-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GxhWHWhs/pE8sBDlvFriQcSBFZDeeLDi3XpzE0Ka5KtWAA1t0Lqe6udxnPloKGWNej4zdiVYTSqEdvD4m5yHrSG0fSyCV3Dqveaoiwd8KcETBOcl0YFRn75YwxcYch0rcE4yaeDtRfMPfjfNbN75NVWzIZ6qsBG67o6pZ3jAw7cgkB27ZpU4h9IrRV4vsemkRKJyZdNW8A3Tcj7IRVRrlR3jFr6Bw0zuirgskSC+dAXe0v4EAoPVY5ku49C4GhxhB+IrDeE7Sr+a2F0bQpLLqK7zFKheebBJOQLReisSJFxeAln1ZnJhabEqro1WqxRXSxAeXHdKHiUkbqyoaqif+g== 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=l7KRV/9J4bj1bWWF2aqOnKB23fKF5Us5BL80aI/80+c=; b=nxoMiyKkvua2PlIqaIRNgFL7wTx1nA+gXXJaPKc4gK3lDA5zJIZZeH08Wh9EX8nWe6XSBR6AYXUP8x0BzmbDSCv1g8/YM7sVSHuTxVSgmIBRa320wA4i+02OerE9pRar5id4RJuhhJSZF/F2stOUSMoEdR6JNnlDJB8//RqEHKJY0cpOTX3Salxgou01NdUaW66Q9MI2wGG1rqzip8FKcsZgXZjL43InZs8uo+2I45IbLOK75freXkCdQDmgSN6i451m7bp/4R5q7QHJx4dh7mHCxY+pHtbClprbX4YaaZReO2075PuPLxQavxVLo5fPjTDLu2R1w1GZ55yflC5/7g== 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=l7KRV/9J4bj1bWWF2aqOnKB23fKF5Us5BL80aI/80+c=; b=mHWqvq5hdLoBH6UqG9Y491+C2RjEQC36lSIqrSbM8VnGXBQhdntZ0lGw4PxE/EEYAn4LRf9sM9Wik+jxSXk/ueBFdjdfHTNM19/4M43k26ofs0j+ujVaNO2QW2ketw+6DcXlwogkyO7a2nkSGHeo2HcAyECNkLl4My6ZlZCe4g7+4jgkacIFEpHFrN9NNDFPgJYnHWCl4n9pyVFcghypFBsm0MOPP4t0EAZlFZB8sxEr+dA1QUVIc/Uw7kG8zGtuoTwL8pvfuiw8bEDPYgNhtOO6+J1qkcHt8+e0z77PhUDREFsHiyfvSDadIxGtnRRZEPURgqgFhUZz9yk9m5bDAg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Paul Durrant Subject: [PATCH v7 01/12] vpci: introduce per-domain lock to protect vpci structure Thread-Topic: [PATCH v7 01/12] vpci: introduce per-domain lock to protect vpci structure Thread-Index: AQHZneJZdDE+HOoSO0y6VB9l0x1hDg== Date: Tue, 13 Jun 2023 10:32:26 +0000 Message-ID: <20230613103159.524763-2-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: 418358fe-47b1-4849-fd6f-08db6bf97c08 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: d8pqRNuGoCYKdA8wTkY0YHIOdODe8/RZb5/BPBIj9GOSwNbjsSpt+1/02me9GnfJSuAYBVejclOLZmaR5bzgjrt9IXi9r1BT4NCtwjjiKFIcfVD5iZgmsFjSohyPZdS5ANecslIUoUCOHUYeVgCWjmh3opju/p+qAgwptld9gGsfU93HWGJyJI6M+PjTgd3Ec4KVNj7ETBbWBLeRlnVTSD/YWixHzhgaxCwIKGAyD7YdiM0K4YRndURdD29/oZoNcFQh/E2d6s6hP36nGwk/Ph8hEIbJcLfxzN9uEvKQiPQGF4cyMmfUMXF8kQYUeKpDLxJOcdye5rcEStvonsl6JEi+dqFZXWnjm9UCaMs4KA53kJwEil1om3WIg3bt8qu2k+SA89JbzT95IY+6OxdRvmyNsRH2/mQoUugq8/AyQ3kr3PXY9hYQXKzjC6ouQ9kqhG83Vf1ydyJ+lIIVTqlE9rWIIXb21f917Fv2LWpvLXuWwNg/BRHfizeUVlTHLLieeB7a9m1Vqx60CEri2a+454/5HGeVF5dMGEEH45FfHn2PVgQaI+hsQ4vq80jUHaIVlJ9qTKHHV2aLQ/ocRFqoPo3+l41a7S/xoREWSn0AD+b0igNu5njYHSillVYs9oNG 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(966005)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(66899021)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(30864003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001)(579004)(559001)(309714004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?Ph6wcIazWHiED5QOzLR6MGszPFLM?= =?utf-8?q?AtozqqZZf80Kx1uw4JqUtCBrQGXsxQ3zI8VnI6MSMYjSRuz9ZJngRK8o9nGV9kdU/?= =?utf-8?q?MYNo1lFQxV2LQKGd71KVH1swi7lynrui1hrJJzbv1BYz0qZcI2iKGrW5G4leNq2NF?= =?utf-8?q?AXRlIORF8RtWmYmhqNb9WZb7heW18uJxPMri0cmmn67XpGo/bDAho8atBLFLNg8PF?= =?utf-8?q?Z+RMQaXEtgIOfPcll/9UB4zSTLqE7gmn4HdrcNtNh2NyeZ/u8tA42I9dgwLUDFpsg?= =?utf-8?q?Z/6/phaWzpl0YHSvazfQGwxIpiNswph3tpmBUipBoPhOY2uR/5wPjN/+H/lTkxNvu?= =?utf-8?q?GlAnQza0S8Fz3PbXd7+EHl2ms+ChPtU//83wQVsM2QhBOD0V6Ft/EDg54wi+Lf3IL?= =?utf-8?q?kmcW9J/cGUN0gcM9wxN/wLHo8dWEfB6KXMY2ZDnog2owOu2g3d7I5SzFtUmbssfXs?= =?utf-8?q?glK8cqgfwpCFE5tjA4s1AuN+ZDRyzJdlufmmEdVgpIPrNOkLu54v/uXpjbrhHU7EF?= =?utf-8?q?Z+Gy2qQSfwkc11TlySYspsANudiKvsD1ZYCCTSmYw4o7rqT8kObbtWbKjel7ziLwN?= =?utf-8?q?UZqZ7aujetnNYezr+/DGohMdErTfrHpbBW5d9ASmjEoHejlr6TMZMB/8WKOyWJsD5?= =?utf-8?q?WMOPsyH0Zx8vO0Yai5knfFFx5SKhbRYnWKhe5mKl6OTxIG5Mxan5cl5RPRd8nZq51?= =?utf-8?q?huMOX5jjWK0qVofVxABxMPMkt5OtyHqatHTYeF/ubT0qgHpOUIEPoiRR3w89smAfp?= =?utf-8?q?18VLl8j3EXPpV46eOa1vVC/QmUWeYQQJHaMuLorblBX240zlgJ3BCKVlNgRqSNO7I?= =?utf-8?q?315ieulBZhxc/FQP5t2TFRLisxQZpynhaF64M2X/rheRe4N9AJTATpfIAFpjWCcX4?= =?utf-8?q?JhIl3nYueXfWtIAz++2uTey9m621RIfnUe6i/X68syxyfI8iGp4XJnV26d4CcSXUe?= =?utf-8?q?PaURRK+E1HIpfqV3IucaHsguKvfsXESnqGIwyQSPW4Wk3qz/e5ZHbdySJ4ejeT0aT?= =?utf-8?q?9vPL/Vw9NaEtmCU/fLryxNc4ym7cJp37aGczsBSoTQWs1ja7i0GPIfWnMyw4ZDqCW?= =?utf-8?q?iiuft8713CTCI15uLzRPn8Z6xAVSHgseHp4Eb5PK/+rsVcil/AKpUOcyedE6ZR72L?= =?utf-8?q?G3KVpMw61EkOh4WpRq8zZh2z/8vEt0DvmcYttBD37wik0QoFgBkzlERC1X6+qHHsy?= =?utf-8?q?4qApmmJCEHvJKGSwp1bMbDwbDtej9Gq3bzet/fZ4azX1dx90bgz58MV7BJLprtfCy?= =?utf-8?q?kXrEP5wV08TjG4AVTVVapcItlJH+vA5XxSDMDTUQB1d0xJeD/ewSr7Tj/UN9q6ruj?= =?utf-8?q?L55uljkX2yV3tK2ID+Q3d5Nv5nuHq8bok1fXy2YlhZ47v8ynmqobOtgWuWXAOKqUQ?= =?utf-8?q?Tn3qysoyhjWbGoxzFb2Debw/N/NRV1QPx8PKoIo8PbthyLtyDcOLF9XBb6A/QwEdJ?= =?utf-8?q?FwJDox/tnwT9fMXr8E0JSIfaKAO63MjeHt157Qsx+FDrD4HO6P652v8LwWPIMP7Jh?= =?utf-8?q?OcE/klb1b8320WSW6l7m+J6e+59yXBGpXg=3D=3D?= Content-ID: 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: 418358fe-47b1-4849-fd6f-08db6bf97c08 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:26.9819 (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: BGl6KtVUFFpq7bzfINa/ESgBU2h9U08hlRap6FMhsd7aas81bxpsopYvDEBUBcVsGqEK1ib6oxBruJcEa8KlYuWszDBL6gPvheT82eKV8Gk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: gL1gMRsyVgjFA6e7UXKA3zTzOmHcmIpD X-Proofpoint-ORIG-GUID: gL1gMRsyVgjFA6e7UXKA3zTzOmHcmIpD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 From: Oleksandr Andrushchenko Introduce a 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. 1. Per-domain's vpci_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, check which registers are going to be written and acquire the lock in the appropriate mode from the beginning. 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. Optimize if ROM BAR write lock required detection by caching offset of the ROM BAR register in vpci->header->rom_reg which depends on header's type. 4. Reduce locked region in vpci_remove_device as it is now possible to set pdev->vpci to NULL early right after the write lock is acquired. 5. Reduce locked region in vpci_add_handlers as it is possible to initialize many more fields of the struct vpci before assigning it to pdev->vpci. 6. vpci_{add|remove}_register are required to be called with the write lock held, but it is not feasible to add an assert there as it requires struct domain to be passed for that. So, add a comment about this requirement to these and other functions with the equivalent constraints. 7. Drop const qualifier where the new rwlock is used and this is appropriate. 8. 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 9. Check for !pdev->vpci in vpci_{read|write} after acquiring the lock and if so, allow reading or writing the hardware register directly. This is acceptable as we only deal with Dom0 as of now. Once DomU support is added the write will need to be ignored and read return all 0's for the guests, while Dom0 can still access the registers directly. 10. Introduce pcidevs_trylock, so there is a possibility to try locking the pcidev's lock. 11. Use pcidev's lock around for_each_pdev and pci_get_pdev_by_domain while accessing pdevs in vpci code. 12. This is based on the discussion at [1]. [1] https://lore.kernel.org/all/20220204063459.680961-4-andr2000@gmail.com/ Suggested-by: Roger Pau Monné Suggested-by: Jan Beulich Signed-off-by: Oleksandr Andrushchenko --- This was checked on x86: with and without PVH Dom0. --- xen/arch/x86/hvm/vmsi.c | 7 +++ xen/common/domain.c | 3 + xen/drivers/passthrough/pci.c | 5 ++ xen/drivers/vpci/header.c | 52 +++++++++++++++++ xen/drivers/vpci/msi.c | 25 +++++++- xen/drivers/vpci/msix.c | 51 +++++++++++++--- xen/drivers/vpci/vpci.c | 107 +++++++++++++++++++++++++--------- xen/include/xen/pci.h | 1 + xen/include/xen/sched.h | 3 + xen/include/xen/vpci.h | 6 ++ 10 files changed, 223 insertions(+), 37 deletions(-) diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index 3cd4923060..f188450b1b 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -895,6 +895,9 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) { unsigned int i; + ASSERT(rw_is_locked(&msix->pdev->domain->vpci_rwlock)); + ASSERT(pcidevs_locked()); + for ( i = 0; i < msix->max_entries; i++ ) { const struct vpci_msix_entry *entry = &msix->entries[i]; @@ -913,7 +916,11 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) struct pci_dev *pdev = msix->pdev; spin_unlock(&msix->pdev->vpci->lock); + pcidevs_unlock(); + read_unlock(&pdev->domain->vpci_rwlock); process_pending_softirqs(); + read_lock(&pdev->domain->vpci_rwlock); + pcidevs_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/common/domain.c b/xen/common/domain.c index 6a440590fe..a4640acb62 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -622,6 +622,9 @@ struct domain *domain_create(domid_t domid, #ifdef CONFIG_HAS_PCI INIT_LIST_HEAD(&d->pdev_list); +#ifdef CONFIG_HAS_VPCI + rwlock_init(&d->vpci_rwlock); +#endif #endif /* All error paths can depend on the above setup. */ diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 07d1986d33..0afcb59af0 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -57,6 +57,11 @@ void pcidevs_lock(void) spin_lock_recursive(&_pcidevs_lock); } +int pcidevs_trylock(void) +{ + return spin_trylock_recursive(&_pcidevs_lock); +} + void pcidevs_unlock(void) { spin_unlock_recursive(&_pcidevs_lock); diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index ec2e978a4e..23b5223adf 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -152,12 +152,14 @@ bool vpci_process_pending(struct vcpu *v) if ( rc == -ERESTART ) return true; + read_lock(&v->domain->vpci_rwlock); 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); + read_unlock(&v->domain->vpci_rwlock); rangeset_destroy(v->vpci.mem); v->vpci.mem = NULL; @@ -181,8 +183,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_write_locked(&d->vpci_rwlock)); + 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. + */ + write_unlock(&d->vpci_rwlock); process_pending_softirqs(); + write_lock(&d->vpci_rwlock); + } + rangeset_destroy(mem); if ( !rc ) modify_decoding(pdev, cmd, false); @@ -213,6 +227,7 @@ static void defer_map(struct domain *d, struct pci_dev *pdev, raise_softirq(SCHEDULE_SOFTIRQ); } +/* This must hold domain's vpci_rwlock in write mode. */ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) { struct vpci_header *header = &pdev->vpci->header; @@ -287,6 +302,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) * Check for overlaps with other BARs. Note that only BARs that are * currently mapped (enabled) are checked for overlaps. */ + pcidevs_lock(); for_each_pdev ( pdev->domain, tmp ) { if ( tmp == pdev ) @@ -326,10 +342,12 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) printk(XENLOG_G_WARNING "Failed to remove [%lx, %lx]: %d\n", start, end, rc); rangeset_destroy(mem); + pcidevs_unlock(); return rc; } } } + pcidevs_unlock(); ASSERT(dev); @@ -482,6 +500,8 @@ static int cf_check init_bars(struct pci_dev *pdev) struct vpci_bar *bars = header->bars; int rc; + ASSERT(rw_is_write_locked(&pdev->domain->vpci_rwlock)); + switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f ) { case PCI_HEADER_TYPE_NORMAL: @@ -570,6 +590,8 @@ static int cf_check init_bars(struct pci_dev *pdev) } } + ASSERT(!header->rom_reg); + /* Check expansion ROM. */ rc = pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size, PCI_BAR_ROM); if ( rc > 0 && size ) @@ -586,12 +608,42 @@ static int cf_check init_bars(struct pci_dev *pdev) 4, rom); if ( rc ) rom->type = VPCI_BAR_EMPTY; + + header->rom_reg = rom_reg; } return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0; } REGISTER_VPCI_INIT(init_bars, VPCI_PRIORITY_MIDDLE); +static bool overlap(unsigned int r1_offset, unsigned int r1_size, + unsigned int r2_offset, unsigned int r2_size) +{ + /* Return true if there is an overlap. */ + return r1_offset < r2_offset + r2_size && r2_offset < r1_offset + r1_size; +} + +bool vpci_header_need_write_lock(const struct pci_dev *pdev, + unsigned int start, unsigned int size) +{ + /* + * 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. At the same time it is not + * possible to upgrade read lock to write lock in such a case. + * Check which registers are going to be written and return true if lock + * needs to be acquired in write mode. + */ + if ( overlap(start, size, PCI_COMMAND, 2) || + (pdev->vpci->header.rom_reg && + overlap(start, size, pdev->vpci->header.rom_reg, 4)) ) + return true; + + return false; +} + /* * Local variables: * mode: C diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index 8f2b59e61a..e7d1f916a0 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -190,6 +190,8 @@ static int cf_check init_msi(struct pci_dev *pdev) uint16_t control; int ret; + ASSERT(rw_is_write_locked(&pdev->domain->vpci_rwlock)); + if ( !pos ) return 0; @@ -265,7 +267,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 +279,15 @@ void vpci_dump_msi(void) printk("vPCI MSI/MSI-X d%d\n", d->domain_id); + if ( !read_trylock(&d->vpci_rwlock) ) + continue; + + if ( !pcidevs_trylock() ) + { + read_unlock(&d->vpci_rwlock); + continue; + } + for_each_pdev ( d, pdev ) { const struct vpci_msi *msi; @@ -318,14 +329,22 @@ 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: + pcidevs_unlock(); + read_unlock(&d->vpci_rwlock); + process_pending_softirqs(); + + read_lock(&d->vpci_rwlock); + pcidevs_lock(); } + pcidevs_unlock(); + read_unlock(&d->vpci_rwlock); } rcu_read_unlock(&domlist_read_lock); } diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index 25bde77586..b5a7dfdf9c 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -143,6 +143,7 @@ static void cf_check control_write( pci_conf_write16(pdev->sbdf, reg, val); } +/* This must hold domain's vpci_rwlock in write mode. */ static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr) { struct vpci_msix *msix; @@ -163,7 +164,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->vpci_rwlock); + rc = !!msix_find(v->domain, addr); + read_unlock(&v->domain->vpci_rwlock); + + return rc; } static bool access_allowed(const struct pci_dev *pdev, unsigned long addr, @@ -358,21 +365,34 @@ 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->vpci_rwlock); + + msix = msix_find(d, addr); if ( !msix ) + { + read_unlock(&d->vpci_rwlock); 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->vpci_rwlock); + return rc; + } if ( !access_allowed(msix->pdev, addr, len) ) + { + read_unlock(&d->vpci_rwlock); return X86EMUL_OKAY; + } spin_lock(&msix->pdev->vpci->lock); entry = get_entry(msix, addr); @@ -404,6 +424,7 @@ static int cf_check msix_read( break; } spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&d->vpci_rwlock); return X86EMUL_OKAY; } @@ -491,19 +512,32 @@ 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->vpci_rwlock); + + msix = msix_find(d, addr); if ( !msix ) + { + read_unlock(&d->vpci_rwlock); 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->vpci_rwlock); + return rc; + } if ( !access_allowed(msix->pdev, addr, len) ) + { + read_unlock(&d->vpci_rwlock); return X86EMUL_OKAY; + } spin_lock(&msix->pdev->vpci->lock); entry = get_entry(msix, addr); @@ -579,6 +613,7 @@ static int cf_check msix_write( break; } spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&d->vpci_rwlock); return X86EMUL_OKAY; } @@ -665,6 +700,8 @@ static int cf_check init_msix(struct pci_dev *pdev) struct vpci_msix *msix; int rc; + ASSERT(rw_is_write_locked(&pdev->domain->vpci_rwlock)); + msix_offset = pci_find_cap_offset(pdev->seg, pdev->bus, slot, func, PCI_CAP_ID_MSIX); if ( !msix_offset ) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 652807a4a4..1270174e78 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -38,20 +38,32 @@ extern vpci_register_init_t *const __end_vpci_array[]; void vpci_remove_device(struct pci_dev *pdev) { - if ( !has_vpci(pdev->domain) || !pdev->vpci ) + struct vpci *vpci; + + if ( !has_vpci(pdev->domain) ) return; - spin_lock(&pdev->vpci->lock); + write_lock(&pdev->domain->vpci_rwlock); + if ( !pdev->vpci ) + { + write_unlock(&pdev->domain->vpci_rwlock); + return; + } + + vpci = pdev->vpci; + pdev->vpci = NULL; + write_unlock(&pdev->domain->vpci_rwlock); + while ( !list_empty(&pdev->vpci->handlers) ) { - struct vpci_register *r = list_first_entry(&pdev->vpci->handlers, + struct vpci_register *r = list_first_entry(&vpci->handlers, struct vpci_register, node); list_del(&r->node); xfree(r); } - spin_unlock(&pdev->vpci->lock); + if ( pdev->vpci->msix ) { unsigned int i; @@ -61,29 +73,33 @@ void vpci_remove_device(struct pci_dev *pdev) if ( pdev->vpci->msix->table[i] ) iounmap(pdev->vpci->msix->table[i]); } - xfree(pdev->vpci->msix); - xfree(pdev->vpci->msi); - xfree(pdev->vpci); - pdev->vpci = NULL; + xfree(vpci->msix); + xfree(vpci->msi); + xfree(vpci); } int vpci_add_handlers(struct pci_dev *pdev) { + struct vpci *vpci; unsigned int i; int rc = 0; if ( !has_vpci(pdev->domain) ) return 0; + vpci = xzalloc(struct vpci); + if ( !vpci ) + return -ENOMEM; + + INIT_LIST_HEAD(&vpci->handlers); + spin_lock_init(&vpci->lock); + + write_lock(&pdev->domain->vpci_rwlock); + /* We should not get here twice for the same device. */ ASSERT(!pdev->vpci); - pdev->vpci = xzalloc(struct vpci); - if ( !pdev->vpci ) - return -ENOMEM; - - INIT_LIST_HEAD(&pdev->vpci->handlers); - spin_lock_init(&pdev->vpci->lock); + pdev->vpci = vpci; for ( i = 0; i < NUM_VPCI_INIT; i++ ) { @@ -91,6 +107,7 @@ int vpci_add_handlers(struct pci_dev *pdev) if ( rc ) break; } + write_unlock(&pdev->domain->vpci_rwlock); if ( rc ) vpci_remove_device(pdev); @@ -139,6 +156,7 @@ uint32_t cf_check vpci_hw_read32( return pci_conf_read32(pdev->sbdf, reg); } +/* This must hold domain's vpci_rwlock in write mode. */ int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, vpci_write_t *write_handler, unsigned int offset, unsigned int size, void *data) @@ -162,8 +180,6 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, r->offset = offset; r->private = data; - spin_lock(&vpci->lock); - /* The list of handlers must be kept sorted at all times. */ list_for_each ( prev, &vpci->handlers ) { @@ -175,25 +191,23 @@ int vpci_add_register(struct vpci *vpci, vpci_read_t *read_handler, break; if ( cmp == 0 ) { - spin_unlock(&vpci->lock); xfree(r); return -EEXIST; } } list_add_tail(&r->node, prev); - spin_unlock(&vpci->lock); return 0; } +/* This must hold domain's vpci_rwlock in write mode. */ int vpci_remove_register(struct vpci *vpci, unsigned int offset, unsigned int size) { const struct vpci_register r = { .offset = offset, .size = size }; struct vpci_register *rm; - spin_lock(&vpci->lock); list_for_each_entry ( rm, &vpci->handlers, node ) { int cmp = vpci_register_cmp(&r, rm); @@ -205,14 +219,12 @@ int vpci_remove_register(struct vpci *vpci, unsigned int offset, if ( !cmp && rm->offset == offset && rm->size == size ) { list_del(&rm->node); - spin_unlock(&vpci->lock); xfree(rm); return 0; } if ( cmp <= 0 ) break; } - spin_unlock(&vpci->lock); return -ENOENT; } @@ -320,7 +332,7 @@ 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; @@ -333,10 +345,18 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) } /* Find the PCI dev matching the address. */ + pcidevs_lock(); pdev = pci_get_pdev(d, sbdf); - if ( !pdev || !pdev->vpci ) + pcidevs_unlock(); + if ( !pdev ) return vpci_read_hw(sbdf, reg, size); + read_lock(&d->vpci_rwlock); + if ( !pdev->vpci ) + { + read_unlock(&d->vpci_rwlock); + return vpci_read_hw(sbdf, reg, size); + } spin_lock(&pdev->vpci->lock); /* Read from the hardware or the emulated register handlers. */ @@ -381,6 +401,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(&d->vpci_rwlock); if ( data_offset < size ) { @@ -423,11 +444,12 @@ static void vpci_write_helper(const struct pci_dev *pdev, 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; const unsigned long *ro_map = pci_get_ro_map(sbdf.seg); + bool write_locked = false; if ( !size ) { @@ -443,14 +465,38 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, * Find the PCI dev matching the address. * Passthrough everything that's not trapped. */ + pcidevs_lock(); pdev = pci_get_pdev(d, sbdf); - if ( !pdev || !pdev->vpci ) + pcidevs_unlock(); + if ( !pdev ) { vpci_write_hw(sbdf, reg, size, data); return; } - spin_lock(&pdev->vpci->lock); + if ( vpci_header_need_write_lock(pdev, reg, size) ) + { + /* Gain exclusive access to all of the domain pdevs vpci. */ + write_lock(&d->vpci_rwlock); + if ( !pdev->vpci ) + { + write_unlock(&d->vpci_rwlock); + vpci_write_hw(sbdf, reg, size, data); + return; + } + write_locked = true; + } + else + { + read_lock(&d->vpci_rwlock); + if ( !pdev->vpci ) + { + read_unlock(&d->vpci_rwlock); + vpci_write_hw(sbdf, reg, size, data); + return; + } + spin_lock(&pdev->vpci->lock); + } /* Write the value to the hardware or emulated registers. */ list_for_each_entry ( r, &pdev->vpci->handlers, node ) @@ -485,7 +531,14 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, break; ASSERT(data_offset < size); } - spin_unlock(&pdev->vpci->lock); + + if ( write_locked ) + write_unlock(&d->vpci_rwlock); + else + { + spin_unlock(&pdev->vpci->lock); + read_unlock(&d->vpci_rwlock); + } if ( data_offset < size ) /* Tailing gap, write the remaining. */ diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 5975ca2f30..4512910dca 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -157,6 +157,7 @@ struct pci_dev { */ void pcidevs_lock(void); +int pcidevs_trylock(void); void pcidevs_unlock(void); bool_t __must_check pcidevs_locked(void); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 85242a73d3..78227b7a1d 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -460,6 +460,9 @@ struct domain #ifdef CONFIG_HAS_PCI struct list_head pdev_list; +#ifdef CONFIG_HAS_VPCI + rwlock_t vpci_rwlock; +#endif #endif #ifdef CONFIG_HAS_PASSTHROUGH diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 0b8a2a3c74..3a7fcc4463 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -57,6 +57,9 @@ uint32_t cf_check vpci_hw_read32( */ bool __must_check vpci_process_pending(struct vcpu *v); +bool vpci_header_need_write_lock(const struct pci_dev *pdev, + unsigned int start, unsigned int size); + struct vpci { /* List of vPCI handlers for a device. */ struct list_head handlers; @@ -83,6 +86,9 @@ struct vpci { } bars[PCI_HEADER_NORMAL_NR_BARS + 1]; /* At most 6 BARS + 1 expansion ROM BAR. */ + /* Offset to the ROM BAR register if any. */ + unsigned int rom_reg; + /* * 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 Jun 13 10:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278332 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 6B7E4C88CB4 for ; Tue, 13 Jun 2023 10:33:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547996.855705 (Exim 4.92) (envelope-from ) id 1q91KM-0001jG-DM; Tue, 13 Jun 2023 10:32:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547996.855705; Tue, 13 Jun 2023 10:32:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KM-0001j9-Am; Tue, 13 Jun 2023 10:32:42 +0000 Received: by outflank-mailman (input) for mailman id 547996; Tue, 13 Jun 2023 10:32:41 +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 1q91KK-0001il-Ve for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:41 +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 9d71503e-09d5-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 12:32:37 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5KY019280; Tue, 13 Jun 2023 10:32:33 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:33 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:30 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:28 +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: 9d71503e-09d5-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ECFcuEJk+JKFmeKInrb/bLSRIwP5S9Bje6ypSBeNHyWg91GQqmm1SIPw/kecxdrr9xHXYNEmGW9vVDX2hikzwTj7xwppk3L7xdeWYkjATDGieq3o3BLyafw8Hld2ALoPoGgThDyUNwVd1L1zwlEZldoDfwYpXuwKI7w0lsCUc79HjINkcFndjDzNQ0/4cUzYRJQEbSd2ifNq81HdQFMcnwIMRDaom1UQGOOjKrI9vN9sI+CJH+EpwYiSqgvdaPhry9cQQZOuZBerWCdWMRUc3CpBaKRP8q/CGG13S6QarTHzV2Lw4OEcgwFlZeTy0DtdPNwFwjN9l0nsEmxB8o9PMw== 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=pzQgHIvh4Yevy8ekMSaMLkJ3eNO1G8Dye2joimf+kvw=; b=Ra0yTTHywEBTBOL9yYWVFWcjIYwm/FS9zCVQu5wsMinN78qaZSQfO/UOLntd+eSXPWOTAhd/KVHA/XcYjt0yvlYmA6TsoazOZOSw87Po6bLd5klACbfs0aJgxgQGB1ILYDiRrTNyqWlI7obG/QX1875Xx6IU1mIEhtLS7d54Lhh6S8KXlGmGgrwnajH6KlM9bXJMykWAs8INsiC2j+nBUqUHY/8MHq2Fxhh8xJ0pKbFxKXphSRBdUYbsHolzt7RY9xJfu0XmnxQAbhSjVtM68FhHwKomdzJdOw9xmDgo5Mg/OjHbs1NHvDhVSpLM6AUCx7xsa1bgQJbpaGb/eLrEtQ== 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=pzQgHIvh4Yevy8ekMSaMLkJ3eNO1G8Dye2joimf+kvw=; b=YAkov4b/MnMMcd6PeiCvlKiTspNK4CZIy4Z4WA1i7B8W+tFvTo9YMYU0c4adTFqLR9OXatLQ7Mnd0S1/EP2i7tpoeij/ZaZbKhqcjYQTsofh2WdZIhmC2Bn6dmOg6OG5AbQEj46IsgXHjBPlvldNpUblYMdkRksppCXX059CusZvDq3sE6fDJYL8EALqRSbvOUbYV3L3DJVev227vFSFrIBYmLF3YY6hwVTC+TNuUQgsW4JoZCE5a3rfOtjgqw1f8eEFz8HxiRBd8sjYjp+6ylwAnA7fG8rCTeOSAOyjayevF1+95cZzPAuZRYOycqqY4p31Uk+JV+h7BLOzysFNow== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?utf-8?q?Ro?= =?utf-8?q?ger_Pau_Monn=C3=A9?= Subject: [PATCH v7 02/12] vpci: restrict unhandled read/write operations for guests Thread-Topic: [PATCH v7 02/12] vpci: restrict unhandled read/write operations for guests Thread-Index: AQHZneJZ4Y/QK9l300mPh5Vy/DhSyA== Date: Tue, 13 Jun 2023 10:32:27 +0000 Message-ID: <20230613103159.524763-3-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: 79d0447c-84d2-47f5-9546-08db6bf97c63 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: O2noGJvs/dXZu12yDA5fO3BXQvQbkhuceF/ZQPIFteTvrQDGkIYsxp/ZKrDi29YjuE1YirCXKqI6oE+IbMKsCNep0apkdGDWazvtNVQWe+hHtNbTm7vQ4yXtduQNuXQC592C6//bxNM4LNhFYxT5qiNLCpoj9KXbPwktgYy4qwwJJxVwMYhuKpzdDNSmYh9rh1EZXG24rQ/kGJx11CRszrXdd90sUOFAY0k/vRL3Cnu+ukJ1K+DwOMDX8kRI+ESc1wBf3fxFGiAaoQ2QaeSzRtJn7RIPa4eglLOwHVShUfx4oqOhEnaBS8Dskn0U7tPUlijxEA9ttNLqAODTkOM+OCypCTPPeE8QRK7Bma79Z+YwOnzBRvnPYmlORbSDI2XU7VbCjHV6Np4mvNeDi3aU1ptP+K04mHuB2S2xe5aJygu8B5fYde7OEzpI6b3dC5tkURSd/Pw5oFb0EEesHUEj/ifXStjUOpshjTsllLOc0Irip5QCRMb68XbEqABl58QYrZbnBLZDN3Jn+f8iUlDhMPEzNty8ZONRInNmMYtvHP9eEkNNGw4SUaqDxwGg9ZkmDRXQQdQdjAkfkRZz00Ozl0p+pTdL3P1fGbXOcyr+18KPdQa5d7q2bq61hgeOPLT4 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?oyrf2bprg6k4M/f77/RMKXWNmYrS?= =?utf-8?q?DHVP+q/hBA//fkcAB8rcEhzMhiamz3kLfWvt+VGrqE80X7HT0rdFuusOaccCotp6q?= =?utf-8?q?LlIe1P5go6sxNqxi+kAtjvEfwW1VevklJ1Dqk4TSblXo5Yz/Ggpc0l0+9um+YscnY?= =?utf-8?q?UxyN0/+5ek3YTS6oAwHEUIuXPZtgCPk3k239UmWaw3FQXIwnK9ids+quXOX50BoId?= =?utf-8?q?OPdSEY4g5x0vXBVXioTM7f0e331SY9u7Easg564CNmZDAUruFzVCSBMho5ZtA4L4c?= =?utf-8?q?IS8i/dZeqGEZKtQi14+aWMfA8+/IRcaZzJYHlVbienLLbH4cyrLDOr39QZEgnLKq1?= =?utf-8?q?Vj3VAXqeSFOO5uH5UA29LTVXSjpZTUOH+J3oHt5SeLHl/anH8DJGGratd4YRhCv7h?= =?utf-8?q?Y/UxMSYiRRYS9+V6dfXI1o3tOEmwWe/iJUNupRK3x6XS00FPZam3j6CY+V8+qc7X0?= =?utf-8?q?OwruD9bGzTk0QAMvFd1ZgpG70MRmYvUbLRoMtugZoxpoTiJGlUbszSpSaBrImGuNM?= =?utf-8?q?wj9qrv4aFeXuANKZHm7wfPs9hAgDP2GEQAn4dZPdD7AFGV5Cfuk7TWH7J1i8a0e1s?= =?utf-8?q?QJ0MayTNr52rBvuXUEzLzDJT7SQtssF7y89qXu5XadCIzkSNEjUD7JU02O6nwRR2n?= =?utf-8?q?cM0WbgGZrlFvr7dyfk3dB8HT9Yj31d7MJa2ITwvOGsWFnx5PGy34YqATppc/ZCgf6?= =?utf-8?q?x9z/PaInwFRWWWm6tfcxY5Tj2xalsDa1zJIp9fzgIpKzds8YxPVcHcpO+VmxZM7/W?= =?utf-8?q?1Y1kf4TI3eLQ8qnwIa13jp/mEZ+WQUEOG2FxhjjQUb+aIbAdza211cxoAMYmyqSy9?= =?utf-8?q?xPvEaUs3GSN+UWwUrKLi3pIwPSYp2UdZBV89bkxyDejVuAOXUFe1uxCNBFerdQriK?= =?utf-8?q?nVb/IrB2T36QbMuIMDWpvBYPubSBJTu0ok+jxWWV4gaVqT6cLhJQMxSqrYsSr5erR?= =?utf-8?q?Afs6Jj7pMyD9jY9MsK9xmbUeJj1m2x07V4FEkiY2koMy8X1RaI+Tmon33bswjwOCJ?= =?utf-8?q?mFfWOTlJj3u6jBH01d7DmhiELt+oxslgNq35LYa5vaTXsWUwRU79KP1JCaYVDiBd3?= =?utf-8?q?VCzYEyhF+44uqExh3bR3knvH6eVEcbvfQd/DC8/kaDUpdf7CU/GHa/9Wb7PBHHREh?= =?utf-8?q?xYv4rTafTpDIPtYjpJK/+EY6sTVbpaN9kIL1Q4UQinuH/GQLamkCQIryPXZflxSX9?= =?utf-8?q?fA/uuD5QVYqa9C2du0lsJbWRDfwuP3NsHUfomm1qazPCdDQEpgDwUA/NikA2Nj/5G?= =?utf-8?q?I2lZsRvFOkMg291uZ8hXJZk/UlgAt2riw3HsndF+1+px4r5/9fU1y1aty4/omBljq?= =?utf-8?q?ZI5s5rESL8DUrH3LgxKoGoC4sEF0Nz81jdv/XJOhee2vLOjv1CXYjMSWs8pV0oYWl?= =?utf-8?q?dknaFB0OzGuKZqQi3OM593cI+YPEff94maYC7YyNM2ZxXzBJs1c+zifmGBWWDk8EW?= =?utf-8?q?aemAisTsfQIl+rqDbpdDIYr9IMyuaZFOiu1nxNjkcofaE2z3FB4w/xzrDPTCRziw/?= =?utf-8?q?R4QFfR2p1sGoQtwq8gaBbSxSIY/bsOxs8Q=3D=3D?= Content-ID: 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: 79d0447c-84d2-47f5-9546-08db6bf97c63 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:27.2488 (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: E1YiMFiGL5YgB7NpFXpmEEm/3vvfLOZJrWb6NR3UXzGjLmcfPzg3WF3KY5VcojL4e7okg4LkPVeb8QxWUTGyNpQS/2tw8ZWPEfXUdwRO6BQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: R15PgsG3ft5Sxe8Pli3J6NwUJ4UZDr0z X-Proofpoint-ORIG-GUID: R15PgsG3ft5Sxe8Pli3J6NwUJ4UZDr0z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 --- 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 1270174e78..0b11d9c3f8 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -235,6 +235,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: @@ -275,9 +279,13 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, return data; } -static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, - uint32_t data) +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 Jun 13 10:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278335 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 84CA8C77B7A for ; Tue, 13 Jun 2023 10:33:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548005.855776 (Exim 4.92) (envelope-from ) id 1q91KV-0003e8-9T; Tue, 13 Jun 2023 10:32:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548005.855776; Tue, 13 Jun 2023 10:32:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KV-0003dp-5K; Tue, 13 Jun 2023 10:32:51 +0000 Received: by outflank-mailman (input) for mailman id 548005; Tue, 13 Jun 2023 10:32:49 +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 1q91KS-0001im-Ve for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:49 +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 a2ff8b91-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:47 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5Ka019280; Tue, 13 Jun 2023 10:32:35 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:35 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:30 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:30 +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: a2ff8b91-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dXcPM430Y0AzK7Lbi6uqAI4PDwVMUU7Tokq6AYARaL9rGoumjn2gomfl9UusCOz0RGla1DIlnw47GjZpOzmqDpSN+DgKKHtDfrgZkuo+E/hD0XNddBFRPZ5bAeK1Hu96uclL+/HcfFvyEoFetofd32UZa+U4AcxR8ei6MauoKUJjk/6eG8LmeQjP2ruF79RbzVAJ7iz7M3xeUHhf4IOz3aTX1wmZKdh1YRSUYPthy5W16jYo1hUKL/ox8MpO+kRXbyb9XiGM8X47NB5OjU/0EOWh/WQ/Pr38iu0MpB5g6lTxbisK2ueNMe1Nw2XvDggMt0y9XIeYMhkipuS7jCrPKQ== 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=Y4ds1N6Vp7dUlaANy/wSVy9nlYUhCmnAHHk12HItlTU=; b=G+zkOZimS+oX3WytR4+2P9J7WPYXWdyCzl5eC12uCGs9Fbw/qN3/9yCiQGKllTAWxaX2WLRsp4sCcjVFTEhPELeqIULzbM7PYZ0UP5u1qVk2wCU6t8S1v87Mcd5Dgn0CeKOLcrj2GpLwaoHRX9A/aXWqb6z+j4WtNkANO02ISgBA7eDbPpqs7Mwl3I3/COlkPzzhOHujQuZqseRKR475h54JTqezQZs4zJBZ9gmCu61vgYDRAvKy19AHf6/i+hqQ+ZxdccWWXUc5AhJVhxbeSbml5RotVq8N/TcjdbdmUAXF3pijO4EptZ5aC0cZZ2bmkkiW5FfcpervrjL0ZJCjqg== 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=Y4ds1N6Vp7dUlaANy/wSVy9nlYUhCmnAHHk12HItlTU=; b=OeDZ52hx11DmqMCIWM52DxOlMpEIKJdI60C6194DaETT6neSaReIAbXRkOjuwatux09If6aihNcOAnHuW6SwIv4m1zdrR1UU8j3yRMhfXXxp5gxkuyhAhv89gtpuqrRo+7L96R0G0QGb2oLmPA24XHtiUMhNgd+vyeraVuAmEjrD6fFyROLhBS0merGRsPG7AFPtN497VGD+nxKlgPY2jt7JBH2ofoo30daQGx3Ix0F5U+G1v5Q8k4lunhp7ErLrT4L1RGOCR2+IKFXKOP9lBCQQ6heVpkYxmLexKXm/0Wmq8EHyvev8fAc3CTFlEBXyeqCcRvDfYX6tOuhYRy6niQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: 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?= Subject: [PATCH v7 03/12] vpci: add hooks for PCI device assign/de-assign Thread-Topic: [PATCH v7 03/12] vpci: add hooks for PCI device assign/de-assign Thread-Index: AQHZneJZP53w2XmssEurF7oAFnlHXQ== Date: Tue, 13 Jun 2023 10:32:27 +0000 Message-ID: <20230613103159.524763-4-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: fa9bfe89-2f24-46d1-cbb8-08db6bf97de5 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3H1r/kDYrmXXsIAEvrwDum+66PlVVU1yPfkh5tC6IExSlwR6/4jV4ba+8YMg33ZSlmPpZDMQxfRur03dUgRotZyx5YcXtC4cm/xpgs1JX3q51m6MdJOKbEAYnuFqdToOOOmwvxB5iDBUWBmJ2AuYykrtXuRh4zPrwcVctGGeK6LjGboMemjm+vtkwc9cKKagyPT4BIxMdLOqkmTNlnacfFgK09crqD0GTwkzoWZWWkxzGbdWG6IJ6ueYq+ss+PrTFERLAXjnO8GWMtVgpZxTKyFXnL4ExGi/fu9mYAopP8w8pltOLwO8lhqZeIgLB0x0cJerWeCi4jztEGXlAVprPNagqzPHoeO84yVcukpk8Tsv+4tzAC6mtzrGwpFhBIB8PlBSbawsYe5lRAXWM1x99tWdqRB6ehg5VaMLKEn+D8dSRRa7VXXQg7Xg458rBHQtHUDre3UmQKm4fHM07juOvsLsVYtvfzekC7No1hmQhYwbLlyBmLI++2nsEk7kuOtjyRM04vIqLSlGLhjP6ITZVZs8ntqplAGokEG0JZAWMw9FgrArmbd58fpFA5yGGw9QWzo7bBRBhhXG8/zuHGUekdKPYUDW62B7uBBkj9am7/2Ok699Tkie2I6H2sO7YYR4 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(6666004)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?kiGhCGnv88Uc4hL9cBf37oV?= =?iso-8859-1?q?HBsGXlo6sKm3vZJE7Tq7yfr2X0EdQ93Qn1Qh2OOrwsK/tJMTbpBYVwX/JFDj?= =?iso-8859-1?q?BZhKs6xxNNi2GXxvupfR8RZ1Hogo8usg3/OjEYtDCN6M9t9jaIu7JxZCDoLf?= =?iso-8859-1?q?FSM8uqFifAA3ZDhUDeUB/r2RB6Vanw/83eD7KjcTabh51hVrnX0dEpPUUv4n?= =?iso-8859-1?q?xJiBGbLlYGwFDFiLRzfXkii5w9D6FcSb4lbxeUFu1JL4o43TYhW2f7pGbkCp?= =?iso-8859-1?q?UpdaAT9fWYwa6Mdtd8P99yUI5CPRRDySECrPr3w3a+ICO1b2YveSwEuQ0bX2?= =?iso-8859-1?q?CW3GCDkC9yq/Hvn5QnyIFTHrN6GhdHJpKRnaYE73xEYinVIBcIB0JEH0aduQ?= =?iso-8859-1?q?Qcnqw6UmmYLlOD9T/o3XRDpKSdIQaXPLk5O/5VhSvvjNcOtzEotZdbEkoRAK?= =?iso-8859-1?q?LEex3S4m7ZASPPnwuIZl5FxZjysHOOcxdphyooFMz073+PQUkHYS09bs7iLZ?= =?iso-8859-1?q?MzapgKA0WjKPvNvRW9S7TAckBKEzMfkwmdBweJ24aqWEFysKPz0Qn76NOATE?= =?iso-8859-1?q?VEPh+QaXQ4peOf2vXuGJ7IckvbFv6OU4CXcOoBQHgR5SnB3Tx+b87VDV2IVT?= =?iso-8859-1?q?O0CbCNzqPftgvQaRL6KSTMautnxbIr07DnIPF/MZp73pE8E7bKHlThvFQ607?= =?iso-8859-1?q?IxSTrvapv4kgFgZwkGgtth5/6zhyIeH6br83pKYnb9PAZ8LLnwlhPyX8hMRf?= =?iso-8859-1?q?geY6ZZDXz7Xr+vWVBlihqvfwrd0aazjb/ae5TXZaDg/T6KX+z+V5vy1Fm6Gv?= =?iso-8859-1?q?mf4D06wVaV0nSbiHohVHySndFPjSxo85T2jAlGNQRWdWK9y6WpyNxL+jpVSq?= =?iso-8859-1?q?WDlYnDrFzkmcnCm6OASJP68kxKuDKJKPVhqNMfVyFna5pHFOzsoej9zMucT2?= =?iso-8859-1?q?jbXeutckcg4uVou+REZoIIl9/OpSoEULqzwyX3QQ2IiZUn3CJrZsdZoPwRyL?= =?iso-8859-1?q?DYwZ/Ww9tMClKoPzqcKajWbMNTdyUg314+kl/Peoxh/sJSHdWAF8o70fFqre?= =?iso-8859-1?q?oMNKKa9nDUVIcWO6JUX+SMAWqGN/FHdS471pBURlyIRiXjAruhQO4aftbyvC?= =?iso-8859-1?q?QomMVNEOQ2wpgsj/Uth3Sv/v2l27NJau114YxFLVxlHXItE0E8V0M9sgcUe7?= =?iso-8859-1?q?jOljT4JcvBKpO/4Y0OizN99LeDH6pxmdIma65L+XekLHpMqDJnoLDDysCx6A?= =?iso-8859-1?q?+8DQVglHCJxUreJ44JcBuWvVtKpyEu3hcUeED8dVTpIpsxac1Q0O0i9IFq4u?= =?iso-8859-1?q?1RImz8zzi2RzRDdHXaPQj1k1QGe56N3PPhmzJIzVPu3lObJqePJxVYv4xEry?= =?iso-8859-1?q?VUrqFoaVNBqZunA6vq02r+IL0EtKqOd0HCJYp2P2BsLVdAVAvfvoV17N8nVB?= =?iso-8859-1?q?un6bdpe3i1zBcRLr7p00vj0xZGLmxNNuLSjgnnBtq4kvEV3CnVy1fIbQsNuX?= =?iso-8859-1?q?hIp7JiuuxK8dkV2wByBNSdbMgWcucvOgLjYCOzi9IgvnlCn8yVpW2i27Fpxm?= =?iso-8859-1?q?jt5ixilYYbpJ72rxYQdpJ13odwkcMa5hIcYR0NeuzlBnxXG5Ty0ao4XqL2r8?= =?iso-8859-1?q?7OznoRz+DFHrbEoVT0oS7RJiFm/lbQeXJv62o/Q=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: fa9bfe89-2f24-46d1-cbb8-08db6bf97de5 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:27.5060 (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: RN+bhgKNKmjVpGUpks2R0tF9bwlP4Wj11u2dJJ1l9MCNCcIN0+EUOcj0FTHfdG/s6m/EfD6zT0XlI6SixwQta/qyhAdkt8D4sd1kIe19HcA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: hZrBNS6L2x-zXTuYiJGvJeB00Ny7B0ii X-Proofpoint-ORIG-GUID: hZrBNS6L2x-zXTuYiJGvJeB00Ny7B0ii X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 From: Oleksandr Andrushchenko When a PCI device gets assigned/de-assigned some work on vPCI side needs to be done for that device. Introduce a pair of hooks so vPCI can handle that. Signed-off-by: Oleksandr Andrushchenko --- 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 | 11 +++++++++++ xen/drivers/vpci/vpci.c | 27 +++++++++++++++++++++++++++ xen/include/xen/vpci.h | 15 +++++++++++++++ 4 files changed, 57 insertions(+) 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 0afcb59af0..f43b40508a 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -877,6 +877,8 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, if ( ret ) goto out; + vpci_deassign_device(pdev); + if ( pdev->domain == hardware_domain ) pdev->quarantine = false; @@ -1417,6 +1419,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) { const struct domain_iommu *hd = dom_iommu(d); struct pci_dev *pdev; + uint8_t old_devfn; int rc = 0; if ( !is_iommu_enabled(d) ) @@ -1436,6 +1439,8 @@ 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; + vpci_deassign_device(pdev); + rc = pdev_msix_assign(d, pdev); if ( rc ) goto done; @@ -1453,6 +1458,8 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) pci_to_dev(pdev), flag)) ) goto done; + old_devfn = devfn; + for ( ; pdev->phantom_stride; rc = 0 ) { devfn += pdev->phantom_stride; @@ -1462,6 +1469,10 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) pci_to_dev(pdev), flag); } + rc = vpci_assign_device(pdev); + if ( rc && deassign_device(d, seg, bus, old_devfn) ) + domain_crash(d); + done: if ( rc ) printk(XENLOG_G_WARNING "%pd: assign (%pp) failed (%d)\n", diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 0b11d9c3f8..4182c65eaa 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -114,6 +114,33 @@ int vpci_add_handlers(struct pci_dev *pdev) return rc; } + +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +/* Notify vPCI that device is assigned to guest. */ +int vpci_assign_device(struct pci_dev *pdev) +{ + int rc; + + if ( !has_vpci(pdev->domain) ) + return 0; + + rc = vpci_add_handlers(pdev); + if ( rc ) + vpci_deassign_device(pdev); + + return rc; +} + +/* Notify vPCI that device is de-assigned from guest. */ +void vpci_deassign_device(struct pci_dev *pdev) +{ + if ( !has_vpci(pdev->domain) ) + return; + + vpci_remove_device(pdev); +} +#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ + #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 3a7fcc4463..5383ede556 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -270,6 +270,21 @@ static inline bool __must_check vpci_process_pending(struct vcpu *v) } #endif +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +/* Notify vPCI that device is assigned/de-assigned to/from guest. */ +int vpci_assign_device(struct pci_dev *pdev); +void vpci_deassign_device(struct pci_dev *pdev); +#else +static inline int vpci_assign_device(struct pci_dev *pdev) +{ + return 0; +}; + +static inline void vpci_deassign_device(struct pci_dev *pdev) +{ +}; +#endif + #endif /* From patchwork Tue Jun 13 10:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278342 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 D177CC88CBD for ; Tue, 13 Jun 2023 10:33:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547998.855717 (Exim 4.92) (envelope-from ) id 1q91KM-0001td-WB; Tue, 13 Jun 2023 10:32:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547998.855717; Tue, 13 Jun 2023 10:32:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KM-0001rz-Rd; Tue, 13 Jun 2023 10:32:42 +0000 Received: by outflank-mailman (input) for mailman id 547998; Tue, 13 Jun 2023 10:32:41 +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 1q91KL-0001il-9R for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:41 +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 9dc236fc-09d5-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 12:32:38 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5Kb019280; Tue, 13 Jun 2023 10:32:36 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:35 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:31 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:31 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9dc236fc-09d5-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cgs50T4PHJFAx6AN472fH7lOQR+CdRNilfvZPfLopN+qB03XMd16Av8PDHKcEA7aVki71QLvF+rSnGkcOJ2dm1776V66xCKjV0goefqyNpFjQu+drV2RenFDiWuFNaJPJFaMr2z6YLpEWUVfuLgh27P7yyWyxZtbE0Wag3e93ADz4rxAIZNV/ciEUW6Ve9N6DZ5KXUX8wUW9DmkxDaFCAKx+BVQGACLmQT8+KQZXIIuDNoPBJVWWGvldR4Rr/eM1JEnopT3U1wmAEm/7sJdDxDpp7r8n82vkI5YkdcN3/rOt4kcRTnd+nWD/kWfPVlW6wKeAmjrLcZHUzuxaeXBsVA== 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=bg2Pv1RvB/O+YBpcN1DSr5WA6RwAEpXU/ehRxVBAmd0=; b=RY35SzCwv5enZ9PZ9bITKyGeF1ETQx7zrw9inDii+TIDs+yNCLCWYKi9S72nWcBbkI8n7TNFtwfWxDW8vGOyo279Yl7K4abwgn8nbXMwy7gNh3bouNaqQb/5Nr0u4W57H9Y3nIeUZqMqzXPccsCstJGmoU53erFnmBKD//GkNscxUw8dI/rsmz0jgUu7gVl9CCWSt8ScWais+IBW30JtcVs8HZhCBfJT0868HFI5pktuRRgxQHv0eFxZ3uzWlSKyateVBdHThE7XGbO7DR/tXSJqLI3VZvjQZR/IaHb5UCj7y/Ti96UdPsUXY18v6qGLsdrHEhUoQeBOk9GNJJnOlg== 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=bg2Pv1RvB/O+YBpcN1DSr5WA6RwAEpXU/ehRxVBAmd0=; b=JbmF4h0Xf7gAFIGnbj7Melf6KO/TQRdIFlPHALmaaNQwLFQVkc+TLt9eNBcliedy27x1cptK9Mnv9AWjG7Dh6IY87xa1Q//0ySpGnIklYsT8Z5Rtto+H0VKNfDmqoLiVRIanGX45ZmgcK5E9c0NoA8jOsMaK6ZuB6ZtsYt3IkKoMNueW9+jO3BOGnCOK20Fr1A1x3zWMQj7lQwUcYa1Vr6FAvuSWm0QVnRy2Ri32YEw89OLCIjXoBcmp2EDJCdiFFCpfoQpwPW2ygAVtsABdXu8uuJKm1U1JP5TN8yNiZPkp0nbnrsyZSI1qVFGlkHwijUNXMJOeSWTHopDTyFsmLQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v7 04/12] vpci/header: implement guest BAR register handlers Thread-Topic: [PATCH v7 04/12] vpci/header: implement guest BAR register handlers Thread-Index: AQHZneJZUi9Iw7CMVkOOSMh1fJDqRg== Date: Tue, 13 Jun 2023 10:32:27 +0000 Message-ID: <20230613103159.524763-5-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: b20dec47-4d7e-411b-c5e1-08db6bf97e42 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: z8ehHA14NksaMzFSB+W1BNxvLxanrInkJas1ZbmAAo0Djkfnozwz5sf13l0WRFrW44SW2+sD0skYVE8miYF0IISf2AlzMYMmtb8v1Fmpe2Pm6ci0aa/oxXAxcy1YYAtksqouF9nQk5L2ULMulZq00q/UkWQhPnm9ktxGcQmK2t4N9EICLb4fVSL9qQJ8V6QwJw+EWT+TtYRO/lu5iJWZYDnGNerDl8PD4FKGDk2EGr0SC3iU9/D3GoDZmM/9gdWS/UtIlE6rpiVsgcI5RDzSSNK6Qs+URPOdqoJDpToLoljEKTzQzSzolgfmIQVIvkzOwW3DkmQI9Ax7i+06n/WFhASbR4VZpuVLtZUv5FZnO2SXEIl9kvWrw6vcmBiOGoeRueTdWXzb0q6bwdA0Qoa/1M8HhzvuhkHsSSsipOaTXlnqvUPhF/fLchGzLPWmIakyS8K6Akcdx3bzrec0XAYjlbFVbnLhe0EUSFTiy4VkpHWuP9hPOYOQ+HoZujfZ0OABkXRk0seUIfqhgVMwhhgFzVszUq82nKXqePaoQ+Vhdr47XiPko6Y6EEICHd3q7Xdl/mXQI+OzoXHbIV+MRibdCqiv+pKCvmdBP4GoDsdW3ihF0Lbh3vHiOLmqR7NQyIKg 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(6666004)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?F4y8YE62j4UKdOjD9QiXsex?= =?iso-8859-1?q?Wqs2XZF943gGjyMOkbAOWLaI128DIcDHqh46YkQs6jeuAbDdG1vrsiDmX8HL?= =?iso-8859-1?q?jkriuD7LZjypofZirbalqnlP38Jutpqy2JtON3/afJblrJlzt2Azc8nOE3hi?= =?iso-8859-1?q?ErJEaus8rBWA3tKzhQgJNY8/0WlvW1Lzj3g/RzWYN8Xi1dfcFzTH376a4SIP?= =?iso-8859-1?q?QkmG01n4nf3BPqPbIteqU3JodvDm/vlCNIllPKFPPPOORufYi29de6Lr/juF?= =?iso-8859-1?q?cFcTTdK5BMF7WAyWjwsgyTiLvQWp9SXh+KwW34UeOgu5CXOIY5PDN5gTILzP?= =?iso-8859-1?q?DxUcAFJknsOr5Y1bhlRzrfhFwKoDxJGflxgQ11YpD6XI0ay9sIrFW3pDL0pt?= =?iso-8859-1?q?bKzf+sO485elNNV5wqeruNqgaV4RJIgyh510OARxAhRvnOczGfZoYSWd/MMd?= =?iso-8859-1?q?5WIIGcIQbu7V2BXE1ei1/UidIcbXu2q/s31tXOnRMg/+AA96NRhkrPKcTkv6?= =?iso-8859-1?q?ndHpve9ejnVRqAIgCld3jRKsasecr1FJ6L/8UUP4NLBEdg5lz9txgeJyTQp9?= =?iso-8859-1?q?taZsl8ZoFL6qdwVk6nasOHwtbpsVeZ9IugXrUK56/iktIzpU5xYSRxXP22ip?= =?iso-8859-1?q?2xDp/LUxvs1AXAWh3CnC55GSSsG5jt8m8V3pGoJ/ZhHRXBREIyyxdjE3sBjn?= =?iso-8859-1?q?4rzJRNZ0Go0CAi3V7vujvAi41n0MlSeSIVkNdpnR1X1PB3mkuEzLu18Qm5BY?= =?iso-8859-1?q?Ud1EkCvQtltu/O+gaikzt3si4GJU6RzIDCmp4rqgstVE4iFdI5dIAgwh0Jsw?= =?iso-8859-1?q?zFyYlMv7+1323c/PkhwIDbW5WhlSrEaUDpEUYSjl9MB3lF3R3xEC7dI3dbZx?= =?iso-8859-1?q?8DSux2cXIq6ungY3tb49+5eObbJAYV5d5NSBExdsKlqqB7519nz86HPrN5Xq?= =?iso-8859-1?q?pHFlStCg2dQjbSpayMIS/JcqwLjk7UvCeIKnk2hQORgPDuP1Z3Wz9d2Jyshp?= =?iso-8859-1?q?W7DInVVxQrsUf+I0/YxYvzJ9GjW1dhJBIFsueqppLpH6NexExwV04Ll8jDRV?= =?iso-8859-1?q?kuYRGjmI+aBJa0wHAfCOd6gXUBIBPh4Qpl2lTvs91HOyqGLHGDL9khYpxFmv?= =?iso-8859-1?q?gUSlH3A4kz0g4adPvuR+F8K5Er+eRwYetSwg9IDff07hRPqYsx6crMBX98DC?= =?iso-8859-1?q?afzMXSBQ+Iry2fRYFS5I70On1zHJNCpDfJ2paVewZv1JmZVBUk2OiGrfDNSz?= =?iso-8859-1?q?uvJZCBZKx7DJ6/sy2b8+FRNF3mDBLOAeWWfTc/cvXIR6B/Oh3vrUl5NHurf1?= =?iso-8859-1?q?E5fnB8xsATFYFoYRpJw6C1C83l2F+KcIn8LuMyh/6uqGGe7hvy5HPddKkD6G?= =?iso-8859-1?q?bkURniA836tDnThhMU1pAM4nNgi12nMSD+xNqo4CebKf8ADRccPfqaczptK7?= =?iso-8859-1?q?ylCnEcc1L+wJVTsoa/3L1GIT2+WDH501Fh5GHWpmf1MdBzWFTYFCdXxpMLD9?= =?iso-8859-1?q?hUvL8QUGo8G+dWCtIm77qzBNhJMIlf5UC8OJBMlUE1swQGCCoZQ2YAkEM0dC?= =?iso-8859-1?q?wbF7XqHV3LvBlNCydUH0nJZ2I6auhiMDWdXr8Jsfrhy5tIbm11DIoyv8ALXZ?= =?iso-8859-1?q?GMxcU0YwRNZkfihEsaFsZdzhSiu7o6GjkTzIqGA=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: b20dec47-4d7e-411b-c5e1-08db6bf97e42 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:27.7897 (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: hI4cfV7LiUpL7A+QjeL4K/rCOaJOn8GmCYbH/0cSBCvujwvrLnS+oVdkvtKXcIPNoHiDBcHhWnKCu9MVHQU1npa9HRmMH/CrXkILKjTnHi4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: s_sy44IgshwmrV0AxU46G3B8zEiRkNBi X-Proofpoint-ORIG-GUID: s_sy44IgshwmrV0AxU46G3B8zEiRkNBi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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. Memory decoding is initially disabled when used by guests in order to prevent the BAR being placed on top of a RAM region. Signed-off-by: Oleksandr Andrushchenko --- 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 | 159 ++++++++++++++++++++++++++++++-------- xen/include/xen/vpci.h | 3 + 2 files changed, 131 insertions(+), 31 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 23b5223adf..8eebbf968b 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -439,6 +439,71 @@ 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_reg = bar->guest_reg; + + if ( bar->type == VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + bar--; + hi = true; + } + else + { + val &= PCI_BASE_ADDRESS_MEM_MASK; + val |= bar->type == VPCI_BAR_MEM32 ? PCI_BASE_ADDRESS_MEM_TYPE_32 + : PCI_BASE_ADDRESS_MEM_TYPE_64; + val |= bar->prefetchable ? PCI_BASE_ADDRESS_MEM_PREFETCH : 0; + } + + guest_reg &= ~(0xffffffffull << (hi ? 32 : 0)); + guest_reg |= (uint64_t)val << (hi ? 32 : 0); + + guest_reg &= ~(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_reg & (~PAGE_MASK & PCI_BASE_ADDRESS_MEM_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_reg = guest_reg; +} + +static uint32_t cf_check guest_bar_read(const struct pci_dev *pdev, + unsigned int reg, void *data) +{ + const struct vpci_bar *bar = data; + bool hi = false; + + if ( bar->type == VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + bar--; + hi = true; + } + + return bar->guest_reg >> (hi ? 32 : 0); +} + +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) { @@ -499,6 +564,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_write_locked(&pdev->domain->vpci_rwlock)); @@ -540,13 +606,12 @@ 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 ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } + goto fail; continue; } @@ -555,6 +620,17 @@ 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; + +#ifndef CONFIG_X86 + if ( !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + reg, 4, &bars[i]); + if ( rc ) + goto fail; + } +#endif + continue; } if ( (val & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == @@ -566,14 +642,20 @@ 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 ) { bars[i].type = VPCI_BAR_EMPTY; + + if ( !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + reg, 4, &bars[i]); + if ( rc ) + goto fail; + } + continue; } @@ -581,38 +663,53 @@ 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 ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } + goto fail; } ASSERT(!header->rom_reg); - - /* Check expansion ROM. */ - rc = pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size, PCI_BAR_ROM); - if ( rc > 0 && size ) + /* Check expansion ROM: we do not handle ROM for guests. */ + 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); - if ( rc ) - rom->type = VPCI_BAR_EMPTY; + rc = vpci_add_register(pdev->vpci, vpci_hw_read32, rom_write, + rom_reg, 4, rom); + if ( rc ) + rom->type = VPCI_BAR_EMPTY; - header->rom_reg = rom_reg; + header->rom_reg = rom_reg; + } + } + else + { + if ( !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + rom_reg, 4, &header->bars[num_bars]); + if ( rc ) + goto fail; + } } 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); diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 5383ede556..e9170cc8ca 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -70,7 +70,10 @@ struct vpci { struct vpci_header { /* Information about the PCI BARs of this device. */ struct vpci_bar { + /* Physical (host) address. */ uint64_t addr; + /* Guest view of the BAR: address and lower bits. */ + uint64_t guest_reg; uint64_t size; enum { VPCI_BAR_EMPTY, From patchwork Tue Jun 13 10:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278338 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 5CA63C88CBB for ; Tue, 13 Jun 2023 10:33:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548004.855764 (Exim 4.92) (envelope-from ) id 1q91KT-0003As-13; Tue, 13 Jun 2023 10:32:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548004.855764; Tue, 13 Jun 2023 10:32:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KS-00038l-Os; Tue, 13 Jun 2023 10:32:48 +0000 Received: by outflank-mailman (input) for mailman id 548004; Tue, 13 Jun 2023 10:32:48 +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 1q91KR-0001im-Vd for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:47 +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 a31f06d3-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:47 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5Kc019280; Tue, 13 Jun 2023 10:32:36 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:36 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:31 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:31 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a31f06d3-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mh3OJYNOrQqDWGMn0p4qXJhuQldj5G3a7bxCGuGeR61CN8BC+SRruhkxd0YbVIT2xA3RqK9B6mO1utJZ7MoABUyYyIlEI0FylcPgwEo8+BWMQtm1wOjGKg2i/R9/yatlpFSZL86v/Tklk8KsIbNLrlTg/2MKBnwZhqfW4D0qNOEIlgi1URhIO0ECHBs7/aWbjbnQRI6j69ST6zqhz/9vMTrc76GmXc1OH+eUbH5mgBO9xi+UiAAPWrFF1ipZAUAnTkfeqkk+tTiCwqSpQCl+qsC7Sd8ZGfqojM1B444A4OIcOr7VbWw7KxSnxxXVljOSIrOQVouZgVAjqXZdg7Pe+w== 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=0WsGRZX+9SxqmlaHATzo+AnAiyqkWEn+UGBnfXu9ZjA=; b=d8jQDbtfqnLRbwTEg2suZ481FQKEhAKgQ+WHWNbNH9flxjC8BvIlgSFbrqE/Hckkebozckpp5sNWNp71iS9NxQCfMUntg1FrHBivBNv5d9oVqXef8Fdfe+HzCBuzIOnsX5SbEP5p+Zeu4OuQPuRQv9geOhppI1S1OmYVCrhMvQcqiWiV8VoGNNUIfBaSfhcu7lSjUIluUBn977R7qp+nS3ol/NlBpuMQdJhqtIHlVHtZYhmJyBeNIcfRcJ1wWVLAnhUOfiiqisQ9lwcRk+FGRCghI6HkF9FPkCYhEOB6KkiseWpi7FavDQDhbPh6MZINhD0Enyd+icb7BmT8qNHV5w== 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=0WsGRZX+9SxqmlaHATzo+AnAiyqkWEn+UGBnfXu9ZjA=; b=UMpIS4N3rEmoX3rNAATik6X8rdzD2Znajw2oxSBMzfx+KTp880w4FrTF+oeauOvJZdLJ/QgnCZGtNola/8qeo3auKJ4UWjcw3TR5g0Py9EllOBrspEcoBRLqikuJ9ZCz6sghIqe+OnvZyrQzrJGb5skhvh1tOCfKwBybdj5zv0n3HFig7SJ+cOf4yMAktsv7V9zX5E/poYOTWyHD659f8f0r2BDXSkQSW7Fol4xZYDOwOOEBV7CZ10B2MPbhGxLLrCRVtrwVu+aioOKksNi9UzApr+3RKC19+iM2IvFu54PdM+220nen2GqMrrPMyyEtFlFqtoK08x4fKzBJS9K6Sw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v7 05/12] rangeset: add RANGESETF_no_print flag Thread-Topic: [PATCH v7 05/12] rangeset: add RANGESETF_no_print flag Thread-Index: AQHZneJZjMgYCyM9JEyUhR2V92gItA== Date: Tue, 13 Jun 2023 10:32:28 +0000 Message-ID: <20230613103159.524763-6-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: 13944d3c-7e36-4be3-ad8a-08db6bf97e8c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OucIsoztlVcf+B/fz0iNYuMyH/YYFfICS5tSTx7tA6dvF1kwEPZhPwXUEhSic7y4F97TrIrXSIvrfPBz6FDdnYDQ+r4ArE/I5FVKCWlxD0IcqMoO9dtobLRoJAxLW+CpHAUHixq7as0VJcPyO9ILmHUhYIdWtUKkedwsYxgKvqkADl7JUxoS8W/SN21exW0Y6ulAWH2316HcRXpS7N/aUfBnKu7sTNxUka8SUcVQfHHBaxjLbVuPSzhdpuGOdWlSa/ZkUkZc2sdV6VUNeFnmHCCKGyTUSg1GGU7mP/fgLJfgWMUb4uxyoHHS6TNMFAFHf9k6X8ncRG8KEzFzNf5wXlfH3Oa9wIC2XhgyXHhp403OD9Uvi11GK4r+o9Q4Bg9NSOok6zm3UGrdDWEnBZ0w56MlpwzcDCN90+4rv64bKkVg/SM6nGz0xQpIVQeU6WMWHs+jNwLpzbSedLPsdPxPBSMYxK3jWDcdqUhiWakW9P8PlS2kBeeC4fZbyfuoCjDus6tR4zm4BCuv9Y5yOdqL5PMgpFPbCxLSuDZODZOiw6LvSNZTUxM5l30GTHt3mBkd2DHd7G8rbOvW0NlhNP6j+mFAngtXuye1aFwg9n3DcVW1DWyhcJfJGQISbXB4Ww+h 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(6666004)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?vVn0VKHXIIjiw/fsXKbNX6+?= =?iso-8859-1?q?3G1pE8klVFmFehye80d/ybVQ5LHbsHdAdGd3X5AyE4bOw8s6tuGi189uFiwt?= =?iso-8859-1?q?aYMyiHYkRBcRLuVLANSCHhAT75wkGxM20hBVx6yFtORXyyFUAGHB6Nb/2Pmy?= =?iso-8859-1?q?maE3+kSs26Jje1i/s9e9Tp8qIe+Pw4XTbOa7FxXjsV2Vu2z+uq5BUNofulRe?= =?iso-8859-1?q?G/qZy/lJ3UX4Ceq/+KgrFFIzmdudcnpLs7HLTfBUtb2uMinPtG5I2HXhEkwf?= =?iso-8859-1?q?eQUBwzCXBheKyjSh13V/qQ4sN2dfEEozpHoTUVcIxK8dk4ObS2BPcwe06f0b?= =?iso-8859-1?q?rYwjWbCbUxWArEh1vtVBHkG6pUat5JNRizGkGK8QI31A7tQP+9VAeZU6cc7V?= =?iso-8859-1?q?J2KE8R9IzHdx9yQ/lsMy3DW5FvYxJlJ3kYhirif1NDKx9+OCgz1Nbswpfn4Q?= =?iso-8859-1?q?4Z7xouEjezy8oChZkM1UYQ6sMdFQGldgiOe/JOhCbF4OhrWLABt5KQMNqS5M?= =?iso-8859-1?q?eW2JMh8c+0De6fj5oZ5tYlagdvX/LpeVwSEOEAnFDeHphHYNk3oJ9eqH2i8E?= =?iso-8859-1?q?QIL/2cqhFZwNYhvemsnYj7/uMMxbXYv3LaGXLe3hmSKV4jjZAoSq2LDDg2fQ?= =?iso-8859-1?q?FYgBHaaFjyq2+cXSsSYTK6jwBQgbao+LZnUByCgm/Kj0ICgrSSB48uIwveW8?= =?iso-8859-1?q?gsJ3iuEbbRN2AUnIjyOl3+odyB/rTvlFlDz5blqCQPy1YkwbMuBbz3pTFpig?= =?iso-8859-1?q?FXKb+bIAgOyw2fNOve5F4OOOuMgoks95cOwgvIsWwNQpngK7kP/tXAgfgmuT?= =?iso-8859-1?q?B6AcS5ZIq2XKRtSKmzl232ZBN9+nQzHHTOzQXT8m+s5nJxDeoEsfag3fAs8T?= =?iso-8859-1?q?ow2jbea7rjtLb2K1qAJGfwX7nDLPZjOKN4dzMI/rexY4y9sZ3QBMtibWCcA6?= =?iso-8859-1?q?tofa8y/wzh1AjYfpHnJ1XeaI4/yvrj4i/B0UCCdn6fbwyHRE5a1DBrfUWEWx?= =?iso-8859-1?q?fGDr6Zxsh/+URnJ+oLBWnAZdOPIzLnkueyIEomQyTQ9gqph8cxVS6JpWhaXX?= =?iso-8859-1?q?0u3kwp3L33w/lJIQWxGIlwy1rNUD3LXdR8K/UafeZK6/Baq1XJJGi9SokVxw?= =?iso-8859-1?q?HgpLjSZLH3e/t4iCEgDMsSTz4zh/L4nN5Nvgphh+m6EYPd3bQ5DbaqzqNsIe?= =?iso-8859-1?q?d1oSfQCfd947CWdZRXTmqH/OlIIbGEd+YSXnoxpi5TRiHtVt1O9UsVhyTCg9?= =?iso-8859-1?q?pkIvP0LEwTBlGpE/tnDUtNP99d3STgpH393HZXq7jGCuHfVosXx8K79DdgnW?= =?iso-8859-1?q?wAM9/TIo9yd/ylHP8CxC83ejuUMXUaCXoOHZojZ6kxDC2Cum3pzki587YuCy?= =?iso-8859-1?q?2hB92MvtAT7zm04SZ+bUWIZemI9CzeW/RtMdwOzKxfBQJWTLjmFqIvmYp0+E?= =?iso-8859-1?q?4bjEX2dbRR4XCQiUcOmifeLgk5hnPaBoTLxffL4HbhoGhMmw46f635O3W1mY?= =?iso-8859-1?q?Wexb6gq5ipubdKOQW8zh28eAuWl9HeFNvZJ3wihqwIKlUEFVJHs8dona/9dW?= =?iso-8859-1?q?fywGLKqrQqU73AFcZolfBTOpM1Wpos36Ao/wsASPSpILMLD5g5Axq/qYUaus?= =?iso-8859-1?q?ATnMmE+jzG5sBo7tzuaEryi7yk7A4ga4O7ur0uQ=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: 13944d3c-7e36-4be3-ad8a-08db6bf97e8c X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:28.0750 (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: EoEJzxgnM2aQbNxQfHKjHKCEfm47/L1RUmQvJlU6yahpVvXIm842Gmbqqp2FILbUTWKTfoWqJdNaz1ml87JbDnq7FyYS8Rn4aiG9efb/HyU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: GX3CMhzyxVkk6O3d-QmWlAGUMRY5ot46 X-Proofpoint-ORIG-GUID: GX3CMhzyxVkk6O3d-QmWlAGUMRY5ot46 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 a6ef264046..f8b909d016 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 Jun 13 10:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278336 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 E6F71C88CB8 for ; Tue, 13 Jun 2023 10:33:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548006.855782 (Exim 4.92) (envelope-from ) id 1q91KV-0003iS-Rl; Tue, 13 Jun 2023 10:32:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548006.855782; Tue, 13 Jun 2023 10:32:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KV-0003hc-HB; Tue, 13 Jun 2023 10:32:51 +0000 Received: by outflank-mailman (input) for mailman id 548006; Tue, 13 Jun 2023 10:32:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KT-0001il-Km for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:49 +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 a33706d1-09d5-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 12:32:47 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5Ke019280; Tue, 13 Jun 2023 10:32:38 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:37 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:32 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:32 +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: a33706d1-09d5-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i682FnO/2vFekdQsH3XqEGLFo7+c87BEyM7znEYjuBIMEoCFzw7bLDfQJpDL9XASAuYmVXsJnCQ5OI1jV9woXxZJ4CUEPSkZWX8ASCcq0Us1EyHYz4RHPSfC4mJNzcFEHcNsiVz5rgaoovAdIzyMffHye+uGPW8xUzqUx7xGHWFVwt8EdkfWDnncQ8+3oY2tT5xM3QJVvz/tkyYhZlS4p+AP8hprDe4ye7OGd7odyJ9Lg1STNTumJW/X5xmtZgxTKe/6uLztztpZ5U2JBVgf3KpZhVMWPBkJ950rRuZtEbKXOwL4vVOu2nNyv3OAM/ezlvI28dQb5oPAJZquUEr/xQ== 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=8fpDlfsuLlhQ46EF1ZKjojVmfi+Mg0Uj5DZlq5hKl7Q=; b=CVziUQyJa5V5DbfS8EB8w4vSquLqS+7z3YSZX9BZzIvSc2q81SfQSCavXa68GHUyR8Mlg2DTNoo/fwGZHp2X+20Xu31gvBRQGc9Z/bWM59TJ9BfJDjymVeJ0aLwEu3+YvBxT+7EIJFMQt2jX/cNEkGQIApzc9esh5Qb6DY9E3UTFZO8SIiy4lg9wvSTY+hjNB2CzSbBmq5eOfc/+ojmRFVV5V1ycaQObXRCcI1n1OE97rKjnx8xxmAGUrZpGTRYRbCB2bRJ+60aOjpzIabsk5zhbXXaUMF+/9MHRGQdM7WMDWD/7ba2y7FbjbDWbZWhJEwJaghrPAEyM18yb4r69hQ== 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=8fpDlfsuLlhQ46EF1ZKjojVmfi+Mg0Uj5DZlq5hKl7Q=; b=HENW7E5vrl3CxFPEySgDfxfVQORodNhMPjHsgeaF4iQ7CzssAMp7pBFzJdoRtixln6rICsJoDF2oq/WblD24sqQWZlMSczzrqi9v5/Uw5LCFwSrt7dmif97WhZ5u7sWRBShrgbm177D3NaM/nd/Bpd1UUF60lv10TWPFtwHFtLRTBhjauzDNO5WoHHLiKA4JzcOwms/VoKQA3CkRW4NpHXyAIg6ofPQehwG6pYqwvbPFhKqoaxnFQ+IDmO9oL3rXqNUF7pBrQU+sSQfB/O8YihMxMG3JNrY3qTFxRZLCiIgaLWSFmPjR0WJleZI5Z51tlEaWR+RdCFanZub65R79hA== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v7 06/12] vpci/header: handle p2m range sets per BAR Thread-Topic: [PATCH v7 06/12] vpci/header: handle p2m range sets per BAR Thread-Index: AQHZneJa4eA0vie3HEayzZAXloxz2A== Date: Tue, 13 Jun 2023 10:32:28 +0000 Message-ID: <20230613103159.524763-7-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: e3cfede5-87c7-42e5-bc26-08db6bf97edd x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xNaS5P8be9C7m7mg/jCOzLJITnRwmkpjUyaQDXTw0vA02LJfEGHOLd6iN0o4fp0eu6Zpvm98NkazNj8ayT8Ej7l5sO1ZuWUfhiHpUl+1EyIKYsVYn4+WS27EffRcHuJc+hrPbW50XEIeLyHxx8ebF9rtmgheqXRoDT0iqSMc4qBUWUlm789wDyN0S4g6/NDAdDDv0TVFQfVkc77WcddDySgq9QnpeRoHsXC4RqyMccvZC9gU6KfcClx/S55JSxeb6Vy/kWgB+1Tn9ESz2DUXlPvVOTpQUIfi9WdpsTWMgT9H24Pxy3OTJBDby9gl/E61cTf9Mpyz/W938/Tu3eVPkNNHcGwwLIRrtLMskSmzmTfXrIuAknp/pWYgbmGmgMeT/sXP41TFeePGUyF9RcphRv2dnqaK0dFr0uf6WZ3wdtmnxOXsyUYf49puwAJuLDicKgX6O14I/PfYK/wMrQMCIXseMMeW7vf7q+Zb1qnpx3+s1KUcctTbGDDYSKnU+FZ7P/wKKNehaxwpmcdmZ1Dc+8lWSgWajTm5yYNe64lUxGgwKXUm815YyZPYZnMS88yqpyh3hFSCDqEZheq0cebtWLTK4Ntk3NqPSDCQZ7K2Bkihw0NmqUGIqnmu1rvbgEsZ 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(30864003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(6666004)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?FeHgA9GOlWEF2kYD8c9JZF8?= =?iso-8859-1?q?O7gJwdNUSg71a/V+n5a4zaZuw3NUcNUVKNftv5vAMXYS/MvnScfFgZx8Iaqr?= =?iso-8859-1?q?TBiNmdMl1/M1HlCvA6NgGiFp4M1Mvz3n3OXjOATXiwS5Ys+ZCR1U8zuUX+Q7?= =?iso-8859-1?q?kGm80S8Q3ZeC8eQpz+J205II/TI4hq1FR1mhJNAY/GQxLCOlFVpsSV+xP8eE?= =?iso-8859-1?q?If5UoZaAJVQZUO3oMkDwjXh9T2OCshPs7C0RDibXf9vwC/+ILjH/PzNEhown?= =?iso-8859-1?q?44AsDKAywK3lkT71i75k671fs2K9wArfD+dHKZJoDp/nGeQMVw5OsmXER9Uc?= =?iso-8859-1?q?E/Trcw4/6j8phHb3vSMySc3K07PbdD02dhZ0vJK+L8GAC9rOb/Lxg7JPlBE8?= =?iso-8859-1?q?tJRqie2OcblK2rpaUPY6MVNOvRCHGrDpGw+21vPAgItln18l8jkn8AurSkdT?= =?iso-8859-1?q?o8M/alEmZJiOfGq0ModikMbbhAca760gEsQTuXlXV36RG56f1l7xNzhdZVCr?= =?iso-8859-1?q?FrL0OJ2Il4HpAFSTYPhg7FoBwaiQ0TB2jLDMGZGX0msNjvSrO88Mf97LIHLj?= =?iso-8859-1?q?Y/rDrbPdnmrBx1Z3aKpopUtt9A/OgobwuFTtTeOmnsRcP/+dvRdelIks8Fjz?= =?iso-8859-1?q?MkKXrt7+QQEkFBl7KbVTYZ+j/z5qjIihfMfivvFWNyNLskuiBlCosYWToXc/?= =?iso-8859-1?q?Z5uw3R342vtoP4l/HRx3rO0crLZJUUBrcQKgwOKaMODRnoVoODvdw2QEQhyF?= =?iso-8859-1?q?ff1fvzLEL3M4XGRwbHp97+gp5gV95Te/XsfHjWaiQrsRXi/+Y2Re1Ipjo2i+?= =?iso-8859-1?q?hINAcYw1TuOWDJxaRXsiNwvIf+ebWps4YGtCRZP7L2J0r9Cf9SKi0PFXiyU7?= =?iso-8859-1?q?vZOkFQ2Arq96KHciUV4xQ1dmRWzWBxS80hnzK0vFm5aHxsy6flB89vqGWz/T?= =?iso-8859-1?q?C+xGKDAo+PLY0nWdN4gIDK1I8PRgZxkm8v4Al6zwqjDn8VJskhZsPJjzCvMt?= =?iso-8859-1?q?RrtSokto8pNAlSXLPW0LQ4a/TXQOcvClS24Nt/saaNivTfCs3kH5igpdipib?= =?iso-8859-1?q?8IaHQKXj8U4H4ZYwnMmci4YNmrjofx7kTuYPKI42O6ZBW3IJjaaAxWBWMgdH?= =?iso-8859-1?q?dLllb/bJ/IpPzyfCRc7qpk2D/gAnpJd46fyQ2YNUHsBlbaOsXgLm0KAG6tT8?= =?iso-8859-1?q?kBEr1ehJ41wZETETYREZja4+qOMwGiTJCvpmujWyOOy/Y/31N3Cq2JNgzjoH?= =?iso-8859-1?q?uGxAXGXxSHcsz3WMEhkzf2wdjSKPVSle4tEfTEyjMLKzGVsh0v4XckAfMIqe?= =?iso-8859-1?q?TdeyOSpQY5pqeb3j0/ocsFA2i3Yf2uMGC+OwQrxQB2LFms1KzkAYztSHsEct?= =?iso-8859-1?q?QY63uIa5uNVOAfUFzDflZqq21JpgfIoivOsfPYnTZ17AoU1FjL388DfztdcT?= =?iso-8859-1?q?t5EovtqFeDDLNMsyCK+HPo3cjAosmmzbQjZxLyQosaJ+LYvNtN2D7yiUmtS7?= =?iso-8859-1?q?jnvVDlgE1YRZiOCWMWwi4ckT3NmnajXiMXFoYV7ybgTlYArFSXwcMF/FoMxu?= =?iso-8859-1?q?PGrH+mu528JtrlhIMDuYbT5oOBnVqjA1NWW4+QxiHO5gThAMkh7n15tnbgOW?= =?iso-8859-1?q?ZxozCbfXnaVD/9nWwJ1WRzACroZUGKI9+nLVBRg=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: e3cfede5-87c7-42e5-bc26-08db6bf97edd X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:28.4558 (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: XsvG42tA7LQvOIzfliyyp11pXyvMgLeAvLkKvNclUWNmdqFsJRat6NphIucuHL+y4cQHH+T8wekFpeTNQOD9EOKVHxmUTWtCLgm4gc+Axa4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: Rm6fJ6vrkbwmHxpQZIsvhvklPZFcNp2N X-Proofpoint-ORIG-GUID: Rm6fJ6vrkbwmHxpQZIsvhvklPZFcNp2N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 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 | 238 +++++++++++++++++++++++++++----------- xen/drivers/vpci/vpci.c | 5 + xen/include/xen/vpci.h | 3 +- 3 files changed, 180 insertions(+), 66 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 8eebbf968b..8e722857d6 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -141,63 +141,102 @@ 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; + + if ( !pdev ) + return false; + + read_lock(&v->domain->vpci_rwlock); + + if ( v->vpci.map_pending ) { 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); - - if ( rc == -ERESTART ) - return true; - - read_lock(&v->domain->vpci_rwlock); - 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); - read_unlock(&v->domain->vpci_rwlock); - - 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_remove_device(v->vpci.pdev); + struct vpci_header *header = &pdev->vpci->header; + unsigned int i; + + for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) + { + 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->vpci_rwlock); + return true; + } + + spin_lock(&pdev->vpci->lock); + /* Disable memory decoding unconditionally on failure. */ + modify_decoding(pdev, rc ? v->vpci.cmd & ~PCI_COMMAND_MEMORY : + v->vpci.cmd, !rc && v->vpci.rom_only); + spin_unlock(&pdev->vpci->lock); + + 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 needs to be killed in + * order to avoid leaking stale p2m mappings on failure. + */ + v->vpci.map_pending = false; + read_unlock(&v->domain->vpci_rwlock); + + if ( is_hardware_domain(v->domain) ) + vpci_remove_device(pdev); + else + domain_crash(v->domain); + + return false; + } + } + + v->vpci.map_pending = false; } + read_unlock(&v->domain->vpci_rwlock); + 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_write_locked(&d->vpci_rwlock)); - 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. - */ - write_unlock(&d->vpci_rwlock); - process_pending_softirqs(); - write_lock(&d->vpci_rwlock); - } + struct vpci_bar *bar = &header->bars[i]; + + if ( rangeset_is_empty(bar->mem) ) + continue; - rangeset_destroy(mem); + 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->vpci_rwlock); + process_pending_softirqs(); + write_lock(&d->vpci_rwlock); + } + } if ( !rc ) modify_decoding(pdev, cmd, false); @@ -205,10 +244,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->vpci_rwlock)); + /* * 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 @@ -216,7 +257,7 @@ 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.map_pending = true; curr->vpci.cmd = cmd; curr->vpci.rom_only = rom_only; /* @@ -231,30 +272,31 @@ 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 vpci_msix *msix = pdev->vpci->msix; - unsigned int i; + unsigned int i, j; int rc; - - if ( !mem ) - return -ENOMEM; + bool map_pending; /* - * 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 BARs 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)) || @@ -270,14 +312,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 *bar = &header->bars[j]; + + if ( rangeset_is_empty(bar->mem) ) + continue; + + rc = rangeset_remove_range(bar->mem, start, end); + if ( rc ) + { + printk(XENLOG_G_WARNING + "Failed to remove overlapping range [%lx, %lx]: %d\n", + start, end, rc); + return rc; + } + } } /* Remove any MSIX regions if present. */ @@ -287,14 +346,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 ) + { + printk(XENLOG_G_WARNING + "Failed to remove MSIX table [%lx, %lx]: %d\n", + start, end, rc); + return rc; + } } } @@ -327,7 +393,8 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) 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 ( !bar->enabled || + !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 @@ -336,12 +403,11 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) (rom_only && tmp == pdev && bar->type == VPCI_BAR_ROM) ) continue; - rc = rangeset_remove_range(mem, start, end); + rc = rangeset_remove_range(bar->mem, start, end); if ( rc ) { printk(XENLOG_G_WARNING "Failed to remove [%lx, %lx]: %d\n", start, end, rc); - rangeset_destroy(mem); pcidevs_unlock(); return rc; } @@ -362,10 +428,23 @@ 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); + /* Find out how many memory ranges has left after MSI and overlaps. */ + map_pending = false; + for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) + if ( !rangeset_is_empty(header->bars[i].mem) ) + { + map_pending = true; + break; + } + + /* If there's no mapping work write the command register now. */ + if ( !map_pending ) + pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); + else + defer_map(dev->domain, dev, cmd, rom_only); return 0; } @@ -556,6 +635,19 @@ static void cf_check rom_write( rom->addr = val & PCI_ROM_ADDRESS_MASK; } +static int bar_add_rangeset(struct pci_dev *pdev, struct vpci_bar *bar, 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; @@ -639,6 +731,13 @@ 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 ) + { + bars[i].type = VPCI_BAR_EMPTY; + return rc; + } + rc = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size, (i == num_bars - 1) ? PCI_BAR_LAST : 0); if ( rc < 0 ) @@ -690,6 +789,15 @@ 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 ) + { + rom->type = VPCI_BAR_EMPTY; + return rc; + } + } header->rom_reg = rom_reg; } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 4182c65eaa..b542ddaf7b 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -39,6 +39,7 @@ extern vpci_register_init_t *const __end_vpci_array[]; void vpci_remove_device(struct pci_dev *pdev) { struct vpci *vpci; + unsigned int i; if ( !has_vpci(pdev->domain) ) return; @@ -73,6 +74,10 @@ void vpci_remove_device(struct pci_dev *pdev) if ( pdev->vpci->msix->table[i] ) iounmap(pdev->vpci->msix->table[i]); } + + for ( i = 0; i < ARRAY_SIZE(vpci->header.bars); i++ ) + rangeset_destroy(vpci->header.bars[i].mem); + xfree(vpci->msix); xfree(vpci->msi); xfree(vpci); diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index e9170cc8ca..1e42a59c1d 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -75,6 +75,7 @@ struct vpci { /* Guest view of the BAR: address and lower bits. */ uint64_t guest_reg; uint64_t size; + struct rangeset *mem; enum { VPCI_BAR_EMPTY, VPCI_BAR_IO, @@ -162,9 +163,9 @@ 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 map_pending : 1; bool rom_only : 1; }; From patchwork Tue Jun 13 10:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278331 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 384C3C7EE2E for ; Tue, 13 Jun 2023 10:33:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547997.855712 (Exim 4.92) (envelope-from ) id 1q91KM-0001mf-NZ; Tue, 13 Jun 2023 10:32:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547997.855712; Tue, 13 Jun 2023 10:32:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KM-0001mW-Iv; Tue, 13 Jun 2023 10:32:42 +0000 Received: by outflank-mailman (input) for mailman id 547997; Tue, 13 Jun 2023 10:32:41 +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 1q91KK-0001im-Tp for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:41 +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 9e6e6cd6-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:39 +0200 (CEST) Received: from pps.filterd (m0174683.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 35DAO5Kd019280; Tue, 13 Jun 2023 10:32:37 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2106.outbound.protection.outlook.com [104.47.18.106]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r5yahmgn9-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:37 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DU0PR03MB9706.eurprd03.prod.outlook.com (2603:10a6:10:44e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 13 Jun 2023 10:32:32 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:32 +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: 9e6e6cd6-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K7gK6EtpgRxLd4ra5bZalEvFz+1OiQoKhMsz1xt59QtINXG5B/56icHyCzU51QgmAzLKspnqkXNFO86AA8tC/aZFd53EhYUD0zxmWCEhmmrcmDpoaKDwSBqW6NVt745VG9rya1dvg+VSDEn9z3toRmHiO/4Gr6uutpqQcMVJRWhakyj2FGi2xuZl40vWZKOql5OLYWrt/MPjSBIQTrGHbh5xxgVrDNkv/IgwW/85VUK/yQVqwgTH1ZjQTLJDspDC0wFIrwvRFCnxukoLa4oKnYLC4kO9xJXkaXR2gtuHl1C/PKREsuZhnDCq0UypB6RKlw7/9Kgb5hK6wDswDRrylA== 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=CNyh7b3z00o9nb1EZGxIuBRmA/qLfWrnIQKWvheJ33w=; b=Ujx1eTytwFJoH7aMBEAv9ur4TUhUHlygmjX1bcqps7qDGR+Oi+foSBaLGqpyxImfxs+QGGgvYUPWpzm7Pqs6pW44v6Y9UHx+jyUEJ2towLOXnj2lvll891lShUOfsOr9cXk85paGb9hAFF7LuncQHIhupHrJhcgxiUI80dSH4KZP5FALH2iwAnvC0ohR2uSbsRnRd4p30gIlFbTF4XU063p+1ZN/RJqRXTeprRAFhVVAOQV6fdCXBkyvd20eFD4iS1gZorFeIzaStQZJivqP2IMVyyP+Wdw7qooX+FttcYwFnpHpcpSSNdgPvHTCOfN6xjO55JMYA298Xi5KYplDgw== 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=CNyh7b3z00o9nb1EZGxIuBRmA/qLfWrnIQKWvheJ33w=; b=kiBq2YIPOA3t9OnlWZXMNQiajs4UAR+UpQkncmIw3ewQyp9ILYwsAWBmoBvSdADJ2z5pY3XncWH6G6zw6TpK4xVdkfgnUD0iOKfwxmtre6lApPDRNBvYvskKMFHfkBLjbCB5+4AZeVXBRfVMLBHVQCf4OP72GlAIUgrCWj7OKo6lDBWZ4AioTeNErOUYitV60dOXX9nKSCTmUfVP7wQx1x/TyfpCviXKPG3nzEO1ZZPE6bGCI0ie64qWUntYaL1LemqXenNwO6iRgJCISpvwTSKi3tK+LpM50nRXQRPxHtMIKfAxaPXTQcDSxltIPEDebl4mSK3icE0A2otffYqMFg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v7 07/12] vpci/header: program p2m with guest BAR view Thread-Topic: [PATCH v7 07/12] vpci/header: program p2m with guest BAR view Thread-Index: AQHZneJan/HM4MlRFEiYjDr8BhS2ig== Date: Tue, 13 Jun 2023 10:32:28 +0000 Message-ID: <20230613103159.524763-8-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DU0PR03MB9706:EE_ x-ms-office365-filtering-correlation-id: 90024425-b506-425a-cabb-08db6bf97f2e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uvx9GSZZau2vgf24paxZHo59i6GQzkHP4nPJGGLZp6oC5+isR+8MWv9GicryXxl9QBjrF/eYBR/U+CIPl2cj04p3ocZubZIjUzUBp6WX9Xs6imcoaZSFkzOYwknkMa7gBUTprgT2Cq5UZor17DBNigmMR8Ko8Ra+lI9tMAEwApcVdf3Hv8vkAOOqszYPQHIqp+kCnfgdCjVegBVgdtDhCl2cghoCgALXLAXiSfQ5KQRqju/sVxX+t6phMun2ra+PxBWO6E3jUtDFSFenyRGARskF9usxJ0MOVTPlTXDRmDjdQpHsMDIdEWasyoQb3fiNuCCp3c+RYc/SyT7J0osgi/5YJEESCo1+g6BevYabNLEQCzTedmPkoHcSJEmnRHcAAV6eUBtMzZK8BhgLsWhmhxYoFmOgWG0pGgXI2bQC75mzwQ3M91tDEroWGTEsXHX8PGkXikciRLyyuH6wIqSXByeTCuMU/aEm4d3ThoXsSA1wz0/BpOrGMONmGV7uOj9Jefw7OcolBAaHKTaloGDCAFnNsv+00rAK5yzisDXwVzh9XWQGYcWPZcfX4r39eIY9GNRc0xRcGYgQ6EYF68gvjqDT1Q+N0maI6b5sOM5aNsn/CJPK3exM5opZT1/phz5c 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:(13230028)(4636009)(39860400002)(396003)(376002)(136003)(346002)(366004)(451199021)(91956017)(64756008)(76116006)(66556008)(66446008)(4326008)(6916009)(66476007)(71200400001)(5660300002)(66946007)(41300700001)(8936002)(8676002)(316002)(36756003)(54906003)(83380400001)(478600001)(2906002)(6486002)(38100700002)(6666004)(186003)(6506007)(26005)(1076003)(6512007)(86362001)(55236004)(38070700005)(2616005)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?3feZgc9oqmxnSad3oHdp5jZ?= =?iso-8859-1?q?+tBpdYqzkAbckadCMpUfaLB3tn0jPsmINqsGJDOmERe3GMyFoI8ZSXCE8S4l?= =?iso-8859-1?q?COggvwGpLNbUST4nEQP+Tl7CoFEDsQLiAYI8EJeJI2myspF0vtOBh9YVS29c?= =?iso-8859-1?q?48jKU3MUPofoLsW6XtyMMUWXWTrqo8PoiRgGR3Liyz7kOoZZRNzJYFWHxhUC?= =?iso-8859-1?q?8ojm8XqltYc1eL4ytzRwE4SfVMBWAHra6XwW8YYSJmh+XhWdH4iVLDPi7hQ4?= =?iso-8859-1?q?0jgjFAjSAiGmj3a+Z9m5wYEWb7mBVfalbVi3q9U95InVKDaNLVagb1Z4upjR?= =?iso-8859-1?q?jRbHJMnVWgjCOxRduv5yFtHzToiuPJjDO9bFb/99ofWDtRTfyah5jt/MzQ9M?= =?iso-8859-1?q?il83OEm/NCnRCGdI7vMR6E45J5SP0JHSmm9qXnqNgdmKYhmNKxQH8MBX8fiZ?= =?iso-8859-1?q?D/NFYIaBc3Dj+z1+Aw1wvESJGdWWXtnUx/vi/LG1L6bqMzaAqvve3euwnMpF?= =?iso-8859-1?q?7aj/zXGJgGqH18x84Zu1fmbem5M8ehskOPEaLsooYEc5lHyBlIL3TS9tZ/X3?= =?iso-8859-1?q?cmwkhUUtJ4TQOdL4Y6CiV2X08MWaGvpMFJIhfJl/I3gAuNLi1WSM0iCBBWdv?= =?iso-8859-1?q?9U6L7mLymh8pGGmen3qXaTbBf+nAWqIcFx/7+84/NkyiYLC3t4KuKDhchq2L?= =?iso-8859-1?q?72mJVUGUImObr32NB3jPrLwdvp00TTt7DeM5fT+EBHc8one5Lm3oVq8RsGvj?= =?iso-8859-1?q?kI1o2eyOfAPB+89Bm/nRPJmecPYep7ncsa7C5lgEpGXpj9gEJPjRur6i9a7O?= =?iso-8859-1?q?H+gqczMLHTWYW+iH3jq++6IA3BJIRPe9RaSatRKi7aPj9Eq2FgGz6xe98WWM?= =?iso-8859-1?q?jxXokMyJbSX0aXjHrMAEFTK0GvEQock1HZu4rOQR2bcOby96D1fUvxpBe7sq?= =?iso-8859-1?q?xXupWADYNKp6p8GgWpq44s2Ba3QRZ/0P4rqjJzrwfkQ8+wlRXJD+n7WSmyKK?= =?iso-8859-1?q?A5h4VbDmNwH63fZ3z2BaYbbETlBhMjWZN/dmwYz4G8a69FcRv1jhoi53pFuB?= =?iso-8859-1?q?tMH8RIBLkxqnRD68CiR+2Xx/wtI77Rdk20oUgjrAtnEhBg7VKkFNq5uL6lCB?= =?iso-8859-1?q?qL2JeWlEFFVSgxZhsQ+xCZdjEDD+KVjYPDa00BlZD+6kcU9dKLftlJ7vekDu?= =?iso-8859-1?q?ZTXUaRbg5CmyLAGSy8tcFqlxkWzesAjwYCxk5l94HdrGSOBCqHUT50v+DURl?= =?iso-8859-1?q?N16Uu/9AQWQXAZaGMvlJHY7sXSgaMXUbPs9Fi4mmgVpe0lSwITrnz1XecXvJ?= =?iso-8859-1?q?/8nOTAoqBM+bUY71EjWPTujMpCYXKHlq+m+kbaygs/dX8RuCJMXypC/pwYl9?= =?iso-8859-1?q?M7la11Dpsoo7RkyTJ49mpHAFu8iYCL0RSvW+psVl5U+r9CkV62jqQouPO6J9?= =?iso-8859-1?q?YnrZgp9w2KqeXR6FEtBcwuJts9Vevlo8ZMhYyu20oVm9kzT3yfw6nfgNpsWu?= =?iso-8859-1?q?iE0PUfBegF3uCH3J0lBUyXCZrkL19KexSP6QmHefWQrtZLVUn2lgt6eK1ugM?= =?iso-8859-1?q?y47ZdiDYvdnaBEly5IjYedXlDbVQ3Bdnf1lNsccav9j5NO4AY6OhnB4NiA3T?= =?iso-8859-1?q?AH6Fz2knbzWIgy2R1W4+7JQW8bnjOgvGicr2XPg=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: 90024425-b506-425a-cabb-08db6bf97f2e X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:28.7428 (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: E6Ax67teC/MtbBieUF9pH4vkD1EiGib29MvIzFW4ufY49Lm9zOfOcJIReZwCBuM0tWX5xWLKmYVr3g8apky/b3N935lhZ7L5Po3qEd4DULo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR03MB9706 X-Proofpoint-GUID: kKPw5AViXivcgLUhkDPKgHMjM4MBYCo7 X-Proofpoint-ORIG-GUID: kKPw5AViXivcgLUhkDPKgHMjM4MBYCo7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 as set up by the PCI bus driver in the hardware domain. This way hardware domain sees physical BAR values and guest sees emulated ones. Signed-off-by: Oleksandr Andrushchenko --- 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 | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 8e722857d6..0524fbd220 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -30,6 +30,7 @@ struct map_data { struct domain *d; + const struct vpci_bar *bar; bool map; }; @@ -41,8 +42,21 @@ 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_reg)); + /* Physical start address of the BAR. */ + mfn_t start_mfn = _mfn(PFN_DOWN(map->bar->addr)); unsigned long size = e - s + 1; + /* + * 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_gfn = gfn_add(start_gfn, s - mfn_x(start_mfn)); + /* * ARM TODOs: * - On ARM whether the memory is prefetchable or not should be passed @@ -52,8 +66,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, start_gfn, size, _mfn(s)) + : unmap_mmio_regions(map->d, start_gfn, size, _mfn(s)); if ( rc == 0 ) { *c += size; @@ -62,8 +76,8 @@ 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] for %pd: %d\n", + map->map ? "" : "un", s, e, map->d, rc); break; } ASSERT(rc < size); @@ -165,6 +179,7 @@ bool vpci_process_pending(struct vcpu *v) if ( rangeset_is_empty(bar->mem) ) continue; + data.bar = bar; rc = rangeset_consume_ranges(bar->mem, map_range, &data); if ( rc == -ERESTART ) @@ -224,6 +239,7 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, if ( rangeset_is_empty(bar->mem) ) continue; + data.bar = bar; while ( (rc = rangeset_consume_ranges(bar->mem, map_range, &data)) == -ERESTART ) { From patchwork Tue Jun 13 10:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278333 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 8B183C88CB7 for ; Tue, 13 Jun 2023 10:33:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.547999.855725 (Exim 4.92) (envelope-from ) id 1q91KN-00022H-Cu; Tue, 13 Jun 2023 10:32:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 547999.855725; Tue, 13 Jun 2023 10:32:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KN-00021R-64; Tue, 13 Jun 2023 10:32:43 +0000 Received: by outflank-mailman (input) for mailman id 547999; Tue, 13 Jun 2023 10:32:41 +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 1q91KL-0001im-C6 for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:41 +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 9ddb8d52-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:38 +0200 (CEST) Received: from pps.filterd (m0174681.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35D7wk88024943; Tue, 13 Jun 2023 10:32:36 GMT Received: from eur03-dba-obe.outbound.protection.outlook.com (mail-dbaeur03lp2169.outbound.protection.outlook.com [104.47.51.169]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3r6b6r9sqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:36 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB10054.eurprd03.prod.outlook.com (2603:10a6:20b:63b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Tue, 13 Jun 2023 10:32:33 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:33 +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: 9ddb8d52-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AwDlxCRDkbFSP9SUWUqjjIoKMiO03Mc1DM4ILm0RMIzoVpI3040pNdH8SisCjfs+h4AV5It0S9R6hNqgO0BpBQariugwzWGjf2okwukXlojiv6lJ/Fem1NX3D8JZBVoLhmhrUr4GC4zkGi+xtT+Cjlmor0cqYOqwqNtHVj1bT00gdMyA5e9/XkP4MMsDRUqC1Y/7jKhvaPjjbKm8JJRVEs/QFdgdkp6+6eRLd5gJt6tLvbU4AjGCF0q4WtWzqlGMqVDhGT2JdNFgCclZ6wA3kfds8bHbi9gt7PRofntz+9VBh+jn6xNnu02zrVXDmagvCTwTqFjPcqVfPlxWxrGxTw== 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=UY3Tc3JYjXd83nRZfS2pIeBc/5nTAWhkdSGDbSn1R9M=; b=SpDEGTznp0M0SivWEblwb2kXWGHSt5uSCs3xTGC2k/IQQOahNzehN5bpOEgKl2+dolkK31GMIgFMFyUbC0FpQz3nsdzVorMAJOOxQeSr6XT3q0w6Xi49zJas9Sfdc3iqzJyUX8y6EO9znRAru/SlHKbc51EwoJPOE5cOGzUoiQwnVDLZ6AhoYrLufWDOilgriR2HfzU9gXa0RlgX9YavV+UZefyLpvpa1PG3m0Y7YIKyLD/scoPKh3ZLZTKXnYt9DHsNoFvTGTYCndypL+Ieigsseh8PRE4wJwFtQE/7ND91Wacry6K4MSUuDg9EdCnrncN2gnSuJCAG7R3lAdQbFQ== 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=UY3Tc3JYjXd83nRZfS2pIeBc/5nTAWhkdSGDbSn1R9M=; b=hUBU6xpxSBK98oYzNp7iJy8eVoyWDtcl5cppb54dAc/goZdwd4tqPBaxPh1KPqfp0hWvIHbcwqa20Oq7D1Hgn8jUNBWcPRN9cxxddFCl59ebWT2i7k2CJdsnAStqPGa8iLDq1m9A/UkF6xW29czB3mG9/n/HGie8z3GUPmofY0XdHrTSdYpBbscwPeLwvKo8JzOhhBupMWmdv3Xqf25271lPeXWsG4YvhiBNPYCX6YseEi85OY3PwBpNHLv/vc2ZIKz8W7G5tzMLJ6cS34BTRIBoNIoNWfkmWwCJI0EiDjgspc3tWN4Bz1C/5OkCHQ45xX14xPHx/ic5OIH82vYM3A== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v7 08/12] vpci/header: emulate PCI_COMMAND register for guests Thread-Topic: [PATCH v7 08/12] vpci/header: emulate PCI_COMMAND register for guests Thread-Index: AQHZneJadSk5dKCDKUGsmZXzTPgN0A== Date: Tue, 13 Jun 2023 10:32:28 +0000 Message-ID: <20230613103159.524763-9-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB10054:EE_ x-ms-office365-filtering-correlation-id: 9a50147d-7fb5-419f-14b4-08db6bf97f7b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7QAaEz9qHw4tbXo3eMCbbBCugU5zi1ITszDvARtwnBwMfOjFjAW9/p+BIEpJrnKcB4n3+gaNyhXEXcNUG9O+BFX18uxFGqJKyLTBJSb5szFE9L1mCKv8ijL1j3SU9pPekjHlOLe3XqLkFI/NNmJsuIgMb07PcdDiB+7E3iepJ7komfLRZOMY9EcQ9orXFmxeO/TCaDc21WVfw7Kx1VQByFndSUSbZtuKvNQePsX9T5fWELmwcEmubHyojx586Mb5sE1h1eD1sEpRgNavl3zuo2ZefBO3nlOTyJ+JJu874z6CGK3dGVl+yMYiMwfAXWQLv3mmDMZ4d+hG0MNhQNLmQGwSnZqb7g3fYopfb98n7+v+yvXGcRJfwlQtBO2wPaB63Jn37ZN8vCQTO0HNLoJtw2mUj6RtjxfEc314KWMgV7XPMdrJljDFtKooYTtbDzRGuh4iN218tmYPzfTqpZzAFYRnT+NnLeh7/z1fDr+XFk5AILo9qoZ3FuOVFt6H6BzmLIyFvZeQPknCHmefjbANbju4L+W2aQyjggY4RNxKjrSK542BmJe/6UMIX+rMGsxQz4yu7PweFWrHR4ee9sW7e1b06KA7eC3yq9XNFNIWOBy/m3H0mQGWr2Tktpg23yrLDGtOnlA8c/ntIm4GQj/QSg== 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:(13230028)(4636009)(366004)(136003)(39860400002)(346002)(396003)(376002)(451199021)(2616005)(83380400001)(86362001)(36756003)(122000001)(38070700005)(38100700002)(478600001)(54906003)(71200400001)(4326008)(6666004)(6486002)(966005)(8936002)(8676002)(2906002)(5660300002)(64756008)(66946007)(91956017)(66446008)(66476007)(66556008)(76116006)(41300700001)(6916009)(316002)(55236004)(186003)(66899021)(6512007)(26005)(1076003)(6506007);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?5okfJ1FcEUByPr/7ctEFxv/?= =?iso-8859-1?q?bxLvaXvXIp1gx2VlNHg4mskTTjSxj4TDM1+RvIKnEAhUpob7jj4GRrClkWI3?= =?iso-8859-1?q?8/bfJS0wF9DiYRTXR5bO7weCv7YsEzpzIdnuwPhTs5iGqR1O+ZJ9923fpJRC?= =?iso-8859-1?q?ODGVweMPQ5dLPQ9ltRB56OXy4xvZdptu0JtyGenWrZwHEgRIyTOETN5d45gz?= =?iso-8859-1?q?ArhPy+sfAs3ydn/hfR0hY/lflxQuGI9xbCjjf0HFhFbCccErVijeSrDVVbtC?= =?iso-8859-1?q?BQbhQyvQ9fgtPlBzul3Opxdqdt+HoIkzYQw7ZiOotuhXj52zVRKMYQuq0l10?= =?iso-8859-1?q?24/+GeOjoFnttXVWpNzLCKM0b+gY11a5NMdT/4B7Cr9yPIJhl4Ril7JNcKam?= =?iso-8859-1?q?11L6vv3kUndGftJKA8RqqQ07SeLC/f7dA1UuQ/nj2HiB+KyhD8UxipGKU5Ek?= =?iso-8859-1?q?6mfIQ6+Ckyy67sq9iDDbYyhnNYlXjLb1QTMgJqKi+pgvYxFKcSZ34BBG4F3U?= =?iso-8859-1?q?st7V19osvLqOMmQJoVb3T0Ca2oNPqCYZWI+TGNNzXVKP/dulSWKdm4YrvxzU?= =?iso-8859-1?q?43JwMW8wcXsNXXquEf8pGeyS5nUgBU6zhDOvZc8c7yU7q/qac1b4A3JxpHLx?= =?iso-8859-1?q?fUipMAnSstk/B7gWpeu5oS0SSdg5bo4eIittqILm5ILrRDVuuR6wfFJL+/DA?= =?iso-8859-1?q?Olz38klN09sRjuUY4rXzg+5+ilHO2iK1N/YEMlEKjMvzqA21ynQUlezW6EB/?= =?iso-8859-1?q?y9o5Ityn83/VasfWsm1tB4npxNw9Ur58VeZN2mhLBKhIyyR/14uNF0Vr/wv0?= =?iso-8859-1?q?Eszt/9Ml+HJc1TioaPHFww/YDTUHCJ/0i8UwPthzUBsnmAK5BI43JMCx0pnB?= =?iso-8859-1?q?BjaY9OGmIz0bAW5+mhOJGwhNg9D0pDDszixXVFS4G8dxpAFlY8A7qg+ApYt4?= =?iso-8859-1?q?G53qfh0iG8Obz5DtWmGE3kM15GnKFY5Mw1nUeWy86/aWXdXzVWUQg/8MHfcg?= =?iso-8859-1?q?UMMnnucl7ZuREZ1Azeat3VrhQSsNz7z6DwgVurwcACUqio/AMiZW/LQxFR2b?= =?iso-8859-1?q?JNdckr6moSmg52/+6yXUw6EAxRNgVVlRe7rbQfxPN4ID8+3e130kzLQtWRxy?= =?iso-8859-1?q?ShumTqwdlXv4Fnj8eEVFa7Ytte+MKj/dKsPbZPXH2Yfb9Ht6lH1CKcU3GaG1?= =?iso-8859-1?q?BXAWTPDaQwc//h26AgEyCJX4MjtUDfW1UAmihHSEPnNCe/JrQDxHYmm/Pwad?= =?iso-8859-1?q?vRsJXVKnWRUo7J44vTaLXvXeMm/dKX2CGJB0JcvTvdmjFL/E5yUCOUsJLM2F?= =?iso-8859-1?q?dIVZxNCy8c78RzlU23eJ8m6NtTGBPmL3j83y/LGBJsQUF/4ZYhxbrGnNgGQo?= =?iso-8859-1?q?wGFivgAtCXxs8mvLXG7kmjTDX3R4kP0LPE73L/2kxWiuUqq1i8aVLBG30e5+?= =?iso-8859-1?q?U8QsOZ6vewRO8eSkx3FrvpBORjDazUiAmEF65Urdp9Z2NaTZsLIP8H8avsTS?= =?iso-8859-1?q?RX23aZiJy8Mk27YIKmRVqBa3sqwSYDDJKAeJfcjGDkonZGav4ykVlU9zpyP8?= =?iso-8859-1?q?XAhkirARxbVtfSvoEq7O2FDCEhFtTXjFPjIFqQywsA5fUMjHKoF9Y4R07GFv?= =?iso-8859-1?q?PwPEjasjynMJ5yTIkYk/GwzG1EtoFW19Cml86Iw=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: 9a50147d-7fb5-419f-14b4-08db6bf97f7b X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:28.9708 (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: St9RhT52Mug8TNe7Ch+6hr4K8OeWO5drqHDdBSb3pt+waRLDHP2sWpWXxYOsZZVSSSE+HKtQ2XvTVXtvJZSgZAtYOjTValJRpddZPUsTwOI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB10054 X-Proofpoint-GUID: JeKz8zX7fR2pCnLmRBophCnGYRxhoQqx X-Proofpoint-ORIG-GUID: JeKz8zX7fR2pCnLmRBophCnGYRxhoQqx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 adultscore=0 spamscore=0 bulkscore=0 impostorscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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. There are examples of emulators [1], [2] which already deal with PCI_COMMAND register emulation and it seems that at most they care about is the only INTx bit (besides IO/memory enable and bus master which are write through). It could be because in order to properly emulate the PCI_COMMAND register we need to know about the whole PCI topology, e.g. if any setting in device's command register is aligned with the upstream port etc. This makes me think that because of this complexity others just ignore that. Neither I think this can easily be done in Xen case. 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. For now our emulation only makes sure INTx is set according to the host requirements, i.e. depending on MSI/MSI-X enabled state. This implementation and the decision to only emulate INTx bit for now is based on the previous discussion at [3]. [1] https://github.com/qemu/qemu/blob/master/hw/xen/xen_pt_config_init.c#L310 [2] https://github.com/projectacrn/acrn-hypervisor/blob/master/hypervisor/hw/pci.c#L336 [3] https://patchwork.kernel.org/project/xen-devel/patch/20210903100831.177748-9-andr2000@gmail.com/ Signed-off-by: Oleksandr Andrushchenko --- lorc's rebase: check for the logic after rebase 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 | 38 +++++++++++++++++++++++++++++++++++++- xen/drivers/vpci/msi.c | 4 ++++ xen/drivers/vpci/msix.c | 4 ++++ xen/include/xen/vpci.h | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 0524fbd220..677b93226c 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -465,11 +465,27 @@ 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) ) + { + struct vpci_header *header = data; + + header->guest_cmd = cmd; +#ifdef CONFIG_HAS_PCI_MSI + if ( pdev->vpci->msi->enabled || pdev->vpci->msix->enabled ) + /* + * Guest wants to enable INTx, but it can't be enabled + * if MSI/MSI-X enabled. + */ + cmd |= PCI_COMMAND_INTX_DISABLE; +#endif + } + /* * Let Dom0 play with all the bits directly except for the memory * decoding one. @@ -486,6 +502,19 @@ static void cf_check cmd_write( pci_conf_write16(pdev->sbdf, reg, cmd); } +static uint32_t cmd_read(const struct pci_dev *pdev, unsigned int reg, + void *data) +{ + if ( !is_hardware_domain(pdev->domain) ) + { + struct vpci_header *header = data; + + return header->guest_cmd; + } + + return pci_conf_read16(pdev->sbdf, reg); +} + static void cf_check bar_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -692,8 +721,15 @@ static int cf_check init_bars(struct pci_dev *pdev) return -EOPNOTSUPP; } + /* + * 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. + */ + ASSERT(header->guest_cmd == 0); + /* Setup a handler for the command register. */ - rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND, + rc = vpci_add_register(pdev->vpci, cmd_read, cmd_write, PCI_COMMAND, 2, header); if ( rc ) return rc; diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index e7d1f916a0..687aef54d1 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -70,6 +70,10 @@ 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. */ + 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 b5a7dfdf9c..e4b957d5f3 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 1e42a59c1d..fe100a8cb7 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -92,6 +92,8 @@ struct vpci { /* Offset to the ROM BAR register if any. */ unsigned int rom_reg; + /* Guest view of the PCI_COMMAND register. */ + uint16_t guest_cmd; /* * Store whether the ROM enable bit is set (doesn't imply ROM BAR From patchwork Tue Jun 13 10:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278341 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 28E14C88CBE for ; Tue, 13 Jun 2023 10:33:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548000.855747 (Exim 4.92) (envelope-from ) id 1q91KP-0002hx-4s; Tue, 13 Jun 2023 10:32:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548000.855747; Tue, 13 Jun 2023 10:32:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KO-0002hK-US; Tue, 13 Jun 2023 10:32:44 +0000 Received: by outflank-mailman (input) for mailman id 548000; Tue, 13 Jun 2023 10:32:43 +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 1q91KN-0001il-5u for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:43 +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 9f3f632a-09d5-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 12:32:41 +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 35D6YVNj012776; Tue, 13 Jun 2023 10:32:39 GMT Received: from eur02-db5-obe.outbound.protection.outlook.com (mail-db5eur02lp2104.outbound.protection.outlook.com [104.47.11.104]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3r63wtu7t4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:39 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6520.eurprd03.prod.outlook.com (2603:10a6:10:19d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.46; Tue, 13 Jun 2023 10:32:33 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:33 +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: 9f3f632a-09d5-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AgvA5psbN+TuvJGRhDt2W7CS5GkdWCzvP0OkAIV1da5PrXbX/ADzl/+b4A/5Mw0X2jUQGgprsHHicbbX+vqEIwK/76jdawjwZzZjnqTO5ZNLAdDz/w86kkKP+DPjefBdiNK6aEA0LXY3sQgx8UCgCc5OMArLh3Zq7Hv6lfN8tp7t5gP4QbLsc7RPcoNqAU3t6zmUX45wi5zBec9s57xsiqp68ncDCgRqf/MewO54nJq+GV1wmP5fO5AqtiLdRCVbIrGIY0rXIkml9cQ2MmX3/kiqhcnDoF+/bd2sNWlQouLaSJkguOBoFiFHRIrIsKm1NThx6oxo2GEqt4rL1D3DDA== 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=zpFpBBN8bFwrHudq+nmPmlQiloYQd/Hb7VVwCBKtEtE=; b=GC7Iymgspayv3LQlo4XrEF6QQcT0HVcv5ACEcEZNIcC46cpApW5VvjxOX3Lxs9dLl9Av6b+hEfkulZHBkq2ecOlSqVs5CVyDeT98Mcu3oGSSc2HB33v5DxLHujsrmzHV+nMtREbfLiDZsoWwbIH4KKUMb7lH7SmwosfeDrdxgh3lKgTxAHfMYg6zu9sBAgy11SmT+0J6GyzYGFoRWerQBL5jKLxaC67ALr4lHhU0FLCo1bmxkNYfw3JCQrNQVoLH6MkavjmwQNAXkk/ivswOmXtZptLplJtSPd8hm8u6Wv81nyHDnIUBZb7LKBX4B6QNVFCrYa8hKNHdlGANKAVg8w== 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=zpFpBBN8bFwrHudq+nmPmlQiloYQd/Hb7VVwCBKtEtE=; b=NSwD/ZTk0yDSQvaYm5btDFx29lDQjiroGWQehjuxaNdq/YnJvfjYaOStJPEC9Xo3KEdF7lQMSYPVxzN+DsTkevrBYvHpgCJLwhY2M4X+6reFgxutvVePjX7WlXLzVmLyRM1l4h6m608wXOFA3MSdMdFJaJo0zcaedt05CUMtysLXt3/1aMPjN5McVmTbWILUU5t+93QpG5wvU1MbP/aGvQ/yvmTNSI0iTqNc99cM4h1XNzssXhmMuY4I54pxhi6mnrjByKCckDhn4YAd8A8jnE8WtclCNsznIfTQN1IA9JsBNc3U2b/XM+nQ5AS2bh6chdLLnJNo8hLp8CsBxWpDSQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v7 09/12] vpci/header: reset the command register when adding devices Thread-Topic: [PATCH v7 09/12] vpci/header: reset the command register when adding devices Thread-Index: AQHZneJaX+tcZrSWoECrBLaG3eDtVg== Date: Tue, 13 Jun 2023 10:32:29 +0000 Message-ID: <20230613103159.524763-10-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6520:EE_ x-ms-office365-filtering-correlation-id: 37ad6a5e-679b-41b6-0ed9-08db6bf97fd8 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6cnvfMhNIEq6N8SpldBQaan5Ivytr8rEJS9BjA5Hw7e0LconSNxaUYeGNXH+oLMtWR3sO6lInmth7Om3oF9RZXgqd8Cjtt6q/qaHI8KTJOLc3bUeYRrpC/fN/iUH3v1+EEzgPwXkjrqwqpHP+MMNByfHiRR1cY7a1nWpbiphj60ZRGpIF4wxtFvXg1vf2jVU5j/+bXSDJPahKJadyUDphAdLiRZdF2d5oo+D5aQILMl4s5qNKLw/NILjfazlM61EPu3duZSjGZWLkpdhF2PiZQumDhLLXE2e/qjKcjMz3mR/8uTqpNLdFFqJZZJmojkccYBmsmwpPFhSfDlcnVW+N3D7TlMNx0BWUX+j/bsWY+EpM1e3TtKNNBzRJlSYH607WZwiFP4qizVU7wpSYjuzdOaiLmBcouB/3Hym325RFxSFKpKNs3l0E1jwWnRZBDfe6kvmdVum+B3Nb5oqL+9Z1l+fXHF981tSxfLG7MwhdsSN3+wnXOjJ9cRllb3MZFKvcfT3S6ZOyB+6HpkWjTZGVdNVzXVSeqbajUXm6fXBSqlmQtEW53gnxxTrsicZ3999RhbW3Q8SELfTpBpaD5Wl6ruDLq48cjcUGOrIvmyTrP9wqbgEUK3Ii9RG0pyGnQfx 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:(13230028)(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(451199021)(6486002)(6666004)(6512007)(36756003)(83380400001)(2616005)(38100700002)(86362001)(38070700005)(122000001)(55236004)(1076003)(6506007)(26005)(186003)(2906002)(66446008)(66476007)(5660300002)(54906003)(8936002)(8676002)(316002)(41300700001)(6916009)(4326008)(66946007)(66556008)(76116006)(91956017)(71200400001)(64756008)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?2qxZQKVStmzJ8UmCks8o73r?= =?iso-8859-1?q?/iZnrnXcfIjsmgVuG0mBqDJBC9xKCPOC8UKwx8sE3+yv0BICW8UAN+fLlPo1?= =?iso-8859-1?q?SG2lVcb6SIQ/mbQohs6Ml8neYkFN+SIApFTFTUd8bSSVY1wzOTztHekKWXfk?= =?iso-8859-1?q?n3qJLhuo5DiZzcl7RY7SGKUvhe6kUTnNhQBcO9nio0roPCHEhr0Oiv9YuG3/?= =?iso-8859-1?q?PcDrwfcC5oQmpWeYRVsNRuBog2yGs43Dhb6Eaz1jJEzFKQr+RDvfe4W3d4su?= =?iso-8859-1?q?ezS86TKlm/Udt3K7n1iFHs7TYNsjcdSWMQ6xLMYQogW7/7qCr7dfdtV3QI+m?= =?iso-8859-1?q?kzRYOoJlmIlUZ2ky5M441gIg9kQnuhHH1ihn93aj41nmSrylEOhT1nAPdv6I?= =?iso-8859-1?q?TSZiELom06/TAorAVpq8GxmnRsE3YJcZqV15OsPAFjOpGH6BJDvEKcbL4Z+B?= =?iso-8859-1?q?Ae+qpvapVurBWwVgWk3SNGoAP0Y749JPO70x2hZWZYzQs4Ec27WGct3Xqeo4?= =?iso-8859-1?q?6ZhRSOhsJRpjZXM+QfDllfsicMm4EMAs0Kugqt7mTr+j0mnWiLJMlt/toA4E?= =?iso-8859-1?q?OBfuQqq9IqghuivQjjbwAk5GBZ23Z/F/InmnCRhoVCBB161UBrX62Sgvu2ju?= =?iso-8859-1?q?IIxLsnlpx6y9vNwHWytQfdn5Vr/McAJZ/RZBCVVjff/vbVz34P+ulXYoNyP+?= =?iso-8859-1?q?zfoqjgoHNSceQ0IOuOmqvScySNV1/pxFEYNAUYQDeqBVEShwIdnFdkbq/QfT?= =?iso-8859-1?q?zyrMy2fEilCKbx5PMo8oKRaRbUQ8Z4uszRsMfYxvXCJmzD38LlWKAmgJeHSj?= =?iso-8859-1?q?DA9OHB8rY2vCJDJtZSDRr/UUR9zS82BPB7kIzz3ANMOWktwz2fUYWnpzb0Kp?= =?iso-8859-1?q?5hzi7GO4m5vU3AW7KgXOjn5p2V0l6awIuqAzXNnrtQ7HmvD/0bzPe7kJNEyj?= =?iso-8859-1?q?/odZGwedUFzVbn4taPFI/89zoy+vmN2AdSrzIOddUJIImw9JWUcBb8YU0yol?= =?iso-8859-1?q?trsPKbzNM5ZC4Cd4tOTC/48lAz44e0t/KCyT062Nx8ZmH+4rJ+3Rd+x0RAVa?= =?iso-8859-1?q?2cC1TgumIcEcqArdady0ERKi1kd9E/wmUCjSJWvtNeASzIIGTfm/b1lFwELQ?= =?iso-8859-1?q?JmVCEPZdv9d+KYHxI5sC7EjgvNKNswDKvPTcJR1uc/4ctN97nb7PzoRON7z0?= =?iso-8859-1?q?oPBLhM94FNJHVsDak1TNxnbhjRL001TlGrkq5BnAUoTgw6IsVfmz9D744wYZ?= =?iso-8859-1?q?B90Cc/qCLnLOk6MRK2IdeKjV39V4ZK+hrYCdsGAEbIjnW+/vMaBoMky3jAZO?= =?iso-8859-1?q?2mtcw0e4+rnscPp7p9rTjvp6a2iq5+BtOcPcP+gFRjvj3SqjyHN1Ieb46nSD?= =?iso-8859-1?q?6uDQoMvIx64YGGZ3uAI4hrEuUxrHwJuxcT6QSbJ9uOTcfSGEUbCT/XvoksTb?= =?iso-8859-1?q?i+uGPVCrI7MtE9T9xHBG//m8cQgXK63KTgO6XUhXPh0unRmj0XwRNkU8qwzG?= =?iso-8859-1?q?7FcS5VWUOB3g39DK28mnnir9Y3g+0k0BnXMKXip+Lad/FdCorT5PadE3TW91?= =?iso-8859-1?q?bu8sTn0SeHtghmNGtxSAb14w9Zlp6VUs1tJQtQlezatJn1KLynmZb2ESMpKA?= =?iso-8859-1?q?Bc/I8SNKZzMuYpRsIvfqLpIqHZrj3+9N7uqey8A=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: 37ad6a5e-679b-41b6-0ed9-08db6bf97fd8 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:29.2119 (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: D3tRgYPrW/X/COSN/d26vQQY71bFMVq8ux3nItXVy6u3Ag58FTkXCys3N1U7ktlVPBB9xTMtiAIlJBMoSUgLBt7gRetoWJrDlw46DhxCoBk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6520 X-Proofpoint-GUID: Q52K87s-lGD9Ee8lFvdXvH4qYj16tVCy X-Proofpoint-ORIG-GUID: Q52K87s-lGD9Ee8lFvdXvH4qYj16tVCy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 mlxscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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. Signed-off-by: Oleksandr Andrushchenko --- 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 677b93226c..1021a61ed6 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -728,6 +728,10 @@ static int cf_check init_bars(struct pci_dev *pdev) */ ASSERT(header->guest_cmd == 0); + /* Reset the command register for guests. */ + if ( !is_hwdom ) + cmd_write(pdev, PCI_COMMAND, 0, header); + /* Setup a handler for the command register. */ rc = vpci_add_register(pdev->vpci, cmd_read, cmd_write, PCI_COMMAND, 2, header); From patchwork Tue Jun 13 10:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278343 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 5B004C88CB4 for ; Tue, 13 Jun 2023 10:33:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548010.855813 (Exim 4.92) (envelope-from ) id 1q91Ka-0004sB-GW; Tue, 13 Jun 2023 10:32:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548010.855813; Tue, 13 Jun 2023 10:32: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 1q91Ka-0004qw-Ay; Tue, 13 Jun 2023 10:32:56 +0000 Received: by outflank-mailman (input) for mailman id 548010; Tue, 13 Jun 2023 10:32:55 +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 1q91KZ-0001im-2G for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:55 +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 a61e7bc9-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:52 +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 35D6YVNm012776; Tue, 13 Jun 2023 10:32:41 GMT Received: from eur02-db5-obe.outbound.protection.outlook.com (mail-db5eur02lp2104.outbound.protection.outlook.com [104.47.11.104]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3r63wtu7t4-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:41 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6520.eurprd03.prod.outlook.com (2603:10a6:10:19d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.46; Tue, 13 Jun 2023 10:32:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:34 +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: a61e7bc9-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=erYGgcVaq8sCLME4yLu0RupUF6ma//sPm7x8PVqzRxfuPqVJvYtqW3QS35jR2x1NVIr6UJdmjJZaMWwGB1Yxp5aVEvOC2jVInATHGnRbJ69S4pi9SMRjw2d66ksAJwXtduGzkj+KV9VHvfV8ECYNm/R9lSpX+i9GZzaupE99iqEr/4M2nmqFmIJJb9POOPelP3hCJ5WiQnRrRtw8iELVfGJLCKla1jni1yyuKM4Zu3bB5LxQxVOFusEeSYWttt/31cabcQmudpEocfT9qPSTwWqSvaYuyNCVdii5g+bDRGB6SLfhoVsrCqT4L9cyh/cxMxLB43qjdtyYYuo3u/5owQ== 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=Fu9nYGTzKNJyaJivkA/1i+SwTC+5h8xHonD698eXMgE=; b=YbKmgdO5I2dHVD4hSth8LVzTmyyXhOJoUdSyTWXlIzoQdjyu5sU/g9zPmbzhwdg+2I34gWzEFt6MM0ISFopI+Tv+Alo6mbiwZU52QEUtb7OUNEb1Y7hNRAUjuQUVJcpV0TaPQKR7Q6xrVcgjcIfKc+Sq2ChsD7LtTKwkNnyu98z8r7/k14FpA/qat6S3sXQ1pZMIafjBrscWlTKIjlPXi+7E7eGgwkiu/eQS1tkOktGSOT0mHQQt4BFmNKEzLQUyoCIuhRalif93atDS2kDvpQ4K5bAfpVN0bQ+/K8au8gfpbP2Ybr8NXpYyPGF1KQYDB/yYLnQO4qKCREO/8Zwyxw== 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=Fu9nYGTzKNJyaJivkA/1i+SwTC+5h8xHonD698eXMgE=; b=fAgPH2+Qmosdlflm0jek7vKYBFFotrMhnB2PTdb1p6Qheh/59ub49VBrQj3kDVCgwnR45q1nor78jNy1JmEG0xN5Lk3r14lboP4d4gjU7GubXf4cT8vugi/0j9NwRbFGEkCEptrDqa0kCAWvBbDdlGKjNT283eVunVKvDLAWfLnVeihSzBnEvN6/qF53dE7Vxw1a6RmGfhKoFG9NIuFdeqA2zN/T6O8k31RKseReF+R+RT+YD0yl4Kq+bBXs0hKj4S7t+2tc8kCMMrRy0EDpdKvFJu7WIEEg3o3tKBq4fwlp2BdnBiTnChqPd4Fmhb2S/1BE9azTg/vR/oKWfXKiPQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v7 10/12] vpci: add initial support for virtual PCI bus topology Thread-Topic: [PATCH v7 10/12] vpci: add initial support for virtual PCI bus topology Thread-Index: AQHZneJaL+74dDpvwk6p5MTZEcUOhg== Date: Tue, 13 Jun 2023 10:32:29 +0000 Message-ID: <20230613103159.524763-11-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6520:EE_ x-ms-office365-filtering-correlation-id: da98dc9c-ebf3-452e-a8a1-08db6bf98013 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: g7SUrKsJ+EPYjtIadrZMznmzpgAjwFmC3Eh90FdW/XTHW2SlzoGI54q1LVk7Z48FBynbzyd44cZxod4B22dI7cQeeDwg+3fD0FEU0UuxIv1VEdETebFG59Br1FtUE6wV1bYqe0Idbr+XgWlwWDNZjd0UsjFcc6rgo3zSlbD5chRoc7F9zly0nx6NS86jaZvpk7H1ep1Y2f9kuHbhgqExjR4EqT+6qeUVN94a/rmrTvjDgx/Swnz87vGgF8ux78xI33JESbiGJDg2r4qFJUjthd0k9MX3Sp+Oh0Usj2uBa9SU1Q6WtGmPpvKS6BbxOZNTjja2rP4QABWLc/HPcSuSKeaMKLqiHzBvclnbojBaZtN0+XdSa76TeehkBAcOgz01cZI6bfRXCv7l8yD0CQu2pGrbkhIJgqf2ao6mKeQ74V0OIb6P5QWWbmPXSsQs5flOq/DyH/IdJsDQujoetvW5saQXHbXsCwcNbL7rmfUV2ns6Qgi34jEL43Z6iJ1lcqNaA6GEdgLviApiC1A9Zr5XN3VHZdzgiJvq89RIVao9E8d6f63iuuuuC2Y/WtdpUIHNrycUPR2HQgHisSfyA5S67HPQba8F01moyzTNBMZ94SjrITQ5aUplDzVggGmbN4tI 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:(13230028)(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(451199021)(6486002)(6666004)(6512007)(36756003)(83380400001)(2616005)(38100700002)(86362001)(38070700005)(122000001)(55236004)(1076003)(6506007)(26005)(186003)(2906002)(66446008)(66476007)(5660300002)(54906003)(8936002)(8676002)(316002)(41300700001)(6916009)(4326008)(66946007)(66556008)(76116006)(91956017)(71200400001)(64756008)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?tCTa99BURWbrfdkk5sk5LZO?= =?iso-8859-1?q?gz8y/YRvg/PB/q3A4GsSDF9ojTiY1Lonqgrxj2bpToznNkHl4mEONXc6oMll?= =?iso-8859-1?q?2F6seUPKRpikXSMY20i/NNq/OnoabnbE8Iy+n1WcA3UWdBbgNNWtCzyW35/L?= =?iso-8859-1?q?TVLj/Zcnzj3lvd81wJHA+5WIz2WlJ7ULSKFL4UiinstbcFSw/M0RXXatr4yG?= =?iso-8859-1?q?A/WGIM/lVt1YrTDaFRmKp1PlC5z8UJhlq87q9oZdtCCoX5LNIRbTqaSeLdcE?= =?iso-8859-1?q?3G1tOQAz5q+yrh4WNnx3rftx+7cy0ud+zVZf2/AaXneeaAvan1Hb+gWwdinN?= =?iso-8859-1?q?H/8zKgKVBjPekx/af9fW0icA77DhrIlmth6SRmPnZjoQBSxW6fk/ug0YlpLT?= =?iso-8859-1?q?kV0gMkK9n4QPmuJ7o/KdpWVWllGD53g/JSAhY8lTMYobLI49y5xgJpT0BcZ+?= =?iso-8859-1?q?yCzUxbyIvI3hPFXz90HIg/Yb2IC18hw0Sn91yqWbLIP/0bnGh6adWK3EvuCb?= =?iso-8859-1?q?6Wsujh3Wv341WpFVx0nrFRp3MQs5XW/v5cGjPLNE5q0OiA5t6ifQ10u2ltWk?= =?iso-8859-1?q?gtyoJyfK1qFJxWdbr8wxqZws9zfDtsegf43w30QRqn0SGDjmhSZjT6T0lN6r?= =?iso-8859-1?q?Iz3ykxA7J6Ue07BL2V+TPVD0fPn4mlkwszvuoGyUCBfRf8pKXic2LEb4fp9f?= =?iso-8859-1?q?5QdxViVjb+D2nbNRwceO1OtCVg1Ou8FF3uHHFN1sDpUWY0KXadm3JlHtMbtB?= =?iso-8859-1?q?oa8pZRSlmL6IGxw+fX+0e1LKfFgoWNgEVkUtGySNVcbMsYHALeJ05PjF1H+F?= =?iso-8859-1?q?F9p79f0t5q86OmeXa2L2dg+A5fBNT+jUk5KgXzpw1DbfuZc5aqL2dp2eYa5l?= =?iso-8859-1?q?6KcTklEmbl8mM/Manm6JpPb79WItaLKtoPJ0UNiyEZIJZMOisCcmZ3KI5E/1?= =?iso-8859-1?q?ZPKxz15OmCilNg+/BkmFPr/mTyKNq0Td62WhGRJgMNHoO1wiIsw12zQ2Qgs1?= =?iso-8859-1?q?LV6J6jf4CZDoTWtQFqQiSwtdf7fs5bkju6rqgaEW2urFYvNJNkGRnAWXVZ8a?= =?iso-8859-1?q?yZObkgE1Lzrr8GVXeSauKetEdxFmDxqDgoxor3+86zasvLKLisPt6zNWvlgG?= =?iso-8859-1?q?I5U/aVrlAIZdx+5wWKuV5FZ00tMJ2tVngHm6ZmS8x7Bnu/4t0ly2xXKD0Iny?= =?iso-8859-1?q?h/MGRR8Jqk9uNvRikmzC188yncqz2beezY9udLTinLbLx6+fDPh5dzdkaZs5?= =?iso-8859-1?q?uTlIWQct6KZ1TFuD3JYKtwrbE6vhKi9L7uFWgJ+AlsVxBLGOnjYn59McmDRN?= =?iso-8859-1?q?HRA6o6p6BXg+PwWxBJH67oA0Jocsw+38ZaVxo2rrIcZn/Cz62049v7bDLBF6?= =?iso-8859-1?q?xEOOOikS4hT08oPWdLxNKX0lVyREhTzUy4tc6P6cgjV3horFz2SSx4DsnL1+?= =?iso-8859-1?q?ieek9FavLzAzQBjdggC3mOlscE+av9LdtqbUMVAhiZI/uKbGasHld0j6VdbO?= =?iso-8859-1?q?fITp2j9YEre6EO1MLlI105jGciS+RB/A9CKwgEdbsZwa/PzzHFK9ZfLub190?= =?iso-8859-1?q?ymoRvkyBzCQjWMBZC5NboPukwcfgFg/FJEA87wbb4GJ76FjZIx0au06fD+In?= =?iso-8859-1?q?XXnNv8P+JqVIby9JgVJgVdAHw5xoUXf3kDeHsvg=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: da98dc9c-ebf3-452e-a8a1-08db6bf98013 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:29.6922 (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: hncphYA7eJcfvmPdHIs3M9ueIZ6XudQ356cKp3IoZxcvwAA7OhaVKsTGe4TRhWLRZWVU3YWAhvSm2eK8Q963dKKagKKvNRWejai4/4UKt3g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6520 X-Proofpoint-GUID: uirJe6HoIbNriTB80PtcRSnsSMXvlJWS X-Proofpoint-ORIG-GUID: uirJe6HoIbNriTB80PtcRSnsSMXvlJWS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 mlxscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 v6: - re-work wrt new locking scheme 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 | 70 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/sched.h | 8 +++++ xen/include/xen/vpci.h | 11 +++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index b542ddaf7b..9dacb70bf3 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -98,6 +98,9 @@ int vpci_add_handlers(struct pci_dev *pdev) INIT_LIST_HEAD(&vpci->handlers); spin_lock_init(&vpci->lock); +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + vpci->guest_sbdf.sbdf = ~0; +#endif write_lock(&pdev->domain->vpci_rwlock); @@ -121,6 +124,62 @@ int vpci_add_handlers(struct pci_dev *pdev) } #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()); + + /* + * 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 ) + 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; + +} + +static void vpci_remove_virtual_device(const struct pci_dev *pdev) +{ + write_lock(&pdev->domain->vpci_rwlock); + if ( pdev->vpci ) + { + __clear_bit(pdev->vpci->guest_sbdf.dev, + &pdev->domain->vpci_dev_assigned_map); + pdev->vpci->guest_sbdf.sbdf = ~0; + } + write_unlock(&pdev->domain->vpci_rwlock); +} + /* Notify vPCI that device is assigned to guest. */ int vpci_assign_device(struct pci_dev *pdev) { @@ -131,8 +190,16 @@ int vpci_assign_device(struct pci_dev *pdev) rc = vpci_add_handlers(pdev); if ( rc ) - vpci_deassign_device(pdev); + goto fail; + + rc = add_virtual_device(pdev); + if ( rc ) + goto fail; + + return 0; + fail: + vpci_deassign_device(pdev); return rc; } @@ -142,6 +209,7 @@ void vpci_deassign_device(struct pci_dev *pdev) if ( !has_vpci(pdev->domain) ) return; + vpci_remove_virtual_device(pdev); vpci_remove_device(pdev); } #endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 78227b7a1d..312a692b31 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -463,6 +463,14 @@ struct domain #ifdef CONFIG_HAS_VPCI rwlock_t vpci_rwlock; #endif +#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 fe100a8cb7..3cb5d63e84 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 @@ -160,6 +167,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 Jun 13 10:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278334 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 1F6E5C88CBA for ; Tue, 13 Jun 2023 10:33:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548009.855806 (Exim 4.92) (envelope-from ) id 1q91KZ-0004ZF-7M; Tue, 13 Jun 2023 10:32:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548009.855806; Tue, 13 Jun 2023 10:32:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91KY-0004Yr-Vg; Tue, 13 Jun 2023 10:32:54 +0000 Received: by outflank-mailman (input) for mailman id 548009; Tue, 13 Jun 2023 10:32:54 +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 1q91KY-0001im-2F for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:54 +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 a622b22f-09d5-11ee-b232-6b7b168915f2; Tue, 13 Jun 2023 12:32:52 +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 35D6YVNl012776; Tue, 13 Jun 2023 10:32:41 GMT Received: from eur02-db5-obe.outbound.protection.outlook.com (mail-db5eur02lp2104.outbound.protection.outlook.com [104.47.11.104]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3r63wtu7t4-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:40 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6520.eurprd03.prod.outlook.com (2603:10a6:10:19d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.46; Tue, 13 Jun 2023 10:32:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:34 +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: a622b22f-09d5-11ee-b232-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=av9kJfi1bM1k9m81oA2bS3uGQE/Lasn6EwvynlwSYb0Z+2MGUtU7EsF9UpM3UPgVR5UVmMwgJGkw50K1eRGEPmIhzSNe7DFwn624KI9ySuHMzQPkknXpn5AQXm9ggzx+GUS/wkH8QojZxigRrkfH4uEdhFYkNtkbC3/xlZi3Aj+CeS+ssFjTmTVuh9QaJrllQU+femRUlbR5jjshi7V2dFGLcWiiEAF+FsEkLuT7GLQVOMQ34sQpebRG2PBSSF9ir79+tyjfz/bzes705QFL18VgTYf61A7s7bWPAd5BqhdfStbajTgoIork2nkB/MOHIgKyYPgPaztVt1Mf2W7spg== 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=aQLDTRCPmYV+snDogimIGaafhmJyMu5DPAp093BY9KE=; b=VufJChg9Gi5GjFgUaMHXuMVQBYCIeenSX6w3FBjUv+GuoqZlgyVDFVPZfGKRPLwxjVbfFpq7u5c5o9llds2NRdfWZTqyiTby3lO0A64zl1mi5sG43pH+t4z99eUfLm8qSqRF8UxVe39tLsPRMh8cfamP3LamhNGo9YlUA84FgAO7+kmk0oBPv62q8lQkBomzchg4Nc2nmSDR1NiBPi6JUoXkdqHN3THKQ7zjySe9o77N+NJ6efuXaD1cZqSwlEd3reL3PjqUPUaJ7boVqSYI7+dtgbdQG/HSx/70DeA7TzaOgFElqekd0AiWkcAUi9J3kuZ5LTU6Gy+zJZW5UcPwBg== 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=aQLDTRCPmYV+snDogimIGaafhmJyMu5DPAp093BY9KE=; b=dVtHAZHhRZiJh9pVeyz1LJpEd2FmZp1/xuIDYbdf2iHuVDIqhU8Umebo0eh7ElOd0qIxoXOLmDQ8/poRS9D/w8M/2TCJ0Ed1FvJRnz7Xh6gzybXeVw08TWsBXIl90nfA8n2O3O2yzoL103/yoVq9AsIrk6/wrwnvPmu3NdePay5ZxYCIJSYzHnVS60V5wc44HO2ZQ18WXzUzMgBYyUMqzFK2cL58IUeLZRId8x5bzMTB5l6VISGMkcGyhET79c+prW+/pvQYfjmIc/xtcg1lR6mTMlAl069sj4n1pfR1LTmBtlekX0qpr7waz/7n/gWlkJ6HWBg9GXDgumgU2L9KYw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: 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 v7 11/12] xen/arm: translate virtual PCI bus topology for guests Thread-Topic: [PATCH v7 11/12] xen/arm: translate virtual PCI bus topology for guests Thread-Index: AQHZneJaM+qTqDNwO06sgUif4aO4dg== Date: Tue, 13 Jun 2023 10:32:29 +0000 Message-ID: <20230613103159.524763-12-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6520:EE_ x-ms-office365-filtering-correlation-id: c9db9436-2d7a-4414-6957-08db6bf98056 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wAfI2XfUEMUszH4AXSjXIfZcMVMcgjUpxfiOkRC2GHOXTM8BZcGV8r79Mflq6LBH5e0fXGUsgfnj+M252I+ufgSvZ2ZBhD+i0jeyGS6gSc43jbHahmxHR9ZGb/uHV03+ASBqp/t2DFGW68eXKq0bTlIhQg02/4YoFVZyP+L9A79Vei7GJKq0rkoEUJxrm+WL6cwwyPQLegh4tyVIe1CpGf9EdCWXD9OeSDbvcak1vyYtgUI3s3DV+IWs4p8c0vFI0NsgvOi++uh49fDGHIf34HQcHIIqVhhm9LfcgiSWHqXjHA0tVH5y2oNCW31OPZDoDCBetBtvT5lX2rTKnUS4QxN7Dsz8sCdMSGz1FaC1bhU4SqEIvMq94bw5MREVtXPrGXL43wTTz8S6DeIan+ZX36E53zkDZz6B8G0WpSyT9sG7aD3veNC9NG3M/PwgbxF9I6hTl7NY/iDySqsBPrqQvFKKJgVlcowVVkQTn/hg0orlhlHKyKINYg7U/+GgmgA/GFUeIABjwNO0yAsJ7r5h5NiN8ohW2XEL+xAsVKi7RorpgvsXED5341B4Pr4jdCp7wcgOKUwcWr+TKCkpHTjTGBEKdadd4ffHq2noMrhe4TipQ0eNphCWK0wfWR9BStKc 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:(13230028)(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(451199021)(6486002)(6666004)(6512007)(36756003)(83380400001)(2616005)(38100700002)(86362001)(38070700005)(122000001)(55236004)(1076003)(6506007)(26005)(186003)(2906002)(66446008)(66476007)(5660300002)(54906003)(8936002)(8676002)(316002)(41300700001)(6916009)(4326008)(66946007)(66556008)(76116006)(91956017)(71200400001)(64756008)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?W77NOWqte3qLyimoPFzcvFY?= =?iso-8859-1?q?T923RGyxpm59ZCIT9b/2wRSGWFORbddfBqtLXPQ4Q+ldpodfx+B+RLmvgfpM?= =?iso-8859-1?q?iYGM3zMYhA14MdoGlEJz4Av7Hb26AOeLlKK5kKjmfMnIVR49/SgumWZBfqpn?= =?iso-8859-1?q?XpCCI5ahSnGqoz/vZjL+DqrpsSw/1bz9hIu+XlQIDNw3/mawU8/a4y1tODGe?= =?iso-8859-1?q?AhvJUO5rxl/C4LqLxgrd33rM04+3R4GLq2zZFEHrfIMLGwi3cMfRhiBL+QPK?= =?iso-8859-1?q?557giQRKuOgL5kvMpn7yUnd/pQ3O5Jbzp/Tqc+4qzKKViGXB98I/nSxPhx/H?= =?iso-8859-1?q?GWW0EINiSZnI8DfVWhjRY9lplnlROD0X3amNVdgJNeaFmh6/kx9g6D/FbvIu?= =?iso-8859-1?q?n+HOnmyO3IRuSZq1VoMzG/6qjDZSjtRCCPaeaOFhGUcgsCPKw+uchH9JlvJ5?= =?iso-8859-1?q?QsFC4z+p9AuPS/UEm73UG7Ctk8BhOQpVhdtA7YXdmbQjTW7jxr2oDg92D8zg?= =?iso-8859-1?q?ivIB+VC3G7JYihy8fJqCOzUYoAJIUz+H0plIVc/VMH6zuzZInZWiA3XtN2DG?= =?iso-8859-1?q?l3TvA/qf02hl63iafLai1NzsOzcegjxtCmEmpUi3bK6VdYAgLpBgN1dDvYfU?= =?iso-8859-1?q?Q55pLZdixWJqDbj9Xxirr40aNvSo5gvwMfquOc87TAGYVXJtnWLiwCyCENHB?= =?iso-8859-1?q?hkUf8z28NOshU/b/y6V+uxIVKR2s+RyMlW2xvUSA1eLTh0/xOKsO9eCGBoW6?= =?iso-8859-1?q?7StF8+sHP4SWJc7Q1aaBmb/8fhCeevTIwfkCpLynrn5pw1PasCemQj8UZ34q?= =?iso-8859-1?q?H5waBMNwHbxMCTJ+npuZGUcBHmqf1hH5cqCWzoMeIfdAaEqaKTvjvIaKWoVI?= =?iso-8859-1?q?K2a/hga7tB2OaGSuwIn8CEN4l/wevFiqKcKKL/O/eelvLUG3Ywzalyh5yFsc?= =?iso-8859-1?q?bOotes2LDCY5bVSMrdvExJWDqCXo+QG+AO/MBVpemPb7dpR3okcmUl80YJ3C?= =?iso-8859-1?q?3Rfqd3DYgh5LisPlD+yrBtj+liaNP22b0PSTAXWbc7bP3wHspVGo8Chl3ddH?= =?iso-8859-1?q?BMGb6587KbxsHIFnI5uQNv5wdrzS96fI59PEZAex4/7Hp64fI804F/S8HXm/?= =?iso-8859-1?q?cRRI/hNW0j/aXPbuS1ypCy0IyugxS9w8sfpz+CaAaHvRDDmD1nKjw7lq/NDy?= =?iso-8859-1?q?dDDZAQPCBtswjJsaEKaMzNjS1n8eA6zH0nldOLcgK6t6hS55bbyTw1IlorSh?= =?iso-8859-1?q?It1eSiu0aPh/nGZ3118nmrVExPIJrBtU7WZyE7FCqm2OwnspJQuB0K4P0HXi?= =?iso-8859-1?q?SQPl5HIcM35L6tZbN+lW4x4Oamwb70hGh24EyAv0aFOXL3KOlW+f/f0j9Scd?= =?iso-8859-1?q?FEKUIaMfZZ3QXK60hVasVBklwgWwLXcfcuuf+TbmysOI0QkVufA6Ava1GNDG?= =?iso-8859-1?q?zg81QJMSj3ZqOu5CsCLndp+S5N8ZMGNEnQ9CkfPX0SrFEOKfT5ssAESw1zaH?= =?iso-8859-1?q?TTkv3NXtkVQAfuExpdTdTetKVsA1TjvMlkUsvMuntYaatOF7Xy7csshAF+sy?= =?iso-8859-1?q?xm2NRARKN8uborVZkiN8bTHZV06myRJUxGpzTxDKMP/6xjFRd7qcv6HtjW/z?= =?iso-8859-1?q?xiYfT7cMIw5Oor3sWUrpq839aP96s2iMbVXllRg=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: c9db9436-2d7a-4414-6957-08db6bf98056 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:29.9298 (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: CehGYQSdFTqvjiB6fiqsYgT0eeFDctLO7RzdWr6PZJMhOFobQO46/txvijh4qKXhqg59XrNv1RN0/YYgWKR8xEVDrkkjtudLRUaemO3OfvM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6520 X-Proofpoint-GUID: 8qCW85zte5c2NE5x0LT9moFSrn1ZdiOa X-Proofpoint-ORIG-GUID: 8qCW85zte5c2NE5x0LT9moFSrn1ZdiOa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 mlxscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 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 | 17 +++++++++++++++++ xen/drivers/vpci/vpci.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/include/xen/vpci.h | 7 +++++++ 3 files changed, 62 insertions(+) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3bc4bb5508..d60913e532 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -32,6 +32,16 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; + /* + * For the passed through devices we need to map their virtual SBDF + * to the physical PCI device being passed through. + */ + if ( !bridge && !vpci_translate_virtual_device(v->domain, &sbdf) ) + { + *r = ~0ul; + return 1; + } + if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) { @@ -50,6 +60,13 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info, struct pci_host_bridge *bridge = p; pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + /* + * For the passed through devices we need to map their virtual SBDF + * to the physical PCI device being passed through. + */ + if ( !bridge && !vpci_translate_virtual_device(v->domain, &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 9dacb70bf3..490e3b14c7 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -180,6 +180,44 @@ static void vpci_remove_virtual_device(const struct pci_dev *pdev) write_unlock(&pdev->domain->vpci_rwlock); } +/* + * Find the physical device which is mapped to the virtual device + * and translate virtual SBDF to the physical one. + */ +bool vpci_translate_virtual_device(struct domain *d, pci_sbdf_t *sbdf) +{ + struct pci_dev *pdev; + + ASSERT(!is_hardware_domain(d)); + + read_lock(&d->vpci_rwlock); + pcidevs_lock(); + for_each_pdev( d, pdev ) + { + bool found; + + if ( !pdev->vpci ) + continue; + + spin_lock(&pdev->vpci->lock); + found = pdev->vpci && (pdev->vpci->guest_sbdf.sbdf == sbdf->sbdf); + spin_unlock(&pdev->vpci->lock); + + if ( found ) + { + /* Replace guest SBDF with the physical one. */ + *sbdf = pdev->sbdf; + pcidevs_unlock(); + read_unlock(&d->vpci_rwlock); + return true; + } + } + + pcidevs_unlock(); + read_unlock(&d->vpci_rwlock); + return false; +} + /* Notify vPCI that device is assigned to guest. */ int vpci_assign_device(struct pci_dev *pdev) { diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 3cb5d63e84..0d085971cc 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -291,6 +291,7 @@ static inline bool __must_check vpci_process_pending(struct vcpu *v) /* Notify vPCI that device is assigned/de-assigned to/from guest. */ int vpci_assign_device(struct pci_dev *pdev); void vpci_deassign_device(struct pci_dev *pdev); +bool vpci_translate_virtual_device(struct domain *d, pci_sbdf_t *sbdf); #else static inline int vpci_assign_device(struct pci_dev *pdev) { @@ -300,6 +301,12 @@ static inline int vpci_assign_device(struct pci_dev *pdev) static inline void vpci_deassign_device(struct pci_dev *pdev) { }; + +static inline bool vpci_translate_virtual_device(struct domain *d, + pci_sbdf_t *sbdf) +{ + return false; +} #endif #endif From patchwork Tue Jun 13 10:32:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13278339 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 D174CC7EE2E for ; Tue, 13 Jun 2023 10:33:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.548014.855826 (Exim 4.92) (envelope-from ) id 1q91Kd-0005da-B1; Tue, 13 Jun 2023 10:32:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 548014.855826; Tue, 13 Jun 2023 10:32:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q91Kd-0005dE-6v; Tue, 13 Jun 2023 10:32:59 +0000 Received: by outflank-mailman (input) for mailman id 548014; Tue, 13 Jun 2023 10:32: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 1q91Kb-0001il-Ji for xen-devel@lists.xenproject.org; Tue, 13 Jun 2023 10:32:57 +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 a800e56b-09d5-11ee-8611-37d641c3527e; Tue, 13 Jun 2023 12:32:55 +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 35D6YVNk012776; Tue, 13 Jun 2023 10:32:40 GMT Received: from eur02-db5-obe.outbound.protection.outlook.com (mail-db5eur02lp2104.outbound.protection.outlook.com [104.47.11.104]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3r63wtu7t4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jun 2023 10:32:39 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6520.eurprd03.prod.outlook.com (2603:10a6:10:19d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.46; Tue, 13 Jun 2023 10:32:35 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::6fa2:d7b8:9bd4:1a51%5]) with mapi id 15.20.6455.045; Tue, 13 Jun 2023 10:32:35 +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: a800e56b-09d5-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c/VM4lVNFpm/Tqs7sjBfTG3jzLmU5+cv24ae6tVY/4db4N59sWbIpB9VZiO8g+JbJmaukUgSqSwAEVk4wRA5k0WIpJ8iYMcH+roe/Cqiq3xu8Dp2v9ym6/7fyfXIM5YLqbe7sXNeuYEYHmvMwKbIvj2cDVDigQpLEG/qBxgU/kSfeFY3stEScp9vhdHvzNTcZ5N7sVHRMEQWV56OWQcdHPNztxdNLngQrJsvsdiMZUtvAk41q5IT4EijciHAEgcvGYlbRDDHQRWA+L7ZIx9wQ6vjWzVW5nB9wfIhJMkygoow1M2eRGEYUhlDx2cyBXExpLszK5YajqFhZvVjjntSNw== 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=zQTW0eUz8gWI49XTcH/ASQwLz+KUFxo+a0xrDbt/xqk=; b=Rtg5FF/ccuyTV7APOw9NTk90lyO337tT0E2rn+pXSIpun3TtiBKy10U8VRy23Wi5L+4nmbjkJoVuc7Rpn52P7bfmWbljbAWe79OkchyT2LKlgE+mhRUri4dWRK+VbgVqzA+FA7ehAre+j+BqTaFOG2Yad49QNHqU0p11Ql25uFmA4pZFlzIb9wyQIdEyvMsoecWyEEHK/vlw+B7RU1liE7yokGyOKBC1VlLCFYiJWYz4hjWGEL13MezA0ArpiR5+/TdnTr2/5h/slanBiyUHae9d//WZzOHM8R3o8HRNP+MujUman4MEQI/jL7p5DOIOMZB65wXhBSnZ+EJhjzP8Qw== 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=zQTW0eUz8gWI49XTcH/ASQwLz+KUFxo+a0xrDbt/xqk=; b=JA2tSBKSG61ZnvGSUV4fZ/gWDBWxgI8izCJ6CRyQACRn0qeWXb1TekOHqow+TaaqOQFTHHhnXMGzy5vS1vHu3reQDTCTJDBqCN7ulpMF/2keKoAnXnWv9YfcLlo0CdYv8xFp8GHHyeBv52aXyFY4pk+JUOEbjpEX99xNgJGAPwRHLn/Wk6AXbHzx7TpiaKFsD7938Sl1Z2E2ylmbx/OToks5BYjWMy9pPpX3vwGjcH2qIUPGh+MCrS4l525rtSvi70TfwR7hT1Dv1mxeN7lJEIM4k/20FoqgOeFXwGQbN1rQUv+vcrzpn2SWEIsELn3fHrcNLxXt4Cj0WDFgRZ2+Mg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Oleksandr Andrushchenko , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Julien Grall , Stefano Stabellini Subject: [PATCH v7 12/12] xen/arm: account IO handlers for emulated PCI MSI-X Thread-Topic: [PATCH v7 12/12] xen/arm: account IO handlers for emulated PCI MSI-X Thread-Index: AQHZneJbvDOlnUhO1ESuNpaA9WRe9g== Date: Tue, 13 Jun 2023 10:32:30 +0000 Message-ID: <20230613103159.524763-13-volodymyr_babchuk@epam.com> References: <20230613103159.524763-1-volodymyr_babchuk@epam.com> In-Reply-To: <20230613103159.524763-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.40.1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6520:EE_ x-ms-office365-filtering-correlation-id: 93648c78-a2d1-42e6-a0da-08db6bf9808f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lWbsTwkfpB0lf+0cGsJwGc7vYQ3cNe4OvC0vYrkrIorxFut2noVaJYl3VrIiHkVwLb2oUgD25v6XTg2VU4m7nw3uKKAiknWtlwHeocH5VnEDl2Aec+r48W9vs9MGS6AdN6Hk/OgjjbxKyArtRha9snKPlAnM+fKBFe1Nv4/M69RC7yxjyqI8MTogppTOJi/qCuIEjbvjliWFSBBnkSOVRMXh4LUH9kgXnOM/12EnmB6NiIwnuO3PDMi8Jsin/6xlA7Sjw/SU0casuQ74ymnqYUbda39SVhBe4uVVMJX2Q+NoGvvV1fU7H5WXFbY+AsQqjGABO64lpmae0engs9ZvwP/jRUSOTtxiV37wklKmi6e31O/qDtN+QppLkp73Pw2A8dCwXNwFr1dVB9yWCXI5I/aKk4+c/9vZ1eWJibmVPGWgLM5VKY3Cp9crZmSewWQI7hWHOEgY8iChnGEQhv15C8s+2Tj5pzjN+SWZS1BwEJOTgz7VDpDPx9Mc7AsiI+nxJv97Z7LYjx4o2t3gRARjs1hw2Nv2P9R1dclD22/qVaUGdjmpd7DloQM2ShzVJRddXbOQfybq+bI1xXb71NUWO+4fEXhoZcrHrGV8SKuX4/rtNaOJG2VSvX7pXgv3656c 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:(13230028)(4636009)(396003)(366004)(136003)(346002)(376002)(39860400002)(451199021)(6486002)(6666004)(6512007)(36756003)(83380400001)(2616005)(38100700002)(86362001)(38070700005)(122000001)(55236004)(1076003)(6506007)(26005)(186003)(2906002)(15650500001)(66446008)(66476007)(5660300002)(54906003)(8936002)(8676002)(316002)(41300700001)(6916009)(4326008)(66946007)(66556008)(76116006)(91956017)(66899021)(71200400001)(64756008)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?NyyV2/MHy1jlM7ZCIv7NPCj?= =?iso-8859-1?q?7eBD5RFlf/YEt80+6EFgSKnhtpZsiyhh31dJFTPDLkgpkSmWXjXQnvxf9aEt?= =?iso-8859-1?q?fic5FmOBYEPQU2O/0vQmHWPZLqL5VHIaVhgjy3L8K6Br1aGtsikDPk351aG5?= =?iso-8859-1?q?4SmcgkXIkxgGDsRztlyE+IduWlcXRRecNllxdyAUIkwQmY3GiuOEVjgMC0Bl?= =?iso-8859-1?q?yfCqM1A7eCe9lRKkbvfaxFoLVm7lkZ69pn0GwTA5LgiktwTNpLVIOVLpggze?= =?iso-8859-1?q?8YNLHdFf4PkqIvlAU3IBfAjGwljI4wzfiWC8IoLN/8AwhvhNhPmuXJHGr0gk?= =?iso-8859-1?q?smYnJjyOMFPUrdwkgoOYTs8CBETNIWF9mdOUnQXE5uJ3uk65gj2xEE53Z4Rj?= =?iso-8859-1?q?fzdrdW/dBvwY8DmFP9/eTBfc7qMjXemIKSVkrm4/cWpZoSlz1gcYjcO3kWLk?= =?iso-8859-1?q?LrLD5YvE3Hd9xQkIn1h8G1LbIhB0hO/+7dCLc+D0JNFl2d25RZbMj95cqHCK?= =?iso-8859-1?q?eUMQE+1dMxD2aDklB6Hs0mWhyrXzDE8It13hbIiCaTsxZX0ZnwBA5pleDW60?= =?iso-8859-1?q?CGHbY37ISD7upSilXQ65pjH/5mtgQ8xA7a6c2Q4B55Few45y5xE0ANFAQJF4?= =?iso-8859-1?q?+SDQBKBaXtJvSVmYbTLFwzLu4mkDMer8CjF/KBw7JFPuM9kLURP82QMXo3OY?= =?iso-8859-1?q?YlUriVo6iRDCoI3jzQQESfiqmzSk3p5dz4xV1PG8qlhOYF3hmoYLSJ+ttbiN?= =?iso-8859-1?q?amHGCkWzKBgZDgoirgm+YUJJVIVzoRgOVufEhSWEnzgVgmJvcLhCOC4Dok+X?= =?iso-8859-1?q?d4ZQK0g6Sd4AMq+Wy70/kcUFFkQGAt9fGBs5ZZaheAyBZmTUfRQ/+jRLAqf+?= =?iso-8859-1?q?v7HFbb5MSGulHoNqmEO/5XOELo1qgmHNW3xUx4BDra5TSPKfDYcLtmoQL2gM?= =?iso-8859-1?q?J8paqf1IG3uTTPQ2rDL80P6F8MRNM3YhpJSL36io9rGRLLBswpgjcr/Xgpkf?= =?iso-8859-1?q?ahSfqUYrnilRuqVdUCtSJeLEzGkOn2O+XjR7OVo7C+hAcLFVDJARPc/uc4nO?= =?iso-8859-1?q?cLyFrZN+DuDBYFBmrNpfd6DximaVjrCl+GIrTRLjGCrl7NyjSPm04btJB8od?= =?iso-8859-1?q?GDVOZ87HI7PKuxo7V052CXvHun85aNiax5k7IuTEklJILTDeBjorCIdeNof6?= =?iso-8859-1?q?WjLVio1zi5m4Adcs6Nx570zCZJSlfq7jxSvTfab3wxr8W6dcY9V2BJrGQLCz?= =?iso-8859-1?q?funFiZPxtj4QrmAMYw//QMY1piqE38StUxS2qDTGIURVdHZSepT2seSwWbQU?= =?iso-8859-1?q?6AkaEwMScL56HyUTVDoOC5+1YtK81rbiWVm2KJNZksS2AWA4uodOTqTjpi+I?= =?iso-8859-1?q?s/Wu2RaWG502u5MMvN47yLBXqvIGCm2sYCuETtXDtIwP+4LLk+QSZ2sxLAiO?= =?iso-8859-1?q?JVbPNfShWqrfbLRkFqQO3OlWmBGr02MIQo/vTI1ZAd+Qd/HdD7Iv5V3IjG1a?= =?iso-8859-1?q?rrc52XH5TBY3R3l92dojBz+O6ac7LtZmjNuv1D6HBx1bcbQrlRA0Q96Zr5F8?= =?iso-8859-1?q?mIR6JQCOue8F7r/8W49kacmfk2ZJbBr0M3Uk4xDxmqYThAcJGUpJ3i46lRZN?= =?iso-8859-1?q?8mG9g5wvYGlqkkBu80erSKuSueNvbfHKuMRuFYQ=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: 93648c78-a2d1-42e6-a0da-08db6bf9808f X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2023 10:32:30.1747 (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: U0gSiYoqumL0WDtvhm0SLwkKqpViEp8Ntc/xB58/1JxXunFu5UwCSgXri3oWOcDQ3dhohI2poeZEEv7Pa3fgvLwTT2aX5Y/IyRYF3eO2a+c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6520 X-Proofpoint-GUID: F0yMd5SMzxh8siSmnZGICctVgUdT5aXe X-Proofpoint-ORIG-GUID: F0yMd5SMzxh8siSmnZGICctVgUdT5aXe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-13_04,2023-06-12_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1011 mlxscore=0 phishscore=0 mlxlogscore=599 priorityscore=1501 spamscore=0 bulkscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306130093 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 d60913e532..7499a1c925 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -122,6 +122,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; @@ -142,7 +144,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; } /*