[PATCH 1/7] lib: sbi: dbtr: check the flags parameter of SETUP_SHMEM

Himanshu Chauhan himanshu.chauhan at oss.qualcomm.com
Sun Nov 22 23:44:15 PST 2026


On Sat, Nov 21, 2026 at 12:11:13AM +0100, Heinrich Schuchardt wrote:
> The SBI specification defines sbi_debug_set_shmem() with three
> arguments: shmem_phys_lo, shmem_phys_hi and flags. The flags parameter
> is reserved for future use and must be zero. If it is not zero the call
> must fail with SBI_ERR_INVALID_PARAM.
> 
> The ecall handler passed only a0 and a1 to sbi_dbtr_setup_shmem(), so
> the value in a2 was ignored. Pass a2 as a new flags argument and return
> SBI_ERR_INVALID_PARAM if it is non-zero. The check is done first, so a
> call with reserved flags does not change the state of the hart.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
>  include/sbi/sbi_dbtr.h   | 3 ++-
>  lib/sbi/sbi_dbtr.c       | 7 ++++++-
>  lib/sbi/sbi_ecall_dbtr.c | 2 +-
>  3 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/include/sbi/sbi_dbtr.h b/include/sbi/sbi_dbtr.h
> index 90871f0d..86af03f2 100644
> --- a/include/sbi/sbi_dbtr.h
> +++ b/include/sbi/sbi_dbtr.h
> @@ -114,7 +114,8 @@ int sbi_dbtr_init(struct sbi_scratch *scratch, bool coldboot);
>  int sbi_dbtr_supported(void);
>  int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
>  			 unsigned long shmem_phys_lo,
> -			 unsigned long shmem_phys_hi);
> +			 unsigned long shmem_phys_hi,
> +			 unsigned long flags);
>  int sbi_dbtr_num_trig(unsigned long trig_tdata1, unsigned long *out);
>  int sbi_dbtr_read_trig(unsigned long smode,
>  		       unsigned long trig_idx_base, unsigned long trig_count);
> diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
> index c97e625f..2108ca9e 100644
> --- a/lib/sbi/sbi_dbtr.c
> +++ b/lib/sbi/sbi_dbtr.c
> @@ -337,10 +337,15 @@ int sbi_dbtr_get_total_triggers(void)
>  
>  int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
>  			 unsigned long shmem_phys_lo,
> -			 unsigned long shmem_phys_hi)
> +			 unsigned long shmem_phys_hi,
> +			 unsigned long flags)
>  {
>  	struct sbi_dbtr_hart_triggers_state *hart_state;
>  
> +	/* The flags parameter is reserved for future use and must be zero */
> +	if (flags)
> +		return SBI_ERR_INVALID_PARAM;
> +
>  	if (dom && !sbi_domain_is_assigned_hart(dom, current_hartindex())) {
>  		sbi_dprintf("%s: calling hart not assigned to this domain\n",
>  			   __func__);
> diff --git a/lib/sbi/sbi_ecall_dbtr.c b/lib/sbi/sbi_ecall_dbtr.c
> index 40a437ee..704af5a4 100644
> --- a/lib/sbi/sbi_ecall_dbtr.c
> +++ b/lib/sbi/sbi_ecall_dbtr.c
> @@ -28,7 +28,7 @@ static int sbi_ecall_dbtr_handler(unsigned long extid, unsigned long funcid,
>  		break;
>  	case SBI_EXT_DBTR_SETUP_SHMEM:
>  		ret = sbi_dbtr_setup_shmem(sbi_domain_thishart_ptr(), smode,
> -					   regs->a0, regs->a1);
> +					   regs->a0, regs->a1, regs->a2);
>  		break;
>  	case SBI_EXT_DBTR_TRIGGER_READ:
>  		ret = sbi_dbtr_read_trig(smode, regs->a0, regs->a1);

LGTM as said in preivous patch.

Reviewed-by: Himanshu Chauhan <himanshu.chauhan at oss.qualcomm.com>

> -- 
> 2.53.0
> 
> 
> -- 
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list