From patchwork Thu Aug 22 08:43:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13773019 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2065.outbound.protection.outlook.com [40.107.255.65]) (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 4E35517C217; Thu, 22 Aug 2024 08:44:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724316292; cv=fail; b=d/iYKrAhr99ztFoG9owYHsaPPy6Y/1YN6ZRvxWXyuN9Lvp7A+XW8AEfgyW/qJS/3Rf2w2XEQooRnj79SYY91v0Ni/uArLSNFI+QEpzhAxeqz3QFlkS5k9GJ11/lFjgUX6eH7sO3XBN4TRy7Ow/aae5/sB9DoaaX9FBEjqyzUw+8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724316292; c=relaxed/simple; bh=3FEvvLx1dutsyAvFnDiBHlJREhhEOwmFEGQtnei+X1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=uSubq7ChEiLhpV1MZGuGW8InkgxeOUcVjUwpVGry16gtJWR0YsCjz9t6YLv+koKGxpayDwiGsWnKntAlQsVCqvTXwdz/P2yV0ykUIIFOnDreSimW/quwNLSP0bT1Ti2jSFv1CIat1+HRb1DMC9MshMfxeZTyY43khD2QapfGIoU= 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=hGv0/goh; arc=fail smtp.client-ip=40.107.255.65 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="hGv0/goh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IDePbvr0GUJakKWB5bUfD7/9ff/Tm0801BAoJsP2uJuNvYbfcv61mcudevBfb9TPkBmnOy/p4i0Ekmeyqn6yR1gfK4MEqYC6d/YsVVkNJIaJK6AXakvGBGrC1EsaqJ/3pB4Nndd5oLlc/GBorfVhAVuenRU2XHR7VSS7kk6O79wDEsFdhEOn7gP2PJiG1NW+7PSF7ZKxcd0Qlc9mI+TQRl8GnWtO1j68pJbeLO5dw9sGSk5Vj6HVdYsaVkbad89x2/JDuuD8Be6KuB2YlHKx6uoYnINTQskPcxFNOREeLgHol9Rhli39o895lFYHnEmJj50TpQcBKcABJwWULHYjPg== 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=Ko/aKqqMO/BFJfW8BMVb0nA4mKprdnKSjuolrgQoDFs=; b=k0o9pPiasQFm76R1vJ1VmrgoBTBjjZoI+mWFb27ER7EiPDnby/2MFXdp5XC5kYxudIq/DMa5T8CGstIAbNTVItleUGvKkuYZ5wOQJQijLcwdpQBjKbI7gqjcR0b+PaCwbRqSzJY1JVviQj627BkOZM9Xjpx+SBjBfTfhrgH5nLDvQ8sjvpg9Z0nOBezQRzPMoJEVJFulO1qmeMV5SiI4Sl1lweoJg/2hHAPzLiXLOicVThSkCgV4B/sD4Yu2b4IAWSQFApgIHE4J62TQKbITc1klkoSlwsnkiNtp6R1rnA/2TNwI8sXW4svfP+yDYuOUqlHYa364XQAqm2Wqx9KR0A== 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=Ko/aKqqMO/BFJfW8BMVb0nA4mKprdnKSjuolrgQoDFs=; b=hGv0/gohsJb70vLIBq0RfXFp8uuH9AYpJhKrtxe0HR/+KTGj8OYFjwO1KsN5V0cpqsagfuDJv/+QXqlWU1AQlgjtdLV2gMmfB1UtvRWXsY9jk4NS89fhDQzkrJSL8gYIC6M2p8daT6pPNcnxTZ80BMw7E3FkmgCGJsrsKl+ZPODhwVhOInRZH80eUIXCVZdB7VaEC6TwIqFVXxWerwxV3dG6Phk1ZlABIoivUPjtqOGAs61PiqR9oiqXe9gvVa//WrN5P6l7Gx1QLDVJWjazx8e8L0/gGjKRA0NjzpXS4wamUooTi1AsQpgSRAyg6AWlBrjQ6/6meXLzq/JKeIf2JA== 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 TYZPR06MB6402.apcprd06.prod.outlook.com (2603:1096:400:425::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.27; Thu, 22 Aug 2024 08:44:46 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%5]) with mapi id 15.20.7875.019; Thu, 22 Aug 2024 08:44:46 +0000 From: Huan Yang To: 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 , Vivek Kasireddy Subject: [PATCH v4 3/5] udmabuf: fix vmap_udmabuf error page set Date: Thu, 22 Aug 2024 16:43:35 +0800 Message-ID: <20240822084342.1574914-4-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240822084342.1574914-1-link@vivo.com> References: <20240822084342.1574914-1-link@vivo.com> X-ClientProxiedBy: SI1PR02CA0059.apcprd02.prod.outlook.com (2603:1096:4:1f5::19) 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_|TYZPR06MB6402:EE_ X-MS-Office365-Filtering-Correlation-Id: 9980c4ea-b4af-4fbb-bb0b-08dcc286ad2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: SbSsRkQLYbnJHIeEg2V2L0j3EUTFtGsUhjyP8o83ykD5O9qhUyo4pw+wFYOde34J4RjG7BCc6A0pWQ1QeQNhkfF8xB3KyB6ZCKmLqtwbYKsYkH1pN6z47kZi8VlAVF0wKj3U/xrzdSOoGnOKwfUnDfzjknnzA3EZNxSNQLGdGMrmJM2Uy6dCxa3+JG50zJeu5Y+qS+qw4o6w2+5KAgzZiLJP8e1pFlSMks9QKyx7r0Eegwq3u4TZEVqvsseeMT3l7KDeYT7McSNfDvL76dO6vKiGb/YfSsaIZxZvTniUkNbMW+e/AmHmH6FTh1EVN5sVBM/aDgH4UrQ9VXY1oOWTGDV+/Jl15YCy3JIP7xywhzouz5Vhf69v1dHMl7QT/MspdrCXV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CL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hF7lIBJJ4LK9ClnsEk8e/vf+Ygrfr5myRc8qGy1whSDZZT9apaRb9OGHhYRP90xcYehX8cg3PVrB11mlb+VtW3l59fEo8t5uGwoPCosapnEURvoWbVwAsItWDoSocpCx2e6ryTRvDW6M7gejGG5X1rGc8kEKsY+O3f3MbmEnJqts5EVmlvZMPhPHRID+LIQ+CfC6KIX8FPBurifhXbptPK2RtDMU8597eCWfP/m5aFCePXZqwZN3NXSf//0cN4BU387q0mqR2+lC5X157anN6fWDY1Dm7mMEcXCl1MbmDEUvRgF4wsC9vd25Qz7yZkUp9N6+sBBdZ69WoQwBY7a9ELJNOqYw+Y0tXJwpSrHO8S3vRBZFKBUYKxrxwR/J0HxfhA9iEmhT0ths0KZcx2GzkuPldhLixip27J2nk5tdbcRei3Ak6GIW2qPBajoEXy1NiRcnahQBaxwRiQUOwfoiwlFf7sB53dGvv7c3sLNsLB61WlhXj8TIscz4M4YNidM0SdxIrauQJbuu6GwON/qEDUXx2RUKp/XcrQ8d4mMYDAPDw7hfAjx1EaIKmBhEbUssFlBr7MtEdhk1l56//VDsOUaoyESLpgLQ7D6yvcp8N94bi8618WH+30NPv8BsX/pUJnnNcBEFkM46NChJJtyPnOkXxZSm/6AXIit8nqeH47R6UWyQMfdCzQqyV+z6S1VhKwzIYgkDFBgSbf+1jPW/bQ/UELKT0iZnxr1KbiapkEyO1xDobIWXAr2MNzjTi89BoQAIwTUxSF9Pq9XWEZmSLG6T9+x/Uz1e9RtC37sdVNe0ofvd4DYTDFaoIOdti3U2dO8d4tZh7j0Ywxt4sclpHpQcrVnJ6OWpQKU0nS2REbaQxxMCnbPTUFwZZma93Vz9MMTB0lA02b+QlUxnLDSHebplshWklKkGKdOQG0dGL6Zxv/tbuaVZdP5Qs5f6kw7Pu46cM15nRVyV9B3+cetG/IKs81EeNdL/1Y/93eXxytd109F38y+RpnoU3OvybRBcW3le7R1W1Tu0/dAMX7/Onozz3nuf+ebPJJZVbhHAS7SEg77DFaIRK5luMrpPq7kzQXAWh7Ad9TA8mqjFwePnG0HBHY7w1yeTGIFGmdH12FIMkhTv2bU2L3e4RUxtxB9H1YuRgLcKUwqvEGjMaf5G/6VdJGvboCCiMkHmTQspUpsHUjWj9UIlocSZ96X9cIPHZMBGcc/AoLHpNFiuPBc5V5RYQxDBAVkG5guc5ePGRv0OyWSS0N+GfgyDG9JqPUdtIjRpcmnKuwBDj3ufeSXTmvapZPHgBTcuMlM2/Wt8sOW8trt7gK7PFxjm8UAmh9AJT4YO/o0jLRw17RyI5IXb8M5hKO/lMkZwxdmzLhOyh0u2I0vn0Jno5xhiQZFWcBiTkWrBYtzt6mOaoIRq6OwQUB3Hi34SsXdDLsckkeS7MjMaAr7vUI2O7VZOFGnRUbFlbwnj5tA9uPB0fnC8Nq4/ITqUikADx2SISO/69b3yHzJGofk4NJRMwIckNkFRhj+fuuIMmexQAv20jEa1aqJ2ff4CfszmIig1z9Wp6M6+4tI84eURNe+vliumuCByiDzy X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9980c4ea-b4af-4fbb-bb0b-08dcc286ad2e X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2024 08:44:46.8043 (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: 4qChdGE0dQrW3WKWv0SByqj3aHIYlXoT/hkR4+7FnlNFcipUeevkh5JB4RZ9/wC7C9HMljNl/bPBRRVgad0T/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB6402 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. By this, we removed page usage in udmabuf totally. Suggested-by: Vivek Kasireddy Signed-off-by: Huan Yang Acked-by: Vivek Kasireddy --- drivers/dma-buf/Kconfig | 1 + drivers/dma-buf/udmabuf.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig index b46eb8a552d7..fee04fdb0822 100644 --- a/drivers/dma-buf/Kconfig +++ b/drivers/dma-buf/Kconfig @@ -36,6 +36,7 @@ config UDMABUF depends on DMA_SHARED_BUFFER depends on MEMFD_CREATE || COMPILE_TEST depends on MMU + select VMAP_PFN help A driver to let userspace turn memfd regions into dma-bufs. Qemu can use this to create host dmabufs for guest framebuffers. diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 1bad4576d492..0bbc9df36c0a 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -96,21 +96,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;