Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5750026img; Wed, 27 Mar 2019 14:38:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkDZVlj/72hjCML73eafdE+/Y4LHHQsOxFJ0Dcnsx5gd1JXafz2y00UNXDFB1yKjJAT40q X-Received: by 2002:a63:4e64:: with SMTP id o36mr35553945pgl.213.1553722701525; Wed, 27 Mar 2019 14:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553722701; cv=none; d=google.com; s=arc-20160816; b=PBLT0ZCBReFxHshzJsx31nn95SvCqI4AuBGIVmqVjPSv/mGs392iGD4foXxWvmim9x tQdc8XupgfiN5y0uWRY85U1rOmoqcAeVsSOAxsH6N6ZB3geb/9lXjIZWWPeHjnIyqvsd YX3lsmjqD6qrLzNnNXo3xk5fu3viqk7ytH7hrMAJF+9XVjWHlad+bDF+vcQhAlstH9Rr dAE6cpaJW1WBjPqypKVZGDRdB0kcTJtKHknT9Bwzvt0tclIqUiEar4VSIe7O3SWz5Rqv 7Ssohm+PvOzWYqqXzVZ5lEFFTG+kopzPG8mi9oHeb/RrzSzbS2SdIJYFUnZeyiu4Trku JiZw== 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=3RYA3WnvSgd5mT81KbFZJo6nXMEqd0FehdSHohrvAMo=; b=t8UdrpJmoxpYZIOdsD03eorv5H9CK/g5fuBFTEwzKAHYf/cq0AmXBQjhg7WIkxHhkD YXDmEIpEC07UaXfnmB9OQhQ5bTHCkSYX+TCCzaQdyG31sKQOY/ry55JaGEAZoYi1hx+I 9Gsnd5FIC0rdsWIdB5UX7NXCX8JTnvA8A1h98A8i1QE9fgh3FpdikmuYl8ESgryUIJoM 0Snacb2wOauRoEDN9H7RTv3BfKg9XYxgq8TJ9AGq85SFMWmwg2V7oE9jvWiy6YD7/o7C VcjsKr+9+KFV+bZiFWf20FatswSkKVHL/5Zqw2ScJWYofNGU/dYedx02GOVwOG3uTxiH 8PBQ== 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 s205si16253175pgs.467.2019.03.27.14.38.06; Wed, 27 Mar 2019 14:38:21 -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 S1730171AbfC0VhO (ORCPT + 99 others); Wed, 27 Mar 2019 17:37:14 -0400 Received: from ale.deltatee.com ([207.54.116.67]:58656 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727140AbfC0Vgt (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-0006DH-Ms; 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 1h9GE1-0006CY-Th; Wed, 27 Mar 2019 15:36:45 -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 , Andrew Waterman , Olof Johansson , Michael Clark , Rob Herring , Zong Li Date: Wed, 27 Mar 2019 15:36:37 -0600 Message-Id: <20190327213643.23789-2-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, palmer@sifive.com, andrew@sifive.com, olof@lixom.net, michaeljclark@mac.com, robh@kernel.org, zong@andestech.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 1/7] RISC-V: Implement sparsemem 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 This patch implements sparsemem support for risc-v which helps pave the way for memory hotplug and eventually P2P support. We introduce Kconfig options for virtual and physical address bits which are used to calculate the size of the vmemmap and set the MAX_PHYSMEM_BITS. The vmemmap is located directly before the VMALLOC region and sized such that we can allocate enough pages to populate all the virtual address space in the system (similar to the way it's done in arm64). During initialization, call memblocks_present() and sparse_init(), and provide a stub for vmemmap_populate() (all of which is similar to arm64). Signed-off-by: Logan Gunthorpe Reviewed-by: Palmer Dabbelt Reviewed-by: Christoph Hellwig Cc: Albert Ou Cc: Andrew Waterman Cc: Olof Johansson Cc: Michael Clark Cc: Rob Herring Cc: Zong Li --- arch/riscv/Kconfig | 23 +++++++++++++++++++++++ arch/riscv/include/asm/pgtable.h | 21 +++++++++++++++++---- arch/riscv/include/asm/sparsemem.h | 11 +++++++++++ arch/riscv/mm/init.c | 11 +++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 arch/riscv/include/asm/sparsemem.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index eb56c82d8aa1..76fc340ae38e 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -57,12 +57,32 @@ config ZONE_DMA32 bool default y if 64BIT +config VA_BITS + int + default 32 if 32BIT + default 39 if 64BIT + +config PA_BITS + int + default 34 if 32BIT + default 56 if 64BIT + config PAGE_OFFSET hex default 0xC0000000 if 32BIT && MAXPHYSMEM_2GB default 0xffffffff80000000 if 64BIT && MAXPHYSMEM_2GB default 0xffffffe000000000 if 64BIT && MAXPHYSMEM_128GB +config ARCH_FLATMEM_ENABLE + def_bool y + +config ARCH_SPARSEMEM_ENABLE + def_bool y + select SPARSEMEM_VMEMMAP_ENABLE + +config ARCH_SELECT_MEMORY_MODEL + def_bool ARCH_SPARSEMEM_ENABLE + config STACKTRACE_SUPPORT def_bool y @@ -97,6 +117,9 @@ config PGTABLE_LEVELS default 3 if 64BIT default 2 +config HAVE_ARCH_PFN_VALID + def_bool y + menu "Platform type" choice diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 1141364d990e..5a9fea00ba09 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -89,6 +89,23 @@ extern pgd_t swapper_pg_dir[]; #define __S110 PAGE_SHARED_EXEC #define __S111 PAGE_SHARED_EXEC +#define VMALLOC_SIZE (KERN_VIRT_SIZE >> 1) +#define VMALLOC_END (PAGE_OFFSET - 1) +#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE) + +/* + * Roughly size the vmemmap space to be large enough to fit enough + * struct pages to map half the virtual address space. Then + * position vmemmap directly below the VMALLOC region. + */ +#define VMEMMAP_SHIFT \ + (CONFIG_VA_BITS - PAGE_SHIFT - 1 + STRUCT_PAGE_MAX_SHIFT) +#define VMEMMAP_SIZE (1UL << VMEMMAP_SHIFT) +#define VMEMMAP_END (VMALLOC_START - 1) +#define VMEMMAP_START (VMALLOC_START - VMEMMAP_SIZE) + +#define vmemmap ((struct page *)VMEMMAP_START) + /* * ZERO_PAGE is a global shared page that is always zero, * used for zero-mapped memory areas, etc. @@ -412,10 +429,6 @@ static inline void pgtable_cache_init(void) /* No page table caches to initialize */ } -#define VMALLOC_SIZE (KERN_VIRT_SIZE >> 1) -#define VMALLOC_END (PAGE_OFFSET - 1) -#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE) - /* * Task size is 0x40000000000 for RV64 or 0xb800000 for RV32. * Note that PGDIR_SIZE must evenly divide TASK_SIZE. diff --git a/arch/riscv/include/asm/sparsemem.h b/arch/riscv/include/asm/sparsemem.h new file mode 100644 index 000000000000..b58ba2d9ed6e --- /dev/null +++ b/arch/riscv/include/asm/sparsemem.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ASM_SPARSEMEM_H +#define __ASM_SPARSEMEM_H + +#ifdef CONFIG_SPARSEMEM +#define MAX_PHYSMEM_BITS CONFIG_PA_BITS +#define SECTION_SIZE_BITS 27 +#endif /* CONFIG_SPARSEMEM */ + +#endif /* __ASM_SPARSEMEM_H */ diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b379a75ac6a6..b9d50031e78f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -141,6 +141,9 @@ void __init setup_bootmem(void) PFN_PHYS(end_pfn - start_pfn), &memblock.memory, 0); } + + memblocks_present(); + sparse_init(); } pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; @@ -224,3 +227,11 @@ asmlinkage void __init setup_vm(void) __pgprot(_PAGE_TABLE)); #endif } + +#ifdef CONFIG_SPARSEMEM +int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, + struct vmem_altmap *altmap) +{ + return vmemmap_populate_basepages(start, end, node); +} +#endif -- 2.20.1