From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 6043C3858D20 for ; Thu, 26 Oct 2023 17:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6043C3858D20 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 6043C3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698340314; cv=none; b=NAo9irWEKU5+rxoiVH6XIjYrmzWI1SJI2juK9wVoU9NKvo6tvk5ibn4ewmrb1E+5mCrS3pl3hQQn3e7l7Cj42mOs7Av3uc0VWQY1uOiprJRcqRaPKGNkx0sFdtDhOmJmKYtDl61EfZwdwMx4j9yl277F2Jb+nJJRriFuBqgLxNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698340314; c=relaxed/simple; bh=0ezF1kaE9aIV933QsI/L4vI5Z7jQJpmXISXRQtBF+zk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ph0WKAekBSDvK2XNnjeGfNOowXb5lS4jlwCN8lyA11VS8BImTUAuk19RDw8AjrBN6IXAuXjHRoKOkaEhdtbwvGcJVRAoBkTwWNm5qFfXepVfNGFHtZ5+r2SJK8knr/a0F5nHNQt2OtvWoopNSaq6S0NdXY9AEJKNXRlsgaaqXxg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6b497c8575aso1139743b3a.1 for ; Thu, 26 Oct 2023 10:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698340309; x=1698945109; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=uC37BdxCh2ViYT3iupCMt3YVltJ7mH95BhJPv/5STvs=; b=A62SOhcDbJ4ytmCO5JiBqJvYywdSpP6Q8VZhRfhItcpbl+pLcbth5R4qeoIQiuDLek bbJAPYdViom7353OsgsfGrq7buv/0sXna9R3mpX6Bk/Kz11ZNy+TM6eOO5T9cVeIoQ3Y vrOF5+DYlxHRhpNz/q5lyOYehrgd1sqkjXFzWaX2b0OmPQk408wIzY/g+smW/SuPwr/i 1ReLUXr4wit+nYK1sACCRZs7/0xL+xnUvkFYYioCucxPp50YeUAJ/Rpt7rF6zKtm+m/M lE4mifoQ5aczobS8Fe1GkmYBGsuky/qF7VpQK6nIDxXeP5xjlYT0a9u/T+21zUp8IR6S lVsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698340309; x=1698945109; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uC37BdxCh2ViYT3iupCMt3YVltJ7mH95BhJPv/5STvs=; b=AenzIE9NUADJdv99nK4GOaA+WYmEIyzsZk77iFglKovnvMYs4sHmBFXpPC4cmRCNcp TFafSAnu4fTzhutF1IPDu3RsAitHiKYJ2BlbG3hhT+0yl+R/cezFOOklUcvUVCwX4qhe JahjF3i1UshMXSPPjradZXp4IVUz536tC2HgY/kPMcnTfDpkShpLdGNpH2PqmBHboAjD FeNAJwXA0VNyxdR5cERzBSmhwB/uc0xZMv4WgUGANRNheNB3dPS9M5wOnISY3zg8yrBO Bbba7TTFsKEEfOBsNPlHOyhg7ylImTk624a1H46sAtuVi8MzkhwENdBgK9A25zQbWAjd ynOQ== X-Gm-Message-State: AOJu0YzJQLYZnhHO4FXjqGnaBXwf5WP+qdR2Eql9PBuDdrwVEA8CzMxh 5qztCn0wjZympoNsaHMQofsBzvQUuDtG0WPEhcxFXQ== X-Google-Smtp-Source: AGHT+IHxXP1+3lp5YKV1MLpC7QQCS60JJEkVkzog5hpAE3Ggzrp5LjbfvW1/BnFbc60wA45iE6PcPw== X-Received: by 2002:a05:6a00:853:b0:6bb:6d30:fc4e with SMTP id q19-20020a056a00085300b006bb6d30fc4emr115415pfk.17.1698340309557; Thu, 26 Oct 2023 10:11:49 -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.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:11:48 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Ian Rogers , Francesco Nigro , Carlos O'Donell , Siddhesh Poyarekar Subject: [PATCH 0/5] Add a tunable to decorate anonymous memory maps Date: Thu, 26 Oct 2023 14:11:39 -0300 Message-Id: <20231026171144.2188549-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Linux 4.5 removed thread stack annotations due to the complexity of computing them, and Linux 5.17 added support to naming anonymous virtual memory areas through the prctl syscall [1]. Android and other projects like sanitizers uses this feature to improve debugability and a way to user understand better what kind of memory runtime allocates. The patchset adds annotations for the pthread stack, on both glibc created and user-provided, on loader minimal malloc and on malloc arenas and default allocation. For instance, on x86_64 the resulting mapping of the newly tst-decorate-maps shows: 5649d25bd000-5649d25bf000 r--p 00000000 103:05 40141614 /elf/tst-decorate-maps 5649d25bf000-5649d25c3000 r-xp 00002000 103:05 40141614 /elf/tst-decorate-maps 5649d25c3000-5649d25c5000 r--p 00006000 103:05 40141614 /elf/tst-decorate-maps 5649d25c5000-5649d25c6000 r--p 00007000 103:05 40141614 /elf/tst-decorate-maps 5649d25c6000-5649d25c7000 rw-p 00008000 103:05 40141614 /elf/tst-decorate-maps 5649d36c4000-5649d36e5000 rw-p 00000000 00:00 0 [heap] 7fc76c000000-7fc76c021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc76c021000-7fc770000000 ---p 00000000 00:00 0 7fc774000000-7fc774021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc774021000-7fc778000000 ---p 00000000 00:00 0 7fc77c000000-7fc77c021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc77c021000-7fc780000000 ---p 00000000 00:00 0 7fc784000000-7fc784021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc784021000-7fc788000000 ---p 00000000 00:00 0 7fc788000000-7fc788021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc788021000-7fc78c000000 ---p 00000000 00:00 0 7fc78c000000-7fc78c021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc78c021000-7fc790000000 ---p 00000000 00:00 0 7fc790000000-7fc790021000 rw-p 00000000 00:00 0 [anon: glibc: malloc arena] 7fc790021000-7fc794000000 ---p 00000000 00:00 0 7fc796800000-7fc797000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188506] 7fc797000000-7fc797800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188505] 7fc797800000-7fc798000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188504] 7fc798000000-7fc798800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188503] 7fc798800000-7fc799000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188502] 7fc799000000-7fc799800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188501] 7fc799800000-7fc79a000000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188500] 7fc79a000000-7fc79a800000 rw-p 00000000 00:00 0 [anon: glibc: pthread stack: 2188499] 7fc79a800000-7fc79a826000 r--p 00000000 103:05 38343761 /libc.so 7fc79a826000-7fc79a99a000 r-xp 00026000 103:05 38343761 /libc.so 7fc79a99a000-7fc79a9f1000 r--p 0019a000 103:05 38343761 /libc.so 7fc79a9f1000-7fc79a9f5000 r--p 001f0000 103:05 38343761 /libc.so 7fc79a9f5000-7fc79a9f7000 rw-p 001f4000 103:05 38343761 /libc.so 7fc79a9f7000-7fc79aa04000 rw-p 00000000 00:00 0 7fc79aabb000-7fc79aafb000 rw-p 00000000 00:00 0 [anon: glibc: pthread user stack: 2188508] 7fc79aafb000-7fc79ab3b000 rw-p 00000000 00:00 0 [anon: glibc: pthread user stack: 2188507] 7fc79ab3b000-7fc79ab7c000 rw-p 00000000 00:00 0 [anon: glibc: malloc] 7fc79ab7c000-7fc79ab7d000 rw-s 00000000 00:01 19458 /dev/zero (deleted) 7fc79ab7d000-7fc79ab82000 rw-p 00000000 00:00 0 [anon: glibc: loader malloc] 7fc79ab82000-7fc79ab83000 r--p 00000000 103:05 40141609 /elf/ld.so 7fc79ab83000-7fc79aba9000 r-xp 00001000 103:05 40141609 /elf/ld.so 7fc79aba9000-7fc79abb3000 r--p 00027000 103:05 40141609 /elf/ld.so 7fc79abb3000-7fc79abb5000 r--p 00031000 103:05 40141609 /elf/ld.so 7fc79abb5000-7fc79abb7000 rw-p 00033000 103:05 40141609 /elf/ld.so 7ffdb2f1d000-7ffdb2f3f000 rw-p 00000000 00:00 0 [stack] 7ffdb2f7a000-7ffdb2f7e000 r--p 00000000 00:00 0 [vvar] 7ffdb2f7e000-7ffdb2f80000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] The PR_SET_VMA_ANON_NAME support is currently 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. There is also a potential scalability issue, where the prctl requires take the mmap global lock and it still not fully fixed in Linux [1] (for pthread stacks and arenas, it is mitigated by the stack cached and the arena reuse). So the decoration is only enable through a new tunable, glibc.mem.decorate_maps. [1] https://github.com/torvalds/linux/commit/65376df582174ffcec9e6471bf5b0dd79ba05e4a [1] https://github.com/torvalds/linux/commit/9a10064f5625d5572c3626c1516e0bebc6c9fe9b Adhemerval Zanella (5): linux: Add __set_vma_name support: Add support_set_vma_name nptl: Decorate thread stack on pthread_create malloc: Decorate malloc maps elf: Add glibc.mem.decorate_maps tunable NEWS | 5 + elf/Makefile | 7 + elf/dl-minimal-malloc.c | 2 + elf/dl-tunables.list | 5 + elf/tst-decorate-maps.c | 197 +++++++++++++++++++++++++++ include/sys/prctl.h | 5 + malloc/arena.c | 4 + malloc/malloc.c | 5 + manual/tunables.texi | 12 ++ nptl/Makefile | 4 + nptl/allocatestack.c | 40 ++++++ nptl/pthread_create.c | 6 + support/Makefile | 1 + support/support.h | 4 + support/support_set_vma_name.c | 49 +++++++ sysdeps/aarch64/Makefile | 5 +- sysdeps/generic/setvmaname.h | 27 ++++ sysdeps/unix/sysv/linux/Makefile | 5 + sysdeps/unix/sysv/linux/setvmaname.c | 48 +++++++ sysdeps/unix/sysv/linux/setvmaname.h | 27 ++++ 20 files changed, 457 insertions(+), 1 deletion(-) create mode 100644 elf/tst-decorate-maps.c create mode 100644 support/support_set_vma_name.c 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 -- 2.34.1