From patchwork Fri Sep 6 00:40:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTl1v0Cz1yhD for ; Fri, 6 Sep 2024 10:41:14 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN24-0001vA-1O; Fri, 06 Sep 2024 00:41:00 +0000 Received: from mail-bn8nam12on2045.outbound.protection.outlook.com ([40.107.237.45] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN21-0001um-FY for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:40:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UcN06mtwIf3Kv5LLMYC40UiFdnOVNTSMrdWmkPiiIQbyLRLh7bFzvWyybxH6rdWc6ZBDAA4NB8cl9fowkZH15WpRPsMVfiAn/CRfASIymdaf2bXS7sGCybI7FvWucPJaGVblrhXsx4F8T0C0G1RGGg9J9n+bgO0V+Ptao9zJruCaf+Tzwwv4A+8TKftXckzpO3PT07gCOshT1njE/pqGtbHLt73n1qeRfa3stcjSVjVYHg3KYkaxwuQwqP2KLXLdGjko7cQ+FHuFVP9Nl2P9blirZcYxVU9niLX7hAf+K+ClI6Wr7Fp/McelapgHp0Mv8L7aUMy3KwluFu9DuNuDQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=23STIrtpTrBBp//iP2u04AaBgq1/lAD+tvhQ9GGrU1s=; b=HpA21db0mLVo3jWPR8DiPJT3z3al8Slpi2q4+hgZE+aD3RIHmmfYM657nyMAKwf1TnpB1AjZm2GglAb3FmOZId8H75OPKuzI9yzWQpuiu8A7qOKl9XydcQD+I+vqFJPzQqt3gwUFXSczxWO2jOANDqzitiQJSP95UIcUeUy2EZtYhUGpJLquzgf/pjx2nF0CE03LFVAIFAwCgG9oU8QqjRFZeUGl2o/d8TcI67hs7qDi45M0A9PDxgmdasnuHeW6kTRefobw6Hcnr1Coow1flt0Ia8lMTOX9Lhb6KsgqAvGJav99F25+7QsFxCIf+Ze58JP1EdT/SIqM+so8jV6Pbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from PH0PR07CA0054.namprd07.prod.outlook.com (2603:10b6:510:e::29) by CH3PR12MB8481.namprd12.prod.outlook.com (2603:10b6:610:157::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Fri, 6 Sep 2024 00:40:52 +0000 Received: from SN1PEPF0002529D.namprd05.prod.outlook.com (2603:10b6:510:e:cafe::96) by PH0PR07CA0054.outlook.office365.com (2603:10b6:510:e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.16 via Frontend Transport; Fri, 6 Sep 2024 00:40:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SN1PEPF0002529D.mail.protection.outlook.com (10.167.242.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:40:50 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:44 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:44 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:43 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 1/7] UBUNTU: SAUCE: dma-buf: Add dma_buf_try_get() Date: Fri, 6 Sep 2024 00:40:32 +0000 Message-ID: <20240906004038.800613-2-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002529D:EE_|CH3PR12MB8481:EE_ X-MS-Office365-Filtering-Correlation-Id: 674798a7-11b0-4fa0-abf7-08dcce0c8ed5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: fpzpc4eDSQxJCxB5IG3R1IrpL0ay+8NcL/jPPH499VNiKqMB3v513TxG+SjuOnC7auMiFgHlsIsKb5o5zCN//I71ys9iwMizQFlOOxGHERDxJEXpRXt0guK+gaL5LAlGjoWabI4pZiF+hHf4pgAUFVUnBcrDeqij9EDt74lfOGlv2R7R55ZnWkK/XqZfJLpC8Ci3MGPw6D2+R2/s5nIE6SDNRBhS9cNz2wMzp6brfh5NMUsT8V6WCoyvz2YBDKsOOQDMmCal/YwS76pNEXd9vvr8M0/WVvge7TkdOnRPSlOpFC36dM0kkC9SgXwkpsFZociGQ9eIXXZBfmeeGnSMY/QOjGBs+2+7OznWu5+G6SlEMSeqlXclyRO129Xr48hLwDqdTEAiaq+vQQzYn7TSDtP8sIoGCZD8QeO3Jj1RO8Lxz5BwGC3zT+Ba6avA/Bg8EFOpN36jFJ+KF4Sq9nbrntPctz7IgTt46mX/0LNLD9fq4Z7TbVjRWjny1FjyYDh5UTmrCmEDhLMskLvYFZShXK0+tOzrI5dR0fjfsF3zFyMi3MB70gS7F8IaEX/jP8BgkqE8hKVy6l0Uol/oFwugRf9UyzrPSQwWj+2wQPZ3pSyj6xR+a75+8R+0X2UgLbxn2brxqezeRcZP8T3BamK9/9DHUDtjaR5puba4nDLvVrjbHXtjAjyI0jjBTt+yCCUxhk4725wGfZFmtpfxS4SccjnoBIe44nxumUyj/Qiw1F/LIqyqq0TwrygYRO9yQ3fKO1/v9CBwzsEAjE2Esv6pW2cWq/jzXZAGl3s/PUyWbxzRWFXPhcjZ+WbWt3fcXU6YwA8zNJB3SyxNhE9GgJo9ubhB1/ZwIQUxxKj7iIAswwPJkDWILUcjDQoAv1rWNS/VpmxM/q2YyVr58uQMsrMgGrEEyflxLmzB60YK9hQKZw19kCg7arIGjt69D3c+cRZyMhKtrjJRsBQTP/NVOyVhhrb7tZgTwX8DmRZZSS+ZVDNgg7RIaT0Jx6bO1Bo6Hcn2iMD4axVF6VKAHFWpQLxg3YdJSLBmObAIFY+IGDQfLaJr5gwSvUBGvdxfHaqKaRLspt6tQIBGvh/9I5s1X69WdOEstqt77hCeFwlgD0/MgGeHPHFqU8HIvffuCB5qcv5O3HHyESlVJ9g2HJTuaHYwJttv83W2/mfP1k9l5gIlcUHwfZ5FnacYp9kIMWa4O1sl2Gapu5FkK971x4UcILeHrprOchh8R2pbb58Le3i9wKvpiklIHYGmRrwjb74gUiaglQ2WxaMWI7pWspmmaqbNds6YeQSoc/66MkY3ms7hwYYilbuEYbBuS5EbBjjOBJJBfrIAoPbcu/NxunJd++e63NjFhdD90nruCeuRLBFBSoh2Bra1eWwY5An0ZUbYJcvwdraPVRBuqHVx2e8GDMxlKbW06vv2m9erJWCRbEu00lhbyKHaJknpduosFpoQvkQu X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:40:50.9658 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 674798a7-11b0-4fa0-abf7-08dcce0c8ed5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002529D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8481 Received-SPF: softfail client-ip=40.107.237.45; envelope-from=witu@nvidia.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 Used to increment the refcount of the dma buf's struct file, only if the refcount is not zero. Useful to allow the struct file's lifetime to control the lifetime of the dmabuf while still letting the driver to keep track of created dmabufs. Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- include/linux/dma-buf.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 3ad636a13b8e..68a4326833d6 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -609,6 +609,19 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags); struct dma_buf *dma_buf_get(int fd); void dma_buf_put(struct dma_buf *dmabuf); +/** + * dma_buf_try_get - try to get a reference on a dmabuf + * @dmabuf - the dmabuf to get + * + * Returns true if a reference was successfully obtained. The caller must + * interlock with the dmabuf's release function in some way, such as RCU, to + * ensure that this is not called on freed memory. + */ +static inline bool dma_buf_try_get(struct dma_buf *dmabuf) +{ + return get_file_rcu(dmabuf->file); +} + struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *, enum dma_data_direction); void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *,