From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: Dave Martin <Dave.Martin@arm.com>
Cc: Eric Biederman <ebiederm@xmission.com>,
Kees Cook <kees@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Mark Brown <broonie@kernel.org>, Baoquan He <bhe@redhat.com>,
Vivek Goyal <vgoyal@redhat.com>, Dave Young <dyoung@redhat.com>,
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
Date: Wed, 8 Jan 2025 13:34:24 +0900 [thread overview]
Message-ID: <2c6f2c95-b2fc-46e0-91ce-1b9f14b28d3d@daynix.com> (raw)
In-Reply-To: <Z31T0dMgMucke5KS@e133380.arm.com>
On 2025/01/08 1:18, Dave Martin wrote:
> 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 <akihiko.odaki@daynix.com>
>> Acked-by: Baoquan He <bhe@redhat.com>
>> ---
>> 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.
If we want elf.h to be the authoritative source, yes, but I like the
current form as it ensures nobody adds a note with a name different from
"LINUX" and it is also simpler. There is a trade-off so I'd like to keep
the current form unless anyone has a strong preference for one option.
Regards,
Akihiko Odaki
>
> 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
next prev parent reply other threads:[~2025-01-08 4:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 12:45 [PATCH v3 0/6] elf: Define " Akihiko Odaki
2025-01-07 12:45 ` [PATCH v3 1/6] " Akihiko Odaki
2025-01-07 12:45 ` [PATCH v3 2/6] binfmt_elf: Use " Akihiko Odaki
2025-01-07 16:18 ` Dave Martin
2025-01-08 4:34 ` Akihiko Odaki [this message]
2025-01-08 13:45 ` Dave Martin
2025-01-07 12:45 ` [PATCH v3 3/6] powwerpc: " Akihiko Odaki
2025-01-07 14:37 ` LEROY Christophe
2025-01-07 12:45 ` [PATCH v3 4/6] crash: " Akihiko Odaki
2025-01-07 12:45 ` [PATCH v3 5/6] s390/crash: " Akihiko Odaki
2025-01-07 16:17 ` Dave Martin
2025-01-08 4:53 ` Akihiko Odaki
2025-01-08 13:02 ` Heiko Carstens
2025-01-08 13:50 ` Dave Martin
2025-01-09 5:29 ` Akihiko Odaki
2025-01-09 12:08 ` Dave Martin
2025-01-07 12:45 ` [PATCH v3 6/6] crash: Remove KEXEC_CORE_NOTE_NAME Akihiko Odaki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c6f2c95-b2fc-46e0-91ce-1b9f14b28d3d@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=Dave.Martin@arm.com \
--cc=bhe@redhat.com \
--cc=binutils@sourceware.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=devel@daynix.com \
--cc=dyoung@redhat.com \
--cc=ebiederm@xmission.com \
--cc=kees@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox