virtio-devices: rng: correctly indicate number of bytes written

Reads from the random file may only be partial, e.g., if the random file is an ordinary text
file. When that happens, the device needs to signal to the driver that only parts of the buffer have
been overwritten.

Signed-off-by: Markus Napierkowski <markus.napierkowski@cyberus-technology.de>
This commit is contained in:
Markus Napierkowski 2022-08-18 14:03:58 +02:00 committed by Rob Bradford
parent 31dfe3d02a
commit b49f8b9248

View File

@ -58,17 +58,13 @@ impl RngEpollHandler {
// Drivers can only read from the random device.
if desc.is_write_only() {
// Fill the read with data from the random device on the host.
if desc_chain
.memory()
.read_from(
desc.addr()
.translate_gva(self.access_platform.as_ref(), desc.len() as usize),
&mut self.random_file,
desc.len() as usize,
)
.is_ok()
{
len = desc.len();
if let Ok(number_of_bytes) = desc_chain.memory().read_from(
desc.addr()
.translate_gva(self.access_platform.as_ref(), desc.len() as usize),
&mut self.random_file,
desc.len() as usize,
) {
len = number_of_bytes as u32;
}
}