From 9b3a31c745b61758aaa5466a3a9fc0526d409188 Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Thu, 21 Nov 2019 16:56:45 +0000 Subject: [PATCH 01/87] kvm: Reallocate dirty_bmap when we change a slot kvm_set_phys_mem can be called to reallocate a slot by something the guest does (e.g. writing to PAM and other chipset registers). This can happen in the middle of a migration, and if we're unlucky it can now happen between the split 'sync' and 'clear'; the clear asserts if there's no bmap to clear. Recreate the bmap whenever we change the slot, keeping the clear path happy. Typically this is triggered by the guest rebooting during a migrate. Corresponds to: https://bugzilla.redhat.com/show_bug.cgi?id=1772774 https://bugzilla.redhat.com/show_bug.cgi?id=1771032 Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu --- accel/kvm/kvm-all.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index ca00daa2f5..7b9f92d51c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -518,6 +518,27 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) +/* Allocate the dirty bitmap for a slot */ +static void kvm_memslot_init_dirty_bitmap(KVMSlot *mem) +{ + /* + * XXX bad kernel interface alert + * For dirty bitmap, kernel allocates array of size aligned to + * bits-per-long. But for case when the kernel is 64bits and + * the userspace is 32bits, userspace can't align to the same + * bits-per-long, since sizeof(long) is different between kernel + * and user space. This way, userspace will provide buffer which + * may be 4 bytes less than the kernel will use, resulting in + * userspace memory corruption (which is not detectable by valgrind + * too, in most cases). + * So for now, let's align to 64 instead of HOST_LONG_BITS here, in + * a hope that sizeof(long) won't become >8 any time soon. + */ + hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), + /*HOST_LONG_BITS*/ 64) / 8; + mem->dirty_bmap = g_malloc0(bitmap_size); +} + /** * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * @@ -550,23 +571,9 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, goto out; } - /* XXX bad kernel interface alert - * For dirty bitmap, kernel allocates array of size aligned to - * bits-per-long. But for case when the kernel is 64bits and - * the userspace is 32bits, userspace can't align to the same - * bits-per-long, since sizeof(long) is different between kernel - * and user space. This way, userspace will provide buffer which - * may be 4 bytes less than the kernel will use, resulting in - * userspace memory corruption (which is not detectable by valgrind - * too, in most cases). - * So for now, let's align to 64 instead of HOST_LONG_BITS here, in - * a hope that sizeof(long) won't become >8 any time soon. - */ if (!mem->dirty_bmap) { - hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), - /*HOST_LONG_BITS*/ 64) / 8; /* Allocate on the first log_sync, once and for all */ - mem->dirty_bmap = g_malloc0(bitmap_size); + kvm_memslot_init_dirty_bitmap(mem); } d.dirty_bitmap = mem->dirty_bmap; @@ -1067,6 +1074,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->ram = ram; mem->flags = kvm_mem_flags(mr); + if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { + /* + * Reallocate the bmap; it means it doesn't disappear in + * middle of a migrate. + */ + kvm_memslot_init_dirty_bitmap(mem); + } err = kvm_set_user_memory_region(kml, mem, true); if (err) { fprintf(stderr, "%s: error registering slot: %s\n", __func__, From 8443415f9a09b6d95d99f02733eb71ac4f2d574d Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:24 +0100 Subject: [PATCH 02/87] migration-test: Create cmd_soure and cmd_target We are repeating almost everything for each machine while creating the command line for migration. And once for source and another for destination. We start putting there opts_src and opts_dst. Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index a5343fdc66..fbddcf2317 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -557,6 +557,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, const char *opts_dst) { gchar *cmd_src, *cmd_dst; + gchar *cmd_source, *cmd_target; char *bootpath = NULL; char *extra_opts = NULL; char *shmem_path = NULL; @@ -584,16 +585,16 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_src = g_strdup_printf("-machine accel=%s -m 150M" " -name source,debug-threads=on" " -serial file:%s/src_serial" - " -drive file=%s,format=raw %s %s", + " -drive file=%s,format=raw %s", accel, tmpfs, bootpath, - extra_opts ? extra_opts : "", opts_src); + extra_opts ? extra_opts : ""); cmd_dst = g_strdup_printf("-machine accel=%s -m 150M" " -name target,debug-threads=on" " -serial file:%s/dest_serial" " -drive file=%s,format=raw" - " -incoming %s %s %s", + " -incoming %s %s", accel, tmpfs, bootpath, uri, - extra_opts ? extra_opts : "", opts_dst); + extra_opts ? extra_opts : ""); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { @@ -601,15 +602,15 @@ static int test_migrate_start(QTestState **from, QTestState **to, extra_opts = use_shmem ? get_shmem_opts("128M", shmem_path) : NULL; cmd_src = g_strdup_printf("-machine accel=%s -m 128M" " -name source,debug-threads=on" - " -serial file:%s/src_serial -bios %s %s %s", + " -serial file:%s/src_serial -bios %s %s", accel, tmpfs, bootpath, - extra_opts ? extra_opts : "", opts_src); + extra_opts ? extra_opts : ""); cmd_dst = g_strdup_printf("-machine accel=%s -m 128M" " -name target,debug-threads=on" " -serial file:%s/dest_serial -bios %s" - " -incoming %s %s %s", + " -incoming %s %s", accel, tmpfs, bootpath, uri, - extra_opts ? extra_opts : "", opts_dst); + extra_opts ? extra_opts : ""); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { @@ -620,15 +621,14 @@ static int test_migrate_start(QTestState **from, QTestState **to, " -prom-env 'use-nvramrc?=true' -prom-env " "'nvramrc=hex .\" _\" begin %x %x " "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " - "until' %s %s", accel, tmpfs, end_address, - start_address, extra_opts ? extra_opts : "", - opts_src); + "until' %s", accel, tmpfs, end_address, + start_address, extra_opts ? extra_opts : ""); cmd_dst = g_strdup_printf("-machine accel=%s,vsmt=8 -m 256M" " -name target,debug-threads=on" " -serial file:%s/dest_serial" - " -incoming %s %s %s", + " -incoming %s %s", accel, tmpfs, uri, - extra_opts ? extra_opts : "", opts_dst); + extra_opts ? extra_opts : ""); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; @@ -638,16 +638,16 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max " "-name vmsource,debug-threads=on -cpu max " "-m 150M -serial file:%s/src_serial " - "-kernel %s %s %s", + "-kernel %s %s", accel, tmpfs, bootpath, - extra_opts ? extra_opts : "", opts_src); + extra_opts ? extra_opts : ""); cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max " "-name vmdest,debug-threads=on -cpu max " "-m 150M -serial file:%s/dest_serial " "-kernel %s " - "-incoming %s %s %s", + "-incoming %s %s", accel, tmpfs, bootpath, uri, - extra_opts ? extra_opts : "", opts_dst); + extra_opts ? extra_opts : ""); start_address = ARM_TEST_MEM_START; end_address = ARM_TEST_MEM_END; @@ -671,11 +671,17 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_dst = tmp; } - *from = qtest_init(cmd_src); + cmd_source = g_strdup_printf("%s %s", + cmd_src, opts_src); g_free(cmd_src); + *from = qtest_init(cmd_source); + g_free(cmd_source); - *to = qtest_init(cmd_dst); + cmd_target = g_strdup_printf("%s %s", + cmd_dst, opts_dst); g_free(cmd_dst); + *to = qtest_init(cmd_target); + g_free(cmd_target); /* * Remove shmem file immediately to avoid memory leak in test failed case. From 1b0237187182f32049831d39c775c93a27a0b3bf Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:25 +0100 Subject: [PATCH 03/87] migration-test: Move hide_stderr to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index fbddcf2317..0c01ed3543 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -558,6 +558,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, { gchar *cmd_src, *cmd_dst; gchar *cmd_source, *cmd_target; + const gchar *ignore_stderr; char *bootpath = NULL; char *extra_opts = NULL; char *shmem_path = NULL; @@ -661,24 +662,19 @@ static int test_migrate_start(QTestState **from, QTestState **to, g_free(extra_opts); if (hide_stderr) { - gchar *tmp; - tmp = g_strdup_printf("%s 2>/dev/null", cmd_src); - g_free(cmd_src); - cmd_src = tmp; - - tmp = g_strdup_printf("%s 2>/dev/null", cmd_dst); - g_free(cmd_dst); - cmd_dst = tmp; + ignore_stderr = "2>/dev/null"; + } else { + ignore_stderr = ""; } - cmd_source = g_strdup_printf("%s %s", - cmd_src, opts_src); + cmd_source = g_strdup_printf("%s %s %s", + cmd_src, opts_src, ignore_stderr); g_free(cmd_src); *from = qtest_init(cmd_source); g_free(cmd_source); - cmd_target = g_strdup_printf("%s %s", - cmd_dst, opts_dst); + cmd_target = g_strdup_printf("%s %s %s", + cmd_dst, opts_dst, ignore_stderr); g_free(cmd_dst); *to = qtest_init(cmd_target); g_free(cmd_target); From e022c2772e8666d6df8ee4b0b7338e8fd0c3cc6a Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:26 +0100 Subject: [PATCH 04/87] migration-test: Move -machine to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 51 +++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 0c01ed3543..5a63158872 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -563,7 +563,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, char *extra_opts = NULL; char *shmem_path = NULL; const char *arch = qtest_get_arch(); - const char *accel = "kvm:tcg"; + const char *machine_type; + const char *machine_args; opts_src = opts_src ? opts_src : ""; opts_dst = opts_dst ? opts_dst : ""; @@ -582,72 +583,78 @@ static int test_migrate_start(QTestState **from, QTestState **to, /* the assembled x86 boot sector should be exactly one sector large */ assert(sizeof(x86_bootsect) == 512); init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect)); + machine_type = ""; + machine_args = ""; extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine accel=%s -m 150M" + cmd_src = g_strdup_printf("-m 150M" " -name source,debug-threads=on" " -serial file:%s/src_serial" " -drive file=%s,format=raw %s", - accel, tmpfs, bootpath, + tmpfs, bootpath, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-machine accel=%s -m 150M" + cmd_dst = g_strdup_printf("-m 150M" " -name target,debug-threads=on" " -serial file:%s/dest_serial" " -drive file=%s,format=raw" " -incoming %s %s", - accel, tmpfs, bootpath, uri, + tmpfs, bootpath, uri, extra_opts ? extra_opts : ""); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf)); + machine_type = ""; + machine_args = ""; extra_opts = use_shmem ? get_shmem_opts("128M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine accel=%s -m 128M" + cmd_src = g_strdup_printf("-m 128M" " -name source,debug-threads=on" " -serial file:%s/src_serial -bios %s %s", - accel, tmpfs, bootpath, + tmpfs, bootpath, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-machine accel=%s -m 128M" + cmd_dst = g_strdup_printf("-m 128M" " -name target,debug-threads=on" " -serial file:%s/dest_serial -bios %s" " -incoming %s %s", - accel, tmpfs, bootpath, uri, + tmpfs, bootpath, uri, extra_opts ? extra_opts : ""); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { + machine_type = ""; + machine_args = ",vsmt=8"; extra_opts = use_shmem ? get_shmem_opts("256M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine accel=%s,vsmt=8 -m 256M -nodefaults" + cmd_src = g_strdup_printf("-m 256M -nodefaults" " -name source,debug-threads=on" " -serial file:%s/src_serial" " -prom-env 'use-nvramrc?=true' -prom-env " "'nvramrc=hex .\" _\" begin %x %x " "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " - "until' %s", accel, tmpfs, end_address, + "until' %s", tmpfs, end_address, start_address, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-machine accel=%s,vsmt=8 -m 256M" + cmd_dst = g_strdup_printf("-m 256M" " -name target,debug-threads=on" " -serial file:%s/dest_serial" " -incoming %s %s", - accel, tmpfs, uri, + tmpfs, uri, extra_opts ? extra_opts : ""); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") == 0) { init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel)); + machine_type = "virt,"; + machine_args = "gic-version=max"; extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max " - "-name vmsource,debug-threads=on -cpu max " + cmd_src = g_strdup_printf("-name vmsource,debug-threads=on -cpu max " "-m 150M -serial file:%s/src_serial " "-kernel %s %s", - accel, tmpfs, bootpath, + tmpfs, bootpath, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max " - "-name vmdest,debug-threads=on -cpu max " + cmd_dst = g_strdup_printf("-name vmdest,debug-threads=on -cpu max " "-m 150M -serial file:%s/dest_serial " "-kernel %s " "-incoming %s %s", - accel, tmpfs, bootpath, uri, + tmpfs, bootpath, uri, extra_opts ? extra_opts : ""); start_address = ARM_TEST_MEM_START; @@ -667,13 +674,15 @@ static int test_migrate_start(QTestState **from, QTestState **to, ignore_stderr = ""; } - cmd_source = g_strdup_printf("%s %s %s", + cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s %s %s %s", + machine_type, machine_args, cmd_src, opts_src, ignore_stderr); g_free(cmd_src); *from = qtest_init(cmd_source); g_free(cmd_source); - cmd_target = g_strdup_printf("%s %s %s", + cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s %s %s %s", + machine_type, machine_args, cmd_dst, opts_dst, ignore_stderr); g_free(cmd_dst); *to = qtest_init(cmd_target); From 7b6d44cb811b987759889c7b2570dd9fe0079b4c Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:27 +0100 Subject: [PATCH 05/87] migration-test: Move memory size to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 5a63158872..9d40f2d30c 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -565,6 +565,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, const char *arch = qtest_get_arch(); const char *machine_type; const char *machine_args; + const char *memory_size; opts_src = opts_src ? opts_src : ""; opts_dst = opts_dst ? opts_dst : ""; @@ -585,15 +586,14 @@ static int test_migrate_start(QTestState **from, QTestState **to, init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect)); machine_type = ""; machine_args = ""; - extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-m 150M" - " -name source,debug-threads=on" + memory_size = "150M"; + extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; + cmd_src = g_strdup_printf(" -name source,debug-threads=on" " -serial file:%s/src_serial" " -drive file=%s,format=raw %s", tmpfs, bootpath, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-m 150M" - " -name target,debug-threads=on" + cmd_dst = g_strdup_printf(" -name target,debug-threads=on" " -serial file:%s/dest_serial" " -drive file=%s,format=raw" " -incoming %s %s", @@ -605,14 +605,13 @@ static int test_migrate_start(QTestState **from, QTestState **to, init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf)); machine_type = ""; machine_args = ""; - extra_opts = use_shmem ? get_shmem_opts("128M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-m 128M" - " -name source,debug-threads=on" + memory_size = "128M"; + extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; + cmd_src = g_strdup_printf(" -name source,debug-threads=on" " -serial file:%s/src_serial -bios %s %s", tmpfs, bootpath, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-m 128M" - " -name target,debug-threads=on" + cmd_dst = g_strdup_printf(" -name target,debug-threads=on" " -serial file:%s/dest_serial -bios %s" " -incoming %s %s", tmpfs, bootpath, uri, @@ -622,8 +621,9 @@ static int test_migrate_start(QTestState **from, QTestState **to, } else if (strcmp(arch, "ppc64") == 0) { machine_type = ""; machine_args = ",vsmt=8"; - extra_opts = use_shmem ? get_shmem_opts("256M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-m 256M -nodefaults" + memory_size = "256M"; + extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; + cmd_src = g_strdup_printf("-nodefaults" " -name source,debug-threads=on" " -serial file:%s/src_serial" " -prom-env 'use-nvramrc?=true' -prom-env " @@ -631,8 +631,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " "until' %s", tmpfs, end_address, start_address, extra_opts ? extra_opts : ""); - cmd_dst = g_strdup_printf("-m 256M" - " -name target,debug-threads=on" + cmd_dst = g_strdup_printf(" -name target,debug-threads=on" " -serial file:%s/dest_serial" " -incoming %s %s", tmpfs, uri, @@ -644,14 +643,15 @@ static int test_migrate_start(QTestState **from, QTestState **to, init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel)); machine_type = "virt,"; machine_args = "gic-version=max"; - extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL; + memory_size = "150M"; + extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; cmd_src = g_strdup_printf("-name vmsource,debug-threads=on -cpu max " - "-m 150M -serial file:%s/src_serial " + "-serial file:%s/src_serial " "-kernel %s %s", tmpfs, bootpath, extra_opts ? extra_opts : ""); cmd_dst = g_strdup_printf("-name vmdest,debug-threads=on -cpu max " - "-m 150M -serial file:%s/dest_serial " + "-serial file:%s/dest_serial " "-kernel %s " "-incoming %s %s", tmpfs, bootpath, uri, @@ -674,15 +674,21 @@ static int test_migrate_start(QTestState **from, QTestState **to, ignore_stderr = ""; } - cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s %s %s %s", + cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s " + "-m %s " + "%s %s %s", machine_type, machine_args, + memory_size, cmd_src, opts_src, ignore_stderr); g_free(cmd_src); *from = qtest_init(cmd_source); g_free(cmd_source); - cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s %s %s %s", + cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s " + "-m %s " + "%s %s %s", machine_type, machine_args, + memory_size, cmd_dst, opts_dst, ignore_stderr); g_free(cmd_dst); *to = qtest_init(cmd_target); From 3ed375e7feff0587d9f370836069951b7df88848 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:28 +0100 Subject: [PATCH 06/87] migration-test: Move shmem handling to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 76 +++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 9d40f2d30c..e17d432043 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -380,13 +380,6 @@ static void cleanup(const char *filename) g_free(path); } -static char *get_shmem_opts(const char *mem_size, const char *shmem_path) -{ - return g_strdup_printf("-object memory-backend-file,id=mem0,size=%s" - ",mem-path=%s,share=on -numa node,memdev=mem0", - mem_size, shmem_path); -} - static char *SocketAddress_to_str(SocketAddress *addr) { switch (addr->type) { @@ -560,8 +553,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, gchar *cmd_source, *cmd_target; const gchar *ignore_stderr; char *bootpath = NULL; - char *extra_opts = NULL; - char *shmem_path = NULL; + char *shmem_opts; + char *shmem_path; const char *arch = qtest_get_arch(); const char *machine_type; const char *machine_args; @@ -575,7 +568,6 @@ static int test_migrate_start(QTestState **from, QTestState **to, g_test_skip("/dev/shm is not supported"); return -1; } - shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid()); } got_stop = false; @@ -587,18 +579,15 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "150M"; - extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; cmd_src = g_strdup_printf(" -name source,debug-threads=on" " -serial file:%s/src_serial" - " -drive file=%s,format=raw %s", - tmpfs, bootpath, - extra_opts ? extra_opts : ""); + " -drive file=%s,format=raw", + tmpfs, bootpath); cmd_dst = g_strdup_printf(" -name target,debug-threads=on" " -serial file:%s/dest_serial" " -drive file=%s,format=raw" - " -incoming %s %s", - tmpfs, bootpath, uri, - extra_opts ? extra_opts : ""); + " -incoming %s", + tmpfs, bootpath, uri); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { @@ -606,36 +595,31 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "128M"; - extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; cmd_src = g_strdup_printf(" -name source,debug-threads=on" - " -serial file:%s/src_serial -bios %s %s", - tmpfs, bootpath, - extra_opts ? extra_opts : ""); + " -serial file:%s/src_serial -bios %s", + tmpfs, bootpath); cmd_dst = g_strdup_printf(" -name target,debug-threads=on" " -serial file:%s/dest_serial -bios %s" - " -incoming %s %s", - tmpfs, bootpath, uri, - extra_opts ? extra_opts : ""); + " -incoming %s", + tmpfs, bootpath, uri); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { machine_type = ""; machine_args = ",vsmt=8"; memory_size = "256M"; - extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; cmd_src = g_strdup_printf("-nodefaults" " -name source,debug-threads=on" " -serial file:%s/src_serial" " -prom-env 'use-nvramrc?=true' -prom-env " "'nvramrc=hex .\" _\" begin %x %x " "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " - "until' %s", tmpfs, end_address, - start_address, extra_opts ? extra_opts : ""); + "until'", tmpfs, end_address, + start_address); cmd_dst = g_strdup_printf(" -name target,debug-threads=on" " -serial file:%s/dest_serial" - " -incoming %s %s", - tmpfs, uri, - extra_opts ? extra_opts : ""); + " -incoming %s", + tmpfs, uri); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; @@ -644,18 +628,15 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = "virt,"; machine_args = "gic-version=max"; memory_size = "150M"; - extra_opts = use_shmem ? get_shmem_opts(memory_size, shmem_path) : NULL; cmd_src = g_strdup_printf("-name vmsource,debug-threads=on -cpu max " "-serial file:%s/src_serial " - "-kernel %s %s", - tmpfs, bootpath, - extra_opts ? extra_opts : ""); + "-kernel %s", + tmpfs, bootpath); cmd_dst = g_strdup_printf("-name vmdest,debug-threads=on -cpu max " "-serial file:%s/dest_serial " "-kernel %s " - "-incoming %s %s", - tmpfs, bootpath, uri, - extra_opts ? extra_opts : ""); + "-incoming %s", + tmpfs, bootpath, uri); start_address = ARM_TEST_MEM_START; end_address = ARM_TEST_MEM_END; @@ -666,7 +647,6 @@ static int test_migrate_start(QTestState **from, QTestState **to, } g_free(bootpath); - g_free(extra_opts); if (hide_stderr) { ignore_stderr = "2>/dev/null"; @@ -674,26 +654,38 @@ static int test_migrate_start(QTestState **from, QTestState **to, ignore_stderr = ""; } + if (use_shmem) { + shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid()); + shmem_opts = g_strdup_printf( + "-object memory-backend-file,id=mem0,size=%s" + ",mem-path=%s,share=on -numa node,memdev=mem0", + memory_size, shmem_path); + } else { + shmem_path = NULL; + shmem_opts = g_strdup(""); + } + cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s " "-m %s " - "%s %s %s", + "%s %s %s %s", machine_type, machine_args, memory_size, - cmd_src, opts_src, ignore_stderr); + cmd_src, shmem_opts, opts_src, ignore_stderr); g_free(cmd_src); *from = qtest_init(cmd_source); g_free(cmd_source); cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s " "-m %s " - "%s %s %s", + "%s %s %s %s", machine_type, machine_args, memory_size, - cmd_dst, opts_dst, ignore_stderr); + cmd_dst, shmem_opts, opts_dst, ignore_stderr); g_free(cmd_dst); *to = qtest_init(cmd_target); g_free(cmd_target); + g_free(shmem_opts); /* * Remove shmem file immediately to avoid memory leak in test failed case. * It's valid becase QEMU has already opened this file From d6b4326714e852a1bca9cfc9902ab6fd7a1d2956 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:29 +0100 Subject: [PATCH 07/87] migration-test: Move -name handling to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index e17d432043..6e828fbc6c 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -579,12 +579,10 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "150M"; - cmd_src = g_strdup_printf(" -name source,debug-threads=on" - " -serial file:%s/src_serial" + cmd_src = g_strdup_printf(" -serial file:%s/src_serial" " -drive file=%s,format=raw", tmpfs, bootpath); - cmd_dst = g_strdup_printf(" -name target,debug-threads=on" - " -serial file:%s/dest_serial" + cmd_dst = g_strdup_printf(" -serial file:%s/dest_serial" " -drive file=%s,format=raw" " -incoming %s", tmpfs, bootpath, uri); @@ -595,11 +593,9 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "128M"; - cmd_src = g_strdup_printf(" -name source,debug-threads=on" - " -serial file:%s/src_serial -bios %s", + cmd_src = g_strdup_printf(" -serial file:%s/src_serial -bios %s", tmpfs, bootpath); - cmd_dst = g_strdup_printf(" -name target,debug-threads=on" - " -serial file:%s/dest_serial -bios %s" + cmd_dst = g_strdup_printf(" -serial file:%s/dest_serial -bios %s" " -incoming %s", tmpfs, bootpath, uri); start_address = S390_TEST_MEM_START; @@ -609,15 +605,13 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_args = ",vsmt=8"; memory_size = "256M"; cmd_src = g_strdup_printf("-nodefaults" - " -name source,debug-threads=on" " -serial file:%s/src_serial" " -prom-env 'use-nvramrc?=true' -prom-env " "'nvramrc=hex .\" _\" begin %x %x " "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " "until'", tmpfs, end_address, start_address); - cmd_dst = g_strdup_printf(" -name target,debug-threads=on" - " -serial file:%s/dest_serial" + cmd_dst = g_strdup_printf(" -serial file:%s/dest_serial" " -incoming %s", tmpfs, uri); @@ -628,11 +622,11 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = "virt,"; machine_args = "gic-version=max"; memory_size = "150M"; - cmd_src = g_strdup_printf("-name vmsource,debug-threads=on -cpu max " + cmd_src = g_strdup_printf("-cpu max " "-serial file:%s/src_serial " "-kernel %s", tmpfs, bootpath); - cmd_dst = g_strdup_printf("-name vmdest,debug-threads=on -cpu max " + cmd_dst = g_strdup_printf("-cpu max " "-serial file:%s/dest_serial " "-kernel %s " "-incoming %s", @@ -666,6 +660,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, } cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s " + "-name source,debug-threads=on " "-m %s " "%s %s %s %s", machine_type, machine_args, @@ -676,6 +671,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, g_free(cmd_source); cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s " + "-name target,debug-threads=on " "-m %s " "%s %s %s %s", machine_type, machine_args, From c5f40ff9f693e56ad7358a41b46dd01d27ad64e7 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:30 +0100 Subject: [PATCH 08/87] migration-test: Move -serial handling to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 6e828fbc6c..e1304d70fc 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -579,13 +579,10 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "150M"; - cmd_src = g_strdup_printf(" -serial file:%s/src_serial" - " -drive file=%s,format=raw", - tmpfs, bootpath); - cmd_dst = g_strdup_printf(" -serial file:%s/dest_serial" - " -drive file=%s,format=raw" + cmd_src = g_strdup_printf("-drive file=%s,format=raw", bootpath); + cmd_dst = g_strdup_printf("-drive file=%s,format=raw" " -incoming %s", - tmpfs, bootpath, uri); + bootpath, uri); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { @@ -593,28 +590,22 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "128M"; - cmd_src = g_strdup_printf(" -serial file:%s/src_serial -bios %s", - tmpfs, bootpath); - cmd_dst = g_strdup_printf(" -serial file:%s/dest_serial -bios %s" + cmd_src = g_strdup_printf("-bios %s", bootpath); + cmd_dst = g_strdup_printf("-bios %s" " -incoming %s", - tmpfs, bootpath, uri); + bootpath, uri); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { machine_type = ""; machine_args = ",vsmt=8"; memory_size = "256M"; - cmd_src = g_strdup_printf("-nodefaults" - " -serial file:%s/src_serial" - " -prom-env 'use-nvramrc?=true' -prom-env " + cmd_src = g_strdup_printf("-nodefaults " + "-prom-env 'use-nvramrc?=true' -prom-env " "'nvramrc=hex .\" _\" begin %x %x " "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " - "until'", tmpfs, end_address, - start_address); - cmd_dst = g_strdup_printf(" -serial file:%s/dest_serial" - " -incoming %s", - tmpfs, uri); - + "until'", end_address, start_address); + cmd_dst = g_strdup_printf(" -incoming %s", uri); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") == 0) { @@ -623,14 +614,12 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_args = "gic-version=max"; memory_size = "150M"; cmd_src = g_strdup_printf("-cpu max " - "-serial file:%s/src_serial " "-kernel %s", - tmpfs, bootpath); + bootpath); cmd_dst = g_strdup_printf("-cpu max " - "-serial file:%s/dest_serial " "-kernel %s " "-incoming %s", - tmpfs, bootpath, uri); + bootpath, uri); start_address = ARM_TEST_MEM_START; end_address = ARM_TEST_MEM_END; @@ -661,10 +650,11 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s " "-name source,debug-threads=on " + "-serial file:%s/src_serial " "-m %s " "%s %s %s %s", machine_type, machine_args, - memory_size, + tmpfs, memory_size, cmd_src, shmem_opts, opts_src, ignore_stderr); g_free(cmd_src); *from = qtest_init(cmd_source); @@ -673,9 +663,10 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s " "-name target,debug-threads=on " "-m %s " + "-serial file:%s/dest_serial " "%s %s %s %s", machine_type, machine_args, - memory_size, + tmpfs, memory_size, cmd_dst, shmem_opts, opts_dst, ignore_stderr); g_free(cmd_dst); *to = qtest_init(cmd_target); From cd49673155a7cf4be879d1451c183a836347ee30 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:31 +0100 Subject: [PATCH 09/87] migration-test: Move -incomming handling to common commandline Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index e1304d70fc..14f2ce30fb 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -580,9 +580,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_args = ""; memory_size = "150M"; cmd_src = g_strdup_printf("-drive file=%s,format=raw", bootpath); - cmd_dst = g_strdup_printf("-drive file=%s,format=raw" - " -incoming %s", - bootpath, uri); + cmd_dst = g_strdup(cmd_src); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { @@ -591,9 +589,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_args = ""; memory_size = "128M"; cmd_src = g_strdup_printf("-bios %s", bootpath); - cmd_dst = g_strdup_printf("-bios %s" - " -incoming %s", - bootpath, uri); + cmd_dst = g_strdup(cmd_src); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { @@ -605,7 +601,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, "'nvramrc=hex .\" _\" begin %x %x " "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " "until'", end_address, start_address); - cmd_dst = g_strdup_printf(" -incoming %s", uri); + cmd_dst = g_strdup(""); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") == 0) { @@ -616,11 +612,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_src = g_strdup_printf("-cpu max " "-kernel %s", bootpath); - cmd_dst = g_strdup_printf("-cpu max " - "-kernel %s " - "-incoming %s", - bootpath, uri); - + cmd_dst = g_strdup(cmd_src); start_address = ARM_TEST_MEM_START; end_address = ARM_TEST_MEM_END; @@ -650,11 +642,11 @@ static int test_migrate_start(QTestState **from, QTestState **to, cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s " "-name source,debug-threads=on " - "-serial file:%s/src_serial " "-m %s " + "-serial file:%s/src_serial " "%s %s %s %s", machine_type, machine_args, - tmpfs, memory_size, + memory_size, tmpfs, cmd_src, shmem_opts, opts_src, ignore_stderr); g_free(cmd_src); *from = qtest_init(cmd_source); @@ -664,9 +656,10 @@ static int test_migrate_start(QTestState **from, QTestState **to, "-name target,debug-threads=on " "-m %s " "-serial file:%s/dest_serial " + "-incoming %s " "%s %s %s %s", machine_type, machine_args, - tmpfs, memory_size, + memory_size, tmpfs, uri, cmd_dst, shmem_opts, opts_dst, ignore_stderr); g_free(cmd_dst); *to = qtest_init(cmd_target); From 68d956092f156ad74e4f75437de626af6192fb71 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:32 +0100 Subject: [PATCH 10/87] migration-test: Rename cmd_src/dst to arch_source/arch_target This explains better what they do and avoid confussino with command_src/target. Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 14f2ce30fb..37e9663ab4 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -549,7 +549,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, bool use_shmem, const char *opts_src, const char *opts_dst) { - gchar *cmd_src, *cmd_dst; + gchar *arch_source, *arch_target; gchar *cmd_source, *cmd_target; const gchar *ignore_stderr; char *bootpath = NULL; @@ -579,8 +579,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "150M"; - cmd_src = g_strdup_printf("-drive file=%s,format=raw", bootpath); - cmd_dst = g_strdup(cmd_src); + arch_source = g_strdup_printf("-drive file=%s,format=raw", bootpath); + arch_target = g_strdup(arch_source); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { @@ -588,20 +588,20 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = ""; machine_args = ""; memory_size = "128M"; - cmd_src = g_strdup_printf("-bios %s", bootpath); - cmd_dst = g_strdup(cmd_src); + arch_source = g_strdup_printf("-bios %s", bootpath); + arch_target = g_strdup(arch_source); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { machine_type = ""; machine_args = ",vsmt=8"; memory_size = "256M"; - cmd_src = g_strdup_printf("-nodefaults " - "-prom-env 'use-nvramrc?=true' -prom-env " - "'nvramrc=hex .\" _\" begin %x %x " - "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " - "until'", end_address, start_address); - cmd_dst = g_strdup(""); + arch_source = g_strdup_printf("-nodefaults " + "-prom-env 'use-nvramrc?=true' -prom-env " + "'nvramrc=hex .\" _\" begin %x %x " + "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " + "until'", end_address, start_address); + arch_target = g_strdup(""); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") == 0) { @@ -609,10 +609,10 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_type = "virt,"; machine_args = "gic-version=max"; memory_size = "150M"; - cmd_src = g_strdup_printf("-cpu max " - "-kernel %s", - bootpath); - cmd_dst = g_strdup(cmd_src); + arch_source = g_strdup_printf("-cpu max " + "-kernel %s", + bootpath); + arch_target = g_strdup(arch_source); start_address = ARM_TEST_MEM_START; end_address = ARM_TEST_MEM_END; @@ -647,8 +647,9 @@ static int test_migrate_start(QTestState **from, QTestState **to, "%s %s %s %s", machine_type, machine_args, memory_size, tmpfs, - cmd_src, shmem_opts, opts_src, ignore_stderr); - g_free(cmd_src); + arch_source, shmem_opts, opts_src, + ignore_stderr); + g_free(arch_source); *from = qtest_init(cmd_source); g_free(cmd_source); @@ -660,8 +661,9 @@ static int test_migrate_start(QTestState **from, QTestState **to, "%s %s %s %s", machine_type, machine_args, memory_size, tmpfs, uri, - cmd_dst, shmem_opts, opts_dst, ignore_stderr); - g_free(cmd_dst); + arch_target, shmem_opts, opts_dst, + ignore_stderr); + g_free(arch_target); *to = qtest_init(cmd_target); g_free(cmd_target); From 5d3b575da64ed3f45952218ab5d3bd9985f35941 Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Thu, 12 Dec 2019 23:20:33 +0100 Subject: [PATCH 11/87] migration-test: Use a struct for test_migrate_start parameters It has two bools and two strings, it is very difficult to remember which does what. And it makes very difficult to add new parameters as we need to modify all the callers. Signed-off-by: Juan Quintela Tested-by: Cornelia Huck #s390x Tested-by: Laurent Vivier --- tests/migration-test.c | 118 +++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 40 deletions(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index 37e9663ab4..dbe25b8d7c 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -544,10 +544,31 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to) qtest_qmp_eventwait(to, "RESUME"); } +typedef struct { + bool hide_stderr; + bool use_shmem; + char *opts_source; + char *opts_target; +} MigrateStart; + +static MigrateStart *migrate_start_new(void) +{ + MigrateStart *args = g_new0(MigrateStart, 1); + + args->opts_source = g_strdup(""); + args->opts_target = g_strdup(""); + return args; +} + +static void migrate_start_destroy(MigrateStart *args) +{ + g_free(args->opts_source); + g_free(args->opts_target); + g_free(args); +} + static int test_migrate_start(QTestState **from, QTestState **to, - const char *uri, bool hide_stderr, - bool use_shmem, const char *opts_src, - const char *opts_dst) + const char *uri, MigrateStart *args) { gchar *arch_source, *arch_target; gchar *cmd_source, *cmd_target; @@ -560,10 +581,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, const char *machine_args; const char *memory_size; - opts_src = opts_src ? opts_src : ""; - opts_dst = opts_dst ? opts_dst : ""; - - if (use_shmem) { + if (args->use_shmem) { if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) { g_test_skip("/dev/shm is not supported"); return -1; @@ -623,13 +641,13 @@ static int test_migrate_start(QTestState **from, QTestState **to, g_free(bootpath); - if (hide_stderr) { + if (args->hide_stderr) { ignore_stderr = "2>/dev/null"; } else { ignore_stderr = ""; } - if (use_shmem) { + if (args->use_shmem) { shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid()); shmem_opts = g_strdup_printf( "-object memory-backend-file,id=mem0,size=%s" @@ -647,7 +665,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, "%s %s %s %s", machine_type, machine_args, memory_size, tmpfs, - arch_source, shmem_opts, opts_src, + arch_source, shmem_opts, args->opts_source, ignore_stderr); g_free(arch_source); *from = qtest_init(cmd_source); @@ -661,8 +679,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, "%s %s %s %s", machine_type, machine_args, memory_size, tmpfs, uri, - arch_target, shmem_opts, opts_dst, - ignore_stderr); + arch_target, shmem_opts, + args->opts_target, ignore_stderr); g_free(arch_target); *to = qtest_init(cmd_target); g_free(cmd_target); @@ -672,11 +690,12 @@ static int test_migrate_start(QTestState **from, QTestState **to, * Remove shmem file immediately to avoid memory leak in test failed case. * It's valid becase QEMU has already opened this file */ - if (use_shmem) { + if (args->use_shmem) { unlink(shmem_path); g_free(shmem_path); } + migrate_start_destroy(args); return 0; } @@ -762,13 +781,13 @@ static void test_deprecated(void) } static int migrate_postcopy_prepare(QTestState **from_ptr, - QTestState **to_ptr, - bool hide_error) + QTestState **to_ptr, + MigrateStart *args) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, hide_error, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return -1; } @@ -813,9 +832,10 @@ static void migrate_postcopy_complete(QTestState *from, QTestState *to) static void test_postcopy(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (migrate_postcopy_prepare(&from, &to, false)) { + if (migrate_postcopy_prepare(&from, &to, args)) { return; } migrate_postcopy_start(from, to); @@ -824,10 +844,13 @@ static void test_postcopy(void) static void test_postcopy_recovery(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; char *uri; - if (migrate_postcopy_prepare(&from, &to, true)) { + args->hide_stderr = true; + + if (migrate_postcopy_prepare(&from, &to, args)) { return; } @@ -910,9 +933,12 @@ static void wait_for_migration_fail(QTestState *from, bool allow_active) static void test_baddest(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (test_migrate_start(&from, &to, "tcp:0:0", true, false, NULL, NULL)) { + args->hide_stderr = true; + + if (test_migrate_start(&from, &to, "tcp:0:0", args)) { return; } migrate(from, "tcp:0:0", "{}"); @@ -923,9 +949,10 @@ static void test_baddest(void) static void test_precopy_unix(void) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -1001,9 +1028,10 @@ static void test_ignore_shared(void) static void test_xbzrle(const char *uri) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -1052,11 +1080,11 @@ static void test_xbzrle_unix(void) static void test_precopy_tcp(void) { + MigrateStart *args = migrate_start_new(); char *uri; QTestState *from, *to; - if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", false, false, - NULL, NULL)) { + if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", args)) { return; } @@ -1096,13 +1124,14 @@ static void test_precopy_tcp(void) static void test_migrate_fd_proto(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; int ret; int pair[2]; QDict *rsp; const char *error_desc; - if (test_migrate_start(&from, &to, "defer", false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, "defer", args)) { return; } @@ -1178,15 +1207,12 @@ static void test_migrate_fd_proto(void) test_migrate_end(from, to, true); } -static void do_test_validate_uuid(const char *uuid_arg_src, - const char *uuid_arg_dst, - bool should_fail, bool hide_stderr) +static void do_test_validate_uuid(MigrateStart *args, bool should_fail) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, hide_stderr, false, - uuid_arg_src, uuid_arg_dst)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -1216,33 +1242,45 @@ static void do_test_validate_uuid(const char *uuid_arg_src, static void test_validate_uuid(void) { - do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", - "-uuid 11111111-1111-1111-1111-111111111111", - false, false); + MigrateStart *args = migrate_start_new(); + + args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + args->opts_target = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + do_test_validate_uuid(args, false); } static void test_validate_uuid_error(void) { - do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", - "-uuid 22222222-2222-2222-2222-222222222222", - true, true); + MigrateStart *args = migrate_start_new(); + + args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + args->opts_target = g_strdup("-uuid 22222222-2222-2222-2222-222222222222"); + args->hide_stderr = true; + do_test_validate_uuid(args, true); } static void test_validate_uuid_src_not_set(void) { - do_test_validate_uuid(NULL, "-uuid 11111111-1111-1111-1111-111111111111", - false, true); + MigrateStart *args = migrate_start_new(); + + args->opts_target = g_strdup("-uuid 22222222-2222-2222-2222-222222222222"); + args->hide_stderr = true; + do_test_validate_uuid(args, false); } static void test_validate_uuid_dst_not_set(void) { - do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", NULL, - false, true); + MigrateStart *args = migrate_start_new(); + + args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + args->hide_stderr = true; + do_test_validate_uuid(args, false); } static void test_migrate_auto_converge(void) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateStart *args = migrate_start_new(); QTestState *from, *to; int64_t remaining, percentage; @@ -1261,7 +1299,7 @@ static void test_migrate_auto_converge(void) */ const int64_t expected_threshold = max_bandwidth * downtime_limit / 1000; - if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } From 53b62bec0144615a54c77f4fc5561501a6a2c844 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 11:50:03 +0100 Subject: [PATCH 12/87] memory: do not look at current_machine->accel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "info mtree -f" prints the wrong accelerator name if used with for example "-machine accel=kvm:tcg". The right thing to do is to fetch the name from the AccelClass, which will also work nicely once current_machine->accel stops existing. Tested-by: Thomas Huth Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- memory.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/memory.c b/memory.c index 0228cad38d..d7b9bb6951 100644 --- a/memory.c +++ b/memory.c @@ -2991,7 +2991,6 @@ struct FlatViewInfo { bool dispatch_tree; bool owner; AccelClass *ac; - const char *ac_name; }; static void mtree_print_flatview(gpointer key, gpointer value, @@ -3061,7 +3060,7 @@ static void mtree_print_flatview(gpointer key, gpointer value, if (fvi->ac->has_memory(current_machine, as, int128_get64(range->addr.start), MR_SIZE(range->addr.size) + 1)) { - qemu_printf(" %s", fvi->ac_name); + qemu_printf(" %s", fvi->ac->name); } } } @@ -3109,8 +3108,6 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner) if (ac->has_memory) { fvi.ac = ac; - fvi.ac_name = current_machine->accel ? current_machine->accel : - object_class_get_name(OBJECT_CLASS(ac)); } /* Gather all FVs in one table */ From 7f8b6126e7d4417a7faa8fdd18d5870d937aadf8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 12:37:00 +0100 Subject: [PATCH 13/87] vl: move icount configuration earlier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once qemu_tcg_configure is turned into a QOM property setter, it will not be able to set a default value for mttcg_enabled. Setting the default will move to the TCG instance_init function, which currently runs before "-icount" is processed. However, it is harmless to do configure_icount for all accelerators; we will just fail later if a non-TCG accelerator is selected. So do that. Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- vl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/vl.c b/vl.c index 94508300c3..6e58c1d08d 100644 --- a/vl.c +++ b/vl.c @@ -2700,6 +2700,12 @@ static void user_register_global_props(void) global_init_func, NULL, NULL); } +static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) +{ + configure_icount(opts, errp); + return 0; +} + int main(int argc, char **argv, char **envp) { int i; @@ -4010,6 +4016,8 @@ int main(int argc, char **argv, char **envp) * Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ + qemu_opts_foreach(qemu_find_opts("icount"), + do_configure_icount, NULL, &error_fatal); configure_accelerator(current_machine, argv[0]); /* @@ -4095,13 +4103,9 @@ int main(int argc, char **argv, char **envp) qemu_spice_init(); cpu_ticks_init(); - if (icount_opts) { - if (!tcg_enabled()) { - error_report("-icount is not allowed with hardware virtualization"); - exit(1); - } - configure_icount(icount_opts, &error_abort); - qemu_opts_del(icount_opts); + if (use_icount && !(tcg_enabled() || qtest_enabled())) { + error_report("-icount is not allowed with hardware virtualization"); + exit(1); } if (tcg_enabled()) { From af0440ae8521b9c173062cce4f231ae981bb9044 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 14 Nov 2019 10:40:27 +0100 Subject: [PATCH 14/87] tcg: move qemu_tcg_configure to accel/tcg/tcg-all.c Move everything related to mttcg_enabled in accel/tcg/tcg-all.c, which will make even more sense when "thread" becomes a QOM property. For now, initializing mttcg_enabled in the instance_init function prepares for the next patch, which will only invoke qemu_tcg_configure when the command line includes a -accel option. Signed-off-by: Paolo Bonzini --- accel/tcg/tcg-all.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ cpus.c | 72 --------------------------------------- 2 files changed, 83 insertions(+), 72 deletions(-) diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index c59d5b0024..6b000f0b94 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -30,6 +30,11 @@ #include "cpu.h" #include "sysemu/cpus.h" #include "qemu/main-loop.h" +#include "tcg/tcg.h" +#include "include/qapi/error.h" +#include "include/qemu/error-report.h" +#include "include/hw/boards.h" +#include "qemu/option.h" unsigned long tcg_tb_size; @@ -58,6 +63,53 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask) } } +/* + * We default to false if we know other options have been enabled + * which are currently incompatible with MTTCG. Otherwise when each + * guest (target) has been updated to support: + * - atomic instructions + * - memory ordering primitives (barriers) + * they can set the appropriate CONFIG flags in ${target}-softmmu.mak + * + * Once a guest architecture has been converted to the new primitives + * there are two remaining limitations to check. + * + * - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) + * - The host must have a stronger memory order than the guest + * + * It may be possible in future to support strong guests on weak hosts + * but that will require tagging all load/stores in a guest with their + * implicit memory order requirements which would likely slow things + * down a lot. + */ + +static bool check_tcg_memory_orders_compatible(void) +{ +#if defined(TCG_GUEST_DEFAULT_MO) && defined(TCG_TARGET_DEFAULT_MO) + return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) == 0; +#else + return false; +#endif +} + +static bool default_mttcg_enabled(void) +{ + if (use_icount || TCG_OVERSIZED_GUEST) { + return false; + } else { +#ifdef TARGET_SUPPORTS_MTTCG + return check_tcg_memory_orders_compatible(); +#else + return false; +#endif + } +} + +static void tcg_accel_instance_init(Object *obj) +{ + mttcg_enabled = default_mttcg_enabled(); +} + static int tcg_init(MachineState *ms) { tcg_exec_init(tcg_tb_size * 1024 * 1024); @@ -65,6 +117,36 @@ static int tcg_init(MachineState *ms) return 0; } +void qemu_tcg_configure(QemuOpts *opts, Error **errp) +{ + const char *t = qemu_opt_get(opts, "thread"); + if (!t) { + return; + } + if (strcmp(t, "multi") == 0) { + if (TCG_OVERSIZED_GUEST) { + error_setg(errp, "No MTTCG when guest word size > hosts"); + } else if (use_icount) { + error_setg(errp, "No MTTCG when icount is enabled"); + } else { +#ifndef TARGET_SUPPORTS_MTTCG + warn_report("Guest not yet converted to MTTCG - " + "you may get unexpected results"); +#endif + if (!check_tcg_memory_orders_compatible()) { + warn_report("Guest expects a stronger memory ordering " + "than the host provides"); + error_printf("This may cause strange/hard to debug errors\n"); + } + mttcg_enabled = true; + } + } else if (strcmp(t, "single") == 0) { + mttcg_enabled = false; + } else { + error_setg(errp, "Invalid 'thread' setting %s", t); + } +} + static void tcg_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); @@ -78,6 +160,7 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) static const TypeInfo tcg_accel_type = { .name = TYPE_TCG_ACCEL, .parent = TYPE_ACCEL, + .instance_init = tcg_accel_instance_init, .class_init = tcg_accel_class_init, }; diff --git a/cpus.c b/cpus.c index 63bda152f5..b472378b70 100644 --- a/cpus.c +++ b/cpus.c @@ -166,78 +166,6 @@ typedef struct TimersState { static TimersState timers_state; bool mttcg_enabled; -/* - * We default to false if we know other options have been enabled - * which are currently incompatible with MTTCG. Otherwise when each - * guest (target) has been updated to support: - * - atomic instructions - * - memory ordering primitives (barriers) - * they can set the appropriate CONFIG flags in ${target}-softmmu.mak - * - * Once a guest architecture has been converted to the new primitives - * there are two remaining limitations to check. - * - * - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) - * - The host must have a stronger memory order than the guest - * - * It may be possible in future to support strong guests on weak hosts - * but that will require tagging all load/stores in a guest with their - * implicit memory order requirements which would likely slow things - * down a lot. - */ - -static bool check_tcg_memory_orders_compatible(void) -{ -#if defined(TCG_GUEST_DEFAULT_MO) && defined(TCG_TARGET_DEFAULT_MO) - return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) == 0; -#else - return false; -#endif -} - -static bool default_mttcg_enabled(void) -{ - if (use_icount || TCG_OVERSIZED_GUEST) { - return false; - } else { -#ifdef TARGET_SUPPORTS_MTTCG - return check_tcg_memory_orders_compatible(); -#else - return false; -#endif - } -} - -void qemu_tcg_configure(QemuOpts *opts, Error **errp) -{ - const char *t = qemu_opt_get(opts, "thread"); - if (t) { - if (strcmp(t, "multi") == 0) { - if (TCG_OVERSIZED_GUEST) { - error_setg(errp, "No MTTCG when guest word size > hosts"); - } else if (use_icount) { - error_setg(errp, "No MTTCG when icount is enabled"); - } else { -#ifndef TARGET_SUPPORTS_MTTCG - warn_report("Guest not yet converted to MTTCG - " - "you may get unexpected results"); -#endif - if (!check_tcg_memory_orders_compatible()) { - warn_report("Guest expects a stronger memory ordering " - "than the host provides"); - error_printf("This may cause strange/hard to debug errors\n"); - } - mttcg_enabled = true; - } - } else if (strcmp(t, "single") == 0) { - mttcg_enabled = false; - } else { - error_setg(errp, "Invalid 'thread' setting %s", t); - } - } else { - mttcg_enabled = default_mttcg_enabled(); - } -} /* The current number of executed instructions is based on what we * originally budgeted minus the current state of the decrementing From deda73e89f271e15044334ad6c0dcdae5341b71d Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 14 Nov 2019 11:10:43 +0100 Subject: [PATCH 15/87] vl: extract accelerator option processing to a separate function As a first step towards supporting multiple "-accel" options, push the late processing of -icount and -accel into a new function, and use qemu_opts_foreach to retrieve -accel options instead of stashing them into globals. Signed-off-by: Paolo Bonzini --- vl.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/vl.c b/vl.c index 6e58c1d08d..7ed90263e7 100644 --- a/vl.c +++ b/vl.c @@ -2706,6 +2706,25 @@ static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) return 0; } +static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) +{ + if (tcg_enabled()) { + qemu_tcg_configure(opts, &error_fatal); + } + return 0; +} + +static void configure_accelerators(void) +{ + qemu_opts_foreach(qemu_find_opts("accel"), + do_configure_accelerator, NULL, &error_fatal); + + if (use_icount && !(tcg_enabled() || qtest_enabled())) { + error_report("-icount is not allowed with hardware virtualization"); + exit(1); + } +} + int main(int argc, char **argv, char **envp) { int i; @@ -4103,14 +4122,7 @@ int main(int argc, char **argv, char **envp) qemu_spice_init(); cpu_ticks_init(); - if (use_icount && !(tcg_enabled() || qtest_enabled())) { - error_report("-icount is not allowed with hardware virtualization"); - exit(1); - } - - if (tcg_enabled()) { - qemu_tcg_configure(accel_opts, &error_fatal); - } + configure_accelerators(); if (default_net) { QemuOptsList *net = qemu_find_opts("net"); From 28a0961757fcf1354a8a8f4df9f40d75c5b633dc Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 09:59:04 +0100 Subject: [PATCH 16/87] vl: merge -accel processing into configure_accelerators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The next step is to move the parsing of "-machine accel=..." into vl.c, unifying it with the configure_accelerators() function that has just been introduced. This way, we will be able to desugar it into multiple "-accel" options, without polluting accel/accel.c. The CONFIG_TCG and CONFIG_KVM symbols are not available in vl.c, but we can use accel_find instead to find their value at runtime. Once we know that the binary has one of TCG or KVM, the default accelerator can be expressed simply as "tcg:kvm", because TCG never fails to initialize. Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- accel/accel.c | 69 ++---------------------------------------- include/sysemu/accel.h | 4 ++- vl.c | 64 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 73 deletions(-) diff --git a/accel/accel.c b/accel/accel.c index 5fa31717b4..60c3827a9d 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -28,13 +28,7 @@ #include "hw/boards.h" #include "sysemu/arch_init.h" #include "sysemu/sysemu.h" -#include "sysemu/kvm.h" -#include "sysemu/qtest.h" -#include "hw/xen/xen.h" #include "qom/object.h" -#include "qemu/error-report.h" -#include "qemu/option.h" -#include "qapi/error.h" static const TypeInfo accel_type = { .name = TYPE_ACCEL, @@ -44,7 +38,7 @@ static const TypeInfo accel_type = { }; /* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find(const char *opt_name) +AccelClass *accel_find(const char *opt_name) { char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name); AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name)); @@ -52,7 +46,7 @@ static AccelClass *accel_find(const char *opt_name) return ac; } -static int accel_init_machine(AccelClass *acc, MachineState *ms) +int accel_init_machine(AccelClass *acc, MachineState *ms) { ObjectClass *oc = OBJECT_CLASS(acc); const char *cname = object_class_get_name(oc); @@ -71,65 +65,6 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms) return ret; } -void configure_accelerator(MachineState *ms, const char *progname) -{ - const char *accel; - char **accel_list, **tmp; - int ret; - bool accel_initialised = false; - bool init_failed = false; - AccelClass *acc = NULL; - - accel = qemu_opt_get(qemu_get_machine_opts(), "accel"); - if (accel == NULL) { - /* Select the default accelerator */ - int pnlen = strlen(progname); - if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { - /* If the program name ends with "kvm", we prefer KVM */ - accel = "kvm:tcg"; - } else { -#if defined(CONFIG_TCG) - accel = "tcg"; -#elif defined(CONFIG_KVM) - accel = "kvm"; -#else - error_report("No accelerator selected and" - " no default accelerator available"); - exit(1); -#endif - } - } - - accel_list = g_strsplit(accel, ":", 0); - - for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc = accel_find(*tmp); - if (!acc) { - continue; - } - ret = accel_init_machine(acc, ms); - if (ret < 0) { - init_failed = true; - error_report("failed to initialize %s: %s", - acc->name, strerror(-ret)); - } else { - accel_initialised = true; - } - } - g_strfreev(accel_list); - - if (!accel_initialised) { - if (!init_failed) { - error_report("-machine accel=%s: No accelerator found", accel); - } - exit(1); - } - - if (init_failed) { - error_report("Back to %s accelerator", acc->name); - } -} - void accel_setup_post(MachineState *ms) { AccelState *accel = ms->accelerator; diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 8eb60b870b..90b6213283 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -66,7 +66,9 @@ typedef struct AccelClass { extern unsigned long tcg_tb_size; -void configure_accelerator(MachineState *ms, const char *progname); +AccelClass *accel_find(const char *opt_name); +int accel_init_machine(AccelClass *acc, MachineState *ms); + /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); diff --git a/vl.c b/vl.c index 7ed90263e7..28adf38285 100644 --- a/vl.c +++ b/vl.c @@ -2714,8 +2714,65 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) return 0; } -static void configure_accelerators(void) +static void configure_accelerators(const char *progname) { + const char *accel; + char **accel_list, **tmp; + int ret; + bool accel_initialised = false; + bool init_failed = false; + AccelClass *acc = NULL; + + qemu_opts_foreach(qemu_find_opts("icount"), + do_configure_icount, NULL, &error_fatal); + + accel = qemu_opt_get(qemu_get_machine_opts(), "accel"); + if (accel == NULL) { + /* Select the default accelerator */ + if (!accel_find("tcg") && !accel_find("kvm")) { + error_report("No accelerator selected and" + " no default accelerator available"); + exit(1); + } else { + int pnlen = strlen(progname); + if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { + /* If the program name ends with "kvm", we prefer KVM */ + accel = "kvm:tcg"; + } else { + accel = "tcg:kvm"; + } + } + } + + accel_list = g_strsplit(accel, ":", 0); + + for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { + acc = accel_find(*tmp); + if (!acc) { + continue; + } + ret = accel_init_machine(acc, current_machine); + if (ret < 0) { + init_failed = true; + error_report("failed to initialize %s: %s", + acc->name, strerror(-ret)); + } else { + accel_initialised = true; + } + } + g_strfreev(accel_list); + + if (!accel_initialised) { + if (!init_failed) { + error_report("-machine accel=%s: No accelerator found", accel); + } + exit(1); + } + + if (init_failed) { + error_report("Back to %s accelerator", acc->name); + } + qemu_opts_foreach(qemu_find_opts("accel"), do_configure_accelerator, NULL, &error_fatal); @@ -4035,9 +4092,7 @@ int main(int argc, char **argv, char **envp) * Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ - qemu_opts_foreach(qemu_find_opts("icount"), - do_configure_icount, NULL, &error_fatal); - configure_accelerator(current_machine, argv[0]); + configure_accelerators(argv[0]); /* * Beware, QOM objects created before this point miss global and @@ -4122,7 +4177,6 @@ int main(int argc, char **argv, char **envp) qemu_spice_init(); cpu_ticks_init(); - configure_accelerators(); if (default_net) { QemuOptsList *net = qemu_find_opts("net"); From 03a7a1961f0ace505dc62d38be84ce3de6c9e92e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 14 Nov 2019 12:06:52 +0100 Subject: [PATCH 17/87] accel: compile accel/accel.c just once Now that accel/accel.c does not use CONFIG_TCG or CONFIG_KVM anymore, it need not be compiled once for every softmmu target. Signed-off-by: Paolo Bonzini --- Makefile.objs | 1 + accel/Makefile.objs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.objs b/Makefile.objs index 4e4d6ddbb3..c4bc783a7d 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -55,6 +55,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ +common-obj-y += accel/ common-obj-y += migration/ common-obj-y += audio/ diff --git a/accel/Makefile.objs b/accel/Makefile.objs index 8b498d39d8..17e5ac6061 100644 --- a/accel/Makefile.objs +++ b/accel/Makefile.objs @@ -1,4 +1,4 @@ -obj-$(CONFIG_SOFTMMU) += accel.o +common-obj-$(CONFIG_SOFTMMU) += accel.o obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o obj-$(CONFIG_KVM) += kvm/ obj-$(CONFIG_TCG) += tcg/ From e5db4bd863c8fdf155b003446b98a7aec65a931c Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 11:44:48 +0100 Subject: [PATCH 18/87] vl: introduce object_parse_property_opt We will reuse the parsing loop of machine_set_property soon for "-accel", but we do not want the "_" -> "-" conversion since "-accel" can just standardize on dashes. We will also add a bunch of legacy option handling to keep the QOM machine object clean. Extract the loop into a separate function, and keep the legacy handling in machine_set_property. Signed-off-by: Paolo Bonzini --- vl.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/vl.c b/vl.c index 28adf38285..efd3b11431 100644 --- a/vl.c +++ b/vl.c @@ -2490,27 +2490,17 @@ static MachineClass *select_machine(void) return machine_class; } -static int machine_set_property(void *opaque, - const char *name, const char *value, - Error **errp) +static int object_parse_property_opt(Object *obj, + const char *name, const char *value, + const char *skip, Error **errp) { - Object *obj = OBJECT(opaque); Error *local_err = NULL; - char *p, *qom_name; - if (strcmp(name, "type") == 0) { + if (g_str_equal(name, skip)) { return 0; } - qom_name = g_strdup(name); - for (p = qom_name; *p; p++) { - if (*p == '_') { - *p = '-'; - } - } - - object_property_parse(obj, value, qom_name, &local_err); - g_free(qom_name); + object_property_parse(obj, value, name, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -2520,6 +2510,21 @@ static int machine_set_property(void *opaque, return 0; } +static int machine_set_property(void *opaque, + const char *name, const char *value, + Error **errp) +{ + g_autofree char *qom_name = g_strdup(name); + char *p; + + for (p = qom_name; *p; p++) { + if (*p == '_') { + *p = '-'; + } + } + + return object_parse_property_opt(opaque, name, value, "type", errp); +} /* * Initial object creation happens before all other From 6f6e1698a68ceb49e57676528612f22eaf2c16c3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 10:10:47 +0100 Subject: [PATCH 19/87] vl: configure accelerators from -accel options Drop the "accel" property from MachineState, and instead desugar "-machine accel=" to a list of "-accel" options. This has a semantic change due to removing merge_lists from -accel. For example: - "-accel kvm -accel tcg" all but ignored "-accel kvm". This is a bugfix. - "-accel kvm -accel thread=single" ignored "thread=single", since it applied the option to KVM. Now it fails due to not specifying the accelerator on "-accel thread=single". - "-accel tcg -accel thread=single" chose single-threaded TCG, while now it will fail due to not specifying the accelerator on "-accel thread=single". Also, "-machine accel" and "-accel" become incompatible. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 21 --------- include/hw/boards.h | 1 - tests/arm-cpu-features.c | 4 +- tests/bios-tables-test.c | 16 +++---- tests/boot-serial-test.c | 4 +- tests/cdrom-test.c | 2 +- tests/libqtest.c | 4 +- tests/migration-test.c | 23 ++++------ tests/pflash-cfi02-test.c | 4 +- tests/pnv-xscom-test.c | 4 +- tests/prom-env-test.c | 2 +- tests/pxe-test.c | 2 +- tests/vmgenid-test.c | 2 +- vl.c | 93 +++++++++++++++++++++++---------------- 14 files changed, 85 insertions(+), 97 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 023548b4f3..e661fa609e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -178,21 +178,6 @@ GlobalProperty hw_compat_2_1[] = { }; const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1); -static char *machine_get_accel(Object *obj, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - return g_strdup(ms->accel); -} - -static void machine_set_accel(Object *obj, const char *value, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - g_free(ms->accel); - ms->accel = g_strdup(value); -} - static void machine_set_kernel_irqchip(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -813,11 +798,6 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->numa_mem_align_shift = 23; mc->numa_auto_assign_ram = numa_default_auto_assign_ram; - object_class_property_add_str(oc, "accel", - machine_get_accel, machine_set_accel, &error_abort); - object_class_property_set_description(oc, "accel", - "Accelerator list", &error_abort); - object_class_property_add(oc, "kernel-irqchip", "on|off|split", NULL, machine_set_kernel_irqchip, NULL, NULL, &error_abort); @@ -976,7 +956,6 @@ static void machine_finalize(Object *obj) { MachineState *ms = MACHINE(obj); - g_free(ms->accel); g_free(ms->kernel_filename); g_free(ms->initrd_filename); g_free(ms->kernel_cmdline); diff --git a/include/hw/boards.h b/include/hw/boards.h index 24cbeecbae..96f2084c6e 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -275,7 +275,6 @@ struct MachineState { /*< public >*/ - char *accel; bool kernel_irqchip_allowed; bool kernel_irqchip_required; bool kernel_irqchip_split; diff --git a/tests/arm-cpu-features.c b/tests/arm-cpu-features.c index 6e99aa951e..bef3ed24b6 100644 --- a/tests/arm-cpu-features.c +++ b/tests/arm-cpu-features.c @@ -20,8 +20,8 @@ */ #define SVE_MAX_VQ 16 -#define MACHINE "-machine virt,gic-version=max,accel=tcg " -#define MACHINE_KVM "-machine virt,gic-version=max,accel=kvm:tcg " +#define MACHINE "-machine virt,gic-version=max -accel tcg " +#define MACHINE_KVM "-machine virt,gic-version=max -accel kvm -accel tcg " #define QUERY_HEAD "{ 'execute': 'query-cpu-model-expansion', " \ " 'arguments': { 'type': 'full', " #define QUERY_TAIL "}}" diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 79f5da092f..bc0ad594a1 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -51,7 +51,7 @@ #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" typedef struct { - const char *accel; + bool tcg_only; const char *machine; const char *variant; const char *uefi_fl1; @@ -607,19 +607,19 @@ static void test_acpi_one(const char *params, test_data *data) * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3) * when arm/virt boad starts to support it. */ - args = g_strdup_printf("-machine %s,accel=%s -nodefaults -nographic " + args = g_strdup_printf("-machine %s %s -accel tcg -nodefaults -nographic " "-drive if=pflash,format=raw,file=%s,readonly " "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s", - data->machine, data->accel ? data->accel : "kvm:tcg", + data->machine, data->tcg_only ? "" : "-accel kvm", data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : ""); } else { /* Disable kernel irqchip to be able to override apic irq0. */ - args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off " + args = g_strdup_printf("-machine %s,kernel-irqchip=off %s -accel tcg " "-net none -display none %s " "-drive id=hd0,if=none,file=%s,format=raw " "-device ide-hd,drive=hd0 ", - data->machine, data->accel ? data->accel : "kvm:tcg", + data->machine, data->tcg_only ? "" : "-accel kvm", params ? params : "", disk); } @@ -904,7 +904,7 @@ static void test_acpi_virt_tcg_memhp(void) { test_data data = { .machine = "virt", - .accel = "tcg", + .tcg_only = true, .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", @@ -929,7 +929,7 @@ static void test_acpi_virt_tcg_numamem(void) { test_data data = { .machine = "virt", - .accel = "tcg", + .tcg_only = true, .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", @@ -951,7 +951,7 @@ static void test_acpi_virt_tcg(void) { test_data data = { .machine = "virt", - .accel = "tcg", + .tcg_only = true, .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c index d3a54a0ba5..05c7f44457 100644 --- a/tests/boot-serial-test.c +++ b/tests/boot-serial-test.c @@ -215,9 +215,9 @@ static void test_machine(const void *data) * Make sure that this test uses tcg if available: It is used as a * fast-enough smoketest for that. */ - qts = qtest_initf("%s %s -M %s,accel=tcg:kvm -no-shutdown " + qts = qtest_initf("%s %s -M %s -no-shutdown " "-chardev file,id=serial0,path=%s " - "-serial chardev:serial0 %s", + "-serial chardev:serial0 -accel tcg -accel kvm %s", codeparam, code ? codetmp : "", test->machine, serialtmp, test->extra); if (code) { diff --git a/tests/cdrom-test.c b/tests/cdrom-test.c index 34e9974634..67635e387a 100644 --- a/tests/cdrom-test.c +++ b/tests/cdrom-test.c @@ -120,7 +120,7 @@ static void test_cdboot(gconstpointer data) { QTestState *qts; - qts = qtest_initf("-M accel=kvm:tcg -no-shutdown %s%s", (const char *)data, + qts = qtest_initf("-accel kvm -accel tcg -no-shutdown %s%s", (const char *)data, isoimage); boot_sector_test(qts); qtest_quit(qts); diff --git a/tests/libqtest.c b/tests/libqtest.c index f36e30a4de..76c9f8eade 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -241,9 +241,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args) "-qtest-log %s " "-chardev socket,path=%s,id=char0 " "-mon chardev=char0,mode=control " - "-accel qtest " "-display none " - "%s", qemu_binary, socket_path, + "%s" + " -accel qtest", qemu_binary, socket_path, getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null", qmp_socket_path, extra_args ?: ""); diff --git a/tests/migration-test.c b/tests/migration-test.c index dbe25b8d7c..e56e6dcb00 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -577,8 +577,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, char *shmem_opts; char *shmem_path; const char *arch = qtest_get_arch(); - const char *machine_type; - const char *machine_args; + const char *machine_opts = NULL; const char *memory_size; if (args->use_shmem) { @@ -594,8 +593,6 @@ static int test_migrate_start(QTestState **from, QTestState **to, /* the assembled x86 boot sector should be exactly one sector large */ assert(sizeof(x86_bootsect) == 512); init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect)); - machine_type = ""; - machine_args = ""; memory_size = "150M"; arch_source = g_strdup_printf("-drive file=%s,format=raw", bootpath); arch_target = g_strdup(arch_source); @@ -603,16 +600,13 @@ static int test_migrate_start(QTestState **from, QTestState **to, end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf)); - machine_type = ""; - machine_args = ""; memory_size = "128M"; arch_source = g_strdup_printf("-bios %s", bootpath); arch_target = g_strdup(arch_source); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { - machine_type = ""; - machine_args = ",vsmt=8"; + machine_opts = "vsmt=8"; memory_size = "256M"; arch_source = g_strdup_printf("-nodefaults " "-prom-env 'use-nvramrc?=true' -prom-env " @@ -624,8 +618,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, end_address = PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") == 0) { init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel)); - machine_type = "virt,"; - machine_args = "gic-version=max"; + machine_opts = "virt,gic-version=max"; memory_size = "150M"; arch_source = g_strdup_printf("-cpu max " "-kernel %s", @@ -658,12 +651,13 @@ static int test_migrate_start(QTestState **from, QTestState **to, shmem_opts = g_strdup(""); } - cmd_source = g_strdup_printf("-machine %saccel=kvm:tcg%s " + cmd_source = g_strdup_printf("-accel kvm -accel tcg%s%s " "-name source,debug-threads=on " "-m %s " "-serial file:%s/src_serial " "%s %s %s %s", - machine_type, machine_args, + machine_opts ? " -machine " : "", + machine_opts ? machine_opts : "", memory_size, tmpfs, arch_source, shmem_opts, args->opts_source, ignore_stderr); @@ -671,13 +665,14 @@ static int test_migrate_start(QTestState **from, QTestState **to, *from = qtest_init(cmd_source); g_free(cmd_source); - cmd_target = g_strdup_printf("-machine %saccel=kvm:tcg%s " + cmd_target = g_strdup_printf("-accel kvm -accel tcg%s%s " "-name target,debug-threads=on " "-m %s " "-serial file:%s/dest_serial " "-incoming %s " "%s %s %s %s", - machine_type, machine_args, + machine_opts ? " -machine " : "", + machine_opts ? machine_opts : "", memory_size, tmpfs, uri, arch_target, shmem_opts, args->opts_target, ignore_stderr); diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c index d3b23f4f66..17aa669b2e 100644 --- a/tests/pflash-cfi02-test.c +++ b/tests/pflash-cfi02-test.c @@ -260,7 +260,7 @@ static void test_geometry(const void *opaque) { const FlashConfig *config = opaque; QTestState *qtest; - qtest = qtest_initf("-M musicpal,accel=qtest" + qtest = qtest_initf("-M musicpal" " -drive if=pflash,file=%s,format=raw,copy-on-read" /* Device geometry properties. */ " -global driver=cfi.pflash02," @@ -580,7 +580,7 @@ static void test_cfi_in_autoselect(const void *opaque) { const FlashConfig *config = opaque; QTestState *qtest; - qtest = qtest_initf("-M musicpal,accel=qtest" + qtest = qtest_initf("-M musicpal" " -drive if=pflash,file=%s,format=raw,copy-on-read", image_path); FlashConfig explicit_config = expand_config_defaults(config); diff --git a/tests/pnv-xscom-test.c b/tests/pnv-xscom-test.c index 9fddc7d5f9..2c46d5cf6d 100644 --- a/tests/pnv-xscom-test.c +++ b/tests/pnv-xscom-test.c @@ -84,7 +84,7 @@ static void test_cfam_id(const void *data) machine = "powernv9"; } - qts = qtest_initf("-M %s,accel=tcg -cpu %s", + qts = qtest_initf("-M %s -accel tcg -cpu %s", machine, chip->cpu_model); test_xscom_cfam_id(qts, chip); qtest_quit(qts); @@ -125,7 +125,7 @@ static void test_core(const void *data) machine = "powernv9"; } - qts = qtest_initf("-M %s,accel=tcg -cpu %s", + qts = qtest_initf("-M %s -accel tcg -cpu %s", machine, chip->cpu_model); test_xscom_core(qts, chip); qtest_quit(qts); diff --git a/tests/prom-env-test.c b/tests/prom-env-test.c index 61bc1d1e7b..9be52c766f 100644 --- a/tests/prom-env-test.c +++ b/tests/prom-env-test.c @@ -57,7 +57,7 @@ static void test_machine(const void *machine) " -machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken"; } - qts = qtest_initf("-M %s,accel=tcg %s -prom-env 'use-nvramrc?=true' " + qts = qtest_initf("-M %s -accel tcg %s -prom-env 'use-nvramrc?=true' " "-prom-env 'nvramrc=%x %x l!' ", (const char *)machine, extra_args, MAGIC, ADDRESS); check_guest_memory(qts); diff --git a/tests/pxe-test.c b/tests/pxe-test.c index aaae54f755..f68d0aadbb 100644 --- a/tests/pxe-test.c +++ b/tests/pxe-test.c @@ -74,7 +74,7 @@ static void test_pxe_one(const testdef_t *test, bool ipv6) } args = g_strdup_printf( - "-machine %s,accel=kvm:tcg -nodefaults -boot order=n " + "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n " "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " "-device %s,bootindex=1,netdev=" NETNAME " %s", test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 85d8e6463e..efba76e716 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -109,7 +109,7 @@ static void read_guid_from_monitor(QTestState *qts, QemuUUID *guid) static char disk[] = "tests/vmgenid-test-disk-XXXXXX"; #define GUID_CMD(guid) \ - "-machine accel=kvm:tcg " \ + "-accel kvm -accel tcg " \ "-device vmgenid,id=testvgid,guid=%s " \ "-drive id=hd0,if=none,file=%s,format=raw " \ "-device ide-hd,drive=hd0 ", guid, disk diff --git a/vl.c b/vl.c index efd3b11431..0f620be8b1 100644 --- a/vl.c +++ b/vl.c @@ -292,7 +292,6 @@ static QemuOptsList qemu_accel_opts = { .name = "accel", .implied_opt_name = "accel", .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), - .merge_lists = true, .desc = { { .name = "accel", @@ -2523,6 +2522,11 @@ static int machine_set_property(void *opaque, } } + /* Legacy options do not correspond to MachineState properties. */ + if (g_str_equal(qom_name, "accel")) { + return 0; + } + return object_parse_property_opt(opaque, name, value, "type", errp); } @@ -2713,74 +2717,88 @@ static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) { + bool *p_init_failed = opaque; + const char *acc = qemu_opt_get(opts, "accel"); + AccelClass *ac = accel_find(acc); + int ret; + + if (!ac) { + return 0; + } + ret = accel_init_machine(ac, current_machine); + if (ret < 0) { + *p_init_failed = true; + error_report("failed to initialize %s: %s", + acc, strerror(-ret)); + return 0; + } + if (tcg_enabled()) { qemu_tcg_configure(opts, &error_fatal); } - return 0; + return 1; } static void configure_accelerators(const char *progname) { const char *accel; char **accel_list, **tmp; - int ret; bool accel_initialised = false; bool init_failed = false; - AccelClass *acc = NULL; qemu_opts_foreach(qemu_find_opts("icount"), do_configure_icount, NULL, &error_fatal); accel = qemu_opt_get(qemu_get_machine_opts(), "accel"); - if (accel == NULL) { - /* Select the default accelerator */ - if (!accel_find("tcg") && !accel_find("kvm")) { - error_report("No accelerator selected and" - " no default accelerator available"); - exit(1); - } else { - int pnlen = strlen(progname); - if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { - /* If the program name ends with "kvm", we prefer KVM */ - accel = "kvm:tcg"; + if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { + if (accel == NULL) { + /* Select the default accelerator */ + if (!accel_find("tcg") && !accel_find("kvm")) { + error_report("No accelerator selected and" + " no default accelerator available"); + exit(1); } else { - accel = "tcg:kvm"; + int pnlen = strlen(progname); + if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { + /* If the program name ends with "kvm", we prefer KVM */ + accel = "kvm:tcg"; + } else { + accel = "tcg:kvm"; + } } } - } - accel_list = g_strsplit(accel, ":", 0); + accel_list = g_strsplit(accel, ":", 0); - for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc = accel_find(*tmp); - if (!acc) { - continue; + for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { + /* + * Filter invalid accelerators here, to prevent obscenities + * such as "-machine accel=tcg,,thread=single". + */ + if (accel_find(*tmp)) { + qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); + } } - ret = accel_init_machine(acc, current_machine); - if (ret < 0) { - init_failed = true; - error_report("failed to initialize %s: %s", - acc->name, strerror(-ret)); - } else { - accel_initialised = true; + } else { + if (accel != NULL) { + error_report("The -accel and \"-machine accel=\" options are incompatible"); + exit(1); } } - g_strfreev(accel_list); - if (!accel_initialised) { + if (!qemu_opts_foreach(qemu_find_opts("accel"), + do_configure_accelerator, &init_failed, &error_fatal)) { if (!init_failed) { - error_report("-machine accel=%s: No accelerator found", accel); + error_report("no accelerator found"); } exit(1); } if (init_failed) { - error_report("Back to %s accelerator", acc->name); + AccelClass *ac = ACCEL_GET_CLASS(current_machine->accelerator); + error_report("Back to %s accelerator", ac->name); } - qemu_opts_foreach(qemu_find_opts("accel"), - do_configure_accelerator, NULL, &error_fatal); - if (use_icount && !(tcg_enabled() || qtest_enabled())) { error_report("-icount is not allowed with hardware virtualization"); exit(1); @@ -3461,9 +3479,6 @@ int main(int argc, char **argv, char **envp) "use -M accel=... for now instead"); exit(1); } - opts = qemu_opts_create(qemu_find_opts("machine"), NULL, - false, &error_abort); - qemu_opt_set(opts, "accel", optarg, &error_abort); break; case QEMU_OPTION_usb: olist = qemu_find_opts("machine"); From 8b90f1c5aca6cfabe97a567150560d06485182fa Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 12:08:38 +0100 Subject: [PATCH 20/87] vl: warn for unavailable accelerators, clarify messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So far, specifying an accelerator that was not compiled in did not result in an error; fix that. While at it, clarify the mysterious "Back to TCG" message. Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- vl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 0f620be8b1..c350eef046 100644 --- a/vl.c +++ b/vl.c @@ -2723,6 +2723,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) int ret; if (!ac) { + *p_init_failed = true; + error_report("invalid accelerator %s", acc); return 0; } ret = accel_init_machine(ac, current_machine); @@ -2777,6 +2779,9 @@ static void configure_accelerators(const char *progname) */ if (accel_find(*tmp)) { qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); + } else { + init_failed = true; + error_report("invalid accelerator %s", *tmp); } } } else { @@ -2796,7 +2801,7 @@ static void configure_accelerators(const char *progname) if (init_failed) { AccelClass *ac = ACCEL_GET_CLASS(current_machine->accelerator); - error_report("Back to %s accelerator", ac->name); + error_report("falling back to %s", ac->name); } if (use_icount && !(tcg_enabled() || qtest_enabled())) { From 1fff3c206f320104e929b22e6b9e82fc6e4c2ae6 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 13:33:44 +0100 Subject: [PATCH 21/87] qom: introduce object_register_sugar_prop Similar to the existing "-rtc driftfix" option, we will convert some legacy "-machine" command line options to global properties on accelerators. Because accelerators are not devices, we cannot use qdev_prop_register_global. Instead, provide a slot in the generic object_compat_props arrays for command line syntactic sugar. Signed-off-by: Paolo Bonzini --- include/qom/object.h | 1 + qom/object.c | 23 +++++++++++++++++++++-- vl.c | 10 +++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 128d00c77f..230b18fe14 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -679,6 +679,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp); void object_set_machine_compat_props(GPtrArray *compat_props); void object_set_accelerator_compat_props(GPtrArray *compat_props); +void object_register_sugar_prop(const char *driver, const char *prop, const char *value); void object_apply_compat_props(Object *obj); /** diff --git a/qom/object.c b/qom/object.c index d51b57fba1..e7b72f7d55 100644 --- a/qom/object.c +++ b/qom/object.c @@ -414,10 +414,29 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp * Global property defaults * Slot 0: accelerator's global property defaults * Slot 1: machine's global property defaults + * Slot 2: global properties from legacy command line option * Each is a GPtrArray of of GlobalProperty. * Applied in order, later entries override earlier ones. */ -static GPtrArray *object_compat_props[2]; +static GPtrArray *object_compat_props[3]; + +/* + * Retrieve @GPtrArray for global property defined with options + * other than "-global". These are generally used for syntactic + * sugar and legacy command line options. + */ +void object_register_sugar_prop(const char *driver, const char *prop, const char *value) +{ + GlobalProperty *g; + if (!object_compat_props[2]) { + object_compat_props[2] = g_ptr_array_new(); + } + g = g_new0(GlobalProperty, 1); + g->driver = g_strdup(driver); + g->property = g_strdup(prop); + g->value = g_strdup(value); + g_ptr_array_add(object_compat_props[2], g); +} /* * Set machine's global property defaults to @compat_props. @@ -445,7 +464,7 @@ void object_apply_compat_props(Object *obj) for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) { object_apply_global_props(obj, object_compat_props[i], - &error_abort); + i == 2 ? &error_fatal : &error_abort); } } diff --git a/vl.c b/vl.c index c350eef046..b95c161c1d 100644 --- a/vl.c +++ b/vl.c @@ -895,13 +895,9 @@ static void configure_rtc(QemuOpts *opts) value = qemu_opt_get(opts, "driftfix"); if (value) { if (!strcmp(value, "slew")) { - static GlobalProperty slew_lost_ticks = { - .driver = "mc146818rtc", - .property = "lost_tick_policy", - .value = "slew", - }; - - qdev_prop_register_global(&slew_lost_ticks); + object_register_sugar_prop("mc146818rtc", + "lost_tick_policy", + "slew"); } else if (!strcmp(value, "none")) { /* discard is default */ } else { From 3c75e12ea64666f2fc9f822675490e8672f45453 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 13:57:55 +0100 Subject: [PATCH 22/87] qom: add object_new_with_class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to CPU and machine classes, "-accel" class names are mangled, so we have to first get a class via accel_find and then instantiate it. Provide a new function to instantiate a class without going through object_class_get_name, and use it for CPUs and machines already. Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- accel/accel.c | 4 +--- include/qom/object.h | 12 ++++++++++++ qom/object.c | 5 +++++ target/i386/cpu.c | 8 ++++---- target/s390x/cpu_models.c | 4 ++-- vl.c | 3 +-- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/accel/accel.c b/accel/accel.c index 60c3827a9d..dd38a468af 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -48,9 +48,7 @@ AccelClass *accel_find(const char *opt_name) int accel_init_machine(AccelClass *acc, MachineState *ms) { - ObjectClass *oc = OBJECT_CLASS(acc); - const char *cname = object_class_get_name(oc); - AccelState *accel = ACCEL(object_new(cname)); + AccelState *accel = ACCEL(object_new_with_class(OBJECT_CLASS(acc))); int ret; ms->accelerator = accel; *(acc->allowed) = true; diff --git a/include/qom/object.h b/include/qom/object.h index 230b18fe14..f9ad692f21 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -592,6 +592,18 @@ struct InterfaceClass ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \ __FILE__, __LINE__, __func__)) +/** + * object_new_with_class: + * @klass: The class to instantiate. + * + * This function will initialize a new object using heap allocated memory. + * The returned object has a reference count of 1, and will be freed when + * the last reference is dropped. + * + * Returns: The newly allocated and instantiated object. + */ +Object *object_new_with_class(ObjectClass *klass); + /** * object_new: * @typename: The name of the type of the object to instantiate. diff --git a/qom/object.c b/qom/object.c index e7b72f7d55..0d971ca897 100644 --- a/qom/object.c +++ b/qom/object.c @@ -658,6 +658,11 @@ static Object *object_new_with_type(Type type) return obj; } +Object *object_new_with_class(ObjectClass *klass) +{ + return object_new_with_type(klass->type); +} + Object *object_new(const char *typename) { TypeImpl *ti = type_get_by_name(typename); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0a9ac65974..e1eb9f4739 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4695,7 +4695,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, return; } - xc = X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); + xc = X86_CPU(object_new_with_class(OBJECT_CLASS(xcc))); x86_cpu_expand_features(xc, &err); if (err) { @@ -4763,7 +4763,7 @@ static GSList *get_sorted_cpu_model_list(void) static char *x86_cpu_class_get_model_id(X86CPUClass *xc) { - Object *obj = object_new(object_class_get_name(OBJECT_CLASS(xc))); + Object *obj = object_new_with_class(OBJECT_CLASS(xc)); char *r = object_property_get_str(obj, "model-id", &error_abort); object_unref(obj); return r; @@ -5141,7 +5141,7 @@ static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) goto out; } - xc = X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); + xc = X86_CPU(object_new_with_class(OBJECT_CLASS(xcc))); if (props) { object_apply_props(OBJECT(xc), props, &err); if (err) { @@ -5983,7 +5983,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) APICCommonState *apic; ObjectClass *apic_class = OBJECT_CLASS(apic_get_class()); - cpu->apic_state = DEVICE(object_new(object_class_get_name(apic_class))); + cpu->apic_state = DEVICE(object_new_with_class(apic_class)); object_property_add_child(OBJECT(cpu), "lapic", OBJECT(cpu->apic_state), &error_abort); diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 547bab8ac3..7c32180269 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -440,7 +440,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque) if (cpu_list_data->model) { Object *obj; S390CPU *sc; - obj = object_new(object_class_get_name(klass)); + obj = object_new_with_class(klass); sc = S390_CPU(obj); if (sc->model) { info->has_unavailable_features = true; @@ -498,7 +498,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info, error_setg(errp, "The CPU definition '%s' requires KVM", info->name); return; } - obj = object_new(object_class_get_name(oc)); + obj = object_new_with_class(oc); cpu = S390_CPU(obj); if (!cpu->model) { diff --git a/vl.c b/vl.c index b95c161c1d..65e6b75a74 100644 --- a/vl.c +++ b/vl.c @@ -3834,8 +3834,7 @@ int main(int argc, char **argv, char **envp) cleanup_add_fd, NULL, &error_fatal); #endif - current_machine = MACHINE(object_new(object_class_get_name( - OBJECT_CLASS(machine_class)))); + current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class))); if (machine_help_func(qemu_get_machine_opts(), current_machine)) { exit(0); } From fc5cf8262113e80d35177f06d49bcc1a9d3dc9fc Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 14:03:46 +0100 Subject: [PATCH 23/87] accel: pass object to accel_init_machine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will have to set QOM properties before accel_init_machine, based on the options provided to -accel. Construct the object outside it so that it will be possible to iterate on properties between object_new_with_class and accel_init_machine. Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- accel/accel.c | 4 ++-- include/sysemu/accel.h | 2 +- vl.c | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/accel/accel.c b/accel/accel.c index dd38a468af..1c5c3a6abb 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -46,9 +46,9 @@ AccelClass *accel_find(const char *opt_name) return ac; } -int accel_init_machine(AccelClass *acc, MachineState *ms) +int accel_init_machine(AccelState *accel, MachineState *ms) { - AccelState *accel = ACCEL(object_new_with_class(OBJECT_CLASS(acc))); + AccelClass *acc = ACCEL_GET_CLASS(accel); int ret; ms->accelerator = accel; *(acc->allowed) = true; diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 90b6213283..22cac0f4db 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -67,7 +67,7 @@ typedef struct AccelClass { extern unsigned long tcg_tb_size; AccelClass *accel_find(const char *opt_name); -int accel_init_machine(AccelClass *acc, MachineState *ms); +int accel_init_machine(AccelState *accel, MachineState *ms); /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); diff --git a/vl.c b/vl.c index 65e6b75a74..b2f00ccd54 100644 --- a/vl.c +++ b/vl.c @@ -2716,6 +2716,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) bool *p_init_failed = opaque; const char *acc = qemu_opt_get(opts, "accel"); AccelClass *ac = accel_find(acc); + AccelState *accel; int ret; if (!ac) { @@ -2723,7 +2724,8 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) error_report("invalid accelerator %s", acc); return 0; } - ret = accel_init_machine(ac, current_machine); + accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); + ret = accel_init_machine(accel, current_machine); if (ret < 0) { *p_init_failed = true; error_report("failed to initialize %s: %s", From 12ceaef6ae0b4d0eec4712aaf54ad3b8434c1afb Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 10:36:01 +0100 Subject: [PATCH 24/87] tcg: convert "-accel threads" to a QOM property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the ad-hoc qemu_tcg_configure with generic code invoking QOM property getters and setters. More properties (and thus more valid -accel suboptions) will be added in the next patches, which will move accelerator-related "-machine" options to accelerators. Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- accel/tcg/tcg-all.c | 52 +++++++++++++++++++++++++++++++------------ include/sysemu/cpus.h | 2 -- vl.c | 32 +++++++++++++------------- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 6b000f0b94..7829f0227c 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -34,7 +34,17 @@ #include "include/qapi/error.h" #include "include/qemu/error-report.h" #include "include/hw/boards.h" -#include "qemu/option.h" + +typedef struct TCGState { + AccelState parent_obj; + + bool mttcg_enabled; +} TCGState; + +#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") + +#define TCG_STATE(obj) \ + OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) unsigned long tcg_tb_size; @@ -107,23 +117,33 @@ static bool default_mttcg_enabled(void) static void tcg_accel_instance_init(Object *obj) { - mttcg_enabled = default_mttcg_enabled(); + TCGState *s = TCG_STATE(obj); + + s->mttcg_enabled = default_mttcg_enabled(); } static int tcg_init(MachineState *ms) { + TCGState *s = TCG_STATE(current_machine->accelerator); + tcg_exec_init(tcg_tb_size * 1024 * 1024); cpu_interrupt_handler = tcg_handle_interrupt; + mttcg_enabled = s->mttcg_enabled; return 0; } -void qemu_tcg_configure(QemuOpts *opts, Error **errp) +static char *tcg_get_thread(Object *obj, Error **errp) { - const char *t = qemu_opt_get(opts, "thread"); - if (!t) { - return; - } - if (strcmp(t, "multi") == 0) { + TCGState *s = TCG_STATE(obj); + + return g_strdup(s->mttcg_enabled ? "multi" : "single"); +} + +static void tcg_set_thread(Object *obj, const char *value, Error **errp) +{ + TCGState *s = TCG_STATE(obj); + + if (strcmp(value, "multi") == 0) { if (TCG_OVERSIZED_GUEST) { error_setg(errp, "No MTTCG when guest word size > hosts"); } else if (use_icount) { @@ -138,12 +158,12 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp) "than the host provides"); error_printf("This may cause strange/hard to debug errors\n"); } - mttcg_enabled = true; + s->mttcg_enabled = true; } - } else if (strcmp(t, "single") == 0) { - mttcg_enabled = false; + } else if (strcmp(value, "single") == 0) { + s->mttcg_enabled = false; } else { - error_setg(errp, "Invalid 'thread' setting %s", t); + error_setg(errp, "Invalid 'thread' setting %s", value); } } @@ -153,15 +173,19 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) ac->name = "tcg"; ac->init_machine = tcg_init; ac->allowed = &tcg_allowed; -} -#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") + object_class_property_add_str(oc, "thread", + tcg_get_thread, + tcg_set_thread, + NULL); +} static const TypeInfo tcg_accel_type = { .name = TYPE_TCG_ACCEL, .parent = TYPE_ACCEL, .instance_init = tcg_accel_instance_init, .class_init = tcg_accel_class_init, + .instance_size = sizeof(TCGState), }; static void register_accel_types(void) diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index 32c05f27e7..3c1da6a018 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -40,6 +40,4 @@ extern int smp_threads; void list_cpus(const char *optarg); -void qemu_tcg_configure(QemuOpts *opts, Error **errp); - #endif diff --git a/vl.c b/vl.c index b2f00ccd54..7f2f3fb63c 100644 --- a/vl.c +++ b/vl.c @@ -293,17 +293,12 @@ static QemuOptsList qemu_accel_opts = { .implied_opt_name = "accel", .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), .desc = { - { - .name = "accel", - .type = QEMU_OPT_STRING, - .help = "Select the type of accelerator", - }, - { - .name = "thread", - .type = QEMU_OPT_STRING, - .help = "Enable/disable multi-threaded TCG", - }, - { /* end of list */ } + /* + * no elements => accept any + * sanity checking will happen later + * when setting accelerator properties + */ + { } }, }; @@ -2711,6 +2706,13 @@ static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) return 0; } +static int accelerator_set_property(void *opaque, + const char *name, const char *value, + Error **errp) +{ + return object_parse_property_opt(opaque, name, value, "accel", errp); +} + static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) { bool *p_init_failed = opaque; @@ -2725,6 +2727,10 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) return 0; } accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); + qemu_opt_foreach(opts, accelerator_set_property, + accel, + &error_fatal); + ret = accel_init_machine(accel, current_machine); if (ret < 0) { *p_init_failed = true; @@ -2732,10 +2738,6 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) acc, strerror(-ret)); return 0; } - - if (tcg_enabled()) { - qemu_tcg_configure(opts, &error_fatal); - } return 1; } From fe174132478b4e7b0086f2305a511fd94c9aca8b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 15:16:44 +0100 Subject: [PATCH 25/87] tcg: add "-accel tcg,tb-size" and deprecate "-tb-size" -tb-size fits nicely in the new framework for accelerator-specific options. It is a very niche option, so insta-deprecate it. Signed-off-by: Paolo Bonzini --- accel/tcg/tcg-all.c | 40 +++++++++++++++++++++++++++++++++++++--- include/sysemu/accel.h | 2 -- qemu-deprecated.texi | 6 ++++++ qemu-options.hx | 8 ++++++-- vl.c | 8 ++++---- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index 7829f0227c..1dc384c8d2 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -34,11 +34,13 @@ #include "include/qapi/error.h" #include "include/qemu/error-report.h" #include "include/hw/boards.h" +#include "qapi/qapi-builtin-visit.h" typedef struct TCGState { AccelState parent_obj; bool mttcg_enabled; + unsigned long tb_size; } TCGState; #define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") @@ -46,8 +48,6 @@ typedef struct TCGState { #define TCG_STATE(obj) \ OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) -unsigned long tcg_tb_size; - /* mask must never be zero, except for A20 change call */ static void tcg_handle_interrupt(CPUState *cpu, int mask) { @@ -126,7 +126,7 @@ static int tcg_init(MachineState *ms) { TCGState *s = TCG_STATE(current_machine->accelerator); - tcg_exec_init(tcg_tb_size * 1024 * 1024); + tcg_exec_init(s->tb_size * 1024 * 1024); cpu_interrupt_handler = tcg_handle_interrupt; mttcg_enabled = s->mttcg_enabled; return 0; @@ -167,6 +167,33 @@ static void tcg_set_thread(Object *obj, const char *value, Error **errp) } } +static void tcg_get_tb_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + TCGState *s = TCG_STATE(obj); + uint32_t value = s->tb_size; + + visit_type_uint32(v, name, &value, errp); +} + +static void tcg_set_tb_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + TCGState *s = TCG_STATE(obj); + Error *error = NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->tb_size = value; +} + static void tcg_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); @@ -178,6 +205,13 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data) tcg_get_thread, tcg_set_thread, NULL); + + object_class_property_add(oc, "tb-size", "int", + tcg_get_tb_size, tcg_set_tb_size, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, "tb-size", + "TCG translation block cache size", &error_abort); + } static const TypeInfo tcg_accel_type = { diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 22cac0f4db..d4c1429711 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -64,8 +64,6 @@ typedef struct AccelClass { #define ACCEL_GET_CLASS(obj) \ OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL) -extern unsigned long tcg_tb_size; - AccelClass *accel_find(const char *opt_name); int accel_init_machine(AccelState *accel, MachineState *ms); diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 62680f7bd5..e88f6d1a9a 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -142,6 +142,12 @@ QEMU 4.1 has three options, please migrate to one of these three: to do is specify the kernel they want to boot with the -kernel option 3. ``-bios `` - Tells QEMU to load the specified file as the firmwrae. +@subsection -tb-size option (since 5.0) + +QEMU 5.0 introduced an alternative syntax to specify the size of the translation +block cache, @option{-accel tcg,tb-size=}. The new syntax deprecates the +previously available @option{-tb-size} option. + @section QEMU Machine Protocol (QMP) commands @subsection change (since 2.5.0) diff --git a/qemu-options.hx b/qemu-options.hx index c63e794b64..ee1f676586 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -118,8 +118,9 @@ Select CPU model (@code{-cpu help} for list and additional feature selection) ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=]accelerator[,thread=single|multi]\n" + "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @item -accel @var{name}[,prop=@var{value}[,...]] @@ -129,6 +130,8 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item tb-size=@var{n} +Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi Controls number of TCG threads. When the TCG is multi-threaded there will be one thread per vCPU therefor taking advantage of additional host cores. The default @@ -3923,7 +3926,8 @@ DEF("tb-size", HAS_ARG, QEMU_OPTION_tb_size, \ STEXI @item -tb-size @var{n} @findex -tb-size -Set TB size. +Set TCG translation block cache size. Deprecated, use @samp{-accel tcg,tb-size=@var{n}} +instead. ETEXI DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ diff --git a/vl.c b/vl.c index 7f2f3fb63c..900f97a36a 100644 --- a/vl.c +++ b/vl.c @@ -2727,6 +2727,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) return 0; } accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); + object_apply_compat_props(OBJECT(accel)); qemu_opt_foreach(opts, accelerator_set_property, accel, &error_fatal); @@ -2738,6 +2739,7 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) acc, strerror(-ret)); return 0; } + return 1; } @@ -3590,10 +3592,8 @@ int main(int argc, char **argv, char **envp) error_report("TCG is disabled"); exit(1); #endif - if (qemu_strtoul(optarg, NULL, 0, &tcg_tb_size) < 0) { - error_report("Invalid argument to -tb-size"); - exit(1); - } + warn_report("The -tb-size option is deprecated, use -accel tcg,tb-size instead"); + object_register_sugar_prop(ACCEL_CLASS_NAME("tcg"), "tb-size", optarg); break; case QEMU_OPTION_icount: icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), From 46472d82322d0af23c7074c1101a791b5a27ca46 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 10:56:53 +0100 Subject: [PATCH 26/87] xen: convert "-machine igd-passthru" to an accelerator property The first machine property to fall is Xen's Intel integrated graphics passthrough. The "-machine igd-passthru" option does not set anymore a property on the machine object, but desugars to a GlobalProperty on accelerator objects. The setter is very simple, since the value ends up in a global variable, so this patch also provides an example before the more complicated cases that follow it. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 20 -------------------- hw/xen/xen-common.c | 18 ++++++++++++++++++ hw/xen/xen_pt.c | 2 ++ include/hw/boards.h | 1 - qemu-options.hx | 7 ++++--- vl.c | 14 ++++---------- 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index e661fa609e..05cea3aace 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -417,20 +417,6 @@ static void machine_set_graphics(Object *obj, bool value, Error **errp) ms->enable_graphics = value; } -static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - return ms->igd_gfx_passthru; -} - -static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - ms->igd_gfx_passthru = value; -} - static char *machine_get_firmware(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -867,12 +853,6 @@ static void machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "graphics", "Set on/off to enable/disable graphics emulation", &error_abort); - object_class_property_add_bool(oc, "igd-passthru", - machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, - &error_abort); - object_class_property_set_description(oc, "igd-passthru", - "Set on/off to enable/disable igd passthrou", &error_abort); - object_class_property_add_str(oc, "firmware", machine_get_firmware, machine_set_firmware, &error_abort); diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index 5284b0dec1..15650d7f6a 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -11,7 +11,9 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/module.h" +#include "qapi/error.h" #include "hw/xen/xen-legacy-backend.h" +#include "hw/xen/xen_pt.h" #include "chardev/char.h" #include "sysemu/accel.h" #include "sysemu/runstate.h" @@ -124,6 +126,16 @@ static void xen_change_state_handler(void *opaque, int running, } } +static bool xen_get_igd_gfx_passthru(Object *obj, Error **errp) +{ + return has_igd_gfx_passthru; +} + +static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) +{ + has_igd_gfx_passthru = value; +} + static void xen_setup_post(MachineState *ms, AccelState *accel) { int rc; @@ -177,6 +189,12 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) ac->compat_props = g_ptr_array_new(); compat_props_add(ac->compat_props, compat, G_N_ELEMENTS(compat)); + + object_class_property_add_bool(oc, "igd-passthru", + xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, + &error_abort); + object_class_property_set_description(oc, "igd-passthru", + "Set on/off to enable/disable igd passthrou", &error_abort); } #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen") diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 8fbaf2eae9..9e767d4244 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -65,6 +65,8 @@ #include "qemu/range.h" #include "exec/address-spaces.h" +bool has_igd_gfx_passthru; + #define XEN_PT_NR_IRQS (256) static uint8_t xen_pt_mapped_machine_irq[XEN_PT_NR_IRQS] = {0}; diff --git a/include/hw/boards.h b/include/hw/boards.h index 96f2084c6e..5025c1af9e 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -287,7 +287,6 @@ struct MachineState { bool mem_merge; bool usb; bool usb_disabled; - bool igd_gfx_passthru; char *firmware; bool iommu; bool suppress_vmdesc; diff --git a/qemu-options.hx b/qemu-options.hx index ee1f676586..153539092a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -37,7 +37,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n" @@ -71,8 +70,6 @@ more than one accelerator specified, the next one is used if the previous one fails to initialize. @item kernel_irqchip=on|off Controls in-kernel irqchip support for the chosen accelerator when available. -@item gfx_passthru=on|off -Enables IGD GFX passthrough support for the chosen machine when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default @@ -120,6 +117,7 @@ ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @@ -130,6 +128,9 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item igd-passthru=on|off +When Xen is in use, this option controls whether Intel integrated graphics +devices can be passed through to the guest (default=off) @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi diff --git a/vl.c b/vl.c index 900f97a36a..774305c3f7 100644 --- a/vl.c +++ b/vl.c @@ -1133,13 +1133,6 @@ static void configure_msg(QemuOpts *opts) } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru(void) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} - /***********************************************************/ /* USB devices */ @@ -2517,6 +2510,10 @@ static int machine_set_property(void *opaque, if (g_str_equal(qom_name, "accel")) { return 0; } + if (g_str_equal(qom_name, "igd-passthru")) { + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value); + return 0; + } return object_parse_property_opt(opaque, name, value, "type", errp); } @@ -4297,9 +4294,6 @@ int main(int argc, char **argv, char **envp) exit(1); } - /* Check if IGD GFX passthrough. */ - igd_gfx_passthru(); - /* init generic devices */ rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), From 23b0898e4471f42e62aa1fea304f6a6e23d03310 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 10:56:53 +0100 Subject: [PATCH 27/87] kvm: convert "-machine kvm_shadow_mem" to an accelerator property Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 43 +++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 39 --------------------------------------- include/hw/boards.h | 2 -- qemu-options.hx | 6 +++--- target/i386/kvm.c | 2 +- vl.c | 4 ++++ 6 files changed, 51 insertions(+), 45 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 7b9f92d51c..4770dd8c67 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -41,6 +41,7 @@ #include "hw/irq.h" #include "sysemu/sev.h" #include "sysemu/balloon.h" +#include "qapi/visitor.h" #include "hw/boards.h" @@ -92,6 +93,7 @@ struct KVMState int max_nested_state_len; int many_ioeventfds; int intx_set_mask; + int kvm_shadow_mem; bool sync_mmu; bool manual_dirty_log_protect; /* The man page (and posix) say ioctl numbers are signed int, but @@ -2954,6 +2956,40 @@ static bool kvm_accel_has_memory(MachineState *ms, AddressSpace *as, return false; } +static void kvm_get_kvm_shadow_mem(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + int64_t value = s->kvm_shadow_mem; + + visit_type_int(v, name, &value, errp); +} + +static void kvm_set_kvm_shadow_mem(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + Error *error = NULL; + int64_t value; + + visit_type_int(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->kvm_shadow_mem = value; +} + +static void kvm_accel_instance_init(Object *obj) +{ + KVMState *s = KVM_STATE(obj); + + s->kvm_shadow_mem = -1; +} + static void kvm_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); @@ -2961,11 +2997,18 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) ac->init_machine = kvm_init; ac->has_memory = kvm_accel_has_memory; ac->allowed = &kvm_allowed; + + object_class_property_add(oc, "kvm-shadow-mem", "int", + kvm_get_kvm_shadow_mem, kvm_set_kvm_shadow_mem, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, "kvm-shadow-mem", + "KVM shadow MMU size", &error_abort); } static const TypeInfo kvm_accel_type = { .name = TYPE_KVM_ACCEL, .parent = TYPE_ACCEL, + .instance_init = kvm_accel_instance_init, .class_init = kvm_accel_class_init, .instance_size = sizeof(KVMState), }; diff --git a/hw/core/machine.c b/hw/core/machine.c index 05cea3aace..9c933539d1 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -216,33 +216,6 @@ static void machine_set_kernel_irqchip(Object *obj, Visitor *v, } } -static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - MachineState *ms = MACHINE(obj); - int64_t value = ms->kvm_shadow_mem; - - visit_type_int(v, name, &value, errp); -} - -static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - MachineState *ms = MACHINE(obj); - Error *error = NULL; - int64_t value; - - visit_type_int(v, name, &value, &error); - if (error) { - error_propagate(errp, error); - return; - } - - ms->kvm_shadow_mem = value; -} - static char *machine_get_kernel(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -790,12 +763,6 @@ static void machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "kernel-irqchip", "Configure KVM in-kernel irqchip", &error_abort); - object_class_property_add(oc, "kvm-shadow-mem", "int", - machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem, - NULL, NULL, &error_abort); - object_class_property_set_description(oc, "kvm-shadow-mem", - "KVM shadow MMU size", &error_abort); - object_class_property_add_str(oc, "kernel", machine_get_kernel, machine_set_kernel, &error_abort); object_class_property_set_description(oc, "kernel", @@ -897,7 +864,6 @@ static void machine_initfn(Object *obj) ms->kernel_irqchip_allowed = true; ms->kernel_irqchip_split = mc->default_kernel_irqchip_split; - ms->kvm_shadow_mem = -1; ms->dump_guest_core = true; ms->mem_merge = true; ms->enable_graphics = true; @@ -968,11 +934,6 @@ bool machine_kernel_irqchip_split(MachineState *machine) return machine->kernel_irqchip_split; } -int machine_kvm_shadow_mem(MachineState *machine) -{ - return machine->kvm_shadow_mem; -} - int machine_phandle_start(MachineState *machine) { return machine->phandle_start; diff --git a/include/hw/boards.h b/include/hw/boards.h index 5025c1af9e..6084e61675 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -66,7 +66,6 @@ bool machine_usb(MachineState *machine); bool machine_kernel_irqchip_allowed(MachineState *machine); bool machine_kernel_irqchip_required(MachineState *machine); bool machine_kernel_irqchip_split(MachineState *machine); -int machine_kvm_shadow_mem(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); bool machine_mem_merge(MachineState *machine); @@ -278,7 +277,6 @@ struct MachineState { bool kernel_irqchip_allowed; bool kernel_irqchip_required; bool kernel_irqchip_split; - int kvm_shadow_mem; char *dtb; char *dumpdtb; int phandle_start; diff --git a/qemu-options.hx b/qemu-options.hx index 153539092a..004370ccec 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -34,7 +34,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " supported accelerators are kvm, xen, hax, hvf, whpx or tcg (default: tcg)\n" " kernel_irqchip=on|off|split controls accelerated irqchip support (default=off)\n" " vmport=on|off|auto controls emulation of vmport (default: auto)\n" - " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" @@ -74,8 +73,6 @@ Controls in-kernel irqchip support for the chosen accelerator when available. Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default is on. -@item kvm_shadow_mem=size -Defines the size of the KVM shadow MMU. @item dump-guest-core=on|off Include guest memory in a core dump. The default is on. @item mem-merge=on|off @@ -118,6 +115,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" + " kvm-shadow-mem=size of KVM shadow MMU in bytes\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @@ -131,6 +129,8 @@ fails to initialize. @item igd-passthru=on|off When Xen is in use, this option controls whether Intel integrated graphics devices can be passed through to the guest (default=off) +@item kvm-shadow-mem=size +Defines the size of the KVM shadow MMU. @item tb-size=@var{n} Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 1d10046a6c..62ce681a96 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -2163,7 +2163,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } qemu_register_reset(kvm_unpoison_all, NULL); - shadow_mem = machine_kvm_shadow_mem(ms); + shadow_mem = object_property_get_int(OBJECT(s), "kvm-shadow-mem", &error_abort); if (shadow_mem != -1) { shadow_mem /= 4096; ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem); diff --git a/vl.c b/vl.c index 774305c3f7..8c6fcdac3c 100644 --- a/vl.c +++ b/vl.c @@ -2514,6 +2514,10 @@ static int machine_set_property(void *opaque, object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value); return 0; } + if (g_str_equal(qom_name, "kvm-shadow-mem")) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value); + return 0; + } return object_parse_property_opt(opaque, name, value, "type", errp); } From 4376c40dedb22530738eeb104a603e94ed03f719 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 11:17:12 +0100 Subject: [PATCH 28/87] kvm: introduce kvm_kernel_irqchip_* functions The KVMState struct is opaque, so provide accessors for the fields that will be moved from current_machine to the accelerator. For now they just forward to the machine object, but this will change. Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 23 +++++++++++++++++++---- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_irq.c | 16 ++++------------ include/sysemu/kvm.h | 7 +++++-- target/arm/kvm.c | 8 ++++---- target/i386/kvm.c | 4 ++-- target/mips/kvm.c | 2 +- target/ppc/kvm.c | 2 +- target/s390x/kvm.c | 2 +- 9 files changed, 39 insertions(+), 30 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 4770dd8c67..34e8f26d6a 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1774,7 +1774,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi) g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi)); } -static void kvm_irqchip_create(MachineState *machine, KVMState *s) +static void kvm_irqchip_create(KVMState *s) { int ret; @@ -1792,9 +1792,9 @@ static void kvm_irqchip_create(MachineState *machine, KVMState *s) /* First probe and see if there's a arch-specific hook to create the * in-kernel irqchip for us */ - ret = kvm_arch_irqchip_create(machine, s); + ret = kvm_arch_irqchip_create(s); if (ret == 0) { - if (machine_kernel_irqchip_split(machine)) { + if (kvm_kernel_irqchip_split()) { perror("Split IRQ chip mode not supported."); exit(1); } else { @@ -2066,7 +2066,7 @@ static int kvm_init(MachineState *ms) } if (machine_kernel_irqchip_allowed(ms)) { - kvm_irqchip_create(ms, s); + kvm_irqchip_create(s); } if (kvm_eventfds_allowed) { @@ -2983,6 +2983,21 @@ static void kvm_set_kvm_shadow_mem(Object *obj, Visitor *v, s->kvm_shadow_mem = value; } +bool kvm_kernel_irqchip_allowed(void) +{ + return machine_kernel_irqchip_allowed(current_machine); +} + +bool kvm_kernel_irqchip_required(void) +{ + return machine_kernel_irqchip_required(current_machine); +} + +bool kvm_kernel_irqchip_split(void) +{ + return machine_kernel_irqchip_split(current_machine); +} + static void kvm_accel_instance_init(Object *obj) { KVMState *s = KVM_STATE(obj); diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 91cd4c26f9..12b6a5b2a8 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -793,7 +793,6 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms, MemoryRegion *ccsr, IrqLines *irqs) { - MachineState *machine = MACHINE(pms); const PPCE500MachineClass *pmc = PPCE500_MACHINE_GET_CLASS(pms); DeviceState *dev = NULL; SysBusDevice *s; @@ -801,10 +800,10 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms, if (kvm_enabled()) { Error *err = NULL; - if (machine_kernel_irqchip_allowed(machine)) { + if (kvm_kernel_irqchip_allowed()) { dev = ppce500_init_mpic_kvm(pmc, irqs, &err); } - if (machine_kernel_irqchip_required(machine) && !dev) { + if (kvm_kernel_irqchip_required() && !dev) { error_reportf_err(err, "kernel_irqchip requested but unavailable: "); exit(1); diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index 07e08d6544..373505d28b 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -75,12 +75,11 @@ int spapr_irq_init_kvm(SpaprInterruptControllerInitKvm fn, uint32_t nr_servers, Error **errp) { - MachineState *machine = MACHINE(qdev_get_machine()); Error *local_err = NULL; - if (kvm_enabled() && machine_kernel_irqchip_allowed(machine)) { + if (kvm_enabled() && kvm_kernel_irqchip_allowed()) { if (fn(intc, nr_servers, &local_err) < 0) { - if (machine_kernel_irqchip_required(machine)) { + if (kvm_kernel_irqchip_required()) { error_prepend(&local_err, "kernel_irqchip requested but unavailable: "); error_propagate(errp, local_err); @@ -185,7 +184,7 @@ static int spapr_irq_check(SpaprMachineState *spapr, Error **errp) */ if (kvm_enabled() && spapr->irq == &spapr_irq_dual && - machine_kernel_irqchip_required(machine) && + kvm_kernel_irqchip_required() && xics_kvm_has_broken_disconnect(spapr)) { error_setg(errp, "KVM is too old to support ic-mode=dual,kernel-irqchip=on"); return -1; @@ -288,20 +287,13 @@ uint32_t spapr_irq_nr_msis(SpaprMachineState *spapr) void spapr_irq_init(SpaprMachineState *spapr, Error **errp) { - MachineState *machine = MACHINE(spapr); SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); - if (machine_kernel_irqchip_split(machine)) { + if (kvm_enabled() && kvm_kernel_irqchip_split()) { error_setg(errp, "kernel_irqchip split mode not supported on pseries"); return; } - if (!kvm_enabled() && machine_kernel_irqchip_required(machine)) { - error_setg(errp, - "kernel_irqchip requested but only available with KVM"); - return; - } - if (spapr_irq_check(spapr, errp) < 0) { return; } diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 9fe233b9bf..aaf2a502e8 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -519,10 +519,13 @@ void kvm_pc_gsi_handler(void *opaque, int n, int level); void kvm_pc_setup_irq_routing(bool pci_enabled); void kvm_init_irq_routing(KVMState *s); +bool kvm_kernel_irqchip_allowed(void); +bool kvm_kernel_irqchip_required(void); +bool kvm_kernel_irqchip_split(void); + /** * kvm_arch_irqchip_create: * @KVMState: The KVMState pointer - * @MachineState: The MachineState pointer * * Allow architectures to create an in-kernel irq chip themselves. * @@ -530,7 +533,7 @@ void kvm_init_irq_routing(KVMState *s); * 0: irq chip was not created * > 0: irq chip was created */ -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s); +int kvm_arch_irqchip_create(KVMState *s); /** * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 5b82cefef6..b87b59a02a 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -741,11 +741,11 @@ void kvm_arch_init_irq_routing(KVMState *s) { } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { - if (machine_kernel_irqchip_split(ms)) { - perror("-machine kernel_irqchip=split is not supported on ARM."); - exit(1); + if (kvm_kernel_irqchip_split()) { + perror("-machine kernel_irqchip=split is not supported on ARM."); + exit(1); } /* If we can create the VGIC using the newer device control API, we diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 62ce681a96..ef63f3a5a6 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -4494,10 +4494,10 @@ void kvm_arch_init_irq_routing(KVMState *s) } } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { int ret; - if (machine_kernel_irqchip_split(ms)) { + if (kvm_kernel_irqchip_split()) { ret = kvm_vm_enable_cap(s, KVM_CAP_SPLIT_IRQCHIP, 0, 24); if (ret) { error_report("Could not enable split irqchip mode: %s", diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 578bc14625..de3e26ef1f 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -57,7 +57,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return 0; } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { return 0; } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 7406d18945..f7e187c961 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -152,7 +152,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return 0; } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { return 0; } diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index ad6e38c876..15260aeb9a 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -374,7 +374,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return 0; } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { return 0; } From 11bc4a13d1f4b07dafbd1dda4d4bf0fdd7ad65f2 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Nov 2019 10:56:53 +0100 Subject: [PATCH 29/87] kvm: convert "-machine kernel_irqchip" to an accelerator property Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 59 +++++++++++++++++++++++++++++++++++++++---- hw/core/machine.c | 61 --------------------------------------------- include/hw/boards.h | 3 --- qemu-options.hx | 9 ++++--- vl.c | 3 ++- 5 files changed, 62 insertions(+), 73 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 34e8f26d6a..b2f1a5bcb5 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -42,6 +42,8 @@ #include "sysemu/sev.h" #include "sysemu/balloon.h" #include "qapi/visitor.h" +#include "qapi/qapi-types-common.h" +#include "qapi/qapi-visit-common.h" #include "hw/boards.h" @@ -94,6 +96,9 @@ struct KVMState int many_ioeventfds; int intx_set_mask; int kvm_shadow_mem; + bool kernel_irqchip_allowed; + bool kernel_irqchip_required; + bool kernel_irqchip_split; bool sync_mmu; bool manual_dirty_log_protect; /* The man page (and posix) say ioctl numbers are signed int, but @@ -1794,7 +1799,7 @@ static void kvm_irqchip_create(KVMState *s) * in-kernel irqchip for us */ ret = kvm_arch_irqchip_create(s); if (ret == 0) { - if (kvm_kernel_irqchip_split()) { + if (s->kernel_irqchip_split) { perror("Split IRQ chip mode not supported."); exit(1); } else { @@ -2065,7 +2070,7 @@ static int kvm_init(MachineState *ms) goto err; } - if (machine_kernel_irqchip_allowed(ms)) { + if (s->kernel_irqchip_allowed) { kvm_irqchip_create(s); } @@ -2983,19 +2988,57 @@ static void kvm_set_kvm_shadow_mem(Object *obj, Visitor *v, s->kvm_shadow_mem = value; } +static void kvm_set_kernel_irqchip(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Error *err = NULL; + KVMState *s = KVM_STATE(obj); + OnOffSplit mode; + + visit_type_OnOffSplit(v, name, &mode, &err); + if (err) { + error_propagate(errp, err); + return; + } else { + switch (mode) { + case ON_OFF_SPLIT_ON: + s->kernel_irqchip_allowed = true; + s->kernel_irqchip_required = true; + s->kernel_irqchip_split = false; + break; + case ON_OFF_SPLIT_OFF: + s->kernel_irqchip_allowed = false; + s->kernel_irqchip_required = false; + s->kernel_irqchip_split = false; + break; + case ON_OFF_SPLIT_SPLIT: + s->kernel_irqchip_allowed = true; + s->kernel_irqchip_required = true; + s->kernel_irqchip_split = true; + break; + default: + /* The value was checked in visit_type_OnOffSplit() above. If + * we get here, then something is wrong in QEMU. + */ + abort(); + } + } +} + bool kvm_kernel_irqchip_allowed(void) { - return machine_kernel_irqchip_allowed(current_machine); + return kvm_state->kernel_irqchip_allowed; } bool kvm_kernel_irqchip_required(void) { - return machine_kernel_irqchip_required(current_machine); + return kvm_state->kernel_irqchip_required; } bool kvm_kernel_irqchip_split(void) { - return machine_kernel_irqchip_split(current_machine); + return kvm_state->kernel_irqchip_split; } static void kvm_accel_instance_init(Object *obj) @@ -3013,6 +3056,12 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) ac->has_memory = kvm_accel_has_memory; ac->allowed = &kvm_allowed; + object_class_property_add(oc, "kernel-irqchip", "on|off|split", + NULL, kvm_set_kernel_irqchip, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, "kernel-irqchip", + "Configure KVM in-kernel irqchip", &error_abort); + object_class_property_add(oc, "kvm-shadow-mem", "int", kvm_get_kvm_shadow_mem, kvm_set_kvm_shadow_mem, NULL, NULL, &error_abort); diff --git a/hw/core/machine.c b/hw/core/machine.c index 9c933539d1..56137e9bf0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -178,44 +178,6 @@ GlobalProperty hw_compat_2_1[] = { }; const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1); -static void machine_set_kernel_irqchip(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - Error *err = NULL; - MachineState *ms = MACHINE(obj); - OnOffSplit mode; - - visit_type_OnOffSplit(v, name, &mode, &err); - if (err) { - error_propagate(errp, err); - return; - } else { - switch (mode) { - case ON_OFF_SPLIT_ON: - ms->kernel_irqchip_allowed = true; - ms->kernel_irqchip_required = true; - ms->kernel_irqchip_split = false; - break; - case ON_OFF_SPLIT_OFF: - ms->kernel_irqchip_allowed = false; - ms->kernel_irqchip_required = false; - ms->kernel_irqchip_split = false; - break; - case ON_OFF_SPLIT_SPLIT: - ms->kernel_irqchip_allowed = true; - ms->kernel_irqchip_required = true; - ms->kernel_irqchip_split = true; - break; - default: - /* The value was checked in visit_type_OnOffSplit() above. If - * we get here, then something is wrong in QEMU. - */ - abort(); - } - } -} - static char *machine_get_kernel(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -757,12 +719,6 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->numa_mem_align_shift = 23; mc->numa_auto_assign_ram = numa_default_auto_assign_ram; - object_class_property_add(oc, "kernel-irqchip", "on|off|split", - NULL, machine_set_kernel_irqchip, - NULL, NULL, &error_abort); - object_class_property_set_description(oc, "kernel-irqchip", - "Configure KVM in-kernel irqchip", &error_abort); - object_class_property_add_str(oc, "kernel", machine_get_kernel, machine_set_kernel, &error_abort); object_class_property_set_description(oc, "kernel", @@ -862,8 +818,6 @@ static void machine_initfn(Object *obj) MachineState *ms = MACHINE(obj); MachineClass *mc = MACHINE_GET_CLASS(obj); - ms->kernel_irqchip_allowed = true; - ms->kernel_irqchip_split = mc->default_kernel_irqchip_split; ms->dump_guest_core = true; ms->mem_merge = true; ms->enable_graphics = true; @@ -919,21 +873,6 @@ bool machine_usb(MachineState *machine) return machine->usb; } -bool machine_kernel_irqchip_allowed(MachineState *machine) -{ - return machine->kernel_irqchip_allowed; -} - -bool machine_kernel_irqchip_required(MachineState *machine) -{ - return machine->kernel_irqchip_required; -} - -bool machine_kernel_irqchip_split(MachineState *machine) -{ - return machine->kernel_irqchip_split; -} - int machine_phandle_start(MachineState *machine) { return machine->phandle_start; diff --git a/include/hw/boards.h b/include/hw/boards.h index 6084e61675..61f8bb8e5a 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -63,9 +63,6 @@ extern MachineState *current_machine; void machine_run_board_init(MachineState *machine); bool machine_usb(MachineState *machine); -bool machine_kernel_irqchip_allowed(MachineState *machine); -bool machine_kernel_irqchip_required(MachineState *machine); -bool machine_kernel_irqchip_split(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); bool machine_mem_merge(MachineState *machine); diff --git a/qemu-options.hx b/qemu-options.hx index 004370ccec..71ec733a6c 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -32,7 +32,6 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " selects emulated machine ('-machine help' for list)\n" " property accel=accel1[:accel2[:...]] selects accelerator\n" " supported accelerators are kvm, xen, hax, hvf, whpx or tcg (default: tcg)\n" - " kernel_irqchip=on|off|split controls accelerated irqchip support (default=off)\n" " vmport=on|off|auto controls emulation of vmport (default: auto)\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" @@ -67,8 +66,6 @@ This is used to enable an accelerator. Depending on the target architecture, kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize. -@item kernel_irqchip=on|off -Controls in-kernel irqchip support for the chosen accelerator when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default @@ -115,6 +112,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" + " kernel-irqchip=on|off|split controls accelerated irqchip support (default=on)\n" " kvm-shadow-mem=size of KVM shadow MMU in bytes\n" " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) @@ -129,6 +127,11 @@ fails to initialize. @item igd-passthru=on|off When Xen is in use, this option controls whether Intel integrated graphics devices can be passed through to the guest (default=off) +@item kernel-irqchip=on|off|split +Controls KVM in-kernel irqchip support. The default is full acceleration of the +interrupt controllers. On x86, split irqchip reduces the kernel attack +surface, at a performance cost for non-MSI interrupts. Disabling the in-kernel +irqchip completely is not recommended except for debugging purposes. @item kvm-shadow-mem=size Defines the size of the KVM shadow MMU. @item tb-size=@var{n} diff --git a/vl.c b/vl.c index 8c6fcdac3c..4034c2343e 100644 --- a/vl.c +++ b/vl.c @@ -2514,7 +2514,8 @@ static int machine_set_property(void *opaque, object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value); return 0; } - if (g_str_equal(qom_name, "kvm-shadow-mem")) { + if (g_str_equal(qom_name, "kvm-shadow-mem") || + g_str_equal(qom_name, "kernel-irqchip")) { object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value); return 0; } From 3d24244b11cbb1bcb2582ed3625f20c6ecd85b1a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 5 Aug 2019 17:11:23 +0200 Subject: [PATCH 30/87] Makefile: remove unused variables Reviewed-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index 1361def144..a2acef3c11 100644 --- a/Makefile +++ b/Makefile @@ -445,10 +445,6 @@ dummy := $(call unnest-vars,, \ io-obj-y \ common-obj-y \ common-obj-m \ - ui-obj-y \ - ui-obj-m \ - audio-obj-y \ - audio-obj-m \ trace-obj-y) include $(SRC_PATH)/tests/Makefile.include From 55deffdb5ca626689b3e08d7e9adeab9f0e5ad5f Mon Sep 17 00:00:00 2001 From: Greg Kurz Date: Wed, 11 Dec 2019 14:32:41 +0100 Subject: [PATCH 31/87] object: Improve documentation of interfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QOM interfaces allow a limited form of multiple inheritance, at the condition of being stateless. That is, they cannot be instantiated and a pointer to an interface shouldn't be dereferenceable in any way. This is achieved by making the QOM instance type an incomplete type, which is, as mentioned by Markus Armbruster, the closest you can get to abstract class in C. Incomplete types are widely used to hide implementation details, but people usually expect to find at least one place where the type is fully defined. The fact that it doesn't happen with QOM interfaces is quite disturbing, especially since it isn't documented anywhere as recently discussed in this thread: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg01579.html Amend the documentation in the object.h header file to provide more details about why and how to implement QOM interfaces using incomplete types. Signed-off-by: Greg Kurz Reviewed-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- include/qom/object.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index f9ad692f21..bd68d1938c 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -200,8 +200,14 @@ typedef struct InterfaceInfo InterfaceInfo; * * Interfaces allow a limited form of multiple inheritance. Instances are * similar to normal types except for the fact that are only defined by - * their classes and never carry any state. You can dynamically cast an object - * to one of its #Interface types and vice versa. + * their classes and never carry any state. As a consequence, a pointer to + * an interface instance should always be of incomplete type in order to be + * sure it cannot be dereferenced. That is, you should define the + * 'typedef struct SomethingIf SomethingIf' so that you can pass around + * 'SomethingIf *si' arguments, but not define a 'struct SomethingIf { ... }'. + * The only things you can validly do with a 'SomethingIf *' are to pass it as + * an argument to a method on its corresponding SomethingIfClass, or to + * dynamically cast it to an object that implements the interface. * * # Methods # * From 57589bc497d518fc509cd8adb9407ea7984ec540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 27 Aug 2019 12:08:24 +0400 Subject: [PATCH 32/87] build-sys: build vhost-user-gpu only if CONFIG_TOOLS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vhost-user-gpu is always built and installed, but it is not part of the emulator proper. Cut it if --disable-tools is specified. Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a2acef3c11..bfd8ba3a96 100644 --- a/Makefile +++ b/Makefile @@ -321,14 +321,10 @@ HELPERS-y = HELPERS-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_LINUX)) = qemu-bridge-helper$(EXESUF) -ifdef CONFIG_LINUX -ifdef CONFIG_VIRGL -ifdef CONFIG_GBM +ifeq ($(CONFIG_LINUX)$(CONFIG_VIRGL)$(CONFIG_GBM)$(CONFIG_TOOLS),yyyy) HELPERS-y += vhost-user-gpu$(EXESUF) vhost-user-json-y += contrib/vhost-user-gpu/50-qemu-gpu.json endif -endif -endif # Sphinx does not allow building manuals into the same directory as # the source files, so if we're doing an in-tree QEMU build we must From b965e8c538b30116a637d64da6e2bd6d54e50171 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 11 Dec 2019 14:41:51 +0100 Subject: [PATCH 33/87] build-sys: do not include Windows SLIRP dependencies in $LIBS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When including the internal SLIRP library, we should add all the libraries that it needs for the build. Right now they are all included by QEMU, but -liphlpapi is not needed without slirp. Move it from LIBS to slirp_libs. Based on a patch by Marc-André Lureau. Acked-by: Samuel Thibault Signed-off-by: Paolo Bonzini --- configure | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 84b413dbfc..55d386c7bc 100755 --- a/configure +++ b/configure @@ -925,7 +925,7 @@ if test "$mingw32" = "yes" ; then DSOSUF=".dll" # MinGW needs -mthreads for TLS and macro _MT. QEMU_CFLAGS="-mthreads $QEMU_CFLAGS" - LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS" + LIBS="-lwinmm -lws2_32 $LIBS" write_c_skeleton; if compile_prog "" "-liberty" ; then LIBS="-liberty $LIBS" @@ -6027,6 +6027,9 @@ case "$slirp" in mkdir -p slirp slirp_cflags="-I\$(SRC_PATH)/slirp/src -I\$(BUILD_DIR)/slirp/src" slirp_libs="-L\$(BUILD_DIR)/slirp -lslirp" + if test "$mingw32" = "yes" ; then + slirp_libs="$slirp_libs -lws2_32 -liphlpapi" + fi ;; system) From e4f1bea2a8d021b35c5f83035f9af89f5e5bfeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 4 Oct 2019 15:12:09 +0400 Subject: [PATCH 34/87] migration: fix maybe-uninitialized warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ../migration/ram.c: In function ‘multifd_recv_thread’: /home/elmarco/src/qq/include/qapi/error.h:165:5: error: ‘block’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 165 | error_setg_internal((errp), __FILE__, __LINE__, __func__, \ | ^~~~~~~~~~~~~~~~~~~ ../migration/ram.c:818:15: note: ‘block’ was declared here 818 | RAMBlock *block; | ^~~~~ Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- migration/ram.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 38070f1bb2..219e3caa03 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -863,15 +863,17 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) p->next_packet_size = be32_to_cpu(packet->next_packet_size); p->packet_num = be64_to_cpu(packet->packet_num); - if (p->pages->used) { - /* make sure that ramblock is 0 terminated */ - packet->ramblock[255] = 0; - block = qemu_ram_block_by_name(packet->ramblock); - if (!block) { - error_setg(errp, "multifd: unknown ram block %s", - packet->ramblock); - return -1; - } + if (p->pages->used == 0) { + return 0; + } + + /* make sure that ramblock is 0 terminated */ + packet->ramblock[255] = 0; + block = qemu_ram_block_by_name(packet->ramblock); + if (!block) { + error_setg(errp, "multifd: unknown ram block %s", + packet->ramblock); + return -1; } for (i = 0; i < p->pages->used; i++) { From a85d0bf361b8d717a9b15e551a05e3572b20a77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 4 Oct 2019 15:18:20 +0400 Subject: [PATCH 35/87] monitor: fix maybe-uninitialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ../monitor/misc.c: In function ‘mon_get_cpu_sync’: /home/elmarco/src/qq/include/sysemu/hw_accel.h:22:9: error: ‘cpu’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 22 | kvm_cpu_synchronize_state(cpu); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../monitor/misc.c:397:15: note: ‘cpu’ was declared here 397 | CPUState *cpu; | ^~~ Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- monitor/misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor/misc.c b/monitor/misc.c index 3baa15f3bf..a74cff398d 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -394,7 +394,7 @@ int monitor_set_cpu(int cpu_index) /* Callers must hold BQL. */ static CPUState *mon_get_cpu_sync(bool synchronize) { - CPUState *cpu; + CPUState *cpu = NULL; if (cur_mon->mon_cpu_path) { cpu = (CPUState *) object_resolve_path_type(cur_mon->mon_cpu_path, @@ -411,6 +411,7 @@ static CPUState *mon_get_cpu_sync(bool synchronize) monitor_set_cpu(first_cpu->cpu_index); cpu = first_cpu; } + assert(cpu != NULL); if (synchronize) { cpu_synchronize_state(cpu); } From 3819af6e6a8fabe90957fa28bff0d9af56481662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 28 Aug 2019 12:18:06 +0400 Subject: [PATCH 36/87] vhost-user-scsi: fix printf format warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: ../contrib/vhost-user-scsi/vhost-user-scsi.c:118:57: error: format specifies type 'unsigned char' but the argument has type 'int' [-Werror,-Wformat] g_warning("Unable to determine cdb len (0x%02hhX)", cdb[0] >> 5); Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c index 0fc14d7899..7a1db164c8 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -115,7 +115,7 @@ static int get_cdb_len(uint8_t *cdb) case 4: return 16; case 5: return 12; } - g_warning("Unable to determine cdb len (0x%02hhX)", cdb[0] >> 5); + g_warning("Unable to determine cdb len (0x%02hhX)", (uint8_t)(cdb[0] >> 5)); return -1; } From 6dd2dacedd83d12328afa8559bffb2b9ec5c89ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 18 Sep 2019 12:24:10 +0400 Subject: [PATCH 37/87] os-posix: simplify os_find_datadir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use g_build_filename instead of sprintf, and g_autofree instead of manual freeing. Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- os-posix.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/os-posix.c b/os-posix.c index 86cffd2c7d..3cd52e1e70 100644 --- a/os-posix.c +++ b/os-posix.c @@ -80,41 +80,26 @@ void os_setup_signal_handling(void) sigaction(SIGTERM, &act, NULL); } -/* Find a likely location for support files using the location of the binary. - For installed binaries this will be "$bindir/../share/qemu". When - running from the build tree this will be "$bindir/../pc-bios". */ -#define SHARE_SUFFIX "/share/qemu" -#define BUILD_SUFFIX "/pc-bios" +/* + * Find a likely location for support files using the location of the binary. + * When running from the build tree this will be "$bindir/../pc-bios". + * Otherwise, this is CONFIG_QEMU_DATADIR. + */ char *os_find_datadir(void) { - char *dir, *exec_dir; - char *res; - size_t max_len; + g_autofree char *exec_dir = NULL; + g_autofree char *dir = NULL; exec_dir = qemu_get_exec_dir(); - if (exec_dir == NULL) { - return NULL; - } - dir = g_path_get_dirname(exec_dir); + g_return_val_if_fail(exec_dir != NULL, NULL); - max_len = strlen(dir) + - MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; - res = g_malloc0(max_len); - snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX); - if (access(res, R_OK)) { - snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX); - if (access(res, R_OK)) { - g_free(res); - res = NULL; - } + dir = g_build_filename(exec_dir, "..", "pc-bios", NULL); + if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { + return g_steal_pointer(&dir); } - g_free(dir); - g_free(exec_dir); - return res; + return g_strdup(CONFIG_QEMU_DATADIR); } -#undef SHARE_SUFFIX -#undef BUILD_SUFFIX void os_set_proc_name(const char *s) { From ee6fe0532c0618e3e556ab1c1c5a24a8aa5f834b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 3 Sep 2019 12:30:48 +0400 Subject: [PATCH 38/87] tests: skip block layer tests if !CONFIG_TOOLS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The block tests, as well as ahci-test needs qemu-img. Do not run them if it wasn't built. Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index b381387048..31b86674e5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -167,7 +167,7 @@ check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) += tests/ivshmem-test$(EXESUF) check-qtest-i386-$(CONFIG_ISA_TESTDEV) = tests/endianness-test$(EXESUF) check-qtest-i386-y += tests/fdc-test$(EXESUF) check-qtest-i386-y += tests/ide-test$(EXESUF) -check-qtest-i386-y += tests/ahci-test$(EXESUF) +check-qtest-i386-$(CONFIG_TOOLS) += tests/ahci-test$(EXESUF) check-qtest-i386-y += tests/hd-geo-test$(EXESUF) check-qtest-i386-y += tests/boot-order-test$(EXESUF) check-qtest-i386-y += tests/bios-tables-test$(EXESUF) @@ -1191,7 +1191,9 @@ check-acceptance: check-venv $(TESTS_RESULTS_DIR) .PHONY: check-block check-qapi-schema check-qtest check-unit check check-clean check-qapi-schema: check-tests/qapi-schema/frontend check-tests/qapi-schema/doc-good.texi check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS)) +ifeq ($(CONFIG_TOOLS),y) check-block: $(patsubst %,check-%, $(check-block-y)) +endif check: check-block check-qapi-schema check-unit check-softfloat check-qtest check-decodetree check-clean: rm -rf $(check-unit-y) tests/*.o $(QEMU_IOTESTS_HELPERS-y) From 534220407696fb2231fb7938d7b28aa1b9cfc676 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 29 Jul 2019 12:50:04 +0200 Subject: [PATCH 39/87] libvixl: remove per-target compiler flags We are already including -D__STDC_LIMIT_MACROS in the global CXXFLAGS, so it makes sense to do the same for -D__STDC_CONSTANT_MACROS and -D__STDC_FORMAT_MACROS instead of limiting that to libvixl. The -Wno-sign-compare option can also be removed since GCC 4.6 is not supported anymore. Signed-off-by: Paolo Bonzini --- configure | 3 ++- disas/libvixl/Makefile.objs | 11 +---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/configure b/configure index 55d386c7bc..0a63c75d36 100755 --- a/configure +++ b/configure @@ -101,7 +101,7 @@ update_cxxflags() { # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those # options which some versions of GCC's C++ compiler complain about # because they only make sense for C programs. - QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS" + QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS" for arg in $QEMU_CFLAGS; do case $arg in @@ -595,6 +595,7 @@ QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" QEMU_INCLUDES="-iquote . -iquote \$(SRC_PATH) -iquote \$(SRC_PATH)/accel/tcg -iquote \$(SRC_PATH)/include" +QEMU_INCLUDES="$QEMU_INCLUDES -iquote \$(SRC_PATH)/disas/libvixl" if test "$debug_info" = "yes"; then CFLAGS="-g $CFLAGS" LDFLAGS="-g $LDFLAGS" diff --git a/disas/libvixl/Makefile.objs b/disas/libvixl/Makefile.objs index 27183b7c20..99a637f6a0 100644 --- a/disas/libvixl/Makefile.objs +++ b/disas/libvixl/Makefile.objs @@ -1,14 +1,5 @@ -libvixl_OBJS = vixl/utils.o \ +common-obj-$(CONFIG_ARM_A64_DIS) = vixl/utils.o \ vixl/compiler-intrinsics.o \ vixl/a64/instructions-a64.o \ vixl/a64/decoder-a64.o \ vixl/a64/disasm-a64.o - -# The -Wno-sign-compare is needed only for gcc 4.6, which complains about -# some signed-unsigned equality comparisons which later gcc versions do not. -$(addprefix $(obj)/,$(libvixl_OBJS)): QEMU_CXXFLAGS := -I$(SRC_PATH)/disas/libvixl $(QEMU_CXXFLAGS) -Wno-sign-compare -# Ensure that C99 macros are defined regardless of the inclusion order of -# headers in vixl. This is required at least on NetBSD. -$(addprefix $(obj)/,$(libvixl_OBJS)): QEMU_CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS - -common-obj-$(CONFIG_ARM_A64_DIS) += $(libvixl_OBJS) From b8d89ba83bf42be1f7b1d7d45236eaf6960d1c4e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 29 Jul 2019 15:55:47 +0200 Subject: [PATCH 40/87] crypto: move common bits for all emulators to libqemuutil qcrypto_random_*, AES and qcrypto_init do not need to be linked as a whole and are the only parts that are used by user-mode emulation. Place them in libqemuutil, so that whatever needs them will pick them up automatically. Signed-off-by: Paolo Bonzini --- Makefile | 3 +-- Makefile.objs | 3 +-- Makefile.target | 2 -- crypto/Makefile.objs | 12 +++++------- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index bfd8ba3a96..fb1728e958 100644 --- a/Makefile +++ b/Makefile @@ -436,7 +436,6 @@ dummy := $(call unnest-vars,, \ block-obj-y \ block-obj-m \ crypto-obj-y \ - crypto-user-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -524,7 +523,7 @@ subdir-capstone: capstone/all subdir-slirp: slirp/all $(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \ - $(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY)) + $(qom-obj-y) ROM_DIRS = $(addprefix pc-bios/, $(ROMS)) ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) diff --git a/Makefile.objs b/Makefile.objs index c4bc783a7d..6807c8b0d5 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -1,7 +1,7 @@ ####################################################################### # Common libraries for tools and emulators stub-obj-y = stubs/ util/ crypto/ -util-obj-y = util/ qobject/ qapi/ +util-obj-y = crypto/ util/ qobject/ qapi/ chardev-obj-y = chardev/ @@ -25,7 +25,6 @@ block-obj-m = block/ # crypto-obj-y is code used by both qemu system emulation and qemu-img crypto-obj-y = crypto/ -crypto-user-obj-y = crypto/ ####################################################################### # qom-obj-y is code used by both qemu system emulation and qemu-img diff --git a/Makefile.target b/Makefile.target index 24d79d26eb..6e61f607b1 100644 --- a/Makefile.target +++ b/Makefile.target @@ -184,7 +184,6 @@ dummy := $(call unnest-vars,.., \ block-obj-m \ chardev-obj-y \ crypto-obj-y \ - crypto-user-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -193,7 +192,6 @@ all-obj-y += $(common-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) -all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index cdb01f9de9..58014d175f 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -19,10 +19,6 @@ crypto-obj-y += tlscredspsk.o crypto-obj-y += tlscredsx509.o crypto-obj-y += tlssession.o crypto-obj-y += secret.o -crypto-rng-obj-$(CONFIG_GCRYPT) += random-gcrypt.o -crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o -crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o -crypto-obj-y += $(crypto-rng-obj-y) crypto-obj-y += pbkdf.o crypto-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o @@ -36,7 +32,9 @@ crypto-obj-y += block.o crypto-obj-y += block-qcow.o crypto-obj-y += block-luks.o -# Let the userspace emulators avoid linking stuff they won't use. -crypto-user-obj-y = aes.o $(crypto-rng-obj-y) init.o - stub-obj-y += pbkdf-stub.o + +util-obj-$(CONFIG_GCRYPT) += random-gcrypt.o +util-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o +util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o +util-obj-y += aes.o init.o From 44e9f2309fdb1315fc7d0a2f37eee3fecd471308 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 6 Aug 2019 15:12:18 +0200 Subject: [PATCH 41/87] stubs: replace stubs with lnot if applicable The stubs mechanism relies on static libraries and compilation order, which is a bit brittle and should be avoided unless necessary. Replace it with Boolean operations on CONFIG_* symbols. Signed-off-by: Paolo Bonzini --- Makefile.objs | 2 +- crypto/Makefile.objs | 3 +-- util/Makefile.objs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 6807c8b0d5..02bf5ce11d 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -1,6 +1,6 @@ ####################################################################### # Common libraries for tools and emulators -stub-obj-y = stubs/ util/ crypto/ +stub-obj-y = stubs/ util-obj-y = crypto/ util/ qobject/ qapi/ chardev-obj-y = chardev/ diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 58014d175f..c2a371b0b4 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -22,6 +22,7 @@ crypto-obj-y += secret.o crypto-obj-y += pbkdf.o crypto-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o +crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT),n,y)) += pbkdf-stub.o crypto-obj-y += ivgen.o crypto-obj-y += ivgen-essiv.o crypto-obj-y += ivgen-plain.o @@ -32,8 +33,6 @@ crypto-obj-y += block.o crypto-obj-y += block-qcow.o crypto-obj-y += block-luks.o -stub-obj-y += pbkdf-stub.o - util-obj-$(CONFIG_GCRYPT) += random-gcrypt.o util-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o diff --git a/util/Makefile.objs b/util/Makefile.objs index df124af1c5..63599d62aa 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -52,8 +52,7 @@ util-obj-y += stats64.o util-obj-y += systemd.o util-obj-y += iova-tree.o util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o +util-obj-$(call lnot,$(CONFIG_INOTIFY1)) += filemonitor-stub.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_POSIX) += drm.o util-obj-y += guest-random.o - -stub-obj-y += filemonitor-stub.o From 95c5f2debc867391a8c7dcc99be57dbab3dc6bda Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 10 Jun 2019 12:03:44 +0200 Subject: [PATCH 42/87] configure: set $PYTHON to a full path This will make it possible to replace it in a shebang line. Signed-off-by: Paolo Bonzini --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 0a63c75d36..2943f5dfb9 100755 --- a/configure +++ b/configure @@ -908,7 +908,7 @@ for binary in "${PYTHON-python3}" python python2 do if has "$binary" then - python="$binary" + python=$(command -v "$binary") break fi done From 21c6b0c87e85d952d3d0e569388526f03ad48576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 15 Aug 2019 17:13:06 +0400 Subject: [PATCH 43/87] configure: simplify vhost condition with Kconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau Signed-off-by: Paolo Bonzini --- Kconfig.host | 5 +++++ Makefile | 1 + hw/virtio/Kconfig | 3 +++ hw/virtio/Makefile.objs | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Kconfig.host b/Kconfig.host index bb6e116e2a..55136e037d 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -25,6 +25,11 @@ config TPM config VHOST_USER bool + select VHOST + +config VHOST_KERNEL + bool + select VHOST config XEN bool diff --git a/Makefile b/Makefile index fb1728e958..531e9555bf 100644 --- a/Makefile +++ b/Makefile @@ -382,6 +382,7 @@ MINIKCONF_ARGS = \ CONFIG_OPENGL=$(CONFIG_OPENGL) \ CONFIG_X11=$(CONFIG_X11) \ CONFIG_VHOST_USER=$(CONFIG_VHOST_USER) \ + CONFIG_VHOST_KERNEL=$(CONFIG_VHOST_KERNEL) \ CONFIG_VIRTFS=$(CONFIG_VIRTFS) \ CONFIG_LINUX=$(CONFIG_LINUX) \ CONFIG_PVRDMA=$(CONFIG_PVRDMA) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 3724ff8bac..f87def27a6 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -1,3 +1,6 @@ +config VHOST + bool + config VIRTIO bool diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index e2f70fbb89..de0f5fc39b 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -2,8 +2,8 @@ ifeq ($(CONFIG_VIRTIO),y) common-obj-y += virtio-bus.o obj-y += virtio.o -obj-$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL)) += vhost.o vhost-backend.o -common-obj-$(call lnot,$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL))) += vhost-stub.o +obj-$(CONFIG_VHOST) += vhost.o vhost-backend.o +common-obj-$(call lnot,$(CONFIG_VHOST)) += vhost-stub.o obj-$(CONFIG_VHOST_USER) += vhost-user.o common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o From feab2124a68ded981a3df60959df820d7a795687 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 11:52:37 +0100 Subject: [PATCH 44/87] i386: conditionally compile more files Reviewed-by: Sergio Lopez Signed-off-by: Paolo Bonzini --- hw/i386/Makefile.objs | 6 +++--- hw/i386/kvm/Makefile.objs | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 0d195b5210..01ae2028e2 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -1,11 +1,11 @@ obj-$(CONFIG_KVM) += kvm/ obj-y += e820_memory_layout.o multiboot.o obj-y += x86.o -obj-y += pc.o +obj-$(CONFIG_PC) += pc.o pc_sysfw.o obj-$(CONFIG_I440FX) += pc_piix.o obj-$(CONFIG_Q35) += pc_q35.o obj-$(CONFIG_MICROVM) += microvm.o -obj-y += fw_cfg.o pc_sysfw.o +obj-y += fw_cfg.o obj-y += x86-iommu.o obj-$(CONFIG_VTD) += intel_iommu.o obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o @@ -14,4 +14,4 @@ obj-$(CONFIG_VMPORT) += vmport.o obj-$(CONFIG_VMMOUSE) += vmmouse.o obj-y += kvmvapic.o -obj-y += acpi-build.o +obj-$(CONFIG_PC) += acpi-build.o diff --git a/hw/i386/kvm/Makefile.objs b/hw/i386/kvm/Makefile.objs index 4224ed900e..0c8d5f2dee 100644 --- a/hw/i386/kvm/Makefile.objs +++ b/hw/i386/kvm/Makefile.objs @@ -1 +1,5 @@ -obj-y += clock.o apic.o i8259.o ioapic.o i8254.o +obj-y += clock.o +obj-$(CONFIG_APIC) += apic.o +obj-$(CONFIG_IOAPIC) += ioapic.o +obj-$(CONFIG_I8254) += i8254.o +obj-$(CONFIG_I8259) += i8259.o From b54f33c4e07758f05ead2c27a2dcd1c1b87a34e7 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 14:12:27 +0100 Subject: [PATCH 45/87] fw_cfg: allow building without other devices The microvm machine type uses fw_cfg but lacks SMBIOS and ACPI. Do not include the files if the symbol is not present in QEMU and remove dependencies on machine-specific files. Reviewed-by: Sergio Lopez Signed-off-by: Paolo Bonzini --- hw/i386/fw_cfg.c | 7 +++++++ hw/i386/pc.c | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c index 39b6bc6052..326e33e2d1 100644 --- a/hw/i386/fw_cfg.c +++ b/hw/i386/fw_cfg.c @@ -22,6 +22,9 @@ #include "hw/nvram/fw_cfg.h" #include "e820_memory_layout.h" #include "kvm_i386.h" +#include "config-devices.h" + +struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX}; const char *fw_cfg_arch_key_name(uint16_t key) { @@ -46,6 +49,7 @@ const char *fw_cfg_arch_key_name(uint16_t key) void fw_cfg_build_smbios(MachineState *ms, FWCfgState *fw_cfg) { +#ifdef CONFIG_SMBIOS uint8_t *smbios_tables, *smbios_anchor; size_t smbios_tables_len, smbios_anchor_len; struct smbios_phys_mem_area *mem_array; @@ -83,6 +87,7 @@ void fw_cfg_build_smbios(MachineState *ms, FWCfgState *fw_cfg) fw_cfg_add_file(fw_cfg, "etc/smbios/smbios-anchor", smbios_anchor, smbios_anchor_len); } +#endif } FWCfgState *fw_cfg_arch_create(MachineState *ms, @@ -114,8 +119,10 @@ FWCfgState *fw_cfg_arch_create(MachineState *ms, */ fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, apic_id_limit); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); +#ifdef CONFIG_ACPI fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, acpi_tables, acpi_tables_len); +#endif fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override()); fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 58867f987d..4bb1710fa4 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -101,8 +101,6 @@ #define DPRINTF(fmt, ...) #endif -struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX}; - GlobalProperty pc_compat_4_2[] = {}; const size_t pc_compat_4_2_len = G_N_ELEMENTS(pc_compat_4_2); From 852c27e2ba99939e13a8e87f0d1a43aaec805f56 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 17:15:43 +0100 Subject: [PATCH 46/87] hw: replace hw/i386/pc.h with a header just for the i8259 Remove the need to include i386/pc.h to get to the i8259 functions. This is enough to remove the inclusion of hw/i386/pc.h from all non-x86 files. Signed-off-by: Paolo Bonzini --- hw/alpha/alpha_sys.h | 3 ++- hw/alpha/dp264.c | 1 + hw/hppa/hppa_sys.h | 3 ++- hw/hppa/machine.c | 1 + hw/i386/kvm/i8259.c | 1 + hw/i386/microvm.c | 1 + hw/i386/pc.c | 1 + hw/i386/x86.c | 1 + hw/input/pckbd.c | 1 - hw/intc/Kconfig | 2 ++ hw/intc/apic.c | 2 +- hw/intc/i8259.c | 2 +- hw/intc/i8259_common.c | 2 +- hw/intc/ioapic.c | 3 ++- hw/isa/i82378.c | 2 +- hw/isa/lpc_ich9.c | 1 - hw/isa/piix4.c | 2 +- hw/mips/gt64xxx_pci.c | 2 +- hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_jazz.c | 2 +- hw/mips/mips_r4k.c | 2 +- hw/pci-host/bonito.c | 1 - hw/pci-host/prep.c | 2 +- include/hw/i386/pc.h | 8 -------- include/hw/intc/i8259.h | 12 ++++++++++++ include/hw/isa/i8259_internal.h | 2 +- target/i386/monitor.c | 1 - 27 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 include/hw/intc/i8259.h diff --git a/hw/alpha/alpha_sys.h b/hw/alpha/alpha_sys.h index 4e127a6de8..95033d7f0b 100644 --- a/hw/alpha/alpha_sys.h +++ b/hw/alpha/alpha_sys.h @@ -7,7 +7,8 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_host.h" #include "hw/ide.h" -#include "hw/i386/pc.h" +#include "hw/boards.h" +#include "hw/intc/i8259.h" PCIBus *typhoon_init(ram_addr_t, ISABus **, qemu_irq *, AlphaCPU *[4], diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index 51b3cf7a61..f2026fda6d 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -19,6 +19,7 @@ #include "hw/timer/i8254.h" #include "hw/isa/superio.h" #include "hw/dma/i8257.h" +#include "net/net.h" #include "qemu/cutils.h" #define MAX_IDE_BUS 2 diff --git a/hw/hppa/hppa_sys.h b/hw/hppa/hppa_sys.h index 43d25d21fc..4e5019695e 100644 --- a/hw/hppa/hppa_sys.h +++ b/hw/hppa/hppa_sys.h @@ -6,7 +6,8 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_host.h" #include "hw/ide.h" -#include "hw/i386/pc.h" +#include "hw/boards.h" +#include "hw/intc/i8259.h" #include "hppa_hardware.h" diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index b30aba6d54..5d0de26140 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -19,6 +19,7 @@ #include "hppa_sys.h" #include "qemu/units.h" #include "qapi/error.h" +#include "net/net.h" #include "qemu/log.h" #define MAX_IDE_BUS 2 diff --git a/hw/i386/kvm/i8259.c b/hw/i386/kvm/i8259.c index d0c1b1deac..e404fdcdac 100644 --- a/hw/i386/kvm/i8259.c +++ b/hw/i386/kvm/i8259.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "hw/isa/i8259_internal.h" +#include "hw/intc/i8259.h" #include "qemu/module.h" #include "hw/i386/apic_internal.h" #include "hw/irq.h" diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index def37e60f7..20683191ba 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -34,6 +34,7 @@ #include "hw/i386/x86.h" #include "hw/i386/pc.h" #include "target/i386/cpu.h" +#include "hw/intc/i8259.h" #include "hw/timer/i8254.h" #include "hw/rtc/mc146818rtc.h" #include "hw/char/serial.h" diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4bb1710fa4..b4384e2db4 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -44,6 +44,7 @@ #include "migration/vmstate.h" #include "multiboot.h" #include "hw/rtc/mc146818rtc.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/timer/i8254.h" #include "hw/input/i8042.h" diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 394edc2f72..3e4aee5ac2 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -39,6 +39,7 @@ #include "target/i386/cpu.h" #include "hw/i386/topology.h" #include "hw/i386/fw_cfg.h" +#include "hw/intc/i8259.h" #include "hw/acpi/cpu_hotplug.h" #include "hw/nmi.h" diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index f0acfd86f7..2f09f780ba 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -26,7 +26,6 @@ #include "qemu/log.h" #include "hw/isa/isa.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" #include "hw/input/ps2.h" #include "hw/irq.h" #include "hw/input/i8042.h" diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 5347f8412c..10a680b53a 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -9,6 +9,7 @@ config PL190 config IOAPIC bool + select I8259 config ARM_GIC bool @@ -21,6 +22,7 @@ config OPENPIC config APIC bool select MSI_NONBROKEN + select I8259 config ARM_GIC_KVM bool diff --git a/hw/intc/apic.c b/hw/intc/apic.c index 2a74f7b4bf..bd40467965 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -22,10 +22,10 @@ #include "hw/i386/apic_internal.h" #include "hw/i386/apic.h" #include "hw/i386/ioapic.h" +#include "hw/intc/i8259.h" #include "hw/pci/msi.h" #include "qemu/host-utils.h" #include "trace.h" -#include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "qapi/error.h" diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index 211a98962e..51b27f6a34 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -23,7 +23,7 @@ */ #include "qemu/osdep.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/irq.h" #include "hw/isa/isa.h" #include "qemu/timer.h" diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c index bd37bb5e68..e7b1a10436 100644 --- a/hw/intc/i8259_common.c +++ b/hw/intc/i8259_common.c @@ -24,7 +24,7 @@ */ #include "qemu/osdep.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/isa/i8259_internal.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c index ead14e1888..4f5577678a 100644 --- a/hw/intc/ioapic.c +++ b/hw/intc/ioapic.c @@ -23,10 +23,11 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "monitor/monitor.h" -#include "hw/i386/pc.h" #include "hw/i386/apic.h" #include "hw/i386/ioapic.h" #include "hw/i386/ioapic_internal.h" +#include "hw/i386/x86.h" +#include "hw/intc/i8259.h" #include "hw/pci/msi.h" #include "hw/qdev-properties.h" #include "sysemu/kvm.h" diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c index de276cdf10..dcb6b479ea 100644 --- a/hw/isa/i82378.c +++ b/hw/isa/i82378.c @@ -19,8 +19,8 @@ #include "qemu/osdep.h" #include "hw/pci/pci.h" -#include "hw/i386/pc.h" #include "hw/irq.h" +#include "hw/intc/i8259.h" #include "hw/timer/i8254.h" #include "migration/vmstate.h" #include "hw/audio/pcspk.h" diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c index 17c292e306..170792a4fc 100644 --- a/hw/isa/lpc_ich9.c +++ b/hw/isa/lpc_ich9.c @@ -35,7 +35,6 @@ #include "hw/isa/isa.h" #include "hw/sysbus.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" #include "hw/irq.h" #include "hw/isa/apm.h" #include "hw/i386/ioapic.h" diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c index 86678e6829..7edec5e149 100644 --- a/hw/isa/piix4.c +++ b/hw/isa/piix4.c @@ -26,11 +26,11 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/irq.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/pci/pci.h" #include "hw/isa/isa.h" #include "hw/sysbus.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/timer/i8254.h" #include "hw/rtc/mc146818rtc.h" diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c index f1af840d8e..b2ea13f09d 100644 --- a/hw/mips/gt64xxx_pci.c +++ b/hw/mips/gt64xxx_pci.c @@ -30,7 +30,7 @@ #include "hw/pci/pci_host.h" #include "hw/southbridge/piix.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/irq.h" #include "exec/address-spaces.h" #include "trace.h" diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index 03a27e1767..9eaa6e2222 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -23,7 +23,7 @@ #include "qemu/units.h" #include "qapi/error.h" #include "cpu.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/isa/superio.h" #include "net/net.h" diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c index ac4d7acb2b..291fd6c1b8 100644 --- a/hw/mips/mips_jazz.c +++ b/hw/mips/mips_jazz.c @@ -26,7 +26,7 @@ #include "qemu-common.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/char/serial.h" #include "hw/char/parallel.h" diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c index 3891be657c..fd926a3575 100644 --- a/hw/mips/mips_r4k.c +++ b/hw/mips/mips_r4k.c @@ -15,7 +15,7 @@ #include "cpu.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/char/serial.h" #include "hw/isa/isa.h" #include "net/net.h" diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c index 4692d419e5..cc6545c8a8 100644 --- a/hw/pci-host/bonito.c +++ b/hw/pci-host/bonito.c @@ -41,7 +41,6 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "hw/pci/pci.h" -#include "hw/i386/pc.h" #include "hw/irq.h" #include "hw/mips/mips.h" #include "hw/pci/pci_host.h" diff --git a/hw/pci-host/prep.c b/hw/pci-host/prep.c index 85d7ba9037..afa136ded3 100644 --- a/hw/pci-host/prep.c +++ b/hw/pci-host/prep.c @@ -32,7 +32,7 @@ #include "hw/pci/pci_host.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/irq.h" #include "hw/loader.h" #include "hw/or-irq.h" diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 61a998de46..e2cd453ffa 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -134,14 +134,6 @@ typedef struct PCMachineClass { #define PC_MACHINE_CLASS(klass) \ OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE) -/* i8259.c */ - -extern DeviceState *isa_pic; -qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq); -qemu_irq *kvm_i8259_init(ISABus *bus); -int pic_read_irq(DeviceState *d); -int pic_get_output(DeviceState *d); - /* ioapic.c */ /* Global System Interrupts */ diff --git a/include/hw/intc/i8259.h b/include/hw/intc/i8259.h new file mode 100644 index 0000000000..e2b1e8c59a --- /dev/null +++ b/include/hw/intc/i8259.h @@ -0,0 +1,12 @@ +#ifndef HW_I8259_H +#define HW_I8259_H + +/* i8259.c */ + +extern DeviceState *isa_pic; +qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq); +qemu_irq *kvm_i8259_init(ISABus *bus); +int pic_get_output(DeviceState *d); +int pic_read_irq(DeviceState *d); + +#endif diff --git a/include/hw/isa/i8259_internal.h b/include/hw/isa/i8259_internal.h index ee189e4a77..861d70d8f8 100644 --- a/include/hw/isa/i8259_internal.h +++ b/include/hw/isa/i8259_internal.h @@ -25,9 +25,9 @@ #ifndef QEMU_I8259_INTERNAL_H #define QEMU_I8259_INTERNAL_H -#include "hw/i386/pc.h" #include "hw/isa/isa.h" #include "hw/intc/intc.h" +#include "hw/intc/i8259.h" typedef struct PICCommonState PICCommonState; diff --git a/target/i386/monitor.c b/target/i386/monitor.c index 9fb4d641d5..27ebfa3ad2 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -28,7 +28,6 @@ #include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "qapi/qmp/qdict.h" -#include "hw/i386/pc.h" #include "sysemu/kvm.h" #include "sysemu/sev.h" #include "qapi/error.h" From ec5ce147a63273bbc55ed1c52c1db41b0c5a7775 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 14:20:05 +0100 Subject: [PATCH 47/87] pci-stub: add more MSI functions On x86, KVM needs some function from the PCI subsystem in order to set up interrupt routes. Provide some stubs to support x86 machines that lack PCI. Reviewed-by: Sergio Lopez Signed-off-by: Paolo Bonzini --- hw/pci/pci-stub.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index c04a5df651..cc2a2e1f73 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -26,6 +26,7 @@ #include "qapi/qmp/qerror.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h" +#include "hw/pci/msix.h" bool msi_nonbroken; bool pci_available; @@ -64,3 +65,29 @@ void msi_notify(PCIDevice *dev, unsigned int vector) { g_assert_not_reached(); } + +/* Required by target/i386/kvm.c */ +bool msi_is_masked(const PCIDevice *dev, unsigned vector) +{ + g_assert_not_reached(); +} + +MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +{ + g_assert_not_reached(); +} + +int msix_enabled(PCIDevice *dev) +{ + return false; +} + +bool msix_is_masked(PCIDevice *dev, unsigned vector) +{ + g_assert_not_reached(); +} + +MSIMessage msix_get_message(PCIDevice *dev, unsigned int vector) +{ + g_assert_not_reached(); +} From ed9e923c3c9a2c50c4e82ba178b3fb1feba56867 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 17:28:01 +0100 Subject: [PATCH 48/87] x86: move SMM property to X86MachineState Add it to microvm as well, it is a generic property of the x86 architecture. Suggested-by: Sergio Lopez Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 49 ------------------------------------------ hw/i386/pc_piix.c | 6 +++--- hw/i386/pc_q35.c | 2 +- hw/i386/x86.c | 50 ++++++++++++++++++++++++++++++++++++++++++- include/hw/i386/pc.h | 3 --- include/hw/i386/x86.h | 5 +++++ target/i386/kvm.c | 3 +-- 7 files changed, 59 insertions(+), 59 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b4384e2db4..e330a916f6 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2031,48 +2031,6 @@ static void pc_machine_set_vmport(Object *obj, Visitor *v, const char *name, visit_type_OnOffAuto(v, name, &pcms->vmport, errp); } -bool pc_machine_is_smm_enabled(PCMachineState *pcms) -{ - bool smm_available = false; - - if (pcms->smm == ON_OFF_AUTO_OFF) { - return false; - } - - if (tcg_enabled() || qtest_enabled()) { - smm_available = true; - } else if (kvm_enabled()) { - smm_available = kvm_has_smm(); - } - - if (smm_available) { - return true; - } - - if (pcms->smm == ON_OFF_AUTO_ON) { - error_report("System Management Mode not supported by this hypervisor."); - exit(1); - } - return false; -} - -static void pc_machine_get_smm(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - OnOffAuto smm = pcms->smm; - - visit_type_OnOffAuto(v, name, &smm, errp); -} - -static void pc_machine_set_smm(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - - visit_type_OnOffAuto(v, name, &pcms->smm, errp); -} - static bool pc_machine_get_smbus(Object *obj, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); @@ -2119,7 +2077,6 @@ static void pc_machine_initfn(Object *obj) { PCMachineState *pcms = PC_MACHINE(obj); - pcms->smm = ON_OFF_AUTO_AUTO; #ifdef CONFIG_VMPORT pcms->vmport = ON_OFF_AUTO_AUTO; #else @@ -2226,12 +2183,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) pc_machine_get_device_memory_region_size, NULL, NULL, NULL, &error_abort); - object_class_property_add(oc, PC_MACHINE_SMM, "OnOffAuto", - pc_machine_get_smm, pc_machine_set_smm, - NULL, NULL, &error_abort); - object_class_property_set_description(oc, PC_MACHINE_SMM, - "Enable SMM (pc & q35)", &error_abort); - object_class_property_add(oc, PC_MACHINE_VMPORT, "OnOffAuto", pc_machine_get_vmport, pc_machine_set_vmport, NULL, NULL, &error_abort); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index ffb30c32ce..b3f0304ca3 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -281,7 +281,7 @@ else { /* TODO: Populate SPD eeprom data. */ pcms->smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, x86ms->gsi[9], smi_irq, - pc_machine_is_smm_enabled(pcms), + x86_machine_is_smm_enabled(x86ms), &piix4_pm); smbus_eeprom_init(pcms->smbus, 8, NULL, 0); @@ -309,9 +309,9 @@ else { static void pc_compat_2_3_fn(MachineState *machine) { - PCMachineState *pcms = PC_MACHINE(machine); + X86MachineState *x86ms = X86_MACHINE(machine); if (kvm_enabled()) { - pcms->smm = ON_OFF_AUTO_OFF; + x86ms->smm = ON_OFF_AUTO_OFF; } } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 7398d7baa2..52f45735e4 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -276,7 +276,7 @@ static void pc_q35_init(MachineState *machine) 0xff0104); /* connect pm stuff to lpc */ - ich9_lpc_pm_init(lpc, pc_machine_is_smm_enabled(pcms)); + ich9_lpc_pm_init(lpc, x86_machine_is_smm_enabled(x86ms)); if (pcms->sata_enabled) { /* ahci and SATA device, for q35 1 ahci controller is built-in */ diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 3e4aee5ac2..6fb01e41e7 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -746,10 +746,53 @@ static void x86_machine_set_max_ram_below_4g(Object *obj, Visitor *v, x86ms->max_ram_below_4g = value; } +bool x86_machine_is_smm_enabled(X86MachineState *x86ms) +{ + bool smm_available = false; + + if (x86ms->smm == ON_OFF_AUTO_OFF) { + return false; + } + + if (tcg_enabled() || qtest_enabled()) { + smm_available = true; + } else if (kvm_enabled()) { + smm_available = kvm_has_smm(); + } + + if (smm_available) { + return true; + } + + if (x86ms->smm == ON_OFF_AUTO_ON) { + error_report("System Management Mode not supported by this hypervisor."); + exit(1); + } + return false; +} + +static void x86_machine_get_smm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + OnOffAuto smm = x86ms->smm; + + visit_type_OnOffAuto(v, name, &smm, errp); +} + +static void x86_machine_set_smm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + + visit_type_OnOffAuto(v, name, &x86ms->smm, errp); +} + static void x86_machine_initfn(Object *obj) { X86MachineState *x86ms = X86_MACHINE(obj); + x86ms->smm = ON_OFF_AUTO_AUTO; x86ms->max_ram_below_4g = 0; /* use default */ x86ms->smp_dies = 1; } @@ -770,9 +813,14 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) object_class_property_add(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "size", x86_machine_get_max_ram_below_4g, x86_machine_set_max_ram_below_4g, NULL, NULL, &error_abort); - object_class_property_set_description(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "Maximum ram below the 4G boundary (32bit boundary)", &error_abort); + + object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto", + x86_machine_get_smm, x86_machine_set_smm, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, X86_MACHINE_SMM, + "Enable SMM", &error_abort); } static const TypeInfo x86_machine_info = { diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index e2cd453ffa..ade5a8577a 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -43,7 +43,6 @@ struct PCMachineState { /* Configuration options: */ OnOffAuto vmport; - OnOffAuto smm; bool acpi_build_enabled; bool smbus_enabled; @@ -61,7 +60,6 @@ struct PCMachineState { #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" #define PC_MACHINE_DEVMEM_REGION_SIZE "device-memory-region-size" #define PC_MACHINE_VMPORT "vmport" -#define PC_MACHINE_SMM "smm" #define PC_MACHINE_SMBUS "smbus" #define PC_MACHINE_SATA "sata" #define PC_MACHINE_PIT "pit" @@ -165,7 +163,6 @@ void vmmouse_set_data(const uint32_t *data); /* pc.c */ extern int fd_bootchk; -bool pc_machine_is_smm_enabled(PCMachineState *pcms); void pc_acpi_smi_interrupt(void *opaque, int irq, int level); void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp); diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 4b84917885..97d1575e63 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -60,6 +60,8 @@ typedef struct { uint16_t boot_cpus; unsigned smp_dies; + OnOffAuto smm; + /* * Address space used by IOAPIC device. All IOAPIC interrupts * will be translated to MSI messages in the address space. @@ -68,6 +70,7 @@ typedef struct { } X86MachineState; #define X86_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g" +#define X86_MACHINE_SMM "smm" #define TYPE_X86_MACHINE MACHINE_TYPE_NAME("x86") #define X86_MACHINE(obj) \ @@ -95,4 +98,6 @@ void x86_load_linux(X86MachineState *x86ms, bool pvh_enabled, bool linuxboot_dma_enabled); +bool x86_machine_is_smm_enabled(X86MachineState *x86ms); + #endif diff --git a/target/i386/kvm.c b/target/i386/kvm.c index ef63f3a5a6..c7ff67a28b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -2173,8 +2173,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } if (kvm_check_extension(s, KVM_CAP_X86_SMM) && - object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE) && - pc_machine_is_smm_enabled(PC_MACHINE(ms))) { + x86_machine_is_smm_enabled(X86_MACHINE(ms))) { smram_machine_done.notify = register_smram_listener; qemu_add_machine_init_done_notifier(&smram_machine_done); } From 4ca8dabdb8b58349c309cfd9624d3f96172a752b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 13 Dec 2019 11:50:57 +0100 Subject: [PATCH 49/87] hw/i386/pc: Convert DPRINTF() to trace events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert the deprecated DPRINTF() macro to trace events. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 19 +++++-------------- hw/i386/trace-events | 6 ++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e330a916f6..d3075e709c 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -91,16 +91,7 @@ #include "config-devices.h" #include "e820_memory_layout.h" #include "fw_cfg.h" - -/* debug PC/ISA interrupts */ -//#define DEBUG_IRQ - -#ifdef DEBUG_IRQ -#define DPRINTF(fmt, ...) \ - do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) -#endif +#include "trace.h" GlobalProperty pc_compat_4_2[] = {}; const size_t pc_compat_4_2_len = G_N_ELEMENTS(pc_compat_4_2); @@ -350,7 +341,7 @@ void gsi_handler(void *opaque, int n, int level) { GSIState *s = opaque; - DPRINTF("pc: %s GSI %d\n", level ? "raising" : "lowering", n); + trace_pc_gsi_interrupt(n, level); if (n < ISA_NUM_IRQS) { qemu_set_irq(s->i8259_irq[n], level); } @@ -428,7 +419,7 @@ static void pic_irq_request(void *opaque, int irq, int level) CPUState *cs = first_cpu; X86CPU *cpu = X86_CPU(cs); - DPRINTF("pic_irqs: %s irq %d\n", level? "raise" : "lower", irq); + trace_pc_pic_interrupt(irq, level); if (cpu->apic_state && !kvm_irqchip_in_kernel()) { CPU_FOREACH(cs) { cpu = X86_CPU(cs); @@ -762,7 +753,7 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val, Port92State *s = opaque; int oldval = s->outport; - DPRINTF("port92: write 0x%02" PRIx64 "\n", val); + trace_port92_write(val); s->outport = val; qemu_set_irq(s->a20_out, (val >> 1) & 1); if ((val & 1) && !(oldval & 1)) { @@ -777,7 +768,7 @@ static uint64_t port92_read(void *opaque, hwaddr addr, uint32_t ret; ret = s->outport; - DPRINTF("port92: read 0x%02x\n", ret); + trace_port92_read(ret); return ret; } diff --git a/hw/i386/trace-events b/hw/i386/trace-events index c8bc464bc5..43f33cf7e2 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -111,3 +111,9 @@ amdvi_ir_irte_ga_val(uint64_t hi, uint64_t lo) "hi 0x%"PRIx64" lo 0x%"PRIx64 # vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p" vmport_command(unsigned char command) "command: 0x%02x" + +# pc.c +pc_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" +pc_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" +port92_read(uint8_t val) "port92: read 0x%02x" +port92_write(uint8_t val) "port92: write 0x%02x" From 89a289c7e9fa857f8b0af0c5f060efa7c0ebe6ba Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 14:14:40 +0100 Subject: [PATCH 50/87] x86: move more x86-generic functions out of PC files These are needed by microvm too, so move them outside of PC-specific files. With this patch, microvm.c need not include pc.h anymore. Signed-off-by: Paolo Bonzini --- hw/i386/acpi-build.c | 1 + hw/i386/fw_cfg.c | 1 - hw/i386/fw_cfg.h | 2 + hw/i386/kvm/ioapic.c | 2 +- hw/i386/microvm.c | 3 +- hw/i386/pc.c | 101 +---------------------------------------- hw/i386/trace-events | 6 ++- hw/i386/x86.c | 103 ++++++++++++++++++++++++++++++++++++++++++ include/hw/i386/pc.h | 20 -------- include/hw/i386/x86.h | 18 ++++++++ target/i386/kvm.c | 2 +- target/i386/machine.c | 2 +- 12 files changed, 133 insertions(+), 128 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 12ff55fcfb..7b8da62d41 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -53,6 +53,7 @@ /* Supported chipsets: */ #include "hw/southbridge/piix.h" #include "hw/acpi/pcihp.h" +#include "hw/i386/fw_cfg.h" #include "hw/i386/ich9.h" #include "hw/pci/pci_bus.h" #include "hw/pci-host/q35.h" diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c index 326e33e2d1..da60ada594 100644 --- a/hw/i386/fw_cfg.c +++ b/hw/i386/fw_cfg.c @@ -16,7 +16,6 @@ #include "sysemu/numa.h" #include "hw/acpi/acpi.h" #include "hw/firmware/smbios.h" -#include "hw/i386/pc.h" #include "hw/i386/fw_cfg.h" #include "hw/timer/hpet.h" #include "hw/nvram/fw_cfg.h" diff --git a/hw/i386/fw_cfg.h b/hw/i386/fw_cfg.h index e0856a3769..9e74278779 100644 --- a/hw/i386/fw_cfg.h +++ b/hw/i386/fw_cfg.h @@ -12,6 +12,8 @@ #include "hw/boards.h" #include "hw/nvram/fw_cfg.h" +#define FW_CFG_IO_BASE 0x510 + #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0) #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1) #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2) diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c index f94729c565..8703f19b43 100644 --- a/hw/i386/kvm/ioapic.c +++ b/hw/i386/kvm/ioapic.c @@ -12,7 +12,7 @@ #include "qemu/osdep.h" #include "monitor/monitor.h" -#include "hw/i386/pc.h" +#include "hw/i386/x86.h" #include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/i386/ioapic_internal.h" diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 20683191ba..827ce29e58 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -32,7 +32,6 @@ #include "hw/kvm/clock.h" #include "hw/i386/microvm.h" #include "hw/i386/x86.h" -#include "hw/i386/pc.h" #include "target/i386/cpu.h" #include "hw/intc/i8259.h" #include "hw/timer/i8254.h" @@ -133,7 +132,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) { qemu_irq *i8259; - i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq()); + i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); for (i = 0; i < ISA_NUM_IRQS; i++) { gsi_state->i8259_irq[i] = i8259[i]; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d3075e709c..dff09e473a 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -337,17 +337,6 @@ GlobalProperty pc_compat_1_4[] = { }; const size_t pc_compat_1_4_len = G_N_ELEMENTS(pc_compat_1_4); -void gsi_handler(void *opaque, int n, int level) -{ - GSIState *s = opaque; - - trace_pc_gsi_interrupt(n, level); - if (n < ISA_NUM_IRQS) { - qemu_set_irq(s->i8259_irq[n], level); - } - qemu_set_irq(s->ioapic_irq[n], level); -} - GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled) { GSIState *s; @@ -387,55 +376,6 @@ static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size) return 0xffffffffffffffffULL; } -/* TSC handling */ -uint64_t cpu_get_tsc(CPUX86State *env) -{ - return cpu_get_ticks(); -} - -/* IRQ handling */ -int cpu_get_pic_interrupt(CPUX86State *env) -{ - X86CPU *cpu = env_archcpu(env); - int intno; - - if (!kvm_irqchip_in_kernel()) { - intno = apic_get_interrupt(cpu->apic_state); - if (intno >= 0) { - return intno; - } - /* read the irq from the PIC */ - if (!apic_accept_pic_intr(cpu->apic_state)) { - return -1; - } - } - - intno = pic_read_irq(isa_pic); - return intno; -} - -static void pic_irq_request(void *opaque, int irq, int level) -{ - CPUState *cs = first_cpu; - X86CPU *cpu = X86_CPU(cs); - - trace_pc_pic_interrupt(irq, level); - if (cpu->apic_state && !kvm_irqchip_in_kernel()) { - CPU_FOREACH(cs) { - cpu = X86_CPU(cs); - if (apic_accept_pic_intr(cpu->apic_state)) { - apic_deliver_pic_intr(cpu->apic_state, level); - } - } - } else { - if (level) { - cpu_interrupt(cs, CPU_INTERRUPT_HARD); - } else { - cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); - } - } -} - /* PC cmos mappings */ #define REG_EQUIPMENT_BYTE 0x14 @@ -879,16 +819,6 @@ void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) nb_ne2k++; } -DeviceState *cpu_get_current_apic(void) -{ - if (current_cpu) { - X86CPU *cpu = X86_CPU(current_cpu); - return cpu->apic_state; - } else { - return NULL; - } -} - void pc_acpi_smi_interrupt(void *opaque, int irq, int level) { X86CPU *cpu = opaque; @@ -1284,11 +1214,6 @@ uint64_t pc_pci_hole64_start(void) return ROUND_UP(hole64_start, 1 * GiB); } -qemu_irq pc_allocate_cpu_irq(void) -{ - return qemu_allocate_irq(pic_irq_request, NULL, 0); -} - DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus) { DeviceState *dev = NULL; @@ -1465,7 +1390,7 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs) } else if (xen_enabled()) { i8259 = xen_interrupt_controller_init(); } else { - i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq()); + i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); } for (size_t i = 0; i < ISA_NUM_IRQS; i++) { @@ -1475,30 +1400,6 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs) g_free(i8259); } -void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) -{ - DeviceState *dev; - SysBusDevice *d; - unsigned int i; - - if (kvm_ioapic_in_kernel()) { - dev = qdev_create(NULL, TYPE_KVM_IOAPIC); - } else { - dev = qdev_create(NULL, TYPE_IOAPIC); - } - if (parent_name) { - object_property_add_child(object_resolve_path(parent_name, NULL), - "ioapic", OBJECT(dev), NULL); - } - qdev_init_nofail(dev); - d = SYS_BUS_DEVICE(dev); - sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); - - for (i = 0; i < IOAPIC_NUM_PINS; i++) { - gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); - } -} - static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 43f33cf7e2..a9b6437050 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -112,8 +112,10 @@ amdvi_ir_irte_ga_val(uint64_t hi, uint64_t lo) "hi 0x%"PRIx64" lo 0x%"PRIx64 vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p" vmport_command(unsigned char command) "command: 0x%02x" +# x86.c +x86_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" +x86_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" + # pc.c -pc_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" -pc_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" port92_read(uint8_t val) "port92: read 0x%02x" port92_write(uint8_t val) "port92: write 0x%02x" diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 6fb01e41e7..80e33be1a2 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -34,6 +34,7 @@ #include "sysemu/numa.h" #include "sysemu/replay.h" #include "sysemu/sysemu.h" +#include "trace.h" #include "hw/i386/x86.h" #include "target/i386/cpu.h" @@ -42,11 +43,14 @@ #include "hw/intc/i8259.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/irq.h" #include "hw/nmi.h" #include "hw/loader.h" #include "multiboot.h" #include "elf.h" #include "standard-headers/asm-x86/bootparam.h" +#include "config-devices.h" +#include "kvm_i386.h" #define BIOS_FILENAME "bios.bin" @@ -221,6 +225,105 @@ static long get_file_size(FILE *f) return size; } +/* TSC handling */ +uint64_t cpu_get_tsc(CPUX86State *env) +{ + return cpu_get_ticks(); +} + +/* IRQ handling */ +static void pic_irq_request(void *opaque, int irq, int level) +{ + CPUState *cs = first_cpu; + X86CPU *cpu = X86_CPU(cs); + + trace_x86_pic_interrupt(irq, level); + if (cpu->apic_state && !kvm_irqchip_in_kernel()) { + CPU_FOREACH(cs) { + cpu = X86_CPU(cs); + if (apic_accept_pic_intr(cpu->apic_state)) { + apic_deliver_pic_intr(cpu->apic_state, level); + } + } + } else { + if (level) { + cpu_interrupt(cs, CPU_INTERRUPT_HARD); + } else { + cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); + } + } +} + +qemu_irq x86_allocate_cpu_irq(void) +{ + return qemu_allocate_irq(pic_irq_request, NULL, 0); +} + +int cpu_get_pic_interrupt(CPUX86State *env) +{ + X86CPU *cpu = env_archcpu(env); + int intno; + + if (!kvm_irqchip_in_kernel()) { + intno = apic_get_interrupt(cpu->apic_state); + if (intno >= 0) { + return intno; + } + /* read the irq from the PIC */ + if (!apic_accept_pic_intr(cpu->apic_state)) { + return -1; + } + } + + intno = pic_read_irq(isa_pic); + return intno; +} + +DeviceState *cpu_get_current_apic(void) +{ + if (current_cpu) { + X86CPU *cpu = X86_CPU(current_cpu); + return cpu->apic_state; + } else { + return NULL; + } +} + +void gsi_handler(void *opaque, int n, int level) +{ + GSIState *s = opaque; + + trace_x86_gsi_interrupt(n, level); + if (n < ISA_NUM_IRQS) { + qemu_set_irq(s->i8259_irq[n], level); + } + qemu_set_irq(s->ioapic_irq[n], level); +} + +void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) +{ + DeviceState *dev; + SysBusDevice *d; + unsigned int i; + + if (kvm_ioapic_in_kernel()) { + dev = qdev_create(NULL, TYPE_KVM_IOAPIC); + } else { + dev = qdev_create(NULL, TYPE_IOAPIC); + } + if (parent_name) { + object_property_add_child(object_resolve_path(parent_name, NULL), + "ioapic", OBJECT(dev), NULL); + } + qdev_init_nofail(dev); + d = SYS_BUS_DEVICE(dev); + sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); + + for (i = 0; i < IOAPIC_NUM_PINS; i++) { + gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); + } +} + struct setup_data { uint64_t next; uint32_t type; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index ade5a8577a..58aaa231e3 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -3,11 +3,9 @@ #include "exec/memory.h" #include "hw/boards.h" -#include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/block/flash.h" #include "net/net.h" -#include "hw/i386/ioapic.h" #include "hw/i386/x86.h" #include "qemu/range.h" @@ -134,17 +132,6 @@ typedef struct PCMachineClass { /* ioapic.c */ -/* Global System Interrupts */ - -#define GSI_NUM_PINS IOAPIC_NUM_PINS - -typedef struct GSIState { - qemu_irq i8259_irq[ISA_NUM_IRQS]; - qemu_irq ioapic_irq[IOAPIC_NUM_PINS]; -} GSIState; - -void gsi_handler(void *opaque, int n, int level); - GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled); /* vmport.c */ @@ -188,7 +175,6 @@ void pc_memory_init(PCMachineState *pcms, MemoryRegion *rom_memory, MemoryRegion **ram_memory); uint64_t pc_pci_hole64_start(void); -qemu_irq pc_allocate_cpu_irq(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, ISADevice **rtc_state, @@ -206,18 +192,12 @@ void pc_pci_device_init(PCIBus *pci_bus); typedef void (*cpu_set_smm_t)(int smm, void *arg); void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); -void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); ISADevice *pc_find_fdc0(void); int cmos_get_fd_drive_type(FloppyDriveType fd0); -#define FW_CFG_IO_BASE 0x510 - #define PORT92_A20_LINE "a20" -/* hpet.c */ -extern int no_hpet; - /* pc_sysfw.c */ void pc_system_flash_create(PCMachineState *pcms); void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory); diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 97d1575e63..41fe37b8a3 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -23,6 +23,8 @@ #include "hw/boards.h" #include "hw/nmi.h" +#include "hw/isa/isa.h" +#include "hw/i386/ioapic.h" typedef struct { /*< private >*/ @@ -100,4 +102,20 @@ void x86_load_linux(X86MachineState *x86ms, bool x86_machine_is_smm_enabled(X86MachineState *x86ms); +/* Global System Interrupts */ + +#define GSI_NUM_PINS IOAPIC_NUM_PINS + +typedef struct GSIState { + qemu_irq i8259_irq[ISA_NUM_IRQS]; + qemu_irq ioapic_irq[IOAPIC_NUM_PINS]; +} GSIState; + +qemu_irq x86_allocate_cpu_irq(void); +void gsi_handler(void *opaque, int n, int level); +void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); + +/* hpet.c */ +extern int no_hpet; + #endif diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c7ff67a28b..55e626590b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -35,7 +35,7 @@ #include "qemu/main-loop.h" #include "qemu/config-file.h" #include "qemu/error-report.h" -#include "hw/i386/pc.h" +#include "hw/i386/x86.h" #include "hw/i386/apic.h" #include "hw/i386/apic_internal.h" #include "hw/i386/apic-msidef.h" diff --git a/target/i386/machine.c b/target/i386/machine.c index 2699eed94e..b6720d86b0 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1,10 +1,10 @@ #include "qemu/osdep.h" #include "cpu.h" #include "exec/exec-all.h" -#include "hw/i386/pc.h" #include "hw/isa/isa.h" #include "migration/cpu.h" #include "hyperv.h" +#include "hw/i386/x86.h" #include "kvm_i386.h" #include "sysemu/kvm.h" From e0c0965f0739becb2942b0866d520d80366c2f65 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 18:03:46 +0100 Subject: [PATCH 51/87] acpi: move PC stubs out of stubs/ This is a small cleanup that lets microvm build entirely without include/hw/i386/pc.h. Signed-off-by: Paolo Bonzini --- hw/acpi/Makefile.objs | 3 ++- stubs/pc_madt_cpu_entry.c => hw/acpi/acpi-x86-stub.c | 0 stubs/Makefile.objs | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) rename stubs/pc_madt_cpu_entry.c => hw/acpi/acpi-x86-stub.c (100%) diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 655a9c1973..99253057e1 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -8,6 +8,7 @@ common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o +common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o common-obj-y += acpi_interface.o common-obj-y += bios-linker-loader.o @@ -20,4 +21,4 @@ common-obj-$(call lnot,$(CONFIG_IPMI)) += ipmi-stub.o else common-obj-y += acpi-stub.o endif -common-obj-$(CONFIG_ALL) += acpi-stub.o ipmi-stub.o +common-obj-$(CONFIG_ALL) += acpi-stub.o acpi-x86-stub.o ipmi-stub.o diff --git a/stubs/pc_madt_cpu_entry.c b/hw/acpi/acpi-x86-stub.c similarity index 100% rename from stubs/pc_madt_cpu_entry.c rename to hw/acpi/acpi-x86-stub.c diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 4a50e95ec3..8b0ff25508 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -33,7 +33,6 @@ stub-obj-y += fd-register.o stub-obj-y += qmp_memory_device.o stub-obj-y += target-monitor-defs.o stub-obj-y += target-get-monitor-def.o -stub-obj-y += pc_madt_cpu_entry.o stub-obj-y += vmgenid.o stub-obj-y += xen-common.o stub-obj-y += xen-hvm.o From 6c730e4af9b64b6c83b233f285ec3649747f7eda Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 12 Dec 2019 18:10:35 +0100 Subject: [PATCH 52/87] pc: stubify x86 iommu Allow building microvm without x86-iommu.c. Signed-off-by: Paolo Bonzini --- hw/i386/Kconfig | 6 ++++++ hw/i386/Makefile.objs | 3 ++- hw/i386/x86-iommu-stub.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 hw/i386/x86-iommu-stub.c diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 5a494342ea..91cf5843b4 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -103,11 +103,17 @@ config MICROVM select MC146818RTC select VIRTIO_MMIO +config X86_IOMMU + bool + depends on PC + config VTD bool + select X86_IOMMU config AMD_IOMMU bool + select X86_IOMMU config VMPORT bool diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 01ae2028e2..1236c3b95c 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -6,7 +6,8 @@ obj-$(CONFIG_I440FX) += pc_piix.o obj-$(CONFIG_Q35) += pc_q35.o obj-$(CONFIG_MICROVM) += microvm.o obj-y += fw_cfg.o -obj-y += x86-iommu.o +obj-$(CONFIG_X86_IOMMU) += x86-iommu.o +obj-$(call lnot,$(CONFIG_X86_IOMMU)) += x86-iommu-stub.o obj-$(CONFIG_VTD) += intel_iommu.o obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ diff --git a/hw/i386/x86-iommu-stub.c b/hw/i386/x86-iommu-stub.c new file mode 100644 index 0000000000..03576cdccb --- /dev/null +++ b/hw/i386/x86-iommu-stub.c @@ -0,0 +1,34 @@ +/* + * Stubs for X86 IOMMU emulation + * + * Copyright (C) 2019 Red Hat, Inc. + * + * Author: Paolo Bonzini + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/i386/x86-iommu.h" + +void x86_iommu_iec_register_notifier(X86IOMMUState *iommu, + iec_notify_fn fn, void *data) +{ +} + +X86IOMMUState *x86_iommu_get_default(void) +{ + return NULL; +} + From 64c033badda77d81d7c949fc6e3ed6c72dd5c92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 13 Dec 2019 12:07:36 +0100 Subject: [PATCH 53/87] hw/i386: De-duplicate gsi_handler() to remove kvm_pc_gsi_handler() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both gsi_handler() and kvm_pc_gsi_handler() have the same content, except one comment. Move the comment, and de-duplicate the code. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/kvm/ioapic.c | 12 ------------ hw/i386/pc.c | 4 +--- hw/i386/x86.c | 1 + include/sysemu/kvm.h | 1 - 4 files changed, 2 insertions(+), 16 deletions(-) diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c index 8703f19b43..973e2b2af1 100644 --- a/hw/i386/kvm/ioapic.c +++ b/hw/i386/kvm/ioapic.c @@ -48,18 +48,6 @@ void kvm_pc_setup_irq_routing(bool pci_enabled) } } -void kvm_pc_gsi_handler(void *opaque, int n, int level) -{ - GSIState *s = opaque; - - if (n < ISA_NUM_IRQS) { - /* Kernel will forward to both PIC and IOAPIC */ - qemu_set_irq(s->i8259_irq[n], level); - } else { - qemu_set_irq(s->ioapic_irq[n], level); - } -} - typedef struct KVMIOAPICState KVMIOAPICState; struct KVMIOAPICState { diff --git a/hw/i386/pc.c b/hw/i386/pc.c index dff09e473a..ea7320b91b 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -344,10 +344,8 @@ GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled) s = g_new0(GSIState, 1); if (kvm_ioapic_in_kernel()) { kvm_pc_setup_irq_routing(pci_enabled); - *irqs = qemu_allocate_irqs(kvm_pc_gsi_handler, s, GSI_NUM_PINS); - } else { - *irqs = qemu_allocate_irqs(gsi_handler, s, GSI_NUM_PINS); } + *irqs = qemu_allocate_irqs(gsi_handler, s, GSI_NUM_PINS); return s; } diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 80e33be1a2..d18a3ef03d 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -295,6 +295,7 @@ void gsi_handler(void *opaque, int n, int level) trace_x86_gsi_interrupt(n, level); if (n < ISA_NUM_IRQS) { + /* Under KVM, Kernel will forward to both PIC and IOAPIC */ qemu_set_irq(s->i8259_irq[n], level); } qemu_set_irq(s->ioapic_irq[n], level); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index aaf2a502e8..141342de98 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -515,7 +515,6 @@ int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, qemu_irq irq); void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi); -void kvm_pc_gsi_handler(void *opaque, int n, int level); void kvm_pc_setup_irq_routing(bool pci_enabled); void kvm_init_irq_routing(KVMState *s); From 14a1bb48ea48d541ea6f373c12fb7e88d2c89d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 13 Dec 2019 12:11:45 +0100 Subject: [PATCH 54/87] hw/i386: Simplify ioapic_init_gsi() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All callers of ioapic_init_gsi() provide a parent. We want new uses to follow the same good practice and provide the parent name, so do not make this optional: assert the parent name is provided, and simplify the code. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/x86.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index d18a3ef03d..d8bb5c2a96 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -307,15 +307,14 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) SysBusDevice *d; unsigned int i; + assert(parent_name); if (kvm_ioapic_in_kernel()) { dev = qdev_create(NULL, TYPE_KVM_IOAPIC); } else { dev = qdev_create(NULL, TYPE_IOAPIC); } - if (parent_name) { - object_property_add_child(object_resolve_path(parent_name, NULL), - "ioapic", OBJECT(dev), NULL); - } + object_property_add_child(object_resolve_path(parent_name, NULL), + "ioapic", OBJECT(dev), NULL); qdev_init_nofail(dev); d = SYS_BUS_DEVICE(dev); sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); From 3c29e188415e81c32a9107ecb2616fc6b967abc5 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 13 Dec 2019 13:00:43 +0100 Subject: [PATCH 55/87] hw/isa/isa-bus: cleanup irq functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The irq number is unsigned; we reject negative values. But -1 is used for the isairq array, which is declared unsigned! And since we have a definition for the number of ISA IRQs, use it. Based on a patch by Philippe Mathieu-Daudé. Signed-off-by: Paolo Bonzini --- hw/isa/isa-bus.c | 11 +++++++---- include/hw/isa/isa.h | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index 388800603b..798dd9194e 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -82,24 +82,27 @@ void isa_bus_irqs(ISABus *bus, qemu_irq *irqs) * This function is only for special cases such as the 'ferr', and * temporary use for normal devices until they are converted to qdev. */ -qemu_irq isa_get_irq(ISADevice *dev, int isairq) +qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq) { assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus); - if (isairq < 0 || isairq > 15) { + if (isairq >= ISA_NUM_IRQS) { hw_error("isa irq %d invalid", isairq); } return isabus->irqs[isairq]; } -void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) +void isa_init_irq(ISADevice *dev, qemu_irq *p, unsigned isairq) { assert(dev->nirqs < ARRAY_SIZE(dev->isairq)); + if (isairq >= ISA_NUM_IRQS) { + hw_error("isa irq %d invalid", isairq); + } dev->isairq[dev->nirqs] = isairq; *p = isa_get_irq(dev, isairq); dev->nirqs++; } -void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq) +void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq) { qemu_irq irq; isa_init_irq(isadev, &irq, isairq); diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h index 79f703fd6c..e9ac1f1205 100644 --- a/include/hw/isa/isa.h +++ b/include/hw/isa/isa.h @@ -88,7 +88,7 @@ struct ISADevice { DeviceState parent_obj; /*< public >*/ - uint32_t isairq[2]; + int8_t isairq[2]; /* -1 = unassigned */ int nirqs; int ioport_id; }; @@ -96,9 +96,9 @@ struct ISADevice { ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space, MemoryRegion *address_space_io, Error **errp); void isa_bus_irqs(ISABus *bus, qemu_irq *irqs); -qemu_irq isa_get_irq(ISADevice *dev, int isairq); -void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq); -void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq); +qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq); +void isa_init_irq(ISADevice *dev, qemu_irq *p, unsigned isairq); +void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq); void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16); IsaDma *isa_get_dma(ISABus *bus, int nchan); MemoryRegion *isa_address_space(ISADevice *dev); From 9e5213c8be63cdc806d1739d48148cd5f1444526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 13 Dec 2019 11:50:58 +0100 Subject: [PATCH 56/87] hw/i386/pc: Use TYPE_PORT92 instead of hardcoded string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By using the TYPE_* definitions for devices, we can: - quickly find where devices are used with 'git-grep' - easily rename a device (one-line change). Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ea7320b91b..67fddcc8c9 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1278,7 +1278,7 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport) qdev_prop_set_ptr(dev, "ps2_mouse", i8042); qdev_init_nofail(dev); } - port92 = isa_create_simple(isa_bus, "port92"); + port92 = isa_create_simple(isa_bus, TYPE_PORT92); a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2); i8042_setup_a20_line(i8042, a20_line[0]); From 1820b70eb3fd8acf25d22485a58d0def8ad72234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 13 Dec 2019 11:50:59 +0100 Subject: [PATCH 57/87] hw/i386/pc: Inline port92_init() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This one-line function is not very helpful, so remove it by inlining the call to qdev_connect_gpio_out_named(). Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 67fddcc8c9..e36053f2a7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -710,11 +710,6 @@ static uint64_t port92_read(void *opaque, hwaddr addr, return ret; } -static void port92_init(ISADevice *dev, qemu_irq a20_out) -{ - qdev_connect_gpio_out_named(DEVICE(dev), PORT92_A20_LINE, 0, a20_out); -} - static const VMStateDescription vmstate_port92_isa = { .name = "port92", .version_id = 1, @@ -770,8 +765,8 @@ static void port92_class_initfn(ObjectClass *klass, void *data) dc->vmsd = &vmstate_port92_isa; /* * Reason: unlike ordinary ISA devices, this one needs additional - * wiring: its A20 output line needs to be wired up by - * port92_init(). + * wiring: its A20 output line needs to be wired up with + * qdev_connect_gpio_out_named(). */ dc->user_creatable = false; } @@ -1282,7 +1277,8 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport) a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2); i8042_setup_a20_line(i8042, a20_line[0]); - port92_init(port92, a20_line[1]); + qdev_connect_gpio_out_named(DEVICE(port92), + PORT92_A20_LINE, 0, a20_line[1]); g_free(a20_line); } From d3e07dc83e98127a130a29878c7c652d05eaaf18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 13 Dec 2019 11:51:00 +0100 Subject: [PATCH 58/87] hw/i386/pc: Extract the port92 device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This device is only used by the PC machines. The pc.c file is already big enough, with 2255 lines. By removing 113 lines of it, we reduced it by 5%. It is now a bit easier to navigate the file. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- hw/i386/Makefile.objs | 1 + hw/i386/pc.c | 113 ------------------------------------- hw/i386/port92.c | 126 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/trace-events | 2 +- include/hw/i386/pc.h | 3 + 5 files changed, 131 insertions(+), 114 deletions(-) create mode 100644 hw/i386/port92.c diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 1236c3b95c..8ce1b26533 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -13,6 +13,7 @@ obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-$(CONFIG_VMPORT) += vmport.o obj-$(CONFIG_VMMOUSE) += vmmouse.o +obj-$(CONFIG_PC) += port92.o obj-y += kvmvapic.o obj-$(CONFIG_PC) += acpi-build.o diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e36053f2a7..42014b06de 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -673,119 +673,6 @@ void pc_cmos_init(PCMachineState *pcms, qemu_register_reset(pc_cmos_init_late, &arg); } -#define TYPE_PORT92 "port92" -#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) - -/* port 92 stuff: could be split off */ -typedef struct Port92State { - ISADevice parent_obj; - - MemoryRegion io; - uint8_t outport; - qemu_irq a20_out; -} Port92State; - -static void port92_write(void *opaque, hwaddr addr, uint64_t val, - unsigned size) -{ - Port92State *s = opaque; - int oldval = s->outport; - - trace_port92_write(val); - s->outport = val; - qemu_set_irq(s->a20_out, (val >> 1) & 1); - if ((val & 1) && !(oldval & 1)) { - qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); - } -} - -static uint64_t port92_read(void *opaque, hwaddr addr, - unsigned size) -{ - Port92State *s = opaque; - uint32_t ret; - - ret = s->outport; - trace_port92_read(ret); - return ret; -} - -static const VMStateDescription vmstate_port92_isa = { - .name = "port92", - .version_id = 1, - .minimum_version_id = 1, - .fields = (VMStateField[]) { - VMSTATE_UINT8(outport, Port92State), - VMSTATE_END_OF_LIST() - } -}; - -static void port92_reset(DeviceState *d) -{ - Port92State *s = PORT92(d); - - s->outport &= ~1; -} - -static const MemoryRegionOps port92_ops = { - .read = port92_read, - .write = port92_write, - .impl = { - .min_access_size = 1, - .max_access_size = 1, - }, - .endianness = DEVICE_LITTLE_ENDIAN, -}; - -static void port92_initfn(Object *obj) -{ - Port92State *s = PORT92(obj); - - memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); - - s->outport = 0; - - qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); -} - -static void port92_realizefn(DeviceState *dev, Error **errp) -{ - ISADevice *isadev = ISA_DEVICE(dev); - Port92State *s = PORT92(dev); - - isa_register_ioport(isadev, &s->io, 0x92); -} - -static void port92_class_initfn(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - - dc->realize = port92_realizefn; - dc->reset = port92_reset; - dc->vmsd = &vmstate_port92_isa; - /* - * Reason: unlike ordinary ISA devices, this one needs additional - * wiring: its A20 output line needs to be wired up with - * qdev_connect_gpio_out_named(). - */ - dc->user_creatable = false; -} - -static const TypeInfo port92_info = { - .name = TYPE_PORT92, - .parent = TYPE_ISA_DEVICE, - .instance_size = sizeof(Port92State), - .instance_init = port92_initfn, - .class_init = port92_class_initfn, -}; - -static void port92_register_types(void) -{ - type_register_static(&port92_info); -} - -type_init(port92_register_types) - static void handle_a20_line_change(void *opaque, int irq, int level) { X86CPU *cpu = opaque; diff --git a/hw/i386/port92.c b/hw/i386/port92.c new file mode 100644 index 0000000000..19866c44ef --- /dev/null +++ b/hw/i386/port92.c @@ -0,0 +1,126 @@ +/* + * QEMU I/O port 0x92 (System Control Port A, to handle Fast Gate A20) + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * SPDX-License-Identifier: MIT + */ + +#include "qemu/osdep.h" +#include "sysemu/runstate.h" +#include "migration/vmstate.h" +#include "hw/irq.h" +#include "hw/i386/pc.h" +#include "trace.h" + +#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) + +typedef struct Port92State { + ISADevice parent_obj; + + MemoryRegion io; + uint8_t outport; + qemu_irq a20_out; +} Port92State; + +static void port92_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + Port92State *s = opaque; + int oldval = s->outport; + + trace_port92_write(val); + s->outport = val; + qemu_set_irq(s->a20_out, (val >> 1) & 1); + if ((val & 1) && !(oldval & 1)) { + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + } +} + +static uint64_t port92_read(void *opaque, hwaddr addr, + unsigned size) +{ + Port92State *s = opaque; + uint32_t ret; + + ret = s->outport; + trace_port92_read(ret); + + return ret; +} + +static const VMStateDescription vmstate_port92_isa = { + .name = "port92", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(outport, Port92State), + VMSTATE_END_OF_LIST() + } +}; + +static void port92_reset(DeviceState *d) +{ + Port92State *s = PORT92(d); + + s->outport &= ~1; +} + +static const MemoryRegionOps port92_ops = { + .read = port92_read, + .write = port92_write, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static void port92_initfn(Object *obj) +{ + Port92State *s = PORT92(obj); + + memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); + + s->outport = 0; + + qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); +} + +static void port92_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE(dev); + Port92State *s = PORT92(dev); + + isa_register_ioport(isadev, &s->io, 0x92); +} + +static void port92_class_initfn(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = port92_realizefn; + dc->reset = port92_reset; + dc->vmsd = &vmstate_port92_isa; + /* + * Reason: unlike ordinary ISA devices, this one needs additional + * wiring: its A20 output line needs to be wired up with + * qdev_connect_gpio_out_named(). + */ + dc->user_creatable = false; +} + +static const TypeInfo port92_info = { + .name = TYPE_PORT92, + .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(Port92State), + .instance_init = port92_initfn, + .class_init = port92_class_initfn, +}; + +static void port92_register_types(void) +{ + type_register_static(&port92_info); +} + +type_init(port92_register_types) diff --git a/hw/i386/trace-events b/hw/i386/trace-events index a9b6437050..e48bef2b0d 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -116,6 +116,6 @@ vmport_command(unsigned char command) "command: 0x%02x" x86_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" x86_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" -# pc.c +# port92.c port92_read(uint8_t val) "port92: read 0x%02x" port92_write(uint8_t val) "port92: write 0x%02x" diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 58aaa231e3..d5ac76d54e 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -196,8 +196,11 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); ISADevice *pc_find_fdc0(void); int cmos_get_fd_drive_type(FloppyDriveType fd0); +/* port92.c */ #define PORT92_A20_LINE "a20" +#define TYPE_PORT92 "port92" + /* pc_sysfw.c */ void pc_system_flash_create(PCMachineState *pcms); void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory); From b66173afbde1d99961e1698f0c957a74bd5bfc5a Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Fri, 13 Dec 2019 13:19:30 +0000 Subject: [PATCH 59/87] hyperv: Use auto rcu_read macros Use RCU_READ_LOCK_GUARD and WITH_RCU_READ_LOCK_GUARD to replace the manual rcu_read_(un)lock calls. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- hw/hyperv/hyperv.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 6ebf31c310..da8ce82725 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -546,14 +546,14 @@ uint16_t hyperv_hcall_post_message(uint64_t param, bool fast) } ret = HV_STATUS_INVALID_CONNECTION_ID; - rcu_read_lock(); - QLIST_FOREACH_RCU(mh, &msg_handlers, link) { - if (mh->conn_id == (msg->connection_id & HV_CONNECTION_ID_MASK)) { - ret = mh->handler(msg, mh->data); - break; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH_RCU(mh, &msg_handlers, link) { + if (mh->conn_id == (msg->connection_id & HV_CONNECTION_ID_MASK)) { + ret = mh->handler(msg, mh->data); + break; + } } } - rcu_read_unlock(); unmap: cpu_physical_memory_unmap(msg, len, 0, 0); @@ -619,7 +619,6 @@ int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) { - uint16_t ret; EventFlagHandler *handler; if (unlikely(!fast)) { @@ -645,15 +644,12 @@ uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) return HV_STATUS_INVALID_HYPERCALL_INPUT; } - ret = HV_STATUS_INVALID_CONNECTION_ID; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); QLIST_FOREACH_RCU(handler, &event_flag_handlers, link) { if (handler->conn_id == param) { event_notifier_set(handler->notifier); - ret = 0; - break; + return 0; } } - rcu_read_unlock(); - return ret; + return HV_STATUS_INVALID_CONNECTION_ID; } From 2a86be257166652b3e4c189c7e2d471e9ab2947f Mon Sep 17 00:00:00 2001 From: "Dr. David Alan Gilbert" Date: Fri, 13 Dec 2019 13:19:31 +0000 Subject: [PATCH 60/87] qsp: Use WITH_RCU_READ_LOCK_GUARD The automatic rcu read lock maintenance works quite nicely in this case where it previously relied on a comment to delimit the lifetime and now has a block. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- util/qsp.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/util/qsp.c b/util/qsp.c index 62265417fd..7d5147f1b2 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -598,7 +598,6 @@ static void qsp_ht_delete(void *p, uint32_t h, void *htp) static void qsp_mktree(GTree *tree, bool callsite_coalesce) { - QSPSnapshot *snap; struct qht ht, coalesce_ht; struct qht *htp; @@ -610,20 +609,19 @@ static void qsp_mktree(GTree *tree, bool callsite_coalesce) * We must remain in an RCU read-side critical section until we're done * with the snapshot. */ - rcu_read_lock(); - snap = atomic_rcu_read(&qsp_snapshot); + WITH_RCU_READ_LOCK_GUARD() { + QSPSnapshot *snap = atomic_rcu_read(&qsp_snapshot); - /* Aggregate all results from the global hash table into a local one */ - qht_init(&ht, qsp_entry_no_thread_cmp, QSP_INITIAL_SIZE, - QHT_MODE_AUTO_RESIZE | QHT_MODE_RAW_MUTEXES); - qht_iter(&qsp_ht, qsp_aggregate, &ht); + /* Aggregate all results from the global hash table into a local one */ + qht_init(&ht, qsp_entry_no_thread_cmp, QSP_INITIAL_SIZE, + QHT_MODE_AUTO_RESIZE | QHT_MODE_RAW_MUTEXES); + qht_iter(&qsp_ht, qsp_aggregate, &ht); - /* compute the difference wrt the snapshot, if any */ - if (snap) { - qsp_diff(&snap->ht, &ht); + /* compute the difference wrt the snapshot, if any */ + if (snap) { + qsp_diff(&snap->ht, &ht); + } } - /* done with the snapshot; RCU can reclaim it */ - rcu_read_unlock(); htp = &ht; if (callsite_coalesce) { From 293a733df783c242f2e67abb16e8ab180e7d5eed Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 13 Dec 2019 15:06:45 +0100 Subject: [PATCH 61/87] memory: use RCU_READ_LOCK_GUARD Cc: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 27a84e0cc3..9d3fdb5696 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2171,7 +2171,7 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, if (__builtin_constant_p(len)) { if (len) { - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); fv = address_space_to_flatview(as); l = len; mr = flatview_translate(fv, addr, &addr1, &l, false, attrs); @@ -2182,7 +2182,6 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, result = flatview_read_continue(fv, addr, attrs, buf, len, addr1, l, mr); } - rcu_read_unlock(); } } else { result = address_space_read_full(as, addr, attrs, buf, len); From 44901b5aff4e013783a0cfb9c743cc2ce900f019 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 13 Dec 2019 15:07:22 +0100 Subject: [PATCH 62/87] colo: fix return without releasing RCU Use WITH_RCU_READ_LOCK_GUARD to avoid exiting colo_init_ram_cache without releasing RCU. Cc: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- migration/ram.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 219e3caa03..96feb4062c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3890,26 +3890,27 @@ int colo_init_ram_cache(void) { RAMBlock *block; - rcu_read_lock(); - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - block->colo_cache = qemu_anon_ram_alloc(block->used_length, - NULL, - false); - if (!block->colo_cache) { - error_report("%s: Can't alloc memory for COLO cache of block %s," - "size 0x" RAM_ADDR_FMT, __func__, block->idstr, - block->used_length); - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - if (block->colo_cache) { - qemu_anon_ram_free(block->colo_cache, block->used_length); - block->colo_cache = NULL; + WITH_RCU_READ_LOCK_GUARD() { + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + block->colo_cache = qemu_anon_ram_alloc(block->used_length, + NULL, + false); + if (!block->colo_cache) { + error_report("%s: Can't alloc memory for COLO cache of block %s," + "size 0x" RAM_ADDR_FMT, __func__, block->idstr, + block->used_length); + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + if (block->colo_cache) { + qemu_anon_ram_free(block->colo_cache, block->used_length); + block->colo_cache = NULL; + } } + return -errno; } - return -errno; + memcpy(block->colo_cache, block->host, block->used_length); } - memcpy(block->colo_cache, block->host, block->used_length); } - rcu_read_unlock(); + /* * Record the dirty pages that sent by PVM, we use this dirty bitmap together * with to decide which page in cache should be flushed into SVM's RAM. Here From a358bca24026a377e0804e137a4499e4e041918d Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 29 Nov 2019 11:42:53 +0100 Subject: [PATCH 63/87] build: rename CONFIG_LIBCAP to CONFIG_LIBCAP_NG Since we are actually testing for the newer capng library, rename the symbol to match. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- configure | 2 +- qemu-bridge-helper.c | 6 +++--- scsi/qemu-pr-helper.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/configure b/configure index 2943f5dfb9..5723a29070 100755 --- a/configure +++ b/configure @@ -6720,7 +6720,7 @@ if test "$l2tpv3" = "yes" ; then echo "CONFIG_L2TPV3=y" >> $config_host_mak fi if test "$cap_ng" = "yes" ; then - echo "CONFIG_LIBCAP=y" >> $config_host_mak + echo "CONFIG_LIBCAP_NG=y" >> $config_host_mak fi echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak for drv in $audio_drv_list; do diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 3d50ec094c..88b26747fc 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -43,7 +43,7 @@ #include "net/tap-linux.h" -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG #include #endif @@ -207,7 +207,7 @@ static int send_fd(int c, int fd) return sendmsg(c, &msg, 0); } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int drop_privileges(void) { /* clear all capabilities */ @@ -246,7 +246,7 @@ int main(int argc, char **argv) int access_allowed, access_denied; int ret = EXIT_SUCCESS; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG /* if we're run from an suid binary, immediately drop privileges preserving * cap_net_admin */ if (geteuid() == 0 && getuid() != geteuid()) { diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index debb18f4aa..0659ceef09 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -24,7 +24,7 @@ #include #include -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG #include #endif #include @@ -70,7 +70,7 @@ static int num_active_sockets = 1; static int noisy; static int verbose; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int uid = -1; static int gid = -1; #endif @@ -97,7 +97,7 @@ static void usage(const char *name) " (default '%s')\n" " -T, --trace [[enable=]][,events=][,file=]\n" " specify tracing options\n" -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG " -u, --user=USER user to drop privileges to\n" " -g, --group=GROUP group to drop privileges to\n" #endif @@ -827,7 +827,7 @@ static void close_server_socket(void) num_active_sockets--; } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int drop_privileges(void) { /* clear all capabilities */ @@ -920,7 +920,7 @@ int main(int argc, char **argv) pidfile = g_strdup(optarg); pidfile_specified = true; break; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG case 'u': { unsigned long res; struct passwd *userinfo = getpwnam(optarg); @@ -1056,7 +1056,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG if (drop_privileges() < 0) { error_report("Failed to drop privileges: %s", strerror(errno)); exit(EXIT_FAILURE); From e2c546358f0eaccc001f457a9eec0ecbe9d3bed7 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 29 Oct 2019 17:22:43 +0100 Subject: [PATCH 64/87] docs: import Linux kernel-doc script and extension Import Linux's kernel-doc script as of commit 15e2544ed38a1e, as well as the Sphinx extension to call kernel-doc according to the arguments and parameters given to a reStructuredText directive. The kernel-doc extension accepts a filename, which is relative to the QEMU source tree root. The extension also notifies Sphinx about the document dependency on the file, causing the document to be rebuilt when the file has been changed. Signed-off-by: Paolo Bonzini --- docs/sphinx/kerneldoc.py | 172 +++ docs/sphinx/kernellog.py | 28 + scripts/kernel-doc | 2226 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 2426 insertions(+) create mode 100644 docs/sphinx/kerneldoc.py create mode 100644 docs/sphinx/kernellog.py create mode 100755 scripts/kernel-doc diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py new file mode 100644 index 0000000000..1159405cb9 --- /dev/null +++ b/docs/sphinx/kerneldoc.py @@ -0,0 +1,172 @@ +# coding=utf-8 +# +# Copyright © 2016 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# Authors: +# Jani Nikula +# +# Please make sure this works on both python2 and python3. +# + +import codecs +import os +import subprocess +import sys +import re +import glob + +from docutils import nodes, statemachine +from docutils.statemachine import ViewList +from docutils.parsers.rst import directives, Directive + +# +# AutodocReporter is only good up to Sphinx 1.7 +# +import sphinx + +Use_SSI = sphinx.__version__[:3] >= '1.7' +if Use_SSI: + from sphinx.util.docutils import switch_source_input +else: + from sphinx.ext.autodoc import AutodocReporter + +import kernellog + +__version__ = '1.0' + +class KernelDocDirective(Directive): + """Extract kernel-doc comments from the specified file""" + required_argument = 1 + optional_arguments = 4 + option_spec = { + 'doc': directives.unchanged_required, + 'functions': directives.unchanged, + 'export': directives.unchanged, + 'internal': directives.unchanged, + } + has_content = False + + def run(self): + env = self.state.document.settings.env + cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno'] + + filename = env.config.kerneldoc_srctree + '/' + self.arguments[0] + export_file_patterns = [] + + # Tell sphinx of the dependency + env.note_dependency(os.path.abspath(filename)) + + tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) + + # FIXME: make this nicer and more robust against errors + if 'export' in self.options: + cmd += ['-export'] + export_file_patterns = str(self.options.get('export')).split() + elif 'internal' in self.options: + cmd += ['-internal'] + export_file_patterns = str(self.options.get('internal')).split() + elif 'doc' in self.options: + cmd += ['-function', str(self.options.get('doc'))] + elif 'functions' in self.options: + functions = self.options.get('functions').split() + if functions: + for f in functions: + cmd += ['-function', f] + else: + cmd += ['-no-doc-sections'] + + for pattern in export_file_patterns: + for f in glob.glob(env.config.kerneldoc_srctree + '/' + pattern): + env.note_dependency(os.path.abspath(f)) + cmd += ['-export-file', f] + + cmd += [filename] + + try: + kernellog.verbose(env.app, + 'calling kernel-doc \'%s\'' % (" ".join(cmd))) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + + out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8') + + if p.returncode != 0: + sys.stderr.write(err) + + kernellog.warn(env.app, + 'kernel-doc \'%s\' failed with return code %d' % (" ".join(cmd), p.returncode)) + return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] + elif env.config.kerneldoc_verbosity > 0: + sys.stderr.write(err) + + lines = statemachine.string2lines(out, tab_width, convert_whitespace=True) + result = ViewList() + + lineoffset = 0; + line_regex = re.compile("^#define LINENO ([0-9]+)$") + for line in lines: + match = line_regex.search(line) + if match: + # sphinx counts lines from 0 + lineoffset = int(match.group(1)) - 1 + # we must eat our comments since the upset the markup + else: + result.append(line, filename, lineoffset) + lineoffset += 1 + + node = nodes.section() + self.do_parse(result, node) + + return node.children + + except Exception as e: # pylint: disable=W0703 + kernellog.warn(env.app, 'kernel-doc \'%s\' processing failed with: %s' % + (" ".join(cmd), str(e))) + return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] + + def do_parse(self, result, node): + if Use_SSI: + with switch_source_input(self.state, result): + self.state.nested_parse(result, 0, node, match_titles=1) + else: + save = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter + self.state.memo.reporter = AutodocReporter(result, self.state.memo.reporter) + self.state.memo.title_styles, self.state.memo.section_level = [], 0 + try: + self.state.nested_parse(result, 0, node, match_titles=1) + finally: + self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = save + + +def setup(app): + app.add_config_value('kerneldoc_bin', None, 'env') + app.add_config_value('kerneldoc_srctree', None, 'env') + app.add_config_value('kerneldoc_verbosity', 1, 'env') + + app.add_directive('kernel-doc', KernelDocDirective) + + return dict( + version = __version__, + parallel_read_safe = True, + parallel_write_safe = True + ) diff --git a/docs/sphinx/kernellog.py b/docs/sphinx/kernellog.py new file mode 100644 index 0000000000..af924f51a7 --- /dev/null +++ b/docs/sphinx/kernellog.py @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Sphinx has deprecated its older logging interface, but the replacement +# only goes back to 1.6. So here's a wrapper layer to keep around for +# as long as we support 1.4. +# +import sphinx + +if sphinx.__version__[:3] >= '1.6': + UseLogging = True + from sphinx.util import logging + logger = logging.getLogger('kerneldoc') +else: + UseLogging = False + +def warn(app, message): + if UseLogging: + logger.warning(message) + else: + app.warn(message) + +def verbose(app, message): + if UseLogging: + logger.verbose(message) + else: + app.verbose(message) + + diff --git a/scripts/kernel-doc b/scripts/kernel-doc new file mode 100755 index 0000000000..81dc91760b --- /dev/null +++ b/scripts/kernel-doc @@ -0,0 +1,2226 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## +## Copyright (C) 2000, 1 Tim Waugh ## +## Copyright (C) 2001 Simon Huggins ## +## Copyright (C) 2005-2012 Randy Dunlap ## +## Copyright (C) 2012 Dan Luedtke ## +## ## +## #define enhancements by Armin Kuster ## +## Copyright (c) 2000 MontaVista Software, Inc. ## +## ## +## This software falls under the GNU General Public License. ## +## Please read the COPYING file for more information ## + +# 18/01/2001 - Cleanups +# Functions prototyped as foo(void) same as foo() +# Stop eval'ing where we don't need to. +# -- huggie@earth.li + +# 27/06/2001 - Allowed whitespace after initial "/**" and +# allowed comments before function declarations. +# -- Christian Kreibich + +# Still to do: +# - add perldoc documentation +# - Look more closely at some of the scarier bits :) + +# 26/05/2001 - Support for separate source and object trees. +# Return error code. +# Keith Owens + +# 23/09/2001 - Added support for typedefs, structs, enums and unions +# Support for Context section; can be terminated using empty line +# Small fixes (like spaces vs. \s in regex) +# -- Tim Jansen + +# 25/07/2012 - Added support for HTML5 +# -- Dan Luedtke + +sub usage { + my $message = <<"EOF"; +Usage: $0 [OPTION ...] FILE ... + +Read C language source or header FILEs, extract embedded documentation comments, +and print formatted documentation to standard output. + +The documentation comments are identified by "/**" opening comment mark. See +Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. + +Output format selection (mutually exclusive): + -man Output troff manual page format. This is the default. + -rst Output reStructuredText format. + -none Do not output documentation, only warnings. + +Output selection (mutually exclusive): + -export Only output documentation for symbols that have been + exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() + in any input FILE or -export-file FILE. + -internal Only output documentation for symbols that have NOT been + exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() + in any input FILE or -export-file FILE. + -function NAME Only output documentation for the given function(s) + or DOC: section title(s). All other functions and DOC: + sections are ignored. May be specified multiple times. + -nofunction NAME Do NOT output documentation for the given function(s); + only output documentation for the other functions and + DOC: sections. May be specified multiple times. + +Output selection modifiers: + -no-doc-sections Do not output DOC: sections. + -enable-lineno Enable output of #define LINENO lines. Only works with + reStructuredText format. + -export-file FILE Specify an additional FILE in which to look for + EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with + -export or -internal. May be specified multiple times. + +Other parameters: + -v Verbose output, more warnings and other information. + -h Print this help. + +EOF + print $message; + exit 1; +} + +# +# format of comments. +# In the following table, (...)? signifies optional structure. +# (...)* signifies 0 or more structure elements +# /** +# * function_name(:)? (- short description)? +# (* @parameterx: (description of parameter x)?)* +# (* a blank line)? +# * (Description:)? (Description of function)? +# * (section header: (section description)? )* +# (*)?*/ +# +# So .. the trivial example would be: +# +# /** +# * my_function +# */ +# +# If the Description: header tag is omitted, then there must be a blank line +# after the last parameter specification. +# e.g. +# /** +# * my_function - does my stuff +# * @my_arg: its mine damnit +# * +# * Does my stuff explained. +# */ +# +# or, could also use: +# /** +# * my_function - does my stuff +# * @my_arg: its mine damnit +# * Description: Does my stuff explained. +# */ +# etc. +# +# Besides functions you can also write documentation for structs, unions, +# enums and typedefs. Instead of the function name you must write the name +# of the declaration; the struct/union/enum/typedef must always precede +# the name. Nesting of declarations is not supported. +# Use the argument mechanism to document members or constants. +# e.g. +# /** +# * struct my_struct - short description +# * @a: first member +# * @b: second member +# * +# * Longer description +# */ +# struct my_struct { +# int a; +# int b; +# /* private: */ +# int c; +# }; +# +# All descriptions can be multiline, except the short function description. +# +# For really longs structs, you can also describe arguments inside the +# body of the struct. +# eg. +# /** +# * struct my_struct - short description +# * @a: first member +# * @b: second member +# * +# * Longer description +# */ +# struct my_struct { +# int a; +# int b; +# /** +# * @c: This is longer description of C +# * +# * You can use paragraphs to describe arguments +# * using this method. +# */ +# int c; +# }; +# +# This should be use only for struct/enum members. +# +# You can also add additional sections. When documenting kernel functions you +# should document the "Context:" of the function, e.g. whether the functions +# can be called form interrupts. Unlike other sections you can end it with an +# empty line. +# A non-void function should have a "Return:" section describing the return +# value(s). +# Example-sections should contain the string EXAMPLE so that they are marked +# appropriately in DocBook. +# +# Example: +# /** +# * user_function - function that can only be called in user context +# * @a: some argument +# * Context: !in_interrupt() +# * +# * Some description +# * Example: +# * user_function(22); +# */ +# ... +# +# +# All descriptive text is further processed, scanning for the following special +# patterns, which are highlighted appropriately. +# +# 'funcname()' - function +# '$ENVVAR' - environmental variable +# '&struct_name' - name of a structure (up to two words including 'struct') +# '&struct_name.member' - name of a structure member +# '@parameter' - name of a parameter +# '%CONST' - name of a constant. +# '``LITERAL``' - literal string without any spaces on it. + +## init lots of data + +my $errors = 0; +my $warnings = 0; +my $anon_struct_union = 0; + +# match expressions used to find embedded type information +my $type_constant = '\b``([^\`]+)``\b'; +my $type_constant2 = '\%([-_\w]+)'; +my $type_func = '(\w+)\(\)'; +my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; +my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params +my $type_env = '(\$\w+)'; +my $type_enum = '\&(enum\s*([_\w]+))'; +my $type_struct = '\&(struct\s*([_\w]+))'; +my $type_typedef = '\&(typedef\s*([_\w]+))'; +my $type_union = '\&(union\s*([_\w]+))'; +my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; +my $type_fallback = '\&([_\w]+)'; +my $type_member_func = $type_member . '\(\)'; + +# Output conversion substitutions. +# One for each output format + +# these are pretty rough +my @highlights_man = ( + [$type_constant, "\$1"], + [$type_constant2, "\$1"], + [$type_func, "\\\\fB\$1\\\\fP"], + [$type_enum, "\\\\fI\$1\\\\fP"], + [$type_struct, "\\\\fI\$1\\\\fP"], + [$type_typedef, "\\\\fI\$1\\\\fP"], + [$type_union, "\\\\fI\$1\\\\fP"], + [$type_param, "\\\\fI\$1\\\\fP"], + [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], + [$type_fallback, "\\\\fI\$1\\\\fP"] + ); +my $blankline_man = ""; + +# rst-mode +my @highlights_rst = ( + [$type_constant, "``\$1``"], + [$type_constant2, "``\$1``"], + # Note: need to escape () to avoid func matching later + [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], + [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], + [$type_fp_param, "**\$1\\\\(\\\\)**"], + [$type_func, "\$1()"], + [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], + [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], + [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], + [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], + # in rst this can refer to any type + [$type_fallback, "\\:c\\:type\\:`\$1`"], + [$type_param, "**\$1**"] + ); +my $blankline_rst = "\n"; + +# read arguments +if ($#ARGV == -1) { + usage(); +} + +my $kernelversion; +my $dohighlight = ""; + +my $verbose = 0; +my $output_mode = "rst"; +my $output_preformatted = 0; +my $no_doc_sections = 0; +my $enable_lineno = 0; +my @highlights = @highlights_rst; +my $blankline = $blankline_rst; +my $modulename = "Kernel API"; + +use constant { + OUTPUT_ALL => 0, # output all symbols and doc sections + OUTPUT_INCLUDE => 1, # output only specified symbols + OUTPUT_EXCLUDE => 2, # output everything except specified symbols + OUTPUT_EXPORTED => 3, # output exported symbols + OUTPUT_INTERNAL => 4, # output non-exported symbols +}; +my $output_selection = OUTPUT_ALL; +my $show_not_found = 0; # No longer used + +my @export_file_list; + +my @build_time; +if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && + (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { + @build_time = gmtime($seconds); +} else { + @build_time = localtime; +} + +my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', + 'July', 'August', 'September', 'October', + 'November', 'December')[$build_time[4]] . + " " . ($build_time[5]+1900); + +# Essentially these are globals. +# They probably want to be tidied up, made more localised or something. +# CAVEAT EMPTOR! Some of the others I localised may not want to be, which +# could cause "use of undefined value" or other bugs. +my ($function, %function_table, %parametertypes, $declaration_purpose); +my $declaration_start_line; +my ($type, $declaration_name, $return_type); +my ($newsection, $newcontents, $prototype, $brcount, %source_map); + +if (defined($ENV{'KBUILD_VERBOSE'})) { + $verbose = "$ENV{'KBUILD_VERBOSE'}"; +} + +# Generated docbook code is inserted in a template at a point where +# docbook v3.1 requires a non-zero sequence of RefEntry's; see: +# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html +# We keep track of number of generated entries and generate a dummy +# if needs be to ensure the expanded template can be postprocessed +# into html. +my $section_counter = 0; + +my $lineprefix=""; + +# Parser states +use constant { + STATE_NORMAL => 0, # normal code + STATE_NAME => 1, # looking for function name + STATE_BODY_MAYBE => 2, # body - or maybe more description + STATE_BODY => 3, # the body of the comment + STATE_PROTO => 4, # scanning prototype + STATE_DOCBLOCK => 5, # documentation block + STATE_INLINE => 6, # gathering documentation outside main block +}; +my $state; +my $in_doc_sect; +my $leading_space; + +# Inline documentation state +use constant { + STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) + STATE_INLINE_NAME => 1, # looking for member name (@foo:) + STATE_INLINE_TEXT => 2, # looking for member documentation + STATE_INLINE_END => 3, # done + STATE_INLINE_ERROR => 4, # error - Comment without header was found. + # Spit a warning as it's not + # proper kernel-doc and ignore the rest. +}; +my $inline_doc_state; + +#declaration types: can be +# 'function', 'struct', 'union', 'enum', 'typedef' +my $decl_type; + +my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. +my $doc_end = '\*/'; +my $doc_com = '\s*\*\s*'; +my $doc_com_body = '\s*\* ?'; +my $doc_decl = $doc_com . '(\w+)'; +# @params and a strictly limited set of supported section names +my $doc_sect = $doc_com . + '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; +my $doc_content = $doc_com_body . '(.*)'; +my $doc_block = $doc_com . 'DOC:\s*(.*)?'; +my $doc_inline_start = '^\s*/\*\*\s*$'; +my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; +my $doc_inline_end = '^\s*\*/\s*$'; +my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; +my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; + +my %parameterdescs; +my %parameterdesc_start_lines; +my @parameterlist; +my %sections; +my @sectionlist; +my %section_start_lines; +my $sectcheck; +my $struct_actual; + +my $contents = ""; +my $new_start_line = 0; + +# the canonical section names. see also $doc_sect above. +my $section_default = "Description"; # default section +my $section_intro = "Introduction"; +my $section = $section_default; +my $section_context = "Context"; +my $section_return = "Return"; + +my $undescribed = "-- undescribed --"; + +reset_state(); + +while ($ARGV[0] =~ m/^--?(.*)/) { + my $cmd = $1; + shift @ARGV; + if ($cmd eq "man") { + $output_mode = "man"; + @highlights = @highlights_man; + $blankline = $blankline_man; + } elsif ($cmd eq "rst") { + $output_mode = "rst"; + @highlights = @highlights_rst; + $blankline = $blankline_rst; + } elsif ($cmd eq "none") { + $output_mode = "none"; + } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document + $modulename = shift @ARGV; + } elsif ($cmd eq "function") { # to only output specific functions + $output_selection = OUTPUT_INCLUDE; + $function = shift @ARGV; + $function_table{$function} = 1; + } elsif ($cmd eq "nofunction") { # output all except specific functions + $output_selection = OUTPUT_EXCLUDE; + $function = shift @ARGV; + $function_table{$function} = 1; + } elsif ($cmd eq "export") { # only exported symbols + $output_selection = OUTPUT_EXPORTED; + %function_table = (); + } elsif ($cmd eq "internal") { # only non-exported symbols + $output_selection = OUTPUT_INTERNAL; + %function_table = (); + } elsif ($cmd eq "export-file") { + my $file = shift @ARGV; + push(@export_file_list, $file); + } elsif ($cmd eq "v") { + $verbose = 1; + } elsif (($cmd eq "h") || ($cmd eq "help")) { + usage(); + } elsif ($cmd eq 'no-doc-sections') { + $no_doc_sections = 1; + } elsif ($cmd eq 'enable-lineno') { + $enable_lineno = 1; + } elsif ($cmd eq 'show-not-found') { + $show_not_found = 1; # A no-op but don't fail + } else { + # Unknown argument + usage(); + } +} + +# continue execution near EOF; + +# get kernel version from env +sub get_kernel_version() { + my $version = 'unknown kernel version'; + + if (defined($ENV{'KERNELVERSION'})) { + $version = $ENV{'KERNELVERSION'}; + } + return $version; +} + +# +sub print_lineno { + my $lineno = shift; + if ($enable_lineno && defined($lineno)) { + print "#define LINENO " . $lineno . "\n"; + } +} +## +# dumps section contents to arrays/hashes intended for that purpose. +# +sub dump_section { + my $file = shift; + my $name = shift; + my $contents = join "\n", @_; + + if ($name =~ m/$type_param/) { + $name = $1; + $parameterdescs{$name} = $contents; + $sectcheck = $sectcheck . $name . " "; + $parameterdesc_start_lines{$name} = $new_start_line; + $new_start_line = 0; + } elsif ($name eq "@\.\.\.") { + $name = "..."; + $parameterdescs{$name} = $contents; + $sectcheck = $sectcheck . $name . " "; + $parameterdesc_start_lines{$name} = $new_start_line; + $new_start_line = 0; + } else { + if (defined($sections{$name}) && ($sections{$name} ne "")) { + # Only warn on user specified duplicate section names. + if ($name ne $section_default) { + print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; + ++$warnings; + } + $sections{$name} .= $contents; + } else { + $sections{$name} = $contents; + push @sectionlist, $name; + $section_start_lines{$name} = $new_start_line; + $new_start_line = 0; + } + } +} + +## +# dump DOC: section after checking that it should go out +# +sub dump_doc_section { + my $file = shift; + my $name = shift; + my $contents = join "\n", @_; + + if ($no_doc_sections) { + return; + } + + if (($output_selection == OUTPUT_ALL) || + ($output_selection == OUTPUT_INCLUDE && + defined($function_table{$name})) || + ($output_selection == OUTPUT_EXCLUDE && + !defined($function_table{$name}))) + { + dump_section($file, $name, $contents); + output_blockhead({'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'module' => $modulename, + 'content-only' => ($output_selection != OUTPUT_ALL), }); + } +} + +## +# output function +# +# parameterdescs, a hash. +# function => "function name" +# parameterlist => @list of parameters +# parameterdescs => %parameter descriptions +# sectionlist => @list of sections +# sections => %section descriptions +# + +sub output_highlight { + my $contents = join "\n",@_; + my $line; + +# DEBUG +# if (!defined $contents) { +# use Carp; +# confess "output_highlight got called with no args?\n"; +# } + +# print STDERR "contents b4:$contents\n"; + eval $dohighlight; + die $@ if $@; +# print STDERR "contents af:$contents\n"; + + foreach $line (split "\n", $contents) { + if (! $output_preformatted) { + $line =~ s/^\s*//; + } + if ($line eq ""){ + if (! $output_preformatted) { + print $lineprefix, $blankline; + } + } else { + if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { + print "\\&$line"; + } else { + print $lineprefix, $line; + } + } + print "\n"; + } +} + +## +# output function in man +sub output_function_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; + + print ".SH NAME\n"; + print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; + + print ".SH SYNOPSIS\n"; + if ($args{'functiontype'} ne "") { + print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; + } else { + print ".B \"" . $args{'function'} . "\n"; + } + $count = 0; + my $parenth = "("; + my $post = ","; + foreach my $parameter (@{$args{'parameterlist'}}) { + if ($count == $#{$args{'parameterlist'}}) { + $post = ");"; + } + $type = $args{'parametertypes'}{$parameter}; + if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { + # pointer-to-function + print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; + } else { + $type =~ s/([^\*])$/$1 /; + print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; + } + $count++; + $parenth = ""; + } + + print ".SH ARGUMENTS\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + print ".IP \"" . $parameter . "\" 12\n"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"", uc $section, "\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output enum in man +sub output_enum_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; + + print ".SH NAME\n"; + print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; + + print ".SH SYNOPSIS\n"; + print "enum " . $args{'enum'} . " {\n"; + $count = 0; + foreach my $parameter (@{$args{'parameterlist'}}) { + print ".br\n.BI \" $parameter\"\n"; + if ($count == $#{$args{'parameterlist'}}) { + print "\n};\n"; + last; + } + else { + print ", \n.br\n"; + } + $count++; + } + + print ".SH Constants\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + print ".IP \"" . $parameter . "\" 12\n"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output struct in man +sub output_struct_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + + print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; + + print ".SH NAME\n"; + print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; + + my $declaration = $args{'definition'}; + $declaration =~ s/\t/ /g; + $declaration =~ s/\n/"\n.br\n.BI \"/g; + print ".SH SYNOPSIS\n"; + print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; + print ".BI \"$declaration\n};\n.br\n\n"; + + print ".SH Members\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + ($parameter =~ /^#/) && next; + + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + print ".IP \"" . $parameter . "\" 12\n"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output typedef in man +sub output_typedef_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + + print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; + + print ".SH NAME\n"; + print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; + + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +sub output_blockhead_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; + + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output in restructured text +# + +# +# This could use some work; it's used to output the DOC: sections, and +# starts by putting out the name of the doc section itself, but that tends +# to duplicate a header already in the template file. +# +sub output_blockhead_rst(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + + foreach $section (@{$args{'sectionlist'}}) { + if ($output_selection != OUTPUT_INCLUDE) { + print "**$section**\n\n"; + } + print_lineno($section_start_lines{$section}); + output_highlight_rst($args{'sections'}{$section}); + print "\n"; + } +} + +# +# Apply the RST highlights to a sub-block of text. +# +sub highlight_block($) { + # The dohighlight kludge requires the text be called $contents + my $contents = shift; + eval $dohighlight; + die $@ if $@; + return $contents; +} + +# +# Regexes used only here. +# +my $sphinx_literal = '^[^.].*::$'; +my $sphinx_cblock = '^\.\.\ +code-block::'; + +sub output_highlight_rst { + my $input = join "\n",@_; + my $output = ""; + my $line; + my $in_literal = 0; + my $litprefix; + my $block = ""; + + foreach $line (split "\n",$input) { + # + # If we're in a literal block, see if we should drop out + # of it. Otherwise pass the line straight through unmunged. + # + if ($in_literal) { + if (! ($line =~ /^\s*$/)) { + # + # If this is the first non-blank line in a literal + # block we need to figure out what the proper indent is. + # + if ($litprefix eq "") { + $line =~ /^(\s*)/; + $litprefix = '^' . $1; + $output .= $line . "\n"; + } elsif (! ($line =~ /$litprefix/)) { + $in_literal = 0; + } else { + $output .= $line . "\n"; + } + } else { + $output .= $line . "\n"; + } + } + # + # Not in a literal block (or just dropped out) + # + if (! $in_literal) { + $block .= $line . "\n"; + if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { + $in_literal = 1; + $litprefix = ""; + $output .= highlight_block($block); + $block = "" + } + } + } + + if ($block) { + $output .= highlight_block($block); + } + foreach $line (split "\n", $output) { + print $lineprefix . $line . "\n"; + } +} + +sub output_function_rst(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $oldprefix = $lineprefix; + my $start = ""; + + if ($args{'typedef'}) { + print ".. c:type:: ". $args{'function'} . "\n\n"; + print_lineno($declaration_start_line); + print " **Typedef**: "; + $lineprefix = ""; + output_highlight_rst($args{'purpose'}); + $start = "\n\n**Syntax**\n\n ``"; + } else { + print ".. c:function:: "; + } + if ($args{'functiontype'} ne "") { + $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; + } else { + $start .= $args{'function'} . " ("; + } + print $start; + + my $count = 0; + foreach my $parameter (@{$args{'parameterlist'}}) { + if ($count ne 0) { + print ", "; + } + $count++; + $type = $args{'parametertypes'}{$parameter}; + + if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { + # pointer-to-function + print $1 . $parameter . ") (" . $2; + } else { + print $type . " " . $parameter; + } + } + if ($args{'typedef'}) { + print ");``\n\n"; + } else { + print ")\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + } + + print "**Parameters**\n\n"; + $lineprefix = " "; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + $type = $args{'parametertypes'}{$parameter}; + + if ($type ne "") { + print "``$type $parameter``\n"; + } else { + print "``$parameter``\n"; + } + + print_lineno($parameterdesc_start_lines{$parameter_name}); + + if (defined($args{'parameterdescs'}{$parameter_name}) && + $args{'parameterdescs'}{$parameter_name} ne $undescribed) { + output_highlight_rst($args{'parameterdescs'}{$parameter_name}); + } else { + print " *undescribed*\n"; + } + print "\n"; + } + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +sub output_section_rst(%) { + my %args = %{$_[0]}; + my $section; + my $oldprefix = $lineprefix; + $lineprefix = ""; + + foreach $section (@{$args{'sectionlist'}}) { + print "**$section**\n\n"; + print_lineno($section_start_lines{$section}); + output_highlight_rst($args{'sections'}{$section}); + print "\n"; + } + print "\n"; + $lineprefix = $oldprefix; +} + +sub output_enum_rst(%) { + my %args = %{$_[0]}; + my ($parameter); + my $oldprefix = $lineprefix; + my $count; + my $name = "enum " . $args{'enum'}; + + print "\n\n.. c:type:: " . $name . "\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + + print "**Constants**\n\n"; + $lineprefix = " "; + foreach $parameter (@{$args{'parameterlist'}}) { + print "``$parameter``\n"; + if ($args{'parameterdescs'}{$parameter} ne $undescribed) { + output_highlight_rst($args{'parameterdescs'}{$parameter}); + } else { + print " *undescribed*\n"; + } + print "\n"; + } + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +sub output_typedef_rst(%) { + my %args = %{$_[0]}; + my ($parameter); + my $oldprefix = $lineprefix; + my $name = "typedef " . $args{'typedef'}; + + print "\n\n.. c:type:: " . $name . "\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +sub output_struct_rst(%) { + my %args = %{$_[0]}; + my ($parameter); + my $oldprefix = $lineprefix; + my $name = $args{'type'} . " " . $args{'struct'}; + + print "\n\n.. c:type:: " . $name . "\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + + print "**Definition**\n\n"; + print "::\n\n"; + my $declaration = $args{'definition'}; + $declaration =~ s/\t/ /g; + print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; + + print "**Members**\n\n"; + $lineprefix = " "; + foreach $parameter (@{$args{'parameterlist'}}) { + ($parameter =~ /^#/) && next; + + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + $type = $args{'parametertypes'}{$parameter}; + print_lineno($parameterdesc_start_lines{$parameter_name}); + print "``" . $parameter . "``\n"; + output_highlight_rst($args{'parameterdescs'}{$parameter_name}); + print "\n"; + } + print "\n"; + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +## none mode output functions + +sub output_function_none(%) { +} + +sub output_enum_none(%) { +} + +sub output_typedef_none(%) { +} + +sub output_struct_none(%) { +} + +sub output_blockhead_none(%) { +} + +## +# generic output function for all types (function, struct/union, typedef, enum); +# calls the generated, variable output_ function name based on +# functype and output_mode +sub output_declaration { + no strict 'refs'; + my $name = shift; + my $functype = shift; + my $func = "output_${functype}_$output_mode"; + if (($output_selection == OUTPUT_ALL) || + (($output_selection == OUTPUT_INCLUDE || + $output_selection == OUTPUT_EXPORTED) && + defined($function_table{$name})) || + (($output_selection == OUTPUT_EXCLUDE || + $output_selection == OUTPUT_INTERNAL) && + !($functype eq "function" && defined($function_table{$name})))) + { + &$func(@_); + $section_counter++; + } +} + +## +# generic output function - calls the right one based on current output mode. +sub output_blockhead { + no strict 'refs'; + my $func = "output_blockhead_" . $output_mode; + &$func(@_); + $section_counter++; +} + +## +# takes a declaration (struct, union, enum, typedef) and +# invokes the right handler. NOT called for functions. +sub dump_declaration($$) { + no strict 'refs'; + my ($prototype, $file) = @_; + my $func = "dump_" . $decl_type; + &$func(@_); +} + +sub dump_union($$) { + dump_struct(@_); +} + +sub dump_struct($$) { + my $x = shift; + my $file = shift; + + if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) { + my $decl_type = $1; + $declaration_name = $2; + my $members = $3; + + # ignore members marked private: + $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; + $members =~ s/\/\*\s*private:.*//gosi; + # strip comments: + $members =~ s/\/\*.*?\*\///gos; + # strip attributes + $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)//gi; + $members =~ s/\s*__aligned\s*\([^;]*\)//gos; + $members =~ s/\s*__packed\s*//gos; + $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; + # replace DECLARE_BITMAP + $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; + # replace DECLARE_HASHTABLE + $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; + # replace DECLARE_KFIFO + $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; + # replace DECLARE_KFIFO_PTR + $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; + + my $declaration = $members; + + # Split nested struct/union elements as newer ones + while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { + my $newmember; + my $maintype = $1; + my $ids = $4; + my $content = $3; + foreach my $id(split /,/, $ids) { + $newmember .= "$maintype $id; "; + + $id =~ s/[:\[].*//; + $id =~ s/^\s*\**(\S+)\s*/$1/; + foreach my $arg (split /;/, $content) { + next if ($arg =~ m/^\s*$/); + if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { + # pointer-to-function + my $type = $1; + my $name = $2; + my $extra = $3; + next if (!$name); + if ($id =~ m/^\s*$/) { + # anonymous struct/union + $newmember .= "$type$name$extra; "; + } else { + $newmember .= "$type$id.$name$extra; "; + } + } else { + my $type; + my $names; + $arg =~ s/^\s+//; + $arg =~ s/\s+$//; + # Handle bitmaps + $arg =~ s/:\s*\d+\s*//g; + # Handle arrays + $arg =~ s/\[.*\]//g; + # The type may have multiple words, + # and multiple IDs can be defined, like: + # const struct foo, *bar, foobar + # So, we remove spaces when parsing the + # names, in order to match just names + # and commas for the names + $arg =~ s/\s*,\s*/,/g; + if ($arg =~ m/(.*)\s+([\S+,]+)/) { + $type = $1; + $names = $2; + } else { + $newmember .= "$arg; "; + next; + } + foreach my $name (split /,/, $names) { + $name =~ s/^\s*\**(\S+)\s*/$1/; + next if (($name =~ m/^\s*$/)); + if ($id =~ m/^\s*$/) { + # anonymous struct/union + $newmember .= "$type $name; "; + } else { + $newmember .= "$type $id.$name; "; + } + } + } + } + } + $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/; + } + + # Ignore other nested elements, like enums + $members =~ s/(\{[^\{\}]*\})//g; + + create_parameterlist($members, ';', $file, $declaration_name); + check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); + + # Adjust declaration for better display + $declaration =~ s/([\{;])/$1\n/g; + $declaration =~ s/\}\s+;/};/g; + # Better handle inlined enums + do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); + + my @def_args = split /\n/, $declaration; + my $level = 1; + $declaration = ""; + foreach my $clause (@def_args) { + $clause =~ s/^\s+//; + $clause =~ s/\s+$//; + $clause =~ s/\s+/ /; + next if (!$clause); + $level-- if ($clause =~ m/(\})/ && $level > 1); + if (!($clause =~ m/^\s*#/)) { + $declaration .= "\t" x $level; + } + $declaration .= "\t" . $clause . "\n"; + $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); + } + output_declaration($declaration_name, + 'struct', + {'struct' => $declaration_name, + 'module' => $modulename, + 'definition' => $declaration, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose, + 'type' => $decl_type + }); + } + else { + print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; + ++$errors; + } +} + + +sub show_warnings($$) { + my $functype = shift; + my $name = shift; + + return 1 if ($output_selection == OUTPUT_ALL); + + if ($output_selection == OUTPUT_EXPORTED) { + if (defined($function_table{$name})) { + return 1; + } else { + return 0; + } + } + if ($output_selection == OUTPUT_INTERNAL) { + if (!($functype eq "function" && defined($function_table{$name}))) { + return 1; + } else { + return 0; + } + } + if ($output_selection == OUTPUT_INCLUDE) { + if (defined($function_table{$name})) { + return 1; + } else { + return 0; + } + } + if ($output_selection == OUTPUT_EXCLUDE) { + if (!defined($function_table{$name})) { + return 1; + } else { + return 0; + } + } + die("Please add the new output type at show_warnings()"); +} + +sub dump_enum($$) { + my $x = shift; + my $file = shift; + + $x =~ s@/\*.*?\*/@@gos; # strip comments. + # strip #define macros inside enums + $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; + + if ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { + $declaration_name = $1; + my $members = $2; + my %_members; + + $members =~ s/\s+$//; + + foreach my $arg (split ',', $members) { + $arg =~ s/^\s*(\w+).*/$1/; + push @parameterlist, $arg; + if (!$parameterdescs{$arg}) { + $parameterdescs{$arg} = $undescribed; + if (show_warnings("enum", $declaration_name)) { + print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; + } + } + $_members{$arg} = 1; + } + + while (my ($k, $v) = each %parameterdescs) { + if (!exists($_members{$k})) { + if (show_warnings("enum", $declaration_name)) { + print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; + } + } + } + + output_declaration($declaration_name, + 'enum', + {'enum' => $declaration_name, + 'module' => $modulename, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); + } + else { + print STDERR "${file}:$.: error: Cannot parse enum!\n"; + ++$errors; + } +} + +sub dump_typedef($$) { + my $x = shift; + my $file = shift; + + $x =~ s@/\*.*?\*/@@gos; # strip comments. + + # Parse function prototypes + if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || + $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { + + # Function typedefs + $return_type = $1; + $declaration_name = $2; + my $args = $3; + + create_parameterlist($args, ',', $file, $declaration_name); + + output_declaration($declaration_name, + 'function', + {'function' => $declaration_name, + 'typedef' => 1, + 'module' => $modulename, + 'functiontype' => $return_type, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); + return; + } + + while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { + $x =~ s/\(*.\)\s*;$/;/; + $x =~ s/\[*.\]\s*;$/;/; + } + + if ($x =~ /typedef.*\s+(\w+)\s*;/) { + $declaration_name = $1; + + output_declaration($declaration_name, + 'typedef', + {'typedef' => $declaration_name, + 'module' => $modulename, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); + } + else { + print STDERR "${file}:$.: error: Cannot parse typedef!\n"; + ++$errors; + } +} + +sub save_struct_actual($) { + my $actual = shift; + + # strip all spaces from the actual param so that it looks like one string item + $actual =~ s/\s*//g; + $struct_actual = $struct_actual . $actual . " "; +} + +sub create_parameterlist($$$$) { + my $args = shift; + my $splitter = shift; + my $file = shift; + my $declaration_name = shift; + my $type; + my $param; + + # temporarily replace commas inside function pointer definition + while ($args =~ /(\([^\),]+),/) { + $args =~ s/(\([^\),]+),/$1#/g; + } + + foreach my $arg (split($splitter, $args)) { + # strip comments + $arg =~ s/\/\*.*\*\///; + # strip leading/trailing spaces + $arg =~ s/^\s*//; + $arg =~ s/\s*$//; + $arg =~ s/\s+/ /; + + if ($arg =~ /^#/) { + # Treat preprocessor directive as a typeless variable just to fill + # corresponding data structures "correctly". Catch it later in + # output_* subs. + push_parameter($arg, "", $file); + } elsif ($arg =~ m/\(.+\)\s*\(/) { + # pointer-to-function + $arg =~ tr/#/,/; + $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; + $param = $1; + $type = $arg; + $type =~ s/([^\(]+\(\*?)\s*$param/$1/; + save_struct_actual($param); + push_parameter($param, $type, $file, $declaration_name); + } elsif ($arg) { + $arg =~ s/\s*:\s*/:/g; + $arg =~ s/\s*\[/\[/g; + + my @args = split('\s*,\s*', $arg); + if ($args[0] =~ m/\*/) { + $args[0] =~ s/(\*+)\s*/ $1/; + } + + my @first_arg; + if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { + shift @args; + push(@first_arg, split('\s+', $1)); + push(@first_arg, $2); + } else { + @first_arg = split('\s+', shift @args); + } + + unshift(@args, pop @first_arg); + $type = join " ", @first_arg; + + foreach $param (@args) { + if ($param =~ m/^(\*+)\s*(.*)/) { + save_struct_actual($2); + push_parameter($2, "$type $1", $file, $declaration_name); + } + elsif ($param =~ m/(.*?):(\d+)/) { + if ($type ne "") { # skip unnamed bit-fields + save_struct_actual($1); + push_parameter($1, "$type:$2", $file, $declaration_name) + } + } + else { + save_struct_actual($param); + push_parameter($param, $type, $file, $declaration_name); + } + } + } + } +} + +sub push_parameter($$$$) { + my $param = shift; + my $type = shift; + my $file = shift; + my $declaration_name = shift; + + if (($anon_struct_union == 1) && ($type eq "") && + ($param eq "}")) { + return; # ignore the ending }; from anon. struct/union + } + + $anon_struct_union = 0; + $param =~ s/[\[\)].*//; + + if ($type eq "" && $param =~ /\.\.\.$/) + { + if (!$param =~ /\w\.\.\.$/) { + # handles unnamed variable parameters + $param = "..."; + } + if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { + $parameterdescs{$param} = "variable arguments"; + } + } + elsif ($type eq "" && ($param eq "" or $param eq "void")) + { + $param="void"; + $parameterdescs{void} = "no arguments"; + } + elsif ($type eq "" && ($param eq "struct" or $param eq "union")) + # handle unnamed (anonymous) union or struct: + { + $type = $param; + $param = "{unnamed_" . $param . "}"; + $parameterdescs{$param} = "anonymous\n"; + $anon_struct_union = 1; + } + + # warn if parameter has no description + # (but ignore ones starting with # as these are not parameters + # but inline preprocessor statements); + # Note: It will also ignore void params and unnamed structs/unions + if (!defined $parameterdescs{$param} && $param !~ /^#/) { + $parameterdescs{$param} = $undescribed; + + if (show_warnings($type, $declaration_name) && $param !~ /\./) { + print STDERR + "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; + ++$warnings; + } + } + + # strip spaces from $param so that it is one continuous string + # on @parameterlist; + # this fixes a problem where check_sections() cannot find + # a parameter like "addr[6 + 2]" because it actually appears + # as "addr[6", "+", "2]" on the parameter list; + # but it's better to maintain the param string unchanged for output, + # so just weaken the string compare in check_sections() to ignore + # "[blah" in a parameter string; + ###$param =~ s/\s*//g; + push @parameterlist, $param; + $type =~ s/\s\s+/ /g; + $parametertypes{$param} = $type; +} + +sub check_sections($$$$$) { + my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; + my @sects = split ' ', $sectcheck; + my @prms = split ' ', $prmscheck; + my $err; + my ($px, $sx); + my $prm_clean; # strip trailing "[array size]" and/or beginning "*" + + foreach $sx (0 .. $#sects) { + $err = 1; + foreach $px (0 .. $#prms) { + $prm_clean = $prms[$px]; + $prm_clean =~ s/\[.*\]//; + $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; + # ignore array size in a parameter string; + # however, the original param string may contain + # spaces, e.g.: addr[6 + 2] + # and this appears in @prms as "addr[6" since the + # parameter list is split at spaces; + # hence just ignore "[..." for the sections check; + $prm_clean =~ s/\[.*//; + + ##$prm_clean =~ s/^\**//; + if ($prm_clean eq $sects[$sx]) { + $err = 0; + last; + } + } + if ($err) { + if ($decl_type eq "function") { + print STDERR "${file}:$.: warning: " . + "Excess function parameter " . + "'$sects[$sx]' " . + "description in '$decl_name'\n"; + ++$warnings; + } + } + } +} + +## +# Checks the section describing the return value of a function. +sub check_return_section { + my $file = shift; + my $declaration_name = shift; + my $return_type = shift; + + # Ignore an empty return type (It's a macro) + # Ignore functions with a "void" return type. (But don't ignore "void *") + if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { + return; + } + + if (!defined($sections{$section_return}) || + $sections{$section_return} eq "") { + print STDERR "${file}:$.: warning: " . + "No description found for return value of " . + "'$declaration_name'\n"; + ++$warnings; + } +} + +## +# takes a function prototype and the name of the current file being +# processed and spits out all the details stored in the global +# arrays/hashes. +sub dump_function($$) { + my $prototype = shift; + my $file = shift; + my $noret = 0; + + $prototype =~ s/^static +//; + $prototype =~ s/^extern +//; + $prototype =~ s/^asmlinkage +//; + $prototype =~ s/^inline +//; + $prototype =~ s/^__inline__ +//; + $prototype =~ s/^__inline +//; + $prototype =~ s/^__always_inline +//; + $prototype =~ s/^noinline +//; + $prototype =~ s/__init +//; + $prototype =~ s/__init_or_module +//; + $prototype =~ s/__meminit +//; + $prototype =~ s/__must_check +//; + $prototype =~ s/__weak +//; + $prototype =~ s/__sched +//; + $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; + my $define = $prototype =~ s/^#\s*define\s+//; #ak added + $prototype =~ s/__attribute__\s*\(\( + (?: + [\w\s]++ # attribute name + (?:\([^)]*+\))? # attribute arguments + \s*+,? # optional comma at the end + )+ + \)\)\s+//x; + + # Yes, this truly is vile. We are looking for: + # 1. Return type (may be nothing if we're looking at a macro) + # 2. Function name + # 3. Function parameters. + # + # All the while we have to watch out for function pointer parameters + # (which IIRC is what the two sections are for), C types (these + # regexps don't even start to express all the possibilities), and + # so on. + # + # If you mess with these regexps, it's a good idea to check that + # the following functions' documentation still comes out right: + # - parport_register_device (function pointer parameters) + # - atomic_set (macro) + # - pci_match_device, __copy_to_user (long return type) + + if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { + # This is an object-like macro, it has no return type and no parameter + # list. + # Function-like macros are not allowed to have spaces between + # declaration_name and opening parenthesis (notice the \s+). + $return_type = $1; + $declaration_name = $2; + $noret = 1; + } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { + $return_type = $1; + $declaration_name = $2; + my $args = $3; + + create_parameterlist($args, ',', $file, $declaration_name); + } else { + print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; + return; + } + + my $prms = join " ", @parameterlist; + check_sections($file, $declaration_name, "function", $sectcheck, $prms); + + # This check emits a lot of warnings at the moment, because many + # functions don't have a 'Return' doc section. So until the number + # of warnings goes sufficiently down, the check is only performed in + # verbose mode. + # TODO: always perform the check. + if ($verbose && !$noret) { + check_return_section($file, $declaration_name, $return_type); + } + + output_declaration($declaration_name, + 'function', + {'function' => $declaration_name, + 'module' => $modulename, + 'functiontype' => $return_type, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); +} + +sub reset_state { + $function = ""; + %parameterdescs = (); + %parametertypes = (); + @parameterlist = (); + %sections = (); + @sectionlist = (); + $sectcheck = ""; + $struct_actual = ""; + $prototype = ""; + + $state = STATE_NORMAL; + $inline_doc_state = STATE_INLINE_NA; +} + +sub tracepoint_munge($) { + my $file = shift; + my $tracepointname = 0; + my $tracepointargs = 0; + + if ($prototype =~ m/TRACE_EVENT\((.*?),/) { + $tracepointname = $1; + } + if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { + $tracepointname = $1; + } + if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { + $tracepointname = $2; + } + $tracepointname =~ s/^\s+//; #strip leading whitespace + if ($prototype =~ m/TP_PROTO\((.*?)\)/) { + $tracepointargs = $1; + } + if (($tracepointname eq 0) || ($tracepointargs eq 0)) { + print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". + "$prototype\n"; + } else { + $prototype = "static inline void trace_$tracepointname($tracepointargs)"; + } +} + +sub syscall_munge() { + my $void = 0; + + $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's +## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { + if ($prototype =~ m/SYSCALL_DEFINE0/) { + $void = 1; +## $prototype = "long sys_$1(void)"; + } + + $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name + if ($prototype =~ m/long (sys_.*?),/) { + $prototype =~ s/,/\(/; + } elsif ($void) { + $prototype =~ s/\)/\(void\)/; + } + + # now delete all of the odd-number commas in $prototype + # so that arg types & arg names don't have a comma between them + my $count = 0; + my $len = length($prototype); + if ($void) { + $len = 0; # skip the for-loop + } + for (my $ix = 0; $ix < $len; $ix++) { + if (substr($prototype, $ix, 1) eq ',') { + $count++; + if ($count % 2 == 1) { + substr($prototype, $ix, 1) = ' '; + } + } + } +} + +sub process_proto_function($$) { + my $x = shift; + my $file = shift; + + $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line + + if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { + # do nothing + } + elsif ($x =~ /([^\{]*)/) { + $prototype .= $1; + } + + if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { + $prototype =~ s@/\*.*?\*/@@gos; # strip comments. + $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. + $prototype =~ s@^\s+@@gos; # strip leading spaces + if ($prototype =~ /SYSCALL_DEFINE/) { + syscall_munge(); + } + if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || + $prototype =~ /DEFINE_SINGLE_EVENT/) + { + tracepoint_munge($file); + } + dump_function($prototype, $file); + reset_state(); + } +} + +sub process_proto_type($$) { + my $x = shift; + my $file = shift; + + $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. + $x =~ s@^\s+@@gos; # strip leading spaces + $x =~ s@\s+$@@gos; # strip trailing spaces + $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line + + if ($x =~ /^#/) { + # To distinguish preprocessor directive from regular declaration later. + $x .= ";"; + } + + while (1) { + if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { + if( length $prototype ) { + $prototype .= " " + } + $prototype .= $1 . $2; + ($2 eq '{') && $brcount++; + ($2 eq '}') && $brcount--; + if (($2 eq ';') && ($brcount == 0)) { + dump_declaration($prototype, $file); + reset_state(); + last; + } + $x = $3; + } else { + $prototype .= $x; + last; + } + } +} + + +sub map_filename($) { + my $file; + my ($orig_file) = @_; + + if (defined($ENV{'SRCTREE'})) { + $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; + } else { + $file = $orig_file; + } + + if (defined($source_map{$file})) { + $file = $source_map{$file}; + } + + return $file; +} + +sub process_export_file($) { + my ($orig_file) = @_; + my $file = map_filename($orig_file); + + if (!open(IN,"<$file")) { + print STDERR "Error: Cannot open file $file\n"; + ++$errors; + return; + } + + while () { + if (/$export_symbol/) { + $function_table{$2} = 1; + } + } + + close(IN); +} + +# +# Parsers for the various processing states. +# +# STATE_NORMAL: looking for the /** to begin everything. +# +sub process_normal() { + if (/$doc_start/o) { + $state = STATE_NAME; # next line is always the function name + $in_doc_sect = 0; + $declaration_start_line = $. + 1; + } +} + +# +# STATE_NAME: Looking for the "name - description" line +# +sub process_name($$) { + my $file = shift; + my $identifier; + my $descr; + + if (/$doc_block/o) { + $state = STATE_DOCBLOCK; + $contents = ""; + $new_start_line = $. + 1; + + if ( $1 eq "" ) { + $section = $section_intro; + } else { + $section = $1; + } + } + elsif (/$doc_decl/o) { + $identifier = $1; + if (/\s*([\w\s]+?)(\(\))?\s*-/) { + $identifier = $1; + } + + $state = STATE_BODY; + # if there's no @param blocks need to set up default section + # here + $contents = ""; + $section = $section_default; + $new_start_line = $. + 1; + if (/-(.*)/) { + # strip leading/trailing/multiple spaces + $descr= $1; + $descr =~ s/^\s*//; + $descr =~ s/\s*$//; + $descr =~ s/\s+/ /g; + $declaration_purpose = $descr; + $state = STATE_BODY_MAYBE; + } else { + $declaration_purpose = ""; + } + + if (($declaration_purpose eq "") && $verbose) { + print STDERR "${file}:$.: warning: missing initial short description on line:\n"; + print STDERR $_; + ++$warnings; + } + + if ($identifier =~ m/^struct\b/) { + $decl_type = 'struct'; + } elsif ($identifier =~ m/^union\b/) { + $decl_type = 'union'; + } elsif ($identifier =~ m/^enum\b/) { + $decl_type = 'enum'; + } elsif ($identifier =~ m/^typedef\b/) { + $decl_type = 'typedef'; + } else { + $decl_type = 'function'; + } + + if ($verbose) { + print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; + } + } else { + print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", + " - I thought it was a doc line\n"; + ++$warnings; + $state = STATE_NORMAL; + } +} + + +# +# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. +# +sub process_body($$) { + my $file = shift; + + if (/$doc_sect/i) { # case insensitive for supported section names + $newsection = $1; + $newcontents = $2; + + # map the supported section names to the canonical names + if ($newsection =~ m/^description$/i) { + $newsection = $section_default; + } elsif ($newsection =~ m/^context$/i) { + $newsection = $section_context; + } elsif ($newsection =~ m/^returns?$/i) { + $newsection = $section_return; + } elsif ($newsection =~ m/^\@return$/) { + # special: @return is a section, not a param description + $newsection = $section_return; + } + + if (($contents ne "") && ($contents ne "\n")) { + if (!$in_doc_sect && $verbose) { + print STDERR "${file}:$.: warning: contents before sections\n"; + ++$warnings; + } + dump_section($file, $section, $contents); + $section = $section_default; + } + + $in_doc_sect = 1; + $state = STATE_BODY; + $contents = $newcontents; + $new_start_line = $.; + while (substr($contents, 0, 1) eq " ") { + $contents = substr($contents, 1); + } + if ($contents ne "") { + $contents .= "\n"; + } + $section = $newsection; + $leading_space = undef; + } elsif (/$doc_end/) { + if (($contents ne "") && ($contents ne "\n")) { + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + } + # look for doc_com + + doc_end: + if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { + print STDERR "${file}:$.: warning: suspicious ending line: $_"; + ++$warnings; + } + + $prototype = ""; + $state = STATE_PROTO; + $brcount = 0; + } elsif (/$doc_content/) { + # miguel-style comment kludge, look for blank lines after + # @parameter line to signify start of description + if ($1 eq "") { + if ($section =~ m/^@/ || $section eq $section_context) { + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + $new_start_line = $.; + } else { + $contents .= "\n"; + } + $state = STATE_BODY; + } elsif ($state == STATE_BODY_MAYBE) { + # Continued declaration purpose + chomp($declaration_purpose); + $declaration_purpose .= " " . $1; + $declaration_purpose =~ s/\s+/ /g; + } else { + my $cont = $1; + if ($section =~ m/^@/ || $section eq $section_context) { + if (!defined $leading_space) { + if ($cont =~ m/^(\s+)/) { + $leading_space = $1; + } else { + $leading_space = ""; + } + } + $cont =~ s/^$leading_space//; + } + $contents .= $cont . "\n"; + } + } else { + # i dont know - bad line? ignore. + print STDERR "${file}:$.: warning: bad line: $_"; + ++$warnings; + } +} + + +# +# STATE_PROTO: reading a function/whatever prototype. +# +sub process_proto($$) { + my $file = shift; + + if (/$doc_inline_oneline/) { + $section = $1; + $contents = $2; + if ($contents ne "") { + $contents .= "\n"; + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + } + } elsif (/$doc_inline_start/) { + $state = STATE_INLINE; + $inline_doc_state = STATE_INLINE_NAME; + } elsif ($decl_type eq 'function') { + process_proto_function($_, $file); + } else { + process_proto_type($_, $file); + } +} + +# +# STATE_DOCBLOCK: within a DOC: block. +# +sub process_docblock($$) { + my $file = shift; + + if (/$doc_end/) { + dump_doc_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + $function = ""; + %parameterdescs = (); + %parametertypes = (); + @parameterlist = (); + %sections = (); + @sectionlist = (); + $prototype = ""; + $state = STATE_NORMAL; + } elsif (/$doc_content/) { + if ( $1 eq "" ) { + $contents .= $blankline; + } else { + $contents .= $1 . "\n"; + } + } +} + +# +# STATE_INLINE: docbook comments within a prototype. +# +sub process_inline($$) { + my $file = shift; + + # First line (state 1) needs to be a @parameter + if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { + $section = $1; + $contents = $2; + $new_start_line = $.; + if ($contents ne "") { + while (substr($contents, 0, 1) eq " ") { + $contents = substr($contents, 1); + } + $contents .= "\n"; + } + $inline_doc_state = STATE_INLINE_TEXT; + # Documentation block end */ + } elsif (/$doc_inline_end/) { + if (($contents ne "") && ($contents ne "\n")) { + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + } + $state = STATE_PROTO; + $inline_doc_state = STATE_INLINE_NA; + # Regular text + } elsif (/$doc_content/) { + if ($inline_doc_state == STATE_INLINE_TEXT) { + $contents .= $1 . "\n"; + # nuke leading blank lines + if ($contents =~ /^\s*$/) { + $contents = ""; + } + } elsif ($inline_doc_state == STATE_INLINE_NAME) { + $inline_doc_state = STATE_INLINE_ERROR; + print STDERR "${file}:$.: warning: "; + print STDERR "Incorrect use of kernel-doc format: $_"; + ++$warnings; + } + } +} + + +sub process_file($) { + my $file; + my $initial_section_counter = $section_counter; + my ($orig_file) = @_; + + $file = map_filename($orig_file); + + if (!open(IN,"<$file")) { + print STDERR "Error: Cannot open file $file\n"; + ++$errors; + return; + } + + $. = 1; + + $section_counter = 0; + while () { + while (s/\\\s*$//) { + $_ .= ; + } + # Replace tabs by spaces + while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; + # Hand this line to the appropriate state handler + if ($state == STATE_NORMAL) { + process_normal(); + } elsif ($state == STATE_NAME) { + process_name($file, $_); + } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { + process_body($file, $_); + } elsif ($state == STATE_INLINE) { # scanning for inline parameters + process_inline($file, $_); + } elsif ($state == STATE_PROTO) { + process_proto($file, $_); + } elsif ($state == STATE_DOCBLOCK) { + process_docblock($file, $_); + } + } + + # Make sure we got something interesting. + if ($initial_section_counter == $section_counter && $ + output_mode ne "none") { + if ($output_selection == OUTPUT_INCLUDE) { + print STDERR "${file}:1: warning: '$_' not found\n" + for keys %function_table; + } + else { + print STDERR "${file}:1: warning: no structured comments found\n"; + } + } +} + + +$kernelversion = get_kernel_version(); + +# generate a sequence of code that will splice in highlighting information +# using the s// operator. +for (my $k = 0; $k < @highlights; $k++) { + my $pattern = $highlights[$k][0]; + my $result = $highlights[$k][1]; +# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; + $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; +} + +# Read the file that maps relative names to absolute names for +# separate source and object directories and for shadow trees. +if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { + my ($relname, $absname); + while() { + chop(); + ($relname, $absname) = (split())[0..1]; + $relname =~ s:^/+::; + $source_map{$relname} = $absname; + } + close(SOURCE_MAP); +} + +if ($output_selection == OUTPUT_EXPORTED || + $output_selection == OUTPUT_INTERNAL) { + + push(@export_file_list, @ARGV); + + foreach (@export_file_list) { + chomp; + process_export_file($_); + } +} + +foreach (@ARGV) { + chomp; + process_file($_); +} +if ($verbose && $errors) { + print STDERR "$errors errors\n"; +} +if ($verbose && $warnings) { + print STDERR "$warnings warnings\n"; +} + +exit($output_mode eq "none" ? 0 : $errors); From 4cf41794411f91453e19da88ecb7e806a831abf8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 29 Oct 2019 17:22:44 +0100 Subject: [PATCH 65/87] docs: tweak kernel-doc for QEMU coding standards Surprisingly, QEMU does have a pretty consistent doc comment style and it is not very different from the Linux kernel's. Of the documentation "sigils", only "#" separates the QEMU doc comment style from Linux's, and it has 200+ instances vs. 6 for the kernel's '&struct foo' (all in accel/tcg/translate-all.c), so it's clear that the two standards are different in this respect. In addition, our structs are typedefed and recognized by CamelCase names. Adjust kernel-doc's parser for these two aspects of the QEMU coding standards. The patch has been valid, with hardly any change, for over two years, so it should not be an issue to keep kernel-doc in sync with the Linux copy. Signed-off-by: Paolo Bonzini --- scripts/kernel-doc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 81dc91760b..af470eb321 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -215,12 +215,12 @@ my $type_func = '(\w+)\(\)'; my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params my $type_env = '(\$\w+)'; -my $type_enum = '\&(enum\s*([_\w]+))'; -my $type_struct = '\&(struct\s*([_\w]+))'; -my $type_typedef = '\&(typedef\s*([_\w]+))'; -my $type_union = '\&(union\s*([_\w]+))'; -my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; -my $type_fallback = '\&([_\w]+)'; +my $type_enum = '#(enum\s*([_\w]+))'; +my $type_struct = '#(struct\s*([_\w]+))'; +my $type_typedef = '#(([A-Z][_\w]*))'; +my $type_union = '#(union\s*([_\w]+))'; +my $type_member = '#([_\w]+)(\.|->)([_\w]+)'; +my $type_fallback = '(?!)'; # this never matches my $type_member_func = $type_member . '\(\)'; # Output conversion substitutions. @@ -1050,6 +1050,14 @@ sub output_blockhead { sub dump_declaration($$) { no strict 'refs'; my ($prototype, $file) = @_; + if ($decl_type eq 'type name') { + if ($prototype =~ /^(enum|struct|union)\s+/) { + $decl_type = $1; + } else { + return; + } + } + my $func = "dump_" . $decl_type; &$func(@_); } @@ -1878,7 +1886,7 @@ sub process_name($$) { } elsif (/$doc_decl/o) { $identifier = $1; - if (/\s*([\w\s]+?)(\(\))?\s*-/) { + if (/\s*([\w\s]+?)(\s*-|:)/) { $identifier = $1; } @@ -1888,7 +1896,7 @@ sub process_name($$) { $contents = ""; $section = $section_default; $new_start_line = $. + 1; - if (/-(.*)/) { + if (/[-:](.*)/) { # strip leading/trailing/multiple spaces $descr= $1; $descr =~ s/^\s*//; @@ -1906,7 +1914,9 @@ sub process_name($$) { ++$warnings; } - if ($identifier =~ m/^struct\b/) { + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { $decl_type = 'struct'; } elsif ($identifier =~ m/^union\b/) { $decl_type = 'union'; From 22b5ea75e1f3644ae1c52b901cf05106cb13816c Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Fri, 29 Nov 2019 14:16:12 +0100 Subject: [PATCH 66/87] docs/conf.py: Enable use of kerneldoc sphinx extension Signed-off-by: Peter Maydell Message-Id: <20190521122519.12573-4-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- docs/conf.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index b7edb0666b..259c6049da 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,7 +54,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['qmp_lexer'] +extensions = ['kerneldoc', 'qmp_lexer'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -216,3 +216,8 @@ +# We use paths starting from qemu_docdir here so that you can run +# sphinx-build from anywhere and the kerneldoc extension can still +# find everything. +kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc') +kerneldoc_srctree = os.path.join(qemu_docdir, '..') From 96ecba67476731c5f44805b8e8a5800a3a8b9db8 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 21 May 2019 13:25:19 +0100 Subject: [PATCH 67/87] Makefile: disable Sphinx nitpicking Turn off Sphinx nitpicking as a temporary (?) measure so sphinx builds complete even with warnings about missing references. Signed-off-by: Peter Maydell Message-Id: <20190521122519.12573-11-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 531e9555bf..6b5ad1121b 100644 --- a/Makefile +++ b/Makefile @@ -1001,7 +1001,7 @@ sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html $(MANUAL_BUILDDIR)/interop/index # Note the use of different doctree for each (manual, builder) tuple; # this works around Sphinx not handling parallel invocation on # a single doctree: https://github.com/sphinx-doc/sphinx/issues/2946 -build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -n -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") +build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") # We assume all RST files in the manual's directory are used in it manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst) $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py From 7d41d764714a99df460fc275edfd33ac32a93349 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 21 May 2019 13:25:14 +0100 Subject: [PATCH 68/87] bitops.h: Silence kernel-doc complaints Fix the problems with kernel-doc/sphinx syntax in the doc comments for the shuffle and unshuffle functions: * mismatch between comment and prototype for argument name * the inline bit patterns need to be marked up so they are processed properly and rendered as monospace Signed-off-by: Peter Maydell Message-Id: <20190521122519.12573-6-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/bitops.h | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index ee76552c06..02c1ce6a5d 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -424,13 +424,16 @@ static inline uint64_t deposit64(uint64_t value, int start, int length, /** * half_shuffle32: - * @value: 32-bit value (of which only the bottom 16 bits are of interest) + * @x: 32-bit value (of which only the bottom 16 bits are of interest) + * + * Given an input value:: + * + * xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP * - * Given an input value: - * xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP * return the value where the bottom 16 bits are spread out into - * the odd bits in the word, and the even bits are zeroed: - * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P + * the odd bits in the word, and the even bits are zeroed:: + * + * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P * * Any bits set in the top half of the input are ignored. * @@ -450,13 +453,16 @@ static inline uint32_t half_shuffle32(uint32_t x) /** * half_shuffle64: - * @value: 64-bit value (of which only the bottom 32 bits are of interest) + * @x: 64-bit value (of which only the bottom 32 bits are of interest) + * + * Given an input value:: + * + * xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * - * Given an input value: - * xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * return the value where the bottom 32 bits are spread out into - * the odd bits in the word, and the even bits are zeroed: - * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f + * the odd bits in the word, and the even bits are zeroed:: + * + * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f * * Any bits set in the top half of the input are ignored. * @@ -477,13 +483,16 @@ static inline uint64_t half_shuffle64(uint64_t x) /** * half_unshuffle32: - * @value: 32-bit value (of which only the odd bits are of interest) + * @x: 32-bit value (of which only the odd bits are of interest) + * + * Given an input value:: + * + * xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP * - * Given an input value: - * xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP * return the value where all the odd bits are compressed down - * into the low half of the word, and the high half is zeroed: - * 0000 0000 0000 0000 ABCD EFGH IJKL MNOP + * into the low half of the word, and the high half is zeroed:: + * + * 0000 0000 0000 0000 ABCD EFGH IJKL MNOP * * Any even bits set in the input are ignored. * @@ -504,13 +513,16 @@ static inline uint32_t half_unshuffle32(uint32_t x) /** * half_unshuffle64: - * @value: 64-bit value (of which only the odd bits are of interest) + * @x: 64-bit value (of which only the odd bits are of interest) + * + * Given an input value:: + * + * xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf * - * Given an input value: - * xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf * return the value where all the odd bits are compressed down - * into the low half of the word, and the high half is zeroed: - * 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef + * into the low half of the word, and the high half is zeroed:: + * + * 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * * Any even bits set in the input are ignored. * From f298bb45dc972c57c52c78c1d99df3bcdedf3a76 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 21 May 2019 13:25:15 +0100 Subject: [PATCH 69/87] docs: Create bitops.rst as example of kernel-docs Create a bitops.rst which is just a container for the kernel-doc comments in qemu/bitops.h. This is mostly a test of the kernel-doc extension machinery. Signed-off-by: Peter Maydell Message-Id: <20190521122519.12573-7-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- docs/devel/bitops.rst | 8 ++++++++ docs/devel/index.rst | 1 + 2 files changed, 9 insertions(+) create mode 100644 docs/devel/bitops.rst diff --git a/docs/devel/bitops.rst b/docs/devel/bitops.rst new file mode 100644 index 0000000000..6addaecf8d --- /dev/null +++ b/docs/devel/bitops.rst @@ -0,0 +1,8 @@ +================== +Bitwise operations +================== + +The header ``qemu/bitops.h`` provides utility functions for +performing bitwise operations. + +.. kernel-doc:: include/qemu/bitops.h diff --git a/docs/devel/index.rst b/docs/devel/index.rst index c86a3cdff2..ac862152dc 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -23,3 +23,4 @@ Contents: secure-coding-practices tcg tcg-plugins + bitops From 08226b44ae7c88629804471298d61e79985794b8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 29 Oct 2019 17:22:46 +0100 Subject: [PATCH 70/87] memory.h: Silence kernel-doc complaints Fix a few instances where kernel-doc complains about doc comments in memory.h. Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 9d3fdb5696..4754749493 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -360,10 +360,14 @@ typedef struct IOMMUMemoryRegionClass { typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; +/** MemoryRegion: + * + * A struct representing a memory region. + */ struct MemoryRegion { Object parent_obj; - /* All fields are private - violators will be prosecuted */ + /* private: */ /* The following fields should fit in a cache line */ bool romd_mode; @@ -452,7 +456,7 @@ struct MemoryListener { * AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ struct AddressSpace { - /* All fields are private. */ + /* private: */ struct rcu_head rcu; char *name; MemoryRegion *root; @@ -1679,8 +1683,8 @@ bool memory_region_is_mapped(MemoryRegion *mr); * * Returns a #MemoryRegionSection that describes a contiguous overlap. * It will have the following characteristics: - * .@size = 0 iff no overlap was found - * .@mr is non-%NULL iff an overlap was found + * - @size = 0 iff no overlap was found + * - @mr is non-%NULL iff an overlap was found * * Remember that in the return value the @offset_within_region is * relative to the returned region (in the .@mr field), not to the @@ -1691,8 +1695,8 @@ bool memory_region_is_mapped(MemoryRegion *mr); * returned one. However, in the special case where the @mr argument * has no container (and thus is the root of the address space), the * following will hold: - * .@offset_within_address_space >= @addr - * .@offset_within_address_space + .@size <= @addr + @size + * - @offset_within_address_space >= @addr + * - @offset_within_address_space + .@size <= @addr + @size * * @mr: a MemoryRegion within which @addr is a relative address * @addr: start of the area within @as to be searched From f3224c528541e9d396c8208c168e0b1e78d1adb9 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 29 Oct 2019 17:22:47 +0100 Subject: [PATCH 71/87] docs: add memory API reference Add kernel-doc directive to parse and include doc comments from include/exec/memory.h. Signed-off-by: Paolo Bonzini --- docs/devel/memory.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/devel/memory.rst b/docs/devel/memory.rst index b6a4c37ea5..5dc8a12682 100644 --- a/docs/devel/memory.rst +++ b/docs/devel/memory.rst @@ -361,3 +361,8 @@ callbacks are called: - .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses. + +API Reference +------------- + +.. kernel-doc:: include/exec/memory.h From 5d248213180749e674fbccbacc6ee9c38499abb3 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 29 Oct 2019 17:22:48 +0100 Subject: [PATCH 72/87] memory: include MemoryListener documentation and some missing function parameters These cover the remaining warnings from kernel-doc. Signed-off-by: Paolo Bonzini Message-Id: <20191029162248.13383-7-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 218 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 214 insertions(+), 4 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 4754749493..e85b7de99a 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -423,30 +423,232 @@ struct IOMMUMemoryRegion { * Use with memory_listener_register() and memory_listener_unregister(). */ struct MemoryListener { + /** + * @begin: + * + * Called at the beginning of an address space update transaction. + * Followed by calls to #MemoryListener.region_add(), + * #MemoryListener.region_del(), #MemoryListener.region_nop(), + * #MemoryListener.log_start() and #MemoryListener.log_stop() in + * increasing address order. + * + * @listener: The #MemoryListener. + */ void (*begin)(MemoryListener *listener); + + /** + * @commit: + * + * Called at the end of an address space update transaction, + * after the last call to #MemoryListener.region_add(), + * #MemoryListener.region_del() or #MemoryListener.region_nop(), + * #MemoryListener.log_start() and #MemoryListener.log_stop(). + * + * @listener: The #MemoryListener. + */ void (*commit)(MemoryListener *listener); + + /** + * @region_add: + * + * Called during an address space update transaction, + * for a section of the address space that is new in this address space + * space since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + */ void (*region_add)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @region_del: + * + * Called during an address space update transaction, + * for a section of the address space that has disappeared in the address + * space since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The old #MemoryRegionSection. + */ void (*region_del)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @region_nop: + * + * Called during an address space update transaction, + * for a section of the address space that is in the same place in the address + * space as in the last transaction. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + */ void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @log_start: + * + * Called during an address space update transaction, after + * one of #MemoryListener.region_add(),#MemoryListener.region_del() or + * #MemoryListener.region_nop(), if dirty memory logging clients have + * become active since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + * @old: A bitmap of dirty memory logging clients that were active in + * the previous transaction. + * @new: A bitmap of dirty memory logging clients that are active in + * the current transaction. + */ void (*log_start)(MemoryListener *listener, MemoryRegionSection *section, int old, int new); + + /** + * @log_stop: + * + * Called during an address space update transaction, after + * one of #MemoryListener.region_add(), #MemoryListener.region_del() or + * #MemoryListener.region_nop() and possibly after + * #MemoryListener.log_start(), if dirty memory logging clients have + * become inactive since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + * @old: A bitmap of dirty memory logging clients that were active in + * the previous transaction. + * @new: A bitmap of dirty memory logging clients that are active in + * the current transaction. + */ void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section, int old, int new); + + /** + * @log_sync: + * + * Called by memory_region_snapshot_and_clear_dirty() and + * memory_global_dirty_log_sync(), before accessing QEMU's "official" + * copy of the dirty memory bitmap for a #MemoryRegionSection. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + */ void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @log_clear: + * + * Called before reading the dirty memory bitmap for a + * #MemoryRegionSection. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + */ void (*log_clear)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @log_global_start: + * + * Called by memory_global_dirty_log_start(), which + * enables the %DIRTY_LOG_MIGRATION client on all memory regions in + * the address space. #MemoryListener.log_global_start() is also + * called when a #MemoryListener is added, if global dirty logging is + * active at that time. + * + * @listener: The #MemoryListener. + */ void (*log_global_start)(MemoryListener *listener); + + /** + * @log_global_stop: + * + * Called by memory_global_dirty_log_stop(), which + * disables the %DIRTY_LOG_MIGRATION client on all memory regions in + * the address space. + * + * @listener: The #MemoryListener. + */ void (*log_global_stop)(MemoryListener *listener); + + /** + * @log_global_after_sync: + * + * Called after reading the dirty memory bitmap + * for any #MemoryRegionSection. + * + * @listener: The #MemoryListener. + */ void (*log_global_after_sync)(MemoryListener *listener); + + /** + * @eventfd_add: + * + * Called during an address space update transaction, + * for a section of the address space that has had a new ioeventfd + * registration since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @match_data: The @match_data parameter for the new ioeventfd. + * @data: The @data parameter for the new ioeventfd. + * @e: The #EventNotifier parameter for the new ioeventfd. + */ void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data, EventNotifier *e); + + /** + * @eventfd_del: + * + * Called during an address space update transaction, + * for a section of the address space that has dropped an ioeventfd + * registration since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @match_data: The @match_data parameter for the dropped ioeventfd. + * @data: The @data parameter for the dropped ioeventfd. + * @e: The #EventNotifier parameter for the dropped ioeventfd. + */ void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data, EventNotifier *e); + + /** + * @coalesced_io_add: + * + * Called during an address space update transaction, + * for a section of the address space that has had a new coalesced + * MMIO range registration since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @addr: The starting address for the coalesced MMIO range. + * @len: The length of the coalesced MMIO range. + */ void (*coalesced_io_add)(MemoryListener *listener, MemoryRegionSection *section, hwaddr addr, hwaddr len); + + /** + * @coalesced_io_del: + * + * Called during an address space update transaction, + * for a section of the address space that has dropped a coalesced + * MMIO range since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @addr: The starting address for the coalesced MMIO range. + * @len: The length of the coalesced MMIO range. + */ void (*coalesced_io_del)(MemoryListener *listener, MemoryRegionSection *section, hwaddr addr, hwaddr len); - /* Lower = earlier (during add), later (during del) */ + /** + * @priority: + * + * Govern the order in which memory listeners are invoked. Lower priorities + * are invoked earlier for "add" or "start" callbacks, and later for "delete" + * or "stop" callbacks. + */ unsigned priority; + + /* private: */ AddressSpace *address_space; QTAILQ_ENTRY(MemoryListener) link; QTAILQ_ENTRY(MemoryListener) link_as; @@ -940,6 +1142,7 @@ void memory_region_init_rom(MemoryRegion *mr, * @mr: the #MemoryRegion to be initialized. * @owner: the object that tracks the region's reference count * @ops: callbacks for write access handling (must not be NULL). + * @opaque: passed to the read and write callbacks of the @ops structure. * @name: Region name, becomes part of RAMBlock name used in migration stream * must be unique within any device * @size: size of the region. @@ -1028,7 +1231,7 @@ static inline IOMMUMemoryRegion *memory_region_get_iommu(MemoryRegion *mr) * Returns pointer to IOMMUMemoryRegionClass if a memory region is an iommu, * otherwise NULL. This is fast path avoiding QOM checking, use with caution. * - * @mr: the memory region being queried + * @iommu_mr: the memory region being queried */ static inline IOMMUMemoryRegionClass *memory_region_get_iommu_class_nocheck( IOMMUMemoryRegion *iommu_mr) @@ -1098,6 +1301,7 @@ void memory_region_notify_one(IOMMUNotifier *notifier, * @n: the IOMMUNotifier to be added; the notify callback receives a * pointer to an #IOMMUTLBEntry as the opaque value; the pointer * ceases to be valid on exit from the notifier. + * @errp: pointer to Error*, to store an error if it happens. */ int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp); @@ -1270,9 +1474,12 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr); void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp); /** - * memory_region_do_writeback: Trigger writeback for selected address range - * [addr, addr + size] + * memory_region_do_writeback: Trigger cache writeback or msync for + * selected address range * + * @mr: the memory region to be updated + * @addr: the initial address of the range to be written back + * @size: the size of the range to be written back */ void memory_region_do_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size); @@ -1591,6 +1798,8 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr, /** * memory_region_get_ram_addr: Get the ram address associated with a memory * region + * + * @mr: the region to be queried */ ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr); @@ -2161,6 +2370,7 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) * @addr: address within that address space * @attrs: memory transaction attributes * @buf: buffer with the data transferred + * @len: length of the data transferred */ static inline __attribute__((__always_inline__)) MemTxResult address_space_read(AddressSpace *as, hwaddr addr, From 72821d93e0cc8c017bf387d2f8826a827cd6dc15 Mon Sep 17 00:00:00 2001 From: Wei Yang Date: Fri, 12 Jul 2019 11:27:04 +0800 Subject: [PATCH 73/87] migration: check length directly to make sure the range is aligned Since the start addr is already checked, to make sure the range is aligned, checking the length is enough. Signed-off-by: Wei Yang Reviewed-by: Dr. David Alan Gilbert Message-Id: <20190712032704.7826-1-richardw.yang@linux.intel.com> Signed-off-by: Paolo Bonzini --- exec.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index a34c348184..dfe2096d4a 100644 --- a/exec.c +++ b/exec.c @@ -3901,10 +3901,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) if ((start + length) <= rb->used_length) { bool need_madvise, need_fallocate; - uint8_t *host_endaddr = host_startaddr + length; - if ((uintptr_t)host_endaddr & (rb->page_size - 1)) { - error_report("ram_block_discard_range: Unaligned end address: %p", - host_endaddr); + if (length & (rb->page_size - 1)) { + error_report("ram_block_discard_range: Unaligned length: %zx", + length); goto err; } From b902710f78cd982db23467b870ce53b3b8482f07 Mon Sep 17 00:00:00 2001 From: Sunil Muthuswamy Date: Wed, 13 Nov 2019 18:54:39 +0000 Subject: [PATCH 74/87] WHPX: refactor load library This refactors the load library of WHV libraries to make it more modular. It makes a helper routine that can be called on demand. This allows future expansion of load library/functions to support functionality that is dependent on some feature being available. Signed-off-by: Sunil Muthuswamy Message-Id: Signed-off-by: Paolo Bonzini --- target/i386/whp-dispatch.h | 4 ++ target/i386/whpx-all.c | 85 ++++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/target/i386/whp-dispatch.h b/target/i386/whp-dispatch.h index 23791fbb47..87d049ceab 100644 --- a/target/i386/whp-dispatch.h +++ b/target/i386/whp-dispatch.h @@ -50,5 +50,9 @@ extern struct WHPDispatch whp_dispatch; bool init_whp_dispatch(void); +typedef enum WHPFunctionList { + WINHV_PLATFORM_FNS_DEFAULT, + WINHV_EMULATION_FNS_DEFAULT, +} WHPFunctionList; #endif /* WHP_DISPATCH_H */ diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c index def0c28480..3ed2aa1892 100644 --- a/target/i386/whpx-all.c +++ b/target/i386/whpx-all.c @@ -1355,6 +1355,58 @@ static void whpx_handle_interrupt(CPUState *cpu, int mask) } } +/* + * Load the functions from the given library, using the given handle. If a + * handle is provided, it is used, otherwise the library is opened. The + * handle will be updated on return with the opened one. + */ +static bool load_whp_dispatch_fns(HMODULE *handle, + WHPFunctionList function_list) +{ + HMODULE hLib = *handle; + + #define WINHV_PLATFORM_DLL "WinHvPlatform.dll" + #define WINHV_EMULATION_DLL "WinHvEmulation.dll" + #define WHP_LOAD_FIELD(return_type, function_name, signature) \ + whp_dispatch.function_name = \ + (function_name ## _t)GetProcAddress(hLib, #function_name); \ + if (!whp_dispatch.function_name) { \ + error_report("Could not load function %s", #function_name); \ + goto error; \ + } \ + + #define WHP_LOAD_LIB(lib_name, handle_lib) \ + if (!handle_lib) { \ + handle_lib = LoadLibrary(lib_name); \ + if (!handle_lib) { \ + error_report("Could not load library %s.", lib_name); \ + goto error; \ + } \ + } \ + + switch (function_list) { + case WINHV_PLATFORM_FNS_DEFAULT: + WHP_LOAD_LIB(WINHV_PLATFORM_DLL, hLib) + LIST_WINHVPLATFORM_FUNCTIONS(WHP_LOAD_FIELD) + break; + + case WINHV_EMULATION_FNS_DEFAULT: + WHP_LOAD_LIB(WINHV_EMULATION_DLL, hLib) + LIST_WINHVEMULATION_FUNCTIONS(WHP_LOAD_FIELD) + break; + } + + *handle = hLib; + return true; + +error: + if (hLib) { + FreeLibrary(hLib); + } + + return false; +} + /* * Partition support */ @@ -1490,51 +1542,30 @@ static void whpx_type_init(void) bool init_whp_dispatch(void) { - const char *lib_name; - HMODULE hLib; - if (whp_dispatch_initialized) { return true; } - #define WHP_LOAD_FIELD(return_type, function_name, signature) \ - whp_dispatch.function_name = \ - (function_name ## _t)GetProcAddress(hLib, #function_name); \ - if (!whp_dispatch.function_name) { \ - error_report("Could not load function %s from library %s.", \ - #function_name, lib_name); \ - goto error; \ - } \ - - lib_name = "WinHvPlatform.dll"; - hWinHvPlatform = LoadLibrary(lib_name); - if (!hWinHvPlatform) { - error_report("Could not load library %s.", lib_name); + if (!load_whp_dispatch_fns(&hWinHvPlatform, WINHV_PLATFORM_FNS_DEFAULT)) { goto error; } - hLib = hWinHvPlatform; - LIST_WINHVPLATFORM_FUNCTIONS(WHP_LOAD_FIELD) - lib_name = "WinHvEmulation.dll"; - hWinHvEmulation = LoadLibrary(lib_name); - if (!hWinHvEmulation) { - error_report("Could not load library %s.", lib_name); + if (!load_whp_dispatch_fns(&hWinHvEmulation, WINHV_EMULATION_FNS_DEFAULT)) { goto error; } - hLib = hWinHvEmulation; - LIST_WINHVEMULATION_FUNCTIONS(WHP_LOAD_FIELD) whp_dispatch_initialized = true; + return true; - - error: - +error: if (hWinHvPlatform) { FreeLibrary(hWinHvPlatform); } + if (hWinHvEmulation) { FreeLibrary(hWinHvEmulation); } + return false; } From 7529a79607f86460dba0bc9b2c91b1359d5e675d Mon Sep 17 00:00:00 2001 From: Eiichi Tsukata Date: Mon, 9 Dec 2019 16:29:32 +0900 Subject: [PATCH 75/87] target/i386: remove unused pci-assign codes Legacy PCI device assignment has been already removed in commit ab37bfc7d641 ("pci-assign: Remove"), but some codes remain unused. CC: qemu-trivial@nongnu.org Signed-off-by: Eiichi Tsukata Message-Id: <20191209072932.313056-1-devel@etsukata.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 140 ----------------------------------------- target/i386/kvm_i386.h | 20 ------ 2 files changed, 160 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 55e626590b..0b511906e3 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -4512,146 +4512,6 @@ int kvm_arch_irqchip_create(KVMState *s) } } -/* Classic KVM device assignment interface. Will remain x86 only. */ -int kvm_device_pci_assign(KVMState *s, PCIHostDeviceAddress *dev_addr, - uint32_t flags, uint32_t *dev_id) -{ - struct kvm_assigned_pci_dev dev_data = { - .segnr = dev_addr->domain, - .busnr = dev_addr->bus, - .devfn = PCI_DEVFN(dev_addr->slot, dev_addr->function), - .flags = flags, - }; - int ret; - - dev_data.assigned_dev_id = - (dev_addr->domain << 16) | (dev_addr->bus << 8) | dev_data.devfn; - - ret = kvm_vm_ioctl(s, KVM_ASSIGN_PCI_DEVICE, &dev_data); - if (ret < 0) { - return ret; - } - - *dev_id = dev_data.assigned_dev_id; - - return 0; -} - -int kvm_device_pci_deassign(KVMState *s, uint32_t dev_id) -{ - struct kvm_assigned_pci_dev dev_data = { - .assigned_dev_id = dev_id, - }; - - return kvm_vm_ioctl(s, KVM_DEASSIGN_PCI_DEVICE, &dev_data); -} - -static int kvm_assign_irq_internal(KVMState *s, uint32_t dev_id, - uint32_t irq_type, uint32_t guest_irq) -{ - struct kvm_assigned_irq assigned_irq = { - .assigned_dev_id = dev_id, - .guest_irq = guest_irq, - .flags = irq_type, - }; - - if (kvm_check_extension(s, KVM_CAP_ASSIGN_DEV_IRQ)) { - return kvm_vm_ioctl(s, KVM_ASSIGN_DEV_IRQ, &assigned_irq); - } else { - return kvm_vm_ioctl(s, KVM_ASSIGN_IRQ, &assigned_irq); - } -} - -int kvm_device_intx_assign(KVMState *s, uint32_t dev_id, bool use_host_msi, - uint32_t guest_irq) -{ - uint32_t irq_type = KVM_DEV_IRQ_GUEST_INTX | - (use_host_msi ? KVM_DEV_IRQ_HOST_MSI : KVM_DEV_IRQ_HOST_INTX); - - return kvm_assign_irq_internal(s, dev_id, irq_type, guest_irq); -} - -int kvm_device_intx_set_mask(KVMState *s, uint32_t dev_id, bool masked) -{ - struct kvm_assigned_pci_dev dev_data = { - .assigned_dev_id = dev_id, - .flags = masked ? KVM_DEV_ASSIGN_MASK_INTX : 0, - }; - - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_INTX_MASK, &dev_data); -} - -static int kvm_deassign_irq_internal(KVMState *s, uint32_t dev_id, - uint32_t type) -{ - struct kvm_assigned_irq assigned_irq = { - .assigned_dev_id = dev_id, - .flags = type, - }; - - return kvm_vm_ioctl(s, KVM_DEASSIGN_DEV_IRQ, &assigned_irq); -} - -int kvm_device_intx_deassign(KVMState *s, uint32_t dev_id, bool use_host_msi) -{ - return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_INTX | - (use_host_msi ? KVM_DEV_IRQ_HOST_MSI : KVM_DEV_IRQ_HOST_INTX)); -} - -int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq) -{ - return kvm_assign_irq_internal(s, dev_id, KVM_DEV_IRQ_HOST_MSI | - KVM_DEV_IRQ_GUEST_MSI, virq); -} - -int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id) -{ - return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSI | - KVM_DEV_IRQ_HOST_MSI); -} - -bool kvm_device_msix_supported(KVMState *s) -{ - /* The kernel lacks a corresponding KVM_CAP, so we probe by calling - * KVM_ASSIGN_SET_MSIX_NR with an invalid parameter. */ - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_NR, NULL) == -EFAULT; -} - -int kvm_device_msix_init_vectors(KVMState *s, uint32_t dev_id, - uint32_t nr_vectors) -{ - struct kvm_assigned_msix_nr msix_nr = { - .assigned_dev_id = dev_id, - .entry_nr = nr_vectors, - }; - - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_NR, &msix_nr); -} - -int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector, - int virq) -{ - struct kvm_assigned_msix_entry msix_entry = { - .assigned_dev_id = dev_id, - .gsi = virq, - .entry = vector, - }; - - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_ENTRY, &msix_entry); -} - -int kvm_device_msix_assign(KVMState *s, uint32_t dev_id) -{ - return kvm_assign_irq_internal(s, dev_id, KVM_DEV_IRQ_HOST_MSIX | - KVM_DEV_IRQ_GUEST_MSIX, 0); -} - -int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id) -{ - return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSIX | - KVM_DEV_IRQ_HOST_MSIX); -} - int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, uint64_t address, uint32_t data, PCIDevice *dev) { diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h index 06fe06bdb3..7d0242f5fb 100644 --- a/target/i386/kvm_i386.h +++ b/target/i386/kvm_i386.h @@ -40,26 +40,6 @@ void kvm_synchronize_all_tsc(void); void kvm_arch_reset_vcpu(X86CPU *cs); void kvm_arch_do_init_vcpu(X86CPU *cs); -int kvm_device_pci_assign(KVMState *s, PCIHostDeviceAddress *dev_addr, - uint32_t flags, uint32_t *dev_id); -int kvm_device_pci_deassign(KVMState *s, uint32_t dev_id); - -int kvm_device_intx_assign(KVMState *s, uint32_t dev_id, - bool use_host_msi, uint32_t guest_irq); -int kvm_device_intx_set_mask(KVMState *s, uint32_t dev_id, bool masked); -int kvm_device_intx_deassign(KVMState *s, uint32_t dev_id, bool use_host_msi); - -int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq); -int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id); - -bool kvm_device_msix_supported(KVMState *s); -int kvm_device_msix_init_vectors(KVMState *s, uint32_t dev_id, - uint32_t nr_vectors); -int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector, - int virq); -int kvm_device_msix_assign(KVMState *s, uint32_t dev_id); -int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id); - void kvm_put_apicbase(X86CPU *cpu, uint64_t value); bool kvm_enable_x2apic(void); From 7332a4a468d7ee9f3e4f0f324bf2c87fafd0f6be Mon Sep 17 00:00:00 2001 From: Cameron Esfahani Date: Fri, 6 Dec 2019 18:33:30 -0800 Subject: [PATCH 76/87] Fix some comment spelling errors. Signed-off-by: Cameron Esfahani Message-Id: <086c197db928384b8697edfa64755e2cb46c8100.1575685843.git.dirty@apple.com> Reviewed-by: Stefan Weil Signed-off-by: Paolo Bonzini --- target/i386/machine.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/machine.c b/target/i386/machine.c index b6720d86b0..0c96531a56 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -261,7 +261,7 @@ static int cpu_pre_save(void *opaque) * intercepted anymore. * * Furthermore, when a L2 exception is intercepted by L1 - * hypervisor, it's exception payload (CR2/DR6 on #PF/#DB) + * hypervisor, its exception payload (CR2/DR6 on #PF/#DB) * should not be set yet in the respective vCPU register. * Thus, in case an exception is pending, it is * important to save the exception payload seperately. @@ -271,9 +271,9 @@ static int cpu_pre_save(void *opaque) * distinguish between a pending and injected exception * and we don't need to store seperately the exception payload. * - * In order to preserve better backwards-compatabile migration, + * In order to preserve better backwards-compatible migration, * convert a pending exception to an injected exception in - * case it is not important to distingiush between them + * case it is not important to distinguish between them * as described above. */ if (env->exception_pending && !(env->hflags & HF_GUEST_MASK)) { @@ -415,7 +415,7 @@ static bool exception_info_needed(void *opaque) /* * It is important to save exception-info only in case - * we need to distingiush between a pending and injected + * we need to distinguish between a pending and injected * exception. Which is only required in case there is a * pending exception and vCPU is running L2. * For more info, refer to comment in cpu_pre_save(). From cd3fdb7f26265eb2e08ca0d74245980cb10d4bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 9 Dec 2019 10:49:57 +0100 Subject: [PATCH 77/87] hw/pci-host/i440fx: Correct the header description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Missed during the refactor in commits 14a026dd58 and 0f25d865a, this file is now only about the i440FX chipset. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Message-Id: <20191209095002.32194-2-philmd@redhat.com> Signed-off-by: Paolo Bonzini --- hw/pci-host/i440fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index f27131102d..3fc94426ea 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -1,5 +1,5 @@ /* - * QEMU i440FX/PIIX3 PCI Bridge Emulation + * QEMU i440FX PCI Bridge Emulation * * Copyright (c) 2006 Fabrice Bellard * From 340207607369f04c14665d94d5e172641391db1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 9 Dec 2019 10:49:58 +0100 Subject: [PATCH 78/87] hw/pci-host/i440fx: Extract PCII440FXState to "hw/pci-host/i440fx.h" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the PCII440FXState structure public, so it can be used out of this source file. This will allow us to extract the IGD Passthrough Host Bridge, which is a children of the TYPE_I440FX_PCI_DEVICE. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Message-Id: <20191209095002.32194-3-philmd@redhat.com> Signed-off-by: Paolo Bonzini --- hw/pci-host/i440fx.c | 18 ------------------ include/hw/pci-host/i440fx.h | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index 3fc94426ea..fbdc563599 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -31,7 +31,6 @@ #include "hw/sysbus.h" #include "qapi/error.h" #include "migration/vmstate.h" -#include "hw/pci-host/pam.h" #include "qapi/visitor.h" #include "qemu/error-report.h" @@ -51,23 +50,6 @@ typedef struct I440FXState { uint32_t short_root_bus; } I440FXState; -#define I440FX_PCI_DEVICE(obj) \ - OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) - -struct PCII440FXState { - /*< private >*/ - PCIDevice parent_obj; - /*< public >*/ - - MemoryRegion *system_memory; - MemoryRegion *pci_address_space; - MemoryRegion *ram_memory; - PAMMemoryRegion pam_regions[13]; - MemoryRegion smram_region; - MemoryRegion smram, low_smram; -}; - - #define I440FX_PAM 0x59 #define I440FX_PAM_SIZE 7 #define I440FX_SMRAM 0x72 diff --git a/include/hw/pci-host/i440fx.h b/include/hw/pci-host/i440fx.h index f54e6466e4..cc58d82ed4 100644 --- a/include/hw/pci-host/i440fx.h +++ b/include/hw/pci-host/i440fx.h @@ -13,12 +13,27 @@ #include "hw/hw.h" #include "hw/pci/pci_bus.h" - -typedef struct PCII440FXState PCII440FXState; +#include "hw/pci-host/pam.h" #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost" #define TYPE_I440FX_PCI_DEVICE "i440FX" +#define I440FX_PCI_DEVICE(obj) \ + OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) + +typedef struct PCII440FXState { + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + + MemoryRegion *system_memory; + MemoryRegion *pci_address_space; + MemoryRegion *ram_memory; + PAMMemoryRegion pam_regions[13]; + MemoryRegion smram_region; + MemoryRegion smram, low_smram; +} PCII440FXState; + #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX" PCIBus *i440fx_init(const char *host_type, const char *pci_type, From 2d61acebe8d8891b5f63fc7221926c1d00bdbd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 9 Dec 2019 10:49:59 +0100 Subject: [PATCH 79/87] hw/pci-host/i440fx: Use size_t to iterate over ARRAY_SIZE() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't enforce the -Wsign-conversion CPPFLAG, but it doesn't hurt to avoid this warning: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion] Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Message-Id: <20191209095002.32194-4-philmd@redhat.com> Signed-off-by: Paolo Bonzini --- hw/pci-host/i440fx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index fbdc563599..0cc80b276d 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -419,12 +419,11 @@ out: static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) { uint32_t val = 0; - int i, num; + size_t i; int pos, len; Error *local_err = NULL; - num = ARRAY_SIZE(igd_host_bridge_infos); - for (i = 0; i < num; i++) { + for (i = 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) { pos = igd_host_bridge_infos[i].offset; len = igd_host_bridge_infos[i].len; host_pci_config_read(pos, len, &val, &local_err); From 86a31fbcbf530380be781157ebbd1ac153cd89e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 9 Dec 2019 10:50:00 +0100 Subject: [PATCH 80/87] hw/pci-host/i440fx: Use definitions instead of magic values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use definitions from "hw/pci/pci_regs.h". This also helps when using git-grep. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Message-Id: <20191209095002.32194-5-philmd@redhat.com> Signed-off-by: Paolo Bonzini --- hw/pci-host/i440fx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index 0cc80b276d..414138595b 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -376,13 +376,13 @@ typedef struct { /* Here we just expose minimal host bridge offset subset. */ static const IGDHostInfo igd_host_bridge_infos[] = { - {0x08, 2}, /* revision id */ - {0x2c, 2}, /* sybsystem vendor id */ - {0x2e, 2}, /* sybsystem id */ - {0x50, 2}, /* SNB: processor graphics control register */ - {0x52, 2}, /* processor graphics control register */ - {0xa4, 4}, /* SNB: graphics base of stolen memory */ - {0xa8, 4}, /* SNB: base of GTT stolen memory */ + {PCI_REVISION_ID, 2}, + {PCI_SUBSYSTEM_VENDOR_ID, 2}, + {PCI_SUBSYSTEM_ID, 2}, + {0x50, 2}, /* SNB: processor graphics control register */ + {0x52, 2}, /* processor graphics control register */ + {0xa4, 4}, /* SNB: graphics base of stolen memory */ + {0xa8, 4}, /* SNB: base of GTT stolen memory */ }; static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp) From 1401897cd1b2ace4c726022aea8b2f63fe462002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 9 Dec 2019 10:50:01 +0100 Subject: [PATCH 81/87] hw/pci-host/i440fx: Extract the IGD passthrough host bridge device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can use a i440FX without the IGD passthrough host bridge. Extract it into a new file, 'hw/pci-host/xen_igd_pt.c'. Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20191209095002.32194-6-philmd@redhat.com> Acked-by: Paul Durrant Signed-off-by: Paolo Bonzini --- MAINTAINERS | 1 + hw/pci-host/Makefile.objs | 1 + hw/pci-host/i440fx.c | 84 -------------------------- hw/pci-host/xen_igd_pt.c | 120 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 84 deletions(-) create mode 100644 hw/pci-host/xen_igd_pt.c diff --git a/MAINTAINERS b/MAINTAINERS index 740401bcbb..0c36106996 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -420,6 +420,7 @@ F: hw/block/dataplane/xen* F: hw/xen/ F: hw/xenpv/ F: hw/i386/xen/ +F: hw/pci-host/xen_igd_pt.c F: include/hw/block/dataplane/xen* F: include/hw/xen/ F: include/sysemu/xen-mapcache.h diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs index efd752b766..fa6d1556c0 100644 --- a/hw/pci-host/Makefile.objs +++ b/hw/pci-host/Makefile.objs @@ -14,6 +14,7 @@ common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o common-obj-$(CONFIG_PCI_SABRE) += sabre.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_I440FX) += i440fx.o +common-obj-$(CONFIG_PCI_I440FX) += xen_igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) += q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) += gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) += xilinx-pcie.o diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index 414138595b..bae7b42327 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -368,89 +368,6 @@ static const TypeInfo i440fx_info = { }, }; -/* IGD Passthrough Host Bridge. */ -typedef struct { - uint8_t offset; - uint8_t len; -} IGDHostInfo; - -/* Here we just expose minimal host bridge offset subset. */ -static const IGDHostInfo igd_host_bridge_infos[] = { - {PCI_REVISION_ID, 2}, - {PCI_SUBSYSTEM_VENDOR_ID, 2}, - {PCI_SUBSYSTEM_ID, 2}, - {0x50, 2}, /* SNB: processor graphics control register */ - {0x52, 2}, /* processor graphics control register */ - {0xa4, 4}, /* SNB: graphics base of stolen memory */ - {0xa8, 4}, /* SNB: base of GTT stolen memory */ -}; - -static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp) -{ - int rc, config_fd; - /* Access real host bridge. */ - char *path = g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", - 0, 0, 0, 0, "config"); - - config_fd = open(path, O_RDWR); - if (config_fd < 0) { - error_setg_errno(errp, errno, "Failed to open: %s", path); - goto out; - } - - if (lseek(config_fd, pos, SEEK_SET) != pos) { - error_setg_errno(errp, errno, "Failed to seek: %s", path); - goto out_close_fd; - } - - do { - rc = read(config_fd, (uint8_t *)val, len); - } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); - if (rc != len) { - error_setg_errno(errp, errno, "Failed to read: %s", path); - } - -out_close_fd: - close(config_fd); -out: - g_free(path); -} - -static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) -{ - uint32_t val = 0; - size_t i; - int pos, len; - Error *local_err = NULL; - - for (i = 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) { - pos = igd_host_bridge_infos[i].offset; - len = igd_host_bridge_infos[i].len; - host_pci_config_read(pos, len, &val, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - pci_default_write_config(pci_dev, pos, val, len); - } -} - -static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - - k->realize = igd_pt_i440fx_realize; - dc->desc = "IGD Passthrough Host bridge"; -} - -static const TypeInfo igd_passthrough_i440fx_info = { - .name = TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE, - .parent = TYPE_I440FX_PCI_DEVICE, - .instance_size = sizeof(PCII440FXState), - .class_init = igd_passthrough_i440fx_class_init, -}; - static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, PCIBus *rootbus) { @@ -495,7 +412,6 @@ static const TypeInfo i440fx_pcihost_info = { static void i440fx_register_types(void) { type_register_static(&i440fx_info); - type_register_static(&igd_passthrough_i440fx_info); type_register_static(&i440fx_pcihost_info); } diff --git a/hw/pci-host/xen_igd_pt.c b/hw/pci-host/xen_igd_pt.c new file mode 100644 index 0000000000..efcc9347ff --- /dev/null +++ b/hw/pci-host/xen_igd_pt.c @@ -0,0 +1,120 @@ +/* + * QEMU Intel IGD Passthrough Host Bridge Emulation + * + * Copyright (c) 2006 Fabrice Bellard + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" +#include "hw/pci-host/i440fx.h" +#include "qapi/error.h" + +typedef struct { + uint8_t offset; + uint8_t len; +} IGDHostInfo; + +/* Here we just expose minimal host bridge offset subset. */ +static const IGDHostInfo igd_host_bridge_infos[] = { + {PCI_REVISION_ID, 2}, + {PCI_SUBSYSTEM_VENDOR_ID, 2}, + {PCI_SUBSYSTEM_ID, 2}, + {0x50, 2}, /* SNB: processor graphics control register */ + {0x52, 2}, /* processor graphics control register */ + {0xa4, 4}, /* SNB: graphics base of stolen memory */ + {0xa8, 4}, /* SNB: base of GTT stolen memory */ +}; + +static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp) +{ + int rc, config_fd; + /* Access real host bridge. */ + char *path = g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", + 0, 0, 0, 0, "config"); + + config_fd = open(path, O_RDWR); + if (config_fd < 0) { + error_setg_errno(errp, errno, "Failed to open: %s", path); + goto out; + } + + if (lseek(config_fd, pos, SEEK_SET) != pos) { + error_setg_errno(errp, errno, "Failed to seek: %s", path); + goto out_close_fd; + } + + do { + rc = read(config_fd, (uint8_t *)val, len); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc != len) { + error_setg_errno(errp, errno, "Failed to read: %s", path); + } + + out_close_fd: + close(config_fd); + out: + g_free(path); +} + +static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) +{ + uint32_t val = 0; + size_t i; + int pos, len; + Error *local_err = NULL; + + for (i = 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) { + pos = igd_host_bridge_infos[i].offset; + len = igd_host_bridge_infos[i].len; + host_pci_config_read(pos, len, &val, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + pci_default_write_config(pci_dev, pos, val, len); + } +} + +static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->realize = igd_pt_i440fx_realize; + dc->desc = "IGD Passthrough Host bridge"; +} + +static const TypeInfo igd_passthrough_i440fx_info = { + .name = TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE, + .parent = TYPE_I440FX_PCI_DEVICE, + .instance_size = sizeof(PCII440FXState), + .class_init = igd_passthrough_i440fx_class_init, +}; + +static void igd_pt_i440fx_register_types(void) +{ + type_register_static(&igd_passthrough_i440fx_info); +} + +type_init(igd_pt_i440fx_register_types) From 3066573ee5e2a7e37638cd91afcd3d8b4a09a227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 9 Dec 2019 10:50:02 +0100 Subject: [PATCH 82/87] hw/pci-host: Add Kconfig entry to select the IGD Passthrough Host Bridge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the XEN_IGD_PASSTHROUGH Kconfig option. Xen build has that option selected by default. Non-Xen builds now have to select this feature manually. Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20191209095002.32194-7-philmd@redhat.com> Acked-by: Paul Durrant Signed-off-by: Paolo Bonzini --- hw/pci-host/Kconfig | 5 +++++ hw/pci-host/Makefile.objs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig index b0aa8351c4..9642c77e98 100644 --- a/hw/pci-host/Kconfig +++ b/hw/pci-host/Kconfig @@ -1,6 +1,11 @@ config PAM bool +config XEN_IGD_PASSTHROUGH + bool + default y + depends on XEN && PCI_I440FX + config PREP_PCI bool select PCI diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs index fa6d1556c0..9c466fab01 100644 --- a/hw/pci-host/Makefile.objs +++ b/hw/pci-host/Makefile.objs @@ -14,7 +14,7 @@ common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o common-obj-$(CONFIG_PCI_SABRE) += sabre.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_I440FX) += i440fx.o -common-obj-$(CONFIG_PCI_I440FX) += xen_igd_pt.o +common-obj-$(CONFIG_XEN_IGD_PASSTHROUGH) += xen_igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) += q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) += gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) += xilinx-pcie.o From 30d2a17b46e9b2979e91f6d85c8b0da98879a879 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 9 Dec 2019 13:52:45 +0100 Subject: [PATCH 83/87] hw/i386: Remove the deprecated machines 0.12 up to 0.15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These machines can't be used reliably for migration anymore, quoting https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg04516.html : " due to the introduction of the memory API, the firmware is not migrated correctly from source to destination. On QEMU <1.3 the 0xf0000-0xfffff area is basically a copy of the higher 0xffff0000-0xffffffff area, while on more recent versions it is initialized with zeroes and the firmware copies from 0xffff0000 to 0xf0000. When you migrate from old to new QEMU, after reboot there's nothing at 0xf0000 and bugs ensue. " The pc-0.x machines have been marked as deprecated since QEMU v4.0, so it is time to remove them now. And while we're at it, mark the remaining pc-1.x machine types as deprecated now, too, so that we finally only have "pc-i440fx" and "pc-q35" machine types left (apart from the non-versioned "isapc" and "microvm") once we remove them in a couple of releases. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Thomas Huth Message-Id: <20191209125248.5849-2-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc_piix.c | 85 +------------------------------------------ qemu-deprecated.texi | 2 +- tests/cpu-plug-test.c | 6 +-- 3 files changed, 4 insertions(+), 89 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index b3f0304ca3..721c7aa64e 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -357,19 +357,13 @@ static void pc_compat_1_3(MachineState *machine) pc_compat_1_4_fn(machine); } -/* PC compat function for pc-0.14 to pc-1.2 */ +/* PC compat function for pc-1.0 to pc-1.2 */ static void pc_compat_1_2(MachineState *machine) { pc_compat_1_3(machine); x86_cpu_change_kvm_default("kvm-pv-eoi", NULL); } -/* PC compat function for pc-0.12 and pc-0.13 */ -static void pc_compat_0_13(MachineState *machine) -{ - pc_compat_1_2(machine); -} - static void pc_init_isa(MachineState *machine) { pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, TYPE_I440FX_PCI_DEVICE); @@ -745,6 +739,7 @@ static void pc_i440fx_1_3_machine_options(MachineClass *m) pc_i440fx_1_4_machine_options(m); m->hw_version = "1.3.0"; + m->deprecation_reason = "use a newer machine type instead"; x86mc->compat_apic_id_mode = true; compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); } @@ -813,82 +808,6 @@ DEFINE_I440FX_MACHINE(v1_0, "pc-1.0", pc_compat_1_2, pc_i440fx_1_0_machine_options); -static void pc_i440fx_0_15_machine_options(MachineClass *m) -{ - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.15") - }; - - pc_i440fx_1_0_machine_options(m); - m->hw_version = "0.15"; - m->deprecation_reason = "use a newer machine type instead"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); -} - -DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2, - pc_i440fx_0_15_machine_options); - - -static void pc_i440fx_0_14_machine_options(MachineClass *m) -{ - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.14") - { "virtio-blk-pci", "event_idx", "off" }, - { "virtio-serial-pci", "event_idx", "off" }, - { "virtio-net-pci", "event_idx", "off" }, - { "virtio-balloon-pci", "event_idx", "off" }, - { "qxl", "revision", "2" }, - { "qxl-vga", "revision", "2" }, - }; - - pc_i440fx_0_15_machine_options(m); - m->hw_version = "0.14"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); -} - -DEFINE_I440FX_MACHINE(v0_14, "pc-0.14", pc_compat_1_2, - pc_i440fx_0_14_machine_options); - -static void pc_i440fx_0_13_machine_options(MachineClass *m) -{ - PCMachineClass *pcmc = PC_MACHINE_CLASS(m); - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.13") - { TYPE_PCI_DEVICE, "command_serr_enable", "off" }, - { "AC97", "use_broken_id", "1" }, - { "virtio-9p-pci", "vectors", "0" }, - { "VGA", "rombar", "0" }, - { "vmware-svga", "rombar", "0" }, - }; - - pc_i440fx_0_14_machine_options(m); - m->hw_version = "0.13"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); - pcmc->kvmclock_enabled = false; -} - -DEFINE_I440FX_MACHINE(v0_13, "pc-0.13", pc_compat_0_13, - pc_i440fx_0_13_machine_options); - -static void pc_i440fx_0_12_machine_options(MachineClass *m) -{ - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.12") - { "virtio-serial-pci", "max_ports", "1" }, - { "virtio-serial-pci", "vectors", "0" }, - { "usb-mouse", "serial", "1" }, - { "usb-tablet", "serial", "1" }, - { "usb-kbd", "serial", "1" }, - }; - - pc_i440fx_0_13_machine_options(m); - m->hw_version = "0.12"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); -} - -DEFINE_I440FX_MACHINE(v0_12, "pc-0.12", pc_compat_0_13, - pc_i440fx_0_12_machine_options); - typedef struct { uint16_t gpu_device_id; uint16_t pch_device_id; diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index e88f6d1a9a..97ba3cb88c 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -265,7 +265,7 @@ The 'scsi-disk' device is deprecated. Users should use 'scsi-hd' or This machine type is very old and unmaintained. Users should use the 'malta' machine type instead. -@subsection pc-0.12, pc-0.13, pc-0.14 and pc-0.15 (since 4.0) +@subsection pc-1.0, pc-1.1, pc-1.2 and pc-1.3 (since 5.0) These machine types are very old and likely can not be used for live migration from old QEMU versions anymore. A newer machine type should be used instead. diff --git a/tests/cpu-plug-test.c b/tests/cpu-plug-test.c index 30e514bbfb..e8ffbbce4b 100644 --- a/tests/cpu-plug-test.c +++ b/tests/cpu-plug-test.c @@ -148,11 +148,7 @@ static void add_pc_test_case(const char *mname) (strcmp(mname, "pc-1.3") == 0) || (strcmp(mname, "pc-1.2") == 0) || (strcmp(mname, "pc-1.1") == 0) || - (strcmp(mname, "pc-1.0") == 0) || - (strcmp(mname, "pc-0.15") == 0) || - (strcmp(mname, "pc-0.14") == 0) || - (strcmp(mname, "pc-0.13") == 0) || - (strcmp(mname, "pc-0.12") == 0)) { + (strcmp(mname, "pc-1.0") == 0)) { path = g_strdup_printf("cpu-plug/%s/init/%ux%ux%u&maxcpus=%u", mname, data->sockets, data->cores, data->threads, data->maxcpus); From c6026998eef382d7ad7613c80439da640e65904c Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 9 Dec 2019 13:52:46 +0100 Subject: [PATCH 84/87] hw/audio: Remove the "use_broken_id" hack from the AC97 device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that the old pc-0.x machine types are gone, we do not need the "use_broken_id" hack anymore. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Thomas Huth Message-Id: <20191209125248.5849-3-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- hw/audio/ac97.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c index a136b97f68..78cda88333 100644 --- a/hw/audio/ac97.c +++ b/hw/audio/ac97.c @@ -161,7 +161,6 @@ typedef struct AC97BusMasterRegs { typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card; - uint32_t use_broken_id; uint32_t glob_cnt; uint32_t glob_sta; uint32_t cas; @@ -1373,13 +1372,6 @@ static void ac97_realize(PCIDevice *dev, Error **errp) c[PCI_BASE_ADDRESS_0 + 6] = 0x00; c[PCI_BASE_ADDRESS_0 + 7] = 0x00; - if (s->use_broken_id) { - c[PCI_SUBSYSTEM_VENDOR_ID] = 0x86; - c[PCI_SUBSYSTEM_VENDOR_ID + 1] = 0x80; - c[PCI_SUBSYSTEM_ID] = 0x00; - c[PCI_SUBSYSTEM_ID + 1] = 0x00; - } - c[PCI_INTERRUPT_LINE] = 0x00; /* intr_ln interrupt line rw */ c[PCI_INTERRUPT_PIN] = 0x01; /* intr_pn interrupt pin ro */ @@ -1411,7 +1403,6 @@ static int ac97_init (PCIBus *bus) static Property ac97_properties[] = { DEFINE_AUDIO_PROPERTIES(AC97LinkState, card), - DEFINE_PROP_UINT32 ("use_broken_id", AC97LinkState, use_broken_id, 0), DEFINE_PROP_END_OF_LIST (), }; From 2a4dbaf1c0db2453ab78fe4b1c2a8fcb6163a672 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 9 Dec 2019 13:52:47 +0100 Subject: [PATCH 85/87] hw/pci: Remove the "command_serr_enable" property Now that the old pc-0.x machine types have been removed, this config knob is not required anymore. Signed-off-by: Thomas Huth Message-Id: <20191209125248.5849-4-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- hw/pci/pci.c | 6 +----- include/hw/pci/pci.h | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index cbc7a32568..e3d310365d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -69,8 +69,6 @@ static Property pci_props[] = { DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), - DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present, - QEMU_PCI_CAP_SERR_BITNR, true), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, QEMU_PCIE_LNKSTA_DLLLA_BITNR, true), DEFINE_PROP_BIT("x-pcie-extcap-init", PCIDevice, cap_present, @@ -751,9 +749,7 @@ static void pci_init_wmask(PCIDevice *dev) pci_set_word(dev->wmask + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INTX_DISABLE); - if (dev->cap_present & QEMU_PCI_CAP_SERR) { - pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR); - } + pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff, config_size - PCI_CONFIG_HEADER_SIZE); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index db75c6dfd0..2acd8321af 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -174,7 +174,7 @@ enum { #define QEMU_PCI_CAP_MULTIFUNCTION_BITNR 3 QEMU_PCI_CAP_MULTIFUNCTION = (1 << QEMU_PCI_CAP_MULTIFUNCTION_BITNR), - /* command register SERR bit enabled */ + /* command register SERR bit enabled - unused since QEMU v5.0 */ #define QEMU_PCI_CAP_SERR_BITNR 4 QEMU_PCI_CAP_SERR = (1 << QEMU_PCI_CAP_SERR_BITNR), /* Standard hot plug controller. */ From 97d8381543647887bc2997ecfeccc67831e47fdc Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 9 Dec 2019 13:52:48 +0100 Subject: [PATCH 86/87] hw/display: Remove "rombar" hack from vga-pci and vmware_vga Now that the old pc-0.x machine types have been removed, we do not need the old "rombar" hacks anymore. Signed-off-by: Thomas Huth Message-Id: <20191209125248.5849-5-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- hw/display/vga-pci.c | 5 ----- hw/display/vga.c | 4 +--- hw/display/vmware_vga.c | 5 ----- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/hw/display/vga-pci.c b/hw/display/vga-pci.c index a27b88122d..cfe095713e 100644 --- a/hw/display/vga-pci.c +++ b/hw/display/vga-pci.c @@ -264,11 +264,6 @@ static void pci_std_vga_realize(PCIDevice *dev, Error **errp) pci_register_bar(&d->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); } - - if (!dev->rom_bar) { - /* compatibility with pc-0.13 and older */ - vga_init_vbe(s, OBJECT(dev), pci_address_space(dev)); - } } static void pci_std_vga_init(Object *obj) diff --git a/hw/display/vga.c b/hw/display/vga.c index 82ebe53610..636586a476 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -2304,9 +2304,7 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space, void vga_init_vbe(VGACommonState *s, Object *obj, MemoryRegion *system_memory) { - /* With pc-0.12 and below we map both the PCI BAR and the fixed VBE region, - * so use an alias to avoid double-mapping the same region. - */ + /* Use an alias to avoid double-mapping the same region */ memory_region_init_alias(&s->vram_vbe, obj, "vram.vbe", &s->vram, 0, memory_region_size(&s->vram)); /* XXX: use optimized standard vga accesses */ diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c index 23dc8910cc..ead754eccf 100644 --- a/hw/display/vmware_vga.c +++ b/hw/display/vmware_vga.c @@ -1312,11 +1312,6 @@ static void pci_vmsvga_realize(PCIDevice *dev, Error **errp) &s->chip.vga.vram); pci_register_bar(dev, 2, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->chip.fifo_ram); - - if (!dev->rom_bar) { - /* compatibility with pc-0.13 and older */ - vga_init_vbe(&s->chip.vga, OBJECT(dev), pci_address_space(dev)); - } } static Property vga_vmware_properties[] = { From e2328a11bda7a4d087200c524333adafb8beb7d7 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 9 Dec 2019 14:30:08 +0100 Subject: [PATCH 87/87] vga: cleanup mapping of VRAM for non-PCI VGA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vga_init_vbe is now used only from ISA VGA cards. Since the alias is not needed anymore, remove it (effectively reverting commit 8294a64d7f, "vga: fix vram double-mapping with -vga std and -M pc-0.12", 2012-05-29) and the now unused vbe_mapped field of VGACommonState. The function now consists of a single memory_region_add_subregion call, so we can inline it; this avoids incorrect usage from PCI cards. Suggested-by: Philippe Mathieu-Daudé Based-on: <05af415a-5058-98b4-4a12-9d093a30b1e3@redhat.com> Signed-off-by: Paolo Bonzini --- hw/display/vga-isa-mm.c | 5 ++++- hw/display/vga-isa.c | 4 +++- hw/display/vga.c | 12 ------------ hw/display/vga_int.h | 3 --- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/hw/display/vga-isa-mm.c b/hw/display/vga-isa-mm.c index e9c43e5530..7321b7a06d 100644 --- a/hw/display/vga-isa-mm.c +++ b/hw/display/vga-isa-mm.c @@ -106,6 +106,9 @@ int isa_vga_mm_init(hwaddr vram_base, s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s); - vga_init_vbe(&s->vga, NULL, address_space); + memory_region_add_subregion(address_space, + VBE_DISPI_LFB_PHYSICAL_ADDRESS, + &s->vga.vram); + return 0; } diff --git a/hw/display/vga-isa.c b/hw/display/vga-isa.c index 873e5e9706..08a2730db5 100644 --- a/hw/display/vga-isa.c +++ b/hw/display/vga-isa.c @@ -76,7 +76,9 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp) memory_region_set_coalescing(vga_io_memory); s->con = graphic_console_init(DEVICE(dev), 0, s->hw_ops, s); - vga_init_vbe(s, OBJECT(dev), isa_address_space(isadev)); + memory_region_add_subregion(isa_address_space(isadev), + VBE_DISPI_LFB_PHYSICAL_ADDRESS, + &s->vram); /* ROM BIOS */ rom_add_vga(VGABIOS_FILENAME); } diff --git a/hw/display/vga.c b/hw/display/vga.c index 636586a476..061fd9ab8f 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -2301,15 +2301,3 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space, portio_list_add(&s->vbe_port_list, address_space_io, 0x1ce); } } - -void vga_init_vbe(VGACommonState *s, Object *obj, MemoryRegion *system_memory) -{ - /* Use an alias to avoid double-mapping the same region */ - memory_region_init_alias(&s->vram_vbe, obj, "vram.vbe", - &s->vram, 0, memory_region_size(&s->vram)); - /* XXX: use optimized standard vga accesses */ - memory_region_add_subregion(system_memory, - VBE_DISPI_LFB_PHYSICAL_ADDRESS, - &s->vram_vbe); - s->vbe_mapped = 1; -} diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 55c418eab5..847e784ca6 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -60,7 +60,6 @@ typedef struct VGACommonState { MemoryRegion *legacy_address_space; uint8_t *vram_ptr; MemoryRegion vram; - MemoryRegion vram_vbe; uint32_t vram_size; uint32_t vram_size_mb; /* property */ uint32_t vbe_size; @@ -106,7 +105,6 @@ typedef struct VGACommonState { uint32_t vbe_start_addr; uint32_t vbe_line_offset; uint32_t vbe_bank_mask; - int vbe_mapped; /* display refresh support */ QemuConsole *con; uint32_t font_offsets[2]; @@ -178,7 +176,6 @@ void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2); int vga_ioport_invalid(VGACommonState *s, uint32_t addr); -void vga_init_vbe(VGACommonState *s, Object *obj, MemoryRegion *address_space); uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr); void vbe_ioport_write_index(void *opaque, uint32_t addr, uint32_t val); void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val);