From patchwork Tue Apr 15 04:57:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051484 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 134DAC369AB for ; Tue, 15 Apr 2025 05:06:48 +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=oNhA5Q6xdTHm9y5k8V8H63jiKzXIqrVsfDenrCBP2fM=; b=SlRJaSjLKgfZFMHio62xdKnV2x YBXAFUD3qkdS/GJFXLrgcwonfrje4ZD6mj5XjMXZrf0klBTYtCa0uDd/TMAoazzs8Q3yt2DzmqTjN 9py5CyTaX7sGaSos0jEGRDkYMkUvn44wBm6c5e2kcQh7EwjEDjJ3r5U71B5N9lnB9bXIVQw/A8rfv m+QAurO1yc6aY3P2xDouUznWzAKyJ1MR574SZAYcMnlzKoPVzmVeAAFKqYktbTwzESSnkbeYRbX5N MARZ/O4aeGywD+ptF/yaHH0Ak/zC+etEpue0v1987I3Lp44425XcR/YMuLD19SlH24Sm9Yf1XcfKT JPMVUXwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YVG-00000004WEq-16gP; Tue, 15 Apr 2025 05:06:34 +0000 Received: from mail-bn8nam12on20600.outbound.protection.outlook.com ([2a01:111:f403:2418::600] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNR-00000004UsK-4Bc8 for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lFV69rXd/po+uPNRz4A8QwdzxCRoS19zSkJYFyxdMfsrmTzcQOOWpfhM4uNluEsdCJGtt8dPSzuFRUeJ8OWXITsHsvGRQkqwZW+EVUsOOqzzwA1Slcxj3eVvStrDekqF6uHQcj0mGIINWJDYaCxUoCpRyHskT0/OcrYyMU1/FN7TpyljPkzmbX/pgBAvRDJRfrHwcDL33E57tgvBt74SFCD1KCmzlAb22H40nEwNaaEx9AMLapdKz35cIwruek+TuPNbUxUNK3FuXkUtZ8n/NGhZTFCuah+/pZKpl0qW2pA7Iq9PlULvpomtbay/V6T6h2j4XGnDS7t0tiLlk1iMdA== 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=oNhA5Q6xdTHm9y5k8V8H63jiKzXIqrVsfDenrCBP2fM=; b=ufQ7DqnYkw9NEPBcLG/FFGayTikbxmLmBE6T5GFgJfkN/HoBcwHEdh6f0ovakgqdtPKQj6y/yKZ20OyIiKQotKacI9p7u+Z1KAu430GT5caXJxuoIpU5NpuGvQoJZylkIVPeFE+1XsarFnqmeXkWd4prw1xrH+WyRCsq8bHNMkfgsQVSPvcg8Ru6nghuBZzKjhuIMPI/UUbKIh5K/12MhFWFtpRD+BGF4RFpBp8I1dMtFGG8y3YTdpgDkzk8S5NsLKgd4D9FdMs4V1k84uQ1fIleCOE/0ArEzkkhizgLizWJpgGK2jj3MukWcCrvvqQSkxnl30K46ikypV0ZBT6dZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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=oNhA5Q6xdTHm9y5k8V8H63jiKzXIqrVsfDenrCBP2fM=; b=t/P9o+BvdTGPausmZWDlZ3B11zBNHieBHmdi7tpljytFweecpG1nbqbqp8bM4+cRHfUI/2C9oB3he4NT4+ho5PVFPrmg9SNqGjb6ZW5QaxQ2x4r2KpUQixpeunP8Cy3ptSIVd5ptvT5iWV/fhgj2AKL/auX4fb6Sbqt26dQd55GQsvgrTLMv4cOPs2tAKFZMIcKxZVuowvNEmy4PTA1t/oWVtFAhvBApjudeb4sbA2TxlqWg8ly9DCuu/OsK4AN2UdX54mtD47xBiCxC9ygDmG2ci/UxBh707U0gkiO7QZ4541+R11hOd9FxuLAZYcQyR1mvKr4KbUrEVGC2j7zyOw== Received: from BN8PR04CA0012.namprd04.prod.outlook.com (2603:10b6:408:70::25) by IA0PR12MB8373.namprd12.prod.outlook.com (2603:10b6:208:40d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.35; Tue, 15 Apr 2025 04:58:22 +0000 Received: from BL02EPF0002992D.namprd02.prod.outlook.com (2603:10b6:408:70:cafe::36) by BN8PR04CA0012.outlook.office365.com (2603:10b6:408:70::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.36 via Frontend Transport; Tue, 15 Apr 2025 04:58:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF0002992D.mail.protection.outlook.com (10.167.249.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:22 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Apr 2025 21:58:10 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:09 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:08 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 01/11] iommu/arm-smmu-v3: Pass in vmid to arm_smmu_make_s2_domain_ste() Date: Mon, 14 Apr 2025 21:57:36 -0700 Message-ID: <137d6eb98c2b7ea9d5cc2fb0f44f3c73065aa23a.1744692494.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0002992D:EE_|IA0PR12MB8373:EE_ X-MS-Office365-Filtering-Correlation-Id: 8155f1f0-cd47-4ebc-725b-08dd7bda2614 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|30052699003|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: SwhY8zp0IDjlz6a/cHfsgXamb7fOR3Y67jaepVIebjY/boSu4sBqjkpj/A5p6WMxyUo8FQL4wMNwkpLzlP2cdFTpFxaZDkYg+/AyJxXWHHCZxL3F5RF/hkyqzlLEpYIhChjNuDgSH/YXzljUIpis3IBylwA8zCWf9081QAG8Iy5pGsreCeGA1/ZRP58AePkUSUIGMmQ/HkdeIx+6BNAZg8gGMY5k+wm2HHtBEhmdWUm/HYrgARWWiIEU1HkZBpKxtIEjC/4Ynnu2mu+RAhjHAgYZ0nGCC+dccar2HzsAiOdc5nDbALZinYDY9v0mWZgXx82BSjxg4ajruBcBwwuBMhQgrkbAgjnJF+m5yLTPUuT0sQDfJZ1f44d6YI1gfAutqRQPd1dG+uaDQzhxY6cQOYKRZc7iRYRaas1cwLm+7YXgXn8nBVal4we8Zw3Xge6fw374+suU1Deu2NheI88xHBUtO5q5eeL8AarRD3alLgfnjHjuIsabaeBKB5uprMqc/XD2+oA/AW7UC3+qpp+kxMeqxDbjN073iOwAKOGKH3kk0Q92V3/+H0V3kg7L/ecWrzbOXihJdxFhk0R2OqTR0LC9+AcMwJt4/nGBKSMI+7EBE6WTALQn1rT3NjJvpdnYrCxxwRohXjJsHCCIhbf6hXR70isqv5SCZwvw6DDV4rIWaX0Kk/x+58W0xkiTitg35JJ2gCEJQr+7WfZmxEm1KPtLS/OIVDeMdQcu2zL0A2TXnGYwRMu2e9DdVD0DcOYuHrps+gMdjcNs6nAfzRazbonwv9rqbO5sK9mZp9v3r2qWrbDWJXGmZrA7GoMSyzLMOwUmBBqFSaq8tkxoDLr3bri9t6jHUVGDkLePn59qI8HgpjWo3I/sB2MY3RjBNvZoG60Pr/b+Tqva1XOootwMoQ4cGUyW3Lxb+rnTJSk27Trs+pb8BybJCi13FxAffjw4C8TbQ2Fk1J2NWGLkSWnVuqlHyiajASp5G8wXuYHzjyjxhQcCLR8BBQGcEq8IiQ9EQSztQ7mLzG4e5T3mR/2ua+WvjNofqeQEgrCGJCB7thkcl0sMxs5k95FR+mRjgx2ANz9m9KHPc1k/nVmWSl+Pb0qldPw0+DNr+iJEMPvjgqmBY3/hG5/gbweU+fhDTKMzyjNeLqe1WnUeH5vWEFgLdOqjaBgM3NrdHxo4qp9PhBC0EHTEexeX2r2tcrOZY4hjz9USdsXIRpBLW6PTJ2ggSGTdYcQaDvI1HPwvClZ2T6HraGgTBr8Cuh6Vnsj5UosivwC0w0VR24pFx0wNJRl68Web2cHy65zbVmoFNn0GOW8ucHWtJ/vz4xO7gerqmrX7JBFD4fobEiI5/U+5G+HZyZ+/9LyEU4exc3Fa1WOe7nonUZWe35uXr0M7dqd8sDYtetFRx4GAYdyk8IQoOutVArwnFDzFlMRINOznNFtlvuwwTVrHErvFObvwFyRh+2qQaBZgnU2Ft6NhxaAVjlaYvEFOf15KK9KphwdEN25y1hSaStynQ4YoEqgvZK8Iq5U1 X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(7416014)(30052699003)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:22.6408 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8155f1f0-cd47-4ebc-725b-08dd7bda2614 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0002992D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8373 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215830_035424_30C1B40A X-CRM114-Status: GOOD ( 12.73 ) 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 An stage-2 STE requires a vmid that has been so far allocated per domain, so arm_smmu_make_s2_domain_ste() has been extracting the vmid from the S2 domain. To share an S2 parent domain across vSMMUs in the same VM, a vmid will be no longer allocated for nor stored in the S2 domain, but per vSMMU, which means the arm_smmu_make_s2_domain_ste() can get a vmid either from an S2 domain (non nesting parent) or a vSMMU. Allow to pass in vmid explicitly to arm_smmu_make_s2_domain_ste(), giving its callers a chance to pick the vmid between a domain or a vSMMU. Add a WARN_ON_ONCE to validate the input vmid. Reviewed-by: Jason Gunthorpe Reviewed-by: Pranjal Shrivastava Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 6 ++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 3 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 +++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index dd1ad56ce863..d4837a33fb81 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -894,7 +894,7 @@ struct arm_smmu_entry_writer_ops { void arm_smmu_make_abort_ste(struct arm_smmu_ste *target); void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, + struct arm_smmu_domain *smmu_domain, u16 vmid, bool ats_enabled); #if IS_ENABLED(CONFIG_KUNIT) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index e4fd8d522af8..d86dba6691e8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -34,8 +34,9 @@ static void arm_smmu_make_nested_cd_table_ste( struct arm_smmu_ste *target, struct arm_smmu_master *master, struct arm_smmu_nested_domain *nested_domain, bool ats_enabled) { - arm_smmu_make_s2_domain_ste( - target, master, nested_domain->vsmmu->s2_parent, ats_enabled); + arm_smmu_make_s2_domain_ste(target, master, + nested_domain->vsmmu->s2_parent, + nested_domain->vsmmu->vmid, ats_enabled); target->data[0] = cpu_to_le64(STRTAB_STE_0_V | FIELD_PREP(STRTAB_STE_0_CFG, @@ -78,6 +79,7 @@ static void arm_smmu_make_nested_domain_ste( case STRTAB_STE_0_CFG_BYPASS: arm_smmu_make_s2_domain_ste(target, master, nested_domain->vsmmu->s2_parent, + nested_domain->vsmmu->vmid, ats_enabled); break; case STRTAB_STE_0_CFG_ABORT: diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index d2671bfd3798..7fac5a112c5c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -316,7 +316,8 @@ static void arm_smmu_test_make_s2_ste(struct arm_smmu_ste *ste, io_pgtable.cfg.arm_lpae_s2_cfg.vtcr.sl = 3; io_pgtable.cfg.arm_lpae_s2_cfg.vtcr.tsz = 4; - arm_smmu_make_s2_domain_ste(ste, &master, &smmu_domain, ats_enabled); + arm_smmu_make_s2_domain_ste(ste, &master, &smmu_domain, + smmu_domain.s2_cfg.vmid, ats_enabled); } static void arm_smmu_v3_write_ste_test_s2_to_abort(struct kunit *test) 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 c32c0b92dc69..1ec5efca1d42 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1656,10 +1656,9 @@ EXPORT_SYMBOL_IF_KUNIT(arm_smmu_make_cdtable_ste); void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, struct arm_smmu_master *master, - struct arm_smmu_domain *smmu_domain, + struct arm_smmu_domain *smmu_domain, u16 vmid, bool ats_enabled) { - struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; const struct io_pgtable_cfg *pgtbl_cfg = &io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops)->cfg; typeof(&pgtbl_cfg->arm_lpae_s2_cfg.vtcr) vtcr = @@ -1667,6 +1666,8 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, u64 vtcr_val; struct arm_smmu_device *smmu = master->smmu; + WARN_ON_ONCE(!vmid); + memset(target, 0, sizeof(*target)); target->data[0] = cpu_to_le64( STRTAB_STE_0_V | @@ -1690,7 +1691,7 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, FIELD_PREP(STRTAB_STE_2_VTCR_S2TG, vtcr->tg) | FIELD_PREP(STRTAB_STE_2_VTCR_S2PS, vtcr->ps); target->data[2] = cpu_to_le64( - FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | + FIELD_PREP(STRTAB_STE_2_S2VMID, vmid) | FIELD_PREP(STRTAB_STE_2_VTCR, vtcr_val) | STRTAB_STE_2_S2AA64 | #ifdef __BIG_ENDIAN @@ -2990,6 +2991,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) } case ARM_SMMU_DOMAIN_S2: arm_smmu_make_s2_domain_ste(&target, master, smmu_domain, + smmu_domain->s2_cfg.vmid, state.ats_enabled); arm_smmu_install_ste_for_dev(master, &target); arm_smmu_clear_cd(master, IOMMU_NO_PASID); From patchwork Tue Apr 15 04:57:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051483 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 A7683C369AB for ; Tue, 15 Apr 2025 05:04:53 +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=AakWwIer6SrxVv7TACYnCn9+EApq7K2deGUXZTvNxIk=; b=Q9TuCLKO6KVEmLj9d52Q4Dz48O dvm6dcsJt6rYIZ6bSPe/vdrEKYspZs9Yu3Ih5yVKC4ej6PE6ZBMg18eZaNVc4ByqDH9ljobeRjzVg Bi8EDwPJk8IFPbLsfhm5wpSacVXmhR0pw7xT/d7xQhU1QkJSFRQQwmOVpY28m1SMaMif03UaJoce1 hjaNFG00esQis8qjnW/N1QRIEo7d2pAMTdJZ79E2f5x61MXtpC8+AMBL/rT3R06Vtn1D5dsSqB9ZT H+nCe+KXkwJ7VIQxEV83/Lz2zp7EXMMHswqqKm0eW7gpdZUoXYMh+ezMFlVKkOWJH3xtLVyz0Dmrb ms8tt8YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YTU-00000004W66-2Bo1; Tue, 15 Apr 2025 05:04:44 +0000 Received: from mail-co1nam11on20610.outbound.protection.outlook.com ([2a01:111:f403:2416::610] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNR-00000004UsG-0bC1 for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S6SQEYiPeJDhxvcOC3SbmfZRI385oqf5IAKUTeXTjTzQeLGpAortlOziZmEuL1rC7xZVTiOzi0R/MsNPLCTIXiqHj0IYBGvRHpsqk7sFWcvLENOuzvZGvVsq7yrcvGJdAUYOznD1MXE8AG4Og+VGgPznVzuPYjIYI4Dz8hnTUTaIqOQYdpoRcK9kV7boXcMAoP383Qxl60myxqtlqo8HbYoZ8eglEDuyYXHKRB6ZV5x4+VbzqNuwxW9txzczS9bGQc6TpOlF4UHYv/Vg/ORh70B13Tjt7TLs95epbKoHBuxtyggFNpB/1HhuaF1yQQFi6+DAqy2XRj//QUMPqy5+wA== 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=AakWwIer6SrxVv7TACYnCn9+EApq7K2deGUXZTvNxIk=; b=mLgEkpZseF3t39N8u96C3JdpTT/Ka7CL49CdccCoba5IF/uBpD4cdmQpFCQ1laqeNQ+ZlKWGPZuww1NX0PWth1uwDi5fmScAUYfG4iu25H3yEJhIJv/NyCcmqI+/ChW742c2u8EsipDX4XhUBqDUyYddxmqMHxZ4EYTvUNfJFlx8c/yavijOjjCTRYmToNaYCJe7UEQskffb5YaIze4HP4CAw6Qvu5zknPTKefa2O5y7meexkU7StOYGIyxitcc7M6CxWuaxQ1TdJ17pieFccDJ+i+dr6+MS6SZmMEpsZyGlAgtGyi5PkeSYziOPy5333/mDbCl20+YWFhetTBPtQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org 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=AakWwIer6SrxVv7TACYnCn9+EApq7K2deGUXZTvNxIk=; b=gdeMOP7dRzJEUKXiPDiTxxtiQLkEs6ZNBldWbN2A/NcANQRsKGlbSYD4QjC2J9rVs94T/wBcSzbOu9UoO4hO6AMgCmmlh+Pa6sPnTrYTIEYDVpEXlWGZpDTmm/5e2BbIA8i7ViOXRX+GbuB7Hqvx3XIHyWu8mxD+sS952f/y/6XvZmqNT8+D27f0rqPzEN6AruQ2DNciiqXLVBcq4GIu2nFc6p9Z2gBviLj8xfq4r9uWEI1JXd/mw7SoYJ5fAc0Z4MaMZadw+1/fNi2TrmJQRb761JFsFqqkaPYqPGV3RuQka7u7a+OIyPSFLLvn1kXYLk80lyyuqejJdecfpzl5LA== Received: from MW4PR03CA0230.namprd03.prod.outlook.com (2603:10b6:303:b9::25) by BN5PR12MB9510.namprd12.prod.outlook.com (2603:10b6:408:2ac::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.35; Tue, 15 Apr 2025 04:58:22 +0000 Received: from SJ1PEPF000023CF.namprd02.prod.outlook.com (2603:10b6:303:b9:cafe::40) by MW4PR03CA0230.outlook.office365.com (2603:10b6:303:b9::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.34 via Frontend Transport; Tue, 15 Apr 2025 04:58:22 +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 SJ1PEPF000023CF.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:22 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Mon, 14 Apr 2025 21:58:11 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:11 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:10 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 02/11] iommu/arm-smmu-v3: Pass in smmu/iommu_domain to __arm_smmu_tlb_inv_range() Date: Mon, 14 Apr 2025 21:57:37 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CF:EE_|BN5PR12MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: 898d9638-4163-4a31-5a74-08dd7bda25dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|7416014|3613699012; X-Microsoft-Antispam-Message-Info: +HU7UvY9jjvq6eWFoslFg6sAomDh4mVPvmg+/vTqFGo8DIqDBr+eomASEgLGRC/9ipY9A8JESj3IL/iAvvz96Ls1C3ZLXLUu08KpEZEwtJTIE8ITXNgk4pkRSxbKtqUiteFf1bfuoKOP/bTihfGG5OZpdKhFXXdlpDYUo3mA/lbfEs/5yvqxZybXuVZO3FzahLIgy9HpM12yuMPQfVeUZEcphn3VFdBpK8+9j54Q/iYJaXwgy7YWcUdYbztCxPy4MVt1nwIGR8GgTHK8dy7ppwcN8sF3B6OTrhInaGPwj+r3GtqfeuE9qG3sadO1tx8Hab020SyBFe0KLIWcHi1OixgEmUeAhJN/brQ3CO0fy8OhcQ4Yviu701K+REfWMnPgGiV9fT2W0nxYELKZyS0QitMuq1pOta867lfvMRGTm1XifS1NrNBGqs1h3d6rZlfK5bleGmCtw72s0ZKQ5g95+ua7wxCUSIZntkf9K1CmY1Wj22lrnUjuWm5//zpPUWzE0mhmjOoLApF8TAiVuUBkaIlkYA7Wg8R+0awhHYtN/VcBZLsQgds8ddizvKwneiL39S0hVTmhDE3Lkd7nzBiEgejgcow3SZEoFJFoyk4GzxyCJjq9mvCpUXGw3S2Eafa4xgt+tsqLiipNPPtaP8pIpvXkIc+BACaDp3FkC+lllredOE9Z+VWpBa9HAN5qMftSmRJCrNj+VjcNGZtPvKI6o0zuC8J7et/TBvnR7BEEvh8wvDdIcelpj/NddEElO3QURs40v06kPzzsD88iDHmRkxN3kZ9nGcnCH/LGnkOV/Pqk5TT137EM7wKYMUbv1O5XiqKMqqi/K1PbWP+Zm1kUqwXJkmJ2DnpIU1nJDWyFaEy2vzdAY3o73bjuEEGGwKTyPlgW+ciNNmAHzDNY5h6ExPacjMEoaV+/YW8eBja5yEzJCTXyinJPHZKF3mLsyuaHTtejLS4DbHq2Gr+dnjpFXjIatrCNUiXuiyQvaAlLM+LLEH2caOpH8xl3J9ETbMmIAHxhImsH48766alsJqSswV6K0WBi6DhFNv3yXveJ/EaMhgEfeJ0O3PIQ289oh6yK6+IIhsOFpmHXN2gnMPqhhkf0/ZowW7m1Wnac4nm49+xfm7E80ENZTeG0/3Z6YUvyjrsP8VBZmdbw250eDVmh8yphma39Xsl0kcbzxfza/MUGxc1b0kvpofq7Ad6S4Oi61ri6re7oam9D4vmeN/iGwfN8ezZp3s5nflFJg+vE/vxnClP7DB3VfSZCXcW5lww9wMvOJl3zwigB5eXElHueVQrHFccmRZ1wi7YadWhbHW6SMFDHe+MmbqL94jYHnaIZrFbLFynonuDu3us0b4lwaZoM04Qr68LRzxDMonyQCkutyez5t4zAecc+ULPhH9X6fYYn8t3AUxq/Buc48Hmng40dZuO1dOAfolMXWV+nhiI4BJ1Mru5MuWoPaZv8WDJbsKu/UM188iLFrRKdrsELbDjJFipqMk28FOzYth3oZ8jh0FnRMJ7uXraieVxgEt7E8/duryGy4nRQDTXHctWiKXf1BhphzpCBWCnPBuRt9fw= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(7416014)(3613699012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:22.3579 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 898d9638-4163-4a31-5a74-08dd7bda25dd 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: SJ1PEPF000023CF.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9510 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215829_181396_0D35B0B6 X-CRM114-Status: GOOD ( 12.76 ) 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 What __arm_smmu_tlb_inv_range() really needs is the smmu and iommu_domain pointers from the smmu_domain. For a nest_parent smmu_domain, it will no longer store an smmu pointer as it can be shared across vSMMU instances. A vSMMU structure sharing the S2 smmu_domain instead would hold the smmu pointer. Pass them in explicitly to fit both !nest_parent and nest_parent cases. While changing it, share it in the header with arm-smmu-v3-iommmufd that will call it too. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 ++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index d4837a33fb81..5dbdc61558a9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -955,6 +955,10 @@ void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, struct arm_smmu_domain *smmu_domain); int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, unsigned long iova, size_t size); +void __arm_smmu_tlb_inv_range(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_ent *cmd, unsigned long iova, + size_t size, size_t granule, + struct iommu_domain *domain); void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq); 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 1ec5efca1d42..e9d4bbdacc99 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2267,12 +2267,11 @@ static void arm_smmu_tlb_inv_context(void *cookie) arm_smmu_atc_inv_domain(smmu_domain, 0, 0); } -static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, - unsigned long iova, size_t size, - size_t granule, - struct arm_smmu_domain *smmu_domain) +void __arm_smmu_tlb_inv_range(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_ent *cmd, unsigned long iova, + size_t size, size_t granule, + struct iommu_domain *domain) { - struct arm_smmu_device *smmu = smmu_domain->smmu; unsigned long end = iova + size, num_pages = 0, tg = 0; size_t inv_range = granule; struct arm_smmu_cmdq_batch cmds; @@ -2282,7 +2281,7 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, if (smmu->features & ARM_SMMU_FEAT_RANGE_INV) { /* Get the leaf page size */ - tg = __ffs(smmu_domain->domain.pgsize_bitmap); + tg = __ffs(domain->pgsize_bitmap); num_pages = size >> tg; @@ -2356,7 +2355,8 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, cmd.opcode = CMDQ_OP_TLBI_S2_IPA; cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; } - __arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); + __arm_smmu_tlb_inv_range(smmu_domain->smmu, &cmd, iova, size, granule, + &smmu_domain->domain); if (smmu_domain->nest_parent) { /* @@ -2387,7 +2387,8 @@ void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, }, }; - __arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); + __arm_smmu_tlb_inv_range(smmu_domain->smmu, &cmd, iova, size, granule, + &smmu_domain->domain); } static void arm_smmu_tlb_inv_page_nosync(struct iommu_iotlb_gather *gather, From patchwork Tue Apr 15 04:57:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051486 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 AE7ABC369AB for ; Tue, 15 Apr 2025 05:10:26 +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=gFq52igyDoDFLgg8qEdSuk0DTG7Xqi0b4EZGCo8EvHE=; b=prkWsxXkRwtA7FfgCNyoD8x1OU hogRa5evGLMTNOQ7w3RU12udZaFFfb0hEbJdOD/h9QtH7tRdC3nJmk6xhICRgIULCjHZ6cTSO4+TP oHgrMSHUb3xrN1RQetp+mOqlRoZDqRyBHZCMFDq8ybOJxPqH7kNI9nL19GiJy6a+IV5ceH4XRwODc PuCr0SbUu6hG15q/AktPrIZQiNg45k3UTTrXr1bM6ErNJ1/2hCCAG0T4UaN4Klytd8BFL3MdYgAR4 HZcXzZA6tCx0ec7pZDkqKmnomrv5uuGEMz+gHV6aNZb+svXpuZm6b8swYIoXN5/KCALXnpbRj5VBX CW5K9Ddw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YYp-00000004WWi-2f6J; Tue, 15 Apr 2025 05:10:15 +0000 Received: from mail-bn8nam11on20606.outbound.protection.outlook.com ([2a01:111:f403:2414::606] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNW-00000004Utx-0Wr2 for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rSjHPDjn6nOovPxTQzOg32ssaGbo27XJrchDKdCnoS8VGeW8VRCF5YrQRmleJPOqqPlslQRKcOZiZgFAMx/XSY5xEK7cJIgWycGgf2OCp1ys4F0Y7SDBd4EuySADbmElS7uqNzaNnzHc0CrU5x3mK1DeYWJFN3BADgAlEs1lKAV4VvemXa+kwyA8sfyK0a/wrdomTlxpdxJK7GajETb9pvWVhb2P6vThDvQWRI7MOPbkEZF2GKVqPwqdgEsRuzGnf/Vb6EOP9iOPZyEiG1Ov354kkckBWuSiQnvLABZJNaZmpS2R2hEwJmB1u3R8bxdLNpEFaDd2CTSkc39mFR2I3A== 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=gFq52igyDoDFLgg8qEdSuk0DTG7Xqi0b4EZGCo8EvHE=; b=S/6j6EJLE1DxmFOWXNz3c2f0BntvThnM2s++NwwfHPYbMg2VZRWk03IbbVo6lCLmAM88Hq2uHBVUiV71frJtSlIldFONv55mOXDydQ7SLKD+DRguv1mLw5Ak/nlPqMXXtsGmbqawl+gPXFE66HTs83vLUNjYQeTxtxVGPjRRYakJkq4WVP3SH4SB+1SdJl9oDhYDKmmsWQNDDFqsECvZPcTiqpmQdh2wf/TBq2VL5oYK6qZs/nbzvLjH1Qq3vK9qXO7ZYB0BVMHJZuMkBQdW2RtNME5jOkDRZUabwwkNefCUczFyM2WJlt3CNlDvASH/akUuXBV2zgUNaqFnZ+JI1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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=gFq52igyDoDFLgg8qEdSuk0DTG7Xqi0b4EZGCo8EvHE=; b=ZQGhVtqDYziVgAyDYxVWm0J6SApmr0SmeAcTKf9BHXfZXA5iNYnEImB0t2RB8kXpf+SKrc2BUlnGWWPNF/Tf55Sbci0Oz9InqB+Xcbi5t4I6mZZC2wUhDV/1/ufNN/4EqP6Vkk+Va/HVUz/U/ZnYh1CFUpy9IcGGj75fbBD+h5NCB7kmzqqBCZMrjtnZEY+QoJNlk67FK5YE2oW05ylIG/V+V4u+6kb0a+T2Eo3ATiqowIEkZ5hYWiqWvoydGzRL184mTD3iA7ysmqGocT5iYfTCFEEfwvmUGuN+C13mGrzPSkconF7/ucxRRtupsQgD63hcc/6kgOaTAX/Mo060gg== Received: from BN9PR03CA0238.namprd03.prod.outlook.com (2603:10b6:408:f8::33) by DS5PPF482CFEB7D.namprd12.prod.outlook.com (2603:10b6:f:fc00::64a) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.37; Tue, 15 Apr 2025 04:58:26 +0000 Received: from BL02EPF00029927.namprd02.prod.outlook.com (2603:10b6:408:f8:cafe::f0) by BN9PR03CA0238.outlook.office365.com (2603:10b6:408:f8::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.32 via Frontend Transport; Tue, 15 Apr 2025 04:58:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF00029927.mail.protection.outlook.com (10.167.249.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:26 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Apr 2025 21:58:12 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:12 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:11 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 03/11] iommu/arm-smmu-v3: Share cmdq/cmd helpers with arm-smmu-v3-iommufd Date: Mon, 14 Apr 2025 21:57:38 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00029927:EE_|DS5PPF482CFEB7D:EE_ X-MS-Office365-Filtering-Correlation-Id: 763af0f7-64d4-4e17-c72d-08dd7bda2839 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: uVVtXMUNRnNPyKQoLJUk19CgAe6jTDMlbwWrF431H0aRe1aPK4coK/H5k34yG12Jocu5Pxys/IhrLGvsVpLy3toVpSNBfL9VEq8wXVqFCkSF+YuYSVy0HcC4UAHd3QkmYfsVum/8GyiE88EhOVwlGdtdQU0PrVeiMMyguSAN020S05tIpLarllQDwKjTAiSwaID3QkRh3D606+pFhEFuyUYVUbSwhPgbFD/5EIhg8011AnS32H5VIzYcCmAK1+vtymtolCW0DKa7i/ouEkTcqpn86LVbc0dzCgXGaYyrJH6WWMe/b0wXu+FrMYY7MKBhpoj0s0chFM5Htd2CHq5v6PPLKNLak630p7ICn0WQyWbbP9LlJt+GrMsACINJJgKhGl2KpNj+O1YEmoq3qXih7PLmvXoTLL2ErBN1dD6PTUBgaj6dRyP4zwK1qygJnYkRQDA5lJ30KmC2SK7hOpg7N1e4Kkru0lGw90XpFKDXaVAq9ERsXoFd8dV4FeKky2oiiUckdMdmHZfAj8lmQs9woLLHDl8Enj9rfVS0KFlMm8+V5xhTln7Q0t7mKXg6BebJeTA/y2/8iOPnxSb6abw9w4BAoERrM/nGsuOaqwjqkcCxfzWyKlLD9d7Tk4hcklrjMFLPIJsjzuzh0r7RncEEaV3ueJVrRBN79l4s7J9XgQrP1kj6TiuVX4g4JJ8aP6i3LdGuwauV9YxWBPw2IHAJqW9kG1WK6VAKFC1cdHj6sCB49/1isgDvZZDpFb9382DpZS1b054soh9f+mq45ee4GFOxK5L+EsJsV5beM/znomQ+RFOpZgwoiA6MnsO1tf6HgctrAoEjnTFhD7sJ1Qlc/OTNzLNPKuNJ3RQm5GrATuEw12oYbC6EbMZc550T9N/O5Q7xK5htn4urcVUyY287+TLPh424Y+JufEcKvuuky9f6Kh5QK1P+WazdU9fzyccu1JKb53Ne9n5DC3IzVAwDSnSqz1cp/aCDHvcecJP4qKYhs+2STzD6KKSNZQz3TteZKHhpOXO96Iydg0rYQhXLM6BJ1RjDzNmu+/GhmQF1tFZ+sPBfOVpHxSpRi2LBgBLCEW66QaAywqygK7Xmh6VrzEBLKMDDZAyb4MY4B/PVlNK3fa//IoNnr4SW4RFbaQoG//0zh68KcnL9qZbl/lv0n/d3Cqp92xK8xCT1sagEexxa2HGdMw21bhRJrXMLh8EmrfUMPZlyx1wtEN57YbcvlquD0BtsuY7rAFBNhZEU8kELa6JVkcqFVwqby8l107kMgcApIKj0zXptKIhrdUT85KdI0LxDXfK89sH4NWxA67l4dhf+tCwCQEfp/2pNP2rfvz4fJjaMax3VrGMO3KTMve89Lkv9Cem3GJJNzOM9kjtgH/8Ki5lhocps1q1qcrDwrpx/kETupwEsVMi5b5Db94gJJSk0Nj8oBwNRanC5YQsSpxNjc+VFhyw3yl2P+T34jXV0x6KCmFjeEckTgSXleCzI+FQnkvhx/0AuVUsz6jMFYqBVW/OpJ0sgKL9v5zoW X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:26.2409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 763af0f7-64d4-4e17-c72d-08dd7bda2839 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00029927.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS5PPF482CFEB7D X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215834_181021_46DD30E2 X-CRM114-Status: GOOD ( 10.04 ) 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 Allow arm-smmu-v3-iommufd to call them for nested/S2 cache invalidations. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 12 ++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 25 ++++++++++----------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 5dbdc61558a9..4f3f4a40a755 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -959,6 +959,8 @@ void __arm_smmu_tlb_inv_range(struct arm_smmu_device *smmu, struct arm_smmu_cmdq_ent *cmd, unsigned long iova, size_t size, size_t granule, struct iommu_domain *domain); +void arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size, + struct arm_smmu_cmdq_ent *cmd); void __arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq); @@ -996,6 +998,16 @@ void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device *smmu, struct arm_smmu_cmdq *cmdq, u64 *cmds, int n, bool sync); +int arm_smmu_cmdq_issue_cmd_with_sync(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_ent *ent); +void arm_smmu_cmdq_batch_init(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds, + struct arm_smmu_cmdq_ent *ent); +void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds, + struct arm_smmu_cmdq_ent *cmd); +int arm_smmu_cmdq_batch_submit(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds); #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); 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 e9d4bbdacc99..8ad249f7dcbf 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -929,23 +929,23 @@ static int arm_smmu_cmdq_issue_cmd(struct arm_smmu_device *smmu, return __arm_smmu_cmdq_issue_cmd(smmu, ent, false); } -static int arm_smmu_cmdq_issue_cmd_with_sync(struct arm_smmu_device *smmu, - struct arm_smmu_cmdq_ent *ent) +int arm_smmu_cmdq_issue_cmd_with_sync(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_ent *ent) { return __arm_smmu_cmdq_issue_cmd(smmu, ent, true); } -static void arm_smmu_cmdq_batch_init(struct arm_smmu_device *smmu, - struct arm_smmu_cmdq_batch *cmds, - struct arm_smmu_cmdq_ent *ent) +void arm_smmu_cmdq_batch_init(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds, + struct arm_smmu_cmdq_ent *ent) { cmds->num = 0; cmds->cmdq = arm_smmu_get_cmdq(smmu, ent); } -static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, - struct arm_smmu_cmdq_batch *cmds, - struct arm_smmu_cmdq_ent *cmd) +void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds, + struct arm_smmu_cmdq_ent *cmd) { bool unsupported_cmd = !arm_smmu_cmdq_supports_cmd(cmds->cmdq, cmd); bool force_sync = (cmds->num == CMDQ_BATCH_ENTRIES - 1) && @@ -974,8 +974,8 @@ static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, cmds->num++; } -static int arm_smmu_cmdq_batch_submit(struct arm_smmu_device *smmu, - struct arm_smmu_cmdq_batch *cmds) +int arm_smmu_cmdq_batch_submit(struct arm_smmu_device *smmu, + struct arm_smmu_cmdq_batch *cmds) { return arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmdq, cmds->cmds, cmds->num, true); @@ -2096,9 +2096,8 @@ static irqreturn_t arm_smmu_combined_irq_handler(int irq, void *dev) return IRQ_WAKE_THREAD; } -static void -arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size, - struct arm_smmu_cmdq_ent *cmd) +void arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size, + struct arm_smmu_cmdq_ent *cmd) { size_t log2_span; size_t span_mask; From patchwork Tue Apr 15 04:57:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051492 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 442A4C369AB for ; Tue, 15 Apr 2025 05:17:47 +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=8GCqDJH1kkCEcAFWw9l9byvMiEmb80U+yERkuDuiHP8=; b=kUQtI8u/s003w0FFtJraqteDU8 gPwbL//P7jUXWTtO8tiY6+Q78MHJwpDz7GAnDsKiSQl/oI7hUCv4nHlhtO87u01wGJmuZCJHEik5w ZxbwjowLEe1Mz0RhWUjzigJ7jtkeEatccbbR9KOYMf1C4k5R2UWr4nahvaG5ANcVq7dj+HPmpP81r acA9KopOQ8gKtIinzo77YsOL+L1FLzrF0wPbkP9tZPbw8bqhF8fMdSq10EdGKSLSRuv17C4l9SpC2 0eEmtnEB4ieV+cwgr1xj+/Xiv49lS8vDJ8+i1UzNItOE1P1qcPK6X2WfvQxo20/bSuh6s23ketHQT YI046Iiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4Yfw-00000004X3R-2CsL; Tue, 15 Apr 2025 05:17:36 +0000 Received: from mail-co1nam11on2062c.outbound.protection.outlook.com ([2a01:111:f403:2416::62c] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNZ-00000004UxE-1b1d for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=keIzn/PHoSluQ0XZzQdsMfIk9ORsXwmgs/NHkJ2QzNIT3rbPBC4j6zlq5FztAlUoJ/YKjPcGVQ4kiAI5L/AEQaeWKkWcrrIeEQfAa63m4xvQdpREDJ8o+fCj+pyYjACPoe8my6jO/qQmlD3Up45AxTMjAVRGO2C2VidiKVVXYyeRHjdrqZxKlRCUUdXliFhs86r5I8TLo19hlt0P777gPUs5McEPWLr+xaqCiWUXFPNJivFvg0XCs5a0Ug9mGPBi0M45Qqsgks11NqbMn6Q5sYILIJ2QDc4zvMrIcRYJu7Yqy9YdFy6117ilb2L73rdobI+jv2cVrktWikKpv1p1Uw== 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=8GCqDJH1kkCEcAFWw9l9byvMiEmb80U+yERkuDuiHP8=; b=sS4xfqecuCWjAEJZPA72s3TFVpCdvoIGtp7hAKNc9cM0cRTu4bzdiXS65+g5Phe+MlRjKfn+oh8aQ3H61UZttZLX+W+n9Pn/hrLIUOz0hiVR87+st43OdgTp5yz7GfAUDbCSUw4letjSpwnDQEKmPhE1yfmn0rEm1Km1sMts/OHy1EQ/RhY2iJ9cJgAYYiHw2xYArSLWU/z+YiV0iln3XTTe+6+8SOzfcvGZpFFqmU/WT08pVAcmAPlIFuzQF6tYd/YdE5JpwlbbNC9KCut9bRvyX6fiCPoKTNEGy6SkziDGqtvGUfPwIGYw/lFiPDJbTl+x98FiHXRCOdkkNtdW6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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=8GCqDJH1kkCEcAFWw9l9byvMiEmb80U+yERkuDuiHP8=; b=QTcAJk3Xw/uxG9NFbV3GwuJ3oSLtBThnKQFrxG3fZST/C08mBQAxCmxCmupTyzvltrTuQUmkTTmGzn7py7wIOkSdzyr3x6KTN41+J2lnb/N7r/sVQEKpYPJ1D8yTLYQoOCEVelFDQGV8mEdrZo+jdemJNUhY3E43hlYEqNQtBUOMmRUooJKaOl/J/RJz10zFLMINuSrP6AeywcpZNQyUbXPq1sOYvUneEx4ejgRuLg+6o0PiRAYUC98v8IcK+LXriFZtGB+JTjp+O9XJt06xFk4pwBsVTXSogRPBVJ2nvblKbEK05kTfZ5B2bkAdqQS/tPyNDkbYVeD0/iyxJuavCw== Received: from BN9PR03CA0240.namprd03.prod.outlook.com (2603:10b6:408:f8::35) by IA0PR12MB8748.namprd12.prod.outlook.com (2603:10b6:208:482::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Tue, 15 Apr 2025 04:58:28 +0000 Received: from BL02EPF00029927.namprd02.prod.outlook.com (2603:10b6:408:f8:cafe::63) by BN9PR03CA0240.outlook.office365.com (2603:10b6:408:f8::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.33 via Frontend Transport; Tue, 15 Apr 2025 04:58:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF00029927.mail.protection.outlook.com (10.167.249.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:28 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Apr 2025 21:58:14 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:13 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:12 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 04/11] iommu/arm-smmu-v3: Add an inline arm_smmu_tlb_inv_vmid helper Date: Mon, 14 Apr 2025 21:57:39 -0700 Message-ID: <95acc4e15f1bc6ee7f08635f5c68d7cea625acd2.1744692494.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00029927:EE_|IA0PR12MB8748:EE_ X-MS-Office365-Filtering-Correlation-Id: 516ee6a9-8f8b-477a-e185-08dd7bda2957 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|36860700013|82310400026|3613699012; X-Microsoft-Antispam-Message-Info: +VwbYETChGeoLtT6gRWUqwc6Femg7GVCNeFM3DPXQiw0icyAD76EDAaWCWbXNaF0uAEhH/oqXO3YdZgeHSDJ5DX01mU7/p7WPG5Wl2hJ9lHaQ+GlGUdr3Nj8STf7KisIL4jSGnvN3uWAYopv6W3Q6WYTbC66fJTDWOhq31U0pyCsUAnqXMiK9iH/8KOvwUXeGp4u5qnhOD2JjPzg2zWAFSEMcx7RbQyGASrnnhMNsdasr8UbbPNG03AqlQu0L8ajj65+IOKLgXsooz3pc04h0WQZV8zCe993UTGoVDgdMcsPZxaogGISKEt/z0bMic5QZvwx+bv4xxIqCuYKOsV7tAuVeGQ1h6G3YGF/X+9dj8UVHQ3S1G/d+5JCQu7X12vIcd2uPo8lRAORxtZ0MNyvEN386jLN5STADTfHMQjubFZFXvKFNscd5vybQVZOWoWNBK9XVGS4qGZempvEve921Sh9UcjouiqJ5cTHredtYiYTq7euk801g70RSuIjX+I2NhT12otqjPl4vav6hIkEIdZJg9lxTRtqDK/2H8v6jy0MplpgaCpLqu6ZWBjaaGEwmeZjAYloH3lU+HQRIgJ2LSdht03XUAVD6yt6r0iwhKnqOlLMBFHp0Ele/al9RaeJ+jigq7XA4flqiWQXeYLAYC5pvCsaKO4cNLAIf3/P0kpSLCLbbbS6/D3Z/RcgAGjG4G8dJ0qQBbkmPCPMCEHAwd6Khf5F+quU5kzOvL2pm9VyhUWGOwmiYUwnD08VT0G+lmzD9NzHv8meWLMN+Om85/y6geGc/l0RNYN6lS2Pj57tZz4BTefX02c5yewrIPqFb7oh4wqkqyHuGrgRbwRAOnj2k9oVP4NYaUl5tpzZ0G4IR8VA1xx7nupKpy5zlPS1sL0eNKwQhxcfLIsb4KhsfTnRgGmtvADICJqfaXk8tQkxFcEF8d3RtbX59q2A8GvR3ZFzEKhzY1jCy3igxLkopIi1Xr72Wxr3n2BUbKmK2NHKiHHpKZEZdOaDfMRPDW4yNsQ00ebEnmmnNDF+rbJymWaHxEy7VCFU9dhkDYf80D5YA/XF1/hwrxxlnSLKrRKSKvQ2cIh+hxiib08z0fIhNG1xg9hKFwCz/ewQxuXS0iihXYukN0hDR8L6MQ+fB2s2DXkjmvZqYR24qFcI3pZhYFsWQpZrSLGqMpqB04NltZqVtzq06o+uGcl2sCCVNimQNEahUj8rkFoAHZg8fJeOdSqiRk2H02M97P0ej/Qto1WJgxI7Ga1c4j/W2K0pA0dcnEVR+T+QoBfV8faqU6/M1c5S7LKdcnB1NN530nbPvBYte1LvpYpZPPWEPvmSvky9wGKbn3Qf5p+6QZNxpyybmz0LnGNBRJWvfjGXh9O/jVbwCh7+E6aKqjFgra53NJ2vK6AetoiTFps+1uFCJuA8IkhxE+S+O2CQ+c+c4N35c2ZP+8BtikXIdEmtkg3Hm2hUB1ZVkgmhJPSeye2PvhHPVkZD+Ez8fkHW2rjY8PVbz0JVtqYsDTYSjpBd3zGHH8z1s7+MZTG+M3mT2TcYzjri72PJeKPCkoMTcCv/y8C3NR4= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(36860700013)(82310400026)(3613699012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:28.1159 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 516ee6a9-8f8b-477a-e185-08dd7bda2957 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00029927.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8748 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215837_415028_4FE32AC8 X-CRM114-Status: GOOD ( 12.91 ) 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 Both arm-smmu-v3 and arm-smmu-v3-iommufd will use this by passing in a vmid from s2_cfg/vsmmu. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 +++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 4f3f4a40a755..2f8928971716 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -1009,6 +1009,16 @@ void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu, int arm_smmu_cmdq_batch_submit(struct arm_smmu_device *smmu, struct arm_smmu_cmdq_batch *cmds); +static inline void arm_smmu_tlb_inv_vmid(struct arm_smmu_device *smmu, u16 vmid) +{ + struct arm_smmu_cmdq_ent cmd = { + .opcode = CMDQ_OP_TLBI_S12_VMALL, + .tlbi.vmid = vmid, + }; + + arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); +} + #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); bool arm_smmu_master_sva_supported(struct arm_smmu_master *master); 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 8ad249f7dcbf..bafe7c7c2769 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2247,7 +2247,6 @@ static void arm_smmu_tlb_inv_context(void *cookie) { struct arm_smmu_domain *smmu_domain = cookie; struct arm_smmu_device *smmu = smmu_domain->smmu; - struct arm_smmu_cmdq_ent cmd; /* * NOTE: when io-pgtable is in non-strict mode, we may get here with @@ -2256,13 +2255,10 @@ static void arm_smmu_tlb_inv_context(void *cookie) * insertion to guarantee those are observed before the TLBI. Do be * careful, 007. */ - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) arm_smmu_tlb_inv_asid(smmu, smmu_domain->cd.asid); - } else { - cmd.opcode = CMDQ_OP_TLBI_S12_VMALL; - cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; - arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); - } + else + arm_smmu_tlb_inv_vmid(smmu, smmu_domain->s2_cfg.vmid); arm_smmu_atc_inv_domain(smmu_domain, 0, 0); } From patchwork Tue Apr 15 04:57:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051487 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 A5445C369AB for ; Tue, 15 Apr 2025 05:12:13 +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=/uq+7w9FcbqkqiuGprKBhaIHnq87wEEktyCmxauxDN8=; b=jJiMed/OtYrxG4i3juQW8Vihsp DAeeB9ioZWq6iYONfl3xiJqHbLIAAN6yeBRmIm4AedLJM/APTNSRNMI+/HOBGtOcST5WEp7XMLtbh KMoj2wMy5zEf9lzO+DwMzS6MhcrJq349bnuGkUPqNQydZ2VVrLPzMjD8HJrxKJS/pe7WT4difDrxX a6IJSZz4XxkggE3deX1D8zGV2mpW6a1Tb8S2rGkjtQUg91iIV75ZkuWWikE8+IbZfvg7e7mAmme35 vCUtu1jM6NM25DiiGgN5cUmKmvbKbp2wqeyrfrodryPLOoLmdBrITq+OI4Kosx5Mci21xNzqUGQ5I bNAtspdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4Yab-00000004WfZ-1mw2; Tue, 15 Apr 2025 05:12:05 +0000 Received: from mail-bn8nam04on20620.outbound.protection.outlook.com ([2a01:111:f403:2408::620] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNW-00000004UuK-34XW for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wP7zFjBsXECXV3R1Bg9Jm3JxWNRP+BqCiUU4k9xu7mG9cuyxIcBFWghz4MokTan8cA6s1bX88P/vttfrZQucNw05y70DWTR7LwTyWZpW4SEDqsSEwFpzMvM58WUVCA4bjtx5rRTRjVV8y3ZvZ7U5E64DW6N4YZRxMBcrl0pbNJNM74oG/tNzDzPZkxbWeM3ZrfDHK9ONdSi7pLn8HqiJDdYWtMnhk8D+rrFpaaGVaif5lrguamGeSj0poPumUdzjYBoMKTTX6d7fSD75T+Jh2v/YizzUavYTFN2UJAFDQJECfhJcYutayYheusgGUgo4TOCPWKsQDTjAAj+ZKe3/eQ== 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=/uq+7w9FcbqkqiuGprKBhaIHnq87wEEktyCmxauxDN8=; b=ILi0kUvqc35Q4M5XGCOBNZnkjsHvc3p6ohlk5fJu2+YxKwgwHY7S2ovrnwzgxWoz4Ss3wGxugyiPo4TcA5Iwj6VX0H0r8IA3qxJY0c72TDxWK/NOK9MLOx4Y682oFXqw0GluISIvewyIW/9EriSAvN3FKH1GhMf+0p3KuuBeCbSR3PE3QQfTz0P56JeZijJvEB+LC+WbzVey8eOt5wjAojdIjyA1lrjTDbPiztQ/3Yrn/SruEcD7wWJK6eCJVW1+bO8v6l+mEOJWd6fTbz+5ezI0ftPViDY6IZ1SLQHWE+fAnY8Tv2HoQHu0aDMm4B4CdLO4GcqWYIKHoQ0Y0VZdBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org 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=/uq+7w9FcbqkqiuGprKBhaIHnq87wEEktyCmxauxDN8=; b=kWbbqcbHdCRDzqrGpMo8AovJPAVXMfr+3pNkq9PKDNw4qSfdsTfzWVTXXETZRa+1kgEc583SqPFFa9/Mu/6WCkFOhq8melBFy6T+XoKR/OnSj4tFxmfJeN0+Sk1Omaf7C0GCZV6t2k+bLrjJh85jTwaUlYSHHW5FCkTRAoNMBDRtqI64knAdjZ9OYY1Hc/JNa34uvlLLqpc6ymglj21+l4DjweelsADTLmPXN44ugkUaloqq5c/EZ4dK6jZP3BfT3rpBqnYcOT3LzAvDmd1f3y6czijF7qSm7tig62+77qLXNkqCU0nvYkmNEvqpbiyUMQBwRYKPM2fKXzb2Xn5VfQ== Received: from MW4PR03CA0223.namprd03.prod.outlook.com (2603:10b6:303:b9::18) by SN7PR12MB7953.namprd12.prod.outlook.com (2603:10b6:806:345::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8606.46; Tue, 15 Apr 2025 04:58:27 +0000 Received: from SJ1PEPF000023CF.namprd02.prod.outlook.com (2603:10b6:303:b9:cafe::ac) by MW4PR03CA0223.outlook.office365.com (2603:10b6:303:b9::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.26 via Frontend Transport; Tue, 15 Apr 2025 04:58:27 +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 SJ1PEPF000023CF.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:27 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) 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; Mon, 14 Apr 2025 21:58:15 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:15 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:14 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 05/11] iommu/arm-smmu-v3: Rename arm_smmu_attach_prepare_vmaster Date: Mon, 14 Apr 2025 21:57:40 -0700 Message-ID: <18d99aa79a024a80b51a821ff3dacad8f7276969.1744692494.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CF:EE_|SN7PR12MB7953:EE_ X-MS-Office365-Filtering-Correlation-Id: c5edb401-f33c-457b-fbde-08dd7bda28e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: OvQ2vkABlAmmTXlCPrunUIeW7r8hxscEOFqKDg/D6S4PM/hXM0TRwuxTmTvU42xMj3D11gksCXXmEpOvPZ4VQtZGoJqw/XgPamGEJg8l0hLm+djl4CMBCceNC01mX0yY/1C00GBrnCpUdRPTzBgRhqPYy/wsI3zucVmU+77jafVlfArzXH4eoZnTIVEyQy+5ud1EXt+6zbA/3da7sJZa4gKCU99mFJMUZ5+9I66jBGv+1OXfkcXqu+RKDuvmX6xd94t8YAq9UY/kpXmqlH6yp76AbicZatlRXMV0t7YP4VwYp0MVK8gATWrLqfrYmk3dHx+1tIATsQ9eFXRC/28mJZ+J75yupp/56O5cg8UhPyNdAE+dJaUvk4EpWNfAChUAEn/mT2Ne88mmHrJ0CdKwjbd9djQi+lpVDMidL150WJQyu82IMxtRAtZl49U5dIxj8oOOeHxjOO5ZqrfiEHIh1c3OQiFQHqeBf5ssmgiRpOv+9uEb5tFTwENCuHwRncnJ3Zc33cOr1+2PhwjercqG2hdjV/VVAER1VMSQTRpC1FMi70vl6Kl1ZeNcdMjNaCbS88oOxEShWCyEVKi2Z1TjbmHyd5cULVI3Ei+X67lXxlhqUhjqiCFnj1EyGViFnTBargZXMik4/Wx/j7BpmOOmzFUZ3EVmgcD4AGxLfEDwFzCrAMcQwS9udal8LSBI9wLCx1TkEcKC7EWK0rSbd7kcpZU/+AxmgDmZjVj+dQm8qGKy4Qx6sziNi5G4m7XsyhjY5c+kJAtTpeMZ7mb1auB9/2+W+1Le7Q+FYGs2YB0c63imMDYmjO1q8/ZjSuLxw5O+fAGUnO3WLgfEpvWOXwEpHtvraqlje989jtfl4AT0lH79L30Y/PAcbUsYgG35mP/c7iVimmS/6+MK8/l5psq8i27AVY7EZExeiiD5O5nKB5s5NpRF0NAjyRY03MdmxZqjrZQsNi9zw+0TsLg8QJYPLeayJSAPYYDf2GW08cSwtdB9+I7HS2H8uSdudRnxq6cWMwLqxav21gD8+NTgLrMSPNnTIk4BwzV0ZXvZNFqqT7EYI7e7ajGsB5eWcc74Var0qk4K8PlAA4fmWs1pyjIgKv1jZ6O4N2paEwpn50zE5vzZuPazGfLtC71NDLA9kwMiFQLOf+lBZp2YKEsoiQNSgoaPKds8C/f9YfeWVcJk0xXyXa1GiYnDBLuc0APQvYcPzknZOKXWEOFERh6cMU0r+5bV3ey5HtNmSql6snWLUzIz6lqIqY+tXKpqqKqhrkrEYnSiATJ7w3TYm9oboAaPMCeWmn75tn1qbjAYhXkkmDSRGq0YFogPtK6yC220ziKBGeSXD1wxuzeqphJ8B4UPtT7CuK6aiPbqZANURwtp//I/QaMYMY+IEyJ7/XzrG0NVD0A8pIysIi+ly7eF/UAyOVtf0u1BxXo0STd3FhvVs3I+VfPvxe3lOBGnd7oWE4zsA7nO1Tmk9FnqWPJ00LGgdyS7sjpUZXoMk1+DgpcrwLQx1f4NwNLfu6uaIyoSyRPL X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:27.4672 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5edb401-f33c-457b-fbde-08dd7bda28e8 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: SJ1PEPF000023CF.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7953 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215834_763820_38970A3E X-CRM114-Status: GOOD ( 13.87 ) 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 There is a need of stuffing more vsmmu-related routine into the prepare(). Given that the arm_smmu_attach_prepare_vmaster() is always called when the domain is a nested domain that always has a valid vsmmu pointer. Rename it to arm_vsmmu_attach_prepare(). Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 ++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 8 ++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 5 +++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 2f8928971716..7b47f4408a7a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -1089,8 +1089,8 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, struct iommu_domain *parent, struct iommufd_ctx *ictx, unsigned int viommu_type); -int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, - struct arm_smmu_nested_domain *nested_domain); +int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, + struct arm_vsmmu *vsmmu); void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state); void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master); int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt); @@ -1098,9 +1098,8 @@ int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt); #define arm_smmu_hw_info NULL #define arm_vsmmu_alloc NULL -static inline int -arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, - struct arm_smmu_nested_domain *nested_domain) +static inline int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, + struct arm_vsmmu *vsmmu) { return 0; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index d86dba6691e8..6cd01536c966 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -89,8 +89,8 @@ static void arm_smmu_make_nested_domain_ste( } } -int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, - struct arm_smmu_nested_domain *nested_domain) +int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, + struct arm_vsmmu *vsmmu) { struct arm_smmu_vmaster *vmaster; unsigned long vsid; @@ -98,7 +98,7 @@ int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, iommu_group_mutex_assert(state->master->dev); - ret = iommufd_viommu_get_vdev_id(&nested_domain->vsmmu->core, + ret = iommufd_viommu_get_vdev_id(&vsmmu->core, state->master->dev, &vsid); if (ret) return ret; @@ -106,7 +106,7 @@ int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state, vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL); if (!vmaster) return -ENOMEM; - vmaster->vsmmu = nested_domain->vsmmu; + vmaster->vsmmu = vsmmu; vmaster->vsid = vsid; state->vmaster = vmaster; 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 bafe7c7c2769..07d435562da2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2839,8 +2839,9 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, if (smmu_domain) { if (new_domain->type == IOMMU_DOMAIN_NESTED) { - ret = arm_smmu_attach_prepare_vmaster( - state, to_smmu_nested_domain(new_domain)); + ret = arm_vsmmu_attach_prepare( + state, + to_smmu_nested_domain(new_domain)->vsmmu); if (ret) return ret; } From patchwork Tue Apr 15 04:57:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051488 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 9520CC369AB for ; Tue, 15 Apr 2025 05:14:06 +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=5T7fnQQ3IaEj29h5JN4p5siPBXQrrDjYGCJlb1jsRHI=; b=RZdmkeoyJq/XD6H3d9Nf7NtwMB KBuebecxU2gbiIwOZmH8QK4KaTvzTi0aPoi9f2H6ECyrZ3gDRdT4pEz36wTF/uR+f5e+KiuNhJq+3 twgmWGvqQb79OtnNYpj53TCKT6ReUz/HpcEAj2wE079nUr1PaMTTDt88dK4+B7ZBTa9In3nIlpLsv 76/0vG+okWnvozsjgZrgyerOyaVwYyRIvzzV0dCe53HDCIKfG+jP34nIm99GJmhZ17TP/+gmH92Rx XRK86T9wxSjw+xKE+7R+UK7vmCMtnq6Qqch+waPNuZ9ALGVdDHJv5aendnrUxlqTVQNj3xg58CQtf JzbeJFZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YcO-00000004Wmu-0Pn9; Tue, 15 Apr 2025 05:13:56 +0000 Received: from mail-bn7nam10on20627.outbound.protection.outlook.com ([2a01:111:f403:2009::627] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNW-00000004UuN-3vfx for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q7yGUo6l/81LVRntJ5mT9kXpXlfKolEOFDLUY6FVsVPHuTUyhpO8KRDqAqLJ4Fg1kTbhp4LYAK3rtL/aXQuXq5UKULIC6jAWvhaj/ogMm5zpmRoInSnfriJqa79c/Hk8xNWwoSS/LEgq5dc2WlNJE/LTVzydVf1t/fpeFLzlTNYvUhF7RiFo62egwOuXHyD36cdl0ogzPx6pJJlUMHg/AxunDc2zghGACT/zQiCDBqIAGYmkWAwVzrrcBZ97lm/K3f75YMr+i1Al6XEeBsxfrgXaxkjXB46Rg2sKJrrCnIDsBKx7P3Pp2TA4CMGRcdiaMnn4op5Fn7QT/gM5yXtZ6w== 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=5T7fnQQ3IaEj29h5JN4p5siPBXQrrDjYGCJlb1jsRHI=; b=c5xDq7EisHgdydv/HD6D2CtQK7HGKl7rRZZo+uCpu/0aUo3226Gn/EvMHgweyXA+AErTJhxAYx+bZQtXl6o5qE3p+lWr51NYkuNZZY7KFWlX5QUwurFQOhztoknCV9Tyt6BIH2gqvhUFNnvczztA6Ho7yIR83ric0J/FUO1NsUxQDETtGszxYOImcVeIq8z1d7fbsMC8XcnK6RQYaoJ9JZpRZqCkNxBpSCcmnHAh/3Oxb+ld/BQa3oQg1TGo87y5JL4mFaeJRTAKDfmw2vPHAYMHExA/pqteXwsd8/c2VnbZYstiDplSkhGurhJgLUWd9mykxCUlOCfIXeuJTxlR3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org 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=5T7fnQQ3IaEj29h5JN4p5siPBXQrrDjYGCJlb1jsRHI=; b=jFZHiMICKxvOfxOUQ5lBqVSJYPgW7FNQnAUg9U7xcH8iSz44VTVp0GHgYIn5hrQtkI6kTFFQTku3Rw896MYPKWzVNGmv3lFkn++YQ1/PeKZ5LTQVmOr8OpewAbUVbMQEaqqAqOgZRIw2uYhrAlGN641VY3HSL/lvggvToU2AkjPaoWFi3FqbpuM8QddEqIHG5xYNmCc3N5BsLhoMEjrJ0aFr6tSGh2QyRZqoOK+Wykc/b7DMvx1DMgoRevNsWEyDlCzvOApRjib79KtFQBcTOlPCRYgsBGhmFLY8gi9aymbPk//ssNy7Vqz/5pN+GnZqUk2lVP88LIGwJUMCwFp8rQ== Received: from SJ0PR13CA0037.namprd13.prod.outlook.com (2603:10b6:a03:2c2::12) by CY5PR12MB6347.namprd12.prod.outlook.com (2603:10b6:930:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.33; Tue, 15 Apr 2025 04:58:29 +0000 Received: from SJ1PEPF000023CC.namprd02.prod.outlook.com (2603:10b6:a03:2c2:cafe::e6) by SJ0PR13CA0037.outlook.office365.com (2603:10b6:a03:2c2::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.15 via Frontend Transport; Tue, 15 Apr 2025 04:58: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 SJ1PEPF000023CC.mail.protection.outlook.com (10.167.244.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:28 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Mon, 14 Apr 2025 21:58:17 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:16 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:15 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 06/11] iommu/arm-smmu-v3: Introduce arm_smmu_s2_parent_tlb_ invalidation helpers Date: Mon, 14 Apr 2025 21:57:41 -0700 Message-ID: <61fef9052b2034e5b4ffa1fa6ce481667d8ea6b1.1744692494.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CC:EE_|CY5PR12MB6347:EE_ X-MS-Office365-Filtering-Correlation-Id: 21cdad51-9e88-4497-497b-08dd7bda29d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: vW+wAczugqUoLIeRsqD8CQQWalcS/r9Fv/WyWeNP37EvMbuvwq2pJ7BNYDmr/Ji23v/J6CXDSsFbCfWSEzweRCIuVH+0Ji5wMuPGgPdUuVCIhqUSC9I3EoAJW0dmYSEMiySgafo8rBynyQlw7R9P4hh0VIHgKceV6RII8yBJhH5jl/rTIfrepOddW+zpyMkjXFhZtsqu8q3wwX/pElBSNk+zlrf5UHX9+iYQYfCo8gNzZReb5i8uiZS4ymlgMxodnlWcqremFyKid/PlMk9R9uW7AtDxX8KD5DVN55lzJ+Gg5/HjmxyU5UUaucgNTI6TthiK/k/aZL4UHERY8HlHIKQeeqsvpMgrJhmj8j70BMZaUKlLvyhEhMQfLdxKlw8ttEW7na8hGFPdGBSGF7OWRK0xLRk0MzokFJaZ1BuUVOXkXnBEeqXV0nHInydfqYtCJRzHKIJlL3SxQ7Eg+f2NFjyiyWExSX/IwpDAEj7cK9v37eWnmSwkOf/cb6y7jD3Qw/KCf9zeyohy3QW0e/WTYljhh77e2ELeOweX1aMuqBDY4uxK8UWSzoQu+4OYUSYRRqb38sBF3+9Mj1VA5XRtcRwqiKAj7SQ8CP5vy3q1EpW94Dp8j1bnHzkXEN+j2IYDknsXZGVaKVIxb/6pLsdg8MtwIFO3TItGLpXUmWIBN9nibWggudvNFtUWzWmzGJobOCDQBB00ooq9z3suXuUzZWUE4UeELCBzdIkumjGMqwk0BvvHIMRgEzWK/fxX9UHgEWBQGEFawAnlAeR5yzbtuA5xz6UkNdJNf/dIae88j77O/DGfX1Fcc8svON6dyNHKfDVSf76U2AWArXlhNl5krs8hsk23YHDeHMgasz0FhxtnbHs/nHr32alu2tYRlvjsy5aTRTp5/jlvrlgisAm55aGXLqvhgixpGTQZtBHPaoD1AXFDSuia812yWD49GSgA2lrOY4ZhnC8gcH+8mWhyx8PjcEmzWAyNd4yEXwztpDN8L0qpaptpYJOGm3RyJV7mPtd1JDyQ//e+IZW5qmBxT8WaK7azbjsuWHacoiwiZCV07tHzUVLDRMp80rLWy3BvCOu29TfJSgOkTghTftqometAsNHo/lydpuYHdzYqNc2BXSqyw8UyJiC7cx4HYbAUm3daGZmJGz7BO+FQkEMPt3c4efyS5VePRYSZZwtKXKHtu1in1PG1G5DrKTDJNjTc45n+TANTvD4qQ9IMJCyX39DK4GvwXCCXuC8d8cHCwto/mYpnm88NNUngFoZbIl1pB9RmyiuWaw8DFjQn4NaHxaVFBoDdMQR6t1SyVDswslzc3BUtIDaM6vpbdFCJ+E+KvM8UY5ygFCpULKz74y4uxpSALLlZKJwP/xWUHosn6prxrygMCMcza19bMa71Yjyu469hVRUpgze4/2koUiuARYA3ARCT8smrm1xbA0KQmFhEW4GOgATYyXWuZM6UbZgy/ODuT3J937dIWYob/2hEI3q48TDuuOPvFCg4xc++EwConquwEa2WhtDmw1bZ9DVM X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:28.9937 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21cdad51-9e88-4497-497b-08dd7bda29d4 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: SJ1PEPF000023CC.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6347 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215835_093203_FEBA9969 X-CRM114-Status: GOOD ( 15.81 ) 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 An S2 nest_parent domain can be shared across vSMMUs in the same VM, since the S2 domain is basically the IPA mappings for the entire RAM of the VM. Meanwhile, each vSMMU can have its own VMID, so the VMID allocation should be done per vSMMU instance v.s. per S2 nest_parent domain. However, an S2 domain can be also allocated when a physical SMMU instance doesn't support S1. So, the structure has to retain the s2_cfg and vmid. Add a per-domain "vsmmus" list pairing with a spinlock, maintaining a list of vSMMUs in the S2 parent domain. Provide two arm_smmu_s2_parent_tlb_ helpers that will be used for nesting cases to invalidate S2 cache using vsmmu->vmid by iterating this "vsmmus" list. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 22 ++++++++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 53 +++++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 + 3 files changed, 77 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 7b47f4408a7a..7d76d8ac9acc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -859,6 +859,10 @@ struct arm_smmu_domain { struct arm_smmu_ctx_desc cd; struct arm_smmu_s2_cfg s2_cfg; }; + struct { + struct list_head list; + spinlock_t lock; + } vsmmus; struct iommu_domain domain; @@ -1081,6 +1085,7 @@ struct arm_vsmmu { struct arm_smmu_device *smmu; struct arm_smmu_domain *s2_parent; u16 vmid; + struct list_head vsmmus_elm; /* arm_smmu_domain::vsmmus::list */ }; #if IS_ENABLED(CONFIG_ARM_SMMU_V3_IOMMUFD) @@ -1094,6 +1099,11 @@ int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state); void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master); int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt); + +void arm_smmu_s2_parent_tlb_inv_domain(struct arm_smmu_domain *s2_parent); +void arm_smmu_s2_parent_tlb_inv_range(struct arm_smmu_domain *s2_parent, + unsigned long iova, size_t size, + size_t granule, bool leaf); #else #define arm_smmu_hw_info NULL #define arm_vsmmu_alloc NULL @@ -1119,6 +1129,18 @@ static inline int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, { return -EOPNOTSUPP; } + +static inline void +arm_smmu_s2_parent_tlb_inv_domain(struct arm_smmu_domain *s2_parent) +{ +} + +static inline void +arm_smmu_s2_parent_tlb_inv_range(struct arm_smmu_domain *s2_parent, + unsigned long iova, size_t size, + size_t granule, bool leaf) +{ +} #endif /* CONFIG_ARM_SMMU_V3_IOMMUFD */ #endif /* _ARM_SMMU_V3_H */ diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 6cd01536c966..45ba68a1b59a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -30,6 +30,54 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type) return info; } +void arm_smmu_s2_parent_tlb_inv_domain(struct arm_smmu_domain *s2_parent) +{ + struct arm_vsmmu *vsmmu, *next; + unsigned long flags; + + spin_lock_irqsave(&s2_parent->vsmmus.lock, flags); + list_for_each_entry_safe(vsmmu, next, &s2_parent->vsmmus.list, + vsmmus_elm) { + arm_smmu_tlb_inv_vmid(vsmmu->smmu, vsmmu->vmid); + } + spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); +} + +void arm_smmu_s2_parent_tlb_inv_range(struct arm_smmu_domain *s2_parent, + unsigned long iova, size_t size, + size_t granule, bool leaf) +{ + struct arm_smmu_cmdq_ent cmd = { .tlbi = { .leaf = leaf } }; + struct arm_vsmmu *vsmmu, *next; + unsigned long flags; + + spin_lock_irqsave(&s2_parent->vsmmus.lock, flags); + list_for_each_entry_safe(vsmmu, next, &s2_parent->vsmmus.list, + vsmmus_elm) { + cmd.tlbi.vmid = vsmmu->vmid; + + /* Must flush all the nested S1 ASIDs when S2 domain changes */ + cmd.opcode = CMDQ_OP_TLBI_NH_ALL; + arm_smmu_cmdq_issue_cmd_with_sync(vsmmu->smmu, &cmd); + cmd.opcode = CMDQ_OP_TLBI_S2_IPA; + __arm_smmu_tlb_inv_range(vsmmu->smmu, &cmd, iova, size, granule, + &s2_parent->domain); + } + spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); +} + +static void arm_vsmmu_destroy(struct iommufd_viommu *viommu) +{ + struct arm_vsmmu *vsmmu = container_of(viommu, struct arm_vsmmu, core); + unsigned long flags; + + spin_lock_irqsave(&vsmmu->s2_parent->vsmmus.lock, flags); + list_del(&vsmmu->vsmmus_elm); + spin_unlock_irqrestore(&vsmmu->s2_parent->vsmmus.lock, flags); + /* Must flush S2 vmid after delinking vSMMU */ + arm_smmu_tlb_inv_vmid(vsmmu->smmu, vsmmu->vmid); +} + static void arm_smmu_make_nested_cd_table_ste( struct arm_smmu_ste *target, struct arm_smmu_master *master, struct arm_smmu_nested_domain *nested_domain, bool ats_enabled) @@ -380,6 +428,7 @@ static int arm_vsmmu_cache_invalidate(struct iommufd_viommu *viommu, } static const struct iommufd_viommu_ops arm_vsmmu_ops = { + .destroy = arm_vsmmu_destroy, .alloc_domain_nested = arm_vsmmu_alloc_domain_nested, .cache_invalidate = arm_vsmmu_cache_invalidate, }; @@ -394,6 +443,7 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct arm_smmu_domain *s2_parent = to_smmu_domain(parent); struct arm_vsmmu *vsmmu; + unsigned long flags; if (viommu_type != IOMMU_VIOMMU_TYPE_ARM_SMMUV3) return ERR_PTR(-EOPNOTSUPP); @@ -433,6 +483,9 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, vsmmu->s2_parent = s2_parent; /* FIXME Move VMID allocation from the S2 domain allocation to here */ vsmmu->vmid = s2_parent->s2_cfg.vmid; + spin_lock_irqsave(&s2_parent->vsmmus.lock, flags); + list_add_tail(&vsmmu->vsmmus_elm, &s2_parent->vsmmus.list); + spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); return &vsmmu->core; } 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 07d435562da2..df87880e2a29 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3256,6 +3256,8 @@ arm_smmu_domain_alloc_paging_flags(struct device *dev, u32 flags, } smmu_domain->stage = ARM_SMMU_DOMAIN_S2; smmu_domain->nest_parent = true; + INIT_LIST_HEAD(&smmu_domain->vsmmus.list); + spin_lock_init(&smmu_domain->vsmmus.lock); break; case IOMMU_HWPT_ALLOC_DIRTY_TRACKING: case IOMMU_HWPT_ALLOC_DIRTY_TRACKING | IOMMU_HWPT_ALLOC_PASID: From patchwork Tue Apr 15 04:57:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051489 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 B2255C369AB for ; Tue, 15 Apr 2025 05:15:54 +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=NxUFIToygWZJnL1QHFsxEXRplUq1RiOvOCD1KbjKJdQ=; b=iZ9Sp1VBVrlsKMgsfn4gOKTk01 R2AE1IKay2gG0G8EraYgelR2fzCybbkL7NeCbVxeaLCSmAwI+Jo+llEpomRpi/QElQ0F1qOMYwhsM Sk+cn838q/HuLQhkO4teLfJST+t3xm0l1JWwzNcTEAMi/j9ETzl5mYEukBWe5PrsrSqXmwj6Mgc5M hpPyJaIAUEYKqCh8f5a6Y1IpNUnb0CvkCVAHfgpkWo/x+Oq1PLq28koH202B2nI+lRZWSSAzQoTd4 GeZRtcE9iXzA9vGKXIZ7NUmvNcJMPwEVdB8HiYq17oQPuAsHu+foH7wF0uv8osu0/ELazKflTBH/Q xCyo2odQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4Ye9-00000004Wvo-3MRc; Tue, 15 Apr 2025 05:15:45 +0000 Received: from mail-dm6nam11on2060f.outbound.protection.outlook.com ([2a01:111:f403:2415::60f] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNY-00000004Uwq-4A3M for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Eh9w8GjfRBaK1JkUu2KPskuGhQwm8hY7whqMRabXbU5Qolz7PIpIvszY+ZvJrDpwvBoiXI16ic2CamQbBrFrRjbJacTeUilvOIxBk4kIPXk7aQwdpKnuyNUer5zVq6Ot79HKi3O+JhjQt1PtEc+u3HPHRrH/l7BLzh66uxHPY544PBfMxIALcXKKw65hK7LGXbmshPXWqDtm3a2tbDPwzoU9ZZF3ilGV9lJfyBAO7KYib53nWQZ6Vgub4LaDeJb8+SEPeObexPHKmf2OWEp/pRZGzRHNZE/fPI1AOkHbE4yWsEoyqX0S4zynnLBYvMkf90I1/cAMrVlLIjOrQouPRg== 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=NxUFIToygWZJnL1QHFsxEXRplUq1RiOvOCD1KbjKJdQ=; b=L+12m6pGUJ4gPzG+cpCTI0677p33+LJDhGYqcJq5pOk9WaSsw6R3xxOG9pn5T+ObKlQUinxilKWfkrI8DK5zpF8ZUeYZWO/rvdKfvzHq/6IV+6IYX87vFu1ob/MmbJd85D3zhZe0CKxy9/SVfkPaGsJka1/E8DTp6xleEeime0Tc88bCpqH6+rFm7cYK/z+2UkZNfGtK8I9eGiCpQ4KzRkvv17qMzFWlkkByrU5kJuVmNBvxCI4Nu6XNOJ/U0SaEFVMLy6zd7MeEahuXiIC3P78DdZllTglusSi0ARjC23bhDGZ+FAF3u1Yc1mDWoczv9t6+/UxYfs2XqK9LFL+22Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org 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=NxUFIToygWZJnL1QHFsxEXRplUq1RiOvOCD1KbjKJdQ=; b=nrWnO95PKaXOi0TQcPkHWT068XOfK2myyRHND7C/vck01X0kDLOYNn1m/uTRv38Xd4T0hK3pqChlNo6mZ/0TRiSnNVQL9Hu6DkI7tK09A+YVUCyCHr3oLBEE6oIRchSnwSfZ4td/Ks5VNnABKpB4HD331Ej6asvKrnuJwS0bVrmh+IelHlkLg7wMOIDEKJmvPO5F5xXl28YIHssc+fbcGbDnMXqn4IfYvAlW6ke6jkD3f+un/fwnePfFiJo/hzDJ5nc/CJ8/yTqGXhkpATqDre9d/DgXG+HUrqUQICXO6npX2Pjl3pCFOiyJ8UU0t+lBtTT3Sb8GegBpd6ccPbvGXw== Received: from MW4PR03CA0213.namprd03.prod.outlook.com (2603:10b6:303:b9::8) by CY5PR12MB6130.namprd12.prod.outlook.com (2603:10b6:930:26::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.28; Tue, 15 Apr 2025 04:58:32 +0000 Received: from SJ1PEPF000023CF.namprd02.prod.outlook.com (2603:10b6:303:b9:cafe::d3) by MW4PR03CA0213.outlook.office365.com (2603:10b6:303:b9::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.26 via Frontend Transport; Tue, 15 Apr 2025 04:58:31 +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 SJ1PEPF000023CF.mail.protection.outlook.com (10.167.244.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:31 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Mon, 14 Apr 2025 21:58:18 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:18 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:17 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 07/11] iommu/arm-smmu-v3: Introduce arm_vsmmu_atc_inv_domain() Date: Mon, 14 Apr 2025 21:57:42 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023CF:EE_|CY5PR12MB6130:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b20ad59-e03e-49f2-cb67-08dd7bda2b60 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|376014|82310400026|36860700013|3613699012; X-Microsoft-Antispam-Message-Info: P2yg1P24mtIHyPXNZt+rWIDXn8m//5V7bW8EHmVNw84vnV4oMpONDonBYe4naX7KqWfKCWheYAqfH7DSayj2qPnDYW2e3xsY9dyouAPDfYN1x4ND4yk3fSwoCu/SsxKGECAL4xzttUzRe7eMuVJT4uS71do/UiwcbiSpsWBcqFsjQJISV7C4/QjV0cbSAFT+o3pNAJ9KJmN4rriCMFlTA2TJT3R9PJLOsbTRCetaSxWNccIRDg0/kmncX1lzrr0pbEqpYRMeylO3RCtCtBet65N6aOE9lppUVg8r6pelYZ3QLlgS9YduyI+SW+SK+KZprdK2ywCPOvZbgKaKPSean59RFCGKcCwaxDqHFzs5sySstKA9VJhUyryBM81FSuhObs1oLosQBCmWDCHibQFoSRUPrZImi+shMykYb2JErDmahmSVQCvH5QU21EpJTcCIQTijoeRZSpMnvyDlNLMkW3uisxjKyTDdU9mF05Bu7lc4eWZzEImmTfl/QCYuvcyqKfzR87rOU3TPTH60EMoiWXnsYZE3+Di7BXDMJHcKzfaFDZBa+lEPlUKEm/dMo49pihEl5CdlV5ShYqVx6d4UjQ9eX+d+5RkQ2zTVg48NKtJbnMzglP2j9EC9+JUvzXaBZMZErJSspy/wXVxTP/wk5Z++OvRmkp44waGrp3ZiGQyQxHvFSE552dYN3L/tnZruRn7CTow1pCHz2s6M+0d5Ti8kNiIqEowop4cBQLVKDbmorU10YUcgk3ySg+SZb0fGILl6/iy4DSArBK092mlrmgAPPWvaM7NajbRkJYegDLmPdD1U6TPMdqe5U7vyOw0ZR7dG7zLjpsd2vmy5o6/Jrl2qVwzQL2OC9ozBOqBkbgDw620uxZddK/EG8YBUO6wpqwZqfOPlrnUaQZkWAxnPjp1tTqK7XoOG/WZXg+xMml271ytasIwnGEuL681bWytoXoOBNCozIcyCIGsqgZqKoZOc9NfzM/bG35rsiFupPUxSpmdxLU6CMfg9zuaerQtMGSZrY86GpRh9n7Tb/rTu8BUBpxsbgKGMUCYCMGb8OenTZQVYlvz1Wb5s5TnLpbdrhmvyUlpPRYrxJd9Oal7R+bPk5bygIt3GKqznFIDvqwVlyi2qLKQd9YHLCYAsI04BdfgUBle2eH5+yDqCa/M0g5pVNN6Nv+DwbPa4/bAwyjZWMeCJ6U9vgeI07PlKfELGiJ0/g/VuyEOPdA3xoefCclQiSlwtWL6o+PsJpSlCyuIy3ZeTV2yhSdsAoYMgNVbKwbVMmKNWNtx9wDlHKw7ZINaE9viZR1SAbQ9dKb897J9S5hS/o7NiGzOlTUYRgpRMz11ex2y8vKG727XhPD2lwTLcu+qEMZu1tV5qK5QCh7Q8ftdVGgGE+9SGHdAW9Zea1r3T2tYsqr3rUdYEDYe/kHNxhs0deaKR9sI3H/4vSWR+v8MBJS99uS17zEF+bJxijmopCriKMSQNHhTIRYqN4HJ02Z+R7WqQTBzIxrIC5CZXu4RvG/thpR83XTLkxLt4DFKCK7GvfJxnLh8C2VZBk2DE4N48vxJIDXA6NLTqJCU= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(376014)(82310400026)(36860700013)(3613699012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:31.6079 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b20ad59-e03e-49f2-cb67-08dd7bda2b60 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: SJ1PEPF000023CF.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6130 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215837_046412_24D00DCF X-CRM114-Status: GOOD ( 15.63 ) 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 Currently, all nested domains that enable ATS (i.e. nested_ats_flush) are added to the devices list in the S2 parent domain via a master_domain. On the other hand, an S2 parent domain can be shared across vSMMU instances. So, storing all devices behind different vSMMU isntances into a shared S2 parent domain apparently isn't ideal. Add a new per-vSMMU ats_devices list (with a pairing lock), which will be stored the devices if their ATS features are enabled. Using this ats_devices list, add an arm_vsmmu_atc_inv_domain() helper, for the s2_parent invalidation routines to proceed ATC invalidation properly, which sends an ATC invalidation request to all the devices on the list. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 6 +++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 7d76d8ac9acc..d130d723cc33 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -840,6 +840,7 @@ struct arm_smmu_master { bool sva_enabled; bool iopf_enabled; unsigned int ssid_bits; + struct list_head devices_elm; /* vsmmu->ats_devices */ }; /* SMMU private data for an IOMMU domain */ @@ -1086,6 +1087,11 @@ struct arm_vsmmu { struct arm_smmu_domain *s2_parent; u16 vmid; struct list_head vsmmus_elm; /* arm_smmu_domain::vsmmus::list */ + /* List of struct arm_smmu_master that enables ATS */ + struct { + struct list_head list; + spinlock_t lock; + } ats_devices; }; #if IS_ENABLED(CONFIG_ARM_SMMU_V3_IOMMUFD) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 45ba68a1b59a..4730ff56cf04 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -30,6 +30,41 @@ void *arm_smmu_hw_info(struct device *dev, u32 *length, u32 *type) return info; } +static void arm_vsmmu_cmdq_batch_add_atc_inv(struct arm_vsmmu *vsmmu, + struct arm_smmu_master *master, + struct arm_smmu_cmdq_batch *cmds, + struct arm_smmu_cmdq_ent *cmd) +{ + int i; + + lockdep_assert_held(&vsmmu->ats_devices.lock); + + arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, cmd); + for (i = 0; i < master->num_streams; i++) { + cmd->atc.sid = master->streams[i].id; + arm_smmu_cmdq_batch_add(vsmmu->smmu, cmds, cmd); + } +} + +static int arm_vsmmu_atc_inv_domain(struct arm_vsmmu *vsmmu, unsigned long iova, + size_t size) +{ + struct arm_smmu_cmdq_ent cmd = { .opcode = CMDQ_OP_ATC_INV }; + struct arm_smmu_master *master, *next; + struct arm_smmu_cmdq_batch cmds; + unsigned long flags; + + arm_smmu_cmdq_batch_init(vsmmu->smmu, &cmds, &cmd); + + spin_lock_irqsave(&vsmmu->ats_devices.lock, flags); + list_for_each_entry_safe(master, next, &vsmmu->ats_devices.list, + devices_elm) + arm_vsmmu_cmdq_batch_add_atc_inv(vsmmu, master, &cmds, &cmd); + spin_unlock_irqrestore(&vsmmu->ats_devices.lock, flags); + + return arm_smmu_cmdq_batch_submit(vsmmu->smmu, &cmds); +} + void arm_smmu_s2_parent_tlb_inv_domain(struct arm_smmu_domain *s2_parent) { struct arm_vsmmu *vsmmu, *next; @@ -39,6 +74,7 @@ void arm_smmu_s2_parent_tlb_inv_domain(struct arm_smmu_domain *s2_parent) list_for_each_entry_safe(vsmmu, next, &s2_parent->vsmmus.list, vsmmus_elm) { arm_smmu_tlb_inv_vmid(vsmmu->smmu, vsmmu->vmid); + arm_vsmmu_atc_inv_domain(vsmmu, 0, 0); } spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); } @@ -62,6 +98,11 @@ void arm_smmu_s2_parent_tlb_inv_range(struct arm_smmu_domain *s2_parent, cmd.opcode = CMDQ_OP_TLBI_S2_IPA; __arm_smmu_tlb_inv_range(vsmmu->smmu, &cmd, iova, size, granule, &s2_parent->domain); + /* + * Unfortunately, this can't be leaf-only since we may have + * zapped an entire table. + */ + arm_vsmmu_atc_inv_domain(vsmmu, iova, size); } spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); } @@ -76,6 +117,7 @@ static void arm_vsmmu_destroy(struct iommufd_viommu *viommu) spin_unlock_irqrestore(&vsmmu->s2_parent->vsmmus.lock, flags); /* Must flush S2 vmid after delinking vSMMU */ arm_smmu_tlb_inv_vmid(vsmmu->smmu, vsmmu->vmid); + arm_vsmmu_atc_inv_domain(vsmmu, 0, 0); } static void arm_smmu_make_nested_cd_table_ste( @@ -487,6 +529,9 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, list_add_tail(&vsmmu->vsmmus_elm, &s2_parent->vsmmus.list); spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); + INIT_LIST_HEAD(&vsmmu->ats_devices.list); + spin_lock_init(&vsmmu->ats_devices.lock); + return &vsmmu->core; } From patchwork Tue Apr 15 04:57:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051493 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 868C4C369AB for ; Tue, 15 Apr 2025 05:19:36 +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=1zNqolHNUJ4bV3FUx5ffk//o9/P5bcuqxh/eGDjRgOU=; b=LCloKzPWxYU4w7oWVWAttPmc20 eZLB7+GUsxQNzjVamxFCxI8Vp3t0KZ0yczveev6xA8V4jMXF5FMFvJ/fmEsbDh0MIf7ounBVu48pM G05WCQ+WV+yWmQarcE4kXF+runPRWMFHbk9r3VOqYP1ndPuINcuozycx8KE4okKNoLZVUcxYKwNJE AWgDILQp3EF0CK7GMXJKAHmjBlWoRMohMzAR7NU8gu4JjTDIQsSb9RFjSLKw2HX+cY9XbXRs1q+hv XXVjy9SGmWngZV25vKS/1JUEAiagyQHaVN5xVyFxDUcpKIS+CamNhEg458+GOtUydpxckvWBIMWXP nYd6P8Gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4Yhj-00000004XPj-0qEe; Tue, 15 Apr 2025 05:19:27 +0000 Received: from mail-bn8nam11on20612.outbound.protection.outlook.com ([2a01:111:f403:2414::612] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNc-00000004UzC-2CH4 for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EDKcot8gJ5ZORSFkzVDisUflaBgRCM0e7crLK34Q3csSFDyu/dpOxJGU39zaR1IqPYSHBrxcK4iSaTv8POSS8AM3MHqqCGIUai7VDQ1jzR+3LnZnEZwZQB2SVce/zR2INMrAiuOk1ZVMH4r1nE/g0V6PPCoRal9Q1Q0v8srnhNgdOxbw2Yqc7znD+kTfjmjrxkRQCkuxfS2/wm9z2a5L4Mdw7M+nhEHyHGPzEXTv2udb5xHaN7yprXr7MbhAWSrLXiFVxF82NCXAMlh45v4YcguZwgUFxbdDNR8LKQNytgrN0EAU2MD8l6jyCnsA75QDdy8TKLuVeTqloBVoH1FtNg== 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=1zNqolHNUJ4bV3FUx5ffk//o9/P5bcuqxh/eGDjRgOU=; b=PHjKF5ssdBjG7ETqvcW/bVsRuT0gbWJsQK9/NS1eGkX+Sx8Qr5aNkN7KtIWzckqXGDgL2Ud/5QGC4jf1z9WcdSOFeyeSGII2HppqOJ82un2sMX4JxcgJTInZQuqTL/7phmMlAQkqTdgdEODnK77raHja3EEoaidC6Bf8an5RJC7gK51RwcojdzuNtpLgPTpAZmHxoeaeYv0jucN2jvcBRp2f4ILFOW+pRQBb+bP2L9B8TxVzS2lTNaEPoO+eexP7uCjX2AoV50Jm50f/Ay69w3a2LsgsUyIwQoZumzueJIKqFQ1pu9qCPuHXAyRT92w2C3jQUfTOUGxK0TlnuDuKoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org 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=1zNqolHNUJ4bV3FUx5ffk//o9/P5bcuqxh/eGDjRgOU=; b=RrD6gWm9/5Vn48UOhQOSX0CbmiF/vAsH88rNIsCJa92W7LiIWfh32ZANyZDEfVD9ziamagMRCin6ZcjFzINS3GJJYt1rghRdynBRNEIhxxrkURomyhWKuhXOQN6Kphql6TpIiFbwavtEumDBnb91ecLEOYIsVost6cNAZ7T/0ya0gE8vP/fbXu0vpt1+vef/wkYxpuWji3wfMJYWwB6JLQGoVn9dabUQi+CIlDgw4T6vsCk+BV0ioCCB7nqIaOaxeIj7/LqVBIFU3uvZMJTSWEeFacO3FMcykaBg09FkfRSXh5auFRctt2WWZOuQf+TsRYjeDwdo837NBEZbcheEzA== Received: from SJ0PR05CA0124.namprd05.prod.outlook.com (2603:10b6:a03:33d::9) by DM6PR12MB4251.namprd12.prod.outlook.com (2603:10b6:5:21e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.32; Tue, 15 Apr 2025 04:58:34 +0000 Received: from SJ1PEPF000023D1.namprd02.prod.outlook.com (2603:10b6:a03:33d:cafe::e5) by SJ0PR05CA0124.outlook.office365.com (2603:10b6:a03:33d::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8655.8 via Frontend Transport; Tue, 15 Apr 2025 04:58:34 +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 SJ1PEPF000023D1.mail.protection.outlook.com (10.167.244.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:33 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Mon, 14 Apr 2025 21:58:19 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:19 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:18 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 08/11] iommu/arm-smmu-v3: Use vSMMU helpers for S2 and ATC invalidations Date: Mon, 14 Apr 2025 21:57:43 -0700 Message-ID: <771891ae889f880832c70d5ed895802732138478.1744692494.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023D1:EE_|DM6PR12MB4251:EE_ X-MS-Office365-Filtering-Correlation-Id: 609de5aa-7a7a-4c8e-d990-08dd7bda2cbd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: bHUQHTHQ7HBnhqgajtc1xpFa9vBPli7JOcocaNBg6tAKOL/OOsbgBjCrbNdvlkakYgOeNUy0a6AP0gWjQu13Wo3G6kEgtS3cQEP3sEcI1OZv5PR71zDQCuxYWYIHzo7gpUcUcXEnUbCAImIDhA0w6os677YzN4mfk5qzrKXssC3ES7SLA41qkthl4yMeIWEQrh57wB9r4jXsqo8lhicq/7gV6MqhU/mfAjGfo6o+Hod2JcBBlHyBN5NWPvzjf/OT0fA/M9ki7qvjpHSu7oK6pHsxKpSU2Ympd8PRyoXg27TqvUzyOF8QUh13CWzAZ2QIhmaL7HXftR4a4U+bJ/YqK4QXrBugrHUHqCMLcDlP35+NqERrG+DObsUBPkBb7Adh+Z6+1hlXrAW4iB0WC2FyiaGe3AjPc5g9MwaIIMR+8P8n5JZGUcJXYr3X7as8yxR5Di9V8q5KDU7wS1Fk83dlBHBEHA1e+gqFQ43LSDm17+R+kVbJWMbxLDBResZvmUtuRcCC8MK9D1b2KBCNznRtY/j+I/3ESjEFHu2jyoTm1gNE5ij/0BNsT9Veed033ZfTH57em46vnP/MScgCG/48VfGj4K4uW3B8voy4Ex1ABnyZ1VD4dHyGUtf+tvcunbPN5V2HyT5+WsjaxsRxsN2tWliBcNzhFZEqEelEsN1IwKsL3EGs2jmcGisqRgcZ6vQHJOpyVr0rKhNzBcCIcE9SUrIWgJ+dOpXXUL4SH+nuKVRUI9bUckrlc0ITG5mPCI6rAcQ3k0GEvp4fFV8j/dNkeJL5EHq0D2FJ+oJoZSPmEIHFsHQ68GT6xI0ndV/lZNf7qqUswyLtB6vFab1awxDbibJYKaTk1iBoaP8PAhif5Jng+l8GvR3a2dBY8RpFbV7iWzdqoCGhWpHzroF9EijHllqZHMMRAZkyeSx6WXZxUuG1BdIwM+ta2iVXqB6lbBuIwjKY19wt/HG0HitquyywqslWM7naq0QZjScUlZf8E4W5dPxtrP5e/oCqkY9u4f1zlSkg510w38BoJtT/un95cFMKGBdrwFjsJXn0v4A6jbTflMTOXI0xT6jgGlRu4ywWp/fpkFcyQX1R48ILi2NuF9q6PfD1FikCmm1hu+qUHtAMAEs7fLMptfKib6L6QVfp2pNpkF0JCBtyG7ZsOpuXHQCcBZfBkDSLMAS5seeEziP40rINGnxrPD5mvFENQsL3mb6pO4KVXbfCxv2azjt0ZLf1YAefqRyHTt6zy556drITWxURMCwQ8K4f/bz3B3/6ODom164WdMlkKwEcleH7WVIgB+cG63U+57NsHOpGUPT8DdhwjStrreTUgt7y0GQmKC6qjgAXvmehizRmOhuUZU/bLTlgl8RtdSBeOcNmhd2T3vSIUf2VBi9H1ShZmcuRPlERO/ZnRD8JkQqxImcEJbAyLHM+lNJnZaXCc16DtQevicbqWRTnODwsDTwSxa1ldWvgAW8SvmftvlTBmuoxLiYA1oOI7/DFybEwZ1Hq/SL+1sg5hjOO7QbGMZEz9LZM X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:33.9111 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 609de5aa-7a7a-4c8e-d990-08dd7bda2cbd 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: SJ1PEPF000023D1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4251 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215840_632920_038127EF X-CRM114-Status: GOOD ( 19.58 ) 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 Now the driver can do a per-vSMMU S2 cache and ATC invalidations, given a pair of arm_smmu_s2_parent_* helpers. Use them in the arm_smmu_tlb_inv_* functions, replacing the existing per-domain invalidations. This also requires to add/remove the device onto/from the ats_devices list of the vSMMU. Note that this is shifting away from the nested_ats_flush in the struct arm_smmu_master_domain, which now became a dead code, requiring a cleanup. Move the arm_vsmmu_attach_prepare() call in arm_smmu_attach_prepare(), out of the !IOMMU_DOMAIN_NESTED routine, so that it doesn't need to revert the arm_vsmmu_attach_prepare(), which wouldn't only require a simple kfree(). All of these have to be done in one single patch, so nothing is broken. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +++ .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 27 ++++++++++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++---------- 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index d130d723cc33..c9b9c7921bee 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -1104,6 +1104,8 @@ int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, struct arm_vsmmu *vsmmu); void arm_smmu_attach_commit_vmaster(struct arm_smmu_attach_state *state); void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master); +void arm_vsmmu_remove_ats_device(struct arm_vsmmu *vsmmu, + struct arm_smmu_master *master); int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt); void arm_smmu_s2_parent_tlb_inv_domain(struct arm_smmu_domain *s2_parent); @@ -1130,6 +1132,11 @@ arm_smmu_master_clear_vmaster(struct arm_smmu_master *master) { } +static inline void arm_vsmmu_remove_ats_device(struct arm_vsmmu *vsmmu, + struct arm_smmu_master *master) +{ +} + static inline int arm_vmaster_report_event(struct arm_smmu_vmaster *vmaster, u64 *evt) { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 4730ff56cf04..491f2b88e30b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -182,11 +182,13 @@ static void arm_smmu_make_nested_domain_ste( int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, struct arm_vsmmu *vsmmu) { + struct arm_smmu_master *master = state->master; struct arm_smmu_vmaster *vmaster; + unsigned long flags; unsigned long vsid; int ret; - iommu_group_mutex_assert(state->master->dev); + iommu_group_mutex_assert(master->dev); ret = iommufd_viommu_get_vdev_id(&vsmmu->core, state->master->dev, &vsid); @@ -200,6 +202,12 @@ int arm_vsmmu_attach_prepare(struct arm_smmu_attach_state *state, vmaster->vsid = vsid; state->vmaster = vmaster; + if (state->ats_enabled) { + spin_lock_irqsave(&vsmmu->ats_devices.lock, flags); + list_add(&master->devices_elm, &vsmmu->ats_devices.list); + spin_unlock_irqrestore(&vsmmu->ats_devices.lock, flags); + } + return 0; } @@ -220,6 +228,23 @@ void arm_smmu_master_clear_vmaster(struct arm_smmu_master *master) arm_smmu_attach_commit_vmaster(&state); } +void arm_vsmmu_remove_ats_device(struct arm_vsmmu *vsmmu, + struct arm_smmu_master *master) +{ + struct arm_smmu_cmdq_ent cmd = { .opcode = CMDQ_OP_ATC_INV }; + struct arm_smmu_cmdq_batch cmds; + unsigned long flags; + + arm_smmu_cmdq_batch_init(vsmmu->smmu, &cmds, &cmd); + + spin_lock_irqsave(&vsmmu->ats_devices.lock, flags); + list_del(&master->devices_elm); + arm_vsmmu_cmdq_batch_add_atc_inv(vsmmu, master, &cmds, &cmd); + spin_unlock_irqrestore(&vsmmu->ats_devices.lock, flags); + + arm_smmu_cmdq_batch_submit(vsmmu->smmu, &cmds); +} + static int arm_smmu_attach_dev_nested(struct iommu_domain *domain, struct device *dev) { 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 df87880e2a29..483ef9e2c6b7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2255,6 +2255,10 @@ static void arm_smmu_tlb_inv_context(void *cookie) * insertion to guarantee those are observed before the TLBI. Do be * careful, 007. */ + + if (smmu_domain->nest_parent) + return arm_smmu_s2_parent_tlb_inv_domain(smmu_domain); + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) arm_smmu_tlb_inv_asid(smmu, smmu_domain->cd.asid); else @@ -2342,6 +2346,11 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, }, }; + if (smmu_domain->nest_parent) { + return arm_smmu_s2_parent_tlb_inv_range(smmu_domain, iova, size, + granule, leaf); + } + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { cmd.opcode = smmu_domain->smmu->features & ARM_SMMU_FEAT_E2H ? CMDQ_OP_TLBI_EL2_VA : CMDQ_OP_TLBI_NH_VA; @@ -2353,15 +2362,6 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, __arm_smmu_tlb_inv_range(smmu_domain->smmu, &cmd, iova, size, granule, &smmu_domain->domain); - if (smmu_domain->nest_parent) { - /* - * When the S2 domain changes all the nested S1 ASIDs have to be - * flushed too. - */ - cmd.opcode = CMDQ_OP_TLBI_NH_ALL; - arm_smmu_cmdq_issue_cmd_with_sync(smmu_domain->smmu, &cmd); - } - /* * Unfortunately, this can't be leaf-only since we may have * zapped an entire table. @@ -2765,8 +2765,11 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, if (!smmu_domain) return; - if (domain->type == IOMMU_DOMAIN_NESTED) - nested_ats_flush = to_smmu_nested_domain(domain)->enable_ats; + if (domain->type == IOMMU_DOMAIN_NESTED && + to_smmu_nested_domain(domain)->enable_ats) { + return arm_vsmmu_remove_ats_device( + to_smmu_nested_domain(domain)->vsmmu, master); + } spin_lock_irqsave(&smmu_domain->devices_lock, flags); master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid, @@ -2837,20 +2840,17 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, arm_smmu_ats_supported(master); } - if (smmu_domain) { - if (new_domain->type == IOMMU_DOMAIN_NESTED) { - ret = arm_vsmmu_attach_prepare( - state, - to_smmu_nested_domain(new_domain)->vsmmu); - if (ret) - return ret; - } + if (new_domain->type == IOMMU_DOMAIN_NESTED) { + struct arm_smmu_nested_domain *nested_domain = + to_smmu_nested_domain(new_domain); + ret = arm_vsmmu_attach_prepare(state, nested_domain->vsmmu); + if (ret) + return ret; + } else if (smmu_domain) { master_domain = kzalloc(sizeof(*master_domain), GFP_KERNEL); - if (!master_domain) { - kfree(state->vmaster); + if (!master_domain) return -ENOMEM; - } master_domain->master = master; master_domain->ssid = state->ssid; if (new_domain->type == IOMMU_DOMAIN_NESTED) @@ -2877,7 +2877,6 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); kfree(master_domain); - kfree(state->vmaster); return -EINVAL; } From patchwork Tue Apr 15 04:57:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051494 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 A070CC369AB for ; Tue, 15 Apr 2025 05:21:27 +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=BZWbtBHZnDON8aPXISxmyG/yHAYHK5hHCsTsyINiglI=; b=j3LmAhkQUZHtMnXRVp4pTZZwTz FdpOHi8fISB2gkaBooKNgsL1BADPi4w+4ZNs2io/rinb/v6YEoNa8ILe+2Y/XNXzJYF1qUnyswUIr PN9wiUx3MPl8IL2dBanCVIf/KMN6JIoNNiqQeFRqspoD1LKQGlp+kbroQWhwxjF+t084kjY/RENq4 vpDBgzf2uKwC5dRXJ7JtpPfM+FwQrAKRUrSeuL5smkXcLKbVEiuIhcVCmqqTOwjRv1beqCSzQISxg kUkrG1mwEeE2LiT5SBv1JykXqhmTu8La2l/BJx0Lcc5WjNH8yEgHUqWdGnFSO4UjvSpE/4Jjt/KpU nnj+sWIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YjU-00000004XfV-3pOE; Tue, 15 Apr 2025 05:21:16 +0000 Received: from mail-dm6nam11on2060d.outbound.protection.outlook.com ([2a01:111:f403:2415::60d] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNe-00000004Uzu-3Msg for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pBRbtVYKtCGeQg/Dh4wyDKl0mnsztfNrRGQTqjEoc6p4lfEOLzdrip6G1NRkK4dxZDDOzWli71ucwXBYk3Cwxk7KJlx6Rde2wPkccGAZBCaFD9b9+91mIL7tVPhiODPhygpRODjXtxf627c1l7X8/nC/DAxjeKUxILtJuEWeoD/q4XU2GTuH0I0BcLVep0ZROtIc5yz/uW2RvEWQOXMXS7yr882bX8O1a81YAYK/McO+I3AV6jQPdAxJd0qNhL30WKxOFcuRhP0dA1GeR8fa++pojyDiNH+PLpS3DafcUmJYQC7W2IJHXdZUvxAuBbFt/A2LCKqKCwIZznVF64233Q== 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=BZWbtBHZnDON8aPXISxmyG/yHAYHK5hHCsTsyINiglI=; b=Am52S9vLo7bPh3PORy0IQCCP1e/+661rev9Wj7h3Xez1046opUuuIhkuI3N8wBIkaweMRm+Riukq+/iad7ZI1CtXJphUWuX8WOcsKdrAw7gZuhIm4Wa3qfvoAlIOzXWyamnSGYZMr80GkzPfxxeZhPgfNzSKSP0j9Y0dcksFacZ062HOmN+glQ5yElX9wh3pwfm5XJgi+GnIEE1w+Ox4O2AkgNC4doXn/D0eMqaGzqi70AHPRytbL0Vbndg16wzFwZ1RSZrujG0DXguKWq0A79ov/CXBr6NsGkq1esT2ZzfOwW7pcTrE+QgI7hPOwzhG6CCJ/SN1EZcJEJl5YZdEpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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=BZWbtBHZnDON8aPXISxmyG/yHAYHK5hHCsTsyINiglI=; b=S/Ahjx0tWvYAM++XX1sL1eqxAC5AC0qgK2to2JlQjcoTGgeTkcRyACHyTw9xtSrjMu2XBd1cUPDSPdmmyy2CuRf6TuRMGY3PjlyuOD19D52DWJD4NHRVyt+Y9F/u8gUrEq79F6aKihs/MN8WtLfkhtPpU2Zv1uFmwAHcs3tN4BUJMyPQ9xD2hEZqsxo6CSCIzE7Msmb6tdVjaAlLTQjd8UYWt5KR/BywYXfVqJrZE9oyRdl6sUHuZ9AQ367ighe3eIIvqjsizlCJ5NP1glfizTYlGkfxe5rfNFwlkCiY+9rTmxFO4svwYC/83k6O5p5cQfbG5BLNJOE3i/m9S3C07A== Received: from BL0PR02CA0073.namprd02.prod.outlook.com (2603:10b6:208:51::14) by CY8PR12MB7490.namprd12.prod.outlook.com (2603:10b6:930:91::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.33; Tue, 15 Apr 2025 04:58:37 +0000 Received: from BL02EPF0002992E.namprd02.prod.outlook.com (2603:10b6:208:51:cafe::64) by BL0PR02CA0073.outlook.office365.com (2603:10b6:208:51::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.34 via Frontend Transport; Tue, 15 Apr 2025 04:58:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF0002992E.mail.protection.outlook.com (10.167.249.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:37 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Apr 2025 21:58:21 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:20 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:19 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 09/11] iommu/arm-smmu-v3: Clean up nested_ats_flush from master_domain Date: Mon, 14 Apr 2025 21:57:44 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0002992E:EE_|CY8PR12MB7490:EE_ X-MS-Office365-Filtering-Correlation-Id: 47dec1d7-abdf-46bf-8ec7-08dd7bda2eb7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: poDcloyORX+DANuBed0lSD+xM+nvgkTl3Qe55aFFfccS/UnJdCvI7pD7Drckj3Oh5hkKGFgVtjJ3IKrGa3b/ZTwbBZDZg3OKZWN7FC5r5wUME+RvM31JnqmQnE62ySH1JciMr4KKXPjqcIlNcNKH4e35escaE3HulJ5goWOTtvGBRzL7Humm7QWsO19CdgDKXTSemQ5G7TmEN0HQmI6oOp5tlu3YwysfD5HDOIrQBWgfMaAFhq5tCYxws+D8dKBrbXM7LY1R/M2IsIHYA+JbwIHxq7AGhfs4bZh2cQ3LwJTwdsjCXQ3LlMYqynBGANcQteIgyo4ClYotRye9HWmdF55yPPV2qymw+amvhw15Xf0i0pnX10X8HdYlNtiN/CPGn2e8MsGJeMG7zURyT6mSlj4QRMvH/Lx3HevbNE/nNSEqE6eW3//FQgd8idonbGufyDBuV5oCR51n1P3norTNhrrQYav1HVrVxNIq3eT1y6lduSPsONbyXm5KSoyalBOnfAdV2XITIi5OzzoGJKe6uoSV9leG030EIA95CAnPnfJUG7C0tFP8rhY9HLDtxpt4KzxWbmt9TY/FV0rigMaMaSXNq01KFmywJynebEDR6nVAGXC9RJ1NBdB3Ll2u91d+rRR13Xq2DpljAEWLUCrkQ0SsGwND1p2YBHqAFg+6k9NAvLfk+4GFK1iSdEaDONFB5cKrhGB1ta+7UxK/uX0FNw3jotpTWNVdjIQ04wOqo4R6t/wJyDNL29EsBoJRaB+UpUJChgikIRyJu9jMY99TdwAfmMGjAn5KWn2HUGrU/hEklQJkZ05Asd8pI/8jYkSd4KYZHLHHR+X3NhKWSJd0KTyxSsNSwfJu0kPuova/tGpnVwUSilbdqYbfGMB3jWfQUj72GWALUjzNmwgzsx7XK+SaN0dSYJc9UX1+i4+HhT8MPV6wVHI/2xzYhq8mc4H9oskwYJEyw3GKPkVDxHOjEWMmqYdLsAK/JJ2IE5wORHEBbsA/1LGYQI6PY8MwT75wBSqcrlyr5Cov7o9Gatx+z14KEjC2xrj0uveUKvELdZC8DnA9NRpPa8bJLmoZm0a2iBY5P29kN2DISVvI4LYkbbjBQp+dn6lGDwyNGjOjnO3HBkYvq++64EzVlUNkRgpZsxOKD0Ho4ZI8th0prlB5EehVTiKC96mQnTG1mPFb8ReniszNse4bVtCQUAJTcy5qYYCpSPfRH9K4PfPqOfuMIGLlT7GjGUgiHbsqPgRtLlBTs41T2UFw8+A3zT2LvRI1UC8yuvsevWS4Un4ZRiGrbzetfbVx7vMwnOr8+K6raJhNCpeplHOdqPWKQQwD6xNAGJGdfqTjXkob3xgUjJeCamkoP31YN/svy1XJ8xQx7U0fgu/SsyVMMzxUT5j/F+Dn0+baB8lCkJTGqrAKB3VhkG7mIJ+P7bJrRQOsEELXyd+M3j0neLW3OLeNJhkzH7nNnY21MFAjtcCaGJXldcKX7bDcwl7EaGUPRk4GzQRWWZBkAmejyVyzhYSkCRsbd8VY X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:37.1472 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47dec1d7-abdf-46bf-8ec7-08dd7bda2eb7 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0002992E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7490 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215842_851284_565BA11A X-CRM114-Status: GOOD ( 15.11 ) 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 Now the ats_devices list is maintained per vSMMU, since an S2 domain could be shared among vSMMU instances. Drop the nested_ats_flush from struct arm_smmu_master_domain, and clean up the dead code in the related functions. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++----------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index c9b9c7921bee..477d4d2f19a6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -921,7 +921,6 @@ struct arm_smmu_master_domain { struct list_head devices_elm; struct arm_smmu_master *master; ioasid_t ssid; - bool nested_ats_flush : 1; }; static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) 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 483ef9e2c6b7..4b9cdfb177ca 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2221,16 +2221,7 @@ int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, if (!master->ats_enabled) continue; - if (master_domain->nested_ats_flush) { - /* - * If a S2 used as a nesting parent is changed we have - * no option but to completely flush the ATC. - */ - arm_smmu_atc_inv_to_cmd(IOMMU_NO_PASID, 0, 0, &cmd); - } else { - arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, - &cmd); - } + arm_smmu_atc_inv_to_cmd(master_domain->ssid, iova, size, &cmd); for (i = 0; i < master->num_streams; i++) { cmd.atc.sid = master->streams[i].id; @@ -2717,8 +2708,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) static struct arm_smmu_master_domain * arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master, - ioasid_t ssid, bool nested_ats_flush) + struct arm_smmu_master *master, ioasid_t ssid) { struct arm_smmu_master_domain *master_domain; @@ -2727,8 +2717,7 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { if (master_domain->master == master && - master_domain->ssid == ssid && - master_domain->nested_ats_flush == nested_ats_flush) + master_domain->ssid == ssid) return master_domain; } return NULL; @@ -2759,7 +2748,6 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, { struct arm_smmu_domain *smmu_domain = to_smmu_domain_devices(domain); struct arm_smmu_master_domain *master_domain; - bool nested_ats_flush = false; unsigned long flags; if (!smmu_domain) @@ -2772,8 +2760,7 @@ static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, } spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid, - nested_ats_flush); + master_domain = arm_smmu_find_master_domain(smmu_domain, master, ssid); if (master_domain) { list_del(&master_domain->devices_elm); kfree(master_domain); @@ -2853,9 +2840,6 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_state *state, return -ENOMEM; master_domain->master = master; master_domain->ssid = state->ssid; - if (new_domain->type == IOMMU_DOMAIN_NESTED) - master_domain->nested_ats_flush = - to_smmu_nested_domain(new_domain)->enable_ats; /* * During prepare we want the current smmu_domain and new From patchwork Tue Apr 15 04:57:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051498 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 2D856C369AB for ; Tue, 15 Apr 2025 05:23:15 +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=Pi7Lx8FzAFjge2/DZPsH5UQQz7ZzdnK46Pkn0ALEFGI=; b=ZFa/M2OpLSmJVdRjeGjBORlguv SGFFyosC+Zmew93sy3EPlYNgnpTLUtGUAU/Z5N13T2udp9xMXpHLWlGyU8zqTUqs9j86ghYoNRAJy 2ePv43GjnvP7xxUqpBJZ6IOJcUnDY1v2z5R+yMzV97aNKmxeF21/Ito0o2c6P9ibq7jyDp3Qs1IXo ytkPE9ch+ZCujoJDrss4BNn6MTJcplLzciZ9rzMxE1Pl8y4sRZl6ALrPsdmvuUxh+5ahkS9lY8790 mAJyduc98dr7k21ncb5DjJC2cUzi33wrqg+1ResYvPAEqG/4LpYuD4WbFzsik/CrvKoleE87Gu8b9 NBWF67LQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YlG-00000004Xpx-2qAi; Tue, 15 Apr 2025 05:23:06 +0000 Received: from mail-mw2nam04on20617.outbound.protection.outlook.com ([2a01:111:f403:240a::617] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNf-00000004V0D-22hH for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=w97QEKi28NWmf/9fqysJlgdeaP7bjlbIejJb2l2Ivk60oToUIG5X/j8grhx1T98mnhb2yPSs11wlhCuIu41FyFSVbYxGbrbEobIs0obbj9WXvHCUv51JlE2NXuHYcrVxHj2ONcLTIoBiKYSlXIdeGQ1iSi4FpPBgueNVmRmDtBMmqRoONjIiJJDsS3r/WNwoILZNlXehX3rgvRLN2sAas0eS4f6JacWsmTkg1QEXY0URcjVtncN1Muv+jbHTige4jxpBR93EQS37uNstyKjKBSf+Kbdz0JVddrRG3bZmx03qFjLJgYrTzfQDBbxWsQbPImuvbEQApT4NmF3qc5StlA== 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=Pi7Lx8FzAFjge2/DZPsH5UQQz7ZzdnK46Pkn0ALEFGI=; b=CxyQftZEE2uvYfXFlFVbGxwP0XZSKUEW+9BkkBopWXRRNGK32Zpi2Iff/Lcou52U8izsfxXbL64KNMD0FOhgR5c6t71dkPGvlpXYsnWOpCfngywbVnoICew2zQtzR/yoceWwHaP9FIN+a64lF2L4VWtUmBkX5CmsNIG2YPSDv8fnjZuAlAoqDcdDcWgvGqMepJx4g0pio0k+gokdhC+rO4voNGW/JCc45xd7Eq/qR5ItsDE8NcoL4RJikWSg4r8ua3AMbVMiK2Y0qyxqD8V9J76vhpdDi5/57wVcTEIgO+d3XQj39Hflhv7dH7Z0yeMtR2EqzGIg/MdZwajz8Qy3Rg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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=Pi7Lx8FzAFjge2/DZPsH5UQQz7ZzdnK46Pkn0ALEFGI=; b=tp/dVvax9l7GdIoPR9gK0h3rmpAKzlPz/4mjsJzsPOMEIfPjMk1VosecNAjIp1xf+wVeZuorrqv8wktRfqAtu17WM7/kK1uzO4anEE9lMwxlIhOjlZ3FOQI0PjD26frmGkQEkr1HSLgiLqmMzc0CcaE2ok39JVeR9LFQ8SQ48R+zzEvSdBn1l6rKpREsgp5RoTod8oVXBfhWPJURtLcdFPky7AkONtttRSSOPy5/7OKra+MmSgOIOzuNGiPD2vOj7DoATsmd8lb5e+2V4twL+kd2Pyw0vpb0EbASABClwcFklNUkWBYtWY4nEsYpgfLr4WwBocmB1dmilWJqUfr0GQ== Received: from BN9PR03CA0217.namprd03.prod.outlook.com (2603:10b6:408:f8::12) by SN7PR12MB8817.namprd12.prod.outlook.com (2603:10b6:806:347::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.29; Tue, 15 Apr 2025 04:58:38 +0000 Received: from BL02EPF00029927.namprd02.prod.outlook.com (2603:10b6:408:f8:cafe::a) by BN9PR03CA0217.outlook.office365.com (2603:10b6:408:f8::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.32 via Frontend Transport; Tue, 15 Apr 2025 04:58:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF00029927.mail.protection.outlook.com (10.167.249.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:38 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Apr 2025 21:58:22 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:21 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:20 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 10/11] iommu/arm-smmu-v3: Decouple vmid from S2 nest_parent domain Date: Mon, 14 Apr 2025 21:57:45 -0700 Message-ID: <74495f4edb0d80dff17cf0ab9fe13c29f55b7502.1744692494.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00029927:EE_|SN7PR12MB8817:EE_ X-MS-Office365-Filtering-Correlation-Id: 68572d6e-6665-4165-c15d-08dd7bda2f6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|7416014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: bLg0i1QnmpCqVUakPXvuKukKbZnIe9sUEzp605Rc65lXNS0wfTrJdSutBmKa5GoUpirwfEm5G2MlfCKx40BToFYkfsWDrD+7Oo8dnrjrKL6u90UiMGIywAv7Wuv+wekVSvo3IZmC8H0shmng3QhP+uhH1st+IaQcxnasZcggIrr6B7oLdJ6UOF2e8pTKMC9/ZNgcXjVOIpW2YE7KN/oc2mwN4xuFYpZUL6dXpMDzVJD3eKavNGa0puJ+A2Lqv3L5cCcz1FtrHejh7aMK2BdrY50V8zUK4OL6wi8jzXp7hgXJX4WNpNbQYx9qEwXz4uO+iT9SB1TmplFt/vH6/KgXQcbxybluvixvHK4m4mvh6cmqdvuJtvMgE5Z5lZSkXB7z7EZ6R97Va3Q97zt5DuMd4Co51ikJ4P9I6xfBzYQwio3p3cyicST+UskmzBw+pL6NVaUiG7krasHIJlLpl3v0a7stLBUx9VxkHTRGMWYMQbkQFmJrrCHGF7BtjlG35XGQQ3Jcrhi0u+1IloxtwKak8nPE8BamJjkJBO0Di43wmRoH9DLW+Szm3WqilZRD+PCPxMmcWsCEFwDrccItdHoECarj8ohYsJQykALWuLRUi3VCAWFlaus9huROl8OZ13S6XEXgCaZMSgC/Y9EZRpo9oqK118b/mICGsqgVkgDe+KB3HjSs2syTxGDmawN8aIH7b6DI48fwnC9lQEDH9xdXxz+L1KExecG6mW+TYU1y1kSHoSPJDnbyVJ+cRnJpS5+8VURRGRfCeE8uIFhFQHuXOZKjckWWay3wX5j+WOantHHpHiocTkNuWZQQmEVtze6lGK5MFV7vC7w5y6clS6YW+0SiH8WWj1I3c9gRosjjr5djzcjhYnewqEt02Dg2Y1yBwVnGNaocNMTsTdA1cwp5APWSeaJqn8HycsMJ/d2Fj1cuk38z9sOW2+iCawFvH41Kgspgw9XIEyEupmt66Erp//Dng3j/qW4xvIaudJaTonNZQxmrF9DtZRLBoDF6mrUTBX82AHZVyCKnz4jnmZtNjb2P0UUAzxJKqPImkDc6TysMM2pENX+j541oRxI8nJLWS1RIrwrN6bygV3EAgz+T8j7n0Xd7Qla0F//egpP5S8m+A6yeX4oxj7/ReUVMPqKaen+YQXH6dQvK50w6Cgsi6SsGq9Hkbts+jiyVv9CdTjTep6jFmpfo+KxiABCnoBsJNNyDFq377yLm6/vpEwrT0O2N4ShkHYlUxJVA39dQlTglWTqNFo9QKJ9dyJImMkld7CIOgnHqpymjMiYVoKiBBoi5syYwgkpMijqtG3BuyHmFQuEohRJvJykuznysBv+RMh6A3P2fNeyB8mYwGsnVAWbIeqI1vM/Ud+4YooER/klJvOMCTB2vb8qWwJINPBC5WExNm2ck5AEyQywRbIeP8XHaGOgcwK6k/u8voRxRmbXdYzeSH5UayqjAqNoxcQ8tdxAyXhYFkPpkUY9dH6m2pSVgeMKvUtRl7PekS3IGMcvr5bCTBzGrDq5dgPG9WGiB X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(82310400026)(7416014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:38.3190 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68572d6e-6665-4165-c15d-08dd7bda2f6c 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00029927.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8817 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215843_518973_ECB2A24B X-CRM114-Status: GOOD ( 17.14 ) 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 Now the new S2 invalidation routines in arm-smmu-v3-iommufd are ready to support a shared S2 nest_parent domain across multiple vSMMU instances. Move the vmid allocation/releasing to the vSMMU allocator/destroyer too. Then, move the vsmmus list next to s2_cfg in the struct arm_smmu_domain, as they can be exclusive now. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 12 ++++++------ .../iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 15 ++++++++++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 477d4d2f19a6..dfb9d5f935e4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -857,13 +857,13 @@ struct arm_smmu_domain { enum arm_smmu_domain_stage stage; union { - struct arm_smmu_ctx_desc cd; - struct arm_smmu_s2_cfg s2_cfg; + struct arm_smmu_ctx_desc cd; /* S1 */ + struct arm_smmu_s2_cfg s2_cfg; /* S2 && !nest_parent */ + struct { /* S2 && nest_parent */ + struct list_head list; + spinlock_t lock; + } vsmmus; }; - struct { - struct list_head list; - spinlock_t lock; - } vsmmus; struct iommu_domain domain; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 491f2b88e30b..5d05f8a78215 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -118,6 +118,7 @@ static void arm_vsmmu_destroy(struct iommufd_viommu *viommu) /* Must flush S2 vmid after delinking vSMMU */ arm_smmu_tlb_inv_vmid(vsmmu->smmu, vsmmu->vmid); arm_vsmmu_atc_inv_domain(vsmmu, 0, 0); + ida_free(&vsmmu->smmu->vmid_map, vsmmu->vmid); } static void arm_smmu_make_nested_cd_table_ste( @@ -511,6 +512,7 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, struct arm_smmu_domain *s2_parent = to_smmu_domain(parent); struct arm_vsmmu *vsmmu; unsigned long flags; + int vmid; if (viommu_type != IOMMU_VIOMMU_TYPE_ARM_SMMUV3) return ERR_PTR(-EOPNOTSUPP); @@ -541,15 +543,22 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, !(smmu->features & ARM_SMMU_FEAT_S2FWB)) return ERR_PTR(-EOPNOTSUPP); + vmid = ida_alloc_range(&smmu->vmid_map, 1, (1 << smmu->vmid_bits) - 1, + GFP_KERNEL); + if (vmid < 0) + return ERR_PTR(vmid); + vsmmu = iommufd_viommu_alloc(ictx, struct arm_vsmmu, core, &arm_vsmmu_ops); - if (IS_ERR(vsmmu)) + if (IS_ERR(vsmmu)) { + ida_free(&smmu->vmid_map, vmid); return ERR_CAST(vsmmu); + } vsmmu->smmu = smmu; + vsmmu->vmid = (u16)vmid; vsmmu->s2_parent = s2_parent; - /* FIXME Move VMID allocation from the S2 domain allocation to here */ - vsmmu->vmid = s2_parent->s2_cfg.vmid; + spin_lock_irqsave(&s2_parent->vsmmus.lock, flags); list_add_tail(&vsmmu->vsmmus_elm, &s2_parent->vsmmus.list); spin_unlock_irqrestore(&s2_parent->vsmmus.lock, flags); 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 4b9cdfb177ca..8047b60ec024 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2474,7 +2474,7 @@ static void arm_smmu_domain_free_paging(struct iommu_domain *domain) mutex_lock(&arm_smmu_asid_lock); xa_erase(&arm_smmu_asid_xa, smmu_domain->cd.asid); mutex_unlock(&arm_smmu_asid_lock); - } else { + } else if (!smmu_domain->nest_parent) { struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; if (cfg->vmid) ida_free(&smmu->vmid_map, cfg->vmid); @@ -2503,7 +2503,10 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_device *smmu, struct arm_smmu_domain *smmu_domain) { int vmid; - struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg; + + /* nest_parent stores vmid in vSMMU instead of a shared S2 domain */ + if (smmu_domain->nest_parent) + return 0; /* Reserve VMID 0 for stage-2 bypass STEs */ vmid = ida_alloc_range(&smmu->vmid_map, 1, (1 << smmu->vmid_bits) - 1, @@ -2511,7 +2514,7 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_device *smmu, if (vmid < 0) return vmid; - cfg->vmid = (u16)vmid; + smmu_domain->s2_cfg.vmid = (u16)vmid; return 0; } From patchwork Tue Apr 15 04:57:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 14051499 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 7E77EC369AB for ; Tue, 15 Apr 2025 05:25:07 +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=xPg8r9+qxP3FUQR7JGslU2hw0AcMpptvhuQODcbrUBo=; b=u//Y4weNvpPAJUFhX1hGrSKPzN lB4xSg+3wmAmNYz4ULzAQdSr7aj/XBZookHBwEoLc8Q4msC/cC5BS59EQGTNXLSyjpCzpFBCGedtW EndnOsaQXn13aztifYUa90xWjiGPOyYkOcs/vRND9a6FSSM//AmjtxF7DaQs4kjwY32OOKmEG/6IV 5wsti3WwIIv5Qt+agv9wlaa20uwzvUwObgs/ywcmLQi+0Juq3Fc5H0bcITf6JSupxtqc0GmquEiex bLYc4mMD/ADkPMa9eyMgCSjERNCJT+owrGHa1hF14EVYPdUb1y2wldG0orrq7Dv+yAvfPoEooKATO MmlAsCNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4Yn2-00000004Y0y-1TR2; Tue, 15 Apr 2025 05:24:56 +0000 Received: from mail-mw2nam04on20613.outbound.protection.outlook.com ([2a01:111:f403:240a::613] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1u4YNi-00000004V25-0XXa for linux-arm-kernel@lists.infradead.org; Tue, 15 Apr 2025 04:58:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a9/Y5i7PvBkwkb13f4rszRPwY+ffud2NFIBvnlDhn5LUg0cog+wov1sZtK9lYxb8Hxu/LaqORSJj7RT6QJWUOkFHAkE95zPczYpp56xr29FlDe1ic9ydSmhOsBhZPzKi53SmrJkgrHOXzhYAIXxs2mVWonOc60VjcJQtVSSZFbR3aT81ohJlYkVauBpmkolKTS40jfOGYBNYga8A10foKIfPDC/RPGhsxUi0p9vIHqoXlqJ1aX4jx2xwPZJEeDZQLa9BnL87ZJg7el54I1RErmoT/QvhUjEwB4BITBKn9UWiUxOYTMQ2YHZ32e+PSHA45QgTwoq9z0j/CpzqaJ7Vkw== 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=xPg8r9+qxP3FUQR7JGslU2hw0AcMpptvhuQODcbrUBo=; b=qFE4+KQ2XXAcGOMVL03uTNwcVReQ413PVDoyKJDkPvIQGhLieSLTYqttNhJPG3TRFFyl9LL7v/1nKufN9t4T6GuOvpRRGq78CMDUONsSgj1KtmzRTXpbsI4jZOOxuzTdkgmK11AE7gWNNMrfjnkgjI2vBL805nbxwqMPXaxLvRyOuz63HLy0373Sb5XuPXBCAH7l3QXSz0SvguES1SD+Zqjv4nOY/VYIP1VLcEIvO2bhc6UWs4jmRl+I9bsSf/9tOEA1arN8AwY3dDyWVFI9cqs7BClvaeipvRDACxL4D52TSuwjQ5+bNGlMk6obDbFrQpU1ynsrmm0jq2c46+Xy8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org 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=xPg8r9+qxP3FUQR7JGslU2hw0AcMpptvhuQODcbrUBo=; b=Sa1tXXKMyqI48eFANd1PhAgvIhqehlRLDEPgw897nmEYeF6rlwAB8tpbFN5Or6BSWiUDMVHpuf61KI0qP9J+UvOlhWF/R6rOlukGVcBW7gA9ZR38/ZAL0cNb5NLiWzLIk5fvKKwkyWz0YHwnvmLFE4qx+Fv8Cr+ctv8NmfWECXsYJPWsqr/Nr49aSjizECFulaLTifeBUIcidqGx2BFUP7aJmrbnsZ49ALq3cGNRZZ7s+fcj7sO3cGgP0r/dmJ4M49ywZjULh8yMw93Nq5GxX11a510RCIsanOk4RSC/eD/CEpOtO7a0qid2fudNhzHLynU+RYoW2yCHYvPnQ1ujOg== Received: from BL0PR02CA0076.namprd02.prod.outlook.com (2603:10b6:208:51::17) by PH8PR12MB6844.namprd12.prod.outlook.com (2603:10b6:510:1cb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8632.34; Tue, 15 Apr 2025 04:58:39 +0000 Received: from BL02EPF0002992E.namprd02.prod.outlook.com (2603:10b6:208:51:cafe::e9) by BL0PR02CA0076.outlook.office365.com (2603:10b6:208:51::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.34 via Frontend Transport; Tue, 15 Apr 2025 04:58:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BL02EPF0002992E.mail.protection.outlook.com (10.167.249.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.12 via Frontend Transport; Tue, 15 Apr 2025 04:58:39 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 14 Apr 2025 21:58:23 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 14 Apr 2025 21:58:23 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Mon, 14 Apr 2025 21:58:22 -0700 From: Nicolin Chen To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH v2 11/11] iommu/arm-smmu-v3: Allow to share S2 nest_parent domain across vSMMUs Date: Mon, 14 Apr 2025 21:57:46 -0700 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0002992E:EE_|PH8PR12MB6844:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e74d588-f5c6-4b84-e04d-08dd7bda302d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: Feaa/PIdfZS7IN2u+8jdzgbMB9CLJef1g+Jv48viimOzb1pXetgTyKELurvLRsxJty1LuByEKRo2P2iAzB4I8sYWamCPo0ClYex9Nd+pjsInFtsXUN/wWyfyOzwTn5fD/t2GEKK7XHVetN6w8VrQhJNYnQgD4Q4grvNPOJyYEuYwAJsmEqDpQUhqsiM2x4KXGk4tZn6/bC4HjrfhYiIZA30qgHXRKEdhZ9FJ3M5BKrTrnPlUO7KZFI86zGW6rzC2Vp0VXYlOm94vgOLGmWGsabce4aryRfAlFmvkoQW/jeapuISb8VWmT9F5lbZywz9vaV3A+DskcXfVZwqoqSsRv+r+4jNmRXwxbDQyh53TM5phJZ7eRZ6DVc0jNUpObaZfa8wRMJKgwpMkbn3NZGv/GPxD9fHcOCiEc+x43FEm8WhYfwv/KoZTqZZlVI/GSnNiFNUONdrCEeiRWpx4JBmnB7m9lD4W47masjjbSvYS2xIAgDH0byUdmJBHfpulwfSkCSedzpZMg7h0XrfCahfb5DvcZ6Rez+ZZLzY6b2itsfqrtb41Gnbu6P2Wx1TFRc8D4RFUa3yb6smp49V5ozmkYZM4QFsWqBgua98AXvMKSFPTDdMNM4I5SdrTwamu3u9SL4XnA70qQJ2LNyD7yVrbl7QAV6i2w+GYz7d2Hv++/6v2SJ3e9BtGznkg8nGacZkouKDLiK3zXvEZWiIqbL2EaeAyl0zDHBxQZ9+xxBYg/SVG7jxxzbh0ILsFn6LkdyD/TFTEcgD+YcWWdxqr5MtFO06S3mGMaQx3TOsdnMBhuorGTwN+z5hGA+bh+j08/vRUX971MNYuBtPK/Ip/TSZJPwHdIKyvc9KleqRnnyjfT2jY1P7i4dnqXtlZ+1kh2Fp3a1xB0OPGGHxb3GT/hyBwTeQMqiTCL8li0XKWA+lwPIN4ZayqaKwH1qSeUdVIubrfWrdee1H5d3m8LpYFzVPqvufuH78vr7yX5GATffHVTlGuWALc9RjLrXlwPd/3KdKtHCHKov+wU6/mk6yLt/8Ndd+l9tepWxa9nPL6SCZix2EY6KM1dN1lSZo5Yx/xKKT1SF3+kql5tvzSlcZginL19drxucBRf8Qcy/Jt+Q16++ov/i8UgsAfREWx23hXw9KFTqF9Uq6hZD1A3dpqe3k60RaWhWvkZB4M2eEkJ4j61X5cyZpNuNxyCr2mRyExCPgy/ohtI3599IvcmHU25XgxzEXdJuaxcs3h2S7FhVrqlPX8vHBej67TJWOLeEZg3Omku+boNkQFHfoyETjBOP1k+U37qekUoJI2KVHCfpGWXF/QuuZfxWeThU2+a4TPjKL3cvcwDtkDfAfLi3Sp6HoxUihaJZCIiwk7CtJCgNazix7LkdhxqIG0AfE8R8JngVXHC7etd4Z/iMdPD9lmPTzF4HAdH8+IBw5h4C5eO/JADJq0OOJUGw3KAl1ocvSq2LG0ppia3K05kXy+ZV9ChyFDHs/4DwLUAfb5itbq4ghgiWnrWe+2uaP7zBStPwQ+Q+ej X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2025 04:58:39.6003 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e74d588-f5c6-4b84-e04d-08dd7bda302d 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.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0002992E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6844 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250414_215846_182439_6FEA9C26 X-CRM114-Status: GOOD ( 14.09 ) 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 An S2 nest_parent domain used by one vSMMU can be shared with another vSMMU so long as the underlying stage-2 page table is compatible by the physical SMMU instance. There is no direct information about the page table from the master device, but a comparison can be done between the physical SMMU that the nest_parent domain was allocated for and the physical SMMU that the device is behind. Replace the smmu test in arm_vsmmu_alloc() with a compatibility test, which goes through the physical SMMU parameters that were used to decide the page table formats. Signed-off-by: Nicolin Chen --- .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index 5d05f8a78215..f654e665739a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -501,6 +501,25 @@ static const struct iommufd_viommu_ops arm_vsmmu_ops = { .cache_invalidate = arm_vsmmu_cache_invalidate, }; +static bool arm_smmu_s2_parent_can_share(struct arm_smmu_domain *s2_parent, + struct arm_smmu_device *smmu) +{ + struct arm_smmu_device *s2_smmu = s2_parent->smmu; + + if (s2_smmu == smmu) + return true; + if (s2_smmu->iommu.ops != smmu->iommu.ops) + return false; + if (s2_smmu->ias > smmu->ias || s2_smmu->oas > smmu->oas) + return false; + if (s2_smmu->pgsize_bitmap != smmu->pgsize_bitmap) + return false; + if ((s2_smmu->features & ARM_SMMU_FEAT_COHERENCY) != + (smmu->features & ARM_SMMU_FEAT_COHERENCY)) + return false; + return true; +} + struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, struct iommu_domain *parent, struct iommufd_ctx *ictx, @@ -520,7 +539,7 @@ struct iommufd_viommu *arm_vsmmu_alloc(struct device *dev, if (!(smmu->features & ARM_SMMU_FEAT_NESTING)) return ERR_PTR(-EOPNOTSUPP); - if (s2_parent->smmu != master->smmu) + if (!arm_smmu_s2_parent_can_share(s2_parent, master->smmu)) return ERR_PTR(-EINVAL); /*