From patchwork Tue Aug 22 16:15: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: 13361234 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 B2E08EE49AF for ; Tue, 22 Aug 2023 17:30:38 +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=Gkad/ANREJkZ9fu/qUbJOlNS9lyn1dsbO2iykSOE43Q=; b=EbmjcVzulqvJ5p sSaPKRdHLIR8KcNgBsVfTVTjCKtVWUeQ8E8W/9hZ/N6kkZOiSU2PkhwMVmXS/EjZ0azNVTwWjokGa DWIBy5npiZeEDHEjNu/WRafhqpDtxoWzkCGYDPXpFJoI99pWZok0Gpk+4TVqRyTM2Axm6BzXy9Fph 3OY/SLdSoVBcmsfyxjw5uu6Ta0cuE+IE/6VC5KzF6v+BVL+nosQen2Z4tg3F5OmMFGgBdryGX4QK5 VZIBdkckqjO+jX87C8H9W1QlbcBP65FKZs/9yCf7CAKK7D4LVO507YoxDfQqfH/Af7dJV2a5DEZIA ezeOi3W/zxBV8q881m/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYVD1-00GZmf-2h; Tue, 22 Aug 2023 17:30:27 +0000 Received: from mail-mw2nam12on20631.outbound.protection.outlook.com ([2a01:111:f400:fe5a::631] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3K-00GS2C-0V; Tue, 22 Aug 2023 16:16:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kEcm0vkiertNFWcuXh51pa7JfIBtAeJTOVmCxuMpJ+qwiEt+4TiheLYinydFn3wpQg4vDuRY8AG/FhQlfFYpz3vadWB1Cr5lVkfwt/tENhrSqIGvDyb1wx5fsCa/WTZKIvWyHj+iYJ8+bnpEusXVVryq6es3x18ZbXOX9fLbia6bWU6lXJF2AfW5jNrIkTzYq/g8u0NdqRL2WQuwLJqjXwo6hVvXM2oisMIhuE2LUWNnNh3SSM7W1MXWfm3qEIuf7QOc/jfvrK8FsjKNodelB+sis4hIR5TObhr6J76IDkBYo+GfAwxOd4Yr/mFgkbZZ1pQ9VfwDo7xYCdfyX37maA== 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=KSOg7xqDOO88Vnx209EahJSnqmdGE28hMiqI5PgO454=; b=WoL+Y3Txeu+nyd6hmtiogPh20C7kKPNuo4oAp2F6g0aDGFlswGsLCOendakxz5uQIZxc5DKt9AfSbu/YAK/ILrBV37RebqDiY2Hy4KGuSJjW6NpJtcl29yUA0lhMFnO3g1dT5I9bbV9TCsIOgGSIdvjMkv1zn9wx09Mor9/HsWW+Bpd5V/hc3mmINXPxOENqa5A90uOAeMtsUgU6y1VRf72e4q3AitoNqKGYt0uyQhT+thdBknwphv35hdy7U9X9U6QczVgZiISdWzE9fwzMcohJwKm0hB+QZ+zJSwrQvCLy1Xp/ten9M9QRwNOKZL9/f8H3IHTICGRXPqNkStmL7A== 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=KSOg7xqDOO88Vnx209EahJSnqmdGE28hMiqI5PgO454=; b=hp92YfIagmnc8LN38MVnREg2Aq3rqr719vUM2HlVVzdTDmSsh169oVYsvlrrIM9GwFd00IyiIWHxSFmpJ+x+pYXgwHLjDvnSGMQfmgwjKFtQFmMwgzuqzevSKRNDgt0QEzi/35i16PpqPAZQjejwLOOJhAzVy7h/bRdbJ4ko1mBdrDDFABWvuf4INYjxPy6ls7uJ6SK6mw0Zbn57radEF3pa3S3V3LsrkA0v77Mr4eY7gyDzKQAdOJSFkB7o+L6VsrgHw2PBDLtoP8LOHE0gmqv91GkB3QNYuh4wSpO/KJ6cc/Hs7arXchePxPHHoQk5t5a9pgF4eimw9FPP18ivJA== 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 PH7PR12MB5831.namprd12.prod.outlook.com (2603:10b6:510:1d6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Tue, 22 Aug 2023 16:16:05 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 16:16:05 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 1/7] iommu: Remove useless group refcounting Date: Tue, 22 Aug 2023 13:15:56 -0300 Message-ID: <1-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR17CA0012.namprd17.prod.outlook.com (2603:10b6:610:53::22) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB5831:EE_ X-MS-Office365-Filtering-Correlation-Id: 5aead877-dac3-460e-eb07-08dba32b153a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GvHdbCpvvJdLEga5ntaYaBWkvQg8LGRCdhbsczKgbKFzfpfm6oXl+t5HbAFQhNNs6L9m9bjGtsADLnZfnCiPY5WXqdVUB1H3oXywHLCQvA2S93pgTrAZkDdFCaf1w5hD4X4mzmxz0LZwXyrSLF80bFFJcJ0ROql2hAcg6SHYmnAi30ZpMVpahtu7kwZ3MwqZvNWbzlRLmf9Yc/3vvsDufDVkf2FbgPuuk4etYsVP8Kli9rPKtMGXeH+1lDnp1VJNE1hTJDKZ1ZShLcWtvwUS3DYY0UftG7yXEt50bW4fW+Vz4PRPTNnfjr0MHtqja1cHUNOFMqpHvTstXhqs0eCEaFnU1BZfJgcYWKf/GzPp7Br//Uhtjp6sTBvg9G+rDDl9GgHV9PTw+IDasaInTDKOScMBPmRp4/OuxOqL/UXPum/siKwfzW+mAEUT1yMP1IDaQzflqq3QIvdKgZ4dMwz01oW9tNLB8mhzZWk5Cwj0tTBoZRElQTJsai8aWK6FDlXrIfyEpQclTQc80VezNEFacjut2/jB0/u9Ls67DG397HuzRE9EoPef8V7+VTXhX2E5SkCJNM3GHpNfsF8zlprX4NJ5qxoONT4bhYdxS/4k6F8KjTFdG5h73WgM+1usR0e2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(451199024)(1800799009)(186009)(2906002)(7416002)(38100700002)(6506007)(6486002)(83380400001)(5660300002)(26005)(86362001)(8676002)(2616005)(8936002)(4326008)(66946007)(6512007)(54906003)(66556008)(66476007)(110136005)(498600001)(921005)(6666004)(36756003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: L3LK/cBYLPyMTgKQzyl0OjPIxBXS4v9/LaLPGxlQqvCL7DJtghtebS1e3nHcfAhymrI8d53kD6xBDhRMkM2RDvJZL4JlSeabheZo6iJgw+2WQzX9m7YJXouvgR2HPCncXz7bE82BbtmyvMVma9c9oO46Ed7aNFUEbKOnJx8FTwudgITpbXOpGHyzQfT+n5wjVbr/BxHQLBNTN/fF4aUs58RbEWWY81KpeLFSa1lMVqBtlO1jVxET6Odp5SMyNfShH0Gvav+UbyJ6au9IsQ5SjjIJNfaHHYBW5fzJsgQlzYo9Lkt2ADcv8Rxs4ilKJQ0wsu7IDvdoBseq+sH5tWG0tW9zYqHGiujaMQGFMsHlnX0yPDnqet/620QRvmbHnzWdgAnqHZwZDibngJnJQcwY+/sDZSiA8ZVgGuGHo3dbC1DaCpD36CrHb1HcJ5GxLD8tP+lTj9IXL/Nq6yuYUECcQeV8tyKjhzMSuFBF1/920lEONFJLv2encP4c16prz+q8dXf4qVr5vpR1roS7uFJKH7hG/EvBbFVA+LxKnoYxZ4JIFCOQrStC3vPQ8HbP6KNlG57p7IUjh0VP5uzmMJ8eZck69vaX50HR97/G/kdQO61YMcwPeHMqToAmoDSzeS2DScm4XPnKgW0HGbQYw+ImL6S8A462kCHgAZl19B2hdgJDyMvhYK95fdej9ztPTuCMnkr4PRfbPPGc27dbHhaTIVE+qDE/asbngZ1hlT+clI8MIiai6w5BUD1zkGUTdNYG2yeCv1aLo5+XMVZfP2FqJpZrvcvR8SzZ1BHvTwpe9LLuzvvTyWIAhzNAUW7qmZZT5gwCFrjFfzQ6Na60ZAzZ+sYss9bTa6pef8B3tjS0X4VIe+OQEvI+OF7YBDd7+rF8EQvH3qhzy6h7ZV5uCFesGv3ANnGIDfdhHCv1nI5ofb16Jv2CM4YZUSI91vlQE989VWWzbAPabM9NOOBFV59bXOE4Hn91J4/aZ/uNH/2oJqbBLLCRxbonV4+NeTZcINE42BGHcX6JstoQCqKz/rSJ4f3LlswKXNZlZal7VgngAu88fKEBIOduOCl37I5nbYkP0K2C89GTgFuPsb8M3F5PDOw1QnRYz34sTUkDH34h7iYrVURzvTsvYmo7MSXy0z3lqody85o4SZGZtyOkqaB0SgX7U/HEGk7szfaQSpkkzAhmNb5pMS+XK5I5CVioy2HmUnW6HkIjeyVUwk0M0WaHjQz+twfCPJCBdnb2WxKVBlzp3eBUHMdmzepo/vD1jolNgMmaDaxKa9o4zkiNlDPLTDd24cfNAhil/g1aeL5/VwFOn7YCIOFenhscKFtT+Ra+IGwBmtcR8VviNrEXTRq3CnzjnO6qE+BKDRg5I/KtOg/fRYJFyRLxk5re0nSkCRyhsXbAum18m+x0NF1+KJd3foA6oKllbm9ohhrZLauFq3F/Qqv1GBbHYQzgK2eg7BmMK0sxo0sih4khS10//s72bxAylmJk/Bxq+gUgjq1VSW8zdjozefjnj5p3rXVHp3RNFNfs4KBvFr3rHsRrSDt+gJDQM0UUsJPip+t2pxG1Lj01FqLq+JvMlQDOi0h17EZT X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5aead877-dac3-460e-eb07-08dba32b153a X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:04.0227 (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: mXoBl782wAeSFFlw1qjrWP+nY55rktTiuMpLGGyL2pWw+iw+f3pOlue7mY1Uds/T X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5831 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_091622_238412_CDEBA809 X-CRM114-Status: GOOD ( 17.29 ) 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. Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- 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 39601fbfd0e0ca..50afc55eaca8e6 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2017,10 +2017,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; @@ -2037,8 +2037,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); @@ -2053,9 +2051,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; @@ -2067,24 +2065,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); @@ -3062,7 +3054,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 is the driver core during the pre-probe path */ + struct iommu_group *group = dev->iommu_group; int ret = 0; if (!group) @@ -3081,8 +3074,6 @@ int iommu_device_use_default_domain(struct device *dev) unlock_out: mutex_unlock(&group->mutex); - iommu_group_put(group); - return ret; } @@ -3096,7 +3087,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 is the driver core during the post-probe path */ + struct iommu_group *group = dev->iommu_group; if (!group) return; @@ -3106,7 +3098,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) @@ -3193,13 +3184,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; @@ -3216,8 +3207,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); @@ -3255,7 +3244,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) @@ -3263,7 +3253,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); @@ -3324,14 +3313,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; @@ -3349,8 +3338,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); @@ -3367,14 +3354,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); @@ -3396,10 +3382,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; @@ -3408,7 +3394,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 Aug 22 16:15: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: 13361129 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 70AE0EE49AE for ; Tue, 22 Aug 2023 16:16:43 +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=dQFrGnV5Z53zLj2MFKLkzPYhBpRTGkH8B/rn+Lc44JE=; b=wVrzLY4IK5soOg Iccb+0DpPDwvONH8ikWEF/OIavbhzt9TsvKs+HV5bbRsuHEdac7z6MAF0Xd3vK8YaPpK5fvPP2pjj 8YwgZS/wra95FoEHdmeTLgncrd1miCB4fPiY1qOUTaIypXKypBLgicuGIbT6CQAnu3Jz/WE3cp7DG cyzasNDMITrNCtZXILoBVgAaHuaJf7ypAZPc8mchgfrjsIPDQ79qgtI5Hbn5IhLl6t2IwYlYghZm3 CZKvS5Dtm2ibRvnVI9WtbMJAqCsiIpbyQHT4U8ckgTavduTevZvb7Go2fyL6FAYf4aKhkk4KEKP6Y 3FZx4fjahYoj/FxNX8Lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3S-00GSCW-0P; Tue, 22 Aug 2023 16:16:30 +0000 Received: from mail-mw2nam12on20631.outbound.protection.outlook.com ([2a01:111:f400:fe5a::631] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3I-00GS2C-0M; Tue, 22 Aug 2023 16:16:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZLUSAvEdYsI1aahuk+uiByU0HihX03I9XKlzLCWLJknKEpiHDM+nvbEIVt+PpJbxxPEqirFW1PpztstqqntcFaFYhOTqHB0igycFGxDuupCPCcBlgckBFfBJ4GVWhpTke5vypBbF38CC2bBe91SCv4IB+seV6zDN+QKU2jz4J5yjJ5M4XCsgMKdE59OcUAoYlJzmY9x9po0IHH03CxA2iAmNTCuO3Rb6ZeE8b4CQOcU6Hp020CZ0o2R9x2cybD7DoeROzj4GR1iKDocuLZ7WdvRPbRlCfpK+C8IlLwoEi0Tuvs8R7/MHWxSQTUP7gXR04JOvJXVi659FQgDxccg+xA== 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=r/EiohERC4PV6mQAz7QZADKo/0C4MxnhQ3V5u2NLOno=; b=CHpb3zzBqJrOynDu3gsWUaDOASGHuVdb+PeE22IQsUW7uyLr7KZ89LLcPa/Ch+V0p4NLtg1X7vvqaKFC7DvpEl5I1QCjiZqtt1Cr5Y+dZKfUn3KxlLmgGGSWV39rhiCagDoOUM0IMXtiPBdoRNGVFA7DvXndQZaOtpq4giuh1bML02OSb6U73aRT5FL35LYhMd8lzXsBOU67w9I0U5gVTFLPXGb+nU1GgwaFSZ0cEKoqi7WNSklP3EU6/XBRsErDj3f1PVJMQ3o5uLymYpgc3WZvejerc1byVI9Pty6SMQCS3dTcnNyCpBexckifnVhDcnGa9qW85zJQx40UO3o0tw== 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=r/EiohERC4PV6mQAz7QZADKo/0C4MxnhQ3V5u2NLOno=; b=I9L4ZHoUk3OTwM0YWpyniB7DEJZUE2s2MTQu+Hypz05oMmbg0rjyFpu+kUuls8DfoDAuZXjUuGootbWa+98GgUKPZNOgK2yi8KDgt/fGYZYYE0qFdERqzh9OtScpZzHNM8v+00pCnZ4Gd5zkCENgeyT11UB98rm/ywvEiXUbzpOw9jAkipKq5ZjYG7+yh360JvUkIHdP2GIJsAWk7o6875jEKL7lJvALvaCmxwMkFJDx3piozxGQEEAO8S1b+T+9gyZYWKSjGipcDMyq85kjsoq+oUxCHqgD3o3JLvPyEdf9ms4QyiShZ9JBjNzzq/CJEOx/Jq2B2/4LmyxJmV1JtA== 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 PH7PR12MB5831.namprd12.prod.outlook.com (2603:10b6:510:1d6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Tue, 22 Aug 2023 16:16:05 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 16:16:05 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 2/7] iommu: Add generic_single_device_group() Date: Tue, 22 Aug 2023 13:15:57 -0300 Message-ID: <2-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR17CA0021.namprd17.prod.outlook.com (2603:10b6:610:53::31) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB5831:EE_ X-MS-Office365-Filtering-Correlation-Id: a4f04f2d-77a0-4c09-ac85-08dba32b155e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gda+1Ljnor2ziEY154vx3O3vKxR7hj7MGA+lWCwWxH+XWRn59R8WzDG1JoLjWU8qGJSUsn/1nQ26HRRHwmTtQzMrnHMgG0PoGIhBDxGauFCvvwBk2Y4N3ApXo6ktgWZ8N2KOjgh6SQmWvljfTgBNwpbHp7H55gtYRIVYXvuDPLlnMSidFFgWdxLBFvFig+E3nR16/He+/Eqc6uAF80XX0OAC1dA+tg3+HgIt6kZhUyaUP9oMTiDhG6QXdnWmXrmJkKMr8enIdX8Ax7t5Y5vs9H98UdzVtAdRxmScoqydmLpYNqpKAINLCc7CfgTjLcOOkZAtlT4jaTvBdcUb199BIbwiDdZ5lt4EbtrdjD83eQlK+wL3G9KxL6kRTtjXEnTWRTvYYIiHNcfCVdrQ/EQgFu6/XWV/100FZKBo5pXKbLhKcsintD2QScCbQbZ18Zpra0Y3hqX/8kzUas3Qxul/vBhkV4De/frhwl5I5j7BSesTVq3lifmaqSORZTaCRTqzccqhGSK24Rt4yL2g0DqvSQ7k+cj7zK2m5vbqGi6HfLDJjTBzg+Wan8F33HEQB7X0YYeP9QJhCKFS5Ul0ytZOJXNq/1LtytffBS34DVEGPkOK3GJu1FIvmrfPNs3nt+5+MsoSiho545soD6HP1re6Rg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(451199024)(1800799009)(186009)(2906002)(7416002)(38100700002)(6506007)(6486002)(83380400001)(5660300002)(26005)(86362001)(8676002)(2616005)(8936002)(4326008)(66946007)(6512007)(54906003)(66556008)(66476007)(110136005)(498600001)(921005)(6666004)(36756003)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Sukzy1eSpfHy5j5DmZrQnHX0c9R/Qs/pycuvZmGQZ/u+s+djd5zXRTxuSaVf0fF13nwxSBcBXLLCfhrAIjjJT1dI7GrRAhuofEMzKNrQ71G5kVCx6a5oZLm/eTbKm4kBZ8p6npiIm6dVdlvmdGQYlaqmPioONITvFkBLuyVfDxgFv6tmQffUWQeh8lFyp3EfCcSmZbzZTYiz3ENxET3QcJDKzfn+WCxIhYKqoWbflI+Bye4kgkbznibQtjGneJxdLWkdThGb1pmwVU/+ek8oA/ffrUuKp6HfW+w/oPLzKH4FiwR3zoYElffA94dJjDc2uNh033Ox029pKBmrdfLUc7A/8NU9AhG+yMSlK+GmH47FCHLv5EcVhIim8bykCD01byfTVjwBcCWsg8eZvGjHgvRABO7H0FhmG0rd9YhDJ/wWgaY1GzCWuwEdLz5ZBuMFjM06CfJaHBbkKwk+RQRupymbwjVgzKJ8o6LEZi2VzRtcRkk+49vu2V9ckDwNhWl4PV7xxyPl5cHlLRrrHo/28a5hqfanFkJBpY6FpS5iKD+d36igE8cEHwJVpMNRJ0Rk01HlTgoQjZTsi+LoDkaG5zXkAUSr+iVKotIjg/CQOvZy0ATNVi3OAhPhwVHPd9gxIWyT8gXHqjNJTTA2AmfTlogta0rk7Spr8S865xpulkwCP4PA/1VQy0qcEWIp78ZSw3LKhxZzPMWkWQq0o1sAV51u7Y6Ml425y7Un3oIVG6cYM9OFwr+tW5G0P+X1dECxJ8CPENutFs0ck4dMeOLi+UWgZ+3KuxWTc6Vx+CJ7gjBovj7MqPVpjT3cSgtpWJBWCez3jpNSf9JvyzkNrntqy2STU2q4sSGmI5a7ag3dfLN3m+dW2hLsaMK2U5pyg6slb5E+Sl4sHa+aPwUCWuo/dQaDrhFNSqVth7IUIvwRBCOHG3TZ1Ta+NcIrZth0A1Cz24Pxiqiyyj90kTFtfwfaxygwgFFY2sz71/BdqlPm9ZR5ICQn3ZXC76g5Gk6AgEC6oA3GvhBG4smvmwbvC//Q0jU8MFRjY+svtQok5HVPHLPfMi2WQGCMzua3uQV5u4ALrU7E7suTY6z/DSJXTdX/9Np9CGv6S8qbD1ETaehDLWiIlFUaaXnv7nxQGPWHP3zmJL6wcQQuNoRhNrRaBKYkfDmx3DkNqfFafd3iJuz2UH2ah80+AUeKoASiYWVClJMqSOmGJoqT+5cxZ/hL4CjSeDDG3sqXxMcF5yG4F/R012rbr6DS9HIRxuKv8Bnyq8FAI09liHrx2LmR1OUOf8dvtgdKyIryPqkFX1RwL1eYZM7IkUeNwsIx+JwIQ3TpssJGgsrr9sH9f5GZuo2XVu/ceYdxPodhEFrNlcXyy6v47xJC69/4wVbPk0T2a9COchpRdWfXNq+CqGRseZ7eQFr2jM730fmJKhfjv/ERO40FFXwtvfVhkGN8r55jUzCQtrMngkk8zxXw1r72GdTNr3vnWXB1/O67mOGARaSLA0GY6nlZ0tgbR2VMkcPGfxGoM8qlD5w/HWsjuSKUf9AkZWB7KXjP/Sp1nq2SLIjWzFfp/6x/h9uzPeTXpUE/GmccWWqG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4f04f2d-77a0-4c09-ac85-08dba32b155e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:04.1898 (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: bW4Q4gQdCCL5stCpSZitijV2v3SKhIRhN8jKXSEbgpql/uqzJ9fXkqElHcdHApQ1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5831 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_091620_173776_1FF89AD8 X-CRM114-Status: GOOD ( 16.72 ) 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 instance. Implement this in core code so the drivers that want this can select it from their ops. Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 28 +++++++++++++++++++++++++++- include/linux/iommu.h | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 50afc55eaca8e6..3d6bb2537e8d85 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -288,6 +288,10 @@ 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); + iommu->singleton_group = NULL; } EXPORT_SYMBOL_GPL(iommu_device_unregister); @@ -360,6 +364,7 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) ret = PTR_ERR(iommu_dev); goto err_module_put; } + dev->iommu->iommu_dev = iommu_dev; ret = iommu_device_link(iommu_dev, dev); if (ret) @@ -374,7 +379,6 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) } dev->iommu_group = group; - dev->iommu->iommu_dev = iommu_dev; dev->iommu->max_pasids = dev_iommu_get_max_pasids(dev); if (ops->is_attach_deferred) dev->iommu->attach_deferred = ops->is_attach_deferred(dev); @@ -388,6 +392,7 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) err_module_put: module_put(ops->owner); err_free: + dev->iommu->iommu_dev = NULL; dev_iommu_free(dev); return ret; } @@ -1591,6 +1596,27 @@ 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 instance shared by every device + * probed by that iommu driver. + */ +struct iommu_group *generic_single_device_group(struct device *dev) +{ + struct iommu_device *iommu = dev->iommu->iommu_dev; + + 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 389fffc0b3a2df..9ed139bf111f6d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -363,6 +363,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 { @@ -370,6 +371,7 @@ struct iommu_device { const struct iommu_ops *ops; struct fwnode_handle *fwnode; struct device *dev; + struct iommu_group *singleton_group; u32 max_pasids; }; @@ -644,6 +646,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 Aug 22 16:15: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: 13361130 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 BEA23EE49A3 for ; Tue, 22 Aug 2023 16:16:59 +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=qvKJTYlKUP/6Pf KeUwLCjNdoUFtEg9I38aw2RNdaeRVJp6F34wgCpIl6xjmmmHw0TUBLEF75hIisORaEiFj/QsNbV5j 3aGdO1N5SgVlBbukwKkIOt2+Irnn+AHflYYFb+UuS6J1i0JbwJkb6+hsiiozYlznazN2CBI7J8Xif UpBSL3ykS0u6Ym+LSnI4Asghn9mPVUEBDGRnP8oIwPy42Ow7MNsYRB4Zk3pr80Bxgl19vkHyJsDj+ 9f2GaMkuG3gj9geMiQXD+hHc1e58llaJxeg7Yk4MiFAsUTEZZOFjM+mKQ1uPOWeoz/1Y8PR4PQ2xT d0jdGKToD/x9FchH+ikw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3o-00GSVs-18; Tue, 22 Aug 2023 16:16:52 +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 1qYU3Z-00GSIq-34; Tue, 22 Aug 2023 16:16:38 +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=SyFqDbS1zXZwszrGyQ0ZO2JyvB FFn8jxXIAv6h9YIMhUYGhLPdfWrqVEOQMWXcEnO8nMwvM4nrhqBnbQ/9U0WQFATci2+dxo7a1WZwz GAn9bdHYZBOkU7x5B7wOTpjUfVoj9X/wLahv6JGKnIri2LzozpMeYDRpTCG6J4KhpPnEN37m2A1mu XOiHJEJ/AgLlRcbWrt4LeMd+vXHFMhz0WwExcXIHsO3UW5EBYDmrW3opNNP1hh77s19g3Q3Jk8pk3 Gs7Q70/8QeKBMcsJR/NaRqQn5smppbJAqS/GSVDjrOZ46q6yt+OtqMGzGRU9iGKBDfvNucD6CyhsW eQht9vGA==; Received: from mail-mw2nam12on2060d.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60d] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3V-002rm8-33; Tue, 22 Aug 2023 16:16:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lc221BsAWrElIWOL/K96cJF+db/94R0bFoHBFmVSY61liav2J5XpqMYY8548budEGD2oQv76F1vEb7ghAE+Vb21T/wRLPn75jfh5W8ocyt3Pkxb9jQChFlZkiA0p2zX9mOOSbjS424Z5QNNfwMAiqDuY1Z2BQhS5zkL1Ot1D72P1PTeygNwbIYJJxr3Vq8JVxbgOkTWlviAPurzt/nnMFmUS/xJKdpXSDGvcGUOd7dmME1ecE9V2CYcH2XbBRGqyuBh2HTW/HfKoXATD2iRYecJoRgtWlOejQhQDmIb6XJMR7BHTmaxwnxwlEZvd6l3w/ET9tV+OnI21mSx/I4pKjw== 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=U6X8z79dF1yEo/+5COidMMxZfEgWR6yZvIknQTGanr65JaWhB/iMd+uwRtgP4HSL4ie/cxksPmiJIzk6FOVq7r232t/k1yP2YnMFdKbm43ZnNHx5xtlkOTTqvd8byZhIcKVm4D209/I4WtPMzOBAHmmby7DQnFajm12s9PXOw8g2iXh2xBCk9iBVqDSmPyr+Iyls2XwGHtpUfI0Jix/GHQWE+j/yLHjVkjQWU4VreidHoNkbTPx9qgzlKVaxPGPXDmdwlNADXzGAYCoWyFmyDatKUSrUWcN1Gwm92vBPOnYsNL1nlcIbn5HBy3+pKLEMvHaj2+qOz4TZbS5zKfEpag== 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=rK2Plpca5CFIL2IWkiClO5JRYE+hPAznABwbZHPV8dyHvYoHxzaVHQv+TWPGCHZt5T5eCIaGWrX8e4TEGa8Ag+rwpqVfUG6Nha7hZpSmfhBobDy6Rwno3ukv+5565KcBPs29bejV12l6IbsYU44wtFdzfGyAXRvu0nXhpdn/5dpGrruo7dnY2lVHCrOaKLX0v7cuF/v4Ce6OjgDHisOw32s9WjdSGS08ZGf5jhqboAN5rrZiNe+3Y2SAAEnwa+zwlQP+hSSGR4NBQZFz4r8QOI4IDooh0u2H7w/O+PbovlQOLVQj1omCASyEXD6tsUafx8e92pRgTIPn1Q9FILmH8Q== 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 PH7PR12MB5831.namprd12.prod.outlook.com (2603:10b6:510:1d6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Tue, 22 Aug 2023 16:16:04 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 16:16:04 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 3/7] iommu/sun50i: Convert to generic_single_device_group() Date: Tue, 22 Aug 2023 13:15:58 -0300 Message-ID: <3-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR05CA0008.namprd05.prod.outlook.com (2603:10b6:610::21) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB5831:EE_ X-MS-Office365-Filtering-Correlation-Id: 91b037d4-9d1d-4e61-0598-08dba32b14f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hSrItAsfCkYynEWChNBqw45UZjYHeelZCNcmr1pKCW9iIS25ekl/lV/EbBQbIz/9T3xs3/djO3cEqBbGrTL8zRho1KGMYTCPATXB7i5cwTQsHWKcoDk/GXPq3gO06XivdixygBQ7m4YR2MqeudTvU9vyLKyZ3Kr2BHAYSABYQ+94KHivsHG+0NiYgxJ5v4rvHOasNebwGvgfbEamuqoO8dZKcXKp/qOD1oMdkiqV5zJicmWRXoM/56NhB5lEH/TgFd9dUt5/tmGwGg9YfVncI4xgab1PQrgk5e6936nDaPjTsilbyyBuPUrZtsVBW1+KcKAHyfeJay3Ppt5ZtvM6WYIajZA6TpKZxEWf3w6bcGDO+Md9HYmRllk9nfYGSx34/rgbmFWZ48NndPDw89417HfQYqCXo+6j2LZ0IVYWGKkudLPGB+PSW2cWt1D/mJWw91WwpIKUfr7YdfzvbW55DsbL57Hv0r//l05t2ZHBZeqY3OwRg7rtQ2HDBwPJTxWB1rKJIuB553sdL8bvuMA71H9J8l57GEZEitYTOFMqAyvI3pq3vPCnpWAeh3Cs0p2PS8OqGDhFwVU8eJblpGBDgGlb7XOYLO6nDAPhZBB9wD1ZwL1q84VFEQATfEZ8IVansI0XIUnFK/A6MC37/6O4sw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(451199024)(1800799009)(186009)(2906002)(7416002)(38100700002)(6506007)(6486002)(83380400001)(5660300002)(26005)(86362001)(8676002)(2616005)(8936002)(4326008)(66946007)(6512007)(54906003)(66556008)(66476007)(110136005)(498600001)(921005)(6666004)(36756003)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B7nlTSZfsSAXKxFu+4p0t4iweSklqeCuMHa/z8SpB5cw3Kx6Fq7N+ryeNqh1cl8ZxaC+nsQFyFg4I3U17/f5n1VWkqZfWMgtzy0oYd52p8dxtHuADUf1NaaOEW+yT4jzyXzUut0QbAK96oAMxRn7RKGJqhN8c2p4f/Ud4pVaRUnREsteApQFzoqWFBFtOVUKUJuACgRRSq/W++dkFaYGoN/Bl8fzO9AJbGUmx5QUH08XhIGfh59CEFHqgXrN3gCffFsEd6nZjYkWUGarpHkHeSV1x/AcUUNHDXbyOU6niy3FWBU2P7BlfYAjiSmIlpnqxI4/Wlbnr6GlQStXiLrE7Ih6gy5IQ21XIPB1MdIRMp7NJsX3sjX2iGfMOlr75+xkIx6a7zromtMy4uirzyPgMZGxTM0cxya9YnAWkq1/+Q4eEbGGZ09LJBZSL1rMfDOnU6JZJv7U+Fz6jJL9SuhtfutV9zU0BLg1RqTNsTFmzNVVXqpxe713VA4PjXyZ79cFWHQF4WU5lVNzEfhoZPQWPixVpyTeoKL7o4ZnVJpU6vmGs4r78Zn/egU5XnlVJ+3our9wS38tyuc89wDgjIu2nTWljxuTLFHjEF/cJZrzfreMyLpC1m97qzIhMiemJ3uvEC75tsDsUxLjQXejC/gNnalaFQeS9OlIgOIROIsy5CXK7hB922/h77Owua3TTrt2F1dLQIwjbtPnP3x0qjBj81BwpJEmWTxGDh6Q9G8wYPco37g5NO/QMYgvoiqyB0eL/H3lI1iXk6IlNxuyiySOLUBNDho/KOI9VGHTZ5hCT6s5x64Xo6qfHmS0K5P3jyuv45L9ehfEBcmy8oOBqIng8/G5jmX2zojLoUhFjyTsEQfInC60rReRzheMkcBpYFiUkFkAjaUR33CF2GQmopVfG07tIQdDkbb8VhGVJomx41aifAByXixxu/3tZ7VBbNlg4LvwcIXfAml+dSeDcxoe//0TQVKVj3PGCO5pP1Q1giQv+xLWKFaCeH9M3SQBxlFSlqzzPE8/CeezZ70likAwEo9g1P8AcVLHHYcIdZSwgxIZz5U+oXSMIJ5npOwiZrhuVcBKExDWKwD4cSMWgz7lSB4nJUXqhtjaMikzQor/mwCzrHrq3WpyQzcrcklFMs/GZ+iR7tWKR23fujXqqdrSAj+3B4gYV35+MXNDTssAts47kg/Sp8fAhWxZ9pp3D9Qnx27DvtJJ4eKBXZejtMF3iA4GgxyJ772DqWvTenjuPAWE93rRq4hUtJ1hLTusRW9XOqow9/inz1cDcHjVvVaQwKzIXHR+PftmABQA3K9DUlg2uopTytgJxCAmGJ6yYLkjFKAJnaRN1b8dK71c316K2Q3lNSKtapB4/Fw48gmdfEHdOuXaGCyR2cY+dpikHIiODMLXuxKhm/in8pw4H9v0TKGtwJaDMncWNx817IItyfY9n87XmtWpclh7zHRLnOavnObl0PEf0ywYL5rt8nc7hY4pwPAtqbx8e7c85BH/IKxcIZAiHD1ZsE/b+eDRFxs43IYxHj/+8CQG9oejZjpW7h5AOMRr0b7Phwf4XHKI63ELM4DfHAlNn+qYz/AK/w+l X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91b037d4-9d1d-4e61-0598-08dba32b14f1 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:03.5471 (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: f5N6oW9i7rwmSgMvCQerg/cjcNPZ8WwAp2lfpYcu0BAWP+iGcn/bbokAUslmGYMy X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5831 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_171634_161896_B1B0857D X-CRM114-Status: GOOD ( 12.29 ) 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 Acked-by: Jernej Skrabec --- 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 Aug 22 16:15:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13361131 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 52E2BEE4993 for ; Tue, 22 Aug 2023 16:17:07 +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=4OH+szvqQzj1ueO35hD5Pm1a3IAxHrdeBRsV68osFKM=; b=t3YL5qYVpetyOf 6ks3l96FBNJYcct/yItDyPjqsCaqYviIRBXpzhNe0CtpJmaD6lN+piOXHsewLJ7rPNmynFWQ+hjFg Byw7hEReM2EX4hywESA88jSEDqZ+ry7taqjjb5Mwy9O/n+k5AQOLlPOUL3Wea1pIuHHlZLCaAyxe4 pUQLbXLP2Kyf6Ay4KwiJrudtvo9ceaYX5R6QWoebmMWXMFqNxnHjLc5QJzQH5WY2lR96X4m+O9OFk jWTKqsZgNQ8rDXWj0OzSpvZc/k1e3MQNSXS4zAg5dNtWpsRrvfKC1g/Ak0zWSBTGCsPs4sx4U47A7 8z8PSLGH59h/RHa9YWnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3w-00GSdc-2k; Tue, 22 Aug 2023 16:17:00 +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 1qYU3d-00GSM8-2h; Tue, 22 Aug 2023 16:16:41 +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=fCojKI/W5M3s3vHbMVLtKa/z4qtT7egQpecWd6L2jls=; b=gZU3LEnzqH7Te26KeYFWqvs/Mm DE0vpWKn5RCtQwYFrFOIOB/rugYzcRD20q5aW2ebuadiFy4yqsVLe/qBk8SLKlZdvGx3Xh4bckYeB QinZ18IQT1m7fa85rKG2g+NFZqYvNnI/bp4IJwQHOkjaR1e2vCkuhdq5m3fNDNUGHhePGHYf8hBxu 38p2Pd2WOKk1nHnHKn7fxApjf6V13Vt8ONNLfINJExTUB5Peh0AewXM5mZC/AXdJBZHUbjKZsznCn QZEpc4EJpJ4YthuzKliNAnZoRLTO+a9jYtSS6qXTu32B1NrFof7ovFYSY5p7NaCYCk58Y6c5Pr/W2 2pJzNPSw==; Received: from mail-mw2nam12on2060d.outbound.protection.outlook.com ([2a01:111:f400:fe5a::60d] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3Z-002rm8-10; Tue, 22 Aug 2023 16:16:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NXAY6x0lHGpQ3qk71UWA7In7OsC1KL94YtT2dqERIC5yigFMk7Y7CfmzCmFm5u2CXKvdDC1GLX4p72AuGWn70DXquBprVVSYd0i6Rs4oxO3KglJKXVKWpfHXf1NG0T44lGMIO0T+zHAvp+RAiQ7i/HKXudISh/EH+6bloLePjQTqlMsWP5h8OoZjlmeyfV9aE6aqpfixLY6qyAz189DnLeBGgrfaoPwNi4k0+aDdmHW6cMj2p0UvfyYhwKF4hlCsHK2opnLFQaAYB4JSLSNHIlRgfBaD/QQwSIlG3nTVWje6PCLEitpruq24MWQiUs8DjL2qII/3/N4qaeR+5ZScTw== 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=fCojKI/W5M3s3vHbMVLtKa/z4qtT7egQpecWd6L2jls=; b=RmTWfZVHzA8YLabfk7ajLAIKPIs2I1H0MElEvrmJl4RKEMWaAp3TrTN6hQHyxAO7Mm67u4BTdR06EqTiiUwgCEL1jJ6Yxi0D/sp5btkDVESV86KN2EM8z6qahN93okDlLtRn5PLsRclxhc7E1oKLozzYIYncgUDamjb7TA0HbwYxoAlq8Rm3ZS3yGvw4fZKVwpBfppCsaX0YIkOKUUhLvMxu6d2KSJs7Sri1wDa07UZ2TQKp/Q7MncS0MyKzjNttbHXwyFp8HL9iQHgCLYj3BfSNeZVKNvdrqbfnvrCb/Wv1KbzRnWUMKnKBtA7eEQEqogn8wyQU5FiVq7/ThlyfOA== 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=fCojKI/W5M3s3vHbMVLtKa/z4qtT7egQpecWd6L2jls=; b=gJcJlkI1CmhWLfT7t89syWJqT2hqeNaYVyd0gvHKfjm3eIjMzCpaenbScGinWU3oZvcnV08vJqcAOqdak8WbSy6gd0a3McOYtLv+HZvenZUrQj1d2IJAgheYprspm3rtMq5q2CUInzmpg8XZDkU4R+eo+btIhkxHu8EHY5nMcPAQeAkB67YyFUQShfOu998pw6naM0XRwnPHvxbiN5SwxfrTpGBUl9o8OFWzY0N87yTgsdZ/uybQHcbalwoiGkyLwPdyeHmHGh4YLbsap6txEJ6l86VJsr2SZRzmYW2R4JRpJ45yZwzbtddixLVOjEV4eRsZljzHDbH7ZzAyR3BwjA== 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 PH7PR12MB5831.namprd12.prod.outlook.com (2603:10b6:510:1d6::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Tue, 22 Aug 2023 16:16:04 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 16:16:04 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 4/7] iommu/sprd: Convert to generic_single_device_group() Date: Tue, 22 Aug 2023 13:15:59 -0300 Message-ID: <4-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR19CA0024.namprd19.prod.outlook.com (2603:10b6:610:4d::34) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH7PR12MB5831:EE_ X-MS-Office365-Filtering-Correlation-Id: 029c95ca-c903-4198-0598-08dba32b14f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MEu6L+7IC1DLMGdiAeUmapuuVT7Yb6AXAyHwF4IrMHl95F4AXyRORN3nEWJus2Hzb+iVs2ew3adZUkRVMyq4lMTrlgEp41nUqz+oA00Qq+IzFj6I/xAXYGBrAkfBtnxVcRiGhn9NT/kuPM8uFx3LDtAzdyi2xnp5YyEYS+zr5GWNxpAWt+A/zxSP1wK4M2M923WSre+RBTkVk1Ky9kJoMJzx7W5gkgntaw1zP/jZa9RDgy6IjURHY/gU4XZLlg9KAQNO5yu+OKs24z/febrplSx+PRqSXJMgE9bmNlUvX78HzBPQN9mfqSYem2ZClDebGVJ5mkdWYHU1mH5Lv4dtH9/U3517kecpxWPBif0cMSxfscl4jKmrGsoFxPFXLCmEo3NpG5cegpeIqwYu5Nf4Ly2rqcA8H4XudUOKRp3fQ2anVo6yZElhl46d2MSRm4v6UN7NyVWqk9mXp6hIzLAdbtFtMxFXf4uDNNZ7fsqukjsQKG3u7gE0dxu3Z2TqbKfa3+27IjFprnFBcT38TfJmWooC3SCBzErCJS38bgh3etfTdWUuRld9Da6QV/h/DluvkKuNRjckvXmFCyZzMb8gmID8aGopZxgppShh3qBO5Q8pivy32EyFnAWCWZVGCc8HVBOaCWp+WuOVLV1qm+jyVA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(451199024)(1800799009)(186009)(2906002)(7416002)(38100700002)(6506007)(6486002)(83380400001)(5660300002)(26005)(86362001)(8676002)(2616005)(8936002)(4326008)(66946007)(6512007)(54906003)(66556008)(66476007)(110136005)(498600001)(921005)(6666004)(36756003)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IzkrZ2XqVKvD5x3MkLFvik7uZ8Yy1ub7PWDNDaufdT1cLe8zrSP+qnWt1FN9v/TuwpQA+00msWDLbPFco8mym8WXgtlf3LAqlgoOgMpMS5jAU4U+EddKcoKr4ZYvrz5v+6MJUXuNhatAyedcxBgmZ8kl4Bi+VKqOxePzJGNmA8jq9MLhb9y8GXCt3reIrec6MpifPjQGY0QncBfTKEkJtiFqZWO+bUcVGrqpqcVlo/JXlWq/odeDC+sR2wH5Xz1ymR1b/wJneu0VR0X4EL4dbNk9yi3iXCPsS4cFvNO/aJL4aO6MAGU9w0Q9ABNNtHIpLTfJLMsCHxsYyz374NGLdWRiVuE6vVmCTzvp44RHIHLQivYj0sU9jkgUFDbOJVpSypTTU2ampsoPeAAQzCaerZ2A8cuyyTTIkTqUQAlDj9MljiDQOmEyd4GJclLflZx2MXwHubj5V59erJ9w9EEi8SK6BTXN4bRkDjtmjjYvhqVxe+mqa09jHBzVB2aqI9fYe9v3zwoquW1LqNCPay6CSrgOW9EMf9sMKeVNv+uoBKTdLSQGG49Cbh/ALNovxlchVCpnrTe8bmVKY8WPs5QBeJSGI/Kngf7N5u9XIyBI0SqfagKMepXNSN5t4IP8kDvDEoA7Y6Kfm5OdVcx7QrTbZe5LOyaQ+MYqCuhmAkqOUSVp+g1Tp93ygJDBv8q2F1rJ5iWb3lMuxUsXkEuZrw2W7d4zpDxx+79bl+BLf2VLuKzs8J6BwsB+4agZRA7jjMp3LNUcwrvtNefXqNZhqjzxAxFBIgkWTS5uY58jNYwwHf8zdcYFrGmF0A/XdCoW5Kx1oU6MBhVmeqf5q3Q12eoaE1k73An419mhpSqjEmKIIBSpnhReIBDmt/xBMMQT5uYJp6tC3QMTzX1tX7CTXqxae/WK6fIpOI7Spb20bJHaqbzrS2coUY5XVKdVOsfIkBnUJcFfkHDojVK5vSBg5rtJsAXDCeKB4RnvkQHUBhoIiXUgHYaHu0JrAkwJ7p7krKQOtUTLjR2rjyoex4Dy5ZGC1LAa7u7ZIkf1sOn0fUT26VU+tGEupvKrlMVzjNWBkildsFRI8QZTT0MUl0I0JF2jNhzhbsKoF4fQxAQXJ6MVgYYkZWSBt33270erzLFnyeiOLk+W73vwMD9fDLqOglgSWFN45whOcXTSG20/eMm0o70L2GkTCuWcKbHVtNryaLBgKhKxI7O7kBIKVCRMfVFXajQ0NxSETHwyr1lbv3owPqdUgkxmvthiHP4cxwGO/W7B2+Y9HXr+OZNxNS70VzHxMUxIALTBNCnAn4Fum6gfpWYctGT60WVk42pXrbQMpoXrxjG+7GrHZDe8OJNLivj6TsKVec1+KcCzaCWuSxQtaZxBXY6gubPsumWgdjmjjmjSbV+vyGV1WBKD1JSvuJ1fXwdG01cKtH+42lXRhI5jlAtXBbZR6yq4Udgtug35CBkOJhu+drZEJtzoh1YiO1I8yu30p6PiXaI0ySK8WALHevKyhm7MfMIy+fAuNnqGdNJhMItmB5wEhb04yPPpVJltp6uWTu/oLbkcZYwysMlOQWc8BY5bPnlcCkHd1fUi2DNe X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 029c95ca-c903-4198-0598-08dba32b14f1 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:03.5739 (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: igYYTj+D1uAd61rPRjJyjCJibVmC7e2iwo6Q2cbhytH1FKe4USytkbhFHfd6Xgfi X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5831 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_171637_463347_34CB490D X-CRM114-Status: GOOD ( 13.16 ) 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 2fa9afebd4f5f0..1ca22368649884 100644 --- a/drivers/iommu/sprd-iommu.c +++ b/drivers/iommu/sprd-iommu.c @@ -70,7 +70,6 @@ struct sprd_iommu_device { void __iomem *base; struct device *dev; struct iommu_device iommu; - struct iommu_group *group; struct clk *eb; }; @@ -399,13 +398,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; @@ -423,7 +415,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, @@ -496,16 +488,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) @@ -530,8 +515,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; @@ -543,9 +526,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 Aug 22 16:16:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13361128 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 12832EE4993 for ; Tue, 22 Aug 2023 16:16:36 +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=4xii8HxqQaNovW 7Y1EZJHe4PSBocxcelSULEHQXUn6EjMr4h+6IwC+CVfLcAdpMl7s3wmkx7/6uEh3W7cDjGJ0OWj2B WqqbjdBGHfQApHrf6rYlavO41eNSvo54+b70cULGCjrbhq8cW9jbjsZ8siAcQIZ+xxsbR7Dc7uGTA jIVNh1zGL2Z0+rHD/ycoS4MEz3/p25xPD7lF+OO/e6vpHuEQ3dc6oPRAytyuDcNGTngA+8BfCSR+j QRH8c9BM0iszo7s3Rvnvkct4lnFtIkLM3EZike6qSS3K1KTcNGorD20B9zpEvkxvaBYXVAf2dW1r+ EvhoB1WG9owO5q4YQXEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3M-00GS7o-0s; Tue, 22 Aug 2023 16:16:24 +0000 Received: from mail-bn8nam12on2061b.outbound.protection.outlook.com ([2a01:111:f400:fe5b::61b] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3E-00GRyc-2B; Tue, 22 Aug 2023 16:16:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d9H1sNYcP/AKNhKXwQl+Z7u5oit8VPW42vCXWPnIZIu2c6wb6RFeJUww+LkpwXzjorAhr1qc8vpggkJOUftw2UOIZgkJLNL4ZlmcSr+MsW5Dmm+9eGmyGhufrAcwq+iXclHfMTBVBhVZvpWvuVM74/xDGX7k3MRNtxko8NZdlyUVBAYZBCGZiGSKmWA1MIFusEfs1NLvOpEPCRR8iaiv9N08HyZffDrRaJpUXp/wt8n1OAduZwAWgNKL/yeyvRBnWiWkbDfJAb9Mm7XDUDEUiHOjoTTbcorvWnBXhjYg8H5a/45FTWlqqGxzI49doudLBBD5U0/K+TeZKHsQbmZApQ== 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=AiDIQYH6GI60yPzzPMn54mrp15O4GEb9EBoY7kp5V8EexlsceM8YRmZ1J3aNxHu0QceugkZcqry6BMvasXKZ9zD2HYM2qTFD8lm2HlFnBR65VYzsCRR6em2eSScaUmUyJnAfTORylq+alHlt/GJc3IVyOfLXe7BPt465Lk8oVOTkluapcg7U6R7OyT5F8X+xnEp3aWdj1+vbFJLTg6lIHKMMcqf8gHQKD/PPhG8UPml+heJoFYbCdl+8SiozOauEvLp061lFqsDxq95gHZGc4FrHP7yUdiCY2N4W/8Y3srzs2Xbz1UPOr7Ny3Rxo3mgdAibt/UgP0HUKN3oL7D0O7A== 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=FBozIvRHPNSCk1f7+fpNYevrJJ/cwWeRjLAZ8Bvh3vM7COXDbDviZI53lyu+oNgDLwVMmP675tTXWVM1SIfpp2Yc/WJHGdvblrK7vKzSgjDPCTBT2W7yWCYNw5nhTxM07eoTscF0KE4d1SxAMXuQahcwFvWv+U15v+XQ0CGeuZoevN6AB6vQpZyVxgqMG0Kg49mzk0nrGan+8vPKiqHDyHXdVmRsiN67aXkMdeibEh+oov0oKIDFAGf5gZS0f5KI/Il7B7u32DffMI6HV+zJ1UjD8in+vTPXvhUUS9kM9zpvQ9ei9nz12oezrJ2sEXGiPbyEIy5FHwXhbs5HgWqj7A== 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.6699.25; Tue, 22 Aug 2023 16:16:06 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 16:16:06 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 5/7] iommu/rockchip: Convert to generic_single_device_group() Date: Tue, 22 Aug 2023 13:16:00 -0300 Message-ID: <5-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR17CA0014.namprd17.prod.outlook.com (2603:10b6:610:53::24) 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: 2b4a6b75-ace7-429f-cda7-08dba32b1670 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AJ1+CA/2tsmP4qEhyNXcopRkv51VwsQrejA7dmtTf5enhIfSv5x6to8NLb0uetJRYhM/mjhjaQrA0WSP5WZTE5jQh8Q+pRnEoNUhU/Gd3PkIoPZ3pB8TMVmwqX1gqJrmWjuj0ypA7Z0mnqprnM4ENRL5mG1E711mQtcFHzMBjnCJBqOqOD8zegTtN82+WP7oemc7amJDE+vmDbVhbDU4RisJpO3231AH3eLBbvdNit9eNAFQudCqDw0F16iEyclGCcAkV9UkYxAXTN6pPEYoIXELXTGlMzo7yrLx56c7h1Rkh0mqXByWz4nkp+lGBlVOErVRa9sqYl4Dl3G/44yFvVlkq/dKWsEIuEWZC86hBlUDVp+kT/4tIKF2d0xdj3ea9skUn2vI8LCODFQZNG42pJo4b7IrX9/SRR58/hO2oB4KP5a74gUWsa8NK8IS7MToxT85YytIYsEaN5c/M85yPm27O/brTdiQ2LLDROFQ3/Ofz9U9VhjFb2HAiQvZnAocqMIuPd74XLYrNroULAUhFcJKm9ql6/yLfJZoTJU564JBrztsdU9kJcCahPjxxPujwksRKxR6cmr7qhHsioCMaoOWzENVws6LdLNyhF/0Jpncv3JlxofRc9wvrMf4n/iioWoCUkNGsU75g+/JZI0V6g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(136003)(39860400002)(376002)(366004)(451199024)(1800799009)(186009)(83380400001)(478600001)(921005)(26005)(6506007)(6486002)(2616005)(6512007)(6666004)(86362001)(5660300002)(4326008)(2906002)(7416002)(66556008)(38100700002)(110136005)(316002)(54906003)(66476007)(41300700001)(8676002)(8936002)(36756003)(66946007)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OSXUxCje1rDULGSL9SjICK7UPgfxBP8ULtlNggFlvW/jkv1gz4XrBepSA6sIm1aMLOHMA9pEnkqE2Hj7rMTCdhtRRr1iWsS3r9c30Bhw2JJFJirnk3YPJ8HID7pxSvPA9UEuhu3FTmK6BvfMyWylSw+XVw0uxxLoJRKvowK8ol1UTm7AqwXqy+wuQK/IMPRrKH9hAK+RIWjTkg1NJer/Mnx20HsVGbH9Y/FnCNv9W7A4iYE3dioroB84h1jqGbAWAXQuVAMJ6ZSIcd9wGkmXGkazC1hy6uUNxghIg+eISskLCfwAQrCW+eHzPmrVGL9u4CJokx8ynpe+8hYCwfY3QS41UJKVsn0AgHzzaGDw8T6nWsWjaXJUmfJM4nqMW2d15rL6TbDRNS88zKtUYy7P/XjnPRJxSEl7xlHsxh9PC/fp5ZDKIO3wV2dGz+J6rqbxO3JVC/gtFFxoO7x3LeT3qizqfK148CRKGLNanY+fu4VHs5cMCn5102qFWb5nKmw69zcI1oNUoSKL5u3GEYCIG1+JW871HppcJRvTL8aCn6aMidjRzdKiLPEyN8gO+EmqHdDaubZwUVgxlFD8BoCBc/tMJ5bLwKm60vCChsrJEe/si17GEa8UR2gEvvFbTxDnT3xeZbM8mYl5OyUyKMoeMKOWBVwSx6q/Gla/wfp7/teViKqaIeunYK5ZUQwhlKASUUEvr946AfFqEAVIUpMCvL+VuieugXZYZLuuo3DeHyrxdsO6C7Kg0VNz6Hv0+qCvOMG9w1IDUHMTFld9fyDGRpwE9SSbOfBCFwxtvUpdGESMQnrthLvp8QFqlnyO7U5YnvFcbynDOUGLqnWxN0ypNN0GIsmUkG5l0m41cDu+znTYC0pdzbLqoDwiZZKgCHy7v50qptsTVZnfx1FbIGPvxL7znTzJum8Lginufio8J0+zsmtqLTY/ELgdVqo62GNRMgXDtwtLC2DvJGGk1wG5q4kP5K12OmiD+OdKosL5ZkbmPwm9BdhI3r1/ceuyFoIlhoET8nkq6IZE+hMEtQ21wMK6h91FVc1qk0U8cgsci2NDju2x9eUXcVTxCuaR7nhFdXgO6A6+d0CpfwYe86lHA2utLQNAxirYD+2J5fwcmalHietdKSVu1EMGdIbcua8G10lVKhmX1Nw7anpf5tBOz6VJujU3iBS7VT9cJU5/iwlOUtBEV8OrQqDdJNw822rlyKlyP+uMi00iyr9UlvcjfXEAvtFoWx+/xwkwOtzvMcugm2MeTbqBhkicnvVEgHDdjBZARGbgydCOHPB0mUFXOTIQKwtJMpt7xUmYT3TsqMOPb63HhUJqJ8Ye5t1mx2WEoVGhd1+cZs3MERBAr1CvaAHvKGIwQMCPgNyaybf4EWvy3NTWhSE2uJnnTLS3fyJGaYOIifnrgVIqy1UBTQlxSr6/O6aI2E2w4mYatRqeWaKKjdr+3Tb+b3JJCOTTLNOqgF1FroDu5D75h46OLMZkYYvGvUd9KDSt2EHmEDW5Yh/mJmggjn8/NKI9mXZNU/cad6nZcoXB2L8zmS5eOcJmVsgyrSRKHzTL4aN6g9HI2/mioz+aWc45BiA2GUz2lmdP X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b4a6b75-ace7-429f-cda7-08dba32b1670 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:05.9970 (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: /gXXYyWnwvXMR6SJ8giS3TK7QvpPaIL7gz00eNTL1tBGnGFXeYtsEcjx7v3njwNv X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_091616_770004_A26320D8 X-CRM114-Status: GOOD ( 13.38 ) 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 Aug 22 16:16:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13361127 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 65590EE49AF for ; Tue, 22 Aug 2023 16:16:33 +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=XxwVADLYuZvSmq3QApOGAyie7Bg8ZN8RnQO+XcPlDUQ=; b=ox8z+Pey0ijAFj S5HINwL9dTzs8q8kPQkfS6qR1ERRzup3wHt9fHYc6zJRMewTLXw0Co0wcpbVG917re24BTE8VCEVn 2AITjlTpHAPkNpmaPdHO/rYDcXfz/U7Y7Nu6ey9K9lbp0MIdq0Jo389xUtA+e2DArjalm+ctn0vzW bbDQrvBfapPACRRNMxA5L7F4CxJXso0lGW+MQqC4qe2o7rbBM7UNYUPcwwloLEFNCmVA6EBzFeOl+ r2eMkxTYo5tgK79tOp94H+gajCJMEHX+dkQgoEj31Db/jp3jnVnuMzTC91VPgTS9veJ42aoeLgyo4 MIdKXoLYyzRwsIp8NU+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3P-00GSA9-17; Tue, 22 Aug 2023 16:16:27 +0000 Received: from mail-bn8nam12on2061b.outbound.protection.outlook.com ([2a01:111:f400:fe5b::61b] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3G-00GRyc-2V; Tue, 22 Aug 2023 16:16:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Abd1IjIhS3A/dWBtpjHYZOAXjnF7jr2TjKGAgFA7xGOWzOVtcsLyJy3NuS4gfApEkblclnhwew/KReF2xc6Ip//0Bk5cnewXbzssMRr2C68voOoxA3QUHmnAejzZIi3SbeUEjbaSfKIEttMpAxXk8yYxdFyDcwc7vXDMGPQmBauYCAnqn9oEzMUzqUTYF6WfEfj0ZMT6p6l50gi+4PLT+7QENRMzoPFAb6S0s4dJUU65BsXS0qPB6aqJyrjGi5iJXKdReXVg6JIyXhw6kR/od5zpspDcj8Cju51yNPke6recYyR5ka8NCxG8CuVfopVC/3a7C28OuTslmwtbp3YoZQ== 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=77p/W8bYfwoAsp4qOGyBgAVJvbIeahNz5F/HKfJdg/E=; b=bJIrVFWVeuAelnrywGTHjHz0ZlJ51SNCsQHTk53mNUWXOzC3tyfJCiF/nfAAA1mTQ29I5rbiZbVQGpSupbyJQZ3n9AG0TR5hTfldARtfM3oRy1MSqpVJr0AJGvHHkana2Nj32/eebtsfjgKHzc6BjYL83WFh9BUhLHYuAua3qRDHIj0mcvW7UDC3lcCvNCyPoowr2wKn9u/873VsRNusmfs8Gu8/z60UDB45t/PpDtxniHHAEb7TEzJ8AQATPc3bUDF5ZgKKoPYNNUIWekXKtw82uv57jPdMy4NvTNcfdFwWdgax1DbcvDcsSyENOk8xSZFLk0DfOzJufzdn+2HQLg== 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=77p/W8bYfwoAsp4qOGyBgAVJvbIeahNz5F/HKfJdg/E=; b=swjEgnDUdUjoqWsOLHyqHfChLS3oNidQCK4QshHtuC2PtUz63d0ZlwSnjrB5NrIQlnlprhVAY7qVEr7NMy+aCCH5JCGPFEFnCsD+0Yma0D2pm5dyhRMRoptXjSyxea/j5bcRyeLidY7OPglVD71muCOd1EP7zXypXJz668gvRnd8fS0T0rkB1ndMmgJfbbsa3Z+zPMADjxWUZjvb2BIPINQT1sWnLce8d36ab0SrfaRexZaIZPZlD1TXArofqZKWm7QWra98KXNakM7IdPf14S+iotWlJPHR0/SGUFBfPM/BXhpIJjVTQZMSHqTdG7rvA/RqmAeEMxeKXrqok7wKnw== 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.6699.25; Tue, 22 Aug 2023 16:16:06 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6699.020; Tue, 22 Aug 2023 16:16:06 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 6/7] iommu/ipmmu-vmsa: Convert to generic_single_device_group() Date: Tue, 22 Aug 2023 13:16:01 -0300 Message-ID: <6-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR19CA0006.namprd19.prod.outlook.com (2603:10b6:610:4d::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: 47fdc0ce-31bd-4d5b-44bb-08dba32b1667 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NFHsBcJni5M4XJHRWapxsjGb2bpDZMtO3EQrKgxyR4kd+L9njSwGyytuj9Gkkwvve9h6k4DbjW5gDAiDwACM3l/jQ0NQWRh6GQ9xBI/X6GFZVcoDt+fvTrByCZN3sl/HTkMTZ/C4u4ku2+4ZYXXq5UtJXVu4ov57o3MbFpRtWzesHd9lgwKM461yM7+AX6o6Ia2J9j4XExnYHKAIDJJITwgOC3MCzXQJE4RA/LP29BLxxYdO7U5jc43nrWKFZqlpMovxvxdz11f4PQr0d+NX/pa4sP8LHxeSt9rLWFCszCqWPcXz31YbFzeYSjNDjBy9yD/7BWBJxq3iV/7WbAVHhXr5sxlf/oKUshIVqbPjxDmICqyyMcQ+eAx7JSWKW2mkpBCKeGsM25FtRAPhMrtetZGFYYDfaBEFzRVVduS/pBOuk6fMbgbBec7OPT8hjkaAHv6gO9ndz9lF+DfD+NKQl2IIPXDt8TYetlOXkh+3KYhXPipue4+nbpIV2kkqLny605BICZMC6KY5/gZfVFyrgb697w6WDL+gms1s1ApAEE5VUBHR2ROGBzOIFlLDCL1XCTy/mLa2o3SdEfXV1oWeFerX8m6a5i/6UH/0e3WTDa9Wk+LjIVnhlUa2edFYUis5qmkmVEVlD+qLyaTDsCk4iA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(396003)(136003)(39860400002)(376002)(366004)(451199024)(1800799009)(186009)(83380400001)(478600001)(921005)(26005)(6506007)(6486002)(2616005)(6512007)(6666004)(86362001)(5660300002)(4326008)(2906002)(7416002)(66556008)(38100700002)(110136005)(316002)(54906003)(66476007)(41300700001)(8676002)(8936002)(36756003)(66946007)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RgQ3f074og1kwpguZvvvx5AiBw2TIDCNoDxBlBZT9F8GYmsT+9UYtaV2iOBs3DsySrVZbpj8h/CQN96duY+sH1KmaWMEbo930fEZGMv+kx3GQSp6fQnDvjM4ph3SY6HrAVZCKAjmZoeRYIzJ3SZzaFLMkTqn+hpjeKfFrepYLKPXChw1bJChzRrdISpzeiA+9qHI/+jtKNB9eoZSaX4mMnmc/HqQ8DPlKvTqy8Si9Vijw8CQ1qqGa17Ko/kKcg63YyQn3dYJIAanEzo0Y+xRm1Vei3Vl8DHSUrcF6OWQ0JtokstdgeuG0xxYLaJi2I43GX9Gf/mqM7pMvDlGy2a2ZsJDt2RagzvhonzjPWChzATHq7IGloOGwcVqafuNd08EQYTRLvyb9ZXo+1ddwknemPGWdR1V6GjRsetIdC5bPoh4BXk15SWPgFkME1Fw2cBDA0aCGvozwqZYJYU15ORZzEfSR6a1znYi+L7JAVB8328Ov87+esttb1kowoe9IQSVcyRxP8BUYJZVd2Kg2VIbJTqRYmZaLJVnFezsFcQkP8oBO7wf4TNfK96Lf6Y+sBiwz/4oJJNz+vNaKuXpT6UisZh0D5TR/T/pgIfiB9qBHhyj8rWD83/QrLntcXbPdekg6WlEkHDIeRyWyzHvSTa3RIBQ5yw5xKh+YUqEUppVic6hI8b4TD65yMlai5wbbsClsC9tzS2BzygAD5c+f3HkR2Qn3V2iQpkd5CpalYxaGZ7B4xhJaheKPhfmpZ9j5iClq03P/89ROx/izoMXm81haE7QHHu4pxmoNkfJ0sfQXWx+arai5167QvjzAwQPUFNETSRYJl1qWrdaKiyfNzSAaPqm1TgImWvNQJUS/si3fOru4yLSXC3NUDF5mM2JrfDkotql4vSlMN6GCO3bKCD2K2Reb51xoHGeaEnyCttuocVUnfjYXdwgPP2z2T07QtGZPcNqRoh5w1xi3DgT/RB9WCXn2h9UN2/gl1o7zbs9ar7XDkXRBr7yDbcQnPWIKbJj8ih25F78vGn8m9Lf2+sGCFZ7g3g98iUKyDk66eHN3fUybQYKLSJp/LNfk6uyuUZyhAQLSM7mOt7taXtfGa0BBi8Ta2j2mxHLNFCsY0yJlJUc+MiUEFAtnEW/R8ov77sUaaLaEDaRrk5WFBDmrfikyl77uUUIuX40LPNVvIkAqce5rDxZHJf3d8L9vJxoa4yKr1Fenn4M0Z1DhgeLu+SrEW3pApg5+s/gqYg8Qb1rTdNX73gcezvhs4lB15w3EBR/KAATll2CpQ6UtB+votWaLqnOSphBLnL9Z4pCfvPKuHzsbvmCpW/E7chCFNJj1lHbhi5DU4I6T5YFHBI5Jvuhqhe5K+vC6askI0IheEcILKcLMXk+xm9VMGpXvD4HN71nFgQ4xpmnOsuuAXihtOQUFvlioZ/on6dr3e8XCrFDl+feDjjSUVvMlwJWtHmWoJOEm6xP2XvaEkppyVE7tCxRetJxCUSJQM6IlqG86m0BLQmWIo9RvSiktL4BzVVk6F0rrnx7zNMaNNIkM9y8nSXN2izDSLTKw5s2sRfjpbFQI/VpTe4b57wq+AdK+QQtiF2V X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47fdc0ce-31bd-4d5b-44bb-08dba32b1667 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:05.9358 (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: DKrGtzxjfS4xOzlwYGkdkwgtFz8Z2ydouakVgnVrReppsUOyt3gQya0qLflBP6Gm X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9329 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_091618_852316_0F629630 X-CRM114-Status: GOOD ( 11.69 ) 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 65ff69477c43e4..8e198776ccff80 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -64,7 +64,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; }; @@ -833,28 +832,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 Aug 22 16:16:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13361125 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 6D56DEE4993 for ; Tue, 22 Aug 2023 16:16:27 +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=ZOH+Wpo8TTZInM LXZLV2+RboSm+99KDiFp+Ff3ILbonsyk0XQwubL29ydOQt126LkqBv/w1WKLumdfbGCUCMzq9OlO2 wmzMxQxiF+q8wFBg6oI/kI9W55DDnqROmIbXolenT/OAnJy1yrly9Pql3opNhUKf5+S1G8hbgCjpc 1aYhpo8+oCOe4LlfoAiRPa7rfVOCGeAUZ2PbUjloaJqi4GJyQDu/nxB2YiNMeGX0CChBuHofa/fGe GnCZZqftjOw9HiAVs1hkBAkEJ7ws8cSkm45yKaDoQBHK8JPcIGR+Wu3lchwFbbPJTP5WAZRJXdDmL y+bd+n9WSkDTJ9XybE0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYU3A-00GRz3-2a; Tue, 22 Aug 2023 16:16:12 +0000 Received: from mail-bn8nam11on20600.outbound.protection.outlook.com ([2a01:111:f400:7eae::600] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYU36-00GRva-2g; Tue, 22 Aug 2023 16:16:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hOlOodWOp+2rRQJ4PIDbu5XqiHFWxZ9DIixWhFLQ3Ri8EDjvd1k7yppjJyyQl6JDCWbtZTtULN7Dz4AamdMYqmvMh7dwcCGKwx5n4zHnVHcCaS+FxwT0nrPOxRl6PtrWbGrK58fBarOmLFJwA2wxoEsGtCgiNj8FAasmIZ6dpyFt+JS2cd4g+7dSfRfS0Iwm6WZt3/uOddz9tr45HD4HKPzhKeOxZlZNrB6+0ryrQYSCobnjqk/ZqxqKDrvW4cxuQw9z0LuK1MuKhvNc0F5wtXgbFi7mE9fOLkXJuR9hU9Qi5xux9ashiYflRSB4VqYgZhoS+3Pusb9eWCjfGjsC6Q== 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=HmK6KZYtrgxkEHjrGyBI/bB1G7d5b9qiKsvvKxZGzkADO/cICE07srIM+pZBv1jtqZEl/xWQwLlTRpfZaGAdAerwruiBhMZP8paX9eLt4hfRc+NUvK11wITprn5ImPDix6qK61tYyH3Zf5mgbHm3A9O3+Eu7+c0jmLEpJ9XrcBAfcqwKlE4a1Iw7xOh07A2S6yHZpsxGlOeWJ438eQqlloHQn8y2DRH6T6/SIRUvh77TkuOVt9ItRsfFpo24CuxHdJ1ciWnDQKE4staUYl5zCVV1waNCmz4UR6c0/g27N8QTy06AnsW1Exx737qjDexwNeyucBmUb38cd0NBC9Xt7g== 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=QWq7+l5rTrZ/08Qm0aeM+wytJ+yFy6cqZdBgWb9O6FQ1yte1TFl35yxE8blKRlqUYinlNUGrh1+YOA4MwDQYzWI2BkVCSj0zSsd7SjkJvduXwn28im4NKoVr+BEhZgcl5DlISz+MWidT/hA3r7Vzz0A5za47t27cGdSr3E0GOMQRs1QHgvQaVDPPOrwR2r0Ln6MtoGs6sBlfbCsX3r1irDUnpCK+6uiqX6XBYenzC/mC3KtO6a+pPZmibN8WTRSBws3dx2iP+MNmRbRQDjRkim56W4KZcIf8B9GdvDbgqnOMI+0rZB+t+uU8zBKzAbHk6EOIJ4WAdRUZXGHmaoC2iA== 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 DS0PR12MB6655.namprd12.prod.outlook.com (2603:10b6:8:d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Tue, 22 Aug 2023 16:16: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.6699.020; Tue, 22 Aug 2023 16:16:03 +0000 From: Jason Gunthorpe To: Baolin Wang , 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: Lu Baolu , Kevin Tian , Marek Szyprowski Subject: [PATCH 7/7] iommu/omap: Convert to generic_single_device_group() Date: Tue, 22 Aug 2023 13:16:02 -0300 Message-ID: <7-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> In-Reply-To: <0-v1-c869a95191f2+5e8-iommu_single_grp_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR19CA0019.namprd19.prod.outlook.com (2603:10b6:610:4d::29) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DS0PR12MB6655:EE_ X-MS-Office365-Filtering-Correlation-Id: 4815ff2b-eaba-4d59-f3d1-08dba32b14dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nFzrUNvYQNaBDsIhFlqWw/E/6QqZBkSzTjdCYnZ8zU1kAkUJIq7ezUDPLoW218yHNf6/nCZFUREgjyRBb9XtrSGL5TEF+K56q/VeRXNQ3UUS2CcXouZty4yQXt/nRKikID+pe/B4FqgImRq7BAEZzr1YFTawh9Lgc9pwywRVvLHn8AxLb7/elmwq++W+OejZ9vvVcjs+y94Fk0TeuDk8SwThmtisYo7ZB7ohiCofodOCxjbB3y9bd66LBZPAWLB5FApjDIBuUzNmkMI8NpAtnuznOre2Ira3cdKQRINowVh7LDT2ZWO9PQXebKAFzLX5ItB1Uq37yy7S3TMCt8tNgGdyJA505wuoh82lxNgEMhNc4nfbNWgq0oa1XelKmVcjvhDvLniUJHUXinUeuOxJ4WMunNEVYQ2E3oYp0pmSUZNHM46gzVYpiPBsG6yBWXC38TCxsjAm86wVT4jyd/lAqNQ885eRGtwQSV6nyh6LNR7DkEMzaYnvbAeulQpU4siQLM+mOrIyyg7IUz8OAO78p4+ta/xFYK8vUvxWA8nesJSzCe2XztHLaIhGzo0+OvXUfMkJz5iiBkgMc8rBP3fT+J6sHKVaTtdxJPQHLAH2kTl43St304U/DuJN4xUfKHMGEbWvFtKU68uAXn4VCzy7pQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(346002)(39860400002)(366004)(396003)(136003)(1800799009)(451199024)(186009)(4326008)(8676002)(8936002)(316002)(478600001)(66556008)(110136005)(66476007)(54906003)(66946007)(41300700001)(6506007)(6486002)(6512007)(921005)(38100700002)(7416002)(36756003)(26005)(5660300002)(2906002)(2616005)(83380400001)(86362001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +xlOYImExYhkKku7dpnoSzA/8TMt9COPEFbW9rZoDFJuPdLAwS3tYk8amDpic8vS5JhC3wiFuIGNSea4YvkE/mUbBEWVqHdtAAmu2fWbnOK67STWANXXPxVD6nve0a6JjnAP3XubbhkcZrj32DZeL2kq4/IAyj75hLUgUBu2Tc1h1AwCv6kusB03PYD8gB1hjRJDkiRVBq/NdNdwc20tWv2Z2jISG9HkbOO9/4d1pgiZ2fjf+s7u7s3wp6jIIWs98csDVzq0rVVQLv6M3L5JkGSYxFs3mGlapgCYZJDvdX5GQOMVztGpz9l559BqRFLnm1MGbRACNhOjZrMPqei8Nqk+HxC8JGS4nfUhH9yCRAB2bFcvD+KnpbWDr/3o49NFjCAlP3X3uMkOka2Z4rkeijtnaDjP8V0MGb7+th/yhAJjtKMpzkEFXScfBffs9yrKt6rs8abhe7aNUTmDuBFcPks6MYq4qSw8ANWi4YO85lhwI4vqps5Bv3oGWow/7EIUI17XC8UaB5RnhJyxlfFTO4lp8OzLkVSikFHSifp3ReeUNkwSuHDuQeU6+IU3a5vXf/eo62jI43ZK1guhjhI9oUaxhuQi8kFSehpzE7jvgpKhoIE2MJQeDRKsUd6EaWJdHIBUVdGsZ/9r/4gauRdPCsgtX26zvwHZxMtIF42vBftaxGpALdhJOGqzo7tudTX4Qqg6UCKdqrkHe5Y+M3WfOs0w2QIxzJZeUasHhTuLYh9IjnGO7Xy1Gj04NXAEpMEo0QolC8QTLGRlJ37zIWLBtDH99dlAcMyZkIRPpx8LoLKUFfjSN8MM2rFNFdr/pQixoWkYSdPg7mAlyb/u3fgr+cRcuMpLiX4huPiikMCU4GkRWwICnt3AMamTwgwbA1DWo7TMW22x5pWluparHxFZD966Wns5L7+DalaFhqEr8HIh1LioVO5L6KKOfQQHZsV63R7dyJKlEk8knuUQlW5zYTOe6tsyg2VuaRWA0B9Xmm8VJrcJriFZvEZLlHP4CH1EI9DDEADmbF1PI3LKlzie8dvwt9/yNTIKu7ElhygMsGj3hXJgkKhO+evptOC3cIwnQydAPw1OLGBjdbU2mRPnJ9EOIcL0ufSaCM1P3s1T75EY2LrPw/8A8Ti+rEhuwebhgJOe8KcC1ipN15kpixTW67zYboOkHc3TUmbNxzFwcvJ1DRuRwp4OuDj7UAVdQ7ELkBO9qqpxq4oUXk2eM9aKtI2p7ueiFpw64NCz/oR2gS/dpt/P9qsKk7tzPfvNQXYjLO64/pXemxmr09Jm63tY4ZJd3xPOoliEPrw9luEStyC4bDmAwv/vCZX1cDdROeTlEe6Iy1D0dznaN4fxmP7KyDrIyCx9UPt6EeOc2is7by2Tky4Cxek8CNrAupNOTkAYLbkYCKpWMcE+PMYB9GYQ2ZF5U5bwSnqQrF915YXnXxfuuCMn9uYRcRNr/LBxP+tT7qB0O431aMv2gxWJyFSu9DUGB18G0+Pm3jseALvs/lIXTD6QXTKlCg/J+jhnHl6Xw8oiFAucRGqW34n5JGRFQihFSL6KShQ8FXj0BF4yKbD9sv668+emmBrGquFIj2zG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4815ff2b-eaba-4d59-f3d1-08dba32b14dd X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2023 16:16:03.4479 (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: +5d6Fe30Ozr5panqyr8TMCaaea6x9eagcANb5Swr8ARYouf5duafLpwANRINcDXq X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6655 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_091608_873455_1D5AF1CD X-CRM114-Status: GOOD ( 14.15 ) 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; };