From patchwork Wed Nov 1 12:56:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740061 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267411wrv; Wed, 1 Nov 2023 05:56:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHG2lk87MksmE+D3kn3fTgcpv8jfuG2c/hILpuXd/wAqISnandJVuqNrjtlvEF+myxArsaV X-Received: by 2002:a05:620a:2846:b0:779:deb9:72c6 with SMTP id h6-20020a05620a284600b00779deb972c6mr17354195qkp.14.1698843404392; Wed, 01 Nov 2023 05:56:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843404; cv=pass; d=google.com; s=arc-20160816; b=n8igER1eWYH7BGBBpizeJEkYnLMbNU9ypRONWigqAAXVhfsFJmxREX8tPPnDzZ1zoB TOKzojsNkTMDPZ5jWtcaZbwYzqJxfJ1ZclEr5jGu8PhqVhwbozovcccc0s7NqcoA7Nhg PrBouWJ3cpyVQhOU4tTTWSu+jDKUPQkudEDrnUqsUUr5ErPm2iEzaTNGZxaOVAxgu/is zR2UWiKV8bb5pItC222dowsKvwMIZdnoTqsTh5N9bh+TySCB2kfiQSdMYmLH8sH0wOpO LYRqTJ4Jp5t1iNIM4YBWs+Og+QILQKmQC2fMJNyYSun0eWum0FtsTZ3aXgp2DG5WQ1Zb qcrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=1F+2KIbgsk1fyfgMGRYp2xAq37K8oAJmUhZ6k/9SOHk=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=wV+Q9EJ+XQfCBdiNZsrcXUPweMHc4suk23CydEf/4CgY40kK5UfMn0/peeUrJjWsTG Dg46+9MI8xMi9BSye66YCKTzMu2ALEpKy8YJR947LAjtqfzglF6llzhLu/9aS5SNUmsP BJZsIBoSTOldU4Zwe+LVz+qbvUlCPClF9qnVlWqBY4/aOl1NEhP+pJwz0qOJkYqMfFoI gGwHM8/jWPvUWxhRedFsr5tNNKbBkpRq1GqQu4uPMZhf+icTcQdCoKFk8EizVgMs29O7 clgsCyXHIvlzq8kbLOOlbiyQMBTafCgm2aUA1vMD46xJyiSYSTEuHsURgpCC9jxH5ntY ztXA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zVAiMoha; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p17-20020a05620a113100b00773d3c0bcdbsi2552284qkk.427.2023.11.01.05.56.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:44 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zVAiMoha; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E81D33857730 for ; Wed, 1 Nov 2023 12:56:43 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by sourceware.org (Postfix) with ESMTPS id B82E23858C2B for ; Wed, 1 Nov 2023 12:56:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B82E23858C2B 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 B82E23858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843391; cv=none; b=IZJYjNdawT+0EgNxawHZkirloHHLsHzu48dH/IhRHOU3Nbtnh743ylagCXsmvvHP7gPRXriKbHAdvC1OCXXiHE3Q0NoV3xY0c7WytGphhDmKMtBJ6GVDlzSQ3iRHXS/QEfcYZS+tNd+CGv0F395U/Mpg+3DZWBV0N+kL0oXKGmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843391; c=relaxed/simple; bh=ISkbMjwVd7JsLOQkuM+rxcrTwsHkdMD8jRVD1FBUMjI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=lfr5w19LiH72OpkWjdV5ippa+xP20ALmHh5BwvQPNAzbkqAffuAJrA0RB1DAYfaMckHYS0Cs7eL5dStlaGD+bwdeuodyiwK7VbJewezaL6+1sAgVZ0rNkhkBh8YPbUiDRdVsunDgQjRb80aaiA9dML/6NnptE9l3kmH6llsaI8M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-da2b9234a9fso4426885276.3 for ; Wed, 01 Nov 2023 05:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843379; x=1699448179; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1F+2KIbgsk1fyfgMGRYp2xAq37K8oAJmUhZ6k/9SOHk=; b=zVAiMoha5wiVzT1aR+qb97tPHTvyBPs7/PfhI4tqzBFpWOpGCDB17kSPgGw60bLmf6 9/IBMPCPti0ChfIJS0hB79C8nTczwgueH+4I89ICb+8QSulylAZIciZR0lgixfgHtOK/ eYJmafB1RnqUMH4FT+l0+IbQR2BoWSGktNy4yPN8/y+DwXBnTvloBSgdEZ+nhg9tiDl+ Pida0aNcm7Tw44nUNqWFUrotOhk8xIqE+3P6iSYtBo12Hntn8noasqX0kX0anrweH0Mz lTYtfcyWj1PMac799nX/L9DAstVnYWxjBF04fFWTJJNLIIUWO/UiIdW28jt2PTB66R40 zhIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843379; x=1699448179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1F+2KIbgsk1fyfgMGRYp2xAq37K8oAJmUhZ6k/9SOHk=; b=F3HDJBTEObBPeVqUKXMxFWZ98jtIO4jwjgGYvesYfcoKxvNy0lAL2oWtrgiFuj2xxX 7QqDcM5Vu6Jp3yq6KHcO1u7xG+vsFUidMsMw0800wL7IW9akufK0v0gqcxBNS5fBkzlp ueVq42FyryAer8oMWpGpVDKqSov6kutKnyZf4chyAXjS+A4kmijJSMj8dMOUl/bdEL/W TcpfCO+PTyb4UGnah/12hy1TceMfa5tqpFCCJDkW2p9qkOtk22gTnqwSNfMu8e3d/SP8 lt1yfwW547B9qBZtED7l//SoDDx0ojlbDzyF6wroL7IxFSZoio/Mw/ChplS/+YlUqRSv IUcw== X-Gm-Message-State: AOJu0Yxrz3Q81Zp5UAFhTTTCc26uUGWFCPLmswOU4o2MnXbsrGUPriii /awmwMTp7s1hUL6Y3+Lmr3xf7wgqHd9XoHt8DIewkg== X-Received: by 2002:a25:aa8b:0:b0:d9b:dae4:63fa with SMTP id t11-20020a25aa8b000000b00d9bdae463famr15834741ybi.34.1698843379397; Wed, 01 Nov 2023 05:56:19 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:18 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 1/7] linux: Add PR_SET_VMA_ANON_NAME support Date: Wed, 1 Nov 2023 09:56:05 -0300 Message-Id: <20231101125611.208544-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org Linux 5.17 added support to naming anonymous virtual memory areas through the prctl syscall. The __set_vma_name is a wrapper to avoid optimizing the prctl call if the kernel does not support it. If the kernel does not support PR_SET_VMA_ANON_NAME, prctl returns EINVAL. And it also returns the same error for an invalid argument. Since it is an internal-only API, it assumes well-formatted input: aligned START, with (START, START+LEN) being a valid memory range, and NAME with a limit of 80 characters without an invalid one ("\\`$[]"). Reviewed-by: DJ Delorie --- include/sys/prctl.h | 5 ++++ sysdeps/generic/setvmaname.h | 27 +++++++++++++++++ sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/setvmaname.c | 44 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/setvmaname.h | 36 +++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 sysdeps/generic/setvmaname.h create mode 100644 sysdeps/unix/sysv/linux/setvmaname.c create mode 100644 sysdeps/unix/sysv/linux/setvmaname.h diff --git a/include/sys/prctl.h b/include/sys/prctl.h index d33f3a290e..8e8e05b07c 100644 --- a/include/sys/prctl.h +++ b/include/sys/prctl.h @@ -3,6 +3,11 @@ # ifndef _ISOMAC +# ifndef PR_SET_VMA +# define PR_SET_VMA 0x53564d41 +# define PR_SET_VMA_ANON_NAME 0 +# endif + extern int __prctl (int __option, ...); libc_hidden_proto (__prctl) diff --git a/sysdeps/generic/setvmaname.h b/sysdeps/generic/setvmaname.h new file mode 100644 index 0000000000..2824587e9f --- /dev/null +++ b/sysdeps/generic/setvmaname.h @@ -0,0 +1,27 @@ +/* Utilities functions to name memory mappings. + Copyright (C) 2023 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 + . */ + +#ifndef __SETVMANAME_H +#define __SETVMANAME_H + +static inline +void __set_vma_name (void *start, size_t len, const char *name) +{ +} + +#endif diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 063719bae6..250df6f455 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -97,6 +97,7 @@ sysdep_routines += \ readahead \ setfsgid \ setfsuid \ + setvmaname \ signalfd \ splice \ sysctl \ diff --git a/sysdeps/unix/sysv/linux/setvmaname.c b/sysdeps/unix/sysv/linux/setvmaname.c new file mode 100644 index 0000000000..9960ab5917 --- /dev/null +++ b/sysdeps/unix/sysv/linux/setvmaname.c @@ -0,0 +1,44 @@ +/* Utilities functions to name memory mappings. + Copyright (C) 2023 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 +#include + +/* If PR_SET_VMA_ANON_NAME is not supported by the kernel, prctl returns + EINVAL. However, it also returns the same error for invalid argument. + Since it is an internal-only API, it assumes well formatted input: + aligned START, with (START, START+LEN) being a valid memory range, + and NAME with a limit of 80 characters without invalid one ("\\`$[]"). */ + +void +__set_vma_name (void *start, size_t len, const char *name) +{ + static int prctl_supported = 1; + if (atomic_load_relaxed (&prctl_supported) == 0) + return; + + int r = INTERNAL_SYSCALL_CALL (prctl, PR_SET_VMA, PR_SET_VMA_ANON_NAME, + start, len, name); + if (r == 0 || r != -EINVAL) + return; + + atomic_store_relaxed (&prctl_supported, 0); + return; +} diff --git a/sysdeps/unix/sysv/linux/setvmaname.h b/sysdeps/unix/sysv/linux/setvmaname.h new file mode 100644 index 0000000000..eaa7a7a32e --- /dev/null +++ b/sysdeps/unix/sysv/linux/setvmaname.h @@ -0,0 +1,36 @@ +/* Utilities functions to name memory mappings. + Copyright (C) 2023 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 + . */ + +#ifndef __SETVMANAME_H +#define __SETVMANAME_H + +/* Set the NAME to the anonymous memory map START with size of LEN. + It assumes well-formatted input. */ +#if IS_IN(libc) || IS_IN(rtld) +void __set_vma_name (void *start, size_t len, const char *name) + attribute_hidden; +#else +#include + +static inline void __set_vma_name (void *start, size_t len, const char *name) +{ + prctl (PR_SET_VMA, PR_SET_VMA_ANON_NAME, start, len, name); +} +#endif + +#endif From patchwork Wed Nov 1 12:56:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740060 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267356wrv; Wed, 1 Nov 2023 05:56:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGP6HqvaR75L0HJyLPLKaDSrtLXyLjvfos2966kcjnSI3ZAXrZgXXqNmDkb5Xj3DuYrrqO6 X-Received: by 2002:a05:622a:82:b0:41c:c066:9c0 with SMTP id o2-20020a05622a008200b0041cc06609c0mr19802091qtw.5.1698843396220; Wed, 01 Nov 2023 05:56:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843396; cv=pass; d=google.com; s=arc-20160816; b=hM/e/+GnuzOl/qn1n7QcG37/B9DDaeFRY1LqROTRI8g/ACVu975Pmv+3+nrtBCsIM5 VT29IkhF2Mqy/ZMM8JgpPmxABiqMyXstO4f4SE717nUojE94Aar5S8uun82uFijLEi0f 1B+SCskJJmfxj7VFlPCikvRGHCuARtbYI9uKaMWaprx8cg0lBOC5zBJEim6/RzVGKqQn yWC6YmstkBd3yhNM8xO9T303sh1othSg1mca4WCFmoxsPM2Yl+ymdwTM/GYP+WwpRD2Z FIAva3AK4Xmbriv10HJxGaliwpR2KBs8gNCgWcWpdo7G4x3DzOWPI9OkBBDOPWOA+McE Bzaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=3a7I+lue/0gnA5BTyHrSEIRxoZIlLTWh+LPA0Yf1gsg=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=ODPrP3B2N+vna9gN7FssIygR8OgsEyzwytKdyUN6V0ec86HSouI7CBrJgpU3Bq+hu3 99FtKea7HgnJbkBsK8kgh/t8MSXIwnkbj8i2OSbmeLK6beIX3xVP7rB7T8K5WydtbHZ5 g9Fc6L1kypVXPQ4upCRqGUXPmBoQW8No2PTpKbsnO67SDlBArASq8/fDE6iADz+jhpX0 BPvdKRiaI2+u7rN2caS9XavvAhX0kdVbpOkzJaJTHI54E/CqbmnBnLJ5uxizmoFVMlxb eW5oVBunpp8XIamy1hn4SOyva8V8CW0qYW9R29/QGskZdg9yUdIxaJ2yYzuGn+XncbUe luxQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B8w5a/px"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s1-20020ac85cc1000000b00417af0ea0c6si2709792qta.358.2023.11.01.05.56.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:36 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B8w5a/px"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEFE93857342 for ; Wed, 1 Nov 2023 12:56:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by sourceware.org (Postfix) with ESMTPS id F02F3385840F for ; Wed, 1 Nov 2023 12:56:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F02F3385840F 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 F02F3385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b36 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843391; cv=none; b=tKcNHSYq0F+ugpNtR7CSQlXJ3ZayWi87ZhI0pbtcFcC6LsMgMhBDQtzxJkj9XJZ/UOyE1YIhv3DQocQR6OTURzCP6+wulne1xEjS+cahd0Vi99xT/B/UAgSdBvhc8xbOXKRAejiyBPotL995PqjvVZkVLE5UbH8L9q2NlY9M/Rw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843391; c=relaxed/simple; bh=WG53seEKpuXvBhS6R/4bsY7sK1gYeZpD7QzufqQ+Lj4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=fiv5oEBfEsNiW/oimwxp/bG3nKpdasrDBE4PoGoLSLg6aBME9MBsTn3dh2JpDM05lLnxIGs+KfiJA7lvZeyHCUWB+0bwKmaOdJmUkLNDh8Em+W558GEpLfDlX4WbOyOzCJJJe20POPkj4hrJO5p4AurwAnuLCLVeop1BW4NZENI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-d865854ef96so6198113276.2 for ; Wed, 01 Nov 2023 05:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843382; x=1699448182; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3a7I+lue/0gnA5BTyHrSEIRxoZIlLTWh+LPA0Yf1gsg=; b=B8w5a/pxfWiwRwDRo0lCr0Z8IEPhBksQdOvDlwY1uCPBiQOWmXMzSM0hAGiUl6I5ps /VZdFgsweXyGdbc7O2C8e81anybGvCzHeJ6nrPsP35Xl0hGZtXMS0WguDO7fqg2lK7q3 OHprOq8vXizm8KxDShjjTgo8Txnd90pfrzhJaR62wVPKswxbcl9MAq4hCdNisKUpFUf9 DTNZSFMz5DZkHr2Tei/rb4ZraLiej4BWtsQGdjzHxzM3CDv/cbJPu5ehdcm3vwuyxjuj Thwvrnzg+asjiYtqpo8iXQXY5pRXG4cHsCnwpLT4CRWlysJqPuNx9U6veGh8vOlfFwqd ALKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843382; x=1699448182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3a7I+lue/0gnA5BTyHrSEIRxoZIlLTWh+LPA0Yf1gsg=; b=TgibRKO8EjEJEz3jArOKjW5uK5XZ4kbJ1W0UXJm0y6Bskol87u8OrUHgsDrvMcbb8R xDmgMUzyMKSgxxf9f5Sgww4b0hHzhuFnanoELKecQIw9xBLwIQMMBKvGq9GcVvkVPyr3 afxTQ5Z4X34VG69VRPfwhGYr35eZYJpK4QURbIOvZ7dm/8pmnsaoJRiGpMf0gebrfBeR b7LeeCIoqXOIi0fvRDLeeKKKfspskTmnAATH6Pcvor8PckaLrBrw3Gb8kO6JXrxADskk z0N30edK0ht/OK7ODPuv9kulL0pDfVVT6KQnOqZkeqjKM4WdpAcXa9f2jF8MFHrRRPaF rHKQ== X-Gm-Message-State: AOJu0YyZWsThItoWqw6IBH2VP2BTAc/LsXMkJDlYVSKZVdWgmcZ1sw+D 06NkFvRmXDeuIOtmdnvjdN4oRg92kQYBDa8cgPp9Tw== X-Received: by 2002:a25:804f:0:b0:d9a:3d70:db36 with SMTP id a15-20020a25804f000000b00d9a3d70db36mr13380088ybn.42.1698843381801; Wed, 01 Nov 2023 05:56:21 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:21 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 2/7] support: Add support_set_vma_name Date: Wed, 1 Nov 2023 09:56:06 -0300 Message-Id: <20231101125611.208544-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org Check if kernel supports prctl (PR_SET_VMA, PR_SET_VMA_ANON_NAME, ...). Reviewed-by: DJ Delorie --- support/Makefile | 1 + support/support.h | 4 ++ support/support_set_vma_name_supported.c | 49 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 support/support_set_vma_name_supported.c diff --git a/support/Makefile b/support/Makefile index 917a858bd1..9aa7f23a6e 100644 --- a/support/Makefile +++ b/support/Makefile @@ -80,6 +80,7 @@ libsupport-routines = \ support_select_modifies_timeout \ support_select_normalizes_timeout \ support_set_small_thread_stack_size \ + support_set_vma_name_supported \ support_shared_allocate \ support_small_stack_thread_attribute \ support_socket_so_timestamp_time64 \ diff --git a/support/support.h b/support/support.h index b7f76bf080..4a068d3aee 100644 --- a/support/support.h +++ b/support/support.h @@ -235,6 +235,10 @@ void support_stack_free (struct support_stack *stack); The returned value is the lowest file descriptor number. */ int support_open_dev_null_range (int num, int flags, mode_t mode); + +/* Check if kernel supports set VMA range name. */ +extern bool support_set_vma_name_supported (void); + __END_DECLS #endif /* SUPPORT_H */ diff --git a/support/support_set_vma_name_supported.c b/support/support_set_vma_name_supported.c new file mode 100644 index 0000000000..712caa9b9b --- /dev/null +++ b/support/support_set_vma_name_supported.c @@ -0,0 +1,49 @@ +/* Check if kernel supports set VMA range name. + Copyright (C) 2023 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 +#include +#ifdef __linux__ +# include +#endif + +bool +support_set_vma_name_supported (void) +{ +#ifdef __linux__ + size_t size = sysconf (_SC_PAGESIZE); + if (size == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n"); + + void *vma = xmmap (0, + size, + PROT_NONE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, + -1); + + int r = prctl (PR_SET_VMA, PR_SET_VMA_ANON_NAME, vma, size, "vmaname"); + + xmunmap (vma, size); + + return r == 0; +#else + return false; +#endif +} From patchwork Wed Nov 1 12:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740062 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267477wrv; Wed, 1 Nov 2023 05:56:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERtRyORLtp1vOX40O4iuhqEATGXetCzt8kATSVGuzYAsDtYP83oOkWDncBy+0pdnwn9p7a X-Received: by 2002:a9d:77d1:0:b0:6bc:fb5f:7b06 with SMTP id w17-20020a9d77d1000000b006bcfb5f7b06mr16474278otl.17.1698843414963; Wed, 01 Nov 2023 05:56:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843414; cv=pass; d=google.com; s=arc-20160816; b=Dr5b7vFt0+Osl/v32yJgu7EaWAiImFmJX79APfOLB6Gbn8x9ePlY2iqBiPc7q1N0K3 gtyLYRQQovWSEOqLTaF1YqfxF7w5swUnhltdHQrMk61X1HxQyFAON0cq9HZS0KHC21Or bGcGOJmaFez3iIj4hsxs4MUH1yu8JOu94TibFvpCQqmXi+ZMllf5p6SZie56L1nrzLeO EfYBPtnwLwlqSNTqki/9nElrTKB0PMJv2cBhJr5ffXhB3uQ9o45c/OvpSb+p+vFIeFnr IyoXPLJKVls8JHl/Y2I6gJT0n7e4884weMBVhKHP+Kt2NcbulgwP3f2EWNnWwyd8Z9ru 6hGw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=bKGTvDrs3EZm8QuGc3+yl+qhCuH5QjsUhkgltvYjiTs=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=ZBvAiPswRZlMR1n/XmsRDjKAsABTAkPKmm1d+e8iVIacSQ9r0oiQp5p+/KrBwtBZWs E+FNXF57lnEUCxeoFoX47DaINeIJwaipl+v/sbtEvKvzgIzs51gAr75el03lyaJ9rrYN MTRgnWxEfYVXU8K7ghM97261o0ZG9ugLxA44XaCR6suSjrYMlXj7wkC4OCXYAWG7Bxr4 N3IHgCHPU2zprfd/pTJ8bDU3TkTMXfi38rlYWFXtN6rqLeYjRuDoHAcX9WGiW/r/i0Tl PYJ455vhmuf8XPBZjO69dLV2yaRnc4i7UDUWTBU5opxOpasV4DknCRPexEQ6anZ6rOf7 60aQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXBPkv6d; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bp42-20020a05622a1baa00b00417dc02ee2fsi2650693qtb.462.2023.11.01.05.56.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:54 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXBPkv6d; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B096D3857806 for ; Wed, 1 Nov 2023 12:56:53 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by sourceware.org (Postfix) with ESMTPS id 83D083858412 for ; Wed, 1 Nov 2023 12:56:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 83D083858412 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 83D083858412 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843395; cv=none; b=E/FjlSwco8HLf607nkZjTSBi7XhBtWs4TjhCAFLF/rnhD5nRlfrzQX0NKtVyFqC9NEnd6ffhB8+Hx5UhIcUHlBFiNaFahpFcQ/jlyGbM2klFaRKVqDd3RR8tAn8BKHB9NVXUbFcFI44uBTaLbvp+SYxWXuebT17Poq+eZSgDHdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843395; c=relaxed/simple; bh=FO3ADlkLBQb15irFLg8Ohq9np5D2yI2q0MMZkaDWk7Y=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=eQVFfkgzptE2Czc1j7YdfulgBJ2/bi2/LFZgQ7rrpkmROJGYv/r3aMfl03jNYug4OLhmOBOccqrwLfEAW5bhLH8IVCWSWVRH2D+UZMONQkBCpFCu9KnVt5dFbY1xgJztydUJ7FkM2pq2qb4s5NXhfUxjTGyZaI60hs20b8PEyYU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-d9ad90e1038so6310173276.3 for ; Wed, 01 Nov 2023 05:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843384; x=1699448184; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bKGTvDrs3EZm8QuGc3+yl+qhCuH5QjsUhkgltvYjiTs=; b=GXBPkv6dVVZtiQFIlUnTVBQyaUfPGRVdbjVLeD2vlyKc7Pbt39nXOGrVomfEGQR6q5 vbuZwq4XgLYIR+NfN26AaGrY3WJTNiYXAkbXDJckHvOSxbHJimtfXEFJ+fVVsO9DDjYW WmnO0WkrxjzG3QpChlwJ45GV3J7MmOEBg30b2FeDQspLq5XVJkA1E30sQ59qlkOUvfgp rS/mjSEAW4QOJsQV2FqwN6D0MwBufS/Drkb1/a2MKDFHVf3CJF/63eYrfd7tnNk/497b n9eYE8xBGYTSuX18wq/7TbRAqile1xdK47/mALRvxwwhdJGFrdtfjmTt9yK70vhUR/M5 fViw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843384; x=1699448184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bKGTvDrs3EZm8QuGc3+yl+qhCuH5QjsUhkgltvYjiTs=; b=hfyQEL0GQJ/jumnvGXfu+YtKVfMFe8301jYIMSdCpadYPkzmIyXRXtSGxBMX1DVbSV G+G8i9n9beYCTTrjz0RLncAJrAMhvQPFIbbu1Y3ZLTZbeEwHBzekvRb1CNIId1xMaSj2 wTJHpNbP3K9zDT3/wD8tqw3JUyx18+kqzVWWV8Y4Ji/fqpknqoX3axWAfMRCLVz9yC8M jQyhvi462zCsQdl8PdsjNxAxAcAN09+Z2FRu2eX8e3AIXQyQ+SuQkTAtvdGtPNXywrlG Xl1oruqeP147SI8LH1aOowmq1/0DN7hRawuHFRXia1lLvME19aRTfPvWljsK+twDThQZ epYg== X-Gm-Message-State: AOJu0Yxk4IPx1+dnd3euu0Ztd8lrzTh+d8rziiKVS9x5ciYm2/TsddOS Ak9r6CcWKvI1V8WQgLUIOkVfFLywm7SxgZw7utwaTg== X-Received: by 2002:a25:9805:0:b0:da0:29e2:d29 with SMTP id a5-20020a259805000000b00da029e20d29mr13213069ybo.42.1698843384204; Wed, 01 Nov 2023 05:56:24 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:23 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 3/7] nptl: Decorate thread stack on pthread_create Date: Wed, 1 Nov 2023 09:56:07 -0300 Message-Id: <20231101125611.208544-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org Linux 4.5 removed thread stack annotations due to the complexity of computing them [1], and Linux added PR_SET_VMA_ANON_NAME on 5.17 as a way to name anonymous virtual memory areas. This patch adds decoration on the stack created and used by pthread_create, for glibc crated thread stack the /proc/self/maps will now show: [anon: glibc: pthread stack: ] And for user-provided stacks: [anon: glibc: pthread user stack: ] The guard page is not decorated, and the mapping name is cleared when the thread finishes its execution (so the cached stack does not have any name associated). Checked on x86_64-linux-gnu aarch64 aarch64-linux-gnu. [1] https://github.com/torvalds/linux/commit/65376df582174ffcec9e6471bf5b0dd79ba05e4a Co-authored-by: Ian Rogers Reviewed-by: DJ Delorie --- elf/Makefile | 3 + elf/tst-decorate-maps.c | 160 ++++++++++++++++++++++++++++++++++++++++ nptl/allocatestack.c | 40 ++++++++++ nptl/pthread_create.c | 6 ++ 4 files changed, 209 insertions(+) create mode 100644 elf/tst-decorate-maps.c diff --git a/elf/Makefile b/elf/Makefile index b46dee1c16..33f88bae96 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -303,6 +303,7 @@ tests := \ tst-array4 \ tst-array5 \ tst-auxv \ + tst-decorate-maps \ tst-dl-hash \ tst-leaks1 \ tst-stringtable \ @@ -2980,3 +2981,5 @@ LDFLAGS-tst-dlclose-lazy-mod1.so = -Wl,-z,lazy,--no-as-needed $(objpfx)tst-dlclose-lazy-mod1.so: $(objpfx)tst-dlclose-lazy-mod2.so $(objpfx)tst-dlclose-lazy.out: \ $(objpfx)tst-dlclose-lazy-mod1.so $(objpfx)tst-dlclose-lazy-mod2.so + +$(objpfx)tst-decorate-maps: $(shared-thread-library) diff --git a/elf/tst-decorate-maps.c b/elf/tst-decorate-maps.c new file mode 100644 index 0000000000..b40a0e9b49 --- /dev/null +++ b/elf/tst-decorate-maps.c @@ -0,0 +1,160 @@ +/* Check the VMA name decoration. + Copyright (C) 2023 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 +#include +#include +#include +#include +#include +#include + +#ifndef MAP_STACK +# define MAP_STACK 0 +#endif + +static pthread_barrier_t b; + +static void * +tf (void *closure) +{ + /* Wait the thread startup, so thread stack is allocated. */ + xpthread_barrier_wait (&b); + + /* Wait the test to read the process mapping. */ + xpthread_barrier_wait (&b); + + return NULL; +} + +struct proc_maps_t +{ + int n_def_threads; + int n_user_threads; +}; + +static struct proc_maps_t +read_proc_maps (void) +{ + if (test_verbose) + printf ("=== print process %jd memory mapping ===\n", + (intmax_t) getpid ()); + struct proc_maps_t r = { 0 }; + + FILE *f = xfopen ("/proc/self/maps", "r"); + char *line = NULL; + size_t line_len = 0; + while (xgetline (&line, &line_len, f)) + { + if (test_verbose) + printf ("%s", line); + if (strstr (line, "[anon: glibc: pthread stack:") != NULL) + r.n_def_threads++; + else if (strstr (line, "[anon: glibc: pthread user stack:") != NULL) + r.n_user_threads++; + } + free (line); + xfclose (f); + + if (test_verbose) + printf ("===\n"); + return r; +} + +static void +do_test_threads (bool set_guard) +{ + enum + { + num_def_threads = 8, + num_user_threads = 2, + num_threads = num_def_threads + num_user_threads, + }; + + xpthread_barrier_init (&b, NULL, num_threads + 1); + + pthread_t thr[num_threads]; + { + int i = 0; + for (; i < num_threads - num_user_threads; i++) + { + pthread_attr_t attr; + xpthread_attr_init (&attr); + /* The guard page is not annotated. */ + if (!set_guard) + xpthread_attr_setguardsize (&attr, 0); + thr[i] = xpthread_create (&attr, tf, NULL); + xpthread_attr_destroy (&attr); + } + for (; i < num_threads; i++) + { + pthread_attr_t attr; + xpthread_attr_init (&attr); + size_t stacksize = support_small_thread_stack_size (); + void *stack = xmmap (0, + stacksize, + PROT_READ | PROT_WRITE, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, + -1); + xpthread_attr_setstack (&attr, stack, stacksize); + if (!set_guard) + xpthread_attr_setguardsize (&attr, 0); + thr[i] = xpthread_create (&attr, tf, NULL); + xpthread_attr_destroy (&attr); + } + } + + /* Wait all threads to finshed statup and stack allocation. */ + xpthread_barrier_wait (&b); + + { + struct proc_maps_t r = read_proc_maps (); + TEST_COMPARE (r.n_def_threads, num_def_threads); + TEST_COMPARE (r.n_user_threads, num_user_threads); + } + + /* Let the threads finish. */ + xpthread_barrier_wait (&b); + + for (int i = 0; i < num_threads; i++) + xpthread_join (thr[i]); + + { + struct proc_maps_t r = read_proc_maps (); + TEST_COMPARE (r.n_def_threads, 0); + TEST_COMPARE (r.n_user_threads, 0); + } +} + +static int +do_test (void) +{ + support_need_proc ("Reads /proc/self/maps to get stack names."); + + if (!support_set_vma_name_supported ()) + FAIL_UNSUPPORTED ("kernel does not support PR_SET_VMA_ANON_NAME"); + + do_test_threads (false); + do_test_threads (true); + + return 0; +} + +#include diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index f9d8cdfd08..97d0efec10 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include /* Default alignment of stack. */ #ifndef STACK_ALIGN @@ -577,3 +579,41 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, return 0; } + +/* Maximum supported name from initial kernel support, not exported + by user API. */ +#define ANON_VMA_NAME_MAX_LEN 80 + +#define SET_STACK_NAME(__prefix, __stack, __stacksize, __tid) \ + ({ \ + char __stack_name[sizeof (__prefix) + \ + INT_BUFSIZE_BOUND (unsigned int)]; \ + _Static_assert (sizeof __stack_name <= ANON_VMA_NAME_MAX_LEN, \ + "VMA name size larger than maximum supported"); \ + __snprintf (__stack_name, sizeof (__stack_name), __prefix "%u", \ + (unsigned int) __tid); \ + __set_vma_name (__stack, __stacksize, __stack_name); \ + }) + +/* Add or remove an associated name to the PD VMA stack. */ +static void +name_stack_maps (struct pthread *pd, bool set) +{ +#if _STACK_GROWS_DOWN && !defined(NEED_SEPARATE_REGISTER_STACK) + void *stack = pd->stackblock + pd->guardsize; +#else + void *stack = pd->stackblock; +#endif + size_t stacksize = pd->stackblock_size - pd->guardsize; + + if (!set) + __set_vma_name (stack, stacksize, NULL); + else + { + unsigned int tid = pd->tid; + if (pd->user_stack) + SET_STACK_NAME (" glibc: pthread user stack: ", stack, stacksize, tid); + else + SET_STACK_NAME (" glibc: pthread stack: ", stack, stacksize, tid); + } +} diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 6a41d50109..63cb684f04 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -369,6 +369,9 @@ start_thread (void *arg) /* Initialize pointers to locale data. */ __ctype_init (); + /* Name the thread stack if kernel supports it. */ + name_stack_maps (pd, true); + /* Register rseq TLS to the kernel. */ { bool do_rseq = THREAD_GETMEM (pd, flags) & ATTR_FLAG_DO_RSEQ; @@ -571,6 +574,9 @@ start_thread (void *arg) /* Free the TCB. */ __nptl_free_tcb (pd); + /* Remove the associated name from the thread stack. */ + name_stack_maps (pd, false); + out: /* We cannot call '_exit' here. '_exit' will terminate the process. From patchwork Wed Nov 1 12:56:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740063 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267559wrv; Wed, 1 Nov 2023 05:57:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/1qI27OgceQxW4O6xs764P2Ccf94KwOpQqzGJF4kksI1M3liw7YIGNeGVIidxfJbqni5W X-Received: by 2002:a05:6808:2882:b0:3af:d7dc:a47e with SMTP id eu2-20020a056808288200b003afd7dca47emr15976241oib.42.1698843427534; Wed, 01 Nov 2023 05:57:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843427; cv=pass; d=google.com; s=arc-20160816; b=aPws3QINncvVmpS8VZIoro7oekiCX3jX/QmQDaz/pn8PAqj3TFZ2EdkNYod9tHOQY6 pXES7v+qbF/VIRj4BCRmlHPftc4u/0bKeNy7eXtEJHM6C1NmSCh+1vFspRf6RjGn/TLG UbFgrcy8H/xZGKzDmhYGhjB7/V9k1lRNC15P8OWFncs0gKyS+Vm/nmeYSmBCXTxjEUL/ TdxQLOZu9VJlWzC/1BskePUjza6PJvNKCMcbaZyt/m1cjzYZDNSQoIfrzpZbcJnSc+46 v3q8cjVklqHasVcHG7aqZRPozFxN78jcfurNpPOJsbSrdmMx2gsUoFcLzPh0qJuVESRl 7XaA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=5UU5ZCHspqZTvou61ny9pg0yAH56hmKfpVaGbMIT1qQ=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=qFgQesTTIoMBJyh2H3RUainIA9dCgCZmex/fWXRxJ2kCRXYz03brpOTMlmicQHKSmz deXU/tR21pjok2x54z0rfa5MRtC5YBEaHOJUqgFPwifYUV1h2yYnMr/lGjpbAukkePK5 QGE7m3SoSbKnOvSRgEHxJivi7T1yLKxQOfpf3jEADuZxQlqYOTO9FOA7wqFB2FI56GSk IUbORRhfob353NWcmXYgVRL9Jc2iYuGpwWtPRwiBukGdivuW/FJEmC1OKpAKNunJpcE0 pK/fJo3MbGskaB4fXcqiYwfieps+YPJtdBVes5ND8ylrMKVTflXuNAz00fcBaQ3MF4c0 pR1Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EGR3oH7J; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c3-20020a05620a134300b007672b5d6f96si2642039qkl.17.2023.11.01.05.57.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:57:07 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EGR3oH7J; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0ECAD385772F for ; Wed, 1 Nov 2023 12:57:07 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by sourceware.org (Postfix) with ESMTPS id E89BF3858415 for ; Wed, 1 Nov 2023 12:56:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E89BF3858415 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 E89BF3858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843398; cv=none; b=n5wAEisB3ymKsVHqT2kNjdkqnnV4ixLPt2GFKslA9RObhXUzxXxhQlobhxPz/uwNre7Bg9ONIsuDLs4caWgtKnj+U1bQiyKrLKX3siNVosKdvCt2OH6uTTnew5gkbInmerCp0guAKLcpM4x/x7d6e0SVX98yTY6DLV7jhQbCqwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843398; c=relaxed/simple; bh=NcvGmsowQEOUgp/21ZCaXbh7XDjjpADGSDeP9F0hqMg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gOatP2eYTBWzvBO4jstsS29FyPGg665aWtdQJJlmJaDpYRhIiZ/ZEpt9kvuqN972XQHgTPjFy0X/kei5+8VJNPlllDYzJxiEI2ltlf2thbMCp9lSDF2qsMDOnVPJ1yrcWGV07BXXASWhzGWf3DS60Sv6YVoZySZSindBfL2Mivk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-d9c7bba32beso6394705276.1 for ; Wed, 01 Nov 2023 05:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843386; x=1699448186; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5UU5ZCHspqZTvou61ny9pg0yAH56hmKfpVaGbMIT1qQ=; b=EGR3oH7JtW0SZn0Gb/s9LhnXXWBeEIa9nNwPCwImqrWrgwoxxz1poeqlfwiWNwej6D DMuuygfU+A4qFUd98KQo0RK1VrE/XlwPNviDS7mahDaiASfQbs2aCDtf/p4x4fJNkaoJ vnzkIv9jDNCjL15Rz4RT18hBaOvwKQsTfIY0QjooNnuDn6MvJKycD1xfDzD2Pcqk1gHM 1z6wHfHLYFDS+nvG9DDXwhh4gxMQ6icDdOpwJ1GlKpCjcAuDnG+ehOMaO7ActAvD5ZAp e75HhpDDPKgjoCw4/LepnJWlQS19FrIf1tF09+KWsvF+2TS9XVcMhQTQJZctLV5VDhd+ uHnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843386; x=1699448186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5UU5ZCHspqZTvou61ny9pg0yAH56hmKfpVaGbMIT1qQ=; b=GRKEsIjzuxHfA/WmsBGC6pHBWNfIIfAhBvpw4Fk1X0F7kgnCq0KauzBSYE0nnTlE/6 Q3eCZKSCVqXjg2qMgmfW8szR3rF7eotdBvR1yLk5eK56mYc8ITjySPQ39+gAX/mAMELU yOIfSx085pWwVgeCL6fSBGLO/jyy2C+9z/L6lfe/hTjmp5AIwEmClGzqryJ5kSOLWf9E 8uR60IIPadQGZBCHhgvqm4dWCmQHfeGffZKYnify7ZLIZxN11gLgsaWbkjC8GNGqV8+O /hwVHSeJydwWJjkpWyQs4FmwEjkX/9B1seNkkmU/GWBdBBc6MKP4WHFwhV0n/HC99/ZG L+hQ== X-Gm-Message-State: AOJu0YzMv+BgI8iy6OZlGicyEWzhhbdfA7I+TYXKyhXSyY21YlDbdpuK a+RDHCqEp5VbGD30+HaNmA3xmBmNEmdyoKIjL94YYA== X-Received: by 2002:a25:6b47:0:b0:da0:cd7b:5cb3 with SMTP id o7-20020a256b47000000b00da0cd7b5cb3mr15974309ybm.15.1698843386499; Wed, 01 Nov 2023 05:56:26 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:25 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 4/7] malloc: Decorate malloc maps Date: Wed, 1 Nov 2023 09:56:08 -0300 Message-Id: <20231101125611.208544-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org Add anonymous mmap annotations on loader malloc, malloc when it allocates memory with mmap, and on malloc arena. The /proc/self/maps will now print: [anon: glibc: malloc arena] [anon: glibc: malloc] [anon: glibc: loader malloc] On arena allocation, glibc annotates only the read/write mapping. Checked on x86_64-linux-gnu and aarch64-linux-gnu. Reviewed-by: DJ Delorie --- elf/Makefile | 4 ++++ elf/dl-minimal-malloc.c | 2 ++ elf/tst-decorate-maps.c | 36 ++++++++++++++++++++++++++++++++++++ malloc/arena.c | 4 ++++ malloc/malloc.c | 5 +++++ nptl/Makefile | 4 ++++ 6 files changed, 55 insertions(+) diff --git a/elf/Makefile b/elf/Makefile index 33f88bae96..328dbe82de 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -2983,3 +2983,7 @@ $(objpfx)tst-dlclose-lazy.out: \ $(objpfx)tst-dlclose-lazy-mod1.so $(objpfx)tst-dlclose-lazy-mod2.so $(objpfx)tst-decorate-maps: $(shared-thread-library) + +tst-decorate-maps-ENV = \ + GLIBC_TUNABLES=glibc.malloc.arena_max=8:glibc.malloc.mmap_threshold=1024 +tst-decorate-maps-ARGS = 8 diff --git a/elf/dl-minimal-malloc.c b/elf/dl-minimal-malloc.c index 27549645d0..da36986269 100644 --- a/elf/dl-minimal-malloc.c +++ b/elf/dl-minimal-malloc.c @@ -26,6 +26,7 @@ #include #include #include +#include static void *alloc_ptr, *alloc_end, *alloc_last_block; @@ -60,6 +61,7 @@ __minimal_malloc (size_t n) MAP_ANON|MAP_PRIVATE, -1, 0); if (page == MAP_FAILED) return NULL; + __set_vma_name (page, nup, " glibc: loader malloc"); if (page != alloc_end) alloc_ptr = page; alloc_end = page + nup; diff --git a/elf/tst-decorate-maps.c b/elf/tst-decorate-maps.c index b40a0e9b49..b0ea65ffd7 100644 --- a/elf/tst-decorate-maps.c +++ b/elf/tst-decorate-maps.c @@ -32,15 +32,21 @@ static pthread_barrier_t b; +static int expected_n_arenas; + static void * tf (void *closure) { + void *p = xmalloc (1024); + /* Wait the thread startup, so thread stack is allocated. */ xpthread_barrier_wait (&b); /* Wait the test to read the process mapping. */ xpthread_barrier_wait (&b); + free (p); + return NULL; } @@ -48,6 +54,9 @@ struct proc_maps_t { int n_def_threads; int n_user_threads; + int n_arenas; + int n_malloc_mmap; + int n_loader_malloc_mmap; }; static struct proc_maps_t @@ -69,6 +78,12 @@ read_proc_maps (void) r.n_def_threads++; else if (strstr (line, "[anon: glibc: pthread user stack:") != NULL) r.n_user_threads++; + else if (strstr (line, "[anon: glibc: malloc arena]") != NULL) + r.n_arenas++; + else if (strstr (line, "[anon: glibc: malloc]") != NULL) + r.n_malloc_mmap++; + else if (strstr (line, "[anon: glibc: loader malloc]") != NULL) + r.n_loader_malloc_mmap++; } free (line); xfclose (f); @@ -90,6 +105,9 @@ do_test_threads (bool set_guard) xpthread_barrier_init (&b, NULL, num_threads + 1); + /* Issue a large malloc to trigger a mmap call. */ + void *p = xmalloc (256 * 1024); + pthread_t thr[num_threads]; { int i = 0; @@ -128,6 +146,10 @@ do_test_threads (bool set_guard) struct proc_maps_t r = read_proc_maps (); TEST_COMPARE (r.n_def_threads, num_def_threads); TEST_COMPARE (r.n_user_threads, num_user_threads); + TEST_COMPARE (r.n_arenas, expected_n_arenas); + TEST_COMPARE (r.n_malloc_mmap, 1); + /* On some architectures the loader might use more than one page. */ + TEST_VERIFY (r.n_loader_malloc_mmap >= 1); } /* Let the threads finish. */ @@ -140,8 +162,22 @@ do_test_threads (bool set_guard) struct proc_maps_t r = read_proc_maps (); TEST_COMPARE (r.n_def_threads, 0); TEST_COMPARE (r.n_user_threads, 0); + TEST_COMPARE (r.n_arenas, expected_n_arenas); + TEST_COMPARE (r.n_malloc_mmap, 1); + TEST_VERIFY (r.n_loader_malloc_mmap >= 1); } + + free (p); +} + +static void +do_prepare (int argc, char *argv[]) +{ + TEST_VERIFY_EXIT (argc == 2); + expected_n_arenas = strtol (argv[1], NULL, 10); + expected_n_arenas = expected_n_arenas - 1; } +#define PREPARE do_prepare static int do_test (void) diff --git a/malloc/arena.c b/malloc/arena.c index 6f03955ff2..d1e214ac2e 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -17,6 +17,7 @@ not, see . */ #include +#include #define TUNABLE_NAMESPACE malloc #include @@ -436,6 +437,9 @@ alloc_new_heap (size_t size, size_t top_pad, size_t pagesize, return 0; } + /* Only considere the actual usable range. */ + __set_vma_name (p2, size, " glibc: malloc arena"); + madvise_thp (p2, size); h = (heap_info *) p2; diff --git a/malloc/malloc.c b/malloc/malloc.c index d0bbbf3710..78a531bc7a 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -218,6 +218,7 @@ #include #include +#include #include #include /* needed for malloc_stats */ @@ -2428,6 +2429,8 @@ sysmalloc_mmap (INTERNAL_SIZE_T nb, size_t pagesize, int extra_flags, mstate av) madvise_thp (mm, size); #endif + __set_vma_name (mm, size, " glibc: malloc"); + /* The offset to the start of the mmapped region is stored in the prev_size field of the chunk. This allows us to adjust returned start address to @@ -2513,6 +2516,8 @@ sysmalloc_mmap_fallback (long int *s, INTERNAL_SIZE_T nb, madvise_thp (mbrk, size); #endif + __set_vma_name (mbrk, size, " glibc: malloc"); + /* Record that we no longer have a contiguous sbrk region. After the first time mmap is used as backup, we do not ever rely on contiguous space since this could incorrectly bridge regions. */ diff --git a/nptl/Makefile b/nptl/Makefile index ffa5722e48..d969419af7 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -699,6 +699,10 @@ tst-audit-threads-ENV = LD_AUDIT=$(objpfx)tst-audit-threads-mod1.so tst-setuid1-static-ENV = \ LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)elf:$(common-objpfx)nss +tst-pthread-proc-maps-ENV = \ + GLIBC_TUNABLES=glibc.malloc.arena_max=8:glibc.malloc.mmap_threshold=1024 +tst-pthread-proc-maps-ARGS = 8 + # The tests here better do not run in parallel. ifeq ($(run-built-tests),yes) ifneq ($(filter %tests,$(MAKECMDGOALS)),) From patchwork Wed Nov 1 12:56:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740064 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267663wrv; Wed, 1 Nov 2023 05:57:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw66xyRZTM8//cxyrFFjuAOCZxu6D2WJiNIx4Br9xZfendWlGnhGkBVD8McM4SOufNr0fy X-Received: by 2002:a05:622a:1493:b0:417:9994:eb75 with SMTP id t19-20020a05622a149300b004179994eb75mr19131694qtx.21.1698843442034; Wed, 01 Nov 2023 05:57:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843442; cv=pass; d=google.com; s=arc-20160816; b=SSJ+ekuLttGJwHX1VRLHGq3+ZUbODy9EXVgvLgdb6vrkYUk8vR8LXkv2PzhISUlIIq DhjAmNwDZ7GKYISZ+t8EOmNvADt8ZVe0d+RIHsVsqfEVLE/yxVI6hUYB7m79l3ggxqPN OUc0eMSlekjCOFQNNxL+PfpH35l9v1bjMiJytiZCaUgwiPdmcPWT7yv5VWSild7N+1G2 z46kq13qlXCB1QYs8mrkInDhY18YgEIbApPOEKPVAo7zaRTyUHa1ijpbVZRHyNL+bY6i 3as21mw6C5AC3lvjiCPMQg/1lq30BxjZfqvzLhp+RE53rMq+Q3lNs9vGl4MV6QOJ/vJS /Ymw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=xLM6XTFrju2h0P2Jp6D87i92a5MTlqzEcCSkMAXExHA=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=v/0A1kXXBPcDvJ5U/2TQTBJ/iRQKx7Ef8HWhKJ4bhxquriVQFWXQVkfxmLiCRAwyxs PsUOOPgCdc90+AWE3pEYHXXCyKoAjXaJ2roUZN8PI/31WGTahKLLvmy1yP6mJizwi2t5 BP3IGL13hAVW5ckglwXTBZ4Ru6fDeQPtCck6JGUQHMg7X/BgK7YBgwxbq7+rH38WeYzK zidSGwCV27DWi9fORDJ4HLocCwvBg1sO7hulksX2eIKoc88LwA574qKelWX2XrQ/RrK7 vCFs+3SrMjdELBoZno1k8otld8GsXpoSdIGQ6XfeOryIgNFti0rrSpD4mZd2ftOCEmaf lphg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mBhXRWNY; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l9-20020a05622a174900b0041971a2b466si2624085qtk.715.2023.11.01.05.57.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:57:22 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mBhXRWNY; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A842D3857722 for ; Wed, 1 Nov 2023 12:57:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id 213A33857C44 for ; Wed, 1 Nov 2023 12:56:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 213A33857C44 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 213A33857C44 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843400; cv=none; b=HaSHfXcUUSbHRNnMo1DmFsMr1g9NyoYrWWekeWwosUbmqAM8VB4t/2Cc17jfOOrRG8uifUmb9x9mG6UCsmMBQnsq1+Vx/PTGWYQQNpUVLBPKPtsB3+cHGQBg3/1YdwZOnfxK+ZGq2XEmoezcqonq9bpBRmUcKH4BV5l77bEG9Gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843400; c=relaxed/simple; bh=7IU+K49IxS1kn/ocnc54WSjSZ3Q/mkS/5hQqscvWxMA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KY4t1i0yaxadKnQ9RTXpNtnADuKx0iIT2ygTKpGH78ZOTWbn6X+uM+Mw0hyj8TFSGnAlmDczdcWgfxdv7CbLXyer51PuPWsKopvipdahyK1rk/cS6bD/4X9wTNTPKXjwoXihzNgO0QG8muTAqJJ6iX7jyU3W/w7gO6SviTdbT+w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5afa5dbc378so52536957b3.0 for ; Wed, 01 Nov 2023 05:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843389; x=1699448189; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xLM6XTFrju2h0P2Jp6D87i92a5MTlqzEcCSkMAXExHA=; b=mBhXRWNYIzTwI5KeY7fNin+XHqQpVLpF8PES5Sr/cIWn3lx8JKFAfimHS8SGESFKhh Kjk+B+dfl8yXKTjwm4E4Coje8SFjUWIUdAb+QHazYP1v5DCv58Ua33kA1CmrKqLuDAmW EgI+YFMVSn1jjx624Ev+Un/ID6KcPMKLt/TmWJ82uhbHCM9HROpogZSgkH8LCtDT9yhx 1lAzRe6EE14NGPH+zmiUlibuIjtarNYo8T5AB5AT5E6Llk12a7CfXeIFEPie5m+toWiE cFOKGk/D8oTxWisl2YYmeGTpmUwoaJKXBo2W4zAi/V9xxdN02CKvnZT0Vm7Vh0YAmtTy 6S8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843389; x=1699448189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xLM6XTFrju2h0P2Jp6D87i92a5MTlqzEcCSkMAXExHA=; b=sKqh0Jp42b3DuVXX+7AvtKN19b62tZyTpJckFvBbG4ScnQt0fGaTiz6qNpNYUF+BEg wd1iIwgnLVKoPNSA/4VpAoY9Pb9MZWZi1MtvHgfuKfNNoATggX0m337O81GKt3OwdppK j5IrWb/rfLoOr5BEtPQ7NrXdsFcrSvjH1+pNs41RERLZ9ifJ87A56DABVJBCc/Lh7jYf 3Y5OrGVzBaA2l6xy7qjoDRdqjBejw6lRX9mFbrfLDsCa4MbwI8pZVod4sRDiGpewrx7+ g5kgzX4fcYzWxdDW26IwTMShRpfXnqid5R8BkXnOoQeFnLihp5wvLGtMU6UJBgUzEMBB 2T3Q== X-Gm-Message-State: AOJu0YwbTcPKxgHRV8wr6kkdrMQn1U+jpUzCRonO0ALTQrNob7+BBlAA EYD7deXjr180hvVgGIvLDR96rLhg/VhSwNRn/giLaw== X-Received: by 2002:a25:40c5:0:b0:da0:c887:36cb with SMTP id n188-20020a2540c5000000b00da0c88736cbmr12731553yba.45.1698843388811; Wed, 01 Nov 2023 05:56:28 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:28 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 5/7] assert: Decorate error message buffer Date: Wed, 1 Nov 2023 09:56:09 -0300 Message-Id: <20231101125611.208544-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org --- assert/assert.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assert/assert.c b/assert/assert.c index b7c7a4a1ba..bf0f4a69f5 100644 --- a/assert/assert.c +++ b/assert/assert.c @@ -24,6 +24,7 @@ #include #include #include +#include extern const char *__progname; @@ -71,6 +72,7 @@ __assert_fail_base (const char *fmt, const char *assertion, const char *file, { buf->size = total; strcpy (buf->msg, str); + __set_vma_name (buf, total, " glibc: assert"); /* We have to free the old buffer since the application might catch the SIGABRT signal. */ From patchwork Wed Nov 1 12:56:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740065 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267721wrv; Wed, 1 Nov 2023 05:57:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4ZZIYgq6QVltD/6dKLMjbMkAAflv5FA4EraFybJZxHg0bNjBix4Phq65vc+GCl3u8gInd X-Received: by 2002:a05:622a:44f:b0:418:fe4:51e5 with SMTP id o15-20020a05622a044f00b004180fe451e5mr19642369qtx.24.1698843451843; Wed, 01 Nov 2023 05:57:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843451; cv=pass; d=google.com; s=arc-20160816; b=DmrsRXFI+ixVK4itdBxmokC+DB1otjosXqLMpabhF6oi+mFJ86Xa1iktJKcvDtH6jR dpi3EF7jeXuaIBNmooVUcZgZaJxgmSDUIYqd896dESsG/p3pFVAJLyHFRxv1IVR13E// 5alcb7VMkhljgCEgkFHGtsyZXhMkZb9Y7oyb2Xa3NRRbhYhvZ+gjndrrch2LCJR3VVpC zAnAeC9af3Wj6G2zRnZW4R47rV/G9+OMmri7xMvfF+CNgJl6ErCh523hMNZvjSuSKR15 i+dStK8MtbFky8vfpU72cbV6cUlU4pW5K6L0ahPE51nSUnir0dBsImT6Q8r42pXEES7Q xWsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=xH2cPYi2ud62JL2Pj9p045VIjHtNXt5o/PabtWc7sl0=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=kaQ5sP6RAdLxeb45gX0fsBFt4PLpAbnf8VEbMQjks1Z7JDhCB7aIlYDLJkod4NdVTL RL2N1LE81wWr8Em1OPD9B658kuc1mX+V8m2DOh7dfkGuxzvCK4FJVrVseKgpRExNSHVV X3cW8Gly+FF+Yr6cruBwqp1kxBMTzh0mswDomqFlDGw73pqIIocMj4PriY5s3uEFYfUT /aVFiLGyovHQu6VUzp5w1X8E3Un538Ip4UYtaNdVMALjQqi2WSkv5dj7odiycvAOSuHJ E0ywHMim5rWGAuHSGW27oSNFLaeeHDvTdVnqnzlOdTQSUIrY9AbqkKuYNRHMZkuhCRdM wnFg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XHRCtxXk; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z13-20020a05622a060d00b004122bb38ef3si2796303qta.701.2023.11.01.05.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:57:31 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XHRCtxXk; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31DA0385697F for ; Wed, 1 Nov 2023 12:57:31 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by sourceware.org (Postfix) with ESMTPS id 4029138582BE for ; Wed, 1 Nov 2023 12:56:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4029138582BE 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 4029138582BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843400; cv=none; b=NP2dLUCfhKCdlTWAoCLaCgMblvpmf9X96kWZ/9WtDj77WSoYHVg9jormdSXr/rY+FI+3E48isOPFa4ZlITLs/ijR0Yl0ieFbY5xV9zs79XLYdCa6JkGuyBbuAdSMwYHHa0qAcXGlxcsfKM6P1KF2Z+HY9LubJJ2+2m6qy+kdI2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843400; c=relaxed/simple; bh=ImCn8D9L4MIrZ9fskXjKjheSDp3oRb8wVhEnozuDrjc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KqBVJL1oW/BLqU7bbiNo2bLgoDzNNpp7hfdYwC85279rFpFDbPMhDFIMjtekTkmG5iiqGKMfN/xNYH2zGaRgBdoiAKoivQEmQckfj0243uc3a7GqKO9wOXJhIMpPU0IBzbi0f9kcx9v147cR+NEauVZHxg7LNcdVJfLVCfBmQ+M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-da041ffef81so6257002276.0 for ; Wed, 01 Nov 2023 05:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843391; x=1699448191; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xH2cPYi2ud62JL2Pj9p045VIjHtNXt5o/PabtWc7sl0=; b=XHRCtxXk2KVwgAznFeEKiH7kVIWRcrET+hvFnYRgU3oc0UGAC7BlXBOntQQ5uNAAiC mOadHpJXLY8pCSrp3hB0gdkFo1YrQy32FlJyBwLFwfyMzwIfpBAzWRxibSQ5cooTA93U TalFvAc4BYZC/UXRmt6TNVMuf61Q0dcpvwb6qcVW2Q9rlxFBw3fh+hPPjFIhzggqOxh8 XKXGTRfMU5UswW71IXVkNkXaLiD3iak02jnNpCvCxZd8pmXYUQAgbA2YobCsXAlsqFxu XJltL1konQXgnCPsqxuEwPxtozMYMRuR5+aK045tg7XR3Ee10M9bnghs2KB96qFDBkdY 167Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843391; x=1699448191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xH2cPYi2ud62JL2Pj9p045VIjHtNXt5o/PabtWc7sl0=; b=ocoZGOOWSFduHticIzJo49PFnzVJbQuAIFy3hMorLgO1gGo9KT9xPc19hbzqFbP3ma VZbnryLjPKxNPwuVYKj9S0d3PHQZEjJaaqmveY9XwrPDLbrWKXZbgf23Wc9Qmz6H1eIr 6dP+TIst0Xi3HXHz76gO+NvSZpPotxlNdhz5dxlO8IDKnl23k6NM+jDnBQQ6xz+oPE2G qGcz5i6TOsnVuSQmeH25YG2usB24iv5LgIUj+6BKKWmla9EWxNKiBg683Je1lVgOXGyl knf3UtCrBc9P/SqEdgI8EIdnTKWshq7By6jtcoHyYhRcuV2MM9MIKsMKpPP78KwE4FvZ Rr2g== X-Gm-Message-State: AOJu0YzeFrHpgIbNsk/q5J94A7p8jtSzyiiLeRo7DYZ7w6EYTrmJoqan p6tdAR+FYyN0H7qlDkX4LXOZxGioWmtLHMHhS/Xk/w== X-Received: by 2002:a25:301:0:b0:d9a:c7af:bb4d with SMTP id 1-20020a250301000000b00d9ac7afbb4dmr14410318ybd.37.1698843391206; Wed, 01 Nov 2023 05:56:31 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:30 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 6/7] linux: Decorate __libc_fatal error buffer Date: Wed, 1 Nov 2023 09:56:10 -0300 Message-Id: <20231101125611.208544-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org --- sysdeps/posix/libc_fatal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index cf28387ee6..f564d232bf 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef FATAL_PREPARE_INCLUDE #include FATAL_PREPARE_INCLUDE @@ -116,6 +117,8 @@ __libc_message_impl (const char *fmt, ...) wp = mempcpy (wp, iov[cnt].iov_base, iov[cnt].iov_len); *wp = '\0'; + __set_vma_name (buf, total, " glibc: fatal"); + /* We have to free the old buffer since the application might catch the SIGABRT signal. */ struct abort_msg_s *old = atomic_exchange_acquire (&__abort_msg, From patchwork Wed Nov 1 12:56:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740066 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267744wrv; Wed, 1 Nov 2023 05:57:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIA02xTauIB68mAUMQ7A3/TGsliOeyFCHDx4ny75A/B/4//hVRkOUQdkU8so9FXD4aeDHm X-Received: by 2002:a05:622a:345:b0:41e:173e:82b7 with SMTP id r5-20020a05622a034500b0041e173e82b7mr16751416qtw.66.1698843454188; Wed, 01 Nov 2023 05:57:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843454; cv=pass; d=google.com; s=arc-20160816; b=06dOVuyTcGYkxoOgsLCIR69hRuVjpdmilVP0WpIFaAF6XprN//s3Kjggl0guhIoLHA hJds7+QuoiQIVrWlfS99p+FrZ9mjVhxpFN8JGqq6n868ydlmxOTlnkb7iAOeuEyCyXdF EKIioc+4qpv44ASA/ixNDHk81aG41ZyWEgdSXb/fT6mWQ3F51eCsadeE2WvbTniVv1hw lDuQ7DVSHrgNO0WGkvUU12xCf7BMBfyCCfgDBGAohtTi3WGst7b9Qa4qWjTrAoE8q/sj 7tFb6gdB9OdGnEjTaOxZpwZfORR7dnIoXQ8xZ12UQHVI335H3gAvsqlCjoz+SGXgikuH tuHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=qZWaRRzU8/sTrAhxTNqYWAPaTlsmh/sGkN6xGP2coh4=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=ZdNbLXeA//utWyFOBPYLdKkpjT353rrnPII24xQ99AnNcAW22mtqFMbRT5w0KZruHo /F1exAeJGkyGMsYGJMCj/l/TqAz32fBZQrcUFuWrFGfqN5R3Irur/Kx5DZLLkMadBfPF gakYxIW+FZPGW/7WTynAmiIXxyLIGrO7Ocexra+iWdbRDIAifyh6V398GDG588T+OsGS CLrAIVz6FmxiRuezjrjgRT0qYHerJNtf8+dxUj/4ufKgYwjESm/9rzRHrvmtolcwq7FT 0KLOJFbFyyMs++npC0H3agau0XqGZKnPU/rhnTARw6ooSh6NTd+MMtaGFOY/QWLqmRT2 XTaQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HTAfZhhl; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bp40-20020a05622a1ba800b0040fe2df28c6si2590370qtb.723.2023.11.01.05.57.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HTAfZhhl; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 390BF385771E for ; Wed, 1 Nov 2023 12:57:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by sourceware.org (Postfix) with ESMTPS id CCF4C3857705 for ; Wed, 1 Nov 2023 12:56:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCF4C3857705 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 CCF4C3857705 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843405; cv=none; b=nD/eV7uh3BGl/ESy0H78OfAQrqjhdPxxjV58ZPt4Pj70qarSoGKX7NIJHvs2T44EFaEG1jTfnMiVQruTBGfP5vXRZEIMDA0hqcieV7eAXKnq0YUVdfBn4rdUWx3qgeJ3cYuW2gtrH0VRpaDJB4dqyfW66ySjp57uJl4xW6fBEzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843405; c=relaxed/simple; bh=2yE+axQLzm6gQZDSffqcCYC8eZg7lyq2yku0NikOPVU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=cK9Vptpof1JJMG6q/MKPTnPsehHcjgYKBSkFTMlLAiK0HiVdOgOLTDAuVqIBTqj+HPB/2kHce661jQ0Ge/i/MbOLWiIyUTJ4yWjT4gioEGboC+/wc09xvo2ZZaV+og1jxlf7VzSbaXKvPkQLfJQbPIxaZwg+cbKzM1hWb4ytrQ8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-d852b28ec3bso6244424276.2 for ; Wed, 01 Nov 2023 05:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843393; x=1699448193; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=qZWaRRzU8/sTrAhxTNqYWAPaTlsmh/sGkN6xGP2coh4=; b=HTAfZhhl8q8RX4HxzFOScoM6PfIUPNPbzvH+i85jsZIhJtH4l07WSLbFcLea50kl/4 jw0cwPt6yeaFTiLEpml4Q41mX/C7WftrnXHAIg1ZKSI2EdP2mARwn/x7iRwptCSjxIpK X2lvIQnaADZ2DorOeEW2iB3yvTlB3U/mdz95KOJMwU2NhVy3NOG/2hB/0gOTnqvb3RGj OPEHQotDWAN/qKKSoCx4P+p5Mqjo1+g/WDbm2Gy+lex1vwrGFSMCP6nIUbsGuoOxYtxN /Mw/GDdmWKBYST4JbX2+I+PjoX8Gjth2zgniOv9jZyC/XHLM0QcyRMgdKnR3iDOcgGm+ iseA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843393; x=1699448193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qZWaRRzU8/sTrAhxTNqYWAPaTlsmh/sGkN6xGP2coh4=; b=TCyqqyx7NHPZx+R+JVryeJL6MuGoYc66XTpxwu2K6RLcX3igRKN/vGpvWPeGWlGRCs CPln/KRV0WYDMUbagLYKhdQdlMPzfd1ZEDD6hSamQkPvnnsC9tj+aZZOXBQensuv6Ede VaFwzpIL6P74zaHmOdzEz9Z2PgQj9GrqIwbIcyLdbm3HcCmB3w1EtlKo6nvkf/2faBk5 PNg3y5KwknmSASCGZQdfrldKm6zUZDkihDVHc47J2s1qq0MNCXX34JXwQ5ETM5LCHFL6 yIm98uAYgxTvnoHiUb7a4Ki7yRrMpLetKvc+K+aZ8rO4lO5Onu2gzuC8TT4FA3pKcYiU oIgQ== X-Gm-Message-State: AOJu0Yy7mD4MRfmT/SD7wx/6wJiTVlEEhQo9DGNZ2W0/RRDoRzOMNOB0 gmgMDjFZRyJQkvRx5FFnnDSQEVIZcdt57RUCWXk/IA== X-Received: by 2002:a25:aa85:0:b0:d9a:5244:32e5 with SMTP id t5-20020a25aa85000000b00d9a524432e5mr16703982ybi.35.1698843393494; Wed, 01 Nov 2023 05:56:33 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:a715:15ac:c4b6:7a0e:f5c5]) by smtp.gmail.com with ESMTPSA id w11-20020a5b08cb000000b00da034601e2esm1888100ybq.52.2023.11.01.05.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 7/7] elf: Add glibc.mem.decorate_maps tunable Date: Wed, 1 Nov 2023 09:56:11 -0300 Message-Id: <20231101125611.208544-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101125611.208544-1-adhemerval.zanella@linaro.org> References: <20231101125611.208544-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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, T_SCC_BODY_TEXT_LINE 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+patch=linaro.org@sourceware.org The PR_SET_VMA_ANON_NAME support is only enabled through a configurable kernel switch, mainly because assigning a name to a anonymous virtual memory area might prevent that area from being merged with adjacent virtual memory areas. For instance, with the following code: void *p1 = mmap (NULL, 1024 * 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); void *p2 = mmap (p1 + (1024 * 4096), 1024 * 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); The kernel will potentially merge both mappings resulting in only one segment of size 0x800000. If the segment is names with PR_SET_VMA_ANON_NAME with different names, it results in two mappings. Although this will unlikely be an issue for pthread stacks and malloc arenas (since for pthread stacks the guard page will result in a PROT_NONE segment, similar to the alignment requirement for the arena block), it still might prevent the mmap memory allocated for detail malloc. There is also another potential scalability issue, where the prctl requires to take the mmap global lock which is still not fully fixed in Linux [1] (for pthread stacks and arenas, it is mitigated by the stack cached and the arena reuse). So this patch disables anonymous mapping annotations as default and add a new tunable, glibc.mem.decorate_maps, can be used to enable it. [1] https://lwn.net/Articles/906852/ Checked on x86_64-linux-gnu and aarch64-linux-gnu. Reviewed-by: DJ Delorie --- NEWS | 5 +++++ elf/Makefile | 2 +- elf/dl-tunables.list | 5 +++++ manual/tunables.texi | 17 +++++++++++++++++ sysdeps/unix/sysv/linux/setvmaname.c | 15 ++++++++++----- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 4580fe381d..139cfef1b0 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,11 @@ Major new features: and the wfN format length modifiers for arguments pointing to types int_fastN_t or uint_fastN_t, as specified in draft ISO C2X. +* A new tunable, glibc.mem.decorate_maps, can be used to add additional + information on underlying memory allocated by the glibc (for instance, + on thread stack created by pthread_create or memory allocated by + malloc). + Deprecated and removed features, and other changes affecting compatibility: * The ldconfig program now skips file names containing ';' or ending in diff --git a/elf/Makefile b/elf/Makefile index 328dbe82de..f9bd86a05a 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -2985,5 +2985,5 @@ $(objpfx)tst-dlclose-lazy.out: \ $(objpfx)tst-decorate-maps: $(shared-thread-library) tst-decorate-maps-ENV = \ - GLIBC_TUNABLES=glibc.malloc.arena_max=8:glibc.malloc.mmap_threshold=1024 + GLIBC_TUNABLES=glibc.malloc.arena_max=8:glibc.malloc.mmap_threshold=1024:glibc.mem.decorate_maps=1 tst-decorate-maps-ARGS = 8 diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index 695ba7192e..888d2ede04 100644 --- a/elf/dl-tunables.list +++ b/elf/dl-tunables.list @@ -160,6 +160,11 @@ glibc { maxval: 255 security_level: SXID_IGNORE } + decorate_maps { + type: INT_32 + minval: 0 + maxval: 1 + } } rtld { diff --git a/manual/tunables.texi b/manual/tunables.texi index 776fd93fd9..c28360adcd 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -653,6 +653,23 @@ support in the kernel if this tunable has any non-zero value. The default value is @samp{0}, which disables all memory tagging. @end deftp +@deftp Tunable glibc.mem.decorate_maps +If the kernel supports naming anonymous virtual memory areas (since +Linux version 5.17, although not always enabled by some kernel +configurations), this tunable can be used to control whether +@theglibc{} decorates the underlying memory obtained from operating +system with a string describing its usage (for instance, on the thread +stack created by @code{ptthread_create} or memory allocated by +@code{malloc}). + +The process mappings can be obtained by reading the @code{/proc/maps} +(with @code{pid} being either the @dfn{process ID} or @code{self} for the +process own mapping). + +This tunable takes a value of 0 and 1, where 1 enables the feature. +The default value is @samp{0}, which disables the decoration. +@end deftp + @node gmon Tunables @section gmon Tunables @cindex gmon tunables diff --git a/sysdeps/unix/sysv/linux/setvmaname.c b/sysdeps/unix/sysv/linux/setvmaname.c index 9960ab5917..cd6d571772 100644 --- a/sysdeps/unix/sysv/linux/setvmaname.c +++ b/sysdeps/unix/sysv/linux/setvmaname.c @@ -20,6 +20,7 @@ #include #include #include +#include /* If PR_SET_VMA_ANON_NAME is not supported by the kernel, prctl returns EINVAL. However, it also returns the same error for invalid argument. @@ -34,11 +35,15 @@ __set_vma_name (void *start, size_t len, const char *name) if (atomic_load_relaxed (&prctl_supported) == 0) return; - int r = INTERNAL_SYSCALL_CALL (prctl, PR_SET_VMA, PR_SET_VMA_ANON_NAME, - start, len, name); - if (r == 0 || r != -EINVAL) - return; - + /* Set the prctl as not supported to avoid checking the tunable on every + call. */ + if (TUNABLE_GET (glibc, mem, decorate_maps, int32_t, NULL) != 0) + { + int r = INTERNAL_SYSCALL_CALL (prctl, PR_SET_VMA, PR_SET_VMA_ANON_NAME, + start, len, name); + if (r == 0 || r != -EINVAL) + return; + } atomic_store_relaxed (&prctl_supported, 0); return; }