[RFC PATCH v5 0/4] Add Smsdid and Smmpt supervisor domain protection
Huamao Wu
huamao.wu at linux.spacemit.com
Sun Oct 25 23:58:47 PDT 2026
Hi Rahul,
Thanks, agreed on making the SDID shortage diagnosable and on moving SDID
into the DT node. Comments inline.
On Sun, Oct 25, 2026 at 10:36 AM Rahul Pathak <rahul.pathak at oss.qualcomm.com> wrote:
> Hi,
>
> Thanks for the feedback, I have comments inline
>
> On Mon, Oct 19, 2026 at 11:19 AM Huamao Wu <huamao.wu at linux.spacemit.com> wrote:
> >
> > Hi Rahul,
> >
> > One design point on the SDID assignment.
> >
> > mpt_state_setup() currently allocates one SDID per SBI domain, at domain
> > registration time, taking the first free bit:
> >
> > for (sdid = 0; sdid < ctrl->max_domains; sdid++)
> > if (bitmap_test(ctrl->sdid_bitmap, sdid))
> > break;
> > if (sdid >= ctrl->max_domains)
> > return SBI_ENOSPC;
> >
> > SDIDLEN is implementation defined and may be as small as 1, i.e. two SDIDs in
> > total. OpenSBI domains are also used for purposes unrelated to MPT (per-hart
> > PMP partitioning, per-domain MPXY channels, IPI grouping), so a platform can
> > easily have more domains than SDIDs while only one or two of them actually
> > need a separate MPT. On such hardware the current binding turns a
> > configuration choice into a boot failure: SBI_ENOSPC propagates from
> > mpt_state_setup() to sbi_domain_finalize() and sbi_init() ends up calling
> > sbi_hart_hang(). Note that sbi_mpt_init() already treats missing Smmpt
> > hardware as non-fatal (returns SBI_ENODEV and sbi_hart_init() ignores it), so
> > "not enough SDIDs" is handled more strictly than "no Smmpt at all".
>
> A sensible hardware designed with SMMPT will need to make sure that
> there are sufficient SDIDLEN to support the use cases for which that
> hardware is meant for. It is exactly like having a system with 0 PMP entries
> though its allowed but the RISC-V ISA.
>
> The current design keeps 1:1 mapping between the SBI domain and the MPT domain.
> Which means each SBI domain will have a MPT domain along with a SDID assigned.
> From a memory-isolation standpoint, a SBI domain is the software construct that
> SMMPT enforces in hardware.
The tree is a function of the memregions alone. mpt_state_finalize() builds
it from the domain's memregions plus "index == 0" for the firmware deny, and
never reads the assigned HARTs, so two domains declared with one memory view
map the same ranges at the same XWR. They remain two SBI domains by every
other measure - separate next-addr, next-arg1, PMP entries, MPXY channels -
and one MPT describes both of them exactly. Sharing the SDID between them is
not a weaker isolation model; it is the same enforcement with one tree.
>
> This keeps the design and isolation model simple and avoids all sorts
> of problems
> which you have highlighted.
>
> The current error handling is the result of design assumptions plus
> what spec states-
>
> - If the SMMPT + SMSDID both are not present then the system can
> function without it
> and SBI domain backed by PMP/ePMP will work.
>
> - If the SMMPT + SMSDID are present then any error in the
> initialization which also
> includes not having sufficient SDIDs should result in a fatal error. Otherwise
> SBI domain backed by (PMP/ePMP + MPT) will be the enforcer.
>
> The cost of sharing SDID is huge which involves a system wide mfence resulting
> in performance issues. If two domains share an SDID but have different
> MPT tables
> then the SDID tagged MPT/TLB caching forces a mfence of that SDID on every
> domain switch between them which discards the optimization the SDID tag exists
> for and making the switch slower.
If two domains do share an SDID, neither condition of that paragraph is met
when their memory view is identical: the tree never differs, so a switch
rewrites mmpt with the same encoding and there is no new MPT to make
visible. The fence is paid either way - sbi_mpt_hart_activate() writes mmpt
and fences the SDID on every domain switch - so sharing adds no fence that
1:1 does not already have. Two SDIDs on one tree would not help either: it
saves the table but not the SDID, which is the scarce resource, and the code
cannot express it - mpt_state_finalize() allocates a root unconditionally
per domain, and sbi_mpt_share_region() copies region entries into the second
tree rather than pointing the second SDID at the first.
>
> I will change the current handling of caase where SDIDs are not sufficient
> and make it diagnosable instead of making is fatal silently rather than
> make SDID assignment opt-in. I will also make SDID part of the DT nodes
> for SBI domains.
Then the binding has to say what an absent sdid means, since that decides
whether "more domains than SDIDs" is describable at all:
a) derived from the domain index, so 1:1 holds for every DT and a
too-small SDIDLEN stays an intended fatal error;
b) the domain owns no MPT and relies on PMP/ePMP.
Under (a) the property only picks a number and that platform stays
undescribable; under (b) it becomes describable, while a DT that sets sdid
for every domain behaves exactly as today. Either way please document the
property as optional. And where two domains may share an sdid, require their
memregion sets to be equal, EINVAL otherwise - sanitize_domain() has already
sorted each set and dropped covered regions, so it is a count and array
compare. There is no sdid property today, so the check has to arrive with the
property, not after it.
>
> >
> > Proposal: make the SDID assignment opt-in per domain instead of implicit for
> > every domain.
> >
> > - Add an optional u32 property "sdid" to the opensbi,domain,instance node.
> > When absent, the domain runs under SDID 0, i.e. under the root domain's
> > MPT, and relies on PMP for its own isolation.
> > - The MPT of SDID N is built from the memregions of the domain that owns N.
> > SDID 0 is always owned by the root domain and its tree is built once.
> > Domains aliasing to an already-owned SDID do not get a tree of their own.
> > - An explicit "sdid" must be < 2^SDIDLEN and unique across domains.
> > - A domain aliasing to SDID N must still program mmpt explicitly on
> > activation. Right now sbi_mpt_hart_activate_for_domain() returns 0 when
> > !sd->valid and sbi_mpt_hart_deactivate() is empty, so a hart switched away
> > from an MPT-backed domain keeps the previous SDID in mmpt and would run
> > under the previous domain's MPT. Today every domain has a valid tree so
> > this is not reachable, but with opt-in assignment it becomes the normal
> > path.
> > - When SDIDLEN is smaller than the number of explicitly requested SDIDs,
> > report it and continue with the domains that fit rather than hanging.
> >
> > This keeps the common case (PMP-only platform, Smmpt capable hart) working
> > without any MPT memory, and lets a platform with SDIDLEN=1 run root plus one
> > protected domain.
> >
> > The assumption behind defaulting to SDID 0 is that PMP/ePMP remains the
> > primary memory protection for domains without their own SDID; Smmpt is
> > layered on top (sbi_hart_protection_configure() applies the TYPE_MEMORY
> > protection and the TYPE_ID protections independently, so the effective
> > permission of such a domain is its PMP entry set intersected with the SDID 0
> > MPT). If the intent is for Smmpt to replace PMP on some platforms, then
> > sharing SDID 0 is not safe and this proposal does not apply.
> >
> > Regards,
> > Huamao Wu
Regards,
Huamao Wu
More information about the opensbi
mailing list