diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-10-28 22:58:56 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-10-28 23:07:14 +0000 |
commit | 19f44d2998f6197b70fa2726c551bc8fe6956fa2 (patch) | |
tree | c10207febe260530dfb7c733912994599a9594bf /src/arch/riscv/core | |
parent | e0e102ee24bdab68b0318b505402f60cfb88a5f0 (diff) | |
download | ipxe-19f44d2998f6197b70fa2726c551bc8fe6956fa2.tar.gz |
[riscv] Check if seed CSR is accessible from S-mode
The seed CSR defined by the Zkr extension is accessible only in M-mode
by default. Older versions of OpenSBI (prior to version 1.4) do not
set mseccfg.sseed, with the result that attempts to access the seed
CSR from S-mode will raise an illegal instruction exception.
Add a facility for testing the accessibility of arbitrary CSRs, and
use it to check that the seed CSR is accessible before reporting the
seed CSR entropy source as being functional.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/riscv/core')
-rw-r--r-- | src/arch/riscv/core/zkr.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/arch/riscv/core/zkr.c b/src/arch/riscv/core/zkr.c index bf1609671..4b6316ea0 100644 --- a/src/arch/riscv/core/zkr.c +++ b/src/arch/riscv/core/zkr.c @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <errno.h> #include <ipxe/hart.h> +#include <ipxe/csr.h> #include <ipxe/entropy.h> #include <ipxe/drbg.h> @@ -60,6 +61,12 @@ static int zkr_entropy_enable ( void ) { return rc; } + /* Check if seed CSR is accessible in S-mode */ + if ( ! csr_can_write ( "seed", 0 ) ) { + DBGC ( colour, "ZKR cannot access seed CSR\n" ); + return -ENOTSUP; + } + /* RISC-V ISA mandates that 128 bits of full entropy shall be * obtained from 256 entropy bits read from the seed CSR. * |