Merge tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu into staging
trivial patches for 2023-10-12
# -----BEGIN PGP SIGNATURE-----
#
# iQFDBAABCAAtFiEEe3O61ovnosKJMUsicBtPaxppPlkFAmUnFa8PHG1qdEB0bHMu
# bXNrLnJ1AAoJEHAbT2saaT5ZBv8H/0MtWL6FqTzvz5yLn2WSbj2ng1RG1Deh36Sy
# 1PCpFKy85ZSBKLOzgvbpn4VfpEdsvD/+sX4C4CVde+vR3oCjdUM14hnzEWX86gFl
# O8Ct8++MLPqnwgu6Rg6Z+Ie2yBtsQ5VABH/1q36T7+XHHh19bgEw6tW34/f2Ncxw
# 8UQO2lm9tAMAOEfXoutoj8K8ch3FvbsEic9L0ORc7ntWc7NIauc3zizogtPHAzR8
# elB3BiLn4sMHLBj+IunndOiLadUAVOKTJ5PKi4b8iRa6aE8E6bjtLxdiPr4XEx/g
# 7rSGvNM+Lm7mEgJSyyik+u0MshKjfRi+SrbvId9FIqACG1GCKeI=
# =rFns
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 11 Oct 2023 17:37:51 EDT
# gpg: using RSA key 7B73BAD68BE7A2C289314B22701B4F6B1A693E59
# gpg: issuer "mjt@tls.msk.ru"
# gpg: Good signature from "Michael Tokarev <mjt@tls.msk.ru>" [full]
# gpg: aka "Michael Tokarev <mjt@corpit.ru>" [full]
# gpg: aka "Michael Tokarev <mjt@debian.org>" [full]
# Primary key fingerprint: 6EE1 95D1 886E 8FFB 810D 4324 457C E0A0 8044 65C5
# Subkey fingerprint: 7B73 BAD6 8BE7 A2C2 8931 4B22 701B 4F6B 1A69 3E59
* tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu:
cpus: Remove unused smp_cores/smp_threads declarations
scripts/xml-preprocess: Make sure this script is invoked via the right Python
roms: use PYTHON to invoke python
MAINTAINERS: Add some unowned files to the SBSA-REF section
MAINTAINERS: Add section for overall sensors
MAINTAINERS: add standard-headers to Hosts/LINUX
MAINTAINERS: Add the CI-related doc files to the CI section
MAINTAINERS: Add include folder to the hw/char/ section
MAINTAINERS: Add unowned RISC-V related files to the right sections
MAINTAINERS: Add g364fb and ds1225y to the Jazz section
Fix compilation when UFFDIO_REGISTER is not set.
Update AMD memory encryption document links.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml
index aee9101..25af1bc 100644
--- a/.gitlab-ci.d/buildtest.yml
+++ b/.gitlab-ci.d/buildtest.yml
@@ -30,6 +30,7 @@
variables:
IMAGE: alpine
MAKE_CHECK_ARGS: check-avocado
+ AVOCADO_TAGS: arch:avr arch:loongarch64 arch:mips64 arch:mipsel
build-system-ubuntu:
extends:
@@ -40,8 +41,7 @@
variables:
IMAGE: ubuntu2204
CONFIGURE_ARGS: --enable-docs
- TARGETS: alpha-softmmu cris-softmmu hppa-softmmu
- microblazeel-softmmu mips64el-softmmu
+ TARGETS: alpha-softmmu microblazeel-softmmu mips64el-softmmu
MAKE_CHECK_ARGS: check-build
check-system-ubuntu:
@@ -61,6 +61,7 @@
variables:
IMAGE: ubuntu2204
MAKE_CHECK_ARGS: check-avocado
+ AVOCADO_TAGS: arch:alpha arch:microblaze arch:mips64el
build-system-debian:
extends:
@@ -72,7 +73,7 @@
IMAGE: debian-amd64
CONFIGURE_ARGS: --with-coroutine=sigaltstack
TARGETS: arm-softmmu i386-softmmu riscv64-softmmu sh4eb-softmmu
- sparc-softmmu xtensaeb-softmmu
+ sparc-softmmu xtensa-softmmu
MAKE_CHECK_ARGS: check-build
check-system-debian:
@@ -92,6 +93,7 @@
variables:
IMAGE: debian-amd64
MAKE_CHECK_ARGS: check-avocado
+ AVOCADO_TAGS: arch:arm arch:i386 arch:riscv64 arch:sh4 arch:sparc arch:xtensa
crash-test-debian:
extends: .native_test_job_template
@@ -114,7 +116,7 @@
variables:
IMAGE: fedora
CONFIGURE_ARGS: --disable-gcrypt --enable-nettle --enable-docs
- TARGETS: tricore-softmmu microblaze-softmmu mips-softmmu
+ TARGETS: microblaze-softmmu mips-softmmu
xtensa-softmmu m68k-softmmu riscv32-softmmu ppc-softmmu sparc64-softmmu
MAKE_CHECK_ARGS: check-build
@@ -135,6 +137,8 @@
variables:
IMAGE: fedora
MAKE_CHECK_ARGS: check-avocado
+ AVOCADO_TAGS: arch:microblaze arch:mips arch:xtensa arch:m68k
+ arch:riscv32 arch:ppc arch:sparc64
crash-test-fedora:
extends: .native_test_job_template
@@ -180,6 +184,8 @@
variables:
IMAGE: centos8
MAKE_CHECK_ARGS: check-avocado
+ AVOCADO_TAGS: arch:ppc64 arch:or1k arch:390x arch:x86_64 arch:rx
+ arch:sh4 arch:nios2
build-system-opensuse:
extends:
@@ -209,6 +215,7 @@
variables:
IMAGE: opensuse-leap
MAKE_CHECK_ARGS: check-avocado
+ AVOCADO_TAGS: arch:s390x arch:x86_64 arch:aarch64
# This jobs explicitly disable TCG (--disable-tcg), KVM is detected by
diff --git a/.gitlab-ci.d/cirrus/macos-12.vars b/.gitlab-ci.d/cirrus/macos-12.vars
index 80eadaa..5f3fb34 100644
--- a/.gitlab-ci.d/cirrus/macos-12.vars
+++ b/.gitlab-ci.d/cirrus/macos-12.vars
@@ -11,6 +11,6 @@
NINJA='/opt/homebrew/bin/ninja'
PACKAGING_COMMAND='brew'
PIP3='/opt/homebrew/bin/pip3'
-PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 jemalloc jpeg-turbo json-c libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol tesseract usbredir vde vte3 xorriso zlib zstd'
+PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 jemalloc jpeg-turbo json-c libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol swtpm tesseract usbredir vde vte3 xorriso zlib zstd'
PYPI_PKGS='PyYAML numpy pillow sphinx sphinx-rtd-theme tomli'
PYTHON='/opt/homebrew/bin/python3'
diff --git a/MAINTAINERS b/MAINTAINERS
index 0bab360..ceea4c2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2857,7 +2857,7 @@
F: include/gdbstub/*
F: gdb-xml/
F: tests/tcg/multiarch/gdbstub/
-F: scripts/feature_to_c.sh
+F: scripts/feature_to_c.py
F: scripts/probe-gdb-support.py
Memory API
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index d31c999..39b3c93 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -866,10 +866,14 @@
* do any clean-up here and make sure things are reset in
* plugin_gen_tb_start.
*/
-void plugin_gen_tb_end(CPUState *cpu)
+void plugin_gen_tb_end(CPUState *cpu, size_t num_insns)
{
struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb;
+ /* translator may have removed instructions, update final count */
+ g_assert(num_insns <= ptb->n);
+ ptb->n = num_insns;
+
/* collect instrumentation requests */
qemu_plugin_tb_trans_cb(cpu, ptb);
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index e7abcd8..575b981 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -158,6 +158,7 @@
} else {
plugin_enabled = plugin_gen_tb_start(cpu, db, false);
}
+ db->plugin_enabled = plugin_enabled;
while (true) {
*max_insns = ++db->num_insns;
@@ -209,7 +210,7 @@
gen_tb_end(tb, cflags, icount_start_insn, db->num_insns);
if (plugin_enabled) {
- plugin_gen_tb_end(cpu);
+ plugin_gen_tb_end(cpu, db->num_insns);
}
/* The disas_log hook may use these values rather than recompute. */
diff --git a/configure b/configure
index 97a5e8d..8fada85 100755
--- a/configure
+++ b/configure
@@ -180,6 +180,7 @@
# some defaults, based on the host environment
# default parameters
+container_engine="auto"
cpu=""
cross_compile="no"
cross_prefix=""
@@ -787,6 +788,8 @@
;;
--disable-containers) use_containers="no"
;;
+ --container-engine=*) container_engine="$optarg"
+ ;;
--gdb=*) gdb_bin="$optarg"
;;
# everything else has the same name in configure and meson
@@ -921,6 +924,7 @@
--enable-plugins
enable plugins via shared library loading
--disable-containers don't use containers for cross-building
+ --container-engine=TYPE which container engine to use [$container_engine]
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
EOF
meson_options_help
@@ -1195,14 +1199,14 @@
container="no"
runc=""
if test $use_containers = "yes" && (has "docker" || has "podman"); then
- case $($python "$source_path"/tests/docker/docker.py probe) in
+ case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in
*docker) container=docker ;;
podman) container=podman ;;
no) container=no ;;
esac
if test "$container" != "no"; then
docker_py="$python $source_path/tests/docker/docker.py --engine $container"
- runc=$($python "$source_path"/tests/docker/docker.py probe)
+ runc=$container
fi
fi
@@ -1330,7 +1334,7 @@
# We don't have any bigendian build tools so we only use this for AArch64
container_image=debian-arm64-cross
container_cross_prefix=aarch64-linux-gnu-
- container_cross_cc=${container_cross_prefix}gcc-10
+ container_cross_cc=${container_cross_prefix}gcc
;;
alpha)
container_image=debian-alpha-cross
@@ -1393,7 +1397,7 @@
ppc)
container_image=debian-powerpc-test-cross
container_cross_prefix=powerpc-linux-gnu-
- container_cross_cc=${container_cross_prefix}gcc-10
+ container_cross_cc=${container_cross_prefix}gcc
;;
ppc64|ppc64le)
container_image=debian-powerpc-test-cross
@@ -1694,7 +1698,6 @@
fi
if test "$container" != no; then
- echo "ENGINE=$container" >> $config_host_mak
echo "RUNC=$runc" >> $config_host_mak
fi
echo "SUBDIRS=$subdirs" >> $config_host_mak
diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c
index 4fca3ed..9e7ade3 100644
--- a/contrib/plugins/cache.c
+++ b/contrib/plugins/cache.c
@@ -535,15 +535,13 @@
}
}
-static void append_stats_line(GString *line, uint64_t l1_daccess,
- uint64_t l1_dmisses, uint64_t l1_iaccess,
- uint64_t l1_imisses, uint64_t l2_access,
- uint64_t l2_misses)
+static void append_stats_line(GString *line,
+ uint64_t l1_daccess, uint64_t l1_dmisses,
+ uint64_t l1_iaccess, uint64_t l1_imisses,
+ uint64_t l2_access, uint64_t l2_misses)
{
- double l1_dmiss_rate, l1_imiss_rate, l2_miss_rate;
-
- l1_dmiss_rate = ((double) l1_dmisses) / (l1_daccess) * 100.0;
- l1_imiss_rate = ((double) l1_imisses) / (l1_iaccess) * 100.0;
+ double l1_dmiss_rate = ((double) l1_dmisses) / (l1_daccess) * 100.0;
+ double l1_imiss_rate = ((double) l1_imisses) / (l1_iaccess) * 100.0;
g_string_append_printf(line, "%-14" PRIu64 " %-12" PRIu64 " %9.4lf%%"
" %-14" PRIu64 " %-12" PRIu64 " %9.4lf%%",
@@ -554,8 +552,8 @@
l1_imisses,
l1_iaccess ? l1_imiss_rate : 0.0);
- if (use_l2) {
- l2_miss_rate = ((double) l2_misses) / (l2_access) * 100.0;
+ if (l2_access && l2_misses) {
+ double l2_miss_rate = ((double) l2_misses) / (l2_access) * 100.0;
g_string_append_printf(line,
" %-12" PRIu64 " %-11" PRIu64 " %10.4lf%%",
l2_access,
diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
index 7129d52..82dc2f5 100644
--- a/contrib/plugins/execlog.c
+++ b/contrib/plugins/execlog.c
@@ -19,7 +19,7 @@
/* Store last executed instruction on each vCPU as a GString */
static GPtrArray *last_exec;
-static GMutex expand_array_lock;
+static GRWLock expand_array_lock;
static GPtrArray *imatches;
static GArray *amatches;
@@ -28,18 +28,16 @@
* Expand last_exec array.
*
* As we could have multiple threads trying to do this we need to
- * serialise the expansion under a lock. Threads accessing already
- * created entries can continue without issue even if the ptr array
- * gets reallocated during resize.
+ * serialise the expansion under a lock.
*/
static void expand_last_exec(int cpu_index)
{
- g_mutex_lock(&expand_array_lock);
+ g_rw_lock_writer_lock(&expand_array_lock);
while (cpu_index >= last_exec->len) {
GString *s = g_string_new(NULL);
g_ptr_array_add(last_exec, s);
}
- g_mutex_unlock(&expand_array_lock);
+ g_rw_lock_writer_unlock(&expand_array_lock);
}
/**
@@ -51,8 +49,10 @@
GString *s;
/* Find vCPU in array */
+ g_rw_lock_reader_lock(&expand_array_lock);
g_assert(cpu_index < last_exec->len);
s = g_ptr_array_index(last_exec, cpu_index);
+ g_rw_lock_reader_unlock(&expand_array_lock);
/* Indicate type of memory access */
if (qemu_plugin_mem_is_store(info)) {
@@ -80,10 +80,14 @@
GString *s;
/* Find or create vCPU in array */
+ g_rw_lock_reader_lock(&expand_array_lock);
if (cpu_index >= last_exec->len) {
+ g_rw_lock_reader_unlock(&expand_array_lock);
expand_last_exec(cpu_index);
+ g_rw_lock_reader_lock(&expand_array_lock);
}
s = g_ptr_array_index(last_exec, cpu_index);
+ g_rw_lock_reader_unlock(&expand_array_lock);
/* Print previous instruction in cache */
if (s->len) {
diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index 6b74d25..4de1b13 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -69,8 +69,8 @@
}
g_list_free(it);
- g_mutex_unlock(&lock);
}
+ g_mutex_unlock(&lock);
qemu_plugin_outs(report->str);
}
diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c
index 682b11f..f0cb879 100644
--- a/contrib/plugins/lockstep.c
+++ b/contrib/plugins/lockstep.c
@@ -245,6 +245,7 @@
static bool setup_socket(const char *path)
{
struct sockaddr_un sockaddr;
+ const gsize pathlen = sizeof(sockaddr.sun_path) - 1;
int fd;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -254,7 +255,11 @@
}
sockaddr.sun_family = AF_UNIX;
- g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1);
+ if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) {
+ perror("bad path");
+ return false;
+ }
+
if (bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
perror("bind socket");
close(fd);
@@ -287,6 +292,7 @@
{
int fd;
struct sockaddr_un sockaddr;
+ const gsize pathlen = sizeof(sockaddr.sun_path) - 1;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
@@ -295,7 +301,10 @@
}
sockaddr.sun_family = AF_UNIX;
- g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1);
+ if (g_strlcpy(sockaddr.sun_path, path, pathlen) >= pathlen) {
+ perror("bad path");
+ return false;
+ }
if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
perror("failed to connect");
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 8eea214..b153211 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -51,7 +51,6 @@
gdb_get_reg_cb get_reg;
gdb_set_reg_cb set_reg;
const char *xml;
- struct GDBRegisterState *next;
} GDBRegisterState;
GDBState gdbserver_state;
@@ -349,11 +348,6 @@
}
}
-bool gdb_has_xml(void)
-{
- return !!gdb_get_cpu_process(gdbserver_state.g_cpu)->target_xml;
-}
-
static const char *get_feature_xml(const char *p, const char **newp,
GDBProcess *process)
{
@@ -373,31 +367,37 @@
if (strncmp(p, "target.xml", len) == 0) {
if (!process->target_xml) {
GDBRegisterState *r;
- GString *xml = g_string_new("<?xml version=\"1.0\"?>");
+ g_autoptr(GPtrArray) xml = g_ptr_array_new_with_free_func(g_free);
- g_string_append(xml,
- "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">"
- "<target>");
+ g_ptr_array_add(
+ xml,
+ g_strdup("<?xml version=\"1.0\"?>"
+ "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">"
+ "<target>"));
if (cc->gdb_arch_name) {
- g_autofree gchar *arch = cc->gdb_arch_name(cpu);
- g_string_append_printf(xml,
- "<architecture>%s</architecture>",
- arch);
+ g_ptr_array_add(
+ xml,
+ g_markup_printf_escaped("<architecture>%s</architecture>",
+ cc->gdb_arch_name(cpu)));
}
- g_string_append(xml, "<xi:include href=\"");
- g_string_append(xml, cc->gdb_core_xml_file);
- g_string_append(xml, "\"/>");
- for (r = cpu->gdb_regs; r; r = r->next) {
- g_string_append(xml, "<xi:include href=\"");
- g_string_append(xml, r->xml);
- g_string_append(xml, "\"/>");
+ g_ptr_array_add(
+ xml,
+ g_markup_printf_escaped("<xi:include href=\"%s\"/>",
+ cc->gdb_core_xml_file));
+ for (guint i = 0; i < cpu->gdb_regs->len; i++) {
+ r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i);
+ g_ptr_array_add(
+ xml,
+ g_markup_printf_escaped("<xi:include href=\"%s\"/>",
+ r->xml));
}
- g_string_append(xml, "</target>");
+ g_ptr_array_add(xml, g_strdup("</target>"));
+ g_ptr_array_add(xml, NULL);
- process->target_xml = g_string_free(xml, false);
- return process->target_xml;
+ process->target_xml = g_strjoinv(NULL, (void *)xml->pdata);
}
+ return process->target_xml;
}
/* Is it dynamically generated by the target? */
if (cc->gdb_get_dynamic_xml) {
@@ -408,11 +408,11 @@
}
}
/* Is it one of the encoded gdb-xml/ files? */
- for (int i = 0; xml_builtin[i][0]; i++) {
- const char *name = xml_builtin[i][0];
+ for (int i = 0; gdb_static_features[i].xmlname; i++) {
+ const char *name = gdb_static_features[i].xmlname;
if ((strncmp(name, p, len) == 0) &&
strlen(name) == len) {
- return xml_builtin[i][1];
+ return gdb_static_features[i].xml;
}
}
@@ -430,7 +430,8 @@
return cc->gdb_read_register(cpu, buf, reg);
}
- for (r = cpu->gdb_regs; r; r = r->next) {
+ for (guint i = 0; i < cpu->gdb_regs->len; i++) {
+ r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i);
if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
return r->get_reg(env, buf, reg - r->base_reg);
}
@@ -448,7 +449,8 @@
return cc->gdb_write_register(cpu, mem_buf, reg);
}
- for (r = cpu->gdb_regs; r; r = r->next) {
+ for (guint i = 0; i < cpu->gdb_regs->len; i++) {
+ r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i);
if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
return r->set_reg(env, mem_buf, reg - r->base_reg);
}
@@ -461,17 +463,23 @@
int num_regs, const char *xml, int g_pos)
{
GDBRegisterState *s;
- GDBRegisterState **p;
+ guint i;
- p = &cpu->gdb_regs;
- while (*p) {
- /* Check for duplicates. */
- if (strcmp((*p)->xml, xml) == 0)
- return;
- p = &(*p)->next;
+ if (cpu->gdb_regs) {
+ for (i = 0; i < cpu->gdb_regs->len; i++) {
+ /* Check for duplicates. */
+ s = &g_array_index(cpu->gdb_regs, GDBRegisterState, i);
+ if (strcmp(s->xml, xml) == 0) {
+ return;
+ }
+ }
+ } else {
+ cpu->gdb_regs = g_array_new(false, false, sizeof(GDBRegisterState));
+ i = 0;
}
- s = g_new0(GDBRegisterState, 1);
+ g_array_set_size(cpu->gdb_regs, i + 1);
+ s = &g_array_index(cpu->gdb_regs, GDBRegisterState, i);
s->base_reg = cpu->gdb_num_regs;
s->num_regs = num_regs;
s->get_reg = get_reg;
@@ -480,7 +488,6 @@
/* Add to end of list. */
cpu->gdb_num_regs += num_regs;
- *p = s;
if (g_pos) {
if (g_pos != s->base_reg) {
error_report("Error: Bad gdb register numbering for '%s', "
@@ -1081,11 +1088,6 @@
{
int reg_size;
- if (!gdb_get_cpu_process(gdbserver_state.g_cpu)->target_xml) {
- gdb_put_packet("");
- return;
- }
-
if (params->len != 2) {
gdb_put_packet("E22");
return;
@@ -1102,11 +1104,6 @@
{
int reg_size;
- if (!gdb_get_cpu_process(gdbserver_state.g_cpu)->target_xml) {
- gdb_put_packet("");
- return;
- }
-
if (!params->len) {
gdb_put_packet("E14");
return;
diff --git a/gdbstub/internals.h b/gdbstub/internals.h
index f7fd1be..465c24b 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -32,8 +32,6 @@
typedef struct GDBProcess {
uint32_t pid;
bool attached;
-
- /* If gdb sends qXfer:features:read:target.xml this will be populated */
char *target_xml;
} GDBProcess;
diff --git a/gdbstub/system.c b/gdbstub/system.c
index 189975b..4897687 100644
--- a/gdbstub/system.c
+++ b/gdbstub/system.c
@@ -292,7 +292,7 @@
assert(cluster->cluster_id != UINT32_MAX);
process->pid = cluster->cluster_id + 1;
process->attached = false;
- process->target_xml[0] = '\0';
+ process->target_xml = NULL;
return 0;
}
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 90f73d4..91c4733 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -22,18 +22,19 @@
* THE SOFTWARE.
*/
-/* #define DEBUG_ES1370 */
-/* #define VERBOSE_ES1370 */
-#define SILENT_ES1370
+#define DEBUG_ES1370 0
+#define VERBOSE_ES1370 0
#include "qemu/osdep.h"
#include "hw/audio/soundhw.h"
#include "audio/audio.h"
#include "hw/pci/pci_device.h"
#include "migration/vmstate.h"
+#include "qemu/cutils.h"
#include "qemu/module.h"
#include "sysemu/dma.h"
#include "qom/object.h"
+#include "trace.h"
/* Missing stuff:
SCTRL_P[12](END|ST)INC
@@ -164,97 +165,85 @@
static void es1370_dac2_callback (void *opaque, int free);
static void es1370_adc_callback (void *opaque, int avail);
-#ifdef DEBUG_ES1370
-
-#define ldebug(...) AUD_log ("es1370", __VA_ARGS__)
-
-static void print_ctl (uint32_t val)
+static void print_ctl(uint32_t val)
{
- char buf[1024];
+ if (DEBUG_ES1370) {
+ char buf[1024];
- buf[0] = '\0';
-#define a(n) if (val & CTRL_##n) strcat (buf, " "#n)
- a (ADC_STOP);
- a (XCTL1);
- a (OPEN);
- a (MSFMTSEL);
- a (M_SBB);
- a (DAC_SYNC);
- a (CCB_INTRM);
- a (M_CB);
- a (XCTL0);
- a (BREQ);
- a (DAC1_EN);
- a (DAC2_EN);
- a (ADC_EN);
- a (UART_EN);
- a (JYSTK_EN);
- a (CDC_EN);
- a (SERR_DIS);
+ buf[0] = '\0';
+#define a(n) if (val & CTRL_##n) pstrcat(buf, sizeof(buf), " "#n)
+ a(ADC_STOP);
+ a(XCTL1);
+ a(OPEN);
+ a(MSFMTSEL);
+ a(M_SBB);
+ a(DAC_SYNC);
+ a(CCB_INTRM);
+ a(M_CB);
+ a(XCTL0);
+ a(BREQ);
+ a(DAC1_EN);
+ a(DAC2_EN);
+ a(ADC_EN);
+ a(UART_EN);
+ a(JYSTK_EN);
+ a(CDC_EN);
+ a(SERR_DIS);
#undef a
- AUD_log ("es1370", "ctl - PCLKDIV %d(DAC2 freq %d), freq %d,%s\n",
- (val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV,
- DAC2_DIVTOSR ((val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
- dac1_samplerate[(val & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL],
- buf);
+ AUD_log("es1370", "ctl - PCLKDIV %d(DAC2 freq %d), freq %d,%s\n",
+ (val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV,
+ DAC2_DIVTOSR((val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
+ dac1_samplerate[(val & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL],
+ buf);
+ }
}
-static void print_sctl (uint32_t val)
+static void print_sctl(uint32_t val)
{
- static const char *fmt_names[] = {"8M", "8S", "16M", "16S"};
- char buf[1024];
+ if (DEBUG_ES1370) {
+ static const char *fmt_names[] = {"8M", "8S", "16M", "16S"};
+ char buf[1024];
- buf[0] = '\0';
+ buf[0] = '\0';
-#define a(n) if (val & SCTRL_##n) strcat (buf, " "#n)
-#define b(n) if (!(val & SCTRL_##n)) strcat (buf, " "#n)
- b (R1LOOPSEL);
- b (P2LOOPSEL);
- b (P1LOOPSEL);
- a (P2PAUSE);
- a (P1PAUSE);
- a (R1INTEN);
- a (P2INTEN);
- a (P1INTEN);
- a (P1SCTRLD);
- a (P2DACSEN);
- if (buf[0]) {
- strcat (buf, "\n ");
- }
- else {
- buf[0] = ' ';
- buf[1] = '\0';
- }
+#define a(n) if (val & SCTRL_##n) pstrcat(buf, sizeof(buf), " "#n)
+#define b(n) if (!(val & SCTRL_##n)) pstrcat(buf, sizeof(buf), " "#n)
+ b(R1LOOPSEL);
+ b(P2LOOPSEL);
+ b(P1LOOPSEL);
+ a(P2PAUSE);
+ a(P1PAUSE);
+ a(R1INTEN);
+ a(P2INTEN);
+ a(P1INTEN);
+ a(P1SCTRLD);
+ a(P2DACSEN);
+ if (buf[0]) {
+ pstrcat(buf, sizeof(buf), "\n ");
+ } else {
+ buf[0] = ' ';
+ buf[1] = '\0';
+ }
#undef b
#undef a
- AUD_log ("es1370",
- "%s"
- "p2_end_inc %d, p2_st_inc %d, r1_fmt %s, p2_fmt %s, p1_fmt %s\n",
- buf,
- (val & SCTRL_P2ENDINC) >> SCTRL_SH_P2ENDINC,
- (val & SCTRL_P2STINC) >> SCTRL_SH_P2STINC,
- fmt_names [(val >> SCTRL_SH_R1FMT) & 3],
- fmt_names [(val >> SCTRL_SH_P2FMT) & 3],
- fmt_names [(val >> SCTRL_SH_P1FMT) & 3]
- );
+ AUD_log("es1370",
+ "%s p2_end_inc %d, p2_st_inc %d,"
+ " r1_fmt %s, p2_fmt %s, p1_fmt %s\n",
+ buf,
+ (val & SCTRL_P2ENDINC) >> SCTRL_SH_P2ENDINC,
+ (val & SCTRL_P2STINC) >> SCTRL_SH_P2STINC,
+ fmt_names[(val >> SCTRL_SH_R1FMT) & 3],
+ fmt_names[(val >> SCTRL_SH_P2FMT) & 3],
+ fmt_names[(val >> SCTRL_SH_P1FMT) & 3]);
+ }
}
-#else
-#define ldebug(...)
-#define print_ctl(...)
-#define print_sctl(...)
-#endif
-#ifdef VERBOSE_ES1370
-#define dolog(...) AUD_log ("es1370", __VA_ARGS__)
-#else
-#define dolog(...)
-#endif
-
-#ifndef SILENT_ES1370
-#define lwarn(...) AUD_log ("es1370: warning", __VA_ARGS__)
-#else
-#define lwarn(...)
-#endif
+#define lwarn(...) \
+do { \
+ if (VERBOSE_ES1370) { \
+ AUD_log("es1370: warning", __VA_ARGS__); \
+ } \
+} while (0)
#define TYPE_ES1370 "ES1370"
OBJECT_DECLARE_SIMPLE_TYPE(ES1370State, ES1370)
@@ -320,8 +309,7 @@
if (level) {
s->status = new_status | STAT_INTR;
- }
- else {
+ } else {
s->status = new_status & ~STAT_INTR;
}
pci_set_irq(&s->dev, !!level);
@@ -344,8 +332,7 @@
if (i == ADC_CHANNEL) {
AUD_close_in (&s->card, s->adc_voice);
s->adc_voice = NULL;
- }
- else {
+ } else {
AUD_close_out (&s->card, s->dac_voice[i]);
s->dac_voice[i] = NULL;
}
@@ -411,12 +398,9 @@
if ((old_fmt != new_fmt) || (old_freq != new_freq)) {
d->shift = (new_fmt & 1) + (new_fmt >> 1);
- ldebug ("channel %zu, freq = %d, nchannels %d, fmt %d, shift %d\n",
- i,
- new_freq,
- 1 << (new_fmt & 1),
- (new_fmt & 2) ? AUDIO_FORMAT_S16 : AUDIO_FORMAT_U8,
- d->shift);
+ trace_es1370_stream_format(i, new_freq,
+ new_fmt & 2 ? "s16" : "u8", new_fmt & 1 ? "stereo" : "mono",
+ d->shift);
if (new_freq) {
struct audsettings as;
@@ -435,8 +419,7 @@
es1370_adc_callback,
&as
);
- }
- else {
+ } else {
s->dac_voice[i] =
AUD_open_out (
&s->card,
@@ -456,8 +439,7 @@
if (i == ADC_CHANNEL) {
AUD_set_active_in (s->adc_voice, on);
- }
- else {
+ } else {
AUD_set_active_out (s->dac_voice[i], on);
}
}
@@ -470,8 +452,9 @@
static inline uint32_t es1370_fixup (ES1370State *s, uint32_t addr)
{
addr &= 0xff;
- if (addr >= 0x30 && addr <= 0x3f)
+ if (addr >= 0x30 && addr <= 0x3f) {
addr |= s->mempage << 8;
+ }
return addr;
}
@@ -502,9 +485,9 @@
case ES1370_REG_DAC2_SCOUNT:
case ES1370_REG_ADC_SCOUNT:
d += (addr - ES1370_REG_DAC1_SCOUNT) >> 2;
- d->scount = (val & 0xffff) | (d->scount & ~0xffff);
- ldebug ("chan %td CURR_SAMP_CT %d, SAMP_CT %d\n",
- d - &s->chan[0], val >> 16, (val & 0xffff));
+ d->scount = (val & 0xffff) << 16 | (val & 0xffff);
+ trace_es1370_sample_count_wr(d - &s->chan[0],
+ d->scount >> 16, d->scount & 0xffff);
break;
case ES1370_REG_ADC_FRAMEADR:
@@ -515,14 +498,14 @@
d += (addr - ES1370_REG_DAC1_FRAMEADR) >> 3;
frameadr:
d->frame_addr = val;
- ldebug ("chan %td frame address %#x\n", d - &s->chan[0], val);
+ trace_es1370_frame_address_wr(d - &s->chan[0], d->frame_addr);
break;
case ES1370_REG_PHANTOM_FRAMECNT:
- lwarn ("writing to phantom frame count %#x\n", val);
+ lwarn("writing to phantom frame count 0x%" PRIx64 "\n", val);
break;
case ES1370_REG_PHANTOM_FRAMEADR:
- lwarn ("writing to phantom frame address %#x\n", val);
+ lwarn("writing to phantom frame address 0x%" PRIx64 "\n", val);
break;
case ES1370_REG_ADC_FRAMECNT:
@@ -534,12 +517,12 @@
framecnt:
d->frame_cnt = val;
d->leftover = 0;
- ldebug ("chan %td frame count %d, buffer size %d\n",
- d - &s->chan[0], val >> 16, val & 0xffff);
+ trace_es1370_frame_count_wr(d - &s->chan[0],
+ d->frame_cnt >> 16, d->frame_cnt & 0xffff);
break;
default:
- lwarn ("writel %#x <- %#x\n", addr, val);
+ lwarn("writel 0x%" PRIx64 " <- 0x%" PRIx64 "\n", addr, val);
break;
}
}
@@ -573,17 +556,9 @@
case ES1370_REG_DAC2_SCOUNT:
case ES1370_REG_ADC_SCOUNT:
d += (addr - ES1370_REG_DAC1_SCOUNT) >> 2;
+ trace_es1370_sample_count_rd(d - &s->chan[0],
+ d->scount >> 16, d->scount & 0xffff);
val = d->scount;
-#ifdef DEBUG_ES1370
- {
- uint32_t curr_count = d->scount >> 16;
- uint32_t count = d->scount & 0xffff;
-
- curr_count <<= d->shift;
- count <<= d->shift;
- dolog ("read scount curr %d, total %d\n", curr_count, count);
- }
-#endif
break;
case ES1370_REG_ADC_FRAMECNT:
@@ -593,17 +568,9 @@
case ES1370_REG_DAC2_FRAMECNT:
d += (addr - ES1370_REG_DAC1_FRAMECNT) >> 3;
framecnt:
+ trace_es1370_frame_count_rd(d - &s->chan[0],
+ d->frame_cnt >> 16, d->frame_cnt & 0xffff);
val = d->frame_cnt;
-#ifdef DEBUG_ES1370
- {
- uint32_t size = ((d->frame_cnt & 0xffff) + 1) << 2;
- uint32_t curr = ((d->frame_cnt >> 16) + 1) << 2;
- if (curr > size) {
- dolog ("read framecnt curr %d, size %d %d\n", curr, size,
- curr > size);
- }
- }
-#endif
break;
case ES1370_REG_ADC_FRAMEADR:
@@ -613,30 +580,32 @@
case ES1370_REG_DAC2_FRAMEADR:
d += (addr - ES1370_REG_DAC1_FRAMEADR) >> 3;
frameadr:
+ trace_es1370_frame_address_rd(d - &s->chan[0], d->frame_addr);
val = d->frame_addr;
break;
case ES1370_REG_PHANTOM_FRAMECNT:
val = ~0U;
- lwarn ("reading from phantom frame count\n");
+ lwarn("reading from phantom frame count\n");
break;
case ES1370_REG_PHANTOM_FRAMEADR:
val = ~0U;
- lwarn ("reading from phantom frame address\n");
+ lwarn("reading from phantom frame address\n");
break;
default:
val = ~0U;
- lwarn ("readl %#x -> %#x\n", addr, val);
+ lwarn("readl 0x%" PRIx64 " -> 0x%x\n", addr, val);
break;
}
return val;
}
static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
- int max, int *irq)
+ int max, bool *irq)
{
uint8_t tmpbuf[4096];
+ size_t to_transfer;
uint32_t addr = d->frame_addr;
int sc = d->scount & 0xffff;
int csc = d->scount >> 16;
@@ -648,53 +617,53 @@
}
int left = ((size - cnt + 1) << 2) + d->leftover;
int transferred = 0;
- int temp = MIN (max, MIN (left, csc_bytes));
int index = d - &s->chan[0];
+ to_transfer = MIN(max, MIN(left, csc_bytes));
addr += (cnt << 2) + d->leftover;
if (index == ADC_CHANNEL) {
- while (temp > 0) {
+ while (to_transfer > 0) {
int acquired, to_copy;
- to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
+ to_copy = MIN(to_transfer, sizeof(tmpbuf));
acquired = AUD_read (s->adc_voice, tmpbuf, to_copy);
- if (!acquired)
+ if (!acquired) {
break;
+ }
pci_dma_write (&s->dev, addr, tmpbuf, acquired);
- temp -= acquired;
+ to_transfer -= acquired;
addr += acquired;
transferred += acquired;
}
- }
- else {
+ } else {
SWVoiceOut *voice = s->dac_voice[index];
- while (temp > 0) {
+ while (to_transfer > 0) {
int copied, to_copy;
- to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
+ to_copy = MIN(to_transfer, sizeof(tmpbuf));
pci_dma_read (&s->dev, addr, tmpbuf, to_copy);
copied = AUD_write (voice, tmpbuf, to_copy);
- if (!copied)
+ if (!copied) {
break;
- temp -= copied;
+ }
+ to_transfer -= copied;
addr += copied;
transferred += copied;
}
}
if (csc_bytes == transferred) {
- *irq = 1;
+ if (*irq) {
+ trace_es1370_lost_interrupt(index);
+ }
+ *irq = true;
d->scount = sc | (sc << 16);
- ldebug ("sc = %d, rate = %f\n",
- (sc + 1) << d->shift,
- (sc + 1) / (double) 44100);
- }
- else {
- *irq = 0;
+ } else {
+ *irq = false;
d->scount = sc | (((csc_bytes - transferred - 1) >> d->shift) << 16);
}
@@ -704,21 +673,26 @@
/* Bah, how stupid is that having a 0 represent true value?
i just spent few hours on this shit */
AUD_log ("es1370: warning", "non looping mode\n");
- }
- else {
+ } else {
d->frame_cnt = size;
- if ((uint32_t) cnt <= d->frame_cnt)
+ if ((uint32_t) cnt <= d->frame_cnt) {
d->frame_cnt |= cnt << 16;
+ }
}
d->leftover = (transferred + d->leftover) & 3;
+ trace_es1370_transfer_audio(index,
+ d->frame_cnt >> 16, d->frame_cnt & 0xffff,
+ d->scount >> 16, d->scount & 0xffff,
+ d->leftover, *irq);
}
static void es1370_run_channel (ES1370State *s, size_t chan, int free_or_avail)
{
uint32_t new_status = s->status;
- int max_bytes, irq;
+ int max_bytes;
+ bool irq;
struct chan *d = &s->chan[chan];
const struct chan_bits *b = &es1370_chan_bits[chan];
@@ -732,6 +706,8 @@
return;
}
+ irq = s->sctl & b->sctl_inten && s->status & b->stat_int;
+
es1370_transfer_audio (s, d, b->sctl_loopsel, max_bytes, &irq);
if (irq) {
@@ -806,8 +782,7 @@
AUD_close_in (&s->card, s->adc_voice);
s->adc_voice = NULL;
}
- }
- else {
+ } else {
if (s->dac_voice[i]) {
AUD_close_out (&s->card, s->dac_voice[i]);
s->dac_voice[i] = NULL;
diff --git a/hw/audio/trace-events b/hw/audio/trace-events
index 89ef299..059ce45 100644
--- a/hw/audio/trace-events
+++ b/hw/audio/trace-events
@@ -6,6 +6,17 @@
cs4231_mem_writel_reg(uint32_t reg, uint32_t old, uint32_t val) "write reg %d: 0x%08x -> 0x%08x"
cs4231_mem_writel_dreg(uint32_t reg, uint32_t old, uint32_t val) "write dreg %d: 0x%02x -> 0x%02x"
+# es1370.c
+es1370_frame_address_rd(int ch, uint32_t addr) "ch=%d addr=0x%08x"
+es1370_frame_address_wr(int ch, uint32_t addr) "ch=%d addr=0x%08x"
+es1370_frame_count_rd(int ch, uint32_t curr, uint32_t size) "ch=%d CURR_CT=%u BUF_SIZE=%u"
+es1370_frame_count_wr(int ch, uint32_t curr, uint32_t size) "ch=%d CURR_CT=%u BUF_SIZE=%u"
+es1370_lost_interrupt(int ch) "ch=%d lost interrupt"
+es1370_sample_count_rd(int ch, uint32_t curr, uint32_t num) "ch=%d CURR_SAMP_CT=%u SAMP_CT=%u"
+es1370_sample_count_wr(int ch, uint32_t curr, uint32_t num) "ch=%d CURR_SAMP_CT=%u SAMP_CT=%u"
+es1370_stream_format(int ch, uint32_t freq, const char *fmt, const char *mode, uint32_t shift) "ch=%d fmt=%u:%s:%s shift=%u"
+es1370_transfer_audio(int ch, uint32_t f_curr, uint32_t f_size, uint32_t s_curr, uint32_t s_num, uint32_t leftover, bool irq) "ch=%d CURR_CT=%u BUF_SIZE=%u CURR_SAMP_CT=%u SAMP_CT=%u leftover=%u irq=%d"
+
# hda-codec.c
hda_audio_running(const char *stream, int nr, bool running) "st %s, nr %d, run %d"
hda_audio_format(const char *stream, int chan, const char *fmt, int freq) "st %s, %d x %s @ %d Hz"
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 16a13904..1a01c35 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -10,6 +10,11 @@
#define GDB_WATCHPOINT_READ 3
#define GDB_WATCHPOINT_ACCESS 4
+typedef struct GDBFeature {
+ const char *xmlname;
+ const char *xml;
+} GDBFeature;
+
/* Get or set a register. Returns the size of the register. */
typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
@@ -40,15 +45,7 @@
void gdb_set_stop_cpu(CPUState *cpu);
-/**
- * gdb_has_xml() - report of gdb supports modern target descriptions
- *
- * This will report true if the gdb negotiated qXfer:features:read
- * target descriptions.
- */
-bool gdb_has_xml(void);
-
-/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
-extern const char *const xml_builtin[][2];
+/* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
+extern const GDBFeature gdb_static_features[];
#endif
diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h
index 5282878..c4552b5 100644
--- a/include/exec/plugin-gen.h
+++ b/include/exec/plugin-gen.h
@@ -20,7 +20,7 @@
bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db,
bool supress);
-void plugin_gen_tb_end(CPUState *cpu);
+void plugin_gen_tb_end(CPUState *cpu, size_t num_insns);
void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db);
void plugin_gen_insn_end(void);
@@ -42,7 +42,7 @@
static inline void plugin_gen_insn_end(void)
{ }
-static inline void plugin_gen_tb_end(CPUState *cpu)
+static inline void plugin_gen_tb_end(CPUState *cpu, size_t num_insns)
{ }
static inline void plugin_gen_disable_mem_helpers(void)
diff --git a/include/exec/translator.h b/include/exec/translator.h
index 9d9e980..6d3f59d 100644
--- a/include/exec/translator.h
+++ b/include/exec/translator.h
@@ -73,6 +73,7 @@
* @max_insns: Maximum number of instructions to be translated in this TB.
* @singlestep_enabled: "Hardware" single stepping enabled.
* @saved_can_do_io: Known value of cpu->neg.can_do_io, or -1 for unknown.
+ * @plugin_enabled: TCG plugin enabled in this TB.
*
* Architecture-agnostic disassembly context.
*/
@@ -85,6 +86,7 @@
int max_insns;
bool singlestep_enabled;
int8_t saved_can_do_io;
+ bool plugin_enabled;
void *host_addr[2];
} DisasContextBase;
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index e02bc59..3968369 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -165,7 +165,7 @@
vaddr (*gdb_adjust_breakpoint)(CPUState *cpu, vaddr addr);
const char *gdb_core_xml_file;
- gchar * (*gdb_arch_name)(CPUState *cpu);
+ const gchar * (*gdb_arch_name)(CPUState *cpu);
const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
@@ -502,7 +502,7 @@
CPUJumpCache *tb_jmp_cache;
- struct GDBRegisterState *gdb_regs;
+ GArray *gdb_regs;
int gdb_num_regs;
int gdb_num_g_regs;
QTAILQ_ENTRY(CPUState) node;
diff --git a/meson.build b/meson.build
index 79aef19..bd65a11 100644
--- a/meson.build
+++ b/meson.build
@@ -3693,7 +3693,7 @@
dependencies: common_all.dependencies(),
name_suffix: 'fa')
-feature_to_c = find_program('scripts/feature_to_c.sh')
+feature_to_c = find_program('scripts/feature_to_c.py')
if targetos == 'darwin'
entitlement = find_program('scripts/entitlement.sh')
diff --git a/migration/migration.c b/migration/migration.c
index 585d3c8..1c6c81a 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -431,13 +431,16 @@
static void qemu_start_incoming_migration(const char *uri, Error **errp)
{
const char *p = NULL;
+ MigrationIncomingState *mis = migration_incoming_get_current();
/* URI is not suitable for migration? */
if (!migration_channels_and_uri_compatible(uri, errp)) {
return;
}
- qapi_event_send_migration(MIGRATION_STATUS_SETUP);
+ migrate_set_state(&mis->state, MIGRATION_STATUS_NONE,
+ MIGRATION_STATUS_SETUP);
+
if (strstart(uri, "tcp:", &p) ||
strstart(uri, "unix:", NULL) ||
strstart(uri, "vsock:", NULL)) {
@@ -531,7 +534,7 @@
mis->largest_page_size = qemu_ram_pagesize_largest();
postcopy_state_set(POSTCOPY_INCOMING_NONE);
- migrate_set_state(&mis->state, MIGRATION_STATUS_NONE,
+ migrate_set_state(&mis->state, MIGRATION_STATUS_SETUP,
MIGRATION_STATUS_ACTIVE);
mis->loadvm_co = qemu_coroutine_self();
@@ -1057,9 +1060,6 @@
break;
case MIGRATION_STATUS_FAILED:
info->has_status = true;
- if (s->error) {
- info->error_desc = g_strdup(error_get_pretty(s->error));
- }
break;
case MIGRATION_STATUS_CANCELLED:
info->has_status = true;
@@ -1069,6 +1069,11 @@
break;
}
info->status = state;
+
+ QEMU_LOCK_GUARD(&s->error_mutex);
+ if (s->error) {
+ info->error_desc = g_strdup(error_get_pretty(s->error));
+ }
}
static void fill_destination_migration_info(MigrationInfo *info)
@@ -1229,6 +1234,13 @@
}
}
+bool migrate_has_error(MigrationState *s)
+{
+ /* The lock is not helpful here, but still follow the rule */
+ QEMU_LOCK_GUARD(&s->error_mutex);
+ return qatomic_read(&s->error);
+}
+
static void migrate_error_free(MigrationState *s)
{
QEMU_LOCK_GUARD(&s->error_mutex);
@@ -1751,6 +1763,16 @@
s->rp_state.error = true;
}
+void migration_rp_wait(MigrationState *s)
+{
+ qemu_sem_wait(&s->rp_state.rp_sem);
+}
+
+void migration_rp_kick(MigrationState *s)
+{
+ qemu_sem_post(&s->rp_state.rp_sem);
+}
+
static struct rp_cmd_args {
ssize_t len; /* -1 = variable */
const char *name;
@@ -1823,7 +1845,7 @@
MIGRATION_STATUS_POSTCOPY_ACTIVE);
/* Notify send thread that time to continue send pages */
- qemu_sem_post(&s->rp_state.rp_sem);
+ migration_rp_kick(s);
return 0;
}
@@ -2452,7 +2474,7 @@
qemu_savevm_send_postcopy_resume(s->to_dst_file);
while (s->state == MIGRATION_STATUS_POSTCOPY_RECOVER) {
- qemu_sem_wait(&s->rp_state.rp_sem);
+ migration_rp_wait(s);
}
if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
diff --git a/migration/migration.h b/migration/migration.h
index 972597f..cd55343 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -316,6 +316,12 @@
* be cleared in the rp_thread!
*/
bool rp_thread_created;
+ /*
+ * Used to synchronize between migration main thread and return
+ * path thread. The migration thread can wait() on this sem, while
+ * other threads (e.g., return path thread) can kick it using a
+ * post().
+ */
QemuSemaphore rp_sem;
/*
* We post to this when we got one PONG from dest. So far it's an
@@ -476,6 +482,7 @@
uint64_t migrate_max_downtime(void);
void migrate_set_error(MigrationState *s, const Error *error);
+bool migrate_has_error(MigrationState *s);
void migrate_fd_connect(MigrationState *s, Error *error_in);
@@ -526,4 +533,13 @@
void migration_reset_vfio_bytes_transferred(void);
void postcopy_temp_page_reset(PostcopyTmpPage *tmp_page);
+/* Migration thread waiting for return path thread. */
+void migration_rp_wait(MigrationState *s);
+/*
+ * Kick the migration thread waiting for return path messages. NOTE: the
+ * name can be slightly confusing (when read as "kick the rp thread"), just
+ * to remember the target is always the migration thread.
+ */
+void migration_rp_kick(MigrationState *s);
+
#endif
diff --git a/migration/options.c b/migration/options.c
index 1d1e132..6bbfd48 100644
--- a/migration/options.c
+++ b/migration/options.c
@@ -1408,20 +1408,25 @@
{
MigrationParameters tmp;
- /* TODO Rewrite "" to null instead */
+ /* TODO Rewrite "" to null instead for all three tls_* parameters */
if (params->tls_creds
&& params->tls_creds->type == QTYPE_QNULL) {
qobject_unref(params->tls_creds->u.n);
params->tls_creds->type = QTYPE_QSTRING;
params->tls_creds->u.s = strdup("");
}
- /* TODO Rewrite "" to null instead */
if (params->tls_hostname
&& params->tls_hostname->type == QTYPE_QNULL) {
qobject_unref(params->tls_hostname->u.n);
params->tls_hostname->type = QTYPE_QSTRING;
params->tls_hostname->u.s = strdup("");
}
+ if (params->tls_authz
+ && params->tls_authz->type == QTYPE_QNULL) {
+ qobject_unref(params->tls_authz->u.n);
+ params->tls_authz->type = QTYPE_QSTRING;
+ params->tls_authz->u.s = strdup("");
+ }
migrate_params_test_apply(params, &tmp);
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 5e8207d..7fb6592 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -142,15 +142,24 @@
*
* Return negative error value if there has been an error on previous
* operations, return 0 if no error happened.
- * Optional, it returns Error* in errp, but it may be NULL even if return value
- * is not 0.
*
+ * If errp is specified, a verbose error message will be copied over.
*/
static int qemu_file_get_error_obj(QEMUFile *f, Error **errp)
{
- if (errp) {
- *errp = f->last_error_obj ? error_copy(f->last_error_obj) : NULL;
+ if (!f->last_error) {
+ return 0;
}
+
+ /* There is an error */
+ if (errp) {
+ if (f->last_error_obj) {
+ *errp = error_copy(f->last_error_obj);
+ } else {
+ error_setg_errno(errp, -f->last_error, "Channel error");
+ }
+ }
+
return f->last_error;
}
diff --git a/migration/ram.c b/migration/ram.c
index e4bfd39..2f5ce4d 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -394,6 +394,14 @@
/* Queue of outstanding page requests from the destination */
QemuMutex src_page_req_mutex;
QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests;
+
+ /*
+ * This is only used when postcopy is in recovery phase, to communicate
+ * between the migration thread and the return path thread on dirty
+ * bitmap synchronizations. This field is unused in other stages of
+ * RAM migration.
+ */
+ unsigned int postcopy_bmap_sync_requested;
};
typedef struct RAMState RAMState;
@@ -4119,21 +4127,21 @@
{
RAMBlock *block;
QEMUFile *file = s->to_dst_file;
- int ramblock_count = 0;
trace_ram_dirty_bitmap_sync_start();
+ qatomic_set(&rs->postcopy_bmap_sync_requested, 0);
RAMBLOCK_FOREACH_NOT_IGNORED(block) {
qemu_savevm_send_recv_bitmap(file, block->idstr);
trace_ram_dirty_bitmap_request(block->idstr);
- ramblock_count++;
+ qatomic_inc(&rs->postcopy_bmap_sync_requested);
}
trace_ram_dirty_bitmap_sync_wait();
/* Wait until all the ramblocks' dirty bitmap synced */
- while (ramblock_count--) {
- qemu_sem_wait(&s->rp_state.rp_sem);
+ while (qatomic_read(&rs->postcopy_bmap_sync_requested)) {
+ migration_rp_wait(s);
}
trace_ram_dirty_bitmap_sync_complete();
@@ -4141,11 +4149,6 @@
return 0;
}
-static void ram_dirty_bitmap_reload_notify(MigrationState *s)
-{
- qemu_sem_post(&s->rp_state.rp_sem);
-}
-
/*
* Read the received bitmap, revert it as the initial dirty bitmap.
* This is only used when the postcopy migration is paused but wants
@@ -4159,6 +4162,7 @@
unsigned long *le_bitmap, nbits = block->used_length >> TARGET_PAGE_BITS;
uint64_t local_size = DIV_ROUND_UP(nbits, 8);
uint64_t size, end_mark;
+ RAMState *rs = ram_state;
trace_ram_dirty_bitmap_reload_begin(block->idstr);
@@ -4225,11 +4229,16 @@
/* We'll recalculate migration_dirty_pages in ram_state_resume_prepare(). */
trace_ram_dirty_bitmap_reload_complete(block->idstr);
+ qatomic_dec(&rs->postcopy_bmap_sync_requested);
+
/*
- * We succeeded to sync bitmap for current ramblock. If this is
- * the last one to sync, we need to notify the main send thread.
+ * We succeeded to sync bitmap for current ramblock. Always kick the
+ * migration thread to check whether all requested bitmaps are
+ * reloaded. NOTE: it's racy to only kick when requested==0, because
+ * we don't know whether the migration thread may still be increasing
+ * it.
*/
- ram_dirty_bitmap_reload_notify(s);
+ migration_rp_kick(s);
ret = 0;
out:
diff --git a/migration/rdma.c b/migration/rdma.c
index cd5e1af..f6fc226 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -40,17 +40,6 @@
#include "options.h"
#include <poll.h>
-/*
- * Print and error on both the Monitor and the Log file.
- */
-#define ERROR(errp, fmt, ...) \
- do { \
- fprintf(stderr, "RDMA ERROR: " fmt "\n", ## __VA_ARGS__); \
- if (errp && (*(errp) == NULL)) { \
- error_setg(errp, "RDMA ERROR: " fmt, ## __VA_ARGS__); \
- } \
- } while (0)
-
#define RDMA_RESOLVE_TIMEOUT_MS 10000
/* Do not merge data if larger than this. */
@@ -85,18 +74,6 @@
*/
static uint32_t known_capabilities = RDMA_CAPABILITY_PIN_ALL;
-#define CHECK_ERROR_STATE() \
- do { \
- if (rdma->error_state) { \
- if (!rdma->error_reported) { \
- error_report("RDMA is in an error state waiting migration" \
- " to abort!"); \
- rdma->error_reported = 1; \
- } \
- return rdma->error_state; \
- } \
- } while (0)
-
/*
* A work request ID is 64-bits and we split up these bits
* into 3 parts:
@@ -133,13 +110,6 @@
RDMA_WRID_RECV_CONTROL = 4000,
};
-static const char *wrid_desc[] = {
- [RDMA_WRID_NONE] = "NONE",
- [RDMA_WRID_RDMA_WRITE] = "WRITE RDMA",
- [RDMA_WRID_SEND_CONTROL] = "CONTROL SEND",
- [RDMA_WRID_RECV_CONTROL] = "CONTROL RECV",
-};
-
/*
* Work request IDs for IB SEND messages only (not RDMA writes).
* This is used by the migration protocol to transmit
@@ -371,9 +341,9 @@
* memory registration, then do not attempt any future work
* and remember the error state.
*/
- int error_state;
- int error_reported;
- int received_error;
+ bool errored;
+ bool error_reported;
+ bool received_error;
/*
* Description of ram blocks used throughout the code.
@@ -458,6 +428,16 @@
uint64_t chunks; /* how many sequential chunks to register */
} RDMARegister;
+static bool rdma_errored(RDMAContext *rdma)
+{
+ if (rdma->errored && !rdma->error_reported) {
+ error_report("RDMA is in an error state waiting migration"
+ " to abort!");
+ rdma->error_reported = true;
+ }
+ return rdma->errored;
+}
+
static void register_to_network(RDMAContext *rdma, RDMARegister *reg)
{
RDMALocalBlock *local_block;
@@ -535,11 +515,12 @@
result->host_addr = ntohll(result->host_addr);
};
-const char *print_wrid(int wrid);
static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *head,
uint8_t *data, RDMAControlHeader *resp,
int *resp_idx,
- int (*callback)(RDMAContext *rdma));
+ int (*callback)(RDMAContext *rdma,
+ Error **errp),
+ Error **errp);
static inline uint64_t ram_chunk_index(const uint8_t *start,
const uint8_t *host)
@@ -567,9 +548,9 @@
return result;
}
-static int rdma_add_block(RDMAContext *rdma, const char *block_name,
- void *host_addr,
- ram_addr_t block_offset, uint64_t length)
+static void rdma_add_block(RDMAContext *rdma, const char *block_name,
+ void *host_addr,
+ ram_addr_t block_offset, uint64_t length)
{
RDMALocalBlocks *local = &rdma->local_ram_blocks;
RDMALocalBlock *block;
@@ -623,8 +604,6 @@
block->nb_chunks);
local->nb_blocks++;
-
- return 0;
}
/*
@@ -638,7 +617,8 @@
void *host_addr = qemu_ram_get_host_addr(rb);
ram_addr_t block_offset = qemu_ram_get_offset(rb);
ram_addr_t length = qemu_ram_get_used_length(rb);
- return rdma_add_block(opaque, block_name, host_addr, block_offset, length);
+ rdma_add_block(opaque, block_name, host_addr, block_offset, length);
+ return 0;
}
/*
@@ -646,7 +626,7 @@
* identify chunk boundaries inside each RAMBlock and also be referenced
* during dynamic page registration.
*/
-static int qemu_rdma_init_ram_blocks(RDMAContext *rdma)
+static void qemu_rdma_init_ram_blocks(RDMAContext *rdma)
{
RDMALocalBlocks *local = &rdma->local_ram_blocks;
int ret;
@@ -654,21 +634,18 @@
assert(rdma->blockmap == NULL);
memset(local, 0, sizeof *local);
ret = foreach_not_ignored_block(qemu_rdma_init_one_block, rdma);
- if (ret) {
- return ret;
- }
+ assert(!ret);
trace_qemu_rdma_init_ram_blocks(local->nb_blocks);
rdma->dest_blocks = g_new0(RDMADestBlock,
rdma->local_ram_blocks.nb_blocks);
local->init = true;
- return 0;
}
/*
* Note: If used outside of cleanup, the caller must ensure that the destination
* block structures are also updated
*/
-static int rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block)
+static void rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block)
{
RDMALocalBlocks *local = &rdma->local_ram_blocks;
RDMALocalBlock *old = local->block;
@@ -754,43 +731,34 @@
&local->block[x]);
}
}
-
- return 0;
}
/*
- * Put in the log file which RDMA device was opened and the details
- * associated with that device.
+ * Trace RDMA device open, with device details.
*/
static void qemu_rdma_dump_id(const char *who, struct ibv_context *verbs)
{
struct ibv_port_attr port;
if (ibv_query_port(verbs, 1, &port)) {
- error_report("Failed to query port information");
+ trace_qemu_rdma_dump_id_failed(who);
return;
}
- printf("%s RDMA Device opened: kernel name %s "
- "uverbs device name %s, "
- "infiniband_verbs class device path %s, "
- "infiniband class device path %s, "
- "transport: (%d) %s\n",
- who,
+ trace_qemu_rdma_dump_id(who,
verbs->device->name,
verbs->device->dev_name,
verbs->device->dev_path,
verbs->device->ibdev_path,
port.link_layer,
- (port.link_layer == IBV_LINK_LAYER_INFINIBAND) ? "Infiniband" :
- ((port.link_layer == IBV_LINK_LAYER_ETHERNET)
- ? "Ethernet" : "Unknown"));
+ port.link_layer == IBV_LINK_LAYER_INFINIBAND ? "Infiniband"
+ : port.link_layer == IBV_LINK_LAYER_ETHERNET ? "Ethernet"
+ : "Unknown");
}
/*
- * Put in the log file the RDMA gid addressing information,
- * useful for folks who have trouble understanding the
- * RDMA device hierarchy in the kernel.
+ * Trace RDMA gid addressing information.
+ * Useful for understanding the RDMA device hierarchy in the kernel.
*/
static void qemu_rdma_dump_gid(const char *who, struct rdma_cm_id *id)
{
@@ -867,18 +835,27 @@
for (x = 0; x < num_devices; x++) {
verbs = ibv_open_device(dev_list[x]);
+ /*
+ * ibv_open_device() is not documented to set errno. If
+ * it does, it's somebody else's doc bug. If it doesn't,
+ * the use of errno below is wrong.
+ * TODO Find out whether ibv_open_device() sets errno.
+ */
if (!verbs) {
if (errno == EPERM) {
continue;
} else {
- return -EINVAL;
+ error_setg_errno(errp, errno,
+ "could not open RDMA device context");
+ return -1;
}
}
if (ibv_query_port(verbs, 1, &port_attr)) {
ibv_close_device(verbs);
- ERROR(errp, "Could not query initial IB port");
- return -EINVAL;
+ error_setg(errp,
+ "RDMA ERROR: Could not query initial IB port");
+ return -1;
}
if (port_attr.link_layer == IBV_LINK_LAYER_INFINIBAND) {
@@ -893,17 +870,18 @@
if (roce_found) {
if (ib_found) {
- fprintf(stderr, "WARN: migrations may fail:"
- " IPv6 over RoCE / iWARP in linux"
- " is broken. But since you appear to have a"
- " mixed RoCE / IB environment, be sure to only"
- " migrate over the IB fabric until the kernel "
- " fixes the bug.\n");
+ warn_report("migrations may fail:"
+ " IPv6 over RoCE / iWARP in linux"
+ " is broken. But since you appear to have a"
+ " mixed RoCE / IB environment, be sure to only"
+ " migrate over the IB fabric until the kernel "
+ " fixes the bug.");
} else {
- ERROR(errp, "You only have RoCE / iWARP devices in your systems"
- " and your management software has specified '[::]'"
- ", but IPv6 over RoCE / iWARP is not supported in Linux.");
- return -ENONET;
+ error_setg(errp, "RDMA ERROR: "
+ "You only have RoCE / iWARP devices in your systems"
+ " and your management software has specified '[::]'"
+ ", but IPv6 over RoCE / iWARP is not supported in Linux.");
+ return -1;
}
}
@@ -918,14 +896,15 @@
/* IB ports start with 1, not 0 */
if (ibv_query_port(verbs, 1, &port_attr)) {
- ERROR(errp, "Could not query initial IB port");
- return -EINVAL;
+ error_setg(errp, "RDMA ERROR: Could not query initial IB port");
+ return -1;
}
if (port_attr.link_layer == IBV_LINK_LAYER_ETHERNET) {
- ERROR(errp, "Linux kernel's RoCE / iWARP does not support IPv6 "
- "(but patches on linux-rdma in progress)");
- return -ENONET;
+ error_setg(errp, "RDMA ERROR: "
+ "Linux kernel's RoCE / iWARP does not support IPv6 "
+ "(but patches on linux-rdma in progress)");
+ return -1;
}
#endif
@@ -940,6 +919,7 @@
*/
static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
{
+ Error *err = NULL;
int ret;
struct rdma_addrinfo *res;
char port_str[16];
@@ -948,21 +928,21 @@
struct rdma_addrinfo *e;
if (rdma->host == NULL || !strcmp(rdma->host, "")) {
- ERROR(errp, "RDMA hostname has not been set");
- return -EINVAL;
+ error_setg(errp, "RDMA ERROR: RDMA hostname has not been set");
+ return -1;
}
/* create CM channel */
rdma->channel = rdma_create_event_channel();
if (!rdma->channel) {
- ERROR(errp, "could not create CM channel");
- return -EINVAL;
+ error_setg(errp, "RDMA ERROR: could not create CM channel");
+ return -1;
}
/* create CM id */
ret = rdma_create_id(rdma->channel, &rdma->cm_id, NULL, RDMA_PS_TCP);
- if (ret) {
- ERROR(errp, "could not create channel id");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: could not create channel id");
goto err_resolve_create_id;
}
@@ -970,31 +950,42 @@
port_str[15] = '\0';
ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res);
- if (ret < 0) {
- ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host);
+ if (ret) {
+ error_setg(errp, "RDMA ERROR: could not rdma_getaddrinfo address %s",
+ rdma->host);
goto err_resolve_get_addr;
}
+ /* Try all addresses, saving the first error in @err */
for (e = res; e != NULL; e = e->ai_next) {
+ Error **local_errp = err ? NULL : &err;
+
inet_ntop(e->ai_family,
&((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip);
trace_qemu_rdma_resolve_host_trying(rdma->host, ip);
ret = rdma_resolve_addr(rdma->cm_id, NULL, e->ai_dst_addr,
RDMA_RESOLVE_TIMEOUT_MS);
- if (!ret) {
+ if (ret >= 0) {
if (e->ai_family == AF_INET6) {
- ret = qemu_rdma_broken_ipv6_kernel(rdma->cm_id->verbs, errp);
- if (ret) {
+ ret = qemu_rdma_broken_ipv6_kernel(rdma->cm_id->verbs,
+ local_errp);
+ if (ret < 0) {
continue;
}
}
+ error_free(err);
goto route;
}
}
rdma_freeaddrinfo(res);
- ERROR(errp, "could not resolve address %s", rdma->host);
+ if (err) {
+ error_propagate(errp, err);
+ } else {
+ error_setg(errp, "RDMA ERROR: could not resolve address %s",
+ rdma->host);
+ }
goto err_resolve_get_addr;
route:
@@ -1002,38 +993,37 @@
qemu_rdma_dump_gid("source_resolve_addr", rdma->cm_id);
ret = rdma_get_cm_event(rdma->channel, &cm_event);
- if (ret) {
- ERROR(errp, "could not perform event_addr_resolved");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: could not perform event_addr_resolved");
goto err_resolve_get_addr;
}
if (cm_event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {
- ERROR(errp, "result not equal to event_addr_resolved %s",
- rdma_event_str(cm_event->event));
- error_report("rdma_resolve_addr");
+ error_setg(errp,
+ "RDMA ERROR: result not equal to event_addr_resolved %s",
+ rdma_event_str(cm_event->event));
rdma_ack_cm_event(cm_event);
- ret = -EINVAL;
goto err_resolve_get_addr;
}
rdma_ack_cm_event(cm_event);
/* resolve route */
ret = rdma_resolve_route(rdma->cm_id, RDMA_RESOLVE_TIMEOUT_MS);
- if (ret) {
- ERROR(errp, "could not resolve rdma route");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: could not resolve rdma route");
goto err_resolve_get_addr;
}
ret = rdma_get_cm_event(rdma->channel, &cm_event);
- if (ret) {
- ERROR(errp, "could not perform event_route_resolved");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: could not perform event_route_resolved");
goto err_resolve_get_addr;
}
if (cm_event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {
- ERROR(errp, "result not equal to event_route_resolved: %s",
- rdma_event_str(cm_event->event));
+ error_setg(errp, "RDMA ERROR: "
+ "result not equal to event_route_resolved: %s",
+ rdma_event_str(cm_event->event));
rdma_ack_cm_event(cm_event);
- ret = -EINVAL;
goto err_resolve_get_addr;
}
rdma_ack_cm_event(cm_event);
@@ -1048,25 +1038,25 @@
err_resolve_create_id:
rdma_destroy_event_channel(rdma->channel);
rdma->channel = NULL;
- return ret;
+ return -1;
}
/*
* Create protection domain and completion queues
*/
-static int qemu_rdma_alloc_pd_cq(RDMAContext *rdma)
+static int qemu_rdma_alloc_pd_cq(RDMAContext *rdma, Error **errp)
{
/* allocate pd */
rdma->pd = ibv_alloc_pd(rdma->verbs);
if (!rdma->pd) {
- error_report("failed to allocate protection domain");
+ error_setg(errp, "failed to allocate protection domain");
return -1;
}
/* create receive completion channel */
rdma->recv_comp_channel = ibv_create_comp_channel(rdma->verbs);
if (!rdma->recv_comp_channel) {
- error_report("failed to allocate receive completion channel");
+ error_setg(errp, "failed to allocate receive completion channel");
goto err_alloc_pd_cq;
}
@@ -1076,21 +1066,21 @@
rdma->recv_cq = ibv_create_cq(rdma->verbs, (RDMA_SIGNALED_SEND_MAX * 3),
NULL, rdma->recv_comp_channel, 0);
if (!rdma->recv_cq) {
- error_report("failed to allocate receive completion queue");
+ error_setg(errp, "failed to allocate receive completion queue");
goto err_alloc_pd_cq;
}
/* create send completion channel */
rdma->send_comp_channel = ibv_create_comp_channel(rdma->verbs);
if (!rdma->send_comp_channel) {
- error_report("failed to allocate send completion channel");
+ error_setg(errp, "failed to allocate send completion channel");
goto err_alloc_pd_cq;
}
rdma->send_cq = ibv_create_cq(rdma->verbs, (RDMA_SIGNALED_SEND_MAX * 3),
NULL, rdma->send_comp_channel, 0);
if (!rdma->send_cq) {
- error_report("failed to allocate send completion queue");
+ error_setg(errp, "failed to allocate send completion queue");
goto err_alloc_pd_cq;
}
@@ -1134,7 +1124,7 @@
attr.qp_type = IBV_QPT_RC;
ret = rdma_create_qp(rdma->cm_id, rdma->pd, &attr);
- if (ret) {
+ if (ret < 0) {
return -1;
}
@@ -1176,15 +1166,11 @@
ret = ibv_advise_mr(pd, advice,
IBV_ADVISE_MR_FLAG_FLUSH, &sg_list, 1);
/* ignore the error */
- if (ret) {
- trace_qemu_rdma_advise_mr(name, len, addr, strerror(errno));
- } else {
- trace_qemu_rdma_advise_mr(name, len, addr, "successed");
- }
+ trace_qemu_rdma_advise_mr(name, len, addr, strerror(ret));
#endif
}
-static int qemu_rdma_reg_whole_ram_blocks(RDMAContext *rdma)
+static int qemu_rdma_reg_whole_ram_blocks(RDMAContext *rdma, Error **errp)
{
int i;
RDMALocalBlocks *local = &rdma->local_ram_blocks;
@@ -1197,7 +1183,12 @@
local->block[i].local_host_addr,
local->block[i].length, access
);
-
+ /*
+ * ibv_reg_mr() is not documented to set errno. If it does,
+ * it's somebody else's doc bug. If it doesn't, the use of
+ * errno below is wrong.
+ * TODO Find out whether ibv_reg_mr() sets errno.
+ */
if (!local->block[i].mr &&
errno == ENOTSUP && rdma_support_odp(rdma->verbs)) {
access |= IBV_ACCESS_ON_DEMAND;
@@ -1219,16 +1210,16 @@
}
if (!local->block[i].mr) {
- perror("Failed to register local dest ram block!");
- break;
+ error_setg_errno(errp, errno,
+ "Failed to register local dest ram block!");
+ goto err;
}
rdma->total_registrations++;
}
- if (i >= local->nb_blocks) {
- return 0;
- }
+ return 0;
+err:
for (i--; i >= 0; i--) {
ibv_dereg_mr(local->block[i].mr);
local->block[i].mr = NULL;
@@ -1245,15 +1236,13 @@
*
* Once the block is found, also identify which 'chunk' within that
* block that the page belongs to.
- *
- * This search cannot fail or the migration will fail.
*/
-static int qemu_rdma_search_ram_block(RDMAContext *rdma,
- uintptr_t block_offset,
- uint64_t offset,
- uint64_t length,
- uint64_t *block_index,
- uint64_t *chunk_index)
+static void qemu_rdma_search_ram_block(RDMAContext *rdma,
+ uintptr_t block_offset,
+ uint64_t offset,
+ uint64_t length,
+ uint64_t *block_index,
+ uint64_t *chunk_index)
{
uint64_t current_addr = block_offset + offset;
RDMALocalBlock *block = g_hash_table_lookup(rdma->blockmap,
@@ -1265,8 +1254,6 @@
*block_index = block->index;
*chunk_index = ram_chunk_index(block->local_host_addr,
block->local_host_addr + (current_addr - block->offset));
-
- return 0;
}
/*
@@ -1309,6 +1296,12 @@
trace_qemu_rdma_register_and_get_keys(len, chunk_start);
block->pmr[chunk] = ibv_reg_mr(rdma->pd, chunk_start, len, access);
+ /*
+ * ibv_reg_mr() is not documented to set errno. If it does,
+ * it's somebody else's doc bug. If it doesn't, the use of
+ * errno below is wrong.
+ * TODO Find out whether ibv_reg_mr() sets errno.
+ */
if (!block->pmr[chunk] &&
errno == ENOTSUP && rdma_support_odp(rdma->verbs)) {
access |= IBV_ACCESS_ON_DEMAND;
@@ -1325,15 +1318,6 @@
}
}
if (!block->pmr[chunk]) {
- perror("Failed to register chunk!");
- fprintf(stderr, "Chunk details: block: %d chunk index %d"
- " start %" PRIuPTR " end %" PRIuPTR
- " host %" PRIuPTR
- " local %" PRIuPTR " registrations: %d\n",
- block->index, chunk, (uintptr_t)chunk_start,
- (uintptr_t)chunk_end, host_addr,
- (uintptr_t)block->local_host_addr,
- rdma->total_registrations);
return -1;
}
rdma->total_registrations++;
@@ -1360,18 +1344,9 @@
rdma->total_registrations++;
return 0;
}
- error_report("qemu_rdma_reg_control failed");
return -1;
}
-const char *print_wrid(int wrid)
-{
- if (wrid >= RDMA_WRID_RECV_CONTROL) {
- return wrid_desc[RDMA_WRID_RECV_CONTROL];
- }
- return wrid_desc[wrid];
-}
-
/*
* Perform a non-optimized memory unregistration after every transfer
* for demonstration purposes, only if pin-all is not requested.
@@ -1385,6 +1360,8 @@
*/
static int qemu_rdma_unregister_waiting(RDMAContext *rdma)
{
+ Error *err = NULL;
+
while (rdma->unregistrations[rdma->unregister_current]) {
int ret;
uint64_t wr_id = rdma->unregistrations[rdma->unregister_current];
@@ -1434,17 +1411,19 @@
block->remote_keys[chunk] = 0;
if (ret != 0) {
- perror("unregistration chunk failed");
- return -ret;
+ error_report("unregistration chunk failed: %s",
+ strerror(ret));
+ return -1;
}
rdma->total_registrations--;
reg.key.chunk = chunk;
register_to_network(rdma, ®);
ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) ®,
- &resp, NULL, NULL);
+ &resp, NULL, NULL, &err);
if (ret < 0) {
- return ret;
+ error_report_err(err);
+ return -1;
}
trace_qemu_rdma_unregister_waiting_complete(chunk);
@@ -1469,8 +1448,8 @@
* (of any kind) has completed.
* Return the work request ID that completed.
*/
-static uint64_t qemu_rdma_poll(RDMAContext *rdma, struct ibv_cq *cq,
- uint64_t *wr_id_out, uint32_t *byte_len)
+static int qemu_rdma_poll(RDMAContext *rdma, struct ibv_cq *cq,
+ uint64_t *wr_id_out, uint32_t *byte_len)
{
int ret;
struct ibv_wc wc;
@@ -1484,24 +1463,19 @@
}
if (ret < 0) {
- error_report("ibv_poll_cq return %d", ret);
- return ret;
+ return -1;
}
wr_id = wc.wr_id & RDMA_WRID_TYPE_MASK;
if (wc.status != IBV_WC_SUCCESS) {
- fprintf(stderr, "ibv_poll_cq wc.status=%d %s!\n",
- wc.status, ibv_wc_status_str(wc.status));
- fprintf(stderr, "ibv_poll_cq wrid=%s!\n", wrid_desc[wr_id]);
-
return -1;
}
if (rdma->control_ready_expected &&
(wr_id >= RDMA_WRID_RECV_CONTROL)) {
- trace_qemu_rdma_poll_recv(wrid_desc[RDMA_WRID_RECV_CONTROL],
- wr_id - RDMA_WRID_RECV_CONTROL, wr_id, rdma->nb_sent);
+ trace_qemu_rdma_poll_recv(wr_id - RDMA_WRID_RECV_CONTROL, wr_id,
+ rdma->nb_sent);
rdma->control_ready_expected = 0;
}
@@ -1512,7 +1486,7 @@
(wc.wr_id & RDMA_WRID_BLOCK_MASK) >> RDMA_WRID_BLOCK_SHIFT;
RDMALocalBlock *block = &(rdma->local_ram_blocks.block[index]);
- trace_qemu_rdma_poll_write(print_wrid(wr_id), wr_id, rdma->nb_sent,
+ trace_qemu_rdma_poll_write(wr_id, rdma->nb_sent,
index, chunk, block->local_host_addr,
(void *)(uintptr_t)block->remote_host_addr);
@@ -1522,7 +1496,7 @@
rdma->nb_sent--;
}
} else {
- trace_qemu_rdma_poll_other(print_wrid(wr_id), wr_id, rdma->nb_sent);
+ trace_qemu_rdma_poll_other(wr_id, rdma->nb_sent);
}
*wr_id_out = wc.wr_id;
@@ -1540,7 +1514,7 @@
struct ibv_comp_channel *comp_channel)
{
struct rdma_cm_event *cm_event;
- int ret = -1;
+ int ret;
/*
* Coroutine doesn't start until migration_fd_process_incoming()
@@ -1557,7 +1531,7 @@
* But we need to be able to handle 'cancel' or an error
* without hanging forever.
*/
- while (!rdma->error_state && !rdma->received_error) {
+ while (!rdma->errored && !rdma->received_error) {
GPollFD pfds[2];
pfds[0].fd = comp_channel->fd;
pfds[0].events = G_IO_IN | G_IO_HUP | G_IO_ERR;
@@ -1577,18 +1551,14 @@
if (pfds[1].revents) {
ret = rdma_get_cm_event(rdma->channel, &cm_event);
- if (ret) {
- error_report("failed to get cm event while wait "
- "completion channel");
- return -EPIPE;
+ if (ret < 0) {
+ return -1;
}
- error_report("receive cm event while wait comp channel,"
- "cm event is %d", cm_event->event);
if (cm_event->event == RDMA_CM_EVENT_DISCONNECTED ||
cm_event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) {
rdma_ack_cm_event(cm_event);
- return -EPIPE;
+ return -1;
}
rdma_ack_cm_event(cm_event);
}
@@ -1600,30 +1570,29 @@
default: /* Error of some type -
* I don't trust errno from qemu_poll_ns
*/
- error_report("%s: poll failed", __func__);
- return -EPIPE;
+ return -1;
}
if (migrate_get_current()->state == MIGRATION_STATUS_CANCELLING) {
/* Bail out and let the cancellation happen */
- return -EPIPE;
+ return -1;
}
}
}
if (rdma->received_error) {
- return -EPIPE;
+ return -1;
}
- return rdma->error_state;
+ return -rdma->errored;
}
-static struct ibv_comp_channel *to_channel(RDMAContext *rdma, int wrid)
+static struct ibv_comp_channel *to_channel(RDMAContext *rdma, uint64_t wrid)
{
return wrid < RDMA_WRID_RECV_CONTROL ? rdma->send_comp_channel :
rdma->recv_comp_channel;
}
-static struct ibv_cq *to_cq(RDMAContext *rdma, int wrid)
+static struct ibv_cq *to_cq(RDMAContext *rdma, uint64_t wrid)
{
return wrid < RDMA_WRID_RECV_CONTROL ? rdma->send_cq : rdma->recv_cq;
}
@@ -1641,10 +1610,11 @@
* completions only need to be recorded, but do not actually
* need further processing.
*/
-static int qemu_rdma_block_for_wrid(RDMAContext *rdma, int wrid_requested,
+static int qemu_rdma_block_for_wrid(RDMAContext *rdma,
+ uint64_t wrid_requested,
uint32_t *byte_len)
{
- int num_cq_events = 0, ret = 0;
+ int num_cq_events = 0, ret;
struct ibv_cq *cq;
void *cq_ctx;
uint64_t wr_id = RDMA_WRID_NONE, wr_id_in;
@@ -1658,7 +1628,7 @@
while (wr_id != wrid_requested) {
ret = qemu_rdma_poll(rdma, poll_cq, &wr_id_in, byte_len);
if (ret < 0) {
- return ret;
+ return -1;
}
wr_id = wr_id_in & RDMA_WRID_TYPE_MASK;
@@ -1667,8 +1637,7 @@
break;
}
if (wr_id != wrid_requested) {
- trace_qemu_rdma_block_for_wrid_miss(print_wrid(wrid_requested),
- wrid_requested, print_wrid(wr_id), wr_id);
+ trace_qemu_rdma_block_for_wrid_miss(wrid_requested, wr_id);
}
}
@@ -1678,20 +1647,18 @@
while (1) {
ret = qemu_rdma_wait_comp_channel(rdma, ch);
- if (ret) {
+ if (ret < 0) {
goto err_block_for_wrid;
}
ret = ibv_get_cq_event(ch, &cq, &cq_ctx);
- if (ret) {
- perror("ibv_get_cq_event");
+ if (ret < 0) {
goto err_block_for_wrid;
}
num_cq_events++;
- ret = -ibv_req_notify_cq(cq, 0);
- if (ret) {
+ if (ibv_req_notify_cq(cq, 0)) {
goto err_block_for_wrid;
}
@@ -1707,8 +1674,7 @@
break;
}
if (wr_id != wrid_requested) {
- trace_qemu_rdma_block_for_wrid_miss(print_wrid(wrid_requested),
- wrid_requested, print_wrid(wr_id), wr_id);
+ trace_qemu_rdma_block_for_wrid_miss(wrid_requested, wr_id);
}
}
@@ -1728,8 +1694,8 @@
ibv_ack_cq_events(cq, num_cq_events);
}
- rdma->error_state = ret;
- return ret;
+ rdma->errored = true;
+ return -1;
}
/*
@@ -1737,9 +1703,10 @@
* containing some data and block until the post completes.
*/
static int qemu_rdma_post_send_control(RDMAContext *rdma, uint8_t *buf,
- RDMAControlHeader *head)
+ RDMAControlHeader *head,
+ Error **errp)
{
- int ret = 0;
+ int ret;
RDMAWorkRequestData *wr = &rdma->wr_data[RDMA_WRID_CONTROL];
struct ibv_send_wr *bad_wr;
struct ibv_sge sge = {
@@ -1777,23 +1744,25 @@
ret = ibv_post_send(rdma->qp, &send_wr, &bad_wr);
if (ret > 0) {
- error_report("Failed to use post IB SEND for control");
- return -ret;
+ error_setg(errp, "Failed to use post IB SEND for control");
+ return -1;
}
ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_SEND_CONTROL, NULL);
if (ret < 0) {
- error_report("rdma migration: send polling control error");
+ error_setg(errp, "rdma migration: send polling control error");
+ return -1;
}
- return ret;
+ return 0;
}
/*
* Post a RECV work request in anticipation of some future receipt
* of data on the control channel.
*/
-static int qemu_rdma_post_recv_control(RDMAContext *rdma, int idx)
+static int qemu_rdma_post_recv_control(RDMAContext *rdma, int idx,
+ Error **errp)
{
struct ibv_recv_wr *bad_wr;
struct ibv_sge sge = {
@@ -1810,6 +1779,7 @@
if (ibv_post_recv(rdma->qp, &recv_wr, &bad_wr)) {
+ error_setg(errp, "error posting control recv");
return -1;
}
@@ -1820,15 +1790,16 @@
* Block and wait for a RECV control channel message to arrive.
*/
static int qemu_rdma_exchange_get_response(RDMAContext *rdma,
- RDMAControlHeader *head, int expecting, int idx)
+ RDMAControlHeader *head, uint32_t expecting, int idx,
+ Error **errp)
{
uint32_t byte_len;
int ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RECV_CONTROL + idx,
&byte_len);
if (ret < 0) {
- error_report("rdma migration: recv polling control error!");
- return ret;
+ error_setg(errp, "rdma migration: recv polling control error!");
+ return -1;
}
network_to_control((void *) rdma->wr_data[idx].control);
@@ -1840,22 +1811,23 @@
trace_qemu_rdma_exchange_get_response_none(control_desc(head->type),
head->type);
} else if (head->type != expecting || head->type == RDMA_CONTROL_ERROR) {
- error_report("Was expecting a %s (%d) control message"
+ error_setg(errp, "Was expecting a %s (%d) control message"
", but got: %s (%d), length: %d",
control_desc(expecting), expecting,
control_desc(head->type), head->type, head->len);
if (head->type == RDMA_CONTROL_ERROR) {
rdma->received_error = true;
}
- return -EIO;
+ return -1;
}
if (head->len > RDMA_CONTROL_MAX_BUFFER - sizeof(*head)) {
- error_report("too long length: %d", head->len);
- return -EINVAL;
+ error_setg(errp, "too long length: %d", head->len);
+ return -1;
}
if (sizeof(*head) + head->len != byte_len) {
- error_report("Malformed length: %d byte_len %d", head->len, byte_len);
- return -EINVAL;
+ error_setg(errp, "Malformed length: %d byte_len %d",
+ head->len, byte_len);
+ return -1;
}
return 0;
@@ -1893,9 +1865,11 @@
static int qemu_rdma_exchange_send(RDMAContext *rdma, RDMAControlHeader *head,
uint8_t *data, RDMAControlHeader *resp,
int *resp_idx,
- int (*callback)(RDMAContext *rdma))
+ int (*callback)(RDMAContext *rdma,
+ Error **errp),
+ Error **errp)
{
- int ret = 0;
+ int ret;
/*
* Wait until the dest is ready before attempting to deliver the message
@@ -1906,9 +1880,9 @@
ret = qemu_rdma_exchange_get_response(rdma, &resp_ignored,
RDMA_CONTROL_READY,
- RDMA_WRID_READY);
+ RDMA_WRID_READY, errp);
if (ret < 0) {
- return ret;
+ return -1;
}
}
@@ -1916,31 +1890,27 @@
* If the user is expecting a response, post a WR in anticipation of it.
*/
if (resp) {
- ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_DATA);
- if (ret) {
- error_report("rdma migration: error posting"
- " extra control recv for anticipated result!");
- return ret;
+ ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_DATA, errp);
+ if (ret < 0) {
+ return -1;
}
}
/*
* Post a WR to replace the one we just consumed for the READY message.
*/
- ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY);
- if (ret) {
- error_report("rdma migration: error posting first control recv!");
- return ret;
+ ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY, errp);
+ if (ret < 0) {
+ return -1;
}
/*
* Deliver the control message that was requested.
*/
- ret = qemu_rdma_post_send_control(rdma, data, head);
+ ret = qemu_rdma_post_send_control(rdma, data, head, errp);
if (ret < 0) {
- error_report("Failed to send control buffer!");
- return ret;
+ return -1;
}
/*
@@ -1949,18 +1919,19 @@
if (resp) {
if (callback) {
trace_qemu_rdma_exchange_send_issue_callback();
- ret = callback(rdma);
+ ret = callback(rdma, errp);
if (ret < 0) {
- return ret;
+ return -1;
}
}
trace_qemu_rdma_exchange_send_waiting(control_desc(resp->type));
ret = qemu_rdma_exchange_get_response(rdma, resp,
- resp->type, RDMA_WRID_DATA);
+ resp->type, RDMA_WRID_DATA,
+ errp);
if (ret < 0) {
- return ret;
+ return -1;
}
qemu_rdma_move_header(rdma, RDMA_WRID_DATA, resp);
@@ -1980,7 +1951,7 @@
* control-channel message.
*/
static int qemu_rdma_exchange_recv(RDMAContext *rdma, RDMAControlHeader *head,
- int expecting)
+ uint32_t expecting, Error **errp)
{
RDMAControlHeader ready = {
.len = 0,
@@ -1992,21 +1963,20 @@
/*
* Inform the source that we're ready to receive a message.
*/
- ret = qemu_rdma_post_send_control(rdma, NULL, &ready);
+ ret = qemu_rdma_post_send_control(rdma, NULL, &ready, errp);
if (ret < 0) {
- error_report("Failed to send control buffer!");
- return ret;
+ return -1;
}
/*
* Block and wait for the message.
*/
ret = qemu_rdma_exchange_get_response(rdma, head,
- expecting, RDMA_WRID_READY);
+ expecting, RDMA_WRID_READY, errp);
if (ret < 0) {
- return ret;
+ return -1;
}
qemu_rdma_move_header(rdma, RDMA_WRID_READY, head);
@@ -2014,10 +1984,9 @@
/*
* Post a new RECV work request to replace the one we just consumed.
*/
- ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY);
- if (ret) {
- error_report("rdma migration: error posting second control recv!");
- return ret;
+ ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY, errp);
+ if (ret < 0) {
+ return -1;
}
return 0;
@@ -2031,7 +2000,7 @@
*/
static int qemu_rdma_write_one(RDMAContext *rdma,
int current_index, uint64_t current_addr,
- uint64_t length)
+ uint64_t length, Error **errp)
{
struct ibv_sge sge;
struct ibv_send_wr send_wr = { 0 };
@@ -2086,11 +2055,11 @@
ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL);
if (ret < 0) {
- error_report("Failed to Wait for previous write to complete "
+ error_setg(errp, "Failed to Wait for previous write to complete "
"block %d chunk %" PRIu64
" current %" PRIu64 " len %" PRIu64 " %d",
current_index, chunk, sge.addr, length, rdma->nb_sent);
- return ret;
+ return -1;
}
}
@@ -2118,10 +2087,10 @@
compress_to_network(rdma, &comp);
ret = qemu_rdma_exchange_send(rdma, &head,
- (uint8_t *) &comp, NULL, NULL, NULL);
+ (uint8_t *) &comp, NULL, NULL, NULL, errp);
if (ret < 0) {
- return -EIO;
+ return -1;
}
/*
@@ -2155,17 +2124,17 @@
register_to_network(rdma, ®);
ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) ®,
- &resp, ®_result_idx, NULL);
+ &resp, ®_result_idx, NULL, errp);
if (ret < 0) {
- return ret;
+ return -1;
}
/* try to overlap this single registration with the one we sent. */
if (qemu_rdma_register_and_get_keys(rdma, block, sge.addr,
&sge.lkey, NULL, chunk,
chunk_start, chunk_end)) {
- error_report("cannot get lkey");
- return -EINVAL;
+ error_setg(errp, "cannot get lkey");
+ return -1;
}
reg_result = (RDMARegisterResult *)
@@ -2183,8 +2152,8 @@
if (qemu_rdma_register_and_get_keys(rdma, block, sge.addr,
&sge.lkey, NULL, chunk,
chunk_start, chunk_end)) {
- error_report("cannot get lkey!");
- return -EINVAL;
+ error_setg(errp, "cannot get lkey!");
+ return -1;
}
}
@@ -2195,8 +2164,8 @@
if (qemu_rdma_register_and_get_keys(rdma, block, sge.addr,
&sge.lkey, NULL, chunk,
chunk_start, chunk_end)) {
- error_report("cannot get lkey!");
- return -EINVAL;
+ error_setg(errp, "cannot get lkey!");
+ return -1;
}
}
@@ -2229,16 +2198,17 @@
trace_qemu_rdma_write_one_queue_full();
ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL);
if (ret < 0) {
- error_report("rdma migration: failed to make "
- "room in full send queue! %d", ret);
- return ret;
+ error_setg(errp, "rdma migration: failed to make "
+ "room in full send queue!");
+ return -1;
}
goto retry;
} else if (ret > 0) {
- perror("rdma migration: post rdma write failed");
- return -ret;
+ error_setg_errno(errp, ret,
+ "rdma migration: post rdma write failed");
+ return -1;
}
set_bit(chunk, block->transit_bitmap);
@@ -2265,7 +2235,7 @@
* We support sending out multiple chunks at the same time.
* Not all of them need to get signaled in the completion queue.
*/
-static int qemu_rdma_write_flush(RDMAContext *rdma)
+static int qemu_rdma_write_flush(RDMAContext *rdma, Error **errp)
{
int ret;
@@ -2273,11 +2243,11 @@
return 0;
}
- ret = qemu_rdma_write_one(rdma,
- rdma->current_index, rdma->current_addr, rdma->current_length);
+ ret = qemu_rdma_write_one(rdma, rdma->current_index, rdma->current_addr,
+ rdma->current_length, errp);
if (ret < 0) {
- return ret;
+ return -1;
}
if (ret == 0) {
@@ -2291,7 +2261,7 @@
return 0;
}
-static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
+static inline bool qemu_rdma_buffer_mergeable(RDMAContext *rdma,
uint64_t offset, uint64_t len)
{
RDMALocalBlock *block;
@@ -2299,11 +2269,11 @@
uint8_t *chunk_end;
if (rdma->current_index < 0) {
- return 0;
+ return false;
}
if (rdma->current_chunk < 0) {
- return 0;
+ return false;
}
block = &(rdma->local_ram_blocks.block[rdma->current_index]);
@@ -2311,29 +2281,29 @@
chunk_end = ram_chunk_end(block, rdma->current_chunk);
if (rdma->current_length == 0) {
- return 0;
+ return false;
}
/*
* Only merge into chunk sequentially.
*/
if (offset != (rdma->current_addr + rdma->current_length)) {
- return 0;
+ return false;
}
if (offset < block->offset) {
- return 0;
+ return false;
}
if ((offset + len) > (block->offset + block->length)) {
- return 0;
+ return false;
}
if ((host_addr + len) > chunk_end) {
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/*
@@ -2348,7 +2318,7 @@
*/
static int qemu_rdma_write(RDMAContext *rdma,
uint64_t block_offset, uint64_t offset,
- uint64_t len)
+ uint64_t len, Error **errp)
{
uint64_t current_addr = block_offset + offset;
uint64_t index = rdma->current_index;
@@ -2356,20 +2326,16 @@
int ret;
/* If we cannot merge it, we flush the current buffer first. */
- if (!qemu_rdma_buffer_mergable(rdma, current_addr, len)) {
- ret = qemu_rdma_write_flush(rdma);
- if (ret) {
- return ret;
+ if (!qemu_rdma_buffer_mergeable(rdma, current_addr, len)) {
+ ret = qemu_rdma_write_flush(rdma, errp);
+ if (ret < 0) {
+ return -1;
}
rdma->current_length = 0;
rdma->current_addr = current_addr;
- ret = qemu_rdma_search_ram_block(rdma, block_offset,
- offset, len, &index, &chunk);
- if (ret) {
- error_report("ram block search failed");
- return ret;
- }
+ qemu_rdma_search_ram_block(rdma, block_offset,
+ offset, len, &index, &chunk);
rdma->current_index = index;
rdma->current_chunk = chunk;
}
@@ -2379,7 +2345,7 @@
/* flush it if buffer is too large */
if (rdma->current_length >= RDMA_MERGE_MAX) {
- return qemu_rdma_write_flush(rdma);
+ return qemu_rdma_write_flush(rdma, errp);
}
return 0;
@@ -2387,18 +2353,21 @@
static void qemu_rdma_cleanup(RDMAContext *rdma)
{
+ Error *err = NULL;
int idx;
if (rdma->cm_id && rdma->connected) {
- if ((rdma->error_state ||
+ if ((rdma->errored ||
migrate_get_current()->state == MIGRATION_STATUS_CANCELLING) &&
!rdma->received_error) {
RDMAControlHeader head = { .len = 0,
.type = RDMA_CONTROL_ERROR,
.repeat = 1,
};
- error_report("Early error. Sending error.");
- qemu_rdma_post_send_control(rdma, NULL, &head);
+ warn_report("Early error. Sending error.");
+ if (qemu_rdma_post_send_control(rdma, NULL, &head, &err) < 0) {
+ warn_report_err(err);
+ }
}
rdma_disconnect(rdma->cm_id);
@@ -2484,7 +2453,6 @@
static int qemu_rdma_source_init(RDMAContext *rdma, bool pin_all, Error **errp)
{
int ret, idx;
- Error *local_err = NULL, **temp = &local_err;
/*
* Will be validated against destination's actual capabilities
@@ -2492,30 +2460,23 @@
*/
rdma->pin_all = pin_all;
- ret = qemu_rdma_resolve_host(rdma, temp);
- if (ret) {
+ ret = qemu_rdma_resolve_host(rdma, errp);
+ if (ret < 0) {
goto err_rdma_source_init;
}
- ret = qemu_rdma_alloc_pd_cq(rdma);
- if (ret) {
- ERROR(temp, "rdma migration: error allocating pd and cq! Your mlock()"
- " limits may be too low. Please check $ ulimit -a # and "
- "search for 'ulimit -l' in the output");
+ ret = qemu_rdma_alloc_pd_cq(rdma, errp);
+ if (ret < 0) {
goto err_rdma_source_init;
}
ret = qemu_rdma_alloc_qp(rdma);
- if (ret) {
- ERROR(temp, "rdma migration: error allocating qp!");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: rdma migration: error allocating qp!");
goto err_rdma_source_init;
}
- ret = qemu_rdma_init_ram_blocks(rdma);
- if (ret) {
- ERROR(temp, "rdma migration: error initializing ram blocks!");
- goto err_rdma_source_init;
- }
+ qemu_rdma_init_ram_blocks(rdma);
/* Build the hash that maps from offset to RAMBlock */
rdma->blockmap = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -2527,9 +2488,10 @@
for (idx = 0; idx < RDMA_WRID_MAX; idx++) {
ret = qemu_rdma_reg_control(rdma, idx);
- if (ret) {
- ERROR(temp, "rdma migration: error registering %d control!",
- idx);
+ if (ret < 0) {
+ error_setg(errp,
+ "RDMA ERROR: rdma migration: error registering %d control!",
+ idx);
goto err_rdma_source_init;
}
}
@@ -2537,7 +2499,6 @@
return 0;
err_rdma_source_init:
- error_propagate(errp, local_err);
qemu_rdma_cleanup(rdma);
return -1;
}
@@ -2558,20 +2519,27 @@
} while (ret < 0 && errno == EINTR);
if (ret == 0) {
- ERROR(errp, "poll cm event timeout");
+ error_setg(errp, "RDMA ERROR: poll cm event timeout");
return -1;
} else if (ret < 0) {
- ERROR(errp, "failed to poll cm event, errno=%i", errno);
+ error_setg(errp, "RDMA ERROR: failed to poll cm event, errno=%i",
+ errno);
return -1;
} else if (poll_fd.revents & POLLIN) {
- return rdma_get_cm_event(rdma->channel, cm_event);
+ if (rdma_get_cm_event(rdma->channel, cm_event) < 0) {
+ error_setg(errp, "RDMA ERROR: failed to get cm event");
+ return -1;
+ }
+ return 0;
} else {
- ERROR(errp, "no POLLIN event, revent=%x", poll_fd.revents);
+ error_setg(errp, "RDMA ERROR: no POLLIN event, revent=%x",
+ poll_fd.revents);
return -1;
}
}
-static int qemu_rdma_connect(RDMAContext *rdma, Error **errp, bool return_path)
+static int qemu_rdma_connect(RDMAContext *rdma, bool return_path,
+ Error **errp)
{
RDMACapabilities cap = {
.version = RDMA_CONTROL_VERSION_CURRENT,
@@ -2596,16 +2564,15 @@
caps_to_network(&cap);
- ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY);
- if (ret) {
- ERROR(errp, "posting second control recv");
+ ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY, errp);
+ if (ret < 0) {
goto err_rdma_source_connect;
}
ret = rdma_connect(rdma->cm_id, &conn_param);
- if (ret) {
- perror("rdma_connect");
- ERROR(errp, "connecting to destination!");
+ if (ret < 0) {
+ error_setg_errno(errp, errno,
+ "RDMA ERROR: connecting to destination!");
goto err_rdma_source_connect;
}
@@ -2613,16 +2580,17 @@
ret = qemu_get_cm_event_timeout(rdma, &cm_event, 5000, errp);
} else {
ret = rdma_get_cm_event(rdma->channel, &cm_event);
+ if (ret < 0) {
+ error_setg_errno(errp, errno,
+ "RDMA ERROR: failed to get cm event");
+ }
}
- if (ret) {
- perror("rdma_get_cm_event after rdma_connect");
- ERROR(errp, "connecting to destination!");
+ if (ret < 0) {
goto err_rdma_source_connect;
}
if (cm_event->event != RDMA_CM_EVENT_ESTABLISHED) {
- error_report("rdma_get_cm_event != EVENT_ESTABLISHED after rdma_connect");
- ERROR(errp, "connecting to destination!");
+ error_setg(errp, "RDMA ERROR: connecting to destination!");
rdma_ack_cm_event(cm_event);
goto err_rdma_source_connect;
}
@@ -2636,8 +2604,8 @@
* and disable them otherwise.
*/
if (rdma->pin_all && !(cap.flags & RDMA_CAPABILITY_PIN_ALL)) {
- ERROR(errp, "Server cannot support pinning all memory. "
- "Will register memory dynamically.");
+ warn_report("RDMA: Server cannot support pinning all memory. "
+ "Will register memory dynamically.");
rdma->pin_all = false;
}
@@ -2656,6 +2624,7 @@
static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
{
+ Error *err = NULL;
int ret, idx;
struct rdma_cm_id *listen_id;
char ip[40] = "unknown";
@@ -2669,22 +2638,22 @@
}
if (!rdma->host || !rdma->host[0]) {
- ERROR(errp, "RDMA host is not set!");
- rdma->error_state = -EINVAL;
+ error_setg(errp, "RDMA ERROR: RDMA host is not set!");
+ rdma->errored = true;
return -1;
}
/* create CM channel */
rdma->channel = rdma_create_event_channel();
if (!rdma->channel) {
- ERROR(errp, "could not create rdma event channel");
- rdma->error_state = -EINVAL;
+ error_setg(errp, "RDMA ERROR: could not create rdma event channel");
+ rdma->errored = true;
return -1;
}
/* create CM id */
ret = rdma_create_id(rdma->channel, &listen_id, NULL, RDMA_PS_TCP);
- if (ret) {
- ERROR(errp, "could not create cm_id!");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: could not create cm_id!");
goto err_dest_init_create_listen_id;
}
@@ -2692,37 +2661,48 @@
port_str[15] = '\0';
ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res);
- if (ret < 0) {
- ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host);
+ if (ret) {
+ error_setg(errp, "RDMA ERROR: could not rdma_getaddrinfo address %s",
+ rdma->host);
goto err_dest_init_bind_addr;
}
ret = rdma_set_option(listen_id, RDMA_OPTION_ID, RDMA_OPTION_ID_REUSEADDR,
&reuse, sizeof reuse);
- if (ret) {
- ERROR(errp, "Error: could not set REUSEADDR option");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: Error: could not set REUSEADDR option");
goto err_dest_init_bind_addr;
}
+
+ /* Try all addresses, saving the first error in @err */
for (e = res; e != NULL; e = e->ai_next) {
+ Error **local_errp = err ? NULL : &err;
+
inet_ntop(e->ai_family,
&((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip);
trace_qemu_rdma_dest_init_trying(rdma->host, ip);
ret = rdma_bind_addr(listen_id, e->ai_dst_addr);
- if (ret) {
+ if (ret < 0) {
continue;
}
if (e->ai_family == AF_INET6) {
- ret = qemu_rdma_broken_ipv6_kernel(listen_id->verbs, errp);
- if (ret) {
+ ret = qemu_rdma_broken_ipv6_kernel(listen_id->verbs,
+ local_errp);
+ if (ret < 0) {
continue;
}
}
+ error_free(err);
break;
}
rdma_freeaddrinfo(res);
if (!e) {
- ERROR(errp, "Error: could not rdma_bind_addr!");
+ if (err) {
+ error_propagate(errp, err);
+ } else {
+ error_setg(errp, "RDMA ERROR: Error: could not rdma_bind_addr!");
+ }
goto err_dest_init_bind_addr;
}
@@ -2735,8 +2715,8 @@
err_dest_init_create_listen_id:
rdma_destroy_event_channel(rdma->channel);
rdma->channel = NULL;
- rdma->error_state = ret;
- return ret;
+ rdma->errored = true;
+ return -1;
}
@@ -2759,30 +2739,28 @@
rdma_return_path->is_return_path = true;
}
-static void *qemu_rdma_data_init(const char *host_port, Error **errp)
+static RDMAContext *qemu_rdma_data_init(const char *host_port, Error **errp)
{
RDMAContext *rdma = NULL;
InetSocketAddress *addr;
- if (host_port) {
- rdma = g_new0(RDMAContext, 1);
- rdma->current_index = -1;
- rdma->current_chunk = -1;
+ rdma = g_new0(RDMAContext, 1);
+ rdma->current_index = -1;
+ rdma->current_chunk = -1;
- addr = g_new(InetSocketAddress, 1);
- if (!inet_parse(addr, host_port, NULL)) {
- rdma->port = atoi(addr->port);
- rdma->host = g_strdup(addr->host);
- rdma->host_port = g_strdup(host_port);
- } else {
- ERROR(errp, "bad RDMA migration address '%s'", host_port);
- g_free(rdma);
- rdma = NULL;
- }
-
- qapi_free_InetSocketAddress(addr);
+ addr = g_new(InetSocketAddress, 1);
+ if (!inet_parse(addr, host_port, NULL)) {
+ rdma->port = atoi(addr->port);
+ rdma->host = g_strdup(addr->host);
+ rdma->host_port = g_strdup(host_port);
+ } else {
+ error_setg(errp, "RDMA ERROR: bad RDMA migration address '%s'",
+ host_port);
+ g_free(rdma);
+ rdma = NULL;
}
+ qapi_free_InetSocketAddress(addr);
return rdma;
}
@@ -2803,8 +2781,7 @@
RDMAContext *rdma;
int ret;
ssize_t done = 0;
- size_t i;
- size_t len = 0;
+ size_t i, len;
RCU_READ_LOCK_GUARD();
rdma = qatomic_rcu_read(&rioc->rdmaout);
@@ -2814,16 +2791,19 @@
return -1;
}
- CHECK_ERROR_STATE();
+ if (rdma->errored) {
+ error_setg(errp,
+ "RDMA is in an error state waiting migration to abort!");
+ return -1;
+ }
/*
* Push out any writes that
* we're queued up for VM's ram.
*/
- ret = qemu_rdma_write_flush(rdma);
+ ret = qemu_rdma_write_flush(rdma, errp);
if (ret < 0) {
- rdma->error_state = ret;
- error_setg(errp, "qemu_rdma_write_flush returned %d", ret);
+ rdma->errored = true;
return -1;
}
@@ -2839,11 +2819,11 @@
head.len = len;
head.type = RDMA_CONTROL_QEMU_FILE;
- ret = qemu_rdma_exchange_send(rdma, &head, data, NULL, NULL, NULL);
+ ret = qemu_rdma_exchange_send(rdma, &head,
+ data, NULL, NULL, NULL, errp);
if (ret < 0) {
- rdma->error_state = ret;
- error_setg(errp, "qemu_rdma_exchange_send returned %d", ret);
+ rdma->errored = true;
return -1;
}
@@ -2888,9 +2868,9 @@
QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(ioc);
RDMAContext *rdma;
RDMAControlHeader head;
- int ret = 0;
- ssize_t i;
- size_t done = 0;
+ int ret;
+ ssize_t done = 0;
+ size_t i, len;
RCU_READ_LOCK_GUARD();
rdma = qatomic_rcu_read(&rioc->rdmain);
@@ -2900,7 +2880,11 @@
return -1;
}
- CHECK_ERROR_STATE();
+ if (rdma->errored) {
+ error_setg(errp,
+ "RDMA is in an error state waiting migration to abort!");
+ return -1;
+ }
for (i = 0; i < niov; i++) {
size_t want = iov[i].iov_len;
@@ -2911,9 +2895,9 @@
* were given and dish out the bytes until we run
* out of bytes.
*/
- ret = qemu_rdma_fill(rdma, data, want, 0);
- done += ret;
- want -= ret;
+ len = qemu_rdma_fill(rdma, data, want, 0);
+ done += len;
+ want -= len;
/* Got what we needed, so go to next iovec */
if (want == 0) {
continue;
@@ -2929,20 +2913,20 @@
/* We've got nothing at all, so lets wait for
* more to arrive
*/
- ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_QEMU_FILE);
+ ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_QEMU_FILE,
+ errp);
if (ret < 0) {
- rdma->error_state = ret;
- error_setg(errp, "qemu_rdma_exchange_recv returned %d", ret);
+ rdma->errored = true;
return -1;
}
/*
* SEND was received with new bytes, now try again.
*/
- ret = qemu_rdma_fill(rdma, data, want, 0);
- done += ret;
- want -= ret;
+ len = qemu_rdma_fill(rdma, data, want, 0);
+ done += len;
+ want -= len;
/* Still didn't get enough, so lets just return */
if (want) {
@@ -2961,17 +2945,19 @@
*/
static int qemu_rdma_drain_cq(RDMAContext *rdma)
{
+ Error *err = NULL;
int ret;
- if (qemu_rdma_write_flush(rdma) < 0) {
- return -EIO;
+ if (qemu_rdma_write_flush(rdma, &err) < 0) {
+ error_report_err(err);
+ return -1;
}
while (rdma->nb_sent) {
ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL);
if (ret < 0) {
error_report("rdma migration: complete polling error!");
- return -EIO;
+ return -1;
}
}
@@ -3095,7 +3081,7 @@
object_unref(OBJECT(ssource->rioc));
}
-GSourceFuncs qio_channel_rdma_source_funcs = {
+static GSourceFuncs qio_channel_rdma_source_funcs = {
qio_channel_rdma_source_prepare,
qio_channel_rdma_source_check,
qio_channel_rdma_source_dispatch,
@@ -3206,21 +3192,21 @@
switch (how) {
case QIO_CHANNEL_SHUTDOWN_READ:
if (rdmain) {
- rdmain->error_state = -1;
+ rdmain->errored = true;
}
break;
case QIO_CHANNEL_SHUTDOWN_WRITE:
if (rdmaout) {
- rdmaout->error_state = -1;
+ rdmaout->errored = true;
}
break;
case QIO_CHANNEL_SHUTDOWN_BOTH:
default:
if (rdmain) {
- rdmain->error_state = -1;
+ rdmain->errored = true;
}
if (rdmaout) {
- rdmaout->error_state = -1;
+ rdmaout->errored = true;
}
break;
}
@@ -3250,6 +3236,7 @@
ram_addr_t offset, size_t size)
{
QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
+ Error *err = NULL;
RDMAContext *rdma;
int ret;
@@ -3261,10 +3248,12 @@
rdma = qatomic_rcu_read(&rioc->rdmaout);
if (!rdma) {
- return -EIO;
+ return -1;
}
- CHECK_ERROR_STATE();
+ if (rdma_errored(rdma)) {
+ return -1;
+ }
qemu_fflush(f);
@@ -3273,9 +3262,9 @@
* is full, or the page doesn't belong to the current chunk,
* an actual RDMA write will occur and a new chunk will be formed.
*/
- ret = qemu_rdma_write(rdma, block_offset, offset, size);
+ ret = qemu_rdma_write(rdma, block_offset, offset, size, &err);
if (ret < 0) {
- error_report("rdma migration: write error! %d", ret);
+ error_report_err(err);
goto err;
}
@@ -3291,7 +3280,7 @@
ret = qemu_rdma_poll(rdma, rdma->recv_cq, &wr_id_in, NULL);
if (ret < 0) {
- error_report("rdma migration: polling error! %d", ret);
+ error_report("rdma migration: polling error");
goto err;
}
@@ -3307,7 +3296,7 @@
ret = qemu_rdma_poll(rdma, rdma->send_cq, &wr_id_in, NULL);
if (ret < 0) {
- error_report("rdma migration: polling error! %d", ret);
+ error_report("rdma migration: polling error");
goto err;
}
@@ -3319,9 +3308,10 @@
}
return RAM_SAVE_CONTROL_DELAYED;
+
err:
- rdma->error_state = ret;
- return ret;
+ rdma->errored = true;
+ return -1;
}
static void rdma_accept_incoming_migration(void *opaque);
@@ -3334,20 +3324,20 @@
MigrationIncomingState *mis = migration_incoming_get_current();
ret = rdma_get_cm_event(rdma->channel, &cm_event);
- if (ret) {
+ if (ret < 0) {
error_report("get_cm_event failed %d", errno);
return;
}
if (cm_event->event == RDMA_CM_EVENT_DISCONNECTED ||
cm_event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) {
- if (!rdma->error_state &&
+ if (!rdma->errored &&
migration_incoming_get_current()->state !=
MIGRATION_STATUS_COMPLETED) {
error_report("receive cm event, cm event is %d", cm_event->event);
- rdma->error_state = -EPIPE;
+ rdma->errored = true;
if (rdma->return_path) {
- rdma->return_path->error_state = -EPIPE;
+ rdma->return_path->errored = true;
}
}
rdma_ack_cm_event(cm_event);
@@ -3361,6 +3351,7 @@
static int qemu_rdma_accept(RDMAContext *rdma)
{
+ Error *err = NULL;
RDMACapabilities cap;
struct rdma_conn_param conn_param = {
.responder_resources = 2,
@@ -3370,11 +3361,11 @@
RDMAContext *rdma_return_path = NULL;
struct rdma_cm_event *cm_event;
struct ibv_context *verbs;
- int ret = -EINVAL;
+ int ret;
int idx;
ret = rdma_get_cm_event(rdma->channel, &cm_event);
- if (ret) {
+ if (ret < 0) {
goto err_rdma_dest_wait;
}
@@ -3403,10 +3394,10 @@
network_to_caps(&cap);
if (cap.version < 1 || cap.version > RDMA_CONTROL_VERSION_CURRENT) {
- error_report("Unknown source RDMA version: %d, bailing...",
- cap.version);
- rdma_ack_cm_event(cm_event);
- goto err_rdma_dest_wait;
+ error_report("Unknown source RDMA version: %d, bailing...",
+ cap.version);
+ rdma_ack_cm_event(cm_event);
+ goto err_rdma_dest_wait;
}
/*
@@ -3436,34 +3427,30 @@
if (!rdma->verbs) {
rdma->verbs = verbs;
} else if (rdma->verbs != verbs) {
- error_report("ibv context not matching %p, %p!", rdma->verbs,
- verbs);
- goto err_rdma_dest_wait;
+ error_report("ibv context not matching %p, %p!", rdma->verbs,
+ verbs);
+ goto err_rdma_dest_wait;
}
qemu_rdma_dump_id("dest_init", verbs);
- ret = qemu_rdma_alloc_pd_cq(rdma);
- if (ret) {
- error_report("rdma migration: error allocating pd and cq!");
+ ret = qemu_rdma_alloc_pd_cq(rdma, &err);
+ if (ret < 0) {
+ error_report_err(err);
goto err_rdma_dest_wait;
}
ret = qemu_rdma_alloc_qp(rdma);
- if (ret) {
+ if (ret < 0) {
error_report("rdma migration: error allocating qp!");
goto err_rdma_dest_wait;
}
- ret = qemu_rdma_init_ram_blocks(rdma);
- if (ret) {
- error_report("rdma migration: error initializing ram blocks!");
- goto err_rdma_dest_wait;
- }
+ qemu_rdma_init_ram_blocks(rdma);
for (idx = 0; idx < RDMA_WRID_MAX; idx++) {
ret = qemu_rdma_reg_control(rdma, idx);
- if (ret) {
+ if (ret < 0) {
error_report("rdma: error registering %d control", idx);
goto err_rdma_dest_wait;
}
@@ -3481,14 +3468,14 @@
}
ret = rdma_accept(rdma->cm_id, &conn_param);
- if (ret) {
- error_report("rdma_accept returns %d", ret);
+ if (ret < 0) {
+ error_report("rdma_accept failed");
goto err_rdma_dest_wait;
}
ret = rdma_get_cm_event(rdma->channel, &cm_event);
- if (ret) {
- error_report("rdma_accept get_cm_event failed %d", ret);
+ if (ret < 0) {
+ error_report("rdma_accept get_cm_event failed");
goto err_rdma_dest_wait;
}
@@ -3501,9 +3488,9 @@
rdma_ack_cm_event(cm_event);
rdma->connected = true;
- ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY);
- if (ret) {
- error_report("rdma migration: error posting second control recv");
+ ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY, &err);
+ if (ret < 0) {
+ error_report_err(err);
goto err_rdma_dest_wait;
}
@@ -3512,10 +3499,10 @@
return 0;
err_rdma_dest_wait:
- rdma->error_state = ret;
+ rdma->errored = true;
qemu_rdma_cleanup(rdma);
g_free(rdma_return_path);
- return ret;
+ return -1;
}
static int dest_ram_sort_func(const void *a, const void *b)
@@ -3548,6 +3535,7 @@
RDMAControlHeader blocks = { .type = RDMA_CONTROL_RAM_BLOCKS_RESULT,
.repeat = 1 };
QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
+ Error *err = NULL;
RDMAContext *rdma;
RDMALocalBlocks *local;
RDMAControlHeader head;
@@ -3557,7 +3545,7 @@
static RDMARegisterResult results[RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE];
RDMALocalBlock *block;
void *host_addr;
- int ret = 0;
+ int ret;
int idx = 0;
int count = 0;
int i = 0;
@@ -3566,25 +3554,27 @@
rdma = qatomic_rcu_read(&rioc->rdmain);
if (!rdma) {
- return -EIO;
+ return -1;
}
- CHECK_ERROR_STATE();
+ if (rdma_errored(rdma)) {
+ return -1;
+ }
local = &rdma->local_ram_blocks;
do {
trace_qemu_rdma_registration_handle_wait();
- ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_NONE);
+ ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_NONE, &err);
if (ret < 0) {
+ error_report_err(err);
break;
}
if (head.repeat > RDMA_CONTROL_MAX_COMMANDS_PER_MESSAGE) {
error_report("rdma: Too many requests in this message (%d)."
"Bailing.", head.repeat);
- ret = -EIO;
break;
}
@@ -3600,8 +3590,7 @@
error_report("rdma: 'compress' bad block index %u (vs %d)",
(unsigned int)comp->block_idx,
rdma->local_ram_blocks.nb_blocks);
- ret = -EIO;
- goto out;
+ goto err;
}
block = &(rdma->local_ram_blocks.block[comp->block_idx]);
@@ -3613,7 +3602,7 @@
case RDMA_CONTROL_REGISTER_FINISHED:
trace_qemu_rdma_registration_handle_finished();
- goto out;
+ return 0;
case RDMA_CONTROL_RAM_BLOCKS_REQUEST:
trace_qemu_rdma_registration_handle_ram_blocks();
@@ -3630,11 +3619,10 @@
}
if (rdma->pin_all) {
- ret = qemu_rdma_reg_whole_ram_blocks(rdma);
- if (ret) {
- error_report("rdma migration: error dest "
- "registering ram blocks");
- goto out;
+ ret = qemu_rdma_reg_whole_ram_blocks(rdma, &err);
+ if (ret < 0) {
+ error_report_err(err);
+ goto err;
}
}
@@ -3669,11 +3657,12 @@
ret = qemu_rdma_post_send_control(rdma,
- (uint8_t *) rdma->dest_blocks, &blocks);
+ (uint8_t *) rdma->dest_blocks, &blocks,
+ &err);
if (ret < 0) {
- error_report("rdma migration: error sending remote info");
- goto out;
+ error_report_err(err);
+ goto err;
}
break;
@@ -3699,8 +3688,7 @@
error_report("rdma: 'register' bad block index %u (vs %d)",
(unsigned int)reg->current_index,
rdma->local_ram_blocks.nb_blocks);
- ret = -ENOENT;
- goto out;
+ goto err;
}
block = &(rdma->local_ram_blocks.block[reg->current_index]);
if (block->is_ram_block) {
@@ -3709,8 +3697,7 @@
" offset: %" PRIx64 " current_addr: %" PRIx64,
block->block_name, block->offset,
reg->key.current_addr);
- ret = -ERANGE;
- goto out;
+ goto err;
}
host_addr = (block->local_host_addr +
(reg->key.current_addr - block->offset));
@@ -3725,8 +3712,7 @@
error_report("rdma: bad chunk for block %s"
" chunk: %" PRIx64,
block->block_name, reg->key.chunk);
- ret = -ERANGE;
- goto out;
+ goto err;
}
}
chunk_start = ram_chunk_start(block, chunk);
@@ -3737,8 +3723,7 @@
(uintptr_t)host_addr, NULL, &tmp_rkey,
chunk, chunk_start, chunk_end)) {
error_report("cannot get rkey");
- ret = -EINVAL;
- goto out;
+ goto err;
}
reg_result->rkey = tmp_rkey;
@@ -3751,11 +3736,11 @@
}
ret = qemu_rdma_post_send_control(rdma,
- (uint8_t *) results, ®_resp);
+ (uint8_t *) results, ®_resp, &err);
if (ret < 0) {
- error_report("Failed to send control buffer");
- goto out;
+ error_report_err(err);
+ goto err;
}
break;
case RDMA_CONTROL_UNREGISTER_REQUEST:
@@ -3776,9 +3761,9 @@
block->pmr[reg->key.chunk] = NULL;
if (ret != 0) {
- perror("rdma unregistration chunk failed");
- ret = -ret;
- goto out;
+ error_report("rdma unregistration chunk failed: %s",
+ strerror(errno));
+ goto err;
}
rdma->total_registrations--;
@@ -3787,28 +3772,25 @@
reg->key.chunk);
}
- ret = qemu_rdma_post_send_control(rdma, NULL, &unreg_resp);
+ ret = qemu_rdma_post_send_control(rdma, NULL, &unreg_resp, &err);
if (ret < 0) {
- error_report("Failed to send control buffer");
- goto out;
+ error_report_err(err);
+ goto err;
}
break;
case RDMA_CONTROL_REGISTER_RESULT:
error_report("Invalid RESULT message at dest.");
- ret = -EIO;
- goto out;
+ goto err;
default:
error_report("Unknown control message %s", control_desc(head.type));
- ret = -EIO;
- goto out;
+ goto err;
}
} while (1);
-out:
- if (ret < 0) {
- rdma->error_state = ret;
- }
- return ret;
+
+err:
+ rdma->errored = true;
+ return -1;
}
/* Destination:
@@ -3830,7 +3812,7 @@
rdma = qatomic_rcu_read(&rioc->rdmain);
if (!rdma) {
- return -EIO;
+ return -1;
}
/* Find the matching RAMBlock in our local list */
@@ -3843,7 +3825,7 @@
if (found == -1) {
error_report("RAMBlock '%s' not found on destination", name);
- return -ENOENT;
+ return -1;
}
rdma->local_ram_blocks.block[curr].src_index = rdma->next_src_index;
@@ -3881,10 +3863,12 @@
RCU_READ_LOCK_GUARD();
rdma = qatomic_rcu_read(&rioc->rdmaout);
if (!rdma) {
- return -EIO;
+ return -1;
}
- CHECK_ERROR_STATE();
+ if (rdma_errored(rdma)) {
+ return -1;
+ }
trace_qemu_rdma_registration_start(flags);
qemu_put_be64(f, RAM_SAVE_FLAG_HOOK);
@@ -3901,9 +3885,10 @@
uint64_t flags, void *data)
{
QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
+ Error *err = NULL;
RDMAContext *rdma;
RDMAControlHeader head = { .len = 0, .repeat = 1 };
- int ret = 0;
+ int ret;
if (migration_in_postcopy()) {
return 0;
@@ -3912,10 +3897,12 @@
RCU_READ_LOCK_GUARD();
rdma = qatomic_rcu_read(&rioc->rdmaout);
if (!rdma) {
- return -EIO;
+ return -1;
}
- CHECK_ERROR_STATE();
+ if (rdma_errored(rdma)) {
+ return -1;
+ }
qemu_fflush(f);
ret = qemu_rdma_drain_cq(rdma);
@@ -3942,10 +3929,11 @@
*/
ret = qemu_rdma_exchange_send(rdma, &head, NULL, &resp,
®_result_idx, rdma->pin_all ?
- qemu_rdma_reg_whole_ram_blocks : NULL);
+ qemu_rdma_reg_whole_ram_blocks : NULL,
+ &err);
if (ret < 0) {
- fprintf(stderr, "receiving remote info!");
- return ret;
+ error_report_err(err);
+ return -1;
}
nb_dest_blocks = resp.len / sizeof(RDMADestBlock);
@@ -3963,12 +3951,12 @@
*/
if (local->nb_blocks != nb_dest_blocks) {
- fprintf(stderr, "ram blocks mismatch (Number of blocks %d vs %d) "
- "Your QEMU command line parameters are probably "
- "not identical on both the source and destination.",
- local->nb_blocks, nb_dest_blocks);
- rdma->error_state = -EINVAL;
- return -EINVAL;
+ error_report("ram blocks mismatch (Number of blocks %d vs %d)",
+ local->nb_blocks, nb_dest_blocks);
+ error_printf("Your QEMU command line parameters are probably "
+ "not identical on both the source and destination.");
+ rdma->errored = true;
+ return -1;
}
qemu_rdma_move_header(rdma, reg_result_idx, &resp);
@@ -3979,12 +3967,13 @@
/* We require that the blocks are in the same order */
if (rdma->dest_blocks[i].length != local->block[i].length) {
- fprintf(stderr, "Block %s/%d has a different length %" PRIu64
- "vs %" PRIu64, local->block[i].block_name, i,
- local->block[i].length,
- rdma->dest_blocks[i].length);
- rdma->error_state = -EINVAL;
- return -EINVAL;
+ error_report("Block %s/%d has a different length %" PRIu64
+ "vs %" PRIu64,
+ local->block[i].block_name, i,
+ local->block[i].length,
+ rdma->dest_blocks[i].length);
+ rdma->errored = true;
+ return -1;
}
local->block[i].remote_host_addr =
rdma->dest_blocks[i].remote_host_addr;
@@ -3995,16 +3984,17 @@
trace_qemu_rdma_registration_stop(flags);
head.type = RDMA_CONTROL_REGISTER_FINISHED;
- ret = qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL);
+ ret = qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL, &err);
if (ret < 0) {
+ error_report_err(err);
goto err;
}
return 0;
err:
- rdma->error_state = ret;
- return ret;
+ rdma->errored = true;
+ return -1;
}
static const QEMUFileHooks rdma_read_hooks = {
@@ -4096,8 +4086,8 @@
trace_qemu_rdma_accept_incoming_migration();
ret = qemu_rdma_accept(rdma);
- if (ret) {
- fprintf(stderr, "RDMA ERROR: Migration initialization failed\n");
+ if (ret < 0) {
+ error_report("RDMA ERROR: Migration initialization failed");
return;
}
@@ -4109,7 +4099,7 @@
f = rdma_new_input(rdma);
if (f == NULL) {
- fprintf(stderr, "RDMA ERROR: could not open RDMA for input\n");
+ error_report("RDMA ERROR: could not open RDMA for input");
qemu_rdma_cleanup(rdma);
return;
}
@@ -4125,7 +4115,6 @@
{
int ret;
RDMAContext *rdma;
- Error *local_err = NULL;
trace_rdma_start_incoming_migration();
@@ -4135,14 +4124,13 @@
return;
}
- rdma = qemu_rdma_data_init(host_port, &local_err);
+ rdma = qemu_rdma_data_init(host_port, errp);
if (rdma == NULL) {
goto err;
}
- ret = qemu_rdma_dest_init(rdma, &local_err);
-
- if (ret) {
+ ret = qemu_rdma_dest_init(rdma, errp);
+ if (ret < 0) {
goto err;
}
@@ -4150,8 +4138,8 @@
ret = rdma_listen(rdma->listen_id, 5);
- if (ret) {
- ERROR(errp, "listening on socket!");
+ if (ret < 0) {
+ error_setg(errp, "RDMA ERROR: listening on socket!");
goto cleanup_rdma;
}
@@ -4164,7 +4152,6 @@
cleanup_rdma:
qemu_rdma_cleanup(rdma);
err:
- error_propagate(errp, local_err);
if (rdma) {
g_free(rdma->host);
g_free(rdma->host_port);
@@ -4178,7 +4165,7 @@
MigrationState *s = opaque;
RDMAContext *rdma_return_path = NULL;
RDMAContext *rdma;
- int ret = 0;
+ int ret;
/* Avoid ram_block_discard_disable(), cannot change during migration. */
if (ram_block_discard_is_required()) {
@@ -4193,14 +4180,14 @@
ret = qemu_rdma_source_init(rdma, migrate_rdma_pin_all(), errp);
- if (ret) {
+ if (ret < 0) {
goto err;
}
trace_rdma_start_outgoing_migration_after_rdma_source_init();
- ret = qemu_rdma_connect(rdma, errp, false);
+ ret = qemu_rdma_connect(rdma, false, errp);
- if (ret) {
+ if (ret < 0) {
goto err;
}
@@ -4215,13 +4202,13 @@
ret = qemu_rdma_source_init(rdma_return_path,
migrate_rdma_pin_all(), errp);
- if (ret) {
+ if (ret < 0) {
goto return_path_err;
}
- ret = qemu_rdma_connect(rdma_return_path, errp, true);
+ ret = qemu_rdma_connect(rdma_return_path, true, errp);
- if (ret) {
+ if (ret < 0) {
goto return_path_err;
}
diff --git a/migration/savevm.c b/migration/savevm.c
index 60eec7c..497ce02 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -2734,7 +2734,8 @@
qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex);
}
- migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE,
+ /* Current state can be either ACTIVE or RECOVER */
+ migrate_set_state(&mis->state, mis->state,
MIGRATION_STATUS_POSTCOPY_PAUSED);
/* Notify the fault thread for the invalidated file handle */
diff --git a/migration/trace-events b/migration/trace-events
index 002abe3..ee9c8f4 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -208,12 +208,14 @@
qemu_rdma_accept_incoming_migration_accepted(void) ""
qemu_rdma_accept_pin_state(bool pin) "%d"
qemu_rdma_accept_pin_verbsc(void *verbs) "Verbs context after listen: %p"
-qemu_rdma_block_for_wrid_miss(const char *wcompstr, int wcomp, const char *gcompstr, uint64_t req) "A Wanted wrid %s (%d) but got %s (%" PRIu64 ")"
+qemu_rdma_block_for_wrid_miss(uint64_t wcomp, uint64_t req) "A Wanted wrid %" PRIu64 " but got %" PRIu64
qemu_rdma_cleanup_disconnect(void) ""
qemu_rdma_close(void) ""
qemu_rdma_connect_pin_all_requested(void) ""
qemu_rdma_connect_pin_all_outcome(bool pin) "%d"
qemu_rdma_dest_init_trying(const char *host, const char *ip) "%s => %s"
+qemu_rdma_dump_id_failed(const char *who) "%s RDMA Device opened, but can't query port information"
+qemu_rdma_dump_id(const char *who, const char *name, const char *dev_name, const char *dev_path, const char *ibdev_path, int transport, const char *transport_name) "%s RDMA Device opened: kernel name %s uverbs device name %s, infiniband_verbs class device path %s, infiniband class device path %s, transport: (%d) %s"
qemu_rdma_dump_gid(const char *who, const char *src, const char *dst) "%s Source GID: %s, Dest GID: %s"
qemu_rdma_exchange_get_response_start(const char *desc) "CONTROL: %s receiving..."
qemu_rdma_exchange_get_response_none(const char *desc, int type) "Surprise: got %s (%d)"
@@ -222,9 +224,9 @@
qemu_rdma_exchange_send_received(const char *desc) "Response %s received."
qemu_rdma_fill(size_t control_len, size_t size) "RDMA %zd of %zd bytes already in buffer"
qemu_rdma_init_ram_blocks(int blocks) "Allocated %d local ram block structures"
-qemu_rdma_poll_recv(const char *compstr, int64_t comp, int64_t id, int sent) "completion %s #%" PRId64 " received (%" PRId64 ") left %d"
-qemu_rdma_poll_write(const char *compstr, int64_t comp, int left, uint64_t block, uint64_t chunk, void *local, void *remote) "completions %s (%" PRId64 ") left %d, block %" PRIu64 ", chunk: %" PRIu64 " %p %p"
-qemu_rdma_poll_other(const char *compstr, int64_t comp, int left) "other completion %s (%" PRId64 ") received left %d"
+qemu_rdma_poll_recv(uint64_t comp, int64_t id, int sent) "completion %" PRIu64 " received (%" PRId64 ") left %d"
+qemu_rdma_poll_write(uint64_t comp, int left, uint64_t block, uint64_t chunk, void *local, void *remote) "completions %" PRIu64 " left %d, block %" PRIu64 ", chunk: %" PRIu64 " %p %p"
+qemu_rdma_poll_other(uint64_t comp, int left) "other completion %" PRIu64 " received left %d"
qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.."
qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %" PRIu64 " bytes @ %p"
qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Paging memory region: %s"
diff --git a/plugins/core.c b/plugins/core.c
index 3c4e26c..fcd33a2 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -64,7 +64,7 @@
CPUState *cpu = container_of(k, CPUState, cpu_index);
run_on_cpu_data mask = RUN_ON_CPU_HOST_ULONG(*plugin.mask);
- if (cpu->created) {
+ if (DEVICE(cpu)->realized) {
async_run_on_cpu(cpu, plugin_cpu_update__async, mask);
} else {
plugin_cpu_update__async(cpu, mask);
diff --git a/qapi/migration.json b/qapi/migration.json
index d8f3bbd..d7dfaa5 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -230,9 +230,8 @@
# throttled during auto-converge. This is only present when
# auto-converge has started throttling guest cpus. (Since 2.7)
#
-# @error-desc: the human readable error description string, when
-# @status is 'failed'. Clients should not attempt to parse the
-# error strings. (Since 2.7)
+# @error-desc: the human readable error description string. Clients
+# should not attempt to parse the error strings. (Since 2.7)
#
# @postcopy-blocktime: total time when all vCPU were blocked during
# postcopy live migration. This is only present when the
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 6beae65..697c655 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -501,13 +501,6 @@
return win2qemu[(int)bus];
}
-DEFINE_GUID(GUID_DEVINTERFACE_DISK,
- 0x53f56307L, 0xb6bf, 0x11d0, 0x94, 0xf2,
- 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
-DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
- 0x2accfe60L, 0xc130, 0x11d2, 0xb0, 0x82,
- 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b);
-
static void get_pci_address_for_device(GuestPCIAddress *pci,
HDEVINFO dev_info)
{
diff --git a/qga/commands.c b/qga/commands.c
index 09c683e..ce172ed 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -206,15 +206,15 @@
#endif
if (gei->out.length > 0) {
ges->out_data = g_base64_encode(gei->out.data, gei->out.length);
- g_free(gei->out.data);
ges->has_out_truncated = gei->out.truncated;
}
+ g_free(gei->out.data);
if (gei->err.length > 0) {
ges->err_data = g_base64_encode(gei->err.data, gei->err.length);
- g_free(gei->err.data);
ges->has_err_truncated = gei->err.truncated;
}
+ g_free(gei->err.data);
QTAILQ_REMOVE(&guest_exec_state.processes, gei, next);
g_free(gei);
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index b720dd4..876e2a8 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -1220,11 +1220,13 @@
# @signal: signal number (linux) or unhandled exception code (windows)
# if the process was abnormally terminated.
#
-# @out-data: base64-encoded stdout of the process
+# @out-data: base64-encoded stdout of the process. This field will only
+# be populated after the process exits.
#
-# @err-data: base64-encoded stderr of the process Note: @out-data and
+# @err-data: base64-encoded stderr of the process. Note: @out-data and
# @err-data are present only if 'capture-output' was specified for
-# 'guest-exec'
+# 'guest-exec'. This field will only be populated after the process
+# exits.
#
# @out-truncated: true if stdout was not fully captured due to size
# limitation.
diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py
new file mode 100755
index 0000000..bcbcb83
--- /dev/null
+++ b/scripts/feature_to_c.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import os, sys
+
+def writeliteral(indent, bytes):
+ sys.stdout.write(' ' * indent)
+ sys.stdout.write('"')
+ quoted = True
+
+ for c in bytes:
+ if not quoted:
+ sys.stdout.write('\n')
+ sys.stdout.write(' ' * indent)
+ sys.stdout.write('"')
+ quoted = True
+
+ if c == b'"'[0]:
+ sys.stdout.write('\\"')
+ elif c == b'\\'[0]:
+ sys.stdout.write('\\\\')
+ elif c == b'\n'[0]:
+ sys.stdout.write('\\n"')
+ quoted = False
+ elif c >= 32 and c < 127:
+ sys.stdout.write(c.to_bytes(1, 'big').decode())
+ else:
+ sys.stdout.write(f'\{c:03o}')
+
+ if quoted:
+ sys.stdout.write('"')
+
+sys.stdout.write('#include "qemu/osdep.h"\n' \
+ '#include "exec/gdbstub.h"\n' \
+ '\n'
+ 'const GDBFeature gdb_static_features[] = {\n')
+
+for input in sys.argv[1:]:
+ with open(input, 'rb') as file:
+ read = file.read()
+
+ sys.stdout.write(' {\n')
+ writeliteral(8, bytes(os.path.basename(input), 'utf-8'))
+ sys.stdout.write(',\n')
+ writeliteral(8, read)
+ sys.stdout.write('\n },\n')
+
+sys.stdout.write(' { NULL }\n};\n')
diff --git a/scripts/feature_to_c.sh b/scripts/feature_to_c.sh
deleted file mode 100644
index c1f67c8..0000000
--- a/scripts/feature_to_c.sh
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/sh
-
-# Convert text files to compilable C arrays.
-#
-# Copyright (C) 2007 Free Software Foundation, Inc.
-#
-# This file is part of GDB.
-#
-# 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 <http://www.gnu.org/licenses/>.
-
-if test -z "$1"; then
- echo "Usage: $0 INPUTFILE..."
- exit 1
-fi
-
-for input; do
- arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
-
- ${AWK:-awk} 'BEGIN { n = 0
- printf "#include \"qemu/osdep.h\"\n"
- print "static const char '$arrayname'[] = {"
- for (i = 0; i < 255; i++)
- _ord_[sprintf("%c", i)] = i
- } {
- split($0, line, "");
- printf " "
- for (i = 1; i <= length($0); i++) {
- c = line[i]
- if (c == "'\''") {
- printf "'\''\\'\'''\'', "
- } else if (c == "\\") {
- printf "'\''\\\\'\'', "
- } else if (_ord_[c] >= 32 && _ord_[c] < 127) {
- printf "'\''%s'\'', ", c
- } else {
- printf "'\''\\%03o'\'', ", _ord_[c]
- }
- if (i % 10 == 0)
- printf "\n "
- }
- printf "'\''\\n'\'', \n"
- } END {
- print " 0 };"
- }' < $input
-done
-
-echo
-echo '#include "exec/gdbstub.h"'
-echo "const char *const xml_builtin[][2] = {"
-
-for input; do
- basename=$(echo $input | sed 's,.*/,,')
- arrayname=xml_feature_$(echo $input | sed 's,.*/,,; s/[-.]/_/g')
- echo " { \"$basename\", $arrayname },"
-done
-
-echo " { (char *)0, (char *)0 }"
-echo "};"
diff --git a/stubs/gdbstub.c b/stubs/gdbstub.c
index 2b7aee5..580e207 100644
--- a/stubs/gdbstub.c
+++ b/stubs/gdbstub.c
@@ -1,6 +1,6 @@
#include "qemu/osdep.h"
-#include "exec/gdbstub.h" /* xml_builtin */
+#include "exec/gdbstub.h" /* gdb_static_features */
-const char *const xml_builtin[][2] = {
- { NULL, NULL }
+const GDBFeature gdb_static_features[] = {
+ { NULL }
};
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 831295d..6c6c551 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2319,15 +2319,15 @@
DEFINE_PROP_END_OF_LIST()
};
-static gchar *arm_gdb_arch_name(CPUState *cs)
+static const gchar *arm_gdb_arch_name(CPUState *cs)
{
ARMCPU *cpu = ARM_CPU(cs);
CPUARMState *env = &cpu->env;
if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
- return g_strdup("iwmmxt");
+ return "iwmmxt";
}
- return g_strdup("arm");
+ return "arm";
}
#ifndef CONFIG_USER_ONLY
@@ -2392,7 +2392,6 @@
cc->sysemu_ops = &arm_sysemu_ops;
#endif
cc->gdb_num_core_regs = 26;
- cc->gdb_core_xml_file = "arm-core.xml";
cc->gdb_arch_name = arm_gdb_arch_name;
cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml;
cc->gdb_stop_before_watchpoint = true;
@@ -2414,8 +2413,10 @@
static void cpu_register_class_init(ObjectClass *oc, void *data)
{
ARMCPUClass *acc = ARM_CPU_CLASS(oc);
+ CPUClass *cc = CPU_CLASS(acc);
acc->info = data;
+ cc->gdb_core_xml_file = "arm-core.xml";
}
void arm_cpu_register(const ARMCPUInfo *info)
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 811f3b3..1cb9d5b 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -781,9 +781,9 @@
{
}
-static gchar *aarch64_gdb_arch_name(CPUState *cs)
+static const gchar *aarch64_gdb_arch_name(CPUState *cs)
{
- return g_strdup("aarch64");
+ return "aarch64";
}
static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c
index 8fc8351..b7ace24 100644
--- a/target/arm/gdbstub.c
+++ b/target/arm/gdbstub.c
@@ -46,21 +46,7 @@
/* Core integer register. */
return gdb_get_reg32(mem_buf, env->regs[n]);
}
- if (n < 24) {
- /* FPA registers. */
- if (gdb_has_xml()) {
- return 0;
- }
- return gdb_get_zeroes(mem_buf, 12);
- }
- switch (n) {
- case 24:
- /* FPA status register. */
- if (gdb_has_xml()) {
- return 0;
- }
- return gdb_get_reg32(mem_buf, 0);
- case 25:
+ if (n == 25) {
/* CPSR, or XPSR for M-profile */
if (arm_feature(env, ARM_FEATURE_M)) {
return gdb_get_reg32(mem_buf, xpsr_read(env));
@@ -100,21 +86,7 @@
env->regs[n] = tmp;
return 4;
}
- if (n < 24) { /* 16-23 */
- /* FPA registers (ignored). */
- if (gdb_has_xml()) {
- return 0;
- }
- return 12;
- }
- switch (n) {
- case 24:
- /* FPA status register (ignored). */
- if (gdb_has_xml()) {
- return 0;
- }
- return 4;
- case 25:
+ if (n == 25) {
/* CPSR, or XPSR for M-profile */
if (arm_feature(env, ARM_FEATURE_M)) {
/*
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index cec5d2b..3aab05d 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5916,12 +5916,12 @@
memset(&env->user_features, 0, sizeof(env->user_features));
}
-static gchar *x86_gdb_arch_name(CPUState *cs)
+static const gchar *x86_gdb_arch_name(CPUState *cs)
{
#ifdef TARGET_X86_64
- return g_strdup("i386:x86-64");
+ return "i386:x86-64";
#else
- return g_strdup("i386");
+ return "i386";
#endif
}
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 2bea7ca..ef1bf89 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -766,9 +766,9 @@
#endif
}
-static gchar *loongarch32_gdb_arch_name(CPUState *cs)
+static const gchar *loongarch32_gdb_arch_name(CPUState *cs)
{
- return g_strdup("loongarch32");
+ return "loongarch32";
}
static void loongarch32_cpu_class_init(ObjectClass *c, void *data)
@@ -780,9 +780,9 @@
cc->gdb_arch_name = loongarch32_gdb_arch_name;
}
-static gchar *loongarch64_gdb_arch_name(CPUState *cs)
+static const gchar *loongarch64_gdb_arch_name(CPUState *cs)
{
- return g_strdup("loongarch64");
+ return "loongarch64";
}
static void loongarch64_cpu_class_init(ObjectClass *c, void *data)
diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c
index 2ad1151..ec5731e 100644
--- a/target/ppc/gdbstub.c
+++ b/target/ppc/gdbstub.c
@@ -54,12 +54,6 @@
case 0 ... 31:
/* gprs */
return sizeof(target_ulong);
- case 32 ... 63:
- /* fprs */
- if (gdb_has_xml()) {
- return 0;
- }
- return 8;
case 66:
/* cr */
case 69:
@@ -74,12 +68,6 @@
case 68:
/* ctr */
return sizeof(target_ulong);
- case 70:
- /* fpscr */
- if (gdb_has_xml()) {
- return 0;
- }
- return sizeof(target_ulong);
default:
return 0;
}
@@ -132,9 +120,6 @@
if (n < 32) {
/* gprs */
gdb_get_regl(buf, env->gpr[n]);
- } else if (n < 64) {
- /* fprs */
- gdb_get_reg64(buf, *cpu_fpr_ptr(env, n - 32));
} else {
switch (n) {
case 64:
@@ -158,9 +143,6 @@
case 69:
gdb_get_reg32(buf, cpu_read_xer(env));
break;
- case 70:
- gdb_get_reg32(buf, env->fpscr);
- break;
}
}
mem_buf = buf->data + buf->len - r;
@@ -589,12 +571,12 @@
return 0;
}
-gchar *ppc_gdb_arch_name(CPUState *cs)
+const gchar *ppc_gdb_arch_name(CPUState *cs)
{
#if defined(TARGET_PPC64)
- return g_strdup("powerpc:common64");
+ return "powerpc:common64";
#else
- return g_strdup("powerpc:common");
+ return "powerpc:common";
#endif
}
diff --git a/target/ppc/internal.h b/target/ppc/internal.h
index 15803bc..c881c67 100644
--- a/target/ppc/internal.h
+++ b/target/ppc/internal.h
@@ -221,7 +221,7 @@
/* gdbstub.c */
void ppc_gdb_init(CPUState *cs, PowerPCCPUClass *ppc);
-gchar *ppc_gdb_arch_name(CPUState *cs);
+const gchar *ppc_gdb_arch_name(CPUState *cs);
/**
* prot_for_access_type:
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index ac2b94b..f557270 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2004,17 +2004,17 @@
DEFINE_PROP_END_OF_LIST(),
};
-static gchar *riscv_gdb_arch_name(CPUState *cs)
+static const gchar *riscv_gdb_arch_name(CPUState *cs)
{
RISCVCPU *cpu = RISCV_CPU(cs);
CPURISCVState *env = &cpu->env;
switch (riscv_cpu_mxl(env)) {
case MXL_RV32:
- return g_strdup("riscv:rv32");
+ return "riscv:rv32";
case MXL_RV64:
case MXL_RV128:
- return g_strdup("riscv:rv64");
+ return "riscv:rv64";
default:
g_assert_not_reached();
}
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 4f7599d..6093ab0 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -282,9 +282,9 @@
#endif
}
-static gchar *s390_gdb_arch_name(CPUState *cs)
+static const gchar *s390_gdb_arch_name(CPUState *cs)
{
- return g_strdup("s390:64-bit");
+ return "s390:64-bit";
}
static Property s390x_cpu_properties[] = {
diff --git a/target/sh4/translate.c b/target/sh4/translate.c
index cbd8dfc..220a06b 100644
--- a/target/sh4/translate.c
+++ b/target/sh4/translate.c
@@ -1816,6 +1816,18 @@
}
#ifdef CONFIG_USER_ONLY
+/*
+ * Restart with the EXCLUSIVE bit set, within a TB run via
+ * cpu_exec_step_atomic holding the exclusive lock.
+ */
+static void gen_restart_exclusive(DisasContext *ctx)
+{
+ ctx->envflags |= TB_FLAG_GUSA_EXCLUSIVE;
+ gen_save_cpu_state(ctx, false);
+ gen_helper_exclusive(tcg_env);
+ ctx->base.is_jmp = DISAS_NORETURN;
+}
+
/* For uniprocessors, SH4 uses optimistic restartable atomic sequences.
Upon an interrupt, a real kernel would simply notice magic values in
the registers and reset the PC to the start of the sequence.
@@ -2149,12 +2161,7 @@
qemu_log_mask(LOG_UNIMP, "Unrecognized gUSA sequence %08x-%08x\n",
pc, pc_end);
- /* Restart with the EXCLUSIVE bit set, within a TB run via
- cpu_exec_step_atomic holding the exclusive lock. */
- ctx->envflags |= TB_FLAG_GUSA_EXCLUSIVE;
- gen_save_cpu_state(ctx, false);
- gen_helper_exclusive(tcg_env);
- ctx->base.is_jmp = DISAS_NORETURN;
+ gen_restart_exclusive(ctx);
/* We're not executing an instruction, but we must report one for the
purposes of accounting within the TB. We might as well report the
@@ -2242,12 +2249,22 @@
#ifdef CONFIG_USER_ONLY
if (unlikely(ctx->envflags & TB_FLAG_GUSA_MASK)
&& !(ctx->envflags & TB_FLAG_GUSA_EXCLUSIVE)) {
- /* We're in an gUSA region, and we have not already fallen
- back on using an exclusive region. Attempt to parse the
- region into a single supported atomic operation. Failure
- is handled within the parser by raising an exception to
- retry using an exclusive region. */
- decode_gusa(ctx, env);
+ /*
+ * We're in an gUSA region, and we have not already fallen
+ * back on using an exclusive region. Attempt to parse the
+ * region into a single supported atomic operation. Failure
+ * is handled within the parser by raising an exception to
+ * retry using an exclusive region.
+ *
+ * Parsing the region in one block conflicts with plugins,
+ * so always use exclusive mode if plugins enabled.
+ */
+ if (ctx->base.plugin_enabled) {
+ gen_restart_exclusive(ctx);
+ ctx->base.pc_next += 2;
+ } else {
+ decode_gusa(ctx, env);
+ }
return;
}
#endif
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index d147762..5ca666e 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -29,9 +29,9 @@
env->features |= 1ULL << feature;
}
-static gchar *tricore_gdb_arch_name(CPUState *cs)
+static const gchar *tricore_gdb_arch_name(CPUState *cs)
{
- return g_strdup("tricore");
+ return "tricore";
}
static void tricore_cpu_set_pc(CPUState *cs, vaddr value)
diff --git a/tests/avocado/machine_aarch64_sbsaref.py b/tests/avocado/machine_aarch64_sbsaref.py
index a794245..bdd1efc 100644
--- a/tests/avocado/machine_aarch64_sbsaref.py
+++ b/tests/avocado/machine_aarch64_sbsaref.py
@@ -28,33 +28,33 @@ def fetch_firmware(self):
"""
Flash volumes generated using:
- - Fedora GNU Toolchain version 13.1.1 20230511 (Red Hat 13.1.1-2)
+ - Fedora GNU Toolchain version 13.2.1 20230728 (Red Hat 13.2.1-1)
- Trusted Firmware-A
- https://github.com/ARM-software/arm-trusted-firmware/tree/c0d8ee38
+ https://github.com/ARM-software/arm-trusted-firmware/tree/7c3ff62d
- Tianocore EDK II
https://github.com/tianocore/edk2/tree/0f9283429dd4
- https://github.com/tianocore/edk2-non-osi/tree/f0bb00937ad6
- https://github.com/tianocore/edk2-platforms/tree/7880b92e2a04
+ https://github.com/tianocore/edk2/tree/ad1c0394b177
+ https://github.com/tianocore/edk2-platforms/tree/d03a60523a60
"""
# Secure BootRom (TF-A code)
fs0_xz_url = (
- "https://fileserver.linaro.org/s/HrYMCjP7MEccjRP/"
+ "https://fileserver.linaro.org/s/rE43RJyTfxPtBkc/"
"download/SBSA_FLASH0.fd.xz"
)
- fs0_xz_hash = "447eff64a90b84ce47703c6ec41fbfc25befaaea"
+ fs0_xz_hash = "cdb8e4ffdaaa79292b7b465693f9e5fae6b7062d"
tar_xz_path = self.fetch_asset(fs0_xz_url, asset_hash=fs0_xz_hash)
archive.extract(tar_xz_path, self.workdir)
fs0_path = os.path.join(self.workdir, "SBSA_FLASH0.fd")
# Non-secure rom (UEFI and EFI variables)
fs1_xz_url = (
- "https://fileserver.linaro.org/s/t8foNnMPz74DZZy/"
+ "https://fileserver.linaro.org/s/AGWPDXbcqJTKS4R/"
"download/SBSA_FLASH1.fd.xz"
)
- fs1_xz_hash = "13a9a262953787c7fc5a9155dfaa26e703631e02"
+ fs1_xz_hash = "411155ae6984334714dff08d5d628178e790c875"
tar_xz_path = self.fetch_asset(fs1_xz_url, asset_hash=fs1_xz_hash)
archive.extract(tar_xz_path, self.workdir)
fs1_path = os.path.join(self.workdir, "SBSA_FLASH1.fd")
@@ -75,7 +75,6 @@ def fetch_firmware(self):
"sbsa-ref",
)
- @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is not reliable')
def test_sbsaref_edk2_firmware(self):
"""
:avocado: tags=cpu:cortex-a57
@@ -144,7 +143,7 @@ def test_sbsaref_alpine_linux_cortex_a57(self):
def test_sbsaref_alpine_linux_neoverse_n1(self):
"""
- :avocado: tags=cpu:max
+ :avocado: tags=cpu:neoverse-n1
"""
self.boot_alpine_linux("neoverse-n1")
@@ -152,4 +151,54 @@ def test_sbsaref_alpine_linux_max(self):
"""
:avocado: tags=cpu:max
"""
- self.boot_alpine_linux("max,pauth-impdef=on")
+ self.boot_alpine_linux("max")
+
+
+ # This tests the whole boot chain from EFI to Userspace
+ # We only boot a whole OS for the current top level CPU and GIC
+ # Other test profiles should use more minimal boots
+ def boot_openbsd73(self, cpu):
+ self.fetch_firmware()
+
+ img_url = (
+ "https://cdn.openbsd.org/pub/OpenBSD/7.3/arm64/miniroot73.img"
+ )
+
+ img_hash = "7fc2c75401d6f01fbfa25f4953f72ad7d7c18650056d30755c44b9c129b707e5"
+ img_path = self.fetch_asset(img_url, algorithm="sha256", asset_hash=img_hash)
+
+ self.vm.set_console()
+ self.vm.add_args(
+ "-cpu",
+ cpu,
+ "-drive",
+ f"file={img_path},format=raw",
+ "-device",
+ "virtio-rng-pci,rng=rng0",
+ "-object",
+ "rng-random,id=rng0,filename=/dev/urandom",
+ )
+
+ self.vm.launch()
+ wait_for_console_pattern(self,
+ "Welcome to the OpenBSD/arm64"
+ " 7.3 installation program.")
+
+ def test_sbsaref_openbsd73_cortex_a57(self):
+ """
+ :avocado: tags=cpu:cortex-a57
+ """
+ self.boot_openbsd73("cortex-a57")
+
+ def test_sbsaref_openbsd73_neoverse_n1(self):
+ """
+ :avocado: tags=cpu:neoverse-n1
+ """
+ self.boot_openbsd73("neoverse-n1")
+
+ def test_sbsaref_openbsd73_max(self):
+ """
+ :avocado: tags=cpu:max
+ """
+ self.boot_openbsd73("max")
+
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index dfabafa..ab68b2d 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -16,9 +16,8 @@
endif
DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY))
-RUNC ?= docker
-ENGINE ?= auto
-DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
+RUNC ?= $(if $(shell command -v docker), docker, podman)
+DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(RUNC)
CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
@@ -158,7 +157,7 @@
)
docker:
- @echo 'Build QEMU and run tests inside Docker or Podman containers'
+ @echo 'Build QEMU and run tests inside $(RUNC) containers'
@echo
@echo 'Available targets:'
@echo
@@ -198,8 +197,6 @@
@echo ' EXECUTABLE=<path> Include executable in image.'
@echo ' EXTRA_FILES="<path> [... <path>]"'
@echo ' Include extra files in image.'
- @echo ' ENGINE=auto/docker/podman'
- @echo ' Specify which container engine to run.'
@echo ' REGISTRY=url Cache builds from registry (default:$(DOCKER_REGISTRY))'
docker-help: docker
diff --git a/tests/docker/dockerfiles/alpine.docker b/tests/docker/dockerfiles/alpine.docker
index d25649c..42f6928 100644
--- a/tests/docker/dockerfiles/alpine.docker
+++ b/tests/docker/dockerfiles/alpine.docker
@@ -100,6 +100,7 @@
sparse \
spice-dev \
spice-protocol \
+ swtpm \
tar \
tesseract-ocr \
usbredir-dev \
diff --git a/tests/docker/dockerfiles/centos8.docker b/tests/docker/dockerfiles/centos8.docker
index 68bfe60..d97c30e 100644
--- a/tests/docker/dockerfiles/centos8.docker
+++ b/tests/docker/dockerfiles/centos8.docker
@@ -107,6 +107,7 @@
socat \
spice-protocol \
spice-server-devel \
+ swtpm \
systemd-devel \
systemtap-sdt-devel \
tar \
diff --git a/tests/docker/dockerfiles/debian-amd64-cross.docker b/tests/docker/dockerfiles/debian-amd64-cross.docker
index 0991938..00bdc06 100644
--- a/tests/docker/dockerfiles/debian-amd64-cross.docker
+++ b/tests/docker/dockerfiles/debian-amd64-cross.docker
@@ -55,6 +55,7 @@
sed \
socat \
sparse \
+ swtpm \
tar \
tesseract-ocr \
tesseract-ocr-eng \
diff --git a/tests/docker/dockerfiles/debian-amd64.docker b/tests/docker/dockerfiles/debian-amd64.docker
index 61dbc3f..9b50fb2 100644
--- a/tests/docker/dockerfiles/debian-amd64.docker
+++ b/tests/docker/dockerfiles/debian-amd64.docker
@@ -124,6 +124,7 @@
sed \
socat \
sparse \
+ swtpm \
systemtap-sdt-dev \
tar \
tesseract-ocr \
diff --git a/tests/docker/dockerfiles/debian-arm64-cross.docker b/tests/docker/dockerfiles/debian-arm64-cross.docker
index 74eabb2..2dae377 100644
--- a/tests/docker/dockerfiles/debian-arm64-cross.docker
+++ b/tests/docker/dockerfiles/debian-arm64-cross.docker
@@ -55,6 +55,7 @@
sed \
socat \
sparse \
+ swtpm \
tar \
tesseract-ocr \
tesseract-ocr-eng \
diff --git a/tests/docker/dockerfiles/debian-armhf-cross.docker b/tests/docker/dockerfiles/debian-armhf-cross.docker
index 1ebd6eb..180ed83 100644
--- a/tests/docker/dockerfiles/debian-armhf-cross.docker
+++ b/tests/docker/dockerfiles/debian-armhf-cross.docker
@@ -55,6 +55,7 @@
sed \
socat \
sparse \
+ swtpm \
tar \
tesseract-ocr \
tesseract-ocr-eng \
diff --git a/tests/docker/dockerfiles/debian-ppc64el-cross.docker b/tests/docker/dockerfiles/debian-ppc64el-cross.docker
index 59091fe..d6be2f0 100644
--- a/tests/docker/dockerfiles/debian-ppc64el-cross.docker
+++ b/tests/docker/dockerfiles/debian-ppc64el-cross.docker
@@ -55,6 +55,7 @@
sed \
socat \
sparse \
+ swtpm \
tar \
tesseract-ocr \
tesseract-ocr-eng \
diff --git a/tests/docker/dockerfiles/debian-s390x-cross.docker b/tests/docker/dockerfiles/debian-s390x-cross.docker
index 48b2f28..ec0041d 100644
--- a/tests/docker/dockerfiles/debian-s390x-cross.docker
+++ b/tests/docker/dockerfiles/debian-s390x-cross.docker
@@ -55,6 +55,7 @@
sed \
socat \
sparse \
+ swtpm \
tar \
tesseract-ocr \
tesseract-ocr-eng \
diff --git a/tests/docker/dockerfiles/fedora-win32-cross.docker b/tests/docker/dockerfiles/fedora-win32-cross.docker
index afa9885..0879921 100644
--- a/tests/docker/dockerfiles/fedora-win32-cross.docker
+++ b/tests/docker/dockerfiles/fedora-win32-cross.docker
@@ -55,6 +55,7 @@
socat \
sparse \
spice-protocol \
+ swtpm \
tar \
tesseract \
tesseract-langpack-eng \
diff --git a/tests/docker/dockerfiles/fedora-win64-cross.docker b/tests/docker/dockerfiles/fedora-win64-cross.docker
index cf93a0c..f8e4cb7 100644
--- a/tests/docker/dockerfiles/fedora-win64-cross.docker
+++ b/tests/docker/dockerfiles/fedora-win64-cross.docker
@@ -55,6 +55,7 @@
socat \
sparse \
spice-protocol \
+ swtpm \
tar \
tesseract \
tesseract-langpack-eng \
diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfiles/fedora.docker
index f00e9e2..9e9c71f 100644
--- a/tests/docker/dockerfiles/fedora.docker
+++ b/tests/docker/dockerfiles/fedora.docker
@@ -118,6 +118,7 @@
sparse \
spice-protocol \
spice-server-devel \
+ swtpm \
systemd-devel \
systemtap-sdt-devel \
tar \
diff --git a/tests/docker/dockerfiles/opensuse-leap.docker b/tests/docker/dockerfiles/opensuse-leap.docker
index ed04b4d..dc0e36c 100644
--- a/tests/docker/dockerfiles/opensuse-leap.docker
+++ b/tests/docker/dockerfiles/opensuse-leap.docker
@@ -100,6 +100,7 @@
socat \
sparse \
spice-protocol-devel \
+ swtpm \
systemd-devel \
systemtap-sdt-devel \
tar \
diff --git a/tests/docker/dockerfiles/ubuntu2204.docker b/tests/docker/dockerfiles/ubuntu2204.docker
index 94c2c16..2ca9cff 100644
--- a/tests/docker/dockerfiles/ubuntu2204.docker
+++ b/tests/docker/dockerfiles/ubuntu2204.docker
@@ -124,6 +124,7 @@
sed \
socat \
sparse \
+ swtpm \
systemtap-sdt-dev \
tar \
tesseract-ocr \
diff --git a/tests/lcitool/libvirt-ci b/tests/lcitool/libvirt-ci
index e3ed1e5..36bc517 160000
--- a/tests/lcitool/libvirt-ci
+++ b/tests/lcitool/libvirt-ci
@@ -1 +1 @@
-Subproject commit e3ed1e5da101943e53d8d89424e17b22120743f5
+Subproject commit 36bc517161c45ead20224d47f2dc4fa428af6724
diff --git a/tests/lcitool/projects/qemu.yml b/tests/lcitool/projects/qemu.yml
index 6f08851..82092c9 100644
--- a/tests/lcitool/projects/qemu.yml
+++ b/tests/lcitool/projects/qemu.yml
@@ -110,6 +110,7 @@
- spice-protocol
- spice-server
- ssh-client
+ - swtpm
- systemd
- tar
- tesseract
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 3f94a4f..dc7a556 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1259,6 +1259,28 @@
qtest_rsp(s);
}
+QDict *qtest_vqmp_assert_failure_ref(QTestState *qts,
+ const char *fmt, va_list args)
+{
+ QDict *response;
+ QDict *ret;
+
+ response = qtest_vqmp(qts, fmt, args);
+
+ g_assert(response);
+ if (!qdict_haskey(response, "error")) {
+ g_autoptr(GString) s = qobject_to_json_pretty(QOBJECT(response), true);
+ g_test_message("%s", s->str);
+ }
+ g_assert(qdict_haskey(response, "error"));
+ g_assert(!qdict_haskey(response, "return"));
+ ret = qdict_get_qdict(response, "error");
+ qobject_ref(ret);
+ qobject_unref(response);
+
+ return ret;
+}
+
QDict *qtest_vqmp_assert_success_ref(QTestState *qts,
const char *fmt, va_list args)
{
@@ -1321,6 +1343,17 @@
}
#endif /* !_WIN32 */
+QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
+{
+ QDict *response;
+ va_list ap;
+
+ va_start(ap, fmt);
+ response = qtest_vqmp_assert_failure_ref(qts, fmt, ap);
+ va_end(ap);
+ return response;
+}
+
QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
{
QDict *response;
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index e53e350..5fe3d13 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -811,6 +811,34 @@
#endif /* !_WIN32 */
/**
+ * qtest_qmp_assert_failure_ref:
+ * @qts: QTestState instance to operate on
+ * @fmt: QMP message to send to qemu, formatted like
+ * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
+ * supported after '%'.
+ *
+ * Sends a QMP message to QEMU, asserts that an 'error' key is present in
+ * the response, and returns the response.
+ */
+QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
+ G_GNUC_PRINTF(2, 3);
+
+/**
+ * qtest_vqmp_assert_failure_ref:
+ * @qts: QTestState instance to operate on
+ * @fmt: QMP message to send to qemu, formatted like
+ * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
+ * supported after '%'.
+ * @args: variable arguments for @fmt
+ *
+ * Sends a QMP message to QEMU, asserts that an 'error' key is present in
+ * the response, and returns the response.
+ */
+QDict *qtest_vqmp_assert_failure_ref(QTestState *qts,
+ const char *fmt, va_list args)
+ G_GNUC_PRINTF(2, 0);
+
+/**
* qtest_qmp_assert_success_ref:
* @qts: QTestState instance to operate on
* @fmt: QMP message to send to qemu, formatted like
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 1fba07f..66795cf 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -317,6 +317,7 @@
'tpm-tis-i2c-test': [io, tpmemu_files, 'qtest_aspeed.c'],
'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
+ 'virtio-net-failover': files('migration-helpers.c'),
'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'),
'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'),
}
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index be00c52..0c185db 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -49,6 +49,26 @@
return false;
}
+void migrate_qmp_fail(QTestState *who, const char *uri, const char *fmt, ...)
+{
+ va_list ap;
+ QDict *args, *err;
+
+ va_start(ap, fmt);
+ args = qdict_from_vjsonf_nofail(fmt, ap);
+ va_end(ap);
+
+ g_assert(!qdict_haskey(args, "uri"));
+ qdict_put_str(args, "uri", uri);
+
+ err = qtest_qmp_assert_failure_ref(
+ who, "{ 'execute': 'migrate', 'arguments': %p}", args);
+
+ g_assert(qdict_haskey(err, "desc"));
+
+ qobject_unref(err);
+}
+
/*
* Send QMP command "migrate".
* Arguments are built from @fmt... (formatted like
@@ -70,6 +90,46 @@
"{ 'execute': 'migrate', 'arguments': %p}", args);
}
+void migrate_set_capability(QTestState *who, const char *capability,
+ bool value)
+{
+ qtest_qmp_assert_success(who,
+ "{ 'execute': 'migrate-set-capabilities',"
+ "'arguments': { "
+ "'capabilities': [ { "
+ "'capability': %s, 'state': %i } ] } }",
+ capability, value);
+}
+
+void migrate_incoming_qmp(QTestState *to, const char *uri, const char *fmt, ...)
+{
+ va_list ap;
+ QDict *args, *rsp, *data;
+
+ va_start(ap, fmt);
+ args = qdict_from_vjsonf_nofail(fmt, ap);
+ va_end(ap);
+
+ g_assert(!qdict_haskey(args, "uri"));
+ qdict_put_str(args, "uri", uri);
+
+ migrate_set_capability(to, "events", true);
+
+ rsp = qtest_qmp(to, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
+ args);
+ g_assert(qdict_haskey(rsp, "return"));
+ qobject_unref(rsp);
+
+ rsp = qtest_qmp_eventwait_ref(to, "MIGRATION");
+ g_assert(qdict_haskey(rsp, "data"));
+
+ data = qdict_get_qdict(rsp, "data");
+ g_assert(qdict_haskey(data, "status"));
+ g_assert_cmpstr(qdict_get_str(data, "status"), ==, "setup");
+
+ qobject_unref(rsp);
+}
+
/*
* Note: caller is responsible to free the returned object via
* qobject_unref() after use
diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 009e250..4f51d0f 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -23,6 +23,16 @@
G_GNUC_PRINTF(3, 4)
void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...);
+G_GNUC_PRINTF(3, 4)
+void migrate_incoming_qmp(QTestState *who, const char *uri,
+ const char *fmt, ...);
+
+G_GNUC_PRINTF(3, 4)
+void migrate_qmp_fail(QTestState *who, const char *uri, const char *fmt, ...);
+
+void migrate_set_capability(QTestState *who, const char *capability,
+ bool value);
+
QDict *migrate_query(QTestState *who);
QDict *migrate_query_not_failed(QTestState *who);
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 46f1c27..8eb2053 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -605,17 +605,6 @@
qtest_qmp_assert_success(who, "{ 'execute': 'migrate_cancel' }");
}
-static void migrate_set_capability(QTestState *who, const char *capability,
- bool value)
-{
- qtest_qmp_assert_success(who,
- "{ 'execute': 'migrate-set-capabilities',"
- "'arguments': { "
- "'capabilities': [ { "
- "'capability': %s, 'state': %i } ] } }",
- capability, value);
-}
-
static void migrate_postcopy_start(QTestState *from, QTestState *to)
{
qtest_qmp_assert_success(from, "{ 'execute': 'migrate-start-postcopy' }");
@@ -708,6 +697,8 @@
MIG_TEST_FAIL,
/* This test should fail, dest qemu should fail with abnormal status */
MIG_TEST_FAIL_DEST_QUIT_ERR,
+ /* The QMP command for this migration should fail with an error */
+ MIG_TEST_QMP_ERROR,
} result;
/*
@@ -1514,6 +1505,7 @@
{
QTestState *from, *to;
void *data_hook = NULL;
+ g_autofree char *connect_uri = NULL;
if (test_migrate_start(&from, &to, args->listen_uri, &args->start)) {
return;
@@ -1548,13 +1540,17 @@
}
if (!args->connect_uri) {
- g_autofree char *local_connect_uri =
- migrate_get_socket_address(to, "socket-address");
- migrate_qmp(from, local_connect_uri, "{}");
+ connect_uri = migrate_get_socket_address(to, "socket-address");
} else {
- migrate_qmp(from, args->connect_uri, "{}");
+ connect_uri = g_strdup(args->connect_uri);
}
+ if (args->result == MIG_TEST_QMP_ERROR) {
+ migrate_qmp_fail(from, connect_uri, "{}");
+ goto finish;
+ }
+
+ migrate_qmp(from, connect_uri, "{}");
if (args->result != MIG_TEST_SUCCEED) {
bool allow_active = args->result == MIG_TEST_FAIL;
@@ -1606,6 +1602,7 @@
wait_for_serial("dest_serial");
}
+finish:
if (args->finish_hook) {
args->finish_hook(from, to, data_hook);
}
@@ -1981,8 +1978,7 @@
close(pair[0]);
/* Start incoming migration from the 1st socket */
- qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
- " 'arguments': { 'uri': 'fd:fd-mig' }}");
+ migrate_incoming_qmp(to, "fd:fd-mig", "{}");
/* Send the 2nd socket to the target */
qtest_qmp_fds_assert_success(from, &pair[1], 1,
@@ -2204,8 +2200,7 @@
migrate_set_capability(to, "multifd", true);
/* Start incoming migration from the 1st socket */
- qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
- " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
+ migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}");
return NULL;
}
@@ -2458,8 +2453,7 @@
migrate_set_capability(to, "multifd", true);
/* Start incoming migration from the 1st socket */
- qtest_qmp_assert_success(to, "{ 'execute': 'migrate-incoming',"
- " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
+ migrate_incoming_qmp(to, "tcp:127.0.0.1:0", "{}");
/* Wait for the first serial output from the source */
wait_for_serial("src_serial");
@@ -2489,8 +2483,7 @@
migrate_set_capability(to2, "multifd", true);
/* Start incoming migration from the 1st socket */
- qtest_qmp_assert_success(to2, "{ 'execute': 'migrate-incoming',"
- " 'arguments': { 'uri': 'tcp:127.0.0.1:0' }}");
+ migrate_incoming_qmp(to2, "tcp:127.0.0.1:0", "{}");
g_free(uri);
uri = migrate_get_socket_address(to2, "socket-address");
diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index 4a80959..0d40bc1 100644
--- a/tests/qtest/virtio-net-failover.c
+++ b/tests/qtest/virtio-net-failover.c
@@ -11,6 +11,7 @@
#include "libqtest.h"
#include "libqos/pci.h"
#include "libqos/pci-pc.h"
+#include "migration-helpers.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qlist.h"
#include "qapi/qmp/qjson.h"
@@ -736,26 +737,10 @@
machine_stop(qts);
}
-static QDict *get_migration_event(QTestState *qts)
-{
- QDict *resp;
- QDict *data;
-
- resp = qtest_qmp_eventwait_ref(qts, "MIGRATION");
- g_assert(qdict_haskey(resp, "data"));
-
- data = qdict_get_qdict(resp, "data");
- g_assert(qdict_haskey(data, "status"));
- qobject_ref(data);
- qobject_unref(resp);
-
- return data;
-}
-
static void test_migrate_in(gconstpointer opaque)
{
QTestState *qts;
- QDict *resp, *args, *ret;
+ QDict *resp, *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@@ -787,18 +772,7 @@
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
- args = qdict_from_jsonf_nofail("{}");
- g_assert_nonnull(args);
- qdict_put_str(args, "uri", uri);
-
- resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
- args);
- g_assert(qdict_haskey(resp, "return"));
- qobject_unref(resp);
-
- resp = get_migration_event(qts);
- g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
- qobject_unref(resp);
+ migrate_incoming_qmp(qts, uri, "{}");
resp = get_failover_negociated_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");
@@ -888,7 +862,7 @@
static void test_off_migrate_in(gconstpointer opaque)
{
QTestState *qts;
- QDict *resp, *args, *ret;
+ QDict *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@@ -920,18 +894,7 @@
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
- args = qdict_from_jsonf_nofail("{}");
- g_assert_nonnull(args);
- qdict_put_str(args, "uri", uri);
-
- resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
- args);
- g_assert(qdict_haskey(resp, "return"));
- qobject_unref(resp);
-
- resp = get_migration_event(qts);
- g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
- qobject_unref(resp);
+ migrate_incoming_qmp(qts, uri, "{}");
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
@@ -1026,7 +989,7 @@
static void test_guest_off_migrate_in(gconstpointer opaque)
{
QTestState *qts;
- QDict *resp, *args, *ret;
+ QDict *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@@ -1058,18 +1021,7 @@
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
- args = qdict_from_jsonf_nofail("{}");
- g_assert_nonnull(args);
- qdict_put_str(args, "uri", uri);
-
- resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
- args);
- g_assert(qdict_haskey(resp, "return"));
- qobject_unref(resp);
-
- resp = get_migration_event(qts);
- g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
- qobject_unref(resp);
+ migrate_incoming_qmp(qts, uri, "{}");
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
@@ -1728,7 +1680,7 @@
static void test_multi_in(gconstpointer opaque)
{
QTestState *qts;
- QDict *resp, *args, *ret;
+ QDict *resp, *ret;
g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque);
qts = machine_start(BASE_MACHINE
@@ -1794,18 +1746,7 @@
check_one_card(qts, true, "standby1", MAC_STANDBY1);
check_one_card(qts, false, "primary1", MAC_PRIMARY1);
- args = qdict_from_jsonf_nofail("{}");
- g_assert_nonnull(args);
- qdict_put_str(args, "uri", uri);
-
- resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}",
- args);
- g_assert(qdict_haskey(resp, "return"));
- qobject_unref(resp);
-
- resp = get_migration_event(qts);
- g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup");
- qobject_unref(resp);
+ migrate_incoming_qmp(qts, uri, "{}");
resp = get_failover_negociated_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0");