From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752285AbdI2OyD (ORCPT ); Fri, 29 Sep 2017 10:54:03 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38253 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751975AbdI2OyB (ORCPT ); Fri, 29 Sep 2017 10:54:01 -0400 X-Google-Smtp-Source: AOwi7QCmEiU08Ct9E/7ZQgMuWUDwG29cjW0cf92WY35iwmKH9aBHTrOJiGatrZqwglXbA7cH6yGU+Q== Subject: Re: [PATCH] kvm/x86: Handle async PF in RCU read-side critical sections To: Boqun Feng , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: "Paul E. McKenney" , Peter Zijlstra , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org References: <20170929110148.3467-1-boqun.feng@gmail.com> From: Paolo Bonzini Message-ID: <95ecfeff-093d-4438-dbcb-ecc81abca993@redhat.com> Date: Fri, 29 Sep 2017 16:53:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170929110148.3467-1-boqun.feng@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/09/2017 13:01, Boqun Feng wrote: > Sasha Levin reported a WARNING: > > | WARNING: CPU: 0 PID: 6974 at kernel/rcu/tree_plugin.h:329 > | rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] > | WARNING: CPU: 0 PID: 6974 at kernel/rcu/tree_plugin.h:329 > | rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 > ... > | CPU: 0 PID: 6974 Comm: syz-fuzzer Not tainted 4.13.0-next-20170908+ #246 > | Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS > | 1.10.1-1ubuntu1 04/01/2014 > | Call Trace: > ... > | RIP: 0010:rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] > | RIP: 0010:rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 > | RSP: 0018:ffff88003b2debc8 EFLAGS: 00010002 > | RAX: 0000000000000001 RBX: 1ffff1000765bd85 RCX: 0000000000000000 > | RDX: 1ffff100075d7882 RSI: ffffffffb5c7da20 RDI: ffff88003aebc410 > | RBP: ffff88003b2def30 R08: dffffc0000000000 R09: 0000000000000001 > | R10: 0000000000000000 R11: 0000000000000000 R12: ffff88003b2def08 > | R13: 0000000000000000 R14: ffff88003aebc040 R15: ffff88003aebc040 > | __schedule+0x201/0x2240 kernel/sched/core.c:3292 > | schedule+0x113/0x460 kernel/sched/core.c:3421 > | kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158 > | do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 > | async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 > | RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 > | RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 > | RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 > | RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 > | RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 > | R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 > | R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 > | vsnprintf+0x173/0x1700 lib/vsprintf.c:2136 > | sprintf+0xbe/0xf0 lib/vsprintf.c:2386 > | proc_self_get_link+0xfb/0x1c0 fs/proc/self.c:23 > | get_link fs/namei.c:1047 [inline] > | link_path_walk+0x1041/0x1490 fs/namei.c:2127 > ... > > And this happened when we hit a page fault in an RCU read-side critical > section and then we tried to reschedule in kvm_async_pf_task_wait(), > this reschedule would hit the WARN in rcu_preempt_note_context_switch(), > and be treated as a sleep in RCU read-side critical section, which is > not allowed(even in preemptible RCU). Just a small fix to the commit message: This happened when the host hit a page fault, and delivered it as in an async page fault, while the guest was in an RCU read-side critical section. The guest then tries to reschedule in kvm_async_pf_task_wait(), but rcu_preempt_note_context_switch() would treat the reschedule as a sleep in RCU read-side critical section, which is not allowed (even in preemptible RCU). Thus the WARN. Queued with that change, thanks. Paolo > To cure this, make kvm_async_pf_task_wait() go to the halt path if the > PF happens in a RCU read-side critical section. > > Reported-by: Sasha Levin > Cc: "Paul E. McKenney" > Cc: Peter Zijlstra > Signed-off-by: Boqun Feng > --- > arch/x86/kernel/kvm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index aa60a08b65b1..e675704fa6f7 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -140,7 +140,8 @@ void kvm_async_pf_task_wait(u32 token) > > n.token = token; > n.cpu = smp_processor_id(); > - n.halted = is_idle_task(current) || preempt_count() > 1; > + n.halted = is_idle_task(current) || preempt_count() > 1 || > + rcu_preempt_depth(); > init_swait_queue_head(&n.wq); > hlist_add_head(&n.link, &b->list); > raw_spin_unlock(&b->lock); >