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).
Reported-by: Peter Xu <peterx(a)redhat.com>
Cc: stable(a)vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini(a)redhat.com>
---
tools/testing/selftests/kvm/dirty_log_test.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index ffa4e2791926..81edbd23d371 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -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++) {
--
2.26.2
+Paolo
On Sun, Apr 18, 2021, Sasha Levin wrote:
> This is a note to let you know that I've just added the patch titled
>
> KVM: VMX: Convert vcpu_vmx.exit_reason to a union
>
> to the 5.10-stable tree which can be found at:
> http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=sum…
>
> The filename of the patch is:
> kvm-vmx-convert-vcpu_vmx.exit_reason-to-a-union.patch
> and it can be found in the queue-5.10 subdirectory.
>
> If you, or anyone else, feels it should not be added to the stable tree,
> please let <stable(a)vger.kernel.org> know about it.
I'm not sure we want this going into stable kernels, even for 5.10 and 5.11.
I assume it got pulled in to resolve a conflict with commit 04c4f2ee3f68 ("KVM:
VMX: Don't use vcpu->run->internal.ndata as an array index"), but that's should
be trivial to resolve since it's just a collision with surrounding code.
Maybe we'll end up with a more painful conflict in the future that would be best
solved by grabbing this refactoring, but I don't think we're there yet.
> commit 1499b54db7d9e7e5f5014307e8391e3ad7986f1f
> Author: Sean Christopherson <seanjc(a)google.com>
> Date: Fri Nov 6 17:03:12 2020 +0800
>
> KVM: VMX: Convert vcpu_vmx.exit_reason to a union
>
> [ Upstream commit 8e53324021645f820a01bf8aa745711c802c8542 ]
>
> Convert vcpu_vmx.exit_reason from a u32 to a union (of size u32). The
> full VM_EXIT_REASON field is comprised of a 16-bit basic exit reason in
> bits 15:0, and single-bit modifiers in bits 31:16.
>
> Historically, KVM has only had to worry about handling the "failed
> VM-Entry" modifier, which could only be set in very specific flows and
> required dedicated handling. I.e. manually stripping the FAILED_VMENTRY
> bit was a somewhat viable approach. But even with only a single bit to
> worry about, KVM has had several bugs related to comparing a basic exit
> reason against the full exit reason store in vcpu_vmx.
>
> Upcoming Intel features, e.g. SGX, will add new modifier bits that can
> be set on more or less any VM-Exit, as opposed to the significantly more
> restricted FAILED_VMENTRY, i.e. correctly handling everything in one-off
> flows isn't scalable. Tracking exit reason in a union forces code to
> explicitly choose between consuming the full exit reason and the basic
> exit, and is a convenient way to document and access the modifiers.
>
> No functional change intended.
>
> Cc: Xiaoyao Li <xiaoyao.li(a)intel.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson(a)intel.com>
> Signed-off-by: Chenyi Qiang <chenyi.qiang(a)intel.com>
> Message-Id: <20201106090315.18606-2-chenyi.qiang(a)intel.com>
> Signed-off-by: Paolo Bonzini <pbonzini(a)redhat.com>
> Signed-off-by: Sasha Levin <sashal(a)kernel.org>
On Mon, Apr 19, 2021 at 2:37 PM Nathan Chancellor <nathan(a)kernel.org> wrote:
>
> This should not have been merged into mainline by itself. It was a fix
> for "gcov: use kvmalloc()", which is still in -mm/-next. Merging it
> alone has now broken the build:
>
> https://github.com/ClangBuiltLinux/continuous-integration2/runs/2384465683?…
>
> Could it please be reverted in mainline [..]
Now reverted in my tree.
Sasha and stable cc'd too, since it was apparently auto-selected there..
Linus