From patchwork Wed Jun 4 13:47:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 31363 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCF52208CF for ; Wed, 4 Jun 2014 13:48:24 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf42823844iec.4 for ; Wed, 04 Jun 2014 06:48:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=kcH7YCzyv9a3XGY2GZ1S6h4wXuDIxD16sbe5Tkw0QzI=; b=ihu8+8876YKmz1eg7WF9LWdcR8uMXR2G46dX9eA9em4/ny+I4AHbAgz5VQDMCVSvTw Bs7yRHygm4W7lViM0Be2iRsVKJjVha7JRSaAKDseXAEnP6xdlvKNtP/DWakTqG/jypIU s3cc5T4OZkB3/j0ws5qMwlxy9KhBEVeDmGitU/MUqDZTzLpa+2IFlsY3XpPVN532JbBw DSCmF932cbNIrqPjFvGZyiO0KVGYGMILfYyfhUkgXFbzUw4/JPDCcOB4TPO1ygGbXEfr yB1S5rAGA7MKhCnxa5RQpPjGBSnIq3+fWamRRkHdshbxUJimJ5Afs8eCOGh6Z10LnZZ5 MP1Q== X-Gm-Message-State: ALoCoQlUAS7mT3xlRF/EaxHby14Z7kFg2chxBeIawYbWOnOL+XTgdYMNI1f1M5BFqRflk8BZXqaO X-Received: by 10.182.97.165 with SMTP id eb5mr22177383obb.43.1401889704155; Wed, 04 Jun 2014 06:48:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.54 with SMTP id b51ls3153121qgf.48.gmail; Wed, 04 Jun 2014 06:48:24 -0700 (PDT) X-Received: by 10.58.94.232 with SMTP id df8mr1399801veb.72.1401889703956; Wed, 04 Jun 2014 06:48:23 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id fa6si1623617veb.20.2014.06.04.06.48.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 06:48:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lc6so1431557vcb.15 for ; Wed, 04 Jun 2014 06:48:23 -0700 (PDT) X-Received: by 10.52.25.130 with SMTP id c2mr32234762vdg.27.1401889703887; Wed, 04 Jun 2014 06:48:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp46722vcb; Wed, 4 Jun 2014 06:48:23 -0700 (PDT) X-Received: by 10.180.84.7 with SMTP id u7mr5444139wiy.31.1401889702981; Wed, 04 Jun 2014 06:48:22 -0700 (PDT) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by mx.google.com with ESMTPS id b6si4716954wjb.67.2014.06.04.06.48.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 06:48:18 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.170 as permitted sender) client-ip=209.85.212.170; Received: by mail-wi0-f170.google.com with SMTP id bs8so7875153wib.3 for ; Wed, 04 Jun 2014 06:48:17 -0700 (PDT) X-Received: by 10.180.126.98 with SMTP id mx2mr5390486wib.55.1401889696233; Wed, 04 Jun 2014 06:48:16 -0700 (PDT) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id ee9sm18724730wib.2.2014.06.04.06.48.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 06:48:15 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, patches@linaro.org, christophe.barnichon@st.com, Eric Auger Subject: [PATCH v2] ARM: KVM: Unmap IPA on memslot delete/move Date: Wed, 4 Jun 2014 15:47:54 +0200 Message-Id: <1401889674-10067-1-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Currently when a KVM region is deleted or moved after KVM_SET_USER_MEMORY_REGION ioctl, the corresponding intermediate physical memory is not unmapped. This patch corrects this and unmaps the region's IPA range in kvm_arch_commit_memory_region using unmap_stage2_range. The patch was tested with QEMU using the VFIO platform device. In a specific IRQ handling case, the device regularly deletes/creates some RAM regions. Changes v1 -> v2 - KVM_MR_MOVE case also handled and tested using a QEMU hack - memslot and memory_region stubs moved from arm.c to mmu.c following Marc Zyngier recommendations. Signed-off-by: Eric Auger Acked-by: Christoffer Dall --- arch/arm/kvm/arm.c | 37 ------------------------------------- arch/arm/kvm/mmu.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index f0e50a0..bcc2929 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -155,16 +155,6 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf) return VM_FAULT_SIGBUS; } -void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, - struct kvm_memory_slot *dont) -{ -} - -int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, - unsigned long npages) -{ - return 0; -} /** * kvm_arch_destroy_vm - destroy the VM data structure @@ -224,33 +214,6 @@ long kvm_arch_dev_ioctl(struct file *filp, return -EINVAL; } -void kvm_arch_memslots_updated(struct kvm *kvm) -{ -} - -int kvm_arch_prepare_memory_region(struct kvm *kvm, - struct kvm_memory_slot *memslot, - struct kvm_userspace_memory_region *mem, - enum kvm_mr_change change) -{ - return 0; -} - -void kvm_arch_commit_memory_region(struct kvm *kvm, - struct kvm_userspace_memory_region *mem, - const struct kvm_memory_slot *old, - enum kvm_mr_change change) -{ -} - -void kvm_arch_flush_shadow_all(struct kvm *kvm) -{ -} - -void kvm_arch_flush_shadow_memslot(struct kvm *kvm, - struct kvm_memory_slot *slot) -{ -} struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) { diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 16f8049..921245c 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -1100,3 +1100,49 @@ out: free_hyp_pgds(); return err; } + +void kvm_arch_commit_memory_region(struct kvm *kvm, + struct kvm_userspace_memory_region *mem, + const struct kvm_memory_slot *old, + enum kvm_mr_change change) +{ + gpa_t gpa = old->base_gfn << PAGE_SHIFT; + u64 size = old->npages << PAGE_SHIFT; + if (change == KVM_MR_DELETE || change == KVM_MR_MOVE) { + spin_lock(&kvm->mmu_lock); + unmap_stage2_range(kvm, gpa, size); + spin_unlock(&kvm->mmu_lock); + } +} + +int kvm_arch_prepare_memory_region(struct kvm *kvm, + struct kvm_memory_slot *memslot, + struct kvm_userspace_memory_region *mem, + enum kvm_mr_change change) +{ + return 0; +} + +void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free, + struct kvm_memory_slot *dont) +{ +} + +int kvm_arch_create_memslot(struct kvm *kvm, struct kvm_memory_slot *slot, + unsigned long npages) +{ + return 0; +} + +void kvm_arch_memslots_updated(struct kvm *kvm) +{ +} + +void kvm_arch_flush_shadow_all(struct kvm *kvm) +{ +} + +void kvm_arch_flush_shadow_memslot(struct kvm *kvm, + struct kvm_memory_slot *slot) +{ +}