From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] KVM: Mapping IOMMU pages after updating memslot Date: Mon, 28 Oct 2013 13:57:32 +0100 Message-ID: <526E5F3C.1060300@redhat.com> References: <1382579799-13273-1-git-send-email-yang.z.zhang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, alex.williamson@redhat.com, gleb@redhat.com, patrick.lu@intel.com To: Yang Zhang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:3985 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756433Ab3J1M5h (ORCPT ); Mon, 28 Oct 2013 08:57:37 -0400 In-Reply-To: <1382579799-13273-1-git-send-email-yang.z.zhang@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: Il 24/10/2013 03:56, Yang Zhang ha scritto: > From: Yang Zhang > > In kvm_iommu_map_pages(), we need to know the page size via call > kvm_host_page_size(). And it will check whether the target slot > is valid before return the right page size. > Currently, we will map the iommu pages when creating a new slot. > But we call kvm_iommu_map_pages() during preparing the new slot. > At that time, the new slot is not visible by domain(still in preparing). > So we cannot get the right page size from kvm_host_page_size() and > this will break the IOMMU super page logic. > The solution is to map the iommu pages after we insert the new slot > into domain. > > Signed-off-by: Yang Zhang > Tested-by: Patrick Lu > --- > virt/kvm/kvm_main.c | 29 ++++++++++++++--------------- > 1 files changed, 14 insertions(+), 15 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index d469114..9ec60a2 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -873,21 +873,6 @@ int __kvm_set_memory_region(struct kvm *kvm, > goto out_free; > } > > - /* > - * IOMMU mapping: New slots need to be mapped. Old slots need to be > - * un-mapped and re-mapped if their base changes. Since base change > - * unmapping is handled above with slot deletion, mapping alone is > - * needed here. Anything else the iommu might care about for existing > - * slots (size changes, userspace addr changes and read-only flag > - * changes) is disallowed above, so any other attribute changes getting > - * here can be skipped. > - */ > - if ((change == KVM_MR_CREATE) || (change == KVM_MR_MOVE)) { > - r = kvm_iommu_map_pages(kvm, &new); > - if (r) > - goto out_slots; > - } > - > /* actual memory is freed via old in kvm_free_physmem_slot below */ > if (change == KVM_MR_DELETE) { > new.dirty_bitmap = NULL; > @@ -901,6 +886,20 @@ int __kvm_set_memory_region(struct kvm *kvm, > kvm_free_physmem_slot(&old, &new); > kfree(old_memslots); > > + /* > + * IOMMU mapping: New slots need to be mapped. Old slots need to be > + * un-mapped and re-mapped if their base changes. Since base change > + * unmapping is handled above with slot deletion, mapping alone is > + * needed here. Anything else the iommu might care about for existing > + * slots (size changes, userspace addr changes and read-only flag > + * changes) is disallowed above, so any other attribute changes getting > + * here can be skipped. > + */ > + if ((change == KVM_MR_CREATE) || (change == KVM_MR_MOVE)) { > + r = kvm_iommu_map_pages(kvm, &new); > + return r; > + } > + > return 0; > > out_slots: > Applied to kvm.git queue, thanks. Paolo