From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Xu <peterx@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sean Christopherson <sean.j.christopherson@intel.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Andrew Jones <drjones@redhat.com>
Subject: Re: [PATCH v13 13/14] KVM: selftests: Let dirty_log_test async for dirty ring test
Date: Fri, 6 Nov 2020 12:27:54 +0100 [thread overview]
Message-ID: <6d5eb99e-e068-e5a6-522f-07ef9c33127f@redhat.com> (raw)
In-Reply-To: <20201001012239.6159-1-peterx@redhat.com>
On 01/10/20 03:22, Peter Xu wrote:
> +
> +static void vcpu_sig_handler(int sig)
> +{
> + TEST_ASSERT(sig == SIG_IPI, "unknown signal: %d", sig);
> +}
> +
Unless you also use run->immediate_exit in vcpu_kick, this is racy. The
alternative is to _not_ set up a signal handler and instead block the
signal. KVM_SET_SIGNAL_MASK unblocks the signal inside the VM and on
-EINTR sigwait accepts the signal (removes it from the set of pending
signal).
This is a bit more complicated, but I think it's a good idea to do it
this way for documentation purposes. Here is the patch:
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c
b/tools/testing/selftests/kvm/dirty_log_test.c
index 4b404dfdc2f9..9a5b876b74af 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -172,11 +172,6 @@ static pthread_t vcpu_thread;
/* Only way to pass this to the signal handler */
static struct kvm_vm *current_vm;
-static void vcpu_sig_handler(int sig)
-{
- TEST_ASSERT(sig == SIG_IPI, "unknown signal: %d", sig);
-}
-
static void vcpu_kick(void)
{
pthread_kill(vcpu_thread, SIG_IPI);
@@ -484,13 +479,26 @@ static void *vcpu_worker(void *data)
struct kvm_vm *vm = data;
uint64_t *guest_array;
uint64_t pages_count = 0;
- struct sigaction sigact;
+ struct kvm_signal_mask *sigmask = alloca(offsetof(struct
kvm_signal_mask, sigset)
+ + sizeof(sigset_t));
+ sigset_t *sigset = (sigset_t *) &sigmask->sigset;
current_vm = vm;
vcpu_fd = vcpu_get_fd(vm, VCPU_ID);
- memset(&sigact, 0, sizeof(sigact));
- sigact.sa_handler = vcpu_sig_handler;
- sigaction(SIG_IPI, &sigact, NULL);
+
+ /*
+ * SIG_IPI is unblocked atomically while in KVM_RUN. It causes the
+ * ioctl to return with -EINTR, but it is still pending and we need
+ * to accept it with the sigwait.
+ */
+ sigmask->len = 8;
+ pthread_sigmask(0, NULL, sigset);
+ 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);
guest_array = addr_gva2hva(vm, (vm_vaddr_t)random_array);
@@ -500,6 +508,11 @@ static void *vcpu_worker(void *data)
pages_count += TEST_PAGES_PER_LOOP;
/* Let the guest dirty the random pages */
ret = ioctl(vcpu_fd, KVM_RUN, NULL);
+ if (ret == -EINTR) {
+ int sig = -1;
+ sigwait(sigset, &sig);
+ assert(sig == SIG_IPI);
+ }
log_mode_after_vcpu_run(vm, ret, errno);
}
next prev parent reply other threads:[~2020-11-06 11:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 1:20 [PATCH v13 00/14] KVM: Dirty ring interface Peter Xu
2020-10-01 1:20 ` [PATCH v13 01/14] KVM: Documentation: Update entry for KVM_X86_SET_MSR_FILTER Peter Xu
2020-10-01 1:20 ` [PATCH v13 02/14] KVM: Cache as_id in kvm_memory_slot Peter Xu
2020-10-01 1:20 ` [PATCH v13 03/14] KVM: X86: Don't track dirty for KVM_SET_[TSS_ADDR|IDENTITY_MAP_ADDR] Peter Xu
2020-10-01 1:20 ` [PATCH v13 04/14] KVM: Pass in kvm pointer into mark_page_dirty_in_slot() Peter Xu
2020-10-01 1:22 ` [PATCH v13 05/14] KVM: X86: Implement ring-based dirty memory tracking Peter Xu
2020-11-06 10:56 ` Paolo Bonzini
2020-10-01 1:22 ` [PATCH v13 06/14] KVM: Make dirty ring exclusive to dirty bitmap log Peter Xu
2020-11-06 11:00 ` Paolo Bonzini
2020-10-01 1:22 ` [PATCH v13 07/14] KVM: Don't allocate dirty bitmap if dirty ring is enabled Peter Xu
2020-10-01 1:22 ` [PATCH v13 08/14] KVM: selftests: Always clear dirty bitmap after iteration Peter Xu
2020-10-01 1:22 ` [PATCH v13 09/14] KVM: selftests: Sync uapi/linux/kvm.h to tools/ Peter Xu
2020-10-01 1:22 ` [PATCH v13 10/14] KVM: selftests: Use a single binary for dirty/clear log test Peter Xu
2020-10-01 1:22 ` [PATCH v13 11/14] KVM: selftests: Introduce after_vcpu_run hook for dirty " Peter Xu
2020-10-01 1:22 ` [PATCH v13 12/14] KVM: selftests: Add dirty ring buffer test Peter Xu
2020-10-01 1:22 ` [PATCH v13 13/14] KVM: selftests: Let dirty_log_test async for dirty ring test Peter Xu
2020-11-06 11:27 ` Paolo Bonzini [this message]
2020-11-06 18:06 ` Peter Xu
2020-11-06 18:15 ` Paolo Bonzini
2020-11-06 18:27 ` Peter Xu
2020-10-01 1:22 ` [PATCH v13 14/14] KVM: selftests: Add "-c" parameter to dirty log test Peter Xu
2020-11-06 11:28 ` [PATCH v13 00/14] KVM: Dirty ring interface Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6d5eb99e-e068-e5a6-522f-07ef9c33127f@redhat.com \
--to=pbonzini@redhat.com \
--cc=dgilbert@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=sean.j.christopherson@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.