From patchwork Mon May 4 01:51:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47942 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B18702121F for ; Mon, 4 May 2015 01:53:49 +0000 (UTC) Received: by lbbrr5 with SMTP id rr5sf38770004lbb.3 for ; Sun, 03 May 2015 18:53:48 -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=PgzfSsp40fLCMf6jma5DZ+pAaqf/RRrBX2ty+7SGNAI=; b=eDg57TbnOjrk9ZlQ3sAKkHy388gdKAckrNJYyvcnAhFJHE7fi8dNCcj7d95OVCgba1 jeXwVSGcStKfCUeEGzWfdh2XcHSSa4ioAn0eO428bNZHQO0Ao9Gu58ik8qcSh7fdy/SP YgP3KoSEMQKqxj2mRwgxY9159HFrynC5RBDdoqeh46Qrr2OnVPLBmNWUIFpjOQvyR+5s xI0gOAU9fi+KSL3y9D99OkZAVmNd8tSMef/sRsXNy0UtQuGnI9s0gtSKIBx47OvUGkrw VnAxnu1Xac0hXfdJ2CF5uLRbIuj18iDwPvmcMFb3ksEKMhL4LtRtAyfSK46XG0Wkq95T 8dKQ== X-Gm-Message-State: ALoCoQklyXxYeHopja48aSwd02WsK0L1Xqug/ooaLq+oCQM5u9aAfpPX5PoUoQLjyLDYiUyCPzQH X-Received: by 10.180.88.226 with SMTP id bj2mr6854986wib.7.1430704428693; Sun, 03 May 2015 18:53:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.98 with SMTP id u2ls661344lae.84.gmail; Sun, 03 May 2015 18:53:48 -0700 (PDT) X-Received: by 10.112.161.66 with SMTP id xq2mr17832609lbb.31.1430704428532; Sun, 03 May 2015 18:53:48 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id zz9si9067407lbb.157.2015.05.03.18.53.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:53:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbcga7 with SMTP id ga7so95732877lbc.1 for ; Sun, 03 May 2015 18:53:48 -0700 (PDT) X-Received: by 10.112.16.196 with SMTP id i4mr17369113lbd.72.1430704428359; Sun, 03 May 2015 18:53:48 -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 l1csp1412483lbt; Sun, 3 May 2015 18:53:47 -0700 (PDT) X-Received: by 10.66.145.133 with SMTP id su5mr37640115pab.114.1430704426521; Sun, 03 May 2015 18:53:46 -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.53.45; Sun, 03 May 2015 18:53:46 -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 S1751647AbbEDBxp (ORCPT + 2 others); Sun, 3 May 2015 21:53:45 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:35625 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbbEDBxo (ORCPT ); Sun, 3 May 2015 21:53:44 -0400 Received: by pabtp1 with SMTP id tp1so147787730pab.2 for ; Sun, 03 May 2015 18:53:44 -0700 (PDT) X-Received: by 10.70.47.9 with SMTP id z9mr38419354pdm.69.1430704424309; Sun, 03 May 2015 18:53:44 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id qe9sm11005917pbc.62.2015.05.03.18.53.42 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:53:42 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: gregkh@linuxfoundation.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.14.y stable 04/47] ARM: KVM: introduce kvm_p*d_addr_end Date: Mon, 4 May 2015 09:51:59 +0800 Message-Id: <1430704362-6292-5-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.169 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: Marc Zyngier commit a3c8bd31af260a17d626514f636849ee1cd1f63e upstream. The use of p*d_addr_end with stage-2 translation is slightly dodgy, as the IPA is 40bits, while all the p*d_addr_end helpers are taking an unsigned long (arm64 is fine with that as unligned long is 64bit). The fix is to introduce 64bit clean versions of the same helpers, and use them in the stage-2 page table code. Signed-off-by: Marc Zyngier Acked-by: Catalin Marinas Reviewed-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/include/asm/kvm_mmu.h | 13 +++++++++++++ arch/arm/kvm/mmu.c | 10 +++++----- arch/arm64/include/asm/kvm_mmu.h | 4 ++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 6d0f3d3..891afe7 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -114,6 +114,19 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd) pmd_val(*pmd) |= L_PMD_S2_RDWR; } +/* Open coded p*d_addr_end that can deal with 64bit addresses */ +#define kvm_pgd_addr_end(addr, end) \ +({ u64 __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) + +#define kvm_pud_addr_end(addr,end) (end) + +#define kvm_pmd_addr_end(addr, end) \ +({ u64 __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) + struct kvm; static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva, diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 2fcd3a3..04d59f1 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -147,7 +147,7 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp, pgd = pgdp + pgd_index(addr); pud = pud_offset(pgd, addr); if (pud_none(*pud)) { - addr = pud_addr_end(addr, end); + addr = kvm_pud_addr_end(addr, end); continue; } @@ -157,13 +157,13 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp, * move on. */ clear_pud_entry(kvm, pud, addr); - addr = pud_addr_end(addr, end); + addr = kvm_pud_addr_end(addr, end); continue; } pmd = pmd_offset(pud, addr); if (pmd_none(*pmd)) { - addr = pmd_addr_end(addr, end); + addr = kvm_pmd_addr_end(addr, end); continue; } @@ -178,10 +178,10 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp, */ if (kvm_pmd_huge(*pmd) || page_empty(pte)) { clear_pmd_entry(kvm, pmd, addr); - next = pmd_addr_end(addr, end); + next = kvm_pmd_addr_end(addr, end); if (page_empty(pmd) && !page_empty(pud)) { clear_pud_entry(kvm, pud, addr); - next = pud_addr_end(addr, end); + next = kvm_pud_addr_end(addr, end); } } diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 6eaf69b..00c0cc8 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -121,6 +121,10 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd) pmd_val(*pmd) |= PMD_S2_RDWR; } +#define kvm_pgd_addr_end(addr, end) pgd_addr_end(addr, end) +#define kvm_pud_addr_end(addr, end) pud_addr_end(addr, end) +#define kvm_pmd_addr_end(addr, end) pmd_addr_end(addr, end) + struct kvm; #define kvm_flush_dcache_to_poc(a,l) __flush_dcache_area((a), (l))