From patchwork Mon Aug 5 03:25:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13753090 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 B571EC3DA7F for ; Mon, 5 Aug 2024 03:26:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 31A1D10E10D; Mon, 5 Aug 2024 03:26:12 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=vivo.com header.i=@vivo.com header.b="ASq+hjIp"; dkim-atps=neutral Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2040.outbound.protection.outlook.com [40.107.215.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id 247C610E10D for ; Mon, 5 Aug 2024 03:26:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qYmtZzd0X3XzutAnE4/PsHOwLpZEvW+VH2Wj+xanttWGISA51vclZP2w5b7nKz24qxOSFUn55wlhuHHw1YspiudxbZLvgQQDDihB1XLwWFS1u3UYckGfGKVCqmTK37CE8oT72bVvsEAxCOuAllvAWq0x9dukvSQPuR/OKSr9m3QoJ9xsXRbtnCecNQw70UFZt7ESa0e6ry/go9YSZnfYKFg9IQKZs+hU3LQJ14SQz/QDHROdxhKkJGGT6FIxG4cBFuTYEuV6Q/PX6/3vGSxfjplr3emqlEae08YuwA53cdD7ZvTbFrpJhHv1LWIni/tLpQRZpkOr/Nypqak68GgUJA== 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=bMMgKldtfDr3QFcMmOCqX4/gPmI6D2ZORAU1RuBPZM4=; b=dt8NUC5h+qxgMOByZ2SPl94eUogQv3+z5v1mZjsScxodygC0H20NE3JGnQkUjmzFpnxKjSWehyZogwC01YS1685f7Nfx878IYIjB/BXuZ8NA2vO8rJdNKBx0LIk+F/2nqNcDeYXc0gn1DY17aqYqnAyUQeky75Qj0Dd3j3JxuYsgTAxrrrThSeLpG77P0L+WISaYUgPQRG6BR/hl7NBHQZq7awnx5DFjHyzk7yTPbV1wepHw99Wv0lZ0mW/Al//7iPKNXnqd9Bei0AesDPFhnoXGt/fNNspy37x74bh5m1vvYH/9Abgm/A0r8AboHwE+lmdrAGDp23WaIBEBwYRliQ== 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=bMMgKldtfDr3QFcMmOCqX4/gPmI6D2ZORAU1RuBPZM4=; b=ASq+hjIpweQ6E69ZcnFI5iqbaAL4e87nVDstv0dxJ2qG1DVAo1v3BtKG/ZA0kt5dMpgHSNgzB6Ivaq3tetDt8NutS3Xwy0eNqyyHeOmHCx5F/O7iC/m3VOXvEm3+ACil3+ATOcjcIZBIlLHnD5ZqyMiA/LT+1p69KDmCpJoOolL2uekTc1S+mYWgPsF28FjYwkqyq3yYfC72sE5lWOduhPlTO/bxfa5spP8cJSWuIJxLSqIjBVbVu6/uvn963pDtdsmM+DlAbJSwoHL9OV103+Z3z24nu0ZNrpS3M1gBlKQZ5bvd0aTEzj6u0GHp4JV1cQAFxFbsMVUH48QN6whraQ== 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 JH0PR06MB7349.apcprd06.prod.outlook.com (2603:1096:990:a5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 03:26:06 +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.7828.023; Mon, 5 Aug 2024 03:26:06 +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 v2 0/4] udmbuf bug fix and some improvements Date: Mon, 5 Aug 2024 11:25:42 +0800 Message-ID: <20240805032550.3912454-1-link@vivo.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|JH0PR06MB7349:EE_ X-MS-Office365-Filtering-Correlation-Id: 3db27d5e-de4e-4177-59ec-08dcb4fe5772 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|376014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?dS8fKQFENEKXtJc/6E+gH24w6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utf-8?q?VFU2d2GC1tnOLaqsEtvEWtCyOfBVLZGk4Cq2GSuj7SfIIZBXKC6WPH1zTzPHl2Xsv?= =?utf-8?q?jLORdcYOLYZeIDFu3AdpoHOLjQHXm0fopnpv3ZmN96a4jQTFTqozO8Tg5txuh1EDI?= =?utf-8?q?XR9nbB2y/vwrl4sxwSehVQTFV8NTQMhdK5omGlUgMJbCTS6Ot6C5cfZxsCG+mWN1G?= =?utf-8?q?OZod1IbpLwzRfx0uVickzaudjNl3xPZreniqlsQoWPLImdkJNbK9U3Pf5xp3z4Cem?= =?utf-8?q?oclITEi1yOWIyu3jY3EqB4DCeBvJrFuJIqAJPTmwwbHp22P402Y43Oq+JX3WGNXBL?= =?utf-8?q?nmOvSjDQAqcmQmCzs4OrBR4/12Z/maOwnY33zYKMvDY6ysmFubF4hoqnIDnvVS4EY?= =?utf-8?q?k4rNyiFzuZ467IbSC0KkKb1EtlQIvWfYbSbHzQConBd4tBrry+wtLPUI=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)(52116014)(376014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ay1DHPvIAgZAE4uXyH4iFozG3u4V?= =?utf-8?q?MdN/LkVPQRox2C049oomq2VXyLdcjsPk94baY3GlzJXpt2/CMIwOWeNGR17NEuvhS?= =?utf-8?q?IeNAwjyeDoeJYbdXUcPamZQTabUHnHnKpSHxs3pOaxpkzu9Khr+lTuS9rk3bFAf1Z?= =?utf-8?q?fWn2DNn20kMoVFnZniWSwkOLgkH56QMhCi1iit/A+GgT9aQVIK+j8aY6r5Q5vM/yn?= =?utf-8?q?jSubaSEk0QkifUv7kzYqFdZlCvwOsobXRRh1bq5nS2ETt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+gJSxdlvJIjOa6yzgU8BBHepjfio?= =?utf-8?q?oh/CUiAVP83HkdJ88Fchy9tO+ZoH3Uuqykpgl0+CmlUYfnutPbsggsCTrG1fajSmv?= =?utf-8?q?E9h+BvWhApjgRuWPH+ub8ZXGTW428HmbEiaV8Yuj5hSK+GFBrnGMRGqWIx/BOWsP5?= =?utf-8?q?prbZKziMVcR/QYRuM7mBVrSaucl3nZg7U7bGuvX5JQJ9I0qJum0oq/A4Pmo6C+wmT?= =?utf-8?q?N9BHwJ0Hwx6+hMApsGIXCrr9vf6G4aI5mln4C+k1X3d/AICA1D6Ro0clvGQrNhuNN?= =?utf-8?q?mJFGiylthpxI4jpzzm8YlriQM/lvVKxJFtQ90PUkxLTn2uAV39SXEbHl3szaFo1tJ?= =?utf-8?q?pwa1GfoErtOOSRV6S7vMV/jEi9ZG4iAalk3T8UvIv4XebV1Rp9EE+7B7OWY0O/61K?= =?utf-8?q?+9sCsbqBA3e3?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3db27d5e-de4e-4177-59ec-08dcb4fe5772 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 03:26:06.3227 (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: 7+IPE1coSyszF+EWbd1lQ8fv3LT+JrzjwbfMraW/SYo4OGnFdKKHo2JWFDTktCatpymmfRM3vW/gEfNpnJP0WA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7349 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. Patch1,2,4 has passed the udmabuf self-test suite's tests. Suggested by Kasireddy, Vivek Test item 6 maybe requires running the command: echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages Patch3 changed vmap, which can't simple test by testsuit. But Patch4 restore vmap to the implementation before adding folio. 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. This implementation is same as this patch: https://lore.kernel.org/all/20240731090233.1343559-1-link@vivo.com/ Patch4 === 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 and modify the semantics of some existing data structures. udmabuf: add folios -> folio array, which only contain's the folio, org contains duplicate. add foliocount -> folios array number add pages -> page array, which contains pages which in folios, offset, size determined by the offset of the memfd when udmabuf created. This patch also remove single folios' create on each create item, use it be the ubuf->folios arrays' pointer, slide to fill the corresponding folio under the item into the array. Changelog === 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 v1 https://lore.kernel.org/all/20240801104512.4056860-1-link@vivo.com/ Huan Yang (4): udmabuf: cancel mmap page fault, direct map it udmabuf: change folios array from kmalloc to kvmalloc fix vmap_udmabuf error page set udmabuf: remove folio unpin list drivers/dma-buf/udmabuf.c | 207 ++++++++++++++------------------------ 1 file changed, 78 insertions(+), 129 deletions(-) base-commit: 048d8cb65cde9fe7534eb4440bcfddcf406bb49c