From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: quintela@redhat.com, Peter Lieven <pl@kamp.de>,
dgilbert@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH] migration: catch unknown flag combinations in ram_load
Date: Tue, 24 Jun 2014 11:32:36 +0200 [thread overview]
Message-ID: <1403602356-13687-1-git-send-email-pl@kamp.de> (raw)
this patch extends commit db80fac by not only checking
for unknown flags, but also filtering out unknown flag
combinations.
Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Peter Lieven <pl@kamp.de>
---
arch_init.c | 62 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index 8ddaf35..fb06d07 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1038,8 +1038,7 @@ void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
static int ram_load(QEMUFile *f, void *opaque, int version_id)
{
- ram_addr_t addr;
- int flags, ret = 0;
+ int flags = 0, ret = 0;
static uint64_t seq_iter;
seq_iter++;
@@ -1048,21 +1047,24 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
ret = -EINVAL;
}
- while (!ret) {
- addr = qemu_get_be64(f);
+ while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
+ ram_addr_t addr, total_ram_bytes;
+ void *host;
+ uint8_t ch;
+ addr = qemu_get_be64(f);
flags = addr & ~TARGET_PAGE_MASK;
addr &= TARGET_PAGE_MASK;
- if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
+ switch (flags & ~RAM_SAVE_FLAG_CONTINUE) {
+ case RAM_SAVE_FLAG_MEM_SIZE:
/* Synchronize RAM block list */
- char id[256];
- ram_addr_t length;
- ram_addr_t total_ram_bytes = addr;
-
- while (total_ram_bytes) {
+ total_ram_bytes = addr;
+ while (!ret && total_ram_bytes) {
RAMBlock *block;
uint8_t len;
+ char id[256];
+ ram_addr_t length;
len = qemu_get_byte(f);
qemu_get_buffer(f, (uint8_t *)id, len);
@@ -1086,16 +1088,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
"accept migration", id);
ret = -EINVAL;
}
- if (ret) {
- break;
- }
total_ram_bytes -= length;
}
- } else if (flags & RAM_SAVE_FLAG_COMPRESS) {
- void *host;
- uint8_t ch;
-
+ break;
+ case RAM_SAVE_FLAG_COMPRESS:
host = host_from_stream_offset(f, addr, flags);
if (!host) {
error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
@@ -1105,9 +1102,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
ch = qemu_get_byte(f);
ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
- } else if (flags & RAM_SAVE_FLAG_PAGE) {
- void *host;
-
+ break;
+ case RAM_SAVE_FLAG_PAGE:
host = host_from_stream_offset(f, addr, flags);
if (!host) {
error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
@@ -1116,8 +1112,9 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
}
qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
- } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
- void *host = host_from_stream_offset(f, addr, flags);
+ break;
+ case RAM_SAVE_FLAG_XBZRLE:
+ host = host_from_stream_offset(f, addr, flags);
if (!host) {
error_report("Illegal RAM offset " RAM_ADDR_FMT, addr);
ret = -EINVAL;
@@ -1130,17 +1127,22 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
ret = -EINVAL;
break;
}
- } else if (flags & RAM_SAVE_FLAG_HOOK) {
- ram_control_load_hook(f, flags);
- } else if (flags & RAM_SAVE_FLAG_EOS) {
- /* normal exit */
break;
- } else {
- error_report("Unknown migration flags: %#x", flags);
- ret = -EINVAL;
+ case RAM_SAVE_FLAG_EOS:
+ /* normal exit */
break;
+ default:
+ if (flags & RAM_SAVE_FLAG_HOOK) {
+ ram_control_load_hook(f, flags);
+ } else {
+ error_report("Unknown combination of migration flags: %#x",
+ flags);
+ ret = -EINVAL;
+ }
+ }
+ if (!ret) {
+ ret = qemu_file_get_error(f);
}
- ret = qemu_file_get_error(f);
}
DPRINTF("Completed load of VM with exit code %d seq iteration "
--
1.7.9.5
next reply other threads:[~2014-06-24 9:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 9:32 Peter Lieven [this message]
2014-06-24 15:49 ` [Qemu-devel] [PATCH] migration: catch unknown flag combinations in ram_load Eric Blake
2014-06-25 11:55 ` Juan Quintela
2014-07-08 20:55 ` Peter Lieven
2014-07-09 4:25 ` Amit Shah
2014-07-09 10:28 ` Peter Maydell
2014-07-09 10:44 ` Amit Shah
2014-07-09 10:50 ` Peter Maydell
2014-07-09 10:56 ` Amit Shah
2014-07-09 11:00 ` Peter Maydell
2014-07-09 13:23 ` Peter Lieven
2014-07-09 13:55 ` Eric Blake
2014-07-11 12:52 ` Amit Shah
2014-08-21 21:57 ` Peter Lieven
2014-08-22 3:57 ` Amit Shah
2014-09-02 9:17 ` Peter Lieven
2014-09-23 9:46 ` Paolo Bonzini
2014-09-23 9:51 ` Paolo Bonzini
2014-09-30 6:38 ` Peter Lieven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1403602356-13687-1-git-send-email-pl@kamp.de \
--to=pl@kamp.de \
--cc=amit.shah@redhat.com \
--cc=dgilbert@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).