Skip to content

Commit 5c24bce

Browse files
committed
Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-and-plugin-160620-2' into staging
Testing and plugin updates - clear up dtc warnings - add support for --enable-tsan builds - re-enable shippable cross builds - serialise cirrus check steps - fix check-tcg plugin issues - add lockstep plugin # gpg: Signature made Tue 16 Jun 2020 14:50:09 BST # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <[email protected]>" [full] # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * remotes/stsquad/tags/pull-testing-and-plugin-160620-2: (21 commits) plugins: new lockstep plugin for debugging TCG changes tests/tcg: ensure -cpu max also used for plugin run tests/tcg: build plugin list from contents of src directory cirrus.yml: serialise make check Revert ".shippable: temporaily disable some cross builds" tests: Disable select tests under TSan, which hit TSan issue. docs: Added details on TSan to testing.rst util: Added tsan annotate for thread name. include/qemu: Added tsan.h for annotations. tests/docker: Added docker build support for TSan. thread: add tsan annotations to QemuSpin translate-all: call qemu_spin_destroy for PageDesc tcg: call qemu_spin_destroy for tb->jmp_lock qht: call qemu_spin_destroy for head buckets cputlb: destroy CPUTLB with tlb_destroy thread: add qemu_spin_destroy cpu: convert queued work to a QSIMPLEQ configure: add --enable-tsan flag + fiber annotations for coroutine-ucontext Makefile: remove old compatibility gunks Makefile: dtc: update, build the libfdt target ... Signed-off-by: Peter Maydell <[email protected]>
2 parents cb8278c + c81950a commit 5c24bce

34 files changed

+910
-68
lines changed

.cirrus.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ freebsd_12_task:
1414
- cd build
1515
- ../configure || { cat config.log; exit 1; }
1616
- gmake -j8
17-
- gmake -j8 V=1 check
17+
- gmake V=1 check
1818

1919
macos_task:
2020
osx_instance:
@@ -26,7 +26,7 @@ macos_task:
2626
- cd build
2727
- ../configure --python=/usr/local/bin/python3 || { cat config.log; exit 1; }
2828
- gmake -j$(sysctl -n hw.ncpu)
29-
- gmake check -j$(sysctl -n hw.ncpu)
29+
- gmake check
3030

3131
macos_xcode_task:
3232
osx_instance:
@@ -39,4 +39,4 @@ macos_xcode_task:
3939
- cd build
4040
- ../configure --cc=clang || { cat config.log; exit 1; }
4141
- gmake -j$(sysctl -n hw.ncpu)
42-
- gmake check -j$(sysctl -n hw.ncpu)
42+
- gmake check

.shippable.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ env:
55
global:
66
- LC_ALL=C
77
matrix:
8-
# - IMAGE=debian-amd64
9-
# TARGET_LIST=x86_64-softmmu,x86_64-linux-user
8+
- IMAGE=debian-amd64
9+
TARGET_LIST=x86_64-softmmu,x86_64-linux-user
1010
- IMAGE=debian-win32-cross
1111
TARGET_LIST=arm-softmmu,i386-softmmu,lm32-softmmu
1212
- IMAGE=debian-win64-cross
@@ -19,10 +19,10 @@ env:
1919
TARGET_LIST=aarch64-softmmu,aarch64-linux-user
2020
- IMAGE=debian-s390x-cross
2121
TARGET_LIST=s390x-softmmu,s390x-linux-user
22-
# - IMAGE=debian-mips-cross
23-
# TARGET_LIST=mips-softmmu,mipsel-linux-user
24-
# - IMAGE=debian-mips64el-cross
25-
# TARGET_LIST=mips64el-softmmu,mips64el-linux-user
22+
- IMAGE=debian-mips-cross
23+
TARGET_LIST=mips-softmmu,mipsel-linux-user
24+
- IMAGE=debian-mips64el-cross
25+
TARGET_LIST=mips64el-softmmu,mips64el-linux-user
2626
- IMAGE=debian-ppc64el-cross
2727
TARGET_LIST=ppc64-softmmu,ppc64-linux-user,ppc64abi32-linux-user
2828
build:

Makefile

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,14 @@ $(SOFTMMU_FUZZ_RULES): $(edk2-decompressed)
526526
$(TARGET_DIRS_RULES):
527527
$(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $(dir $@) V="$(V)" TARGET_DIR="$(dir $@)" $(notdir $@),)
528528

529-
DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_srcdir=$(SRC_PATH)/dtc/libfdt
529+
# LIBFDT_lib="": avoid breaking existing trees with objects requiring -fPIC
530+
DTC_MAKE_ARGS=-I$(SRC_PATH)/dtc VPATH=$(SRC_PATH)/dtc -C dtc V="$(V)" LIBFDT_lib=""
530531
DTC_CFLAGS=$(CFLAGS) $(QEMU_CFLAGS)
531-
DTC_CPPFLAGS=-I$(BUILD_DIR)/dtc -I$(SRC_PATH)/dtc -I$(SRC_PATH)/dtc/libfdt
532+
DTC_CPPFLAGS=-I$(SRC_PATH)/dtc/libfdt
532533

533534
.PHONY: dtc/all
534-
dtc/all: .git-submodule-status dtc/libfdt dtc/tests
535-
$(call quiet-command,$(MAKE) $(DTC_MAKE_ARGS) CPPFLAGS="$(DTC_CPPFLAGS)" CFLAGS="$(DTC_CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)" ARFLAGS="$(ARFLAGS)" CC="$(CC)" AR="$(AR)" LD="$(LD)" $(SUBDIR_MAKEFLAGS) libfdt/libfdt.a,)
535+
dtc/all: .git-submodule-status dtc/libfdt
536+
$(call quiet-command,$(MAKE) $(DTC_MAKE_ARGS) CPPFLAGS="$(DTC_CPPFLAGS)" CFLAGS="$(DTC_CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)" ARFLAGS="$(ARFLAGS)" CC="$(CC)" AR="$(AR)" LD="$(LD)" $(SUBDIR_MAKEFLAGS) libfdt,)
536537

537538
dtc/%: .git-submodule-status
538539
@mkdir -p $@
@@ -561,12 +562,6 @@ slirp/all: .git-submodule-status
561562
CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \
562563
CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
563564

564-
# Compatibility gunk to keep make working across the rename of targets
565-
# for recursion, to be removed some time after 4.1.
566-
subdir-dtc: dtc/all
567-
subdir-capstone: capstone/all
568-
subdir-slirp: slirp/all
569-
570565
$(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
571566
$(qom-obj-y)
572567

@@ -820,7 +815,6 @@ distclean: clean
820815
rm -rf $$d || exit 1 ; \
821816
done
822817
rm -Rf .sdk
823-
if test -f dtc/version_gen.h; then $(MAKE) $(DTC_MAKE_ARGS) clean; fi
824818

825819
KEYMAPS=da en-gb et fr fr-ch is lt no pt-br sv \
826820
ar de en-us fi fr-be hr it lv nl pl ru th \

accel/tcg/cputlb.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ void tlb_init(CPUState *cpu)
270270
}
271271
}
272272

273+
void tlb_destroy(CPUState *cpu)
274+
{
275+
CPUArchState *env = cpu->env_ptr;
276+
int i;
277+
278+
qemu_spin_destroy(&env_tlb(env)->c.lock);
279+
for (i = 0; i < NB_MMU_MODES; i++) {
280+
CPUTLBDesc *desc = &env_tlb(env)->d[i];
281+
CPUTLBDescFast *fast = &env_tlb(env)->f[i];
282+
283+
g_free(fast->table);
284+
g_free(desc->iotlb);
285+
}
286+
}
287+
273288
/* flush_all_helper: run fn across all cpus
274289
*
275290
* If the wait flag is set then the src cpu's helper will be queued as

accel/tcg/translate-all.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
384384
return 0;
385385
}
386386

387+
void tb_destroy(TranslationBlock *tb)
388+
{
389+
qemu_spin_destroy(&tb->jmp_lock);
390+
}
391+
387392
bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)
388393
{
389394
TranslationBlock *tb;
@@ -413,6 +418,7 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)
413418
/* one-shot translation, invalidate it immediately */
414419
tb_phys_invalidate(tb, -1);
415420
tcg_tb_remove(tb);
421+
tb_destroy(tb);
416422
}
417423
r = true;
418424
}
@@ -541,6 +547,15 @@ static PageDesc *page_find_alloc(tb_page_addr_t index, int alloc)
541547
#endif
542548
existing = atomic_cmpxchg(lp, NULL, pd);
543549
if (unlikely(existing)) {
550+
#ifndef CONFIG_USER_ONLY
551+
{
552+
int i;
553+
554+
for (i = 0; i < V_L2_SIZE; i++) {
555+
qemu_spin_destroy(&pd[i].lock);
556+
}
557+
}
558+
#endif
544559
g_free(pd);
545560
pd = existing;
546561
}
@@ -1886,6 +1901,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
18861901

18871902
orig_aligned -= ROUND_UP(sizeof(*tb), qemu_icache_linesize);
18881903
atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned);
1904+
tb_destroy(tb);
18891905
return existing_tb;
18901906
}
18911907
tcg_tb_insert(tb);
@@ -2235,6 +2251,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
22352251
tb_phys_invalidate(tb->orig_tb, -1);
22362252
}
22372253
tcg_tb_remove(tb);
2254+
tb_destroy(tb);
22382255
}
22392256

22402257
/* TODO: If env->pc != tb->pc (i.e. the faulting instruction was not

configure

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ gprof="no"
395395
debug_tcg="no"
396396
debug="no"
397397
sanitizers="no"
398+
tsan="no"
398399
fortify_source=""
399400
strip_opt="yes"
400401
tcg_interpreter="no"
@@ -1152,6 +1153,10 @@ for opt do
11521153
;;
11531154
--disable-sanitizers) sanitizers="no"
11541155
;;
1156+
--enable-tsan) tsan="yes"
1157+
;;
1158+
--disable-tsan) tsan="no"
1159+
;;
11551160
--enable-sparse) sparse="yes"
11561161
;;
11571162
--disable-sparse) sparse="no"
@@ -1764,6 +1769,7 @@ Advanced options (experts only):
17641769
--with-pkgversion=VERS use specified string as sub-version of the package
17651770
--enable-debug enable common debug build options
17661771
--enable-sanitizers enable default sanitizers
1772+
--enable-tsan enable thread sanitizer
17671773
--disable-strip disable stripping binaries
17681774
--disable-werror disable compilation abort on warning
17691775
--disable-stack-protector disable compiler-provided stack protection
@@ -4312,7 +4318,6 @@ EOF
43124318
mkdir -p dtc
43134319
if [ "$pwd_is_source_path" != "y" ] ; then
43144320
symlink "$source_path/dtc/Makefile" "dtc/Makefile"
4315-
symlink "$source_path/dtc/scripts" "dtc/scripts"
43164321
fi
43174322
fdt_cflags="-I\$(SRC_PATH)/dtc/libfdt"
43184323
fdt_ldflags="-L\$(BUILD_DIR)/dtc/libfdt"
@@ -6221,6 +6226,30 @@ if test "$fuzzing" = "yes" ; then
62216226
fi
62226227
fi
62236228

6229+
# Thread sanitizer is, for now, much noisier than the other sanitizers;
6230+
# keep it separate until that is not the case.
6231+
if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
6232+
error_exit "TSAN is not supported with other sanitiziers."
6233+
fi
6234+
have_tsan=no
6235+
have_tsan_iface_fiber=no
6236+
if test "$tsan" = "yes" ; then
6237+
write_c_skeleton
6238+
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
6239+
have_tsan=yes
6240+
fi
6241+
cat > $TMPC << EOF
6242+
#include <sanitizer/tsan_interface.h>
6243+
int main(void) {
6244+
__tsan_create_fiber(0);
6245+
return 0;
6246+
}
6247+
EOF
6248+
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
6249+
have_tsan_iface_fiber=yes
6250+
fi
6251+
fi
6252+
62246253
##########################################
62256254
# check for libpmem
62266255

@@ -6378,6 +6407,16 @@ if test "$have_asan" = "yes"; then
63786407
"Without code annotation, the report may be inferior."
63796408
fi
63806409
fi
6410+
if test "$have_tsan" = "yes" ; then
6411+
if test "$have_tsan_iface_fiber" = "yes" ; then
6412+
QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
6413+
QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
6414+
else
6415+
error_exit "Cannot enable TSAN due to missing fiber annotation interface."
6416+
fi
6417+
elif test "$tsan" = "yes" ; then
6418+
error_exit "Cannot enable TSAN due to missing sanitize thread interface."
6419+
fi
63816420
if test "$have_ubsan" = "yes"; then
63826421
QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
63836422
QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
@@ -6413,7 +6452,8 @@ if test "$werror" = "yes"; then
64136452
QEMU_CFLAGS="-Werror $QEMU_CFLAGS"
64146453
fi
64156454

6416-
if test "$solaris" = "no" ; then
6455+
# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
6456+
if test "$solaris" = "no" && test "$tsan" = "no"; then
64176457
if $ld --version 2>/dev/null | grep "GNU ld" >/dev/null 2>/dev/null ; then
64186458
QEMU_LDFLAGS="-Wl,--warn-common $QEMU_LDFLAGS"
64196459
fi
@@ -7477,6 +7517,10 @@ if test "$have_asan_iface_fiber" = "yes" ; then
74777517
echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
74787518
fi
74797519

7520+
if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
7521+
echo "CONFIG_TSAN=y" >> $config_host_mak
7522+
fi
7523+
74807524
if test "$has_environ" = "yes" ; then
74817525
echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak
74827526
fi

cpus-common.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void cpu_list_remove(CPUState *cpu)
9797
}
9898

9999
struct qemu_work_item {
100-
struct qemu_work_item *next;
100+
QSIMPLEQ_ENTRY(qemu_work_item) node;
101101
run_on_cpu_func func;
102102
run_on_cpu_data data;
103103
bool free, exclusive, done;
@@ -106,13 +106,7 @@ struct qemu_work_item {
106106
static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)
107107
{
108108
qemu_mutex_lock(&cpu->work_mutex);
109-
if (cpu->queued_work_first == NULL) {
110-
cpu->queued_work_first = wi;
111-
} else {
112-
cpu->queued_work_last->next = wi;
113-
}
114-
cpu->queued_work_last = wi;
115-
wi->next = NULL;
109+
QSIMPLEQ_INSERT_TAIL(&cpu->work_list, wi, node);
116110
wi->done = false;
117111
qemu_mutex_unlock(&cpu->work_mutex);
118112

@@ -306,17 +300,14 @@ void process_queued_cpu_work(CPUState *cpu)
306300
{
307301
struct qemu_work_item *wi;
308302

309-
if (cpu->queued_work_first == NULL) {
303+
qemu_mutex_lock(&cpu->work_mutex);
304+
if (QSIMPLEQ_EMPTY(&cpu->work_list)) {
305+
qemu_mutex_unlock(&cpu->work_mutex);
310306
return;
311307
}
312-
313-
qemu_mutex_lock(&cpu->work_mutex);
314-
while (cpu->queued_work_first != NULL) {
315-
wi = cpu->queued_work_first;
316-
cpu->queued_work_first = wi->next;
317-
if (!cpu->queued_work_first) {
318-
cpu->queued_work_last = NULL;
319-
}
308+
while (!QSIMPLEQ_EMPTY(&cpu->work_list)) {
309+
wi = QSIMPLEQ_FIRST(&cpu->work_list);
310+
QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node);
320311
qemu_mutex_unlock(&cpu->work_mutex);
321312
if (wi->exclusive) {
322313
/* Running work items outside the BQL avoids the following deadlock:

cpus.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,19 @@ bool cpu_is_stopped(CPUState *cpu)
9797
return cpu->stopped || !runstate_is_running();
9898
}
9999

100+
static inline bool cpu_work_list_empty(CPUState *cpu)
101+
{
102+
bool ret;
103+
104+
qemu_mutex_lock(&cpu->work_mutex);
105+
ret = QSIMPLEQ_EMPTY(&cpu->work_list);
106+
qemu_mutex_unlock(&cpu->work_mutex);
107+
return ret;
108+
}
109+
100110
static bool cpu_thread_is_idle(CPUState *cpu)
101111
{
102-
if (cpu->stop || cpu->queued_work_first) {
112+
if (cpu->stop || !cpu_work_list_empty(cpu)) {
103113
return false;
104114
}
105115
if (cpu_is_stopped(cpu)) {
@@ -1518,7 +1528,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
15181528
cpu = first_cpu;
15191529
}
15201530

1521-
while (cpu && !cpu->queued_work_first && !cpu->exit_request) {
1531+
while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
15221532

15231533
atomic_mb_set(&tcg_current_rr_cpu, cpu);
15241534
current_cpu = cpu;

0 commit comments

Comments
 (0)