From patchwork Tue Sep 3 08:38:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13788297 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2066.outbound.protection.outlook.com [40.107.117.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 196DE1B985A; Tue, 3 Sep 2024 08:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.117.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725352902; cv=fail; b=WuYHPnyupih5XNL/twTnMzCSxP2ByrFZYBwYgA8TW4S3zkPGy370BuBVz7xHkK6UznF0py6o+QvDhaKPnHVF+L45AZEdbclsND4CLIJqZRa3ABgV07Do3IsLDJEddR0pc0+cjcNuycFRY3n11snH93CH+XQVLstGKyGsrrToCRg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725352902; c=relaxed/simple; bh=JHqpb7xfk8Sa8+DAo03tHzA3Pn6eevyi6iV+5Ktegi4=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=bWGH53iFXSBjJGDmZk1Xq2rqdy6J5VyOzyspTyVm9ulnnQD0sIGx9sI2b/T7HHYYIwgEz1mrnnzHI03YskYsUun0kJs4dlt4GwXEQnUM2EjiF6Y0Nzwb3Nth6Mke+NDIVQr1+3qUJoUn+iOww3elE22DmchagCyuDtBCAYGn4tg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=KdFE4NjS; arc=fail smtp.client-ip=40.107.117.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="KdFE4NjS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zFP23RRFgqXRUNbZjlf+dZBKMBphbVzuLq98E/rWboDxPsAQubILB91u1uIBElUG779Jvm5CRKuLxP+/q6JieLiSUZrujGKz+UupqdMVJi/PyTysmBxrkYyuHkmQsntqptyd5ZNheT6AS9gcY9+4kQo1cLwxqoSRXIMGMS65KysuXsNJXPfoJk3zYA4Ynu1e8kfc9s9I4bI6O4nleTU3rTwn3pwTiu32A/3trlkAjM7fHQdmpfu49dvGoH6LhUdkQJXHQEUwV6CQ1StoleJYq6JjJGFJ7GY8FT4kwOry9aw/BQwM4anywMPkrSdvCK29WUG3kABNetLdytkM4aRhuw== 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=Z8ywkoNL33RDIyoTlNZYtSPcsmbjf2buTyOB9sZCS+I=; b=sTskR04Rc4XSzk4Q5n0RglLa+dfyzWhkFU76aIEPPaMs+yd0drryc3Nz9TeOLOJbgNNtawYGuCREWxLWjtsCrdQKWhlkg+61zOGe62EzNdVIbX9xwF4TZtnwg0LB5mRHf+bJBHJwQtsDkeGbxhF0Dkx22h0h0yQ+ewsJSecM7s4eG/UzBamzylxvF9Y0on3++lJXcvurcWw/0FOAS6N7pCEzQA8MNDdyXBRRUPjnPRK/IA+DpXXUZ7oLxa31de9pbfvNLd1aaYr9MsPXgiGL4jsN1ZVtYRpmFiNAq0O45I6MvvO7f2bwsZ+Kx7lsbxjzCIbQXzGl+VJsxpXVt02sww== 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=Z8ywkoNL33RDIyoTlNZYtSPcsmbjf2buTyOB9sZCS+I=; b=KdFE4NjSoxJBGq4E/JL9e7VTuql+X+AJNtmoK0mBlnAiIMzVUnsqcTbs/YHZTFyBV43aBq/il+conGza5kWIYrXFyMq1SBLlblAYv8Df3dxpKjPtw9O2DZcRSg08Y6ZmvFCf4IrEb6zzdOnFVWewwcbrLfFNC+V6M9avCXEAqJ+2He+xPSc3opZHtcURomGdP/lYkdyP04GbtX3b5BJo9DuWEfj8CMh8v/KyLql+POGm6bKT9cAZQTg/8haaCOAV7WibkjHwc9Z56Arjq5Bb+ggJ5djELTj1vXbGcZH+GuCjZD+X6J0lcqRvwzIL1TFGqo/wovYEXBIILDIXBUyM7g== 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 SG2PR06MB5359.apcprd06.prod.outlook.com (2603:1096:4:1d7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.24; Tue, 3 Sep 2024 08:41:37 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%6]) with mapi id 15.20.7918.024; Tue, 3 Sep 2024 08:41:36 +0000 From: Huan Yang To: vivek.kasireddy@intel.com, Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Gerd Hoffmann , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH v5 0/7] udmbuf bug fix and some improvements Date: Tue, 3 Sep 2024 16:38:05 +0800 Message-ID: <20240903083818.3071759-1-link@vivo.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: SI1PR02CA0026.apcprd02.prod.outlook.com (2603:1096:4:1f4::11) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SG2PR06MB5359:EE_ X-MS-Office365-Filtering-Correlation-Id: 76f0976e-c6c0-4d7b-b638-08dccbf438dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?epz7QMjirbMMQyhCgChG/St6oEmFAvp?= =?utf-8?q?EO4jIYP7jbpbuHTv6HnwLG5wN3d10zyB/31kJXzwWDZN3M1nETKjflCmj/jKjInQI?= =?utf-8?q?FxM8GSo41B+U1r1JglPvgJ1vYGVIh30HRsb14W+0JmaRfnVE4Unxd9tPIaCInMNbz?= =?utf-8?q?0dqCZ9P7RsfF3A+AzQbv3EjWyIA41CDetspyC2HaYb294T9Q4CzShaRs16Qxbh6Q6?= =?utf-8?q?6ktp8AAhRGELQ93ecOt8Q3t/1BdhzO8FUMHErJsX4kOBs0jFRoXLbJZf/2PkO2K1T?= =?utf-8?q?Ed6gEFJuxZfsIJBjYCpvZI+7l5KW2rVHQJhRnH5BzklwwxJ7zC+Nm62Jc0nvEciFU?= =?utf-8?q?nffPdEzUTzgcDYLix6AkT4/s0neBbSpjmsiQTD1VnwfK42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cICrLI3hJiJ2S5Yr0zNSo?= =?utf-8?q?rVLaLzcV4KEkT2vV18QdaGMaBMnEcOzbNV80PXxPW0XjQ/uh6Abki2tOq6lzLBoeI?= =?utf-8?q?jrvBSN2jvSOZLkkkJXbQmnplKcEIc0idmA=3D=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)(52116014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+kdwkhumwA73rKHih6W7A5P8eOhf?= =?utf-8?q?SlMY1mQCdTuYT/CpkqnQNw0utQLqNGdUvDMU4iWgpBTTkIUHyY4SbQwb65qsFs5Pd?= =?utf-8?q?p0n6NnjeXfrvx0tF4g7FmBXe1YvuZk+7W87RVoDb+eJ1u7lZJ9jTIB5itUuhJt2u9?= =?utf-8?q?0wJldLBFwdNSyFmenGbIqGEs/yvhQVhXQJX/On/QWBwiOH77huKVW5tC7MngAp5jo?= =?utf-8?q?2cG5nYOzGkvBmRPBXvZJGOtUAZ7j2rnCHD6yNb0/TZKFFeEstaPBqw89NdFKiBPiL?= =?utf-8?q?tDupJu3hgqgwImDsijzwgTybqgb4hHlcGXFRNy99laopXiWfVo+gy4yYUtStgpYjN?= =?utf-8?q?sasA6NrmNg74yH4xyVUHcRiLEFaxBbLEVxOfathV3aMILONVnwecwIR88AWnFb8pN?= =?utf-8?q?Rs6Z91O0nQeuJVGaEkULT4gtmTINzwKFAge3QSow+DuOE9tVs/o7ktqH11Kf3Zc6n?= =?utf-8?q?/U9RqJGh8PxzhnVnnQ0g5VOX3anTnPZasak477A55rgTzfOaFhvu1XETf40cQ+V9x?= =?utf-8?q?Nt4bDUqCTUaN9Hv8BRa8LPSrOcQW3qk3mF3Mg7Z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dBQNqniwvb8rS5TGjWcPU8?= =?utf-8?q?VttkVu6Ra1wjxnawjCDUwRZRzk1+ZP1bO6ejqeiOy/UcXqtSvCk5M/kbfl8td0dql?= =?utf-8?q?kb052yq+y2bI?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 76f0976e-c6c0-4d7b-b638-08dccbf438dc X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2024 08:41:36.8413 (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: UZZmqzZ+8lNZ/SdcpFQ/GiXzZF3+1IjuFdEPWqi525pB6KDDqeiQACLJpZh194FoeBXHyiChxomir2qbNgZZ/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359 This patchset attempts to fix some errors in udmabuf and remove the upin_list structure. By this patchset, udmabuf remove page struct relay, only use pfn and folios. Some of this fix just gather the patches which I upload before. Any patch 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 Changelog === v4 -> v5: Patch1 doc why pre-fault failed not report error. Patch2 no change Patch3 update ack tag marked in v4 Patch4 split some change into patch5 and patch7, this only contains udmabuf pin folio's function Patch5 add helper init/deini to clean udmabuf struct initialized Patch6 remove unnecessary code Patch7 remove reuse folio remove v4 patch4 v3 -> v4: Patch1 fill vma area with pfn only when true access. Patch2 no change Patch3 select VMAP_PFN Patch4 use function pin each item. Patch5 use pinned folio array instead udmabuf_folio struct. v2 -> v3: 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 --- v1 -> v2: 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 v4 https://lore.kernel.org/all/20240822084342.1574914-1-link@vivo.com/ v3 https://lore.kernel.org/all/20240813090518.3252469-1-link@vivo.com/ 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 (7): udmabuf: pre-fault when first page fault udmabuf: change folios array from kmalloc to kvmalloc udmabuf: fix vmap_udmabuf error page set udmabuf: udmabuf_create pin folio codestyle cleanup udmabuf: introduce udmabuf init and deinit helper udmabuf: remove udmabuf_folio udmabuf: reuse folio array when pin folios drivers/dma-buf/Kconfig | 1 + drivers/dma-buf/udmabuf.c | 272 +++++++++++++++++++++++--------------- 2 files changed, 166 insertions(+), 107 deletions(-) base-commit: c79c85875f1af04040fe4492ed94ce37ad729c4d