mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@igalia.com>
To: Thomas Gleixner <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kselftest@vger.kernel.org,
	Ryan Houdek <Sonicadvance1@gmail.com>,
	Waiman Long <longman@redhat.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	linux-api@vger.kernel.org, kernel-dev@igalia.com,
	Davidlohr Bueso <dave@stgolabs.net>,
	Darren Hart <dvhart@infradead.org>, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v8 04/10] futex: Create set_robust_list2() syscall
Date: Tue, 1 Dec 2026 15:07:33 -0300	[thread overview]
Message-ID: <3ab72bfa-0126-49d7-8691-06b5f891bef5@igalia.com> (raw)
In-Reply-To: <8733shrds3.ffs@fw13>

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, &current->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


  reply	other threads:[~2026-12-01 18:07 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 17:31 [PATCH v8 00/10] futex: Create {set,get}_robust_list2() syscalls André Almeida
2026-11-15 17:31 ` [PATCH v8 01/10] futex: Skip test_futex_robust_unlock() if not supported André Almeida
2026-11-30 21:06   ` [tip: locking/futex] " tip-bot2 for André Almeida
2026-11-15 17:31 ` [PATCH v8 02/10] futex: Use explicit sizes for compat_robust_list structs André Almeida
2026-11-15 17:31 ` [PATCH v8 03/10] futex: Make exit_robust_list32() unconditionally available for 64-bit kernels André Almeida
2026-11-15 17:31 ` [PATCH v8 04/10] futex: Create set_robust_list2() syscall André Almeida
2026-11-21  0:14   ` kernel test robot
2026-12-01  1:27   ` Thomas Gleixner
2026-12-01 18:07     ` André Almeida [this message]
2026-11-15 17:31 ` [PATCH v8 05/10] futex: Create get_robust_list2() syscall André Almeida
2026-11-21  0:35   ` kernel test robot
2026-11-21  0:46   ` kernel test robot
2026-11-15 17:31 ` [PATCH v8 06/10] futex: Wire up set_robust_list2 syscall André Almeida
2026-11-15 20:55   ` kernel test robot
2026-11-15 21:30   ` kernel test robot
2026-11-15 17:31 ` [PATCH v8 07/10] futex: Wire up get_robust_list2 syscall André Almeida
2026-11-15 17:31 ` [PATCH v8 08/10] selftests/futex: Expand for set_robust_list2() André Almeida
2026-11-15 17:31 ` [PATCH v8 09/10] selftests/futex: Expand for get_robust_list2() André Almeida
2026-11-15 17:31 ` [PATCH v8 10/10] futex: Use new robust list API internally André Almeida
2026-11-15 20:44   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ab72bfa-0126-49d7-8691-06b5f891bef5@igalia.com \
    --to=andrealmeid@igalia.com \
    --cc=Sonicadvance1@gmail.com \
    --cc=arnd@arndb.de \
    --cc=bigeasy@linutronix.de \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=kernel-dev@igalia.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®