-
Notifications
You must be signed in to change notification settings - Fork 35
Dma fixes #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Dma fixes #329
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -556,9 +556,10 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
|
|
||||||||||||||||||||
| #ifdef WOLFHSM_CFG_DMA | ||||||||||||||||||||
| case WH_MESSAGE_CERT_ACTION_ADDTRUSTED_DMA: { | ||||||||||||||||||||
| whMessageCert_AddTrustedDmaRequest req = {0}; | ||||||||||||||||||||
| whMessageCert_SimpleResponse resp = {0}; | ||||||||||||||||||||
| void* cert_data = NULL; | ||||||||||||||||||||
| whMessageCert_AddTrustedDmaRequest req = {0}; | ||||||||||||||||||||
| whMessageCert_SimpleResponse resp = {0}; | ||||||||||||||||||||
| void* cert_data = NULL; | ||||||||||||||||||||
| int cert_dma_pre_ok = 0; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (req_size != sizeof(req)) { | ||||||||||||||||||||
| /* Request is malformed */ | ||||||||||||||||||||
|
|
@@ -574,6 +575,9 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, req.cert_len, | ||||||||||||||||||||
| WH_DMA_OPER_CLIENT_READ_PRE, (whServerDmaFlags){0}); | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| cert_dma_pre_ok = 1; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| /* Process the add trusted action */ | ||||||||||||||||||||
|
|
@@ -586,9 +590,10 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| (void)WH_SERVER_NVM_UNLOCK(server); | ||||||||||||||||||||
| } /* WH_SERVER_NVM_LOCK() */ | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| /* Post-process client address */ | ||||||||||||||||||||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| /* Always call POST for successful PRE, regardless of operation | ||||||||||||||||||||
| * result */ | ||||||||||||||||||||
| if (cert_dma_pre_ok) { | ||||||||||||||||||||
| (void)wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, req.cert_len, | ||||||||||||||||||||
| WH_DMA_OPER_CLIENT_READ_POST, (whServerDmaFlags){0}); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -600,11 +605,12 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| }; break; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| case WH_MESSAGE_CERT_ACTION_READTRUSTED_DMA: { | ||||||||||||||||||||
| whMessageCert_ReadTrustedDmaRequest req = {0}; | ||||||||||||||||||||
| whMessageCert_SimpleResponse resp = {0}; | ||||||||||||||||||||
| void* cert_data = NULL; | ||||||||||||||||||||
| whMessageCert_ReadTrustedDmaRequest req = {0}; | ||||||||||||||||||||
| whMessageCert_SimpleResponse resp = {0}; | ||||||||||||||||||||
| void* cert_data = NULL; | ||||||||||||||||||||
| uint32_t cert_len; | ||||||||||||||||||||
| whNvmMetadata meta; | ||||||||||||||||||||
| int cert_dma_pre_ok = 0; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (req_size != sizeof(req)) { | ||||||||||||||||||||
| /* Request is malformed */ | ||||||||||||||||||||
|
|
@@ -620,6 +626,9 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, req.cert_len, | ||||||||||||||||||||
| WH_DMA_OPER_CLIENT_WRITE_PRE, (whServerDmaFlags){0}); | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| cert_dma_pre_ok = 1; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| /* Check metadata to see if the certificate is non-exportable */ | ||||||||||||||||||||
|
|
@@ -641,10 +650,11 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| (void)WH_SERVER_NVM_UNLOCK(server); | ||||||||||||||||||||
| } /* WH_SERVER_NVM_LOCK() */ | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| /* Post-process client address */ | ||||||||||||||||||||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, cert_len, | ||||||||||||||||||||
| /* Always call POST for successful PRE, regardless of operation | ||||||||||||||||||||
| * result */ | ||||||||||||||||||||
| if (cert_dma_pre_ok) { | ||||||||||||||||||||
| (void)wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, req.cert_len, | ||||||||||||||||||||
| WH_DMA_OPER_CLIENT_WRITE_POST, (whServerDmaFlags){0}); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+653
to
659
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -655,10 +665,11 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| }; break; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| case WH_MESSAGE_CERT_ACTION_VERIFY_DMA: { | ||||||||||||||||||||
| whMessageCert_VerifyDmaRequest req = {0}; | ||||||||||||||||||||
| whMessageCert_VerifyDmaResponse resp = {0}; | ||||||||||||||||||||
| void* cert_data = NULL; | ||||||||||||||||||||
| whKeyId keyId = WH_KEYID_ERASED; | ||||||||||||||||||||
| whMessageCert_VerifyDmaRequest req = {0}; | ||||||||||||||||||||
| whMessageCert_VerifyDmaResponse resp = {0}; | ||||||||||||||||||||
| void* cert_data = NULL; | ||||||||||||||||||||
| whKeyId keyId = WH_KEYID_ERASED; | ||||||||||||||||||||
| int cert_dma_pre_ok = 0; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (req_size != sizeof(req)) { | ||||||||||||||||||||
| /* Request is malformed */ | ||||||||||||||||||||
|
|
@@ -677,6 +688,9 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, req.cert_len, | ||||||||||||||||||||
| WH_DMA_OPER_CLIENT_READ_PRE, (whServerDmaFlags){0}); | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| cert_dma_pre_ok = 1; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| resp.rc = WH_SERVER_NVM_LOCK(server); | ||||||||||||||||||||
|
|
@@ -693,9 +707,10 @@ int wh_Server_HandleCertRequest(whServerContext* server, uint16_t magic, | |||||||||||||||||||
| (void)WH_SERVER_NVM_UNLOCK(server); | ||||||||||||||||||||
| } /* WH_SERVER_NVM_LOCK() */ | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (resp.rc == WH_ERROR_OK) { | ||||||||||||||||||||
| /* Post-process client address */ | ||||||||||||||||||||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| /* Always call POST for successful PRE, regardless of operation | ||||||||||||||||||||
| * result */ | ||||||||||||||||||||
| if (cert_dma_pre_ok) { | ||||||||||||||||||||
| (void)wh_Server_DmaProcessClientAddress( | ||||||||||||||||||||
| server, req.cert_addr, &cert_data, req.cert_len, | ||||||||||||||||||||
| WH_DMA_OPER_CLIENT_READ_POST, (whServerDmaFlags){0}); | ||||||||||||||||||||
|
Comment on lines
+713
to
715
|
||||||||||||||||||||
| (void)wh_Server_DmaProcessClientAddress( | |
| server, req.cert_addr, &cert_data, req.cert_len, | |
| WH_DMA_OPER_CLIENT_READ_POST, (whServerDmaFlags){0}); | |
| int post_rc = wh_Server_DmaProcessClientAddress( | |
| server, req.cert_addr, &cert_data, req.cert_len, | |
| WH_DMA_OPER_CLIENT_READ_POST, (whServerDmaFlags){0}); | |
| if ((resp.rc == WH_ERROR_OK) && (post_rc != WH_ERROR_OK)) { | |
| resp.rc = post_rc; | |
| } |
Copilot
AI
Apr 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DMA READ_POST return code is discarded. If the verify action succeeds but POST fails, this path will still report success (resp.rc remains WH_ERROR_OK), potentially masking DMA/cache maintenance failures. Consider capturing the POST rc and surfacing it when rc/resp.rc is still WH_ERROR_OK (or logging it).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -349,6 +349,8 @@ int wh_Server_HandleNvmRequest(whServerContext* server, | |
| whMessageNvm_SimpleResponse resp = {0}; | ||
| void* metadata = NULL; | ||
| void* data = NULL; | ||
| int metadata_dma_pre_ok = 0; | ||
| int data_dma_pre_ok = 0; | ||
|
|
||
| if (req_size != sizeof(req)) { | ||
| /* Request is malformed */ | ||
|
|
@@ -363,11 +365,17 @@ int wh_Server_HandleNvmRequest(whServerContext* server, | |
| resp.rc = wh_Server_DmaProcessClientAddress( | ||
| server, req.metadata_hostaddr, &metadata, sizeof(whNvmMetadata), | ||
| WH_DMA_OPER_CLIENT_READ_PRE, (whServerDmaFlags){0}); | ||
| if (resp.rc == 0) { | ||
| metadata_dma_pre_ok = 1; | ||
| } | ||
| } | ||
| if (resp.rc == 0) { | ||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||
| server, req.data_hostaddr, &data, req.data_len, | ||
| WH_DMA_OPER_CLIENT_READ_PRE, (whServerDmaFlags){0}); | ||
| if (resp.rc == 0) { | ||
| data_dma_pre_ok = 1; | ||
| } | ||
| } | ||
| if (resp.rc == 0) { | ||
| rc = WH_SERVER_NVM_LOCK(server); | ||
|
|
@@ -381,14 +389,15 @@ int wh_Server_HandleNvmRequest(whServerContext* server, | |
| } /* WH_SERVER_NVM_LOCK() */ | ||
| resp.rc = rc; | ||
| } | ||
| if (resp.rc == 0) { | ||
| /* perform platform-specific host address processing */ | ||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||
| /* Always call POST for successful PREs, regardless of operation | ||
| * result */ | ||
| if (metadata_dma_pre_ok) { | ||
| (void)wh_Server_DmaProcessClientAddress( | ||
| server, req.metadata_hostaddr, &metadata, sizeof(whNvmMetadata), | ||
| WH_DMA_OPER_CLIENT_READ_POST, (whServerDmaFlags){0}); | ||
| } | ||
| if (resp.rc == 0) { | ||
| resp.rc = wh_Server_DmaProcessClientAddress( | ||
| if (data_dma_pre_ok) { | ||
| (void)wh_Server_DmaProcessClientAddress( | ||
| server, req.data_hostaddr, &data, req.data_len, | ||
| WH_DMA_OPER_CLIENT_READ_POST, (whServerDmaFlags){0}); | ||
| } | ||
|
Comment on lines
+392
to
403
|
||
|
|
@@ -405,6 +414,7 @@ int wh_Server_HandleNvmRequest(whServerContext* server, | |
| whNvmMetadata meta = {0}; | ||
| whNvmSize read_len = 0; | ||
| void* data = NULL; | ||
| int data_dma_pre_ok = 0; | ||
|
|
||
| if (req_size != sizeof(req)) { | ||
| /* Request is malformed */ | ||
|
|
@@ -441,15 +451,19 @@ int wh_Server_HandleNvmRequest(whServerContext* server, | |
| rc = wh_Server_DmaProcessClientAddress( | ||
| server, req.data_hostaddr, &data, req.data_len, | ||
| WH_DMA_OPER_CLIENT_WRITE_PRE, (whServerDmaFlags){0}); | ||
| if (rc == 0) { | ||
| data_dma_pre_ok = 1; | ||
| } | ||
| } | ||
| if (rc == 0) { | ||
| /* Process the Read action */ | ||
| rc = wh_Nvm_ReadChecked(server->nvm, req.id, req.offset, | ||
| read_len, (uint8_t*)data); | ||
| } | ||
| if (rc == 0) { | ||
| /* perform platform-specific host address processing */ | ||
| rc = wh_Server_DmaProcessClientAddress( | ||
| /* Always call POST for successful PRE, regardless of read | ||
| * result */ | ||
| if (data_dma_pre_ok) { | ||
| (void)wh_Server_DmaProcessClientAddress( | ||
| server, req.data_hostaddr, &data, req.data_len, | ||
| WH_DMA_OPER_CLIENT_WRITE_POST, (whServerDmaFlags){0}); | ||
| } | ||
|
Comment on lines
+463
to
469
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DMA READ_POST return code is discarded via a void cast. If the POST callback fails after the certificate is added successfully, this handler will still return WH_ERROR_OK, potentially leaving DMA/cache state inconsistent. Consider propagating POST errors when resp.rc is still WH_ERROR_OK (or logging POST failures).