From patchwork Mon Sep 9 09:18:39 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13796500
Received: from APC01-PSA-obe.outbound.protection.outlook.com
(mail-psaapc01on2069.outbound.protection.outlook.com [40.107.255.69])
(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 615D71B2514;
Mon, 9 Sep 2024 09:19:13 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.255.69
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725873555; cv=fail;
b=YNWmNBRN7eCYkr/DHmhd/LJ4VS8KcweBcESkRvGUyAHkuiGCi+RCZHmN7f4oNuje28NLFR2BjkOT14jkv4EX9akGST2mBeDh9H6AsoEYv68VFwouRGn6nkp+RmgJzpt4mQojLsL/ay6zG0nBS+SXDyrPVz7sz89E2jse3ad4vfU=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725873555; c=relaxed/simple;
bh=qxD06Ft1qUU3poiLBG7Ax/3h3dOz1OZtadfeRGHv4cI=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=s5FB+ft0RSW/7WVPmCeeLubL3RGVune8er36KFfcoYu3gAsGgdTwZLG78VDmUxaBNzZzVXIplu22J8YzeXvsP3K56+7j7yqK04mYtaDzbpuVF1WWRZ6fkhIP4qWCW2uJoDr3Gix2jV13OvBpPzPBS4lKPzOS4GiC/iQvVPbTGyw=
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=fSpub4LG; arc=fail smtp.client-ip=40.107.255.69
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="fSpub4LG"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=VK+Sypy38ttK0ZDJ6rNgFj10cJdcw+TKFH9Eeq2Ifotev3eqbpd0sZjrgZ5DlolQ7V8fLdMAelnhG0F3ND87a/QxUwOBIpORXns149VGPo2uaY5R6zgwDQ8r9V+4VDCx6IgCnBgA5y0eDI5T1yzLTY1XgYhmGYIVr36GSArlRHoaJAporaGwgIEX6/6ZNraJ0NxLCOfJOhdXMN5btKdoGPmt7KBvA4K2WBvwBzy4GWZVi607fKP5KHEFrchWzawtaQ2SUp5WHvcya957V3BwDf5DZh56q0gHEQOhim0A3BqSvBSLiJ4o2lKyAYJgZW9fkKbvcRVm9gDwcu+KxiO9ag==
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=IBJq46i+MDJIrHpwc8Xbk+MqNZThsVd6uFadfEfiiHTw2K32sdOA+fYu/VoSdxZWemRrsO78erN82WKy5+a8DmgYWigjKFWVolCQrb5psdqbEt1w1frldnAazxXvJ8AOXkzKas20yd9fxw0h7cVbEkc0IOKpbzW4nTLsxdzHTDBuLDJhIoCnBDh3gNYbkKO61/yU29gSskLWZdPLDtjSzsmMXACCT055jfQxXvr7EwuUJa4P9Fh4x0YtUNCYDUGQqUPcuLeDlN/4pdfL8q67Mr8wHIZrRizDebNcQse05ICLol9UibWsHpBYK2SxC90NmKWsTS4uV8hrrnBWLxDkOw==
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=fSpub4LGlr02q2ajoJGRIOQOcZ4PN18Ph2nmDzUv8xbLsAUl09kjLmNUhcWUIFQykTiQQuU436Dj67t7UNXdfR2PcxtNCo8I59zgUgO8g3cHKKt+9z05OlVDIjSNXDd2Lmbf25Zk3ziLBOx6zIk9ErLXVkH78jULcMecoeNftyA9xeQCmLYMjjbaYSsbVKRo73wa9vY8cPhOK3H1JBVgesuNzIPHJhbfIyrUnF+9bOfxjaGIxL+xYoTM7bbN2AKE1xjYp6R0k/F8pKJUolHM5c2NT0fasamHdP1DkeYPLscoAQ8Nxu5LcqU9xlXIca9xKhRnLodEtHAV6sJdSX+CNw==
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 JH0PR06MB7180.apcprd06.prod.outlook.com (2603:1096:990:98::11) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 9 Sep
2024 09:19: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%6]) with mapi id 15.20.7939.017; Mon, 9 Sep 2024
09:19:08 +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 v6 1/7] udmabuf: pre-fault when first page fault
Date: Mon, 9 Sep 2024 17:18:39 +0800
Message-ID: <20240909091851.1165742-2-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240909091851.1165742-1-link@vivo.com>
References: <20240909091851.1165742-1-link@vivo.com>
X-ClientProxiedBy: SI1PR02CA0011.apcprd02.prod.outlook.com
(2603:1096:4:1f7::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_|JH0PR06MB7180:EE_
X-MS-Office365-Filtering-Correlation-Id: 547b8ed0-d8bd-4b8d-bcae-08dcd0b07595
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam:
BCL:0;ARA:13230040|366016|1800799024|52116014|376014|38350700014;
X-Microsoft-Antispam-Message-Info:
xWtUO1kFD8OfMwP+Y4e4HIWKT6VjrQCt6X2gkAp69MaGV4pFiwwgGu1Sl85LVrew9+U8RqvWyKfC6Ho5BsUlX+D7fm6wB1z8rFkqpXXcthPaCoSIzlcwDsoVJCv3kdbYIgntjKfxVu0L201WIBWw9B9j91A2YAOwrz8yEba+khp5UHKn4D0cB/hFXTAOve9W8zO9cX3HvUZK3QHGOjHprKXO/7oGHpN8nOSPYCkdEFxNnOHC1f6yr79KCWOGXlaYRNuQEDCUho8GOtzaL4pw2QLGpWoHj9PAVi+yhqNMi3ifkUpQLEAMFWhdD0cdel9g7+UMlb7nHyz44BEWd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/t8xrw==
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:
fpI95VbIck56EVrOyABw7n5ijNyOBQ+aBg6AsRrb0hcQ3qQr73G4Biw5YHHnRPtbhG/pNT/CPClHOz2kazusjVLFm1OLqWck8M4O/qSeRF+gHlAFWT7GRE5yU3IrFovVl7YLFWZwjiwvKtCHtZjN79w0/6QiNAwNzt2tHfDWAhugntuoqhh1fqaH0a9PvE00zzaMNyzcbia4G1JiAYq+tnTFU7Ll/9fxqxq++ENeP8gNZKZhrcL00gESDRSoPwRFutuKICQEVcjWH85D0o4Pce5zCloLav7VcWj0v6eBVhOiP1kfgOb4VfcGwxSNWVrD+t0UvDptNvkYVYBrYRfAJgXEY7LTRoNcv+KAr+i1weLnvXyv3PLwiNXfJC2IVRF65loJlYD616NYhlBLO2DWgeyYItqlCPQTH5drhfyr8VcrHd5h5wH5VRpzvHI/pGbSQlCTjM8xrXe0Y/rDHXrLjVusyX1udswgDbpfOhNWKzkIK1p2JoyqWVioxNLiB9mdnCLN4BjQYDeyBUOE5BWar0FvtXHIZ3RUSgOs4ke+S/Rgps6zRe2OeNIsoe3hI5SUNRFh0xWzuHqlKXtgiwZQZo+QRc6glqM6D+FjIbHu4oQtetaoC9wGfInhGS2vqustM07dgZj7JuJ8qaFCy8uKJv6E/LgyCbtDgVuwkhVlAQV+tUzOCb/kRLKAnRcrKVMed79dOE+k8B1Cb99fu5yZVYaoAGcRF3VnzVsq119q6FwdR0KrHStUjZkvM9xrLEojLkbcmGQOtRbRAVOjzE65cEANAQItwNCIPah/LUXt5Takqg6i8XJTsEeBRj/oBPWbxGRpQFo/iR87mI4tkZVQX16Tl+3J2ljfYHhpxw6WRsZAJL66+spnA+OWxKHEShh+TTKN9z4eYtFelT9BHaiwolGadPtPevAw3QFM/uSt0Qp6iTAZ8/l1XRGbDlGcYO3DL0vpFNs64/nicNRQPBoIY3nF2bI0dnDd6p0Ay0VT2nRsVhNvGzwIcZjwW0YYLE9l0l2mFB4Trs1cXvIu+xKuWiLcT/wZaIJSiSU9aXpsWKYPbpAwsjHvnuvFlAYTsir2Sad7HEnu/zE4m3UMIBxLwbsVfW3aTK1EMb22jgRMNhI9n0abwE/CaxgaRiAF0G3VaVXgInt9kLMQg+sCCSNLe+0CNFvDHRQEB1vaDVgJrTZRZj/mt4JPqWZSto76Gmq9ArpEzftIW4Lvqq2f+8fbesCTKiPRX50Gjr1+V5qTAVmlH+6vZDHsP6yVZsOuUgWwy7t2tqN8E35lRRCOeWPwTODgsaO2X0kiWKjW1roq7iPjnzV7NvDbfvmz4JjsO2u0qwc5szfNamDrOeH5916iumW40Eq48q1+k+pQ64WHQrlNXUmtpJdvUIk6jy/rrNWQ62dY982y5aesTW382YaijXpkxoMiD8LNfDaZ5fbRMnZlMtlNyRG9C6/JGNyIWswr/QnjfRz6cdUa+jZ4ZwWE3VU+fcJaD46agK6e3CfPHR6+o9d3QxKqSOktpyAjteVJOvAKZ5KCw8fcE6wybNyJqAeWikiA3XCqp4EGABBuQEvdOtJOR/gJ+WoDBQE5DHzS
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
547b8ed0-d8bd-4b8d-bcae-08dcd0b07595
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2024 09:19:08.6705
(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:
5DwNIy56TfWgpzjZsGXBrx6oKRF2yIxXPX+heaJy2srxFJF0R7J/hYghXJ+g4OgdVCdpn87rCzbwCcpodibVqQ==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7180
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 = vmf->vma;
struct udmabuf *ubuf = vma->vm_private_data;
pgoff_t pgoff = vmf->pgoff;
- unsigned long pfn;
+ unsigned long addr, pfn;
+ vm_fault_t ret;
if (pgoff >= ubuf->pagecount)
return VM_FAULT_SIGBUS;
@@ -51,7 +52,35 @@ 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;
+ addr = vma->vm_start;
+
+ for (; addr < vma->vm_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 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;
}
static const struct vm_operations_struct udmabuf_vm_ops = {