From patchwork Wed Aug 9 14:43: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: 712713 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 002BEC04A94 for ; Wed, 9 Aug 2023 14:43:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbjHIOn7 (ORCPT ); Wed, 9 Aug 2023 10:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233933AbjHIOnz (ORCPT ); Wed, 9 Aug 2023 10:43:55 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2068.outbound.protection.outlook.com [40.107.94.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D16A81FCC for ; Wed, 9 Aug 2023 07:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hcx8YrxNeOd5VzW3xP7MAkiLPMqF/ZFLQ92IykEWfrVqxCmB95P2Bwjz6pvCWMV9s4P/tjnNnfBpJCHYoW4BlUxiT0alJf0DJtf6FeujCZ8suBJOuaKDV02CvTAFUifNGSRWXrzEV5g57o90PytW3E7n0RsY44yf3MDtd+wL7Fe7ld3LLs7YVeX0EuC9/B9Ce5ctlM+y+VHUWlKY/CT+R/j8rs2AH2qV/nOWH8DmgJoAlPWY/evZ1D5fCajxS1je7xZkjTv2s6Zf2jmzDbByYrjMLKl1mullz65C0n/reBzJ2CNXPdPrOk5gwwwM53Twk2JDk2XPzvk6wJp0OToy2w== 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=LkdAutco3x4EvBL+RjTWnfwUrmOSLLFpYQm4R6Yqqzo=; b=YLVG4fAF4Fj0jmpkE8rPOqmdx/10bKX0lfylqZEvfo/rA+5A3J+WihrHxVq/gomVkv7F/BoZw2CQh9GQHa81gKC5wubfWzQNb45bsiQJr53zxrMWS7/IhqR+D/ZC7Hyhs6hP0x1rmVEcjYW6qUEV/OsdAe+VQh8IPcAnJKLgwxTWgxoxphYMb9F3424L2LzEqB4VjQA4ib34VycchrD7eXn35CSFD0DqSy0aBT6WSvniNM0UnfCKv5aw8IjbxOSfX653PYtO05cE0vu4O+vT8z8iSIsNLold47UY/34oVigV8QdTDRUex+hBUGm2Y0kfPEQqikDxnZsvgeOa+KLBYA== 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=LkdAutco3x4EvBL+RjTWnfwUrmOSLLFpYQm4R6Yqqzo=; b=BdXcJAXNzivp3xeFHvFQUpkrIJc1PFm8nDM16DFQ36YJZQpVAm9onYKhPiWlCDX6yK/y43pRY5zEO+VjE4CCL1V0BOh33B4oOFRu6xkkRN2rAZz2uW6hsevDZfYCL/21BJTtA/n1DrQVrdjMvUx0PH5CbzsaItDti+s9k/eUwALMKnNmAILJ7AFMsVkNswoR7T/SyzgdjMpPT06he3rXfPN4AuKejzrCbJ23blIkm/BCNGttXd0WeWk/kvCVwdwdwh8tGvrSJegLY2l72qvShgaFocGCK/Rb8qJ6sqENeGjNsxSv6y7QPywUl9KAYMXsKBxZ1vIBaDXZ9Twh/xGe6w== 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 CH0PR12MB5059.namprd12.prod.outlook.com (2603:10b6:610:e2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28; Wed, 9 Aug 2023 14:43:52 +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.6652.028; Wed, 9 Aug 2023 14:43:52 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Joerg Roedel , Kevin Tian , Marek Szyprowski , Chen-Yu Tsai Subject: [PATCH v2 1/4] iommu: Provide iommu_probe_device_locked() Date: Wed, 9 Aug 2023 11:43:47 -0300 Message-ID: <1-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> In-Reply-To: <0-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0079.namprd13.prod.outlook.com (2603:10b6:208:2b8::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_|CH0PR12MB5059:EE_ X-MS-Office365-Filtering-Correlation-Id: f4169639-b686-4252-041c-08db98e70c40 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 88/uqWvUCZ17wtN9uj0Z3kPHCvetZAsrHq+gK+7MSZhRNaa6I9B84YQGJagVtuB9HO3fUlFSNkydRFPICEefFTOWaVQ+O5CBygUho4jHh+AWRTwH0NzpI8xSrV1V15WCJEEt/MXqJVbLjdO8eaEe6VJsJzsJAnj92WVg8ITzCX+x4m9tegHgYaMvjhcqoYWvLCb+cPzjYLchMTQEf6ThwKz+MMunDFgibXEyM8hKpO+50anKuO7BfFMlPTK3fb9nzz0995hoOgzTkTCYSF8qZTARN8pOpS9bKOIHaj2Ujt3R5OhzAZ8wqvtQmbsyewODdFxqRYPyu6RBy6oVIcTOOeRwWaMDwKSIr9XpSzm6Ul2Bi4XggbK/6XMMnSaMEOo7b8Yri9ZMbWF5iAXOjTgiFa4UT+zocj01jcMKPnVPQa9oCJzlnuINlw9kW6NH0CpuM+X93jscVSSwyj+gsevEFuKauio8DuCtTBSCFt2+Xpj2fCfMdfdHSe1McFH5436IeTEVHbGokHOBQosv8PfREqyUzYXaVpxQYOzqgvJYNXwRN2tHKzfp0VsHUjgC+qoqznD0yzhTHrp7vo6L7s8Wcf6PYiUVb3q3q2jFKwdKSyUAsURyvmH4aENK6qGwmH6YOsF5IxwOng6yNtlBfu86UA== 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)(346002)(136003)(396003)(376002)(39860400002)(451199021)(186006)(1800799006)(36756003)(110136005)(6666004)(478600001)(66556008)(66476007)(66946007)(54906003)(26005)(6506007)(6512007)(6486002)(4326008)(966005)(2906002)(41300700001)(7416002)(316002)(5660300002)(8936002)(8676002)(38100700002)(86362001)(83380400001)(2616005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r2GhyyZrOG6vPPUsgYCxJxMNIx1G7GHb9AlGcUDDjiVYlE4A7K5cYedINmccnQws4hOXdNM3A/QgXQhUDtwRu9Q59uqi0mWZ9nCRO+FtcABTEurUfSE2KMKvj4JmiRaPi2KBpeksCsetHMXplYsUfcNOWGv/GcCPgUal5H89bg2JOnF2S4TI+V/ue17l2w4eHZ+dore2f8h6vGbElWifu8OtqqRyX7yMYjovJ37fx6j+hcGZ+fC5eyP8r01lmNV12gPotsT6ls8Du1hfwfAtUUIGyFaD5s7TDODWDNV9+lJapCfNGfP0azK7jFiXio4vWbi8vp4OgN3ATgQAlbtUqR2S9UBRYDbnRoWTOJEevvDFzJ4VODiPgtneKdZqaqzV6Hbr+6znSGmycOiv0aZeHuHcXTdsS9uPrOysop4YuLOM1m9F/cc5uQebTTtyroxoIEDphTAYgHXz1Whn1ZbITkjnOq+ZumFGTvf7spG43OhEKMJTe9gnjf2sL0oyovijXz9yPDK/820gubGGRBTfHiHzEPFXkQY0gBWI79fBog+32z2YXKE+WiSKO+evgkjtafF9UgfW2xExF/BwT5tLb4uQWsULuoLb3lIUbAN5L3ykoIjFxdYT0VEoDbS76v3rnqmRdKczWctA3JvXjIx/QjAxtE6oIufIwDZFPExGtwWX9sWYWjrJa5ee2xF4OJuB1NtKdzIUn17unHAqVqLOCslZkSsll30pyCnfyrXzoIGb8JSxQ7vqfFGv/j5RIbBv/ErDxOdIqajxVWu/jGQE5k5jUd7WKv0ToMCBKHfKiiZoj6Nzri3IO/6ZkV/5Y8DZEUzva6jiKWZhAyM9UGfDA9V6F2U2GM3G/YcIZP8KXLTXlM0456PXAfRK1goMAg9mLSTSz6pK3aiQ4d20DNzdUuq4UEMq3ErfUhx/va+/16d9gsYvEjnP3P9o2orf8/P8ylfVyrG7vWOI7feQQ19NtUyA1U62zXkSF3OjCLN2sT2oDvj1P5l/L3anF5c/LHMaMNYwWZWaZxaADnpg1MUM+N7y0AwL2ER4skJwYVtAUsZ0RTLoPVEvw8VddbtGoLfKSNPh4N0QgywbN3yNxy57j8p8psJWGXYB+B0Z9LoSEu1au+bQBIAGfqw+TcrGTiSXvIjqkCt/bn3HOqz8hWL8G8ZdcCL47FJHzR2nWE76zZml8QIPeBnBjYzFbHGEaa/wXrF95hWNE3prioeZRyh2ylQKGMsWJi/36KsgSbMU5cjtiyNwUrCTBMTvH0CvJWU60MqJzVVfGS6ctH2PSMvqkvPukqIqCxZY9JYC86O8znKKFe8n+6HHPuQEeeYIkJO0ULP7tGWTLYIDiufqvhmYwOpjX6RV7rUVCuwS+oRVtp1bEywPiiDqvp3Eap+zmoCiLSd0nkS0Y77oNEIqE962JkbkMz4JYRaPA3Xq+t8Jtly0dD4j+rafxLwzz0PTaRJvee/n7fncpmBJmEVNtHrYPl9wA6H0bcH5vEtXKCa8lVdPwTM7de5DpCjGrEG9VKivNJN2TV181w+TYylIc/hJ2b2zLwr9S1ZLNbNhJPhu12+KTk9cqoa8XGYMWwIrwPYf X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4169639-b686-4252-041c-08db98e70c40 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 14:43:51.4857 (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: NFf6o3AQ/hQH07ERzuWwVqp5SHbBMbTzhvxk8lTSXhn1Rc98JzLXKQ4PS70h23KL X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5059 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The two callers coming from bus_type -> dma_configure() already have the device_lock held for the device being probed. Mark this in the API so that the core code doesn't attempt to re-acquire the same lock and deadlock. __iommu_probe_device from iommu_probe_device+0x10/0x40 iommu_probe_device from of_iommu_configure+0xf8/0x1c8 of_iommu_configure from of_dma_configure_id+0x188/0x450 of_dma_configure_id from platform_dma_configure+0x24/0x60 platform_dma_configure from really_probe+0xac/0x3d4 really_probe from __driver_probe_device+0xa0/0x1e8 __driver_probe_device from driver_probe_device+0x30/0xd0 driver_probe_device from __driver_attach+0x10c/0x190 __driver_attach from bus_for_each_dev+0x60/0xb4 bus_for_each_dev from bus_add_driver+0xe0/0x208 bus_add_driver from driver_register+0x7c/0x118 driver_register from exynos_drm_init+0xe0/0x14c exynos_drm_init from do_one_initcall+0x6c/0x318 do_one_initcall from kernel_init_freeable+0x1c4/0x214 kernel_init_freeable from kernel_init+0x18/0x12c kernel_init from ret_from_fork+0x14/0x2c Internally make __iommu_probe_device() require the caller to get the device_lock(). The three remaining callers of iommu_probe_device() don't seem to hold the device_lock(): powerpc/kernel/iommu.c: iommu_add_device() iommu/iommu.c: iommu_bus_notifier()/BUS_NOTIFY_ADD_DEVICE/ intel/iommu.c: probe_acpi_namespace_devices() Fixes: a16b5d1681ab ("iommu: Complete the locking for dev->iommu_group") Reported-by: Marek Szyprowski Closes: https://lore.kernel.org/linux-iommu/bc5d6aa8-e8ca-c896-2f39-af074d55e436@samsung.com Tested-by: Marek Szyprowski Tested-by: Chen-Yu Tsai Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/acpi/scan.c | 5 +++-- drivers/iommu/iommu.c | 34 ++++++++++++++++++++++------------ drivers/iommu/of_iommu.c | 2 +- include/linux/iommu.h | 1 + 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index daa64dd687524b..3771164af60279 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1579,10 +1579,11 @@ 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. + * iommu_probe_device_locked() call for dev, replay it to get things in + * order. */ if (!err && dev->bus) - err = iommu_probe_device(dev); + err = iommu_probe_device_locked(dev); /* Ignore all other errors apart from EPROBE_DEFER */ if (err == -EPROBE_DEFER) { diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 25d7327e8013e7..ecf61bd3cfb076 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -452,24 +452,23 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list struct group_device *gdev; int ret; - if (!ops) - return -ENODEV; /* * 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. */ - device_lock(dev); + device_lock_assert(dev); + + if (!ops) + return -ENODEV; /* Device is probed already if in a group */ - if (dev->iommu_group) { - ret = 0; - goto out_unlock; - } + if (dev->iommu_group) + return 0; ret = iommu_init_device(dev, ops); if (ret) - goto out_unlock; + return ret; group = dev->iommu_group; gdev = iommu_group_alloc_device(group, dev); @@ -505,7 +504,6 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list list_add_tail(&group->entry, group_list); } mutex_unlock(&group->mutex); - device_unlock(dev); if (dev_is_pci(dev)) iommu_dma_set_pci_32bit_workaround(dev); @@ -519,16 +517,16 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list iommu_deinit_device(dev); mutex_unlock(&group->mutex); iommu_group_put(group); -out_unlock: - device_unlock(dev); return ret; } -int iommu_probe_device(struct device *dev) +int iommu_probe_device_locked(struct device *dev) { const struct iommu_ops *ops; int ret; + device_lock_assert(dev); + ret = __iommu_probe_device(dev, NULL); if (ret) return ret; @@ -540,6 +538,16 @@ int iommu_probe_device(struct device *dev) return 0; } +int iommu_probe_device(struct device *dev) +{ + int ret; + + device_lock(dev); + ret = iommu_probe_device_locked(dev); + device_unlock(dev); + return ret; +} + static void __iommu_group_free_device(struct iommu_group *group, struct group_device *grp_dev) { @@ -1789,7 +1797,9 @@ static int probe_iommu_group(struct device *dev, void *data) struct list_head *group_list = data; int ret; + device_lock(dev); ret = __iommu_probe_device(dev, group_list); + device_unlock(dev); if (ret == -ENODEV) ret = 0; diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 157b286e36bf3a..b5b7d4bd2cefb9 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -160,7 +160,7 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, * probe for dev, replay it to get things in order. */ if (!err && dev->bus) - err = iommu_probe_device(dev); + err = iommu_probe_device_locked(dev); /* Ignore all other errors apart from EPROBE_DEFER */ if (err == -EPROBE_DEFER) { diff --git a/include/linux/iommu.h b/include/linux/iommu.h index f1e18e81fca78b..cb4fc518797039 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -709,6 +709,7 @@ static inline void dev_iommu_priv_set(struct device *dev, void *priv) } int iommu_probe_device(struct device *dev); +int iommu_probe_device_locked(struct device *dev); int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f); int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f); From patchwork Wed Aug 9 14:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 712025 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 3A2BDC41513 for ; Wed, 9 Aug 2023 14:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233935AbjHIOoA (ORCPT ); Wed, 9 Aug 2023 10:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233945AbjHIOn6 (ORCPT ); Wed, 9 Aug 2023 10:43:58 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2068.outbound.protection.outlook.com [40.107.94.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F67210B for ; Wed, 9 Aug 2023 07:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QSYTfR8OgPmEoCmhG5DjVNFMZNRscXOeRJHLfTtMlNMuc7qyZY2iV2ITu47J6CuJiJ+jgGYEjtmCG1heWY5ATQqsjih2C3w5t/s1i6kpQ2MqKzswOW2ABOtJ1ZL/DQcf6ZgaQc1jYukdgBX+9xTj2/gclFu+psScfQnsuxE1h5LRnqB9kYnhMxGP+lhcL5PUnIdEwmNo4dHfMPGKQ5BcPymHVmCgZDTRLF3srm6lt0ilyBfLibx8DhD9bKj7STVGa3USkkKnvCYXjLAXJp6bzMKyPOczL1CPSbnLQEQpKjHiWrlglT1DR4dbJ8ePCdC0ov3Q5Sje2Ka5lpZdjXCaTQ== 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=rVU9xQXGUwb2BJP2PBDltxr922QF7zao2nZtVwfYBwM=; b=h0CgvAeEulK8NBSsMw5c8kzVz9qCaIpYPoLVHGlQgHd7SPmUcJXdl5mRYx3WPXedRxJ7uM3YGQP8qa+dCcLP8BNdNodsK81qqtt51ZFSsU0z4r/PbpbTU7LrJfdPAc82IcIZA6fD/4WKT1YtKtwjK/m4Ols17qR7VzQqyBfXndDrB2TCQZmWtgZJkoKv3i6RNm7GORohic6ylYwLA4SvNDzRzMBofaJcmgMFJVVDrL8fdaEn08KpsR9RvO+QxE9C9Uik+vDMI3o2FJCddCAo23Efu/e6BKeBcq3cvDlPA2Mx/z/91CSufl7TGgwo8cvNuyvtpY/d9abehblTz79jGQ== 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=rVU9xQXGUwb2BJP2PBDltxr922QF7zao2nZtVwfYBwM=; b=coRTLBM0lSUAq3RMnPvZZVGPVTHYswE7M9mlCQWrAUD0vBEC785uuuPXJfI1BCryb7+JgBAtMELTBWD9VGV1bVZ578ahN6QFvfvFTpch/yAv1iJGSreIQvYo2FQOOY/OOS7sbNIj+A9LylHxvM86xHo7ayVnQkbm2nUvrpG4Nr4ZM/evzU2t8SsSYoHfErlUbvFa4BncUT6ue9TpokiDvwIjiJ2/lLMCmiE0RWqT4sDq6xt8Yp8arl5fV/ncrssE8oKg2rqCjwDupkoTbJnj+N20SQ9S8CP9OdrdlD1jz1K05RPglRBSZDrFFqI++ubU9MwfRww/lT5f323Kw1FFJg== 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 CH0PR12MB5059.namprd12.prod.outlook.com (2603:10b6:610:e2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28; Wed, 9 Aug 2023 14:43:52 +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.6652.028; Wed, 9 Aug 2023 14:43:52 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Joerg Roedel , Kevin Tian , Marek Szyprowski , Chen-Yu Tsai Subject: [PATCH v2 2/4] iommu: Pass in the iommu_device to probe for in bus_iommu_probe() Date: Wed, 9 Aug 2023 11:43:48 -0300 Message-ID: <2-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> In-Reply-To: <0-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0064.namprd15.prod.outlook.com (2603:10b6:208:237::33) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB5059:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e16c2cf-2f25-4e71-c5bc-08db98e70c63 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +8F1o+8gggqk5QxuhVH0Zl0zEHwbJfs1EVMAMpmBqybAo2iEfYxulHJbXYDjnAITSnarP9NYVcFxM2UwZgdWh3zEwMXLTCoxV3AADWuAZXPQoTstm8Ds294c1UjoJ4cNHbUWz3DDz+83i20bRLZsR6c9kYS3gDbG0PsGJQWG1Evq0OzqLYxp6mnUJgB89pfAY5pXIHZsJQ60FuCExbiPHRjpZD0u+64QPLwc4ejKP9ziGgwz7hop5QRZsW7IZrNSo5B2/a7+dltIfCsF92R+qDx0Pey9n6HWZGbMyW8QACG/Km8aq26cIhdSlVLEnhIZdQzavhKsjD5QUPRP9tRO8mN52abmbUWIJYs+a8pidgcuJ9f79gcQhBK3xUaFuUXVJvPkOeoffZhdB8kgtfVa3BjbDEbVjVV4MxwjkkumzYioKVdxDVmKwfF52JL9wDQlgIHUq3yND0lrR5tGeW96SQcbNLtrRWMLpXxr7OV+BdmMv25FapigO5f9m8J69I124QLLUccnqQRNyyYiIfj2axBq/d78gGWcuIPNILzeIMEj0+5FDGbTG6XqCY7F5WYHYojQvDz6FDDXmWcvUC01jgkuKMUOab82I2KdS6c2H8k= 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)(346002)(136003)(396003)(376002)(39860400002)(451199021)(186006)(1800799006)(36756003)(110136005)(6666004)(478600001)(66556008)(66476007)(66946007)(54906003)(26005)(6506007)(6512007)(6486002)(4326008)(2906002)(41300700001)(7416002)(316002)(5660300002)(8936002)(8676002)(38100700002)(86362001)(83380400001)(2616005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J85xXTTW15tMAhTP9VCrjneossx3Ofi24XQMJ5G+oD43PurpXEP32LpyNk8T8BVh6SK1gtKsSGFGeaeEJFD/7xMBPiU9ACIIk4kPDqMNCVTGMO7doGeNINdZJvQf70zCInnM6cwnqqoMdyiPsIZW7Yqloe7ydvdajF8145NZT4k0LIX6v9N6anQfKCIajLJzlWtVQAMDaiGu+UaTA5Qt5bcsqXkkcG16Ai3gaNjtNMeCq6BWvZPKvtSOJvm34pfdAHRyx2rupBv9t23gj8R2QPy5sP2SS18rfUsEzaIBInEqYplDRYBwpmbNHkeikk5m4/63+Wl6IRg5hNOBPxpQOHH2eLfCjFK2JdkEfgajldKuUJpnIChSTlEQolohT2gluuVFsQX4ZljnyEhqN54EZ+WoSeeGo+hxlJMhoMwLN7/yCnpyeQ4GZ/lddU5zOXCywsaaYabttRHfrvWU8gI1XHVazpYAMZxx5O1V4BwKOZxlQsBzm67zE7PmKXjjDWWbSwL9cO/Z+NbchpNXKRnnulWtPZ3e7BmvyIvuv1wmMaYWgbdjSGQLRlP3/Al+YBH+0MSxJCAFl2tCdmItfeCjc+IbeMTKMqEiO1m9pFmSzRMybmoZka7GZ5FsYbXl19YflSTEA7b4vtdwzBZf9E6mfn5QXbXNCjsql9/3tSF0RhEKQYdURcgZrBgmdXsgVKl5sBr1AatMIMh6h1yI+CEmc/9JWfn03Qzb/BuHoyKj6a0dgSuctiXMjcHXAErbwBayMe8XiqPm3uvcCBYaXYQwb9HUpdO2ITI+cE8AGcoHhOnD2KErsdwnIyKF3jD0mYcSn6K9rFFvM+6Dp68zGTrnQEo2fSOVA+v0SwIPJ1xkBXhZB8Wu4UBm4j4jmf34eII+Q/gEefS0NzdTrWiDoiJp25skfAEOQvfz5NosH2BKyrupGayFTU7j0W3oewF0n6uMapAAK8noC/FNAUca8jnPcoXbF+5XOpydGht+jyIauI0bSZ+2ns7SD1vzL3k9mEZjf1LSfOfgk94zvUgtQE6E0dXIOZ3seoakfwQ13fyR6f0bKyXZ0XwhcLORwft+dYUHvX+WUguc6KNbxUc+iWutuudltAy27cGsRLcDvE2hR4uVNemrtE56/0nPPhsEhdhY7+e0w5Zfrr1sPFWndPvH2rtKg272MFCU/N5YRUdBrgbGVjQ9x99n/Be7z7KCIbZeVrga9KQp+ojBntwu2s740K0H6FAS27KMlyOtSeWwEdKx8WgaiLk//dmVfYD2wrDm+FdKuCU1XIr8BLwO468boL6KOdnase9zY9aDsH3Kkir6M9w0TK1A0ivjFDGmSivD+sxBWRxowc2lC6ZMldRdgNntmNUNDRZWg4C6u8XiYdsJ2eTRM1tpNxYbcOkMYl8lwYioeg605u8RrZz1kRew7zADZJViTbjl8GgtvkUzrLBOtVKpDm/u3tH0w459jcUFjg1lUv8ixGu/tDqnENj0kwo/8OdRkdwFwm3Omurc2zvo8KR3reaImWlAb6cbjfOaBdhWPExjMR7As6+doapZm8RlDsHVnxTNZgmesA0beVmNtjAeu2lZXgXHxTLZagW9 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e16c2cf-2f25-4e71-c5bc-08db98e70c63 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 14:43:51.7312 (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: GgPi3bcUWGxMCtlgTBTYQXPBoqikdddQYK+knsDFejZoP9/1IwkdpE6zciBNPZJm X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5059 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This is preparation for the next patch. Each iommu driver is associated with a 'struct iommu_device' handle. Pass in the iommu_device to bus_iommu_probe() and all the way through to probe_iommu_group(). omap is weird, it has a whole bunch of iommu devices that it creates a struct omap_iommu for, but it only registers some of them with the subsystem. In the case it doesn't register then it has to open code the call to bus_iommu_probe() as it's omap_iommu_probe_device() function is sensitive. Pass in the unregistered iommu_device struct and move this code into an else block since there is no sense in calling bus_iommu_probe() twice in a row. Reviewed-by: Kevin Tian Tested-by: Chen-Yu Tsai Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 18 +++++++++++++----- drivers/iommu/omap-iommu.c | 11 ++++++++--- include/linux/iommu.h | 3 ++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index ecf61bd3cfb076..19fdb1a220240f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -273,7 +273,7 @@ int iommu_device_register(struct iommu_device *iommu, for (int i = 0; i < ARRAY_SIZE(iommu_buses) && !err; i++) { iommu_buses[i]->iommu_ops = ops; - err = bus_iommu_probe(iommu_buses[i]); + err = bus_iommu_probe(iommu_buses[i], iommu); } if (err) iommu_device_unregister(iommu); @@ -1792,13 +1792,18 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) return group->default_domain; } +struct probe_iommu_args { + struct list_head *group_list; + struct iommu_device *iommu; +}; + static int probe_iommu_group(struct device *dev, void *data) { - struct list_head *group_list = data; + struct probe_iommu_args *args = data; int ret; device_lock(dev); - ret = __iommu_probe_device(dev, group_list); + ret = __iommu_probe_device(dev, args->group_list); device_unlock(dev); if (ret == -ENODEV) ret = 0; @@ -1868,13 +1873,16 @@ static void iommu_group_do_probe_finalize(struct device *dev) ops->probe_finalize(dev); } -int bus_iommu_probe(const struct bus_type *bus) +int bus_iommu_probe(const struct bus_type *bus, struct iommu_device *iommu) { + struct probe_iommu_args args = {}; struct iommu_group *group, *next; LIST_HEAD(group_list); int ret; - ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group); + args.group_list = &group_list; + args.iommu = iommu; + ret = bus_for_each_dev(bus, NULL, &args, probe_iommu_group); if (ret) return ret; diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 97c45f50bf4332..1e4a90ec64322b 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1234,6 +1234,14 @@ static int omap_iommu_probe(struct platform_device *pdev) if (err) goto out_sysfs; obj->has_iommu_driver = true; + } else { + /* + * omap_iommu_probe_device() requires all the iommus associated + * with a device to have been probed to succeed. We just created + * an iommu without registering it, so re-run probe again to try + * to match any devices that are waiting for this iommu. + */ + bus_iommu_probe(&platform_bus_type, &obj->iommu); } pm_runtime_enable(obj->dev); @@ -1242,9 +1250,6 @@ static int omap_iommu_probe(struct platform_device *pdev) dev_info(&pdev->dev, "%s registered\n", obj->name); - /* Re-probe bus to probe device attached to this IOMMU */ - bus_iommu_probe(&platform_bus_type); - return 0; out_sysfs: diff --git a/include/linux/iommu.h b/include/linux/iommu.h index cb4fc518797039..cc47e4086d69ec 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -465,7 +465,8 @@ static inline const struct iommu_ops *dev_iommu_ops(struct device *dev) return dev->iommu->iommu_dev->ops; } -extern int bus_iommu_probe(const struct bus_type *bus); +extern int bus_iommu_probe(const struct bus_type *bus, + struct iommu_device *iommu); extern bool iommu_present(const struct bus_type *bus); extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap); extern bool iommu_group_has_isolated_msi(struct iommu_group *group); From patchwork Wed Aug 9 14:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 712714 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 42D86C001B0 for ; Wed, 9 Aug 2023 14:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233923AbjHIOny (ORCPT ); Wed, 9 Aug 2023 10:43:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233915AbjHIOny (ORCPT ); Wed, 9 Aug 2023 10:43:54 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2068.outbound.protection.outlook.com [40.107.94.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CE7E1FCC for ; Wed, 9 Aug 2023 07:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJJOfhiHmBYYie9s8RijIdLy4z5qgrS6Y/1E1aAZ3RD3wUdEh151pfz3SLcAXREbIu4CdtUg4Of0Pq5V/ZDI+I6hO2HBvJgS/ZbiLiALi/BsmxyVPkgEcI10lH6CpXx0gNlduBZ3i2KnJ5EMI4+l9ITc6E6Uneg5DGam6p/CD8hoqAyNKlXg2atH4T3x68cXag2D9rQz827d4iaIOfLWtBNgb2+BTaXZiIXNh6r/C1hc2OH3/LWQZ9pCw9E1HZI0JhwsGNR7ECKVwjGJnqcpLrU513r5we2LWidEmrzCVnccU0gOgERHPgTn4E+oZHYzLO5XzL7Y3VGl/EDgS69v4Q== 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=06Yo9x3XaDiNwBSd+cBJ+EDGP18o813wTppg8YKH9eE=; b=JeI9kM3KAuMLSXF6y5uK46YjZEmEakQSu+tFQWNbCz7vj0+WhrYlYr/v7nr7okwM/M51qPiK9jhCf8CVzE3Wo690ngyrgzLpOzxq/343oWsvxFKApF+SeGMu15ta1zAC+UTX1S9uUMIQzvhYuuEB9nhXhpZm5wcQeyyZkZWAjT6TjnxCbxhctMzhiONYW5mfW86Kr9uD7HgMhipn+27NDIwK5fkG0xTba7wB31Y8OVnC9wwVUwFxJpE0suYZ9wVozlN62sNx7IPffCEJmSaXK23krezLEjuDHBRGn5vq9/wNkYDHSsc5zkmi/xJWjsHaBgPKS1rDobAyGiEznEhEOg== 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=06Yo9x3XaDiNwBSd+cBJ+EDGP18o813wTppg8YKH9eE=; b=QTTHkOnmE+eCtQ4GCitVQst0wO9FwprwjwzqSvK5t/lHeL5jG1Ts2hPyhgi6D7sUXZawuT9sKk4V8xUklUo5mNoY05AwA/pmxQ3iv+nbW+wgSPcDrndF9vyRgxcBiBZ7cOj2P8Ohn1OvoLIiMKAhZWm2tCIYZvKSANrVvTq3NDOHy7UI03EB1csRVgazQdglmgwAf2sZSp3ytSnLH4zr5qze9YUf87G8xiYLcKyQ68A2DGZMTp+m1PPrisEmayhmTTXmmmML1Mx86Da3mPObK+mLMQHVbV8fldcFtzMnbfNCZbI8U6uxJVFVzQWjXgXeWlTOT+RhigxI/cJE3KY0PQ== 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 CH0PR12MB5059.namprd12.prod.outlook.com (2603:10b6:610:e2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28; Wed, 9 Aug 2023 14:43:51 +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.6652.028; Wed, 9 Aug 2023 14:43:51 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Joerg Roedel , Kevin Tian , Marek Szyprowski , Chen-Yu Tsai Subject: [PATCH v2 3/4] iommu: Do not attempt to re-lock the iommu device when probing Date: Wed, 9 Aug 2023 11:43:49 -0300 Message-ID: <3-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> In-Reply-To: <0-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0071.namprd13.prod.outlook.com (2603:10b6:208:2b8::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_|CH0PR12MB5059:EE_ X-MS-Office365-Filtering-Correlation-Id: 8920be56-5cc5-4eb4-30a0-08db98e70c09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SHKNJPO05+5qI91u47DZa6C7KI/iR6oV5Li59+fYa2lMmlCFR/7YAlv79gYLVv7upXZgswaeByYw9srQS1sJ9nc/HHmtr1Dsazl2Ff2h81ly0GBev1BFKZA3zpNNBKhqJjAIMjvF4tJ7EjDMTrfMu84nI9irPFWOqYPmF6HQ/YacGhICWl14XAnVKH85j8bbCwSnErzMZa8wFBXcQXYF3KDO9zhDi4lZpYIrRIAlZNYFOrn/yiEmUk6bkPyWgBCCEKpaN0NcpYpLr7r6PJ1ZCv3A4MWrH0aYjdxncseMPjnQYa9MomF+j2xaym+lE1nj7UcmHruZCkKw2kHxARhOP8yJtLKMIxzfRlJT9sSZ0Qps/quptR4DKhsZ+l7NRjRTlkU8U9hEsLH+841xpp5ndDJM19OD4taxHZhOJ/+in77l23PdLnNGIHkry2TO+Ke8crefGChVZBTKXaewIvDBwHYcVmlPKBOxG9cSUrn7ARvWnQnepLxhe/BHktiL6qLA7lvJnZ9FdNVpD0Hwrrhjpciv8SOSClMixCIdvqQSlIHU900bnLhkhIRFjXALCtwqnkvN4ICw9qVi8o8CirmSxZK92SUXMlxndzrJmckZd54BfcXobbVdXfsuCDrifKS5wi10Kw8iHu/cwCGnxIcGew== 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)(346002)(136003)(396003)(376002)(39860400002)(451199021)(186006)(1800799006)(36756003)(110136005)(478600001)(66556008)(66476007)(66946007)(54906003)(26005)(6506007)(6512007)(6486002)(4326008)(966005)(2906002)(41300700001)(7416002)(316002)(5660300002)(8936002)(8676002)(38100700002)(86362001)(83380400001)(2616005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K5shcIF1KdStL7oG4w4sfRnAB1qzsXr/7yGC/1LBDbERIaMOv8gJMyNsEfFPspoVcpApdd5cxhPMwGtxM0LfAHnozHz8snRH8DXxVCj5XO2ndvirERXkTkNoOw6pWMK88BvDfoL7hVMWaOo9Ekc6swvUawYVssCo7mILTF1ZKIJlSoQcFfVyW9hDMKhNc+FreyATddWcMU9OXNQjpMWuTGJqL31wb5KKoHRlsjdKaEy2VIev2EMiO4mS6DY/LYR79g4tdOKSjg+/hv8yw/L2deshOEIXzz01kpobY462G7cy7rkHD4rMsoowgW2DEi8htyT1EXNXp/cCWsCQbdvu5Flsc798f335s8MNuSpm6oOYat+N2eehlpfzdxHJj5Ws6Ia3uuQAxe+KRDOkx61zhUd87t7gvVFcDtOUJmmqfS+ajSaP4ZW8o/rIcjDQ1VdcHT69lCU84cRVBUEFdemNqV8ylnHR1vheuW6eaUdwxdpwnV1lx42Ajs5EE1acNihjGgakkn6U8ZF1DA2ElcMX7q0EPHSbXGW5so8hf+9Jr2R5kvQVln6nLf487usHXmdReG/uJkqGTGbf5NUHRvtqc75jIMMkNWZAS7374H/fX3mS9++43am87dif7Fr5GuSXV1fT2Bi6Xt33UIv37JPXf9Y0+X5B/GM0RAi/vnbLcxzMCDY/V5S3g3WmOEnmxwKtA4AEQ+OPU1PEZt3u55YefmzMINnXu+qU8MsumW9aOo/uiWRkV5SoLhd7VzSxSrARd4pCVHkWfUmZx3VzP1bcPkBqLjFG2vu3gjdlSZHr4H0pVtCX5+iajTpLBzofBxEtqcXw3o2j5x/aNQsJ4jKeAGcDOWR1h+aKOjWD+uadXa1YxNovyi+U5oChVP9d2vVz5WabvSIfgOLHstw9S6awibc97jR5MJGnuekYXwYHwCIbcKZY4cUrZZo+pdzR9leebey/ZGj8DfWRfKzjc0mJkby3fsNcOlxQud4G7vzTpzgPajR3oo29zOyFcj92i6hkCs4Lwzp9SgUuhHQ/FRqbBFDU3qc4NGE4WkmavOcXfcpm6VaEkOTXKfaoELDHuCUrgjnujWuUsIdYOm8GBPJE+VT/d+v0639TODUBx67dJ8pIH8o7RzgIUtbC6iERvSz6YWs5+C6v7RKvx62WQ7y8RsSpT9chaeIif9vF171tlbNe0/C8/VHXrh25idq+/FbTZWS20Pq9BtnBangHnXwD8Iz07jexYVe8vI6Fue51hefAIRRTDOdCQutw1f2Tyd8kULEKTZkaNtzABqX7TqgxailX56MBhhkWtwR89tiysaGPbA7rCQypjPkXHE44vWAsGnlISMP7TH4lyu1iBFrmxpBQ5N5WRHYB+81zJakLSLwYtk9Mpanwn1V5jAT0DrC/w62SqaWslvsPw60e8GwQa3tbkgl1g2VNrGsaqUNsxVQl/kP3JSwN1dP2JLPWAdSqqaj3e2NrnU5zWJrr2P87JQKpcQn3jyKYIEjjC2ziF0O+mpW/vodbMKrRGqwJONsLZ6KhF/3GWWqhXtu90VF0663I1+ptLugODIBVb8I6MOv0iN5YqSD16WtMIDj+iJDG X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8920be56-5cc5-4eb4-30a0-08db98e70c09 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 14:43:51.2057 (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: 9W1GpR7/spaXVUxjSDZG3WTqeHKu1RhRlFn43IUVP91iUjgXw9FfpdBnYRG9j4p9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5059 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org When bus_iommu_probe() runs it can attempt to probe the iommu itself, for instance if the iommu is located on a platform_bus. This will cause the device_lock() to deadlock on itself as the device_driver probe() callback for the device calling iommu_device_register() already holds the device_lock(): probe_iommu_group+0x18/0x38 bus_for_each_dev+0xe4/0x168 bus_iommu_probe+0x8c/0x240 iommu_device_register+0x120/0x1b0 mtk_iommu_probe+0x494/0x7a0 platform_probe+0x94/0x100 really_probe+0x1e4/0x3e8 __driver_probe_device+0xc0/0x1a0 driver_probe_device+0x110/0x1f0 __device_attach_driver+0xf0/0x1b0 bus_for_each_drv+0xf0/0x170 __device_attach+0x120/0x240 device_initial_probe+0x1c/0x30 bus_probe_device+0xdc/0xe8 deferred_probe_work_func+0xf0/0x140 process_one_work+0x3b0/0x910 worker_thread+0x33c/0x610 kthread+0x1dc/0x1f0 ret_from_fork+0x10/0x20 Keep track of the iommu itself and do not attempt to relock the device while doing the probe_iommu_group scan. To accommodate omap's use of unregistered struct iommu_device's add a new 'hwdev' member to keep track of the hwdev in all cases. Normally this would be dev->parent, but since omap doesn't allocate that struct it won't exist for it. Fixes: a16b5d1681ab ("iommu: Complete the locking for dev->iommu_group") Reported-by: Chen-Yu Tsai Closes: https://lore.kernel.org/linux-iommu/CAGXv+5E-f9AteAYkmXYzVDZFSA_royc7-bS5LcrzzuHDnXccwA@mail.gmail.com Tested-by: Marek Szyprowski Tested-by: Chen-Yu Tsai Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 10 ++++++++++ drivers/iommu/omap-iommu.c | 1 + include/linux/iommu.h | 2 ++ 3 files changed, 13 insertions(+) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 19fdb1a220240f..3ff365c9117850 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -264,6 +264,7 @@ int iommu_device_register(struct iommu_device *iommu, return -EBUSY; iommu->ops = ops; + iommu->hwdev = hwdev; if (hwdev) iommu->fwnode = dev_fwnode(hwdev); @@ -1802,9 +1803,18 @@ static int probe_iommu_group(struct device *dev, void *data) struct probe_iommu_args *args = data; int ret; + /* + * The iommu device itself is not probed, in part because no sane iommu + * should self-attach to its own HW, but specifically because we already + * hold the device_lock for the hwdev when calling here. + */ + if (args->iommu->hwdev == dev) + return 0; + device_lock(dev); ret = __iommu_probe_device(dev, args->group_list); device_unlock(dev); + if (ret == -ENODEV) ret = 0; diff --git a/drivers/iommu/omap-iommu.c b/drivers/iommu/omap-iommu.c index 1e4a90ec64322b..20fcc8ebab6ae3 100644 --- a/drivers/iommu/omap-iommu.c +++ b/drivers/iommu/omap-iommu.c @@ -1241,6 +1241,7 @@ static int omap_iommu_probe(struct platform_device *pdev) * an iommu without registering it, so re-run probe again to try * to match any devices that are waiting for this iommu. */ + obj->iommu.hwdev = &pdev->dev; bus_iommu_probe(&platform_bus_type, &obj->iommu); } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index cc47e4086d69ec..96782bfb384462 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 + * @hwdev: The device HW that controls the iommu * @singleton_group: Used internally for drivers that have only one group * @max_pasids: number of supported PASIDs */ @@ -369,6 +370,7 @@ struct iommu_device { const struct iommu_ops *ops; struct fwnode_handle *fwnode; struct device *dev; + struct device *hwdev; struct iommu_group *singleton_group; u32 max_pasids; }; From patchwork Wed Aug 9 14:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 712712 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 87375C04A6A for ; Wed, 9 Aug 2023 14:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233933AbjHIOn7 (ORCPT ); Wed, 9 Aug 2023 10:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233935AbjHIOn4 (ORCPT ); Wed, 9 Aug 2023 10:43:56 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2068.outbound.protection.outlook.com [40.107.94.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28CBD2109 for ; Wed, 9 Aug 2023 07:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ay2aytO3Y+l9XIYpabhOnfQHLC8tjvrum0T11ChZ5IRgr5fGeUyGzJxgcPwiZ/obOECzmZ5QoX5qdnhVIr7Ii4bq4gAwCelsKraA9f7fH93wL7ts8lgKXb0Kn/zy5IzrRNmty9ZrE4xd3CS2uvYRD08u6B6vla+wzDTyIg/AoRwAVv9tpopJ0R/wVPcU72DmQ07ClJ8rpzBwonSM4N7TqCXG9ZgOGDZm5zcf84//iqaoBgZlhB1/WlTHImc/f3z5AafOn9kVPgV5eELgLkzQ19nDBLdz53TaxVF7dLD1FKzTf9OXn2Ibe/HwDf4gWc2myV4RtPPRnSc0oikUWFd1hA== 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=KKAR5bavY/ywkaKA+NiyFP7gx3dDXMGnoQA53giOlzM=; b=PMC7svhLuAprcK3MWOConXw8sBaUd4GiiGVQKzFAa8TlSMIY5ihcrGJBdG3vpL0tQvh5nQyh1ZMu9RbX5vK6mjnwavts4NBEKdLgSS4c2b8UQQFvnJIhqm6/n0ZBCASHECbvaOJ3ZhTjim4TpTV65D3h87Cr6wpET68VgsQhildb3xhHIAq61tft7GwNXmedaOTBDAyr7VwSAc0i9j1860TfNUrYAQjehrnJzWKG1s62/ThLt1TQlUn//gTnWf8LbSxg/pApar8UluVHsoDbpbngsOIfNo28sm+bF/HEPgmPYAuNGmpbTKqJ6pP09sIE2hcMHp1iubrg7AKKyj97fA== 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=KKAR5bavY/ywkaKA+NiyFP7gx3dDXMGnoQA53giOlzM=; b=HwwpwnuTp1Lwx5oLvwrdGN+Iv747zu8ol1UtDXHZpEtDq44xt6ycOeKh4PnPLm9ipFvvNfsUMG+OoalNH6RtQGw1T9r14Uy4E4iPgV6ks3sc+jS07osC8ropQSyzk7fbEyZ4oOR3+vfXICO4Mu6o4FQ9PgnSuOkANZAS43wpbOx6756CfC2NtbNiBuZ01k62nfr7JGgfvxcg3KOtRkzB/8+eazeYCHEgdLhtSG6Z7et5RgxwQsGGz7XMVAtD5hD90ufKPRvkrdCb8s8mA1fdDQsFg9EWrU92mYzMCy1RN5b7m9sL1sRUesxmxwYASVMg+olL/bJ3/EVklx5rFAfUmw== 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 CH0PR12MB5059.namprd12.prod.outlook.com (2603:10b6:610:e2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28; Wed, 9 Aug 2023 14:43:52 +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.6652.028; Wed, 9 Aug 2023 14:43:52 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , Len Brown , linux-acpi@vger.kernel.org, "Rafael J. Wysocki" , Robin Murphy , Will Deacon Cc: Lu Baolu , Joerg Roedel , Kevin Tian , Marek Szyprowski , Chen-Yu Tsai Subject: [PATCH v2 4/4] iommu: dev->iommu->iommu_dev must be set before ops->device_group() Date: Wed, 9 Aug 2023 11:43:50 -0300 Message-ID: <4-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> In-Reply-To: <0-v2-d2762acaf50a+16d-iommu_group_locking2_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0053.namprd15.prod.outlook.com (2603:10b6:208:237::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_|CH0PR12MB5059:EE_ X-MS-Office365-Filtering-Correlation-Id: d72049bf-cca0-4a77-014d-08db98e70c5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fp8z0J7rGNQnGVqEgaZ3pJf+Hkzi5KiYVBL6hTPPoY+fPHVmat+bRtJWXotIKbRicWpwdM5/GxVCRk9RYLdXWOZL4sa271K9y/0stU2D5wDEsWv08aj2hHVVkAXAHNe6xiXMV+gVs7XcJ0lV9KcNmv9juWpEimxyODICh5Q29UojWmIYy7y55do3o6P9fvLcuCjU3+p40Wl49Rqz/KhEAtVG/yi9dASzalklR6OmpKR3Bwz2rH+ZFAkO/KPE3slF6krcdAPS94oSv6PUy4Rgc9Kdv48/Q29Wv7ma0deKSN49X1k6Rc0R5Fjmws0ZUXNXJC6mHp741hXVCfZRZSPrEnjyTOKDxlpCq0OKAc7iTDGeyW9eXyYRNXqWNGSfr/qqyyHcud0GVuQk4BRC1qEmDZH3MBRcQGbwiZG/J3xW3tN/QBlErQ7LnFjsEAzaSfvG2W+UtCIOZ7+0SBdKkbHuYXlTKMVbT4j7GKEs8eb7xBS7aNbHfF3cCY17v5y1KDI0EjZqDR2etLQu3FweHB+kH80tlDhqCS64293AZfQ7Kk13ca4+9ZkvgmyA7cSSmU+baPTsarhWTDDcOPRh+TP7ajFM1JlzHSJH1MZuwvFEFIyGiT31xtDWK1OqlaaX3kRSJXvZTsU7XcmLz9Ee0q1EAg== 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)(346002)(136003)(396003)(376002)(39860400002)(451199021)(186006)(1800799006)(36756003)(110136005)(478600001)(66556008)(66476007)(66946007)(54906003)(26005)(6506007)(6512007)(6486002)(4326008)(966005)(2906002)(41300700001)(7416002)(316002)(5660300002)(8936002)(8676002)(38100700002)(86362001)(83380400001)(2616005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VRCmXIkVeEqz493JP7LTAOA6nCRX3l61bk3Cri+kWEKAF+s5OXFhYSCPf7tSlX5FhmQ/kYfyBh7174nTFJAOU+e1k6GwIo2iXjOb4mvSYUkC87Aiu/yRCCiXNhylKZWTIVPxJssS0lUQcDPfuZq9iZfdaScbOJnaRZ9WAeKIIbWbXkY3+b6fMSY4oQjXG436gD4YmvW7j2KaywU738s3UM9xVHd7CKxhT+zR8b9rxlvWnBFRsGSKeDwMKH7kT5I9TFSaq14zy/YDxQHpQxJTUCFIOv4q+D2xSbbG6RfevhG4BEk7Tf9Wc2eyxri6RixiAUjVz+69vaJGxUzaa5cPKa/ZeFCcaUgr5nZqfPJOh03+3wfpNQVaWJpF7u+l1sYOmnTJSRk0pBowQALtBOeQljBlHoVKLYBhGLHU/WQFTqe/uYVrKJ81tEAX8Y7HrcgNnOueOW5RrA8s9SAbirXo3NgGNZfeeYFLgRs/WEndKMU4jfv4zuqtCZYwRNVZW5Em1/3baTZWO41CDbiBqlWVczfpgCz0VECayuPLlwDF8bUoAy3/3s/VoiBuHphBYNmw300pl1bkRSWVCnt99OiDW3lGViPfEOP+/naSgGpUsYEB7Y7NCasrcTQ+qSSgvm5HRrjmqinQKJHsqDT71+3KLenNE3xfDNpn0Qk41IjNObHSuJe6aLt8Dv7H0VEfqGrH4YwV5vUkIbkkpVlaRWVF5LuIXfic7K0ndXNT4Kjmi+5bx4WhNbo8IEyR58jSoz1+QhS5dHsY1RpEpuKrF0seyvevjNGZiFJiMtG925K44RtLU6hLEnBjRVZWCgEOtqHwPAb8pvnRryJ/vJDgZTSwsEBxVRrOVmmub9IkVas5S3BhR2quVrqG6UooQkOvsXBiYW0zhbdOExc6ZS1Yi20DAOkIbKFJcrby7iohB2f1KRqqRYiP7rxVJdTw8gj1Y9C6pxD82VGApYNQVb7cdhXzELY+fAoEdhrjj//7qS6azDSN/WurL5GR+5wpwH1ae0j/Tl2IguefVNkHp/Me8y3iw6aQf6fUtDOfKtWwgslx+JNGPj1913wov9cNlemsnofV3m1Uzyya7n7zLSGD0I0WieAenRJQkY+E8jI6hj/CaqR3wFtUUqwhOIA6cNOtKexpLXafHoiPKLJ7puAXc/1vC0QpGxqxX1HiMJcKNVEeGQYe2edyoIzQ+M7VKVDOszqy8j3qtap2xbuBsUFr1vMKd9mw1O+arWEfLbV8RrrWh2C4i2HhNrAWhIfkUoek+N4FZ3EcuJrK7LtNkUqhgf974MItaMrrqczX0nLiPkgBzyrkaDEBqsyFarQiOgH+GKyD5I+AX8ebng5sz7BUWGaOwJMgnFcjjSFSQ0L8HkMaVhgbxnTJPLicrU278sXKIWH5bjD/yZjmOxus5Cp5Pc3B71CMk5YeisuQXsBYY+3/7LxS/w+6UpWdVZLmz8269fgtLqaRO2jcP0ePi/OWCEQN4wvqRQT00IspvyTZmL/nuD5LReHeQUwzAYy6/8ZFkG5eXt/gpZbQwJaPognTWd0AE4Kk+oeiuGZ6O5lxHWZ2t+8umC8qAsY3mi0nLGLV8l93 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d72049bf-cca0-4a77-014d-08db98e70c5f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 14:43:51.7137 (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: yw3kmwqcBEGxCJQ4X7kLSKCLhAc7zUz49TowIk444bEKE8Zc2O9MkiA64/2HHhXz X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5059 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org As generic_single_device_group() requires it. Otherwise it crashes: generic_single_device_group+0x24/0x88 __iommu_probe_device+0xe8/0x444 iommu_probe_device+0x1c/0x54 of_iommu_configure+0x10c/0x200 of_dma_configure_id+0x1e0/0x3b4 platform_dma_configure+0x30/0x78 really_probe+0x70/0x2b4 __driver_probe_device+0x78/0x12c driver_probe_device+0x3c/0x160 __driver_attach+0x9c/0x1ac bus_for_each_dev+0x74/0xd4 driver_attach+0x24/0x30 bus_add_driver+0xe4/0x1e8 driver_register+0x60/0x128 __platform_driver_register+0x28/0x34 hantro_driver_init+0x20/0x1000 [hantro_vpu] do_one_initcall+0x74/0x2f0 do_init_module+0x58/0x1ec load_module+0x1a20/0x1c64 init_module_from_file+0x84/0xc0 idempotent_init_module+0x180/0x250 __arm64_sys_finit_module+0x64/0xa0 invoke_syscall+0x48/0x114 el0_svc_common.constprop.0+0xec/0x10c do_el0_svc+0x38/0xa4 el0_svc+0x40/0xac el0t_64_sync_handler+0xc0/0xc4 el0t_64_sync+0x190/0x194 Fixes: 5dd59857af60 ("iommu: Add generic_single_device_group()") Reported-by: Marek Szyprowski Closes: https://lore.kernel.org/all/e5e75222-13a9-ee01-0c25-8311b622fe0d@samsung.com/ Tested-by: Marek Szyprowski Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 3ff365c9117850..18162049bd2294 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -366,6 +366,7 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) ret = PTR_ERR(iommu_dev); goto err_module_put; } + dev->iommu->iommu_dev = iommu_dev; ret = iommu_device_link(iommu_dev, dev); if (ret) @@ -383,7 +384,6 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) 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); if (ops->is_attach_deferred) dev->iommu->attach_deferred = ops->is_attach_deferred(dev); @@ -397,6 +397,7 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) err_module_put: module_put(ops->owner); err_free: + dev->iommu->iommu_dev = NULL; dev_iommu_free(dev); return ret; }