From 75b208c28316095c4685e8596ceb9e3f656592e2 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 23 Nov 2020 07:17:47 -0500 Subject: target/i386: fix operand order for PDEP and PEXT For PDEP and PEXT, the mask is provided in the memory (mod+r/m) operand, and therefore is loaded in s->T0 by gen_ldst_modrm. The source is provided in the second source operand (VEX.vvvv) and therefore is loaded in s->T1. Fix the order in which they are passed to the helpers. Reported-by: Lenard Szolnoki Analyzed-by: Lenard Szolnoki Fixes: https://bugs.launchpad.net/qemu/+bug/1605123 Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- tests/tcg/i386/Makefile.target | 3 +++ tests/tcg/i386/test-i386-bmi2.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/tcg/i386/test-i386-bmi2.c (limited to 'tests') diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target index a66232a..ad187cb 100644 --- a/tests/tcg/i386/Makefile.target +++ b/tests/tcg/i386/Makefile.target @@ -18,6 +18,9 @@ test-i386-pcmpistri: CFLAGS += -msse4.2 run-test-i386-pcmpistri: QEMU_OPTS += -cpu max run-plugin-test-i386-pcmpistri-%: QEMU_OPTS += -cpu max +run-test-i386-bmi2: QEMU_OPTS += -cpu max +run-plugin-test-i386-bmi2-%: QEMU_OPTS += -cpu max + # # hello-i386 is a barebones app # diff --git a/tests/tcg/i386/test-i386-bmi2.c b/tests/tcg/i386/test-i386-bmi2.c new file mode 100644 index 0000000..935a4d2 --- /dev/null +++ b/tests/tcg/i386/test-i386-bmi2.c @@ -0,0 +1,42 @@ +/* See if various BMI2 instructions give expected results */ +#include +#include + +int main(int argc, char *argv[]) { + uint64_t ehlo = 0x202020204f4c4845ull; + uint64_t mask = 0xa080800302020001ull; + uint32_t result32; + +#ifdef __x86_64 + uint64_t result64; + + /* 64 bits */ + asm volatile ("pextq %2, %1, %0" : "=r"(result64) : "r"(ehlo), "m"(mask)); + assert(result64 == 133); + + asm volatile ("pdepq %2, %1, %0" : "=r"(result64) : "r"(result64), "m"(mask)); + assert(result64 == (ehlo & mask)); + + asm volatile ("pextq %2, %1, %0" : "=r"(result64) : "r"(-1ull), "m"(mask)); + assert(result64 == 511); /* mask has 9 bits set */ + + asm volatile ("pdepq %2, %1, %0" : "=r"(result64) : "r"(-1ull), "m"(mask)); + assert(result64 == mask); +#endif + + /* 32 bits */ + asm volatile ("pextl %2, %k1, %k0" : "=r"(result32) : "r"((uint32_t) ehlo), "m"(mask)); + assert(result32 == 5); + + asm volatile ("pdepl %2, %k1, %k0" : "=r"(result32) : "r"(result32), "m"(mask)); + assert(result32 == (uint32_t)(ehlo & mask)); + + asm volatile ("pextl %2, %k1, %k0" : "=r"(result32) : "r"(-1ull), "m"(mask)); + assert(result32 == 7); /* mask has 3 bits set */ + + asm volatile ("pdepl %2, %k1, %k0" : "=r"(result32) : "r"(-1ull), "m"(mask)); + assert(result32 == (uint32_t)mask); + + return 0; +} + -- cgit v1.1 From 991c180d740c04c2f8c08c8783ad868fc832589f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 13 Nov 2020 03:10:52 -0500 Subject: treewide: do not use short-form boolean options They are going to be deprecated, avoid warnings on stdout while the tests run. Signed-off-by: Paolo Bonzini --- tests/qtest/bios-tables-test.c | 4 ++-- tests/qtest/pflash-cfi02-test.c | 4 ++-- tests/qtest/test-filter-redirector.c | 8 ++++---- tests/qtest/vhost-user-test.c | 8 ++++---- tests/test-char.c | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c index f2f79dd..4e026f9 100644 --- a/tests/qtest/bios-tables-test.c +++ b/tests/qtest/bios-tables-test.c @@ -674,14 +674,14 @@ static void test_acpi_one(const char *params, test_data *data) if (data->cd) { 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,readonly=on " "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s", data->machine, data->tcg_only ? "" : "-accel kvm", data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : ""); } else { 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,readonly=on " "-drive if=pflash,format=raw,file=%s,snapshot=on %s", data->machine, data->tcg_only ? "" : "-accel kvm", data->uefi_fl1, data->uefi_fl2, params ? params : ""); diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c index afb702b..60db81a 100644 --- a/tests/qtest/pflash-cfi02-test.c +++ b/tests/qtest/pflash-cfi02-test.c @@ -261,7 +261,7 @@ static void test_geometry(const void *opaque) const FlashConfig *config = opaque; QTestState *qtest; qtest = qtest_initf("-M musicpal" - " -drive if=pflash,file=%s,format=raw,copy-on-read" + " -drive if=pflash,file=%s,format=raw,copy-on-read=on" /* Device geometry properties. */ " -global driver=cfi.pflash02," "property=num-blocks0,value=%d" @@ -581,7 +581,7 @@ static void test_cfi_in_autoselect(const void *opaque) const FlashConfig *config = opaque; QTestState *qtest; qtest = qtest_initf("-M musicpal" - " -drive if=pflash,file=%s,format=raw,copy-on-read", + " -drive if=pflash,file=%s,format=raw,copy-on-read=on", image_path); FlashConfig explicit_config = expand_config_defaults(config); explicit_config.qtest = qtest; diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter-redirector.c index 829db8c..4269b2c 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -95,8 +95,8 @@ static void test_redirector_tx(void) qts = qtest_initf( "-netdev socket,id=qtest-bn0,fd=%d " "-device %s,netdev=qtest-bn0,id=qtest-e0 " - "-chardev socket,id=redirector0,path=%s,server,nowait " - "-chardev socket,id=redirector1,path=%s,server,nowait " + "-chardev socket,id=redirector0,path=%s,server=on,wait=off " + "-chardev socket,id=redirector1,path=%s,server=on,wait=off " "-chardev socket,id=redirector2,path=%s " "-object filter-redirector,id=qtest-f0,netdev=qtest-bn0," "queue=tx,outdev=redirector0 " @@ -165,8 +165,8 @@ static void test_redirector_rx(void) qts = qtest_initf( "-netdev socket,id=qtest-bn0,fd=%d " "-device %s,netdev=qtest-bn0,id=qtest-e0 " - "-chardev socket,id=redirector0,path=%s,server,nowait " - "-chardev socket,id=redirector1,path=%s,server,nowait " + "-chardev socket,id=redirector0,path=%s,server=on,wait=off " + "-chardev socket,id=redirector1,path=%s,server=on,wait=off " "-chardev socket,id=redirector2,path=%s " "-object filter-redirector,id=qtest-f0,netdev=qtest-bn0," "queue=rx,indev=redirector0 " diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 3df5322..1a5f531 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -537,7 +537,7 @@ static void test_server_create_chr(TestServer *server, const gchar *opt) static void test_server_listen(TestServer *server) { - test_server_create_chr(server, ",server,nowait"); + test_server_create_chr(server, ",server=on,wait=off"); } static void test_server_free(TestServer *server) @@ -846,7 +846,7 @@ static void *vhost_user_test_setup_reconnect(GString *cmd_line, void *arg) g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - s->vu_ops->append_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server=on"); g_test_queue_destroy(vhost_user_test_cleanup, s); @@ -883,7 +883,7 @@ static void *vhost_user_test_setup_connect_fail(GString *cmd_line, void *arg) g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - s->vu_ops->append_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server=on"); g_test_queue_destroy(vhost_user_test_cleanup, s); @@ -898,7 +898,7 @@ static void *vhost_user_test_setup_flags_mismatch(GString *cmd_line, void *arg) g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - s->vu_ops->append_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server=on"); g_test_queue_destroy(vhost_user_test_cleanup, s); diff --git a/tests/test-char.c b/tests/test-char.c index 9196e56..953e0d1 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -413,7 +413,7 @@ static void char_websock_test(void) CharBackend client_be; Chardev *chr_client; Chardev *chr = qemu_chr_new("server", - "websocket:127.0.0.1:0,server,nowait", NULL); + "websocket:127.0.0.1:0,server=on,wait=off", NULL); const char handshake[] = "GET / HTTP/1.1\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" @@ -696,7 +696,7 @@ char_socket_addr_to_opt_str(SocketAddress *addr, bool fd_pass, fd = ioc->fd; ioc->fd = -1; optstr = g_strdup_printf("socket,id=cdev0,fd=%d%s", - fd, is_listen ? ",server,nowait" : ""); + fd, is_listen ? ",server=on,wait=off" : ""); object_unref(OBJECT(ioc)); return optstr; } else { @@ -706,13 +706,13 @@ char_socket_addr_to_opt_str(SocketAddress *addr, bool fd_pass, addr->u.inet.host, addr->u.inet.port, reconnect ? reconnect : "", - is_listen ? ",server,nowait" : ""); + is_listen ? ",server=on,wait=off" : ""); case SOCKET_ADDRESS_TYPE_UNIX: return g_strdup_printf("socket,id=cdev0,path=%s%s%s", addr->u.q_unix.path, reconnect ? reconnect : "", - is_listen ? ",server,nowait" : ""); + is_listen ? ",server=on,wait=off" : ""); default: g_assert_not_reached(); -- cgit v1.1 From 32c02fdda49b8ace1517f1b95bfc215e0b92a154 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 9 Nov 2020 04:46:30 -0500 Subject: qemu-option: restrict qemu_opts_set to merge-lists QemuOpts qemu_opts_set is used to create default network backends and to parse sugar options -kernel, -initrd, -append, -bios and -dtb. These are very different uses: I would *expect* a function named qemu_opts_set to set an option in a merge-lists QemuOptsList, such as -kernel, and possibly to set an option in a non-merge-lists QemuOptsList with non-NULL id, similar to -set. However, it wouldn't *work* to use qemu_opts_set for the latter because qemu_opts_set uses fail_if_exists==1. So, for non-merge-lists QemuOptsList and non-NULL id, the semantics of qemu_opts_set (fail if the (QemuOptsList, id) pair already exists) are debatable. On the other hand, I would not expect qemu_opts_set to create a non-merge-lists QemuOpts with a single option; which it does, though. For this case of non-merge-lists QemuOptsList and NULL id, qemu_opts_set hardly adds value over qemu_opts_parse. It does skip some parsing and unescaping, but that's not needed when creating default network backends. So qemu_opts_set has warty behavior for non-merge-lists QemuOptsList if id is non-NULL, and it's mostly pointless if id is NULL. My solution to keeping the API as simple as possible is to limit qemu_opts_set to merge-lists QemuOptsList. For them, it's useful (we don't want comma-unescaping for -kernel) *and* has sane semantics. Network backend creation is switched to qemu_opts_parse. qemu_opts_set is now only used on merge-lists QemuOptsList... except in the testcase, which is changed to use a merge-list QemuOptsList. With this change we can also remove the id parameter. With the parameter always NULL, we know that qemu_opts_create cannot fail and can pass &error_abort to it. Signed-off-by: Paolo Bonzini --- tests/test-qemu-opts.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 297ffe7..2aab831 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -84,11 +84,25 @@ static QemuOptsList opts_list_03 = { }, }; +static QemuOptsList opts_list_04 = { + .name = "opts_list_04", + .head = QTAILQ_HEAD_INITIALIZER(opts_list_04.head), + .merge_lists = true, + .desc = { + { + .name = "str3", + .type = QEMU_OPT_STRING, + }, + { /* end of list */ } + }, +}; + static void register_opts(void) { qemu_add_opts(&opts_list_01); qemu_add_opts(&opts_list_02); qemu_add_opts(&opts_list_03); + qemu_add_opts(&opts_list_04); } static void test_find_unknown_opts(void) @@ -402,17 +416,17 @@ static void test_qemu_opts_set(void) QemuOpts *opts; const char *opt; - list = qemu_find_opts("opts_list_01"); + list = qemu_find_opts("opts_list_04"); g_assert(list != NULL); g_assert(QTAILQ_EMPTY(&list->head)); - g_assert_cmpstr(list->name, ==, "opts_list_01"); + g_assert_cmpstr(list->name, ==, "opts_list_04"); /* should not find anything at this point */ opts = qemu_opts_find(list, NULL); g_assert(opts == NULL); /* implicitly create opts and set str3 value */ - qemu_opts_set(list, NULL, "str3", "value", &error_abort); + qemu_opts_set(list, "str3", "value", &error_abort); g_assert(!QTAILQ_EMPTY(&list->head)); /* get the just created opts */ -- cgit v1.1 From 2c65db5e58d2c74921077f6c064ba4c91ebde16a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 28 Oct 2020 07:36:57 -0400 Subject: vl: extract softmmu/datadir.c Reviewed-by: Igor Mammedov Signed-off-by: Paolo Bonzini --- tests/qtest/fuzz/fuzz.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index 7be7226..238866a 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -15,6 +15,7 @@ #include +#include "qemu/datadir.h" #include "sysemu/qtest.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h" -- cgit v1.1