On Wed, May 15, 2024 at 06:15:56PM +0400, [email protected] wrote:
> From: Marc-André Lureau <[email protected]>
>
> Commit dfcf74fa ("virtio-gpu: fix scanout migration post-load") broke
> forward/backward version migration. Versioning of nested VMSD structures
> is not straightforward, as the wire format doesn't have nested
> structures versions.
>
> Use the previously introduced check_machine_version() function as a
> field test to ensure proper saving/loading based on the machine version.
> The VMSD.version is irrelevant now.
>
> Fixes: dfcf74fa ("virtio-gpu: fix scanout migration post-load")
> Suggested-by: Peter Xu <[email protected]>
> Signed-off-by: Marc-André Lureau <[email protected]>
I don't get it. Our standard way to do it is:
- add a property (begin name with x- so we don't commit to an API)
- set from compat machinery
- test property value in VMSTATE macros
Big advantage is, it works well with any downstreams
which pick any properties they like.
Why is this not a good fit here?
> ---
> hw/display/virtio-gpu.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
> index ae831b6b3e..b2d8e5faeb 100644
> --- a/hw/display/virtio-gpu.c
> +++ b/hw/display/virtio-gpu.c
> @@ -20,6 +20,7 @@
> #include "trace.h"
> #include "sysemu/dma.h"
> #include "sysemu/sysemu.h"
> +#include "hw/boards.h"
> #include "hw/virtio/virtio.h"
> #include "migration/qemu-file-types.h"
> #include "hw/virtio/virtio-gpu.h"
> @@ -1166,10 +1167,14 @@ static void virtio_gpu_cursor_bh(void *opaque)
> virtio_gpu_handle_cursor(&g->parent_obj.parent_obj, g->cursor_vq);
> }
>
> +static bool machine_check_9_0(void *opaque, int version)
> +{
> + return machine_check_version(9, 0);
> +}
> +
> static const VMStateDescription vmstate_virtio_gpu_scanout = {
> .name = "virtio-gpu-one-scanout",
> - .version_id = 2,
> - .minimum_version_id = 1,
> + .version_id = 1,
> .fields = (const VMStateField[]) {
> VMSTATE_UINT32(resource_id, struct virtio_gpu_scanout),
> VMSTATE_UINT32(width, struct virtio_gpu_scanout),
> @@ -1181,12 +1186,12 @@ static const VMStateDescription
> vmstate_virtio_gpu_scanout = {
> VMSTATE_UINT32(cursor.hot_y, struct virtio_gpu_scanout),
> VMSTATE_UINT32(cursor.pos.x, struct virtio_gpu_scanout),
> VMSTATE_UINT32(cursor.pos.y, struct virtio_gpu_scanout),
> - VMSTATE_UINT32_V(fb.format, struct virtio_gpu_scanout, 2),
> - VMSTATE_UINT32_V(fb.bytes_pp, struct virtio_gpu_scanout, 2),
> - VMSTATE_UINT32_V(fb.width, struct virtio_gpu_scanout, 2),
> - VMSTATE_UINT32_V(fb.height, struct virtio_gpu_scanout, 2),
> - VMSTATE_UINT32_V(fb.stride, struct virtio_gpu_scanout, 2),
> - VMSTATE_UINT32_V(fb.offset, struct virtio_gpu_scanout, 2),
> + VMSTATE_UINT32_TEST(fb.format, struct virtio_gpu_scanout,
> machine_check_9_0),
> + VMSTATE_UINT32_TEST(fb.bytes_pp, struct virtio_gpu_scanout,
> machine_check_9_0),
> + VMSTATE_UINT32_TEST(fb.width, struct virtio_gpu_scanout,
> machine_check_9_0),
> + VMSTATE_UINT32_TEST(fb.height, struct virtio_gpu_scanout,
> machine_check_9_0),
> + VMSTATE_UINT32_TEST(fb.stride, struct virtio_gpu_scanout,
> machine_check_9_0),
> + VMSTATE_UINT32_TEST(fb.offset, struct virtio_gpu_scanout,
> machine_check_9_0),
> VMSTATE_END_OF_LIST()
> },
> };
> --
> 2.41.0.28.gd7d8841f67