From patchwork Thu Sep 25 18:32:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 37931 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 96041202DB for ; Thu, 25 Sep 2014 18:33:50 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id s18sf6739257lam.5 for ; Thu, 25 Sep 2014 11:33:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=zzKfBeRDj0cIvS0C3OtfB/B6XV8kt94ZedU1/cbiYMQ=; b=R6DZC48g08QOfsU2m2KXE1HVPQ888B6iLycfkV6/NfdxdMKNQiYq8pTD4869HnIFlu 6FaVfskrEJRTJHPqpsDoXNq5qWAQzt69gTT32dS5x/eI2C5FYmKHRKPMsDC3dwHAZsyl AQHeHUlB5QFSfPLjrGLZ50H288st/lMAYttUiXT4faqJ5pxKJDT2uG2s+B3UdSkscEVK pcX536nhM2Tof89933zBDfh/9DfSd5Q0OGS89TKsy2bAMOfaAip0EfDdYQ094VdmPD5E VIZ3WMQFtKOPvPcB9n/5Dlwjcmu3Y5HgujGOPIrPdU3gK+Tq13vDvWCL4VrhqKeRPvyf WWJQ== X-Gm-Message-State: ALoCoQnkRYPftVy8DbuzylOPfpQNWegBq6R11vpdiQNdsuLma8K5zScqq699IClf3e4SuFGsXNCv X-Received: by 10.152.6.9 with SMTP id w9mr589639law.7.1411670029411; Thu, 25 Sep 2014 11:33:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.116.18 with SMTP id js18ls325047lab.69.gmail; Thu, 25 Sep 2014 11:33:49 -0700 (PDT) X-Received: by 10.152.25.129 with SMTP id c1mr15716492lag.14.1411670029259; Thu, 25 Sep 2014 11:33:49 -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 cr11si4192837lad.61.2014.09.25.11.33.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Sep 2014 11:33:49 -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 mail-la0-f54.google.com with SMTP id ty20so614699lab.41 for ; Thu, 25 Sep 2014 11:33:49 -0700 (PDT) X-Received: by 10.112.130.226 with SMTP id oh2mr4675124lbb.100.1411670029108; Thu, 25 Sep 2014 11:33:49 -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.130.169 with SMTP id of9csp804291lbb; Thu, 25 Sep 2014 11:33:48 -0700 (PDT) X-Received: by 10.68.245.135 with SMTP id xo7mr21971669pbc.161.1411670027649; Thu, 25 Sep 2014 11:33:47 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id pq1si5244540pac.109.2014.09.25.11.33.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Sep 2014 11:33:47 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XXDq4-0003K3-3N; Thu, 25 Sep 2014 18:32:24 +0000 Received: from mail-lb0-f175.google.com ([209.85.217.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XXDq1-0003En-Nt for linux-arm-kernel@lists.infradead.org; Thu, 25 Sep 2014 18:32:22 +0000 Received: by mail-lb0-f175.google.com with SMTP id w7so7617940lbi.34 for ; Thu, 25 Sep 2014 11:31:58 -0700 (PDT) X-Received: by 10.152.202.135 with SMTP id ki7mr11569116lac.16.1411669918736; Thu, 25 Sep 2014 11:31:58 -0700 (PDT) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id ey9sm1075787lbc.1.2014.09.25.11.31.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Sep 2014 11:31:57 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc Date: Thu, 25 Sep 2014 20:32:19 +0200 Message-Id: <1411669939-24648-1-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.0.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140925_113221_966932_859023DC X-CRM114-Status: GOOD ( 14.93 ) X-Spam-Score: -1.0 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.175 listed in list.dnswl.org] -0.3 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.217.175 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record Cc: Catalin Marinas , jungseoklee85@gmail.com, Christoffer Dall , kvm@vger.kernel.org, Joel Schopp X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@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 From: Joel Schopp 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 ] Signed-off-by: Joel Schopp Signed-off-by: Christoffer Dall Reviewed-by: Catalin Marinas --- 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 40bc3df..7796051 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -410,9 +410,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 cc83520..7fd3e27 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: @@ -149,7 +160,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)