From patchwork Wed Aug 17 16:11:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 598024 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 E8654C25B08 for ; Wed, 17 Aug 2022 16:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241024AbiHQQMr (ORCPT ); Wed, 17 Aug 2022 12:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240665AbiHQQM0 (ORCPT ); Wed, 17 Aug 2022 12:12:26 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2085.outbound.protection.outlook.com [40.107.244.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92EF4A1D05; Wed, 17 Aug 2022 09:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z76zhMgemkqWN6FZH/cngDKs1Mu/iqrZvIW0dkismymSTSli3B3wkdd1IxUpwJKEQSOFTCoA65Aqqid3N3W2kJb06pWxsY+cFcsn54EJKVHadgLRV5lcTpsKiflNNQP+SgWbb499rPP/nlaTu/xLsVFNQ/8TDltgyFA+NdKmCXABhadXtgC5/O+TCA8rReIFrTJ18WOUKjdd+P+djDh1mYATM1QtR63dpbGU9uW7J16ExOI32Ro71D+RcEwrR0T9muio5XOyX6c0414yFQbWZYZuC2GtE3WUGkphGjgsgGo0ltqfp8TaSZt9sGNLlbrF3ogqGadOZxai6WxEFc4j4A== 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=YoW90LWPuwfvOOkBJA/EMKYX3uNOBwS4KYHJwbCGqbk=; b=cykaQG7q6QyckTBSkUjEOcFBVsAy/lwtt4oYZJ5TTvjaD0Ah0b0WkBZA9P32nQl+3cfkGGow+8iB8GVhM5Ly10clY7lqT9mGEzknqkA7IBJN1M5VqFawaBuBe6+HACZJxgNtQCsrlKqLUFEc7ISQkhvbtjn051rV6sczrgxE/dOOonKdHhR9cE2ejVyKn44ctLI/2SEeND1K8Fbr5vEahDleMQ9x05UGUKf1SL4+hsVTXD0IWztLFGY0MyZpsjLGbZ7ECfXorL2/UIfi7uc3tOWqiU8cYf7mTDsCXBbTmbVeLe/WshPAa7N/leJJtCvVlJLwkqELoGnbBDjEH1G3UQ== 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=YoW90LWPuwfvOOkBJA/EMKYX3uNOBwS4KYHJwbCGqbk=; b=j2pnhNffBMRC9DTqj9oLN2r50C9fPgGHM/Nk/7Pglw7KD8J86p105qXzDtOIq4Y9iyQcqYkFMefc+AHJ3cAW2vUuHg/6EQ8s8AAZhWcOrXKEMy97qEPOJAgIKNlktV+0NqkBk75fNmmYd428UC+7DI3UxwX40GoFS/1aF66eFTV8aDUWSHwPPtNI1/YohmwnLvFSm3KrWgp3pf3Q0/ra8z68erMxoio5FEwMcNGSGXMPnzDWELNICAPXRYhKjnJXhTuV3SU9pVMgrAYlI2UfWywIkNmGzbKIkN0wN1oW7JbIf+YEL4JWlf7MXRFxuY8BowwrNvpKvwyrtCHJob7PIA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by CO6PR12MB5458.namprd12.prod.outlook.com (2603:10b6:5:35b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Wed, 17 Aug 2022 16:11:43 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5%6]) with mapi id 15.20.5525.019; Wed, 17 Aug 2022 16:11:43 +0000 From: Jason Gunthorpe To: Alex Williamson , =?utf-8?q?Christian_K?= =?utf-8?q?=C3=B6nig?= , Cornelia Huck , dri-devel@lists.freedesktop.org, kvm@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, Sumit Semwal Cc: Daniel Vetter , Leon Romanovsky , linux-rdma@vger.kernel.org, Maor Gottlieb , Oded Gabbay Subject: [PATCH 2/4] vfio: Add vfio_device_get() Date: Wed, 17 Aug 2022 13:11:40 -0300 Message-Id: <2-v1-9e6e1739ed95+5fa-vfio_dma_buf_jgg@nvidia.com> In-Reply-To: <0-v1-9e6e1739ed95+5fa-vfio_dma_buf_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR05CA0036.namprd05.prod.outlook.com (2603:10b6:208:c0::49) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5e25a312-2e10-4ae5-a0d3-08da806b2d3a X-MS-TrafficTypeDiagnostic: CO6PR12MB5458:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0oobJOxrjozstFJbpTjHcHQToLGpeP5GoHiM+N/07bWzSZTdtfoDnfE2v58JLDcIocdaqncxDtzVCy/8g5ztbFWkf+DuQwTypQt4JRnD1lZnBVrB5/ZhpDsBl5NQL0tf/lL2afrD50tw650jKMDiW3ZEho+IYYuSaOqcOBI0YAZAKMiDek1r/Ut9BcaG5jFy9RahDhfOx4DbCVzoEKctzFrrCbGiTNsFAs1usm4W4LuFaAjG2LkTTjl22lrEqlBS9izmmB2q4W/WlMwh6JVqXcPkDOMC0gD2nFC11FuKE3fAk5YfDtuhk/heRK3+4ZTxcqr3ZqNVSS9zUuVef5IMJKONYkMt2d94KQUYcc8I59SvlRqz/CRV8J2hT2KC0kj6lpAuMTZ14PW51wSOniaL0wPhS0gOOqRg1dONxuGlNA0YZ0T0An7MpdNP75RfkqvERbxTnmdq7uEqTJdofjaE/E5B5DQOmeLMaPPBzmoqvceUh2dB4XXfcqNLSUnLYuY2YYPUuPH0R0BCWakEXd0GqC96RVtefEiwbrQu3SZqEF7FZJQGQg2E4mesKPJR8xilSBi3KNMUeDdeR28tLVLQ42+Cbl970+Do7TZQM+UgVtyyJ6S+F2Yw3FeWPUG0pAVffMoTHKgq3xJ+94a9Oba809VlphZR8hfF0Z9tXTw6+V3GhSOHEKl3vwcSNhVlnCNqqCV81exuxCZ1l2RpAaww3BvfezjrQDRAdOv++W/lkJHmTCbJASGy0sAbefLcr8DKedGsQZ7iEkdbzv965lL3SjC5wXO8Rk+O+1gIFPlCClA= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR12MB4192.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(396003)(39860400002)(376002)(136003)(346002)(366004)(26005)(316002)(41300700001)(2616005)(7416002)(6512007)(2906002)(66476007)(66946007)(8676002)(4326008)(38100700002)(66556008)(186003)(5660300002)(478600001)(54906003)(83380400001)(8936002)(110136005)(86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Ih4tsPuqpVqTxC6xFm+CGpky7gbwU3jF98Lhzywf/MdYFO4OdaLZPzZ/Ppw95anIepJKKRsbrxpaRCuXdtkfM8seyVOtyh2Ztku+JbFHhifP4urt8uIUCxOcX5CkmzVXYNl51u23enko79s7KqUNn0W4lpnPtZ0hkb2yImhK0nJzJLX/4wHZtmYH7ds3thbJGeTzwBfYnHTk+fSfyCUd9hvklaAblOA96OUhJC+jLpvHu0T2qCz+2DHAnGdR6u1pS6VmE9jpiFWZoTF1OjJt0VoKbR7pRnI/RDg4sWTS4xDYFU7/Hg3dmB/p5BXbnQl/DpTWu5hIAsYGwNw3b7fWbuMWbWtfmDVJE4NtGluzYyPslYiEsYjuSI6gsseGx0Vcl7XlUvjH/3fQzQ+Q5hB16oNIUX8Xxs3hnhrZxU144tkjkjySH7tTtM15oLTuGqymyV1nKbn7FVb3izNPB5L/W8h9Q3TGv7tb/rzsL9PhXIwIuaNoX5X9MnbG8epAd3Atik7mnc/KCORjOdPnj3Hi5BBte60tFX0q42zcQOm3ICTf+uA8+whE14n909etJ3FxcsHxMRWK6Y/fe6otAdEkorGEMxWhm/L2ttgoDKTkFpcicolX6ZhCIBtv+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e25a312-2e10-4ae5-a0d3-08da806b2d3a X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2022 16:11:43.6113 (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: /IriunbvT7X6ABd3G26KGtH6W09oLRi7hxDx5La4E+uyAcJ2aciXWhu3BoSgT5C8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5458 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org To increment a reference the caller already holds. Export vfio_device_put() to pair with it. Signed-off-by: Jason Gunthorpe --- drivers/vfio/vfio_main.c | 3 ++- include/linux/vfio.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 6f96e6d07a5e98..5ad50aec7dc94c 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -451,11 +451,12 @@ static void vfio_group_get(struct vfio_group *group) * Device objects - create, release, get, put, search */ /* Device reference always implies a group reference */ -static void vfio_device_put(struct vfio_device *device) +void vfio_device_put(struct vfio_device *device) { if (refcount_dec_and_test(&device->refcount)) complete(&device->comp); } +EXPORT_SYMBOL_GPL(vfio_device_put); static bool vfio_device_try_get(struct vfio_device *device) { diff --git a/include/linux/vfio.h b/include/linux/vfio.h index e05ddc6fe6a556..25850b1e08cba9 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -143,6 +143,12 @@ void vfio_uninit_group_dev(struct vfio_device *device); int vfio_register_group_dev(struct vfio_device *device); int vfio_register_emulated_iommu_dev(struct vfio_device *device); void vfio_unregister_group_dev(struct vfio_device *device); +void vfio_device_put(struct vfio_device *device); + +static inline void vfio_device_get(struct vfio_device *device) +{ + refcount_inc(&device->refcount); +} int vfio_assign_device_set(struct vfio_device *device, void *set_id);