From patchwork Fri Aug 30 03:51:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 2851757 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 37C1E9F88A for ; Fri, 30 Aug 2013 04:04:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 590072035C for ; Fri, 30 Aug 2013 04:04:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89B382034D for ; Fri, 30 Aug 2013 04:04:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752541Ab3H3EEu (ORCPT ); Fri, 30 Aug 2013 00:04:50 -0400 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:43074 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752099Ab3H3EEt (ORCPT ); Fri, 30 Aug 2013 00:04:49 -0400 X-Greylist: delayed 934 seconds by postgrey-1.27 at vger.kernel.org; Fri, 30 Aug 2013 00:04:49 EDT Received: from mfs5.rdh.ecl.ntt.co.jp (mfs5.rdh.ecl.ntt.co.jp [129.60.39.144]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id r7U3n8EM019253; Fri, 30 Aug 2013 12:49:08 +0900 Received: from mfs5.rdh.ecl.ntt.co.jp (localhost.localdomain [127.0.0.1]) by mfs5.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id D26ACE0144; Fri, 30 Aug 2013 12:49:08 +0900 (JST) Received: from imail2.m.ecl.ntt.co.jp (imail2.m.ecl.ntt.co.jp [129.60.5.247]) by mfs5.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id C671EE0142; Fri, 30 Aug 2013 12:49:08 +0900 (JST) Received: from yshpad ([129.60.241.195]) by imail2.m.ecl.ntt.co.jp (8.13.8/8.13.8) with SMTP id r7U3n8u9024723; Fri, 30 Aug 2013 12:49:08 +0900 Date: Fri, 30 Aug 2013 12:51:21 +0900 From: Takuya Yoshikawa To: gleb@redhat.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, xiaoguangrong@linux.vnet.ibm.com Subject: [PATCH 1/2] KVM: Take mmu_lock only while write-protecting pages in get_dirty_log Message-Id: <20130830125121.e8ef36de.yoshikawa_takuya_b1@lab.ntt.co.jp> In-Reply-To: <20130830125011.ba85e94d.yoshikawa_takuya_b1@lab.ntt.co.jp> References: <20130830125011.ba85e94d.yoshikawa_takuya_b1@lab.ntt.co.jp> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-TM-AS-MML: No Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Xiao's "KVM: MMU: flush tlb if the spte can be locklessly modified" allows us to release mmu_lock before flushing TLBs. Signed-off-by: Takuya Yoshikawa Cc: Xiao Guangrong --- Xiao can change the remaining mmu_lock to RCU's read-side lock: The grace period will be reasonably limited. arch/x86/kvm/mmu.c | 4 ++++ arch/x86/kvm/x86.c | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 5d9efb1..c6da9ba 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1249,6 +1249,8 @@ void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, { unsigned long *rmapp; + spin_lock(&kvm->mmu_lock); + while (mask) { rmapp = __gfn_to_rmap(slot->base_gfn + gfn_offset + __ffs(mask), PT_PAGE_TABLE_LEVEL, slot); @@ -1257,6 +1259,8 @@ void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, /* clear the first set bit */ mask &= mask - 1; } + + spin_unlock(&kvm->mmu_lock); } static bool rmap_write_protect(struct kvm *kvm, u64 gfn) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e5ca72a..1d1f6df 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3543,8 +3543,6 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) dirty_bitmap_buffer = dirty_bitmap + n / sizeof(long); memset(dirty_bitmap_buffer, 0, n); - spin_lock(&kvm->mmu_lock); - for (i = 0; i < n / sizeof(long); i++) { unsigned long mask; gfn_t offset; @@ -3563,8 +3561,6 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) if (is_dirty) kvm_flush_remote_tlbs(kvm); - spin_unlock(&kvm->mmu_lock); - r = -EFAULT; if (copy_to_user(log->dirty_bitmap, dirty_bitmap_buffer, n)) goto out;