From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796572064; b=21+pK5uVImdI27ALB/Rf9E7n7hNWCUxZNr0N9OFcPWCgbT8JG7DldeBA49ufKBer8r8x dfSWmUHPbmLilFI+ss6VUK7w0UZ4JV9FpsSOvEUcnxh8KgF8sbAfMJQ8YYdoi2TVh7D3q lMCHDSYNapwnokH/XLrfxceYF65s7FTLVob7ae5vq99h4cDic/GoxBT3FOmzxtFIKHRYv +AFxz6Vg9UKiLBvuFDTeN2x/ihXjoD7aowF/1fOZ4JUrzthU3mfyfTOGUniVINqSE1vza hSirLXoNtooWtKfpOg81K5IkqDqWJwiiBgWMbx7m9zk4npXJljqfQLGRdvmRa5oLAUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796572064; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=+E4qfcPAS2QbUdLo5ZHEXPcBZcpw+nVAS8/Y4B+Balo=; b=1N/gkPVJVXxjaKS9LdG2rHbK+X+rchxgL4RdF5hvRSL+9H6fnmRz4Av1mRS9cFf8UxnY 5ejpMv1JioBBwTiNNqCd/zU7hlgMDTph/n0rj6wTLkFMskaCinHRY9HGlNvvAD5zuxM3H v17pxYaCY5NVdsr3ahG16IIw9Ictwoco0tuXDObdkDeN8rH5zwTm0zt3ODqvvr6eGGGBs HHRMylLK9QL4sVJ1uAou62RkKnoqh9VVHOJ1MzPhMlJpWfDK0gz7PMvgIJ3tAiQ4AbEAl ORpE7uftmgSbtQ1fpxFnHdTQcu9hybhjBItoQO14o93M1EtlcElE2clhkp2yXj9kPUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KHEIHQ1d; arc=none smtp.remote-ip=209.85.221.53 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AC0B606A31F for ; Sun, 6 Dec 2026 15:47:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7AC0B606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KHEIHQ1d Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-498f5fa5103so1603210f8f.2 for ; Sun, 06 Dec 2026 07:47:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796572063; x=1797176863; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+E4qfcPAS2QbUdLo5ZHEXPcBZcpw+nVAS8/Y4B+Balo=; b=KHEIHQ1dx5hqFTzTxtW7bcjJGD2QjsqUnga91EBbvoGHW5xue1szT/O+7UA/XSMQY1 eVSmHfU7Gb2xDiLgRtz+gJpW2heUg+CfJwhMs5EdTGG3jfahjolWPBzdFdPRBVQUsLjw R1iau9kIvaBlNR11zVOI06EQVokCdNBZKtb+bwEFfJ5h27Kfw6w3aKxnWV4BKXA6XrN4 QdpSF/PTIVkEViVMTiEZpeXNiSjNkNeLeyuuHS2O8hsJD2oryLD7UTFLB0KpXUw1rQIy dk5pw1QynNXDj7zfqcN1pWsOhERRUkPjb5PJywuougWa7GvqoBKmRDac4id17zG61LuI 1KSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796572063; x=1797176863; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+E4qfcPAS2QbUdLo5ZHEXPcBZcpw+nVAS8/Y4B+Balo=; b=liSnx4RPnHHjJRwFb+1K95atkmZwcJkjiVwsuQlxELCqg37oPPYO+FqxvJ9D2DKBag U8vG1w2e7VdKzG5eoO/ul613rQ28d6PWlJBnMMDO8MhmKVsBa7PQC+6jI0vsDxAbPX68 0TSE8AIxF+r9imk6/k3A9gI7c0wxLRqvMYTNyIC0RmZIrbhhEXY9webHS/WIJsIwm+TO P920p43rsuThQ8jxwDEoFU6UJjWFNp96QN+cepqLan2uozuKUoYiKuOG0Ux51K/QojJq yUsIs0jOAetxzFSs6yz1CYmN/cX6jxgzvQVRmVGFVNs5TtBQSMGJp47GZ3ZDZjWe8nLB xKDQ== X-Forwarded-Encrypted: i=1; AL+hErFCu2t5pnycJAOUcH/0UBohF92AuyrO8mc6AmUkkI8Kl33ul8rSwYRJ9rcEFWNvm60AMSDDis5Txv4=@vger.kernel.org X-Gm-Message-State: AB4q+uFKEv3vtXF1y6PH1xkS3TMMHBu5kMP081PTds++m5B4kmjXyMBJ NIPskQPsBr7IzoAO0Pzo+4j/UomkZweaF5PgRGfTZFkOFA4KfTdihTF4 X-Gm-Gg: AZFdTZe6WlltnOkRaK4d9dedZj706fo0yar1zXJGOBOCYbSPTFesnQjtuyHwKHWPjVT ho6MCKx9SWWKJrQRj+HvQikkuhK/nPEuuuptYJnNMTvEWd83hoY+j6o/L9oItGzRhfuD2pQhE/q mi6M3FJhVsT4iTEEKqUNlgnFY1yFf9CPZZ1YdG8IFkL4bj46Bs46sRzDiS1oruOicWLIqX7tQjQ SmZJcGnZV3jHJcKbdXt+ncs07vbbAWBc3u0D3bMGWn3ohSzU7xafT9DRX5l48PKNh4f677zKYAo S2p0cm3re8njteo1cRgjZXW5zU3Obma2nLMhQFgO7o8ixDgivcEOrscZWeZD4hfl8qulYGuyR8K VVCE8yblkzihunZT73qS/gB6qJFdzwJxlNg5iwyupTYyH+Cxo7SwT2o6XG4EnbIQP8K4ad85nU0 oLo7L/7ilxJLZSOmiGb0XY7+rwX624A5LnTO01NrRsyuaujdqtQdFtnMraU89eqj2W3MricKMg2 85b6rhHiQW/kAllyzxVImdA0YAbwkhBCaeZjwpIgc/00nIpP7tqyV2t5HQzIemWJHniGvx5u1Lk HnbHXgsDdNkbmV6mnYlTXpzAiwJAEyYjYfkxeMk0RIKlUxzTt+cu1k5TISKJqN9aIMV7QRrlAx8 = X-Received: by 2002:a05:6000:2401:b0:4b8:6c3e:95e9 with SMTP id ffacd0b85a97d-4d1e86123c5mr15529616f8f.28.1796572062827; Sun, 06 Dec 2026 07:47:42 -0800 (PST) Received: from ?IPV6:2a0d:e487:419d:c934:db1f:58a0:980:8f76? ([2a0d:e487:419d:c934:db1f:58a0:980:8f76]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1738cfa05sm18455880f8f.35.2026.12.06.07.47.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2026 07:47:42 -0800 (PST) Message-ID: <5289de37-6e07-428d-8303-acf3f7c813b1@gmail.com> Date: Sun, 6 Dec 2026 16:47:40 +0100 X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [libc-coord] [PATCH v9 08/14] futex: Create syscall set_robust_list2() To: libc-coord@lists.openwall.com, =?UTF-8?Q?Andr=C3=A9_Almeida?= , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Arnd Bergmann , Sebastian Andrzej Siewior , Waiman Long , Ryan Houdek , Florian Weimer , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org, kernel-dev@igalia.com References: <20261204-tonyk-robust_futex-v9-0-743d68d488b5@igalia.com> <20261204-tonyk-robust_futex-v9-8-743d68d488b5@igalia.com> Content-Language: en-US From: Gabriel Ravier In-Reply-To: <20261204-tonyk-robust_futex-v9-8-743d68d488b5@igalia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/4/26 5:15 PM, André Almeida wrote: > Emulators (like FEX-Emu, to run x86 apps on top of Aarch64) have two > special needs about robust lists: to be able to register more than one > robust list, one of the app being emulated and one list for the emulator > itself; and to be able to walk 32-bit robust lists on a 64-bit > platform without compat entry points. > > The current syscall allows one robust list per task (on x86-64, it > can have two if compat is enabled) and on Aarch64 there's no way to > parse a 32-bit robust list. The current syscall cannot be expanded to > solve both needs due to the lack of `flags` argument, so create a new > syscall, set_robust_list2() with the following signature: > > sys_set_robust_list2(struct robust_list_head __user *head, > unsigned int index, unsigned int flags) > > The new syscall allows setting multiple lists per task, of 64-bit or > 32-bit types. These are the arguments: > > - `*head` is the same structure used in the current syscall. > - `index` is used to set which index of task array of heads to be changed. > It should be between zero and the number of elements in the robust list > array, [0, robust_list2_list_limit). > - `flags` can be used for special operations: > - `FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY`: to avoid conflicts between the > app logic and libc, the kernel provides this special flag to get an > unused index. `index` must be zero and `head` must point to a valid > address. The kernel looks for an empty index, sets `head` there and > returns such index. > - `FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY`: to specify that a given `head` > is a 32-bit pointer. The kernel will later call the appropriate > function to walk the list in 64-bit kernels. `head` should point to > a `struct robust_list_head32`, defined in the uAPI header. Using this > flag from a compat app is a no-op, given that the kernel will flag > every entry as a 32-bit struct anyway. > - Both flags can be combined and used together. > > Kernel is responsible for always providing valid indexes, but userspace is > responsible for managing such indexes afterwards. Userspace can rewrite any > index at any given time. Using `head` as `NULL` to a given index makes it > free to be later returned by the kernel. However, it's invalid to ask for a > new entry while setting `head` as `NULL`. > > And those are the error return values: > > - `EINVAL`: for invalid flags, unaligned `head` address, `index` out of > range, when `head` is NULL or `index` is not zero when using > `FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY`. > - `ENOMEM`: the allocation of the array of robust list heads failed. > - `EFAULT`: `head` address can't be accessed. > - `ENOSPC`: when `FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY` is used but there's > no empty index available at the moment. > > The array of lists is dynamically allocated on first use, but has a fixed > size determined by the kernel. Userspace should use sysctl interfaces > to gather how many `head` indexes are allocated > (`futex.robust_list2_list_limit`) and how many elements each list can > handle (`futex.robust_list2_elements_per_list`). > > 8 slots cover the target use case with headroom. However, userspace should > always check this number and not make assumptions. > > The first two slots are internally reserved for the kernel, to store the > original syscall robust_list_head's (the native and compat one). Map the > indexes in such a way that userspace can't touch those indexes with the new > syscall and needs to use the original syscalls to manipulate such > addresses. > > The array of lists is destroyed only during task exit. There are no > guarantees about the order of the lists. > > Signed-off-by: André Almeida > --- > include/uapi/linux/futex.h | 7 +++++++ > kernel/futex/core.c | 32 ++++++++++++++++++++++++++++++++ > kernel/futex/futex.h | 2 ++ > kernel/futex/syscalls.c | 30 ++++++++++++++++++++++++++++++ > 4 files changed, 71 insertions(+) > > [...] > > diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c > index 8e7aec8fe03b..af75ffb70956 100644 > --- a/kernel/futex/syscalls.c > +++ b/kernel/futex/syscalls.c > @@ -115,6 +115,36 @@ SYSCALL_DEFINE3(get_robust_list, int, pid, > return put_user(head, head_ptr); > } > > +SYSCALL_DEFINE3(set_robust_list2, struct robust_list_head * __user, head, __user should be before the * aiui > + unsigned int, index, unsigned int, flags) > +{ > + size_t align = sizeof(u64), head_size = sizeof(*head); > + bool new = false, compat = false; > + > + if (flags & ~FUTEX_ROBUST_LIST2_FLAGS) > + return -EINVAL; > + > + if (flags & FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY) { > + if (index || !head) > + return -EINVAL; > + new = true; > + } > + > + if (flags & FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY || in_compat_syscall()) { > + compat = true; > + align = sizeof(u32); > + head_size = sizeof(struct robust_list_head32); > + } > + > + if (!IS_ALIGNED((uintptr_t)head, align)) > + return -EINVAL; > + > + if (head && unlikely(!access_ok(head, head_size))) > + return -EFAULT; > + > + return futex_robust_list_install((uintptr_t) head, index, new, compat); > +} > + > long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, > u32 __user *uaddr2, u32 val2, u32 val3) > { >