From patchwork Tue Apr 23 13:14:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13640071 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 C4FE8C10F15 for ; Tue, 23 Apr 2024 13:15:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=HA6rHA2MtUEsJebggK16ZWRh2LvoSvFGPhXoWmlBrjo=; b=N2QRcOHuHZkslq V6+jx+vj29ch5WvPGCYgDI5rQEmcuzpiTvk7LSFoGnAnmCoQ757fevWJk7gKAIdWivH1kuoKh/CLm QajhgzKHw8CrDvLdrSjJ/lCe/AZ0fG8IT1wgHpxC2x9egAdIX35pgubowBitEL3SDPbyYTeTE9ml5 UpivL8CZizu4PaQOP8KhgTZWJ1bVGuV/0SDbHxbZ5abe+8YI52LW5MmhLwRHOwDrZn5t9GU1gNyVE pdRU213AN37tD8wHQqxDApZnLc5OtO4dbBn7Z6uprMci9bWEyuOeMSCJ5YVeOuf4vBA4uD7+3eUju 0nDPnk/Rgyn5rL4iDABw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzFzF-000000000nq-2dzE; Tue, 23 Apr 2024 13:15:05 +0000 Received: from mail-mw2nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:200a::601] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzFyu-000000000Vz-1FmO for linux-arm-kernel@lists.infradead.org; Tue, 23 Apr 2024 13:14:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xhiq89R0eL5Er705famNhbnFlEbXJRnAcpf9EXS0beeHN2R8EHULBx44gcvEGriUtDeihrnx6hI9fhjBRK5r9gs9lFb21QFqH3ZrTwnE3ywQbM74df1sb2UFh3uDxfRt7Cqkf3f0A13qPRpX/LWRGjZgBjDxIAcxMHPaRklWHV3q2fXSk5RvVqGN9NSLoQl2mIzFR1AVVib6170H75UOpwHYP8/Q96NlrKPjemnqTpUeMKmfGPf8i0yBYHoUZKMvYaZ312OPWJfQdbBftoieR/J//hVNbluMxfuR3PxJ8Y3wcwBbKzCvDisrVV7y9lbGmo9AQMHTbdFBJd+NqUVlKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XocpU0tFjlHL+rmZCrfxaLKuFktrIUjMB+U9J7W3n9c=; b=aS8EdnLR4uytMOXckzQx9zJlnsTqs3q8sUuU2tUr4m/Lms9Zalxrks45qYWfpu5CdUcm0yx/hEVZFl60yjPFHU9s8EAHrQUsCE6l5bfVPGCGWwBLoHIAKTK5Ij46ubTUbzZJrkEd7yWS52L3EEmJuTfpibYhof/qctFkxhUAhBb71ha/7lJFXOtfFGKepXk4rwaOTx/scOk/puEZdqloAe/WvMawrEUtNNYEF46NH9RBDlmr3GMNTwqrDMeQYwNBbdb9KiFehjqUqfDoNE1NKIrp4OhxlIee8w6GzcNQchi14hcv63yYT3gCzJ5NjgZHqECx08O+4OceYs/moJrfnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none 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=XocpU0tFjlHL+rmZCrfxaLKuFktrIUjMB+U9J7W3n9c=; b=gNKnK1FNHIPVOVQk6dsht9rYiOGF+F2NhGI5NWYhJTN599UVhIyX1peM9JoDuPjL0r3WoR3B1UpRRQjOS1QzlOwJwGo0S30HDleeraTK5BLOCJOSAtJ+nunUwyVwivXfAuWuctg8L/WytzmHMlB+7nPwXVQn1pc/9GAaOk5mTDtdOcTReFEAsDBA43n+6xw2FWPV1kYo1LtKK8S8Rd3KpTBjBaIlpiIL+krDLpyQah/p/DCfawLctYBYKSQJh52LXzd0nIiJOS46GN84/iPVmfrN9w76YagZnIzVkCVmVUfsLjXxYQjM0GGQjdEHelV1+m0wzHC69sWqqPw6z/NV9Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by BL3PR12MB6593.namprd12.prod.outlook.com (2603:10b6:208:38c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Tue, 23 Apr 2024 13:14:16 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%3]) with mapi id 15.20.7519.021; Tue, 23 Apr 2024 13:14:16 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Eric Auger , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum , Mostafa Saleh Subject: [PATCH v8 0/9] Make the SMMUv3 CD logic match the new STE design (part 2a/3) Date: Tue, 23 Apr 2024 10:14:05 -0300 Message-ID: <0-v8-4c4298c63951+13484-smmuv3_newapi_p2_jgg@nvidia.com> X-ClientProxiedBy: BL1PR13CA0373.namprd13.prod.outlook.com (2603:10b6:208:2c0::18) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|BL3PR12MB6593:EE_ X-MS-Office365-Filtering-Correlation-Id: 591bd20e-fcda-49e9-732d-08dc63974669 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FS/FFva6/ZNSeDp94n1r8IkAyL0/Rn+p7/WY3M34k+5V8nNfnnF20b8prLQ9ZDIOHTBNiIiECQRpoW6j93TKno2DYJ9a+9CnIEo6lcok32s4vfWXwQYiIDZIKL/89mdWcpJ1Ar7521c45FitaGRY5r9Dzc1k0V3uovGQAOJlJz5/xkWTcM0x5260szpt5eH/kZ3oMzRcemzPbjf6+ZXJCyUN1lvC2FgEHK4o/zLTqPhJc993cBTfP2iQyOHpHqbDXWS9qV5SAGm6nUYQMliSbA2zh6u3XL80pfjB7w9NmnIlL29Qmrqf4NyAd7RvBDgrbPFxwVIdG2RbPyZ+KI48hSKVX2Aqc6n4tHyOfxjGbK6ypHQmTuuK1P6L+maRI4wrVW7WldN6Hyl4/UHKQubr7L433ctWIZUQyPKqG896jHn8MSa5iPXi16kDb85q/S2v9j3TcA89f+GHwFnoJeEXaD1hggsX4oc6WXg2v5aMP/DyuZ6c/csjGi/c6943Mf2c7Gx6QwyoIrCEuxz21CyrpdZmA5n38hS8s8qlAtblnX+hFOqxcCXBfgV3apcS2Mz9uuSYAQI50IDwoqyH+wwCB52t/XMBkE3cMj8yBXRUEXTiKVgeC9Hh6DPjfApEDrVEm+o/XlcZxv4hRNndhNmEB1N95b61VReZOz0rrgEVV+KjF/lbee02YYRzsKjToF8lX4JjcnALItTvkMeS3PYwpxo2QgzdNj9HTZPc3jQc2xTQnbFCec1LQryhqgphI+UNre4J3kYHzxlHU5WbnCTLSFWnVLi1cVbZ1zzrIEEm+WPPTr8PrPwoXE8gKMzcNu7K69CHEVzHV5y67wbygSALPZrunSCTk7CiHLyDISb+Yh3/u77X6+JdJ6RiFStgz5+9O5uEDZpJfS8v1sU4YgiOyD0iNv9oEUNKM0jG4oLBumuM38QUhty/e9LZN/zDJNBq47AUOOVAYMacQlkjvP5grdnX5UNJqHjmuavdVwCDKRGk2Dv23omM7kZnLgnhvAUdWG+B0j6tXh17JORDFk1moFxr8M6AIdDvOrpIAsHdI7qk+WkHpLoo1n1qaRMWh6bmExIw/TcchQFUDdK5ExYED2Ss+2QZ6kl6FjaWEdntt/SBXrs/L0aILEkKexTJx1WoPB3R33eKFoV/IwyKRhu2WMJeWrl1wtIpLLlCYTZ3wBUqOlh+PpltQCpPnS6h2XnT00kWHfzSjRDwvUMVkei/WhxgBvQ1UYpnaNv5c7i1b0G8fqngy3pmeade+LgjAf2OSfIMUn+SCSPKlP/Wj3WoIg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(7416005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xDBGPfgBq9jYa3HqWAXwJo7W7QSy/frRaawJBE41nohZb3sU9cvjVmz0a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aoUKIT//lWXJi94uGRBKbIcPyYYtqL9ZOec2mx+lYDQAxV8PjAKVDdUMN8fw63GSdd3w2XawchvjY9+cE5eu6mKd0paA0EFWJLv6GtoYqvB+8250BaG8zjbSHK6JWU1QgSdN4bo8OGbJlyGrVoOe2rzJadyfuI+n4jrW2XKEz9EiG7jaNVfyAtWY6S6wJxx8NSDPprhr0hDuIGUeK3HBm6zDua+nYtlr446pghK7lkzLhtv03L2GMbwLhFX8kw+t1T6SQREYs43q8GXVdHWR8QpKIZoNbyLgmdv2D7OkHzeeEG5JKhCTx+abYoTCQrE1i1uoMnw+dpmpj2KkjPbrVfIVitOKH37uaZAb65UfdoSUCFqRaiThvqbueF746qHfQji/ZsVgpwiAkTbb/dW9qxSVb0r+a0x4ELNHQT/YV0B20JbPdwibBxvAkho5eKjLzOb6P4ZdbJW6BQyIDqah/283hoPIn0eZhBzueBOoc X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 591bd20e-fcda-49e9-732d-08dc63974669 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2024 13:14:15.3396 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OsYKg1xZHen1hYn1ZySNzpHt0S1ZtQBwRrVVdM3RK0oyxBr/jtWCrwOM9rK3WNGY X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6593 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240423_061444_369890_0B37A7BA X-CRM114-Status: GOOD ( 14.21 ) 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 This is split out from the larger part two which aimes to rework the PASID related code. No new functionality is introduced in theses commits, it just reorganizes the CD logic to follow the same design of the new STE logic using make functions and a single programming flow without leaking details to callers. CD does not have as strong a need for this as STE, but all the code exists and continuing with the same pattern makes for fewer things to understand inside the driver. The following PASID code makes use of this to rethread how the CD programming works to take a caller created struct arm_smmu_cd and then stick whatever that is into the live CD entry. This allows the actual PASID and CD logic to be general and then the PAGING and SVA domain types can sit on top of it. There are four kinds of CDs: - Blocking (ie cleared) - S1 PAGING - SVA - SVA with a released MM (all fault) The last two have to transition hitlessly. v8: - Remove ops->v_bit and just use entry[0] = 0 - Revise commit messages - Revise comment in arm_smmu_get_cd_used() - Move hunks removing code from arm_smmu_write_ctx_desc() earlier for clarity - Consistently avoid CTXDESC_SPLIT and remove the macro - Don't check master->stall_enabled for the STALL_FORCE mm release - Fixup rand config failures on the kunit - Use VISIBLE_IF_KUNIT - Move more mock structs to .data to avoid stack frame size warnings v7: https://lore.kernel.org/r/0-v7-cb149db3a320+3b5-smmuv3_newapi_p2_jgg@nvidia.com - Rebase on Will's for-next & v6.9-rc2 - Split series in half - Include the kunit test - Update comments to refer to the STE & CD in the writer logic v6: https://lore.kernel.org/r/0-v6-228e7adf25eb+4155-smmuv3_newapi_p2_jgg@nvidia.com Jason Gunthorpe (9): iommu/arm-smmu-v3: Add an ops indirection to the STE code iommu/arm-smmu-v3: Make CD programming use arm_smmu_write_entry() iommu/arm-smmu-v3: Move the CD generation for S1 domains into a function iommu/arm-smmu-v3: Consolidate clearing a CD table entry iommu/arm-smmu-v3: Make arm_smmu_alloc_cd_ptr() iommu/arm-smmu-v3: Allocate the CD table entry in advance iommu/arm-smmu-v3: Move the CD generation for SVA into a function iommu/arm-smmu-v3: Build the whole CD in arm_smmu_make_s1_cd() iommu/arm-smmu-v3: Add unit tests for arm_smmu_write_entry drivers/iommu/Kconfig | 13 +- drivers/iommu/arm/arm-smmu-v3/Makefile | 1 + .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 164 ++++-- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 465 ++++++++++++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 504 ++++++++++-------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 53 +- 6 files changed, 903 insertions(+), 297 deletions(-) create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c base-commit: e8e4398d53f98be7ac48e0bda9ea6e26df24136d