From patchwork Fri May 19 18:42:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 683954 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 347F0C77B7A for ; Fri, 19 May 2023 18:42:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229650AbjESSmh (ORCPT ); Fri, 19 May 2023 14:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjESSm2 (ORCPT ); Fri, 19 May 2023 14:42:28 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2067.outbound.protection.outlook.com [40.107.96.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FE971A8 for ; Fri, 19 May 2023 11:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i1P08YbrmpNxnRdrQndb8YNNHq8wfMno+MQqtPhsi3BVm+WCE/I5dkUGRDSrqYbcmzn8j8iirZJIld9PE7t5iaFwuykW1RBD6ID2et0RLSoG0wy0MVqLO1vLE3LcgpWu6oKMF4rQqecO+cAMPV2kpfKZfbjDUPVf40tvYpxW62biKGmZweuYWnEqabwMZborVYeYRNQyoliz6FuWv02evIp+903RX9D7sffoJyYjssVymzT9Habc/dp5JBRQhsyYVf7fvUeOq8sxgJp0SiRSv6nmBRJZpo3/eRdiPWCqef/26e1w4XiFRTYeKi4NbBmW8T9spzc1GVYOfyIEgnHcNQ== 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=T5sK9T7mR+u37FgOSN9zxH5lJAsl+6bhGCeOIHAvo6k=; b=mLN+LrJosFYo2T4WOrdYRRkv1EceFg42FG1EeOaqgbGEd6YagQVKQWQ1EG+xt9GGFPJxW3ysizXYvfsCQQf5w7rv8c87DgI7AXZ8VcoVFQJMAXuvj961Pctxwxuq4Wy8NKOyv6uO12COiUlb1CCjsC/hVN9ajneSWg82nci2klJnKyjDBYyg0KcqK1zXd0V5MN7Xslz3Go+IPHhDSHui/bbqP3YUxjww2yeOxKAt7B8w0/e6mL8xnqMmstz2OViZaoESLZ1W/OtYlDUGcBUCuspLeX7zd/3GBk2ADacSv0KWn4nSfShfQjZxRspJzHn8ag1UWnr6aDENe0gXBk+1LQ== 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=T5sK9T7mR+u37FgOSN9zxH5lJAsl+6bhGCeOIHAvo6k=; b=KsvGCEvzfMT+Nu2Jg1TEqZOdV6RQpEVIeuJDk35q+YQhAcH0TwgZvyoxogEXWmgjVnquwDkgpZcizU02TRr6HD+AU8DXq/m+Om3NK2G9Z1zt1os7Rn6o7J2BBOMzIS0nZzUNEqm+gIqQunQcuuJbuMjM4caW8Xhq4FQ2VKc8pIzq1x0qtVa0LCh9Uwo5TolSWFLCcGy1e34GN3zDQ09JOLH9QC306OwLj+DaNso0Y7biRAvIYN5JnSrRI1Bv0Z353InGDkRkqtuE2RHNonoHOoCwYPEe4S7jhKAgNnF0hpkD2sT7kGkc045Qtwwq6Xz24b5lQZXwZo+VNG8Tm+IhDQ== 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 PH7PR12MB5688.namprd12.prod.outlook.com (2603:10b6:510:130::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Fri, 19 May 2023 18:42:24 +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.6411.021; Fri, 19 May 2023 18:42:24 +0000 From: Jason Gunthorpe To: Lu Baolu , David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Kevin Tian , Nicolin Chen Subject: [PATCH v2 08/10] iommu: Always destroy the iommu_group during iommu_release_device() Date: Fri, 19 May 2023 15:42:17 -0300 Message-Id: <8-v2-3c3bb7aa6e48+1916b-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v2-3c3bb7aa6e48+1916b-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0341.namprd13.prod.outlook.com (2603:10b6:208:2c6::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_|PH7PR12MB5688:EE_ X-MS-Office365-Filtering-Correlation-Id: 4fdc39ac-84c3-4211-cc6c-08db5898c78f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XQzUP0+pOQoJEZhxEF7hpGPzAc4ux4C4e1YsACw0RlJo0OSUD6SpEA2LEalERvB7yGNQeXGrhr7hXRtiSx0d1WK8bS9Gkp6LysQPyD5QvHuSUjQS5oTmRM4LJPvqlg8VVa6O3dLFOf6+rS1C5PEZLWOaE5pxsDyY+Q+3/Y2mgagaPjVTJJkEA/fY3H3WJ98ggxeghFU+ICtZ7oodhnm35tVdZePwLYFk3EsGyIVbTQSdJiXQVQd2Pwu/szIHj4hbZaJcJgoaKT75hZ5fJXp/npnWPq7pt8NwzFy17hExjo/uR66si4VrMRkZzPpzQ+GPcfU2b0KjW6FTxjPM0Hwu+SZcoehc1x567L02MWyUz1HTR4pTPoPPtxVCly/NhTLejMx45WsvGAZRpZJYs8bcCfupKTZz4S/0hLvBHMJS1PqDSQP1bmMPL9iz72M9x+rTgIpSveTofkk9Vsx+r0G0Y72+f0+3BIVDPIA6wQassL99N5736GzWUx7uiIVoYNNcHt4MQmpQ8ehtky/y8ap+9HeLXFfKOM2fm8dq1QxFC6zg5raie63/qDeZRHBxatXxg/SWuYW1vhiPRlh6TkWlsc8lTwylXETuHqkoftrQbas= 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)(346002)(376002)(39860400002)(136003)(366004)(396003)(451199021)(6512007)(6506007)(2906002)(186003)(107886003)(26005)(86362001)(83380400001)(2616005)(36756003)(38100700002)(316002)(41300700001)(6666004)(4326008)(6486002)(66556008)(66476007)(66946007)(110136005)(54906003)(7416002)(5660300002)(478600001)(8676002)(8936002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ugLYxoKtvwomSLvbUAhQY7ygVELZ6HiESEOyRazqmC2/4Ao38ayG9otHr4pfBcP5nYCADzi+3eVyg65SZNe36f/fRj4jqBXlLMfuJfGHBIIo7LdC/9H30oCr/Qdk+dpNZSmJxpkAv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no8FIQrTQKlkDrc3B1GtCLdbHW808Ms1iihRC7TO3LFomIrcqO8oqEML+6oWIDb97FKrRMzinEBzRMIXqzLyR0XXwpD/NavE11ivhw4gxHWqGOY2VrGN8KnWWUZwP033KqxIaHG3qjugqkreyVuLboRmS9qkcgrIYHMovBmQisTPDoDEziIPRwT/l3gF1a7M6qEZGObyvdz+O/4J/rycSX5I9uSUgHkcZmxb3mF8qn5OEtfbkqimWTMUkpk8uZrxIw8bzn1ZBaZ2dXBdHrrISJCr2in20NS3vVsLRdBIrlPpyvRWr7SucgzMvZ3GBmWkT9Cs1snKQw4dPYJ/giecUbQYN1e3EiELsfwYOhS861xaTCmk2iIG8d6tr5duUWIGP X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fdc39ac-84c3-4211-cc6c-08db5898c78f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2023 18:42:21.0787 (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: s48bNV2MMp7TRA+0xkdzBwhrB44YRsGTvx1vcvC8+NNeluvtBJXY1wDsIQGV1kGV X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5688 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Lu Baolu --- 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 69e4227bb7404f..6a8cbfd2274770 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -575,10 +575,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() */ @@ -589,10 +587,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)