From: Greg KH <gregkh@linuxfoundation.org>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: add basic ELF sections parser
Date: Thu, 15 May 2025 13:42:05 +0200 [thread overview]
Message-ID: <2025051532-gentleman-reset-58f2@gregkh> (raw)
In-Reply-To: <D9WP3YU31199.Q8IEDBJZ87LU@nvidia.com>
On Thu, May 15, 2025 at 08:25:33PM +0900, Alexandre Courbot wrote:
> On Thu May 15, 2025 at 5:32 PM JST, Alexandre Courbot wrote:
> > Hi Greg,
> >
> > On Thu May 15, 2025 at 4:38 PM JST, Greg KH wrote:
> >> On Thu, May 15, 2025 at 03:03:51PM +0900, Alexandre Courbot wrote:
> >>> Add a simple ELF sections parser for unpacking loaded binaries from
> >>> user-space. This is not intended to become a fully-fledged ELF parser,
> >>> just a helper to parse firmwares packaged in that format.
> >>>
> >>> This parser is notably helpful for NVIDIA's GSP firmware, which is
> >>> provided as an ELF binary using sections to separate the firmware code
> >>> to its other components like chipset-specific signatures.
> >>>
> >>> Since the data source is likely to be user-space, checked arithmetic
> >>> operations and strict bound checking are used.
> >>>
> >>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> >>> ---
> >>> This will soon be needed in order to load the GSP firmware in nova-core,
> >>> so sending this early for separate review.
> >>> ---
> >>> rust/kernel/elf.rs | 322 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >>
> >> Why is this not just done in userspace and then have userspace feed the
> >> proper elf sections to the kernel through the firmware interface?
> >> Having to parse elf seems crazy for the kernel to be forced to do here
> >> as the kernel should NOT be touching anything in a firmware blob other
> >> than passing it off to the firmware directly.
> >
> > FWIW, the GSP firmware in question is already in linux-firmware and
> > loaded by e.g. Nouveau.
> >
> > I am not sure how userspace could feed the proper ELF sections otherwise
> > than by splitting the ELF binary into as many files as there are
> > sections. Is that what you imply, or is there another means that would
> > preserve the current firmware format?
> >
> > Note also that in this particular case, the kernel cannot just pass the
> > firmware without modifying it anyway since the signatures relevant to
> > the chipset need to be patched into the right place before it is loaded.
>
> Quick nit, as that last statement was not entirely correct: while we do
> patch some loaded firmware with signatures, this is not the case for the
> GSP (the one in ELF format). Not that it changes the point, but for the
> sake of accuracy. :)
>
> The point being that even without using ELF as a container format, we do
> need to parse header structures in loaded firmware files anyway, so the
> kernel cannot simply act as a dumb pipe for firmware. And since we need
> to add structure, let's at least use a format that is simple, well
> accepted and which layout is already in the kernel.
>
> Or if ELF is the problem, I don't mind introducing a WAD loader. ;)
The "problem" I'm not understanding is why does the kernel have to do
any of this parsing at all? What does it do with these segments that
userspace can't do instead? Why does patching have to be done within
the kernel at all? What prevents all of this from being done elsewhere?
And ELF parsing is "tricky" in places, and you aren't using the existing
elf parser, as proof of needing a new parser in rust :)
thanks,
greg k-h
next prev parent reply other threads:[~2025-05-15 11:43 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 6:03 [PATCH] rust: add basic ELF sections parser Alexandre Courbot
2025-05-15 7:38 ` Greg KH
2025-05-15 8:32 ` Alexandre Courbot
2025-05-15 11:25 ` Alexandre Courbot
2025-05-15 11:42 ` Greg KH [this message]
2025-05-15 13:09 ` Alexandre Courbot
2025-05-15 14:30 ` Timur Tabi
2025-05-15 19:17 ` John Hubbard
2025-05-16 13:15 ` Greg KH
2025-05-16 13:26 ` Alexandre Courbot
2025-05-16 13:32 ` Greg KH
2025-05-16 13:35 ` Danilo Krummrich
2025-05-16 14:35 ` Alexandre Courbot
2025-05-16 16:01 ` Danilo Krummrich
2025-05-16 19:00 ` John Hubbard
2025-05-17 10:13 ` Danilo Krummrich
2025-05-17 13:41 ` Alexandre Courbot
2025-05-16 16:28 ` Timur Tabi
2025-05-17 0:51 ` Alexandre Courbot
2025-05-29 6:53 ` Alexandre Courbot
2025-05-29 8:01 ` Greg KH
2025-05-30 0:58 ` Alexandre Courbot
2025-05-30 6:21 ` Greg KH
2025-05-30 6:56 ` Alexandre Courbot
2025-05-30 9:00 ` Greg KH
2025-05-30 6:22 ` Greg KH
2025-05-30 6:59 ` Alexandre Courbot
2025-05-30 9:01 ` Greg KH
2025-05-30 14:34 ` Alexandre Courbot
2025-05-30 15:42 ` Greg KH
2025-05-30 18:10 ` Timur Tabi
2025-05-31 5:45 ` Greg KH
2025-05-31 10:17 ` Timur Tabi
2025-05-31 12:25 ` Greg KH
2025-05-31 14:38 ` Timur Tabi
2025-05-31 15:28 ` Danilo Krummrich
2025-06-01 7:48 ` Greg KH
2025-05-31 12:33 ` Alexandre Courbot
2025-05-31 13:30 ` Greg KH
2025-06-01 12:23 ` Alexandre Courbot
2025-06-13 3:32 ` Alexandre Courbot
2025-06-24 14:26 ` Greg KH
2025-06-24 14:51 ` Danilo Krummrich
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=2025051532-gentleman-reset-58f2@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).