From patchwork Tue Apr 30 17:21:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13649709 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 00900C19F4F for ; Tue, 30 Apr 2024 17:22:28 +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=yCfgLeuMEYiNBuOUbubVnsFp4k+h/OWKWBH4LHRmyas=; b=SP5jHjzG092Ti4 qKI/Q8NKu6S71F87ibPQOBTvZhU6/ci8o3FQzdJBDI8ZFRTDr8levc8aTWLHjZCV9o8j41ogCoOKG b376cS3pm5keBcQOzkZtxQOTJnune6GzmQHsQ5sM8lCMDMj/i52Fm+gEP013XuXSgjFWBJPn9rw2G hIyKAXNVdIjFgiSX36GhYhFkXnMjq4IxLCJ4BOSHIFrfT5/8QZkpWwINbZESmZ5ve/VC1bMS7w/9Y z0TgpRCYE1JG8QGGdvtCMIGcSzZLo3GnlxhpbIHZPMWgdgUxWUB1VurqtLG0CiwhodMD9Om2F+jb/ piGEhyPc2aIjpSKU57pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rBJ-00000007Ojt-2zGJ; Tue, 30 Apr 2024 17:22:17 +0000 Received: from mail-bn8nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2418::601] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rB4-00000007OX2-2H5d for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2024 17:22:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jg2GNFAVV8PfYVW/Y+GEpzcdBBOIbD5w3RFr3c0A0htsWiBXR10t2Aclag89PAcZck7xRPPFDmGWkYiy2SXvcq5eGx2MGGkATdGtHtkTTmPAT6l6T17bsojIJduh7dy5BztcPavRaFaknRekuzoficsj6Sja6IgMM+0DRorTxwcOcPwHE44+vaZOXqWhHXnBzGhowVze3D8oUsju4Z1iTZzOxUGbjVeY/tJygNh26mICyrGCmPUkORw79IjUNuMuoRpLlJh+2fZz1v9MxZYPYSFGGVga370x7i5EOPVm3L7MB5VMyj/1DATL6xukCBQB3HiokgR2i0a/9HVQ6S/PfA== 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=8iPtGTT05UbcD/zPgD3HjFeiQfpFkOFel/L2sCOlTIc=; b=IPMzMUDyvX8OSHMCenqrNInZLL4j7HkbNpcB0kRBS/h/1iR7T01UL0LMnQ1JFgDy7TW44xm5JUX39WR8+etFRnp82wJbAGCG1gLk6NtC0Q0aOrGPYNOVpF2TTO8o30eugt8f6dV+QMKw9jxDaZf8ZLpmd3I+18yKqRRayL8ktz/XT7tMt2NKv7H/AClr5myWupTXB5qoZ3lECm0IVDyYAkgJ+KyN43w5TvbEFCKzzopLJMzpLP499ElisGHB2Sg7PRlk6BWuPO06n+plkbI4etk5OW0ULWjxfl3Gz/4mM/lsRZ9wj8QVy6zSRgfMAwcUGy5/MPf/Hcqo19gOJ+XEKA== 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=8iPtGTT05UbcD/zPgD3HjFeiQfpFkOFel/L2sCOlTIc=; b=lDp3KrQA8AitHGIg/VvpxgMu/9HbkIRnWLGhRRAaxj7wc5MW0/R3VgZBILAEoc1YRKxpkJaLSC9bUP/cqvHA/aHZu6AIVKCZgKfoVmuWQ2NTTmVXi3vqbY7MwgpdNrLIAJCPR7zmQ+1MyLU7nFRUBMjR0TTx8SBzdiYTAISe8ydSTNw96KaftO0v2zwmj6W5BVr3QbcFX3I3y7siJnqeHy/AQLP5SWpciOQVMd15soDzLAnI1Nff0hjROVbfm6AA22v5rsgt4Fu1G/rqzUOyIYbj9k7rUE31Bo+pqft3ArfX559eQp2eor/X2W/CWDLgGpaYLbUyFczRGF97cOiDWQ== 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 DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Tue, 30 Apr 2024 17:21:46 +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.031; Tue, 30 Apr 2024 17:21:46 +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 v9 0/9] Make the SMMUv3 CD logic match the new STE design (part 2a/3) Date: Tue, 30 Apr 2024 14:21:32 -0300 Message-ID: <0-v9-5040dc602008+177d7-smmuv3_newapi_p2_jgg@nvidia.com> X-ClientProxiedBy: BLAPR03CA0135.namprd03.prod.outlook.com (2603:10b6:208:32e::20) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|DM6PR12MB4172:EE_ X-MS-Office365-Filtering-Correlation-Id: 50524f7a-1898-4b28-6ede-08dc693a01b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|7416005|366007; X-Microsoft-Antispam-Message-Info: 7W4PBdhey+XlYwXewuOz0T3iBvPFlOYBephlbNS2mV/XGXenxah43ZySSJQwk7jGIAA1+2xmbgO7IqUWPW8nWfIez2JgkUJLSLm/cE09rtlazozbKvIIJUCfsGgE6+AqD0VhZ9AFcCA3GHBl0F1SEwcuVXrZf+7Mq83YQr33JSKt0ANI2efzWvQHOkLJ1f5R6LyxXdp5DgB07CkZTUxBBZxbln2tpLhX3Oc2qXf+lpsViQCqEtdK0FbleEv5vj39fW+a3KAkznx1JOceA17LIGK4UfmQ510T4bu9wqTBD9uynW4ojjUR+BmfQ9IyCc7uXifAI/3IEXmDdzF3DynLzXx9jSnJRFxgHihNzMRvNaMzIu7ubIuiW5Ba47ryrAPxIlLC0cvKmmkGNAPRqxlhMrPB/0lXkvJria7Tu/2MffW/vQ1xJcOvT/g6HIPN12czHMZogPjnHSLxt62eg4CM+82NhaJHf7aO0CPTLiqRCrUK8AVR2Bunhcs8nxAqrl6NjJec3JsXlYRc7FR2/r7uh1N+PfmPWEp5BTLOrFygV+nGUIO/KbCmnTpeq/o5wePOMbyuZhyXXbbtx5yYozB1JJVqy5yT9GUBn3T/HqhncVnCSdxtRGBzplwE1tNnOIDPPn+pcDQuDgHbSIf+BIRadz+TMslJzT812/wUTtoR0kKk8+F7BIIvnI/Nfzub9XbuKlfKTtg2D3r7eLLhM0qvwiNdt47L6B3hcMhgDOGkxLhlt5t/Hw36XJeVtYXVj23xjXhEYjdH7FoeDBgFpY+ET8O3kPArA240VjHrKlavO57bKwVJQz8zE5ZL+Y/Gc08WjxV0Dmt1snMmyCRU/cqaZ7MKN6dRC2XMPtOLUDcVDcsNL8UCge1nVfNr+xqxTJLe0JTf6ahM/3TDzl4yacnH1JA62ceHPxc7fnDAmlqZdXhfZ37xJ6lhQ6wew6Lje9hsuEfIP1/2ZxQTWMJw97gETpTPL0WSKZcDCWCfJn6zrfoE0gigYTq5pCDrCFtqAWTcwt4aSVAr9hsjx0TzAiTRfjEDFqz2WBoIaLrreKllKO26PJQTwIKg3X8EGaCh1oF6gbCQE3YgHbpmaNB+BnmOGD3DBe8B4uYn1MV7u0Zho/+9U8z21mzHlnaqgyOF2LskZwt8Dn+u4sFi38oKU1F10VK4vVuJshFg7QJC4sziC7VTbW40mLLYBRNlFuW66u2lgCY7JFqqdR0D9KgV2tqPpescaOwJ8ZOoHfWoMXEUy/NR6oMBH9qjk0BitGmTr85mfWIulJW7aE2CHjzznZ9DXw== 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: 2sJOOjM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RTrbWRiY44LBJeLqTn/tB+WRh1W3xlHwlO/ZHNFXKUQB0MHvOFJoNwxKxdDtbf18aACQ5Mgf1g5ktl6HlyqE5FDHGVgKZyHClO9lYty/wVn72zYVye22wBVzh2U3OW7MdyeMtjn5K1puNVGZbtLJGTUAH0xHRXdwjjuUnBe5fV5DJPs4xXMNCYGCAuXJlVtAwg1XUlefpYVNs5e5yI+oSCXiCHWs0YB+R5uTARsB0ypCdYRKiVJ0i7nCZXW/EdanuVAbTwSah0x2qhZun6S08Bx5vphD8SXkVCCpYPNR52z4ooQA8YalS050Xh16oreKKnD0puuYQ85N8RCsT0iCcO9d6fJl2YFUz4hT2m12v6mI+s9GEesMGY+m5CqKF/tGDKxaGzRCnxtioacMEt8MsvL/0uD07sMd2U155R6MAxK7Ct7pFamxh9vutFLnnwYCdOtu4mzMAJamk5s1VGtDBz6o1PWI8IftmWjWBRNuB7eWf16Ng0uBt0JXmC X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50524f7a-1898-4b28-6ede-08dc693a01b1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 17:21:43.8063 (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: LrQdV77BA6/gc9uXnZvtjb9IKFGW2Pduld/F7uowoxSREVezP36m32TOMU31krBv X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240430_102202_705184_3107B1BF X-CRM114-Status: GOOD ( 14.65 ) 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. v9: - Remove arm_smmu_clean_cd_entry() and instead zero the required CD bits inside arm_smmu_write_ctx_desc() v8: https://lore.kernel.org/r/0-v8-4c4298c63951+13484-smmuv3_newapi_p2_jgg@nvidia.com - 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