From patchwork Wed Apr 19 16:11: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: 675084 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 095EAC77B73 for ; Wed, 19 Apr 2023 16:12:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233442AbjDSQM3 (ORCPT ); Wed, 19 Apr 2023 12:12:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232360AbjDSQMY (ORCPT ); Wed, 19 Apr 2023 12:12:24 -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 E1F882D58 for ; Wed, 19 Apr 2023 09:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lskPeg9/4a1TV9FFDHrwxJ+Y9DyVVzCCfNsay5IUPHED/DSHWJ7w00XkCe+tLVt1ukRxrw2MQspsZ9Y6rxG6Bp2F9S8zPLxYzI49RsippnqYfCGxgKBut20MdgJQHMbxFi/hVL8/6A37gNoB1+hpeG+XNlfuxL1kuJj+8OzoXSFiHK4pV6EUr5jEwoOtpdiwHOob5q+1VwN+LE/LwZcd7kRF+ZO/2RjGvT+OEs/Vt/jJMJIoGJNwTbYBkKSCAdcQpW1EO6j38paiSzXWZQ0/32hTkua5hJ//Tivp4yx02UlCG6MQjPkyUDD1YD9Ha68iT67XTcrWL6C0UxU7PeJgrA== 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=tkhcwo1MvvS4uEyQLFGpPIJVUSByXI6UYKCVXZ7joNE=; b=D87dynAkOy2SOABlz9Pj0tMimzYItJBa2hYgyNDPDxEk3/zmimo1YKrrsOlXW+mJW/GoKBqQDDSBTXxn++l4ZTbzzU9tX0cmHLmEaZtWQ8znuJubu8AWCUYSHbpl/0DV/pMdzHxYN2Nvk4LScHrALV5HV1Rj71HsCVykMExFFkNd/WvVd+13o6s05JUOWxK8uEfINltbrlSoznTH3KhKUtaxE7qPpPVJ6o96UOjXLK7vy2YGuh5Wt38aFwn6M8ADmMnalsyf1Lhr7nOzgF7JPR/xbaP4Capi9KMpLp3Dupf2dVVd+iRipemR4AyFpRB9jMga+jjvhIqSOecQqlT0pw== 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=tkhcwo1MvvS4uEyQLFGpPIJVUSByXI6UYKCVXZ7joNE=; b=B5jsfNfFVK543HtMFQD3dDuZU+lSzlI+lQFASNyibQZN+ksqFPJqn/+MW+DO4ZDnGoq/7WXoE8IHOMhqMDOgOsOB6JeSFZrGtH6ZPN3ThwRF6pOnkK2i6nUzALD5L4s4erxRMI4YMDi4KrGCA130eWty8x0O8LpPoJQQmZZs9ZaEVqX5Bf6tQJBSGhqVqmm5i6sKHwf57pApnl9DIRfcO0bgG8DxoVsriJEEPJPqPFwSm0vPN9AXKNjmzU/Ntu5WJCJ+dRWd3LuSNBQ5feieV/XumhZ/kKNgFEaFkWI8UrOwaaGKKTKKsQYyy428RXs6S/eyUTZVdgMH5rFUqD35Aw== 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:01 +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:01 +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 03/11] iommu: Inline iommu_group_get_for_dev() into __iommu_probe_device() Date: Wed, 19 Apr 2023 13:11:49 -0300 Message-Id: <3-v1-8aecc628b904+2f42-iommu_probe_jgg@nvidia.com> In-Reply-To: <0-v1-8aecc628b904+2f42-iommu_probe_jgg@nvidia.com> References: X-ClientProxiedBy: BYAPR11CA0077.namprd11.prod.outlook.com (2603:10b6:a03:f4::18) 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: 971a1756-062f-43b1-aa96-08db40f0ceb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z6SbkqeSJrZ2EN4nL5a2buEX0UhkYjQXurehhBztfMA0XhM3ygof08J3eWc+xb43aBG0IMo0I4CxkMo8exQjUswFIociBe6JrPX4+36cwinCEetiHRUQBXjLswZM2KQ9NS3gU0FlSpGKxuCbph5wji2ixp07I7V8lBUOCpMQbR9a5BjeowG67DxGCaVVOfRJUNzvXbfzRt+LXdAPncK/0F35kqbjeE568QpKWbI0VWl2Hao3Lg1ceKEi1jO610aWOBV1/x/LcgXV/sxd0TrOJ3B+KVF13hktquwauWwSYGviLRkanFdZHn28FZ7UvhWiC/BXsBZRhpX934+j4SvN10h+gGJuCIA8l2L+hSmeejJX89iK06m3FKAeEEztnMVZj8azlqg+Ef2PTITl94BFNBKXp88At83IJuUNYEhcdE6wZN5OQ/eQLWNHnuhadR+p8iYOD7jFqbDZsA2r7ndHX1c9R2Kq9g3ijJNU03OxsSVF83KBnzY/wquOEvQTbELBjtynkiTLK8uQsmz0ZTNXnldyC/wSvq678OZ8EJiqvPwKl9Qkinh+TYkSY59Hwb2ouSJE9iGNnUi72IFuMazkUfANguPgW0fXWR42WIWLYbeVtYNU3IVmMtpI21DJAcSI 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: AdFI03mAuk7avDzQ9NEQg65jUrsnlIdNK36o3dsFTUVTuUjoC/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ZrSLxXDpFgwuRw9MqyO/bu2/ygtxAxLdTQ9mxvV/Huoumw/xzhH29naneEw0TZT4NKRQyLa33yCWWCxeT6n5Q4nzXrjEVRzBQm8nQYQgus+kWDVYAvMw/XQVxT0/NyuAziGd5DMRKB566fuU+CxChsFjXyrdq/FiVhT8me9wMtJ6Fub5ejT6BD50wxxHofe007cN/4e59eQjhdg6m8D0F3RpvPsgcu3V4/rkXDkJsP/R9lftNRYYXo8RKHwIvrt+DFEAAoBh8FvGos0Jbx/VIINQgCoo4VHnIKDEbS56Z6Oa6AnfJEJBhHnkR57tkB55vWQe7Sy8DJwh1dMZ5QMGfi0lxOSqMYttfS4Va8yR1aZbaNJCexhkuW08S1NxFbVMo7AZvBlF4zTVVUHudjKDJTQQc03mD0P5Px8jyQtjcnFKeq2ZpirDuoESPzWt0dkSSApHR8r+/XtShBgxx X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 971a1756-062f-43b1-aa96-08db40f0ceb5 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:00.8786 (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: vkhff+qS+U68PG9NZ4RZMJeoYziZ2rNW4sYPk2BOBh0Qa8iJsDhlNiWNM1ptH42M X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6342 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This is the only caller, and it doesn't need the generality of the function. We already know there is no iommu_group, so it is simply two function calls. Moving it here allows the following patches to split the logic in these functions. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommu.c | 50 ++++++++----------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 73e9f50fba9dd2..e08856c17121d8 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -126,7 +126,6 @@ static int iommu_setup_default_domain(struct iommu_group *group, int target_type); static int iommu_create_device_direct_mappings(struct iommu_domain *domain, struct device *dev); -static struct iommu_group *iommu_group_get_for_dev(struct device *dev); static ssize_t iommu_group_store_type(struct iommu_group *group, const char *buf, size_t count); @@ -375,12 +374,18 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list if (ops->is_attach_deferred) dev->iommu->attach_deferred = ops->is_attach_deferred(dev); - group = iommu_group_get_for_dev(dev); + group = ops->device_group(dev); + if (WARN_ON_ONCE(group == NULL)) + group = ERR_PTR(-EINVAL); if (IS_ERR(group)) { ret = PTR_ERR(group); goto out_release; } + ret = iommu_group_add_device(group, dev); + if (ret) + goto err_put_group; + mutex_lock(&group->mutex); if (group_list && !group->default_domain && list_empty(&group->entry)) list_add_tail(&group->entry, group_list); @@ -392,6 +397,8 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list return 0; +err_put_group: + iommu_group_put(group); out_release: if (ops->release_device) ops->release_device(dev); @@ -1666,45 +1673,6 @@ iommu_group_alloc_default_domain(struct iommu_group *group, int req_type) return dom; } -/** - * iommu_group_get_for_dev - Find or create the IOMMU group for a device - * @dev: target device - * - * This function is intended to be called by IOMMU drivers and extended to - * support common, bus-defined algorithms when determining or creating the - * IOMMU group for a device. On success, the caller will hold a reference - * to the returned IOMMU group, which will already include the provided - * device. The reference should be released with iommu_group_put(). - */ -static struct iommu_group *iommu_group_get_for_dev(struct device *dev) -{ - const struct iommu_ops *ops = dev_iommu_ops(dev); - struct iommu_group *group; - int ret; - - group = iommu_group_get(dev); - if (group) - return group; - - group = ops->device_group(dev); - if (WARN_ON_ONCE(group == NULL)) - return ERR_PTR(-EINVAL); - - if (IS_ERR(group)) - return group; - - ret = iommu_group_add_device(group, dev); - if (ret) - goto out_put_group; - - return group; - -out_put_group: - iommu_group_put(group); - - return ERR_PTR(ret); -} - struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) { return group->default_domain;