Linux userland API discussions
 help / color / mirror / Atom feed
From: Gabriel Ravier <gabravier@gmail.com>
To: libc-coord@lists.openwall.com,
	"André Almeida" <andrealmeid@igalia.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Waiman Long" <longman@redhat.com>,
	"Ryan Houdek" <Sonicadvance1@gmail.com>,
	"Florian Weimer" <fweimer@redhat.com>,
	"Thomas Gleixner" <tglx@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-api@vger.kernel.org, kernel-dev@igalia.com
Subject: Re: [libc-coord] [PATCH v9 14/14] selftests/futex: Expand for get_robust_list2()
Date: Sun, 6 Dec 2026 17:06:27 +0100	[thread overview]
Message-ID: <48cb7d1c-bf33-4c7c-ad9c-4c5ad54a70bf@gmail.com> (raw)
In-Reply-To: <20261204-tonyk-robust_futex-v9-14-743d68d488b5@igalia.com>

On 12/4/26 5:15 PM, André Almeida wrote:
> Reuse the same selftest for the original set_robust_list() syscall for
> the new set_robust_list2() syscall. Use kselftest variants feature to
> run the relevant tests for both interfaces. Create a new test case to
> get different lists from the same task.
> 
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
>   .../selftests/futex/functional/robust_list.c       | 157 ++++++++++++++++++---
>   1 file changed, 136 insertions(+), 21 deletions(-)
> 
> diff --git a/tools/testing/selftests/futex/functional/robust_list.c b/tools/testing/selftests/futex/functional/robust_list.c
> index 8723f8a3606c..143e36473539 100644
> --- a/tools/testing/selftests/futex/functional/robust_list.c
> +++ b/tools/testing/selftests/futex/functional/robust_list.c
> @@ -51,6 +51,7 @@
>   
>   #ifndef SYS_set_robust_list2
>   # define SYS_set_robust_list2 473
> +# define SYS_get_robust_list2 474
>   
>   #define FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY	0x1
>   #define FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY	0x2
> @@ -109,6 +110,12 @@ static int robust_list2_get_list_limit(void)
>   	return limit;
>   }
>   
> +static int get_robust_list2(int pid, struct robust_list_head **head,
> +			    unsigned int index, unsigned int flags)
> +{
> +	return syscall(SYS_get_robust_list2, pid, head, index, flags);
> +}
> +
>   static bool robust_list2_support(void)
>   {
>   	if (robust_list2_get_list_limit() == -1)
> @@ -230,6 +237,23 @@ static int modify_list(struct robust_list_head *head, int index)
>   	return set_robust_list2(head, index, 0);
>   }
>   
> +static int get_list(pid_t pid, struct robust_list_head **head, bool robust2, int index)
> +{
> +	int ret;
> +
> +	if (!robust2) {
> +		size_t len_ptr;
> +
> +		ret = get_robust_list(pid, head, &len_ptr);
> +		if (sizeof(**head) != len_ptr)
> +			return -EINVAL;
> +
> +		return ret;
> +	}
> +
> +	return get_robust_list2(pid, head, index, 0);
> +}
> +
>   /*
>    * A basic (and incomplete) mutex lock function with robustness
>    */
> @@ -431,40 +455,45 @@ TEST(test_set_robust_list2_inval)
>   /*
>    * Test get_robust_list with pid = 0, getting the list of the running thread
>    */
> -TEST(test_get_robust_list_self)
> +TEST_F(robust_api, test_get_robust_list_self)
>   {
>   	struct robust_list_head head, head2, *get_head;
> -	size_t head_size = sizeof(head), len_ptr;
> -	int ret;
> +	bool robust2 = variant->robust2;
> +	int ret, index = 0;
>   
> -	ret = set_robust_list(&head, head_size);
> -	ASSERT_EQ(ret, 0);
> +	ret = set_list(&head, robust2, 0);
> +	ASSERT_GE(ret, 0);
>   
> -	ret = get_robust_list(0, &get_head, &len_ptr);
> +	ret = get_list(0, &get_head, robust2, 0);
>   	ASSERT_EQ(ret, 0);
>   	ASSERT_EQ(get_head, &head);
> -	ASSERT_EQ(head_size, len_ptr);
>   
> -	ret = set_robust_list(&head2, head_size);
> -	ASSERT_EQ(ret, 0);
> +	ret = set_list(&head2, robust2, &index);
> +	ASSERT_GE(ret, 0);
>   
> -	ret = get_robust_list(0, &get_head, &len_ptr);
> +	ret = get_list(0, &get_head, robust2, index);
>   	ASSERT_EQ(ret, 0);
>   	ASSERT_EQ(get_head, &head2);
> -	ASSERT_EQ(head_size, len_ptr);
>   }
>   
> +struct child_arg_struct {
> +	struct robust_list_head *head;
> +	bool robust2;
> +};
> +
>   static int child_list(void *arg)
>   {
>   	struct child_args *cargs = arg;
>   	struct __test_metadata *_metadata = cargs->_metadata;
> -	struct robust_list_head *head = cargs->arg;
> +	struct child_arg_struct *child_arg = (struct child_arg_struct *) cargs->arg;
> +	struct robust_list_head *head = child_arg->head;
> +	bool robust2 = child_arg->robust2;
>   	int ret;
>   
>   	free(cargs);
>   
> -	ret = set_robust_list(head, sizeof(*head));
> -	ASSERT_EQ(ret, 0)
> +	ret = set_list(head, robust2, 0);
> +	ASSERT_GE(ret, 0)
>   		TH_LOG("set_robust_list error");
>   
>   	/*
> @@ -484,23 +513,25 @@ static int child_list(void *arg)
>    * parent
>    *   2) the child thread still alive when we try to get the list from it
>    */
> -TEST(test_get_robust_list_child)
> +TEST_F(robust_api, test_get_robust_list_child)
>   {
>   	struct robust_list_head head, *get_head;
> +	bool robust2 = variant->robust2;
> +	struct child_arg_struct child = {.robust2 = robust2, .head = &head};
>   	int ret, wstatus;
> -	size_t len_ptr;
>   	pid_t tid;
>   
> +
>   	ret = pthread_barrier_init(&barrier, NULL, 2);
>   	ret = pthread_barrier_init(&barrier2, NULL, 2);
>   	ASSERT_EQ(ret, 0);
>   
> -	tid = create_child(_metadata, &child_list, &head);
> +	tid = create_child(_metadata, &child_list, &child);
>   	ASSERT_NE(tid, -1);
>   
>   	pthread_barrier_wait(&barrier);
>   
> -	ret = get_robust_list(tid, &get_head, &len_ptr);
> +	ret = get_list(tid, &get_head, robust2, 0);
>   	ASSERT_EQ(ret, 0);
>   	ASSERT_EQ(&head, get_head);
>   
> @@ -1050,9 +1081,9 @@ static int child_lock_holder32(void *arg)
>   	struct child_args *cargs = arg;
>   	struct lock_struct32 *locks = cargs->arg;
>   	struct __test_metadata *_metadata = cargs->_metadata;
> -	struct robust_list_head32 *head;
> +	struct robust_list_head32 *head, *head_ptr;
>   	pid_t tid = gettid();
> -	int i, ret;
> +	int i, ret, index;
>   
>   	head = mmap((void *)0x10000, sizeof(*head), PROT_READ | PROT_WRITE,
>   		    MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> @@ -1065,10 +1096,15 @@ static int child_lock_holder32(void *arg)
>   	head->list.next = (uint32_t)(uintptr_t) &head->list;
>   	head->list_op_pending = (uint32_t)(uintptr_t) NULL;
>   
> -	ret = set_robust_list2((struct robust_list_head *) head, 0,
> +	index = set_robust_list2((struct robust_list_head *) head, 0,
>   				FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY |
>   				FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY);
> +	ASSERT_GE(index, 0);
> +
> +	/* Test get list */
> +	ret = get_robust_list2(0, (struct robust_list_head **)&head_ptr, index, 0);
>   	ASSERT_GE(ret, 0);
> +	ASSERT_EQ(head, head_ptr);
>   
>   	/*
>   	 * Take all the locks and insert them in the list
> @@ -1181,4 +1217,83 @@ TEST(test_32bit_lists)
>   	munmap(locks, sizeof(*locks) * CHILD_NR);
>   }
>   
> +/*
> + * Test setting and getting multiple head lists
> + */
> +TEST(set_and_get_robust2)
> +{
> +	struct robust_list_head *head = NULL, *heads;
> +	int list_limit, ret, *index, i, j;
> +
> +	if (!robust_list2_support()) {
> +		SKIP(return, "robust_list2 not supported\n");
> +		return;
> +	}
> +
> +	list_limit = robust_list2_get_list_limit();
> +	ASSERT_GT(list_limit, 1);
> +
> +	heads = malloc(list_limit * sizeof(*heads));
> +	ASSERT_NE(heads, NULL);
> +
> +	index = malloc(list_limit * sizeof(*index));
> +	ASSERT_NE(index, NULL);
> +
> +	/*
> +	 * Insert various elements into the lists
> +	 */
> +	for (i = 0; i < list_limit; i++) {
> +		ret = set_list(&heads[i], true, &index[i]);
> +		ASSERT_GE(ret, 0);
> +		ASSERT_EQ(i, index[i]);
> +	}
> +
> +	for (i = 0; i < list_limit; i++) {
> +		ret = get_list(0, &head, true, index[i]);
> +		ASSERT_EQ(ret, 0);
> +		ASSERT_EQ(head, &heads[i]);
> +	}
> +
> +	/*
> +	 * Modify the list, adding the elements in the other ordering
> +	 */
> +	for (i = 0, j = list_limit; i < list_limit; i++, j--) {
> +		ret = modify_list(&heads[j], index[i]);

Accesses heads[list_limit] (off-by-one heap hosing) and never heads[0]

> +		ASSERT_EQ(ret, index[i]);
> +	}
> +
> +	for (i = 0, j = list_limit; i < list_limit; i++, j--) {
> +		ret = get_list(0, &head, true, index[i]);
> +		ASSERT_EQ(ret, 0);
> +		ASSERT_EQ(head, &heads[j]);
> +	}
> +
> +	/*
> +	 * Delete all elements
> +	 */
> +	for (i = 0; i < list_limit; i++) {
> +		ret = modify_list(NULL, index[i]);
> +		ASSERT_EQ(ret, index[i]);
> +	}
> +
> +	for (i = 0; i < list_limit; i++) {
> +		ret = get_list(0, &head, true, index[i]);
> +		ASSERT_EQ(ret, 0);
> +		ASSERT_EQ(head, NULL);
> +	}
> +
> +	/*
> +	 * Recreate the list. It should support the same number of elements as
> +	 * before, given that we just cleared the list.
> +	 */
> +	for (i = 0; i < list_limit; i++) {
> +		ret = set_list(&heads[i], true, &index[i]);
> +		ASSERT_EQ(ret, index[i]);
> +		ASSERT_EQ(i, index[i]);
> +	}
> +
> +	free(heads);
> +	free(index);
> +}
> +
>   TEST_HARNESS_MAIN
> 


      reply	other threads:[~2026-12-06 16:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:15 [PATCH v9 00/14] futex: Create {set,get}_robust_list2() syscalls André Almeida
2026-12-04 16:15 ` [PATCH v9 01/14] futex: Use explicit sizes for compat_robust_list structs André Almeida
2026-12-04 16:15 ` [PATCH v9 02/14] futex: Make exit_robust_list32() unconditionally available for 64-bit kernels André Almeida
2026-12-04 16:15 ` [PATCH v9 03/14] futex: Give a specific head pointer to exit_robust_list() André Almeida
2026-12-04 16:15 ` [PATCH v9 04/14] futex: Introduce futex_get_robust_lists() and futex_sched_data::robust_lists André Almeida
2026-12-06 15:42   ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 05/14] futex: Create exit_robust_lists() for multi-robust list André Almeida
2026-12-05  9:55   ` kernel test robot
2026-12-04 16:15 ` [PATCH v9 06/14] futex: Use the multi-robust list infrastructure for current syscalls André Almeida
2026-12-06 15:18   ` [libc-coord] " Gabriel Ravier
2026-12-06 15:45   ` Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 07/14] futex: Expose robust_list2 limits via sysctl André Almeida
2026-12-04 16:15 ` [PATCH v9 08/14] futex: Create syscall set_robust_list2() André Almeida
2026-12-06 15:47   ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 09/14] futex: Make futex_task_robust_list() get list by index André Almeida
2026-12-04 16:15 ` [PATCH v9 10/14] futex: Create get_robust_list2() syscall André Almeida
2026-12-04 16:15 ` [PATCH v9 11/14] futex: Wire up set_robust_list2 syscall André Almeida
2026-12-05  9:55   ` kernel test robot
2026-12-05  9:55   ` kernel test robot
2026-12-04 16:15 ` [PATCH v9 12/14] futex: Wire up get_robust_list2 syscall André Almeida
2026-12-04 16:15 ` [PATCH v9 13/14] selftests/futex: Expand for set_robust_list2() André Almeida
2026-12-06 16:03   ` [libc-coord] " Gabriel Ravier
2026-12-04 16:15 ` [PATCH v9 14/14] selftests/futex: Expand for get_robust_list2() André Almeida
2026-12-06 16:06   ` Gabriel Ravier [this message]

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=48cb7d1c-bf33-4c7c-ad9c-4c5ad54a70bf@gmail.com \
    --to=gabravier@gmail.com \
    --cc=Sonicadvance1@gmail.com \
    --cc=andrealmeid@igalia.com \
    --cc=arnd@arndb.de \
    --cc=bigeasy@linutronix.de \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=fweimer@redhat.com \
    --cc=kernel-dev@igalia.com \
    --cc=libc-coord@lists.openwall.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