From patchwork Tue Aug 13 09:05:07 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13761594
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.lore.kernel.org (Postfix) with ESMTPS id 79C7DC52D7B
for ; Tue, 13 Aug 2024 09:05:53 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id 0223E10E2AC;
Tue, 13 Aug 2024 09:05:53 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="QABmRsCH";
dkim-atps=neutral
Received: from APC01-SG2-obe.outbound.protection.outlook.com
(mail-sgaapc01on2055.outbound.protection.outlook.com [40.107.215.55])
by gabe.freedesktop.org (Postfix) with ESMTPS id 154F910E2D5
for ; Tue, 13 Aug 2024 09:05:50 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=LG9eTygCQeq/sOk5rTPfTdGhno93PFD+fnfYa3tVCIp5uKziW58F1b6q7WxTwZ8MefAp0uP2GjsZZS7dMtUAz3/h8OFWEBfOqZ6+QHkx+Aaqnxg37p55yPdF1CngK7ltefwZQfS1HgoHUZ+JFQVq+tDtBkqYtisPpPI8NvZfxbK6I5za89aHiSWDfAnv+mbysfobuGib3Mowugi2+612w0PTBY6i/AZ2Hib2aNa5DWThOg4dGhTgk9SZo92bLb/F1hSlpNuv8/jloJ1OixVT6KGa6JQ1j+O5Y4yDE5GDVB9KoAoTggu1VDJeGcfsu0fN/whmrI/FwB4HR48OHcEJCQ==
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=rg6KYKgpaSeM55sTXqXgdPKjcJnZRfusdSSul92Ad0s=;
b=JWkDCFNPxoUlZGYuKPkxcARgxm7+57zOwlvF07pN1CevMggaE2H6YLxk7yJZrSpqb+gAPo6qLl9EHC3qGWgBPgrpceuO9EgOveNuWkcUZZHxEEt9mq2OF6cDghX22ZFqVX0NX27omGkZ0F6rCUDMuDqAl6XrmRAoFxhj7r+maZKD8tiJ6JiepaxxGCNgm/P/IlVV/wwaJk1F6mMo7CSDNJEyoQPWjAwsGiWRCgzcSMCfazGBwyqQLyJUdldq6Mid2d8UL4CCt2dU1eg7mb/NUq2X+MR3HjbuxhPySb7GGsIirapv1xPSqkKDVrivUvOMPTac35SJelQBkkYA6UoffQ==
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=rg6KYKgpaSeM55sTXqXgdPKjcJnZRfusdSSul92Ad0s=;
b=QABmRsCHTS82EhXw0tPBbYONtqL9G3fO4tu5QwiOqYfq7GMzb9J/MT5OcMDDKMplFJQ/Xr89H2jZRklhI02Zkk27PesSGdcJZ8gfiyrGNTlx9WsVhVfJB6OfVcLzexTwKE0+nNH4s1H39t6D0OKicKLtJcFfr9A5BD5SIfW/mVgNvMvjqW4m9RJvZlh/0yaDw8PvQyTM6Ew1STmrf9Bmqmo92FcxX7YB4dwCsfbvVuypCePxaWCx1ReUj++mQeMNxHvoKh4LYB478jPESaRILevDElko0ZU4I4NRAlXffoaPa2Qqgjw2cl0fMlJv8fRyYuPH+lb97uCr8ToErCoPQQ==
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 JH0PR06MB7198.apcprd06.prod.outlook.com (2603:1096:990:98::7) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Tue, 13 Aug
2024 09:05:37 +0000
Received: from PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f%4]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024
09:05:37 +0000
From: Huan Yang
To: Gerd Hoffmann , Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Huan Yang ,
Vivek Kasireddy
Subject: [PATCH v3 1/5] udmabuf: cancel mmap page fault, direct map it
Date: Tue, 13 Aug 2024 17:05:07 +0800
Message-ID: <20240813090518.3252469-2-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240813090518.3252469-1-link@vivo.com>
References: <20240813090518.3252469-1-link@vivo.com>
X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com
(2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|JH0PR06MB7198:EE_
X-MS-Office365-Filtering-Correlation-Id: 16218051-0a07-4a6e-b125-08dcbb7718c7
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|366016|376014|52116014|1800799024|38350700014;
X-Microsoft-Antispam-Message-Info:
ARADFJzMIFN2nPQz/viCA3PWd/mq+7AHZnV1xx2uQv9mBvyK6yhODqhiNhkbfUEeU47stmjd/iGDw6qdpz6pjFw0eVLx2viyj5CjRDvxquWpVQ41m2SR5z6HnlPnZf9WCEv2QWcF2OJ5asWu/3eWHjiW2lD94iV2MILYpRDQonMYjlLfO5C6at/nXY+WiYtW2ApqOkU0uYpwcjb+5zfGnldwnF87WEh63CCaXkEbEfJyN+3QkbE2h2GzUIaJrH+6ye60gd3KjMmVmOoIokK78BOhZNX8V3mv8YMKDPtTO9qFqAASPDEwttQUHe4d5UnWERgrmf+stghBztgfwAZqthgaxhPU774ifjVT68ToEjVOlVP8MAhMlKocJeTvnJQLZcLMVnngrtbDOGYMeDe3v2j5S7KgNCaYFZl1hSG0Bohq2RfCHmsYumnbVxBV0bZusxP2/z8SFd8UqA3PlXUlFTF/azbP8nxdwnsxPKcbhoGq+5pHiMsQRumBESwY20FOBZ20bKTyA7nMIrSyHKQOSoh8wmX8dT0MbNm6YgKkH0rPy0KFhEAvjAXa3XyIfDuxVm58LQmCf7/bvTdsxYNmutI8MOzs9rMHoWu+nx8UDiVukdaCtUL+YjaRokn5hd1Ce9cShWtIPc7wzlnMwo0cMqzs3ytl1eALO2x6oGT4kW5Wf9HjYWOVR/eBFOPPR40DWbWQthqDAeJaLuQQESYEnTJ9+Q8Qhi8k8neZL4iDKDIsIQRw2dJbt5bzrT/DSJhjBtgnMDdjtaxLOiZXlpkYxY2CWREUd7dXmM73jBjEkp9qqvWrG4RKzIEcpHEccqkR5ltDBvhMj1m5mCGtvMmHJkoMDF7qwUyquSIVfd/VDzJyPBoHzsRTXdWe7g8jh0LB87X1+uUMcPZ6EnP67I/9eB2rxNzlhUT9vbVruJHFc3EuvzkgGmsFUwUqC0AKg8nnZ5dqn4+AVJLqR6qc0rdmgoeLynXdYFegbUZLQzRoppCFKtfmOgWLJ/5s9QrhW6xVsCPqYuPp4FXN5N4oAcCJj3/oWMPpi9ZP+XvnUytq+K7fd/Z7QC8W7c/4pxOCqKMQsZ9hR+8ZvwnU3Yq2SeT94C6HX7ESoH9DgTX3p5j/8Uu1rGrdXZt+gKL8+fA/bz1AVGfOezYtB9qQe5WbKp3DdgO33sDXw1Q6j+GDAQ0fs1OmtXIl5cBz96rhc7B8XHFeKKbu7GiaC1SoZ/nc6CqeQRLTtiF+RDyWkH7QCf3nB4m/hG2vYnz1o5UHAY/olCdW5py5HTI7jlok94oevA2H8uKI0g/Mg53wcyZpB5l2wzMqohnq8v6pdTaG64Nu3ti+Mj8O3Z5Uets/omls2thmFPl8TQmFr7Lw9UgwY13tpBZ2nMQpSo5seyh3aHTXJ8dqlWVtUw+THJL3ASNMtFwzSA==
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)(376014)(52116014)(1800799024)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
7qBpOFuNQ9GLOBackr8KFgsyStYhuJmJ1JEKTEn0w9U0kgpAyGC2FBi7SSX7Mhs9HdbDppI4nTcwj5QRtHuKeuS2e82ItgcIbiTMvbrFzp2cpNfOYKBoAUqQbfOiNOWzjTu5zcPM9JX4fTU82KwdDNxVwXhUXRi5Spy0NZXIgdg0KCwzS3V6vJTCboJwzjC+6Y20XqmWDdFeESAajiGKL7JEM7EAKL1ukwM40/o64ZbXVEqKvWp0GRKeIF0vcjlKGSkv/ZTVvXQtQxV1rLCKdidEZ8RgG8al8/Epf9AiQHqTf9jiCTifoHG5DHT1Dp6JjyD4L4QpNYdKC73spYqCN5SlRs4qj6c1MJEmoMF62TO1pASkh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wgLaXhS9z16Eq6j0PHV1Uo0ABscc17RYT2o1/2h1U5B+JBILViUkWJs/bjO/oq3h/G9+J5th5rxeUyiuoYC7Ha0MkiR8TTUryO7OE5I8AzQgFJfWk9O8IyJIaYzqUKHupjzVshU++EEj8ba0VRB2
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
16218051-0a07-4a6e-b125-08dcbb7718c7
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 09:05:37.2723 (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:
ITe3cNikEuCiTXnm65tG/7DB17pDCw6BcMSgt7PPj/bRpe0xnYaJDBzaPO0+ndB0apmrqSRYZBS4nC39tZ+rYg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7198
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
The current udmabuf mmap uses a page fault to populate the vma.
However, the current udmabuf has already obtained and pinned the folio
upon completion of the creation.This means that the physical memory has
already been acquired, rather than being accessed dynamically. The
current page fault method only saves some page table memory.
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.
The current patch removes the page fault method of mmap and
instead fills pfn directly when mmap is triggered.
Signed-off-by: Huan Yang
Suggested-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 37 +++++++++++++++----------------------
1 file changed, 15 insertions(+), 22 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 047c3cd2ceff..d39f9e1cd532 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -38,36 +38,29 @@ struct udmabuf_folio {
struct list_head list;
};
-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;
-
- if (pgoff >= ubuf->pagecount)
- return VM_FAULT_SIGBUS;
-
- pfn = folio_pfn(ubuf->folios[pgoff]);
- pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT;
-
- return vmf_insert_pfn(vma, vmf->address, pfn);
-}
-
-static const struct vm_operations_struct udmabuf_vm_ops = {
- .fault = udmabuf_vm_fault,
-};
-
static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
{
struct udmabuf *ubuf = buf->priv;
+ unsigned long addr;
+ unsigned long end;
+ unsigned long pgoff;
+ int ret;
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
return -EINVAL;
- vma->vm_ops = &udmabuf_vm_ops;
- vma->vm_private_data = ubuf;
vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP);
+
+ for (pgoff = vma->vm_pgoff, end = vma->vm_end, addr = vma->vm_start;
+ addr < end; pgoff++, addr += PAGE_SIZE) {
+ unsigned long pfn = folio_pfn(ubuf->folios[pgoff]);
+
+ pfn += ubuf->offsets[pgoff] >> PAGE_SHIFT;
+ ret = vmf_insert_pfn(vma, addr, pfn);
+ if (ret & VM_FAULT_ERROR)
+ return vm_fault_to_errno(ret, 0);
+ }
+
return 0;
}
From patchwork Tue Aug 13 09:05:08 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13761596
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.lore.kernel.org (Postfix) with ESMTPS id D800DC52D7D
for ; Tue, 13 Aug 2024 09:05:56 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id 53F6E10E07F;
Tue, 13 Aug 2024 09:05:56 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="Z7xK6XoT";
dkim-atps=neutral
Received: from APC01-SG2-obe.outbound.protection.outlook.com
(mail-sgaapc01on2055.outbound.protection.outlook.com [40.107.215.55])
by gabe.freedesktop.org (Postfix) with ESMTPS id 6CAED10E2D5
for ; Tue, 13 Aug 2024 09:05:50 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=WDhbWnYY2/Udac1YcnRLS+Kycb7DS0gcVEkQebsMsH1QK3yRt6SFkWfrQZxQ4QmpltAnwZ2cPTzhXjQ2zI5hBL12CnR/LBIwuQQxhq5nDarB+x5HavODUUnv1m/7pIfuyfD6utt7tHGeyQgltCRe4cl2zpk/nnlXQVT0k84eY6bTBJsnvA7KzP4fgDygV9jUUXX3D47tpBuhkDF7a733msTh+gAG2ZtHDvQnizgqIGy7iZkDnbViqpJ59KaOOyvNGvxoq8Apyg+hkWHbpZEsEDX970MuGdAJm5JTaKkFnInuybtMBkv30TtvL/DrhsXISnnjSZkzA9XsjdtoedXXMw==
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=VTn0BzRKTwiLZKTuKqzQTczqkn80pNa+NRgRfpbQSwg=;
b=OS8WGebSfxYc+22B/yZV8PqQlPqD7rJVlgSFPVqTLeuN4m3xKGwlDnHgh6ovMiYtGRXQR+vjSM1dV7ArW64aARjxiFzwKyUlxh1avqcURp+8yo+BE0dKoYST0cD8yRzvuhHOKEcjfy7QFe5baa7RdtTHBCh+RmMezY2G+NTrRr57i/YABNf3WbfY5DEICn98rxfnWD+Bt1tT+MhSosa/uejE2Fd7M7wUeBkVrLdtP47gBJ3AGcvHVQTdyPzQlssKoh6U1A4pJ+4a2TfOgyRskaPMXrhh5t0Y3bPVnEJmUgn4MZmoYU9uqsxlAufnVpfhY1x56vLmp/mM0DiPqtOPQw==
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=VTn0BzRKTwiLZKTuKqzQTczqkn80pNa+NRgRfpbQSwg=;
b=Z7xK6XoTY4FCifL4ngbUVsor9BAZfKA1fXWfKLcMOxWu3PoXB76kspBFjAUEejLLiXwzFOsGN9RQALgOR6/BaY/YyY9Xs5wXh6nkseDrBWCeGNBUnBOOYpcfLYqZnpYUwqVMlx7e0wXYUwQY4idFLs7HW0piMY/F80EgkTqIOuR7C5CxYxgTvDpnBq1/TbYRVwHyBombwbBnG4d3fToa9Ko3Tgvziv8XVmwyb3BnHdeqaP+EO/pZr8uVM6ljowWaWWcG1yUxUuZ5PAhafYvPHLYP5czgbeSDSrmmVY61LgxHABMn5qPSusidVHUnvrO5HwR/mtlpo9TE8aCXr+Ms7Q==
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 JH0PR06MB7198.apcprd06.prod.outlook.com (2603:1096:990:98::7) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.20; Tue, 13 Aug
2024 09:05: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%4]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024
09:05:39 +0000
From: Huan Yang
To: Gerd Hoffmann , Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Huan Yang ,
Vivek Kasireddy
Subject: [PATCH v3 2/5] udmabuf: change folios array from kmalloc to kvmalloc
Date: Tue, 13 Aug 2024 17:05:08 +0800
Message-ID: <20240813090518.3252469-3-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240813090518.3252469-1-link@vivo.com>
References: <20240813090518.3252469-1-link@vivo.com>
X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com
(2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|JH0PR06MB7198:EE_
X-MS-Office365-Filtering-Correlation-Id: 8ab71fcc-9f61-444d-a0e7-08dcbb771a37
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|366016|376014|52116014|1800799024|38350700014;
X-Microsoft-Antispam-Message-Info: =?utf-8?q?baoFqYPCMQeOQmTEo1Y3itJ4A0jmzds?=
=?utf-8?q?6qFfhPEz9w4fBiaHcIHeT4CQzy/swydrLpegDdKlg7wNBTkXubPZnDPchktZM8XLw?=
=?utf-8?q?Y+vRCH7HrAOgONlma8sg3iy8iZ/K0/D5f6um74kYi2IOpRzt6WoKVSllCyHCjlbbX?=
=?utf-8?q?Agz57i4Ph62S++qLPWiAh6LjW43QWUHKfihzJ3KUEaL0awjYLrG7+YakZfvs6b0FI?=
=?utf-8?q?WxKdpGlsqTigAdWgunK6cSBmrCWjmOHhTZmfxiNjvD22DzwYOhobpgoS4wlBcKI1G?=
=?utf-8?q?HuCqorGXZPi+dztyqTnpi5QkvnLgyo+98QV0cVo4+m6Lwh5H1p9DV7MWYd232/nXQ?=
=?utf-8?q?g1KaPHajPXWm8qIxethG7Br5epps9Qte+UKq1zMeQw82KUZIHPqavVmNJwJsx1OyM?=
=?utf-8?q?jrmH/0nIgOEmnU+z5nPWH8OqqYY7Wqh2yuoxwoJ7yGb9Sy4xv8bKWcIgsNaCcZI18?=
=?utf-8?q?KfHIwEP777SPqHKAJW4wo8l9LYKGfhS3BfQMlSIWnfNhbTcDpfJ8bJyPm0xC4Z5JY?=
=?utf-8?q?kBj+Zlns0g87qX2FOvwTgGn0yefRhnopQt0iyLyLB9fWy+dxd2omq0VOBOuUF/S4f?=
=?utf-8?q?Gd1y013f+wHOTljzNEBZs8J+e0qmSsrcMh0sht2FuCfthoaIjuyUbNecaFaeOtOIG?=
=?utf-8?q?NTcCRP+yViqWiMmThaU7T5hXFhsZQ24ykpqb7UoArz52p/E7O5ezRQp5TEC2g54HV?=
=?utf-8?q?1q3CN3yAiGyb08P7fp+YP8xp2MsIKEbqJJChQezRxMobpH20LxbIa41SUBmr1TU5n?=
=?utf-8?q?Y/h4D9cGQf6/rs80WwYIKka0QfRnYu4FZwVn2LHy+NZd69AZPw65TTxPz2g+B0paQ?=
=?utf-8?q?S52kMeHca0UMhlMizgMpcDbTclvgQOGOCIlLpce07fg2WuLzoJZk6PwRgse0eod97?=
=?utf-8?q?eEkLZ8RU7X7o06ZTPHwROtx2gTfBpvobiEz43GeCWOCFYMgAyDL3jDqJ7Ak18DwP7?=
=?utf-8?q?6vL8W8hVB8ezHUrx5LJepaGa0vQs6Gop9WIL+InhuaZvLVLOiFkKDM/F4yYx61pZm?=
=?utf-8?q?gQtWqCtg2nf0yQ7l6ZBXeBgVqScrQYB3XM9OX0g9kVkpI65naNS3JkJPTK93CPhEU?=
=?utf-8?q?ZNeZroeeVi2+yYCFYbzF441IHAahDCxDUg/9S8hSls55lFvidnoUSDkgExprqZUpU?=
=?utf-8?q?DJjOdBRAVhDvHaO61G9L4B5blebEqWP3J/PQ2H7+RwFsNbheTXDIdYILaIFX5V1jQ?=
=?utf-8?q?FcHSEfP6GaZMeRceRiRg4Zr/7m/zIS+XOgmLuDWSLak51VOwqsAW3HSv18ru9TVHD?=
=?utf-8?q?JGHaV1j8PL9jd4PBxMk/QxhlRDmEZ/zR3BbZIrhXHAFlUIJRkz52yweqyCpeZcRC9?=
=?utf-8?q?TX/O9cFOMpKy0mWdqhaLjfCjLYolJnkLdA=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)(376014)(52116014)(1800799024)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?+12xlRfZE0eVOIeCu/Pu1Movokos?=
=?utf-8?q?V3FH/mwDpk+R+ufP1LuHCvMK4PU9/2NeG+YWsDMjAdRKkiF29OHj0TeCE8DkF+D04?=
=?utf-8?q?4OooudW2dGsnYWUJytA2wB9D1OH9a2ghCRrU59KlX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DyO7LKGxUw+DIWayOvfGg2EgPh7mQAuZK?=
=?utf-8?q?rljWs4e0yhJ9A/7xZ60MVYZMalvR8KM+QCA3+upXSE0x+kQwhtAEDnQPvP8bZm8uc?=
=?utf-8?q?Fdwky0NH0qFoP9UMXh/Z47iU6CBkub0EFZDBN7nNU0eZUEmQzju1dR38OdAOIfDk4?=
=?utf-8?q?IHfMLgOAjs4rfp88iKMi1bVtpGIYD0ZpXJMz6wQ7cHzTrpoWpx0Dz56F5pF2V/UtY?=
=?utf-8?q?5NWWBOD0rpANC4cl7vqf8tT98wiYcJYe65ymONa6HF3a6Tun+Fb0ea8977Py3Nteu?=
=?utf-8?q?MHsSzTQiwCthS7NrP5cYLFNhoZ8wJ/74EIA+jZHMV6V9a53t1ox0fxfAy4WlxP2OS?=
=?utf-8?q?TBqVAI+ZihTAkAAPgUYqBO1gplNFtU+WhAuGZtTnKYs9XueKJustYJbB3NvvTFZmZ?=
=?utf-8?q?7Dl34Xp6LHJbuchigV7nYUUduT64EHcbTYXexuMSGGIpwjokuHcEVEfGzvpg8kIK9?=
=?utf-8?q?lk242n9Prgzkb0zgWicAYhrFnRmOk0jQQmqho2U/jbt+s2NRXCkOBFqO/7VrbIIym?=
=?utf-8?q?Ec+eV+ufCUtL?=
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
8ab71fcc-9f61-444d-a0e7-08dcbb771a37
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 09:05:39.6696 (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:
OHHIkHj1HeznqKEYjG+LFxBm4vZsxbtWZqqo6fCY4gbT+c7OXM8c16Iuj+hDd8cMhMG+6PTALIaOZhiJbhlYEg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7198
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
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 d39f9e1cd532..3ec72d47bb1c 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -73,7 +73,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;
@@ -81,7 +81,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;
@@ -189,8 +189,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);
}
@@ -315,14 +315,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;
@@ -336,7 +336,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;
@@ -346,7 +346,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;
@@ -375,7 +375,7 @@ static long udmabuf_create(struct miscdevice *device,
}
}
- kfree(folios);
+ kvfree(folios);
fput(memfd);
memfd = NULL;
}
@@ -391,8 +391,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 Aug 13 09:05: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: 13761592
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.lore.kernel.org (Postfix) with ESMTPS id 8276DC52D7C
for ; Tue, 13 Aug 2024 09:05:49 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id F2A1210E2A6;
Tue, 13 Aug 2024 09:05:48 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="fU6YpAqS";
dkim-atps=neutral
Received: from HK2PR02CU002.outbound.protection.outlook.com
(mail-eastasiaazon11010003.outbound.protection.outlook.com [52.101.128.3])
by gabe.freedesktop.org (Postfix) with ESMTPS id 15B2610E272
for ; Tue, 13 Aug 2024 09:05:48 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=Mn7gCkZO15xn1rtXLqTNY4CryzG0Ic7RwYoGo+h9jHF04am/vKNcnPvvEUkhNpqP8l+xpv4DY12yCSyADSorCUWOpDxarfXuHb8ucrWqPM0ls4Svpwfy2fuGDovOZs4kwrqtlvUZ6ZqQUQKPSWC0csSkufS/nI8t2RkZJqrLiC9FRhSqiPk+jgGrTYj3r7wvImGHs4tfoZTDjkaP+nNXKu97NTGvVBkusLaYJZsq3L1v3L3aHxd6Wf2fUWpQjlLqah0amCkXOptWy+Wf2DSiTrjdpXB8KlpSGtKI7wZ1VXXnWO16TJhRJk1itsCPV2COXRUPz2syK/KUaB1zxzai0Q==
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=iM+4srm+h3ujw3a+DyJXfMCGQHcV9mbwLUC4bdV0DqQ=;
b=c5h5gZqv1kAwLnVAZ4P7Ptj/vGQNTqu0Xn3aI6dBVvRagUtIMRVYjVZyAFv/WJUAXTkXTNSKBOlB7ZCasOPrz+VNnZ6qMf/3p0ocaiMy5eHX94qliy0Y6HFGf3zazztnEVc59S8a3vKIuQJXRSsGEYK9m3GStFzM7JW4TqkqYjkaIQWQe7elgbP/Va8VxvDXvZN7FnD9Fy3ZC6mp68YQYszEttA/Dz4VUhUz2B9CM7fA+5k4h28fVQNkhc/eVpBuwvBB/DaRNqhaSsav4AYQ1pY1EtV1F6QazbJr/4fgCkXxC9NGY1Qvo+Xwy5sVxjVq85xus05aSla2qgn5IlhSwA==
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=iM+4srm+h3ujw3a+DyJXfMCGQHcV9mbwLUC4bdV0DqQ=;
b=fU6YpAqSKJdufyYUY5cvkETVU2yJnPDu5JSZKFUud+Bpmyj/6d5TIlbUayr0xq2nPoDDBaR+1AmngZiCHQdYaqprkEDggYHfSC+spYmP+l3/G4z8hUrD30KlSN2OIsZ+GmeBoxXQVqVdMJQ5/rjMQ+26Qin5R/mhD/gRJC3SAqg9zqK7lOmjoSYuV1d3tZoJURzG2ReX8VRPnADulJKybPO0SjnE2i5lY9NONzx/6UFkuLyZqAXnVmB7VnUx6mJDTxIzgJOSXeXS43vbSdy89tQmJyAetiKZO3TVCmngzc7zqrXbMzcTV/URt5MpmWP3w3JK9ME8mXqbiahMtQMvgA==
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 SEYPR06MB5400.apcprd06.prod.outlook.com (2603:1096:101:8d::6) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Tue, 13 Aug
2024 09:05: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%4]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024
09:05:42 +0000
From: Huan Yang
To: Gerd Hoffmann , Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com, Huan Yang ,
Vivek Kasireddy
Subject: [PATCH v3 3/5] fix vmap_udmabuf error page set
Date: Tue, 13 Aug 2024 17:05:09 +0800
Message-ID: <20240813090518.3252469-4-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240813090518.3252469-1-link@vivo.com>
References: <20240813090518.3252469-1-link@vivo.com>
X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com
(2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SEYPR06MB5400:EE_
X-MS-Office365-Filtering-Correlation-Id: bc1298f1-368d-4a7a-bd57-08dcbb771ba1
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|366016|1800799024|376014|52116014|38350700014;
X-Microsoft-Antispam-Message-Info:
g+xTO4CjnAlUZoHx8tVicgE3X1i04Ma+8PQsLPEGYXu8pbdo755CE0Po7evz8tR+AZ5LxS6PzsQevUmDeLFBuqopJLGAzZAxEkcYcGxYge5DG4wTrojc0oguab7GQ+KMPH8AF6iPtG7T/vqAw71mUyzEuPBzakZEc/Iz6f0+iKc3GcNJF+bFxXYAyO7bP5eB3BSbL1B08BXRT2d3dBQxIHnBAYPfYdFVd2sM6LfYSQhNO3ePdyIgZQ2t3Eu74jpV6p4BpgIe/UwTL9rZ2Bmns/RkIFvbXemzKA0Qo3n/K73ED/9SL2NFFjgbtloKvQYnLLGznJY6NYOMFxA9JWnTjqJ+Y2usefO5Q0TcBbj+P5XOD90eAzkkOCthl3jcAYM25XLtOrXF1A4ySW7tFkKadNVGq5PNLS2Uhs1PQmARwujATaGg24jzYEu1eavP34TRfF/QpyX01mHrkzLfPD4kncGrLNIB+hz3RqW7fPQ5FRPBQtlpr1osx6+ur5KPX3Hy4OmFI/Y4/glqdtrFdL/PKKdCnHjtYM+EzUQSUuXAzdAlsFT4GDH94N9Sp06Ie1iEj0SXmQTnSG7xDdIdA0dMmUfw8t+bSERGjFCUd/BCMAcrYbUpcv+HcRo0v2KYt9NTaBxmGJmOMtBbMoJWOdNMCG6Jld+xMHwQOt2q2jlbYaGxRE6XGYELls1sV2m0Uq1cEEJ8SLlq8WS+VIRCIasuOurz3RI7z7Bqy6JUrTtpYF6AI6uBPZMn1mqOXP84zNYgmH3BA6P/6QnBFqUgG7rIgxK5ZdTKtTG+Z8Gb89ol/KzffSmO/18FcNPaXgfH8dWa+VZIW28UbtGlK+64VvYeKWO5KXnTykRZWER1F7RzBvp99W7ToWl5I1PoPr59YLyeKbPQtQv/BOhEcR8dlM4FpmhxzE46d4hS3lqcNve9Wu86sP33GdQE+uwSTqxmW3eINJ+RfkBiMsqx5ZMLHupN1mzJPOtOWbxMRmUXbkyEcQCCHl2oaHJtTWK/AVTevk7THP69+SZieLkuXtorDRBWET1PNqJo7u5uZAI/OgFgVLHDXZPooExSUUAZpuGggfd53mC9oFtVtGr1FlJqgGXoBD89oEHwMsIzqm2YF1I9Vyo6DM0m3v+mur3Cy/xhHCOTD59UGiM5wlhlHW3bYToNjQz+O6mcJPrysrggYapSX8AXGScrfsUU0E1YBCEv1Qiwot5XWKu/Z2TJN/xXAdVqRh/NH4AQmVdol66i6EoQzM5CT+v9G0t6zFjfbZJkmHfk7Ae8KBrI+2n4j9dBInHgXsBOo/So0RmxUFMwhyD22/p8KI5UzI+drPjMQk6aVg3YONMJOe6MvQHLWeH9RtsDrA5SRWgjFgM4KlST9jvkxaXJEpQROEKynuVnQYidjNesxD+Nz7sWniQrZ3IrLNnKCg==
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)(376014)(52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9xKrDGZamyELsBGOB340EQ4YPaTxkhRFWhkGIrYT4Nj7K++hcBoHPzrTHYHOi233OEzRwDr4Z6T9rd7lje7J3C5tAC5Hyi+tJFA2tJluQz/nYs65bnoZ1Lg3QwO6XZRQj/2T1cpx8oDTGGWgWrFs8/zbW9wDLN0S/YFNustXiMBppZqilDAdUngvSbW6lrtJw5Xm0lX6b6Iiew9qnDzZ1BjfjEfk5RyGLTpO9WKRM/TUv7wJDL/qv3NP0EgdrSjcBwtom0xly80hJuC4LjUqVYPtF3VOxTgAq+lcqVWuGTgAWcepmmaao3ag9XZNotT/lo071iToQqps7GWxjhsd8i6aiOv8HdXrrV/zUfYjICOF+aISP73OKzzbWFXPxlDvYSQpGne6URRGEBcV+zJr0pA6nv88Oi+YmmvKAOpOGDhThz5HanGXMHjWCKm9AsylPNmiSL2YU71wS6o8PndEk9xfBpHaLv/6V9uNqp2YfIlp7wGiHPr2G/TtCQsxNPQDaePYCf6KpAmDKnf6+ZFeQDy/vI9q7a1tgctevuNCiwGwpkzqxrJYXJxObF5KsMVMOyHqXWMKTrBNSjZZSSH4bMtEWhKkTNnNIf6+H+Y2aAu
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
bc1298f1-368d-4a7a-bd57-08dcbb771ba1
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 09:05:42.0345 (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:
qb0mMbd/6NkvCXSaAopZkOsEW7ygD940Wk+u7/nudITHMT+3ZRdxOiXGIg9iDPtzHpQnd+7BpCWt5+JVnGYW2Q==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5400
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
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.
Signed-off-by: Huan Yang
Suggested-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 3ec72d47bb1c..4ec54c60d76c 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -67,21 +67,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 Aug 13 09:05: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: 13761593
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.lore.kernel.org (Postfix) with ESMTPS id A2B77C52D7B
for ; Tue, 13 Aug 2024 09:05:50 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id EA03710E2D3;
Tue, 13 Aug 2024 09:05:49 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="Mj1aQv/f";
dkim-atps=neutral
Received: from HK2PR02CU002.outbound.protection.outlook.com
(mail-eastasiaazon11010003.outbound.protection.outlook.com [52.101.128.3])
by gabe.freedesktop.org (Postfix) with ESMTPS id 7903110E272
for ; Tue, 13 Aug 2024 09:05:48 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=NxhIclmUSF6MwLLQE4gwMf2VRzB1ilgaOgaLpZKNTD3NE8TZWTqvvW6clRERB2di4n/RznjVGeA8wc/TPGsgBp8VpiNHmfkTHcb1xI37lGAK/AmEQgmM6XOdGTzFZcaHwJyyTBraHXwGaGfFM5lDtrrkHSCMaBxQF17XnaoDCOjee67E64VTHt/DluEBZ0EXTGEifX4Np03scB3ezU8GsZrIiWTE9Vrwnqqso9mbc3fwgYUla1iyLcTfkdEaCm0wYT+1ll9sAyWr2TKBE4ktUtiaPMvFstILtiCG+Baddw+vSmcYm+gnbK98wanoPUV4kJ0c6fPXWYnSdV0mwvWHlA==
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=vbHVesOajLT6BoqvW7mli+cTiCaZZJnwmj1hAE6QkLo=;
b=juwqWCNghmwStliDtthSRB3DBuYrV+2iimR0XrEKpG4+cjUNDESqtxmLn/dDzVnvUJe1S4sqPAH6WOHefF+0uuIlAy44fNTfhpqocHf7xMiH69CN99uC9FXzPWpKL5UD0TZok/H1DuSf1c6paWNd3mL/BUYe7VkBmuCS1OzKH3uXEo65HSIYp/N0BaPzJSF1UGxGY3hE71aBt0yZLy2ko1JdHIVnxHO9tNUnd0dqU7B/XaHCgQM2OYq9Zrf5up66+XTowARA5veGvVzV3wXmERTSoXbWmdruzmN4eMQhYfbPqYfDicPqEhibDXFfFMIQtCWnU/Y/G+x/rtR4eamY2A==
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=vbHVesOajLT6BoqvW7mli+cTiCaZZJnwmj1hAE6QkLo=;
b=Mj1aQv/fUVtp8iANdjyzctBJGsHWdK/tmei84W9ZBjBYHwsRh2qkNQS3uX5CFr3I7dkCsVpfY6TPZLBG7ziukXZq3ce7WMELY0OGJ+xdnosZGZrUzaJZujJZKys8BebzXDpAufCXPjvf7x82HyLQTmdE/7wlUj29wwqOE5cJaLu2NurDY7Kx1hX1A3R218FoArj6E3PFCLu/fN63o1/rzgue7xgqeC4DFolyhEpx9cKymYDfykk9P+cu9fohWsX3rUuo/MOtsFebWukpWchsVgpl4A7iQu8sgFq5VeK0Qbtr5G5mW1dmdEmQ+r3a+ZqSJzTFkCtI+XRCLtMmD118Jw==
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 SEYPR06MB5400.apcprd06.prod.outlook.com (2603:1096:101:8d::6) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Tue, 13 Aug
2024 09:05: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%4]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024
09:05:44 +0000
From: Huan Yang
To: Gerd Hoffmann , Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com,
Huan Yang
Subject: [PATCH v3 4/5] udmabuf: codestyle cleanup
Date: Tue, 13 Aug 2024 17:05:10 +0800
Message-ID: <20240813090518.3252469-5-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240813090518.3252469-1-link@vivo.com>
References: <20240813090518.3252469-1-link@vivo.com>
X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com
(2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SEYPR06MB5400:EE_
X-MS-Office365-Filtering-Correlation-Id: a92c7671-af66-4e60-433b-08dcbb771cf9
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|366016|1800799024|376014|52116014|38350700014;
X-Microsoft-Antispam-Message-Info:
bFcxMPp3TafpKVFbccDXXgjZAedWga9v5rNlnedXyXs9MdTCDo+nlnHSqBbPJEPJCRQwuaa8NugNSaNjs78MmcL4kWYfZsAfQIj40VsELVP6QFxTTeQ1rrtI+dordDOoa4rU0jbb3AZjJVVsl8BSQj2QFXnymRuGOyWmeAX6mBsh1azOR/BMTaeOfqLc6MPZOarlk++mx4UyqXl/6HwYiOh0vW9v+a1wwLwbwx2yxEqT3SgoHTgtJRWSsDP2XTvNBfo+AS750QCH6NvjzQYfLWej1lbjfJoBqxPnBg/gozBbP1g1VFY7l4WLq/Q74XEni0873wYaxV3vQOzbBOVNbjvu7h2TbPl+fOuzHKLLsGu0a0krxe1LSjToWdC6g8hoNy0EyN9vy+vy50wrnpi94YlLcCqun9/+9OtsrnyTInauuwFV8bMohN92qR8bsAbUFmKcmrU+P1UrYFvLY/NOj5iMxqOyQzm4uTxSuu35w0uwAncF7gJGPeusULDHosvZ7sMcBWRFQJSb0pYyDKtftQN6zys0g2TUjHWedtR6rPEyfMNlc0xVK4RwweUadwHGk7pFYcbDRQK1YNqMioe236a638Ogmzrm9KLxzYDHXR9u2miv19If38Uc/2LKUUH/HH2nQn6glkN2AiQGM+xiXDHbLSgWh2tfCzUsDSys6xggrdeiYFM/7dKVEVd6i5pnTHXlzADxyILgHuNiXgc7jdzjUkk6C3Qv0e9Dy+lTI5n5CmsxL5196QruRDNSgWEDLT7pVkWUd4+Y5f4fokEmFl/j7UcITEGOE5mbSlc8XtfXPjsIDg2sNxSs/tx0zwebPMH6flHUDZIBQuNM8UMsk0w4T9l5iUtLI33kMtM8w+hL6XrVOT3/GDXP8JIgKtQLokXOZ4MpL1lfyIBpfn4WUhFd0a3cuQN9nVWn+KspLeZqqz5psvk5R3yv8ks3C8Nn95jg0IVTVv7TF0UGvnzuPMY+Bhj78o3WwQ4QuZODDn12j0e3x74Ycec9nCUTaWhQtNW1ON5UivBZ6AzG8YK2c8rB4VG1IU/ZxpSRevyHiJTwkIc6/wS4tIWEU2Nji2u495GCHhMNyEZA4li7LteFTUzF8lhaQIyqtwG0HkTUHOAlZ5cxhEi17wYpGrxX880Iz2Zv17vvFbGPUqxJ5PMt9apvAw+LHhsI9yTdBB8h9n7cj95Qn+yIlSOLAKmk2wQhj5a8mObkNkzjLrPvxxyRACo+8vFHOLmpj1LOYZl0unvyj3qnONpnzdCR0ZvbkQg7Vh38ZiGN7+fztQEAYK1eNQXT4bt2SLyXIYFPpCJAd40i8PmU8zktHe36ZxaR4haJ9CkhZSxqHnQDlkWXiLLEBDw94F3lJCSDWFYugb8VVD5oQs8vxKaWyvX95/0u7IujqGRpvMtrNNWhSvJ9O8ZGQA==
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)(376014)(52116014)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
+KkAzq3wWjjbv/uEiP9+TnIPpv8s2oYDItKnLwP9SR4Q3sqViq100uixLo2BKt1ipy/yf9DlkF8AoYHzUnZ4kKnBicpzLEiEC/g77W224i21CDfX+VD9MGZT/beQEoU/P/PTE3+1ii4oPzaynOEHk82Gacv0752e9CATUE4I7qsjMb9VMzREI1Z7eDJtz6ugg/Ib49A1Hb66ihol17wYPXlQFVGR2sHXRzuwhtR1UZvtiOSt22TCbxxoccTtUIjURHJvjjIhRgCg8wBPFUpBiBzmMi5TAgIEAXIKrRE/qUx0RCncF0a4O3P+gce+i6nk7NIrJDDcH9elN2c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cdWi119LKNVY6YqUJvZjJgm3Q3vslszy+SlzGV8TxgUM5pw8qWr7CHNX4RSszSu+8AF3s9nvJhZ5v+pzA9Lqt9G0Ni493QtK1qZLK8JAwl4e0mK3wRN5MOlU4y3sOeYKK4z7JpJvSSAzJA7tAzh/j+VNPOPRuTud924OeP3C0UITRw4xc6zt2MUswt
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
a92c7671-af66-4e60-433b-08dcbb771cf9
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 09:05:44.2639 (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:
vl3vCJQZuX52alBrZ51/bb1areNmsnRthrUHvuG+8j0WB0/tG9eOZEJkG/Q+7DRalCY6owxJzcFcUN6hx7u/Ww==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5400
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
There are some variables in udmabuf_create that are only used inside the
loop. Therefore, there is no need to declare them outside the scope.
This patch moved it into loop.
It is difficult to understand the loop condition of the code that adds
folio to the unpin_list.
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 | 65 ++++++++++++++++++++-------------------
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 4ec54c60d76c..8f9cb0e2e71a 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -296,12 +296,12 @@ 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;
+ pgoff_t upgcnt = 0, pglimit, pgbuf = 0;
+ long ret = -EINVAL;
struct file *memfd = NULL;
struct folio **folios;
struct udmabuf *ubuf;
- u32 i, j, k, flags;
+ u32 i, flags;
loff_t end;
ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
@@ -315,22 +315,21 @@ static long udmabuf_create(struct miscdevice *device,
goto err;
if (!IS_ALIGNED(list[i].size, PAGE_SIZE))
goto err;
- ubuf->pagecount += list[i].size >> PAGE_SHIFT;
+ upgcnt += list[i].size >> PAGE_SHIFT;
if (ubuf->pagecount > pglimit)
goto err;
}
- if (!ubuf->pagecount)
+ if (!upgcnt)
goto err;
- ubuf->folios = kvmalloc_array(ubuf->pagecount, sizeof(*ubuf->folios),
+ ubuf->folios = kvmalloc_array(upgcnt, 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(upgcnt, sizeof(*ubuf->offsets), GFP_KERNEL);
if (!ubuf->offsets) {
ret = -ENOMEM;
goto err;
@@ -338,6 +337,10 @@ static long udmabuf_create(struct miscdevice *device,
pgbuf = 0;
for (i = 0; i < head->count; i++) {
+ pgoff_t pgoff, pgcnt;
+ u32 j, cnt;
+ long nr_folios;
+
memfd = fget(list[i].memfd);
ret = check_memfd_seals(memfd);
if (ret < 0)
@@ -351,38 +354,36 @@ static long udmabuf_create(struct miscdevice *device,
}
end = list[i].offset + (pgcnt << PAGE_SHIFT) - 1;
- ret = memfd_pin_folios(memfd, list[i].offset, end,
- folios, pgcnt, &pgoff);
- if (ret <= 0) {
+ nr_folios = memfd_pin_folios(memfd, list[i].offset, end, folios,
+ pgcnt, &pgoff);
+ if (nr_folios <= 0) {
kvfree(folios);
- if (!ret)
- ret = -EINVAL;
+ ret = nr_folios ? nr_folios : -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;
- }
+ for (j = 0, cnt = 0; j < nr_folios; ++j, pgoff = 0) {
+ u32 k;
+ long fsize = folio_size(folios[j]);
+
+ ret = add_to_unpin_list(&ubuf->unpin_list, folios[j]);
+ if (ret < 0) {
+ kfree(folios);
+ goto err;
}
- pgbuf++;
- if (++pgoff == folio_nr_pages(folios[k])) {
- pgoff = 0;
- if (++k == nr_folios)
- break;
+ for (k = pgoff; k < fsize; k += PAGE_SIZE) {
+ ubuf->folios[pgbuf] = folios[j];
+ ubuf->offsets[pgbuf] = k;
+ ++pgbuf;
+
+ if (++cnt >= pgcnt)
+ goto end;
}
}
-
+end:
+ // update the number of pages that have already been set up.
+ ubuf->pagecount += pgcnt;
kvfree(folios);
fput(memfd);
memfd = NULL;
From patchwork Tue Aug 13 09:05: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: 13761595
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by smtp.lore.kernel.org (Postfix) with ESMTPS id 9804AC52D7C
for ; Tue, 13 Aug 2024 09:05:55 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id 1A6AC10E2A8;
Tue, 13 Aug 2024 09:05:55 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="VWRv/8Rv";
dkim-atps=neutral
Received: from APC01-TYZ-obe.outbound.protection.outlook.com
(mail-tyzapc01on2063.outbound.protection.outlook.com [40.107.117.63])
by gabe.freedesktop.org (Postfix) with ESMTPS id 9E19410E272
for ; Tue, 13 Aug 2024 09:05:53 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=lDGwMF5HJC8UVXGXFyVTbDPFhmq+g7ueSLPlFwcUVgZwZ1NALeJf9lArTj1PoJoR1RWwJkCcRV2FX9Jz1Ayr7dybc8iVhKYOiH2DKCp2MPgBgwFHXXW2wtHS8D/wb3FEReedhuJYeyUu5X1ElBK6tnUZcpCuJY0rfCTpSqz6fXA69WdDMmTtb6p/SjuPDZuatSvtDgRszdkvRrNhmD+5Bc6TdVzQqzr+YwXBSnqY65QoI7ULSrgozbzpH7Cwgpv0LvuD6vFDFXETMdUPT0L3b8AwuEsX9CUB8Z+wTv3tVDRN2tIfZkaB/kWICZ2CLsCFefOuXo85JXXjN2p6se5O5A==
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=kcLyYBhcFFKALBjmJ3FFvEcxMSv+YUb9+KtElz+e5pA=;
b=UTu+cxGMEPRmTn8vZMPVoG9znsV5v68MZPHhX2zBHbO5yozeNEpITpevPdJnBXYN6r93TfYa8tDnOGmdeJ+D9rYwR46UL0gQa8th0ITtmpHbeMzYuSW+HNGm8eB6ToBuwj+wBhnPMW7rzL5Ugdd4p0i4wqTIIzrKXxQdg5WWGOVHydNQvJgt7dvWqAKkVS3iWTZVUxgjQIYiEI77CrU0zAeWk0K9p9wcqW8xf8qsNanVquJ9Y87kJ+AQ91hAHKhQlftyhDUiCJfAsytadHmD8/FuZAsJHQxEM4GztGIbwrNecAnt0Z5/wKWcMQ1XbsHZWd+tfBanFYp0OHSh2RaeZA==
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=kcLyYBhcFFKALBjmJ3FFvEcxMSv+YUb9+KtElz+e5pA=;
b=VWRv/8RvqRYKdH0tZ/aF8nlbW1t4OdQnjBqRO9vqYGCQP3jp5A6/EaR+PRmHU9d2zi7AKTxNF2xp8xLFZ43vaZACnJW/sQiVbdtxvSS+K7H1r327t9gSb17ixDGwdQsEn0OE1tuv8MoupOY7WTFl5yJ5Kfyy6nqBB3jBiPOWTtDJNbx+XBaHkYtVIQkzwRaNTLhvfcM5GKeFfCY0TfvNti6K4qTiqTl4vhTwrqlDOtJNONQZ5OfV2SOdOLZQ3+g3iFuZhwQIoL0zElUaMXFHl5unqYlHjCH7/mUWGTMRBtYpahhGiSHB+eCsHmqnfZz1iStuvcXQk96iO0sZlwH4fg==
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 PUZPR06MB5820.apcprd06.prod.outlook.com (2603:1096:301:f2::8) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7849.22; Tue, 13 Aug
2024 09:05:46 +0000
Received: from PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f%4]) with mapi id 15.20.7849.019; Tue, 13 Aug 2024
09:05:46 +0000
From: Huan Yang
To: Gerd Hoffmann , Sumit Semwal ,
=?utf-8?q?Christian_K=C3=B6nig?= ,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com,
Huan Yang
Subject: [PATCH v3 5/5] udmabuf: remove udmabuf_folio
Date: Tue, 13 Aug 2024 17:05:11 +0800
Message-ID: <20240813090518.3252469-6-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240813090518.3252469-1-link@vivo.com>
References: <20240813090518.3252469-1-link@vivo.com>
X-ClientProxiedBy: SI2PR01CA0041.apcprd01.prod.exchangelabs.com
(2603:1096:4:193::15) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|PUZPR06MB5820:EE_
X-MS-Office365-Filtering-Correlation-Id: 566b5c2f-5736-4b79-c08f-08dcbb771e51
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|1800799024|52116014|376014|366016|38350700014;
X-Microsoft-Antispam-Message-Info:
TkdByDFraWgtMssmVj/jrlio7OQS2mjQVV4k8WRoxrQWhzutLwTPz0LSWTmR85HKSd6c5ELo8R1G8swW93ulS2E6d9d6Spj7h6F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DDVk0wMIE1c/jgnEwtCTYfzyqJZRyTfNkUph1r/RIHFStbs6aju+c9kot31rhPH2GWU+1ORr+4P1nSv1OsYacqGZxq/FAH3ERUkiKyn7D3fiB0n7PNXZuy+k7flstgeZCiHik6uy6HRGrOhRRIkJ3GHo6JCqyJS+7m3WQHe7Yb49aeBJQa1hkP6LtpzBtv8IBw4j4uySRrqdMOSimWd6o3ssICk8Kg==
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:PUZPR06MB5676.apcprd06.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230040)(1800799024)(52116014)(376014)(366016)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
HY0H0ZMQJrisFSn5HLG0zRRu8pMKxTZza/YtSZLi46xDYZXR4Tgpd06mSSDGfOzIHTlWXARIOVUY+T4g0dtJ/lM0rcN0qj5fBXYX6tGWOY/Vdqgpv4nPkQDWPpi9kwnRNtz26qddPWPDZdZUPmDrR3n4vGiwDvjKo05kPugzKLA0vvms0MFnJGtQ0ew3gVZBfXoVVa12kP2AMx/vQbatOP5YcKUn9TLFbGaKoEjjvIQZeQRbB/UFrxoRtJRa9cLyhuiKYaLFezgkFdtW6IeB/VYUy3IrQpPRxM7NkNr+5MzRB+MJTCJq1jXD03flmqZfE9Wa0eEz5rPtKz0Kl9+c2VZ0ggAb/n+lPLFyYmnF55yZJnT6synXf4NBeYvSLRtjmqsH0+jV5qzMPOsMoEOkvgUSihrhnNEHcrHyGDcXzDneExlTqr2w2PcVpvkHFt1+hwkN+VlioRkphseIsDsAu2beyRkunZH020yz7iy0qJ/SQSrbgs1WQHTeVIassv/QA8tA9WSdH4FMaV3yOwqUWjConGJo8QYpXiGrdXoOej0v+91wnP4hxGKsFJBpkVjTGN7nMz6afzjWYoqQWVmSBEU/VG9MhatxXebsSup5JJlpk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: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2024 09:05:46.5668 (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:
+Jm8sHAD1ys20DRVjcyOWnxsMzCZtCibkSXjB9k0ZNE9ubmvi34aOCM2wRn2pdre5b8Uw3cCBa140aeYgjlk8g==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB5820
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
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
---
drivers/dma-buf/udmabuf.c | 68 +++++++++++++++++----------------------
1 file changed, 30 insertions(+), 38 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 8f9cb0e2e71a..1e7f46c33d1a 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -26,16 +26,19 @@ MODULE_PARM_DESC(size_limit_mb, "Max size of a dmabuf, in megabytes. Default is
struct udmabuf {
pgoff_t pagecount;
- struct folio **folios;
struct sg_table *sg;
struct miscdevice *device;
+ struct folio **folios;
+ /**
+ * offset in folios array's folio, byte unit.
+ * udmabuf can use either shmem or hugetlb pages, an array based on
+ * pages may not be suitable.
+ * Especially when HVO is enabled, the tail page will be released,
+ * so our reference to the page will no longer be correct.
+ * Hence, it's necessary to record the offset in order to reference
+ * the correct PFN within the folio.
+ */
pgoff_t *offsets;
- struct list_head unpin_list;
-};
-
-struct udmabuf_folio {
- struct folio *folio;
- struct list_head list;
};
static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
@@ -160,32 +163,28 @@ 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)
+/**
+ * unpin_all_folios: unpin each folio we pinned in create
+ * The udmabuf set all folio in folios and pinned it, but for large folio,
+ * We may have only used a small portion of the physical in the folio.
+ * we will repeatedly, sequentially set the folio into the array to ensure
+ * that the offset can index the correct folio at the corresponding index.
+ * Hence, we only need to unpin the first iterred folio.
+ */
+static void unpin_all_folios(struct udmabuf *ubuf)
{
- struct udmabuf_folio *ubuf_folio;
-
- while (!list_empty(unpin_list)) {
- ubuf_folio = list_first_entry(unpin_list,
- struct udmabuf_folio, list);
- unpin_folio(ubuf_folio->folio);
-
- list_del(&ubuf_folio->list);
- kfree(ubuf_folio);
- }
-}
+ pgoff_t pg;
+ struct folio *last = NULL;
-static int add_to_unpin_list(struct list_head *unpin_list,
- struct folio *folio)
-{
- struct udmabuf_folio *ubuf_folio;
+ for (pg = 0; pg < ubuf->pagecount; pg++) {
+ struct folio *tmp = ubuf->folios[pg];
- ubuf_folio = kzalloc(sizeof(*ubuf_folio), GFP_KERNEL);
- if (!ubuf_folio)
- return -ENOMEM;
+ if (tmp == last)
+ continue;
- ubuf_folio->folio = folio;
- list_add_tail(&ubuf_folio->list, unpin_list);
- return 0;
+ last = tmp;
+ unpin_folio(tmp);
+ }
}
static void release_udmabuf(struct dma_buf *buf)
@@ -196,7 +195,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);
+ unpin_all_folios(ubuf);
kvfree(ubuf->offsets);
kvfree(ubuf->folios);
kfree(ubuf);
@@ -308,7 +307,6 @@ 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 (!IS_ALIGNED(list[i].offset, PAGE_SIZE))
@@ -366,12 +364,6 @@ static long udmabuf_create(struct miscdevice *device,
u32 k;
long fsize = folio_size(folios[j]);
- ret = add_to_unpin_list(&ubuf->unpin_list, folios[j]);
- if (ret < 0) {
- kfree(folios);
- goto err;
- }
-
for (k = pgoff; k < fsize; k += PAGE_SIZE) {
ubuf->folios[pgbuf] = folios[j];
ubuf->offsets[pgbuf] = k;
@@ -399,7 +391,7 @@ static long udmabuf_create(struct miscdevice *device,
err:
if (memfd)
fput(memfd);
- unpin_all_folios(&ubuf->unpin_list);
+ unpin_all_folios(ubuf);
kvfree(ubuf->offsets);
kvfree(ubuf->folios);
kfree(ubuf);