From nobody Mon Feb 9 20:09:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail(p=none dis=none) header.from=xilinx.com ARC-Seal: i=2; a=rsa-sha256; t=1630565477; cv=pass; d=zohomail.com; s=zohoarc; b=GjqiNc7Ze7tpXfv6+/TwIKUVYusRrFR5nP+eIDrUXP5KXO0xz+i3vr9Adr3zHF+rqSe/Vh7AE3FE5gbJZDfHfrYfK7rzf7YK94AlXotzQMyEh9TFowj7GX6qZiaVCq4wsaje4BMwZu/lX2F2nhlNSzxO5H/fv44sIyKgO7GNVCU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630565477; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EVas2kXYqY8J1i69hD1pnLTQnzKqbS4jKsdjLz6x97c=; b=lUq53u8A35JQaO/5SmbO2P2WdQhRXlJqkQ3ItrNqTwhfsPUOoWINXr4IJ9Wc+eWXCyPDcPP3esHf3Db3HXLaKWd8GbvxLShhfpOxI9JWMru3BlzdVYwmV69y83CnLBQXuX+pXLaE4onqocsE420r+VuYkiCcujz/0KS3PYjms6Q= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=xilinx.com); dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1630565477230739.9015166720325; Wed, 1 Sep 2021 23:51:17 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.176926.322132 (Exim 4.92) (envelope-from ) id 1mLgYu-0005n8-5L; Thu, 02 Sep 2021 06:51:00 +0000 Received: by outflank-mailman (output) from mailman id 176926.322132; Thu, 02 Sep 2021 06:50:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYt-0005kp-Co; Thu, 02 Sep 2021 06:50:59 +0000 Received: by outflank-mailman (input) for mailman id 176926; Thu, 02 Sep 2021 06:07:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsv-0004hX-Ty for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:37 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (unknown [40.107.243.58]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d71d7a5a-f0b0-458d-8457-d905d920e6b9; Thu, 02 Sep 2021 06:07:36 +0000 (UTC) Received: from SA0PR11CA0187.namprd11.prod.outlook.com (2603:10b6:806:1bc::12) by MWHPR02MB2606.namprd02.prod.outlook.com (2603:10b6:300:44::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Thu, 2 Sep 2021 06:07:35 +0000 Received: from SN1NAM02FT0051.eop-nam02.prod.protection.outlook.com (2603:10b6:806:1bc:cafe::47) by SA0PR11CA0187.outlook.office365.com (2603:10b6:806:1bc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 06:07:35 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0051.mail.protection.outlook.com (10.97.5.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:34 +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; Wed, 1 Sep 2021 23:07:13 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:13 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsX-000F6q-F6; Wed, 01 Sep 2021 23:07:13 -0700 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d71d7a5a-f0b0-458d-8457-d905d920e6b9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PwWMyGPlBKtFHj1zM/gtcQiLwDgH+yShnsoTOJSsSbOnxUVjkYii203fAKF2tfN3J0iRBuAX9wx2as5wSlKlDt7V+FZrd5iC0gVGQmYWWG6l1u2+ald2Ldc28FAhqxaxOqHB95/lLOX0PQ6w9Uf+eziftZfbnhPOZPC4nlsOK8vd6eHFz2IGUuP2CYDoC7lqInZ7kIp9FnGC+b2SqJCkMEoYcQjlpokiCL4h7ppC7IrStudyGvXuVfRJ1OuYls8OmMwPwoS/unmsvEVPgF+rhyFN00spTN9ZDa1lN8WsIyt7iDsLSrm/KNbWnGNkaRbrpvr2JtRAxwcQcOOwNzZZpA== 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; bh=EVas2kXYqY8J1i69hD1pnLTQnzKqbS4jKsdjLz6x97c=; b=baGfgKv6wfpslNLcyv4rKCbR3vhTEl/V+OdFy+IgivH9xZIn3/bMExf23cMh7y5/jpnd9xauUSY+AQopw3w2txn1uXKketaIOsJ9OE96cbKG8aOyLa+/RvbFZ33Uoa7wfbcWnx3buXcylsfn7L8sElihGqZIUKiUn+imUsnMxQcuvuTBjh1wWN6YaOXhpaCkf2vvWBC0PXRpMOd5b1OwiUMgmRyVdYf2DpvDx325qbPUsd2ZieSnwbQp6m/NYoDF90spKygJvB4ITpEYVyGH8hwE4+3SlbWGxcCjRbVdCNbrnCuFGFQk50cJvNXa6LFZxpPRXK7uYgoB2G1ntl4guA== 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=EVas2kXYqY8J1i69hD1pnLTQnzKqbS4jKsdjLz6x97c=; b=OhDJ97JWnZlQmoCvp1jgfKBkXfc7CTrXRjx9a1itEgWqm+nvR8rkYqPd8FEVw2kYPd3cEUQhMrGgpdT85MROte2W9HmBJLrRE6QRIrg35hC2a3+dMECG4dqdsnbXG30TvYW1g4f8/V9tmF/jQQc2SBdGJdPfTKe99GV9/AcniQ8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 , Jan Beulich , Paul Durrant Subject: [XEN][RFC PATCH 08/13] xen/iommu: Introduce iommu_remove_dt_devices function Date: Wed, 1 Sep 2021 23:05:58 -0700 Message-ID: <1630562763-390068-9-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e9508a7b-7601-4ec8-4fbb-08d96dd7f529 X-MS-TrafficTypeDiagnostic: MWHPR02MB2606: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TMQQTZIpkWWv10Ikt+KPGzuRQXvsobuI7WlcFc7zHglAU7EPq34TwwLc8REM6x9UCzfA+OIWUlUkYBJPchPItU4BduToxXXwNtLikwy+i7xfVo7EBHiKkws/1TqNsdPhOjOeeIU4/db7oS1GreqCl1UXP0bSnlLzYoKVeaQJcWRxIWK3OO8dN0xWFGzZDiNNDOZavcS6X4K6iaKtE7loInF61Q2w+ETeuV2N5+GfUytah1iE3bB5GlQE+0G5k4eYfJpVHh1lj/GMfiKHvfJOEgpPSVRIslaa6SaVTOlidGQGcRd/E59DAmBJYDB+dOvMh0IMoxSIYMMge3QPEq9XwmUFiQMcB0gowseVr41IVhhO74seru+ixoSQZAiF4vQmR83rQ2Z66odrEQPai81dJBE9LMr6stnG5nya1WpvLFLMUVjzXWAgcl2p73NIeUjaz6xVHoDqgkJvayixjJz9K6oKBsvaimIBnHgBmo9EZuMf/fKiZMhLfCdAxzKp856xouT9IuQDMHBRiAp9LC8+wLaFFt0QgvW4seVVdPaTqKshfyFW0HghGsv2ChgU0zWonNdP/KXYv14FP+4LKIwm+HnpUKyxycO2gGqCnKjeqyMVTRrxRUKuv5DRkb+wDyVapCTNoWkgaIo5OGoUchKQhTvO2tKEC8thALJM8DI8adV44qAHjuUdRh4SwMc9JbRWtA4N4i9tD9nUU1S3CwiHfSUsqE3SfXHG7yvIsw6KMJU= 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:(4636009)(376002)(39860400002)(346002)(136003)(396003)(46966006)(36840700001)(36860700001)(186003)(336012)(36906005)(2906002)(9786002)(26005)(82740400003)(316002)(4326008)(426003)(54906003)(70206006)(70586007)(7636003)(47076005)(5660300002)(7696005)(8936002)(356005)(36756003)(82310400003)(6916009)(2616005)(478600001)(8676002)(6666004)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:34.7337 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9508a7b-7601-4ec8-4fbb-08d96dd7f529 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: SN1NAM02FT0051.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2606 X-ZohoMail-DKIM: pass (identity @xilinx.onmicrosoft.com) X-ZM-MESSAGEID: 1630565478910100009 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" iommu_remove_dt_device function is introduced for supporting dynamic progra= mming i.e. adding and removing a node during runtime. When user removes the device node, iommu_remove_dt_device() removes the device entry from smmu-masters t= oo using following steps: 1. Find if SMMU master exists for the device node. 2. Remove the SMMU master. Signed-off-by: Vikram Garhwal --- xen/drivers/passthrough/arm/smmu.c | 53 +++++++++++++++++++++++++++++++= ++++ xen/drivers/passthrough/device_tree.c | 30 ++++++++++++++++++++ xen/include/xen/iommu.h | 2 ++ 3 files changed, 85 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index c9dfc4c..7b615bc 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -816,6 +816,17 @@ static int insert_smmu_master(struct arm_smmu_device *= smmu, return 0; } =20 +static int remove_smmu_master(struct arm_smmu_device *smmu, + struct arm_smmu_master *master) +{ + if (!(smmu->masters.rb_node)) + 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 +864,31 @@ static int arm_smmu_dt_add_device_legacy(struct arm_sm= mu_device *smmu, return insert_smmu_master(smmu, master); } =20 +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 =3D dev_get_dev_node(dev); + int ret; + + master =3D find_smmu_master(smmu, dev_node); + if (master =3D=3D NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret =3D remove_smmu_master(smmu, master); + + if (ret) + return ret; + + master->of_node =3D NULL; + kfree(master); + return 0; +} + static int register_smmu_master(struct arm_smmu_device *smmu, struct device *dev, struct of_phandle_args *masterspec) @@ -876,6 +912,22 @@ static int register_smmu_master(struct arm_smmu_device= *smmu, fwspec); } =20 +static int arm_smmu_dt_remove_device_generic(u8 devfn, struct device *dev) +{ + struct arm_smmu_device *smmu; + struct iommu_fwspec *fwspec; + + fwspec =3D dev_iommu_fwspec_get(dev); + if (fwspec =3D=3D NULL) + return -ENXIO; + + smmu =3D find_smmu(fwspec->iommu_dev); + if (smmu =3D=3D 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; @@ -2876,6 +2928,7 @@ static const struct iommu_ops arm_smmu_iommu_ops =3D { .init =3D arm_smmu_iommu_domain_init, .hwdom_init =3D arm_smmu_iommu_hwdom_init, .add_device =3D arm_smmu_dt_add_device_generic, + .remove_device =3D arm_smmu_dt_remove_device_generic, .teardown =3D arm_smmu_iommu_domain_teardown, .iotlb_flush =3D arm_smmu_iotlb_flush, .iotlb_flush_all =3D arm_smmu_iotlb_flush_all, diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 98f2aa0..37f4945 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -127,6 +127,36 @@ int iommu_release_dt_devices(struct domain *d) return 0; } =20 +int iommu_remove_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops =3D iommu_get_ops(); + struct device *dev =3D dt_to_dev(np); + int rc =3D 1; + + if ( !ops ) + return -EINVAL; + + if ( iommu_dt_device_is_assigned(np) ) + return -EPERM; + + /* + * The driver which supports generic IOMMU DT bindings must have + * these callback implemented. + */ + if ( !ops->remove_device ) + return -EINVAL; + + /* + * Remove master device from the IOMMU if latter is present and availa= ble. + */ + rc =3D ops->remove_device(0, dev); + + if ( rc =3D=3D 0 ) + iommu_fwspec_free(dev); + + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops =3D iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 6b2cdff..c4d5d12 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); =20 +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)); =20 --=20 2.7.4