Skip to content

Commit 559d03b

Browse files
Dorinda Basseyslp
authored andcommitted
devices/vhost: Implement write_config for dynamic config
Implement write_config in VhostUserDevice to support virtio devices that use dynamic configuration space, such as virtio-input. Some virtio devices like virtio-input use a request-response pattern for device discovery. Without write_config support, the backend never receives the virtio_input config values, causing device initialization to fail. This implementation uses VHOST_USER_SET_CONFIG to forward writes to the backend. Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
1 parent 263f36e commit 559d03b

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

src/devices/src/virtio/vhost_user/device.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,33 @@ impl VirtioDevice for VhostUserDevice {
400400
data.fill(0);
401401
}
402402

403-
fn write_config(&mut self, offset: u64, _data: &[u8]) {
404-
// For now, configuration space writes are not supported
405-
// This can be extended using VHOST_USER_SET_CONFIG
406-
debug!(
407-
"{}: config write at offset {} (not yet implemented)",
408-
self.device_name, offset
409-
);
403+
fn write_config(&mut self, offset: u64, data: &[u8]) {
404+
if !self.has_protocol_features {
405+
debug!(
406+
"{}: config write at offset {} skipped (no protocol features)",
407+
self.device_name, offset
408+
);
409+
return;
410+
}
411+
412+
if let Ok(mut frontend) = self.frontend.lock() {
413+
match frontend.set_config(offset as u32, VhostUserConfigFlags::empty(), data) {
414+
Ok(_) => {
415+
debug!(
416+
"{}: wrote {} bytes to config at offset {}",
417+
self.device_name,
418+
data.len(),
419+
offset
420+
);
421+
}
422+
Err(e) => {
423+
warn!(
424+
"{}: failed to write config at offset {}: {:?}",
425+
self.device_name, offset, e
426+
);
427+
}
428+
}
429+
}
410430
}
411431

412432
fn activate(

0 commit comments

Comments
 (0)