Re: [PATCH 1/3] lib: sbi_domain: Check possible harts in sbi_domain_context_enter/exit()
Pawandeep Oza <[email protected]>
| Newsgroups | org.infradead.lists.opensbi |
|---|---|
| Message-ID | <CAAVgOkJG4nyd-PgwQxBvVL0Dj7R+unXC+NXe_uTjeqT=kd91Xg@mail.gmail.com> |
On Thu, Aug 6, 2026 at 9:50 PM Anup Patel <[email protected]> wrote: > > When context switching to a domain the current hart MUST be part > of the possible harts of that domain. Add appropriate checks in > sbi_domain_context_enter/exit() along these lines. > > Signed-off-by: Anup Patel <[email protected]> > --- > lib/sbi/sbi_domain_context.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c > index 0861d541..837ff54f 100644 > --- a/lib/sbi/sbi_domain_context.c > +++ b/lib/sbi/sbi_domain_context.c > @@ -231,18 +231,23 @@ int sbi_domain_context_enter(struct sbi_domain *dom) > int rc; > struct hart_context *dom_ctx; > struct hart_context *ctx = hart_context_thishart_get(); > + u32 hartindex = current_hartindex(); > > /* Target domain must not be same as the current domain */ > if (!dom || dom == sbi_domain_thishart_ptr()) > return SBI_EINVAL; > > + /* Target domain must have current hart as a possible harts */ > + if (!sbi_hartmask_test_hartindex(hartindex, dom->possible_harts)) > + return SBI_EINVAL; > + > /* > * If it's first time to call `enter` on the current hart, no > * context allocated before. Allocate context for each valid > * domain on the current hart. > */ > if (!ctx) { > - rc = hart_context_init(current_hartindex()); > + rc = hart_context_init(hartindex); > if (rc) > return rc; > > @@ -251,7 +256,7 @@ int sbi_domain_context_enter(struct sbi_domain *dom) > return SBI_EINVAL; > } > > - dom_ctx = hart_context_get(dom, current_hartindex()); > + dom_ctx = hart_context_get(dom, hartindex); > /* Validate the domain context existence */ > if (!dom_ctx) > return SBI_EINVAL; > @@ -276,7 +281,7 @@ int sbi_domain_context_exit(void) > * its context on the current hart if valid. > */ > if (!ctx) { > - rc = hart_context_init(current_hartindex()); > + rc = hart_context_init(hartindex); > if (rc) > return rc; > > @@ -294,6 +299,9 @@ int sbi_domain_context_exit(void) > if (dom == &root || dom == sbi_domain_thishart_ptr()) > continue; > > + if (!sbi_hartmask_test_hartindex(hartindex, dom->possible_harts)) > + continue; > + > tmp = hart_context_get(dom, hartindex); > if (tmp && !tmp->initialized) { > dom_ctx = tmp; > -- > 2.43.0 if (!dom_ctx || tmp->dom->init_order < dom_ctx->dom->init_order) { dom_ctx = tmp; break; } Oza: remove this break as it picks up wrong order since it doenst get a chance to iterate through the list fully. Reviewed-by: Pawandeep Oza <[email protected]> Tested-by: Pawandeep Oza <[email protected]> > > > -- > opensbi mailing list > [email protected] > http://lists.infradead.org/mailman/listinfo/opensbi -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi