linux-next: manual merge of the powerpc tree with Linus' tree

2018-08-14 Thread Stephen Rothwell
Hi all,

Today's linux-next merge of the powerpc tree got a conflict in:

  Documentation/admin-guide/kernel-parameters.txt

between commits:

  05736e4ac13c ("cpu/hotplug: Provide knobs to control SMT")
  506a66f37489 ("Revert "x86/apic: Ignore secondary threads if nosmt=force"")

from Linus' tree and commit:

  26cb1f36c43e ("Documentation: Add nospectre_v1 parameter")

from the powerpc tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc Documentation/admin-guide/kernel-parameters.txt
index 5a67e409d370,4167bbea51e1..
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@@ -2761,10 -2687,10 +2761,14 @@@
nosmt   [KNL,S390] Disable symmetric multithreading (SMT).
Equivalent to smt=1.
  
 +  [KNL,x86] Disable symmetric multithreading (SMT).
 +  nosmt=force: Force disable SMT, cannot be undone
 +   via the sysfs control file.
 +
+   nospectre_v1[PPC] Disable mitigations for Spectre Variant 1 (bounds
+   check bypass). With this option data leaks are possible
+   in the system.
+ 
nospectre_v2[X86] Disable all mitigations for the Spectre variant 2
(indirect branch prediction) vulnerability. System may
allow data leaks with this option, which is equivalent


pgpMw0YI5f61K.pgp
Description: OpenPGP digital signature


Re: [PATCH 0/2] Use ARRAY_SIZE to replace its implementation

2018-08-14 Thread David Howells
> "Use ARRAY_SIZE to replace its implementation"

Um, the subject line doesn't make sense.

David


[PATCH v2 4/4] powerpc/mm: remove unnecessary test in pgtable_cache_init()

2018-08-14 Thread Christophe Leroy
pgtable_cache_add() gracefully handles the case when a cache that
size already exists by returning early with the following test:

if (PGT_CACHE(shift))
return; /* Already have a cache of this size */

It is then not needed to test the existence of the cache before.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/init-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index b7ca03643d0b..1e6910eb70ed 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -111,13 +111,13 @@ void pgtable_cache_init(void)
 {
pgtable_cache_add(PGD_INDEX_SIZE);
 
-   if (PMD_CACHE_INDEX && !PGT_CACHE(PMD_CACHE_INDEX))
+   if (PMD_CACHE_INDEX)
pgtable_cache_add(PMD_CACHE_INDEX);
/*
 * In all current configs, when the PUD index exists it's the
 * same size as either the pgd or pmd index except with THP enabled
 * on book3s 64
 */
-   if (PUD_CACHE_INDEX && !PGT_CACHE(PUD_CACHE_INDEX))
+   if (PUD_CACHE_INDEX)
pgtable_cache_add(PUD_CACHE_INDEX);
 }
-- 
2.13.3



[PATCH v2 3/4] powerpc/mm: fix a warning when a cache is common to PGD and hugepages

2018-08-14 Thread Christophe Leroy
While implementing TLB miss HW assistance on the 8xx, the following
warning was encountered:

[  423.732965] WARNING: CPU: 0 PID: 345 at mm/slub.c:2412 
___slab_alloc.constprop.30+0x26c/0x46c
[  423.733033] CPU: 0 PID: 345 Comm: mmap Not tainted 
4.18.0-rc8-00664-g2dfff9121c55 #671
[  423.733075] NIP:  c0108f90 LR: c0109ad0 CTR: 0004
[  423.733121] REGS: c455bba0 TRAP: 0700   Not tainted  
(4.18.0-rc8-00664-g2dfff9121c55)
[  423.733147] MSR:  00021032   CR: 24224848  XER: 2000
[  423.733319]
[  423.733319] GPR00: c0109ad0 c455bc50 c4521910 c60053c0 007080c0 c0011b34 
c7fa41e0 c455be30
[  423.733319] GPR08: 0001 c00103a0 c7fa41e0 c49afcc4 24282842 10018840 
c079b37c 0040
[  423.733319] GPR16: 73f0 00210d00  0001 c455a000 0100 
0200 c455a000
[  423.733319] GPR24: c60053c0 c0011b34 007080c0 c455a000 c455a000 c7fa41e0 
 9032
[  423.734190] NIP [c0108f90] ___slab_alloc.constprop.30+0x26c/0x46c
[  423.734257] LR [c0109ad0] kmem_cache_alloc+0x210/0x23c
[  423.734283] Call Trace:
[  423.734326] [c455bc50] [0100] 0x100 (unreliable)
[  423.734430] [c455bcc0] [c0109ad0] kmem_cache_alloc+0x210/0x23c
[  423.734543] [c455bcf0] [c0011b34] huge_pte_alloc+0xc0/0x1dc
[  423.734633] [c455bd20] [c01044dc] hugetlb_fault+0x408/0x48c
[  423.734720] [c455bdb0] [c0104b20] follow_hugetlb_page+0x14c/0x44c
[  423.734826] [c455be10] [c00e8e54] __get_user_pages+0x1c4/0x3dc
[  423.734919] [c455be80] [c00e9924] __mm_populate+0xac/0x140
[  423.735020] [c455bec0] [c00db14c] vm_mmap_pgoff+0xb4/0xb8
[  423.735127] [c455bf00] [c00f27c0] ksys_mmap_pgoff+0xcc/0x1fc
[  423.735222] [c455bf40] [c000e0f8] ret_from_syscall+0x0/0x38
[  423.735271] Instruction dump:
[  423.735321] 7cbf482e 38fd0008 7fa6eb78 7fc4f378 4bfff5dd 7fe3fb78 4bfffe24 
81370010
[  423.735536] 71280004 41a2ff88 4840c571 4b80 <0fe0> 4bfffeb8 81340010 
712a0004
[  423.735757] ---[ end trace e9b222919a470790 ]---

This warning occurs when calling kmem_cache_zalloc() on a
cache having a constructor.

In this case it happens because PGD cache and 512k hugepte cache are
the same size (4k). While a cache with constructor is created for
the PGD, hugepages create cache without constructor and uses
kmem_cache_zalloc(). As both expect a cache with the same size,
the hugepages reuse the cache created for PGD, hence the conflict.

In order to avoid this conflict, this patch:
- modifies pgtable_cache_add() so that a zeroising constructor is
added for any cache size.
- replaces calls to kmem_cache_zalloc() by kmem_cache_alloc()

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/pgtable.h |  2 +-
 arch/powerpc/mm/hugetlbpage.c  |  6 ++---
 arch/powerpc/mm/init-common.c  | 46 ++
 3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/include/asm/pgtable.h 
b/arch/powerpc/include/asm/pgtable.h
index 14c79a7dc855..1e6265dc6697 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -72,7 +72,7 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, 
unsigned long addr,
 /* can we use this in kvm */
 unsigned long vmalloc_to_phys(void *vmalloc_addr);
 
-void pgtable_cache_add(unsigned shift, void (*ctor)(void *));
+void pgtable_cache_add(unsigned int shift);
 void pgtable_cache_init(void);
 
 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_PPC32)
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 53b7a605c3a8..6cd90445b1f5 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -71,7 +71,7 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t 
*hpdp,
num_hugepd = 1;
}
 
-   new = kmem_cache_zalloc(cachep, pgtable_gfp_flags(mm, GFP_KERNEL));
+   new = kmem_cache_alloc(cachep, pgtable_gfp_flags(mm, GFP_KERNEL));
 
BUG_ON(pshift > HUGEPD_SHIFT_MASK);
BUG_ON((unsigned long)new & HUGEPD_SHIFT_MASK);
@@ -702,10 +702,10 @@ static int __init hugetlbpage_init(void)
 * use pgt cache for hugepd.
 */
if (pdshift > shift)
-   pgtable_cache_add(pdshift - shift, NULL);
+   pgtable_cache_add(pdshift - shift);
 #if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_8xx)
else
-   pgtable_cache_add(PTE_T_ORDER, NULL);
+   pgtable_cache_add(PTE_T_ORDER);
 #endif
}
 
diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 41190f2b60c2..b7ca03643d0b 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -25,19 +25,37 @@
 #include 
 #include 
 
-static void pgd_ctor(void *addr)
-{
-   memset(addr, 0, PGD_TABLE_SIZE);
+#define CTOR(shift) static void ctor_##shift(void *addr) \
+{  \
+   memset(addr, 0, sizeof(void *) << (shift)); \
 }
 
-static void 

[PATCH v2 2/4] powerpc/mm: replace hugetlb_cache by PGT_CACHE(PTE_T_ORDER)

2018-08-14 Thread Christophe Leroy
Instead of opencoding cache handling for the special case
of hugepage tables having a single pte_t element, this
patch makes use of the common pgtable_cache helpers

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/hugetlb.h |  2 --
 arch/powerpc/mm/hugetlbpage.c  | 26 +++---
 2 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/include/asm/hugetlb.h 
b/arch/powerpc/include/asm/hugetlb.h
index 2d00cc530083..e13843556414 100644
--- a/arch/powerpc/include/asm/hugetlb.h
+++ b/arch/powerpc/include/asm/hugetlb.h
@@ -6,8 +6,6 @@
 #include 
 #include 
 
-extern struct kmem_cache *hugepte_cache;
-
 #ifdef CONFIG_PPC_BOOK3S_64
 
 #include 
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 7296a42eb62e..53b7a605c3a8 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -43,6 +43,8 @@ EXPORT_SYMBOL(HPAGE_SHIFT);
 
 #define hugepd_none(hpd)   (hpd_val(hpd) == 0)
 
+#define PTE_T_ORDER(__builtin_ffs(sizeof(pte_t)) - 
__builtin_ffs(sizeof(void *)))
+
 pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, unsigned long 
sz)
 {
/*
@@ -62,7 +64,7 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t 
*hpdp,
int num_hugepd;
 
if (pshift >= pdshift) {
-   cachep = hugepte_cache;
+   cachep = PGT_CACHE(PTE_T_ORDER);
num_hugepd = 1 << (pshift - pdshift);
} else {
cachep = PGT_CACHE(pdshift - pshift);
@@ -265,7 +267,7 @@ static void hugepd_free_rcu_callback(struct rcu_head *head)
unsigned int i;
 
for (i = 0; i < batch->index; i++)
-   kmem_cache_free(hugepte_cache, batch->ptes[i]);
+   kmem_cache_free(PGT_CACHE(PTE_T_ORDER), batch->ptes[i]);
 
free_page((unsigned long)batch);
 }
@@ -278,7 +280,7 @@ static void hugepd_free(struct mmu_gather *tlb, void 
*hugepte)
 
if (atomic_read(>mm->mm_users) < 2 ||
mm_is_thread_local(tlb->mm)) {
-   kmem_cache_free(hugepte_cache, hugepte);
+   kmem_cache_free(PGT_CACHE(PTE_T_ORDER), hugepte);
put_cpu_var(hugepd_freelist_cur);
return;
}
@@ -653,7 +655,6 @@ static int __init hugepage_setup_sz(char *str)
 }
 __setup("hugepagesz=", hugepage_setup_sz);
 
-struct kmem_cache *hugepte_cache;
 static int __init hugetlbpage_init(void)
 {
int psize;
@@ -703,21 +704,8 @@ static int __init hugetlbpage_init(void)
if (pdshift > shift)
pgtable_cache_add(pdshift - shift, NULL);
 #if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_8xx)
-   else if (!hugepte_cache) {
-   /*
-* Create a kmem cache for hugeptes.  The bottom bits in
-* the pte have size information encoded in them, so
-* align them to allow this
-*/
-   hugepte_cache = kmem_cache_create("hugepte-cache",
- sizeof(pte_t),
- HUGEPD_SHIFT_MASK + 1,
- 0, NULL);
-   if (hugepte_cache == NULL)
-   panic("%s: Unable to create kmem cache "
- "for hugeptes\n", __func__);
-
-   }
+   else
+   pgtable_cache_add(PTE_T_ORDER, NULL);
 #endif
}
 
-- 
2.13.3



[PATCH v2 1/4] powerpc/mm: enable the use of page table cache of order 0

2018-08-14 Thread Christophe Leroy
hugepages uses a cache of order 0. Lets allow page tables
of order 0 in the common part in order to avoid open coding
in hugetlb

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/32/pgalloc.h | 5 +
 arch/powerpc/include/asm/book3s/64/pgalloc.h | 5 +
 arch/powerpc/include/asm/nohash/32/pgalloc.h | 5 +
 arch/powerpc/include/asm/nohash/64/pgalloc.h | 5 +
 arch/powerpc/mm/init-common.c| 6 +++---
 5 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/32/pgalloc.h 
b/arch/powerpc/include/asm/book3s/32/pgalloc.h
index 82e44b1a00ae..96138ab3ddd6 100644
--- a/arch/powerpc/include/asm/book3s/32/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/32/pgalloc.h
@@ -25,10 +25,7 @@
 extern void __bad_pte(pmd_t *pmd);
 
 extern struct kmem_cache *pgtable_cache[];
-#define PGT_CACHE(shift) ({\
-   BUG_ON(!(shift));   \
-   pgtable_cache[(shift) - 1]; \
-   })
+#define PGT_CACHE(shift) pgtable_cache[shift]
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
diff --git a/arch/powerpc/include/asm/book3s/64/pgalloc.h 
b/arch/powerpc/include/asm/book3s/64/pgalloc.h
index 391ed2c3b697..bfed4cf3b2f3 100644
--- a/arch/powerpc/include/asm/book3s/64/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/64/pgalloc.h
@@ -37,10 +37,7 @@ extern struct vmemmap_backing *vmemmap_list;
 #define MAX_PGTABLE_INDEX_SIZE 0xf
 
 extern struct kmem_cache *pgtable_cache[];
-#define PGT_CACHE(shift) ({\
-   BUG_ON(!(shift));   \
-   pgtable_cache[(shift) - 1]; \
-   })
+#define PGT_CACHE(shift) pgtable_cache[shift]
 
 extern pte_t *pte_fragment_alloc(struct mm_struct *, unsigned long, int);
 extern pmd_t *pmd_fragment_alloc(struct mm_struct *, unsigned long);
diff --git a/arch/powerpc/include/asm/nohash/32/pgalloc.h 
b/arch/powerpc/include/asm/nohash/32/pgalloc.h
index 8825953c225b..6fbbb90043c0 100644
--- a/arch/powerpc/include/asm/nohash/32/pgalloc.h
+++ b/arch/powerpc/include/asm/nohash/32/pgalloc.h
@@ -25,10 +25,7 @@
 extern void __bad_pte(pmd_t *pmd);
 
 extern struct kmem_cache *pgtable_cache[];
-#define PGT_CACHE(shift) ({\
-   BUG_ON(!(shift));   \
-   pgtable_cache[(shift) - 1]; \
-   })
+#define PGT_CACHE(shift) pgtable_cache[shift]
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
diff --git a/arch/powerpc/include/asm/nohash/64/pgalloc.h 
b/arch/powerpc/include/asm/nohash/64/pgalloc.h
index e2d62d033708..e95eb499a174 100644
--- a/arch/powerpc/include/asm/nohash/64/pgalloc.h
+++ b/arch/powerpc/include/asm/nohash/64/pgalloc.h
@@ -36,10 +36,7 @@ extern struct vmemmap_backing *vmemmap_list;
 #define MAX_PGTABLE_INDEX_SIZE 0xf
 
 extern struct kmem_cache *pgtable_cache[];
-#define PGT_CACHE(shift) ({\
-   BUG_ON(!(shift));   \
-   pgtable_cache[(shift) - 1]; \
-   })
+#define PGT_CACHE(shift) pgtable_cache[shift]
 
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 2b656e67f2ea..41190f2b60c2 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -40,7 +40,7 @@ static void pmd_ctor(void *addr)
memset(addr, 0, PMD_TABLE_SIZE);
 }
 
-struct kmem_cache *pgtable_cache[MAX_PGTABLE_INDEX_SIZE];
+struct kmem_cache *pgtable_cache[MAX_PGTABLE_INDEX_SIZE + 1];
 EXPORT_SYMBOL_GPL(pgtable_cache);  /* used by kvm_hv module */
 
 /*
@@ -71,7 +71,7 @@ void pgtable_cache_add(unsigned shift, void (*ctor)(void *))
 * moment, gcc doesn't seem to recognize is_power_of_2 as a
 * constant expression, so so much for that. */
BUG_ON(!is_power_of_2(minalign));
-   BUG_ON((shift < 1) || (shift > MAX_PGTABLE_INDEX_SIZE));
+   BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
 
if (PGT_CACHE(shift))
return; /* Already have a cache of this size */
@@ -83,7 +83,7 @@ void pgtable_cache_add(unsigned shift, void (*ctor)(void *))
panic("Could not allocate pgtable cache for order %d", shift);
 
kfree(name);
-   pgtable_cache[shift - 1] = new;
+   pgtable_cache[shift] = new;
 
pr_debug("Allocated pgtable cache for order %d\n", shift);
 }
-- 
2.13.3



Re: [PATCH] powerpc/perf: Update perf_regs structure to include SIER

2018-08-14 Thread Madhavan Srinivasan

Hi arnaldo,

Any comments or ack for this patch.

With regards
Maddy

On Tuesday 10 July 2018 03:59 PM, Madhavan Srinivasan wrote:

On each sample, Sample Instruction Event Register (SIER) content
is saved in pt_regs. SIER does not have a entry as-is in the pt_regs
but instead, SIER content is saved in the "dar" register of pt_regs.

Patch adds another entry to the perf_regs structure to include the "SIER"
printing which internally maps to the "dar" of pt_regs.

Cc: Arnaldo Carvalho de Melo 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Alexander Shishkin 
Cc: Anju T Sudhakar 
Cc: Ravi Bangoria 
Signed-off-by: Madhavan Srinivasan 
---
  arch/powerpc/include/uapi/asm/perf_regs.h   | 1 +
  arch/powerpc/perf/perf_regs.c   | 1 +
  tools/arch/powerpc/include/uapi/asm/perf_regs.h | 1 +
  tools/perf/arch/powerpc/include/perf_regs.h | 3 ++-
  tools/perf/arch/powerpc/util/perf_regs.c| 1 +
  5 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/uapi/asm/perf_regs.h 
b/arch/powerpc/include/uapi/asm/perf_regs.h
index 9e52c86ccbd3..ff91192407d1 100644
--- a/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -46,6 +46,7 @@ enum perf_event_powerpc_regs {
PERF_REG_POWERPC_TRAP,
PERF_REG_POWERPC_DAR,
PERF_REG_POWERPC_DSISR,
+   PERF_REG_POWERPC_SIER,
PERF_REG_POWERPC_MAX,
  };
  #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
diff --git a/arch/powerpc/perf/perf_regs.c b/arch/powerpc/perf/perf_regs.c
index 09ceea6175ba..c262aea22ad9 100644
--- a/arch/powerpc/perf/perf_regs.c
+++ b/arch/powerpc/perf/perf_regs.c
@@ -69,6 +69,7 @@ static unsigned int pt_regs_offset[PERF_REG_POWERPC_MAX] = {
PT_REGS_OFFSET(PERF_REG_POWERPC_TRAP, trap),
PT_REGS_OFFSET(PERF_REG_POWERPC_DAR, dar),
PT_REGS_OFFSET(PERF_REG_POWERPC_DSISR, dsisr),
+   PT_REGS_OFFSET(PERF_REG_POWERPC_SIER, dar),
  };

  u64 perf_reg_value(struct pt_regs *regs, int idx)
diff --git a/tools/arch/powerpc/include/uapi/asm/perf_regs.h 
b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
index 9e52c86ccbd3..ff91192407d1 100644
--- a/tools/arch/powerpc/include/uapi/asm/perf_regs.h
+++ b/tools/arch/powerpc/include/uapi/asm/perf_regs.h
@@ -46,6 +46,7 @@ enum perf_event_powerpc_regs {
PERF_REG_POWERPC_TRAP,
PERF_REG_POWERPC_DAR,
PERF_REG_POWERPC_DSISR,
+   PERF_REG_POWERPC_SIER,
PERF_REG_POWERPC_MAX,
  };
  #endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */
diff --git a/tools/perf/arch/powerpc/include/perf_regs.h 
b/tools/perf/arch/powerpc/include/perf_regs.h
index 00e37b106913..1076393e6f43 100644
--- a/tools/perf/arch/powerpc/include/perf_regs.h
+++ b/tools/perf/arch/powerpc/include/perf_regs.h
@@ -62,7 +62,8 @@ static const char *reg_names[] = {
[PERF_REG_POWERPC_SOFTE] = "softe",
[PERF_REG_POWERPC_TRAP] = "trap",
[PERF_REG_POWERPC_DAR] = "dar",
-   [PERF_REG_POWERPC_DSISR] = "dsisr"
+   [PERF_REG_POWERPC_DSISR] = "dsisr",
+   [PERF_REG_POWERPC_SIER] = "sier"
  };

  static inline const char *perf_reg_name(int id)
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c 
b/tools/perf/arch/powerpc/util/perf_regs.c
index ec50939b0418..07fcd977d93e 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -52,6 +52,7 @@ const struct sample_reg sample_reg_masks[] = {
SMPL_REG(trap, PERF_REG_POWERPC_TRAP),
SMPL_REG(dar, PERF_REG_POWERPC_DAR),
SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR),
+   SMPL_REG(sier, PERF_REG_POWERPC_SIER),
SMPL_REG_END
  };





Re: [PATCH] powerpc/perf: Update perf_regs structure to include SIER

2018-08-14 Thread Ravi Bangoria



On 08/14/2018 03:46 PM, Madhavan Srinivasan wrote:
> Hi arnaldo,
> 
> Any comments or ack for this patch.

Tested-by: Ravi Bangoria 

Thanks,
Ravi



Re: [PATCH v7 7/9] powerpc/pseries: Dump the SLB contents on SLB MCE errors.

2018-08-14 Thread Aneesh Kumar K.V

On 08/14/2018 04:27 PM, Mahesh Jagannath Salgaonkar wrote:

On 08/13/2018 07:57 PM, Nicholas Piggin wrote:

On Mon, 13 Aug 2018 09:47:04 +0530
Mahesh Jagannath Salgaonkar  wrote:


On 08/11/2018 10:03 AM, Nicholas Piggin wrote:

On Tue, 07 Aug 2018 19:47:39 +0530
Mahesh J Salgaonkar  wrote:
   

From: Mahesh Salgaonkar 

If we get a machine check exceptions due to SLB errors then dump the
current SLB contents which will be very much helpful in debugging the
root cause of SLB errors. Introduce an exclusive buffer per cpu to hold
faulty SLB entries. In real mode mce handler saves the old SLB contents
into this buffer accessible through paca and print it out later in virtual
mode.

With this patch the console will log SLB contents like below on SLB MCE
errors:

[  507.297236] SLB contents of cpu 0x1
[  507.297237] Last SLB entry inserted at slot 16
[  507.297238] 00 c800 400ea1b217000500
[  507.297239]   1T  ESID=   c0  VSID=  ea1b217 LLP:100
[  507.297240] 01 d800 400d43642f000510
[  507.297242]   1T  ESID=   d0  VSID=  d43642f LLP:110
[  507.297243] 11 f800 400a86c85f000500
[  507.297244]   1T  ESID=   f0  VSID=  a86c85f LLP:100
[  507.297245] 12 7f000800 4008119624000d90
[  507.297246]   1T  ESID=   7f  VSID=  8119624 LLP:110
[  507.297247] 13 1800 00092885f5150d90
[  507.297247]  256M ESID=1  VSID=   92885f5150 LLP:110
[  507.297248] 14 01000800 4009e7cb5d90
[  507.297249]   1T  ESID=1  VSID=  9e7cb50 LLP:110
[  507.297250] 15 d800 400d43642f000510
[  507.297251]   1T  ESID=   d0  VSID=  d43642f LLP:110
[  507.297252] 16 d800 400d43642f000510
[  507.297253]   1T  ESID=   d0  VSID=  d43642f LLP:110
[  507.297253] --
[  507.297254] SLB cache ptr value = 3
[  507.297254] Valid SLB cache entries:
[  507.297255] 00 EA[0-35]=7f000
[  507.297256] 01 EA[0-35]=1
[  507.297257] 02 EA[0-35]= 1000
[  507.297257] Rest of SLB cache entries:
[  507.297258] 03 EA[0-35]=7f000
[  507.297258] 04 EA[0-35]=1
[  507.297259] 05 EA[0-35]= 1000
[  507.297260] 06 EA[0-35]=   12
[  507.297260] 07 EA[0-35]=7f000

Suggested-by: Aneesh Kumar K.V 
Suggested-by: Michael Ellerman 
Signed-off-by: Mahesh Salgaonkar 
---

Changes in V7:
- Print slb cache ptr value and slb cache data
---
  arch/powerpc/include/asm/book3s/64/mmu-hash.h |7 ++
  arch/powerpc/include/asm/paca.h   |4 +
  arch/powerpc/mm/slb.c |   73 +
  arch/powerpc/platforms/pseries/ras.c  |   10 +++
  arch/powerpc/platforms/pseries/setup.c|   10 +++
  5 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h 
b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index cc00a7088cf3..5a3fe282076d 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -485,9 +485,16 @@ static inline void hpte_init_pseries(void) { }
  
  extern void hpte_init_native(void);
  
+struct slb_entry {

+   u64 esid;
+   u64 vsid;
+};
+
  extern void slb_initialize(void);
  extern void slb_flush_and_rebolt(void);
  extern void slb_flush_and_rebolt_realmode(void);
+extern void slb_save_contents(struct slb_entry *slb_ptr);
+extern void slb_dump_contents(struct slb_entry *slb_ptr);
  
  extern void slb_vmalloc_update(void);

  extern void slb_set_size(u16 size);
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 7f22929ce915..233d25ff6f64 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -254,6 +254,10 @@ struct paca_struct {
  #endif
  #ifdef CONFIG_PPC_PSERIES
u8 *mce_data_buf;   /* buffer to hold per cpu rtas errlog */
+
+   /* Capture SLB related old contents in MCE handler. */
+   struct slb_entry *mce_faulty_slbs;
+   u16 slb_save_cache_ptr;
  #endif /* CONFIG_PPC_PSERIES */
  } cacheline_aligned;
  
diff --git a/arch/powerpc/mm/slb.c b/arch/powerpc/mm/slb.c

index e89f675f1b5e..16a53689ffd4 100644
--- a/arch/powerpc/mm/slb.c
+++ b/arch/powerpc/mm/slb.c
@@ -151,6 +151,79 @@ void slb_flush_and_rebolt_realmode(void)
get_paca()->slb_cache_ptr = 0;
  }
  
+void slb_save_contents(struct slb_entry *slb_ptr)

+{
+   int i;
+   unsigned long e, v;
+
+   /* Save slb_cache_ptr value. */
+   get_paca()->slb_save_cache_ptr = get_paca()->slb_cache_ptr;


What's the point of saving this?


This is to know how many valid cache entries were present at the time of
SLB mutlihit. We use this index value while dumping the slb cahce entries.


Oh I see you're dumping that thing as well. I don't know if that's
worth doing, it just gives you the first 8 SLB entries installed but
you already have those (or they're overwritten and irrelevat).


Aneesh, Can you comment 

[PATCH V3] ocxl: Fix access to the AFU Descriptor Data

2018-08-14 Thread Christophe Lombard
The AFU Information DVSEC capability is a means to extract common,
general information about all of the AFUs associated with a Function
independent of the specific functionality that each AFU provides.
Write in the AFU Index field allows to access to the descriptor data
for each AFU.

With the current code, we are not able to access to these specific data
when the index >= 1 because we are writing to the wrong location.
All requests to the data of each AFU are pointing to those of the AFU 0,
which could have impacts when using a card with more than one AFU per
function.

This patch fixes the access to the AFU Descriptor Data indexed by the
AFU Info Index field.

Fixes: 5ef3166e8a32 ("ocxl: Driver code for 'generic' opencapi devices")
Cc: stable  # 4.16
Signed-off-by: Christophe Lombard 

Acked-by: Frederic Barrat 
Acked-by: Andrew Donnellan 
---
Changelog[v3]
 - Rebase to latest upstream.
 - Update the commit message.

Changelog[v2]
 - Rebase to latest upstream.
 - Use pci_write_config_byte instead of pci_write_config_word
---
 drivers/misc/ocxl/config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index 2e30de9..57a6bb1 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -280,7 +280,9 @@ int ocxl_config_check_afu_index(struct pci_dev *dev,
u32 val;
int rc, templ_major, templ_minor, len;
 
-   pci_write_config_word(dev, fn->dvsec_afu_info_pos, afu_idx);
+   pci_write_config_byte(dev,
+   fn->dvsec_afu_info_pos + OCXL_DVSEC_AFU_INFO_AFU_IDX,
+   afu_idx);
rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_VERSION, );
if (rc)
return rc;
-- 
2.7.4



Re: [PATCH V2] ocxl: Fix access to the AFU Descriptor Data

2018-08-14 Thread christophe lombard

Le 14/08/2018 à 05:26, Michael Ellerman a écrit :

Hi Christophe,

The patch looks fine, just a nit about the change log:

Christophe Lombard  writes:

The AFU Information DVSEC capability is a means to extract common,
general information about all of the AFUs associated with a Function
independent of the specific functionality that each AFU provides.

This patch fixes the access to the AFU Descriptor Data indexed by the
AFU Info Index field.



Fixes: 5ef3166e8a32 ("ocxl: Driver code for 'generic' opencapi devices")
Cc: stable  # 4.16
Signed-off-by: Christophe Lombard 


When fixing a bug it's always good to describe how the bug manifests.
ie. in this case we are clearly writing to the wrong location in config
space, but what is the consequence of that? Does it kill the device, or
just fails to initialise something correctly? How could I tell if I'm
hitting this bug currently? How would I tell if the fix is applied
correctly?


You are right, let me send a new version.

Thanks



cheers


---
Changelog[v2]
  - Rebase to latest upstream.
  - Use pci_write_config_byte instead of pci_write_config_word
---
  drivers/misc/ocxl/config.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index 2e30de9..57a6bb1 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -280,7 +280,9 @@ int ocxl_config_check_afu_index(struct pci_dev *dev,
u32 val;
int rc, templ_major, templ_minor, len;
  
-	pci_write_config_word(dev, fn->dvsec_afu_info_pos, afu_idx);

+   pci_write_config_byte(dev,
+   fn->dvsec_afu_info_pos + OCXL_DVSEC_AFU_INFO_AFU_IDX,
+   afu_idx);
rc = read_afu_info(dev, fn, OCXL_DVSEC_TEMPL_VERSION, );
if (rc)
return rc;
--
2.7.4






Re: [PATCH v7 7/9] powerpc/pseries: Dump the SLB contents on SLB MCE errors.

2018-08-14 Thread Mahesh Jagannath Salgaonkar
On 08/13/2018 07:57 PM, Nicholas Piggin wrote:
> On Mon, 13 Aug 2018 09:47:04 +0530
> Mahesh Jagannath Salgaonkar  wrote:
> 
>> On 08/11/2018 10:03 AM, Nicholas Piggin wrote:
>>> On Tue, 07 Aug 2018 19:47:39 +0530
>>> Mahesh J Salgaonkar  wrote:
>>>   
 From: Mahesh Salgaonkar 

 If we get a machine check exceptions due to SLB errors then dump the
 current SLB contents which will be very much helpful in debugging the
 root cause of SLB errors. Introduce an exclusive buffer per cpu to hold
 faulty SLB entries. In real mode mce handler saves the old SLB contents
 into this buffer accessible through paca and print it out later in virtual
 mode.

 With this patch the console will log SLB contents like below on SLB MCE
 errors:

 [  507.297236] SLB contents of cpu 0x1
 [  507.297237] Last SLB entry inserted at slot 16
 [  507.297238] 00 c800 400ea1b217000500
 [  507.297239]   1T  ESID=   c0  VSID=  ea1b217 LLP:100
 [  507.297240] 01 d800 400d43642f000510
 [  507.297242]   1T  ESID=   d0  VSID=  d43642f LLP:110
 [  507.297243] 11 f800 400a86c85f000500
 [  507.297244]   1T  ESID=   f0  VSID=  a86c85f LLP:100
 [  507.297245] 12 7f000800 4008119624000d90
 [  507.297246]   1T  ESID=   7f  VSID=  8119624 LLP:110
 [  507.297247] 13 1800 00092885f5150d90
 [  507.297247]  256M ESID=1  VSID=   92885f5150 LLP:110
 [  507.297248] 14 01000800 4009e7cb5d90
 [  507.297249]   1T  ESID=1  VSID=  9e7cb50 LLP:110
 [  507.297250] 15 d800 400d43642f000510
 [  507.297251]   1T  ESID=   d0  VSID=  d43642f LLP:110
 [  507.297252] 16 d800 400d43642f000510
 [  507.297253]   1T  ESID=   d0  VSID=  d43642f LLP:110
 [  507.297253] --
 [  507.297254] SLB cache ptr value = 3
 [  507.297254] Valid SLB cache entries:
 [  507.297255] 00 EA[0-35]=7f000
 [  507.297256] 01 EA[0-35]=1
 [  507.297257] 02 EA[0-35]= 1000
 [  507.297257] Rest of SLB cache entries:
 [  507.297258] 03 EA[0-35]=7f000
 [  507.297258] 04 EA[0-35]=1
 [  507.297259] 05 EA[0-35]= 1000
 [  507.297260] 06 EA[0-35]=   12
 [  507.297260] 07 EA[0-35]=7f000

 Suggested-by: Aneesh Kumar K.V 
 Suggested-by: Michael Ellerman 
 Signed-off-by: Mahesh Salgaonkar 
 ---

 Changes in V7:
 - Print slb cache ptr value and slb cache data
 ---
  arch/powerpc/include/asm/book3s/64/mmu-hash.h |7 ++
  arch/powerpc/include/asm/paca.h   |4 +
  arch/powerpc/mm/slb.c |   73 
 +
  arch/powerpc/platforms/pseries/ras.c  |   10 +++
  arch/powerpc/platforms/pseries/setup.c|   10 +++
  5 files changed, 103 insertions(+), 1 deletion(-)

 diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h 
 b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
 index cc00a7088cf3..5a3fe282076d 100644
 --- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
 +++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
 @@ -485,9 +485,16 @@ static inline void hpte_init_pseries(void) { }
  
  extern void hpte_init_native(void);
  
 +struct slb_entry {
 +  u64 esid;
 +  u64 vsid;
 +};
 +
  extern void slb_initialize(void);
  extern void slb_flush_and_rebolt(void);
  extern void slb_flush_and_rebolt_realmode(void);
 +extern void slb_save_contents(struct slb_entry *slb_ptr);
 +extern void slb_dump_contents(struct slb_entry *slb_ptr);
  
  extern void slb_vmalloc_update(void);
  extern void slb_set_size(u16 size);
 diff --git a/arch/powerpc/include/asm/paca.h 
 b/arch/powerpc/include/asm/paca.h
 index 7f22929ce915..233d25ff6f64 100644
 --- a/arch/powerpc/include/asm/paca.h
 +++ b/arch/powerpc/include/asm/paca.h
 @@ -254,6 +254,10 @@ struct paca_struct {
  #endif
  #ifdef CONFIG_PPC_PSERIES
u8 *mce_data_buf;   /* buffer to hold per cpu rtas errlog */
 +
 +  /* Capture SLB related old contents in MCE handler. */
 +  struct slb_entry *mce_faulty_slbs;
 +  u16 slb_save_cache_ptr;
  #endif /* CONFIG_PPC_PSERIES */
  } cacheline_aligned;
  
 diff --git a/arch/powerpc/mm/slb.c b/arch/powerpc/mm/slb.c
 index e89f675f1b5e..16a53689ffd4 100644
 --- a/arch/powerpc/mm/slb.c
 +++ b/arch/powerpc/mm/slb.c
 @@ -151,6 +151,79 @@ void slb_flush_and_rebolt_realmode(void)
get_paca()->slb_cache_ptr = 0;
  }
  
 +void slb_save_contents(struct slb_entry *slb_ptr)
 +{
 +  int i;
 +  unsigned long e, v;
 +
 +  /* Save slb_cache_ptr value. */
 +  get_paca()->slb_save_cache_ptr = 

Re: [PATCH 2/2] powerpc: Use ARRAY_SIZE to replace its implementation

2018-08-14 Thread zhong jiang
On 2018/8/14 17:28, Michael Ellerman wrote:
> zhong jiang  writes:
>> Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.
>> So just replace it.
>>
>> Signed-off-by: zhong jiang 
>> ---
>>  arch/powerpc/xmon/ppc-opc.c | 12 
>>  1 file changed, 4 insertions(+), 8 deletions(-)
> This code is copied from binutils and we don't want to needlessly cause
> it to diverge from the binutils copy.
>
> So thanks but no thanks.
Thank you for clarification.

Sincerely
zhong jiang
> cheers
>
>> diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
>> index ac2b55b..f3f57a1 100644
>> --- a/arch/powerpc/xmon/ppc-opc.c
>> +++ b/arch/powerpc/xmon/ppc-opc.c
>> @@ -966,8 +966,7 @@
>>{ 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
>>  };
>>  
>> -const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
>> -   / sizeof (powerpc_operands[0]));
>> +const unsigned int num_powerpc_operands = ARRAY_SIZE(powerpc_operands);
>>  
>>  /* The functions used to insert and extract complicated operands.  */
>>  
>> @@ -6980,8 +6979,7 @@
>>  {"fcfidu.", XRC(63,974,1),  XRA_MASK, POWER7|PPCA2, PPCVLE, {FRT, 
>> FRB}},
>>  };
>>  
>> -const int powerpc_num_opcodes =
>> -  sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
>> +const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes);
>>  
>>  /* The VLE opcode table.
>>  
>> @@ -7219,8 +7217,7 @@
>>  {"se_bl",   BD8(58,0,1),BD8_MASK,   PPCVLE, 0,  {B8}},
>>  };
>>  
>> -const int vle_num_opcodes =
>> -  sizeof (vle_opcodes) / sizeof (vle_opcodes[0]);
>> +const int vle_num_opcodes = ARRAY_SIZE(vle_opcodes);
>>  
>>  /* The macro table.  This is only used by the assembler.  */
>>  
>> @@ -7288,5 +7285,4 @@
>>  {"e_clrlslwi",4, PPCVLE, "e_rlwinm %0,%1,%3,(%2)-(%3),31-(%3)"},
>>  };
>>  
>> -const int powerpc_num_macros =
>> -  sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
>> +const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);
>> -- 
>> 1.7.12.4
> .
>




Re: [PATCH 1/3] powerpc/mm: fix a warning when a cache is common to PGD and hugepages

2018-08-14 Thread Christophe LEROY




Le 13/08/2018 à 15:44, Aneesh Kumar K.V a écrit :

On 08/13/2018 06:57 PM, Christophe Leroy wrote:

While implementing TLB miss HW assistance on the 8xx, the following
warning was encountered:

[  423.732965] WARNING: CPU: 0 PID: 345 at mm/slub.c:2412 
___slab_alloc.constprop.30+0x26c/0x46c
[  423.733033] CPU: 0 PID: 345 Comm: mmap Not tainted 
4.18.0-rc8-00664-g2dfff9121c55 #671

[  423.733075] NIP:  c0108f90 LR: c0109ad0 CTR: 0004
[  423.733121] REGS: c455bba0 TRAP: 0700   Not tainted  
(4.18.0-rc8-00664-g2dfff9121c55)

[  423.733147] MSR:  00021032   CR: 24224848  XER: 2000
[  423.733319]
[  423.733319] GPR00: c0109ad0 c455bc50 c4521910 c60053c0 007080c0 
c0011b34 c7fa41e0 c455be30
[  423.733319] GPR08: 0001 c00103a0 c7fa41e0 c49afcc4 24282842 
10018840 c079b37c 0040
[  423.733319] GPR16: 73f0 00210d00  0001 c455a000 
0100 0200 c455a000
[  423.733319] GPR24: c60053c0 c0011b34 007080c0 c455a000 c455a000 
c7fa41e0  9032

[  423.734190] NIP [c0108f90] ___slab_alloc.constprop.30+0x26c/0x46c
[  423.734257] LR [c0109ad0] kmem_cache_alloc+0x210/0x23c
[  423.734283] Call Trace:
[  423.734326] [c455bc50] [0100] 0x100 (unreliable)
[  423.734430] [c455bcc0] [c0109ad0] kmem_cache_alloc+0x210/0x23c
[  423.734543] [c455bcf0] [c0011b34] huge_pte_alloc+0xc0/0x1dc
[  423.734633] [c455bd20] [c01044dc] hugetlb_fault+0x408/0x48c
[  423.734720] [c455bdb0] [c0104b20] follow_hugetlb_page+0x14c/0x44c
[  423.734826] [c455be10] [c00e8e54] __get_user_pages+0x1c4/0x3dc
[  423.734919] [c455be80] [c00e9924] __mm_populate+0xac/0x140
[  423.735020] [c455bec0] [c00db14c] vm_mmap_pgoff+0xb4/0xb8
[  423.735127] [c455bf00] [c00f27c0] ksys_mmap_pgoff+0xcc/0x1fc
[  423.735222] [c455bf40] [c000e0f8] ret_from_syscall+0x0/0x38
[  423.735271] Instruction dump:
[  423.735321] 7cbf482e 38fd0008 7fa6eb78 7fc4f378 4bfff5dd 7fe3fb78 
4bfffe24 81370010
[  423.735536] 71280004 41a2ff88 4840c571 4b80 <0fe0> 4bfffeb8 
81340010 712a0004

[  423.735757] ---[ end trace e9b222919a470790 ]---

This warning occurs when calling kmem_cache_zalloc() on a
cache having a constructor.

In this case it happens because PGD cache and 512k hugepte cache are
the same size (4k). While a cache with constructor is created for
the PGD, hugepages create cache without constructor and uses
kmem_cache_zalloc(). As both expect a cache with the same size,
the hugepages reuse the cache created for PGD, hence the conflict.

As the constructors only aim at zeroing the allocated memory, this
patch fixes this issue by removing the constructors and using
kmem_cache_zalloc() instead.



But that means we zero out on each alloc from the slab right? Earlier we 
allocated we we added memory to the slab. Also we have code that 
carefully zero things out when we free the page table back to slab.
The idea there was, it is better take the cost of zeroing out during 
free rather than fault.


Ok, then it means we have to do it the other way round and change
hugetlb to use cache with constructors as well.

At first look, it seems quite tricky to do it though. The constructor 
doesn't get the size of the cache, so it means we need one constructor 
for each possible size.


Christophe





Signed-off-by: Christophe Leroy 
---
  arch/powerpc/include/asm/book3s/32/pgalloc.h |  2 +-
  arch/powerpc/include/asm/book3s/64/pgalloc.h |  4 ++--
  arch/powerpc/include/asm/nohash/32/pgalloc.h |  2 +-
  arch/powerpc/include/asm/nohash/64/pgalloc.h |  6 +++---
  arch/powerpc/mm/init-common.c    | 21 +++--
  5 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/32/pgalloc.h 
b/arch/powerpc/include/asm/book3s/32/pgalloc.h

index 82e44b1a00ae..4c23cc1ae7a1 100644
--- a/arch/powerpc/include/asm/book3s/32/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/32/pgalloc.h
@@ -32,7 +32,7 @@ extern struct kmem_cache *pgtable_cache[];

  static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  {
-    return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
+    return kmem_cache_zalloc(PGT_CACHE(PGD_INDEX_SIZE),
  pgtable_gfp_flags(mm, GFP_KERNEL));
  }

diff --git a/arch/powerpc/include/asm/book3s/64/pgalloc.h 
b/arch/powerpc/include/asm/book3s/64/pgalloc.h

index 76234a14b97d..074359cd632a 100644
--- a/arch/powerpc/include/asm/book3s/64/pgalloc.h
+++ b/arch/powerpc/include/asm/book3s/64/pgalloc.h
@@ -81,7 +81,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  if (radix_enabled())
  return radix__pgd_alloc(mm);

-    pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
+    pgd = kmem_cache_zalloc(PGT_CACHE(PGD_INDEX_SIZE),
 pgtable_gfp_flags(mm, GFP_KERNEL));
  /*
   * Don't scan the PGD for pointers, it contains references to 
PUDs but
@@ -120,7 +120,7 @@ static inline pud_t *pud_alloc_one(struct 
mm_struct *mm, unsigned long addr)

  {
  pud_t *pud;

-    pud = kmem_cache_alloc(PGT_CACHE(PUD_CACHE_INDEX),
+    pud = 

Re: [PATCH 2/2] powerpc: Use ARRAY_SIZE to replace its implementation

2018-08-14 Thread Michael Ellerman
zhong jiang  writes:
> Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.
> So just replace it.
>
> Signed-off-by: zhong jiang 
> ---
>  arch/powerpc/xmon/ppc-opc.c | 12 
>  1 file changed, 4 insertions(+), 8 deletions(-)

This code is copied from binutils and we don't want to needlessly cause
it to diverge from the binutils copy.

So thanks but no thanks.

cheers

> diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
> index ac2b55b..f3f57a1 100644
> --- a/arch/powerpc/xmon/ppc-opc.c
> +++ b/arch/powerpc/xmon/ppc-opc.c
> @@ -966,8 +966,7 @@
>{ 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
>  };
>  
> -const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
> -/ sizeof (powerpc_operands[0]));
> +const unsigned int num_powerpc_operands = ARRAY_SIZE(powerpc_operands);
>  
>  /* The functions used to insert and extract complicated operands.  */
>  
> @@ -6980,8 +6979,7 @@
>  {"fcfidu.",  XRC(63,974,1),  XRA_MASK, POWER7|PPCA2, PPCVLE, {FRT, 
> FRB}},
>  };
>  
> -const int powerpc_num_opcodes =
> -  sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
> +const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes);
>  
>  /* The VLE opcode table.
>  
> @@ -7219,8 +7217,7 @@
>  {"se_bl",BD8(58,0,1),BD8_MASK,   PPCVLE, 0,  {B8}},
>  };
>  
> -const int vle_num_opcodes =
> -  sizeof (vle_opcodes) / sizeof (vle_opcodes[0]);
> +const int vle_num_opcodes = ARRAY_SIZE(vle_opcodes);
>  
>  /* The macro table.  This is only used by the assembler.  */
>  
> @@ -7288,5 +7285,4 @@
>  {"e_clrlslwi",4, PPCVLE, "e_rlwinm %0,%1,%3,(%2)-(%3),31-(%3)"},
>  };
>  
> -const int powerpc_num_macros =
> -  sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
> +const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);
> -- 
> 1.7.12.4


[PATCH 1/2] powerpc/process: fix nested output in show_user_instructions()

2018-08-14 Thread Christophe Leroy
When two processes crash at the same time, we sometimes encounter
nesting in the middle of a line:

[4.365317] init[1]: segfault (11) at 0 nip 0 lr 0 code 1
[4.370452] init[1]: code:    
[4.372042] init[74]: segfault (11) at 10a74 nip 1000c198 lr 100078c8 code 1 
in sh[1000+14000]
[4.386829]    
[4.391542] init[1]: code:      
  
[4.400863] init[74]: code: 90010024 bf61000c 91490a7c 3fa01002 3be0 
7d3e4b78 3bbd0c20 3b60
[4.409867] init[74]: code: 3b9d0040 7c7fe02e 2f83 419e0028 <8923> 
2f89 41be001c 4b7f6e79

This patch fixes it by preparing complete lines in a buffer and
printing it at once.

Fixes: 88b0fe1757359 ("powerpc: Add show_user_instructions()")
Cc: Murilo Opsfelder Araujo 
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/process.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 913c5725cdb2..c722ce4ca1c0 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1303,32 +1303,33 @@ void show_user_instructions(struct pt_regs *regs)
 {
unsigned long pc;
int i;
+   char buf[96]; /* enough for 8 times 9 + 2 chars */
+   int l = 0;
 
pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));
 
-   pr_info("%s[%d]: code: ", current->comm, current->pid);
-
for (i = 0; i < instructions_to_print; i++) {
int instr;
 
if (!(i % 8) && (i > 0)) {
-   pr_cont("\n");
-   pr_info("%s[%d]: code: ", current->comm, current->pid);
+   pr_info("%s[%d]: code: %s\n", current->comm, 
current->pid, buf);
+   l = 0;
}
 
if (probe_kernel_address((unsigned int __user *)pc, instr)) {
-   pr_cont(" ");
+   l += sprintf(buf + l, " ");
} else {
if (regs->nip == pc)
-   pr_cont("<%08x> ", instr);
+   l += sprintf(buf + l, "<%08x> ", instr);
else
-   pr_cont("%08x ", instr);
+   l += sprintf(buf + l, "%08x ", instr);
}
 
pc += sizeof(int);
}
 
-   pr_cont("\n");
+   if (l)
+   pr_info("%s[%d]: code: %s\n", current->comm, current->pid, buf);
 }
 
 struct regbit {
-- 
2.13.3



[PATCH 2/2] powerpc/process: Constify the number of insns printed by show instructions functions.

2018-08-14 Thread Christophe Leroy
instructions_to_print var is assigned value 16 and there is no
way to change it.

This patch replaces it by a constant.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/process.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index c722ce4ca1c0..6317f2ed04ab 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1259,17 +1259,16 @@ struct task_struct *__switch_to(struct task_struct 
*prev,
return last;
 }
 
-static int instructions_to_print = 16;
+#define NR_INSN_TO_PRINT   16
 
 static void show_instructions(struct pt_regs *regs)
 {
int i;
-   unsigned long pc = regs->nip - (instructions_to_print * 3 / 4 *
-   sizeof(int));
+   unsigned long pc = regs->nip - (NR_INSN_TO_PRINT * 3 / 4 * sizeof(int));
 
printk("Instruction dump:");
 
-   for (i = 0; i < instructions_to_print; i++) {
+   for (i = 0; i < NR_INSN_TO_PRINT; i++) {
int instr;
 
if (!(i % 8))
@@ -1306,9 +1305,9 @@ void show_user_instructions(struct pt_regs *regs)
char buf[96]; /* enough for 8 times 9 + 2 chars */
int l = 0;
 
-   pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));
+   pc = regs->nip - (NR_INSN_TO_PRINT * 3 / 4 * sizeof(int));
 
-   for (i = 0; i < instructions_to_print; i++) {
+   for (i = 0; i < NR_INSN_TO_PRINT; i++) {
int instr;
 
if (!(i % 8) && (i > 0)) {
-- 
2.13.3