From patchwork Tue Aug 13 09:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13761591 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 615EDC52D7C for ; Tue, 13 Aug 2024 09:05:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CDDB210E069; Tue, 13 Aug 2024 09:05:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=vivo.com header.i=@vivo.com header.b="GEAZcncz"; dkim-atps=neutral Received: from HK3PR03CU002.outbound.protection.outlook.com (mail-eastasiaazon11011000.outbound.protection.outlook.com [52.101.129.0]) by gabe.freedesktop.org (Postfix) with ESMTPS id F2FC910E069 for ; Tue, 13 Aug 2024 09:05:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dj4frDjv0jZ+oun6pWyzSBcr2SKZlLZENPr5rl1ENBqCzb11/ObJ5ZGHFXrzKfe5Pwo7MdTK83e1G15KQZB3C7odcNUbyz/OyD7B9DPc947kTpomjRmtu5iin1XErrT5jz2mwzv8v6S86mNQWTe3ynl+fww0JhpVakLzhR9SPPRfZP/tLxBM8Glqs2mtX3JtTnqpJHDoEuyPLTErT3GBSiMy+mx4x3Rj84b9efXdCtxywWq4PKLmX2oveha2FP3QJe1wwRzZ1MQxqLGH9Ogt4r5Dj1FXRYEMVeLYPf6rWz1gO/O1zN5r+elBJ0EoKaz31Zywz0Cq5hr6qzvp+JWYCw== 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=p+BAVsbafWS5M8Zwsgb4zx7BrseTuCYrgJ+/U/HeGJY=; b=M958T84C0saeXEBOckjE6oO8AdFXq0tHtHMXV7/576U16lfbcvxfTDE66P351c0hRI1Ku/7/NpQMmR+7NQaZ7+8KaY7lR6JwWALGcMG4ZwdKJMPUtzSo+4SZg536fDJLSmCQ1mYCJwXv9zQz/0UHpKm5wfDPOcOqI87+mzrScitqqOjFak7APeOzOuDA9EMLB6Of+R4we2u1E8cs26F6NaWWWAltjkagsdxG47QPHIXRc3SE2HYiAgbrLj3JK2BOcXKC7nqwHEoQxq/ghfIMXH+0mZw7RRi/XcGUpmS44psMSfz1ZSH+2sBADHabm1WUVfQzG2KUhkYDWlK1PduROA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p+BAVsbafWS5M8Zwsgb4zx7BrseTuCYrgJ+/U/HeGJY=; b=GEAZcncza6DcXI9S3G7Mca06HLzrSydTaszrh+sUOKzOYLrsw5zTHGzdYIU7QnfckdBv51UkdOH0CVVQ0CBfmeYw+DRZZWeOI9VrL6yCJGSWTceVTPmvpEVO7JR8MzZJrZ4Yw5IhaNr2seyiFuPU/nS7ThtmQYOYnWRWWJWg7pDbdbpvGF6fue7gk4XkrIreqlBWECAS1vEzBdrUnXdzq4R6avvEIFGlvps2NM7h/QKxon0ACNqHXUrFILxYdOXFPKQecekKRFGT3//9TfV8lWzSgqTYaFGO4z8YiBsw+r9XxntPA5/HfWaK1FeX2zF6PrY4dXV8dejaJpxcC9P6Nw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by SEYPR06MB5400.apcprd06.prod.outlook.com (2603:1096:101:8d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Tue, 13 Aug 2024 09:05:35 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%4]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024 09:05:34 +0000 From: Huan Yang To: Gerd Hoffmann , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH v3 0/5] udmbuf bug fix and some improvements Date: Tue, 13 Aug 2024 17:05:06 +0800 Message-ID: <20240813090518.3252469-1-link@vivo.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com (2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SEYPR06MB5400:EE_ X-MS-Office365-Filtering-Correlation-Id: b87c1c79-bbc1-417a-bee3-08dcbb771743 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?09J0ZkvpwgNhKxpDUW2zdivv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6mRChu+?= =?utf-8?q?w8oEjzk02HOewmjwXijC8QyZ7AF4Qv1fVGHgebKvEvSP/Kt3ZZ0zKgjI55uhil1uc?= =?utf-8?q?ftjIkmIuXVYSbFYLxWFeFl21jegukdky4H14PUwy5qlxBwPPVW9fWpzjz7xtjK7j0?= =?utf-8?q?VM0no5nl/Hv7O8Anv9+BR4UfqIaxvNq+zg6LPpmrhIOw2+xqClUHj/a2yqlrluzYF?= =?utf-8?q?MO6WgUDF963n1cCfezRGCiAbHeLpRtyUl8FqiRpl99JqXC31OXi/tGI+C/HVSlByt?= =?utf-8?q?Nhwx+kbjw9qE4H6ksS3Bf/Ujg5sI4tDxpBoj+v61lgVPtnLrEbHo7VTVEc+lO3n29?= =?utf-8?q?bqHaOVpTkEe4akK7nmI+8boiZVmbAEtOoqZAdYrPHgYlHFvmT2SXb/PaxknFasHa6?= =?utf-8?q?dojn34GZe5GavKr/+jL3e1N52AQnysEQvVGpswd0nenejSs5/JP7AHHY=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PUZPR06MB5676.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014)(52116014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?v8JAvVXUrwFFFi2NUBlc9hrAqPwj?= =?utf-8?q?vKQ9sjATr0V6+pQ5LS/wdHSRR7q5Kq9Fxi7oxx6O6uYgv20Tm9IWxMbtScrQRE/Gl?= =?utf-8?q?Ah/yo5tPkxZpU2b52YGNm1wGn0bqqpyY8ArGn/Mjj2mbJSNwe4zct5mBs3hk/eO56?= =?utf-8?q?9EK6+UJLMlVoi4Ok6eLXL23YN8PFaSb2gEKjf2W45ZqTuKgpDLdCvy4chFOhrCGF1?= =?utf-8?q?77Q6itJxVfNllTEJQCSMgKAhEoB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fizIKcrcXIFLxF4dQFCtrDj+6DxKjs0WaC/r?= =?utf-8?q?RJQzqGjcXNfPeB827aL1fIr7sc2+IhfgK7j3OZKdbOUfa/i2OhL2xaGJqk+TGzVWR?= =?utf-8?q?me73AbSzbXbUpq8z8obbYMLwgM5YXXF/Khw1PCg7hS9cifkK85+0UOiLb3mXEtaMu?= =?utf-8?q?6yaKDwaw/P0yJ8uS4gnJeF5S1N9j+1sgQf+YDkDqOOJTxON4WQsSxt0lbAMmD3D5G?= =?utf-8?q?Rh3uC5sqKyVJ7R+3QvXLTirtuPvAcptbgIDisyyHWNlMliPhQJizEImQPp5WM15Qb?= =?utf-8?q?oVY7OxJGh2M7/IU/D2Rp9aRcvaMisisniaKFRdcAQZWSgTwwIlPOVtBmcaRd2lUVM?= =?utf-8?q?rZwjVSPMMFdR9kxL6D0110VxD19eGvw5XnyD+6zGEsM1b8LIJdSwrHC5m5WwsyVth?= =?utf-8?q?jY33ExIequ4D?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b87c1c79-bbc1-417a-bee3-08dcbb771743 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 09:05:34.8014 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zeuEYigkIYyfLN3jjNZR3NRrrcIjR8YQl4AilHjWnb3w4Qs1r8qHvMPTMwUtqdYHees8LVQBqNJoTFLRV9ZDyA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5400 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This patchset attempts to fix some errors in udmabuf and remove the upin_list structure. Some of this fix just gather the patches which I upload before. Patch 1,2,4,5 has passed the udmabuf self-test suite's tests. Suggested by Kasireddy, Vivek Patch5 modified the unpin function, therefore running the udmabuf self-test program in a loop did not reveal any memory leaks. Notice: Test item 6 maybe requires running the command: echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages Patch1 === Try to remove page fault mmap and direct map it. Due to current udmabuf has already obtained and pinned the folio upon completion of the creation.This means that the physical memory has already been acquired, rather than being accessed dynamically. The current page fault method only saves some page table memory. As a result, the page fault mechanism has lost its purpose as a demanding page. Due to the fact that page fault requires trapping into kernel mode and filling in when accessing the corresponding virtual address in mmap, this means that user mode access to virtual addresses needs to trap into kernel mode. Therefore, when creating a large size udmabuf, this represents a considerable overhead. Patch2 === This is the same to patch: https://lore.kernel.org/all/20240725021349.580574-1-link@vivo.com/ Patch3 === The current implementation of udmabuf's vmap has issues. It does not correctly set each page of the folio to the page structure, so that when vmap is called, all pages are the head page of the folio. Due to udmabuf can use hugetlb, if HVO enabled, tail page may not exist, so, we can't use page array to map, instead, use pfn array. Patch4 === Change codestyle and fix a potential bug. There are some variables in udmabuf_create that are only used inside the loop. Therefore, there is no need to declare them outside the scope. This patch moved it into loop. It is difficult to understand the loop condition of the code that adds folio to the unpin_list. The outer loop of this patch iterates through folios, while the inner loop correctly sets the folio and corresponding offset into the udmabuf starting from the offset. if reach to pgcnt or nr_folios, end of loop. By this, more readable. ubuf->pagecount already set before true set in loop, if get some error when create, This means that pagecount and folios are not equivalent, which could lead to potential issues when release. This patch dynamic update ubuf->pagecount only when folios update end. Patch5 === Attempt to remove unpin_list and other related data structures. In order to adapt to Folio, we established the unpin_list data structure to unpin all folios and maintain the page mapping relationship. However, this data structure requires 24 bytes for each page and has low traversal performance for the list. And maintaining the offset structure also consumes a portion of memory. This patch attempts to remove these data structures. Considering that during creation, we arranged the folio array in the order of pin and set the offset according to pgcnt. We actually don't need to use unpin_list to unpin during release. Instead, we can iterate through the folios array during release and unpin any folio that is different from the ones previously accessed. By this, not only saves the overhead of the udmabuf_folio data structure but also makes array access more cache-friendly. Changelog === v3 -> v2: Patch1, avoid use page, instead, use pfn, and use vmf_insert_pfn map suggested-by Kasireddy, Vivek Patch2, update acked-by Kasireddy, Vivek And keep the kvcalloc on the same line. Patch3, avoid use page, instead, use pfn, then use vmap_pfn map Patch4, split v2 patch4, single update codestyle to keep review easy. Patch5, another way to remove udmabuf_folio --- v2 -> v1: Patch1, 3 Rectify the improper use of the sg table. suggested-by Christian König Patch2 add acked-by Christian K�nig which marked in v1 Patch4 Modify the data structure to restore the use of pages and correct the misunderstanding of loop conditions such as "pgcnt". make sure pass self test. remove v1's patch4 v2 https://lore.kernel.org/all/20240805032550.3912454-1-link@vivo.com/ v1 https://lore.kernel.org/all/20240801104512.4056860-1-link@vivo.com/ Huan Yang (5): udmabuf: cancel mmap page fault, direct map it udmabuf: change folios array from kmalloc to kvmalloc fix vmap_udmabuf error page set udmabuf: codestyle cleanup udmabuf: remove udmabuf_folio drivers/dma-buf/udmabuf.c | 198 ++++++++++++++++++-------------------- 1 file changed, 96 insertions(+), 102 deletions(-) base-commit: 033a4691702cdca3a613256b0623b8eeacb4985e