Skip to content

Commit

Permalink
vhost_user: ignore unknown features from backend
Browse files Browse the repository at this point in the history
virtiofsd 1.11.0 added support for VHOST_USER_PROTOCOL_F_DEVICE_STATE.
Upgrading virtiofsd meant that the latest released version of Cloud
Hypervisor (39.0) was no longer able to communicate with it, because
rather than just ignoring the unsupported feature, it got an
unrecoverable "invalid message" error.  This demonstrates that it's
better for frontends to just ignore offers of unsupported features.
If the backend requires some feature, it'll get a chance to know that
when we send VHOST_USER_SET_PROTOCOL_FEATURES anyway.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
  • Loading branch information
alyssais authored and stefano-garzarella committed Jul 1, 2024
1 parent 6755c6c commit 7554d06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions vhost/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [[#241]](/~https://github.com/rust-vmm/vhost/pull/241) Add shared objects support

### Changed
- [[#243]](/~https://github.com/rust-vmm/vhost/pull/243) Ignore unknown bits in `VHOST_USER_GET_PROTOCOL_FEATURES` response.

### Remove
- [[#246]](/~https://github.com/rust-vmm/vhost/pull/246) Remove support for FS_* requests
Expand Down
14 changes: 7 additions & 7 deletions vhost/src/vhost_user/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,9 @@ impl VhostUserFrontend for Frontend {
let hdr = node.send_request_header(FrontendReq::GET_PROTOCOL_FEATURES, None)?;
let val = node.recv_reply::<VhostUserU64>(&hdr)?;
node.protocol_features = val.value;
// Should we support forward compatibility?
// If so just mask out unrecognized flags instead of return errors.
match VhostUserProtocolFeatures::from_bits(node.protocol_features) {
Some(val) => Ok(val),
None => error_code(VhostUserError::InvalidMessage),
}
Ok(VhostUserProtocolFeatures::from_bits_truncate(
node.protocol_features,
))
}

fn set_protocol_features(&mut self, features: VhostUserProtocolFeatures) -> Result<()> {
Expand Down Expand Up @@ -811,6 +808,8 @@ mod tests {

use std::path::PathBuf;

const INVALID_PROTOCOL_FEATURE: u64 = 1 << 63;

fn temp_path() -> PathBuf {
PathBuf::from(format!(
"/tmp/vhost_test_{}",
Expand Down Expand Up @@ -935,7 +934,8 @@ mod tests {

let pfeatures = VhostUserProtocolFeatures::all();
let hdr = VhostUserMsgHeader::new(FrontendReq::GET_PROTOCOL_FEATURES, 0x4, 8);
let msg = VhostUserU64::new(pfeatures.bits());
// Unknown feature bits should be ignored.
let msg = VhostUserU64::new(pfeatures.bits() | INVALID_PROTOCOL_FEATURE);
peer.send_message(&hdr, &msg, None).unwrap();
let features = frontend.get_protocol_features().unwrap();
assert_eq!(features, pfeatures);
Expand Down

0 comments on commit 7554d06

Please sign in to comment.