Re: [PATCH v6 00/13] glibc port to ARC processors

2020-05-14 Thread Vineet Gupta
On 5/4/20 2:21 PM, Vineet Gupta wrote:
> On 4/22/20 6:41 PM, Vineet Gupta wrote:
>> Hi,
>>
>> This patchset implements glibc port to ARC HS48x processor from Synopsys.
> 
> ping !

ping ^2

I have rebased and adjusted the v6 patch for semaphore header unification. Would
appreciate more technincal review.


> 
>>
>> This still needs a couple of inflight 64-time, offset patches.
>>
>> g...@github.com:foss-for-synopsys-dwc-arc-processors/glibc.git  upstream-v6
>>
>> v6:
>>* Dropped 11/14: merged upstream
>>* _FPU_SETS() inline asm reworked
>>* Introduce fixup-asm-unistd.h to elide 32-bit time, offset syscalls and
>>  regenerate arch-syscall.h
>>* Fix snafu in updating build-many-glibcs for ARC
>>* More code sytle fixes flagged by Joseph
>> v5:
>>* Big Endian formally supported as multi-ABI
>>* Removed code for ARC700 processors
>>* Hard-float code updates: fegetmode, fesetround, feupdateenv
>>* socket-constant.h update for 64-bit ABI spun off as standalone patch
>>* __syscall_error made glibc_private
>>* math ulps regen
>>* gmp-mparam.h removed
>>* lint fixes as flagged by Joseph
>> v4:
>>* Dropped 1/17: Merged upstream
>>* Dropped 17/17:
>>- 64-bit time/offset code chunked up into respective patches
>>* sysctl removed
>>* Updated README for arc gnu triplet
>>* Updated install files for ARC gcc/binutils requirements
>>* Updated NEWS with brief ISA/ABI info
>>
>> v3:
>>* Support for Hardware Floating Point
>>* 64-bit time and offsets ABI (although all such changes are confined
>>  to a single patch)
>>
>> v5: https://sourceware.org/pipermail/libc-alpha/2020-April/112657.html
>> v4: https://sourceware.org/pipermail/libc-alpha/2020-March/111855.html
>> v3: https://sourceware.org/legacy-ml/libc-alpha/2020-03/msg00167.html
>> v2: https://sourceware.org/legacy-ml/libc-alpha/2019-01/msg00681.html
>> v1: https://sourceware.org/legacy-ml/libc-alpha/2018-12/msg00678.html
>>
>> Documentation:
>> --
>>
>> (a) ABI doc:
>> https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/wiki/files/ARCv2_ABI.pdf
>>
>> (b) Programmer's Reference Manual (PRM) : needs a download request to be 
>> filled
>> https://www.synopsys.com/dw/ipdir.php?ds=arc-hs44-hs46-hs48
>> https://www.synopsys.com/dw/doc.php/ds/cc/programmers-reference-manual-ARC-HS.pdf
>>
>> Test Results:
>> --
>> (a) build-many-glibcs.py
>>
>> | Summary of test results:
>> |   1251 PASS
>> | 15 XFAIL
>>
>>
>> (b) Full testsuite ran in a cross compile setup using buildroot on HSDK 
>> development
>> platform. Bulk of failures come from cross testing setup and I
>> intend to improve things with native testing going forward.
>>
>> | Summary of test results:
>> | 30 FAIL   (-3)
>> |
>> | FAIL: csu/test-as-const-tcb-offsets
>> + FAIL: elf/tst-audit14
>> + FAIL: elf/tst-audit15
>> + FAIL: elf/tst-audit16
>> | FAIL: elf/tst-ldconfig-ld_so_conf-update # not true: dlopen
>> | FAIL: iconv/test-iconvconfig   # Needs gconv installed
>> - FAIL: iconv/tst-gconv-init-failure
>> | FAIL: io/ftwtest   # Requires execution by non-root
>> - FAIL: io/tst-futimesat
>> | FAIL: io/tst-lockf
>> | FAIL: libio/tst-wfile-sync
>> | FAIL: locale/tst-C-locale
>> | FAIL: locale/tst-duplocale
>> | FAIL: locale/tst-locale-locpath
>> | FAIL: locale/tst-locname
>> | FAIL: localedata/sort-test
>> | FAIL: nptl/test-cond-printers  # needs Python3 and target GDB 
>> on target
>> | FAIL: nptl/test-condattr-printers  #ditto
>> | FAIL: nptl/test-mutex-printers #ditto
>> | FAIL: nptl/test-mutexattr-printers #ditto
>> | FAIL: nptl/test-rwlock-printers#ditto
>> | FAIL: nptl/test-rwlockattr-printers#ditto
>> | FAIL: nptl/tst-umask1  # passes if run natively on 
>> target (NFS ACLv3 support needed)
>> | FAIL: nss/bug-erange
>> | FAIL: nss/tst-nss-files-hosts-getent   # Timed out
>> | FAIL: nss/tst-nss-files-hosts-multi# Timed out
>> | FAIL: posix/bug-ga2# DNS issue: google DNS vs. SNPS
>> | FAIL: posix/globtest   # require same user on target 
>> and host
>> | FAIL: posix/tst-getaddrinfo5   # passes outside corporate 
>> network
>> - FAIL: resolv/tst-resolv-basic
>> - FAIL: resolv/tst-resolv-edns
>> - FAIL: resolv/tst-resolv-rotate
>> - FAIL: resolv/tst-resolv-search
>> | FAIL: stdio-common/bug22   # Needs more RAM: 2 GB memory
>> | FAIL: sunrpc/bug20790  # missing cpp on target
>> | FAIL: timezone/tst-tzset   # passes outside corporate network
>>
>>
>> kindly review.
>>
>> Thx,
>> -Vineet
>>
>> Vineet Gupta (13):
>>   ARC: ABI Implementation
>>   ARC: startup and dynamic linking code
>>   ARC: Thread Local Storage support
>>   ARC: Atomics and Locking primitives
>>   ARC: math soft float support
>>   ARC: hardware floating point support
>>   ARC: Linux Syscall Interface
>>  

[PATCH v2 12/12] mm: consolidate pgd_index() and pgd_offset{_k}() definitions

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

All architectures tables define pgd_offset() as an entry in the array of
PGDs indexed by the pgd_index(), where pgd_index() is

(address >> PGD_SHIFT) & (PTRS_PER_PGD - 1)

For the most cases, the pgd_offset() uses mm->pgd as the pointer to the
top-level page directory and the pgd_offset_k() is a helper that presumes
that mm == &init_mm.

Use x86 implementation as the generic one and remove redundant definitions
of PGD accessors in most of arch/*/include/asm/pgtable.h

The generic implementation can be overridden by an architecture and this
ability is currently in use by there architectures:
* ia64 has custom implementation of pgd_index()
* s390 has custom definitions of all page table accessors

Signed-off-by: Mike Rapoport 
---
 arch/alpha/include/asm/pgtable.h |  9 
 arch/arc/include/asm/pgtable.h   |  7 ---
 arch/arm/include/asm/pgtable.h   |  8 
 arch/arm64/include/asm/pgtable.h | 10 
 arch/arm64/kernel/hibernate.c|  4 +-
 arch/arm64/mm/kasan_init.c   |  2 +-
 arch/arm64/mm/mmu.c  |  8 ++--
 arch/csky/include/asm/pgtable.h  | 11 -
 arch/hexagon/include/asm/pgtable.h   | 18 ---
 arch/ia64/include/asm/pgtable.h  | 14 +-
 arch/m68k/include/asm/mcf_pgtable.h  | 11 -
 arch/m68k/include/asm/motorola_pgtable.h | 16 ---
 arch/m68k/include/asm/sun3_pgtable.h |  9 
 arch/microblaze/include/asm/pgtable.h|  7 ---
 arch/mips/include/asm/pgtable-32.h   |  8 
 arch/mips/include/asm/pgtable-64.h   |  8 
 arch/nds32/include/asm/pgtable.h |  6 ---
 arch/nios2/include/asm/pgtable.h |  8 
 arch/openrisc/include/asm/pgtable.h  | 10 
 arch/parisc/include/asm/pgtable.h|  9 
 arch/powerpc/include/asm/book3s/32/pgtable.h |  7 ---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 13 -
 arch/powerpc/include/asm/nohash/32/pgtable.h |  7 ---
 arch/powerpc/include/asm/nohash/64/pgtable.h | 12 -
 arch/riscv/include/asm/pgtable.h | 10 
 arch/riscv/mm/init.c | 12 ++---
 arch/s390/include/asm/pgtable.h  |  1 -
 arch/sh/include/asm/pgtable_32.h |  7 ---
 arch/sh/include/asm/pgtable_64.h | 11 -
 arch/sparc/include/asm/pgtable_32.h  |  8 
 arch/sparc/include/asm/pgtable_64.h  |  7 ---
 arch/um/include/asm/pgtable.h| 50 ++--
 arch/unicore32/include/asm/pgtable.h |  8 
 arch/x86/include/asm/pgtable.h   | 24 --
 arch/xtensa/include/asm/pgtable.h|  8 
 include/linux/pgtable.h  | 26 ++
 36 files changed, 55 insertions(+), 339 deletions(-)

diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
index 314973d2810d..162c17b2631f 100644
--- a/arch/alpha/include/asm/pgtable.h
+++ b/arch/alpha/include/asm/pgtable.h
@@ -276,15 +276,6 @@ extern inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) 
&= ~_PAGE_FOW; return
 extern inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= __DIRTY_BITS; 
return pte; }
 extern inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= 
__ACCESS_BITS; return pte; }
 
-#define PAGE_DIR_OFFSET(tsk,address) pgd_offset((tsk),(address))
-
-/* to find an entry in a kernel page-table-directory */
-#define pgd_offset_k(address) pgd_offset(&init_mm, (address))
-
-/* to find an entry in a page-table-directory. */
-#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
-#define pgd_offset(mm, address)((mm)->pgd+pgd_index(address))
-
 /*
  * The smp_read_barrier_depends() in the following functions are required to
  * order the load of *dir (the pointer in the top level page table) with any
diff --git a/arch/arc/include/asm/pgtable.h b/arch/arc/include/asm/pgtable.h
index 1146905f594b..f1ed17edb085 100644
--- a/arch/arc/include/asm/pgtable.h
+++ b/arch/arc/include/asm/pgtable.h
@@ -316,13 +316,6 @@ static inline void set_pte_at(struct mm_struct *mm, 
unsigned long addr,
set_pte(ptep, pteval);
 }
 
-/*
- * All kernel related VM pages are in init's mm.
- */
-#define pgd_offset_k(address)  pgd_offset(&init_mm, address)
-#define pgd_index(addr)((addr) >> PGDIR_SHIFT)
-#define pgd_offset(mm, addr)   (((mm)->pgd)+pgd_index(addr))
-
 /*
  * Macro to quickly access the PGD entry, utlising the fact that some
  * arch may cache the pointer to Page Directory of "current" task
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index 41543bc47660..c02f24400369 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -166,14 +166,6 @@ extern struct page *empty_zero_page;
 
 extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 
-/* to find an entry in a page-table-directory */
-#define pgd_index(addr

[PATCH v2 10/12] mm: consolidate pmd_index() and pmd_offset() definitions

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

All architectures define pmd_index() as

(address >> PMD_SHIFT) & (PTRS_PER_PMD - 1)

and all architectures that have at least three-level page tables define
pmd_offset() as an entry in the array of PMDs indexed by the pmd_index().

For the most architectures the pmd_offset() implementation relies on
the availability of pud_page_vaddr() that converts a PMD entry value to the
virtual address of the page containing PMD array.

Let's use such implementation as a generic and drop most of the definitions
of pmd_index() and pmd_offset() in  files.

The architectures that didn't provide pud_page_vaddr() are updated to
have that defined.

The generic implementation can be overridden by an architecture and this
ability is currently in use by there architectures:
* alpha has special requirements for memory access ordering
* arm has custom definition of folded 2-level page tables
* s390 has custom definitions of all page table accessors

Signed-off-by: Mike Rapoport 
---
 arch/alpha/include/asm/pgtable.h |  1 +
 arch/arm/include/asm/pgtable-2level.h|  1 +
 arch/arm/include/asm/pgtable-3level.h|  7 -
 arch/arm/include/asm/pgtable-nommu.h |  1 -
 arch/arm64/include/asm/pgtable.h |  8 --
 arch/c6x/include/asm/pgtable.h   |  1 -
 arch/csky/include/asm/pgtable.h  |  1 -
 arch/hexagon/include/asm/pgtable.h   |  9 --
 arch/ia64/include/asm/pgtable.h  |  4 ---
 arch/m68k/include/asm/motorola_pgtable.h |  7 -
 arch/microblaze/include/asm/pgtable.h|  1 -
 arch/mips/include/asm/pgtable-32.h   |  1 -
 arch/mips/include/asm/pgtable-64.h   |  6 
 arch/parisc/include/asm/pgtable.h|  8 --
 arch/parisc/kernel/pci-dma.c |  2 +-
 arch/powerpc/include/asm/book3s/64/pgtable.h |  3 --
 arch/powerpc/include/asm/nohash/64/pgtable.h |  3 --
 arch/riscv/include/asm/pgtable-64.h  |  7 -
 arch/riscv/mm/init.c | 12 
 arch/s390/include/asm/pgtable.h  |  1 +
 arch/sh/include/asm/pgtable-3level.h |  7 -
 arch/sh/include/asm/pgtable_32.h |  1 -
 arch/sh/include/asm/pgtable_64.h |  1 -
 arch/sparc/include/asm/pgtable_32.h  |  9 +-
 arch/sparc/include/asm/pgtable_64.h  |  7 +
 arch/um/include/asm/pgtable-3level.h |  4 ---
 arch/um/include/asm/pgtable.h|  4 ---
 arch/x86/include/asm/pgtable.h   | 17 
 include/asm-generic/pgtable-nopmd.h  |  1 +
 include/linux/pgtable.h  | 29 ++--
 30 files changed, 44 insertions(+), 120 deletions(-)

diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
index dac20d03b727..314973d2810d 100644
--- a/arch/alpha/include/asm/pgtable.h
+++ b/arch/alpha/include/asm/pgtable.h
@@ -305,6 +305,7 @@ extern inline pmd_t * pmd_offset(pud_t * dir, unsigned long 
address)
smp_read_barrier_depends(); /* see above */
return ret;
 }
+#define pmd_offset pmd_offset
 
 /* Find an entry in the third-level page table.. */
 extern inline pte_t * pte_offset_kernel(pmd_t * dir, unsigned long address)
diff --git a/arch/arm/include/asm/pgtable-2level.h 
b/arch/arm/include/asm/pgtable-2level.h
index 9e084a464a97..3502c2f746ca 100644
--- a/arch/arm/include/asm/pgtable-2level.h
+++ b/arch/arm/include/asm/pgtable-2level.h
@@ -187,6 +187,7 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long 
addr)
 {
return (pmd_t *)pud;
 }
+#define pmd_offset pmd_offset
 
 #define pmd_large(pmd) (pmd_val(pmd) & 2)
 #define pmd_leaf(pmd)  (pmd_val(pmd) & 2)
diff --git a/arch/arm/include/asm/pgtable-3level.h 
b/arch/arm/include/asm/pgtable-3level.h
index 1933aed9f68d..fbb6693c3352 100644
--- a/arch/arm/include/asm/pgtable-3level.h
+++ b/arch/arm/include/asm/pgtable-3level.h
@@ -133,13 +133,6 @@ static inline pmd_t *pud_page_vaddr(pud_t pud)
return __va(pud_val(pud) & PHYS_MASK & (s32)PAGE_MASK);
 }
 
-/* Find an entry in the second-level page table.. */
-#define pmd_index(addr)(((addr) >> PMD_SHIFT) & (PTRS_PER_PMD 
- 1))
-static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
-{
-   return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(addr);
-}
-
 #define pmd_bad(pmd)   (!(pmd_val(pmd) & 2))
 
 #define copy_pmd(pmdpd,pmdps)  \
diff --git a/arch/arm/include/asm/pgtable-nommu.h 
b/arch/arm/include/asm/pgtable-nommu.h
index 1a758f14e0c3..d16aba48fa0a 100644
--- a/arch/arm/include/asm/pgtable-nommu.h
+++ b/arch/arm/include/asm/pgtable-nommu.h
@@ -22,7 +22,6 @@
 #define pgd_bad(pgd)   (0)
 #define pgd_clear(pgdp)
 #define kern_addr_valid(addr)  (1)
-#definepmd_offset(a, b)((void *)0)
 /* FIXME */
 /*
  * PMD_SHIFT determines the size of the area a second-level page table can map
diff --git a/arch/arm64/include/asm/pgtable.h 

[PATCH v2 11/12] mm: consolidate pud_index() and pud_offset() definitions

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

All architectures that have at least four-level page tables define
pud_offset() as an entry in the array of PUDs indexed by the pud_index(),
where pud_index() is

(address >> PUD_SHIFT) & (PTRS_PER_PUD - 1)

For the most architectures the pud_offset() implementation relies on
the availability of pud_page_vaddr() that converts a PUD entry value to the
virtual address of the page containing PUD array.

Let's use such implementation as a generic and drop most of the definitions
of pud_index() and pud_offset() in  files.

The architectures that didn't provide pud_page_vaddr() are updated to
have that defined.

The generic implementation can be overridden by an architecture and this
ability is currently in use by there architectures:
* s390 has custom definitions of all page table accessors

Signed-off-by: Mike Rapoport 
---
 arch/arm64/include/asm/pgtable.h|  8 +---
 arch/csky/include/asm/pgtable.h |  2 --
 arch/ia64/include/asm/pgtable.h |  6 --
 arch/mips/include/asm/pgtable-32.h  |  1 -
 arch/mips/include/asm/pgtable-64.h  |  7 ---
 arch/powerpc/include/asm/book3s/64/pgtable.h|  4 
 arch/powerpc/include/asm/nohash/64/pgtable-4k.h |  4 
 arch/s390/include/asm/pgtable.h |  1 +
 arch/sh/include/asm/pgtable_32.h|  2 --
 arch/sh/include/asm/pgtable_64.h|  2 --
 arch/sparc/include/asm/pgtable_64.h |  5 -
 arch/x86/include/asm/pgtable.h  | 11 ---
 include/asm-generic/pgtable-nopud.h |  1 +
 include/linux/pgtable.h | 16 
 14 files changed, 23 insertions(+), 47 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index d0175335a2f2..c0155814b374 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -626,11 +626,13 @@ static inline phys_addr_t p4d_page_paddr(p4d_t p4d)
return __p4d_to_phys(p4d);
 }
 
-/* Find an entry in the frst-level page table. */
-#define pud_index(addr)(((addr) >> PUD_SHIFT) & (PTRS_PER_PUD 
- 1))
+static inline unsigned long p4d_page_vaddr(p4d_t p4d)
+{
+   return (unsigned long)__va(p4d_page_paddr(p4d));
+}
 
+/* Find an entry in the frst-level page table. */
 #define pud_offset_phys(dir, addr) (p4d_page_paddr(READ_ONCE(*(dir))) + 
pud_index(addr) * sizeof(pud_t))
-#define pud_offset(dir, addr)  ((pud_t *)__va(pud_offset_phys((dir), 
(addr
 
 #define pud_set_fixmap(addr)   ((pud_t *)set_fixmap_offset(FIX_PUD, 
addr))
 #define pud_set_fixmap_offset(p4d, addr)   
pud_set_fixmap(pud_offset_phys(p4d, addr))
diff --git a/arch/csky/include/asm/pgtable.h b/arch/csky/include/asm/pgtable.h
index dc613f20e2e1..c5ab20970857 100644
--- a/arch/csky/include/asm/pgtable.h
+++ b/arch/csky/include/asm/pgtable.h
@@ -220,8 +220,6 @@ static inline pte_t pte_mkyoung(pte_t pte)
return pte;
 }
 
-#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
-
 /* to find an entry in a kernel page-table-directory */
 #define pgd_offset_k(address)  pgd_offset(&init_mm, address)
 
diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
index d75d981e6ee1..4c24e5e18bff 100644
--- a/arch/ia64/include/asm/pgtable.h
+++ b/arch/ia64/include/asm/pgtable.h
@@ -383,12 +383,6 @@ pgd_offset (const struct mm_struct *mm, unsigned long 
address)
here.  */
 #define pgd_offset_gate(mm, addr)  pgd_offset_k(addr)
 
-#if CONFIG_PGTABLE_LEVELS == 4
-/* Find an entry in the second-level page table.. */
-#define pud_offset(dir,addr) \
-   ((pud_t *) p4d_page_vaddr(*(dir)) + (((addr) >> PUD_SHIFT) & 
(PTRS_PER_PUD - 1)))
-#endif
-
 /* atomic versions of the some PTE manipulations: */
 
 static inline int
diff --git a/arch/mips/include/asm/pgtable-32.h 
b/arch/mips/include/asm/pgtable-32.h
index 05b51c344939..9c0e7a5ffc75 100644
--- a/arch/mips/include/asm/pgtable-32.h
+++ b/arch/mips/include/asm/pgtable-32.h
@@ -199,7 +199,6 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t 
prot)
 #define pgd_offset_k(address) pgd_offset(&init_mm, address)
 
 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
-#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
 
 /* to find an entry in a page-table-directory */
 #define pgd_offset(mm, addr)   ((mm)->pgd + pgd_index(addr))
diff --git a/arch/mips/include/asm/pgtable-64.h 
b/arch/mips/include/asm/pgtable-64.h
index 21fb55510d35..38170fdac5bf 100644
--- a/arch/mips/include/asm/pgtable-64.h
+++ b/arch/mips/include/asm/pgtable-64.h
@@ -172,8 +172,6 @@
 
 extern pte_t invalid_pte_table[PTRS_PER_PTE];
 
-#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
-
 #ifndef __PAGETABLE_PUD_FOLDED
 /*
  * For 4-level pagetables we defines these ourselves, for 3-level the
@@ -222,11 +220,

[PATCH v2 08/12] mm: pgtable: add shortcuts for accessing kernel PMD and PTE

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

The powerpc 32-bit implementation of pgtable has nice shortcuts for
accessing kernel PMD and PTE for a given virtual address.
Make this helpers available for all architectures.

Signed-off-by: Mike Rapoport 
---
 arch/arc/mm/highmem.c | 10 +---
 arch/arm/mach-sa1100/assabet.c|  2 +-
 arch/arm/mm/highmem.c |  4 ++--
 arch/arm/mm/ioremap.c | 31 
 arch/arm/mm/mm.h  |  5 
 arch/arm/mm/mmu.c |  7 +-
 arch/hexagon/include/asm/fixmap.h |  4 
 arch/m68k/mm/motorola.c   | 26 
 arch/microblaze/kernel/signal.c   |  8 +--
 arch/microblaze/mm/init.c |  9 ---
 arch/mips/include/asm/fixmap.h|  3 ---
 arch/mips/mm/c-r3k.c  | 10 ++--
 arch/mips/mm/c-r4k.c  | 10 ++--
 arch/mips/mm/c-tx39.c | 10 ++--
 arch/mips/mm/highmem.c|  2 +-
 arch/nds32/include/asm/pgtable.h  |  2 --
 arch/nds32/mm/init.c  | 13 ++
 arch/nds32/mm/proc.c  |  6 +
 arch/parisc/mm/fixmap.c   |  6 +
 arch/powerpc/include/asm/pgtable.h| 19 ---
 arch/powerpc/mm/book3s32/mmu.c|  2 +-
 arch/powerpc/mm/book3s32/tlb.c|  4 ++--
 arch/powerpc/mm/kasan/kasan_init_32.c |  8 +++
 arch/powerpc/mm/nohash/40x.c  |  4 ++--
 arch/powerpc/mm/pgtable_32.c  |  2 +-
 arch/s390/mm/pageattr.c   | 10 +---
 arch/sh/mm/cache-sh4.c|  8 +--
 arch/sh/mm/kmap.c |  5 +---
 arch/sparc/mm/highmem.c   | 12 ++
 arch/sparc/mm/init_64.c   |  6 +
 arch/sparc/mm/io-unit.c   | 10 ++--
 arch/sparc/mm/iommu.c |  8 +--
 arch/sparc/mm/srmmu.c | 34 +++
 arch/um/kernel/mem.c  | 10 +---
 arch/um/kernel/trap.c |  8 +--
 arch/unicore32/mm/mm.h| 10 
 arch/x86/mm/init_32.c | 26 +++-
 arch/xtensa/include/asm/fixmap.h  |  8 ---
 arch/xtensa/mm/highmem.c  |  2 +-
 arch/xtensa/mm/kasan_init.c   | 10 ++--
 arch/xtensa/mm/mmu.c  |  5 +---
 include/linux/pgtable.h   | 24 +++
 42 files changed, 80 insertions(+), 323 deletions(-)

diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c
index d6b74883fd1f..1b9f473c6369 100644
--- a/arch/arc/mm/highmem.c
+++ b/arch/arc/mm/highmem.c
@@ -92,17 +92,9 @@ EXPORT_SYMBOL(kunmap_atomic_high);
 
 static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
 {
-   pgd_t *pgd_k;
-   p4d_t *p4d_k;
-   pud_t *pud_k;
-   pmd_t *pmd_k;
+   pmd_t *pmd_k = pmd_off_k(kvaddr);
pte_t *pte_k;
 
-   pgd_k = pgd_offset_k(kvaddr);
-   p4d_k = p4d_offset(pgd_k, kvaddr);
-   pud_k = pud_offset(p4d_k, kvaddr);
-   pmd_k = pmd_offset(pud_k, kvaddr);
-
pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
if (!pte_k)
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
diff --git a/arch/arm/mach-sa1100/assabet.c b/arch/arm/mach-sa1100/assabet.c
index 8e3f5fdb4883..aa265ede5730 100644
--- a/arch/arm/mach-sa1100/assabet.c
+++ b/arch/arm/mach-sa1100/assabet.c
@@ -632,7 +632,7 @@ static void __init map_sa1100_gpio_regs( void )
int prot = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_DOMAIN(DOMAIN_IO);
pmd_t *pmd;
 
-   pmd = pmd_offset(pud_offset(p4d_offset(pgd_offset_k(virt), virt), 
virt), virt);
+   pmd = pmd_off_k(virt);
*pmd = __pmd(phys | prot);
flush_pmd_entry(pmd);
 }
diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c
index e013f6b81328..187fab227b50 100644
--- a/arch/arm/mm/highmem.c
+++ b/arch/arm/mm/highmem.c
@@ -18,7 +18,7 @@
 static inline void set_fixmap_pte(int idx, pte_t pte)
 {
unsigned long vaddr = __fix_to_virt(idx);
-   pte_t *ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
+   pte_t *ptep = virt_to_kpte(vaddr);
 
set_pte_ext(ptep, pte, 0);
local_flush_tlb_kernel_page(vaddr);
@@ -26,7 +26,7 @@ static inline void set_fixmap_pte(int idx, pte_t pte)
 
 static inline pte_t get_fixmap_pte(unsigned long vaddr)
 {
-   pte_t *ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
+   pte_t *ptep = virt_to_kpte(vaddr);
 
return *ptep;
 }
diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
index 75529d76d28c..000e821b 100644
--- a/arch/arm/mm/ioremap.c
+++ b/arch/arm/mm/ioremap.c
@@ -141,16 +141,8 @@ void __check_vmalloc_seq(struct mm_struct *mm)
 static void unmap_area_sections(unsigned long virt, unsigned long size)
 {
unsigned long addr = virt, end = virt + (size & ~(SZ_1M - 1));
-   pgd_t *pgd;
-   p4d_t *p4d;
-   pud_t *pud;
-  

[PATCH v2 09/12] mm: consolidate pte_index() and pte_offset_*() definitions

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

All architectures define pte_index() as

(address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)

and all architectures define pte_offset_kernel() as an entry
in the array of PTEs indexed by the pte_index().

For the most architectures the pte_offset_kernel() implementation relies on
the availability of pmd_page_vaddr() that converts a PMD entry value to the
virtual address of the page containing PTEs array.

Let's move x86 definitions of the PTE accessors to the generic place in
 and then simply drop the respective definitions from the
other architectures.

The architectures that didn't provide pmd_page_vaddr() are updated to have
that defined.

The generic implementation of pte_offset_kernel() can be overridden by an
architecture and alpha makes use of this because it has special ordering
requirements for its version of pte_offset_kernel().

Signed-off-by: Mike Rapoport 
---
 arch/alpha/include/asm/pgtable.h |  4 +--
 arch/arc/include/asm/pgtable.h   | 15 --
 arch/arm/include/asm/pgtable.h   | 15 --
 arch/arm64/include/asm/pgtable.h | 10 +++
 arch/csky/include/asm/pgtable.h  | 16 ---
 arch/hexagon/include/asm/pgtable.h   | 25 +++--
 arch/ia64/include/asm/pgtable.h  |  9 --
 arch/m68k/include/asm/mcf_pgtable.h  | 12 +---
 arch/m68k/include/asm/motorola_pgalloc.h |  2 +-
 arch/m68k/include/asm/motorola_pgtable.h | 11 +---
 arch/m68k/include/asm/sun3_pgtable.h | 15 --
 arch/m68k/mm/init.c  |  2 +-
 arch/microblaze/include/asm/pgtable.h| 13 +++--
 arch/mips/include/asm/pgtable-32.h   | 12 
 arch/mips/include/asm/pgtable-64.h   | 11 
 arch/mips/kvm/mmu.c  | 20 +++---
 arch/mips/kvm/trap_emul.c|  2 +-
 arch/nds32/include/asm/pgtable.h | 12 +++-
 arch/nios2/include/asm/pgtable.h | 14 +++---
 arch/openrisc/include/asm/pgtable.h  | 23 
 arch/parisc/include/asm/pgtable.h| 15 +++---
 arch/powerpc/include/asm/book3s/32/pgtable.h | 13 ++---
 arch/powerpc/include/asm/book3s/64/pgtable.h |  8 --
 arch/powerpc/include/asm/nohash/32/pgtable.h | 13 ++---
 arch/powerpc/include/asm/nohash/64/pgtable.h |  7 -
 arch/powerpc/include/asm/pgtable.h   |  7 +
 arch/riscv/include/asm/pgtable.h | 10 ---
 arch/riscv/mm/init.c |  6 ++--
 arch/s390/include/asm/pgtable.h  | 10 ++-
 arch/s390/mm/pageattr.c  |  2 +-
 arch/sh/include/asm/pgtable_32.h | 15 --
 arch/sh/include/asm/pgtable_64.h | 12 
 arch/sparc/include/asm/pgalloc_64.h  |  2 +-
 arch/sparc/include/asm/pgtable_32.h  | 15 --
 arch/sparc/include/asm/pgtable_64.h  | 12 ++--
 arch/sparc/mm/srmmu.c| 10 ---
 arch/um/include/asm/pgtable.h| 13 -
 arch/unicore32/include/asm/pgtable.h |  9 --
 arch/x86/include/asm/pgtable.h   | 19 -
 arch/x86/include/asm/pgtable_32.h| 11 
 arch/x86/include/asm/pgtable_64.h|  4 ---
 arch/xtensa/include/asm/pgtable.h| 10 +--
 include/linux/pgtable.h  | 29 
 43 files changed, 113 insertions(+), 382 deletions(-)

diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
index 1c263922beb3..dac20d03b727 100644
--- a/arch/alpha/include/asm/pgtable.h
+++ b/arch/alpha/include/asm/pgtable.h
@@ -314,9 +314,7 @@ extern inline pte_t * pte_offset_kernel(pmd_t * dir, 
unsigned long address)
smp_read_barrier_depends(); /* see above */
return ret;
 }
-
-#define pte_offset_map(dir,addr)   pte_offset_kernel((dir),(addr))
-#define pte_unmap(pte) do { } while (0)
+#define pte_offset_kernel pte_offset_kernel
 
 extern pgd_t swapper_pg_dir[1024];
 
diff --git a/arch/arc/include/asm/pgtable.h b/arch/arc/include/asm/pgtable.h
index 29137bcedd93..1146905f594b 100644
--- a/arch/arc/include/asm/pgtable.h
+++ b/arch/arc/include/asm/pgtable.h
@@ -248,9 +248,6 @@
 extern char empty_zero_page[PAGE_SIZE];
 #define ZERO_PAGE(vaddr)   (virt_to_page(empty_zero_page))
 
-#define pte_unmap(pte) do { } while (0)
-#define pte_unmap_nested(pte)  do { } while (0)
-
 #define set_pte(pteptr, pteval)((*(pteptr)) = (pteval))
 #define set_pmd(pmdptr, pmdval)(*(pmdptr) = pmdval)
 
@@ -282,18 +279,6 @@ static inline void pmd_set(pmd_t *pmdp, pte_t *ptep)
 
 /* Don't use virt_to_pfn for macros below: could cause truncations for PAE40*/
 #define pte_pfn(pte)   (pte_val(pte) >> PAGE_SHIFT)
-#define __pte_index(addr)  (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
-
-/*
- * pte_offs

[PATCH v2 07/12] x86/mm: simplify init_trampoline() and surrounding logic

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

There are three cases for the trampoline initialization:
* 32-bit does nothing
* 64-bit with kaslr disabled simply copies a PGD entry from the direct map
  to the trampoline PGD
* 64-bit with kaslr enabled maps the real mode trampoline at PUD level

These cases are currently differentiated by a bunch of ifdefs inside
asm/include/pgtable.h and the case of 64-bits with kaslr on uses
pgd_index() helper.

Replacing the ifdefs with a static function in arch/x86/mm/init.c gives
clearer code and allows moving pgd_index() to the generic implementation in
include/linux/pgtable.h

Signed-off-by: Mike Rapoport 
---
 arch/x86/include/asm/kaslr.h   |  2 ++
 arch/x86/include/asm/pgtable.h | 15 +--
 arch/x86/include/asm/setup.h   |  9 +
 arch/x86/mm/init.c | 22 ++
 arch/x86/mm/kaslr.c| 33 +
 5 files changed, 35 insertions(+), 46 deletions(-)

diff --git a/arch/x86/include/asm/kaslr.h b/arch/x86/include/asm/kaslr.h
index db7ba2feb947..0648190467ba 100644
--- a/arch/x86/include/asm/kaslr.h
+++ b/arch/x86/include/asm/kaslr.h
@@ -6,8 +6,10 @@ unsigned long kaslr_get_random_long(const char *purpose);
 
 #ifdef CONFIG_RANDOMIZE_MEMORY
 void kernel_randomize_memory(void);
+void init_trampoline_kaslr(void);
 #else
 static inline void kernel_randomize_memory(void) { }
+static inline void init_trampoline_kaslr(void) {}
 #endif /* CONFIG_RANDOMIZE_MEMORY */
 
 #endif
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index d24f8e1f7250..6366136b0e46 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -1070,27 +1070,14 @@ void init_mem_mapping(void);
 void early_alloc_pgt_buf(void);
 extern void memblock_find_dma_reserve(void);
 
+
 #ifdef CONFIG_X86_64
-/* Realmode trampoline initialization. */
 extern pgd_t trampoline_pgd_entry;
-static inline void __meminit init_trampoline_default(void)
-{
-   /* Default trampoline pgd value */
-   trampoline_pgd_entry = init_top_pgt[pgd_index(__PAGE_OFFSET)];
-}
 
 void __init poking_init(void);
 
 unsigned long init_memory_mapping(unsigned long start,
  unsigned long end, pgprot_t prot);
-
-# ifdef CONFIG_RANDOMIZE_MEMORY
-void __meminit init_trampoline(void);
-# else
-#  define init_trampoline init_trampoline_default
-# endif
-#else
-static inline void init_trampoline(void) { }
 #endif
 
 /* local pte updates need not use xchg for locking */
diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
index ed8ec011a9fd..d95cacf210bb 100644
--- a/arch/x86/include/asm/setup.h
+++ b/arch/x86/include/asm/setup.h
@@ -78,6 +78,15 @@ static inline bool kaslr_enabled(void)
return !!(boot_params.hdr.loadflags & KASLR_FLAG);
 }
 
+/*
+ * Apply no randomization if KASLR was disabled at boot or if KASAN
+ * is enabled. KASAN shadow mappings rely on regions being PGD aligned.
+ */
+static inline bool kaslr_memory_enabled(void)
+{
+   return kaslr_enabled() && !IS_ENABLED(CONFIG_KASAN);
+}
+
 static inline unsigned long kaslr_offset(void)
 {
return (unsigned long)&_text - __START_KERNEL;
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 235dd0e35741..e225ebb25197 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -682,6 +682,28 @@ static void __init memory_map_bottom_up(unsigned long 
map_start,
}
 }
 
+/*
+ * The real mode trampoline, which is required for bootstrapping CPUs
+ * occupies only a small area under the low 1MB.  See reserve_real_mode()
+ * for details.
+ *
+ * If KASLR is disabled the first PGD entry of the direct mapping is copied
+ * to map the real mode trampoline.
+ *
+ * If KASLR is enabled, copy only the PUD which covers the low 1MB
+ * area. This limits the randomization granularity to 1GB for both 4-level
+ * and 5-level paging.
+ */
+static void __init init_trampoline(void)
+{
+#ifdef CONFIG_X86_64
+   if (!kaslr_memory_enabled())
+   trampoline_pgd_entry = init_top_pgt[pgd_index(__PAGE_OFFSET)];
+   else
+   init_trampoline_kaslr();
+#endif
+}
+
 void __init init_mem_mapping(void)
 {
unsigned long end;
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index faf02e1e1517..fb620fd9dae9 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -61,15 +61,6 @@ static inline unsigned long get_padding(struct 
kaslr_memory_region *region)
return (region->size_tb << TB_SHIFT);
 }
 
-/*
- * Apply no randomization if KASLR was disabled at boot or if KASAN
- * is enabled. KASAN shadow mappings rely on regions being PGD aligned.
- */
-static inline bool kaslr_memory_enabled(void)
-{
-   return kaslr_enabled() && !IS_ENABLED(CONFIG_KASAN);
-}
-
 /* Initialize base and padding for each memory region randomized with KASLR */
 void __init kernel_randomize_memory(void)
 {
@@ -148,7 +139,7 @@ void __init kernel_randomize_memory(void)
}
 }
 
-static void __meminit 

[PATCH v2 05/12] m68k/mm/motorola: move comment about page table allocation funcitons

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

The comment about page table allocation functions resides in
include/asm/motorola_pgtable.h while the functions live in
include/asm/motorola_pgaloc.h.

Move the comment close to the code.

Signed-off-by: Mike Rapoport 
---
 arch/m68k/include/asm/motorola_pgalloc.h | 6 ++
 arch/m68k/include/asm/motorola_pgtable.h | 6 --
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/m68k/include/asm/motorola_pgalloc.h 
b/arch/m68k/include/asm/motorola_pgalloc.h
index c66e42917912..f3cb453a07b7 100644
--- a/arch/m68k/include/asm/motorola_pgalloc.h
+++ b/arch/m68k/include/asm/motorola_pgalloc.h
@@ -18,6 +18,12 @@ extern void init_pointer_table(void *table, int type);
 extern void *get_pointer_table(int type);
 extern int free_pointer_table(void *table, int type);
 
+/*
+ * Allocate and free page tables. The xxx_kernel() versions are
+ * used to allocate a kernel page table - this turns on ASN bits
+ * if any.
+ */
+
 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
 {
return get_pointer_table(TABLE_PTE);
diff --git a/arch/m68k/include/asm/motorola_pgtable.h 
b/arch/m68k/include/asm/motorola_pgtable.h
index 48f19f0ab1e7..9e5a3de21e15 100644
--- a/arch/m68k/include/asm/motorola_pgtable.h
+++ b/arch/m68k/include/asm/motorola_pgtable.h
@@ -227,12 +227,6 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmdp, 
unsigned long address)
 #define pte_offset_map(pmdp,address) ((pte_t *)__pmd_page(*pmdp) + (((address) 
>> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
 #define pte_unmap(pte) ((void)0)
 
-/*
- * Allocate and free page tables. The xxx_kernel() versions are
- * used to allocate a kernel page table - this turns on ASN bits
- * if any.
- */
-
 /* Prior to calling these routines, the page should have been flushed
  * from both the cache and ATC, or the CPU might not notice that the
  * cache setting for the page has been changed. -jskov
-- 
2.26.2


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


[PATCH v2 06/12] m68k/mm: move {cache, nocahe}_page() definitions close to their user

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

The cache_page() and nocache_page() functions are only used by the motorola
MMU variant for setting caching attributes for the page table pages.

Move the definitions of these functions from
arch/m68k/include/asm/motorola_pgtable.h closer to their usage in
arch/m68k/mm/motorola.c and drop unused definition in
arch/m68k/include/asm/mcf_pgtable.h.

Signed-off-by: Mike Rapoport 
Acked-by: Greg Ungerer 
---
 arch/m68k/include/asm/mcf_pgtable.h  | 40 -
 arch/m68k/include/asm/motorola_pgtable.h | 44 
 arch/m68k/mm/motorola.c  | 43 +++
 3 files changed, 43 insertions(+), 84 deletions(-)

diff --git a/arch/m68k/include/asm/mcf_pgtable.h 
b/arch/m68k/include/asm/mcf_pgtable.h
index 0031cd387b75..737e826294f3 100644
--- a/arch/m68k/include/asm/mcf_pgtable.h
+++ b/arch/m68k/include/asm/mcf_pgtable.h
@@ -328,46 +328,6 @@ extern pgd_t kernel_pg_dir[PTRS_PER_PGD];
 #define pte_offset_kernel(dir, address) \
((pte_t *) __pmd_page(*(dir)) + __pte_offset(address))
 
-/*
- * Disable caching for page at given kernel virtual address.
- */
-static inline void nocache_page(void *vaddr)
-{
-   pgd_t *dir;
-   p4d_t *p4dp;
-   pud_t *pudp;
-   pmd_t *pmdp;
-   pte_t *ptep;
-   unsigned long addr = (unsigned long) vaddr;
-
-   dir = pgd_offset_k(addr);
-   p4dp = p4d_offset(dir, addr);
-   pudp = pud_offset(p4dp, addr);
-   pmdp = pmd_offset(pudp, addr);
-   ptep = pte_offset_kernel(pmdp, addr);
-   *ptep = pte_mknocache(*ptep);
-}
-
-/*
- * Enable caching for page at given kernel virtual address.
- */
-static inline void cache_page(void *vaddr)
-{
-   pgd_t *dir;
-   p4d_t *p4dp;
-   pud_t *pudp;
-   pmd_t *pmdp;
-   pte_t *ptep;
-   unsigned long addr = (unsigned long) vaddr;
-
-   dir = pgd_offset_k(addr);
-   p4dp = p4d_offset(dir, addr);
-   pudp = pud_offset(p4dp, addr);
-   pmdp = pmd_offset(pudp, addr);
-   ptep = pte_offset_kernel(pmdp, addr);
-   *ptep = pte_mkcache(*ptep);
-}
-
 /*
  * Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e))
  */
diff --git a/arch/m68k/include/asm/motorola_pgtable.h 
b/arch/m68k/include/asm/motorola_pgtable.h
index 9e5a3de21e15..e1594acf7c7e 100644
--- a/arch/m68k/include/asm/motorola_pgtable.h
+++ b/arch/m68k/include/asm/motorola_pgtable.h
@@ -227,50 +227,6 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmdp, 
unsigned long address)
 #define pte_offset_map(pmdp,address) ((pte_t *)__pmd_page(*pmdp) + (((address) 
>> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
 #define pte_unmap(pte) ((void)0)
 
-/* Prior to calling these routines, the page should have been flushed
- * from both the cache and ATC, or the CPU might not notice that the
- * cache setting for the page has been changed. -jskov
- */
-static inline void nocache_page(void *vaddr)
-{
-   unsigned long addr = (unsigned long)vaddr;
-
-   if (CPU_IS_040_OR_060) {
-   pgd_t *dir;
-   p4d_t *p4dp;
-   pud_t *pudp;
-   pmd_t *pmdp;
-   pte_t *ptep;
-
-   dir = pgd_offset_k(addr);
-   p4dp = p4d_offset(dir, addr);
-   pudp = pud_offset(p4dp, addr);
-   pmdp = pmd_offset(pudp, addr);
-   ptep = pte_offset_kernel(pmdp, addr);
-   *ptep = pte_mknocache(*ptep);
-   }
-}
-
-static inline void cache_page(void *vaddr)
-{
-   unsigned long addr = (unsigned long)vaddr;
-
-   if (CPU_IS_040_OR_060) {
-   pgd_t *dir;
-   p4d_t *p4dp;
-   pud_t *pudp;
-   pmd_t *pmdp;
-   pte_t *ptep;
-
-   dir = pgd_offset_k(addr);
-   p4dp = p4d_offset(dir, addr);
-   pudp = pud_offset(p4dp, addr);
-   pmdp = pmd_offset(pudp, addr);
-   ptep = pte_offset_kernel(pmdp, addr);
-   *ptep = pte_mkcache(*ptep);
-   }
-}
-
 /* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */
 #define __swp_type(x)  (((x).val >> 4) & 0xff)
 #define __swp_offset(x)((x).val >> 12)
diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
index 904c2a663977..8e5e74121a78 100644
--- a/arch/m68k/mm/motorola.c
+++ b/arch/m68k/mm/motorola.c
@@ -45,6 +45,49 @@ unsigned long mm_cachebits;
 EXPORT_SYMBOL(mm_cachebits);
 #endif
 
+/* Prior to calling these routines, the page should have been flushed
+ * from both the cache and ATC, or the CPU might not notice that the
+ * cache setting for the page has been changed. -jskov
+ */
+static inline void nocache_page(void *vaddr)
+{
+   unsigned long addr = (unsigned long)vaddr;
+
+   if (CPU_IS_040_OR_060) {
+   pgd_t *dir;
+   p4d_t *p4dp;
+   pud_t *pudp;
+   pmd_t *pmdp;
+   pte_t *ptep;
+
+   dir = pgd_offset_k

[PATCH v2 04/12] csky: replace definitions of __pXd_offset() with pXd_index()

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

All architectures use pXd_index() to get an entry in the page table page
corresponding to a virtual address.

Align csky with other architectures.

Signed-off-by: Mike Rapoport 
---
 arch/csky/include/asm/pgtable.h | 5 ++---
 arch/csky/mm/fault.c| 2 +-
 arch/csky/mm/highmem.c  | 2 +-
 arch/csky/mm/init.c | 6 +++---
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/csky/include/asm/pgtable.h b/arch/csky/include/asm/pgtable.h
index 9d2d16db237d..2eff4aea51b3 100644
--- a/arch/csky/include/asm/pgtable.h
+++ b/arch/csky/include/asm/pgtable.h
@@ -229,9 +229,8 @@ static inline pte_t pte_mkyoung(pte_t pte)
return pte;
 }
 
-#define __pgd_offset(address)  pgd_index(address)
-#define __pud_offset(address)  (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
-#define __pmd_offset(address)  (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
+#define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
+#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
 
 /* to find an entry in a kernel page-table-directory */
 #define pgd_offset_k(address)  pgd_offset(&init_mm, address)
diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
index 4e6dc68f3258..4055d430c0c8 100644
--- a/arch/csky/mm/fault.c
+++ b/arch/csky/mm/fault.c
@@ -78,7 +78,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned 
long write,
 * Do _not_ use "tsk" here. We might be inside
 * an interrupt in the middle of a task switch..
 */
-   int offset = __pgd_offset(address);
+   int offset = pgd_index(address);
pgd_t *pgd, *pgd_k;
pud_t *pud, *pud_k;
pmd_t *pmd, *pmd_k;
diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c
index 3b3f622f5ae9..89ec32e602a1 100644
--- a/arch/csky/mm/highmem.c
+++ b/arch/csky/mm/highmem.c
@@ -92,7 +92,7 @@ static void __init kmap_pages_init(void)
vaddr = PKMAP_BASE;
fixrange_init(vaddr, vaddr + PAGE_SIZE*LAST_PKMAP, swapper_pg_dir);
 
-   pgd = swapper_pg_dir + __pgd_offset(vaddr);
+   pgd = swapper_pg_dir + pgd_index(vaddr);
pud = (pud_t *)pgd;
pmd = pmd_offset(pud, vaddr);
pte = pte_offset_kernel(pmd, vaddr);
diff --git a/arch/csky/mm/init.c b/arch/csky/mm/init.c
index eda2b4291485..af627128314f 100644
--- a/arch/csky/mm/init.c
+++ b/arch/csky/mm/init.c
@@ -157,9 +157,9 @@ void __init fixrange_init(unsigned long start, unsigned 
long end,
unsigned long vaddr;
 
vaddr = start;
-   i = __pgd_offset(vaddr);
-   j = __pud_offset(vaddr);
-   k = __pmd_offset(vaddr);
+   i = pgd_index(vaddr);
+   j = pud_index(vaddr);
+   k = pmd_index(vaddr);
pgd = pgd_base + i;
 
for ( ; (i < PTRS_PER_PGD) && (vaddr != end); pgd++, i++) {
-- 
2.26.2


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


[PATCH v2 03/12] mm: reorder includes after introduction of linux/pgtable.h

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

The replacement of  with  made the include
of the latter in the middle of asm includes. Fix this up with the aid of
the below script and manual adjustments here and there.

import sys
import re

if len(sys.argv) is not 3:
print "USAGE: %s  " % (sys.argv[0])
sys.exit(1)

hdr_to_move="#include " % sys.argv[2]
moved = False
in_hdrs = False

with open(sys.argv[1], "r") as f:
lines = f.readlines()
for _line in lines:
line = _line.rstrip('\n')
if line == hdr_to_move:
continue
if line.startswith("#include 
---
 arch/alpha/kernel/proto.h | 2 --
 arch/arc/mm/highmem.c | 2 +-
 arch/arc/mm/tlbex.S   | 2 +-
 arch/arm/include/asm/efi.h| 1 -
 arch/arm/include/asm/fixmap.h | 2 +-
 arch/arm/kernel/head.S| 2 +-
 arch/arm/kernel/suspend.c | 2 +-
 arch/arm/kernel/vmlinux.lds.S | 2 +-
 arch/arm/mach-integrator/core.c   | 2 +-
 arch/arm/mach-keystone/platsmp.c  | 2 +-
 arch/arm/mach-sa1100/hackkit.c| 2 +-
 arch/arm/mach-zynq/common.c   | 2 +-
 arch/arm/mm/idmap.c   | 2 +-
 arch/arm/mm/mm.h  | 1 -
 arch/arm/mm/proc-arm1020.S| 2 +-
 arch/arm/mm/proc-arm1020e.S   | 2 +-
 arch/arm/mm/proc-arm1022.S| 2 +-
 arch/arm/mm/proc-arm1026.S| 2 +-
 arch/arm/mm/proc-arm720.S | 2 +-
 arch/arm/mm/proc-arm740.S | 2 +-
 arch/arm/mm/proc-arm7tdmi.S   | 2 +-
 arch/arm/mm/proc-arm920.S | 2 +-
 arch/arm/mm/proc-arm922.S | 2 +-
 arch/arm/mm/proc-arm925.S | 2 +-
 arch/arm/mm/proc-arm926.S | 2 +-
 arch/arm/mm/proc-arm940.S | 2 +-
 arch/arm/mm/proc-arm946.S | 2 +-
 arch/arm/mm/proc-arm9tdmi.S   | 2 +-
 arch/arm/mm/proc-fa526.S  | 2 +-
 arch/arm/mm/proc-feroceon.S   | 2 +-
 arch/arm/mm/proc-mohawk.S | 2 +-
 arch/arm/mm/proc-sa110.S  | 2 +-
 arch/arm/mm/proc-sa1100.S | 2 +-
 arch/arm/mm/proc-v6.S | 2 +-
 arch/arm/mm/proc-v7.S | 2 +-
 arch/arm/mm/proc-xsc3.S   | 2 +-
 arch/arm/mm/proc-xscale.S | 2 +-
 arch/arm/mm/pv-fixup-asm.S| 2 +-
 arch/arm64/include/asm/io.h   | 2 +-
 arch/arm64/include/asm/kvm_mmu.h  | 2 +-
 arch/arm64/include/asm/mmu_context.h  | 2 +-
 arch/arm64/include/asm/vmap_stack.h   | 2 +-
 arch/arm64/kernel/acpi.c  | 2 +-
 arch/arm64/kernel/head.S  | 2 +-
 arch/arm64/kernel/kaslr.c | 2 +-
 arch/arm64/kernel/suspend.c   | 2 +-
 arch/arm64/kernel/vmlinux.lds.S   | 1 -
 arch/arm64/mm/proc.S  | 2 +-
 arch/ia64/kernel/entry.S  | 2 +-
 arch/ia64/kernel/head.S   | 3 ++-
 arch/ia64/kernel/irq_ia64.c   | 2 +-
 arch/ia64/kernel/ivt.S| 2 +-
 arch/ia64/kernel/kprobes.c| 2 +-
 arch/ia64/kernel/mca_asm.S| 2 +-
 arch/ia64/kernel/relocate_kernel.S| 4 +---
 arch/ia64/kernel/setup.c  | 2 +-
 arch/ia64/kernel/uncached.c   | 2 +-
 arch/ia64/kernel/vmlinux.lds.S| 2 +-
 arch/m68k/68000/m68VZ328.c| 2 +-
 arch/m68k/include/asm/sun3xflop.h | 2 +-
 arch/m68k/kernel/head.S   | 2 +-
 arch/microblaze/include/asm/pgalloc.h | 2 +-
 arch/microblaze/kernel/hw_exception_handler.S | 2 +-
 arch/microblaze/kernel/module.c   | 2 +-
 arch/microblaze/kernel/setup.c| 2 +-
 arch/microblaze/mm/pgtable.c  | 2 +-
 arch/mips/jazz/irq.c  | 2 +-
 arch/mips/jazz/setup.c| 2 +-
 arch/mips/kvm/mips.c  | 2 +-
 arch/mips/mm/tlbe

[PATCH v2 01/12] mm: don't include asm/pgtable.h if linux/mm.h is already included

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

The linux/mm.h header includes  to allow inlining of the
functions involving page table manipulations, e.g. pte_alloc() and
pmd_alloc(). So, there is no point to explicitly include  in
the files that include .

The include statements in such cases are remove with a simple loop:

for f in $(git grep -l "include ") ; do
sed -i -e '/include / d' $f
done

Signed-off-by: Mike Rapoport 
---
 arch/alpha/boot/bootp.c   | 1 -
 arch/alpha/boot/bootpz.c  | 1 -
 arch/alpha/boot/main.c| 1 -
 arch/alpha/include/asm/io.h   | 1 -
 arch/alpha/kernel/process.c   | 1 -
 arch/alpha/kernel/ptrace.c| 1 -
 arch/alpha/kernel/setup.c | 1 -
 arch/alpha/kernel/smp.c   | 1 -
 arch/alpha/kernel/sys_alcor.c | 1 -
 arch/alpha/kernel/sys_cabriolet.c | 1 -
 arch/alpha/kernel/sys_dp264.c | 1 -
 arch/alpha/kernel/sys_eb64p.c | 1 -
 arch/alpha/kernel/sys_eiger.c | 1 -
 arch/alpha/kernel/sys_jensen.c| 1 -
 arch/alpha/kernel/sys_marvel.c| 1 -
 arch/alpha/kernel/sys_miata.c | 1 -
 arch/alpha/kernel/sys_mikasa.c| 1 -
 arch/alpha/kernel/sys_nautilus.c  | 1 -
 arch/alpha/kernel/sys_noritake.c  | 1 -
 arch/alpha/kernel/sys_rawhide.c   | 1 -
 arch/alpha/kernel/sys_ruffian.c   | 1 -
 arch/alpha/kernel/sys_rx164.c | 1 -
 arch/alpha/kernel/sys_sable.c | 1 -
 arch/alpha/kernel/sys_sio.c   | 1 -
 arch/alpha/kernel/sys_sx164.c | 1 -
 arch/alpha/kernel/sys_takara.c| 1 -
 arch/alpha/kernel/sys_titan.c | 1 -
 arch/alpha/kernel/sys_wildfire.c  | 1 -
 arch/alpha/mm/init.c  | 1 -
 arch/arm/kernel/machine_kexec.c   | 1 -
 arch/arm/kernel/module.c  | 1 -
 arch/arm/kernel/ptrace.c  | 1 -
 arch/arm/kernel/smp.c | 1 -
 arch/arm/mach-ebsa110/core.c  | 1 -
 arch/arm/mach-footbridge/common.c | 1 -
 arch/arm/mach-imx/mm-imx21.c  | 1 -
 arch/arm/mach-imx/mm-imx27.c  | 1 -
 arch/arm/mach-imx/mm-imx3.c   | 1 -
 arch/arm/mach-iop32x/i2c.c| 1 -
 arch/arm/mach-iop32x/iq31244.c| 1 -
 arch/arm/mach-iop32x/iq80321.c| 1 -
 arch/arm/mach-iop32x/n2100.c  | 1 -
 arch/arm/mach-ixp4xx/common.c | 1 -
 arch/arm/mach-sa1100/assabet.c| 1 -
 arch/arm/mm/copypage-v4mc.c   | 1 -
 arch/arm/mm/copypage-v6.c | 1 -
 arch/arm/mm/copypage-xscale.c | 1 -
 arch/arm/mm/dump.c| 1 -
 arch/arm/mm/fault-armv.c  | 1 -
 arch/arm/mm/fault.c   | 1 -
 arch/arm/mm/pageattr.c| 1 -
 arch/arm64/kernel/hibernate.c | 1 -
 arch/arm64/kernel/ptrace.c| 1 -
 arch/arm64/kernel/smp.c   | 1 -
 arch/arm64/mm/dump.c  | 1 -
 arch/arm64/mm/fault.c | 1 -
 arch/arm64/mm/kasan_init.c| 1 -
 arch/arm64/mm/pageattr.c  | 1 -
 arch/csky/kernel/module.c | 1 -
 arch/csky/kernel/ptrace.c | 1 -
 arch/csky/mm/init.c   | 1 -
 arch/csky/mm/tlb.c| 1 -
 arch/h8300/kernel/process.c   | 1 -
 arch/h8300/kernel/setup.c | 1 -
 arch/h8300/kernel/signal.c| 1 -
 arch/h8300/mm/fault.c | 1 -
 arch/h8300/mm/init.c  | 1 -
 arch/h8300/mm/memory.c| 1 -
 arch/hexagon/mm/vm_fault.c| 1 -
 arch/ia64/kernel/efi.c| 1 -
 arch/ia64/kernel/ptrace.c | 1 -
 arch/ia64/kernel/smp.c| 1 -
 arch/ia64/kernel/smpboot.c| 1 -
 arch/ia64/mm/contig.c | 1 -
 arch/ia64/mm/fault.c  | 1 -
 arch/m68k/68000/timers.c  | 1 -
 arch/m68k/amiga/config.c  | 1 -
 arch/m68k/apollo/config.c | 1 -
 arch/m68k/atari/atasound.c| 1 -
 arch/m68k/atari/stram.c   | 1 -
 arch/m68k/bvme6000/config.c   | 1 -
 arch/m68k/kernel/process.c| 1 -
 arch/m68k/kernel/ptrace.c | 1 -
 arch/m68k/kernel/setup_no.c   | 1 -
 arch/m68k/kernel/signal.c | 1 -
 arch/m68k/kernel/uboot.c  | 1 -

[PATCH v2 00/12] mm: consolidate definitions of page table accessors

2020-05-14 Thread Mike Rapoport
From: Mike Rapoport 

Hi,

The low level page table accessors (pXY_index(), pXY_offset()) are
duplicated across all architectures and sometimes more than once. For
instance, we have 31 definition of pgd_offset() for 25 supported
architectures.

Most of these definitions are actually identical and typically it boils
down to, e.g. 

static inline unsigned long pmd_index(unsigned long address)
{
return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
}

static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
{
return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(address);
}

These definitions can be shared among 90% of the arches provided XYZ_SHIFT,
PTRS_PER_XYZ and xyz_page_vaddr() are defined.

For architectures that really need a custom version there is always
possibility to override the generic version with the usual ifdefs magic.

These patches introduce include/linux/pgtable.h that replaces
include/asm-generic/pgtable.h and add the definitions of the page table
accessors to the new header.

The patches are vs the v5.7-rc5-mmotm-2020-05-13-20-30

v2 changes:
* s/morotola/motorola in the changelog of patch 6
* replace FIXME with a comment about pmf_off and virt_to_kpte in patch 8
* rebase on v5.7-rc5-mmotm-2020-05-13-20-30

Mike Rapoport (12):
  mm: don't include asm/pgtable.h if linux/mm.h is already included
  mm: introduce include/linux/pgtable.h
  mm: reorder includes after introduction of linux/pgtable.h
  csky: replace definitions of __pXd_offset() with pXd_index()
  m68k/mm/motorola: move comment about page table allocation funcitons
  m68k/mm: move {cache,nocahe}_page() definitions close to their user
  x86/mm: simplify init_trampoline() and surrounding logic
  mm: pgtable: add shortcuts for accessing kernel PMD and PTE
  mm: consolidate pte_index() and pte_offset_*() definitions
  mm: consolidate pmd_index() and pmd_offset() definitions
  mm: consolidate pud_index() and pud_offset() definitions
  mm: consolidate pgd_index() and pgd_offset{_k}() definitions

 arch/alpha/boot/bootp.c   |   1 -
 arch/alpha/boot/bootpz.c  |   1 -
 arch/alpha/boot/main.c|   1 -
 arch/alpha/include/asm/io.h   |   1 -
 arch/alpha/include/asm/pgtable.h  |  16 +--
 arch/alpha/kernel/process.c   |   1 -
 arch/alpha/kernel/proto.h |   2 -
 arch/alpha/kernel/ptrace.c|   1 -
 arch/alpha/kernel/setup.c |   1 -
 arch/alpha/kernel/smp.c   |   1 -
 arch/alpha/kernel/sys_alcor.c |   1 -
 arch/alpha/kernel/sys_cabriolet.c |   1 -
 arch/alpha/kernel/sys_dp264.c |   1 -
 arch/alpha/kernel/sys_eb64p.c |   1 -
 arch/alpha/kernel/sys_eiger.c |   1 -
 arch/alpha/kernel/sys_jensen.c|   1 -
 arch/alpha/kernel/sys_marvel.c|   1 -
 arch/alpha/kernel/sys_miata.c |   1 -
 arch/alpha/kernel/sys_mikasa.c|   1 -
 arch/alpha/kernel/sys_nautilus.c  |   1 -
 arch/alpha/kernel/sys_noritake.c  |   1 -
 arch/alpha/kernel/sys_rawhide.c   |   1 -
 arch/alpha/kernel/sys_ruffian.c   |   1 -
 arch/alpha/kernel/sys_rx164.c |   1 -
 arch/alpha/kernel/sys_sable.c |   1 -
 arch/alpha/kernel/sys_sio.c   |   1 -
 arch/alpha/kernel/sys_sx164.c |   1 -
 arch/alpha/kernel/sys_takara.c|   1 -
 arch/alpha/kernel/sys_titan.c |   1 -
 arch/alpha/kernel/sys_wildfire.c  |   1 -
 arch/alpha/mm/init.c  |   1 -
 arch/arc/include/asm/pgtable.h|  24 
 arch/arc/mm/highmem.c |  12 +-
 arch/arc/mm/tlbex.S   |   2 +-
 arch/arm/include/asm/efi.h|   1 -
 arch/arm/include/asm/fixmap.h |   2 +-
 arch/arm/include/asm/idmap.h  |   2 +-
 arch/arm/include/asm/pgtable-2level.h |   1 +
 arch/arm/include/asm/pgtable-3level.h |   7 -
 arch/arm/include/asm/pgtable-nommu.h  |   3 -
 arch/arm/include/asm/pgtable.h|  25 
 arch/arm/kernel/head.S|   2 +-
 arch/arm/kernel/machine_kexec.c   |   1 -
 arch/arm/kernel/module.c  |   1 -
 arch/arm/kernel/ptrace.c  |   1 -
 arch/arm/kernel/smp.c |   1 -
 arch/arm/kernel/suspend.c |   2 +-
 arch/arm/kernel/vmlinux.lds.S |   2 +-
 arch/arm/mach-ebsa110/core.c  |   1 -
 arch/arm/mach-footbridge/common.c |   1 -
 arch/arm/mach-imx/mm-imx21.c  |   1 -
 arch/arm/mach-imx/mm-imx27.c  |   1 -
 arch/arm/mach-imx/mm-imx3.c   |   1 -
 arch/arm/mach-integrator/core.c   |

Re: [RFC] ARC: initial ftrace support

2020-05-14 Thread Eugeniy Paltsev
Hi Claudiu,
ping!

Is is possible to switch between mcount modes (Linux-style <-> baremetal-style) 
via command-line options for ARC GCC?

>From: Alexey Brodkin 
>Sent: Thursday, April 2, 2020 17:15
>To: Claudiu Zissulescu Ianculescu
>Cc: linux-ker...@vger.kernel.org; Steven Rostedt; Ingo Molnar; 
>linux-snps-arc@lists.infradead.org; Eugeniy Paltsev; Vineet Gupta
>Subject: RE: [RFC] ARC: initial ftrace support
>
> Hi Claus,
>
>> -Original Message-
>> From: linux-snps-arc  On Behalf 
>> Of Claudiu Zissulescu
>> Ianculescu
>> Sent: Thursday, April 2, 2020 11:10 AM
>> To: Vineet Gupta 
>> Cc: Alexey Brodkin ; linux-ker...@vger.kernel.org; 
>> Steven Rostedt
>> ; Ingo Molnar ; 
>> linux-snps-arc@lists.infradead.org; Eugeniy
>> Paltsev 
>> Subject: Re: [RFC] ARC: initial ftrace support
>>
>> Hi,
>>
>> ARC-gcc has two modes to call the mcount routines. When using elf32
>> configuration, the toolchain is set to use newlib mcount. When
>> configured for linux, gcc toolchain is using a library call to _mcall
>> (single underscore)  having blink as input argument.
>> So, using the proper linux toolchain, your patch should work.
>
>
> Is there a chance to switch to Linux-style mcount in Elf32 toolchain with a 
> command-line
> option?
>
> Otherwise I guess we'll need to implement some warning which explicitly says 
> why Elf32
> toolchain is not usable for building the Linux kernel... at least in case 
> with ftrace enabled.
>
>-Alexey

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