Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp595875ybg; Wed, 3 Jun 2020 08:42:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm1UK3EfEDgCJ7Y3BUIVlmFXhm6AIkhzeFtQ9XwiV41dwoqAATnCo7EtpYNwa/vB5aAJNB X-Received: by 2002:aa7:cdda:: with SMTP id h26mr25009231edw.327.1591198932680; Wed, 03 Jun 2020 08:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591198932; cv=none; d=google.com; s=arc-20160816; b=SffKnlM+CoCK6x/+NTqzGO2LbxCrFUH10tX2BsKCo/1lrJEBxKmt4LA4fN66kwEPTs aa0Kb23YzocjQqNMqhwhD8gQy37+5kPKYNcYN9tdc1KRgRNi1lF+hkNMso+WFKZVikxU 9QQqqWLBQX/z4z5UrIGY3RVS5oecnyOUiotZ7u8Z2tspO5DaXGafwC2HfAKN05FTP3k3 HfJyogKB0Mv+H+K1PMi35+iEiMruKABClQpny3GdOHki6QVovyCRq2yXjSnwde0oBxIU YDZXafn0gNoLklt1z7gM7jCVrw7ZbhAdUXqBgVYMgZUZVsJyziqLvyZqNa2V3ETJnzrS KpTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tETO9ars3qx4Orm0RFV7MLueBBFZKPD2GEgabqzYEKU=; b=cxklPl5DkEwZ7FlH65MjNoyemDxhxKvk+MStZetyWm3A3QGPSGf7ExMO3GT6jLiaZW SkxzK8n4PrLvAii0hh/ST1MJO2ZUcZstdXIfugEGRPjkAMu/z7yukLXQEtub11Nrw4Um tjX91/QNow7mwLDSF+L/T/BVqAtUxh+RhNd5FJynme0/gI4ep1EAmXbRkAQDPYAUQNtg zbzJ+eSGmkZiXwsmK+z+891/4tkzZjhUug5Nx5oqSl9zKK8BkBmhE33zb/Sbs1kLXwS8 lnCWXYc1jvZrJgo7LaM+1UswN1NdssJhXEU9bqrfW6DIh0uwV+bnHQld7RTrurNOvlDe rOpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si1291700edl.466.2020.06.03.08.41.48; Wed, 03 Jun 2020 08:42:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726186AbgFCPhU (ORCPT + 99 others); Wed, 3 Jun 2020 11:37:20 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:37783 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726061AbgFCPhT (ORCPT ); Wed, 3 Jun 2020 11:37:19 -0400 X-Originating-IP: 90.112.45.105 Received: from debian.home (lfbn-gre-1-325-105.w90-112.abo.wanadoo.fr [90.112.45.105]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id BB59E2000F; Wed, 3 Jun 2020 15:37:16 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 1/2] riscv: Get memory below load_pa while ensuring linear mapping is PMD aligned Date: Wed, 3 Jun 2020 11:36:07 -0400 Message-Id: <20200603153608.30056-2-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200603153608.30056-1-alex@ghiti.fr> References: <20200603153608.30056-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Early page table uses the kernel load address as mapping for PAGE_OFFSET: that makes memblock remove any memory below the kernel which results in using only PMD entries for the linear mapping. By setting MIN_MEMBLOCK_ADDR to 0, we allow this memory to be present when creating the kernel page table: that potentially allows to use PUD/PGDIR entries for the linear mapping. But as the firmware might ask the kernel to remove some part of this memory, we need to ensure that the physical address targeted by PAGE_OFFSET is at least aligned on PMD size since otherwise the linear mapping would use only PTE entries. Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/page.h | 8 ++++++++ arch/riscv/mm/init.c | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 5e77fe7f0d6d..b416396fc357 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -100,6 +100,14 @@ typedef struct page *pgtable_t; #define PTE_FMT "%08lx" #endif +/* + * Early page table maps PAGE_OFFSET to load_pa, which may not be the memory + * base address and by default MIN_MEMBLOCK_ADDR is equal to __pa(PAGE_OFFSET) + * then memblock ignores memory below load_pa: we want this memory to get mapped + * as it may allow to use hugepages for linear mapping. + */ +#define MIN_MEMBLOCK_ADDR 0 + #ifdef CONFIG_MMU extern unsigned long va_pa_offset; extern unsigned long va_kernel_pa_offset; diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 4064639b24e4..9a5c97e091c1 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -664,7 +664,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) static void __init setup_vm_final(void) { uintptr_t va, map_size; - phys_addr_t pa, start, end; + phys_addr_t pa, start, end, dram_start; struct memblock_region *reg; static struct vm_struct vm_kernel = { 0 }; @@ -676,6 +676,28 @@ static void __init setup_vm_final(void) __pa_symbol(fixmap_pgd_next), PGDIR_SIZE, PAGE_TABLE); + /* + * Make sure that virtual and physical addresses are at least aligned + * on PMD_SIZE, even if we have to lose some memory (< PMD_SIZE) + * otherwise the linear mapping would get mapped using PTE entries. + */ + dram_start = memblock_start_of_DRAM(); + if (dram_start & (PMD_SIZE - 1)) { + uintptr_t next_dram_start; + + next_dram_start = (dram_start + PMD_SIZE - 1) & ~(PMD_SIZE - 1); + memblock_remove(dram_start, next_dram_start - dram_start); + dram_start = next_dram_start; + } + + /* + * We started considering PAGE_OFFSET would start at load_pa because + * it was the only piece of information we had, but now make PAGE_OFFSET + * point to the real beginning of the memory area. + */ + va_pa_offset = PAGE_OFFSET - dram_start; + pfn_base = PFN_DOWN(dram_start); + /* Map all memory banks */ for_each_memblock(memory, reg) { start = reg->base; -- 2.20.1