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: 13788298
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2066.outbound.protection.outlook.com [40.107.117.66])
(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 13F4021C160;
Tue, 3 Sep 2024 08:41:43 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.66
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352904; cv=fail;
b=taYq9+DWdNQHCZXTtqIPfsCcLpzdDTThNYMULRCiOl5k/vyqR3a5BG6g+43S4im9FSwiplJ0MFBoyJByKQ6/lqfpy8yYwO+L82940nmwqijMG79nFBl0RA81hQQOnIPPyrVzt1y+bs0IldkHkw4ueoJh40sgfnlJBqceKdMBjzw=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352904; c=relaxed/simple;
bh=MJh9qeeM0oh93AJXo0IjTavN5Bi6QdM4YDnD7nz+HFg=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=LvJihidumNAPDmz2XcT0gIcVWzGii8/JU1Vr9IKELl1/J7HLhBvi3aZOhN+1u/+dDxomCv8UQqxVGXqcu7rXZEuJJOVFyDt6sP2KyPCpGpp+a+GGpE/mwl6Ie89cEs8MXwev4AUvmlVUddDd0uPSL0f6OSWWYBhg5YlKD1hYGGQ=
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=Fv/Upo97; arc=fail smtp.client-ip=40.107.117.66
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="Fv/Upo97"
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)
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_|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|38350700014;
X-Microsoft-Antispam-Message-Info:
n0bbmmjkjKt4uVm/XCez0FN/heKCMx0xc+JjlaHzB6/DrqsP3B4uHnOzrPieOZMu+dm/X7/MfNYWA+LuAuKU1pusLoalZOYivwf/w6Fpre8NBKMx5ruuGLQ1KTWCTDecNBeimKFjmJLYAELIRHZ1UjOs9CiB8bAucBE7OYEO6IM5yH/2Q/HXxkonAYMZTZ5/8CtlCopSjw6wQK1DszJLgxEukJ5WUJV7Da5yGnM5uZVRSvD44h4P1JdEHX/KLEVAUSj4FEkp6pu2g7QHLwjcr+95yEdkV48Dq5fUpyUAvk/A6fv7seug9kXLOMl9yu9RKgE34y04zWUyMgFTTCRh7cJtJ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vjqcRg==
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/Ge4F4pekURLOu0JmEfyX5KOSnwEfkwHFceqiZFgM/E7lhWi9Udgwx2IkNruG48osmHEDihLgxV3fp13Yyli74HW0MdVyXor+aix38TrVir2E2iQxGPk5KhqjTDoqO3ifYOHd3P7ghNEWNS+BPqwuXcXgN1gluf8r2rO4ftkTHukThtyVvVCM9JSxQd6wJnzwcHKGiyRTrUKuGAWdGxfhGhFJXbQnol+YezCvGnUaBbSDXLH+Es04onBaUc4FX2fT4P+nXm2s0WCYam0oJB9+XZYInA3lfhr6wU72P9FHrjqbnCw+PT7sYMWApB/8Wu/FKjSWjqkrmoAYEbYw1SWs+gE+JgKfsIEVf89SVMUUfha1CDYij451f+BC05B7EOrE8X3lSZFd2GtNd7othV5o+xw7ZJTT60hNyOEeSdTjncTc6II7sd0nhjrtEpW4sCthh/NeBnft/Kn0ucO2lxYizAU5+EkqMOjaFXiLzUI1+0nbGwY6y4PA64PlFW8VMeH7vSQfEKI5/v89c9Q3q08rzqjIrny5daNnVvFV+0IolCAaxJh6geSSXqzcznYPilxuz3LOotWNxa1HYzatVyg18W3RPzW1Rd7RSk/lUtS23+29xbja/2sfVwNcx0bcceGWhvnkewMoqbZTUwQ0mtjQHFHsb6vGzSGSOY5Zuc61fRKl9iJ7ek1QZ5pwJHTElwnguMhdR6zCQeAlh+3Aiuoa9f4SxAIsBCquthnm2Urw6bay21KHsWBC1Lhwq1tMarwex0mFwqtCKWXtN8CGyHXaSCXPh7sCf6M53H5NgLlTixoU8kF4MVjC24ZBOr0SpdEeKpwKeEfzlYn9mxRbq91MevXqm4KmkfODFnVve7SPV6KMrCmtpO9pzlJE1pOjOzZ7Dzs+udUkKT6WzF32AMaX6osZMZFrhzfAe1oix7CuPpjKPWyPyVp5Cc+i6WlnRKiGAcIm25l3ZxKvRAFC/K4gNxKU0skuBBI/Y94qd0u3MsUl9jBw9mSKagGIJmTG+Yl9sk/5O+vt/inYJdhzcNBOjd4OcEDSBFm0dEtArt1v17vHy0GmfEvuX+R5SM9pvaJg84i3dJ5Y7J0i/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
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 = {
From patchwork Tue Sep 3 08:38:07 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788299
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2066.outbound.protection.outlook.com [40.107.117.66])
(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 E36A33DABE6;
Tue, 3 Sep 2024 08:41:44 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.66
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352906; cv=fail;
b=NWvd+xHSz2rQfptdbHESipfyX9/ZEIG71kzrg0rUcrU04FA1+vHLFAU+Qz7CYeB7mQtLaXSlMkOYD8XlCAi6e/p2orcg9iS/ney6to9ss12ep8JoPRrG+ObAxIF3DlIcBO36yj287L2RPxKcmNqWDkxTRABYEzNUELW8tgiCfDg=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352906; c=relaxed/simple;
bh=F6hE2Hob1C9OH63nyEve8jtrlhyVSXG0qswWbVYVbZw=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=okyxkFbD1NSnqwZhM9f0M+xk9PGVs96dyu6sHF8v3k/VpSDLr0Fwm7hjDm4AYvAcnZw5kjJaNtW5qLJzdZKwJI46QpljWdoEMcqAI2u/CoNB5N94d22Q1V/nvQ7tonPQmUHbQvwLA4jntQlZPBjQgvhnrk1x70C94kmCVi4bZVY=
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=DKo6Zlde; arc=fail smtp.client-ip=40.107.117.66
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="DKo6Zlde"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=xxUwp1yEyUK4EvgQBLmQydU5conZpMlQMisXkRqV0oKQ6s06Do3A1dBF8hzl23z/WmBnx0jJC7pqirQ6WDl+1poZOtlZYPvjunTGBwYQIsoYvG8Kfbbozg0VKAFT9uN9D7XBsaP3Lgbl65yQ1AFoKkiQiBOeRepfed2zKnHpfPhxRtStKA/RUgqQTARr7g3awiDJjVUP0BgHEGXKt+0I+H5cCT5RK+McwHQX+XZGAXew1dhLtjkrLq2KTEOr8CORs5Loqzxlexg6uBz2P3f85fTuXSTY+OJ9DwAxnzwdAabAhtVSfUWlfTrRO/SjSQ5nIsqlM0OKMdQv/8DxT5OlmQ==
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=XIEQ3rlqzNJaqDoCL5uRxsy7PyfbHUkPJ0IE5caIGbk=;
b=v97dTY+2fAGsKsxuqH32jPbAz05RyaQbSpTys4aqKdxoq2wFoCpY9WvhQT62EIL9AHwzt1qQHjJYeamLYSmxltUjhwYqbCyZhLnqzBhljim6nT21XCVtQLwV3Tv+G66J74mzOyrzMkQYTSeQrZU/gzPQqHscHmjVoSP357n1LQRNTSe3BCIwWXa2kuHxJO0AlWu4mwHC4oiiEQSfPynJl89zgukqZzfSvmVtX5A4RczEMsorZDr/nl+y/OoB5UJoBucxOj1DxzbQQ6E09J5Hj5t75Uj9hqMDlrGdayyOCYFtzd1RUOvHJX8xFdZJefH4UZ9Ok91mBGZIjXhM1CdXOQ==
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=XIEQ3rlqzNJaqDoCL5uRxsy7PyfbHUkPJ0IE5caIGbk=;
b=DKo6Zldeca6M9Gr6TObpIlaYiD92BMBwP8YEuS1CQpuIH14O33znoJAxmEYd23BBs/zUUdoNyfFwWc61EoGHnznr5kjlfq51Y6azMnM1Wjei/RV+4ytt+jNzySzknMM0QpvCoJi1neKQ8KpWk7Fn9Ut7EO2bfhTlFnLhIcDEU0t2UUBfLBhsDywkJtlCsi1hcQFLWVU7aOaA1TppFJ5bXTBTe6f73BYz+MnLBxXlsXllLJrrrQGZdYMauIQFZpT62EXDphVA6gTyxj34qP7ahb/a9hKL5QSXl7zkiKeGInu3rovytFC3KANM/x7IljL0UPdqt72tfo3US8Ecr8xORQ==
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: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%6]) with mapi id 15.20.7918.024; Tue, 3 Sep 2024
08:41:42 +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 2/7] udmabuf: change folios array from kmalloc to kvmalloc
Date: Tue, 3 Sep 2024 16:38:07 +0800
Message-ID: <20240903083818.3071759-3-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)
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_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: 24b1f3b8-3626-4974-a4ef-08dccbf43bf6
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: =?utf-8?q?SkS8J/paByaM+cBmIQRuXGjd560QPc4?=
=?utf-8?q?UqoAHq6qcHwVabl6X1XUgiJsjfeF41QP0bihOtZ2A3B81/SxKiAoSvx3BoimFtQlV?=
=?utf-8?q?p1xqfGayx/tUQGWyny+p0qTM35HXBP8m2OaCm0s9NGfiCtq/hQhJWYcCP1ukDwPPW?=
=?utf-8?q?RSmt992bDmz6zGLKDa/8B5JS8tHqpgZ0QX1fcvHvQHE0CCPMNb+rGkOjNzGxtCJ3t?=
=?utf-8?q?aKzHsxfE6WVaGx9GY9gU1x0KZFjRv1A5mYXOlw4HA9VmieZlMfXvdDtHliugXpAL3?=
=?utf-8?q?zYSRP5FDGkAJhKVhGC+SwL0umFb5mm6m/HvJDxXfuKUYiHB6DEQDcCUwlDhjewS/d?=
=?utf-8?q?tLmzdJiSYkcumVHPp6XOUbOlJ7JBpj9utvayQehzSrYUGZl27D1XBfI3MpUSS2zR8?=
=?utf-8?q?U2X3m212n0FqtG9yHkeXqmg7n+g1b2mM0YHE4hwPZ8r9cxbXEaicAOAEje5VRaAl0?=
=?utf-8?q?Vc03XA9u8RtRVSJLv87P9Y/TxfKsJQtJsfN/Au5SPgUDLobnRTw1l79jWCrK9kx1+?=
=?utf-8?q?JOArJkmdta+keL6i02abVB2dzCswMiua9/lmrqVoISc+UhbRwTIPstRi+/oNQRFvq?=
=?utf-8?q?TMYq9ZOTaddqSg9nEddG4Y/g+ft4CSqh0A65PBVzdaL6wAK9oy6XZhjYIjsIoOUQt?=
=?utf-8?q?Pf8vz5C6tKunJERYoCQ6wnws7a5NJzwqZjqs+R56OruhuddGJJf9Drvraif6q5RPF?=
=?utf-8?q?yhmh9U8YYBjTsi5tPH4YA3BnRa41P3YgHoYVKat0QgmHj6xlGwBGZL+f21cD7DiAD?=
=?utf-8?q?aMlL0zv0D/dqqAYX7CRPqWVb6h3YLVJQLv1BeQ3o0wp5zyEumNMZlQ03eKXGZKvWa?=
=?utf-8?q?RVRmvJdGMlGE4eE8rl2mGJ4waT1TGhGwqf4+4PYdsRj3jILl9EQS4FOXQt2+74dKh?=
=?utf-8?q?f3bnPkoojgNKsRlwFjgW0BIuaVR7f+xtNXE1JEs5TJ4pnPJk3o6m1XVDkW/vMWn2f?=
=?utf-8?q?2qTHLBv9pMoAeIUjzxLcTmIMlEJyazN/aA6ysU9jJSfnzxpzDXtIfi3gFFOUkRrkq?=
=?utf-8?q?tqTabDRFT39zPQhJw1QsimwyfdSmIAVMZ9RntRObyzHndqUSxNDECEhLx5a+8DvjV?=
=?utf-8?q?Vgj8x+t3r4d9+QZ3AChWAR9CnzMTPo0mXf1shJQbOwUsuHbEH2qg+uZ40FDys+mBa?=
=?utf-8?q?UxXBoYrqalOmsNJ1ocRy0cxH/sE1080j3N9c1YrR5U9BPXdDtY5sSk7F4b/USYngk?=
=?utf-8?q?voy8yOVYG7WORxepa2+PzfgkfYqBZ2Mc9zKvyiLQOPLyPCjfFPaHQCN9dSrw7L3Z/?=
=?utf-8?q?1JpR6MqBEZENp3COuq8iMB53Brqf/aFN+PeCPSH3La0lEa+82FUp0ZcPle7oEqhKA?=
=?utf-8?q?q++o2N7PA1TWBv5qygHtGUf6UQcBhLUiSw=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)(366016)(1800799024)(52116014)(376014)(38350700014);DIR:OUT;SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7UmduumG5r87pyB62W5gu9bZ3zO8?=
=?utf-8?q?ss2Rkdjw9rgHmQMNkK1ZmkrQz993x2itt+ohX5xnLPB8WjjP3glpuzb6+ZIcxvSes?=
=?utf-8?q?JgFh8iRYXb1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z307Pt3u7D83OgfldPckAsMsdo0mc/w/82yOTVtXcVREbaBcmvmfcPxUwe6eLPY66?=
=?utf-8?q?I5B51kWERCNUSb920ZkRSAiZyz6FbiM7pCNmeU5txmicZXeGMyaDh5AhjeEjvqIOl?=
=?utf-8?q?PwAM0diGcRR0bsauLgxGDfUvIGUMZO2qJtTnQJ5xnVvLThbF0s1dCXkYjn/7Le5IH?=
=?utf-8?q?8x/YTW/ff44HK/Sp2SOUgicdQXC8f7kTAjo6aGL6qlPxBwY/X91S0oFqijYiHsZVq?=
=?utf-8?q?kwIocre2jqynbfCewyMEja+KKBWYw6ZQhp/ajEB4Qs99cuZZywWoQ/e1c5w2CoZG/?=
=?utf-8?q?99UXb/Nvmc7rZr7gK1px9Pzlk0g1YauTX5B9f6gx7X7M1o4fa8N9gVlFHQkNQFNmw?=
=?utf-8?q?PXHXbffK8M5TBp4ASsxZVDouUpyHHWtW2O6II9W2KRs6Fn2SQ/Z50VHQ1clO/IqmO?=
=?utf-8?q?6ljyzdj6W37/nq+bhh4df2ZtDcXuU+4yVlsRJwl5GnodJTqMcptDyT95RmONXPw4g?=
=?utf-8?q?LNOTMVrzq+kI97hdlSVBZo4YGOI+DRUsCr9kuKTEIoPWcwur4pArDIidlWnMD8mlj?=
=?utf-8?q?pL8Dz3sKH7j5?=
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
24b1f3b8-3626-4974-a4ef-08dccbf43bf6
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:41.9549
(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:
Dso8+b8AUVvpim3qBIORCPxeiASKu+ZoOqQQ3vlNwrqx2unnpJtbbe5i7h9dBRHnte/0RwRyIwyCF5IT9IL1ew==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
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 0a8c231a36e1..789fba312a68 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -111,7 +111,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;
@@ -119,7 +119,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;
@@ -227,8 +227,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);
}
@@ -353,14 +353,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;
@@ -374,7 +374,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;
@@ -384,7 +384,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;
@@ -413,7 +413,7 @@ static long udmabuf_create(struct miscdevice *device,
}
}
- kfree(folios);
+ kvfree(folios);
fput(memfd);
memfd = NULL;
}
@@ -429,8 +429,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 Tue Sep 3 08:38:08 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788300
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2066.outbound.protection.outlook.com [40.107.117.66])
(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 EA9913DAC0F;
Tue, 3 Sep 2024 08:41:46 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.66
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352908; cv=fail;
b=EI5aBC3h8tYxon8+X9eeQTPV+/goWB8iOxJk1BPm123kq6W4EuVS9qTPptllEV+C/QCAucT8HEYiAn41aT7gs/XFmINtu9aD5LUh7OqccRyzbxDuosyZ1J3rmzrZU8yLAkPQSFMbWBV8Za+ddwzZdDF0MhtlWIjSCERlt3yBYnc=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352908; c=relaxed/simple;
bh=4TS1H5FaunkQIN3UyBznmjJzf7LO9AMEA2xM2LCIGz4=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=ecHnWoDmCFJTtqd32rJDlMHI3GXxFhVAp1GuKOR1VWA0zoyuDbWs++A2r597S90iNQeE4E1lFZDEPXJJr4S2bh0hU/f5UhbwbFGBXHigmuaeuGQIyWZ0Ev0L7AdmeWir7Ye6a/Yr1TeT99/n3c8r1EmNnb2zdRL7JkattiGkATY=
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=H+vlZO11; arc=fail smtp.client-ip=40.107.117.66
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="H+vlZO11"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=J8hvYnT+X/GODP6mJQXAUCOwnRqbS1sLENyuC1HS4cTuabwW1Vk7Vz4y9Ua1wctx2VpOErMFhylj/Jhp1ZXd/t1lgkzAsek6FsOoxM7FKlsbxelGpCpjIL8O2Ozq8n5SYiZmE2fl/6fA5SSGzI0eK9GZLvQblu7D3IYK9z1s7QY9rLFhWJW5MZBVRNHMKP6P407AyP2B1ykCYX6EOu4JjRpLHpjNbDcY2RNXizLfo0Qya57FWp9K8YeqCEKuib8YgnNPYTSgi0bHd2MPaOGn19LHPCsEu4t9xuR+1c5rjWyCBAUMSmPgfwRH0FA/TA8nEnqhwtA2GC92NN1+SFDdsA==
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=yrcsXSzao/1m9YhUG4R6phJgjboEubpDXKN4lMRZP5g=;
b=n4a99/BpffyLp4Hq4kcAav0PADuITOjDdGyKLRZz2vfrTa1OIfn0lqv9Cyd3suytkU4a1jwGoShVxjs2iYDrIJ8a/2EXBc9MlpN5p+dQFV/SCPrw/v/IHo4zlKQdTR2Fa3ZtcMaIn4PFGveNkEfQ9Xw0go7Fh0UqUrj+Zzvx4fJiBDGrpR/gKALUZ1gVCGqdhu5nNeiesaBXwp7BB4QzCPPtWqjqITIOcO3PCVGK+u0svu+88QAUGEMHG0An8Z3S/OAD4BzGPNLjWgA5xxhtHNoTO1oCdlkapqlWZQFlfkr5L1RNnC67F5IZyZGJdC+nNjy5GtGmVHj8hCXK34thhQ==
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=yrcsXSzao/1m9YhUG4R6phJgjboEubpDXKN4lMRZP5g=;
b=H+vlZO11hMpb8fmq4bdvrW1aucm6YCmZ13sfH7jN66OaasJjOLlAdcSyRcG3BxG9nkQg5UNowVvKmRB9kAgVVBKZ/ms+wBkf6rvTrOYlrA7aSSynrjLGeIVfsPk7VuuuQQjmZ9xgQ9ax1VjD1g5mn2lc6SMVWN0Pe8mhrgy0bxCipWP6+Nz7vG7MEwaI5lqCU7XnPTY3miGDdGyKfAwRAwmoyvzAVP6PeojnQQ0SppMM/CaWG0mskypozLcuwtz9LDegjj8EgiqKEoN5JGYn3nIvkPj+SICu/vxwIrs2HiF5dUZZ8nuNIPTCyAXHM/c01PWLjnGc2sghC3rsyfzzEw==
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:44 +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:44 +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 3/7] udmabuf: fix vmap_udmabuf error page set
Date: Tue, 3 Sep 2024 16:38:08 +0800
Message-ID: <20240903083818.3071759-4-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)
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_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: 0c3fb7d4-028d-4b25-5b5d-08dccbf43d79
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-Antisp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qETvb2NDL/kGsd7swRQMNqkMXxhZuNd1RQ1LmcDCDbsZWFiSktkG2S2FLClcDUQ5qBmBz3Kfe+z1p+RmDoYF7e7kOiw9DPK3isAsqr6OKkwywa4e5Sr+tMZRBTW/XjF5MMu6PyfYu4CXYmmHcIF6q5EaBannkZlBPUkXnZrVbEo73k7j5rS6AbFO4cRRlFw4+8pHQpaLHsrYpzDKvx5zPDBG/fq1MTYPw7EFztGkY9Ovrb509d5BO0PwMQ6+0whGbyMVDGZzvbzxIQcZzm7HmSkSq2JJY/DeBcNT4MNxjTjeXIfuj7Ux+ZznXWR9I5+M8XtjkWa7x/EzrxxFkEowUrAD4cTsf9VdfBVg==
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:
y0uOxV/nZ7CdR/i8+0qbQNVkBBWqKEPSZFeCj5piYCeCiy60I+SOPoOVrxMhXfvzlwIKQPxQ/LAiYY5SApPS6YexleRIpM1NIxVGTXR4bSwJvnpS6kvR25mYWvECLeYOMC/ytNyskynFbNGMvyoC+QASwC61xQvm8XDiivXtq9ag6JI6lcntVSfSAsgob5MUvDm5ef7PNbmE7k66w4dsD18E7kRjZjhNS37Xy5uQzB0P53FS6P2UvMD1SoM5nsIeYLYvfJouY0b4W/hy1FTet1WWpbRw1UQCEpY/IVocUyYB6wQ64RBHTEDFc0a6Yet/3jdSjre9iYWAU3UDcuO1UTx42rSRWpaLbwroXuAnJ2Q0HCqwdz/0e5jM3Zt+47iA1kBGPMw2iKAYxmGFcGaA4qnIk08pDi87QRbCIw373hqxOlR0tw857bUmF5a29BAZJTOi3XzVftmsZuuw0NI0ytAxd/p633CRa/Rvr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t0ni9JJQtkFGQGitYUz1SERRcw+NCueTlc4R
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
0c3fb7d4-028d-4b25-5b5d-08dccbf43d79
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:44.4878
(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:
dY3C6Ky295kVXV28dx1WLvIrNdXvdJNQYKrjABlVqN36hZv4iiRysciFAU5DxAGcgcxGEaUPqO2ouTSo1fggbg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
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.
Due to udmabuf can use hugetlb, if HVO enabled, tail page may not exist,
so, we can't use page array to map, instead, use pfn array.
By this, we removed page usage in udmabuf totally.
Suggested-by: Vivek Kasireddy
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/Kconfig | 1 +
drivers/dma-buf/udmabuf.c | 22 +++++++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index b46eb8a552d7..fee04fdb0822 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -36,6 +36,7 @@ config UDMABUF
depends on DMA_SHARED_BUFFER
depends on MEMFD_CREATE || COMPILE_TEST
depends on MMU
+ select VMAP_PFN
help
A driver to let userspace turn memfd regions into dma-bufs.
Qemu can use this to create host dmabufs for guest framebuffers.
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 789fba312a68..456db58446e1 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -105,21 +105,29 @@ 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;
+ unsigned long *pfns;
void *vaddr;
pgoff_t pg;
dma_resv_assert_held(buf->resv);
- pages = kvmalloc_array(ubuf->pagecount, sizeof(*pages), GFP_KERNEL);
- if (!pages)
+ /**
+ * HVO may free tail pages, so just use pfn to map each folio
+ * into vmalloc area.
+ */
+ pfns = kvmalloc_array(ubuf->pagecount, sizeof(*pfns), GFP_KERNEL);
+ if (!pfns)
return -ENOMEM;
- for (pg = 0; pg < ubuf->pagecount; pg++)
- pages[pg] = &ubuf->folios[pg]->page;
+ for (pg = 0; pg < ubuf->pagecount; pg++) {
+ unsigned long pfn = folio_pfn(ubuf->folios[pg]);
- vaddr = vm_map_ram(pages, ubuf->pagecount, -1);
- kvfree(pages);
+ pfn += ubuf->offsets[pg] >> PAGE_SHIFT;
+ pfns[pg] = pfn;
+ }
+
+ vaddr = vmap_pfn(pfns, ubuf->pagecount, PAGE_KERNEL);
+ kvfree(pfns);
if (!vaddr)
return -EINVAL;
From patchwork Tue Sep 3 08:38:09 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788301
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2066.outbound.protection.outlook.com [40.107.117.66])
(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 0C6791D095F;
Tue, 3 Sep 2024 08:41:49 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.66
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352910; cv=fail;
b=rejZC24xNP6hBD51z7Iuf+IVWMol63TGiKhzdKZLxJoCHrHI2362k2JvK9xHflsMSdv5J5Wadavnt/QP5Id6ocvNvhOPdtjHxZUaQJk8Pqgks2O8P2rR1nZRxFmHMcnX5oOTd4ZNR5A7pp8Yl6ahW1EFgnuFh/ZaKbfBN0nmiAU=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352910; c=relaxed/simple;
bh=/bJ3kPIC3q5soaFW+DrWHX5yxOyxEMGu1gxW1cSLMs4=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=A4///CydV742/DTaO0/U6FMlYqyqYQ+pWCLBOUvrY2xfByqEgjXAehGu64GDM9RwVyFW0oAcsCAqRc7HYJxnOLLeyGIutq0W2LcQO7eELQiqyrb29n4mxQTPXgWh49RJvnLItfln+tPSwGc5Nndf4Sqe/fI3pPSRfMinJokqP9o=
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=L+6DvRb0; arc=fail smtp.client-ip=40.107.117.66
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="L+6DvRb0"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=hs9X7PKuvHf9ZZL82gR8/motsl/pEQZqjgmlVSuBYDUgiartOX/AK68st9zMB5YTWgsJ18GJeIXDxmAhqaZzNuyRlDTpGaNCgJCPMiCcDx7Jxua+/8GYQDATne6mGHUG1E/WzoBryuieUhp2cLvTDSBPUTAMNvctj4NJwa/eGvNHOcdvO4E0H54N3jWxIjMRyaxXKO44UiAQA+7aaQJzrOhjTlK0VwfFqDBW2sPEh9tsg30iRx4PvhAjSdxr+2obxM4mbXZSvgG+bh+3we9n/lvw/GLrKZS8hezhBoY7qAlcd8TK8ZTBlCmdejlKqG79JL1xI4cwAdhwYOsXIpLpQw==
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=d+oBILXlrKLI4yMdKcQ0YyodD+3vURTgtAhI0Rs4j0o=;
b=ev5wzGGusGRvotVWNDaiVs6HhoqJo+dl2et1tEn7vLPw7gzuxlXRE9esM+h380xxygfVfkFxRpp/ZleldyL8A1fmR94jyuCpUcRHgjqSXmsXEjYssm9gTJWG+KfSIPD0I23DoKCOdUR/9tLjEo3jkZ6rMXNCT/HVLq3SxspaQyAYWpOsC5tLSy0dJWlB7yNdVKm6rGSX1CCnHnEu8tzOXwRsoLNzgcrZgIEK0AGM58F4DdNW/tQKODPVyjlOy9o4i1zprtLkhRTzJUFUx/0P59Ypg92W88bRw8OLuyMrMwvkB/3xx+DOOpKSOln3YCAdIELFNYwpAVqF8Kv7tOtp3w==
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=d+oBILXlrKLI4yMdKcQ0YyodD+3vURTgtAhI0Rs4j0o=;
b=L+6DvRb06GusiyIcGc5cHYfeor1DraKrFKeoZuF1kb8RTLiInupZyzyQhhMTy8AWBK20w5oHwdx4RMN6rlwtqz5k7PLRAGYXmVWfLdban4422ZH0G/VC7Gfcr2cmMe1nPQNMzq4ChbhiZSt51htSZmYCt5+skAGTe+g+OEtIR1WbHGn3sJ7g9KF8bci6Z142b/EYJXPw1CYjlIB4O7xk4bUDJvdTmWPbzWFCadGBze09tWSmAnA/oBj0ZLnZsASIqMfGhQe6g5EDtDtf6idjzVP7rUULxbHVu4TgLaq6Ar/kx6E8NjJbd5vkl/f/oKjP4G7U6jgN/kz67GfZljIIzQ==
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:47 +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:47 +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 4/7] udmabuf: udmabuf_create pin folio codestyle cleanup
Date: Tue, 3 Sep 2024 16:38:09 +0800
Message-ID: <20240903083818.3071759-5-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)
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_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: d374601e-6c5a-4a0b-d6bb-08dccbf43f07
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:
cn58EvbnXD7D23BVX5TVfF70tWvvXlkh/DWCPJ/vhwosnG3WHZSxvFi+qsxXvMvg9J+UGDE1uP4XLA6cawFa85A4eqzHORHbR/heqolYh9EtcG5rXEKkq9OKolFgXqgQQpfxHCXHB53yDxfPX/ws21y6n2gXbHV0o4cxlPniWdqiXHxZDCAutkIiWC2WBvt3YeDZVA8jgRNfR2LsFuk5lmumuSHemMnGoARVLDuflbjXWCakQmszS21JdjoFk9CNjKGQ8sM/zwYGTTo6aY9cuF3BQrjpz0fAaFJrAo7gh7Uj3rFjFEKEAxb5F/fjUIxuC/Ru5gaTKyWlOD9YZq0vBPFmSsOyt72WNLroq6jpLvBZK5OUZYx4iS+yQc1Wre+1Swhagd2356o61yAytevSaMUYtIiQP9/iOm0GUTZD+NIX6y4ltNNx2rgMsb06HKiyDcPAvRTjxyBWOVRHBwMRRBYBKCgOef/8rPKq/FsBPkvRqdc6Agk/+GhmoDlTT0KJ25T+SHULMfzAz/GVVSIPl7F3vejHiPLqSJco+8CA+6wR++b1q2WCcoW4JM+kVW1l9cNwcYnIF98VzsJvnxZ47HFLXXqz2zdQK+stT6Y29Cw0ZijXv6x5DPDFX4AE6gff/ksL/JXb8/q+CzHvCLc3+um84IslAcma17SNNNBQtgm3x3evVNbXzWNX1mH+sD+b+vWcyU4bC5+VFsy3flyOwAaLDH2H+97qjrxN6PNCjp7awJtnTOGUzDC1zxkpRSbAetaUvsNJbrA6jfXqcOqMX1pJScedj5emcjsESDeb98wGLVuyvqBuxmQ1oJS/LmJ/MGFiAI0ejhr85wcNhByxSAsM1aIM4OJCvDVPhwH+Gxxy7+qVZsifqDrr8IqhfMBSPdnevIk1huzj9MYiAbWFTw5HI4Fv3nVdqzdV36Bkyti59lEtX901okK6QcIfmdaRqi3z1OBlg5crZYD1G++IN+Ei+bVhkb4juNZZjermtJzwbXJeD4HNn36PxPlcqxkRwsU6DUimJtzbn45zEEcUrr/aXla1CUHm880k9DXDNCwyedbff2eP/Vgo0DkDp7zPZqO9yCY3eSK2Z56Uwa+dQmzVO6ru+iVnlv0BQtRh0cpTzfHwvRGS/7BRqh/qdQTtOIg8yYibpQG3QBvmx0F/m9PGOlzXY67Hzn51qYp11fpf30O2/KZGoNdQKUHM6GIN054epGHtaWBndtSw39fySwhl4C/A1CiBL9OfJAd3thd/srOwhwuTUGD85jGqpORp4cyJd2hnT7f1m0DdLtyWVIfe0s2aEmq5e+93TxK3ZNu871SouH/bOB+zU22znO7CPXlhKkv2iIUKjm8THghWqaPnMLxbYP0qMBdfu4vrx1oCWDCTKtV2pjJxNu4JLLhLGEUwKpT/7g54uSwQLVbR7g==
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:
t6YMiXkMOmMBZmpuu/NJYN+C/GzDLZi7+8brNDT4xOh3peDg57RnWhUOCfmzLxtMsK6UH+3MNeVwgBiUSOpLPmN4A7YhYUGA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4ZzsG9STJ2PjimBgHTWJARVCIYKxffTERq+CiIkx2ryQbqJXlxPTP/+GQs4n9+FNK/dvZ0Z3oYw6fO8R4ccUpjG6kDpDYlm3LJSeqco3jsekdiV7FKHGpls27NAEpHJnn2y14mi/RvynCQWg4vpXDR9QlUv8Nselk1YnxsUGIURrzmRXNBI2bJepR21qTztMdMxATe8b55d+0HkqojDTUOn41WgdtobBxGSG2ztNTqiAHVx7EFqiv61fmHU7GZHXCPajVUcGvsqEvZz3BwHY/NNXo7ho1I0OYAKjB70H1nQmsrFQexGvQYm+Qrai/pLun73nGsmkHoQb239WxTHEQ8Z0uGLM6WrFGOxjR0V8G9mzQfYYeRzTDIJudMNGsNBJuHiALttc0xBxUtZkgaE32hEThOYuj
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
d374601e-6c5a-4a0b-d6bb-08dccbf43f07
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:47.0985
(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:
kiPQwDpkf/K2qTB9u+CyNdTpjQ/9zNRUfcMFzqHjHaxfgL3UjhyuCscft1ncgzu6lb0jTS6+vsS4rgRC6IqxLg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
This patch split pin folios into single function: udmabuf_pin_folios.
When record folio and offset into udmabuf_folio and offsets, the outer
loop of this patch iterates through folios, while the inner loop correctly
sets the folio and corresponding offset into the udmabuf starting from
the offset. if reach to pgcnt or nr_folios, end of loop.
By this, more readable.
Signed-off-by: Huan Yang
---
drivers/dma-buf/udmabuf.c | 132 ++++++++++++++++++++------------------
1 file changed, 71 insertions(+), 61 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 456db58446e1..ca2b21c5c57f 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -330,17 +330,67 @@ static int export_udmabuf(struct udmabuf *ubuf,
return dma_buf_fd(buf, flags);
}
+static int udmabuf_pin_folios(struct udmabuf *ubuf, struct file *memfd,
+ loff_t start, loff_t size)
+{
+ pgoff_t pgoff, pgcnt, upgcnt = ubuf->pagecount;
+ u32 cur_folio, cur_pgcnt;
+ struct folio **folios = NULL;
+ long nr_folios;
+ loff_t end;
+ int ret = 0;
+
+ pgcnt = size >> PAGE_SHIFT;
+ folios = kvmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL);
+ if (!folios)
+ return -ENOMEM;
+
+ end = start + (pgcnt << PAGE_SHIFT) - 1;
+ nr_folios = memfd_pin_folios(memfd, start, end, folios, pgcnt, &pgoff);
+ if (nr_folios <= 0) {
+ ret = nr_folios ? nr_folios : -EINVAL;
+ goto err;
+ }
+
+ cur_pgcnt = 0;
+ for (cur_folio = 0; cur_folio < nr_folios; ++cur_folio) {
+ pgoff_t subpgoff = pgoff;
+ size_t fsize = folio_size(folios[cur_folio]);
+
+ ret = add_to_unpin_list(&ubuf->unpin_list, folios[cur_folio]);
+ if (ret < 0)
+ goto err;
+
+ for (; subpgoff < fsize; subpgoff += PAGE_SIZE) {
+ ubuf->folios[upgcnt] = folios[cur_folio];
+ ubuf->offsets[upgcnt] = subpgoff;
+ ++upgcnt;
+
+ if (++cur_pgcnt >= pgcnt)
+ goto end;
+ }
+
+ /**
+ * The term range may start with offset, so the first folio
+ * need take care of it. And the remain folio start from 0.
+ */
+ pgoff = 0;
+ }
+end:
+err:
+ ubuf->pagecount = upgcnt;
+ kvfree(folios);
+ return ret;
+}
+
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;
- struct file *memfd = NULL;
- struct folio **folios;
+ pgoff_t pgcnt = 0, pglimit;
+ long ret = -EINVAL;
struct udmabuf *ubuf;
- u32 i, j, k, flags;
- loff_t end;
+ u32 i, flags;
ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
if (!ubuf)
@@ -349,81 +399,43 @@ static long udmabuf_create(struct miscdevice *device,
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))
+ if (!PAGE_ALIGNED(list[i].offset))
goto err;
- if (!IS_ALIGNED(list[i].size, PAGE_SIZE))
+ if (!PAGE_ALIGNED(list[i].size))
goto err;
- ubuf->pagecount += list[i].size >> PAGE_SHIFT;
- if (ubuf->pagecount > pglimit)
+
+ pgcnt += list[i].size >> PAGE_SHIFT;
+ if (pgcnt > pglimit)
goto err;
}
- if (!ubuf->pagecount)
+ if (!pgcnt)
goto err;
- ubuf->folios = kvmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
- GFP_KERNEL);
+ ubuf->folios = kvmalloc_array(pgcnt, sizeof(*ubuf->folios), GFP_KERNEL);
if (!ubuf->folios) {
ret = -ENOMEM;
goto err;
}
- ubuf->offsets = kvcalloc(ubuf->pagecount, sizeof(*ubuf->offsets),
- GFP_KERNEL);
+
+ ubuf->offsets = kvcalloc(pgcnt, sizeof(*ubuf->offsets), GFP_KERNEL);
if (!ubuf->offsets) {
ret = -ENOMEM;
goto err;
}
- pgbuf = 0;
for (i = 0; i < head->count; i++) {
- memfd = fget(list[i].memfd);
+ struct file *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);
- if (ret <= 0) {
- kvfree(folios);
- if (!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;
- }
- }
-
- kvfree(folios);
+ ret = udmabuf_pin_folios(ubuf, memfd, list[i].offset,
+ list[i].size);
fput(memfd);
- memfd = NULL;
+ if (ret)
+ goto err;
}
flags = head->flags & UDMABUF_FLAGS_CLOEXEC ? O_CLOEXEC : 0;
@@ -434,8 +446,6 @@ static long udmabuf_create(struct miscdevice *device,
return ret;
err:
- if (memfd)
- fput(memfd);
unpin_all_folios(&ubuf->unpin_list);
kvfree(ubuf->offsets);
kvfree(ubuf->folios);
From patchwork Tue Sep 3 08:38:10 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788302
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2060.outbound.protection.outlook.com [40.107.117.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 7B9241D86CC;
Tue, 3 Sep 2024 08:41:52 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.60
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352914; cv=fail;
b=o1pyyVYuYr0xirYxuQXfdjb7YfOZL9ZpKjKkDsJp31mYtoT0mztzn346zU6WKkS2Ar0PhRmH6AQvlNGCGpkNJgDmiSZavvOMkT8OtATerhcDT4nge1SyPc3+XQI2TivP6A4orn60iOriNSuk2U9RGaDrLCpSPG11B0VgxhTZl94=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352914; c=relaxed/simple;
bh=+wtAyTZqB5EKV7cKoVKbNMxFnrdXRF7b6LorZ1FcXtM=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=s0lvUKxVe6cSEiUpz1nA2bLyd0pLAdzaFJt44HygNDMrBBgUIzRRH636UkeR1Au58EkJBx0GjjcdZd6IdA3mmMmBHeaOqtkU+ZVNLUDZ0dPloRiv9+VgnXaubZqZW0o0zovyX5eb6X0kg0Yp64QjOLGuXC/Zu7UFIj6DC6wbnWY=
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=VeTTAqhJ; arc=fail smtp.client-ip=40.107.117.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="VeTTAqhJ"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=kcEpYELBzUJvNFowwWcRh8FmTJ/PcVgJ4PASxMzATh/jdfHWq3U3xjKWcG3YbzGfm+MsN365DAdcpKBnmG+2bBY09Kaiycm8dkjC3zkpLkfglczIop5zEUZafg+zKX70zUlEEm+K0wAPunqu4sRdqgrEMRGo14x3shreeXXM/xeV+uL9vBf1msOevvLW8B6AyI+EN2GShDeyVs2nKjeraA+ol5wbD7PhyS+OGQ68h6wkf9Blj4YsE0l/uiXYnqYZ8qJMtNkNOPZwvrqjHCTfivArLKqip7kac3AESaTvM99hIReuupLT/eA2Hc91EyF2wYcyd3VkSk44+/4TeLEfzA==
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=fSFf2g3ny3ZSHAkRcTr13Ksd+qIbg9+zhN/spkWHmIM=;
b=TwfsBqukAn+oUuHsy+Ol6eN8325/hFvoq41F7Zd2FqcxewzhnoCIhCkveAVs3lEtb2+jtkmgVe5Xw7hsMbd3J6CjVezDN58WgZU9VlxwisLjLxJsSVIuC1BJ9Rf5OnEq092B8Ik4cPS4tyQB0w/oz7Vike7UpwzUECwFJb9L8eC3aiBQPkLZ28rplOp9pwQYodrrAF2LsaarA6M+KtlqPGIjWY4NQ8cnhyuaBUkffDhCddwQgAqe5ZfaARHXV0Ji5h0ApcNlfOJKwM+Mo+ZLRVxL7cme8Y6u/0Y+VGbcPnJj841x41DHISvA4RSe8ktjp5pk7byR2DApgx6Ap4fKYQ==
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=fSFf2g3ny3ZSHAkRcTr13Ksd+qIbg9+zhN/spkWHmIM=;
b=VeTTAqhJqSUmJ6aPS66q8dYOPdEqzXNkAdW8f9NNsrikGhIZtr+fkevG14c4crU4IugD2qkifvSVaGvGgNLhbZV/Wyndmfco+pFf8xOkxro+9IKv2CALgezh7x7TLg8m0iMB0j8VaAcUga/F9fAcqw4iXaGPgIr54ENRIxEbzKaGzY1NnLYxyYKZwObSAFQI5TbvwUNN6mI2MJ9ZBCXzCeAxUiasUeqYnbpLSR6Zxut3HXaA17Excnb4wk1GrOvKhmt7juWNVzZNK29LWUhYYZhAw2mkT+9s579GqihwlWSShBWQrBC3bonzTJv6VHMmSmqjV2lIoThANJHcjmnyQA==
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:49 +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:49 +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 5/7] udmabuf: introduce udmabuf init and deinit helper
Date: Tue, 3 Sep 2024 16:38:10 +0800
Message-ID: <20240903083818.3071759-6-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)
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_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: bf3a0b50-ab8e-4cda-880a-08dccbf4408e
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:
T0g8gcG8WM7pFoPX529vuNzzmf8DOsgv6MiB0Js77okuMlQlwuWybJBverDvwJAYqbrY4lJ3Nx/AkWEWHjjhoq7WGO4RtKUlbRkVmXBhrUipF5kkbn4Zf3//72KQqJOW1waZcZU+C5QSe3N8pRzCXjg8w3d1r4N5FjpHFJgdtS28tYuvadf20v6BFfSyjyEr2NWi5T5a0y5B2uGdiLbK3e2TBBzpdD4/ADEqNixC4KjfaOWjSIO/vVffcrxr4KtduWjw9SUGugYSq/Go6XIZ1lW59pX7thvkY0RtBuSgvdPFUDNpDy7jra/SlAEvVbmfFbJ3AEXsq2lSq9Zpe5ChCpPeWJw7tKFecHXNek+uhTwAanmy0BpEa97fT4+oy0aKzlGwkg778n2DULdwR86kuDJ9jshrYhfWC8dYB+9At5aBprd5sCRvfbMByPiHihXNJA+cDmW6DtKEGNzA4WrcpHWlBQr7D/JyPvZoib1uojzqAMc/8FVY/9iWm3jjQtm41Fmf/pTm4WGHgHwVJ7o4D6AohjVscqGtNoPB9sN4rfJxhAYU5iyyAOHxTmTwcKswfPPzsRjjrEm5Ylvi7mmELIcqRXnB5Fs5LSEF54ayNHS6C79Etvpepwvsmh8mnMlFw2cB7w4X9nm6tLRCxxbPMUo+J0RO8H9ZjqOzkU4VNPwTUEqiHV2h11DtW/0BO1f8OmV49Ljp9TRyqhYi5xlQ1oshn2xGyJFnoQcarXVceavvdYIa9up1KkEE/HVA78WCp9yyYGnECv2/v0YATSnrmaJrKXNeaTjq3bwCYrU/qUdVFdGnB1rLg4H8VzhN+mQ3tg4IxJ5Wre3KR7lAaLm9NlO93g07iJkIQviyCZJitp6BnNQDG/+ArP0vHJVZfiD9qMouBHCa8V/eE2tAQchKhVTkdXFIgnCk62zYI4mZpgDBG/WLnUEIHPKQG7G8VKja71lEGuYPmyf+jcAGGOP1Mn/5EJJG2pIVivNOwIpXFtij1YrUaPMpVRwh21RWirf08IX/OCGO1teZ5+4x3o1dkDeQvwo8QNt1TMSXhOAO0g2nPBuNTOgKPfUYZ3XmDb/1jfS9fpzAQhB+pPN2VTvnq6Mp5TgwvEfwRbTigpiLjY3aIr46xdraYay2raC/6M5APGKBVv20khkFG7QTF8YZJlOlCN65zVWiVUbhdfF2drN/E815QpzVO0TMFQP/SE7IZtQ37nZTd9l8ejEG1KiozJletNhKGNeZOTytmmiJQTa0OUfqSi4I5+0S+hPmDdp37VhAPGDG2tPU6DzJsxFNkEAQli8lL5N+oAfBRaacReEIVkkehe5aitgQ7fQx2kWxW11HPNbHTTBi0llJ+Mk6Pd04+oZu5lgK8lhNbXk1Ft8GDqOTCYjZXHFKsn2q7IeQmT+iEtO1jdSQbf1Q78lqLQ==
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:
Yz0Kt6suNci93Mhoq53zzx2XRFhb6e0GmQp+5Fsyy0/YQzh7nHObUHIwDQ4y+iAvlhS0AgfLsUrf4FjO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Ne0v4rDZFqMtEF+FvZ0KkM9u1w7x2nGzcU27Lm+OUUxIqQy0e1eOHU1JykPMR3N6wAT+FRPwD7K3auu+ieIpH6fRDdJodmDiXkBvPy2xYTt3FgcZefTiHKvoZ5z0glVExO7TMspLfivwrsAYxFE1b5qfEVl4ClB/5S+AvZlH6/SiO1v1CTJc7LBqBfmGmesqcYXYxb7F52AYsSvwpjFDQfdEtF2H9q+DCSqICSoXTKmkEMQx75Pq1g62UP4B4HtRK/GmC4A2My8/YRrXF2FQt5/c2d0nxi3Kdoqtevp+KpkYaIdYm14Oa14QC6bgtDsDkMmBG83wS+znU+8aSqhGSy91gl5MOODw/xr0fGxzz+RqJ4S8Knq5kR0cXiqidwZyh6uWigbENUJxH533NWxcOL4y1cS28kDzmtpkxuqGYtk7Cgug5e1Laxw2
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
bf3a0b50-ab8e-4cda-880a-08dccbf4408e
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:49.6819
(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:
e4+UH7M0V/Vecu+xI5/neW35wzbcKE0wlg8ZxjFVFmgtdKna/ZDtZ8KCxR6JjP8EQvSrOKm7rFLbc3n+bbnqXg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
After udmabuf is allocated, its resources need to be initialized,
including various array structures. The current array structure has
already been greatly expanded.
Also, before udmabuf needs to be kfree, the occupied resources need to
be released.
This part is repetitive and maybe overlooked.
This patch give a helper function when init and deinit, by this,
deduce duplicate code.
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 52 +++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 21 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index ca2b21c5c57f..254d9ec3d9f3 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -226,6 +226,28 @@ static int add_to_unpin_list(struct list_head *unpin_list,
return 0;
}
+static __always_inline int init_udmabuf(struct udmabuf *ubuf, pgoff_t pgcnt)
+{
+ INIT_LIST_HEAD(&ubuf->unpin_list);
+
+ ubuf->folios = kvmalloc_array(pgcnt, sizeof(*ubuf->folios), GFP_KERNEL);
+ if (!ubuf->folios)
+ return -ENOMEM;
+
+ ubuf->offsets = kvcalloc(pgcnt, sizeof(*ubuf->offsets), GFP_KERNEL);
+ if (!ubuf->offsets)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static __always_inline void deinit_udmabuf(struct udmabuf *ubuf)
+{
+ unpin_all_folios(&ubuf->unpin_list);
+ kvfree(ubuf->offsets);
+ kvfree(ubuf->folios);
+}
+
static void release_udmabuf(struct dma_buf *buf)
{
struct udmabuf *ubuf = buf->priv;
@@ -234,9 +256,7 @@ 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);
- kvfree(ubuf->folios);
+ deinit_udmabuf(ubuf);
kfree(ubuf);
}
@@ -396,33 +416,24 @@ static long udmabuf_create(struct miscdevice *device,
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 (!PAGE_ALIGNED(list[i].offset))
- goto err;
+ goto err_noinit;
if (!PAGE_ALIGNED(list[i].size))
- goto err;
+ goto err_noinit;
pgcnt += list[i].size >> PAGE_SHIFT;
if (pgcnt > pglimit)
- goto err;
+ goto err_noinit;
}
if (!pgcnt)
- goto err;
+ goto err_noinit;
- ubuf->folios = kvmalloc_array(pgcnt, sizeof(*ubuf->folios), GFP_KERNEL);
- if (!ubuf->folios) {
- ret = -ENOMEM;
+ ret = init_udmabuf(ubuf, pgcnt);
+ if (ret)
goto err;
- }
-
- ubuf->offsets = kvcalloc(pgcnt, sizeof(*ubuf->offsets), GFP_KERNEL);
- if (!ubuf->offsets) {
- ret = -ENOMEM;
- goto err;
- }
for (i = 0; i < head->count; i++) {
struct file *memfd = fget(list[i].memfd);
@@ -446,9 +457,8 @@ static long udmabuf_create(struct miscdevice *device,
return ret;
err:
- unpin_all_folios(&ubuf->unpin_list);
- kvfree(ubuf->offsets);
- kvfree(ubuf->folios);
+ deinit_udmabuf(ubuf);
+err_noinit:
kfree(ubuf);
return ret;
}
From patchwork Tue Sep 3 08:38:11 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788303
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2060.outbound.protection.outlook.com [40.107.117.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 6AADA1D86E4;
Tue, 3 Sep 2024 08:41:54 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.60
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352916; cv=fail;
b=IFSIDFkgajUlkDdOZWITS0ozRaXQOGFJ6/0z1vIMutm/q473EAoQladuWJvWcL3IVWRjgRy6aY7TLAGB32fboTu45IU8m5AMpU07JN+nl0A42begBJbixk8naTRXKKcuTzbZch5derodRNMDsZmK/QzcwYDUoYAQA6xpYUdzodY=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352916; c=relaxed/simple;
bh=R8I81NvpBR0lVlTEVYqm7gYrhKrTWrG+8HtvdWKwmNo=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=UdrKC1CgY5KWl60YsK9iIz62Ix9X/crS8AiMv5exLD0+JSwWOLWn7j45nmrQcCJd4D4ddnK4YXFAGr55GpDg+fclpg/OVqtiTSUnhThrhWXR1QT0QQHEmZoYb7auRCTyuTHkWo7Bk56Kgcw4jm+Hf5W3CterzkxZcQ0k85GlyFw=
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=EHIPtM9x; arc=fail smtp.client-ip=40.107.117.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="EHIPtM9x"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=Nle11Vm9Bod4tsd5/kHfEUXC6GsdqVIiwV/12SjavF1OizJMIw1UsXmOQJs77P7QjD2V6HTVTBtv/XWW18suphh5lkPci88FjYqZStt5SSou/cnMqPqHhsysIKlPPulB6vtY1qT53iUIgtlFTyn0Sk/25nIN21W1VYe06HuZ9D5wHsph26BFolATTlWtFMeIQfeT9TfzqX0oGKlzGX0nfCsEaauV6CUrCYwR7YjLWAlpexBKLszg6/ZWYbJBuix8x1vHR9U+KD9hdPHElgSW9NK6JxU/RqlCM1V6XNqaHU9JJn1y2MX9gGUxtgNJHg+GZ8FY3MET0YbgeKizhFwpyw==
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=2w9ISoNQ1TCRixOf5sLn0DMvJi7b12W4RPHtDUCStiw=;
b=FS6I4mVkCTIv/nMkq4nckItnc0IWwJA266V8F51FNCNxhitHpib5wm0Erg9G7O5cHEb+SL9uHjRkdSkulmTTWq/JURbMaok8TWQNx5YQExmjtoRMg8JtHNRV2VWUV5lQJpAO2uVQb4K3XMazzoYzguJ0qqZH/qyIxsy8ZBSja+7ZQ7TBBEhV7CFDJWtN+YB7anHgOXcHIvWmBIHh/R++il9MZIGEoiBjOmsg1CBbkph4Bi0QUDBBrviZBpgGFEIKZeSbVFbVazoLvK0mEc8d2xBl2fIYlZpL36A+B8SljvyyCOJmT4RdrSmqqKDAQxPseKEts3qb6rRmQfI3k8OxyQ==
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=2w9ISoNQ1TCRixOf5sLn0DMvJi7b12W4RPHtDUCStiw=;
b=EHIPtM9xQiQPONc11ouLV0nXGwx2PTMr5f+VCu68inahk2iWOisvKvo+fvOUa/+2/oTTcHOtz0DZTW1Q6ixAKbu6gBWikGVCc8NJG7/wv6vJAMTv24QYuaTiPo/HKVyX/I+SJyB38LW824XE8wg+Xh43Z9QJGophbW+ndNGZut6cxsW7or8wxZvz746smRxxprVvqFH/tkMrO+PRB2/QftICv9UFH2QKeoFTgMGHBq7tFg/Krmogat1Ypn1nUgD7JoGd47jBkmriA6VaK5xVi1PC99G9qC2x+1OG2SupEh2H6DmwoizVKPQ09IdWY/dy8iyNhlw6LQs3H5BS3SiyCw==
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:52 +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:52 +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 6/7] udmabuf: remove udmabuf_folio
Date: Tue, 3 Sep 2024 16:38:11 +0800
Message-ID: <20240903083818.3071759-7-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)
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_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: f25467ed-1eca-48a1-e229-08dccbf44219
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:
D57RObyxoOlSOocTFfzsVAo0sVRHkAdZUGEtrcvwqINfk10nulEN6B3nwQxCbPwx7Ub8aRMRkckYkyxkW/nxztxbb0y8Ac5ClrLZTD0U2yqdjET+v0n0m5xo79lSw+S/m4m4m+4w7AXVzrsjDn/d9o9abfxYRFC6Lgan1KwhdplBQG3LMSMxBPkKj1ipc+8LDvbhpUP5++CdNkMqCZM5fxscUGjrc9KJNmYW4QKLCZIfr4FJYeZlNAN0gdIKjGhGjh9edHzuQyxthtlZpZqv4EoJO7r+HaU3fzVSaGlj+dgD2lfPutvlQ4oynAsymZPucNkyH4jzoW7IupBIxTqMHMl5URGDS16xVsvu0E3sFmjtFp1GTAXu9LTWlYfwvp5Gf1zq5ZFGw+iJ2FGqZo0mpDjIWpPBCGu5kR6E5zOBa19k4if15GEBxcZhXJE8jeVaOYaB8NIpks1qoykF6HbVRkWc6+OFkgWG28h2gKb7gRwo0P7MnK0U31b/XoRgEDR+6lXbYF98GbCLbTetfZEWZEIwCHRMrXpyTEGGm3HVasSOX9F5IivX2FBbf8Og/9nC2ldjxR4YZEzjXkG7prBJ2Qezy76I27COeGbCHknAAAGhTYVxLnaqnfYHQ+WBXpHH7/bircakOCurobi31hz6JnlHs4ZwbAiFHXNLuZVWul2kltMiuF9YhM4ircw3CZ8kIaztuEsr+f+deUOG9Y85rndwFtbSU5f7zNcikfa48mi/WnUwTEl1nHWw+GAUcUcwC1hifq6UK8y7/03HDJpjHEYXDWTFOXrndYwU2JdUXvw3FrYLGMHf8AfncHCTlYaK1dTSrfFmcAp/66Z+7HP+WCJbn+bKZp4UOMZjfiPG9NFsEszgNbNB0kNfoiYvOQRb+IsB27AuzdZiWLO5GrrZs9YD9JTHEO1xPcviyiTZoB/HpT59Cq+4tV13b/XYy/GlaQaFKpVcvnsfWKMpeXIwIAijwmPxyicvTZF7sENZ8VZMMa428uGwKjSUtzhvGK29R8y6UizRGdd6Ew380jybfjCxanpEZZLqjCM3Wg7SJ12UtSjXWzUwrty8ZcGqrofyAOdMCtqnvrI5l+y1UjUydZxXMudUzsMaLUKdnPeClUYdCj680bev3mqVLPbbGB1FYrXVzpoQSlHBwvta7A3s1XOSdHP1GAOaYBPRa3u+Nm1mkAVlY3Afkz1gKi9PRk25f4nl/NbfUFatEt6PsctLLuk8NumArl00pmkNP5eHD8jzBaWnKoGa2kXXDe7Q1pq8O0TQ1bGs1XB5+Bg8tjgVz90Dr6rsjxuIbFUWchMGS2FpetkOpgjDM3K/WbsdpXSIyhAZOmntPUhTqQrDLJ8ZcizPaoLRKoaUfOTFylDdS3R85hE3V0qhWHbdNjSJfmwgPVkl5qbf73zqyyx9QW5BGQ==
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:
USTIxZZq6cMXN4G8MbZtah8/MEF8JEXQ7oQ5JR2L0h7CGDPTEGhdWgPtSn5vrT0W3AavUXencKlmV3krMfmjlh3xB7NdjDb3+DcVe5gGmtjr0WGwEK+xhTshZFnowzthTuvINnbXs8jxU6geFk8IErADWKkOIoCK2j8m3isoqrHXyM7UsMH2jD4n8aORO53qUTLEpxdt6GwUWNaveom/v2RBIERDk44eRrTnNmgRvpN6JO6WoKHrVnCGCE+7DBOls09pmUimH5gbfJBDcvm/NLKZ1QwU/I+r3XU9vbfLnT4Nep8hWluw+5GoEuLWa5D1BrZX8n7KtczW6hqfKUOOiYCxnhyQTXq0x/xgAJuEVN+aoyXqN0Rn50P+0a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g7KKiBi6V0RSEVnw5VW2VcKXIJ1R/qG8oSrh88To0XRPQwIJjEXP6flPGL1RhI4TBAJTt0WXiLM8jYrIhac0LG0ZkfR7XcExxOsH66IR+CMHzQxaXDb56KMgprA+jvxfnxq8/mruRdqUxvAXxn6
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
f25467ed-1eca-48a1-e229-08dccbf44219
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:52.2579
(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:
+fZMt5zDK8qC+CCNcWzpx5ydeJohsc67KhGiYXZ2zH5+ISHTljGqpEum4bzih0G8TJci8uE3/83oGmoMc9wR3g==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
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.
Considering that during creation, we arranged the folio array in the
order of pin and set the offset according to pgcnt.
We actually don't need to use unpin_list to unpin during release.
Instead, we can iterate through the folios array during release and
unpin any folio that is different from the ones previously accessed.
By this, not only saves the overhead of the udmabuf_folio data structure
but also makes array access more cache-friendly.
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 65 +++++++++++++++++----------------------
1 file changed, 29 insertions(+), 36 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 254d9ec3d9f3..d449c1fd67a5 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -27,15 +27,21 @@ MODULE_PARM_DESC(size_limit_mb, "Max size of a dmabuf, in megabytes. Default is
struct udmabuf {
pgoff_t pagecount;
struct folio **folios;
+
+ /**
+ * Unlike folios, pinned_folios is only used for unpin.
+ * So, nr_pinned is not the same to pagecount, the pinned_folios
+ * only set each folio which already pinned when udmabuf_create.
+ * Note that, since a folio may be pinned multiple times, each folio
+ * can be added to pinned_folios multiple times, depending on how many
+ * times the folio has been pinned when create.
+ */
+ pgoff_t nr_pinned;
+ struct folio **pinned_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 vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
@@ -198,38 +204,18 @@ 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)
+static void unpin_all_folios(struct udmabuf *ubuf)
{
- struct udmabuf_folio *ubuf_folio;
+ pgoff_t i;
- while (!list_empty(unpin_list)) {
- ubuf_folio = list_first_entry(unpin_list,
- struct udmabuf_folio, list);
- unpin_folio(ubuf_folio->folio);
+ for (i = 0; i < ubuf->nr_pinned; ++i)
+ unpin_folio(ubuf->pinned_folios[i]);
- 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;
+ kvfree(ubuf->pinned_folios);
}
static __always_inline int init_udmabuf(struct udmabuf *ubuf, pgoff_t pgcnt)
{
- INIT_LIST_HEAD(&ubuf->unpin_list);
-
ubuf->folios = kvmalloc_array(pgcnt, sizeof(*ubuf->folios), GFP_KERNEL);
if (!ubuf->folios)
return -ENOMEM;
@@ -238,12 +224,18 @@ static __always_inline int init_udmabuf(struct udmabuf *ubuf, pgoff_t pgcnt)
if (!ubuf->offsets)
return -ENOMEM;
+ ubuf->pinned_folios = kvmalloc_array(pgcnt,
+ sizeof(*ubuf->pinned_folios),
+ GFP_KERNEL);
+ if (!ubuf->pinned_folios)
+ return -ENOMEM;
+
return 0;
}
static __always_inline void deinit_udmabuf(struct udmabuf *ubuf)
{
- unpin_all_folios(&ubuf->unpin_list);
+ unpin_all_folios(ubuf);
kvfree(ubuf->offsets);
kvfree(ubuf->folios);
}
@@ -353,7 +345,9 @@ static int export_udmabuf(struct udmabuf *ubuf,
static int udmabuf_pin_folios(struct udmabuf *ubuf, struct file *memfd,
loff_t start, loff_t size)
{
- pgoff_t pgoff, pgcnt, upgcnt = ubuf->pagecount;
+ pgoff_t pgoff, pgcnt;
+ pgoff_t upgcnt = ubuf->pagecount;
+ pgoff_t nr_pinned = ubuf->nr_pinned;
u32 cur_folio, cur_pgcnt;
struct folio **folios = NULL;
long nr_folios;
@@ -377,9 +371,7 @@ static int udmabuf_pin_folios(struct udmabuf *ubuf, struct file *memfd,
pgoff_t subpgoff = pgoff;
size_t fsize = folio_size(folios[cur_folio]);
- ret = add_to_unpin_list(&ubuf->unpin_list, folios[cur_folio]);
- if (ret < 0)
- goto err;
+ ubuf->pinned_folios[nr_pinned++] = folios[cur_folio];
for (; subpgoff < fsize; subpgoff += PAGE_SIZE) {
ubuf->folios[upgcnt] = folios[cur_folio];
@@ -399,6 +391,7 @@ static int udmabuf_pin_folios(struct udmabuf *ubuf, struct file *memfd,
end:
err:
ubuf->pagecount = upgcnt;
+ ubuf->nr_pinned = nr_pinned;
kvfree(folios);
return ret;
}
From patchwork Tue Sep 3 08:38:12 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13788304
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2060.outbound.protection.outlook.com [40.107.117.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 74E9819F407;
Tue, 3 Sep 2024 08:41:56 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.117.60
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1725352918; cv=fail;
b=Zk+TRpye+xb+vkpgJq+vwnPOK4Z3TVLjjTQRDjqO/7q22xoq6+pgfo1dupVFL6pBJT87+1lX1p227nInI4BcUNVM38li410clgqA3bxHEmEtu3lRSQ3ywHBbPeQIOZnUlPdAxBWg/75JNnY5Tc1iRB5gwNRrTAiYiNQkBLR6CHs=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1725352918; c=relaxed/simple;
bh=3GhRg7mSN5QNZmL4NHe5fzimHgjym9npTMSvLPvtTho=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=aWXp973yOby6GrDcabW0Ofmvj+RvTenNM7JV9chgRZOxJnySRHMpqeLoVbw+JeNCTQLIAdR4N7B/7OWwBJkVUbLZuLDK/rM6WOzXCBuIBEgrqTb9BUzQ5ycXDJEafU59q2UanvB7ZS5hQ9O1EgeSF201ofpzuD1/7M6KYU9re8Y=
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=gBrldKQ4; arc=fail smtp.client-ip=40.107.117.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="gBrldKQ4"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=WjrzoBmjhL8lpT1oYnHLmwoiP6KVNdS54hJA2aBZuEWOAGnJ82Xo0J94jyWkFWH9lJQfevy3Pc0TBQGNsbaG0hSb01gLOAgWvp7JJedE9iwAtymZRgk/ELqcK/XkPIm4vjEgHfOO8GjTvMhKTF3NzcI3yI/sJEJHnwUWrxcIeHeqfCxh/1qQt8wwEnASkv2TxAOba+lqnqv5XbHgTY+ZKCiQGQtfk2hj8ctSOUiF1FyeVEcygW4dptJWUEm4qHUuPl40anOtT66K07dGZdMuAZleDT2FV6J9b9QkqgQPskPbLyJs2kZB5LYpF8tMqit/wB5dYXmnj0JqBe/CKxixqg==
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=ZO19NvW2yqwHS9ErLNNIkL0bAv+E9vx+kkHbMqAsKoc=;
b=RvurjIzPAWKNApuZkF+y1rnaq8cm0Q6pHwg2mTAVLd4tCZ8NM3zeKTvaw/WHj4NnriMEwvfvS7AWdW9zaYHEX61U2mAUdrMCqO35SYJb/hNnvzZ+Vn5NaYKXqMQ5/t161ekBTYziSJck8ywdiHk2DeycltAN2tJZAe2B4RMISveesUFLDdZQwX/oOIvxRsUmrWEu3EVhxjYMeDUpUX0DfZD14ls0cE7pVfg2X0ndt9+j7xeBW80XVV+GDNsIi18wzYQsXtzdHD30+7oDn0hIontd+CnKvmldP5ipfwiPGS8/iuXCirkPQ7aUoS91vMbvPqd7gLTSjo1wvFty4yN29A==
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=ZO19NvW2yqwHS9ErLNNIkL0bAv+E9vx+kkHbMqAsKoc=;
b=gBrldKQ4tOnFXvjooYnCQQmsqyeD85qnWKYvTzBWjrOXTM3dbMIoB7yuwJwxsirGBBBUU8W46LpwPc/NvnmMrqVlS2umz1qhrCkqTaXHnWp3PSsWK2785qIptaO0Rnm0Ee3qZJv+UpGRMsO8r5J40bdJuQ1YgZlP3FiqYtVNJ8D/TmipWCiRUCcKS9EjjLDWDcFvKgZQAMw9fj5NIiJz1P1O5sZvkNDTF8TLRhJy1tA7pta5DKY0d5AOouLxjOk01sMLXW2sKrQYSf6DwJccCidBMd+yQ7J/gcz/fuDkF1x2Jd4EWebwWOtG+h2I9FQPZSxbUwft16JlIFTC3lxNuQ==
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:55 +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:54 +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 7/7] udmabuf: reuse folio array when pin folios
Date: Tue, 3 Sep 2024 16:38:12 +0800
Message-ID: <20240903083818.3071759-8-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)
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_|SG2PR06MB5359:EE_
X-MS-Office365-Filtering-Correlation-Id: 4d0df1d2-189b-419d-aab8-08dccbf443a7
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:
QaUsqUtOJKBAq4wo9kQdnWPRJoaLGKKPUO2WvuMF1iBjNtf/MNJPa/C5ce4WltNglHA88rkBluAd3ONVKEvc1TP/VBDs9cNs9yzB8y33NDjyJ1lhyf9Twd842L9NlK9J+EfaU85T/MoDrgLOrnax5zVOyf6QjsiUHVZck7+FA6BJJslcFl3yepbD25GCQ5Hp0L5VQ5szF0nU0Crygf0LRmrX86LZagJuBiMBultfjM9u62rVDR0R9IUfq/yWa/sDZzLqJi7N9/RI+rsu88XudtxhfrYy9fsruNPW9blmWLN6M2F8QXoXWabCpcmyH2SRBvWqtPc8OscsZ/HstpiA0rH0aYhLaKrMxQji0sGz2qtihQy/bSzRAjRvDNKFtouUplvvr4qpnSB94s+HOdFvSyQU50P7pRVvgLdbJTe3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5676.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:
VfJ/7h8ztenxhHQ4FnT2vEw8aFGrOXpXTM02QOo79FkOFLbPPoeMKDZKUNDtZYjhgkg4HhUY7QKqnh9MdFtzOUMulhxHl4oOIw7ZatLJqVLtGxIQo2199sK3HgipopahGDbIJn06TPVzvPgrbOvsv+xmEisvzwpyCezs/sPPMTEsxE/SY78KAhYZTRYlYVSs1RE5kYVhMpbnZTYvlM+VOwB48RNNl9LKI8XlEXBaSVm5kmqA0IVYnrQh4j6TiPnni7vAiGuRAQgsd6sAZodNMO7fpbUgX5nrK0TdA+K3QGUgUkP49PDK2skp01Ey7RHGQDtWlwP/XCcuXRV4Ai/iFYb11holfZ2hUgpHZyGrJToE0StzwaBMAKNw4u5E7G0qwSU9KbITO4Pw7ZWB5qd5vZa58RdtEJfOt3jgUen/OId3RZpXl71PqWBj7sjmJyoB9gbGYUQDBeaQPsvAMfnfLx36WPxvqA9WV9kBNRi1ZAQEgkWzAu2UgPnXdwzFiJEH1LX9WFSJWjVb12yIkmI9ni6+xsCgS4yQIvsX3etqhnfnYGUbHpE4sh32zPJ3ZRyOM4AxAL5Bgr76vi4DO3eEalHjj8J6pXx7pu7eYDmB9vypHDPEiJ0sEIoiCzdCxFfD7J8HWCwl3VTvG9UFesUWGF+UC0xuQOvoWXrIxAYhIjWPY5lAwdc+gSRxgozslmEqDo4hM+g3srlFKJVHDdRvwENOsPbPDYVZbTCZQfsRkj90izjZ+K0xBhPZlVoMdX3dnIbHZKaW2nBlK6MEbyRwLL5q8TP92FEKLLxYwGnTyAS2/5PLA0Yql25i05uH9JDKTryYsYiNPfOy2N7sUOtTwahy0YWNKYzc12X43cCyBRtKzLxf/i1TG7KaetZy1WaUObWjDPVlpF7XZQ8QQuh3LO83sBtkVpDKzrDlzWPaHSX1GEHeh2h+i6WRSSigYPEat6Ftv/mIsK13rTFmfHPVf74Xp9ZEM+dF+tPz89Weo/AWj2GqhdalSIcL0BoyC/H/7tJc5ecFImERmpOseQMiIv3ugE/vu53k+4ftP6+wL2qxaTD0/Yy9B69H7Wl4HaQHz8blUbSBndS7XZX8kGRHUSP1tmZ/UhICdG7Qmv/DG/f84Sn8ViCHakTmEsnOT661/ekuTh3GHqlEDFr0Y8edvwHubsPaXyoSA2gLd9pavt2/e1sJElNPJxGJh1EF9Ot/ZeAgn3fIPVSl2F9/8brwJO33XWKmdgsDMcVlvjAAq1vs83cNzOS2dekSH5UxFli2LS/lxqJx001mlg37H1k5y7PSLvuqQ/QJD65iwFddKyESwPaB42dHaT4+uD3OMlQF4pxs52dJQZ9oDfZ1d5US1wqPtzJ73R2Xxzpr0Gdn23Kkr3QibHbof8AcRgVkDcHh6yvcpo4gdhsNmHoLDyWK+k5nHKWqcv1vUmaZGMMM/I0LPBt14ko+ky4ndL2BivM2Is2bmFEu9jwV73mnhM7AWFSGUGN+yqSSemzvEiAw1MLZYTI18lR2D4Bv6TI+L8BzPw/JwRGOBHUEyFQtUwEXUMsHpQScwusK90jL96Tevod+PFAdbMrJVAd2Pho/cUlB
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
4d0df1d2-189b-419d-aab8-08dccbf443a7
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:54.8969
(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:
PGwm1g29Hv0XqNBYTKe5spvNeBVPwFAiHEwvfGt2dYujebYrQ9Il7ik/TAEJPCId5N48qqI3O13y+4lk207dGg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB5359
When invoke memfd_pin_folios, we need offer an array to save each folio
which we pinned.
The currently way is dynamic alloc an array, get folios, save into
udmabuf and then free.
If the size is tiny, alloc from slab, is ok due to slab can cache it.
Or, just PCP order can cover, also ok.
But if size is huge, need fallback into vmalloc, then, not well, due to
each page will iter alloc, and map into vmalloc area. Too heavy.
Now that we need to iter each udmabuf item, then pin it's range folios,
we can reuse the maximum size range's folios array.
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index d449c1fd67a5..d70e45c33442 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -343,28 +343,21 @@ static int export_udmabuf(struct udmabuf *ubuf,
}
static int udmabuf_pin_folios(struct udmabuf *ubuf, struct file *memfd,
- loff_t start, loff_t size)
+ loff_t start, loff_t size, struct folio **folios)
{
pgoff_t pgoff, pgcnt;
pgoff_t upgcnt = ubuf->pagecount;
pgoff_t nr_pinned = ubuf->nr_pinned;
u32 cur_folio, cur_pgcnt;
- struct folio **folios = NULL;
long nr_folios;
loff_t end;
int ret = 0;
pgcnt = size >> PAGE_SHIFT;
- folios = kvmalloc_array(pgcnt, sizeof(*folios), GFP_KERNEL);
- if (!folios)
- return -ENOMEM;
-
end = start + (pgcnt << PAGE_SHIFT) - 1;
nr_folios = memfd_pin_folios(memfd, start, end, folios, pgcnt, &pgoff);
- if (nr_folios <= 0) {
- ret = nr_folios ? nr_folios : -EINVAL;
- goto err;
- }
+ if (nr_folios <= 0)
+ return nr_folios ? nr_folios : -EINVAL;
cur_pgcnt = 0;
for (cur_folio = 0; cur_folio < nr_folios; ++cur_folio) {
@@ -389,10 +382,8 @@ static int udmabuf_pin_folios(struct udmabuf *ubuf, struct file *memfd,
pgoff = 0;
}
end:
-err:
ubuf->pagecount = upgcnt;
ubuf->nr_pinned = nr_pinned;
- kvfree(folios);
return ret;
}
@@ -403,6 +394,8 @@ static long udmabuf_create(struct miscdevice *device,
pgoff_t pgcnt = 0, pglimit;
long ret = -EINVAL;
struct udmabuf *ubuf;
+ struct folio **folios = NULL;
+ unsigned long max_nr_folios = 0;
u32 i, flags;
ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
@@ -411,14 +404,19 @@ static long udmabuf_create(struct miscdevice *device,
pglimit = (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
for (i = 0; i < head->count; i++) {
+ pgoff_t subpgcnt;
+
if (!PAGE_ALIGNED(list[i].offset))
goto err_noinit;
if (!PAGE_ALIGNED(list[i].size))
goto err_noinit;
- pgcnt += list[i].size >> PAGE_SHIFT;
+ subpgcnt = list[i].size >> PAGE_SHIFT;
+ pgcnt += subpgcnt;
if (pgcnt > pglimit)
goto err_noinit;
+
+ max_nr_folios = max_t(unsigned long, subpgcnt, max_nr_folios);
}
if (!pgcnt)
@@ -428,6 +426,12 @@ static long udmabuf_create(struct miscdevice *device,
if (ret)
goto err;
+ folios = kvmalloc_array(max_nr_folios, sizeof(*folios), GFP_KERNEL);
+ if (!folios) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
for (i = 0; i < head->count; i++) {
struct file *memfd = fget(list[i].memfd);
@@ -436,7 +440,7 @@ static long udmabuf_create(struct miscdevice *device,
goto err;
ret = udmabuf_pin_folios(ubuf, memfd, list[i].offset,
- list[i].size);
+ list[i].size, folios);
fput(memfd);
if (ret)
goto err;
@@ -447,12 +451,14 @@ static long udmabuf_create(struct miscdevice *device,
if (ret < 0)
goto err;
+ kvfree(folios);
return ret;
err:
deinit_udmabuf(ubuf);
err_noinit:
kfree(ubuf);
+ kvfree(folios);
return ret;
}