linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Move all address space definition macros to one place
@ 2020-02-24 19:34 Atish Patra
  2020-02-28  4:08 ` Anup Patel
  2020-03-06  0:20 ` Palmer Dabbelt
  0 siblings, 2 replies; 7+ messages in thread
From: Atish Patra @ 2020-02-24 19:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: Albert Ou, Nick Hu, David Abdurachmanov, Björn Töpel,
	Anup Patel, stable, Mike Rapoport, Atish Patra, Thomas Gleixner,
	Paul Walmsley, Palmer Dabbelt, Greentime Hu, Andrew Morton,
	linux-riscv

If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get the
following compilation error.

---------------------------------------------------------------
./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’ undeclared
(first use in this function); did you mean ‘mem_map’?
 #define __pfn_to_page(pfn) (vmemmap + (pfn))
                             ^~~~~~~
./include/asm-generic/memory_model.h:82:21: note: in expansion of
macro ‘__pfn_to_page’

 #define pfn_to_page __pfn_to_page
                     ^~~~~~~~~~~~~
./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of macro
‘pfn_to_page’
  return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
---------------------------------------------------------------

Fix the compliation errors by moving all the address space definition
macros before including pgtable-64.h.

Cc: stable@vger.kernel.org
Fixes: 8ad8b72721d0 (riscv: Add KASAN support)

Signed-off-by: Atish Patra <atish.patra@wdc.com>
---
 arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++---------------
 1 file changed, 41 insertions(+), 37 deletions(-)

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 453afb0a570a..4f6ee48a42e8 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -19,6 +19,47 @@
 #include <asm/tlbflush.h>
 #include <linux/mm_types.h>
 
+#ifdef CONFIG_MMU
+
+#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
+#define VMALLOC_END      (PAGE_OFFSET - 1)
+#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
+
+#define BPF_JIT_REGION_SIZE	(SZ_128M)
+#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
+#define BPF_JIT_REGION_END	(VMALLOC_END)
+
+/*
+ * 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	BIT(VMEMMAP_SHIFT)
+#define VMEMMAP_END	(VMALLOC_START - 1)
+#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)
+
+/*
+ * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
+ * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
+ */
+#define vmemmap		((struct page *)VMEMMAP_START)
+
+#define PCI_IO_SIZE      SZ_16M
+#define PCI_IO_END       VMEMMAP_START
+#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
+
+#define FIXADDR_TOP      PCI_IO_START
+#ifdef CONFIG_64BIT
+#define FIXADDR_SIZE     PMD_SIZE
+#else
+#define FIXADDR_SIZE     PGDIR_SIZE
+#endif
+#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
+
+#endif
+
 #ifdef CONFIG_64BIT
 #include <asm/pgtable-64.h>
 #else
@@ -90,31 +131,6 @@ 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)
-
-#define BPF_JIT_REGION_SIZE	(SZ_128M)
-#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
-#define BPF_JIT_REGION_END	(VMALLOC_END)
-
-/*
- * 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	BIT(VMEMMAP_SHIFT)
-#define VMEMMAP_END	(VMALLOC_START - 1)
-#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)
-
-/*
- * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
- * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
- */
-#define vmemmap		((struct page *)VMEMMAP_START)
-
 static inline int pmd_present(pmd_t pmd)
 {
 	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
@@ -452,18 +468,6 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
 #define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)	((pte_t) { (x).val })
 
-#define PCI_IO_SIZE      SZ_16M
-#define PCI_IO_END       VMEMMAP_START
-#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
-
-#define FIXADDR_TOP      PCI_IO_START
-#ifdef CONFIG_64BIT
-#define FIXADDR_SIZE     PMD_SIZE
-#else
-#define FIXADDR_SIZE     PGDIR_SIZE
-#endif
-#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
-
 /*
  * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
  * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
-- 
2.25.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] RISC-V: Move all address space definition macros to one place
  2020-02-24 19:34 [PATCH] RISC-V: Move all address space definition macros to one place Atish Patra
@ 2020-02-28  4:08 ` Anup Patel
  2020-02-28 18:23   ` Atish Patra
  2020-03-06  0:20 ` Palmer Dabbelt
  1 sibling, 1 reply; 7+ messages in thread
From: Anup Patel @ 2020-02-28  4:08 UTC (permalink / raw)
  To: Atish Patra
  Cc: Albert Ou, Nick Hu, David Abdurachmanov, Björn Töpel,
	Anup Patel, linux-kernel@vger.kernel.org List, stable,
	Mike Rapoport, Thomas Gleixner, Paul Walmsley, Palmer Dabbelt,
	Greentime Hu, Andrew Morton, linux-riscv

On Tue, Feb 25, 2020 at 1:04 AM Atish Patra <atish.patra@wdc.com> wrote:
>
> If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get the
> following compilation error.
>
> ---------------------------------------------------------------
> ./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
> ./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’ undeclared
> (first use in this function); did you mean ‘mem_map’?
>  #define __pfn_to_page(pfn) (vmemmap + (pfn))
>                              ^~~~~~~
> ./include/asm-generic/memory_model.h:82:21: note: in expansion of
> macro ‘__pfn_to_page’
>
>  #define pfn_to_page __pfn_to_page
>                      ^~~~~~~~~~~~~
> ./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of macro
> ‘pfn_to_page’
>   return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
> ---------------------------------------------------------------
>
> Fix the compliation errors by moving all the address space definition
> macros before including pgtable-64.h.
>
> Cc: stable@vger.kernel.org
> Fixes: 8ad8b72721d0 (riscv: Add KASAN support)
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> ---
>  arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++---------------
>  1 file changed, 41 insertions(+), 37 deletions(-)
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index 453afb0a570a..4f6ee48a42e8 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -19,6 +19,47 @@
>  #include <asm/tlbflush.h>
>  #include <linux/mm_types.h>
>
> +#ifdef CONFIG_MMU
> +
> +#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
> +#define VMALLOC_END      (PAGE_OFFSET - 1)
> +#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
> +
> +#define BPF_JIT_REGION_SIZE    (SZ_128M)
> +#define BPF_JIT_REGION_START   (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> +#define BPF_JIT_REGION_END     (VMALLOC_END)
> +
> +/*
> + * 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   BIT(VMEMMAP_SHIFT)
> +#define VMEMMAP_END    (VMALLOC_START - 1)
> +#define VMEMMAP_START  (VMALLOC_START - VMEMMAP_SIZE)
> +
> +/*
> + * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> + * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> + */
> +#define vmemmap                ((struct page *)VMEMMAP_START)
> +
> +#define PCI_IO_SIZE      SZ_16M
> +#define PCI_IO_END       VMEMMAP_START
> +#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> +
> +#define FIXADDR_TOP      PCI_IO_START
> +#ifdef CONFIG_64BIT
> +#define FIXADDR_SIZE     PMD_SIZE
> +#else
> +#define FIXADDR_SIZE     PGDIR_SIZE
> +#endif
> +#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> +
> +#endif
> +
>  #ifdef CONFIG_64BIT
>  #include <asm/pgtable-64.h>
>  #else
> @@ -90,31 +131,6 @@ 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)
> -
> -#define BPF_JIT_REGION_SIZE    (SZ_128M)
> -#define BPF_JIT_REGION_START   (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> -#define BPF_JIT_REGION_END     (VMALLOC_END)
> -
> -/*
> - * 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   BIT(VMEMMAP_SHIFT)
> -#define VMEMMAP_END    (VMALLOC_START - 1)
> -#define VMEMMAP_START  (VMALLOC_START - VMEMMAP_SIZE)
> -
> -/*
> - * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> - * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> - */
> -#define vmemmap                ((struct page *)VMEMMAP_START)
> -
>  static inline int pmd_present(pmd_t pmd)
>  {
>         return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
> @@ -452,18 +468,6 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
>  #define __pte_to_swp_entry(pte)        ((swp_entry_t) { pte_val(pte) })
>  #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
>
> -#define PCI_IO_SIZE      SZ_16M
> -#define PCI_IO_END       VMEMMAP_START
> -#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> -
> -#define FIXADDR_TOP      PCI_IO_START
> -#ifdef CONFIG_64BIT
> -#define FIXADDR_SIZE     PMD_SIZE
> -#else
> -#define FIXADDR_SIZE     PGDIR_SIZE
> -#endif
> -#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> -
>  /*
>   * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
>   * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
> --
> 2.25.0
>

Looks good to me. At least now all virtual memory layout related
defines are in one place.

Reviewed-by: Anup Patel <anup@brainfault.org>

Regards,
Anup


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RISC-V: Move all address space definition macros to one place
  2020-02-28  4:08 ` Anup Patel
@ 2020-02-28 18:23   ` Atish Patra
  0 siblings, 0 replies; 7+ messages in thread
From: Atish Patra @ 2020-02-28 18:23 UTC (permalink / raw)
  To: anup, palmerdabbelt
  Cc: aou, nickhu, david.abdurachmanov, bjorn.topel, Anup Patel,
	linux-kernel, stable, rppt, tglx, paul.walmsley, greentime.hu,
	linux-riscv, akpm

On Fri, 2020-02-28 at 09:38 +0530, Anup Patel wrote:
> On Tue, Feb 25, 2020 at 1:04 AM Atish Patra <atish.patra@wdc.com>
> wrote:
> > If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get
> > the
> > following compilation error.
> > 
> > ---------------------------------------------------------------
> > ./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
> > ./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’
> > undeclared
> > (first use in this function); did you mean ‘mem_map’?
> >  #define __pfn_to_page(pfn) (vmemmap + (pfn))
> >                              ^~~~~~~
> > ./include/asm-generic/memory_model.h:82:21: note: in expansion of
> > macro ‘__pfn_to_page’
> > 
> >  #define pfn_to_page __pfn_to_page
> >                      ^~~~~~~~~~~~~
> > ./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of
> > macro
> > ‘pfn_to_page’
> >   return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
> > ---------------------------------------------------------------
> > 
> > Fix the compliation errors by moving all the address space
> > definition
> > macros before including pgtable-64.h.
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: 8ad8b72721d0 (riscv: Add KASAN support)
> > 
> > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > ---
> >  arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++-----------
> > ----
> >  1 file changed, 41 insertions(+), 37 deletions(-)
> > 
> > diff --git a/arch/riscv/include/asm/pgtable.h
> > b/arch/riscv/include/asm/pgtable.h
> > index 453afb0a570a..4f6ee48a42e8 100644
> > --- a/arch/riscv/include/asm/pgtable.h
> > +++ b/arch/riscv/include/asm/pgtable.h
> > @@ -19,6 +19,47 @@
> >  #include <asm/tlbflush.h>
> >  #include <linux/mm_types.h>
> > 
> > +#ifdef CONFIG_MMU
> > +
> > +#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
> > +#define VMALLOC_END      (PAGE_OFFSET - 1)
> > +#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
> > +
> > +#define BPF_JIT_REGION_SIZE    (SZ_128M)
> > +#define BPF_JIT_REGION_START   (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > +#define BPF_JIT_REGION_END     (VMALLOC_END)
> > +
> > +/*
> > + * 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   BIT(VMEMMAP_SHIFT)
> > +#define VMEMMAP_END    (VMALLOC_START - 1)
> > +#define VMEMMAP_START  (VMALLOC_START - VMEMMAP_SIZE)
> > +
> > +/*
> > + * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if
> > kernel
> > + * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > + */
> > +#define vmemmap                ((struct page *)VMEMMAP_START)
> > +
> > +#define PCI_IO_SIZE      SZ_16M
> > +#define PCI_IO_END       VMEMMAP_START
> > +#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > +
> > +#define FIXADDR_TOP      PCI_IO_START
> > +#ifdef CONFIG_64BIT
> > +#define FIXADDR_SIZE     PMD_SIZE
> > +#else
> > +#define FIXADDR_SIZE     PGDIR_SIZE
> > +#endif
> > +#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > +
> > +#endif
> > +
> >  #ifdef CONFIG_64BIT
> >  #include <asm/pgtable-64.h>
> >  #else
> > @@ -90,31 +131,6 @@ 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)
> > -
> > -#define BPF_JIT_REGION_SIZE    (SZ_128M)
> > -#define BPF_JIT_REGION_START   (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > -#define BPF_JIT_REGION_END     (VMALLOC_END)
> > -
> > -/*
> > - * 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   BIT(VMEMMAP_SHIFT)
> > -#define VMEMMAP_END    (VMALLOC_START - 1)
> > -#define VMEMMAP_START  (VMALLOC_START - VMEMMAP_SIZE)
> > -
> > -/*
> > - * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if
> > kernel
> > - * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > - */
> > -#define vmemmap                ((struct page *)VMEMMAP_START)
> > -
> >  static inline int pmd_present(pmd_t pmd)
> >  {
> >         return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
> > @@ -452,18 +468,6 @@ static inline int
> > ptep_clear_flush_young(struct vm_area_struct *vma,
> >  #define __pte_to_swp_entry(pte)        ((swp_entry_t) {
> > pte_val(pte) })
> >  #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
> > 
> > -#define PCI_IO_SIZE      SZ_16M
> > -#define PCI_IO_END       VMEMMAP_START
> > -#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > -
> > -#define FIXADDR_TOP      PCI_IO_START
> > -#ifdef CONFIG_64BIT
> > -#define FIXADDR_SIZE     PMD_SIZE
> > -#else
> > -#define FIXADDR_SIZE     PGDIR_SIZE
> > -#endif
> > -#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > -
> >  /*
> >   * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
> >   * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
> > --
> > 2.25.0
> > 
> 
> Looks good to me. At least now all virtual memory layout related
> defines are in one place.
> 
> Reviewed-by: Anup Patel <anup@brainfault.org>
> 
> Regards,
> Anup
> 

Hi Palmer,
I think this patch is a RC candidate. Can this be included in next PR ?

-- 
Regards,
Atish

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RISC-V: Move all address space definition macros to one place
  2020-02-24 19:34 [PATCH] RISC-V: Move all address space definition macros to one place Atish Patra
  2020-02-28  4:08 ` Anup Patel
@ 2020-03-06  0:20 ` Palmer Dabbelt
  2020-03-21 20:29   ` David Abdurachmanov
  1 sibling, 1 reply; 7+ messages in thread
From: Palmer Dabbelt @ 2020-03-06  0:20 UTC (permalink / raw)
  To: Atish Patra
  Cc: aou, nickhu, david.abdurachmanov, Bjorn Topel, Anup Patel,
	linux-kernel, stable, rppt, Atish Patra, linux-riscv,
	Paul Walmsley, greentime.hu, tglx, akpm

On Mon, 24 Feb 2020 11:34:36 PST (-0800), Atish Patra wrote:
> If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get the
> following compilation error.
>
> ---------------------------------------------------------------
> ./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
> ./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’ undeclared
> (first use in this function); did you mean ‘mem_map’?
>  #define __pfn_to_page(pfn) (vmemmap + (pfn))
>                              ^~~~~~~
> ./include/asm-generic/memory_model.h:82:21: note: in expansion of
> macro ‘__pfn_to_page’
>
>  #define pfn_to_page __pfn_to_page
>                      ^~~~~~~~~~~~~
> ./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of macro
> ‘pfn_to_page’
>   return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
> ---------------------------------------------------------------
>
> Fix the compliation errors by moving all the address space definition
> macros before including pgtable-64.h.
>
> Cc: stable@vger.kernel.org
> Fixes: 8ad8b72721d0 (riscv: Add KASAN support)
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> ---
>  arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++---------------
>  1 file changed, 41 insertions(+), 37 deletions(-)
>
> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> index 453afb0a570a..4f6ee48a42e8 100644
> --- a/arch/riscv/include/asm/pgtable.h
> +++ b/arch/riscv/include/asm/pgtable.h
> @@ -19,6 +19,47 @@
>  #include <asm/tlbflush.h>
>  #include <linux/mm_types.h>
>
> +#ifdef CONFIG_MMU
> +
> +#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
> +#define VMALLOC_END      (PAGE_OFFSET - 1)
> +#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
> +
> +#define BPF_JIT_REGION_SIZE	(SZ_128M)
> +#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> +#define BPF_JIT_REGION_END	(VMALLOC_END)
> +
> +/*
> + * 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	BIT(VMEMMAP_SHIFT)
> +#define VMEMMAP_END	(VMALLOC_START - 1)
> +#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)
> +
> +/*
> + * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> + * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> + */
> +#define vmemmap		((struct page *)VMEMMAP_START)
> +
> +#define PCI_IO_SIZE      SZ_16M
> +#define PCI_IO_END       VMEMMAP_START
> +#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> +
> +#define FIXADDR_TOP      PCI_IO_START
> +#ifdef CONFIG_64BIT
> +#define FIXADDR_SIZE     PMD_SIZE
> +#else
> +#define FIXADDR_SIZE     PGDIR_SIZE
> +#endif
> +#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> +
> +#endif
> +
>  #ifdef CONFIG_64BIT
>  #include <asm/pgtable-64.h>
>  #else
> @@ -90,31 +131,6 @@ 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)
> -
> -#define BPF_JIT_REGION_SIZE	(SZ_128M)
> -#define BPF_JIT_REGION_START	(PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> -#define BPF_JIT_REGION_END	(VMALLOC_END)
> -
> -/*
> - * 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	BIT(VMEMMAP_SHIFT)
> -#define VMEMMAP_END	(VMALLOC_START - 1)
> -#define VMEMMAP_START	(VMALLOC_START - VMEMMAP_SIZE)
> -
> -/*
> - * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> - * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> - */
> -#define vmemmap		((struct page *)VMEMMAP_START)
> -
>  static inline int pmd_present(pmd_t pmd)
>  {
>  	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
> @@ -452,18 +468,6 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
>  #define __pte_to_swp_entry(pte)	((swp_entry_t) { pte_val(pte) })
>  #define __swp_entry_to_pte(x)	((pte_t) { (x).val })
>
> -#define PCI_IO_SIZE      SZ_16M
> -#define PCI_IO_END       VMEMMAP_START
> -#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> -
> -#define FIXADDR_TOP      PCI_IO_START
> -#ifdef CONFIG_64BIT
> -#define FIXADDR_SIZE     PMD_SIZE
> -#else
> -#define FIXADDR_SIZE     PGDIR_SIZE
> -#endif
> -#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> -
>  /*
>   * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
>   * Note that PGDIR_SIZE must evenly divide TASK_SIZE.

While this isn't technically a fix, I'm inclined to target it for the RCs just
to avoid conflicts.  I've put it on for-next now so the builders have some time
to chew on things, as I don't want to put in a non-fix too quickly.

Thanks!


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RISC-V: Move all address space definition macros to one place
  2020-03-06  0:20 ` Palmer Dabbelt
@ 2020-03-21 20:29   ` David Abdurachmanov
  2020-03-23 10:31     ` David Abdurachmanov
  0 siblings, 1 reply; 7+ messages in thread
From: David Abdurachmanov @ 2020-03-21 20:29 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Albert Ou, nickhu, Bjorn Topel, Anup Patel,
	linux-kernel@vger.kernel.org List, stable, Mike Rapoport,
	Atish Patra, linux-riscv, Paul Walmsley, Greentime Hu,
	Thomas Gleixner, akpm

On Fri, Mar 6, 2020 at 2:20 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>
> On Mon, 24 Feb 2020 11:34:36 PST (-0800), Atish Patra wrote:
> > If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get the
> > following compilation error.
> >
> > ---------------------------------------------------------------
> > ./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
> > ./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’ undeclared
> > (first use in this function); did you mean ‘mem_map’?
> >  #define __pfn_to_page(pfn) (vmemmap + (pfn))
> >                              ^~~~~~~
> > ./include/asm-generic/memory_model.h:82:21: note: in expansion of
> > macro ‘__pfn_to_page’
> >
> >  #define pfn_to_page __pfn_to_page
> >                      ^~~~~~~~~~~~~
> > ./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of macro
> > ‘pfn_to_page’
> >   return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
> > ---------------------------------------------------------------
> >
> > Fix the compliation errors by moving all the address space definition
> > macros before including pgtable-64.h.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 8ad8b72721d0 (riscv: Add KASAN support)
> >
> > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > ---
> >  arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++---------------
> >  1 file changed, 41 insertions(+), 37 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> > index 453afb0a570a..4f6ee48a42e8 100644
> > --- a/arch/riscv/include/asm/pgtable.h
> > +++ b/arch/riscv/include/asm/pgtable.h
> > @@ -19,6 +19,47 @@
> >  #include <asm/tlbflush.h>
> >  #include <linux/mm_types.h>
> >
> > +#ifdef CONFIG_MMU
> > +
> > +#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
> > +#define VMALLOC_END      (PAGE_OFFSET - 1)
> > +#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
> > +
> > +#define BPF_JIT_REGION_SIZE  (SZ_128M)
> > +#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > +#define BPF_JIT_REGION_END   (VMALLOC_END)
> > +
> > +/*
> > + * 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 BIT(VMEMMAP_SHIFT)
> > +#define VMEMMAP_END  (VMALLOC_START - 1)
> > +#define VMEMMAP_START        (VMALLOC_START - VMEMMAP_SIZE)
> > +
> > +/*
> > + * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> > + * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > + */
> > +#define vmemmap              ((struct page *)VMEMMAP_START)
> > +
> > +#define PCI_IO_SIZE      SZ_16M
> > +#define PCI_IO_END       VMEMMAP_START
> > +#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > +
> > +#define FIXADDR_TOP      PCI_IO_START
> > +#ifdef CONFIG_64BIT
> > +#define FIXADDR_SIZE     PMD_SIZE
> > +#else
> > +#define FIXADDR_SIZE     PGDIR_SIZE
> > +#endif
> > +#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > +
> > +#endif
> > +
> >  #ifdef CONFIG_64BIT
> >  #include <asm/pgtable-64.h>
> >  #else
> > @@ -90,31 +131,6 @@ 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)
> > -
> > -#define BPF_JIT_REGION_SIZE  (SZ_128M)
> > -#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > -#define BPF_JIT_REGION_END   (VMALLOC_END)
> > -
> > -/*
> > - * 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 BIT(VMEMMAP_SHIFT)
> > -#define VMEMMAP_END  (VMALLOC_START - 1)
> > -#define VMEMMAP_START        (VMALLOC_START - VMEMMAP_SIZE)
> > -
> > -/*
> > - * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> > - * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > - */
> > -#define vmemmap              ((struct page *)VMEMMAP_START)
> > -
> >  static inline int pmd_present(pmd_t pmd)
> >  {
> >       return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
> > @@ -452,18 +468,6 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> >  #define __pte_to_swp_entry(pte)      ((swp_entry_t) { pte_val(pte) })
> >  #define __swp_entry_to_pte(x)        ((pte_t) { (x).val })
> >
> > -#define PCI_IO_SIZE      SZ_16M
> > -#define PCI_IO_END       VMEMMAP_START
> > -#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > -
> > -#define FIXADDR_TOP      PCI_IO_START
> > -#ifdef CONFIG_64BIT
> > -#define FIXADDR_SIZE     PMD_SIZE
> > -#else
> > -#define FIXADDR_SIZE     PGDIR_SIZE
> > -#endif
> > -#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > -
> >  /*
> >   * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
> >   * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
>
> While this isn't technically a fix, I'm inclined to target it for the RCs just
> to avoid conflicts.  I've put it on for-next now so the builders have some time
> to chew on things, as I don't want to put in a non-fix too quickly.

I hit the same issue in Fedora/RISCV while building kernel-5.6.0-0.rc6, and
we don't have KASAN selected. We do have CONFIG_SPARSEMEM_VMEMMAP
selected.

I will try this patch tomorrow.

>
> Thanks!


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RISC-V: Move all address space definition macros to one place
  2020-03-21 20:29   ` David Abdurachmanov
@ 2020-03-23 10:31     ` David Abdurachmanov
  2020-03-26 21:43       ` Atish Patra
  0 siblings, 1 reply; 7+ messages in thread
From: David Abdurachmanov @ 2020-03-23 10:31 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Albert Ou, nickhu, Bjorn Topel, Anup Patel,
	linux-kernel@vger.kernel.org List, stable, Mike Rapoport,
	Atish Patra, linux-riscv, Paul Walmsley, Greentime Hu,
	Thomas Gleixner, akpm

On Sat, Mar 21, 2020 at 10:29 PM David Abdurachmanov
<david.abdurachmanov@gmail.com> wrote:
>
> On Fri, Mar 6, 2020 at 2:20 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
> >
> > On Mon, 24 Feb 2020 11:34:36 PST (-0800), Atish Patra wrote:
> > > If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get the
> > > following compilation error.
> > >
> > > ---------------------------------------------------------------
> > > ./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
> > > ./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’ undeclared
> > > (first use in this function); did you mean ‘mem_map’?
> > >  #define __pfn_to_page(pfn) (vmemmap + (pfn))
> > >                              ^~~~~~~
> > > ./include/asm-generic/memory_model.h:82:21: note: in expansion of
> > > macro ‘__pfn_to_page’
> > >
> > >  #define pfn_to_page __pfn_to_page
> > >                      ^~~~~~~~~~~~~
> > > ./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of macro
> > > ‘pfn_to_page’
> > >   return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
> > > ---------------------------------------------------------------
> > >
> > > Fix the compliation errors by moving all the address space definition
> > > macros before including pgtable-64.h.
> > >
> > > Cc: stable@vger.kernel.org
> > > Fixes: 8ad8b72721d0 (riscv: Add KASAN support)
> > >
> > > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > > ---
> > >  arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++---------------
> > >  1 file changed, 41 insertions(+), 37 deletions(-)
> > >
> > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> > > index 453afb0a570a..4f6ee48a42e8 100644
> > > --- a/arch/riscv/include/asm/pgtable.h
> > > +++ b/arch/riscv/include/asm/pgtable.h
> > > @@ -19,6 +19,47 @@
> > >  #include <asm/tlbflush.h>
> > >  #include <linux/mm_types.h>
> > >
> > > +#ifdef CONFIG_MMU
> > > +
> > > +#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
> > > +#define VMALLOC_END      (PAGE_OFFSET - 1)
> > > +#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
> > > +
> > > +#define BPF_JIT_REGION_SIZE  (SZ_128M)
> > > +#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > > +#define BPF_JIT_REGION_END   (VMALLOC_END)
> > > +
> > > +/*
> > > + * 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 BIT(VMEMMAP_SHIFT)
> > > +#define VMEMMAP_END  (VMALLOC_START - 1)
> > > +#define VMEMMAP_START        (VMALLOC_START - VMEMMAP_SIZE)
> > > +
> > > +/*
> > > + * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> > > + * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > > + */
> > > +#define vmemmap              ((struct page *)VMEMMAP_START)
> > > +
> > > +#define PCI_IO_SIZE      SZ_16M
> > > +#define PCI_IO_END       VMEMMAP_START
> > > +#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > > +
> > > +#define FIXADDR_TOP      PCI_IO_START
> > > +#ifdef CONFIG_64BIT
> > > +#define FIXADDR_SIZE     PMD_SIZE
> > > +#else
> > > +#define FIXADDR_SIZE     PGDIR_SIZE
> > > +#endif
> > > +#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > > +
> > > +#endif
> > > +
> > >  #ifdef CONFIG_64BIT
> > >  #include <asm/pgtable-64.h>
> > >  #else
> > > @@ -90,31 +131,6 @@ 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)
> > > -
> > > -#define BPF_JIT_REGION_SIZE  (SZ_128M)
> > > -#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > > -#define BPF_JIT_REGION_END   (VMALLOC_END)
> > > -
> > > -/*
> > > - * 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 BIT(VMEMMAP_SHIFT)
> > > -#define VMEMMAP_END  (VMALLOC_START - 1)
> > > -#define VMEMMAP_START        (VMALLOC_START - VMEMMAP_SIZE)
> > > -
> > > -/*
> > > - * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> > > - * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > > - */
> > > -#define vmemmap              ((struct page *)VMEMMAP_START)
> > > -
> > >  static inline int pmd_present(pmd_t pmd)
> > >  {
> > >       return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
> > > @@ -452,18 +468,6 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> > >  #define __pte_to_swp_entry(pte)      ((swp_entry_t) { pte_val(pte) })
> > >  #define __swp_entry_to_pte(x)        ((pte_t) { (x).val })
> > >
> > > -#define PCI_IO_SIZE      SZ_16M
> > > -#define PCI_IO_END       VMEMMAP_START
> > > -#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > > -
> > > -#define FIXADDR_TOP      PCI_IO_START
> > > -#ifdef CONFIG_64BIT
> > > -#define FIXADDR_SIZE     PMD_SIZE
> > > -#else
> > > -#define FIXADDR_SIZE     PGDIR_SIZE
> > > -#endif
> > > -#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > > -
> > >  /*
> > >   * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
> > >   * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
> >
> > While this isn't technically a fix, I'm inclined to target it for the RCs just
> > to avoid conflicts.  I've put it on for-next now so the builders have some time
> > to chew on things, as I don't want to put in a non-fix too quickly.
>
> I hit the same issue in Fedora/RISCV while building kernel-5.6.0-0.rc6, and
> we don't have KASAN selected. We do have CONFIG_SPARSEMEM_VMEMMAP
> selected.
>
> I will try this patch tomorrow.
>
Confirmed to solve my build errors with kernel in Fedora/RISCV.

david


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] RISC-V: Move all address space definition macros to one place
  2020-03-23 10:31     ` David Abdurachmanov
@ 2020-03-26 21:43       ` Atish Patra
  0 siblings, 0 replies; 7+ messages in thread
From: Atish Patra @ 2020-03-26 21:43 UTC (permalink / raw)
  To: David Abdurachmanov
  Cc: Palmer Dabbelt, akpm, Nick Hu, Bjorn Topel, Anup Patel,
	linux-kernel@vger.kernel.org List, stable, Mike Rapoport,
	Atish Patra, Albert Ou, Paul Walmsley, Greentime Hu, linux-riscv,
	Thomas Gleixner

On Mon, Mar 23, 2020 at 3:32 AM David Abdurachmanov
<david.abdurachmanov@gmail.com> wrote:
>
> On Sat, Mar 21, 2020 at 10:29 PM David Abdurachmanov
> <david.abdurachmanov@gmail.com> wrote:
> >
> > On Fri, Mar 6, 2020 at 2:20 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
> > >
> > > On Mon, 24 Feb 2020 11:34:36 PST (-0800), Atish Patra wrote:
> > > > If both CONFIG_KASAN and CONFIG_SPARSEMEM_VMEMMAP are set, we get the
> > > > following compilation error.
> > > >
> > > > ---------------------------------------------------------------
> > > > ./arch/riscv/include/asm/pgtable-64.h: In function ‘pud_page’:
> > > > ./include/asm-generic/memory_model.h:54:29: error: ‘vmemmap’ undeclared
> > > > (first use in this function); did you mean ‘mem_map’?
> > > >  #define __pfn_to_page(pfn) (vmemmap + (pfn))
> > > >                              ^~~~~~~
> > > > ./include/asm-generic/memory_model.h:82:21: note: in expansion of
> > > > macro ‘__pfn_to_page’
> > > >
> > > >  #define pfn_to_page __pfn_to_page
> > > >                      ^~~~~~~~~~~~~
> > > > ./arch/riscv/include/asm/pgtable-64.h:70:9: note: in expansion of macro
> > > > ‘pfn_to_page’
> > > >   return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
> > > > ---------------------------------------------------------------
> > > >
> > > > Fix the compliation errors by moving all the address space definition
> > > > macros before including pgtable-64.h.
> > > >
> > > > Cc: stable@vger.kernel.org
> > > > Fixes: 8ad8b72721d0 (riscv: Add KASAN support)
> > > >
> > > > Signed-off-by: Atish Patra <atish.patra@wdc.com>
> > > > ---
> > > >  arch/riscv/include/asm/pgtable.h | 78 +++++++++++++++++---------------
> > > >  1 file changed, 41 insertions(+), 37 deletions(-)
> > > >
> > > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
> > > > index 453afb0a570a..4f6ee48a42e8 100644
> > > > --- a/arch/riscv/include/asm/pgtable.h
> > > > +++ b/arch/riscv/include/asm/pgtable.h
> > > > @@ -19,6 +19,47 @@
> > > >  #include <asm/tlbflush.h>
> > > >  #include <linux/mm_types.h>
> > > >
> > > > +#ifdef CONFIG_MMU
> > > > +
> > > > +#define VMALLOC_SIZE     (KERN_VIRT_SIZE >> 1)
> > > > +#define VMALLOC_END      (PAGE_OFFSET - 1)
> > > > +#define VMALLOC_START    (PAGE_OFFSET - VMALLOC_SIZE)
> > > > +
> > > > +#define BPF_JIT_REGION_SIZE  (SZ_128M)
> > > > +#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > > > +#define BPF_JIT_REGION_END   (VMALLOC_END)
> > > > +
> > > > +/*
> > > > + * 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 BIT(VMEMMAP_SHIFT)
> > > > +#define VMEMMAP_END  (VMALLOC_START - 1)
> > > > +#define VMEMMAP_START        (VMALLOC_START - VMEMMAP_SIZE)
> > > > +
> > > > +/*
> > > > + * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> > > > + * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > > > + */
> > > > +#define vmemmap              ((struct page *)VMEMMAP_START)
> > > > +
> > > > +#define PCI_IO_SIZE      SZ_16M
> > > > +#define PCI_IO_END       VMEMMAP_START
> > > > +#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > > > +
> > > > +#define FIXADDR_TOP      PCI_IO_START
> > > > +#ifdef CONFIG_64BIT
> > > > +#define FIXADDR_SIZE     PMD_SIZE
> > > > +#else
> > > > +#define FIXADDR_SIZE     PGDIR_SIZE
> > > > +#endif
> > > > +#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > > > +
> > > > +#endif
> > > > +
> > > >  #ifdef CONFIG_64BIT
> > > >  #include <asm/pgtable-64.h>
> > > >  #else
> > > > @@ -90,31 +131,6 @@ 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)
> > > > -
> > > > -#define BPF_JIT_REGION_SIZE  (SZ_128M)
> > > > -#define BPF_JIT_REGION_START (PAGE_OFFSET - BPF_JIT_REGION_SIZE)
> > > > -#define BPF_JIT_REGION_END   (VMALLOC_END)
> > > > -
> > > > -/*
> > > > - * 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 BIT(VMEMMAP_SHIFT)
> > > > -#define VMEMMAP_END  (VMALLOC_START - 1)
> > > > -#define VMEMMAP_START        (VMALLOC_START - VMEMMAP_SIZE)
> > > > -
> > > > -/*
> > > > - * Define vmemmap for pfn_to_page & page_to_pfn calls. Needed if kernel
> > > > - * is configured with CONFIG_SPARSEMEM_VMEMMAP enabled.
> > > > - */
> > > > -#define vmemmap              ((struct page *)VMEMMAP_START)
> > > > -
> > > >  static inline int pmd_present(pmd_t pmd)
> > > >  {
> > > >       return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
> > > > @@ -452,18 +468,6 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
> > > >  #define __pte_to_swp_entry(pte)      ((swp_entry_t) { pte_val(pte) })
> > > >  #define __swp_entry_to_pte(x)        ((pte_t) { (x).val })
> > > >
> > > > -#define PCI_IO_SIZE      SZ_16M
> > > > -#define PCI_IO_END       VMEMMAP_START
> > > > -#define PCI_IO_START     (PCI_IO_END - PCI_IO_SIZE)
> > > > -
> > > > -#define FIXADDR_TOP      PCI_IO_START
> > > > -#ifdef CONFIG_64BIT
> > > > -#define FIXADDR_SIZE     PMD_SIZE
> > > > -#else
> > > > -#define FIXADDR_SIZE     PGDIR_SIZE
> > > > -#endif
> > > > -#define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
> > > > -
> > > >  /*
> > > >   * Task size is 0x4000000000 for RV64 or 0x9fc00000 for RV32.
> > > >   * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
> > >
> > > While this isn't technically a fix, I'm inclined to target it for the RCs just
> > > to avoid conflicts.  I've put it on for-next now so the builders have some time
> > > to chew on things, as I don't want to put in a non-fix too quickly.
> >
> > I hit the same issue in Fedora/RISCV while building kernel-5.6.0-0.rc6, and
> > we don't have KASAN selected. We do have CONFIG_SPARSEMEM_VMEMMAP
> > selected.
> >

Yes. I just verified that. CONFIG_SPARSEMEM_VMEMMAP is enough to
trigger the build error.
The code that raises the compilation error is added by kasan patchset,
but it is not dependent upon kasan.

--- a/arch/riscv/include/asm/pgtable-64.h
+++ b/arch/riscv/include/asm/pgtable-64.h
@@ -58,6 +58,11 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
        return (unsigned long)pfn_to_virt(pud_val(pud) >> _PAGE_PFN_SHIFT);
 }

+static inline struct page *pud_page(pud_t pud)
+{
+       return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
+}
+

@palmer: I am not sure if it is too late for an RC-fix. If not, can
you send it as an RC-fix ?

Let me know if you want me to respin the patch editing the commit text.

> > I will try this patch tomorrow.
> >
> Confirmed to solve my build errors with kernel in Fedora/RISCV.
>
> david
>


-- 
Regards,
Atish


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-26 21:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 19:34 [PATCH] RISC-V: Move all address space definition macros to one place Atish Patra
2020-02-28  4:08 ` Anup Patel
2020-02-28 18:23   ` Atish Patra
2020-03-06  0:20 ` Palmer Dabbelt
2020-03-21 20:29   ` David Abdurachmanov
2020-03-23 10:31     ` David Abdurachmanov
2020-03-26 21:43       ` Atish Patra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).