Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp695405ybl; Fri, 9 Aug 2019 12:16:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeQ9y1+udTGQuhcE8KvAzET7+7Yrukw4wGBGBX1eOU0D9NFzhCvtnEYdVm+DUE0nzHZGLX X-Received: by 2002:a17:902:b08a:: with SMTP id p10mr20749486plr.83.1565378188928; Fri, 09 Aug 2019 12:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565378188; cv=none; d=google.com; s=arc-20160816; b=RGEntRpE418AZnX0Av8PBwERhunxaQso+GN1cSpXyPV2kVpj90qkf9uKGkye6L8B/g IKaSMN492DWNi5VIlWotXhnYi5Sq6vfNLBA2/hiEmANQLJGKgcnD78d0ZurZA4YWiiW/ HA+IYKiRglYbf/58xVbIeeynlJAGuAjCH/GG8WPHp0BVrLN2UYzuQZ7idHvQ9ENhJ78N NFcHRVtmLaSih/+xbSnsazGhc7/lWWdhIyZD8hs2g75uQ931MsYvYTAamrLw/yHBC+nr XlRKLO6qal5cGN0DEzSdq+LEuPrCRV+4UghOQKPXc6EvIFYTAAIDULWUXtbH9zYSsDr1 PNsQ== 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=FclrxiNVeDQRBUVrlhHeOXQhVrnasVK2qCxhjrZ+ESw=; b=IEELsZXgyCu26DYVVR4IMfcSvoHKuE6dFMPHWoGTwc9mI0VOGndkHJjrgqBptqJHeA fDKgSrGl2UbQlhXX61ioAcFvA0L756Op+Mu0Y5FdIsKAqlGCMGWsIKXZgGcEBbBaivZV 8Pg4Pbrbd+mqTt/inxIdnc/TtSv8evEafe4sYL0eo/ogXpoY/L+/vJ9YGmIn2BW05RBu AL9Yvm6vQU+onnkd1iOp7fzfPvE2ZsisRgWseOU/KJcr/d4BAIP6czpJ0Fxsetu3ud0z 3hRvYQ7PoyYdZAIRNkW60Tv981qMNw6vNlqA1cM7WVAKciHepunEncnYSueannXJvN1G fFAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p98Vpv2+; 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 bg2si49325206plb.263.2019.08.09.12.16.11; Fri, 09 Aug 2019 12:16:28 -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=p98Vpv2+; 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 S2436902AbfHIRC1 (ORCPT + 99 others); Fri, 9 Aug 2019 13:02:27 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:39465 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407436AbfHIRC1 (ORCPT ); Fri, 9 Aug 2019 13:02:27 -0400 Received: by mail-qt1-f194.google.com with SMTP id l9so96399213qtu.6 for ; Fri, 09 Aug 2019 10:02:26 -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=FclrxiNVeDQRBUVrlhHeOXQhVrnasVK2qCxhjrZ+ESw=; b=p98Vpv2+yYXOmOjE4tNlUje0o/LvDN/IAP+Fw1/Itzh0AJJ/uEtrDzY8ClOf7M0TnO mN1LOwLQUEzGyxEbMGGdyJH1s/VCPwzmUZJHTwEG0MVM5qhAx11Sg4ja/z45ABcp0k1W aY8RKwKC44kvIKcHqscV8bEWZrvvHnu/s6pcCE4Jpz7LSWYF1xlNVt1UmxKYtSS7ZBEH 2Dqz8S6e0VM9dFdAnDPj+PdrYisTl43RWG9JC83jwpUaEQwvqrnoQN2IO+39b8X0h4Q+ 76YB2aKWznpt4hd3SQ+cMH0iWVjxSEkSCG9iXTs6wcnPIfgd/Q328wN7GPx/P66NzMiZ tGLA== 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=FclrxiNVeDQRBUVrlhHeOXQhVrnasVK2qCxhjrZ+ESw=; b=iFOIRZpoE0D44FlAPRUJz30uDGFStIOsGEdVaAiBLGg0AnLcXTFzZwyjKh8Lj7+OeP fDjabjSu96pypwsEoY1DWXuGvuTjV+380EtWFUvrPKArqBB+kEo9aw/4hIAGzrI1sGOh pi52FoKU3K1RTrwokrV4DxNwEXz4FpRAAc+xAqaUvNLq3c7EPc25En/FWyY1LBoNnVHY 6Em4hY8WTT/yK0TRbWZik/neATIMF2GNmJG0swIakj19Jc+p+DKwS41spW7QITDOqbEE 4z6G7JWV6mzZY2FtE+/P2InYjmT1cMw7heytUkKCgqgoz+weMLvucEEATA9NUAf3U50m z7BA== X-Gm-Message-State: APjAAAXNA7F42Srj/5VhhG6JjHF2LS2PB66wP3IB56hQINy9O0Jj49Xb FtFZ2XjAJxm6Ub2+HH94eQBneOz89aiQ+i5V2/I= X-Received: by 2002:ad4:4423:: with SMTP id e3mr19119365qvt.145.1565370146012; Fri, 09 Aug 2019 10:02:26 -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: <0926a261-520e-4c40-f926-ddd40bb8ce44@deltatee.com> From: Greentime Hu Date: Sat, 10 Aug 2019 01:01:50 +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=889=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/pag= e.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. In my test case it will be ((6GB>>PAGE_SHIFT)-(2GB>>PAGE_SHIFT)=3D(4GB>>PAGE_SHIFT) < (3GB>>PAGE_SHIFT) to return false. memory@80000000 { device_type =3D "memory"; reg =3D <0x0 0x80000000 0x0 0x80000000>; }; memory@180000000 { device_type =3D "memory"; reg =3D <0x1 0x80000000 0x0 0x40000000>; }; To cause the check here failed to initialize page struct. for (pfn =3D start_pfn; pfn < end_pfn; pfn++) { /* * There can be holes in boot-time mem_map[]s handed to this * function. They do not exist on hotplugged memory. */ if (context =3D=3D MEMMAP_EARLY) { if (!early_pfn_valid(pfn)) continue; if (!early_pfn_in_nid(pfn, nid)) continue; if (overlap_memmap_init(zone, &pfn)) continue; if (defer_init(nid, pfn, end_pfn)) break; } page =3D pfn_to_page(pfn); __init_single_page(page, pfn, zone, nid); ---------------------------------------------------------------------------= --- 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/page.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)