linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Another preempt folding issue?
@ 2014-02-11 18:34 Stefan Bader
  2014-02-11 19:45 ` Peter Zijlstra
  0 siblings, 1 reply; 34+ messages in thread
From: Stefan Bader @ 2014-02-11 18:34 UTC (permalink / raw)
  To: Peter Zijlstra, Paolo Bonzini; +Cc: Linux Kernel Mailing List, kvm

[-- Attachment #1: Type: text/plain, Size: 2624 bytes --]

Hi Peter,

I am currently looking at a weird issue that manifest itself when trying to run
kvm enabled qemu on a i386 host (v3.13 kernel, oh and potentially important the
cpu is 64bit capable, so qemu-system-x86_64 is called). Sooner or later this
causes softlockup messages on the host. I tracked this down to __vcpu_run in
arch/x86/kvm/x86.c which does a loop which in that case never seems to make
progress or exit.

What I found is that vcpu_enter_guest will exit quickly without causing the loop
to exit when need_resched() is true. Looking at a crash dump I took, this was
the case (thread_info->flags had TIF_NEED_RESCHED set). So after immediately
returning __vcpu_run has the following code:

        if (need_resched()) {
                srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
                kvm_resched(vcpu); // now cond_resched();
                vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
        }

The kvm_resched basically would end up doing a cond_resched() which now checks
preempt_count() to be 0. If that is zero it will do the reschedule, otherwise it
just does nothing. Looking at the percpu variables in the dump, I saw that
the preempt_count was 0x8000000 (actually it was 0x80110000 but that was me
triggering the kexec crashdump with sysrq-c).

I saw that there have been some changes in the upstream kernel and have picked
the following:
1) x86, acpi, idle: Restructure the mwait idle routines
2) x86, idle: Use static_cpu_has() for CLFLUSH workaround, add barriers
3) sched/preempt: Fix up missed PREEMPT_NEED_RESCHED folding
4) sched/preempt/x86: Fix voluntary preempt for x86

Patch 1) and 2) as dependencies of 3) (to get the mwait function correct and to
the other file). Finally 4) is fixing up 3). [maybe worth suggesting to do for
3.13.y stable].

Still, with all those I got the softlockup. Since I knew from the dump info that
something is wrong with the folding, I made the pragmatic approach and added the
following:

        if (need_resched()) {
                srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
+               preempt_fold_need_resched();
                kvm_resched(vcpu); // now cond_resched();
                vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
        }

And this lets the kvm guest run without the softlockups! However I am less than
convinced that this is the right thing to do. Somehow something done when
converting the preempt_count into percpu has caused at least the i386 side to
get into this mess (as there has not been any whining about 64bit). Just fail to
see what.

-Stefan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 901 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2014-03-25  8:24 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-11 18:34 Another preempt folding issue? Stefan Bader
2014-02-11 19:45 ` Peter Zijlstra
2014-02-12  8:20   ` Stefan Bader
2014-02-12 10:37     ` Peter Zijlstra
2014-02-12 10:40       ` Borislav Petkov
2014-02-12 11:09         ` Stefan Bader
2014-02-12 11:54           ` Peter Zijlstra
2014-02-13 17:00             ` Stefan Bader
2014-02-13 17:38               ` Peter Zijlstra
2014-02-13 18:03                 ` Stefan Bader
2014-02-13 18:26                   ` Peter Zijlstra
2014-02-14 13:34                     ` Borislav Petkov
2014-02-14 13:40                       ` Stefan Bader
2014-02-14 14:24                       ` Stefan Bader
2014-02-14 14:47                         ` Borislav Petkov
2014-02-14 17:02                           ` Stefan Bader
2014-02-14 17:21                             ` Peter Zijlstra
2014-02-20 15:38                               ` Stefan Bader
2014-02-20 15:50                                 ` Peter Zijlstra
2014-03-24 17:39                                   ` Paolo Bonzini
2014-03-25  8:23                                     ` Stefan Bader
2014-02-14 17:33                             ` Borislav Petkov
2014-02-14 18:23                               ` Stefan Bader
2014-02-14 19:03                                 ` Stefan Bader
2014-02-14 15:21                         ` Another preempt folding issue? (maybe bisect) Borislav Petkov
2014-02-14 15:28                           ` Stefan Bader
2014-02-14 15:44                             ` Borislav Petkov
2014-02-14 16:21                           ` Peter Zijlstra
2014-02-13 18:25               ` Another preempt folding issue? Peter Zijlstra
2014-02-14 10:55                 ` Stefan Bader
2014-02-14 13:17                   ` Peter Zijlstra
2014-02-14 11:24                 ` Stefan Bader
2014-02-14 11:49                   ` Peter Zijlstra
2014-02-12 11:12         ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).