From patchwork Thu Aug 22 08:43:33 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 821552
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 5B43619470;
Thu, 22 Aug 2024 08:44:46 +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=1724316289; cv=fail;
b=nGrleQYjTKgDO1DpQR7jstJ6wEg18aN+5D9AG8SmPWkurSuKCANZQVGqEID6h2hRpxX/Xdxs5vpY1ZMhk2H8UY69d0w2ovKZwTRHBGxDhXpwqedZI017SYe0GogY9xYZwTWxOn//9wr4iAzoXp0f9fb7D1K76tFK+qXRzaxWPmw=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1724316289; c=relaxed/simple;
bh=oiu5UtSSW8XH/h/B60o95/K2pqT/jsE+Y3eyQRJYuag=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=DnErvWFeWmcbO0BO73JWNTGnqbWnqxOAkl04aXv7+fyfPE0oLBTTK80p4L/WYC0cy9lR/weDDCEigHJ5GTHqH8A97gmPguGgS9dU+VKQm+m1pqJ8wztytaWXV0K5CoMYpTk6MKDQN07jCOAHB1jl6NXJn0kfCH3iDRgjq8rhhBA=
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=hw62FJPG; 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="hw62FJPG"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=U7ve0okPVbm2Kil/p7fq3tjecuZvkKVIsOjigvufAkRGadarjio5lGbllw58cU+NMml+Wm01mdrNBpbxzlzVq9bPZBq0h+LtmS66PD+IwEZ4xvSv0Pvm+tsah4Y/LAtBDJWm2+CGB4XZ0PEniS1+f/ihD6guLCLWG/QivBQoVBU1fjiFy3t2/xnbWDoAFuH6OCnbCdAhvOlk1FNK0zp9wQaGioE96Ve8WyqpkCKJU3eshFgfbisaxyljrBVACjv1u8NzWmUR2nEcER27DIIKSXSThOoROKI3V7NtM+otHqqNUDL34QUay8AAWE6Hy0W8MdAm1JO8gq8A8DSpPq5b2w==
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=nzuJ8J9ZQT1nrd+zYDpOnn3+Vmeyyfpx3zVmuuT8KuI=;
b=AOeeOReXD9TqoP4U7+lEsth+DDcawcT3J8RsaSJnAD7JK62sobnIqKTveXLQfHc9JKmdSlJQFjEv2302TAVcOX0Q267xXdfYrTqB7jIdJ3W8ekVzZYTFZB7VKzrWQRljydmOF3kfRmFXaxQC83nN7dMW8mHVtE57Qqnk0BdN+uiyHZZJmBExD5MRP3JrynyMNGnAqF3vjQKoUYhuyJxMCr0go07Drw0GIL66osvpXR4cN9UieJaLJ42iXGzhtQfske4/dacqznxZAq051ZKejvWdSKtJ8Q0Yq+HbTUmO+w0G4rp9kdVNS04LFAYQSiFXH03X0BvFgnrXsI/uYXLLug==
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=nzuJ8J9ZQT1nrd+zYDpOnn3+Vmeyyfpx3zVmuuT8KuI=;
b=hw62FJPGy7/wwxQnqDuZqiKBJ0/FarpCd/B6mBiWWMtD/nSl9PszJ0WiFguLASK1ipLKs8q4SoBy1iju9wqyN4r63uc+CvL+1eyxwUZZWrmTBHi4vndJ19iQXl57Zu482X676bkBJBY0b+FptA+DvSF6+MpusfgmHk4nF1QJO2EXdJoqZU9FRdkK4ZAACiPIP7f/IpBjhwvTlFK3u9kxr/ILs7qCtO0kCJIEzyfTS3qkgK1M4eWXJGTGOVsmdJOUpVcX/cqJpmCepXunHUzbWR2svq8dRj/rj+gsEzV1p/lgpnxBnAsDpmyXcpofArBJkPAPjrVLIp3u0uxbV7B7CA==
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: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%5]) with mapi id 15.20.7875.019; Thu, 22 Aug 2024
08:44:41 +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 1/5] udmabuf: direct map pfn when first page fault
Date: Thu, 22 Aug 2024 16:43:33 +0800
Message-ID: <20240822084342.1574914-2-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: 57638795-8c5f-41a3-c021-08dcc286aa2d
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: 8TcsI1Nq2DhUDZyN96sOmRcmZLOhJUqto3ybeZRrOEABDjFNnUF7thuNEzKjCP80ic6qK+7nMxRRDE/VOvUWBqih2RSFYok10gnn31Lh63QnjTI/UCSWTqTLPlryxf/EScnKVhpoZQo7AiW3PTUC+K8WJQlDMOEaWBp2Lq6zmYcd1eAwmyhkwYj+8qeXyjGaVFL3AoGQ6CQUhku/zMHRweP54E2XihjKi9pLisK10piK3qNMJigF9nFb2r2VLpgT3bQXfqlkbIFGUdVO/3ibarV5SNFwQjwwtZfcvQf50RYlNkeKjK7VQfVcmMLYf8aIxOCw709f8ZOEVO3AlR1O25KEKtf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PJIt3A==
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)(366016)(376014)(52116014)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: /jn4Hz8YfUYysaj8tuVOMVJ2WNEbPunMnmT7Oux4UktcICpClfQfFVaGxfVYKDrVp3PbbW5ROFa7mmua1quBtAsrAHEoyaERgXsadf/UxjeqqurXzKpBIw2E0HKTNQ1Z6DqAjMr1NtVOC+fA5scdL0TaZxV2zZbvT3oTj3x6S9fvQ0sDgQOnPxu8MeKGdRoTK+l8GyhXrcYvTHAfrmtLas5xkCP9WdqTr4SOTCrxFRJMTw3IY73HrM4SZYwunJ5ZUHDMucTCBvVXhsh1d/GRv2b/JqZhxkoI8HCSqAEno/kNlLpak6xdJefr3MMcCB2ugZOW892PrD3yaS4Rxwv6PbQNdROHSAGcGdIS4EPCW6IML1ZbbxvDzzybg/gwUvZwwwkfc2ls+qK5MtIUEFWahYKxkZkMMRs9AuIRLZeorugqPvigdkFPI3KANuvu2vRnCq7+17P4aZG8YOSNaMZqpEcsLtsrb4+HfYb7xDuR+ZxNhZnEqbpvnoaM9r0LAH2rAd4/dI89/AFKaQ08Do+eabnbzDL/UI5NWv280lpKQQR9X3FRQifLM9lLsvlevuvjxnQZlcnRKgs5M9pmQCMPifc7jcugXzKy0mdh3cLGPIPvskgxKUy0Pd0h0fsnOcO/ubswBgSMhOZ166O6SJhAWOETXJD8gsnT8a61EQBNHlcOGNdlHiPTX/oYkX3DPeI4LYpU+bzcEhbVijbs5wtApJBr2cffeDPGD4d3sCcjZKMfYArUhIXSLSktTP6MSAuLiJoWzZnFDGGXPqHm8NFlefeA/2odwmhRvRupXo3tFReH4D4esCPZ05XNfiIm7yOfrAx+y2x8ReLDBZj93STK8qDtSpUKEgQwO5zkL+UE3g9WwI0sAvjmMgGiGAFgD43L7nkYYL4ecUhr5igEXParyOplL6fMjnBnGVChfpFzHT4we80wsaKSY+Z0inRrd50gY3X4ItsDNE6txMiItuaZNn4UkWfqrLh9KWVVybrEFjgsmcNPoGp4JsjXSNcDaxfx1wjlMuHQf8XQ6IXKrjJ3vXne3mACINzit14LhotvpK1bzbrPW+jMO0go803SxhMk14649NZtdF005w9GGf09GkV6GJC0cuPgLCIH7HI5JO40vgYqJ2JyH2A0Dz99h4BUsHmz8JxyJSCa7tPQqZvtLNLhdJj4TFLs3fn9LkXlK4P4rOHtYUDoWTRs59F8i/jg3DduvXzM5X+GWXBO2soQG3oK2/C2gh8w92bJeB6vjcHQ2tPWCHZnmYLlgYiU3afWRH6Vb5Rgk+G1hSGlaB6Hxbd5olVnxMIb57XBAnP0Zgin7enx3AeEJF7M7SdM6zOVRutqrXXardKLyoUJSuKBtIn1hyO/+QNtbVyBoccC2iBaXba3TE9nH4rWmIU0rXfLzlzdFywNPwTr94w85F89i8uSAZx21Eczw8+naljtvyK5Sv8udZxbJnCvVZSVgVKkKQ3Ybop0aSlf90bPN6ull64YZtVq6dGAmaDL4yDIktNjUyKigqhvshkPt8DziAgp1GeAtTnkpoxZjVIKBqHgDpXXFGRdip5B0zkrgA8KD0VODcL6GusDvoehrUth8fSw
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 57638795-8c5f-41a3-c021-08dcc286aa2d
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:41.8227 (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: a0l9MHEH+zOwyOm3wAr5cDeLXM6Gx+svB5rGG2TwcNp219D8CeNUCpKThJdGcOu5BMJNuCHQJNLTRymBryLIxA==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB6402
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 fill vma area with pfn when the first page fault trigger, so,
any other access will not enter page fault.
Suggested-by: Vivek Kasireddy
Signed-off-by: Huan Yang
---
drivers/dma-buf/udmabuf.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 047c3cd2ceff..0e33d25310ec 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,28 @@ 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;
+
+ pfn = folio_pfn(ubuf->folios[pgoff]);
+
+ pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT;
+
+ if (vmf_insert_pfn(vma, addr, pfn) & VM_FAULT_ERROR)
+ break;
+ }
+
+ return ret;
}
static const struct vm_operations_struct udmabuf_vm_ops = {