summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/linux.rs39
-rw-r--r--src/plugin/mod.rs47
2 files changed, 70 insertions, 16 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 91ea1ae..b45b956 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -668,17 +668,40 @@ fn run_vcpu(
                 match run_res {
                     Ok(run) => {
                         match run {
-                            VcpuExit::IoIn(addr, data) => {
-                                io_bus.read(addr as u64, data);
+                            VcpuExit::IoIn { port, mut size } => {
+                                let mut data = [0; 8];
+                                if size > data.len() {
+                                    error!("unsupported IoIn size of {} bytes", size);
+                                    size = data.len();
+                                }
+                                io_bus.read(port as u64, &mut data[..size]);
+                                if let Err(e) = vcpu.set_data(&data[..size]) {
+                                    error!("failed to set return data for IoIn: {:?}", e);
+                                }
                             }
-                            VcpuExit::IoOut(addr, data) => {
-                                io_bus.write(addr as u64, data);
+                            VcpuExit::IoOut {
+                                port,
+                                mut size,
+                                data,
+                            } => {
+                                if size > data.len() {
+                                    error!("unsupported IoOut size of {} bytes", size);
+                                    size = data.len();
+                                }
+                                io_bus.write(port as u64, &data[..size]);
                             }
-                            VcpuExit::MmioRead(addr, data) => {
-                                mmio_bus.read(addr, data);
+                            VcpuExit::MmioRead { address, mut size } => {
+                                let mut data = [0; 8];
+                                mmio_bus.read(address, &mut data[..size]);
+                                // Setting data for mmio can not fail.
+                                let _ = vcpu.set_data(&data[..size]);
                             }
-                            VcpuExit::MmioWrite(addr, data) => {
-                                mmio_bus.write(addr, data);
+                            VcpuExit::MmioWrite {
+                                address,
+                                size,
+                                data,
+                            } => {
+                                mmio_bus.write(address, &data[..size]);
                             }
                             VcpuExit::Hlt => break,
                             VcpuExit::Shutdown => break,
diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs
index 8cd81b4..9f229ac 100644
--- a/src/plugin/mod.rs
+++ b/src/plugin/mod.rs
@@ -363,17 +363,48 @@ pub fn run_vcpus(
                             let run_res = vcpu.run();
                             match run_res {
                                 Ok(run) => match run {
-                                    VcpuExit::IoIn(addr, data) => {
-                                        vcpu_plugin.io_read(addr as u64, data, &vcpu);
+                                    VcpuExit::IoIn { port, mut size } => {
+                                        let mut data = [0; 8];
+                                        if size > data.len() {
+                                            error!("unsupported IoIn size of {} bytes", size);
+                                            size = data.len();
+                                        }
+                                        vcpu_plugin.io_read(port as u64, &mut data[..size], &vcpu);
+                                        if let Err(e) = vcpu.set_data(&data[..size]) {
+                                            error!("failed to set return data for IoIn: {:?}", e);
+                                        }
                                     }
-                                    VcpuExit::IoOut(addr, data) => {
-                                        vcpu_plugin.io_write(addr as u64, data, &vcpu);
+                                    VcpuExit::IoOut {
+                                        port,
+                                        mut size,
+                                        data,
+                                    } => {
+                                        if size > data.len() {
+                                            error!("unsupported IoOut size of {} bytes", size);
+                                            size = data.len();
+                                        }
+                                        vcpu_plugin.io_write(port as u64, &data[..size], &vcpu);
                                     }
-                                    VcpuExit::MmioRead(addr, data) => {
-                                        vcpu_plugin.mmio_read(addr as u64, data, &vcpu);
+                                    VcpuExit::MmioRead { address, mut size } => {
+                                        let mut data = [0; 8];
+                                        vcpu_plugin.mmio_read(
+                                            address as u64,
+                                            &mut data[..size],
+                                            &vcpu,
+                                        );
+                                        // Setting data for mmio can not fail.
+                                        let _ = vcpu.set_data(&data[..size]);
                                     }
-                                    VcpuExit::MmioWrite(addr, data) => {
-                                        vcpu_plugin.mmio_write(addr as u64, data, &vcpu);
+                                    VcpuExit::MmioWrite {
+                                        address,
+                                        size,
+                                        data,
+                                    } => {
+                                        vcpu_plugin.mmio_write(
+                                            address as u64,
+                                            &data[..size],
+                                            &vcpu,
+                                        );
                                     }
                                     VcpuExit::Hlt => break,
                                     VcpuExit::Shutdown => break,