From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C976EC3ABB9 for ; Mon, 5 May 2025 19:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:CC:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lzYz1kQE776rppX2LjWBcEzYot/SUfNrKDUyz+RyId0=; b=1qhaoWIUOM0t44c+VbT/6qCfc/ hOMuYSe01c3SSr3AIZS1saRAexp6eG53iZ9/th/m917EljV3Ehti8qc7uMo/s3pWlTon6Jk7mKF4K +VsE2UBiRtWv6PrUHtlGPMpXF2fDICjTsVG4tBHSAu5cEyfaWcS2XxJ+3lg4MOv+KSPaxQYc5ywtp 7OJ+V3wulStVwm2cpSio61RWV5tEaKogaaH+bgu66g+1IEgKuR0J5XA7rlEV4+gn10g1P9rkIth8o jfG8K/I2JqCFdO7n8ULih1k5NKY0BbLhYQ/mbNX+dZIFejqcu5t2i3HWaBXdfLXFb0YYYHI0GQ7kZ 82njAKZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uC1t8-00000008S15-2r2v; Mon, 05 May 2025 19:54:06 +0000 Received: from mail-sn1nam02on20619.outbound.protection.outlook.com ([2a01:111:f403:2406::619] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uC1r8-00000008Rq4-46Ta for linux-arm-kernel@lists.infradead.org; Mon, 05 May 2025 19:52:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ffQK/aqdXSmr4zZdoh2l6/UoOloYTCuEje3TQr1avStP7GRqUgKbBYhDMa4xhn1CJDfYoA4g3XuFYWeZ8XKhcHlsmGIp8XE2pmCsHhNy86iu5cFDuih7OOC/brg/V6lGau9T2NasZPK6M89sRdKi0XIZx3aXAkGRT1VKsoqLUkJkpTd9yLsiYJHNi6m8ITTPP9RmQ8xlPsbqHSF2H1dGfNBDnMUWlxy4QISkv0CR/IZ74gGSXTwsh91u0BCjlfju0c5E8ew5M+SOgdpMfuQXeBbUPoHrplxs8Nn5KJSZ9ZAiIGiaX5jCk6Bvz7um6aJIlI52ysfMzH9PqtAKtcCttg== 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=lzYz1kQE776rppX2LjWBcEzYot/SUfNrKDUyz+RyId0=; b=gI0RbNlQPDEhprL8fLU2+rE9+jvV//cfQcc6kASgf2dsYA5E4hbHiuEXaof2mwseGvU0iLee4AaT3mK7+LUjcFjRvSnOqGDq3P5+G+5smNZQ9jCm6mxRSiNeLWNd3oxErOiLP+XTJJx4rVI/9bfcwZKhP/xvZS70tli7QVPd2yZAeMZYkLHDvbftM8d7tjdNY9A5vljPq8jJ/n1rqeGKxCfPGIZa3SgWofBQaLJtzjnoOAWD1AjAzSg1Gw5jteX2nKgeWjNf4VsEM1Wmy9re4M9J596rRz/SU/BjJFANTOfW0fNPojwZBVTZcNvoJsIQHDLb/RjhCDHJGUc4o+RfCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.linux.dev smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lzYz1kQE776rppX2LjWBcEzYot/SUfNrKDUyz+RyId0=; b=BPTx2CmJpt2SZLOgPcsu3iGTTQKEHXkXmi2EWp9nC5eSc6AsWnmDVIB2Meh8H9VCw6ty8alTSQOCAF2we9FzvKd7RfNWdNZj/7fiC0Dwc5+k7hw9C4+4xH3vIY2Ah9q7HFVKP8UgCN+q033dE5whIxFMzHK2i7PY8dI8K6DQglX6lCM/m6XDDEx87wMpFw7K4rz0oKmUj5WBusw/2F8nAnbOq55wE32+sf4LpJxE9KYg/qFjlRHIaOimTHFByEnEgx3jd9uchbz4kbWZxLFibUcxiddOMqDKPJLEuugLMaKCJJopWOKX3TnctX6YTYgX6usVhdwLDJvZla/2bV6WGA== Received: from CH0PR03CA0016.namprd03.prod.outlook.com (2603:10b6:610:b0::21) by SA1PR12MB8743.namprd12.prod.outlook.com (2603:10b6:806:37c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8699.24; Mon, 5 May 2025 19:51:55 +0000 Received: from CH2PEPF00000141.namprd02.prod.outlook.com (2603:10b6:610:b0:cafe::20) by CH0PR03CA0016.outlook.office365.com (2603:10b6:610:b0::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8699.31 via Frontend Transport; Mon, 5 May 2025 19:51:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CH2PEPF00000141.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8722.18 via Frontend Transport; Mon, 5 May 2025 19:51:54 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 5 May 2025 12:51:33 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Mon, 5 May 2025 12:51:32 -0700 Received: from nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14 via Frontend Transport; Mon, 5 May 2025 12:51:05 -0700 Date: Mon, 5 May 2025 12:50:56 -0700 From: Nicolin Chen To: Jason Gunthorpe CC: Pranjal Shrivastava , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v2 13/22] iommufd: Add mmap interface Message-ID: References: <20250505165552.GN2260709@nvidia.com> <20250505173101.GT2260709@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20250505173101.GT2260709@nvidia.com> X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000141:EE_|SA1PR12MB8743:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d706f07-d75f-4763-2845-08dd8c0e4976 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|1800799024|376014|36860700013|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?6wnDJg8TfHKTv54yOKMCTOAojk6lC2PwLFxItsGRTOjvAqR+q2DgtDh+nzwj?= =?us-ascii?Q?73j2Ls1EBIEZcsgXP7WYkRWD4s63RwnABRhSgUo7p3v3RQqzy9jP0fNGJv0E?= =?us-ascii?Q?2CQys5kC8fgsqOHqetIktkxz81EnFB/VH68GAtNXFgBUc9DAEa5isvCAXUte?= =?us-ascii?Q?FtE7qAlqsLUVPXhoOQm4zDFK1va3p3s9yPAsgvSrlRmeRfizYGgw6UdGQ7xy?= =?us-ascii?Q?tR317b1JRXwVBE8OB+T6ThxEK3O3dKwLp+byAzYclgHynSFWAxZqt4FdPu3J?= =?us-ascii?Q?3fy/ss+ZgxYvEUGUod8OvFGgUFnrPtjd5cj3LmgeFojWF4qUWLpNcnTzBmcs?= =?us-ascii?Q?oFEmRnzz4+Gjiag5tUjAHEqThvfFCvZAUD97pqC/ApRY+u95FaIiwZx840qQ?= =?us-ascii?Q?CEEZhiuJxix7YIYe2MIpoMdHENShXRY99rS4AFM+8SXjEPE9sCby7IH2O6uS?= =?us-ascii?Q?ji1XMxiBdwDsL8Bpyd1nIX2xIjkPynXKk8zqmQ93sw+0ecKkmiyohmU8MNXy?= =?us-ascii?Q?mNOTqHAThesKyCNpao42YFnIXcHu5bCwFPypFUt1dT/2HJa7d0ffKT+3XPam?= =?us-ascii?Q?8gexgI1xTQ40U6VouP4/wzYOQqUplrlQJYNrQ8QCUxf4oJEVnVIwKFRSNP7u?= =?us-ascii?Q?0bLiJrAAGou/PnvRPlmBbuCGPOgRJexDhYaJM8HbfPkluZr6EDdW3aubsbP8?= =?us-ascii?Q?oNoD1GeckP6AT2qgY1Giq3CsVhk9ttG98eBByNsolEEFLULqkrzYAdehxGab?= =?us-ascii?Q?8hNSw/HpaYe/xRZB/zg9IMPX0TIKaOi/2o9f/mUV6H+cdQ2nAo5kw70udEJj?= =?us-ascii?Q?QV/HEhpwISmyTXUMFHzyFfoobSrvrqmmhydirW1hgt8MejQzThv7YQHf7sZR?= =?us-ascii?Q?3KGgOw4yMhndPVTGWE3nbgEgjHwqebEYZIqAF6Mck8YJjlaJWI1ketuAs8Ag?= =?us-ascii?Q?t67kYhVHPZIkztokI+pRPfb6ouUDVdWyFlhBVFQZzaAZinIlDyfDN3TGhcn+?= =?us-ascii?Q?IEvTU49qMBmt9DIsngCGmhp4LDvvO9uSDdF+V5ukPfriIRQEdnnfgnBLH7P/?= =?us-ascii?Q?TujLdFQ/6yyTLLi+IkW71kYS1IN88ZfWQGkbkvx3Kd1T8WNaBIB/X74FFWzZ?= =?us-ascii?Q?Sbz2tREnxkKPjbq0zYBey+SPbS3bp39NLUfW4DdYIyIZL1m5j+R3+9tu0uzu?= =?us-ascii?Q?Df/0dTMucw01d9HhRdBLAKCU2UzaPqadCBXSsKxXvMsSphRTC1gFWxPBLzg7?= =?us-ascii?Q?TR+tZWIFvwY8x538QlQPA5WfssIWFCYZM10pWmmN7pUhk2YZqcEVVJnxkaDP?= =?us-ascii?Q?w6yiv7b5pCRhhhT1GzU2iFmt69t0/lpAyehRlGgnOojB6Ih1hiBZpyyN+Zf0?= =?us-ascii?Q?kXGC/oWDUe+umz/LrYKzLZhuTs2Vp8YkOPjPjrbUe1NPkxk42i8bZwqOTxGu?= =?us-ascii?Q?MANXCT0aI3RzHQUammuQtTIvE+39uoW+Q9GCisER1m8R9Mc4YPPQmZmSaYyy?= =?us-ascii?Q?JZOnpJz8VmkI+AcxIq0rSbu6BKkLyGm9xKtIfk+jGPY4naYtHfjG06eS3Q?= =?us-ascii?Q?=3D=3D?= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(1800799024)(376014)(36860700013)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2025 19:51:54.4858 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d706f07-d75f-4763-2845-08dd8c0e4976 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000141.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8743 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250505_125203_012971_B0E050B5 X-CRM114-Status: GOOD ( 22.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, May 05, 2025 at 02:31:01PM -0300, Jason Gunthorpe wrote: > On Mon, May 05, 2025 at 10:27:30AM -0700, Nicolin Chen wrote: > > > So when calling mtree_alloc_range: > > > > > > int mtree_alloc_range(struct maple_tree *mt, unsigned long *startp, > > > void *entry, unsigned long size, unsigned long min, > > > unsigned long max, gfp_t gfp) > > > > > > size should be the number of PFNs this mmap is going to use, which is > > > not sizeof() anything > > > > > > min should be 0 and max should be uh.. U32_MAX >> PAGE_SHIFT > > > IIRC.. There is a different limit for pgof fon 32 bit mmap() > > > > Should the startp (input) be the pfn_start (i.e. pgoff)? > > pfn_start/pgoff is the output of the allocation, it is not an input. Sorry, I got it wrong. Not "startp": it's an output that should be returned to user space, as pgoff of mmap. I wanted to ask: what should we pass in to the "entry"? An mmap structure that hold the pfn range? Or just pfn_start? > > In this case, it would return startp as the ID, which will > > be further returned to the user space. So, basically user > > space know the pfn range, v.s being given an mmap cookie? > > Userspace is given the pgoff to pass to mmap as a cookie, it doesn't > know anything about it beyond that passing that pgoff will get the > mmap it should get. Userspace must also know how big the mmap is. Yes. I got this part. > The pgoffs should all be allocated from non-overlapping ranges as > though they were bytes in a file so that the mmaps are all > disjoint. This makes debugging easier and the API saner. > > There is no "id" here.. Ah, right. "ID" is more of the xarray term. Here it's "startp" right? And it would be used as the "index" for mtree_load(). With that being said, it seems that I have been misusing the mtree data structure, treating it as an xarray. In your very first email suggesting the mmap design, where you mentioned "xarray" first and "maple tree" following. So, I thought they can be used in the similar way, especially after reading this: https://lwn.net/Articles/846175/ Thanks Nicolin