Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1878496ybl; Thu, 15 Aug 2019 02:48:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxH3s91UKr3tEQsQWwRm7e9oGhm2nzb9c/mgTOnurbgtXLWOhmakyLYHmTU0GUQQmJe9ISH X-Received: by 2002:a63:184b:: with SMTP id 11mr2995150pgy.112.1565862523786; Thu, 15 Aug 2019 02:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565862523; cv=none; d=google.com; s=arc-20160816; b=pxJYtEDQZ52MIXJovAlrUNcdZA4cKaQgYLr7FMygv6As6+Ky6w9qACaW96d6l9oBh9 Ywr3UR4/GkITfGI73zYUAKwSr7Di/WH4VaKE4Q9VeKnGk6nVm80C1JVilmWkQbNrRTE8 XG2Qa2QkYsR5UhxEaf55lfnqcke2iKz6P5Hv9U0/UUJNIy8gf+QkNbVNKUuT16I5hMzR 3WKBEyZACzS57XnuTBqVN0m/mPg3D4MraIR/sifffqHqqKC7ihkWVnlMOSVPdpovOGpI hGitN39u+iHHz2o4sFHclwJaOfCJ42crEF0Tjy1emXyQLb8MTXB7J+NvMuSb4i3i1y32 QnJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EexUI7pBO+y+x9iztzk6muOC5V/JyQ3M/ih3wi+9iUo=; b=e5IJQDTVXWkWkzt/SVkQkr5y3riSV+3cji6Wksr5NjnraXZnF5x9v7j9/4ATqisJ/W e4EyVw/aZ8GAtAhVPqKo9HNIN6SXILPRygWnbfkRo8CPxexrDAnjr6aRuKc/xEcPpWjE XyN8r5fLQpZJGzWDYx2P+Fgvxma5ErlItl5X/RYMI94AfdEP+epothqTOT6ScRXfUjKN DLaRF8fNGH+TCWLghvIIP8J5mhaaoc+b0xflSVM7ywYfLQFH+v9cbfT9B+gsuDdUzPhy LRS65/pq5U+aZxRkmhAj01/DqDrWFYKRcJj8W5yQeUEhZI7BYywO1J/HSJHnE2QEBjJ/ xIhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="X/wbCO64"; 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 19si1723410pfu.109.2019.08.15.02.48.28; Thu, 15 Aug 2019 02:48:43 -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; dkim=pass header.i=@sifive.com header.s=google header.b="X/wbCO64"; 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 S1731400AbfHOJcH (ORCPT + 99 others); Thu, 15 Aug 2019 05:32:07 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55096 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbfHOJcH (ORCPT ); Thu, 15 Aug 2019 05:32:07 -0400 Received: by mail-wm1-f66.google.com with SMTP id p74so743965wme.4 for ; Thu, 15 Aug 2019 02:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EexUI7pBO+y+x9iztzk6muOC5V/JyQ3M/ih3wi+9iUo=; b=X/wbCO64nDBxAR7srA/xsH1W7BhyQJ7EWOaub7eQ7JF70Y5IGtkMUVmZB4XNSbUBrb aPk+Cm1w8Ce2Yvf9liGUPvmWCwn7KuJN8r6BQQ67OpUhjBuqW8dAz/ekw9OttDvPpKxg qi3z5/Txu+/6Y1vnz+2B5PKDIOYepvv9RXXJZFMme9sEvQtS141a/2orR3GY2yu31ESs eh+Qc/KNlpGwsh7dir4e8cA57eODbD/4BVa/OXHdOdqf59sOtiXXUptDVEc7cscDndds FG0Zmd5kMUfwBVjwJEu2zgqDtKlf3YcWqmzcJlEeZ9ECfTKNa+MEhRL+UaT/slwvjBig CXgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EexUI7pBO+y+x9iztzk6muOC5V/JyQ3M/ih3wi+9iUo=; b=YizC3ZTOHvtYjttRVvNsYy9FSGA9UgX05Uzk9B/lJh11TCYafnKCwqbkFvXo2tG7Hy IZOpYL/GRT3Yql3HXxbk60tnHqGj1FetWGQqzZzWweQo4+oFMz1bPD0Ds/P4Vny0n4yr sUbJjGJrwHsjmP5ZdM9LNG65vXk3EJk9jYHUWO8LYtoFFNYKnSDEjOcz9LNgI/jlzVS8 TITa9V9RZAG+evS8c51SNXyqcadnElE1XXsMvn3+UyoMNtDVH9e33lRrko8LliCgsb3z GM3HERjTPLtSYEKR4ICSCXhE47xienkdpCsoPG9fFBT6intrJtQlJE7ytC713RpAfsiZ 28fQ== X-Gm-Message-State: APjAAAWqh9dN7hFIhGQ1oODOj1GU2nUtAwdF+OZiqSe0iUaRW5hUPYa1 3A9J3IVLOdcUzfiQHellP0tOpBjv15e6sUoyEJ3gEw== X-Received: by 2002:a1c:2dcf:: with SMTP id t198mr1707704wmt.147.1565861524605; Thu, 15 Aug 2019 02:32:04 -0700 (PDT) MIME-Version: 1.0 References: <20190109203911.7887-1-logang@deltatee.com> <20190109203911.7887-3-logang@deltatee.com> <0926a261-520e-4c40-f926-ddd40bb8ce44@deltatee.com> <96156909-1453-d487-ff66-a041d67c74d6@deltatee.com> <5506c875-9387-acc9-a7fe-5b7c10036c40@deltatee.com> <8b7b6285-dd85-5895-8653-be1f6f08cca8@deltatee.com> In-Reply-To: <8b7b6285-dd85-5895-8653-be1f6f08cca8@deltatee.com> From: Greentime Hu Date: Thu, 15 Aug 2019 17:31:52 +0800 Message-ID: Subject: Re: [PATCH v4 2/2] RISC-V: Implement sparsemem To: Logan Gunthorpe Cc: Greentime Hu , Paul Walmsley , Rob Herring , Albert Ou , Andrew Waterman , Palmer Dabbelt , Linux Kernel Mailing List , Stephen Bates , Olof Johansson , linux-riscv@lists.infradead.org, Michael Clark , Christoph Hellwig , linux-mm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Logan, On Thu, Aug 15, 2019 at 6:21 AM Logan Gunthorpe wrote: > > Hey, > > On 2019-08-14 7:35 a.m., Greentime Hu wrote: > > How about this fix? Not sure if it is good for everyone. > > I applied your fix to the patch and it seems ok. But it doesn't seem to > work on a recent version of the kernel. Have you got it working on v5.3? > It seems the following patch breaks things: > > 671f9a3e2e24 ("RISC-V: Setup initial page tables in two stages") > > I don't really have time right now to debug this any further. > I just tried v5.3-rc4 and it failed. I try to debug this case. I found it failed might be because of an unmapped virtual address is used in memblocks_present() -> memblock_alloc (). In this commit 671f9a3e2e24 ("RISC-V: Setup initial page tables in two stages"), it finishes all the VA/PA mapping after setup_vm_final() is called. So we have to call memblocks_present() and sparse_init() right after setup_vm_final(). Here is my patch and I tested with memory-with-hole. It can boot normally in Unleashed board after applying this patch. diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 27d1d847fb2d..35aacb0c93e5 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -138,8 +138,6 @@ void __init setup_bootmem(void) PFN_PHYS(end_pfn - start_pfn), &memblock.memory, 0); } - memblocks_present(); - sparse_init(); } unsigned long va_pa_offset; @@ -452,6 +450,8 @@ static void __init setup_vm_final(void) void __init paging_init(void) { setup_vm_final(); + memblocks_present(); + sparse_init(); setup_zero_page(); zone_sizes_init(); } Test case: memory@80000000 { device_type = "memory"; reg = <0x0 0x80000000 0x0 0x80000000>; }; memory@180000000 { device_type = "memory"; reg = <0x1 0x80000000 0x0 0x40000000>; }; # cat /proc/meminfo MemTotal: 3003496 kB MemFree: 2986584 kB MemAvailable: 2970176 kB Buffers: 0 kB Cached: 3540 kB SwapCached: 0 kB Active: 3920 kB Inactive: 68 kB Active(anon): 3920 kB Inactive(anon): 68 kB Active(file): 0 kB Inactive(file): 0 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 528 kB Mapped: 1984 kB Shmem: 3540 kB KReclaimable: 688 kB Slab: 5700 kB SReclaimable: 688 kB SUnreclaim: 5012 kB KernelStack: 424 kB PageTables: 80 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 1501748 kB Committed_AS: 3200 kB VmallocTotal: 67108863 kB VmallocUsed: 12 kB VmallocChunk: 0 kB Percpu: 272 kB # uname -a Linux buildroot 5.3.0-rc4-00001-g44404421c481-dirty #10 SMP Thu Aug 15 16:28:24 DST 2019 riscv64 GNU/Lin[ 2352.443621] random: fast init done ux # zcat /proc/config.gz |grep SPARSE CONFIG_SPARSE_IRQ=y CONFIG_ARCH_SPARSEMEM_ENABLE=y CONFIG_SPARSEMEM_MANUAL=y CONFIG_SPARSEMEM=y CONFIG_SPARSEMEM_EXTREME=y CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y CONFIG_SPARSEMEM_VMEMMAP=y # CONFIG_INPUT_SPARSEKMAP is not set