From patchwork Mon May 4 01:52:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47967 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E85102121F for ; Mon, 4 May 2015 01:55:51 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf41026703wgt.1 for ; Sun, 03 May 2015 18:55:51 -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=rUzcd/SCbi7T5z6nkvAtmVYKVeAb/tSZohkxEXIa48E=; b=fKSvuNkiBPoERRVhdCyvnhkydHhuMrU7/YEG7el3KKNyOHKSvw3RohlWaBNei2VSYW /6EDLeay5fd2Q6PeHzfgGJYEI5XBxzM8lJNjjvMpMF0MTI+matRc17fXqhFQssopDZlI 5Rum74rvY2DPShCdHRQEWU7pL3OTWzYuPqmj/L9MD35vsQ9+3lOy5lAR19qPGmUnitt0 /JlwZdAA7TPn4EII1KFGNCPdloQjims3c+wZcc5uMcm7SJCPVQUKzCjzsrLLbJEZzG4w R0eWY/9nnhjTJ+V3cdriuqTFPud1YXkFD/SveaMd8Nlgz2tIWYyAe/U7DmrPaYUB2kE/ HF9w== X-Gm-Message-State: ALoCoQk7Su7TiEYX+L7gCGI3YkdxfjRNs0EBtCklTP3QjHjOQ4OjjZ2sU3EoJIDsPbmSnED7sjiG X-Received: by 10.112.51.68 with SMTP id i4mr17104651lbo.13.1430704551231; Sun, 03 May 2015 18:55:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.72 with SMTP id h8ls723795laa.71.gmail; Sun, 03 May 2015 18:55:51 -0700 (PDT) X-Received: by 10.152.36.227 with SMTP id t3mr18037314laj.12.1430704551089; Sun, 03 May 2015 18:55:51 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id ap7si9104309lac.21.2015.05.03.18.55.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:55:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbcga7 with SMTP id ga7so95750270lbc.1 for ; Sun, 03 May 2015 18:55:51 -0700 (PDT) X-Received: by 10.112.29.36 with SMTP id g4mr18041075lbh.56.1430704550951; Sun, 03 May 2015 18:55:50 -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 l1csp1413030lbt; Sun, 3 May 2015 18:55:49 -0700 (PDT) X-Received: by 10.70.55.41 with SMTP id o9mr37936700pdp.80.1430704548879; Sun, 03 May 2015 18:55:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ix6si17838787pac.46.2015.05.03.18.55.48; Sun, 03 May 2015 18:55:48 -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 S1751959AbbEDBzr (ORCPT + 2 others); Sun, 3 May 2015 21:55:47 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:34643 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751923AbbEDBzr (ORCPT ); Sun, 3 May 2015 21:55:47 -0400 Received: by pacyx8 with SMTP id yx8so147801706pac.1 for ; Sun, 03 May 2015 18:55:46 -0700 (PDT) X-Received: by 10.66.62.201 with SMTP id a9mr38076657pas.101.1430704546830; Sun, 03 May 2015 18:55:46 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id c1sm11039412pdc.45.2015.05.03.18.55.44 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:55:45 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: gregkh@linuxfoundation.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Joel Schopp Subject: [PATCH for 3.14.y stable 29/47] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc Date: Mon, 4 May 2015 09:52:24 +0800 Message-Id: <1430704362-6292-30-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430704362-6292-1-git-send-email-shannon.zhao@linaro.org> References: <1430704362-6292-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.171 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: Joel Schopp commit dbff124e29fa24aff9705b354b5f4648cd96e0bb upstream. The current aarch64 calculation for VTTBR_BADDR_MASK masks only 39 bits and not all the bits in the PA range. This is clearly a bug that manifests itself on systems that allocate memory in the higher address space range. [ Modified from Joel's original patch to be based on PHYS_MASK_SHIFT instead of a hard-coded value and to move the alignment check of the allocation to mmu.c. Also added a comment explaining why we hardcode the IPA range and changed the stage-2 pgd allocation to be based on the 40 bit IPA range instead of the maximum possible 48 bit PA range. - Christoffer ] Reviewed-by: Catalin Marinas Signed-off-by: Joel Schopp Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/kvm/arm.c | 4 ++-- arch/arm64/include/asm/kvm_arm.h | 13 ++++++++++++- arch/arm64/include/asm/kvm_mmu.h | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index df6e75e..55c1ebf 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -427,9 +427,9 @@ static void update_vttbr(struct kvm *kvm) /* update vttbr to be used with the new vmid */ pgd_phys = virt_to_phys(kvm->arch.pgd); + BUG_ON(pgd_phys & ~VTTBR_BADDR_MASK); vmid = ((u64)(kvm->arch.vmid) << VTTBR_VMID_SHIFT) & VTTBR_VMID_MASK; - kvm->arch.vttbr = pgd_phys & VTTBR_BADDR_MASK; - kvm->arch.vttbr |= vmid; + kvm->arch.vttbr = pgd_phys | vmid; spin_unlock(&kvm_vmid_lock); } diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 00fbaa7..2bc2602 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -122,6 +122,17 @@ #define VTCR_EL2_T0SZ_MASK 0x3f #define VTCR_EL2_T0SZ_40B 24 +/* + * We configure the Stage-2 page tables to always restrict the IPA space to be + * 40 bits wide (T0SZ = 24). Systems with a PARange smaller than 40 bits are + * not known to exist and will break with this configuration. + * + * Note that when using 4K pages, we concatenate two first level page tables + * together. + * + * The magic numbers used for VTTBR_X in this patch can be found in Tables + * D4-23 and D4-25 in ARM DDI 0487A.b. + */ #ifdef CONFIG_ARM64_64K_PAGES /* * Stage2 translation configuration: @@ -151,7 +162,7 @@ #endif #define VTTBR_BADDR_SHIFT (VTTBR_X - 1) -#define VTTBR_BADDR_MASK (((1LLU << (40 - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) +#define VTTBR_BADDR_MASK (((1LLU << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) #define VTTBR_VMID_SHIFT (48LLU) #define VTTBR_VMID_MASK (0xffLLU << VTTBR_VMID_SHIFT) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 737da74..a030d16 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -59,10 +59,9 @@ #define KERN_TO_HYP(kva) ((unsigned long)kva - PAGE_OFFSET + HYP_PAGE_OFFSET) /* - * Align KVM with the kernel's view of physical memory. Should be - * 40bit IPA, with PGD being 8kB aligned in the 4KB page configuration. + * We currently only support a 40bit IPA. */ -#define KVM_PHYS_SHIFT PHYS_MASK_SHIFT +#define KVM_PHYS_SHIFT (40) #define KVM_PHYS_SIZE (1UL << KVM_PHYS_SHIFT) #define KVM_PHYS_MASK (KVM_PHYS_SIZE - 1UL)