This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issue with mutex_init_platform

So I am doing a number of crypto operations. One of which for example is an ECDSA signing operation. I do that through mbedtls_ecdsa_write_signature which is using the CC310 layer to actually do the operations. That function calls ecdsa_sign_det_restartable, which calls mbedtls_hmac_drbg_init which eventually calls mutex_init_platform. 

mutex_init_platform has this line  

ret = k_mem_slab_alloc(&mutex_slab, &mutex->mutex, K_FOREVER);

Well during testing, when trying to run my function 100 times, I get stuck after 60 times (it works 60 times), It gets stuck here waiting forever. 

I am going to look into it some more and see if I can figure out why, but I wanted to check with you all first. I don't think I am doing anything wrong in my code. I am freeing all the mbedtls variables I init. I think I am passing good parameters. 

Parents
  • So I noticed that the free_list of the slab was filling up. It fills up from the back to the front. And then once its full, the code is waiting forever for a block to be freed. But I see that k_mem_slab_free is being called for every time the alloc is being called. But I watched the free function work, and it does not change the value of the slab free_list.  After k_mem_slab_free, the value of free_list is the same as before, and that location still points to the next block up the buffer. So even though we did free, nothing was really freed. And there are 60 blocks in this slab, which is why I see my test fail after 60 iterations.

Reply
  • So I noticed that the free_list of the slab was filling up. It fills up from the back to the front. And then once its full, the code is waiting forever for a block to be freed. But I see that k_mem_slab_free is being called for every time the alloc is being called. But I watched the free function work, and it does not change the value of the slab free_list.  After k_mem_slab_free, the value of free_list is the same as before, and that location still points to the next block up the buffer. So even though we did free, nothing was really freed. And there are 60 blocks in this slab, which is why I see my test fail after 60 iterations.

Children
No Data
Related