From patchwork Tue Jun 2 14:48:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 49406 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 075BD20BD1 for ; Tue, 2 Jun 2015 14:52:22 +0000 (UTC) Received: by labc7 with SMTP id c7sf14297205lab.1 for ; Tue, 02 Jun 2015 07:52:20 -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=42OHZLs9g3pIrKPkLDlbc1kGakZcbc/gSVHoOHpQvD0=; b=gJmSUx/rzfqikBQpo5RyFlfDqGHG2oNR2SgALHqg9bAGmoQk6CJx2PVZhOCj4guAbm DgC7Hx4zt7uslNLiE2jLYF5qrEPV23UkJaYiKXe0sJyndeWr4GhtP5wkqKytz/v6R8e8 /kU1JNAcDbuL0HXPJCbsGRBL0mqDguUsxMXfI+jR6e/R6BXtUdlhdOElsGKVTB3+qw6y ppRU+vKs0RzQBrg/dOKLJnXwoTtRhgqcQrjCFAby9bjuE7KI30EjqXVqr/HFt5exXULn aJ6HzFXKW6Z2mJX8plgBtcMaIrwCQEBuhnMej6EgYkbMuG7+0cbrGn4I65jt7QyaXR0c CB3g== X-Gm-Message-State: ALoCoQmgsMcqqaIp/3ncciacsxMoDqVMMnwR7XRh9zrHWhVeqV7GT4fwUyd/iM73zU0omwAgUH0A X-Received: by 10.112.14.101 with SMTP id o5mr25866987lbc.3.1433256740734; Tue, 02 Jun 2015 07:52:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.36 with SMTP id t4ls806900lal.99.gmail; Tue, 02 Jun 2015 07:52:20 -0700 (PDT) X-Received: by 10.112.210.9 with SMTP id mq9mr2641505lbc.4.1433256740586; Tue, 02 Jun 2015 07:52:20 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id de11si15278094lac.76.2015.06.02.07.52.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 07:52:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbbqq2 with SMTP id qq2so106039374lbb.3 for ; Tue, 02 Jun 2015 07:52:20 -0700 (PDT) X-Received: by 10.152.7.7 with SMTP id f7mr27002985laa.106.1433256740154; Tue, 02 Jun 2015 07:52:20 -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.108.230 with SMTP id hn6csp3130302lbb; Tue, 2 Jun 2015 07:52:18 -0700 (PDT) X-Received: by 10.70.89.199 with SMTP id bq7mr50045095pdb.168.1433256738154; Tue, 02 Jun 2015 07:52:18 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id po1si26750474pac.52.2015.06.02.07.52.17; Tue, 02 Jun 2015 07:52:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932567AbbFBOwQ (ORCPT + 2 others); Tue, 2 Jun 2015 10:52:16 -0400 Received: from mail-ob0-f178.google.com ([209.85.214.178]:34417 "EHLO mail-ob0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759010AbbFBOwQ (ORCPT ); Tue, 2 Jun 2015 10:52:16 -0400 Received: by obew15 with SMTP id w15so130055282obe.1 for ; Tue, 02 Jun 2015 07:52:16 -0700 (PDT) X-Received: by 10.182.16.161 with SMTP id h1mr2004079obd.49.1433256735990; Tue, 02 Jun 2015 07:52:15 -0700 (PDT) Received: from localhost ([167.160.116.34]) by mx.google.com with ESMTPSA id yo9sm9565188obc.3.2015.06.02.07.52.13 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 02 Jun 2015 07:52:14 -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.14.y stable 31/32] arm64: KVM: Do not use pgd_index to index stage-2 pgd Date: Tue, 2 Jun 2015 22:48:26 +0800 Message-Id: <1433256507-7856-32-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1433256507-7856-1-git-send-email-shannon.zhao@linaro.org> References: <1433256507-7856-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.217.177 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 9f79231..7d35af3 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -117,13 +117,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(ptep) kvm_page_empty(ptep) #define kvm_pmd_table_empty(pmdp) kvm_page_empty(pmdp) #define kvm_pud_table_empty(pudp) (0) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 524b4b5..c612e37 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -194,7 +194,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)) @@ -264,7 +264,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); @@ -649,7 +649,7 @@ static pmd_t *stage2_get_pmd(struct kvm *kvm, struct kvm_mmu_memory_cache *cache pud_t *pud; pmd_t *pmd; - pgd = kvm->arch.pgd + pgd_index(addr); + pgd = kvm->arch.pgd + kvm_pgd_index(addr); pud = pud_offset(pgd, addr); if (pud_none(*pud)) { if (!cache) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 0d51874..15a8a86 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -69,6 +69,8 @@ #define PTRS_PER_S2_PGD (1 << (KVM_PHYS_SHIFT - PGDIR_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)) + int create_hyp_mappings(void *from, void *to); int create_hyp_io_mappings(void *from, void *to, phys_addr_t); void free_boot_hyp_pgd(void);