From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796571932; b=SgKCxUod3NA16qWqQ5Wj71Bm3mdExJjPV/AHo2nlWlDuOqAH0YNUP2H3Zqhz6SG1FaQv GOAh8SCKhPnhx6m1c09ISK3AbfxUro9oMqixnzMXtfELjSQMysVgTs8sfJzWUq8QxHuE9 7XaXjJAAmqWV/ZCvCobdqXkm+jGAr7H9h+dmahVUbeDDOGP4yrubGMdppshf5PT+VuAmd h2XswZvP/SWsfiSaQTC2TE0iMV+6KOC6Gbo8KK2GxCWDhRaJ4Uq4RDKGiZ4Tzh7vbu0mH riUJNCxkET1hemugeTS64LifcUJRLYe9wYuVzpTLzzwm7ZgaXmNQj34wvnsp0F7R3hA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796571932; 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=fFcaW9gUqlDtu1c7VFjX6sHDhKI8J9SbqxcGFtaPsE0=; b=WfEenWiMm5gMOrQCg9SW+4ODHqNX+Pio6xNr+haXLtq66pqq5A07R4rnXqgLP2tIrVxE Vl/plnLWjNScC0MT7fm5E99NmaKQcYDQvSeeQ3N/lSFZ83FNq2Fc/M7Fhh+X9RKqfoFvD 9+XvDma5QXPDzWAzEpd6kgJAkdlgQRvGUmLOKaUceGb+cw7ywHE3j6hHDvmy4SHt08b3r NzXX0ABM3A0eTz0GYyGzM9pfHFGUV7gLmRsL/Jld6mJKvYWAWKhg4v/teSDokWj6XdrhE hmRL4Yfr3CFCyc7rH598cB2xioDUGrYJwRdL3wQ5nGV1ZOYlksU5rvvRAQahNWaJvcA== 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=m0eaXikS; arc=none smtp.remote-ip=209.85.221.47 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 B2500606A321 for ; Sun, 6 Dec 2026 15:45:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2500606A321 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=m0eaXikS Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-48e47347279so1725850f8f.1 for ; Sun, 06 Dec 2026 07:45:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796571930; x=1797176730; 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=fFcaW9gUqlDtu1c7VFjX6sHDhKI8J9SbqxcGFtaPsE0=; b=m0eaXikSHCniFx8c+rO0g+L7b14ik30y+3mmaZNxq2MoTOx//meeGkBZ0Qfq1+hITv 8DmAitzDGIDSGETUQPqxzdJhtXJyD5zCmjNTc1UjIeJA9YH3WdJiHYniKGnog2DHCV7E dOoxP32nhO6Br1TP38GcKYo7mk0V2uvtbxHUwNlCF4qIE0LblwQwfIawh4zQ+sKfrvO/ mcS04TpW6x+61LBiBJSvyhnHpSyF1fl8VXQf7rBnpSiiVhElZxdggK+yowhAD0ZdAZu7 aZov1aXMvgnP++dgzcZQr/iVyWHfGnknNS+xpSb6eYm8T8L5VcxcX6UhHyyTEWssLs0r OYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796571930; x=1797176730; 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=fFcaW9gUqlDtu1c7VFjX6sHDhKI8J9SbqxcGFtaPsE0=; b=FCiV/MCQ68WFvhn9DJRO5lM0NVb9fVAlCpElJp/NHXczrb20b9SQOESh+KEw5t7QxQ AY0GyXDL6lm1oQdbkMTvy0jiFcPaCH9ra/D0ojH9wWrkg/F9gKwvjJtkqf1Y7zj6TV73 A4r59lRpdX1/vQlp4EqIPTHzmYTWa0DKz70Uipen5NDTFWKk1hSVpegauJ0G3UnD2mZM UlswpjQgD31avNU/CyNSQgUm/lgDAba2fHbR2iEVQhLcpHeDNGEumnkvjjcasXVyB5wU yAcaVBibGbw2sGEAQ1fC1HPLOltpQu7Hnzkoz2w/dnhN8TuDmOkJw766xTeL4vODVdIZ JUKg== X-Forwarded-Encrypted: i=1; AL+hErHIQuDUv5MLha5qaeRU1CPPb31Ab8inJPd9QVXd/XIENLpiSc3q1/Tlpkoz53jIoqKSE/r/otRYhhk=@vger.kernel.org X-Gm-Message-State: AB4q+uGXKRI70AxmObzG3bggtnIqvi3OCre7tch9aCE0+AQcYIZY2G72 LRn5KXucbVSZHByf/9UvDKztwmowj1+cVwrzjz9uOR34Pjx2EZj9Sq8G X-Gm-Gg: AZFdTZfEwSP+9QD3tywPmKkIzM6hwPFI90GIbqJBXuFITMkDnSL9iom8sNTwAwc2jvv q+13g2zSykXj9HD4eqXevbCUY1lYFsT17OyO1So5rkhU5dY0Cs1tXksGSkGlZoZ9hLvKV4NFUxA ewQpaZTNSk0bFnt7Lgxj8yTxMSuuZJK/6WRURxXyzfcrPAR+4kW/r4viwRnyhbJ2RvOcmcCz22L OR+jHeBjAFIX527dmfA8kemS+MUaH6Uz6sRPIW6NivLNBTXRPYKH3NjFcjwH9iJ+WcSMP2VHQ/f t4R6RgwgVUqRIZ8podG8I32o98rYFg7pIHl8LnEbbSck2Z+ip2RzLg3H6r6hB19wUnXPxxw8FPV pTISjBTztvE51/syjjjkxH0jOF6OhKZ8lA07LmO2JyHtHulX6KqgGFn5Qhx6xS0s+E2HLU0jGvD fJ9TUC6yodPGrCCJN/4zxf/hu4ioCTElSRUTbZZBCPBu5a48GWGUB9GApsGbVdfiZsV19ZVgmAX Z7ohzGgV0fSnGF93GHB5WPukuACdoOpJFHk2ZrDiMtxyyFMbBIkr5iBK5NGQHu+M9K48eSdNJyZ Vqog+0MlXymnhV40lv44D5CAFFHXXUj0pogAXQBinn5CAIqGZS6FbHfqtfY+6yCFdOnpu56xUN0 = X-Received: by 2002:a05:6000:480f:b0:4b7:760c:71ac with SMTP id ffacd0b85a97d-4d1e8612016mr16380104f8f.24.1796571929896; Sun, 06 Dec 2026 07:45:29 -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-4d16e0b0c9bsm18222113f8f.3.2026.12.06.07.45.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2026 07:45:29 -0800 (PST) Message-ID: Date: Sun, 6 Dec 2026 16:45:27 +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 06/14] futex: Use the multi-robust list infrastructure for current syscalls 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-6-743d68d488b5@igalia.com> Content-Language: en-US From: Gabriel Ravier In-Reply-To: <20261204-tonyk-robust_futex-v9-6-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: > Use the multi-robust list infrastructure for the current system calls and > drop robust_list and robust_list32 from struct futex_sched_data, relying > solely on the robust_lists member. Make use of the reserved array positions > for the current system call and the compat entry point. > > For the robust_list_clear_pending() functions, walk the array of robust > list heads checking which one, if any, matches the pop address. > > Syscall set_robust_list() now can return -ENOMEM in case the allocation > fails. > > Signed-off-by: André Almeida > --- > include/linux/futex.h | 4 ---- > include/linux/futex_types.h | 4 ---- > kernel/futex/core.c | 58 +++++++++++++++++++++++++++++++-------------- > kernel/futex/syscalls.c | 24 +++++++++++++++---- > 4 files changed, 59 insertions(+), 31 deletions(-) > > diff --git a/include/linux/futex.h b/include/linux/futex.h > index 0da95f94cfe9..75a83f262d1c 100644 > --- a/include/linux/futex.h > +++ b/include/linux/futex.h > @@ -72,10 +72,6 @@ static inline void futex_init_task(struct task_struct *tsk) > INIT_LIST_HEAD(&tsk->futex.pi_state_list); > tsk->futex.state = FUTEX_STATE_OK; > mutex_init(&tsk->futex.exit_mutex); > - tsk->futex.robust_list = NULL; > -#ifdef CONFIG_COMPAT > - tsk->futex.robust_list32 = NULL; > -#endif > tsk->futex.robust_lists = NULL; > } > > diff --git a/include/linux/futex_types.h b/include/linux/futex_types.h > index 20123110c80d..a2b4ec0cb125 100644 > --- a/include/linux/futex_types.h > +++ b/include/linux/futex_types.h > @@ -21,10 +21,6 @@ struct robust_list_head; > * @state: Futex handling state to handle exit races correctly > */ > struct futex_sched_data { > - struct robust_list_head __user *robust_list; > -#ifdef CONFIG_COMPAT > - struct robust_list_head32 __user *robust_list32; > -#endif > uintptr_t *robust_lists; > struct list_head pi_state_list; > struct futex_pi_state *pi_state_cache; > diff --git a/kernel/futex/core.c b/kernel/futex/core.c > index d15906f3c80c..a0a391330408 100644 > --- a/kernel/futex/core.c > +++ b/kernel/futex/core.c > @@ -1223,7 +1223,8 @@ static void exit_robust_list(struct task_struct *curr, > > static bool robust_list_clear_pending(unsigned long __user *pop) > { > - struct robust_list_head __user *head = current->futex.robust_list; > + uintptr_t *rl = current->futex.robust_lists; > + unsigned int i; > > if (!put_user(0UL, pop)) > return true; > @@ -1237,8 +1238,24 @@ static bool robust_list_clear_pending(unsigned long __user *pop) > * task exits. Better a few stale futexes than corrupted memory. But > * that's mostly an academic exercise. > */ > - if (pop == (unsigned long __user *)&head->list_op_pending) > - current->futex.robust_list = NULL; > + if (!rl) > + return false; > + > + for (i = 0; i < FUTEX_ROBUST_LIST2_MAX_IDX; i++) { > + struct robust_list_head __user *head; > + > + if (!rl[i] || rl[i] & FUTEX_ROBUST_LIST2_ENTRY_32BIT) > + continue; > + > + head = (struct robust_list_head __user *) > + (rl[i] & FUTEX_ROBUST_LIST2_ENTRY_MASK); > + > + if (pop == (unsigned long __user *)&head->list_op_pending) { > + rl[i] = (uintptr_t) NULL; Doesn't this (and all the other rl[i] accesses too) need WRITE_ONCE/READ_ONCE to not be flagged by KCSAN? > + break; > + } > + } > + > return false; > } > > @@ -1342,14 +1359,31 @@ static void exit_robust_list32(struct task_struct *curr, > > static bool robust_list_clear_pending32(u32 __user *pop) > { > - struct robust_list_head32 __user *head = current->futex.robust_list32; > + uintptr_t *rl = current->futex.robust_lists; > + unsigned int i; > > if (!put_user(0U, pop)) > return true; > > /* See comment in robust_list_clear_pending(). */ > - if (pop == &head->list_op_pending) > - current->futex.robust_list32 = NULL; > + if (!rl) > + return false; > + > + for (i = 0; i < FUTEX_ROBUST_LIST2_MAX_IDX; i++) { > + struct robust_list_head32 __user *head; > + > + if (!rl[i] || !(rl[i] & FUTEX_ROBUST_LIST2_ENTRY_32BIT)) > + continue; > + > + head = (struct robust_list_head32 __user *) > + (rl[i] & FUTEX_ROBUST_LIST2_ENTRY_MASK); > + > + if (pop == (unsigned __user *)&head->list_op_pending) { > + rl[i] = (uintptr_t) NULL; > + break; > + } > + } > + > return false; > } > #else > @@ -1514,18 +1548,6 @@ static void futex_cleanup(struct task_struct *tsk) > if (unlikely(tsk->futex.robust_lists)) > exit_robust_lists(tsk); > > - if (unlikely(tsk->futex.robust_list)) { > - exit_robust_list(tsk, tsk->futex.robust_list); > - tsk->futex.robust_list = NULL; > - } > - > -#ifdef CONFIG_64BIT > - if (unlikely(tsk->futex.robust_list32)) { > - exit_robust_list32(tsk, tsk->futex.robust_list32); > - tsk->futex.robust_list32 = NULL; > - } > -#endif > - > if (unlikely(!list_empty(&tsk->futex.pi_state_list))) > exit_pi_state_list(tsk); > } > diff --git a/kernel/futex/syscalls.c b/kernel/futex/syscalls.c > index 4a45bace75fc..8e7aec8fe03b 100644 > --- a/kernel/futex/syscalls.c > +++ b/kernel/futex/syscalls.c > @@ -27,21 +27,31 @@ > */ > SYSCALL_DEFINE2(set_robust_list, struct robust_list_head __user *, head, size_t, len) > { > + uintptr_t *rl = futex_get_robust_lists(); > + > /* The kernel knows only one size for now. */ > if (unlikely(len != sizeof(*head))) > return -EINVAL; > > - current->futex.robust_list = head; > + if (!rl) > + return -ENOMEM; > + > + rl[FUTEX_ROBUST_LIST2_NATIVE_IDX] = (uintptr_t)head; > return 0; > } > > static inline void __user *futex_task_robust_list(struct task_struct *p, bool compat) > { > + uintptr_t *rl = p->futex.robust_lists; > + > + if (!rl) > + return NULL; > + > #ifdef CONFIG_COMPAT > if (compat) > - return p->futex.robust_list32; > + return (void __user *)rl[FUTEX_ROBUST_LIST2_COMPAT_IDX]; > #endif > - return p->futex.robust_list; > + return (void __user *)rl[FUTEX_ROBUST_LIST2_NATIVE_IDX]; > } > > static void __user *futex_get_robust_list_common(int pid, bool compat) > @@ -76,7 +86,7 @@ static void __user *futex_get_robust_list_common(int pid, bool compat) > up_read(&p->signal->exec_update_lock); > put_task_struct(p); > > - return head; > + return (void __user *)((uintptr_t) head & FUTEX_ROBUST_LIST2_ENTRY_MASK); > > err_unlock: > up_read(&p->signal->exec_update_lock); > @@ -481,11 +491,15 @@ SYSCALL_DEFINE4(futex_requeue, > COMPAT_SYSCALL_DEFINE2(set_robust_list, struct robust_list_head32 __user *, head, > compat_size_t, len) > { > + uintptr_t *rl = futex_get_robust_lists(); > + > if (unlikely(len != sizeof(*head))) > return -EINVAL; > > - current->futex.robust_list32 = head; > + if (!rl) > + return -ENOMEM; > > + rl[FUTEX_ROBUST_LIST2_COMPAT_IDX] = (uintptr_t)head | FUTEX_ROBUST_LIST2_ENTRY_32BIT; > return 0; > } > >