From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E0D5E77198 for ; Tue, 7 Jan 2025 16:18:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0D536B00B4; Tue, 7 Jan 2025 11:18:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBCC16B00B7; Tue, 7 Jan 2025 11:18:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5D566B00B9; Tue, 7 Jan 2025 11:18:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9800A6B00B4 for ; Tue, 7 Jan 2025 11:18:32 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 42590140A56 for ; Tue, 7 Jan 2025 16:18:32 +0000 (UTC) X-FDA: 82981163664.12.C4E23D7 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf04.hostedemail.com (Postfix) with ESMTP id 9ABBC40011 for ; Tue, 7 Jan 2025 16:18:30 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of Dave.Martin@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=Dave.Martin@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736266710; a=rsa-sha256; cv=none; b=3vtl9lmfUg9LFs6/99JQEWAYWEORDrXdFu0gR+PyH2E4N3fucWjBnBB99QJqbl2g9UPjZB 0kDPkSGf97wLybzXsiYP+KrBFG97tWsB/j3MG0TXUDzbulb78XbQ6P/SoWyIkr6ufEZyQz Dq1Locn8skslE10FXDS664l+BzQH5I0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of Dave.Martin@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=Dave.Martin@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736266710; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJSphBGIariLO7Kt8bB27/WK7gPxbh/RSwAS9mn80rs=; b=Z6OlMMKDGEu5EmvWiFPodYzr6ExGXBljeWTL8X3kavm/EbbDfaJEWibvrh3iRtW6S0IdIq k9cu9IgUCu3oG+7FXBLTkziNIEhFUPLPWQrZt8ilBpi32w3LQt+eLPGUoYdsFCBFxSj5t0 7V9sMVVMYWl41T4G9tFarNFtLeXA5CQ= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 30929143D; Tue, 7 Jan 2025 08:18:58 -0800 (PST) Received: from e133380.arm.com (e133380.arm.com [10.1.197.41]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CD3AA3F59E; Tue, 7 Jan 2025 08:18:27 -0800 (PST) Date: Tue, 7 Jan 2025 16:18:25 +0000 From: Dave Martin To: Akihiko Odaki Cc: Eric Biederman , Kees Cook , Catalin Marinas , Mark Brown , Baoquan He , Vivek Goyal , Dave Young , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kexec@lists.infradead.org, binutils@sourceware.org, devel@daynix.com Subject: Re: [PATCH v3 2/6] binfmt_elf: Use note name macros Message-ID: References: <20250107-elf-v3-0-99cb505b1ab2@daynix.com> <20250107-elf-v3-2-99cb505b1ab2@daynix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250107-elf-v3-2-99cb505b1ab2@daynix.com> X-Rspamd-Queue-Id: 9ABBC40011 X-Stat-Signature: 87b8i14nx7uhgp8chk7edfpbk58p5p8b X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736266710-833496 X-HE-Meta: U2FsdGVkX19Mon9/GtZuS8ws2n23b6R7hsh82XfabgT9MHMhEF77HrbOtD0AS+0BHqJbFfwDk3KivvSOW4OEU/bxyQUpUNI1zWCGjacluBDmyUHmY0IH1RE25Ix2kZ2fIHomhTZN/soYtzTRCtIAJ5CgjODq8O6da/EuJn46eUWDIgkkGqe34kwzcYmemT4cHqBvzuWGAGcRdT/v3aRZmOyonSvTZiOoiwQy05qQwN817SN7vGNjFjpuZ3C6jP1xbMXuMuEdPhodZuJU6y9fUZr1CnQ/PnxoCzVEKZlw0WlBYZzKIqJq8SckMmPv0R3OZpwXNP7SiDbZCt0lwFmeYB9tN1Mn9MKV/pWbwd69ihi+yo0g0iqi/S48mBRtOpeST+Kcero+K1eqYkTHiBc1CtGjvsL0p3VFIWWru+ZGrcF+LAi4eZrPNy+3oUECtWHbxhX2ROjdzjq5l0+8GsllUwAKKe7bDSKyArbKLRWo5ZRoq01G97LqEfcO1oJFxIg+E7wq/sjaYtxQGAbtI0H93KgKtqMlKlWvHjAhTWGuXMkz8J1laXcJRkVx7/5Mh6mYrB3VlVPXuV83KNNO1ABKq/RijfKxW86S30TM6711lk0UI4Y0aISQFJPhKQP5BBU8pkncnlGjz2427He0N4pWaVj2VMdr4fx8eq2FhHH03U24g6ds7hMuOpioWAklI2ZixLOXArHLOVyv9WET+1SOlC0GrPgExDPNaL1SaKEtSnKweIMnn6EGKfzeFl79e2VfzAQOcVxLKtrOoURtS5SUY7Na6J7OU0r46qnxt+ZvDa9RxnCqwBqyxWVqkFO/2eh5WTp2/JdhJALn/c/rLlhF9yb10K83QzdypBZWzYIGwo+j0N9snlT0xv91hnUOTpqPXts4hLosQh8RUuzuAiVc6+5gQtrd/3rJz+Ccxh5HbfSMHhG817m4inE2czrS1aQO2i+psqvxiLjMDhnMpoD Lo70Trgw 3encawXOxuSo7cS5bFyfSDRahDw6okzy5/waSjAL9RCaOGsjDTAKveQzEj8xicjHUHNm9/h6zaWSifA/IMt2SBSyFk5x6Lu6bfy0jtdD6BkFaZsVOR+bItxLEveX4LAJC0YAJAAETiOVCINfGojJWhDsV3C+rad6OCVH9smumMzMwNyvlgnYR+OMok7cXw7T34Wyfi3rQsYJWqBe5EkP9AqcpgC4n1wA0LzgFzIzRkA0Oyk6V9Aa/A87tgP17THd8Bx/yiuAtOol/LT6k1blK+L7WYQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jan 07, 2025 at 09:45:53PM +0900, Akihiko Odaki wrote: > Use note name macros to match with the userspace's expectation. Also (and more importantly) get rid of duplicated knowledge about the mapping of note types to note names, so that elf.h is the authoritative source of this information? > > Signed-off-by: Akihiko Odaki > Acked-by: Baoquan He > --- > fs/binfmt_elf.c | 21 ++++++++++----------- > fs/binfmt_elf_fdpic.c | 8 ++++---- > 2 files changed, 14 insertions(+), 15 deletions(-) > > diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c > index 106f0e8af177..5b4a92e5e508 100644 > --- a/fs/binfmt_elf.c > +++ b/fs/binfmt_elf.c [...] > @@ -1538,7 +1538,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) > do > i += 2; > while (auxv[i - 2] != AT_NULL); > - fill_note(&auxv_note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv); > + fill_note(&auxv_note, NN_AUXV, NT_AUXV, i * sizeof(elf_addr_t), auxv); > thread_status_size += notesize(&auxv_note); > > offset = sizeof(*elf); /* ELF header */ Looking at this code, it appears that the right name is explicitly taken from elf.h for a few specific notes, but for those that are specified by the arch code (e.g., in struct user_regset entries) the name is still guessed locally: static int fill_thread_core_info(...) { ... fill_note(&t->notes[note_iter], is_fpreg ? "CORE" : "LINUX", note_type, ret, data); It would be preferable to clean this up if we want elf.h to be the authoritative source for the names. It would be possible to add a .core_note_name entry in struct user_regset, and define a helper macro to populate the note type and name, something like the following: struct user_regset { ... unsigned int core_note_type; + unsigned int core_note_name; }; #define USER_REGSET_NOTE_TYPE(type) \ .core_note_type = NT_ ## type, \ .core_note_name = NN_ ## name, ...and then replace every .core_note_type assignment with an invocation of this macro. A quick git grep should easily find all the affected cases. Alternatively, as discussed in the last review round, a helper could be defined to get the name for a note type: const char *elf_note_name(int Elf32_Word n_type) { switch (n_type) { case NT_PRSTATUS: return NN_PRSTATUS; case NT_PRFPREG: return NN_PRFPREG; /* ...and all the rest..., then: */ default: WARN(); return "LINUX"; } } This avoids the caller having to specify the name explicitly, but only works if all the n_type values are unique for the note types that Linux knows about (currently true). Experimenting with this shows that GCC 11.4.0 (for example) doesn't do a very good job with this switch, though, and it requires building knowledge about irrelevant arch-specific note types into every kernel. I think that extending struct user_regset is probably the better approach -- though other people may disagree. Cheers ---Dave