]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
kvm/x86: Avoid async PF preempting the kernel incorrectly
authorBoqun Feng <boqun.feng@gmail.com>
Tue, 3 Oct 2017 13:36:51 +0000 (21:36 +0800)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 19 Oct 2017 14:49:15 +0000 (09:49 -0500)
commita71ae6ea3591ac61cfa955061860c8743af5b6e1
treeef1c1b644af504018ecc31e2f77e13ae3ea8c5a7
parent0be85b002bb693270de6e05c7ee74887a3ad60bd
kvm/x86: Avoid async PF preempting the kernel incorrectly

BugLink: http://bugs.launchpad.net/bugs/1723145
commit a2b7861bb33b2538420bb5d8554153484d3f961f upstream.

Currently, in PREEMPT_COUNT=n kernel, kvm_async_pf_task_wait() could call
schedule() to reschedule in some cases.  This could result in
accidentally ending the current RCU read-side critical section early,
causing random memory corruption in the guest, or otherwise preempting
the currently running task inside between preempt_disable and
preempt_enable.

The difficulty to handle this well is because we don't know whether an
async PF delivered in a preemptible section or RCU read-side critical section
for PREEMPT_COUNT=n, since preempt_disable()/enable() and rcu_read_lock/unlock()
are both no-ops in that case.

To cure this, we treat any async PF interrupting a kernel context as one
that cannot be preempted, preventing kvm_async_pf_task_wait() from choosing
the schedule() path in that case.

To do so, a second parameter for kvm_async_pf_task_wait() is introduced,
so that we know whether it's called from a context interrupting the
kernel, and the parameter is set properly in all the callsites.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
arch/x86/include/asm/kvm_para.h
arch/x86/kernel/kvm.c
arch/x86/kvm/mmu.c