From b63578bdb50243d05c48c3c94cc58ae446f2eb93 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Thu, 21 Jul 2016 17:54:37 +0200 Subject: [PATCH 1/6] spapr: init CPUState->cpu_index with index relative to core-id It will enshure that cpu_index for a given cpu stays the same regardless of the order cpus has been created/deleted and so it would be possible to migrate QEMU instance with out of order created CPU. Signed-off-by: Igor Mammedov Signed-off-by: David Gibson --- hw/ppc/spapr_cpu_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index c04aaa47d7cd..1f3f4dd1e880 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -307,9 +307,13 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) sc->threads = g_malloc0(size * cc->nr_threads); for (i = 0; i < cc->nr_threads; i++) { char id[32]; + CPUState *cs; + obj = sc->threads + i * size; object_initialize(obj, size, typename); + cs = CPU(obj); + cs->cpu_index = cc->core_id + i; snprintf(id, sizeof(id), "thread[%d]", i); object_property_add_child(OBJECT(sc), id, obj, &local_err); if (local_err) { From 7cdd76132a7daff30cde12ba81684741d50c4f22 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 26 Jul 2016 13:37:20 +1000 Subject: [PATCH 2/6] Revert "spapr: Ensure CPU cores are added contiguously and removed in LIFO order" This reverts commit 5cbc64de25973e9129c5a7897734a06ac64b9aff. Now that we have stable cpu_index values for pseries-2.7 (and future) machine types, we can now safely allow hotplug and unplug in any order. Conflicts: hw/ppc/spapr_cpu_core.c Some conflicts on revert due to some small changes in the inserted code since the original commit. Signed-off-by: David Gibson --- hw/ppc/spapr_cpu_core.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 1f3f4dd1e880..5a132bfa1a14 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -125,7 +125,6 @@ static void spapr_core_release(DeviceState *dev, void *opaque) void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { - sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev)); CPUCore *cc = CPU_CORE(dev); int smt = kvmppc_smt_threads(); int index = cc->core_id / smp_threads; @@ -133,16 +132,7 @@ void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index * smt); sPAPRDRConnectorClass *drck; Error *local_err = NULL; - int spapr_max_cores = max_cpus / smp_threads; - int i; - for (i = spapr_max_cores - 1; i > index; i--) { - if (spapr->cores[i]) { - error_setg(errp, "core-id %d should be removed first", - i * smp_threads); - return; - } - } g_assert(drc); drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); @@ -224,7 +214,7 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(OBJECT(hotplug_dev)); sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev)); int spapr_max_cores = max_cpus / smp_threads; - int index, i; + int index; Error *local_err = NULL; CPUCore *cc = CPU_CORE(dev); char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model); @@ -261,14 +251,6 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, goto out; } - for (i = 0; i < index; i++) { - if (!spapr->cores[i]) { - error_setg(&local_err, "core-id %d should be added first", - i * smp_threads); - goto out; - } - } - out: g_free(base_core_type); error_propagate(errp, local_err); From aaf89c8a49a8c1259b6b181d701070c6df83f3d7 Mon Sep 17 00:00:00 2001 From: "lvivier@redhat.com" Date: Thu, 21 Jul 2016 18:47:56 +0200 Subject: [PATCH 3/6] test: port postcopy test to ppc64 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 9286148432fa..4b5123bdeb1f 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 16465ab57e0a..229e9e901a6a 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'," From bcd510b141eee18b7fcd445f8c9ea3be347d16fc Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Wed, 27 Jul 2016 08:20:55 +1000 Subject: [PATCH 4/6] ppc: Fix fault PC reporting for lve*/stve* VMX instructions We forgot to do gen_update_nip() for these like we do with other helpers. Fix this, but in a more efficient way by passing the RA to the accessors instead so the overhead is only taken on faults. Signed-off-by: Benjamin Herrenschmidt Signed-off-by: David Gibson --- target-ppc/mem_helper.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/target-ppc/mem_helper.c b/target-ppc/mem_helper.c index e4de86bc5e4d..e4ed3773e8fe 100644 --- a/target-ppc/mem_helper.c +++ b/target-ppc/mem_helper.c @@ -232,16 +232,16 @@ target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg, \ if (needs_byteswap(env)) { \ r->element[LO_IDX ? index : (adjust - index)] = \ - swap(access(env, addr)); \ + swap(access(env, addr, GETPC())); \ } else { \ r->element[LO_IDX ? index : (adjust - index)] = \ - access(env, addr); \ + access(env, addr, GETPC()); \ } \ } #define I(x) (x) -LVE(lvebx, cpu_ldub_data, I, u8) -LVE(lvehx, cpu_lduw_data, bswap16, u16) -LVE(lvewx, cpu_ldl_data, bswap32, u32) +LVE(lvebx, cpu_ldub_data_ra, I, u8) +LVE(lvehx, cpu_lduw_data_ra, bswap16, u16) +LVE(lvewx, cpu_ldl_data_ra, bswap32, u32) #undef I #undef LVE @@ -259,16 +259,17 @@ LVE(lvewx, cpu_ldl_data, bswap32, u32) \ if (needs_byteswap(env)) { \ access(env, addr, swap(r->element[LO_IDX ? index : \ - (adjust - index)])); \ + (adjust - index)]), \ + GETPC()); \ } else { \ access(env, addr, r->element[LO_IDX ? index : \ - (adjust - index)]); \ + (adjust - index)], GETPC()); \ } \ } #define I(x) (x) -STVE(stvebx, cpu_stb_data, I, u8) -STVE(stvehx, cpu_stw_data, bswap16, u16) -STVE(stvewx, cpu_stl_data, bswap32, u32) +STVE(stvebx, cpu_stb_data_ra, I, u8) +STVE(stvehx, cpu_stw_data_ra, bswap16, u16) +STVE(stvewx, cpu_stl_data_ra, bswap32, u32) #undef I #undef LVE From 62be8b044adf47327ebefdefb25f28a40316ebd0 Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Wed, 27 Jul 2016 10:44:42 +0530 Subject: [PATCH 5/6] spapr: Prevent boot CPU core removal Boot CPU is assumed to be always present in QEMU code. So until that assumptions are gone, deny removal request. In another words, QEMU won't support boot CPU core hot-unplug. Signed-off-by: Bharata B Rao [dwg: Tweaked error message for clarity] Signed-off-by: David Gibson --- hw/ppc/spapr_cpu_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 5a132bfa1a14..ec81ee60884a 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -133,6 +133,11 @@ void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, sPAPRDRConnectorClass *drck; Error *local_err = NULL; + if (index == 0) { + error_setg(errp, "Boot CPU core may not be unplugged"); + return; + } + g_assert(drc); drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); From 059ce0f00af0124740bcb9991d160f93c92ae174 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Thu, 28 Jul 2016 17:18:09 +0200 Subject: [PATCH 6/6] tests: add drive_del-test to ppc/ppc64 Signed-off-by: Laurent Vivier Signed-off-by: David Gibson --- tests/Makefile.include | 2 ++ tests/drive_del-test.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 4b5123bdeb1f..ebecfa445c82 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -259,6 +259,8 @@ check-qtest-arm-y += tests/virtio-blk-test$(EXESUF) gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c check-qtest-ppc-y += tests/boot-order-test$(EXESUF) check-qtest-ppc64-y += tests/boot-order-test$(EXESUF) +check-qtest-ppc-y += tests/drive_del-test$(EXESUF) +check-qtest-ppc64-y += tests/drive_del-test$(EXESUF) check-qtest-ppc64-y += tests/spapr-phb-test$(EXESUF) gcov-files-ppc64-y += ppc64-softmmu/hw/ppc/spapr_pci.c check-qtest-ppc-y += tests/prom-env-test$(EXESUF) diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c index 74e43c248bdb..121b9c917e84 100644 --- a/tests/drive_del-test.c +++ b/tests/drive_del-test.c @@ -115,7 +115,8 @@ int main(int argc, char **argv) qtest_add_func("/drive_del/without-dev", test_drive_without_dev); /* TODO I guess any arch with PCI would do */ - if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) { + if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64") || + !strcmp(arch, "ppc") || !strcmp(arch, "ppc64")) { qtest_add_func("/drive_del/after_failed_device_add", test_after_failed_device_add); qtest_add_func("/blockdev/drive_del_device_del",