Re: [PATCH 1/9] alpha: remove DISCONTIGMEM and NUMA

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

NUMA is marked broken on alpha for more than 15 years and DISCONTIGMEM was
replaced with SPARSEMEM in v5.11.

Remove both NUMA and DISCONTIGMEM support from alpha.

Signed-off-by: Mike Rapoport 
---
  arch/alpha/Kconfig|  22 ---
  arch/alpha/include/asm/machvec.h  |   6 -
  arch/alpha/include/asm/mmzone.h   | 100 --
  arch/alpha/include/asm/pgtable.h  |   4 -
  arch/alpha/include/asm/topology.h |  39 --
  arch/alpha/kernel/core_marvel.c   |  53 +--
  arch/alpha/kernel/core_wildfire.c |  29 +---
  arch/alpha/kernel/pci_iommu.c |  29 
  arch/alpha/kernel/proto.h |   8 --
  arch/alpha/kernel/setup.c |  16 ---
  arch/alpha/kernel/sys_marvel.c|   5 -
  arch/alpha/kernel/sys_wildfire.c  |   5 -
  arch/alpha/mm/Makefile|   2 -
  arch/alpha/mm/init.c  |   3 -
  arch/alpha/mm/numa.c  | 223 --
  15 files changed, 4 insertions(+), 540 deletions(-)
  delete mode 100644 arch/alpha/include/asm/mmzone.h
  delete mode 100644 arch/alpha/mm/numa.c

diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 5998106faa60..8954216b9956 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -549,29 +549,12 @@ config NR_CPUS
  MARVEL support can handle a maximum of 32 CPUs, all the others
  with working support have a maximum of 4 CPUs.
  
-config ARCH_DISCONTIGMEM_ENABLE

-   bool "Discontiguous Memory Support"
-   depends on BROKEN
-   help
- Say Y to support efficient handling of discontiguous physical memory,
- for architectures which are either NUMA (Non-Uniform Memory Access)
- or have huge holes in the physical address space for other reasons.
- See  for more.
-
  config ARCH_SPARSEMEM_ENABLE
bool "Sparse Memory Support"
help
  Say Y to support efficient handling of discontiguous physical memory,
  for systems that have huge holes in the physical address space.
  
-config NUMA

-   bool "NUMA Support (EXPERIMENTAL)"
-   depends on DISCONTIGMEM && BROKEN
-   help
- Say Y to compile the kernel to support NUMA (Non-Uniform Memory
- Access).  This option is for configuring high-end multiprocessor
- server machines.  If in doubt, say N.
-
  config ALPHA_WTINT
bool "Use WTINT" if ALPHA_SRM || ALPHA_GENERIC
default y if ALPHA_QEMU
@@ -596,11 +579,6 @@ config ALPHA_WTINT
  
  	  If unsure, say N.
  
-config NODES_SHIFT

-   int
-   default "7"
-   depends on NEED_MULTIPLE_NODES
-
  # LARGE_VMALLOC is racy, if you *really* need it then fix it first
  config ALPHA_LARGE_VMALLOC
bool
diff --git a/arch/alpha/include/asm/machvec.h b/arch/alpha/include/asm/machvec.h
index a4e96e2bec74..e49fabce7b33 100644
--- a/arch/alpha/include/asm/machvec.h
+++ b/arch/alpha/include/asm/machvec.h
@@ -99,12 +99,6 @@ struct alpha_machine_vector
  
  	const char *vector_name;
  
-	/* NUMA information */

-   int (*pa_to_nid)(unsigned long);
-   int (*cpuid_to_nid)(int);
-   unsigned long (*node_mem_start)(int);
-   unsigned long (*node_mem_size)(int);
-
/* System specific parameters.  */
union {
struct {
diff --git a/arch/alpha/include/asm/mmzone.h b/arch/alpha/include/asm/mmzone.h
deleted file mode 100644
index 86644604d977..
--- a/arch/alpha/include/asm/mmzone.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Written by Kanoj Sarcar (ka...@sgi.com) Aug 99
- * Adapted for the alpha wildfire architecture Jan 2001.
- */
-#ifndef _ASM_MMZONE_H_
-#define _ASM_MMZONE_H_
-
-#ifdef CONFIG_DISCONTIGMEM
-
-#include 
-
-/*
- * Following are macros that are specific to this numa platform.
- */
-
-extern pg_data_t node_data[];
-
-#define alpha_pa_to_nid(pa)\
-(alpha_mv.pa_to_nid\
-? alpha_mv.pa_to_nid(pa)   \
-: (0))
-#define node_mem_start(nid)\
-(alpha_mv.node_mem_start   \
-? alpha_mv.node_mem_start(nid) \
-: (0UL))
-#define node_mem_size(nid) \
-(alpha_mv.node_mem_size\
-? alpha_mv.node_mem_size(nid)  \
-: ((nid) ? (0UL) : (~0UL)))
-
-#define pa_to_nid(pa)  alpha_pa_to_nid(pa)
-#define NODE_DATA(nid) (&node_data[(nid)])
-
-#define node_localnr(pfn, nid) ((pfn) - NODE_DATA(nid)->node_start_pfn)
-
-#if 1
-#define PLAT_NODE_DATA_LOCALNR(p, n)   \
-   (((p) >> PAGE_SHIFT) - PLAT_NODE_DATA(n)->gendata.node_start_pfn)
-#else
-static inline unsigned long
-PLAT_NODE_DATA_LOCALNR(unsigned long p, int n)
-{
-   unsigned long temp;
-   temp = p >> PAGE_SHIFT;
-   return temp - PLAT_NODE_DATA(n)->gendata.node_start_pfn;
-}
-#endif
-
-/*
- * Following are macros that each numa implementation must define.
- */
-
-/*
- * Given a kernel address, find the home node of the

Re: [PATCH 2/9] arc: update comment about HIGHMEM implementation

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

Arc does not use DISCONTIGMEM to implement high memory, update the comment
describing how high memory works to reflect this.

Signed-off-by: Mike Rapoport 
---
  arch/arc/mm/init.c | 13 +
  1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index e2ed355438c9..397a201adfe3 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -139,16 +139,13 @@ void __init setup_arch_memory(void)
  
  #ifdef CONFIG_HIGHMEM

/*
-* Populate a new node with highmem
-*
 * On ARC (w/o PAE) HIGHMEM addresses are actually smaller (0 based)
-* than addresses in normal ala low memory (0x8000_ based).
+* than addresses in normal aka low memory (0x8000_ based).
 * Even with PAE, the huge peripheral space hole would waste a lot of
-* mem with single mem_map[]. This warrants a mem_map per region design.
-* Thus HIGHMEM on ARC is imlemented with DISCONTIGMEM.
-*
-* DISCONTIGMEM in turns requires multiple nodes. node 0 above is
-* populated with normal memory zone while node 1 only has highmem
+* mem with single contiguous mem_map[].
+* Thus when HIGHMEM on ARC is enabled the memory map corresponding
+* to the hole is freed and ARC specific version of pfn_valid()
+* handles the hole in the memory map.
 */
  #ifdef CONFIG_DISCONTIGMEM
node_set_online(1);



Reviewed-by: David Hildenbrand 

--
Thanks,

David / dhildenb


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 3/9] arc: remove support for DISCONTIGMEM

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

DISCONTIGMEM was replaced by FLATMEM with freeing of the unused memory map
in v5.11.

Remove the support for DISCONTIGMEM entirely.

Signed-off-by: Mike Rapoport 


Acked-by: David Hildenbrand 

--
Thanks,

David / dhildenb


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 5/9] mm: remove CONFIG_DISCONTIGMEM

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

There are no architectures that support DISCONTIGMEM left.

Remove the configuration option and the dead code it was guarding in the
generic memory management code.

Signed-off-by: Mike Rapoport 
---
  include/asm-generic/memory_model.h | 37 --
  include/linux/mmzone.h |  4 ++--
  mm/Kconfig | 25 +++-
  mm/memory.c|  3 +--
  mm/page_alloc.c| 13 ---
  5 files changed, 10 insertions(+), 72 deletions(-)

diff --git a/include/asm-generic/memory_model.h 
b/include/asm-generic/memory_model.h
index 7637fb46ba4f..a2c8ed60233a 100644
--- a/include/asm-generic/memory_model.h
+++ b/include/asm-generic/memory_model.h
@@ -6,47 +6,18 @@
  
  #ifndef __ASSEMBLY__
  
+/*

+ * supports 3 memory models.
+ */
  #if defined(CONFIG_FLATMEM)
  
  #ifndef ARCH_PFN_OFFSET

  #define ARCH_PFN_OFFSET   (0UL)
  #endif
  
-#elif defined(CONFIG_DISCONTIGMEM)

-
-#ifndef arch_pfn_to_nid
-#define arch_pfn_to_nid(pfn)   pfn_to_nid(pfn)
-#endif
-
-#ifndef arch_local_page_offset
-#define arch_local_page_offset(pfn, nid)   \
-   ((pfn) - NODE_DATA(nid)->node_start_pfn)
-#endif
-
-#endif /* CONFIG_DISCONTIGMEM */
-
-/*
- * supports 3 memory models.
- */
-#if defined(CONFIG_FLATMEM)
-
  #define __pfn_to_page(pfn)(mem_map + ((pfn) - ARCH_PFN_OFFSET))
  #define __page_to_pfn(page)   ((unsigned long)((page) - mem_map) + \
 ARCH_PFN_OFFSET)
-#elif defined(CONFIG_DISCONTIGMEM)
-
-#define __pfn_to_page(pfn) \
-({ unsigned long __pfn = (pfn);\
-   unsigned long __nid = arch_pfn_to_nid(__pfn);  \
-   NODE_DATA(__nid)->node_mem_map + arch_local_page_offset(__pfn, __nid);\
-})
-
-#define __page_to_pfn(pg)  \
-({ const struct page *__pg = (pg); \
-   struct pglist_data *__pgdat = NODE_DATA(page_to_nid(__pg)); \
-   (unsigned long)(__pg - __pgdat->node_mem_map) +  \
-__pgdat->node_start_pfn;\
-})
  
  #elif defined(CONFIG_SPARSEMEM_VMEMMAP)
  
@@ -70,7 +41,7 @@

struct mem_section *__sec = __pfn_to_section(__pfn);\
__section_mem_map_addr(__sec) + __pfn;  \
  })
-#endif /* CONFIG_FLATMEM/DISCONTIGMEM/SPARSEMEM */
+#endif /* CONFIG_FLATMEM/SPARSEMEM */
  
  /*

   * Convert a physical address to a Page Frame Number and back
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 0d53eba1c383..2b41e252a995 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -738,8 +738,8 @@ struct zonelist {
struct zoneref _zonerefs[MAX_ZONES_PER_ZONELIST + 1];
  };
  
-#ifndef CONFIG_DISCONTIGMEM

-/* The array of struct pages - for discontigmem use pgdat->lmem_map */
+#ifdef CONFIG_FLATMEM
+/* The array of struct pages for flatmem */
  extern struct page *mem_map;
  #endif
  
diff --git a/mm/Kconfig b/mm/Kconfig

index 02d44e3420f5..218b96ccc84a 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -19,7 +19,7 @@ choice
  
  config FLATMEM_MANUAL

bool "Flat Memory"
-   depends on !(ARCH_DISCONTIGMEM_ENABLE || ARCH_SPARSEMEM_ENABLE) || 
ARCH_FLATMEM_ENABLE
+   depends on !ARCH_SPARSEMEM_ENABLE || ARCH_FLATMEM_ENABLE
help
  This option is best suited for non-NUMA systems with
  flat address space. The FLATMEM is the most efficient
@@ -32,21 +32,6 @@ config FLATMEM_MANUAL
  
  	  If unsure, choose this option (Flat Memory) over any other.
  
-config DISCONTIGMEM_MANUAL

-   bool "Discontiguous Memory"
-   depends on ARCH_DISCONTIGMEM_ENABLE
-   help
- This option provides enhanced support for discontiguous
- memory systems, over FLATMEM.  These systems have holes
- in their physical address spaces, and this option provides
- more efficient handling of these holes.
-
- Although "Discontiguous Memory" is still used by several
- architectures, it is considered deprecated in favor of
- "Sparse Memory".
-
- If unsure, choose "Sparse Memory" over this option.
-
  config SPARSEMEM_MANUAL
bool "Sparse Memory"
depends on ARCH_SPARSEMEM_ENABLE
@@ -62,17 +47,13 @@ config SPARSEMEM_MANUAL
  
  endchoice
  
-config DISCONTIGMEM

-   def_bool y
-   depends on (!SELECT_MEMORY_MODEL && ARCH_DISCONTIGMEM_ENABLE) || 
DISCONTIGMEM_MANUAL
-
  config SPARSEMEM
def_bool y
depends on (!SELECT_MEMORY_MODEL && ARCH_SPARSEMEM_ENABLE) || 
SPARSEMEM_MANUAL
  
  config FLATMEM

def_bool y
-   depends on (!DISCONTIGMEM && !SPARSEMEM) || FLATMEM_MANUAL
+   depends on !SPARSEMEM || FLATMEM_MANUAL
  
  config FLAT_NODE_MEM_MAP

def_bool y
@@ -85,7 +66,7 @@ config FLAT_NODE_MEM_MAP
  #
  config NEED_MULTIPLE_NODES
def_bool y
- 

Re: [PATCH 6/9] arch, mm: remove stale mentions of DISCONIGMEM

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

There are several places that mention DISCONIGMEM in comments or have stale
code guarded by CONFIG_DISCONTIGMEM.

Remove the dead code and update the comments.

Signed-off-by: Mike Rapoport 
---
  arch/ia64/kernel/topology.c | 5 ++---
  arch/ia64/mm/numa.c | 5 ++---
  arch/mips/include/asm/mmzone.h  | 6 --
  arch/mips/mm/init.c | 3 ---
  arch/nds32/include/asm/memory.h | 6 --
  arch/xtensa/include/asm/page.h  | 4 
  include/linux/gfp.h | 4 ++--
  7 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index 09fc385c2acd..3639e0a7cb3b 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -3,9 +3,8 @@
   * License.  See the file "COPYING" in the main directory of this archive
   * for more details.
   *
- * This file contains NUMA specific variables and functions which can
- * be split away from DISCONTIGMEM and are used on NUMA machines with
- * contiguous memory.
+ * This file contains NUMA specific variables and functions which are used on
+ * NUMA machines with contiguous memory.
   *2002/08/07 Erich Focht 
   * Populate cpu entries in sysfs for non-numa systems as well
   *Intel Corporation - Ashok Raj
diff --git a/arch/ia64/mm/numa.c b/arch/ia64/mm/numa.c
index 46b6e5f3a40f..d6579ec3ea32 100644
--- a/arch/ia64/mm/numa.c
+++ b/arch/ia64/mm/numa.c
@@ -3,9 +3,8 @@
   * License.  See the file "COPYING" in the main directory of this archive
   * for more details.
   *
- * This file contains NUMA specific variables and functions which can
- * be split away from DISCONTIGMEM and are used on NUMA machines with
- * contiguous memory.
+ * This file contains NUMA specific variables and functions which are used on
+ * NUMA machines with contiguous memory.
   *
   * 2002/08/07 Erich Focht 
   */
diff --git a/arch/mips/include/asm/mmzone.h b/arch/mips/include/asm/mmzone.h
index b826b8473e95..7649ab45e80c 100644
--- a/arch/mips/include/asm/mmzone.h
+++ b/arch/mips/include/asm/mmzone.h
@@ -20,10 +20,4 @@
  #define nid_to_addrbase(nid) 0
  #endif
  
-#ifdef CONFIG_DISCONTIGMEM

-
-#define pfn_to_nid(pfn)pa_to_nid((pfn) << PAGE_SHIFT)
-
-#endif /* CONFIG_DISCONTIGMEM */
-
  #endif /* _ASM_MMZONE_H_ */
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index c36358758969..97f6ca341448 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -454,9 +454,6 @@ void __init mem_init(void)
BUILD_BUG_ON(IS_ENABLED(CONFIG_32BIT) && (_PFN_SHIFT > PAGE_SHIFT));
  
  #ifdef CONFIG_HIGHMEM

-#ifdef CONFIG_DISCONTIGMEM
-#error "CONFIG_HIGHMEM and CONFIG_DISCONTIGMEM dont work together yet"
-#endif
max_mapnr = highend_pfn ? highend_pfn : max_low_pfn;
  #else
max_mapnr = max_low_pfn;
diff --git a/arch/nds32/include/asm/memory.h b/arch/nds32/include/asm/memory.h
index 940d32842793..62faafbc28e4 100644
--- a/arch/nds32/include/asm/memory.h
+++ b/arch/nds32/include/asm/memory.h
@@ -76,18 +76,12 @@
   *  virt_to_page(k)   convert a _valid_ virtual address to struct page *
   *  virt_addr_valid(k)indicates whether a virtual address is valid
   */
-#ifndef CONFIG_DISCONTIGMEM
-
  #define ARCH_PFN_OFFSET   PHYS_PFN_OFFSET
  #define pfn_valid(pfn)((pfn) >= PHYS_PFN_OFFSET && (pfn) < 
(PHYS_PFN_OFFSET + max_mapnr))
  
  #define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))

  #define virt_addr_valid(kaddr)((unsigned long)(kaddr) >= PAGE_OFFSET && 
(unsigned long)(kaddr) < (unsigned long)high_memory)
  
-#else /* CONFIG_DISCONTIGMEM */

-#error CONFIG_DISCONTIGMEM is not supported yet.
-#endif /* !CONFIG_DISCONTIGMEM */
-
  #define page_to_phys(page)(page_to_pfn(page) << PAGE_SHIFT)
  
  #endif

diff --git a/arch/xtensa/include/asm/page.h b/arch/xtensa/include/asm/page.h
index 37ce25ef92d6..493eb7083b1a 100644
--- a/arch/xtensa/include/asm/page.h
+++ b/arch/xtensa/include/asm/page.h
@@ -192,10 +192,6 @@ static inline unsigned long ___pa(unsigned long va)
  #define pfn_valid(pfn) \
((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
  
-#ifdef CONFIG_DISCONTIGMEM

-# error CONFIG_DISCONTIGMEM not supported
-#endif
-
  #define virt_to_page(kaddr)   pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  #define page_to_virt(page)__va(page_to_pfn(page) << PAGE_SHIFT)
  #define virt_addr_valid(kaddr)pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 11da8af06704..dbe1f5fc901d 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -494,8 +494,8 @@ static inline int gfp_zonelist(gfp_t flags)
   * There are two zonelists per node, one for all zones with memory and
   * one containing just zones from the node the zonelist belongs to.
   *
- * For the normal case of non-DISCONTIGMEM systems the NODE_DATA() gets
- * optimized to &

Re: [PATCH 7/9] docs: remove description of DISCONTIGMEM

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

Remove description of DISCONTIGMEM from the "Memory Models" document and
update VM sysctl description so that it won't mention DISCONIGMEM.

Signed-off-by: Mike Rapoport 
---
  Documentation/admin-guide/sysctl/vm.rst | 12 +++
  Documentation/vm/memory-model.rst   | 45 ++---
  2 files changed, 8 insertions(+), 49 deletions(-)

diff --git a/Documentation/admin-guide/sysctl/vm.rst 
b/Documentation/admin-guide/sysctl/vm.rst
index 586cd4b86428..ddbd71d592e0 100644
--- a/Documentation/admin-guide/sysctl/vm.rst
+++ b/Documentation/admin-guide/sysctl/vm.rst
@@ -936,12 +936,12 @@ allocations, THP and hugetlbfs pages.
  
  To make it sensible with respect to the watermark_scale_factor

  parameter, the unit is in fractions of 10,000. The default value of
-15,000 on !DISCONTIGMEM configurations means that up to 150% of the high
-watermark will be reclaimed in the event of a pageblock being mixed due
-to fragmentation. The level of reclaim is determined by the number of
-fragmentation events that occurred in the recent past. If this value is
-smaller than a pageblock then a pageblocks worth of pages will be reclaimed
-(e.g.  2MB on 64-bit x86). A boost factor of 0 will disable the feature.
+15,000 means that up to 150% of the high watermark will be reclaimed in the
+event of a pageblock being mixed due to fragmentation. The level of reclaim
+is determined by the number of fragmentation events that occurred in the
+recent past. If this value is smaller than a pageblock then a pageblocks
+worth of pages will be reclaimed (e.g.  2MB on 64-bit x86). A boost factor
+of 0 will disable the feature.
  
  
  watermark_scale_factor

diff --git a/Documentation/vm/memory-model.rst 
b/Documentation/vm/memory-model.rst
index ce398a7dc6cd..30e8fbed6914 100644
--- a/Documentation/vm/memory-model.rst
+++ b/Documentation/vm/memory-model.rst
@@ -14,15 +14,11 @@ for the CPU. Then there could be several contiguous ranges 
at
  completely distinct addresses. And, don't forget about NUMA, where
  different memory banks are attached to different CPUs.
  
-Linux abstracts this diversity using one of the three memory models:

-FLATMEM, DISCONTIGMEM and SPARSEMEM. Each architecture defines what
+Linux abstracts this diversity using one of the two memory models:
+FLATMEM and SPARSEMEM. Each architecture defines what
  memory models it supports, what the default memory model is and
  whether it is possible to manually override that default.
  
-.. note::

-   At time of this writing, DISCONTIGMEM is considered deprecated,
-   although it is still in use by several architectures.
-
  All the memory models track the status of physical page frames using
  struct page arranged in one or more arrays.
  
@@ -63,43 +59,6 @@ straightforward: `PFN - ARCH_PFN_OFFSET` is an index to the

  The `ARCH_PFN_OFFSET` defines the first page frame number for
  systems with physical memory starting at address different from 0.
  
-DISCONTIGMEM

-
-
-The DISCONTIGMEM model treats the physical memory as a collection of
-`nodes` similarly to how Linux NUMA support does. For each node Linux
-constructs an independent memory management subsystem represented by
-`struct pglist_data` (or `pg_data_t` for short). Among other
-things, `pg_data_t` holds the `node_mem_map` array that maps
-physical pages belonging to that node. The `node_start_pfn` field of
-`pg_data_t` is the number of the first page frame belonging to that
-node.
-
-The architecture setup code should call :c:func:`free_area_init_node` for
-each node in the system to initialize the `pg_data_t` object and its
-`node_mem_map`.
-
-Every `node_mem_map` behaves exactly as FLATMEM's `mem_map` -
-every physical page frame in a node has a `struct page` entry in the
-`node_mem_map` array. When DISCONTIGMEM is enabled, a portion of the
-`flags` field of the `struct page` encodes the node number of the
-node hosting that page.
-
-The conversion between a PFN and the `struct page` in the
-DISCONTIGMEM model became slightly more complex as it has to determine
-which node hosts the physical page and which `pg_data_t` object
-holds the `struct page`.
-
-Architectures that support DISCONTIGMEM provide :c:func:`pfn_to_nid`
-to convert PFN to the node number. The opposite conversion helper
-:c:func:`page_to_nid` is generic as it uses the node number encoded in
-page->flags.
-
-Once the node number is known, the PFN can be used to index
-appropriate `node_mem_map` array to access the `struct page` and
-the offset of the `struct page` from the `node_mem_map` plus
-`node_start_pfn` is the PFN of that page.
-
  SPARSEMEM
  =
  



Reviewed-by: David Hildenbrand 

--
Thanks,

David / dhildenb


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 8/9] mm: replace CONFIG_NEED_MULTIPLE_NODES with CONFIG_NUMA

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

After removal of DISCINTIGMEM the NEED_MULTIPLE_NODES and NUMA
configuration options are equivalent.

Drop CONFIG_NEED_MULTIPLE_NODES and use CONFIG_NUMA instead.

Done with

$ sed -i 's/CONFIG_NEED_MULTIPLE_NODES/CONFIG_NUMA/' \
$(git grep -wl CONFIG_NEED_MULTIPLE_NODES)
$ sed -i 's/NEED_MULTIPLE_NODES/NUMA/' \
$(git grep -wl NEED_MULTIPLE_NODES)

with manual tweaks afterwards.

Signed-off-by: Mike Rapoport 
---
  arch/arm64/Kconfig|  2 +-
  arch/ia64/Kconfig |  2 +-
  arch/mips/Kconfig |  2 +-
  arch/mips/include/asm/mmzone.h|  2 +-
  arch/mips/include/asm/page.h  |  2 +-
  arch/mips/mm/init.c   |  4 ++--
  arch/powerpc/Kconfig  |  2 +-
  arch/powerpc/include/asm/mmzone.h |  4 ++--
  arch/powerpc/kernel/setup_64.c|  2 +-
  arch/powerpc/kernel/smp.c |  2 +-
  arch/powerpc/kexec/core.c |  4 ++--
  arch/powerpc/mm/Makefile  |  2 +-
  arch/powerpc/mm/mem.c |  4 ++--
  arch/riscv/Kconfig|  2 +-
  arch/s390/Kconfig |  2 +-
  arch/sh/include/asm/mmzone.h  |  4 ++--
  arch/sh/kernel/topology.c |  2 +-
  arch/sh/mm/Kconfig|  2 +-
  arch/sh/mm/init.c |  2 +-
  arch/sparc/Kconfig|  2 +-
  arch/sparc/include/asm/mmzone.h   |  4 ++--
  arch/sparc/kernel/smp_64.c|  2 +-
  arch/sparc/mm/init_64.c   | 12 ++--
  arch/x86/Kconfig  |  2 +-
  arch/x86/kernel/setup_percpu.c|  6 +++---
  arch/x86/mm/init_32.c |  4 ++--
  include/asm-generic/topology.h|  2 +-
  include/linux/memblock.h  |  6 +++---
  include/linux/mm.h|  4 ++--
  include/linux/mmzone.h|  8 
  kernel/crash_core.c   |  2 +-
  mm/Kconfig|  9 -
  mm/memblock.c |  8 
  mm/page_alloc.c   |  6 +++---
  34 files changed, 58 insertions(+), 67 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9f1d8566bbf9..d01a1545ab8f 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1035,7 +1035,7 @@ config NODES_SHIFT
int "Maximum NUMA Nodes (as a power of 2)"
range 1 10
default "4"
-   depends on NEED_MULTIPLE_NODES
+   depends on NUMA
help
  Specify the maximum number of NUMA Nodes available on the target
  system.  Increases memory reserved to accommodate various tables.
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 279252e3e0f7..da22a35e6f03 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -302,7 +302,7 @@ config NODES_SHIFT
int "Max num nodes shift(3-10)"
range 3 10
default "10"
-   depends on NEED_MULTIPLE_NODES
+   depends on NUMA
help
  This option specifies the maximum number of nodes in your SSI system.
  MAX_NUMNODES will be 2^(This value).
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index ed51970c08e7..4704a16c2e44 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2867,7 +2867,7 @@ config RANDOMIZE_BASE_MAX_OFFSET
  config NODES_SHIFT
int
default "6"
-   depends on NEED_MULTIPLE_NODES
+   depends on NUMA
  
  config HW_PERF_EVENTS

bool "Enable hardware performance counter support for perf events"
diff --git a/arch/mips/include/asm/mmzone.h b/arch/mips/include/asm/mmzone.h
index 7649ab45e80c..602a21aee9d4 100644
--- a/arch/mips/include/asm/mmzone.h
+++ b/arch/mips/include/asm/mmzone.h
@@ -8,7 +8,7 @@
  
  #include 
  
-#ifdef CONFIG_NEED_MULTIPLE_NODES

+#ifdef CONFIG_NUMA
  # include 
  #endif
  
diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h

index 195ff4e9771f..96bc798c1ec1 100644
--- a/arch/mips/include/asm/page.h
+++ b/arch/mips/include/asm/page.h
@@ -239,7 +239,7 @@ static inline int pfn_valid(unsigned long pfn)
  
  /* pfn_valid is defined in linux/mmzone.h */
  
-#elif defined(CONFIG_NEED_MULTIPLE_NODES)

+#elif defined(CONFIG_NUMA)
  
  #define pfn_valid(pfn)			\

  ({\
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 97f6ca341448..19347dc6bbf8 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -394,7 +394,7 @@ void maar_init(void)
}
  }
  
-#ifndef CONFIG_NEED_MULTIPLE_NODES

+#ifndef CONFIG_NUMA
  void __init paging_init(void)
  {
unsigned long max_zone_pfns[MAX_NR_ZONES];
@@ -473,7 +473,7 @@ void __init mem_init(void)
0x8000 - 4, KCORE_TEXT);
  #endif
  }
-#endif /* !CONFIG_NEED_MULTIPLE_NODES */
+#endif /* !CONFIG_NUMA */
  
  void free_init_pages(const char *what, unsigned long begin, unsigned long end)

  {
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 08

Re: [PATCH 9/9] mm: replace CONFIG_FLAT_NODE_MEM_MAP with CONFIG_FLATMEM

2021-06-09 Thread David Hildenbrand

On 02.06.21 12:53, Mike Rapoport wrote:

From: Mike Rapoport 

After removal of the DISCONTIGMEM memory model the FLAT_NODE_MEM_MAP
configuration option is equivalent to FLATMEM.

Drop CONFIG_FLAT_NODE_MEM_MAP and use CONFIG_FLATMEM instead.

Signed-off-by: Mike Rapoport 
---
  include/linux/mmzone.h | 4 ++--
  kernel/crash_core.c| 2 +-
  mm/Kconfig | 4 
  mm/page_alloc.c| 6 +++---
  mm/page_ext.c  | 2 +-
  5 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index ad42f440c704..2698cdbfbf75 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -775,7 +775,7 @@ typedef struct pglist_data {
struct zonelist node_zonelists[MAX_ZONELISTS];
  
  	int nr_zones; /* number of populated zones in this node */

-#ifdef CONFIG_FLAT_NODE_MEM_MAP/* means !SPARSEMEM */
+#ifdef CONFIG_FLATMEM  /* means !SPARSEMEM */
struct page *node_mem_map;
  #ifdef CONFIG_PAGE_EXTENSION
struct page_ext *node_page_ext;
@@ -865,7 +865,7 @@ typedef struct pglist_data {
  
  #define node_present_pages(nid)	(NODE_DATA(nid)->node_present_pages)

  #define node_spanned_pages(nid)   (NODE_DATA(nid)->node_spanned_pages)
-#ifdef CONFIG_FLAT_NODE_MEM_MAP
+#ifdef CONFIG_FLATMEM
  #define pgdat_page_nr(pgdat, pagenr)  ((pgdat)->node_mem_map + (pagenr))
  #else
  #define pgdat_page_nr(pgdat, pagenr)  pfn_to_page((pgdat)->node_start_pfn + 
(pagenr))
diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index 53eb8bc6026d..2b8446ea7105 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -483,7 +483,7 @@ static int __init crash_save_vmcoreinfo_init(void)
VMCOREINFO_OFFSET(page, compound_head);
VMCOREINFO_OFFSET(pglist_data, node_zones);
VMCOREINFO_OFFSET(pglist_data, nr_zones);
-#ifdef CONFIG_FLAT_NODE_MEM_MAP
+#ifdef CONFIG_FLATMEM
VMCOREINFO_OFFSET(pglist_data, node_mem_map);
  #endif
VMCOREINFO_OFFSET(pglist_data, node_start_pfn);
diff --git a/mm/Kconfig b/mm/Kconfig
index bffe4bd859f3..ded98fb859ab 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -55,10 +55,6 @@ config FLATMEM
def_bool y
depends on !SPARSEMEM || FLATMEM_MANUAL
  
-config FLAT_NODE_MEM_MAP

-   def_bool y
-   depends on !SPARSEMEM
-
  #
  # SPARSEMEM_EXTREME (which is the default) does some bootmem
  # allocations when sparse_init() is called.  If this cannot
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 8f08135d3eb4..f039736541eb 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6444,7 +6444,7 @@ static void __meminit zone_init_free_lists(struct zone 
*zone)
}
  }
  
-#if !defined(CONFIG_FLAT_NODE_MEM_MAP)

+#if !defined(CONFIG_FLATMEM)
  /*
   * Only struct pages that correspond to ranges defined by memblock.memory
   * are zeroed and initialized by going through __init_single_page() during
@@ -7241,7 +7241,7 @@ static void __init free_area_init_core(struct pglist_data 
*pgdat)
}
  }
  
-#ifdef CONFIG_FLAT_NODE_MEM_MAP

+#ifdef CONFIG_FLATMEM
  static void __ref alloc_node_mem_map(struct pglist_data *pgdat)
  {
unsigned long __maybe_unused start = 0;
@@ -7289,7 +7289,7 @@ static void __ref alloc_node_mem_map(struct pglist_data 
*pgdat)
  }
  #else
  static void __ref alloc_node_mem_map(struct pglist_data *pgdat) { }
-#endif /* CONFIG_FLAT_NODE_MEM_MAP */
+#endif /* CONFIG_FLATMEM */
  
  #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT

  static inline void pgdat_set_deferred_range(pg_data_t *pgdat)
diff --git a/mm/page_ext.c b/mm/page_ext.c
index df6f74aac8e1..293b2685fc48 100644
--- a/mm/page_ext.c
+++ b/mm/page_ext.c
@@ -191,7 +191,7 @@ void __init page_ext_init_flatmem(void)
panic("Out of memory");
  }
  
-#else /* CONFIG_FLAT_NODE_MEM_MAP */

+#else /* CONFIG_FLATMEM */
  
  struct page_ext *lookup_page_ext(const struct page *page)

  {



Acked-by: David Hildenbrand 

--
Thanks,

David / dhildenb


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v2 0/9] Remove DISCINTIGMEM memory model

2021-06-09 Thread Arnd Bergmann
On Fri, Jun 4, 2021 at 8:49 AM Mike Rapoport  wrote:
>
> From: Mike Rapoport 
>
> Hi,
>
> SPARSEMEM memory model was supposed to entirely replace DISCONTIGMEM a
> (long) while ago. The last architectures that used DISCONTIGMEM were
> updated to use other memory models in v5.11 and it is about the time to
> entirely remove DISCONTIGMEM from the kernel.
>
> This set removes DISCONTIGMEM from alpha, arc and m68k, simplifies memory
> model selection in mm/Kconfig and replaces usage of redundant
> CONFIG_NEED_MULTIPLE_NODES and CONFIG_FLAT_NODE_MEM_MAP with CONFIG_NUMA
> and CONFIG_FLATMEM respectively.
>
> I've also removed NUMA support on alpha that was BROKEN for more than 15
> years.
>
> There were also minor updates all over arch/ to remove mentions of
> DISCONTIGMEM in comments and #ifdefs.

Hi Mike and Andrew,

It looks like everyone is happy with this version so far. How should we merge it
for linux-next? I'm happy to take it through the asm-generic tree, but linux-mm
would fit at least as well. In case we go for linux-mm, feel free to add

Acked-by: Arnd Bergmann 

for the whole series.

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


QEmu ARC port - decoder implementation feedback

2021-06-09 Thread Cupertino Miranda
Hi Richard,

Last few weeks I have been working on cleaning up ARC port for further
reviewing.

In the context of the decoder, if I recall well, your observation was
that a linear search was not Ok.
Your suggestion was not to reinvent the wheel and generate decodetree to
create the decoder.

We started to do that and in the process we realize that the approach
would bring us yet another encoding language description to maintain.
Also that decodetree alone would not allow us to properly disassembly
code, still requiring to keep the initial structure.

Taking in consideration that we do all the other toolchain tools for ARC
and that the decoder structure is already upstreamed in binutils we
would definitely prefer to keep that structure and optimize the
surroundings for proper decoding speeds.

So far, we did the following:
   - converted opcodes.def to macros instead of table entries.
   - created a script that reads those entries and outputs macros that
directly translate to a switch/case decision tree (example below), just
like the ones produced by decodetree. The difference is that the switch
will return the enum entry for the proper decoder structure instead of
calling a translation function.
   - the script can either be contributed in C or python language as it
is based on a simple recursive algorithm.

As you have been the one giving attention to our target, I seek for your
early feedback and to make sure that the solution is still inline with
your expectations.

Looking forward for your feedback.

Regards,
Cupertino

PS: Would it be asking too much if we could have a call, just to
get to meet each other. Unfortunately, no one now is able to do it any
other way. I miss the traveling and conferences.

Example1 (first few lines of the file):

   MATCH_PATTERN(0xf800) /* 1000 */
    MATCH_VALUE(0x0) /* 0 */
     MATCH_PATTERN(0x1) /* 1 */
      MATCH_VALUE(0x0) /* 0 */
RETURN_MATCH(OPCODE_ARCv2HS_b_0x_0xF801_BRANCH_OP_SIMM21_A16_5)
/* 0ss0SSNQ */
      END_MATCH_VALUE(0x0) /* 0 */
      MATCH_VALUE(0x1) /* 1 */
RETURN_MATCH(OPCODE_ARCv2HS_b_0x0001_0xF801_BRANCH_OP_SIMM25_A16_5)
/* 0ss1SSNR */
      END_MATCH_VALUE(0x1) /* 1 */
     END_MATCH_PATTERN(0x1) /* 1 */
    END_MATCH_VALUE(0x0) /* 0 */
    MATCH_VALUE(0x800) /* 1000 */
     MATCH_PATTERN(0x1) /* 1 */
      MATCH_VALUE(0x0) /* 0 */
   MATCH_PATTERN(0x2) /* 10 */
    MATCH_VALUE(0x0) /* 0 */
RETURN_MATCH(OPCODE_ARCv2HS_bl_0x0800_0xF803_BRANCH_OP_SIMM21_A32_5)
/* 1s00SSNQ */
    END_MATCH_VALUE(0x0) /* 0 */
    MATCH_VALUE(0x2) /* 10 */
RETURN_MATCH(OPCODE_ARCv2HS_bl_0x0802_0xF803_BRANCH_OP_SIMM25_A32_5)
/* 1s10SSNR */
    END_MATCH_VALUE(0x2) /* 10 */
   END_MATCH_PATTERN(0x2) /* 10 */
      END_MATCH_VALUE(0x0) /* 0 */
      MATCH_VALUE(0x1) /* 1 */
   MATCH_PATTERN(0x17) /* 10111 */
    MATCH_VALUE(0x0) /* 0 */
MULTI_MATCH(OPCODE_ARCv2HS_breq_0x0801_0xF8010017_BRCC_OP_RB_RC_SIMM9_A16_8)
/* 1bbbsss1SBBBCCN0Y000 */
MULTI_MATCH(OPCODE_ARCv2HS_breq_0x08010F80_0xF8010FF7_BRCC_OP_RB_LIMM_SIMM9_A16_8)
/* 1bbbsss1SBBB1000Y000 */
MULTI_MATCH(OPCODE_ARCv2HS_breq_0x0E017000_0xFF017037_BRCC_OP_LIMM_RC_SIMM9_A16_8)
/* 1110sss1S111CC00Y000 */
MULTI_MATCH(OPCODE_ARCv2HS_breq_0x0E017F80_0xFF017FF7_BRCC_OP_LIMM_LIMMdup_SIMM9_A16_8)
/* 1110sss1S000Y000 */
    END_MATCH_VALUE(0x0) /* 0 */

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH v2 0/9] Remove DISCINTIGMEM memory model

2021-06-09 Thread Mike Rapoport
Hi Arnd,

On Wed, Jun 09, 2021 at 01:30:39PM +0200, Arnd Bergmann wrote:
> On Fri, Jun 4, 2021 at 8:49 AM Mike Rapoport  wrote:
> >
> > From: Mike Rapoport 
> >
> > Hi,
> >
> > SPARSEMEM memory model was supposed to entirely replace DISCONTIGMEM a
> > (long) while ago. The last architectures that used DISCONTIGMEM were
> > updated to use other memory models in v5.11 and it is about the time to
> > entirely remove DISCONTIGMEM from the kernel.
> >
> > This set removes DISCONTIGMEM from alpha, arc and m68k, simplifies memory
> > model selection in mm/Kconfig and replaces usage of redundant
> > CONFIG_NEED_MULTIPLE_NODES and CONFIG_FLAT_NODE_MEM_MAP with CONFIG_NUMA
> > and CONFIG_FLATMEM respectively.
> >
> > I've also removed NUMA support on alpha that was BROKEN for more than 15
> > years.
> >
> > There were also minor updates all over arch/ to remove mentions of
> > DISCONTIGMEM in comments and #ifdefs.
> 
> Hi Mike and Andrew,
> 
> It looks like everyone is happy with this version so far. How should we merge 
> it
> for linux-next? I'm happy to take it through the asm-generic tree, but 
> linux-mm
> would fit at least as well. In case we go for linux-mm, feel free to add

Andrew already took to mmotm.
 
> Acked-by: Arnd Bergmann 

Thanks!

> for the whole series.

-- 
Sincerely yours,
Mike.

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: QEmu ARC port - decoder implementation feedback

2021-06-09 Thread Richard Henderson

On 6/9/21 2:58 AM, Cupertino Miranda wrote:

We started to do that and in the process we realize that the approach
would bring us yet another encoding language description to maintain.


Why would you be maintaining another description?  Your approach below with the 
simple recursive algorithm appears to be no different.



Also that decodetree alone would not allow us to properly disassembly
code, still requiring to keep the initial structure.


Why is that?

The current uses of decodetree are quite complex, so I sincerely doubt that it 
cannot do the job.  You've asked no questions, nor have you described any 
problems you have encountered.


That said, decodetree was merely a suggestion based on what appeared to me to 
be a trivial automated textual rewrite of your current data set.  If you want 
to use something else that performs equally well, fine.



So far, we did the following:
    - converted opcodes.def to macros instead of table entries.


Sure.


    - created a script that reads those entries and outputs macros that
directly translate to a switch/case decision tree (example below), just
like the ones produced by decodetree. The difference is that the switch
will return the enum entry for the proper decoder structure instead of
calling a translation function.


An enum result is fine, sure.

The example is not especially enlightening because you don't show the macro 
definitions, or the expansion.  Have you a link to a git repo that you can share?



    - the script can either be contributed in C or python language as it
is based on a simple recursive algorithm.


Either is fine.  We currently use both as build-time generators.


r~

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: QEmu ARC port - decoder implementation feedback

2021-06-09 Thread Cupertino Miranda
Hi Richard

> Why would you be maintaining another description?  Your approach below 
> with the simple recursive algorithm appears to be no different.

We initially considered to drop our tables completely replacing it by 
decodetree.

>
>> Also that decodetree alone would not allow us to properly disassembly
>> code, still requiring to keep the initial structure.
>
> Why is that?

By disassembly I am referring to the pretty-print of the instructions 
when using "-d in_asm". Our tables contain information for printing as 
they are the ones used by bintutils assembler.

>
> The current uses of decodetree are quite complex, so I sincerely doubt 
> that it cannot do the job.  You've asked no questions, nor have you 
> described any problems you have encountered.

There where no problems from the perspective of understanding what it 
did or how to use it.
It was just that auto generating of the decodetree seemed more then a 
simple task but a rather elaborated one, since we needed to identify 
common operand style instructions, group similar instruction conflicting 
encodings, etc. And when comparing to the ease of automating the 
creation of the decoding trees, seemed much more complex.

>
> The example is not especially enlightening because you don't show the 
> macro definitions, or the expansion.  Have you a link to a git repo 
> that you can share?
I do have. Please allow me a few days to properly clean it. Considering, 
I wanted to get your opinion before of a greater commitment to the 
solution, it is still in a prototype stage.

Cupertino

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] ARCv2: save ABI registers across signal handling

2021-06-09 Thread Vineet Gupta
ARCv2 has some configuration dependent registers (r30, r58, r59) which
could be targetted by the compiler. To keep the ABI stable, these were
unconditionally part of the glibc ABI
(sysdeps/unix/sysv/linux/arc/sys/ucontext.h:mcontext_t) however we
missed populating them (by saving/restoring them across signal
handling).

This patch fixes the issue by
 - adding arcv2 ABI regs to kernel struct sigcontext
 - populating them during signal handling

Change to struct sigcontext might seem like a glibc ABI change (although
it primarily uses ucontext_t:mcontext_t) but the fact is
 - it has only been extended (existing fields are not touched)
 - the old sigcontext was ABI incomplete to begin with anyways

Fixes: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/53
Cc: 
Reported-by: Vladimir Isaev 
Signed-off-by: Vineet Gupta 
---
 arch/arc/include/uapi/asm/sigcontext.h |  1 +
 arch/arc/kernel/signal.c   | 29 ++
 2 files changed, 30 insertions(+)

diff --git a/arch/arc/include/uapi/asm/sigcontext.h 
b/arch/arc/include/uapi/asm/sigcontext.h
index 95f8a4380e11..7a5449dfcb29 100644
--- a/arch/arc/include/uapi/asm/sigcontext.h
+++ b/arch/arc/include/uapi/asm/sigcontext.h
@@ -18,6 +18,7 @@
  */
 struct sigcontext {
struct user_regs_struct regs;
+   struct user_regs_arcv2 v2abi;
 };
 
 #endif /* _ASM_ARC_SIGCONTEXT_H */
diff --git a/arch/arc/kernel/signal.c b/arch/arc/kernel/signal.c
index b3ccb9e5ffe4..534b3d9bafc8 100644
--- a/arch/arc/kernel/signal.c
+++ b/arch/arc/kernel/signal.c
@@ -94,6 +94,21 @@ stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs 
*regs,
 
err = __copy_to_user(&(sf->uc.uc_mcontext.regs.scratch), &uregs.scratch,
 sizeof(sf->uc.uc_mcontext.regs.scratch));
+
+   if (is_isa_arcv2()) {
+   struct user_regs_arcv2 v2abi;
+
+   v2abi.r30 = regs->r30;
+#ifdef CONFIG_ARC_HAS_ACCL_REGS
+   v2abi.r58 = regs->r58;
+   v2abi.r59 = regs->r59;
+#else
+   v2abi.r58 = v2abi.r59 = 0;
+#endif
+   err |= __copy_to_user(&(sf->uc.uc_mcontext.v2abi), &v2abi,
+ sizeof(sf->uc.uc_mcontext.v2abi));
+   }
+
err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(sigset_t));
 
return err ? -EFAULT : 0;
@@ -109,6 +124,20 @@ static int restore_usr_regs(struct pt_regs *regs, struct 
rt_sigframe __user *sf)
err |= __copy_from_user(&uregs.scratch,
&(sf->uc.uc_mcontext.regs.scratch),
sizeof(sf->uc.uc_mcontext.regs.scratch));
+
+   if (is_isa_arcv2()) {
+   struct user_regs_arcv2 v2abi;
+
+   err |= __copy_from_user(&v2abi, &(sf->uc.uc_mcontext.v2abi),
+   sizeof(sf->uc.uc_mcontext.v2abi));
+
+   regs->r30 = v2abi.r30;
+#ifdef CONFIG_ARC_HAS_ACCL_REGS
+   regs->r58 = v2abi.r58;
+   regs->r59 = v2abi.r59;
+#endif
+   }
+
if (err)
return -EFAULT;
 
-- 
2.25.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH] ARC: fix CONFIG_HARDENED_USERCOPY

2021-06-09 Thread Vineet Gupta
Currently enabling this triggers a warning

| usercopy: Kernel memory overwrite attempt detected to kernel text (offset 
155633, size 11)!
| usercopy: BUG: failure at mm/usercopy.c:99/usercopy_abort()!
|
|gcc generated __builtin_trap
|Path: /bin/busybox
|CPU: 0 PID: 84 Comm: init Not tainted 5.4.22
|
|[ECR ]: 0x00090005 => gcc generated __builtin_trap
|[EFA ]: 0x9024fcaa
|[BLINK ]: usercopy_abort+0x8a/0x8c
|[ERET ]: memfd_fcntl+0x0/0x470
|[STAT32]: 0x80080802 : IE K
|BTA: 0x901ba38c SP: 0xbe161ecc FP: 0xbf9fe950
|LPS: 0x90677408 LPE: 0x9067740c LPC: 0x
|r00: 0x003c r01: 0xbf0ed280 r02: 0x
|r03: 0xbe15fa30 r04: 0x00d2803e r05: 0x
|r06: 0x675d7000 r07: 0x r08: 0x675d9c00
|r09: 0x r10: 0x035c r11: 0x61206572
|r12: 0x9024fcaa r13: 0x000b r14: 0x000b
|r15: 0x r16: 0x90169ffc r17: 0x90168000
|r18: 0x r19: 0xbf092010 r20: 0x0001
|r21: 0x0011 r22: 0x5ff1 r23: 0x90169ff1
|r24: 0xbe196c00 r25: 0xbf0ed280
|
|Stack Trace:
| memfd_fcntl+0x0/0x470
| usercopy_abort+0x8a/0x8c
| __check_object_size+0x10e/0x138
| copy_strings+0x1f4/0x38c
| __do_execve_file+0x352/0x848
| EV_Trap+0xcc/0xd0

Fixes: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/15
Reported-by: Evgeniy Didin 
Signed-off-by: Vineet Gupta 
---
 arch/arc/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
index 33ce59d91461..e2146a8da195 100644
--- a/arch/arc/kernel/vmlinux.lds.S
+++ b/arch/arc/kernel/vmlinux.lds.S
@@ -57,7 +57,6 @@ SECTIONS
.init.ramfs : { INIT_RAM_FS }
 
. = ALIGN(PAGE_SIZE);
-   _stext = .;
 
HEAD_TEXT_SECTION
INIT_TEXT_SECTION(L1_CACHE_BYTES)
@@ -83,6 +82,7 @@ SECTIONS
 
.text : {
_text = .;
+   _stext = .;
TEXT_TEXT
SCHED_TEXT
CPUIDLE_TEXT
-- 
2.25.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[linux-next:pending-fixes 265/302] arch/arc/kernel/signal.c:101:21: error: 'struct pt_regs' has no member named 'r30'; did you mean 'r10'?

2021-06-09 Thread kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 
pending-fixes
head:   2413b547bbb10e9b0d9da0e15040d2228ef17a76
commit: 98ec2edf58c820ef953fbdfcf98d706aa804b822 [265/302] ARCv2: save ABI 
registers across signal handling
config: arc-randconfig-r001-20210610 (attached as .config)
compiler: arceb-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=98ec2edf58c820ef953fbdfcf98d706aa804b822
git remote add linux-next 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
git fetch --no-tags linux-next pending-fixes
git checkout 98ec2edf58c820ef953fbdfcf98d706aa804b822
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   arch/arc/kernel/signal.c: In function 'stash_usr_regs':
>> arch/arc/kernel/signal.c:101:21: error: 'struct pt_regs' has no member named 
>> 'r30'; did you mean 'r10'?
 101 |   v2abi.r30 = regs->r30;
 | ^~~
 | r10
   arch/arc/kernel/signal.c: In function 'restore_usr_regs':
   arch/arc/kernel/signal.c:134:9: error: 'struct pt_regs' has no member named 
'r30'; did you mean 'r10'?
 134 |   regs->r30 = v2abi.r30;
 | ^~~
 | r10
   arch/arc/kernel/signal.c: At top level:
   arch/arc/kernel/signal.c:387:6: warning: no previous prototype for 
'do_signal' [-Wmissing-prototypes]
 387 | void do_signal(struct pt_regs *regs)
 |  ^
   arch/arc/kernel/signal.c:420:6: warning: no previous prototype for 
'do_notify_resume' [-Wmissing-prototypes]
 420 | void do_notify_resume(struct pt_regs *regs)
 |  ^~~~


vim +101 arch/arc/kernel/signal.c

63  
64  static int
65  stash_usr_regs(struct rt_sigframe __user *sf, struct pt_regs *regs,
66 sigset_t *set)
67  {
68  int err;
69  struct user_regs_struct uregs;
70  
71  uregs.scratch.bta   = regs->bta;
72  uregs.scratch.lp_start  = regs->lp_start;
73  uregs.scratch.lp_end= regs->lp_end;
74  uregs.scratch.lp_count  = regs->lp_count;
75  uregs.scratch.status32  = regs->status32;
76  uregs.scratch.ret   = regs->ret;
77  uregs.scratch.blink = regs->blink;
78  uregs.scratch.fp= regs->fp;
79  uregs.scratch.gp= regs->r26;
80  uregs.scratch.r12   = regs->r12;
81  uregs.scratch.r11   = regs->r11;
82  uregs.scratch.r10   = regs->r10;
83  uregs.scratch.r9= regs->r9;
84  uregs.scratch.r8= regs->r8;
85  uregs.scratch.r7= regs->r7;
86  uregs.scratch.r6= regs->r6;
87  uregs.scratch.r5= regs->r5;
88  uregs.scratch.r4= regs->r4;
89  uregs.scratch.r3= regs->r3;
90  uregs.scratch.r2= regs->r2;
91  uregs.scratch.r1= regs->r1;
92  uregs.scratch.r0= regs->r0;
93  uregs.scratch.sp= regs->sp;
94  
95  err = __copy_to_user(&(sf->uc.uc_mcontext.regs.scratch), 
&uregs.scratch,
96   sizeof(sf->uc.uc_mcontext.regs.scratch));
97  
98  if (is_isa_arcv2()) {
99  struct user_regs_arcv2 v2abi;
   100  
 > 101  v2abi.r30 = regs->r30;
   102  #ifdef CONFIG_ARC_HAS_ACCL_REGS
   103  v2abi.r58 = regs->r58;
   104  v2abi.r59 = regs->r59;
   105  #else
   106  v2abi.r58 = v2abi.r59 = 0;
   107  #endif
   108  err |= __copy_to_user(&(sf->uc.uc_mcontext.v2abi), 
&v2abi,
   109sizeof(sf->uc.uc_mcontext.v2abi));
   110  }
   111  
   112  err |= __copy_to_user(&sf->uc.uc_sigmask, set, 
sizeof(sigset_t));
   113  
   114  return err ? -EFAULT : 0;
   115  }
   116  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip
___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc