From patchwork Fri Jul 3 08:56:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiejun Chen X-Patchwork-Id: 6713611 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 81743C05AC for ; Fri, 3 Jul 2015 09:02:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF9712061F for ; Fri, 3 Jul 2015 09:02:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF6A120703 for ; Fri, 3 Jul 2015 09:02:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932161AbbGCJBp (ORCPT ); Fri, 3 Jul 2015 05:01:45 -0400 Received: from mga02.intel.com ([134.134.136.20]:46739 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754509AbbGCJBO (ORCPT ); Fri, 3 Jul 2015 05:01:14 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 03 Jul 2015 02:01:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,399,1432623600"; d="scan'208";a="722291203" Received: from tchen0-linux.bj.intel.com ([10.238.135.75]) by orsmga001.jf.intel.com with ESMTP; 03 Jul 2015 02:01:11 -0700 From: Tiejun Chen To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Gleb Natapov , Paolo Bonzini Subject: [[PATCH 2/2] kvm: enable preemption to register/unregister preempt notifier Date: Fri, 3 Jul 2015 16:56:28 +0800 Message-Id: <1435913788-4300-2-git-send-email-tiejun.chen@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435913788-4300-1-git-send-email-tiejun.chen@intel.com> References: <1435913788-4300-1-git-send-email-tiejun.chen@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After commit 1cde2930e154 ("sched/preempt: Add static_key() to preempt_notifiers") is introduced, preempt_notifier_{register, unregister} always hold a mutex, jump_label_mutex. So in current case this shouldn't work further under the circumstance of disabled preemption, and its also safe since we're just handling a per-vcpu stuff with holding vcpu->mutex. Otherwise, some warning messages are posted like this, BUG: scheduling while atomic: qemu-system-x86/17177/0x00000002 2 locks held by qemu-system-x86/17177: #0: (&vcpu->mutex){+.+.+.}, at: [] vcpu_load+0x28/0xf0 [kvm] #1: (jump_label_mutex){+.+.+.}, at: [] static_key_slow_inc+0xc4/0x140 Modules linked in: x86_pkg_temp_thermal kvm_intel kvm Preemption disabled at:[] kvm_vcpu_ioctl+0x7e/0xeb0 [kvm] CPU: 2 PID: 17177 Comm: qemu-system-x86 Tainted: G W 4.1.0+ #30 Hardware name: Dell Inc. OptiPlex 9020/0DNKMN, BIOS A05 12/05/2013 0000000000200206 ffff8801c584bc38 ffffffff81f974ab 0000000000000003 ffff880211289a80 ffff8801c584bc58 ffffffff81f8fd3e 0000000000000001 ffff8802161d5d00 ffff8801c584bcb8 ffffffff81fa43dc ffff8801c584bd68 Call Trace: [] dump_stack+0x95/0xf2 [] __schedule_bug+0x108/0x126 [] __schedule+0x12dc/0x1590 [] schedule+0x75/0x150 [] ? mutex_lock_nested+0x393/0x780 [] schedule_preempt_disabled+0x30/0x60 [] mutex_lock_nested+0x24a/0x780 [] ? static_key_slow_inc+0xc4/0x140 [] ? static_key_slow_inc+0xc4/0x140 [] ? vcpu_load+0x28/0xf0 [kvm] [] static_key_slow_inc+0xc4/0x140 [] preempt_notifier_register+0x25/0x70 [] vcpu_load+0x76/0xf0 [kvm] [] kvm_vcpu_ioctl+0x7e/0xeb0 [kvm] [] ? __lock_is_held+0x70/0xa0 [] ? get_parent_ip+0x19/0x90 [] do_vfs_ioctl+0x3c4/0x910 [] ? expand_files+0x311/0x360 [] ? selinux_file_ioctl+0x6f/0x150 [] SyS_ioctl+0xad/0xe0 [] entry_SYSCALL_64_fastpath+0x12/0x6f CC: Gleb Natapov CC: Paolo Bonzini Signed-off-by: Tiejun Chen --- virt/kvm/kvm_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 848af90..bde5f66f 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -127,8 +127,8 @@ int vcpu_load(struct kvm_vcpu *vcpu) if (mutex_lock_killable(&vcpu->mutex)) return -EINTR; - cpu = get_cpu(); preempt_notifier_register(&vcpu->preempt_notifier); + cpu = get_cpu(); kvm_arch_vcpu_load(vcpu, cpu); put_cpu(); return 0; @@ -138,8 +138,8 @@ void vcpu_put(struct kvm_vcpu *vcpu) { preempt_disable(); kvm_arch_vcpu_put(vcpu); - preempt_notifier_unregister(&vcpu->preempt_notifier); preempt_enable(); + preempt_notifier_unregister(&vcpu->preempt_notifier); mutex_unlock(&vcpu->mutex); }