hwrng: optee: handle unlimited data rates
Subsystems (3)
PATCH v2 1/2 hwrng: optee: handle unlimited data rates
Data rates of MAX_UINT32 will schedule an unnecessary one jiffy timeout on the call to msleep. Avoid this scenario by using 0 as the unlimited data rate.
--- drivers/char/hw_random/optee-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/hw_random/optee-rng.c +1 -1
@@ -128,7 +128,7 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) data += rng_size; read += rng_size; -if (wait) { +if (wait && pvt_data->data_rate) {if (timeout-- ==0 )return read;msleep ((1000 * (max - read)) / pvt_data->data_rate);
Signature · 1 line
2.17.1
PATCH v2 2/2 hwrng: optee: fix wait use case
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
---
v2: tidy up the while loop to avoid reading when no data is requested
drivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/hw_random/optee-rng.c +2 -2
@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read)); data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else {
Signature · 1 line
2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
Quoted 16 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +0
-0@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ;
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 10 lines
drivers/char/hw_random/optee-rng.c +2
-2-while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read)); data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))
If read == max, would there be any sleep?
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 6 lines · Sumit Garg
Quoted 5 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
Quoted 6 lines
Quoted 4 lines
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
currently, if the user sets max 0, get_optee_rng_data will regardless issuese a call to the secure world requesting 0 bytes from the RNG
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));
Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Quoted 9 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 49 lines · Foundries
Quoted 6 lines · Sumit Garg
Quoted 5 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
Quoted 6 lines
Quoted 4 lines
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGwith this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 7 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
any further comments?
Quoted 9 lines
Quoted 9 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
In reply to Jorge Ramirez-Ortiz, FoundriesApologies for my delayed response as I was busy with some other tasks along with holidays.
Quoted 11 lines · Foundries
Quoted 9 lines · Sumit Garg
Quoted 8 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNG
This case is already handled by core API: rng_dev_read().
Quoted 32 lines
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 6 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Wouldn't it lead to a call as msleep(0); that means no wait as well?
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 2 lines · Sumit Garg
Apologies for my delayed response as I was busy with some other tasks along with holidays.
no pb! was just making sure this wasnt falling through some cracks.
Quoted 16 lines
Quoted 13 lines · Foundries
Quoted 11 lines · Sumit Garg
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I am not sure how this is possible, can you elaborate?
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGThis case is already handled by core API:
rng_dev_read().
ah ok good point, you are right
but yeah, there is no consequence to the actual patch.
Quoted 33 lines
Quoted 33 lines
with this patch, this request is avoided.
Quoted 29 lines
Quoted 17 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +0
-0@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ;drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 10 lines
drivers/char/hw_random/optee-rng.c +2
-2-while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read)); data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 8 lines
Quoted 6 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Wouldn't it lead to a call as msleep(0); that means no wait as well?
I dont understand: there is no reason to wait if read == max and this patch will not wait: if read == max it calls 'return read'
am I misunderstanding your point?
Quoted 13 lines
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 25 lines · Foundries
Quoted 2 lines · Sumit Garg
Apologies for my delayed response as I was busy with some other tasks along with holidays.
no pb! was just making sure this wasnt falling through some cracks.
Quoted 18 lines
Quoted 15 lines · Foundries
Quoted 12 lines · Sumit Garg
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGThis case is already handled by core API:
rng_dev_read().ah ok good point, you are right
but yeah, there is no consequence to the actual patch.
So, at least you could get rid of the corresponding text from commit message.
Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Quoted 6 lines
Quoted 1 line
Wouldn't it lead to a call as msleep(0); that means no wait as well?
I dont understand: there is no reason to wait if read == max and this patch will not wait: if read == max it calls 'return read'
am I misunderstanding your point?
What I mean is that we shouldn't require this extra check here as there wasn't any wait if read == max with existing implementation too.
-Sumit
Quoted 14 lines
Quoted 14 lines
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 81 lines · Sumit Garg
Quoted 25 lines · Foundries
Quoted 2 lines · Sumit Garg
Apologies for my delayed response as I was busy with some other tasks along with holidays.
no pb! was just making sure this wasnt falling through some cracks.
Quoted 18 lines
Quoted 15 lines · Foundries
Quoted 12 lines · Sumit Garg
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGThis case is already handled by core API:
rng_dev_read().ah ok good point, you are right
but yeah, there is no consequence to the actual patch.So, at least you could get rid of the corresponding text from commit message.
Quoted 42 lines
Quoted 41 lines
Quoted 33 lines
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 6 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Wouldn't it lead to a call as msleep(0); that means no wait as well?
Quoted 7 lines
Quoted 4 lines
I dont understand: there is no reason to wait if read == max and this patch will not wait: if read == max it calls 'return read'
am I misunderstanding your point?
What I mean is that we shouldn't require this extra check here as there wasn't any wait if read == max with existing implementation too.
um, I am getting confused Sumit
with the exisiting implementation (the one we aim to replace), if get_optee_rng_data reads all the values requested on the first call (ie, read = 0) with wait set to true, the call will wait with msleep(0). Which is unnecessary and waits for a jiffy (ie, the call to msleep 0 will schedule a one jiffy timeout interrruptible)
with this alternative implementation, msleep(0) does not get called.
are we in synch?
Quoted 17 lines
-Sumit
Quoted 14 lines
Quoted 14 lines
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 91 lines · Foundries
Quoted 81 lines · Sumit Garg
Quoted 25 lines · Foundries
Quoted 2 lines · Sumit Garg
Apologies for my delayed response as I was busy with some other tasks along with holidays.
no pb! was just making sure this wasnt falling through some cracks.
Quoted 18 lines
Quoted 15 lines · Foundries
Quoted 12 lines · Sumit Garg
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGThis case is already handled by core API:
rng_dev_read().ah ok good point, you are right
but yeah, there is no consequence to the actual patch.So, at least you could get rid of the corresponding text from commit message.
Quoted 42 lines
Quoted 41 lines
Quoted 33 lines
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 6 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Wouldn't it lead to a call as msleep(0); that means no wait as well?
Quoted 7 lines
Quoted 4 lines
I dont understand: there is no reason to wait if read == max and this patch will not wait: if read == max it calls 'return read'
am I misunderstanding your point?
What I mean is that we shouldn't require this extra check here as there wasn't any wait if read == max with existing implementation too.
Quoted 7 lines
um, I am getting confused Sumit
with the exisiting implementation (the one we aim to replace), if
get_optee_rng_datareads all the values requested on the first call (ie, read = 0) with wait set to true, the call will wait with msleep(0). Which is unnecessary and waits for a jiffy (ie, the call to msleep 0 will schedule a one jiffy timeout interrruptible)with this alternative implementation, msleep(0) does not get called.
are we in synch?
Ah, I see msleep(0) also by default schedules timeout for 1 jiffy. So we are in sync now. Probably you can clarify this in commit message as well to avoid confusion.
-Sumit
Quoted 18 lines
Quoted 18 lines
-Sumit
Quoted 14 lines
Quoted 14 lines
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 97 lines · Sumit Garg
Quoted 95 lines · Foundries
Quoted 81 lines · Sumit Garg
Quoted 25 lines · Foundries
Quoted 2 lines · Sumit Garg
Apologies for my delayed response as I was busy with some other tasks along with holidays.
no pb! was just making sure this wasnt falling through some cracks.
Quoted 18 lines
Quoted 15 lines · Foundries
Quoted 12 lines · Sumit Garg
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGThis case is already handled by core API:
rng_dev_read().ah ok good point, you are right
but yeah, there is no consequence to the actual patch.So, at least you could get rid of the corresponding text from commit message.
Quoted 42 lines
Quoted 41 lines
Quoted 33 lines
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 6 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Wouldn't it lead to a call as msleep(0); that means no wait as well?
Quoted 7 lines
Quoted 4 lines
I dont understand: there is no reason to wait if read == max and this patch will not wait: if read == max it calls 'return read'
am I misunderstanding your point?
What I mean is that we shouldn't require this extra check here as there wasn't any wait if read == max with existing implementation too.
um, I am getting confused Sumit
with the exisiting implementation (the one we aim to replace), if
get_optee_rng_datareads all the values requested on the first call (ie, read = 0) with wait set to true, the call will wait with msleep(0). Which is unnecessary and waits for a jiffy (ie, the call to msleep 0 will schedule a one jiffy timeout interrruptible)
Quoted 7 lines
Quoted 3 lines
with this alternative implementation, msleep(0) does not get called.
are we in synch?
Ah, I see msleep(0) also by default schedules timeout for 1 jiffy. So we are in sync now. Probably you can clarify this in commit message as well to avoid confusion.
ok will do.
shall I add your reviewed-by line or just resend?
Quoted 21 lines
-Sumit
Quoted 18 lines
Quoted 18 lines
-Sumit
Quoted 14 lines
Quoted 14 lines
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
Quoted 101 lines · Foundries
Quoted 99 lines · Sumit Garg
Quoted 97 lines · Foundries
Quoted 81 lines · Sumit Garg
Quoted 25 lines · Foundries
Quoted 2 lines · Sumit Garg
Apologies for my delayed response as I was busy with some other tasks along with holidays.
no pb! was just making sure this wasnt falling through some cracks.
Quoted 18 lines
Quoted 15 lines · Foundries
Quoted 12 lines · Sumit Garg
Quoted 9 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
I am not sure how this is possible, can you elaborate?
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
currently, if the user sets max 0,
get_optee_rng_datawill regardless issuese a call to the secure world requesting 0 bytes from the RNGThis case is already handled by core API:
rng_dev_read().ah ok good point, you are right
but yeah, there is no consequence to the actual patch.So, at least you could get rid of the corresponding text from commit message.
Quoted 42 lines
Quoted 41 lines
Quoted 33 lines
with this patch, this request is avoided.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));Quoted 8 lines
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 132
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))If read == max, would there be any sleep?
Quoted 6 lines
no but I see no reason why there should be a wait since we already have all the data that we need; the msleep is only required when we need to wait for the RNG to generate entropy for the number of bytes we are requesting. if we are requesting 0 bytes, the entropy is already available. at leat this is what makes sense to me.
Wouldn't it lead to a call as msleep(0); that means no wait as well?
Quoted 7 lines
Quoted 4 lines
I dont understand: there is no reason to wait if read == max and this patch will not wait: if read == max it calls 'return read'
am I misunderstanding your point?
What I mean is that we shouldn't require this extra check here as there wasn't any wait if read == max with existing implementation too.
um, I am getting confused Sumit
with the exisiting implementation (the one we aim to replace), if
get_optee_rng_datareads all the values requested on the first call (ie, read = 0) with wait set to true, the call will wait with msleep(0). Which is unnecessary and waits for a jiffy (ie, the call to msleep 0 will schedule a one jiffy timeout interrruptible)with this alternative implementation, msleep(0) does not get called.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
are we in synch?
Ah, I see msleep(0) also by default schedules timeout for 1 jiffy. So we are in sync now. Probably you can clarify this in commit message as well to avoid confusion.
ok will do.
shall I add your reviewed-by line or just resend?
Yes it's fine with me to add mine reviewed-by.
Quoted 21 lines
Quoted 21 lines
-Sumit
Quoted 18 lines
Quoted 18 lines
-Sumit
Quoted 14 lines
Quoted 14 lines
-Sumit
Quoted 10 lines
Quoted 10 lines
-Sumit
Quoted 6 lines
drivers/char/hw_random/optee-rng.c +0
-1return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else { --2.17.1
Re: [PATCHv2 2/2] hwrng: optee: fix wait use case
In reply to Jorge Ramirez-OrtizQuoted 27 lines · Jorge Ramirez-Ortiz
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop exits.
This fix does not wait if all data has been read and reads a second time if only partial data was retrieved on the first read.
This fix also does not attempt to read if not data is requested.
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>---
v2: tidy up the while loop to avoid reading when no data is requesteddrivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/char/hw_random/optee-rng.c +1
-1@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)if (max >MAX_ENTROPY_REQ_SZ ) max =MAX_ENTROPY_REQ_SZ ; -while (read ==0 ) { +while (read < max) { rng_size =get_optee_rng_data (pvt_data, data, (max - read));
drivers/char/hw_random/optee-rng.c static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) · line 135
Quoted 10 lines
drivers/char/hw_random/optee-rng.c +1
-1data += rng_size; read += rng_size;if (wait && pvt_data->data_rate) { -if (timeout-- ==0 ) +if ((timeout-- ==0 ) || (read == max))return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); }else {
any comments please?
Quoted 10 lines · Jorge Ramirez-Ortiz
Data rates of
MAX_UINT32will schedule an unnecessary one jiffy timeout on the call to msleep. Avoid this scenario by using 0 as the unlimited data rate.Signed-off-by Jorge Ramirez-Ortiz <[email protected]>--- drivers/char/hw_random/optee-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Sounds good to me. FWIW:
-Sumit
Quoted 16 lines
drivers/char/hw_random/optee-rng.c +1
-2@@ -128,7 +128,7 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) data += rng_size; read += rng_size; -if (wait) { +if (wait && pvt_data->data_rate) {if (timeout-- ==0 )return read;msleep ((1000 * (max - read)) / pvt_data->data_rate); --2.17.1