> On 18 Jan 2018, at 04:18, Jacob Bachmeyer <
jcb6...@gmail.com> wrote:
>
> ... larger systems (1) should use CSRs as they are currently defined and (2) should *not* make CSRs accessible in MMIO space for security reasons, with a possible exception to (2) for the monitor. S-mode MMIO access to CSRs is asking for exploits as I see it.
I understand the need for security, but are you sure all CSRs can be a security threat?
Even on my small HiFive1, OpenOCD and GDB insist on pushing onto me the following list each time I need to transfer the general registers:
```
231,028 @"===== RISC-V Registers\n"
231,028 @"(0) zero (/32): 0x00000000\n"
231,028 @"(1) ra (/32): 0x80000094\n"
231,028 @"(2) sp (/32): 0x80003F80\n"
231,029 @"(3) gp (/32): 0x80000868\n"
231,029 @"(4) tp (/32): 0x00000000\n"
231,029 @"(5) t0 (/32): 0x80000004\n"
231,029 @"(6) t1 (/32): 0x80000000\n"
231,029 @"(7) t2 (/32): 0x00000000\n"
231,029 @"(8) fp (/32): 0x80003FC0\n"
231,029 @"(9) s1 (/32): 0x00000000\n"
231,029 @"(10) a0 (/32): 0x00000001\n"
231,029 @"(11) a1 (/32): 0x80000068\n"
231,029 @"(12) a2 (/32): 0x00000000\n"
231,029 @"(13) a3 (/32): 0x00000000\n"
231,029 @"(14) a4 (/32): 0x80000068\n"
231,029 @"(15) a5 (/32): 0x00000001\n"
231,029 @"(16) a6 (/32): 0x61727261\n"
231,029 @"(17) a7 (/32): 0x00000001\n"
231,029 @"(18) s2 (/32): 0x00008000\n"
231,030 @"(19) s3 (/32): 0x00000000\n"
231,030 @"(20) s4 (/32): 0xCEB98000\n"
231,030 @"(21) s5 (/32): 0x00000004\n"
231,030 @"(22) s6 (/32): 0x00000000\n"
231,030 @"(23) s7 (/32): 0x00000000\n"
231,030 @"(24) s8 (/32): 0x00000000\n"
231,030 @"(25) s9 (/32): 0x00000000\n"
231,030 @"(26) s10 (/32): 0x00000000\n"
231,030 @"(27) s11 (/32): 0x00000000\n"
231,030 @"(28) t3 (/32): 0x00000003\n"
231,030 @"(29) t4 (/32): 0x00000000\n"
231,030 @"(30) t5 (/32): 0x00000000\n"
231,030 @"(31) t6 (/32): 0x00000000\n"
231,030 @"(32) pc (/32): 0x20400000\n"
231,031 @"(833) mstatus (/32): 0x00001808\n"
231,031 @"(834) misa (/32)\n"
231,031 @"(835) medeleg (/32)\n"
231,031 @"(836) mideleg (/32)\n"
231,031 @"(837) mie (/32)\n"
231,031 @"(838) mtvec (/32)\n"
231,031 @"(839) mcounteren (/32)\n"
231,031 @"(868) mhpmevent3 (/32)\n"
231,031 @"(869) mhpmevent4 (/32)\n"
231,031 @"(870) mhpmevent5 (/32)\n"
231,031 @"(871) mhpmevent6 (/32)\n"
231,031 @"(872) mhpmevent7 (/32)\n"
231,031 @"(873) mhpmevent8 (/32)\n"
231,031 @"(874) mhpmevent9 (/32)\n"
231,031 @"(875) mhpmevent10 (/32)\n"
231,031 @"(876) mhpmevent11 (/32)\n"
231,031 @"(877) mhpmevent12 (/32)\n"
231,031 @"(878) mhpmevent13 (/32)\n"
231,031 @"(879) mhpmevent14 (/32)\n"
231,031 @"(880) mhpmevent15 (/32)\n"
231,031 @"(881) mhpmevent16 (/32)\n"
231,032 @"(882) mhpmevent17 (/32)\n"
231,032 @"(883) mhpmevent18 (/32)\n"
231,032 @"(884) mhpmevent19 (/32)\n"
231,032 @"(885) mhpmevent20 (/32)\n"
231,032 @"(886) mhpmevent21 (/32)\n"
231,032 @"(887) mhpmevent22 (/32)\n"
231,032 @"(888) mhpmevent23 (/32)\n"
231,032 @"(889) mhpmevent24 (/32)\n"
231,032 @"(890) mhpmevent25 (/32)\n"
231,032 @"(891) mhpmevent26 (/32)\n"
231,032 @"(892) mhpmevent27 (/32)\n"
231,032 @"(893) mhpmevent28 (/32)\n"
231,032 @"(894) mhpmevent29 (/32)\n"
231,033 @"(895) mhpmevent30 (/32)\n"
231,033 @"(896) mhpmevent31 (/32)\n"
231,033 @"(897) mscratch (/32)\n"
231,033 @"(898) mepc (/32)\n"
231,033 @"(899) mcause (/32)\n"
231,033 @"(900) mtval (/32)\n"
231,033 @"(901) mip (/32)\n"
231,033 @"(993) pmpcfg0 (/32)\n"
231,033 @"(994) pmpcfg1 (/32)\n"
231,033 @"(995) pmpcfg2 (/32)\n"
231,033 @"(996) pmpcfg3 (/32)\n"
231,033 @"(1009) pmpaddr0 (/32)\n"
231,033 @"(1010) pmpaddr1 (/32)\n"
231,033 @"(1011) pmpaddr2 (/32)\n"
231,033 @"(1012) pmpaddr3 (/32)\n"
231,033 @"(1013) pmpaddr4 (/32)\n"
231,033 @"(1014) pmpaddr5 (/32)\n"
231,033 @"(1015) pmpaddr6 (/32)\n"
231,033 @"(1016) pmpaddr7 (/32)\n"
231,033 @"(1017) pmpaddr8 (/32)\n"
231,033 @"(1018) pmpaddr9 (/32)\n"
231,033 @"(1019) pmpaddr10 (/32)\n"
231,033 @"(1020) pmpaddr11 (/32)\n"
231,034 @"(1021) pmpaddr12 (/32)\n"
231,034 @"(1022) pmpaddr13 (/32)\n"
231,034 @"(1023) pmpaddr14 (/32)\n"
231,034 @"(1024) pmpaddr15 (/32)\n"
231,034 @"(2017) tselect (/32)\n"
231,034 @"(2018) tdata1 (/32)\n"
231,034 @"(2019) tdata2 (/32)\n"
231,034 @"(2020) tdata3 (/32)\n"
231,034 @"(2033) dcsr (/32)\n"
231,034 @"(2034) dpc (/32)\n"
231,034 @"(2035) dscratch (/32)\n"
231,034 @"(2881) mcycle (/32)\n"
231,034 @"(2883) minstret (/32)\n"
231,034 @"(2884) mhpmcounter3 (/32)\n"
231,034 @"(2885) mhpmcounter4 (/32)\n"
231,034 @"(2886) mhpmcounter5 (/32)\n"
231,034 @"(2887) mhpmcounter6 (/32)\n"
231,034 @"(2888) mhpmcounter7 (/32)\n"
231,034 @"(2889) mhpmcounter8 (/32)\n"
231,034 @"(2890) mhpmcounter9 (/32)\n"
231,034 @"(2891) mhpmcounter10 (/32)\n"
231,034 @"(2892) mhpmcounter11 (/32)\n"
231,034 @"(2893) mhpmcounter12 (/32)\n"
231,034 @"(2894) mhpmcounter13 (/32)\n"
231,035 @"(2895) mhpmcounter14 (/32)\n"
231,035 @"(2896) mhpmcounter15 (/32)\n"
231,035 @"(2897) mhpmcounter16 (/32)\n"
231,035 @"(2898) mhpmcounter17 (/32)\n"
231,035 @"(2899) mhpmcounter18 (/32)\n"
231,035 @"(2900) mhpmcounter19 (/32)\n"
231,035 @"(2901) mhpmcounter20 (/32)\n"
231,035 @"(2902) mhpmcounter21 (/32)\n"
231,035 @"(2903) mhpmcounter22 (/32)\n"
231,036 @"(2904) mhpmcounter23 (/32)\n"
231,036 @"(2905) mhpmcounter24 (/32)\n"
231,036 @"(2906) mhpmcounter25 (/32)\n"
231,036 @"(2907) mhpmcounter26 (/32)\n"
231,036 @"(2908) mhpmcounter27 (/32)\n"
231,036 @"(2909) mhpmcounter28 (/32)\n"
231,036 @"(2910) mhpmcounter29 (/32)\n"
231,036 @"(2911) mhpmcounter30 (/32)\n"
231,036 @"(2912) mhpmcounter31 (/32)\n"
231,036 @"(3009) mcycleh (/32)\n"
231,036 @"(3011) minstreth (/32)\n"
231,036 @"(3012) mhpmcounter3h (/32)\n"
231,036 @"(3013) mhpmcounter4h (/32)\n"
231,036 @"(3014) mhpmcounter5h (/32)\n"
231,036 @"(3015) mhpmcounter6h (/32)\n"
231,036 @"(3016) mhpmcounter7h (/32)\n"
231,036 @"(3017) mhpmcounter8h (/32)\n"
231,036 @"(3018) mhpmcounter9h (/32)\n"
231,036 @"(3019) mhpmcounter10h (/32)\n"
231,036 @"(3020) mhpmcounter11h (/32)\n"
231,036 @"(3021) mhpmcounter12h (/32)\n"
231,036 @"(3022) mhpmcounter13h (/32)\n"
231,036 @"(3023) mhpmcounter14h (/32)\n"
231,036 @"(3024) mhpmcounter15h (/32)\n"
231,036 @"(3025) mhpmcounter16h (/32)\n"
231,036 @"(3026) mhpmcounter17h (/32)\n"
231,036 @"(3027) mhpmcounter18h (/32)\n"
231,036 @"(3028) mhpmcounter19h (/32)\n"
231,036 @"(3029) mhpmcounter20h (/32)\n"
231,036 @"(3030) mhpmcounter21h (/32)\n"
231,036 @"(3031) mhpmcounter22h (/32)\n"
231,036 @"(3032) mhpmcounter23h (/32)\n"
231,036 @"(3033) mhpmcounter24h (/32)\n"
231,037 @"(3034) mhpmcounter25h (/32)\n"
231,037 @"(3035) mhpmcounter26h (/32)\n"
231,037 @"(3036) mhpmcounter27h (/32)\n"
231,037 @"(3037) mhpmcounter28h (/32)\n"
231,038 @"(3038) mhpmcounter29h (/32)\n"
231,038 @"(3039) mhpmcounter30h (/32)\n"
231,038 @"(3040) mhpmcounter31h (/32)\n"
231,038 @"(3137) cycle (/32)\n"
231,038 @"(3138) time (/32)\n"
231,038 @"(3139) instret (/32)\n"
231,038 @"(3140) hpmcounter3 (/32)\n"
231,038 @"(3141) hpmcounter4 (/32)\n"
231,038 @"(3142) hpmcounter5 (/32)\n"
231,038 @"(3143) hpmcounter6 (/32)\n"
231,038 @"(3144) hpmcounter7 (/32)\n"
231,038 @"(3145) hpmcounter8 (/32)\n"
231,038 @"(3146) hpmcounter9 (/32)\n"
231,038 @"(3147) hpmcounter10 (/32)\n"
231,038 @"(3148) hpmcounter11 (/32)\n"
231,038 @"(3149) hpmcounter12 (/32)\n"
231,038 @"(3150) hpmcounter13 (/32)\n"
231,038 @"(3151) hpmcounter14 (/32)\n"
231,038 @"(3152) hpmcounter15 (/32)\n"
231,038 @"(3153) hpmcounter16 (/32)\n"
231,038 @"(3154) hpmcounter17 (/32)\n"
231,038 @"(3155) hpmcounter18 (/32)\n"
231,038 @"(3156) hpmcounter19 (/32)\n"
231,038 @"(3157) hpmcounter20 (/32)\n"
231,038 @"(3158) hpmcounter21 (/32)\n"
231,038 @"(3159) hpmcounter22 (/32)\n"
231,038 @"(3160) hpmcounter23 (/32)\n"
231,038 @"(3161) hpmcounter24 (/32)\n"
231,038 @"(3162) hpmcounter25 (/32)\n"
231,038 @"(3163) hpmcounter26 (/32)\n"
231,038 @"(3164) hpmcounter27 (/32)\n"
231,038 @"(3165) hpmcounter28 (/32)\n"
231,038 @"(3166) hpmcounter29 (/32)\n"
231,038 @"(3167) hpmcounter30 (/32)\n"
231,038 @"(3168) hpmcounter31 (/32)\n"
231,038 @"(3265) cycleh (/32)\n"
231,038 @"(3266) timeh (/32)\n"
231,038 @"(3267) instreth (/32)\n"
231,039 @"(3268) hpmcounter3h (/32)\n"
231,039 @"(3269) hpmcounter4h (/32)\n"
231,039 @"(3270) hpmcounter5h (/32)\n"
231,039 @"(3271) hpmcounter6h (/32)\n"
231,039 @"(3272) hpmcounter7h (/32)\n"
231,039 @"(3273) hpmcounter8h (/32)\n"
231,039 @"(3274) hpmcounter9h (/32)\n"
231,039 @"(3275) hpmcounter10h (/32)\n"
231,039 @"(3276) hpmcounter11h (/32)\n"
231,040 @"(3277) hpmcounter12h (/32)\n"
231,040 @"(3278) hpmcounter13h (/32)\n"
231,040 @"(3279) hpmcounter14h (/32)\n"
231,040 @"(3280) hpmcounter15h (/32)\n"
231,040 @"(3281) hpmcounter16h (/32)\n"
231,040 @"(3282) hpmcounter17h (/32)\n"
231,040 @"(3283) hpmcounter18h (/32)\n"
231,040 @"(3284) hpmcounter19h (/32)\n"
231,040 @"(3285) hpmcounter20h (/32)\n"
231,040 @"(3286) hpmcounter21h (/32)\n"
231,040 @"(3287) hpmcounter22h (/32)\n"
231,040 @"(3288) hpmcounter23h (/32)\n"
231,040 @"(3289) hpmcounter24h (/32)\n"
231,040 @"(3290) hpmcounter25h (/32)\n"
231,040 @"(3291) hpmcounter26h (/32)\n"
231,040 @"(3292) hpmcounter27h (/32)\n"
231,040 @"(3293) hpmcounter28h (/32)\n"
231,040 @"(3294) hpmcounter29h (/32)\n"
231,040 @"(3295) hpmcounter30h (/32)\n"
231,040 @"(3296) hpmcounter31h (/32)\n"
231,040 @"(3922) mvendorid (/32)\n"
231,040 @"(3923) marchid (/32)\n"
231,040 @"(3924) mimpid (/32)\n"
231,040 @"(3925) mhartid (/32)\n"
231,040 @"(4161) priv (/8)\n"
231,040 36^done
231,040 (gdb)
```
Do you think that those tens of counters, which are not even implemented, are a big security threat?
I agree that some core registers should be treated carefully, but the bulk of them can be moved to MMIO, as `mtime` was.
And definitely do not encourage users to add their private CSRs if not really needed, MMIO should be fine for most of the use cases.
> I agree that the simplest M-mode-only embedded systems should use MMIO and RVA instead of CSRs,
This can only be achieved by creating a separate riscv-embed profile, with its own specifications.
Large 'application' type devices should implement basic ISA plus the 'priviledged' profile; small (M or M+U, definitely no MMU) devices should implement basic ISA plus the 'embedded' profile.
The current approach, to enforce the privileged specs onto all devices and allow for some features to be optional is not beneficial, and generates only frustration for the embedded developers.
You simply cannot expect to have millions of happy coders if you ask them to write assembly code all over the place, especially when the main competing architecture (Cortex-M) successfully proved that assembly is generally not required (system registers are MMIO, interrupt handlers are plain C functions, the stack pointer is set automatically before reset, etc).
Regards,
Liviu