linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Bader <stefan.bader@canonical.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	kvm@vger.kernel.org
Subject: Another preempt folding issue?
Date: Tue, 11 Feb 2014 19:34:51 +0100	[thread overview]
Message-ID: <52FA6D4B.7020709@canonical.com> (raw)

[-- 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 --]

             reply	other threads:[~2014-02-11 18:35 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-11 18:34 Stefan Bader [this message]
2014-02-11 19:45 ` Another preempt folding issue? 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

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=52FA6D4B.7020709@canonical.com \
    --to=stefan.bader@canonical.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    /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 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).