From patchwork Wed Oct 9 16:38:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13828821 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 BC93ACEE32D for ; Wed, 9 Oct 2024 16:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hbyxRVmZSVIo9+hIvLvnktC8eUsa67K5lJbGGR93RTw=; b=O/VIXjXBNOsPk4pRdNeolbOm0V nfE0flYRA3gqg5451fR7uB8VKBuUmskeCNIjfJ94G1dMt6bCiwv/Yn7JpXVnsJhTcS0ISRcHCO2hf +yGasrwvF4XjylVjeacSHShx1IMAN5j1N8sE4d2XQ53s+/IuroFfanSLetT5oLYbzPi+znDDthbZf JlXaqatsVDVYXui2YUJ6pg8+kQloS9CDIQzR7Fd0tK4fcvRKHpdT8VmrZJR2XujJ1FiOnmoMMKtRC wJxV2CwxosoxXe6c64Ow9nLISjM0gdtxq1GpEJ8qGlTsHuqFcHMPmdeiQdRsWaiINnl8uErdqpJld 2kxHK3Eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syZxt-0000000A51D-2tUs; Wed, 09 Oct 2024 16:55:09 +0000 Received: from mail-mw2nam04on20602.outbound.protection.outlook.com ([2a01:111:f403:240a::602] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syZiK-0000000A0PC-3kY4 for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 16:39:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XA3yJB3hV9D8ezBKAr7b2NibOtxIop81Xq4r0NlkinNnmWTpn5ClylIPtItoGfH/x39Rr3H6EnQLv3pQl34brUnwyntd6+66LahyNnx1IthsBNIySo9prZfoVDAe2YnmFysm+gvUh1RCrjy1GhTV4+M6hhIpMXzHtC1gjh+hZ4r3fPt1PEOquaMfWkQ3FY+XJs4aUSrghkAF7YH+YCzPiwrVvdhsvXCyh1bjUbCt4Nh7ZkA7nFjuxJJb8XZWCnc4NQJtq9JJ5BxHoGpSDw5cTPL34grdWN94t2Q2EP4CQLJO/+YJuKOM1VEo8xgr44oqys4qCBABMyaVyARciJ1EWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=hbyxRVmZSVIo9+hIvLvnktC8eUsa67K5lJbGGR93RTw=; b=YUFjvzeDJvF/KA73srnkKC5S6okVs1yUsFQChTqK1wxjhuUzHUPbHgwIUSS/CpQWSi2gL979lca8ORX5DVon6fU6lqMEXRfvwNY5E6TlnirM/xiWtu99c4jY6qc4q9NnGY5/UT59RECGJcgsww6sqo0G3kgzKAhBE8oRslg9yWw9+AtHKTPyWuxU/u8WTZMHsHZJABXT3hlQslUhXTvU1OXvojUYOAayCJZuYiYe/SoQeTfR8czIbmb3nzP/tqyQsm34GQNVndV95gCnsSo/8URnjSoPpNfL07a+moQGlZ1beWhlmQl/HlK+9O1+erHflMOQuYgdeLLl7ExhyAit2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hbyxRVmZSVIo9+hIvLvnktC8eUsa67K5lJbGGR93RTw=; b=Ou8DOyd2qVm3ot41iZWT7OxoSKUQIas8GJJ820bXvz4KM19rQJP0MHMh/8pZOci1d/I3cpiDX12iqXEMR7hnA48lErQ2GwYqRnC9FDeuuRp9faCf+k0JRq2f9A4Bux8sLf7rMGU1cDlurtLvjOuBAD9wK9+BzrDuFTSeiPCas89gUEqsK/hGdV2i2zZEfF1V3Hfj9ygHXTKNMTGMYVeHw2U9FMsiJ2bLZsrD5wkIU9sDDeQ8eK7CZjyhbJBTvoxBDlWdQu64FAEUeNRcZmJ/tK9BbLc3TF5VidXchgUS+th0oqhccAvBIYgnFN6OgLdGRah/k2WroevUP/wHmWibnA== Received: from CH5P223CA0001.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:1f3::27) by SJ2PR12MB8009.namprd12.prod.outlook.com (2603:10b6:a03:4c7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Wed, 9 Oct 2024 16:38:52 +0000 Received: from DS3PEPF000099E1.namprd04.prod.outlook.com (2603:10b6:610:1f3:cafe::c8) by CH5P223CA0001.outlook.office365.com (2603:10b6:610:1f3::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18 via Frontend Transport; Wed, 9 Oct 2024 16:38:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099E1.mail.protection.outlook.com (10.167.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.13 via Frontend Transport; Wed, 9 Oct 2024 16:38:52 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:38:46 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 9 Oct 2024 09:38:46 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 9 Oct 2024 09:38:45 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 05/11] iommu: Pass in a viommu pointer to domain_alloc_user op Date: Wed, 9 Oct 2024 09:38:05 -0700 Message-ID: <781b5bddb195bffa2ba80e5a04cb10336db74c03.1728491453.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E1:EE_|SJ2PR12MB8009:EE_ X-MS-Office365-Filtering-Correlation-Id: bf181ab7-f500-437e-1a74-08dce880dbef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014; X-Microsoft-Antispam-Message-Info: yuFiYe+MBhhorhxkxZShmIF1suacZbhEYNm/GTu9yzjVYEEDDU9oMvO5kITa16bIYrZTNqrCzvxW6aHFMFRlNKvyvh4KA2wOxyUv0r8TexChVDJQQI7LizrdMYYEoRlL0j4qdxRbm166xwkZC1r5tInCYbA7gXSI1zTcSHRRh0oKlztAnsH8JQMXOlKb9w9EnCyNJypf8BB301rXfRnGzAQWpfk171tJTAV89uRd4jsNSMlpSP9u02IXHxbPWXoSSQxAGqyxwZOnin7nzb5eHp3rRPujo/oAMTaC8blVdfR0UR/ur6gsQGABRfS479wumlxZL43eZI2mjwX0HcypdF5yX+wpQqtczrS0y3M72YlO/EHVwEzNfi3j2BvIRX2EPn6yYMd4LFUBqo4qj+cyc2K+stpuqUYhgwnvkSsvUl9TjSPHor1htTO8qF9hI7FsDquRk/8nvy5X9HVE6rcL6peRYDBRfXHW20PI0i+LskBvXkbz/H9BkxjnLZvQbSSJMpPoLRDUY7BHGvTO0Rj/AfSBCpOtif32jQ4VbxjaCJfn6DGXvPtpaD1sjcYX+bGShNLvN2Wbp8jDQEsa5EyG+Lu+Dk5maA7J7PhZAVHip4/QiO8FfsnhHnvgZsnQT26uz59ITqmVwqBXNy7ug+IA1qg1pFeuXM3VyLfywDZNvN02kqSXBccG3ewz+pxoqueNOP+3PYxAjJw+3CLKienn9QBL6l8xQEBIJuEfvS8y0yS4dCihG0Vq05Gvej3tk8xc7m81Pgd/gVY7v2YwcAZRm38R/Qlo7McaJVT0jyFq3tt+biT+v7W7VmIUXHFT9CaFPDOPJamM6A1ZRRK3qqafSZmdlqVb5z7umIobVcUcUQuJWMvvtiAcYf38O4/AhAeZgaOLP+Hho7BHRqOpZwTqxIveAlv8P7XUsYTg+7eG3q99UmZtJrRj6W7nLL6sQ5i6GTwjY7DNmD5n03pFr69MFtI7BbCQFltZc4E885CJwKk5OAxxxqxlmgTGM4IOE/TBaLPFA7q7MjpkPx0lP482zXA11mT47WuDS1RTuPkEA8swg5EjjxU6deY3WhvWoRXYVi6bsJTcvPj04B0JLZXW0USOFo/xlGM+uMWnAkrQxoLwif6xIugRxxL9FLuYb+gWv+V/Es1oMq6C626CcGh4VGUp2Ga8hC05SNGPK6QwYC6sjY1n3SZyN0ArvwwpB/a1pu0OsQQvoxHqIKqeiQLT4IBR6vJvfbMAnhcbNH0idHoNn5FRWklKn48cNpOgAbijD3WpoTlFxNcHHDtl7ST2KC36kO3TTfCImtcrh5p9ZC801OxYiX6fs/NuleN+U1Fg1jSnWPuEPg4dqbhx4uUgtx8T61OS8yntirUVHRkhrzGPyOcN44DTfZ49krUycOiT X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2024 16:38:52.1699 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf181ab7-f500-437e-1a74-08dce880dbef X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8009 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_093905_131236_8809FCEA X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With a viommu object wrapping a potentially shareable S2 domain, a nested domain should be allocated by associating to a viommu instead. For drivers without a viommu support, keep the parent domain input, which should be just viommu->hwpt->common.domain otherwise. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 1 + drivers/iommu/amd/iommu.c | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/intel/iommu.c | 1 + drivers/iommu/iommufd/hw_pagetable.c | 5 +++-- drivers/iommu/iommufd/selftest.c | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 3a50f57b0861..9105478bdbcd 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -573,6 +573,7 @@ struct iommu_ops { struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); struct iommu_domain *(*domain_alloc_user)( struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data); struct iommu_domain *(*domain_alloc_paging)(struct device *dev); struct iommu_domain *(*domain_alloc_sva)(struct device *dev, diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 8364cd6fa47d..3100ddcaf62e 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2394,6 +2394,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned int type) static struct iommu_domain * amd_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 4e559e025149..4b836a5e9fde 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3117,6 +3117,7 @@ static struct iommu_domain arm_smmu_blocked_domain = { static struct iommu_domain * arm_smmu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9f6b0780f2ef..a8a66a954c27 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3522,6 +3522,7 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) static struct iommu_domain * intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { struct device_domain_info *info = dev_iommu_priv_get(dev); diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index d06bf6e6c19f..77a1d30031d2 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -137,7 +137,7 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, if (ops->domain_alloc_user) { hwpt->domain = ops->domain_alloc_user(idev->dev, flags, NULL, - user_data); + NULL, user_data); if (IS_ERR(hwpt->domain)) { rc = PTR_ERR(hwpt->domain); hwpt->domain = NULL; @@ -240,7 +240,8 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, hwpt->domain = ops->domain_alloc_user(idev->dev, flags & ~IOMMU_HWPT_FAULT_ID_VALID, - parent->common.domain, user_data); + parent->common.domain, + NULL, user_data); if (IS_ERR(hwpt->domain)) { rc = PTR_ERR(hwpt->domain); hwpt->domain = NULL; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 540437be168a..f4be87b49447 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -319,6 +319,7 @@ __mock_domain_alloc_nested(struct mock_iommu_domain *mock_parent, static struct iommu_domain * mock_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, + struct iommufd_viommu *viommu, const struct iommu_user_data *user_data) { struct mock_iommu_domain *mock_parent;