Skip to content

Commit

Permalink
core: pta: stats: get RPMB secure storage allocation stats
Browse files Browse the repository at this point in the history
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 <etienne.carriere@foss.st.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
etienne-lms committed Jan 20, 2025
1 parent c0a732c commit fe0d2f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/pta/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string.h>
#include <string_ext.h>
#include <tee_api_types.h>
#include <tee/tee_fs.h>
#include <trace.h>

static TEE_Result get_alloc_stats(uint32_t type, TEE_Param p[TEE_NUM_PARAMS])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/libutee/include/pta_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe0d2f2

Please sign in to comment.