[PATCH v3] lib: utils/mpxy: bind channel access to owning domain
Anup Patel
anup.patel at oss.qualcomm.com
Wed Jul 22 01:32:43 PDT 2026
On Wed, Jul 22, 2026 at 3:28 AM Pawandeep Oza
<pawandeep.oza at oss.qualcomm.com> wrote:
>
> From: Oza Pawandeep <pawandeep.oza at oss.qualcomm.com>
>
> The MPXY framework currently stores registered channels in a global
> list and exposes them to all callers. However, the intended model is
> that each channel is assigned to a single supervisor domain at boot and
> remains owned by that domain for its lifetime.
>
> Introduce fixed owner-domain tracking in struct sbi_mpxy_channel and
> make channel lookup and enumeration domain-aware. A channel is now
> visible only when accessed from its owning domain. Also require the
> owner to be set before channel registration.
>
> This allows MPXY to support systems where the same hart may be reused by
> multiple domains while keeping channel ownership and visibility fixed to
> the domain that owns the service.
>
> Signed-off-by: Oza Pawandeep <pawandeep.oza at oss.qualcomm.com>
> Reviewed-by: Rahul Pathak <rahul.pathak at oss.qualcomm.com>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
> ---
> include/sbi/sbi_mpxy.h | 5 +--
> lib/sbi/sbi_mpxy.c | 53 ++++++++++++++++++++++++-----
> lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 2 ++
> 3 files changed, 49 insertions(+), 11 deletions(-)
>
> diff --git a/include/sbi/sbi_mpxy.h b/include/sbi/sbi_mpxy.h
> index 9da2791e..e7b28527 100644
> --- a/include/sbi/sbi_mpxy.h
> +++ b/include/sbi/sbi_mpxy.h
> @@ -13,6 +13,7 @@
> #include <sbi/sbi_list.h>
>
> struct sbi_scratch;
> +struct sbi_domain;
>
> #define SBI_MPXY_MSGPROTO_VERSION(Major, Minor) ((Major << 16) | Minor)
>
> @@ -91,12 +92,13 @@ struct sbi_mpxy_channel_attrs {
> /* Events State Control */
> u32 eventsstate_ctrl;
> };
> -
> /** A Message proxy channel accessible through SBI interface */
> struct sbi_mpxy_channel {
> /** List head to a set of channels */
> struct sbi_dlist head;
> u32 channel_id;
> +
> + struct sbi_domain *owner_domain;
> struct sbi_mpxy_channel_attrs attrs;
>
> /**
> @@ -181,5 +183,4 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
> /** Get Message proxy notification events */
> int sbi_mpxy_get_notification_events(u32 channel_id,
> unsigned long *events_len);
> -
> #endif
> diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c
> index ff5c6ab6..1007f556 100644
> --- a/lib/sbi/sbi_mpxy.c
> +++ b/lib/sbi/sbi_mpxy.c
> @@ -145,14 +145,36 @@ static inline bool mpxy_is_std_attr(u32 attr_id)
> return (attr_id >> 31) ? false : true;
> }
>
> +static inline bool mpxy_channel_visible(struct sbi_mpxy_channel *channel,
> + struct sbi_domain *dom)
> +{
> + return channel->owner_domain == dom;
> +}
> +
> +/** Find channel_id in registered channels list for this domain */
> +static struct sbi_mpxy_channel *mpxy_find_channel(u32 channel_id,
> + struct sbi_domain *dom)
> +{
> + struct sbi_mpxy_channel *channel;
> +
> + sbi_list_for_each_entry(channel, &mpxy_channel_list, head) {
> + if (channel->channel_id == channel_id &&
> + mpxy_channel_visible(channel, dom))
> + return channel;
> + }
> +
> + return NULL;
> +}
> +
> /** Find channel_id in registered channels list */
> -static struct sbi_mpxy_channel *mpxy_find_channel(u32 channel_id)
> +struct sbi_mpxy_channel *sbi_mpxy_find_channel_any(u32 channel_id)
> {
> struct sbi_mpxy_channel *channel;
>
> - sbi_list_for_each_entry(channel, &mpxy_channel_list, head)
> + sbi_list_for_each_entry(channel, &mpxy_channel_list, head) {
> if (channel->channel_id == channel_id)
> return channel;
> + }
>
> return NULL;
> }
> @@ -222,9 +244,12 @@ static void mpxy_std_attrs_init(struct sbi_mpxy_channel *channel)
> int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel)
> {
> if (!channel)
> + return SBI_EINVAL;
> +
> + if (!channel->owner_domain)
> return SBI_EINVAL;
>
> - if (mpxy_find_channel(channel->channel_id))
> + if (sbi_mpxy_find_channel_any(channel->channel_id))
> return SBI_EALREADY;
>
> /* Initialize channel specific attributes */
> @@ -397,12 +422,15 @@ int sbi_mpxy_get_channel_ids(u32 start_index)
> struct sbi_mpxy_channel *channel;
> u32 channels_count = 0;
> u32 *shmem_base;
> + struct sbi_domain *dom = sbi_domain_thishart_ptr();
>
> if (!mpxy_shmem_enabled(ms))
> return SBI_ERR_NO_SHMEM;
>
> - sbi_list_for_each_entry(channel, &mpxy_channel_list, head)
> - channels_count += 1;
> + sbi_list_for_each_entry(channel, &mpxy_channel_list, head) {
> + if (mpxy_channel_visible(channel, dom))
> + channels_count += 1;
> + }
>
> if (start_index > channels_count)
> return SBI_ERR_INVALID_PARAM;
> @@ -420,6 +448,9 @@ int sbi_mpxy_get_channel_ids(u32 start_index)
>
> // Iterate over the list of channels to get the channel ids.
> sbi_list_for_each_entry(channel, &mpxy_channel_list, head) {
> + if (!mpxy_channel_visible(channel, sbi_domain_thishart_ptr()))
> + continue;
> +
> if (node_index >= start_index &&
> node_index < (start_index + returned)) {
> shmem_base[2 + node_ret] = cpu_to_le32(channel->channel_id);
> @@ -446,11 +477,12 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
> int ret = SBI_SUCCESS;
> u32 *attr_ptr, end_id;
> void *shmem_base;
> + struct sbi_domain *dom = sbi_domain_thishart_ptr();
>
> if (!mpxy_shmem_enabled(ms))
> return SBI_ERR_NO_SHMEM;
>
> - struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id);
> + struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id, dom);
> if (!channel)
> return SBI_ERR_NOT_SUPPORTED;
>
> @@ -597,11 +629,12 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
> struct sbi_mpxy_channel *channel;
> int ret, mem_idx;
> void *shmem_base;
> + struct sbi_domain *dom = sbi_domain_thishart_ptr();
>
> if (!mpxy_shmem_enabled(ms))
> return SBI_ERR_NO_SHMEM;
>
> - channel = mpxy_find_channel(channel_id);
> + channel = mpxy_find_channel(channel_id, dom);
> if (!channel)
> return SBI_ERR_NOT_SUPPORTED;
>
> @@ -686,12 +719,13 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
> struct sbi_mpxy_channel *channel;
> void *shmem_base, *resp_buf;
> u32 resp_bufsize;
> + struct sbi_domain *dom = sbi_domain_thishart_ptr();
> int ret;
>
> if (!mpxy_shmem_enabled(ms))
> return SBI_ERR_NO_SHMEM;
>
> - channel = mpxy_find_channel(channel_id);
> + channel = mpxy_find_channel(channel_id, dom);
> if (!channel)
> return SBI_ERR_NOT_SUPPORTED;
>
> @@ -743,12 +777,13 @@ int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len)
> struct mpxy_state *ms = sbi_domain_mpxy_state_thishart_ptr();
> struct sbi_mpxy_channel *channel;
> void *eventsbuf, *shmem_base;
> + struct sbi_domain *dom = sbi_domain_thishart_ptr();
> int ret;
>
> if (!mpxy_shmem_enabled(ms))
> return SBI_ERR_NO_SHMEM;
>
> - channel = mpxy_find_channel(channel_id);
> + channel = mpxy_find_channel(channel_id, dom);
> if (!channel || !channel->get_notification_events)
> return SBI_ERR_NOT_SUPPORTED;
>
> diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
> index 84b7a67d..825ac9b3 100644
> --- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
> +++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
> @@ -299,6 +299,8 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
> /* Setup MPXY mbox client */
> /* Channel ID*/
> rmb->channel.channel_id = channel_id;
> + /* Set the owner domain */
> + rmb->channel.owner_domain = &root;
> /* Callback for read RPMI attributes */
> rmb->channel.read_attributes = mpxy_mbox_read_attributes;
> /* Callback for write RPMI attributes */
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list