From patchwork Mon Aug 5 03:25:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 817277 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2040.outbound.protection.outlook.com [40.107.215.40]) (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 D61A113D28F; Mon, 5 Aug 2024 03:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828375; cv=fail; b=Zi/fmR9POYuCUgE1bkPvc3LyxMPU5EzU6Uwd5l9D8ElnnfF3GYG7jjdf+gi4mvM7BHOJpenZX42+M7Fv7WzUKZZcy68YrxxKKXk/w2OBTlj0vChPjlJO4sE9G5K/jj+hpbBhIMK/z+GXPy8y/dUfynID+eET1EgsRoqgUKVlRAA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828375; c=relaxed/simple; bh=cUkW6TeLRe6fboqss0BHYX+bgMX1dfJqYVRWdhgjqK4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=D+9YIwaBow1fgyrDFDLOHx7X7sErBq8SdodQ8NkVwt3MH28tySSUcz17xhwfX7Vl6+kOj1/0sHkqLg92V1UTKRtIcVzeWPBfZVPOj6EveCygsOIcrDpttsy5dYtSokA3VrbLQh7EmBoZFvr7csBerZt7KrxJvsg994xRX0xQnZo= 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=bd8RT065; arc=fail smtp.client-ip=40.107.215.40 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="bd8RT065" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Rh9v6vMeYK2CR15cTFqdTg6jP+TJdgyRAg4r912VgCyGa5Zv9NwFt6+XuZjPzOFtYn7Bq/BdMdjs4HxlAbHfPFCkIa4agwsYiFHmeIyCN4pSJ2ukVmGC3+nC7ODkQR8c/gzEuq5Yit8z3PlIJztAT11QI0PIDxcBWQXI4THFAV5Mm8shWJ6CH+SiIcTX+oF2x7hlx7XPCLOBXkAzNJ9cMEN0qeN01ig3fBkPXrYxL2P3jasWYbV2WF0f/hr0mgF4bqYE0MnLgLh/+l3UwAUQpyM80LRjNTsZnSmQGkmP7cShXb7OvjEN5HfbAEEFrggyewGeLmqcAeh1bdAaSQPSMw== 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=zN4BPOIWPDGqdDeOp0lBQqizd09UwfjA8JkwBWWPokw=; b=QdeHY6AtHG9alhhxinWZLqbY10XExsMMFSHcUZHjppDcVlvYaWjKWp0f/DyJPb1dRU3EV85PZhZEOzHcY7zZAGgQrrMHJEv0oymBxuQOr+73VKYuVNrNEoUWG4HuDBF1tcUhxHQlLr8PLCI/fOg5n5qiKWrCDkBXHEY86bzawto6bm+AYuAFp4QpGx/IzDP7A00PixE34ipLDUGVtg0b9bHWFobBc2HdYceEp5n6BBK0DumisqH6Aj8O4/JVdAmC7lmpZLzZNUqxWE9UFDpU8RGCffvRYoPYWHq21TJy+bGI4jI8v/28K9XBmwdIBvqUiyj3zXRUVm92mVatCYUlUA== 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=zN4BPOIWPDGqdDeOp0lBQqizd09UwfjA8JkwBWWPokw=; b=bd8RT065lorg7IgjwpZbZCcsGpcXmFePm+9qv3HFckThFKiPS+mY677Q8HlpuCPW0fj20a29nJpaxvHlbRUMP0mdiib/3f6dqVJG51EP2R/hafprg7YZ8LsVD34gzcjPj5dVp3H9BqsR+ImxtLs7W6NQM5MxM8x8Zv6p0XZKMmMhpspfpZl0+bGLpcoRWVQ0+y/DOSTXHqb96oRO7zEv6HsBM4kIQNW8336aoSuuvSR5BBPq805kFO20hC9JkzDA3ZsS3zVBYAcuygy3EOrHGOBcaR8lSDwDAdU75NdnQr120GCsa2CQ/W0rKmXOKrSGz9wC7ZwlrTOIP5jJqA2VaQ== 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 JH0PR06MB7349.apcprd06.prod.outlook.com (2603:1096:990:a5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 03:26:08 +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.7828.023; Mon, 5 Aug 2024 03:26:08 +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 Subject: [PATCH v2 1/4] udmabuf: cancel mmap page fault, direct map it Date: Mon, 5 Aug 2024 11:25:43 +0800 Message-ID: <20240805032550.3912454-2-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805032550.3912454-1-link@vivo.com> References: <20240805032550.3912454-1-link@vivo.com> X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) 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_|JH0PR06MB7349:EE_ X-MS-Office365-Filtering-Correlation-Id: 01379263-71d2-4dbd-97bd-08dcb4fe58ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|376014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: Sta/5HTwmHdzjAzlWdiN4gzbn9UEHvNL31YWCL6m1d7mvsYAxV9Kr5AHFah2HLJct5g3KjAT2G7CDNFgEh06XzhDypZkH7JyfRuGlpQAhQahnNsrBJlMoUyhWvaQsiHTVrnS/j9MzDun4JSONeN4XL/PP6bSh88vqoT3x+n/+NpFMkiKKhzl/7nunY+D2J8bCQrQL3M4dTfWhLBHYotuUCvUqdg7oNa0KGQ5Ncr2DBTfjKvV3IMT6CdlQsmPvplS7+mFYxlhNtD1Z/QoJTQArGIbeMn0lSD+PjRQvY95oNJd7H9Gr/yjcsqaH8fVJi4XJaQDjuTksWfpsZPnhaT6k7upveEQpLyCPvV/8EOBi2hWv/cJgs6mpeUCtvGc25Wh2hhkBwiCw8XR6xxFpSxiQNA6/tObB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PUZPR06MB5676.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(52116014)(376014)(366016)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DudbI0jsHexhODq+pT7oLJYTDpHU20dVWaMNH6rMF1i2aq9HSaTVOgeW1Se3zHrtjAq4UUL47bF8do9pmXkSjrBroFF3hwho8g2BnsZO797CwdMYst8pnVw0Moq4G5ubOZNzRdhvxSUvI0ZoIfnA7YTJHa4u/OdnOZSoKmHYXUHSakH7zUboavdHlccFrcl6xxrLktpcShL282I/NDcINwISsg7WeIFH1QfnNMetPIZ7GhCZSZNQ9bhTzuFN9dNeFDD8DSK3R090pf/JXz+6HsRaVHgtILYHux27cQjZDO8mJtuWTBpxW7idopucA/kJhayCroR4uA/oiM+/xiYFjA0b3VricGkHSHgHv1R3pvnk7hTjGaRls/PQRl3zfVzsiF2T6zYI+0yu039tAoKpGE4djMd1v1yQcoJX3eLnY3mC9YjPRJZVWykr9lsszUywbxMVwl84x2hBRTgvvF+2+kBNP6nnHp3IyPj5ndE8C2An7MfbjeipdqSmG9/MA0EGhh+jA4MFTFV/K0eq9DX/RY3t0J95G+cueG9j/YN6j81i3YgHciVdWR1W3IPbIsH+bQD3+NyeV48BWl68YqUDtXqu4/4v0qYHlu2QSZrfowjrTicptub+HLsHUF1YQiKFp7oJLR217i1ALUGPPcMbVpzXFPJMVGWLanK6PTK+83kNDEBzLMi8YhyeQbyMfsVY173gfyzA6//pHe33pNuO/gDRXpXXDxchu+bTvVdRLv1ebv4yYmy8QZBjJS3U6/2D9fQJ1i8xd99bGR8iahIoH3uK20vMMOvl6uZuhaBNgiSBLqsm6EbDqgQZd9//uu62mY8QUhGIg3jpN16BxwMrZFMAtWztOwM2zcWXWIvOOYB8u4fehuYuy+caozzOl1afxHthZuFEc9TXmZ3ExCXOFSQmx1Z1CkCUt+QfvgeYqRn3kVXsJpaxZQS3OUUbA9+62BkRJvquKUYVccWqUqIWehQekHIKREozsm+1VNCggHdhABoaDKNjS0lluyvOVxNdHq5HRKg2N0cQYmx0qF+yV5PxMIHYX8qKkmX2H6t+iwu3lF9YwJVB7FUJQmZvicbDpfEBCpo9+HpgfCHUjGnrcanSG2SADyY+lFymBcdZm7148W9oPRVsw2/CtwHWr4GPLhc6r4n9vRi0ZbHvq1WEyjWQ7AHoYSzu3lVon4+ObUom81/vY7fUwZsqUiJfwS/c/OVu8G8z8N2vC57nGoSHEBs+m9oEJuH/SyuSiYR7FxLjLAkDUWoSe8c3nht2RMIkxrO8jKVj4JYhO9jIKbXFxoRfV4GUSS6CHqaFQGdwxc4M+I0G2ZnN43dje8Zt7lX8FKCkAGqJUK81D+pZpAuPK2SEpFbKy61I/DLT+yZpVkCchF8xae5gFp9hQh9nCatHtdvShVWwY6f266HrVDSCiJsYfpD6I2jGazbzwX/hsUV79ySC5O7IL8DEVTuIlzJkSjMDIECJs1T9fxCvD0zaLrZbOuRO3yNJIAEptojL9+4LllslPat1zKetwXKd09WQRyXEKQtqdVtkxOSnskdibeglP8FmZzRT0njIwBmmmEsH3uGUPHD9TqBvDu2OYBBN X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01379263-71d2-4dbd-97bd-08dcb4fe58ae X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 03:26:08.3821 (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: j+ekU6rWPpT7eZwcW7AKZQP3E9R+A0MbR9qfaRcgTEaO0x5meedV1y7IgUcAENJ60I/fRiMqqprnlqJhVWjW3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7349 The current udmabuf mmap uses a page fault mechanism to populate the vma. However, the current udmabuf has already obtained and pinned the folio upon completion of the creation.This means that the physical memory has already been acquired, rather than being accessed dynamically. The current page fault method only saves some page table memory. As a result, the page fault mechanism has lost its purpose as a demanding page. Due to the fact that page fault requires trapping into kernel mode and filling in when accessing the corresponding virtual address in mmap, this means that user mode access to virtual addresses needs to trap into kernel mode. Therefore, when creating a large size udmabuf, this represents a considerable overhead. The current patch removes the page fault method of mmap and instead fills it directly when mmap is triggered. Signed-off-by: Huan Yang --- drivers/dma-buf/udmabuf.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 047c3cd2ceff..475268d4ebb1 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -38,36 +38,29 @@ struct udmabuf_folio { struct list_head list; }; -static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) -{ - struct vm_area_struct *vma = vmf->vma; - struct udmabuf *ubuf = vma->vm_private_data; - pgoff_t pgoff = vmf->pgoff; - unsigned long pfn; - - if (pgoff >= ubuf->pagecount) - return VM_FAULT_SIGBUS; - - pfn = folio_pfn(ubuf->folios[pgoff]); - pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT; - - return vmf_insert_pfn(vma, vmf->address, pfn); -} - -static const struct vm_operations_struct udmabuf_vm_ops = { - .fault = udmabuf_vm_fault, -}; - static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) { struct udmabuf *ubuf = buf->priv; + unsigned long addr; + unsigned long end; + unsigned long pgoff; + int ret; if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0) return -EINVAL; - vma->vm_ops = &udmabuf_vm_ops; - vma->vm_private_data = ubuf; - vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); + for (pgoff = vma->vm_pgoff, end = vma->vm_end, addr = vma->vm_start; + addr < end; pgoff++, addr += PAGE_SIZE) { + struct page *page = + folio_page(ubuf->folios[pgoff], + ubuf->offsets[pgoff] >> PAGE_SHIFT); + + ret = remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, + vma->vm_page_prot); + if (ret) + return ret; + } + return 0; } From patchwork Mon Aug 5 03:25:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 816911 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2060.outbound.protection.outlook.com [40.107.215.60]) (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 D98A01422BD; Mon, 5 Aug 2024 03:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828382; cv=fail; b=lCH4d1wSzCg4tAxKj+wrtOMRNu+neZyVc7o3IVJts7M7h+Wn3p7giA2AP7mRA7ApxwZ6MNVJ0cRygr8oGSFAzhREYIXkRJ2a3UrZ6aQnvJfqbnI2PLSIJ52j2Rd6AQ6/uk+0ZvV82IMj02vRnxQ5Dq29CfS25ksrur3sEny01zE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828382; c=relaxed/simple; bh=1JV5KSiwfEaIFUEDfFjf2A1mxlEviQDERg3Ki6gKE2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Q9YkUz5GlWO9wHTgBeZ3PK9GLJ8hY0ufWZv6H/QZEykysw80I+ACmh2Dpy9NTzlOooFcxHqVs2fey8EDlQ+CymS1jvv/SVJdDmmnz6lbIkvReTZ38tVbg6yZqB+o+JAPYnUGrTacjAJpbGUQ+9xLUO7s9PxbQwI6qSyvu0m+NSw= 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=nLQtw5nE; arc=fail smtp.client-ip=40.107.215.60 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="nLQtw5nE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xAHzvs0zhAAxkvwni4WuadJsl43EkEXt4294iLXKxTm3Y0rAL8OzYuxYlVU6LNpxErHBz5mfv/NXlSRkzDbdGn1VAw1Trz+KCdqanwxdPSmvoJ7PyYAzeXWe7JSLeTYdsMfT0XIGLlHAZScFuF99B7UquPRnEZEVcbwuj7GK3mY8DbNPjzcedcdi8vd/134vEpzz8wmnWeAnOtjcGwkdFuVos2wsdIxscnifHQs8Vu8SaGiadgnZBdTEvjr6tVr5gSsgq1OHdgFqQAHZLwQonG01rPaUIDtaiJBWKZ3FaTBg3SQTYgj/z2KTUKurZkUCl+AWvsITsgsOpFZ7dvutXQ== 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=tsHH4X5CdxMLGJRzF8Qxk8XqsOUiC6aUr+MRuw1SGcU=; b=CSDEKNsZgKiAUD5dKC9TRFW1P/YoNMcUoqLh81EGp+Bqo1gyKQuxIztnwNBve0oZCxnrmjLHhWwtU/YP/eQ4V0265kpAGhC3QQbL86VVY6qnJ/U5XKayOISqAT7VRRAxIWfg0N7T1wU73zeiniS7zMyWHJKgSmOAOxcwnHmRL69GDUaeCdDhPHhnoy3xkiEymoiuXzr/Kxo0h/jd8tdLIVTUs2i7qvwSII1p6wePhXMiMEuarlQ0kQu1ubL5mHLqWxi6QEVC8LRAzfxgJAJLG/J7e598McEeLHrmSNIpH1LCoy+SyC8vNgXVvHHb4VZwDYXsInPCQ0o7iUmkuLjSRQ== 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=tsHH4X5CdxMLGJRzF8Qxk8XqsOUiC6aUr+MRuw1SGcU=; b=nLQtw5nEjr6NORcz+HemiqGEyLFIkoPO2DkSdXG8NeGAGyPUq+Tr8+8YBaTVsOj04p+Di68uj+i6D43XSatd139HMjYZHeaCdLepLCRcjLdLE++xShGyj9RnFXCZJsgoyPJLrChs7vrmQRyRqS8FixsoYZuNEn3uE2ZLXl0JN7vEDdugHvtOP1PzvTjwtr01wLG+P6AmgP9OLPOGXcfwJItXPscsC0YOv6uvjSaUEFmo4eiN28xHQ8NqiCj8XLFSYTgzlUfGT3K64WWfsOozAXDYveytnolQAyxuO7xbU+x1VF0zUFm+y/6Q+XGuCekQi8Va/AclkpgQn6qrluICKA== 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 KL1PR06MB6988.apcprd06.prod.outlook.com (2603:1096:820:11b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 03:26:10 +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.7828.023; Mon, 5 Aug 2024 03:26:10 +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 Subject: [PATCH v2 2/4] udmabuf: change folios array from kmalloc to kvmalloc Date: Mon, 5 Aug 2024 11:25:44 +0800 Message-ID: <20240805032550.3912454-3-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805032550.3912454-1-link@vivo.com> References: <20240805032550.3912454-1-link@vivo.com> X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) 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_|KL1PR06MB6988:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e9b9454-d87f-48c1-5537-08dcb4fe59e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?MU1pYJMgdOP2yKYOLatHFFXaAhWAc5k?= =?utf-8?q?clvHdvbKn62Gg40p3HUoV9BnKfo7PzSKQNM+t00CgunPs+KnzVGxxXiXMeV8AO7Ch?= =?utf-8?q?jNRBN9oX18CS/hRiuQbqGTnA4YD9HccHVz/6PDA0AMPb5NXPOKh424QNzhCeEaiyS?= =?utf-8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evHREU2rLKHi8a2gDn8ZFewDgKDzxwT+6/+gexLqDHGj+Tyq?= =?utf-8?q?rd7zzuSM/NHH07+s2elLoAW/NRLldcHBe14L2GiCzCmKxxToTWbFi0y0024yCdW6r?= =?utf-8?q?DWhVbYNKxw36m7hftpJ5DVcXsgRqQE7ewrlbWVrFwEG1+snf6sDpyxw0lkydFgYpY?= =?utf-8?q?PeMINHJhRrd0+KPoW19ZNV3LEBBr81ES9jE6SKyhc0IypPvtNYdJVGIeAhso9DBdf?= =?utf-8?q?gFvMAFJ3sdwDsYkTd60dLrWNOkdYzpbymLPVhcuSs1WnbB2KW+Ul6/Kfj1C/lq7am?= =?utf-8?q?njL4/1loXtTsR3rK5hOFy3Xj9mQzJWcCyw=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)(52116014)(376014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?v8qKAB2LgjkdjKZO2V+Su5c+gBlO?= =?utf-8?q?saonjejxY/YP98BYwxX9pA4UD1xm5RdLXwPlHCCAF/i61FQCODLh58xcHD0z+9uEs?= =?utf-8?q?ZHqypeeuIvLlM3DBDbmLZXRa3j+TEoW8ezisILdd7NS+2SYoz78FyWLBA9D9sh0yD?= =?utf-8?q?ilZ3LXedrROXXuLrqDeAI0gWSLhbXuJ/cQKmctYj3mBSDm/uJKwxINUNWZNSM4A7e?= =?utf-8?q?X4cYYnMtWolCUidUZ/D2NOQczHgfZTI1VTSmMtAD0RQZ/mnln+1UuMWjiBthW3vf9?= =?utf-8?q?tVk6IHLfqJplmqKxpoesajRL8fsnGoEwF2IfFk0c3ijB4kEKA18jqNEApV1pIo4Fg?= =?utf-8?q?Eb3ABbDUB+qKx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hj+sUE+yPnOhruIiGWQsFhpB/akttS5FFFWFK13eHqQPy5II+vG?= =?utf-8?q?hQnLaTPLJgEiXOo4ZO6klBczMgNeWswBUZ3hue0vPs+7VXT3O7Z7eVDHrZSwNza/s?= =?utf-8?q?TfTuGsFKePslKuPuKpZ4fdOXlQ+sn3ViU4GYLvjovdt3uuFq8PlkIIdY/OAiFmj8T?= =?utf-8?q?ZRZG/LJzavBNhPvKGPPc+Rc0Vb+C1wkoDX/3s402k0MOjivkYxvNkcw55ZSm0+4S3?= =?utf-8?q?llNd90A1BAnQy/b1VdlSqAuTfzXxTn1w9CvCk830l7YvSpZmIQbjbqy/Dr1EbkJ8N?= =?utf-8?q?yYDpR7E6vZW2?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e9b9454-d87f-48c1-5537-08dcb4fe59e8 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 03:26:10.5236 (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: ddhW1yfnWIcNHiLjML+fhV/EqjdlpvMj3Qf0A8A68SOskCSBnUpOstVsFMF0+nzbE/A8k+Q4ZHdFzM2cwAhzNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6988 When PAGE_SIZE 4096, MAX_PAGE_ORDER 10, 64bit machine, page_alloc only support 4MB. If above this, trigger this warn and return NULL. udmabuf can change size limit, if change it to 3072(3GB), and then alloc 3GB udmabuf, will fail create. [ 4080.876581] ------------[ cut here ]------------ [ 4080.876843] WARNING: CPU: 3 PID: 2015 at mm/page_alloc.c:4556 __alloc_pages+0x2c8/0x350 [ 4080.878839] RIP: 0010:__alloc_pages+0x2c8/0x350 [ 4080.879470] Call Trace: [ 4080.879473] [ 4080.879473] ? __alloc_pages+0x2c8/0x350 [ 4080.879475] ? __warn.cold+0x8e/0xe8 [ 4080.880647] ? __alloc_pages+0x2c8/0x350 [ 4080.880909] ? report_bug+0xff/0x140 [ 4080.881175] ? handle_bug+0x3c/0x80 [ 4080.881556] ? exc_invalid_op+0x17/0x70 [ 4080.881559] ? asm_exc_invalid_op+0x1a/0x20 [ 4080.882077] ? udmabuf_create+0x131/0x400 Because MAX_PAGE_ORDER, kmalloc can max alloc 4096 * (1 << 10), 4MB memory, each array entry is pointer(8byte), so can save 524288 pages(2GB). Further more, costly order(order 3) may not be guaranteed that it can be applied for, due to fragmentation. This patch change udmabuf array use kvmalloc_array, this can fallback alloc into vmalloc, which can guarantee allocation for any size and does not affect the performance of kmalloc allocations. Signed-off-by: Huan Yang Acked-by: Christian König Acked-by: Vivek Kasireddy --- drivers/dma-buf/udmabuf.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 475268d4ebb1..af2391cea0bf 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -73,7 +73,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) dma_resv_assert_held(buf->resv); - pages = kmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL); + pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL); if (!pages) return -ENOMEM; @@ -81,7 +81,7 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) pages[pg] = &ubuf->folios[pg]->page; vaddr = vm_map_ram(pages, ubuf->pagecount, -1); - kfree(pages); + kvfree(pages); if (!vaddr) return -EINVAL; @@ -189,8 +189,8 @@ static void release_udmabuf(struct dma_buf *buf) put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL); unpin_all_folios(&ubuf->unpin_list); - kfree(ubuf->offsets); - kfree(ubuf->folios); + kvfree(ubuf->offsets); + kvfree(ubuf->folios); kfree(ubuf); } @@ -315,14 +315,14 @@ static long udmabuf_create(struct miscdevice *device, if (!ubuf->pagecount) goto err; - ubuf->folios = kmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios), - GFP_KERNEL); + ubuf->folios = kvmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios), + GFP_KERNEL); if (!ubuf->folios) { ret = -ENOMEM; goto err; } - ubuf->offsets = kcalloc(ubuf->pagecount, sizeof(*ubuf->offsets), - GFP_KERNEL); + ubuf->offsets = + kvcalloc(ubuf->pagecount, sizeof(*ubuf->offsets), GFP_KERNEL); if (!ubuf->offsets) { ret = -ENOMEM; goto err; @@ -336,7 +336,7 @@ static long udmabuf_create(struct miscdevice *device, goto err; pgcnt = list[i].size >> PAGE_SHIFT; - folios = kmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL); + folios = kvmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL); if (!folios) { ret = -ENOMEM; goto err; @@ -346,7 +346,7 @@ static long udmabuf_create(struct miscdevice *device, ret = memfd_pin_folios(memfd, list[i].offset, end, folios, pgcnt, &pgoff); if (ret <= 0) { - kfree(folios); + kvfree(folios); if (!ret) ret = -EINVAL; goto err; @@ -375,7 +375,7 @@ static long udmabuf_create(struct miscdevice *device, } } - kfree(folios); + kvfree(folios); fput(memfd); memfd = NULL; } @@ -391,8 +391,8 @@ static long udmabuf_create(struct miscdevice *device, if (memfd) fput(memfd); unpin_all_folios(&ubuf->unpin_list); - kfree(ubuf->offsets); - kfree(ubuf->folios); + kvfree(ubuf->offsets); + kvfree(ubuf->folios); kfree(ubuf); return ret; } From patchwork Mon Aug 5 03:25:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 816912 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2060.outbound.protection.outlook.com [40.107.215.60]) (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 D97A213E881; Mon, 5 Aug 2024 03:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828379; cv=fail; b=ekw6Xp3ZEKnX4AJEE73zye1o0HkL7XLjkoTRP8t1RaFtZbcWHvrZvkAR245BCqs7YsjkYZBJXP2rxFmtzJsnU2OpYN/IpEDHhG+eJE7EZz/l9lP1Jq8AmTBqw3lTcCxsUNedVFh1tPC9+H+eC3J98BONTdARaRV4CHguwQN7VGY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828379; c=relaxed/simple; bh=pErINMFT7IfmYG0GEJAUtRbyEkcrnvQ/3R3/ev6ebYY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=mQ9dWU8r7r5muaTvy63CgKy8RgRu/abYihyQLtFkJ+f3jQuriNQyOTnGN7iO0oPqoGzVLmyB+d7Ede+qrarJGfcW5IHsSTN/1RXDmWjLW44MfuD0f2vUaqNw0qLkvs8SYsMLZYleJUFdCuREVFQI+7VR4LDtmJuOWNzMBmICzQA= 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=Ug+sMb+B; arc=fail smtp.client-ip=40.107.215.60 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="Ug+sMb+B" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kT2LGoI83+6lvunhp7+zi2bcNBVzAtAEDmY7OaKObmlXaTrNsPH5KigLNrUWQEPX11inSQR1sr3BIg7THt/LbWlXgS1C+2ge19A6ve8okvEUtyUf+BFccjSIz/q8qx/TWQ0V9jlDdMMHVUG4ejgAgs4vUZmqLT/acx6PKuqN0/ut0+wKZiUuUBtDEJVk8bTcL5e7eP1EHXobGA0LCRvPEMJmM06cfIJOR0k5PdlaEGGrP9SWLseEcYZYVEWYFcJ2qmPm+qUbkrly5IlTMq2UkgOlzj9jADXgXBdlH5EHxUzPT3gJn6wCrXC7+pz2IuwZq7atwEVz/Mm94XTgITvK+A== 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=N2cWvy/CqupHCFSbbHPQVyjQiZ/HSwtMGli/YgYqm7Y=; b=UkZ8xZDWvCHl0ThDc0Kb1PmR63pjK0MuoYy0KEVw4XQS3xdYS2BWvvH0J99pzVGxQ9hVPeeT7JHGGehLUOgls/iQmKYTkby5RZRKW5jXB/m08yDqp/BLHLOt01CUtrbW48MwQI02EFnHMfWAMIFQsFaowHIDQVZFQWm2ulxX5oh1d/NjPJNW8C8WfMuC1Jqh6hL+Z5RUj4NtuvhU8ekmd5vsbhJ8AUX7A4g69GsZpJlCgaNB32lMjpyLuLAsqy4CLabvxghrhmD/s/Kwhbf86qfELUg5KZiWKxD+B7ooRuUmPQ1cA3xu1ys0JB6rs7WLczkKKh5gHr2IQg4DyhVzRA== 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=N2cWvy/CqupHCFSbbHPQVyjQiZ/HSwtMGli/YgYqm7Y=; b=Ug+sMb+B+7Lmfztjj+ECy0+TS/MYpV+BQu3k+iv4CDQLjW1m21EnJ+8LaLJ0jS3CGzBK+VGrvIm5ROG/DsC6ntaaHpvUMQuhBDuw2I76ft98BvzxI2I4hifEcJyacAu5SKmXlEwtN65l+i6vItkd1lM29fyEicu43peAlLCbM3eoQJQdIvWEp99Wd+2SFHlavxnJrzDGYTEly9anfYRzHaLeznPqKyxjRrbu0fFAdjw6HPiwSzm46A4IqkjC07sAqv3yzFrcctUzAiyx2zQhP/GiZMREGebOQzGWRr3GXt3cpD5ZsHbR6U+Cj84P5QPBzJBlI4KcFAj94Qfa1HcX5g== 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 KL1PR06MB6988.apcprd06.prod.outlook.com (2603:1096:820:11b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 03:26:13 +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.7828.023; Mon, 5 Aug 2024 03:26:12 +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 Subject: [PATCH v2 3/4] fix vmap_udmabuf error page set Date: Mon, 5 Aug 2024 11:25:45 +0800 Message-ID: <20240805032550.3912454-4-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805032550.3912454-1-link@vivo.com> References: <20240805032550.3912454-1-link@vivo.com> X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) 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_|KL1PR06MB6988:EE_ X-MS-Office365-Filtering-Correlation-Id: 970a2b40-6021-4f64-d6fd-08dcb4fe5b2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: dOKilgeqrm+Xo6eNryomT3SOd8pLGkglP22yrUILkQYiosX4/Pftf+jT7wRYGtkPvz4u9hVfDaKAvxBCuvL85K5VUtlHnXK4UrBfbrzb0s9IwqJuV1KxZfnvq9K8w4nQw1ZkS5wCecfUYKEaU3lqtKEfDvwgvs2xQrhwnhcgZOf8iNnVvceyBfTrLgu9rf7xuwV412jZzO8yZq6lROv82pFLBfdl+wTEQ2UBdtOvPk7VArisFr2KEGw7L75C99yZ9vxFg6I+YqMixBeV5pXtyRKJ7CUgWyaZxFPRacdoAKrbWtAqhvpANbC2XTJa6KdcXQlvP+6waCKXYvfPmaXdbNcMpbz14IweH2H970iC3UkoEGa/4RMpoTvBAiQTAU0itvSks4eqdecyr4xa4wDguwVYQivVstDiPX6s3QxHzumjHtgSYq/DWN27ufRwwzBXDh4mVxAML15drOBpUS/ND63QC5y7khZNyHfcgPyjW+3llMuxZbZ5Maw/KztN4GSPbhChsKc1XUb6092/rr3b/niQmOMYua++TejKlLWDyNi0xl9uEgL14YhKC78tUcSNAHfNwsGMLrb2DQUkbq9NsCo161/e1eRzky/73Y2Ok+0rnTQ2eiMrU+tBCEuu7oD+1Ypxl93e3m8OukbV50uXdvkNCqFHGbmgzOxVTLKlBLrFOi+fYh8G5as+9qfCEcblPpYBPras5QJAb6tZYyNvoensA+XbLz4pqFGLRjYXYvxooc3FD13pSRred084h5AhLs4mHdvFEnL6kfx966XLPZ/7IY2v6+BbI1PcE1Ld3XxMqjwX/f1xfmAEd7/z+vZKctzpumuZrG37Y5vNzGmkxGqtIc+olWdRE+j2oCwMDQZcyoaFEWHeI0fO/WAXnX+9pb6a/5ylixViUYp38wq2DgihVBF0iyBGF1616s7/LYVIPBAk87FqLBzPHW4ZobqxXtcLdIjoobBZX48K+N1l8iPStaSEWjVFwyiiE0RsPN44OocLroanAsrNmpRg0B9jnu2aRbKBoqyYeX8TzyPFUnLbO/FFds71+cAikZYOUNzVcct3Cen3TIZh46eow+03lXBB07WeojTM+cJ6NpTQzNFxkkzH5XRzSvggZe7GabHe1vHWT0HJCf/FmdaunIueBfTFHCSDsqMtQAl301edAk6JHN/bo4wXzwdd2Y9Ui6t8ifS0kPoU6wgOi5yGkD1+K4SUQyaddyME5gKp1Q/t0c8HcWz6Z2puZ1Ba9tYGkURtJRzCKFC2Y51Ul3k9m81kTrKz6JXJtQpEallyXwmzqQc8JDs3q20C8MRbSLKWr83LbPZ5tW4zZiKovQFtTW1M9mKDShiTTwrvssxHkffsz8Tx12j/EkA/qvpJzYFpqsOyVbmpQo4myqe5WNhk3UX/f4aHlYoeQpDguCmXlbxu8g== 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)(52116014)(376014)(1800799024)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-A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QEfsAJgQYx8hEOLJh4YJN6bFqMw/vJINN7MGjOTmY6KthbHPsd9ZTuuIeoYEAHFEVvVqw5ndqmc5ofDOE3o1zgnrESjiWE7mXVfd3uP8CVCJn6a6WOJFNfv6ptFSLl3xBhkQe+cR3f6Gdlj2IfXUvvBDnKgXKBqIQGtph6GYU17uPe/+CLF7tznCbAEbaTqVPTSqF5Lg5GneYzTDYNT32960Q0j7+rByTfjgfVcSfuNaN2x+fbhBT6n9B5YsZwqopl4R0QHXNcIrM231RaOy36pE0xp0KkiJbwgLPZK2AvZMktmWgofOwD1utN2nkI7WoU9reuxMloG3+9QNfUrZMupqWodF4WwdbfnA3lx9KHzaekytI7NfsVjjWfnLnqSGCRyJpN0fGwt/mzhC4cIjRn8/eB0f9l7Ogrq07DCCjJImJxkpgKNSl/tDNbQyPazBvpraYjCgG+0zRiA+TExTGheb9ZmkICQbGNoJwivO9mz31smAoPsmTbyrXI1wZtXKdC7IjLK X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 970a2b40-6021-4f64-d6fd-08dcb4fe5b2f X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 03:26:12.6199 (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: umqNwg+O98Je9z0HhvYhZ4NdqB7seKM4j+KdgXfylpoI9Q4KagyJ1OR1ufb+sdt8AENDClVmPn7RyBmdekOGzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6988 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. This patch fix it, set each folio's page correct, so that pages array contains right page, and then map into vmalloc area Signed-off-by: Huan Yang --- drivers/dma-buf/udmabuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index af2391cea0bf..9737f063b6b3 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -78,7 +78,8 @@ static int vmap_udmabuf(struct dma_buf *buf, struct iosys_map *map) return -ENOMEM; for (pg = 0; pg < ubuf->pagecount; pg++) - pages[pg] = &ubuf->folios[pg]->page; + pages[pg] = folio_page(ubuf->folios[pg], + ubuf->offsets[pg] >> PAGE_SHIFT); vaddr = vm_map_ram(pages, ubuf->pagecount, -1); kvfree(pages); From patchwork Mon Aug 5 03:25:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 817276 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2070.outbound.protection.outlook.com [40.107.255.70]) (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 8BD61140397; Mon, 5 Aug 2024 03:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828380; cv=fail; b=G+vW1vXj+PAD9S7FDUePkaD0WtlfMmUCb4Vr4eeTgNWCQFnjFb3e0BsZp7r+LGqGlbMQio32iKZbDBJufsKT68qERpgrySQ8cIDcKyaTmENNkrrIvSt2rl72XEBaYR4uLwHDardkDwEGTQ+ExwPsRWzs8C6gufARo2viDDykLVw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722828380; c=relaxed/simple; bh=tVP70bDqQ2LhNHNXDrKNBh/eSHAuU1ZyGqn43xzt8iY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=WK6mlUW/Ib98TXF5rbDVdy5xprw7ZbQGJHbAtR5FUj8HvCZWep9gzcGVKkfILqw1C0GvqzMetNR2o+DOY5dMaZHytBSYrotuf5+RomCg9UuK78MeQWxsSRMM78UMrTdBZLuyyDk5ZEeyEwiAvnbOI26PsV+f0wP/ZlmCSQuW2HY= 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=cfK/XM5t; arc=fail smtp.client-ip=40.107.255.70 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="cfK/XM5t" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hWeSPB3cojb5CCrsNtHsWaS5i7Mq6dIVVQAFl9DfFTSzZfpt2XKXMGxLl+tNsw6jQvRGHaDSDXDs+OWsFnpbsfbAh2zwxXI6Tow7cqPa7Nyeju6FqUzW1x7jom2ZoBAKjaxgmQzeqaMJSw3mDQKCZDrgXT6fKmOarmf5FYZZcEApYcY65EjCAxyzLr9G/DOiZC7S4h95yKqHAMtxi+RI99uSc1JU0ZvAcnLOrAUNOg7sozKBsRcAmciPJqe2eXEzy8RfiEMrAuoDSijNVeEgF4AD94oHgEFlCCv/OVWtavzShyTXh4Ym16f2ia+SUre919VoBaLco6bbbELi+O2Wrg== 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=EUCEDBtnwqDVDwiaL17GMS+rnWbFLnQk5kXnB8bMGV8=; b=rr8DfNJfjeAhi9WkgWAsnrucgs1cOBAM7mrFTnlFfdsBw8rnvT/sOhyotk4maykMetIvxVULelL4q+/OVNgH3h19vKwSWjoy7nCC5YZndRrjvpLJ+X+wMBuJ8pj7q4451m/9qWefT/oWH5fErHTBJ7eyj7vBXI+kuSU05rIxc7jhLncq+d5TI3WWNCBTmqR06PswZ2/HYw3HV9Q2Q9I670kQZhxYiqPl9JZ4aO62MsiJwTsCk+zJVvmPuVdi7EgL0NmLvgHfNdJlrAtyt7gDy5uzR8vF5qov2A6swCkWknn0Yqa0HBp1T8xb8O44s62YNAFR6FG9x6jfeAec/QhQZg== 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=EUCEDBtnwqDVDwiaL17GMS+rnWbFLnQk5kXnB8bMGV8=; b=cfK/XM5tf15v//lTPxq4WTLGLNn7RUgCOBVOHtjcx+fOh/kDmx1X6VzoJ7uji/Nswc67hUHdGHK21qViaPwH++ZtiQp4l8Vuy33opAaq9yGFTSiqtqJihxwrC0r1GkKA7vvIx2egzWLZT6x+P1GWXoqSxIfbWJ5cCoB8xAKI5WORbA48cKR6Rlm1plxSSHapfFQ/1ussLGEgyHyL5tZCyTdj+cqUQERLNKox7Lg/yIYeFnUqOXnveFKQZjivcQEzuR168gNE9Z9fxCQo+nhIBFJ0Ys8Gg2QVrcPRCfJlKunkQjsq8G4phBT3aRHvY9TTWOZhB9ceRW4rk6+wAsLigw== 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 TY0PR06MB5471.apcprd06.prod.outlook.com (2603:1096:400:265::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.24; Mon, 5 Aug 2024 03:26:14 +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.7828.023; Mon, 5 Aug 2024 03:26:14 +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 Subject: [PATCH v2 4/4] udmabuf: remove folio unpin list Date: Mon, 5 Aug 2024 11:25:46 +0800 Message-ID: <20240805032550.3912454-5-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805032550.3912454-1-link@vivo.com> References: <20240805032550.3912454-1-link@vivo.com> X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::12) 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_|TY0PR06MB5471:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ffa4ada-1df3-4fc7-5716-08dcb4fe5c79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: pNpj2guqw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gYB8VIRe952ia7DkWqzx8RqS8g4LsqhpEOjO7HAZ7oquE0M8LQRPUzDPelytb8iiMBONseVrWKDC+lcyjthjDTr0vj0yQAj1WSP+keiy2dNiDTHzcvzu8fgnaT7Ip7wnD/q9rhVQ5mjYrHw3KEphd8YsneIJyh1zyQja5L1xMpM5oG4FIMMLDymzu9Qpc6zadLhOVxXLudmGNdvyNInCJdIHP25pOvXcFQ3n7jI05FGe4s2AuYKlWVxtxbVucO7mYweLaVaxYLKlkyfyAXVsnptKV3CvNvKYITsu61ZM0OZxQpnnjjYepKbALr1+zRw6E8eE48SBFWkGnsX0HFpKr8cMzg== 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)(376014)(52116014)(366016)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2k4+cDt0zX0ovjcnOokCNhOvEyCoqZbaydpumfZEV3xTrI/WopSD+3g+ulg+t2ng03YnJl0031/BQCKae2gNS8azxDyP0HMGlbiCwbBF5Ku87PvG/RFaMDktMyPvx/aJULVov7+S9ZzRAysjAcxrh1ZtUA8IaqCZCJhwYxa/agDkYgW6DEGoWzZ8roz2hBtKfsl9TJe36nP7F2NcMY6YvK3veR/DBdx/t9Zb4+zesn4fOh7iR6pjYU36tSqkoou8xVHKKTK+6N7XS7+0BMZDZVwwRjeEk2TfhyilLsGjAjEzV0CAwApEcVzNb6sk2CJs1aciW+rrkRdlxOXu3W/S0vQ3BZLnekVUbxQuNOBj2pGkMSS0eCUfzARuz68Tz6i6yRR38T5ODpqFdAnXMK/fpUb9GMonPz7A5MiRMgj2yj1RTIgkDzXd8nKTcp33CF5CzjFDsPn8dW4i5KVFpUuCoy2emc2mmvy+THSCt7bDdve0DE/KVgZoT/tEGI7l9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-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ffa4ada-1df3-4fc7-5716-08dcb4fe5c79 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 03:26:14.7402 (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: UTH0Mcmbs7/Gy7mxHbJrUgLLwi2gmhnjGV/qoxf4JC8WMq1m10QLYM+GoWJZC7lH1pT8tQJ1vUhYLZEHBp9wnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR06MB5471 Currently, udmabuf handles folio by creating an unpin list to record each folio obtained from the list and unpinning them when released. To maintain this approach, many data structures have been established. However, maintaining this type of data structure requires a significant amount of memory and traversing the list is a substantial overhead, which is not friendly to the CPU cache, TLB, and so on. Therefore, this patch removes the relationship between the folio and its offset in the linear address mapping. As an alternative, udmabuf both maintain the folio array and page array, folio array use to unpin, and the page array is used as before to handle the requirements for the page. So, udmabuf's folios only save the folio struct, foliocount point the size of array. pages save page in folios, number offset given by create list, pagecount point the size of array. Even if we restore the pages structure, its memory usage should be smaller than the combined memory usage of offsets(8 bytes in 64bit machine) and udmabuf_folio structures(24 bytes in 64bit machine). By doing this, we can accept the overhead of the udmabuf_folio structure and the performance loss of traversing the list during unpinning. Signed-off-by: Huan Yang --- drivers/dma-buf/udmabuf.c | 167 ++++++++++++++------------------------ 1 file changed, 61 insertions(+), 106 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 9737f063b6b3..442ed99d8b33 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -25,17 +25,24 @@ module_param(size_limit_mb, int, 0644); MODULE_PARM_DESC(size_limit_mb, "Max size of a dmabuf, in megabytes. Default is 64."); struct udmabuf { + /** + * Each page used by udmabuf in the folio. When obtaining a page from a + * folio, it does not necessarily begin from the head page. This is + * determined by the offset of the memfd when udmabuf created. + */ pgoff_t pagecount; + struct page **pages; + + /** + * Each folio in memfd, when a udmabuf is created, it is pinned to + * ensure that the folio is not moved or reclaimed. + * folio array used to unpin all when releasing. + */ + pgoff_t foliocount; struct folio **folios; + struct sg_table *sg; struct miscdevice *device; - pgoff_t *offsets; - struct list_head unpin_list; -}; - -struct udmabuf_folio { - struct folio *folio; - struct list_head list; }; static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) @@ -51,9 +58,7 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) for (pgoff = vma->vm_pgoff, end = vma->vm_end, addr = vma->vm_start; addr < end; pgoff++, addr += PAGE_SIZE) { - struct page *page = - folio_page(ubuf->folios[pgoff], - ubuf->offsets[pgoff] >> PAGE_SHIFT); + struct page *page = ubuf->pages[pgoff]; ret = remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, vma->vm_page_prot); @@ -67,22 +72,11 @@ 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; void *vaddr; - pgoff_t pg; dma_resv_assert_held(buf->resv); - pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL); - if (!pages) - return -ENOMEM; - - for (pg = 0; pg < ubuf->pagecount; pg++) - pages[pg] = folio_page(ubuf->folios[pg], - ubuf->offsets[pg] >> PAGE_SHIFT); - - vaddr = vm_map_ram(pages, ubuf->pagecount, -1); - kvfree(pages); + vaddr = vm_map_ram(ubuf->pages, ubuf->pagecount, -1); if (!vaddr) return -EINVAL; @@ -104,30 +98,25 @@ static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf, { struct udmabuf *ubuf = buf->priv; struct sg_table *sg; - struct scatterlist *sgl; - unsigned int i = 0; int ret; sg = kzalloc(sizeof(*sg), GFP_KERNEL); if (!sg) return ERR_PTR(-ENOMEM); - ret = sg_alloc_table(sg, ubuf->pagecount, GFP_KERNEL); + ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount, + 0, ubuf->pagecount << PAGE_SHIFT, + GFP_KERNEL); if (ret < 0) - goto err_alloc; - - for_each_sg(sg->sgl, sgl, ubuf->pagecount, i) - sg_set_folio(sgl, ubuf->folios[i], PAGE_SIZE, - ubuf->offsets[i]); + goto err; ret = dma_map_sgtable(dev, sg, direction, 0); if (ret < 0) - goto err_map; + goto err; return sg; -err_map: +err: sg_free_table(sg); -err_alloc: kfree(sg); return ERR_PTR(ret); } @@ -153,34 +142,6 @@ static void unmap_udmabuf(struct dma_buf_attachment *at, return put_sg_table(at->dev, sg, direction); } -static void unpin_all_folios(struct list_head *unpin_list) -{ - struct udmabuf_folio *ubuf_folio; - - while (!list_empty(unpin_list)) { - ubuf_folio = list_first_entry(unpin_list, - struct udmabuf_folio, list); - unpin_folio(ubuf_folio->folio); - - list_del(&ubuf_folio->list); - kfree(ubuf_folio); - } -} - -static int add_to_unpin_list(struct list_head *unpin_list, - struct folio *folio) -{ - struct udmabuf_folio *ubuf_folio; - - ubuf_folio = kzalloc(sizeof(*ubuf_folio), GFP_KERNEL); - if (!ubuf_folio) - return -ENOMEM; - - ubuf_folio->folio = folio; - list_add_tail(&ubuf_folio->list, unpin_list); - return 0; -} - static void release_udmabuf(struct dma_buf *buf) { struct udmabuf *ubuf = buf->priv; @@ -189,9 +150,9 @@ static void release_udmabuf(struct dma_buf *buf) if (ubuf->sg) put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL); - unpin_all_folios(&ubuf->unpin_list); - kvfree(ubuf->offsets); + unpin_folios(ubuf->folios, ubuf->foliocount); kvfree(ubuf->folios); + kvfree(ubuf->pages); kfree(ubuf); } @@ -289,19 +250,18 @@ static long udmabuf_create(struct miscdevice *device, struct udmabuf_create_list *head, struct udmabuf_create_item *list) { - pgoff_t pgoff, pgcnt, pglimit, pgbuf = 0; - long nr_folios, ret = -EINVAL; + pgoff_t pgoff, pgcnt, pglimit, nr_pages; + long nr_folios = 0, ret = -EINVAL; struct file *memfd = NULL; struct folio **folios; struct udmabuf *ubuf; - u32 i, j, k, flags; + u32 i, flags; loff_t end; ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL); if (!ubuf) return -ENOMEM; - INIT_LIST_HEAD(&ubuf->unpin_list); pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT; for (i = 0; i < head->count; i++) { if (!IS_ALIGNED(list[i].offset, PAGE_SIZE)) @@ -322,64 +282,58 @@ static long udmabuf_create(struct miscdevice *device, ret = -ENOMEM; goto err; } - ubuf->offsets = - kvcalloc(ubuf->pagecount, sizeof(*ubuf->offsets), GFP_KERNEL); - if (!ubuf->offsets) { + folios = ubuf->folios; + + ubuf->pages = kvmalloc_array(ubuf->pagecount, sizeof(*ubuf->pages), + GFP_KERNEL); + if (!ubuf->pages) { ret = -ENOMEM; goto err; } - pgbuf = 0; - for (i = 0; i < head->count; i++) { + for (i = 0, nr_pages = 0; i < head->count; i++) { + u32 j, pg; + memfd = fget(list[i].memfd); ret = check_memfd_seals(memfd); if (ret < 0) goto err; pgcnt = list[i].size >> PAGE_SHIFT; - folios = kvmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL); - if (!folios) { - ret = -ENOMEM; - goto err; - } end = list[i].offset + (pgcnt << PAGE_SHIFT) - 1; - ret = memfd_pin_folios(memfd, list[i].offset, end, - folios, pgcnt, &pgoff); + ret = memfd_pin_folios(memfd, list[i].offset, end, folios, + pgcnt, &pgoff); if (ret <= 0) { - kvfree(folios); - if (!ret) - ret = -EINVAL; + ret = ret ?: -EINVAL; goto err; } - nr_folios = ret; - pgoff >>= PAGE_SHIFT; - for (j = 0, k = 0; j < pgcnt; j++) { - ubuf->folios[pgbuf] = folios[k]; - ubuf->offsets[pgbuf] = pgoff << PAGE_SHIFT; - - if (j == 0 || ubuf->folios[pgbuf-1] != folios[k]) { - ret = add_to_unpin_list(&ubuf->unpin_list, - folios[k]); - if (ret < 0) { - kfree(folios); - goto err; - } - } - - pgbuf++; - if (++pgoff == folio_nr_pages(folios[k])) { - pgoff = 0; - if (++k == nr_folios) - break; + /** + * Iter the pinned folios and record them for later unpin + * when releasing. + * memfd may start from any offset, so we need check it + * carefully at first. + */ + for (j = 0, pgoff >>= PAGE_SHIFT, pg = 0; j < ret; + ++j, pgoff = 0) { + pgoff_t k; + struct folio *folio = folios[j]; + + for (k = pgoff; k < folio_nr_pages(folio); ++k) { + ubuf->pages[nr_pages++] = folio_page(folio, k); + + if (++pg >= pgcnt) + goto end; } } - - kvfree(folios); +end: + folios += ret; + nr_folios += ret; fput(memfd); memfd = NULL; } + ubuf->foliocount = nr_folios; flags = head->flags & UDMABUF_FLAGS_CLOEXEC ? O_CLOEXEC : 0; ret = export_udmabuf(ubuf, device, flags); @@ -391,8 +345,9 @@ static long udmabuf_create(struct miscdevice *device, err: if (memfd) fput(memfd); - unpin_all_folios(&ubuf->unpin_list); - kvfree(ubuf->offsets); + if (nr_folios) + unpin_folios(ubuf->folios, nr_folios); + kvfree(ubuf->pages); kvfree(ubuf->folios); kfree(ubuf); return ret;