summaryrefslogtreecommitdiffstats
path: root/util/coroutine-sigaltstack.c
diff options
context:
space:
mode:
authorPeter Maydell2021-01-26 22:08:13 +0100
committerPeter Maydell2021-01-26 22:08:13 +0100
commit565c86af519aa7f4e80622432a053c2a65a9b80e (patch)
tree61de3ad6cd944cbe8cc634aa0526dd0621e7d780 /util/coroutine-sigaltstack.c
parentMerge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2021-01-25-1... (diff)
parentiotests/178: Pass value to invalid option (diff)
downloadqemu-565c86af519aa7f4e80622432a053c2a65a9b80e.tar.gz
qemu-565c86af519aa7f4e80622432a053c2a65a9b80e.tar.xz
qemu-565c86af519aa7f4e80622432a053c2a65a9b80e.zip
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2021-01-26' into staging
Block patches: - Make backup block jobs use asynchronous requests with the block-copy module - Use COR filter node for stream block jobs - Make coroutine-sigaltstack’s qemu_coroutine_new() function thread-safe - Report error string when file locking fails with an unexpected errno - iotest fixes, additions, and some refactoring # gpg: Signature made Tue 26 Jan 2021 14:16:59 GMT # gpg: using RSA key 91BEB60A30DB3E8857D11829F407DB0061D5CF40 # gpg: issuer "mreitz@redhat.com" # gpg: Good signature from "Max Reitz <mreitz@redhat.com>" [full] # Primary key fingerprint: 91BE B60A 30DB 3E88 57D1 1829 F407 DB00 61D5 CF40 * remotes/maxreitz/tags/pull-block-2021-01-26: (53 commits) iotests/178: Pass value to invalid option iotests/118: Drop 'change' test iotests: Add test for the regression fixed in c8bf9a9169 block: report errno when flock fcntl fails simplebench: add bench-backup.py simplebench: bench_block_job: add cmd_options argument simplebench/bench_block_job: use correct shebang line with python3 block/block-copy: drop unused argument of block_copy() block/block-copy: drop unused block_copy_set_progress_callback() qapi: backup: disable copy_range by default backup: move to block-copy block/backup: drop extra gotos from backup_run() block/block-copy: make progress_bytes_callback optional iotests: 257: prepare for backup over block-copy iotests: 219: prepare for backup over block-copy iotests: 185: prepare for backup over block-copy iotests/129: Limit backup's max-chunk/max-workers iotests: 56: prepare for backup over block-copy qapi: backup: add max-chunk and max-workers to x-perf struct job: call job_enter from job_pause ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util/coroutine-sigaltstack.c')
-rw-r--r--util/coroutine-sigaltstack.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/util/coroutine-sigaltstack.c b/util/coroutine-sigaltstack.c
index aade82afb8..e99b8a4f9c 100644
--- a/util/coroutine-sigaltstack.c
+++ b/util/coroutine-sigaltstack.c
@@ -157,6 +157,7 @@ Coroutine *qemu_coroutine_new(void)
sigset_t sigs;
sigset_t osigs;
sigjmp_buf old_env;
+ static pthread_mutex_t sigusr2_mutex = PTHREAD_MUTEX_INITIALIZER;
/* The way to manipulate stack is with the sigaltstack function. We
* prepare a stack, with it delivering a signal to ourselves and then
@@ -186,6 +187,12 @@ Coroutine *qemu_coroutine_new(void)
sa.sa_handler = coroutine_trampoline;
sigfillset(&sa.sa_mask);
sa.sa_flags = SA_ONSTACK;
+
+ /*
+ * sigaction() is a process-global operation. We must not run
+ * this code in multiple threads at once.
+ */
+ pthread_mutex_lock(&sigusr2_mutex);
if (sigaction(SIGUSR2, &sa, &osa) != 0) {
abort();
}
@@ -234,6 +241,8 @@ Coroutine *qemu_coroutine_new(void)
* Restore the old SIGUSR2 signal handler and mask
*/
sigaction(SIGUSR2, &osa, NULL);
+ pthread_mutex_unlock(&sigusr2_mutex);
+
pthread_sigmask(SIG_SETMASK, &osigs, NULL);
/*