From patchwork Fri Nov 15 16:10:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 3188761 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 05730C045B for ; Fri, 15 Nov 2013 16:09:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DBC5B2095B for ; Fri, 15 Nov 2013 16:09:41 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA43F2096B for ; Fri, 15 Nov 2013 16:09:34 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VhLxN-0002MC-Hf; Fri, 15 Nov 2013 16:09:17 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VhLxG-0006XB-PJ; Fri, 15 Nov 2013 16:09:10 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VhLxE-0006VL-S0 for linux-arm-kernel@lists.infradead.org; Fri, 15 Nov 2013 16:09:09 +0000 Received: by mail-pb0-f49.google.com with SMTP id um1so3741287pbc.36 for ; Fri, 15 Nov 2013 08:08:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=NUKZMijX0ffgQ5gaXT5qAKDUZVnPlcvow1eY3nlWiuA=; b=JoeynKknZxKuWG/ql42Vs3qKIpeUKnZJYIf+vOAKejzvo1rUZaPnJ4xw2j1tvQKNH6 lThxs4vtTRrfxwUGNhMPgPf4pBkLr8HzOw8SbSEuG6kc01SPxgoQf9MD3DlQzOYG+3Vb m3gw/qw0AUqLU9p4/31S7bG6N+I3Swgatwm/d4EvIA/Q6TYcBw0bA0oqCMBHrt1rrv79 HNURXplJtOjkZtbI4PiDTvgDmb9GBx37WFBOvyVkJztsiBLxYqtCt+iAtO9oA3ofOtE9 zYRI1hd3gj4EXv2i1UKIFMvWaNVmaW+FBfDJXEbT9YqEoujeA5gmxJdQ7i0tiaS3qErs 63xA== X-Gm-Message-State: ALoCoQkqYCkYLkKxw91JnhInU5b4M1Am+rNllpIDEeWlMK01tCvZoW0Qq5GdO2DFC7G59FvRisAo X-Received: by 10.66.152.11 with SMTP id uu11mr7658960pab.124.1384531726689; Fri, 15 Nov 2013 08:08:46 -0800 (PST) Received: from localhost (c-67-169-181-221.hsd1.ca.comcast.net. [67.169.181.221]) by mx.google.com with ESMTPSA id sy10sm6029366pac.15.2013.11.15.08.08.45 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 15 Nov 2013 08:08:45 -0800 (PST) Date: Fri, 15 Nov 2013 08:10:04 -0800 From: Christoffer Dall To: Marc Zyngier Subject: Re: [PATCH] arm/arm64: KVM: introduce new mapping API for percpu mappings Message-ID: <20131115161004.GA25051@cbox> References: <1384530008-18181-1-git-send-email-marc.zyngier@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1384530008-18181-1-git-send-email-marc.zyngier@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131115_110908_975122_BC6E84C3 X-CRM114-Status: GOOD ( 15.06 ) X-Spam-Score: -2.6 (--) Cc: Santosh Shilimkar , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Nov 15, 2013 at 03:40:08PM +0000, Marc Zyngier wrote: > Using virt_to_phys on percpu mappings is horribly wrong (my own bad). > Thankfully, the kernel offers a way to obtain the physical address > of such a mapping. > > Add a new create_hyp_percpu_mappings function to deal with those. > > Reported-by: Santosh Shilimkar > Cc: Christoffer Dall > Signed-off-by: Marc Zyngier > --- So, I find this nicer, somehow, what do you think: diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 3719583..dd531ba 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -334,6 +334,15 @@ out: return err; } +static phys_addr_t kvm_kaddr_to_phys(void *kaddr) +{ + if (!is_vmalloc_addr(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 +354,24 @@ 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; + for (virt_addr = start; virt_addr < end; virt_addr += PAGE_SIZE) { + int err; - return __create_hyp_mappings(hyp_pgd, start, end, - __phys_to_pfn(phys_addr), PAGE_HYP); + 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; } /**