I am currently working with the HSE APIs on the S32G3 platform and had a query regarding the use of the hse_mem_allocfunction.
From my understanding, this function is used to allocate memory space for operations, but I am concerned about its impact on memory consumption if it is called repeatedly. Could you please clarify:
Thank you in advance for your guidance!
Hello @ashwini2024,
Can you help me indicating where did you find that function? I have searched in the HSE M7 demo app, ARM trusted firmware, u-boot and Linux code bases and I was not able to find it.
Thanks in advance for the information.
Hello @alejandro_e ,
The link https://github.com/nxp-auto-linux/pkcs11-hse/blob/release/bsp40.0/examples/hse-encrypt/hse-encrypt.c... for the code .
Hello @ashwini2024,
Thanks for letting me know. About your question, to the best of my understanding, there is no way to workaround the memory allocation, this means you will need to follow the same flow as the one shown in the examples, therefore you will need to use hse_mem_alloc.
Doing a surface level analysis, the logic implemented to handle memory allocation and free is similar to a liked list. However the exact details are out of my expertise.
This function does not handle memory deallocation automatically. You will need to implement your own logic to free the memory using the function hse_mem_free. You can check the provided examples for a reference on how to use it, for instance examples/hse-encrypt/hse-encrypt.c#L172.
I can also recommend checking section 10.3 of the BSP40 user manual, starting at page 78:
Let me know if this information answers your question.
I wanted to understand if the HSE memory can get exhausted when handling multiple cryptographic operations concurrently. Are there any specific limitations or guidelines for memory usage when performing multiple HSE operations simultaneously?
Hello @ashwini2024,
In general, like any other memory allocation it will have a limit, and if you check the funciton definition libhse/hse-mem.c#L119 you will see there are some conditions that will cause the function to return NULL, which in general means that the memory is all used, as you can see in the examples, if the function returns NULL, the functions return error ENOMEM (Error no memory) for instance in this line hse-encrypt/hse-encrypt.c#L98. You can implement a similar mechanism to control when to stop allocating new memory.
However, by reviewing the code I am not able to conclude what is the exact limit. I will raise this question with the internal team and let you know their feedback.
Best regards
Hello @ashwini2024,
I have received the following information from the internal team:
"
The function hse_mem_alloc() allocates memory from the memory space called “HSE reserved memory range”, which is defined in device tree <linux/arch/arm64/boot/dts/freescale/s32cc.dtsi> . Customer can modify the memory range according to user's requirement.
The HSE driver creates the "HSE reserved memory range” based on the device tree, The source of hse driver is <linux/drivers/uio/uio_hse.c>
For example, according to the below picture, the start address of HSE reserved memory range is 0x8400 0000 and the size is 0x100 000. So the maximum size can be allocated from hse_mem_alloc() is 16MB.
"
Let me know if this information fully answers your questions.