From nobody Fri Nov 29 18:41:21 2024
Received: from APC01-SG2-obe.outbound.protection.outlook.com
(mail-sgaapc01on2078.outbound.protection.outlook.com [40.107.215.78])
(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 1C63C282E5;
Wed, 18 Sep 2024 02:52:59 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.215.78
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1726627981; cv=fail;
b=cswqS2KtRimllAY3sFnIhDyvJ/0TcV5o3Qi6UvSGvvmpmF+BpxoQ2ow8DBCDkeKGW8O/bzjMSkBiiUkZLXUtqbBeGB894bSJ0h3pn5g6fd+8yTaXag2CZVBzdtqX7bchgsP6LYIe2X52aToiOcCzIi6rFrRPOL1VsoxbD7sy2ZE=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1726627981; c=relaxed/simple;
bh=qxD06Ft1qUU3poiLBG7Ax/3h3dOz1OZtadfeRGHv4cI=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=tRIsqZXEC5wCgodM6/l5cDX6Ej0Dbo0wNoVRlAuA4zWF9tU+aduEDOZNjzMFJWHqZl397hcNI76ZWlmNci1PzT4npMGFI68BnGoDXh5Ev6VA8AUWiDhuKJI8iAGPpDdn//al57I6T5zTigKM/gEdkyui1/u+YNi/lIcsF4n4SVw=
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=JKydu68v; arc=fail smtp.client-ip=40.107.215.78
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="JKydu68v"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=lYRbzls+yOOUG2ViIrZUg70ZUE9GFfueluHI9uwmh2V66NqmOuwk62Q3vR7PuHylAjtaBRHD2kW2W4byEVQWoJitiwqskQQTXheNd87SanyN6cQurZE4XAmUFXOBFw5l+fu6G1yJ0yhp2fuHRXX8B4fIyMS/40RE0uTF94rqkKnUcLbp+ZqFOzYG7csZayE8+fdiZsjqMrLBArAkEYi9vRgPVeKL+c2Xbrjiay4jHyDJIK4bLI/ELmckMr4u94OSTQKKbFGaDXc8nj7VSRtKNvOFZC0EBdDdFFZEH1IS0L7vXvMtjuqxFLEE/NPDKNxzkWA9zsz3zWnMp4t+oYcs5g==
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=93hIlXR6rTCFIQW+5KF6L9/Zv17kVZyN1YP+CsH762Y=;
b=UQ8e0wYHxucCIsMRm9Goa9hgeMB+ZQXpe1q+cyK+35n8EeI+S5RTsELtbS4ELtF1SYkY7hTsMzvDSCUaDFqfUAYoOTvY06iI73H409L1w9ZXjQCaHeyRIHbfiFQ/+YAah0Em0IQVfGGMzc/Pv559xdl/rZvBR8c5agtaL40QeNcyDE2JhfJvMtm0vSlvkFGH5wnNoGLZ/8WLzebsZrHHydKg2Z0FwpeIqZRfWMUVXO8HbSIKHjFowi4+7aGIcyal0VzpY65zW4zUdX4zrTR2WV8t0t0+gtwP0kmnNjv0xipuGUq4YskRp5uu3cjq+F7fX189e0gwRo8RJeZRhhddoA==
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=93hIlXR6rTCFIQW+5KF6L9/Zv17kVZyN1YP+CsH762Y=;
b=JKydu68vwRA+Mkz93I3+LG17SlBUWoi690Pl+qTcqhqGwGZU9s9gT1yTYbrjDXzhFnjbEIFNAFBw0EYJh1y6q/9bo18RvsAVa+amofK8ztoe3c2qimiBrHJAVoWIzdLeYmfgodHr3tKCpFINaukff/Qjcvixu80JP6tIk5pC85U9j9gMb4wUuWTyW5nPRLuQ8p7mlSXpwDh9Ba7T9IRsoIJ4d0OR1YKU0MxTLsUXFDTpghTCmwikre1TUCNg47Ou+Q1v1P8WFAeGHG4IcBVKC0OpYJmU6SCeCVuk3C8fnPgo3kH79uKeu6FTvwAkwKKpLteQiSFbNVMfNSK+N9e20g==
Authentication-Results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=vivo.com;
Received: from SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11)
by KL1PR06MB6236.apcprd06.prod.outlook.com (2603:1096:820:d7::11) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Wed, 18 Sep
2024 02:52:53 +0000
Received: from SEYPR06MB5672.apcprd06.prod.outlook.com
([fe80::2f0c:5cf2:abb0:d852]) by SEYPR06MB5672.apcprd06.prod.outlook.com
([fe80::2f0c:5cf2:abb0:d852%5]) with mapi id 15.20.7962.022; Wed, 18 Sep 2024
02:52:52 +0000
From: Huan Yang
To: vivek.kasireddy@intel.com,
Sumit Semwal ,
=?UTF-8?q?Christian=20K=C3=B6nig?= ,
Gerd Hoffmann ,
Dave Airlie ,
Andrew Morton ,
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 v7 1/7] udmabuf: pre-fault when first page fault
Date: Wed, 18 Sep 2024 10:52:24 +0800
Message-ID: <20240918025238.2957823-2-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240918025238.2957823-1-link@vivo.com>
References: <20240918025238.2957823-1-link@vivo.com>
Content-Transfer-Encoding: quoted-printable
X-ClientProxiedBy: SI2P153CA0014.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::6)
To SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11)
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id:
List-Subscribe:
List-Unsubscribe:
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: SEYPR06MB5672:EE_|KL1PR06MB6236:EE_
X-MS-Office365-Filtering-Correlation-Id: 7bbf6e02-177c-406a-0513-08dcd78cfd44
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam:
BCL:0;ARA:13230040|1800799024|52116014|366016|376014|7416014|38350700014|921020;
X-Microsoft-Antispam-Message-Info:
=?us-ascii?Q?pq8E/VnWpdN/DcD+4hGexP2XoLgjF6CWYYWxe2LSWAkLvzLydxl53zlBW+Kb?=
=?us-ascii?Q?xQBV8BybCCfE2ctSs/58kg+zQgH5vPeTyc41dW0X29YCRNi7dst0Bi08rDsc?=
=?us-ascii?Q?Jom1xwDLJEzQiko3N5hD3cGRr1d8asumPwBQFEQz8oiTxk7gwD0sh7EqM5p4?=
=?us-ascii?Q?DfOo3YT4Wuje5YOaPu7P+ycD+lFrnRPJU7uPDvzb44ho2oWntPczSTZIX3n8?=
=?us-ascii?Q?RsFeKV6XTwHbrBrWHEYLFmU3WG5Sd/dX2bJ7SQ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?URuC1fGDLGdSuEJjfjM1rnUveSGFgr8nKDuw6/TnzL9NjCiTmShB3rVfXwK+?=
=?us-ascii?Q?kSqaHvgxbuicl2DcUzA2YZVDhs3zQ3twd9H0boiFLuCbZAX+1E96o+CfftVR?=
=?us-ascii?Q?/kr4QXCwd9zpzpxTplQJhy5ahXHFumTc6vTJEgAPSvlOhN1+0MvjoSl8mfO8?=
=?us-ascii?Q?kPem4cGK7u/D8ESA1Ub+rMLIbCHGWZ/BFYMKBb7zeUW0rFJGnrzESqmsp37U?=
=?us-ascii?Q?qkRbsGJGeUQM/u2omJgYFdTP8BQZWPnx1Hb67JSKN0MAojQjrEpRj8x7NL+h?=
=?us-ascii?Q?0NmrW4mg84U=3D?=
X-Forefront-Antispam-Report:
CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEYPR06MB5672.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(366016)(376014)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
=?us-ascii?Q?XmldueXiy6GACmwEMo2M/9KHeHrVzMA+6ngOxi3BazRGuLtOGLjlkUKwlQr/?=
=?us-ascii?Q?ItXhyrwWtIkWhEnSi7nsgihct9MaUTTinhN6I2MXKz+JvaMoNdorQQU2obMT?=
=?us-ascii?Q?iqaFeQp/taT+tGwMOe0sXAC22gjsNg8eutgs+l9vPMHHTx2ur7/OrqlBw763?=
=?us-ascii?Q?oyMfqRwGNiym/3lfGzuW7q60VbiWgU/aJbJgKbHDJt74ycVVjGq+rGUxrGXT?=
=?us-ascii?Q?Og7b0ZsiENCbIBTV2rPU2DlcPbOntIJ0FKlqR6KuzhIBQ+6GTkB6muo8Uv4h?=
=?us-ascii?Q?04Xi0oBSXVXXOkJpzOlj6daLdAtRht7zSgKElvs46kblGq4fmI5fY0t8nQzi?=
=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zRAJfzc40BK9Nzw+zI9dw7A4+Zsn+uf7uIOXjH4M9G4ULwc?=
=?us-ascii?Q?3xRf5BVQ2xUa4cOXf3xl+8JUSuMNJGUQgXmDgPaVFROuWAjFIEOVmo4BxTgw?=
=?us-ascii?Q?tldbQuVWkSBWwEwB1/xWVyDkmpNY7QJAedJrwQ2CboZNkbxefXXf0bHfZG6U?=
=?us-ascii?Q?JUa/NK8WKkxotX4hwuMY+2laejbJ3YVuyzXYOKJoocfzmBDOUxyXidHkEezq?=
=?us-ascii?Q?uTByzwGmfQH3O8vDtadXAvNB79O639Pc9opMQxirioylxV7/f8mYDJIh5Rl1?=
=?us-ascii?Q?tzImDtyD93GOratT0FqmN/TDVkys+eRn+9zYkLYtol7qzV408m8Ox7rO6NJo?=
=?us-ascii?Q?jsnP64lgfCOuNEFowAUijGVi8enmJXJxkJOHCdEv?=
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
7bbf6e02-177c-406a-0513-08dcd78cfd44
X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5672.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 02:52:52.8498
(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:
2We4XLip6P05NPhjUcmG4NMgv4O6v4NWDKqVIbkt1wosygGCwIEm9ylhJwOxAE/w3jJVhtnq1HfZMQ+gLSc8Tg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6236
Content-Type: text/plain; charset="utf-8"
The current udmabuf mmap only fills the physical memory to the
corresponding virtual address when the user actually accesses the
virtual address.
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 the pfn into page table, and then pre-fault each pfn
into vma, when first access.
Notice, if anything wrong , we do not return an error during this
pre-fault step. However, an error will be returned if the failure occurs
when the addr is truly accessed
Suggested-by: Vivek Kasireddy
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 047c3cd2ceff..2170d975cc76 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 =3D vmf->vma;
struct udmabuf *ubuf =3D vma->vm_private_data;
pgoff_t pgoff =3D vmf->pgoff;
- unsigned long pfn;
+ unsigned long addr, pfn;
+ vm_fault_t ret;
=20
if (pgoff >=3D ubuf->pagecount)
return VM_FAULT_SIGBUS;
@@ -51,7 +52,35 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
pfn =3D folio_pfn(ubuf->folios[pgoff]);
pfn +=3D ubuf->offsets[pgoff] >> PAGE_SHIFT;
=20
- return vmf_insert_pfn(vma, vmf->address, pfn);
+ ret =3D vmf_insert_pfn(vma, vmf->address, pfn);
+ if (ret & VM_FAULT_ERROR)
+ return ret;
+
+ /* pre fault */
+ pgoff =3D vma->vm_pgoff;
+ addr =3D vma->vm_start;
+
+ for (; addr < vma->vm_end; pgoff++, addr +=3D PAGE_SIZE) {
+ if (addr =3D=3D vmf->address)
+ continue;
+
+ if (WARN_ON(pgoff >=3D ubuf->pagecount))
+ break;
+
+ pfn =3D folio_pfn(ubuf->folios[pgoff]);
+ pfn +=3D ubuf->offsets[pgoff] >> PAGE_SHIFT;
+
+ /**
+ * If the below vmf_insert_pfn() fails, we do not return an
+ * error here during this pre-fault step. However, an error
+ * will be returned if the failure occurs when the addr is
+ * truly accessed.
+ */
+ if (vmf_insert_pfn(vma, addr, pfn) & VM_FAULT_ERROR)
+ break;
+ }
+
+ return ret;
}
=20
static const struct vm_operations_struct udmabuf_vm_ops =3D {
--=20
2.45.2