fix(riscv): mask mcounteren to 32 bits and gate counter reads - #314
Closed
carlosqwqqwq wants to merge 3 commits into
Closed
fix(riscv): mask mcounteren to 32 bits and gate counter reads#314carlosqwqqwq wants to merge 3 commits into
carlosqwqqwq wants to merge 3 commits into
Conversation
Member
|
Thank you for the report and implementation proposal. I independently reproduced and validated the accepted behavior, then reimplemented it with direct and SMIR/JIT coverage in #296 at commit 9027ae1. No contributor patch was imported; the consolidation commit records @carlosqwqqwq as co-author. I am closing this implementation PR because it is now consolidated into #296. Please review the rollup there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mcounterenis a 32-bit register and counter reads in S/U-mode must be gated on it: with CY clear, a non-M read ofcyclemust raise an illegal-instruction exception. RAX storedmcounterenwithout a width mask and never gatedcycle/time/instretreads, so disabled counters silently succeeded.This change masks
mcounterenwrites to 32 bits and gates non-M counter reads on the corresponding enable bits.Validation
mcounteren_is_32bit_and_gates_counter_reads: bit 33 is not stored, U-mode reads of disabled counters trap, enabled reads succeed, and M-mode reads are unaffected.cargo test --libtargeted test passes; full suite shows no regressions.Closes #309