Re: [PATCH v4 2/2] RISC-V: Implement sparsemem
From: Logan Gunthorpe
Date: Fri Aug 09 2019 - 11:47:02 EST
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/page.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) >= 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.
Logan