Skip to content

wolfHSM: add DMA_NONCOHERENT macro and support - #547

Open
rizlik wants to merge 4 commits into
wolfSSL:mainfrom
rizlik:dma_noncoherent
Open

rizlik wants to merge 4 commits into
wolfSSL:mainfrom
rizlik:dma_noncoherent

Conversation

@rizlik

@rizlik rizlik commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Adds WOLFHSM_CFG_DMA_NONCOHERENT for targets without hardware cache coherency.

  • Introduces configurable DMA buffer alignment, padding, and allocation helpers; updates internal buffers and POSIX shared-memory handling.
  • Fixes cache flush/invalidate range handling and isolates LMS/XMSS public-key DMA writes.
  • Disables wolfCrypt DMA dispatch in this mode because buffer alignment cannot be guaranteed; direct wh_Client_*Dma APIs remain available.
  • Adds alignment/padding checks, regression tests, CI coverage, benchmark updates, and configuration documentation.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Cache-coherency and stateful-key changes need hardware validation, and stress-test payload-length regressions remain unresolved.

1 open issue
What changed in this PR

Adds non-coherent DMA support to wolfHSM while preserving direct DMA APIs and refusing unsafe wolfCrypt DMA dispatch.

Changes:

  • Adds aligned, padded buffers and allocation helpers; corrects cache-range handling.
  • Updates client dispatch, stateful-key transfers, and POSIX shared-memory handling.
  • Adds regression tests, CI coverage, benchmark adjustments, and documentation.
File Description
wolfhsm/​wh_utils.h Declares DMA allocation helpers.
wolfhsm/​wh_settings.h Defines alignment configuration and macros.
wolfhsm/​wh_client.h Documents DMA dispatch restrictions.
wolfhsm/​wh_client_cryptocb.h Documents non-coherent callback behavior.
test/​wh_test_posix_threadsafe_stress.c Pads per-client DMA buffers.
test/​wh_test_nvmflags.c Aligns NVM outputs and preserves payload lengths.
test/​wh_test_multiclient.c Aligns multi-client DMA outputs.
test/​wh_test_dma.c Aligns bounce storage and checks outputs.
test/​wh_test_crypto.c Adapts DMA tests and adds refusal checks.
test/​wh_test_common.h Restricts DMA dispatch test modes.
test/​wh_test_clientserver.c Aligns client/server test buffers.
test/​wh_test_cert.c Aligns certificate export buffers.
test/​Makefile Adds non-coherent DMA build options.
test-refactor/​wh_test_list.c Registers new regression tests.
test-refactor/​README.md Documents stateful-signature test restrictions.
test-refactor/​posix/​wh_test_posix_shm_dma.c Tests in-place shared-memory DMA buffers.
test-refactor/​posix/​wh_test_posix_main.c Runs shared-memory DMA regression tests.
test-refactor/​posix/​Makefile Adds non-coherent DMA build options.
test-refactor/​misc/​wh_test_multiclient.c Aligns multi-client DMA outputs.
test-refactor/​misc/​wh_test_dma_noncoherent.c Tests allocation and dispatch refusals.
test-refactor/​misc/​wh_test_crypto_affinity.c Aligns DMA cipher outputs.
test-refactor/​misc/​wh_test_cache.c Tests cache-line range coverage.
test-refactor/​config/​wolfhsm_cfg.h Enables cache-operation recording.
test-refactor/​client-server/​wh_test_nvm_ops.c Aligns NVM read storage.
test-refactor/​client-server/​wh_test_crypto_xmss.c Skips unsupported wolfCrypt DMA tests.
test-refactor/​client-server/​wh_test_crypto_rng.c Aligns outputs while preserving request lengths.
test-refactor/​client-server/​wh_test_crypto_mldsa.c Aligns signature and export buffers.
test-refactor/​client-server/​wh_test_crypto_lms.c Skips unsupported wolfCrypt DMA tests.
test-refactor/​client-server/​wh_test_crypto_keystore.c Aligns exported-key buffers.
test-refactor/​client-server/​wh_test_crypto_ed25519.c Aligns signature storage.
test-refactor/​client-server/​wh_test_crypto_ecc.c Aligns public-key export storage.
test-refactor/​client-server/​wh_test_crypto_aes.c Adapts buffers and DMA test guards.
src/​wh_utils.c Corrects cache ranges and adds DMA allocation.
src/​wh_client.c Rejects non-coherent DMA-preferred dispatch.
src/​wh_client_dma.c Adds test-only alignment and padding checks.
src/​wh_client_cryptocb.c Refuses non-coherent wolfCrypt DMA operations.
src/​wh_client_crypto.c Isolates and aligns DMA key outputs.
port/​posix/​posix_transport_shm.c Aligns bounce allocations and validates in-place outputs.
docs/​src/​9-Configuration.md Documents new configuration options.
docs/​src/​6-Utilities.md Documents the benchmark build option.
docs/​src/​5-Features.md Explains non-coherent DMA requirements.
benchmark/​wh_bench_utils.h Defines supported DMA benchmark guards.
benchmark/​wh_bench_data.h Enforces DMA buffer alignment constraints.
benchmark/​wh_bench_data.c Aligns built-in DMA storage.
benchmark/​Makefile Adds the non-coherent DMA option.
benchmark/​bench_modules/​wh_bench_mod_xmss.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_sha3.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_sha2.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_mlkem.c Aligns ciphertext buffers.
benchmark/​bench_modules/​wh_bench_mod_mldsa.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_lms.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_hmac.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_cmac.c Guards unsupported DMA benchmarks.
benchmark/​bench_modules/​wh_bench_mod_aes.c Updates guards and DMA allocations.
.github/​workflows/​build-and-test.yml Adds non-coherent DMA sanitizer coverage.
.github/​workflows/​build-and-test-refactor.yml Adds refactored-suite sanitizer coverage.
.github/​workflows/​build-and-bench.yml Adds non-coherent DMA benchmark coverage.

Review effort: Balanced

Comment thread test/wh_test_posix_threadsafe_stress.c
@padelsbach

Copy link
Copy Markdown
Contributor

@rizlik , if possible can you ensure that the updates to test/ and test-refactor/ add roughly the same coverage?

@bigbrett

Copy link
Copy Markdown
Contributor

@rizlik thanks for this, going to chew on it soon. Did a quick skim already.

In the meantime, agree with @padelsbach about test-refactor. Ideally we are going to switch frameworks over in next release, so want to ensure coverage is in that suite.

@rizlik

rizlik commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@rizlik , if possible can you ensure that the updates to test/ and test-refactor/ add roughly the same coverage?

Added lms, xmss under NO_COHERENT and the refusal that were only in test. The DMA alignment check in the bounce callback is already covered in the test-refactor using ASAN.

@bigbrett bigbrett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, I agree that there insn't much we can do about this problem when it comes to using DMA through the wolfCrypt API and the best option is just to prohibit it.

A few changes (including renaming the feature flag) otherwise it makes sense to me. I want to test this on some hardware ports once buttoned up too.

Comment thread src/wh_client.c
Comment thread wolfhsm/wh_utils.h Outdated
Comment thread wolfhsm/wh_settings.h Outdated
@bigbrett bigbrett assigned rizlik and unassigned bigbrett and billphipps Oct 23, 2026
@rizlik
rizlik requested a review from bigbrett October 26, 2026 17:14
@rizlik rizlik assigned bigbrett and unassigned rizlik Oct 26, 2026
@bigbrett

Copy link
Copy Markdown
Contributor

@JacobBarthelmeh @billphipps this touches some of the POSIX SHM stuff which I know you are using so could use one of your eyes before merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants