From patchwork Thu Oct 12 22:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419852 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 DF93EC41513 for ; Thu, 12 Oct 2023 22:09:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616069.957816 (Exim 4.92) (envelope-from ) id 1qr3s4-0001yR-Fj; Thu, 12 Oct 2023 22:09:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616069.957816; Thu, 12 Oct 2023 22:09:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s4-0001xq-63; Thu, 12 Oct 2023 22:09:32 +0000 Received: by outflank-mailman (input) for mailman id 616069; Thu, 12 Oct 2023 22:09:30 +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 1qr3s2-00016v-Qw for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:30 +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 038fa9a2-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:30 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml4008371; Thu, 12 Oct 2023 22:09:18 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:18 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:15 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:15 +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: 038fa9a2-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HCVX/2lqseYlqrTNVPwrAyVuvhlRLLg/hegDl11cpLjnCiujJxRxVa19fu9nc4Wlf8TQVU2jh6p/9kkDyg+v2HFohG1O8fxVZiIBQ/0DUZAVdM6HKa6IQNrFobPgtsgtBrxUROhBsS1f5Tn1wz4C0QqSvOPfKd24LMV/02BN1tl83KR0Y7/5TzHSN7zX53hD/BI5UZuLvJfMlPmfBOHrflLZIE0Zg7ZsmE45t4WMkhCDv5mwv4W5VpUe/i0yULIx4BqFZ4rwTqwk8wItndi/ZIdG80MwFTVkYpb3s0cc0hAo7GO+XpfnOpX0+ppEhuJdwCdOjwmpbvJS/26BNTO1KQ== 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=nUbdmISXespujyGMhnqpZyFZ9IBb/MEFeA/aVd7WW+s=; b=mVCvwanMMS3gWHTNPG5cMEQziX3sJ7Qk6d0+Uz06dHftVlsJ+tRVBO5MZ8c8ET5ZybR38oeJ0Nj1QiaE81q7Epz88i18m9sfgnpr/DoqYvaciV7qMR7K/eA1i0uXZLM9VawvTUYhAHFNb2XSWT26LIdhdkINPelNGounp/R28V+JGtY/u/vvnCzgXFsYwjnlIYGEWdP4Lxot5/znc415bBt2FPKApnSDm/ZxeDeA4B6nfp0OkDFghTaZnDQJmelbxXd0BdOqS4RJUIFlsZzs5tbZy3NFYwqaseOgI3cZlp61rdoqMiFvOVzZvrkWvWMiN6GaL68HSFgqHJPHj4kHZQ== 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=nUbdmISXespujyGMhnqpZyFZ9IBb/MEFeA/aVd7WW+s=; b=lpPZlM1yKu+nbUsMNnz+qLHhrt2nrbr73jEJgtgsh4XGBjLJvwAggbGiCJMg5/Uiufk6pZqvwKrGMJqLE627/TOZ7WpPjZNbzxZSuxUULb339FBBAJMwJ/RrSX6FyFsJeCRpw3Oo15L8nVFRlMIVMDYR4VgWXKLzS9rvKV/bwyClExpRwy46vytiJDgd9/yM2YVW/R/6MNseSvGvqbKU/sW7QGXkxnI7C/b7wX/37rN8ZGVzm1f1apLfdCkkvVuV8QBDCGRkFvFQPTzbJIIMlJDhMesX03sge4y3xEDjHCfmZcPx1/Pw23O+X6rQhJAypzXeLPEB12O3Bw5ojoWQPQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , Jan Beulich , Andrew Cooper , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v10 01/17] pci: msi: pass pdev to pci_enable_msi() function Thread-Topic: [PATCH v10 01/17] pci: msi: pass pdev to pci_enable_msi() function Thread-Index: AQHZ/Vi8+1vtmDC560CdrPPIvL4UuQ== Date: Thu, 12 Oct 2023 22:09:14 +0000 Message-ID: <20231012220854.2736994-2-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 9385d259-8333-464f-e543-08dbcb6fdf48 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: if2bpCTT6R5djnnp24r325/p4Ni3LFzDfiigZrGdmD2YfbpCcbzfA1AeSgODRB46Cp9VhdRVSWdBY3yn0j0x+X1/1aFL6IA/QrxPQjsKDrmhFcmnMrs2QsyjjMYlT8ho0QK6Pl+uZgDnT890xiLORbJAuQR5aWAnJq0Lbb9gtEVvyQMzQ5HeW+e018z/Bn3+JmNAky6dr45tKN3lHP5m54bVEvjrhtT7E6BQEevs2oh3L7IakkoDZh/Lqy02CdzskzvTAQb2KLAtZI2RAjyCFVXa4sU6vnt0TzJnz/BJLWl+/ialLGfQqui6WDNPCRhZzuNR3lV+0KaVLKDxH7wzWFtBAvKafen5yRAaeGh+wVPQmKdUJALAj8iU0l/46JGssLLO9rO0KNC6zvRgEOrP0Y2BU9TwN5BdmxI2v4kSDtBTFdODlpvn5l4kGAEIFOX0tAX8/WQEq3WWS0VDcYQLaDb0LDpb9Ga0mATl/Am+J/i2SwJxu5ix7rry4NuX7SC8XnnbZE9lD3+hZR60cd/GK98ZZtGLjOhTRMOkXJjFu3HDzUXHWkBaNdzYRDJY6gQFezGWKIyIh3oC+e+9L+GOtclGg/csBl4afaginXoy7wiiAHEox9lCgSBasbZre+V4 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?/Iz9Pg2fBp+lj8rwpOs4fb0?= =?iso-8859-1?q?hCEImxuUhFtNj0OfmpkEto3yyybeUeEt0iKBdLc9OAmCQjeRcNyxLnvn+3hc?= =?iso-8859-1?q?Z3DqC7355PNn7SA2I9oDK7uIxgFhZht4zDgH22CJNBwQNqXQd6/m1eO0Ysc5?= =?iso-8859-1?q?MWmI9GI3lWh9gEJ4CsM/5B1C/iJzIrtxek9qHAc686OerriC15KSJjQgNe0L?= =?iso-8859-1?q?MrTO5fLJ9UfN5CpLzlRXDBtLttFsHRgF0kZkuaBtLxzUUq0aijea63ugmydi?= =?iso-8859-1?q?UY4jdxHONdarS/yjdw0xDTZnIKIrcziGi5Vy3g5hHSsTG7qHBFar1Ux/DHDL?= =?iso-8859-1?q?aBuVdir8e17CihXZtjLDCQE7WnvHhBAupybIo/a6phdkUnXiIscew2n4JbrO?= =?iso-8859-1?q?t+hX3xeOwNRCOG56SCFxxo9oygrciHIsH4IbrLV8GDOE3VUZWair6oj3+Ztj?= =?iso-8859-1?q?3Wh4M+Xxeln8de82yZt7Dmiv6sRr/4IIyIQ3VetH2m5xbQHSJPDbSH5TFilV?= =?iso-8859-1?q?++8hCSZlyxd6dN0uSgQclDe09EOA0SEMNLmnLNbH5OxMLxNqaZFvnmy9ZU9z?= =?iso-8859-1?q?Rjfixxkt/nFGiC2WTf5glpCtzSwjsLWMjam39dLxep8D5tOj/x0xALN1eexC?= =?iso-8859-1?q?9Ump/dz4EyrQ1a/KBBDPRfgTkk7aPzVoo74OrKvQLbhLDXbv9AMsbBL3N9l1?= =?iso-8859-1?q?UHXySM9JNDMTHKYr66UUFBXTbar7tO1sxacqGX4NHASZHjLG16IuaWoC5dGI?= =?iso-8859-1?q?cj3BEx+8YB0jyOXpvbV6Rit6HavvNFlFd4uwJm0pjK/k3ZnL6xHMR5widCV1?= =?iso-8859-1?q?8q2P1sva3na7L4Ccw6bi04ODWe7hBYs0kjTVy82zWzxeg2rSNLeM7PCzp2x3?= =?iso-8859-1?q?zyqVqI0BXRqUnpFad0p4BM6U+0eqPdYTTmLXz8xPv2JO+7c5jB7FKcfXKKkv?= =?iso-8859-1?q?kBIPXYhsKAwS7GhNUNVDgLT0tMOsmJMUq6OFC0z75astU5w7pWbvinkmSwSl?= =?iso-8859-1?q?V8KNv2OUEnVsvJ0Sde4kxw1NZ1Et+Ef3saqko0agapPCL3uG8qq5kGETQv70?= =?iso-8859-1?q?O+e6o8mwLcxr11xn3W39jgkPHTG6Rq3HwPqUYSMlgo16SwKFo2BZPtzZqKcP?= =?iso-8859-1?q?McBctozf7yuS8TgzgTd31Snuj0ZruPVMeFadp9Aoe4bITwHlumvClCW0kvCG?= =?iso-8859-1?q?zm6VYNeH38vCatW1M30//k7LnBCnolhH9zUfulXJwTBU8gpJF4D3UbzLJMLe?= =?iso-8859-1?q?MbCUM1c9cCay9j18/EOyxY5lyOEiCzPu1xSlKiMnXSGK16Qi7jbjkeoG3aFY?= =?iso-8859-1?q?i/HeOQOAa0NrRfT5rlOkyV3EgelGzOk6LVirEpF+7Fu7idGNoqZRBAeK6G3Q?= =?iso-8859-1?q?/lmvQqVq13lbJbsZB9xs461rw6T3Vx9f8061z7DVxIWVPkqZP6FEzdarBH5u?= =?iso-8859-1?q?tkxaywjMoCLhEpjj5aA3ydru70Cy4Kb59MFTJaKSFHilOu5gyhufBfndVNa5?= =?iso-8859-1?q?e1/Tt23tx4SHuV8fU0vD34Y8DnHxQicv4IGr6ahSTNbCfuFOYydCZLmKOHAS?= =?iso-8859-1?q?cowx8gkeq4etCOQq1R7TBkJOD6PbLI8ASkcxzdCuafXvmmfcdsfioOaivI82?= =?iso-8859-1?q?t37xQKAFX5Jf3UMIxhE3vB8EA2eR5iVxA8XV6QA=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: 9385d259-8333-464f-e543-08dbcb6fdf48 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:14.5076 (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: iK/voxAwtiw+7wIxak+45MttHbuarMe2lCVNroGC85TNgBLTalS7ZH/HkIFdyKHF5qkfyV9zp6G9FYJE8rhzfwleU+v6RP1ifS9rR/XUb40= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: oWPZhzSBKvDFZcijyL9aFYhlavcIPxAL X-Proofpoint-ORIG-GUID: oWPZhzSBKvDFZcijyL9aFYhlavcIPxAL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=574 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 Previously pci_enable_msi() function obtained pdev pointer by itself, but taking into account upcoming changes to PCI locking, it is better when caller passes already acquired pdev pointer to the function. Note that ns16550 driver does not check validity of obtained pdev pointer because pci_enable_msi() already does this. Signed-off-by: Volodymyr Babchuk --- Changes in v10: - New in v10. This is the result of discussion in "vpci: add initial support for virtual PCI bus topology" --- xen/arch/x86/include/asm/msi.h | 3 ++- xen/arch/x86/irq.c | 2 +- xen/arch/x86/msi.c | 19 ++++++++++--------- xen/drivers/char/ns16550.c | 4 +++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/include/asm/msi.h b/xen/arch/x86/include/asm/msi.h index a53ade95c9..836c8cd4ba 100644 --- a/xen/arch/x86/include/asm/msi.h +++ b/xen/arch/x86/include/asm/msi.h @@ -81,7 +81,8 @@ struct irq_desc; struct hw_interrupt_type; struct msi_desc; /* Helper functions */ -extern int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc); +extern int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc, + struct pci_dev *pdev); extern void pci_disable_msi(struct msi_desc *desc); extern int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off); extern void pci_cleanup_msi(struct pci_dev *pdev); diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 6abfd81621..68b788c42e 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -2167,7 +2167,7 @@ int map_domain_pirq( if ( !pdev ) goto done; - ret = pci_enable_msi(msi, &msi_desc); + ret = pci_enable_msi(msi, &msi_desc, pdev); if ( ret ) { if ( ret > 0 ) diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index a78367d7cf..20275260b3 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -983,13 +983,13 @@ static int msix_capability_init(struct pci_dev *dev, * irq or non-zero for otherwise. **/ -static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc) +static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc, + struct pci_dev *pdev) { - struct pci_dev *pdev; struct msi_desc *old_desc; ASSERT(pcidevs_locked()); - pdev = pci_get_pdev(NULL, msi->sbdf); + if ( !pdev ) return -ENODEV; @@ -1038,13 +1038,13 @@ static void __pci_disable_msi(struct msi_desc *entry) * of irqs available. Driver should use the returned value to re-send * its request. **/ -static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc) +static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc, + struct pci_dev *pdev) { - struct pci_dev *pdev; struct msi_desc *old_desc; ASSERT(pcidevs_locked()); - pdev = pci_get_pdev(NULL, msi->sbdf); + if ( !pdev || !pdev->msix ) return -ENODEV; @@ -1151,15 +1151,16 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off) * Notice: only construct the msi_desc * no change to irq_desc here, and the interrupt is masked */ -int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc) +int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc, + struct pci_dev *pdev) { ASSERT(pcidevs_locked()); if ( !use_msi ) return -EPERM; - return msi->table_base ? __pci_enable_msix(msi, desc) : - __pci_enable_msi(msi, desc); + return msi->table_base ? __pci_enable_msix(msi, desc, pdev) : + __pci_enable_msi(msi, desc, pdev); } /* diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index 28ddedd50d..1856b72e63 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -452,10 +452,12 @@ static void __init cf_check ns16550_init_postirq(struct serial_port *port) if ( rc > 0 ) { struct msi_desc *msi_desc = NULL; + struct pci_dev *pdev; pcidevs_lock(); - rc = pci_enable_msi(&msi, &msi_desc); + pdev = pci_get_pdev(NULL, msi.sbdf); + rc = pci_enable_msi(&msi, &msi_desc, pdev); if ( !rc ) { struct irq_desc *desc = irq_to_desc(msi.irq); From patchwork Thu Oct 12 22:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419850 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 C2AB2CDB484 for ; Thu, 12 Oct 2023 22:09:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616075.957881 (Exim 4.92) (envelope-from ) id 1qr3sB-0003xB-AU; Thu, 12 Oct 2023 22:09:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616075.957881; Thu, 12 Oct 2023 22:09:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3sB-0003w9-1X; Thu, 12 Oct 2023 22:09:39 +0000 Received: by outflank-mailman (input) for mailman id 616075; Thu, 12 Oct 2023 22:09:37 +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 1qr3s9-00016v-2U for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:37 +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 0694ae73-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:35 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml5008371; Thu, 12 Oct 2023 22:09:19 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:19 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:15 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:15 +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: 0694ae73-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UXISerJCozR/cSwWSnZVN/L+9TPx2Rzj4hJ/5MfQZS9Mtij8+zqQQ/Ulb+5kz9ycTTTC5E+fZ6T/32gd8OvFZgqLUpSmn2rWK/Ag6o/QqUpey52nbcLFVKShUNOTrC9ZNX2pcTBUmz6vXlzaSbl/gpt/208IXIk5aMiFCeqIy0WzgXYhvG9DncC18g2LV9uZIIhX4kXDBpzaVtGr2lgsnQT6PV31cgIax3fmORGBpeeanKD8Wm5uRVg07H3HYmGzjfTp6cX7B10FvmU63REt5veCHJtJUdMrOV5Hl/qetV//w1pOxVmJuGJOqp1f+Hd+ctG0RDX6pStzHC+ITIjrvw== 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=mKMPqeeqAlF1usHbA+jD7EzzRAsY3Lp/fUoH9/LNTBQ=; b=N8a6gYJ7S6sOVVs6/KN0tpX4sFbJYPhiZPgwRURtmP34r6FmFEmY4E3ZVy2OeRnx1qE317DEBTtOSFW9SlWpb8H8na6Ht35IlLnQ+AnUpRV2V8AXkgZzvPTjyHE+LBWdR4g3VV/jNH/0ku5dtg3JlQDGB4B3inA/t1uPWOYB3RUZW8vgROI3X+zbUQF72wrwS0uAPFyM1gECI8z363ip4OwR1ATONba4U1LcPBDSIJYNo5C+EP2Tg5qqawY6g3og6Mp4o4/up3QzshHbCZ7nu4raW4HoL8rOTuLkZFCvhJPWT0Mh8mtb3As6qaw+avbnJ1qaoxL3COCkLWShZqFcVg== 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=mKMPqeeqAlF1usHbA+jD7EzzRAsY3Lp/fUoH9/LNTBQ=; b=B6TKsS8Q7pFbjbb/rI8gVx1rx4CHgfALbJVTqKkmyCXCgjt093jxFpUFQP4I6IZnBShg0yExtaRP+b5nvqEduPuKyOZ4k79HBaZdQEUfHGqfUORQU6YqnQMAvTAswzUZ4Qn9vEzonFAY1BtFcVKyHja0ZTe+Xzo8+xv1sCTnsLnCFxWQWeAgPMTmTr1rfTJ/Fnq49Z8KU/VSUCTduizJCV6KLMZLGeiZU2buEFM2Mz7MS6wG5SpXUSZ7JDKersmEyYsECrGIhDwAcSEOshSm4ddafkU3R9FtP0afUHnERQEx9kvzh3HYvjHwKafUeTXacOUPRvaiMgqXBBJEZHQYJg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Paul Durrant , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= , Kevin Tian Subject: [PATCH v10 02/17] pci: introduce per-domain PCI rwlock Thread-Topic: [PATCH v10 02/17] pci: introduce per-domain PCI rwlock Thread-Index: AQHZ/Vi8UBjbIJy6YEm3bNbn9ygUkA== Date: Thu, 12 Oct 2023 22:09:15 +0000 Message-ID: <20231012220854.2736994-3-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 66e37b67-8e0a-4acb-e154-08dbcb6fdf86 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: CKd8MLleDT85CFN7KIFs/VrYxxMKc9ul7g+aJs7LWbaof7T1wkfU1RdjoIYbXL1aW5l2UJKHOeL7t0cwPe5CElKu2SwhgYYeUhzKgxWmAF9OxyAwmHVzSL+iMSNUyFGAk3ybZHGg+W/6xNpQVjhuDbc9QmMGPBcLnWuFqvAMNd6CMkM5IZY/qlAv+3WJcRZIxiikhtNvGzYf7jGCaCG17K3dX6p35o7+Itn/oEKyDVg7QvDhEzX/K3fbCZc6mc//CWKJotZyJC3YpQRFgTmT/OXfJKePJiJxEcDt0E5XiUjq0q6PlxEoJvdMhdE+E2F/3l4tVmWJxoBuZyKpyryokeyUA5rFm8CDLUJHPNUDJT8/DbNHsftZIt4m8PhyY6d0yf4eoo+Fgl0GAlrAQfWn6GnvCijcuwF3Ocx+ytaZ4ABJ2D/LseuElzEzn2DzKsbCc60k75LLzqkjAFdYNVCTfQxA4HI0kgh8WvwgvOlZ+FQAtAxQDj1KaUzT0p9jxBUcFw4NsYHJJl/STgflgZrVpfSG9FnyGd8Tw5QR57lJ3g4ceBGzJdj2tman03EXVz13PazVcXT0RH95gHgq3S1cWbaii8AnupLFCZxv8L2v/eZxdkkuwvwzXOE+jzlj+BFI x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(7416002)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?hD//dhkLidD2lqFsjZCIbiDE05yv?= =?utf-8?q?C11IO+Uzo44MHgxhssVZ/3Bq1Ap038yHObW6M9pYnzelOCCvcvwRqc/mmWEkRxy+i?= =?utf-8?q?kPXALI6syRGiRjxqRboUM+ztrG76P/EEzqAC3J7R2RtPYBURazmhV1iGjQxX9z4MR?= =?utf-8?q?+Z3NLEThDdHdOWUjOC/FKM0Vlny2+adUmm+kQY/HLb6X6GOgdUvd9TGJVwZJjE0ZO?= =?utf-8?q?dG2DbkPxBfj1h6pfREqo4MGXKTJYhqxIWTgdQziz4aUSpqeLCN27/rLdgmZWB2Bd8?= =?utf-8?q?NxtyWYXff3uu2e2mRQf+MkeJ882OrPmh+tgH/KDNz06oShuq8WgjR8t+RnQNZtJme?= =?utf-8?q?oBn43+0Yxp823VzCH3qzF8hyVJo6w5FB7D6DfvwXMDJzHMj2c/Bb0F9EbHPnxKs83?= =?utf-8?q?tJ5HHxva9Oix0Y7pzbqaRFgUB2Iu9SN/jgJAdmdgt4YnoYWB9zWIJhz2l/bFiO0/W?= =?utf-8?q?/bT1T5qTCtEFeKx9mSrp+a/8Y6YtMo6blsWFk1jhgZ94sr9eqET4thWcURF1bzmOR?= =?utf-8?q?VJiI7CLA1q7dc0sSmEyU++/udm6SvivtJGOlYRMmBEbUOzLd0jDKF/o8bjSzWUe2Z?= =?utf-8?q?Fvex8YWkQs/Ov3t+znuocRslJdn+VZfWlY+0yqiH52zKKYWQHinbZf97EM6l1aCLf?= =?utf-8?q?yhS3xQhssRt4rsD0IrlsDn8/n9t/LxgdSc7Iww5ZEBZzBOpISNPlribt2CdtupFFB?= =?utf-8?q?6jwQrd7imeAEnzga/EJmdcugn6EpZAf/SjeYq3wB6Xu6DSt/aIiSn4x0wjrBTpXeo?= =?utf-8?q?xtsS2O6fqUCFS26aDGMHkJIWHIy1V4SXDYuJdM4FSgTc5ogDZ2vmMuLY/6TQ6V5Zd?= =?utf-8?q?61EYGCNgHGkEVONwXO3cRaUDo0+qWnLReFnJa1n7QogaatXz+9YQejulmFL04tvFb?= =?utf-8?q?m9syeUTJQ2A0EHpR5fx7XdowisGxUo8XrMmxKK0bNpYLdhzhQB6OHjuIpjReb2Ppn?= =?utf-8?q?osQi5qdwKZtt0qZwWZQ3UZjB5MtoL/lmppwUxHFFMFt08oOC6D2xJIjg+d8fUowmT?= =?utf-8?q?YiY1WIWkdmNhIFsHyMXbkcq2VlrgPUvy+32xo2RsO1/W/pkPQ2amZaXbnLu+ijjgZ?= =?utf-8?q?zHq+jm/SLNi0es6cIA8ZLwTmmgCnyo7XM8YZ5N2QiLpNyTpzIYuJ4/Qm2SvOMAeHw?= =?utf-8?q?rbJ7rHiEHccen6iw2t7/4xOIRdu4qXzpUUmNQC6NmlzozfY2vk4IDkq8Fj9TLxOUX?= =?utf-8?q?upVS+ztt201O1QkvC3kK6bi4NAMRk5lgVMlc1jvhBCpC/QOE3zqUPyFgUGPNnz4QT?= =?utf-8?q?G7SIMaCWZg3qqn6R/yo1rHz3c2nXyXcg/DWKPqpDuJBGXSOBqMaol9Wg7l6+fTgYP?= =?utf-8?q?du6rIl0DFRgGzgXm8q7LU9D97PlZFB45DwsDVOInDQ4VaG/pmH6WzKyWqUNPUDJYe?= =?utf-8?q?aw+91Ynl5/VNYTM5zEP2xKWlRjsLZdT9YGmNhJo+WcI5XAKtByu+riiPFLZtbC/+z?= =?utf-8?q?+oDc5e1SJMvketjuLFMTOCkUKdqPpcxLoC/uF8MDU1WqsPbUvvnaqkbKlGM/pPoZl?= =?utf-8?q?YIZzo0NnJpBN5KvIAGvtu3/G8DN5HKfKgA=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: 66e37b67-8e0a-4acb-e154-08dbcb6fdf86 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:15.1897 (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: ax9t6PRfM1NWgQR+g8sQK1eHftN+s5NKCNACQY0wFqzIxx3j4UVDorCtKLU052VCFbJgccOln4irUyZAOvTlyC4xNZlu2eSlfF+/ovVBUuQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: mEd38r7guj_3gAoyQaBuv4MEc-YoAHxc X-Proofpoint-ORIG-GUID: mEd38r7guj_3gAoyQaBuv4MEc-YoAHxc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 Add per-domain d->pci_lock that protects access to d->pdev_list. Purpose of this lock is to give guarantees to VPCI code that underlying pdev will not disappear under feet. This is a rw-lock, but this patch adds only write_lock()s. There will be read_lock() users in the next patches. This lock should be taken in write mode every time d->pdev_list is altered. All write accesses also should be protected by pcidevs_lock() as well. Idea is that any user that wants read access to the list or to the devices stored in the list should use either this new d->pci_lock or old pcidevs_lock(). Usage of any of this two locks will ensure only that pdev of interest will not disappear from under feet and that the pdev still will be assigned to the same domain. Of course, any new users should use pcidevs_lock() when it is appropriate (e.g. when accessing any other state that is protected by the said lock). In case both the newly introduced per-domain rwlock and the pcidevs lock is taken, the later must be acquired first. Suggested-by: Roger Pau Monné Suggested-by: Jan Beulich Signed-off-by: Volodymyr Babchuk Reviewed-by: Roger Pau Monné --- Changes in v10: - pdev->domain is assigned after removing from source domain but before adding to target domain in reassign_device() functions. Changes in v9: - returned back "pdev->domain = target;" in AMD IOMMU code - used "source" instead of pdev->domain in IOMMU functions - added comment about lock ordering in the commit message - reduced locked regions - minor changes non-functional changes in various places Changes in v8: - New patch Changes in v8 vs RFC: - Removed all read_locks after discussion with Roger in #xendevel - pci_release_devices() now returns the first error code - extended commit message - added missing lock in pci_remove_device() - extended locked region in pci_add_device() to protect list_del() calls --- xen/common/domain.c | 1 + xen/drivers/passthrough/amd/pci_amd_iommu.c | 9 ++- xen/drivers/passthrough/pci.c | 71 +++++++++++++++++---- xen/drivers/passthrough/vtd/iommu.c | 9 ++- xen/include/xen/sched.h | 1 + 5 files changed, 78 insertions(+), 13 deletions(-) diff --git a/xen/common/domain.c b/xen/common/domain.c index 8f9ab01c0c..785c69e48b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -651,6 +651,7 @@ struct domain *domain_create(domid_t domid, #ifdef CONFIG_HAS_PCI INIT_LIST_HEAD(&d->pdev_list); + rwlock_init(&d->pci_lock); #endif /* All error paths can depend on the above setup. */ diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 836c24b02e..36a617bed4 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -476,8 +476,15 @@ static int cf_check reassign_device( if ( devfn == pdev->devfn && pdev->domain != target ) { - list_move(&pdev->domain_list, &target->pdev_list); + write_lock(&source->pci_lock); + list_del(&pdev->domain_list); + write_unlock(&source->pci_lock); + pdev->domain = target; + + write_lock(&target->pci_lock); + list_add(&pdev->domain_list, &target->pdev_list); + write_unlock(&target->pci_lock); } /* diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 04d00c7c37..b8ad4fa07c 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -453,7 +453,9 @@ static void __init _pci_hide_device(struct pci_dev *pdev) if ( pdev->domain ) return; pdev->domain = dom_xen; + write_lock(&dom_xen->pci_lock); list_add(&pdev->domain_list, &dom_xen->pdev_list); + write_unlock(&dom_xen->pci_lock); } int __init pci_hide_device(unsigned int seg, unsigned int bus, @@ -746,7 +748,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( !pdev->domain ) { pdev->domain = hardware_domain; + write_lock(&hardware_domain->pci_lock); list_add(&pdev->domain_list, &hardware_domain->pdev_list); + write_unlock(&hardware_domain->pci_lock); /* * For devices not discovered by Xen during boot, add vPCI handlers @@ -756,7 +760,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); + write_lock(&hardware_domain->pci_lock); list_del(&pdev->domain_list); + write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; goto out; } @@ -764,7 +770,9 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { vpci_remove_device(pdev); + write_lock(&hardware_domain->pci_lock); list_del(&pdev->domain_list); + write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; goto out; } @@ -814,7 +822,11 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) pci_cleanup_msi(pdev); ret = iommu_remove_device(pdev); if ( pdev->domain ) + { + write_lock(&pdev->domain->pci_lock); list_del(&pdev->domain_list); + write_unlock(&pdev->domain->pci_lock); + } printk(XENLOG_DEBUG "PCI remove device %pp\n", &pdev->sbdf); free_pdev(pseg, pdev); break; @@ -885,26 +897,61 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, int pci_release_devices(struct domain *d) { - struct pci_dev *pdev, *tmp; - u8 bus, devfn; - int ret; + int combined_ret; + LIST_HEAD(failed_pdevs); pcidevs_lock(); - ret = arch_pci_clean_pirqs(d); - if ( ret ) + + combined_ret = arch_pci_clean_pirqs(d); + if ( combined_ret ) { pcidevs_unlock(); - return ret; + return combined_ret; } - list_for_each_entry_safe ( pdev, tmp, &d->pdev_list, domain_list ) + + write_lock(&d->pci_lock); + + while ( !list_empty(&d->pdev_list) ) { - bus = pdev->bus; - devfn = pdev->devfn; - ret = deassign_device(d, pdev->seg, bus, devfn) ?: ret; + struct pci_dev *pdev = list_first_entry(&d->pdev_list, + struct pci_dev, + domain_list); + uint16_t seg = pdev->seg; + uint8_t bus = pdev->bus; + uint8_t devfn = pdev->devfn; + int ret; + + write_unlock(&d->pci_lock); + ret = deassign_device(d, seg, bus, devfn); + write_lock(&d->pci_lock); + if ( ret ) + { + const struct pci_dev *tmp; + + /* + * We need to check if deassign_device() left our pdev in + * domain's list. As we dropped the lock, we can't be sure + * that list wasn't permutated in some random way, so we + * need to traverse the whole list. + */ + for_each_pdev ( d, tmp ) + { + if ( tmp == pdev ) + { + list_move_tail(&pdev->domain_list, &failed_pdevs); + break; + } + } + + combined_ret = combined_ret ?: ret; + } } + + list_splice(&failed_pdevs, &d->pdev_list); + write_unlock(&d->pci_lock); pcidevs_unlock(); - return ret; + return combined_ret; } #define PCI_CLASS_BRIDGE_HOST 0x0600 @@ -1124,7 +1171,9 @@ static int __hwdom_init cf_check _setup_hwdom_pci_devices( if ( !pdev->domain ) { pdev->domain = ctxt->d; + write_lock(&ctxt->d->pci_lock); list_add(&pdev->domain_list, &ctxt->d->pdev_list); + write_unlock(&ctxt->d->pci_lock); setup_one_hwdom_device(ctxt, pdev); } else if ( pdev->domain == dom_xen ) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index d34c98d9c7..cdb1225578 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2806,8 +2806,15 @@ static int cf_check reassign_device_ownership( if ( devfn == pdev->devfn && pdev->domain != target ) { - list_move(&pdev->domain_list, &target->pdev_list); + write_lock(&source->pci_lock); + list_del(&pdev->domain_list); + write_unlock(&source->pci_lock); + pdev->domain = target; + + write_lock(&target->pci_lock); + list_add(&pdev->domain_list, &target->pdev_list); + write_unlock(&target->pci_lock); } if ( !has_arch_pdevs(source) ) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3609ef88c4..57391e74b6 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -461,6 +461,7 @@ struct domain #ifdef CONFIG_HAS_PCI struct list_head pdev_list; + rwlock_t pci_lock; #endif #ifdef CONFIG_HAS_PASSTHROUGH From patchwork Thu Oct 12 22:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419856 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 1E227C46CA1 for ; Thu, 12 Oct 2023 22:09:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616068.957800 (Exim 4.92) (envelope-from ) id 1qr3s3-0001Yi-ED; Thu, 12 Oct 2023 22:09:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616068.957800; Thu, 12 Oct 2023 22:09:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s3-0001Wm-5P; Thu, 12 Oct 2023 22:09:31 +0000 Received: by outflank-mailman (input) for mailman id 616068; Thu, 12 Oct 2023 22:09:29 +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 1qr3s1-00016s-2F for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:29 +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 00417a42-694c-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:24 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml7008371; Thu, 12 Oct 2023 22:09:21 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:20 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:15 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:15 +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: 00417a42-694c-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TGW4xvV/izEZ5YfWl/iobS/kYRHZwM8WgHgRExmyMYF8kzodlECRQ7tmDXQwPTktvCjW18EsKR8B3LxUQQ1gOSLwnLZ2xhcxKXi4v4G7BWDmfsy0yxy/ovniyz/ksdSocx5FI3aGyo8yPDlLXXrhleB/AfFhC4JMlSYqdFsY7tHb9YZUg/Okk0tNE2p8RXiTkIf5+luvAkkS6AGmGzMorDJ3+c5A9p1JW/a4FI8sgNOJ6taA6gkV9njqpjK8xexgkp2LGQ2EbFbyI0xkh60yLTtFDKtBbpLi0oTiHOrdqKRFYhD28eOm7lU4FFeUAIa0o7Vo3C4+QyF6vP/BHY9hag== 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=j3YYW5qeUu5BWrrKwAUFAd6TaoNJsexdP9B8tOFJn3M=; b=lWBdiwpt/ewIDlE6qmbwE+2oTi1nRNBtRYEZKfivP9FRKI7K/nWnBqtB+ue9YOb1N4wrQ9LSKDq7SVFkWDMkb+9qDlyHnsq1e260HPB4g1MFVxA3TpZt3u3C0koCalPeqXzVCLQBA6hn6lWqbGlqDs8yafOmxaF/jBON6hTI8hJmeegJIoOJ02hiHVpW7qLPf4IgkuSL7Bowxajw949a+MZ1BRG3pZNCZPNZimUlqHjhNShEQAbC/IUUgJWXvtpjEIbCG9F1+PvwH/eROagcZ17kQfWZlYzQBjUaXzpUxbFXz2NOKVcFzkYYDv3dHESvjN9ePc4JmIaebzNuML+WBg== 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=j3YYW5qeUu5BWrrKwAUFAd6TaoNJsexdP9B8tOFJn3M=; b=VY+XMmk1osqYFpb9q8zZnjbQwhovWQMSB7jBNP7K+z3jYYeR9tw+3llwjxEmLDwpYaup4F4KWBatOLckZixYdFe+vL5+r5L2ODSTDemSxvpxUvtmkgGHdWPQlHhpYYIgQo8baqM2SLAnMdnr8vjy+C+Qlpu7qfD2ARhzo/jCVZt+n7N4PU5UzsJNi3uS3DCjq2ZP4HCvwZUix9tlEGmcI5S3Byk4NCqXN2T1gUUWFXD/KYvFgflKwPaidN3ayY5B1YwgsY0haTsvzvvy1EtQ/m7q64xxO/hV+eMYq7hVxJJ+m3x9kMwfW1xATLyqGxxzp4ldRJpJFFkaAsaWDLow1w== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Jun Nakajima , Kevin Tian , Paul Durrant , Volodymyr Babchuk Subject: [PATCH v10 03/17] vpci: use per-domain PCI lock to protect vpci structure Thread-Topic: [PATCH v10 03/17] vpci: use per-domain PCI lock to protect vpci structure Thread-Index: AQHZ/Vi9bRc3EUPSDEy0THfJgPlJLA== Date: Thu, 12 Oct 2023 22:09:15 +0000 Message-ID: <20231012220854.2736994-4-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 3947b02b-484e-427c-f1ee-08dbcb6fdfb8 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7L1lYIiSqChxt0uxM1bq5tJ3gvwVw318n5K2Y0AMCB/PWDVmRcjmVTsG9VTbuhs4gKftZc3YBkHbpcnv3IGhDQCdiXpSs/6ZSoOaNqVoVKw49SqEXzjLCp1ajkswwUudMFTk8wgSiifbWh4VCOaEK9lIHkhBVKHqTC6SZkrekrMEZcY5fQ24ovlEJJXEHiebbELDjkS4HxA9U4hOxdQBd0FChmZZ6Z75+tzjKHea71AQt6YmP1K4DOzQeht4DhBKJDG4BDV0pBLfoYd0fJyZ73Fm3Dq1K265+xMaLLwk9yhh+x8nRzTqv/zpxGfMxz5BMiHJ6YAiRaJlk/7Mqh8UgilSX4A0PR4V6wr/1p5qWPWToliZubBRM9IYUIjPKFLc0xG0ddqjCxGDGOGJGtBCYdEc9ueiSFQM7p2bTcyLHrHZCDWjsp34DwTvDA0eUYGl+YtWsucaX6bGYfzQ4Q+kRm2wv3Uouxq/arkv7WD2/71kBX1uuIT9j10oUNNykLMo9HUHN9kSJ4RoKms7/ebyPmuSK6ZS+70HDPSmjn9YRK7+/UGLChZEwNMdCix+faDcd9MY7SsK96gu7cscZiU4IFVxD9XhCuei8KYj6xBiUzP4EtZEYAogFY2vnVqL41S6eZLKmLH8r1GjSzQRDRyqHg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(107886003)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(30864003)(5660300002)(8676002)(4326008)(6486002)(478600001)(579004)(559001)(309714004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?2VjvMyBqMp2bFA4cL9+V47StUsdP?= =?utf-8?q?TPXxKNy3FtR5Vexno65WZz4HUzh3vVcdcaw3LsZ5bYejRvjb4G9WjdU4/bRnKnVgA?= =?utf-8?q?tOzFJqZ0MH6eXvbVJWx0AAmwBbwVhAlqntzr/kC8d8A6b3GS9PNpY9RjERQcpaPVJ?= =?utf-8?q?8Y4FI/nckQ/bdhRImoHpiQOGOfMxAPSEZDjzMeCsw1y1+6O8UnX6X2po4BPE0CNeh?= =?utf-8?q?9lpfiGQQY/a2dzXctiMgwZGR1SKik2XZOSuza0OmxXjGRdbnqRAcHJwBVP4bXO4Y3?= =?utf-8?q?QgxTUKibjtvZtqx/lcaa33GnPblO0VyxzHkJ8MAb59+ySCzlBy+cj7aNE3CcxfRqJ?= =?utf-8?q?R0QcPUvmIv58gRizbghficKTpy/bP5JzoVWZxkqAL9fiedXkfOJR4Ab0q91SxRWBk?= =?utf-8?q?YbyAQ/UaNOKqlpGVUfdDx6k8cF7xXOp3HwmJXoOglpoFRj8SeMHzsapNfzKkMsReU?= =?utf-8?q?9XumggGpzEFvTDkNuUkRL4W75lQshHmEx6yrEQgVEgXZkRnD3H+cPmXix6uWbMytA?= =?utf-8?q?x4gQ9gJ57Q8VLII7v6bfAXAwa7qrVZcq4iQOUracKLBMgvk0kYz5wz/6ujou5oKW1?= =?utf-8?q?Ao7mqfHORC/n7ANFmFkz3jDGAA+iuzDW7EMPpfUZylvxOx0N8Qz/n+z1yF0top9Fz?= =?utf-8?q?FP/cYa2+NVHSe4GDkzBg+ufxQI7mWgS7UZCQM9F3KW1PsOAb2WbKnrg+8KqBx6geU?= =?utf-8?q?+tWyfllgov9zyLQ5s11/2I7ODcL2z3po5K4KR1t0kfGCX70Y1EyO8dW2h9Th1wMWr?= =?utf-8?q?JcYkHVmjec40wMUjsFUeA/d3faqq4nMUjWbx3OpcSCjB5ccyLwOXQLj1SK8j2OrhI?= =?utf-8?q?EePrT61o20+dD3xGowoPuD4ft2c9Wp7/e3XUe26twdZJyjnlmJbetBLH+P/AB/tyH?= =?utf-8?q?H0XqSuYmlBTEfPCjV8iQWOnVfoaFX0dVb5+uQ8SNGdwvvfB0BeTiF4AbQbfKclB/Z?= =?utf-8?q?jhH//EFbUG+bSb3vMQau6BglgMUEJ8tQJ9RxNkIjjLlyhqUVECjJFBr+rkNHDcyVE?= =?utf-8?q?gEOBHcKnoHpB3HCdvdFCVAGmcRWloJ8kMefSZWRrukvHUpOp/IqgbkrYTKrL2vtoV?= =?utf-8?q?VyVR21XwIMSfLb4slJbC9/XJ+OUUoHfGjiLtBD9ueTmdUY0ingFfZj8Pndk6ct1Dr?= =?utf-8?q?ecmBiJCqizdkN94S9/5zvqCm6jkOYR57HsCS/NtB23ZgYoCBHlBLosFusN3zxYkNP?= =?utf-8?q?XdNclsAGTUCtrp4f/ADYgvrS/g6a6OYAgdeHYQs35i3wSJghDX8xnWuPFPw1cjpr3?= =?utf-8?q?3/2D1CenVeXcV0l4WfTErMZ0rQq3RQKoBhx2LakPRe4i9RX9DBslP9uY3TALAOtDV?= =?utf-8?q?oKRjb7Z2kaic0T0Z61Kllhfx/nsxdNHhjDnOQiCiqGGHUt0jfTY094R6wWZUa67rl?= =?utf-8?q?whDkx+fj3JF3o9Xmr49pFTieV62rQDHnYMTp3KqzDugA7gkOBekXmyOTAjJtez6X8?= =?utf-8?q?5SoS6YFIdfk32gshh83ySo5s7YEC76VS3JCJWsFdc0p1GPxOs80WFSuIGNnRmneU1?= =?utf-8?q?94m76GSmUKqVUZX12ywLFDAqp2T9oDr+kA=3D=3D?= Content-ID: <57387D3FB082414E919B9386B171DFEE@eurprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3947b02b-484e-427c-f1ee-08dbcb6fdfb8 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:15.4954 (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: Db/z4yYebUNvQxz2QyWNDZ1SIeEdMrh3rd9UWdl5TsDiRVI76yCscIrKBtHsFnwWEzUo8G/cr7kiyL/QmNhpD6+aNCgkRRjIiZn04ebQT4o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: ESMUjASsK3lvBmr-MMh_uOmwLmWuAyEM X-Proofpoint-ORIG-GUID: ESMUjASsK3lvBmr-MMh_uOmwLmWuAyEM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko Use a previously introduced per-domain read/write lock to check whether vpci is present, so we are sure there are no accesses to the contents of the vpci struct if not. This lock can be used (and in a few cases is used right away) so that vpci removal can be performed while holding the lock in write mode. Previously such removal could race with vpci_read for example. When taking both d->pci_lock and pdev->vpci->lock, they should be taken in this exact order: d->pci_lock then pdev->vpci->lock to avoid possible deadlock situations. 1. Per-domain's pci_rwlock is used to protect pdev->vpci structure from being removed. 2. Writing the command register and ROM BAR register may trigger modify_bars to run, which in turn may access multiple pdevs while checking for the existing BAR's overlap. The overlapping check, if done under the read lock, requires vpci->lock to be acquired on both devices being compared, which may produce a deadlock. It is not possible to upgrade read lock to write lock in such a case. So, in order to prevent the deadlock, use d->pci_lock instead. To prevent deadlock while locking both hwdom->pci_lock and dom_xen->pci_lock, always lock hwdom first. All other code, which doesn't lead to pdev->vpci destruction and does not access multiple pdevs at the same time, can still use a combination of the read lock and pdev->vpci->lock. 3. Drop const qualifier where the new rwlock is used and this is appropriate. 4. Do not call process_pending_softirqs with any locks held. For that unlock prior the call and re-acquire the locks after. After re-acquiring the lock there is no need to check if pdev->vpci exists: - in apply_map because of the context it is called (no race condition possible) - for MSI/MSI-X debug code because it is called at the end of pdev->vpci access and no further access to pdev->vpci is made 5. Use d->pci_lock around for_each_pdev and pci_get_pdev_by_domain while accessing pdevs in vpci code. 6. We are removing multiple ASSERT(pcidevs_locked()) instances because they are too strict now: they should be corrected to ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)), but problem is that mentioned instances does not have access to the domain pointer and it is not feasible to pass a domain pointer to a function just for debugging purposes. There is a possible lock inversion in MSI code, as some parts of it acquire pcidevs_lock() while already holding d->pci_lock. Suggested-by: Roger Pau Monné Suggested-by: Jan Beulich Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- Changes in v10: - Moved printk pas locked area - Returned back ASSERTs - Added new parameter to allocate_and_map_msi_pirq() so it knows if it should take the global pci lock - Added comment about possible improvement in vpci_write - Changed ASSERT(rw_is_locked()) to rw_is_write_locked() in appropriate places - Renamed release_domain_locks() to release_domain_write_locks() - moved domain_done label in vpci_dump_msi() to correct place Changes in v9: - extended locked region to protect vpci_remove_device and vpci_add_handlers() calls - vpci_write() takes lock in the write mode to protect potential call to modify_bars() - renamed lock releasing function - removed ASSERT()s from msi code - added trylock in vpci_dump_msi Changes in v8: - changed d->vpci_lock to d->pci_lock - introducing d->pci_lock in a separate patch - extended locked region in vpci_process_pending - removed pcidevs_lockis vpci_dump_msi() - removed some changes as they are not needed with the new locking scheme - added handling for hwdom && dom_xen case --- xen/arch/x86/hvm/vmsi.c | 26 ++++++++--------- xen/arch/x86/hvm/vmx/vmx.c | 2 -- xen/arch/x86/include/asm/irq.h | 3 +- xen/arch/x86/irq.c | 12 ++++---- xen/arch/x86/msi.c | 10 ++----- xen/arch/x86/physdev.c | 2 +- xen/drivers/passthrough/pci.c | 9 +++--- xen/drivers/vpci/header.c | 18 ++++++++++++ xen/drivers/vpci/msi.c | 28 ++++++++++++++++-- xen/drivers/vpci/msix.c | 52 +++++++++++++++++++++++++++++----- xen/drivers/vpci/vpci.c | 51 +++++++++++++++++++++++++++++++-- 11 files changed, 166 insertions(+), 47 deletions(-) diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index 128f236362..6b33a80120 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -468,7 +468,7 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable) struct msixtbl_entry *entry, *new_entry; int r = -EINVAL; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ASSERT(rw_is_write_locked(&d->event_lock)); if ( !msixtbl_initialised(d) ) @@ -538,7 +538,7 @@ void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq) struct pci_dev *pdev; struct msixtbl_entry *entry; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ASSERT(rw_is_write_locked(&d->event_lock)); if ( !msixtbl_initialised(d) ) @@ -684,7 +684,7 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data, { unsigned int i; - ASSERT(pcidevs_locked()); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); if ( (address & MSI_ADDR_BASE_MASK) != MSI_ADDR_HEADER ) { @@ -725,8 +725,8 @@ void vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev) int rc; ASSERT(msi->arch.pirq != INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); - pcidevs_lock(); for ( i = 0; i < msi->vectors && msi->arch.bound; i++ ) { struct xen_domctl_bind_pt_irq unbind = { @@ -745,7 +745,6 @@ void vpci_msi_arch_update(struct vpci_msi *msi, const struct pci_dev *pdev) msi->arch.bound = !vpci_msi_update(pdev, msi->data, msi->address, msi->vectors, msi->arch.pirq, msi->mask); - pcidevs_unlock(); } static int vpci_msi_enable(const struct pci_dev *pdev, unsigned int nr, @@ -762,7 +761,7 @@ static int vpci_msi_enable(const struct pci_dev *pdev, unsigned int nr, rc = allocate_and_map_msi_pirq(pdev->domain, -1, &pirq, table_base ? MAP_PIRQ_TYPE_MSI : MAP_PIRQ_TYPE_MULTI_MSI, - &msi_info); + &msi_info, false); if ( rc ) { gdprintk(XENLOG_ERR, "%pp: failed to map PIRQ: %d\n", &pdev->sbdf, rc); @@ -778,15 +777,13 @@ int vpci_msi_arch_enable(struct vpci_msi *msi, const struct pci_dev *pdev, int rc; ASSERT(msi->arch.pirq == INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); rc = vpci_msi_enable(pdev, vectors, 0); if ( rc < 0 ) return rc; msi->arch.pirq = rc; - - pcidevs_lock(); msi->arch.bound = !vpci_msi_update(pdev, msi->data, msi->address, vectors, msi->arch.pirq, msi->mask); - pcidevs_unlock(); return 0; } @@ -797,8 +794,8 @@ static void vpci_msi_disable(const struct pci_dev *pdev, int pirq, unsigned int i; ASSERT(pirq != INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); - pcidevs_lock(); for ( i = 0; i < nr && bound; i++ ) { struct xen_domctl_bind_pt_irq bind = { @@ -814,7 +811,6 @@ static void vpci_msi_disable(const struct pci_dev *pdev, int pirq, write_lock(&pdev->domain->event_lock); unmap_domain_pirq(pdev->domain, pirq); write_unlock(&pdev->domain->event_lock); - pcidevs_unlock(); } void vpci_msi_arch_disable(struct vpci_msi *msi, const struct pci_dev *pdev) @@ -854,6 +850,8 @@ int vpci_msix_arch_enable_entry(struct vpci_msix_entry *entry, int rc; ASSERT(entry->arch.pirq == INVALID_PIRQ); + ASSERT(rw_is_locked(&pdev->domain->pci_lock)); + rc = vpci_msi_enable(pdev, vmsix_entry_nr(pdev->vpci->msix, entry), table_base); if ( rc < 0 ) @@ -861,7 +859,6 @@ int vpci_msix_arch_enable_entry(struct vpci_msix_entry *entry, entry->arch.pirq = rc; - pcidevs_lock(); rc = vpci_msi_update(pdev, entry->data, entry->addr, 1, entry->arch.pirq, entry->masked); if ( rc ) @@ -869,7 +866,6 @@ int vpci_msix_arch_enable_entry(struct vpci_msix_entry *entry, vpci_msi_disable(pdev, entry->arch.pirq, 1, false); entry->arch.pirq = INVALID_PIRQ; } - pcidevs_unlock(); return rc; } @@ -895,6 +891,8 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) { unsigned int i; + ASSERT(rw_is_locked(&msix->pdev->domain->pci_lock)); + for ( i = 0; i < msix->max_entries; i++ ) { const struct vpci_msix_entry *entry = &msix->entries[i]; @@ -913,7 +911,9 @@ int vpci_msix_arch_print(const struct vpci_msix *msix) struct pci_dev *pdev = msix->pdev; spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&pdev->domain->pci_lock); process_pending_softirqs(); + read_lock(&pdev->domain->pci_lock); /* NB: we assume that pdev cannot go away for an alive domain. */ if ( !pdev->vpci || !spin_trylock(&pdev->vpci->lock) ) return -EBUSY; diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 1edc7f1e91..545a27796e 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -413,8 +413,6 @@ static int cf_check vmx_pi_update_irte(const struct vcpu *v, spin_unlock_irq(&desc->lock); - ASSERT(pcidevs_locked()); - return iommu_update_ire_from_msi(msi_desc, &msi_desc->msg); unlock_out: diff --git a/xen/arch/x86/include/asm/irq.h b/xen/arch/x86/include/asm/irq.h index ad907fc97f..3d24f39ca6 100644 --- a/xen/arch/x86/include/asm/irq.h +++ b/xen/arch/x86/include/asm/irq.h @@ -213,6 +213,7 @@ static inline void arch_move_irqs(struct vcpu *v) { } struct msi_info; int allocate_and_map_gsi_pirq(struct domain *d, int index, int *pirq_p); int allocate_and_map_msi_pirq(struct domain *d, int index, int *pirq_p, - int type, struct msi_info *msi); + int type, struct msi_info *msi, + bool use_pci_lock); #endif /* _ASM_HW_IRQ_H */ diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 68b788c42e..970ba04aa0 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -2157,7 +2157,7 @@ int map_domain_pirq( struct pci_dev *pdev; unsigned int nr = 0; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ret = -ENODEV; if ( !cpu_has_apic ) @@ -2314,7 +2314,7 @@ int unmap_domain_pirq(struct domain *d, int pirq) if ( (pirq < 0) || (pirq >= d->nr_pirqs) ) return -EINVAL; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&d->pci_lock)); ASSERT(rw_is_write_locked(&d->event_lock)); info = pirq_info(d, pirq); @@ -2875,7 +2875,7 @@ int allocate_and_map_gsi_pirq(struct domain *d, int index, int *pirq_p) } int allocate_and_map_msi_pirq(struct domain *d, int index, int *pirq_p, - int type, struct msi_info *msi) + int type, struct msi_info *msi, bool use_pci_lock) { int irq, pirq, ret; @@ -2908,7 +2908,8 @@ int allocate_and_map_msi_pirq(struct domain *d, int index, int *pirq_p, msi->irq = irq; - pcidevs_lock(); + if ( use_pci_lock ) + pcidevs_lock(); /* Verify or get pirq. */ write_lock(&d->event_lock); pirq = allocate_pirq(d, index, *pirq_p, irq, type, &msi->entry_nr); @@ -2924,7 +2925,8 @@ int allocate_and_map_msi_pirq(struct domain *d, int index, int *pirq_p, done: write_unlock(&d->event_lock); - pcidevs_unlock(); + if ( use_pci_lock ) + pcidevs_unlock(); if ( ret ) { switch ( type ) diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index 20275260b3..466725d8ca 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -602,7 +602,7 @@ static int msi_capability_init(struct pci_dev *dev, unsigned int i, mpos; uint16_t control; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&dev->domain->pci_lock)); pos = pci_find_cap_offset(dev->sbdf, PCI_CAP_ID_MSI); if ( !pos ) return -ENODEV; @@ -771,7 +771,7 @@ static int msix_capability_init(struct pci_dev *dev, if ( !pos ) return -ENODEV; - ASSERT(pcidevs_locked()); + ASSERT(pcidevs_locked() || rw_is_locked(&dev->domain->pci_lock)); control = pci_conf_read16(dev->sbdf, msix_control_reg(pos)); /* @@ -988,8 +988,6 @@ static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc, { struct msi_desc *old_desc; - ASSERT(pcidevs_locked()); - if ( !pdev ) return -ENODEV; @@ -1043,8 +1041,6 @@ static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc, { struct msi_desc *old_desc; - ASSERT(pcidevs_locked()); - if ( !pdev || !pdev->msix ) return -ENODEV; @@ -1154,8 +1150,6 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off) int pci_enable_msi(struct msi_info *msi, struct msi_desc **desc, struct pci_dev *pdev) { - ASSERT(pcidevs_locked()); - if ( !use_msi ) return -EPERM; diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 2f1d955a96..7cbb5bc2c8 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -123,7 +123,7 @@ int physdev_map_pirq(domid_t domid, int type, int *index, int *pirq_p, case MAP_PIRQ_TYPE_MSI: case MAP_PIRQ_TYPE_MULTI_MSI: - ret = allocate_and_map_msi_pirq(d, *index, pirq_p, type, msi); + ret = allocate_and_map_msi_pirq(d, *index, pirq_p, type, msi, true); break; default: diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index b8ad4fa07c..182da45acb 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -750,7 +750,6 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, pdev->domain = hardware_domain; write_lock(&hardware_domain->pci_lock); list_add(&pdev->domain_list, &hardware_domain->pdev_list); - write_unlock(&hardware_domain->pci_lock); /* * For devices not discovered by Xen during boot, add vPCI handlers @@ -759,18 +758,18 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, ret = vpci_add_handlers(pdev); if ( ret ) { - printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); - write_lock(&hardware_domain->pci_lock); list_del(&pdev->domain_list); write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; + printk(XENLOG_ERR "Setup of vPCI failed: %d\n", ret); goto out; } + write_unlock(&hardware_domain->pci_lock); ret = iommu_add_device(pdev); if ( ret ) { - vpci_remove_device(pdev); write_lock(&hardware_domain->pci_lock); + vpci_remove_device(pdev); list_del(&pdev->domain_list); write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; @@ -1146,7 +1145,9 @@ static void __hwdom_init setup_one_hwdom_device(const struct setup_hwdom *ctxt, } while ( devfn != pdev->devfn && PCI_SLOT(devfn) == PCI_SLOT(pdev->devfn) ); + write_lock(&ctxt->d->pci_lock); err = vpci_add_handlers(pdev); + write_unlock(&ctxt->d->pci_lock); if ( err ) printk(XENLOG_ERR "setup of vPCI for d%d failed: %d\n", ctxt->d->domain_id, err); diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 767c1ba718..a52e52db96 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -172,6 +172,7 @@ bool vpci_process_pending(struct vcpu *v) if ( rc == -ERESTART ) return true; + write_lock(&v->domain->pci_lock); spin_lock(&v->vpci.pdev->vpci->lock); /* Disable memory decoding unconditionally on failure. */ modify_decoding(v->vpci.pdev, @@ -190,6 +191,7 @@ bool vpci_process_pending(struct vcpu *v) * failure. */ vpci_remove_device(v->vpci.pdev); + write_unlock(&v->domain->pci_lock); } return false; @@ -201,8 +203,20 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, struct map_data data = { .d = d, .map = true }; int rc; + ASSERT(rw_is_write_locked(&d->pci_lock)); + while ( (rc = rangeset_consume_ranges(mem, map_range, &data)) == -ERESTART ) + { + /* + * It's safe to drop and reacquire the lock in this context + * without risking pdev disappearing because devices cannot be + * removed until the initial domain has been started. + */ + read_unlock(&d->pci_lock); process_pending_softirqs(); + read_lock(&d->pci_lock); + } + rangeset_destroy(mem); if ( !rc ) modify_decoding(pdev, cmd, false); @@ -243,6 +257,8 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) unsigned int i; int rc; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + if ( !mem ) return -ENOMEM; @@ -522,6 +538,8 @@ static int cf_check init_bars(struct pci_dev *pdev) struct vpci_bar *bars = header->bars; int rc; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f ) { case PCI_HEADER_TYPE_NORMAL: diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index a253ccbd7d..2faa54b7ce 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -263,7 +263,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 ) @@ -275,6 +275,9 @@ void vpci_dump_msi(void) printk("vPCI MSI/MSI-X d%d\n", d->domain_id); + if ( !read_trylock(&d->pci_lock) ) + continue; + for_each_pdev ( d, pdev ) { const struct vpci_msi *msi; @@ -316,14 +319,33 @@ void vpci_dump_msi(void) * holding the lock. */ printk("unable to print all MSI-X entries: %d\n", rc); - process_pending_softirqs(); - continue; + goto pdev_done; } } spin_unlock(&pdev->vpci->lock); + pdev_done: + /* + * Unlock lock to process pending softirqs. This is + * potentially unsafe, as d->pdev_list can be changed in + * meantime. + */ + read_unlock(&d->pci_lock); process_pending_softirqs(); + if ( !read_trylock(&d->pci_lock) ) + { + printk("unable to access other devices for the domain\n"); + goto domain_done; + } } + read_unlock(&d->pci_lock); + domain_done: + /* + * We need this label at the end of the loop, but some + * compilers might not be happy about label at the end of the + * compound statement so we adding an empty statement here. + */ + ; } rcu_read_unlock(&domlist_read_lock); } diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index d1126a417d..b6abab47ef 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -147,6 +147,8 @@ static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr) { struct vpci_msix *msix; + ASSERT(rw_is_locked(&d->pci_lock)); + list_for_each_entry ( msix, &d->arch.hvm.msix_tables, next ) { const struct vpci_bar *bars = msix->pdev->vpci->header.bars; @@ -163,7 +165,13 @@ static struct vpci_msix *msix_find(const struct domain *d, unsigned long addr) static int cf_check msix_accept(struct vcpu *v, unsigned long addr) { - return !!msix_find(v->domain, addr); + int rc; + + read_lock(&v->domain->pci_lock); + rc = !!msix_find(v->domain, addr); + read_unlock(&v->domain->pci_lock); + + return rc; } static bool access_allowed(const struct pci_dev *pdev, unsigned long addr, @@ -358,21 +366,35 @@ static int adjacent_read(const struct domain *d, const struct vpci_msix *msix, static int cf_check msix_read( struct vcpu *v, unsigned long addr, unsigned int len, unsigned long *data) { - const struct domain *d = v->domain; - struct vpci_msix *msix = msix_find(d, addr); + struct domain *d = v->domain; + struct vpci_msix *msix; const struct vpci_msix_entry *entry; unsigned int offset; *data = ~0UL; + read_lock(&d->pci_lock); + + msix = msix_find(d, addr); if ( !msix ) + { + read_unlock(&d->pci_lock); return X86EMUL_RETRY; + } if ( adjacent_handle(msix, addr) ) - return adjacent_read(d, msix, addr, len, data); + { + int rc = adjacent_read(d, msix, addr, len, data); + + read_unlock(&d->pci_lock); + return rc; + } if ( !access_allowed(msix->pdev, addr, len) ) + { + read_unlock(&d->pci_lock); return X86EMUL_OKAY; + } spin_lock(&msix->pdev->vpci->lock); entry = get_entry(msix, addr); @@ -404,6 +426,7 @@ static int cf_check msix_read( break; } spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&d->pci_lock); return X86EMUL_OKAY; } @@ -491,19 +514,33 @@ static int adjacent_write(const struct domain *d, const struct vpci_msix *msix, static int cf_check msix_write( struct vcpu *v, unsigned long addr, unsigned int len, unsigned long data) { - const struct domain *d = v->domain; - struct vpci_msix *msix = msix_find(d, addr); + struct domain *d = v->domain; + struct vpci_msix *msix; struct vpci_msix_entry *entry; unsigned int offset; + read_lock(&d->pci_lock); + + msix = msix_find(d, addr); if ( !msix ) + { + read_unlock(&d->pci_lock); return X86EMUL_RETRY; + } if ( adjacent_handle(msix, addr) ) - return adjacent_write(d, msix, addr, len, data); + { + int rc = adjacent_write(d, msix, addr, len, data); + + read_unlock(&d->pci_lock); + return rc; + } if ( !access_allowed(msix->pdev, addr, len) ) + { + read_unlock(&d->pci_lock); return X86EMUL_OKAY; + } spin_lock(&msix->pdev->vpci->lock); entry = get_entry(msix, addr); @@ -579,6 +616,7 @@ static int cf_check msix_write( break; } spin_unlock(&msix->pdev->vpci->lock); + read_unlock(&d->pci_lock); return X86EMUL_OKAY; } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 3bec9a4153..112de56fb3 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -38,6 +38,8 @@ extern vpci_register_init_t *const __end_vpci_array[]; void vpci_remove_device(struct pci_dev *pdev) { + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + if ( !has_vpci(pdev->domain) || !pdev->vpci ) return; @@ -73,6 +75,8 @@ int vpci_add_handlers(struct pci_dev *pdev) const unsigned long *ro_map; int rc = 0; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + if ( !has_vpci(pdev->domain) ) return 0; @@ -326,11 +330,12 @@ static uint32_t merge_result(uint32_t data, uint32_t new, unsigned int size, uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) { - const struct domain *d = current->domain; + struct domain *d = current->domain; const struct pci_dev *pdev; const struct vpci_register *r; unsigned int data_offset = 0; uint32_t data = ~(uint32_t)0; + rwlock_t *lock; if ( !size ) { @@ -342,11 +347,21 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) * Find the PCI dev matching the address, which for hwdom also requires * consulting DomXEN. Passthrough everything that's not trapped. */ + lock = &d->pci_lock; + read_lock(lock); pdev = pci_get_pdev(d, sbdf); if ( !pdev && is_hardware_domain(d) ) + { + read_unlock(lock); + lock = &dom_xen->pci_lock; + read_lock(lock); pdev = pci_get_pdev(dom_xen, sbdf); + } if ( !pdev || !pdev->vpci ) + { + read_unlock(lock); return vpci_read_hw(sbdf, reg, size); + } spin_lock(&pdev->vpci->lock); @@ -392,6 +407,7 @@ uint32_t vpci_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int size) ASSERT(data_offset < size); } spin_unlock(&pdev->vpci->lock); + read_unlock(lock); if ( data_offset < size ) { @@ -431,10 +447,23 @@ static void vpci_write_helper(const struct pci_dev *pdev, r->private); } +/* Helper function to unlock locks taken by vpci_write in proper order */ +static void release_domain_write_locks(struct domain *d) +{ + ASSERT(rw_is_write_locked(&d->pci_lock)); + + if ( is_hardware_domain(d) ) + { + ASSERT(rw_is_write_locked(&dom_xen->pci_lock)); + write_unlock(&dom_xen->pci_lock); + } + write_unlock(&d->pci_lock); +} + void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, uint32_t data) { - const struct domain *d = current->domain; + struct domain *d = current->domain; const struct pci_dev *pdev; const struct vpci_register *r; unsigned int data_offset = 0; @@ -447,8 +476,20 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, /* * Find the PCI dev matching the address, which for hwdom also requires - * consulting DomXEN. Passthrough everything that's not trapped. + * consulting DomXEN. Passthrough everything that's not trapped. + * If this is hwdom, we need to hold locks for both domain in case if + * modify_bars() is called + */ + /* + * TODO: We need to take pci_locks in exclusive mode only if we + * are modifying BARs, so there is a room for improvement. */ + write_lock(&d->pci_lock); + + /* dom_xen->pci_lock always should be taken second to prevent deadlock */ + if ( is_hardware_domain(d) ) + write_lock(&dom_xen->pci_lock); + pdev = pci_get_pdev(d, sbdf); if ( !pdev && is_hardware_domain(d) ) pdev = pci_get_pdev(dom_xen, sbdf); @@ -457,8 +498,11 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, /* Ignore writes to read-only devices, which have no ->vpci. */ const unsigned long *ro_map = pci_get_ro_map(sbdf.seg); + release_domain_write_locks(d); + if ( !ro_map || !test_bit(sbdf.bdf, ro_map) ) vpci_write_hw(sbdf, reg, size, data); + return; } @@ -498,6 +542,7 @@ void vpci_write(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, ASSERT(data_offset < size); } spin_unlock(&pdev->vpci->lock); + release_domain_write_locks(d); if ( data_offset < size ) /* Tailing gap, write the remaining. */ From patchwork Thu Oct 12 22:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419857 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 5DD75CDB48A for ; Thu, 12 Oct 2023 22:09:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616065.957779 (Exim 4.92) (envelope-from ) id 1qr3s2-0001Av-BL; Thu, 12 Oct 2023 22:09:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616065.957779; Thu, 12 Oct 2023 22:09:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s2-0001Aa-5N; Thu, 12 Oct 2023 22:09:30 +0000 Received: by outflank-mailman (input) for mailman id 616065; Thu, 12 Oct 2023 22:09:28 +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 1qr3s0-00016s-H8 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:28 +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 ff93ab1f-694b-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:23 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml6008371; Thu, 12 Oct 2023 22:09:20 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:19 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:16 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:16 +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: ff93ab1f-694b-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TwV1CL9F8uqYT/YStuDwHZR4YQ6G9v0Dnik/ojsBNLU9mVIK2fEMZ483/xJS3hcal3szhTlGRpxNZI9EtVzn+ToZPYQPw3GFpGOQgVT53PxGDT8x6vjgwolRNFsprEPHWEukTnU9V3nm8LC/U9zFzSYVRf9WFjxEU27qiol87OJ0Y45hX1zxuy7V34lAmf1u9A/tPHRdqMCHmAFL6mul298QT59EzXmaG9bUP3IyfcHdmhC86V0+TUwJvEJyOll1zlwqmnp4Lf2RshwDnoKryHBCpnkqJLDUCmYmtSmStzED/R1DP2bAjQaJlJWjCxhucW/oFn+/WZTzrrRlVNmwkA== 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=YQA/auCUyQ9aU8VntbUejZ+kWLEP5minC3jSAets2yA=; b=SAxexvi/1Qls45JhUuym0XSFO2xxGma+jxRhZTXRkDFsr/z88HelTDYgQ3SFiwumGRJ2yd3o/v4FP85+DN8QoMwS3MySH9VPN6e4+kJ6dSIVPkog1SFj1kO92yYfGTtPXf2dUrMoscHfPPZUB3/Xm+AMF8B6ExiqNBQ8ww9pg4btosVyz3R3YGqfY6BiSApdBgJ/Rh2qs1kqGRfwVFljeTfC8XNieKZGuS0QxWvfgb2RGuMFbPd4dDLLN0uiC2FJoh9hmN0F/xRCtP+KiGrnURKlZ6zRmwU47Y2dq3bph4GBPPj1cbAQPnecuxbZEcYL5bwvWE9cecxHBHXcd4nHxg== 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=YQA/auCUyQ9aU8VntbUejZ+kWLEP5minC3jSAets2yA=; b=jPyTj5dMXQxkSyCkShcE2yOwiiqiFDb/3SorteaR0KrCWWULvvzwnTdRmaBrRwwSDEYzy4GrQ3cVwU84xx++PJ91U2GD8x2U5xzTV/5O8CLlJomkRpqLRq4+BlwysYqkBE/MPJWGBT1cD7z9ItWLPhrJjf83Xe/MYDs5cLDEwOpx7f3S6oXcdTHf1VUZvDaie7wPYjLAIinTrpck1dMtyLG6EzhyM9cgW4G/8AigMZDbSVGAwtYcrRQSM/CuNb6rABNMTjfXgJE1BDAt/vP/XhkKuPy9181D7D4gO5HE9PVY/kTdodly0x7gUBQeZJ+8f+l6lVF6SXrjhqgR/TUYoQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?utf-8?q?Roger?= =?utf-8?q?_Pau_Monn=C3=A9?= Subject: [PATCH v10 04/17] vpci: restrict unhandled read/write operations for guests Thread-Topic: [PATCH v10 04/17] vpci: restrict unhandled read/write operations for guests Thread-Index: AQHZ/Vi9RFnVSEkUl0CU8ZWONnKP8w== Date: Thu, 12 Oct 2023 22:09:15 +0000 Message-ID: <20231012220854.2736994-5-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 0708c5ce-f72d-4f88-64bc-08dbcb6fdfed x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pCgljNsC/vH2LHKERU8YLBnRmE2rqcuFdfgJXxDu7qHVgk4fsnMHSIMySATppl/Kjs1xXSCHSRitKlkpeFGmEQUX4OnIZPYlDXLWikqDiur5snnt0K+LIlgZNfoIZsuViaDejuhoVncg9BkO7Kp+UzUB1MkJE/UkmW3+Bv9ol8yLWxuNU96pIptzeHPfr/Mts3X1OxJSUkeWIp47tk7BBARkzkQpL4qQ7huorTxXG4kMz7+tHLoTyzX+TQIItZwF/PkK/HE/8ZZSiJLgcqArZWl3OnyvsWBlvY+oQEWTqJwTPSTls7VT/ItXvexvM8rbrpzr2IsghqRWP0S3JAY+lLoRWJl6KM9H3nWf2/XKd6OezEyopduBZldQbtG+ocMlfMauZgD6IIH0AhXeK8IejrjnAQnUefcSYDMcIxGV2IyDUNy3bawJ0QipwXEDz/r9qqTUlIB3lETBLAdc0gTFgDoOyO2aMla9BotxfHoFh8sKdNY0Yujn2JYC3BwjKnHrBBNzkplgQi1HP8bfk9YLTjj6HZ/qQb/np/BC1Gbw6TDk0QFy0Jb6NZbCwYC9M6PRBZme1XZA6MhgTK/zcib6al56ALzuGSl9QvLA5FOs646OoPwFgNqoT9+KuVgcc+3v x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?L6fdlRkQ6Sd7ggrslMW5gpZS/T00?= =?utf-8?q?9QgZkWQi1O95Rk1fNGyBvjwTH+Tqo1Eg24uZbWQhoKemlR4dCBb+V31TJy7tQI6N5?= =?utf-8?q?WOeoXW/Cwb4DPGtU8VjMoCbgJ/S4y78wgoi3US2xgRp4zfGIWNcEghyU71YnWS4i1?= =?utf-8?q?jGJtQcHIm3MH9M6JgeU/u4QcMrN9ro3kjMcYYNqYuel9wx92J9GfszaDNhEGDZxcH?= =?utf-8?q?F5zg3MMSfWv+WqVI2EZ9kaYJ9rWahDWtQ8dqKpWlAHjJNCd4EDCwdqv/VVAsr05HG?= =?utf-8?q?/16VLR3g36QEKaWahrnyGmQQCgvPjHg5f4tPO3PcHtrhIwfU+PB7DROnisncv1tXe?= =?utf-8?q?KD0Vp6l3aiLIihjOe7FfCFtUU0KxIgO95QGCouZcQKGx92PeHXNgNgs49JStwTCJj?= =?utf-8?q?AIDlYZUN7o7+r4eEpzaumrSYvD79K+OjmRGFzLa+tD9sb4DboEeY4cHvQBaMmloIg?= =?utf-8?q?Cf7D/rp0SMk9m+tEjxjNqmivobIOtwwFSRV38a9DrWzxjHfQCO4Om8hQs20RSJfxF?= =?utf-8?q?cje4BVVkEtg8rsbTqR0wdFlZ6CThL/dmacFbCTnuWvFTRHB1WYFjXWFvulCCB5U/O?= =?utf-8?q?Fr+gbqldUH2mEARXi+Xjc8bM6Id1/j0zGLoj4ycceGpkpzCoUQYH17Km7YozBlA9v?= =?utf-8?q?BV48lalPZqqSMpFYdRVXUMChASXb713KxzemZn6R66VKk7zcmHXWABDr1blDW9fIL?= =?utf-8?q?Vzwn7XLYyaMXNNsNZYEWu5kpE+GTBFeHCw/9WG6ynW3CnCU1oPijrLpW2TTbe7HM6?= =?utf-8?q?ELU1zAxzU0rgo4aRC6Y03aMBsxGZ60JprK7HNCbqzeH0L2og0YAbGXjtBQlBPu9SZ?= =?utf-8?q?GTvElNT6osWgtMaHY5Zt4WNRPY/IhMhAY/deXQWDKcWU60VDuPwE4Pe+KpFG9iFs+?= =?utf-8?q?HxyHEifbSsZN9Oew11qGN80/N7rOOpvdg72HkWFAe19KfhAfj3sv7ckgCcq6t+r5H?= =?utf-8?q?DbLtj69dxkhLcJZ2KOKNNcZty2UBxuSMAyaLw0vFzMaDlpY5Ra3MJZWLOebgarrDr?= =?utf-8?q?6veXOKXUElgE4Qskwf//KVOqSyhlkbT5OHRuNJTFbqcjew+w5xGDGtT5yH8WI3N+H?= =?utf-8?q?QoYzDAeL+giMbsRSq8cHBg2JB8b4zmyTlQmHDUdaHkTvNv+qR+cCOZ/JUtJxj0gxe?= =?utf-8?q?lTfP3H0hYQQ7wBWnmxwTgBrlpd8wW2CjzMxSmPcNi8pdJ8mnMQVqFXFBaVZnQI5Zh?= =?utf-8?q?IwBK1yGSrc/XSYjrb1m/AjyjGdkztpbTBzx6nlLDxOuQtp9e7H7qztjdD0MLrz4U7?= =?utf-8?q?0FO3dnKSaar+DhaeIjCTGDwnJwrMpE5QNw9HTWzjhaqdZs1HMbpjItOzZJpkyqhyE?= =?utf-8?q?ANvkWwfBCk/8lC7X7XxRcxXUiBFCUuexXGjMwwFlMy0HgqkcJGnYSfmdaEFbYUgtb?= =?utf-8?q?eV++PGSl5aEELXg7B95Jlc+On1FqRtBkaU+kfllvHaZNi2PLniotE17AadLzuoVMU?= =?utf-8?q?Ih99/ua5eP+JuB4t9v6DdnmYQtVGbTWCVIvITpB/BaIOPoNfC2BPYxsZMQo3qr9Ae?= =?utf-8?q?Lf1mT8dM5V7RWue8fSubxnNy0iGt40QsJg=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: 0708c5ce-f72d-4f88-64bc-08dbcb6fdfed X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:15.7341 (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: MAeqH9VN3RfHTineyTIwTsWNdPI6IyB2e1jn3Nv8ierpvEOXIgIL1+TazPXWAapZQfWO4a5UirRii5eToyXaa/uzroym+EvnYS0fiHvhPHw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: o8iHpim3AG1REOvPtu8c6yw4aPgPdVM1 X-Proofpoint-ORIG-GUID: o8iHpim3AG1REOvPtu8c6yw4aPgPdVM1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko A guest would be able to read and write those registers which are not emulated and have no respective vPCI handlers, so it will be possible for it to access the hardware directly. In order to prevent a guest from reads and writes from/to the unhandled registers make sure only hardware domain can access the hardware directly and restrict guests from doing so. Suggested-by: Roger Pau Monné Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Roger Pau Monné --- Since v9: - removed stray formatting change - added Roger's R-b tag Since v6: - do not use is_hwdom parameter for vpci_{read|write}_hw and use current->domain internally - update commit message New in v6 --- xen/drivers/vpci/vpci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 112de56fb3..724987e981 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -233,6 +233,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, { uint32_t data; + /* Guest domains are not allowed to read real hardware. */ + if ( !is_hardware_domain(current->domain) ) + return ~(uint32_t)0; + switch ( size ) { case 4: @@ -276,6 +280,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg, static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, unsigned int size, uint32_t data) { + /* Guest domains are not allowed to write real hardware. */ + if ( !is_hardware_domain(current->domain) ) + return; + switch ( size ) { case 4: From patchwork Thu Oct 12 22:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419855 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 24ED1CDB487 for ; Thu, 12 Oct 2023 22:09:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616067.957793 (Exim 4.92) (envelope-from ) id 1qr3s3-0001SD-14; Thu, 12 Oct 2023 22:09:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616067.957793; Thu, 12 Oct 2023 22:09:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s2-0001Nj-QZ; Thu, 12 Oct 2023 22:09:30 +0000 Received: by outflank-mailman (input) for mailman id 616067; Thu, 12 Oct 2023 22:09:28 +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 1qr3s0-00016s-O7 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:28 +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 00298d58-694c-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:24 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml8008371; Thu, 12 Oct 2023 22:09:21 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:21 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:16 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:16 +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: 00298d58-694c-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HCUez6HIdfcr1Yr7xZFa4YnP3Ck7kWtx5ZCufd0F5z3GXbzU6+Q1IwHRPPkYhzGc1lpaSBnKITIkZc5vV5eiEv3rnZddrCf+9IS0n7/bxs5CfozBM9+TXfd+BHTUnaoBqmfC8phIs1dsn2eMgOJ8DcARhaH+vCJE64ESfJaHfOHdfUk4XpZmn5ovfxg8Q0FRR9nHbxfo08EiFhCHlu+CY/TKhWE2wwvoEebj+lCUXJHj4vDfTjc1wFjkVXYX5+Cq9Ox0gjaXwbKhwSFhd5Lm6Z454e7DzgffXlD/y30wRVB6WL9KsDtKubpkt7pZsCCH///eirgb071Ej1t1WxUfkw== 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=3qmsepwPT5LEYBRF5H3XVtxBcmvh8BkH9lW5MHLqJWE=; b=N8Nw+usgSJRHJVFyRTs4mfN5DxrFxBpFMGeMcWVhpbFMXdXP31sOFzVz0g6xUqdlsMw/urL2vPOXa3L3eqgg/XwZrdhzW7EH9VLuE9JkgBYAH3SxG+mCx8JVxJ9OovZWhUV9lt88ZRt89o54KSEgamCHaytB3vr7M41Ctje3aQa8CSkWmHClYYaeXn2KYCA+VOq0h648DAAFTlzdDQrEkpKxmwBcXuXtnEr1HqxbxpHJrLq/MwJSkzh/SnOOOawLGVLzS3ub1w9cwf65MkkChtASC2qWgs7yrK+RLbQXQbq3eXXIQ71h5zoHIFu78wsaaVdrV/ySRd4zwnDyN7BMjA== 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=3qmsepwPT5LEYBRF5H3XVtxBcmvh8BkH9lW5MHLqJWE=; b=bsJ+IMRouNrG9vZQ3Pub+bkrb1CdKlZG3BpzrbYNXBnDBjdRU73CSCb0XrAw6WqiTF+lARHviht/CfdrrxPTLMPg2hzddStp8Y0RgE+1nZgPqPfqrHDrAvL8F1dnVPUXn+aQAmOJO6PncvGSK1T8ikr42lFtLQaWclGx/89TDU2aGzCoJBYfAAyj2ouDg7mG+5vIO6sWRHJ/Bxf3loEoQai6M+zDa5S0ztp5TCPrGyxVwycgMcKVywpwyGh5tVJBuYXvgCQQ/rCO8clkS5kLR+E/Nlo8Wj+H8ErL5qCguRuT3j8VGruz2vC2KILE3doQNaRsV9+0K3YgdFwzoE+ZKg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Jan Beulich , Paul Durrant , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v10 05/17] vpci: add hooks for PCI device assign/de-assign Thread-Topic: [PATCH v10 05/17] vpci: add hooks for PCI device assign/de-assign Thread-Index: AQHZ/Vi9fq+uOYreoU2R3lof3/0hww== Date: Thu, 12 Oct 2023 22:09:15 +0000 Message-ID: <20231012220854.2736994-6-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: cf61ec12-f889-4405-110e-08dbcb6fe03c x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qu9pTc5w0Ntn2RomDq8KEVzcM+p2XK18Gtxpt76OEIK4kbpUgS8Y3srZBY95pZuNCVVH6RaZRQHtredepyPK5sOR1Rs74CB/IMzl+cx6g7fRW2yIg51qpyAYoTyx33RGbgFm+X1AbuZbd4m48ZXaD6oLt5GLTDXWf+5nreJSKhe+AaUwzNTwo0+wXFLekeLo5KhtWJm2QOuN9ozVBTEmfh7GycuNgG42OCf/5DGqhf+hsp4TA5Nwf1ZkhenPU1dIr3zqW0kq5mmPbk/Arw0dx3vmhrRXft71uf2G0erjUJBb7akEBdoYEfozPWhC9CV1E8NL3FvRhjjO+U9X/0oEy3dLQUv3hlX8UC0CSfUeRPvLVCNy5PZIA89yUClx2cogJlw8+yuDZ6C6rWJ4S77Tw5fH+8X++oTAOSIZlD+noLWgBOE5CfzrQP0XNr5JzA7546fKuzQtGnxGOSp6e2Ak4OqoKfXBicxh5JpGBpZz+BnruS9GzyuloxKv0QByBGH7id0idxhSx53ZMkoE7MrxT2k095nnj8TngUmm7CCUAzLjtiSTyk0GHCmicci3QtKxQsgGI6Zjc8B74uaOCZYL08UxllNmjcuUMT2u7jjKGZpv4gSzEa9DxtzxKPb10xAq x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(107886003)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?3Pj47ZPJX0bsHYz6M+r4sGB?= =?iso-8859-1?q?WeJE4qa0wCHPbthmG6vHAwYWyhWBNBKXp41aH7jDcOVfFoIt1sV1Hj5qNCkR?= =?iso-8859-1?q?It8vJkHQ8Jcg0PF36PfnNts2gAzwa8VandEpimYJpD68A7IhtioyKIoI1wTT?= =?iso-8859-1?q?U4nydak6NM+JTaReiCbQIEXrkkUMbCbB34OFgW9PNPX+iB05ppNoNfeTi3uw?= =?iso-8859-1?q?E7GnncQ3/GTydD1I0D7ZlBt+AbD9OpSQ3FZbhT3rRlaKBmBF5hGDbEXoNUi/?= =?iso-8859-1?q?Ck3B4Z6a0pat2HcTrNUVhxlg35OrUQqpHn8ofmhOm0yXR21GmLho8EkARzQM?= =?iso-8859-1?q?NvBhciaQFUUsNhYaYBDxZf/Bd2Uxb8idF8I0uZjrCR88zUzQ1q2rBCG7gtNr?= =?iso-8859-1?q?OPzA/CSq2f7hpmU/1jxbtr65IIp3UMwefIe93+nqqD1HfACTvc8c3zhkIcZH?= =?iso-8859-1?q?PDiTBydDL/5WVIo3x4DfAY1Upo3+46Xg0Akx7YmDSEl7mYnNV1bvZv3lvD84?= =?iso-8859-1?q?wa2LKzNR09/i2NtA2sOuiHynWGZlovP8R9Z/zxS+MNXlonPrzdooLMwNmdvq?= =?iso-8859-1?q?bdeGgy2YyWKS/S/YXVjNG6PwACLdoOwTVX9Z+El6j/quQJXfCpnw9xodwItM?= =?iso-8859-1?q?bu45o06N7WdRHr/tS1KLWmnHetKZls7csdO0nJNrArZ3N1S1vAOe+M+/U84T?= =?iso-8859-1?q?mT7Q7mbRZXzphV7FWIY+8uZP1qjidwXaNINWQooF4tm13Ho5W0C4aZ2Pnotp?= =?iso-8859-1?q?purJZMPhusLF9a/E1nSUdRIInZfNn5vhF1YWO+wDH9UI5VUSjn/UlCrsXRp6?= =?iso-8859-1?q?czTvFO0aC4GSf6IoHmL2TDcDMDwdKfN2ZG/LmniahpmVNBufE7p84ggnJEPu?= =?iso-8859-1?q?5FqjSo+Osf0KyTeKtrNS4fgGC8AmTy4cUXA7lIMRUUh0AbpsD5qQmyBIzS9j?= =?iso-8859-1?q?u8NxUNjzXd7xd6etc7oXhEwrpYF3qUknRWzK41TNOmBDEyUv6i9UMe5elkiJ?= =?iso-8859-1?q?IkLj6wSRm0MiBZ8iz5fxg86oEHVTHxlp2W0HunugkZqQa+dxFCPBIpKOkyGY?= =?iso-8859-1?q?9ry1B3pfjjz0epHyWE55RC6CkHPjl2u1qjCCZSdluwahBPwCkbTWkzGtKq0t?= =?iso-8859-1?q?hUyTq0QozUmeOjRPRlHix0EzEOrHxWi4BUfsPQa3NKhxJfaYS2F3FKyQlojX?= =?iso-8859-1?q?lldBIFK6MP7ixShyLXt6g+u/YW4F93yttQphA5iu9A6x5o9zCuJT/c/qGEV9?= =?iso-8859-1?q?LAIT6cQ63AJ1dTs+/swMHCnUprXL3feh+LIh69S+lL4PUipm2i5c8e2X9FNP?= =?iso-8859-1?q?Q0nM2Cn43tRFCKvQt+LB+0jTYJ+oGunRMuLI8loEwIBLyhjUMGwyYRwShfvS?= =?iso-8859-1?q?7PxAwYU1HhYQVkMX7RlH2wXPz8/TC3kMevuk3IfsyuldXBsAFQzILH+7W0vR?= =?iso-8859-1?q?7cahW8WoK/ilPmYlmIRHQce8QUObH8YFeTJZzQxJo00GYrd83lXcY54s3mnp?= =?iso-8859-1?q?1xbCQ7hzfqoDQSqoazrM8+bsgvzVp1jW1IsO/ORd3GrjHZt3iAp3R3hteXx/?= =?iso-8859-1?q?nboBPuaIqfICryJRNrR5XRD3obkDJM5BI2TR0IB7AC7pyPc8cmVYRAeYK9Qk?= =?iso-8859-1?q?KDGWOkKP2rG5qEUJmlcGsumI1dJk5PPxnvA3GGg=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: cf61ec12-f889-4405-110e-08dbcb6fe03c X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:15.9960 (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: AIAFc4iL0q9YIslbonRlXVRU1pNguMnvCgzJ07rAgBenojzNTT7UcMvzPiUv2SPliGZ9/dXvhkLC7HdVgZKLal8iNfjKe2GtUGY/EJE+ZZ0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: xPGnu4w1kRYsw0G2gEzggBmRHh7JGbMm X-Proofpoint-ORIG-GUID: xPGnu4w1kRYsw0G2gEzggBmRHh7JGbMm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=803 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko When a PCI device gets assigned/de-assigned we need to initialize/de-initialize vPCI state for the device. Also, rename vpci_add_handlers() to vpci_assign_device() and vpci_remove_device() to vpci_deassign_device() to better reflect role of the functions. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- In v10: - removed HAS_VPCI_GUEST_SUPPORT checks - HAS_VPCI_GUEST_SUPPORT config option (in Kconfig) as it is not used anywhere In v9: - removed previous vpci_[de]assign_device function and renamed existing handlers - dropped attempts to handle errors in assign_device() function - do not call vpci_assign_device for dom_io - use d instead of pdev->domain - use IS_ENABLED macro In v8: - removed vpci_deassign_device In 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 In 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 In 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 In 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 In v2: - define CONFIG_HAS_VPCI_GUEST_SUPPORT so dead code is not compiled for x86 In v1: - constify struct pci_dev where possible - do not open code is_system_domain() - extended the commit message --- xen/drivers/passthrough/pci.c | 20 ++++++++++++++++---- xen/drivers/vpci/header.c | 2 +- xen/drivers/vpci/vpci.c | 6 +++--- xen/include/xen/vpci.h | 10 +++++----- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 182da45acb..b7926a291c 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -755,7 +755,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, * For devices not discovered by Xen during boot, add vPCI handlers * when Dom0 first informs Xen about such devices. */ - ret = vpci_add_handlers(pdev); + ret = vpci_assign_device(pdev); if ( ret ) { list_del(&pdev->domain_list); @@ -769,7 +769,7 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, if ( ret ) { write_lock(&hardware_domain->pci_lock); - vpci_remove_device(pdev); + vpci_deassign_device(pdev); list_del(&pdev->domain_list); write_unlock(&hardware_domain->pci_lock); pdev->domain = NULL; @@ -817,7 +817,7 @@ int pci_remove_device(u16 seg, u8 bus, u8 devfn) list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) if ( pdev->bus == bus && pdev->devfn == devfn ) { - vpci_remove_device(pdev); + vpci_deassign_device(pdev); pci_cleanup_msi(pdev); ret = iommu_remove_device(pdev); if ( pdev->domain ) @@ -875,6 +875,10 @@ static int deassign_device(struct domain *d, uint16_t seg, uint8_t bus, goto out; } + write_lock(&d->pci_lock); + vpci_deassign_device(pdev); + write_unlock(&d->pci_lock); + devfn = pdev->devfn; ret = iommu_call(hd->platform_ops, reassign_device, d, target, devfn, pci_to_dev(pdev)); @@ -1146,7 +1150,7 @@ static void __hwdom_init setup_one_hwdom_device(const struct setup_hwdom *ctxt, PCI_SLOT(devfn) == PCI_SLOT(pdev->devfn) ); write_lock(&ctxt->d->pci_lock); - err = vpci_add_handlers(pdev); + err = vpci_assign_device(pdev); write_unlock(&ctxt->d->pci_lock); if ( err ) printk(XENLOG_ERR "setup of vPCI for d%d failed: %d\n", @@ -1476,6 +1480,10 @@ 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; + write_lock(&pdev->domain->pci_lock); + vpci_deassign_device(pdev); + write_unlock(&pdev->domain->pci_lock); + rc = pdev_msix_assign(d, pdev); if ( rc ) goto done; @@ -1502,6 +1510,10 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn, u32 flag) pci_to_dev(pdev), flag); } + write_lock(&d->pci_lock); + rc = vpci_assign_device(pdev); + write_unlock(&d->pci_lock); + done: if ( rc ) printk(XENLOG_G_WARNING "%pd: assign (%pp) failed (%d)\n", diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index a52e52db96..176fe16b9f 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -190,7 +190,7 @@ bool vpci_process_pending(struct vcpu *v) * killed in order to avoid leaking stale p2m mappings on * failure. */ - vpci_remove_device(v->vpci.pdev); + vpci_deassign_device(v->vpci.pdev); write_unlock(&v->domain->pci_lock); } diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 724987e981..b20bee2b0b 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -36,7 +36,7 @@ extern vpci_register_init_t *const __start_vpci_array[]; extern vpci_register_init_t *const __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) -void vpci_remove_device(struct pci_dev *pdev) +void vpci_deassign_device(struct pci_dev *pdev) { ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); @@ -69,7 +69,7 @@ void vpci_remove_device(struct pci_dev *pdev) pdev->vpci = NULL; } -int vpci_add_handlers(struct pci_dev *pdev) +int vpci_assign_device(struct pci_dev *pdev) { unsigned int i; const unsigned long *ro_map; @@ -103,7 +103,7 @@ int vpci_add_handlers(struct pci_dev *pdev) } if ( rc ) - vpci_remove_device(pdev); + vpci_deassign_device(pdev); return rc; } diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index d743d96a10..75cfb532ee 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -25,11 +25,11 @@ typedef int vpci_register_init_t(struct pci_dev *dev); static vpci_register_init_t *const x##_entry \ __used_section(".data.vpci." p) = x -/* Add vPCI handlers to device. */ -int __must_check vpci_add_handlers(struct pci_dev *pdev); +/* Assign vPCI to device by adding handlers to device. */ +int __must_check vpci_assign_device(struct pci_dev *pdev); /* Remove all handlers and free vpci related structures. */ -void vpci_remove_device(struct pci_dev *pdev); +void vpci_deassign_device(struct pci_dev *pdev); /* Add/remove a register handler. */ int __must_check vpci_add_register(struct vpci *vpci, @@ -235,12 +235,12 @@ bool vpci_ecam_read(pci_sbdf_t sbdf, unsigned int reg, unsigned int len, #else /* !CONFIG_HAS_VPCI */ struct vpci_vcpu {}; -static inline int vpci_add_handlers(struct pci_dev *pdev) +static inline int vpci_assign_device(struct pci_dev *pdev) { return 0; } -static inline void vpci_remove_device(struct pci_dev *pdev) { } +static inline void vpci_deassign_device(struct pci_dev *pdev) { } static inline void vpci_dump_msi(void) { } From patchwork Thu Oct 12 22:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419847 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 F319ACDB482 for ; Thu, 12 Oct 2023 22:09:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616064.957772 (Exim 4.92) (envelope-from ) id 1qr3s1-00017S-Vd; Thu, 12 Oct 2023 22:09:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616064.957772; Thu, 12 Oct 2023 22:09:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s1-00017L-So; Thu, 12 Oct 2023 22:09:29 +0000 Received: by outflank-mailman (input) for mailman id 616064; Thu, 12 Oct 2023 22:09:28 +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 1qr3s0-00016v-B4 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:28 +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 00f71115-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:26 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqml9008371; Thu, 12 Oct 2023 22:09:23 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:23 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:17 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:17 +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: 00f71115-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h63PPNZt3JfrvOJ4ZdEAarqk8/nnxRj5O2mdCGhqm5fqHBavlVR/wmtDTUMLKcH/LHJtk1u3ok2LZXo3daIt8H83FULAEec96x/1X56riIRTBQdMazCjDT+lg2UFXyksgYFngsJkDJ77XzxUHRlOsBFv/RNfwuo4Ti53Z93g3QR0w+E7fNwY49GcQXzcb4RuHH4O36KohAZZG4KygfO7WdLLVELCVC4hTb5IzSw9D5tK4CchBCC2wLIUmxlGxP2PztHM8hlq93HV8i0Q2fHofuad2eQZ6B+lN0L+9N4+nUAbC8EpQn8cmQP7GgkWeUIbfbAjcVTmtoesco6yBjHNrA== 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=zMLvoJ8oLwDDcIwwFQCmO1G6TxLtjEG3z/3WmRJCPC8=; b=cj6d/YyEeNdAMACZm8lGafBreEklzgsBPYRNlhhdENjWWgpx4wj53dSSWYNk3efWF6sIiAjZPKZE8dDFbSULrzrHssSSm1oUydkEmRV2+eO4rvrO5QRRAwaZ1Uq8TlQPRm/itiYsZyUhj3r/f0MssnQz0dC9dBNiAR0fFYXnAZ5aPx5JsmdoQoBEtZt4C8r8xcbP7b9otzt9uU2kq95qmprcY3imipkKtJxyhkRmypEstuHD96NdijnTcIUS4EKvuwYIQ7Rmzc5zUbGaf3I6gOdbThuVSnngm1lw4iv7F8qgylAMC7NcsS5aoWez6jY2DRXHf4Gj4oUqiu54fLxdvg== 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=zMLvoJ8oLwDDcIwwFQCmO1G6TxLtjEG3z/3WmRJCPC8=; b=CtKDOFS4Qamh5MA6OTmYZ/iVQupGqJ4Ayfycsf0H1NlwIKLLDRqGi2OCvx4B9OtXlSTjWAJTGsTutnIBZN/cuK0jhXWw0qm0+0BnZV/aQxNKMr07Q9F9Nd8s3b13ahCpJz3pwE/Gdi7TAskzzrpAOsqFHV2nDc2SOjh8skExjsL9F1+rB970ZmkhtufvgrGItnnE88viMh5eJXAiX3o7jRrAgtfD2ALF8tUhRtubajMPazjc2RXWPgopdvBg4mYfadZjvsJHX2r6B6hwuo9zU/S1cg9geyRNHX5ECRXHcKLlv5ltSThchBW6/GwvQl7WX0U5gDCUl9Je2hVNw5+rPg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Subject: [PATCH v10 06/17] vpci/header: rework exit path in init_bars Thread-Topic: [PATCH v10 06/17] vpci/header: rework exit path in init_bars Thread-Index: AQHZ/Vi9WQzEUKFClEWKXSReXuWjGg== Date: Thu, 12 Oct 2023 22:09:16 +0000 Message-ID: <20231012220854.2736994-7-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 7c11578c-7fcc-47a4-4889-08dbcb6fe075 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: M/D5Wx0CEZKab6dvl8nUSy9VRijS0vZ3VQwpXXpaXVwKMLRfwfzhrjzdyjTtzq3VqNjR1S0fxJWfzzG9Gt6G6d06Vqes/QR9IMjJxPt1oBvpqrViEJojt1lpEcVKFr/tm1d4MwR7kt2+NyH01Et3U9vN2BmmwLif7fo/LNXkGbexK57r1W66Xx84ftGlruFWWPBe+5MfkcK9DKqXLpFhyRQiHvtjnLMY+Ha2M2K5lJTsBA3ugvHD2ja6pjL5vKdViDEmhdUxZaA8zpArHMPNEviFK67q1eJ24p8Si67ztsqzKRPGCCH6SigfdnoNw5b73yDQcQiieskBrvc22XadTRgy+Dm09HSgJnX/fMin3GoQVRb/TKa5WqZrtf1UtPnyF8O177WeLcqdVqcPqrePvLqPuWaHpfkxMoE9TyllPr97Z+l/2EYZXNgHjNZyCJalHupAjSZF9hOHJMZr8jWRAeRxvulnx9L4bx0/tVfcnqnXZDutd6tWLT3CMIaSkMwK8n/86P4BSDBre+56jKA1gsPBoTYx5z9AnS78yhF4/hMLT7U/TvWqHWHy9u0UWDA903HKhSKy46/vOPKcidd67GLPuZo3XsxBHHh8ML1rlBoVmrpZumhRIFEzeLRR0R95 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?czngQSDCvLQOvJPF2tuDWfoOQo0s?= =?utf-8?q?/6moLGWoLPAkuMxKWLHAK2Njokmzxynv86B6jbAKAVfTJ4yBriaHig4EEQ3E7br6Y?= =?utf-8?q?VvXFZM5Z71ZHx9x/B9bZENTNGeBtY9bQD7waL+KcSpJJuMuYCI4+QDn5ZjVJGG515?= =?utf-8?q?jVooS6Oz/kDo0Orn3XsulcjrlGCpg9LNuR1nchi9t6K6I88rmXygVd0OZZ5d5mv1N?= =?utf-8?q?DLNamu1H6Ufc4lX0A+iQdhncSwgKmXgv9YX/DbTuWncNLcAnPjkzVoTVGtSNiZbPu?= =?utf-8?q?EQh0LaQuwTLP4GPbI1D2SdoyI7LbyAq39KX1ttiGjNpZQDttzK5rKG0Ric2vc35W+?= =?utf-8?q?DcsyLy2m9vFx8ltEuGuGBN7T3ikz1Xhj2C9j5P5m4VWbb5wkqBDnFc1yQldlmKCHD?= =?utf-8?q?hT+bTm214tQ9ZzDi1yxyAJulC9Ro1nCv2GIAKCb1qh5kyG0K/rVX/LSICEGiu+At5?= =?utf-8?q?FgEONOV5KMpXTaxFrM4rBLPn1/BAHjs/rxJZB68fVOYtj+510RdG1E82R3mwyxjey?= =?utf-8?q?xR1ZdFFxTv/A5vARCBFukjG9PiadDPoXN2ZP84CMPxN74Lq9DNFarY55awJWD3k8a?= =?utf-8?q?Q3sOO2WGZba5scqsF21GjVwULdR9l/IBOf/bhkpzjENWU7BZ1BGAWnOam5/df5pmw?= =?utf-8?q?ClBHznSXHHOreZdmRDoYpyUJrOtuKDrhZhMLGVo3gfe0ceoolvMmiW0A/QQ0FL8xe?= =?utf-8?q?uPuz0Hx73OHFVGvS66Qqyz+UNgMR4hr561CWsACtL/e9Ypklgp9csMTecjJoKdkYS?= =?utf-8?q?fVTORKciQ78vUWEJvFAZ4pOGxvOfkGyouQKsK4ddvD0Bff6GVD9AVpU4UEXdLZtvY?= =?utf-8?q?x8rwr5PriayhzI69E9AyvD69O+H5ScF4x/eYMGTly1S0y8YLVq7kaRwayLWbGaXvn?= =?utf-8?q?I2p3ezf/hn4EfNtIZiFoMCt7Y7Jwqdlyu2poJPYJN2m+cj6w0WBZCKIsE1Sxv7XKC?= =?utf-8?q?oyOO75oyf9bKR4nSPAodQG2uApp4JuykOG823j+cz7C7ka6/XLt0IXKj6dlaz/RFd?= =?utf-8?q?oK+MPe7snT35TmVoLzob5b9V31YedOI+fpGZLLcB6/qSZodRy5x/nRzHAataKO9TH?= =?utf-8?q?lJGGyj23t5jhJMPF/QkRQCB764T3j1LTIlSnzY+z8+O8Oa38PZSgLhoA6k9ik1Eed?= =?utf-8?q?5DX96UywvXp3o2ZtSJPRogDM2NpTKE+r5tRDsgPOKvrHkDnqxZgDMR4H4AqEdHFAR?= =?utf-8?q?8uw5cAz4pBEyMekPopd2o1w3U8iJkBIV1Eig8wXj6ed2wgWHciiYipao8WOoCmSYA?= =?utf-8?q?Mv5mPixVkRtgD4oML6O2PNE76uh6WkZxvJqzmTUpjRRHPdEOpZbM9P2wCtGiTI7y3?= =?utf-8?q?61rq2X7sAtAyFmxNG2OSB7BhdD0XcFv6DGdq3N8GR++G6hiNDsX/cZxOGhAufdSGV?= =?utf-8?q?d/+i74kXXbxRF3ZldEGV6Vo3KOkKgAXNamIgLB+VCC4TqO4pNDVk6erHUHcgyUifY?= =?utf-8?q?NPi3/VB6EBQZIa2xYZ2+AbSX8QWWwkOiICRNZgTAwcuolpHwksfmga8S36d6mu/5S?= =?utf-8?q?3aDpDkXhcHmRaAI4wJFN5KmmqfnmwVqOeg=3D=3D?= Content-ID: <0C02E46285954F4D8569410BCEA0378F@eurprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB3710.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c11578c-7fcc-47a4-4889-08dbcb6fe075 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:16.3254 (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: 1pIvwGhVxGNY7O5U3lPKRBNrTuZ2o0XunhKF1Y2fdlCAPsOoapOtgSwEyRGVFtNkDJvUSjwu+rk4mH1LvBLTKK2jAqjSaUM0miXV9Fi9Ezg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: s1xqamOyCo_cF0K__10qdjW3KjxVfRg- X-Proofpoint-ORIG-GUID: s1xqamOyCo_cF0K__10qdjW3KjxVfRg- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 Introduce "fail" label in init_bars() function to have the centralized error return path. This is the pre-requirement for the future changes in this function. This patch does not introduce functional changes. Signed-off-by: Volodymyr Babchuk Suggested-by: Roger Pau Monné Acked-by: Roger Pau Monné --- In v10: - Added Roger's A-b tag. In v9: - New in v9 --- xen/drivers/vpci/header.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 176fe16b9f..33db58580c 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -581,11 +581,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, 4, &bars[i]); if ( rc ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } - + goto fail; continue; } @@ -604,10 +600,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rc = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size, (i == num_bars - 1) ? PCI_BAR_LAST : 0); if ( rc < 0 ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } + goto fail; if ( size == 0 ) { @@ -622,10 +615,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, 4, &bars[i]); if ( rc ) - { - pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); - return rc; - } + goto fail; } /* Check expansion ROM. */ @@ -647,6 +637,10 @@ static int cf_check init_bars(struct pci_dev *pdev) } return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0; + + fail: + pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd); + return rc; } REGISTER_VPCI_INIT(init_bars, VPCI_PRIORITY_MIDDLE); From patchwork Thu Oct 12 22:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419846 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 04763CDB474 for ; Thu, 12 Oct 2023 22:09:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616066.957785 (Exim 4.92) (envelope-from ) id 1qr3s2-0001Hi-Kq; Thu, 12 Oct 2023 22:09:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616066.957785; Thu, 12 Oct 2023 22:09:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s2-0001FW-E7; Thu, 12 Oct 2023 22:09:30 +0000 Received: by outflank-mailman (input) for mailman id 616066; Thu, 12 Oct 2023 22:09:28 +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 1qr3s0-00016v-Lo for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:28 +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 01ef1e01-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:27 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqmlB008371; Thu, 12 Oct 2023 22:09:24 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-8 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:24 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:17 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:17 +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: 01ef1e01-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HKfg5qXdDexzLV0+sZbNbyvTpFHTwVC5+rRHRYnQj4SK+Xl0hOCChTqhFsmRDjK6hrkQcBA5Md4w6VfFjcz7hcCkIgPWW+CfiX25Xy7p4HkNqjQY8oITAD/n2YG7ZJPkr9G23BmtB+h+00JbmS6h2QI52e3BZAUaDpvjuoMfq08IitmRjg0kZrFg0OXY/wlJVOpL6tm7d51cH4L7WgWAKqIw+KVEP3GZUnr8ZZ54I7kLVpcyYwJxWvlbI4cwyfH2e+68DMlrgqNdqI+2I4Cm5e5S30SBaynbkLS+J8iYKhZ+NCsG6BcOc3OLGkPvXzQHiOj9okJ8coIvhN/S9C6dng== 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=sHEaJEc3G9E8e7KRUoJf4jCqFeFYGoQCExX39F4Rr1I=; b=RsiRUVP8cT+JS7Dw9wFSb/H4R+DZCcREN2y30ac875vhZqKpeqxLV311RQ14Wf8QsslJUFldkyla3T+opjtBzRbW6Wb8Py3uXcq0jFhKXpcgy7PfbTmSFNiWg0nN857wquTrqSoApcA6jJoY/JE8urhquy8W02LX6NTtaflKv9bAeyiKOllOB4NB6FEa3P2+YUPds3EUYLv1Y1w7HWA0phKbNq5jRRnWCUS/yaBejceHRmKfAOmHr1NshqK2GPhiYLZ/xPEuhYECfeAktuENLUy2yKrboVRq9+Oga6cl9tNqirQyfM9IoDSk8ovRic6XrgcX7vwDQ+eXXJOWmCTp0A== 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=sHEaJEc3G9E8e7KRUoJf4jCqFeFYGoQCExX39F4Rr1I=; b=KL1ebSqNDtsoco09bWyUcTxN0oR1TTeo/3xGTjP+GXZzZLpYGr7EZ5y0OKehB1Ds28MHVbKQnv4Zh2d3+d3M21sQC0M7UTonnFQoI5FBVR3/rY2jj7463qezz9nh4b+0ylwB1XzwCiO7Q4WfmJBph2rsN5XkSGlj4EmUUibgL4lpox+rRNL8QMJmnX+3I2DL36277iut03Bw2bn1ZTnk/Z1Ndj+eYrlXN5oMl2VKdcrRBMDpXq+OV7p90F/mxGeyC8qZFc7ypRHVR0LnwvpRPcKtcywkWLk4G5FFFeaKEyjfFduRpSZrxUveNoyzrbMAFb9ZIy2SJHhIYz5v1R/Ufw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v10 07/17] vpci/header: implement guest BAR register handlers Thread-Topic: [PATCH v10 07/17] vpci/header: implement guest BAR register handlers Thread-Index: AQHZ/Vi9sL7dfLy6W0u4NsE3jXsp9g== Date: Thu, 12 Oct 2023 22:09:16 +0000 Message-ID: <20231012220854.2736994-8-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 84293fd7-60c6-45d2-927d-08dbcb6fe0c1 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: g5TcQAGvDSz6D5rIRrUrWqzsLuXPF6SMdzA5Dv9UheJumLKqV6ToelEolQLEI9ILPkh0JyG9S9P60ujoliRBdhix1iLsr+BCGihJGR/QERnxVZxgHzWLWI3eBTP24tmWQmNFRa/Gq6xGv/bkj4XE/7yIvhsjJ0+DUPpyXROoj6kYxW9IIKSjMKw9muHhq0KZ8W79ooT/1y7Ehc5Xeio7UJDsB0avQKsSbX1XfQFstfSHySzJeyZc83ajarPUfVXw2qMIqveN5917cDziKM1ZZ7vpwpXOl9Nc/qJGPVpYBGG8wm0Sckp2E/jWkfATWP5qTRZZhvvTZrclh3kfjn8ubRCfP158gfNmiQaGnpGU55jNwAXwrSsJU4zC3KCr4mvNA3geiYqb/0r5OCmSkU6X1C69Kod228XXg6NA219umVb8GmKmI4qc48yKbA+f5oZSUJlVdZL6k3ik99KwSe4qMHy9nKDnOCSolcwLZvsyi1XoTjk7u5C4h61vhLzV4hT9xBfGMgEMz0g94HMzT/gtaUqKKlL5f+F2ucIgHkgk1nQEthEZqQQTaPtarOcYRL8xrz3GBApTCghOvv1Gtmb1rJqk6rCnS2yp73iaAxcImmPo0pEL9vmTi0RBGfgOXkCE x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0oODUwcBgKr4gqpn75YmGL+?= =?iso-8859-1?q?2GYSfZGSQinF3y6ess2CVsOpxIOT1uUP5h4P7HOkN9TSdEPHUeIUPlZ18RRT?= =?iso-8859-1?q?5p5+VLCXNQ28o1AdV8ZClF2hd8oZKmGhTjNVmyBwHBBCK0De1g9XCbNGEywh?= =?iso-8859-1?q?rXNZ6wUnFB/tz0sXP15qUqUkYk+o0w9zuUL7J0G0KVUDBrxrSlEpWKwMg8NL?= =?iso-8859-1?q?2ENvcktXYk3gmm5LQxZAaj8gqwT4P/SUcNkFmuwprKTZT92DOmH7J54ZKipR?= =?iso-8859-1?q?sTBZTyE/OickSfowpGMoO3psB7wLxdO3TDxLkm5ehZ6GXB4NfZlEUNuUy+BE?= =?iso-8859-1?q?Jxvo+eqdsJs+NMeXSJw4fjz0MBiyLs823WKktrPgyAUH8ObZh1zT1rSSuk5s?= =?iso-8859-1?q?1d5GMTF5MAm9zdqGtv4ztYfWEQM23SR8PxdUfxSUMmCyFizY/5DzHsO/Icsz?= =?iso-8859-1?q?U9zdk8x1a/FEigdQ7q4Z7H8FOAQC0FnkhvcMEZY+2/Z1rHPR8vShv+ISQdt6?= =?iso-8859-1?q?oh2zK4F8e7jiy6a4c5l1dsMRXVticzaqgaJZrQ5BbmgPPuIia9kPTPijmwZj?= =?iso-8859-1?q?IHifHRN1aDzpYmlSmqASRL8enpU9VbBiH/1ZtulAU/7ArppnzX2/XYNCSjAb?= =?iso-8859-1?q?RobXGzanaAMGhF+3KBUDglZ881MeXFz/m8M3ZXMkznNH0T7HohD/ZUjHRBVw?= =?iso-8859-1?q?WE0z6pjPodH8t71uAYjw+/3naXxJT6hQtst+MvY0qEd3+C+v/xvLIrbVxFr7?= =?iso-8859-1?q?XCwjc6cwtjFzuTFRO1zvm5s64pikSSI1E0we9X0ajcC43fpTikDADW5L0qzs?= =?iso-8859-1?q?PY9cHtewVAhHkiygJStllj5hbgvLnTNIGHBlSVElBjAVd6EcxPJn3rnnqgfS?= =?iso-8859-1?q?iUQPRYwlw+z4gFEz1HU21ylq0noF+yzMbBLcVVCF6KeJYkYjjIjZ3IsE8/n6?= =?iso-8859-1?q?gK5bjMzy13I2PW9SRl8dWKn87qZfm8hGDDgyXjXHSU9J8CV6qzBb84fra89U?= =?iso-8859-1?q?dhh7aGn5KUGerpTH6A4cWXxD6cggoG0WTJ2948C2U6qx1uMy4aF+9/JZ55CH?= =?iso-8859-1?q?gi23jFgjEy2SG47ApbK7BLEOLt81V83e9DPfVsTfC21Gdvb9eCfPIUfN8rbi?= =?iso-8859-1?q?C0A9liN+gTmDK3uXBcEj4TIvAYrwPdmP4PJj0ukkCyOB/Mq0w55PUN9S051M?= =?iso-8859-1?q?Fnvq4IMI46uFvinWdapzH6jHPoVUCPsjxXmIc0SDng2cjtKV0hFDAqj6A0pM?= =?iso-8859-1?q?zWeXVTP5ZLix3vjEENe4dOWmloI8AlxNBM7trftGU3lgG0SneS7dOhPnhg1R?= =?iso-8859-1?q?/RxgorMdR6RIfYmFh0XBXF8iNjdBPMBy5Wn23jJr7GLaoL8AzE0jP0qv+WwJ?= =?iso-8859-1?q?cVXVr3hm9guj0jR2BCXzDcNp4PoeUxXVINrv+QxS0+1L469DqwLEfwbjtfE6?= =?iso-8859-1?q?feFkIr7SqRlMV7RsDBIZEG98rpS1ywGn86piRoLPvogmXBdDIDPixgrkiCVt?= =?iso-8859-1?q?IXeVVS9ap+QEja5laTJQ21Y5q5YISHxBenoZsFpbvardtnl76RjuwtATtZ6d?= =?iso-8859-1?q?RBXUj4poUB3m56stKMLEPgTf7sgp5ItkG4VtGMPB6IXxRgX1CVoQL38PzPAy?= =?iso-8859-1?q?LKVjssCePjNgT66xcwZY3nhq76ycR50zgXKufnA=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: 84293fd7-60c6-45d2-927d-08dbcb6fe0c1 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:16.6198 (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: 0xjQaEJ1sdTbZRPOoTkk22uoYvAw8ba6sDXGfJkW0WSQNyRKfLCrAbAG84aGnZSw93AhJZttYWcscZltRqT4UkiyjKdGMeLsqCI9GIfIvEI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: Nj2eEDhtFVFt6sGLO1ttSKBvltZmPO8t X-Proofpoint-ORIG-GUID: Nj2eEDhtFVFt6sGLO1ttSKBvltZmPO8t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko Add relevant vpci register handlers when assigning PCI device to a domain and remove those when de-assigning. This allows having different handlers for different domains, e.g. hwdom and other guests. Emulate guest BAR register values: this allows creating a guest view of the registers and emulates size and properties probe as it is done during PCI device enumeration by the guest. All empty, IO and ROM BARs for guests are emulated by returning 0 on reads and ignoring writes: this BARs are special with this respect as their lower bits have special meaning, so returning default ~0 on read may confuse guest OS. Signed-off-by: Oleksandr Andrushchenko --- In v10: - ull -> ULL to be MISRA-compatbile - Use PAGE_OFFSET() instead of combining with ~PAGE_MASK - Set type of empty bars to VPCI_BAR_EMPTY In v9: - factored-out "fail" label introduction in init_bars() - replaced #ifdef CONFIG_X86 with IS_ENABLED() - do not pass bars[i] to empty_bar_read() handler - store guest's BAR address instead of guests BAR register view Since v6: - unify the writing of the PCI_COMMAND register on the error path into a label - do not introduce bar_ignore_access helper and open code - s/guest_bar_ignore_read/empty_bar_read - update error message in guest_bar_write - only setup empty_bar_read for IO if !x86 Since v5: - make sure that the guest set address has the same page offset as the physical address on the host - remove guest_rom_{read|write} as those just implement the default behaviour of the registers not being handled - adjusted comment for struct vpci.addr field - add guest handlers for BARs which are not handled and will otherwise return ~0 on read and ignore writes. The BARs are special with this respect as their lower bits have special meaning, so returning ~0 doesn't seem to be right Since v4: - updated commit message - s/guest_addr/guest_reg Since v3: - squashed two patches: dynamic add/remove handlers and guest BAR handler implementation - fix guest BAR read of the high part of a 64bit BAR (Roger) - add error handling to vpci_assign_device - s/dom%pd/%pd - blank line before return Since v2: - remove unneeded ifdefs for CONFIG_HAS_VPCI_GUEST_SUPPORT as more code has been eliminated from being built on x86 Since v1: - constify struct pci_dev where possible - do not open code is_system_domain() - simplify some code3. simplify - use gdprintk + error code instead of gprintk - gate vpci_bar_{add|remove}_handlers with CONFIG_HAS_VPCI_GUEST_SUPPORT, so these do not get compiled for x86 - removed unneeded is_system_domain check - re-work guest read/write to be much simpler and do more work on write than read which is expected to be called more frequently - removed one too obvious comment --- xen/drivers/vpci/header.c | 137 +++++++++++++++++++++++++++++++++----- xen/include/xen/vpci.h | 3 + 2 files changed, 123 insertions(+), 17 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 33db58580c..40d1a07ada 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -477,6 +477,74 @@ static void cf_check bar_write( pci_conf_write32(pdev->sbdf, reg, val); } +static void cf_check guest_bar_write(const struct pci_dev *pdev, + unsigned int reg, uint32_t val, void *data) +{ + struct vpci_bar *bar = data; + bool hi = false; + uint64_t guest_addr = bar->guest_addr; + + if ( bar->type == VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + bar--; + hi = true; + } + else + { + val &= PCI_BASE_ADDRESS_MEM_MASK; + } + + guest_addr &= ~(0xffffffffULL << (hi ? 32 : 0)); + guest_addr |= (uint64_t)val << (hi ? 32 : 0); + + /* Allow guest to size BAR correctly */ + guest_addr &= ~(bar->size - 1); + + /* + * Make sure that the guest set address has the same page offset + * as the physical address on the host or otherwise things won't work as + * expected. + */ + if ( guest_addr != ~(bar->size -1 ) && + PAGE_OFFSET(guest_addr) != PAGE_OFFSET(bar->addr) ) + { + gprintk(XENLOG_WARNING, + "%pp: ignored BAR %zu write attempting to change page offset\n", + &pdev->sbdf, bar - pdev->vpci->header.bars + hi); + return; + } + + bar->guest_addr = guest_addr; +} + +static uint32_t cf_check guest_bar_read(const struct pci_dev *pdev, + unsigned int reg, void *data) +{ + const struct vpci_bar *bar = data; + uint32_t reg_val; + + if ( bar->type == VPCI_BAR_MEM64_HI ) + { + ASSERT(reg > PCI_BASE_ADDRESS_0); + bar--; + return bar->guest_addr >> 32; + } + + reg_val = bar->guest_addr; + reg_val |= bar->type == VPCI_BAR_MEM32 ? PCI_BASE_ADDRESS_MEM_TYPE_32 : + PCI_BASE_ADDRESS_MEM_TYPE_64; + reg_val |= bar->prefetchable ? PCI_BASE_ADDRESS_MEM_PREFETCH : 0; + + return reg_val; +} + +static uint32_t cf_check empty_bar_read(const struct pci_dev *pdev, + unsigned int reg, void *data) +{ + return 0; +} + static void cf_check rom_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -537,6 +605,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->pci_lock)); @@ -578,8 +647,10 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( i && bars[i - 1].type == VPCI_BAR_MEM64_LO ) { bars[i].type = VPCI_BAR_MEM64_HI; - rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, - 4, &bars[i]); + rc = vpci_add_register(pdev->vpci, + is_hwdom ? vpci_hw_read32 : guest_bar_read, + is_hwdom ? bar_write : guest_bar_write, + reg, 4, &bars[i]); if ( rc ) goto fail; continue; @@ -588,7 +659,17 @@ static int cf_check init_bars(struct pci_dev *pdev) val = pci_conf_read32(pdev->sbdf, reg); if ( (val & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO ) { - bars[i].type = VPCI_BAR_IO; + if ( !IS_ENABLED(CONFIG_X86) && !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + reg, 4, NULL); + if ( rc ) + { + bars[i].type = VPCI_BAR_EMPTY; + goto fail; + } + } + continue; } if ( (val & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == @@ -605,6 +686,15 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( size == 0 ) { bars[i].type = VPCI_BAR_EMPTY; + + if ( !is_hwdom ) + { + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + reg, 4, NULL); + if ( rc ) + goto fail; + } + continue; } @@ -612,28 +702,41 @@ static int cf_check init_bars(struct pci_dev *pdev) bars[i].size = size; bars[i].prefetchable = val & PCI_BASE_ADDRESS_MEM_PREFETCH; - rc = vpci_add_register(pdev->vpci, vpci_hw_read32, bar_write, reg, 4, - &bars[i]); + rc = vpci_add_register(pdev->vpci, + is_hwdom ? vpci_hw_read32 : guest_bar_read, + is_hwdom ? bar_write : guest_bar_write, + reg, 4, &bars[i]); if ( rc ) goto fail; } - /* Check expansion ROM. */ - rc = pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size, PCI_BAR_ROM); - if ( rc > 0 && size ) + /* TODO: Check expansion ROM, we do not handle ROM for guests for now. */ + if ( is_hwdom ) { - struct vpci_bar *rom = &header->bars[num_bars]; + rc = pci_size_mem_bar(pdev->sbdf, rom_reg, &addr, &size, PCI_BAR_ROM); + if ( rc > 0 && size ) + { + struct vpci_bar *rom = &header->bars[num_bars]; - rom->type = VPCI_BAR_ROM; - rom->size = size; - rom->addr = addr; - header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) & - PCI_ROM_ADDRESS_ENABLE; + rom->type = VPCI_BAR_ROM; + rom->size = size; + rom->addr = addr; + header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) & + PCI_ROM_ADDRESS_ENABLE; - rc = vpci_add_register(pdev->vpci, vpci_hw_read32, rom_write, rom_reg, - 4, rom); + rc = vpci_add_register(pdev->vpci, vpci_hw_read32, rom_write, + rom_reg, 4, rom); + if ( rc ) + rom->type = VPCI_BAR_EMPTY; + } + } + else + { + header->bars[num_bars].type = VPCI_BAR_EMPTY; + rc = vpci_add_register(pdev->vpci, empty_bar_read, NULL, + rom_reg, 4, NULL); if ( rc ) - rom->type = VPCI_BAR_EMPTY; + goto fail; } return (cmd & PCI_COMMAND_MEMORY) ? modify_bars(pdev, cmd, false) : 0; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 75cfb532ee..2028f2151f 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -67,7 +67,10 @@ struct vpci { struct vpci_header { /* Information about the PCI BARs of this device. */ struct vpci_bar { + /* Physical (host) address. */ uint64_t addr; + /* Guest address. */ + uint64_t guest_addr; uint64_t size; enum { VPCI_BAR_EMPTY, From patchwork Thu Oct 12 22:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419851 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 30CBECDB488 for ; Thu, 12 Oct 2023 22:09:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616070.957832 (Exim 4.92) (envelope-from ) id 1qr3s5-0002WM-MB; Thu, 12 Oct 2023 22:09:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616070.957832; Thu, 12 Oct 2023 22:09:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s5-0002WE-ID; Thu, 12 Oct 2023 22:09:33 +0000 Received: by outflank-mailman (input) for mailman id 616070; Thu, 12 Oct 2023 22:09:31 +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 1qr3s3-00016s-Lq for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:31 +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 036dea3c-694c-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:29 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqmlC008371; Thu, 12 Oct 2023 22:09:25 GMT Received: from eur01-db5-obe.outbound.protection.outlook.com (mail-db5eur01lp2050.outbound.protection.outlook.com [104.47.2.50]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8dp-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:25 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:18 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:18 +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: 036dea3c-694c-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K01p0D6CTf1gJqbojqphmWFrqYpv3U2b5T130F9+y8xPt8mmHhLcS/g38NSfVCgVjJau+wJwcQScJiBUmgnbaseBHByBel2MgcMABUzoZ0BTjXmClUETTHRwXEpmGzcf0jA87HU3hFlm3jl8p2yniFkHIFiMebWBxpDX8YTrhFK6G2Bv186fuIO0m72nAxLYjPH7GH9tI1mtc8QS+f5vCxwEyZ2HJLZKlD6nePDuKtT2dqdiGW7FqC43ZkbDjoiBMBZNVhUN3mowySjGjkY+/0nNl0FvUydcfG42DJXPuVNVZnXiEXyUaBgURYDhns8vvLoAdEAKZFyVAgvKI0DVXA== 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=3CXc+8tX6pBxxfJFpCA5LYlgxAC78/KBYrjedW2YSTs=; b=aAR2gCzjmxBMHzjEyAMQnk6E5fnrRTbS4q0ULpDxzKFjsHj7s1RdJjqEliG1Byl+EyQ3cnbSVHLh8ohTMJOg9utnl7rUe3VLr7pbf0jtKKOU73LaFkFF/XY/2CL4Da8DmdxKalx1f/9bm4oSPzNN1uEiB61mOY3BMw00rPcNo+OAowjbR6JvRaceENDE1TibDZEnvzUiUe7RNPKD7Ss1245uIhuIq5oLyQ2gTeqOCeLX68jcmXYiAE/x3denuWc2ueObD0+irbwN7eT39C0G2KakW709Y37wWutDb4GY1nd4VWpBxR+nuLfkFAlpEQ3WdJx6T0SVMK+gEKEj7Ec6Mg== 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=3CXc+8tX6pBxxfJFpCA5LYlgxAC78/KBYrjedW2YSTs=; b=mFsLeuqU5CVV0qamOsO0ew1vbsWymMJ96rbk3rEiwtJUm+wqe9MSqZQEmoxytRFDp/iORH8DDEEEKRlAVQlh3wzOuYo+pOdjBDdVMlkx8km67C5JvOEB5tO5pHp4LYBD2YcN/BbB+b/gJXhnoytcH5R1xZaSWXdsZpyfdhq+GCmuAilWbmWkIEH/GQcpiF150YyGp422ZF61Ht/O/X41tEuEF89hP9LgKds9iwYpzL3une9AgCngmEhOYJ2vaUqe2PIpvwHrJief2PNqAJK4LcPUIYB8BgPlbD23iNERnE6t9KQDL7pkNOs/5VAQf0Dtl3inaU6nKDWdXArE4j5w7A== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v10 08/17] rangeset: add RANGESETF_no_print flag Thread-Topic: [PATCH v10 08/17] rangeset: add RANGESETF_no_print flag Thread-Index: AQHZ/Vi9FGz7fvuB1UuuzM8p/4QjlA== Date: Thu, 12 Oct 2023 22:09:16 +0000 Message-ID: <20231012220854.2736994-9-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: 50804346-9409-4745-3ece-08dbcb6fe110 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: WbdXn/iWcHUfvCky1h5v0IRMQybWxeH5I6vc7/G6AieH4buFhCm6x4z5Vrxyq6JI9StcvHXd+pCSK+B0X9eoo8SoJtubeyZ+ftwm+qQcbMvxeXoRWMisZrzhbO8IjrW9MMafR/Y941WGgiuVYV1jOL7yJTm3Us/i8vAgaVVVj4mn2DWjLR3Z4y/dWHjfuWoMhhbIlbdyYuYuZDW6Kz3VolWSpKffCjhgZaEPTnP6uLbvmCehAdVNy3s4tHX1BWq3lye4tvihu3+9nSKmW506rUjux1eh2mACvK/tiMnXjnDFuolSiBKftUmMNlCVD24LwWxSN5i2FB0R4X3u4yhuVDBGLOeA/U+sfekPBah+wbW0W2cPkE756dmMJG41VdL2b32d030hBmfTw8w9XbaqktRadfwnzTuBiMy24laOQRBV6ukyGZdNmnLbdSn9EgqJR/+jYuPg9Ro+W1UWrjBCtLYmCm8x+XF5FlcerUnFy9sv6LbJaFrals03EjloOFAUlEpx+HRARldTsD8NF4VQVriHbDlgd+BprElAb4mbd36+H245He+nUxDsQpBUvxFerhj5p/Qn1WVIRV4vn+O6uGugCymwViCfqub4VYQIrTJfuUwwMHDqwoH4MNS6weid x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?xyc9xJ94f5mYD7PnywC1qW9?= =?iso-8859-1?q?i3uRG+HqKKAW8XWZ5aGSXlOYEOP1WiNaAMGytDC6rF1hFlUT81J0D/9VHsgh?= =?iso-8859-1?q?/ygyQRN3sOg3fvWeu3qFKLYlHMxOS+1U4GDIHiuyoaGKUtnXoGJjg5dlwfSN?= =?iso-8859-1?q?f23edL5CjuTwP+smvph7DUYMQ4uliJrM1Q0sW5NAsZmBbYEnRx2yB1seLmH4?= =?iso-8859-1?q?YXOOcrxYo8/6+Pwg8HhKukR308wJiQ8Tc7EikwPv7eCtUdTZz5jWm1LeZb57?= =?iso-8859-1?q?5vF3swYYGIg6IipsG3S7ecrT5Bh+FrIattLK1X3UipRl+y49HwPce2bXQhgg?= =?iso-8859-1?q?Rl4VKknnYs2KScRh4oVyk8Umr5UMBvQ0KAzGW62fWBw1mCxl86p9lxDCZWv0?= =?iso-8859-1?q?dpyckbod/GlutiPA00Vtk4c161/lFCebIyMJrTa9udwV2QlTK7qYiYcPeIdH?= =?iso-8859-1?q?G/pX/bWo83FtKR/rAFLjTREPDqr7YhmvVOlupWcgp4K4AUBRBzc2O18pKsYZ?= =?iso-8859-1?q?712PXAbkzeMcseUs/SMkEReWbLb8cWAMH2A4n8MZzo2tdeOzuaE5BCjs12VG?= =?iso-8859-1?q?g4LUyPepVXvYexe/8No/ttF1+wwTv5He4GDmCiUVxBHLHdrKz/GT0/wOIVIS?= =?iso-8859-1?q?7s3s5AQ1FT/r7zyJsOSFS3KwOy/VtDcCzbGTswsfUInQsbxsvUc7LUnUlJXZ?= =?iso-8859-1?q?owwagfTSdHCIOZ7o46s6beniJoNLI4bPEJCVd6xaNQbgNTarSNrZUycsMFOY?= =?iso-8859-1?q?bYerEXcVh85gBLJa+FQPM5vbZbI7J4Fg14Q4qpen7eP8wE9Jx8D70CnkHgtM?= =?iso-8859-1?q?H5jah7FR8Jy3jfcdheHte74sPwUtTfERODgyVFZMi8dUOUOrxwMx1ASwjRvI?= =?iso-8859-1?q?ZdsA5nnUYCxMvc5BSRwtmfGwyDcmf3sBF3BeXyNlIMn/mGfP7TbbDJjnYEoj?= =?iso-8859-1?q?8xGXGzaOZKTWUUsJyYBiaJcTg+TxKi3vLIer6XqltilWY+4NP0s2BfA07Q58?= =?iso-8859-1?q?ONxBfkYI6NW5hwWmTgeLgpkRztz7WpkYZP1eusnpGr/5S5XY4eq8XiHk8+4i?= =?iso-8859-1?q?tDNYzbTHZs8/hqkndQXQOTy7MJuPR3FgURWnceA/fZ+NX8rrv6mg5GmhF1sp?= =?iso-8859-1?q?SivPI3R4dXD3+imyiwxqnitB1GW2F2mjOKiEdm9eTi/z5vraxAR0lYQU8MVp?= =?iso-8859-1?q?n9qc7PYNQXySp1tOXT6429trdQBCzJNmOxkn4q0WaAtrUXxluQDI9ZJW6MA4?= =?iso-8859-1?q?aNcmNGmpBFsmS7ZIw/5D9u1REC14MlKCOW4/S/BjJ4AuouxD2cE7yk0R52Tw?= =?iso-8859-1?q?3smOAbh+iDNGMIwXZ70mzCA+aPmhldShl3NZpsYMVHq8ur6dqxOoKMYlFf9w?= =?iso-8859-1?q?27A2T47EOnI+yk6oLoe3i51vu4B/z34RAHxVqIoN5KiVctku1jLwWTJjz90i?= =?iso-8859-1?q?1SVAJ1lEQdmXJx2p3lg0w/4HdJcqTk26cBaBxC7tMtxnP5ldPW0N8/pUZsOD?= =?iso-8859-1?q?97GSiHc2h44Buh7yjYEVSVFCAWarqeTy9nqHhFwse7IwdgCEVIUt2qNLpa/T?= =?iso-8859-1?q?QynmPG3D0o8AD/ZptRrBP8pSPXQwSUXfQlWMA35PVS15kgPRiWhUCaNdmLnC?= =?iso-8859-1?q?qOa+ximZaJBvK2igIOTQ9qmPRF/blMFDl+asaXA=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: 50804346-9409-4745-3ece-08dbcb6fe110 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:16.9516 (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: athmZe0YnSiUKlKOx/JaNiwB/22yXYb5ojlolh2IbIqs/Z0xfyUd9g4BfdIcz/6BwtBoskeCJ1WH8vLP5ODlrgjSW/CLXM1R19E38cX8Li0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: 3FMKdQ3tyOgELXzpi1gM4MVpENRkgynf X-Proofpoint-ORIG-GUID: 3FMKdQ3tyOgELXzpi1gM4MVpENRkgynf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko There are range sets which should not be printed, so introduce a flag which allows marking those as such. Implement relevant logic to skip such entries while printing. While at it also simplify the definition of the flags by directly defining those without helpers. Suggested-by: Jan Beulich Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Jan Beulich --- Since v5: - comment indentation (Jan) Since v1: - update BUG_ON with new flag - simplify the definition of the flags --- xen/common/rangeset.c | 5 ++++- xen/include/xen/rangeset.h | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index f3baf52ab6..35c3420885 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -433,7 +433,7 @@ struct rangeset *rangeset_new( INIT_LIST_HEAD(&r->range_list); r->nr_ranges = -1; - BUG_ON(flags & ~RANGESETF_prettyprint_hex); + BUG_ON(flags & ~(RANGESETF_prettyprint_hex | RANGESETF_no_print)); r->flags = flags; safe_strcpy(r->name, name ?: "(no name)"); @@ -575,6 +575,9 @@ void rangeset_domain_printk( list_for_each_entry ( r, &d->rangesets, rangeset_list ) { + if ( r->flags & RANGESETF_no_print ) + continue; + printk(" "); rangeset_printk(r); printk("\n"); diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h index 135f33f606..f7c69394d6 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -49,8 +49,9 @@ void rangeset_limit( /* Flags for passing to rangeset_new(). */ /* Pretty-print range limits in hexadecimal. */ -#define _RANGESETF_prettyprint_hex 0 -#define RANGESETF_prettyprint_hex (1U << _RANGESETF_prettyprint_hex) +#define RANGESETF_prettyprint_hex (1U << 0) + /* Do not print entries marked with this flag. */ +#define RANGESETF_no_print (1U << 1) bool_t __must_check rangeset_is_empty( const struct rangeset *r); From patchwork Thu Oct 12 22:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419854 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 55E0DCDB485 for ; Thu, 12 Oct 2023 22:09:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616071.957843 (Exim 4.92) (envelope-from ) id 1qr3s7-0002pG-0B; Thu, 12 Oct 2023 22:09:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616071.957843; Thu, 12 Oct 2023 22:09:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s6-0002p1-Q0; Thu, 12 Oct 2023 22:09:34 +0000 Received: by outflank-mailman (input) for mailman id 616071; Thu, 12 Oct 2023 22:09:33 +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 1qr3s5-00016v-1g for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:33 +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 04e62cb8-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:32 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqkS7008330; Thu, 12 Oct 2023 22:09:28 GMT Received: from eur05-am6-obe.outbound.protection.outlook.com (mail-am6eur05lp2105.outbound.protection.outlook.com [104.47.18.105]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8e6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:27 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by DBAPR03MB6376.eurprd03.prod.outlook.com (2603:10a6:10:193::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Thu, 12 Oct 2023 22:09:18 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:18 +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: 04e62cb8-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ClqvpfGUzGJTS1zkloI+Jb7/A4CoasVB3w78j8m/J0Rqx8+QaBbaz8exPkbifdGO0mPWTuIoPO3bQh/cfBKelGOkPP+ihLYWNYwE4f4F8fFp3gSQQEvEXSD0G4qKrbthSqU92T8Vq7SJLx1+7mXmga3d42Lce9LxGtdhQPPA30/04GyMVQQnbdoIt8vDc/2zdLIm4Hnf85IvTYbzymp7+xmhY1K4KaASc4u2YIFDH84kypeNIqG/6FxdWNDiEpDBCcFWdZ7M/b1reJhzNmrXz69iJivYT5y47ZXCFViYW1+c0H8xRv9dq/E3ZeHDx2jyA4ucfC3UU1Y7htqwjlCgPA== 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=WqFu7ENzCaUUEb1owleNXNDVOW0gyYfuYWQAj6HYjqM=; b=GLp+uLHgBlPVBealxURibDhEpcZ0o0ds4GV/5g9ei7AbjncGIlbcE8iN8+fleSyrtkt29S8q3NuWB0Fp5njvwRZhf6Bf4M8KTHyIWtk2OeGylpfAbCKwOMZzs89+Q8qWcujFRe3GqxJJwEw6wS/jsSvRkqyVGvF8YKpSnQdjjxupu5YW3/wdsNstqlms+i/Am0LzZW+SfrkG9axcTsXHdfl6iX3odhT3nyYm9Nroe5g2Bj4Uq1AIn4m1XqZCbTwjWYdP/BMtGr1e4bAcAgAyLD72EiaY4/ZAIPXiNtibH4lJB6avE8StML7wad9dq0u13/uLCZboD8WNYd2M99qP1A== 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=WqFu7ENzCaUUEb1owleNXNDVOW0gyYfuYWQAj6HYjqM=; b=j0+l/wT7XYT80yt3rK4SdeDSOW6xXvXJnTsyg5TibE5dy4EGmoLQymitLjLLpwgax2oxkbbS6dthMOEk3MP/zIrC5xE9tUj2XwtJmXVFFGCe/hCuTPFD/5SIE7CcPjpEaMfk2CanHxAptCKntxx6gW+ggsAZoKVXuMwkDzIHBKPdBCRH6MWbKiydC2erpm2sSpR9fPomsYYGb7AQ8JCg+yAffIi70/4dXMu5xgM6RMGDOFIbRzXBU/TugW7JS+B5yw9lcwf3vUWxX6aYIfGJXXJlMtRf+YHq9UlDlWrIBpAGYAEEV4fxiuQKDGXlfOX6ERb6wkE8pONf2ny/hyG9sw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v10 09/17] rangeset: add rangeset_empty() function Thread-Topic: [PATCH v10 09/17] rangeset: add rangeset_empty() function Thread-Index: AQHZ/Vi+5V9BMbiD1kqnOLtHs/D1yw== Date: Thu, 12 Oct 2023 22:09:17 +0000 Message-ID: <20231012220854.2736994-10-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|DBAPR03MB6376:EE_ x-ms-office365-filtering-correlation-id: ad3e8fd7-1644-4ae1-1401-08dbcb6fe147 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: dafA2DWolEtBzNinphf7l40wykR6Ps52HNA5GTSlmc6zFSFGe+LBt4P5KWYJANmEHnYJ8R40OuIb5mdfDlL+JeDhBqt62y3hfXOd2vM/nOwqzildndOhS7/sSIFdORR2zp74mIMmgoHZyBPGZG/Y/u0UGDdEKvwrZgydhi6IbPHV6vmCw3aY+FpXpUlO8RVdOjloBjK8EJVLja1NaoL3vDscvch6jfNEUSZV5Kw4Y8ZtVyvxdEMQBgadi1vuBkiyVUFAcMcSFiMk+0Rieitn4JneP2hF3XQnHRVyk6WpTge8Itjlsb0SST5SckXjgxcCi/XCs1Sz+Amv+Ld7tH9iOgDQTp6LHrOFv97gGm+p6VUpEzgqiG5ghsfXq2sxit5Zh7dmN44xaXVJP8LXbRKSRZ5oHXPI91o4arAI76b6krW2SWG8ZxhAqCUELh4zwKnsZRlSRyq1FDdnk9JFd7fYP9vdjGrwpAXaNqYF4xQrphQMP7Tsx+iJppa98MwhIaY7xA2NYNFlAaN56aNlzpVIZ99pOdJJfMUKbnRoMid4UFa8v5qAT2ldn6q5S/Nsqpol3RZctX6lFf0DGeM7NsL3/jf27ggrgvn8XV9kNMxffV/3af9tiICoSGiLg3MxZcM0 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(346002)(366004)(136003)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(2616005)(71200400001)(26005)(6512007)(6506007)(55236004)(36756003)(86362001)(38100700002)(38070700005)(122000001)(1076003)(83380400001)(91956017)(41300700001)(64756008)(316002)(76116006)(54906003)(66946007)(66446008)(6916009)(66556008)(66476007)(2906002)(8936002)(5660300002)(8676002)(4326008)(6486002)(478600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?FNguRjMLrctWsis3oh5k6rM?= =?iso-8859-1?q?LJ+BJ+qUFZpz8AYTALTJvUl8WsAHeSEXPjkqO/XC02p13/K7kbyltyFX4efZ?= =?iso-8859-1?q?E2ustXY6WFeLudHHnF6pwbGUWgaOnqqjPn5C8MbEoeo8jZzHwQ0ol5XOhvWw?= =?iso-8859-1?q?075XOtOwOSL+F5p1Dd1yXbXj1CBKu2b7y9yF19ekbcPUKplFnFdSM/yVuOpY?= =?iso-8859-1?q?qLdjUcsrkBAs2PXMIJLrNdK7NwZN3P3oWv13lwF9HnYKZ1H3zxeRQnBee0Qa?= =?iso-8859-1?q?iHuICtJDS+zyDyX0ag88r2qj490IKgx+bOMyWbVQglpEbMBQ9j9iqzVW+2Tb?= =?iso-8859-1?q?TFy4FrUlg5j5THUkxUSGZVze+IFDfkFqggyOZBWbi7VwPXl+ruG3OWr4ve5v?= =?iso-8859-1?q?LE4amN/w+Et+LNUX0FZkB+3yPPJ+wgo6B//yTcRWK+kQTSV4UQb7+6umaa3Q?= =?iso-8859-1?q?uoA5wK2WNPkgp1Lo/uD3CQ7wi/PocN4PKBpMf5LN5oilUWHtW9WWTDHq7zFs?= =?iso-8859-1?q?Kx5gmxPTccJS3ygffQIVNRhczL8OCa6FKv0G02wI+UrUGvhBo56VeI9BU2Sp?= =?iso-8859-1?q?2ddXRngnBMUuvkJnjNpkDT/ubSo1ELUnNPTuu9bPLwCiVsX7cIZzotwcSdW+?= =?iso-8859-1?q?8M2UN7XNxhIxMBZE1ITjgBrLqicNrqpq9dbfkb9GhjvRXkjJ4FJlnWZDD/+m?= =?iso-8859-1?q?tjUJR5QxX2ft3G2Xuy9eRAVU86CdY83c5JZ+5m4e2XLs0Q+Sq6y6qsHDNTG+?= =?iso-8859-1?q?1yGIM8Ko836/2YU4JnaBdXfVS1E7waxcxNdIxY+SD9wXm4FzPdKqFV4NbSTA?= =?iso-8859-1?q?t00YmcNEQh7d6EqrgegqDcxptIgtmYpL1KVLDGz8U0mRnIfIzwSKMYvrKcwB?= =?iso-8859-1?q?1GzODyPO6b/CCPfRMMyG60gGEdomX0UbIeZUjqcAOEKI0Qmz8NXcORAG2DJb?= =?iso-8859-1?q?5CDT4EnLf+PqIcRiuz8LU4w7F9WHUPOz60nFdllTcuc5pDTagnrBK/TEBbFl?= =?iso-8859-1?q?0UsUXsmIm/+1q+ngawcDyiU4jRQxH2h9E0mMzzFlb87LAVy9Dbywu13slHPJ?= =?iso-8859-1?q?dS7Qt6wnmPb5aoP+iPeIYKpfx32EQZgD6GHkgh6voXeZc7+1WJ7q9U1x1ick?= =?iso-8859-1?q?pAe/DlD6vB87yNOsEUogUSTs2jbd+s/3b89tR9olbXNgKZsGpeEGZhilZWME?= =?iso-8859-1?q?kNKXTny6FSSsXaztSKFrXi88IWt1IPznDN/6s+c/r+iS4ZN20EtP/xmn9ZYh?= =?iso-8859-1?q?OT63M+WPGO8a5uJySNie9ZCm4Az7m3Qz0IPbwCuSk4Bqf/svF0vWWz36nY6X?= =?iso-8859-1?q?rdw44NNjQN16MSELuB2RFqxcYXjp4kh0UZq4/Y3K1XjpLmNgRBvnpNi+dveW?= =?iso-8859-1?q?Z1H6ERaqQPHRP5osgR407ka5MI+1HU7Np+quNpBTSVjYBrUwfKkDtRhO6Vza?= =?iso-8859-1?q?88hbDIzzcdRjuNum/SP68anrFHPD1OgDoVzc+TwPXnTlMMAoR9xr66sULtzF?= =?iso-8859-1?q?A11+kmLuwbU34gaMMaKUyS/MY/YD6NpCoM2/ltiHNWiqN+xMUr6CkoC0+qKE?= =?iso-8859-1?q?ai4vdU08HSxiV42Az/CqeYh7ia0ZDH4DejiEZVwUKe6Zf+3eATLmLEzcNIOm?= =?iso-8859-1?q?L7cArsDjXFvkdHB5m3sAnpqzV1cwW5Zn0UqgtRA=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: ad3e8fd7-1644-4ae1-1401-08dbcb6fe147 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:17.1773 (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: TKGb42ebSqpbVCV3r2d3fNGjTY4qbRXJnXZTsDcsS7TK+nGV9rPaLlGYC552k9zmUHkhv3h51USFI+pJnzlIC8DDqRmhzkluAVmFAikBCTA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR03MB6376 X-Proofpoint-GUID: -Z955gI3G8DxrKjvTmp74BgdfJeP3YW_ X-Proofpoint-ORIG-GUID: -Z955gI3G8DxrKjvTmp74BgdfJeP3YW_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=705 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 This function can be used when user wants to remove all rangeset entries but do not want to destroy rangeset itself. Signed-off-by: Volodymyr Babchuk --- Changes in v10: - New in v10. The function is used in "vpci/header: handle p2m range sets per BAR" --- xen/common/rangeset.c | 9 +++++++-- xen/include/xen/rangeset.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index 35c3420885..420275669e 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -448,8 +448,7 @@ struct rangeset *rangeset_new( return r; } -void rangeset_destroy( - struct rangeset *r) +void rangeset_empty(struct rangeset *r) { struct range *x; @@ -465,6 +464,12 @@ void rangeset_destroy( while ( (x = first_range(r)) != NULL ) destroy_range(r, x); +} + +void rangeset_destroy( + struct rangeset *r) +{ + rangeset_empty(r); xfree(r); } diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h index f7c69394d6..5eded7ffc5 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -56,7 +56,7 @@ void rangeset_limit( bool_t __must_check rangeset_is_empty( const struct rangeset *r); -/* Add/claim/remove/query a numeric range. */ +/* Add/claim/remove/query/empty a numeric range. */ int __must_check rangeset_add_range( struct rangeset *r, unsigned long s, unsigned long e); int __must_check rangeset_claim_range(struct rangeset *r, unsigned long size, @@ -70,6 +70,7 @@ bool_t __must_check rangeset_overlaps_range( int rangeset_report_ranges( struct rangeset *r, unsigned long s, unsigned long e, int (*cb)(unsigned long s, unsigned long e, void *), void *ctxt); +void rangeset_empty(struct rangeset *r); /* * Note that the consume function can return an error value apart from From patchwork Thu Oct 12 22:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419849 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 63534CDB47E for ; Thu, 12 Oct 2023 22:09:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616076.957892 (Exim 4.92) (envelope-from ) id 1qr3sD-0004Jq-1H; Thu, 12 Oct 2023 22:09:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616076.957892; Thu, 12 Oct 2023 22:09:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3sC-0004JQ-RT; Thu, 12 Oct 2023 22:09:40 +0000 Received: by outflank-mailman (input) for mailman id 616076; Thu, 12 Oct 2023 22:09:38 +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 1qr3sA-00016v-2l for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:38 +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 06aca185-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:35 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqPBg007501; Thu, 12 Oct 2023 22:09:32 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8ed-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:32 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:25 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:19 +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: 06aca185-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SaNcNbe3UpKnrgHa3nrz9oOl2Vy+susreq27CaTZJj9u2jGjfLi6ObtW4P+JMm3uO502xVSAzmvfuAhUevajU1nRMSYO9FziXkqe2IT6zszxv9FJzYsDIkZFr6Y4cU2qcjdM21pWjDzCFxen6bv5GIilx17kCATnq51pRP/nkML5UjIuR5zhyJ22Xv+m8/ir5USK+QYR/YFpa9Oetm2G0Rv1o5G49nKsq0WaU9tW7jcpRLy1xdgQ48rkl46y5AbSAf77g311CFogdMp5DF568EPyj2/fVkJ+QacXNb8pSp2JZrpKy1tFvE0saHC9HmXFhXenlcgDAXZfq6jr2Ty/8g== 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=zRrQIG2V9z8F0Ugjpn5uJ8rRJhFipg3lIxGypqk3JAM=; b=cASQHk4D/LfgjcZkc7yP1DafXTnNx5OtLu4GBSsFfaSGMDmf77j21xNQLhHXiTheC/Fyhi39LQD0KDy5SknhU5Uy6K+JjmN6QcnDem8OTVu/Ap0ahriwE8cCQjDjbBDVd2m1jKx6Djv0kKa0o2XOjTdVkEomVDZS6EJ8LiR4Hka+64RX/8qnVkaObpd0GERIZJLS8T4mUKHmKelDtgluKtEW3hTU40Uw8fZYJxuA66Bj/PcM0FsGkU/hlrW5yBZZMyQ03f7kaXSCeb2KBVielsBD0YWP5t7IRRs1f3BGCRQFD9j6DlkbzudsQMHSH63yxYP/pvkR/LGRRR6mecM/rw== 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=zRrQIG2V9z8F0Ugjpn5uJ8rRJhFipg3lIxGypqk3JAM=; b=aQGJ9YDQJ/ZhLyA9sBWFVCaW/x1a4kT47xuQw4JE8lNl4Ijc7yvOaYAFZutCMb2UJTawhSqOmPposlBOeJreYrbAdOauKQOqbnMPM+e5rnVtSK680m8grPHSFb9GN8IbSED8BKnwQk8DngJZ7scG3SRVsLaEoUj3P+IZ82LxCcOE6nnE1UpzPHDcTfApPcTgaeAdFjnfSBmd4z/LNuhh9AtjImIlR9ozi0pdTjkaOoaD1nL6pwgi0Q+qSZ621sLTBwE2qs0slYpXpwVKQiy10ZTtICa58ympPN3cXrBvc+aYUnEwUCkBPg2WqHavuHrOtm/JXHUOlAh9v88FZ3RmKw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v10 10/17] vpci/header: handle p2m range sets per BAR Thread-Topic: [PATCH v10 10/17] vpci/header: handle p2m range sets per BAR Thread-Index: AQHZ/Vi+Y1LP9L+txUiVfqLkjSET0g== Date: Thu, 12 Oct 2023 22:09:17 +0000 Message-ID: <20231012220854.2736994-11-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: b5a8b96e-dc9d-4030-7085-08dbcb6fe1a6 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: +Fv8StPi9fs0dNdHZkYK/8YwBkxg/0pjjnMBOrB55iGM1J9b2xA9Hh6/RFIUGtWOtwPVDrHW+QGQBp7fLFKLp3KGdaJPYMgWXVNQ0eUSwdqDUxukKc5o0KHFm1Eoer4Y7w0D7tPHJB/gU0iC6Vb8mV61hllfA9zNyDR4/wtXvG78J+roTsPFuU3dlQB8P6haeZhjzbKA7AX1BtYpMnotdcj8TiCfT9coucBzCwZN5k844hQ/vabFfb10nac66DuB26DUxl+nltHuOeX13lWai7BYnbVO6e1DYrr6spXlUv6HNplArbTHKu2R/dtgLVy8YEXJIH0UuyEWv/4CLnSSi79AJ4/YYXJmjdd6GICd+gE3WOTRUEgowYY0bKltTei70T+Cjki6XEK/azAxJu/gWLed6WFlJ4OFajt2ussHHWPWyieC25MXsl1RC92H6JbLdL2+qTLChxfstIqR6v2qEe50UieUGrCasq6RPmvieaMwJYMjwfmr+rLrXIVZEVszqZ7IUQu0IhmmJOrNbvElqItCqmQkOdQ0XykZBWkYw+nDCkNRyowhWUPol5lcwUx6d40II2XaPTFEhSV1z04vQwj6g/h7JXLwo1ihj34/IkEL5N94q5PNKzRs9tK+tKzU x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(30864003)(6512007)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?A6BoYlf4Yl4hwQ+zXyqY1iu?= =?iso-8859-1?q?OIGy+n6Rp9NQXmrZuN8BIrL8XEWnsBd6yuNZ5K0YGaud0GLZVUpnasO6BPKD?= =?iso-8859-1?q?E9Q2wZKbaEKZSd15LyDBSJQAzMVxMo0NzdR2IHwKjR7N443qPPD04tHDbh8V?= =?iso-8859-1?q?ovPdhPl/Yuc+YkfOfx5AvkhZ8RWR2wdQeju8wcH/rQ2IRCB0hauAnU57T0yI?= =?iso-8859-1?q?pm++G7TLfFC1aJsC+BJYmj8haXtdjzP6D0BKWa+RDNbaxqgn9C/FIXftSW+D?= =?iso-8859-1?q?1nL3Zy1WAQJfJXM05V7zlXiljS6kJ42fmCgJjusWkI2SN6kSdzGPjWm+QUId?= =?iso-8859-1?q?C+p1F6wyqKI4rjcDeYsfUD8GXJKzA5/mvA90A9gvZPDJomOCsSPHMMuwR+qk?= =?iso-8859-1?q?SyRWGSe54E3lyzfs6QbC4+YKyYTKXvST+0HCvqU2uc+a9JGGfBG/H6RLYR3k?= =?iso-8859-1?q?oECCrHqjUoFs7XrsVomppxb/2WwQ+3jSkgQU2kpu5YBN6U0kirAGRO6cmhZU?= =?iso-8859-1?q?CrS8550E2B8I+H7NAd9/mMNwpPJv8jS+B0J/8Wdh97yuA8ihh/QxXa8YhFq7?= =?iso-8859-1?q?vdMogatVL9yz27i16BoP9rbB+EpWrtYUZPdCXDY7OsX+F9QZ90jymcLj8vPi?= =?iso-8859-1?q?HpU0aMAIQzoKiITJfutnWCexONh+VzXSaziEoypzuJ9In9xznb0zgir+OQBl?= =?iso-8859-1?q?fvdnEjtTCkSC06AtQs25td6GKA758crUulhSmhQL49LmHGZXkXRFyFs4NNEP?= =?iso-8859-1?q?zLIsg3VwHxT0+97fKdNrzmwa5QCc3Jdp8S6iyyV5HeLCvvBb0RUwGoPB4NMy?= =?iso-8859-1?q?X8juf3c8zwOKiHfoUkJlh+5CIOaFaaNa47q5Bl7W/2+D9QRqcTc6trHbycpJ?= =?iso-8859-1?q?pULS9GEABXGwB7Hoek6n76g79RhidMqIHi5rs4ltO8QccqzGLMBDY3WXKDE/?= =?iso-8859-1?q?OjmPQbAcnVEffHFJyyhXDWyNSYbP75ZYBGE66ODRv7mI9oV4mAaxIwzm3eZ7?= =?iso-8859-1?q?b4Z7dNv2gmDFtjpCuiDLkEkv3DpE1g0R+XklFTDt2qVHgI3/p71KHZcMX1Uh?= =?iso-8859-1?q?T8nc9M2UXSB+V9dA/m5sAeGA+DuCOmEMWSn5FwQ0o9CEoZNZSOMnzS4Zonmh?= =?iso-8859-1?q?aL3QCr3scIT4V4/FLK/T8Zo2cU9SxidJ0r5dKce7Z48BBY3OQMnrrJZFyt+0?= =?iso-8859-1?q?xNS0CtSOs/qBoIxduvlj0wbkl3bitmYhCing7vPrXubQouPd+5apgs/4OFs3?= =?iso-8859-1?q?mH8bcGWd1js77t9c6H5RNdSLhH5rtZTD/VTX4AvCgCvlY7AAjsZ3gS2diy8N?= =?iso-8859-1?q?TlZGmh0xf+EREqAOSVnQFs7ZBYrWjzQ3lsv0tJlN8OKZnR03dAWNzqPAB+6R?= =?iso-8859-1?q?0ypJJ+l3+FVpfuFo5aeX8HNmqJS8k+XW/g7qLe5jFYaTEdYm3lIwjLJHFOlT?= =?iso-8859-1?q?8NHbeWiGVzsU/hxIVE6U+gTWy0Q/TUSHop4VUO7/CM33rd97+oACnxy908eN?= =?iso-8859-1?q?VhE6yDhFEeSJYfJgfx/sa34WR+3zzcRR8ztjY4fkcgJSqSDYlW8xdcnnCmx/?= =?iso-8859-1?q?9XV9UNCC/JGL7d4JjWbKjcS0lOkwGYp8XSQsgjL4lVjJkmYurdOeHlpM8Ier?= =?iso-8859-1?q?0lEfwN1EAxGclS25QARFbeBsp206N/g8Bdgp8kQ=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: b5a8b96e-dc9d-4030-7085-08dbcb6fe1a6 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:17.4861 (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: 2EF5nD5fsGbeDMa+RbYmSOt7+d3btMuHhdjnar5ClRcCexsT6CW27ySb37eTqzWPVevuy4yFNlVHLW2xh1nVFOMxcOWV7/3jwHEL/ALGYb0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: 5BoxB-Lt0e24MYwbLkVZvjwROgstqp0F X-Proofpoint-ORIG-GUID: 5BoxB-Lt0e24MYwbLkVZvjwROgstqp0F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 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 Reviewed-by: Roger Pau Monné --- In v10: - Added additional checks to vpci_process_pending() - vpci_process_pending() now clears rangeset in case of failure - Fixed locks in vpci_process_pending() - Fixed coding style issues - Fixed error handling in init_bars In v9: - removed d->vpci.map_pending in favor of checking v->vpci.pdev != NULL - printk -> gprintk - renamed bar variable to fix shadowing - fixed bug with iterating on remote device's BARs - relaxed lock in vpci_process_pending - removed stale comment Since v6: - update according to the new locking scheme - remove odd fail label in modify_bars Since v5: - fix comments - move rangeset allocation to init_bars and only allocate for MAPPABLE BARs - check for overlap with the already setup BAR ranges Since v4: - use named range sets for BARs (Jan) - changes required by the new locking scheme - updated commit message (Jan) Since v3: - re-work vpci_cancel_pending accordingly to the per-BAR handling - s/num_mem_ranges/map_pending and s/uint8_t/bool - ASSERT(bar->mem) in modify_bars - create and destroy the rangesets on add/remove --- xen/drivers/vpci/header.c | 256 ++++++++++++++++++++++++++------------ xen/drivers/vpci/vpci.c | 6 + xen/include/xen/vpci.h | 2 +- 3 files changed, 184 insertions(+), 80 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 40d1a07ada..5c056923ad 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -161,63 +161,106 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, bool vpci_process_pending(struct vcpu *v) { - if ( v->vpci.mem ) + struct pci_dev *pdev = v->vpci.pdev; + struct map_data data = { + .d = v->domain, + .map = v->vpci.cmd & PCI_COMMAND_MEMORY, + }; + struct vpci_header *header = NULL; + unsigned int i; + + if ( !pdev ) + return false; + + read_lock(&v->domain->pci_lock); + + if ( !pdev->vpci || (v->domain != pdev->domain) ) { - 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); + read_unlock(&v->domain->pci_lock); + return false; + } + + header = &pdev->vpci->header; + 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->pci_lock); return true; + } - write_lock(&v->domain->pci_lock); - spin_lock(&v->vpci.pdev->vpci->lock); - /* Disable memory decoding unconditionally on failure. */ - modify_decoding(v->vpci.pdev, - rc ? v->vpci.cmd & ~PCI_COMMAND_MEMORY : v->vpci.cmd, - !rc && v->vpci.rom_only); - spin_unlock(&v->vpci.pdev->vpci->lock); - - rangeset_destroy(v->vpci.mem); - v->vpci.mem = NULL; if ( rc ) - /* - * FIXME: in case of failure remove the device from the domain. - * Note that there might still be leftover mappings. While this is - * safe for Dom0, for DomUs the domain will likely need to be - * killed in order to avoid leaking stale p2m mappings on - * failure. - */ - vpci_deassign_device(v->vpci.pdev); - write_unlock(&v->domain->pci_lock); + { + spin_lock(&pdev->vpci->lock); + /* Disable memory decoding unconditionally on failure. */ + modify_decoding(pdev, v->vpci.cmd & ~PCI_COMMAND_MEMORY, + false); + spin_unlock(&pdev->vpci->lock); + + /* Clean all the rangesets */ + for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) + if ( !rangeset_is_empty(header->bars[i].mem) ) + rangeset_empty(header->bars[i].mem); + + v->vpci.pdev = NULL; + + read_unlock(&v->domain->pci_lock); + + if ( !is_hardware_domain(v->domain) ) + domain_crash(v->domain); + + return false; + } } + v->vpci.pdev = NULL; + + spin_lock(&pdev->vpci->lock); + modify_decoding(pdev, v->vpci.cmd, v->vpci.rom_only); + spin_unlock(&pdev->vpci->lock); + + read_unlock(&v->domain->pci_lock); return false; } static int __init apply_map(struct domain *d, const struct pci_dev *pdev, - struct rangeset *mem, uint16_t cmd) + uint16_t cmd) { struct map_data data = { .d = d, .map = true }; - int rc; + struct vpci_header *header = &pdev->vpci->header; + int rc = 0; + unsigned int i; ASSERT(rw_is_write_locked(&d->pci_lock)); - while ( (rc = rangeset_consume_ranges(mem, map_range, &data)) == -ERESTART ) + for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { - /* - * It's safe to drop and reacquire the lock in this context - * without risking pdev disappearing because devices cannot be - * removed until the initial domain has been started. - */ - read_unlock(&d->pci_lock); - process_pending_softirqs(); - read_lock(&d->pci_lock); - } + struct vpci_bar *bar = &header->bars[i]; + + 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->pci_lock); + process_pending_softirqs(); + write_lock(&d->pci_lock); + } + } if ( !rc ) modify_decoding(pdev, cmd, false); @@ -225,10 +268,12 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, } static void defer_map(struct domain *d, struct pci_dev *pdev, - struct rangeset *mem, uint16_t cmd, bool rom_only) + uint16_t cmd, bool rom_only) { struct vcpu *curr = current; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + /* * FIXME: when deferring the {un}map the state of the device should not * be trusted. For example the enable bit is toggled after the device @@ -236,7 +281,6 @@ static void defer_map(struct domain *d, struct pci_dev *pdev, * started for the same device if the domain is not well-behaved. */ curr->vpci.pdev = pdev; - curr->vpci.mem = mem; curr->vpci.cmd = cmd; curr->vpci.rom_only = rom_only; /* @@ -250,33 +294,33 @@ static void defer_map(struct domain *d, struct pci_dev *pdev, static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) { struct vpci_header *header = &pdev->vpci->header; - struct rangeset *mem = rangeset_new(NULL, NULL, 0); struct pci_dev *tmp, *dev = NULL; const struct domain *d; const struct vpci_msix *msix = pdev->vpci->msix; - unsigned int i; + unsigned int i, j; int rc; ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); - if ( !mem ) - return -ENOMEM; - /* - * Create a rangeset that represents the current device BARs memory region - * and compare it against all the currently active BAR memory regions. If - * an overlap is found, subtract it from the region to be mapped/unmapped. + * Create a rangeset per BAR that represents the current device memory + * region and compare it against all the currently active BAR memory + * regions. If an overlap is found, subtract it from the region to be + * mapped/unmapped. * - * First fill the rangeset with all the BARs of this device or with the ROM + * First fill the rangesets with the BAR of this device or with the ROM * BAR only, depending on whether the guest is toggling the memory decode * bit of the command register, or the enable bit of the ROM BAR register. */ for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { - const struct vpci_bar *bar = &header->bars[i]; + struct vpci_bar *bar = &header->bars[i]; unsigned long start = PFN_DOWN(bar->addr); unsigned long end = PFN_DOWN(bar->addr + bar->size - 1); + if ( !bar->mem ) + continue; + if ( !MAPPABLE_BAR(bar) || (rom_only ? bar->type != VPCI_BAR_ROM : (bar->type == VPCI_BAR_ROM && !header->rom_enabled)) || @@ -292,14 +336,31 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) continue; } - rc = rangeset_add_range(mem, start, end); + rc = rangeset_add_range(bar->mem, start, end); if ( rc ) { printk(XENLOG_G_WARNING "Failed to add [%lx, %lx]: %d\n", start, end, rc); - rangeset_destroy(mem); return rc; } + + /* Check for overlap with the already setup BAR ranges. */ + for ( j = 0; j < i; j++ ) + { + struct vpci_bar *prev_bar = &header->bars[j]; + + if ( rangeset_is_empty(prev_bar->mem) ) + continue; + + rc = rangeset_remove_range(prev_bar->mem, start, end); + if ( rc ) + { + gprintk(XENLOG_WARNING, + "%pp: failed to remove overlapping range [%lx, %lx]: %d\n", + &pdev->sbdf, start, end, rc); + return rc; + } + } } /* Remove any MSIX regions if present. */ @@ -309,14 +370,21 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) unsigned long end = PFN_DOWN(vmsix_table_addr(pdev->vpci, i) + vmsix_table_size(pdev->vpci, i) - 1); - rc = rangeset_remove_range(mem, start, end); - if ( rc ) + for ( j = 0; j < ARRAY_SIZE(header->bars); j++ ) { - printk(XENLOG_G_WARNING - "Failed to remove MSIX table [%lx, %lx]: %d\n", - start, end, rc); - rangeset_destroy(mem); - return rc; + const struct vpci_bar *bar = &header->bars[j]; + + if ( rangeset_is_empty(bar->mem) ) + continue; + + rc = rangeset_remove_range(bar->mem, start, end); + if ( rc ) + { + gprintk(XENLOG_WARNING, + "%pp: failed to remove MSIX table [%lx, %lx]: %d\n", + &pdev->sbdf, start, end, rc); + return rc; + } } } @@ -356,27 +424,35 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) for ( i = 0; i < ARRAY_SIZE(tmp->vpci->header.bars); i++ ) { - const struct vpci_bar *bar = &tmp->vpci->header.bars[i]; - unsigned long start = PFN_DOWN(bar->addr); - unsigned long end = PFN_DOWN(bar->addr + bar->size - 1); - - if ( !bar->enabled || - !rangeset_overlaps_range(mem, start, end) || - /* - * If only the ROM enable bit is toggled check against - * other BARs in the same device for overlaps, but not - * against the same ROM BAR. - */ - (rom_only && tmp == pdev && bar->type == VPCI_BAR_ROM) ) + const struct vpci_bar *remote_bar = &tmp->vpci->header.bars[i]; + unsigned long start = PFN_DOWN(remote_bar->addr); + unsigned long end = PFN_DOWN(remote_bar->addr + + remote_bar->size - 1); + + if ( !remote_bar->enabled ) continue; - rc = rangeset_remove_range(mem, start, end); - if ( rc ) + for ( j = 0; j < ARRAY_SIZE(header->bars); j++) { - printk(XENLOG_G_WARNING "Failed to remove [%lx, %lx]: %d\n", - start, end, rc); - rangeset_destroy(mem); - return rc; + const struct vpci_bar *bar = &header->bars[j]; + + if ( !rangeset_overlaps_range(bar->mem, start, end) || + /* + * If only the ROM enable bit is toggled check against + * other BARs in the same device for overlaps, but not + * against the same ROM BAR. + */ + (rom_only && tmp == pdev && bar->type == VPCI_BAR_ROM) ) + continue; + + rc = rangeset_remove_range(bar->mem, start, end); + if ( rc ) + { + gprintk(XENLOG_WARNING, + "%pp: failed to remove [%lx, %lx]: %d\n", + &pdev->sbdf, start, end, rc); + return rc; + } } } } @@ -400,10 +476,10 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) * will always be to establish mappings and process all the BARs. */ ASSERT((cmd & PCI_COMMAND_MEMORY) && !rom_only); - return apply_map(pdev->domain, pdev, mem, cmd); + return apply_map(pdev->domain, pdev, cmd); } - defer_map(dev->domain, dev, mem, cmd, rom_only); + defer_map(dev->domain, dev, cmd, rom_only); return 0; } @@ -597,6 +673,18 @@ static void cf_check rom_write( rom->addr = val & PCI_ROM_ADDRESS_MASK; } +static int bar_add_rangeset(const struct pci_dev *pdev, struct vpci_bar *bar, + unsigned int i) +{ + char str[32]; + + snprintf(str, sizeof(str), "%pp:BAR%u", &pdev->sbdf, i); + + bar->mem = rangeset_new(pdev->domain, str, RANGESETF_no_print); + + return !bar->mem ? -ENOMEM : 0; +} + static int cf_check init_bars(struct pci_dev *pdev) { uint16_t cmd; @@ -678,6 +766,10 @@ static int cf_check init_bars(struct pci_dev *pdev) else bars[i].type = VPCI_BAR_MEM32; + rc = bar_add_rangeset(pdev, &bars[i], i); + if ( rc ) + goto fail; + rc = pci_size_mem_bar(pdev->sbdf, reg, &addr, &size, (i == num_bars - 1) ? PCI_BAR_LAST : 0); if ( rc < 0 ) @@ -728,6 +820,12 @@ static int cf_check init_bars(struct pci_dev *pdev) rom_reg, 4, rom); if ( rc ) rom->type = VPCI_BAR_EMPTY; + else + { + rc = bar_add_rangeset(pdev, rom, i); + if ( rc ) + goto fail; + } } } else diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index b20bee2b0b..5e34d0092a 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -38,6 +38,8 @@ extern vpci_register_init_t *const __end_vpci_array[]; void vpci_deassign_device(struct pci_dev *pdev) { + unsigned int i; + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); if ( !has_vpci(pdev->domain) || !pdev->vpci ) @@ -63,6 +65,10 @@ void vpci_deassign_device(struct pci_dev *pdev) if ( pdev->vpci->msix->table[i] ) iounmap(pdev->vpci->msix->table[i]); } + + for ( i = 0; i < ARRAY_SIZE(pdev->vpci->header.bars); i++ ) + rangeset_destroy(pdev->vpci->header.bars[i].mem); + xfree(pdev->vpci->msix); xfree(pdev->vpci->msi); xfree(pdev->vpci); diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 2028f2151f..18a0eca3da 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -72,6 +72,7 @@ struct vpci { /* Guest address. */ uint64_t guest_addr; uint64_t size; + struct rangeset *mem; enum { VPCI_BAR_EMPTY, VPCI_BAR_IO, @@ -156,7 +157,6 @@ struct vpci { struct vpci_vcpu { /* Per-vcpu structure to store state while {un}mapping of PCI BARs. */ - struct rangeset *mem; struct pci_dev *pdev; uint16_t cmd; bool rom_only : 1; From patchwork Thu Oct 12 22:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419848 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 3187CCDB483 for ; Thu, 12 Oct 2023 22:09:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616074.957869 (Exim 4.92) (envelope-from ) id 1qr3s9-0003WQ-ML; Thu, 12 Oct 2023 22:09:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616074.957869; Thu, 12 Oct 2023 22:09:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s9-0003VC-HV; Thu, 12 Oct 2023 22:09:37 +0000 Received: by outflank-mailman (input) for mailman id 616074; Thu, 12 Oct 2023 22:09:36 +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 1qr3s8-00016v-2F for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:36 +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 05e6990a-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:34 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqPBf007501; Thu, 12 Oct 2023 22:09:32 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8ed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:31 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:26 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:26 +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: 05e6990a-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HIVHukI6DY1jicziqQA9sKEXzCbKwJItULBXDfw44l8oTiQd5UHj30XkQKSbUTW8xg6GEHKcT8bOmQcZ8tOw+OGYaJj+ZE+01P2bvsgGRdd52Xxg2eMw0D3tH5v2KrxP0XtiCx+EWdlA1AyFXwuidafbQM/sWfebTMwkiddtFC8p60aehW40hmaQT51zolfQZtfrFBGIqFnCRIevtF9bVquTEkMuVIOp0EtlXXawbY0XBacWKTXqb4JvQP+/FBfC8nLte/Fw7d3Eo8l9ZbUvCRpHaA+G8tmQBbTOlXgtiqTBEwkAXah1K5xc4fw2mdpk2ecZ9kN/rXW7Iq5ktwZj1w== 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=UYZ7tRQPfqclo5BluXN3478d5t09C8GyH1jJk/ns/pQ=; b=KqrHHCJpc/jme8Af4CSo1RhMS+PGbY5aUbVpjnYoMiKZWpuZpGcu2f+qUq3pz+7Q2Oag2C0YM88EYBt59g+OVKUNg5UAP3Kei26k0Q6e70c7QdM29nqyZKceklaN/oNGOhtHa/sKxynqdetdbMppnQ8h+GtKnvYyRcuZgyklGh5XhUXgiyeB0S/2bWTHjapdwBs8k+cEDfn7vNwzGRIAUExvUqLrCsUx2ntkqNuVW1ADX664CbvC62mcuTW3tHLW42x1+LyhXryti8+VgZDOwiON0wzqVVCoPtCLSthqOf87vYrTvKryQJPHftm9I1I4N9uMlJF3/owqFoFNcpD3OQ== 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=UYZ7tRQPfqclo5BluXN3478d5t09C8GyH1jJk/ns/pQ=; b=A020tdTt/LnAUbUdlSAH1lxTPi/QJYGDVuOQVJanlU3vs/JZWOtpNj9qkEpjAid6Ef5RmEPZzZhV2qQG9a5tjbPO+jzVAH0raaSvqX9fAsFpcgjYUnqRMci3sH1z+u2OEJEpRnm2CZGKUQpxMapD62fwTeB2/FmxgkuFW45vPiWApvU1idW6Yh+1TNSXiQVFoRSaR1sMH06otWPzFFdjA5mgZTswSpJCQBwdT2OPvrNsyKKooIHsPqCIQZ7zhwOkPay34XF2sliyu5vbrwjn/SlqwNfHjE9kY+xHr5PlO1s1v+TrmYZcZR2YArBj++fOWTDSAySS+aJAglxljJPYgw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v10 11/17] vpci/header: program p2m with guest BAR view Thread-Topic: [PATCH v10 11/17] vpci/header: program p2m with guest BAR view Thread-Index: AQHZ/Vi+CbAsU1ux6EmeYOWm6y793A== Date: Thu, 12 Oct 2023 22:09:17 +0000 Message-ID: <20231012220854.2736994-12-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: ba9fd60f-357f-4ec3-554a-08dbcb6fe5cb x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0GRauQs9UdBcf+2FeoY+B2HQCuG43gxyIhOjyDowXYEcNfk0hlJ/aKue/3A0HCKxM2KX+P8gnVsy/IzXt0uBLb7Fid52HoqSGQjUmQNAB4s1O1GYjeUMTfXmjykeyVZiutDTCYSHXdfoXGBMOFNYKaAwL9GQ49bkirmTfB4uDvx3dPzOPCuRS7G9VCT7wDoYn35Adg0/rmIhZNkF9Yqtv7jKRrZdeoAwFITbZZf5u5yMYLlcQnDMT4ikJ26H2LBoCs834JrNZiwiHpT8mfnURgyjk3k/9xTQpy1gFrgNbQphO5hHpDbNjxZGXLUs388Ltyb8MJM2Buo8iq8oWP/8C3O4F80qcRtuVOO4uacNTEiU4ffMfyfeMh8WOGWKFUBFm/ZMeEiMjtraVCwMiC+zqTVdhIKERnbyErX/HyvnWY4OX0lJjqJT3AFzs8yPfdo4/Rd+AN9aKvjC1/gY6FZSpYN3kojyy8D1FH0DtluWgTDC5JUgKgweUD+J141lS+VQDuVN1UK9ysqVHVYdq8E4c2KRJ2zsPVZQmBzpvt0KSOsHkKaa47jbP+6lSQSWXuxQFOFQ3KVKD1F+HVZ0vPQGAdeRZElgdL0KJ903vGArriU4WX6B8Z9k1kFPG2ic3ByK x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(107886003)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?XkdPP6w69Br1ezKwLvmKg0T?= =?iso-8859-1?q?NdeSoy5aeVIY8gCgMpw7OMIQ93E0OaUIvfEfy0j68io7fpp+4Nyg+8jxZJpK?= =?iso-8859-1?q?uryyVBJtEhc2BHXOPGOGjnNg/gIbF6Br8Jx+gRjU9ZiJwHB+rxit1Lt8RLcR?= =?iso-8859-1?q?nkAFstXOa1d87OBcoYAW46NjzAmNfLPwoHaQ+uKSZ6rDOlXJeS7qAqh31nMA?= =?iso-8859-1?q?KftbATSTI6eS8EUExvtaXLj2IIEbeS8RF6aXhjcRkjlVFRco0THy9kGsDtlQ?= =?iso-8859-1?q?1BlBDqlRtDIlSVD5/14o/hkQFuOMU9vU0LQvGwROWIdh6prHWTL1uZbKoyr8?= =?iso-8859-1?q?mU7AsS/r9eLdMY8XSY8qGI4l5f4k+dmH2nvNZ8TF6+gaycgFL3UUCPHGzaf4?= =?iso-8859-1?q?0i92bXYXjgQomxVxXMSxFXBjjOcuPe5lsqT8gfmYHqEXbcl5bjPzAduuj2BH?= =?iso-8859-1?q?dt/3t9JnkEM0wx1MrzQn7v5obzlFLdX2egODtVUmfeBO7/rWIzB8AEHUE569?= =?iso-8859-1?q?kVLhIAyrQaf6D6kRDEjst14XlzL6gJy/nVaRkFlIaqxSuC5GidsaCXOMap9P?= =?iso-8859-1?q?nC2tMREeVGeW0fdPZs8mE/g96wfj5G29KJigv76LuFpYojL4F9BX0OU1n/Nu?= =?iso-8859-1?q?uWGqSb245asqyd8dFci5sLHnc7Nw/jd6Fvh9STCqs9tcvn959WXXJXdqmreM?= =?iso-8859-1?q?0MgeN/gzB9W9cuM47gAcNj0AiccGswBX742b6ds6aMjk+1BA68nrt4IY1KDy?= =?iso-8859-1?q?44M3pu31IAe/+zo4B5IdUHPHj2wcYmoUmrbKfwpa7vdZTTilkEMlzzyI3bBJ?= =?iso-8859-1?q?s39i0o2D2vWAdRQHAeKMRDc+4gErx2lKsvVSMBTkwC3zHEZOCtTGi/TGvRbZ?= =?iso-8859-1?q?5yMPPlTUXmRDkCW3/usJRLmanhrUK3Qtelo2L1dRu9jCa8gB3K0UbVZs1lqw?= =?iso-8859-1?q?1BnytV1hRgT751z0Xe2d53Ems5hXAYEi7V/pOpD+L/2PPPPkfcOWmRYObNRA?= =?iso-8859-1?q?kTQkinJ+glsIL2lwalvKBHxiHZJqYGtX1pTc0tbt53IMdob2h7jPxFCyhVFg?= =?iso-8859-1?q?eSP5Lt/TgmTFy8mbZp12DMCejj/0ZCwRb1SVInMwhqHMyyNldNYXb/Eqdfee?= =?iso-8859-1?q?yI/7fP2br/cHrIOD0E5dkMr3+Wn9M1nRrLVFdI3rwKyytjiJO8JfNhvdawDt?= =?iso-8859-1?q?eJYfkprq0+mpvDNgB2GyUeo3sU7TA4M+TfI5QZ6ukbra1JA/Hm7L/+C0CFWl?= =?iso-8859-1?q?LGxtUQuJ4guuo2UJQPH0Bif7fFNmPewaV6wmuf02TIXg1bPW/KaYnoIF1j95?= =?iso-8859-1?q?PvokIO7K78j3NqXL8dEvcTkZXO/iw1MfUfYyu9QJbMAdEvd25r5mkap/zlDx?= =?iso-8859-1?q?dI/pYsMJ7ih3CV6Kkxc1145I3W2nABIUjiIAhK+jOqRxkQ8M+2pX7w9qovuf?= =?iso-8859-1?q?Q+FCAHLMr3MqAAutCZ2q9O6wGex5jUzirQXUdnwoIyLjUVetnYKVxlrRsedi?= =?iso-8859-1?q?ZRjsToZdNVg0ziXKY5GmEfrXeVBzQRFb8AOcG7QZdPmDUNxuJ06Q4kjPiGvs?= =?iso-8859-1?q?LL82pYLklJMh/AujXjq2VBWHU/GGGKgbwjNdokCNDOy5uzQlXSAF2mOUIU25?= =?iso-8859-1?q?VIGehmc5kriZNJXYH9CwmLPSrWYboKOe7azJpfw=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: ba9fd60f-357f-4ec3-554a-08dbcb6fe5cb X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:17.8144 (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: 5rKKv0KTbESFSDGLgxlXR0Z7G/OyxDxb3d+nDK3y+WccxkgA3pS5nTkth/ud3p+ZOPJl9+LUUnOZ236JBLkfMePS82DNFzyM3gRUMEJGiyc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: N4wJ2Hy__vRSZRsiASKSz8UtEKzNkYHK X-Proofpoint-ORIG-GUID: N4wJ2Hy__vRSZRsiASKSz8UtEKzNkYHK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko Take into account guest's BAR view and program its p2m accordingly: gfn is guest's view of the BAR and mfn is the physical BAR value. This way hardware domain sees physical BAR values and guest sees emulated ones. Hardware domain continues getting the BARs identity mapped, while for domUs the BARs are mapped at the requested guest address without modifying the BAR address in the device PCI config space. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- In v10: - Moved GFN variable definition outside the loop in map_range() - Updated printk error message in map_range() - Now BAR address is always stored in bar->guest_addr, even for HW dom, this removes bunch of ugly is_hwdom() checks in modify_bars() - vmsix_table_base() now uses .guest_addr instead of .addr In v9: - Extended the commit message - Use bar->guest_addr in modify_bars - Extended printk error message in map_range - Moved map_data initialization so .bar can be initialized during declaration Since v5: - remove debug print in map_range callback - remove "identity" from the debug print Since v4: - moved start_{gfn|mfn} calculation into map_range - pass vpci_bar in the map_data instead of start_{gfn|mfn} - s/guest_addr/guest_reg Since v3: - updated comment (Roger) - removed gfn_add(map->start_gfn, rc); which is wrong - use v->domain instead of v->vpci.pdev->domain - removed odd e.g. in comment - s/d%d/%pd in altered code - use gdprintk for map/unmap logs Since v2: - improve readability for data.start_gfn and restructure ?: construct Since v1: - s/MSI/MSI-X in comments --- xen/drivers/vpci/header.c | 53 ++++++++++++++++++++++++++++----------- xen/include/xen/vpci.h | 3 ++- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index 5c056923ad..efce0bc2ae 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -33,6 +33,7 @@ struct map_data { struct domain *d; + const struct vpci_bar *bar; bool map; }; @@ -40,11 +41,21 @@ static int cf_check map_range( unsigned long s, unsigned long e, void *data, unsigned long *c) { const struct map_data *map = data; + /* Start address of the BAR as seen by the guest. */ + unsigned long start_gfn = PFN_DOWN(map->bar->guest_addr); + /* Physical start address of the BAR. */ + mfn_t start_mfn = _mfn(PFN_DOWN(map->bar->addr)); int rc; for ( ; ; ) { 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. + */ + mfn_t map_mfn = mfn_add(start_mfn, s - start_gfn); if ( !iomem_access_permitted(map->d, s, e) ) { @@ -72,8 +83,8 @@ static int cf_check map_range( * - {un}map_mmio_regions doesn't support preemption. */ - rc = map->map ? map_mmio_regions(map->d, _gfn(s), size, _mfn(s)) - : unmap_mmio_regions(map->d, _gfn(s), size, _mfn(s)); + rc = map->map ? map_mmio_regions(map->d, _gfn(s), size, map_mfn) + : unmap_mmio_regions(map->d, _gfn(s), size, map_mfn); if ( rc == 0 ) { *c += size; @@ -82,8 +93,9 @@ static int cf_check map_range( if ( rc < 0 ) { printk(XENLOG_G_WARNING - "Failed to identity %smap [%lx, %lx] for d%d: %d\n", - map->map ? "" : "un", s, e, map->d->domain_id, rc); + "Failed to %smap [%lx %lx] -> [%lx %lx] for %pd: %d\n", + map->map ? "" : "un", s, e, mfn_x(map_mfn), + mfn_x(map_mfn) + size, map->d, rc); break; } ASSERT(rc < size); @@ -162,10 +174,6 @@ static void modify_decoding(const struct pci_dev *pdev, uint16_t cmd, bool vpci_process_pending(struct vcpu *v) { struct pci_dev *pdev = v->vpci.pdev; - struct map_data data = { - .d = v->domain, - .map = v->vpci.cmd & PCI_COMMAND_MEMORY, - }; struct vpci_header *header = NULL; unsigned int i; @@ -184,6 +192,11 @@ bool vpci_process_pending(struct vcpu *v) for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar = &header->bars[i]; + struct map_data data = { + .d = v->domain, + .map = v->vpci.cmd & PCI_COMMAND_MEMORY, + .bar = bar, + }; int rc; if ( rangeset_is_empty(bar->mem) ) @@ -234,7 +247,6 @@ bool vpci_process_pending(struct vcpu *v) static int __init apply_map(struct domain *d, const struct pci_dev *pdev, uint16_t cmd) { - struct map_data data = { .d = d, .map = true }; struct vpci_header *header = &pdev->vpci->header; int rc = 0; unsigned int i; @@ -244,6 +256,7 @@ static int __init apply_map(struct domain *d, const struct pci_dev *pdev, for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar = &header->bars[i]; + struct map_data data = { .d = d, .map = true, .bar = bar }; if ( rangeset_is_empty(bar->mem) ) continue; @@ -311,12 +324,16 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) * First fill the rangesets with the BAR of this device or with the ROM * BAR only, depending on whether the guest is toggling the memory decode * bit of the command register, or the enable bit of the ROM BAR register. + * + * For non-hardware domain we use guest physical addresses. */ for ( i = 0; i < ARRAY_SIZE(header->bars); i++ ) { struct vpci_bar *bar = &header->bars[i]; unsigned long start = PFN_DOWN(bar->addr); unsigned long end = PFN_DOWN(bar->addr + bar->size - 1); + unsigned long start_guest = PFN_DOWN(bar->guest_addr); + unsigned long end_guest = PFN_DOWN(bar->guest_addr + bar->size - 1); if ( !bar->mem ) continue; @@ -336,11 +353,11 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) continue; } - rc = rangeset_add_range(bar->mem, start, end); + rc = rangeset_add_range(bar->mem, start_guest, end_guest); if ( rc ) { printk(XENLOG_G_WARNING "Failed to add [%lx, %lx]: %d\n", - start, end, rc); + start_guest, end_guest, rc); return rc; } @@ -357,7 +374,7 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) { gprintk(XENLOG_WARNING, "%pp: failed to remove overlapping range [%lx, %lx]: %d\n", - &pdev->sbdf, start, end, rc); + &pdev->sbdf, start_guest, end_guest, rc); return rc; } } @@ -425,8 +442,8 @@ static int modify_bars(const struct pci_dev *pdev, uint16_t cmd, bool rom_only) for ( i = 0; i < ARRAY_SIZE(tmp->vpci->header.bars); i++ ) { const struct vpci_bar *remote_bar = &tmp->vpci->header.bars[i]; - unsigned long start = PFN_DOWN(remote_bar->addr); - unsigned long end = PFN_DOWN(remote_bar->addr + + unsigned long start = PFN_DOWN(remote_bar->guest_addr); + unsigned long end = PFN_DOWN(remote_bar->guest_addr + remote_bar->size - 1); if ( !remote_bar->enabled ) @@ -511,6 +528,8 @@ static void cf_check bar_write( struct vpci_bar *bar = data; bool hi = false; + ASSERT(is_hardware_domain(pdev->domain)); + if ( bar->type == VPCI_BAR_MEM64_HI ) { ASSERT(reg > PCI_BASE_ADDRESS_0); @@ -541,6 +560,10 @@ static void cf_check bar_write( */ bar->addr &= ~(0xffffffffULL << (hi ? 32 : 0)); bar->addr |= (uint64_t)val << (hi ? 32 : 0); + /* + * Update guest address as well, so hardware domain sees BAR identity mapped + */ + bar->guest_addr = bar->addr; /* Make sure Xen writes back the same value for the BAR RO bits. */ if ( !hi ) @@ -791,6 +814,7 @@ static int cf_check init_bars(struct pci_dev *pdev) } bars[i].addr = addr; + bars[i].guest_addr = addr; bars[i].size = size; bars[i].prefetchable = val & PCI_BASE_ADDRESS_MEM_PREFETCH; @@ -813,6 +837,7 @@ static int cf_check init_bars(struct pci_dev *pdev) rom->type = VPCI_BAR_ROM; rom->size = size; rom->addr = addr; + rom->guest_addr = addr; header->rom_enabled = pci_conf_read32(pdev->sbdf, rom_reg) & PCI_ROM_ADDRESS_ENABLE; diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 18a0eca3da..c5301e284f 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -196,7 +196,8 @@ int vpci_msix_arch_print(const struct vpci_msix *msix); */ static inline paddr_t vmsix_table_base(const struct vpci *vpci, unsigned int nr) { - return vpci->header.bars[vpci->msix->tables[nr] & PCI_MSIX_BIRMASK].addr; + return + vpci->header.bars[vpci->msix->tables[nr] & PCI_MSIX_BIRMASK].guest_addr; } static inline paddr_t vmsix_table_addr(const struct vpci *vpci, unsigned int nr) From patchwork Thu Oct 12 22:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419853 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 D3C28CDB486 for ; Thu, 12 Oct 2023 22:09:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616073.957861 (Exim 4.92) (envelope-from ) id 1qr3s8-0003Kc-SH; Thu, 12 Oct 2023 22:09:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616073.957861; Thu, 12 Oct 2023 22:09:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3s8-0003Jm-Mj; Thu, 12 Oct 2023 22:09:36 +0000 Received: by outflank-mailman (input) for mailman id 616073; Thu, 12 Oct 2023 22:09:35 +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 1qr3s7-00016v-20 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:35 +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 055714ca-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:33 +0200 (CEST) Received: from pps.filterd (m0174679.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CG29eN021659; Thu, 12 Oct 2023 22:09:31 GMT Received: from eur03-am7-obe.outbound.protection.outlook.com (mail-am7eur03lp2232.outbound.protection.outlook.com [104.47.51.232]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3tpcc6c048-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:30 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:26 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09:26 +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: 055714ca-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MeAe1z11V4yCH/nwHGCAa9MrU+IAY6nIC9xRcYwm6z1I9xJj3MrLXLUHMxTobHtDXu7wn7f50GszGUMnFkw5HEkSMSvo5/bgP70Ia3S9U8JKTmQLTDBu1PjUE4ZgjckdM0NRYUWXfqaEeZmRcg83+uEEA6Qk1oR0vpj6Cz/jok6Z09JjwkSFIiUXUBazl25LiMndb46VJVjekT2F8AYIcQ1HgrwLKKqb/FeXHTM17mF5GZsXYfTX+BViNGud40y0xuFYJBikHHs3zO0HFYBstI8cV4rXEnVBcMqShfAYMpNKg4trxbBf5fTzHZn8EtAqL3OwTWouVpoIL6a12TxBwA== 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=FxjLbTo8iMMJkl5SzG0dB3gVCQncYAbfISdfduk5+ws=; b=iBlRD29ZaXTmzVP8vksrzIGSnYGBYLcNRd31pQhay8GTIe275Q468eaB2q4+nrMOUGXTiYZ94sZZMLiYG+6JrHUMAxErr2e8vJOmQOCjQEV7wfScPM2o9jll/6SZxPUUdkLScsNYbeyAQ4xrisKEnn17p6hjWVwVZ4lJ+l/Ib30UYHSVAnpnkspHBSvv9fR5MvSOtNP5MxnR9t1RbkuqcsvMs2CcrTCd45FJ5kslTr0OOxm7qBKjja1YCvGJLZ0M2qmBYjFBpL5X6Y0FQO5GqugL5hNikv4MHtfr57vA1COhREgM4xBds8hEBL4lONpYLDkruOetIXdb15YD+QC+AA== 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=FxjLbTo8iMMJkl5SzG0dB3gVCQncYAbfISdfduk5+ws=; b=o1ny1wsRodTOPqoDT0iwdZrFqPvfdxeO196cJeFx19Ox1/8gZMdMTOhT8UMZ4w/McZBjy7whcYsV2W+9OWLIpVZ2LAUjgCyC8RutbNdHK3iTGxgiQOlR4EMETGJ4Gj+/vZg0B4in83Mp5hgq/SJiq9HbAAgN354jSv6R3eIbQgOa6uH1FRBaCX6c4lroATVPwDKU8iSPyCcaO9+sygWqWjqjI013dPNmciGgPPWEZmgWQi2uf+betUhijlcNQyJYp5LvURkE4WqpGC31fgoAbC42NUng3bskSyB1i5FHM4/VXlrmaxXYxtthHiqijdWK1gA98n3qJSsY4J5snFs2Kw== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , =?iso-8859-1?q?Roger_Pau_Monn=E9?= , Volodymyr Babchuk Subject: [PATCH v10 12/17] vpci/header: emulate PCI_COMMAND register for guests Thread-Topic: [PATCH v10 12/17] vpci/header: emulate PCI_COMMAND register for guests Thread-Index: AQHZ/Vi+sHqpo/XMzUSHL9PkKFM5oA== Date: Thu, 12 Oct 2023 22:09:18 +0000 Message-ID: <20231012220854.2736994-13-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: f2747525-f901-49f7-63dd-08dbcb6fe61c x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: XFYWFNcoiZlGzyj1dy0AJp8PtoYHfD/stRJ1jctbLu9C8au4lXgcewB/xwPymcy4+qSfzgeGkVQBcFQ11OOMiqJ5FYbUqZ0qsCyWblX4K6mPrH7vrX9Eb2RGC9XDyArqia6/kB3cRylAaWxoM0U0LRqO2nJ+XE7PYbd7YCZllL+Bh6APMp4SgH1y46KLCvqww2hd2Nc4ZcUe/2Uuq6dRUkWRsguJ089d/HRvHKmxBXqpDm2E7HM6+xF6NTYr6LF9Zc36xEo7mQwPCY8IKojgk0V5+zkj13aYvEW652jltnYA7sltifMmlHqTealGC5zomEGUGOSztJLaJCjGjroQ/n0PM9zKKB3dRrIsTnPq6Webh9KhcDIpMje30kCf8GOMCpipF8jwd17UaSqReug+eytCqPIXf8yZiSvohrTr0biYkU8aPIQEOdv9WRk9N/ooBxDVLJUHyX2jyYsXN+sI97shmL4Mwm5z/cfWtSuxeKNcfJkuN0ogew2/GBMt8mRBhJnNH577VKpIXXnQRCoiu8wONQ2qbpD8FSjcVeORMOUewDtd9VTEAC1R9tOryFOV87LSxGC/LQ8J5RouatD/0IrKzBssCpC2AIXq5lH4ls1ERi8tuYWV+wBcTWIfXUGi x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(107886003)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?rLRTpMPntF+kt8fSiqeOaGb?= =?iso-8859-1?q?KAdW3JUH6eJVKS2eXzd4MqLXwuvjaEeYhqaJYRHuv8dywfPcK3auubar7rZo?= =?iso-8859-1?q?+Pr0eCIob2KUzOeAu+V1oltVvHJEyPMGtYHEitEjV46uEB+7oTGb0K8ywdKH?= =?iso-8859-1?q?x9cG+z/FSnw/lEzKsiKChePGNExrOCWjcU77SSg2Ma4P69DKCk6FzMLVeRai?= =?iso-8859-1?q?OKFlMANxhQhCF74odTnaopvUocXIVx5CjMcN0m/v6O7SejlFI2ZZE3C4zL4r?= =?iso-8859-1?q?RupjVHJMk32prl46ZlFnCfFpRlj3dRpDxqPiwYxLe5rGZLmTIE+UUBwiJBS9?= =?iso-8859-1?q?OOwxlafJwIxPcpxF3vyAQ6pdK0J1QNs+IUuVlOHDMPoN8eYF7yMssqn2tA6f?= =?iso-8859-1?q?uHIzx2ADMorN7kshZOK9qBQg8TCtmwwmA6RyEdq4teTackS0Gw7YeafSPoDF?= =?iso-8859-1?q?3c3xrnu/1N8eA4bPT4FhxTdGlobGTJ4P9XxP355innSF182EzxR09AKiPLgq?= =?iso-8859-1?q?WD35Cd712sOzI+w74iKYCryd029cBZ6KD63Tmezdh8sN6aj6iQHZ2Jl6AWgp?= =?iso-8859-1?q?DM0ZvLuMzO+PmGKln+NkSLHs7I8hpgxce4IhkGgwK4tP5lx0I507nmWsJ5q5?= =?iso-8859-1?q?CNTEobK/KLJD//GxA2TEt1Fj1aqVPSQlI0dZon+odI38BPOx2Dqo2HyAYUAl?= =?iso-8859-1?q?Twi/4OiqAp7ulQHu+6HBoNYYbtTOWrwxoVP82t30/x9eWQ5NM2hBLQn3J3C5?= =?iso-8859-1?q?/1z5BZOHh4MnSw7kNlCEKslvEnRztUT2lYe7sLUP1g3rYgXynaMccBKb8zY+?= =?iso-8859-1?q?D/Kq4VtT/p19b3Yin+MoH/eqOUL0lU2WpFn9AhzeLq6N+ilDzv8CbYpzdTzY?= =?iso-8859-1?q?4J9WyHZTRhfjVWLPmaCpYCS4ftNAnBQoK8l66WrqIoNeSoetwhao4CR5DVUo?= =?iso-8859-1?q?JcnhVLOQ9zBDRIHvCbDyRvFn31uDr3Z7Pl0jD3URy02jr1S5tYHgwSs0O0NM?= =?iso-8859-1?q?2tyFLV9J6A7JP/FRTUz/28Ino9T1AP+6o5Bj+8GkGXJzd8dMacGtLYg1WdVo?= =?iso-8859-1?q?nuaEBzSW/E8V87uM/1tyauG3AnrxRJptWmwgq1RZVHsrfPS6/GRI+69qMk3n?= =?iso-8859-1?q?5b06h4LWfWjPOQQ3NM0XvvyRai1td9zL9uX5xPRMWeEN6LbT6L0PuVa7vORc?= =?iso-8859-1?q?l6gD+UgL83jbXns55fkcBgUEp/BPRtOy/yM19PdlkYtk70NEfUzMByF1hOe7?= =?iso-8859-1?q?cLaTM7FI+dEfseVO/0RbntmbiEPfBudCmiUPU+Uhm1+/lOBlDIBG3LWLa9KC?= =?iso-8859-1?q?qxLlist196+2ryHFkgZLqFB4We9D8M8j9AIcOx5ied3l5WQRlaN41u9OTC75?= =?iso-8859-1?q?MQ9jQ02oFM5fqLx3DqszdTY6/53c2Hw6a8FOU7NlpUdkiQ6sdTVZZ1XG4U7O?= =?iso-8859-1?q?Qo/3vA3U+SH6hh82ArsTktLvDZM/p8WLRE0FlplLyPR5dEDVBxDf5JDnCpIv?= =?iso-8859-1?q?tg1X0PXmn4wuzWZ7HaK4m6iborqri+l3Mcwl7n5ZTkOrxc8jipV3W4WTckFg?= =?iso-8859-1?q?mExOVtbtbkye0JhT1h7+KWFFgr3lup7y6nMh8Rbsx3hqR5zn97XV+dn43wnD?= =?iso-8859-1?q?0dyO+kFj1RTseI4zYk9+c8wEvgos7KbPz10ZPLg=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: f2747525-f901-49f7-63dd-08dbcb6fe61c X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:18.1381 (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: CshJD4+uYU9GB7h7iX8nMQx7PiyIxfkhfPBvvk7xNyfv1DkuO6Fd0cQ8ZEuyJou3jn115a81HOPS86xu/a49Tlebmbl6856yYSXswhZ7FcY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: 04X6v8G0BIywl6wgAQe7Iz8w0rtLWt-c X-Proofpoint-ORIG-GUID: 04X6v8G0BIywl6wgAQe7Iz8w0rtLWt-c X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 mlxscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 spamscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko Xen and/or Dom0 may have put values in PCI_COMMAND which they expect to remain unaltered. PCI_COMMAND_SERR bit is a good example: while the guest's view of this will want to be zero initially, the host having set it to 1 may not easily be overwritten with 0, or else we'd effectively imply giving the guest control of the bit. Thus, PCI_COMMAND register needs proper emulation in order to honor host's settings. According to "PCI LOCAL BUS SPECIFICATION, REV. 3.0", section "6.2.2 Device Control" the reset state of the command register is typically 0, so when assigning a PCI device use 0 as the initial state for the guest's view of the command register. Here is the full list of command register bits with notes about emulation, along with QEMU behavior in the same situation: PCI_COMMAND_IO - QEMU does not allow a guest to change value of this bit in real device. Instead it is always set to 1. A guest can write to this register, but writes are ignored. PCI_COMMAND_MEMORY - QEMU behaves exactly as with PCI_COMMAND_IO. In Xen case, we handle writes to this bit by mapping/unmapping BAR regions. For devices assigned to DomUs, memory decoding will be disabled and the initialization. PCI_COMMAND_MASTER - Allow guest to control it. QEMU passes through writes to this bit. PCI_COMMAND_SPECIAL - Guest can generate special cycles only if it has access to host bridge that supports software generation of special cycles. In our case guest has no access to host bridges at all. Value after reset is 0. QEMU passes through writes of this bit, we will do the same. PCI_COMMAND_INVALIDATE - Allows "Memory Write and Invalidate" commands to be generated. It requires additional configuration via Cacheline Size register. We are not emulating this register right now and we can't expect guest to properly configure it. QEMU "emulates" access to Cachline Size register by ignoring all writes to it. QEMU passes through writes of PCI_COMMAND_INVALIDATE bit, we will do the same. PCI_COMMAND_VGA_PALETTE - Enable VGA palette snooping. QEMU passes through writes of this bit, we will do the same. PCI_COMMAND_PARITY - Controls how device response to parity errors. QEMU ignores writes to this bit, we will do the same. PCI_COMMAND_WAIT - Reserved. Should be 0, but QEMU passes through writes of this bit, so we will do the same. PCI_COMMAND_SERR - Controls if device can assert SERR. QEMU ignores writes to this bit, we will do the same. PCI_COMMAND_FAST_BACK - Optional bit that allows fast back-to-back transactions. It is configured by firmware, so we don't want guest to control it. QEMU ignores writes to this bit, we will do the same. PCI_COMMAND_INTX_DISABLE - Disables INTx signals. If MSI(X) is enabled, device is prohibited from asserting INTx as per specification. Value after reset is 0. In QEMU case, it checks of INTx was mapped for a device. If it is not, then guest can't control PCI_COMMAND_INTX_DISABLE bit. In our case, we prohibit a guest to change value of this bit if MSI(X) is enabled. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Volodymyr Babchuk --- In v10: - Added cf_check attribute to guest_cmd_read - Removed warning about non-zero cmd - Updated comment MSI code regarding disabling INTX - Used ternary operator in vpci_add_register() call - Disable memory decoding for DomUs in init_bars() In v9: - Reworked guest_cmd_read - Added handling for more bits Since v6: - fold guest's logic into cmd_write - implement cmd_read, so we can report emulated INTx state to guests - introduce header->guest_cmd to hold the emulated state of the PCI_COMMAND register for guests Since v5: - add additional check for MSI-X enabled while altering INTX bit - make sure INTx disabled while guests enable MSI/MSI-X Since v3: - gate more code on CONFIG_HAS_MSI - removed logic for the case when MSI/MSI-X not enabled --- xen/drivers/vpci/header.c | 44 +++++++++++++++++++++++++++++++++++---- xen/drivers/vpci/msi.c | 6 ++++++ xen/drivers/vpci/msix.c | 4 ++++ xen/include/xen/vpci.h | 3 +++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index efce0bc2ae..e8eed6a674 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -501,14 +501,32 @@ 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) ) + { + const struct vpci *vpci = pdev->vpci; + uint16_t excluded = PCI_COMMAND_PARITY | PCI_COMMAND_SERR | + PCI_COMMAND_FAST_BACK; + + header->guest_cmd = cmd; + + if ( (vpci->msi && vpci->msi->enabled) || + (vpci->msix && vpci->msi->enabled) ) + excluded |= PCI_COMMAND_INTX_DISABLE; + + cmd &= ~excluded; + cmd |= pci_conf_read16(pdev->sbdf, reg) & excluded; + } + /* - * Let Dom0 play with all the bits directly except for the memory - * decoding one. + * Let guest play with all the bits directly except for the memory + * decoding one. Bits that are not allowed for DomU are already + * handled above. */ if ( header->bars_mapped != !!(cmd & PCI_COMMAND_MEMORY) ) /* @@ -522,6 +540,14 @@ static void cf_check cmd_write( pci_conf_write16(pdev->sbdf, reg, cmd); } +static uint32_t cf_check guest_cmd_read( + const struct pci_dev *pdev, unsigned int reg, void *data) +{ + const struct vpci_header *header = data; + + return header->guest_cmd; +} + static void cf_check bar_write( const struct pci_dev *pdev, unsigned int reg, uint32_t val, void *data) { @@ -737,8 +763,9 @@ static int cf_check init_bars(struct pci_dev *pdev) } /* Setup a handler for the command register. */ - rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND, - 2, header); + rc = vpci_add_register(pdev->vpci, + is_hwdom ? vpci_hw_read16 : guest_cmd_read, + cmd_write, PCI_COMMAND, 2, header); if ( rc ) return rc; @@ -750,6 +777,15 @@ static int cf_check init_bars(struct pci_dev *pdev) if ( cmd & PCI_COMMAND_MEMORY ) pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY); + /* + * Clear PCI_COMMAND_MEMORY for DomUs, so they will always start with + * memory decoding disabled and to ensure that we will not call modify_bars() + * at the end of this function. + */ + if ( !is_hwdom ) + cmd &= ~PCI_COMMAND_MEMORY; + header->guest_cmd = cmd; + for ( i = 0; i < num_bars; i++ ) { uint8_t reg = PCI_BASE_ADDRESS_0 + i * 4; diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c index 2faa54b7ce..0920bd071f 100644 --- a/xen/drivers/vpci/msi.c +++ b/xen/drivers/vpci/msi.c @@ -70,6 +70,12 @@ 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 b6abab47ef..9d0233d0e3 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 c5301e284f..60bdc10c13 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -87,6 +87,9 @@ struct vpci { } bars[PCI_HEADER_NORMAL_NR_BARS + 1]; /* At most 6 BARS + 1 expansion ROM BAR. */ + /* Guest view of the PCI_COMMAND register. */ + uint16_t guest_cmd; + /* * Store whether the ROM enable bit is set (doesn't imply ROM BAR * is mapped into guest p2m) if there's a ROM BAR on the device. From patchwork Thu Oct 12 22:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419861 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 16051CDB474 for ; Thu, 12 Oct 2023 22:15:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616090.957922 (Exim 4.92) (envelope-from ) id 1qr3y1-0002QN-Qb; Thu, 12 Oct 2023 22:15:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616090.957922; Thu, 12 Oct 2023 22:15:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3y1-0002QG-Nz; Thu, 12 Oct 2023 22:15:41 +0000 Received: by outflank-mailman (input) for mailman id 616090; Thu, 12 Oct 2023 22:15:40 +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 1qr3sH-00016v-Sm for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:46 +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 0c3c9fdf-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:44 +0200 (CEST) Received: from pps.filterd (m0174679.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CG29eO021659; Thu, 12 Oct 2023 22:09:33 GMT Received: from eur03-am7-obe.outbound.protection.outlook.com (mail-am7eur03lp2232.outbound.protection.outlook.com [104.47.51.232]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3tpcc6c048-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:32 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:27 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09: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: 0c3c9fdf-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q61p4uwi9nQLGSZCjjCKGrRLgMeuRGRt3tscWNCw+a9xalu2e7d4GFNOwtaAH+A9sjype9LLDeTRcV8pY3l+haaA6NfrMSzd2DrdEOFAwOCyYRTIz0VyinBXU7CTTREDxer/dEYptydIR4ces7c8ts6FV+Vax/GDUuDRCH+rer9Veg7mUuohB4UDy4q5sUJLYwvTxKuAmRi3B8098U5+3GxmwdGdYWEldKwZObJi1SAiFm5aq7/fIeVutZVFVWf6T2V+S/zbkisplmJaGUHOuAF/LpHa6pFYwCr3fY7XlAp6TfsBk4AgY48+5buvF/4n+j6QHD1W6o/l++zIlc4LPw== 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=gEhXn9ctGp3Gi+ciQHEpitWLa9ZFpk23aJZmdmWltD4=; b=XPaooHPLc7CSLX3+UjB9mfDODvmggXJWfekf9a0Qg6ljPaOsJ2sXLZz3qnaszOd6iXZc+O8nkCiiDih/G+Smg7EIybXhbpsij819X87tXjNUt+F9kKzKi0wNWpksF303XumAOt0LPfc7ypSbPSX8tw4Q0PHz7X62H71eN/6UHTelBu6KqwsrYYZbbXG5/8VfNwFTs/UZD/W5iEosdA6zSbfB5SQRM1XC6mp3xD3+WTWtIT1/ESWjHAdjrMbiPistsUX8nMIRZ60qZ6q7xtf2NSwNuR0ktOXSoRvsIJeBGvsPyHoWLm9f/LgXlfhCG6eDbsAC7LMaR09D5tCf3k4bew== 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=gEhXn9ctGp3Gi+ciQHEpitWLa9ZFpk23aJZmdmWltD4=; b=rrzUp/i1au7Pj2pr8aXijdoteTMcXvmKKZY9RuNfH/RrbXkJ4sqFw+3UeBKENKNe18ODqfajWpWigJ0/20B4B3kQliCWTOK4cfzuAAtoZGaLDN+/DztEKoKnpcdWWRknHaJmzPF7qtJG/2mfa6j/9ogENLFlPQCZcZ13jayL4q0kTqjSfA/digLbvHz/BCOwZhbtSsDKQMJLeM5whrLZ+NT9Y1g0n2EaimoUUAfGuAiwSBQgjzUTitcxjBcDLSgiegSa2d6bv4I5eUfMQz29ESurSath/B4QKcYncZZkocxOi2PdGBIHKePLF8OelesEaa7XeBGottlukpN5/23S0g== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?iso-8859-1?q?Roger_Pau_Monn=E9?= Subject: [PATCH v10 13/17] vpci: add initial support for virtual PCI bus topology Thread-Topic: [PATCH v10 13/17] vpci: add initial support for virtual PCI bus topology Thread-Index: AQHZ/Vi+wP3QsyKZ0EartcLXqtnBRA== Date: Thu, 12 Oct 2023 22:09:18 +0000 Message-ID: <20231012220854.2736994-14-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: af23428e-e030-405d-370e-08dbcb6fe672 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KGvcqEzkj68c298YWAZf1r/swsRacm2Nb8MF4H656bvNkjJAmeM0e/F/wJ7vpEUKI6l0F+YFBjsPTyQEtKlTg24AuyYJ4TvqVydZ/kY5QkqEYBExanVQOijSZu6bS/b4hDf7RqpFeKpgqrsmtGzCQV0wseW22Fdaxm5DyNF00wvg91OTan+RvZd1D3vi6ng6/cbpATq0UtakxWhXTRSZumiHnH0M+nE0pyctlEBy1jAVP4jILCdrk/lKd5UM9tbX/wi5fQDh/69G2lAenDCNGriAwxDp/z6TufKckQ4mF9tGTfK9rDg/aYdeqrgG3yOrXo4j/TNBOUxbGLi5gG3IWDjC4qrkLDgmnhf4REy/ddKajqLbQRgXcoF9GS5hbShKCFAe30riX+MKXluvn8206FNQw789TAWrIE3enlKszmOS/bazpT2NhoMpgHraB+UZ3R196m6dFaBaRNCnK5lydVHu+jOG8s8jyYMK1AO6Qzugc1eQJCgyU78bMK452AMnvM+7bQZFgXliNp/ooe6MGrwAkFdkNaB+zYhGLIPY7HKAJcWp7pp3olo/DTbvNcJv6Cn9JSailUEFbKP1JmNGxfJHvcFOUDwVfPrvTw4uqbd/iSbg+aIPG8CD6IwGWhFJ x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?MNkZ4Fr7Jqg1k7q+9gBDkwE?= =?iso-8859-1?q?8fmQcvMpmhPLS6rvj/7ko+dLHfDRWh+ZrdcRqCSnShNFsxttDNVkqNZgMNIj?= =?iso-8859-1?q?AYu4drhDGW6HE7iIdoxBlpsNF4DFnUC+bL5pWq2R3Com7JeoWCGuuKBVl28l?= =?iso-8859-1?q?BuoVzO8lx2nWGUdUMx65r/js9/AS07lMGHBw4RHhBv06smtykceYKLWaUFiQ?= =?iso-8859-1?q?06oJI+H+3gNfljt3GM78syW6vuPeH+nxJ3ofjUhyMZl+PmbmzlEPsvUSdyG3?= =?iso-8859-1?q?uKqEi/LYPBvh8Mtac0wus4jV4cJ3NIcAATSw3JF8ClZrenadaLv58QJyL8dK?= =?iso-8859-1?q?uTN9zTpGV2z2KpB7Ek/gpIXEjImTbEL11myZJgksL7JcYqT4YjnCDKv158FF?= =?iso-8859-1?q?l8R7nIhBlQIRmY1QyhpLAbqUv69o3d8hyZkIIYh1xG34jgNleycNDqbAGZhB?= =?iso-8859-1?q?XscWt0K9BnN9WZ8AJzOWyKeg+unh8ZVg+/zK8gbjTEVvwVZW3ZsP19oroHow?= =?iso-8859-1?q?s74lQ/lipV6K+9Ui/h5RZ78J+2jj1wEEkbKHZUV8mXDcrup863SPVAzohKvf?= =?iso-8859-1?q?W0x7Xw+mmVKWK4MIILnj8R/1xMv0AEPJ0jcWs6FR97OOrYgBFPASwhALNHF8?= =?iso-8859-1?q?DcknUApQovlcz2tyAz9STFYD+zZ2BEvjB9JJArTSb2DhdoqctFf9zRdSh+kc?= =?iso-8859-1?q?iI5cFaeLga8kZf8+dLrb/goJ46oDiFoVXjohTZwaVJr71gG2h+F1v8qA+jtj?= =?iso-8859-1?q?SsAZy5sbQtoIU9uRjgQICXuD/pv7mDvA1lknTpIggOAt6exGbIFLyTYHRvHk?= =?iso-8859-1?q?b+DHDd4oonllAN8s/PUMEjE/UHB9zJx3nBJiOh3z0ZOuwovKUU6rZLxOZ+K1?= =?iso-8859-1?q?7ovh8fafeXE1cuUygwI4N6jnxZMVoDvFiHnDJW0nPJGiQkIo2lYFdQO10nNp?= =?iso-8859-1?q?t7p8oAm07EdL/wv0VP5UgMKhMGFAx2GTmoWOhJzErzvYgyS+bzTjJk9PQ32t?= =?iso-8859-1?q?EvztSQaeNPwDdBe/aXEOHTXhDgDY3OJwipYBS5t1G3MuGdFffCW4rRvGDMIw?= =?iso-8859-1?q?gusy2MTNTARVkxkOIomZCxisbV21Vw5FMcN0l7UjKVgVVOB3TdGxTZOVJeaj?= =?iso-8859-1?q?E5T1LnTQ+Z0jZQFnFjHB2/zCWwoaNhvDNV0YfyplKalgqZsu1nbCz+vZQ6CP?= =?iso-8859-1?q?MmbdoSJrYJIIF2/ICKe1VWCRmCW0VZtwseSVz433dT9Af6bZff4x11OrcRZ2?= =?iso-8859-1?q?CT3bHsWR7mMOyjHIKOC0tnFW6OKRI6rNscpiJ2xuvNst9sB6ABiBuJAmGmxM?= =?iso-8859-1?q?SKVJWxAu0zCZCp+5EGwTaQm6CDEFyPZo4kiw4jSeCx2NM04Mo2xBXaxfDJzo?= =?iso-8859-1?q?7ZUlvnGEjW0A4eXSAPnJFtoUXmI1d8+JQbjde1fqu9leDoNWAjaQl2CscIzi?= =?iso-8859-1?q?APifi70hc+dbNwh1e0U7JFaS+j4mSyI8fdhV76NNHzuYP0mCzn11RWrBVVS6?= =?iso-8859-1?q?1IpvXzhMJfp91vNMnBDRxeel9lEmGTpLO76fRvW3FROCGUt8491PW+psRwXv?= =?iso-8859-1?q?CcEQrZI9djWLIw5F71HmW4DzBzYbC3BtjGeXgF8qLI/LTb7Up80zq9Qw9R4k?= =?iso-8859-1?q?fVLf/5jk2tX6fCsjhGAzUP6rbAPNJlu9RlV92JQ=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: af23428e-e030-405d-370e-08dbcb6fe672 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:18.5386 (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: 1qb5iQm3iKkzV2GNG76/ui4kQvK+5WOfYB6TtYRmZgC1gGCcUyvwUeh1pGcmTo/Ihtqm7DzeZtDRQoMxoiadQFKkX7qyHDkHKuCV/qw+WuY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: sRrPYYwi133mn3eTIeNbZIwA1anw6OwG X-Proofpoint-ORIG-GUID: sRrPYYwi133mn3eTIeNbZIwA1anw6OwG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 mlxscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 spamscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 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 --- In v10: - Removed ASSERT(pcidevs_locked()) - Removed redundant code (local sbdf variable, clearing sbdf during device removal, etc) - Added __maybe_unused attribute to "out:" label - Introduced HAS_VPCI_GUEST_SUPPORT Kconfig option, as this is the first patch where it is used (previously was in "vpci: add hooks for PCI device assign/de-assign") In v9: - Lock in add_virtual_device() replaced with ASSERT (thanks, Stewart) In v8: - Added write lock in add_virtual_device Since v6: - re-work wrt new locking scheme - OT: add ASSERT(pcidevs_write_locked()); to add_virtual_device() Since v5: - s/vpci_add_virtual_device/add_virtual_device and make it static - call add_virtual_device from vpci_assign_device and do not use REGISTER_VPCI_INIT machinery - add pcidevs_locked ASSERT - use DECLARE_BITMAP for vpci_dev_assigned_map Since v4: - moved and re-worked guest sbdf initializers - s/set_bit/__set_bit - s/clear_bit/__clear_bit - minor comment fix s/Virtual/Guest/ - added VPCI_MAX_VIRT_DEV constant (PCI_SLOT(~0) + 1) which will be used later for counting the number of MMIO handlers required for a guest (Julien) Since v3: - make use of VPCI_INIT - moved all new code to vpci.c which belongs to it - changed open-coded 31 to PCI_SLOT(~0) - added comments and code to reject multifunction devices with functions other than 0 - updated comment about vpci_dev_next and made it unsigned int - implement roll back in case of error while assigning/deassigning devices - s/dom%pd/%pd Since v2: - remove casts that are (a) malformed and (b) unnecessary - add new line for better readability - remove CONFIG_HAS_VPCI_GUEST_SUPPORT ifdef's as the relevant vPCI functions are now completely gated with this config - gate common code with CONFIG_HAS_VPCI_GUEST_SUPPORT New in v2 --- xen/drivers/Kconfig | 4 +++ xen/drivers/vpci/vpci.c | 63 +++++++++++++++++++++++++++++++++++++++++ xen/include/xen/sched.h | 8 ++++++ xen/include/xen/vpci.h | 11 +++++++ 4 files changed, 86 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/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 5e34d0092a..7c46a2d3f4 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -36,6 +36,52 @@ extern vpci_register_init_t *const __start_vpci_array[]; extern vpci_register_init_t *const __end_vpci_array[]; #define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array) +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +static int add_virtual_device(struct pci_dev *pdev) +{ + struct domain *d = pdev->domain; + unsigned long new_dev_number; + + if ( is_hardware_domain(d) ) + return 0; + + ASSERT(rw_is_write_locked(&pdev->domain->pci_lock)); + + /* + * Each PCI bus supports 32 devices/slots at max or up to 256 when + * there are multi-function ones which are not yet supported. + */ + if ( pdev->info.is_extfn && !pdev->info.is_virtfn ) + { + gdprintk(XENLOG_ERR, "%pp: only function 0 passthrough supported\n", + &pdev->sbdf); + return -EOPNOTSUPP; + } + new_dev_number = find_first_zero_bit(d->vpci_dev_assigned_map, + VPCI_MAX_VIRT_DEV); + if ( new_dev_number == VPCI_MAX_VIRT_DEV ) + { + write_unlock(&pdev->domain->pci_lock); + return -ENOSPC; + } + + __set_bit(new_dev_number, &d->vpci_dev_assigned_map); + + /* + * Both segment and bus number are 0: + * - we emulate a single host bridge for the guest, e.g. segment 0 + * - with bus 0 the virtual devices are seen as embedded + * endpoints behind the root complex + * + * TODO: add support for multi-function devices. + */ + pdev->vpci->guest_sbdf = PCI_SBDF(0, 0, new_dev_number, 0); + + return 0; +} + +#endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ + void vpci_deassign_device(struct pci_dev *pdev) { unsigned int i; @@ -46,6 +92,13 @@ void vpci_deassign_device(struct pci_dev *pdev) return; spin_lock(&pdev->vpci->lock); + +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + if ( pdev->vpci->guest_sbdf.sbdf != ~0 ) + __clear_bit(pdev->vpci->guest_sbdf.dev, + &pdev->domain->vpci_dev_assigned_map); +#endif + while ( !list_empty(&pdev->vpci->handlers) ) { struct vpci_register *r = list_first_entry(&pdev->vpci->handlers, @@ -101,6 +154,13 @@ int vpci_assign_device(struct pci_dev *pdev) INIT_LIST_HEAD(&pdev->vpci->handlers); spin_lock_init(&pdev->vpci->lock); +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + pdev->vpci->guest_sbdf.sbdf = ~0; + rc = add_virtual_device(pdev); + if ( rc ) + goto out; +#endif + for ( i = 0; i < NUM_VPCI_INIT; i++ ) { rc = __start_vpci_array[i](pdev); @@ -108,11 +168,14 @@ int vpci_assign_device(struct pci_dev *pdev) break; } + out: + __maybe_unused; if ( rc ) vpci_deassign_device(pdev); return rc; } + #endif /* __XEN__ */ static int vpci_register_cmp(const struct vpci_register *r1, diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 57391e74b6..84e608f670 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -462,6 +462,14 @@ struct domain #ifdef CONFIG_HAS_PCI struct list_head pdev_list; rwlock_t pci_lock; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* + * The bitmap which shows which device numbers are already used by the + * virtual PCI bus topology and is used to assign a unique SBDF to the + * next passed through virtual PCI device. + */ + DECLARE_BITMAP(vpci_dev_assigned_map, VPCI_MAX_VIRT_DEV); +#endif #endif #ifdef CONFIG_HAS_PASSTHROUGH diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 60bdc10c13..4a53936447 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -21,6 +21,13 @@ typedef int vpci_register_init_t(struct pci_dev *dev); #define VPCI_ECAM_BDF(addr) (((addr) & 0x0ffff000) >> 12) +/* + * Maximum number of devices supported by the virtual bus topology: + * each PCI bus supports 32 devices/slots at max or up to 256 when + * there are multi-function ones which are not yet supported. + */ +#define VPCI_MAX_VIRT_DEV (PCI_SLOT(~0) + 1) + #define REGISTER_VPCI_INIT(x, p) \ static vpci_register_init_t *const x##_entry \ __used_section(".data.vpci." p) = x @@ -155,6 +162,10 @@ struct vpci { struct vpci_arch_msix_entry arch; } entries[]; } *msix; +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT + /* Guest SBDF of the device. */ + pci_sbdf_t guest_sbdf; +#endif #endif }; From patchwork Thu Oct 12 22:09:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419859 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 9A917CDB47E for ; Thu, 12 Oct 2023 22:09:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616078.957913 (Exim 4.92) (envelope-from ) id 1qr3sI-000573-1v; Thu, 12 Oct 2023 22:09:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616078.957913; Thu, 12 Oct 2023 22:09:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr3sH-00056p-TJ; Thu, 12 Oct 2023 22:09:45 +0000 Received: by outflank-mailman (input) for mailman id 616078; Thu, 12 Oct 2023 22:09:42 +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 1qr3sD-00016s-SX for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09: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 0971534a-694c-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:39 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqPBh007501; Thu, 12 Oct 2023 22:09:33 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8ed-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:33 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:27 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09: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: 0971534a-694c-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LzqoB+T0mOkj9SjaXkk2OjtfC2eAIEXu+1BeNHtk3BrnFBo7ItIB0nId9nnnok/41bLscA+VP1XQb4hgqsgRPCXnkf7kXmQ7NngD3tsT9UfNIUPD/mJ4Pdmw8xDZ4hJX8Rz3uyMgn+yjXniA1XALDKP0Gj1o4ZpNDB/lAPCSNy4a0kzlsOqjPVSL64YbKneei0kcAAaOUtvUx5BGcT8YsBkaFG+N02XI6nKI6CTXbjPXquGqxKJwurgp/e8eG1FF+LouSqMFGomSUMYcEFFsUBLIdK2EK7QIwKF6m3bBXpiDbZIPm97LsQ5KB0tjXnIRbemJGhz4aQllQPj95gUFUg== 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=9cvt5808hHcwhF44p0mrt1sssUp8SRDE7SeZ89SeYcE=; b=DXq9tgR8B4jl0AcqqXKu2v/f0HFK2zkaGEeLRhDT5C3P+RpKV/WI8Oz75XfefTckeQfPdq9B+NgKnwy4dERg1PdT+NWRnQl2ie8NPuM18rBvzNYy6mlW5yFfjmLipxQ93seTa1Dn8dKw52TSvZlYWsOr59Zvj7w9wVEKdFWj+6oWdzFq7XHNYtQsgHQ85YE3T7D9smTnllKWnGPZpgEJ7qK7ULWwQV5qfURwZC0uGa766wcN/WZwwcbsBdPSw7kKszhC536sUDTnKECFD6g4Z+9aq2fLjKFRZuvUADTIUf3vfOHH99sDkfkFLkhHTvZRIMJhJyAi2/eIqme0vvdeUA== 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=9cvt5808hHcwhF44p0mrt1sssUp8SRDE7SeZ89SeYcE=; b=RoIi/u6HSuztALBaP1VdZaqOCM59eZ6Ez2DtpPjUKd3FmvBlA98tNKyLOnue8CVYLq8UiPvlm+7WEq8m4WyKEKiiucD1H23CyB2OmCkFRHc2KZ0Fhi8pvJRp9J95MDuJKZDPzHzZuUs8GvNUyTjSjjmnuOF1QOJIG85YvbwZoG9Hh/odpNOzZNKv+OXFdb5xSqk9RzG0X8z75izm6AwnwsMd1izCcUPabKuU5hh54uN8yqcgJXo0Zs5uqQw8zf855SF6k2zBc/e0vQzr24vDHLGRAhxq1OlRng8HndMSJUj6tznfwsjQyAQha9HO6zdvA2iqjKki+BaRPE6bQm0B/g== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , =?iso-8859-1?q?Roger_Pau_Mo?= =?iso-8859-1?q?nn=E9?= Subject: [PATCH v10 14/17] xen/arm: translate virtual PCI bus topology for guests Thread-Topic: [PATCH v10 14/17] xen/arm: translate virtual PCI bus topology for guests Thread-Index: AQHZ/Vi/w/6hIJcad0KQMXZM3sEAgA== Date: Thu, 12 Oct 2023 22:09:18 +0000 Message-ID: <20231012220854.2736994-15-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: a86bb6c9-fc02-422b-6e86-08dbcb6fe6ab x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OH72IzH+dD0Z8WBsT4/MFDWdg5Cq0iBxgqhMP10ci6iyCVaxKHSER3R3ZnX2d8WtVTUXYO66nrGOGqgU1AxpWpVT8xvRsf3QMx8mXka9QPFkVxtSjtbad19YkLupwpaD8oxs9/efdA4rMgkBg+2il8aiOQILCnSbIPqBr5olmMVoWN7VwBHZaMYXvkDh60RMmjX836NxtwpVSri+wU0VUo7bEniaP9DgSI60xcdfpM401cbF8xhlQeKKYNMsfvAtNekltwBNkcMToi54cZzyWv1LVTuURlubKAaEA9d3ZdFTdEco1FhN8JpEdENKofBqifYV9Kc0OLmW455z/cO8dTx3nyjXO28cBtw/nbsyIUEvut4l4sFNwOzCEZwMSs+tGiwSAFrPzrGO4s3Ek0UriJ6ESi0eHCeXLQOwbX0qQkqbLYYZ2RlAnHIBeP3bIZU2bCfONwSipxkTIdrAAvV/tw+4HF6PCN9auk871Rx+MnMPE4B36RA2l5JJv1zY+OL9fWYDLXpoUiBgMEZTmDINsGV+ZvJN/IzmuOxXpZpWT9sAvUWe5hAJi6x865uYj7UzzoKete48YPj8X7e8IS5d3ItRmItlAutnAgyzu/emE+ug0/prAmLSaSkmmHvV7Mfc x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?6drs2tRmmXLL2G8k/BWKX2e?= =?iso-8859-1?q?bmVXQeWtHZHlD6J0CUVijEN5RcY1wz0BYoy0j8ryXb95+z/zOZaEVpS9ZL7D?= =?iso-8859-1?q?XkRiX+5rFUTqZEAkqOEdESagDVAPNYv4yCO9eWCFLVNlfShzqG657jMvFfdo?= =?iso-8859-1?q?Gim/zrFr/oys5jK91kTOTfafgg67Jl0NHUB6bNEelbztmbTnbBGTslMWRYV4?= =?iso-8859-1?q?ttwhT+HIg2JSeLimjapGuoWixOxzAPbQ4XcGX4lsaCxTAaegcwAnQyjLuTEZ?= =?iso-8859-1?q?ryEMhPokNQIHmOy5uPetV+FIl1r4rYj3rcBZi8Sde5Lmm5kE9onfDy1h3PRZ?= =?iso-8859-1?q?Ztl/z7SUKHwQT6nDGbXWh1NsFXuh9FWUREgdtqiOm5bwkakNL5j1yAizUARv?= =?iso-8859-1?q?N1fgPltYCMVA0maM5B1Lm1DQ9FMkPEstLXEcLOSphqVO8LsTxYC02YZp2Vvd?= =?iso-8859-1?q?++pRRjcfxT6XV2z4JDRp2m769EixIpg8gCYhDGTlg3pXsTwTCYT1UyHGf5W8?= =?iso-8859-1?q?k2bZ44kVP7zilrxGRCXmQLka/6Bz6Z5HCahT72XyJAHtXtMkedU+FWn9fOfq?= =?iso-8859-1?q?9bejaMGOWWfM21Ivt1fkUvjcH4Idxz1jnfx0og9YoJ/dIvY2i6fQXmN7cXFZ?= =?iso-8859-1?q?VRf/Hjqt62IF1rA/BzBZjWVd6Gbemq0FWzTZKjtrVHQ+otKGi9SOE2ge+h7z?= =?iso-8859-1?q?fHtmSDYl5G1yVW0qimKGA1lm638be2n+CLkGpIwm9H8E28RXgiyK5kK4fnxf?= =?iso-8859-1?q?AS65faU4vVH+dMzGPYvR5XGIv6llHGL/qNdJ/SufP99aKdR2CgzC9H2y2B8n?= =?iso-8859-1?q?nPhEGivO/v1ym2QH5OpIa2LSyQm1nJJBGfDkIrq9P1/1ku7ATpA74klbc9Vc?= =?iso-8859-1?q?c4Sy3sgankVIVXEe0K4A+wQbwlgqxGnHRKn/dRPVoma2gfcHmnaI2LFzBwVT?= =?iso-8859-1?q?fKo3Ee2xbWTDpGoxb1V4qyhC9n1FtT76TLlhr0VyzxBuASIGeHh/gYLBsrYA?= =?iso-8859-1?q?ySYnc/zgkha5gO5difca6abRiZTMlvumg0dJk6brqfQGyv/rPAZLM13iDE4L?= =?iso-8859-1?q?xBR2/pDBq4qkrVGzfdM9U+4DboQr7399MAyGD3KnycHG83RGngy1zY+q/tI8?= =?iso-8859-1?q?nOoggp65VH068SRNdV2EFIipjgCoK4EkzaKkSzM1lX8z5pjm3aMIzWzyC+BC?= =?iso-8859-1?q?+mpkJHprKTidcFAmfdnbn6w2sxFwcURz66a0x8NqMXNe/2+a/P+At5NVlX22?= =?iso-8859-1?q?GSrfgWlZJfynJ8RRfNa3R6ldKuERURkgaQrTbmRDyCRwPAn+Cs7p/wHEmnH3?= =?iso-8859-1?q?/+L3g4D+S+XVz2GbpaNg1iLTRMTGZ5OmRKblSlXmzESw3/p6o13a1u1IADEK?= =?iso-8859-1?q?qdRKdRdeITNjkxL7NTeDMa2b93+I5V+2hsY4affolmXwSvbpsN6ik34VcLSa?= =?iso-8859-1?q?l2K1S3tZa3x5hfTTYU+h8vqWayGHc6OnDYSRNl4uUuCP8OCvhkOPXwzXd8fc?= =?iso-8859-1?q?vrEZFQFTWIvnN0V9OJOidgrpNqJ+bTAB543JXzJVsJrdluVx6zjxcKpJgM/7?= =?iso-8859-1?q?XYIBxPIOZm9H4UTE6I6Devdda1uXCYDKMSqSXpA6ljnmJz8qaeuEdw7Ey/6a?= =?iso-8859-1?q?/pxpgL+3SDepSLzXluXlzFoXV4wBuYKZUZsRJZQ=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: a86bb6c9-fc02-422b-6e86-08dbcb6fe6ab X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:18.8303 (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: i3lKaamBaJSTixOYuvdI+p9ZzO9sKymESFgNPo9KRRRm6yoxLEmO7MxANmPTyWGp27fZgN3x+B7jTPWkEeXunxXw9l2ESMbhVHdJff6HyrU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: bnRiCwm7jn_N8h9kqXU1LIMOfxUjw53P X-Proofpoint-ORIG-GUID: bnRiCwm7jn_N8h9kqXU1LIMOfxUjw53P X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko There are three originators for the PCI configuration space access: 1. The domain that owns physical host bridge: MMIO handlers are there so we can update vPCI register handlers with the values written by the hardware domain, e.g. physical view of the registers vs guest's view on the configuration space. 2. Guest access to the passed through PCI devices: we need to properly map virtual bus topology to the physical one, e.g. pass the configuration space access to the corresponding physical devices. 3. Emulated host PCI bridge access. It doesn't exist in the physical topology, e.g. it can't be mapped to some physical host bridge. So, all access to the host bridge itself needs to be trapped and emulated. Signed-off-by: Oleksandr Andrushchenko --- Since v9: - Commend about required lock replaced with ASSERT() - Style fixes - call to vpci_translate_virtual_device folded into vpci_sbdf_from_gpa Since v8: - locks moved out of vpci_translate_virtual_device() Since v6: - add pcidevs locking to vpci_translate_virtual_device - update wrt to the new locking scheme Since v5: - add vpci_translate_virtual_device for #ifndef CONFIG_HAS_VPCI_GUEST_SUPPORT case to simplify ifdefery - add ASSERT(!is_hardware_domain(d)); to vpci_translate_virtual_device - reset output register on failed virtual SBDF translation Since v4: - indentation fixes - constify struct domain - updated commit message - updates to the new locking scheme (pdev->vpci_lock) Since v3: - revisit locking - move code to vpci.c Since v2: - pass struct domain instead of struct vcpu - constify arguments where possible - gate relevant code with CONFIG_HAS_VPCI_GUEST_SUPPORT New in v2 --- xen/arch/arm/vpci.c | 51 ++++++++++++++++++++++++++++++++--------- xen/drivers/vpci/vpci.c | 25 +++++++++++++++++++- xen/include/xen/vpci.h | 10 ++++++++ 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3bc4bb5508..58e2a20135 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -7,31 +7,55 @@ #include -static pci_sbdf_t vpci_sbdf_from_gpa(const struct pci_host_bridge *bridge, - paddr_t gpa) +static bool_t vpci_sbdf_from_gpa(struct domain *d, + const struct pci_host_bridge *bridge, + paddr_t gpa, pci_sbdf_t *sbdf) { - pci_sbdf_t sbdf; + ASSERT(sbdf); if ( bridge ) { - sbdf.sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); - sbdf.seg = bridge->segment; - sbdf.bus += bridge->cfg->busn_start; + sbdf->sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); + sbdf->seg = bridge->segment; + sbdf->bus += bridge->cfg->busn_start; } else - sbdf.sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); - - return sbdf; + { + bool translated; + + /* + * For the passed through devices we need to map their virtual SBDF + * to the physical PCI device being passed through. + */ + sbdf->sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); + read_lock(&d->pci_lock); + translated = vpci_translate_virtual_device(d, sbdf); + read_unlock(&d->pci_lock); + + if ( !translated ) + { + return false; + } + } + return true; } static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, register_t *r, void *p) { struct pci_host_bridge *bridge = p; - pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + pci_sbdf_t sbdf; /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; + ASSERT(!bridge == !is_hardware_domain(v->domain)); + + if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) + { + *r = ~0ul; + return 1; + } + if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) { @@ -48,7 +72,12 @@ static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info, register_t r, void *p) { struct pci_host_bridge *bridge = p; - pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); + pci_sbdf_t sbdf; + + ASSERT(!bridge == !is_hardware_domain(v->domain)); + + if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) + return 1; return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, r); diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index 7c46a2d3f4..0dee5118d6 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -80,6 +80,30 @@ static int add_virtual_device(struct pci_dev *pdev) return 0; } +/* + * Find the physical device which is mapped to the virtual device + * and translate virtual SBDF to the physical one. + */ +bool vpci_translate_virtual_device(const struct domain *d, pci_sbdf_t *sbdf) +{ + const struct pci_dev *pdev; + + ASSERT(!is_hardware_domain(d)); + ASSERT(rw_is_locked(&d->pci_lock)); + + for_each_pdev ( d, pdev ) + { + if ( pdev->vpci && (pdev->vpci->guest_sbdf.sbdf == sbdf->sbdf) ) + { + /* Replace guest SBDF with the physical one. */ + *sbdf = pdev->sbdf; + return true; + } + } + + return false; +} + #endif /* CONFIG_HAS_VPCI_GUEST_SUPPORT */ void vpci_deassign_device(struct pci_dev *pdev) @@ -175,7 +199,6 @@ int vpci_assign_device(struct pci_dev *pdev) return rc; } - #endif /* __XEN__ */ static int vpci_register_cmp(const struct vpci_register *r1, diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h index 4a53936447..e9269b37ac 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -282,6 +282,16 @@ static inline bool __must_check vpci_process_pending(struct vcpu *v) } #endif +#ifdef CONFIG_HAS_VPCI_GUEST_SUPPORT +bool vpci_translate_virtual_device(const struct domain *d, pci_sbdf_t *sbdf); +#else +static inline bool vpci_translate_virtual_device(const struct domain *d, + pci_sbdf_t *sbdf) +{ + return false; +} +#endif + #endif /* From patchwork Thu Oct 12 22:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419863 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 BB513CDB474 for ; Thu, 12 Oct 2023 22:22:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616124.957942 (Exim 4.92) (envelope-from ) id 1qr44f-0005s5-UG; Thu, 12 Oct 2023 22:22:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616124.957942; Thu, 12 Oct 2023 22:22:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr44f-0005ry-Rc; Thu, 12 Oct 2023 22:22:33 +0000 Received: by outflank-mailman (input) for mailman id 616124; Thu, 12 Oct 2023 22:22:33 +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 1qr3sL-00016s-GW for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:49 +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 0dbbbeb5-694c-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:47 +0200 (CEST) Received: from pps.filterd (m0174679.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CG29eP021659; Thu, 12 Oct 2023 22:09:33 GMT Received: from eur03-am7-obe.outbound.protection.outlook.com (mail-am7eur03lp2232.outbound.protection.outlook.com [104.47.51.232]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3tpcc6c048-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:33 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:27 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09: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: 0dbbbeb5-694c-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZX5CmX5ZAA1MFmLL+DAWkF5Qv69/hO3KeUn82IVnWIlfXkM8x2euEaHimm99zXw7uZ5JvbYD1ee7m8lHUm5EcKkTQncavHm7q2obXmw4QdH3nzv0TlpCHruxlf0TODcPSTv3J4FlyA7fiLq+GD+87cxAsPCc3hxAoGrocgk3qtAXwCwtaGxbN8+r0Okay/ueWjE9rbIGHbaWbqsB63imO6SRwTijK8/Y/24azq7ti41qjNtRF1087KKV2qFtsF1ALFbv7gUfU/Xt1FMExOBVwA0olThQiMdN2I6qLjzcSANg5DdaTjV/RwH1boQoGQY+x8SNZAOb5MoGUxx1W8mv+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=ntwIQOSKcHFal4kV0pXQkxtpoJAwWh5cbfLdqCXSimQ=; b=baJjW/HnTYnLX/6VFCx/qOIS/mypLINKET48DoF/+1ycdBitODdroGpJqgKn2AE6oncGnmL8o7pCXYwHDrZ+7usrw3gLnKm1sq5OIn0YiWroAJqlNu7cD/ZgtersEuyE6kxB0HZSTARQbVpdPbJIiSVQglEfUXynnSrRajQVtE6v6j6Gn0xfy6vyqT1pHL/TjNiCE2v3ACjMFnkSd3bG+dgFpB9xDp8yvXjebcmyFWrtkMOZfbuFWN31+VItY1dFfh4dmZ36RrYXbEZSxiVJIWVBvrF9MaFZciEsdlxvX1aw6fOXGdCJDhe30vitRAgB7HqcQWVs5WQAHhyk0cvb7A== 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=ntwIQOSKcHFal4kV0pXQkxtpoJAwWh5cbfLdqCXSimQ=; b=SKZV3kc6hPg5rrRhIaOny8XRAy89MIRSw7BAlIDZNSDrACRVzrfntl0soV1BNJK/QGfV/g0bfNKYZhvfm9FRXxpWsAsXi4H6lD26ye06TgHLoyN7qyRpuTuT5/K7Oo3o7YNkGH3ReHJ3pUIVMWCxKW76xp4K9kByfTNAjhcpNOAKyY7tQ3vnK+QmCSloBBrJUFFBUvcHiPauRDZJXr59wJnsaHW8S1WfKfFGN/ba1lqGs1UlHRqfjN9g9h3X1xC8UzDP0IHWVA8TxLtOowwzLT27x/sGy+0gZBI2+HmQahWYZNZOIU+rK35dRWZ6VJJkdd58O2dJVrSdO6CmSjAnBg== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Oleksandr Andrushchenko , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Julien Grall , Stefano Stabellini Subject: [PATCH v10 15/17] xen/arm: account IO handlers for emulated PCI MSI-X Thread-Topic: [PATCH v10 15/17] xen/arm: account IO handlers for emulated PCI MSI-X Thread-Index: AQHZ/Vi/WuE7cEBbNE2PUEpOXmVwbA== Date: Thu, 12 Oct 2023 22:09:19 +0000 Message-ID: <20231012220854.2736994-16-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: c3a20365-1089-4e00-a60b-08dbcb6fe6e4 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: UDUDW4GJK+gQ7nZrHdUIGaQN6bHf/FG4io24AzMDKurSotPzQTJGlyFZF/bP92ICM5YcdM59G9ALeBpdHtIYfDlnYA2dthgxZeLoBRlkpFJCjA4ljEJm+tYe8ndXCT0ySesVHow8f92Q/2y2/QFHa5gHlhxdMZs4GLNgTQ1MHTTxOMC7qfIbjFDnepAl6UV9q9CbLpCorCWaML4HrNMZLuybe1opmn6+3BFguZ9dyzer7UObmx19PI4Z8fncGQG5tjR31CfgJM4NNZE93UkOgsy9OuVWOg0PBPmwDrNboE37w9TOZjcT2tmo4zje17w3tRrzia3bTrnWJ5kDBIfSujw1+heb8JE/9TJbnxIfsaCQisime3AgQ/lFFLk7+O4puLXdHFPybvDW6+CFr90C9aHLXfWXYtxPiHbikyVDc4U8pWQmsUA3Y3MvflSN9c+hulkR22IWVQOa2Z2369Wzd54l0v9YQRcDF867DQDwITAwq9HABy9U5WJoprlmfo5DTO7yMQxXvL7aL8y3v23Jv6SF9SDdDANwFREzdB/wDv4xeuS+lrYqqu78GFUKukNO8rFlGfaBJlopjXQsxJgCo0UB3zAsJ6FUHW5086KbCUwfP0iSEchJWHwfeSLMxlnV x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(66899024)(71200400001)(6486002)(26005)(1076003)(2616005)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(15650500001)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?nKZVTjkf9xFLWi8aVvUMm5F?= =?iso-8859-1?q?8QKk/HXMCyS6Mvly8J5xjr6juhrj6isCXWl6jgF+SjbszYZaY/JgQXJYx7oo?= =?iso-8859-1?q?k5dYKMfCdCiBagazdLw7aw1+NTvSDyNL1j90EeDwG+X9KhFaBocc70P816cl?= =?iso-8859-1?q?xKSNUuZBcx5H2fuv1kWEuEbS9cs4IA5hyDOTV12OtOjA4yz7lBXOD5qEDU/i?= =?iso-8859-1?q?zUkvfHXAY3L9GdsS8WUzOL7pIVnMbeXR0wo0IYnbWjSVZIOF4RNVddSS+Q+5?= =?iso-8859-1?q?Pr1huqGuufzO6rMr6RwWX8h9CjyTunOTEZXjnXVKSlvz4AUNVBfHLoHdrUgz?= =?iso-8859-1?q?ey/JpjQQnzv5XPhsR/zsjZY24rUJajouLtzf9TvpPOSvZUK2sVSEZ4QVaAMc?= =?iso-8859-1?q?VTFfVhGxk8Dy2Kx3zx9+JjmGmfJMg7Ri9FLPYmPHGGKnjnDWrzAxuvyYA1Qz?= =?iso-8859-1?q?iyCzG5IWkrceV4zIRvIYofPrKaQdaTvjqsOkqALd25Oo3yftts9GOWan+ayn?= =?iso-8859-1?q?yNqY20M9vliiMybBECh6b++TUWz8RX44yPwIzCm3yKihnbf2X4u0uFAaTyaW?= =?iso-8859-1?q?paKXhpyF/ts7fluHozffcZX/gjNqRhPQKsRMKeS5HIYkDsauGeul3y/63Zay?= =?iso-8859-1?q?sdwElMY/uglq8mXJzu/fSR2iJwdCv4atcewAP1L4B2q9i0IBjWhJEUfM32rL?= =?iso-8859-1?q?oDQHxc4WTsWohxkP5UGxgiqTaXPYDNMV0cilAWC/9X4mzJr7Wtdm2pcSwaEl?= =?iso-8859-1?q?SCkAgdblJoHwrF+WgM5X6+KlojwuNZGtrerekrmW0CEvMteymnKW57FBrwLE?= =?iso-8859-1?q?qGR6s5hYJKjqFODNBoqhLWLkMmgyWARRmlwR46E6RtKvLaiq97OUL0xk22TO?= =?iso-8859-1?q?0PoPFKODWStvMihIpdcSF9NcNBLDP/SL5c2jh+mfk4Ig6y8GeB2i0d9TKXfI?= =?iso-8859-1?q?F5v6tMYISYHFWrrFDSKV8LcQtdsuz42g+ZZAFBksopOVMY104FdenHfNL95/?= =?iso-8859-1?q?7wSpYj7ycsEEq7X61EBr5FF093ZLKcELjvnk01yhu6l0CrA+oFVSs4lVxyfj?= =?iso-8859-1?q?nqXPuQJrMyW12iIYSvepYtzsKsSwFP1kAIko3bCtbWcBP+XNIZVySYdese3o?= =?iso-8859-1?q?AZqpJQ8lpkNnWqi9wg1HKr34nMRvYNprQ3NWu3N8SH5rNTxkzo2U4W7uwyF3?= =?iso-8859-1?q?9xLSuWYwVfYTOLkuUaSnI6hyX58rDURL+czEMllaed2LfA7/FuYtR/jR68M+?= =?iso-8859-1?q?0dqO2nsG1jXzPdAUBihLRQOEKt1rCu+/UjTycWZ3wa0PlNTbmwdh8UkPMTWU?= =?iso-8859-1?q?2y51XnY0o55/3f49YEYe4Q6VsoTswcU1ltk5KdCRO7WRBDy+LxQsR/tQbAn3?= =?iso-8859-1?q?eBlDxy5f8K+Ek1t+ocDfGr8WdD1D22VzWnq7r7WnZtHs/Ag+iYcPCrRjnewZ?= =?iso-8859-1?q?+vYfMzKtyu1qwLf81vHoGZVeQAV1xEQ4/ZKqfCFgH6E0Hvw+hdTFwhlTSyeX?= =?iso-8859-1?q?SGuHaVFsdB05SWE2H3X93jyrocc6HcObzAq+DPMJ3v/322SVuVyyz+/GE8+S?= =?iso-8859-1?q?rkZ0tNqoqao9zUfM9BmGrxhREKQBL7a4y9O4wHdBjKwNohLXO6YxTajQnMbc?= =?iso-8859-1?q?Z3F6sb2Ah4w/O5u78s6TkRVlIKeosf3MefSSZow=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: c3a20365-1089-4e00-a60b-08dbcb6fe6e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:19.0875 (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: LUfhM3fXebidXZgmN7yZKylfOyzSN/YRqVPQZpnQc+FIzbWBXn4HgT7UQBAL1UyXA+Of/R7df+8d0rrmPGGTDsm51xEOM9ofdVklbT2j4c4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: 8tQ5bdFlrfWwIv5IwbLsTI4yzCUg4ofu X-Proofpoint-ORIG-GUID: 8tQ5bdFlrfWwIv5IwbLsTI4yzCUg4ofu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1011 mlxscore=0 bulkscore=0 mlxlogscore=417 lowpriorityscore=0 suspectscore=0 spamscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Oleksandr Andrushchenko At the moment, we always allocate an extra 16 slots for IO handlers (see MAX_IO_HANDLER). So while adding IO trap handlers for the emulated MSI-X registers we need to explicitly tell that we have additional IO handlers, so those are accounted. Signed-off-by: Oleksandr Andrushchenko Acked-by: Julien Grall --- Cc: Julien Grall Cc: Stefano Stabellini --- This actually moved here from the part 2 of the prep work for PCI passthrough on Arm as it seems to be the proper place for it. Since v5: - optimize with IS_ENABLED(CONFIG_HAS_PCI_MSI) since VPCI_MAX_VIRT_DEV is defined unconditionally New in v5 --- xen/arch/arm/vpci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 58e2a20135..01b50d435e 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -134,6 +134,8 @@ static int vpci_get_num_handlers_cb(struct domain *d, unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) { + unsigned int count; + if ( !has_vpci(d) ) return 0; @@ -154,7 +156,17 @@ unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) * For guests each host bridge requires one region to cover the * configuration space. At the moment, we only expose a single host bridge. */ - return 1; + count = 1; + + /* + * There's a single MSI-X MMIO handler that deals with both PBA + * and MSI-X tables per each PCI device being passed through. + * Maximum number of emulated virtual devices is VPCI_MAX_VIRT_DEV. + */ + if ( IS_ENABLED(CONFIG_HAS_PCI_MSI) ) + count += VPCI_MAX_VIRT_DEV; + + return count; } /* From patchwork Thu Oct 12 22:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419858 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 BD1D4CDB474 for ; Thu, 12 Oct 2023 22:09:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616077.957903 (Exim 4.92) (envelope-from ) id 1qr3sF-0004jo-EM; Thu, 12 Oct 2023 22:09:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616077.957903; Thu, 12 Oct 2023 22:09: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 1qr3sF-0004jH-A6; Thu, 12 Oct 2023 22:09:43 +0000 Received: by outflank-mailman (input) for mailman id 616077; Thu, 12 Oct 2023 22:09: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 1qr3sD-00016v-D2 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09: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 09e25b93-694c-11ee-98d4-6d05b1d4d9a1; Fri, 13 Oct 2023 00:09:40 +0200 (CEST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CKqPBi007501; Thu, 12 Oct 2023 22:09:34 GMT Received: from eur05-vi1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3tpr7cr8ed-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:28 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09: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: 09e25b93-694c-11ee-98d4-6d05b1d4d9a1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hJbruyxws4nBodWCnx+vIYgRU/g843StHlFKRppiGuJDvOkZhw02lDdntYLZ1uVSFyJOZOgdiV2N/Vqiy2cW0ugW6Lke6Vc4TmokRLhRwoC6esEwD+uemb50BIoAn5xuJEDuT3oPkOrdfhoDgJzb+obXa+QC0CVdL4CXhotzDcscRQ3swNZ0wc3QJDZX/OTC6VtScc3bUM7cWjyBOUBVZnhTi9cF7jzJglXfWXTUXis/GgLKeGhRnFkIQWEfD1KvHn7JnNuS/AiIneUf1t91cvvmhPjEDZ0cXsYEGlXwbvxJJv0YwyShjcN2PBBfYvXezxzTNyZUA8D1pfNaYBFpTQ== 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=jemp8AXG4G7kZd1vekfyMfuZ4tvRJAgtq1QGyeWPS1Q=; b=f6sh31/FA41mqMk7gaME+9n30WHMj5fEHmoLU7l6A9t5brplpnA0Fr024IupBRf1jEgLPED5AlB/eCQcex4yUzqOBflt3ZInjAdD6Cz3kh8d0o+fsAR3ZuFREb0AkeofS+hShhIMEHHyRXPQUBH/n8UDaiAj1TnHHUQ4/XtVUcnUY/VdF6ISZdpYaNxJdM8A5cWVyc7mVpCF1j7+43OyxXRmTvnmcxzWZ235gHWKOb0d+BKq2QN6zeii8F0SojIjQnqTy+ug7dhtzzDV67q+9OzTBGg7qtossLKB3Qp4uyBF8kDv7ejAhmqQBIv9zFqPUjpr1dO1zlgatjS8OBTyAg== 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=jemp8AXG4G7kZd1vekfyMfuZ4tvRJAgtq1QGyeWPS1Q=; b=nGyd0Caq3i1wXCUzPcZaeLXjsR1tzwwTzmrHzO5TG4yvMOxZ/xVBEWUtn+MG9xBKKTWy00bYY/NBR/so2cpVWeerMd2mcctUseR8NDQZUFhRSRU9BABQPh+8KuMVnbm/6XDlUpikrIezSe4oa7vHaEKFeeha4wlTXd3zaid+a/R6Hx1R0tm0NyTG4lzIE/4+00raeqrpQkzAOyEKH2vMSeSqvStBPpi5hOX91BzwkPYS+q+1baecTLVrF5YXsB+Q63oeVLcovxzXhmfMzIKl0mLNhkrLGqEPEz4IDtAd4Tlui48j9hzcuYjB+CWp5GJuzDX42IoYjtuheKeMmbGtaA== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [PATCH v10 16/17] xen/arm: vpci: permit access to guest vpci space Thread-Topic: [PATCH v10 16/17] xen/arm: vpci: permit access to guest vpci space Thread-Index: AQHZ/Vi/DuQgj4K7kE6rd+kBlTBFxQ== Date: Thu, 12 Oct 2023 22:09:19 +0000 Message-ID: <20231012220854.2736994-17-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: 8fd38337-2e9f-4761-543a-08dbcb6fe714 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ffTSLedFRd+w0V6Xbn8EPtE56dozfnHAnzDpshiPlmBIbUdIm/Y9rXQPe4T7VRE5oU2pxIUsgLN/cWCAu+DBh9yy0WOhwgHgtjV1l53yMhgg7X+6WflhxNOwKaP8nHIow5eYXy1luo6oI9yKp0fQ7oMP2Xf6lKmWRCtq8mxexP8j40POLYv1YFQozPX4ihOmA3/Juhc128xR1lyZcr2PXLUhJqXflRVAQzOxYCGfFvmUoV4mhR6CdMnfz/xTBHm9gquQ/3PqCLmkD1r8/L+WSfX/Lrm/J4YRxKzIKwMrJlzvwrcwsf7GlrCgiAH+SzzNt2roxav86ujpopnYNtic1Xv+n5epNPmLqEtGY9FGjLIVxr59k2h4ITKwWfjDit6wP/FaFjJkF/6moNSXRcE0sCzjmI0AwgElTvlrped/hSS/wuYkBmR3sRspwDPTdtKxlITh0Q2vmAdpMwvh5wBlwpVIoNdmLuGoHasOaoUiDx22DKRscDC+/BZFngYCTJVZZm+aXFzcLffbzBaLpth4yogX698YXxjaPS7imW3Jk369eG972ZvNCG5EgAf2uNGWnXv+54WUsa34kEu1B1ILQGEF2k0ijhcsbzyhznE4c22mj+WUUJpSUGf18iMySJG0 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?b8Qx6VCj8Xs+59yBENAfIVE?= =?iso-8859-1?q?pGTXhLV6G8QBXuEL37IfFBDeCm51cQDf7K5TGPou4NYYKKpmkvobPdObrA7b?= =?iso-8859-1?q?n8wxTpsELEAYjRe10Bjs2y5x9isloYsnu4/lRmQtDw8vLVN/6RxmsVmRsu76?= =?iso-8859-1?q?+H70HcobHHuanK7z6offCzEDCKtBv2/T/HQiwjOXP4kPrENiQK704+bUxzeh?= =?iso-8859-1?q?qKVoJtx8cUED6Q7GJnk0IbPSxv8u0ut3FvCBMqZ/nMDJUGg5SdV/f4SVp5Xo?= =?iso-8859-1?q?WJsNZej/xE/oMsbejhHAPv8x+fmj9gss4rbd6b1KP/HijwuRAiRE2nCjNTyC?= =?iso-8859-1?q?NYr9o14hC+QcKGuXhc7L/EvlUYbOf348gP6WNbNeY4823gL/Sa2/ljgJ0+fb?= =?iso-8859-1?q?kJro4sjUnDswfmOgOj1H6dZMGGd+crwHXa7Zfc46uRTlPvCA90f7AiqZROJV?= =?iso-8859-1?q?WCX2pQSq4pMbbKs9K0Eg3nq3iJOBp/rO5cHBMVu0zANppZbkwkJ1grSlSBCu?= =?iso-8859-1?q?u792Vuq11cTAoCetLTynGSx0mt4+99EypAWuI9JZjfdIK/P0waWXEng1kKjc?= =?iso-8859-1?q?qfwhk5HmssCWpqSfVORdGVAgpgV3GBxGzZjaAzlZwuBqLXyPafHMGDlFwGqj?= =?iso-8859-1?q?VPhn5LgLmzhtMJLPDLtXpilqYDnt05i89PIWNWY54nkitggfErkuBqpmwH8X?= =?iso-8859-1?q?C6v2IR3WpFVyGoZLKFanA7XpqTsX56hD8lzS9qEkNxZLO5Pn3XVpsO36MKbd?= =?iso-8859-1?q?uv+S2UUZNuJeQAkKxiZCzULyrFpaqxigRUfoSZj3fY525SURogCqm56UuIu+?= =?iso-8859-1?q?J+ssKawfdHOj8kvTyeoeNbhABpdrY2aMSikNyvSYBZDpZxNmTCPx/yJrv033?= =?iso-8859-1?q?9H3Ol8/Xplgkp/cUGLmWe75BccASu6UgT7Hygq5pn94vL9P9JS+esXfuxv8a?= =?iso-8859-1?q?uCQ/aCXN2j3JT5tSqoTPN9stiBBly3atcLxrBfcidjDDvGlQ+aD05Plh80/z?= =?iso-8859-1?q?1k8oad0Njj1M9va7iQot2im3645kZmjHMoE0FdjgLA9wgSMCrkd7NHzzsLta?= =?iso-8859-1?q?KWB2xsZ7H7zaYrUTeD5fWHa7iqb9rwiDfcHWEsJTx39GmPlYBRbNdFWXuS8g?= =?iso-8859-1?q?K92u40+tUvNEJYpDo4vT0EFm/ro+y5FYpEsaKIMcpp/EjmTS0FtltJOKMFtY?= =?iso-8859-1?q?PM342TRMSMP0yDyKx1MlDN6BvyVQsPLwiq+UN2/S2GsMsH4HjX3K7eG1hAer?= =?iso-8859-1?q?I81KGZQdHpWnje46IZpvDofT3Zx4pSgEvkO+MIfSW+sdbbTb95rQe6QnseCi?= =?iso-8859-1?q?suELEBi2QjY4nq1IL07TJ1e0jlENRpxtHCfRqd4bXfUyaUXcud9of0MDTQAT?= =?iso-8859-1?q?9D1WjyGItoOPFGCLcGR2rfMhj6UcBE69UnpqLvE1sV4DQUhhmXbN1ZfAUyc5?= =?iso-8859-1?q?sNzAJv9XySErBZ/8OS7X8hcQsZYvwk9v+JKzfwIVxJ2asfqnL0c0jm9n0PEK?= =?iso-8859-1?q?r6dpabMyQvZ1hw1K17eWB9JojPjSyUjOWbDToQrpWLrgStmKrkjf0PJULTvU?= =?iso-8859-1?q?IF6LXpirWGQCJK5JvwVoSfqnCOd9PVT3o4LFm4jZTJ9GxM+8p0V/a3bYbDu7?= =?iso-8859-1?q?FxsqOH1ZQ0cZOClV6nQGCFcluq31qJ1kjs8lcyQ=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: 8fd38337-2e9f-4761-543a-08dbcb6fe714 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:19.3499 (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: LhO6AQkeX5sOBVAq6w1qOegLr0061bO8HhnllXNCpdN2dnYsAXEh8de3XZlRXeOfuOixwCsuNbTiXUztC4rexrHHC1kAxKG3FfT1l2xcDEc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: x3E5hzTw5cNs-lSgq5IEbQebQwK4hAb2 X-Proofpoint-ORIG-GUID: x3E5hzTw5cNs-lSgq5IEbQebQwK4hAb2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxlogscore=689 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 From: Stewart Hildebrand Move iomem_caps initialization earlier (before arch_domain_create()). Signed-off-by: Stewart Hildebrand --- Changes in v10: * fix off-by-one * also permit access to GUEST_VPCI_PREFETCH_MEM_ADDR Changes in v9: * new patch This is sort of a follow-up to: baa6ea700386 ("vpci: add permission checks to map_range()") I don't believe we need a fixes tag since this depends on the vPCI p2m BAR patches. --- xen/arch/arm/vpci.c | 9 +++++++++ xen/common/domain.c | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 01b50d435e..3521d5bc2f 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -2,6 +2,7 @@ /* * xen/arch/arm/vpci.c */ +#include #include #include @@ -119,8 +120,16 @@ int domain_vpci_init(struct domain *d) return ret; } else + { register_mmio_handler(d, &vpci_mmio_handler, GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL); + iomem_permit_access(d, paddr_to_pfn(GUEST_VPCI_MEM_ADDR), + paddr_to_pfn(GUEST_VPCI_MEM_ADDR + + GUEST_VPCI_MEM_SIZE - 1)); + iomem_permit_access(d, paddr_to_pfn(GUEST_VPCI_PREFETCH_MEM_ADDR), + paddr_to_pfn(GUEST_VPCI_PREFETCH_MEM_ADDR + + GUEST_VPCI_PREFETCH_MEM_SIZE - 1)); + } return 0; } diff --git a/xen/common/domain.c b/xen/common/domain.c index 785c69e48b..bf63fab29b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -695,6 +695,9 @@ struct domain *domain_create(domid_t domid, radix_tree_init(&d->pirq_tree); } + if ( !is_idle_domain(d) ) + d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex); + if ( (err = arch_domain_create(d, config, flags)) != 0 ) goto fail; init_status |= INIT_arch; @@ -704,7 +707,6 @@ struct domain *domain_create(domid_t domid, watchdog_domain_init(d); init_status |= INIT_watchdog; - d->iomem_caps = rangeset_new(d, "I/O Memory", RANGESETF_prettyprint_hex); d->irq_caps = rangeset_new(d, "Interrupts", 0); if ( !d->iomem_caps || !d->irq_caps ) goto fail; From patchwork Thu Oct 12 22:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Babchuk X-Patchwork-Id: 13419862 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 F1A69CDB474 for ; Thu, 12 Oct 2023 22:21:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.616115.957933 (Exim 4.92) (envelope-from ) id 1qr43P-00052O-Jw; Thu, 12 Oct 2023 22:21:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 616115.957933; Thu, 12 Oct 2023 22:21:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qr43P-00052H-GS; Thu, 12 Oct 2023 22:21:15 +0000 Received: by outflank-mailman (input) for mailman id 616115; Thu, 12 Oct 2023 22:21:14 +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 1qr3sL-00016s-9T for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 22:09:49 +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 0d93cdf7-694c-11ee-9b0e-b553b5be7939; Fri, 13 Oct 2023 00:09:47 +0200 (CEST) Received: from pps.filterd (m0174679.ppops.net [127.0.0.1]) by mx0a-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39CG29eQ021659; Thu, 12 Oct 2023 22:09:34 GMT Received: from eur03-am7-obe.outbound.protection.outlook.com (mail-am7eur03lp2232.outbound.protection.outlook.com [104.47.51.232]) by mx0a-0039f301.pphosted.com (PPS) with ESMTPS id 3tpcc6c048-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Oct 2023 22:09:34 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com (2603:10a6:803:31::18) by AS8PR03MB8758.eurprd03.prod.outlook.com (2603:10a6:20b:53e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.41; Thu, 12 Oct 2023 22:09:28 +0000 Received: from VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076]) by VI1PR03MB3710.eurprd03.prod.outlook.com ([fe80::f606:63f7:5875:6076%4]) with mapi id 15.20.6863.043; Thu, 12 Oct 2023 22:09: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: 0d93cdf7-694c-11ee-9b0e-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AgnX5BmG6ny5bXSPcSa+e79ivWFctQhzJWGHb9pU0sDniaWje5fMJ6HbzyDiYngv0IZrBn46Cai1q+dWf57D1TgeXwBPBFkIdlYiY/dNkrFzsdK+BneTgTpT7ldG+s319XZjL0huhiXaXmK9tOdLozFpyBVUhHlcTjX801oqN5VHVjXtwz0PGMbEHbSaGH0mvc/zVGObRdvtfMXlQg9TDwry4Tj1aPZQYKRBx+8kpAmas3kO+8VYvRnSWem0nNnOnQcjiAQ6Nz1sYeKHl8Ilv0XTTj6g9TNHup9Q6M6A7hKNJZBz84cIFoFLRWwPk4+R0kKBNDMS8qFdIlxjrhWxdg== 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=6fCPCQQkuoUbzHvgCuLMRvBKFHMr2721/yam2GyvN+o=; b=fbSqGUHZD3PeiYHjYDp4zyYD8kiGNSpR0iUdjs0wppF+JfcaCYCDXaVINKViqsnTU3W37qzXc1MBIipW7CeUEBiq/koorWp8Pc1zWN+dcYdIWCkoG4v/R1vq0uH1XuOddn75sJAFMMk1jdest1su+KAU+cKoOIC2RqJuc1g49CxV65T2gGqnrSwq+/swLfug+IHjBrEAF4bf447zV7kdyx7NKdHMMa6JgS16NIIy4UNIqbAeiUvxPn0a2258OMhBH2Ib8prcktU+3wZMwdb9PbuWVcpr8Kw5WLICgHbB51yHb1Vx8DA5rUfk5BH7/tdmqMvi4pdWOwBU5XVMb/UiAA== 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=6fCPCQQkuoUbzHvgCuLMRvBKFHMr2721/yam2GyvN+o=; b=P1ipP9kAqSHZfGH8c8XlxfNwP/oP6GQ88E13pubS5y7PdRPEuY5FF4A15BBhTiXOKxItkqqcU9HlxVCkglr5DAZUaUFewwTYqLYJSZlmRE+ruby7EKh5ayfaMR393NjEBppSWy30r2vQZIoOJnp4gwxdL1qFe/DnEgIfYKApEd3d03Iu7rpt6ZCXYvmrhYl2ESt2s1q4KTlnuAylAQGdECFdUXKp3v0GjAoNrThpqnkrd1uLSPj2DFkwjSGNYUIbF2o5V8dwGUXt/6gFNLWLCrQaObskfMsnNYRulZNA6f3EBYNS/W7vyR5G7Zqc0z0nsknbealo1YV1Gwkl2xbUZQ== From: Volodymyr Babchuk To: "xen-devel@lists.xenproject.org" CC: Stewart Hildebrand , Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH v10 17/17] arm/vpci: honor access size when returning an error Thread-Topic: [PATCH v10 17/17] arm/vpci: honor access size when returning an error Thread-Index: AQHZ/Vi/FcbNdUf5hUOov/su5MD7Xg== Date: Thu, 12 Oct 2023 22:09:19 +0000 Message-ID: <20231012220854.2736994-18-volodymyr_babchuk@epam.com> References: <20231012220854.2736994-1-volodymyr_babchuk@epam.com> In-Reply-To: <20231012220854.2736994-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.42.0 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: VI1PR03MB3710:EE_|AS8PR03MB8758:EE_ x-ms-office365-filtering-correlation-id: e1dbf20e-1f04-4d70-a031-08dbcb6fe741 x-ld-processed: b41b72d0-4e9f-4c26-8a69-f949f367c91d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: fLgTqDYSB6qOd8P8sAT/xDozmDn39xYYs4M61Lwv570Q9xEzuW9XmTBNkPYBelFKO2d5B6BWdnQXcQ4fYRpJQLNf6Mcj+uiY53nG16xIdH+7Mz2gYZMHT1PTIglHjCq0ZMlNL7CMdgrj6S+huiRUnNapCtvgO5b/RxfpI93mpeZerIfmCHKz/80dw1Ez0y7s+Hl6quaZZJPvlXcapnfLrXxAxSqvrhb4WwIZBC7wGgQlrZB32hUITCdm2zaZf2PuLtc/swnVJosyrhdervY+HS8KWBn1Y17HDCfNpU+Kh9RhVHSMdHniOcxOFKyLGrIvHQY+mtTmDanLQRisT0iJEFWPvcEL5wDQdsZE78smD2QgWyMsD+bhZEpgUvf2i6IWAdlEyyDF8pZpl6epamOZvTkxZskRm8IiBLzQML8MEMvs7tAxqOdjXW4pzADZ0Hb8RO5UuK0Cff4Q36fg8LQVetg1nr8Kjn62ZY6wP9tjD9LYfyzH8OnhJSAVQzLBiBmTf1Am0Dpd1UZhwiMfKLt9sAPc50XXPWvZAv/HvyOlo+aKyEFQwGmUGyy/U4hlGvbs4/s0ffuKY3ZGkUkrBo0RpkSTPq4HSfCHEZpFInQbM+OMQJNXrmz/UdOOxjVDezX+ x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR03MB3710.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(366004)(136003)(396003)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(38070700005)(6916009)(5660300002)(41300700001)(316002)(83380400001)(86362001)(122000001)(38100700002)(66446008)(71200400001)(6486002)(26005)(1076003)(2616005)(107886003)(54906003)(478600001)(76116006)(66556008)(66946007)(66476007)(64756008)(91956017)(2906002)(8936002)(8676002)(36756003)(6512007)(6666004)(55236004)(6506007)(4326008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?0QWRMrx15lgJPaYn+1mV174?= =?iso-8859-1?q?FJ9sYrdunJ/iQYJ1MN3EdUrR9Hq24ZtcSBQekvh3dw4qxN3gWNKRoGRV5RCa?= =?iso-8859-1?q?iT4yPgjyl0PTpBHQ2z7s0SmcOdehl1ThvLbTLhOIChmHByqgpraU1au//vt4?= =?iso-8859-1?q?MOug4+ZFcCpDWGLsZK/cDiscdI2pcf2tJAnJT3ATULGNBDyafHb7Mdljp6/U?= =?iso-8859-1?q?3uACiADBXz+t/z2gnDRCAhH/RFqt7V7b+QWiiNsktAus4WIobnAhv0w8/MV3?= =?iso-8859-1?q?yXV1sFq/LbgQwFY3HUFHneOMYdoBYfxl+++jrHUO1sVXGTP8y3W2Esjb9NVl?= =?iso-8859-1?q?jzLGeXv+aH1vaRCqYDlsgBnVvfoxqO6i3jNo5lUbuKTo/9r9u4wJq5BugdKh?= =?iso-8859-1?q?gp8tDZLj7VPA8yR8BFJ8S8nK2A2G3f0O9mQioUE4oTmr34Iy4Hp3iQ6WLAWl?= =?iso-8859-1?q?/ewaHcuMihkNmHtxXO8CGgecbdARneINJT90e2keTu2o2SZYhWPKqSlOgwA5?= =?iso-8859-1?q?/Hev3TuWvtwrTWDJymuAtcPaNfVXJI9cKoLlAIqrvfeogHF4YJDJ49JRiQdo?= =?iso-8859-1?q?eZZmM6dJq6xXSSjWxsV5L45zxA4kD8BbOGMpTL2EEl4Cy4Gij8ktZnnfgulo?= =?iso-8859-1?q?1M2Knr+tvLA4DAa46o3kXwHfG6K0za8wnDwkobFwoKjkuPx8X7OuMiqpinWd?= =?iso-8859-1?q?fnwS6Q9XzJoReAj7le25HJNQPj3Jnvun88MQJItXlq8g8cnP9/KoTZ4RsBKo?= =?iso-8859-1?q?sbz87isFyn1Sk51PXw8IsSEb4D0MyIPa+1K1XcxD0OKGrhCV5xRf6hD1vcZU?= =?iso-8859-1?q?5r83yEr8/4qJ/NqYvNB3V0j6+DZ/IFaBhio1SA95pHwOpeUq6inkmpiK3TT6?= =?iso-8859-1?q?KfDBmDqRK5HxSE+jD3aJbaJTZyWZq3SDsyAyeFMXBjYFMiHQiaRq5SGYIVFK?= =?iso-8859-1?q?eqC421bpJi3YQjkbdKqztxRkdwVx+9b2bawl/sRSsj8CyZY8JUsdQvZtNiEK?= =?iso-8859-1?q?x239GdLWW1Rk3IoabjFGAJALIyd4rOaN9gdV48WgfMCRB9/ofjGhV4BQsaoi?= =?iso-8859-1?q?y57ABDK7bRHNPiWyOyUCqy2213Q66SfmeSWBXfAk5BezbcZPbckfxEmfq+fU?= =?iso-8859-1?q?XBiwN09QrnTfPtohex9WaBK0obzH0hwwTgGpnYzHSO5Jw8ShRa62z9hzzexW?= =?iso-8859-1?q?NDOgWY3QN32ekaGB4JEDMoeUgMRBTAbdlmMv4INcg+qUnwBcFGL1PImch6yB?= =?iso-8859-1?q?tacWZEJOxsVTekBDPF4XNwC2Me27nH5qfywk39bojtTVrg9O9SSTqkNBTGdh?= =?iso-8859-1?q?kb+tQljkQaQ1ZNQn7oU7UsIND303uo38jyUEusZEWK8Ludk6O2VwIwhWPskS?= =?iso-8859-1?q?MUfmOzhJFK2tIw5uBLZM9+Rib+fEU2Cgr9y0Nb7n6fIrmdh9QQ5m4AKxxcsJ?= =?iso-8859-1?q?EbbYcVjnfgkQ6qUdnAwlTFQ1FXJXL/xkfMM1C+7Mc6lI63zugQaHD9+2Ijdm?= =?iso-8859-1?q?nwUFGYKhlUuNQsHYJELkC7R5nhqjGQsgo0JitMHQ0aeRDKe0kqO2PDiJROIW?= =?iso-8859-1?q?hg2Hc0dDO1oPT1cmc2bvb14avhU6mTOI4gBc01zz4816plZPvWoVW5bOk/mC?= =?iso-8859-1?q?h+JqHfdTZeAVTJqOU0prhr2rjVgUXF2d5upLYvg=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: e1dbf20e-1f04-4d70-a031-08dbcb6fe741 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Oct 2023 22:09:19.6132 (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: fkhAIBvNH+jIsm8oCYBHUqB6wco71O5s0xn+DABaLJDGqZoupVvqzORXJ9j12MS3gg+WwXnvLeXtGxB3pzZ8gkGDPXTSxGwgSUTX0zespvk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB8758 X-Proofpoint-GUID: YBVKK9rlz3ToRA9CiDZ51KkeBGw_J4Uo X-Proofpoint-ORIG-GUID: YBVKK9rlz3ToRA9CiDZ51KkeBGw_J4Uo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-12_14,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 mlxscore=0 bulkscore=0 mlxlogscore=911 lowpriorityscore=0 suspectscore=0 spamscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310120186 Guest can try to read config space using different access sizes: 8, 16, 32, 64 bits. We need to take this into account when we are returning an error back to MMIO handler, otherwise it is possible to provide more data than requested: i.e. guest issues LDRB instruction to read one byte, but we are writing 0xFFFFFFFFFFFFFFFF in the target register. Signed-off-by: Volodymyr Babchuk --- xen/arch/arm/vpci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 3521d5bc2f..f1e434a5db 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -46,6 +46,8 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, { struct pci_host_bridge *bridge = p; pci_sbdf_t sbdf; + const uint8_t access_size = (1 << info->dabt.size) * 8; + const uint64_t access_mask = GENMASK_ULL(access_size - 1, 0); /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; @@ -53,7 +55,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, if ( !vpci_sbdf_from_gpa(v->domain, bridge, info->gpa, &sbdf) ) { - *r = ~0ul; + *r = access_mask; return 1; } @@ -64,7 +66,7 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, return 1; } - *r = ~0ul; + *r = access_mask; return 0; }