From patchwork Tue Jun 30 10:49:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 50469 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 EA350229DF for ; Tue, 30 Jun 2015 10:51:58 +0000 (UTC) Received: by lagx9 with SMTP id x9sf2291850lag.2 for ; Tue, 30 Jun 2015 03:51:57 -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=zrLTkHo6jQWB97otiFT4NiFVW8OunL2ZeijmlA915j8=; b=G1SXG6Pr7CLMENEhQ4H7onEYbg/npLcEwDNTFl+uDJ+4uM+kHHqoljWs5Vkb+Tm8eF sqnuRYrPqC2fXWNY/jqLbf8qA7dtT0/+uo3b8p6jJr5q9/u3VbZzs8tPOzCdYla4D19x 6LkwreAsBJKeKOKrOy1TM0bCT121K27U5GwHoMWcEYi70+6V6wKMoty38aXEINxfql7E 9nRj482qVIDWqGR9l7t6+z6K27eKMTpcRU6kK73+y9sQKhrv1LOj4HJBhd8fLAxumKfc 2YxSf8vbuq2NXTW4OStCM4adNpXXLTc8gIBj4lIRmI0HYiAX86CiWkNZ7l6TDJYV2oGl IsFQ== X-Gm-Message-State: ALoCoQlMQ9xSFtrdzqBxPTi42VlYDxxcxFQjzJHWdYyihWRjObw//9nC0iG/AQ3ZA79vWx+WJr9x X-Received: by 10.112.219.200 with SMTP id pq8mr13786309lbc.7.1435661517910; Tue, 30 Jun 2015 03:51:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.7 with SMTP id bc7ls25719lab.74.gmail; Tue, 30 Jun 2015 03:51:57 -0700 (PDT) X-Received: by 10.112.50.66 with SMTP id a2mr19128591lbo.68.1435661517562; Tue, 30 Jun 2015 03:51:57 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id rb8si37794985lbb.34.2015.06.30.03.51.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2015 03:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by lagc2 with SMTP id c2so8119633lag.3 for ; Tue, 30 Jun 2015 03:51:57 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr19017484lbc.73.1435661517455; Tue, 30 Jun 2015 03:51:57 -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 hn6csp2353620lbb; Tue, 30 Jun 2015 03:51:56 -0700 (PDT) X-Received: by 10.68.57.168 with SMTP id j8mr31764pbq.99.1435661506156; Tue, 30 Jun 2015 03:51:46 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lj11si69631040pab.25.2015.06.30.03.51.45; Tue, 30 Jun 2015 03:51:46 -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 S1752926AbbF3Kvo (ORCPT + 2 others); Tue, 30 Jun 2015 06:51:44 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:36176 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753141AbbF3Kvo (ORCPT ); Tue, 30 Jun 2015 06:51:44 -0400 Received: by paceq1 with SMTP id eq1so3797081pac.3 for ; Tue, 30 Jun 2015 03:51:43 -0700 (PDT) X-Received: by 10.70.90.162 with SMTP id bx2mr36367612pdb.60.1435661503857; Tue, 30 Jun 2015 03:51:43 -0700 (PDT) Received: from localhost ([120.136.36.232]) by mx.google.com with ESMTPSA id kh6sm45124720pbc.50.2015.06.30.03.51.41 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 30 Jun 2015 03:51:42 -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 21/22] arm64: KVM: Do not use pgd_index to index stage-2 pgd Date: Tue, 30 Jun 2015 18:49:09 +0800 Message-Id: <1435661350-8060-22-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1435661350-8060-1-git-send-email-shannon.zhao@linaro.org> References: <1435661350-8060-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.54 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 Since we don't backport commit c647355 (KVM: arm: Add initial dirty page locking support) for linux-3.14.y, there is no stage2_wp_range in arch/arm/kvm/mmu.c. So ignore the change in stage2_wp_range introduced by this patch. 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);