From patchwork Tue Sep 3 08:38:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13788290 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 32D13CD3420 for ; Tue, 3 Sep 2024 08:41:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 442E310E3AB; Tue, 3 Sep 2024 08:41:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=vivo.com header.i=@vivo.com header.b="Fv/Upo97"; dkim-atps=neutral Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2075.outbound.protection.outlook.com [40.107.255.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id D7D8810E3AB for ; Tue, 3 Sep 2024 08:41:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QvG6HXwlM3yBwkT+v63EveUC46NMI6rJ5PfnThKc3/Bm/IHbNrXy3k5iwksBy95f24c0uja0LDO1A27vQ6gnnr1BdNskTzrJsEqnuu0671zex14x7Aflfth05M0TVaIW54IMJ/e1pSbmaLlQEFJvnVJRvb8cftHGBcvH94GV89+xOqqlkGFSm7ELjcyShuZi4MoaOZi86ob6vkvwSbfFL7U8w1j36Qz9vBZ5e6dVK1AkkvJkKKxm2RL3uVLeDz1HIBV4yGnluVuVI7vfc09O9tfUuzg2KojVP9MF7dISfX3h3Fttx9E6xnLcaYdZmgzc49XlfSfMuHsREQMGT4NAlA== 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=bEl7paveOHylyyRXGVKtozPBzrcu8xkDidxcynB+u1Q=; b=m5vS1PosSG5y/OZasLOJ1WDOz+c7h1LdMsDsyGjxguwBNbNsfGqEwJU4BOIxGJ6YN7HqYZdG8W53ifESZpa4ReMl9kALRYYsBGVDpg9V+UQJ3UGYvAsm/vnLYuvgHCvu+TtaiBt007VlGN5SeBPX21wiFBvpKduT64+c4pA0XgbU3j83RcJpuiIEGG92kL1zqkG4K3767PeW4IO1YN3i84EYPShQPnN4ODOC6ELen/X9vkbl9YwqS478+ClGRMSqKgBTSBpjVvkHX4zzJGbinXTQWMozTPMiFY2GM1Pf+DlGA7S8MMLPbVxOHbrxo66llKjCJRBNg6dtrjG2bzThZg== 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=bEl7paveOHylyyRXGVKtozPBzrcu8xkDidxcynB+u1Q=; b=Fv/Upo97xxwZfcJg9/oeU1OyEKf7gEV26hSI0fFmiveAeEM+JJM4FRH9SM3UNzUtp/2Uj0ryC5L7KdAwvorUedqNgw9zLkQ3KWKc3IJO4lzYM7xFjryn4Iw/08gg4yPW5m6An9vZPA8vb3WiYx6kshx4afrsPc+JEbSAns4zosdhp4YscVMb7zW4TKQN2wi1tCKF1HSj0krQ+hKbr5bmm76d59UqKppFtYgqAPz2zLGwUFiil8hcenryz/7R6tWFE9ZCyJkiMwXf3FANze8IwFVxeLSwyv2Jtuz3SuVjzWl6QQLZGc4V34Cv3XI0Cu1Ae3beAgatprZ7STiHB6wWRg== 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 SG2PR06MB5359.apcprd06.prod.outlook.com (2603:1096:4:1d7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.24; Tue, 3 Sep 2024 08:41:39 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%6]) with mapi id 15.20.7918.024; Tue, 3 Sep 2024 08:41:39 +0000 From: Huan Yang To: vivek.kasireddy@intel.com, 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 Subject: [PATCH v5 1/7] udmabuf: pre-fault when first page fault Date: Tue, 3 Sep 2024 16:38:06 +0800 Message-ID: <20240903083818.3071759-2-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240903083818.3071759-1-link@vivo.com> References: <20240903083818.3071759-1-link@vivo.com> X-ClientProxiedBy: SI1PR02CA0026.apcprd02.prod.outlook.com (2603:1096:4:1f4::11) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SG2PR06MB5359:EE_ X-MS-Office365-Filtering-Correlation-Id: 70e5a525-5a94-4afe-000e-08dccbf43a70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|52116014|376014|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gnRGbHf3Vb6GOBpWgCoB4HirdXh8FN0sbH8B/J3QV38UDFemskhR3hGU+ttNd2Be433K5tHk7o4nGzTNniYy01FdO+eFgNAZsbokjQ+x6V556U68vmhz3DnlIGdKEkDAwyuOsvZVfSqb6WophitY4WzpAnXSqUzsXsxSANHnDgWkhJ1JWV3N9UpN0M99kCVVpnLfsuxmcvuTrLrotPsgfbUOs/Wl0coR+i6tN37EfE3OB5tGzaQgw0GpU6wZh0TrHSBMYUuGleoqu9r9BOassauvK0Wji8U8XTSJd2dhR28VE+J72qkfEejIjWnDXIquF3za07ODtPZ3WRoYNjuDCf7eNTOJz5H4sYoc8zvSR36F6LZ3J6UGx0TB+P3vjqcRg== 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)(52116014)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /FjlB/p7g7cEDaiVo6iRrh7piPy6QMGpL3o1N//x1MiHckANIDwj/KRShFWB9UlfVH6IKYzKxuQY2dMkMZ9uM3CXgXHjDjPHsgKLh+jlcLOBAFO0S+FWXnR+YhTQv5c+pN5e+xNx0r0V6a+/V854c+EP8H/3ydlmyWmaGzZgkWiGcTO+LtNLE8ddp5tg6PBx6L7inHqLW7Z7HXoWU4s785eaPHzDdNwLKHDMbkS49XCAp9y/QbV+F8B2+7T4d3GXZ/hjkMnRNeu1Vn3GvMEiSPRuisNtMKOjTUJZm76RmiDMpTV+i6ufSBTSEfsIpngOMSISQsw3xWGyf3+nJ8H27GSMhGOQ2TtCM3QoY2xHnybeJGx3e6THpIoi5Jwhxxm75S9zKxhbbE9nkBOQ2dypGQIN5YmiQpaaFabSpiQAj2G7UtpJlAJoZNfzZIYv/Jm/Ge4F4pekURLOu0J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/0rKzzSyS7yw8jFO8XdZBS1AhSVlj95arzl9enF0d/J0ENXnlBXA X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70e5a525-5a94-4afe-000e-08dccbf43a70 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2024 08:41:39.4418 (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: HB1RjU6gXPuOyOclPsR25n9UHFNZwnzI/YocektBUbcXEcbGhldYC5C3PuniuW5pi2OTVMqmHNl2fXu2N52rdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359 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" The current udmabuf mmap uses a page fault 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. As a result, the page fault 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, when creating a large size udmabuf, this represents a considerable overhead. This patch first the pfn into page table, and then pre-fault each pfn into vma, when first access. Should know, if anything wrong when pre-fault, will not report it's error, else, report when task access it at the first time. Suggested-by: Vivek Kasireddy Signed-off-by: Huan Yang Acked-by: Vivek Kasireddy --- drivers/dma-buf/udmabuf.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 047c3cd2ceff..0a8c231a36e1 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -43,7 +43,8 @@ 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; + unsigned long addr, end, pfn; + vm_fault_t ret; if (pgoff >= ubuf->pagecount) return VM_FAULT_SIGBUS; @@ -51,7 +52,37 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) pfn = folio_pfn(ubuf->folios[pgoff]); pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT; - return vmf_insert_pfn(vma, vmf->address, pfn); + ret = vmf_insert_pfn(vma, vmf->address, pfn); + if (ret & VM_FAULT_ERROR) + return ret; + + /* pre fault */ + pgoff = vma->vm_pgoff; + end = vma->vm_end; + addr = vma->vm_start; + + for (; addr < end; pgoff++, addr += PAGE_SIZE) { + if (addr == vmf->address) + continue; + + if (WARN_ON(pgoff >= ubuf->pagecount)) + break; + + pfn = folio_pfn(ubuf->folios[pgoff]); + + pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT; + + /** + * If something wrong, due to this vm fault success, + * do not report in here, report only when true access + * this addr. + * So, don't update ret here, just break. + */ + if (vmf_insert_pfn(vma, addr, pfn) & VM_FAULT_ERROR) + break; + } + + return ret; } static const struct vm_operations_struct udmabuf_vm_ops = {