From patchwork Sat Oct 28 19:55:59 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: 738988 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp482957wrt; Sat, 28 Oct 2023 12:57:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN9zCCte41ZgJzCY9gG0z2Cut5731RzGk8QZHfocQK9qFqqDyzNXUy2podeCKJ1inuhSVu X-Received: by 2002:a05:6214:5b04:b0:65b:134:ed27 with SMTP id ma4-20020a0562145b0400b0065b0134ed27mr13517648qvb.4.1698523033868; Sat, 28 Oct 2023 12:57:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698523033; cv=pass; d=google.com; s=arc-20160816; b=RX4U3+7D4FvbudeHpalpLHDu05XUL7sDZWB9JVKvdMkjBmE9bwOIG1DhlNitbQQmBB aP2jIJYZ51L18VaMNORPjyWuJcGurFvdEICjGU1vdA2hdrywG3gYf+jsEXCaSKNwysa9 wtpjgE96uLhhEq5khpnutXXWQTERrOg2BuBxb0zI/W+ZbVDbb8wAMCLmEJtIFzMMcN/4 6sgI0JFyYt/qHsMOrXa01kKYHKbvabFSQCjVFAac2o1C0U1UvwF8aCdexP/lzmDS4Ywu cPYbv8Uw0z8VscVJgMnCWu7AgJkJZvo+F/tVUEVXdAjPMzRDT0Hogrv5qDCA0rIsHH88 2nGQ== 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=WlH95tVNYVT/bq+I1M60U0Pco+sIKS/SJrorYGSac1k=; fh=Lbqp+rs2mRBTG5C9ik7cirOzlOF2+U9yLxjtEQVqExY=; b=GeUEq6X58uO+yBVYkzjGbRKgwIPDcA7AipvraZlm6Eu3LX+XaFpRx3PgbyoLyEn1WA r1yYNfvy/acUrEjTLJVakx2WDck0YhxnDCk+jr0WjkiCHg/nsaF0eCCqAONDRmuq5VDp 8irk6F83xHxcFVSpL0xZPAkH/NFKFRCiT2QW2+2juXWljtf9QN3zv9e2lxSgYsfNt1c9 TJe5FBmwzAtmq2HUsldh28i5u/ObQxezEu6qqen+dfqiHOLI9dXI+H618VZ7l6VTOSSo y40QxAazhzDM7DBwuXFwb24q1Puf0Y+GNPcd2VKtMjUb1hTeP8BStIi8Sq5pLNZ1uEeu tMEw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ExAGM1HW; 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 ml4-20020a056214584400b0066d17e5f450si2845129qvb.30.2023.10.28.12.57.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 12:57:13 -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=ExAGM1HW; 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 7DDB53861924 for ; Sat, 28 Oct 2023 19:57:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 8BD1138618E1 for ; Sat, 28 Oct 2023 19:56:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BD1138618E1 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 8BD1138618E1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698522984; cv=none; b=M5UcDjMlwUsYuoIS6IftfIe6klnodMGkw2H73CaO6u1qwsUmz3qupVMnnbJo3VrJpTmvlPDF34dHOd7Wv9r2yTZlpllWQd5ycTy53LZGxIR2Y8IE5WsttPwhkKAH9F8nSOAaSD8Di1ebnDBFE/+eSz47AxGmiadsUy1QYbHICNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698522984; c=relaxed/simple; bh=54XFVv6yTgUxeZ6DeSgmQxu0PKDIKjfP/KDiGrUfBLM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jdCXj+KcPA6elAa4ynQkR2SFtBnOV79eVcn536ckgOnASWWAZBPb5XTk+DbZEWmL9zKWFeHvsM+XDeG2jphRp+kqjx5IqWaXNlEQMmAMZFCt0nz2x7aq174NPSoeBMzc7fa3Y4TFgKNprwCN2Egu6L2uJW9lsVVKt5Szp5OR0TI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6ce327458a6so1631300a34.1 for ; Sat, 28 Oct 2023 12:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698522981; x=1699127781; 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=WlH95tVNYVT/bq+I1M60U0Pco+sIKS/SJrorYGSac1k=; b=ExAGM1HWrfikSiQClfCF9Wg+Skt1niDyKbM55mnKCPiPWweMCNAMY9n8lJqGxsX4yr I6qagUZ4v1V2em4CL0hI/uNFdkGKrhPtjaWD1Lc9vvTZTQgx4JLhDZB2ZADRpcjiPoBQ rGlkAFI7UDgIOuqS4sFH3uQVuL1frBsz7PTYqbJYRaFHFCXIwogCADVA3qrFG7fwG7AO P1knIdh85uP16OYuKPWaU0igiJ38/9J+PX8mC8CwffDndB218C7fpCmN59gJwlbvmUBL zlTY7A5u2p7P/c/9urUmBxKL2WmmYYn98QNZJiL+Uh5WZ4T0c3ORnrFaP+3/Dfgnxhhe dBEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698522981; x=1699127781; 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=WlH95tVNYVT/bq+I1M60U0Pco+sIKS/SJrorYGSac1k=; b=u1hG3TwfASTBi/amlCDG2peDmcjB8GluNoCNsRqP2nnb6fi3hJePq1XXlCKX3hzrRF nUUv2MJ6TgBJzo9VnujCtSrWuYsyEU5Yzo4iemhdsyCDyGsnWhbnGqGw0lEe3jghaP2K KmD5+BA4FMWbGybXLEQoNt9ds6gPwRWV71SBWStSWMiZZaerPG7QJQFQ7fuqalls1mCE KWusetj4bvCm0rtokNC2ql80SRVYbyGutIdbD6VXiIZT9dko5emDLxJS1YcXVT77nygx 2vVlOXgnF8cILxCjtzbtmkC3hN0aVOkce/eZSgeob2TtPQcRAZVDwaURhQVdLu5AOeG6 Hq+w== X-Gm-Message-State: AOJu0YxXOD5OG5nV+u2cDEzgDTOLf9H4W95IY/9Awl19eXV0bdlnfoNC wqbs4kSz6vxF6A9fRcNUQz8vqM+9Sz1VrHWWrqzG7JlQ X-Received: by 2002:a05:6830:1550:b0:6b4:4ee1:b525 with SMTP id l16-20020a056830155000b006b44ee1b525mr3231663otp.1.1698522981219; Sat, 28 Oct 2023 12:56:21 -0700 (PDT) Received: from localhost.localdomain ([139.178.84.207]) by smtp.gmail.com with ESMTPSA id w20-20020a056830411400b006b8c87551e8sm763181ott.35.2023.10.28.12.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 12:56:19 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Ian Rogers , Francesco Nigro , Carlos O'Donell , Siddhesh Poyarekar Subject: [PATCH v2 7/7] elf: Add glibc.mem.decorate_maps tunable Date: Sat, 28 Oct 2023 19:55:59 +0000 Message-Id: <20231028195559.390407-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231028195559.390407-1-adhemerval.zanella@linaro.org> References: <20231028195559.390407-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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. Reviewed-by: DJ Delorie --- 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 9960ab5917..62237fcf7c 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, 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;