From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: "Juan Quintela" <quintela@redhat.com>,
"Peter Xu" <peterx@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Leonardo Bras" <leobras@redhat.com>,
"Steve Sistare" <steven.sistare@oracle.com>
Subject: [PATCH V5 09/12] tests/qtest: option to suspend during migration
Date: Mon, 13 Nov 2023 10:33:57 -0800 [thread overview]
Message-ID: <1699900440-207345-10-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1699900440-207345-1-git-send-email-steven.sistare@oracle.com>
Add an option to suspend the src in a-b-bootblock.S, which puts the guest
in S3 state after one round of writing to memory. The option is enabled by
poking a 1 into the suspend_me word in the boot block prior to starting the
src vm. Generate symbol offsets in a-b-bootblock.h so that the suspend_me
offset is known.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Acked-by: Peter Xu <peterx@redhat.com>
---
tests/migration/i386/Makefile | 5 ++--
tests/migration/i386/a-b-bootblock.S | 50 +++++++++++++++++++++++++++++++++---
tests/migration/i386/a-b-bootblock.h | 26 +++++++++++++------
tests/qtest/migration-test.c | 8 ++++--
4 files changed, 74 insertions(+), 15 deletions(-)
diff --git a/tests/migration/i386/Makefile b/tests/migration/i386/Makefile
index 5c03241..37a72ae 100644
--- a/tests/migration/i386/Makefile
+++ b/tests/migration/i386/Makefile
@@ -4,9 +4,10 @@
.PHONY: all clean
all: a-b-bootblock.h
-a-b-bootblock.h: x86.bootsect
+a-b-bootblock.h: x86.bootsect x86.o
echo "$$__note" > header.tmp
xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
+ nm x86.o | awk '{print "#define SYM_"$$3" 0x"$$1}' >> header.tmp
mv header.tmp $@
x86.bootsect: x86.boot
@@ -16,7 +17,7 @@ x86.boot: x86.o
$(CROSS_PREFIX)objcopy -O binary $< $@
x86.o: a-b-bootblock.S
- $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+ $(CROSS_PREFIX)gcc -I.. -m32 -march=i486 -c $< -o $@
clean:
@rm -rf *.boot *.o *.bootsect
diff --git a/tests/migration/i386/a-b-bootblock.S b/tests/migration/i386/a-b-bootblock.S
index 6bb9999..6f39eb6 100644
--- a/tests/migration/i386/a-b-bootblock.S
+++ b/tests/migration/i386/a-b-bootblock.S
@@ -9,6 +9,23 @@
#
# Author: dgilbert@redhat.com
+#include "migration-test.h"
+
+#define ACPI_ENABLE 0xf1
+#define ACPI_PORT_SMI_CMD 0xb2
+#define ACPI_PM_BASE 0x600
+#define PM1A_CNT_OFFSET 4
+
+#define ACPI_SCI_ENABLE 0x0001
+#define ACPI_SLEEP_TYPE 0x0400
+#define ACPI_SLEEP_ENABLE 0x2000
+#define SLEEP (ACPI_SCI_ENABLE + ACPI_SLEEP_TYPE + ACPI_SLEEP_ENABLE)
+
+#define LOW_ADDR X86_TEST_MEM_START
+#define HIGH_ADDR X86_TEST_MEM_END
+
+/* Save the suspended status at an address that is not written in the loop. */
+#define suspended (X86_TEST_MEM_START + 4)
.code16
.org 0x7c00
@@ -35,8 +52,8 @@ start: # at 0x7c00 ?
mov %eax,%ds
# Start from 1MB
-.set TEST_MEM_START, (1024*1024)
-.set TEST_MEM_END, (100*1024*1024)
+.set TEST_MEM_START, X86_TEST_MEM_START
+.set TEST_MEM_END, X86_TEST_MEM_END
mov $65,%ax
mov $0x3f8,%dx
@@ -69,7 +86,30 @@ innerloop:
mov $0x3f8,%dx
outb %al,%dx
- jmp mainloop
+ # should this test suspend?
+ mov (suspend_me),%eax
+ cmp $0,%eax
+ je mainloop
+
+ # are we waking after suspend? do not suspend again.
+ mov $suspended,%eax
+ mov (%eax),%eax
+ cmp $1,%eax
+ je mainloop
+
+ # enable acpi
+ mov $ACPI_ENABLE,%al
+ outb %al,$ACPI_PORT_SMI_CMD
+
+ # suspend to ram
+ mov $suspended,%eax
+ movl $1,(%eax)
+ mov $SLEEP,%ax
+ mov $(ACPI_PM_BASE + PM1A_CNT_OFFSET),%dx
+ outw %ax,%dx
+ # not reached. The wakeup causes reset and restart at 0x7c00, and we
+ # do not save and restore registers as a real kernel would do.
+
# GDT magic from old (GPLv2) Grub startup.S
.p2align 2 /* force 4-byte alignment */
@@ -95,6 +135,10 @@ gdtdesc:
.word 0x27 /* limit */
.long gdt /* addr */
+ /* test launcher can poke a 1 here to exercise suspend */
+suspend_me:
+ .int 0
+
/* I'm a bootable disk */
.org 0x7dfe
.byte 0x55
diff --git a/tests/migration/i386/a-b-bootblock.h b/tests/migration/i386/a-b-bootblock.h
index 5b52391..c83f871 100644
--- a/tests/migration/i386/a-b-bootblock.h
+++ b/tests/migration/i386/a-b-bootblock.h
@@ -4,7 +4,7 @@
* the header and the assembler differences in your patch submission.
*/
unsigned char x86_bootsect[] = {
- 0xfa, 0x0f, 0x01, 0x16, 0x8c, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00,
+ 0xfa, 0x0f, 0x01, 0x16, 0xb8, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00,
0x0f, 0x22, 0xc0, 0x66, 0xea, 0x20, 0x7c, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x92, 0x0c, 0x02,
0xe6, 0x92, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x8e, 0xd8, 0x66, 0xb8, 0x41,
@@ -13,13 +13,13 @@ unsigned char x86_bootsect[] = {
0x40, 0x06, 0x7c, 0xf1, 0xb8, 0x00, 0x00, 0x10, 0x00, 0xfe, 0x00, 0x05,
0x00, 0x10, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x40, 0x06, 0x7c, 0xf2, 0xfe,
0xc3, 0x80, 0xe3, 0x3f, 0x75, 0xe6, 0x66, 0xb8, 0x42, 0x00, 0x66, 0xba,
- 0xf8, 0x03, 0xee, 0xeb, 0xdb, 0x8d, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00,
- 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00, 0x27, 0x00, 0x74, 0x7c,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xf8, 0x03, 0xee, 0xa1, 0xbe, 0x7c, 0x00, 0x00, 0x83, 0xf8, 0x00, 0x74,
+ 0xd3, 0xb8, 0x04, 0x00, 0x10, 0x00, 0x8b, 0x00, 0x83, 0xf8, 0x01, 0x74,
+ 0xc7, 0xb0, 0xf1, 0xe6, 0xb2, 0xb8, 0x04, 0x00, 0x10, 0x00, 0xc7, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x66, 0xb8, 0x01, 0x24, 0x66, 0xba, 0x04, 0x06,
+ 0x66, 0xef, 0x66, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00, 0xff, 0xff, 0x00, 0x00,
+ 0x00, 0x92, 0xcf, 0x00, 0x27, 0x00, 0xa0, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -49,3 +49,13 @@ unsigned char x86_bootsect[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
};
+#define SYM_do_zero 0x00007c3d
+#define SYM_gdt 0x00007ca0
+#define SYM_gdtdesc 0x00007cb8
+#define SYM_innerloop 0x00007c51
+#define SYM_mainloop 0x00007c4c
+#define SYM_pre_zero 0x00007c38
+#define SYM_start 0x00007c00
+#define SYM_suspend_me 0x00007cbe
+#define SYM_TEST_MEM_END 0x06400000
+#define SYM_TEST_MEM_START 0x00100000
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 59fbbef..bef1430 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -133,7 +133,7 @@ static char *bootpath;
#include "tests/migration/aarch64/a-b-kernel.h"
#include "tests/migration/s390x/a-b-bios.h"
-static void bootfile_create(char *dir)
+static void bootfile_create(char *dir, bool suspend_me)
{
const char *arch = qtest_get_arch();
unsigned char *content;
@@ -143,6 +143,7 @@ static void bootfile_create(char *dir)
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
/* the assembled x86 boot sector should be exactly one sector large */
g_assert(sizeof(x86_bootsect) == 512);
+ x86_bootsect[SYM_suspend_me - SYM_start] = suspend_me;
content = x86_bootsect;
len = sizeof(x86_bootsect);
} else if (g_str_equal(arch, "s390x")) {
@@ -646,6 +647,8 @@ typedef struct {
bool use_dirty_ring;
const char *opts_source;
const char *opts_target;
+ /* suspend the src before migrating to dest. */
+ bool suspend_me;
} MigrateStart;
/*
@@ -767,6 +770,8 @@ static int test_migrate_start(QTestState **from, QTestState **to,
dst_state = (QTestMigrationState) { };
src_state = (QTestMigrationState) { };
+ bootfile_create(tmpfs, args->suspend_me);
+
if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
memory_size = "150M";
@@ -3329,7 +3334,6 @@ int main(int argc, char **argv)
g_get_tmp_dir(), err->message);
}
g_assert(tmpfs);
- bootfile_create(tmpfs);
module_call_init(MODULE_INIT_QOM);
--
1.8.3.1
next prev parent reply other threads:[~2023-11-13 18:35 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 18:33 [PATCH V5 00/12] fix migration of suspended runstate Steve Sistare
2023-11-13 18:33 ` [PATCH V5 01/12] cpus: refactor vm_stop Steve Sistare
2023-11-20 13:22 ` Fabiano Rosas
2023-11-20 19:09 ` Steven Sistare
2023-11-20 19:46 ` Peter Xu
2023-11-20 19:49 ` Steven Sistare
2023-11-20 20:01 ` Fabiano Rosas
2023-11-13 18:33 ` [PATCH V5 02/12] cpus: stop vm in suspended state Steve Sistare
2023-11-20 14:15 ` Fabiano Rosas
2023-11-20 19:10 ` Steven Sistare
2023-11-20 19:59 ` Peter Xu
2023-11-20 20:47 ` Fabiano Rosas
2023-11-20 21:26 ` Steven Sistare
2023-11-20 20:55 ` Steven Sistare
2023-11-20 21:44 ` Peter Xu
2023-11-21 21:21 ` Steven Sistare
2023-11-21 22:47 ` Peter Xu
2023-11-22 9:38 ` Daniel P. Berrangé
2023-11-22 16:21 ` Peter Xu
2023-11-28 13:26 ` Steven Sistare
2023-11-13 18:33 ` [PATCH V5 03/12] cpus: pass runstate to vm_prepare_start Steve Sistare
2023-11-13 18:33 ` [PATCH V5 04/12] cpus: start vm in suspended state Steve Sistare
2023-11-20 17:20 ` Fabiano Rosas
2023-11-13 18:33 ` [PATCH V5 05/12] migration: preserve suspended runstate Steve Sistare
2023-11-20 17:30 ` Fabiano Rosas
2023-11-13 18:33 ` [PATCH V5 06/12] migration: preserve suspended for snapshot Steve Sistare
2023-11-20 18:13 ` Fabiano Rosas
2023-11-20 19:10 ` Steven Sistare
2023-11-13 18:33 ` [PATCH V5 07/12] migration: preserve suspended for bg_migration Steve Sistare
2023-11-20 18:18 ` Fabiano Rosas
2023-11-13 18:33 ` [PATCH V5 08/12] tests/qtest: migration events Steve Sistare
2023-11-13 18:33 ` Steve Sistare [this message]
2023-11-13 18:33 ` [PATCH V5 10/12] tests/qtest: precopy migration with suspend Steve Sistare
2023-11-13 18:33 ` [PATCH V5 11/12] tests/qtest: postcopy " Steve Sistare
2023-11-13 18:34 ` [PATCH V5 12/12] tests/qtest: background " Steve Sistare
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=1699900440-207345-10-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=berrange@redhat.com \
--cc=farosas@suse.de \
--cc=leobras@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=thuth@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).