Fix for crash after migration in virtio-rng on bi-endian targets
PATCH 1/1 Fix for crash after migration in virtio-rng on bi-endian targets
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the assert() in virtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.
The cause is that virtio_rng_load_device() calls virtio_rng_process() which accesses the ring and thus needs the endianness. However, virtio_rng_process() is called via virtio_load() before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.
This patch fixes the bug by moving the virtio_rng_process() after the call to virtio_load(). Better yet would be to convert virtio to use vmsd and have the virtio_rng_process() as a post_load callback, but that's a bigger project for another day.
This is bugfix, and should be considered for the 2.2 branch.
--- hw/virtio/virtio-rng.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
hw/virtio/virtio-rng.c +8 -7
@@ -113,20 +113,22 @@ static void virtio_rng_save(QEMUFile *f, void *opaque)static int virtio_rng_load (QEMUFile *f,void *opaque,int version_id) { +VirtIORNG *vrng = opaque; +int ret; +if (version_id !=1 ) {return -EINVAL ; } -return virtio_load (VIRTIO_DEVICE (opaque), f, version_id); -} + ret =virtio_load (VIRTIO_DEVICE (vrng), f, version_id); +if (ret !=0 ) { +return ret; + } -static int virtio_rng_load_device (VirtIODevice *vdev,QEMUFile *f, -int version_id) -{/* We may have an element ready but couldn't process it due to a quota * limit. Make sure to try again after live migration when the quota may * have been reset. */ -virtio_rng_process (VIRTIO_RNG (vdev)); +virtio_rng_process (vrng);return 0 ; }
@@ -231,7 +233,6 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data) vdc->realize = virtio_rng_device_realize; vdc->unrealize = virtio_rng_device_unrealize; vdc->get_features = get_features; - vdc->load = virtio_rng_load_device; }static void virtio_rng_initfn (Object *obj)
Signature · 1 line
1.9.3
Quoted 10 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.
Quoted 6 lines
The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.
Agreed.
Quoted 6 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.This is bugfix, and should be considered for the 2.2 branch.
This is undoing most of 3902d49e13c2428bd6381cfdf183103ca4477c1f , added Greg to CC list.
Did you try this on x86 guests, or with multiple rng devices?
(keeping context for Greg)
Quoted 39 lines
Signed-off-by David Gibson <[email protected]>--- hw/virtio/virtio-rng.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)hw/virtio/virtio-rng.c +8
-6@@ -113,20 +113,22 @@ static void virtio_rng_save(QEMUFile *f, void *opaque)static int virtio_rng_load (QEMUFile *f,void *opaque,int version_id) { +VirtIORNG *vrng = opaque; +int ret; +if (version_id !=1 ) {return -EINVAL ; } -return virtio_load (VIRTIO_DEVICE (opaque), f, version_id); -} + ret =virtio_load (VIRTIO_DEVICE (vrng), f, version_id); +if (ret !=0 ) { +return ret; + } -static int virtio_rng_load_device (VirtIODevice *vdev,QEMUFile *f, -int version_id) -{/* We may have an element ready but couldn't process it due to a quota * limit. Make sure to try again after live migration when the quota may * have been reset. */ -virtio_rng_process (VIRTIO_RNG (vdev)); +virtio_rng_process (vrng);return 0 ; }
hw/virtio/virtio-rng.c static void virtio_rng_class_init(ObjectClass *klass, void *data) · line 238
Quoted 7 lines
hw/virtio/virtio-rng.c +0
-1@@ -231,7 +233,6 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data) vdc->realize = virtio_rng_device_realize; vdc->unrealize = virtio_rng_device_unrealize; vdc->get_features = get_features; - vdc->load = virtio_rng_load_device; }static void virtio_rng_initfn (Object *obj)
Thanks,
Amit
(actually adding Greg)
Quoted 79 lines · Amit Shah
Quoted 10 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.Quoted 6 lines
The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.Agreed.
Quoted 6 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.This is bugfix, and should be considered for the 2.2 branch.
This is undoing most of
3902d49e13c2428bd6381cfdf183103ca4477c1f, added Greg to CC list.Did you try this on x86 guests, or with multiple rng devices?
(keeping context for Greg)
Quoted 45 lines
Signed-off-by David Gibson <[email protected]>--- hw/virtio/virtio-rng.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)hw/virtio/virtio-rng.c +8
-7@@ -113,20 +113,22 @@ static void virtio_rng_save(QEMUFile *f, void *opaque)static int virtio_rng_load (QEMUFile *f,void *opaque,int version_id) { +VirtIORNG *vrng = opaque; +int ret; +if (version_id !=1 ) {return -EINVAL ; } -return virtio_load (VIRTIO_DEVICE (opaque), f, version_id); -} + ret =virtio_load (VIRTIO_DEVICE (vrng), f, version_id); +if (ret !=0 ) { +return ret; + } -static int virtio_rng_load_device (VirtIODevice *vdev,QEMUFile *f, -int version_id) -{/* We may have an element ready but couldn't process it due to a quota * limit. Make sure to try again after live migration when the quota may * have been reset. */ -virtio_rng_process (VIRTIO_RNG (vdev)); +virtio_rng_process (vrng);return 0 ; }@@ -231,7 +233,6 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data) vdc->realize = virtio_rng_device_realize; vdc->unrealize = virtio_rng_device_unrealize; vdc->get_features = get_features; - vdc->load = virtio_rng_load_device; }
Quoted 6 lines
hw/virtio/virtio-rng.c static void virtio_rng_class_init(ObjectClass *klass, void *data) · line 238
Quoted 1 line
hw/virtio/virtio-rng.c +0
-0static void virtio_rng_initfn (Object *obj)Thanks,
Amit
Amit
Greg Kurz
Reviewed-byQuoted 11 lines · On Thu, 27 Nov 2014 14:38:42 +0530 Amit Shah <[email protected]> wrote:
Quoted 10 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.
Quoted 14 lines
Quoted 6 lines
The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.Agreed.
Quoted 5 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.
I remember discussions on IRC last spring where I agreed I would work on it. :)
Quoted 5 lines
Quoted 1 line
This is bugfix, and should be considered for the 2.2 branch.
This is undoing most of
3902d49e13c2428bd6381cfdf183103ca4477c1f, added Greg to CC list.
This commit is indeed completely wrong: the load callback only makes sense when there's something to read which is obviously not the case here... This is definitely post load stuff :-\
Thanks ! :)
--
Greg
Quoted 56 lines
Did you try this on x86 guests, or with multiple rng devices?
(keeping context for Greg)
Quoted 39 lines
Signed-off-by David Gibson <[email protected]>--- hw/virtio/virtio-rng.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)hw/virtio/virtio-rng.c +8
-6@@ -113,20 +113,22 @@ static void virtio_rng_save(QEMUFile *f, void *opaque)static int virtio_rng_load (QEMUFile *f,void *opaque,int version_id) { +VirtIORNG *vrng = opaque; +int ret; +if (version_id !=1 ) {return -EINVAL ; } -return virtio_load (VIRTIO_DEVICE (opaque), f, version_id); -} + ret =virtio_load (VIRTIO_DEVICE (vrng), f, version_id); +if (ret !=0 ) { +return ret; + } -static int virtio_rng_load_device (VirtIODevice *vdev,QEMUFile *f, -int version_id) -{/* We may have an element ready but couldn't process it due to a quota * limit. Make sure to try again after live migration when the quota may * have been reset. */ -virtio_rng_process (VIRTIO_RNG (vdev)); +virtio_rng_process (vrng);return 0 ; }hw/virtio/virtio-rng.c static void virtio_rng_class_init(ObjectClass *klass, void *data) · line 238
Quoted 7 lines
hw/virtio/virtio-rng.c +0
-1@@ -231,7 +233,6 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data) vdc->realize = virtio_rng_device_realize; vdc->unrealize = virtio_rng_device_unrealize; vdc->get_features = get_features; - vdc->load = virtio_rng_load_device; }static void virtio_rng_initfn (Object *obj)Thanks,
Amit
Quoted 25 lines · Amit Shah
Quoted 10 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.Quoted 6 lines
The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.Agreed.
Quoted 5 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.
Quoted 6 lines
Quoted 1 line
This is bugfix, and should be considered for the 2.2 branch.
This is undoing most of
3902d49e13c2428bd6381cfdf183103ca4477c1f, added Greg to CC list.Did you try this on x86 guests, or with multiple rng devices?
Not so far, I'll see what I can do.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 26 lines · David Gibson
Quoted 25 lines · Amit Shah
Quoted 10 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.Quoted 6 lines
The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.Agreed.
Quoted 5 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
This is bugfix, and should be considered for the 2.2 branch.
This is undoing most of
3902d49e13c2428bd6381cfdf183103ca4477c1f, added Greg to CC list.Did you try this on x86 guests, or with multiple rng devices?
Not so far, I'll see what I can do.
Thanks.
Amit
Quoted 17 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.
Quoted 6 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.This is bugfix, and should be considered for the 2.2 branch.
"[PATCH for-2.2]" would have been a good idea then. Next time :)
Quoted 19 lines · Markus Armbruster
Quoted 17 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.
Quoted 8 lines
Quoted 6 lines
This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.This is bugfix, and should be considered for the 2.2 branch.
"[PATCH for-2.2]" would have been a good idea then. Next time :)
So do you want this patch in 2.2? I was planning to put in the virtio-vs-xen fixes today and tag rc4, so it's not too late if you're confident this patch is good. Let me know if you think it should go in, and I can apply it to master directly.
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This is bugfix, and should be considered for the 2.2 branch.
"[PATCH for-2.2]" would have been a good idea then. Next time :)
So do you want this patch in 2.2? I was planning to put in the virtio-vs-xen fixes today and tag rc4, so it's not too late if you're confident this patch is good. Let me know if you think it should go in, and I can apply it to master directly.
Yes, I think it should be applied.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 27 lines · On Fri, 28 Nov 2014 09:14:46 +0000 Peter Maydell <[email protected]>…
Quoted 26 lines · Markus Armbruster
Quoted 23 lines · David Gibson
VirtIO devices now remember which endianness they're operating in in order to support targets which may have guests of either endianness, such as powerpc. This endianness state is transferred in a subsection of the virtio device's information.
With virtio-rng this can lead to an abort after a loadvm hitting the
assert()invirtio_is_big_endian(). This can be reproduced by doing a migrate and load from file on a bi-endian target with a virtio-rng device. The actual guest state isn't particularly important to triggering this.The cause is that
virtio_rng_load_device()callsvirtio_rng_process()which accesses the ring and thus needs the endianness. However,virtio_rng_process()is called viavirtio_load()before it loads the subsections. Essentially the ->load callback in VirtioDeviceClass should only be used for actually reading the device state from the stream, not for post-load re-initialization.This patch fixes the bug by moving the
virtio_rng_process()after the call tovirtio_load(). Better yet would be to convert virtio to use vmsd and have thevirtio_rng_process()as apost_loadcallback, but that's a bigger project for another day.This is bugfix, and should be considered for the 2.2 branch.
Quoted 9 lines
Quoted 1 line
"[PATCH for-2.2]" would have been a good idea then. Next time :)
So do you want this patch in 2.2? I was planning to put in the virtio-vs-xen fixes today and tag rc4, so it's not too late if you're confident this patch is good. Let me know if you think it should go in, and I can apply it to master directly.
-- PMM
Peter,
FWIW I think it should. Commit 3902d49e13c2428bd6381cfdf183103ca4477c1f is clearly bad: virtio-rng does not need the .load callback obviously... and the fact it breaks migration makes it even worse... :(
Please apply to 2.2.
Cheers.
--
Greg
Peter Maydell
AppliedQuoted 5 lines · Greg Kurz
FWIW I think it should. Commit
3902d49e13c2428bd6381cfdf183103ca4477c1fis clearly bad: virtio-rng does not need the .load callback obviously... and the fact it breaks migration makes it even worse... :(Please apply to 2.2.
Applied to master, thanks.
-- PMM