From patchwork Tue Mar 21 19:14:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13183088 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 7187DC6FD20 for ; Tue, 21 Mar 2023 19:15:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbjCUTPc (ORCPT ); Tue, 21 Mar 2023 15:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjCUTPb (ORCPT ); Tue, 21 Mar 2023 15:15:31 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2056.outbound.protection.outlook.com [40.107.93.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8437328E80; Tue, 21 Mar 2023 12:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dry082sR05ZLLXcjMpGW9Fai3/wLVn941nujmAuQjSpbP9w3Wxg7M+415YjyGTIcCuusDQZVbwiS0OwuR0Xcx148YLrlUndDBxk+6W0uevlKKTR3Jcf65K/oGDcPrsPRAkzXh7b2BFoCcrSl04GAkrKyJiwsqV6gCeSzrMBrOxqQtUnr4PcKPTn6gpKWxe8/HGSZ/z4T5tBUxlkvzLkLVlk9KmJ/J5q1WBA5dGXuIsfjdNAsrfXrswkPuQ0hpchtpsCIZEz2gFFY6P+dEGok5H7ZjkJ8NVKMCmckYaarZD8MNlJ7mw8qBks5ksQ7WTP3KOA2jG0eKg8Zsd3uql4dSA== 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=xypDS+fWL+QwOX1nn84bHtzcNWNlLcLZqKhHnGD4/N4=; b=Bxwn8PNgU8EanwLNTWbVAvwXbnCbb3kcSrRef4D9cSrNF/WGfF8SqGEg9ci2LkPxCwGHPVk710DZelX1nZOyNjbYcQf3GRbtfYjFA8un7n2Q1RhKX6k209Vmna3bTkNW6GBJEFrHhbTZM1xDrrb5l47hloeVvBUpiyheOW18om7Cv5WoCGqrbvSuK8kl2dgBVJq3a0jr5d+1MRtCCU4H99WAtefdRgO9OUj3VCqeJEHN2Ykk7ZsMg8vMcjG1HydkyZkh81TU+RNiaHAYjeRLVf77QE8Go/GpZHrcsbhoX3CG/I3mlaPsE9NzKdLg4ddYGbsF1Y4ESEs0xMF6obU4TQ== 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=xypDS+fWL+QwOX1nn84bHtzcNWNlLcLZqKhHnGD4/N4=; b=VioMr57u0ei9zNoNTs2Me9G8dm78kFTvh1b8J85ctrEStEujw3ytoqo3InfndY8L+GZFnig0uAYY3dZfXzQ9PfnHR5n0+5yBDEQ8Fca+fNZ+Hs+XiYgq9Vu0sT+4xvZGalbF7aK90GdQAs/E3ZLVfCcwtHPDXf38vpPy+EsLZalR/s8SSb1majORuXC/VTQsxR/vxvNMjntq0OZilGliJ+N/MAlRCtaJ2PcTZY0JKZonHXNM1rYpYtMay/4gyVRIUePbV+DJhQBhRe4BKo+AZaF14cvvmdt/iXjnDWsr2DmzHijIyZiAwZSM5POw+gmuKBHY8pk7qjZhaOZ/5CETGA== 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 IA1PR12MB8237.namprd12.prod.outlook.com (2603:10b6:208:3f3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 19:14:56 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::ef6d:fdf6:352f:efd1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::ef6d:fdf6:352f:efd1%3]) with mapi id 15.20.6178.037; Tue, 21 Mar 2023 19:14:56 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org Cc: Lu Baolu , kvm@vger.kernel.org, Nicolin Chen , Yi Liu Subject: [PATCH v3 08/17] iommufd: Move putting a hwpt to a helper function Date: Tue, 21 Mar 2023 16:14:42 -0300 Message-Id: <8-v3-61d41fd9e13e+1f5-iommufd_alloc_jgg@nvidia.com> In-Reply-To: <0-v3-61d41fd9e13e+1f5-iommufd_alloc_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR15CA0051.namprd15.prod.outlook.com (2603:10b6:208:237::20) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB8237:EE_ X-MS-Office365-Filtering-Correlation-Id: f237ffa1-e3a8-4fcc-109f-08db2a408d70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mHRCslcYyvB2PRMyUxjfYQDc+PyaEZPYt42rUHbNtt6M3lNrc7hqe7xwC4iWwsOynkRlFp8SI+mcc+swNogIz9ODIA9gzMs0WUV5idj84S2algEWZ6dQqvEsd46jNohbweliM3se+AmHGCkS5bIKniCeKsM2vUtoiEp2Pd5GMw2qVtzKyOgZgHpIpTSqvTwiIyQx6g8GEYz/FeMjLbviYYfDKMx+DloVKWvDqFuKeZ1qMOb10bV01dO5/cejMDA7c4V28Q+ociB49K8dng10HCC+ZzGxNxrUg82MIDEkbiy9i8QxZ7mCmP5E98qzDJMj8PJ5GkmsOg3eRPscTENmhO3hDhbExUGIYXADUBSxn/NE3vBgL477U7OW+U0aiqVks6xuOVV94xKi/CEkGk1FvvUr6rclKEcn7Ho0jrS/uxBtmepT2KYRIwsTX/fhqpkwMJ05hB75zu80DdsyoFR3WLq+OE8G+cCiZdQS6mxQ89XJoG89gxQbjV1YKt3oVP4F5ogyUCp00HknLN1H/NNMdIa9u/SrgCxvHxErcKhzvZAHmwk+zd2ddpVWeXqMZB/cS/fkl5ta6lB7JehQ2EleRK31RMxgJNmQqcMLD+a4dFU5GCVgvCrfyGYDW0sDxgKRfbqYAgtLUpcjepee+o4a3GgcSIm4s2u44ZMegFkRomK/XmynGTmXtVDt+38jedAH 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:(13230025)(4636009)(136003)(366004)(376002)(39860400002)(346002)(396003)(451199018)(38100700002)(36756003)(86362001)(83380400001)(26005)(6506007)(6512007)(186003)(6666004)(2616005)(6486002)(8676002)(66476007)(66946007)(4326008)(66556008)(478600001)(316002)(54906003)(5660300002)(8936002)(2906002)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pQ/oQemMcbkkCg1ZsUes+1HBLaQV9YeOXWdmiVTkRXIhXEkfXE9iWWfKqLebyPSZ8Zjn3omiWodMurl50QGeZ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+q/IE2+IJRD5C+/mHYWdIf+xV3TDGe3hu6qARH4sAjYpsQlhskLr/wN5Giz9r8FUGhHIMhxwTOCL8Y5fNg0ddtjE9zPrIi4RaiJVzvYavHkaL8oEySRSRp8RDR0Xq3/ICxc9WJNIP/DKgKD4Ob5vtbt9MxxkADuFvBgIJUjHcRICFXYT4dWpsBrN1rxtVdPib9HJ7HAMsVtV7VIqf+iy12vop+MLMTzxU4yW86oiF/upPWpQLXWwDBgaw7XWaNZk2kkkKO4Zvf/vXuFXE1u4C7IbSt6vWpJOHRWsG92XqGRFML8ReXdEADixqy88+2kJSxcPHAkyVok5+ywnKOXv05pK5pL96jJ5Jc5oJMk86U0EJY++3ekfFBltjaCt/YEIDrwKAw6T6NccJwP7wn0jZSwSlZrwvc7vo/LJzkwFgkj6CEsIamZt48zmht X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f237ffa1-e3a8-4fcc-109f-08db2a408d70 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 19:14:54.3980 (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: mY+hHtRYOlLMInX2fl23YMmvYpTsjT+h+M6Et/FkATZ7OFE//R479Af4ffK6i5KP X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8237 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Next patch will need to call this from two places. Reviewed-by: Lu Baolu Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 6 +----- drivers/iommu/iommufd/iommufd_private.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 616a23939e968b..8946de73660ece 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -489,11 +489,7 @@ void iommufd_device_detach(struct iommufd_device *idev) hwpt = iommufd_hw_pagetable_detach(idev); mutex_unlock(&idev->igroup->lock); - if (hwpt->auto_domain) - iommufd_object_destroy_user(idev->ictx, &hwpt->obj); - else - refcount_dec(&hwpt->obj.users); - + iommufd_hw_pagetable_put(idev->ictx, hwpt); refcount_dec(&idev->obj.users); } EXPORT_SYMBOL_NS_GPL(iommufd_device_detach, IOMMUFD); diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 7f4936cf537be4..8bf053f4d4a9ce 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -260,6 +260,16 @@ struct iommufd_hw_pagetable * iommufd_hw_pagetable_detach(struct iommufd_device *idev); void iommufd_hw_pagetable_destroy(struct iommufd_object *obj); +static inline void iommufd_hw_pagetable_put(struct iommufd_ctx *ictx, + struct iommufd_hw_pagetable *hwpt) +{ + lockdep_assert_not_held(&hwpt->ioas->mutex); + if (hwpt->auto_domain) + iommufd_object_destroy_user(ictx, &hwpt->obj); + else + refcount_dec(&hwpt->obj.users); +} + struct iommufd_group { struct kref ref; struct mutex lock;