Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3320917ybl; Sun, 11 Aug 2019 21:05:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGpCqT7Hb3B19/EQzuz5cMprp24OzLHSeYqI9K7qAZnNlBvYhHcdBZzEbUyz4FLj7E9SJi X-Received: by 2002:a62:2784:: with SMTP id n126mr34311611pfn.61.1565582710806; Sun, 11 Aug 2019 21:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565582710; cv=none; d=google.com; s=arc-20160816; b=aAONQeD0YSJ8wA/3+A3BAzEoKzj39PeJy76qFeMAexKzTg39JJZyxBzDV0B+AU5Xji Fgka0KdypWTETB5FOuZv563lr+JYwnmIeJ8WfwSsD50Jqh3GZWASrrqUC2wW9w5m/BsD hUBDb2zrpZ30W48xmyfEp5nlk8r7KUI8dBRFWeAXbnIrqiLd5Xpn1ym66UD6luW6kiXu 92wAetGTgIu5bdX1XP9STLZV//2+95f1U0FKlqRHxOhHdAdKrRiFnG0hMIbsCM4NJw/v mVZSIIFTRHdw9lyJM4rJTmOLS0EPanBqHhn3qnY19yMNQOQzAkl+T9K9Td8S82hDWw4S PCyg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=/4YnpQhIEZcscEz7uCIGbe6A/Kj16Z9K3vN8c7z419g=; b=gY56BMTlgC4aKvVkfzu2PwSgUu2NJkhWsnJDrOODXWmiIWRXT+Lik+Fd3GFjXqLpaG SdOG32xiz/GAtl2ZWfTeANBM+yXvBPfS/yQMWmmUpZmcImjPoSEEJ74nJwTwgmetRWVf 9KpbrK+rnWbvd1m9acDaAdFbaQXbShS7ALoNqe14wXdHbCiYW4zcdB8ZkNCJ9ldbhrqd q/JmADtWpUHMh8aLcIht7sHKEHpk5AHwNjp7ovrrpFo7R+OPZg9jteHfEOEH8iPOCP3J Ut/nvozMeAVDW0jK6HuBDasXHm+cihzvWJeWEmiyX58lR6ti8XODJewHy2GclHhEMXOI lfSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tBT5gyj2; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 19si28299210pgh.262.2019.08.11.21.04.54; Sun, 11 Aug 2019 21:05:10 -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=@gmail.com header.s=20161025 header.b=tBT5gyj2; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726304AbfHLECY (ORCPT + 99 others); Mon, 12 Aug 2019 00:02:24 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:39981 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725648AbfHLECX (ORCPT ); Mon, 12 Aug 2019 00:02:23 -0400 Received: by mail-qt1-f193.google.com with SMTP id e8so1113792qtp.7 for ; Sun, 11 Aug 2019 21:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/4YnpQhIEZcscEz7uCIGbe6A/Kj16Z9K3vN8c7z419g=; b=tBT5gyj2w+9S3FzzabYm9eqPL/FRGIHVoK3/HO/QuWUaZr2kcDDZ4PTHdPfSFK2BGd OPVNfb0CdADvleEhQK7qYnWZhBlS6N01jYodJMPEaY9s4O85dU66TtdjkvGXPnMnmP8e KdOq7qwnG51CB8dBZaamlmltv11JADM8xxcNDLGboLTy+9X8mxXFdmoohJIWm1W4Wha+ KwyOwJMvZsX1vhUdyq3eomCKblJuZ/jIK+crYjLS2IHI73fMiAHben/v69hZ8nm19LEs kQgP9z68SWRdxqsLzWCFc3PV6gwWakf4rODe3wI+oXMjPbZSjqvo3AABFSgvbaZGlxu9 Xx/w== 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:content-transfer-encoding; bh=/4YnpQhIEZcscEz7uCIGbe6A/Kj16Z9K3vN8c7z419g=; b=pCTOqeeHKvumZKF+NiESGdb1QG2jek41NNG7hJA4y/BjNtZrlBG95vy7uRuTMZIWER pDtVB+KTnmtpzCLyjrIbedBECjCozHM9v/WrF2j1IF9brhcE+s4KOmzcsrSc+VBNFMyc 7L9jhroPGh2AChdSXKZe1Iwm8ALc/3invcSVX3LqbnLxqJEGgCiODa6pjtfQrK2keqj7 4LSlhjko4zUNE/Z7TGfQXv4uzvu+E+lh7Y3djx7ho/MNZFErmkbtm1Tehg5xlTH7TJ7f cAIWmFwL9//EHMgfk+e5TZ0FX3wTLYDGvKoBODNzcYZxyPOe9tDG0QVtpor9OzRt+2mr bajg== X-Gm-Message-State: APjAAAVsh3U7Af0/Faywj8MF97PFZreyIMPAwkRHsC8pPZ93ZS9XmpIG QQVuU5tWyGyW30dpwVZkc8Wiw/Poz1AHZrpbLfI= X-Received: by 2002:ac8:2d2c:: with SMTP id n41mr28162850qta.28.1565582542296; Sun, 11 Aug 2019 21:02:22 -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> In-Reply-To: From: Greentime Hu Date: Mon, 12 Aug 2019 12:01:49 +0800 Message-ID: Subject: Re: [PATCH v4 2/2] RISC-V: Implement sparsemem To: Logan Gunthorpe Cc: greentime.hu@sifive.com, paul.walmsley@sifive.com, Rob Herring , Albert Ou , Andrew Waterman , Palmer Dabbelt , Linux Kernel Mailing List , Stephen Bates , Zong Li , Olof Johansson , linux-riscv@lists.infradead.org, Michael Clark , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Logan, Logan Gunthorpe =E6=96=BC 2019=E5=B9=B48=E6=9C=8810= =E6=97=A5 =E9=80=B1=E5=85=AD =E4=B8=8A=E5=8D=883:03=E5=AF=AB=E9=81=93=EF=BC= =9A > > > > On 2019-08-09 11:01 a.m., Greentime Hu wrote: > > Hi Logan, > > > > Logan Gunthorpe =E6=96=BC 2019=E5=B9=B48=E6=9C=88= 9=E6=97=A5 =E9=80=B1=E4=BA=94 =E4=B8=8B=E5=8D=8811:47=E5=AF=AB=E9=81=93=EF= =BC=9A > >> > >> > >> > >> On 2019-08-08 10:23 p.m., Greentime Hu wrote: > >>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > >>> index 3f12b069af1d..208b3e14ccd8 100644 > >>> --- a/arch/riscv/Kconfig > >>> +++ b/arch/riscv/Kconfig > >>> @@ -116,7 +116,8 @@ config PGTABLE_LEVELS > >>> default 2 > >>> > >>> config HAVE_ARCH_PFN_VALID > >>> - def_bool y > >>> + bool > >>> + default !SPARSEMEM_VMEMMAP > >>> > >>> menu "Platform type" > >>> > >>> diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/p= age.h > >>> index 8ddb6c7fedac..6991f7a5a4a7 100644 > >>> --- a/arch/riscv/include/asm/page.h > >>> +++ b/arch/riscv/include/asm/page.h > >>> @@ -93,16 +93,20 @@ extern unsigned long min_low_pfn; > >>> #define virt_to_pfn(vaddr) (phys_to_pfn(__pa(vaddr))) > >>> #define pfn_to_virt(pfn) (__va(pfn_to_phys(pfn))) > >>> > >>> +#if !defined(CONFIG_SPARSEMEM_VMEMMAP) > >>> +#define pfn_valid(pfn) \ > >>> + (((pfn) >=3D pfn_base) && (((pfn)-pfn_base) < max_mapnr)) > >>> #define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) > >>> #define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) > >>> +#else > >>> +#define virt_to_page(vaddr) ((struct page *)((((u64)vaddr - > >>> va_pa_offset) / PAGE_SIZE) * sizeof(struct page) + VMEMMAP_START)) > >>> +#define page_to_virt(pg) ((void *)(((((u64)pg - VMEMMAP_START)= / > >>> sizeof(struct page)) * PAGE_SIZE) + va_pa_offset)) > >>> +#endif > >> > >> This doesn't make sense to me at all. It should always use pfn_to_page= () > >> for virt_to_page() and the generic pfn_to_page()/page_to_pfn() > >> implementations essentially already do what you are doing in a cleaner > >> way. So I'd be really surprised if this does anything at all. > >> > > > > Thank you for point me out that. I just checked the generic > > implementation and I should use that one. > > Sorry I didn't check the generic one and just implement it again. > > I think the only patch we need is the first part to use generic > > pfn_valid(). I just tested it and yes it can boot successfully in dts > > with hole. > > > > It will fail in this check ((pfn)-pfn_base) < max_mapnr. > > Sounds to me like max_mapnr is not set correctly. See the code in > setup_bootmem(). Seems like 'mem_size' should be set to the largest > memory block, not just the one that contains the kernel... > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index 3f12b069af1d..208b3e14ccd8 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -116,7 +116,8 @@ config PGTABLE_LEVELS > > default 2 > > > > config HAVE_ARCH_PFN_VALID > > - def_bool y > > + bool > > + default !SPARSEMEM_VMEMMAP > > > > menu "Platform type" > > > > diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/pag= e.h > > index 8ddb6c7fedac..80d28fa1e2eb 100644 > > --- a/arch/riscv/include/asm/page.h > > +++ b/arch/riscv/include/asm/page.h > > @@ -100,8 +100,10 @@ extern unsigned long min_low_pfn; > > #define page_to_bus(page) (page_to_phys(page)) > > #define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) > > > > +#if !defined(CONFIG_SPARSEMEM_VMEMMAP) > > #define pfn_valid(pfn) \ > > (((pfn) >=3D pfn_base) && (((pfn)-pfn_base) < max_mapnr)) > > +#endif > > > > #define ARCH_PFN_OFFSET (pfn_base) > > > This patch still makes no sense. I'm not sure why we have an arch > specific pfn_valid() because it's very similar to the generic one. But > my guess is there's a reason for it and it's not doing what it is > supposed when you remove it for the sparsemem case. It will use another pfn_valid() implementation in include/linux/mmzone.h if CONFIG_SPARSEMEM and !CONFIG_HAVE_ARCH_PFN_VALID It will be this one. static inline int pfn_valid(unsigned long pfn) { if (pfn_to_section_nr(pfn) >=3D NR_MEM_SECTIONS) return 0; return valid_section(__nr_to_section(pfn_to_section_nr(pfn))); } This generic pfn_valid() API can check the pfn is valid or not even if there a hole in the memory. For example: A hole is between 0x100000000 to 0x180000000 (4GB-6GB) in my dts test case. [ 0.000000] In setup_bootmem, pfn_valid(0x180000)=3D1 [ 0.000000] In setup_bootmem, pfn_valid(0x80000)=3D1 [ 0.000000] In setup_bootmem, pfn_valid(0x80200)=3D1 [ 0.000000] In setup_bootmem, pfn_valid(0x80300)=3D1 [ 0.000000] In setup_bootmem, pfn_valid(0x160000)=3D0 [ 0.000000] In setup_bootmem, pfn_valid(0x17ffff)=3D0 [ 0.000000] In setup_bootmem, pfn_valid(0x120000)=3D0 [ 0.000000] In setup_bootmem, pfn_valid(0x100000)=3D0 [ 0.000000] In setup_bootmem, pfn_valid(0xfffff)=3D1 This generic pfn_valid() could tell the pfn is valid or not. I think this one is only available for flatmem. #define pfn_valid(pfn) (((pfn) >=3D pfn_base) && (((pfn)-pfn_base) < max_m= apnr))