From patchwork Thu Jul 2 10:59:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 50571 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0147B214B3 for ; Thu, 2 Jul 2015 11:00:33 +0000 (UTC) Received: by wiar9 with SMTP id r9sf23061474wia.1 for ; Thu, 02 Jul 2015 04:00:32 -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=UkWTLCTcFObMmebVClfuH6bQxV12MUG31p09kvP0TwnXdCbgmY3FiZA4a/7uvRdB+U 0qqEdXa7iQWavt63UQuzgPsOlexQG7ufhklVOvcmaG3kaeA3Z0y4ppiIL1McNdzky4cX uA6L+CCeJ/GLJ2s2fOePt1A1esQW0Kg6ZavzJwzMJYhnAth1G1YxxNtBq/rVT2s3HuBn I9BpljKogKzqwJhQ6M1Omvd8xLnQSjDu4VtC2rnekQfkPfr7U286+kTR/BO4iU4w5Egv 0dvvJI08iWqbYdqkAfvu9U0iE4fyb7QBJj4ARP9G18tm3Uy5vbYdB+XJOIfVhSKSWnzK q+hg== X-Gm-Message-State: ALoCoQlIoy922YhNm5T2L0Bi0x0Tcy/nNqVY9L1QkbMbYU2TXI6y10Y+9KC5cTn4pTdL9MZqmaCI X-Received: by 10.112.42.236 with SMTP id r12mr19837278lbl.2.1435834832222; Thu, 02 Jul 2015 04:00:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.1 with SMTP id n1ls274738laa.87.gmail; Thu, 02 Jul 2015 04:00:31 -0700 (PDT) X-Received: by 10.112.126.136 with SMTP id my8mr29539419lbb.18.1435834831943; Thu, 02 Jul 2015 04:00:31 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id pc6si4134012lbc.178.2015.07.02.04.00.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 04:00:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbcui10 with SMTP id ui10so29528356lbc.0 for ; Thu, 02 Jul 2015 04:00:31 -0700 (PDT) X-Received: by 10.152.37.228 with SMTP id b4mr29610593lak.117.1435834831468; Thu, 02 Jul 2015 04:00:31 -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 hn6csp392792lbb; Thu, 2 Jul 2015 04:00:30 -0700 (PDT) X-Received: by 10.68.203.231 with SMTP id kt7mr65224733pbc.58.1435834829594; Thu, 02 Jul 2015 04:00:29 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si8481613pds.160.2015.07.02.04.00.28; Thu, 02 Jul 2015 04:00:29 -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 S1752095AbbGBLA1 (ORCPT + 2 others); Thu, 2 Jul 2015 07:00:27 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:35692 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752339AbbGBLA0 (ORCPT ); Thu, 2 Jul 2015 07:00:26 -0400 Received: by pactm7 with SMTP id tm7so38937715pac.2 for ; Thu, 02 Jul 2015 04:00:25 -0700 (PDT) X-Received: by 10.70.38.33 with SMTP id d1mr63883970pdk.99.1435834825644; Thu, 02 Jul 2015 04:00:25 -0700 (PDT) Received: from localhost ([120.136.34.253]) by mx.google.com with ESMTPSA id fr2sm5310948pdb.22.2015.07.02.04.00.22 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 02 Jul 2015 04:00:24 -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 4/5] arm64: KVM: Do not use pgd_index to index stage-2 pgd Date: Thu, 2 Jul 2015 18:59:48 +0800 Message-Id: <1435834789-8020-5-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1435834789-8020-1-git-send-email-shannon.zhao@linaro.org> References: <1435834789-8020-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.181 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);