From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.198.10 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796465209; b=qxaFjxghVumQP0ScX41zs98TChbdbh+lpU3G780/6gnLuM3d0WPirgdxaF+Wqb5lK+1e geNibigUL+AZ70xVNDAgzPA99+eoeLVG6c6zhnQ5DkH+y5/9kk/+GN6pl8oNTksCIdFN5 IpxZjm0c6DZQRzHElySHK3QCTqJeDsyYlJyUqeasRtgN96IN/HcJWqpOI2IcCzKHFLrti v6Cdqo9/2F8yPfEqn1iRBc1p9KDXJYlxqIvmLZ0BKUwRSKHHnZy1OlBBIsnECTfVS/7n5 W4jXeRF6uYLv/72p1Pa0MGWcNhG4p/U1VCev3/z9lYStsokOJ9veCXf0JN82INwZcMw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796465209; h=DMARC-Filter:DKIM-Signature:Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:Content-Transfer-Encoding:Content-Type: X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=LC9T6at0QYE9+Mqp4gdVIQIYHTAWZM9O8E+4vRkEdZg=; b=VWAkskUr0ilh8VcguVF73Ygn3A9eNGQ8Y5SkuX0En68qgfHZodY1qCR6YH0I8/QM6HT5 EwejmZeKJOpKpcMHJNIxx0lMYdgzAYiRgXwEky55aHx9PGoRzhMpPSbtKCThHSATXxBBY lQxwEmVMGGP16UGXb3P0I288guMIP+MFGi4VSJwS4Gu+yTLWOvoJf7/0BRtfFuu+HDoY2 qLNPNR+nOnpw/tYaOiOEh6N+GYEcpGP3aNRKK6PGV/r5ns3MhonuIwPPZtHgIEyhJDTh4 SGx8izkjoqB5X+SwYb6lPqr4Xnu1FdNpjdpUn4nFZyF7XxRq9Ipd+tm078zJ1z7nHKw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=FJ+URp2q; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.198.10 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010010.outbound.protection.outlook.com [40.93.198.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00667606A322; Sat, 5 Dec 2026 10:06:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 00667606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=FJ+URp2q ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bm6Y5WB2tj8ecSEeAr+W8VvuEZ/SL+Iiat2YWdTyVSkuDF7/BHYAEAjnFISLGCwrhzatO12m37C13JtYClh5u0AjWp8okZ6gtFdCrK4+MbEa9GEkZNXw0i7B1lWRaS+ZYOpoL17Vi4fAXiekWShcdz1Dyli9Pmr/R3pstI8ErouYEdfwaRgnfNFHSmQj3/XMIJJYaPYf7YQo5n3pAEB2YONSd6ZjwhxutCp0cAwU7hrEW9NYaVy/luNJ38qqEYY/NbrIP+WYqM399xDzrzvLZ3nfPUsmmhlptr+93uVg8LfuIB4y9zwaKt7xNn3jQhgJcQxu5ZPuh7Pt8sPnpIU5Tw== 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=LC9T6at0QYE9+Mqp4gdVIQIYHTAWZM9O8E+4vRkEdZg=; b=ApC+oUe+8OjhKknzlSsyhvCMhUR7+jp2RDWkTDnQknBsAtbVpKk9Eev5lu1pBBdUn7KL6B5SkK0Kr1Zr5Qpe7WcBc6XwjyK2qsmafo+FdfMPbUfIIf6WfYXRrQ6A1Lq+9R1kEfDnin6um/eZb/zMFr7UpAOBv476egByH6k6itqVQ1i5KlyaDS/x4CcXYLtXaXfxl6S6QZ/vs9LgaCFzYlAywGQpIlN6KMIYVE4oqI4uFTYS5HR0OZabRa0YWLUS4lT0pvfCZQSx7kAdLP5iIxFvc4K3tOoQ5ZcFuXf8WJYpXQUIOZXAfr6ImdC3n/Zx26nHNokpLGC1gL1r+w/OdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none 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=LC9T6at0QYE9+Mqp4gdVIQIYHTAWZM9O8E+4vRkEdZg=; b=FJ+URp2qyYS7lWlKSZ/S7jz03mIfCIft6ysS7sNI1pRn66CXTD53zFIhKOGKpBljoNC1rikmZtCINq4hL74s0QvSZEUwcjBfeEjAwcHGmNtXtUNmRglxRvtxk4dyoekyc+g3ouxs2OxHffxuUsmr8fH3ntVWMotmkJGFYxfIoH7lHQRGaUVsJojYu1Woc6CHwCcXZl82Z7jiCdHYOBGGaQJfdPjWkO7Na0oBMVhB6Cp8BgGgddFC9ciPP7Tpt0sdkpqEQfaHLGmdGf4AlKDPm2gMncllYXKzOml6SrHfsGboJROZnEwt2DRdhEUwmm4R2qSEJSngbEA89lP0+EEsxQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BL1PR12MB5174.namprd12.prod.outlook.com (2603:10b6:208:31c::19) by CY5PR12MB6083.namprd12.prod.outlook.com (2603:10b6:930:29::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Sat, 5 Dec 2026 10:06:40 +0000 Received: from BL1PR12MB5174.namprd12.prod.outlook.com ([fe80::58de:822b:868:96e9]) by BL1PR12MB5174.namprd12.prod.outlook.com ([fe80::58de:822b:868:96e9%5]) with mapi id 15.21.0688.010; Sat, 5 Dec 2026 10:06:40 +0000 From: Andrea Righi To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , John Fastabend , Vishal Verma , Dave Jiang , Alison Schofield , Matthew Wilcox , Jan Kara , Tejun Heo , David Vernet , Changwoo Min , Josh Don , Vineeth Pillai , Peilin Ye , Zhi Wang , Lee Trager , Balbir Singh , Shameer Kolothum , Himadri Chhaya-Shailesh , NchangRoy , bpf@vger.kernel.org, sched-ext@lists.linux.dev, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 bpf-next 0/5] bpf: Import external pages into an arena Date: Sat, 5 Dec 2026 11:03:56 +0100 Message-ID: <20261205100518.687948-1-arighi@nvidia.com> X-Mailer: git-send-email 2.56.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MI2P293CA0015.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:45::9) To BL1PR12MB5174.namprd12.prod.outlook.com (2603:10b6:208:31c::19) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL1PR12MB5174:EE_|CY5PR12MB6083:EE_ X-MS-Office365-Filtering-Correlation-Id: 86644d48-2793-4873-e1c4-08df52b77457 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|23010399003|18002099003|56012099006|261026121527099003|261028144727099003|261026140227099003|261022105027099003|261022075727099003|261021135927099003|261021123027099003|261021121427099003|10067099003|261102123227099003|261102130727099003|261009223027099003|11063799006|6133799003|4133799003; X-Microsoft-Antispam-Message-Info: 2gAWtN7jOM4b551W0+yzcdaqLvNCGcPvHTIy+UeTAWFuaDgcASl4DKrKmtP8wxcbmD8hYtznOSXq76fzY8ZV8HCaoI9DxAH8eErpWeXQCVw5h6Kzvas1/57zTwX/dGvqBxWNzl33u0xDD1l3Gs7WXEEVbJ3JvGUG0JjBXjHRz/eYleiTna3PWwbZnYUceO/J9OaoikzaGlqp2r8IzNFaKAUDTVJuy1rTVzrmaYMwDzwVHtFg5/PaU1IuQc/rJUBwCexVpMe4De7WDJtJjGjiUt5xM81OT3y/3X4uQV3K46Aw4pg6rj4/xGmfMa/k/0EF25ygmh3j+FAd8nMyiCMTQI5Ly6glqD5oyg1XBn0BV3Mq6rO5XrJmHGe3NuAD24UNF4WAOA/KZtAv0ym5nPYe5/rvk70YnmFqFxTqzdvpkTCqqSzJnKjxLS10qN7TN55nEjNDnuG6OhK2MniWqg/CMzgqi4ol81dfQQ7uOQUwvBXiK86VqxExtFqeCA9/OH4G4iR4dqfw2whNtfRRH8vO9LI5WZwCljKsMK7Fb6k4Q80PwNnJ5SLlzSRuLRYZmhd/e6c7/D841+mSp119EZ6nUDu8b6DWqbBGZZVr6PpZ2JftZqvGXZLvcW89g7J7oPzWGWYxP5Oio3/CgVCYI78xI6xUxuvvDq+eriYlQ7BGoBQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL1PR12MB5174.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(23010399003)(18002099003)(56012099006)(261026121527099003)(261028144727099003)(261026140227099003)(261022105027099003)(261022075727099003)(261021135927099003)(261021123027099003)(261021121427099003)(10067099003)(261102123227099003)(261102130727099003)(261009223027099003)(11063799006)(6133799003)(4133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?LQ5eK3N5G0sqX9tZHPiXQ+NlLimCnM6S8ykHuKX6Slb3eWmd+MR7E2r4qF16?= =?us-ascii?Q?cesJAqmUQwJobSb4JhkcJ1fzrfFfldeAahA3LsYcme0E5qj9jL8OD9VmfzYD?= =?us-ascii?Q?J7A8m1P1T6NAhctKyr363gcWaKqUYDRVF+YkToUG09qphEO6yUXqqw26VYQW?= =?us-ascii?Q?pgKvOtP9uE+dMU3Jyr/MBbgEvhavfcxv2oGi3JZ5ZqhCDaDHjpv1VRH6/OUH?= =?us-ascii?Q?w5UIcy1Td1UgHKLaJihJTj+icQ+YGAeQ3f8BbDcoUSxZWiKZBo5A+briH9w6?= =?us-ascii?Q?O6hUTTb0j7JMfrTcjyqc+yzN/SMPJFXBLdhdd9DXMTAC9996+FUxhKdJw+Bd?= =?us-ascii?Q?QnUDQ0yby5CoOWrO5WqNMu9NQqTrdsQ6OKnlGW7tbFOFuoSQxmKsm5FODFVc?= =?us-ascii?Q?s2qHOjNJdO+5h4fNdB2MhR9lMfBSyxcKlnB1i4EzznOmUo+JEgZ62FUX3/Ay?= =?us-ascii?Q?RFcon5IZg+iPQ6nWy7b5ZX+geInzOVIhVOsQ80lK6ZUS4L6wr0B5wz0wBe8r?= =?us-ascii?Q?meun5qcW8gwxNuws0GvquUTA8JTy/sqPf2l23+lnuRKCe01/rbHfhERXczx5?= =?us-ascii?Q?miGe6nq4dnRMAzteXqbFXPF6XHBf9HDsxPafuTKV+B+Y+bvbnIYuobCIWdXr?= =?us-ascii?Q?4G5KChPBo46UrQkthPpRoUG3TbjAsqS5tZGoCC4zDBnuydLrr2rLXHW4f4fY?= =?us-ascii?Q?FMr4AKUvC5Yp1JgzsEehYC2n9jV0QILDsm0Y0tL0dBLSkbCkMzbARr38hwoO?= =?us-ascii?Q?94oQ/p8tACTNz6/ELUNDpnhQBFeZLa4r0n5peoFKz7vx/wzeHB8+am1NFcmV?= =?us-ascii?Q?PE/5ylpu5flChkfjor6GhoGina+QgOn/q7vTkCXuBlD7Kgw5bPrTMkH5SQ4F?= =?us-ascii?Q?bYp28ovBmklZWh4bTxhvrQTtRlmdfTTxg1BOFXcm6gijAI+qhlrNeLDaT8X/?= =?us-ascii?Q?O3OyN00pvhLpWT25O1ZFf5J1wN4oFlpy/eeb97OMvT54EjDIXqcn17pgzgTD?= =?us-ascii?Q?pAAeuaqiorPyXa74Q2ogN283j92hxGPIkMCsgCoSS4cxzFCU2vP9oAtudVeh?= =?us-ascii?Q?2noV/aQ/itehlcBKYmcXiEw/iTHFka2hB8NZVDbFmRTzNL9WwoqhPPT9+cGf?= =?us-ascii?Q?axYCc3FO31adio9JJILPrM0vL5++IB/ul+fnibjqxMvlvMgFgGuj1My8hQKw?= =?us-ascii?Q?A4JVcgWt7Y/G55zh8FajR9Sd4dQ5y6SOtXYn+xspWtIyeKYOlcEQW8ogxeOR?= =?us-ascii?Q?ua4S18q7PvBuk8OjPeQ6tbo61hMjuXkY6Vhw+SNEHjrzLlHD4FeJaQ74mmCT?= =?us-ascii?Q?kS7zsZQ+lBvK9potVO31hYqIQgP0bq+pxcIUTzG9pGyNQ5LLFcMFHXqwaH6W?= =?us-ascii?Q?tmHgwMG0c1OF029f9J0IqtdQNw4txK6AMhVOYCf6Qhq7o/z7RXUbVTbPVPws?= =?us-ascii?Q?X6rQ2g6dyRInCylogqZDPlhGqvjmB0IaNrJ3+9ao02DF2QBS2XFPmCQWSDK8?= =?us-ascii?Q?6GoXgJ51IO8WLOApGVUPL27lD3hYAI6pTJE3N5Dt60A1CIAUwYLyBChvh6vI?= =?us-ascii?Q?GRr0ll4OTbI845nrRBqfczatjRnfPkEp7d7CyXx/GQEcnLHny9b5TSZ1VzEG?= =?us-ascii?Q?C+q+WrdcC+YJR4L/oJFZyE643vucjz8tvwM6vUo5elCtEnloREfLC/XVOMwG?= =?us-ascii?Q?iHsENg9DxoGVzDho/kONkX8KoGVNoZlj/Z5ura29ePPNdqsfZyO4LhBfy+5u?= =?us-ascii?Q?KZKfn0at+Q=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86644d48-2793-4873-e1c4-08df52b77457 X-MS-Exchange-CrossTenant-AuthSource: BL1PR12MB5174.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2026 10:06:40.0385 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xqIwcdi/Uzp81jrspbmK9rpLXt6453T/OwOLG2j9pmasQybLDlzmO7wGpsdZiZds/g74+1oATGiy/oKPZGxkzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6083 As discussed in the BPF track and the sched_ext microconference at Linux Plumbers 2026 [1][2], shared BPF arenas can provide a generic channel for bidirectional zero-copy communication between BPF programs running on a host and its guests, for example to exchange scheduling hints between host and guest sched_ext schedulers. This series teaches the arena to map pages that it didn't allocate, based on Alexei's prototype [3]. Background ========== An arena can only map pages it allocated itself, so its memory can be shared only with the BPF programs and the user space that map the arena. A host and a guest have no such mapping in common: they need an arena that maps memory supplied by something else, such as the VMM or a paravirt device. Design ====== The arena gains a single primitive, which maps pages supplied from outside at a free arena address. Each call creates one import, kept in an interval tree with its pages, which belong to their supplier, not to the arena: - bpf_arena_free_pages() over any of them releases the whole import: the pages are unmapped and given back to their supplier, and the range goes back to the arena, so the arena doesn't grow as guests come and go, - they are released when the arena is destroyed, - they are not counted in the arena memory usage, - the arena mapping raises SIGBUS on them (SIGSEGV with BPF_F_SEGV_ON_FAULT): user space accesses them through their supplier. There are three ways to supply the pages. Two are sleepable kfuncs for syscall programs, one for each side of a host/guest shared arena, which work with existing VMMs: int bpf_arena_import_memfd(void *map, void __arena *addr, u32 page_cnt, int fd, u64 off); Host side: pins the pages of a memfd, or of any file on tmpfs or hugetlbfs, with memfd_pin_folios() like udmabuf does. The host hands the same file to the VMM as a memory backend, with no change to the VMM. int bpf_arena_import_dax(void *map, void __arena *addr, u32 page_cnt, u64 src); Guest side: the VMM exposes the file as a virtio-pmem or NVDIMM device, which the guest turns into a device-dax device (/dev/daxX.Y). The kfunc pins the device-dax pages mapped at an address of the calling task, and holds a reference on their dev_pagemap until it releases them. It needs CONFIG_DAX=y. Both kfuncs act on the current task, its file descriptors or its address space, so they fail with -EPERM in async callbacks, which may run in another task. The third one is a kernel API, for suppliers that own the pages, such as a paravirt transport: int bpf_arena_map_ext_pages(struct bpf_map *map, u64 addr, struct page **pages, u32 page_cnt, void (*release)(struct page **pages, u32 page_cnt, void *priv), void *priv); int bpf_arena_unmap_ext_pages(struct bpf_map *map, u64 addr, void *priv); The arena calls release() once it no longer maps the pages, whatever the reason. bpf_arena_unmap_ext_pages() revokes them synchronously: when it returns, BPF programs can no longer access the pages and release() has run. release() is called under a mutex of the arena, so it must not take a lock that is held across bpf_arena_unmap_ext_pages(). The only user in this series is bpf_testmod: the API is meant for transports like pvsched, see the discussion on v2 [4][5]. Once one is available, bpf_arena_import_dax() may be deprecated in favor of it. Both sides then see the same pages as arena memory, at an offset known to both of them, so they can agree on a layout in-band, with plain BPF loads and stores, and keep pointers to it in the rest of their arena state. Use case: paravirt scheduling ============================= The git tree below has an additional [DEMO] commit, not meant for upstream, that provides a real, tested use case of this functionality: a pair of sched_ext schedulers, scx_pvhost on the host and scx_pvguest in every guest, which share a few pages per VM through their arenas. The host publishes which vCPUs it has preempted, its idle CPUs and every VM's fair share of the host CPUs; the guests publish their demand and the state of their vCPUs. With that, the guests stop queueing work behind preempted vCPUs and fold onto their share of the host CPUs only while that pays off. On an NVIDIA Vera host (arm64), with 8-vCPU VMs on QEMU or Firecracker, at 2x and 6x overcommit, compared to stock VMs, the paravirt pair is 2.2-3x as fast on hackbench, 1.3-1.9x on a kernel build and serves 1.6-2x the requests of schbench and nginx; tools/sched_ext/scx-pvsched.md in the [DEMO] commit describes the design, the results and how to run it. Known limitations ================= - Imports are released whole: freeing part of an import releases all of it. - On x86 and arm64, a BPF program that accesses pages after their release is cancelled, as with any free page of the arena, and sched_ext disables the scheduler. Whoever releases them has to stop the programs from using them and wait for the ones that are running first, e.g. for an RCU grace period. - Imported device-dax pages keep the device in use: unbinding it blocks until the arena releases them. Revoking them would need a notification from the dax core. - BPF programs have no machine check recovery: on a real NVDIMM, the supplier has to keep bad pages out of the arena. - There is no doorbell: the sched_ext use case polls the shared pages at scheduling events. - Confidential VMs would need the guest to keep the shared pages shared with the host, which the device-dax import doesn't handle. A paravirt transport can do that before it maps the pages with bpf_arena_map_ext_pages(). References ========== [1] https://lpc.events/event/20/contributions/2429/ [2] https://lpc.events/event/20/contributions/2482/ [3] https://lore.kernel.org/r/DM6HVNSP3USV.AJSWS289Z3I9@gmail.com/ [4] https://lore.kernel.org/r/CA+HDTgQ0mx0PgXDps2h2kd8TbJsFWOmJGJmDRGEHZgBZ_qSVwQ@mail.gmail.com/ [5] https://github.com/pvsched/linux Git tree: git://git.kernel.org/pub/scm/linux/kernel/git/arighi/linux.git scx-pvsched Changes in v4: - Complete the deferred frees in bpf_arena_unmap_ext_pages() before revoking the pages: one of them could run later and free what was allocated at the same address in the meantime (Sashiko) - Flush the TLB once when a free releases imports or the arena is destroyed, and don't zap the user mappings if only imported pages are freed (Sashiko) - Check that the current task has an address space before untagging the address in bpf_arena_import_dax(): untagged_addr() uses it on RISC-V - Serialize the bpf_testmod kfuncs that import pages, and compare only the lower 32 bits of their arena address, like the arena does (Sashiko) - Charge the imports and their page arrays to the memory cgroup of the map, instead of the one of the current task - Clarify the kernel-doc: return values, holes filled by a failed import, and frees that race with bpf_arena_unmap_ext_pages() - Rebase on bpf-next, where an access to released pages now cancels the BPF program, and mention it in the known limitations - Link to v3: https://lore.kernel.org/r/20261202182648.2239421-1-arighi@nvidia.com/ Changes in v3: - Make the import kfuncs fail in async callbacks, with bpf_in_async_cb(): from a bpf_task_work callback, a program could import a memfd of another task (BPF CI bot) - Add bpf_arena_map_ext_pages() and bpf_arena_unmap_ext_pages(), to let kernel code import its own pages and revoke them synchronously, and release all the imports through a callback of their supplier (Vineeth Pillai) - Protect the device-dax import from a concurrent unbind with the dax SRCU and dax_alive(), instead of get_online_mems(), which could deadlock with mmap_lock; this requires CONFIG_DAX=y, the kfunc returns -EOPNOTSUPP otherwise (BPF CI bot) - Add a preliminary patch that declares inode_dax() in linux/dax.h, needed to call dax_alive() on the device of a device-dax mapping - Accept tagged addresses in bpf_arena_import_dax() (BPF CI bot) - Document that importing a range of a memfd with holes allocates their pages, and which memory cgroup is charged for them (BPF CI bot) - Link to v2: https://lore.kernel.org/r/20261117103028.4105609-1-arighi@nvidia.com/ Changes in v2: - Drop BPF_F_ARENA_NO_FREE, BPF_F_ARENA_EXPORT and the sized bpffs file, and map pages that the arena didn't allocate instead (Alexei Starovoitov) - Import the host's pages from a memfd with memfd_pin_folios(), the VMM uses the same file as a memory backend (Alexei Starovoitov) - Replace the guest NUMA node with a device-dax import, so the guest's pages never go back to its buddy allocator (Alexei Starovoitov, Josh Don) - Release an import with bpf_arena_free_pages(), instead of keeping the arena at its high watermark (Alexei Starovoitov, Josh Don) - Map the shared pages at an offset known to both sides, instead of discovering it out of band (Josh Don) - Track imports in an interval tree instead of a second range tree and a list, so that a release finds its import without allocating - Link to v1: https://lore.kernel.org/r/20261010224902.1232178-1-arighi@nvidia.com/ Andrea Righi (5): dax: Declare inode_dax() in linux/dax.h bpf: Allow importing memfd pages into an arena bpf: Let kernel code import pages into an arena bpf: Allow importing device-dax pages into an arena selftests/bpf: Test importing pages into an arena drivers/dax/dax-private.h | 1 - include/linux/bpf.h | 21 + include/linux/dax.h | 1 + kernel/bpf/arena.c | 626 +++++++++++++++++++++- tools/testing/selftests/bpf/prog_tests/arena_import.c | 572 ++++++++++++++++++++ tools/testing/selftests/bpf/progs/arena_import.c | 187 +++++++ tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 99 ++++ .../selftests/bpf/test_kmods/bpf_testmod_kfunc.h | 3 + 8 files changed, 1492 insertions(+), 18 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_import.c create mode 100644 tools/testing/selftests/bpf/progs/arena_import.c