From patchwork Sun Aug 19 20:00:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1344721 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id D6C6BDF264 for ; Sun, 19 Aug 2012 20:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752113Ab2HSUAV (ORCPT ); Sun, 19 Aug 2012 16:00:21 -0400 Received: from mail-vc0-f174.google.com ([209.85.220.174]:35361 "EHLO mail-vc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751107Ab2HSUAU (ORCPT ); Sun, 19 Aug 2012 16:00:20 -0400 Received: by vcbfk26 with SMTP id fk26so4369074vcb.19 for ; Sun, 19 Aug 2012 13:00:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=aaec0XytphyGMyzj2x+JcrU5CNLTXm07uZOZAsFRpRw=; b=etXyaTAxpKtKtyAjKGyTDsEyHfDxCOMtXMtBRbJKwQvX4MtdgTQUG7ZqeQfqWafGfL ctPOVm2TKqEzkQWxIVAtq1m7BTO1usC2VdPyEjBSyjyjszw+q7C0ZepJH8T0LuCwhZUz vYiKntPl599twBx14kqqRcBJ28Jj7LivV+qBDCXIInd3kfdtxP3Ql8BmdWFdenHtRAhZ vI4aDOYGQzkMQsQH6hnQAdtIqbxPLaIWA73Y/alH/u8rCfM3TqVDD1a7fJuPtaDUTn5m 5i4Aw9+RP4ItMCAWY5nL+FJV+m/yn+rheYZSngDsNwLAWRhab7YGhx1dVAE2CTzB+UJ3 bqkw== MIME-Version: 1.0 Received: by 10.58.58.174 with SMTP id s14mr2433810veq.51.1345406416655; Sun, 19 Aug 2012 13:00:16 -0700 (PDT) Received: by 10.58.127.97 with HTTP; Sun, 19 Aug 2012 13:00:16 -0700 (PDT) X-Originating-IP: [72.80.83.148] In-Reply-To: <5030E359.5040201@redhat.com> References: <20120816152637.21484.65421.stgit@ubuntu> <20120816152918.21484.48428.stgit@ubuntu> <10AE40D4-7DF6-466F-B5F7-1352BD37DA62@suse.de> <5030E359.5040201@redhat.com> Date: Sun, 19 Aug 2012 16:00:16 -0400 Message-ID: Subject: Re: [kvmarm] [PATCH v10 07/14] KVM: ARM: Memory virtualization setup From: Christoffer Dall To: Avi Kivity Cc: Peter Maydell , Alexander Graf , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org X-Gm-Message-State: ALoCoQkzyvqCZIvUrUT1+pIIAyzZuCFUKCmaClTRD8tsbC27K/NmVOHo9Fa2jHbQsfDNOVbp5gZd Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Sun, Aug 19, 2012 at 9:00 AM, Avi Kivity wrote: > On 08/19/2012 12:38 PM, Peter Maydell wrote: >> On 19 August 2012 05:34, Christoffer Dall wrote: >>> On Thu, Aug 16, 2012 at 2:25 PM, Alexander Graf wrote: >>>> A single hva can have multiple gpas mapped, no? At least that's what I gathered >>>> from the discussion about my attempt to a function similar to this :). >> >>> I don't think this is the case for ARM, can you provide an example? We >>> use gfn_to_pfn_prot and only allow user memory regions. What you >>> suggest would be multiple physical addresses pointing to the same >>> memory bank, I don't think that makes any sense on ARM hardware, for >>> x86 and PPC I don't know. >> >> I don't know what an hva is, > > host virtual address > > (see Documentation/virtual/kvm/mmu.txt for more TLAs in this area). > > but yes, ARM boards can have the same >> block of RAM aliased into multiple places in the physical address space. >> (we don't currently bother to implement the aliases in qemu's vexpress-a15 >> though because it's a bunch of mappings of the low 2GB into high >> addresses mostly intended to let you test LPAE code without having to >> put lots of RAM on the hardware). I stand corrected. > > Even if it weren't common, the API allows it, so we must behave sensibly. > true, this should be a solution: commit 2a8661fd7e6c15889a20a4547bd7861e84b778a8 Author: Christoffer Dall Date: Sun Aug 19 15:52:10 2012 -0400 KVM: ARM: A single hva can map multiple gpas Handle mmu notifier ops for every such mapping. Signed-off-by: Christoffer Dall @@ -769,31 +772,36 @@ static bool hva_to_gpa(struct kvm *kvm, unsigned long hva, gpa_t *gpa) end = start + (memslot->npages << PAGE_SHIFT); if (hva >= start && hva < end) { + gpa_t gpa; gpa_t gpa_offset = hva - start; - *gpa = (memslot->base_gfn << PAGE_SHIFT) + gpa_offset; - found = true; - /* no overlapping memslots allowed: break */ - break; + gpa = (memslot->base_gfn << PAGE_SHIFT) + gpa_offset; + handler(kvm, hva, gpa, data); + cnt++; } } - return found; + return cnt; +} + +static void kvm_unmap_hva_handler(struct kvm *kvm, unsigned long hva, + gpa_t gpa, void *data) +{ + spin_lock(&kvm->arch.pgd_lock); + stage2_clear_pte(kvm, gpa); + spin_unlock(&kvm->arch.pgd_lock); } int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) { - bool found; - gpa_t gpa; + int found; if (!kvm->arch.pgd) return 0; - found = hva_to_gpa(kvm, hva, &gpa); - if (found) { - spin_lock(&kvm->arch.pgd_lock); - stage2_clear_pte(kvm, gpa); - spin_unlock(&kvm->arch.pgd_lock); - } + found = handle_hva_to_gpa(kvm, hva, &kvm_unmap_hva_handler, NULL); + if (found > 0) + __kvm_tlb_flush_vmid(kvm); + return 0; } @@ -814,21 +822,27 @@ int kvm_unmap_hva_range(struct kvm *kvm, return 0; } +static void kvm_set_spte_handler(struct kvm *kvm, unsigned long hva, + gpa_t gpa, void *data) +{ + pte_t *pte = (pte_t *)data; + + spin_lock(&kvm->arch.pgd_lock); + stage2_set_pte(kvm, NULL, gpa, pte); + spin_unlock(&kvm->arch.pgd_lock); +} + + void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) { - gpa_t gpa; - bool found; + int found; if (!kvm->arch.pgd) return; - found = hva_to_gpa(kvm, hva, &gpa); - if (found) { - spin_lock(&kvm->arch.pgd_lock); - stage2_set_pte(kvm, NULL, gpa, &pte); - spin_unlock(&kvm->arch.pgd_lock); + found = handle_hva_to_gpa(kvm, hva, &kvm_set_spte_handler, &pte); + if (found > 0) __kvm_tlb_flush_vmid(kvm); - } } void kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu) --- -- 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 diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 3df4fa8..9b23230 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -754,11 +754,14 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) return ret ? ret : 1; } -static bool hva_to_gpa(struct kvm *kvm, unsigned long hva, gpa_t *gpa) +static int handle_hva_to_gpa(struct kvm *kvm, unsigned long hva, + void (*handler)(struct kvm *kvm, unsigned long hva, + gpa_t gpa, void *data), + void *data) { struct kvm_memslots *slots; struct kvm_memory_slot *memslot; - bool found = false; + int cnt = 0; slots = kvm_memslots(kvm);