-
Notifications
You must be signed in to change notification settings - Fork 0
Server thread safe #14
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?
Conversation
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.
Pull request overview
This pull request implements thread-safe access to shared server resources in wolfHSM, specifically targeting the NVM (non-volatile memory) and global key cache subsystems. The implementation introduces a platform-agnostic lock abstraction layer with a POSIX pthread_mutex implementation, along with comprehensive stress testing infrastructure.
Changes:
- Introduces lock abstraction layer (
wh_lock.h/c) with callback-based design for platform independence - Adds POSIX lock implementation using
pthread_mutex - Implements thread-safe wrappers for all NVM and keystore operations with proper lock acquisition/release
- Adds "unlocked" variants of functions for atomic multi-step operations
- Includes comprehensive stress tests with 18+ contention phases and TSAN (Thread Sanitizer) integration
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| wolfhsm/wh_settings.h | Documents WOLFHSM_CFG_THREADSAFE configuration option |
| wolfhsm/wh_nvm.h | Adds lock member to NVM context and declares unlocked function variants |
| wolfhsm/wh_lock.h | Defines platform-agnostic lock abstraction API |
| src/wh_lock.c | Implements lock abstraction with callback-based design |
| src/wh_nvm.c | Adds locking to all NVM operations and implements unlocked variants |
| src/wh_server_keystore.c | Adds locking to all keystore operations with atomic multi-step support |
| port/posix/posix_lock.h | Defines POSIX-specific lock structures and callbacks |
| port/posix/posix_lock.c | Implements pthread_mutex-based locking |
| test/wh_test_lock.h | Header for lock unit tests |
| test/wh_test_lock.c | Basic lock functionality tests |
| test/wh_test_threadsafe_stress.h | Header for stress tests |
| test/wh_test_threadsafe_stress.c | Comprehensive multi-threaded stress tests |
| test/wh_test_crypto.c | Initializes NVM config to avoid uninitialized memory |
| test/wh_test.c | Integrates lock and stress tests into test suite |
| test/tsan.supp | Thread Sanitizer suppressions for known false positives |
| test/Makefile | Adds TSAN support and stress test mode |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ety, serializing access to shared global resources like NVM and global keycache
4acd6dd to
2cfc0e4
Compare
TL;DR: Makes wolfHSM server thread safe!
This pull request implements a generic framework for thread-safe access to shared server resources in wolfHSM, specifically targeting the NVM (non-volatile memory) and global key cache subsystems.
Note that an instance of a server context itself cannot be shared across threads without serialization by the caller. This PR just ensures that if multiple server contexts share an NVM or global keystore, that accesses to shared resources are properly serialized such that requests from multiple clients can be processed concurrently in their own threads.
Changes:
wh_lock.{c,h}) with callback-based design for platform independenceWOLFHSM_CFG_THREADSAFEbuild option. When this option is NOT defined, all lock abstraction operations compile to no-ops, with zero overheadGaps/future work: