From patchwork Fri Apr 24 05:27:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47533 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 94C3720553 for ; Fri, 24 Apr 2015 05:34:11 +0000 (UTC) Received: by wgiv13 with SMTP id v13sf9013968wgi.3 for ; Thu, 23 Apr 2015 22:34:10 -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=X0dn17u9p8IYXfiPUNuoLdh05bEH+1FLWVM6v6suMDo=; b=WHrXRoyf3zzjTjdscJ/klinZv36fVBB5uanAIy4DeDhVCXg3DJQ3J1eecKd8/efqvJ 9kNg2vGjhgDHsnCiVbu75yjT1tTR7Ri+wte0B2rg4boyF430/9EbMwqqK3EaAIIenr80 wUaJPinY0m2d7aQw5pepho57bBcmJ2zVob3eD7bBICRDv1fmpSTOfDojG5rJjVaOtAsX 9OubLXuVlT4UiO+0+iAoj95w7xUeVK2iUmA+GRTeAa+BojogOqElRHEeferHkKybQJbp ZgSuAsuH3M22RE9rmh8WcMsiaTzj6PaGqBbcpmraWNh+i36NGVc+bLQa0S8r2bAWsqJF 96cQ== X-Gm-Message-State: ALoCoQkv6Gn3HX0SeLCP8nkw4Wc1ZT49Ze+8Rw056sbmCBZXWMpCc9gHDkkY/EhxhKvesMzNsE6l X-Received: by 10.112.122.39 with SMTP id lp7mr3191722lbb.5.1429853650867; Thu, 23 Apr 2015 22:34:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.169 with SMTP id x9ls449861lal.92.gmail; Thu, 23 Apr 2015 22:34:10 -0700 (PDT) X-Received: by 10.152.27.98 with SMTP id s2mr5454644lag.106.1429853650684; Thu, 23 Apr 2015 22:34:10 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id lc4si7480842lac.26.2015.04.23.22.34.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:34:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbqq2 with SMTP id qq2so28563937lbb.3 for ; Thu, 23 Apr 2015 22:34:10 -0700 (PDT) X-Received: by 10.152.9.66 with SMTP id x2mr5434070laa.36.1429853650393; Thu, 23 Apr 2015 22:34:10 -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 l1csp978679lbt; Thu, 23 Apr 2015 22:34:09 -0700 (PDT) X-Received: by 10.70.36.175 with SMTP id r15mr3067284pdj.26.1429853648499; Thu, 23 Apr 2015 22:34:08 -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.34.07; Thu, 23 Apr 2015 22:34:08 -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 S1754566AbbDXFeH (ORCPT + 2 others); Fri, 24 Apr 2015 01:34:07 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:34493 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754559AbbDXFeG (ORCPT ); Fri, 24 Apr 2015 01:34:06 -0400 Received: by oiko83 with SMTP id o83so32505742oik.1 for ; Thu, 23 Apr 2015 22:34:06 -0700 (PDT) X-Received: by 10.202.177.68 with SMTP id a65mr5375386oif.46.1429853646028; Thu, 23 Apr 2015 22:34:06 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id w72sm6074505oie.28.2015.04.23.22.34.03 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:34:04 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Joel Schopp Subject: [PATCH for 3.12.y stable 48/63] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc Date: Fri, 24 Apr 2015 13:27:46 +0800 Message-Id: <1429853281-6136-49-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.217.172 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 8eacf88..26ca5c6 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -425,9 +425,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 fd0a651..0392ab7 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 6e8eacd..5966ad5 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)