From patchwork Thu Oct 26 17:11:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 738336 Delivered-To: patch@linaro.org Received: by 2002:ab3:1905:0:b0:23f:8cfb:5ad7 with SMTP id u5csp1312612ltc; Thu, 26 Oct 2023 10:13:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhO/C2en/N/mHWAJMLKihC9ZNfStQSEdcF3C/odgnlKGw1P1CUj+bHxdQZkh9Oscehnq3x X-Received: by 2002:ad4:594b:0:b0:66d:1f29:3ea8 with SMTP id eo11-20020ad4594b000000b0066d1f293ea8mr233696qvb.57.1698340415735; Thu, 26 Oct 2023 10:13:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698340415; cv=pass; d=google.com; s=arc-20160816; b=Ur7kudl1ANmzKy0BM7gQyoDsXi0118csBYO3Rumvj/rKp4HiqiMknxSsOjmXyGBNtl iU2X5atnSFQfSRTeeoVgGXzJUkMI4EBOrutTcDqnLgEb4DAgaOC+35XiQ68aur4vWqiS WWgybhqBWHYr2pQ+nm5wxfnEdL7xvd3jNYaMtvi0urPcofyoZPn5dvD+zCD+pW2e+qFL IM+CRXAVxB2jAMplCogkqFVpg4oRdPRuTwjkYZNX/M5CgPpBiHrTwap6mDFrLT0JbwbE YXYkrf7RjVuyk9xVQhxZlkneEyPS1PlE1D8q2rO3A/OJiOilZeTZJIaU+L8XLVQeS0cA l6mw== 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=AuEyVWSJ7DsKUMa1yDoscVDOdz5BQpDjkPiwROVWQRU=; fh=Lbqp+rs2mRBTG5C9ik7cirOzlOF2+U9yLxjtEQVqExY=; b=Opzf3IxawWGaiHH8QG7HXyE04lzRnJdXpm+YBA24l3NCtBkCU/p75KJqJdEzHw3xer 079uJX+Tlg+mu7WObZffHSPQaH1Dx272PMEedIMdCxLQcjbzit6Z58lAO2XD+4cvuFsD VT6/Fr5T/IP0dAaswFttXi0Ql2+WZipyZdsZZGcS7OSlfnZ9gt1BmmnjZVQPJ+3K4VJN ZyE+DI7/Ifct1KJV0KcPcDM3/PYH2DzE1ZcxYqZKL1ndm6OwGASyWFiMTC071fIlHpfu ZkFuZ3zhQ2gieGwL8+xNJLF9Fz1pDBNhVTobkL9d695x1BEIKGSPMshBQ4+0LynNKK7k 9UkQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AIWBCJci; 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 k16-20020ad44510000000b0065b284d5678si9532095qvu.109.2023.10.26.10.13.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:13:35 -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=AIWBCJci; 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 288F8385350C for ; Thu, 26 Oct 2023 17:13:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 28F50385840C for ; Thu, 26 Oct 2023 17:12:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 28F50385840C 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 28F50385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698340327; cv=none; b=UgD1vW1X0yVtuEa1LjuKrmXP8Np/98sLiGW61wyfC068mL0ZWym5LpmsQvmvITIsQ4rMzp4NVaJO2EOErZCZCZA+I3LoeT+/nzehgGmuumfdF47MvA8ouq6i675LCm1wRykMON3bRTZhqs8+3tKUeieOSlPKH/KAuJwU/0AhdpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698340327; c=relaxed/simple; bh=MaK5Xv6njvvXip1gUIhFMG8RujKPPMi65avj//kgvus=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=PpzZ6FPDOEgfgMAUq8CktIbmcjIIUJD+VbG2Pxipa/bpVz3kalEqkmCaFN89Ytt7F6WPTHFmaDC6n2SBpWp4EN/7KIwednP1kww0KP5k655w0T83tFSpIhZwHrfQ7kQSmxUntoSlYhzI5nMwoc5LR7GKCr6cQF8rf3auBChtc+Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6b1e46ca282so1130192b3a.2 for ; Thu, 26 Oct 2023 10:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698340323; x=1698945123; 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=AuEyVWSJ7DsKUMa1yDoscVDOdz5BQpDjkPiwROVWQRU=; b=AIWBCJciru1+HNJeX2nWScALNT++73j6+AP1GK7Z7QGSHMA8r610XpHOmy/hyYbZ91 mDkP7qnqf/k7E5NPtqJu8mxgCxXtpokFYqfmOt4lrkqWgdHzOz+iDKdVC5CkJPBja2O0 TeObwd0IPnxtB+ioeei7BzNUEmOV2CMYw+44KTdcd9aRKgyUQxfkhL35E/YOcjeqGT2f seS22cpl1uE0bUvAtNTO7YoGuM4vYLQuIWl7l4CxqTtLdnDLJEZrqlBvoQVJmF5Z0mvD tklbHIACk3QgMj8JAaaTQaJvj/vUsQeI3EqjpwgHoGPxZQ10wvUuRMvKtYONa8BPThVQ hzQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698340323; x=1698945123; 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=AuEyVWSJ7DsKUMa1yDoscVDOdz5BQpDjkPiwROVWQRU=; b=R4oJmktyXui8IUTohW9pqjU10fB85M/lMHYPGdHxTCmXGay94eLAfqQOyaPsWcZjQo bmnxlbACErsMIqUcxQQFizyGbXpDEBHFflXOnzRCleBPAcZKo0tOXTCMEIg5bF+UeNoa Y6dOBKw5mDb6tbuZHWFsHmu6djwg4xWi6kWOxBon+AvobktvUjC0yKGxcyPkfOhJmfuJ KiSakJsUHKcZM8GQFWxTKfYhmB/oplxcBL3N/G1Xbhb5OpJzdhLprXYC5nCr2EiBQdjE GG88nWZH5KM/zLoe8LfEgbl1VQCXydoRHfH1RpmxQqWddV+YkBPm5XVSO5xeIRVb0XGA bSLg== X-Gm-Message-State: AOJu0YwyRp72PlyzIK6XF4SqQnC05JoQOFeRh3ey4otQoEgaQhtVNDZK T8NlKmJAittx78vM+/YTdHp+5StXUDAS+zXy7S2Xng== X-Received: by 2002:a05:6a00:1886:b0:692:a727:1fdd with SMTP id x6-20020a056a00188600b00692a7271fddmr103239pfh.4.1698340322692; Thu, 26 Oct 2023 10:12:02 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:a647:ad90:6e37:bd13:fb33]) by smtp.gmail.com with ESMTPSA id w18-20020aa78592000000b006bee5ad4efasm11516394pfn.67.2023.10.26.10.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:12:01 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Ian Rogers , Francesco Nigro , Carlos O'Donell , Siddhesh Poyarekar Subject: [PATCH 5/5] elf: Add glibc.mem.decorate_maps tunable Date: Thu, 26 Oct 2023 14:11:44 -0300 Message-Id: <20231026171144.2188549-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231026171144.2188549-1-adhemerval.zanella@linaro.org> References: <20231026171144.2188549-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, 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+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. --- NEWS | 5 +++++ elf/Makefile | 2 +- elf/dl-tunables.list | 5 +++++ manual/tunables.texi | 12 ++++++++++++ sysdeps/unix/sysv/linux/setvmaname.c | 4 ++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 9432564444..67f6e63b14 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 c3cf63a443..2603b90961 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -3023,5 +3023,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..2a5ad73e9d 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -653,6 +653,18 @@ 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), 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}). + +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 6459a158ac..466a0a004d 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. @@ -30,6 +31,9 @@ void __set_vma_name (void *start, size_t len_in, const char *name) { + if (TUNABLE_GET (glibc, mem, decorate_maps, int32_t, NULL) == 0) + return; + static int prctl_supported = 1; if (atomic_load_relaxed (&prctl_supported) == 0) return;