From patchwork Wed Aug 7 20:10:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 13756707 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 DE7B1C52D6F for ; Wed, 7 Aug 2024 20:14:37 +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=w9858rqDV1CFWhgdnWboF+QA8Bv5pFDo1GqZgaCeVgc=; b=lNh1nBv5cTdPpLEB1tR6CXHr+X c2l/jA3fpeutJ+8S5ywPclt93OX/u1q5RJVxYPg2CzmgURUiItjdTWisPaO2XyEpMn17vyYdHpFsz blLN8hqTyzz1E0+RfUnNpmBoVuNoSF/sfR116ZwBiuWmMPzo3yFe6BrhPBy7L2hyLqNodcIsSkFbN ZhP/XHJlrhwzrQhDC5CMnykT3avs477LV8tBlyQZ3ROlDI2jr8x+U2xHrAnrC6F2SeC7NYqPNKiDZ uIO9iSJRSQmAjApxVGnUcoWqPyBz7wb4O7XlhsZbdnvvL1LVEuyDS0lvoLjWzeD8HUM6GHjClN971 3Clu0PAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn3D-00000006AFV-3I9Y; Wed, 07 Aug 2024 20:14:28 +0000 Received: from mail-mw2nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:200a::600] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbn0P-00000006997-2BRK for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2024 20:11:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eOQUbgTQaOs528/2A5Yv7QocgDmKWYb1maIYiPaCNWjvwIVpJeRRgTNq7VaCa7vpq8fUG+6ypXyFBb92Y3x/cCGtTHTmNtUAQlm7/c9DVmGhylaien8Bc8no2y5Bc6+t2rNkRkowUl1sHFHVAGO8jBYEBc3ZZdcl4MfU/vvNVBvksGwDE6pPZVV5P+GXVCLwLNorTp0LhOBVA1BB0i8jvnVmfQYGPRp1sJEMdxPwYTYKcu7csKULy6ebZa3ScfQ2x18S+5K9cW15/VsdiVt4TFxTdKnzm2ErTMt9egiNNZ5oHe0Spc1K/Qgh/IBgMp07b/JOeqWhA+yZW7Q+7uBhbg== 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=w9858rqDV1CFWhgdnWboF+QA8Bv5pFDo1GqZgaCeVgc=; b=xYm/2kji3B59Hc/kI0+Rb1qVAnCWmk8+FCkbjNo6b4lnROq5SRHBhf/c09aE5C4/e1BZe0RbI/auQskkLf5F8QpEFzV/OJ5x3E7h8gU426TSflzO8H3exFm8D5ne0McODz/JUpchLcmTz71NIwTjI/FzntZAchIqbZl5CBzJo5aws+iki+Gg1Wvm0NSJdIF6UL+QEPUcRdgWZrmphZh6+PEyu6zfoLHVnA9pF1ociUg2hv7dwe2yGWAx1QBmS1mrbKJ+NxUCvmWvRUDLlARbcVo7fF489l7hX3tNXy3FDfcDgkfpAqKP82aGcVQflHOdlv0pcYJhgkd2mr+7o4FXQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=w9858rqDV1CFWhgdnWboF+QA8Bv5pFDo1GqZgaCeVgc=; b=hoyvg7AIEIkKOI4ibybwsq2IBzjwXYp3eIfVhXxpuZaPREdDoadMmNa/RC84thWb/21TRjplBjJg1+Vrtb1AAI6Zy/EcrgmORTp6dhlBOGS0e1e7Ub5lRAzCIT4T3oO7r5gAGurn3ts+rz1n9zLF30ACn3i7NZHHtlSU+CD7YZ6DUwMGbA3XdiM61a+EjGWF425rti+8mYooa8O5TNvl6e01Wt9cHNehanGz+7EmG0zfrK5jhuGB22gxPFHvs5UCa7Bq4NPgdWEjnaFbj/OA/vq5jDOCn1WQmnI5aVzvHG4QHE1LDWq3eANU1HWyAf1vRX9rDRsSkjVO6hsWWDmMeg== Received: from BN6PR17CA0041.namprd17.prod.outlook.com (2603:10b6:405:75::30) by SA3PR12MB9130.namprd12.prod.outlook.com (2603:10b6:806:37f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.14; Wed, 7 Aug 2024 20:11:29 +0000 Received: from BN3PEPF0000B06A.namprd21.prod.outlook.com (2603:10b6:405:75:cafe::80) by BN6PR17CA0041.outlook.office365.com (2603:10b6:405:75::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.13 via Frontend Transport; Wed, 7 Aug 2024 20:11:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN3PEPF0000B06A.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.2 via Frontend Transport; Wed, 7 Aug 2024 20:11:29 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:08 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 7 Aug 2024 13:11:08 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 7 Aug 2024 13:11:07 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , Subject: [PATCH v1 02/16] iommu: Pass in a viommu pointer to domain_alloc_user op Date: Wed, 7 Aug 2024 13:10:43 -0700 Message-ID: <41602c71a6b865734d34feac46cc596ff9fb7780.1723061378.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: BN3PEPF0000B06A:EE_|SA3PR12MB9130:EE_ X-MS-Office365-Filtering-Correlation-Id: 362532b7-2dac-4a64-b510-08dcb71d1fa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|7416014|82310400026; X-Microsoft-Antispam-Message-Info: MeWfrshpcbjzseiORYsT/fg8/n70DHBVvN9J9flRCk7pTTi3QsGkv6OOQdl+UcTVWdj4o7F67/MfDuFzjwdhKShibW5odZd0i+RNMcbJW1yLiE6ekLWGD2vTYbGHH5I9H/Se+wvLcz42uh4IKlYo702++iBFhgiGiw1kcK2DX0AT88GU/Xwtk2+rwPZH/z8FYJP+Yfv+IJ0BxW28l7LY0p672eJ27SAXYggLABf4iHVaBEVN1kJeaK4m0yfYMNo4s+b0UKxiZEWBCoTeojDu8BD2ysXf7uGoBRhRKyramYyTuEDJrir2VuU3o9yuqlmHCu1JgkEdk4T+aR+YxzB6diTGxER0N+BGJaTNh++ngJ8kYfL84xcRzqpjg+Dpte2d0Ke66XNaaXwLotzl3+UI/dq2TaTFZ1PCUKFW5hkBEFGhvkY/otxwQfUYyBzXPCocyqGrwXxFeyFY2Es7dj0pk3z3lX/YvIr0j1FTM8nRWVtXAhiSqNTAJh0lACgqiaH/9tgq3toGpWm4CGHb/r1Y6rWjOyQWV8BJ6RKjnCZ4ZsTRugx8Oved54RW7qMK4Y0Pnepyfqcrz2Rim+f0DE9qSo8+/fs0uq5CJdYNBYaFxzIbIarFcolMeMMERJk2pJT/giONwZDcX4fTEw830ftL/DQiJClew5jEyoGnr89D/aDBJOd+0aOM9c+9wgKiGMEB5g3LlkXcsj1cmxpk3u1ZhgZOdJqbZxknUcYK6afJTY+UrUi4LwMBM78KCqkTSP9JfqKzvmR+zplb/M+oVqHZFq5jYJj9pLkpv+luDmnThWKcqzOGGY+Ovo7MZ5m18ZgaJxp8SHg5W0Ngo8b5lt5sXTUPGozPsP6IMDmfczLMriEajFHz5RrvL12+BwcT6eS96lgbJuUyhQVOXNoQu8fQZKDQdx4vHRpqPNyYN167PmCTxKR4190lU+7uWgU9jjeLMeWvjVTYYXEPL5RpbMD3vsIydydKufkU5iRtgk6JuTQKd8vOw3wIa+uUXEXoQ7ooK1hsKwx5JeZt3MqqUkxtNcsxxF9VffQ5u+HcafOssGKwcBggytjoI6QLtOwyMRNf6eM+hdbtYJA4IFd7bwdwe7hiSQm/9eyQek1/eg6E72bWOau7Iu8uQjY96D/pe1usOfeb9grQ+Z5VCsu9ahK47Vq+NwS/AJLaTVwdzgXzuE/2hdP0hZK0CYg2i2q4AGQO72deaxbcaMK5jB5D0/DfpVUEbxDhb2XISJf/TEW803IRBj4o93sq2+3ZoKh/760i/iZSDsZixu081ppSgeF8QgNDeGFZ58F6VRSLFskS607bk/1K7lraw7/oEVdzKtOUwTQPd6O8YeOiYStpRPzNo/F7gK/54OZX7CclaCAwimB1gqaDgEu4xHTR+4kfJQxriCO64QWUnWINECMxj2yZDg== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2024 20:11:29.0821 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 362532b7-2dac-4a64-b510-08dcb71d1fa8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06A.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9130 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240807_131133_593857_6E0DE87D X-CRM114-Status: GOOD ( 14.02 ) 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. Driver can store this viommu pointer somewhere, so as to later use it calling viommu helpers for virtual device ID lookup and viommu invalidation. 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 --- 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 + include/linux/iommu.h | 2 ++ 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b19e8c0f48fa..e31f7a5fc650 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2432,6 +2432,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 3962d5a55519..558cf3bb24e0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3403,6 +3403,7 @@ arm_smmu_domain_alloc_nesting(struct device *dev, u32 flags, 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 9ff8b83c19a3..0590528799d8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3703,6 +3703,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 aefde4443671..c21bb59c4022 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; @@ -239,7 +239,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 642ae135ada9..a165b162c88f 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -320,6 +320,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; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 20a40fd6c4ba..0b71b2b24ede 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -42,6 +42,7 @@ struct notifier_block; struct iommu_sva; struct iommu_dma_cookie; struct iommu_fault_param; +struct iommufd_viommu; #define IOMMU_FAULT_PERM_READ (1 << 0) /* read */ #define IOMMU_FAULT_PERM_WRITE (1 << 1) /* write */ @@ -611,6 +612,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,