The feature negotiation was designed in a way that makes it possible for devices to know which config fields will be accessed by drivers. This is broken since commit 404123c2db79 ("virtio: allow drivers to validate features") with fallout in at least block and net. We have a partial work-around in commit 2f9a174f918e ("virtio: write back F_VERSION_1 before validate") which at least lets devices find out which format should config space have, but this is a partial fix: guests should not access config space without acknowledging features since otherwise we'll never be able to change the config space format. To fix, split finalize_features from virtio_finalize_features and call finalize_features with all feature bits before validation, and then - if validation changed any bits - once again after. Since virtio_finalize_features no longer writes out features rename it to virtio_features_ok - since that is what it does: checks that features are ok with the device. As a side effect, this also reduces the amount of hypervisor accesses - we now only acknowledge features once unless we are clearing any features when validating (which is uncommon). IRC I think that this was more or less always the intent in the spec but unfortunately the way the spec is worded does not say this explicitly, I plan to address this at the spec level, too.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -64,8 +64,9 @@ struct virtio_shm_region { · 63 unmodified lines | ||
| 64 | 64 | * Returns the first 64 feature bits (all we currently need). |
| 65 | 65 | * @finalize_features: confirm what device features we'll be using. |
| 66 | 66 | * vdev: the virtio_device |
| 67 | − * This gives the final feature bits for the device: it can change | |
| 67 | + * This sends the driver feature bits to the device: it can change | |
| 68 | 68 | * the dev->feature bits if it wants. |
| 69 | + * Note: despite the name this can be called any number of times. | |
| 69 | 70 | * Returns 0 on success or error status |
| 70 | 71 | * @bus_name: return the bus name associated with the device (optional) |
| 71 | 72 | * vdev: the virtio_device |