From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=213.97.179.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796148452; b=pBbTUrrUnwC70EFc3ylcDYfZ/wBa+/kgBBfjzJJR/IADmhaDvTO0MV3P4h90pr/jFh9a dUNEGwDwxRU4p3/crR/HX16aD9Oda5qFAVFXl0YmJWXjoUp6DyqsofHtfkgr5ztAclO7W lnMmrWBcGsMf/R7Eu+i2/70ZmYZOuFWe3sd1/ZvQ99EEOdcPowMkAIXYPw55rE4EeBTjq QM9QfIJyawgnlXSTJVEjPCr5t9YdRILG/y38h5lAiuhk2l/3NRnnYNjJdSPaD1BFQwo1W CslDwFPCYrdDBwe7D/zx6MNnsPEc0enLgQikl9vszJjOrii7t/cRGZ8uRX1YlwABQdA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796148452; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=E8oQSFEu042aIlx/4HGusOtABWcV1eCbQGk5ShzDzgw=; b=SOabg5Std8MLtEndS4AIPp62G3m/OrFFKUcRZ1CUS+bY+dSZ+FHTQA9vnWJDSXhQoKpp 6+wd6BuA4FMgvAtiXF5CkihJZcnEcxKgePaPcGh1jB1Ybc/9idVjKRGXX+alewTfz9BC/ ROY1ofrVhjUumMGeX3LjLHWPZRMHU56zQU9YsYcKiNkGklslnth6XWPIny4q5no+lQ3V8 oEE5AMJ+WVvOh30TesQ3ZjYrga8ePO0nB+Mb58/5yKJS1WcSsP9wi3TU4MEOtTAgJThtn v9LjUSV/ivZlNYXzlxBxUgtVIP4Of3xpj/rM7/InbO2V8gfuFG55lwb2J2OpnVOG7RA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=Lza7LTgQ; arc=none smtp.remote-ip=213.97.179.56 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB294606A31A; Tue, 1 Dec 2026 18:07:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EB294606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=Lza7LTgQ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:From:Cc:To:Subject: MIME-Version:Date:Message-ID:From:Reply-To; bh=E8oQSFEu042aIlx/4HGusOtABWcV1eCbQGk5ShzDzgw=; t=1796148450; x=2111508450; b=Lza7LTgQ93xhJQ00kH553fPQIPVSiMbNGILQGQdvRXfFZKQx0hwOpSIJMLXsI4FPNfTPqwZ5tps eMw3D4RzHuQ9EP7br4M3ZxImM4yqr7U0b9bl1+8M7EPWyl1Wwv/XGQ1HC9xjUltmUXZFMSPGaJTmA i/T6OduMLgOzMJ8eHPVVwoKY2mN5teRKFkP7fLXMDm12BZoSCQt2w03lSfTy+mK/vWQfMAtyHdpTv 9jgM7pYtqrvWBMs24ZRwRzrcSoSJ+3R/PkT1L0ewdWP3wc/55xijBgpKwJUZQk3WCakfbVcS19dEE cGijlQ8w1qnZ8wBwl6cD01DlMiu3XBZ4PyPg==; Received: from [177.172.123.95] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) (envelope-from ) id 1xYSGE-00000000mcR-2UKC; Tue, 01 Dec 2026 19:07:26 +0100 Message-ID: <3ab72bfa-0126-49d7-8691-06b5f891bef5@igalia.com> Date: Tue, 1 Dec 2026 15:07:33 -0300 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 04/10] futex: Create set_robust_list2() syscall To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , linux-kselftest@vger.kernel.org, Ryan Houdek , Waiman Long , Sebastian Andrzej Siewior , linux-api@vger.kernel.org, kernel-dev@igalia.com, Davidlohr Bueso , Darren Hart , Arnd Bergmann References: <20261115-tonyk-robust_futex-v8-0-a4fe47333a28@igalia.com> <20261115-tonyk-robust_futex-v8-4-a4fe47333a28@igalia.com> <8733shrds3.ffs@fw13> Content-Language: en-US From: =?UTF-8?Q?Andr=C3=A9_Almeida?= In-Reply-To: <8733shrds3.ffs@fw13> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Thomas, Em 30/11/2026 22:27, Thomas Gleixner escreveu: > On Sun, Nov 15 2026 at 14:31, AndrĂ© Almeida wrote: > >> +enum robust_list2_cmd { >> + FUTEX_ROBUST_LIST_CMD_CREATE_64, >> + FUTEX_ROBUST_LIST_CMD_CREATE_32, > > This is a complete misnomer. It does not create a robust list. It > installs a robust list pointer which is handed in from user space. Agreed, to install (or to set) looks like a better name. I've based the naming (and much of the design bellow) on this email from you: https://lore.kernel.org/all/87zfdto0bv.ffs@tglx/ > >> + FUTEX_ROBUST_LIST_CMD_MODIFY_64, >> + FUTEX_ROBUST_LIST_CMD_MODIFY_32, >> + FUTEX_ROBUST_LIST_CMD_LIST_LIMIT, >> + FUTEX_ROBUST_LIST_CMD_USER_MAX, > > >> +int futex_robust_list_create(uintptr_t head, enum robust_list2_cmd cmd) >> +{ >> + uintptr_t *rl = current->futex.robust_lists, entry = FUTEX_ROBUST_LIST_ENTRY_INUSE; >> + unsigned int index; >> + >> + if (!rl) { >> + rl = kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL); >> + if (!rl) >> + return -ENOMEM; >> + >> + scoped_guard(mutex, ¤t->futex.exit_mutex) { >> + /* check if another thread set the list before us */ > [...] >> + /* >> + * If the list type is the same as the kernel bitness, always >> + * calls exit_robust_list(). exit_robust_list32() is only for >> + * 32-bit lists in a 64-bit kernel. >> + */ > > You really have a tendency to comment the obvious... Right, I will be briefer in the comments for the v9. [...] > >> + if (futex_in_32bit_syscall()) >> + return -EOPNOTSUPP; >> + align = sizeof(u64); >> + } >> + >> + switch (cmd) { >> + case FUTEX_ROBUST_LIST_CMD_CREATE_64: >> + case FUTEX_ROBUST_LIST_CMD_CREATE_32: >> + if (index) >> + return -EINVAL; > > This check is pretty pointless because 0 is also a valid index, no? The idea is that, when issuing a create command, userspace can't choose the index. The idea is to refuse any index to avoid confusion. [...] > >> + return futex_robust_list_modify(entry, cmd, index); >> + case FUTEX_ROBUST_LIST_CMD_LIST_LIMIT: >> + return FUTEX_ROBUST_LISTS_PER_USER; > > This does not make sense at all because that's a compile time constant > so it should be read from a sysctl and not be multiplexed into this > syscall just because, no? > Yes, sounds good to me. >> + } >> + >> + return -EINVAL; >> +} > > This whole thing can be simplified so it becomes comprehensible. > > SYSCALL_DEFINE4(set_robust_list2, struct robust_list_head * __user, head, unsigned int, > cmd, unsigned int, index, unsigned int, flags) > { > if (flags || cmd >= FUTEX_ROBUST_LIST_CMD_USER_MAX) > return -EINVAL; > > size_t align = sizeof(u32); > > switch (cmd) { > case FUTEX_ROBUST_LIST_CMD_INSTALL_64: > case FUTEX_ROBUST_LIST_CMD_MODIFY_64: > if (futex_in_32bit_syscall()) > return -EOPNOTSUPP; > align = sizeof(u64); > } > > if (unlikely(!access_ok(uaddr, align))) > return -EFAULT; > > uintptr_t entry = (__force uintptr_t)head; > > if (entry % align) > return -EINVAL; > > switch (cmd) { > case FUTEX_ROBUST_LIST_CMD_INSTALL_32: > entry |= FUTEX_ROBUST_LIST_ENTRY_32BIT; > fallthrough; > case FUTEX_ROBUST_LIST_CMD_INSTALL_64: > return futex_robust_list_create(entry); > > case FUTEX_ROBUST_LIST_CMD_MODIFY_32: > entry |= FUTEX_ROBUST_LIST_ENTRY_32BIT; > fallthrough; > case FUTEX_ROBUST_LIST_CMD_MODIFY_64: > return futex_robust_list_modify(entry, index); > } > > return -EINVAL; > } > > No? > > But I really have to ask how the distinction between INSTALL and MODIFY > is actually valuable. > > This whole thing can be made _ONE_ operation, which removes boatloads of > pointless code and solves the install NULL and then modify issue I > pointed out above: > > static int __robust_list_install(uintptr_t *rl, , unsigned int idx, uintptr_t entry) > { > rl[idx] = entry & FUTEX_ROBUST_LIST_ENTRY_MASK ? : NULL; > return idx - FUTEX_ROBUST_LIST2_IDX; > } > > int robust_list_install(uintptr_t entry, unsigned int idx) > { > uintptr_t *rl = robust_get_lists(); > > if (!rl) > return -ENOMEM; > > // Update an distinct entry? > if (idx != FUTEX_ROBUST_LIST2_NEW_ENTRY) { > if (idx >= FUTEX_ROBUST_LIST2_MAX_USER_IDX) > return -EINVAL; > > return __robust_list_install(rl, idx, entry); > } > > /* Search for an empty slot */ > for (idx = FUTEX_ROBUST_LIST2_IDX; idx < FUTEX_ROBUST_LIST2_MAX_IDX; idx++) { > if (!rl[idx]) > return __robust_list_install(rl, idx, entry); > } > return -ENOSPC; > } > > Note that this does not care whether there is a bitness mismatch in case > of updating a particular index. Why? > > The kernel is not responsible for user space to get its act together > and there is zero impact for the kernel if user space screws that up. > > No? That sounds good to me too. The main concern here is to be able to both the libc and the application to use the same interface without poking each other. If there's a way to userspace to ask for a brand new entry (like you suggested above with FUTEX_ROBUST_LIST2_NEW_ENTRY) that's great and works for me. > > That said, the whole ordering approach of this patch set is backwards > and unreviewable. > > What you want to do is: > > 1) Preperatory patches > > Patch 02/03 plus patches which change the exit_robust_list() > signature and add missing sanity checks to the existing syscalls. > > 2) Introduce robust_get_lists() which either returns the existing > robust lists pointer or allocates the robust list array > > uintptr_t *robust_get_lists(void) > { > uintptr_t *rl = current->futex.robust_lists; > > if (!rl) { > rl = kcalloc(FUTEX_ROBUST_LIST2_MAX_IDX, sizeof(*rl), GFP_KERNEL); > current->futex.robust_lists = rl; > } > return rl; > } > > 3) Provide the exit() walker for this new thing and invoke it which > will be a NOOP because the list is empty. > > 4) Use #2/#3 for the existing syscalls and remove the then unused leftovers > > SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head, size_t, len) > { > uintptr_t *rl = robust_get_lists(); > > if (!rl) > return -ENOMEM; > rl[FUTEX_ROBUST_LIST_NATIVE_IDX] = head; > return 0; > } > ... > > 5/6) Add the new syscalls > > 7/8) Wire up the syscalls > Thanks again for the valuable feedback and the proposed design, I will work on that for the v9. > Thanks, > > tglx