From patchwork Fri Jul 29 04:53:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 653988 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s0xPF46Cxz9sC4 for ; Fri, 29 Jul 2016 15:00:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.b=QqXGi388; dkim-atps=neutral Received: from localhost ([::1]:57409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSzuB-0006pA-Jw for incoming@patchwork.ozlabs.org; Fri, 29 Jul 2016 01:00:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSzmD-0007tB-NE for qemu-devel@nongnu.org; Fri, 29 Jul 2016 00:52:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSzm5-0002Xz-Nm for qemu-devel@nongnu.org; Fri, 29 Jul 2016 00:52:01 -0400 Received: from ozlabs.org ([103.22.144.67]:41525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSzm5-0002W3-3T; Fri, 29 Jul 2016 00:51:53 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3s0xCV1ggQz9t29; Fri, 29 Jul 2016 14:51:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1469767910; bh=21CyVst+mmj2ZOUizCEkVh8da6zKdkqRA/uP2XnGPv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QqXGi388HzFg1FocChEXaCZuoc8dVVcyWhUkO+EXolITWLZcWYFUVLL38jELWvpSS xpjnELfWEr2otbVSLQfpWGeJauv26GXA7/LaDzg7ZeVv6AMqm9hRA13adBa+4d/xdJ uxop5dPGNouk8oMbamGGRWMp2BGPiMfOSdZ4nMzY= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 29 Jul 2016 14:53:41 +1000 Message-Id: <1469768024-32108-4-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1469768024-32108-1-git-send-email-david@gibson.dropbear.id.au> References: <1469768024-32108-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 3/6] test: port postcopy test to ppc64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "lvivier@redhat.com" , pkrempa@redhat.com, ehabkost@redhat.com, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, imammedo@redhat.com, David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "lvivier@redhat.com" As userfaultfd syscall is available on powerpc, migration postcopy can be used. This patch adds the support needed to test this on powerpc, instead of using a bootsector to run code to modify memory, we use a FORTH script in "boot-command" property. As spapr machine doesn't support "-prom-env" argument (the nvram is initialized by SLOF and not by QEMU), "boot-command" is provided to SLOF via a file mapped nvram (with "-drive file=...,if=pflash") Signed-off-by: Laurent Vivier Signed-off-by: David Gibson --- tests/Makefile.include | 1 + tests/postcopy-test.c | 116 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 98 insertions(+), 19 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 9286148..4b5123b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -268,6 +268,7 @@ check-qtest-sparc-y += tests/prom-env-test$(EXESUF) #check-qtest-sparc64-y += tests/prom-env-test$(EXESUF) check-qtest-microblazeel-y = $(check-qtest-microblaze-y) check-qtest-xtensaeb-y = $(check-qtest-xtensa-y) +check-qtest-ppc64-y += tests/postcopy-test$(EXESUF) check-qtest-generic-y += tests/qom-test$(EXESUF) diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c index 16465ab..229e9e9 100644 --- a/tests/postcopy-test.c +++ b/tests/postcopy-test.c @@ -18,6 +18,9 @@ #include "qemu/sockets.h" #include "sysemu/char.h" #include "sysemu/sysemu.h" +#include "hw/nvram/openbios_firmware_abi.h" + +#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */ const unsigned start_address = 1024 * 1024; const unsigned end_address = 100 * 1024 * 1024; @@ -122,6 +125,44 @@ unsigned char bootsect[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa }; +static void init_bootfile_x86(const char *bootpath) +{ + FILE *bootfile = fopen(bootpath, "wb"); + + g_assert_cmpint(fwrite(bootsect, 512, 1, bootfile), ==, 1); + fclose(bootfile); +} + +static void init_bootfile_ppc(const char *bootpath) +{ + FILE *bootfile; + char buf[MIN_NVRAM_SIZE]; + struct OpenBIOS_nvpart_v1 *header = (struct OpenBIOS_nvpart_v1 *)buf; + + memset(buf, 0, MIN_NVRAM_SIZE); + + /* Create a "common" partition in nvram to store boot-command property */ + + header->signature = OPENBIOS_PART_SYSTEM; + memcpy(header->name, "common", 6); + OpenBIOS_finish_partition(header, MIN_NVRAM_SIZE); + + /* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB, + * so let's modify memory between 1MB and 100MB + * to do like PC bootsector + */ + + sprintf(buf + 16, + "boot-command=hex .\" _\" begin %x %x do i c@ 1 + i c! 1000 +loop " + ".\" B\" 0 until", end_address, start_address); + + /* Write partition to the NVRAM file */ + + bootfile = fopen(bootpath, "wb"); + g_assert_cmpint(fwrite(buf, MIN_NVRAM_SIZE, 1, bootfile), ==, 1); + fclose(bootfile); +} + /* * Wait for some output in the serial output file, * we get an 'A' followed by an endless string of 'B's @@ -131,10 +172,29 @@ static void wait_for_serial(const char *side) { char *serialpath = g_strdup_printf("%s/%s", tmpfs, side); FILE *serialfile = fopen(serialpath, "r"); + const char *arch = qtest_get_arch(); + int started = (strcmp(side, "src_serial") == 0 && + strcmp(arch, "ppc64") == 0) ? 0 : 1; do { int readvalue = fgetc(serialfile); + if (!started) { + /* SLOF prints its banner before starting test, + * to ignore it, mark the start of the test with '_', + * ignore all characters until this marker + */ + switch (readvalue) { + case '_': + started = 1; + break; + case EOF: + fseek(serialfile, 0, SEEK_SET); + usleep(1000); + break; + } + continue; + } switch (readvalue) { case 'A': /* Fine */ @@ -147,6 +207,8 @@ static void wait_for_serial(const char *side) return; case EOF: + started = (strcmp(side, "src_serial") == 0 && + strcmp(arch, "ppc64") == 0) ? 0 : 1; fseek(serialfile, 0, SEEK_SET); usleep(1000); break; @@ -295,32 +357,48 @@ static void test_migrate(void) char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *global = global_qtest, *from, *to; unsigned char dest_byte_a, dest_byte_b, dest_byte_c, dest_byte_d; - gchar *cmd; + gchar *cmd, *cmd_src, *cmd_dst; QDict *rsp; char *bootpath = g_strdup_printf("%s/bootsect", tmpfs); - FILE *bootfile = fopen(bootpath, "wb"); + const char *arch = qtest_get_arch(); got_stop = false; - g_assert_cmpint(fwrite(bootsect, 512, 1, bootfile), ==, 1); - fclose(bootfile); - cmd = g_strdup_printf("-machine accel=kvm:tcg -m 150M" - " -name pcsource,debug-threads=on" - " -serial file:%s/src_serial" - " -drive file=%s,format=raw", - tmpfs, bootpath); - from = qtest_start(cmd); - g_free(cmd); + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + init_bootfile_x86(bootpath); + cmd_src = g_strdup_printf("-machine accel=kvm:tcg -m 150M" + " -name pcsource,debug-threads=on" + " -serial file:%s/src_serial" + " -drive file=%s,format=raw", + tmpfs, bootpath); + cmd_dst = g_strdup_printf("-machine accel=kvm:tcg -m 150M" + " -name pcdest,debug-threads=on" + " -serial file:%s/dest_serial" + " -drive file=%s,format=raw" + " -incoming %s", + tmpfs, bootpath, uri); + } else if (strcmp(arch, "ppc64") == 0) { + init_bootfile_ppc(bootpath); + cmd_src = g_strdup_printf("-machine accel=kvm:tcg -m 256M" + " -name pcsource,debug-threads=on" + " -serial file:%s/src_serial" + " -drive file=%s,if=pflash,format=raw", + tmpfs, bootpath); + cmd_dst = g_strdup_printf("-machine accel=kvm:tcg -m 256M" + " -name pcdest,debug-threads=on" + " -serial file:%s/dest_serial" + " -incoming %s", + tmpfs, uri); + } else { + g_assert_not_reached(); + } - cmd = g_strdup_printf("-machine accel=kvm:tcg -m 150M" - " -name pcdest,debug-threads=on" - " -serial file:%s/dest_serial" - " -drive file=%s,format=raw" - " -incoming %s", - tmpfs, bootpath, uri); - to = qtest_init(cmd); - g_free(cmd); + from = qtest_start(cmd_src); + g_free(cmd_src); + + to = qtest_init(cmd_dst); + g_free(cmd_dst); global_qtest = from; rsp = qmp("{ 'execute': 'migrate-set-capabilities',"