Skip to content

Commit 70d52df

Browse files
author
Dorinda Bassey
committed
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 50c4b2a commit 70d52df

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
@@ -390,13 +390,33 @@ impl VirtioDevice for VhostUserDevice {
390390
data.fill(0);
391391
}
392392

393-
fn write_config(&mut self, offset: u64, _data: &[u8]) {
394-
// For now, configuration space writes are not supported
395-
// This can be extended using VHOST_USER_SET_CONFIG
396-
debug!(
397-
"{}: config write at offset {} (not yet implemented)",
398-
self.device_name, offset
399-
);
393+
fn write_config(&mut self, offset: u64, data: &[u8]) {
394+
if !self.has_protocol_features {
395+
debug!(
396+
"{}: config write at offset {} skipped (no protocol features)",
397+
self.device_name, offset
398+
);
399+
return;
400+
}
401+
402+
if let Ok(mut frontend) = self.frontend.lock() {
403+
match frontend.set_config(offset as u32, VhostUserConfigFlags::empty(), data) {
404+
Ok(_) => {
405+
debug!(
406+
"{}: wrote {} bytes to config at offset {}",
407+
self.device_name,
408+
data.len(),
409+
offset
410+
);
411+
}
412+
Err(e) => {
413+
warn!(
414+
"{}: failed to write config at offset {}: {:?}",
415+
self.device_name, offset, e
416+
);
417+
}
418+
}
419+
}
400420
}
401421

402422
fn activate(

0 commit comments

Comments
 (0)