From patchwork Wed Apr 19 16:11:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 675913 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 16D59C6FD18 for ; Wed, 19 Apr 2023 16:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233170AbjDSQMm (ORCPT ); Wed, 19 Apr 2023 12:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233409AbjDSQM1 (ORCPT ); Wed, 19 Apr 2023 12:12:27 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2056.outbound.protection.outlook.com [40.107.237.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AF694692 for ; Wed, 19 Apr 2023 09:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e2gdzuPiPGvLbAULbJRD77GDLD3HMF0Fr0IoYH4drYIf94FQynVyADSzBd5pudi7H97vgP7SJGvdVllsk7WsTyB6ix3USs+5AxtqBt+IRe5t5Baa6Mp8J83tGYrWGbHR++UhUmYLJQe8vkEqpNc+X3p2h/p8jO3bUtC7EnAoIfc+1AWgeWH4KAG1eHYN3dzx7WThop4FyemU+Hn3NGrx1a9+HOHU0IRiXjbzLqrOszSRiCnjPGC7iIzA3/uURlXfPHvwQLWn9U+C1RoAwhCpgjH9HGM/9XVFanRb9bb0UcJvqiGOM/3as08MAg5I8KYPTLNRR1Y1dCsSu1fytbf9xQ== 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=uXROLBZWq41chf0UWWjKrlZqXcyr2NcZSeQQ5Hphdt4=; b=DTB8rrC9chuqbtnsJlWkr0VZ5O6nyozhW0O1K0wCyJ+xxXTapXuIlbDS92QlY0xmzRoYGvhAB/H0X6uyKvbW31iP7IfCcX13QJtiFKbWoPZXHWbS2R5gZN3wxkxa9DhSCY5otcM8s++WF1uUB2v+OI3AxXLFbWc3lNMgQ3w0EGS0sXwkquR2pkF3Al8iglLxJh9H92eZTtt9DpKwn+E0xaPS4+s2LYBWrM8/k6rlN+Gz700jrcAn5FFidF82d50LQis4Htc2G6Oqdg9NIbfagkT4bBTk6wnoZDgFoBOdAU7E2IsIfrgtW1EWf1kjn6PMmXp1bnNcSx0qergDjR7R+g== 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=uXROLBZWq41chf0UWWjKrlZqXcyr2NcZSeQQ5Hphdt4=; b=Ik35qUtnrQo63VLUyOTrTMHHQEAH0Mz+jD1YTznEY8c2QLXIQqkuYjJEiXxtqY0B6OCXlIKIUxvosc8Y204GksMq/D9MUfbgXGNbWgtnIOzrKccT080iYIYemuyONfo3q3lWC1vwTcmJhZpEJdrU9pFp57X00tSHGNXJuclMk4Sp+as4v84kqkTuoOSVPl0ZPTEb7WzdFjqR50VSI1/On8YmPHObUksxGlnj6xglMFVu0p97VLvvMtYINUFzvomosKoAkP7p8HLovXysBkafrulkXv/ysqRBjxa4GwjQh6rn/6fvpP9LTulUvmXKRNiAfCcZw+AoTEiSAR2BebNHiA== 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 MN0PR12MB6342.namprd12.prod.outlook.com (2603:10b6:208:3c1::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.20; Wed, 19 Apr 2023 16:12:03 +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.6319.020; Wed, 19 Apr 2023 16:12:03 +0000 From: Jason Gunthorpe To: Lu Baolu , Christophe Leroy , David Woodhouse , iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Nicholas Piggin , "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Kevin Tian , Nicolin Chen Subject: [PATCH 08/11] iommu: Always destroy the iommu_group during iommu_release_device() Date: Wed, 19 Apr 2023 13:11:54 -0300 Message-Id: <8-v1-8aecc628b904+2f42-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v1-8aecc628b904+2f42-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: SJ0PR05CA0177.namprd05.prod.outlook.com (2603:10b6:a03:339::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MN0PR12MB6342:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d768044-573e-4e16-4295-08db40f0cef1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DIKW/4pLKXCwL2bMw0GdK53xznvgV+ZM4zEbPV2DpRydBNQ8KIg7riHSv/X84+TTZRd+LfPvIbC6IJoj2eWgdrnPVvqcrsS1rhXQqr1QjGbuWjUCIcE/MIMmzhylRe9VMtc8nHotENmWdjXxPMa13RdPfXlTP/2KKkL+bcMOa3138N/04OGwHeMzp3sWWgaU+IKWLzevGnfLp6LDRctVW2NTX0MDQ1e4QTAPNYSnkmXNqsAAYPPYC0+rMtfS51xEWn6kheDVBKgp4WMaAc3iOVDkbiIRQdG+O1HsgPyxkGU2uVDqV4I0FR0ld7GR+l9mpdL+3HwOYrz/65TrEHS1b8AMTdzTdYeKmBfQ/8tbVkUY7PqPz9AxH1MoNLx2q4wv2yiSIl9IAYI0R84lWtAFA9vX1zX9ZUi87YgpUVkSw/SNYaVAlbaauO3LT4ZSZ2+mk30WytuKUmYF4mBbV5QPqJeX4Otylx1q1X5FkDZkDd6cve0bhIZCnkvOXxdMn+tZAIqwQalCxH/sE+B3eK7ucebM6ivo1vGVhnK9eozpuDFRPYgCsWNsYfJ6YJM6gLV9jfMpak1LfHhJdssUxzG5cGBmbE6kYKPg5LlqcdUzBJRidJKv+Jl3xNGQgPywoHwv 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)(396003)(376002)(39860400002)(366004)(346002)(136003)(451199021)(6666004)(6486002)(478600001)(110136005)(86362001)(36756003)(2616005)(83380400001)(107886003)(6512007)(186003)(6506007)(26005)(38100700002)(316002)(921005)(66946007)(66476007)(66556008)(2906002)(8676002)(5660300002)(8936002)(7416002)(41300700001)(4326008)(54906003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2NKee0phDVWu2C9sVDaLY0Qq1YK1KRYYghXDntxBW1C97Yy+Qsn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jptL7CTPerEhyMzE5r4T9OwDIqkY9AvfAdVQhutRSPWBLbK2ZzkgRuew4QFSZPxl1nXMMz3zLhjyDvsDsSbcNh4vynHlt8YCclniTJCoBz/VkZ/DRQw01sEOUtnf0FA6pSeKRf7QT/OuLv/PAspxY28mE7s5vKuliv7CZqZX/RyYr7UM2618xaOkms4F49ZEb36FEmePUEKC6BYASnStB/KRV7+MJ68IjPpcyEdqCkX9DsAWQjCFFHkggXKfhQdPNX7gz8YP5+2GDKsLpPabjxU4DhXUZ05+bPenTA4ozjNMpvsrO8F1Ue4wdYLWBR8DOzEBY+RZ+jSjwveZoUIqpouhsoI/7H9WKMplaRl/vge7euOPVGopuEYBDXDCUBAf3eAFSupu6qO6yRFEIUyTQ3bsdLKup8a8/P3I7i3DzErRGBXYjC6hroUwwwBJmARXtIoR1Bn4FfN1GvA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d768044-573e-4e16-4295-08db40f0cef1 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 16:12:01.2197 (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: 1UmE3jrkFKhbNLr+EnP5Oebi5nxl8HqYpY54/AXJpGIiN242ykJG0z9eq9hSHWGR X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6342 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. POWER creates iommu_groups without drivers attached, and the next patch removes the open-coding of this same cleanup from POWER. 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, eg for fwsepc - Any attached driver via a struct group_device This fixes a bug where a fwspec created without an iommu_group being probed would not be freed. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index dbaf3ed9012c45..a82516c8ea87ad 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -569,7 +569,6 @@ static void __iommu_group_remove_device(struct device *dev) dev->iommu_group = NULL; goto out; } - WARN(true, "Corrupted iommu_group device_list"); out: mutex_unlock(&group->mutex); @@ -581,10 +580,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)