From patchwork Fri Apr 24 05:28:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47547 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4E26820553 for ; Fri, 24 Apr 2015 05:35:28 +0000 (UTC) Received: by wghm4 with SMTP id m4sf9151260wgh.2 for ; Thu, 23 Apr 2015 22:35: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=ML81yjJS43anwkItlODFzmK1GZ6hNMqYGGD2B41tqRQ=; b=R22Nj4EhOTZiux24iU7oqIATobUSEl3y/TcRZYsxtSrFGKfYawXBhOSxUG7PBCcdtV sUmKyRB7LUCp4k0aeukoJPMgR1+7Wzc1lKfbjkkzn+0WVIPg4RyIczL9UYTWgtDc09gr EIJfE12d+meTb9hSQqqJLJYr23D94G+TthzfZl8xUaQSTkDShDX6Fd65IANvfXjVaULd H9bhZPmXP8uSfMNDhb8I400bxnwNSyEdnUX+kvVp0vNgPSypKdRhjOcedT8nCOPRSF6a GKRuqlj1px00HIX/HGwX+IiQWh8ZAh8SjSlF86XSx/2r8dQ5DP+7YBse9WnG5m+DJ0Ly LKCw== X-Gm-Message-State: ALoCoQnnhWp85LnWAOH/1rvd9D3zF1e0idwtOnvgfuKUypK6HdXqFANsClff1KoXgUaj7XfqGBgS X-Received: by 10.152.184.73 with SMTP id es9mr3222033lac.4.1429853727620; Thu, 23 Apr 2015 22:35:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.3.133 with SMTP id c5ls373168lac.68.gmail; Thu, 23 Apr 2015 22:35:27 -0700 (PDT) X-Received: by 10.112.162.167 with SMTP id yb7mr5469327lbb.121.1429853727466; Thu, 23 Apr 2015 22:35:27 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id d9si7485119lah.23.2015.04.23.22.35.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:35:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by laat2 with SMTP id t2so27598739laa.1 for ; Thu, 23 Apr 2015 22:35:27 -0700 (PDT) X-Received: by 10.152.26.34 with SMTP id i2mr5353338lag.117.1429853727188; Thu, 23 Apr 2015 22:35:27 -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 l1csp979151lbt; Thu, 23 Apr 2015 22:35:26 -0700 (PDT) X-Received: by 10.68.94.129 with SMTP id dc1mr11802913pbb.8.1429853725407; Thu, 23 Apr 2015 22:35:25 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd10si15800741pdb.178.2015.04.23.22.35.24; Thu, 23 Apr 2015 22:35:25 -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 S1754588AbbDXFfY (ORCPT + 2 others); Fri, 24 Apr 2015 01:35:24 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:32968 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754592AbbDXFfX (ORCPT ); Fri, 24 Apr 2015 01:35:23 -0400 Received: by oica37 with SMTP id a37so32500397oic.0 for ; Thu, 23 Apr 2015 22:35:23 -0700 (PDT) X-Received: by 10.202.222.138 with SMTP id v132mr5346377oig.106.1429853723334; Thu, 23 Apr 2015 22:35:23 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id h4sm6075722obr.18.2015.04.23.22.35.21 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:35:22 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.12.y stable 62/63] arm64: KVM: Do not use pgd_index to index stage-2 pgd Date: Fri, 24 Apr 2015 13:28:00 +0800 Message-Id: <1429853281-6136-63-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> References: <1429853281-6136-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.47 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 | 2 ++ arch/arm/kvm/mmu.c | 6 +++--- arch/arm64/include/asm/kvm_mmu.h | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 8cd8856..7a1d664 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -106,6 +106,8 @@ static inline void kvm_set_s2pte_writable(pte_t *pte) (__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); diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index a79baa5..87a2769 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -177,7 +177,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); unmap_puds(kvm, pgd, addr, next); @@ -236,7 +236,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); @@ -624,7 +624,7 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, pte_t *pte, old_pte; /* Create 2nd stage page table mapping - Level 1 */ - 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 6e127e7..0c661b8 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -106,6 +106,8 @@ static inline void kvm_set_s2pte_writable(pte_t *pte) #define kvm_pud_addr_end(addr, end) pud_addr_end(addr, end) #define kvm_pmd_addr_end(addr, end) pmd_addr_end(addr, end) +#define kvm_pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_S2_PGD - 1)) + static inline bool kvm_page_empty(void *ptr) { struct page *ptr_page = virt_to_page(ptr);