Repository navigation
Conversation
|
The human adds: this is a rather involved change, and I don't have the personal expertise to vouch for it being any kind of elegant or optimal solution. We found it because one of my experiments involves loading arbitrary Xtensa code at runtime, so that select extended functionality can be added as desired, without requiring a full firmware flash. So far the fixes in this PR appear to be working, [edit: in the sense that they behave the same on hardware now] but I've not made any attempt to look for any refinements. |
|
Thanks for tracking this down. Loading code at runtime is a case Flexe should handle on its own, so rather than add an observer API I fixed it in the core in 9372d98. Guest stores that change RAM holding translated code now invalidate it directly, through any alias (including the S3 DRAM view of IRAM), whether or not an I'm closing this in favour of that commit. If your runtime-loading experiment still misbehaves on master, please open an issue with a reproducer and I'll take a look. |
|
Thanks, Lev, for fixing this in the core; our development build already uses your fix. — Written by Codex on behalf of Brandon. |
Prepared by Codex on behalf of Brandon
This PR resolves stale code executing after an embedding host replaces an
already translated RAM function and the guest executes
ISYNC, when the hostsupplies the attached invalidation policy. In the linked
reproducer, the replacement should return 43, but cached execution still returns
42. The correction supplies an optional ISYNC observer through which the host
can invalidate changed executable RAM.
The interpreter currently treats
ISYNCas a no-op, the predecoder classifiesit as
PD_NOP, and the JIT can compile across it. An embedding host thereforecannot apply its translation-coherence policy at that architectural boundary.
Explicit
xtensa_invalidate_codeworks, but the guest barrier does not exposea place to call it. This is separate from host ARM64 instruction-cache flushing.
Add an optional CPU observer and context, call it for
ISYNCin the canonicaland quick interpreter paths, prevent cached no-op handling and terminate JIT
blocks before the barrier. Preserve the observer across session CPU reset.
Other synchronization instructions retain their current semantics.
The synthetic regression contains both the guest
instruction bytes and a small host invalidation policy. It warms a function
returning 42, replaces it with one returning 43, executes an actual guest
ISYNC, then executes the same address again. It covers byte, halfword, word,backing-copy and interpreted/JIT guest stores, including a translated store
prefix directly before ISYNC, plus first load into predecoded RAM. Explicit
invalidation and null-observer/barrier controls accompany it. No firmware,
ROM image, application or game assets are needed.
The same regression compiles against both APIs. Observer registration and its
callback-count checks are conditional on the new feature macro; expected guest
values are identical.
The embedding host must supply the invalidation policy: installing no observer
does not automatically make all RAM writes coherent. This does not promise
coherence for arbitrary self-modifying code without
ISYNC, cross-core policy,or hardware cache timing. Embedders must rebuild for the changed CPU structure.
Validated against master
e2b79fc7a8987b2821f74065e47e70e3e261e45eon Linux ARM64, GCC 14.2, Release with LTO/native tuning disabled:
assertions, including all seven replacements returning 42 instead of 43.
145 passing assertions, 0 failures (15 extra observer-count checks are now available).
assertions, 0 failures. These are unit checks, not hardware/application acceptance.
Build the normal
xtensa-teststarget, then run:Reproduction instructions explain applying the regression
first, observing assertion failures, then applying the source patch and rerunning.