From patchwork Mon Apr 27 01:41:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47594 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 104EA2121F for ; Mon, 27 Apr 2015 01:42:28 +0000 (UTC) Received: by lbbrr5 with SMTP id rr5sf21547485lbb.3 for ; Sun, 26 Apr 2015 18:42:27 -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=u+LoTi+1PR7aazO2iJvuMykRtM4miIYTx+tCHVrZceU=; b=JKXLt27dnOTLb9WIf4nbqaF2hbWrCeXSo6yy1Rw1UzccxWrHyeTwnrr50pPYNejcWb 8C4BU+jITvRYMLeyiKXUXQCT6NdzQbX9Gwx0fo19vI3JTY7W0N+lDNNC9zcOEQQ68AQy YvcEWRDwVXv6/kpYhpFIz5yDZIoMlqm1lDIB5ibMzRB9EnZrNBRy9aAOTr/26u/7Fd5q Y+/Ubng33HkgHanA6RYMWHHmLlUWTYtLpZL8Jp2CiIGTuqC0Ewb7M7am7cMerTGQWsKh uslMXXyPZnIukecOnamsU4ESnvlS8cD74ZSgZnbHVGeFnPG8CMhbQ3G1RAMmueaj20fh u3yA== X-Gm-Message-State: ALoCoQnQiiaUM8By7ZhyKgW9ukHcFIVxNa1oRPPVQkUhlyjx1bZMh8B0s4pWODMYlEM55Lhvh0mp X-Received: by 10.112.138.2 with SMTP id qm2mr5836186lbb.19.1430098947033; Sun, 26 Apr 2015 18:42:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.67 with SMTP id da3ls780778lad.49.gmail; Sun, 26 Apr 2015 18:42:26 -0700 (PDT) X-Received: by 10.112.47.73 with SMTP id b9mr7975047lbn.46.1430098946828; Sun, 26 Apr 2015 18:42:26 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id oc2si13707772lbb.1.2015.04.26.18.42.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Apr 2015 18:42:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by laat2 with SMTP id t2so69337474laa.1 for ; Sun, 26 Apr 2015 18:42:26 -0700 (PDT) X-Received: by 10.152.2.227 with SMTP id 3mr1820437lax.73.1430098946702; Sun, 26 Apr 2015 18:42:26 -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 l1csp1008274lbt; Sun, 26 Apr 2015 18:42:25 -0700 (PDT) X-Received: by 10.66.192.74 with SMTP id he10mr17415960pac.145.1430098944844; Sun, 26 Apr 2015 18:42:24 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ro6si27582230pab.194.2015.04.26.18.42.23; Sun, 26 Apr 2015 18:42:24 -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 S1751937AbbD0BmX (ORCPT + 2 others); Sun, 26 Apr 2015 21:42:23 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:35459 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751890AbbD0BmX (ORCPT ); Sun, 26 Apr 2015 21:42:23 -0400 Received: by pabtp1 with SMTP id tp1so112277369pab.2 for ; Sun, 26 Apr 2015 18:42:22 -0700 (PDT) X-Received: by 10.67.7.162 with SMTP id dd2mr17245688pad.151.1430098942559; Sun, 26 Apr 2015 18:42:22 -0700 (PDT) Received: from localhost ([167.160.116.64]) by mx.google.com with ESMTPSA id dv3sm5813123pbb.91.2015.04.26.18.42.20 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 26 Apr 2015 18:42:21 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: gregkh@linuxfoundation.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.19.y stable 4/5] arm64: KVM: Do not use pgd_index to index stage-2 pgd Date: Mon, 27 Apr 2015 09:41:18 +0800 Message-Id: <1430098879-5980-5-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430098879-5980-1-git-send-email-shannon.zhao@linaro.org> References: <1430098879-5980-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.42 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 9ebb328..5de64c0 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 b6b2e6f..9ec6dfe 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 8827a95..df150ae 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