From patchwork Thu Aug 3 00:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13339094 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 5A121C001DE for ; Thu, 3 Aug 2023 01:15:44 +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: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=+6Ur5ud4VWuaCiPyQoUvWWGs8hid4vn4AWrPcGeoLfI=; b=Ez4uwSMuIds3S/ A7kQdeHO2tVa8pE/gSbyYNNh0uKL1GFnrPb9U2dop8mBMXlTkx8IJyx9z6QlbPXCOrFThhiyNtyu+ j81HsPJ8wAEfp8ARd3vV61Kj9Emh4HZETnVpehzyUQPUthplRq5zWdEqzSB9MJL+Won/D6ynlZaCq 7MQld8d9O7X9mdv2NmebvklPZ0a3/B2m0UNdyCBFarxo06W5+QORGhGxw3/LgLSP+tCvUyJpwp/U8 xf3ZlHQTF93RAcTNnvYMR/+pPqZ3DYdluzoTlpSaCOgwXPq05ppd7ciNfAN8dJHZJ95Dm2rojGLLT OtMqjNfRKA+fudnmoOVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRMwF-006L3f-0O; Thu, 03 Aug 2023 01:15:39 +0000 Received: from mail-dm6nam10on20631.outbound.protection.outlook.com ([2a01:111:f400:7e88::631] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRLtM-006Cej-1A; Thu, 03 Aug 2023 00:08:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KT/xuRwvJ2DrIBtxFxqp0UQygvAMNxLkkDetjArS/ouYV5F+xEPtBt2Y/3voh326Gg1ntwD3oulKg41E4JyKzfEuz0Dy2E0eVgU/dyscLP0NtzWu5e0RuWqWKbSXSwKN/Zf0DJauM6uxU5yi2A4+M5lJUwwbSZioDW8rdzyZ5lqHNncirsfL88v2brvYXAq14ba8WVEuLZDlLFtYRlJqYJlrj+YGJYBUFyHtU+sM5EAiUgpAN8NkZuA8KAd3+cMXZ0/dJ0iWolvsxxS8D1PWm9aUa+5OuehLH/c5cCNgv4RmMci5pqCd1iT7jyoTFa3tgyyvoBGGlpgpWsOZrCXbqg== 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=cc3SdkZBuY9gSAlyxygUxH6uwPRgSkuV7Wuw5HQx8PE=; b=Zw5GiWBjsdpeKpPcBc2Rh25zHsotnTWp546JAU4z5czJ+4OVZuNnHPnoGtlq0By1K+xMyLk3fDBNJxdq5E7kMZcoe/JYXkBt8oKnYlRWYzZKwxvXOHZmgsA3hgFxHSPR27xg9L3+4L56mICo4z6LgYqcg3j/fh10BlhQs0f1OYuCYxxIdpQlavz0EmAp4T8tsgWeOgTmWkirPQMV+gbaTAOlYhLxP3J77ojKUMQowRDKz4oB4kufDebFDWAadgOX6ioeteosg35d6Dga7f6D4mfiXXZJG2stKRTUZrQ7Sgw9PMtVpeVNy8l+oIUCU2uIC3ulozelrNhugNjV5iuITg== 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=cc3SdkZBuY9gSAlyxygUxH6uwPRgSkuV7Wuw5HQx8PE=; b=uc4IdoP4cmI0dqm6CQOg576iIEDSBE0DvrR2fP3OwqeJ81XZwGEVvTUWbeNsQ/fqCzPWar0WlUJsMLkc3cgCFNOhPmUYJPL9YfOr4G+lay+v6aFfD7y+kFaBKgwAFFe0NcAoWeKeB/7nmAJr439Xf4zEuyGKHW0lm4d0//HQ4WhGKnv8Mg+rXCCYfJTKYSANB+ShocN6wsjmmwsUd7DwMHUMCf3v11TAVVQwiSrLfiJmivUHzL68xSBsdbRgT18UtUMEiirLE0jYKUeAx/25SIjaVSHMPLbrK58liNqM0uC7vjLJLSnPLO08GKxy4Pksx9MDs9RhEetfZ495dFbODg== 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 MN0PR12MB5809.namprd12.prod.outlook.com (2603:10b6:208:375::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44; Thu, 3 Aug 2023 00:08:18 +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.6631.045; Thu, 3 Aug 2023 00:08:18 +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 v6 02/25] iommu: Add IOMMU_DOMAIN_PLATFORM Date: Wed, 2 Aug 2023 21:07:49 -0300 Message-ID: <2-v6-e8114faedade+425-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v6-e8114faedade+425-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0037.namprd16.prod.outlook.com (2603:10b6:208:234::6) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: 566413f0-a27a-4843-a52e-08db93b5bba8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FRCX/0/qLye+8ApBYi1hZzCSzJTo2MoNTx88J0t0lr2YXDAu9+z81ACGFcRwJOeeZk2sqyMfEFSQhN2Q/JBaBaIPnHnxDHeeRjMIS200pCZm1Yak5LMitPK4UmoA9GtpBut5ItckhfoMmjZUArSJodS8nBwOkXj+0+JB9DyU2Dr8hpiVzSDZ1N7BTdbVtDgETD+0OjkAbwpxvalUzb5CxFumgcJq8ioqLbTNNr2wRD1hGQwLgS63kojo1O+k4ukRb8YK40c/Ps6N2O+GEnFV1xz00VMdrEoS/tycqGiVHLYPtFfY0BLSEF+mQ1Db5O6vDcPH/7yS2CQVb1bdM0WNmfYfeDscxmXj5F9ytpKWOAy898r8BnJgF7fh/3uVYKisPLttVBuz7PTgP1grL2yYJO/zv3wrWkQU3ZE1OuFm9A1NOemwp51nfLzQdo21aoaRpJJ2TRPIJbJdNre1GXw7au5SOA4MdOhoCf46fquJ+VKx8vuxbbriyMkU2x0LqK5/3dIp+zIH0TIC8K6BQ2IEIimpzgsSrIwkfcvs4Euo+2pZVJtogidp6ZMRoWz1UdI6qbDk1EqxHU1Iuc0fGxIVzzdxWTfaEnmAx4W5292wVYEt0VJpIsJjOZq0ng0VFjZ9 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)(366004)(376002)(396003)(136003)(346002)(39860400002)(451199021)(110136005)(6512007)(54906003)(6486002)(6666004)(921005)(478600001)(38100700002)(41300700001)(5660300002)(316002)(66476007)(66946007)(8676002)(4326008)(8936002)(66556008)(2616005)(83380400001)(7406005)(26005)(107886003)(186003)(6506007)(7416002)(86362001)(36756003)(2906002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nMji5UfwvwDeKBmkWy3wH3LO5qdovfpOLho5O6VwksGg9gg7KwF7rVbG4wpVbk0jkKiYrLcMHLUpvkpZPUHGEAyJVHO865OR0BRS0BdJaSbdlRVi6XW59X2DBXO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0X4fJd9sLhYSp6EafVukxGAoxXouR28VYdx/vHOVLhdXigb7GZOOQeAoiMVyYKk6eWr2cW6Sv2VPvBVeireOH5B9nTadInb9GWFtKnCiueTDl/exEanGknAiXe9w/XDi/IoPJqqHF9AHSSUmJ5oBt6JDwKxgiGaGgq5k05S+DjgwUwUrBr5j65PBWYEs9pEWXOHQhPycHYwUNQIoS8rhCwCwhdRV0U/8mDQXaFeYAsnTJhTPhcs1C71CHS5SouqP6Pat4yQcGMVeSqis6Hqkx69pLA39191pPEg1BcnrcmH8rW/tiIX4nOeyUzOR3QlLOQ9uvaqqu5M+BYe4ran094ddecRyjmU/TxClGH6OsSrYKPK17++so5EDGu37xwE2HPIUXNaVwOqLNMz3RQQg+odpuh1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 566413f0-a27a-4843-a52e-08db93b5bba8 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 00:08:15.2925 (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: pPdm0BFfqIFg/LvEIk9lVRtMSGgPTtpxM8VnH3c2WdHxJCfZLZbTkaQGEX8AK5YP X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230802_170836_433184_FC124CD4 X-CRM114-Status: GOOD ( 16.36 ) 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 used when the iommu driver is taking control of the dma_ops, currently only on S390 and power spapr. It is designed to preserve the original ops->detach_dev() semantic that these S390 was built around. Provide an opaque domain type and a 'default_domain' ops value that allows the driver to trivially force any single domain as the default domain. Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 14 +++++++++++++- include/linux/iommu.h | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 5e3cdc9f3a9e78..c64365169b678d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1705,6 +1705,17 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) lockdep_assert_held(&group->mutex); + /* + * Allow legacy drivers to specify the domain that will be the default + * domain. This should always be either an IDENTITY or PLATFORM domain. + * Do not use in new drivers. + */ + if (bus->iommu_ops->default_domain) { + if (req_type) + return ERR_PTR(-EINVAL); + return bus->iommu_ops->default_domain; + } + if (req_type) return __iommu_group_alloc_default_domain(bus, group, req_type); @@ -1967,7 +1978,8 @@ void iommu_domain_free(struct iommu_domain *domain) if (domain->type == IOMMU_DOMAIN_SVA) mmdrop(domain->mm); iommu_put_dma_cookie(domain); - domain->ops->free(domain); + if (domain->ops->free) + domain->ops->free(domain); } EXPORT_SYMBOL_GPL(iommu_domain_free); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e05c93b6c37fba..87aebba474e093 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -64,6 +64,7 @@ struct iommu_domain_geometry { #define __IOMMU_DOMAIN_DMA_FQ (1U << 3) /* DMA-API uses flush queue */ #define __IOMMU_DOMAIN_SVA (1U << 4) /* Shared process address space */ +#define __IOMMU_DOMAIN_PLATFORM (1U << 5) #define IOMMU_DOMAIN_ALLOC_FLAGS ~__IOMMU_DOMAIN_DMA_FQ /* @@ -81,6 +82,8 @@ struct iommu_domain_geometry { * invalidation. * IOMMU_DOMAIN_SVA - DMA addresses are shared process addresses * represented by mm_struct's. + * IOMMU_DOMAIN_PLATFORM - Legacy domain for drivers that do their own + * dma_api stuff. Do not use in new drivers. */ #define IOMMU_DOMAIN_BLOCKED (0U) #define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT) @@ -91,6 +94,7 @@ struct iommu_domain_geometry { __IOMMU_DOMAIN_DMA_API | \ __IOMMU_DOMAIN_DMA_FQ) #define IOMMU_DOMAIN_SVA (__IOMMU_DOMAIN_SVA) +#define IOMMU_DOMAIN_PLATFORM (__IOMMU_DOMAIN_PLATFORM) struct iommu_domain { unsigned type; @@ -256,6 +260,7 @@ struct iommu_iotlb_gather { * @owner: Driver module providing these ops * @identity_domain: An always available, always attachable identity * translation. + * @default_domain: If not NULL this will always be set as the default domain. */ struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); @@ -290,6 +295,7 @@ struct iommu_ops { unsigned long pgsize_bitmap; struct module *owner; struct iommu_domain *identity_domain; + struct iommu_domain *default_domain; }; /**