From patchwork Mon May 4 01:25:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47937 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6614C20553 for ; Mon, 4 May 2015 01:28:34 +0000 (UTC) Received: by wiun10 with SMTP id n10sf30444603wiu.1 for ; Sun, 03 May 2015 18:28:33 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=ih+qi4uGH1Nt7/bqplsq+pE4m7fKeL0Q5Ga8SYVLC80=; b=BGGsgJPsalOPcqcqwMYBpdBzmjmadCHEPPlimLB/J5vmeRwvWybvOuisafvJzE9unY BdZCmdGSGS9Xcryo3VQ7AcJifR76EiE7VX0+uVes2O68v9r8xF+lEom1T7sEBEGk3rn3 DKwSBN6BY6N8L8veCZz3QVEa+F0HiNRUeln/00hd4obZkoXyjuET+sxMtxQ35FxvL6o/ 0DgkTIlYNf9o1ErFV+FVm1myD8ig/jvsXL1isl4Mso7mhaH0jT5xkc5mSouoZSQhO38N QbYDcOOaN3ISxwiaIHX8Kb7h7jP75/hHoENGT7q4A/zt2XWTnh+Plhl27wPMYTuArZi4 boRA== X-Gm-Message-State: ALoCoQlBB4NruSzP2uE7iZuE/CqVeDSzUGre7br3rXhdFK0sQJAn/VUPsxMNlwE0QmdSC18FvGkq X-Received: by 10.112.160.197 with SMTP id xm5mr16865923lbb.15.1430702913701; Sun, 03 May 2015 18:28:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.25.132 with SMTP id c4ls661701lag.75.gmail; Sun, 03 May 2015 18:28:33 -0700 (PDT) X-Received: by 10.152.45.97 with SMTP id l1mr17891019lam.55.1430702913279; Sun, 03 May 2015 18:28:33 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id wm10si9039509lbb.149.2015.05.03.18.28.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:28:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by laat2 with SMTP id t2so94817240laa.1 for ; Sun, 03 May 2015 18:28:33 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr17311782lak.117.1430702913058; Sun, 03 May 2015 18:28:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp1406212lbt; Sun, 3 May 2015 18:28:32 -0700 (PDT) X-Received: by 10.68.218.103 with SMTP id pf7mr37973853pbc.32.1430702911056; Sun, 03 May 2015 18:28:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id es7si17680936pbd.123.2015.05.03.18.28.29; Sun, 03 May 2015 18:28:31 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751869AbbEDB23 (ORCPT + 2 others); Sun, 3 May 2015 21:28:29 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:35494 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751570AbbEDB23 (ORCPT ); Sun, 3 May 2015 21:28:29 -0400 Received: by pabtp1 with SMTP id tp1so147376164pab.2 for ; Sun, 03 May 2015 18:28:28 -0700 (PDT) X-Received: by 10.70.108.137 with SMTP id hk9mr38082807pdb.105.1430702908666; Sun, 03 May 2015 18:28:28 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id qe9sm10973157pbc.62.2015.05.03.18.28.26 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:28:27 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: sasha.levin@oracle.com, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.18.y stable 21/22] arm64: KVM: Do not use pgd_index to index stage-2 pgd Date: Mon, 4 May 2015 09:25:25 +0800 Message-Id: <1430702726-2056-22-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430702726-2056-1-git-send-email-shannon.zhao@linaro.org> References: <1430702726-2056-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@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.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Marc Zyngier commit 04b8dc85bf4a64517e3cf20e409eeaa503b15cc1 upstream. The kernel's pgd_index macro is designed to index a normal, page sized array. KVM is a bit diffferent, as we can use concatenated pages to have a bigger address space (for example 40bit IPA with 4kB pages gives us an 8kB PGD. In the above case, the use of pgd_index will always return an index inside the first 4kB, which makes a guest that has memory above 0x8000000000 rather unhappy, as it spins forever in a page fault, whist the host happilly corrupts the lower pgd. The obvious fix is to get our own kvm_pgd_index that does the right thing(tm). Tested on X-Gene with a hacked kvmtool that put memory at a stupidly high address. Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/include/asm/kvm_mmu.h | 3 ++- arch/arm/kvm/mmu.c | 6 +++--- arch/arm64/include/asm/kvm_mmu.h | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index f949cb6..16d9d78 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -128,13 +128,14 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd) (__boundary - 1 < (end) - 1)? __boundary: (end); \ }) +#define kvm_pgd_index(addr) pgd_index(addr) + static inline bool kvm_page_empty(void *ptr) { struct page *ptr_page = virt_to_page(ptr); return page_count(ptr_page) == 1; } - #define kvm_pte_table_empty(kvm, ptep) kvm_page_empty(ptep) #define kvm_pmd_table_empty(kvm, pmdp) kvm_page_empty(pmdp) #define kvm_pud_table_empty(kvm, pudp) (0) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 203c5ac..cba52cf 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -251,7 +251,7 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp, phys_addr_t addr = start, end = start + size; phys_addr_t next; - pgd = pgdp + pgd_index(addr); + pgd = pgdp + kvm_pgd_index(addr); do { next = kvm_pgd_addr_end(addr, end); if (!pgd_none(*pgd)) @@ -316,7 +316,7 @@ static void stage2_flush_memslot(struct kvm *kvm, phys_addr_t next; pgd_t *pgd; - pgd = kvm->arch.pgd + pgd_index(addr); + pgd = kvm->arch.pgd + kvm_pgd_index(addr); do { next = kvm_pgd_addr_end(addr, end); stage2_flush_puds(kvm, pgd, addr, next); @@ -791,7 +791,7 @@ static pud_t *stage2_get_pud(struct kvm *kvm, struct kvm_mmu_memory_cache *cache pgd_t *pgd; pud_t *pud; - pgd = kvm->arch.pgd + pgd_index(addr); + pgd = kvm->arch.pgd + kvm_pgd_index(addr); if (WARN_ON(pgd_none(*pgd))) { if (!cache) return NULL; diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 93f1a4c..a205e95 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -137,6 +137,8 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd) #define PTRS_PER_S2_PGD (1 << PTRS_PER_S2_PGD_SHIFT) #define S2_PGD_ORDER get_order(PTRS_PER_S2_PGD * sizeof(pgd_t)) +#define kvm_pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_S2_PGD - 1)) + /* * If we are concatenating first level stage-2 page tables, we would have less * than or equal to 16 pointers in the fake PGD, because that's what the