Skip to contentSkip to conversation

KVM: selftests: Always run vCPU thread with blocked SIG_IPI

PATCH In review Paolo Bonzini 2 participants 5 messages Apr 20, 2021

Subsystems (3)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 KVM: selftests: Always run vCPU thread with blocked SIG_IPI

The main thread could start to send SIG_IPI at any time, even before signal blocked on vcpu thread. Therefore, start the vcpu thread with the signal blocked.

Without this patch, on very busy cores the dirty_log_test could fail directly on receiving a SIGUSR1 without a handler (when vcpu runs far slower than main).

---
 tools/testing/selftests/kvm/dirty_log_test.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/dirty_log_test.c +7 -2
index ffa4e2791926..81edbd23d371 100644
@@ -527,9 +527,8 @@ static void *vcpu_worker(void *data)
 	 */
 	sigmask->len = 8;
 	pthread_sigmask(0, NULL, sigset);
+	sigdelset(sigset, SIG_IPI);
 	vcpu_ioctl(vm, VCPU_ID, KVM_SET_SIGNAL_MASK, sigmask);
-	sigaddset(sigset, SIG_IPI);
-	pthread_sigmask(SIG_BLOCK, sigset, NULL);
 
 	sigemptyset(sigset);
 	sigaddset(sigset, SIG_IPI);
@@ -858,6 +857,7 @@ int main(int argc, char *argv[])
 		.interval = TEST_HOST_LOOP_INTERVAL,
 	};
 	int opt, i;
+	sigset_t sigset;
 
 	sem_init(&sem_vcpu_stop, 0, 0);
 	sem_init(&sem_vcpu_cont, 0, 0);
@@ -916,6 +916,11 @@ int main(int argc, char *argv[])
 
 	srandom(time(0));
 
+	/* Ensure that vCPU threads start with SIG_IPI blocked.  */
+	sigemptyset(&sigset);
+	sigaddset(&sigset, SIG_IPI);
+	pthread_sigmask(SIG_BLOCK, &sigset, NULL);
+
 	if (host_log_mode_option == LOG_MODE_ALL) {
 		/* Run each log mode */
 		for (i = 0; i < LOG_MODE_NUM; i++) {
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Paolo Bonzini

The main thread could start to send SIG_IPI at any time, even before signal blocked on vcpu thread. Therefore, start the vcpu thread with the signal blocked.

Without this patch, on very busy cores the dirty_log_test could fail directly on receiving a SIGUSR1 without a handler (when vcpu runs far slower than main).

Yes, indeed better! :)

Signature · 1 line
Peter Xu
#2 lore raw
Quoted 8 lines · Peter Xu
Quoted 7 lines · Paolo Bonzini

The main thread could start to send SIG_IPI at any time, even before signal blocked on vcpu thread. Therefore, start the vcpu thread with the signal blocked.

Without this patch, on very busy cores the dirty_log_test could fail directly on receiving a SIGUSR1 without a handler (when vcpu runs far slower than main).

Quoted 7 lines
Quoted 3 lines

Yes, indeed better! :)

I just remembered one thing: this will avoid program quits, but still we'll get the signal missing. From that pov I slightly prefer the old patch. However not a big deal so far as only dirty ring uses SIG_IPI, so there's always ring full which will just delay the kick. It's just we need to remember this when we extend IPI to non-dirty-ring tests as the kick is prone to be lost then.

Thanks,

Signature · 1 line
Peter Xu
author maintainer
#3 lore raw
Quoted 13 lines · Peter Xu
Quoted 12 lines · Peter Xu
Quoted 10 lines · Paolo Bonzini

The main thread could start to send SIG_IPI at any time, even before signal blocked on vcpu thread. Therefore, start the vcpu thread with the signal blocked.

Without this patch, on very busy cores the dirty_log_test could fail directly on receiving a SIGUSR1 without a handler (when vcpu runs far slower than main).

Quoted 6 lines
Quoted 3 lines

Yes, indeed better! :)

I just remembered one thing: this will avoid program quits, but still we'll get the signal missing.

In what sense the signal will be missing? As long as the thread exists, the signal will be accepted (but not delivered because it is blocked); it will then be delivered on the first KVM_RUN.

Paolo

From that pov I slightly prefer the old patch. However

Quoted 6 lines

not a big deal so far as only dirty ring uses SIG_IPI, so there's always ring full which will just delay the kick. It's just we need to remember this when we extend IPI to non-dirty-ring tests as the kick is prone to be lost then.

Thanks,

#4 lore raw
Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Peter Xu
Quoted 14 lines · Peter Xu
Quoted 10 lines · Paolo Bonzini

The main thread could start to send SIG_IPI at any time, even before signal blocked on vcpu thread. Therefore, start the vcpu thread with the signal blocked.

Without this patch, on very busy cores the dirty_log_test could fail directly on receiving a SIGUSR1 without a handler (when vcpu runs far slower than main).

Yes, indeed better! :)

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

I just remembered one thing: this will avoid program quits, but still we'll get the signal missing.

In what sense the signal will be missing? As long as the thread exists, the signal will be accepted (but not delivered because it is blocked); it will then be delivered on the first KVM_RUN.

Ah right.. Thanks,

Signature · 1 line
Peter Xu