From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 3/3] arm, arm64: KVM: handle potential incoherency of readonly memslots Date: Wed, 19 Nov 2014 12:02:47 +0100 Message-ID: <546C78D7.6090201@redhat.com> References: <1416236333-9378-1-git-send-email-ard.biesheuvel@linaro.org> <1416236333-9378-3-git-send-email-ard.biesheuvel@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: KVM devel mailing list To: kvm@vger.kernel.org Return-path: Received: from plane.gmane.org ([80.91.229.3]:56701 "EHLO plane.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750757AbaKSLDB (ORCPT ); Wed, 19 Nov 2014 06:03:01 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Xr32J-0007qq-Hh for kvm@vger.kernel.org; Wed, 19 Nov 2014 12:02:59 +0100 Received: from net-93-146-133-240.cust.vodafonedsl.it ([93.146.133.240]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 19 Nov 2014 12:02:59 +0100 Received: from pbonzini by net-93-146-133-240.cust.vodafonedsl.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 19 Nov 2014 12:02:59 +0100 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On 19/11/2014 09:51, Ard Biesheuvel wrote: > On 17 November 2014 15:58, Ard Biesheuvel wrote: >> Readonly memslots are often used to implement emulation of ROMs and >> NOR flashes, in which case the guest may legally map these regions as >> uncached. >> To deal with the incoherency associated with uncached guest mappings, >> treat all readonly memslots as incoherent, and ensure that pages that >> belong to regions tagged as such are flushed to DRAM before being passed >> to the guest. >> >> Signed-off-by: Ard Biesheuvel >> --- > > Hello all, > > I have another bug report (from Canonical this time) of essentially > the same issue, and it is also fixed by these patches. > Are you happy with these patches? Should I respin to add Laszlo's tested-by? Christoffer can add it, together with... Acked-by: Paolo Bonzini Paolo > Cheers, > Ard. > > >> arch/arm/kvm/mmu.c | 20 +++++++++++++++----- >> 1 file changed, 15 insertions(+), 5 deletions(-) >> >> diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c >> index cb924c6d56a6..f2a9874ff5cb 100644 >> --- a/arch/arm/kvm/mmu.c >> +++ b/arch/arm/kvm/mmu.c >> @@ -919,7 +919,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, >> if (!hugetlb && !force_pte) >> hugetlb = transparent_hugepage_adjust(&pfn, &fault_ipa); >> >> - fault_ipa_uncached = false; >> + fault_ipa_uncached = memslot->flags & KVM_MEMSLOT_INCOHERENT; >> >> if (hugetlb) { >> pmd_t new_pmd = pfn_pmd(pfn, mem_type); >> @@ -1298,11 +1298,12 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, >> hva = vm_end; >> } while (hva < reg_end); >> >> - if (ret) { >> - spin_lock(&kvm->mmu_lock); >> + spin_lock(&kvm->mmu_lock); >> + if (ret) >> unmap_stage2_range(kvm, mem->guest_phys_addr, mem->memory_size); >> - spin_unlock(&kvm->mmu_lock); >> - } >> + else >> + stage2_flush_memslot(kvm, memslot); >> + spin_unlock(&kvm->mmu_lock); >> return ret; >> } >> >> @@ -1314,6 +1315,15 @@ void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, >> int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, >> unsigned long npages) >> { >> + /* >> + * Readonly memslots are not incoherent with the caches by definition, >> + * but in practice, they are used mostly to emulate ROMs or NOR flashes >> + * that the guest may consider devices and hence map as uncached. >> + * To prevent incoherency issues in these cases, tag all readonly >> + * regions as incoherent. >> + */ >> + if (slot->flags & KVM_MEM_READONLY) >> + slot->flags |= KVM_MEMSLOT_INCOHERENT; >> return 0; >> } >> >> -- >> 1.8.3.2 >> > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >