Re: [PATCH 3/4] KVM: MMU: Make kvm_handle_hva() handle range of addresses

Takuya Yoshikawa
2012-06-18T13:20:10Z

On Mon, 18 Jun 2012 15:11:42 +0300
Avi Kivity <avi@redhat.com> wrote:

> > kvm_for_each_memslot(memslot, slots) {
> > - gfn_t gfn = hva_to_gfn(hva, memslot);
> > + gfn_t gfn = hva_to_gfn(start_hva, memslot);
> > + gfn_t end_gfn = hva_to_gfn(end_hva, memslot);
>
> These will return random results which you then use in min/max later, no?

Yes, I will follow your advice: check-then-convert (or check-and-convert).

> > @@ -1212,7 +1218,9 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
> > rmapp = __gfn_to_rmap(gfn, j, memslot);
> > ret |= handler(kvm, rmapp, data);
>
> Potential for improvement: don't do 512 iterations on same large page.
>
> Something like
>
> if ((gfn ^ prev_gfn) & mask(level))
> ret |= handler(...)
>
> with clever selection of the first prev_gfn so it always matches (~gfn
> maybe).

Really nice.
I'm sure that will make this much faster!

Thanks,
Takuya