From patchwork Fri Nov 15 23:24:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 21547 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7605223FD6 for ; Fri, 15 Nov 2013 23:23:32 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id r7sf7204318qcx.11 for ; Fri, 15 Nov 2013 15:23:31 -0800 (PST) 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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=90AnTo1Oq+74nk2WEZBU4W71vrSeR7OlliFkT/pr1RY=; b=L4G1keNrLGO8UZijK0LcouEG8jrCDDpp+7nq8DepmZ8PUFkGiDPVNU8CMSaSDJ/uf1 62u5Iwm+S+0tIFvm8a9lOiNmOVO0VqgKURWe8QN09HtJDsxF3rhlpq/Sp06XHNm7VUpx 2Zf9gPCpCUyHjasDQdkXkrGze2UuSTVlZOaTbYoLcrvx559VNvC/X55avveJffezDgaC DYtpMMDD5DeIp17/S++wJEAtv+fYiuOiABcGJIyOkiQjue7leuTzSNv4oPAr3eW/mjUS mwv41Z4U5JiwTJUlOHc+5M99gSrhSZzQ9HxkWdY9ekGsX1sVamY7wk58UdOVLG7mD2XI 1VjQ== X-Gm-Message-State: ALoCoQljqonrTSzCHjvRoUGkLmO6iG8SKQ5o6jDwvU01kFcl0ojlJTYCJVzp2cAJa1WIpyqMi0hk X-Received: by 10.58.23.166 with SMTP id n6mr3972596vef.13.1384557811775; Fri, 15 Nov 2013 15:23:31 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.94.196 with SMTP id de4ls1778448qeb.77.gmail; Fri, 15 Nov 2013 15:23:31 -0800 (PST) X-Received: by 10.220.206.131 with SMTP id fu3mr23940vcb.80.1384557811615; Fri, 15 Nov 2013 15:23:31 -0800 (PST) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id wp10si2417525vdb.110.2013.11.15.15.23.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Nov 2013 15:23:31 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id if17so2216646vcb.33 for ; Fri, 15 Nov 2013 15:23:31 -0800 (PST) X-Received: by 10.220.244.132 with SMTP id lq4mr1039050vcb.31.1384557811245; Fri, 15 Nov 2013 15:23:31 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp63255vcz; Fri, 15 Nov 2013 15:23:30 -0800 (PST) X-Received: by 10.68.218.165 with SMTP id ph5mr8863024pbc.11.1384557810043; Fri, 15 Nov 2013 15:23:30 -0800 (PST) Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by mx.google.com with ESMTPS id sw1si3222874pbc.282.2013.11.15.15.23.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Nov 2013 15:23:30 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.45 is neither permitted nor denied by best guess record for domain of christoffer.dall@linaro.org) client-ip=209.85.160.45; Received: by mail-pb0-f45.google.com with SMTP id mc8so4233117pbc.4 for ; Fri, 15 Nov 2013 15:23:29 -0800 (PST) X-Received: by 10.68.203.195 with SMTP id ks3mr1552128pbc.83.1384557809489; Fri, 15 Nov 2013 15:23:29 -0800 (PST) Received: from localhost.localdomain (c-67-169-181-221.hsd1.ca.comcast.net. [67.169.181.221]) by mx.google.com with ESMTPSA id wp8sm6942123pbc.26.2013.11.15.15.23.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Nov 2013 15:23:28 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, patches@linaro.org, Christoffer Dall , Marc Zyngier Subject: [PATCH] arm/arm64: KVM: Fix hyp mappings of vmalloc regions Date: Fri, 15 Nov 2013 15:24:40 -0800 Message-Id: <1384557880-14107-1-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Using virt_to_phys on percpu mappings is horribly wrong as it may be backed by vmalloc. Introduce kvm_kaddr_to_phys which translates both types of valid kernel addresses to the corresponding physical address. At the same time resolves a typing issue where we were storing the physical address as a 32 bit unsigned long (on arm), truncating the physical address for addresses above the 4GB limit. This caused breakage on Keystone. Reported-by: Santosh Shilimkar Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- This patch is loosely based on Marc's previous patch from today but instead of introducing another Hyp mapping function, it fixes the existing one to deal with both kinds of kernel addresses. arch/arm/kvm/mmu.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 3719583..5809069 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -334,6 +334,17 @@ out: return err; } +static phys_addr_t kvm_kaddr_to_phys(void *kaddr) +{ + if (!is_vmalloc_addr(kaddr)) { + BUG_ON(!virt_addr_valid(kaddr)); + return __pa(kaddr); + } else { + return page_to_phys(vmalloc_to_page(kaddr)) + + offset_in_page(kaddr); + } +} + /** * create_hyp_mappings - duplicate a kernel virtual address range in Hyp mode * @from: The virtual kernel start address of the range @@ -345,16 +356,27 @@ out: */ int create_hyp_mappings(void *from, void *to) { - unsigned long phys_addr = virt_to_phys(from); + phys_addr_t phys_addr; + unsigned long virt_addr; unsigned long start = KERN_TO_HYP((unsigned long)from); unsigned long end = KERN_TO_HYP((unsigned long)to); - /* Check for a valid kernel memory mapping */ - if (!virt_addr_valid(from) || !virt_addr_valid(to - 1)) - return -EINVAL; + start = start & PAGE_MASK; + end = PAGE_ALIGN(end); - return __create_hyp_mappings(hyp_pgd, start, end, - __phys_to_pfn(phys_addr), PAGE_HYP); + for (virt_addr = start; virt_addr < end; virt_addr += PAGE_SIZE) { + int err; + + phys_addr = kvm_kaddr_to_phys(from + virt_addr - start); + err = __create_hyp_mappings(hyp_pgd, virt_addr, + virt_addr + PAGE_SIZE, + __phys_to_pfn(phys_addr), + PAGE_HYP); + if (err) + return err; + } + + return 0; } /**