Skip to content

feat(vex): serve arm64 RNDR and RNDRRS with --deterministic-rng - #56

Open
not-matthias wants to merge 1 commit into
masterfrom
cod-4061-deterministic-rng-support-arm64-rndrrndrrs
Open

not-matthias wants to merge 1 commit into
masterfrom
cod-4061-deterministic-rng-support-arm64-rndrrndrrs

Conversation

@not-matthias

Copy link
Copy Markdown
Member

Decode MRS Xt, RNDR and MRS Xt, RNDRRS (FEAT_RNG) on arm64. With --deterministic-rng=yes, both draw 64 bits from the calling thread's PRNG stream and always succeed (NZCV=0000), like RDRAND/RDSEED on amd64. Without the option, the host register is read and its NZCV is passed through.

Before this change, VEX did not decode these registers, so a program that executed RNDR without checking for FEAT_RNG got SIGILL. Programs that check fell back to getrandom, because Valgrind dropped AT_HWCAP2 and masked the RNDR field of ID_AA64ISAR0_EL1.

Changes:

  • Decode: active when the host has FEAT_RNG, or when a deterministic RNG is installed. In deterministic mode the host register is never read, so the test also runs on hosts without FEAT_RNG.
  • Advertising: FEAT_RNG is still reported only when the host has it. AT_HWCAP2 now passes through HWCAP2_RNG (all other bits are still cleared), and the emulated ID_AA64ISAR0_EL1 keeps the RNDR field. This keeps client code paths the same as a native run on the same host.
  • The --help line now says "hardware RNG insns" instead of "RDRAND/RDSEED"; cmdline1/cmdline2 expectations are updated.

Verified on a ubuntu-24.04-arm GitHub runner without FEAT_RNG: none/tests/arm64/deterministic_rng, cmdline1 and cmdline2 pass. The host-passthrough path (host with FEAT_RNG, no --deterministic-rng) has not been run on hardware.

Closes COD-4061

Decode MRS RNDR and RNDRRS (FEAT_RNG). With --deterministic-rng they
draw 64 bits from the calling thread's PRNG stream and always report
success (NZCV=0000), also on hosts without FEAT_RNG. Otherwise the
host register is read and its NZCV is passed through.

FEAT_RNG is advertised to the client only when the host has it:
AT_HWCAP2 now keeps HWCAP2_RNG instead of being dropped, and the
emulated ID_AA64ISAR0_EL1 keeps the RNDR field.

Refs COD-4061
@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 84 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing cod-4061-deterministic-rng-support-arm64-rndrrndrrs (97727ef) with master (81d7365)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@not-matthias
not-matthias marked this pull request as ready for review October 30, 2026 09:24
@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds ARM64 RNDR and RNDRRS support.

  • Arm64 RNDR and RNDRRS instructions return host or repeatable random values.
  • Arm64 clients see RNG support only when the host has it.

No actionable issues found. Review used code inspection; no tests were run. not-matthias acknowledged that the host-passthrough path has not been run on RNG-capable hardware.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["RNDR or RNDRRS"] --> B{"Host supports RNG or callback installed?"}
  B -->|No| C["Instruction not decoded"]
  B -->|Yes| D{"Callback installed?"}
  D -->|Yes| E["Draw two words from calling thread"]
  E --> F["Return 64-bit value and NZCV = 0"]
  D -->|No| G["Read host RNG register and NZCV"]
  F --> H["Write guest register and flags"]
  G --> H
Loading

Reviews (1) · Last reviewed commit: "feat(vex): serve arm64 RNDR and RNDRRS w..." · Reviewed by Greptile

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.

1 participant