From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796573041; b=BSUOuPubH5yqHCLIrTMuR3ml7LaRlxJ65UfMGCTfEaxYIHX2Hc8z55ruP1OSc9/6jSZF CFi2DZdpSzdJyahWI4TTxVRUyN5ravRppCpIsZ2JIzyvz/Oe2V7spHcnrYyqtkSsLuLyx uS8XzkQDO9k7JBUxJ2mJjKCt8Eai+3/muDVPZHKi5Vg4KbJ6emKVEWeIaXRtigmYG0RvK GcvqXAkxs76nZGn7xKwIQeY1vmL5cGlTAAYi6yxC7Nsqp6gnFaEGWmz64figPprLMIARE wSwtUJqx6qQi6M3nM8mQNN1mq3Ek3yaROunHMiN9owItgJFTuc3yUKVK4zGy7HOVl7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796573041; 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=NhBPvERtirEMPzGUpHDrrwqp+2+c6j/PCPh+qvWnTFk=; b=0rLi750DKEox8gbV5c8Abd3PDCCJkjmiYQH9/MafScpmRfjM9ubEyKtNPLFYKAAY5Dq5 hi8MmoyYHD7O+gEqZ2+2sEtUMssUntjF2O1dDc3M4z+q+DaI/ELht5WcXeUqivzbChXLk WDjTRlA0dFNKIiidkHFnNwqMpXHFhwGrHAvUMBrocSQGvXbG1U8NI/8HToWft7+Yma/tO WiSLeNqy+LfJjPk3U6KIHUOrWM8P7jrbNXRQFH/TK+n+rT2o6Y1U1QMJKhqUS1ieI50WL 7jtgZPdmc7ai259jGaw4BFLcFTVhcET6Z7oKcLRpLubg60CnFebaXZw7mAihgLdQjOw== 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=Tour0z3n; arc=none smtp.remote-ip=209.85.128.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 2CE6C606A322 for ; Sun, 6 Dec 2026 16:04:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2CE6C606A322 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=Tour0z3n Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4bb72b44a97so18303005e9.0 for ; Sun, 06 Dec 2026 08:04:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796573039; x=1797177839; 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=NhBPvERtirEMPzGUpHDrrwqp+2+c6j/PCPh+qvWnTFk=; b=Tour0z3n1+XijjNl/O1KghjUsbkylsIbHVwrovlcO2EwvBWla5nAXM7jyTj0XxhTep Iu08lz9879vLwxNddcZE3lnryJSha7m2QSw4y9hwTpEGy7xtCq+h1KVtOacG5xNHTLiw b6CON36+U7QD3zmLKpr9DmkpTE8jhRDd06seiW9rK6NgDIgs8nMdtWp8D6c4Mvm8zmZv Qbg8RQmfilBS9t87Dkpg4NNfmL+z3MNwhujZlVRnB3ICCqFHWt/pWBAQ9FSi4UWMcss8 IaOsh+huYAI7Qnq9yWSwPISuvrQ58jf9W7g1ZuJXnFEP59j20jpmW/AXlloedbem4hsS 54eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796573039; x=1797177839; 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=NhBPvERtirEMPzGUpHDrrwqp+2+c6j/PCPh+qvWnTFk=; b=iUswI1LYzhU+EMSGNdsjmzBaucqdEkCeImzyv0IDcGDSjyNGqrkQORKOfIcEIx7T66 sEOhMrYx8qHNgkQzsHjNNXNwfNtcl87td7YCdqWNeWvSESygbstYrNhDsaTLawpcWyQL lX3YJW2jI8QsJu+xanOHb9EBbgUK3Oy3MGpq2cT+VsSveU75/HbY4CeGtzS/bn9XRNWJ Dpk19BEHgSkSj3LBqZ5UeF9EcZM4Rjybm9I/UykHUAPKnKH2x7cahnM+4wcgEJLUDdKG Da/tL8Pn13zfM1LuS0V1yUwJlXdx4sgh4WrNhtzAUdWs6pCSi8FedaSB4ZjImpxFdKaQ UZrw== X-Forwarded-Encrypted: i=1; AL+hErETP5x0/nwLlu+B0WhH7vO2ougQ28w3rPfKthbXvoEWO8uhrfnB1SOE/9P7Srw2x0XQLVHULCS+85s=@vger.kernel.org X-Gm-Message-State: APuU4Z+5PZytOWYKk93zmNO8AXzlJcGTss71bw24qaS66BUh7ORktM/v 25nRWirSG8BKxdD4EfcI/f+XbRe8976CCQvKouui3xzrPY8zhvnthMP3 X-Gm-Gg: AZFdTZfZXFFjhnRW1yNdcVpN+m5+G0oxyd7rlCIh/GUfsE/vDeLAuIbz/CIaTfAjB+4 2w18ARRcA6ElcmX32ExbwiMNT4TlUxG6czu6fiOFAVSVqjlWeeanbRgn7PUqhNqUI6Xibe4SWYW 1my80lbERCVVvl7EDTVsqHjS5kg0YBbzdTBsenqdwqRG5cewYJHga5tc/qvH1xMRuxTpTaANolZ LEfD9RqjBNzNE+uzAx9A8X9zbClprkTqn14X6hCFEjav7ITVs8r02xjGfAzYT63qxeh1U0ZfrqM TlsWPgc3ADwgsrAGkfu5900n1GOm6bYMRZuZD/k1Ebbx3htH6+YnfEZOqV3b0iwxYVWbgtOreCC XM9gS7M4mBXA+cG4Mcm6IoKgCj2N1BQ+YxM3Wf4qmQbK0Y1tRzZ7ZrzrgA6/7s5Z1SMlT4QnNJ4 +bc2zGGft0I8Cl7HTjgib+qP8Tbn+TTNodmwwV3FXcB/5bBAtCdEW6AhVZsO3luKWZcUa+yzMoa VtPwwd8qD8TRrdXw03nweLdgpSVNkRMKT8OqFNRGYr6VAqgsUum/eketeDmyWjPlw+ZsxQgs1D1 Gbv5/8Imod65bCerdfiROwaM3jsajjX7JWTEdhLrmyugZDMgasbpA1fB/R/1atSqPJlFMDODaCQ = X-Received: by 2002:a05:600d:13:b0:4a1:f8cb:7d70 with SMTP id 5b1f17b1804b1-4bbeb8e297amr120125055e9.24.1796573039266; Sun, 06 Dec 2026 08:03:59 -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 5b1f17b1804b1-4bbea29f8casm223268145e9.9.2026.12.06.08.03.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2026 08:03:58 -0800 (PST) Message-ID: Date: Sun, 6 Dec 2026 17:03:56 +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 13/14] selftests/futex: Expand for 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-13-743d68d488b5@igalia.com> Content-Language: en-US From: Gabriel Ravier In-Reply-To: <20261204-tonyk-robust_futex-v9-13-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: > 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 new test cases for > checking invalid parameters, the ability to correctly set multiple lists > for the same task, and to use 32-bit lists in a 64-bit task. > > Signed-off-by: André Almeida > --- > .../selftests/futex/functional/robust_list.c | 443 +++++++++++++++++++-- > 1 file changed, 409 insertions(+), 34 deletions(-) > > diff --git a/tools/testing/selftests/futex/functional/robust_list.c b/tools/testing/selftests/futex/functional/robust_list.c > index 5076a685ba97..8723f8a3606c 100644 > --- a/tools/testing/selftests/futex/functional/robust_list.c > +++ b/tools/testing/selftests/futex/functional/robust_list.c > @@ -49,6 +49,23 @@ > # define BUILD_64 > #endif > > +#ifndef SYS_set_robust_list2 > +# define SYS_set_robust_list2 473 > + > +#define FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY 0x1 > +#define FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY 0x2 > + > +struct robust_list32 { > + uint32_t next; > +}; > + > +struct robust_list_head32 { > + struct robust_list32 list; > + int32_t futex_offset; > + uint32_t list_op_pending; > +}; > +#endif > + > static pthread_barrier_t barrier, barrier2; > > static int set_robust_list(struct robust_list_head *head, size_t len) > @@ -67,6 +84,67 @@ static int sys_futex_robust_unlock(_Atomic(uint32_t) *uaddr, unsigned int op, in > return syscall(SYS_futex, uaddr, op, val, NULL, list_op_pending, val3, 0); > } > > +static int set_robust_list2(struct robust_list_head *head, unsigned int index, > + unsigned int flags) > +{ > + return syscall(SYS_set_robust_list2, head, index, flags, 0, 0); > +} > + > +static int robust_list2_get_list_limit(void) > +{ > + const char *sysctl = "/proc/sys/kernel/futex/robust_list2_list_limit"; > + FILE *f = fopen(sysctl, "r"); > + unsigned int limit; > + > + if (!f) > + return -1; > + > + if (fscanf(f, "%d", &limit) != 1) { Should presumably be %u (technically UB right now :p) > + fclose(f); > + return -1; > + } > + > + fclose(f); > + > + return limit; > +} > + > +static bool robust_list2_support(void) > +{ > + if (robust_list2_get_list_limit() == -1) > + return false; > + > + return true; > +} > + > +FIXTURE(robust_api) {}; > + > +FIXTURE_VARIANT(robust_api) > +{ > + bool robust2; > +}; > + > +FIXTURE_SETUP(robust_api) > +{ > + if (!variant->robust2) > + return; > + > + if (!robust_list2_support()) > + SKIP(return, "robust_list2 not supported"); > +} > + > +FIXTURE_TEARDOWN(robust_api) {} > + > +FIXTURE_VARIANT_ADD(robust_api, robust1) > +{ > + .robust2 = false, > +}; > + > +FIXTURE_VARIANT_ADD(robust_api, robust2) > +{ > + .robust2 = true, > +}; > + > /* > * Basic lock struct, contains just the futex word and the robust list element > * Real implementations have also a *prev to easily walk in the list > @@ -76,6 +154,12 @@ typedef _Atomic(unsigned int) atomic_futex_t; > struct lock_struct { > atomic_futex_t futex; > struct robust_list list; > + bool robust2; > +}; > + > +struct lock_struct32 { > + _Atomic(uint32_t) futex; > + struct robust_list32 list; > }; > > struct child_args { > @@ -118,20 +202,32 @@ static int create_child(struct __test_metadata *_metadata, int (*fn)(void *arg), > /* > * Helper function to prepare and register a robust list > */ > -static int set_list(struct robust_list_head *head) > +static int set_list(struct robust_list_head *head, bool robust2, int *index) > { > int ret; > > - ret = set_robust_list(head, sizeof(*head)); > - if (ret) > - return ret; > - > head->futex_offset = (size_t) offsetof(struct lock_struct, futex) - > (size_t) offsetof(struct lock_struct, list); > head->list.next = &head->list; > head->list_op_pending = NULL; > > - return 0; > + if (!robust2) > + return set_robust_list(head, sizeof(*head)); > + > + ret = set_robust_list2(head, 0, FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY); > + > + if (ret >= 0 && index) > + *index = ret; > + > + return ret; > +} > + > +/* > + * Change a given list index to a different head > + */ > +static int modify_list(struct robust_list_head *head, int index) > +{ > + return set_robust_list2(head, index, 0); > } > > /* > @@ -203,12 +299,12 @@ static int child_fn_lock(void *arg) > struct __test_metadata *_metadata = cargs->_metadata; > struct lock_struct *lock = cargs->arg; > struct robust_list_head head; > - int ret; > + int ret, index; > > free(cargs); > > - ret = set_list(&head); > - ASSERT_EQ(ret, 0) > + ret = set_list(&head, lock->robust2, &index); > + ASSERT_NE(ret, -1) > TH_LOG("set_robust_list error"); > > ret = mutex_lock(lock, &head, false); > @@ -233,15 +329,17 @@ static int child_fn_lock(void *arg) > * in the robust list and die. The parent thread will wait on this futex, and > * should be waken up when the child exits. > */ > -TEST(test_robustness) > +TEST_F(robust_api, test_robustness) > { > struct lock_struct lock = { .futex = 0 }; > atomic_futex_t *futex = &lock.futex; > struct robust_list_head head; > - int ret, pid, wstatus; > + int ret, pid, wstatus, index; > > - ret = set_list(&head); > - ASSERT_EQ(ret, 0); > + lock.robust2 = variant->robust2; > + > + ret = set_list(&head, lock.robust2, &index); > + ASSERT_NE(ret, -1); > > /* > * Lets use a barrier to ensure that the child thread takes the lock > @@ -281,7 +379,7 @@ TEST(test_set_robust_list_invalid_size) > int ret; > > ret = set_robust_list(&head, head_size); > - ASSERT_EQ(ret, 0); > + ASSERT_GE(ret, 0); > > ret = set_robust_list(&head, head_size * 2); > ASSERT_EQ(ret, -1); > @@ -296,6 +394,40 @@ TEST(test_set_robust_list_invalid_size) > ASSERT_EQ(errno, EINVAL); > } > > +/* > + * Test invalid parameters > + */ > +TEST(test_set_robust_list2_inval) > +{ > + struct robust_list_head head; > + int i, ret, index, list_limit; > + > + if (!robust_list2_support()) > + SKIP(return, "robust_list2 not supported\n"); > + > + /* Bad flag */ > + ret = set_robust_list2(&head, 0, 999); > + ASSERT_EQ(ret, -1); > + ASSERT_EQ(errno, EINVAL); > + > + /* List out of range */ > + list_limit = robust_list2_get_list_limit(); > + ASSERT_GT(list_limit, 1); > + > + for (i = 0; i < list_limit; i++) { > + ret = set_list(&head, true, &index); > + ASSERT_EQ(ret, i); > + } > + > + ret = set_list(&head, true, &index); > + ASSERT_EQ(ret, -1); > + ASSERT_EQ(errno, ENOSPC); > + > + /* clear the list */ > + for (i = 0; i < list_limit; i++) > + modify_list(NULL, i); > +} > + > /* > * Test get_robust_list with pid = 0, getting the list of the running thread > */ > @@ -388,12 +520,12 @@ static int child_fn_lock_with_error(void *arg) > struct __test_metadata *_metadata = cargs->_metadata; > struct lock_struct *lock = cargs->arg; > struct robust_list_head head; > - int ret; > + int ret, index; > > free(cargs); > > - ret = set_list(&head); > - ASSERT_EQ(ret, 0) > + ret = set_list(&head, lock->robust2, &index); > + ASSERT_NE(ret, -1) > TH_LOG("set_robust_list error"); > > ret = mutex_lock(lock, &head, true); > @@ -413,15 +545,17 @@ static int child_fn_lock_with_error(void *arg) > * earlier, just after setting list_op_pending and taking the lock, to test the > * list_op_pending mechanism > */ > -TEST(test_set_list_op_pending) > +TEST_F(robust_api, test_set_list_op_pending) > { > struct lock_struct lock = { .futex = 0 }; > atomic_futex_t *futex = &lock.futex; > struct robust_list_head head; > - int ret, wstatus; > + int ret, wstatus, index; > > - ret = set_list(&head); > - ASSERT_EQ(ret, 0); > + lock.robust2 = variant->robust2; > + > + ret = set_list(&head, lock.robust2, &index); > + ASSERT_NE(ret, -1); > > ret = pthread_barrier_init(&barrier, NULL, 2); > ASSERT_EQ(ret, 0); > @@ -450,11 +584,11 @@ static int child_lock_holder(void *arg) > struct child_args *cargs = arg; > struct lock_struct *locks = cargs->arg; > struct robust_list_head head; > - int i; > + int i, index; > > free(cargs); > > - set_list(&head); > + set_list(&head, locks[0].robust2, &index); > > for (i = 0; i < CHILD_NR; i++) { > locks[i].futex = 0; > @@ -495,17 +629,23 @@ static int child_wait_lock(void *arg) > * Test a robust list of more than one element. All the waiters should wake when > * the holder dies > */ > -TEST(test_robust_list_multiple_elements) > +TEST_F(robust_api, test_robust_list_multiple_elements) > { > struct lock_struct locks[CHILD_NR]; > pid_t pids[CHILD_NR + 1]; > int i, ret, wstatus; > > + if (variant->robust2 && !robust_list2_support()) > + SKIP(return, "robust_list2 not supported\n"); > + > + locks[0].robust2 = variant->robust2; > + > ret = pthread_barrier_init(&barrier, NULL, 2); > ASSERT_EQ(ret, 0); > ret = pthread_barrier_init(&barrier2, NULL, CHILD_NR + 1); > ASSERT_EQ(ret, 0); > > + > pids[0] = create_child(_metadata, &child_lock_holder, &locks); > ASSERT_NE(pids[0], -1); > > @@ -532,18 +672,112 @@ TEST(test_robust_list_multiple_elements) > TH_LOG("One or more children failed"); > } > > +static int child_lock_holder_multiple_lists(void *arg) > +{ > + struct child_args *cargs = arg; > + struct __test_metadata *_metadata = cargs->_metadata; > + struct lock_struct *locks = cargs->arg; > + struct robust_list_head *heads; > + int i, list_limit, index, ret; > + > + free(cargs); > + > + list_limit = robust_list2_get_list_limit(); > + ASSERT_GT(list_limit, 1); > + > + heads = malloc(list_limit * sizeof(*heads)); > + ASSERT_TRUE((uintptr_t) heads); > + > + /* > + * Try to clear any exiting list, ignore errors if they didn't exit > + */ > + for (i = 0; i < list_limit; i++) > + modify_list(NULL, i); > + > + /* > + * Given that this thread has no robust list attached yet, it should > + * get as return all available lists in order [0, list_limit) > + */ > + for (i = 0; i < list_limit; i++) { > + ret = set_list(&heads[i], true, &index); > + ASSERT_EQ(ret, i); > + locks[i].futex = 0; > + mutex_lock(&locks[i], &heads[i], false); > + } > + > + pthread_barrier_wait(&barrier); > + pthread_barrier_wait(&barrier2); > + > + /* See comment at child_fn_lock() */ > + usleep(SLEEP_US * 10); > + > + return 0; > +} > + > +/* > + * Similar to test_robust_list_multiple_elements, but instead of one list with > + * several elements, create several lists with one element. > + */ > +TEST(test_robust_list_multiple_lists) > +{ > + int i, ret, wstatus, list_limit; > + struct lock_struct *locks; > + pid_t *pids; > + > + if (!robust_list2_support()) > + SKIP(return, "robust_list2 not supported\n"); > + > + list_limit = robust_list2_get_list_limit(); > + ASSERT_GT(list_limit, 1); > + > + locks = malloc(list_limit * sizeof(*locks)); > + ASSERT_NE(locks, NULL); > + > + pids = malloc(list_limit * sizeof(*pids)); > + ASSERT_NE(pids, NULL); > + > + ret = pthread_barrier_init(&barrier, NULL, 2); > + ASSERT_EQ(ret, 0); > + ret = pthread_barrier_init(&barrier2, NULL, list_limit + 1); > + ASSERT_EQ(ret, 0); > + > + pids[0] = create_child(_metadata, &child_lock_holder_multiple_lists, locks); > + > + /* Wait until the locker thread takes the look */ > + pthread_barrier_wait(&barrier); > + > + for (i = 0; i < list_limit; i++) > + pids[i+1] = create_child(_metadata, &child_wait_lock, &locks[i]); Writes one past the end. > + > + /* Wait for all children to return */ > + ret = 0; > + > + for (i = 0; i < list_limit; i++) { > + waitpid(pids[i], &wstatus, 0); > + if (WEXITSTATUS(wstatus)) > + ret = -1; > + } > + > + pthread_barrier_destroy(&barrier); > + pthread_barrier_destroy(&barrier2); > + > + free(locks); > + free(pids); > +} The last waiter (the one that hoses the heap) is never waited on. Also, ret is neatly assembled and then never checked :) (incidentally, also hoses the heap from the child itself, since it shares memory for locks and that can get freed before it exits, since it isn't waited on, but more of a side effect than anything else :p) > + > static int child_circular_list(void *arg) > { > struct child_args *cargs = arg; > + bool robust2 = cargs->arg; > struct __test_metadata *_metadata = cargs->_metadata; > static struct lock_struct a, b, c; > struct robust_list_head head; > - int ret; > + int ret, index; > > free(cargs); > > - ret = set_list(&head); > - ASSERT_EQ(ret, 0) > + ret = set_list(&head, robust2, &index); > + ASSERT_NE(ret, -1) > TH_LOG("set_list error"); > > head.list.next = &a.list; > @@ -563,11 +797,13 @@ static int child_circular_list(void *arg) > * while processing it so it won't be trapped in an infinite loop while handling > * a process exit > */ > -TEST(test_circular_list) > +TEST_F(robust_api, test_circular_list) > { > + bool robust2 = variant->robust2; > int wstatus; > pid_t pid; > > + create_child(_metadata, child_circular_list, (void *) robust2); Is it normal that this doesn't save/check pid and etc.? > pid = create_child(_metadata, child_circular_list, NULL); > ASSERT_NE(pid, -1); > > @@ -660,8 +896,8 @@ TEST_F(vdso_unlock, test_robust_try_unlock_uncontended) > > *futex = tid; > > - ret = set_list(&head); > - if (ret) > + ret = set_list(&head, false, NULL); > + if (ret == -1) > ksft_test_result_fail("set_robust_list error\n"); > > head.list_op_pending = &lock.list; > @@ -700,8 +936,8 @@ TEST_F(vdso_unlock, test_robust_try_unlock_contended) > > *futex = tid | FUTEX_WAITERS; > > - ret = set_list(&head); > - if (ret) > + ret = set_list(&head, false, NULL); > + if (ret == -1) > ksft_test_result_fail("set_robust_list error\n"); > > head.list_op_pending = &lock.list; > @@ -783,8 +1019,8 @@ TEST_F(futex_op, test_futex_robust_unlock) > > *futex = tid | FUTEX_WAITERS; > > - ret = set_list(&head); > - if (ret) > + ret = set_list(&head, false, 0); > + if (ret == -1) > ksft_test_result_fail("set_robust_list error\n"); > > head.list_op_pending = &lock.list; > @@ -806,4 +1042,143 @@ TEST_F(futex_op, test_futex_robust_unlock) > ASSERT_EQ((uintptr_t)(unsigned long)head.list_op_pending, exp); > } > > +/* > + * 32-bit version of child_lock_holder. > + */ > +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; > + pid_t tid = gettid(); > + int i, ret; > + > + head = mmap((void *)0x10000, sizeof(*head), PROT_READ | PROT_WRITE, > + MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); > + > + ASSERT_TRUE((uintptr_t) head); mmap returns MAP_FAILED on failure, not NULL > + ASSERT_LT(((uint32_t)(uintptr_t) head), 0x7FFFFFFF); > + > + head->futex_offset = (uint32_t) ((size_t) offsetof(struct lock_struct32, futex) - > + (size_t) offsetof(struct lock_struct32, list)); > + 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, > + FUTEX_ROBUST_LIST2_FLAG_NEW_ENTRY | > + FUTEX_ROBUST_LIST2_FLAG_32BIT_ENTRY); > + ASSERT_GE(ret, 0); > + > + /* > + * Take all the locks and insert them in the list > + */ > + for (i = 0; i < CHILD_NR; i++) { > + struct robust_list32 *list = &head->list; > + > + locks[i].futex = tid; > + > + while (list->next != (uint32_t)(uintptr_t) &head->list) > + list = (struct robust_list32 *)(uintptr_t) list->next; > + > + list->next = (uint32_t)(uintptr_t) &locks[i].list; > + locks[i].list.next = (uint32_t)(uintptr_t) &head->list; > + } > + > + pthread_barrier_wait(&barrier); > + pthread_barrier_wait(&barrier2); > + > + /* See comment at child_fn_lock() */ > + usleep(SLEEP_US); > + > + /* Exit holding all the locks */ > + return 0; > +} > + > +static int child_wait_lock32(void *arg) > +{ > + struct child_args *cargs = arg; > + struct __test_metadata *_metadata = cargs->_metadata; > + struct lock_struct32 *lock = cargs->arg; > + atomic_futex_t *futex; > + struct timespec to; > + pid_t tid; > + int ret; > + > + futex = &lock->futex; > + > + pthread_barrier_wait(&barrier2); > + > + to.tv_sec = FUTEX_TIMEOUT; > + to.tv_nsec = 0; > + > + tid = atomic_load(futex); > + > + /* Kernel ignores futexes without the waiters flag */ > + tid |= FUTEX_WAITERS; > + atomic_store(futex, tid); > + > + ret = futex_wait((futex_t *) futex, tid, &to, 0); > + > + ASSERT_EQ(ret, 0); > + ASSERT_TRUE(lock->futex & FUTEX_OWNER_DIED); > + > + return 0; > +} > + > +/* > + * Test to create a 32-bit robust list in a 64-bit kernel. Replicate > + * test_robust_list_multiple_elements, but it's simplified: don't do all the > + * mutex lock dance, just insert futexes in the list and check if the kernel > + * correctly walks the list and wake the threads > + */ > +TEST(test_32bit_lists) > +{ > + struct lock_struct32 *locks; > + pid_t pids[CHILD_NR + 1]; > + int i, ret, wstatus; > + > +#ifndef BUILD_64 > + SKIP(return, "Test only for 64-bit\n"); > +#endif > + > + if (!robust_list2_support()) > + SKIP(return, "robust_list2 not supported\n"); > + > + locks = mmap((void *)0x20000, sizeof(*locks) * CHILD_NR, > + PROT_READ | PROT_WRITE, > + MAP_FIXED_NOREPLACE | MAP_PRIVATE | MAP_ANONYMOUS, > + -1, 0); > + > + ASSERT_NE(locks, NULL); mmap returns MAP_FAILED on failure, not NULL > + ASSERT_LT((uintptr_t) locks, 0x7FFFFFFF); > + > + ret = pthread_barrier_init(&barrier, NULL, 2); > + ASSERT_EQ(ret, 0); > + ret = pthread_barrier_init(&barrier2, NULL, CHILD_NR + 1); > + ASSERT_EQ(ret, 0); > + > + pids[0] = create_child(_metadata, &child_lock_holder32, locks); > + > + /* Wait until the locker thread takes the look */ > + pthread_barrier_wait(&barrier); > + > + for (i = 0; i < CHILD_NR; i++) > + pids[i+1] = create_child(_metadata, &child_wait_lock32, &locks[i]); > + > + /* Wait for all children to return */ > + ret = 0; > + > + for (i = 0; i < CHILD_NR; i++) { > + waitpid(pids[i], &wstatus, 0); > + if (WEXITSTATUS(wstatus)) > + ret = -1; > + } > + > + pthread_barrier_destroy(&barrier); > + pthread_barrier_destroy(&barrier2); > + > + munmap(locks, sizeof(*locks) * CHILD_NR); > +} Also off-by-one in the wait loop as in test_robust_list_multiple_lists, and fails to check ret (and can segfault that last unwaited child from munmap as a side effect :p). > + > TEST_HARNESS_MAIN >