From patchwork Wed Sep 18 02:52:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13806541 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2078.outbound.protection.outlook.com [40.107.215.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06F536FB6; Wed, 18 Sep 2024 02:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726627978; cv=fail; b=qgiKnPf3ED4he/keUlDmy7gDWCMgqqx5X4Ue9YSePdV1pyyGWksiwnBYVgjzqSvnbhBxzlVex8MWIGa9SOle+Ha+fsfnv103celatMVV4patQ1i+KIlpIUWYJeLHqRc+LQtveC7fjoPIi5BEnPeiVnfIrjqsxEsc793xf+yPoFk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726627978; c=relaxed/simple; bh=+ZvjeJbM40ecmlcXR4QWSwOBE5PK7EWAhWeivEd8PfA=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=n2j94YThlWpEhKAzAb0eTdL9fKfy2T+3glrVrA9riks12yGGJQRBI2Hr223i/VSZ+KbKGv25whpPE5KO7asXoNXmQwYsINrA/nXETBQ1ks/21PfGEoq+LifGiA/0Fr+wzKaBP6dUMvsxUWMqGVWRktToAaqeunhYVARBP1Myqw0= 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=bQ2CIOqf; arc=fail smtp.client-ip=40.107.215.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="bQ2CIOqf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oTFG3A5B50wLmWTe9P3haZYK7QPcxBMo9DL90LWPwWfwN7dx3yKlKkX/g63ohveODZ34E62h+Jg7pkV0jixtqupLki15z1/ez/n8AJk9VSFSxRj5N4OvhzsYdXebND9Mx/wSDJfTYSwdxwFib1bwvAIrtuGEe2xwCb0sTEoNRfLdDXWmj0YJm0RIVrLDcwC+KbQuefoLjA9i8g9r7WcsBLGasSy8cqgA8kWhipYaorcxVn2z6345IeirW3JJeY8rrIGUNHcXatqIe6rX7BpjkaYkW9YfEr5dqlLPO/S+HT2zBGysYpeMQBgFxjG3Z6lq6mHXrzwcdkN+iTFYEWpZcg== 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=YLKPo1EheqMI5ggviZniCHFiZAO5fXmoSEx1z0ZNRBs=; b=zOzOz4BSGz76N5W37JLRAO0K+xpKEvK0uMmd93iikhjAgJMjsDzZaxGbrz7t+1bxOACIYkv3aH+iKD3iwZh04kMiwRVCMdK61xUjUdiIAgO1UnNLbEXCOYOYUhW51ce2MRm6ClVmFGepnFqgGeCQqrYdDMsMi/QnRxr4eyPqqRrGKr2yNjYmH4PaWxPwVgagwv0yhcFr8bReqaeGsFuDrlhBJ3fEsqDo7Rntv1/I3jH1QIYdJ8RXGecEB05v0SqtL0OG33stweTQb5nLO1OlGUm3CwTpA6OmcjlKMUnplB6NEnH9Nz6uCuTLJExRcGfTlNiCanbjY8oF1yoAMhWzaw== 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=YLKPo1EheqMI5ggviZniCHFiZAO5fXmoSEx1z0ZNRBs=; b=bQ2CIOqfiSaMe6J2TK5RIqjdP1FHOH0Ji+sk/ZgHAzWoE8UoeIiLT6QpBFGSHpqSKgr0mIQfPGwYCHKqROXe8fLRXGuMpIqB8ntwLxYAC7uRv17ljeGEwPmrLpnMD8rz0ylbj29iJtOuRdI9JLvN1MgRUbqp4TBaUKWSIy3e3R01t08k7TDBF4BX3v0IyxvLaDTpFedpYcYvPnO823lfTIKKZY5wiy1ebdQDlF0HTNI7GP69B7uGR1ul/vV2TSdMGNcByKVVz8TFqDqy6Z73RHqtgq7HyVTmvh15mLXxG9N84Z6zkh4aYLMYbs0bKdK8hfBWMkrZPupuSJljK/aJ8g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11) by KL1PR06MB6236.apcprd06.prod.outlook.com (2603:1096:820:d7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Wed, 18 Sep 2024 02:52:50 +0000 Received: from SEYPR06MB5672.apcprd06.prod.outlook.com ([fe80::2f0c:5cf2:abb0:d852]) by SEYPR06MB5672.apcprd06.prod.outlook.com ([fe80::2f0c:5cf2:abb0:d852%5]) with mapi id 15.20.7962.022; Wed, 18 Sep 2024 02:52:49 +0000 From: Huan Yang To: vivek.kasireddy@intel.com, Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Gerd Hoffmann , Dave Airlie , Andrew Morton , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH v7 0/7] udmabuf bug fix and some improvements Date: Wed, 18 Sep 2024 10:52:23 +0800 Message-ID: <20240918025238.2957823-1-link@vivo.com> X-Mailer: git-send-email 2.45.2 X-ClientProxiedBy: SI2P153CA0014.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::6) To SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEYPR06MB5672:EE_|KL1PR06MB6236:EE_ X-MS-Office365-Filtering-Correlation-Id: 49b667b7-545d-4086-9b90-08dcd78cfb72 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|366016|376014|7416014|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?u+FZMaycOqQzQUn2PWWP/685D4XwKmr?= =?utf-8?q?CH7SSETBxLr25Q0qRL9uTySi3g+KuqhLJQx7OuLo+mOHF7OXs7Fo8TlK81y8MY1oY?= =?utf-8?q?Xb14nfrWiuTz/LCXaz1Yo6Qgprb/iZzUtZD9MNMVN/nOT8h0xAKULUP+l07ifD0wl?= =?utf-8?q?A2PHQIo1yKIpzyZEyLUaL6LtfaG+mOni7GAMdmjLfRJWpbc7MN129Flsc3vCWVtNG?= =?utf-8?q?yHie84M7h0BKRCe6l8OKiGroTuDs75mMJV0sMbF9FPDo5NBCn0SncB/RKVXIEXq57?= =?utf-8?q?SkJvsBOH19vT8QGiEYxsmLwHUvFYUR8Alz3z32zB3eorftXfk2j6L8/+Kng5UdzE8?= =?utf-8?q?72Lr/wPsySYY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z9mdrY9hp/Vxw+2GGrFC0Ou4FMfTzSsEnQfwoI8O/9XVlUC4l3l4YXyC4?= =?utf-8?q?PWBeXvVrmF3kFTPCtpjdPLCeT7OhMcbMr8/JRkX/ye5I/ewJw0O/SXPVvgc/aUtcp?= =?utf-8?q?uuw/1yFFsc9YiDCD5RIwxfq9xKZVqUqWHuQm3BeTalcWgkGSfrAF2ZI=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEYPR06MB5672.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(366016)(376014)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Zv8Mta3NdoTlLlfPSoqZHIOyzBlG?= =?utf-8?q?eJN4QC/NhtG7tFlRfy02MMzS4CzpR/X/6WjpDzracKDw6brpY8kYN1KWZsZpUgydZ?= =?utf-8?q?D1pOaQpUr9csRnl40Itb+QB/nX5Pt80MQ+eWJ2NxEsNeEqCWil+qbV+nHF100ovvI?= =?utf-8?q?qKTam2t//xVNihT/G1k+jHxfv1I+ao+COdJKxVSjGlf8gxRj+gmUG0agcrppHitaJ?= =?utf-8?q?SMxfRUQZMZ0alp/3E62a5apDndHZjSlHrF5Cc+YE7TbqkG+qgmY7wEJrFyMVbFZj5?= =?utf-8?q?t83dexAvl1t/WXEQnVGxtPKyW3aTrcyDvo3ABywzK0B/KcUsLWjngILM6bqXtXWWq?= =?utf-8?q?A6ARkCASvh9ELBCxs7uFL8zh48o7S3bD866cF5Ov7XKNCGFnvHx5ZNUVsTaEQVSil?= =?utf-8?q?AInMzx1MTMDes/QYUmvjCN8sm58MHBBre7AtTwq2wWv9UmPTYDgewv0yVGLA7g/Oo?= =?utf-8?q?bcmjOe69VN8dSDjOTJLAi1DvHGBVD8vilZA249SAPLEu7F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7vPjYySXBhz0VGkBzE1WeGoY?= =?utf-8?q?gJ3+m21f2uHbhc+uA4wtnl5FxaCmxs2blBr16Hcu3iPLgF/j6xGDdKwPsUsNhAc7j?= =?utf-8?q?fQQwzLkCt2jyZdT2LqA6MSzr+EfAYU8L5y0YocWR1myVHZTlJwUhddEwVYzjN/Lau?= =?utf-8?q?zH+fcG4dYcW6?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 49b667b7-545d-4086-9b90-08dcd78cfb72 X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5672.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 02:52:49.6318 (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: bklQZjpiWwQC8/iavZgLHevSQEFRqmKzjlEfSnCADZOg1VkNyTNkTtEM/VWm8ikkdzt2tPnZIBFBpfQrFYTmcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6236 This patchset attempts to fix some errors in udmabuf and remove the upin_list structure, also try clean up code. By this patchset, udmabuf remove page struct relay, only use pfn and folios. Some of this fix just gather the patches which I upload before. Any patch has passed the udmabuf self-test suite's tests. Suggested by Kasireddy, Vivek Patch6 modified the unpin function, therefore running the udmabuf self-test program in a loop did not reveal any memory leaks. Notice: Test item 6 maybe requires running the command: echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages Changelog === v6 - > v7: A little change, update some commit message. Patch3: add fixes tag. Patch4: update ack tag, remove the redundant if (!memfd) check from check_memfd_seals(). update commit message. Patch6: update commit message to describe how unpin array worked. Patch7: update commit message to describe why need reuse the folios array. v5 -> v6: Patch1 use Vivek's comments(thank you), fix code style, update ack-tag. Patch2, 3 no change. Patch4 fix memfd miss fput, use Vivek's comments(thank you), fix code style, update suggested-by. Patch5 update ack-tag, fix error word in commit message. Patch6 update ack-tag, use xmas style. Patch7 update ack-tag, remove unused ret variable. --- v4 -> v5: Patch1 doc why pre-fault failed not report error. Patch2 no change Patch3 update ack tag marked in v4 Patch4 split some change into patch5 and patch7, this only contains udmabuf pin folio's function Patch5 add helper init/deini to clean udmabuf struct initialized Patch6 remove unnecessary code Patch7 remove reuse folio remove v4 patch4 --- v3 -> v4: Patch1 fill vma area with pfn only when true access. Patch2 no change Patch3 select VMAP_PFN Patch4 use function pin each item. Patch5 use pinned folio array instead udmabuf_folio struct. --- v2 -> v3: Patch1, avoid use page, instead, use pfn, and use vmf_insert_pfn map suggested-by Kasireddy, Vivek Patch2, update acked-by Kasireddy, Vivek And keep the kvcalloc on the same line. Patch3, avoid use page, instead, use pfn, then use vmap_pfn map Patch4, split v2 patch4, single update codestyle to keep review easy. Patch5, another way to remove udmabuf_folio --- v1 -> v2: Patch1, 3 Rectify the improper use of the sg table. suggested-by Christian König Patch2 add acked-by Christian K�nig which marked in v1 Patch4 Modify the data structure to restore the use of pages and correct the misunderstanding of loop conditions such as "pgcnt". make sure pass self test. remove v1's patch4 v6 https://lore.kernel.org/all/20240909091851.1165742-1-link@vivo.com/ v5 https://lore.kernel.org/all/20240903083818.3071759-1-link@vivo.com/ v4 https://lore.kernel.org/all/20240822084342.1574914-1-link@vivo.com/ v3 https://lore.kernel.org/all/20240813090518.3252469-1-link@vivo.com/ v2 https://lore.kernel.org/all/20240805032550.3912454-1-link@vivo.com/ v1 https://lore.kernel.org/all/20240801104512.4056860-1-link@vivo.com/ Huan Yang (7): udmabuf: pre-fault when first page fault udmabuf: change folios array from kmalloc to kvmalloc udmabuf: fix vmap_udmabuf error page set udmabuf: udmabuf_create pin folio codestyle cleanup udmabuf: introduce udmabuf init and deinit helper udmabuf: remove udmabuf_folio udmabuf: reuse folio array when pin folios drivers/dma-buf/Kconfig | 1 + drivers/dma-buf/udmabuf.c | 275 +++++++++++++++++++++++--------------- 2 files changed, 169 insertions(+), 107 deletions(-) base-commit: 57f962b956f1d116cd64d5c406776c4975de549d