Fix: accept interior copy_to/copy_from ranges within a live allocation - #1557
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough
ChangesChild-memory provenance guards
Estimated code review effort: 4 (Complex) | ~35 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant Orchestrator
participant ChildProvenance
participant DeviceMemory
Caller->>Orchestrator: copy_to or copy_from with pointer and size
Orchestrator->>ChildProvenance: Validate contained live range
ChildProvenance-->>Orchestrator: Validation result
Orchestrator->>DeviceMemory: Execute validated copy
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/gemini review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
The child-pointer provenance guard keyed every allocation by its exact (worker_id, base) and admitted a copy only when the address hit that base. A partial update of a persistent device buffer — copy_to(base + offset) into one page of a resident cache — was rejected as though the interior address were unknown, because the guard stored no allocation extent to range-check against. Record each allocation's byte extent in provenance and validate copies by containment instead of exact base: base <= ptr && ptr + nbytes <= base + extent Changes: - _ChildProvEntry carries malloc_size and maps each CommDomain allocation id to the extent of the window / buffer recorded at that base; live_extent() returns the widest live role. - copy_to / copy_from (Worker L2 path and Orchestrator L3 path) call the new _child_prov_require_live_range, which admits any range wholly contained in one live allocation on the worker. A copy to the exact base resolves in O(1); only an interior address falls back to scanning the worker's live allocations. Python ints are unbounded, so the ptr + nbytes bound is exact. - A CommDomain carves its first buffer at offset 0, so that buffer aliases the window base under the same allocation id. Record the max of the prior and new extent per allocation id so the smaller buffer never narrows the window's copy range. - free() and kind4 dispatch are unchanged — they still require the exact base, since they act on the whole allocation, not an interior slice. - Document the interior-range behavior in the Python API reference. Regression coverage in tests/ut/py/test_worker/test_child_addr_guard.py, at both the L3 orchestrator and L2 worker entry points: interior range accepted, out-of-range / negative-size / wrong-worker / stale rejected, free still requires the exact base, and a domain-window chunk is not narrowed by its aliasing buffer. Fixes hw-native-sys#1537.
8f33cbb to
3e48520
Compare
Problem
Issue #1537: the child-pointer provenance guard keyed every allocation by its exact
(worker_id, base)and admitted a copy only when the address hit that base. A partial update of a persistent device buffer —copy_to(base + offset)into one page of a resident cache (e.g. the DeepSeek V4 decode KV cache) — was rejected as though the interior address were unknown, because the guard stored no allocation extent to range-check against.Fix
Record each allocation's byte extent in provenance and validate copies by containment instead of exact base:
_ChildProvEntrynow carriesmalloc_sizeand maps each CommDomain allocation id to the extent of the window / buffer recorded at that base;live_extent()returns the widest live role.copy_to/copy_from(Worker L2 path and Orchestrator L3 path) call the new_child_prov_require_live_range, which scans the worker's live allocations and admits any range wholly contained in one. Python ints are unbounded, so theptr + nbytesbound is exact (no wraparound).free()and kind4 dispatch are unchanged — they still require the exact base, since they act on the whole allocation, not an interior slice.Behavior
copy_to(base + 32, ..., 16)within amalloc(64)copy_to(base + 63, ..., 2)(overruns)free(base)free(base + 32)Tests
Device-free, mocked-orchestrator regression coverage in
tests/ut/py/test_worker/test_child_addr_guard.pyfor all five cases in the issue, at both the L3 orchestrator and L2 worker entry points.tests/ut/py/test_worker/— 349 passed, 2 skipped (pre-existing).close #1537