Skip to content

[Store] Wire hardened HMAC-authenticated TCP SSD owner-push runtime into RealClient and Python - #5790

Draft
MaskVulcan wants to merge 30 commits into
kvcache-ai:mainfrom
MaskVulcan:ssd/pr4-owner-push-runtime
Draft

MaskVulcan wants to merge 30 commits into
kvcache-ai:mainfrom
MaskVulcan:ssd/pr4-owner-push-runtime

Conversation

@MaskVulcan

@MaskVulcan MaskVulcan commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part 4 of 5 in the SSD Offload streaming & owner-push series tracked in RFC #5768.

Stacked Draft PR: Depends on #5789 (PR 3: owner-push engine). Because cross-fork PRs target main, GitHub's Files changed view currently includes PR 1–3 commits; review only this PR's incremental changes here: Incremental diff (29ec5ac7d...1ae815a9c).

Summary

Completes the opt-in CPU/TCP SSD Owner-Push feature end-to-end across control RPC, peer discovery, RealClient/DummyClient/Python _store, and documentation:

  1. Hardened HMAC-SHA256 Control RPC & Crash-Safe Peer Directory (ssd_control_rpc.*, ssd_peer_directory.*):
    • Authenticates both requests and terminal replies (dma_drained) with bidirectional per-message HMAC-SHA256 using constant-time CRYPTO_memcmp; raw 128-bit credentials are never transmitted on the wire.
    • Offloads control execution and recovery onto dedicated worker pools off the coro_rpc I/O loop, binds only to the configured private control_host (rejecting wildcard 0.0.0.0/::), enforces 60s idle timeouts, and skips launching any control listener on requester-only nodes (control_port == 0).
    • SsdPeerDirectory uses flock-protected records, strict JSON isObject() checks, bounded capacity (kMaxPeers = 256), and std::shared_mutex, so crashed peer leftovers (fork()+_exit()) never poison discovery.
  2. SsdDirectRuntime & Client/Python Integration (ssd_direct_runtime.*, real_client.*, dummy_client.*, pyclient.h, store_py.cpp, rpc_client_io_context.h, docs/source/design/store/ssd-push.md):
    • Opt-in via MOONCAKE_OFFLOAD_SSD_PUSH=true (classic TCP only; default false leaves existing pull paths unchanged).
    • Exposes get_ssd_push_peer_info(), configure_ssd_push_peers(...) (with self-deduplication), recover_ssd_push(), and timeout_ms on batch_get_into / batch_get_into_multi_buffers (enforced across memory, local-disk, and DISK/DFS tiers).
    • Retryable teardown & GIL safety: tearDownAll_internal() checks pending registrations and ssd_direct_->Close() before shutting down prefetcher/servers while keeping RpcDrainGuard open on OBJECT_HAS_LEASE; Python close() retains self.store_ on OBJECT_HAS_LEASE and always releases RealClient outside the GIL.
    • Memory & registration safety: checks HasPending() across all read/write/upsert paths (get_into*, batch_get_into*, put_from*, batch_put_from*, upsert_from*, batch_upsert_from*), guards inner multi-buffer range sizes against mismatch, serializes per-address register_buffer/unregister_buffer with RAII guards, and cleans up SsdDirectRuntime::Impl safely on constructor unwind.

Series Overview (RFC #5768)

| PR 4 | #5790 (this PR) | Hardened HMAC-SHA256 control RPC, peer directory, RealClient & Python _store | Depends on #5789 |
| PR 5 | #5791 | V6 object write generations, SSD task fencing & HA durable retirement | Independent (main) |

Local Validation

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add portable POSIX pread bounded streaming read pipeline (ReadSource,
ReadPipeline, ThreadedPipelineDriver, BoundedExecutor with WaitSubmit
backpressure) and wire FileStorage::ReadLocalStreaming into RealClient
whole and ranged local CPU restore paths under MOONCAKE_OFFLOAD_LOCAL_STREAMING_READ.

Includes ranged read fallback safety for unregistered CPU user buffers,
shared-mutex close drain, O_NONBLOCK clearing after regular-file validation,
aligned direct short-read continuation, unit/integration tests, and design docs.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add optional io_uring streaming read executor and pipeline driver
(UringReadExecutor, UringPipelineDriver) with fixed-buffer support,
EBUSY/EINTR/EAGAIN retry handling, short-read continuation, liburing 2.1
user_data compatibility, atomic WaitForEvent ready/active check, ARM64
SYS_ppoll fallback in fault fixture, and CTest/ASan/UBSan coverage.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Address review findings for submitAcknowledgedTcpWrite:
- Enforce v2 framing and WRITE opcode before the zero-length fast path in
  TcpTransport::startTransfer, log rejected requests, and document local
  no-op semantics for zero-length acknowledged writes.
- Validate classic TCP availability before selectTransports, pre-check
  v2 framing (MC_TCP_PROTO / peer tcp_proto_version) before mutating the
  batch so mixed v2/v1 batches cannot partially dispatch, and require an
  explicit require_ack argument on startTransferSequence.
- Include tcp_proto_version in TransferMetadata::SegmentDesc::operator==
  so protocol-only metadata updates are installed by syncSegmentCache.
- Dispatch unpooled one-shot ClientSession::initiate() onto
  socket->get_executor() in TcpTransport::startTransferWithSocket to avoid
  cross-thread progress timer races, and track one-shot sessions in
  ConnectionLaneState so shutdownConnectionLanes() cancels and fails
  in-flight unpooled work cleanly.
- Encapsulate TcpTransport acknowledged-write helpers behind friend class
  MultiTransport.
- Expand unit tests for zero-length legacy writes, legacy peer metadata,
  mixed batches, ungrouped and grouped mid-sequence metadata downgrades,
  grouped writes, unpooled connections, and unpooled shutdown while
  awaiting a receiver ACK.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Address adversarial review findings across local streaming restore and io_uring:
- Guard both can_use_pinned_restore_arena and local streaming under
  offload_rpc_drain_ in RealClient::execute_ranged_read, avoid holding
  offload_rpc_drain_ across outbound remote peer RPCs, null-guard
  file_storage_/client_ in offload RPC handlers, and skip redundant local
  streaming retries after fallback.
- Propagate sys_errno from PosixReadSource and io_uring read completions to
  NotifyDiskError/OnDiskError, respect disk_fenced_, validate backend type
  via dynamic_cast, reject overlapping destinations before source
  acquisition or max_chunks checks, merge multi-object batches into a
  single multi-source ReadPlan/driver with graceful slot degradation and
  expired-lease reaping on slot miss, check Start/Drain returns
  defensively, and map plan limits to NO_AVAILABLE_HANDLE for clean
  fallback.
- Probe IORING_OP_READ/IORING_OP_READ_FIXED via io_uring_get_probe_ring so
  pre-5.6 kernels cleanly fall back to POSIX pread, expose
  UringReadExecutor::healthy(), make UringReadExecutor::Impl::Fail()
  idempotent, flush retries inline in both UringReadExecutor and
  UringPipelineDriver, keep shutdown drain retrying short reads/EINTR,
  retry io_uring_unregister_buffers on EINTR, validate O_DIRECT alignment
  on local-ring reads, clamp Wait() deadlines against signed overflow in
  both drivers, return kInvalidArgument for null sources, cap read lengths
  at INT_MAX with saturating object-end arithmetic, and gate
  UringPipelineDriver::Create cleanly.
- Fix uint64_t/size_t deduction on 32-bit/macOS in file_storage_config.cpp,
  keep the deterministic fault test liburing fixture independent of distro
  <linux/io_uring.h> versions, and link
  ssd_uring_read_executor_contract_test standalone for BUILD_SHARED_LIBS=ON.
- Harden io_uring and config/storage tests with opcode/RLIMIT_MEMLOCK/
  O_DIRECT probes, safe RAII teardown ordering, WaitAccepted
  synchronization, default config assertions, and regression coverage for
  unhealthy/unsupported-opcode executors, disk fencing, plan limits,
  overlap precedence, multi-object uring/degraded-slot batches, and lease GC.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Replace the process-global coro_io::io_context_pool used by offload
restore RPC reads with a RealClient-owned asio::thread_pool that is
initialized lazily on first use and stopped and joined during teardown
after in-flight offload RPCs drain.

Lazily initialize FileStorage::streaming_reads_ only when the portable
pread driver is needed so io_uring-backed local streaming restores do
not spawn idle fallback read workers, and align the SSD offload design
doc with per-batch fixed-buffer rings and fallback semantics.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Clarify submitAcknowledgedTcpWrite as a fail-closed v2 downgrade guard
on top of TCP v2's existing receiver-ACK write semantics, tighten
internal boundaries, and streamline tests:
- Replace friend class MultiTransport with public validation/submit
  helpers on TcpTransport and hide OneShotSession in
  tcp_transport_lane_impl.h.
- Query getSegmentDescByID instead of getCachedSegmentDescByID during
  acknowledged-write preflight to eliminate a stale-cache race window.
- Rate-limit dispatch-time rejection logs, drop the redundant opcode
  check, and assert transport identity in MultiTransport.
- Consolidate tests into five focused cases covering pooled, grouped,
  and unpooled acknowledged writes, legacy/downgrade rejections,
  unpooled shutdown via submitTransfer, and SegmentDesc equality.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Trim unused zero-caller abstractions and heavy test fixtures from the
local streaming restore path while fixing four correctness/usability
issues:
- Remove unused O_DIRECT, fixed_buffers per-batch io_uring engine,
  RebindSource, Cancel/attempt_id/region_id fields, and TrySubmit
  overloads; compile ssd_uring_pipeline.cpp only on Linux with liburing.
- Account for OffsetAllocator 3-bit-mantissa bin rounding in
  StreamingReadConfig::Validate() via OffsetAllocatorSlotBudget() with a
  lockstep test against OffsetAllocator::normalizedAllocationSize().
- Deduplicate bucket file descriptors and BucketReadGuards per bucket in
  BucketStorageBackend::AcquireReadSources() so large multi-key batches
  sharing a few buckets do not hit the open-source limit.
- Return NOT_SUPPORTED on overlapping destinations so RealClient falls
  back to the legacy sequential restore path instead of failing.
- Extract pure ClassifyUringReadResult() with table-driven unit tests,
  probe io_uring_enter via NOP during worker init, log warnings on
  io_uring init/runtime failure and pread fallback, and remove the fake
  liburing.h / libc-interposition fault test targets.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan
MaskVulcan force-pushed the ssd/pr4-owner-push-runtime branch from 01027be to 5e44143 Compare November 25, 2026 17:42
…nd harden unpooled shutdown

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
… contracts

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
@MaskVulcan
MaskVulcan force-pushed the ssd/pr4-owner-push-runtime branch from 5e44143 to 49e7525 Compare November 25, 2026 21:14
…e and split out TCP bugfixes

Address review feedback on kvcache-ai#5773:
- Split out unpooled TCP initiation/shutdown tracking and SegmentDesc::operator== tcp_proto_version comparison into standalone independent bugfix PRs, restoring TcpTransport::supportsParallelBatchSubmit() == true.
- Rename submitAcknowledgedTcpWrite to guarantee-oriented submitReceiverVisibleWrite and move route validation/submission onto Transport virtual hooks (validateReceiverVisibleWrites / submitReceiverVisibleWriteTasks) so each transport decides whether it can satisfy receiver-visible write completion without MultiTransport special-casing TCP.
- Share the completion-latch arming, seal/unseal, and pinned tail release lifecycle between submitTransfer and submitReceiverVisibleWrite via MultiTransport::submitTransferImpl.
- Add Status::Code::kProtocolUnsupported (Status::ProtocolUnsupported / IsProtocolUnsupported) so legacy peer / MC_TCP_PROTO=1 rejections are machine-distinguishable from TENT NotImplemented and unsupported-transport NotSupportedTransport.
- Simplify TcpTransport::validateReceiverVisibleWrites to a plain std::unordered_set<SegmentID> when metacache is enabled and document the deliberate per-stage descriptor refreshes when metacache is disabled.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add owner-push control primitives (DestinationRegistry, SsdReadProtocol,
SsdOwnerRequestLedger with bounded retired-ID intervals and completion-time
eviction, SsdControlWire codec, SsdDirectReadOwner, SsdFixedL2Requester with
bounded ReadWithRecovery, and portable secureRandomBytes).

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add classic host TCP v2 SourceDrainedWriteTarget adapter built on
TransferEngine::submitAcknowledgedTcpWrite without TransferRequest ABI,
submitScatter, RDMA/TENT, or global drain changes.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add the authenticated Fixed-L2 control RPC transport (SsdReadIntoRpcEndpoint
and MakeSsdRequesterControlCall) and crash-safe SsdPeerDirectory, removing
all dead V1 4-RPC machinery (SsdControlRpcEndpoint / CallSsdControlRpc).

Fixes review security and lifecycle issues:
- Per-frame bidirectional HMAC-SHA256 authentication (OpenSSL Crypto,
  constant-time CRYPTO_memcmp) bound to requester identity and request tag;
  raw WriteCredential secrets never cross the wire in plaintext.
- Dispatches both kReadInto and kRecoverReadInto off the coro_rpc I/O loop
  onto separate bounded executors so blocked reads cannot starve recovery
  and directory lookups never stall I/O threads.
- Rejects wildcard 0.0.0.0/:: addresses and oversized headers before buffer
  allocation; connection pool uses LIFO and skips stale/closed sockets.
- SsdPeerDirectory checks JSON object types before field indexing, validates
  max_batch_objects symmetrically, and holds an exclusive flock on a sidecar
  lock file so crash-leftover records from SIGKILL/OOM never permanently
  poison LookupLegacy with kDuplicate.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Add FileStorage::ReadOwnerStreaming and MakeFileStorageOwnerReader
connecting FileStorage's bounded staging pipeline (POSIX and io_uring) to
SsdDirectReadOwner::Reader.

- Holds streaming_mutex_ shared lock so FileStorage::Shutdown drains active
  owner reads before releasing staging memory.
- Guards BuildColdReadFlightKey optional before dereference.
- Falls back cleanly to ThreadedPipelineDriver when io_uring is unavailable.
- Adds FileStorage owner streaming unit tests and an end-to-end TCP v2
  owner-push restore test across two TransferEngines.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
…Python

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
…aming tests

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
…tion races, and Python bindings

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
EL8 wheel-builder containers ship liburing 1.0.7, which provides
io_uring_get_probe_ring() and io_uring_opcode_supported() but predates
io_uring_free_probe() (introduced in liburing 2.0). Fall back to
std::free(probe) when IO_URING_VERSION_MAJOR < 2 (or undefined),
matching uring_file.cpp's version guard.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Assert requester peer info shape to remove unused local req_peer (F841),
apply Ruff formatting, and tighten subprocess/context-manager lint checks
in test_ssd_fixed_l2_direct.py.

Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>
Signed-off-by: MaskVulcan <9528071+MaskVulcan@users.noreply.github.com>

This branch has not been deployed

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

Labels

Common documentation Improvements or additions to documentation Integration run-ci size/L 1001+ changed lines (additions + deletions) Store Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant