[rv_core_ibex] Add u-mode performance counters and mcounteren#30135
Conversation
3baeac4 to
a204ac4
Compare
rswarbrick
left a comment
There was a problem hiding this comment.
Should the "Add missing rvfi ports" commit be squashed with the vendoring update? Otherwise, I think we have a (slightly) broken intermediate state of the repository?
Yes good point. I will squash the two once we merge the Ibex PR and I vendor in Ibex from the main branch. |
|
I pulled in the Ibex changes from upstream, squashed the commits and extended the commit messages a bit. So this is ready to go from my side. |
marnovandermaas
left a comment
There was a problem hiding this comment.
Just one minor improvement to the test but otherwise looks good to me.
fe0d5f5 to
8b41d27
Compare
|
CHANGE AUTHORIZED: hw/top_earlgrey/ip_autogen/rv_core_ibex/data/rv_core_ibex.hjson |
andreaskurth
left a comment
There was a problem hiding this comment.
LGTM with only two small suggestions. Thanks @SamuelRiedel!
| ibex_pkg::ibex_mubi_t mcounteren_writable_ibex; | ||
| assign mcounteren_writable_mubi4 = prim_mubi_pkg::mubi4_t'(reg2hw.mcounteren_writable.q); | ||
| // Convert the mubi4 to ibex_mubi. They are both four bit, but with different encodings. | ||
| // This conversion should be a simple wire crossing. |
There was a problem hiding this comment.
I think this isn't true because there's no bit permutation that maps one pair to the other, so it's a genuine re-encoding, not a rewiring. I don't think this is a problem and the implementation is correct, but suggest rephrasing the comment.
There was a problem hiding this comment.
It should map well by swapping the lower two bits; at least the True/False values match. Nevertheless, this might not hold true generally if the values change, nor is it particularly relevant, so I removed this line of the comment.
| srcs = ["rv_core_ibex_mcounteren_writable_test.c"], | ||
| exec_env = EARLGREY_TEST_ENVS, | ||
| deps = [ | ||
| "//hw/top_earlgrey/sw/autogen:top_earlgrey", |
There was a problem hiding this comment.
As the C file #includes hw/top/rv_core_ibex_regs.h, I suggest you add //hw/top:rv_core_ibex_c_regs. The test seems to build, so this gets transitively pulled in already, but it's cleaner to have the depencency explicit.
There was a problem hiding this comment.
Right, I added this.
|
CHANGE AUTHORIZED: hw/top_earlgrey/ip_autogen/rv_core_ibex/data/rv_core_ibex.hjson Agreed new feature for Ibex. |
This register allows locking/unlocking the mcounteren CSR in Ibex to control which performance counters are available in U-mode. Signed-off-by: Samuel Riedel <sriedel@lowrisc.org>
Update code from upstream repository https://github.com/lowRISC/ibex.git to revision aae4809aea170fc605bdaa64a70a13efd2408829 * [dv] Check u-mode counter alias the correct m-mode counter (Samuel Riedel) * [formal] Exclude u-mode counters from formal verification (Samuel Riedel) * [doc] Document the newly added performance counters (Samuel Riedel) * [dv] Add directed test for mcounteren lock signal (Samuel Riedel) * [dv] Add `mcounteren` directed test (Samuel Riedel) * [dv] Fix ordering in `directed_testlist.yml` (Samuel Riedel) * [dv] Implement Ibex-specific mcounteren behavior in cosim (Samuel Riedel) * [rtl] Add input to lock mcounteren (Samuel Riedel) * [rtl] Add unpriviledged counter/timers (Samuel Riedel) * [rtl] Add register for `mcounteren` (Samuel Riedel) * [rtl] Fix incrementing `minstret` after setting it (Samuel Riedel) * [rtl] Fix speculative increment of `minstret` (Samuel Riedel) * [syn] Fix scripts for new vendored lowrisc_ip (Harry Callahan) * [syn] Add nix devShell for example synthesis flow (Harry Callahan) * [dv] Fixup explicit static lifetime on initializer by seperating decl from assign. (Harry Callahan) * [vendor/google_riscv-dv] Add VCS -Xcflags to suppress build warnings (Harry Callahan) * [vendor/google_riscv-dv] use env bash and non-absolute bash paths (Harry Callahan) * [rtl] Explicitly define mapping to `prim_generic` for linter targets (Samuel Riedel) * [rtl] Fix prim_generic mapping in ibex_top (Samuel Riedel) * [rtl] Move prim_generic dependency to ibex_top (Samuel Riedel) * [doc] Ibex Concierge updated (Marno van der Maas) Signed-off-by: Samuel Riedel <sriedel@lowrisc.org>
Software test to verify that the `mcounteren_writable` can be set and cleared and locked. This test also verifies that it locks the `mcounteren` CSR in Ibex Signed-off-by: Samuel Riedel <sriedel@lowrisc.org>
| ] | ||
| }, | ||
|
|
||
| { name: "MCOUNTEREN_WRITABLE_REGWEN", |
There was a problem hiding this comment.
As discussed offline, OK for me to have this as a single-bit value and not a mubi. To change the MCOUNTEREN value below, an attacker would need to fault it to be unlocked and also have SW access to write to it.
|
Merging as the timeout in the CW340 ROM Tests is a known issue that is not related to this PR. |
mcounterenCSR to control which u-mode counters are accessiblemcounterenCSR can be locked through an input signal to prevent modifying it even in m-modemcounteren_writableregister inrv_core_ibexdriving the above signal. This register is lockable with themcounteren_writable_regwenregister.ToDo:
mcounterenregister in Ibexmcounterenregister ibex#2403 is mergedThe test will run in the nightly CI. I activated it temporarily also in the PR's CI and the run can be found here.