Received: from eggs.gnu.org ([2001:4830:134:3::10]:49564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQDpk-0007F4-4Y for qemu-devel@nongnu.org; Thu, 21 Jul 2016 09:16:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQDpg-0004lY-V5 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 09:16:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46834) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQDpg-0004lN-N0 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 09:16:08 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EDCC46213 for ; Thu, 21 Jul 2016 13:16:08 +0000 (UTC) References: <1469095928-5816-1-git-send-email-lvivier@redhat.com> From: Thomas Huth Message-ID: <28cbdb75-ff4d-bd3a-95a1-6edbc1379084@redhat.com> Date: Thu, 21 Jul 2016 15:16:05 +0200 MIME-Version: 1.0 In-Reply-To: <1469095928-5816-1-git-send-email-lvivier@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] test: port postcopy test to ppc64 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier , qemu-devel@nongnu.org Cc: dgilbert@redhat.com, dgibson@redhat.com On 21.07.2016 12:12, Laurent Vivier wrote: > As userfaultfd syscall is available on powerpc, migration > postcopy can be used. Good idea to add this test for PPC, too! > 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. >=20 > 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=3D...,if=3Dpflash") I wonder whether we could easily add support for the "-prom-env" parameter for the sPAPR machine, too, since the NVRAM layout seems to be pretty much the same as on the old CHRP Mac machines...? > Signed-off-by: Laurent Vivier > --- > tests/Makefile.include | 1 + > tests/postcopy-test.c | 141 +++++++++++++++++++++++++++++++++++++++++= +------- > 2 files changed, 123 insertions(+), 19 deletions(-) >=20 > diff --git a/tests/Makefile.include b/tests/Makefile.include > index e7e50d6..e2d1885 100644 > --- a/tests/Makefile.include > +++ b/tests/Makefile.include > @@ -268,6 +268,7 @@ check-qtest-sparc-y +=3D tests/prom-env-test$(EXESU= F) > #check-qtest-sparc64-y +=3D tests/prom-env-test$(EXESUF) > check-qtest-microblazeel-y =3D $(check-qtest-microblaze-y) > check-qtest-xtensaeb-y =3D $(check-qtest-xtensa-y) > +check-qtest-ppc64-y +=3D tests/postcopy-test$(EXESUF) > =20 > check-qtest-generic-y +=3D tests/qom-test$(EXESUF) > =20 > diff --git a/tests/postcopy-test.c b/tests/postcopy-test.c > index 16465ab..439afd9 100644 > --- a/tests/postcopy-test.c > +++ b/tests/postcopy-test.c > @@ -19,6 +19,24 @@ > #include "sysemu/char.h" > #include "sysemu/sysemu.h" > =20 > +/* These structures are already defined by OpenBIOS and usable with SL= OF */ > +#define NVRAM_PART_SYSTEM 0x70 > +struct nvpart { > + uint8_t signature; > + uint8_t checksum; > + uint16_t len; /* BE, length divided by 16 */ > + char name[12]; > + char content[0]; IIRC zero-sized arrays are a GCC extension ... for valid C99, it might be better to use "char content[]" instead? > +}; > > +#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */ > + > +/* 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 > + */ > +#define FORTH_BOOTSCRIPT "boot-command=3Dhex .\" _\" begin %x %x do i = c@ 1 + i c! 1000 +loop .\" B\" 0 until" Just a matter of taste, but I somewhat dislike the idea of hiding a string with format parameters in a macro ... I think I'd rather place this string directly into the corresponding sprintf() statement below instead. > const unsigned start_address =3D 1024 * 1024; > const unsigned end_address =3D 100 * 1024 * 1024; > bool got_stop; > @@ -122,6 +140,52 @@ unsigned char bootsect[] =3D { > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa > }; > =20 > +static void init_bootfile_x86(const char *bootpath) > +{ > + FILE *bootfile =3D fopen(bootpath, "wb"); > + > + g_assert_cmpint(fwrite(bootsect, 512, 1, bootfile), =3D=3D, 1); > + fclose(bootfile); > +} > + > +static void nvpart_checksum(struct nvpart *header) > +{ > + unsigned int i, sum; > + uint8_t *tmpptr; > + > + tmpptr =3D (uint8_t *)header; > + sum =3D *tmpptr; > + for (i =3D 0; i < 14; i++) { > + sum +=3D tmpptr[2 + i]; > + sum =3D (sum + ((sum & 0xff00) >> 8)) & 0xff; > + } > + header->checksum =3D sum & 0xff; > +} Have you tried to include openbios_firmware_abi.h instead and use OpenBIOS_finish_partition() here? That would avoid to have this code duplicated. > +static void init_bootfile_ppc(const char *bootpath) > +{ > + FILE *bootfile; > + char buf[MIN_NVRAM_SIZE]; > + struct nvpart *header =3D (struct nvpart *)buf; > + > + memset(buf, 0, MIN_NVRAM_SIZE); > + > + /* Create a "common" partition in nvram to store boot-command prop= erty */ > + > + header->signature =3D NVRAM_PART_SYSTEM; > + memcpy(header->name, "common", 6); > + header->len =3D cpu_to_be16(MIN_NVRAM_SIZE >> 4); > + nvpart_checksum(header); /* can change if we change header->len */ > + > + sprintf(header->content, FORTH_BOOTSCRIPT, end_address, start_addr= ess); > + > + /* Write partition to the NVRAM file */ > + > + bootfile =3D fopen(bootpath, "wb"); > + g_assert_cmpint(fwrite(buf, MIN_NVRAM_SIZE, 1, bootfile), =3D=3D, = 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 +195,31 @@ static void wait_for_serial(const char *side) > { > char *serialpath =3D g_strdup_printf("%s/%s", tmpfs, side); > FILE *serialfile =3D fopen(serialpath, "r"); > + const char *arch =3D qtest_get_arch(); > + int started =3D (strcmp(side, "src_serial") =3D=3D 0 && > + strcmp(arch, "ppc64") =3D=3D 0) ? 0 : 1; > =20 > do { > int readvalue =3D fgetc(serialfile); > =20 > + 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 =3D 1; > + break; > + case EOF: > + fseek(serialfile, 0, SEEK_SET); > + usleep(1000); > + break; > + default: > + break; I think you could remove that default case. > + } > + continue; > + } > switch (readvalue) { > case 'A': > /* Fine */ > @@ -147,6 +232,8 @@ static void wait_for_serial(const char *side) > return; > =20 > case EOF: > + started =3D (strcmp(side, "src_serial") =3D=3D 0 && > + strcmp(arch, "ppc64") =3D=3D 0) ? 0 : 1; I somehow fail to see why is this needed here again? Isn't the initial setup of "started" at the beginning of the function enough? > fseek(serialfile, 0, SEEK_SET); > usleep(1000); > break; > @@ -295,32 +382,48 @@ static void test_migrate(void) > char *uri =3D g_strdup_printf("unix:%s/migsocket", tmpfs); > QTestState *global =3D 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; > =20 > char *bootpath =3D g_strdup_printf("%s/bootsect", tmpfs); > - FILE *bootfile =3D fopen(bootpath, "wb"); > + const char *arch =3D qtest_get_arch(); > =20 > got_stop =3D false; > - g_assert_cmpint(fwrite(bootsect, 512, 1, bootfile), =3D=3D, 1); > - fclose(bootfile); > =20 > - cmd =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 150M" > - " -name pcsource,debug-threads=3Don" > - " -serial file:%s/src_serial" > - " -drive file=3D%s,format=3Draw", > - tmpfs, bootpath); > - from =3D qtest_start(cmd); > - g_free(cmd); > + if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D= 0) { > + init_bootfile_x86(bootpath); > + cmd_src =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 150M" > + " -name pcsource,debug-threads=3Don" > + " -serial file:%s/src_serial" > + " -drive file=3D%s,format=3Draw", > + tmpfs, bootpath); > + cmd_dst =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 150M" > + " -name pcdest,debug-threads=3Don" > + " -serial file:%s/dest_serial" > + " -drive file=3D%s,format=3Draw" > + " -incoming %s", > + tmpfs, bootpath, uri); > + } else if (strcmp(arch, "ppc64") =3D=3D 0) { > + init_bootfile_ppc(bootpath); > + cmd_src =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 256M" > + " -name pcsource,debug-threads=3Don" > + " -serial file:%s/src_serial" > + " -drive file=3D%s,if=3Dpflash,forma= t=3Draw", > + tmpfs, bootpath); > + cmd_dst =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 256M" > + " -name pcdest,debug-threads=3Don" > + " -serial file:%s/dest_serial" > + " -incoming %s", > + tmpfs, uri); > + } else { > + g_assert_not_reached(); > + } > =20 > - cmd =3D g_strdup_printf("-machine accel=3Dkvm:tcg -m 150M" > - " -name pcdest,debug-threads=3Don" > - " -serial file:%s/dest_serial" > - " -drive file=3D%s,format=3Draw" > - " -incoming %s", > - tmpfs, bootpath, uri); > - to =3D qtest_init(cmd); > - g_free(cmd); > + from =3D qtest_start(cmd_src); > + g_free(cmd_src); > + > + to =3D qtest_init(cmd_dst); > + g_free(cmd_dst); > =20 > global_qtest =3D from; > rsp =3D qmp("{ 'execute': 'migrate-set-capabilities'," >=20 Thomas