From patchwork Tue Aug 13 09:05:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13761592 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 8276DC52D7C for ; Tue, 13 Aug 2024 09:05:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F2A1210E2A6; Tue, 13 Aug 2024 09:05:48 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=vivo.com header.i=@vivo.com header.b="fU6YpAqS"; dkim-atps=neutral Received: from HK2PR02CU002.outbound.protection.outlook.com (mail-eastasiaazon11010003.outbound.protection.outlook.com [52.101.128.3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 15B2610E272 for ; Tue, 13 Aug 2024 09:05:48 +0000 (UTC) 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 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 , Vivek Kasireddy 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> 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: bc1298f1-368d-4a7a-bd57-08dcbb771ba1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: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CHl2oaHJtTWK/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/vHAuDCdOgeVH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KpAmDKnf6+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-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" 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 Suggested-by: Vivek Kasireddy --- 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; 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;