Message ID | 20240813090518.3252469-4-link@vivo.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers |
Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <linux-media+bounces-16177-patchwork=linuxtv.org@vger.kernel.org>) id 1sdnTc-0005Gn-14 for patchwork@linuxtv.org; Tue, 13 Aug 2024 09:06:01 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 888A028280C for <patchwork@linuxtv.org>; Tue, 13 Aug 2024 09:05:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04A7917C228; Tue, 13 Aug 2024 09:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="fU6YpAqS" X-Original-To: linux-media@vger.kernel.org Received: from HK2PR02CU002.outbound.protection.outlook.com (mail-eastasiaazon11010062.outbound.protection.outlook.com [52.101.128.62]) (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 C175E16DEA9; Tue, 13 Aug 2024 09:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.128.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723539946; cv=fail; b=udJVxo/3Bp5wkCHZUPKw0AWJ37MliH81nx4rnzkL2MlFkCJZz9TIGSwZJEdVm8ApLE8VGnli1CSntst9mYFRcpj5AUS6kSmkD0iL4mwwOrYbdl/2pYD5YGC4+SICRDEgMueHVuQG+bHGvTBGhomWtQ/3aLr+xmVl+QWhIj+u5hE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723539946; c=relaxed/simple; bh=kpIqsZiiuu6FcDIhS1GCMxS6rYYVLwrbCLyVYyGZM0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=b5Veh8WYPJTcWqDgNY1g6eDLfCVJYYtCM/BMtiRnixaJIlo/OOkkOoaLWObGo43kFIdVuabyvjAokBceZfhpY8KLBxmEgp5fdYi99GO5Ex/66YLly8XlFngomQhj79jVagZkbMbJ85r6N6iN6mfFpVU0wDNAtj5s/W6whEgOCeU= 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=fU6YpAqS; arc=fail smtp.client-ip=52.101.128.62 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Mn7gCkZO15xn1rtXLqTNY4CryzG0Ic7RwYoGo+h9jHF04am/vKNcnPvvEUkhNpqP8l+xpv4DY12yCSyADSorCUWOpDxarfXuHb8ucrWqPM0ls4Svpwfy2fuGDovOZs4kwrqtlvUZ6ZqQUQKPSWC0csSkufS/nI8t2RkZJqrLiC9FRhSqiPk+jgGrTYj3r7wvImGHs4tfoZTDjkaP+nNXKu97NTGvVBkusLaYJZsq3L1v3L3aHxd6Wf2fUWpQjlLqah0amCkXOptWy+Wf2DSiTrjdpXB8KlpSGtKI7wZ1VXXnWO16TJhRJk1itsCPV2COXRUPz2syK/KUaB1zxzai0Q== 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=iM+4srm+h3ujw3a+DyJXfMCGQHcV9mbwLUC4bdV0DqQ=; b=c5h5gZqv1kAwLnVAZ4P7Ptj/vGQNTqu0Xn3aI6dBVvRagUtIMRVYjVZyAFv/WJUAXTkXTNSKBOlB7ZCasOPrz+VNnZ6qMf/3p0ocaiMy5eHX94qliy0Y6HFGf3zazztnEVc59S8a3vKIuQJXRSsGEYK9m3GStFzM7JW4TqkqYjkaIQWQe7elgbP/Va8VxvDXvZN7FnD9Fy3ZC6mp68YQYszEttA/Dz4VUhUz2B9CM7fA+5k4h28fVQNkhc/eVpBuwvBB/DaRNqhaSsav4AYQ1pY1EtV1F6QazbJr/4fgCkXxC9NGY1Qvo+Xwy5sVxjVq85xus05aSla2qgn5IlhSwA== 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=iM+4srm+h3ujw3a+DyJXfMCGQHcV9mbwLUC4bdV0DqQ=; b=fU6YpAqSKJdufyYUY5cvkETVU2yJnPDu5JSZKFUud+Bpmyj/6d5TIlbUayr0xq2nPoDDBaR+1AmngZiCHQdYaqprkEDggYHfSC+spYmP+l3/G4z8hUrD30KlSN2OIsZ+GmeBoxXQVqVdMJQ5/rjMQ+26Qin5R/mhD/gRJC3SAqg9zqK7lOmjoSYuV1d3tZoJURzG2ReX8VRPnADulJKybPO0SjnE2i5lY9NONzx/6UFkuLyZqAXnVmB7VnUx6mJDTxIzgJOSXeXS43vbSdy89tQmJyAetiKZO3TVCmngzc7zqrXbMzcTV/URt5MpmWP3w3JK9ME8mXqbiahMtQMvgA== 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:42 +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:42 +0000 From: Huan Yang <link@vivo.com> To: Gerd Hoffmann <kraxel@redhat.com>, Sumit Semwal <sumit.semwal@linaro.org>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, 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 <link@vivo.com>, Vivek Kasireddy <vivek.kasireddy@intel.com> Subject: [PATCH v3 3/5] fix vmap_udmabuf error page set Date: Tue, 13 Aug 2024 17:05:09 +0800 Message-ID: <20240813090518.3252469-4-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240813090518.3252469-1-link@vivo.com> References: <20240813090518.3252469-1-link@vivo.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com (2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: <linux-media.vger.kernel.org> List-Subscribe: <mailto:linux-media+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-media+unsubscribe@vger.kernel.org> MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SEYPR06MB5400:EE_ X-MS-Office365-Filtering-Correlation-Id: bc1298f1-368d-4a7a-bd57-08dcbb771ba1 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: g+xTO4CjnAlUZoHx8tVicgE3X1i04Ma+8PQsLPEGYXu8pbdo755CE0Po7evz8tR+AZ5LxS6PzsQevUmDeLFBuqopJLGAzZAxEkcYcGxYge5DG4wTrojc0oguab7GQ+KMPH8AF6iPtG7T/vqAw71mUyzEuPBzakZEc/Iz6f0+iKc3GcNJF+bFxXYAyO7bP5eB3BSbL1B08BXRT2d3dBQxIHnBAYPfYdFVd2sM6LfYSQhNO3ePdyIgZQ2t3Eu74jpV6p4BpgIe/UwTL9rZ2Bmns/RkIFvbXemzKA0Qo3n/K73ED/9SL2NFFjgbtloKvQYnLLGznJY6NYOMFxA9JWnTjqJ+Y2usefO5Q0TcBbj+P5XOD90eAzkkOCthl3jcAYM25XLtOrXF1A4ySW7tFkKadNVGq5PNLS2Uhs1PQmARwujATaGg24jzYEu1eavP34TRfF/QpyX01mHrkzLfPD4kncGrLNIB+hz3RqW7fPQ5FRPBQtlpr1osx6+ur5KPX3Hy4OmFI/Y4/glqdtrFdL/PKKdCnHjtYM+EzUQSUuXAzdAlsFT4GDH94N9Sp06Ie1iEj0SXmQTnSG7xDdIdA0dMmUfw8t+bSERGjFCUd/BCMAcrYbUpcv+HcRo0v2KYt9NTaBxmGJmOMtBbMoJWOdNMCG6Jld+xMHwQOt2q2jlbYaGxRE6XGYELls1sV2m0Uq1cEEJ8SLlq8WS+VIRCIasuOurz3RI7z7Bqy6JUrTtpYF6AI6uBPZMn1mqOXP84zNYgmH3BA6P/6QnBFqUgG7rIgxK5ZdTKtTG+Z8Gb89ol/KzffSmO/18FcNPaXgfH8dWa+VZIW28UbtGlK+64VvYeKWO5KXnTykRZWER1F7RzBvp99W7ToWl5I1PoPr59YLyeKbPQtQv/BOhEcR8dlM4FpmhxzE46d4hS3lqcNve9Wu86sP33GdQE+uwSTqxmW3eINJ+RfkBiMsqx5ZMLHupN1mzJPOtOWbxMRmUXbkyEcQCCHl2oaHJtTWK/AVTevk7THP69+SZieLkuXtorDRBWET1PNqJo7u5uZAI/OgFgVLHDXZPooExSUUAZpuGggfd53mC9oFtVtGr1FlJqgGXoBD89oEHwMsIzqm2YF1I9Vyo6DM0m3v+mur3Cy/xhHCOTD59UGiM5wlhlHW3bYToNjQz+O6mcJPrysrggYapSX8AXGScrfsUU0E1YBCEv1Qiwot5XWKu/Z2TJN/xXAdVqRh/NH4AQmVdol66i6EoQzM5CT+v9G0t6zFjfbZJkmHfk7Ae8KBrI+2n4j9dBInHgXsBOo/So0RmxUFMwhyD22/p8KI5UzI+drPjMQk6aVg3YONMJOe6MvQHLWeH9RtsDrA5SRWgjFgM4KlST9jvkxaXJEpQROEKynuVnQYidjNesxD+Nz7sWniQrZ3IrLNnKCg== 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: NVHPk5hYDPK416Atl+K+uFHg09jZ5T1VNAObY3tFVB+H0p000lQjPUMSNanx+cBnzAMvGo6RKQXape9RYblwRtL2QyP9f8Szbb680YWkhU3G71BSLhYFflsn+X1AwNmSg4q4213CgX4tiJ28q7C6QcyP/de5uOxbMqI34TOX6qI8C9duMhLmOC+OrnyCkhfhjMZZCFl+EKYZJcdwjihHU1xwaA+WI3Z78645l0C4LhgMbeRvsMUgrrMb0qhYklrZPg/aA3G0Y2QC4BQDHY9FeMn9+ij58m/TmOEfMYhNP8N/Ie4Gz13bXmlxhzBGO9HknkVDI36Dp0iPeI+ZqtZTXggZUAwWSr/zFgMWlbbG7u6RU9gb+Jl3ToPjXuMYhXGlb1WAWRQMjyU7ofkWTRlYadKh9fs6XtI6o/vHAuDCdOgeVHVmhDwB2w5b45I7OI348vCjRTVFoeHVzmOryMZlFgLdzwp260aNTKm9gb/htAtjOnvLZXs3rqG9DhXnzOJfUT7LLU3uw/vYvb7Zt4VTRX6mC0D1m+ERZycTG7NVHJzPi9oPK/y1dyRXqRWtZ2m/kBM2Od3Qbhj4Ob8DYtKoPkPmSbhHIT0IXz2VpxvqXwC6C0eW8Neww2RuysWZl/lMqiEMFDFPipNfGC1+HRdXIy64b993IcIOfG7tPesp/lA0XK8PfsR5gR2G6ySqpG6CRPySiLHkhgzvVJWfPF/quoUCTizj7zz2ixLCKVWgMQhb+Sd2wIh/c1TRkNc3oAOGcmLKN9mJfdSv64UXndOqgkK4w0Trn7fxRniE+mQR9WcT1D8jk/Un6Rp1u4WDzGlh5RuD3PVJPW9hIL+ZG2rLFP1f+3rntWoO01a+Z4zEu1YO5PX/5z36Nz5wquvMb9u+AHP8o8f/aD38Q+Rg1+3yYGvF1fmMRn8POCQOTsaeZNkXwxcloSjx2mFCrUrxAWWElMb62ZaCqYdXjOD+cGxJC9xKrDGZamyELsBGOB340EQ4YPaTxkhRFWhkGIrYT4Nj7K++hcBoHPzrTHYHOi233OEzRwDr4Z6T9rd7lje7J3C5tAC5Hyi+tJFA2tJluQz/nYs65bnoZ1Lg3QwO6XZRQj/2T1cpx8oDTGGWgWrFs8/zbW9wDLN0S/YFNustXiMBppZqilDAdUngvSbW6lrtJw5Xm0lX6b6Iiew9qnDzZ1BjfjEfk5RyGLTpO9WKRM/TUv7wJDL/qv3NP0EgdrSjcBwtom0xly80hJuC4LjUqVYPtF3VOxTgAq+lcqVWuGTgAWcepmmaao3ag9XZNotT/lo071iToQqps7GWxjhsd8i6aiOv8HdXrrV/zUfYjICOF+aISP73OKzzbWFXPxlDvYSQpGne6URRGEBcV+zJr0pA6nv88Oi+YmmvKAOpOGDhThz5HanGXMHjWCKm9AsylPNmiSL2YU71wS6o8PndEk9xfBpHaLv/6V9uNqp2YfIlp7wGiHPr2G/TtCQsxNPQDaePYCf6KpAmDKnf6+ZFeQDy/vI9q7a1tgctevuNCiwGwpkzqxrJYXJxObF5KsMVMOyHqXWMKTrBNSjZZSSH4bMtEWhKkTNnNIf6+H+Y2aAu X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc1298f1-368d-4a7a-bd57-08dcbb771ba1 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:42.0345 (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: qb0mMbd/6NkvCXSaAopZkOsEW7ygD940Wk+u7/nudITHMT+3ZRdxOiXGIg9iDPtzHpQnd+7BpCWt5+JVnGYW2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5400 X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no |
Series | udmbuf bug fix and some improvements | |
Commit Message
Huan Yang
Aug. 13, 2024, 9:05 a.m. UTC
Currently vmap_udmabuf set page's array by each folio.
But, ubuf->folios is only contain's the folio's head page.
That mean we repeatedly mapped the folio head page to the vmalloc area.
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.
Signed-off-by: Huan Yang <link@vivo.com>
Suggested-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
drivers/dma-buf/udmabuf.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
Comments
Hi Huan, > Subject: [PATCH v3 3/5] fix vmap_udmabuf error page set Please prepend a "udmabuf:" to the subject line and improve the wording. > > Currently vmap_udmabuf set page's array by each folio. > But, ubuf->folios is only contain's the folio's head page. > > That mean we repeatedly mapped the folio head page to the vmalloc area. > > 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. > > Signed-off-by: Huan Yang <link@vivo.com> > Suggested-by: Vivek Kasireddy <vivek.kasireddy@intel.com> > --- > drivers/dma-buf/udmabuf.c | 22 +++++++++++++++------- > 1 file changed, 15 insertions(+), 7 deletions(-) > > diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c > index 3ec72d47bb1c..4ec54c60d76c 100644 > --- a/drivers/dma-buf/udmabuf.c > +++ b/drivers/dma-buf/udmabuf.c > @@ -67,21 +67,29 @@ static int mmap_udmabuf(struct dma_buf *buf, > struct vm_area_struct *vma) > static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) > { > struct udmabuf *ubuf = buf->priv; > - struct page **pages; > + unsigned long *pfns; I wish there was a way to easily test the vmap scenario but its great that you are able to eliminate the usage of "struct page" completely from udmabuf driver, with this patch. > void *vaddr; > pgoff_t pg; > > dma_resv_assert_held(buf->resv); > > - pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), > GFP_KERNEL); > - if (!pages) > + /** > + * HVO may free tail pages, so just use pfn to map each folio > + * into vmalloc area. > + */ > + pfns = kvmalloc_array(ubuf->pagecount, sizeof(*pfns), GFP_KERNEL); > + if (!pfns) > return -ENOMEM; > > - for (pg = 0; pg < ubuf->pagecount; pg++) > - pages[pg] = &ubuf->folios[pg]->page; > + for (pg = 0; pg < ubuf->pagecount; pg++) { > + unsigned long pfn = folio_pfn(ubuf->folios[pg]); > > - vaddr = vm_map_ram(pages, ubuf->pagecount, -1); > - kvfree(pages); > + pfn += ubuf->offsets[pg] >> PAGE_SHIFT; > + pfns[pg] = pfn; > + } > + > + vaddr = vmap_pfn(pfns, ubuf->pagecount, PAGE_KERNEL); Looks like this would require a "select VMAP_PFN" in Kconfig. Thanks, Vivek > + kvfree(pfns); > if (!vaddr) > return -EINVAL; > > -- > 2.45.2
在 2024/8/17 8:54, Kasireddy, Vivek 写道: > Hi Huan, > >> Subject: [PATCH v3 3/5] fix vmap_udmabuf error page set > Please prepend a "udmabuf:" to the subject line and improve the wording. OK, sorry for this mistake. > >> Currently vmap_udmabuf set page's array by each folio. >> But, ubuf->folios is only contain's the folio's head page. >> >> That mean we repeatedly mapped the folio head page to the vmalloc area. >> >> 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. >> >> Signed-off-by: Huan Yang <link@vivo.com> >> Suggested-by: Vivek Kasireddy <vivek.kasireddy@intel.com> >> --- >> drivers/dma-buf/udmabuf.c | 22 +++++++++++++++------- >> 1 file changed, 15 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c >> index 3ec72d47bb1c..4ec54c60d76c 100644 >> --- a/drivers/dma-buf/udmabuf.c >> +++ b/drivers/dma-buf/udmabuf.c >> @@ -67,21 +67,29 @@ static int mmap_udmabuf(struct dma_buf *buf, >> struct vm_area_struct *vma) >> static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) >> { >> struct udmabuf *ubuf = buf->priv; >> - struct page **pages; >> + unsigned long *pfns; > I wish there was a way to easily test the vmap scenario but its great that It need a driver set in kernel. maybe write a debug code in udmabuf?(not sure) > you are able to eliminate the usage of "struct page" completely from > udmabuf driver, with this patch. > >> void *vaddr; >> pgoff_t pg; >> >> dma_resv_assert_held(buf->resv); >> >> - pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), >> GFP_KERNEL); >> - if (!pages) >> + /** >> + * HVO may free tail pages, so just use pfn to map each folio >> + * into vmalloc area. >> + */ >> + pfns = kvmalloc_array(ubuf->pagecount, sizeof(*pfns), GFP_KERNEL); >> + if (!pfns) >> return -ENOMEM; >> >> - for (pg = 0; pg < ubuf->pagecount; pg++) >> - pages[pg] = &ubuf->folios[pg]->page; >> + for (pg = 0; pg < ubuf->pagecount; pg++) { >> + unsigned long pfn = folio_pfn(ubuf->folios[pg]); >> >> - vaddr = vm_map_ram(pages, ubuf->pagecount, -1); >> - kvfree(pages); >> + pfn += ubuf->offsets[pg] >> PAGE_SHIFT; >> + pfns[pg] = pfn; >> + } >> + >> + vaddr = vmap_pfn(pfns, ubuf->pagecount, PAGE_KERNEL); > Looks like this would require a "select VMAP_PFN" in Kconfig. Yes, I miss this. Thank you too much. > > Thanks, > Vivek > >> + kvfree(pfns); >> if (!vaddr) >> return -EINVAL; >> >> -- >> 2.45.2
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 3ec72d47bb1c..4ec54c60d76c 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -67,21 +67,29 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) { struct udmabuf *ubuf = buf->priv; - struct page **pages; + unsigned long *pfns; void *vaddr; pgoff_t pg; dma_resv_assert_held(buf->resv); - pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL); - if (!pages) + /** + * HVO may free tail pages, so just use pfn to map each folio + * into vmalloc area. + */ + pfns = kvmalloc_array(ubuf->pagecount, sizeof(*pfns), GFP_KERNEL); + if (!pfns) return -ENOMEM; - for (pg = 0; pg < ubuf->pagecount; pg++) - pages[pg] = &ubuf->folios[pg]->page; + for (pg = 0; pg < ubuf->pagecount; pg++) { + unsigned long pfn = folio_pfn(ubuf->folios[pg]); - vaddr = vm_map_ram(pages, ubuf->pagecount, -1); - kvfree(pages); + pfn += ubuf->offsets[pg] >> PAGE_SHIFT; + pfns[pg] = pfn; + } + + vaddr = vmap_pfn(pfns, ubuf->pagecount, PAGE_KERNEL); + kvfree(pfns); if (!vaddr) return -EINVAL;