From patchwork Wed Aug 23 16:47:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13362819 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 C8FCEC79F64 for ; Wed, 23 Aug 2023 16:48:10 +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=UgywVNlhFQ35vAd5Hsq7NIjA9vpEXDzWVF/QHxThjRs=; b=oSVH7tIDKZNHQM nBTDfGZizp5BqJRn+TgVHSQwKGg6fpMvTDbGmc111/tUY1Pk0tmeozkogCsZpPzPwVCMmuqa1+0+D VGaf2YhcIDL4WEnWcLiFlOIMyst1w9z79ihjlRPZ0aSLd2FdInIId+EqYgmH2YQ3c6NJBP0dz1TdX xvybRwdIg1bLSeC8fl2Mmpa6RgQ4jukT0YNubTufRv3D07XUezhPduMlluPnwpSnzu2Z80JYRqWOr GSw/9H3JRJpG7wX2uX2sjE4rStTg/JBCRNhEwA4ivWGHkkfff6CkdNzJKX96kZXxEqXAOPPrYe0jF gnZL8mYIQDOXEqutG8xA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYr1Z-0016LG-0K; Wed, 23 Aug 2023 16:48:05 +0000 Received: from mail-mw2nam10on2062c.outbound.protection.outlook.com ([2a01:111:f400:7e89::62c] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYr1M-00168J-1p; Wed, 23 Aug 2023 16:47:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dhMYuFDZLLTFxLqcNAPQ2XEZwxRn39P8CV3d/zDOkRs22xUEIh0xW8dYdCHgEgAAqcO6Z8xW+/YLwo0TA+0Bl+iS2Q7CJa7X6uL26ikk1I1meSmnPymy9kcgan03XeCY2mk8d6Ye52hRLSWDN+hAu3uJt5dCloTnuY5dKK/enrXDN1zcYz/o8spJFmAa3QUHAuSLEWe39PdVm4f9/o/sKIxpFuiJujwfNB12KTlUpGTQgcCbbtjeb1+2ZtJOi8uQvRxgF51Mszlt/gS22O7orp47BH7qU871b0+2qASlQy4fMQB2HbJ8mxKmBpR+3VMAkEGPZAt9JDXYzJWDR3QRNw== 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=b9jVqWjNYnYdiXeki1jbg6BHd/kVXWFzDIgAyZvEFCM=; b=FByMbCXjF1+0w/aOU6cH8sxdoEvBaMXpn0J/QGgp9OgzpOkqWM5EIrgu0AjxCOpP3yuJKFGc3aBwUDtWq4/oM+a8BJTqIrzGee59VHab/pfua20OsWRHVkMMYELKzr6EpfGyu+BaQHgi2b06Y10CT/GH8AIl+RopH/2xcSWWD0PgARTwzNbYGkkFvw4GBG9qeCG9F9gShdRpDAyHS109kRLg38EOUICfjzQ1ApLwm4Iao5LkWPrk4eOF+gawKj5jd60k0zzhBQtZo76PsVRUMsUqgSS9Q8MM8Itr9yrPdvwPwRyXBTBs5XkLdgeJXWgUrxfGlinx04eWn3i0Vjsa1A== 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=b9jVqWjNYnYdiXeki1jbg6BHd/kVXWFzDIgAyZvEFCM=; b=aL/0e88HN4uaG0Tirqjb1ct9Mv8GGht65a7N5/6k0qVI8xU+0XpjYOvlZnPVou5NrCoz7eHOPsEVUtZFxdAhHDt2tM3dW237GpBSSNGsLJU+P/BZAAyNDGqIl/m0APfvh1fTGa2bcfozkvqd1yoi4WYeWkIV4kvSMKIjcAMLiD/9VHilY+MeVyNPtHVcupcKgl2wkwYdzP0tgoYsPKJvREx2YDOqo4yqUuFd0vEwpcoEXBn0xrrcQFetjDasIypWLZiLyw317bFbBj0vQC2uFN4AbsVoGVFmQSnmphHTQHwcEm+qwpaSR1usa1Wk+LdGQ7+n4FjcSYSIij7KPEouHw== 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 IA1PR12MB6459.namprd12.prod.outlook.com (2603:10b6:208:3a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.26; Wed, 23 Aug 2023 16:47:41 +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.6699.020; Wed, 23 Aug 2023 16:47:41 +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 v7 02/24] iommu: Add IOMMU_DOMAIN_PLATFORM Date: Wed, 23 Aug 2023 13:47:16 -0300 Message-ID: <2-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> In-Reply-To: <0-v7-de04a3217c48+15055-iommu_all_defdom_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0420.namprd03.prod.outlook.com (2603:10b6:610:11b::25) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB6459:EE_ X-MS-Office365-Filtering-Correlation-Id: 28fad826-712f-4553-4de0-08dba3f8aa29 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uNHgQ+qvzYBmm/wXR5Gu3Ij+luOnSlur+FgHruOpZ2oSnlQX0j73ndQVeE9o4RRADs58kgXAOD5MFNDJN2K0J8oNEsBGakjAQ8M1jmoDwuL8I/lXqhKHbdSGXQEicS39Wi1Y3W0jTiTrEtAIJC83gpc6t6Rj9v48pOifr/y5uemM4jfrNIjDl3c8xAWruf7BXpczJVqXUbyy8B2UJ5qf1dyaIhDYGM17I0ur/tNXA2t/r8suqlOjjjPgHjj5CF9jECVKvLNmY8xrRWtd76IZBoJ6aDboQRsCwYjFedVjEwofuIOpxr76vi7wqG/JHjr0L2/I3SSqpsAjjHk7/WxGDR+2V8vrxuMlsbJxsSQCB015icga/0OZ2RojM2bn3S2k3ZN3WiVV0WemYsTvmBLeL1cjb39SqJjLXBQSLWp+6b1XkT23trJ8YcGaeDzOV9AD9IxUP6vCCbf0oJrWdRNFvArt3ZvISKkZtkaH64KCdQTn7sGj+BTA92QS1kllBBhBXFw2PT2xj33QhzaOoqOZYbyPfqwEq5lF+LjRHN4RMadnONA2LhoGh4G9LqKDPfEPo/d9fr7EvSVbfy4NXsqKbZnK7WjHNi/PMV9Aiw/vZw/AaayvwWXZRuk1p/pgzaUl 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:(13230031)(346002)(39860400002)(136003)(366004)(396003)(376002)(451199024)(186009)(1800799009)(36756003)(478600001)(86362001)(6486002)(6506007)(66476007)(66556008)(316002)(54906003)(110136005)(66946007)(6666004)(41300700001)(6512007)(38100700002)(8676002)(4326008)(8936002)(5660300002)(107886003)(921005)(26005)(2616005)(7406005)(7416002)(83380400001)(2906002)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BMHpyuXpC4lINj6m/ScgmjDOHT1VhSaq0ZK3ayMItsdG+yzmpUx/fcuAbvnLHTM6fgL5IdmoexVfLYxOev1JtMF7Ot3E+wU6umxQ/oKKmkhyylPw4BBILYv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bf9+nl/TkQwMwANWoHshl76ACmnwmvrcX8uxngYLOpZ7/TpEDh5LinMS0RVxRiZkD7CO5zfNHg6IzDWMBR4+WLTrZETPY2a9B80W5e3hQIoMe6ypJu9a8oj87ETLlNSCWoQNmHRH7I1wBGn1SKezYP0f15HQNAz6pPCYUziiGNUIF8a2y+fjwH57xpku4pKwPifyLuuKagEDSIDpf4eZP9NVRrY2hB85VzrNcj4K/AZEGDDEASdRbar/oaPrYj/tUZzR9rJ2if96DjglkUJKF3JkuqWeJJW+h/R91zQ48jrerpXPnaOCXFIxPlEEyHaHrGkObl3yHaB5Q4q0BVtVQUbN2Qw9YGDIdv0Gv+Bq++BHUtFmMMReRCJEIEQZ9n0F3lfZPqd6Qnc X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28fad826-712f-4553-4de0-08dba3f8aa29 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2023 16:47:40.8439 (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: CK1vyeWTN3+yk0JrlP8ocPls7qunniOQa+2676khNxlI6sOdCkyO8iW78GwyH5Wu X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6459 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_094752_611968_427A1724 X-CRM114-Status: GOOD ( 18.90 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=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. Update iommufd selftest to use this instead of set_platform_dma_ops Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe Reviewed-by: Jerry Snitselaar --- drivers/iommu/iommu.c | 13 +++++++++++++ drivers/iommu/iommufd/selftest.c | 14 +++++--------- include/linux/iommu.h | 6 ++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 33bd1107090720..7cedb0640290c8 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -184,6 +184,8 @@ static const char *iommu_domain_type_str(unsigned int t) case IOMMU_DOMAIN_DMA: case IOMMU_DOMAIN_DMA_FQ: return "Translated"; + case IOMMU_DOMAIN_PLATFORM: + return "Platform"; default: return "Unknown"; } @@ -1752,6 +1754,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); diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index d48a202a7c3b81..fb981ba97c4e87 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -281,14 +281,6 @@ static bool mock_domain_capable(struct device *dev, enum iommu_cap cap) return cap == IOMMU_CAP_CACHE_COHERENCY; } -static void mock_domain_set_plaform_dma_ops(struct device *dev) -{ - /* - * mock doesn't setup default domains because we can't hook into the - * normal probe path - */ -} - static struct iommu_device mock_iommu_device = { }; @@ -298,12 +290,16 @@ static struct iommu_device *mock_probe_device(struct device *dev) } static const struct iommu_ops mock_ops = { + /* + * IOMMU_DOMAIN_BLOCKED cannot be returned from def_domain_type() + * because it is zero. + */ + .default_domain = &mock_blocking_domain, .owner = THIS_MODULE, .pgsize_bitmap = MOCK_IO_PAGE_SIZE, .hw_info = mock_domain_hw_info, .domain_alloc = mock_domain_alloc, .capable = mock_domain_capable, - .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, .device_group = generic_device_group, .probe_device = mock_probe_device, .default_domain_ops = diff --git a/include/linux/iommu.h b/include/linux/iommu.h index d0920b2a9f1c0e..48a18b6e07abff 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; @@ -262,6 +266,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); @@ -297,6 +302,7 @@ struct iommu_ops { unsigned long pgsize_bitmap; struct module *owner; struct iommu_domain *identity_domain; + struct iommu_domain *default_domain; }; /**