From patchwork Sat Oct 20 14:14:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1621481 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 D902DDF26F for ; Sat, 20 Oct 2012 14:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754920Ab2JTOOK (ORCPT ); Sat, 20 Oct 2012 10:14:10 -0400 Received: from mail-vc0-f174.google.com ([209.85.220.174]:52888 "EHLO mail-vc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754780Ab2JTOOJ (ORCPT ); Sat, 20 Oct 2012 10:14:09 -0400 Received: by mail-vc0-f174.google.com with SMTP id fk26so1480447vcb.19 for ; Sat, 20 Oct 2012 07:14:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=F9Pz4ianXM152QS7HUV450Bz/D6vSL/lD0F4+j3jgOY=; b=buKBAG3khndApPB8RhGImhg339fBctn2xLy4BiO+xXW3DZ9t6pyyQIl7VGOgRjAJxn 83FjYbhNJL6NznaS2crpebAqRsviI3Ci6MiMUn4vxGKOfmcVb7oU+DmzdFJV0G5Bxn9s FW56qfcHgExXzIMJHnBIZz4pzqe1UZmp0e+oj4DKOw5iTr49EC+1oZzN/SQuyuu4y1eZ NTFauQxcf9GGK+Ctp9N9b7xpkhi4eQTEf/K3Csa8Ccu1D/2tMepboPnrSrPxFCmLmxds QhR2EC+P7pvg2C/ZJbx8ivbAKkjfAGwmPCrxN4fmnzIGJLdGPQGLz1H+SAPAs2Q/L3YG poiQ== Received: by 10.52.28.144 with SMTP id b16mr4724287vdh.4.1350742448902; Sat, 20 Oct 2012 07:14:08 -0700 (PDT) Received: from [127.0.1.1] (pool-72-80-83-148.nycmny.fios.verizon.net. [72.80.83.148]) by mx.google.com with ESMTPS id u2sm4395079vdt.11.2012.10.20.07.14.08 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 20 Oct 2012 07:14:08 -0700 (PDT) Subject: [PATCH v2 1/3] KVM: ARM: Check for overlaps of mapped io addresses To: kvmarm@lists.cs.columbia.edu From: Christoffer Dall Cc: kvm@vger.kernel.org Date: Sat, 20 Oct 2012 10:14:18 -0400 Message-ID: <20121020141418.24046.45036.stgit@ubuntu> In-Reply-To: <20121020141255.24046.20020.stgit@ubuntu> References: <20121020141255.24046.20020.stgit@ubuntu> User-Agent: StGit/0.16-2-g0d85 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm2RxvoNnL5Z4kg0hp35sF2r5ILpVxpB4MgmX97mNHt7vKcnwqgski2BIiATRNbzWu6yx/b Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When calling stage2_set_pte from kvm_phys_addr_ioremap we pass an argument to say that this is an IO mapping, and that we expect the adress range to be free, otherwise return an error. This should catch errors earlier when user space supplies guest physical addresses that overlap. Signed-off-by: Christoffer Dall --- arch/arm/kvm/mmu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- 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 0ab098e..e5ace0e 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -422,7 +422,7 @@ static void stage2_clear_pte(struct kvm *kvm, phys_addr_t addr) } static void stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, - phys_addr_t addr, const pte_t *new_pte) + phys_addr_t addr, const pte_t *new_pte, bool iomap) { pgd_t *pgd; pud_t *pud; @@ -454,6 +454,9 @@ static void stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, } else pte = pte_offset_kernel(pmd, addr); + if (iomap && pte_present(old_pte)) + return -EFAULT; + /* Create 2nd stage page table mapping - Level 3 */ old_pte = *pte; set_pte_ext(pte, *new_pte, 0); @@ -489,7 +492,7 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, if (ret) goto out; spin_lock(&kvm->mmu_lock); - stage2_set_pte(kvm, &cache, addr, &pte); + stage2_set_pte(kvm, &cache, addr, &pte, true); spin_unlock(&kvm->mmu_lock); pfn++; @@ -565,7 +568,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, pte_val(new_pte) |= L_PTE_S2_RDWR; kvm_set_pfn_dirty(pfn); } - stage2_set_pte(vcpu->kvm, memcache, fault_ipa, &new_pte); + stage2_set_pte(vcpu->kvm, memcache, fault_ipa, &new_pte, false); out_unlock: spin_unlock(&vcpu->kvm->mmu_lock); @@ -716,7 +719,7 @@ static void kvm_set_spte_handler(struct kvm *kvm, gpa_t gpa, void *data) { pte_t *pte = (pte_t *)data; - stage2_set_pte(kvm, NULL, gpa, pte); + stage2_set_pte(kvm, NULL, gpa, pte, false); }