From patchwork Tue Jun 6 00:59:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 689801 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99A94C7EE2C for ; Tue, 6 Jun 2023 01:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232455AbjFFBA0 (ORCPT ); Mon, 5 Jun 2023 21:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbjFFBAD (ORCPT ); Mon, 5 Jun 2023 21:00:03 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2048.outbound.protection.outlook.com [40.107.93.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A5DF10A for ; Mon, 5 Jun 2023 18:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P7cznAkqGj09NE08ZrDyfl8/iNgWYhzjTzlPLH7Sr+siQzj+r+2aqAn5HUfqBZ1QnI81pDghGtLruIRchu5DdevLmN0/Ggk/rLAEm+qe7CFp7lZMiCQ+VsUwj/PBhg1ylRJ0aH0N+MyYgmLJcWUaU+KSpQRx5l0MCNa6cTNFb+0R/+IwZlqIXNQMGvZHQgHYmJfF0eHaL+5bJhszeBtOYOHJ2QjP//Qy0s99zcAJ0EYu5GFQ8XeOnWiTiZJu8kJGZxPsVmG5FE0gub4TYMTwdmAUN6LKD+ucpEioxM16ScgY/arjWIPoglCPdg5rehInXzHCnVr8XoX3HsQelQ0cNg== 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=bfwabyxfmnwXdSrTfsfPnrJGW806V4BjcvUqcAm7T0Q=; b=dO+7w7uJeJK8w7rvlieA/eS6cfa7Mmoo9m55r+Pi1uaW3ElTDpBU4/8UCcNTWoIEZlelWwQWQ96SnLhGcIKrMKcnDl9qzsh7SLcmiuaxGZCqd9pKCp7FKgcUV6EkmCSf85LD2aPK4nQ948kFXUE5LoPuikZQVSHCifrS2TMDxCkP8WUtUBC4WQRRG86NwKRSXBQMwYmZxG82n8NA1Fe7of7SwYvq2VgU8oqXuVtVDfYvHh1es4dRE2rdHNX6UrrFmOZvk3ihCxua7tKNTuY0dBfqI1dJlDirLxYoKaKeLOkXP4wX+jUf8P0K9QMBBHfjEIqzxCUUsadACqXPeZ3iig== 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=bfwabyxfmnwXdSrTfsfPnrJGW806V4BjcvUqcAm7T0Q=; b=KKwPx0n1SJ2KMJ1JiFU9OwC6NyNXWFCZRBhfnB4xwZuYQe1DwTG6CXa0pVO2cz2Av3l4jo2+sYPLz+eJOuqb1bqDavxJRbj2qf0A4J3ha6KiLtMD/ODnz//B6d4nvGysNBG6246Jbc/B6GdC4xB1+Xl93AMK/9ZlfWDKm6h/mq00mwVDGHHd8/eoO7+HeirlqDczA6vgfJcR1m/7kWXqRlHqUJiiM1q9r/t2p0EPDSwgJQc0qnazaFlBzE4w8HPXA+c/aD4QR3mV+dknqgx9IoqEmV3AMK3J4zYRZ0UQO8EXy0pY9Kk48xFWPwW9lkCfgExQGPtNdzATeKDeXf6u0g== 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 DM4PR12MB7765.namprd12.prod.outlook.com (2603:10b6:8:102::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.32; Tue, 6 Jun 2023 00:59:50 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.028; Tue, 6 Jun 2023 00:59:50 +0000 From: Jason Gunthorpe To: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Kevin Tian , Nicolin Chen , "Rafael J. Wysocki" Subject: [PATCH v3 01/10] iommu: Have __iommu_probe_device() check for already probed devices Date: Mon, 5 Jun 2023 21:59:39 -0300 Message-Id: <1-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: SJ2PR07CA0023.namprd07.prod.outlook.com (2603:10b6:a03:505::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_|DM4PR12MB7765:EE_ X-MS-Office365-Filtering-Correlation-Id: cabbfab3-88c9-4607-f2ce-08db662954e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0nzMcQLN6TL8BfR2XZMnzDWxEtgsKfYTM5Aser1gycSqqURM88ou3vl/oqcUcrmTSUp31i4rbHt0njgBdmqpxJ0kHrkRXFmBxxdOSRwEs8myvmycePrpROxPDCGRUEBdM6wstWjraIfQz/6D5oNBzfTOcV0+iyMqzSfpm+WDlbArTKlLf/zamWrwBnQJfNsCrA2wlXHjfz7LkRJHs3uHkCvYDrcWtLSmJpH/jbWGuNKCyAQNhtgAUPY2H30+Ndse7hRi73FMm0Mq2YgCAH02M36HQDdrTamoqrBDhrmxAMAvJGXclcMISH61fdjuSnFdTB8vHRTaEU+iu1xKkBhkuc1Cnkh23hyvh8DqtVucDXOfzMGHKRvKHrx002hc9OOY4zggts34AhR6CPuO4+gHTPcp9otx/PmiHBmKNOvD2TcP0MgJfmPizbky58CjmsRovfSATkgIWSSNEG0U1ytxhl7sVWisRrtiniV97Sn0LTabBPS6L2MerGPEnmNlSLOn9Y8me9FATGIm9X5HDyu00sr+FqXdesyCnOk40Ra+ORMqt4Fq93igKmf6ARRYE44frwJrhiPUG8k6509PBG9KYqGeuOxM5HfUOm962x9BMbE= 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)(54906003)(66946007)(110136005)(478600001)(8936002)(8676002)(38100700002)(66476007)(316002)(41300700001)(66556008)(4326008)(2616005)(186003)(6486002)(6666004)(83380400001)(26005)(6512007)(6506007)(7416002)(86362001)(5660300002)(2906002)(36756003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Xsq2FV4NutbGQkqzGLGxUzkk1ggKUVx/M44ECRUHitojpwmAEfatr6yo/VjQ0RsIcV28BzkoiX+kYU4kH/z+qxcuW/e602wDX23N+xryPF3Dl4phC4yJeyX59XWcsyA5rgl4tIutW8kfEIhjdyynRIhMdEQqYLCQV6+unkBTjrWAbOgwSRsZl28HP/gCJxaRCRDS0OgOpArTafBXhQ3ykFt/1WutaJ/Bf+0S6xX08ffL4UmXvWVcakSYpTEUXI8Tz1wqYCnBruE1HPva83gOpNQ+V+vCTYnyrMWr1a3nqH3TkFYcyOrU/Bhn9kmcTFT6Bv4RdfbTi5GHQaPEJxyNcvn5u0ULmV2uL4zRQsyKcjkokqhtCl5jAFud1wrm9/OwKEyKwz2P3e/VEUgyW6ETnRNOffprswnFC1P/XpsFXotS6rOY7kUmvy2dtNwXVeSqp0GHvX5aEzx+Y2rOL/p1H4lhPiqCE9rNuRp5VMkapNZhuESu8VL8PFSNjgI5P5OMG3S1Fq6tUGMBl19XHLGW4sehqHL6JvWmWfDBz39czws/2GufnsjrX9Sj4DxxMaPjscw27xHz4FXy+Q3oIGy1pC9HtJNqFGnb1gz6z1gkBnzPQYsYw7DL/bXY/ov71cmsTX9wCNGtWehHel/lJYQcGj8BvbSd8O4s0F95k4oi0bOvuTfo1iwcBh3z5M2sdE65gMPR9IWvasP2l/lbulWB4OwD49KCV61ZvXSU54WJyouch8VSyhIc8My2dBSL9n0RE3E29Xqj+jPEItwaSbS5Mi2GpoAGKxQJx3pBv4DHCGFqHpGgJz9xgPq8mDps/tFJMmhNA7Ys2cQMGZGUAwlvn5Ycr1sB2++AoaIUR00WgxncR+DXSehHFRHDKXPcCKhTCszQlOktmVfjShqgx/415n1UPhkxOley0h5/x/lSLkOF6lBGIsJafR95CEoy5DJ9k1DCBvld51TxAL13M1QtIO4atYMEXm/d8XVnYq993O8TZ/FUCcARjpFf/O89D0xUKDIGJeq9QOPn/hRdYe3fF80NxUzBgfiU577vYnVyC4VF/rBrNXiIgQ3jP2bnDKwetcygVQ+pfTBLFiFjuWXp3VZLzM8jrQRaLEk/vmADNbdL7mEgbGXLY4FnVkA/oFxOFILONLgP/6kbm/wri9Jt9eTO1axvy6Q8a4mzoG+lWBSP0n+duv5fKEuUaN8gd/Kj3R1PYtW4S6gcgQi3/j8UpU7Ix3/lGRxR0Oyy3SW77yGWpIUGqKB7HFboRr06w+U5aAtZg8GYIFaPbkYMWgCM9sw1Uu4/Tdb3ll7xTt1sv/g5zzRKpjlOBIQSDMqJp4PrGVGV4fDBaLn4BAalw23bkbn0864fZIEEo7F4oJI2pcyUl7jDUK0r7pIfPWzIkNSnmrYPEnh+NbH9YevgUxVE4dkIER5gv8pL+hk0gPjNgPG3U5TubWEsRLh938dUVTWN1rbLGVneRh04hkmc2ddnNO4wWfvPAnt7+ctoxWxR4LW72tViexrBwrR1um/mEWVeJdEjiB13vR1QalEDhDJUS1+ugyTpiJiqPfXklg0uzl0Dn5fZVmSaZZSGC7WuBmzN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cabbfab3-88c9-4607-f2ce-08db662954e5 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 00:59:50.8397 (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: ZKgUmU85DMlOmHwSpCOGZabbktxTDBAU0bxK7rHf/dJ72lwwsAJDIqnXOKKztBea X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7765 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This is a step toward making __iommu_probe_device() self contained. It should, under proper locking, check if the device is already associated with an iommu driver and resolve parallel probes. All but one of the callers open code this test using two different means, but they all rely on dev->iommu_group. Currently the bus_iommu_probe()/probe_iommu_group() and probe_acpi_namespace_devices() rejects already probed devices with an unlocked read of dev->iommu_group. The OF and ACPI "replay" functions use device_iommu_mapped() which is the same read without the pointless refcount. Move this test into __iommu_probe_device() and put it under the iommu_probe_device_lock. The store to dev->iommu_group is in iommu_group_add_device() which is also called under this lock for iommu driver devices, making it properly locked. The only path that didn't have this check is the hotplug path triggered by BUS_NOTIFY_ADD_DEVICE. The only way to get dev->iommu_group assigned outside the probe path is via iommu_group_add_device(). Today the only caller is VFIO no-iommu which never associates with an iommu driver. Thus adding this additional check is safe. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Acked-by: Rafael J. Wysocki Signed-off-by: Jason Gunthorpe --- drivers/acpi/scan.c | 2 +- drivers/iommu/intel/iommu.c | 7 ------- drivers/iommu/iommu.c | 19 +++++++++---------- drivers/iommu/of_iommu.c | 2 +- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 0c6f06abe3f47f..945866f3bd8ebd 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1579,7 +1579,7 @@ static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, * If we have reason to believe the IOMMU driver missed the initial * iommu_probe_device() call for dev, replay it to get things in order. */ - if (!err && dev->bus && !device_iommu_mapped(dev)) + if (!err && dev->bus) err = iommu_probe_device(dev); /* Ignore all other errors apart from EPROBE_DEFER */ diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 8096273b034c3a..61cfae38c8ba96 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3763,7 +3763,6 @@ static int __init probe_acpi_namespace_devices(void) for_each_active_dev_scope(drhd->devices, drhd->devices_cnt, i, dev) { struct acpi_device_physical_node *pn; - struct iommu_group *group; struct acpi_device *adev; if (dev->bus != &acpi_bus_type) @@ -3773,12 +3772,6 @@ static int __init probe_acpi_namespace_devices(void) mutex_lock(&adev->physical_node_lock); list_for_each_entry(pn, &adev->physical_node_list, node) { - group = iommu_group_get(pn->dev); - if (group) { - iommu_group_put(group); - continue; - } - ret = iommu_probe_device(pn->dev); if (ret) break; diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 9e0228ef612b85..8e77e12a180116 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -351,9 +351,16 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list * but for now enforcing a simple global ordering is fine. */ mutex_lock(&iommu_probe_device_lock); + + /* Device is probed already if in a group */ + if (dev->iommu_group) { + ret = 0; + goto out_unlock; + } + if (!dev_iommu_get(dev)) { ret = -ENOMEM; - goto err_unlock; + goto out_unlock; } if (!try_module_get(ops->owner)) { @@ -399,7 +406,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list err_free: dev_iommu_free(dev); -err_unlock: +out_unlock: mutex_unlock(&iommu_probe_device_lock); return ret; @@ -1711,16 +1718,8 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) static int probe_iommu_group(struct device *dev, void *data) { struct list_head *group_list = data; - struct iommu_group *group; int ret; - /* Device is probed already if in a group */ - group = iommu_group_get(dev); - if (group) { - iommu_group_put(group); - return 0; - } - ret = __iommu_probe_device(dev, group_list); if (ret == -ENODEV) ret = 0; diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 40f57d293a79d4..157b286e36bf3a 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -159,7 +159,7 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, * If we have reason to believe the IOMMU driver missed the initial * probe for dev, replay it to get things in order. */ - if (!err && dev->bus && !device_iommu_mapped(dev)) + if (!err && dev->bus) err = iommu_probe_device(dev); /* Ignore all other errors apart from EPROBE_DEFER */ From patchwork Tue Jun 6 00:59:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 689806 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E528FC7EE23 for ; Tue, 6 Jun 2023 00:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231967AbjFFA76 (ORCPT ); Mon, 5 Jun 2023 20:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjFFA76 (ORCPT ); Mon, 5 Jun 2023 20:59:58 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2076.outbound.protection.outlook.com [40.107.94.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E35A2EA for ; Mon, 5 Jun 2023 17:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mHOwqa20oJz0Uis1XzLkCLvN5hbRcPZQE0VnlE2gjovaIFhTSIQX2jZYt7Dq7bAmb6GynKKBYcDkf4mrpKA4dc0k7kYsR7xQyxeoUhvKKhIRmrUcLYxz0FZVw3HfQFTyoPWEm6gft3E9vS0dClpH3txDCL3V5G78oHtqO6dNSj5XolDYmokPkThuPT51KR9m4kCndIrWp4FJ+1fY+lCM/DKntmTNzHMSScWTNOxnqKQkfAAKMpRQ4lIA9y5VmiJOWPjZsQ37TIT6A5XMUwp/UeezQWGRDc10hS0bCb7D3piHh/jotZto/ZqxCkBI2P9UrQSxFj7ya9ZbQkBW3YWuHQ== 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=8diz4XTS7ftFZVs8zPgjZwLv6G8O1Qh/M2aGohNqR1c=; b=KGCWyniE7OoC7nfvoyF8OLBncSu+Ma2PcfvV9rbd0zcHhZAhXqP5W7xjhXYo17qjoqBpsvYBa80iGw+kDDm7VIQll+kzo8UQvrVmqfUs9j3qlFOOHFcF10MUU6EPMKZ71kr8HKdUotHyDlpHK9UpEE7q6dHiuXuPsW5PjLaONv5D12DAquSct0Ics/cy9k75/lAb+6HYCEFIaqcdKCev/cuje+dkxeROJNj3TJMPwKgJ79Nkd/ILuSGufu8x1E4L9eUQV1IG2UyZ+/8ZifAzJkAcUnuuRCWvxAu0K9hsuejSajKrdxNUCffwsSiZ20/SlK1fVsSvAtGTViiPm0lP2w== 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=8diz4XTS7ftFZVs8zPgjZwLv6G8O1Qh/M2aGohNqR1c=; b=GGCL8NBK4hJ7XVQXrAL273E/gEZNSVbOK9G/Bloim/OHdwgJLtkCJ8MMHn/s96rCIIKrUdqkklUJA0uy96JtOIChqjapvhIkJP2GmFEZ7D+EpOkacZeuVuAAVNbjfx/ZOV9+dVsnfKfKTg7kfvx5IvtKNZrKvFTZzjGCx+ZR3eckdnRgzEV9GXJUG9JGeSRBFTQiegcnt5LJS9mix2Jj+axj6NKXdOt9hRcqnm7BfNmrBhhOr0ymJTjHPEPg+gidrtFIfCofHYem1hkfDcs4ZKLKsC/Uh0uy+cFaf5KwOfCPXDzF5/c1P+a7QhZUcAOGNi1GSzJtQRTFZQHdrUcNKA== 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 DM4PR12MB7765.namprd12.prod.outlook.com (2603:10b6:8:102::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.32; Tue, 6 Jun 2023 00:59:52 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.028; Tue, 6 Jun 2023 00:59:51 +0000 From: Jason Gunthorpe To: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Kevin Tian , Nicolin Chen , "Rafael J. Wysocki" Subject: [PATCH v3 02/10] iommu: Use iommu_group_ref_get/put() for dev->iommu_group Date: Mon, 5 Jun 2023 21:59:40 -0300 Message-Id: <2-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: BY3PR10CA0017.namprd10.prod.outlook.com (2603:10b6:a03:255::22) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|DM4PR12MB7765:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c58df7e-c9ad-45ad-3d5d-08db66295513 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ej+C2E37dO+8Q9H1pL/SZwRFbYx5SPAnwgikkSNIm3VQJUaDR8+46MdqBHQFMAfdoyXZ690qr1PHtz1vngmiqmW3tfp1oKvXKCLSfyguYCOgivdSQP86QZ4l+IUJZnYqOEqwVxNfqFMbMUnk+EisP/m0mULo6xTLOfBqls7MqI/uxwZeNgipHicVRcr9+RiuzdeeM+4o+MT3tJOOKrBI2ieq8VE9ejHVeL5us3FjzjTRflKws75g2jUcvOhSH0Nk9b1emq2lCzPmKVAQO58NOxizxUTI0eKCdpEIvpcnp7JT8uOs8lp1yMy3mc8XdshT4aB0iX2iQX43bH28o+GZc+ZL57n9BzGbb/3aFHeFhXb7RKHNJF2F+y9x7viLLSR9njCrWCSXMhlxvO/mGPOxxR1xEWDiiRR09KCqFZ7z+obg7V7icUYpMD+KOXWqd1n7ERzNx8y6FB4Bk7TWamvpL+0zGQvbn7bQft+H+X85/skwHYw2HijZpzGltJOuOg+3PL1A5wuO1x/T5YzfOXlZcMTyQzDhjo0366nTDY5DNWld3u1zKFkpf4lb7gzV/lJNnzTyuA8Alrl9QmJRRkT6iggplILiv1kCWnBf5jP56/o= 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)(54906003)(66946007)(110136005)(478600001)(8936002)(8676002)(38100700002)(66476007)(316002)(41300700001)(66556008)(4326008)(2616005)(186003)(6486002)(6666004)(83380400001)(26005)(6512007)(6506007)(7416002)(86362001)(5660300002)(4744005)(2906002)(36756003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y7dMRSZnJeoMFXPIVTtTdcBewCkwKUJx5xpKWvss4+lZIZYrBUq4CIomBWd22pZIPDe5eG76ZxGUO92+A4ZkFVwjozfTCFxBFziELLiOqGrPMVDUhOhRYd4lg3QOoTjK9AN6v3U8G1ElpucAD5Xf1F4Gm8EEnW1ngPdE5S0VJWlzmoGZXzVzQw9CMwO2f+aH427x4RixUhvtR7rvfqXyUTmMNO/j8MBsYut1jkgr+VpIvOSjKKXnk3JhY9l9TY5j+dmQ+HE6S1MvS1wkFo7z5ZFK+1sV5C06wB4SUk3m3S7bxlm2Wc2/MNfK+FczLpwND0DQxH36ReZUHDENuDCMEiACFI9+wNNfj8vkbLHByw60Zv8ashcurtJT1txGA2lpTeAMTbnO4tybn7Z6SzY16oGBx6VQHtTQO9Nb5kht76cxTAB5ZI3KWTfO0vcplXx7c1AA9KHa8OhwfykxelcCN6RJi54RkY1ygjr5QKSOtkiMnz9LmTeAbp5qcl1QUYyn/8YqIxZTTgoKPBnVSoXvR4JlIRCSYoFcV9hgH4NHuan6EwUtrq1OEshjvv4mTbEMCeNYXvyrLL5ORnyKWZFEXJ+PKPKpVDctkBgO7OZd/QH+65stNtEgZU+AFh+5bEvCa0RCsVyDKob0Nq63VOWJERBuryux75dQ7gHX6ta06XXZXXQ1tmDLHNxUTCv1WMCwnZ5h1HOjNPsg/dqXP1aDUIUGiLfzV/kzicooa1m1Dhb9lirK4AeqjJo01qyF/rPh5Fku3+ttvCQS7eE+zEjqIIsc3YmLkfTIb0zmXWzJAdA3XZPEbRRjQSc7IyCipbrIRdrlZJh9dotp/EqQka+b78QwETJl1Cx7/BZihrwHv5k94blKWgtf4DnDt6liuTilWlLpl/nuK9/FUVjZhKap04jdLysPuDlG0ty3+TrDcbBs1VpGyFCAtyBKCDnYU5H0TWyOe4PDfjbXheA2EaS9f3Q0n/SDjCQd//KqinvZj+4p1HFA26IlD3Fb5xergeoqCu52T/ZK7TKAK9QI6i3iHvsvaZmm8TgpfwsKz3gQ59XkX9uPIOCgm1V7/gBadNplb4bwtpF4noJWF3FOOPvuv8Mj4cUcwShP5fdfUkKRAn4+GzSYXU+hT+nWJZhEnV9nh4jc4fXSQaQx33/KiWgJnLA6TGjUleEsSuxUqxi8KrQGVioeGaXpR6dS9xM0/+7KasZhZoZZas3meNwPF8H/Yk500h4QMpXlhmtkGQ5/NhdMi5nBQNCVN5TjLRzRU49j1pvGdOYJ++O63CfoaBynS7WtGS7hMSQkNY70Zn+69AE3nn6XyexBSZs7ehBUGIreJd1zew/IZqNp19K75o7RBZtr//RaV3aSU0+CBRQ6Ib586dqpse99ZH+I7j95uAR6NfvPOsQILXH/O7aOVVQ9c34eEXMLWokueDRbJb2ZpHCs8N0cC5+4t1/c+3PzeNGyAv9gtbZ5w1q0kbvuItIEMy0+jYGWhl9d+DLAeicdQ6yfgpnMs+hn5SkG0IaxVfGBe08WReKsdkw98pdxYxhnB4NS3nMAutNW3GKM3kcqU67n3724X3sbT5qRjCLfiwqN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c58df7e-c9ad-45ad-3d5d-08db66295513 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 00:59:51.0893 (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: p3sQdkeo24Oy+n4frliaebepcSwlvbNcMZ+v/6J0ZdNYeIOQd4IQZtj9bYgapXTD X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7765 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org No reason to open code this, use the proper helper functions. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 8e77e12a180116..aa162b48c7dc64 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -500,7 +500,7 @@ static void __iommu_group_release_device(struct iommu_group *group, kfree(grp_dev->name); kfree(grp_dev); dev->iommu_group = NULL; - kobject_put(group->devices_kobj); + iommu_group_put(group); } static void iommu_release_device(struct device *dev) @@ -1067,8 +1067,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) goto err_free_name; } - kobject_get(group->devices_kobj); - + iommu_group_ref_get(group); dev->iommu_group = group; mutex_lock(&group->mutex); From patchwork Tue Jun 6 00:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 689804 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6F06C7EE23 for ; Tue, 6 Jun 2023 01:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232410AbjFFBAE (ORCPT ); Mon, 5 Jun 2023 21:00:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233193AbjFFBAB (ORCPT ); Mon, 5 Jun 2023 21:00:01 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2070.outbound.protection.outlook.com [40.107.100.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029F0102 for ; Mon, 5 Jun 2023 18:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dfg0vBe/D0Xi54pwdADXToBHSj+YGN9wV0anmGM+baOEf8bcsGz5c+AHsG/Wn3Tb0SlP9VkLap0rojsJX0f43cFonCahfcBln61S7py1u+Taf7NohasYPlttPmuiDvsvVoqmWrxjk8WDuNnUfc6//M1zJXngyTbyzFadYm0qpMSGx2sGpjHzyir/CL/2xvL720jaZcpkP4IRgHlKg/5uVU6YHSJyHk4gp7VDLDmYpZJSjrGoLT4lMV2/i1Zzv1cQNW0aV56Jna9Hn5BTEWKWCMdUAoFgwoTmHOoP5gdxj0Kwm2jQ4FPSEuYqeFdAcxOFuUSTbc2cgLMdgkalKk3CoQ== 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=TYBf0AK7hbCXqXwso/9VcXX3AL5HJHKoPMemFXl/wjc=; b=ET5ALWLfqCglMV34HBIma1ARwyFwE4Qf4VlI+srzuEdxVbnS97O6fiyvPyXzsKRt9RtquwU7jpJZ6pZiRhsVaiEZ9plDqt00y/g7VnnCyb6G+1g6UL+DFLSZwIx6sCzdPpTUub1TdTkrQQr4mcdXwnHu1K5kJ6lvaYQzJ9F8Aed+OYwEnW8heuXvtWg9HQfazBr5ZLFWLUkRK0tq2rdL2hj8lDRY4O2ZglZ8HMqFUvLMDUkILiyvB6/nEzXaTLwzBeJHZ6LFSwmtYyd8h6zFkGVu0guGxzS9EEKAOWzBVyJcprfbBqpcLa2/gBdZj78IvNsGMgT/TkG1NHeBiPmBAQ== 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=TYBf0AK7hbCXqXwso/9VcXX3AL5HJHKoPMemFXl/wjc=; b=CpXFncrMOxzyUvjwQCzJXg+nC44dx09xr8nur52fK9bCGtakREC9uFc2owu3v68hY66E1egp9oKQn4ElN+9fdOWVAhWN8tj5/x6KQ0BS8NUI4/mf3BXzxq588+mckd34EusK1TaqZ59EleMytqPY1gUL0LTanwmoVa/V/JlJRf9nd318zzkwTfjgnrd7ZI2GYtu5irDKdI6XHyhuzq78GUPD5k8tWnrJSOXEyZGtE+8+CFckCxnlOnblOcopIQpBqEpWUjpQh+mnwoME26hJLNPQpxLPRuSNUMzU/WioGxk329r9dto8JkOrlq8uysTnu3oU6Ro3HmGs5voCzuBF6w== 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 CH2PR12MB4085.namprd12.prod.outlook.com (2603:10b6:610:79::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 6 Jun 2023 00:59:53 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.028; Tue, 6 Jun 2023 00:59:53 +0000 From: Jason Gunthorpe To: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Kevin Tian , Nicolin Chen , "Rafael J. Wysocki" Subject: [PATCH v3 06/10] iommu: Move the iommu driver sysfs setup into iommu_init/deinit_device() Date: Mon, 5 Jun 2023 21:59:44 -0300 Message-Id: <6-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: SJ0PR05CA0076.namprd05.prod.outlook.com (2603:10b6:a03:332::21) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH2PR12MB4085:EE_ X-MS-Office365-Filtering-Correlation-Id: 615ef9a2-0048-4b95-ef01-08db66295542 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L8lW5SZDFjFq57/Z9oJqbcEvIMj7wVVFc9YTKNkEpBI6AEHotuPmz34w92wHV+1HdjGrDC8RqS2V18wSfV3cKHaTmaGVQkNs12/JGexoCWWCO++ZxrQ2euDxw7+2OsaoZFWp3OA2UQGy0iuKQspL+T67MVP2Ed7Y1gSw81f3oLmIWv/RX80yqPwZuPXQTrw5C9sTL53rGCDckUy4uiPUWG4c/W7o+qnHpodIWTqz3C7n1fUlYVsbBrkv5jry3WKT6H5RxYKc9LmTUiaM5UJC4jK+vcvq556mPxOIG+Ee0JmZVCVqthXAKYNFy0K9d4uzD05+rdjknPCzb8NsLcZY0qpeE9J0fIDptuWAxafminwdPZJxmyO/1x6QWWIT1yLmSXQ4IGBXEfz/YFS07bSyyXcsN0TohUOLBZsTfdOmYYQn25910A4YbpyAVhoFI+qh1FklqFBZzm/yHB4mGzU73R7jlyrcTdj0xJ1dq1ehuBJdNTXcxxYyezg9nGP1+/8Evt8FrIxp1mSosMNDk3pw8dEJiFxeiNL7JxPVD570+vn7jSPhTto9n3axxgSlGm0SJZoT3oGW+LxKqSwTYHt26ioRgGiA9ik9PRRPTe4s0Sk= 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)(376002)(346002)(396003)(366004)(136003)(39860400002)(451199021)(36756003)(110136005)(54906003)(2906002)(478600001)(86362001)(38100700002)(7416002)(41300700001)(8936002)(8676002)(5660300002)(316002)(4326008)(66556008)(66946007)(66476007)(83380400001)(6506007)(2616005)(6512007)(26005)(186003)(6486002)(6666004)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tBhLT3pblBZemCMXQKKhXE27jto3OF/B/IsC8RcA7HGWd6ns3b08CEyuef+g0tU2Zs3MIxmcqd2I8gYKv4b7PI2KOAHD+wXj1PwVI0bsaDyM6FhozV84eBtPxSSUczF9eeSe2q5WxulilG8V1JDKSrbHbfE7o1cs8XaB+hMwVAhWsN6ZgQvTIn4uVrCMiNJ6fHIckztoin3oJ7/Tm81EUgGjy4qzjMFomEhBtdBHPwk4jrpCkvbIUWXlpa57I86m3v054EthE0VHvwVeIWVw47YUcejavLgkPWjyPVraVrkX/J+Ku3IkSceLcNqwVcaGuuWGXr4DKMbrQKJ1tvocNflL498HFQI1ElJMU1N/WX/GXfPCkX6Najf8GL5D66vR0W0jRPs/SZ0DmCoLUDqBSBlqf9LYLKUg2YEA3VTsaBSG1zMaupEyE2WiIj7UMYrxXK+HQqxIz2sAPieN4xJGtAXtWnF39sxQPsxydj37haeNzYop7oY2P3WwPKVpuElANMCEdt4DdDOkaoxQ207uNqDnUPzRB9niUFzv3dxnu6S4N2INITlNLtc39yjAhcRoB/avtxw/1hRh2+r1MFSmxq4iwAJ2lk1SnK+AVS/2hCIuzKcRZ9CyJRWdGxWUnxtTB7aL5bLTivppdFH60Z9bUqaPFZIjD/OhbnEcnAySo7XI+tA4bMYlSszhZkw2E3qVppf9oZnYqVWiDH0e1szlxUyK3NTlQbADMhdZUM8lXutv3xGiq3Q6xyBWyVNDew4DjbO6bGg9N1HaEe8OVtxwGL0auA+2L12MPmHhg5q6B/KMPR+R8nK/ohyir+r2zwtU/3nwPYTL19jXy2et1Rg6A2fSvbdEdrpUiSmxj+T0V6F3d7xvqYl79BgSURuhRTsckuX3B+8N5UvYxdHCuUAuGziBq0R6XNZx9MLA3E0vmDPDQMWfVQi+EYKZhkEX1tGVgIWjVdQOZOvBbCnrDKIe8XiIe/+4r72XMpt5xn0pas8JZ5U5shoe6yuv8xROeOLV3mZED41mZhPJo1VVt/tSRV69BjmqX2m9dGyUGdRJpwFY5D1sblkij4lQd72TnOa7cRswQcgPft40Ot5tPLDmxnT6vPGPUYFyoSH5TKKQYZxVjB5wR9OkHYhCEQQi8VZX/SBkEEuTbTAaQbc4atdFvvRua2uILceLweUX8kO+LJIlY6jEfYOOgh/omBhn+GkYMWVSjioMXG+Vm+un5JAdhpiEzfkpGD+pW01PXn/K0U2MbeSYD1NDimL/iHtgkZUvldoxPEO4rtbFYcV4dLPlHKHL27CWYD89e2kyCoylHrWrxN2QsEtqeachujqdHwpPkMshjik3IXhy1hztsrF0o2Ey8Qw5pTPNz5fzJ5zsZ4LpQXW7JfCxdasUa3yIWZRpmgbFab+rD7xLZC5hM4i/lVTxtB5KAK/9YJYDVnZ3uGMYJuHbVO/L2oREaCgz0qG7J4XLD8eJTDqCDcfFNL0uJdobHRsTIqKWAlU5RxZU00DY9pRp7UHkwMD4si7pcgYvQu4MtJvgQDSS+gR2JgaWKIWl0Xc6eIU5qgIhQ94DrXN8xzumDNNyd+4OfvsNHPBx X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 615ef9a2-0048-4b95-ef01-08db66295542 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 00:59:51.4243 (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: 6mtNpcyXs/qad0nlBHIPerYvHEMq/WerRmVk2RyhSNkU+CrjGyYnMt2hYIFVl1Hj X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4085 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org It makes logical sense that once the driver is attached to the device the sysfs links appear, even if we haven't fully created the group_device or attached the device to a domain. Fix the missing error handling on sysfs creation since iommu_init_device() can trivially handle this. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu-sysfs.c | 6 ------ drivers/iommu/iommu.c | 13 +++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommu-sysfs.c b/drivers/iommu/iommu-sysfs.c index 99869217fbec7d..c8aba0e2a30d70 100644 --- a/drivers/iommu/iommu-sysfs.c +++ b/drivers/iommu/iommu-sysfs.c @@ -107,9 +107,6 @@ int iommu_device_link(struct iommu_device *iommu, struct device *link) { int ret; - if (!iommu || IS_ERR(iommu)) - return -ENODEV; - ret = sysfs_add_link_to_group(&iommu->dev->kobj, "devices", &link->kobj, dev_name(link)); if (ret) @@ -126,9 +123,6 @@ EXPORT_SYMBOL_GPL(iommu_device_link); void iommu_device_unlink(struct iommu_device *iommu, struct device *link) { - if (!iommu || IS_ERR(iommu)) - return; - sysfs_remove_link(&link->kobj, "iommu"); sysfs_remove_link_from_group(&iommu->dev->kobj, "devices", dev_name(link)); } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 7e8f5edcff2145..2281f3281ea4a0 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -356,12 +356,16 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) goto err_module_put; } + ret = iommu_device_link(iommu_dev, dev); + if (ret) + goto err_release; + group = ops->device_group(dev); if (WARN_ON_ONCE(group == NULL)) group = ERR_PTR(-EINVAL); if (IS_ERR(group)) { ret = PTR_ERR(group); - goto err_release; + goto err_unlink; } dev->iommu_group = group; @@ -371,6 +375,8 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) dev->iommu->attach_deferred = ops->is_attach_deferred(dev); return 0; +err_unlink: + iommu_device_unlink(iommu_dev, dev); err_release: if (ops->release_device) ops->release_device(dev); @@ -388,6 +394,8 @@ static void iommu_deinit_device(struct device *dev) lockdep_assert_held(&group->mutex); + iommu_device_unlink(dev->iommu->iommu_dev, dev); + /* * release_device() must stop using any attached domain on the device. * If there are still other devices in the group they are not effected @@ -462,7 +470,6 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list iommu_group_put(group); mutex_unlock(&iommu_probe_device_lock); - iommu_device_link(dev->iommu->iommu_dev, dev); return 0; @@ -584,8 +591,6 @@ static void iommu_release_device(struct device *dev) if (!dev->iommu || !group) return; - iommu_device_unlink(dev->iommu->iommu_dev, dev); - __iommu_group_remove_device(dev); } From patchwork Tue Jun 6 00:59:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 689803 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 283B5C7EE24 for ; Tue, 6 Jun 2023 01:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233119AbjFFBAX (ORCPT ); Mon, 5 Jun 2023 21:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbjFFBAC (ORCPT ); Mon, 5 Jun 2023 21:00:02 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2070.outbound.protection.outlook.com [40.107.100.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19923109 for ; Mon, 5 Jun 2023 18:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=etnIfPFnquGKXMiZLHKsnDrNh4gyz0ELPVvKwDzN3QBIXFAzASNR6GjxZd9Cx2jelC2lymePu6QY7rtcTBz0+jcl6ziFhh4wUXokktHlPCtaIMMpyghuCNEJun8Shfm3MTwBzWg00Iwl/BM5t5OUyMFQlI044AnXqMo/V7XCix4Ugpj8838nhqCktpoFSIgxHshhdFIuSb+FUHoktFR9gHENsA+R346BhyYJyIfaZcq1+ezUPJzF/9esRGpFROGJCVghb2sGBV3mFSkSulYpuOr6MWYWIGwVR9JfuKe+5M2gAd1K5cLUIFmHW4mJwWi/VjNrfLp68y1Te2QOMT9oNg== 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=pmoDPoU3V6R7hplC/i33578VGjjaJ0snSYhYFvlP2/s=; b=Ca/vUiAdJefiSEs+e1Px29D04yMGH/EZ6PL/d2OSp9BsySeaDhdFlSgZw5VadYpo1L/VwkCjy1GpHU4AM90eJDqbGfLE6gSN3HK/yeUwbaJdeft1kmCtW+k01ykZBV3SUDH0CLxXDuajwMDaPUEC7/12Iuv9D6V8uY30cFMMQbnU5zBGdk332bCfLHukgJG37nWvzuVuxCjQRbAutN+qlrYDWhuHYqX3WLXYi4yye/xiBNSq/UwJ2bwAtpJsI1lHElt7xdXLnxBgmpzz9iCReoQvg08ugvVnnQv77i1VwcorZ38wF15yQ8Y/diQ/1euN8SbLImWog7fhm+kx0Gmong== 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=pmoDPoU3V6R7hplC/i33578VGjjaJ0snSYhYFvlP2/s=; b=Ssn2jf/MtoGpMlzg7CJvNIJyjhV+iyDq7nXHAkSXBQ/Llx5UJMnA5BVV3K9vhXaZFCJczf8kqrsqoh9uqY70rA0DfV+hIebZNFvDJ47sMa+SfbfyjNSoLCI9NxMoaxzwnKwPxkcMJQEQrEs9TPsEVgax4GqwWNxaCxFzqBjS/rzKEPPAOj11Gw+LExwDBPQpjiw5JcmrS0U8svagfJPuWF0L3t2vp6wVvqlVg473TRaH5mLkRAjsMnwugGMk5MRYbpHOcsL63XJq6fiTfJV+sCY2gl31wZOCSUusWxrcyrfu1wDmV/R3mQASdoM3D8Ur729e3u6yIwSV+ByXKvoJ/Q== 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 CH2PR12MB4085.namprd12.prod.outlook.com (2603:10b6:610:79::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 6 Jun 2023 00:59:57 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.028; Tue, 6 Jun 2023 00:59:57 +0000 From: Jason Gunthorpe To: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Kevin Tian , Nicolin Chen , "Rafael J. Wysocki" Subject: [PATCH v3 07/10] iommu: Do not export iommu_device_link/unlink() Date: Mon, 5 Jun 2023 21:59:45 -0300 Message-Id: <7-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: SJ2PR07CA0015.namprd07.prod.outlook.com (2603:10b6:a03:505::28) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH2PR12MB4085:EE_ X-MS-Office365-Filtering-Correlation-Id: a556a0d2-d384-443d-84cc-08db6629555f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k30RIXPiasdfH00EQXmlpKPfEan0UbPZsWKJfn25ubYdQJTFkcKCYZwBkfbbsxGuSRv+LcNCu1psbL5gOBndylNAk98zgw/6xYCCjIKDQWSoT8AAA95s6F1PJ+pODyCNFmtJBS1XmRL7c13hB+NPft9R6ST2JZ0PLuWNqdQceik4DcmhaPdZ9SP1KhZIfZ2Iv+bhYibmxxvgqcFwgpxMK1iVKNdzz8HAle8CRIP5LOLXWDeTvHkCYlIGhBiZx6H0IvGz//SRw9REfnIa/rSTLpuqJ9vguw7Jr3Wdil/0WtBf8b6A7X7UB6mN1StARANkG8HKLepVAsdBhizwhgYmbDxLmga+SkWiD1bko2UTxnpuFvDgHufmiBNJUX2a69AU0wSbAa+fvX77E418ZlV5EzTjyqq/CHpZLrc8dVjjty76hx1TqZVGNeAe/Bxn0yELKqz1yJx/NuTfHv8vpsz5reXN8Ms6kUJv4uHjfWzGaYrWlgNlwA2KVqtnJ+HelW+yFRQcil5rFqcbGXHKEOGlrANQIQFn38ZY3lYVcagN/vs2wWUSY+A9PipiqOy/3hNmB88WaK3vs8QuXtTl1iDToumo2qyEeHu1P/3DPv+vJl8= 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)(376002)(346002)(396003)(366004)(136003)(39860400002)(451199021)(36756003)(110136005)(54906003)(4744005)(2906002)(478600001)(86362001)(38100700002)(7416002)(41300700001)(8936002)(8676002)(5660300002)(316002)(4326008)(66556008)(66946007)(66476007)(83380400001)(6506007)(2616005)(6512007)(26005)(186003)(6486002)(6666004)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d4avrx/KHWkYmD/HTAuL3EF9JIjrY4C3dqUh9pBt/Ad7R59VYaZpz6q9eJG/QMZW7BdAXE687420SZdAmX/AsQasZD2MzrkZ4iEsz4jOvlmHt1xhq7qNIdODfNM56YKcmLeImVf/2Iucq9vSP7pABIQ8DaA0c7+j9iO6+MfsdRWblzucN1iWayPzkrTJdEaXC174ClSesKY8jmiidHZ1n+0WWEN9IgMmf+3BTvssTuTNV5s8T4kIChhfMPIUpcFCqfRzBHNgMfPNvC6UgzOgOdgogexGVfE7P9vCqoZZ6gO0HTQ1xn1CiL1VGSsJ3brNLE1XNfiPvKHwppOGSwQDelqiItERpnYnYcBtAY5rMXy6RCSYJXib9lqnwLAzWI+5DFM6+2RqrYZo9WdzDGWTWql7hNcEuAwclXc2gwmeW37r1HzQInkm5MiNimW7lPH62LoZeWlbl8UqpaKLQYHqUjT5XUcH2zpLtLCpfvwW2Rgdc79Quedld1J9sRFjX7lR5yRo0UHHiH6WmzFhHxOrAT6HqpyeRgb26sZW/z9e6ANSq+kXZE81paZe4P/mZmceTbMnZB8AaUqlmWJGYNV0XwmVzxw1SQd2DLMvNUAkgQNEXNhqmFkhkVHi8PZJGkMSr3jWHWBtiS7VN7t0xGwzAfjNHwZenzUrbkT/U83aA9o9RPT4Z+Ds6QnZ66rOTYGp+yjLqzItEySD1sy2If3uoqaY8wIxWERoCGICPC48L+thNB+1s0pmr8f3HhN24Ls8tkSK1WVhGiKvFysBAvAjDoxFlI0vX51SwgdIo+dzZMuV1NoDIxS8cH7l8i7aUZH29423wPTggQpu1daWorY0qAxJmQghJw25ImjtznIlCX1V7MGHe2w5vgcoDHPSDi9NLZjrj20diy1wKoyu2EOhHp0cDVXqD1RMGYO3dOS/mUzktAArlWPFqctCTZWQ0IO5RidESMTBk6Ojq+RYnXEwc8ck7wg330xnDOlQ2bTmCbAsmuhkC+rAJw5phm9DCDBxNIyNl0JappfoysZvQP0XGGv5n0XoW/eojzdyHPbfNlOe7i66TXnlnF+qacp8MfxitXvL+Kt5w2sY1hKWdhxRoAqX08X+kWbmLdxseoZsIwwzdj+JkRl2aUNsEvboeWrtPyBCcxQq+sjWJi0N7px56W6GK/gdICQVEMcd8ZkpenHKqqAo7gLeMoUeMwYpa3F77lsO0LOmxwCXf8cbPchgRLSA0TM/oxBzA3vdtiyGZC5kLsQ+5fJG+lP5tn2zUkE4E77uUF1eANBsLMhkJsrlPGHm77sqCXnJeQjnppaljf0iWCH85/DUgbxj0HxFiQHY0+2LGzt445Ar5HdqV/9/gs8c1W19o6tNoC74M5dn3GaveUqC4o1sMKUQSf+a1VPOsfHVC0mhgFgTiKdOcOuJ8ww26slD3jTZooY6eHRROFYx+oJeHvc8hz74QIGDYUEq3IC5C0/O4Y+xVrP6ciFcrDPiujO5xuIc0dvJBLjJsCwkpkVxP4q6QPgxFzc7hz9SL1zuCGabl0/lwhCxKQRyYaoUDBikYcZwhs+2d25W2SZvqwRRyjcOsKgXywPHgcp6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a556a0d2-d384-443d-84cc-08db6629555f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 00:59:51.6055 (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: mR+Sxd+G2jWABlPaa4jWyqrtp7sW9ywC/3g0MP7Ve2EoUYxEmBnMNQGz4wxTkRTC X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4085 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org These are not used outside iommu.c, they should not be available to modular code. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu-sysfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/iommu/iommu-sysfs.c b/drivers/iommu/iommu-sysfs.c index c8aba0e2a30d70..cbe378c34ba3eb 100644 --- a/drivers/iommu/iommu-sysfs.c +++ b/drivers/iommu/iommu-sysfs.c @@ -119,11 +119,9 @@ int iommu_device_link(struct iommu_device *iommu, struct device *link) return ret; } -EXPORT_SYMBOL_GPL(iommu_device_link); void iommu_device_unlink(struct iommu_device *iommu, struct device *link) { sysfs_remove_link(&link->kobj, "iommu"); sysfs_remove_link_from_group(&iommu->dev->kobj, "devices", dev_name(link)); } -EXPORT_SYMBOL_GPL(iommu_device_unlink); From patchwork Tue Jun 6 00:59:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 689805 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25DA9C7EE2C for ; Tue, 6 Jun 2023 01:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232645AbjFFBAA (ORCPT ); Mon, 5 Jun 2023 21:00:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232455AbjFFA77 (ORCPT ); Mon, 5 Jun 2023 20:59:59 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2076.outbound.protection.outlook.com [40.107.94.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C697103 for ; Mon, 5 Jun 2023 17:59:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C2iTZCQt7igALPBPGVCm927qt5+3HVyhVZIOx52jnU6KD6JCxWkG4Xs4vmHnbJt3V6pBDfgH8E3lY/k0Hc9hGJWBoAOOwoh/8QGt/jEzXA82xA9FRWQBTJKgvNcw+SX3XKBv406RzQzEmzx+OGGXqUWbO41aoEs7WNkENHKytu5u1fT1izIFjQqgKv1xTA2O1Hp3oiTR+EKMWifD3OW7tdxBEFL6cRrTvRmXLFWl2QnWLZPyft3GH6M+CLy74UtKtbhl1tPdRPRYyRwO0l2wgnAvYKVJ/vs5aumtS5s63NF6VNA+LhgumnBvkrIUt93+aHzxM5zQLdmWjxb090ialQ== 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=LD+aZxD7prbAKwYhMNTTFLzpZAebdsaAwXEyKTBB+9Y=; b=HuxGzFSktC2SWcdujUYkvbGpr2k+GtvDd3+/HTmhZcEul1IETCCKzU2cMMzcQrRKWW956pOVZzYPhO0h18wh91kjgJivVo3JS4nc3mMd/dyEvvav6/dzAUZRHahcYNkPWAGjf3M4URfn3GkFtcuiYgSBx6Lu1vD+JcVwN8p2oJrC81ZiRuSha/KQXcFTH0Jp+4y4JSr5bg0HOF0F37MndbQ3I+F4i+Qk8pjEYVkddoZ+OfRr6sCxGLIh6ORTatH7oNEyNVs3MyavdR4PRvi2miL5UY2LBjS6Xhx2piSA6UA3ovrq3pY84d4kA1ahcSylvbHTsFbQfeG8yK0HFzFxiw== 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=LD+aZxD7prbAKwYhMNTTFLzpZAebdsaAwXEyKTBB+9Y=; b=rwsNx0Fwx42sPRhGCaIZrL8r2D7lrxx0ETn9dxaxo93UfI/SGhQIv3Yav6GyLhm4TFU35E+G5KDAesnCESAKxPiubOKq/7hEJEyrpDYdFtOiRF4FJ+SBcdBfKGi+VGKzFT1dH2PbwdASjvws2fefLOZ0AQ1R4QwAZkSpBFINyqtLtWaaMe7DwWQRewV+K8Bf164nEkWQovDvJtWDREJ0o4/xszKgkGDYBdVDQF87NFyiAW1rbWRUf32VFF7QA526RPgDrQttLF5vYBZpYK4+68vmYCeXxqUb/7bed/qyHhhEL5spKhJwpzY0NE+FeHrO8EMpZv8hIXmZJfYAumDJXg== 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 DM4PR12MB7765.namprd12.prod.outlook.com (2603:10b6:8:102::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.32; Tue, 6 Jun 2023 00:59:52 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.028; Tue, 6 Jun 2023 00:59:52 +0000 From: Jason Gunthorpe To: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Kevin Tian , Nicolin Chen , "Rafael J. Wysocki" Subject: [PATCH v3 08/10] iommu: Always destroy the iommu_group during iommu_release_device() Date: Mon, 5 Jun 2023 21:59:46 -0300 Message-Id: <8-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: BYAPR11CA0054.namprd11.prod.outlook.com (2603:10b6:a03:80::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_|DM4PR12MB7765:EE_ X-MS-Office365-Filtering-Correlation-Id: 89ffdc29-26bb-46f4-4f34-08db66295526 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lLvThqBC81+Hm0NtJtBR8miyk/qrjN3uju9KVNz/ZGKItxYqhPkMR8aYgOKZPVZ50FYaNfZ/wZ6HUd4I09zLVHpksUguKie2vYsGEPDkdRgC1fQwh7Cy+m67AonD+Z2PQD4am9M6oRGweciLZ8wYM6zBOoDl1b3cjfcBRNWSgvB4NZk8L07b1Wh6GPIF4qRA16rXpFqtWeYkzdpryIcvXHWIOTuKUqEkLRvUBX2GGvqZPdtXDwUSSEO+Ax95EJ0H1qmEgK/bCFeDJ4/BvsmQ9qx03DAjFIHIxbG3Ml6CuX66pdwuzXqc9l7QhKv7ploGl7SVccb8VdoFBFExPkR7YiuFJrKbymGyzJtXYXfqEKbYZtXXBFmnBSzhyq7rTPle9l5wIPQBd2yPKoDw9ImmZCRXS6/kHfH21ASO5lHEBEFcsDs7p3eMgNADq+MkuRuuNdeGij5K0F63oqbOHcIEIYaip/CDLxq0aHbbkhOy0D4kyCWsM7/mfD8TlrHZPPzp+ABdq6PkfIDVdExR7gFyoNAI0gk2vgroR+H4biNlt/ioKJ9kXMYdJ+zems+stV0AteabyXaRMQB2wEgj/zuE1VRMsk35mVl0IbDy8H98jMg= 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)(54906003)(66946007)(110136005)(478600001)(8936002)(8676002)(38100700002)(66476007)(316002)(41300700001)(66556008)(4326008)(2616005)(186003)(6486002)(6666004)(83380400001)(26005)(6512007)(6506007)(7416002)(86362001)(5660300002)(2906002)(36756003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zkf9UnjogYNDIsuy9AifvqTeAfAEthpMWQzC4D6DF4h8L9+rfqnn9gw+fc+BgPo8FaA0HsA5AGWHL04Aq+oSYQlRO9h5rdV0KuOmn3EOvPSb4+McMd0A6o+vaaUql4bZsCOSa6OdeUKeB8E3ySubO9FPC8Qjd4pbM0Q0tq56w0JTWc0padAVP9VvQt3+f8mVlxE2XY5zm4fCp1CryWXJCIr/WB1AkZFKDqKdrkmLUKOMIbeT3SgZx217cYUFyRfPlnAY9LklCRFXG7QH19iVWlffLgVRAo0Dja+lSFciCiqt27n6mZI9WFtEymGYuZfIO5Hg0833ZIlVnds0Q/Tc6LdhutCTyUs5Wx9p7tL0Yz25UI8pyU2SpPwFtFOBPPCnssYkqg6VPW8VfC4rA4KxB+0dPrW1P+qr/C4leG4COaeEC5yauJ3GimC7qPx3Vd2pI9t0V4cj/ajS5V3Wn9kBzLvPNaE+5VTfOU0ndJTSo22j0HGUSfQ4Igk8Y3qFY6bc/hpitiwEARi1B6VQWRaM1Ynp4LjXdMPlDU3T6ojpSCYOapGkecuJOFoHE1EMuJNseCTom79ZmWbzr7Q0+eKNFWfmQOd6cuISKunw46pFdjc3fzF+egmsGIQWmdo/N89heGLJIFJeft6mJf+SAWbATNK5F9ccXhH5n62YhA3jjdmL1gq5iPSOYUB/ilF+Z5B6wtH2DYfiL+wuPmrRnQuJKLwafjPWrPugsXUCCbJ/ZTHigQF++E3EY2Rtoo+qvwsTKDyMoCjaI2TtmCWfG/vXkRccElu4RIewtXVegJsgUppKaXg5+1C4nB2IM1vJSXYMvxpufVLjL1nXOS/rPLC43mdjM2hsKdd53fxWuexnTgnIUI/ZQGIjnRHEfs64WxUEbmbvW7ghGSiPXZFege0PVnvo43z55dMBOCvaHILBEQ3SE0dG2DG1WMqdViRZS13/lR92MF0ve2bnl1C9vi9MLbvb1kxyonLQmY2X9oBm6g47NYSDnYg7vYp9/6VD29NiKaN9Z7AU91FteHaomaTD7zkjbCnjUHsiLdl2c7ZNLVvB0qlJ5QBZY7Cahqtn1XBc2H0TQzGeoitl1QHF2RpIBzBiP7TLDPIn6ZMDqg32FtDlBIh2zvlPygEECkd7rjb82d16PnIpCoMD1FWVinXYPPcHB5MymiiLWhkjSd+Bv4d6mSfYw0Hwhf/v964qu79k5e2My4W8vp2L2E7Ne/o1eP4w8cORQE/1F0HwZc7+V1NuY+c6n2HY3Ou+LkB8Ds8IWG4pbiwL7rNMY0IYbbf31jdNBVWywz1sOl++qtBEJNpfNcDHj/oj/PqANqcvsVGb+pIIBPvLDGaxHGmDf+2yrfgXifLCUiWWRhLsb36VFQMvBpYddewQVMwVEUQw0jn5ZQX+p7HSfUSTDx82C4Ms5ArswZoOe9+kyaz9GI59zlnUnwXzN5hPniQA/AqbyuoDisvSm/z/iEGD4SteAX+jk/2YMpN0Wg4xTLZdyNkKeg1lNCXyG1KXoO6BM4djPEkQcyMQcZS1j1SRGkS8Ey7NauC8Uf7O0vTFIeVTTgimo7rk6uyoAW9Z0f+55j2sAvgZ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89ffdc29-26bb-46f4-4f34-08db66295526 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 00:59:51.2304 (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: iLonQWtX8tJ/V+/Kw2CLzR8HsTmO3oTa+UcSViFtj94DpU12sqp98WZbe10pcAJa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7765 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Have release fully clean up the iommu related parts of the struct device, no matter what state they are in. Split the logic so that the three things owned by the iommu core are always cleaned up: - Any attached iommu_group - Any allocated dev->iommu and its contents including a fwsepc - Any attached driver via a struct group_device This fixes a minor bug where a fwspec created without an iommu_group being probed would not be freed. Reviewed-by: Kevin Tian Reviewed-by: Lu Baolu Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2281f3281ea4a0..45d69462ddedab 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -574,10 +574,8 @@ static void __iommu_group_remove_device(struct device *dev) iommu_deinit_device(dev); else dev->iommu_group = NULL; - goto out; + break; } - WARN(true, "Corrupted iommu_group device_list"); -out: mutex_unlock(&group->mutex); /* Pairs with the get in iommu_group_add_device() */ @@ -588,10 +586,12 @@ static void iommu_release_device(struct device *dev) { struct iommu_group *group = dev->iommu_group; - if (!dev->iommu || !group) - return; + if (group) + __iommu_group_remove_device(dev); - __iommu_group_remove_device(dev); + /* Free any fwspec if no iommu_driver was ever attached */ + if (dev->iommu) + dev_iommu_free(dev); } static int __init iommu_set_def_domain_type(char *str) From patchwork Tue Jun 6 00:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 689802 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 912F8C7EE23 for ; Tue, 6 Jun 2023 01:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233001AbjFFBAY (ORCPT ); Mon, 5 Jun 2023 21:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233276AbjFFBAD (ORCPT ); Mon, 5 Jun 2023 21:00:03 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2049.outbound.protection.outlook.com [40.107.100.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3490310D for ; Mon, 5 Jun 2023 18:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fHSLxbSWmirPQ0yHN45JcRwIXzVMm7u5Qna4bFm/qhvFWuYY8WL5tXRizW4odw9Tr37azARB/H49cYCAXIQVZs48QbKnkZcgb0c5shSlSIJ/lc2PD6kmzxMZ5vfPrKzdVxM0YLYxVeft5Ozb1lZ6+CPV1OKUH+bxW4jnxAIalCOyGzOFnAh1z0PjKnc6qv4uxQ/j4fxBkPiseByzc57uEZy0tgOqCVmIY+ErStvhCAkD0a+bo2i8iMXsGnaxc+Tf+6aojUn/j5cEkSNpJH7XaIdvLM5gd5ct/AyhcS0DMiDflGeEdigCXB4qG1HHsH3GloLobySvLLXPXsQozxE8KA== 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=QV0fBNdP8q2LSAZbZz7kY45ymHKMpmGt0ba2hCmRtME=; b=W2VzX7AIUIJ/8WZy0otp+uIb2af+B/Aw1r6thdUHznu4YIpwpe3EcRhiam8kzIUBfQJmQt37oAPOjw9I2HNM/f42XbDvp5AOI4BLYT1vmrgVLPFDdyLZWi0R1ESCJlNrxMJZhQfk2umPu/Xt+xY83jOFvOKCIzs8kXqQ7W5+vKnwwmfHxhmrKMjecHwNwVVEiFfo04qUyCRczZejoA0MAfwGGyYNO2MpmCocvUvdHGtKh9tcsjNYdp1Juj8ZZi87VlFJci8mggR6zIuKVGj3VbhAq/QZxuzxf2ucoga2JIm+X+TIG9P54bLIz6zmH5AsUGuemFmGP/qQb5DjPkkcBg== 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=QV0fBNdP8q2LSAZbZz7kY45ymHKMpmGt0ba2hCmRtME=; b=FbHi/fV3bHIppvEaf0CG9CKlqq4RyBBZ21VLtReur7oqNV+s9uME9sWypiemjb1siXmpTfZK/BeNYlWncxaDnM1vHLPeh7IOfZJ6iuZubTxVcocLOiI+KfTbCz9H4j8bvpVAN4mr+pTMYXMvlU59Nsey0FOJao8UUTMHa7NV+xdTpqXho4SVVdgX2U6kLXh6J3rwFabuz81uVqg7y4z/GeUrObEfYTuqtuyDq1IXIPGFAPrcVWnatZj17RGYgZluFqEqfweM7v2Dd9+JAQMc+Be0KZ4VYJmKTuXi5qjidfB/2/kL3NevuNEq/IxHCbLGOIdpzCkEqtocVq6/wCBdTw== 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 CH2PR12MB4085.namprd12.prod.outlook.com (2603:10b6:610:79::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 6 Jun 2023 00:59:57 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%6]) with mapi id 15.20.6455.028; Tue, 6 Jun 2023 00:59:57 +0000 From: Jason Gunthorpe To: David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Kevin Tian , Nicolin Chen , "Rafael J. Wysocki" Subject: [PATCH v3 09/10] iommu: Split iommu_group_add_device() Date: Mon, 5 Jun 2023 21:59:47 -0300 Message-Id: <9-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v3-328044aa278c+45e49-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: BYAPR11CA0050.namprd11.prod.outlook.com (2603:10b6:a03:80::27) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH2PR12MB4085:EE_ X-MS-Office365-Filtering-Correlation-Id: e2b420a8-1add-45f3-cf98-08db66295726 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YNyXvDHyLSyIwtYbqJ2iggFj0YOO2OonV0mUFottWAUJ3xMugNQvOqwc/L7GrEqSWAUnSdnYWODsC75ht0ajYH/DZYtBMLuDLVmEA6WBCIXVZ9msCsyFPCiMXqz+oIGXUSlXIN9qsWevbzd5rWbyzkTRV4ZcUZ0OSLZNvR8G6+vDvk9RF3DUdImqe8VqjsMGBUuyGo0Bt11d2806UGVi9vl6wiiuEe5SOmd3TPwBhOpa0zKHBOKUuV0Ee1u9nG+ci7s1Ycyq1BhHNeXGhqjVmNAJ8ZfhDTxgQEHCmQn6UHTdVRQ4cGwLT4A6oKP4I3yGiha2Lq5WWgLZL48CmrArHPeH/pWE04PrUHDghcQMWUyTMXGgDMIeMfoLWhaxUMt4idb6tGGcLdcWSTL7ZlmeNHFOFcwKLR1t28hzeD2UJ0uFOUkjMxZ40+u6G65X0FnTq5bGWGWxfbSD+FTKm7XNOXXLYbclpu0VstID/b2xithNZD3qBI9M3cXMLNLcBg+A90GlSUX0sX+Ovwu4AoudajS5E5NT1diY3ZcHayh2o93yyPw2jizbVDacdg2jG59uejt3hJNnfsfapcW/5ABilsc8Ib/cMD//4EHzPjF/VZ4= 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)(376002)(346002)(396003)(366004)(136003)(39860400002)(451199021)(36756003)(110136005)(54906003)(2906002)(478600001)(86362001)(38100700002)(7416002)(41300700001)(8936002)(8676002)(5660300002)(316002)(4326008)(66556008)(66946007)(66476007)(83380400001)(6506007)(2616005)(6512007)(26005)(186003)(6486002)(6666004)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /IsU54zcRCHQQRtlR/mT2RICXuYvZmTBkcp6P6HzjgFp2fhBZsBxkMAcaQ+kn2FaZukftnoNbfcO3ljnbAcENEqdyVHkjdsP2lqIJmk0aRmP4O3vvOZMLXIHuJ9AnZbezPg7VcSO0keO0oCy/DDPLnzPqHaHOlg9HQKE5SICxsw9YrxADlssr3uwkiOdYfq060IKZ23BPRFKFXuAgAh39QVmUxx65HJtn33dmPCn6MSg+S29QISfI29TS4Z+rv/DmzSgi9hfgmEJBcY3eOFmDL/19n6q9GuLnf9yHJnnCay+fIhPhw4PTNC+xMPgRWQxZwCPnWuU2LNNYwjhq8ybj2Rhbt2HmJKGFhm92eCPDOEBAjmv+gMtKAUyOeLtlvFJ4blhHwxfOlIdLKUPKUbUF5+/XVkX/8hbiDG1xUngmYDbUgjwD2hiMEM2N+iTiGrPqNbI5xFd5n0KfAkzKT8O94EfPusKMaN40MyRBRYP3A3W0XWoS/8CTM5oQCupnQ6+6UmN3WhfZuqCWrE4/KkE/PVd+oPg69/c5QCWrlE454LzZNT/Dg/FH3Q7MrVgcAsQH+8+SrL+9p6lwm3I7s/a064LSA64dPWJ0SrmfwUTgu7U1+Zp4hGqqv36vclc9xDKMVKjJEBoh96f7TcdEDWZwEn9jueEezZGxH/pY1T+Q+dcxtDkjq1m+MYSOQSsp5PBspn1h8W+0ig0d6klLwX2mqs7JsmD3Y3cgkAlSD//UCDOD7XuOmPlDxcL5qL2Lw1FxmS7TvZTixDGYxduINtURcnPWHw/Z5W6Spa+ZMhgJHyBYzU+GWkgh1mAQfaFWl8XuWndJlC2GfE40Bc/NqcGPMKfiw6EzXcTdbshnhWD7aR7qpcctsNdU5akKoOk6BzKtetrYbOMroBCpm5R9UdQLxw1J64tZIKkpYrIhhHetmw5BNE1KNmwTAdT3+9gpfxQdE6HL/+9CseP+nY3Dq6m+i32vy82Y6U8j7Jfk2FIvsFirH3jE+/3f2+P9/jOQ7jJ98xwAM/Bhz33617zEGO2x7InSN4x/TAQnQorTVyciWmXpMDIrd0Qp0wdblcUvwqoxlJijJ1rXRZt4tjgYLwALPLW369ebRaT6N7qSXUPowhALpByvlfMPA9Oh770ZSGaSYIuO0rSXCccWSr4LZx1rtk3SUNOzHKWsEZoAtK2EVghYEEFHobbT6f33ZxQPy1xR1J2KJKm1JiFpd3w99eZjq1e/k2dWzqPJ47fp+HzsyV52Iry2jXvaSy/nQ0eIopVDK+/7Pdot2VcgotuKBmg0nMMoTdTUsijReJ53Xo/aqa/P0rr9Nm2+AAPss//OX7QJPB6jfmciEpxC4ZfkPPR/Skz/lOZG71PjvOt7L7kYm0o+FoyPrdTFIWKfDpWLcnzv1JKIzTuFWQRnsp49BL9Kr5UcjnRfZlgUwqlx5lvev8SK5Cgi/dozSrjbBdH8z0iZAGnyiU3V3gRvwsTMZxlPJhbNEHjMwhS8q2afAr2XZXNA4jhgy0EBXIWq90j6uUxsi3Lgy1TtM604sSqnUQ7NPpuY7lfUuoAW+sQ8QpKeG+gTGxtjLIgbwuhYz/26Ba6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2b420a8-1add-45f3-cf98-08db66295726 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 00:59:54.5940 (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: HChCLQprQRLVl40nTvxrdl0d/rGUe8IUoHNfRGwXMPx7yIhsscl8PtQuWJJ3uQne X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4085 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Move the list_add_tail() for the group_device into the critical region that immediately follows in __iommu_probe_device(). This avoids one case of unlocking and immediately re-locking the group->mutex. Consistently make the caller responsible for setting dev->iommu_group, prior patches moved this into iommu_init_device(), make the no-driver path do this in iommu_group_add_device(). This completes making __iommu_group_free_device() and iommu_group_alloc_device() into pair'd functions. Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 66 ++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 45d69462ddedab..4da3623d7686a0 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -129,6 +129,8 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain, struct device *dev); static ssize_t iommu_group_store_type(struct iommu_group *group, const char *buf, size_t count); +static struct group_device *iommu_group_alloc_device(struct iommu_group *group, + struct device *dev); #define IOMMU_GROUP_ATTR(_name, _mode, _show, _store) \ struct iommu_group_attribute iommu_group_attr_##_name = \ @@ -435,6 +437,7 @@ 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; if (!ops) @@ -459,16 +462,17 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list goto out_unlock; group = dev->iommu_group; - ret = iommu_group_add_device(group, dev); + gdev = iommu_group_alloc_device(group, dev); mutex_lock(&group->mutex); - if (ret) + if (IS_ERR(gdev)) { + ret = PTR_ERR(gdev); goto err_put_group; + } + list_add_tail(&gdev->list, &group->devices); if (group_list && !group->default_domain && list_empty(&group->entry)) list_add_tail(&group->entry, group_list); mutex_unlock(&group->mutex); - iommu_group_put(group); - mutex_unlock(&iommu_probe_device_lock); return 0; @@ -578,7 +582,10 @@ static void __iommu_group_remove_device(struct device *dev) } mutex_unlock(&group->mutex); - /* Pairs with the get in iommu_group_add_device() */ + /* + * Pairs with the get in iommu_init_device() or + * iommu_group_add_device() + */ iommu_group_put(group); } @@ -1067,22 +1074,16 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain, return ret; } -/** - * iommu_group_add_device - add a device to an iommu group - * @group: the group into which to add the device (reference should be held) - * @dev: the device - * - * This function is called by an iommu driver to add a device into a - * group. Adding a device increments the group reference count. - */ -int iommu_group_add_device(struct iommu_group *group, struct device *dev) +/* This is undone by __iommu_group_free_device() */ +static struct group_device *iommu_group_alloc_device(struct iommu_group *group, + struct device *dev) { int ret, i = 0; struct group_device *device; device = kzalloc(sizeof(*device), GFP_KERNEL); if (!device) - return -ENOMEM; + return ERR_PTR(-ENOMEM); device->dev = dev; @@ -1113,17 +1114,11 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) goto err_free_name; } - iommu_group_ref_get(group); - dev->iommu_group = group; - - mutex_lock(&group->mutex); - list_add_tail(&device->list, &group->devices); - mutex_unlock(&group->mutex); trace_add_device_to_group(group->id, dev); dev_info(dev, "Adding to iommu group %d\n", group->id); - return 0; + return device; err_free_name: kfree(device->name); @@ -1132,7 +1127,32 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) err_free_device: kfree(device); dev_err(dev, "Failed to add to iommu group %d: %d\n", group->id, ret); - return ret; + return ERR_PTR(ret); +} + +/** + * iommu_group_add_device - add a device to an iommu group + * @group: the group into which to add the device (reference should be held) + * @dev: the device + * + * This function is called by an iommu driver to add a device into a + * group. Adding a device increments the group reference count. + */ +int iommu_group_add_device(struct iommu_group *group, struct device *dev) +{ + struct group_device *gdev; + + gdev = iommu_group_alloc_device(group, dev); + if (IS_ERR(gdev)) + return PTR_ERR(gdev); + + iommu_group_ref_get(group); + dev->iommu_group = group; + + mutex_lock(&group->mutex); + list_add_tail(&gdev->list, &group->devices); + mutex_unlock(&group->mutex); + return 0; } EXPORT_SYMBOL_GPL(iommu_group_add_device);