From: Alexander Graf Subject: Re: [PATCH 5/8] KVM: Add hva_to_memslot Date: Sun, 12 Aug 2012 13:03:41 +0200 Message-ID: <623895C2-40C1-48C8-B3DF-DA1FFFE742B4@suse.de> References: <1344337036-22244-1-git-send-email-agraf@suse.de> <1344337036-22244-6-git-send-email-agraf@suse.de> <20120809193441.f8336b66.yoshikawa.takuya@oss.ntt.co.jp> <502392A6.7070404@redhat.com> <50277659.3080107@redhat.com> Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT Cc: Takuya Yoshikawa , "kvm-ppc@vger.kernel.org" , KVM list , "kvmarm@lists.cs.columbia.edu" To: Avi Kivity Return-path: In-Reply-To: <50277659.3080107@redhat.com> Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 12.08.2012, at 11:24, Avi Kivity wrote: > On 08/09/2012 08:02 PM, Alexander Graf wrote: >> >> >> On 09.08.2012, at 12:36, Avi Kivity wrote: >> >>> On 08/09/2012 01:34 PM, Takuya Yoshikawa wrote: >>>> On Tue, 7 Aug 2012 12:57:13 +0200 >>>> Alexander Graf wrote: >>>> >>>>> +struct kvm_memory_slot *hva_to_memslot(struct kvm *kvm, hva_t hva) >>>>> +{ >>>>> + struct kvm_memslots *slots = kvm_memslots(kvm); >>>>> + struct kvm_memory_slot *memslot; >>>>> + >>>>> + kvm_for_each_memslot(memslot, slots) >>>>> + if (hva >= memslot->userspace_addr && >>>>> + hva < memslot->userspace_addr + memslot->npages) >>>>> + return memslot; >>>>> + >>>>> + return NULL; >>>>> +} >>>> >>>> Can't we have two memory slots which contain that hva? >>>> I thought that's why hva handler had to check all slots. >>> >>> We can and do. Good catch. >>> >> >> Hrm. So I guess we can only do an hva_is_guest_memory() helper? That's all I really need anyways :) >> > > How about kvm_for_each_memslot_hva_range()? That can useful in > kvm_handle_hva_range(). For your use case, you just do you stuff and > return immediately. Well, for now I just dropped the whole thing. In general, chances are pretty good that an HVA we get notified on with mmu notifiers is representing guest memory. And flushing a few times too often shouldn't hurt. Alex