From patchwork Thu Mar 27 09:28:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 14030878 Received: from HK2PR02CU002.outbound.protection.outlook.com (mail-eastasiaazon11010026.outbound.protection.outlook.com [52.101.128.26]) (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 716FF1FF7D7; Thu, 27 Mar 2025 09:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.128.26 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743067796; cv=fail; b=sVq+uUgKs8c/46eDG8MHgcKJUEDscfVwZc70tuWDHCDnJpcpTU3SIgmu7UHk+g078llUJ4JWBr6y0RPuY4phfR1SjOAuhT9BIlaiN4YaEIV6dtOQ58pJ/axh+0jyiOxRR2ZjzO3gffX5c3dB7BRSutgbl/JgKKWk7WFRte+NTAg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743067796; c=relaxed/simple; bh=/zv7My3QF1NIbDyOZpJg9b6ER0zrr4Z/J3k39yFjF9k=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=RLJQJIYLeisaF2bh7ElkgsxbzFHoEiY/QDpE7N2yzPNSk3Z2y+YeDL8rmEmwyCQLwRR78wd4e008WL9/n4xx+xmkNdFYixm7zEA2MVNs/utWmb/1WcWCtKSwHZHWMLUcN/J+vg26fdfix8PCF0U3zWo/9jx0k6AfWmIxv0H8T9c= 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=QZlkeeBg; arc=fail smtp.client-ip=52.101.128.26 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="QZlkeeBg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RgsVESWBfRXkbxeGA/SwXe6z746j29H+R2zCByNETvYXaiiU5OkcXr1OqkyLX8GE7bODK9fJSE33Ve3IIBT2QPaGG5q9wP75RQAmHh9JV38lyPkJGXrN6ZcWBq+Y0OQCV2Qk2q41/ddsaoW928xzJNajfXTB4Fro0aNUMkcXUxR26wuqKFDq5mXPsR8RrdDZ6wrBRl0/tXL/Zn+H+olQeH41HBHHbJt8oLCNmHWrFeW1QyANSga2fCTg7jOkEeLzbasqZ0my8o2ItDHErtkfXkdzc+LS/nMwaOyrbvldh7tXb0UEyWxbeSBQJGlPPf5ZICRqAaATsbGf0Y0QOMeZtw== 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=H6MuiRg/LpZjYdujLAws+nhzac92C0nGR5kw/Fv5FWM=; b=YdJe7yxjVZCAeXcXjfQKn2HHEnbslTm99h/AiX4Qt33lBpnWSpV8080VB1PjRt3GBLWGdr2GWVsCsBY5r0LiCOYp62SYumBnju7eQmjyc2UX0nR5Jah5NM7LRFWzH0cdjPrB74o9cHgUtWP98g5a7Ob9cJg+cIAiJYZsMvWavNGTwJFCLiCtGgR8FGNUsnb0OKiuTtyZiM3k6hSVxCOmc9TjsT3g7p3eJOhpKRufGJaGUzoxFF1igF/DUwwisqhRbr24IPjinf+aa5wfTbKvor6vBaqCPpD/V3q5yJKfLudNdRBk5X/gIV7OAITpSkhqoSzdB45vflQGOTE5fgsRLQ== 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=H6MuiRg/LpZjYdujLAws+nhzac92C0nGR5kw/Fv5FWM=; b=QZlkeeBgVnIJkw33o4q6WMN+LKoqPGlh6b+xUfBxExVSQfJWd/dalqVbN0Ck91OqocE00DESDPd/BBLeIKtjEZR4THzSPYbUN2Fm2GXy/U8j8lFoIrZdHQyVGSpDMMXDLklIhG2+E8aP1sFX27K54HBoH4P3i7BYMPjccBW9q32BhRiY8yE66igrty1W+Pd+G0XIXt4zYvV21974TM3q4ow1P3tkHht4zqdIg7K+/IFGx2WLjOQRXBT4yqcuSbq8Yaw9wbIRFYRHyNVF+ZKOZ2wIvuHF1s8lNjUkOLbP9+aATBFfXFOFZUfAsYHbPvPGPvul1DNsObRZ61N8biM86w== 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 SEZPR06MB7238.apcprd06.prod.outlook.com (2603:1096:101:226::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.44; Thu, 27 Mar 2025 09:29:50 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%3]) with mapi id 15.20.8534.043; Thu, 27 Mar 2025 09:29:50 +0000 From: Huan Yang To: bingbu.cao@linux.intel.com, Matthew Wilcox , Christoph Hellwig , Gerd Hoffmann , Vivek Kasireddy , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Andrew Morton , Uladzislau Rezki , Shuah Khan , Huan Yang , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: opensource.kernel@vivo.com Subject: [RFC PATCH 0/6] Deep talk about folio vmap Date: Thu, 27 Mar 2025 17:28:27 +0800 Message-ID: <20250327092922.536-1-link@vivo.com> X-Mailer: git-send-email 2.48.1 X-ClientProxiedBy: TY2PR02CA0041.apcprd02.prod.outlook.com (2603:1096:404:a6::29) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SEZPR06MB7238:EE_ X-MS-Office365-Filtering-Correlation-Id: c1d140a8-b466-4e06-7eb2-08dd6d11ec25 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: eNbK5ZNN2dAMyEA1d28vi/ZRPq8HSXrPD/DheZaKJ2nBQzzP4Eic/KnIJTkzhErX/NfitOZDN2smTgkj4ktNqerG7muZQb2gKDlq9INUGjitfwRYt7QR3uK1OnTaZDOzc2SG1v+ybmNFgMVQKeufVR7WlG6Botp9f1IKFfvh0j2izbS7VCWD7mSVU0Txcv5ptbUjSr6EIltHhpswNjX2OleWy2rw+SUZY4VWTuKQARXT0TB3g/dzK7kBhRu/70DcP3wj+D+eBPw/QkUKa1omcjVdCD49UaFN+C8JXUKNLNm1HHyN/Y0VZhPqw9NeOWkRy1uIWcxqAGBoyh9OBHC1Vz8WviSsOOgcumUgvXSlgNp/BS9aOs3S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Fd6Sjo0ai29qWOibgYfa/VGNIwyPw== 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)(1800799024)(366016)(376014)(7416014)(52116014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: h6hkgquEq+umvDUDVGAFhibr5fXH9PbDmOdtCx5eelNxgzd8CFduC1HT89TfCj9UEH9f9hp91d3KFjz4UX7QxBeFZXVHMWizZ+P8M91U+V/kjOehZ/Fo76H0XcKYKTzFojBzxDplWaoZ5TJJbgygpeZ6MrLpubtFBL0aY3Cjt8hNlVstrJAHnwS/IthN2j0TgJViNf9TufLqF5a4R0d1MJdBvQbxAqZmflMrCo618EBC5YLhCP2DDTHE8chzoBeSdZglc5PHq4ixSO3Od6Q0O8ZifLtA8rjhQS/zUA80Au09tC6Zis/9INu3Mq9Qx0bXALVjUK2zZ9692CtCKsDzc2v2zs2QvdVXmr1/wN1yPMJBMv2aRHweIfCrqugTNg4PyFUJzso6txUJYY60Kra8STjePBNKV873fF2uqm1o+AFhJEWNqRxijAl7AbS+Zs0b5TETiwkoGVDgMjYHt2Ce5PpuZ/JBoG2SRnI/OGPUqgjTfmp5nmp0e+Is/TJzHaKw3ayKCcTFGBfU5c0owt6N68wJiTosnNTRbSzhS/CypHxpOZNbMkPYGqC7NKd1GUYijcPF9LnDkYKPH+/01WJx4yNxA0EAMRB4MpM8jIAtTyAyEmFgyotU8elFDOkykvSO6x/2AnHjqsoa91n8OdQ90jAR0VkXAzu+LW/sTIpTDDyk9iWJQ5szYVocTwspIP5WFzP/cyNwjLCeceamIyZxbxHF1kYgLzQietl4ZYRCyON+LtwIOmUvNq/lIxeC+/qvSeWyJwzMik3QQiDWCarUysZvcUcQFWzs87LD+gWNaw134veCLJ7f4JNb/6M+NzrBanmVYeq0Fnuch+NnRtTbHaV+Xn6noNyj9M+IcvK3J/kUIBU1AYwG7Ga6GeTAfWzIMWSbMrGB5O8bEHllMl0dyKSeHYpmg+cV/zyE6eFk82HtlYrqHtZtURM4j06biF7IYJhsSl53woAePs+rE9iexhzgNmmUeRTmnO/hhnG8W4J3E6FsxGE8I/5HrtZ9ynG/c7Tr8GZi5reg4lOuwVsz2ZY7G25JHlwYf6V6hSqrvrQG0p6zXAkTxN0ZeMQWL2KiKVAZVpMFmtZ5gV7AlmQz4+Ix/76Pnlqoa90CeMkeBKET4JU++nbEy+nDZfQUnFDrVltpphkSgwH11mkJpwPUpfNaOx1RnKkPYCObc+UcL+Wo6S8FhS11QsEhLx7BRDMnzcW/FDswzw+MK5pK+Cdwog9CPCTIKrl2f5OPs18I5LMlaoJGh58TgAmD2n7fXhhp4kjbxPY5zMILExHb3vAwLd0tnKps0wChZNWjrP69i14dygc7zAb1lwGAQOpziQKRG9HOFJcxqXek14KH6QXpsCtfSo6mFuM9+BademCP+mbyDD+rGUeg3D/dRvF1DXlRCp1SxvGZctRKUGmglz21KLcw9jEclqz79dQ/fr18D1R0N1vRJ8um+HpcUioapdYgWPpc1G3fY3e7LMmj2iK1PsZxIoargPnBc3i1hDGnP5ep1iwQ1LnLS9dQgMge5fwA9TEyLyMjL3X6yTAxKCCvQbXr1+6ZVCl0KDPcxSbzc3evd66H2GYEIa5CN11HeQeC X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1d140a8-b466-4e06-7eb2-08dd6d11ec25 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2025 09:29:50.2854 (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: FReU9+e4g5Q1ee0jCch+m4QPPRib8T5MsnP+UigGEn35MRjHxaGPJOL3/5k5guTUK1zdqi9yM6Ojv55tOR1dKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB7238 Bingbu reported an issue in [1] that udmabuf vmap failed and in [2], we discussed the scenario of folio vmap due to the misuse of vmap_pfn in udmabuf. We reached the conclusion that vmap_pfn prohibits the use of page-based PFNs: Christoph Hellwig : 'No, vmap_pfn is entirely for memory not backed by pages or folios, i.e. PCIe BARs and similar memory. This must not be mixed with proper folio backed memory.' But udmabuf still need consider HVO based folio's vmap, and need fix vmap issue. This RFC code want to show the two point that I mentioned in [2], and more deep talk it: Point1. simple copy vmap_pfn code, don't bother common vmap_pfn, use by itself and remove pfn_valid check. Point2. implement folio array based vmap(vmap_folios), which can given a range of each folio(offset, nr_pages), so can suit HVO folio's vmap. Patch 1-2 implement point1, and add a test simple set in udmabuf driver. Patch 3-5 implement point2, also can test it. Kasireddy also show that 'another option is to just limit udmabuf's vmap() to only shmem folios'(This I guess folio_test_hugetlb_vmemmap_optimized can help.) But I prefer point2 to solution this issue, and IMO, folio based vmap still need. Compare to page based vmap(or pfn based), we need split each large folio into single page struct, this need more large array struct and more longer iter. If each tail page struct not exist(like HVO), can only use pfn vmap, but there are no common api to do this. In [2], we talked that udmabuf can use hugetlb as the memory provider, and can give a range use. So if HVO used in hugetlb, each folio's tail page may freed, so we can't use page based vmap, only can use pfn based, which show in point1. Further more, Folio based vmap only need record each folio(and offset, nr_pages if range need). For 20MB vmap, page based need 5120 pages(40KB), 2MB folios only need 10 folio(80Byte). Matthew show that Vishal also offered a folio based vmap - vmap_file[3]. This RFC patch want a range based folio, not only a full folio's map(like file's folio), to resolve some problem like HVO's range folio vmap. Please give me more suggestion. Test case: //enable/disable HVO 1. echo [1|0] > /proc/sys/vm/hugetlb_optimize_vmemmap //prepare HUGETLB 2. echo 10 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages 3. ./udmabuf_vmap 4. check output, and dmesg if any warn. [1] https://lore.kernel.org/all/9172a601-c360-0d5b-ba1b-33deba430455@linux.intel.com/ [2] https://lore.kernel.org/lkml/20250312061513.1126496-1-link@vivo.com/ [3] https://lore.kernel.org/linux-mm/20250131001806.92349-1-vishal.moola@gmail.com/ Huan Yang (6): udmabuf: try fix udmabuf vmap udmabuf: try udmabuf vmap test mm/vmalloc: try add vmap folios range udmabuf: use vmap_range_folios udmabuf: vmap test suit for pages and pfns compare udmabuf: remove no need code drivers/dma-buf/udmabuf.c | 29 +++++++++----------- include/linux/vmalloc.h | 57 +++++++++++++++++++++++++++++++++++++++ mm/vmalloc.c | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 16 deletions(-) --- 2.48.1