From patchwork Tue Feb 18 08:23:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 3667461 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 A5D309F1EE for ; Tue, 18 Feb 2014 08:25:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D5472201FD for ; Tue, 18 Feb 2014 08:25:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CAFC201F7 for ; Tue, 18 Feb 2014 08:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754289AbaBRIZc (ORCPT ); Tue, 18 Feb 2014 03:25:32 -0500 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:57356 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754045AbaBRIZc (ORCPT ); Tue, 18 Feb 2014 03:25:32 -0500 Received: from mfs6.rdh.ecl.ntt.co.jp (mfs6.rdh.ecl.ntt.co.jp [129.60.39.149]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id s1I8J4o9027501; Tue, 18 Feb 2014 17:19:04 +0900 Received: from mfs6.rdh.ecl.ntt.co.jp (localhost.localdomain [127.0.0.1]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 9D75AE013A; Tue, 18 Feb 2014 17:19:04 +0900 (JST) Received: from imail2.m.ecl.ntt.co.jp (imail2.m.ecl.ntt.co.jp [129.60.5.247]) by mfs6.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 883AFE0138; Tue, 18 Feb 2014 17:19:04 +0900 (JST) Received: from yshpad ([129.60.241.228]) by imail2.m.ecl.ntt.co.jp (8.13.8/8.13.8) with SMTP id s1I8J4oT018696; Tue, 18 Feb 2014 17:19:04 +0900 Date: Tue, 18 Feb 2014 17:23:47 +0900 From: Takuya Yoshikawa To: gleb@kernel.org, pbonzini@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH B] KVM: Explain tlbs_dirty trick in kvm_flush_remote_tlbs() Message-Id: <20140218172347.b38d66b3.yoshikawa_takuya_b1@lab.ntt.co.jp> In-Reply-To: <20140218172150.7723d3a5.yoshikawa_takuya_b1@lab.ntt.co.jp> References: <20140218172150.7723d3a5.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=-7.5 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 When this was introduced, kvm_flush_remote_tlbs() could be called without holding mmu_lock. It is now acknowledged that the function must be called before releasing mmu_lock, and all callers have already been changed to do so. This patch adds a comment explaining this. Signed-off-by: Takuya Yoshikawa --- virt/kvm/kvm_main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a9e999a..53521ea 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -184,6 +184,15 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req) return called; } +/* + * tlbs_dirty is used only for optimizing x86's shadow paging code with mmu + * notifiers in mind, see the note on sync_page(). Since it is always protected + * with mmu_lock there, should kvm_flush_remote_tlbs() be called before + * releasing mmu_lock, the trick using smp_mb() and cmpxchg() is not necessary. + * + * Currently, the assumption about kvm_flush_remote_tlbs() callers is true, but + * the code is kept as is for someone who may change the rule in the future. + */ void kvm_flush_remote_tlbs(struct kvm *kvm) { long dirty_count = kvm->tlbs_dirty;