From patchwork Mon Jul 31 17:50:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335342 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 5A2B5C41513 for ; Mon, 31 Jul 2023 17:51:06 +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=6nZ91DysHUN/nax2VwY+MVphmVWmsAGdZEKUs0YqIsc=; b=gn7AVOdVikxcfA TBOF+d7ZPKe0E0FP/AD2FPGUG3KOV93/OGey5/ggF+MjN6NX3E9UfpKhtkCtHMIcrwYodn5ti6IZi CQyDx1HpcKgkyD1huYeDZGJ7dcvrJY9n3f7VAJarH5tNCq/kOl+P+sC/R3/X71dBvaYv8ds5657+B w39W5gN5FUToi0hQN9yaLFLkQFytdsYpY6GOxFUAIsgwC8p0Xrn5FxGZLKZ7CM56Zy2Y0KzFhKMW+ 5VZVsuHCHPlrdZl+8KQy1eIrd6gABB8VjGi2lEkvJvM7hKPFi71vt5lQqCOK8jjIAYXhcMQNABuTr /hQGk49mcMGdR3AFODKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2r-00GtrH-1O; Mon, 31 Jul 2023 17:51:01 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2d-00GtYt-0S; Mon, 31 Jul 2023 17:50:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CYLV3oN/ek01u1srxsYStEcUq6hDKxxZO2a4XQ0zoDtWpVRcziP7u3mIqVKotxNf0OPtE7XKxsqtMUYAXUFfucbJBJ/h2wkyedbRdAtXEus6pVw4W1zoWcorQs0Mhc2DqtjWsjTXkPIiFIPLQGwFFsVwFOHmbiimHg6QegqTcNse+Tg9B98nLbvOGtIJ96njcOX9ctgEzlG8x2+ioIR/JSCJXkQHx+5W/TQ80r/uV0tb3zHYAyJIAzgj1domd6C875A0QPxyM3QMDJhgxHnhqIYImk32NjN5CkSHzSJsm5PbJamN05YXgPyq3HGmsJ4nh4BiiJmXnztbaVqsTVuL8A== 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=BhnYxwrsnrjdzbpdLkjENtz+lYlfys1ukcorW6kYP5E=; b=np3lpiK2ykUG5C9KW05V4v30NjYnECwqsqMElZ6y44jFo9FKYhnUE2WzKYnW30vxpnuNsfJLX7Cg4pPrifC9XmysbhCSSBh6LOicE7jGcIbjMxDfDd0WbLJIf+TK5GYqUrdY5fhokk2XcGQlTvCn7h42kVS+QJiJJDPkQ1kyxB43HJ9jhvuCbSiE/sQn0ptWkoZaSau0Hx78cXTRUPLFeKiGXnGJQprWAcJMMVY7eN52yTSfYlRhoXaUArPPTtcuKiwYMZfL316cNPgkTYnU//NMK0CvTtkusQqEJBtZ07FM5lPnIhpxKs4VleNF41HbcExYdakrIGHOcEBYcEpgaw== 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=BhnYxwrsnrjdzbpdLkjENtz+lYlfys1ukcorW6kYP5E=; b=RXbL58vFXJKh9ZUM03kCJz7zOcoKLJUGoH18B5k5VpXZ7Wnw0eCJwCv59OljRrMi3S9XzodwQXZ4D6RXEtrnYJMmx8olC+PcqKbmDRHowNuLo/hXCs5pbT/7SCvXsY6LBnhkQujcsGSTP/Jj+YExzRtVMPXQaJdL3FWgVt9HUWdyqSR4a2fLD6WfMX2ySI3L3G36QW+Y9b9GCQXrpDUKbDt/fN+9/ucjAU6OrJhfDVNjLlt3S1KmEPpNFvw9RB92+ifCJqLSFj6h/GyyrKVOQINIhUxcUQfyrfwxPnonI8y534t8DinsBgy1Y3TK+zdRsM1YzUVJSPu0R4WPnPSzww== 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 SJ0PR12MB6992.namprd12.prod.outlook.com (2603:10b6:a03:483::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:37 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:37 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 01/10] iommu: Remove useless group refcounting Date: Mon, 31 Jul 2023 14:50:24 -0300 Message-ID: <1-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT3PR01CA0016.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:86::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_|SJ0PR12MB6992:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f4d5926-30df-47bb-5968-08db91eea475 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WkvjYD5n3KKTtxX1ZA8Shf+zR52ggYfKmEHlBkAIJf3jTjMqMeUzzdYlp0WBUZzI8rvep0gVxdc/6wAOXbAJ1v+jZvWnR9O2SxjmnEV1w9SnzOxdVjU+TqNMw7Y3jCUXOAzJWJgFBOzcM2JyK9lReInAw7Q4DVq3/JalMYK3QkHGVqy6gwo8B0lnhJ0HmIjY0UiZlJQCTmM2aAetMyyVpEvuMPsNu5p/4BmzfYgFEp4shG1gQRZci4UL53tYu1q9ekaZUlX4JaHct5wgqqpclgskBLbZaZUlPcuuHyNSyL2leAkWHSFNYxfcZdpWB1hM03OIowwyLCSJEIE9b/iKRsPAPyT3S33nJiCbImqkxXG4F5dYOd4DkeuRRii15IsFgQ+mdCPV0E8HruYR90FwQiyOcqkRUYmolPA8fyD7dXuF9sSfDZjAD9Ej6Umm0fjmAfTzSrY61IaWgHlQ9z6y1+eNv/f54x289lUv/rGO5NrxFb+ZBGskk2wdReP/hB03mmzmbL/q5qWf2V/5ErMHBZ3GVN4lP6oXB4e9prQjCSYlgzMVhQVIGIN9bKgPI3QPsRVbXHj/bDbIxp1AbXrNZVV3hdBd9c6wxcemI26VOQRiNvlrK1cpClhVGzEktI7d 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)(366004)(376002)(136003)(396003)(451199021)(6512007)(6486002)(36756003)(2616005)(6506007)(26005)(83380400001)(186003)(66946007)(66556008)(7416002)(54906003)(41300700001)(921005)(110136005)(38100700002)(66476007)(86362001)(316002)(5660300002)(4326008)(8676002)(8936002)(2906002)(6666004)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pXH7XxJhNtY0vr9qHKF2wRdwRE0rsSw5p0/EfjqLFJ/tloislSWiHhWekp8DcvdlJtJ7P1NXoZtoNVn41RSQ8MbMu5Mw5vQsX6EGYapXl39P2sO75LIx5opXMvk/9U/hhD0yZuuXT4+qDN1Hk44NPcprPsvGOygfltGYQ+fJtqn7rVmWxJuxd69Glnt3aQiUX+JuQGaBDGeIQZmu4W8gnzFkXDnuUDyEWBEkHYPvoHpiEQfBP3JeJUhXTNkBibLGZZv1L2PUgRWdQClGtA91ITp/EJc8sjd2SaNfai35nlhT0fDoEUn9honSYxh8BWSu4tTgalITKRaVH360tEnfAMTArd2NM9otpNyZXD5QD69GFPb7m7XzwgBFPlF6TYfjI+pMLMEYtbGOI5H8w4Kj7KSfyeeYaChRkCglkctfgBmg3G6NHL7HVkl6FADesVYWmDJ8pGR4u9wX4/04Ear9Ex9KLFSxBQe88P+lwxS/F1NfRYsp9N7wHPPFAfdB0artmV6mABdn6on0N0GtYdRh0TkaiEZ75fuPhRuu7MoyilRBP+o7ndpNZAHglVAKI8LOYRCRUhvAJtIpwhGdJ663vmv/QwLmtUwhrp2IlGa76sfpBUlmGfDzJaurKf0VVqOCiT++N4rvqX64IAwoZL+Qlu6WxO1hVGlhitBSOos0Sc44morbYBh+PoNPDTNNIAJaJiW2TxllfbWsJ278gAL9DLLqRwhn373q5kLE8aLk+HTwNOL7EQ+PABoeN1vGogMYL1HHBkUXMmNAwFcVSh6fuusZq+uW2etyT7RO1YFuzANFpwyFEbmCW3Y4UHs29F8nR99hwQ32pQ1hxR84QcaBFZFH83vmfMzQGh+J0mvS2f3AfDWacglDZh7jDeJxjCbwYY72ljRi4Ye8LAgpdq6zgn5dI0JI7cict4dCHkLe85MWZB4gqYMpr6xAu8mVW8eAU6rytmSdPJzaaaZnVZGk791CHJlMsCps7X9B8NrOnIueSp/VoQ9aODZwKVSDb1cXFLhqcdlW/AJ9BZ2E/qfOH+zovT++yG/XyEdfGhAa29fZZxCmJV86VQ4r987ON9CuWHONNckiS6LNJ1b196b7U99EWfACWfwg1lU66Qf7Zo4ggtM8CVipIoMazrWwngmIO7ICCEGcHC18Zy65PdQVpSkWkDQunafK34+NploYM/aPmV0EtMclBSUd6712+7cmCVSIRKkXvzbQcGx1sTTSQO4+koLHijZXustVkNJk9WmEs/aca3G9p75atUVhoOiMhsA+VH/z5mZ8mvlRUGQ8lDEi5onBE3wNfd51nB9KDBl4QG2f64p7YGf3trQOWtTlYH1XonIaF/60qeQsojQYPllaUskPBDbRL1linExpZZT0c1qDzTUEUoQEUNoSMO31+MO+siaHcUgDu8rCIgacjy3FhCIIn+i/aonVnurTLSeISnN4fs37kVKKWu2ptwWZxtRMB9LMvLWSd6q997jwIyqsnAeaWEOOtCVRV1IZZBFCQ0RYIx+UfA9hvYtM/+kIBae8zPAZTB7eGUVhStCjeTKbsUGLXDI6QFkhNKVUazJGDX83wLc5rqBPAEZIzCBo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f4d5926-30df-47bb-5968-08db91eea475 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.2622 (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: nw54Lh56omDfFMc9UTh0mOVlyXbA542I4Jt0RhG5tfhrNeotYxLBLci7uOMxpynv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6992 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105047_183921_290764F7 X-CRM114-Status: GOOD ( 18.28 ) 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- 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..409090eaac543a 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 is the driver core during the pre-probe path */ + 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 is the driver core during the post-probe path */ + 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 Mon Jul 31 17:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335341 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 47974C001E0 for ; Mon, 31 Jul 2023 17:51:06 +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=GbLX7AILK6uXh9JW+SWHSEbV6TithpQMXM002isUp8Y=; b=AABb8FntDeXSZH Ho4mSIG8S/R2POHUlSn0H2nC/oopD3bJgGdK2d5ck0EOe1vyt1287HN97ONQ/kOF5SUkrI02tZq4j DTV01dF5GzwhuYUGqUTrjcfWstT78oz1UIwLL+GydbAGijQqSGuMZR1Tme9zBCH6PY1oNQ+f+99yw GEKFVSbZlkvkaFdu4Mwm9cLHSxEYAccGAUztR/oA2V4zD26sso/ee5c/E3PtpTr+YWUZp60pXJY7W ry3vvhSa82Bxki8vxJdZnrGv9AEj4PzVdyPrdw12rPrHkShGuwt/7edKtAck1mfWFm5RIyhWVHYoO KEnGKgpxHwcezaUnU3jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2o-00Gtne-0k; Mon, 31 Jul 2023 17:50:58 +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 1qQX2a-00GtZZ-0y; Mon, 31 Jul 2023 17:50:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gu+o/EgWPdsiZ5DnRmfioObAEvHrAKMZzPCfvY1hr3CJiFSrOG1l/bC/WM7IJWMAbPnejcgbChwindljWMFBbmbywjAWcRLB9ODp37m81x0/T4Sn8MKtSO8oTGy1pCTT6x8ezxMp5tdFxksl+BaFi/lXwD8lpLMWe9bDh/rvBFHXjquFKB151AiRuHK9VuJrOCohdyWJICmXTRn0mYvZqEoWhaL+yyqraYthPFTtkohF7EPrZ107VPg+xC/c+RxxCBEu+9UqVXCzAsPrGNgrlWhG78F0NUzpiuRkmM9NQmBTkNFn53Y4NylZr4dDwK5b6xExOIpQ3DlJsKHIv4f57w== 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=AmX4WHHL23gUBireWMOT34rh6wFQKVQ+0sJ2x2RXhfo=; b=NTtk6ukTzSMpcuvfud0cvXnYZGNuf8iVLa/G8/2w5O2zwRNKxGSiPrTiC8uNkYlqZvGnUUpvvNYRpAob1ognn2q8NSpOZ66iFEYF7c7jytKtztc4epKp1+h0AdMESbLy4f73bOZYyx9aNZ/eH9WwFB+J1znGf7oz5dQJD9cgE+T1VLxY/Nm2AmcAny6B7HLssq3VKCzdq1OBjtlQEzNZAREzDEzyNSQrpaUrzRkX+RjyZHMCn2GrDmXXRr/y+p30lF1BGEwcQWwX2innfMncuelRUkADONNGTAoxsVwlJO1vut19TJ8hyQ01eBMFsoSXeDBpdKk5Na+Jxg5modUBEw== 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=AmX4WHHL23gUBireWMOT34rh6wFQKVQ+0sJ2x2RXhfo=; b=Bj+ZcY0Tb17ryvBsU2b3S+8mK4pz5kPYtgBSr7Je8MbTC4dVPgM9uOr6uZSztVdLWq0FKsT0DMb+GEgtKl03uZby8wHFM3vr8im3M7fHTrVg1OirGu73dtENy9RvVj/ICso7Ig8I0AlqiEF5aGCHXmvE/i3rmK39BoKjsul/W3m/nLR6W9zvo9gmj22SD3gPs+MFCgpvkq1pKlMP8JNPCoxULMnZFgGPOOOL1nnrpYjVfd9Lt1BA0LFLVG+Rez9ICURI1Xpl0h1HqBMcMQWU6Z3h/JyjSs9Rzt3ec2e9OcREfWIeyBmMcdI3fb/u4+HkvMK6h+69RkSGTZTSEyw/Tw== 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 MN0PR12MB6320.namprd12.prod.outlook.com (2603:10b6:208:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:39 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 02/10] iommu: Add a lockdep assertion for remaining dev->iommu_group reads Date: Mon, 31 Jul 2023 14:50:25 -0300 Message-ID: <2-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0086.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::25) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB6320:EE_ X-MS-Office365-Filtering-Correlation-Id: 459127bf-4727-41fd-6583-08db91eea4c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VpOdn2abDiShUr57WT8Gbw+65CWEggZC8gw5GnlDWG83cVAn95IHHQBepE5jVnawa97vPYipZn+qHxu4HXZ7jIV70/9P+FjORlhbRpvVfYKO/arGqTGWYOcm/jJ20iSB/R95A3fEm6nEzT5p8BI6Crm356bGd9NNFyI7eGLqN7gAYWZfjHUbfJAmlyVEjJM8kcFnjgrXxA9vbsucTutGyZTOgXXKgFGOiwrQE2gXpxkFjwHP/9UbUqi0KX7d3GNcG6ogzgz3Bo14hTqII2mVja1xVLUYN2Ora2oUSVlGDAGjxfPfSFxvnV4wmsIrcaP2wz09c5F6GnSr3ZATD69qsjsCvh5VsJAnZe5Nkmn9v7Yvf3TDiBMhDVerY30i3yS+nNhuhOrBWMOpQ/mDIjI6pP/td9ed3XJoc6FuiYEkhYBe4ENJUNMWmQgQ6hkNgZ5PMZAKUmtVz8QXQECKAzd1TKwfJ6izCsGS37gpOjReSTJX0ZR8PZs+XQZfwA3ZKn1t7gz5x7EvuvUlN6lkVD5lwlltJAQv5Ic9PScR1GyeVorlc0axn5WonH8+l3fIRWoWLm0WKBCmDbdtp8u7+/8F5BBtVUsn+N1/Wda8V/+2GDZNJ1O7fo16sEqNhlEPTkgh 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)(376002)(346002)(366004)(39860400002)(396003)(451199021)(478600001)(38100700002)(921005)(86362001)(6512007)(36756003)(6486002)(6666004)(2616005)(186003)(8676002)(26005)(8936002)(6506007)(5660300002)(4326008)(2906002)(66476007)(66946007)(66556008)(41300700001)(54906003)(110136005)(316002)(7416002)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ugDGh5kPWgV1xkgviYe1kwLmloNDxEpNhIDsExVy1dYGTUEbJ2Af1rGYtHksgD7upZ+zcyIuG4J9NOaKDYa7qHUbm2Tulx7X4nIddO8jabQ8PzmCbFHlAxeQuLDFNpOW2Br9R8U2XdrGOL2Tb4Q7ms5ovpcgB18hbWubhbHdq53paUA117olWhLRraYPMXrgSrLSXMcYt+0KWZzDwVwC09/lHxZW2vfF5DsH7LJ1puqo6o2yKTZ+Lq7BB1CkRtGmxyngYJF/P71gtzHo2LTEd8HeaujSPDP7dTxrMQ4xmAKNcrlHaOsBCsNf9sew5gGlUc3kooCLGswMvqZSPYzKo+C+YDK9ax1BjIxksk600yjjvazHoExW9QvF7XlqfNuj43mG1KN0PueBzQCyUNSl7hSwZ0M+lomxjANvTJdnWzv9xsuNXVYUc+uhcIrj9A+TfQAdEVRqCpTcbhrompJnG4UD/G7+u6Dhnya9/OhDBDviOi92dKNRzkrsDBMDBQuy/MMAL3wUSQIf2XLN1a61mCjkCe4X+GZKGbuAHL4CKxuK+v8vMmafvkFfBGpmba5kLaMT9NDZVy64CtEl3sFovjZ7QoALy3NnHYL23vxzId1Cj2g5mkR9ERgy/6c/782vrcFNzPtC+vAsQr2nhsRBWp+EESa98F2kPUu5lE5/9NO17HTtZlWFXWkh7Gq7SeUZuofajl11PBdKD1mi37/vb58YgBaLUjgVHVLMDaoilk4/zuv5KiWaak7u4r/1RkKJX2+Sw8R+1KFOCjDU29hrnTWNe5/UWEtEtfFBFp6gU1vOu/2/9V3/eEc12ZFYhtA0xYHpVcG2LDXVZFkJKGfbI0SQ32mH7lEC7MNezi7+O9gA1Xy2bbPbHa4+D7AeUXzJVAzfPyHmyhLc0yBkfXwSi3VpXAm+Oj1NnI6aIjM6SuUNl5BHz3fjlpj35CQi8NYh2Xc3bW6HIyO5C/3pak/quYX/FNeY+NMvp+0b0ELJDG0sDLmMkE+HQVj7v5rrleHTh4/SL446h1vs11jvZGikObL8QYTOsorAmM7JABK9ZgoMenqMtNNbdTpMNPIHgw2T+NU2tBol5NNzteYiCZQuyrOl6/mVDuvQxB+HSrchbp4lFdPNuSCoLMNrQ2N45wsMejTzNeLufFqFLk5SD8KbdWiygUOijpgDlJbyKvrhsHQN+TklIqTvIcZAkEGAo1fslM3kVVh53G2sUL/34vhpfvw+T+H5t+23urSZRsrvjjm9eCk/24NRbIbTr3Rjo7w8o0Lr9PMIHB6mJqmR5/Cn92W0RUJcDpZnoir0K1g3LvkPz7lS5rQdCISE7jQO8r7hvGIW2D/PPrf/rAVL7Hm4tMQnWy9ZxfE+VtVKha7zNio6e/zUBcd7Brbj3Is4zwG/Sky/nnOmVBN/eDxm4pOr4p51lD+0g+GLo8uiuSOUPpugT3K4Jyy7l5Jw0yEYhvtQpWY31JCvdB1kv0RiEv39xiLGDQsi+yvczEe/L0xV5w3F93P9qNoEXreeUoI5PdSa+MGBgkvPahmz7nRyj0hK5H+NkXJlFaGIc12OYwe/OtQ6bVdwMk7KTggd+jMrXlm4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 459127bf-4727-41fd-6583-08db91eea4c6 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.8790 (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: 941zaoeslWMjhrj7dmdxifPD1fhePYvOKqEnKjXUDGWGmtf44iPEh+A4DFvqpZxb X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6320 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105044_353110_E188167B 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 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. Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- 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 409090eaac543a..f1c8a333553e3b 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 Mon Jul 31 17:50:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335345 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 C6FFFC00528 for ; Mon, 31 Jul 2023 17:51:08 +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=bX4N017l77NX01iTEKomqxRxLSY+05vDfKxq3FVp+z0=; b=B8+yBxV0xrVw0o CpV4LzwPIVg9uaVKGkcU4bN5WMgLUD+orxLgGlqkzQr2YYwXQbODbfbC8sD59WY5+FZt4ZIyYP/2E RctgDHIghLahRCQslu/MPRmMJRF4DFPompMsChIj1gUQ4DTV7eooXrqrstKCCPqcGKPt/iK1LThb5 9/tTvSw+jzocXqX7tN2Z/J7dBpU8fYBN5Ar2e8qSY4aBghO+jMdGOzvOUtuFshOBo6h2eJhLzZyie jv581U8lQLSME43WFoXYPtgK7tGjv7MtIegDbt4hibIOkQR2ZzdYthyn3i9QcMX8k81zjACSWlIY/ fy8/RGCtbOcSqaJfSYGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2m-00Gtlk-0p; Mon, 31 Jul 2023 17:50:56 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2Z-00GtYt-1B; Mon, 31 Jul 2023 17:50:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l5BYgaN6E6oMSJ7pc0pK8shan4qemJJfkrwBUtCIHySEHdhz1uT3aquELrWDUo4yoSJXmCZLGLC2lnaSqpkBgs/1r7ptBuK9rPuJdRC43XSNYLIcqvyWLN5fJ636ixbMk23UOWXBk5d9Tmi6BJmPhkqPdAudgVFPVbQVqJEg7YKeZJ6yXPkRFqPWXa6K1czSV5Xa3JxklXNReMz8DPTorElO304jhE7wdZz7b/j+N6iL6NrC+DrKT6ylOlBs8+LUDKFPmpi89U/l3SdpRCKnNh74+cv1V9RKWAIogEyaxiUzIxAdGjj1F7HfBvI5rA+ATedLdOSvX8cQf7BHwTUT4g== 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=2GIBQCaLptdeGVGlR2btZ3TztjtvQ4WCLvPN7KeQI5U=; b=YOoWQ3uH8iF9mSCxXerMV5q1MAFsxKw7uahnCjZlOr+boZSMu3fFyfBWOA3DGLquYFTlsMKsA0x1AYUU/wcXkQi4oo1DY3GQFrNy79v4l283qd+CkI40VvCcrq2nod33AJnh9SxRijuEGtsMCIB4B4hypIdG6zjHsMyv9klVELDpzsd6S5dajWK3DGolyQDTpovF8qnfvNkOuPbuGvhFuuJHSRaJv5VkKV83U5GNapM3EeL0HqCf4y2sEHgIM0lV65unzGsGAVxg2wsw8YHajRqEnCSbyFPKLZbieS5paxMieCWyV0Pnw+9FwkD84198COXVCEgPaS7efuUNg2KNQg== 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=2GIBQCaLptdeGVGlR2btZ3TztjtvQ4WCLvPN7KeQI5U=; b=sW4V8gksyAIaeNius6p03qIEMP1chd+cI6KnSm62o006lqdlxaOWE9u/J2gW70VfznHonvx8H1VKFOVyIDvncbMU+le7wJ7M2nX82DF1RvDnXPmxgr+MhI7G1HGcWl+HnxXDqe5WyiqgDmR7fMsf1tCbiZM+yN7CuDDU4Vh6GwzOsawjEdu4UbQngWxAFKJAqK1eNeemey2p474S4O63M39iQ5DsN+/kWOQRwIgzw/HU9ccNd76qjW0uXQas/8wn4rY1HJ57crdxAW0ZtGPlwzCyEMhxE3sV1lyNSiNbiOwWDBp8ciFOfaptjA87O9OJUGf2S45WX9KBeCWcdE04AA== 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 SJ0PR12MB6992.namprd12.prod.outlook.com (2603:10b6:a03:483::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:36 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:36 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 03/10] iommu: Add generic_single_device_group() Date: Mon, 31 Jul 2023 14:50:26 -0300 Message-ID: <3-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT4P288CA0038.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:d3::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_|SJ0PR12MB6992:EE_ X-MS-Office365-Filtering-Correlation-Id: 3547cdc4-839e-489d-4787-08db91eea462 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3uqDZSzsumXXTCKovB2Hd2MLgoq92IPMLYQBkYNjSUESieFL5yKfHzm407dUqCmBfYYeCIKJg8ZfDyF5mcpWKrhNEAKfL13a651KiUlt3ZJV/rcbfEm841qK8jYfpV3XDB86iWexshUhM3tHbWrXurJNqTMkaVT5mZQwsbvf85E4CclSIesdBdXXczwiXRjwTD12Ee21mweIJY4G0Kfzf+bv02rYwDrs1d6RtVp4/att4Z4OEhdj7YRvlnXG3oJ7dDhfarlmZDcp80B1TG6J9oH/B2kn7goW8bn906F+tvZmf6ZnvBxTXKTWAJkvnA90r5bAi+NkHalQxK4z3xqwnSlfsurk6Cp4fR5nQFv5ntfwpCQ7NaWAZ5KFDpMIsXPtaJk5MMl7kWGCWpVBFF+Xc/7tEyyxw373lDkTTjv2YlvdAGR/+v17Zelh3FtLr2R2YZb799Ds6eKSjr+sQoQ+3U7BFJaIrHozwNvyjN6P9WvDDJmxmHqbTIOYd/S8Sn+uDchvj8AHAGXfBYlvBrMVy0Xf5goBg26mLrrRJikxtEDzgsO0SXPU5KGZt/V6gZ4TeOL9CHVbcqYgn5t9lX/ckXs58UjgKQWuDpoq+7LjbOZk8+yTyTZWZIPQ3SMKgqwPbq8GYCy9mwNN5Lr/d6rMKg== 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)(366004)(376002)(136003)(396003)(451199021)(6512007)(6486002)(36756003)(2616005)(6506007)(26005)(83380400001)(186003)(66946007)(66556008)(7416002)(54906003)(41300700001)(921005)(110136005)(38100700002)(66476007)(86362001)(316002)(5660300002)(4326008)(8676002)(8936002)(2906002)(6666004)(478600001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HfrHOAZmXt6cbiHAEwMuyLnfydBwryNyLTVJn8sv0+SoPJba78b8nA1ehNgT0l1VITbOhKplAS5yRO3pazzAa7SjKMqn522qvxcngfGEs8M68sxtuvFxFyOAZTvTd92Lwtqxa/lGWe9xEU1Cbs57iXM67AcGN9fKz9Z2Q0YUmL7DEd9k3Op5ZqL6K2bMvOJQ7zYGHb7dx+94DQ8wuyQp8eUcHuJTKget6Is3J1fZam96bX1AxZVsLOvmFtiwPnQ+Icvd8pj3BHvXPl69eCIhHfNDZFvCdIbPGxGlksq4lhPt9QiVQR0g98EKsanY8ZuyLJdbQsEufm+9eXStmAg2Jxgp4cBrU5Ykn5AsDXOeAqwU6PNhWGd9e8HiW7xDyhaYh8Oe0Am9CvzTsHYQkSAlJUBR59RatBU9e1iDeyQEkxc+KIDJWmNVTpRiTcXZBvdXwNMLdRvQluv1vBnwXxNWpFWacc4PYiB5YnMpwiF8IhDHfYzFbeu1isuFiri7W+y9v2+yexSF/F5irSBsYTTCwdkh5q6uFCeIwcbHPTJZNa0c1N7zC46tl+m+cGj5A+7pEwfE60DVCQ6fwRyAIahh26HJHL5B+W1wjUM106EZbYUxJrNuZ5RzWt2Sus8zto3NJqNHfOKJLOAoOs46mAd3xjBbXrwsFfOxJIIAG44WCau06L+NjetvUNBSVCmxtf0thKWjL5nyej8xxetAEnsWdpkN2KZirToXaaWPJcGlYrrIDT/lR0Lsenj1yaNkKQ0uPfpdfBcYngyjBEohScxTRJw4qJp1ysgUvVilelFOeSjb4ekSSP0CwG4fDWY3dt0YwiQtjYT9z7LABPuQ+ozuQO6mQMgR0CDRQOD30rqjSRC87TI6KYJDk54jx0fS6l6uEmbGDKAOc/5Ot1u1mZp67LwN8zZ6aKAmUnxwWhnxy0UEYpWXClUi+6F+5zncYuIw1x/sDzdw1IrHqKyBwVcHJTD4ElEInOVBosRpHlThDUoVgNEIlD32K5jBOVtY6APJJ4TlelUMcU0SGoCEEkoIrfkLuUTcffkXhAPQVk+lNIIJzOO/VKKPqwaIm265XWGOEHptc3NqS85ckqB1xqGDuz0fwfwFce8bfsWLh3Ssf81ns92hcZHAL+RaljE/Mo92N9FO2ARIO6gXkEx4+67zGD4E7jHsIrMZMDnAO5WhFElbGRsziv7BfSW52oYcaUB5JwLACiz+jWBWNgLBasvuGxEM19gqkPIb+gsm2a2neOlj/TtwgX/ebLwwSu1rizvlabJUZmi9zfw+LPtGX3QXkUCtCA/pTO/fQ0YBrn2O6qpxTBObfByeiib8GnoDSuQXUReJniDk/uGDRdOQwRfCCnW84i4OPueZEY41gjOxb+mhda1iJavgSDeRTAtjyKN2So0vfYmJ1cDHtVyAKi/sRolAvyb9T4+W0OLwtHz6eo2v6/hxHglNZMPpW3k1/Iegi6BD3FQUO7I7VTJTVL6FPFUSzKzszv2cHiUz5869Gh1hZYFtMZscwNAkjt9ENpLGf+PSC1qCEl5MEa6Zr2znuQjYxV2VmIPJc90QjMDiEEvs6Wfm/fOT4AwxPC7gZHS7 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3547cdc4-839e-489d-4787-08db91eea462 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.0704 (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: rCaMASu3STTYMzi4fWciT/VFWfFk6X4PgP8oIpzPWTdc1MtET7SFS1nTbp1c1j3C X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6992 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105043_411467_29607A5A X-CRM114-Status: GOOD ( 15.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 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 27 +++++++++++++++++++++++++++ include/linux/iommu.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f1c8a333553e3b..c673d021d367e4 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -289,6 +289,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); @@ -1595,6 +1599,29 @@ 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; + + 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 Mon Jul 31 17:50:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335343 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 0927DC001DE for ; Mon, 31 Jul 2023 17:51:08 +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=bjfFKrFFE0UsZI Pn2k+U1DNMRxje+u7PCpHY+GlcNd222NKHz76Xu89D9NGQwa70Jd4ZxCxM07ravbIlNq4JAjGq0wg 5+lCKEC/gZRoysZpDzeAQIqp2pU5H8HK3FxTWiH39+0ldbc2GVs5I2eSYuastFVa0gaDnus4dG4V4 n/ScHZIymN9eLUtyOvFutTVqHC+1zhyhu+h/uqFi6qI17NGZ5MG2WFNoo8qIHIiEXF4gUmtpoHP90 Cq99sBQuH9dA68R0g8aEpyCv85jVkfpiyEcoTuNGBlVoPtHEUJyuSLgJvOozrAUO2hUZEEUEE8oX2 runMe+eORgYuHj+HJ7vA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2t-00Gttk-1s; Mon, 31 Jul 2023 17:51:03 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2f-00GtYt-0X; Mon, 31 Jul 2023 17:50:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L7bqMvQBrw1sRVSzRHcXZLmi6ykBUgBKcTffvrH8lMLVi33brrvoEePnQfAzS8smDO3L5nbnG1kT4zobYiDAXSsnMoc03ZyedRgC3qG3XjRUrTcGl+Q9476F4jPlwm0yFR5P6Q36jdX5VWx0ZtApaPPohwxqrb76CwI0KTQlhjp9W3Wg8t/S+yuzgZlyfWh4pQFVAiI04XaROMT5w57+lcrlBzolqJ8k5nl176SNYEShulQPSmKUx6EcKVvAq3p2t+JnwxGoZUVtDwMpDmhT8+SUsA3lZ9RGPaPWdEW8mB8CFIAKZPMUEMwCDUe4ggiWyduk4o4LW702RGh/GEODpw== 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=ZIdXmDWgOW3unTdZQskpf+n0HmxnhCRKld9eygCnCT4GL5PPIrR620WezWe1L7OOhXexbnWGIw/aBcb8Z+wXR06fs4VPIQYot7TvK4lLIv8gxID+HIbHpelVIH6Gxkfkl1sfO9faaNl7gVEmbEj0wEnfKGoP3TuFroB1wx+1C4jQWtiYqEQv38pVAVunA5CADa+EvSTZ7Tz//Xo//6LwH7oyJOGgxaq6XlP2uFOL5d9RQ+7DF+pc/tmsLiNp4n9BdnfrAMLS8PFRonw9i3MaedvFcE6ZweAIhizlee32LKOhRgf+pA8ylskC4Lw6yBp10FsjMW4KttCR4cG/abikdg== 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=RAZXl1rJWXqSWA76F2G0W08Si7S3Dtr682bNiZ7+GmN+Dl0YggG1c7AwCcYd+7QzZ36sUpiCY4U0x0h3xQL/E+l4SCiCYCJlKEHBnRX+3W/L55mZguvjZ2KFZMrsZd+Q1Q7oyGNEdLmXL/pa8GbA7YZld2hyiwYvgxofyZ9ZTBIp0MwSBnHguXDVPJvIKpd2+bNAQSzsZhPDVan+31V/34b7KuOlLGHKmUUpMkWdlp0l7wwf/KlXvVkNCAz46gcIxPKliplWm8OU6wDb58AOP41DjyGXHWFrObXGmElpIL06nhjdNBVs05ho6Ew4Y9n91ytB1Gc4QMf4ea1RCqfefg== 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 SJ0PR12MB6992.namprd12.prod.outlook.com (2603:10b6:a03:483::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:37 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:37 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 04/10] iommu/sun50i: Convert to generic_single_device_group() Date: Mon, 31 Jul 2023 14:50:27 -0300 Message-ID: <4-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0003.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d1::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6992:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a5083ec-369c-4ea3-092c-08db91eea486 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: efqiC01FRoHj0Ym9PZZrklkAgy2MXMyDI22K2Tc8Jy3BHQxKq+Jn6gvxGwEk84TJ9/Xykc3PIMu6J8plMfWH9nOzhF1RLAPScs/CgVYX8CUkabpFLm28nQsxhNhrwab0tww3SDRVFDsuvDNZNA97wDsZ04f1r9m4be5HeoXntfeFdlWUWa7kw+ZhgR897CDm+FASwYVpRzntRo5ndTn4JRtwkxvKUAjEVyW0fZUpmGNzhhc68BCaxx/oSQYSb97Gs5iBHxE3LNmXteOAYLmkvbDsXBgqQ89yhskdCvRh7TueNbOvhWtfPSB8+a27sSZs9EyPtZYTwWUvR4gFKXdok1/41gS3aW7VcShKV+FnmT2WeTouZ4SOcoRlR+CQsSQK93na4Y2wKgyVXESsEE67Ukn4QjLT92RODRuVLBvpAaT/v/2P8MpJ/b+jHsVYRDLeKRGe6cknbINo3grWHrnCuuJns/sqE+D1NxGCozocIvJBPnIKtQdEdk4SEwC/1sT8Y3ygIwK3CEhnMIzSRIihDjk0N9cfj9ZjnjUaMiFhdjDEMRWhxVe6xMf8EfMVf8K4iq5RtpFv5+h5nv6+T6Msw8b/XONkTubaxku6tqtZCB1rH8vmCxVYnSORFigBVHiI0ekqAKDetd412hBM0qEtJw== 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)(366004)(376002)(136003)(396003)(451199021)(6512007)(6486002)(36756003)(2616005)(6506007)(26005)(83380400001)(186003)(66946007)(66556008)(7416002)(54906003)(41300700001)(921005)(110136005)(38100700002)(66476007)(86362001)(316002)(5660300002)(4326008)(8676002)(8936002)(2906002)(6666004)(478600001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DWht0jx4cMbK+WRz6P++YXkShMxZvvIAmrF92yZYGdMpsUBHYZhYh35m2bCHAJxocmYofPlMUfyPToThAYPl3sYSCPqlxAd749tkM/7Mo4NYjExZU3/V+XfRi9FeZLKVFwG4AG7qgyby8IqGtuDqbj7LUllOEYkhO6gUgwGo3AjYgnAqrHHGy8Rv2e+TY0DYdI5wCBZb8cMqqx3oQM4Bem3904fXAXOIZWrbn321HCZs50KklRDPer81u3dVqNDtMCrMvdPkoTkuqRgbjfRE5dn/hgcAbihSYjfp+iwX2wertG+gBGe/v+sBU97fnJTTs64+E3kZ8pYaSumIdHt5r9pgkyvfBHRECBlAKL2HMzqwK8dRcT1IhbduLYBI5fdjaDNOKRKuFd1Iir5O/UTHYVPUTy081Vo8LINv9H+Xaz8Nu83ZMU3Psl7hRww+REbGgFLyAdTdWULwQRgfMbd3nk52SJyjfcg0zmg9fvAQRgk0YeohjSFrQKVK5QWjfBBCHOzDv8Pg9PR9IGyNEpAFcd6Sn4l7ge8XuMSX0Acgn2nsL/06VhyokVJzBr5b0vfzoVNCOa5znhDUFa7CRg0qn+609StuAJhI7Iat1wX1zWH4YmURX1WVY8Zw/yf0w5CllX42douZqySYDVTgBmPSZ1e2+WBJdKLfqkJULFQOET8pA5l5YlrjWLE8aRJ7WJ0vFRQtcCVw5de5K3uyOy8a9fajgjVbQ1Htfxear45B1bNeMJhrpN4uVjCd4oGzWgm8b9CMwJ9a/jmrfdBCn5ELzRuDJzlHkt/faz4vil1Qpptqf7Wnq9m03fBbKHfrqfIzfRGBEjB9d3uachF9Fav+xgNmr5fDiCyrKcPKls72KvOvOa1TfekNFPZshysq+AIHa14WGdgGT2vVOI1ULdtfATjgqTeH76+fP2BHzeUTyHJ/HX8j1vV9pZySfUCW33A1AivvqscHKw7JqM/gdH4TFmh6o7KN7eLLdemndYjkBNUPRwLrGBdGfISspJUKCM0xbMSzMGhs0dYrVL0zjH1p9D9AYCaElbZc68uhcqFMZzKmmVD3zk+wHpvHQdWO7qykYpzn57/XGXQn8DINhu9KSSpm/e9a7ywnZll57nx6NmHCrudKWCP7cXSUxOsLznU5TsKh7qhlfan1ij400JTPVa7Q8Zoliwd5mu9zkoR4N2G8e1cHgB0dTnccbv+5pn+ijwylTANFtm+7wjEW4dcPkCLCoJh6oOMrdv9idJV3b/w3ilYRWiBCNHRFqKUKjxJ19g1BOgksxW3t/DInyX5oMxNRzZC6oJYgvyZg5If9ezjDcIEywXGFRjO5dYUhuYMrwssmzdAHJ0WL+Lr+p6Y5AdD3536LxYTHr3i7sJITRMEM5W5Q6VdiAZlpsGOYGzlx2KfvQygLsY6PtY1c/JNqTSyG0sCIS6sFHeddbORmTm8tBtV07nRgG2HttAB2t+7kuk4l0A1KHdU1XGJeoixjdb0WO9tEUG1vGPYJ1+tudK4aTAjwNmqdUEkiX8N1JSJJrK6bqZAVJZuu3dwXNbgS3Hc2xUKm3PngNe1Tll/rT4uMAk0zIC+3cuDq061ZWzu1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a5083ec-369c-4ea3-092c-08db91eea486 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.3520 (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: TLWppAQV/Eja5IzsaE5x//+vv1sYX6+UusDItUUoVIRGqpTkxbxD50cU97c+Qe1L X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6992 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105049_205099_AF258D4D X-CRM114-Status: GOOD ( 13.46 ) 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 Mon Jul 31 17:50:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335344 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 1F751C04A94 for ; Mon, 31 Jul 2023 17:51:09 +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=NRYCzql27PIQ24 uAg2mDP2b3cbkz2VAY4H5ya8sVx3ENeC0pkbqpvRWingRWOYp9tOLdDrvnRAoBCFwxKxNxMca5yET 6zz80OU9qCScZA+dLnlhce+vtbCSLpfc8ZziXJim/vihje+HJHj5K+RB7MYmywiqi9ZFcLZFl6Z4K F/NtyntK0N7T5329J27jBL19y16RsouIQvUGI1v6Pz2krugEQLl/dnwZbAIpxmKJZGwTKvVxiuKHH j1rvgT/8+H8RvhMh+6/PBOTLK8CnxlNReoDhJtiXZ4QryFiQccCjlrA7k2QNYnV0YMs5m/Oe/1FJR cKKcVIFWuGhe/0TzL4XA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2q-00Gtpo-0U; Mon, 31 Jul 2023 17:51:00 +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 1qQX2c-00GtZZ-0p; Mon, 31 Jul 2023 17:50:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R95p/g5E0H+TFmZP6QAueObapZ4ZqUAXknEzSPBG/rP15cmVoBBiid+oApFdsfRef4JQMF2VGiTHBNpXew5/obYbRukLX6ARfl+fsiYeTIP25stNQuIyd4w/ggpDz/oo03iLnxeZRBmSgwuC8zUefT/KXHDTgS0L1O8XoyDol+Jiu0961R4beWtES/nCX89Y1kr7XSnK2QlHwQ1OqDBHT5Pz1+yBvY2s4ZZt1CbMelnVqKCtMvUHSyQIoCHZrY0FwdoFBUFGT2Hy9xpmmt9nWobcjeo0D7avnM77p+XRWSU8HViyr/l8rkSLQ7fgva1pUdGxylAAIMt6Py8uk/2nrg== 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=XVHlKOPb70hGKVLGgMNOSrC/uJGrhBp6B71UmCieiLz9jw/wL7hT+Il9lqWVlXbavCv5Tr0SorLLiNp/tgJOpdFwubzEQmkZ6DONkTw8uO4EmfrrhKulJzuQeFMXUcYXl6lZjwKRCulfIDrWo+PbZ1DnwAlDMcOZO863NDOeVJRwZZa+Tc74wvKxvdSXhEmIrwnIZk+8tkfvR/UMIph1ZgspEST41rJmvjbh9BjFcXRzhFOcdR/UKl2DhAbpz0xQHoWsy94yOd079mb+U1PKbIZXta0OuUHpsi9J/9SkHtXZS4D8qcBpGr38sgTW6FNjw+LWSrsVpkGytgEim/eRnQ== 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=XUqB1Zr26e5E0d7k6yswxcoNvJowMDFxJePea8wGa8qDjHtMhvP2LGcCax+lyypS359UAdTTVwz/jizI0Q1BnS563QPfkGUYVq2n8/Y8mbgETgHXI70QLGQbIyAtEfxfIju9cz58VFeMEv2m/h1LWu08Z0XJ94y6KnP8U3vWs0cKa23rPrGR+5MoQapFpwtDtNseSR1O0Wlhp53ZlcLPYiSTHqtaAgibg8L+5REn4kmxcp3zPnlqZ/SD4v8y3VfWQSNQ6MkaNUvxnnFBlXBY2tcQvYf1KjE7FFA0NPE86HfoQDDq1haQYD4Tse+SoHUbEy412wRu3Rx/74n5Bk0nTw== 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 MN0PR12MB6320.namprd12.prod.outlook.com (2603:10b6:208:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:38 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:38 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 05/10] iommu/sprd: Convert to generic_single_device_group() Date: Mon, 31 Jul 2023 14:50:28 -0300 Message-ID: <5-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0084.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::23) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB6320:EE_ X-MS-Office365-Filtering-Correlation-Id: f0967efd-18c0-408e-8f21-08db91eea4ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2/C6ywM9FH8t3Oa9/OUgfD35T5901MBRPQWn6n8ri194MnLT3bRiscsSehN9EQLPlThYbxz7V7TMEdNRQWasZyXs3HyaN26TP238XOTti4P3Qwt9V6YRBJTQ+qOFlQqRNWOyFfWve26AypEppm16k7CiOvdMOFgvtemHb459X0N35L9k4Vkspt/iu5tCvkg7JLc5FCCrMn+t1Z3kRk+vZIXajLCnJa6LgdnK35KozCIGhQUznHR7OFUYYdEXtg3JhM5IaiCtwR+6/Lg1JgAdjwijdJJf+Lec+qkV6S4Fp3HH6IVDikKaIn8kl8S0W8X4cUFbmD05jsvEOweU8gU6hwy6PgGsv+4jQXjbzU9/3jhW67SrXGd8Gl3Eofm5PUfcsDtmsus6cvYJnMTQVithC7jWzWza7qIwu3Q2IMfdc08oosPoiIRXq6DNjSKwdgMDsMz/ruNNrmIhOCjjqkofAQJyZBws+cz0x8/D6VwXcK0mTK31Ukz6wd8T54r2hL4LlE9h3HMYgO8SyBRnPEx5DB2/N4ymTu5ZgJLXZN8wLSbOTb7UKo+2IblWqF2J/bNn55BdNABzmPJKKNk3YJ1U9w0d1Qm/kF5yRFNJSULh3gJOR21MS4FrfdYfLdBvDcp5cSUDbTWxEAArjrZYVV2Vyw== 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)(376002)(346002)(366004)(39860400002)(396003)(451199021)(478600001)(38100700002)(921005)(86362001)(6512007)(36756003)(6486002)(6666004)(2616005)(186003)(8676002)(26005)(8936002)(6506007)(5660300002)(4326008)(2906002)(66476007)(66946007)(66556008)(41300700001)(54906003)(110136005)(316002)(7416002)(83380400001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SYOpQFNQ/qnwhimnkjyWygl3SZufIOc/Dh7e6dSM2x6t5gdO2r5UKcO8L3LBqOTwTXNDw9EKp8LO0c2JwWjzqcIkYAkJ7gOQuW8N7BrAqJxByv5Eb9gTeS/Fn8qO+pEDrKZGiEeVPKFNAR67JNr4Zb2VB5RIAB6HJSvXRwG2mNOXG17DUjmMa8rwY41N/iejjbJVEgLhuzjLcIb4YWASbzSfNpX52+awVfhNSxBioNWHyeGuXd0kUU3rU3UNZOyVcRockeeLQov5Sqj0CNxMAhB8mt/kxmRrToMCbjgFNTw8GQMXuNc4k46mXoGSOzfMJ1G7NAjNU9avhj0lK1996cFHudefGsc9HU6Ond0gUu2DpHRY3udMIuxozk8+wKTtr3bKXz8EENH7jKrG87PmeY7yrlugScpHRY5P/8ctQWWZjiAIYSoQRoc46F+SLOM5cRKbRDeOnJQmSss8Ze2f3ZZFj4iJK29Yrwp+ou1xKaHD9mis1bwIwhZhzlzcUNOeN3a/DJAPc+eh+gvDNHqv0otRkZ9OdMJj0o6PwL5opg56QZeKMgTD24nP0qI+IuRQL2zFI/sV6sjUTMdQEoFCmwa9uyjEek4G6V6sW4rrsofJZZ1Rum7t/zjwZyyIDEWItG0sFgyKtMeYhXOliS0AXuYk/hUjdJAnHtQoe7UJxjsgHKce/2czPmPALiuojFSHf3bhhoriVQCmZYS0W9TVqMoMi1mOzrQXkPc6iYKasz7UnXUNH0H6xaRrYmBTYFZf1Ekt+Mr7NFAmBYVUJhzXoDImE5QISH+tq/bFJ7w3jrBtQgoc14fPz+ji3/ba2L2ki3EgikBCmabC4lvKnst/KS3M1nbsZPjl399k7ATMGJrdX3Blff6vPbCCYsZtntycM19PQBhbVUJWCh7ji6++gjks07jeBGQfw49ocGD9zvSDjM2jsRXSWYLFJrqIjowV5ob/9Z91oESVExmI23iMTxgZGXWWJzTSXl7FuEsni9B0ZF4O17lcStgXdFPOBypKG/LDTRGuRaHkK/dINdJ1a+LyDoR68XsscdHi3ODDzXJzgW3x2jaRpCC8SMIMgECNFnfs06wo03lY/b3603Cin4Z3E4wqQEW9W/53MZqw8hPDJM/ol/UhvmDNiS2THYlkN1RxjUlUFkmiEByY6h7qzbiEEsBumV7uDy/JTEwhdy9JjHR12q0s3d+6kElst1WHIxt0s3DToMGe18m3wnvIv6FdfvFMiVRY4oD9kzvYEBLUJUXS/gFat7eefNbDgwBhkLMBjBThjoK/EuCPMKuCgNA4OMrha2kNF+YZ6IB7e8nhtYshZwh2HFF52fodjD2tnjj5tCqWM9j0lfUk8znfHTtdDDeFHxTrRpy9+sBzWZ6UmBeO3y5YTItmCnIed53pw7mxOVCZ+00YmyYfBHH9BFQiYwCgcmC+OA8+1BqZgcVBjRh5t6Cm249Hnfbb/DuZKfBcfc+0q2ZfMT+96Qx4zYu4g2itoQ8+6JcDsKkLimvB0GG7dau2ETy5RbP9H9pVnsBc8W0V/suEYAJZEU+oMvaHhXH66AwKi5Pl1Olca3GeGGQv4mMZMEhzVvCf3R/K X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f0967efd-18c0-408e-8f21-08db91eea4ae X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.7101 (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: vc1P//GNgBxNHCPGW2wzd0PahObZiszYcmVDyzRHNrI85THkHZDdivdQdd1iG347 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6320 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105046_313805_7541270E X-CRM114-Status: GOOD ( 13.82 ) 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 Mon Jul 31 17:50:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335346 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 6CC31C04E69 for ; Mon, 31 Jul 2023 17:51:11 +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=UdfEVtwcMtIwzV Z24xVpG1h35TLf9mvInNyCtTAsipDQpx84S3IzSl7dS/IRt0Z9Q8mfTEeylXujyZrG9VMWcPtncgL jA1Wved6p0C9RXDROAjxBIH7WlDq1FxFCibW4gSxjhMmPbPDZ+FuPC/56SbwP2KBqXr13zCYMqbCa GkaxUVM7wy/eTAwHYyIJ907SeEpQq6m/PCQSw6Ljcfb+l+PjzjoCHEjLvM++X56G0x4PDgmjcLNHz 0DimKRdRnOBCDtOdGH+9VHJNhgoeVA+PhOvCVCYC0mNb66gYuYsCRyY+5fJV/hF8gPdBE0h5YCULN XPgK1q6OjQuIfdu+ilow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2w-00Gtwq-0C; Mon, 31 Jul 2023 17:51:06 +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 1qQX2h-00GtZZ-26; Mon, 31 Jul 2023 17:50:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FRwV+ux3ZTHWH4U8dJW+KLmNaNB0VjcVgDzXPkexPW7kyzg45498uCZgeMUgxINxp1B9TBAbAIAQvGfnybl1D22cRin8qfNM6lYBq4lrxb5ygFeX3+dlMGFodOuROAbBDYwBDMLRXP2WJZf6zq6Yz3Qm+UiIE0+Sf1zQyp5o0SXZ0lM1328NA3yGXJqotk7PnDpCDUdQCoxPIuT24iucyJWFWHptXlqP6EgkmG7SKpFnGh9XOqz2iaX0V1ZqV6rItDaJJffgXh5IpdfbtAB88LfDEZNoLQ3KaonO9SEl35+FJqCMI8oIVRDVPi8MjPlOCVGhmVwXf1eiDjajemYILg== 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=GA8E44QRGw4D1VgDRxNvrOKZKkkNYmiQ8iVze25Y9E16svTVn102L2WZWGYqTETg2iYTFBIWY+xIXBdUv5W43WI2cmg7XNQQr/cirXQAm3O8SWNyfB9dtIwXVYDgcNzrjdB7jC4vn3iAcY6z0cK+X/3LLFVCksy3WHQmFFHAj+0xZk6R4/kJqoImZY0tdHYX/Go8mnbw2tOErbP3FyB2t6DrtRCtC8ZrJs45WsQRr9DPDpri8Ypr8ScLdxIcmvC1Mdx4ermbd0V5anmIQW4YvnldqToUEKBtWmyfwTDqgcOdWCYSiaxdAUsoeCNC/z7kaxjsB2kMehxWsmwfnIDwgw== 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=JDMempPnYJc5LHO0+eCUSurKVuBRTTVc4+12fqoZXVKIOqqwrbVuuvsEcipjZQlk1H0Dofq7961I1MXaZL9PkOWr1XsShVZS9KoGgqxrsr9Xq37upx6ch+rf85aNbGwKekmIy8tOrYgSLcuAQl5Oi4sFwvGMtwfM3r+mLYtks57C+V5WF7/Kv93bnaFww0M4EUODH+MwfKYs69+JnXrkESmLSeAiECuczVuqAmJ3RryMbUENHYDolmXfIJ0SmzJmrkkWlarzQ41X2CriBDY2njDEOOKaKnI1qdcqY/s0nZu/zfD9pny9Q4cWn0wMRSdqYjnzYhQIxBDC8pQasPb8Nw== 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 MN0PR12MB6320.namprd12.prod.outlook.com (2603:10b6:208:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:39 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 06/10] iommu/rockchip: Convert to generic_single_device_group() Date: Mon, 31 Jul 2023 14:50:29 -0300 Message-ID: <6-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0085.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::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_|MN0PR12MB6320:EE_ X-MS-Office365-Filtering-Correlation-Id: 745bcb3a-2833-43f1-86c3-08db91eea5d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SOZfZ11q/pG8HXVho72Co31TBrkL+9hq+CSR8jS0EY0w4pYG919iosIXQv6IoYMP3jnlDV06ejq4dR8xW+VI5tUYOeJZAVGNK5Fu51c4H3huvaOkb7mtHCO8M09M0lsfHM6pnxweya+ANNsU5GM/xCuT4wlAxDsQQy+nsdE1phAP99hRHIVZUVmLptYXT+sRAT8S25sqvyUJTOGj3oHjSAFEiTOGaH9jpnHgPu3Xy73++DNm0qnNcV1801O91CjOK2p1vktnE8jK/376a9y0r3436TpJMEQk0qKrryAhS1Nv4gkxsO+GEQJQlJCRPEoxmk084Lx4TvNWQ3rUxXOK90kQFbPef1AeUSNNXihejQU8uwXWZIN4YFw87j4t9SYv6sT9QQUJb28TtVL9C7tt/j5UdDuo8rs+IxOinV9sGGLV0UTTZHM/P9ocxWXCwDrWHkkf7f/WKR9HhOpSDiM+GZdtqd8M2E9p7VuEvTaMiUNgqwGynG5Go9FrPXeMp8uIfRIL+CgsiNu34cdKiU8EH0tCqqS4oRwii09D8U/ND+Bkt2qlk83luNBhpUZL9xTNEmPkLnS3hTcHHfH6/ECqOv1QO1AOvmMaC5aNlvAVZOhjDEQx8auMeY/7M0hAXtxn852MW5i+rTx7SgJG5Y9yuw== 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)(376002)(346002)(366004)(39860400002)(396003)(451199021)(478600001)(38100700002)(921005)(86362001)(6512007)(36756003)(6486002)(6666004)(2616005)(186003)(8676002)(26005)(8936002)(6506007)(5660300002)(4326008)(2906002)(66476007)(66946007)(66556008)(41300700001)(54906003)(110136005)(316002)(7416002)(83380400001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SlMRSOqnqQ1IO7YhYhw13Xg/dMhEjITfXrcrwChhGbYjK0ai+tioN7ASndMwdv2/MBErX4Xvi6xtemUxL+BLBUgtSDTujxcc9ia2Xa7XNFSJX78FBAaG/mFy7R+3bT0NzzmSYTM/LdSc6G9/qlMNGr9+JCiJxoV22RGaHFTLBdYH/h61tAiQ7pwwNAUX7xD/2NqQyvMjg/yF921uVtzHD2evUemogiH96EJmzKODYMsmNYKIHyzM5n9mzGuKqvtTHzlnPcbHMVbQSxIUB7lu3ZvuyqW+gk2CNwZls55Megr2+QwzNqTu8GgsqgmOkKylw0q3vm77vWVzQj0rzMC8eFM1tobE/CMVOMdbhSX4eUcbUh1tq2X60rPQ2eUDlJqsRHE/S9F4UfF1fwOBEPBto9sswPuI21DaFP2URChxW57d4H4hW1ieODG46SxYPmuYkCDDDTaYmwEll2Hxj9ll6k2nQwiUOtb1wlAFMLVQYTIqHDbgYAP57Vl/94Oklh3fqUj1dE5yjvFpoSnpBrwPAm5iLrk7AnsRhro7nf+siYs6jpLzJ+TEPaXkVbVVrjXeXu6+tP/nyAd/YZQOPT5HQd+l+53hLiYhX5SqjuZTSQw9qc6eQd1x4PkObJstrwgppYrfTix0jNtLYk3cEBQX7sM2L/wBPLzWMuOp44n703dn++IWWWsSlR9N+e1K+lLpkKnOgkOFAWAB2o+9tVqck+t7xbuJIsHKyaRs3Af2wmcQrFeHHZL1p3QiCKCiA6YZDgN4DHNosXcb9tuWHIvgK+2IQfFG3QCMlv2OZVyrGAC+hCZyKMcRh82O4tOlsxyLI0rLn9nWqZQCItER+Nz1JKhpXj8FVKLoDBOb9hprP4D9JyawxEoOUYe03G7FBrXbJ3bjxbqMgjGcv0RTVVwGSxjagFAzuDKCJZ/fH2OSbZSEDA/fd4qmXxWK+x3SvphvEN0GsXq7FH8Ptom4ub6IHJg1kxwE4pDsMebSeVuC5SNEvff9tkQyJn6M08SZ7JCX6NTZjoUHtN8gPLvfqr4qa8HhZLgjToFkZ8M0u1/haNrCLufF7uIANem2R73mG0U+bKFeA9eRa8LFQJS2PyuvMeyPpl0tgUUHVDkVENL/g/aqkxz8tnCi6pkvBqOzZxkimyTT9Sr8dm7Zxgg6aQyXhbze33r1AsWZkK1AY3JKhNdeKkLgoDGd+FucqyAY3dQE4VW8lI6hfmk50Qd0CqOZ9cYxVthwBhIdzfti0kiJ5wPMnrJEWkst+C64itX+BhbSyfEYf1RQeL1DzCaRbSaXKuEF/kSSfIWFl+Ef5HlhmclagVBzl/rhFKINw88Eg7WU/ApsfhVLjRUNGH2BHZrgjEodesJZ8E/hc9PWF2sw/jCTSBzZx77ZvU6fXSvWm+dM2EeedKGKkPYDYxrGekzsVR49vW2E2AYfUUe93hoTH+oeA0H0xWHwq59vlh+/KHDl6Pa6axjv7vvof39XAHBuBGhOyVGZ8SXDGHFvVCuQx7GcjISPCpONNZXSqHLAF97FIHUdJpYxvCgv6GmX5lBoEMMCMiqeHuJoLe1qcTRCp0TbjH4wa9X6+JFt/dBgGUah X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 745bcb3a-2833-43f1-86c3-08db91eea5d8 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:37.5274 (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: pu7FQ1dVHes6exME9Tzmxj/GxPcZIKf1YL2w9eE2+HZe/bcxA16Iu0I4j0KNVgAd X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6320 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105051_716536_0D737B0E X-CRM114-Status: GOOD ( 14.49 ) 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 Tested-by: Marek Szyprowski --- 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 Mon Jul 31 17:50:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335340 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 B2716C04A94 for ; Mon, 31 Jul 2023 17:51:03 +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=ddqAImrVoWsoCZ 9ci/67Rm5FQt1U2lacmPP5bTykqmnSGSq2L/ShNq4C24ZL1NtdDgRDPZ0mWfWTuXhIPgQCnrqQ4Z1 AduDTwgTXoaGVZc8EtRPqf3Ulfdwp6FyEtYfbKF5fnkgcFF50z9TBksl7H0v+ppMr4KgOYHsVl1Y/ p3iUHP93F8PtsNIelYDZx1n0hIPlyS8MD4TBgK1tcE4T818Ao1S/ns+DnM3n0I20OgP0kj8Z/cr2U MDifiJndMIxusI+JndkeYnorGaTvZEVYEp+Zgat01UAgE+NvNwfi/TGhtI96GHQX8oaJUm1gq+rJm ttt7VZglS4G99TcSwQWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2p-00Gtom-0X; Mon, 31 Jul 2023 17:50:59 +0000 Received: from mail-bn8nam12on20618.outbound.protection.outlook.com ([2a01:111:f400:fe5b::618] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2b-00GtYt-0Q; Mon, 31 Jul 2023 17:50:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NDXmMHnJqqDlNJzodEanOZoRM0kCpwJBVFhcMwDz4HvCvuCTiHGEuSGM4LTsBucSChocURErZFs6+RdU9mgo6aSZBZbf3JEi1wIWO3VmMhLPXb2igN19wrltJ2B5xoonEXxFQvYdFzTa8QjvPHj6k86lQ8ceGz5Lb+rIRcmur0H3P/yafNykGtlmqIHMUFoLMYOmegROwQrI/qgS/sjd2qLZDTUHvWpSV892S1UNGblbc764DGeUuxcmDIuODLMqOveCFIm5hAjMNBmGPf2HTPMIl9FtuRt3TqsdY6DtU5hS14sAkineAFzw9tfPASAsFvRy0Av/GaYMYHOY8BvLQA== 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=OwbALvmWVNAu72IHRgr1HZ/yxIHHLHw3bululBMvay8top3F8RCGjtdrHP3yp1k+6WFwWVNAriKeat1CBS4OvrgNurYOimL31PfeGvTZhNCgWNhvDfZ9fsKFIOm7HvkvBiBv/zpLcjaSCwVeJZOVISAik3paJEnc+l+uciq5Q9WBl+iqEZ/vYnbiU1tCZ8GtFsBzuUD6feyNTThQ0AK9xUZBf+1QJvGyGLPUoPls+iCvBvJlGDNIAYaoau9AMv4Jp+5MAqqIX7CZFK5mlSCAPvYMTV4KoKNF4ISi4fKhY89pMKO5hO7VMxzv/tAbensc97HVFm1lMmy8rBCx5SiAbQ== 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=AqXyF/y89Zwce+TDk0giA5nNr8N5KIBk9Ng4Gv9LroF8Tfk8dEAajVooOIR9YQ7txfJKVh2+L0JnGp4//sZGAx0StqwAmIbGSGvRETxaq8ppqL3yK0xPRytm8bEkGTBPfyBLH/CFXEdYf2dFvAd5Gdvyr87geYZskjPiodVxDR9dnhV4GM+/xENAI4Y7N3TZWsQPJYVMPXi1ZzZFmPMMrA45GiqBE5poQoo7t/5lUfLmu9QpWDlRPHh5tIavzQkks9NDONqz6ItuCSJDINZwEsZ1uXa43MCIfvceL1nOVUqcTj//6pRh7Uzidu4cklGaa/OnD4kh3HpDLLsMgkFo0w== 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 SJ0PR12MB6992.namprd12.prod.outlook.com (2603:10b6:a03:483::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:36 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:36 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 07/10] iommu/ipmmu-vmsa: Convert to generic_single_device_group() Date: Mon, 31 Jul 2023 14:50:30 -0300 Message-ID: <7-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT4P288CA0044.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:d3::26) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SJ0PR12MB6992:EE_ X-MS-Office365-Filtering-Correlation-Id: 76b5cf4a-7d74-410a-f741-08db91eea472 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Y4np+zfeE4m8pervQMr+s8lgiNcQ2bRp85ajSw3pT0E0BIuXt/KwOG1kTIWVCtHW084IOzc5hYn2kAHNSwk4aniRZK0Qx8oBYDbOS6xDffcloSDNzHAiY03UCRUg2s/ud9alrLCao8nxGietqviRvtxbQ70oBSVYEr4sYfT0bvHW8mYYJ/2PtPtiZY+AUXfCJy3Y6hSMJ0HybHkAEBlrz5DG3Zl1N+38izqRycOISjM5t/X8On/loBKwdg8ZiY4JiAzj62/kmhk0sH1xW8TAsjiNLAPmw9tNhm/uVOuULqPp74adFGmFHvomszFWa0RG7jwCeu4QBiALlmstvg4EJ1xlSAObr1bXVh/pAQ1ZxaaN1ncsqip1F6kKbvUuJYRtV/MJi6gcooBKPxsGrLBLX6YdG5+uVlL7C/+uQkpQnyYFaByL04NiREnOt0q55A2lejseoMmZRrmeQlybrScOewnP6KAmFN/YQA1M3PwTSClQMcoa8Hm563dq8UeTAT19SqbvIAicCbtVOMJPWioXiiHOhMsoNqjTVGZk5A4j1+RPV5KPLJGc6N0cTP4D2UZyWNmiUH6Y1RfWqVnR5jW3wuNPXtWknVqBhv2cdRnoGpLBk3HLI580sEyn5nNLa2kcpBPuvGUWwnMrOJWOF/YWoA== 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)(366004)(376002)(136003)(396003)(451199021)(6512007)(6486002)(36756003)(2616005)(6506007)(26005)(83380400001)(186003)(66946007)(66556008)(7416002)(54906003)(41300700001)(921005)(110136005)(38100700002)(66476007)(86362001)(316002)(5660300002)(4326008)(8676002)(8936002)(2906002)(6666004)(478600001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O5TyRPmq9x6kEAPO2ljJsnaQa7SbJ20597/xs3b2YF7yZQHwMjV+bXNVGObiXi5IpDZhQp1M1yz+w1fWAP3sSe6XiThx8cYRfc9XxjZYXQFgbKgLo/tR00510osNM+v30D8o6+TqaXqN17VLsWpyGC2OvQigHaA5ipheXd802uOCGUSH17jV23Xh2meSROcs+Q1SM2siEAyqqPl9Oe544bNONpTVHNm7ZQcVgLgaHC+OVQtUFobOSf3NZMRr5OQwz2K/dk3yPh7KiCvjDr2HDUbkwxyOKQddCS+Tfq8PFvsvAkhEbC53BfMg7jXLoqZc2iiFQssaKkxsuyuBjee8jvQJP/gEOzfpSElDTXA2zbQuhznYLkBljpMi5UMs2+lL9V9raQ1Ta/sInNCNSvDjJIT1kokWfUn387ZvKKTAXjiKS9/Mic4137weROnEgHctRliggQobmJQnNak7dpqFE5WfMco+HoW8q6R3tdeYO9eG16dK/BqOiMWDkxKg+BCPeUvK5Lj72NFULUVWBqTc4gYToPJ+PTdYe3/z+CX576iiYxSu/ocEv0Joof3wzglNnvUPOip8cVNwev0eYgHg3sIybADoMnPDbJtdpgdTW/QsnPDZJECmXyEip+S7lZvxStGq8s9/zO6DP4I2fK+ZiOjEAXjP8KeM40IRgJf+BLSxhtiC6QVekuOdqjxRf4GSpGzHrHbkmgKBUYnU13h5N4I/Kpw1vxePmKi2xFErwBdo1HpzEiecEkFzNPzGRM46eKxC52mWdj1xT5FyTWzQo1q0ZeRPGzx6wusAu3pyIYYoYgRd9oLDdbN3U3EpGSXbFkMj/mGYntXS0EhNjoO3tq8jIugwRIGPUMyLRMXsUZd5UJexc8I2x4BtUqAjP8Kq+THnjZ4QWz3aE57xWLmd1rEglHv/CWt+K20NOjlx6uiJms2eVlQADXpqPkLatXvNKGYWtAWiyGsw8a3AEoAS8rMN53iJpvH6wRNBUZNpAbyS02o+RIM0J6n4rbtGTagIoPlypWxXU8pCeNsFukUjGehCDXXTeABkmNL3tLGqhiws73VYboQ91wJ6rAQBLrT5H4jIsOiWtbvg0Ib5FT3fKloUfNpFKBzsfYy8ge9p+988wG1fIFvl/yXvZoeXD/kNcoXTr1Ram/T0ol0E9LpSOHGYLexqSJouYtLN2rfQU7S4qPRWDfPjblpWplrVyR57+ausfgaWa28Hj5oT0bDDBe6Ipi2dgEmhPmsBpx2Ru+yY4TSGJdrWp0YWuigZgRYEI5bSgWkzEaanCcI7vT/RQCKeodsXAIDskqnRRIqvNyMxgLcIPRpxLCFRVKtjGEQvHad3kJLRxFvjiFWZDkm2zNdnrOIEbQ68oh7pu8yDpmOrlpeWfhJSMw5BL33ruWl0X/3acsmbLsshwbF7UyiUwZaB3kVSKWZ/tOtYwZ/3prAKU/YojAz+AUjHn6axkifGn4bnUH/FqpgBwvdGvUVCGOg2F+27XGi4foG9nRLizTZ2Mu3B5dgjhaK0Mqf2OuCMDxJFp2ox0zIgNGtr60cA0Zgp/TAX+yr1NT78XEGQ/m/pb8Gc+amcfqNuDoX9L41K X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76b5cf4a-7d74-410a-f741-08db91eea472 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.1718 (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: lBWBj/L5M1ar2RuiBbOlVHqza4Cca3/GyZ2IbxIxRNS/3RQBjpVEkYpziakmFqdv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6992 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105045_224266_38821A5A X-CRM114-Status: GOOD ( 12.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 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 Mon Jul 31 17:50:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335339 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 D9504C001E0 for ; Mon, 31 Jul 2023 17:51:02 +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=b+cRqDRd0lg++0 47BmiP3/UeMDYO+QyNwljLuN6LOYukkvNOZGi888UxP8OkplQ98wZrR6jOVcmhkVCgwFaDRukK6Tn 9+YaeOiE6XGJJAMzmNMBDPyMgZdKJah7jzPEnIckQ51HvJNa7OI3aTW3maIB+Pm1nMXmczSnn9rUC LiKUQZxiqoJ7SnRKE9rT9AdS0s/6/85zNDyURyimJeDmod+6uEMO61/+QId1YNEMM2msU4pL+5nUC th4j/U7Hbon2RB2/PT5OgVrW2i4V0VJAvjdWE9jONmTI1Ii6HYpWijlCNIogBEAFsG+NiD1HoxYmu WcZEXRacjOCimga2vtCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2n-00Gtmf-0l; Mon, 31 Jul 2023 17:50:57 +0000 Received: from mail-dm6nam10on2062d.outbound.protection.outlook.com ([2a01:111:f400:7e88::62d] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2Z-00GtYu-28; Mon, 31 Jul 2023 17:50:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QfD108AiJdAsLzSu4vKnd0+b7pZH3QbmwuTsr7hhRpfHyLnGw5dN4p6iAy0635wP7XXjMhH2IpcWyGHd9vdvqLBCqTkMzV8zFqzVkuC6z53Frxp+qezbMObEq7KGASAIPxCdjCvoax7cFjRxBKJN7j/jftFx3GjpvRiC8CtVYE9nIBxoMdgban/Wl9Q7Y036pfyoa8H9dMScLkR6L3AQsgk1cSGOlaUM8Ye6CPaiAXW6sK7HWkEw4K9h33GqkyfNt7+Ia1Kqvtcq7BA0OPnThAG31efkbtIJZWBvBXFBNnXhVYFbgusctaBsa5wQ1a8gbnRzvSJG58RjoNzwep3AnQ== 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=b+1NsdXAPsJ9be9aHVTvK0vEdttDTlymuQAR40YnFdUlGG79T7dKDkuqQ4tgnLch8QL/2h4JzX9NIShbolJJ62NMqGZwb9t9yx4aq6LRtzcfjRG/9rT9yZGYt8cCwZXZVlQUEiFFKaRCSfgea9mGRBcJu9FDPU5TwsybgFYNgCt70kGMQGBqhnuU5S76XILJ2LXCD3YUzTV7U8FSEEw/RwD3qHIYh6umG3va2Y4AxCk8pEMwE8KiizmzlGS7o3EXtwBNvHPhyvJIDFFa1SwZiMGslAqpA/7vdTIx22D0VFsG8wv+mMs/MfAIVOb1N34Rw4RocKrXC4DPCmwejaBgzQ== 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=EIduvNwv52kq0QdRbl0HVMfs6HhHoUzgD5Ona5UHBNWKhmyi+/zmTNbFXGs+zDwGwIJ6Du1vJomEFyI8dmMQx91U5LAuRtql9/ZytQtDqGJv7Y7G2IIBDa3Id40qlD20j1TrKoKes4XdzSG2+vEP5+IFZCrF22eDGAhPEoIZAgFVwoGt0nFto7gIhv2cl/tTqDbRHL6wcTRhRC9oGCiEUwiCXvu3Ety4Ax/QRoHZGdTVK5lepYjYotq/QuP/qBWyq/G3TVqwmbO+LkVcQdGVr5Zij4H3LDxEOUL30Kl4Kdx2m9+ONJMKkrfKLLCEz2qn4FG9GyVGgFoigU+ky/ZAhg== 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 PH8PR12MB6937.namprd12.prod.outlook.com (2603:10b6:510:1bc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.42; Mon, 31 Jul 2023 17:50:35 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:35 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 08/10] iommu/omap: Convert to generic_single_device_group() Date: Mon, 31 Jul 2023 14:50:31 -0300 Message-ID: <8-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT4P288CA0031.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:d3::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_|PH8PR12MB6937:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a10c20f-d063-4b44-35a9-08db91eea44f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vJjOVy3TE0lFVDf02U97m9rb+6YxB/BPm8LNE/RWa59h8RjjjepXhKmbqZOYk50v33SNgb4jsdkggQ7uZOjB2KBSlClniJQDimtWwuKfiJFBalaBkW2DyPl6V2qnHaNbiloFjLmxDPVYRelQco1r8x6WJvClikIeli+k/Fcjs7XzKs49RKj5Bgmn7FR7ufJofUsHl7wO6koC9/zz0+PBmU47GVJc6TxGT9cGP1nMPyS1gZfcJMoNGD6NyBaqGiCNvk6cM6sIEeFrBSuai14H6+Sx5IdB3DoCDzU7z2j8e0/mB8ukWCjypLkNXdMAO7Jz7sF3ErTqpzD1AW/SXIiXxvd0LrBotWFyv0Bv9R4HJFbnXJpkL2PH9uthNLWJI8HBCxSmmdBbwOVdo0h7fWoufusSFbzjGdwrPfcOsxoEkwxUtzMqMAppAdzrfo98csV71/9ccnPB03H5KELU4thkDgRBQtf9p+xtO/9FIvPsmTdgUCwyhNkgGB3U4VTCZxUYOk8K38Ob/byy5U3sLTrCgnIYQIyhzfLbdZa4rFmyHcscb+uKuPerG9FpBw7ev50P6toFnSosq74yeGXstL2TKVaRzsUhlokwgoGo6k3STP4bCXxCB2IQvzOjQXry+f91svB1GpbBM+e9qZSXd49/Cw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(39860400002)(346002)(376002)(136003)(396003)(451199021)(6512007)(6486002)(36756003)(2616005)(26005)(6506007)(83380400001)(186003)(66946007)(66556008)(7416002)(38100700002)(41300700001)(921005)(54906003)(110136005)(86362001)(66476007)(316002)(4326008)(5660300002)(8936002)(8676002)(2906002)(6666004)(478600001)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: f+Xgo53rVl3wV3bI2FRmT8qhO4HK4b5lnOS4vwmoBa10ADSaA+1FWHDHPhPU0vI246LJ/kmJKytWIahcW7GYxLpOxlSGUqn3u15qy9wMLKV0OmkcC5WbJ3wjQIXYENeQrya56rb3cimsV/oVuhZnPyU4tNYSnB16DU0sPvswDHPMj3aYDVnUfijQSDZ64paCYJ8CFzPzoGGXe+S5j8IkTzQ9Ql0v8Z0GbLp+scQiXWwzV8rMp/9ARiuhUp8TV+IxSIDs04x+9Of+R46UqftH2dHeZfxpQ4DD0ww18m8mAlwxynSvcP5tD3dcjjHsFnazaulTtkeadCCxW3+qyk4w4WinFUXhM9x2h71yCDPAOSrZxKz7SIDDybiuiPjnXYaPBncPRl8PUfPYAfQhKhuV9jkve1dvvMhanVuSQrGkdVnP/jsWc8zzrhji3c3nJQskTbJf1r7CG3Z7QKmrDcOL12WFRBLnCXaZHXtkbz+jrf3NRwrfAlD1zRwPjg/DPB02vIwnSkwC/vz3iEj7Yq9ofj/ZwGGE7XSghXOkrf60WfUpNB25A8Y+hwqw2zqPl6IFs2bXRLsSg8x7rtpmV+8E/Pidb1YFkWtxedmj17Bf/rpzKlq2FwM42KAZHpZegdkoJw84aIsCJiX1i4HDl7nq7mZyw3FYJy2bu5URFjHOa07HJZoocY3JrocXODeHL+6G4sGYRw16k/lt+ivKu5OH2BDPSpr97sH1IHS7LBled4Ca1TFX36a4vb/xZ0g5q2nyp8s+mCWbo+XfWWWenIJS+93KKOqnSYr9kbI0fwlxXuCd0nZMHQUBmengWttl8SD98omGcXFW0acdQkObtxE5HZm1cnQ1UJJVRGbEfKXCnhPchMZzxtgD8Xzj8FTLBJX0qb6sKTCHGDIvQbfsAAdEsyk54Wb8Q31qr/7VfDn4dSnTW6I4FrJ3JfhzV0dB/oNrYnvKODwOk8FoPFbuOVsiOhTUSOro2eUmAqBMJQpn6pl3WDe8EblexA5twwf5sbTrb2myW2U37/WcHuI0+JFxf4FLDiC1DZ3femPA3njXua+DWv73YMfAR2Stp/NIULOaf3P/ZxFK01Aabb7GLosRSip3uiJKW92CukXPoMOTILsK3UrZJpRaAUHHaWjXrtf6IseWMYxC/uzO5BXTu5I3dOSrAESOMUome4QVGuFHP2sqr9xdZpJnxGi/NoqPuCXOu9xGzY6YG50on/qKqMheYiryMUfNZchWzA6S6nQTCUY+GdaZE5iZjtINc2g7effVDPaq9K0KPP6YFukr4dbvOyYPb2v5/ItZ/a6Qc7O/9wDTFJt7idYHxQpoNIOmzj2pNoNTa4Jj1mFlf5QH7NE0sfPe1MffXZs7Szh5dboBetmPSTBMtGNstojENj12vDpkxlzqY2PShxXaWNcycqMYsJpmSfeaxw2TakN31uoXl8u3ZgrD9+ZVn60EAId/SiOAhoZayPDOUTowuOdGIpxux0yPCKZWg6JPA4STJSnB0aw/loJa72FtSuKlXqCIpTgIUycaVy0CV+fAja+r7508wuwp/6vAAFw8IsKfwVAyKEfQYEgrxAyqp+juy+AKYNj0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a10c20f-d063-4b44-35a9-08db91eea44f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:34.9784 (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: hZe7r22PHNjj0DtMCW6ZMxxT9NuSeQfoMe6inbG7iEUaaxxU+MoxXJVaJSoEzcXK X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6937 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105043_703132_60C754DC X-CRM114-Status: GOOD ( 15.26 ) 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 Mon Jul 31 17:50:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335347 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 6BFC4C001DE for ; Mon, 31 Jul 2023 17:51:14 +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=BFSsuyBBym1Shp0mtLr3ZDJarnHo0aO9ueOl2kI9Sew=; b=eXJHaaBR2xMo0+ 2Ai9pcnG0r+uYmLvpOp7eOThXjN5zwmQQbIrGhGVTxSUKiR5ZwC6eX4cjU4XaZKxaotGXLB7rPkbV WuOuRal4fMBmu31Ktebu4BfPC3I441X6LZWTcuQllLWUu3hFGSS1869dPW13/tYmm+dwCdEfxhJBK 9MvL9KXmarDsbp7/HXO+otOzP1TtWr1NZNnBI92SmpSp4MBW6Io3Ug9a85eTrzCh8sAhkzh9tuFUx 4Z9jvRuYDKAlAlFZbCmuxgSQqNN5i4euuu8vmaGFV93A94HFp4zQPlDLniLS5ytxdFcXZBhcSkxF6 5U5ORf0yPQWW7ATH+UsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2u-00GtvE-2S; Mon, 31 Jul 2023 17:51:04 +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 1qQX2f-00GtZZ-1j; Mon, 31 Jul 2023 17:50:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qpz43rVbO1Wrd94DRTk++oKEfII4fQybdKhBi7ryg1tmYH7W2UTDjiXk0nm83bJBfQ5MPJBaBO4AyJ4WtQtBL3/7FORC0zmFC6HGWfCd30c1uaIKjFTwZYeEBXyInkEuNUM4rO0nSrXwAQpyTaGctDUoN0wLJdkezFHHcsnobTegYBkYJnx2QKEtVh+ODcrfxXcm7bwI4bhug85QMlfQY7KBN5pdo1Hq/4w6+9EcvvuR4mAc2ZfjC7km6n3seXtoiUG8UUz+EJjKOGgDf7ouUva9j0ndh1eNxbQA9373enHagc3/rP5dD7sKkVbzea4hkbyGqhLbNvtV/ydz8nr2uw== 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=fm5LUa3xn01J65w1U0t9fA9MeZit4npwSMlbpQZiOng=; b=CcU5igDD078g45AuVtwRxUGo2NdjkChIPmj6b0XHhosNeFvKJDwzXzFmRzYEq7HEt3IVa78dMHeJ2RIj+rc5z+fyYha8pqFhBeiB6fCGn6CUyFdYRjZ2zB2QDdP50FMhckIsrLc7KnxUWq4B/xqlb/02wiwhI8w7Rs6EXinIb0JjbI3B+tPZpBLKkdvvMRwLSVgfN3BCEQ7LBupVw3wMDE290FMAXTItsyPvs9InbA8JscYVSASrXSJmWntz+ZhCdPLoVHtP8Y/r3rSPjQ+yixA3iPyxGyQpaM+yX9kWwG7zKiyWHp5gTy9D44iUZWl9rXran+lSsjakrPgqWfdjpA== 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=fm5LUa3xn01J65w1U0t9fA9MeZit4npwSMlbpQZiOng=; b=FkiaZvM5Bb4nt9MmnBZdslMPn29F/I2X6mp2ssawrd8Qn7m0YHZLfJJYCfXyC8FZGUOLn1tV5/j7EEu42PhFiIhNLT6HyZac7Dhveo4E9Usd4+U6Vx21XyuGzDU9LpkUZmJeOeQW1Ie/qYPuaFkSMZeXhfeuz1KLmADhCjxg9yVLaiXwHv0ms0LrXwph5sX7DYvxmAQfuHkNIX6z5WywELJtFIDU2GRAJWG/a4yK3UfDJiWY1AeZT/5wgBsJIkDkVMTqSo0bKE24RCr1YVroyNQ4vYlIFjJUrJkJvyhX8BoErK79/EHHvbXfk8Y2VDG+8HsqlYL5I4Bqs1qUWh95mQ== 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 MN0PR12MB6320.namprd12.prod.outlook.com (2603:10b6:208:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:38 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 09/10] iommu: Complete the locking for dev->iommu_group Date: Mon, 31 Jul 2023 14:50:32 -0300 Message-ID: <9-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT3PR01CA0024.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:86::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_|MN0PR12MB6320:EE_ X-MS-Office365-Filtering-Correlation-Id: fe7a23c6-3802-4c48-f15d-08db91eea4b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9wDEBdukX5jtVQV3mPcGunXxOJBLAenAVUwkC43Qdmf1UBP+CBBpvnyv1k4Tam+KqnFCTLTNGL0yGjl75SLAYJdWuURtrEKnoS4EJydZkTifRpwzOB3/cXH/DUU3rir/v95tdJtIPnVMrQSINq2ZTw38Qa8kZmnfVsVMCaQPz1QuV7fZMm+CsGJlqQCA66l3k8WhKj0QTJXOxpHrWzAY+O/JSBJ3gwLtrCemuR7/vFGUsUlzeoPBo4xf8DUhQkGmIYvjVEcdyWTnpRc7vPERdbdLyqAj/4Ts6z4iVFRmE5rf76d+dQ4o4VhSppsVoMh2OI1SwqSqPZNXOPFCqYBXB5BEkU+vStoZeVVltM5Qs9nnpJvGsdbozUckhE1oIDzNkZc50O5g2R6wWk01addWfNniw9Hhb9AKZaejLxI1ua18bYydqx7rPFIZIjOTgRXFuyyIU5YQa7B+7QRU8OnqDzJuhUAjRvkBokvZaTHn7Esd5iJlPmgD1wfgtKDeo8kZv8pudB4PTWCLyUKFLmE5aen6Aiw66SHW5tBi9go4zjgHgZrredEv7EMBVDYoqklUIjfsPHWTi7zPohvsD89HgDZkAOIB88x6TShC8ZPCXnEMUMahoeN6i0Xcq7T4sfpr 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)(376002)(346002)(366004)(39860400002)(396003)(451199021)(478600001)(38100700002)(921005)(86362001)(6512007)(36756003)(6486002)(6666004)(2616005)(186003)(8676002)(26005)(8936002)(6506007)(5660300002)(4326008)(2906002)(66476007)(66946007)(66556008)(41300700001)(54906003)(110136005)(316002)(7416002)(83380400001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: to8OFne8zeVOfOtcKLMm8Z0aXjCkU1s+F8FkvF5npNUDezqdxvskjqzUSIKQfUl8Hce1cWRFlWkWhOVamOWK+u+R6FWv0SGwbeTYcGB7N1ukHKx1zLZ0LvW4re8CRM2TTMQfUE4J2AgrqIDb18wjVQsrX3YmmokXOZwF91Z4ivhSzCrlCB+bsSEMBoveCl42GIV7/+3FQ+OpRM04/B3fya19TgEmO1hUxHyf+agxv7fGZykkcuqZ8BFq13zbsGSn9zA+hZkaSB+pIUfbkAdWJ4caci3KsutQofyCyOG05RiMTv9tL3WV0UuszGPn+FwpOFyk3eCjRP0pZY6N9mVJV2m70i6UvHQtotYqLeG5N3UwnEmUVEpqRg/PKX7ncr/2xgBcQNg+5j5pbeYU+FG4Vu/e9GHGTxF946hFnVpAZLWUMX2HroknJtNMIG9Os+2FDO+hpwq7832L6RznCgw+1oTu1XpZ2MW7NIIHPGtmb5ZX1yKSeZL0IjxHZ/XtuP7LSW6IsR7MWnPjLF3mLqUqrrc+DeBfJCYxqTLm0/N4PQqSkbEJ5Y+gqeMRUSvWCVTX6wwra6atiCA+g9MiCyJPPCxdyO9CyjUJAM61KyI3qCY15EDsNQPooruQl5oYQsiO40gf5uGbgs8bZB9lw0B2xT8U/Q1FwxrCmxQI/Sa+KIYKX6gWoeVcScIy+KODHVjywmoY6peLLvaE3MZ6A2E6zoO5attJ/Wgm2kbfB7Fan6QWvDblIVsT/LC9ns0oqtzI+IzdKfAWFhLN0jYo+Vjj+vDGZBsR2QT/kO4wJgbJMsmHAJg/iar3xDlQUXqRZsebUJB9end8EP2Wb5SiJgM57UiBs9WwcIcMqafcFpWusUAFU8VFIoralCPQZCFGfqyK4CS2A/5Bx7B8SKDdkfnd9yZpd2AbUKaBfyE/8wq9CEPh8doLyriA7buSK92xIcx0eFSyZJ4gQa51keeXawyTt9rGT+jHzUtOzYq8yczgJ2yrfPZkCoCRGqkxNcuVSaLAGLH8oxDP6Ay87TVMzBi142D4tqr76uiUMUGZTZy1tsQBVemJSOiAnwgKmnYj9XtpcSvTyyKjX6upv8pRSeTvj+nOldGXmX4ImbtxtIsRl/WbQ1MWwNmxFFJ5fTX7hveFjB57lVepKmOlwSYBJnJKajlDkDPRVmH+G7eBQXhdhxPrqxHOJ37QHOqCt6g8oxt9ewIortZRo7d2kOPG0Jsu26IYv7ZXKwcitLFs6D14rcIjUA+QQ+UHskc4DB951uxhI/dTFN7VltMHr0uZrpvMvWS5R/659hvgfzgN1z8eDHx74xyBAtQVPer6p2e6trx9eaYccHaRDuJCm08Swce5+dAwFxhp1pO8tzsVx5gdXhI5A4Xuf1EVrvjcN3tuoief90Hb+XJm48wZiEggqP2aWgOyhactXhKTHN/AzE8WQIR/M3UjX24mfxd6cZcD6npxoR3rPaY7Tv49z2j0zGM2j+EmRA//pm8DSmWxFlvqA5VL+49NhWK54J0RulkbMuCl/zKSKNGRq7u6anVYyCuLE1f89Kif3RZOuxDyuWWDiuFHBYRAlApC/9w7MgXChNFw X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe7a23c6-3802-4c48-f15d-08db91eea4b0 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:35.8145 (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: qyCMO4SFyqgVyr/FiCsnAuf9EIjuk1vjoMyGLFkOEEw8wggo7KdZshhdQ07txvEV X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6320 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105049_581570_A1A80106 X-CRM114-Status: GOOD ( 27.71 ) 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(). Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- 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 c673d021d367e4..7dbbcffac21930 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -370,14 +370,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); @@ -435,7 +438,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); } @@ -450,13 +455,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) { @@ -502,7 +505,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); @@ -517,8 +520,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; } @@ -567,6 +569,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) @@ -591,14 +594,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) @@ -1081,6 +1093,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); @@ -1142,9 +1156,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; @@ -1152,6 +1169,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); @@ -1165,14 +1183,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 Mon Jul 31 17:50:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13335348 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 2F29EC00528 for ; Mon, 31 Jul 2023 17:51:15 +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=y+4m98AyYdbU44qhLRwp+tOQggFZwr45EO0wBZB+6JM=; b=z/mnoiUY3F5hXT GEa4IhwpFkydj3i0DLCTaORILxZ4tneo/a9pSCr3VbrSkLtKJ015sT/LLpXKs44zPOIfhqEPy2qCw 0Tr87i8fpVYLjEQN8dGVxriKlwFJPl6xBf4pZmmHETUUdgg+k7qFQc5l3cn6LsVVX/eWXbQ7uElZ7 6k2AVxcgvHM5guBhHz1dXgBf3NAr2m6HyxlPdTT3l9QbVPXafC2LBhqCPRy7PIYkDpxKp/O+53vKw MhX/7zmACDK6S5LTQLmEq9HE+f0vI+wpnIrYdp0Ct2XBVeN3vhZd2lj8+gQRMWoUFxJUiNGhT215Z kYluu5ThounHh0UOeSig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQX2s-00GtsU-1k; Mon, 31 Jul 2023 17:51:02 +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 1qQX2d-00GtZZ-2V; Mon, 31 Jul 2023 17:50:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D067OVg3NN2lP1o5V/UMdEQqjZyt2KwAGaBA1x2FwwzzW2u6ifvvGC/+jS2CosIcLI57rxZ+dbMQWarqBiWtf84TPjQbeQ+wv16ubU/nqlDW2/jIMaEdN5XpfWveCe4EDtgEfiLKzJ9DOmpVi+jrTBqsvXdcn4sG2nVAMeeGdeoLPo03CTOiNS0xoITjoSODyhTgCAaIDGxIVbya5Z/uGkgy2MpvoyPrauTETE53yjE4qk59xEMfsg2qCdvJfi0DVpErARqnUgeRPicXQBBGgWZFHgoCfU9L4J/GDBYSqlvu0Y5L1/k1gnSzmdclZ6/3ZUqmz2XUpCBne6WqEmj/dg== 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=oKa3MByOgnOA1c0jfesSBHrkwAfoQyALjze5rwFRISM=; b=VEZBVlACZEg6RrbMLdMmKwpvbfcDZLyCfHJ1C4uywXIg4a8PonLFrVccKPhcUZU8YbBJOSF3t4b2iPXSosqMNZGp+UyrUGjaso7Hn6XPJ4UcWFY5AQpXEAfxWiaQOv0eHVp/3kTlZGw+dtTjUTtKmgKFPOp+laG127/hN6Jl/mGIcWlFVYLbSetM6xSmB0V7v8jhKKplk3pWS+zCBsxLxnyqwiRiY57o8Sfx7VKqhpgBHbtiuoOEZskZIYnD1VuBWFCZqwrluyXSmNe79uZ3+wSxehPnzSKS8zyAOwHrxMta71AJBwZmeWn0s+ITpfzEOllwpI5hV6rMzsTd2FU4Sw== 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=oKa3MByOgnOA1c0jfesSBHrkwAfoQyALjze5rwFRISM=; b=hCSScOCITSYYqjtTmDx2bEb9f7vUxC9GEUWe7/wq29Tg3IoBgtAt7rk2H3KbMt8OxiOzZZ8PBNONXF7XwtgDh3V53+zfE4bzvQZX+aAhFjJ+Rg8K/lZMFNqP2zv5H+rDu0xB7QQMws8ekBZ+7uWpdAsPw0f3Orv4ykyEJBJQNge8rcuAvn2RA+ek74HRoiaRFMJDOiKx/WDcHvzjO5188UhZhI7NU5qq/QZHMsYuzqmChHpEO97H2FaEGKdTmJB94yYRMlcLV2s4xkl2Uw1UJLNUCHoOxqa6Sj8lZc4D//r1Tr0hh9L5misx/4+mlnw6Q6xl+L1ZlsMaPE48N8DPnA== 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 MN0PR12MB6320.namprd12.prod.outlook.com (2603:10b6:208:3d3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 17:50:39 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::5111:16e8:5afe:1da1%6]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 17:50:39 +0000 From: Jason Gunthorpe To: Baolin Wang , 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 , Lu Baolu Subject: [PATCH v2 10/10] iommu/intel: Fix missing locking for show_device_domain_translation() Date: Mon, 31 Jul 2023 14:50:33 -0300 Message-ID: <10-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> In-Reply-To: <0-v2-b0417f84403e+11f-iommu_group_locking_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0022.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d1::25) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB6320:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a507935-0d8a-4089-2a53-08db91eea598 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LhQxRzi65hIWPPtNuK2W1+s22HZfTlnnKxUzi5IEQXybEOtBYEht8cm78PSzd8aEI8HRprZYJkiRIAvhFWBPhdRByPlDALufle/O3sTq+I15zALfCaLMC1NvvIifVuDAeVPDpYfQWfiQcyj8i/xklgFlkQmk4DFmRW2G2AWeQz32ACRiLuUV4ZarO5i/dejXl5QKC+qjCOldFG6HUlhfrGdlNf7mTlk7tchPEJ1QeKXDcvz+GZOezM4NChKmBevqXHsfwcfFQhwlfaI7oOYL/EEBnIi8MiG762kPUQSsoKT0aRrwHsGI5d/AmbYOGdkEkL5iTGBYg166qNT4Fsk8nuOV5owPcgjjuUlrjjEUq0vCQ5ss4s8pUmfd4Ow1HK12R7om6oeNk+2BcjdaBftT+neQr+bXogwC6hUjcT0ne7Uojmcoqqf/GmxjnCX3Xj0euUUPMHvbajC78ZxBhXNQrX9l3zvIgci2ZmVY8J+3mb+LLwIKrvQ064bryCckgYbpVGS8RE43AGBqCcJpreDS9wuywkddA9GVo8p4NL+WXQlgG1Ac86jQmXePSC7iTaSaOGN/ewDNmOkGjqUKUeMVEVExs/r3VSXufyx3XSwpnxI= 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)(376002)(346002)(366004)(39860400002)(396003)(451199021)(478600001)(38100700002)(921005)(86362001)(6512007)(36756003)(6486002)(6666004)(2616005)(186003)(8676002)(26005)(8936002)(6506007)(5660300002)(4326008)(2906002)(66476007)(66946007)(66556008)(41300700001)(54906003)(110136005)(316002)(7416002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TAVJVBqZ9xTteSkQo007z0t3y6qIHhjXbtIAxmVIwKQaQsY+ApwcQY0NqfBdekQJyAPm19f0BCgX5i277GMQgYr8AIPA75o7uR59ahdqwPhX6JuucVWmjhi2ZhiFXeorrrP9kzUpvvZxfw42pCzN3V7cnYKBuJxwrw3oq9zEF5DMsZd6pgnhGTxEicFf+406dcBYJ/yhHVgs7ygr19eAKa4bXLaG3AZTYl5f/Jim1FE2GFHPGVcFpAbnJYLVrt3+TEPq3z45pUJX2wScANDgMo1s6TP7TANsojegdFa3wfD+TPMKp77HkRjc5NZTOp5iegEZG0jL+i8zKJ7e63Z3Qzyv6HTmKRSguB1buozzfaA0HyEuke2xdGJVxpp3DNS9a32aJaN6DJ3j9KtJV9M2vC4oyHEtJb+EbbKrBaJhSJjeO2dc3NFFo1rRdaRkSXd9haoUyGbum69wQdQInPg9abtp8qnYOurFf26kmlB2ko1z/KoDq2GRLKdOgevuOdcUk+yXneJuLS7KkFejKM5fL2bmg3OyHQdBTAKinlZL3PWPObHURSyUBMm7eDGy1MXrEoCAesIDY/WNNixZhQxIEzzEMBWVWJZf6ZfHkJpEQyVfSm/AA+SllCdOGXyKN5Y5L7vmP5IjqKfdcrvjkvRBQqQohxFg1Owp3nGujz8OOB4G3bqjjxwcCvYmgmil+OwfWh/drPspAyWbAFZQSnnSPIBfEqfn7U4oytngyzdghKDWPYW4P/R8ad/71hPcMEtI7x/6dL/izSePPa7U+1ih4Med6PpHy17RowSOLbDlf/b4ErO57pvMNxEtVopiGb/CWN/l5nmCTmmu6hlgNZzZxC6znwvq0fSIqmLleySjG9PP6uB1SvEDA3Ltr0GH0bYA0aKgh4mWBU6LwrZiItOZ97pxNOI1wtOjseWIKzR80wni2WbaevI9mRHDJN4ZggPHFYqJ+vkmSsKfGzwPMFFeUIxkNBbtqhmQDVebT4CCGDlnvIYkk/HCNZCzS9k04/PVJ28mMx3y7xYEcTC6b6Yd1omSzXek+l2iVlU1gy9ARMrTR8xeHhJDykW6Y/HGCxWNSLGq+hRwb5x99X/L6hw0KWonUHU+IzwGCtd/g+ksZpJZ7OOqmmwNd5MsBLJIhPncB5Y09ugBlKYezJhhfNdoEsPxaRAKzM1b1yIf2LNqsRM5600faoFUw+8lncTsayZLoyqWdA7mh6ioIKA3PU512WQxcRQ3Au23UvozYCn8UZgLasl8MVCINrJscP62rURGdQlP6YAbBHNi2zMD5wi6nQ9kUYSnsCggTIS6LJ3Vuc3aZhCQfDs0n+bkzmXGIR1P1FKfltlafomnk2G5IGEFMN+nl8pDAUB49tJO/FIjchBFMfN7CVMajfR4ZdgnRJaWrPBmrGxecZj6YkFFmEzT2tmdeKWP4LTw+oDpgWIYsZQO8TOXoJMfSmU6fbKvIOS/pc7F83dNLVLva7qlMK937J1r/xUzt4fWbtwkSpzoqTP9cCPTG4n80T9lzUSRqFA2cGEHbVPuSZ/kKP+4fLlJdUO3MZu2L2HzrCKaNxScT+wNVWo1mLrEHJjL9C1RK/4/ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a507935-0d8a-4089-2a53-08db91eea598 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 17:50:37.1202 (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: l/Mpz9k4cCqV0NdwtIm4p+Jz9gIHI2RPus+uTBxqQeaGIPMEtoWGTaWgmp5e2gVw X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6320 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_105047_835545_60EA782A X-CRM114-Status: GOOD ( 14.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 is called from bus_for_each_dev() and must lock the device before calling iommu_group_get(). Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- 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; }