From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: KVM: MMU: nuke shadowed pgtable pages and pte's on memslot destruction Date: Sat, 5 Jul 2008 16:23:44 -0300 Message-ID: <20080705192344.GA16596@dmt.cnet> References: <20080704010618.GA25834@dmt.cnet> <486FAE8A.2050308@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "Richard W.M. Jones" , kvm-devel To: Avi Kivity Return-path: Received: from mx1.redhat.com ([66.187.233.31]:56482 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751727AbYGETYS (ORCPT ); Sat, 5 Jul 2008 15:24:18 -0400 Content-Disposition: inline In-Reply-To: <486FAE8A.2050308@qumranet.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sat, Jul 05, 2008 at 08:25:30PM +0300, Avi Kivity wrote: >> @@ -1955,6 +1955,22 @@ void kvm_mmu_slot_remove_write_access(st >> } >> } >> +int kvm_mmu_slot_has_shadowed_page(struct kvm *kvm, int slot) >> +{ >> + struct kvm_mmu_page *sp; >> + int ret = 0; >> + >> + spin_lock(&kvm->mmu_lock); >> + list_for_each_entry(sp, &kvm->arch.active_mmu_pages, link) { >> + if (test_bit(slot, &sp->slot_bitmap)) { >> + ret = -EINVAL; >> + break; >> + } >> + } >> + spin_unlock(&kvm->mmu_lock); >> + return ret; >> +} >> + >> > > I don't like the guest influencing host actions in this way. It's just > a guest. > > But I think it's unneeded. kvm_mmu_zap_page() will mark a root shadow > page invalid and force all vcpus to reload it, so all that's needed is > to keep the mmu spinlock held while removing the slot. You're still keeping a shadowed page around with sp->gfn pointing to non-existant memslot. The code generally makes the assumption that gfn_to_memslot(gfn) on shadowed info will not fail. kvm_mmu_zap_page -> unaccount_shadowed, for example. The other option is to harden gfn_to_memslot() callers to handle failure, is that saner?