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+McMd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d+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)