On 24-07-25, 06:53, Bertrand Marquis wrote:
We need to check for operations like feature or config space read as I do not see how an error can be signaled back to the driver when it is reading a register/
For them we we can simply return 0, as there is no way to send an error.
We will need to check that this is mentioned in the spec. Would be a good idea anyway to have a build time assert checking that this value is not smaller than that as a lot of the code is working on this assumption without checking it.
what about this then ?
diff --git a/include/uapi/linux/virtio_msg.h b/include/uapi/linux/virtio_msg.h index 823bfbd6ecf1..58fca6799e3c 100644 --- a/include/uapi/linux/virtio_msg.h +++ b/include/uapi/linux/virtio_msg.h @@ -171,6 +171,27 @@ struct virtio_msg { __u8 payload[]; } __attribute__((packed));
+static_assert(sizeof(struct virtio_msg) + sizeof(struct get_device_info_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_features) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_features_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct set_features) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_config) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_config_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct set_config) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct set_config_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_device_status_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct set_device_status) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct set_device_status_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_vqueue) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_vqueue_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct set_vqueue) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct reset_vqueue) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_shm) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct get_shm_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct event_config) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct event_avail) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct event_used) < VIRTIO_MSG_MIN_SIZE); + static inline void *virtio_msg_payload(struct virtio_msg *vmsg) { return &vmsg->payload; @@ -218,4 +239,10 @@ struct bus_status { __u8 state; } __attribute__((packed));
+static_assert(sizeof(struct virtio_msg) + sizeof(struct bus_get_devices) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct bus_get_devices_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct bus_event_device) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct bus_ping) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct bus_ping_resp) < VIRTIO_MSG_MIN_SIZE); +static_assert(sizeof(struct virtio_msg) + sizeof(struct bus_status) < VIRTIO_MSG_MIN_SIZE); #endif /* _LINUX_VIRTIO_MSG_H */