From patchwork Mon Aug 5 03:25:43 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Huan Yang
X-Patchwork-Id: 13753091
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 B3901C3DA64
for ; Mon, 5 Aug 2024 03:26:14 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id 3A20510E110;
Mon, 5 Aug 2024 03:26:14 +0000 (UTC)
Authentication-Results: gabe.freedesktop.org;
dkim=pass (2048-bit key;
unprotected) header.d=vivo.com header.i=@vivo.com header.b="bd8RT065";
dkim-atps=neutral
Received: from APC01-SG2-obe.outbound.protection.outlook.com
(mail-sgaapc01on2040.outbound.protection.outlook.com [40.107.215.40])
by gabe.freedesktop.org (Postfix) with ESMTPS id 9A72B10E10D
for ; Mon, 5 Aug 2024 03:26:11 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=Rh9v6vMeYK2CR15cTFqdTg6jP+TJdgyRAg4r912VgCyGa5Zv9NwFt6+XuZjPzOFtYn7Bq/BdMdjs4HxlAbHfPFCkIa4agwsYiFHmeIyCN4pSJ2ukVmGC3+nC7ODkQR8c/gzEuq5Yit8z3PlIJztAT11QI0PIDxcBWQXI4THFAV5Mm8shWJ6CH+SiIcTX+oF2x7hlx7XPCLOBXkAzNJ9cMEN0qeN01ig3fBkPXrYxL2P3jasWYbV2WF0f/hr0mgF4bqYE0MnLgLh/+l3UwAUQpyM80LRjNTsZnSmQGkmP7cShXb7OvjEN5HfbAEEFrggyewGeLmqcAeh1bdAaSQPSMw==
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=zN4BPOIWPDGqdDeOp0lBQqizd09UwfjA8JkwBWWPokw=;
b=QdeHY6AtHG9alhhxinWZLqbY10XExsMMFSHcUZHjppDcVlvYaWjKWp0f/DyJPb1dRU3EV85PZhZEOzHcY7zZAGgQrrMHJEv0oymBxuQOr+73VKYuVNrNEoUWG4HuDBF1tcUhxHQlLr8PLCI/fOg5n5qiKWrCDkBXHEY86bzawto6bm+AYuAFp4QpGx/IzDP7A00PixE34ipLDUGVtg0b9bHWFobBc2HdYceEp5n6BBK0DumisqH6Aj8O4/JVdAmC7lmpZLzZNUqxWE9UFDpU8RGCffvRYoPYWHq21TJy+bGI4jI8v/28K9XBmwdIBvqUiyj3zXRUVm92mVatCYUlUA==
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=zN4BPOIWPDGqdDeOp0lBQqizd09UwfjA8JkwBWWPokw=;
b=bd8RT065lorg7IgjwpZbZCcsGpcXmFePm+9qv3HFckThFKiPS+mY677Q8HlpuCPW0fj20a29nJpaxvHlbRUMP0mdiib/3f6dqVJG51EP2R/hafprg7YZ8LsVD34gzcjPj5dVp3H9BqsR+ImxtLs7W6NQM5MxM8x8Zv6p0XZKMmMhpspfpZl0+bGLpcoRWVQ0+y/DOSTXHqb96oRO7zEv6HsBM4kIQNW8336aoSuuvSR5BBPq805kFO20hC9JkzDA3ZsS3zVBYAcuygy3EOrHGOBcaR8lSDwDAdU75NdnQr120GCsa2CQ/W0rKmXOKrSGz9wC7ZwlrTOIP5jJqA2VaQ==
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 JH0PR06MB7349.apcprd06.prod.outlook.com (2603:1096:990:a5::10)
with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug
2024 03:26:08 +0000
Received: from PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com
([fe80::a00b:f422:ac44:636f%4]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024
03:26:08 +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 v2 1/4] udmabuf: cancel mmap page fault, direct map it
Date: Mon, 5 Aug 2024 11:25:43 +0800
Message-ID: <20240805032550.3912454-2-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240805032550.3912454-1-link@vivo.com>
References: <20240805032550.3912454-1-link@vivo.com>
X-ClientProxiedBy: SI2P153CA0025.APCP153.PROD.OUTLOOK.COM
(2603:1096:4:190::12) To PUZPR06MB5676.apcprd06.prod.outlook.com
(2603:1096:301:f8::10)
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|JH0PR06MB7349:EE_
X-MS-Office365-Filtering-Correlation-Id: 01379263-71d2-4dbd-97bd-08dcb4fe58ae
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
ARA:13230040|52116014|376014|366016|1800799024|38350700014;
X-Microsoft-Antispam-Message-Info:
Sta/5HTwmHdzjAzlWdiN4gzbn9UEHvNL31YWCL6m1d7mvsYAxV9Kr5AHFah2HLJct5g3KjAT2G7CDNFgEh06XzhDypZkH7JyfRuGlpQAhQahnNsrBJlMoUyhWvaQsiHTVrnS/j9MzDun4JSONeN4XL/PP6bSh88vqoT3x+n/+NpFMkiKKhzl/7nunY+D2J8bCQrQL3M4dTfWhLBHYotuUCvUqdg7oNa0KGQ5Ncr2DBTfjKvV3IMT6CdlQsmPvplS7+mFYxlhNtD1Z/QoJTQArGIbeMn0lSD+PjRQvY95oNJd7H9Gr/yjcsqaH8fVJi4XJaQDjuTksWfpsZPnhaT6k7upveEQpLyCPvV/8EOBi2hWv/cJgs6mpeUCtvGc25Wh2hhkBwiCw8XR6xxFpSxiQNA6/tObBphKi1cSznedSWoRGc8es0IjZebIAfr3kgarHLmRbUHNvLLr6LsTmENc3GaUJOyh3R0RHeRD2xt9HDy/yBh6Y4OsE7gah46DAu2aZrkUVPzd52d0dzYcH/KTdlUoqFzMpC/ZxqFRWnuu480RxQJdCHeYf7O/bJdaBDkNts3AcGxWw3zgxw+8zfdiEkap5fpRFo9n6UgO1HcBcUBfrVQc2d3bBkUuydwUdd80FxcE+OSLXCH7uXXxXUSOXODUwfMGOxFe5iRhyzKwbGQvlcWRSo2hJUTv2eHh7aU9/qpqzQXjqagFuCtYR+De2ort1Av6ussgXoBpau9Xf9I2y/sPkSY+hna7PPFGissK29LOOWlyfFxdGkqSUMiWYw9dbjey+IIdrwN5j6zysmsPhXAJGjwRpg2kN1WwfhT8SwaWo7v8SngBbQpGb5XbAlqvynMjdq3dY2ju5cImciCI1AF5vy//3huCyJeQqIPmDM9YsNV+1t0/BxT3WMk9Ar1GFqezSnBwiI6dWfJKyU1dsEY2a/L77E/AZ2yfeacf6nzHMAEu/4HbU6azT3UoDMruhVCEq+3toLp4g73rtsORpLBguWkYj/PiJase7RBDEnwjkhRZmqdbr2kQlScCSCxLZK0HOSo/MS8ZKBBhbkDlpyvtv6OnLQkOepqdL52oXsYCaR8VwiRSrF/atjAb3vfReN8NdCXcf9sSIb73qrOSflqBie7DnUUZ3dorEj8nflT4tSx7sjeW9VNPmxfzONhQNZwWVk2c6UDk55EIz2PzBGQKZkArqCLIJO+PtxZgvSqc7BC/NFfMIi2pg+uB6SX/0nsyW12+GHylssxZ8rdXI3KTRi06QkKUFGzxm7aOPL4s/VvC7LOFiEYQ/9ENQPWR8XL9hT7dfiOSmkSlZVghPsxtTrySxFdSlmjVezIS88XnfH6Bz9HAELRC/aDQreCbJP+V5B8G0D14qip2iTokHRcBTZn6wn7LuYEMncTM0lxs9NBKnRkuZHt28HtZMA==
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)(52116014)(376014)(366016)(1800799024)(38350700014); DIR:OUT;
SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
DudbI0jsHexhODq+pT7oLJYTDpHU20dVWaMNH6rMF1i2aq9HSaTVOgeW1Se3zHrtjAq4UUL47bF8do9pmXkSjrBroFF3hwho8g2BnsZO797CwdMYst8pnVw0Moq4G5ubOZNzRdhvxSUvI0ZoIfnA7YTJHa4u/OdnOZSoKmHYXUHSakH7zUboavdHlccFrcl6xxrLktpcShL282I/NDcINwISsg7WeIFH1QfnNMetPIZ7GhCZSZNQ9bhTzuFN9dNeFDD8DSK3R090pf/JXz+6HsRaVHgtILYHux27cQjZDO8mJtuWTBpxW7idopucA/kJhayCroR4uA/oiM+/xiYFjA0b3VricGkHSHgHv1R3pvnk7hTjGaRls/PQRl3zfVzsiF2T6zYI+0yu039tAoKpGE4djMd1v1yQcoJX3eL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+4LllslPat1zKetwXKd09WQRyXEKQtqdVtkxOSnskdibeglP8FmZzRT0njIwBmmmEsH3uGUPHD9TqBvDu2OYBBN
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
01379263-71d2-4dbd-97bd-08dcb4fe58ae
X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 03:26:08.3821 (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:
j+ekU6rWPpT7eZwcW7AKZQP3E9R+A0MbR9qfaRcgTEaO0x5meedV1y7IgUcAENJ60I/fRiMqqprnlqJhVWjW3g==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7349
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 mechanism 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 mechanism 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,
this means that user mode access to virtual addresses needs to trap into
kernel mode.
Therefore, when creating a large size udmabuf, this represents a
considerable overhead.
The current patch removes the page fault method of mmap and
instead fills it directly when mmap is triggered.
Signed-off-by: Huan Yang
---
drivers/dma-buf/udmabuf.c | 39 ++++++++++++++++-----------------------
1 file changed, 16 insertions(+), 23 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 047c3cd2ceff..475268d4ebb1 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) {
+ struct page *page =
+ folio_page(ubuf->folios[pgoff],
+ ubuf->offsets[pgoff] >> PAGE_SHIFT);
+
+ ret = remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE,
+ vma->vm_page_prot);
+ if (ret)
+ return ret;
+ }
+
return 0;
}