From ef4ed2dda76648171d551537443a16b5db712284 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Thu, 20 Feb 2025 10:42:27 -0800 Subject: lib: sbi_scratch: Apply bounds check to platform hart_count The internal limit on the number of harts is SBI_HARTMASK_MAX_BITS, as this value determines the size of various bitmaps and arrays (including hartindex_to_hartid_table and hartindex_to_scratch_table). Clamp the value provided by the platform, and drop the extra array element. Update the documentation to indicate that hart_index2id must be sized based on hart_count, and that hart indexes must be contiguous. As of commit 5e90e54a1a53 ("lib: utils:Check that hartid is valid"), there is no restriction on the valid hart ID values. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- include/sbi/sbi_platform.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 6d5fbc7d..5e50c997 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -169,7 +169,7 @@ struct sbi_platform { char name[64]; /** Supported features */ u64 features; - /** Total number of HARTs */ + /** Total number of HARTs (at most SBI_HARTMASK_MAX_BITS) */ u32 hart_count; /** Per-HART stack size for exception/interrupt handling */ u32 hart_stack_size; @@ -184,17 +184,12 @@ struct sbi_platform { /** * HART index to HART id table * - * For used HART index : + * If hart_index2id != NULL then the table must contain a mapping + * for each HART index 0 <= < hart_count: * hart_index2id[] = some HART id - * For unused HART index : - * hart_index2id[] = -1U * * If hart_index2id == NULL then we assume identity mapping * hart_index2id[] = - * - * We have only two restrictions: - * 1. HART index < sbi_platform hart_count - * 2. HART id < SBI_HARTMASK_MAX_BITS */ const u32 *hart_index2id; }; -- cgit v1.3.1