From patchwork Wed Nov 1 12:56:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 740059 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp267343wrv; Wed, 1 Nov 2023 05:56:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFG2XZqbogE1lxEMROmcgJ5WbnILn1xMAdtCwNabdMHJkJJ1hwyN0DCgi62ejsAsPMDjcTn X-Received: by 2002:a05:622a:307:b0:41c:dfce:1289 with SMTP id q7-20020a05622a030700b0041cdfce1289mr20236306qtw.51.1698843393933; Wed, 01 Nov 2023 05:56:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698843393; cv=pass; d=google.com; s=arc-20160816; b=Ks8KG/H19SdXgjlda8+K5omflIgRl52+a5dbdP7WeCQzGwRHZRupmvwtdS2KItC1Oq 3NrPVfxzaY6+Yve3HKv3lZ7EDAYT2r0l5Sg+12IVvbbtxkveSwzb5KVTgjl8sCYoHKVe IRqXhwg78UeYfaSD8boWr624U4aoaZZIT8KOpkzjE+cIXNyZvLC3H0i6ThPDZWxfdV9J 0Oj7QhFw7GCnEUfkRgsct/Fbk1X10CyYuWQzI6Q83/iqL0BvW/l7zRN8S0qlYEbGPDek 6KvDgt0NVB12nXM0k++Go2HdQ4RhJ2qI/rZFI6JQLDgGIhWZmvyC5ArnCu8c13FRDFen EHJA== 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:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=HBBLnLezcgsC9fgPZBJl25j0TweFDWSN9xTQJx9hrnk=; fh=wOialSeEyZrL0Zmx/XQW8gMhKHOwjxYz8NEgiPSksGI=; b=0dq8RkcqODf8rvFWa2fhyEy44qqvNqN7TrsKbvQuNH64doCCg63+QB784eQ4zCUttA ylRA6oiczMx9H3T/dFoNP3K4A5eVjLE2i1BTsirvFlQSljemd3nUMeRF7o8zT+7JKVSR 42KhwzhQOmuRzhx9lEe+C3NefFfCGHijtFjTCE24w33j7XvVgGmHqxzlfiney83ewQfo 3AzejIFLR+D/BNu9IGlzPAobiV1Vyqgl273kAqVUX5xGhoii9ztPqE9oMw8YNGZf3EYr yJiW5T22gsRvCnAb5vCIpREr1Htn58ruuU1vCbqQo76Xq/6P5bJ5loXWq501YnLqQROC XtDQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yAopBu1C; 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 l4-20020a05622a174400b004198ff97550si2631258qtk.28.2023.11.01.05.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:33 -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=yAopBu1C; 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 8C7E73857737 for ; Wed, 1 Nov 2023 12:56:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by sourceware.org (Postfix) with ESMTPS id 91C9B3858C60 for ; Wed, 1 Nov 2023 12:56:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91C9B3858C60 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 91C9B3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843387; cv=none; b=GIwaQ79zlzpMRRPXPA+px7RQnkegaHbr2phX/k/KY6UGBZL+4ObcuU28PiZnhvjAskdLpBmpLpJKfruIvUf4Hin8Y1HdjU6bNRjFsOQAuZnfDQoGhmJJGBcba/K+rirlRBi696Ks/EWqw45QrYzHIdbIvUT3lgWbCM5mz7FBmVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698843387; c=relaxed/simple; bh=pFxXY2ytaq/J8nv3jruAUxkWI0CpVOyFD76ghPKUmGI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=i6ODhP7tMClA8vBhxl9cSXrbiIPx72prOw4xfY2ftNRHlw/W/8ENNSt7gbsx+FLbJYKxb1mYFxf0urfBuzKFzwkVba/AyEce1njg+2B8PzByLPs7s2QecfViGliuLNadRACxyhRwe+roBZGjImEhjPlYvrbHd27aikLK7wMVVpg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5b383b4184fso17811937b3.1 for ; Wed, 01 Nov 2023 05:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698843376; x=1699448176; 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=HBBLnLezcgsC9fgPZBJl25j0TweFDWSN9xTQJx9hrnk=; b=yAopBu1CUwdElpIiLzNQ5u0Xp4J/GBHZbx6kx23mUUxMFeCfG8d3hp4ucEBMcD6E6G IFFFRxK+42/bJNQopgUAbPd9gRht6gsoHBdVB2/Fjuz5kSxa5r9E8/8wf/D54JXf3Z9X 40/zDmti8LDSN5fBk7/VjRi5bu6A/VuzLFk5SAN+tJzX7xtMCaeujb66pwx39PP3b6t8 DlbSQAUNnJvL8q5COUG0XWPh0HmgPQqSPDCObLkomlXipli4CT022oiAvCb1q59uqtDH Sy1WrL+f23jScv4L+tfE6p1Rb+BzzUBNQUa3eONScHXnWjso1EhBDxVjcbqwTijScWXL lFyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698843376; x=1699448176; 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=HBBLnLezcgsC9fgPZBJl25j0TweFDWSN9xTQJx9hrnk=; b=mzPZMf0rFm4XWVdth3vaL9d4BaT5kyThpWqeo780jnijF6fIFUZEANTYMhLCdkINB/ R6OlhsjoHl4s6Ye5wXGCTSOYA+Sxu5nMbAaflueLkabF4qpbX/OdBlVpekoxFYwJ+yw6 B2lCBRJp2iUH4Xn/IcVapHqK/cwUL9okGOH2MikBxbmJFZQBPWuw6RGfa3mDrDnD5yX8 Ll0HrWPkXRbZklXEDKcH2LE1P3KYfyIlGQ1DxLcASjtm9cUYGc6d/+ASHCU8TiKWgqdp OB6kZX+cVfUL1BZZLTy/tAFTPu6X4bt6hWNWkF8xkAth2rSle6baKqAtfcxpt0vYH36a 6EEw== X-Gm-Message-State: AOJu0YxTDglbJyhTjBLTxhApxniVOWZccMjD1CnOA/5Vck7WeYVYwn6I nexBPoE6Ce5S+pvLhCf5238vg/5y0jO8gglbq3We3w== X-Received: by 2002:a25:6b4b:0:b0:d9d:5e9:c65b with SMTP id o11-20020a256b4b000000b00d9d05e9c65bmr13323709ybm.39.1698843376297; Wed, 01 Nov 2023 05:56:16 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 05:56:15 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, DJ Delorie , Ian Rogers , Francesco Nigro , Carlos O'Donell Subject: [PATCH v3 0/7] Add a tunable to decorate anonymous memory maps Date: Wed, 1 Nov 2023 09:56:04 -0300 Message-Id: <20231101125611.208544-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.5 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, T_SCC_BODY_TEXT_LINE, 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 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, 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 Changes from v2: * Rename support_set_vma_name to support_set_vma_name_supported. * Extend documentation. Changes from v1: * Fixed arm thumb build. * Added decoration on assert and __libc_fatal. Adhemerval Zanella (7): linux: Add PR_SET_VMA_ANON_NAME support support: Add support_set_vma_name nptl: Decorate thread stack on pthread_create malloc: Decorate malloc maps assert: Decorate error message buffer linux: Decorate __libc_fatal error buffer elf: Add glibc.mem.decorate_maps tunable NEWS | 5 + assert/assert.c | 2 + elf/Makefile | 7 + elf/dl-minimal-malloc.c | 2 + elf/dl-tunables.list | 5 + elf/tst-decorate-maps.c | 196 +++++++++++++++++++++++ include/sys/prctl.h | 5 + malloc/arena.c | 4 + malloc/malloc.c | 5 + manual/tunables.texi | 17 ++ nptl/Makefile | 4 + nptl/allocatestack.c | 40 +++++ nptl/pthread_create.c | 6 + support/Makefile | 1 + support/support.h | 4 + support/support_set_vma_name_supported.c | 49 ++++++ sysdeps/generic/setvmaname.h | 27 ++++ sysdeps/posix/libc_fatal.c | 3 + sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/setvmaname.c | 49 ++++++ sysdeps/unix/sysv/linux/setvmaname.h | 36 +++++ 21 files changed, 468 insertions(+) create mode 100644 elf/tst-decorate-maps.c create mode 100644 support/support_set_vma_name_supported.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