From: Takuya Yoshikawa Subject: Re: [PATCH v2] KVM: Avoid zapping unrelated shadows in __kvm_set_memory_region() Date: Sat, 14 Apr 2012 10:01:34 +0900 Message-ID: <20120414100134.6bdde68a3bd015dd99e828f2@gmail.com> References: <20120410220503.36efa6bfb776e741ba076115@gmail.com> <20120413213339.GB4190@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: avi@redhat.com, kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp To: Marcelo Tosatti Return-path: Received: from mail-pz0-f52.google.com ([209.85.210.52]:36729 "EHLO mail-pz0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751893Ab2DNBBj (ORCPT ); Fri, 13 Apr 2012 21:01:39 -0400 Received: by dake40 with SMTP id e40so4518379dak.11 for ; Fri, 13 Apr 2012 18:01:38 -0700 (PDT) In-Reply-To: <20120413213339.GB4190@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, 13 Apr 2012 18:33:39 -0300 Marcelo Tosatti wrote: > > kvm_arch_commit_memory_region(kvm, mem, old, user_alloc); > > > > - /* > > - * If the new memory slot is created, we need to clear all > > - * mmio sptes. > > - */ > > - if (npages && old.base_gfn != mem->guest_phys_addr >> PAGE_SHIFT) > > - kvm_arch_flush_shadow(kvm); > > + /* Need to clear all mmio sptes used before. */ > > + if (npages && old.npages && base_gfn != old.base_gfn) > > + kvm_arch_flush_shadow(kvm, mem->slot); > > mmio sptes are not related to any particular slot (by definition), > i think you misunderstood the purpose of this flush. It handles > > 1) [start, end] gpa range unmapped. > 2) mmio sptes are created that map this range. > 3) a new slot is created. mmio sptes that map [start, end] range, > which is now backed by new memslot should be removed. Ah, OK. > Perhaps there is an efficient way to clear all mmio sptes, or all > mmio sptes pointing to [start, end] (instead of all sptes), here. Well, I am OK -- though not happy -- with flushing everything during the guest start-up. But once shadows are fully created, we do not want to do that. So maybe worth thinking such an efficient way! Takuya