From fe0d2f2b195d1eb741cc497dbc81ed375e66de15 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Thu, 16 Jan 2025 10:20:19 +0100 Subject: [PATCH] core: pta: stats: get RPMB secure storage allocation stats Retrieve RPMB secure storage space allocation statistics from PTA stats STATS_CMD_ALLOC_STATS command. STATS_NB_POOLS is intentionally not incremented since it is expected to give the number of pools which IDs start from 1 (ALLOC_ID_HEAP), not from 0 (ALLOC_ID_ALL) that is a magic ID. Ensure the stats are all 0 for when RPMB_FS is not supported or we failed to get the stats info. For this, let's zero initialize the shared buffer so that these default stats also apply on other stats that may not be reachable (deprecate public DDR pool, Nexus heap). Signed-off-by: Etienne Carriere Acked-by: Jens Wiklander --- core/pta/stats.c | 11 +++++++++++ lib/libutee/include/pta_stats.h | 1 + 2 files changed, 12 insertions(+) diff --git a/core/pta/stats.c b/core/pta/stats.c index 93a3c1056da..383c0f9886a 100644 --- a/core/pta/stats.c +++ b/core/pta/stats.c @@ -15,6 +15,7 @@ #include #include #include +#include #include static TEE_Result get_alloc_stats(uint32_t type, TEE_Param p[TEE_NUM_PARAMS]) @@ -52,6 +53,7 @@ static TEE_Result get_alloc_stats(uint32_t type, TEE_Param p[TEE_NUM_PARAMS]) } p[1].memref.size = size_to_retrieve; stats = p[1].memref.buffer; + memset(stats, 0, size_to_retrieve); for (i = ALLOC_ID_HEAP; i <= STATS_NB_POOLS; i++) { if (pool_id != ALLOC_ID_ALL && i != pool_id) @@ -83,6 +85,15 @@ static TEE_Result get_alloc_stats(uint32_t type, TEE_Param p[TEE_NUM_PARAMS]) nex_malloc_reset_stats(); break; #endif + case ALLOC_ID_RPMB: + if (rpmb_mem_stats(stats, p[0].value.b)) + strlcpy(stats->desc, + "RPMB secure storage (no data)", + sizeof(stats->desc)); + else + strlcpy(stats->desc, "RPMB secure storage", + sizeof(stats->desc)); + break; default: EMSG("Wrong pool id"); break; diff --git a/lib/libutee/include/pta_stats.h b/lib/libutee/include/pta_stats.h index f95d3acb8c6..d2c378ab963 100644 --- a/lib/libutee/include/pta_stats.h +++ b/lib/libutee/include/pta_stats.h @@ -38,6 +38,7 @@ #define ALLOC_ID_PUBLIC_DDR 2 /* Public DDR allocator (deprecated) */ #define ALLOC_ID_TA_RAM 3 /* TA_RAM allocator */ #define ALLOC_ID_NEXUS_HEAP 4 /* Nexus heap allocator */ +#define ALLOC_ID_RPMB 5 /* RPMB secure storage */ #define STATS_NB_POOLS 5 #define TEE_ALLOCATOR_DESC_LENGTH 32