From patchwork Tue Jul 18 19:05: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: 13318224 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 70763EB64DA for ; Wed, 19 Jul 2023 05:33:57 +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=9QlwLTgTz/pKI506oOQcmv/VD5KoMH/CE3z+eYmWyJk=; b=woyJLwKxM27yMd oFuJCnWq9pRPBUZ9dyJMUHpntJqMVhMDW1Q02ZdmNew6ozW+OTr4nKx5wcW2gnZ2SAWuNFBv49XSw DEmNbRRChZ9P9j3xhOKE055h8U67QXPmw0vRjzueB/qxXkcH9vnkrAFYFYOJtDvl1ZVho31IgUf9j Pkz6nSi88ZW74VUYk7DtgsopJ79O37AwKE/Ia0JnKyFJwAsxVqiNGHB4X6FdmoRjuHI8qdBwFO5C3 TAl0knK6Yf1jsTSbiwSTSXVR504G9YrkarcywXGwZz+uwsTtqavsTxjKjXik4cUVFpibwrbYvD5lR LaaPnI+sQCtwXZIoBzmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qLzor-005L0P-2r; Wed, 19 Jul 2023 05:33:49 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLzop-005Kyq-1O; Wed, 19 Jul 2023 05:33:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=xcAzE1KjuDaXFBNrXOjdF1BHmyGySlPB9hXcEv4cYjI=; b=gcmKfqUYPXISQ8ZQ/rs88bUVUm PYg5iK2bbs9dEh1elG+sg3qKjE6ulUn7aBs7QqtVURXxqhQhYvUjphgfReiA+7aPI/kaegHgBlfVO dMfVbmU5zcTAAOPNKXIM6seBaSImkN2Du2JTyxZpc+u1+mx6mnY0ZUM+TC7gTiSINwUvR3nA+O5R0 hOa+2H/6tBbzs9Fh6Zna2uAT9lY3X9Fcm340TH+nYUaORqQH0AutyOiSjUUGGY+vClSVee4ewQFeO 7cjl96zhGPcvAUBnOSR0Me0/9Al9gD8q9RIHnK6veezsQWfnp2CSIFnpLZQLK+6FFHXNdtOPqpi4t 0+xYS6IQ==; Received: from mail-mw2nam10on20609.outbound.protection.outlook.com ([2a01:111:f400:7e89::609] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2c-00Bvif-0m; Tue, 18 Jul 2023 19:07:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ajf2FLBar/IfGJNsMV8KzgqRYy4bB/E2LdLyuIQ74mmGPKMXowCNhlWNgqRy5Hk7hP/6NacFvmHxZiOpqMJ4ac3ha/3/3mwRygHCuw4z05QRqTR9s0JKNN73TnMTH2a7I1+7INnoN4TC9nG1DanSi8bwQuELKOvb5Z3K5nTqISuwjxS9WDZNpViaC3CUtc36GH2u9zzAqvRoNSpQ2XHfjLKdPH37W9zFDuI3PZmK79KhQWADdhGD/qc5S4y7j+Lol5+Tt3rGiRF7rQp9WRPcNHg+rK6gUhsXxO4YSl0UKt4m/ugbedFnbHZxsuHN6Gu877GaCfvUa3PCKqQsfpTJWg== 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=xcAzE1KjuDaXFBNrXOjdF1BHmyGySlPB9hXcEv4cYjI=; b=DyQb44NX/X4efZTZvO0gTkeVKA2D4uSg53V6coTVbqTBGgzMoGc4uOFM8IoO1lIkwDOWqw93fdPmsdrGmfp2uAsnFvno/k6kOKyO2dqJXPnQqGx2FPLSWwT9pjZQFVudWcT6rma119CN9udM8LInOcp9TzKe5grNc3XRYbPkeVaxXXwkeAEqnR6fwuZA+Yy0NhNVocfgluC/csc2muVwdSaV62OEEFgSBZrsYSxF/05UMqwO5bngeIoyxnAs6iZk3JRtwQe9mnipcU7iQKJsANVLjSP0KwIqYSfwXQs8GlK42E8krtcayWhpLXz0czYtWoev6VxwWzEG1oPIGw1rQw== 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=xcAzE1KjuDaXFBNrXOjdF1BHmyGySlPB9hXcEv4cYjI=; b=arRpKHsLhJsYOgmdcscRkkjLNXUYb9NSdQjNNK6uEsHLM9fHxZ8ewwdrXYYKxR3NR4hifLaay79IPHP7judNhnPW83PWtWAVvrZgrPdzZ4CWzWN7tfB7d3dvcG+6LjB1mylrO1cM4Yu5RuIFSw9Zd9RQP8fKQYbuGP9fO8R5xfbDjZaql8gZv3M5/dP3iSiZtEYwQg6ytwc5MnxBo1fmeaY5IuRH6zl5UHd0srD8uC9KjLz6/U/TCZ3BxBiWHorUhWzha85+wHIdhZ8efqtSRRjIydedmHFraf45ClqP/T9+lcg126Xm5WaxeJ//EQwgb/Ajf2fwRih1C4YSuaIWEA== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:02 +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.6588.031; Tue, 18 Jul 2023 19:06:02 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 01/10] iommu: Remove useless group refcounting Date: Tue, 18 Jul 2023 16:05:49 -0300 Message-ID: <1-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR05CA0040.namprd05.prod.outlook.com (2603:10b6:610:38::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: df2f2cf1-8915-4369-1b23-08db87c20722 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0AP6SKs3B9IUARBhxnzz9099+nA6dCRr7oVuCVTQpsbAtoAgmq+4mfSxnnvTSfT3WQBmf8wg7bOFYbqCAqZKyhWtjHMKC3YsygKUWD/J05DwFI2QIIptKRKBMSs18lQjm2t3MZOhf6DLLUeqTTvODOZKH7jZCyETrNbiQns1T9d6YvoSoUlDzDy7RVXqR72+ffvvgKicEjlanMB5hNBtvyliQ16T/wXeEK8w4EBo6aPQKGI5Jh66HCaqW1NPqI5JgnDbxVclVSjC5SRwfmcq8zbNnekOLmwegVa8zdJUWdPS3YaLPBpZ04/3tZzEMQJyBqC8jGzKR6FEVAfLp0QZQ3uj+JjXAelVYu/ER7B8StXVcNPohLPfpVf3FCsCk+nRdA1wvJnMZkIdipXR9sXIDhxHqEj9Zxn+MV9tzWPPrTV56GlibNDqnimye9Ftr5LVTchlO62iOE4Uupc49JyGAIv07eaB3njVj9/5ha3ffQ2g1lDE7IqCkWLgfP50ZYfY7ERsNyW1o8sTzgTPgL2WSdbIoXKgdBV52vXryuQl04seKOvW8M8fYKJ1iBVQxz9O57J5FxK2clS01jUDapV9wgs/rVM/JXxI4VkIVCdx1dgsH9jrCbvdLwPdD9uJ8UxV 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r8FNoykOAuAW43BFLX9IqdAt8xrfh+1oYTLVgRxj+F4Y9akGzrIi8vveLqhShdMhgurDFGZV+F2CSG3fqMFTfjrUcYy/qurgrXA6XVpXUTccYAzOhUel3lgyVf2x+h8T8rdz5BzRVgwnZ0BY3wh0dDKvB9y9RnWgzkyMTO8mYN41FI6JLloN1guPVwy05poSqgvdNeMCtX6uSskbvU2XsmQ6gy2ixMyWUQ98na1j78J6UFlT/B0WA/E2fq+P7aVd/VwT1+o60/aJJ1tmN+9RkOH25cf0kPYFNUAI8XbiUGk+fcL8XJdjZymQC0ELElu/YhQltE3b0dcWOAK5oRvAD057XBuLEjA5B9BLvLY8cTt1wMV8HXRBKnT6eb3eAmddVvS5mizcV2eE2I8BUMx4esrMe6z3RmRYEbw7iqIIzD0MhHwt7wjS9ogWWwKGKkTugPjovSrPeBrb7E2zCPz4wNCj7yCuNTFJ+bXtRrpTO8donDAlx1EZkEArm/hh3y8E5oS46PZkIA9Mv6bpRRVOO/J+it87aKtAyzk/+mjSsiDiScpcbErgdzr7VvZQcS7mXUK3KIlsiyYCLe4aFzmAXtf7oftpATDOW/Pd7A6wSrrE/SWRlvCNAL8+9SFK8nRDQbDwulSLolhYVrfuuTlZoS01AhkPIAugQsJRqQSVp7TmkU7blv6USG7LMiLc3P1qOSJoIbtWJNGYGXh7E2vhKKQ5z98ZWoGfWFUv8GWWyxvyUFdZjYtYmVY2BWRAi4aX2h649a1a+NvaFQElNmCL/Z4v3Lcu6ucT5OfJTaymyEQbzzfsG9uAFEGUtgE5kKGh9j+texmhXM7jYSxTlVZhqz9WqjkHHyY65fLwlq6ojgl+ChBnfdoYHzcAVqJl1fA+oYq2voU5pUiQ99aixO3Kh2azC4Kan+ioYnXOEwOR9QCvexdYd/V6s64SNDe9XSxOEgDUkm/3EkxgYKq5/tdl24T4OPDoVAcj80PiZTKzB0vVeyLc6gG5PdFeA9we7V1WrScAADw8GltOnkXiCFtLXaCqWdlcu2q/2XWlflfhD73rRVyq/lqlzrJ4waBcb8etwedrKDPnBptFPk6JeTqUHW9v7K5GD1oYwRQTkrBx6Ne7vNsQgw30/0EUNfvFuQzHfzlBTC9PKyqWnuRPnhkfRHlsCTt8dkh86gzjJT5mtQC/CxL8RqxxDT+ZOkot2o8SoH/TEugPCFasSCVfY1MgLHZ3TZZW8FOHPP/0hcOmqQdF9c6+pLFBunN7+XTHUlCj6wlyz9UrP3kTA6aa6dhnf095yT2RwDePjYJ2Odm8MhUbwvduArZvFCZD7Oe83a2DctbSZbc+tZWmXc9xxcXEjjUnbGxTEcAqxdtOtHab5PkbE455u5TITdHRPCBkOlsvVkylURyG6Neuh/fqHYfA1RSah5WAOGXeqFEUMSyEh7eY/i8OFzWfUYKDwyH3EyT1iycRN9xRus7EPpI1+W9fGnwYKgHZ/l0c6LbaZi8VJZjQzO3dghWA3XHzzTn6GnoT7js6uyBv1a43Eyp7/YHp5fTbD2VTWoZpj1qfeaWSk/PrNguhVEUiBGoPqBCabfkT X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: df2f2cf1-8915-4369-1b23-08db87c20722 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:01.7838 (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: WZWWLU+DlnVTm24bUIbEVXwc7Uvcdg8/CkF8qla4iMUT6fYEcpkZrfGyCljFkTY3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200722_556856_92539EC9 X-CRM114-Status: GOOD ( 17.45 ) 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 Several functions obtain the group reference and then release it before returning. This gives the impression that the refcount is protecting something for the duration of the function. In truth all of these functions are called in places that know a device driver is probed to the device and our locking rules already require that dev->iommu_group cannot change while a driver is attached to the struct device. If this was not the case then this code is already at risk of triggering UAF as it is racy if the dev->iommu_group is concurrently going to NULL/free. refcount debugging will throw a WARN if kobject_get() is called on a 0 refcount object to highlight the bug. Remove the confusing refcounting and leave behind a comment about the restriction. Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/iommu.c | 57 ++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 4352a149a935e8..2f6eb781dfc317 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2014,10 +2014,10 @@ static int __iommu_attach_device(struct iommu_domain *domain, */ int iommu_attach_device(struct iommu_domain *domain, struct device *dev) { - struct iommu_group *group; + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; int ret; - group = iommu_group_get(dev); if (!group) return -ENODEV; @@ -2034,8 +2034,6 @@ int iommu_attach_device(struct iommu_domain *domain, struct device *dev) out_unlock: mutex_unlock(&group->mutex); - iommu_group_put(group); - return ret; } EXPORT_SYMBOL_GPL(iommu_attach_device); @@ -2050,9 +2048,9 @@ int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain) void iommu_detach_device(struct iommu_domain *domain, struct device *dev) { - struct iommu_group *group; + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; - group = iommu_group_get(dev); if (!group) return; @@ -2064,24 +2062,18 @@ void iommu_detach_device(struct iommu_domain *domain, struct device *dev) out_unlock: mutex_unlock(&group->mutex); - iommu_group_put(group); } EXPORT_SYMBOL_GPL(iommu_detach_device); struct iommu_domain *iommu_get_domain_for_dev(struct device *dev) { - struct iommu_domain *domain; - struct iommu_group *group; + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; - group = iommu_group_get(dev); if (!group) return NULL; - domain = group->domain; - - iommu_group_put(group); - - return domain; + return group->domain; } EXPORT_SYMBOL_GPL(iommu_get_domain_for_dev); @@ -3044,7 +3036,8 @@ static bool iommu_is_default_domain(struct iommu_group *group) */ int iommu_device_use_default_domain(struct device *dev) { - struct iommu_group *group = iommu_group_get(dev); + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; int ret = 0; if (!group) @@ -3063,8 +3056,6 @@ int iommu_device_use_default_domain(struct device *dev) unlock_out: mutex_unlock(&group->mutex); - iommu_group_put(group); - return ret; } @@ -3078,7 +3069,8 @@ int iommu_device_use_default_domain(struct device *dev) */ void iommu_device_unuse_default_domain(struct device *dev) { - struct iommu_group *group = iommu_group_get(dev); + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; if (!group) return; @@ -3088,7 +3080,6 @@ void iommu_device_unuse_default_domain(struct device *dev) group->owner_cnt--; mutex_unlock(&group->mutex); - iommu_group_put(group); } static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) @@ -3175,13 +3166,13 @@ EXPORT_SYMBOL_GPL(iommu_group_claim_dma_owner); */ int iommu_device_claim_dma_owner(struct device *dev, void *owner) { - struct iommu_group *group; + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; int ret = 0; if (WARN_ON(!owner)) return -EINVAL; - group = iommu_group_get(dev); if (!group) return -ENODEV; @@ -3198,8 +3189,6 @@ int iommu_device_claim_dma_owner(struct device *dev, void *owner) ret = __iommu_take_dma_ownership(group, owner); unlock_out: mutex_unlock(&group->mutex); - iommu_group_put(group); - return ret; } EXPORT_SYMBOL_GPL(iommu_device_claim_dma_owner); @@ -3237,7 +3226,8 @@ EXPORT_SYMBOL_GPL(iommu_group_release_dma_owner); */ void iommu_device_release_dma_owner(struct device *dev) { - struct iommu_group *group = iommu_group_get(dev); + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; mutex_lock(&group->mutex); if (group->owner_cnt > 1) @@ -3245,7 +3235,6 @@ void iommu_device_release_dma_owner(struct device *dev) else __iommu_release_dma_ownership(group); mutex_unlock(&group->mutex); - iommu_group_put(group); } EXPORT_SYMBOL_GPL(iommu_device_release_dma_owner); @@ -3306,14 +3295,14 @@ static void __iommu_remove_group_pasid(struct iommu_group *group, int iommu_attach_device_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid) { - struct iommu_group *group; + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; void *curr; int ret; if (!domain->ops->set_dev_pasid) return -EOPNOTSUPP; - group = iommu_group_get(dev); if (!group) return -ENODEV; @@ -3331,8 +3320,6 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, } out_unlock: mutex_unlock(&group->mutex); - iommu_group_put(group); - return ret; } EXPORT_SYMBOL_GPL(iommu_attach_device_pasid); @@ -3349,14 +3336,13 @@ EXPORT_SYMBOL_GPL(iommu_attach_device_pasid); void iommu_detach_device_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid) { - struct iommu_group *group = iommu_group_get(dev); + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; mutex_lock(&group->mutex); __iommu_remove_group_pasid(group, pasid); WARN_ON(xa_erase(&group->pasid_array, pasid) != domain); mutex_unlock(&group->mutex); - - iommu_group_put(group); } EXPORT_SYMBOL_GPL(iommu_detach_device_pasid); @@ -3378,10 +3364,10 @@ struct iommu_domain *iommu_get_domain_for_dev_pasid(struct device *dev, ioasid_t pasid, unsigned int type) { + /* Caller must be a probed driver on dev */ + struct iommu_group *group = dev->iommu_group; struct iommu_domain *domain; - struct iommu_group *group; - group = iommu_group_get(dev); if (!group) return NULL; @@ -3390,7 +3376,6 @@ struct iommu_domain *iommu_get_domain_for_dev_pasid(struct device *dev, if (type && domain && domain->type != type) domain = ERR_PTR(-EBUSY); xa_unlock(&group->pasid_array); - iommu_group_put(group); return domain; } From patchwork Tue Jul 18 19:05:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318143 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 3C7C5C001DC for ; Wed, 19 Jul 2023 05:19:35 +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=bWeBDCkTwECmayeWMx3NhxxGadR9ujvbLOXa6O2XBtI=; b=sEQzQrupLZ+zu7 637HAoE2ASnhCyH4bNh9VgqqRwKTVaq6UrcSGDaJdts3CtwBjwlotTW9EHtKF8OV58iIIxiL+jmgr UA1WUUBrfbBmpinQSQ6obQRyUTTzHXC/QtCZQbOYglbabAmMFQP2mr+vNuegBFP13Sc5ukD9w+EOi SkwQ1p4fFqqtiloiWJZvvKGznvCHC0xPdYaPlc/5usx2DprPg/j9uNy+yqCYtIXmxQsPJ+0jBsZp6 1p/yxnPUprBUjJ9oOttU+/oqwsADhdhlSgtfWDk+sDtUxSDc77Fuip8PMqUscd/t2QnEn3FgHJotU ulmArgcZJurMW3gSOdyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qLzaz-005DZ0-0l; Wed, 19 Jul 2023 05:19:29 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLzax-005DYS-2V; Wed, 19 Jul 2023 05:19:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=ukn66KhLeCsvtHlPco2qZ6rSHFsaSzXOasMO11oLCi0=; b=G5dN4iwhjkiMq0raD0XUpRuXVE Ic98a9t7ufCHtly8+MjbKeIUVbq4y162Tp4R7FPeHSucMg+S8xv/YGpWE6wiSML1SUxWv+uJ7uBok pzesEVbyjk9kHn2voQLutbKprW0mIeKuipmWA7FAeM/fCZkLckuzkr+qlalQZxtufe8GapglsYbdb tjbbZTafkQLJYWnr0sMC0J9S/dl08mFu2TsaOc62ygOFc9ga0/4O7caEHIpRWsq2kKvZ9Ll93JANH bAYnP7flg/++R+kC0LTJ6wyxUAtgZl1cpyL+ElUv0gH5OLinAGNw8LaIBrENYLi5htg6SOyC4SX6v mBRGJvvg==; Received: from mail-mw2nam10on2060c.outbound.protection.outlook.com ([2a01:111:f400:7e89::60c] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2V-00Bvgh-14; Tue, 18 Jul 2023 19:07:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LOJmBMqvEVvh4SizPINNEg674e5vuBCiTFhrA6S0LVJrixQaciWa5XrQIEkaL2eVSUboWblalc9o3zfoHH2YqqouXh99RXrjG0wWS7pK6BLzoIDTIV8xYuUZ2YrzzjluJq51Jcjz9/z74XQs3L89Lv1AFUCy9id+sEkRoBCrOJLFO29610ky6JVIEuacSw6O44mZK/ShB/ba2PSiKklPGxHLsQLorcDXtGU+Y47ZToT43w60vJXHMecMcQVAvXVhe4N2reabkexVyWtA7IW7UBebWtMnl/ImUD9c04a0KAJHv13iybbIq1ltxQMu6tHlkD7EcCbGInZOji8LzF2wqQ== 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=ukn66KhLeCsvtHlPco2qZ6rSHFsaSzXOasMO11oLCi0=; b=aUGoQCrnxdYDXCMT4K1EN6olOPW3dyGaCCnkjWR2vv0pXzQ8wCLobtglVfr6M9OQ7AVvMbstHpSOMLwNvGGdN2dfGG67Zr+PeM6bVRSJCo8ZUHDoCV21AIQ1CBniRzsOzK7ERcSmF/34gtwdDlxLagurkn7T8rvScnKdTJpNxl+IDq5uXj3Zia0k3UCRtB+LQgSEz80ZEzV6QpwABxOuX13NcwuCh3+77dgeeYfzQpPimyvqIbv0hffMukKOpoFx9su4bbJNZXV4iFY/ov8nEW1C4oNvbbqUe3PaZLAZaMhTec4BhsGXBAPTLRNZmd0DRhdhnPt30zbBjJCCoay3hQ== 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=ukn66KhLeCsvtHlPco2qZ6rSHFsaSzXOasMO11oLCi0=; b=HN1pGkPL+77VDGr3jp5hc6tJxaQMXwztaKGA3eqwASCdQcqE8cC34v2ud7MpWWUJxYDzCrDKIJKRDLi4J0XEIc027ZPBtVh8fz8C4r9NeKVuTZHHDaupqZJjVJjbNGFrWVrHOwObT2TKCpCt3QpLyB+Nd9LC7YfQMPuqBJfjN6wuwuP7DBhisx0Y7mm9UaHYeCNkLvT7z/n/he6n8JSN2TJgygPx971QP3WAF+UZxA19iBPVxjt6QpWQAwWU9/aU2tdj/F/Ok3vKD/AruaIKGNBAyqi7AB5wPFjIVLkqPZjKPQJTuucYzQMHRFpXifzXsvT/O7XYlECNt+U+jXLV7g== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:01 +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.6588.031; Tue, 18 Jul 2023 19:06:01 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 02/10] iommu: Add a lockdep assertion for remaining dev->iommu_group reads Date: Tue, 18 Jul 2023 16:05:50 -0300 Message-ID: <2-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR05CA0042.namprd05.prod.outlook.com (2603:10b6:610:38::19) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: a44b31be-078e-49b4-7c9e-08db87c20657 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ePRJaiudtrzrYnTY90p/Af1pXeXPsTKqwftbMrYomct972Ka9x8CEPgWmf97yx9kQLTSgL03o//VRnzRHHoKJxhkMjgAOtCEO12ObDonM08iFtXS+046jtnFHeuRgevDZNFHBgf/3sLTq6I2FqKcU6zqfl2xNl6rXuF+ZpKqFyH1LH9KiYXFVN1cOjhJoH4QXMKh2YUod1nthcmUqYaVtcdFKCvjSVEkcJmuPEDhShJAG6ZcHpqVYi7jrOrWVwfwq5L7E82vNm8Gd01dvz1tF389zNDMiSFtrJiTVVnKX8jBI/7fMFAEFSSZSyxHV7dd4Qm3SSfwpE1xQDNDoeutPI+yWa7nNw6qxKWbLlWcQ4ZjRw/TWQIcVbDjMKTrs8gSaSnY6QRSVoxCFaBVhT0/BodBL/jxAqO+qsx+T5qMYFqoXS6mHPBWq4P1aDpWMAms0PDEuUDtr2ZLtxYl6FLhH6ORiKZ/XcEWnFhMZZlhzwDJ4aHjn9jENMtDGK3h6ygXTjGhmv/fMzjKpzDEy6tPP4QXnM9q4pXgrBfbQ/1++wjsNjBJ1Fw5UA+1REyvUZiKVssUgYPhQKZvzia9gKIUyYD1YX5ij7nbVCl5wHCUWTDgGycG4+zkToJnMKw4OHqt 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wlyg/TZG8gNYo/dLhmOVO1MC525h66hdvsck4jgg/6ii3KIr2F1yBcJTHf62iVCEHzf8cWgDYAXbLfJonLp5FQj50N3NNQYcrXZItBdDBhmVfGytKv6m7KXMPdSwBtSqpiKioLW6bRVgg1Zi9zAMGyPBuhiqgrix4fisWz6yhk5l4NWHZ/A5Vs3cUET+DKe/ZbUO1fW4rakxnkwoWbiPH0Wfv++wC2KbANS9sgYy6J20onlv+rRQyXXuxm9F5Hb9d614dUAxZeeqtAFWGvg64BC3dVjwWJ9ta1SfXoh2Qfb7e2wVtDw5LynUQuzHhvOy5SO1SjXxPfxPYXJVqgyZdkLcHeMpe1PzVBhpUPuY+CuCKCfiHmnZiAIHCITV6stLLByOAUR1QEtfcnDfi4Ez5kaCwoo1/H15TQl+2VbhtIRRwLdMYNnyyPjGI2HOU2+QncpLxAMx4ICSJujvk+huKAAlaSR2pDabZXTLEqH2WRJafkephuvHvXiuiDoyvqywe5l6HQNUw78fz4vRSa4wDaE5nOYqAC9b8dS58E9xCjHqXcT0lMbcQJ1JAD+VUXrNrWWQ/AVvn3CHCRmxc4h71KLZ1VmnvfYSdkU33r/GvuIF9SDAbDlZ7nlOo9gvadBOE2vFduGlEV3lMPVWzHjnPIhlVsGdrM88uIsHJX4BwphZyQN7dxQeYxG3sueEn2MafZJwQxZzK/doo6fKZnvVEbWURh+dQFVnvpSFB9Ye0lCkPDAWBT+lFrOh5nUi54SUDnGi3yXmSaDJ83TxG6VxxoqsY4lcXCNPNNYZuP940OWcxIqEfYyEVnPYpyqE19CfQfCLYfS0s1GDe6nhxugqiLVs3WaeFQommMgxevMU+SswdFbr1Z5gXlreU1LP1GiXBoKwGbyKV9RGB6AesmpMgdnp/FeLxd/7XY82pBapfbJmsWO9Vrw783exM9SiU30TK9h6tPnnjJIz602auM1DheV/UlhjrVkI9GPJPNlJmnzPV3Mo7O3P8c5zkfuy1fxFVlaIv4mbgOSxhPa3RtBwxjU7uYYfchlU7apiincu0gJFjH4goXuNkUyEnhvQHYGmBL4/85u5kKOS2JYR9Us8gxZEZN4UFR6p1UfgF2WAaSEBHqDO+wMHxwCdv/PQl7YM9qFWHB07wNkcCUgRPCa1qo9B6PmZTHNUPHI5HfcV2KTDbo6csXz84YGb5q7Sl2cshCnYEsctSvdP2N9S6x0IJOXoGumGiglBsM+386iTNC8nxdZmhg6TiM4dgaIWk6wMkmtv6IbBEil3OADqdHwDCEILjJ2CEc/P+wEnDaxyMvF+D4HoNjCStln5ioqtnS4jUrKCYQjNOjyy35dWPJLtVxFY9+zDOtPLtSRocCSbyKJH/cDbZj/B4/c3fmEHnF79m1sseB8pjMwUuVobk8oqC1IjbQm84PQZwuqwDXaQBp4TjvNbt9jGH2NzJqFnQrzBfL6hQBFMq/TLq+4lljhYS7AVXsQX4j0X8E26VQ4ZmsleJ2/+QVHdcaT4yZrSyT7SHKZaTRjKEmW+CIJYtKp+wcNk9wZgGInQbp0zZ9cHXHryKCnE/bO90aS3+XzUNd+6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a44b31be-078e-49b4-7c9e-08db87c20657 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:00.5038 (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: vUFi3nQPrSM/raMVb31q82+R+jnpZIow+vZz/ueZnz3T/qe68CZepGYoyIrxhc/B X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200719_037838_DB9CEC31 X-CRM114-Status: GOOD ( 17.23 ) 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 The remaining reads are all in functions called under ops->device_group. Broadly these functions are walking around the device tree (eg going up the PCI bus tree) and are trying to de-duplicate group allocations according to their logic. Since these functions don't hold any particular per-device locks their reads to dev->iommu_group are being locked by the caller's iommu_probe_device_lock, and this explains why iommu_probe_device_lock needs to be a global lock. Rename iommu_probe_device_lock to dev_iommu_group_lock, make it local to the module and annotate all the device_group helpers with iommu_group_get_locked() that includes a lockdep to indicate that they are special. Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/iommu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2f6eb781dfc317..9e41ad4e3219b6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -44,6 +44,8 @@ static unsigned int iommu_def_domain_type __read_mostly; static bool iommu_dma_strict __read_mostly = IS_ENABLED(CONFIG_IOMMU_DEFAULT_DMA_STRICT); static u32 iommu_cmd_line __read_mostly; +static DEFINE_MUTEX(dev_iommu_group_lock); + struct iommu_group { struct kobject kobj; struct kobject *devices_kobj; @@ -438,7 +440,6 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list { const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; - static DEFINE_MUTEX(iommu_probe_device_lock); struct group_device *gdev; int ret; @@ -451,7 +452,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list * probably be able to use device_lock() here to minimise the scope, * but for now enforcing a simple global ordering is fine. */ - mutex_lock(&iommu_probe_device_lock); + mutex_lock(&dev_iommu_group_lock); /* Device is probed already if in a group */ if (dev->iommu_group) { @@ -497,7 +498,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list list_add_tail(&group->entry, group_list); } mutex_unlock(&group->mutex); - mutex_unlock(&iommu_probe_device_lock); + mutex_unlock(&dev_iommu_group_lock); if (dev_is_pci(dev)) iommu_dma_set_pci_32bit_workaround(dev); @@ -512,7 +513,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list mutex_unlock(&group->mutex); iommu_group_put(group); out_unlock: - mutex_unlock(&iommu_probe_device_lock); + mutex_unlock(&dev_iommu_group_lock); return ret; } @@ -1219,6 +1220,12 @@ struct iommu_group *iommu_group_get(struct device *dev) } EXPORT_SYMBOL_GPL(iommu_group_get); +static struct iommu_group *iommu_group_get_locked(struct device *dev) +{ + lockdep_assert_held(&dev_iommu_group_lock); + return iommu_group_get(dev); +} + /** * iommu_group_ref_get - Increment reference on a group * @group: the group to use, must not be NULL @@ -1532,7 +1539,7 @@ static struct iommu_group *get_pci_alias_group(struct pci_dev *pdev, if (test_and_set_bit(pdev->devfn & 0xff, devfns)) return NULL; - group = iommu_group_get(&pdev->dev); + group = iommu_group_get_locked(&pdev->dev); if (group) return group; @@ -1573,7 +1580,7 @@ static int get_pci_alias_or_group(struct pci_dev *pdev, u16 alias, void *opaque) struct group_for_pci_data *data = opaque; data->pdev = pdev; - data->group = iommu_group_get(&pdev->dev); + data->group = iommu_group_get_locked(&pdev->dev); return data->group != NULL; } @@ -1629,7 +1636,7 @@ struct iommu_group *pci_device_group(struct device *dev) pdev = bus->self; - group = iommu_group_get(&pdev->dev); + group = iommu_group_get_locked(&pdev->dev); if (group) return group; } @@ -1662,7 +1669,7 @@ struct iommu_group *fsl_mc_device_group(struct device *dev) struct device *cont_dev = fsl_mc_cont_dev(dev); struct iommu_group *group; - group = iommu_group_get(cont_dev); + group = iommu_group_get_locked(cont_dev); if (!group) group = iommu_group_alloc(); return group; From patchwork Tue Jul 18 19:05:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318371 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 EA9CCC001DE for ; Wed, 19 Jul 2023 06:47:16 +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=Z3QWknwN0ny3McGx5DgO6M+6xHVulg8u/tnF5O03F8M=; b=2yiSnyku7HdXLo msp8xm1QITZzi6WdKTUyA3+yFsTXw9V44gkV752Gs4R7lM2rvuK/riHAnCkfRqxhdqJoQ2zW5yKz2 TjNUPMo7PhJUAAx92IpAByFUyxOoxNc46xoPAFED8z1GJDSiz9UvriUlQh0K5SPFUQDcxRPr1ptT0 jOtfFJocxR3tXOVoJIUYpP4pn9klU/YLRpctoTt62eGmKaKF0/E1kJ0rgiQfrtUwZhYFg5/Y7D+CY VEGUVedWWm/za/5dSOkR9Af34ERLXFDAhSZJzMcVIv0PKP8RbWX3KjhcfDP19M3LOJ8zJ04iNcj+b gfPKTlNKeJCUWzNQtTFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0xp-005tRd-0V; Wed, 19 Jul 2023 06:47:09 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0xn-005tQW-1I; Wed, 19 Jul 2023 06:47:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=7pnbxtqHWGpIJo+wuQLHeeEKl94TLbOO5AnLoMVlrio=; b=E/yU5QKNX1PwJxikaLt6l99sYs 1HXarmjk/Smf8Uxw7oFyzLeZN2Kz4v6jUvYoV8EzRun4dCr1DIeGsdiwqDI8EvvaE4swVNIiqWvnl D/lmq15lGdNsveUiE35FmbWQrHAy1cu8b3sOSMH2QbluUONgiDsyYRKmy3USkQW3q5r/mfpkUedFl s4gO4MM6lKsfuL5444D6ozbV8ChC3dT1DKOGEv7vwTuAw23ol86CtqA1ZEUCQcIHo7MGVnK8S1dFd eO75B7R3K68Kb+rCZpt6PjgHGsudoA7jV1Wvpth9R2khBAfYsANAQP+lWHpCyp9EuUncTA2FbOWhc Y/98MtgA==; Received: from mail-dm6nam10on20608.outbound.protection.outlook.com ([2a01:111:f400:7e88::608] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2X-00Bvjg-25; Tue, 18 Jul 2023 19:07:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fNsOkQ3Gb1aWge27zEzOyPSwScUjkcslZGMcB2zOuI2JLVZxet8s1PbFXj9PoWdxgvE5iL3YHtDuiwY2U7C1+5OJOnCXt7j0JXHYGccyAykVDRbTkRljQfTtLyaRmeMZIibflX5chH0PI9fAV9wcwykuFMDRBN3hmak5Isr+OrdnJdJNZVUDpUqHZxyQN6PqkOfzqmS+pZrXogaktd6+x7ZvAqgiS+GpHB0R582zb0UtnsKi3HJj7xkr+nsKENqZTHispILZEEUuEcPz5S7w6pk+S7ZmptBHIt7C7f2droMW5buQq0YFL+0XNC81we0Qk37kbRPB/Mf1eUBk8Revpg== 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=7pnbxtqHWGpIJo+wuQLHeeEKl94TLbOO5AnLoMVlrio=; b=Aps9skWn33S3Wbs7QwZED3otf4+Kjyv72OaFCX4+2RXe3Ab83kOY1inny/e6HIQf//jPGe05GNHxVDogPlIldWF8ZFJjnJY7OT86zJ/W1JPwLHgdp0qXKl46K8jYljd3LZUG1S/hUXhdJnr8wU5EvzFKR9VVpibcISFyR009p5U+bOicg/nT1F04KUJT9qe+u/1t4SWMUQerx6PBQ3joc7EAHUCbTU6LbRKpHCLAvaQrVCJYQ+kHMKuk3LMD/GLqLelFxzttuiOauxiPoufhYsSJU9NtS09UXrfME2Gs8kiDQP8xqURFQMQpI7IPUIC+YNfpNuuf6b+9NGXB/+149Q== 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=7pnbxtqHWGpIJo+wuQLHeeEKl94TLbOO5AnLoMVlrio=; b=NZEO4THihMFsi/lhQePmETNzAR0AA48+53o3xCbfGqXzSsVeB58isJpCn98JG/2ceKWDKU7P5hmw78J2x5p5lE+Ea4mG6crm1AqOxZjK1SWHbcycyG/5rxqGPUbdNkSqySe3iMUBSuFxS32fxxh/9tYMaPbUU+S+uwQX/hNVCm086nLTcEJEkVjk3Fmp0DmQ82X8p0Hp9R/DhPkYQt3x7ku6TojDdf7RSEDGyvEaHAhkpVZtOyzBZ0jBNmZTKWd+YDc9kgf/0QCByIuigwmI5n+XTVUTihq/tcqrY3qm6H3owmVWTciwkZyFlZmG5XcxcuZn+yNkTgUxvenrk4O+4g== 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 DS7PR12MB6264.namprd12.prod.outlook.com (2603:10b6:8:94::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:03 +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.6588.031; Tue, 18 Jul 2023 19:06:03 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 03/10] iommu: Add generic_single_device_group() Date: Tue, 18 Jul 2023 16:05:51 -0300 Message-ID: <3-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0094.namprd03.prod.outlook.com (2603:10b6:610:cd::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB6264:EE_ X-MS-Office365-Filtering-Correlation-Id: fa47b215-5d56-4b76-62d9-08db87c2076e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D+A9gRCH3tHrBY5uvleFwHYoOrXtXPCtHETlPDe2YOmzchbCTOBD78FQn6wyRnpt9nkxp62hLtWZSMep/Kegw/A85nRTUiZl9xfQP8s/+cKmB4O+X+rVj+KiOiZovti6YY7uZva4xt8IJOwz42AExvBqbstWbLHOPQ6jbNk3hktTrJWgYgOHZGTUoonlqkzOYSHY6zHun0z7yMyoN5yBe2Q99KHkuyvQE+XzRc/uNM/ESQqDCB7qyscB2QVrZUuY34+iWky9HYPPzTfNpDFa8pjQboEda+jAj7c7HTmPyybOq+V3DUYkx7vB2w+8bSYUyb+anTSI9jChvq4WNIA2kdOdCw4MpM2qwplxY09dQ1hcfgOoV/rTlqusmHe/SQrASD/JfQIVlXLpL2W9IcLokSWubQZFS4rDj91yyZOAE306lafvgMahd9MtBJPdqGIp2+/iHh8lIp4nkc9lbfBvPIOzWEI2/olGX2W8klH26+NogQaYWhR1WmVfiTIsoaVTRBN6Y7MGgLgR+yt/fj4mHWbxnutFKZ2c0mBq2/g5SXuiYhE5mVirc+oQnGy474wJkXxUJmKzbd1qGZU1ZjK3+eI9+MUqa8ZxcOlBXSjTTIm1D4a8o2LauNg3+Ga1Gp7ZEh+ljbZGBZzcjvleWbVz3g== 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)(136003)(366004)(396003)(346002)(376002)(39860400002)(451199021)(6506007)(26005)(38100700002)(66946007)(110136005)(36756003)(66476007)(66556008)(7416002)(5660300002)(2906002)(316002)(41300700001)(4326008)(8676002)(8936002)(86362001)(6486002)(6666004)(478600001)(921005)(6512007)(2616005)(83380400001)(186003)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pVNoWXGNKGUaEeQYArLoYokTjQ02ONIfQ4Qi8/fuR7cosXCwuxwpe+kPeS2hnewvFDh+kblpcDZWBMhiYRntL+qo/UGnEACkCModRsLCL02a4bc+jRO9r1ej0O57iq/ViZTVoS5MBIEg6tNJCe+byNZrt1aL47BQ29wuLFoB1d0Q4uNwlt2qBf4S4LCgh7Skor8/FmbT1QXuPfzZ5eGbp1I4oQrTsAbWCiCSvrFdooRkXnYD8MW/wqHtm9xEcsvd3Z0BEwQm5rz3ge7SmvIuYY0oNJ1y2Ix4QeBg+tsbr1gf9zkKA2gOZs+pl028QHZWZeTWhwP5uStAa8sXt9cA+O8DPEG+jKRo1Fb5/JXwriQMyzDmyPaAjLW7bRmsxqqwHXFnRNHYGSKRxxEommDrolKSNWBYHKi39ixnjUEqEKECrwPypvu1hw3w2GNXEQBFW3dGDx/EtScgExrGkJ6yLOWLlkzsI+bDH0nlno9KfHvnnKvCn55HiKL/vhYZNUvjhGMnUkDt3g19Ga6zxHQntFwP9sBuukId6lxicQhUkqGhQ5/QXVFVZNdQj4g7oKLJfPU7nTTKfID4iMOxN3E8+mYd4NaxhGfeX/bU0EFmvfDw1YM/39ULQMiieuaFFncTO4SAdpP9P6y2zmVbNXgM30uzLzvJlis1/m5ZZ6k6c9sZsr6Ob3fryHwZqt2ktZnUBjlpyYQLWvYBDFn3LvzKB9/a9MjXLawRcxX488A0J8MePr0Wc0iBNbQirusIK43c/LyxHgU0HH4+61csqr5u4kNWOXRj29ul2360e7hJS5B1OioAeyYWIP6vR7R+2Kzr/IkfT+RsA8oZlzDjvTlBxtgQ6j28/qlfJn8xG2/ZBUX/FLZsDYvYsVfaw3bkQv5QRaSxxAG10ELMPyXytLGENbukFdNle5O9qERJj68BI8KaehD8NKNNkecU7AQyd2EkgQi7a6J9enj7OZYCF+OrU1r8ih+UAOdz3usdSW0uX1f33I6YERdmDoD+LWeQ++GWntQ0dmt11c8Wdn0iYptD2Li1nYMQJoqBQpJ7n5bCbD47/SXm0LivpeQILC3niOHUNqSy8cBo22VifR5pMchQvTFlsfaXgsfnEXQbqhJaFsIruZ2YuUjGOT/enGJU9TYRxgLAmJtncABmprnQmGTcryWXTFy6GAussH0cG9KK3adCvKS68BB6g7Bf657a7X5pR+gP+rNh9balDOCHxSU4Qm1g1BENyFMGTpwfvn50clkuv6K2kCEc08rG4belecc1vLV1ZA2RLAesENpPHZITolIL5IPi6eCxd2zvpc7VXQ8p1k88U4DLO+ixTvj5t6lmZktT3lHHZx/NklWRnR8bzurRZnScVnrsyebYWkR+09oPcqIfCCaxEJj5KQT7sAuJu+aMtxJclbaKxJ21WN+La6hci58hlVgLhImU+4OkOsTpcRXw+o/9LFA7L6shMTz9ldLd8YZs0pxKenCMumEtSXVOOb7Ja7ay4h2AD3KvgQH1t02X4atxQRD15eo8HbkTvhU4wyn2ekiJe7wFXyZxVqWHYO6NDz6cBx+T/jbPjaiMquGTh20WNk/rTbfvthm4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa47b215-5d56-4b76-62d9-08db87c2076e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:02.2195 (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: UemF4KK99/7p5/gKhQdjyKxCcrBtOuZFOdovjxoMNpyTIRvaVEHVOK+Z9GGtWWLv X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6264 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200719_120687_2ABFAE1D X-CRM114-Status: GOOD ( 14.80 ) 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 implements the common pattern seen in drivers of a single iommu_group for the entire iommu driver. Implement this in core code so the drivers that want this can select it from their ops. Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/iommu.c | 25 +++++++++++++++++++++++++ include/linux/iommu.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 9e41ad4e3219b6..1e0c5d9a0370fb 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -289,6 +289,9 @@ void iommu_device_unregister(struct iommu_device *iommu) spin_lock(&iommu_device_lock); list_del(&iommu->list); spin_unlock(&iommu_device_lock); + + /* Pairs with the alloc in generic_single_device_group() */ + iommu_group_put(iommu->singleton_group); } EXPORT_SYMBOL_GPL(iommu_device_unregister); @@ -1595,6 +1598,28 @@ struct iommu_group *generic_device_group(struct device *dev) } EXPORT_SYMBOL_GPL(generic_device_group); +/* + * Generic device_group call-back function. It just allocates one + * iommu-group per iommu driver. + */ +struct iommu_group *generic_single_device_group(struct device *dev) +{ + struct iommu_device *iommu = dev->iommu->iommu_dev; + + lockdep_assert_held(&dev_iommu_group_lock); + + if (!iommu->singleton_group) { + struct iommu_group *group; + + group = iommu_group_alloc(); + if (IS_ERR(group)) + return group; + iommu->singleton_group = group; + } + return iommu_group_ref_get(iommu->singleton_group); +} +EXPORT_SYMBOL_GPL(generic_single_device_group); + /* * Use standard PCI bus topology, isolation features, and DMA alias quirks * to find or create an IOMMU group for a device. diff --git a/include/linux/iommu.h b/include/linux/iommu.h index b1dcb1b9b17040..f1e18e81fca78b 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -361,6 +361,7 @@ struct iommu_domain_ops { * @list: Used by the iommu-core to keep a list of registered iommus * @ops: iommu-ops for talking to this iommu * @dev: struct device for sysfs handling + * @singleton_group: Used internally for drivers that have only one group * @max_pasids: number of supported PASIDs */ struct iommu_device { @@ -368,6 +369,7 @@ struct iommu_device { const struct iommu_ops *ops; struct fwnode_handle *fwnode; struct device *dev; + struct iommu_group *singleton_group; u32 max_pasids; }; @@ -640,6 +642,7 @@ extern struct iommu_group *pci_device_group(struct device *dev); extern struct iommu_group *generic_device_group(struct device *dev); /* FSL-MC device grouping function */ struct iommu_group *fsl_mc_device_group(struct device *dev); +extern struct iommu_group *generic_single_device_group(struct device *dev); /** * struct iommu_fwspec - per-device IOMMU instance data From patchwork Tue Jul 18 19:05:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318316 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 0259CC0015E for ; Wed, 19 Jul 2023 06:21:12 +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=WHj+Aw/GG/hBkWLqw03iEnSRz/Vl862y2mcKl9LAu9M=; b=kowWAj+ID5Bpg8 9ZjQ+D2OajTmQn+LErCaspUEAniE7vQizS7ju3WlJbxsdDm+Jx54QTxkT8J5HGOtaWCzc/JQmdPZG HO/snaun9FYqKgziN1c73LNVDDuZjWqqqO1nrKNLrPEVHNU6dBU7HMYJk6opzzjLvBcGTkJfKYaf4 i5nkd3OYdWwCgGRUpQ8QgTOdYth9j8j7446R3JBPsmUKabV2Gg0JQfNs9wEkh3k30soiL/B1ZcvTn Xej2nCGPPaPR2r5akamV99dQig3tvZ/UmXTbcDQXbnlCqz/vthSymIWIrHIcUIgnDsd3N7SZL24Bz Rotx4WviR2GF8Du0ePVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0YY-005g2V-2x; Wed, 19 Jul 2023 06:21:02 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0YX-005g1X-3A; Wed, 19 Jul 2023 06:21:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=SrLde/OIC0cgtPmLWXIJF5U19mbUA+17Secmw/4gCag=; b=MSaTnQllhd/U6/9JW37nKpHaGa 8Z1BOCQiIETHkM6TS4Ik5TNCrkYGU3I1wDDy33HwuqfWayXfcdnJaVm1wSuFsQXWJzTxzctcC2sxz Qmip2HQtDzA2pHNJfiHE6RJscyGDwtrlFC6mTDP7lg+ZEQI/YDEbrtc+eneYGUUxNLz6vsbXvOUIx +Ik0UAbVNYLeROFPYxm+d4JZA3Sgv+ahY2yXmS4J34iEcYZdrSBOOXxwhwSVu/XNrY06w2v45oW7a p4j00a9uCQf8/KKo2j/QoeMqwMydsb0iI/qYDJkkceXsAL0Gql0DUTggDsAycbb7mqLsqEgebNvl/ Pif9LD0A==; Received: from mail-mw2nam10on20609.outbound.protection.outlook.com ([2a01:111:f400:7e89::609] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2G-00Bvif-26; Tue, 18 Jul 2023 19:07:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LllfVeens09LQryR9nR1xRCTB+5Rnl38z5AVV1jXCuTjIO3V6vkcieHC3p9/iKsXMY+45wf9Bjwk8Ai+9c8eMp/LOjDPfEqGPNl+a8gUd/jHcp4DYNnynqpWqUxRSwXlZnRrVaO4tjdeg0dw/IL0oMuA26Nx+Reb3DFWCpEIvVFbLocWxq0a0POu7JVNXPZrDSKsqvvUWoYepUDubCOhD4OPzAUHxLgyhTJB8xV90wYkgyBZGIx+yN33Y8L9wVSiZw6a5l5bgKeLSSYRSqSELs/PNfEYzsHGdS3RoWM69dQv0X6TSr3p3K1JfUbA8GZCz6kG2gcF8m7QvHlYCMMOvA== 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=SrLde/OIC0cgtPmLWXIJF5U19mbUA+17Secmw/4gCag=; b=lGrq7IRSqNZBk6IbygcB29yiIdq5MEk88nWjGMvCMJIfBstg23nTOjIZB3M2LAHJcyMDizVttIaIQhvIxlGWXdovP6EKKfboLLPDAMA3F/tlj7eB2eNuhGDpETEcIp8R0SSrGuhGrOsc4AJW0Lilly+EPmB9z3R9xsSd4SObbCDHGMw9X9nf41GlH8AeduMR3SxVPLoKbtRCDykCzFLke01ZpjO3ogLBnKy6mapFZLkxyuEBdAFy5YAmQBQCmnymLpnMfEk1E/VHlCUDOV0jxaYfoHTwtYD0aT4k+LYeExh8JgGUxdZ6hGzWBnpgjLI8hSuiKu3y7j4wfIGJDj8c7Q== 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=SrLde/OIC0cgtPmLWXIJF5U19mbUA+17Secmw/4gCag=; b=kYo6NlixnJAa8D/JmbI1R6TSESnq/G3jbfFAv/NFAlmqA2zZfceoqXZIEazRYFqb2LIIqs10Ij3P+Pwe0cjg4t5zidP0ZDZstDsPLywVHLj3w+6OcIRs0JGKnsQ6U9wzYKmWiidBwfwSRyU29RfiiG0yqtm2LiLMvkznbfxV0OdZaIbFMOH3Fgofee/yf6ZjhTTnmVnRJPC98YMJ7c+nHsNDVCTvRhXbEO8bOhVpeDJCNIZOCwswzvM2l/u/T5cHtB76za0lBfRef/6fPwaH+MtuAB0GMAx32RK7o4olAd5/Mba1y4h5G9v1keGc6mKoRvjxT8YmL6Ro3qXHduZlaQ== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:00 +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.6588.031; Tue, 18 Jul 2023 19:06:00 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 04/10] iommu/sun50i: Convert to generic_single_device_group() Date: Tue, 18 Jul 2023 16:05:52 -0300 Message-ID: <4-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0101.namprd03.prod.outlook.com (2603:10b6:610:cd::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: 03351347-0704-4c80-a92a-08db87c20620 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ItdDadcKRdMIMco/7BzdkAYYRW4Zf2xcKztRlaWF5AviCzpWfbzzIqcSI+J4lqxRxTknvgp2bUWQ7ZFrS2H0oZ9gYhqYv3/vdPiWauWouiy1GFCQ4owSg76AFMmxee+pYbiywfvvXETTQwT6rp/OpySplELSnnEGujvPpXZ4Cjvk9cxuP3xeG9wRyO4ThxaIrK3mkJG25CMPc5Xf9jNXVb2pCdD0DRlms6HJmA+GEOX+ohs0OdDimEIj1VUZgQTmkKTKz0VIJflrwvWUNA2GPchR4tD1E1dOT50ae++CjzcCqKF7rjhPjNc3IuE+fqq2asN2jjb6sz3z6vXwL3aHcRObT6MahuOKkA28MmSrArdDKMkTGvcrOmqxlLFg1ozA6lex0uzlYuhCvUZeWcgKzz1rxoL00eKSmNuBksWFyBc77Pxsefrg/A5E1B2HAQ3153NlUiID3l2P0/gl2UyvoVKCrYEcr2gb1U6CQQj6N5gyXo764C1oP+Ts2GfP1SJgES8HwPvuoj+NotYnJnvjto1VACpKHyaInnz4cvHDfMjZbvOBctmzRfeSwISX9Ghr4gRnJPaJn2MH+i5qDtSlBzzv0iqtbCmDy9v63LW1VSd8qB0XRxSy/uElVN5kbfheAXXE9UByTh9mjwsjTZkilA== 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jVFq/mIBTF0GfZKJiDlUMRkv8EfEqKLymaUFXO8k4A5E6yywtNcbasPdVSzlNLKMFIqsIS6KxL0yPX9noktB3hPVESA08AH2eFL2N0W4tF3437sB9NNqpjClOMLBgg68/TVSaqQBC+lMyrT4XZQK8mTobcOyEwvqA7Z/jZQbaf/xILsuLt0QHYLWJ7J+Ji2awu+h6urdBin2zrSHyyIfIRWcWvq3b6xO1o9Mokn8RaYNfLPOa1x0bSIaWAWV8dMC1u9iDjZvKCDOA+W0DkqeoFvZGpklNiVSNvQhH+tg27UFAWa3YGwytSHujQNCtk0TgBfJqenycWepXe/AQBmOYuV5h6Z7Px1VLQLdXf7CqZNICUILWPBQrxEPuutLUC6vOT7oA+oLBPM+ZgNuAr3knwhvZn4u0RawXh4ldm5lJ2pPxHuy9uqO8A14aaIJw70q91qWQz0RvgfA7JK8H0vDM/eBRz26+eUNrzYiZ35+QKEsK1t829TXDusEHUXO8tTtVlcFaEOof/mLt46/bm9XdY1VpNB+UWg0bMiCRqMDpeyFF9UibMFLk8fgwocRJQ6cXmaLUcQt8lTUHNgaBRiPc3vXLbniL2x7yTOsyWMGGH/uLV8vRVANLwyNWUCCiAedv69mfXoEshXm5B5nLxKn3K8cXNQL3VwNJnv4d4JfOWDri0i8fwvNd0Yb3rmLxTJDiHVFPmwwrwFvADhszdQrae8kMWHksMmcRQnlciBccfj7ie2PA8YDEQCA4Lqa7Taf373V1ePdQrOPZxrdrhxkrqCCvNuLwp65gRDF0iggJS8Fe8m62Ui1XXkTV2SPZZEShbWP6n5sLQy7IL/i95Q87XkCrwtNXOvfuXV46oNer1SWMdagbURB0RZCMv6PjQjkNlSoLXddwxOOknC6zTJwfJWMyn30zauTABXFRSubV/zXlWcODGbGxTw+j9nUT5p6h+uGRSjgYr/0eD39udCnO/xsMrtg2tJdtGVl8ld3+KQNyUvBh1UV31Nvjsmt1Huyy/cvL9mdxT/HH8a5fCXYobTHMBgeL8U/ZlcZbGM9ReBJ9MDdSUkHkiyVCt2LJjxE91UMhMvM2amwvN/J5ZINBseoF9wNZV5V2fGTeUuuu1S1ciGtxar/OgIE6BTqZhRUvNthAiLHDtr9p0LGj7apL/PtU2TCfNwX1bxcWG/XoK7DztPY4C3EzRyii5LMo8lR1nDS1UhqtDrWka+/PY6e0Ga+w2MdJbWAjl8OkKttxrRXzZ6rCEOSf6L4s+iCn4sTdtEydMTIw3ZdiWZORE0xHZje83uC7VsnPGm5pSJots0BSafsB9KaJTvqMzac3Y0rSdxOwXKY9fMGhuzGvpUI6pRIh4v+uSwRxwnenPxUwT0S2KTozk0TyXpHbE5rpwQsLmojf6os9mHq+Q8RwCa1kYZm/d68JOZ7API2bnwgX4FcagvGHsZI+9IsLnRqzdzwygscwrgy296wKdGNxPUXyRHz6J1UDy5TJuAXUrqRVgOIPlvp8auTpwHpsclqtVNX6rdQqvKz695C0rRbqOl+JpeAHfHDZQqAL0TTwbJHR5ynMFZ4Up94p1bDiwEuu8x0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03351347-0704-4c80-a92a-08db87c20620 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:00.1675 (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: pGL0EpBMkX5GJkRnQFxShH67lJDtUcHePitGFHTNAHQpgqY8HQGN0WBzKjQGxcnx X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200707_844316_90372B8D X-CRM114-Status: GOOD ( 13.06 ) 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 Use the new helper. Signed-off-by: Jason Gunthorpe --- drivers/iommu/sun50i-iommu.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 74c5cb93e90027..b8df655185ab2a 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -107,7 +107,6 @@ struct sun50i_iommu { struct clk *clk; struct iommu_domain *domain; - struct iommu_group *group; struct kmem_cache *pt_pool; }; @@ -808,13 +807,6 @@ static struct iommu_device *sun50i_iommu_probe_device(struct device *dev) return &iommu->iommu; } -static struct iommu_group *sun50i_iommu_device_group(struct device *dev) -{ - struct sun50i_iommu *iommu = sun50i_iommu_from_dev(dev); - - return iommu_group_ref_get(iommu->group); -} - static int sun50i_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) { @@ -828,7 +820,7 @@ static int sun50i_iommu_of_xlate(struct device *dev, static const struct iommu_ops sun50i_iommu_ops = { .pgsize_bitmap = SZ_4K, - .device_group = sun50i_iommu_device_group, + .device_group = generic_single_device_group, .domain_alloc = sun50i_iommu_domain_alloc, .of_xlate = sun50i_iommu_of_xlate, .probe_device = sun50i_iommu_probe_device, @@ -995,42 +987,36 @@ static int sun50i_iommu_probe(struct platform_device *pdev) if (!iommu->pt_pool) return -ENOMEM; - iommu->group = iommu_group_alloc(); - if (IS_ERR(iommu->group)) { - ret = PTR_ERR(iommu->group); - goto err_free_cache; - } - iommu->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(iommu->base)) { ret = PTR_ERR(iommu->base); - goto err_free_group; + goto err_free_cache; } irq = platform_get_irq(pdev, 0); if (irq < 0) { ret = irq; - goto err_free_group; + goto err_free_cache; } iommu->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(iommu->clk)) { dev_err(&pdev->dev, "Couldn't get our clock.\n"); ret = PTR_ERR(iommu->clk); - goto err_free_group; + goto err_free_cache; } iommu->reset = devm_reset_control_get(&pdev->dev, NULL); if (IS_ERR(iommu->reset)) { dev_err(&pdev->dev, "Couldn't get our reset line.\n"); ret = PTR_ERR(iommu->reset); - goto err_free_group; + goto err_free_cache; } ret = iommu_device_sysfs_add(&iommu->iommu, &pdev->dev, NULL, dev_name(&pdev->dev)); if (ret) - goto err_free_group; + goto err_free_cache; ret = iommu_device_register(&iommu->iommu, &sun50i_iommu_ops, &pdev->dev); if (ret) @@ -1049,9 +1035,6 @@ static int sun50i_iommu_probe(struct platform_device *pdev) err_remove_sysfs: iommu_device_sysfs_remove(&iommu->iommu); -err_free_group: - iommu_group_put(iommu->group); - err_free_cache: kmem_cache_destroy(iommu->pt_pool); From patchwork Tue Jul 18 19:05:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318544 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 559ADEB64DA for ; Wed, 19 Jul 2023 08:18:05 +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=oJh36wRfk1IZJ2DQXgDGsJS4v7ACeBr7J0khN8qXtt8=; b=IllBFrVzfgXvAz gaFYRrDUjBoeOWwbRjDk91mI4GRFn+55SKXj4rUCPvV5u7DOIyxYdv3HnFgIlZFyLQS0u3F/sei1v VHhKKFzqurNCkUC+ehV+78UuYdpviUVwA33C1J0TpKoIENKhPvYE8p+yWgaXJGUqldtQXuAAbS9it eGxX7idGfc46oSc7BfNjV6oDPe7GW8IBk8Bibfv/XUjdheN/28ZQ5en+ypY69gJ8xkJHxZvs+YEdX N2yXH1kSizhPsbL0Sy9mem/a+UYTm4L/5o9EDaNarSnjbchTi0W1++X6RXy3lQU5odnbPngF0doVN tGilW1GinjFNM6zO//Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM2Ne-006He2-00; Wed, 19 Jul 2023 08:17:54 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM2Nd-006Hdj-0d; Wed, 19 Jul 2023 08:17:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=hvwdiC6E5CEiy25PSFgk7REzIIrBWJs/ybCCiwdcjMs=; b=UV6MEQq2SMTFteMPEvlgp/zlCh oTuUWkszFd29jZYww4kJXgMWE7kh1FdnLQjyVI+YP7DHCnHGiTq9NRTe+AJZ4g7RGUZPzMiZorSbV 8fpqvBYrW7F1hHV6jwBKwG9aCAu4Axr6439bTb/jr/ZE/05Xw5PJOf8Mlqz7bXqi3dfmWY7eSW2hy J/+ud3CBWC03SCScmvaHvtKOHOGR+6LPUHpyLNk0G2fAt16I0vFDkMloxc+gywCWwuuhitu8qIJ9R ZZPehhN6qQeokmBaJVA+tCa2GsJdDzgZRrulAaLWDN7rdQuBHPHVBFZ2vkxQMaDATXZ5cjxstCv5V faKifQkw==; Received: from mail-mw2nam10on2061e.outbound.protection.outlook.com ([2a01:111:f400:7e89::61e] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2h-00BvjX-1n; Tue, 18 Jul 2023 19:07:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i29eL/tZdPg1vVMF5gZf+BjRfFnIXh14DseczAaURECLy10corm7/5oXKXT0+t7SXjPUc00AlFJ0STwGo187HsuxXLNgXRHt1atDPanAaXJ5Z79nteUycXIHeZ0lyyzZAFmnPbuGcrXEvBMewzueGoTuk6LdaOnnswV33H1PNuJ1YsZao80uztj2qRaskRSVNcsXJ36/dchh30E8sucnEG7jN9H9qOVMJngzvasmUB5Bb1JOpipD0Nob3OCPFP47G3xGqbhED77IoJKEN2B9FZ+UfBdKzNy2yFCcaHHIUfniBt1aKml5e+E2imxpnrC7F5dFZ+OFvtXwRRAO4ub6zg== 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=hvwdiC6E5CEiy25PSFgk7REzIIrBWJs/ybCCiwdcjMs=; b=iUsXfKZ4aQoD9Ayh82Ix5re1gReinVIjthI/0FuJxmHDCcGufXAu7suYdbMpVvfSzvdRerA6XaxN3XbdQgWM4Vsi2eQhFNyDCqJoBVGA6Sr0yk58jn0jhOmCeWf94sllECIQK2qQVyhi2x936a38Z7Txjjaue0nwHTrYcy8mwTcbz2gcsTJzRMKdCg8EivTq/5j02EJdX9LuCFuzSKlJwU39VIPxinuTZDt6oUEhO7TwNe6rOgIM3fRslGjifOsfQ182wo0RW/ryXKLQ8k39n/xN+nRIRy3CISzswJy1XfqYLZR+UszqK3Rx0qbfm+LCtYJH3aZsU6nHM3YTF6sjpg== 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=hvwdiC6E5CEiy25PSFgk7REzIIrBWJs/ybCCiwdcjMs=; b=gMHMbfMbWIQafZQIpEklpBBJ5yFUyCGeuhJf5nuEg4Otm/BmZO1mDUpz2wP5/iRfAOoIcPNBoeKXcrRt2S04CreWxddUgDGskzDsukBtMEXL1XUCBH2/26bovdufutC2yhyIE9mFBkh9dp3DEJWq9pM4K3kox5yv0TKZFw+lJpY0eyXI35g6Fa9OtmZIeUwYBnMMnlSnhaWzd6BCyEh76M2/+HvC43SSEvz9fpEz8rqtDgGCPMWTGaTuY9RboqAB5teAoFWJhRNd1FXuh0EuzjMYm9ik8CR6B5Qpy6CWS4rovi0XHtgAIWJM/vlBsk9hOATxLiXfcFsHTUfdbX5QYw== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:02 +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.6588.031; Tue, 18 Jul 2023 19:06:02 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 05/10] iommu/sprd: Convert to generic_single_device_group() Date: Tue, 18 Jul 2023 16:05:53 -0300 Message-ID: <5-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0098.namprd03.prod.outlook.com (2603:10b6:610:cd::13) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: 66291ebd-c23e-4706-1845-08db87c20741 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nGqKpBzPonSXjnixyKZOAlmwq9swWBnZqZbLdCR2x2I7fkaRd8r+HF/59Uppo4Rc8sxb6NnsB+5RhtA5YSnCBzWGEOAIxeaUeKvNwtlt5PD+dxC6tsC8GppBHCtxCso/WJ6DJq6aJpyRivwZsHBJqpr6VlqfdcVhsVu4JEVU8+Ur6J2eJSTJfQ4yiXb+b8tJ+JEO1BySt8xxZQYiyrhE752CcaTv1yrm8RzgQ1ia8+V4mB1UEg/EJbkDmrNhnd8CSjFNZ5fJucGrmo/Zp3pBAcFiWqhErHjDA5sg4zfjUGRUhDv2A56QljN4igrDKoQWKgnQnP2HlBuQmvklvHQt/We/bokM3uETDKYJ0uzQY2LduP0GhG1s8jUqXadRg/4WnKGOhSaPIVBZy+6LleEc38WjcI0ObFIziBGYUqaLgsdidFLOvvh0kfBZwUPxIA7KgIV8KeLDDD3SrWwp+DdIv54r0fLb174Nb6encIR/g2hZ/LSgtsE9iKebz0f3fEYgZc7V5VvR4NOnoYx6XTI6iwuGyONHH34qgM7mOOT5lPDie9z0aU8uH8kQKWRKNviuq3BSy3TUVlFiR8SkgMC7tYkEUOxecLe/vkqTAjK9HUeAuo5TJfZxchU82vYOMbqajDrklWRLim4NST4HoTkeNg== 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FAiSilI2AEX1WM/+id/sdhA7Sabg2oFT7Rz8jcvV6tlet+s1695z79Zb8SdOkcEjO8nb0La5LWSqQS7HXqB3MJ6m0vTc7Qp/A2089BuFMAhMiRfJ5/5d9NVzIAU28R+eGsHc7dATe4yfLlDN8eYv2cqyxoC/DkME2NLtYtBEGeClvGGCeGyfRtI7QXyy5PGwq3eyKORR2JVi+ZxsJXz0spKJuQXO3diKFuPZgngbdogm+zePSvRywSowbqNJN0vTobPJDhV+C67krlmv5XAW2U/5QcwtcrnBrHMDec2B8Ji2vwlyu86dW1AQCldVCjNX+XYIk5/wC5lH1CrIrabH8vaxm3X8wa1nl1iKFpV40hGrtxBGPK7YjXvTuWjqf+NXLJsKUEJ+Q8m2Y6r2bcTtzqpUjihdTrbhSTyGJkQ9a+IlDgexwsH+GWmMZujW6i8bWpx2FFb5XIDzhcvP9B/ONBxMU8YTJbWjEjLOgS2naqKzbcULq39YE39ZTuf+qdaF8wXllRoRoVp9WsqKXmQrp+9XUdTlYM0CJtquKHxcZptTyiE1/SSeeIliCpS/3bLgsxvuq2uLq+JpB3VWicoy/6bViiSHr0McGMBwLFn9ZKY9i/7Kgg4tBF5mt7hF1AywWrHRACppg4Eif1RsCmqIoNLSRkAkfGlxv3/y7M9kKcECTlAK1f0UlxQdu6o8uIvceQWeCEgKjEdoILSorRv3/r3bM3vFUrVjqlFdrb+pTICkziD48cj3Iht+Rk4ZRgJa0hW3xr7z0tJ+DqXWX0A4V/Ve77vnL2lE73gbL71+EBPgDP74z32V5EtY+l088oNhqLbpAQ+zxeWdjWmhYizZ/WogpRxmsdvY0rBxaY+K/WONE7LbJFCOE886QPkzGPq2nzsm1e+Y57DZ8zSpqhrR7c+QR3LgpOtqliDrE78TOaUsgm/X09auXPZay7cseaR6GlUM92rt/GV2VT0tChAnOLOaGpT8f+W16KT81w37UywvYFiZC+2Q7hiHMwVcD9gxm5wd4rQcxi5CId60jxYpRndSVkHqKkBDelmFEk9gWKy6w5FklhEdY5i9pCtSolqvOWvKq3Hwzr+fLfHTBMZicjcbn6bDCzpDT7PJngwcBR+9u+1zr/Uum46ixLOaB1d6xbweBPb5/aGboh0Raka+4rr7oYgznpvgOiqHvDQ6KlWX7e2ivnx/q3vqMEjqN1qOFPsesJIKt1SAmctzeKgp9kTFPrdVTGVDw0lA3LkvWRcCG5VyCCH/0hX+2gwqaH675i+c+GZgTc1XJULSM9HpN2W1Lzlo8HffGrmJ4qM7j78fBW7eGhkmYQD/ayBGg09hcJyCyJ+NP9vx70UtqGGNIsnuR4fgNCISZNOOJ6H3u9T/cI+YuA28h4MpmxP2D33zxvolLQfcoi3kKA0TSlxhX83hYuuBpEy+n8tVf1KWF333+clYksfcc8QxUQnf/i+0AtPLcegfoGQ3TB8VjU1VFmL1K5nsJq9kzsN8BqjMNZM9YnG3s4TxeYOu3PTj6RycDLw16Nur4RpxMF9H+iC8MJUu+TJ4It8wXxCdWUODzTq6lgv5PUI2zFOgwA/pBWtR X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66291ebd-c23e-4706-1845-08db87c20741 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:01.9531 (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: f1fLm+e+dNOUIVGtjFXvVl4SwvvGDDoGqezA6eaUbD9qMzaHOqW/dCHX/Rcdd6dF X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200730_357896_13B241B9 X-CRM114-Status: GOOD ( 13.62 ) 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 Use the new helper. Signed-off-by: Jason Gunthorpe --- drivers/iommu/sprd-iommu.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/sprd-iommu.c b/drivers/iommu/sprd-iommu.c index 39e34fdeccda78..9fc98fd144e445 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -69,7 +69,6 @@ struct sprd_iommu_device { void __iomem *base; struct device *dev; struct iommu_device iommu; - struct iommu_group *group; struct clk *eb; }; @@ -397,13 +396,6 @@ static struct iommu_device *sprd_iommu_probe_device(struct device *dev) return &sdev->iommu; } -static struct iommu_group *sprd_iommu_device_group(struct device *dev) -{ - struct sprd_iommu_device *sdev = dev_iommu_priv_get(dev); - - return iommu_group_ref_get(sdev->group); -} - static int sprd_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) { struct platform_device *pdev; @@ -421,7 +413,7 @@ static int sprd_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) static const struct iommu_ops sprd_iommu_ops = { .domain_alloc = sprd_iommu_domain_alloc, .probe_device = sprd_iommu_probe_device, - .device_group = sprd_iommu_device_group, + .device_group = generic_single_device_group, .of_xlate = sprd_iommu_of_xlate, .pgsize_bitmap = SPRD_IOMMU_PAGE_SIZE, .owner = THIS_MODULE, @@ -494,16 +486,9 @@ static int sprd_iommu_probe(struct platform_device *pdev) platform_set_drvdata(pdev, sdev); sdev->dev = dev; - /* All the client devices are in the same iommu-group */ - sdev->group = iommu_group_alloc(); - if (IS_ERR(sdev->group)) { - ret = PTR_ERR(sdev->group); - goto free_page; - } - ret = iommu_device_sysfs_add(&sdev->iommu, dev, NULL, dev_name(dev)); if (ret) - goto put_group; + goto free_page; ret = iommu_device_register(&sdev->iommu, &sprd_iommu_ops, dev); if (ret) @@ -528,8 +513,6 @@ static int sprd_iommu_probe(struct platform_device *pdev) iommu_device_unregister(&sdev->iommu); remove_sysfs: iommu_device_sysfs_remove(&sdev->iommu); -put_group: - iommu_group_put(sdev->group); free_page: dma_free_coherent(sdev->dev, SPRD_IOMMU_PAGE_SIZE, sdev->prot_page_va, sdev->prot_page_pa); return ret; @@ -541,9 +524,6 @@ static void sprd_iommu_remove(struct platform_device *pdev) dma_free_coherent(sdev->dev, SPRD_IOMMU_PAGE_SIZE, sdev->prot_page_va, sdev->prot_page_pa); - iommu_group_put(sdev->group); - sdev->group = NULL; - platform_set_drvdata(pdev, NULL); iommu_device_sysfs_remove(&sdev->iommu); iommu_device_unregister(&sdev->iommu); From patchwork Tue Jul 18 19:05:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318395 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 17640EB64DA for ; Wed, 19 Jul 2023 06:56:39 +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=m6v7jeXu4SbMHzDvcwLrA/QU5hs7R9FkBNry/UE1SgQ=; b=FrVxCamO9gDEQ0 yulJ6pbACWSykQZxcSt7ILR2uhXpc10yB/bEuHFdAMMmhdoOoiJCCLsK6lUcrSfz5ru3LkAXQ23pZ vUyPjlEnwdLLVR6sI0C+XkrN+nqwRx70ReDX6rZ4V2MZa160qw2a9CP+2asStiP0hiEHTTFzOIXLU z8Kk+VJy8qtsch9nBhb/jkQld8SSzuY8USqEnY42B5BLQzcixXBLcq+Aa6CD4VlRlaQFqV+KYJWOl meAAmrTHnN+YD3/wmtZDE/VzCA/mgJ71xo9dw3p8mQnGvrjFFlvWUNjwo7BbXOXNREUjv+/v++fpf xLwmMAo/YRv4HX3N1pKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM16v-005zDq-39; Wed, 19 Jul 2023 06:56:33 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM16u-005zBx-2O; Wed, 19 Jul 2023 06:56:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=lF20GgUKOoytttAX7Lh/dfU2iYeWLRAsCCkrvp7s/OM=; b=kUwfmWU5r6xyuHoA8EZ7TpLW8K fuApVkQTs2UUO2QSDmzY30O9KXwLE2xGkheQUGlu8yPxZBcdd5SMtuu9jPAcPtWfhsMwYhS54DJ+i islUpX8bvorCs/hu1FCJ/TsTavCytvlw8U6v851IXEBKTQ+YT9+UwfRRe73Wumco29n4XtYhkvyqc cTSaXuT3mU2ueFrL+TQb6ZRD6CfLrDOuutDrftNS9dpg9RxYxb0lrrF46xy6q3NIzxONFbWxBNxdx TgMRLHxs60g7imCc6Ysdn1lVY6TSMPLjetRfKAqNY0/7xP/hXJ6azd28IXlJSitBQAER/CjeXMkML IvgyiccQ==; Received: from mail-mw2nam10on20609.outbound.protection.outlook.com ([2a01:111:f400:7e89::609] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2h-00Bvif-1I; Tue, 18 Jul 2023 19:07:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Frt5JINZ1pTmetuol7aUY7Y/pjre5CWFSghdQMUGommMNJ7RbSsq18O9aabIlk41yc2UAMP2f3otYQ7mKvoowfNPG+C+p2oQbpTVdsufGFcK5TNRZNpt82EZ+xWYk6PCiKramBJHZzfHnro+Fbf49rjGKGGVcszsYlUgTz/vFK4MoO5feDifldwjnkgl8kqNVP7nF35btaktqfQ99hiPhWFdXJM4GzfnrxKZnQ5T97AsLxsDAvL3JsqpYp1FcssPTcPdgBd0NipEdtJtDqaeFuDrcnxLZiTnLRVuWse3IyDd/BfahaVjVPLa0Oxa+DYLNhERbZMYbuYBj8eHSMuEiA== 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=lF20GgUKOoytttAX7Lh/dfU2iYeWLRAsCCkrvp7s/OM=; b=Zbe/BTPSA/Clz78ewCOmmaAU+qlmXww4c1ixwMNW/1hL/6+TxxhB5/1GNFttsimBUxm9kmd9XkYdVFEwho4ux3pEmpB+IzWwYbR6sL3Ji7l0Y3fFTXfqGSJUTVaS4W6WtosMl/pbw9XL5CWmpA5j2AVr4eLgajAq1giqZihZxELqAx2Qofoz7JRMdriR+HapLPMrdRPXyRYCyjhzyVlYS/Ll79F8ruMaac8LKAllMS6EJ9pvnohx7udaZJhrpnRwHwOFeC53h/MXVRZanL4n8N8mdeJroNCJwnHIgJpDOOx7iwaXyURYJvsXhIVGZ+0NeQcmeOjKDYblEToRk8y5/Q== 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=lF20GgUKOoytttAX7Lh/dfU2iYeWLRAsCCkrvp7s/OM=; b=eM+Ul4qoWyjCDEv8f+R8Zx7Ey/sYCTZPbBxOLkLByJg5hjAlo7DUo4EQl1qcgOO3SfzHFt5JIgfgfiRRHzghQ+grHkLSC/XsjkrjRFWMDXyXqbZv98ZyxWm3RlmHMtlQ50gXyp/UJcY1R35vUE6/P/S+3N8VD/p+WKjAIsYUPoK+3upey9JZGrHQ1KWzJcbCUfdweaQYIinnwGawdoeuZqJif6MDzzVXDY74gCePiMjEPFgUTXiS8x368ZwKb+2sCTWSsoDhVU4Whou+UfaByHDVvzpuj9oKGpprJMcM2IMAgznngqUKg4yeri4fpqFGRAKnOVuZjCaH/BUGGTXuZg== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:02 +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.6588.031; Tue, 18 Jul 2023 19:06:02 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 06/10] iommu/rockchip: Convert to generic_single_device_group() Date: Tue, 18 Jul 2023 16:05:54 -0300 Message-ID: <6-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0P220CA0018.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:ef::30) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: 13f8454f-c42f-4f5c-8f59-08db87c20737 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O5ysfGhkHCM/O9WIyaA+ZlzwuKQyEPWbi60Plh3yLgXL6zZDt6J6suL9olq96s8LRFBpukclsUwBMmne7e0zoP+t/4v6OBN3NPGyXJw8n07Erd0ZLz0OXE3CRZ8gft7PmlxmCBuBdXZRNh9qmXWc1DYnaSxcwjU0HBT3tRHbwn6tSZUg3P4F1M3TMV6cIFEF4nOt1XpiBsMILD/Emia2sqfHu0nr9NTqf7J87CZMCFvKToCoxFmQaYGih7cBsad0t9WYMmnMpgOnMV+H2Zxc6v1cKksm5qC+mO9GF9h4ofeuMJFEtnA8M+vpWl6lp0utJbh/EQ4Vpd5YrGFQ+0T1gtx8a7zzPAZl/YQxlYWfOMMpgVXJFt8m8gZesheaKMiYfFg8PkoYVDAslB4aQTRqjCjUFmVEDiI1jX0gzu9hAEE9seSehxoXC/14iXjF4syS2yxF40MIxF49E9JcgiAE0YF6itgVFiI5e5C2d6C0T0NSO34PasfEhFFSbrNKqStNGPaQM0aXq4Vqak9eRQkeOWmNob1eF7i95FqlGENK4rWnsxeuPODeN2vdExU2zmZAWmc6Wd/kQPntHrmuybIMmlRMfZ7eMjW9H+D+32ihnleeQayH/uE93+lhS+SHGKvX25vXSuy68f4gGskWxUDu9Q== 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yul6aPNttOTZMOdaGf5Lw5CH//iSVa9x3D3RcJ1SKbWH+hM5jSFn/SS2CFkh874lUY9Jk4zqO526KJEL/11FCcGcQcFXrEH7TzHfBEk0ViYmI2kVHAXAz9h52o/uWfJ5XDAg5KRfCAJLzC+bHfCKpb9VxxqzIycz/V2+gHUSwbcyOzrhWlnnHgdnAeb0ViYbn/SUnNsdWDY9V79bZT65LbeTkL9FNy9Woq1GnW1MPCZiV0zdJPw04eWP2bW3lAWjhTBE48LcTf/U+grTTH6bLnqAKoAD19jI+FdayNPRMDybL1HcAWxokfJezTyowWIC3K/2U+keVhq1hxrsg7pFuybUKvzvo4JcSnIhbF1hm40kYWxMtzP4vb3EChVvs90HqmAf8o+9O/nmcb6D1LC7VssLQNwdCS//9F3JKXOhuaz5B+32aXiXX+s/q9MFLMSdqsgLgKLN2+lXsW4ZXF5rXHZDa4+eaVxVyH4/fG9eoBXbJp9/KFvyOItFAewEqGlR43XEfdk3TyuDLufa0jNur7BVY7+tlknZfwK5ElEL5T60TIuG46lcyV9t0fKHOKKFPrqyK8USExnKuTox1HfPgnNJ6EfEh69+ddAMZh/cUYCLOZu2tEaWebw9Nyu60wwf1TJbBC0BRys5rlAL/rffOZzPxwaVpqaxSyTa/Xp3XqwspfNxTg3eNfjeqmHKDpe/vVIrHTutSh7kCbsdbxmWt+Z4rmznhRF7nD797L7n1nYlOdmGOtStvNrLFioI/5O2KftqkMv26vJG5dUL7tdD73m8tdvjazWLcjFAUUFinfng3qzOekJOwkHaw/haxqKi7UDaLcvuoRp/IAMmNByw85tKyEmymywlGoQEbJUb/jfOZrBMCvgzWKozqaSTYm1sUxyrA9TrlQjBHwht/RLipIYstrDv4Z6UITSmGK3TJqQF1KcDd2VsS6mYC8KLpB0FSjHKZZp8My4p342UOsmfZrvVF418ahPzgEn+R3c/sFVE6Ha8AFK+JvsTVBv0UBnh6IS6bqFQp8q345Sh1kt8Wfmpvikim17G10sYHj6HMJnvd2AtT8LxKODO2muS8ndol4J1ldyD8G0IGNbm7lPfrFv74U3azx9DDf5+LFhgdlHwHEuCRgi6CeaSJPWVjUz9Y9JUCtdBUaaBjWbpZRUag6MZkRvsWjsnsbx0l/4A/E9YbPGCfnBww1xMcfxCD0gtrjExcflvAM9ISFRBRDzNtBp71daJ6wSl2QukoggFqTBOIMLR3rxgZ9sP9gWNTSqfZlhPWgJvOdvJlcNpjnTURl9kIMtAHcQkVQMHwJ62zSbaNb/whcly4TO7kFOOmiDiKM0jbHDGqLC7fiqI9niBDMr6biFXEt6cXp9YVpShvcU44yKrgVZB80uQ9VI+s1cAT6GZbS1wEiIlwtYcvqWiYaaMKEM182cnIFptYeQKNySU6EYLp+BVyfDYxIrpYqanaRDT0hgpxkFdfR+l9jOZCfDN0VAwrgffXP39ssTkMJpOEk/HFyjhg8U2tfsOBii7S6XW4pDVsHj1yCD+bFZthC5aoNuJ2sIN1bnZSJmG86ZaqML/fSZGsPPwzZJByHPE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13f8454f-c42f-4f5c-8f59-08db87c20737 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:01.9392 (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: nEb4wJHAXWn7mVDHrmgS8YSj+MUT5f/ue49MwQTcgs32KM7C+qEOmebWwWY8NAgJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200730_349988_18440B67 X-CRM114-Status: GOOD ( 13.99 ) 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 Use the new helper. Signed-off-by: Jason Gunthorpe --- drivers/iommu/rockchip-iommu.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 8ff69fbf9f65db..91f13cc9411548 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -113,7 +113,6 @@ struct rk_iommu { struct iommu_device iommu; struct list_head node; /* entry in rk_iommu_domain.iommus */ struct iommu_domain *domain; /* domain to which iommu is attached */ - struct iommu_group *group; }; struct rk_iommudata { @@ -1155,15 +1154,6 @@ static void rk_iommu_release_device(struct device *dev) device_link_del(data->link); } -static struct iommu_group *rk_iommu_device_group(struct device *dev) -{ - struct rk_iommu *iommu; - - iommu = rk_iommu_from_dev(dev); - - return iommu_group_ref_get(iommu->group); -} - static int rk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) { @@ -1189,7 +1179,7 @@ static const struct iommu_ops rk_iommu_ops = { .domain_alloc = rk_iommu_domain_alloc, .probe_device = rk_iommu_probe_device, .release_device = rk_iommu_release_device, - .device_group = rk_iommu_device_group, + .device_group = generic_single_device_group, #ifdef CONFIG_ARM .set_platform_dma_ops = rk_iommu_set_platform_dma, #endif @@ -1280,15 +1270,9 @@ static int rk_iommu_probe(struct platform_device *pdev) if (err) return err; - iommu->group = iommu_group_alloc(); - if (IS_ERR(iommu->group)) { - err = PTR_ERR(iommu->group); - goto err_unprepare_clocks; - } - err = iommu_device_sysfs_add(&iommu->iommu, dev, NULL, dev_name(dev)); if (err) - goto err_put_group; + goto err_unprepare_clocks; err = iommu_device_register(&iommu->iommu, &rk_iommu_ops, dev); if (err) @@ -1325,8 +1309,6 @@ static int rk_iommu_probe(struct platform_device *pdev) pm_runtime_disable(dev); err_remove_sysfs: iommu_device_sysfs_remove(&iommu->iommu); -err_put_group: - iommu_group_put(iommu->group); err_unprepare_clocks: clk_bulk_unprepare(iommu->num_clocks, iommu->clocks); return err; From patchwork Tue Jul 18 19:05:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318347 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 482AAEB64DA for ; Wed, 19 Jul 2023 06:38:04 +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=AIy61eT4TZC1ydnu5Gd3ePNVRoW9PDCJ45daKMqd3Ss=; b=pOJ6vgCA8XnFrN VyejEw6NnlcXb7CuRvIz83njn9uyBmoyiig4JOy/IkdH90QK/0VPCUqAXvocKWKnMjF7L5Eq0Lrk/ yJO2JYqYlsHFH6g4WDtFH4SDv4ue4s80hUilTa58ixWmszsvX0Lx5DEZbIMyQ0euugsbrnuag8g+K tA0jR+9zT2GOsnybZc0hsS20E1AQuAgFXQwH3CzP2y1ptegxd4tzTuH+Yl3ejH05FkemjM4yl/pJg sqdxyuBQUYSNhOvdNiAx9Xi1Irsh5/d9cNNlC4L5+hjiGLYABsCe5Lqs5yaj7gp6K8k7FOEjwEpaO 9kux2QocJaA9pk4JB/wA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qM0ou-005oqW-35; Wed, 19 Jul 2023 06:37:56 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qM0os-005ooK-1a; Wed, 19 Jul 2023 06:37:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=WsVGvn1CLzcH649pQIKz9cVx8Rm/xdS4JuFMWCG0qS0=; b=N+1rxZz3F3LtKL2pgYZbSdqpGE ijmR3tdTmKg9bRqcrGs9isNgSLGcL2GpYmI88sZVGd4rKtDYoBOQ9pdowc8Q8GEM28AqIRmxMaiIO 8ALsSB9b9Gpjhf83aTLMVRvMj2Ld5no6tjdgMDUHLvaCAyLnfqR3a8jJTWO4LfSa+m8AUHmczAwrC 8f8b+8GQ2nTlp2LkqU3ENHD1uGOHYALDOrDg4r1XuXmOqXNhRUwrhlnjpQ/2GCrvlrHm8dmml/pE+ ov9daIXn6fYrWmerb8kt83Jou7GAYUIGQZFidx87L0Kv/32Gs9ezXs26ArbvBZPmDmQquV4SX3HkL N+q1taTg==; Received: from mail-mw2nam10on2061e.outbound.protection.outlook.com ([2a01:111:f400:7e89::61e] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2T-00BvjX-0N; Tue, 18 Jul 2023 19:07:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H8gBb6e4W9vlsqAcmiD3oBHKMBt83MkWOl6BqM91JtRiGdanXbAsV91crrZCe/bvlfMy5zH2s/cz/eeynelY4Yi4NTXdZMaP3lux5TlaL231GIUhUDARjVwxY9RgbTKyfI1bmFVOPb/TKPsNHaryk+K28ntuOUn42R3d0HElidS3bztShTSnTTJ3kMNrfJkVgvl84DHSktayanQFffPTQIv6Z22gkk2LsUAUYn0XgrcKiBQAzBf9grPXhoBC+xaIMXG7f9mxVuljQB2gQxVekKaVNkxTCBTuJi8uYrKI/wtHbEtYQwFXBDOR/gOcrDNtZ22t4b7IFd7DMwY+I4/z7Q== 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=WsVGvn1CLzcH649pQIKz9cVx8Rm/xdS4JuFMWCG0qS0=; b=NNO9ETZRk8xKe83wovrL6zkCE85Qle3dNUG7f5GIqW6BwNhadX9DclyOywN5AZBQ1lSrQbF/CO0T6jH3JzgfI9Y5wvqqle53+HZdkxIWJstlrAY7jW3zc+T+8wrb1Uj/XCAVfddz2d/wSNs7is1jfL6HWivbxItMLVldIjI1HGHOvRxOhiWC0AZrSqrD7P66tck5XsnNtkP6+kWHJ6oqa1/bZHtmptw8quAqeYbvfMfBxeYRdXPweH6JvAgZ4zOvkmdsfasEDqusT3m2NKJOyWvwhoHl6a9oHaS0h+xanA3PDWXQdCOPja7dOZVdHnpbV0saVUAfbreYoZuTxxmMuQ== 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=WsVGvn1CLzcH649pQIKz9cVx8Rm/xdS4JuFMWCG0qS0=; b=hQvpA+lxTz5wGXZc8GAknw6ktHYpCQy/I9YoQ2quKCCb0P6cfkJShLmB4od1lUbXP+tQ48vRktn/EUaKYOPLdcA8T3tpFIHXRyu2dRs59OYXfO5IyVuLtYdmc/divMeITchhMdInaj7LiZIYDY/4H//zqWkDnqqvOvKyy3INe1TgcXJ+6bPi2Z80uCwnQOS9r/rXGc+8qXonAszfKf7MOLmt++R4aXys/prSTTTVlB1E63hG8KxiOhTuSlL9967XQtiCg7yN/tIP35JIsqFBq13jp9VjLiO0Oi+BQAmoEZGp10JLf+YORkYwuWTZW7pvCGdfMUS3vEFBIWeKHOOp2A== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:01 +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.6588.031; Tue, 18 Jul 2023 19:06:01 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 07/10] iommu/ipmmu-vmsa: Convert to generic_single_device_group() Date: Tue, 18 Jul 2023 16:05:55 -0300 Message-ID: <7-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR04CA0034.namprd04.prod.outlook.com (2603:10b6:610:77::9) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: 2fb92bdb-ba00-4676-f696-08db87c2062e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hlAXMSyVIbdanwBuBtrtZUvcWBar8IoWNa/ssUdPmsrz3i9o+GtMlSZpkzgTwmogDFcyqzQxeT3hXGpPnwLB0ZguwE21HxCBNWcKZ0GMl32vnN9BQu/T1E62nrZ+9fY3LSDjou3KeKgRxREYu6N/bU4ZcU7KDl0ffhirBwEuh7+4wu/GXYmhj0+dUOWliijiZTfLdXUdg/8BuqWNFI9ugo6wXqy876puwdn2RvekZgbNJcGHlKyfYHyyncambHeJzSeJyYlXDoVYmXkT02IQNgI06z7rG5BZGeTkqwqtfIy9RvH5dgGNhXpv2VPC+tzLBzTHPHYiSnAJviFoOAUwEFRLepHeyK/qjSkX9blvXtDuyV0jWB3nAr+IFzvJCTDo5oi4QyH+r8L/CuOxEpawK8cAfAPSqRRPqOh1oFcuN2CVBS6qjro0JADqBi6bfOP4EjOP8K0gArND4Fx1YRVdna08biRbZPcq/4SV3bhfwhOLKDyMHCp1Q/roaG0WyV+pzeE38znNOJCkMAJNWOcMV6+fGHIVywJycvWgHHpBdTejIwluAAKVoKs952rBFwNiiiNNlspmSBJarNXYJ+8M6hXfJgyEXIgtAzRvdxUSxzK8+XXZNBq4ZESjBkIeUPI5sAfcXp/lxgwDsBU2sQ+8/A== 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qs85dXeNUQ1t3c2bR9ULYBC5CsVpLnvOuQXxjIS+rdrw7jyodMwf45eARpJWw9xR9F+M32lcVOfbQxu4qyGcN5kKPx1+BaGCnHoAh2RZF7mSR7q87yDDYSqUnBCkyZjv07DxaMmXNWV1RQl6FkTt7mEW/kaH8upyq7PcES9arJMmH0ykLPLeRoJdbQa/RI5xpjbXJ7nk8aXKHje9sdEZK1EKJi/eIFippUbKwVEoG5njKylE8IEzgS+wYJek7FQTriQ+tcrROYv5bNrYh3pQwZFs+GgyzWXn2CYtzmddIvAtwOorP5qk0jqkrVexrBPp19kknVLGsHeYSKQJee0K6h2YpBk4++DOI+d9i/gwKMMCL6ffmAPtMKj+/hwAFGi9dgKBvSnL95kaqXanm0g41h4HvASVMLrkD48CiwsBvAn3HatFXx7EvHHshUgO9SYqVwYdt5jIE/wZAZ0hHhkwq+/WkRkNxNpKtozwpkvEFVyXXsJ47GS1YDo6RCzwhDlhBVMI8VkvE9IpzhWVuR6bZ9pmwgbgTCtvDthBPNHOKrVzEpT/PdP/Y7Guux3gfGU+zLqbNpAgq5oszjwEqDaDLjwqawapOHBE5sXKzjP/I/4kGY0CEi/pKDZlOE3eDEYFmJ8tWGOLj7hclDv75WD1uXK+wSNP2Fk6MU/ccV59qqexd66oX3vtfb9Yg+0VPUUySTV4DqlY4p4zCW/b89IGrIitWKkmPXP2HouFf1BpTqhffD4jGcsXQMoRvOW8gshBuiybXUmNPssQE8MRoriW0lUjCTUNXTOkHoBpuuHM1GyTO1EUL1yP5CESQw8syA9GcQW5CEbqeCboAp4UPvoaHtw9KAxw8uVY95CL1d8OdPVcluV8SckEGDT8j8hDYTUsy/UuPIw1u6r88PRfqAhuUghZAIB46ITUzwKvjNHsqTQmu+z9ZLVV//c44gAVO5FkResfaBL6JePg3u6ZFCVXTX4atxxEf7hwRcFKytk8s0TvMnbuavqGIw5HX7obeaxdLf/5vmxmHZiu2j1Hwsd5rn4jmRukSUD8bfQt5jMGwAaQGmVBxVZOTuSbEssWuueun2lGJChD2cYDcH4kT0dXZkkKa0cR0pu9CU7q64d+GxBu22xtoXge2YpwcnBYPlAay5mu3nv5iRvuS/Mu37jYlzKxfp6nMOD3+8ybihUaG5f7UXp75eqxTj/+ZSkm0b9xoUtrch2D/Qw/pa+U8Jfg+vpKT2bMz7+1wxTPFr5x+pQDdj4x5WZet2nYQ09tqk+gM9koxbx41+B7dC1z01HiyAwAtgnrCD6/WJA1Bh/MfZDW54/YWpp/X4aqj572zQu+8wKc4++jx6tqsvqczb7CFxtlukbfP7zQAsJud5tCsxv/x78A/b6T5MImJJLMK+4C7TRFIgbHDw0T/Ga+w6WhXZuwt5EuROYpXXm/6KfEM0diwMp7nmxZmKVesPk9LFvrktSfhhdkDteFh5tXgaBnY5p143lx84nJXHadjsqzvV7m3pTZMcAbV7caK2s8S4HWCFPWySvXbNAXb/A+h9muRR3vjwVFeO1YaKwo4xoCv7MU35E3xTRaLX/Xi0XdAnho X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fb92bdb-ba00-4676-f696-08db87c2062e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:00.1834 (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: xn3fkm/SMRAnW668dEfmGhtRda7gQauv6AbwAOnoke91lDieonY/1JH3TV1bcAAg X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200717_973940_C3E85621 X-CRM114-Status: GOOD ( 12.41 ) 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 Use the new helper. This driver is kind of weird since in ARM mode it pretends it has per-device groups, but ARM64 mode does not. Signed-off-by: Jason Gunthorpe --- drivers/iommu/ipmmu-vmsa.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9f64c5c9f5b90a..55b9b29221461c 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -63,7 +63,6 @@ struct ipmmu_vmsa_device { struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; s8 utlb_ctx[IPMMU_UTLB_MAX]; - struct iommu_group *group; struct dma_iommu_mapping *mapping; }; @@ -832,28 +831,17 @@ static void ipmmu_release_device(struct device *dev) arm_iommu_release_mapping(mmu->mapping); } -static struct iommu_group *ipmmu_find_group(struct device *dev) -{ - struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); - struct iommu_group *group; - - if (mmu->group) - return iommu_group_ref_get(mmu->group); - - group = iommu_group_alloc(); - if (!IS_ERR(group)) - mmu->group = group; - - return group; -} - static const struct iommu_ops ipmmu_ops = { .domain_alloc = ipmmu_domain_alloc, .probe_device = ipmmu_probe_device, .release_device = ipmmu_release_device, .probe_finalize = ipmmu_probe_finalize, + /* + * FIXME: The device grouping is a fixed property of the hardware's + * ability to isolate and control DMA, it should not depend on kconfig. + */ .device_group = IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_IOMMU_DMA) - ? generic_device_group : ipmmu_find_group, + ? generic_device_group : generic_single_device_group, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .of_xlate = ipmmu_of_xlate, .default_domain_ops = &(const struct iommu_domain_ops) { From patchwork Tue Jul 18 19:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318131 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 EE668C0015E for ; Wed, 19 Jul 2023 05:10:12 +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=vYMPnNW10YH+6gkSqHqJtWvk2TOgcZ9lqLeFS2rmYJU=; b=He5g5iWKpQf3c+ qn7CPfBzwZhwkxyxgUxwzcrVS1EGUi8WZo5tT3qKwQhP19sYUAFYmP7sqK8XkvHfF/G+iqgDpwDWd ySgb+OfK3itiS5Fz+OIQyXNfq0RpXjfWF3D/Fu0qOTL3sf5d401bDLQxCpw8Z9tANTUhjDmdhb9qr yRcD6jBDmMesfhPkxuZQCTxQ4njahbPYa+7JhOR2STWXvKZuIYNPDlyRWM6QXnrnyfpQUvuguFn9l LOF0OUy2Xk9UhYsyr77mfJeSfGXqMq0aV8T6KtsK9ZZfKQrtZiCi6Y4g0oFtuaNrgUW5wybDzq+r5 6/3SRRUjzy4e+slMpVFw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qLzRu-005AOS-0G; Wed, 19 Jul 2023 05:10:06 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLzRt-005AO0-0X; Wed, 19 Jul 2023 05:10:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=nZbD14POHu2WrHgEO8Jvpv+BAByIdXDcXCIfoGvu5FQ=; b=ElfJX4QUM97REZJrkMO7E57E9l tlHo4HAkgBrhUumPDPVmsKAKmLuy6gOnomFZ1QrScBf2g8HZl/mJ/FUQqCn1VGH73mS3wih+NjGLd lD0PdH4hXPQF0fV74LS/raKV1R2hbH4C5DDxXWg7I3JFrkwjcGTpE3sAu2NqvEp8AQ2C6eUVcpPsS V3OqEQSClBuWg++a8ktF9+9QK9Q0EMy9PgJXC2lNEH/wUwf2ocv4ybF3mAAkBabQI0cMQ+jxxQGyH /xHfRQNoIgUSME1bH5HrFLWnrm4VOHkzR7a8KcmunYTlDNslgL2xv1KSRpAnO9NFU3Kd58K4Ec/tV d4MnEE/A==; Received: from mail-mw2nam10on20615.outbound.protection.outlook.com ([2a01:111:f400:7e89::615] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq2t-00BvpF-14; Tue, 18 Jul 2023 19:07:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S9q41sScpglmPdEKKHS+l3CEBnWRfJ8m0glo5X+sduQ6pKtuMeNjIGcmaAx3953udc+KRruQU8+rNtF76CLoXXfQupDFdJBlYJaIXVTWM/64ONzdYYTNvWeplXWS8eQnw5dr6pVuVu3PMCulcYLdbsWPbiMlrFYQzQbrUIpxKNr62TJkDsbZpjMDUKejDV4rRzLy/wFXnkYnFAAsHxS2L9ZYhrIwcdUEjbrnDHJQIKwyitLyg3hutaCGstaI8CKjv3je9gPhZ8Zdx1LhRiQxg0WoIjKMmU3hLjJIIcoicO5xFdE0X69l2VvQXP+TpXboGlopJDHWBSqyDaNSJRyyQQ== 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=nZbD14POHu2WrHgEO8Jvpv+BAByIdXDcXCIfoGvu5FQ=; b=UyOBBSIOig0L+UgUPTsVSSt5UltT5iapMj26Twr7zNaP7pWOCmRRNwncAM+ZIXPp7pLLszaZRypO0nwYyqERugkf8zRe2iIHZqsl/I2OcM/m85h/5gi5nfPM2xI5kihMH3DHHe0TGe0vkyyJAfHYpUYdSZDsMP5rn3APwKjH4X34Z7WjdvubQh+33xlC0dm/+kECq3F+LooIjJ/LSQ8gso41YU2fmiKKZAyqWgNHlQuH9tH/e1lZS1srJK8ivg/hBb6B9CXeZQ8PnUiTokt9Hz37wxmK5agrv9b/lkdGMrfXnmcUgtrZKOpYzy0hqs/UQV+ibQlUIJEHFJd3IZ/Cmg== 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=nZbD14POHu2WrHgEO8Jvpv+BAByIdXDcXCIfoGvu5FQ=; b=sWq5OrCLwrtjnD4l2odtGdLIq+arSIbHGC5LeeeggdgHXoIYtL3NHpcMVfCa25dG/fgzcCggejb0RbVw/9+Tu1SF734ZNyT+UsGnTL+/qmBaIJrzPgE9u8u6vkV88zly+OLnkkOHW7YtSL7HuGW8sQS8MGF/y9MOLs1dTXsGF91bkZxWor5iOWSX4lUaB9RqA0NjzZ4hQ1GBLAsTTomPB/tvqSb0lMdDTtkUdKblkna6w8IkuGtLSluWt4MWn54Z0fxw9lbtVR6KMnJSSAyekTQazR/UWHVeilnuxd8r42o5QzlIaOrEiAflu9EIkD/iOOYApl5uMAH5NUpeUpNZpg== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:01 +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.6588.031; Tue, 18 Jul 2023 19:06:01 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 08/10] iommu/omap: Convert to generic_single_device_group() Date: Tue, 18 Jul 2023 16:05:56 -0300 Message-ID: <8-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0091.namprd03.prod.outlook.com (2603:10b6:610:cd::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_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: 035651ed-bedc-4766-7c9e-08db87c20657 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kyah1U0JWdXNbMkkUsBV7TUlFSWQTRa1RxIvgkyImlk6FgHEOSu/RKGbUSFfPBBAvhv1BjWnsBbdFulrga84ddoB9YcxNd5PRfQw2oKK/PZ64eiDLbItn33HkQUJgWvDJ2JxSSOIzf7s0uuhjdJdxM27YfXhNsosw9yFqRdIBpkkh8qHdeuFpiteQUtiQe4qjq5VtnOQ9ihKpokwT//5iRJl78XbjPBhIcBCwwk//lV+BEYNQUvW8HHNXO6pvovt7w0yFx+Qo7mMypmNVJ9HOc17BlKj/JFkAi0ImRRGwIBWpCYpzhP8lI0redmB+kqyvsFPxyUW0HtQWr/YASHHTeXCOtIYgLgpWkH6KoUKGpsm5fA09zDipg8iKcAmfcgBGXzw2G+2Lclgdxqb3jVY5QvlDDhST3CO+IBZdsPt3bFyOZp/HwJBqL7uxaOFWtT6KyVn+hGplI4FRQGBShA7+24GqMZkeHwExamE/+dFfIxHNvAjtXlb/CcOcRMnum3zUpexWlndC+RUMHI33dldQkYO3NX5YChApRLhpc/Z4Zgll3nyjTaDCwf1bAS5ziEW8DJQbZV1gL9k+a/2uCQIpFQItuA6FufulSa9KnTS2gx2JNss+LEFScsAFtbXObK1y7e3WlZ5id7mxXRGGJ+eTA== 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6666004)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uHNtXY0nfg+mRsxsEOxcE0ThzVzItKhoVzSxsutjUFgMcDYeQ7LU030G/8SvFL1jMSr2EVaxxXsXCVpLp9pyoaDxj9PuJ0FcCaDO0Mnyo9KoHstLMNjcP+Ik8a/gpJ/z/nTnXgF8Xg8HYut0MR0QWl/fRgeuv4BiJxU8nWz87MSWyIIjNHu8CCT/jQTGkDANpJPoaLWQ8h+t0+7NmZB3e2hs9GyvEW117Eo1REBAMP0PqEXDWGY1GuO3wLDjC3hhWL2d84vt/ZxvupZLpztZYhf7eb6Q46NWgkfnV+IPMScAtL2f0Oq1EDcMxSYomekSjRYdWQEarq6M/66jGmvCfLa1eRIt/CATmtb5Zknj9hd3P1XuLOPrcl+vTTxRVsACm/CoDdMNAbkPNAd3lZ5q7Qj9l9RnuUUdlDcoETiTDg8BAuTv8sM46GP4Am0Q8VhcY3zP5hKnE5SYGTUlOK7ImHEOEDyflKpXmtBY/GrOTZOKapuSyE2eXKjYekn6KpTaAT3/1+RL7sDE5zbU05reEXJ5ew61ruzJMx+TPoaG31nTVWtwiLTtCnnVIEICo+sABuHSyHQsvw+/VEIqPFow5JD8m15qTjtGJKbvbr12rAWummCfprbIU36zDX6YwewYKFezCFy/WMz/6q9vxMGYaBAnHNppAR+ckiW0zx+xH6304NYff/E5hjZkIZkawRZwzZbl6gRFVLXKpwVEo5HQXnSbvG61sSLoAsthNHiSllJMSje8u9+xyVqgFFyN7SlDRky1rAJG+iP5uOb8o0kAbdm9r+I23+hk6Y4KPYX1uJn1JBpZCI4wNhKLCqz82HdmCNHGxtV5GYnGDep8rkb1yh1sYnnCg2VBHa+IkZYuDQWaxzBiO3ot9XwMV6EDgbVx9Ujwh2U6ymD4l2y4C9oAKt6ran8gcTAdrNw6cgQ7SOhbaKyD4CBzv4XAwoOa6Z23NVpmAtL/+PxCbSoPJW9C9vEZoDRCUsIF4UVJ+TrBPmkPgviFocQ201atgZGoijfOZO+Fj2ohUBGb8LG6YxKIws4V9Njx+LIiz66kMexL7G8VOhqbe6edug4MqEbMBvAmwg2irIUnnhipvYJISmrvdrzoEHI1yGVH6M7WBZ0MrPWGaJNn7h79q67Sbn02izyV5s/1cRmUkLEZj+v2X/coxz9Gf+WW/Tv8CZXjWWJQoc28ppcTvKTEK4tjvQr61jN3GTWm48Sv9qAO0msdFZBi9qlyFspJnbaazEW2PWgNasmR8pDZZvjEdFAY6XTeoT7OnO7nCqOpjzYV43LlmDRC5i3RqdJqo7JknQ3UcZqatTEpW0waXBbJChcW/KkH99HxbrTPCa8jmzujRKn6DvxffP730GUjKSREqWHkzHY9IKe8HY1k1U0ydNRw1RU6Phhz3Oh/dL9zLdFMqi8rxutcZFswZ9c1OSBRfUtrsDAAqKckk1V+S4J4c/PPayH5NKF8xyL7IF/BJ+pMZsxvuXZbBatu0+890aLLnYp9RI9C03soQklNPmZUPTCz2ZKVc4pPxMG7ge3FKdppxOj479N7FYN0xWs7oBwExPUFhAQqhRfpexKmycXt9xzokakY0mfV X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 035651ed-bedc-4766-7c9e-08db87c20657 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:00.4695 (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: TypXv4oTIwtT6hUzWOboVZq1K3EH1Qn3Vs7lDMQfyvwRrOw56tB/L3AZy7jZoyT9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200739_658006_579C4D7B X-CRM114-Status: GOOD ( 14.86 ) 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 Use the new helper. For some reason omap will probe its driver even if it doesn't load an iommu driver. Keep this working by keeping a bool to track if the iommu driver was started. Signed-off-by: Jason Gunthorpe --- drivers/iommu/omap-iommu.c | 30 ++++-------------------------- drivers/iommu/omap-iommu.h | 2 +- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 537e402f9bba97..97c45f50bf4332 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1225,18 +1225,15 @@ static int omap_iommu_probe(struct platform_device *pdev) platform_set_drvdata(pdev, obj); if (omap_iommu_can_register(pdev)) { - obj->group = iommu_group_alloc(); - if (IS_ERR(obj->group)) - return PTR_ERR(obj->group); - err = iommu_device_sysfs_add(&obj->iommu, obj->dev, NULL, obj->name); if (err) - goto out_group; + return err; err = iommu_device_register(&obj->iommu, &omap_iommu_ops, &pdev->dev); if (err) goto out_sysfs; + obj->has_iommu_driver = true; } pm_runtime_enable(obj->dev); @@ -1252,8 +1249,6 @@ static int omap_iommu_probe(struct platform_device *pdev) out_sysfs: iommu_device_sysfs_remove(&obj->iommu); -out_group: - iommu_group_put(obj->group); return err; } @@ -1261,10 +1256,7 @@ static void omap_iommu_remove(struct platform_device *pdev) { struct omap_iommu *obj = platform_get_drvdata(pdev); - if (obj->group) { - iommu_group_put(obj->group); - obj->group = NULL; - + if (obj->has_iommu_driver) { iommu_device_sysfs_remove(&obj->iommu); iommu_device_unregister(&obj->iommu); } @@ -1717,25 +1709,11 @@ static void omap_iommu_release_device(struct device *dev) } -static struct iommu_group *omap_iommu_device_group(struct device *dev) -{ - struct omap_iommu_arch_data *arch_data = dev_iommu_priv_get(dev); - struct iommu_group *group = ERR_PTR(-EINVAL); - - if (!arch_data) - return ERR_PTR(-ENODEV); - - if (arch_data->iommu_dev) - group = iommu_group_ref_get(arch_data->iommu_dev->group); - - return group; -} - static const struct iommu_ops omap_iommu_ops = { .domain_alloc = omap_iommu_domain_alloc, .probe_device = omap_iommu_probe_device, .release_device = omap_iommu_release_device, - .device_group = omap_iommu_device_group, + .device_group = generic_single_device_group, .set_platform_dma_ops = omap_iommu_set_platform_dma, .pgsize_bitmap = OMAP_IOMMU_PGSIZES, .default_domain_ops = &(const struct iommu_domain_ops) { diff --git a/drivers/iommu/omap-iommu.h b/drivers/iommu/omap-iommu.h index 18ee713ede784d..27697109ec79a5 100644 --- a/drivers/iommu/omap-iommu.h +++ b/drivers/iommu/omap-iommu.h @@ -80,7 +80,7 @@ struct omap_iommu { u32 id; struct iommu_device iommu; - struct iommu_group *group; + bool has_iommu_driver; u8 pwrst; }; From patchwork Tue Jul 18 19:05:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318216 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 29226EB64DA for ; Wed, 19 Jul 2023 05:30:55 +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=5lMKBr7ti8SX1d/0dSJPN/gqHEdZs17gHOlul2QWdjA=; b=pMm/MFg46X+yL8 Xkrm25iV7XyK2AmzT72H8AiUn/gqFCbl/YevN+KaJnKDUbRKPao+xH8QQ0rKnXnkxaP2zMpAhwB5f kYcJl7ZllmJlUc1HFOydWwqqfE84wvtWLDpsoTvLjlcgrvhT46qzOIXYxX+SPTroIm8v1FW0/8rnw M7kHBMeanwpZf09ixYcmDU6bBC335JYA40jikPZCol3YhJbUtKnrZLPyCiUj9Ag2TglcMciM5Tdu2 ANNs78XyVnFRbQNXoUHg/tWKgYjijH6H54I8ctP63Ru+tusz7ONYkRKAX6rfoWxeLU+MrXw1QJ658 oAHcjInTuuvu9qvz0aDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qLzlu-005K2R-02; Wed, 19 Jul 2023 05:30:46 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLzlr-005K1e-2B; Wed, 19 Jul 2023 05:30:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=TnwYqHQtS893OX10weEJL48b3I9U2VW+JlRaCdx6dOk=; b=fEi9H1YSZt6CHoHwIuhiK1/+J6 Y2kvK/jV2Mjf21iyMyrKSVFO/mmt8vLmlEYAUOKzOTykWIgoYDLzIVkq1jPGrwuL+9HbaB16quLsb P4Ldt9y9l+jCahXf17k7xPtvl+WCABYBZWpzRbEslY6UPPXTno8tAafP0Q4Z2jqEtCO+3ulC+tI30 RbDwbOiQoZ+Cn2reUk/YBrM4pDEAMXdAMhNdne7zDXvMXvhDObmRzoAW5h3trG/xsjU3ZCh6D5GcL p9ovAfh1VAtk2EVBilFZRTC6eYEARRF/V3kAzXDRQVc/D6/Xql/t8OGZQn+tHKRRaPgpCggvksvI1 hIXOMZ6Q==; Received: from mail-dm6nam10on20619.outbound.protection.outlook.com ([2a01:111:f400:7e88::619] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq29-00Bvgi-2r; Tue, 18 Jul 2023 19:06:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jE7qBc+pZFTnpxQcCU/pzJitqL+1bvj89cc/ECqunQfhIVSmMd4QlEWuWvP0fUbMix3ynUaq/Cw0GkpA3ZSYRWfFWPJ78F4rCETEbI0ikjMGVvTFTCz5jEMg7DWqg9blgTaQ/3QBBaV8PHgeADBkXytA/6v+aK5n9Uyo6qXFjJvG4R9iOfuqjyFFKRRmzTcOu+MnLQyDuIGmOwIZcCDOEhIj4H/S8QHfxbzfk5LBDi+ohuGMjA8hMTWGr2aWVnSsvONvh7atZfuF/ujeiVIijfeTj0jSvsrJFKHEH0XOgpXSN/KEPGIFFB4yr3XpOsfpp1emlSWkJFC/VLDZQs+67A== 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=TnwYqHQtS893OX10weEJL48b3I9U2VW+JlRaCdx6dOk=; b=LaMGKjbqC01hprs1khKOL7upk9pl8+K6RNh6kn+DqjWdpVrabtXfG11pSA3h13CcFkvsKUSwK2WfkNHDqwRxjya4vc8OV4CgvQo7gNj8ioALW6B2NQY5wfuO3IVkwb4OrtOrCH1W5ht/yZsaoR4B3XYqODzAjZx7HXV2Oo/wlSPc8dHqhjG+WYgVbRCTCFjX80NL6ilm3Ax/SrAB/ym+1Pe2tKidKzAELXfRfZEjyqnw6mFb/5WTaJ4dvzGoYydgu5OrHD2Zm17uphUGD+r0JCtTREMhVjRAG5elHiQ+RuIWx9Z+xzBPr5fPJnmf1LVoxbW3OagXnnfoHD6XG3ec/A== 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=TnwYqHQtS893OX10weEJL48b3I9U2VW+JlRaCdx6dOk=; b=Zv3BZa7Xkn5LJIqF+1Qk8ERxCHaaVzA3DlGA3PBIUXgerp8f8ctOQ1A190+/e8pEvcaNXlZ0Isn0i+mY/OTMxAiQUFoeThZ26HKYkIPJYAjqPP6Uy01qUvwjNRmNEr0bqJwzLzMx56qhF6h3FF9FICYSyvmUqLuzLNmwx6Zqa96w79zxg4DXQ7ZBRqXYOuYiHZHgBnleubXrsNHyVCRYKTysAgcjfn8MWowp9n7qFxfEfC1GSdctAdFuMJPRnAR5A6PTVP4WcKCDuTiIftPTuZTsBj8Qd5JMIuBTHyc0+LRHl9S1QYnpCSJfmABxzqqg4esS/dRMGYpai/8aGaSUpw== 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 DS7PR12MB6264.namprd12.prod.outlook.com (2603:10b6:8:94::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:03 +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.6588.031; Tue, 18 Jul 2023 19:06:03 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 09/10] iommu: Complete the locking for dev->iommu_group Date: Tue, 18 Jul 2023 16:05:57 -0300 Message-ID: <9-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0117.namprd03.prod.outlook.com (2603:10b6:610:cd::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS7PR12MB6264:EE_ X-MS-Office365-Filtering-Correlation-Id: d3b9e5d0-6402-4a50-65c1-08db87c2074f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pD9oTZASGwKy+XBLE9NEQEN3yBsA+eTg0B/wAlEso30Qwbl276wABvwqMTJOidm/YsxtEcI5r0nOXyM/wMk6hyL+7b19AtwZhf8oaLd9lHo53aHM0Oip/122zzVE4Mb3yVBnfmrYsMNRwvIJv9U56XvgwT4mVQUPjmHegvpo/E7dVa0ar4scfu9Es5HiurTZe+R1o/vN+KWOgOjsL7jBki26vn+EkAojAVhCREloZEOYL7IKaYU3YRLF5tt6jduBgB6M/22Oshy2lG0angpL0jf0r3LbuVrYoSim2979QuT39BrVHyKtvZVGThr9u3lDyOozCH03sjyXITxzBtR37zFREF2hL98TMbGZ3LOgM4j8pYgvNUtR9d2ooX7TkObmk4BEvTYrY7/6DBLLbpFHuq/au0pcsLib6alVbZB20E4d6LTHO1gr1Ihk4h8xMD6LCXKBAgZK+WTj9UagpdW0rGYbbdhW/aEe3sZ9VT6mdpW89cScLPTYvPbML4ptkorJEj4VOxgiEIAty2VzIFIqfyBAZCg8nxfUECqgQNHjAuwkdur0NCeiSzwRvXLaW9iw8C4arGKHsD9AgJ8Py7LtIPXxZQn1eCcQ/0zZyp/hvMM+8t1mHw2/ndkDWB0PqMD9 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)(136003)(366004)(396003)(346002)(376002)(39860400002)(451199021)(6506007)(26005)(38100700002)(66946007)(110136005)(36756003)(66476007)(66556008)(7416002)(5660300002)(2906002)(316002)(41300700001)(4326008)(8676002)(8936002)(86362001)(6486002)(6666004)(478600001)(921005)(6512007)(2616005)(83380400001)(186003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kXvsD+HILAXmbaJ3s1pg/KdDBZ7myaefnles81JlYlAaeUyedSuMQH1+J1bSQB4V7PoWwQi+DJ5TXuK+6MsgB8IV5YVdWmC/JlXuccHZiM9UiX5kRPl7pkd78PAy7AHTdobKwpIxoez3TuLKUfH1KR2tlzO2/Gwi5Ec4EjWQfwLyIXkWQ/Iv+ljbSgaYzHSXKwmXxpP/N3WdA7DvR9yyMMqzlPHqg431mmmP00sXdoQImLPXk8KDhLIHtGrxCjY3ebH9uakrZC/qw3m3ZAlg+qREtlXKXm9g+M/yWF6K0KpFtBvqbf6Ty5YNBDVSA0MPqaV237eY1jIk2nM4CJoR9IqfD8FtEcwduDVuOh6NTiDWP6GXDUd9/BNq25UMs4J0TxqCy8LLarCoKiBNhksDJo1duJZU9lIQoYVLBy6oY8iH5OOttM9fWJ0p1Lk3vRuJkNm+ku/wqYU36N7CRWtlQdh2h95ERA2Ypgh2y17ENIEjuBujK3OexU07pU3bkA4hCkxhPkgiTm+rSVqVD5sPSqOGH33Sh56+24BjH1KW0pYXjDaglw6Ce/GcfkeWWdkUM+jZtsT2qSBAzTqyrT/cAxrQrNV0YhAYgmYgMsi2/357UyksOCntslKB8dKXVXEeTs9bUEgdu+adhLt8fLfdsQSwCQHrLzAWc7K4UUc6A9sSJX6dmVN0k+GM/MECMPCXkVekAU4KQwgGvw2tn0XXZ/MpxjgzlsAyLmETlEmlAo7CUqx/gX2VG+IzRm74wFHiMgBKV6IdGIsL3mmL+XYDrX5RDfH81M9L3Nhcmi+XCsZPRhDgdrnO4+ExaBfMk1o6rXjwKVw8fy+4/2C4P8l5ZgxCL0+u2SN7tGcmUR7R2tB4RjXNaZSvXqazHuCR4M7XOGwBZKjFhSB8yytHdOjDVDd1gwN1j2qdXhoWmx+5hxZE93MrOQcSO6TQ3y6SzkO0ItfesPp9WSRnWkxKKeTpu6CtnFCFhy2fhF/cISQwUelM/Ewt2XL88GzQ6Y/GDeghraWMc6WEi+W9OOSAHYMoUa5ISWSuxPjIFj6/OWGqQa8dKE5nhiZDMGHvelfhtJT9zkqmirEhpH2VSOjB/FjLC9pe8wpLl6t4BzGGgg++dhG2D3HSTPkiGFkYbJkKHN+TokZFMYToE9WnKVtjESQKs4Ao6jhAAb1KWDcc3eHi5bWwAQW9sBPVUwKyMjeKwU+mzLac6RKOXX/azOUohZ+5yiO29npSB/VaYA66LK4pfW8rgmr+QJI0toq2rlROnUphjN9MsWNq0qGbi0S7/a4lzDNnICYKiuu2TUDKjrnl58pKhOjhrktxICDm4m+tnF6aHY5OHfZ/uaQYAK9jqzisfFq5/wmB/wZqD8mvnO6q4dHoech0Md89+Nc4f4WeT8SHxPL4bTYOkOrS47BrN5F/HxbFpFEQgVuSN95frhH6L6IGHX0vKe0breINO/oUrWnyrOtSHTdRXkObebuREyyYyiK7Uw3A4I/4Y5Bs+OCvKXSPXe3uizu+WXdR9nMx6I2fw+mwIhX+tawvDIDTFAfEaYyOHZivCFnqlorlzowanne+k5VaGxf1Pm07dG95vSSD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3b9e5d0-6402-4a50-65c1-08db87c2074f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:02.0812 (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: ScNM6QsVh8gTMTY4e0TSWHU3qHLmqkAz4FgTvceTvPMuT+D3yKiGI217E6WxOlI4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6264 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200654_459966_3B449964 X-CRM114-Status: GOOD ( 27.34 ) 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 Revise the locking for dev->iommu_group so that it has three safe ways to access it: - It is read by a probe'd device driver. So long as a device driver is probed the dev->iommu_group will be guaranteed stable without further locking. - Read under the device_lock(), this primarily protects against parallel probe of the same device, and parallel probe/remove - Read/Write under the global dev_iommu_group_lock. This is used during probe time discovery of groups. Device drivers will scan unlocked portions of the device tree to locate an already existing group. These scans can access the dev->iommu_group under the global lock to single thread determining and installing the group. This ensures that groups are reliably formed. Narrow the scope of the global dev_iommu_group_lock to be only during the dev->iommu_group setup, and not for the entire probing. Prior patches removed the various races inherent to the probe process by consolidating all the work under the group->mutex. In this configuration it is fine if two devices race to the group_device step of a new iommu_group, the group->mutex locking will ensure the group_device and domain setup part remains properly ordered. Add the missing locking on the remove paths. For iommu_deinit_device() it is necessary to hold the dev_iommu_group_lock due to possible races during probe error unwind. Fully lock the iommu_group_add/remove_device() path so we can use lockdep assertions. Other than lockdep this is redundant, VFIO no-iommu doesn't use group clustering. For iommu_release_device() it is redundant, as we expect no external references to the struct device by this point, but it is harmless so add the missing lock to allow lockdep assertions to work. This resolves the remarks of the comment in __iommu_probe_device(). Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/iommu.c | 54 +++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 1e0c5d9a0370fb..0f75428be79d4d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -369,14 +369,17 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) if (ret) goto err_release; + mutex_lock(&dev_iommu_group_lock); group = ops->device_group(dev); if (WARN_ON_ONCE(group == NULL)) group = ERR_PTR(-EINVAL); if (IS_ERR(group)) { + mutex_unlock(&dev_iommu_group_lock); ret = PTR_ERR(group); goto err_unlink; } dev->iommu_group = group; + mutex_unlock(&dev_iommu_group_lock); dev->iommu->iommu_dev = iommu_dev; dev->iommu->max_pasids = dev_iommu_get_max_pasids(dev); @@ -434,7 +437,9 @@ static void iommu_deinit_device(struct device *dev) } /* Caller must put iommu_group */ + mutex_lock(&dev_iommu_group_lock); dev->iommu_group = NULL; + mutex_unlock(&dev_iommu_group_lock); module_put(ops->owner); dev_iommu_free(dev); } @@ -449,13 +454,11 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list if (!ops) return -ENODEV; /* - * Serialise to avoid races between IOMMU drivers registering in - * parallel and/or the "replay" calls from ACPI/OF code via client - * driver probe. Once the latter have been cleaned up we should - * probably be able to use device_lock() here to minimise the scope, - * but for now enforcing a simple global ordering is fine. + * Allow __iommu_probe_device() to be safely called in parallel, + * both dev->iommu_group and the initial setup of dev->iommu are + * protected this way. */ - mutex_lock(&dev_iommu_group_lock); + device_lock(dev); /* Device is probed already if in a group */ if (dev->iommu_group) { @@ -501,7 +504,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list list_add_tail(&group->entry, group_list); } mutex_unlock(&group->mutex); - mutex_unlock(&dev_iommu_group_lock); + device_unlock(dev); if (dev_is_pci(dev)) iommu_dma_set_pci_32bit_workaround(dev); @@ -516,8 +519,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list mutex_unlock(&group->mutex); iommu_group_put(group); out_unlock: - mutex_unlock(&dev_iommu_group_lock); - + device_unlock(dev); return ret; } @@ -566,6 +568,7 @@ static void __iommu_group_remove_device(struct device *dev) struct iommu_group *group = dev->iommu_group; struct group_device *device; + device_lock_assert(dev); mutex_lock(&group->mutex); for_each_group_device(group, device) { if (device->dev != dev) @@ -590,14 +593,23 @@ static void __iommu_group_remove_device(struct device *dev) static void iommu_release_device(struct device *dev) { - struct iommu_group *group = dev->iommu_group; + struct iommu_group *group; + /* + * This locking for dev->iommu_group is overkill when this is called + * from the BUS_NOTIFY_REMOVED_DEVICE, as we don't expect any other + * threads to have a reference to the device at that point. Keep it + * because this isn't a performance path and helps lockdep analysis. + */ + device_lock(dev); + group = dev->iommu_group; if (group) __iommu_group_remove_device(dev); /* Free any fwspec if no iommu_driver was ever attached */ if (dev->iommu) dev_iommu_free(dev); + device_unlock(dev); } static int __init iommu_set_def_domain_type(char *str) @@ -1080,6 +1092,8 @@ static struct group_device *iommu_group_alloc_device(struct iommu_group *group, int ret, i = 0; struct group_device *device; + device_lock_assert(dev); + device = kzalloc(sizeof(*device), GFP_KERNEL); if (!device) return ERR_PTR(-ENOMEM); @@ -1141,9 +1155,12 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) { struct group_device *gdev; + device_lock(dev); gdev = iommu_group_alloc_device(group, dev); - if (IS_ERR(gdev)) + if (IS_ERR(gdev)) { + device_unlock(dev); return PTR_ERR(gdev); + } iommu_group_ref_get(group); dev->iommu_group = group; @@ -1151,6 +1168,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) mutex_lock(&group->mutex); list_add_tail(&gdev->list, &group->devices); mutex_unlock(&group->mutex); + device_unlock(dev); return 0; } EXPORT_SYMBOL_GPL(iommu_group_add_device); @@ -1164,14 +1182,16 @@ EXPORT_SYMBOL_GPL(iommu_group_add_device); */ void iommu_group_remove_device(struct device *dev) { - struct iommu_group *group = dev->iommu_group; + struct iommu_group *group; - if (!group) - return; + device_lock(dev); + group = dev->iommu_group; + if (group) { + dev_info(dev, "Removing from iommu group %d\n", group->id); + __iommu_group_remove_device(dev); + } + device_unlock(dev); - dev_info(dev, "Removing from iommu group %d\n", group->id); - - __iommu_group_remove_device(dev); } EXPORT_SYMBOL_GPL(iommu_group_remove_device); From patchwork Tue Jul 18 19:05:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13318215 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 30F4EC001B0 for ; Wed, 19 Jul 2023 05:27: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=LiZA+R55sfZ5YEktU+7HuaqP2IFmjbCXzPy3e0jo6Lo=; b=oganYCGJC7/sWk KTzJr2AmJKztd4x1860NzoIxGzddzp7Bn/7mOcJ3Xu23/THjO418m/WOQb/kniTX7qq6Ol1vN5poU Al9HGTfFgyLyLAlGkT64gQBrzfOj4RUgppbytlg8q30AyVdXI7VOMTjXKIVPUw+vljCjIA/sqAAQo GYpXDhAZAAfLYu0ugIMe3QBrOScYwup4udAHasmi+p4/7a89AGJ8upXykan6pjviOcBlLdKr52lN7 YbT+7rwhzGJlavRRFU6Yjcq5ZaFeWdZqRDZS8WQ7ZiBmh8MMDo2wE4P/xyHLOkwHQ1Dy75/shGncD IeV2Yf6jRvNBwl4yxTyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qLzil-005Ixx-0l; Wed, 19 Jul 2023 05:27:31 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLzij-005IxH-2M; Wed, 19 Jul 2023 05:27:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=cE+UQONWAdRVQ3rLYcmUMjoa9bBXOMIEbkUImBMOc2I=; b=IDsHC9YqHxnGSckRUu3I1H0THS 41TncWbCS2azzDh6r93ZFZ3Se3Sa2NYkEDNpHysnPY0ayUPLO6tMG83q8RgaWX3L4gx7FQhQ04liz bUfY4x/L0qkBaiwBg9A2nL/PTPq1TDa82VkM2ZRsZXlf5SLDA7kzO2NjmobBSAiXhvef3nYfttLWs 5Vm67GeDs8qrZX+SBscOhAB0eRE+IpD1wq16Zx/TGT86aYfqqueYsPLwsGQnE47ahrl2ySYDvrWDz 1KGxdATFUXhsZFq3mueAs3zrL20hfZA/3YTu70DCR3uGYEogqZ9oc2/OYRDUEkMCQcwoFiOFEKCk2 5XP5jAkQ==; Received: from mail-mw2nam10on2060c.outbound.protection.outlook.com ([2a01:111:f400:7e89::60c] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLq29-00Bvgh-3D; Tue, 18 Jul 2023 19:06:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fsrG+F5afznIIuubP4ZMJKFkzpdpeXIym9QL6t5eWH7MFD4iMtyqKKmH4RDWhx/682gppXfolWk2cAXXEr18IiRGnR/CjzCR9OJZ+msRPVjR3ssLHApkLEN2DrG2l6fYOhBtNB0EtZXuFh2YFgicssQ8Xmf356Apoux58gV+NAD0n8SaG7JNSTJg1Lz/w+8i/2oiws10HtsolzrUthO+JgbvrsXrODz5Zk1ZcDhQhSZyvkGOyM7gpKKNgtEmhxKB96++nEi1DaKmo7WnXUmm+gTJc+ORdE/+xq6ceWLqvLxKyrB3BXbysYyq8WqhRdZjJq5yJPuUEE4p8wt2jpxu6g== 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=cE+UQONWAdRVQ3rLYcmUMjoa9bBXOMIEbkUImBMOc2I=; b=E4DFPKezYIRsSH08wHNeg+6zXGhP4yMKSypoezQs0u+hi2U4Qhp9LcSquIwrFpaLhYcaJvYjJVwYHbR22AJchxgKT2gXYVF9aQWGhbFt5OhN3qftF2E/LOwvrLcEaMXI+FgABNJDRuRDklv/JclDiHNxxwG30FIeOw3hOT0L6TH/QAQ7I49YeelXMIPlHpoh2yJxw9ZMb9iFmL4nQriC6Ufr7qtnXvH7dUuDrhSEWeycwbVat0prScqOgio0AeKEN6cG9nN3nDtNZ7su8fAy84/Nb9vOAM3Z00vt/SaY/2SZEyodlWIDoHqFuiOXcPPuJnD6Cyi0uK7xTkgz8Sxj6w== 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=cE+UQONWAdRVQ3rLYcmUMjoa9bBXOMIEbkUImBMOc2I=; b=Jqg7U8312aEjU3emr45IonNgXUBWzJyI498fLngZAxfAeHIykuk9KWpS03trDxCvC5F/+YJtxckyt7GYcyLq4RK710ObartEf/Ztudw8wqHNWKDHfw3YGaaEwdk43H8gopbNYjzefaVaFs+2Wkc5MA88pVezQHT1pk9lcVQpaGGqCraEOZdONbQbVtJ7yHcbS98LN0CuHs8na4vOMOUIh6H9aBbOZ+VmpgOKb/Ef3CEZ5DMJGB4eE5PmN92eudJSPgpW3Qy2lcRCQ9ZiBp9kJUCe6TrettRSoOYQfRT9Fw56zcBbSkmWIqCUccu1+PL7lPlqzTBn/cP4J22jjqawHQ== 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 LV3PR12MB9329.namprd12.prod.outlook.com (2603:10b6:408:21c::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Tue, 18 Jul 2023 19:06:00 +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.6588.031; Tue, 18 Jul 2023 19:06:00 +0000 From: Jason Gunthorpe To: Baolin Wang , Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Joerg Roedel , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Orson Zhai , Robin Murphy , Samuel Holland , Chen-Yu Tsai , Will Deacon , Chunyan Zhang Cc: Alex Williamson Subject: [PATCH 10/10] iommu/intel: Fix missing locking for show_device_domain_translation() Date: Tue, 18 Jul 2023 16:05:58 -0300 Message-ID: <10-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v1-3c8177327a47+256-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: CH0P220CA0020.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:ef::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_|LV3PR12MB9329:EE_ X-MS-Office365-Filtering-Correlation-Id: 6318ddf4-4dc9-4d1f-f696-08db87c2062e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1JKjP4e7z4HuMZj81Oejfx4565+SZsPAqc5+w2c2js7FCYcfC6xhDsfAB5X0XFSKUnCocefvSJPQqPxJdJpu9atNTq2UqLohDyEbN6LJvOPMTiEg6ibZO5vQ/J3wJJ5XSzHmBSz+PcrUlNuHDKGUdxXfPRtwZJcpGRVaVtYA7T7AYFsA7Ep+kcUz/Kb8vBl5EXQVXfmdUNDepO+Eb3uW+7PxoMcoC3ds9D1VdAboA8XTyNX+VajoYIqruQJbhaFLJmdyYmh1o/oq8g1S1knIaz0nzif9+tfubLZXuJr1fnnIoLsFFfL1GoZnfSSHGJg6ZDuEadXXpty8kXr8PIdX77SKV87av6p5seMlarIe1W/kXsqFOctqhDb6IBFEKPGLNdhgj1BdruQ7gd2lsnzUAw3pfHu591JP3JlUL/EXT89Tol4JYZ++a7v3X52knewod5VcgrcCuURxYquv6TpBWHFbuxSp37keOf9ba5XO+87bABvTjdwvd2BzHymOaRG9G9+8qxz2uDNc3hskHAqsXsektBajeuxA2WfQYl7RahLBa5tX1r7RJe5UROcE8vnso8PwchzJstE5CPP/KMB4s/iViyS2bj3QJGf1r50+GtA= 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)(39860400002)(346002)(376002)(396003)(136003)(366004)(451199021)(2906002)(110136005)(6512007)(38100700002)(921005)(2616005)(83380400001)(186003)(6506007)(26005)(5660300002)(86362001)(36756003)(8676002)(7416002)(4326008)(478600001)(6486002)(316002)(66946007)(8936002)(66476007)(41300700001)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UtFeln/cH2EW1zzArrxD67+3KOtCDSL41qtWNw+/acdxx6s//xigN8Y3DrQ/OpGCJyiwqvNyPb2E9fFEoa70PQ0nW7oi5q/ASABv4IUaYqdn3fEw4LQ0UEr3dXASUL8FFmLm2KJEXaJeZBjbBPDBmwnbNnKhQVfwMPLGB3QwRKVkLkV3oybWTFkA/A49iEAb5Yw2Urw+w0ksQMfYtVUso9rrcO4q2pzZPW3WqY88GDrjXa/xSsO8v8OhoDBaaV9O68HN6UoV9XDyo6TPrEVv1ZrNWMZ+Aj51PD3xOVIPb+0RomRsmgpOUN949kjRwftx+kk8VJKrdtrVyUrbh3PU58eyb9neaeABldMyp/X4cdQCFhZre22wna/jtZTaoII8NQlRgsR9+ow3F4GQZenECaAIPOLGlDx3c+vRoUjmw8WJxPWJ0Cd1Q6HRk0+nl+DAISo9+Zo1kBxIMxGB6nVL/FB0Q9PXJsYD3lR96PSfTn4vARk2L2QPdUMLUbAyvqH1nvsWcconyFgIiYbRT+X1y2umOMMQKeLFKHp/jVNCjX/ZGQtk/LMiwNSvw7HLZF8jDwVea6AUm3f1jNfC5bUnhlLXQy/XjAX5RH/qBc1dY8QTUwXKJZLXWPd2twpZ55/GizJIcc2v5nxtZHdM23Mnr2cW+ZGf3A6ZnrM3QDGThUzqfAgnNhk1zcnyE/1o6qnNjpVMMnmta2z1+qsbbbRZ4iLGJq88WNaTczR3j5yc3FjcM2h1c1l7pYr0pJRs/U/RSeRxbhc+p67T/jDAMHGA51U6ZGpkP42+558houo2LbtqTqJyXl22vqg1xLJ35x3D0mBYf2VqcE/PTsu4Tu0+2Y/xNM6RcZML1gk8BIyI75DKGXGxbTRl0U+zLYk5dcQXm3Bn4Q/ZZQn0WWP4GpYKgQkjAez5CYoW7nGu27eukswXXH2EDdZfTZPnvIuWyvMOlV5ErYbTFM81NU0X7t6fkaNRSij1V3MjXGUEUwdrwf71UgrMvJZIbwmCrSDWbeAClxS4hl+q0pG+YGbso26oOJjuSd7hYCuxlpLR3lh9fJ8zkPUgZtVfUVUW3t7lSrPNKmq9rdCsyJ1m5CpGMCMB+9sIG5vjifWXWgVooIYPjf1ngpBm05caBDoAuvOuDZoT8qtkhHVlEqWVzkpra5jIqryj2/1CGnDUvyEnEmtzzwbrNmBicS0AOF99dpG0V3vMq8ktAmnSe48pGSOygtQDfvnBBUyryDvln3iCPGGjWgRsELZhoLqrh9hj4CtCIER71z1XwVtgUsPTTTjM6JfhQyKChhe4ADgTTo/kXchIKn9RHBWHRYo/yGcUStCX+ajsTR9FX1CjmkAEixQ25AgYmnryhzadn5kpwBPGVA/ECIF4avqIjjOfkIiq0l46u02A1YnD6Rqv160wdwPJLyOP+MOeDQHIV9bUG1npSCadrzW0o4yIirxIzA5dJJLnLk24IgVRZZ9sTwtPUpzNg2jzkzUzn47sX6SW2PyUmOiB/PCR8zDejKCPjUKo9hiUopVebFZjZib0xJWm9cdqNEpvURUs2XCS7T7dUw/QHABDq+hLJ+Yl+sa09845Mjjzahzk X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6318ddf4-4dc9-4d1f-f696-08db87c2062e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2023 19:06:00.1467 (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: PedWjx6rJZ+0xpIV7Ogu71TLvzBfsy1uc8CNccL3duVJfPHOpVC4YNGUd2AHUuTE X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_200654_303159_706178F4 X-CRM114-Status: GOOD ( 14.33 ) 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 called from bus_for_each_dev() and must lock the device before calling iommu_group_get(). Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- drivers/iommu/intel/debugfs.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 1f925285104eee..0255c4a2326931 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -365,23 +365,25 @@ static int show_device_domain_translation(struct device *dev, void *data) { struct iommu_group *group; + device_lock(dev); group = iommu_group_get(dev); - if (group) { - /* - * The group->mutex is held across the callback, which will - * block calls to iommu_attach/detach_group/device. Hence, - * the domain of the device will not change during traversal. - * - * All devices in an iommu group share a single domain, hence - * we only dump the domain of the first device. Even though, - * this code still possibly races with the iommu_unmap() - * interface. This could be solved by RCU-freeing the page - * table pages in the iommu_unmap() path. - */ - iommu_group_for_each_dev(group, data, - __show_device_domain_translation); - iommu_group_put(group); - } + device_unlock(dev); + if (!group) + return 0; + + /* + * The group->mutex is held across the callback, which will + * block calls to iommu_attach/detach_group/device. Hence, + * the domain of the device will not change during traversal. + * + * All devices in an iommu group share a single domain, hence + * we only dump the domain of the first device. Even though, + * this code still possibly races with the iommu_unmap() + * interface. This could be solved by RCU-freeing the page + * table pages in the iommu_unmap() path. + */ + iommu_group_for_each_dev(group, data, __show_device_domain_translation); + iommu_group_put(group); return 0; }