From patchwork Tue Mar 8 19:46:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774314 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 12F84C4332F for ; Tue, 8 Mar 2022 19:47:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287467.487536 (Exim 4.92) (envelope-from ) id 1nRfoB-0006sR-EG; Tue, 08 Mar 2022 19:47:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287467.487536; Tue, 08 Mar 2022 19:47:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoA-0006op-Vp; Tue, 08 Mar 2022 19:47:46 +0000 Received: by outflank-mailman (input) for mailman id 287467; Tue, 08 Mar 2022 19:47:46 +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 1nRfo9-0004Df-Td for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:46 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20624.outbound.protection.outlook.com [2a01:111:f400:7e89::624]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9d6bb113-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:43 +0100 (CET) Received: from DS7PR06CA0032.namprd06.prod.outlook.com (2603:10b6:8:54::17) by DM5PR02MB3896.namprd02.prod.outlook.com (2603:10b6:4:b7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Tue, 8 Mar 2022 19:47:39 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::64) by DS7PR06CA0032.outlook.office365.com (2603:10b6:8:54::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:38 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:18 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:13 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnd-000Cws-Eq; Tue, 08 Mar 2022 11:47:13 -0800 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: 9d6bb113-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZYtKFWu1scH24pEV6+3pn2Hh5fjHeU+xk2aIt0gL24+HQnSTok66G/FIBZvSeUl+sREj+g/0xnG9ZPCpDNyAqVg7imSiGmcj9/8b2yW29YCkY6QMon92nsH99BE5YQjdq6DWrcr/C/fBqP3aZG+SCe6KJNPCX1dcEq8ISlwuUTAuFp4VQieSyXIuQ7pD2HFHkh2f6KtXmZ9eK1VARTPl2w9CiExqe59Ki48ZC6hXR5b5RcicMyBBE3qIQlJymZXdM+vw4EvD4xZji6bSqSEDQ99E+9ur74BeQGHsl3AJ6NSLPOGzcsNPD/jE10szSTAINKrK3EMfrDN0w2C6eZwffw== 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=BGOLVwYIhgLxJ0FfO3ayOZRIIs0BtuO6sjO2GpK4r3o=; b=myb3fS3ippQYdiWr5UhtR2sWeP6gVPADl0Dzd7ibwEIJfWDEYhNg0FAeD/muNlF6iCoN9GJ6238FAHvA+Ef8YEfeeX5X6frvM/Yjov5zZHNtkhFB99GuIBfXnzR92gGHCDjIYWIoQH78J5/qiein2dliaaudaOoZLLl76OCTEIQEkGwtWj3SD54KS4/r+m2fXZ2h35fV+mzmXfkJ2KtHuMxmXBnBQ+b4rMwq/lEmFrq8X2PgKiF6vO/R/t/mv9cWncOKFHkx4xqKKxmC2Vd6nGrxNVBhVhdwQH77F4xjhmFmecIJZXat26mNkptyRbR19n5V0mEoAGRjv3/4L2ErUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BGOLVwYIhgLxJ0FfO3ayOZRIIs0BtuO6sjO2GpK4r3o=; b=lBnJKRZ4+KligpCfMabgh2jHuqO7BCVfA/IiQ3VfhqMd7zmuaAYoT/ZI9u8KrfKVn/KA60VrfX/r5TNUH+Q/c+vgQSncXThD2jRIOOzrzBQIUaOfFrw40GtxNNlwN/VTuCJVzDg45NFXv7DG1+ZmF5aRAlcL3Qyhn1GvigP/crg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Volodymyr Babchuk Subject: [XEN][RFC PATCH v3 01/14] xen/arm/device: Remove __init from function type Date: Tue, 8 Mar 2022 11:46:51 -0800 Message-ID: <20220308194704.14061-2-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ef5bf915-62d3-47c2-de44-08da013c804d X-MS-TrafficTypeDiagnostic: DM5PR02MB3896:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aMV8CKYmDRUtN7YElMMfIUu31J7TQDaJuVAQUWA8w8IURSrvj4Ulhct7CZorWnuFBIrZRx3rhXOgte+uPt6OlncSAZlxJAUYbtm3mjw5IonCNcfDKfOLuXytPXEm9llNvPps2FIrmhp/qkiTaRqiL7XDRqJ+urSy62uRUkYOpr5ichdfyTH+ewoOILkIH0q1A+uoSD1/jWBQfzWIaizqEuNE6OcXJTD8gB9cv45dfUbXHv4v/SUs3iBJRHSc6ZCkDeXYt9XB9H94X2SeEwARDI7FxZsY/+yKVN/0JnsRrzE1n5WUVPsenf2ftI+HDYLiWe7FdeDR0iUSIkebrStRlWxiEeZ9Cd9Dc3HK+HDVViwyTqw/B1l0/myHdemX9vWt/FSVtNw2hOXDU+/7+o0joSpcQ9eya0ivoY+s5BKBNTLxs44NURik7IoK+SHjbQYMjv+skAKh3Ko57H5IHdVVy7XFAALZyQYdRFuIDbmX+iSRTOxzEfkuue1ceKd0VbhZQV7+XfEmrFyox4Y2HxCuAXHHc2TLgI/+ZnZINY6wkZv0DEQst4s5P2SQvjbvLcLmXgn87rPjTa4Q5Ty8iqGGTiKvl0Cha+aLzXZpD17wZJ7DzND9l8XwFb86nNnOi0CqMqzU3hAAdGVXmz2gIdVDM3LYBqEcqu+wLMwRpP9RUNlKdomLWtrth0X78ONsZQX2un1H6RevHvBcoPTPL3LA/Q== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(26005)(186003)(83380400001)(36756003)(82310400004)(2906002)(2616005)(356005)(7636003)(336012)(426003)(40460700003)(47076005)(36860700001)(1076003)(316002)(8676002)(4326008)(6916009)(54906003)(6666004)(70206006)(70586007)(30864003)(508600001)(7696005)(8936002)(9786002)(5660300002)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:38.7661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef5bf915-62d3-47c2-de44-08da013c804d X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR02MB3896 Change function type of following function to access during runtime: 1. map_irq_to_domain() 2. handle_device_interrupt() 3. map_range_to_domain() 4. unflatten_dt_node() 5. unflatten_device_tree() Move map_irq_to_domain(), handle_device_interrupt() and map_range_to_domain() to device.c. These changes are done to support the dynamic programming of a nodes where an overlay node will be added to fdt and unflattened node will be added to dt_host. Furthermore, IRQ and mmio mapping will be done for the added node. Signed-off-by: Vikram Garhwal --- xen/arch/arm/device.c | 136 +++++++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 142 ------------------------------- xen/arch/arm/include/asm/setup.h | 3 + xen/common/device_tree.c | 20 ++--- xen/include/xen/device_tree.h | 5 ++ 5 files changed, 154 insertions(+), 152 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 70cd6c1a19..0dfd33b33e 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include extern const struct device_desc _sdevice[], _edevice[]; extern const struct acpi_device_desc _asdevice[], _aedevice[]; @@ -84,6 +87,139 @@ enum device_class device_get_class(const struct dt_device_node *dev) return DEVICE_UNKNOWN; } +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname) +{ + int res; + + res = irq_permit_access(d, irq); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n", + d->domain_id, irq); + return res; + } + + if ( need_mapping ) + { + /* + * Checking the return of vgic_reserve_virq is not + * necessary. It should not fail except when we try to map + * the IRQ twice. This can legitimately happen if the IRQ is shared + */ + vgic_reserve_virq(d, irq); + + res = route_irq_to_guest(d, irq, irq, devname); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map IRQ%"PRId32" to dom%d\n", + irq, d->domain_id); + return res; + } + } + + dt_dprintk(" - IRQ: %u\n", irq); + return 0; +} + +int map_range_to_domain(const struct dt_device_node *dev, + u64 addr, u64 len, void *data) +{ + struct map_range_data *mr_data = data; + struct domain *d = mr_data->d; + int res; + + res = iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); + return res; + } + + if ( !mr_data->skip_mapping ) + { + res = map_regions_p2mt(d, + gaddr_to_gfn(addr), + PFN_UP(len), + maddr_to_mfn(addr), + mr_data->p2mt); + + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map 0x%"PRIx64 + " - 0x%"PRIx64" in domain %d\n", + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, + d->domain_id); + return res; + } + } + + dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", + addr, addr + len, mr_data->p2mt); + + return 0; +} + +/* + * handle_device_interrupts retrieves the interrupts configuration from + * a device tree node and maps those interrupts to the target domain. + * + * Returns: + * < 0 error + * 0 success + */ +int handle_device_interrupts(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) +{ + unsigned int i, nirq; + int res; + struct dt_raw_irq rirq; + + nirq = dt_number_of_irq(dev); + + /* Give permission and map IRQs */ + for ( i = 0; i < nirq; i++ ) + { + res = dt_device_get_raw_irq(dev, i, &rirq); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + /* + * Don't map IRQ that have no physical meaning + * ie: IRQ whose controller is not the GIC + */ + if ( rirq.controller != dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", + i, dt_node_full_name(rirq.controller)); + continue; + } + + res = platform_get_irq(dev, i); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to get irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + if ( res ) + return res; + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 8be01678de..b06770a2af 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1794,41 +1794,6 @@ int __init make_chosen_node(const struct kernel_info *kinfo) return res; } -int __init map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname) -{ - int res; - - res = irq_permit_access(d, irq); - if ( res ) - { - printk(XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n", - d->domain_id, irq); - return res; - } - - if ( need_mapping ) - { - /* - * Checking the return of vgic_reserve_virq is not - * necessary. It should not fail except when we try to map - * the IRQ twice. This can legitimately happen if the IRQ is shared - */ - vgic_reserve_virq(d, irq); - - res = route_irq_to_guest(d, irq, irq, devname); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to map IRQ%"PRId32" to dom%d\n", - irq, d->domain_id); - return res; - } - } - - dt_dprintk(" - IRQ: %u\n", irq); - return 0; -} - static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, const struct dt_irq *dt_irq, void *data) @@ -1860,57 +1825,6 @@ static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, return 0; } -int __init map_range_to_domain(const struct dt_device_node *dev, - u64 addr, u64 len, void *data) -{ - struct map_range_data *mr_data = data; - struct domain *d = mr_data->d; - int res; - - /* - * reserved-memory regions are RAM carved out for a special purpose. - * They are not MMIO and therefore a domain should not be able to - * manage them via the IOMEM interface. - */ - if ( strncasecmp(dt_node_full_name(dev), "/reserved-memory/", - strlen("/reserved-memory/")) != 0 ) - { - res = iomem_permit_access(d, paddr_to_pfn(addr), - paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); - if ( res ) - { - printk(XENLOG_ERR "Unable to permit to dom%d access to" - " 0x%"PRIx64" - 0x%"PRIx64"\n", - d->domain_id, - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); - return res; - } - } - - if ( !mr_data->skip_mapping ) - { - res = map_regions_p2mt(d, - gaddr_to_gfn(addr), - PFN_UP(len), - maddr_to_mfn(addr), - mr_data->p2mt); - - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to map 0x%"PRIx64 - " - 0x%"PRIx64" in domain %d\n", - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, - d->domain_id); - return res; - } - } - - dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", - addr, addr + len, mr_data->p2mt); - - return 0; -} - /* * For a node which describes a discoverable bus (such as a PCI bus) * then we may need to perform additional mappings in order to make @@ -1938,62 +1852,6 @@ static int __init map_device_children(const struct dt_device_node *dev, return 0; } -/* - * handle_device_interrupts retrieves the interrupts configuration from - * a device tree node and maps those interrupts to the target domain. - * - * Returns: - * < 0 error - * 0 success - */ -static int __init handle_device_interrupts(struct domain *d, - struct dt_device_node *dev, - bool need_mapping) -{ - unsigned int i, nirq; - int res; - struct dt_raw_irq rirq; - - nirq = dt_number_of_irq(dev); - - /* Give permission and map IRQs */ - for ( i = 0; i < nirq; i++ ) - { - res = dt_device_get_raw_irq(dev, i, &rirq); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - /* - * Don't map IRQ that have no physical meaning - * ie: IRQ whose controller is not the GIC - */ - if ( rirq.controller != dt_interrupt_controller ) - { - dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", - i, dt_node_full_name(rirq.controller)); - continue; - } - - res = platform_get_irq(dev, i); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to get irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); - if ( res ) - return res; - } - - return 0; -} - /* * For a given device node: * - Give permission to the guest to manage IRQ and MMIO range diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 7a1e1d6798..8a26f1845c 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -134,6 +134,9 @@ void device_tree_get_reg(const __be32 **cell, u32 address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); +int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, + bool need_mapping); + int map_range_to_domain(const struct dt_device_node *dev, u64 addr, u64 len, void *data); diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 4aae281e89..f43d66a501 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1811,12 +1811,12 @@ int dt_count_phandle_with_args(const struct dt_device_node *np, * @allnextpp: pointer to ->allnext from last allocated device_node * @fpsize: Size of the node path up at the current depth. */ -static unsigned long __init unflatten_dt_node(const void *fdt, - unsigned long mem, - unsigned long *p, - struct dt_device_node *dad, - struct dt_device_node ***allnextpp, - unsigned long fpsize) +static unsigned long unflatten_dt_node(const void *fdt, + unsigned long mem, + unsigned long *p, + struct dt_device_node *dad, + struct dt_device_node ***allnextpp, + unsigned long fpsize) { struct dt_device_node *np; struct dt_property *pp, **prev_pp = NULL; @@ -2047,7 +2047,7 @@ static unsigned long __init unflatten_dt_node(const void *fdt, } /** - * __unflatten_device_tree - create tree of device_nodes from flat blob + * unflatten_device_tree - create tree of device_nodes from flat blob * * unflattens a device-tree, creating the * tree of struct device_node. It also fills the "name" and "type" @@ -2056,8 +2056,8 @@ static unsigned long __init unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +void unflatten_device_tree(const void *fdt, + struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; @@ -2179,7 +2179,7 @@ dt_find_interrupt_controller(const struct dt_device_match *matches) void __init dt_unflatten_host_device_tree(void) { - __unflatten_device_tree(device_tree_flattened, &dt_host); + unflatten_device_tree(device_tree_flattened, &dt_host); dt_alias_scan(); } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index fd6cd00b43..06d7866c10 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -177,6 +177,11 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/* + * unflatten any device tree. + */ +void unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes); + /** * IRQ translation callback * TODO: For the moment we assume that we only have ONE From patchwork Tue Mar 8 19:46:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774306 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 E4183C433FE for ; Tue, 8 Mar 2022 19:47:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287458.487481 (Exim 4.92) (envelope-from ) id 1nRfnu-0004p5-IJ; Tue, 08 Mar 2022 19:47:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287458.487481; Tue, 08 Mar 2022 19:47: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 1nRfnu-0004ow-Eb; Tue, 08 Mar 2022 19:47:30 +0000 Received: by outflank-mailman (input) for mailman id 287458; Tue, 08 Mar 2022 19:47:29 +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 1nRfnt-0004Om-3w for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:29 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20613.outbound.protection.outlook.com [2a01:111:f400:fe5b::613]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 954be4e0-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:28 +0100 (CET) Received: from SN1PR12CA0071.namprd12.prod.outlook.com (2603:10b6:802:20::42) by SJ0PR02MB7230.namprd02.prod.outlook.com (2603:10b6:a03:29a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 19:47:24 +0000 Received: from SN1NAM02FT0043.eop-nam02.prod.protection.outlook.com (2603:10b6:802:20:cafe::57) by SN1PR12CA0071.outlook.office365.com (2603:10b6:802:20::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17 via Frontend Transport; Tue, 8 Mar 2022 19:47:24 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0043.mail.protection.outlook.com (10.97.5.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:24 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:20 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:15 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnf-000Cws-Pa; Tue, 08 Mar 2022 11:47:15 -0800 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: 954be4e0-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JjYCbAC33fZjBExGYzn6KfLfJpuUjoJyfUdNTSq1nd8MnbdRjhQxh7yEc9LcTwkRPJkgfwWp9GBIJ9lB7B997wU6o9mN1CeTYNyGXkHniMlJDgg/TB9iJLfFs24YYb9PFwj7ckP++IMAJ+SLMN757ibS7d9avqwRraum7kGuhC7AtiB7hM3Satqwk3pSxfgiRNJubcVlz4hq8J7CmxhQ6OZBQn2DrtWtSk4kzXiabbJLNRG0E/Oyx3cXNWhE9VgGsGcTzEFEZtGbKTfpuUxHzrZprIbhB+OQaE5lBliZXABQqIfSegDHo4R7/g8qKJOhAqlZUsPATylqA+QW09p8PA== 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=KrNaJDTXo0BfvUNG8uMhFTZZ7d11YwLQSgOOIsuxOC4=; b=KoBQsYvemfLaZ06U7SHKhiWQzJtPm4FQTkSpaoVfAkgppwFvpsXx9Y69iFdDeW8yQ99UwniyCAu58AFKaf+tPAg+85tWrQRW9CBnh9lbY8ifda6GPDHoqiyHR23sCMEhWlBo1Wy7rOBvT8338WRPCRkg6836NG1k8sXZ1mj9A38T9l9I2QCT+sjfn+go9imc7nNPzAqQRdH8y7SEerCnNpgNA//46STvAGCgA+aV3NTbzWB2TXDUzXJJDP4LfrpqNyty/0d543RoCZwJ3xXzSkEcGR7UoCL5It2n94uc03h1YxA93gwsgPH7WA8pg3HxN01SKQi4fI0+xyhPbu/C2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KrNaJDTXo0BfvUNG8uMhFTZZ7d11YwLQSgOOIsuxOC4=; b=G65kcUVgrti9rwVDnyMxwV+arSsqCEqzgc8+6pslZJF6ySc+6CC3+8tUSubxqivQxwrtICdgA3NKUGM1Py5o3E/rMAK3DcKXHt+hpjp2jscHu22gwzs2EUPTQUIJV5hjOu+vk8au/84j59BEsInoCyqeg4ftvWzFuiHZ61XK1xw= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Volodymyr Babchuk Subject: [XEN][RFC PATCH v3 02/14] xen/arm: Add CONFIG_OVERLAY_DTB Date: Tue, 8 Mar 2022 11:46:52 -0800 Message-ID: <20220308194704.14061-3-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b671b5af-4179-454e-6f7b-08da013c77b0 X-MS-TrafficTypeDiagnostic: SJ0PR02MB7230:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kJ1XdXTdgbeddIecBIqAGYkuswc+k8EmaGuWqk+kG2FSjAkUp3GaMb0w8tpFH4zGg1nhTO4M1tDQHhChvZiQwo8EH8hv2IxgQJJ3EDZYPruRc3IwVUyyZyzag8s1cIrHoygu+J0vv9VQqiuYrpka1BWfNboyPfxmecsoP7brC54lBeH7HtCho6amgsrIG5SaYtIUEeIa5lfCzzzaGpH1Xgzn3Wgg8Pf7Cu/lVGKJ8s7bNvKFSt56ISMckDCrH7oO1GBWTSfLmsO/oQFi9KgArAkBWMq6rmYpCPDXzkG+wCqznFFH8ZgfGbLPNUSZyEQw+rlKT8/XpIv9E8jTqVQ4tap+bKw1D5C8d64uw1793UFoOihWyB2DNwdsSOuUcybim686+JoGEpPcbPg9oRhJ2X+gMWTn5daXjSSk20XNfs6x/A2nK0UXPwWuyr/45UNsOd+BdwfXlaMxlKcyaZ9nuveW7OL7lkCrXB3xxm9iesDxXKDJ29n4E6Rg4pJO4tUVai9BUHUwrGlAgSKjzqNIIBep3WN6O1h0PozDNMR0MHy8jYG28qefBAewJrBilcqG17s4sLfzycn19nBYx9TPIJRTfrdiEp9EBWC70S96BGF/VnNpKpLWsCYYsxu5ynZx7QP21J8uTu2TSj8+U35yK9vCqJU6CuQlB4jtcKunTEw7lX5PoLwXfcDijrgNDzasggZ3v/GmVwyg37E+w+zF9Q== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(26005)(8676002)(1076003)(70206006)(356005)(70586007)(82310400004)(336012)(426003)(186003)(47076005)(8936002)(9786002)(40460700003)(36860700001)(5660300002)(7636003)(4326008)(4744005)(2906002)(54906003)(6916009)(508600001)(316002)(7696005)(6666004)(36756003)(2616005)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:24.3126 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b671b5af-4179-454e-6f7b-08da013c77b0 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0043.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR02MB7230 Introduce a config option where the user can enable support for adding/removing device tree nodes using a device tree binary overlay. Signed-off-by: Vikram Garhwal --- xen/arch/arm/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ecfa6822e4..0159fbe27a 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -46,6 +46,12 @@ config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC +config OVERLAY_DTB + bool "DTB overlay support (UNSUPPORTED)" if UNSUPPORTED + ---help--- + + Dynamic addition/removal of Xen device tree nodes using a dtbo. + config HVM def_bool y From patchwork Tue Mar 8 19:46:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774308 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 47B9EC433F5 for ; Tue, 8 Mar 2022 19:47:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287457.487470 (Exim 4.92) (envelope-from ) id 1nRfns-0004Xm-9a; Tue, 08 Mar 2022 19:47:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287457.487470; Tue, 08 Mar 2022 19:47:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfns-0004Xf-65; Tue, 08 Mar 2022 19:47:28 +0000 Received: by outflank-mailman (input) for mailman id 287457; Tue, 08 Mar 2022 19:47:27 +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 1nRfnr-0004Om-2N for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:27 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20629.outbound.protection.outlook.com [2a01:111:f400:fe5a::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 931f53e8-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:25 +0100 (CET) Received: from SN1PR12CA0077.namprd12.prod.outlook.com (2603:10b6:802:20::48) by SA2PR02MB7532.namprd02.prod.outlook.com (2603:10b6:806:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 19:47:21 +0000 Received: from SN1NAM02FT0043.eop-nam02.prod.protection.outlook.com (2603:10b6:802:20:cafe::8a) by SN1PR12CA0077.outlook.office365.com (2603:10b6:802:20::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:21 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0043.mail.protection.outlook.com (10.97.5.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:20 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:17 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:17 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnh-000Cws-Sd; Tue, 08 Mar 2022 11:47:17 -0800 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: 931f53e8-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B+tSBFRZX0M2Ka1jVzjwPBfEsexw/LMPuSyrjcHh844AtifyZ1nNzfjYqnr6xSZzsqxH5HO2m4V3D4uy7MK5groI/UIRdczo+OQWEZ/73BmbPJg1Z5qJnNwcyO88wdkyeR17r5Hm6eaMufGifUdyRV8vTx0lrxAXL1H7cWltqC1kLpH18oPymfItJNPl/WhVsR7inMyledKJgo1+ai2GF1JRqYFbOCaHQCpIPuWSjcmBNNeXNSvkJFQfY6lYwNHIbpkAisYzHnDVyiUpDx0huQZwykCBcG8yaYTPC0ApsnKZ1rOualxGIGxe0h6Mi3J20Hkzu4Spr/ia2z1kcHIanw== 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=o2me5A34S/CA57rO9JX2LJVZGCsANGo9EZ0shS6bP8E=; b=XQA3OqMDMBFxxfkfPdYJthY1/d6wFcin+7qc1B+OJVhKSmFY5IOV4zxZobGrH8HMiQBErB2UII+WYT73alYcMcElwQXiMANHatxe5CD6c0zJmwtIRoBdwehcF0bxJshnGtt9UJ2W5kFQQQQcjaToOT8PfoHu/JZNrfqH4ZJFjHiZaOkEievd+GQpADVyGdOGie9pR0TaPuxbfmuE99sPDWE5hTuTGHd6C2LgPOW2tr92EJtJkhLRn3tx7Hrrq1mZh7EQ6NJ1zGSEqpR1+vvYR/G1Mrj66UuP1j0+Mf6bDFATDKpe4wr4+RBjwpAtp/FTpycYhA4SF80cizvul5GSBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o2me5A34S/CA57rO9JX2LJVZGCsANGo9EZ0shS6bP8E=; b=FJ6EUcmwNeZZIIZ9c/GZrH1RK5N3T8Q30fLs4xcQuAo3fanqNVvcPm+5oi70bMhZO5KjbBGWLnQvjSUVyWCMigTp2FHDNpGNhcfktUnsJqxMs85TPRPyR8KpX1PwEGBILJ2tURst2Ge4F99fiYsHU7NIPZUCx+CSvROTLlrMDx8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal Subject: [XEN][RFC PATCH v3 03/14] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Tue, 8 Mar 2022 11:46:53 -0800 Message-ID: <20220308194704.14061-4-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fefc3967-106b-45a4-ba6a-08da013c75a8 X-MS-TrafficTypeDiagnostic: SA2PR02MB7532:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dW/r58LtlZwBmki+QFLi+J8+utBW6kRLsPiveHuLHGVjr2940NpPcvTQtiraROc1jjMiDEW4FfBq5qUbZEKOmxL9yrBJTq/R0KBPsbbvCCJC/8LFbTYU39vbFrh10dZNEHYMcs8zdppIpNqxKWXNjZ29+Bsvk3aZZ67HObTArW/N7uk/+8DuqUksi/xRbjW+a3w0VWNTTSm8kJaQ8FC1Jw3OlvfAoOSHsgk4sRHzvQZUwjBO2FBGUKNBIcmhsV+PRoqOZYwkOTgOiEpTGtg+UnbOHVraAoLJ0IU86BkrEROCIJbh4X5Pb/ZNnkd1FOAvHMLRjN89II4kY929QyXep9BWe96gKD8EBhFVxvPJkPkisVYwgKiPyIdV/cKKmLXHCVhzI8C97Bd6WXXuWaowgIzQaiKn70l6mBJijwXrISXYFvaKRyGE5sVXTlhqktGt/uADQsa8pdtvnMHZxIyyI7te8evA34Ip4nT0tRAoUqdRt0cr4KXt4KBgQ9Wfb6of1NyqIdDxerkwM+ronmisPgql/Ifvrdbh5CZq0KawvBEQBKr7n1rtJNeE/qMq50lW3Oc43To19I7WwhgBppzMAlaUzW54KD5ci7HTDPvEh+w/s0FxZ6QDqJujG1GHr9ws1awk+IMg4Se1nc/AjlnAL713SbpDnUsVnOcwQEkvN3LbI9pLaF6YrPEeaACDK/7dDVodieR0E313sYctc9eueA== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(4744005)(4326008)(8676002)(336012)(426003)(26005)(47076005)(316002)(7636003)(186003)(6916009)(82310400004)(5660300002)(54906003)(8936002)(70206006)(70586007)(1076003)(7696005)(36756003)(2616005)(356005)(107886003)(36860700001)(508600001)(40460700003)(83380400001)(2906002)(6666004)(9786002)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:20.9066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fefc3967-106b-45a4-ba6a-08da013c75a8 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0043.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR02MB7532 This is done to access fdt library function which are required for adding device tree overlay nodes for dynamic programming of nodes. Acked-by: Julien Grall Signed-off-by: Vikram Garhwal --- xen/common/libfdt/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile index 6708af12e5..86faa90f79 100644 --- a/xen/common/libfdt/Makefile +++ b/xen/common/libfdt/Makefile @@ -1,7 +1,11 @@ include $(src)/Makefile.libfdt SECTIONS := text data $(SPECIAL_DATA_SECTIONS) + +# For CONFIG_OVERLAY_DTB, libfdt functionalities will be needed during runtime. +ifneq ($(CONFIG_OVERLAY_DTB),y) OBJCOPYFLAGS := $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) +endif obj-y += libfdt.o nocov-y += libfdt.o From patchwork Tue Mar 8 19:46:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774310 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 A05EFC43219 for ; Tue, 8 Mar 2022 19:47:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287459.487486 (Exim 4.92) (envelope-from ) id 1nRfnu-0004su-To; Tue, 08 Mar 2022 19:47:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287459.487486; Tue, 08 Mar 2022 19:47: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 1nRfnu-0004sK-Oq; Tue, 08 Mar 2022 19:47:30 +0000 Received: by outflank-mailman (input) for mailman id 287459; Tue, 08 Mar 2022 19:47: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 1nRfnt-0004Df-7o for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:29 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060b.outbound.protection.outlook.com [2a01:111:f400:fe59::60b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 94df3c0a-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:28 +0100 (CET) Received: from SN1PR12CA0050.namprd12.prod.outlook.com (2603:10b6:802:20::21) by PH0PR02MB7448.namprd02.prod.outlook.com (2603:10b6:510:15::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 19:47:24 +0000 Received: from SN1NAM02FT0043.eop-nam02.prod.protection.outlook.com (2603:10b6:802:20::4) by SN1PR12CA0050.outlook.office365.com (2603:10b6:802:20::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19 via Frontend Transport; Tue, 8 Mar 2022 19:47:23 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0043.mail.protection.outlook.com (10.97.5.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:23 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:19 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:19 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnj-000Cws-Hh; Tue, 08 Mar 2022 11:47:19 -0800 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: 94df3c0a-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HmJL+E1gcn2t7gqHBgKEsXEd+xRdLjuu2iyEPkCjBTexdygU6p3IwPIZbfmT0Knj4m3CZQ1C3Gbf7W8XGrP+axY+ZOLtRXtgT9QKwr9FXILfUuEeBcC1WzHLjtwt+i1u2SQJsLwJVtvcCTnHXOxRps6NkHRLdLWwumQrM/ud5RuYnpcLLFZYHCOUa6YAoiiCF8pec28urwf4+o3myXSifjD2p6+IawnTHguQPXHl33Eb2PK0Yyt+p8xstodZqkiOZDYEukUhchzJqHF+qLWIqF4kWdpBseHozCaGhzbuAXBz5KRo0kCX7Hh0ZZnprS0ySB/dq3OpwHettrcnPjRwCA== 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=S/DNwe4q4N3MUz/sgnELcNL1mBi4irU86Q0dfHBdLwk=; b=ZVbbf34t5wxWGEw/F/zaamR/1GKx/goeRZJO2NS/2RFHRDmHrROyGGNqSnAEtAeSuCHN4Gqpcw+GMvsTzY0YTwtOy2exdpq1cJNz+8ySo8KJMva0wYkXicYuS9j+njrmtmOvj7eJuYrHsrDWtj1ut7/muIOLkkn1VOeb0wcMz4QpYaItvwJU9dzugKGnu+tsWK7VJqhFilDE/RHwjeTrISoHeKF3U7vXQanMyNEssyOQnuxYqKSxXGQ9UpWAZqnCX2kE/Ows/T8CHNTD8nGQA3BbahWG4Oz+QfOe0MNpl5kn9KrmeUxSZPW8KQivaK62aDZJm0yRIm7839DVokj7CQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S/DNwe4q4N3MUz/sgnELcNL1mBi4irU86Q0dfHBdLwk=; b=HKmHXv2R0Qk6O9/TmJBT0VcglglOphz6s9SmiW8XlzDpFafRKhpi8quqEaJYI6fE7TslYnSkOvKeVm2gf8Gkhi8vQzYvH2X/3FpE6lHKZibc7yO6ITmHYfaJmRwXysvJI/0DdGQ37mOgHXeM/iNBR9XI7JS7R4FUxwOtEkjwO8M= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal Subject: [XEN][RFC PATCH v3 04/14] libfdt: overlay: change overlay_get_target() Date: Tue, 8 Mar 2022 11:46:54 -0800 Message-ID: <20220308194704.14061-5-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 28ca5c7b-9d87-4eb1-c3a2-08da013c7761 X-MS-TrafficTypeDiagnostic: PH0PR02MB7448:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X+CwbwEBtlcuIZN9EWkBgOV0ov4fijA+LfNP9jWrek5fa7vYoH+XjTnpz5BoUxe1N8+t4kkpWKX+44eThCicXSB4YkFRb5CSVIqZec64Z0E2ZvmuKQDxvZsKrYhHwSemb/uvr8kgyDu6OBGITGxgItw9xYCBSTcx9SiLjA17khVrC7YjMgbsLXb5OuutphsSXUUgNidKRblpgQNtZ4ywW6mSlzxq8K9w3UAYz8o2nWVNu9D3dVYmmKRWSXLSRlY8BpTtlBzC5GwYqEZa/oRHENneIFiVvSH5emM/aElwAzS7BRA0wX+EFiohfFRhyT1tBKBLIL3xF665o5Pu6wXnjir/RwKnjxfnqm35r9di3Whe6pjiQOQseuWgug+a9F608ozRO7tQXdn9xC53na3pOi/lpbV88/TGj023xT/WH9MqU0u1BxR/bSk00d7BlGdH7sQVNmPWdDOxseUkjOx/+D5KwXmzsI6HSCHj7MeX4/GR+fPD8yKTmloLr0XCmyC+jAQ68U1B7Jv2D1dL9iYgoElIk5uD17cbOkLfE5kDKTqg5AQ2anm+4Cwq8v66WwyeHYKF8GEB7kBN+LZhZNJhlRHk6DCWVt4lusucK1CQ0qXAQ0VYLBDrB9YxxLqFRuRA+VtvlV3b52KTR2FfvLmb08H6BcsXUesSHsgWzejz/04ogqKCuzFqqD4G9FTpiwcBQaWpcboRJ4t06Ne1lqJgmw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(36860700001)(8676002)(4326008)(316002)(54906003)(6916009)(107886003)(70206006)(70586007)(508600001)(40460700003)(47076005)(9786002)(5660300002)(8936002)(356005)(36756003)(26005)(2616005)(1076003)(426003)(336012)(186003)(7636003)(2906002)(83380400001)(6666004)(7696005)(82310400004)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:23.7970 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28ca5c7b-9d87-4eb1-c3a2-08da013c7761 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0043.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB7448 Rename overlay_get_target() to fdt_overlay_target_offset() and remove static function type. This is done to get the target path for the overlay nodes which is very useful in many cases. For example, Xen hypervisor needs it when applying overlays because Xen needs to do further processing of the overlay nodes, e.g. mapping of resources(IRQs and IOMMUs) to other VMs, creation of SMMU pagetables, etc. This commit is also applied to git://github.com/dgibson/dtc: commit: ad9cf6bde5b90d4c1e5a79a2803e98d6344c27d7. Signed-off-by: Vikram Garhwal --- xen/common/libfdt/fdt_overlay.c | 29 +++++++---------------------- xen/common/libfdt/version.lds | 1 + xen/include/xen/libfdt/libfdt.h | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c index 7b95e2b639..acf0c4c2a6 100644 --- a/xen/common/libfdt/fdt_overlay.c +++ b/xen/common/libfdt/fdt_overlay.c @@ -41,37 +41,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) return fdt32_to_cpu(*val); } -/** - * overlay_get_target - retrieves the offset of a fragment's target - * @fdt: Base device tree blob - * @fdto: Device tree overlay blob - * @fragment: node offset of the fragment in the overlay - * @pathp: pointer which receives the path of the target (or NULL) - * - * overlay_get_target() retrieves the target offset in the base - * device tree of a fragment, no matter how the actual targeting is - * done (through a phandle or a path) - * - * returns: - * the targeted node offset in the base device tree - * Negative error code on error - */ -static int overlay_get_target(const void *fdt, const void *fdto, - int fragment, char const **pathp) +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp) { uint32_t phandle; const char *path = NULL; int path_len = 0, ret; /* Try first to do a phandle based lookup */ - phandle = overlay_get_target_phandle(fdto, fragment); + phandle = overlay_get_target_phandle(fdto, fragment_offset); if (phandle == (uint32_t)-1) return -FDT_ERR_BADPHANDLE; /* no phandle, try path */ if (!phandle) { /* And then a path based lookup */ - path = fdt_getprop(fdto, fragment, "target-path", &path_len); + path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len); if (path) ret = fdt_path_offset(fdt, path); else @@ -638,7 +623,7 @@ static int overlay_merge(void *fdt, void *fdto) if (overlay < 0) return overlay; - target = overlay_get_target(fdt, fdto, fragment, NULL); + target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); if (target < 0) return target; @@ -781,7 +766,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) return -FDT_ERR_BADOVERLAY; /* get the target of the fragment */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; @@ -803,7 +788,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) if (!target_path) { /* again in case setprop_placeholder changed it */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; diff --git a/xen/common/libfdt/version.lds b/xen/common/libfdt/version.lds index 7ab85f1d9d..cbce5d4a8b 100644 --- a/xen/common/libfdt/version.lds +++ b/xen/common/libfdt/version.lds @@ -77,6 +77,7 @@ LIBFDT_1.2 { fdt_appendprop_addrrange; fdt_setprop_inplace_namelen_partial; fdt_create_with_flags; + fdt_overlay_target_offset; local: *; }; diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h index c71689e2be..fabddbee8c 100644 --- a/xen/include/xen/libfdt/libfdt.h +++ b/xen/include/xen/libfdt/libfdt.h @@ -2109,6 +2109,24 @@ int fdt_del_node(void *fdt, int nodeoffset); */ int fdt_overlay_apply(void *fdt, void *fdto); +/** + * fdt_overlay_target_offset - retrieves the offset of a fragment's target + * @fdt: Base device tree blob + * @fdto: Device tree overlay blob + * @fragment_offset: node offset of the fragment in the overlay + * @pathp: pointer which receives the path of the target (or NULL) + * + * fdt_overlay_target_offset() retrieves the target offset in the base + * device tree of a fragment, no matter how the actual targeting is + * done (through a phandle or a path) + * + * returns: + * the targeted node offset in the base device tree + * Negative error code on error + */ +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ From patchwork Tue Mar 8 19:46:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774312 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 1B0F9C433F5 for ; Tue, 8 Mar 2022 19:47:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287465.487525 (Exim 4.92) (envelope-from ) id 1nRfoA-0006hw-DZ; Tue, 08 Mar 2022 19:47:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287465.487525; Tue, 08 Mar 2022 19:47: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 1nRfoA-0006hd-8G; Tue, 08 Mar 2022 19:47:46 +0000 Received: by outflank-mailman (input) for mailman id 287465; Tue, 08 Mar 2022 19:47:45 +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 1nRfo8-0004Df-Tb for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:45 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20613.outbound.protection.outlook.com [2a01:111:f400:7e89::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9db42aac-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:44 +0100 (CET) Received: from DS7PR06CA0052.namprd06.prod.outlook.com (2603:10b6:8:54::30) by DM6PR02MB5868.namprd02.prod.outlook.com (2603:10b6:5:150::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Tue, 8 Mar 2022 19:47:39 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::83) by DS7PR06CA0052.outlook.office365.com (2603:10b6:8:54::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:20 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:20 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnk-000Cws-DA; Tue, 08 Mar 2022 11:47:20 -0800 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: 9db42aac-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ckjGEXAKtYf2+ownQ1TlKXrAbMXYFIFMLtaBVqmflU0FaELV47fqPSz4+STLwDge0ub+PpsbfdcLGESMzd2Z2CLAJrdFDx6YNn2vhM3+W5n3FT+Illb7D0unQwxShSv/hnRu+IBc47ZfeMkF4bo5XK/a0a4IhAIXJK1psyROFuqVIiwAVjbQstN/zHiJmCXrG1ja+o+YkNw5KLZCd81O4e8cphv6mjTw2jV25iM1+oxV1tlQ2GkfWvW+IKUnpwWsJnxxFZUs2AxN3nf/t1awa8jo8q8nwEpH023yYxA6Uq0561TLRBMC4lobP29E3PI5qc/wGmA1gk4DLOb6/emUiw== 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=ktbSIbgnDy4Elv8mz8USxfaqVJQB12rlhbrwf9cRzXw=; b=iO9sRq5R4pjqDo6w0BLmKxJT/QHUDE0Vo//7Wkq1E7y9LPNOXaeYhHl745j4Fu6GK1OqP/o4FgzGu095AYBPSZkVRxqgaHy0IyIijzIsrs3gQ8HSCY68ZaFMBzAhSopSMU8WWJjvyDEz12zirswoA3qAAHelFdOFshQvMhW9JLcqUyw7D3s4YuTpdDaD1lplVDmwqVnC38AgYxTnAKFPzWq6bTPQ96UPbJRRtiTWWtH3GZU5XJStmauV4WbMyO0pdVJeEZBOBWSXJltidLfNu5cWui5wpY1WRlw6U2udr5CrrF/cd78rNVPSOXO0JX9vZzSQd77zfiEz4LTRa0vQ+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ktbSIbgnDy4Elv8mz8USxfaqVJQB12rlhbrwf9cRzXw=; b=I1xz+qdYktOMasdMfGSa63VypE49vBF7oimq0cETEcKTZJxZU2QRxbd3wwX1YSZC7xrBH0xMiX3WuLp7h4DeJMQOGsjoxZwK147BMDp2ih8V3wK8LaBk2CNqwDdaFN+Z2R58L5vRsdg3602wNI2rwHC0tg6tPdvdTC9LBBg7nnk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal Subject: [XEN][RFC PATCH v3 05/14] xen/device-tree: Add _dt_find_node_by_path() to find nodes in device tree Date: Tue, 8 Mar 2022 11:46:55 -0800 Message-ID: <20220308194704.14061-6-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ff52281-8d79-4c1f-13d2-08da013c80a6 X-MS-TrafficTypeDiagnostic: DM6PR02MB5868:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mMiEKPPpPmLgVBvSeZnPHYKcY6ImqGUhqCq8wwEdO2H1qB4do5N/QkzqwKjdu/cajG31cW7OaQmEDbokCDp9Km/6Qg8KsBv9OVX28AaDf3kYyBnpvW/POAABMBoSkQbp/UC9SfZchpjvv4eUIyyqxn2azMBwFhgZQYzIHg2ntoGrMWvTEcu1yeOhTYukc/arjTMImMiV4MG3Mtwq78ybHfrl3u9cB/cTGyAdYUbWeG8efX8jiS2zdUDN3Q0nbJcIAqk4WAT8vJ08rkFAzVHHjGzSC36LCDZ5wWD5LE+e/RqGzpgSt21yznU969rPcPJhHV4DNGbzPyv8hrjoNbTFgFo1FolYY8CM0t3NrW6pqnK+pLKDnuX/+jE4n0dSR/lBXuy5SLmnW/TwnsMUkBIGO6jxoct6wH0tO12K0KCpXpMBDD4u7LS1+gqeoLgxN8XeDxv1S+9k2HqHBU5vdxyRLO8aov8PWS+Zs9+ATDO9Tm+zUk99c4YOlGmp/wQPwcckU0swuvstdCqJETj92SBHIDmZM6kTgbma+qyUoH5F9XKkzjAsGJl5yR1eVP0TjPD7+HmZLRbX26m+eilWE41tYhL+s/dfho1SOz51Nhd/8OiypH/YiUU0FW+30heDWPoFBLkdbA95ZEmKtB9hGy80cjJe8yWRNFIZlsJAvhCmDqO7QNlOFU+xnZFo1THnstMsOSmoxZ4gMQ53MSIJWamO+gn6zMEWaRyM2jKZvPl5ufM= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(336012)(6666004)(356005)(7636003)(26005)(8676002)(40460700003)(2616005)(1076003)(7696005)(5660300002)(508600001)(2906002)(426003)(36860700001)(8936002)(9786002)(70586007)(70206006)(82310400004)(186003)(316002)(47076005)(107886003)(54906003)(36756003)(4326008)(6916009)(83380400001)(102446001)(37363002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:39.3442 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ff52281-8d79-4c1f-13d2-08da013c80a6 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB5868 Add _dt_find_by_path() to find a matching node with path for a dt_device_node. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 10 ++++++++-- xen/include/xen/device_tree.h | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index f43d66a501..2e334f949e 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -358,17 +358,23 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, return np; } -struct dt_device_node *dt_find_node_by_path(const char *path) +struct dt_device_node *_dt_find_node_by_path(struct dt_device_node *dt, + const char *path) { struct dt_device_node *np; - dt_for_each_device_node(dt_host, np) + dt_for_each_device_node(dt, np) if ( np->full_name && (dt_node_cmp(np->full_name, path) == 0) ) break; return np; } +struct dt_device_node *dt_find_node_by_path(const char *path) +{ + return _dt_find_node_by_path(dt_host, path); +} + int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, struct dt_device_node **node) { diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 06d7866c10..9da32a851e 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -525,6 +525,15 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias); */ struct dt_device_node *dt_find_node_by_path(const char *path); +/** + * _dt_find_node_by_path - Find a node matching a full DT path + * @dt_node: The device tree to search + * @path: The full path to match + * + * Returns a node pointer. + */ +struct dt_device_node *_dt_find_node_by_path(struct dt_device_node *dt, + const char *path); /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the From patchwork Tue Mar 8 19:46:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774319 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 97FB7C433F5 for ; Tue, 8 Mar 2022 19:48:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287478.487586 (Exim 4.92) (envelope-from ) id 1nRfoH-0008Qo-TB; Tue, 08 Mar 2022 19:47:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287478.487586; Tue, 08 Mar 2022 19:47:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoH-0008PA-81; Tue, 08 Mar 2022 19:47:53 +0000 Received: by outflank-mailman (input) for mailman id 287478; Tue, 08 Mar 2022 19:47:52 +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 1nRfoF-0004Om-Pl for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:51 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20618.outbound.protection.outlook.com [2a01:111:f400:7eab::618]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a252d0fa-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:49 +0100 (CET) Received: from DS7PR06CA0029.namprd06.prod.outlook.com (2603:10b6:8:54::29) by SJ0PR02MB8784.namprd02.prod.outlook.com (2603:10b6:a03:3e1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Tue, 8 Mar 2022 19:47:46 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::92) by DS7PR06CA0029.outlook.office365.com (2603:10b6:8:54::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:45 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:45 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:26 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:21 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnl-000Cws-5e; Tue, 08 Mar 2022 11:47:21 -0800 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: a252d0fa-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=evO+N4/NqQj5VI5dAlaM6O4Yo2tX0jJQ8SDjFtHSF8I+OiR2/+vGinMiMDYOgWI4qZ//eg2wjwblNMzG06946MDLv00u3JZ74N6gu3F5lyOGjjVGe/r/gC9+IrkvdsrE2CSgxQGigWcodanRl8w3AZ5hBvyzjZAVtOxQPsHh7uPo89e/kCSvJ5N+7enyhmw80IPl2v8h6CXNo1KxsmCaYYzVIxjW/nilXLx/oMTExKnOAQxc7/y9r4haqHE+pFvfGOMxASYjx2fJV2KeOhi9SdV72dznYBfHsxR3cJq4xad5CURst/TPjl2MbulRR0hnNWKiKaZ6p7BrH09931Sgkg== 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=W7qfG/E62ZPUQLKP3CMDSNtZWZYJXpDeF3V5RfWzOVc=; b=k7MyJrWg39HGU/4vZC1XRjnzJWQDtBTJiqfAHhEgMqanlqk2bY0ypKeQVHzNcmRm0WtKWUzp8wGDMF53NFQqhnlXglR3sZFIwXhHUmc+SwEaP6rg36rPp9T359o9q10FxeI8ABKCrCbJ3GVBEE6l3Iy7sTFPEz7fmMYengLI1Nc+WjLbIP+O5DLSOBf2EqyenmsiRGPquhAuQ7OLnW99aPqry9bOCX0A3v6Lf8YmkPpUAL23kj38IgiCjPgCuZ28y1loAm3RT6E8ix9xcS073rThqEjaZz6AWvTXIgqqVU4oC2HmpEX8afN+O0WZvur73AdAxYaWW+qrgEDT7JSNmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W7qfG/E62ZPUQLKP3CMDSNtZWZYJXpDeF3V5RfWzOVc=; b=QbgF+U/E95WZso4QCEbIj/KlZ4pc452OiDNG4SDGpcXAPHihjXoTrZFdl9NgYdZx+0nSiacUh0u2kKfZtS91YOCxnOFHJqcDeCyKBkk+mUjwzb0qkLurzoJhEKoOGuBUOV/tnSa238ql2f2zCEvd9jjCLjs8Uw+hpXwy7+FlVzs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Volodymyr Babchuk Subject: [XEN][RFC PATCH v3 06/14] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Tue, 8 Mar 2022 11:46:56 -0800 Message-ID: <20220308194704.14061-7-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bef838d3-10fd-4806-fe9a-08da013c846d X-MS-TrafficTypeDiagnostic: SJ0PR02MB8784:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g1o9PnDS8k8B4xsbIxjCbdSVqwspk9GkJBJaPYgyG2EDBLHw93Ng9bi4QBvcMmPbbQz7+0xvTxdgOdbf7uvVZNs3zmzjOajkPsUihcfDOkHslJFzlIIiZWKJbMgCWPXhsnqcTXUcNbQBk9dnl2fjqEF9R+X9SIBHuzKsrTyqwANfONZBdclyWbcospVG581HFt3b5l3hO46QFyXKzRaIUp+5gCZgUkVaB62webvcrjDh6rBinvhZp+vYK3NBOv+kUQ8xfm+faFxdbCIQYXh6WVGXW57M9n1usWqOWKXiIA4VJyXFZZ3finu5oPZE68o6zZJSq1OXTm0FY2paJ/8gHoW2WmgHr2Icszc1869TND3dBgJdMkQA+75WprB/IfPokPEtI7JjIK9/cDcchfGI49PwJQwcoL13ECD69NDJGFZvji/S9fGJWwZXSrsbKxO/c4qwjL6q1UiigYQ448Cs1ACdtbAmbXEHRUqYho3MtY175lSQKNLUOdfsOCz1ASSblXf0FMO7/3Q9FmytMlAicW+DcrUefkxtVwwuPYsKd1BRDoQYQ7R92CoudmvDI5+5vtOs5KsOEu1A/344FMoK4+MuE4/mF7fWKkIj3CQB0NZ8wp0aFuSMs4smIYCTQtfuRQjrBN/SF/U5auIv3KiuTmxkdsRgIOXWgFEOltp3HdHTvQ03iHIwPXnXGGm27Ui0Cvk7o8ZMncr9gGabIPVVYg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(6666004)(2616005)(8936002)(8676002)(4326008)(508600001)(70586007)(70206006)(5660300002)(36756003)(1076003)(9786002)(26005)(2906002)(316002)(186003)(7696005)(36860700001)(6916009)(54906003)(47076005)(336012)(426003)(40460700003)(7636003)(356005)(82310400004)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:45.6875 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bef838d3-10fd-4806-fe9a-08da013c846d X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR02MB8784 Add remove_device callback for removing the device entry from smmu-master using following steps: 1. Find if SMMU master exists for the device node. 2. Remove the SMMU master Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- xen/drivers/passthrough/arm/smmu.c | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index b186c28dff..8b3b8b9850 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -816,6 +816,19 @@ static int insert_smmu_master(struct arm_smmu_device *smmu, return 0; } +static int remove_smmu_master(struct arm_smmu_device *smmu, + struct arm_smmu_master *master) +{ + if (!smmu->masters.rb_node) { + ASSERT_UNREACHABLE(); + return -ENOENT; + } + + rb_erase(&master->node, &smmu->masters); + + return 0; +} + static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, struct device *dev, struct iommu_fwspec *fwspec) @@ -853,6 +866,32 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, return insert_smmu_master(smmu, master); } +static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu, + struct device *dev) +{ + struct arm_smmu_master *master; + struct device_node *dev_node = dev_get_dev_node(dev); + int ret; + + master = find_smmu_master(smmu, dev_node); + if (master == NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret = remove_smmu_master(smmu, master); + + if (ret) + return ret; + + dev_node->is_protected = false; + + kfree(master); + return 0; +} + static int register_smmu_master(struct arm_smmu_device *smmu, struct device *dev, struct of_phandle_args *masterspec) @@ -876,6 +915,22 @@ static int register_smmu_master(struct arm_smmu_device *smmu, fwspec); } +static int arm_smmu_dt_remove_device_generic(u8 devfn, struct device *dev) +{ + struct arm_smmu_device *smmu; + struct iommu_fwspec *fwspec; + + fwspec = dev_iommu_fwspec_get(dev); + if (fwspec == NULL) + return -ENXIO; + + smmu = find_smmu(fwspec->iommu_dev); + if (smmu == NULL) + return -ENXIO; + + return arm_smmu_dt_remove_device_legacy(smmu, dev); +} + static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev) { struct arm_smmu_device *smmu; @@ -2861,6 +2916,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arch_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, + .remove_device = arm_smmu_dt_remove_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, From patchwork Tue Mar 8 19:46:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774315 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 7C8D3C433F5 for ; Tue, 8 Mar 2022 19:48:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287468.487553 (Exim 4.92) (envelope-from ) id 1nRfoD-0007OF-5O; Tue, 08 Mar 2022 19:47:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287468.487553; Tue, 08 Mar 2022 19:47:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoC-0007NM-Lf; Tue, 08 Mar 2022 19:47:48 +0000 Received: by outflank-mailman (input) for mailman id 287468; Tue, 08 Mar 2022 19:47:47 +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 1nRfoA-0004Df-Tl for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:47 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20613.outbound.protection.outlook.com [2a01:111:f400:7eab::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9dc8150a-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:44 +0100 (CET) Received: from DS7PR06CA0038.namprd06.prod.outlook.com (2603:10b6:8:54::19) by BL3PR02MB8161.namprd02.prod.outlook.com (2603:10b6:208:35c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Tue, 8 Mar 2022 19:47:39 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::f5) by DS7PR06CA0038.outlook.office365.com (2603:10b6:8:54::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:21 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:21 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnl-000Cws-Px; Tue, 08 Mar 2022 11:47:21 -0800 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: 9dc8150a-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dZ/5wE7D9jBOwYwBEyQgN5cHRcTrRomQr0ye7YjnVC/Ed4oTfmSlNb2Wf4pkS5WW+IGw1D+qWY0DY4WBmVMC7v5ofnLCDD8dGvUpKRhu7z8P9UHuVm1929hI1PchcGes06yJh06+YekQTtlCHuDMOsk9V+JQwyEsS9ukDiOdZK/QOz/efCKgxCVVSZ07J2ySwx2mVkpgMOlGR3PTnnRjToKZdfPXH1NY9IQytQ96k53VkIYPO8J5TYvWZsrPhsDb/WLBnf6isxfL/WTQrGrTat0tCcSLcCbXgqC9YjS7lG8pB9lHHMekvEUvqPn3f5pk+vLYjwA8a7gUbsG3X7TIqg== 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=c4E5KeTGHuyUkTzR8/a8yq2xjltDv0G0kEA7U7nbO7M=; b=bry9dVVFKrnyNLLm13blu/q7Pn6UMNdF8ACy6ZndOcHwgMmxNSaKK1S+7mhqTsww0sULTh3m7IceRlWPWlJsbuq8OuDN/bS8ueKi+dtoKMDCHEHJLFfnyVRK2shNiZNu0RepG9Dv5fxuQuSO4hoEXqtjq3fdEHSSAz6sA2bXsj1KU2SZ0Hc0NY7U7oglL8bC1vUsrfER5S2Yaeh8GlVfHzx2CheqV8Ao+ydN3AcXhKVnGGe5xvB+CjuAYo9C4azcepLHdrtRcUPEYyb3408MOrBucGNrsNluljKDlKnuClXM078a7rvHtVVHcs9XoJxuPb++SeG/AWQRM3xCx+3NNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=c4E5KeTGHuyUkTzR8/a8yq2xjltDv0G0kEA7U7nbO7M=; b=d659+CeKBo0KqQL4JG/FwUOalGibM+BEQYq2w8vXyy/NOYthdTAnCCC0O3sODCb13yLpbDWOXZMV1ERs2FaeKTs7Kt+MpqJLhoqLtx4sJaBe840JOjSlOH7yO0CuckOdMGwt1X/Io7udXrHi21mUQim90u7zrPEnjkZoFBLWTPc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal Subject: [XEN][RFC PATCH v3 07/14] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Tue, 8 Mar 2022 11:46:57 -0800 Message-ID: <20220308194704.14061-8-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 66a19008-cac4-4baf-c20c-08da013c80d5 X-MS-TrafficTypeDiagnostic: BL3PR02MB8161:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yI18U2FpnYgabbtahPvrZvth0sOxswSTH/tFgHVSxLUjpPq3MC9vDGI9FRgTNbCjB5N39H8KT3JanZlHnMo5yYp3dTxQHCeh8lF07E9zh/FDCHtBoCgsIRBZgxKrE34uZhs6d709u1jgEX5NI2opTFXVg5C06MKmt0O/euu5Qwh2GlmWmZiBzfPYa7N4lPpQkTXx45qFunkP2tNww+JmqWQp6/pWU6+04YWs1a6R0pYk05wVo0KZd+stPW9N4aAtRBmVAWhipgpxz01SLA1nB68Ax1XCP/XO+kfF7nYrykYW6c80xe/pEqwTqCzluUHHz0R4nfJyXO1owTNVpo7UMBNKy4MDgLEcZDDOzyOOWpCvvY6k5uq+5MdswE9feeRQYgEhCcJlJj0K6+pHcRHADg2DXUNpPsLwMC/y2RKj4uf6z9ElVC4yE/RBmCi/D2akd6xgwar8nTfVy2rCmNeHq7gzzYGPsKAxx45wS6rruN+PpbJ62ZU5FZywpqA1U4Qxvu29fGHJlVzKwklQS3Mu31ZWSWNbk58KYs0kj9uz0ULveHI51KvzHg4kbV10wIfoo6bovodZpWz61Hr+MYKK739HLgAKRKuI87pEywgUqC2kMeoyCceUIe42T/oHZmkPrTxQbpMTzPg/TtFvFChCrxYyl2pb68jQtqnBS4ZWffLOSZr2pPT0K4VJjC0C8j2JtB/ShJFjcy4g8YPUiTzSJw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(40460700003)(36860700001)(356005)(7636003)(6916009)(70206006)(70586007)(4326008)(54906003)(316002)(2906002)(9786002)(8936002)(5660300002)(426003)(336012)(8676002)(107886003)(1076003)(186003)(26005)(47076005)(83380400001)(2616005)(508600001)(7696005)(6666004)(82310400004)(36756003)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:39.6567 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 66a19008-cac4-4baf-c20c-08da013c80d5 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR02MB8161 Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_lock(). Moving spin_lock to caller was done to prevent the concurrent access to iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- xen/drivers/passthrough/device_tree.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 98f2aa0dad..b3b04f8e03 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -83,16 +83,14 @@ fail: return rc; } -static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev) +static bool_t iommu_dt_device_is_assigned_lock(const struct dt_device_node *dev) { bool_t assigned = 0; if ( !dt_device_is_protected(dev) ) return 0; - spin_lock(&dtdevs_lock); assigned = !list_empty(&dev->domain_list); - spin_unlock(&dtdevs_lock); return assigned; } @@ -225,12 +223,17 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, if ( domctl->cmd == XEN_DOMCTL_test_assign_device ) { - if ( iommu_dt_device_is_assigned(dev) ) + spin_lock(&dtdevs_lock); + + if ( iommu_dt_device_is_assigned_lock(dev) ) { printk(XENLOG_G_ERR "%s already assigned.\n", dt_node_full_name(dev)); ret = -EINVAL; } + + spin_unlock(&dtdevs_lock); + break; } From patchwork Tue Mar 8 19:46:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774309 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 6992FC4332F for ; Tue, 8 Mar 2022 19:47:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287460.487503 (Exim 4.92) (envelope-from ) id 1nRfnw-0005MO-Fh; Tue, 08 Mar 2022 19:47:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287460.487503; Tue, 08 Mar 2022 19:47: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 1nRfnw-0005MH-Bi; Tue, 08 Mar 2022 19:47:32 +0000 Received: by outflank-mailman (input) for mailman id 287460; Tue, 08 Mar 2022 19:47:31 +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 1nRfnv-0004Om-9Q for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:31 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062c.outbound.protection.outlook.com [2a01:111:f400:fe5b::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 96a8cb47-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:30 +0100 (CET) Received: from SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) by CH0PR02MB8092.namprd02.prod.outlook.com (2603:10b6:610:10c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 19:47:27 +0000 Received: from SN1NAM02FT0027.eop-nam02.prod.protection.outlook.com (2603:10b6:805:ca:cafe::5c) by SN6PR16CA0062.outlook.office365.com (2603:10b6:805:ca::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:27 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0027.mail.protection.outlook.com (10.97.4.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:27 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:22 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:22 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnm-000Cws-Ei; Tue, 08 Mar 2022 11:47:22 -0800 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: 96a8cb47-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ETL0EnEm8zZvceHCk9Sc4USiDH9/QC18lc6pSqjuz/35oSSQjpuMi533y+I/hXd8+9KituXkPncfRdmBUh02HNuOxP3DC0ClJnuCkjo1+rzOkI4QXsqYjGDpkydGeP26AQ2d7bwIHxHWBuuTxNbFWdBBM0LTyvfOL7tIKFnOCvk/ix6YZwARL9T+1q3hkIkSP48DNXtwzfjZYpgti8bOzntiU42RmC2C/ceBbPjY6PRnljA04Cqy/uznAgkD3izPri/9fSOh30L7g47EqrOFJEwkcIvMQYkERQlC0VRWHawqeaFwiDWvDrB5EhYaSHPf6XFDtLQ1nXAvYAr0oZt2eQ== 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=3IWMUDk1B29LOn60YW7dkrnq4Tu3150fXZJyXETxs0g=; b=QET60cJxqjQyKmYqU66ZH7Tya0UYonhuDYyuvLRv4Krkuc2D7vqMcOBftloMXqbF1Baw4YD8sijq7ZOE8OeArC8HWeKifB5AM4/ACub/TeJkhrvw8uU9K0yhpzMbHhlflAWg1jY+GMvNjM70ClzsFCpeX2L07e85shu8pQ/5P+5j/420tskQBQ1L6jc3OnUMkyfKPZ/cOz+KenZwW5LD20yFtPSNKAhvtzvBVFnDUEIZJn+nbyVaRkx4vlW8EdUenpmCeq2X7kWZI3fZfpFZtbAsyac5PFfAHFeRh1Fsi9EYsjmDIzMYm369BbWS2FXTaC8+XnJyYwjncwluKPwQKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3IWMUDk1B29LOn60YW7dkrnq4Tu3150fXZJyXETxs0g=; b=PcToAz9Lv2wQUk+Qqi/uwDz80/MozqmOVAz8mMwDq1Xc+v7YpFFTfrU2T2j7mUsNiHE9iSNigykLwzDvtUkF/VM0IXZ/AFhX+Oc/4CelRp3Ix8hvU33GrGOvSZkx38/5TBU+SIKmwFd5GwquVjUG4/yTz5LBoWncbpulo7qn1u8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal Subject: [XEN][RFC PATCH v3 08/14] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Tue, 8 Mar 2022 11:46:58 -0800 Message-ID: <20220308194704.14061-9-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f23ba2e9-c30a-4b02-1b46-08da013c795f X-MS-TrafficTypeDiagnostic: CH0PR02MB8092:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E+1kSDI9CKq/nGZUfoTRLeQhuupL5WeTD/y3gQgiiSqxIWwIiw3C+Zeog4HK7yDjLFYNGJTdQN9TJoCX9o41NLxnlfVWSs9Kq3BrDk63OJxynvmYXCFSA8EvFUyKHSBj6EdhdSPBvSL97zRsqMZ5lhVwj/nZyc2OqTcGkxMtILf6GFm6sxdVxwP8qwQS8kRakt/IsgmCy7MoljhM+By3dVmbT9YAaqWylMx62j2dEodshDDl50TdiyWsyYrY0/OjpLJakTwTTOt7JgFg3YCNkS2z/PxC2cEDuPvkJMlHZHAZ2/d+QiIYtdGWYi/iWEbSZcLOQKHYiBPH7/oTu6DGLAYJz7qFfqgEAmDrEHN1UDLNQpWCGThmZJi92sMhGV4Ba1UIvoWe6q0Q17jk5EoptQJEgYhhhqVm46lvUWm/yK2kVVDqv/MrT0zy4RoE6uZZzq13/GFz1Ojl2rtLVeX+BpXWjk0+JanMaxXSDBoqe8D+lDlPqzbee/5tVGAoPZ6YeqUcp/cwBatuJEQdQkBBt/DkypriP7rDNFlsps5aR2AVIIArdj/Uxuq3uZAElv7/29M54arAGo2h6sbncUDyfX5xoBuA17mi8pszG6Gk/EJoleO0/WZGkXwuSJVMxPlboL82l+XZXdUhMltOOWspwXc7SZviVLdAauytTkcdbVihq8cd/R8OyNgIc+uwapc//0sCxfJST8xHgIAbjuDJNA== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(8676002)(508600001)(7696005)(6666004)(82310400004)(4326008)(6916009)(316002)(70206006)(70586007)(54906003)(47076005)(40460700003)(36860700001)(26005)(7636003)(83380400001)(336012)(356005)(2616005)(426003)(186003)(1076003)(107886003)(36756003)(5660300002)(2906002)(8936002)(9786002)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:27.1350 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f23ba2e9-c30a-4b02-1b46-08da013c795f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0027.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR02MB8092 Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access add. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- xen/drivers/passthrough/device_tree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index b3b04f8e03..776809a8f2 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -145,6 +145,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( dev_iommu_fwspec_get(dev) ) return 0; + spin_lock(&dtdevs_lock); + /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt * from Linux. @@ -157,7 +159,10 @@ int iommu_add_dt_device(struct dt_device_node *np) * these callback implemented. */ if ( !ops->add_device || !ops->dt_xlate ) - return -EINVAL; + { + rc = -EINVAL; + goto fail; + } if ( !dt_device_is_available(iommu_spec.np) ) break; @@ -188,6 +193,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); +fail: + spin_unlock(&dtdevs_lock); return rc; } From patchwork Tue Mar 8 19:46:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774313 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 C43ADC433EF for ; Tue, 8 Mar 2022 19:47:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287466.487530 (Exim 4.92) (envelope-from ) id 1nRfoA-0006mF-Tr; Tue, 08 Mar 2022 19:47:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287466.487530; Tue, 08 Mar 2022 19:47: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 1nRfoA-0006lx-M0; Tue, 08 Mar 2022 19:47:46 +0000 Received: by outflank-mailman (input) for mailman id 287466; Tue, 08 Mar 2022 19:47:45 +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 1nRfo9-0004Om-9D for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:45 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060d.outbound.protection.outlook.com [2a01:111:f400:fe59::60d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9e3e1468-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:44 +0100 (CET) Received: from DS7PR06CA0029.namprd06.prod.outlook.com (2603:10b6:8:54::29) by SN6PR02MB4222.namprd02.prod.outlook.com (2603:10b6:805:35::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.25; Tue, 8 Mar 2022 19:47:40 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::82) by DS7PR06CA0029.outlook.office365.com (2603:10b6:8:54::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:40 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:40 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:23 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:23 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnn-000Cws-52; Tue, 08 Mar 2022 11:47:23 -0800 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: 9e3e1468-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ldUdEaGswBbDtujp2DwHiW9MsZxSMSw9dv8eJW3h+o/vdVRpOUVzRHcljLXEpXVYo6cNag64sS/DaraIMRk1eFBVq1wbau1vzT737ELklqoJITzXiXsmgYf17ZVTL5HcqLAzq+btsPz2+WgaQPpiUPUgHTfK5qqgBSjMrn2ddYixa3rj3ied+P2fbzP0jvaQJ6jQsnGMSG2L/qOMldYFRdx4OhqiE3NejHCm48T/ed9da1kHMEFb/TCzoFcamm1w2GbaNztxRwEGnXZBN4CW7vr9eNbGTsJppqPwX+eNoFdSviII7T3rK5YOZH+V1NVa2GcKf2/eEW+k4p+8qF1ZfA== 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=2hiYAAnRJSQ97HoN+W3p3cdTXxnyKZvARJ1IXwEqMPM=; b=bQd8aM+ebjaAE8OXf+SMczAKEo0tzaLLPAeSu7J5PoEMaHnKc9eecJphouJiBkZ8fWsUVwdZj7RDzg+cS0UkLGinoaUZctx+GNR6LoxiY58OKJzqSI7vl2uYxC1cVEs2NAW9xC0e8EfcQR4DGzMWFt2PdTULhEnDLSP/en6L6pHyG/x6liFD7rntuJAz3sRjYBtwBcuMT2haHHFGNdhCLY4HOGEfAKVHeKK15+/5xhZORT6ILvi1E/PzsZDcwPH04uMXhcWJlsMhkxYv6eZgkzs8W6wwJq1RxpRjvLNe7FU1MakzvJI+Q2trYNctu2/0b40HEaIP3saVpmxDLdQG5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2hiYAAnRJSQ97HoN+W3p3cdTXxnyKZvARJ1IXwEqMPM=; b=cw/3WSoAJl73LKZPmd/Gmv/mB0ewwY6/7iZ1Pm8qlV8getsWibNYVVA3v5+K23WO3t5u9Q13uAoDqafHJiWs1muqn+bIerrJEaykrrWyDmfMuJy+wOKsmMVVvE6q334cKWJULvhY8HmEMA/k/kt7qjbytFoTav/mnr+36v+5s0w= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Jan Beulich , Paul Durrant Subject: [XEN][RFC PATCH v3 09/14] xen/iommu: Introduce iommu_remove_dt_device() Date: Tue, 8 Mar 2022 11:46:59 -0800 Message-ID: <20220308194704.14061-10-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9124e229-8348-42cf-476b-08da013c811d X-MS-TrafficTypeDiagnostic: SN6PR02MB4222:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RZGXsKx1kLKXkbheqRNcSMIzKDdeROoEuLZgNUfmfaFHaX4WiuX+Q1MfQumsS9bA9Iv8mkpPUauhStOCQ34SSNo7J12L87lMMpaj7ci7o7HsxKw+X9x/H0wsxAodDK/rxelxEi4wZorOLoMoGOfK/RVNgWhTU4aXZTU0wlLGqbNUOczz8WxG1gDxk2CMfGXa4Bw9iLlGb8eLhvKuIehRlhLeVc6rhEJY/xPe9YD2JIrE4WoYdQ0uco5zdeDT5dX/odevPvOLGledHdE2ft2GcWWuixX9LK8PSxxmS1UhpCnkJw7f/tslEtWM+jHPE1V3QW141uq2Db8bR2T1/Endz/HPJ6EPbn3di+uhPnoYA7N7bSSSgGYHyPd9QqSddiGQDKlkWbsNEhX1HjgbZLeqdIXcuaWwEZXSMTe84C055iV+1LiSW/F0qsrWDHopcWNVPSdgxq1nBrVP1eJoMxkqo559xTeB3d6hHNlNCBoaGGs6CnvQ8LBY9kqLw6d6Dz0RZqLZIevxTqQgOqVSoFIlFR9RJaqo6uMXX5EQpnbcsFWLB6O2gpFcPfeuAFWEKJWS1ha3O7bounaOijIWr6quyuf6EaaN57ogeQzAc9ypMufjMzEB89f6k1QdFz1xKIs4ssiTK0pdIkKT+dw7LQaJBf1K+lson8TQTx9doO4EYOty3WR2rBk0x8jcAuBORGziUOZwZBWYBfV2/vbMlUc0wg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(508600001)(9786002)(5660300002)(54906003)(316002)(426003)(336012)(7636003)(83380400001)(8936002)(7696005)(6666004)(82310400004)(8676002)(70586007)(70206006)(4326008)(356005)(2616005)(6916009)(1076003)(40460700003)(26005)(47076005)(36756003)(2906002)(186003)(36860700001)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:40.1410 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9124e229-8348-42cf-476b-08da013c811d X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4222 Remove master device from the IOMMU. Signed-off-by: Vikram Garhwal --- xen/drivers/passthrough/device_tree.c | 38 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 776809a8f2..5cd0b20c77 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -125,6 +125,44 @@ int iommu_release_dt_devices(struct domain *d) return 0; } +int iommu_remove_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops = iommu_get_ops(); + struct device *dev = dt_to_dev(np); + int rc; + + if ( !ops ) + return -EOPNOTSUPP; + + spin_lock(&dtdevs_lock); + + if ( iommu_dt_device_is_assigned_lock(np) ) { + rc = -EBUSY; + goto fail; + } + + /* + * The driver which supports generic IOMMU DT bindings must have + * these callback implemented. + */ + if ( !ops->remove_device ) { + rc = -EOPNOTSUPP; + goto fail; + } + + /* + * Remove master device from the IOMMU if latter is present and available. + */ + rc = ops->remove_device(0, dev); + + if ( rc == 0 ) + iommu_fwspec_free(dev); + +fail: + spin_unlock(&dtdevs_lock); + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops = iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index b18e7760a2..64871e5cb8 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -215,6 +215,8 @@ int iommu_release_dt_devices(struct domain *d); */ int iommu_add_dt_device(struct dt_device_node *np); +int iommu_remove_dt_device(struct dt_device_node *np); + int iommu_do_dt_domctl(struct xen_domctl *, struct domain *, XEN_GUEST_HANDLE_PARAM(xen_domctl_t)); From patchwork Tue Mar 8 19:47:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774317 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 E6DB0C433EF for ; Tue, 8 Mar 2022 19:48:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287474.487572 (Exim 4.92) (envelope-from ) id 1nRfoF-00087o-W0; Tue, 08 Mar 2022 19:47:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287474.487572; Tue, 08 Mar 2022 19:47:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoF-00086L-Le; Tue, 08 Mar 2022 19:47:51 +0000 Received: by outflank-mailman (input) for mailman id 287474; Tue, 08 Mar 2022 19:47:50 +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 1nRfoD-0004Df-Ui for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:50 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20621.outbound.protection.outlook.com [2a01:111:f400:7e8a::621]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9f2d93f8-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:47 +0100 (CET) Received: from DS7PR06CA0035.namprd06.prod.outlook.com (2603:10b6:8:54::9) by DM6PR02MB6122.namprd02.prod.outlook.com (2603:10b6:5:1f9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Tue, 8 Mar 2022 19:47:41 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::4) by DS7PR06CA0035.outlook.office365.com (2603:10b6:8:54::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:41 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:41 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:23 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:23 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnn-000Cws-QH; Tue, 08 Mar 2022 11:47:23 -0800 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: 9f2d93f8-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z5TNxbQUIim6w3W4ZjYPL66AY59IwxnlczCY/GUo+Bn/xpow9ncfSFFq61lCNJD/G2wKiWVXw2JuJgNkGx46cajke2+ataR8Ahf6x3DiHhL7f6b94w837KfvyI6FPYCcQopv3+29g0JHwKfUb3s4jIaOfCFKjv1I1R6NkvfzOu7rnfO8fax+vdvfUFWGriCUD4yRyKlMyzFoI5RCFHNRx5rEQhGG7Oy8BDDnPO6LPEQx/o5xQTbBsmM2HJd9Ceopa3f6R/lV7t6cX1Ycub2MSHieISpjAJ6aDgTqsJ2qnmkjAbFb7gdjhu4UlvQaMK/bXmn2CwS02njAFYQTSdX1aQ== 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=6bEthf9q3/3acjkmaRhHs4J03T9SMN4B3DkYAhksGq4=; b=cvfeK9x+rJ79ff/TRqqyZw4ILx4dg9xZjJqjidL8yigiEVHOiRuJoICD1NrYYsF+1tTSCWofQnaq3TkiTdyZbBhfsaA3Hz+g6t4bTUHlOUlwCOjSuKKbDGEeHMMgGpAnF+iCD91nKhawJNj/risV46FmSgfhJn4iVK30rs4z8gvLBx8we0iQl8DTDgguGRPLo65LK5XLJF9r1OaU3ZjTOg8Dpbk+LOhTlRFggtZmqt3mqDoOW/OVACGtnLNAKMI70OHY8TKfeyvfuL0Ube1FPKmUb0S3+VX73aZRcCQAqvT8Abgmk5P+hkY4wO3xP3w6a0qZKXBU2MZ+6MhadB/B1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6bEthf9q3/3acjkmaRhHs4J03T9SMN4B3DkYAhksGq4=; b=tFDJlqmoHgmPswEjQ8goO1uuTd73Wn2he5+v+ZDN2y0hYG3Afeoyz2eKOMBTcUWyXcjI60nJjPL+w9FfvUd4XJBA3ZzyLYr/Mn9ygMDjAwzKbPwl2QIxhIrya/gySLtxZoYSjWp/A7m6Wj7zYHlzPL6vxx+LDS195kZOr2dnpkQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [XEN][RFC PATCH v3 10/14] xen/arm: Implement device tree node removal functionalities Date: Tue, 8 Mar 2022 11:47:00 -0800 Message-ID: <20220308194704.14061-11-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7fa4e145-f812-4fbd-b479-08da013c81ae X-MS-TrafficTypeDiagnostic: DM6PR02MB6122:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mf5LzJTTJZ2O8XSrWgeyASXIF+JIcFSiy7sVHtrQs0qrEC6ymbhLD1OqdZb3ka342fe/SriSvvy+tUpl8JmAA1VVGUOIznuau3HnEJ+8P4CIPFR+/2UsHfZCuz+Z/HLG1+L/Ug1afLU7qXXkH9DPjzqKBR8LzPJ+ylxw/x9Cnk9zLgi5bT+SS4p/ORgMbDPsY6OAgS8xmFR+8ZEKu6Qwc7hohB9rFkhjDrdUZ1wC8s07gbp2+CBKcr4JGL387l6SbiNonte/aDvsCZHjw4DAwpe8j7+HGzMYrsrHE9ud0qxhxPrkucmSADsMTjBQ+3e5FH6UActMe4k3i+BGvxvuOXZeqhunsnbuw/peUNgLa64o+clTqw+dW9jDsDHmkj6WmQyvA6H93SOLeRmrVn8TdXob6glBtczSnNIy8eMN8/oKFdvb4naRIl1AtGNNP5bSE/7vlCJZ7BNe9fZNJszswksWki5qn8yy1dluMVVHzglUcqtutvANI9L4arQiDHlmyMVOiGONOtqJNRxkN6wHeV5ESdRmKVZPHwyeC4DZC95MuQIq2s20PaZn2Oyao0fyi8000BLmMRhzWnGz72ZEYD5M1c0dd3gLQjsXkMfz71MvhyLzQu/n1Z2vVi4hYtNgTBHyQ6U7qKoP9QATQkNOulNRIKUCT748DMRwLasDkydhr/UbMkaeodSu9YVrkPgS81XI4K6bhaTjC9ppl946HCWmtlBfwG47RqJeB/uhBxu7CpCzHAV09oS+lmBD5ni3 X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(4326008)(8676002)(336012)(426003)(26005)(30864003)(47076005)(316002)(7636003)(186003)(6916009)(82310400004)(5660300002)(54906003)(8936002)(70206006)(70586007)(1076003)(7696005)(36756003)(2616005)(356005)(36860700001)(508600001)(40460700003)(83380400001)(2906002)(6666004)(9786002)(102446001)(403724002)(2004002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:41.0784 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fa4e145-f812-4fbd-b479-08da013c81ae X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB6122 Introduce sysctl XEN_SYSCTL_dt_overlay to remove device-tree nodes added using device tree overlay. xl overlay remove file.dtbo: Removes all the nodes in a given dtbo. First, removes IRQ permissions and MMIO accesses. Next, it finds the nodes in dt_host and delete the device node entries from dt_host. The nodes get removed only if it is not used by any of dom0 or domio. Also, added overlay_track struct to keep the track of added node through device tree overlay. overlay_track has dt_host_new which is unflattened form of updated fdt and name of overlay nodes. When a node is removed, we also free the memory used by overlay_track for the particular overlay node. Signed-off-by: Vikram Garhwal --- xen/common/Makefile | 1 + xen/common/dt_overlay.c | 447 +++++++++++++++++++++++++++++++++++ xen/common/sysctl.c | 10 + xen/include/public/sysctl.h | 18 ++ xen/include/xen/dt_overlay.h | 47 ++++ 5 files changed, 523 insertions(+) create mode 100644 xen/common/dt_overlay.c create mode 100644 xen/include/xen/dt_overlay.h diff --git a/xen/common/Makefile b/xen/common/Makefile index dc8d3a13f5..2eb5734f8e 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -54,6 +54,7 @@ obj-y += wait.o obj-bin-y += warning.init.o obj-$(CONFIG_XENOPROF) += xenoprof.o obj-y += xmalloc_tlsf.o +obj-$(CONFIG_OVERLAY_DTB) += dt_overlay.o obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo unlz4 unzstd earlycpio,$(n).init.o) diff --git a/xen/common/dt_overlay.c b/xen/common/dt_overlay.c new file mode 100644 index 0000000000..fcb31de495 --- /dev/null +++ b/xen/common/dt_overlay.c @@ -0,0 +1,447 @@ +/* + * xen/common/dt_overlay.c + * + * Device tree overlay support in Xen. + * + * Copyright (c) 2021 Xilinx Inc. + * Written by Vikram Garhwal + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include +#include +#include +#include +#include + +static LIST_HEAD(overlay_tracker); +static DEFINE_SPINLOCK(overlay_lock); + +static int dt_overlay_remove_node(struct dt_device_node *device_node) +{ + struct dt_device_node *np; + struct dt_device_node *parent_node; + struct dt_device_node *current_node; + + parent_node = device_node->parent; + + current_node = parent_node; + + if ( parent_node == NULL ) + { + dt_dprintk("%s's parent node not found\n", device_node->name); + return -EFAULT; + } + + np = parent_node->child; + + if ( np == NULL ) + { + dt_dprintk("parent node %s's not found\n", parent_node->name); + return -EFAULT; + } + + /* If node to be removed is only child node or first child. */ + if ( !dt_node_cmp(np->full_name, device_node->full_name) ) + { + current_node->allnext = np->allnext; + + /* If node is first child but not the only child. */ + if ( np->sibling != NULL ) + current_node->child = np->sibling; + else + /* If node is only child. */ + current_node->child = NULL; + return 0; + } + + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + current_node = np; + if ( !dt_node_cmp(np->sibling->full_name, device_node->full_name) ) + { + /* Found the node. Now we remove it. */ + current_node->allnext = np->allnext->allnext; + + if ( np->sibling->sibling ) + current_node->sibling = np->sibling->sibling; + else + current_node->sibling = NULL; + + break; + } + } + + return 0; +} + +/* Basic sanity check for the dtbo tool stack provided to Xen. */ +static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) +{ + if ( (fdt_totalsize(overlay_fdt) != overlay_fdt_size) || + fdt_check_header(overlay_fdt) ) + { + printk(XENLOG_ERR "The overlay FDT is not a valid Flat Device Tree\n"); + return -EINVAL; + } + + return 0; +} + +static unsigned int overlay_node_count(void *fdto) +{ + unsigned int num_overlay_nodes = 0; + int fragment; + + fdt_for_each_subnode(fragment, fdto, 0) + { + + int subnode; + int overlay; + + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * Overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + + fdt_for_each_subnode(subnode, fdto, overlay) + { + num_overlay_nodes++; + } + } + + return num_overlay_nodes; +} + +/* + * overlay_get_nodes_info will get the all node's full name with path. This is + * useful when checking node for duplication i.e. dtbo tries to add nodes which + * already exists in device tree. + */ +static int overlay_get_nodes_info(const void *fdto, char ***nodes_full_path, + unsigned int num_overlay_nodes) +{ + int fragment; + unsigned int node_num = 0; + + *nodes_full_path = xmalloc_bytes(num_overlay_nodes * sizeof(char *)); + + if ( *nodes_full_path == NULL ) + return -ENOMEM; + memset(*nodes_full_path, 0x0, num_overlay_nodes * sizeof(char *)); + + fdt_for_each_subnode(fragment, fdto, 0) + { + int target; + int overlay; + int subnode; + const char *target_path; + + target = fdt_overlay_target_offset(device_tree_flattened, fdto, + fragment, &target_path); + if ( target < 0 ) + return target; + + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * Overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + fdt_for_each_subnode(subnode, fdto, overlay) + { + const char *node_name = NULL; + unsigned int node_name_len = 0; + unsigned int target_path_len = strlen(target_path); + unsigned int node_full_name_len = 0; + + node_name = fdt_get_name(fdto, subnode, &node_name_len); + + if ( node_name == NULL ) + return -EINVAL; + + /* + * Magic number 2 is for adding '/'. This is done to keep the + * node_full_name in the correct full node name format. + */ + node_full_name_len = target_path_len + node_name_len + 2; + + (*nodes_full_path)[node_num] = xmalloc_bytes(node_full_name_len); + + if ( (*nodes_full_path)[node_num] == NULL ) + return -ENOMEM; + + memcpy((*nodes_full_path)[node_num], target_path, target_path_len); + + (*nodes_full_path)[node_num][target_path_len] = '/'; + + memcpy((*nodes_full_path)[node_num] + target_path_len + 1, node_name, + node_name_len); + + (*nodes_full_path)[node_num][node_full_name_len - 1] = '\0'; + + node_num++; + } + } + + return 0; +} + +/* Remove nodes from dt_host. */ +static int remove_nodes(char **full_dt_node_path, int **nodes_irq, + int *node_num_irq, unsigned int num_nodes) +{ + struct domain *d = hardware_domain; + int rc = 0; + struct dt_device_node *overlay_node; + unsigned int naddr; + unsigned int i, j, nirq; + u64 addr, size; + domid_t domid = 0; + + for ( j = 0; j < num_nodes; j++ ) + { + dt_dprintk("Finding node %s in the dt_host\n", full_dt_node_path[j]); + + overlay_node = dt_find_node_by_path(full_dt_node_path[j]); + + if ( overlay_node == NULL ) + { + printk(XENLOG_ERR "Device %s is not present in the tree. Removing nodes failed\n", + full_dt_node_path[j]); + return -EINVAL; + } + + domid = dt_device_used_by(overlay_node); + + dt_dprintk("Checking if node %s is used by any domain\n", + full_dt_node_path[j]); + + /* Remove the node iff it's assigned to domain 0 or domain io. */ + if ( domid != 0 && domid != DOMID_IO ) + { + printk(XENLOG_ERR "Device %s as it is being used by domain %d. Removing nodes failed\n", + full_dt_node_path[j], domid); + return -EINVAL; + } + + dt_dprintk("Removing node: %s\n", full_dt_node_path[j]); + + nirq = node_num_irq[j]; + + /* Remove IRQ permission */ + for ( i = 0; i < nirq; i++ ) + { + rc = nodes_irq[j][i]; + /* + * TODO: We don't handle shared IRQs for now. So, it is assumed that + * the IRQs was not shared with another domain. + */ + rc = irq_deny_access(d, rc); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %u for %s\n", + i, dt_node_full_name(overlay_node)); + return rc; + } + } + + rc = iommu_remove_dt_device(overlay_node); + if ( rc != 0 && rc != -ENXIO ) + return rc; + + naddr = dt_number_of_address(overlay_node); + + /* Remove mmio access. */ + for ( i = 0; i < naddr; i++ ) + { + rc = dt_device_get_address(overlay_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(overlay_node)); + return rc; + } + + rc = iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + size - 1))); + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); + return rc; + } + } + + rc = dt_overlay_remove_node(overlay_node); + if ( rc ) + return rc; + } + + return rc; +} + +/* + * First finds the device node to remove. Check if the device is being used by + * any dom and finally remove it from dt_host. IOMMU is already being taken care + * while destroying the domain. + */ +static long handle_remove_overlay_nodes(char **full_dt_nodes_path, + unsigned int num_nodes) +{ + int rc = 0; + struct overlay_track *entry, *temp, *track; + bool found_entry = false; + unsigned int i; + + spin_lock(&overlay_lock); + + /* + * First check if dtbo is correct i.e. it should one of the dtbo which was + * used when dynamically adding the node. + * Limitation: Cases with same node names but different property are not + * supported currently. We are relying on user to provide the same dtbo + * as it was used when adding the nodes. + */ + list_for_each_entry_safe( entry, temp, &overlay_tracker, entry ) + { + /* Checking the num of nodes first. If not same skip to next entry. */ + if ( num_nodes == entry->num_nodes ) + { + for ( i = 0; i < num_nodes; i++ ) + { + if ( strcmp(full_dt_nodes_path[i], entry->nodes_fullname[i]) ) + { + /* Node name didn't match. Skip to next entry. */ + break; + } + } + + /* Found one tracker with all node name matching. */ + track = entry; + found_entry = true; + break; + } + } + + if ( found_entry == false ) + { + rc = -EINVAL; + + printk(XENLOG_ERR "Cannot find any matching tracker with input dtbo." + " Removing nodes is supported for only prior added dtbo. Please" + " provide a valid dtbo which was used to add the nodes.\n"); + goto out; + + } + + rc = remove_nodes(full_dt_nodes_path, entry->nodes_irq, entry->node_num_irq, + num_nodes); + + if ( rc ) + { + printk(XENLOG_ERR "Removing node failed\n"); + goto out; + } + + list_del(&entry->entry); + + for ( i = 0; i < entry->num_nodes && entry->nodes_fullname[i] != NULL; i++ ) + { + xfree(entry->nodes_fullname[i]); + } + xfree(entry->nodes_fullname); + for ( i = 0; i < entry->num_nodes && entry->nodes_irq[i] != NULL; i++ ) + { + xfree(entry->nodes_irq[i]); + } + xfree(entry->nodes_irq); + xfree(entry->node_num_irq); + xfree(entry->dt_host_new); + xfree(entry->fdt); + xfree(entry); + +out: + spin_unlock(&overlay_lock); + return rc; +} + +long dt_sysctl(struct xen_sysctl *op) +{ + long ret = 0; + void *overlay_fdt; + char **nodes_full_path = NULL; + unsigned int num_overlay_nodes = 0; + + if ( op->u.dt_overlay.overlay_fdt_size <= 0 ) + return -EINVAL; + + overlay_fdt = xmalloc_bytes(op->u.dt_overlay.overlay_fdt_size); + + if ( overlay_fdt == NULL ) + return -ENOMEM; + + ret = copy_from_guest(overlay_fdt, op->u.dt_overlay.overlay_fdt, + op->u.dt_overlay.overlay_fdt_size); + if ( ret ) + { + gprintk(XENLOG_ERR, "copy from guest failed\n"); + xfree(overlay_fdt); + + return -EFAULT; + } + + switch ( op->u.dt_overlay.overlay_op ) + { + case XEN_SYSCTL_DT_OVERLAY_REMOVE: + ret = check_overlay_fdt(overlay_fdt, + op->u.dt_overlay.overlay_fdt_size); + if ( ret ) + { + ret = -EFAULT; + break; + } + + num_overlay_nodes = overlay_node_count(overlay_fdt); + if ( num_overlay_nodes == 0 ) + { + ret = -ENOMEM; + break; + } + + ret = overlay_get_nodes_info(overlay_fdt, &nodes_full_path, + num_overlay_nodes); + if ( ret ) + break; + + ret = handle_remove_overlay_nodes(nodes_full_path, + num_overlay_nodes); + break; + + default: + break; + } + + if ( nodes_full_path != NULL ) + { + int i; + for ( i = 0; i < num_overlay_nodes && nodes_full_path[i] != NULL; i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + return ret; +} diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index fc4a0b31d6..d685c07159 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -29,6 +29,10 @@ #include #include +#ifdef CONFIG_OVERLAY_DTB +#include +#endif + long cf_check do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { long ret = 0; @@ -482,6 +486,12 @@ long cf_check do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) copyback = 1; break; +#ifdef CONFIG_OVERLAY_DTB + case XEN_SYSCTL_overlay: + ret = dt_sysctl(op); + break; +#endif + default: ret = arch_do_sysctl(op, u_sysctl); copyback = 0; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 55252e97f2..e256aeb7c6 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1069,6 +1069,22 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#define XEN_SYSCTL_DT_OVERLAY_REMOVE 2 + +/* + * XEN_SYSCTL_dt_overlay + * Performs addition/removal of device tree nodes under parent node using dtbo. + * This does in three steps: + * - Adds/Removes the nodes from dt_host. + * - Adds/Removes IRQ permission for the nodes. + * - Adds/Removes MMIO accesses. + */ +struct xen_sysctl_dt_overlay { + XEN_GUEST_HANDLE_64(void) overlay_fdt; + uint32_t overlay_fdt_size; /* Overlay dtb size. */ + uint8_t overlay_op; /* Add or remove. */ +}; + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1099,6 +1115,7 @@ struct xen_sysctl { #define XEN_SYSCTL_livepatch_op 27 /* #define XEN_SYSCTL_set_parameter 28 */ #define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_dt_overlay 30 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -1129,6 +1146,7 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + struct xen_sysctl_dt_overlay dt_overlay; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/dt_overlay.h b/xen/include/xen/dt_overlay.h new file mode 100644 index 0000000000..525818b77c --- /dev/null +++ b/xen/include/xen/dt_overlay.h @@ -0,0 +1,47 @@ +/* + * xen/common/dt_overlay.c + * + * Device tree overlay suppoert in Xen. + * + * Copyright (c) 2021 Xilinx Inc. + * Written by Vikram Garhwal + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#ifndef __XEN_DT_SYSCTL_H__ +#define __XEN_DT_SYSCTL_H__ + +#include +#include +#include +#include + +/* + * overlay_node_track describes information about added nodes through dtbo. + * @entry: List pointer. + * @dt_host_new: Pointer to the updated dt_host_new unflattened 'updated fdt'. + * @fdt: Stores the fdt. + * @nodes_fullname: Stores the full name of nodes. + * @nodes_irq: Stores the IRQ added from overlay dtb. + * @node_num_irq: Stores num of IRQ for each node in overlay dtb. + * @num_nodes: Stores total number of nodes in overlay dtb. + */ +struct overlay_track { + struct list_head entry; + struct dt_device_node *dt_host_new; + void *fdt; + char **nodes_fullname; + int **nodes_irq; + int *node_num_irq; + unsigned int num_nodes; +}; + +long dt_sysctl(struct xen_sysctl *op); +#endif From patchwork Tue Mar 8 19:47:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774316 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 C5F11C433F5 for ; Tue, 8 Mar 2022 19:48:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287473.487568 (Exim 4.92) (envelope-from ) id 1nRfoF-00082v-Cv; Tue, 08 Mar 2022 19:47:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287473.487568; Tue, 08 Mar 2022 19:47:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoF-00081d-6O; Tue, 08 Mar 2022 19:47:51 +0000 Received: by outflank-mailman (input) for mailman id 287473; Tue, 08 Mar 2022 19:47:50 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoD-0004Om-P4 for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:50 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062b.outbound.protection.outlook.com [2a01:111:f400:7e8a::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a13ebabf-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:48 +0100 (CET) Received: from DS7PR06CA0033.namprd06.prod.outlook.com (2603:10b6:8:54::15) by BY5PR02MB6452.namprd02.prod.outlook.com (2603:10b6:a03:1b6::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Tue, 8 Mar 2022 19:47:42 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::ff) by DS7PR06CA0033.outlook.office365.com (2603:10b6:8:54::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:42 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:42 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:24 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:24 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfno-000Cws-CG; Tue, 08 Mar 2022 11:47:24 -0800 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: a13ebabf-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=csH/2uVh0owjvzpQq0bEkynkriDNS5ewgniFxH+RClBE5IkVDZ0EXNM3QWQoL6LRBJqiCU5usL+qj4vAHwvPkOJez6zyHXT78N2Dp3G0QbDZOCvtWI1fZHm/SZHkvkMBV7nBC7qqN6nZQcf7ErZHlecAVefahez8vQo7p83l0N82oaUL6zZSamYRiTDtrAC1wqDF34ayXPahd0dX6h/4tRrStWgJ8DveBKEZ/AgLklx8eBN7AWjpdcrQcOSfUEo+BO+gfd188H6SyAmmKDFaPvdp6fh4xQnSwd8sNRflTLdBOtaFaaVdGKREIVZiHpnIBkCO+JXAZKW+W9yqWVRplA== 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=g1gi60PB1fCf6Gz/jhEFM/GsLELukVETFiTkGYpX/Lk=; b=YdhItRRo6THX2lyxNo1/1rac3NsU2bYJ5OxcUX9opjXHsFiKFL1CKieYhBn4KA1ViKG19+P+r2n4MQgbWRdXwrpKFtgQZfIOHq2EHE5hmHAhKJTX3PfeSO73MeseoPeBTjjxs06Y34GR3+qRMjG62lgtjV2K/zWZmBxMpGYafMJWD7HBRS/t/hxb9x8/baIVvchN75c93EsSuaVWW9Dy/fmcoIKTRFy8VlvOQnEv4DlcbKXtfF+HtBz3cx1bx4Z7sDejrA+b6UvOGlSk27fIcr7JpqO2OAtCDmxuNdcO/KgDIOe50HMxy2J1cjCbG1BsFkHp9b01rjLq+OnQuzrcCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g1gi60PB1fCf6Gz/jhEFM/GsLELukVETFiTkGYpX/Lk=; b=iYtVWejklPcrJTweZwKJjMK6fxo0i4pX5Ci0NQxZREIkTdnaqQkuAcUuROtm72cewmI3k7/f6mK1XnUCS5aNQfJnIMgw8TwZDAHUGHMedNss40BHw+Z1Z40U8OUck09BqX/o+rs0HIMMJY91Kg0rHVZN5SuLzhWM+gjPvvDUvfY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [XEN][RFC PATCH v3 11/14] xen/arm: Implement device tree node addition functionalities Date: Tue, 8 Mar 2022 11:47:01 -0800 Message-ID: <20220308194704.14061-12-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6628726e-b0a2-4795-1fa2-08da013c825f X-MS-TrafficTypeDiagnostic: BY5PR02MB6452:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SMwBTaiIIrBoiF72brPAdLFYZ8Evs5O4rFRiQ1Lo5XLz5zWG7LsRQqLNt8NJkTft00S/ZzaJ+HbrKD9VoFsJeULo8nImY8XRSXA7+IkTcQ32Cjh0dZnIAjWavEfBvOU/2hai6y7gHlf7zR9LIHHtsC73yB7x12coys7AyUdMYGLi6iFU4Hznj6LNtNXgebsy896EC6S8D6uWaa/uyrRtW/QQYqf5bfyLa6/Rghl4XArRNFWquYrPj1O9n8hqk9SfyAn7g8rIP/RtxJJv7dOEwFFZKvKUgV7XvUVR6YzTX9lIU49VIFnqhWG+d0hAXPEjW54EikhwPoHLys2b8PuiZ1c4BRRa1mhWPqtxsyTR3LU/TMP6CLwYTI3NbV9dYFlW1q2SV0HhZ47xTyltKtlmrDnys89785CoEOo3cgaj1jXJsbWK6sYUqSjakO2b3rCc5nyTAjaQKRrx9d3Q+EjsK2E0jO3DxZWqy2k5wB/jcY49bE7cXJgvMfAJKL1WvXwCs1d6gWLLwzt0jnB2bpTn9tQczTT+Z5jAsGiTSQg8N6b9bABN5lymFl6+SrDD4ihFKTNzOid38kWUZKcKG9bmMgx/PJbCqxcUrSS5fm1Ki/cwqPJWpvjhVgb3E7VMYCW7SoigfANjledj1jMYV70MvyqSGbv3CFb9Qw0VldkzKjBrvH9KAuXbfMUySzDvxU89GypSqrI1mA2I8O+axI9TRg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(336012)(6666004)(356005)(7636003)(26005)(8676002)(2616005)(1076003)(7696005)(5660300002)(508600001)(2906002)(426003)(36860700001)(8936002)(9786002)(70586007)(70206006)(82310400004)(186003)(316002)(47076005)(54906003)(36756003)(4326008)(6916009)(83380400001)(102446001)(403724002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:42.2346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6628726e-b0a2-4795-1fa2-08da013c825f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR02MB6452 Update sysctl XEN_SYSCTL_dt_overlay to enable support for dtbo nodes addition using device tree overlay. xl overlay add file.dtbo: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, it checks if any of the overlay nodes already exists in the dt_host. If overlay nodes doesn't exist then find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. The node is attached as the last node under target parent. Finally, add IRQs, add device to IOMMUs, set permissions and map MMIO for the overlay node. When a node is added using overlay, a new entry is allocated in the overlay_track to keep the track of memory allocation due to addition of overlay node. This is helpful for freeing the memory allocated when a device tree node is removed. Signed-off-by: Vikram Garhwal --- xen/common/dt_overlay.c | 324 ++++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 1 + 2 files changed, 325 insertions(+) diff --git a/xen/common/dt_overlay.c b/xen/common/dt_overlay.c index fcb31de495..01aed62d74 100644 --- a/xen/common/dt_overlay.c +++ b/xen/common/dt_overlay.c @@ -82,6 +82,64 @@ static int dt_overlay_remove_node(struct dt_device_node *device_node) return 0; } +static int dt_overlay_add_node(struct dt_device_node *device_node, + const char *parent_node_path) +{ + struct dt_device_node *parent_node; + struct dt_device_node *np; + struct dt_device_node *next_node; + struct dt_device_node *new_node; + + parent_node = dt_find_node_by_path(parent_node_path); + + new_node = device_node; + + if ( new_node == NULL ) + return -EINVAL; + + if ( parent_node == NULL ) + { + dt_dprintk("Node not found. Partial dtb will not be added"); + return -EINVAL; + } + + /* + * If node is found. We can attach the device_node as a child of the + * parent node. + */ + + /* If parent has no child. */ + if ( parent_node->child == NULL ) + { + next_node = parent_node->allnext; + new_node->parent = parent_node; + parent_node->allnext = new_node; + parent_node->child = new_node; + /* Now plug next_node at the end of device_node. */ + new_node->allnext = next_node; + } else { + /* If parent has at least one child node. */ + + /* + * Iterate to the last child node of parent. + */ + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + } + + next_node = np->allnext; + new_node->parent = parent_node; + np->sibling = new_node; + np->allnext = new_node; + /* Now plug next_node at the end of device_node. */ + new_node->sibling = next_node; + new_node->allnext = next_node; + np->sibling->sibling = NULL; + } + + return 0; +} + /* Basic sanity check for the dtbo tool stack provided to Xen. */ static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) { @@ -377,6 +435,267 @@ out: return rc; } +/* + * Adds device tree nodes under target node. + * We use dt_host_new to unflatten the updated device_tree_flattened. This is + * done to avoid the removal of device_tree generation, iomem regions mapping to + * hardware domain done by handle_node(). + */ +static long handle_add_overlay_nodes(void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc = 0; + struct dt_device_node *overlay_node; + char **nodes_full_path = NULL; + int **nodes_irq = NULL; + int *node_num_irq = NULL; + void *fdt = NULL; + struct dt_device_node *dt_host_new = NULL; + struct domain *d = hardware_domain; + struct overlay_track *tr = NULL; + unsigned int naddr; + unsigned int num_irq; + unsigned int i, j, k; + unsigned int num_overlay_nodes; + u64 addr, size; + + fdt = xmalloc_bytes(fdt_totalsize(device_tree_flattened)); + if ( fdt == NULL ) + return -ENOMEM; + + num_overlay_nodes = overlay_node_count(overlay_fdt); + if ( num_overlay_nodes == 0 ) + { + xfree(fdt); + return -ENOMEM; + } + + spin_lock(&overlay_lock); + + memcpy(fdt, device_tree_flattened, fdt_totalsize(device_tree_flattened)); + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + { + xfree(fdt); + return rc; + } + + /* + * overlay_get_nodes_info is called to get the node information from dtbo. + * This is done before fdt_overlay_apply() because the overlay apply will + * erase the magic of overlay_fdt. + */ + rc = overlay_get_nodes_info(overlay_fdt, &nodes_full_path, + num_overlay_nodes); + if ( rc ) + { + printk(XENLOG_ERR "Getting nodes information failed with error %d\n", + rc); + goto err; + } + + nodes_irq = xmalloc_bytes(num_overlay_nodes * sizeof(int *)); + + if ( nodes_irq == NULL ) + { + rc = -ENOMEM; + goto err; + } + memset(nodes_irq, 0x0, num_overlay_nodes * sizeof(int *)); + + node_num_irq = xmalloc_bytes(num_overlay_nodes * sizeof(int)); + if ( node_num_irq == NULL ) + { + rc = -ENOMEM; + goto err; + } + memset(node_num_irq, 0x0, num_overlay_nodes * sizeof(int)); + + rc = fdt_overlay_apply(fdt, overlay_fdt); + if ( rc ) + { + printk(XENLOG_ERR "Adding overlay node failed with error %d\n", rc); + goto err; + } + + for ( j = 0; j < num_overlay_nodes; j++ ) + { + /* Check if any of the node already exists in dt_host. */ + overlay_node = dt_find_node_by_path(nodes_full_path[j]); + if ( overlay_node != NULL ) + { + printk(XENLOG_ERR "node %s exists in device tree\n", + nodes_full_path[j]); + rc = -EINVAL; + goto err; + } + } + + /* Unflatten the fdt into a new dt_host. */ + unflatten_device_tree(fdt, &dt_host_new); + + for ( j = 0; j < num_overlay_nodes; j++ ) + { + dt_dprintk("Adding node: %s\n", nodes_full_path[j]); + + /* Find the newly added node in dt_host_new by it's full path. */ + overlay_node = _dt_find_node_by_path(dt_host_new, nodes_full_path[j]); + if ( overlay_node == NULL ) + { + dt_dprintk("%s node not found\n", nodes_full_path[j]); + rc = -EFAULT; + goto remove_node; + } + + /* Add the node to dt_host. */ + rc = dt_overlay_add_node(overlay_node, overlay_node->parent->full_name); + if ( rc ) + { + /* Node not added in dt_host. */ + goto remove_node; + } + + overlay_node = dt_find_node_by_path(overlay_node->full_name); + if ( overlay_node == NULL ) + { + /* Sanity check. But code will never come here. */ + printk(XENLOG_ERR "Cannot find %s node under updated dt_host\n", + overlay_node->name); + goto remove_node; + } + + /* First let's handle the interrupts. */ + rc = handle_device_interrupts(d, overlay_node, false); + if ( rc ) + { + printk(XENLOG_ERR "Interrupt failed\n"); + goto remove_node; + } + + /* Store IRQs for each node. */ + num_irq = dt_number_of_irq(overlay_node); + node_num_irq[j] = num_irq; + nodes_irq[j] = xmalloc_bytes(num_irq * sizeof(int)); + if ( nodes_irq[j] == NULL ) + { + rc = -ENOMEM; + goto remove_node; + } + + for ( k = 0; k < num_irq; k++ ) + { + nodes_irq[j][k] = platform_get_irq(overlay_node, k); + } + + /* Add device to IOMMUs */ + rc = iommu_add_dt_device(overlay_node); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(overlay_node)); + goto remove_node; + } + + /* Set permissions. */ + naddr = dt_number_of_address(overlay_node); + + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(overlay_node), false, naddr); + + /* Give permission for map MMIOs */ + for ( i = 0; i < naddr; i++ ) + { + struct map_range_data mr_data = { .d = d, + .p2mt = p2m_mmio_direct_c, + .skip_mapping = true }; + rc = dt_device_get_address(overlay_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(overlay_node)); + goto remove_node; + } + + rc = map_range_to_domain(overlay_node, addr, size, &mr_data); + if ( rc ) + goto remove_node; + } + } + + /* This will happen if everything above goes right. */ + tr = xzalloc(struct overlay_track); + if ( tr == NULL ) + { + rc = -ENOMEM; + goto remove_node; + } + + tr->dt_host_new = dt_host_new; + tr->fdt = fdt; + tr->nodes_fullname = nodes_full_path; + tr->num_nodes = num_overlay_nodes; + tr->nodes_irq = nodes_irq; + tr->node_num_irq = node_num_irq; + + if ( tr->nodes_fullname == NULL ) + { + rc = -ENOMEM; + goto remove_node; + } + + INIT_LIST_HEAD(&tr->entry); + list_add_tail(&tr->entry, &overlay_tracker); + + spin_unlock(&overlay_lock); + return rc; + +/* + * Failure case. We need to remove the nodes, free tracker(if tr exists) and + * dt_host_new. + */ +remove_node: + rc = remove_nodes(nodes_full_path, nodes_irq, node_num_irq, j); + + if ( rc ) + { + printk(XENLOG_ERR "Removing node failed\n"); + spin_unlock(&overlay_lock); + return rc; + } + +err: + spin_unlock(&overlay_lock); + + xfree(dt_host_new); + xfree(fdt); + + if ( nodes_full_path != NULL ) + { + for ( i = 0; i < num_overlay_nodes && nodes_full_path[i] != NULL; i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + if ( nodes_irq != NULL ) + { + for ( i = 0; i < num_overlay_nodes && nodes_irq[i] != NULL; i++ ) + { + xfree(nodes_irq[i]); + } + xfree(nodes_irq); + } + + if ( node_num_irq ) + xfree(node_num_irq); + + xfree(tr); + + return rc; +} + long dt_sysctl(struct xen_sysctl *op) { long ret = 0; @@ -404,6 +723,11 @@ long dt_sysctl(struct xen_sysctl *op) switch ( op->u.dt_overlay.overlay_op ) { + case XEN_SYSCTL_DT_OVERLAY_ADD: + ret = handle_add_overlay_nodes(overlay_fdt, + op->u.dt_overlay.overlay_fdt_size); + break; + case XEN_SYSCTL_DT_OVERLAY_REMOVE: ret = check_overlay_fdt(overlay_fdt, op->u.dt_overlay.overlay_fdt_size); diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index e256aeb7c6..bb3ef44989 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1069,6 +1069,7 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#define XEN_SYSCTL_DT_OVERLAY_ADD 1 #define XEN_SYSCTL_DT_OVERLAY_REMOVE 2 /* From patchwork Tue Mar 8 19:47:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774311 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 CE14CC433EF for ; Tue, 8 Mar 2022 19:47:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287461.487514 (Exim 4.92) (envelope-from ) id 1nRfny-0005iC-Ru; Tue, 08 Mar 2022 19:47:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287461.487514; Tue, 08 Mar 2022 19:47: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 1nRfny-0005hz-Mv; Tue, 08 Mar 2022 19:47:34 +0000 Received: by outflank-mailman (input) for mailman id 287461; Tue, 08 Mar 2022 19:47: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 1nRfnx-0004Om-16 for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:33 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2060c.outbound.protection.outlook.com [2a01:111:f400:7eab::60c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 974e7593-9f18-11ec-8eba-a37418f5ba1a; Tue, 08 Mar 2022 20:47:32 +0100 (CET) Received: from SN6PR16CA0066.namprd16.prod.outlook.com (2603:10b6:805:ca::43) by PH0PR02MB8732.namprd02.prod.outlook.com (2603:10b6:510:db::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Tue, 8 Mar 2022 19:47:28 +0000 Received: from SN1NAM02FT0027.eop-nam02.prod.protection.outlook.com (2603:10b6:805:ca:cafe::33) by SN6PR16CA0066.outlook.office365.com (2603:10b6:805:ca::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:28 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0027.mail.protection.outlook.com (10.97.4.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:28 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:25 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:25 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnp-000Cws-8n; Tue, 08 Mar 2022 11:47:25 -0800 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: 974e7593-9f18-11ec-8eba-a37418f5ba1a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SW6n1ovMxpxPmckryBrLGZY6+5lXFjpDr1XbY58aLAgFaciVcePgo09O88u/CDqc1y5nKenQstGng+tt6F1WbwrU5/IsEBJeYOVwjOVUsrl3dWecR49n3lacyYXzq5LI91BP0V6u9IVBgv0XckWMrqiMCGXkjVvzLsZiES9HsNjxlc9aFLYAXCwVfW8VMkrJoaewcnxL367SGeg2FW9Fls0dON7xHiN9k+CFbv3JVQP/uN6UOZagcxoz7PiiEIFUbFpPRe8REago3Fc6O/SzFcuZv1vhht9P7UNtqrHXHc7RNNfAysQ201JlvKuIqKUlaRLp4tvEExgv7BNeonLZtA== 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=gfEqKpmJRR5O6DgmlR17CSpSZiZGd6fXDbnnsIWjXck=; b=huzsMQmbP/wzhvrRzEyVd396KlOwbWmFHFqWXm3FdTUE4lfgMpszmvy5ecv6/1c6a70ANnpNRopYinUOpm/BcYpoQ4HZ1mvsVXx3ftvRTVm7AE76fywjzs99/Dby7cy5zCpvNl0LZjEtjR4tQ4/RfqB9ObVqoLBtVOjjF6qSf2xYlmhV3d7CRFofnglMBw1IQxoFOTCU7tB53o98oMu1MnAGPH/2p6YEZMmU9feWku6am5pj8fgdpmPj1Kg39PQONResJezBOT0Qmarct0CfUxwCl2+FA3EIRmtOCDi/sMr+L8XmnZPMhxSuk20a2P1o+4t02u+mGq+T0tPPdpyoKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gfEqKpmJRR5O6DgmlR17CSpSZiZGd6fXDbnnsIWjXck=; b=kkESmhVov3/WUVgzrBubA+XlXU/w+X7ojt2ijb8aU4OaMP5rxjwhoeVsmjimFHDtnS+ILbfjM46IEahd7NOJEhju2Qm6ptXk+lZMHTkAMOrvI7ku43hsMR/a+5l2H1ELVJWH7LhabIsat39YV2TvldX2KJIVfNd7IWNK3LNJs2Y= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][RFC PATCH v3 12/14] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Tue, 8 Mar 2022 11:47:02 -0800 Message-ID: <20220308194704.14061-13-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f6aaedb-1a4b-4154-736a-08da013c79fc X-MS-TrafficTypeDiagnostic: PH0PR02MB8732:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QhO8XzGx9rykcAndvVDyOtxgbWPAt8XNRO/730uxTPPV2tBhthZ2q1blWJ9s2PXsfMobQ97am8n9XmEq2CSH95X1IOIExZ1g+DoTys7RxxbZYI8XSNBFKXNomdtK3vFAUp7+1ZaCbdTdvfnttwbDaAPF3lW+ykFx/Uwd4+pp5wWNgYwfLwmu+AlHD5IAMOca493dsqFEZ6+E28Nh1e0gYeqV/8SpchK54hi+nk+rySHGYs9G5YDUdPwHcVUqQEg7DfTnab4TzVjkbV555atRQtfC2DoyOb/AicjuaT+BJ+n1Dvqxgwwj7WKlKpZBgC5qiv8/QYDVCeuKFOMT1bE1vdlN8ydm8KmbQEpHGF2r2EvCocrIrDidWkbaXPHSVanO6fckccVkzB1zeJdtDTyNtBdS5wN3VrDLu99tKvdqCEhMBeG/SIOmSecP8egjTMwG5VNjZGIM02uk2++EdQQL36z195N2Im5IJvTrEMZ+h46pRpVxhvoaQd8zwPOPofi4Ymj5nPv9BZwGI8rgG/njbbKCr6jVJgKvmqHkTF9lBKuosE6SewPcMFKyIm7a0YgndCBD3vEerdhbFgO5SljBrh508zh75btW/hqGdsSMkkoQCuZAVHfDC1vp2fObax5xrB9VkJW2Jad7i47Ky+6Zvd9SUlb8CnFRXe7QjRQeG5jwucjTmr9DiRqo2bnHSLYiRVLg9zBgzvyC8SJJgaT+TSdOHBXWeWnGbQ4qjqmYHIHnIBXuNY8Nd4agIKTNYt36t6KxvhUpRhp0OioZYzB9weYICRJadAs+5gJ3vbcZrfm/4opj96n6So+pMOACko6s X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(508600001)(6666004)(82310400004)(7696005)(9786002)(1076003)(47076005)(186003)(26005)(36860700001)(426003)(356005)(7636003)(336012)(2616005)(5660300002)(8936002)(4326008)(8676002)(70586007)(70206006)(36756003)(2906002)(54906003)(6916009)(40460700003)(316002)(102446001)(2004002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:28.1662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f6aaedb-1a4b-4154-736a-08da013c79fc X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0027.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB8732 xc_dt_overlay() sends the device tree binary overlay, size of .dtbo and overlay operation type i.e. add or remove to xen. Signed-off-by: Vikram Garhwal --- tools/include/xenctrl.h | 3 +++ tools/libs/ctrl/Makefile | 1 + tools/libs/ctrl/xc_overlay.c | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 tools/libs/ctrl/xc_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 95bd5eca67..b7552d0d9c 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2629,6 +2629,9 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, int overlay_fdt_size, + uint8_t overlay_op); + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile index ef7362327f..848a8737c7 100644 --- a/tools/libs/ctrl/Makefile +++ b/tools/libs/ctrl/Makefile @@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk SRCS-y += xc_altp2m.c SRCS-y += xc_cpupool.c +SRCS-y += xc_overlay.c SRCS-y += xc_domain.c SRCS-y += xc_evtchn.c SRCS-y += xc_gnttab.c diff --git a/tools/libs/ctrl/xc_overlay.c b/tools/libs/ctrl/xc_overlay.c new file mode 100644 index 0000000000..8fe780d75a --- /dev/null +++ b/tools/libs/ctrl/xc_overlay.c @@ -0,0 +1,51 @@ +/* + * + * Overlay control functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_bitops.h" +#include "xc_private.h" +#include +#include + +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, int overlay_fdt_size, + uint8_t overlay_op) +{ + int err; + DECLARE_SYSCTL; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + sysctl.cmd = XEN_SYSCTL_dt_overlay; + sysctl.u.dt_overlay.overlay_op = overlay_op; + sysctl.u.dt_overlay.overlay_fdt_size = overlay_fdt_size; + + set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err = do_sysctl(xch, &sysctl)) != 0 ) + PERROR("%s failed\n", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} From patchwork Tue Mar 8 19:47:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774318 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 5945FC433FE for ; Tue, 8 Mar 2022 19:48:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287475.487580 (Exim 4.92) (envelope-from ) id 1nRfoH-0008IP-Cl; Tue, 08 Mar 2022 19:47:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287475.487580; Tue, 08 Mar 2022 19:47:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoG-0008Fd-JZ; Tue, 08 Mar 2022 19:47:52 +0000 Received: by outflank-mailman (input) for mailman id 287475; Tue, 08 Mar 2022 19:47:51 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoE-0004Df-UX for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:51 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2062a.outbound.protection.outlook.com [2a01:111:f400:7eae::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a0fb9c64-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:48 +0100 (CET) Received: from DS7PR06CA0052.namprd06.prod.outlook.com (2603:10b6:8:54::30) by MWHPR0201MB3626.namprd02.prod.outlook.com (2603:10b6:301:77::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.17; Tue, 8 Mar 2022 19:47:45 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::f2) by DS7PR06CA0052.outlook.office365.com (2603:10b6:8:54::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:45 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:45 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:26 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:26 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnp-000Cws-Ux; Tue, 08 Mar 2022 11:47:25 -0800 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: a0fb9c64-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PJ/9LP3IjTq1HpjojWR4DRKOH/RiiupFn8vgqXYhr69OIC+KKWf10dcdFVs0ClEVzuQcsu/kutMOurD0mYh95anFF9kVn4Ypo/e+BQ9B9cL+UXox7z/pJ8B83UbV47mjbyEOEhOJ+mqZOBHDThpmdReFejheTBvNBRweUyZvuKWhMCWgFUQmYiILAy5cwM/jDJDvjeLeQWKp9mX7SNAxk/YHVNCiFfVnWLjnK/IJ07xxjCe183vEFSFGq6zTZOMzzrLJRICJjCi+DMTAFveGe2jjx5Z87zpkT2b0F3FkbgtVUmlYUgmRbbjMtacT+iy1Tkb1eqpTEqEmlNPws0UGPA== 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=n0mw2y4BYfrLOmQKhWhdHmTRvK5Ny8UEy4PO2h9XNts=; b=E7YLZo25We6jEghN5JYnGXlhdi+DVL9Qz3y2ttEPrDINduLLQ54wenb9CEQfB8TtTNpuE31rMW3HuaVVec+lGSNIHOa0GUxWDjepeeeDaBBkwJh9TYnolnAkAyP5x4fsHgVCxLMbw2q77k4SnVNxTHtwk+vtR9SiiTN1Uyd1+jTXuPJGLem5U9Jv1UFyCu+SNVRdg29O4wOAr/AfO71HXxeTPEoJJnDdyrPenL3Eoql2OcqYBPofvcZ3hb+cmfaWq0uHfrrWfieSsLFa8OycB7n0Id8GSTZ0LLlgh2CnS9zeVT/Kf4v7jx9KYzpp9JBfdEMh+68ztzbXigA95y1qog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n0mw2y4BYfrLOmQKhWhdHmTRvK5Ny8UEy4PO2h9XNts=; b=eM6utED1MC17LS6pwcCgYaHiSIiTR4ME+F6uLz9f5snLuWdxMeszEWsw0YH5npBhBFrX/GApPEsaytrllxMaa/BJ6I6y7vAoPUpDr+usf8j81erxy4h9lZHybQaF79Mb6CQ40o6liALWdB6Dd0EUW85L/l8TVf3TixD+wvG5zic= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][RFC PATCH v3 13/14] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Tue, 8 Mar 2022 11:47:03 -0800 Message-ID: <20220308194704.14061-14-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95d1b2e3-fbf6-4ac7-3fcf-08da013c840c X-MS-TrafficTypeDiagnostic: MWHPR0201MB3626:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NdDwXP0WZ+dIH2Wa+zvGFH3Pkuxzm0MzF82YgvCUfzK6wsv979eCU7cw/Zh7/QwaCV2ug6cMUr0pi9/V3Ba9b5WYe8Dav03KPEES4m+DEO1a8WX1nK+OEBwblxUXy3u9wNgIKDfywrcuc8Qu5NPXKkJ6NDrN0JIlfiQ9JWI2mgNfOlkqW+L1a9gThvEQIcNEoKTAGGbWxpIlQZ5C+9I4cs0f6utIxzzFE37JKuqbSPMRjKNDmkOjT77gkaWNgY2+f4j1PBQTaQlH3MT5Ag+rCPPSqNc7a6q1jW0OiG9Ti7t3tF1QR1zEbG3fgX+pyGz60rTvXz39od2nDmQh0qMBr3KttSHh4+eproBDcGMNQrdkB3NhR4VUFrn/c9u/xRc1nBaguI7LbXYHTGV0lSndoxrffbm7l7cpiuJj1D+tCTgcy9KV/FFep3vw0tRsuycIltUiAyYDZMUDqURZXOpHL5pOEIP0FUBLs2bKO88ZyiSJ4vqiAuwENV4fMHOfA/hsvTdZnW/Unpz4IYYEaZ0iBwumC9U7mPxFxyRiE3Ul/bjPpedmOLPdlLjcegNdg9zjwzyj7b0FImiu3es7X39ON2O5IihFGxshFsizfRyHwacJz2/N2XfANKLquyLPHRP1WN4XOZsj0/Svq4Q14SZRmxYII/SLwpWd6rMjgxWjzx0BMspeY4QdpUgHjL5Dif4Djlk6B9r5UQW8RxL28KIOFWPtOjDRG/YnQ2VN6K7Cuq0= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(8676002)(36756003)(36860700001)(2906002)(40460700003)(4326008)(82310400004)(70206006)(508600001)(26005)(186003)(426003)(336012)(1076003)(2616005)(70586007)(356005)(7636003)(8936002)(5660300002)(6916009)(54906003)(316002)(6666004)(9786002)(47076005)(7696005)(102446001)(2004002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:45.0313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95d1b2e3-fbf6-4ac7-3fcf-08da013c840c X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0201MB3626 Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- tools/include/libxl.h | 3 ++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_overlay.c | 67 ++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 tools/libs/light/libxl_overlay.c diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 51a9b6cfac..b31e17c2ce 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -2419,6 +2419,9 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); void libxl_device_pci_list_free(libxl_device_pci* list, int num); +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay, + int overlay_size, uint8_t overlay_op); + /* * Turns the current process into a backend device service daemon * for a driver domain. diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 453bea0067..405115c13c 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -116,6 +116,7 @@ SRCS-y += libxl_genid.c SRCS-y += _libxl_types.c SRCS-y += libxl_flask.c SRCS-y += _libxl_types_internal.c +SRCS-y += libxl_overlay.o ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL += $(LIBNL3_CFLAGS) diff --git a/tools/libs/light/libxl_overlay.c b/tools/libs/light/libxl_overlay.c new file mode 100644 index 0000000000..e370e8cac8 --- /dev/null +++ b/tools/libs/light/libxl_overlay.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" +#include +#include +#include + +static int check_overlay_fdt(libxl__gc *gc, void *fdt, size_t size) +{ + int r; + + if (fdt_magic(fdt) != FDT_MAGIC) { + LOG(ERROR, "Overlay FDT is not a valid Flat Device Tree"); + return ERROR_FAIL; + } + + r = fdt_check_header(fdt); + if (r) { + LOG(ERROR, "Failed to check the overlay FDT (%d)", r); + return ERROR_FAIL; + } + + if (fdt_totalsize(fdt) > size) { + LOG(ERROR, "Overlay FDT totalsize is too big"); + return ERROR_FAIL; + } + + return 0; +} + +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay_dt, int overlay_dt_size, + uint8_t overlay_op) +{ + int rc = 0; + GC_INIT(ctx); + + if (check_overlay_fdt(gc, overlay_dt, overlay_dt_size)) { + LOG(ERROR, "Overlay DTB check failed\n"); + GC_FREE; + return ERROR_FAIL; + } else + LOG(DEBUG, "Overlay DTB check passed\n"); + + /* We don't need to do xc_interface_open here. */ + rc = xc_dt_overlay(ctx->xch, overlay_dt, overlay_dt_size, overlay_op); + + if (rc) + LOG(ERROR, "%s: Adding/Removing overlay dtb failed.\n", __func__); + + GC_FREE; + return rc; +} + From patchwork Tue Mar 8 19:47:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12774320 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 71193C433EF for ; Tue, 8 Mar 2022 19:48:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.287479.487604 (Exim 4.92) (envelope-from ) id 1nRfoK-0000ft-Di; Tue, 08 Mar 2022 19:47:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 287479.487604; Tue, 08 Mar 2022 19:47:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nRfoJ-0000eO-U7; Tue, 08 Mar 2022 19:47:55 +0000 Received: by outflank-mailman (input) for mailman id 287479; Tue, 08 Mar 2022 19:47:54 +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 1nRfoH-0004Df-Af for xen-devel@lists.xenproject.org; Tue, 08 Mar 2022 19:47:53 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2061c.outbound.protection.outlook.com [2a01:111:f400:7e8d::61c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a364e957-9f18-11ec-8539-5f4723681683; Tue, 08 Mar 2022 20:47:52 +0100 (CET) Received: from DS7PR06CA0046.namprd06.prod.outlook.com (2603:10b6:8:54::13) by SN6PR02MB4720.namprd02.prod.outlook.com (2603:10b6:805:98::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 19:47:48 +0000 Received: from DM3NAM02FT023.eop-nam02.prod.protection.outlook.com (2603:10b6:8:54:cafe::18) by DS7PR06CA0046.outlook.office365.com (2603:10b6:8:54::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.13 via Frontend Transport; Tue, 8 Mar 2022 19:47:48 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT023.mail.protection.outlook.com (10.13.5.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Tue, 8 Mar 2022 19:47:48 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 8 Mar 2022 11:47:26 -0800 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 8 Mar 2022 11:47:26 -0800 Received: from [172.19.2.115] (port=58782 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1nRfnq-000Cws-QV; Tue, 08 Mar 2022 11:47:26 -0800 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: a364e957-9f18-11ec-8539-5f4723681683 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mmOAUVnNBNpPZc7bqD88t0rW5jGi+VG1IRkGjhzyurV8IkaGa0crf14DLDN/YwPhuEaUGQuPdwKVp1mbPpPkZNFJWtyv8bdeyPeRNbe5nchPmEJGWBUWy5xQ9ZXOHiZGP2SRZXJY3csfVohvz4bJmZ3NBpv+N0s+nr8s6r3iY0UOQe1F+qjMxdq4vnWoYaQiyRMvAliOBApZ07EItC6OEQjM6mKmQeiAk7eHFojY1YSLBtXGQtBuJtHB6ddM6w/Wtk3O8W0qJkK6EYUbP9eRvdHsO9ucaLhJtun+4376ZOhuP2sWFRL4/p8j5P7AQ0wahXU6TicIDyAERo01QedCUg== 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=T7zkeDAGnOQcMYph4tEAaHti6ByfmmWahNuniPhChE4=; b=j6VTeevhv8Ds29dPFOh6SBhLMorR+xVuecgRh9WcJH4ZH0ujXf60G4TWhQaXjABPGMpTcQFKxauBclqNWnoi/GQPVyO7Q1tPefsrQFwc/gU0F8vRGZoxTBCGYlcuDNCpYSZsoFGchwRyvPSLtjPFVb3m5aLumz0iUc1UOkulW7NxZMEzf3dZuQ5NNgTqWllOqx04ntH0SZAHELlkSONVrMQ5nD7BFEfI5HbCrhSOAZBagkqsoLMmRei1lWPuE85HTivVM1Rt5D3pPfhpeMCuV2yBAMH88g7sC6cZUOMlTHVCiUKJCJinnKfRgKMmNKsBJDJN8MJj/1DkQIQpzjuGPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T7zkeDAGnOQcMYph4tEAaHti6ByfmmWahNuniPhChE4=; b=UYbIbwfV4/YBCkzOo5HGokNt3G2dQAxDI3NNaWF8oX4LySY3/6UoZgTsvMZJ4BLmu+zEjKwlMfnI9mPHcSPGe3IYK2E06oJNOHRiWvLX7TzwL+K7RjWGiQu2OP0EvNhVvnZB0onzu8M4hWv40qdVNbzBqD4egCCxUVpFRUfeNRM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , Wei Liu , Anthony PERARD Subject: [XEN][RFC PATCH v3 14/14] tools/xl: Add new xl command overlay for device tree overlay support Date: Tue, 8 Mar 2022 11:47:04 -0800 Message-ID: <20220308194704.14061-15-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220308194704.14061-1-fnu.vikram@xilinx.com> References: <20220308194704.14061-1-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 280302db-73eb-4084-5c27-08da013c85f7 X-MS-TrafficTypeDiagnostic: SN6PR02MB4720:EE_ X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z/PtrEmXEFjsusmiHv467GDfGqXhivWYVfhcp2AX1iS3NN+uWFATbecWk5S5pCwJUu8i57Q6yVxpbiRssQE6NeIZGbZKh26eL34F7QDwWD8kOPcASUPgmUbniqwB1xsNY+LoO/4e29Iq/0QvGdm4qU2m9GkSDZY44xvbGyedeIyI2oe4BD0ACh3CbdmTAZk6fGdvURT8uzyBvwfVPTvu3g4Kl7VUg2geZo7Fjq52iBLzC51XMWMhuc5fowHOiVcEDGC2ZMp2sFIuG5uqUj5LJvsqxYP64MhnMCkDHbOMpDDAfRrklCTuRBqC5XLcIotPNu4XEZJ6NzrP8LpT2HOVU2Xz62YXq7w6gYMa20WpElidjkJuKMwJKB2u+H5zMfl2pJhRn0dCdhNeLZOERjkainnpxHEdbQ2+7E8wZ7LAMTTVKFB+ank8+O92ACjpkMbHk1g3TyworqTxwtc7Sc+6WrxrtFv3ChcPOSu8iUhGFxyM8smROKLdIEP3fPvWX2kVYDKwOXWIO+Oy5nQru68jZ6qTLvaEeL8xvEd9Z3ca7eJMEpjyKtgQBmFSIqJ5A6WFOsATUiPbq0uCEqXYmM9XwhE8zncbamFKwl8Pn2LUzH+FH9t/9If8S3I02AB2eqBkfQR2dgAnkKIfHFGIPuSSCKpM4RjED0w2aVIeKwhC2prLdcq/hlP87cK/U5YUT75RSsFzyOjtPoR9PIknF+DrTQ== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(8936002)(36756003)(2906002)(9786002)(316002)(508600001)(54906003)(6916009)(7696005)(5660300002)(6666004)(356005)(2616005)(47076005)(7636003)(36860700001)(82310400004)(40460700003)(1076003)(186003)(26005)(8676002)(4326008)(70206006)(70586007)(83380400001)(426003)(336012)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 19:47:48.2655 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 280302db-73eb-4084-5c27-08da013c85f7 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT023.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR02MB4720 Signed-off-by: Vikram Garhwal --- tools/xl/xl.h | 4 ++++ tools/xl/xl_cmdtable.c | 6 ++++++ tools/xl/xl_vmcontrol.c | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index c5c4bedbdd..604fd5bb94 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -97,6 +97,9 @@ struct save_file_header { #define SAVEFILE_BYTEORDER_VALUE ((uint32_t)0x01020304UL) +#define XL_DT_OVERLAY_ADD 1 +#define XL_DT_OVERLAY_REMOVE 2 + void save_domain_core_begin(uint32_t domid, int preserve_domid, const char *override_config_file, @@ -139,6 +142,7 @@ int main_shutdown(int argc, char **argv); int main_reboot(int argc, char **argv); int main_list(int argc, char **argv); int main_vm_list(int argc, char **argv); +int main_dt_overlay(int argc, char **argv); int main_create(int argc, char **argv); int main_config_update(int argc, char **argv); int main_button_press(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 661323d488..5812d19db8 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -20,6 +20,12 @@ #include "xl.h" const struct cmd_spec cmd_table[] = { + { "overlay", + &main_dt_overlay, 1, 1, + "Add/Remove a device tree overlay", + "add/remove <.dtbo>" + "-h print this help\n" + }, { "create", &main_create, 1, 1, "Create a domain from config file ", diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 435155a033..76b969dc33 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1262,6 +1262,51 @@ int main_create(int argc, char **argv) return 0; } +int main_dt_overlay(int argc, char **argv) +{ + const char *overlay_ops = argv[1]; + const char *overlay_config_file = argv[2]; + void *overlay_dtb = NULL; + int rc; + uint8_t op; + int overlay_dtb_size = 0; + + if (overlay_ops == NULL) { + fprintf(stderr, "No overlay operation mode provided\n"); + return ERROR_FAIL; + } + + if (strcmp(overlay_ops, "add") == 0) + op = XL_DT_OVERLAY_ADD; + else if (strcmp(overlay_ops, "remove") == 0) + op = XL_DT_OVERLAY_REMOVE; + else { + fprintf(stderr, "Invalid dt overlay operation\n"); + return ERROR_FAIL; + } + + if (overlay_config_file) { + rc = libxl_read_file_contents(ctx, overlay_config_file, + &overlay_dtb, &overlay_dtb_size); + + if (rc) { + fprintf(stderr, "failed to read the overlay device tree file %s\n", + overlay_config_file); + free(overlay_dtb); + return ERROR_FAIL; + } + } else { + fprintf(stderr, "overlay dtbo file not provided\n"); + return ERROR_FAIL; + } + + rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + if (rc) + fprintf(stderr, "Overlay operation failed\n"); + + free(overlay_dtb); + return rc; +} /* * Local variables: * mode: C