@@ -343,12 +343,10 @@ struct OtCSRNGState {
343
343
bool enabled ;
344
344
bool sw_app_granted ;
345
345
bool read_int_granted ;
346
- bool es_available ; /* guest warning if entropy power cycling is invalid */
347
346
uint32_t scheduled_cmd ;
348
347
unsigned entropy_delay ;
349
348
unsigned es_retry_count ;
350
349
unsigned state_db_ix ;
351
- int entropy_gennum ;
352
350
int aes_cipher ; /* AES handle for tomcrypt */
353
351
OtCSRNGFsmState state ;
354
352
OtCSRNGInstance * instances ;
@@ -777,18 +775,6 @@ ot_csrng_drng_reseed(OtCSRNGInstance *inst, DeviceState *rand_dev, bool flag0)
777
775
drng -> seeded = false;
778
776
779
777
if (!flag0 ) {
780
- if (!s -> es_available ) {
781
- qemu_log_mask (LOG_GUEST_ERROR ,
782
- "%s: Requesting entropy w/o power cycling ES\n" ,
783
- __func__ );
784
- /*
785
- * Continue anyway as it seems HW does not enforce what is
786
- * documented. Force the flag so the warning message is only
787
- * shown once (it does not serve any other purpose).
788
- */
789
- s -> es_available = true;
790
- }
791
-
792
778
uint64_t buffer [OT_RANDOM_SRC_DWORD_COUNT ];
793
779
memset (buffer , 0 , sizeof (buffer ));
794
780
unsigned len = drng -> material_len * sizeof (uint32_t );
@@ -798,20 +784,21 @@ ot_csrng_drng_reseed(OtCSRNGInstance *inst, DeviceState *rand_dev, bool flag0)
798
784
uint64_t entropy [OT_RANDOM_SRC_DWORD_COUNT ];
799
785
int res ;
800
786
bool fips ;
801
- trace_ot_csrng_request_entropy (slot , s -> entropy_gennum );
787
+ trace_ot_csrng_request_entropy (slot );
802
788
OtRandomSrcIfClass * cls = OT_RANDOM_SRC_IF_GET_CLASS (rand_dev );
803
789
OtRandomSrcIf * randif = OT_RANDOM_SRC_IF (rand_dev );
804
- res = cls -> get_random_values (randif , s -> entropy_gennum , entropy , & fips );
805
- if (res ) {
790
+ res = cls -> get_random_values (randif , entropy , & fips );
791
+
792
+ if (res < 0 ) {
793
+ s -> entropy_delay = 0 ;
794
+ trace_ot_csrng_entropy_rejected (slot , "error" , res );
795
+ return CSRNG_CMD_STALLED ;
796
+ }
797
+
798
+ if (res > 0 ) {
806
799
s -> entropy_delay = (res > 1 ) ? (unsigned )res : 0 ;
807
- trace_ot_csrng_entropy_rejected (slot ,
808
- res < 0 ? (res == -2 ? "stalled" :
809
- "error" ) :
810
- "not ready" ,
811
- res );
812
- return res < 0 ? (res == -2 ? CSRNG_CMD_STALLED :
813
- CSRNG_CMD_RESEED_CNT_EXCEEDED ) :
814
- CSRNG_CMD_RETRY ;
800
+ trace_ot_csrng_entropy_rejected (slot , "not ready" , res );
801
+ return CSRNG_CMD_RETRY ;
815
802
}
816
803
817
804
/* always perform XOR which is a no-op if material_len is zero */
@@ -987,39 +974,11 @@ static void ot_csrng_release_hw_app(OtCSRNGInstance *inst)
987
974
988
975
static void ot_csrng_handle_enable (OtCSRNGState * s )
989
976
{
990
- /*
991
- * As per EarlGrey 2.5.2-rc0:
992
- * "CSRNG may only be enabled if ENTROPY_SRC is enabled. CSRNG may only be
993
- * disabled if all EDNs are disabled. Once disabled, CSRNG may only be
994
- * re-enabled after ENTROPY_SRC has been disabled and re-enabled."
995
- */
996
- OtRandomSrcIfClass * cls = OT_RANDOM_SRC_IF_GET_CLASS (s -> random_src );
997
- OtRandomSrcIf * randif = OT_RANDOM_SRC_IF (s -> random_src );
998
-
999
977
if (ot_csrng_is_ctrl_enabled (s )) {
1000
978
xtrace_ot_csrng_info ("enabling CSRNG" , 0 );
1001
- int gennum = cls -> get_random_generation (randif );
1002
- if (gennum >= 0 ) {
1003
- /*
1004
- * however it is not re-enabling CSRNG w/o cycling the entropy_src
1005
- * that is prohibited, but to request entropy from it. The check is
1006
- * therefore deferred to the reseed handling which makes use of the
1007
- * entropy_src only if flag0 is not set.
1008
- */
1009
- s -> es_available = gennum > s -> entropy_gennum ;
1010
- xtrace_ot_csrng_info ("enable: new ES generation" , gennum );
1011
- } else {
1012
- /*
1013
- * tracking enablement/disablement order is not supported by the
1014
- * entropy source (such as on Darjeeling)
1015
- */
1016
- s -> es_available = true;
1017
- xtrace_ot_csrng_info ("enable: no ES gen tracking" , gennum );
1018
- }
1019
979
s -> enabled = true;
1020
980
s -> regs [R_SW_CMD_STS ] |= R_SW_CMD_STS_CMD_RDY_MASK ;
1021
981
s -> es_retry_count = ENTROPY_SRC_INITIAL_REQUEST_COUNT ;
1022
- s -> entropy_gennum = gennum ;
1023
982
}
1024
983
1025
984
if (ot_csrng_is_ctrl_disabled (s )) {
@@ -1040,8 +999,6 @@ static void ot_csrng_handle_enable(OtCSRNGState *s)
1040
999
s -> enabled = false;
1041
1000
s -> regs [R_SW_CMD_STS ] &= ~R_SW_CMD_STS_CMD_RDY_MASK ;
1042
1001
s -> es_retry_count = 0 ;
1043
- s -> entropy_gennum = cls -> get_random_generation (randif );
1044
- xtrace_ot_csrng_info ("disable: last RS generation" , s -> entropy_gennum );
1045
1002
1046
1003
/* cancel any outstanding asynchronous request */
1047
1004
qemu_bh_cancel (s -> cmd_scheduler );
@@ -2024,8 +1981,6 @@ static void ot_csrng_reset(DeviceState *dev)
2024
1981
s -> regs [R_INT_STATE_READ_ENABLE ] = 0x7u ;
2025
1982
s -> regs [R_MAIN_SM_STATE ] = 0x4eu ;
2026
1983
s -> enabled = false;
2027
- s -> es_available = false;
2028
- s -> entropy_gennum = 0 ;
2029
1984
s -> sw_app_granted = false;
2030
1985
s -> read_int_granted = false;
2031
1986
s -> es_retry_count = 0 ;
0 commit comments