From: Yao Zi <me@ziyao.cc>
To: E Shattow <e@freeshell.de>, Yao Zi <me@ziyao.cc>,
Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
Cc: u-boot@lists.u-boot-project.org,
Tim Ouyang <tim609@andestech.com>,
Leo Liang <leo.liang@sifive.com>, Tom Rini <trini@konsulko.com>,
Troy Mitchell <troy.mitchell@linux.spacemit.com>
Subject: Re: [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode
Date: Sun, 6 Dec 2026 00:23:04 +0000 [thread overview]
Message-ID: <axSq6EHJw6UV16N8@pie> (raw)
In-Reply-To: <aef3af29-e024-4e34-8d03-4a45758dd182@freeshell.de>
On Sat, Dec 05, 2026 at 02:34:02PM -0800, E Shattow wrote:
> On 12/5/26 13:54, Yao Zi wrote:
> > On Sat, Dec 05, 2026 at 09:40:16AM -0800, E Shattow wrote:
> >> Hi Anirudh,
> >>
> >> Thanks for your patience :) replying my questions.
> >>
> >> On 12/4/26 06:25, Anirudh Srinivasan wrote:
> >>> Hi E,
> >>>
> >>> On Fri, Dec 4, 2026 at 5:10 AM E Shattow <e@freeshell.de> wrote:
> >>>>
> >>>> Hi Anirudh,
> >>>>
> >>>> On 12/3/26 08:56, Anirudh Srinivasan wrote:
> >>>>> When U-Boot is running in S mode, the DT passed to the next S mode stage
> >>>>> can either be the bundled in DT U-Boot and the previous M mode stage
> >>>>> use, or be loaded by U-Boot from some boot media. In the former case,
> >>>>> the M mode stage can fix up the DT to disable the M-IMSIC and M-APLIC
> >>>>> nodes on an AIA system (for example, OpenSBI does this fixup). These
> >>>>> controllers are to be managed by M-mode software, so this is done to
> >>>>> prevent S mode software from trying to probe them.
> >>>>>
> >>>>
> >>>> The way it reads now (in my point of view) is as:
> >>>>
> >>>> "M-IMSIC and M-APLIC controllers are to be managed by M-mode software,
> >>>> and so enforce any M-mode M-IMSIC and M-APLIC nodes are effectively
> >>>> status 'reserved' in S-mode U-Boot with a fixup to the received control
> >>>
> >>> This is what OpenSBI does.
> >>>
> >>>> Fdt from preceding M-Mode software (e.g. OpenSBI). Enforce again this
> >>>> same fixup when entering the next S-mode kernel to prevent S-mode
> >>>> software from trying to probe them.
> >>>
> >>> We're doing this again here cause we may possibly not use the DT
> >>> passed by OpenSBI and use a fresh DT from boot media.
> >>>
> >>> Regards
> >>> Anirudh srinivasan
> >>
> >> If we did not call out to an M-Mode SBI for the transition to S-Mode
> >> then we would be managing these with a fix-up at M-Mode U-Boot SPL when
> >> handing off to S-Mode U-Boot main app; I see the problem now, M-Mode
> >> U-Boot SPL loads U-Boot main multi-fit image which begins code execution
> >> with M-Mode SBI (e.g. OpenSBI or RustSBI, etc.) and we have no domain
> >> over the Fdt control state as S-Mode U-Boot main app is loaded and
> >> begins code execution because that is done by the 3rd party M-Mode SBI.
> >> We again incur this problem exiting from S-Mode U-Boot Main app because
> >> there are provisions for a user to again load data to the Fdt for
> >> hand-off to the next boot phase.
> >>
> >> I think it would be appropriate to log a warning (or even log "info"
> >> level) that this particular M-mode <=> S-Mode fix-up consistency
> >> enforcement is being done, as for example:
> >>
> >> "Enforce reserved M-mode Fdt property status for handoff to S-Mode kernel:
> >> * M-IMSIC okay => reserved
> >> * M-APLIC okay => reserved"
> >>
> >> or when the fix-up is activated but no nodes are changed then as:
> >>
> >> "Enforce reserved M-mode Fdt property status for handoff to S-Mode
> >> kernel: (n/a)"
> >
> > A message at warning or info level sounds too verbose. A message at
> > debug level would indeed help debugging when problems occur.
> >
> >> Also for consistency we should enforce this twice, at both S-Mode U-Boot
> >> main app initialization and at hand-off exiting S-Mode U-Boot main app.
> >
> > What do you mean by "enforce this twice"? Do you mean to fix up the FDT
> > both on entry of the U-Boot proper and on hand-off to the OS?
> >
> > If my understanding is correct, this doesn't make sense. U-Boot makes no
> > use of interrupts, thus imsic/aplic means nothing to it.
> >
>
> Also running the fix-up at the entry of S-mode U-Boot Main app serves as
> a user-facing warning when the Fdt is not consistent for the S-mode
> operation. That is a hint that the SBI did not do its job. We don't know
> all the possible things a user-defined SBI might do so just posture this
> as input validation on both the entry to S-mode U-Boot and the hand-off
> to exit from S-mode U-Boot. It's not relevant that U-Boot itself has no
> interaction with interrupts or what the particular node is, only that it
> is a fix-up that enforces M-mode <=> S-mode changeover.
We couldn't validate every possible defect in the devicetree in a
reasonable way, and I don't see anything different for the IMSIC/APLIC
from other devicetree nodes. It's not U-Boot's job to take care of other
components' issues.
> >> I would like an explicit opt-in / opt-out strategy for the M-mode <=>
> >> S-mode Fdt fix-up. A compile-time option is fine, here, and to make this
> >> implicit for all RISC-V makes sense to me unless disabled explicitly
> >> with "=n".... something so it appears in the .config but that it is a
> >> sensible default so we don't require an opt-in. Presumably this is only
> >> applicable to RISC-V platform?
> >
> > It makes sense to have a configurable option, but it should probably be
> > off by default. At the time of writing, we don't have a lot of RISC-V
> > SoCs implementing IMSIC/APLIC. AFAIK all in-tree RISC-V platforms except
> > SpacemiT K3 don't require this fixup, so disabling it by default would
> > avoid increase their binary size while keeping the code change minimal.
> >
>
> I consider this as belonging to a group of M-mode <=> S-mode domain
> specific Fdt properties that need to be input validated... not specific
> to the peripherals or SoC features implemented by those.
U-Boot is not even the consumer of this property, it's not U-Boot's job
to do the validation. You probably want to add a check to the OS side
instead.
> >> I think this also would apply to U-Boot SPL, in terms of consistency
> >> this fix-up should be instrumented so that you can require it to run
> >> when exiting the SPL (but this would of course be disabled when there is
> >> an SBI). This should not incur any code size overhead as a config option
> >> it would simply not be compiled-in. This gives it an explicit
> >> application at build time and be visible in the .config
> >
> > arch_fixup_fdt() is already invoked in SPL when transferring control to
> > Linux. We should probably also do so when transferring control to
> > OpenSBI, but this has nothing to do with this patch. Code included in
> > this patch only gets executed in S-mode, in which case OpenSBI couldn't
> > be invoked at all.
> >
>
> Okay fine with me to keep the scope narrower, but I see nothing here
> that restricts this to IMSIC/APLIC hardware features, or to "OpenSBI".
> This is logically just input and output validation.
See my previous replies, U-Boot isn't responsible for validating stuff
about which it doesn't care.
> >> With the above suggestions implemented, I think the commit message does
> >> not require to mention "OpenSBI" at all. It simply becomes a matter of
> >> informing the user and being a consistency enforcement SPL and Main app
> >> boot phases.
> >
> > No, introducing this fixup to both SPL and U-Boot proper has nothing to
> > do with the issue it solves. The original problem is that fixups
> > performed by M-mode firmware are lost when loading a fresh devicetree,
> > and it's good to describe the issue clearly in the commit message. I'm
> > fine with this commit message.
> >
>
> The issue IMO is not being addressed by this patch as it is; as-is this
> is merely a workaround for a specific circumstance that depends on what
> OpenSBI is or is not doing.
Replacing devicetrees in the middle of the boot chain is always a
dangerous operation, since you'll lose all changes that previous
firmware commits. It's impossible to have a generic solution to this,
because you couldn't infer the purpose of the changes without
overfitting a specific implementation.
However, supporting replacing devicetrees does matter, since it does a
good job for debugging/development purposes, etc.. Without a generic
solution, we could only play the whack-a-mole like this patch, which is
probably okay as long as we only cover the common cases, considering
that we already have fixups for reserved-memory, etc...
> Look at it from the view of M-mode <=>
> S-mode input validation and it's clear what to do, and the explanation
> doesn't have to be so "what-about-..." explaining what OpenSBI does,
> what U-Boot does, when and where. It is simply on every edge where
> U-Boot goes M-mode <=> S-Mode we validate and enforce Fdt properties
> that need to be adjusted for the new mode, no exceptions or inconsistencies.
Generalizing the problem too much doesn't help others to understand
what is happening, and this patch isn't going to validate properties.
For the reason I've mentioned before, it's not U-Boot's job to
validate things of which it doesn't make use.
> -E
--
Thanks,
Yao Zi
Meow-mrrp-mrow, I'm a cat.
prev parent reply other threads:[~2026-12-06 0:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:56 [PATCH v4] riscv: Mark M-IMSIC and M-APLIC nodes as reserved in DT passed to next stage in S mode Anirudh Srinivasan
2026-12-04 11:10 ` E Shattow
2026-12-04 14:25 ` Anirudh Srinivasan
2026-12-05 17:40 ` E Shattow
2026-12-05 21:54 ` Yao Zi
2026-12-05 22:34 ` E Shattow
2026-12-06 0:23 ` Yao Zi [this message]
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=axSq6EHJw6UV16N8@pie \
--to=me@ziyao.cc \
--cc=asrinivasan@oss.tenstorrent.com \
--cc=e@freeshell.de \
--cc=leo.liang@sifive.com \
--cc=tim609@andestech.com \
--cc=trini@konsulko.com \
--cc=troy.mitchell@linux.spacemit.com \
--cc=u-boot@lists.u-boot-project.org \
/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