From patchwork Mon Jul 24 17:22:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13325138 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F35AC41513 for ; Mon, 24 Jul 2023 17:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbjGXRW6 (ORCPT ); Mon, 24 Jul 2023 13:22:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbjGXRWz (ORCPT ); Mon, 24 Jul 2023 13:22:55 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2085.outbound.protection.outlook.com [40.107.101.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6871A6; Mon, 24 Jul 2023 10:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VqujkkzwlHP0oCciMyR4vPi1tVuTPxX3hMrtQhQ3yle2nuxFZG1I1517XpInZrISqH6b1o3FuxRhUUxIcxLwENuESzLNby5Xgvl/utKf7e9z66WyG0zPAIV80y/y3Q+X3uhauSXwnBiml5y63yTpEZIv0aDdK969DbPSRhl/6tJo1eNWDN3MkPlIdAzI2EmP84TwDNwwsefTCiLP5PlKwtNVR4pNjSOCNGCfyEtfOOXfKoUoLR8o0X1oyF6bla+XGMxzmxheZXV6iKTn16qJwvk51wx7ym1/P0aQjypPjUhkdZKfeEFYD1cxwfOaI57RzIxmf5dU8H2agRTuIC84ZQ== 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=r5GHXDukFiznG+BAnSybCGYJiW7ONltFgIdytInRrqc=; b=Y8YPJLsfOPHrR9+ULssMHADAT73E6Veui18tvDVIisQMTET0ATi93+3tY+N+XIysRlWf1H4NDGfPqnANuL4rb29bSVtK9wL2pN8qm+aIPi8U7slFMZlkbb0gTRrS84IYycTP0ZQmRwhdvBKBIEFvpjoPOH3el01EchxaSiwYbupIJsrTMdBQKKRs5UVcMqo0VHmCf5ZtC3EYITo/eZOYJwPcn2GQqzE/q3YA43t3ZL+V0nZpxiKeWMLD2rrxtBp0aszsqKCLQBfots4jf91sKq3NmRblegngtm6fQi9eRO/9xZXPIVtbTebEKIRtrKNtYF6YNqWgRfjnJT3DZ/etMQ== 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=r5GHXDukFiznG+BAnSybCGYJiW7ONltFgIdytInRrqc=; b=WuEHKuHOqZra+9S92CZOlLPyMwUczz8JFohL1ePn/v7LgnFPb2M1iejFNLxZ8JYeyymjUX7w2WZdiGRgfNmpo/pNveIFVEGhHoXZbxqIAi5NRSxFNZSd7c/I2YOGTrjiZdBjiycfUL56CAX3C75p+VREm/qJr+wFpf+SNu/tcw4OAbYEcBRdxCR+4MOTYaJDCgStdf3cnAUXjBLMi6WUVYMbnVC5P9dCI7162kJ/1cs7t93A2H2Uzdzmhb8LmUWpOeJfmgbPlHRQeg+haL4uNjSttPTBpChTwUeeVakQVIsoOjyt1MIs6SBzLRpYBmcHIY2DvU/06BwHwpqRW682qQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CH0PR12MB5252.namprd12.prod.outlook.com (2603:10b6:610:d3::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 17:22:27 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6609.032; Mon, 24 Jul 2023 17:22:27 +0000 From: Jason Gunthorpe To: Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang Cc: Lu Baolu , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: [PATCH v5 21/25] iommu: Require a default_domain for all iommu drivers Date: Mon, 24 Jul 2023 14:22:11 -0300 Message-ID: <21-v5-d0a204c678c7+3d16a-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v5-d0a204c678c7+3d16a-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0208.namprd13.prod.outlook.com (2603:10b6:208:2be::33) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5252:EE_ X-MS-Office365-Filtering-Correlation-Id: 6660280b-5ade-4a49-d0ea-08db8c6a88f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cCdF6hIqphmlsSQ1TsdyVw7GKBc7IxYaudO+fcFepF0WblehN0UeZiMvoTF1sICAMYr9DFt0W0g7gn2qNbM4b8wachUmLzXHmtcolOg2mdvnKI/ttq8lXSz8s6nFPrarlnR71T8/0J/075VwbDgE9iTVvP0Es6fiXqCkYl4gfZ3jV0aOKy8LTC80yDGV/CqTyCu6x4aBgajDlpUq+KpeSlrmwV8QNAFIvy1t3b4eAISKZ5kOp/9DWz1fo4A9132y6sosnmgPBjn/KmqI7o0yk8TbkodqBbyfL3Dg8GsVra9B4OuZ36mG784eAyi8xL/bOuVOkqifiLVR09pE9hmKxOuTeT2X/tA2ei5c9LVfGodx/1HHRQwhx8PdoUNFD1FyhMEOAlTWFFs+/DgsZqbahLX95yy5KJWM8U2UFdWcXUOjAHdMMZs2xZzWIlCiDk1+cH+usIYOSIPsl9fp1SWaHOZ34KQqQQBbktrNYE73nZaA91svlcFEP24aXWwwhLaGsyWWBj+bhr7yim0UWrwngfgsK4Svb/eBdAz6XTGzlKuleHuHxqhe5vb5m2GQTz1qwcijhbQpyVkB8qIHFQ7o22vEueeKsNE9yqPG1kg2aUo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(396003)(136003)(39860400002)(366004)(451199021)(2906002)(2616005)(83380400001)(4326008)(316002)(6512007)(66476007)(66556008)(66946007)(107886003)(41300700001)(6486002)(36756003)(478600001)(6666004)(86362001)(110136005)(54906003)(921005)(38100700002)(186003)(7406005)(7416002)(8676002)(8936002)(6506007)(5660300002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E9Y7GSXorc9/MenCgNl0Efd+2iGEw9EkCXVu7Mp92haw3me5FS0fTQmKJtgYOEZ+KTldetKckIywRfM5zTH26eYnPBixIhKihGTddl1mbY1O7RJqaVCfiMWPqb0TW8FtqUZa0zFB7jwbzNWVxR92DaQkGGjqAkbwuHi0Ncv6ukjec0k5SDGSH9hado0qXgpjIIV2Q9+6B4w+SYib/PveXp7huibFMDfnpbjBBqhk7Ynx3wPg6RAnv2CSMWkxb+f66THXXFbWrTXMO+iLx4YtOf7uZiJwDil3/0ZLTYf2SeMjbKu/1Rb36he3klWwdIQCwwKYYHkHWMs6dEokiKM+4mgTCWXcU9w6g3MBulJzv5w/K7ZCgdIEPMm46GK9rL+mGBPMiFkmwmPau+5uWfCuCoQv/4+gktVR7i+jr7Nr52ke54o8zGY1vCoh451jIgLtUk/loh75LLnZm0CGQLHXqqma3vroL+3MntVH/3AWoICQksLsSLyJe4A//ObeMsCcMXjP3flKlX5lxOQKBz7QNh0r233Q70V0eA+GERHoIK91iTzuFvBmvbIyUrtGaU89uvYx2qeY1yXvu5kWGjhXJlvM9SlQVlEMlNqRjxw/jGhvuyJb0ziFnuAEvXj7xQ5fZAkzifWtgwmh60xjuZzl3J8Gue72JYGBqvi08/wYgvCPvhxHYtM7yYZTut51NSiYmqfc+h2zHO92vqnYd7JOCdttLvJkncnOCeWtFRkLbEMTt83wBnU57bXd8pP7jGR03gHQUCFfeZNwHe3j8Xi/+NS2WIpENKPnJb77j6K1/p4hZbQT2vC+LSAqO40QGJaF9Cml0I2dx3BY7QrCIJqNp3JGL+PuDZi8uRH5rXyk4BCfGtTyGzjbPV4VuezWKfY5TnJ4MRf5JSCMwC5uz77vSQSO2qxvJUF8AOLJi9t7MQqOLDq3ZLMSsQYDJhIYTdCbjyz7rFCyPWSVd8EFY9dwyPEJ5zOzcgwtSH83vLMGKleAjQ3AMgEYlN5NN9kc+Mqpn2jsoLvsBNzr+2DyW0198bWMKvOHY3xIIKumEbA30XYJwd1oc6Q6WEbLVuUkKxJ7/41eyF70jqEVW86sgj3Kz6y2/3WbNSwU9/UwPXRUW9eZf9Ilofr2DSCEHuZ3ZfvDQ+bbE8SU7IUqPuqSSVn6/77y7iRBB1X2YlXl+tGLh41wfp7VbKPEPdIOa+0TukWiibtq1F4CHKa7g3jxOSuoeKUE80URkBPgDRqgwat81woCU31T2sf8j2uDFrHYSOYgtDkq40JczpttIWBbb8sm7AS7jICr6DugNGfMFsLm9cnYnJl6x3ZOM68F1d3CEjhqNscicqSVR1kw8wEHR3PgBX1klfMjcKW1UBL+HiVzlZOJgTQJAywq2Ly/RZqAEXvy0VUqydUFm9cOldZf8vo0QekyL2PRbaIyEWzm7ZEXgLZ8wGfp0VvkCg6YA6ijnkHVd1+W6dpDT/eU1xrwdLKOm+RWEaCPSNonmYZ8iEJGlqznfkR6ZYCyBRd22VW8Yhiq8og339pnCfmUvX8qmvxDwtl80G2DXrBoK4coukBX4PYrgmbIx4Sl3q9Z3SlMFJVw X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6660280b-5ade-4a49-d0ea-08db8c6a88f2 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 17:22:19.6438 (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: E7W4DX9vpBaiZPPeUxuPcbzapFiVr1Z1j+lOtNmL/iqjpzGshyAo1cuSEvU0nkG5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5252 Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org At this point every iommu driver will cause a default_domain to be selected, so we can finally remove this gap from the core code. The following table explains what each driver supports and what the resulting default_domain will be: ops->defaut_domain IDENTITY DMA PLATFORM v ARM32 dma-iommu ARCH amd/iommu.c Y Y N/A either apple-dart.c Y Y N/A either arm-smmu.c Y Y IDENTITY either qcom_iommu.c G Y IDENTITY either arm-smmu-v3.c Y Y N/A either exynos-iommu.c G Y IDENTITY either fsl_pamu_domain.c Y N/A N/A PLATFORM intel/iommu.c Y Y N/A either ipmmu-vmsa.c G Y IDENTITY either msm_iommu.c G IDENTITY N/A mtk_iommu.c G Y IDENTITY either mtk_iommu_v1.c G IDENTITY N/A omap-iommu.c G IDENTITY N/A rockchip-iommu.c G Y IDENTITY either s390-iommu.c Y Y N/A N/A PLATFORM sprd-iommu.c Y N/A DMA sun50i-iommu.c G Y IDENTITY either tegra-smmu.c G Y IDENTITY IDENTITY virtio-iommu.c Y Y N/A either spapr Y Y N/A N/A PLATFORM * G means ops->identity_domain is used * N/A means the driver will not compile in this configuration ARM32 drivers select an IDENTITY default domain through either the ops->identity_domain or directly requesting an IDENTIY domain through alloc_domain(). In ARM64 mode tegra-smmu will still block the use of dma-iommu.c and forces an IDENTITY domain. S390 uses a PLATFORM domain to represent when the dma_ops are set to the s390 iommu code. fsl_pamu uses an IDENTITY domain. POWER SPAPR uses PLATFORM and blocking to enable its weird VFIO mode. The x86 drivers continue unchanged. After this patch group->default_domain is only NULL for a short period during bus iommu probing while all the groups are constituted. Otherwise it is always !NULL. This completes changing the iommu subsystem driver contract to a system where the current iommu_domain always represents some form of translation and the driver is continuously asserting a definable translation mode. It resolves the confusion that the original ops->detach_dev() caused around what translation, exactly, is the IOMMU performing after detach. There were at least three different answers to that question in the tree, they are all now clearly named with domain types. Tested-by: Heiko Stuebner Tested-by: Niklas Schnelle Tested-by: Steven Price Tested-by: Marek Szyprowski Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/iommu.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index dada2c00d78ca4..1533e65d075bce 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1819,10 +1819,12 @@ static int iommu_get_default_domain_type(struct iommu_group *group, * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an * identity_domain and it will automatically become their default * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. - * Override the selection to IDENTITY if we are sure the driver supports - * it. + * Override the selection to IDENTITY. */ - if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && ops->identity_domain) { + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) { + static_assert(!(IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && + IS_ENABLED(CONFIG_IOMMU_DMA))); + type = IOMMU_DOMAIN_IDENTITY; if (best_type && type && best_type != type) return -1; @@ -2920,18 +2922,9 @@ static int iommu_setup_default_domain(struct iommu_group *group, if (req_type < 0) return -EINVAL; - /* - * There are still some drivers which don't support default domains, so - * we ignore the failure and leave group->default_domain NULL. - */ dom = iommu_group_alloc_default_domain(group, req_type); - if (!dom) { - /* Once in default_domain mode we never leave */ - if (group->default_domain) - return -ENODEV; - group->default_domain = NULL; - return 0; - } + if (!dom) + return -ENODEV; if (group->default_domain == dom) return 0;