Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5749648img; Wed, 27 Mar 2019 14:37:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8IFVg8Qp6gFO0lInEr08VlnQHTFi9MUshr5vPVE1OpiF05c45ufw48WXai0ntsczg6/kH X-Received: by 2002:a63:29c8:: with SMTP id p191mr28621799pgp.197.1553722662731; Wed, 27 Mar 2019 14:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553722662; cv=none; d=google.com; s=arc-20160816; b=GETljcY1UP7mHoOZrCY2RGNsLfxxVYo8jXetVBIWCMkNvu+MuZ5VMUCN69E6m7NIOd t0q78xhlG+rRWTu8pWmEn9FKsQqVU/ZpgMeFCYe1GDXSUn8Wd0wdwtqIxLA+YBqMJOyh TrfnPGzYIlEg2B0o+/J3nIIdb+tUFy4QhUjaGCIDnvy8aTKDCJ+AA7NST/CPuPixzJzV c5DNx6wCGjer9GTr96UnIymhrwVoyzD3bYsNy2GTahC+7f1A08Wo8vycjadr7EijIy+L rASmKRdT5HrgYSdIPSWQzHN18ArxbWdX+92oDZ7VIe5ZDumjznbLuXb+L9AYnhYLJ8MF 4auQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=LRI+dc/KlJUoYE25Ew5tA1y+glZ6wtdPjKLNKoeWGR4=; b=swqBvyvCtjBpJlSnsXRmTaodkQE327nkjaMInBbW+4W0h81sZwe86dG+NcMyvxlcAn g0HhGFBJWO5TN5KHaaMkGa9uwsKeQkMtlnBJi3bXdw+JXfp9Pvf8MceInTJu7puJQ81a f4SX/JPHY80aLiOf+Ds1m+GueM2xeVJlUGRTPKREJCFbU9B5wVB5mOtkRqB9ksmQnE+B Px0h3yy7LQkWf6QvTUsWBFgarBhvSbbyLuZ4uIMN1gK3x2yILCEJpP0Vjryw/IytTlRi UDVIw65Tc6ovEshLrDG6TmE1nXO6VNd9gr9QznvAl+Z/2DVJR3Y2yKsFLApRQ/KDoEuJ 94xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 16si19334731pgc.312.2019.03.27.14.37.26; Wed, 27 Mar 2019 14:37:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728934AbfC0Vgu (ORCPT + 99 others); Wed, 27 Mar 2019 17:36:50 -0400 Received: from ale.deltatee.com ([207.54.116.67]:58652 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbfC0Vgt (ORCPT ); Wed, 27 Mar 2019 17:36:49 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1h9GE3-0006DK-7y; Wed, 27 Mar 2019 15:36:48 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1h9GE2-0006Ch-8E; Wed, 27 Mar 2019 15:36:46 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Stephen Bates , Palmer Dabbelt , Christoph Hellwig , Albert Ou , Logan Gunthorpe , Anup Patel , Atish Patra , Paul Walmsley , Zong Li , Mike Rapoport Date: Wed, 27 Mar 2019 15:36:40 -0600 Message-Id: <20190327213643.23789-5-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327213643.23789-1-logang@deltatee.com> References: <20190327213643.23789-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, sbates@raithlin.com, hch@lst.de, aou@eecs.berkeley.edu, logang@deltatee.com, anup.patel@wdc.com, atish.patra@wdc.com, palmer@sifive.com, paul.walmsley@sifive.com, zongbox@gmail.com, rppt@linux.ibm.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.2 Subject: [PATCH 4/7] RISC-V: Update page tables to cover the whole linear mapping X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the new virtual address changes in an earlier patch, we want the page tables to cover more of the linear mapping region. Instead of only mapping from PAGE_OFFSET and up, we instead map starting from an aligned version of va_pa_offset such that all of the physical address space will be mapped. Signed-off-by: Logan Gunthorpe Cc: Palmer Dabbelt Cc: Albert Ou Cc: Anup Patel Cc: Atish Patra Cc: Paul Walmsley Cc: Zong Li Cc: Mike Rapoport --- arch/riscv/kernel/setup.c | 1 - arch/riscv/mm/init.c | 27 +++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index ecb654f6a79e..8286df8be31a 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -59,7 +59,6 @@ EXPORT_SYMBOL(empty_zero_page); /* The lucky hart to first increment this variable will boot the other cores */ atomic_t hart_lottery; unsigned long boot_cpu_hartid; - void __init parse_dtb(unsigned int hartid, void *dtb) { if (early_init_dt_scan(__va(dtb))) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b9d50031e78f..315194557c3d 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -150,8 +150,8 @@ pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); #ifndef __PAGETABLE_PMD_FOLDED -#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT) -pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss; +#define NUM_SWAPPER_PMDS ((uintptr_t)-VMALLOC_END >> PGDIR_SHIFT) +pmd_t swapper_pmd[PTRS_PER_PMD*((-VMALLOC_END)/PGDIR_SIZE)] __page_aligned_bss; pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss; #endif @@ -180,13 +180,18 @@ asmlinkage void __init setup_vm(void) extern char _start; uintptr_t i; uintptr_t pa = (uintptr_t) &_start; + uintptr_t linear_start; + uintptr_t off; pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC); va_pa_offset = PAGE_OFFSET - pa; pfn_base = PFN_DOWN(pa); + linear_start = ALIGN_DOWN(va_pa_offset, PGDIR_SIZE); + off = linear_start - va_pa_offset; + /* Sanity check alignment and size */ - BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0); + BUG_ON(linear_start <= VMALLOC_END); BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0); #ifndef __PAGETABLE_PMD_FOLDED @@ -195,15 +200,14 @@ asmlinkage void __init setup_vm(void) __pgprot(_PAGE_TABLE)); trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot); - for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) { - size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i; - + for (i = 0; i < (-linear_start)/PGDIR_SIZE; ++i) { + size_t o = (linear_start >> PGDIR_SHIFT) % PTRS_PER_PGD + i; swapper_pg_dir[o] = pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i, __pgprot(_PAGE_TABLE)); } for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++) - swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot); + swapper_pmd[i] = pfn_pmd(PFN_DOWN(off + i * PMD_SIZE), prot); swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pmd), @@ -215,11 +219,10 @@ asmlinkage void __init setup_vm(void) trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] = pfn_pgd(PFN_DOWN(pa), prot); - for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) { - size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i; - - swapper_pg_dir[o] = - pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot); + for (i = 0; i < (-linear_start)/PGDIR_SIZE; ++i) { + size_t o = (linear_start >> PGDIR_SHIFT) % PTRS_PER_PGD + i; + swapper_pg_dir[o] = pfn_pgd(PFN_DOWN(off + i * PGDIR_SIZE), + prot); } swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] = -- 2.20.1