From patchwork Tue Jul 29 18:21:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 117226 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EE8C3858CD1 for ; Tue, 29 Jul 2025 18:26:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EE8C3858CD1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HT999zmN X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 944B43858D26 for ; Tue, 29 Jul 2025 18:22:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 944B43858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 944B43858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753813359; cv=none; b=boXA7QtiZWyUNTZ5tRxzXVzK/BuPRoLvRaq6Uir+ak677slcEhSzQ1Zz8Rui7ArkzsB6NesIUrNE22Hhb9O6tD6XgViZqPlkzgYnR++nv8iP8FVGBiP0r31oSqOA7xGIGwhNHAm0DertyjzREAsrdCSpA6qf2tVcHAI76vydIUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753813359; c=relaxed/simple; bh=+gEyu7qXN+IIQ+yLk616gcemVyIdugzZjgVHzS6PCiw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Wgn5xDocOM9PvrZs4zzt/q1G+69wE1FnYg3UbH5zYpRo7LlYxwV+4pxLGMRx0SkOGLcboZxE88Kx6IKIRiQIhlICcFi7axep63JE/Xi8xSk6m9Iq2ii3O8fZrhNRVm7bnOpEqhG+r3SZ/EKnr0l78kyXdJC//6XS0rOxUqh6Ueo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 944B43858D26 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7600271f3e9so177571b3a.0 for ; Tue, 29 Jul 2025 11:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1753813358; x=1754418158; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8bJBEh0mZVkNRga++9bB8M+cJVyTrakE5FdyxIxfJgI=; b=HT999zmNhUs0W1Rw7jWgfx+5Imc4iC1yeAcSmk3/yom8lXgwEq+z0W4Phm75H5d64+ 17qBQEWQDUcn938L6YzSFBE9s/ySqWwZRUjQ4I6SvL/Q5wafhpcB9TGPvYNchppM+hvK TwMeXpx6J3j8Xm/pcuURDF3oEpofgO4czsLSe04FhgOXY1OLPxDtG5hkM2bGz7FfG1F7 MPzpGO6ds0HqRth0PnxXedheWawL/p568tRiAogOOnDA2p3wJXG7k8PZcehhta7q9RM8 tJz8e38wWo0vuOahxr+6FrrylvQI7e3WPnPBOMYKGKZuPzWnUZsf/pFSjw+u6Is+CgbW Cp5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753813358; x=1754418158; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8bJBEh0mZVkNRga++9bB8M+cJVyTrakE5FdyxIxfJgI=; b=e9OKtsM67EK6j3Lr9EvV2LNm/+2nmoolCYcRJ/1QpyXX+k595jtvu1co5F/ougoQFz 55YosRflXX1D8Vd17AcJfnQxQBvR5joG8j6HErUuDwbncX++ZhaFre9SvIJ/z4Xvz1OO itUQ4FlxXdI4n5V/ZjUJOSGcvIVLCjp2zUrJJv7MXQplwz2H5Cziij+TnaFlby1NYqBD 3AlKY0iRmqaXyem8M3i/Xni4VD1Bh8JzEiG4gRk02BYiPTkK6OvG3gzTeZgWEL7kXkM5 EdSogoAXOPwg2Zojpj7dT5DY0D/mzMDk2WAUkv6WNLuUz0xMaoGGclyIYq/HpyGUV959 w7bw== X-Gm-Message-State: AOJu0Yy2wqzKBJn5XVGKVFXoef03t3gM87u0XcI/90WUfVM0DDdzYWXG 5tH32Jwfjx8h2Lr2NCXNN5wL1SpH9G2O49mmM//SXgUGdz3pZ33p/WEijAqM2hgjPkrqtx0sNxW qrWQk X-Gm-Gg: ASbGnctC3WT/eV5BeSp3OowGiD10EdZ9h3B/2waaq9XkfGs8+UiiMKcoCrhUDDDEz1r 2gyZAmbRl7eRC10sHd94lKMTS08sGl+dzky6J3d+WgUKswfuFttljgDTJOaT9JaW4dBSnDEbkOx Q1c6yWoGyAvQdXGzPeruWfek8/TrmNbh71j8tam0MHfbxYYXcUijdXnqkTozkKdq/nMDt9HUxzV IWujlHj+AyxNmAiTXfZ0LJw4tVK23ga1jnyTKc9/Ns1lEf+7Dse5TM2/3HfXhPrr3sucR+hA6gx fMrifj7Gq1p/VsEVnnZqHaHeoxIrC6El4l0oCWBDVFvMlbkaLSQTsX84GenDVe5v4+ASd3vjGpn TaD+800vR6UOIoX2LMAVN/BPtfHaUXuvZEGs= X-Google-Smtp-Source: AGHT+IG73+Velm7CKuubcvKq8WxvzWPejDvAtsbcfSZWgqfxUyR0DjcXMSqsAcJ3S1PhVFL/C26yIA== X-Received: by 2002:aa7:9ec6:0:b0:74a:cd4d:c0a6 with SMTP id d2e1a72fcca58-76965af187emr5333092b3a.5.1753813358224; Tue, 29 Jul 2025 11:22:38 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:4712:1467:cc89:a081:2ab3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7640b3d3d3csm8660546b3a.111.2025.07.29.11.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jul 2025 11:22:37 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Daniel Henrique Barboza Subject: [PATCH 1/3] support: Add support_process_shared_robust_mutex Date: Tue, 29 Jul 2025 15:21:27 -0300 Message-ID: <20250729182232.2563519-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250729182232.2563519-1-adhemerval.zanella@linaro.org> References: <20250729182232.2563519-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Returns whether process-shared robust mutexes are supported. --- support/Makefile | 1 + support/support_mutex_robust.c | 34 ++++++++++++++++++++++++++++++++++ support/xthread.h | 3 +++ 3 files changed, 38 insertions(+) create mode 100644 support/support_mutex_robust.c diff --git a/support/Makefile b/support/Makefile index d41278eeab..035e1d6a04 100644 --- a/support/Makefile +++ b/support/Makefile @@ -67,6 +67,7 @@ libsupport-routines = \ support_fuse \ support_isolate_in_subprocess \ support_mutex_pi_monotonic \ + support_mutex_robust \ support_need_proc \ support_open_and_compare_file_bytes \ support_open_and_compare_file_string \ diff --git a/support/support_mutex_robust.c b/support/support_mutex_robust.c new file mode 100644 index 0000000000..2957aca230 --- /dev/null +++ b/support/support_mutex_robust.c @@ -0,0 +1,34 @@ +/* Returns whether process-shared robust mutexes are supported. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +bool +support_process_shared_robust_mutex (void) +{ +#ifdef __linux__ + void *head; + size_t len; + int r = syscall (__NR_get_robust_list, 0, &head, &len); + return r == 0; +#else + return true; +#endif +} diff --git a/support/xthread.h b/support/xthread.h index c63c38f786..b5beb6cebe 100644 --- a/support/xthread.h +++ b/support/xthread.h @@ -36,6 +36,9 @@ void delayed__exit (int seconds); /* Returns true if Priority Inheritance support CLOCK_MONOTONIC. */ bool support_mutex_pi_monotonic (void); +/* Returns true if process-shared robust mutexes are supported. */ +bool support_process_shared_robust_mutex (void); + /* Terminate the process (with exit status 1) if VALUE is not zero. In that case, print a failure message to standard output mentioning FUNCTION. The process is terminated with the exit function, so From patchwork Tue Jul 29 18:21:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 117225 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 468AF3858CD1 for ; Tue, 29 Jul 2025 18:24:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 468AF3858CD1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=PbMNtdqx X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id DE93B3858CD1 for ; Tue, 29 Jul 2025 18:22:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE93B3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE93B3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753813363; cv=none; b=kLz/ApriaO8A7Bq/GTm4oEpWZdDkIeQNVPkqPqUHV+mitqhzo3mrEECFuf13whI2ulrvOPPVUHUWAvwcnpmBvJ/2R5gCkTDca0/HZHELdilUnY5NinrNufEzVkdsyPVd8mY/HtPpCHsvpUz4HFNKL8a6la1/56HHTBwAhVPgXZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753813363; c=relaxed/simple; bh=GEPI9Rf/N9TXtfJAqr5PRGNwGRERezK/BRcnJffFMMw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NIhCBqSuvn/9xNwWeEX/g+/Ii9ZQOwPXJGoWIrYTwJquyZA5Nw49+mPbSWKMMhQNtCO2V4WgyA2AvzvcmhLBHV8+CCwzWxpXHZgYsQQcga1WEyYh1CLrsghBciBtJqnzZuQ8hohqNAd/AtoDqQP7JQcf9kOBrs6OWdX85bGviAM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE93B3858CD1 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7682560a2f2so191239b3a.1 for ; Tue, 29 Jul 2025 11:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1753813362; x=1754418162; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cE/oIFIYNDT5+Ygi3BYsxdxnhVbvppLbkNYb9hcU+so=; b=PbMNtdqxTnpie5NPt/RL8w6q+F0cvDwHXH4ck4gwkyL0wpHol/dqR19eDO3SNVlcyD +Mil6Y02jAzc8yKjX44UFILNFv+51Y8KANBc/BAmV9lTOIQSgaZONmGvxTSnnLTF7VYb 0H9EGDSwvymYYqZ5xBNQHrz68PDEC94U0A9EIKhfUyHZ4cq2n1t8Wx7Er2PjwCfpiX7E w/0zYCTFPPMnqaaB5YQtTv8tgT1e/vLBL2u7cbIjk3s/nZmYJkEnRSkfORKoKXwpinrU DjonjzLJ3P0irBTgLexhquqTooH8mngxrG99GDeTAbAzrevIk96gAI7HjAi3wfv8CpGv iVaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753813362; x=1754418162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cE/oIFIYNDT5+Ygi3BYsxdxnhVbvppLbkNYb9hcU+so=; b=Vv5pkOpjPAPDcwwtQrwWHv5dxCr5e1RRcH1M0XHIQdJoGnmUxqPolPw8oSJJ7oTo+j dinkfWVS+SKo7BuhgdTGbT7/xjPxE7AvADORTOW+wAvZNeOSDQiKnIZ76CTnag0VUvq2 OilUl0urqvwdcB3jiagR3t4JqtV/GJlFRwE2Q4FzKZitpZGMAvWtXKNnUK88nv5mfRIc +6dF2YSJk0XREaBhKSfZo7akzjKYJOQLVQkBc47wif9ChJ2x2/AIjj0RngRnKaaAoo6u E2J1FwAK8bLK7bXiBTpXFXK5BqUFRo2Z9nIOVPy9WFSn4Z/RWdNDPVH5PV62Ead7nUNG Bkaw== X-Gm-Message-State: AOJu0YxNs6ZtkCK4pUdm6xxEeVJOhUOvzErGNYfCIyRnC5nLpnArJF8n P6Mpm/7ILeg+Ulbs2myQ+D4W8lFTwnlBG+T0BVIV4MPSJuGcZ6EKtmlLRONRgK36pejgpTj1QL3 sKWrw X-Gm-Gg: ASbGncsxg2jZ/YngPew4bOk50mCwYMnRVkKg4K5/NPLcsQqz0PlTim1AIXAF9zutUR4 yHVD3PaKPTlt3yQ4gmIFF3Ak+mC0yPHL3jqhEGZOXXQbu5Nkb5Dhd/SzzMvyY70JnH3aOm/Li5d 0WHl8lzZzm8XhO7uFe3wOzD36f7zZNAtPH+/vUChdztGNmmcWoW3gyaTsvAa9ECEfvg6h1LuPE4 QDkAyAfSmBMmJFfPuGYLcKrmI611d+bA8y/2ULAK78+gVpP7lK45H8AcHgH3gSqZ3leCh/RPhQD W5IqhZE05EiJp+CudijZm46cMhi3dWI9BOFdaF30RxIBHifOvmg2kkmAAiYQt1hmGzL7AsjvFKM 2WLNvr0k4vosGwIibQVd/AmHslJ7KWpVN8cs= X-Google-Smtp-Source: AGHT+IEMchkneEBWEOYKq9zmfYtV0mFYnpHuP46QEGPSHhWMesGV64HgiIYxwgXMU+z1BDNlsrvIDw== X-Received: by 2002:a05:6a00:3e13:b0:74e:aaca:c32d with SMTP id d2e1a72fcca58-76ab8c4bd2amr704435b3a.10.1753813361397; Tue, 29 Jul 2025 11:22:41 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:4712:1467:cc89:a081:2ab3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7640b3d3d3csm8660546b3a.111.2025.07.29.11.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jul 2025 11:22:41 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Daniel Henrique Barboza Subject: [PATCH 2/3] nptl: Do not always assume set_robust_list availability (BZ 33225) Date: Tue, 29 Jul 2025 15:21:28 -0300 Message-ID: <20250729182232.2563519-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250729182232.2563519-1-adhemerval.zanella@linaro.org> References: <20250729182232.2563519-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The __ASSUME_SET_ROBUST_LIST is used to define and set __nptl_set_robust_list_avail to advertise process shared robust mutex support, done at __tls_init_tp (during pthread initialization). Some specific kernel configurations and the qemu-user (for all ABIs) do not implement the set_robust_list syscal. Therefore, for the default case (__ASSUME_SET_ROBUST_LIST being true), the missing support is not detected, and pthread_mutex_init succeeds where it should fail. For instance, the sequence succeeds on qemu-user even when set_robust_list fails with ENOSYS. pthread_mutexattr_init(&attr); pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST); pthread_mutex_init(&mutex, &attr); This patch removes __ASSUME_SET_ROBUST_LIST and always enables __nptl_set_robust_list_avail detection. Checked on x86_64-linux-gnu. Reported-by: Daniel Henrique Barboza --- nptl/pthread_create.c | 4 ---- nptl/pthread_mutex_init.c | 3 --- nptl/tst-mutexpi10.c | 4 +++- nptl/tst-robust-fork.c | 21 +++++++++++++++++++ sysdeps/nptl/dl-tls_init_tp.c | 8 +------ sysdeps/nptl/pthreadP.h | 2 -- sysdeps/pthread/tst-mutex7.c | 3 +++ sysdeps/pthread/tst-robust1.c | 3 +++ sysdeps/pthread/tst-robust10.c | 3 +++ sysdeps/pthread/tst-robust7.c | 2 ++ sysdeps/pthread/tst-robust8.c | 6 ++++++ sysdeps/pthread/tst-robust9.c | 2 ++ sysdeps/unix/sysv/linux/arm/kernel-features.h | 7 ------- .../unix/sysv/linux/hppa/kernel-features.h | 3 --- sysdeps/unix/sysv/linux/kernel-features.h | 5 ----- .../unix/sysv/linux/m68k/kernel-features.h | 5 ----- .../unix/sysv/linux/mips/kernel-features.h | 6 ------ .../unix/sysv/linux/riscv/kernel-features.h | 5 ----- .../unix/sysv/linux/sparc/kernel-features.h | 6 ------ 19 files changed, 44 insertions(+), 54 deletions(-) diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index e1033d4ee6..04b8f27b99 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -380,9 +380,7 @@ start_thread (void *arg) __libc_fatal ("Fatal glibc error: rseq registration failed\n"); } -#ifndef __ASSUME_SET_ROBUST_LIST if (__nptl_set_robust_list_avail) -#endif { /* This call should never fail because the initial call in init.c succeeded. */ @@ -517,7 +515,6 @@ start_thread (void *arg) pd->exiting = true; __libc_lock_unlock (pd->exit_lock); -#ifndef __ASSUME_SET_ROBUST_LIST /* If this thread has any robust mutexes locked, handle them now. */ # if __PTHREAD_MUTEX_HAVE_PREV void *robust = pd->robust_head.list; @@ -548,7 +545,6 @@ start_thread (void *arg) } while (robust != (void *) &pd->robust_head); } -#endif /* Release the vDSO getrandom per-thread buffer with all signal blocked, to avoid creating a new free-state block during thread release. */ diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c index 1639935202..35b55576c4 100644 --- a/nptl/pthread_mutex_init.c +++ b/nptl/pthread_mutex_init.c @@ -93,12 +93,9 @@ ___pthread_mutex_init (pthread_mutex_t *mutex, if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0) { -#ifndef __ASSUME_SET_ROBUST_LIST if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_PSHARED) != 0 && !__nptl_set_robust_list_avail) return ENOTSUP; -#endif - mutex_kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP; } diff --git a/nptl/tst-mutexpi10.c b/nptl/tst-mutexpi10.c index 6d2bbbb308..92bd82ebb7 100644 --- a/nptl/tst-mutexpi10.c +++ b/nptl/tst-mutexpi10.c @@ -58,7 +58,9 @@ do_test (void) xpthread_mutexattr_setrobust (&attr, robust[r]); pthread_mutex_t mtx; - xpthread_mutex_init (&mtx, &attr); + if (pthread_mutex_init (&mtx, &attr) == ENOTSUP + && robust[r] == PTHREAD_MUTEX_ROBUST) + continue; /* Uncontended case does not trigger any futex call. */ struct timespec tmo = timespec_add (xclock_now (clocks[c].clk), diff --git a/nptl/tst-robust-fork.c b/nptl/tst-robust-fork.c index 8144b3de3d..375dad768a 100644 --- a/nptl/tst-robust-fork.c +++ b/nptl/tst-robust-fork.c @@ -159,9 +159,20 @@ one_test (int parent_bits, int child_bits, int nonshared_bits, xmunmap (shared, sizeof (*shared)); } +static inline bool +is_robust_pshared (int bits) +{ + return (bits & (mutex_robust | mutex_pshared)) + == (mutex_robust | mutex_pshared); +} + static int do_test (void) { + bool robust_support = support_mutex_robust (); + if (test_verbose) + printf ("info: robust_support=%d\n", robust_support); + for (int parent_bits = 0; parent_bits <= mutex_all_bits; ++parent_bits) for (int child_bits = 0; child_bits <= mutex_all_bits; ++child_bits) for (int nonshared_bits = 0; nonshared_bits <= mutex_all_bits; @@ -175,6 +186,16 @@ do_test (void) parent_bits, child_bits, nonshared_bits, lock_nonshared ? " lock_nonshared" : "", lock_child ? " lock_child" : ""); + if ((is_robust_pshared (parent_bits) + || is_robust_pshared (child_bits) + || is_robust_pshared (nonshared_bits)) + && !robust_support) + { + if (test_verbose) + printf ("info: skipping tests due missing robust mutex" + "support"); + continue; + } one_test (parent_bits, child_bits, nonshared_bits, lock_nonshared, lock_child); } diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c index 47566dce4f..8bf3c7f14b 100644 --- a/sysdeps/nptl/dl-tls_init_tp.c +++ b/sysdeps/nptl/dl-tls_init_tp.c @@ -28,10 +28,8 @@ #define TUNABLE_NAMESPACE pthread #include -#ifndef __ASSUME_SET_ROBUST_LIST bool __nptl_set_robust_list_avail; rtld_hidden_data_def (__nptl_set_robust_list_avail) -#endif bool __nptl_initial_report_events; rtld_hidden_def (__nptl_initial_report_events) @@ -94,11 +92,7 @@ __tls_init_tp (void) int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, sizeof (struct robust_list_head)); if (!INTERNAL_SYSCALL_ERROR_P (res)) - { -#ifndef __ASSUME_SET_ROBUST_LIST - __nptl_set_robust_list_avail = true; -#endif - } + __nptl_set_robust_list_avail = true; } { diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h index 8f256967e2..0822a437da 100644 --- a/sysdeps/nptl/pthreadP.h +++ b/sysdeps/nptl/pthreadP.h @@ -210,12 +210,10 @@ libc_hidden_proto (__pthread_keys) extern unsigned int __nptl_nthreads; libc_hidden_proto (__nptl_nthreads) -#ifndef __ASSUME_SET_ROBUST_LIST /* True if the set_robust_list system call works. Initialized in __tls_init_tp. */ extern bool __nptl_set_robust_list_avail; rtld_hidden_proto (__nptl_set_robust_list_avail) -#endif /* Thread Priority Protection. */ extern int __sched_fifo_min_prio; diff --git a/sysdeps/pthread/tst-mutex7.c b/sysdeps/pthread/tst-mutex7.c index fc8220eec7..d56a7f4dbb 100644 --- a/sysdeps/pthread/tst-mutex7.c +++ b/sysdeps/pthread/tst-mutex7.c @@ -21,6 +21,9 @@ #include #include +#include +#include + /* This test is a template for other tests to use. Other tests define the following macros to change the behaviour of the template test. The test is very simple, it configures N threads given the parameters diff --git a/sysdeps/pthread/tst-robust1.c b/sysdeps/pthread/tst-robust1.c index bd659cc494..638cb705c8 100644 --- a/sysdeps/pthread/tst-robust1.c +++ b/sysdeps/pthread/tst-robust1.c @@ -20,6 +20,9 @@ #include #include +#include +#include + static pthread_mutex_t m1; static pthread_mutex_t m2; diff --git a/sysdeps/pthread/tst-robust10.c b/sysdeps/pthread/tst-robust10.c index ef1e3113f0..813d785ed7 100644 --- a/sysdeps/pthread/tst-robust10.c +++ b/sysdeps/pthread/tst-robust10.c @@ -22,6 +22,9 @@ #include #include +#include +#include + pthread_mutex_t mutex; static void * diff --git a/sysdeps/pthread/tst-robust7.c b/sysdeps/pthread/tst-robust7.c index bf660e8cb0..f73363de96 100644 --- a/sysdeps/pthread/tst-robust7.c +++ b/sysdeps/pthread/tst-robust7.c @@ -21,6 +21,8 @@ #include #include +#include +#include static pthread_barrier_t b; static pthread_cond_t c = PTHREAD_COND_INITIALIZER; diff --git a/sysdeps/pthread/tst-robust8.c b/sysdeps/pthread/tst-robust8.c index 4c8a20e916..dd6230168d 100644 --- a/sysdeps/pthread/tst-robust8.c +++ b/sysdeps/pthread/tst-robust8.c @@ -10,6 +10,8 @@ #include +#include +#include static void prepare (void); @@ -143,6 +145,10 @@ child (int round) static int do_test (void) { + /* Process shared robust mutexes requires kernel support. */ + if (!support_mutex_robust ()) + FAIL_UNSUPPORTED ("robust mutexes not supported"); + if (ftruncate (fd, N * sizeof (pthread_mutex_t)) != 0) { puts ("cannot size new file"); diff --git a/sysdeps/pthread/tst-robust9.c b/sysdeps/pthread/tst-robust9.c index ca24f24282..de675259da 100644 --- a/sysdeps/pthread/tst-robust9.c +++ b/sysdeps/pthread/tst-robust9.c @@ -5,6 +5,8 @@ #include #include +#include +#include static pthread_mutex_t m; diff --git a/sysdeps/unix/sysv/linux/arm/kernel-features.h b/sysdeps/unix/sysv/linux/arm/kernel-features.h index 10caae8b91..a1f8611160 100644 --- a/sysdeps/unix/sysv/linux/arm/kernel-features.h +++ b/sysdeps/unix/sysv/linux/arm/kernel-features.h @@ -20,13 +20,6 @@ #include #include_next -/* The ARM kernel before 3.14.3 may or may not support - futex_atomic_cmpxchg_inatomic, depending on kernel - configuration. */ -#if __LINUX_KERNEL_VERSION < 0x030E03 -# undef __ASSUME_SET_ROBUST_LIST -#endif - /* ARM fadvise64_64 reorganize the syscall arguments. */ #define __ASSUME_FADVISE64_64_6ARG 1 diff --git a/sysdeps/unix/sysv/linux/hppa/kernel-features.h b/sysdeps/unix/sysv/linux/hppa/kernel-features.h index 102714166e..e9b3bcaa1a 100644 --- a/sysdeps/unix/sysv/linux/hppa/kernel-features.h +++ b/sysdeps/unix/sysv/linux/hppa/kernel-features.h @@ -30,6 +30,3 @@ #undef __ASSUME_CLONE_DEFAULT #define __ASSUME_CLONE_BACKWARDS 1 - -/* QEMU does not support set_robust_list. */ -#undef __ASSUME_SET_ROBUST_LIST diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index a49a9159cf..f203d038da 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -49,11 +49,6 @@ SH this appeared first in 2.6.19-rc1. */ #define __ASSUME_PSELECT 1 -/* Support for inter-process robust mutexes was added in 2.6.17 (but - some architectures lack futex_atomic_cmpxchg_inatomic in some - configurations). */ -#define __ASSUME_SET_ROBUST_LIST 1 - /* The termios2 interface was introduced across all architectures except Alpha in kernel 2.6.22. */ #define __ASSUME_TERMIOS2 1 diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h index 3515b20433..ba0cc0844f 100644 --- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h +++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h @@ -42,11 +42,6 @@ # undef __ASSUME_GETPEERNAME_SYSCALL #endif -/* No support for PI futexes or robust mutexes before 3.10 for m68k. */ -#if __LINUX_KERNEL_VERSION < 0x030a00 -# undef __ASSUME_SET_ROBUST_LIST -#endif - /* m68k only supports ipc syscall before 5.1. */ #if __LINUX_KERNEL_VERSION < 0x050100 # undef __ASSUME_DIRECT_SYSVIPC_SYSCALLS diff --git a/sysdeps/unix/sysv/linux/mips/kernel-features.h b/sysdeps/unix/sysv/linux/mips/kernel-features.h index d86ac92352..c9bba743ac 100644 --- a/sysdeps/unix/sysv/linux/mips/kernel-features.h +++ b/sysdeps/unix/sysv/linux/mips/kernel-features.h @@ -21,12 +21,6 @@ #include_next -/* The MIPS kernel does not support futex_atomic_cmpxchg_inatomic if - emulating LL/SC. */ -#if __mips == 1 || defined _MIPS_ARCH_R5900 -# undef __ASSUME_SET_ROBUST_LIST -#endif - /* Define this if your 32-bit syscall API requires 64-bit register pairs to start with an even-number register. */ #if _MIPS_SIM == _ABIO32 diff --git a/sysdeps/unix/sysv/linux/riscv/kernel-features.h b/sysdeps/unix/sysv/linux/riscv/kernel-features.h index dce50835d1..83e0c69ee3 100644 --- a/sysdeps/unix/sysv/linux/riscv/kernel-features.h +++ b/sysdeps/unix/sysv/linux/riscv/kernel-features.h @@ -21,8 +21,3 @@ #undef __ASSUME_CLONE_DEFAULT #define __ASSUME_CLONE_BACKWARDS 1 - -/* No support for PI mutexes or robust futexes before 4.20. */ -#if __LINUX_KERNEL_VERSION < 0x041400 -# undef __ASSUME_SET_ROBUST_LIST -#endif diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h index 24423db127..8e7ee91eeb 100644 --- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h @@ -19,12 +19,6 @@ #include_next -/* 32-bit SPARC kernels do not support - futex_atomic_cmpxchg_inatomic. */ -#if !defined __arch64__ && !defined __sparc_v9__ -# undef __ASSUME_SET_ROBUST_LIST -#endif - /* These syscalls were added for 32-bit in 4.4 (but present for 64-bit in all supported kernel versions); the architecture-independent kernel-features.h assumes some of them to be present by default. From patchwork Tue Jul 29 18:21:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 117224 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8D2A3858C50 for ; Tue, 29 Jul 2025 18:24:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8D2A3858C50 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Caxt6sbL X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 9C9803858D1E for ; Tue, 29 Jul 2025 18:22:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C9803858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C9803858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753813364; cv=none; b=nWwWOiZeB8XMe/wcFeiDnvUy0ZSiaf3NILpIETBudzqB6Prs3ufkwaNwJArt4IaYYZtyafSgLTUMepQ+Rv5bdteZiRNm7U+xrRhMupYd3TBZS7gJlgNQEXThOo58mGEhmjuWG4U1DfDfwDR29lvdkcGBbqE9LIuzzAMCkAsovH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1753813364; c=relaxed/simple; bh=tFgBzDvQ80/Y9v4HXzB8Rr3H4yjQXVVm/4e49XcY77c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tYgvF3RW22AckynKHguxlzeGNvHX6M3U2Jffn470fsKxE4xLeOxQex9uAyl5gvyG0ve731Pfeo8PawlxiwsRQLDBp1G52nnzPxwRdZMfgy7PsUF9X/Wba5rnQoxsh6Mu5PIaAa5J1LLFIAGtbsew96yR3MqT81MCP5MdbRbOLgM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C9803858D1E Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-74b52bf417cso4041773b3a.0 for ; Tue, 29 Jul 2025 11:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1753813363; x=1754418163; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wCHQh7+0j9v7vKkzlJuNXTO6viGEumjuEeae2hDFtAA=; b=Caxt6sbLieH2TOhXT48w24ocLoGkGX5ZIde7vUyMV6GE99eBL92BL/vNoAwhNjUcbx rV00x9zJ+34SSDf0AdEo9Gwhi3uiztKbM7ysbASZOimwEpNGIfDwrZGeGctcCMSqRAcB 7Vuy6P0bUtzf1XcrPwE3rGlo20wT1o2EBJZ4ni7zBU5BT7T2Hs+xD+/5sAdDIMAEgCpN fCajzYUf2nYN0+DSnLEhqtRqJnvp7nMzvGeSlcHa24sraj4yTvkFpkTDWquL8I+jgPTa CeVulEzWmjU6YnhK8Zz3bnmVOE0NzSLsmMFrPoon62PyTCf17cX03rG2r1smVEAb1SH8 Jo0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753813363; x=1754418163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wCHQh7+0j9v7vKkzlJuNXTO6viGEumjuEeae2hDFtAA=; b=V9iYxYbb1pcDMpzDxviItvEQO052nRmy1ynNCOn+i9SOj6nZq7fxfJZkcj3SqSh3L2 5fj16gG2UveenAtH+gpTmFfbf1UI3lCE17KlKXYmdmf93oenkwBloSt5A9XwD+E7J1cB l4IHqU8yNc9KEXJKWoEXBEzZnBVup+s5EqIg+vZNDr1JmtoCW2EZWTxfnSIQ+7K5Q+fo E7ZBaRTfqSsqjVshqTNDGE3XoUKDjCaXICf4PcmLNy5QbctxCo9dG9ozIn28vHAhxUB9 wxBQGpoRCpkKEGVDv5HDg3i8Q29w37PKFD80kXmBY8VGyy891vIH78zOZPwhQpFVCBjQ Vk3w== X-Gm-Message-State: AOJu0YxtYguyiWXF4IEjgT3vvv+O/HqbSqtrjZgjHb037rkDd4MeR84N GJud4deqffncFXeyQjWJYzRCl2jKWOJVmDkedk6WrVv66viMHDqjcd/JO9B1dB+8/8isJnr6XCY FaO+G X-Gm-Gg: ASbGncvUHvXcrIhVxNeD1F9vak8SkN+DgHChMrdnNuvxvUwovpgq45olSm+Y62xY1JI OB+QsV6wfTO7gX9JDpMYi6Jrx+m8SxTVLBHfZT/J1JOYN6zy+PEl+ttnqk/PKlskaG77IRCWJbB SHMaj/BNtExlzB+QMUEftpE6sQV+DkwDDPHiK4cmaQsdyezkD7/f2hRdF9XsYmQIaeiZh4HLxD7 hCwLGsd3xkTJdvq2JbNf1paq1uTdYnY8xTirt+IoEiNdUs9cTxDaha3904tg4oqPfRFxSzNs0aq wyxfHVrH4BXIM6XIWzzbPdYcVNnyTgQKB2t82f9AhYqab/ba3zVmnOHO/Kn7grWNBpMHMO3WvhO UVzzXUh/EgAN2yoh9va1f/Lx3t1GoUpQPXfw= X-Google-Smtp-Source: AGHT+IEAHsFVZ0iYe132mnHMfB8adDK63LFHhud3ynM+ZEwdXlnXZScj8u4CQ4zsSqPnqu1t5AmEMg== X-Received: by 2002:a05:6a00:3d4d:b0:76a:d724:d6f1 with SMTP id d2e1a72fcca58-76ad724dd2amr109789b3a.8.1753813363201; Tue, 29 Jul 2025 11:22:43 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:4712:1467:cc89:a081:2ab3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7640b3d3d3csm8660546b3a.111.2025.07.29.11.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jul 2025 11:22:42 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Daniel Henrique Barboza Subject: [PATCH 3/3] nptl: Only initialize robust list at mutex usage Date: Tue, 29 Jul 2025 15:21:29 -0300 Message-ID: <20250729182232.2563519-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250729182232.2563519-1-adhemerval.zanella@linaro.org> References: <20250729182232.2563519-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The robust mutex kernel initialization is always performed at process startup and thread creation, even when the process does not use any robust mutexes. This patch moves the set_robust_issue syscall to either when a robust process is initialized or used, saving the syscall issue for processes that do not use robust mutexes. The field futex_offset is used as a sentinel to indicate whether the struct pthread list is already initialized. This also allows to move the __nptl_set_robust_list_avail from ld.so to libc.so, since there is no need to initialize it at pthread startup. Checked on x86_64-linux-gnu and aarch64-linux-gnu. --- nptl/Makefile | 1 + nptl/Versions | 1 - nptl/allocatestack.c | 9 +------- nptl/descr.h | 32 ++++++++++++++++++++++++++++ nptl/nptl_robust_setup.c | 38 ++++++++++++++++++++++++++++++++++ nptl/pthread_create.c | 8 ------- nptl/pthread_mutex_init.c | 2 +- nptl/pthread_mutex_lock.c | 2 ++ nptl/pthread_mutex_timedlock.c | 2 ++ nptl/pthread_mutex_trylock.c | 2 ++ sysdeps/nptl/dl-tls_init_tp.c | 17 +-------------- sysdeps/nptl/pthreadP.h | 6 ++---- 12 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 nptl/nptl_robust_setup.c diff --git a/nptl/Makefile b/nptl/Makefile index e6481d5694..f0864c7054 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -55,6 +55,7 @@ routines = \ nptl_deallocate_tsd \ nptl_free_tcb \ nptl_nthreads \ + nptl_robust_setup \ nptl_setxid \ nptlfreeres \ old_pthread_cond_broadcast \ diff --git a/nptl/Versions b/nptl/Versions index ef55376dd9..019bc132fe 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -533,6 +533,5 @@ libpthread { ld { GLIBC_PRIVATE { __nptl_initial_report_events; - __nptl_set_robust_list_avail; } } diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index 800ca89720..a3c7b75eb9 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -611,14 +611,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* The robust mutex lists also need to be initialized unconditionally because the cleanup for the previous stack owner might have happened in the kernel. */ - pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock) - - offsetof (pthread_mutex_t, - __data.__list.__next)); - pd->robust_head.list_op_pending = NULL; -#if __PTHREAD_MUTEX_HAVE_PREV - pd->robust_prev = &pd->robust_head; -#endif - pd->robust_head.list = &pd->robust_head; + robust_list_init (pd); /* We place the thread descriptor at the end of the stack. */ *pdp = pd; diff --git a/nptl/descr.h b/nptl/descr.h index ada6867a19..7961d28944 100644 --- a/nptl/descr.h +++ b/nptl/descr.h @@ -454,6 +454,38 @@ cancel_enabled_and_canceled_and_async (int value) == (CANCELTYPE_BITMASK | CANCELED_BITMASK); } +static inline void +robust_list_init (struct pthread *pd) +{ + pd->robust_head.list_op_pending = NULL; +#if __PTHREAD_MUTEX_HAVE_PREV + pd->robust_prev = &pd->robust_head; +#endif + pd->robust_head.list = &pd->robust_head; + pd->robust_head.futex_offset = 0; +} + +extern bool __nptl_robust_setup (struct robust_list_head *robust_head) + attribute_hidden; + +static inline bool +robust_list_setup (struct pthread *pd) +{ + /* The current thread was already initialized. */ + if (pd->robust_head.futex_offset != 0) + return true; + + if (__nptl_robust_setup (&pd->robust_head)) + { + pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock) + - offsetof (pthread_mutex_t, + __data.__list.__next)); + return true; + } + + return false; +} + /* This yields the pointer that TLS support code calls the thread pointer. */ #if TLS_TCB_AT_TP # define TLS_TPADJ(pd) (pd) diff --git a/nptl/nptl_robust_setup.c b/nptl/nptl_robust_setup.c new file mode 100644 index 0000000000..cf72677c63 --- /dev/null +++ b/nptl/nptl_robust_setup.c @@ -0,0 +1,38 @@ +/* Linux robust mutext setup. + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +int __nptl_set_robust_list_avail = 1; + +bool +__nptl_robust_setup (struct robust_list_head *robust_head) +{ + if (atomic_load_relaxed (&__nptl_set_robust_list_avail)) + { + int res = INTERNAL_SYSCALL_CALL (set_robust_list, robust_head, + sizeof (struct robust_list_head)); + if (!INTERNAL_SYSCALL_ERROR_P (res)) + return true; + + atomic_store_relaxed (&__nptl_set_robust_list_avail, 0); + } + return false; +} diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 04b8f27b99..4bf1ff56de 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -380,14 +380,6 @@ start_thread (void *arg) __libc_fatal ("Fatal glibc error: rseq registration failed\n"); } - if (__nptl_set_robust_list_avail) - { - /* This call should never fail because the initial call in init.c - succeeded. */ - INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, - sizeof (struct robust_list_head)); - } - /* This is where the try/finally block should be created. For compilers without that support we do use setjmp. */ struct pthread_unwind_buf unwind_buf; diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c index 35b55576c4..85a1371afd 100644 --- a/nptl/pthread_mutex_init.c +++ b/nptl/pthread_mutex_init.c @@ -94,7 +94,7 @@ ___pthread_mutex_init (pthread_mutex_t *mutex, if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_ROBUST) != 0) { if ((imutexattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_PSHARED) != 0 - && !__nptl_set_robust_list_avail) + && !robust_list_setup (THREAD_SELF)) return ENOTSUP; mutex_kind |= PTHREAD_MUTEX_ROBUST_NORMAL_NP; } diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 604941c9dd..8e435147bc 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -201,6 +201,7 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP: case PTHREAD_MUTEX_ROBUST_NORMAL_NP: case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP: + robust_list_setup (THREAD_SELF); THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, &mutex->__data.__list.__next); /* We need to set op_pending before starting the operation. Also @@ -385,6 +386,7 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) if (robust) { + robust_list_setup (THREAD_SELF); /* Note: robust PI futexes are signaled by setting bit 0. */ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, (void *) (((uintptr_t) &mutex->__data.__list.__next) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 138cdcc985..387597f7d9 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -125,6 +125,7 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP: case PTHREAD_MUTEX_ROBUST_NORMAL_NP: case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP: + robust_list_setup (THREAD_SELF); THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, &mutex->__data.__list.__next); /* We need to set op_pending before starting the operation. Also @@ -309,6 +310,7 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, if (robust) { + robust_list_setup (THREAD_SELF); /* Note: robust PI futexes are signaled by setting bit 0. */ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, (void *) (((uintptr_t) &mutex->__data.__list.__next) diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c index dbb8fcc754..d9ae14b636 100644 --- a/nptl/pthread_mutex_trylock.c +++ b/nptl/pthread_mutex_trylock.c @@ -84,6 +84,7 @@ ___pthread_mutex_trylock (pthread_mutex_t *mutex) case PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP: case PTHREAD_MUTEX_ROBUST_NORMAL_NP: case PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP: + robust_list_setup (THREAD_SELF); THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, &mutex->__data.__list.__next); /* We need to set op_pending before starting the operation. Also @@ -226,6 +227,7 @@ ___pthread_mutex_trylock (pthread_mutex_t *mutex) if (robust) { + robust_list_setup (THREAD_SELF); /* Note: robust PI futexes are signaled by setting bit 0. */ THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, (void *) (((uintptr_t) &mutex->__data.__list.__next) diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c index 8bf3c7f14b..d42d9203ce 100644 --- a/sysdeps/nptl/dl-tls_init_tp.c +++ b/sysdeps/nptl/dl-tls_init_tp.c @@ -28,9 +28,6 @@ #define TUNABLE_NAMESPACE pthread #include -bool __nptl_set_robust_list_avail; -rtld_hidden_data_def (__nptl_set_robust_list_avail) - bool __nptl_initial_report_events; rtld_hidden_def (__nptl_initial_report_events) @@ -81,19 +78,7 @@ __tls_init_tp (void) THREAD_SETMEM (pd, report_events, __nptl_initial_report_events); /* Initialize the robust mutex data. */ - { -#if __PTHREAD_MUTEX_HAVE_PREV - pd->robust_prev = &pd->robust_head; -#endif - pd->robust_head.list = &pd->robust_head; - pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock) - - offsetof (pthread_mutex_t, - __data.__list.__next)); - int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head, - sizeof (struct robust_list_head)); - if (!INTERNAL_SYSCALL_ERROR_P (res)) - __nptl_set_robust_list_avail = true; - } + robust_list_init (pd); { /* If the registration fails or is disabled by tunable, the public diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h index 0822a437da..f404b791fd 100644 --- a/sysdeps/nptl/pthreadP.h +++ b/sysdeps/nptl/pthreadP.h @@ -210,10 +210,8 @@ libc_hidden_proto (__pthread_keys) extern unsigned int __nptl_nthreads; libc_hidden_proto (__nptl_nthreads) -/* True if the set_robust_list system call works. Initialized in - __tls_init_tp. */ -extern bool __nptl_set_robust_list_avail; -rtld_hidden_proto (__nptl_set_robust_list_avail) +/* Set if the set_robust_list system call works. */ +extern int __nptl_set_robust_list_avail attribute_hidden; /* Thread Priority Protection. */ extern int __sched_fifo_min_prio;