From patchwork Thu Oct 26 17:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 738332 Delivered-To: patch@linaro.org Received: by 2002:ab3:1905:0:b0:23f:8cfb:5ad7 with SMTP id u5csp1311623ltc; Thu, 26 Oct 2023 10:12:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeYvbwYzFhVbbCJURFVjhV0oVVnwW9EQW3NlTt5PSiAAhX5ay33FEN0un/kfFkPsGJJ3nS X-Received: by 2002:a05:6102:101b:b0:457:c445:69f3 with SMTP id q27-20020a056102101b00b00457c44569f3mr207859vsp.34.1698340328719; Thu, 26 Oct 2023 10:12:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698340328; cv=pass; d=google.com; s=arc-20160816; b=YaShkRJkcOepSlWhpXBiP03ceijj4kH2dMYlJ7gr+o+l7q423yrlfjFjF/jh59jIUX myrKZZjwRoVnY87dbIorL9J8vMRsKKNhbdDSMl1CTy6rV7FoHUTj9KZyztcGyOqzUNGF yzv4aASduCDhO6V9C+J9DWVbgYepwF1G7gmN6GJYXFdYOa0p/jrzA6oZ1UBdBpKPvccn FazVMDKA946GjW1cIzNwRAMFijr2G7RBWIr2cNGgYpYzQHKh8nwSTZtFPSO4vyrt7OIh CZKnrv9UZitmYQxX4sgwNohQOWiSxiltkYw9agD6UOvKZKdzp05CP7u38GE1ZzcGE4pZ Ndew== 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=P82T3XiHlcAORYon69t5gtQ9Xhw+Xw3KC0QpBrGYFAQ=; fh=Lbqp+rs2mRBTG5C9ik7cirOzlOF2+U9yLxjtEQVqExY=; b=IMHBHdXqguGtLfEBZHYhSX7ZV2BSd/dqxJyj52f6u3MoB9IMlaUDRVksDlHY/rFn5a Cic1rQ9nrFYzRcUG99WuDhQSRVtZNI/G5xaSegesZaZnvYoCpmzhqQ6yl7n3kOXZucrO COefS5uwJdDfTodQ3nM7Bvd0ZV//vnx/7C8O9syUQEuUXkklsaLuH22vEY1QIw6NybV9 UMHJKnJEFWpjz1k1A9tHDc+Hg+s3zk3/hp2+pydrfQR8q8M9yRH7AuKnkzlHYEkSyHFG d7Z22ay3bFh5yWFjj0hNHZsSjziJXK9ZqXWIBwcCH2Rv+zkcVJO3XA2YFV7Q6Ho/otoU 7wSw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mNCJPPSB; 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 dt31-20020a05620a479f00b00770eaca9182si9640291qkb.303.2023.10.26.10.12.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:12:08 -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=mNCJPPSB; 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 4C49B385414F for ; Thu, 26 Oct 2023 17:12:08 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 93C793858C2A for ; Thu, 26 Oct 2023 17:11:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93C793858C2A 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 93C793858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698340316; cv=none; b=NtFP9snnyehy8YYXR37uqFKYwyvtl2k4lCkHB59+phYN0RpYpeXcqVoEsTsHQ//cn72vf25US8s3hkcTr+3MD85ay0hysF7P7LLKuakmplP0wLUva+9/mXtybz008fPDjofAX5CDw5Q4/HXRebde0880XMbYlMxuX9R52+gTpHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698340316; c=relaxed/simple; bh=YXj8f/nMi4Loh2EH2RC257eclpZ4ggJfMEt6u6AsvYQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=IaR4pd++ti1kQxDVUyoKeBJ9sBSaamePbBnGy7uE7g1pk7bOjq00rJ6IPrEg8a2zn3YvcqlW2Cmoj1qzGS7qw3KHGmP43r7oL4ex3x3aTEdhDMz7sfLx4GkPn2b/jiWtBZz4AKXsUvBBAHRk1kENW01OdDx42MCgkOgDN4fEpiQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6b2018a11efso1149380b3a.0 for ; Thu, 26 Oct 2023 10:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698340312; x=1698945112; 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=P82T3XiHlcAORYon69t5gtQ9Xhw+Xw3KC0QpBrGYFAQ=; b=mNCJPPSB5Z9TZEtrip8y8ORwAVvp8BpX02PafYmiUKU5ioF4VMERcK4Z8/UU9Roum+ BsTfRKwf69VrKdD4k2ZFSgCLspnse6Jvm+1Ul6k2vDfS8Oqeqh/BhY20oQWyvNtoDJXC qXVVkFrMMXBOBAj8RxG28s8JS8MC77H2REoFSrWl8xanY5MwY6J/4UOAXtPlHgabMiYY rMelXtYNm6+o9lCqe+N83l58F1qfdHVVEvCCBksPsI05D1XXhwdLbwwednMp+JgM/rm/ wIbdKl7mkmWPmNvYPMop5d4jYKTIMN0v5ZpsC1TLY89dSLYLe42Sos4HApRuOeOZP57S qLsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698340312; x=1698945112; 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=P82T3XiHlcAORYon69t5gtQ9Xhw+Xw3KC0QpBrGYFAQ=; b=DGwH/5hGLLFxg4vjjoIfHufzsGAvxKPvHVbof+BqWmjBEgIv9dWtIJKEkFArK0Rqys LIUrWxEufJJ7GC2wPiy9JXV2FNxoPr0Cte3tsAl0SaspJh3qbPb4PF9gsfpDp4jAvIqL i/0ytAeutqvfcQpOgsXPWHqHw+zft5+GvATl9xJbR9TdhUtIOe/B286L+KdbIefmvDcO ZeQWAVMunMKKH3w2yCKVCjGjvIjFwUw2Xr7Lbz5U0Wt5xFqC4w/AWlLfRLFILT0PpoG0 j08+zXS2ahy70cCOkVyaUJA8+q7s2GvZARXI+U4WUzChpDWgPGYLHzh8sxazvmdJarDC uhlQ== X-Gm-Message-State: AOJu0YxYRgPotvysyVBj3Yo9DUnEcVPjkTgjioELHMh/XdunnqWlAst7 fDpP/393Pri7hv2C6m0IZH3lsmP5K+Nh8p/XgCmV+A== X-Received: by 2002:a05:6a21:819e:b0:15e:7323:5c0f with SMTP id pd30-20020a056a21819e00b0015e73235c0fmr460157pzb.16.1698340311930; Thu, 26 Oct 2023 10:11:51 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:11:51 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Ian Rogers , Francesco Nigro , Carlos O'Donell , Siddhesh Poyarekar Subject: [PATCH 1/5] linux: Add __set_vma_name Date: Thu, 26 Oct 2023 14:11:40 -0300 Message-Id: <20231026171144.2188549-2-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.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 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 ("\\`$[]"). --- 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 | 27 +++++++++++++++++ 5 files changed, 104 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..43ebd93822 --- /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_in, + 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..6459a158ac --- /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_in, 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_in, 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..0f875dbf5a --- /dev/null +++ b/sysdeps/unix/sysv/linux/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 + +/* Set the NAME to the anonymous memory map START with size of LEN. + It assumes well-formatted input. */ +void __set_vma_name (void *start, size_t len, const char *name) + attribute_hidden; + +#endif