[PATCH] selftests/powerpc: Fix matrix multiply assist test

2022-06-16 Thread Rashmica Gupta
The ISA states: "when ACC[i] contains defined data, the contents of VSRs
4×i to 4×i+3 are undefined until either a VSX Move From ACC instruction
is used to copy the contents of ACC[i] to VSRs 4×i to 4×i+3 or some other
instruction directly writes to one of these VSRs." We aren't doing this.

This test only works on Power10 because the hardware implementation
happens to map ACC0 to VSRs 0-3, but will fail on any other implementation
that doesn't do this. So add xxmfacc between writing to the accumulator
and accessing the VSRs.

Fixes commit 3527e1ab9a79 ("selftests/powerpc: Add matrix multiply assist
(MMA) test")

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/math/mma.S | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/powerpc/math/mma.S 
b/tools/testing/selftests/powerpc/math/mma.S
index 8528c9849565..61cc88b1b26b 100644
--- a/tools/testing/selftests/powerpc/math/mma.S
+++ b/tools/testing/selftests/powerpc/math/mma.S
@@ -20,6 +20,9 @@ test_mma:
/* xvi16ger2s */
.long   0xec042958
 
+   /* Deprime the accumulator - xxmfacc 0 */
+   .long 0x7c000162
+
/* Store result in image passed in r5 */
stxvw4x 0,0,5
addi5,5,16
-- 
2.35.3



[PATCH] powerpc/signal: Update comment for clarity

2022-06-16 Thread Rashmica Gupta
The comment being referred to was deleted in commit af1bbc3dd3d5 ("powerpc:
Remove UP only lazy floating point and vector optimisations").

Add a bit more detail so it's clear why we need to clear the FP/VEC/VSX
bits here.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/signal_64.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index 472596a109e2..86bb5bb4c143 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -377,9 +377,12 @@ static long notrace __unsafe_restore_sigcontext(struct 
task_struct *tsk, sigset_
unsafe_get_user(set->sig[0], &sc->oldmask, efault_out);
 
/*
-* Force reload of FP/VEC.
-* This has to be done before copying stuff into tsk->thread.fpr/vr
-* for the reasons explained in the previous comment.
+* Force reload of FP/VEC/VSX so userspace sees any changes.
+* Clear these bits from the user process' MSR before copying into the
+* thread struct. If we are rescheduled or preempted and another task
+* uses FP/VEC/VSX, and this process has the MSR bits set, then the
+* context switch code will save the current CPU state into the
+* thread_struct - possibly overwriting the data we are updating here.
 */
regs_set_return_msr(regs, regs->msr & ~(MSR_FP | MSR_FE0 | MSR_FE1 | 
MSR_VEC | MSR_VSX));
 
-- 
2.35.3



[PATCH] powerpc: make facility_unavailable_exception 64s

2022-06-16 Thread Rashmica Gupta
The facility unavailable exception is only available on ppc book3s
machines so use CONFIG_PPC_BOOK3S_64 rather than CONFIG_PPC64.
tm_unavailable is only called from facility_unavailable_exception so can
also be under this Kconfig symbol.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 3aaa50e5c72f..dadfcef5d6db 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -1676,7 +1676,7 @@ DEFINE_INTERRUPT_HANDLER(vsx_unavailable_exception)
die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
 }
 
-#ifdef CONFIG_PPC64
+#ifdef CONFIG_PPC_BOOK3S_64
 static void tm_unavailable(struct pt_regs *regs)
 {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-- 
2.35.3



Re: [PATCH] powerpc/asm-offsets: GPR14 is not needed either

2021-03-24 Thread Rashmica Gupta
On Mon, 2021-03-15 at 11:01 +, Christophe Leroy wrote:
> Commit aac6a91fea93 ("powerpc/asm: Remove unused symbols in
> asm-offsets.c") removed GPR15 to GPR31 but kept GPR14,
> probably because it pops up in a couple of comments when doing
> a grep.
> 
> However, it was never used either, so remove it as well.
> 

Looks good to me.

Reviewed-by: Rashmica Gupta 

> Fixes: aac6a91fea93 ("powerpc/asm: Remove unused symbols in asm-
> offsets.c")
> Cc: Rashmica Gupta 
> Signed-off-by: Christophe Leroy 
> ---
>  arch/powerpc/kernel/asm-offsets.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/asm-offsets.c
> b/arch/powerpc/kernel/asm-offsets.c
> index f3a662201a9f..4d230c5c7099 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -323,9 +323,6 @@ int main(void)
>   STACK_PT_REGS_OFFSET(GPR11, gpr[11]);
>   STACK_PT_REGS_OFFSET(GPR12, gpr[12]);
>   STACK_PT_REGS_OFFSET(GPR13, gpr[13]);
> -#ifndef CONFIG_PPC64
> - STACK_PT_REGS_OFFSET(GPR14, gpr[14]);
> -#endif /* CONFIG_PPC64 */
>   /*
>* Note: these symbols include _ because they overlap with
> special
>* register names



Re: [PATCH 3/3] selftests/powerpc: ensure PMC reads are set and ordered on count_pmc

2020-04-22 Thread Rashmica Gupta
On Wed, 2020-04-08 at 19:35 -0300, Desnes A. Nunes do Rosario wrote:
> Function count_pmc() needs a memory barrier to ensure that PMC reads
> are
> fully consistent. The lack of it can occasionally fail pmc56_overflow
> test,
> since depending on the workload on the system, PMC5 & 6 can have past
> val-
> ues from the time the counters are frozen and turned back on. These
> past
> values will be accounted as overflows and make the test fail.
> 
> =
> test: pmc56_overflow
> ...
> ebb_state:
> ...
> > > pmc[5] count = 0xfd4cbc8c
> > > pmc[6] count = 0xddd8b3b6
> HW state:
> MMCR0 0x8400 FC PMAE
> MMCR2 0x
> EBBHR 0x10003f68
> BESCR 0x8000 GE
> ...
> PMC5  0x
> PMC6  0x
> SIAR  0x10003398
> ...
>   [3]: register SPRN_PMC2  = 0x8003
>   [4]: register SPRN_PMC5  = 0x
>   [5]: register SPRN_PMC6  = 0x
>   [6]: register SPRN_PMC2  = 0x8003
> > > [7]: register SPRN_PMC5  = 0x8f21266d
> > > [8]: register SPRN_PMC6  = 0x0da80f8d
>   [9]: register SPRN_PMC2  = 0x8003
> > > [10]: register SPRN_PMC5  = 0x6e2b961f
> > > [11]: register SPRN_PMC6  = 0xd030a429
>   [12]: register SPRN_PMC2  = 0x8003
>   [13]: register SPRN_PMC5  = 0x
>   [14]: register SPRN_PMC6  = 0x
> ...
> PMC5/6 overflow 2
> [FAIL] Test FAILED on line 87
> failure: pmc56_overflow
> =
> 
> Signed-off-by: Desnes A. Nunes do Rosario 

Reviewed-by: Rashmica Gupta 

> ---
>  tools/testing/selftests/powerpc/pmu/ebb/ebb.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> index bf6f25dfcf7b..6199f3cea0f9 100644
> --- a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> +++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> @@ -258,6 +258,10 @@ int count_pmc(int pmc, uint32_t sample_period)
>   start_value = pmc_sample_period(sample_period);
>  
>   val = read_pmc(pmc);
> +
> + /* Ensure pmc value is consistent between freezes */
> + mb();
> +
>   if (val < start_value)
>   ebb_state.stats.negative++;
>   else



Re: [PATCH, RESEND, 2/3] selftests/powerpc: enable performance alerts when freezing counters on cycles_with_freeze_test selftest

2020-04-22 Thread Rashmica Gupta
On Wed, 2020-04-08 at 19:35 -0300, Desnes A. Nunes do Rosario wrote:
> From: Gustavo Romero 
> 
> When disabling freezing counters by setting MMCR0 FC bit to 0, the
> MMCR0
> PMAE bit must also be enabled if a Performance Monitor Alert (and the
> cor-
> responding Performance Monitor Interrupt) is still desired to be
> received
> when an enabled condition or event occurs.
> 
> This is the case of the cycles_with_freeze_test selftest, since the
> test
> disables the MMCR0 PMAE due to the usage of PMU to trigger EBBs. This
> can
> make the test loop up to the point of being killed by the test
> harness
> timeout (2500 ms), since no other ebb event will happen because the
> MMCR0
> PMAE bit is disabled, and thus, no more increments to ebb_count
> occur.
> 
> Fixes: 3752e453f6bafd7 ("selftests/powerpc: Add tests of PMU EBBs")
> Signed-off-by: Gustavo Romero 
> [desnesn: Only set MMCR0_PMAE when disabling MMCR0_FC, reflow
> comment]
> Signed-off-by: Desnes A. Nunes do Rosario 

Reviewed and Tested-by: Rashmica Gupta 

> ---
>  .../testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c | 2
> +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> index 0f2089f6f82c..d368199144fb 100644
> ---
> a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> +++
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> @@ -81,7 +81,7 @@ int cycles_with_freeze(void)
>   {
>   counters_frozen = false;
>   mb();
> - mtspr(SPRN_MMCR0, mfspr(SPRN_MMCR0) & ~MMCR0_FC);
> + mtspr(SPRN_MMCR0, (mfspr(SPRN_MMCR0) & ~MMCR0_FC) |
> MMCR0_PMAE);
>  
>   FAIL_IF(core_busy_loop());
>  



Re: [PATCH, RESEND, 1/3] selftests/powerpc: Use write_pmc instead of count_pmc to reset PMCs on ebb tests

2020-04-22 Thread Rashmica Gupta
On Wed, 2020-04-08 at 19:35 -0300, Desnes A. Nunes do Rosario wrote:
> By using count_pmc() to reset PMCs instead of write_pmc(), an extra
> count
> is performed on ebb_state.stats.pmc_count[PMC_INDEX(pmc)]. This extra
> pmc_count can occasionally invalidate results, such as the ones from
> cycles_test shown hereafter. The ebb_check_count() failed with an
> above
> the upper limit error due to the extra ebb_state.stats.pmc_count.
> 
> Furthermore, this extra count is also indicated by extra PMC1
> trace_log on
> the output of the cycle test (as well as on pmc56_overflow_test):
> 
> ==
>...
>[21]: counter = 8
>[22]: register SPRN_MMCR0 = 0x8080
>[23]: register SPRN_PMC1  = 0x8004
>[24]: counter = 9
>[25]: register SPRN_MMCR0 = 0x8080
>[26]: register SPRN_PMC1  = 0x8004
>[27]: counter = 10
>[28]: register SPRN_MMCR0 = 0x8080
>[29]: register SPRN_PMC1  = 0x8004
> > > [30]: register SPRN_PMC1  = 0x451e
> PMC1 count (0x28546) above upper limit 0x283e8 (+0x15e)
> [FAIL] Test FAILED on line 52
> failure: cycles
> ==
> 
> [desnesn: reflow of original comment]
> Signed-off-by: Desnes A. Nunes do Rosario 

Reviewed and Tested-by: Rashmica Gupta 

> ---
>  .../powerpc/pmu/ebb/back_to_back_ebbs_test.c |  2 +-
>  .../testing/selftests/powerpc/pmu/ebb/cycles_test.c  |  2 +-
>  .../powerpc/pmu/ebb/cycles_with_freeze_test.c|  2 +-
>  .../powerpc/pmu/ebb/cycles_with_mmcr2_test.c |  2 +-
>  tools/testing/selftests/powerpc/pmu/ebb/ebb.c|  2 +-
>  .../powerpc/pmu/ebb/ebb_on_willing_child_test.c  |  2 +-
>  .../selftests/powerpc/pmu/ebb/lost_exception_test.c  |  2 +-
>  .../selftests/powerpc/pmu/ebb/multi_counter_test.c   | 12 ++--
> 
>  .../selftests/powerpc/pmu/ebb/multi_ebb_procs_test.c |  2 +-
>  .../selftests/powerpc/pmu/ebb/pmae_handling_test.c   |  2 +-
>  .../selftests/powerpc/pmu/ebb/pmc56_overflow_test.c  |  2 +-
>  11 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git
> a/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c
> b/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c
> index a2d7b0e3dca9..f133ab425f10 100644
> ---
> a/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c
> +++
> b/tools/testing/selftests/powerpc/pmu/ebb/back_to_back_ebbs_test.c
> @@ -91,7 +91,7 @@ int back_to_back_ebbs(void)
>   ebb_global_disable();
>   ebb_freeze_pmcs();
>  
> - count_pmc(1, sample_period);
> + write_pmc(1, pmc_sample_period(sample_period));
>  
>   dump_ebb_state();
>  
> diff --git a/tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c
> index bc893813483e..14a399a64729 100644
> --- a/tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c
> +++ b/tools/testing/selftests/powerpc/pmu/ebb/cycles_test.c
> @@ -42,7 +42,7 @@ int cycles(void)
>   ebb_global_disable();
>   ebb_freeze_pmcs();
>  
> - count_pmc(1, sample_period);
> + write_pmc(1, pmc_sample_period(sample_period));
>  
>   dump_ebb_state();
>  
> diff --git
> a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> index dcd351d20328..0f2089f6f82c 100644
> ---
> a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> +++
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_freeze_test.c
> @@ -99,7 +99,7 @@ int cycles_with_freeze(void)
>   ebb_global_disable();
>   ebb_freeze_pmcs();
>  
> - count_pmc(1, sample_period);
> + write_pmc(1, pmc_sample_period(sample_period));
>  
>   dump_ebb_state();
>  
> diff --git
> a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
> index 94c99c12c0f2..a8f3bee04cd8 100644
> ---
> a/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
> +++
> b/tools/testing/selftests/powerpc/pmu/ebb/cycles_with_mmcr2_test.c
> @@ -71,7 +71,7 @@ int cycles_with_mmcr2(void)
>   ebb_global_disable();
>   ebb_freeze_pmcs();
>  
> - count_pmc(1, sample_period);
> + write_pmc(1, pmc_sample_period(sample_period));
>  
>   dump_ebb_state();
>  
> diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> index dfbc5c3ad52d..bf6f25dfcf7b 100644
> --- a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> +++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
> @@ -396,7 +396,7 @@ int ebb_chil

[PATCH] powerpc/mm: Check secondary hash page table

2019-02-12 Thread Rashmica Gupta
We were always calling base_hpte_find() with primary = true,
even when we wanted to check the secondary table...

Fixes: 1515ab932156 powerpc/mm: Dump hash table

Signed-off-by: Rashmica Gupta 
---

Thanks Paul for spotting this :)

 arch/powerpc/mm/dump_hashpagetable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/dump_hashpagetable.c 
b/arch/powerpc/mm/dump_hashpagetable.c
index 869294695048..b430e4e08af6 100644
--- a/arch/powerpc/mm/dump_hashpagetable.c
+++ b/arch/powerpc/mm/dump_hashpagetable.c
@@ -342,7 +342,7 @@ static unsigned long hpte_find(struct pg_state *st, 
unsigned long ea, int psize)
 
/* Look in secondary table */
if (slot == -1)
-   slot = base_hpte_find(ea, psize, true, &v, &r);
+   slot = base_hpte_find(ea, psize, false, &v, &r);
 
/* No entry found */
if (slot == -1)
-- 
2.17.2



[PATCH v2] powerpc/perf: Use PVR rather than oprofile field to determine CPU version

2019-02-05 Thread Rashmica Gupta
Currently the perf CPU backend drivers detect what CPU they're on using
cur_cpu_spec->oprofile_cpu_type.

Although that works, it's a bit crufty to be using oprofile related fields,
especially seeing as oprofile is more or less unused these days.

It also means perf is reliant on the fragile logic in setup_cpu_spec()
which detects when we're using a logical PVR and copies back the PMU
related fields from the raw CPU entry. So lets check the PVR directly.

Suggested-by: Michael Ellerman 
Signed-off-by: Rashmica Gupta 
---
v2: fixed misspelling of PVR_VER_E500V2

 arch/powerpc/perf/e500-pmu.c| 10 ++
 arch/powerpc/perf/e6500-pmu.c   |  5 +++--
 arch/powerpc/perf/hv-24x7.c |  6 +++---
 arch/powerpc/perf/mpc7450-pmu.c |  5 +++--
 arch/powerpc/perf/power5+-pmu.c |  6 +++---
 arch/powerpc/perf/power5-pmu.c  |  5 +++--
 arch/powerpc/perf/power6-pmu.c  |  5 +++--
 arch/powerpc/perf/power7-pmu.c  |  7 ---
 arch/powerpc/perf/power8-pmu.c  |  5 +++--
 arch/powerpc/perf/power9-pmu.c  |  4 +---
 arch/powerpc/perf/ppc970-pmu.c  |  8 +---
 11 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/perf/e500-pmu.c b/arch/powerpc/perf/e500-pmu.c
index fb664929f5da..e1a185a30928 100644
--- a/arch/powerpc/perf/e500-pmu.c
+++ b/arch/powerpc/perf/e500-pmu.c
@@ -122,12 +122,14 @@ static struct fsl_emb_pmu e500_pmu = {
 
 static int init_e500_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type)
-   return -ENODEV;
+   unsigned int pvr = mfspr(SPRN_PVR);
 
-   if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500mc"))
+   /* ec500mc */
+   if ((PVR_VER(pvr) == PVR_VER_E500MC) || (PVR_VER(pvr) == PVR_VER_E5500))
num_events = 256;
-   else if (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500"))
+   /* e500 */
+   else if ((PVR_VER(pvr) != PVR_VER_E500V1) &&
+   (PVR_VER(pvr) != PVR_VER_E500V2))
return -ENODEV;
 
return register_fsl_emb_pmu(&e500_pmu);
diff --git a/arch/powerpc/perf/e6500-pmu.c b/arch/powerpc/perf/e6500-pmu.c
index 3d877aa777b5..47c93d13da1a 100644
--- a/arch/powerpc/perf/e6500-pmu.c
+++ b/arch/powerpc/perf/e6500-pmu.c
@@ -111,8 +111,9 @@ static struct fsl_emb_pmu e6500_pmu = {
 
 static int init_e6500_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type ||
-   strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e6500"))
+   unsigned int pvr = mfspr(SPRN_PVR);
+
+   if (PVR_VER(pvr) != PVR_VER_E6500)
return -ENODEV;
 
return register_fsl_emb_pmu(&e6500_pmu);
diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index 72238eedc360..30dd379ddcd3 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -1583,16 +1583,16 @@ static int hv_24x7_init(void)
 {
int r;
unsigned long hret;
+   unsigned int pvr = mfspr(SPRN_PVR);
struct hv_perf_caps caps;
 
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
pr_debug("not a virtualized system, not enabling\n");
return -ENODEV;
-   } else if (!cur_cpu_spec->oprofile_cpu_type)
-   return -ENODEV;
+   }
 
/* POWER8 only supports v1, while POWER9 only supports v2. */
-   if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power8"))
+   if (PVR_VER(pvr) == PVR_POWER8)
interface_version = 1;
else {
interface_version = 2;
diff --git a/arch/powerpc/perf/mpc7450-pmu.c b/arch/powerpc/perf/mpc7450-pmu.c
index d115c5635bf3..17e69cabbcac 100644
--- a/arch/powerpc/perf/mpc7450-pmu.c
+++ b/arch/powerpc/perf/mpc7450-pmu.c
@@ -413,8 +413,9 @@ struct power_pmu mpc7450_pmu = {
 
 static int __init init_mpc7450_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type ||
-   strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/7450"))
+   unsigned int pvr = mfspr(SPRN_PVR);
+
+   if (PVR_VER(pvr) != PVR_7450)
return -ENODEV;
 
return register_power_pmu(&mpc7450_pmu);
diff --git a/arch/powerpc/perf/power5+-pmu.c b/arch/powerpc/perf/power5+-pmu.c
index 0526dac66007..17a32e7ef234 100644
--- a/arch/powerpc/perf/power5+-pmu.c
+++ b/arch/powerpc/perf/power5+-pmu.c
@@ -679,9 +679,9 @@ static struct power_pmu power5p_pmu = {
 
 static int __init init_power5p_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type ||
-   (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5+")
-&& strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5++")))
+   unsigned int pvr = mfspr(SPRN_PVR);
+
+   if (PVR_VER(pvr) != PVR_POWER5p)
return -ENODEV;
 
return register_power_pmu(&power5p_pmu);
diff --git a/arch/powerpc/perf/power5-pmu.c b/arch/powerpc/perf/power5-pmu.c
index 4dc99f9f7962..844782e6d367 100644
---

[PATCH] powerpc/perf: Use PVR rather than oprofile field to determine CPU version

2019-02-05 Thread Rashmica Gupta
Currently the perf CPU backend drivers detect what CPU they're on using
cur_cpu_spec->oprofile_cpu_type.

Although that works, it's a bit crufty to be using oprofile related fields,
especially seeing as oprofile is more or less unused these days.

It also means perf is reliant on the fragile logic in setup_cpu_spec()
which detects when we're using a logical PVR and copies back the PMU
related fields from the raw CPU entry. So lets check the PVR directly.

Suggested-by: Michael Ellerman 
Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/perf/e500-pmu.c| 10 ++
 arch/powerpc/perf/e6500-pmu.c   |  5 +++--
 arch/powerpc/perf/hv-24x7.c |  6 +++---
 arch/powerpc/perf/mpc7450-pmu.c |  5 +++--
 arch/powerpc/perf/power5+-pmu.c |  6 +++---
 arch/powerpc/perf/power5-pmu.c  |  5 +++--
 arch/powerpc/perf/power6-pmu.c  |  5 +++--
 arch/powerpc/perf/power7-pmu.c  |  7 ---
 arch/powerpc/perf/power8-pmu.c  |  5 +++--
 arch/powerpc/perf/power9-pmu.c  |  4 +---
 arch/powerpc/perf/ppc970-pmu.c  |  8 +---
 11 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/perf/e500-pmu.c b/arch/powerpc/perf/e500-pmu.c
index fb664929f5da..f3a4179f46c6 100644
--- a/arch/powerpc/perf/e500-pmu.c
+++ b/arch/powerpc/perf/e500-pmu.c
@@ -122,12 +122,14 @@ static struct fsl_emb_pmu e500_pmu = {
 
 static int init_e500_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type)
-   return -ENODEV;
+   unsigned int pvr = mfspr(SPRN_PVR);
 
-   if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500mc"))
+   /* ec500mc */
+   if ((PVR_VER(pvr) == PVR_VER_E500MC) || (PVR_VER(pvr) == PVR_VER_E5500))
num_events = 256;
-   else if (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e500"))
+   /* e500 */
+   else if ((PVR_VER(pvr) != PVR_VER_E500V1) &&
+   (PVR_VER(pvr) != PVR_VER_E50V2))
return -ENODEV;
 
return register_fsl_emb_pmu(&e500_pmu);
diff --git a/arch/powerpc/perf/e6500-pmu.c b/arch/powerpc/perf/e6500-pmu.c
index 3d877aa777b5..47c93d13da1a 100644
--- a/arch/powerpc/perf/e6500-pmu.c
+++ b/arch/powerpc/perf/e6500-pmu.c
@@ -111,8 +111,9 @@ static struct fsl_emb_pmu e6500_pmu = {
 
 static int init_e6500_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type ||
-   strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/e6500"))
+   unsigned int pvr = mfspr(SPRN_PVR);
+
+   if (PVR_VER(pvr) != PVR_VER_E6500)
return -ENODEV;
 
return register_fsl_emb_pmu(&e6500_pmu);
diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index 72238eedc360..30dd379ddcd3 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -1583,16 +1583,16 @@ static int hv_24x7_init(void)
 {
int r;
unsigned long hret;
+   unsigned int pvr = mfspr(SPRN_PVR);
struct hv_perf_caps caps;
 
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
pr_debug("not a virtualized system, not enabling\n");
return -ENODEV;
-   } else if (!cur_cpu_spec->oprofile_cpu_type)
-   return -ENODEV;
+   }
 
/* POWER8 only supports v1, while POWER9 only supports v2. */
-   if (!strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power8"))
+   if (PVR_VER(pvr) == PVR_POWER8)
interface_version = 1;
else {
interface_version = 2;
diff --git a/arch/powerpc/perf/mpc7450-pmu.c b/arch/powerpc/perf/mpc7450-pmu.c
index d115c5635bf3..17e69cabbcac 100644
--- a/arch/powerpc/perf/mpc7450-pmu.c
+++ b/arch/powerpc/perf/mpc7450-pmu.c
@@ -413,8 +413,9 @@ struct power_pmu mpc7450_pmu = {
 
 static int __init init_mpc7450_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type ||
-   strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc/7450"))
+   unsigned int pvr = mfspr(SPRN_PVR);
+
+   if (PVR_VER(pvr) != PVR_7450)
return -ENODEV;
 
return register_power_pmu(&mpc7450_pmu);
diff --git a/arch/powerpc/perf/power5+-pmu.c b/arch/powerpc/perf/power5+-pmu.c
index 0526dac66007..17a32e7ef234 100644
--- a/arch/powerpc/perf/power5+-pmu.c
+++ b/arch/powerpc/perf/power5+-pmu.c
@@ -679,9 +679,9 @@ static struct power_pmu power5p_pmu = {
 
 static int __init init_power5p_pmu(void)
 {
-   if (!cur_cpu_spec->oprofile_cpu_type ||
-   (strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5+")
-&& strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5++")))
+   unsigned int pvr = mfspr(SPRN_PVR);
+
+   if (PVR_VER(pvr) != PVR_POWER5p)
return -ENODEV;
 
return register_power_pmu(&power5p_pmu);
diff --git a/arch/powerpc/perf/power5-pmu.c b/arch/powerpc/perf/power5-pmu.c
index 4dc99f9f7962..844782e6d367 100644
--- a/arch/powerpc/perf/power5-pmu.c
+

Re: [PATCH RFCv2 3/6] mm/memory_hotplug: fix online/offline_pages called w.o. mem_hotplug_lock

2018-09-24 Thread Rashmica Gupta
On Mon, 2018-09-17 at 09:32 +0200, David Hildenbrand wrote:
> Am 03.09.18 um 02:36 schrieb Rashmica:
> > Hi David,
> > 
> > 
> > On 21/08/18 20:44, David Hildenbrand wrote:
> > 
> > > There seem to be some problems as result of 30467e0b3be ("mm,
> > > hotplug:
> > > fix concurrent memory hot-add deadlock"), which tried to fix a
> > > possible
> > > lock inversion reported and discussed in [1] due to the two locks
> > >   a) device_lock()
> > >   b) mem_hotplug_lock
> > > 
> > > While add_memory() first takes b), followed by a) during
> > > bus_probe_device(), onlining of memory from user space first took
> > > b),
> > > followed by a), exposing a possible deadlock.
> > 
> > Do you mean "onlining of memory from user space first took a),
> > followed by b)"? 
> 
> Very right, thanks.
> 
> > 
> > > In [1], and it was decided to not make use of
> > > device_hotplug_lock, but
> > > rather to enforce a locking order.
> > > 
> > > The problems I spotted related to this:
> > > 
> > > 1. Memory block device attributes: While .state first calls
> > >mem_hotplug_begin() and the calls device_online() - which
> > > takes
> > >device_lock() - .online does no longer call
> > > mem_hotplug_begin(), so
> > >effectively calls online_pages() without mem_hotplug_lock.
> > > 
> > > 2. device_online() should be called under device_hotplug_lock,
> > > however
> > >onlining memory during add_memory() does not take care of
> > > that.
> > > 
> > > In addition, I think there is also something wrong about the
> > > locking in
> > > 
> > > 3. arch/powerpc/platforms/powernv/memtrace.c calls
> > > offline_pages()
> > >without locks. This was introduced after 30467e0b3be. And
> > > skimming over
> > >the code, I assume it could need some more care in regards to
> > > locking
> > >(e.g. device_online() called without device_hotplug_lock - but
> > > I'll
> > >not touch that for now).
> > 
> > Can you mention that you fixed this in later patches?
> 
> Sure!
> 
> > 
> > 
> > The series looks good to me. Feel free to add my reviewed-by:
> > 
> > Reviewed-by: Rashmica Gupta 
> > 
> 
> Thanks, r-b only for this patch or all of the series?

Sorry, I somehow missed this. To all of the series.
> 


[PATCH] powerpc/memtrace: Remove memory in chunks

2018-08-16 Thread Rashmica Gupta
When hot-removing memory release_mem_region_adjustable() splits iomem
resources if they are not the exact size of the memory being
hot-deleted. Adding this memory back to the kernel adds a new resource.

Eg a node has memory 0x0 - 0xf. Hot-removing 1GB from
0xf4000 results in the single resource 0x0-0xf being split
into two resources: 0x0-0xf3fff and 0xf8000-0xf.

When we hot-add the memory back we now have three resources:
0x0-0xf3fff, 0xf4000-0xf7fff, and 0xf8000-0xf.

This is an issue if we try to remove some memory that overlaps
resources. Eg when trying to remove 2GB at address 0xf4000,
release_mem_region_adjustable() fails as it expects the chunk of memory
to be within the boundaries of a single resource. We then get the
warning: "Unable to release resource" and attempting to use memtrace
again gives us this error: "bash: echo: write error: Resource
temporarily unavailable"

This patch makes memtrace remove memory in chunks that are always the
same size from an address that is always equal to end_of_memory -
n*size, for some n. So hotremoving and hotadding memory of different
sizes will now not attempt to remove memory that spans multiple
resources.

Signed-off-by: Rashmica Gupta 
---

To replicate the above issue hot-remove and hot-add memory of different
sizes a bunch of times. This does it for me on POWER8 and POWER9: 
for i in `seq 1 10`; do
echo $(( $i * 268435456))  >  /sys/kernel/debug/powerpc/memtrace/enable 
echo '.'
done

 arch/powerpc/platforms/powernv/memtrace.c | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/memtrace.c 
b/arch/powerpc/platforms/powernv/memtrace.c
index 51fe0862dcab..c5749f898652 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -119,17 +119,15 @@ static bool memtrace_offline_pages(u32 nid, u64 
start_pfn, u64 nr_pages)
walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE,
  change_memblock_state);
 
-   lock_device_hotplug();
-   remove_memory(nid, start_pfn << PAGE_SHIFT, nr_pages << PAGE_SHIFT);
-   unlock_device_hotplug();
 
return true;
 }
 
 static u64 memtrace_alloc_node(u32 nid, u64 size)
 {
-   u64 start_pfn, end_pfn, nr_pages;
+   u64 start_pfn, end_pfn, nr_pages, pfn;
u64 base_pfn;
+   u64 bytes = memory_block_size_bytes();
 
if (!node_spanned_pages(nid))
return 0;
@@ -142,8 +140,20 @@ static u64 memtrace_alloc_node(u32 nid, u64 size)
end_pfn = round_down(end_pfn - nr_pages, nr_pages);
 
for (base_pfn = end_pfn; base_pfn > start_pfn; base_pfn -= nr_pages) {
-   if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true)
+   if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true) {
+   /* Remove memory in memory block size chunks so that
+* iomem resources are always split to the same size
+* and we never try to remove memory that spans two
+* iomem resources.
+*/
+   lock_device_hotplug();
+   end_pfn = base_pfn + nr_pages;
+   for (pfn = base_pfn; pfn < end_pfn; pfn += bytes>> 
PAGE_SHIFT) {
+   remove_memory(nid, pfn << PAGE_SHIFT, bytes);
+   }
+   unlock_device_hotplug();
return base_pfn << PAGE_SHIFT;
+   }
}
 
return 0;
-- 
2.14.4



Re: [PATCH] lib/test_hexdump: fix failure on big endian cpu

2018-08-08 Thread rashmica



On 08/08/18 17:25, Michael Ellerman wrote:
> Christophe Leroy  writes:
>> diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
>> index 3f415d8101f3..626f580b4ff7 100644
>> --- a/lib/test_hexdump.c
>> +++ b/lib/test_hexdump.c
>> @@ -32,16 +32,33 @@ static const char * const test_data_2_le[] __initconst = 
>> {
>>  "d14c", "9919", "b143", "0caf",
>>  };
>>  
>> +static const char * const test_data_2_be[] __initconst = {
>> +"be32", "db7b", "0a18", "93b2",
>> +"70ba", "c424", "7d83", "349b",
>> +"a69c", "31ad", "9c0f", "ace9",
>> +"4cd1", "1999", "43b1", "af0c",
>> +};
>> +
>>  static const char * const test_data_4_le[] __initconst = {
>>  "7bdb32be", "b293180a", "24c4ba70", "9b34837d",
>>  "ad319ca6", "e9ac0f9c", "9919d14c", "0cafb143",
>>  };
>>  
>> +static const char * const test_data_4_be[] __initconst = {
>> +"be32db7b", "0a1893b2", "70bac424", "7d83349b",
>> +"a69c31ad", "9c0face9", "4cd11999", "43b1af0c",
>> +};
>> +
> Is there a reason we can't do it all at compile time?

mpe I sent a patch doing that awhile ago and you obviously didn't like
it because you never merged it :P
http://patchwork.ozlabs.org/patch/620405/ I prefer this version because
of the IS_ENABLED



> eg:
>
> static const char * const test_data_4[] __initconst = {
> #ifdef CONFIG_CPU_LITTLE_ENDIAN
>   "7bdb32be", "b293180a", "24c4ba70", "9b34837d",
>   "ad319ca6", "e9ac0f9c", "9919d14c", "0cafb143",
> #else
>   "be32db7b", "0a1893b2", "70bac424", "7d83349b",
>   "a69c31ad", "9c0face9", "4cd11999", "43b1af0c",
> #endif
> };
>
>
> cheers



[PATCH 2/2] Update documentation on ppc-memtrace

2018-08-02 Thread Rashmica Gupta
Signed-off-by: Rashmica Gupta 
---
 Documentation/ABI/testing/ppc-memtrace | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/Documentation/ABI/testing/ppc-memtrace 
b/Documentation/ABI/testing/ppc-memtrace
index 2e8b93741270..9606aed33137 100644
--- a/Documentation/ABI/testing/ppc-memtrace
+++ b/Documentation/ABI/testing/ppc-memtrace
@@ -13,10 +13,11 @@ Contact:linuxppc-dev@lists.ozlabs.org
 Description:   Write an integer containing the size in bytes of the memory
you want removed from each NUMA node to this file - it must be
aligned to the memblock size. This amount of RAM will be removed
-   from the kernel mappings and the following debugfs files will be
-   created. This can only be successfully done once per boot. Once
-   memory is successfully removed from each node, the following
-   files are created.
+   from each NUMA node in the kernel mappings and the following
+   debugfs files will be created. Once memory is successfully
+   removed from each node, the following files are created. To
+   re-add memory to the kernel, echo 0 into this file (it will be
+   automatically onlined).
 
 What:  /sys/kernel/debug/powerpc/memtrace/
 Date:  Aug 2017
-- 
2.14.4



[PATCH 1/2] powerpc: Allow memory that has been hot-removed to be hot-added

2018-08-02 Thread Rashmica Gupta
This patch allows the memory removed by memtrace to be readded to the
kernel. So now you don't have to reboot your system to add the memory
back to the kernel or to have a different amount of memory removed.

Signed-off-by: Rashmica Gupta 
---
To remove 1GB from each node:
echo 1073741824  >  /sys/kernel/debug/powerpc/memtrace/enable

To add this memory back and remove 2GB:
echo 2147483648 >  /sys/kernel/debug/powerpc/memtrace/enable 

To just re-add memory:
echo 0  >  /sys/kernel/debug/powerpc/memtrace/enable 


 arch/powerpc/platforms/powernv/memtrace.c | 93 ---
 1 file changed, 86 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/memtrace.c 
b/arch/powerpc/platforms/powernv/memtrace.c
index b99283df8584..51fe0862dcab 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -206,8 +206,11 @@ static int memtrace_init_debugfs(void)
 
snprintf(ent->name, 16, "%08x", ent->nid);
dir = debugfs_create_dir(ent->name, memtrace_debugfs_dir);
-   if (!dir)
+   if (!dir) {
+   pr_err("Failed to create debugfs directory for node 
%d\n",
+   ent->nid);
return -1;
+   }
 
ent->dir = dir;
debugfs_create_file("trace", 0400, dir, ent, &memtrace_fops);
@@ -218,18 +221,94 @@ static int memtrace_init_debugfs(void)
return ret;
 }
 
+static int online_mem_block(struct memory_block *mem, void *arg)
+{
+   return device_online(&mem->dev);
+}
+
+/*
+ * Iterate through the chunks of memory we have removed from the kernel
+ * and attempt to add them back to the kernel.
+ */
+static int memtrace_online(void)
+{
+   int i, ret = 0;
+   struct memtrace_entry *ent;
+
+   for (i = memtrace_array_nr - 1; i >= 0; i--) {
+   ent = &memtrace_array[i];
+
+   /* We have onlined this chunk previously */
+   if (ent->nid == -1)
+   continue;
+
+   /* Remove from io mappings */
+   if (ent->mem) {
+   iounmap(ent->mem);
+   ent->mem = 0;
+   }
+
+   if (add_memory(ent->nid, ent->start, ent->size)) {
+   pr_err("Failed to add trace memory to node %d\n",
+ent->nid);
+   ret += 1;
+   continue;
+   }
+
+   /*
+* If kernel isn't compiled with the auto online option
+* we need to online the memory ourselves.
+*/
+   if (!memhp_auto_online) {
+   walk_memory_range(PFN_DOWN(ent->start),
+   PFN_UP(ent->start + ent->size - 1),
+   NULL, online_mem_block);
+   }
+
+   /*
+* Memory was added successfully so clean up references to it
+* so on reentry we can tell that this chunk was added.
+*/
+   debugfs_remove_recursive(ent->dir);
+   pr_info("Added trace memory back to node %d\n", ent->nid);
+   ent->size = ent->start = ent->nid = -1;
+   }
+   if (ret)
+   return ret;
+
+   /* If all chunks of memory were added successfully, reset globals */
+   kfree(memtrace_array);
+   memtrace_array = NULL;
+   memtrace_size = 0;
+   memtrace_array_nr = 0;
+   return 0;
+
+}
+
 static int memtrace_enable_set(void *data, u64 val)
 {
-   if (memtrace_size)
+   uint64_t bytes;
+
+   /*
+* Don't attempt to do anything if size isn't aligned to a memory
+* block or equal to zero.
+*/
+   bytes = memory_block_size_bytes();
+   if (val & (bytes - 1)) {
+   pr_err("Value must be aligned with 0x%llx\n", bytes);
return -EINVAL;
+   }
 
-   if (!val)
-   return -EINVAL;
+   /* Re-add/online previously removed/offlined memory */
+   if (memtrace_size) {
+   if (memtrace_online())
+   return -EAGAIN;
+   }
 
-   /* Make sure size is aligned to a memory block */
-   if (val & (memory_block_size_bytes() - 1))
-   return -EINVAL;
+   if (!val)
+   return 0;
 
+   /* Offline and remove memory */
if (memtrace_init_regions_runtime(val))
return -EINVAL;
 
-- 
2.14.4



Re: Infinite looping observed in __offline_pages

2018-07-31 Thread Rashmica



On 26/07/18 04:11, John Allen wrote:
> Hi All,
>
> Under heavy stress and constant memory hot add/remove, I have observed
> the following loop to occasionally loop infinitely:
>
> mm/memory_hotplug.c:__offline_pages
>
> repeat:
>    /* start memory hot removal */
>    ret = -EINTR;
>    if (signal_pending(current))
>    goto failed_removal;
>
>    cond_resched();
>    lru_add_drain_all();
>    drain_all_pages(zone);
>
>    pfn = scan_movable_pages(start_pfn, end_pfn);
>    if (pfn) { /* We have movable pages */
>    ret = do_migrate_range(pfn, end_pfn);
>    goto repeat;
>    }
>

What is CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE set to for you?

I have also observed this when hot removing and adding memory. However I
only have only seen this when my kernel has
CONFIG_MEMORY_HOTPLUG_DEFAULT_ONLINE=n (when it is set to online
automatically I do not have this issue) so I assumed that I wasn't
onlining the memory properly...

> What appears to be happening in this case is that do_migrate_range
> returns a failure code which is being ignored. The failure is stemming
> from migrate_pages returning "1" which I'm guessing is the result of
> us hitting the following case:
>
> mm/migrate.c: migrate_pages
>
> default:
>     /*
>  * Permanent failure (-EBUSY, -ENOSYS, etc.):
>  * unlike -EAGAIN case, the failed page is
>  * removed from migration page list and not
>  * retried in the next outer loop.
>  */
>     nr_failed++;
>     break;
> }
>
> Does a failure in do_migrate_range indicate that the range is
> unmigratable and the loop in __offline_pages should terminate and goto
> failed_removal? Or should we allow a certain number of retrys before we
> give up on migrating the range?
>
> This issue was observed on a ppc64le lpar on a 4.18-rc6 kernel.
>
> -John
>



Re: [resend] Revert "powerpc/powernv: Increase memory block size to 1GB on radix"

2018-05-01 Thread rashmica
Tested hot-unplugging dimm device on radix guest on p9 host with KVM.


On 01/05/18 12:57, Balbir Singh wrote:
> This commit was a stop-gap to prevent crashes on hotunplug, caused by
> the mismatch between the 1G mappings used for the linear mapping and the
> memory block size. Those issues are now resolved because we split the
> linear mapping at hotunplug time if necessary, as implemented in commit
> 4dd5f8a99e79 ("powerpc/mm/radix: Split linear mapping on hot-unplug").
>
> Signed-off-by: Balbir Singh 
> Signed-off-by: Michael Neuling 
Tested-by: Rashmica Gupta 
> ---
>
> Resend with a newer commit message grabbed from an email sent by mpe.
>
>  arch/powerpc/platforms/powernv/setup.c | 10 +-
>  1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/platforms/powernv/setup.c 
> b/arch/powerpc/platforms/powernv/setup.c
> index ef8c9ce53a61..fa63d3fff14c 100644
> --- a/arch/powerpc/platforms/powernv/setup.c
> +++ b/arch/powerpc/platforms/powernv/setup.c
> @@ -356,15 +356,7 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int 
> secondary)
>  #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
>  static unsigned long pnv_memory_block_size(void)
>  {
> - /*
> -  * We map the kernel linear region with 1GB large pages on radix. For
> -  * memory hot unplug to work our memory block size must be at least
> -  * this size.
> -  */
> - if (radix_enabled())
> - return 1UL * 1024 * 1024 * 1024;
> - else
> - return 256UL * 1024 * 1024;
> + return 256UL * 1024 * 1024;
>  }
>  #endif
>  



Re: [PATCH 2/2] powerpc/mm/memtrace: Let the arch hotunplug code flush cache

2018-04-10 Thread rashmica


On 06/04/18 15:24, Balbir Singh wrote:
> Don't do this via custom code, instead now that we have support
> in the arch hotplug/hotunplug code, rely on those routines
> to do the right thing.
>
> Fixes: 9d5171a8f248 ("powerpc/powernv: Enable removal of memory for in memory 
> tracing")
> because the older code uses ppc64_caches.l1d.size instead of
> ppc64_caches.l1d.line_size
>
> Signed-off-by: Balbir Singh 

Reviewed-by: Rashmica Gupta 



Re: [PATCH 1/2] powerpc/mm: Flush cache on memory hot(un)plug

2018-04-10 Thread rashmica


On 06/04/18 15:24, Balbir Singh wrote:
> This patch adds support for flushing potentially dirty
> cache lines when memory is hot-plugged/hot-un-plugged.
> The support is currently limited to 64 bit systems.
>
> The bug was exposed when mappings for a device were
> actually hot-unplugged and plugged in back later.
> A similar issue was observed during the development
> of memtrace, but memtrace does it's own flushing of
> region via a custom routine.
>
> These patches do a flush both on hotplug/unplug to
> clear any stale data in the cache w.r.t mappings,
> there is a small race window where a clean cache
> line may be created again just prior to tearing
> down the mapping.
>
> The patches were tested by disabling the flush
> routines in memtrace and doing I/O on the trace
> file. The system immediately checkstops (quite
> reliablly if prior to the hot-unplug of the memtrace
> region, we memset the regions we are about to
> hot unplug). After these patches no custom flushing
> is needed in the memtrace code.
>
> Signed-off-by: Balbir Singh 

Reviewed-by: Rashmica Gupta 




[PATCH v3 3/3] Add documentation for the powerpc memtrace debugfs files

2017-05-31 Thread Rashmica Gupta
CONFIG_PPC64_HARDWARE_TRACING must be set to use this feature. This can only
be used on powernv platforms.

Signed-off-by: Rashmica Gupta 
---
 Documentation/ABI/testing/ppc-memtrace | 45 ++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/ABI/testing/ppc-memtrace

diff --git a/Documentation/ABI/testing/ppc-memtrace 
b/Documentation/ABI/testing/ppc-memtrace
new file mode 100644
index 000..f7eff02
--- /dev/null
+++ b/Documentation/ABI/testing/ppc-memtrace
@@ -0,0 +1,45 @@
+What:  /sys/kernel/debug/powerpc/memtrace
+Date:  May 2017
+KernelVersion: 4.13?
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   This folder contains the relevant debugfs files for the
+   hardware trace macro to use. CONFIG_PPC64_HARDWARE_TRACING
+   must be set.
+
+What:  /sys/kernel/debug/powerpc/memtrace/enable
+Date:  May 2017
+KernelVersion: 4.13?
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   Write an integer containing the size of the memory you want
+   removed from each NUMA node to this file - it must be
+   aligned to the memblock size. This amount of RAM will be
+   removed from the kernel mappings and the following debugfs
+   files will be created. This can only be successfully done
+   once per boot. Once memory is successfully removed from
+   each node, the following files are created.
+
+What:  /sys/kernel/debug/powerpc/memtrace/
+Date:  May 2017
+KernelVersion: 4.13?
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   This directory contains information about the removed memory
+   from the specific NUMA node.
+
+What:  /sys/kernel/debug/powerpc/memtrace//size
+Date:  May 2017
+KernelVersion: 4.13?
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   This contains the size of the memory removed from the node.
+
+What:  /sys/kernel/debug/powerpc/memtrace//start
+Date:  May 2017
+KernelVersion: 4.13?
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   This contains the start address of the removed memory.
+
+What:  /sys/kernel/debug/powerpc/memtrace//trace
+Date:  May 2017
+KernelVersion: 4.13?
+Contact:   linuxppc-dev@lists.ozlabs.org
+Description:   This is where the hardware trace macro will output the trace
+   it generates.
-- 
2.9.3



[PATCH v3 2/3] powerpc/powernv: Enable removal of memory for in memory tracing

2017-05-31 Thread Rashmica Gupta
The hardware trace macro feature requires access to a chunk of real
memory. This patch provides a debugfs interface to do this. By
writing an integer containing the size of memory to be unplugged into
/sys/kernel/debug/powerpc/memtrace/enable, the code will attempt to
remove that much memory from the end of each NUMA node.

This patch also adds additional debugsfs files for each node that
allows the tracer to interact with the removed memory, as well as
a trace file that allows userspace to read the generated trace.

Note that this patch does not invoke the hardware trace macro, it
only allows memory to be removed during runtime for the trace macro
to utilise.

Signed-off-by: Rashmica Gupta 
---
v2 -> v3 : - Some changes required to compile with 4.12-rc3.
- Iterating from end of node rather than the start.
- As io_remap_pfn_range is defined as remap_pfn_range, just use 
remap_pfn_range.
- Removed the creation of the node debugsfs file as it had no use.

 arch/powerpc/platforms/powernv/memtrace.c | 289 ++
 1 file changed, 289 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/memtrace.c

diff --git a/arch/powerpc/platforms/powernv/memtrace.c 
b/arch/powerpc/platforms/powernv/memtrace.c
new file mode 100644
index 000..21fa2e4
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -0,0 +1,289 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) IBM Corporation, 2014
+ *
+ * Author: Anton Blanchard 
+ */
+
+#define pr_fmt(fmt) "powernv-memtrace: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* This enables us to keep track of the memory removed from each node. */
+struct memtrace_entry {
+   void *mem;
+   u64 start;
+   u64 size;
+   u32 nid;
+   struct dentry *dir;
+   char name[16];
+};
+
+static struct memtrace_entry *memtrace_array;
+static unsigned int memtrace_array_nr;
+
+static ssize_t memtrace_read(struct file *filp, char __user *ubuf,
+size_t count, loff_t *ppos)
+{
+   struct memtrace_entry *ent = filp->private_data;
+
+   return simple_read_from_buffer(ubuf, count, ppos, ent->mem, ent->size);
+}
+
+static bool valid_memtrace_range(struct memtrace_entry *dev,
+unsigned long start, unsigned long size)
+{
+   if ((start >= dev->start) &&
+   ((start + size) <= (dev->start + dev->size)))
+   return true;
+
+   return false;
+}
+
+static int memtrace_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+   unsigned long size = vma->vm_end - vma->vm_start;
+   struct memtrace_entry *dev = filp->private_data;
+
+   if (!valid_memtrace_range(dev, vma->vm_pgoff << PAGE_SHIFT, size))
+   return -EINVAL;
+
+   vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+   if (remap_pfn_range(vma, vma->vm_start,
+  vma->vm_pgoff + (dev->start >> PAGE_SHIFT),
+  size, vma->vm_page_prot))
+   return -EAGAIN;
+
+   return 0;
+}
+
+static const struct file_operations memtrace_fops = {
+   .llseek = default_llseek,
+   .read   = memtrace_read,
+   .mmap   = memtrace_mmap,
+   .open   = simple_open,
+};
+
+static void flush_memory_region(u64 base, u64 size)
+{
+   unsigned long line_size = ppc64_caches.l1d.size;
+   u64 end = base + size;
+   u64 addr;
+
+   base = round_down(base, line_size);
+   end = round_up(end, line_size);
+
+   for (addr = base; addr < end; addr += line_size)
+   asm volatile("dcbf 0,%0" : "=r" (addr) :: "memory");
+}
+
+static int check_memblock_online(struct memory_block *mem, void *arg)
+{
+   if (mem->state != MEM_ONLINE)
+   return -1;
+
+   return 0;
+}
+
+static int change_memblock_state(struct memory_block *mem, void *arg)
+{
+   unsigned long state = (unsigned long)arg;
+
+   mem->state = state;
+   return 0;
+}
+
+static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
+{
+   u64 end_pfn = start_pfn + nr_pages - 1;
+
+   if (walk_memory_range(start_pfn, end_pfn, NULL,
+   check_memblock_online))
+   return false;
+
+   walk_memory_range(start_pfn, end_pfn

[PATCH v3 1/3] powerpc/powernv: Add config option for removal of memory

2017-05-31 Thread Rashmica Gupta
This patch adds the config option to enable the removal
of memory from the kernel mappings at runtime. This needs
to be enabled for the hardware trace macro to work.

Signed-off-by: Rashmica Gupta 
---
v2 -> v3: Better description

 arch/powerpc/platforms/powernv/Kconfig  | 8 
 arch/powerpc/platforms/powernv/Makefile | 1 +
 2 files changed, 9 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/Kconfig 
b/arch/powerpc/platforms/powernv/Kconfig
index 6a6f4ef..92493d6 100644
--- a/arch/powerpc/platforms/powernv/Kconfig
+++ b/arch/powerpc/platforms/powernv/Kconfig
@@ -30,3 +30,11 @@ config OPAL_PRD
help
  This enables the opal-prd driver, a facility to run processor
  recovery diagnostics on OpenPower machines
+
+config PPC64_HARDWARE_TRACING
+   bool "Enable removal of RAM from kernel mappings for tracing"
+   help
+ Enabling this option allows for the removal of memory (RAM)
+ from the kernel mappings to be used for hardware tracing.
+   depends on MEMORY_HOTREMOVE
+   default n
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index b5d98cb..8fb026d 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_PPC_SCOM)+= opal-xscom.o
 obj-$(CONFIG_MEMORY_FAILURE)   += opal-memory-errors.o
 obj-$(CONFIG_TRACEPOINTS)  += opal-tracepoints.o
 obj-$(CONFIG_OPAL_PRD) += opal-prd.o
+obj-$(CONFIG_PPC64_HARDWARE_TRACING)   += memtrace.o
-- 
2.9.3



Re: [PATCH 1/6] powerpc/mm: Wire up hpte_removebolted for powernv

2017-05-24 Thread Rashmica Gupta

Looks good to me


On 23/05/17 14:05, Oliver O'Halloran wrote:

From: Anton Blanchard 

Adds support for removing bolted (i.e kernel linear mapping) mappings on
powernv. This is needed to support memory hot unplug operations which
are required for the teardown of DAX/PMEM devices.

Reviewed-by: Rashmica Gupta 

^^ x2

Signed-off-by: Anton Blanchard 
Signed-off-by: Oliver O'Halloran 
---
v1 -> v2: Fixed the commit author
   Added VM_WARN_ON() if we attempt to remove an unbolted hpte
---
  arch/powerpc/mm/hash_native_64.c | 33 +
  1 file changed, 33 insertions(+)

diff --git a/arch/powerpc/mm/hash_native_64.c b/arch/powerpc/mm/hash_native_64.c
index 65bb8f33b399..b534d041cfe8 100644
--- a/arch/powerpc/mm/hash_native_64.c
+++ b/arch/powerpc/mm/hash_native_64.c
@@ -407,6 +407,38 @@ static void native_hpte_updateboltedpp(unsigned long 
newpp, unsigned long ea,
tlbie(vpn, psize, psize, ssize, 0);
  }
  
+/*

+ * Remove a bolted kernel entry. Memory hotplug uses this.
+ *
+ * No need to lock here because we should be the only user.
+ */
+static int native_hpte_removebolted(unsigned long ea, int psize, int ssize)
+{
+   unsigned long vpn;
+   unsigned long vsid;
+   long slot;
+   struct hash_pte *hptep;
+
+   vsid = get_kernel_vsid(ea, ssize);
+   vpn = hpt_vpn(ea, vsid, ssize);
+
+   slot = native_hpte_find(vpn, psize, ssize);
+   if (slot == -1)
+   return -ENOENT;
+
+   hptep = htab_address + slot;
+
+   VM_WARN_ON(!(be64_to_cpu(hptep->v) & HPTE_V_BOLTED));
+
+   /* Invalidate the hpte */
+   hptep->v = 0;
+
+   /* Invalidate the TLB */
+   tlbie(vpn, psize, psize, ssize, 0);
+   return 0;
+}
+
+
  static void native_hpte_invalidate(unsigned long slot, unsigned long vpn,
   int bpsize, int apsize, int ssize, int local)
  {
@@ -725,6 +757,7 @@ void __init hpte_init_native(void)
mmu_hash_ops.hpte_invalidate= native_hpte_invalidate;
mmu_hash_ops.hpte_updatepp  = native_hpte_updatepp;
mmu_hash_ops.hpte_updateboltedpp = native_hpte_updateboltedpp;
+   mmu_hash_ops.hpte_removebolted = native_hpte_removebolted;
mmu_hash_ops.hpte_insert= native_hpte_insert;
mmu_hash_ops.hpte_remove= native_hpte_remove;
mmu_hash_ops.hpte_clear_all = native_hpte_clear;




Re: [PATCH 2/2] v1 powerpc/powernv: Enable removal of memory for in memory tracing

2017-05-14 Thread Rashmica Gupta



On 14/05/17 14:55, Anshuman Khandual wrote:

On 05/09/2017 12:36 PM, Rashmica Gupta wrote:

Sorry for the late reply, I somehow missed this.


On 03/05/17 21:56, Anshuman Khandual wrote:

On 05/03/2017 09:22 AM, Rashmica Gupta wrote:

On 28/04/17 19:52, Anshuman Khandual wrote:

On 04/28/2017 11:12 AM, Rashmica Gupta wrote:

Some powerpc hardware features may want to gain access to a chunk of

What kind of features ? Please add specifics.


undisturbed real memory.  This update provides a means to unplug said
memory

Undisturbed ? Meaning part of memblock and currently inside the buddy
allocator which we are trying to hot unplug out ?


from the kernel with a set of debugfs calls.  By writing an integer
containing
the size of memory to be unplugged into

Does the size has some constraints like aligned with memblock section
size ? LMB size ? page block size ? etc. Please add the details.

Will do.


/sys/kernel/debug/powerpc/memtrace/enable, the code will remove that
much
memory from the end of each available chip's memory space (ie each
memory node).

 amount (I guess bytes in this case) of memory will be removed
from the end of the NUMA node ? Whats the guarantee that they would be
free at that time and not being pinned by some process ? If its not
guaranteed to be freed, then interface description should state that
clearly.

We start looking from the end of the NUMA node but of course there is no
guarantee
that we will always be able to find some memory there that we are able
to remove.

Okay. Do we have interface for giving this memory back to the buddy
allocator again when we are done with HW tracing ? If not we need to
add one.

Not at the moment. Last time I spoke to Anton he said something along
the lines
of it not being too important as if you are getting the hardware traces
for debugging
purposes you are probably not worried about a bit of memory being out of
action.

However I can't see why having an interface to online the memory would
be a bad thing,
so I'll look into it.

Yes, the interface to put them back into buddy is important even if the
amount of memory is very less for tracing. Just need to trigger hotplug
and online procedure to put it back.


In addition, the means to read out the contents of the unplugged
memory is also
provided by reading out the
/sys/kernel/debug/powerpc/memtrace//trace
file.

All of the debugfs file interfaces added here should be documented some
where in detail.


Signed-off-by: Anton Blanchard 
Signed-off-by: Rashmica Gupta 

---
This requires the 'Wire up hpte_removebolted for powernv' patch.

RFC -> v1: Added in two missing locks. Replaced the open-coded
flush_memory_region() with the existing
flush_inval_dcache_range(start, end).

memtrace_offline_pages() is open-coded because offline_pages is
designed to be
called through the sysfs interface - not directly.

We could move the offlining of pages to userspace, which removes some
of this
open-coding. This would then require passing info to the kernel such
that it
can then remove the memory that has been offlined. This could be done
using
notifiers, but this isn't simple due to locking (remove_memory needs
mem_hotplug_begin() which the sysfs interface already has). This
could also be
done through the debugfs interface (similar to what is done here).
Either way,
this would require the process that needs the memory to have
open-coded code
which it shouldn't really be involved with.

As the current remove_memory() function requires the memory to
already be
offlined, it makes sense to keep the offlining and removal of memory
functionality grouped together so that a process can simply make one
request to
unplug some memory. Ideally there would be a kernel function we could
call that
would offline the memory and then remove it.


arch/powerpc/platforms/powernv/memtrace.c | 276
++
1 file changed, 276 insertions(+)
create mode 100644 arch/powerpc/platforms/powernv/memtrace.c

diff --git a/arch/powerpc/platforms/powernv/memtrace.c
b/arch/powerpc/platforms/powernv/memtrace.c
new file mode 100644
index 000..86184b1
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -0,0 +1,276 @@
+/*
+ * This program is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as
published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) IBM Corporation, 2014
+ *
+ * Author: Anton Blanchard 
+ */
+
+#define pr_fmt(fmt) "powernv-memtrace: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#inc

Re: [PATCH 2/2] v1 powerpc/powernv: Enable removal of memory for in memory tracing

2017-05-09 Thread Rashmica Gupta

Sorry for the late reply, I somehow missed this.


On 03/05/17 21:56, Anshuman Khandual wrote:

On 05/03/2017 09:22 AM, Rashmica Gupta wrote:

On 28/04/17 19:52, Anshuman Khandual wrote:

On 04/28/2017 11:12 AM, Rashmica Gupta wrote:

Some powerpc hardware features may want to gain access to a chunk of

What kind of features ? Please add specifics.


undisturbed real memory.  This update provides a means to unplug said
memory

Undisturbed ? Meaning part of memblock and currently inside the buddy
allocator which we are trying to hot unplug out ?


from the kernel with a set of debugfs calls.  By writing an integer
containing
   the size of memory to be unplugged into

Does the size has some constraints like aligned with memblock section
size ? LMB size ? page block size ? etc. Please add the details.

Will do.


/sys/kernel/debug/powerpc/memtrace/enable, the code will remove that
much
memory from the end of each available chip's memory space (ie each
memory node).

 amount (I guess bytes in this case) of memory will be removed
from the end of the NUMA node ? Whats the guarantee that they would be
free at that time and not being pinned by some process ? If its not
guaranteed to be freed, then interface description should state that
clearly.

We start looking from the end of the NUMA node but of course there is no
guarantee
that we will always be able to find some memory there that we are able
to remove.


Okay. Do we have interface for giving this memory back to the buddy
allocator again when we are done with HW tracing ? If not we need to
add one.


Not at the moment. Last time I spoke to Anton he said something along 
the lines
of it not being too important as if you are getting the hardware traces 
for debugging
purposes you are probably not worried about a bit of memory being out of 
action.


However I can't see why having an interface to online the memory would 
be a bad thing,

so I'll look into it.


In addition, the means to read out the contents of the unplugged
memory is also
provided by reading out the
/sys/kernel/debug/powerpc/memtrace//trace
file.

All of the debugfs file interfaces added here should be documented some
where in detail.


Signed-off-by: Anton Blanchard 
Signed-off-by: Rashmica Gupta 

---
This requires the 'Wire up hpte_removebolted for powernv' patch.

RFC -> v1: Added in two missing locks. Replaced the open-coded
flush_memory_region() with the existing
flush_inval_dcache_range(start, end).

memtrace_offline_pages() is open-coded because offline_pages is
designed to be
called through the sysfs interface - not directly.

We could move the offlining of pages to userspace, which removes some
of this
open-coding. This would then require passing info to the kernel such
that it
can then remove the memory that has been offlined. This could be done
using
notifiers, but this isn't simple due to locking (remove_memory needs
mem_hotplug_begin() which the sysfs interface already has). This
could also be
done through the debugfs interface (similar to what is done here).
Either way,
this would require the process that needs the memory to have
open-coded code
which it shouldn't really be involved with.

As the current remove_memory() function requires the memory to
already be
offlined, it makes sense to keep the offlining and removal of memory
functionality grouped together so that a process can simply make one
request to
unplug some memory. Ideally there would be a kernel function we could
call that
would offline the memory and then remove it.


   arch/powerpc/platforms/powernv/memtrace.c | 276
++
   1 file changed, 276 insertions(+)
   create mode 100644 arch/powerpc/platforms/powernv/memtrace.c

diff --git a/arch/powerpc/platforms/powernv/memtrace.c
b/arch/powerpc/platforms/powernv/memtrace.c
new file mode 100644
index 000..86184b1
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -0,0 +1,276 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) IBM Corporation, 2014
+ *
+ * Author: Anton Blanchard 
+ */
+
+#define pr_fmt(fmt) "powernv-memtrace: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct memtrace_entry {
+void *mem;
+u64 start;
+u64 size;
+u32 nid;
+struct dentry *dir;
+char name[16];
+};

Little bit of description about the structure here will help.

Something like 'thi

Re: [PATCH 2/2] v1 powerpc/powernv: Enable removal of memory for in memory tracing

2017-05-02 Thread Rashmica Gupta



On 03/05/17 13:52, Rashmica Gupta wrote:

On 28/04/17 19:52, Anshuman Khandual wrote:


+static int check_memblock_online(struct memory_block *mem, void *arg)
+{
+if (mem->state != MEM_ONLINE)
+return -1;
+
+return 0;
+}
+
+static int change_memblock_state(struct memory_block *mem, void *arg)
+{
+unsigned long state = (unsigned long)arg;
+
+mem->state = state;
+return 0;
+}
+
+static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 
nr_pages)

+{
+u64 end_pfn = start_pfn + nr_pages - 1;
+
+if (walk_memory_range(start_pfn, end_pfn, NULL,
+check_memblock_online))
+return false;
+
+walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE,
+  change_memblock_state);
+

walk_memory_range() might be expensive, cant we just change the state
to MEM_GOING_OFFLINE while checking the state for MEM_ONLINE during
the first loop and bail out if any of the memblock is not in MEM_ONLINE
in the first place.


Good idea.



This is assuming that it's more likely that the state of memory will be 
MEM_ONLINE rather than anything else (if the state isn't MEM_ONLINE we 
will still have to do a second call of walk_memory_range() to revert the 
state of any memory blocks that we changed). Seems like a reasonable 
assumption to me, thoughts?






Re: [PATCH 2/2] v1 powerpc/powernv: Enable removal of memory for in memory tracing

2017-05-02 Thread Rashmica Gupta



On 03/05/17 13:52, Rashmica Gupta wrote:

On 28/04/17 19:52, Anshuman Khandual wrote:


+static int check_memblock_online(struct memory_block *mem, void *arg)
+{
+if (mem->state != MEM_ONLINE)
+return -1;
+
+return 0;
+}
+
+static int change_memblock_state(struct memory_block *mem, void *arg)
+{
+unsigned long state = (unsigned long)arg;
+
+mem->state = state;
+return 0;
+}
+
+static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 
nr_pages)

+{
+u64 end_pfn = start_pfn + nr_pages - 1;
+
+if (walk_memory_range(start_pfn, end_pfn, NULL,
+check_memblock_online))
+return false;
+
+walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE,
+  change_memblock_state);
+

walk_memory_range() might be expensive, cant we just change the state
to MEM_GOING_OFFLINE while checking the state for MEM_ONLINE during
the first loop and bail out if any of the memblock is not in MEM_ONLINE
in the first place.


Good idea.



This is assuming that it's more likely that the state of memory will be 
MEM_ONLINE rather than anything else (if the state isn't MEM_ONLINE we 
will still have to do a second call of walk_memory_range() to revert the 
state of any memory blocks that we changed). Seems like a reasonable 
assumption to me, thoughts?






Re: [PATCH 2/2] v1 powerpc/powernv: Enable removal of memory for in memory tracing

2017-05-02 Thread Rashmica Gupta

On 28/04/17 19:52, Anshuman Khandual wrote:

On 04/28/2017 11:12 AM, Rashmica Gupta wrote:

Some powerpc hardware features may want to gain access to a chunk of

What kind of features ? Please add specifics.


undisturbed real memory.  This update provides a means to unplug said memory

Undisturbed ? Meaning part of memblock and currently inside the buddy
allocator which we are trying to hot unplug out ?


from the kernel with a set of debugfs calls.  By writing an integer containing
  the size of memory to be unplugged into

Does the size has some constraints like aligned with memblock section
size ? LMB size ? page block size ? etc. Please add the details.


Will do.




/sys/kernel/debug/powerpc/memtrace/enable, the code will remove that much
memory from the end of each available chip's memory space (ie each memory node).

 amount (I guess bytes in this case) of memory will be removed
from the end of the NUMA node ? Whats the guarantee that they would be
free at that time and not being pinned by some process ? If its not
guaranteed to be freed, then interface description should state that
clearly.


We start looking from the end of the NUMA node but of course there is no 
guarantee
that we will always be able to find some memory there that we are able 
to remove.



In addition, the means to read out the contents of the unplugged memory is also
provided by reading out the /sys/kernel/debug/powerpc/memtrace//trace
file.

All of the debugfs file interfaces added here should be documented some
where in detail.


Signed-off-by: Anton Blanchard 
Signed-off-by: Rashmica Gupta 

---
This requires the 'Wire up hpte_removebolted for powernv' patch.

RFC -> v1: Added in two missing locks. Replaced the open-coded 
flush_memory_region() with the existing
flush_inval_dcache_range(start, end).

memtrace_offline_pages() is open-coded because offline_pages is designed to be
called through the sysfs interface - not directly.

We could move the offlining of pages to userspace, which removes some of this
open-coding. This would then require passing info to the kernel such that it
can then remove the memory that has been offlined. This could be done using
notifiers, but this isn't simple due to locking (remove_memory needs
mem_hotplug_begin() which the sysfs interface already has). This could also be
done through the debugfs interface (similar to what is done here). Either way,
this would require the process that needs the memory to have open-coded code
which it shouldn't really be involved with.

As the current remove_memory() function requires the memory to already be
offlined, it makes sense to keep the offlining and removal of memory
functionality grouped together so that a process can simply make one request to
unplug some memory. Ideally there would be a kernel function we could call that
would offline the memory and then remove it.


  arch/powerpc/platforms/powernv/memtrace.c | 276 ++
  1 file changed, 276 insertions(+)
  create mode 100644 arch/powerpc/platforms/powernv/memtrace.c

diff --git a/arch/powerpc/platforms/powernv/memtrace.c 
b/arch/powerpc/platforms/powernv/memtrace.c
new file mode 100644
index 000..86184b1
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -0,0 +1,276 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) IBM Corporation, 2014
+ *
+ * Author: Anton Blanchard 
+ */
+
+#define pr_fmt(fmt) "powernv-memtrace: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct memtrace_entry {
+   void *mem;
+   u64 start;
+   u64 size;
+   u32 nid;
+   struct dentry *dir;
+   char name[16];
+};

Little bit of description about the structure here will help.


Something like 'this enables us to keep track of the memory removed from 
each node'?



+
+static struct memtrace_entry *memtrace_array;
+static unsigned int memtrace_array_nr;
+
+static ssize_t memtrace_read(struct file *filp, char __user *ubuf,
+size_t count, loff_t *ppos)
+{
+   struct memtrace_entry *ent = filp->private_data;
+
+   return simple_read_from_buffer(ubuf, count, ppos, ent->mem, ent->size);
+}
+
+static bool valid_memtrace_range(struct memtrace_entry *dev,
+unsigned long start, unsigned long size)
+{
+   if ((dev->start <= start) &&

Swi

Re: [PATCH 1/2] powerpc/powernv: Add config option for removal of memory

2017-05-02 Thread Rashmica Gupta


On 28/04/17 19:39, Anshuman Khandual wrote:

On 04/28/2017 11:12 AM, Rashmica Gupta wrote:

Signed-off-by: Rashmica Gupta 

Please describe a bit about the function/feature you are trying
to add with this new config option. The subject says " Add config
option for removal of memory" but I guess its not related to
memory hotplug but about hardware enabled tracing IIUC.


Correct!


Hence
it should have some amount of description.


---
  arch/powerpc/platforms/powernv/Kconfig  | 4 
  arch/powerpc/platforms/powernv/Makefile | 1 +
  2 files changed, 5 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/Kconfig 
b/arch/powerpc/platforms/powernv/Kconfig
index 6a6f4ef..1b8b3a8 100644
--- a/arch/powerpc/platforms/powernv/Kconfig
+++ b/arch/powerpc/platforms/powernv/Kconfig
@@ -30,3 +30,7 @@ config OPAL_PRD
help
  This enables the opal-prd driver, a facility to run processor
  recovery diagnostics on OpenPower machines
+
+config HARDWARE_TRACING

This is too generic for platform specific feature and also it does
not intend to fit into a generic HW tracing infrastructure. IMHO
it should be named something like "PPC64_HARDWARE_TRACING" or
something similar.


+   bool 'Enable removal of memory for hardware memory tracing'

If this memory is going to be taken out of memblock like normal
memory hotplug and eventually goes away from kernel control, then
you need to be more specific about its usage.



All good points! Thanks for the review.


[PATCH 2/2] v1 powerpc/powernv: Enable removal of memory for in memory tracing

2017-04-27 Thread Rashmica Gupta
Some powerpc hardware features may want to gain access to a chunk of
undisturbed real memory.  This update provides a means to unplug said memory
from the kernel with a set of debugfs calls.  By writing an integer containing
 the size of memory to be unplugged into
/sys/kernel/debug/powerpc/memtrace/enable, the code will remove that much
memory from the end of each available chip's memory space (ie each memory node).
In addition, the means to read out the contents of the unplugged memory is also
provided by reading out the /sys/kernel/debug/powerpc/memtrace//trace
file.

Signed-off-by: Anton Blanchard 
Signed-off-by: Rashmica Gupta 

---
This requires the 'Wire up hpte_removebolted for powernv' patch.

RFC -> v1: Added in two missing locks. Replaced the open-coded 
flush_memory_region() with the existing
flush_inval_dcache_range(start, end).

memtrace_offline_pages() is open-coded because offline_pages is designed to be
called through the sysfs interface - not directly.

We could move the offlining of pages to userspace, which removes some of this
open-coding. This would then require passing info to the kernel such that it
can then remove the memory that has been offlined. This could be done using
notifiers, but this isn't simple due to locking (remove_memory needs
mem_hotplug_begin() which the sysfs interface already has). This could also be
done through the debugfs interface (similar to what is done here). Either way,
this would require the process that needs the memory to have open-coded code
which it shouldn't really be involved with.

As the current remove_memory() function requires the memory to already be
offlined, it makes sense to keep the offlining and removal of memory
functionality grouped together so that a process can simply make one request to
unplug some memory. Ideally there would be a kernel function we could call that
would offline the memory and then remove it.


 arch/powerpc/platforms/powernv/memtrace.c | 276 ++
 1 file changed, 276 insertions(+)
 create mode 100644 arch/powerpc/platforms/powernv/memtrace.c

diff --git a/arch/powerpc/platforms/powernv/memtrace.c 
b/arch/powerpc/platforms/powernv/memtrace.c
new file mode 100644
index 000..86184b1
--- /dev/null
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -0,0 +1,276 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) IBM Corporation, 2014
+ *
+ * Author: Anton Blanchard 
+ */
+
+#define pr_fmt(fmt) "powernv-memtrace: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct memtrace_entry {
+   void *mem;
+   u64 start;
+   u64 size;
+   u32 nid;
+   struct dentry *dir;
+   char name[16];
+};
+
+static struct memtrace_entry *memtrace_array;
+static unsigned int memtrace_array_nr;
+
+static ssize_t memtrace_read(struct file *filp, char __user *ubuf,
+size_t count, loff_t *ppos)
+{
+   struct memtrace_entry *ent = filp->private_data;
+
+   return simple_read_from_buffer(ubuf, count, ppos, ent->mem, ent->size);
+}
+
+static bool valid_memtrace_range(struct memtrace_entry *dev,
+unsigned long start, unsigned long size)
+{
+   if ((dev->start <= start) &&
+   ((start + size) <= (dev->start + dev->size)))
+   return true;
+
+   return false;
+}
+
+static int memtrace_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+   unsigned long size = vma->vm_end - vma->vm_start;
+   struct memtrace_entry *dev = filp->private_data;
+
+   if (!valid_memtrace_range(dev, vma->vm_pgoff << PAGE_SHIFT, size))
+   return -EINVAL;
+
+   vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+   if (io_remap_pfn_range(vma, vma->vm_start,
+  vma->vm_pgoff + (dev->start >> PAGE_SHIFT),
+  size, vma->vm_page_prot))
+   return -EAGAIN;
+
+   return 0;
+}
+
+static const struct file_operations memtrace_fops = {
+   .llseek = default_llseek,
+   .read   = memtrace_read,
+   .mmap   = memtrace_mmap,
+   .open   = simple_open,
+};
+
+static int check_memblock_online(struct memory_block *mem, void *arg)
+{
+   if (mem->state != MEM_ONLINE)
+   return -1;
+
+   return 0;
+}

[PATCH 1/2] powerpc/powernv: Add config option for removal of memory

2017-04-27 Thread Rashmica Gupta
Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/platforms/powernv/Kconfig  | 4 
 arch/powerpc/platforms/powernv/Makefile | 1 +
 2 files changed, 5 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/Kconfig 
b/arch/powerpc/platforms/powernv/Kconfig
index 6a6f4ef..1b8b3a8 100644
--- a/arch/powerpc/platforms/powernv/Kconfig
+++ b/arch/powerpc/platforms/powernv/Kconfig
@@ -30,3 +30,7 @@ config OPAL_PRD
help
  This enables the opal-prd driver, a facility to run processor
  recovery diagnostics on OpenPower machines
+
+config HARDWARE_TRACING
+   bool 'Enable removal of memory for hardware memory tracing'
+   depends on PPC_POWERNV && MEMORY_HOTPLUG
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index b5d98cb..e61be1b 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -12,3 +12,4 @@ obj-$(CONFIG_PPC_SCOM)+= opal-xscom.o
 obj-$(CONFIG_MEMORY_FAILURE)   += opal-memory-errors.o
 obj-$(CONFIG_TRACEPOINTS)  += opal-tracepoints.o
 obj-$(CONFIG_OPAL_PRD) += opal-prd.o
+obj-$(CONFIG_HARDWARE_TRACING) += memtrace.o
-- 
2.9.3



Re: [PATCH] powerpc/xmon: Deindent the SLB dumping logic

2017-04-23 Thread Rashmica Gupta


On 24/04/17 10:35, Michael Ellerman wrote:

Currently the code that dumps SLB entries uses a double-nested if. This
means the actual dumping logic is a bit squashed. Deindent it by using
continue.

Signed-off-by: Michael Ellerman 


Reviewed-by: Rashmica Gupta 


---
  arch/powerpc/xmon/xmon.c | 39 ++-
  1 file changed, 22 insertions(+), 17 deletions(-)

Found lying around in an old tree of mine :}

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 16321ad9e70c..199ba2663f21 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -3070,23 +3070,28 @@ void dump_segments(void)
for (i = 0; i < mmu_slb_size; i++) {
asm volatile("slbmfee  %0,%1" : "=r" (esid) : "r" (i));
asm volatile("slbmfev  %0,%1" : "=r" (vsid) : "r" (i));
-   if (esid || vsid) {
-   printf("%02d %016lx %016lx", i, esid, vsid);
-   if (esid & SLB_ESID_V) {
-   llp = vsid & SLB_VSID_LLP;
-   if (vsid & SLB_VSID_B_1T) {
-   printf("  1T  ESID=%9lx  VSID=%13lx LLP:%3lx 
\n",
-   GET_ESID_1T(esid),
-   (vsid & ~SLB_VSID_B) >> 
SLB_VSID_SHIFT_1T,
-   llp);
-   } else {
-   printf(" 256M ESID=%9lx  VSID=%13lx LLP:%3lx 
\n",
-   GET_ESID(esid),
-   (vsid & ~SLB_VSID_B) >> 
SLB_VSID_SHIFT,
-   llp);
-   }
-   } else
-   printf("\n");
+
+   if (!esid && !vsid)
+   continue;
+
+   printf("%02d %016lx %016lx", i, esid, vsid);
+
+   if (!(esid & SLB_ESID_V)) {
+   printf("\n");
+   continue;
+   }
+
+   llp = vsid & SLB_VSID_LLP;
+   if (vsid & SLB_VSID_B_1T) {
+   printf("  1T  ESID=%9lx  VSID=%13lx LLP:%3lx \n",
+   GET_ESID_1T(esid),
+   (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT_1T,
+   llp);
+   } else {
+   printf(" 256M ESID=%9lx  VSID=%13lx LLP:%3lx \n",
+   GET_ESID(esid),
+   (vsid & ~SLB_VSID_B) >> SLB_VSID_SHIFT,
+   llp);
}
}
  }




Re: [PATCH 2/2] powerpc/mm: add phys addr to linux page table dump

2017-04-11 Thread Rashmica Gupta



On 31/03/17 12:37, Oliver O'Halloran wrote:

The current page table dumper scans the linux page tables and coalesces
mappings with adjacent virtual addresses and similar PTE flags. This
behaviour is somewhat broken when you consider the IOREMAP space where
entirely unrelated mappings will appear to be contiguous.  This patch
modifies the range coalescing so that only ranges that are both physically
and virtually contiguous are combined. This patch also adds to the dump
output the physical address at the start of each range.

Cc: Rashmica Gupta 
Signed-off-by: Oliver O'Halloran 
---
  arch/powerpc/mm/dump_linuxpagetables.c | 18 --
  1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/dump_linuxpagetables.c 
b/arch/powerpc/mm/dump_linuxpagetables.c
index e7cbfd5a0940..85e6a45bd7ee 100644
--- a/arch/powerpc/mm/dump_linuxpagetables.c
+++ b/arch/powerpc/mm/dump_linuxpagetables.c
@@ -56,6 +56,8 @@ struct pg_state {
struct seq_file *seq;
const struct addr_marker *marker;
unsigned long start_address;
+   unsigned long start_pa;
+   unsigned long last_pa;
unsigned int level;
u64 current_flags;
  };
@@ -265,7 +267,9 @@ static void dump_addr(struct pg_state *st, unsigned long 
addr)
const char *unit = units;
unsigned long delta;
  
-	seq_printf(st->seq, "0x%016lx-0x%016lx   ", st->start_address, addr-1);

+   seq_printf(st->seq, "0x%016lx-0x%016lx ", st->start_address, addr-1);
+   seq_printf(st->seq, "%016lx ", st->start_pa);
+
delta = (addr - st->start_address) >> 10;
/* Work out what appropriate unit to use */
while (!(delta & 1023) && unit[1]) {
@@ -280,11 +284,15 @@ static void note_page(struct pg_state *st, unsigned long 
addr,
   unsigned int level, u64 val)
  {
u64 flag = val & pg_level[level].mask;
+   u64 pa = val & PTE_RPN_MASK;
+
/* At first no level is set */
if (!st->level) {
st->level = level;
st->current_flags = flag;
st->start_address = addr;
+   st->start_pa = pa;
+   st->last_pa = pa;
seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
/*
 * Dump the section of virtual memory when:
@@ -292,9 +300,11 @@ static void note_page(struct pg_state *st, unsigned long 
addr,
 *   - we change levels in the tree.
 *   - the address is in a different section of memory and is thus
 *   used for a different purpose, regardless of the flags.
+*   - the pa of this page is not adjacent to the last inspected page
 */
} else if (flag != st->current_flags || level != st->level ||
-  addr >= st->marker[1].start_address) {
+  addr >= st->marker[1].start_address ||
+  pa != st->last_pa + PAGE_SIZE) {
  
  		/* Check the PTE flags */

if (st->current_flags) {
@@ -318,8 +328,12 @@ static void note_page(struct pg_state *st, unsigned long 
addr,
seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
}
st->start_address = addr;
+   st->start_pa = pa;
+   st->last_pa = pa;
    st->current_flags = flag;
st->level = level;
+   } else {
+   st->last_pa = pa;
}
  }
  

Makes sense to me!
Reviewed-by: Rashmica Gupta 


Re: [PATCH 1/2] powerpc/mm: fix up pgtable dump flags

2017-04-11 Thread Rashmica Gupta


On 31/03/17 12:37, Oliver O'Halloran wrote:

On Book3s we have two PTE flags used to mark cache-inhibited mappings:
_PAGE_TOLERANT and _PAGE_NON_IDEMPOTENT. Currently the kernel page
table dumper only looks at the generic _PAGE_NO_CACHE which is
defined to be _PAGE_TOLERANT. This patch modifies the dumper so
both flags are shown in the dump.

Cc: Rashmica Gupta 
Signed-off-by: Oliver O'Halloran 

Should we also add in _PAGE_SAO  that is in Book3s?



---
  arch/powerpc/mm/dump_linuxpagetables.c | 13 +
  1 file changed, 13 insertions(+)

diff --git a/arch/powerpc/mm/dump_linuxpagetables.c 
b/arch/powerpc/mm/dump_linuxpagetables.c
index 49abaf4dc8e3..e7cbfd5a0940 100644
--- a/arch/powerpc/mm/dump_linuxpagetables.c
+++ b/arch/powerpc/mm/dump_linuxpagetables.c
@@ -154,11 +154,24 @@ static const struct flag_info flag_array[] = {
.clear  = " ",
}, {
  #endif
+#ifndef CONFIG_PPC_BOOK3S_64
.mask   = _PAGE_NO_CACHE,
.val= _PAGE_NO_CACHE,
.set= "no cache",
.clear  = "",
}, {
+#else
+   .mask   = _PAGE_NON_IDEMPOTENT,
+   .val= _PAGE_NON_IDEMPOTENT,
+   .set= "non-idempotent",
+   .clear  = "  ",
+   }, {
+   .mask   = _PAGE_TOLERANT,
+   .val= _PAGE_TOLERANT,
+   .set= "tolerant",
+   .clear  = "",
+   }, {
+#endif
  #ifdef CONFIG_PPC_BOOK3S_64
.mask   = H_PAGE_BUSY,
.val= H_PAGE_BUSY,




Re: [PATCH 8/9] powerpc/mm: Wire up hpte_removebolted for powernv

2017-04-11 Thread Rashmica Gupta



On 12/04/17 10:18, Stephen Rothwell wrote:

Hi Oliver,

On Wed, 12 Apr 2017 08:50:56 +1000 Anton Blanchard  wrote:

From: Rashmica Gupta 

Adds support for removing bolted (i.e kernel linear mapping) mappings
on powernv. This is needed to support memory hot unplug operations
which are required for the teardown of DAX/PMEM devices.

Cc: Rashmica Gupta 
Cc: Anton Blanchard 
Signed-off-by: Oliver O'Halloran 
---
Could the original author of this add their S-o-b? I pulled it out of
Rashmica's memtrace patch, but I remember someone saying Anton wrote
it originally.

I did.

Signed-off-by: Anton Blanchard 

If you are going to claim that Rashmica authored this patch (and you do
with the From: line above), then you need her Signed-off-by as well.


Oliver, can you change the 'From' to a 'Reviewed By'?


[PATCH] powerpc/mm: Dump hash table

2017-04-09 Thread Rashmica Gupta
Current behaviour assumes that memory in RAM is contiguous and
iterates from the start of RAM to (start + size of memory). When the
memory isn't physically contiguous, this approach doesn't work.

If memory exists at 0-5 GB and 6-10 GB then the current approach will
check if entries exist in the hash table from 0GB to 9GB. This patch
changes the behaviour to iterate up to the end of RAM.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/mm/dump_hashpagetable.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/dump_hashpagetable.c 
b/arch/powerpc/mm/dump_hashpagetable.c
index d979709..ee07398 100644
--- a/arch/powerpc/mm/dump_hashpagetable.c
+++ b/arch/powerpc/mm/dump_hashpagetable.c
@@ -468,7 +468,7 @@ static void walk_linearmapping(struct pg_state *st)
unsigned long psize = 1 << mmu_psize_defs[mmu_linear_psize].shift;
 
for (addr = PAGE_OFFSET; addr < PAGE_OFFSET +
-   memblock_phys_mem_size(); addr += psize)
+   memblock_end_of_DRAM(); addr += psize)
hpte_find(st, addr, mmu_linear_psize);
 }
 
-- 
2.9.3



[RFC] Remove memory from nodes for memtrace.

2017-02-22 Thread Rashmica Gupta
 Some powerpc hardware features may want to gain access to a
 chunk of undisturbed real memory.  This update provides a means to unplug
 said memory from the kernel with a set of sysfs calls.  By writing an integer
 containing  the size of memory to be unplugged into
 /sys/kernel/debug/powerpc/memtrace/enable, the code will remove that much
 memory from the end of each available chip's memory space. In addition, the
 means to read out the contents of the unplugged memory is also provided by
 reading out the /sys/kernel/debug/powerpc/memtrace//dump file.

Signed-off-by: Rashmica Gupta 
---
Written by Douglas Lehr .
Have tested and seems to work as I would expect. Only change I have made from
the original is to check that the value being written to the debugfs file is
not 0 (or obscenely large), as otherwise you get a nice kernel oops where the
kernel attempts to access data at 0xfffe0.  

Thoughts about doing this with hot unplug or other changes?

 arch/powerpc/mm/hash_native_64.c  |  39 +++-
 arch/powerpc/platforms/powernv/Makefile   |   1 +
 arch/powerpc/platforms/powernv/memtrace.c | 285 ++
 3 files changed, 321 insertions(+), 4 deletions(-)
 create mode 100644 arch/powerpc/platforms/powernv/memtrace.c

diff --git a/arch/powerpc/mm/hash_native_64.c b/arch/powerpc/mm/hash_native_64.c
index cc33260..44cc6ce 100644
--- a/arch/powerpc/mm/hash_native_64.c
+++ b/arch/powerpc/mm/hash_native_64.c
@@ -3,7 +3,7 @@
  *
  * SMP scalability work:
  *Copyright (C) 2001 Anton Blanchard , IBM
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version
@@ -181,7 +181,7 @@ static inline void native_lock_hpte(struct hash_pte *hptep)
while (1) {
if (!test_and_set_bit_lock(HPTE_LOCK_BIT, word))
break;
-   while(test_bit(HPTE_LOCK_BIT, word))
+   while (test_bit(HPTE_LOCK_BIT, word))
cpu_relax();
}
 }
@@ -208,10 +208,10 @@ static long native_hpte_insert(unsigned long hpte_group, 
unsigned long vpn,
}
 
for (i = 0; i < HPTES_PER_GROUP; i++) {
-   if (! (be64_to_cpu(hptep->v) & HPTE_V_VALID)) {
+   if (!(be64_to_cpu(hptep->v) & HPTE_V_VALID)) {
/* retry with lock held */
native_lock_hpte(hptep);
-   if (! (be64_to_cpu(hptep->v) & HPTE_V_VALID))
+   if (!(be64_to_cpu(hptep->v) & HPTE_V_VALID))
break;
native_unlock_hpte(hptep);
}
@@ -407,6 +407,36 @@ static void native_hpte_updateboltedpp(unsigned long 
newpp, unsigned long ea,
tlbie(vpn, psize, psize, ssize, 0);
 }
 
+/*
+ * Remove a bolted kernel entry. Memory hotplug uses this.
+ *
+ * No need to lock here because we should be the only user.
+ */
+static int native_hpte_removebolted(unsigned long ea, int psize, int ssize)
+{
+   unsigned long vpn;
+   unsigned long vsid;
+   long slot;
+   struct hash_pte *hptep;
+
+   vsid = get_kernel_vsid(ea, ssize);
+   vpn = hpt_vpn(ea, vsid, ssize);
+
+   slot = native_hpte_find(vpn, psize, ssize);
+   if (slot == -1)
+   return -ENOENT;
+
+   hptep = htab_address + slot;
+
+   /* Invalidate the hpte */
+   hptep->v = 0;
+
+   /* Invalidate the TLB */
+   tlbie(vpn, psize, psize, ssize, 0);
+   return 0;
+}
+
+
 static void native_hpte_invalidate(unsigned long slot, unsigned long vpn,
   int bpsize, int apsize, int ssize, int local)
 {
@@ -722,6 +752,7 @@ void __init hpte_init_native(void)
mmu_hash_ops.hpte_invalidate= native_hpte_invalidate;
mmu_hash_ops.hpte_updatepp  = native_hpte_updatepp;
mmu_hash_ops.hpte_updateboltedpp = native_hpte_updateboltedpp;
+   mmu_hash_ops.hpte_removebolted = native_hpte_removebolted;
mmu_hash_ops.hpte_insert= native_hpte_insert;
mmu_hash_ops.hpte_remove= native_hpte_remove;
mmu_hash_ops.hpte_clear_all = native_hpte_clear;
diff --git a/arch/powerpc/platforms/powernv/Makefile 
b/arch/powerpc/platforms/powernv/Makefile
index b5d98cb..2026661 100644
--- a/arch/powerpc/platforms/powernv/Makefile
+++ b/arch/powerpc/platforms/powernv/Makefile
@@ -11,4 +11,5 @@ obj-$(CONFIG_EEH) += eeh-powernv.o
 obj-$(CONFIG_PPC_SCOM) += opal-xscom.o
 obj-$(CONFIG_MEMORY_FAILURE)   += opal-memory-errors.o
 obj-$(CONFIG_TRACEPOINTS)  += opal-tracepoints.o
+obj-$(CONFIG_MEMORY_HOTREMOVE) += memtrace.o
 obj-$(CONFIG_OPAL_PRD) += opal-prd.o
diff --git a/arch/powerpc/platforms/powernv/memtrace.c 
b/arch/powerpc/platforms/powernv/memtrace.c
new file mode 100644
index 000..fdba3ee
--- /dev/null
+++ b/ar

[PATCH 3/3] powerpc/asm: Add STACK_INT_OFFSET macro in asm-offsets.c

2016-06-01 Thread Rashmica Gupta
There are quite a few entries in asm-offests.c look like this:
DEFINE(REG, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, reg));

So define a local MACRO to clean this up:
STACK_INT_OFFSET(sym, val) DEFINE(sym, STACK_INT_FRAME_SIZE + \
   offsetof(struct exception_regs, val))

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/asm-offsets.c | 30 --
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 3dbd3bd016ba..5efe5e297256 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -70,6 +70,8 @@
 
 #define STACK_OFFSET(sym, val) DEFINE(sym, STACK_FRAME_OVERHEAD + \
offsetof(struct pt_regs, val))
+#define STACK_INT_OFFSET(sym, val) DEFINE(sym, \
+   STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, val))
 
 int main(void)
 {
@@ -308,21 +310,21 @@ int main(void)
 #if defined(CONFIG_PPC32)
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
DEFINE(EXC_LVL_SIZE, STACK_EXC_LVL_FRAME_SIZE);
-   DEFINE(MAS0, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas0));
+   STACK_INT_OFFSET(MAS0, mas0);
/* we overload MMUCR for 44x on MAS0 since they are mutually exclusive 
*/
-   DEFINE(MMUCR, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas0));
-   DEFINE(MAS1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas1));
-   DEFINE(MAS2, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas2));
-   DEFINE(MAS3, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas3));
-   DEFINE(MAS6, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas6));
-   DEFINE(MAS7, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
mas7));
-   DEFINE(_SRR0, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
srr0));
-   DEFINE(_SRR1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
srr1));
-   DEFINE(_CSRR0, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
csrr0));
-   DEFINE(_CSRR1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
csrr1));
-   DEFINE(_DSRR0, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
dsrr0));
-   DEFINE(_DSRR1, STACK_INT_FRAME_SIZE+offsetof(struct exception_regs, 
dsrr1));
-   DEFINE(SAVED_KSP_LIMIT, STACK_INT_FRAME_SIZE+offsetof(struct 
exception_regs, saved_ksp_limit));
+   STACK_INT_OFFSET(MMUCR, mas0);
+   STACK_INT_OFFSET(MAS1, mas1);
+   STACK_INT_OFFSET(MAS2, mas2);
+   STACK_INT_OFFSET(MAS3, mas3);
+   STACK_INT_OFFSET(MAS6, mas6);
+   STACK_INT_OFFSET(MAS7, mas7);
+   STACK_INT_OFFSET(_SRR0, srr0);
+   STACK_INT_OFFSET(_SRR1, srr1);
+   STACK_INT_OFFSET(_CSRR0, csrr0);
+   STACK_INT_OFFSET(_CSRR1, csrr1);
+   STACK_INT_OFFSET(_DSRR0, dsrr0);
+   STACK_INT_OFFSET(_DSRR1, dsrr1);
+   STACK_INT_OFFSET(SAVED_KSP_LIMIT, saved_ksp_limit);
 #endif
 #endif
 
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/3] powerpc/asm: Define STACK_OFFSET macro in asm-offsets.c

2016-06-01 Thread Rashmica Gupta
There are quite a few entries in asm-offests.c look like this:
DEFINE(REG, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, reg));

So define a local MACRO to clean this up:
STACK_OFFSET(sym, val) DEFINE(sym, STACK_FRAME_OVERHEAD + \
   offsetof(struct pt_regs, val))

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/asm-offsets.c | 61 ---
 1 file changed, 32 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 345a351909c5..3dbd3bd016ba 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -68,6 +68,9 @@
 #include "../mm/mmu_decl.h"
 #endif
 
+#define STACK_OFFSET(sym, val) DEFINE(sym, STACK_FRAME_OVERHEAD + \
+   offsetof(struct pt_regs, val))
+
 int main(void)
 {
OFFSET(THREAD, task_struct, thread);
@@ -253,38 +256,38 @@ int main(void)
DEFINE(PROM_FRAME_SIZE, STACK_FRAME_OVERHEAD + sizeof(struct pt_regs) + 
16);
DEFINE(RTAS_FRAME_SIZE, STACK_FRAME_OVERHEAD + sizeof(struct pt_regs) + 
16);
 #endif /* CONFIG_PPC64 */
-   DEFINE(GPR0, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[0]));
-   DEFINE(GPR1, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[1]));
-   DEFINE(GPR2, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[2]));
-   DEFINE(GPR3, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[3]));
-   DEFINE(GPR4, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[4]));
-   DEFINE(GPR5, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[5]));
-   DEFINE(GPR6, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[6]));
-   DEFINE(GPR7, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[7]));
-   DEFINE(GPR8, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[8]));
-   DEFINE(GPR9, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[9]));
-   DEFINE(GPR10, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[10]));
-   DEFINE(GPR11, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[11]));
-   DEFINE(GPR12, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[12]));
-   DEFINE(GPR13, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[13]));
+   STACK_OFFSET(GPR0, gpr[0]);
+   STACK_OFFSET(GPR1, gpr[1]);
+   STACK_OFFSET(GPR2, gpr[2]);
+   STACK_OFFSET(GPR3, gpr[3]);
+   STACK_OFFSET(GPR4, gpr[4]);
+   STACK_OFFSET(GPR5, gpr[5]);
+   STACK_OFFSET(GPR6, gpr[6]);
+   STACK_OFFSET(GPR7, gpr[7]);
+   STACK_OFFSET(GPR8, gpr[8]);
+   STACK_OFFSET(GPR9, gpr[9]);
+   STACK_OFFSET(GPR10, gpr[10]);
+   STACK_OFFSET(GPR11, gpr[11]);
+   STACK_OFFSET(GPR12, gpr[12]);
+   STACK_OFFSET(GPR13, gpr[13]);
 #ifndef CONFIG_PPC64
-   DEFINE(GPR14, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, gpr[14]));
+   STACK_OFFSET(GPR14, gpr[14]);
 #endif /* CONFIG_PPC64 */
/*
 * Note: these symbols include _ because they overlap with special
 * register names
 */
-   DEFINE(_NIP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, nip));
-   DEFINE(_MSR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, msr));
-   DEFINE(_CTR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, ctr));
-   DEFINE(_LINK, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, link));
-   DEFINE(_CCR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, ccr));
-   DEFINE(_XER, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, xer));
-   DEFINE(_DAR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, dar));
-   DEFINE(_DSISR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, dsisr));
-   DEFINE(ORIG_GPR3, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, 
orig_gpr3));
-   DEFINE(RESULT, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, result));
-   DEFINE(_TRAP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, trap));
+   STACK_OFFSET(_NIP, nip);
+   STACK_OFFSET(_MSR, msr);
+   STACK_OFFSET(_CTR, ctr);
+   STACK_OFFSET(_LINK, link);
+   STACK_OFFSET(_CCR, ccr);
+   STACK_OFFSET(_XER, xer);
+   STACK_OFFSET(_DAR, dar);
+   STACK_OFFSET(_DSISR, dsisr);
+   STACK_OFFSET(ORIG_GPR3, orig_gpr3);
+   STACK_OFFSET(RESULT, result);
+   STACK_OFFSET(_TRAP, trap);
 #ifndef CONFIG_PPC64
/*
 * The PowerPC 400-class & Book-E processors have neither the DAR
@@ -292,10 +295,10 @@ int main(void)
 * DEAR and ESR SPRs for such processors.  For critical interrupts
 * we use them to hold SRR0 and SRR1.
 */
-   DEFINE(_DEAR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, dar));
-   DEFINE(_ESR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, dsisr));
+   STACK_OFFSET(_DEAR, dar);
+   STACK_OFFSET(_ESR, dsisr);
 #else /* CONFIG_PPC64 */
-   DEFINE(SOFTE, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, softe));
+   STACK_OFFSET(SOFTE, softe);
 
/* These _only_ to be used with {PROM,RTAS}_FRAME_SIZE!!! */
DEFINE(_SRR0, STACK_FRAME_O

[PATCH 1/3] powerpc/asm: Use OFFSET macro in asm-offsets.c

2016-06-01 Thread Rashmica Gupta
A lot of entries in asm-offests.c look like this:
DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));

But there is a common macro, OFFSET, which makes this cleaner:
OFFSET(TI_flags, thread_info, flags), so use this.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/asm-offsets.c | 685 ++
 1 file changed, 333 insertions(+), 352 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index f351f7325f20..345a351909c5 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -70,188 +70,180 @@
 
 int main(void)
 {
-   DEFINE(THREAD, offsetof(struct task_struct, thread));
-   DEFINE(MM, offsetof(struct task_struct, mm));
-   DEFINE(MMCONTEXTID, offsetof(struct mm_struct, context.id));
+   OFFSET(THREAD, task_struct, thread);
+   OFFSET(MM, task_struct, mm);
+   OFFSET(MMCONTEXTID, mm_struct, context.id);
 #ifdef CONFIG_PPC64
DEFINE(SIGSEGV, SIGSEGV);
DEFINE(NMI_MASK, NMI_MASK);
-   DEFINE(TASKTHREADPPR, offsetof(struct task_struct, thread.ppr));
+   OFFSET(TASKTHREADPPR, task_struct, thread.ppr);
 #else
-   DEFINE(THREAD_INFO, offsetof(struct task_struct, stack));
+   OFFSET(THREAD_INFO, task_struct, stack);
DEFINE(THREAD_INFO_GAP, _ALIGN_UP(sizeof(struct thread_info), 16));
-   DEFINE(KSP_LIMIT, offsetof(struct thread_struct, ksp_limit));
+   OFFSET(KSP_LIMIT, thread_struct, ksp_limit);
 #endif /* CONFIG_PPC64 */
 
 #ifdef CONFIG_LIVEPATCH
-   DEFINE(TI_livepatch_sp, offsetof(struct thread_info, livepatch_sp));
+   OFFSET(TI_livepatch_sp, thread_info, livepatch_sp);
 #endif
 
-   DEFINE(KSP, offsetof(struct thread_struct, ksp));
-   DEFINE(PT_REGS, offsetof(struct thread_struct, regs));
+   OFFSET(KSP, thread_struct, ksp);
+   OFFSET(PT_REGS, thread_struct, regs);
 #ifdef CONFIG_BOOKE
-   DEFINE(THREAD_NORMSAVES, offsetof(struct thread_struct, normsave[0]));
+   OFFSET(THREAD_NORMSAVES, thread_struct, normsave[0]);
 #endif
-   DEFINE(THREAD_FPEXC_MODE, offsetof(struct thread_struct, fpexc_mode));
-   DEFINE(THREAD_FPSTATE, offsetof(struct thread_struct, fp_state));
-   DEFINE(THREAD_FPSAVEAREA, offsetof(struct thread_struct, fp_save_area));
-   DEFINE(FPSTATE_FPSCR, offsetof(struct thread_fp_state, fpscr));
-   DEFINE(THREAD_LOAD_FP, offsetof(struct thread_struct, load_fp));
+   OFFSET(THREAD_FPEXC_MODE, thread_struct, fpexc_mode);
+   OFFSET(THREAD_FPSTATE, thread_struct, fp_state);
+   OFFSET(THREAD_FPSAVEAREA, thread_struct, fp_save_area);
+   OFFSET(FPSTATE_FPSCR, thread_fp_state, fpscr);
+   OFFSET(THREAD_LOAD_FP, thread_struct, load_fp);
 #ifdef CONFIG_ALTIVEC
-   DEFINE(THREAD_VRSTATE, offsetof(struct thread_struct, vr_state));
-   DEFINE(THREAD_VRSAVEAREA, offsetof(struct thread_struct, vr_save_area));
-   DEFINE(THREAD_VRSAVE, offsetof(struct thread_struct, vrsave));
-   DEFINE(THREAD_USED_VR, offsetof(struct thread_struct, used_vr));
-   DEFINE(VRSTATE_VSCR, offsetof(struct thread_vr_state, vscr));
-   DEFINE(THREAD_LOAD_VEC, offsetof(struct thread_struct, load_vec));
+   OFFSET(THREAD_VRSTATE, thread_struct, vr_state);
+   OFFSET(THREAD_VRSAVEAREA, thread_struct, vr_save_area);
+   OFFSET(THREAD_VRSAVE, thread_struct, vrsave);
+   OFFSET(THREAD_USED_VR, thread_struct, used_vr);
+   OFFSET(VRSTATE_VSCR, thread_vr_state, vscr);
+   OFFSET(THREAD_LOAD_VEC, thread_struct, load_vec);
 #endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
-   DEFINE(THREAD_USED_VSR, offsetof(struct thread_struct, used_vsr));
+   OFFSET(THREAD_USED_VSR, thread_struct, used_vsr);
 #endif /* CONFIG_VSX */
 #ifdef CONFIG_PPC64
-   DEFINE(KSP_VSID, offsetof(struct thread_struct, ksp_vsid));
+   OFFSET(KSP_VSID, thread_struct, ksp_vsid);
 #else /* CONFIG_PPC64 */
-   DEFINE(PGDIR, offsetof(struct thread_struct, pgdir));
+   OFFSET(PGDIR, thread_struct, pgdir);
 #ifdef CONFIG_SPE
-   DEFINE(THREAD_EVR0, offsetof(struct thread_struct, evr[0]));
-   DEFINE(THREAD_ACC, offsetof(struct thread_struct, acc));
-   DEFINE(THREAD_SPEFSCR, offsetof(struct thread_struct, spefscr));
-   DEFINE(THREAD_USED_SPE, offsetof(struct thread_struct, used_spe));
+   OFFSET(THREAD_EVR0, thread_struct, evr[0]);
+   OFFSET(THREAD_ACC, thread_struct, acc);
+   OFFSET(THREAD_SPEFSCR, thread_struct, spefscr);
+   OFFSET(THREAD_USED_SPE, thread_struct, used_spe);
 #endif /* CONFIG_SPE */
 #endif /* CONFIG_PPC64 */
 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
-   DEFINE(THREAD_DBCR0, offsetof(struct thread_struct, debug.dbcr0));
+   OFFSET(THREAD_DBCR0, thread_struct, debug.dbcr0);
 #endif
 #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
-   DEFINE(THREAD_KVM_SVCPU, offsetof(struct thread_struct, 
kvm_shadow_vcpu));
+   OFFSET(THREAD_KVM_SVCPU, thread_struct, kvm_shadow_vcpu);
 #endif
 #if

[PATCH] powerpc/asm: Remove unused symbols in asm-offsets.c

2016-06-01 Thread Rashmica Gupta
THREAD_DSCR: Added in commit efcac6589a27 ("powerpc: Per process DSCR +
some fixes (try#4)") and last usage was removed in commit 152d523e6307
("powerpc: Create context switch helpers save_sprs() and
restore_sprs()")
---
THREAD_DSCR_INHERIT: Added in commit 714332858bfd ("powerpc: Restore
correct DSCR in context switch") and last usage was removed in commit
152d523e6307 ("powerpc: Create context switch helpers save_sprs() and
restore_sprs()")
---
THREAD_TAR: Added in commit 2468dcf641e4 ("powerpc: Add support for
context switching the TAR register") and last usage was removed in
commit 152d523e6307 ("powerpc: Create context switch helpers save_sprs()
and restore_sprs()")
---
THREAD_BESCR, THREAD_EBBHR and THREAD_EBBRR: Added in commit
9353374b8e15 ("powerpc: Context switch the new EBB SPRs") and last usage
was removed in commit 152d523e6307 ("powerpc: Create context switch
helpers save_sprs() and restore_sprs()")
---
THREAD_SIAR, THREAD_SDAR, THREAD_SIER, THREAD_MMCR0, and THREAD_MMCR2:
Added commit 59affcd3e460 ("powerpc: Context switch more PMU related
SPRs") and last usage was removed in commit b11ae95100f7 ("powerpc:
Partial revert of "Context switch more PMU related SPRs"")
---
PACA_LOCK_TOKEN: Added commit 9e368f291560 ("KVM: PPC: book3s_hv: Add
support for PPC970-family processors") and last usage was removed in
commit c17b98cf6028 ("KVM: PPC: Book3S HV: Remove code for PPC970
processors")
---
HCALL_STAT_SIZE, HCALL_STAT_CALLS, HCALL_STAT_TB and HCALL_STAT_PURR:
Added in commit 57852a853b0d ("[POWERPC] powerpc: Instrument Hypervisor
Calls") and last usage was removed in commit c8cd093a6e9f ("powerpc:
tracing: Add hypervisor call tracepoints")
---
VCPU_EPLC: Added in commit d30f6e480055 ("KVM: PPC: booke: category E.HV
(GS-mode) support") and was never used.
---
CPU_DOWN_FLUSH: Added in commit e7affb1dba0e ("powerpc/cache: add cache
flush operation for various e500") and was never used.
---
CFG_STAMP_XSEC: Added in commit commit 14cf11af6cf6 ("powerpc: Merge
enough to start building in arch/powerpc.") and last usage was removed
in commit 0e469db8f70c ("powerpc: Rework VDSO gettimeofday to prevent
time going backwards")
---
KVM_LPCR: Added in commit aa04b4cc5be6 ("KVM: PPC: Allocate RMAs (Real
Mode Areas) at boot for use by guests") and last usage was removed in
commit a0144e2a6b0b ("KVM: PPC: Book3S HV: Store LPCR value for each
virtual core")
---
GPR15, GPR16, GPR17, GPR18, GPR19, GPR20, GPR21, GPR22, GPR23, GPR24,
GPR25, GPR26, GPR27, GPR28, GPR29 and GPR30: Added in commit
a4bcbe6a41ad ("powerpc: Remove old compile time disabled syscall tracing
code") and were never used.
---
GPR31: Added in commit a4bcbe6a41ad ("powerpc: Remove old compile time
disabled syscall tracing code") and last usage was removed in commit
a4bcbe6a41ad ("powerpc: Remove old compile time disabled syscall tracing
code")
---
VCPU_SPMC: Added in commit b005255e12a3 ("KVM: PPC: Book3S HV:
Context-switch new POWER8 SPRs") and was never used.
---
VCPU_SHADOW_FSCR: Added in commit 616dff860282 ("KVM: PPC: Book3S PR:
Handle Facility interrupt and FSCR") and was never used.
---
VCPU_SHADOW_SRR1: Added in commit a2d56020d1d9 ("KVM: PPC: Book3S PR:
Keep volatile reg values in vcpu rather than shadow_vcpu") and was never
used.
---
KVM_SPLIT_SIZE: Added in commit b4deba5c41e9 ("KVM: PPC: Book3S HV:
Implement dynamicmicro-threading on POWER8") and was never used.
---
VCPU_VCPUID: Added in commit de56a948b918 ("KVM: PPC: Add support for
Book3S processors in hypervisor mode") and last usage was removed in
commit 1b400ba0cd24 ("KVM: PPC: Book3S HV: Improve handling of local vs.
global TLB invalidations")
---
_MQ: Added in commit 14cf11af6cf6 ("powerpc: Merge enough to start
building in arch/powerpc.") and never used.
---
AUDITCONTEXT: Added in commit 14cf11af6cf6 ("powerpc: Merge enough to
start building in arch/powerpc.") and last usage was removed in commit
401d1f029beb ("[PATCH] syscall entry/exit revamp")

CLONE_VM: Added in commit 14cf11af6cf6 ("powerpc: Merge enough to start
building in arch/powerpc.") and currently unused.
---
CLONE_UNTRACED: Added in commit 14cf11af6cf6 ("powerpc: Merge enough to
start building in arch/powerpc.") and currently unused.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/asm-offsets.c | 50 ---
 1 file changed, 50 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 9ea09551a2cd..f351f7325f20 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -74,11 +74,8 @@ int main(void)
DEFINE(MM, offsetof(struct task_struct, mm

Re: [PATCH 1/5] powerpc/pseries: Drop support for MPIC in pseries

2016-05-30 Thread Rashmica



On 31/05/16 11:34, Rashmica wrote:



On 30/05/16 17:32, Benjamin Herrenschmidt wrote:

On Mon, 2016-05-30 at 16:18 +1000, Rashmica Gupta wrote:

MPIC was only used by Power3 which is now unsupported, so drop support
for MPIC. XICS is now the only supported interrupt controller for
pSeries so make the XICS functions generic.

The second half I'm not sure ... XIVE is around the corner...

Cheers,
Ben.

I thought XIVE was replacing XICS? And so then we can just simply 
replace all the specific XICS code such as xics_init() and 
xics_smp_probe() with the relevant XIVE functions?


By "make the XICS functions generic" I meant that if there is only one 
interrupt controller for pseries then we don't need to have both 
static void __init pseries_xics_init_IRQ(void) and static void __init 
pSeries_init_IRQ(void), etc.


Oliver just informed me that it is only replacing XICS for p9. Should I 
leave this for the person adding in the XIVE code?

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 1/5] powerpc/pseries: Drop support for MPIC in pseries

2016-05-30 Thread Rashmica



On 30/05/16 17:32, Benjamin Herrenschmidt wrote:

On Mon, 2016-05-30 at 16:18 +1000, Rashmica Gupta wrote:

MPIC was only used by Power3 which is now unsupported, so drop support
for MPIC. XICS is now the only supported interrupt controller for
pSeries so make the XICS functions generic.

The second half I'm not sure ... XIVE is around the corner...

Cheers,
Ben.

I thought XIVE was replacing XICS? And so then we can just simply 
replace all the specific XICS code such as xics_init() and 
xics_smp_probe() with the relevant XIVE functions?


By "make the XICS functions generic" I meant that if there is only one 
interrupt controller for pseries then we don't need to have both static 
void __init pseries_xics_init_IRQ(void) and static void __init 
pSeries_init_IRQ(void), etc.

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 5/5] powerpc/pseries: Remove MPIC from pseries event sources

2016-05-29 Thread Rashmica Gupta
MPIC was only used by Power3 which is now unsupported, so remove MPIC
code. XICS is now the only supported interrupt controller for
pSeries so do some cleanups too.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/platforms/pseries/event_sources.c | 53 +++---
 1 file changed, 13 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/event_sources.c 
b/arch/powerpc/platforms/pseries/event_sources.c
index 18380e8f6dfe..a6ddca833119 100644
--- a/arch/powerpc/platforms/pseries/event_sources.c
+++ b/arch/powerpc/platforms/pseries/event_sources.c
@@ -26,48 +26,21 @@ void request_event_sources_irqs(struct device_node *np,
 {
int i, index, count = 0;
struct of_phandle_args oirq;
-   const u32 *opicprop;
-   unsigned int opicplen;
unsigned int virqs[16];
 
-   /* Check for obsolete "open-pic-interrupt" property. If present, then
-* map those interrupts using the default interrupt host and default
-* trigger
-*/
-   opicprop = of_get_property(np, "open-pic-interrupt", &opicplen);
-   if (opicprop) {
-   opicplen /= sizeof(u32);
-   for (i = 0; i < opicplen; i++) {
-   if (count > 15)
-   break;
-   virqs[count] = irq_create_mapping(NULL, *(opicprop++));
-   if (virqs[count] == NO_IRQ) {
-   pr_err("event-sources: Unable to allocate "
-  "interrupt number for %s\n",
-  np->full_name);
-   WARN_ON(1);
-   }
-   else
-   count++;
-
-   }
-   }
-   /* Else use normal interrupt tree parsing */
-   else {
-   /* First try to do a proper OF tree parsing */
-   for (index = 0; of_irq_parse_one(np, index, &oirq) == 0;
-index++) {
-   if (count > 15)
-   break;
-   virqs[count] = irq_create_of_mapping(&oirq);
-   if (virqs[count] == NO_IRQ) {
-   pr_err("event-sources: Unable to allocate "
-  "interrupt number for %s\n",
-  np->full_name);
-   WARN_ON(1);
-   }
-   else
-   count++;
+   /* First try to do a proper OF tree parsing */
+   for (index = 0; of_irq_parse_one(np, index, &oirq) == 0;
+index++) {
+   if (count > 15)
+   break;
+   virqs[count] = irq_create_of_mapping(&oirq);
+   if (virqs[count] == NO_IRQ) {
+   pr_err("event-sources: Unable to allocate "
+  "interrupt number for %s\n",
+  np->full_name);
+   WARN_ON(1);
+   } else {
+   count++;
}
}
 
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 4/5] powerpc/pseries: Remove MPIC from pseries cpu hotplug

2016-05-29 Thread Rashmica Gupta
MPIC was only used by Power3 which is now unsupported, so remove MPIC
code.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/platforms/pseries/hotplug-cpu.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c 
b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 282837a1d74b..a1b63e00b2f7 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -903,8 +903,6 @@ static int parse_cede_parameters(void)
 
 static int __init pseries_cpu_hotplug_init(void)
 {
-   struct device_node *np;
-   const char *typep;
int cpu;
int qcss_tok;
 
@@ -913,17 +911,6 @@ static int __init pseries_cpu_hotplug_init(void)
ppc_md.cpu_release = dlpar_cpu_release;
 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
 
-   for_each_node_by_name(np, "interrupt-controller") {
-   typep = of_get_property(np, "compatible", NULL);
-   if (strstr(typep, "open-pic")) {
-   of_node_put(np);
-
-   printk(KERN_INFO "CPU Hotplug not supported on "
-   "systems using MPIC\n");
-   return 0;
-   }
-   }
-
rtas_stop_self_token = rtas_token("stop-self");
qcss_tok = rtas_token("query-cpu-stopped-state");
 
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 3/5] powerpc/pseries: Remove MPIC from pseries kexec

2016-05-29 Thread Rashmica Gupta
MPIC was only used by Power3 which is now unsupported, so remove MPIC
code. XICS is now the only supported interrupt controller for
pSeries so do some cleanups too.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/platforms/pseries/kexec.c   | 23 +--
 arch/powerpc/platforms/pseries/pseries.h |  8 +---
 arch/powerpc/platforms/pseries/setup.c   |  2 +-
 3 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/kexec.c 
b/arch/powerpc/platforms/pseries/kexec.c
index 13fa95b3aa8b..f7a93e6bb630 100644
--- a/arch/powerpc/platforms/pseries/kexec.c
+++ b/arch/powerpc/platforms/pseries/kexec.c
@@ -14,14 +14,13 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 
 #include "pseries.h"
 
-static void pseries_kexec_cpu_down(int crash_shutdown, int secondary)
+void pSeries_kexec_cpu_down(int crash_shutdown, int secondary)
 {
/* Don't risk a hypervisor call if we're crashing */
if (firmware_has_feature(FW_FEATURE_SPLPAR) && !crash_shutdown) {
@@ -51,26 +50,6 @@ static void pseries_kexec_cpu_down(int crash_shutdown, int 
secondary)
   "(hw %d) failed with %d\n", cpu, hwcpu, ret);
}
}
-}
-
-static void pseries_kexec_cpu_down_mpic(int crash_shutdown, int secondary)
-{
-   pseries_kexec_cpu_down(crash_shutdown, secondary);
-   mpic_teardown_this_cpu(secondary);
-}
 
-void __init setup_kexec_cpu_down_mpic(void)
-{
-   ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_mpic;
-}
-
-static void pseries_kexec_cpu_down_xics(int crash_shutdown, int secondary)
-{
-   pseries_kexec_cpu_down(crash_shutdown, secondary);
xics_kexec_teardown_cpu(secondary);
 }
-
-void __init setup_kexec_cpu_down_xics(void)
-{
-   ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_xics;
-}
diff --git a/arch/powerpc/platforms/pseries/pseries.h 
b/arch/powerpc/platforms/pseries/pseries.h
index edeaec74b656..d81aa1e08478 100644
--- a/arch/powerpc/platforms/pseries/pseries.h
+++ b/arch/powerpc/platforms/pseries/pseries.h
@@ -36,13 +36,7 @@ extern void smp_init_pseries(void);
 static inline void smp_init_pseries(void) { };
 #endif
 
-#ifdef CONFIG_KEXEC
-extern void setup_kexec_cpu_down_xics(void);
-extern void setup_kexec_cpu_down_mpic(void);
-#else
-static inline void setup_kexec_cpu_down_xics(void) { }
-static inline void setup_kexec_cpu_down_mpic(void) { }
-#endif
+extern void pSeries_kexec_cpu_down(int crash_shutdown, int secondary);
 
 extern void pSeries_final_fixup(void);
 
diff --git a/arch/powerpc/platforms/pseries/setup.c 
b/arch/powerpc/platforms/pseries/setup.c
index 32a224d3eaa1..15ca3441cf1d 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -436,7 +436,6 @@ static void __init pSeries_setup_arch(void)
set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
 
/* Discover PIC type and setup ppc_md accordingly */
-   setup_kexec_cpu_down_xics();
smp_init_pseries();
 
 
@@ -786,6 +785,7 @@ define_machine(pseries) {
.machine_check_exception = pSeries_machine_check_exception,
 #ifdef CONFIG_KEXEC
.machine_kexec  = pSeries_machine_kexec,
+   .kexec_cpu_down = pSeries_kexec_cpu_down,
 #endif
 #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
.memory_block_size  = pseries_memory_block_size,
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/5] powerpc/pseries: Remove MPIC from pseries smp

2016-05-29 Thread Rashmica Gupta
MPIC was only used by Power3 which is now unsupported, so remove MPIC
code. XICS is now the only supported interrupt controller for
pSeries so do some cleanups too.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/platforms/pseries/pseries.h |  6 ++
 arch/powerpc/platforms/pseries/setup.c   |  2 +-
 arch/powerpc/platforms/pseries/smp.c | 31 +--
 3 files changed, 8 insertions(+), 31 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/pseries.h 
b/arch/powerpc/platforms/pseries/pseries.h
index 7aa83f00ac62..edeaec74b656 100644
--- a/arch/powerpc/platforms/pseries/pseries.h
+++ b/arch/powerpc/platforms/pseries/pseries.h
@@ -31,11 +31,9 @@ extern int pSeries_system_reset_exception(struct pt_regs 
*regs);
 extern int pSeries_machine_check_exception(struct pt_regs *regs);
 
 #ifdef CONFIG_SMP
-extern void smp_init_pseries_mpic(void);
-extern void smp_init_pseries_xics(void);
+extern void smp_init_pseries(void);
 #else
-static inline void smp_init_pseries_mpic(void) { };
-static inline void smp_init_pseries_xics(void) { };
+static inline void smp_init_pseries(void) { };
 #endif
 
 #ifdef CONFIG_KEXEC
diff --git a/arch/powerpc/platforms/pseries/setup.c 
b/arch/powerpc/platforms/pseries/setup.c
index f83ac9be7f34..32a224d3eaa1 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -437,7 +437,7 @@ static void __init pSeries_setup_arch(void)
 
/* Discover PIC type and setup ppc_md accordingly */
setup_kexec_cpu_down_xics();
-   smp_init_pseries_xics();
+   smp_init_pseries();
 
 
/* openpic global configuration register (64-bit format). */
diff --git a/arch/powerpc/platforms/pseries/smp.c 
b/arch/powerpc/platforms/pseries/smp.c
index 6932ea803e33..93a8a67006c7 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -38,7 +38,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -140,7 +139,7 @@ out:
return 1;
 }
 
-static void smp_xics_setup_cpu(int cpu)
+static void smp_setup_cpu(int cpu)
 {
if (cpu != boot_cpuid)
xics_setup_cpu();
@@ -207,28 +206,22 @@ static __init void pSeries_smp_probe(void)
}
 }
 
-static struct smp_ops_t pSeries_mpic_smp_ops = {
-   .message_pass   = smp_mpic_message_pass,
-   .probe  = smp_mpic_probe,
-   .kick_cpu   = smp_pSeries_kick_cpu,
-   .setup_cpu  = smp_mpic_setup_cpu,
-};
-
-static struct smp_ops_t pSeries_xics_smp_ops = {
+static struct smp_ops_t pSeries_smp_ops = {
.message_pass   = NULL, /* Use smp_muxed_ipi_message_pass */
.cause_ipi  = NULL, /* Filled at runtime by pSeries_smp_probe() */
.probe  = pSeries_smp_probe,
.kick_cpu   = smp_pSeries_kick_cpu,
-   .setup_cpu  = smp_xics_setup_cpu,
+   .setup_cpu  = smp_setup_cpu,
.cpu_bootable   = smp_generic_cpu_bootable,
 };
 
 /* This is called very early */
-static void __init smp_init_pseries(void)
+void __init smp_init_pseries(void)
 {
int i;
 
pr_debug(" -> smp_init_pSeries()\n");
+   smp_ops = &pSeries_smp_ops;
 
alloc_bootmem_cpumask_var(&of_spin_mask);
 
@@ -258,17 +251,3 @@ static void __init smp_init_pseries(void)
 
pr_debug(" <- smp_init_pSeries()\n");
 }
-
-void __init smp_init_pseries_mpic(void)
-{
-   smp_ops = &pSeries_mpic_smp_ops;
-
-   smp_init_pseries();
-}
-
-void __init smp_init_pseries_xics(void)
-{
-   smp_ops = &pSeries_xics_smp_ops;
-
-   smp_init_pseries();
-}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/5] powerpc/pseries: Drop support for MPIC in pseries

2016-05-29 Thread Rashmica Gupta
MPIC was only used by Power3 which is now unsupported, so drop support
for MPIC. XICS is now the only supported interrupt controller for
pSeries so make the XICS functions generic.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/platforms/pseries/setup.c | 77 +++---
 1 file changed, 5 insertions(+), 72 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/setup.c 
b/arch/powerpc/platforms/pseries/setup.c
index 9883bc7ea007..f83ac9be7f34 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -57,7 +57,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -77,8 +76,6 @@ EXPORT_SYMBOL(CMO_PageSize);
 
 int fwnmi_active;  /* TRUE if an FWNMI handler is present */
 
-static struct device_node *pSeries_mpic_node;
-
 static void pSeries_show_cpuinfo(struct seq_file *m)
 {
struct device_node *root;
@@ -172,48 +169,7 @@ static void __init pseries_setup_i8259_cascade(void)
irq_set_chained_handler(cascade, pseries_8259_cascade);
 }
 
-static void __init pseries_mpic_init_IRQ(void)
-{
-   struct device_node *np;
-   const unsigned int *opprop;
-   unsigned long openpic_addr = 0;
-   int naddr, n, i, opplen;
-   struct mpic *mpic;
-
-   np = of_find_node_by_path("/");
-   naddr = of_n_addr_cells(np);
-   opprop = of_get_property(np, "platform-open-pic", &opplen);
-   if (opprop != NULL) {
-   openpic_addr = of_read_number(opprop, naddr);
-   printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
-   }
-   of_node_put(np);
-
-   BUG_ON(openpic_addr == 0);
-
-   /* Setup the openpic driver */
-   mpic = mpic_alloc(pSeries_mpic_node, openpic_addr,
-   MPIC_NO_RESET, 16, 0, " MPIC ");
-   BUG_ON(mpic == NULL);
-
-   /* Add ISUs */
-   opplen /= sizeof(u32);
-   for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
-   unsigned long isuaddr = of_read_number(opprop + i, naddr);
-   mpic_assign_isu(mpic, n, isuaddr);
-   }
-
-   /* Setup top-level get_irq */
-   ppc_md.get_irq = mpic_get_irq;
-
-   /* All ISUs are setup, complete initialization */
-   mpic_init(mpic);
-
-   /* Look for cascade */
-   pseries_setup_i8259_cascade();
-}
-
-static void __init pseries_xics_init_IRQ(void)
+static void __init pSeries_init_IRQ(void)
 {
xics_init();
pseries_setup_i8259_cascade();
@@ -228,32 +184,6 @@ static void pseries_lpar_enable_pmcs(void)
plpar_hcall_norets(H_PERFMON, set, reset);
 }
 
-static void __init pseries_discover_pic(void)
-{
-   struct device_node *np;
-   const char *typep;
-
-   for_each_node_by_name(np, "interrupt-controller") {
-   typep = of_get_property(np, "compatible", NULL);
-   if (!typep)
-   continue;
-   if (strstr(typep, "open-pic")) {
-   pSeries_mpic_node = of_node_get(np);
-   ppc_md.init_IRQ   = pseries_mpic_init_IRQ;
-   setup_kexec_cpu_down_mpic();
-   smp_init_pseries_mpic();
-   return;
-   } else if (strstr(typep, "ppc-xicp")) {
-   ppc_md.init_IRQ   = pseries_xics_init_IRQ;
-   setup_kexec_cpu_down_xics();
-   smp_init_pseries_xics();
-   return;
-   }
-   }
-   printk(KERN_ERR "pSeries_discover_pic: failed to recognize"
-  " interrupt-controller\n");
-}
-
 static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long 
action, void *data)
 {
struct of_reconfig_data *rd = data;
@@ -506,7 +436,9 @@ static void __init pSeries_setup_arch(void)
set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
 
/* Discover PIC type and setup ppc_md accordingly */
-   pseries_discover_pic();
+   setup_kexec_cpu_down_xics();
+   smp_init_pseries_xics();
+
 
/* openpic global configuration register (64-bit format). */
/* openpic Interrupt Source Unit pointer (64-bit format). */
@@ -838,6 +770,7 @@ define_machine(pseries) {
.probe  = pSeries_probe,
.setup_arch = pSeries_setup_arch,
.init_early = pSeries_init_early,
+   .init_IRQ   = pSeries_init_IRQ,
.show_cpuinfo   = pSeries_show_cpuinfo,
.log_error  = pSeries_log_error,
.pcibios_fixup  = pSeries_final_fixup,
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v3 PATCH 2/2] powerpc/mm: Dump hash table

2016-05-26 Thread Rashmica Gupta
Useful to be able to dump the kernel hash page table to check
which pages are hashed along with their sizes and other details.

Add a debugfs file to check the hash page table. If radix is enabled
(and so there is no hash page table) then this file doesn't exist. To
use this the PPC_PTDUMP config option must be selected.

Signed-off-by: Rashmica Gupta 
---
v2 -> v3: Changed to be compatible with P9.

 arch/powerpc/mm/Makefile |   3 +-
 arch/powerpc/mm/dump_hashpagetable.c | 543 +++
 2 files changed, 545 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/mm/dump_hashpagetable.c

diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index d3dfa02082b1..df4fbf56aa7b 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -43,4 +43,5 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
-obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o \
+  dump_hashpagetable.o
diff --git a/arch/powerpc/mm/dump_hashpagetable.c 
b/arch/powerpc/mm/dump_hashpagetable.c
new file mode 100644
index ..f8ccc224eb2c
--- /dev/null
+++ b/arch/powerpc/mm/dump_hashpagetable.c
@@ -0,0 +1,543 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * This traverses the kernel virtual memory and dumps the pages that are in
+ * the hash pagetable, along with their flags to
+ * /sys/kernel/debug/kernel_hash_pagetable.
+ *
+ * If radix is enabled then there is no hash page table and so no debugfs file
+ * is generated.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned int level;
+   u64 current_flags;
+};
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+static struct addr_marker address_markers[] = {
+   { 0,"Start of kernel VM" },
+   { 0,"vmalloc() Area" },
+   { 0,"vmalloc() End" },
+   { 0,"isa I/O start" },
+   { 0,"isa I/O end" },
+   { 0,"phb I/O start" },
+   { 0,"phb I/O end" },
+   { 0,"I/O remap start" },
+   { 0,"I/O remap end" },
+   { 0,"vmemmap start" },
+   { -1,   NULL },
+};
+
+struct flag_info {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+   boolis_val;
+   int shift;
+};
+
+static const struct flag_info v_flag_array[] = {
+   {
+   .mask   = SLB_VSID_B,
+   .val= SLB_VSID_B_256M,
+   .set= "ssize: 256M",
+   .clear  = "ssize: 1T  ",
+   }, {
+   .mask   = HPTE_V_SECONDARY,
+   .val= HPTE_V_SECONDARY,
+   .set= "secondary",
+   .clear  = "primary  ",
+   }, {
+   .mask   = HPTE_V_VALID,
+   .val= HPTE_V_VALID,
+   .set= "valid  ",
+   .clear  = "invalid",
+   }, {
+   .mask   = HPTE_V_BOLTED,
+   .val= HPTE_V_BOLTED,
+   .set= "bolted",
+   .clear  = "",
+   }
+};
+
+static const struct flag_info r_flag_array[] = {
+   {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RWXX,
+   .set= "prot:RW--",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RWRX,
+   .set= "prot:RWR-",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RWRW,
+   .set= "prot:RWRW",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RXRX,
+   .set= "prot:R-R-",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RXXX,
+   .set= "prot:R---",
+   }, {
+   .mask   = HPTE_R_KEY_HI | HPTE_R_KEY_LO,
+   .val= HPTE_R_KEY_HI | HPTE_R_KEY_LO,
+   .set= "key",
+   .clear  = "",
+   

[v3 PATCH 1/2] powerpc/mm: Dump linux pagetables

2016-05-26 Thread Rashmica Gupta
Useful to be able to dump the kernels page tables to check permissions
and memory types - derived from arm64's implementation.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Signed-off-by: Rashmica Gupta 
---
v2 -> v3: Changed to be compatible with P9. 

 arch/powerpc/Kconfig.debug |  12 +
 arch/powerpc/mm/Makefile   |   1 +
 arch/powerpc/mm/dump_linuxpagetables.c | 440 +
 3 files changed, 453 insertions(+)
 create mode 100644 arch/powerpc/mm/dump_linuxpagetables.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 2be221874de8..d19f496a7e12 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -350,4 +350,16 @@ config FAIL_IOMMU
 
  If you are unsure, say N.
 
+config PPC_PTDUMP
+bool "Export kernel pagetable layout to userspace via debugfs"
+depends on DEBUG_KERNEL
+select DEBUG_FS
+help
+ This option exports the state of the kernel pagetables to a
+ debugfs file. This is only useful for kernel developers who are
+ working in architecture specific areas of the kernel - probably
+ not a good idea to enable this feature in a production kernel.
+
+ If you are unsure, say N.
+
 endmenu
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index f2cea6d5e764..d3dfa02082b1 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -43,3 +43,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o
diff --git a/arch/powerpc/mm/dump_linuxpagetables.c 
b/arch/powerpc/mm/dump_linuxpagetables.c
new file mode 100644
index ..d242bc79ae64
--- /dev/null
+++ b/arch/powerpc/mm/dump_linuxpagetables.c
@@ -0,0 +1,440 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * This traverses the kernel pagetables and dumps the
+ * information about the used sections of memory to
+ * /sys/kernel/debug/kernel_pagetables.
+ *
+ * Derived from the arm64 implementation:
+ * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
+ * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * To visualise what is happening,
+ *
+ *  - PTRS_PER_P** = how many entries there are in the corresponding P**
+ *  - P**_SHIFT = how many bits of the address we use to index into the
+ * corresponding P**
+ *  - P**_SIZE is how much memory we can access through the table - not the
+ * size of the table itself.
+ * P**={PGD, PUD, PMD, PTE}
+ *
+ *
+ * Each entry of the PGD points to a PUD. Each entry of a PUD points to a
+ * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to
+ * a page.
+ *
+ * In the case where there are only 3 levels, the PUD is folded into the
+ * PGD: every PUD has only one entry which points to the PMD.
+ *
+ * The page dumper groups page table entries of the same type into a single
+ * description. It uses pg_state to track the range information while
+ * iterating over the PTE entries. When the continuity is broken it then
+ * dumps out a description of the range - ie PTEs that are virtually contiguous
+ * with the same PTE flags are chunked together. This is to make it clear how
+ * different areas of the kernel virtual memory are used.
+ *
+ */
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned int level;
+   u64 current_flags;
+};
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+static struct addr_marker address_markers[] = {
+   { 0,"Start of kernel VM" },
+   { 0,"vmalloc() Area" },
+   { 0,"vmalloc() End" },
+   { 0,"isa I/O start" },
+   { 0,"isa I/O end" },
+   { 0,"phb I/O start" },
+   { 0,"phb I/O end" },
+   { 0,"I/O remap start" },
+   { 0,"I/O remap end" },
+   { 0,"vmemmap start" },
+   { -1,   NULL },
+};
+
+struct flag_info {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+   boolis_val;
+   int shift;
+};
+
+static const struct flag_info flag_array[] = {
+   {
+#ifdef CONFIG_PPC_STD_MMU_64
+   .mas

[PATCH 2/2] powerpc/SROP mitigation: Add cookies to sigframes

2016-05-17 Thread Rashmica Gupta
This patch adds SROP mitigation logic to the powerpc signal delivery
and sigreturn code. The cookie is placed in the sigframe just after (at
a lower address) the ABI gap.

This is derived from the x86 SROP mitigation patch:
https://lkml.org/lkml/2016/3/29/791.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/signal_32.c | 33 +
 arch/powerpc/kernel/signal_64.c | 21 +++--
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index b6aa378aff63..01e6d0c966ee 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -207,6 +207,7 @@ static inline int restore_general_regs(struct pt_regs *regs,
  * When we have signals to deliver, we set up on the
  * user stack, going down from the original stack pointer:
  * an ABI gap of 56 words
+ * a cookie
  * an mcontext struct
  * a sigcontext struct
  * a gap of __SIGNAL_FRAMESIZE bytes
@@ -222,6 +223,7 @@ struct sigframe {
struct sigcontext sctx_transact;
struct mcontext mctx_transact;
 #endif
+   unsigned long user_cookie;
/*
 * Programs using the rs6000/xcoff abi can save up to 19 gp
 * regs and 18 fp regs below sp before decrementing it.
@@ -235,7 +237,7 @@ struct sigframe {
 /*
  *  When we have rt signals to deliver, we set up on the
  *  user stack, going down from the original stack pointer:
- * one rt_sigframe struct (siginfo + ucontext + ABI gap)
+ * one rt_sigframe struct (siginfo + ucontext + cookie + ABI gap)
  * a gap of __SIGNAL_FRAMESIZE+16 bytes
  *  (the +16 is to get the siginfo and ucontext in the same
  *  positions as in older kernels).
@@ -253,6 +255,7 @@ struct rt_sigframe {
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
struct ucontext uc_transact;
 #endif
+   unsigned long user_cookie;
/*
 * Programs using the rs6000/xcoff abi can save up to 19 gp
 * regs and 18 fp regs below sp before decrementing it.
@@ -980,11 +983,12 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t 
*oldset,
unsigned long newsp = 0;
int sigret;
unsigned long tramp;
-
+   void __user *cookie_location;
/* Set up Signal Frame */
/* Put a Real Time Context onto stack */
rt_sf = get_sigframe(ksig, get_tm_stackpointer(regs), sizeof(*rt_sf), 
1);
addr = rt_sf;
+   cookie_location = &(rt_sf->user_cookie);
if (unlikely(rt_sf == NULL))
goto badframe;
 
@@ -1016,6 +1020,8 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t 
*oldset,
__put_user((unsigned long)tm_frame,
   &rt_sf->uc_transact.uc_regs))
goto badframe;
+   if (set_sigcookie(cookie_location))
+   goto badframe;
if (save_tm_user_regs(regs, frame, tm_frame, sigret))
goto badframe;
}
@@ -1024,6 +1030,8 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t 
*oldset,
{
if (__put_user(0, &rt_sf->uc.uc_link))
goto badframe;
+   if (set_sigcookie(cookie_location))
+   goto badframe;
if (save_user_regs(regs, frame, tm_frame, sigret, 1))
goto badframe;
}
@@ -1219,11 +1227,13 @@ long sys_rt_sigreturn(int r3, int r4, int r5, int r6, 
int r7, int r8,
unsigned long tmp;
int tm_restore = 0;
 #endif
+   void __user *user_cookie;
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
 
rt_sf = (struct rt_sigframe __user *)
(regs->gpr[1] + __SIGNAL_FRAMESIZE + 16);
+   user_cookie = &(rt_sf->user_cookie);
if (!access_ok(VERIFY_READ, rt_sf, sizeof(*rt_sf)))
goto bad;
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -1264,6 +1274,9 @@ long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int 
r7, int r8,
 * always done it up until now so it is probably better not to
 * change it.  -- paulus
 */
+
+   if (verify_clear_sigcookie(user_cookie))
+   goto bad;
 #ifdef CONFIG_PPC64
if (compat_restore_altstack(&rt_sf->uc.uc_stack))
goto bad;
@@ -1404,11 +1417,12 @@ int handle_signal32(struct ksignal *ksig, sigset_t 
*oldset, struct pt_regs *regs
unsigned long newsp = 0;
int sigret;
unsigned long tramp;
-
+   void __user *cookie_location;
/* Set up Signal Frame */
frame = get_sigframe(ksig, get_tm_stackpointer(regs), sizeof(*frame), 
1);
if (unlikely(frame == NULL))
goto badframe;
+   cookie_location = &(frame->user_cookie);
sc = (struct sigcontext __user *) &frame->sctx;
 
 #i

[PATCH 1/2] powerpc/SROP Mitigation: Architecture independent SROP mitigation code

2016-05-17 Thread Rashmica Gupta
This is based off Scotty's patch: https://lkml.org/lkml/2016/3/29/792.
The only difference being that the sig_cookie is apart of the struct
sighand_struct instead of task_struct so the the sig_cookie is shared
between threads.

Signed-off-by: Rashmica Gupta 
---
 fs/exec.c  |  4 
 include/linux/sched.h  |  1 +
 include/linux/signal.h |  2 ++
 kernel/signal.c| 41 +
 4 files changed, 48 insertions(+)

diff --git a/fs/exec.c b/fs/exec.c
index c4010b8207a1..487f3b20b8d8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1231,6 +1232,9 @@ void setup_new_exec(struct linux_binprm * bprm)
/* This is the point of no return */
current->sas_ss_sp = current->sas_ss_size = 0;
 
+   get_random_bytes(¤t->sighand->sig_cookie,
+   sizeof(current->sighand->sig_cookie));
+
if (uid_eq(current_euid(), current_uid()) && gid_eq(current_egid(), 
current_gid()))
set_dumpable(current->mm, SUID_DUMP_USER);
else
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 52c4847b05e2..aa0f2cd2f46b 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -519,6 +519,7 @@ struct sighand_struct {
struct k_sigaction  action[_NSIG];
spinlock_t  siglock;
wait_queue_head_t   signalfd_wqh;
+   unsigned long   sig_cookie;
 };
 
 struct pacct_struct {
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 92557bbce7e7..fae0618b436f 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -280,6 +280,8 @@ extern int get_signal(struct ksignal *ksig);
 extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping);
 extern void exit_signals(struct task_struct *tsk);
 extern void kernel_sigaction(int, __sighandler_t);
+extern int set_sigcookie(unsigned long __user *location);
+extern int verify_clear_sigcookie(unsigned long __user *sig_cookie_ptr);
 
 static inline void allow_signal(int sig)
 {
diff --git a/kernel/signal.c b/kernel/signal.c
index aa9bf00749c1..6db671ebf44b 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2430,6 +2430,47 @@ out:
}
 }
 
+static unsigned long gen_sigcookie(unsigned long __user *location)
+{
+
+   unsigned long sig_cookie;
+
+   sig_cookie = (unsigned long) location ^ current->sighand->sig_cookie;
+
+   return sig_cookie;
+}
+
+int set_sigcookie(unsigned long __user *location)
+{
+
+   unsigned long sig_cookie = gen_sigcookie(location);
+
+   return put_user(sig_cookie, location);
+}
+
+int verify_clear_sigcookie(unsigned long __user *sig_cookie_ptr)
+{
+   unsigned long user_cookie;
+   unsigned long calculated_cookie;
+
+   if (get_user(user_cookie, sig_cookie_ptr))
+   return 1;
+
+   calculated_cookie = gen_sigcookie(sig_cookie_ptr);
+
+   if (user_cookie != calculated_cookie) {
+   pr_warn("Signal protector does not match what kernel set it to"\
+   ". Possible exploit attempt or buggy program!\n");
+   return 1;
+
+   }
+
+   user_cookie = 0;
+   return put_user(user_cookie, sig_cookie_ptr);
+}
+
+EXPORT_SYMBOL(verify_clear_sigcookie);
+EXPORT_SYMBOL(set_sigcookie);
 EXPORT_SYMBOL(recalc_sigpending);
 EXPORT_SYMBOL_GPL(dequeue_signal);
 EXPORT_SYMBOL(flush_signals);
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[RFC 0/2] SROP Mitigation for powerpc

2016-05-17 Thread Rashmica Gupta
This is all derived from Scott Bauer's x86 patches 
(https://lkml.org/lkml/2016/3/29/788). Have tested rc5 with these patches on: 
- BE VM
- BE bare metal
- LE VM
- LE bare metal

with the Linux Test Project runltp test script with all default configs. From 
rc5 to rc5 with these patches no new tests failed. 

Any comments/suggestions are welcome!

Rashmica Gupta (2):
  powerpc/SROP Mitigation: Architecture independent SROP mitigation code
  powerpc/SROP mitigation: Add cookies to sigframes

 arch/powerpc/kernel/signal_32.c | 33 +
 arch/powerpc/kernel/signal_64.c | 21 +++--
 fs/exec.c   |  4 
 include/linux/sched.h   |  1 +
 include/linux/signal.h  |  2 ++
 kernel/signal.c | 41 +
 6 files changed, 96 insertions(+), 6 deletions(-)

-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V2] powerpc/tm: Clean up duplication of code

2016-05-11 Thread Rashmica Gupta
The same logic for tm_abort appears twice, so pull it out into a
function.

Signed-off-by: Rashmica Gupta 
---
v2: Removed some #ifdefs from inside C code and changed the formatting of the
comment.

 arch/powerpc/mm/hash_utils_64.c | 56 +++--
 1 file changed, 26 insertions(+), 30 deletions(-)

diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 7635b1c6b5da..b92cca033131 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1318,6 +1318,30 @@ out_exit:
local_irq_restore(flags);
 }
 
+   /*
+* Transactions are not aborted by tlbiel, only tlbie.
+* Without, syncing a page back to a block device w/ PIO could pick up
+* transactional data (bad!) so we force an abort here.  Before the
+* sync the page will be made read-only, which will flush_hash_page.
+* BIG ISSUE here: if the kernel uses a page from userspace without
+* unmapping it first, it may see the speculated version.
+*/
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+static inline void tlb_flush_abort_tm(int local)
+{
+   if (local && cpu_has_feature(CPU_FTR_TM) &&
+   current->thread.regs &&
+   MSR_TM_ACTIVE(current->thread.regs->msr)) {
+   tm_enable();
+   tm_abort(TM_CAUSE_TLBI);
+   }
+}
+#else
+static inline void tlb_flush_abort_tm(int local)
+{
+}
+#endif
+
 /* WARNING: This is called from hash_low_64.S, if you change this prototype,
  *  do not forget to update the assembly call site !
  */
@@ -1343,21 +1367,7 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, 
int psize, int ssize,
ppc_md.hpte_invalidate(slot, vpn, psize, psize, ssize, local);
} pte_iterate_hashed_end();
 
-#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-   /* Transactions are not aborted by tlbiel, only tlbie.
-* Without, syncing a page back to a block device w/ PIO could pick up
-* transactional data (bad!) so we force an abort here.  Before the
-* sync the page will be made read-only, which will flush_hash_page.
-* BIG ISSUE here: if the kernel uses a page from userspace without
-* unmapping it first, it may see the speculated version.
-*/
-   if (local && cpu_has_feature(CPU_FTR_TM) &&
-   current->thread.regs &&
-   MSR_TM_ACTIVE(current->thread.regs->msr)) {
-   tm_enable();
-   tm_abort(TM_CAUSE_TLBI);
-   }
-#endif
+   tlb_flush_abort_tm(local);
 }
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -1414,21 +1424,7 @@ void flush_hash_hugepage(unsigned long vsid, unsigned 
long addr,
   MMU_PAGE_16M, ssize, local);
}
 tm_abort:
-#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-   /* Transactions are not aborted by tlbiel, only tlbie.
-* Without, syncing a page back to a block device w/ PIO could pick up
-* transactional data (bad!) so we force an abort here.  Before the
-* sync the page will be made read-only, which will flush_hash_page.
-* BIG ISSUE here: if the kernel uses a page from userspace without
-* unmapping it first, it may see the speculated version.
-*/
-   if (local && cpu_has_feature(CPU_FTR_TM) &&
-   current->thread.regs &&
-   MSR_TM_ACTIVE(current->thread.regs->msr)) {
-   tm_enable();
-   tm_abort(TM_CAUSE_TLBI);
-   }
-#endif
+   tlb_flush_abort_tm(local);
return;
 }
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] powerpc/tm: Clean up duplication of code

2016-05-11 Thread Rashmica



On 11/05/16 15:03, Balbir Singh wrote:


On 11/05/16 14:55, Rashmica Gupta wrote:

The same logic for tm_abort appears twice, so pull it out into a
function.

Signed-off-by: Rashmica Gupta 
---
  arch/powerpc/mm/hash_utils_64.c | 47 ++---
  1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 7635b1c6b5da..1cef8f5aee9b 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1318,6 +1318,25 @@ out_exit:
local_irq_restore(flags);
  }
  
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM

+   /* Transactions are not aborted by tlbiel, only tlbie.
+* Without, syncing a page back to a block device w/ PIO could pick up
+* transactional data (bad!) so we force an abort here.  Before the
+* sync the page will be made read-only, which will flush_hash_page.
+* BIG ISSUE here: if the kernel uses a page from userspace without
+* unmapping it first, it may see the speculated version.
+*/
+static inline void abort_tm(int local)
+{
+   if (local && cpu_has_feature(CPU_FTR_TM) &&
+   current->thread.regs &&
+   MSR_TM_ACTIVE(current->thread.regs->msr)) {
+   tm_enable();
+   tm_abort(TM_CAUSE_TLBI);
+   }
+}

While your at this do

#else

static inline void abort_tm(int local)
{
}

If I'm doing that, wouldn't it make more sense to write:

+static inline void abort_tm(int local)
+{
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+   if (local && cpu_has_feature(CPU_FTR_TM) &&
+   current->thread.regs &&
+   MSR_TM_ACTIVE(current->thread.regs->msr)) {
+   tm_enable();
+   tm_abort(TM_CAUSE_TLBI);
+   }
+#endif
+}



+#endif
+
  /* WARNING: This is called from hash_low_64.S, if you change this prototype,
   *  do not forget to update the assembly call site !
   */
@@ -1344,19 +1363,7 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, 
int psize, int ssize,
} pte_iterate_hashed_end();
  
  #ifdef CONFIG_PPC_TRANSACTIONAL_MEM

Then remove these extra #ifdef

-   /* Transactions are not aborted by tlbiel, only tlbie.
-* Without, syncing a page back to a block device w/ PIO could pick up
-* transactional data (bad!) so we force an abort here.  Before the
-* sync the page will be made read-only, which will flush_hash_page.
-* BIG ISSUE here: if the kernel uses a page from userspace without
-* unmapping it first, it may see the speculated version.
-*/
-   if (local && cpu_has_feature(CPU_FTR_TM) &&
-   current->thread.regs &&
-   MSR_TM_ACTIVE(current->thread.regs->msr)) {
-   tm_enable();
-   tm_abort(TM_CAUSE_TLBI);
-   }
+   abort_tm(local);
  #endif
  }
  
@@ -1415,19 +1422,7 @@ void flush_hash_hugepage(unsigned long vsid, unsigned long addr,

}
  tm_abort:
  #ifdef CONFIG_PPC_TRANSACTIONAL_MEM

Then remove these extra #ifdef

-   /* Transactions are not aborted by tlbiel, only tlbie.
-* Without, syncing a page back to a block device w/ PIO could pick up
-* transactional data (bad!) so we force an abort here.  Before the
-* sync the page will be made read-only, which will flush_hash_page.
-* BIG ISSUE here: if the kernel uses a page from userspace without
-* unmapping it first, it may see the speculated version.
-*/
-   if (local && cpu_has_feature(CPU_FTR_TM) &&
-   current->thread.regs &&
-   MSR_TM_ACTIVE(current->thread.regs->msr)) {
-   tm_enable();
-   tm_abort(TM_CAUSE_TLBI);
-   }
+   abort_tm(local);
  #endif
return;
  }



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc/tm: Clean up duplication of code

2016-05-10 Thread Rashmica Gupta
The same logic for tm_abort appears twice, so pull it out into a
function.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/mm/hash_utils_64.c | 47 ++---
 1 file changed, 21 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 7635b1c6b5da..1cef8f5aee9b 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1318,6 +1318,25 @@ out_exit:
local_irq_restore(flags);
 }
 
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+   /* Transactions are not aborted by tlbiel, only tlbie.
+* Without, syncing a page back to a block device w/ PIO could pick up
+* transactional data (bad!) so we force an abort here.  Before the
+* sync the page will be made read-only, which will flush_hash_page.
+* BIG ISSUE here: if the kernel uses a page from userspace without
+* unmapping it first, it may see the speculated version.
+*/
+static inline void abort_tm(int local)
+{
+   if (local && cpu_has_feature(CPU_FTR_TM) &&
+   current->thread.regs &&
+   MSR_TM_ACTIVE(current->thread.regs->msr)) {
+   tm_enable();
+   tm_abort(TM_CAUSE_TLBI);
+   }
+}
+#endif
+
 /* WARNING: This is called from hash_low_64.S, if you change this prototype,
  *  do not forget to update the assembly call site !
  */
@@ -1344,19 +1363,7 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, 
int psize, int ssize,
} pte_iterate_hashed_end();
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-   /* Transactions are not aborted by tlbiel, only tlbie.
-* Without, syncing a page back to a block device w/ PIO could pick up
-* transactional data (bad!) so we force an abort here.  Before the
-* sync the page will be made read-only, which will flush_hash_page.
-* BIG ISSUE here: if the kernel uses a page from userspace without
-* unmapping it first, it may see the speculated version.
-*/
-   if (local && cpu_has_feature(CPU_FTR_TM) &&
-   current->thread.regs &&
-   MSR_TM_ACTIVE(current->thread.regs->msr)) {
-   tm_enable();
-   tm_abort(TM_CAUSE_TLBI);
-   }
+   abort_tm(local);
 #endif
 }
 
@@ -1415,19 +1422,7 @@ void flush_hash_hugepage(unsigned long vsid, unsigned 
long addr,
}
 tm_abort:
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-   /* Transactions are not aborted by tlbiel, only tlbie.
-* Without, syncing a page back to a block device w/ PIO could pick up
-* transactional data (bad!) so we force an abort here.  Before the
-* sync the page will be made read-only, which will flush_hash_page.
-* BIG ISSUE here: if the kernel uses a page from userspace without
-* unmapping it first, it may see the speculated version.
-*/
-   if (local && cpu_has_feature(CPU_FTR_TM) &&
-   current->thread.regs &&
-   MSR_TM_ACTIVE(current->thread.regs->msr)) {
-   tm_enable();
-   tm_abort(TM_CAUSE_TLBI);
-   }
+   abort_tm(local);
 #endif
return;
 }
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH V2] lib/test-hexdump: Changed to work on BE

2016-05-09 Thread Rashmica Gupta
test-hexdump.c doesn't work on BE because the test data is in LE format.
So add in data for BE.

Signed-off-by: Rashmica Gupta 
---

V2: Checking __BYTE_ORDER__. 

 lib/test_hexdump.c | 35 +++
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 3f415d8101f3..9de91a1b98bf 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -18,29 +18,48 @@ static const unsigned char data_b[] = {
 
 static const unsigned char data_a[] = ".2.{p..$}.4...1.L...C...";
 
-static const char * const test_data_1_le[] __initconst = {
+static const char * const test_data_1[] __initconst = {
"be", "32", "db", "7b", "0a", "18", "93", "b2",
"70", "ba", "c4", "24", "7d", "83", "34", "9b",
"a6", "9c", "31", "ad", "9c", "0f", "ac", "e9",
"4c", "d1", "19", "99", "43", "b1", "af", "0c",
 };
 
-static const char * const test_data_2_le[] __initconst = {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+static const char * const test_data_2[] __initconst = {
"32be", "7bdb", "180a", "b293",
"ba70", "24c4", "837d", "9b34",
"9ca6", "ad31", "0f9c", "e9ac",
"d14c", "9919", "b143", "0caf",
 };
 
-static const char * const test_data_4_le[] __initconst = {
+static const char * const test_data_4[] __initconst = {
"7bdb32be", "b293180a", "24c4ba70", "9b34837d",
"ad319ca6", "e9ac0f9c", "9919d14c", "0cafb143",
 };
 
-static const char * const test_data_8_le[] __initconst = {
+static const char * const test_data_8[] __initconst = {
"b293180a7bdb32be", "9b34837d24c4ba70",
"e9ac0f9cad319ca6", "0cafb1439919d14c",
 };
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+static const char * const test_data_2[] __initconst = {
+   "be32", "db7b", "0a18", "93b2",
+   "70ba", "c424", "7d83", "349b",
+   "a69c", "31ad", "9c0f", "ace9",
+   "4cd1", "1999", "43b1", "af0c",
+};
+
+static const char * const test_data_4[] __initconst = {
+   "be32db7b", "0a1893b2", "70bac424", "7d83349b",
+   "a69c31ad", "9c0face9", "4cd11999", "43b1af0c",
+};
+
+static const char * const test_data_8[] __initconst = {
+   "be32db7b0a1893b2", "70bac4247d83349b",
+   "a69c31ad9c0face9", "4cd1199943b1af0c",
+};
+#endif
 
 #define FILL_CHAR  '#'
 
@@ -67,13 +86,13 @@ static void __init test_hexdump_prepare_test(size_t len, 
int rowsize,
gs = 1;
 
if (gs == 8)
-   result = test_data_8_le;
+   result = test_data_8;
else if (gs == 4)
-   result = test_data_4_le;
+   result = test_data_4;
else if (gs == 2)
-   result = test_data_2_le;
+   result = test_data_2;
else
-   result = test_data_1_le;
+   result = test_data_1;
 
/* hex dump */
p = test;
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc: Remove unused remnants from A2 cpu

2016-04-11 Thread Rashmica Gupta
Support for the A2 cpu was removed in commit fb5a515704d7 ("powerpc:
Remove platforms/wsp and associated pieces"), and the externs:
__setup_cpu_a2 and __restore_cpu_a2 are still around and unused, so
remove them.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/cputable.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 6c662b8de90d..eeeacf6235a3 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -63,7 +63,6 @@ extern void __setup_cpu_745x(unsigned long offset, struct 
cpu_spec* spec);
 extern void __setup_cpu_ppc970(unsigned long offset, struct cpu_spec* spec);
 extern void __setup_cpu_ppc970MP(unsigned long offset, struct cpu_spec* spec);
 extern void __setup_cpu_pa6t(unsigned long offset, struct cpu_spec* spec);
-extern void __setup_cpu_a2(unsigned long offset, struct cpu_spec* spec);
 extern void __restore_cpu_pa6t(void);
 extern void __restore_cpu_ppc970(void);
 extern void __setup_cpu_power7(unsigned long offset, struct cpu_spec* spec);
@@ -72,7 +71,6 @@ extern void __setup_cpu_power8(unsigned long offset, struct 
cpu_spec* spec);
 extern void __restore_cpu_power8(void);
 extern void __setup_cpu_power9(unsigned long offset, struct cpu_spec* spec);
 extern void __restore_cpu_power9(void);
-extern void __restore_cpu_a2(void);
 extern void __flush_tlb_power7(unsigned int action);
 extern void __flush_tlb_power8(unsigned int action);
 extern void __flush_tlb_power9(unsigned int action);
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] lib/test-hexdump: Changed to work on BE

2016-04-11 Thread Rashmica Gupta
test-hexdump.c doesn't work on BE because the test data is in LE format.
So add in data for BE.

Signed-off-by: Rashmica Gupta 
---
 lib/test_hexdump.c | 35 +++
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 3f415d8101f3..cfd86d59e0d0 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -18,29 +18,48 @@ static const unsigned char data_b[] = {
 
 static const unsigned char data_a[] = ".2.{p..$}.4...1.L...C...";
 
-static const char * const test_data_1_le[] __initconst = {
+static const char * const test_data_1[] __initconst = {
"be", "32", "db", "7b", "0a", "18", "93", "b2",
"70", "ba", "c4", "24", "7d", "83", "34", "9b",
"a6", "9c", "31", "ad", "9c", "0f", "ac", "e9",
"4c", "d1", "19", "99", "43", "b1", "af", "0c",
 };
 
-static const char * const test_data_2_le[] __initconst = {
+#ifdef __LITTLE_ENDIAN
+static const char * const test_data_2[] __initconst = {
"32be", "7bdb", "180a", "b293",
"ba70", "24c4", "837d", "9b34",
"9ca6", "ad31", "0f9c", "e9ac",
"d14c", "9919", "b143", "0caf",
 };
 
-static const char * const test_data_4_le[] __initconst = {
+static const char * const test_data_4[] __initconst = {
"7bdb32be", "b293180a", "24c4ba70", "9b34837d",
"ad319ca6", "e9ac0f9c", "9919d14c", "0cafb143",
 };
 
-static const char * const test_data_8_le[] __initconst = {
+static const char * const test_data_8[] __initconst = {
"b293180a7bdb32be", "9b34837d24c4ba70",
"e9ac0f9cad319ca6", "0cafb1439919d14c",
 };
+#elif __BIG_ENDIAN
+static const char * const test_data_2[] __initconst = {
+   "be32", "db7b", "0a18", "93b2",
+   "70ba", "c424", "7d83", "349b",
+   "a69c", "31ad", "9c0f", "ace9",
+   "4cd1", "1999", "43b1", "af0c",
+};
+
+static const char * const test_data_4[] __initconst = {
+   "be32db7b", "0a1893b2", "70bac424", "7d83349b",
+   "a69c31ad", "9c0face9", "4cd11999", "43b1af0c",
+};
+
+static const char * const test_data_8[] __initconst = {
+   "be32db7b0a1893b2", "70bac4247d83349b",
+   "a69c31ad9c0face9", "4cd1199943b1af0c",
+};
+#endif
 
 #define FILL_CHAR  '#'
 
@@ -67,13 +86,13 @@ static void __init test_hexdump_prepare_test(size_t len, 
int rowsize,
gs = 1;
 
if (gs == 8)
-   result = test_data_8_le;
+   result = test_data_8;
else if (gs == 4)
-   result = test_data_4_le;
+   result = test_data_4;
else if (gs == 2)
-   result = test_data_2_le;
+   result = test_data_2;
else
-   result = test_data_1_le;
+   result = test_data_1;
 
/* hex dump */
p = test;
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/2] powerpc/pagetable: Add option to dump kernel hashpagetable

2016-03-28 Thread Rashmica Gupta
Useful to be able to dump the kernel hash page table to check
which pages are hashed along with their sizes and other details.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/mm/Makefile |   3 +-
 arch/powerpc/mm/dump_hashpagetable.c | 501 +++
 2 files changed, 503 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/mm/dump_hashpagetable.c

diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 6935c6204fbc..0bd48b345ff3 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -41,4 +41,5 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
-obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o \
+  dump_hashpagetable.o
diff --git a/arch/powerpc/mm/dump_hashpagetable.c 
b/arch/powerpc/mm/dump_hashpagetable.c
new file mode 100644
index ..fbd746ffe26a
--- /dev/null
+++ b/arch/powerpc/mm/dump_hashpagetable.c
@@ -0,0 +1,501 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * This traverses the kernel virtual memory and dumps the pages that are in
+ * the hash pagetable, along with their flags to
+ * /sys/kernel/debug/kernel_hash_pagetable.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+static struct addr_marker address_markers[] = {
+   { PAGE_OFFSET,  "Start of kernel VM"},
+   { VMALLOC_START,"vmalloc() Area" },
+   { VMALLOC_END,  "vmalloc() End" },
+   { ISA_IO_BASE,  "isa I/O start" },
+   { ISA_IO_END,   "isa I/O end" },
+   { PHB_IO_BASE,  "phb I/O start" },
+   { PHB_IO_END,   "phb I/O end" },
+   { IOREMAP_BASE, "I/O remap start" },
+   { IOREMAP_END,  "I/O remap end" },
+   { VMEMMAP_BASE, "vmemmap start" },
+   { -1,   NULL },
+};
+
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned level;
+   u64 current_flags;
+};
+
+struct flag_info {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+   boolis_val;
+};
+
+static const struct flag_info v_flag_array[] = {
+   {
+   .mask   = SLB_VSID_B,
+   .val= SLB_VSID_B_256M,
+   .set= "ssize: 256M",
+   .clear  = "ssize: 1T  ",
+   }, {
+   .mask   = HPTE_V_SECONDARY,
+   .val= HPTE_V_SECONDARY,
+   .set= "secondary",
+   .clear  = "primary  ",
+   }, {
+   .mask   = HPTE_V_VALID,
+   .val= HPTE_V_VALID,
+   .set= "valid  ",
+   .clear  = "invalid",
+   }, {
+   .mask   = HPTE_V_BOLTED,
+   .val= HPTE_V_BOLTED,
+   .set= "bolted",
+   .clear  = "",
+   }
+};
+
+static const struct flag_info r_flag_array[] = {
+   {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RWXX,
+   .set= "prot:RW--",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RWRX,
+   .set= "prot:RWR-",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RWRW,
+   .set= "prot:RWRW",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RXRX,
+   .set= "prot:R-R-",
+   }, {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= PP_RXXX,
+   .set= "prot:R---",
+   }, {
+   .mask   = HPTE_R_KEY_HI | HPTE_R_KEY_LO,
+   .val= HPTE_R_KEY_HI | HPTE_R_KEY_LO,
+   .set= "key",
+   .clear  = "",
+   .is_val = true,
+   }, {
+   .mask   = HPTE_R_R,
+   .val= HPTE_R_R,
+

[v2 PATCH 1/2] powerpc/pagetable: Add option to dump the linux pagetables

2016-03-28 Thread Rashmica Gupta
Useful to be able to dump the kernels page tables to check permissions
and memory types - derived from arm64's implementation.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Signed-off-by: Rashmica Gupta 
---
Do not check for COMBO pages if default page size is 4K.

 arch/powerpc/Kconfig.debug |  12 +
 arch/powerpc/mm/Makefile   |   1 +
 arch/powerpc/mm/dump_linuxpagetables.c | 398 +
 3 files changed, 411 insertions(+)
 create mode 100644 arch/powerpc/mm/dump_linuxpagetables.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 638f9ce740f5..26a60effea1a 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -344,4 +344,16 @@ config FAIL_IOMMU
 
  If you are unsure, say N.
 
+config PPC_PTDUMP
+bool "Export kernel pagetable layout to userspace via debugfs"
+depends on DEBUG_KERNEL
+select DEBUG_FS
+help
+ This option exports the state of the kernel pagetables to a
+ debugfs file. This is only useful for kernel developers who are
+ working in architecture specific areas of the kernel - probably
+ not a good idea to enable this feature in a production kernel.
+
+ If you are unsure, say N.
+
 endmenu
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index adfee3f1aeb9..6935c6204fbc 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -41,3 +41,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o
diff --git a/arch/powerpc/mm/dump_linuxpagetables.c 
b/arch/powerpc/mm/dump_linuxpagetables.c
new file mode 100644
index ..566ae4487a19
--- /dev/null
+++ b/arch/powerpc/mm/dump_linuxpagetables.c
@@ -0,0 +1,398 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * This traverses the kernel pagetables and dumps the
+ * information about the used sections of memory to
+ * /sys/kernel/debug/kernel_pagetables.
+ *
+ * Derived from the arm64 implementation:
+ * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
+ * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+static struct addr_marker address_markers[] = {
+   { VMALLOC_START,"vmalloc() Area" },
+   { VMALLOC_END,  "vmalloc() End" },
+   { ISA_IO_BASE,  "isa I/O start" },
+   { ISA_IO_END,   "isa I/O end" },
+   { PHB_IO_BASE,  "phb I/O start" },
+   { PHB_IO_END,   "phb I/O end" },
+   { IOREMAP_BASE, "I/O remap start" },
+   { IOREMAP_END,  "I/O remap end" },
+   { -1,   NULL },
+};
+
+/*
+ * To visualise what is happening,
+ *
+ *  - PTRS_PER_P** = how many entries there are in the corresponding P**
+ *  - P**_SHIFT = how many bits of the address we use to index into the
+ * corresponding P**
+ *  - P**_SIZE is how much memory we can access through the table - not the
+ * size of the table itself.
+ * P**={PGD, PUD, PMD, PTE}
+ *
+ *
+ * Each entry of the PGD points to a PUD. Each entry of a PUD points to a
+ * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to
+ * a page.
+ *
+ * In the case where there are only 3 levels, the PUD is folded into the
+ * PGD: every PUD has only one entry which points to the PMD.
+ *
+ * The page dumper groups page table entries of the same type into a single
+ * description. It uses pg_state to track the range information while
+ * iterating over the PTE entries. When the continuity is broken it then
+ * dumps out a description of the range - ie PTEs that are virtually contiguous
+ * with the same PTE flags are chunked together. This is to make it clear how
+ * different areas of the kernel virtual memory are used.
+ *
+ */
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned level;
+   u64 current_flags;
+};
+
+struct flag_info {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+   boolis_val;
+   int shift;
+};
+
+static const struct flag_info flag_array[] = {
+   {
+

[PATCH 2/2] powerpc/pagetable: Add option to dump kernel hashpagetable

2016-03-21 Thread Rashmica Gupta
Useful to be able to dump the kernel hash page table to check
which pages are hashed along with their sizes and other details.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/mm/Makefile |   3 +-
 arch/powerpc/mm/dump_hashpagetable.c | 488 +++
 2 files changed, 490 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/mm/dump_hashpagetable.c

diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 6935c6204fbc..0bd48b345ff3 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -41,4 +41,5 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
-obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o \
+  dump_hashpagetable.o
diff --git a/arch/powerpc/mm/dump_hashpagetable.c 
b/arch/powerpc/mm/dump_hashpagetable.c
new file mode 100644
index ..044fd13e4d07
--- /dev/null
+++ b/arch/powerpc/mm/dump_hashpagetable.c
@@ -0,0 +1,488 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * This traverses the kernel virtual memory and dumps the pages that are in
+ * the hash pagetable, along with their flags to
+ * /sys/kernel/debug/kernel_hash_pagetable.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+static struct addr_marker address_markers[] = {
+   { PAGE_OFFSET,  "Start of kernel VM"},
+   { VMALLOC_START,"vmalloc() Area" },
+   { VMALLOC_END,  "vmalloc() End" },
+   { ISA_IO_BASE,  "isa I/O start" },
+   { ISA_IO_END,   "isa I/O end" },
+   { PHB_IO_BASE,  "phb I/O start" },
+   { PHB_IO_END,   "phb I/O end" },
+   { IOREMAP_BASE, "I/O remap start" },
+   { IOREMAP_END,  "I/O remap end" },
+   { VMEMMAP_BASE, "vmemmap start" },
+   { -1,   NULL },
+};
+
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned level;
+   u64 current_flags;
+};
+
+struct flag_info {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+   boolis_val;
+};
+
+static const struct flag_info v_flag_array[] = {
+   {
+   .mask   = SLB_VSID_B,
+   .val= SLB_VSID_B_256M,
+   .set= "ssize: 256M",
+   .clear  = "ssize: 1T  ",
+   }, {
+   .mask   = HPTE_V_SECONDARY,
+   .val= HPTE_V_SECONDARY,
+   .set= "secondary",
+   .clear  = "primary  ",
+   }, {
+   .mask   = HPTE_V_VALID,
+   .val= HPTE_V_VALID,
+   .set= "valid  ",
+   .clear  = "invalid",
+   }, {
+   .mask   = HPTE_V_BOLTED,
+   .val= HPTE_V_BOLTED,
+   .set= "bolted",
+   .clear  = "",
+   }
+};
+
+static const struct flag_info r_flag_array[] = {
+   {
+   .mask   = HPTE_R_PP0 | HPTE_R_PP,
+   .val= HPTE_R_PP0 | HPTE_R_PP,
+   .set= "prot",
+   .clear  = "",
+   .is_val = true,
+   }, {
+   .mask   = HPTE_R_KEY_HI | HPTE_R_KEY_LO,
+   .val= HPTE_R_KEY_HI | HPTE_R_KEY_LO,
+   .set= "key",
+   .clear  = "",
+   .is_val = true,
+   }, {
+   .mask   = HPTE_R_R,
+   .val= HPTE_R_R,
+   .set= "ref",
+   .clear  = "   ",
+   }, {
+   .mask   = HPTE_R_C,
+   .val= HPTE_R_C,
+   .set= "changed",
+   .clear  = "   ",
+   }, {
+   .mask   = HPTE_R_N,
+   .val= HPTE_R_N,
+   .set= "no execute",
+   .clear  = "",
+   }, {
+   .mask   = HPTE_R_WIMG,
+  

[PATCH 1/2] powerpc/pagetable: Add option to dump the linux pagetables

2016-03-21 Thread Rashmica Gupta
Useful to be able to dump the kernels page tables to check permissions
and memory types - derived from arm64's implementation.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/Kconfig.debug |  12 ++
 arch/powerpc/mm/Makefile   |   1 +
 arch/powerpc/mm/dump_linuxpagetables.c | 377 +
 3 files changed, 390 insertions(+)
 create mode 100644 arch/powerpc/mm/dump_linuxpagetables.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 638f9ce740f5..26a60effea1a 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -344,4 +344,16 @@ config FAIL_IOMMU
 
  If you are unsure, say N.
 
+config PPC_PTDUMP
+bool "Export kernel pagetable layout to userspace via debugfs"
+depends on DEBUG_KERNEL
+select DEBUG_FS
+help
+ This option exports the state of the kernel pagetables to a
+ debugfs file. This is only useful for kernel developers who are
+ working in architecture specific areas of the kernel - probably
+ not a good idea to enable this feature in a production kernel.
+
+ If you are unsure, say N.
+
 endmenu
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index adfee3f1aeb9..6935c6204fbc 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -41,3 +41,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump_linuxpagetables.o
diff --git a/arch/powerpc/mm/dump_linuxpagetables.c 
b/arch/powerpc/mm/dump_linuxpagetables.c
new file mode 100644
index ..f97fbfdac4b9
--- /dev/null
+++ b/arch/powerpc/mm/dump_linuxpagetables.c
@@ -0,0 +1,377 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * This traverses the kernel pagetables and dumps the
+ * information about the used sections of memory to
+ * /sys/kernel/debug/kernel_pagetables.
+ *
+ * Derived from the arm64 implementation:
+ * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
+ * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+static struct addr_marker address_markers[] = {
+   { VMALLOC_START,"vmalloc() Area" },
+   { VMALLOC_END,  "vmalloc() End" },
+   { ISA_IO_BASE,  "isa I/O start" },
+   { ISA_IO_END,   "isa I/O end" },
+   { PHB_IO_BASE,  "phb I/O start" },
+   { PHB_IO_END,   "phb I/O end" },
+   { IOREMAP_BASE, "I/O remap start" },
+   { IOREMAP_END,  "I/O remap end" },
+   { -1,   NULL },
+};
+
+/*
+ * To visualise what is happening,
+ *
+ *  - PTRS_PER_P** = how many entries there are in the corresponding P**
+ *  - P**_SHIFT = how many bits of the address we use to index into the
+ * corresponding P**
+ *  - P**_SIZE is how much memory we can access through the table - not the
+ * size of the table itself.
+ * P**={PGD, PUD, PMD, PTE}
+ *
+ *
+ * Each entry of the PGD points to a PUD. Each entry of a PUD points to a
+ * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to
+ * a page.
+ *
+ * In the case where there are only 3 levels, the PUD is folded into the
+ * PGD: every PUD has only one entry which points to the PMD.
+ *
+ * The page dumper groups page table entries of the same type into a single
+ * description. It uses pg_state to track the range information while
+ * iterating over the PTE entries. When the continuity is broken it then
+ * dumps out a description of the range - ie PTEs that are virtually contiguous
+ * with the same PTE flags are chunked together. This is to make it clear how
+ * different areas of the kernel virtual memory are used.
+ *
+ */
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned level;
+   u64 current_flags;
+};
+
+struct flag_info {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+};
+
+static const struct flag_info flag_array[] = {
+   {
+   .mask   = _PAGE_USER,
+   .val= _PAGE_USER,
+   .set= "user"

Re: [PATCH] powerpc/pagetable: Add option to dump kernel pagetable

2016-02-22 Thread Rashmica



On 23/02/16 16:30, Anshuman Khandual wrote:

On 02/23/2016 03:57 AM, Rashmica wrote:

Hi Anshuman,

Thanks for the feedback!

On 22/02/16 21:13, Anshuman Khandual wrote:

On 02/22/2016 11:32 AM, Rashmica Gupta wrote:

Useful to be able to dump the kernel page tables to check permissions
and
memory types - derived from arm64's implementation.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Tested on 64BE and 64LE with both 4K and 64K page sizes.
---

This statement above must be after the  line else it will be part of
the commit message or you wanted the test note as part of commit message
itself ?

The patch seems to contain some white space problems. Please clean
them up.

Will do!

   arch/powerpc/Kconfig.debug |  12 ++
   arch/powerpc/mm/Makefile   |   1 +
   arch/powerpc/mm/dump.c | 364
+
   3 files changed, 377 insertions(+)
   create mode 100644 arch/powerpc/mm/dump.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 638f9ce740f5..e4883880abe3 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -344,4 +344,16 @@ config FAIL_IOMMU
   If you are unsure, say N.
   +config PPC_PTDUMP
+bool "Export kernel pagetable layout to userspace via debugfs"
+depends on DEBUG_KERNEL
+select DEBUG_FS
+help
+  This options dumps the state of the kernel pagetables in a
debugfs
+  file. This is only useful for kernel developers who are
working in
+  architecture specific areas of the kernel - probably not a
good idea to
+  enable this feature in a production kernel.

Just clean the paragraph alignment here
..


+
+  If you are unsure, say N.
+
   endmenu
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 1ffeda85c086..16f84bdd7597 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -40,3 +40,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
   obj-$(CONFIG_HIGHMEM)+= highmem.o
   obj-$(CONFIG_PPC_COPRO_BASE)+= copro_fault.o
   obj-$(CONFIG_SPAPR_TCE_IOMMU)+= mmu_context_iommu.o
+obj-$(CONFIG_PPC_PTDUMP)+= dump.o

File name like "[kernel_]pgtable_dump.c" will sound better ? Or
just use like the X86 one "dump_pagetables.c". "dump.c" sounds
very generic.

Yup, good point.

diff --git a/arch/powerpc/mm/dump.c b/arch/powerpc/mm/dump.c
new file mode 100644
index ..937b10fc40cc
--- /dev/null
+++ b/arch/powerpc/mm/dump.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * Debug helper to dump the current kernel pagetables of the system
+ * so that we can see what the various memory ranges are set to.
+ *
+ * Derived from the arm64 implementation:
+ * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
+ * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PUD_TYPE_MASK   (_AT(u64, 3) << 0)
+#define PUD_TYPE_SECT   (_AT(u64, 1) << 0)
+#define PMD_TYPE_MASK   (_AT(u64, 3) << 0)
+#define PMD_TYPE_SECT   (_AT(u64, 1) << 0)
+
+
+#if CONFIG_PGTABLE_LEVELS == 2
+#include 
+#elif CONFIG_PGTABLE_LEVELS == 3
+#include 
+#endif

Really ? Do we have any platform with only 2 level of page table ?
   

I'm not sure - was trying to cover all the bases. If you're
confident that we don't, I can remove it.

I am not sure though, may be Michael or Mikey can help here.


+
+#define pmd_sect(pmd)  ((pmd_val(pmd) & PMD_TYPE_MASK) ==
PMD_TYPE_SECT)
+#ifdef CONFIG_PPC_64K_PAGES
+#define pud_sect(pud)   (0)
+#else
+#define pud_sect(pud)   ((pud_val(pud) & PUD_TYPE_MASK) == \
+   PUD_TYPE_SECT)
+#endif

Can you please explain the use of pmd_sect() and pud_sect() defines ?


+
+
+struct addr_marker {
+unsigned long start_address;
+const char *name;
+};

All the architectures are using the same structure addr_marker.
Cannot we just move it to a generic header file ? There are
other such common structures like these in the file which are
used across architectures and can be moved to some where common ?

Could do that. Where do you think would be the appropriate place
for such a header file?

We can start at include/linux/mmdebug.h header file.


+
+enum address_markers_idx {
+VMALLOC_START_NR = 0,
+VMALLOC_END_NR,
+ISA_IO_START_NR,
+ISA_IO_END_NR,
+PHB_IO_START_NR,
+PHB_IO_END_NR,
+IOREMAP_START_NR,
+IOREM

Re: [PATCH] powerpc/pagetable: Add option to dump kernel pagetable

2016-02-22 Thread Rashmica

Hi Anshuman,

Thanks for the feedback!

On 22/02/16 21:13, Anshuman Khandual wrote:

On 02/22/2016 11:32 AM, Rashmica Gupta wrote:

Useful to be able to dump the kernel page tables to check permissions and
memory types - derived from arm64's implementation.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Tested on 64BE and 64LE with both 4K and 64K page sizes.
---

This statement above must be after the  line else it will be part of
the commit message or you wanted the test note as part of commit message
itself ?

The patch seems to contain some white space problems. Please clean them up.

Will do!

  arch/powerpc/Kconfig.debug |  12 ++
  arch/powerpc/mm/Makefile   |   1 +
  arch/powerpc/mm/dump.c | 364 +
  3 files changed, 377 insertions(+)
  create mode 100644 arch/powerpc/mm/dump.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 638f9ce740f5..e4883880abe3 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -344,4 +344,16 @@ config FAIL_IOMMU
  
  	  If you are unsure, say N.
  
+config PPC_PTDUMP

+bool "Export kernel pagetable layout to userspace via debugfs"
+depends on DEBUG_KERNEL
+select DEBUG_FS
+help
+  This options dumps the state of the kernel pagetables in a debugfs
+  file. This is only useful for kernel developers who are working in
+  architecture specific areas of the kernel - probably not a good idea 
to
+  enable this feature in a production kernel.

Just clean the paragraph alignment here 
..


+
+  If you are unsure, say N.
+
  endmenu
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 1ffeda85c086..16f84bdd7597 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -40,3 +40,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
  obj-$(CONFIG_HIGHMEM) += highmem.o
  obj-$(CONFIG_PPC_COPRO_BASE)  += copro_fault.o
  obj-$(CONFIG_SPAPR_TCE_IOMMU) += mmu_context_iommu.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump.o

File name like "[kernel_]pgtable_dump.c" will sound better ? Or
just use like the X86 one "dump_pagetables.c". "dump.c" sounds
very generic.

Yup, good point.

diff --git a/arch/powerpc/mm/dump.c b/arch/powerpc/mm/dump.c
new file mode 100644
index ..937b10fc40cc
--- /dev/null
+++ b/arch/powerpc/mm/dump.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ *
+ * Debug helper to dump the current kernel pagetables of the system
+ * so that we can see what the various memory ranges are set to.
+ *
+ * Derived from the arm64 implementation:
+ * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
+ * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PUD_TYPE_MASK   (_AT(u64, 3) << 0)
+#define PUD_TYPE_SECT   (_AT(u64, 1) << 0)
+#define PMD_TYPE_MASK   (_AT(u64, 3) << 0)
+#define PMD_TYPE_SECT   (_AT(u64, 1) << 0)
+
+
+#if CONFIG_PGTABLE_LEVELS == 2
+#include 
+#elif CONFIG_PGTABLE_LEVELS == 3
+#include 
+#endif

Really ? Do we have any platform with only 2 level of page table ?
  

I'm not sure - was trying to cover all the bases. If you're
confident that we don't, I can remove it.

+
+#define pmd_sect(pmd)  ((pmd_val(pmd) & PMD_TYPE_MASK) == PMD_TYPE_SECT)
+#ifdef CONFIG_PPC_64K_PAGES
+#define pud_sect(pud)   (0)
+#else
+#define pud_sect(pud)   ((pud_val(pud) & PUD_TYPE_MASK) == \
+   PUD_TYPE_SECT)
+#endif

Can you please explain the use of pmd_sect() and pud_sect() defines ?


+   
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};

All the architectures are using the same structure addr_marker.
Cannot we just move it to a generic header file ? There are
other such common structures like these in the file which are
used across architectures and can be moved to some where common ?

Could do that. Where do you think would be the appropriate place
for such a header file?

+
+enum address_markers_idx {
+   VMALLOC_START_NR = 0,
+   VMALLOC_END_NR,
+   ISA_IO_START_NR,
+   ISA_IO_END_NR,
+   PHB_IO_START_NR,
+   PHB_IO_END_NR,
+   IOREMAP_START_NR,
+   IOREMP_END_NR,
+};

Where these are used ? ^ I dont see any where.

Whoops, yes those are not used anymore.


Also as it dumps only the kernel virtual mapping, should

[PATCH] powerpc/pagetable: Add option to dump kernel pagetable

2016-02-21 Thread Rashmica Gupta
Useful to be able to dump the kernel page tables to check permissions and
memory types - derived from arm64's implementation.

Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
config option must be selected.

Tested on 64BE and 64LE with both 4K and 64K page sizes.
---
 arch/powerpc/Kconfig.debug |  12 ++
 arch/powerpc/mm/Makefile   |   1 +
 arch/powerpc/mm/dump.c | 364 +
 3 files changed, 377 insertions(+)
 create mode 100644 arch/powerpc/mm/dump.c

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 638f9ce740f5..e4883880abe3 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -344,4 +344,16 @@ config FAIL_IOMMU
 
  If you are unsure, say N.
 
+config PPC_PTDUMP
+bool "Export kernel pagetable layout to userspace via debugfs"
+depends on DEBUG_KERNEL
+select DEBUG_FS
+help
+  This options dumps the state of the kernel pagetables in a debugfs
+  file. This is only useful for kernel developers who are working in
+  architecture specific areas of the kernel - probably not a good idea 
to
+  enable this feature in a production kernel.
+
+  If you are unsure, say N.
+
 endmenu
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index 1ffeda85c086..16f84bdd7597 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -40,3 +40,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
 obj-$(CONFIG_HIGHMEM)  += highmem.o
 obj-$(CONFIG_PPC_COPRO_BASE)   += copro_fault.o
 obj-$(CONFIG_SPAPR_TCE_IOMMU)  += mmu_context_iommu.o
+obj-$(CONFIG_PPC_PTDUMP)   += dump.o
diff --git a/arch/powerpc/mm/dump.c b/arch/powerpc/mm/dump.c
new file mode 100644
index ..937b10fc40cc
--- /dev/null
+++ b/arch/powerpc/mm/dump.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2016, Rashmica Gupta, IBM Corp.
+ * 
+ * Debug helper to dump the current kernel pagetables of the system
+ * so that we can see what the various memory ranges are set to.
+ * 
+ * Derived from the arm64 implementation:
+ * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
+ * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PUD_TYPE_MASK   (_AT(u64, 3) << 0)
+#define PUD_TYPE_SECT   (_AT(u64, 1) << 0)
+#define PMD_TYPE_MASK   (_AT(u64, 3) << 0)
+#define PMD_TYPE_SECT   (_AT(u64, 1) << 0)
+
+ 
+#if CONFIG_PGTABLE_LEVELS == 2
+#include 
+#elif CONFIG_PGTABLE_LEVELS == 3
+#include 
+#endif
+ 
+#define pmd_sect(pmd)  ((pmd_val(pmd) & PMD_TYPE_MASK) == PMD_TYPE_SECT)
+#ifdef CONFIG_PPC_64K_PAGES
+#define pud_sect(pud)   (0)
+#else
+#define pud_sect(pud)   ((pud_val(pud) & PUD_TYPE_MASK) == \
+   PUD_TYPE_SECT)
+#endif
+
+
+struct addr_marker {
+   unsigned long start_address;
+   const char *name;
+};
+
+enum address_markers_idx {
+   VMALLOC_START_NR = 0,
+   VMALLOC_END_NR,
+   ISA_IO_START_NR,
+   ISA_IO_END_NR,
+   PHB_IO_START_NR,
+   PHB_IO_END_NR,
+   IOREMAP_START_NR,
+   IOREMP_END_NR,
+};
+
+static struct addr_marker address_markers[] = {
+   { VMALLOC_START,"vmalloc() Area" },
+   { VMALLOC_END,  "vmalloc() End" },
+   { ISA_IO_BASE,  "isa I/O start" },
+   { ISA_IO_END,   "isa I/O end" },
+   { PHB_IO_BASE,  "phb I/O start" },
+   { PHB_IO_END,   "phb I/O end" },
+   { IOREMAP_BASE, "I/O remap start" },
+   { IOREMAP_END,  "I/O remap end" },
+   { -1,   NULL },
+};
+
+/*
+ * The page dumper groups page table entries of the same type into a single
+ * description. It uses pg_state to track the range information while
+ * iterating over the pte entries. When the continuity is broken it then
+ * dumps out a description of the range.
+ */
+struct pg_state {
+   struct seq_file *seq;
+   const struct addr_marker *marker;
+   unsigned long start_address;
+   unsigned level;
+   u64 current_prot;
+};
+
+struct prot_bits {
+   u64 mask;
+   u64 val;
+   const char  *set;
+   const char  *clear;
+};
+
+static const struct prot_bits pte_bits[] = {
+   {
+   .mask   = _PAGE_USER,
+   .val= _PAGE_USER,
+   .set= "user",
+   .clear  = "",

[PATCH V2] powerpc/Kconfig: Update config option based on page size.

2016-02-18 Thread Rashmica Gupta
Currently on PPC64 changing kernel pagesize from 4K to 64K leaves
FORCE_MAX_ZONEORDER set to 13 - which produces a compile error.

The error occurs because of the following constraint (from
include/linux/mmzone.h) being violated:

MAX_ORDER -1 + PAGESHIFT <= SECTION_SIZE_BITS.

Expanding this out, we get:

FORCE_MAX_ZONEBITS <= 25 - PAGESHIFT,

which requires, for a 64K page, FORCE_MAX_ZONEBITS <= 9. Thus set max
value of FORCE_MAX_ZONEORDER for 64K pages to 9, and 4K pages to 13.

Also, check the minimum value:
In include/linux/huge_mm.h, we have the constraint HPAGE_PMD_ORDER <
MAX_ORDER which expands out to:

PTE_INDEX_SIZE < FORCE_MAX_ZONEORDER.

PTE_INDEX_SIZE is:
9 (4k hash or no hash 4K pgtable) or
8 (64K hash or no hash 64K pgtable).
Thus a min value of 8 for 64K pages and 9 for 4K pages is reasonable.

So, update the range of FORCE_MAX_ZONEORDER from 9-64 to 8-9 for 64K pages
and from 13-64 to 9-13 for 4K pages.

Signed-off-by: Rashmica Gupta 
---

v2: Changed the range for 4K pages and minimum for 64K pages as suggested
by Balbir Singh. 


 arch/powerpc/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e4824fd04bb7..b933530821fb 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -585,9 +585,9 @@ endchoice
 
 config FORCE_MAX_ZONEORDER
int "Maximum zone order"
-   range 9 64 if PPC64 && PPC_64K_PAGES
+   range 8 9 if PPC64 && PPC_64K_PAGES
default "9" if PPC64 && PPC_64K_PAGES
-   range 13 64 if PPC64 && !PPC_64K_PAGES
+   range 9 13 if PPC64 && !PPC_64K_PAGES
default "13" if PPC64 && !PPC_64K_PAGES
range 9 64 if PPC32 && PPC_16K_PAGES
default "9" if PPC32 && PPC_16K_PAGES
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH] powerpc/Kconfig: Update config option based on page size.

2016-02-18 Thread Rashmica



On 19/02/16 15:08, Balbir Singh wrote:


On 19/02/16 12:55, Rashmica Gupta wrote:

Currently on PPC64 changing kernel pagesize from 4K to 64K leaves
FORCE_MAX_ZONEORDER set to 13 - which produces a compile error.

The error occurs because of the following constraint (from
include/linux/mmzone.h) being violated:

MAX_ORDER -1 + PAGESHIFT <= SECTION_SIZE_BITS.

IA64 has this cool hack

   12 #ifdef CONFIG_FORCE_MAX_ZONEORDER
   13 #if ((CONFIG_FORCE_MAX_ZONEORDER - 1 + PAGE_SHIFT) > 
SECTION_SIZE_BITS)
   14 #undef SECTION_SIZE_BITS
   15 #define SECTION_SIZE_BITS (CONFIG_FORCE_MAX_ZONEORDER - 1 + 
PAGE_SHIFT)
   16 #endif

But coming back (we can revisit the SECTION_SIZE_BITS definition later)
I feel like someone more senior than me should weigh in on if this is 
worth doing...



MAX_ORDER -1 + 16 <= 24 for 64 K

and

MAX_ORDER -1 + 12 < = 24 for 4K

Your calculations are correct

Expanding this out, we get:

FORCE_MAX_ZONEBITS <= 25 - PAGESHIFT,

which requires, for a 64K page, FORCE_MAX_ZONEBITS <= 9. Thus
set max value of FORCE_MAX_ZONEORDER for 64K pages to 9.

Also, check the minimum value:
In include/linux/huge_mm.h, we have the constraint HPAGE_PMD_ORDER <
MAX_ORDER which expands out to:

PTE_INDEX_SIZE < FORCE_MAX_ZONEORDER.
PTE_INDEX_SIZE is:
9 (4k hash or no hash 4K pgtable) or
8 (64K hash or no hash 64K pgtable).
Thus a min value of 9 for 64K pages is reasonable.

For 4K pages we end up with

9 < FORCE_MAX_ZONE_ORDER
FORCE_MAX_ZONE_ORDER -1 + 12 < = 24

The range is 9 to 13

For 64K we end up with
8 < FORCE_MAX_ZONE_ORDER
FORCE_MAX_ZONE_ORDER -1 + 16 <= 24 or FORCE_MAX_ZONE_ORDER <= 9

The range is really between 8 and 9 unless we tweak the SECTION_SIZE_BITS

Yup, you are right! Might have had a brain spaz...

So, update the range of FORCE_MAX_ZONEORDER from 9-64 to 9-9.

Signed-off-by: Rashmica Gupta 
---
  arch/powerpc/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e4824fd04bb7..3bd3465b93ba 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -585,7 +585,7 @@ endchoice
  
  config FORCE_MAX_ZONEORDER

int "Maximum zone order"
-   range 9 64 if PPC64 && PPC_64K_PAGES
+   range 9 9 if PPC64 && PPC_64K_PAGES

range 8 9?

Agreed.

default "9" if PPC64 && PPC_64K_PAGES
range 13 64 if PPC64 && !PPC_64K_PAGES

Should this be fixed as well?
range 9 13?

Agreed.

default "13" if PPC64 && !PPC_64K_PAGES
Should the default values remain as is, or follow the trend and be equal 
to the minimum value?

Please check my calculations

Reviewed-by: Balbir Singh 

Balbir Singh


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc/Kconfig: Update config option based on page size.

2016-02-18 Thread Rashmica Gupta
Currently on PPC64 changing kernel pagesize from 4K to 64K leaves
FORCE_MAX_ZONEORDER set to 13 - which produces a compile error.

The error occurs because of the following constraint (from
include/linux/mmzone.h) being violated:

MAX_ORDER -1 + PAGESHIFT <= SECTION_SIZE_BITS.

Expanding this out, we get:

FORCE_MAX_ZONEBITS <= 25 - PAGESHIFT,

which requires, for a 64K page, FORCE_MAX_ZONEBITS <= 9. Thus
set max value of FORCE_MAX_ZONEORDER for 64K pages to 9.

Also, check the minimum value:
In include/linux/huge_mm.h, we have the constraint HPAGE_PMD_ORDER <
MAX_ORDER which expands out to:

PTE_INDEX_SIZE < FORCE_MAX_ZONEORDER.

PTE_INDEX_SIZE is:
9 (4k hash or no hash 4K pgtable) or
8 (64K hash or no hash 64K pgtable).
Thus a min value of 9 for 64K pages is reasonable.

So, update the range of FORCE_MAX_ZONEORDER from 9-64 to 9-9.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e4824fd04bb7..3bd3465b93ba 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -585,7 +585,7 @@ endchoice
 
 config FORCE_MAX_ZONEORDER
int "Maximum zone order"
-   range 9 64 if PPC64 && PPC_64K_PAGES
+   range 9 9 if PPC64 && PPC_64K_PAGES
default "9" if PPC64 && PPC_64K_PAGES
range 13 64 if PPC64 && !PPC_64K_PAGES
default "13" if PPC64 && !PPC_64K_PAGES
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 5/5] selftests/powerpc: Add test to check if TM SPRs are corrupted

2015-12-22 Thread Rashmica Gupta
Testing that the TM SPRs are behaving the way they should. Uses more
threads than cpus to see if the following register values persist with
context switching:
- the FS (failure summary) flag in TEXASR
- TFIAR and TFHAR

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/.gitignore |   1 +
 tools/testing/selftests/powerpc/tm/Makefile   |   3 +-
 tools/testing/selftests/powerpc/tm/tm-tmspr.c | 143 ++
 3 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tmspr.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 2ac376410c70..bb942db845bf 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -5,3 +5,4 @@ tm-signal-stack
 tm-vmxcopy
 tm-fork
 tm-tar
+tm-tmspr
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index cb4b3bf57a4d..d0505dbd22d5 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy tm-fork tm-tar
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy tm-fork tm-tar tm-tmspr
 
 all: $(TEST_PROGS)
 
@@ -6,6 +6,7 @@ $(TEST_PROGS): ../harness.c ../utils.c
 
 tm-syscall: tm-syscall-asm.S
 tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
+tm-tmspr: CFLAGS += -pthread
 
 include ../../lib.mk
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tmspr.c 
b/tools/testing/selftests/powerpc/tm/tm-tmspr.c
new file mode 100644
index ..2bda81c7bf23
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tmspr.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Original: Michael Neuling 3/4/2014
+ * Modified: Rashmica Gupta 8/12/2015
+ *
+ * Check if any of the Transaction Memory SPRs get corrupted.
+ * - TFIAR  - stores address of location of transaction failure
+ * - TFHAR  - stores address of software failure handler (if transaction
+ *   fails)
+ * - TEXASR - lots of info about the transacion(s)
+ *
+ * (1) create more threads than cpus
+ * (2) in each thread:
+ * (a) set TFIAR and TFHAR a unique value
+ * (b) loop for awhile, continually checking to see if
+ * either register has been corrupted.
+ *
+ * (3) Loop:
+ * (a) begin transaction
+ * (b) abort transaction
+ * (c) check TEXASR to see if FS has been corrupted
+ *
+ */
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "utils.h"
+#include "tm.h"
+
+intnum_loops   = 1;
+intpassed = 1;
+
+void tfiar_tfhar(void *in)
+{
+   int i, cpu;
+   unsigned long tfhar, tfhar_rd, tfiar, tfiar_rd;
+   cpu_set_t cpuset;
+
+   CPU_ZERO(&cpuset);
+   cpu = (unsigned long)in >> 1;
+   CPU_SET(cpu, &cpuset);
+   sched_setaffinity(0, sizeof(cpuset), &cpuset);
+
+   /* TFIAR: Last bit has to be high so userspace can read register */
+   tfiar = ((unsigned long)in) + 1;
+   tfiar += 2;
+   mtspr(SPRN_TFIAR, tfiar);
+
+   /* TFHAR: Last two bits are reserved */
+   tfhar = ((unsigned long)in);
+   tfhar &= ~0x3UL;
+   tfhar += 4;
+   mtspr(SPRN_TFHAR, tfhar);
+
+   for (i = 0; i < num_loops; i++) {
+   tfhar_rd = mfspr(SPRN_TFHAR);
+   tfiar_rd = mfspr(SPRN_TFIAR);
+   if ( (tfhar != tfhar_rd) || (tfiar != tfiar_rd) ) {
+   passed = 0;
+   return;
+   }
+   }
+   return;
+}
+
+void texasr(void *in)
+{
+   unsigned long i;
+   uint64_t result = 0;
+
+   for (i = 0; i < num_loops; i++) {
+   asm __volatile__(
+   "tbegin.;"
+   "beq3f ;"
+   "tabort. 0 ;"
+   "tend.;"
+
+   /* Abort handler */
+   "3: ;"
+   ::: "memory");
+
+/* Check the TEXASR */
+result = mfspr(SPRN_TEXASR);
+   if ((result & TEXASR_FS) == 0) {
+   passed = 0;
+   return;
+   }
+   }
+   return;
+}
+
+int test_tmspr()
+{
+   pthread_t   thread;
+   int thread_num;
+   unsigned long   i;
+
+   SKIP_IF(!have_htm());
+
+   /* To cause some context switching */
+   thread_num = 10 * sysconf(_SC_NPROCESSORS_ONLN);
+
+   /* Test TFIAR and TFHAR */
+   for (i = 0 ; i < thread_num ; i += 2){
+   if (pthread_create(&thread, NULL, (void*)tfiar_tfhar, (void 
*)i))
+   return EXIT

[PATCH 4/5] selftests/powerpc: Add TM test to check if TAR is corrupted

2015-12-22 Thread Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the
checkpointed value before the transaction began. The value written to the
TAR when the transaction is suspended should only remain there if the
transaction completes successfully.

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-tar.c   | 90 +++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index d216eddcd493..2ac376410c70 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -4,3 +4,4 @@ tm-signal-msr-resv
 tm-signal-stack
 tm-vmxcopy
 tm-fork
+tm-tar
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 2db475b12720..cb4b3bf57a4d 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy tm-fork
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy tm-fork tm-tar
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tar.c 
b/tools/testing/selftests/powerpc/tm/tm-tar.c
new file mode 100644
index ..2d2fcc2b7a60
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tar.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the tar is corrupted.
+ * If the transaction is aborted, the TAR should be rolled back to the
+ * checkpointed value before the transaction began. The value written to
+ * TAR in suspended mode should only remain in TAR if the transaction
+ * completes.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+intnum_loops   = 1;
+
+int test_tar(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[tar], 7;" /* tar = 1 */
+   "tbegin.;"
+   "beq3f;"
+   "li 4, 0x7000;" /* Loop lots, to use time */
+   "2:;"   /* Start loop */
+   "li 7, 2;"
+   "mtspr  %[tar], 7;" /* tar = 2 */
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[tar], 7;" /* tar = 3 */
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   /* Transaction sucess! TAR should be 3 */
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 4;"  // res = 3|4 = 7
+   "b  4f;"
+
+   /* Abort handler. TAR should be rolled back to 1 */
+   "3:;"
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 8;"  // res = 1|8 = 9
+   "4:;"
+
+   : [res]"=r"(result)
+   : [tar]"i"(SPRN_TAR)
+  : "memory", "r0", "r4", "r7");
+
+   /* If result is anything else other than 7 or 9, the tar
+* value must have been corrupted. */
+   if ((result != 7) && (result != 9))
+   return 1;
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   /* A low number of iterations (eg 100) can cause a false pass */
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 1;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   return test_harness(test_tar, "tm_tar");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 3/5] selftests/powerpc: Add test for forking inside transaction

2015-12-22 Thread Rashmica Gupta
This test does a fork syscall inside a transaction. Basic sniff test to see
if we can enter the kernel during a transaction.

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c  | 42 +++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 7d0f14b8cb2e..d216eddcd493 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -3,3 +3,4 @@ tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
 tm-vmxcopy
+tm-fork
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 737f72c964e6..2db475b12720 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy tm-fork
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-fork.c 
b/tools/testing/selftests/powerpc/tm/tm-fork.c
new file mode 100644
index ..8d48579b7778
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-fork.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Edited: Rashmica Gupta, Nov 2015
+ *
+ * This test does a fork syscall inside a transaction. Basic sniff test
+ * to see if we can enter the kernel during a transaction.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "utils.h"
+#include "tm.h"
+
+int test_fork(void)
+{
+   SKIP_IF(!have_htm());
+
+   asm __volatile__(
+   "tbegin.;"
+   "blt1f; "
+   "li 0, 2;"  /* fork syscall */
+   "sc  ;"
+   "tend.;"
+   "1: ;"
+   : : : "memory", "r0");
+   /* If we reach here, we've passed.  Otherwise we've probably crashed
+* the kernel */
+
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   return test_harness(test_fork, "tm_fork");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/5] selftests/powerpc: Standardise TM calls

2015-12-22 Thread Rashmica Gupta
Currently tbegin, tend etc are written as opcodes or asm instructions. So
standardise these to asm instructions.

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/tm-resched-dscr.c | 16 +---
 tools/testing/selftests/powerpc/tm/tm-signal-stack.c |  4 ++--
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c 
b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
index 8fde93d6021f..d9c49f41515e 100644
--- a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
+++ b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
@@ -31,12 +31,6 @@
 #include "utils.h"
 #include "tm.h"
 
-#define TBEGIN  ".long 0x7C00051D ;"
-#define TEND".long 0x7C00055D ;"
-#define TCHECK  ".long 0x7C00059C ;"
-#define TSUSPEND".long 0x7C0005DD ;"
-#define TRESUME ".long 0x7C2005DD ;"
-#define SPRN_TEXASR 0x82
 #define SPRN_DSCR   0x03
 
 int test_body(void)
@@ -55,13 +49,13 @@ int test_body(void)
"mtspr   %[sprn_dscr], 3;"
 
/* start and suspend a transaction */
-   TBEGIN
+   "tbegin.;"
"beq 1f;"
-   TSUSPEND
+   "tsuspend.;"
 
/* hard loop until the transaction becomes doomed */
"2: ;"
-   TCHECK
+   "tcheck 0;"
"bc  4, 0, 2b;"
 
/* record DSCR and TEXASR */
@@ -70,8 +64,8 @@ int test_body(void)
"mfspr   3, %[sprn_texasr];"
"std 3, %[texasr];"
 
-   TRESUME
-   TEND
+   "tresume.;"
+   "tend.;"
"li  %[rv], 0;"
"1: ;"
: [rv]"=r"(rv), [dscr2]"=m"(dscr2), [texasr]"=m"(texasr)
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c 
b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
index e44a238c1d77..1f0eb567438d 100644
--- a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
@@ -60,9 +60,9 @@ int tm_signal_stack()
exit(1);
asm volatile("li 1, 0 ;"/* stack ptr == NULL */
 "1:"
-".long 0x7C00051D ;"   /* tbegin */
+"tbegin.;"
 "beq 1b ;" /* retry forever */
-".long 0x7C0005DD ; ;" /* tsuspend */
+"tsuspend.;"
 "ld 2, 0(1) ;" /* trigger segv" */
 : : : "memory");
 
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/5] selftests/powerpc: Make reg.h common to all powerpc selftests

2015-12-22 Thread Rashmica Gupta
Currently there is a reg.h in pmu/ebb that has defines that are useful in
other powerpc selftests so move this up into selftests/powerpc folder. Also
include in utils.h - as this is often used in self tests. Add in some other
useful register defines.
---
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c  |  1 -
 tools/testing/selftests/powerpc/pmu/ebb/reg.h  | 49 --
 .../selftests/powerpc/pmu/ebb/reg_access_test.c|  1 -
 tools/testing/selftests/powerpc/reg.h  | 43 +++
 tools/testing/selftests/powerpc/utils.h|  1 +
 5 files changed, 44 insertions(+), 51 deletions(-)
 delete mode 100644 tools/testing/selftests/powerpc/pmu/ebb/reg.h
 create mode 100644 tools/testing/selftests/powerpc/reg.h

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c 
b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
index e67452f1bcff..46681fec549b 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
+++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
@@ -15,7 +15,6 @@
 #include 
 
 #include "trace.h"
-#include "reg.h"
 #include "ebb.h"
 
 
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/reg.h 
b/tools/testing/selftests/powerpc/pmu/ebb/reg.h
deleted file mode 100644
index 5921b0dfe2e9..
--- a/tools/testing/selftests/powerpc/pmu/ebb/reg.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2014, Michael Ellerman, IBM Corp.
- * Licensed under GPLv2.
- */
-
-#ifndef _SELFTESTS_POWERPC_REG_H
-#define _SELFTESTS_POWERPC_REG_H
-
-#define __stringify_1(x)#x
-#define __stringify(x)  __stringify_1(x)
-
-#define mfspr(rn)   ({unsigned long rval; \
- asm volatile("mfspr %0," __stringify(rn) \
- : "=r" (rval)); rval; })
-#define mtspr(rn, v)asm volatile("mtspr " __stringify(rn) ",%0" : \
-: "r" ((unsigned long)(v)) \
-: "memory")
-
-#define mb()   asm volatile("sync" : : : "memory");
-
-#define SPRN_MMCR2 769
-#define SPRN_MMCRA 770
-#define SPRN_MMCR0 779
-#define   MMCR0_PMAO   0x0080
-#define   MMCR0_PMAE   0x0400
-#define   MMCR0_FC 0x8000
-#define SPRN_EBBHR 804
-#define SPRN_EBBRR 805
-#define SPRN_BESCR 806 /* Branch event status & control register */
-#define SPRN_BESCRS800 /* Branch event status & control set (1 bits 
set to 1) */
-#define SPRN_BESCRSU   801 /* Branch event status & control set upper */
-#define SPRN_BESCRR802 /* Branch event status & control REset (1 bits 
set to 0) */
-#define SPRN_BESCRRU   803 /* Branch event status & control REset upper */
-
-#define BESCR_PMEO 0x1 /* PMU Event-based exception Occurred */
-#define BESCR_PME  (0x1ul << 32) /* PMU Event-based exception Enable */
-
-#define SPRN_PMC1  771
-#define SPRN_PMC2  772
-#define SPRN_PMC3  773
-#define SPRN_PMC4  774
-#define SPRN_PMC5  775
-#define SPRN_PMC6  776
-
-#define SPRN_SIAR  780
-#define SPRN_SDAR  781
-#define SPRN_SIER  768
-
-#endif /* _SELFTESTS_POWERPC_REG_H */
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/reg_access_test.c 
b/tools/testing/selftests/powerpc/pmu/ebb/reg_access_test.c
index 5b1188f10c15..f923228bca22 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/reg_access_test.c
+++ b/tools/testing/selftests/powerpc/pmu/ebb/reg_access_test.c
@@ -7,7 +7,6 @@
 #include 
 
 #include "ebb.h"
-#include "reg.h"
 
 
 /*
diff --git a/tools/testing/selftests/powerpc/reg.h 
b/tools/testing/selftests/powerpc/reg.h
new file mode 100644
index ..1dacd8916a86
--- /dev/null
+++ b/tools/testing/selftests/powerpc/reg.h
@@ -0,0 +1,43 @@
+#define mfspr(rn)   ({unsigned long rval; \
+   asm volatile("mfspr %0," _str(rn) \
+   : "=r" (rval)); rval; })
+#define mtspr(rn, v)asm volatile("mtspr " _str(rn) ",%0" : \
+   : "r" ((unsigned long)(v)) \
+   : "memory")
+
+#define mb()asm volatile("sync" : : : "memory");
+
+#define SPRN_MMCR2 769
+#define SPRN_MMCRA 770
+#define SPRN_MMCR0 779
+#define   MMCR0_PMAO   0x0080
+#define   MMCR0_PMAE   0x0400
+#define   MMCR0_FC 0x8000
+#define SPRN_EBBHR 804
+#define SPRN_EBBRR 805
+#define SPRN_BESCR 806 /* Branch event status & control register */
+#define SPRN_BESCRS800 /* Branch event status & control set (1 bits 
set to 1) */
+#define SPRN_BESCRSU   801 /* Branch event status & control set upper */
+#define SPRN_BESCRR802 /* Branch event status & control REset (1 bits 
set to 0) */
+#define SPRN_BESCRRU   803 /* Branch event status & control REset upper */
+
+#define BESCR_PMEO 0x1 /* PMU Event-based exception Occurred */
+#define BESCR_PME  (0x1ul << 32) /* PMU Event-based exception Enable */
+
+#define SPRN_PMC1  771

[PATCH 0/5] Rebase powerpc selftests

2015-12-22 Thread Rashmica Gupta
Rebase the previous powerpc selftests against the current next tree.

Rashmica Gupta (5):
  selftests/powerpc: Make reg.h common to all powerpc selftests
  selftests/powerpc: Standardise TM calls
  selftests/powerpc: Add test for forking inside transaction
  selftests/powerpc: Add TM test to check if TAR is corrupted
  selftests/powerpc: Add test to check if TM SPRs are corrupted

 tools/testing/selftests/powerpc/pmu/ebb/ebb.c  |   1 -
 tools/testing/selftests/powerpc/pmu/ebb/reg.h  |  49 ---
 .../selftests/powerpc/pmu/ebb/reg_access_test.c|   1 -
 tools/testing/selftests/powerpc/reg.h  |  43 +++
 tools/testing/selftests/powerpc/tm/.gitignore  |   3 +
 tools/testing/selftests/powerpc/tm/Makefile|   3 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c   |  42 ++
 .../testing/selftests/powerpc/tm/tm-resched-dscr.c |  16 +--
 .../testing/selftests/powerpc/tm/tm-signal-stack.c |   4 +-
 tools/testing/selftests/powerpc/tm/tm-tar.c|  90 +
 tools/testing/selftests/powerpc/tm/tm-tmspr.c  | 143 +
 tools/testing/selftests/powerpc/utils.h|   1 +
 12 files changed, 331 insertions(+), 65 deletions(-)
 delete mode 100644 tools/testing/selftests/powerpc/pmu/ebb/reg.h
 create mode 100644 tools/testing/selftests/powerpc/reg.h
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tmspr.c

-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] selftests/powerpc: Add test to check if TM SPRs are corrupted

2015-12-15 Thread Rashmica Gupta
Just testing that things are behaving the way they should. Uses more
threads than cpus to see if the following values persist with context
switching:
- the FS (failure summary) flag in TEXASR
- TFIAR and TFHAR

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/.gitignore |   1 +
 tools/testing/selftests/powerpc/tm/Makefile   |   6 +-
 tools/testing/selftests/powerpc/tm/tm-tmspr.c | 154 ++
 3 files changed, 159 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tmspr.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index c4667790d01d..42a6467afe93 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -3,3 +3,4 @@ tm-syscall
 tm-signal-msr-resv
 tm-signal-stack 
 tm-vmxcopy
+tm-tmspr
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index d013447fb6d9..21435399e8e9 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,11 +1,13 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-vmxcopy tm-tmspr
 
 all: $(TEST_PROGS)
 
 $(TEST_PROGS): ../harness.c ../utils.c
 
 tm-syscall: tm-syscall-asm.S
-   tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
+tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
+
+tm-tmspr: CFLAGS += -pthread
 
 include ../../lib.mk
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tmspr.c 
b/tools/testing/selftests/powerpc/tm/tm-tmspr.c
new file mode 100644
index ..6b317b8d7067
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tmspr.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Original: Michael Neuling 3/4/2014
+ * Modified: Rashmica Gupta 8/12/2015
+ *
+ * Check if any of the Transaction Memory SPRs get corrupted.
+ * - TFIAR  - stores address of location of transaction failure
+ * - TFHAR  - stores address of software failure handler (if transaction
+ *   fails)
+ * - TEXASR - lots of info about the transacion(s)
+ *
+ * (1) create more threads than cpus
+ * (2) in each thread:
+ * (a) set TFIAR and TFHAR a unique value
+ * (b) loop for awhile, continually checking to see if
+ * either register has been corrupted.
+ *
+ * (3) Loop:
+ * (a) begin transaction
+ * (b) abort transaction
+ * (c) check TEXASR to see if FS has been corrupted
+ *
+ */
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "utils.h"
+
+
+#define __stringify_1(x)   #x
+#define __stringify(x) __stringify_1(x)
+#define mfspr(rn)  ({unsigned long rval; \
+   asm volatile("mfspr %0," __stringify(rn) \
+   : "=r" (rval)); rval; })
+#define mtspr(rn, v)   asm volatile("mtspr " __stringify(rn) ",%0" : \
+: "r" ((unsigned long)(v)) \
+: "memory")
+#define SPRN_TEXASR 0x82
+#define TEXASR_FS   0x0800
+#define SPRN_TFIAR 0x81/* Transaction Failure Inst Addr*/
+#define SPRN_TFHAR 0x80/* Transaction Failure Handler Addr */
+
+intnum_loops   = 1;
+intpassed = 1;
+
+void tfiar_tfhar(void *in)
+{
+   int i, cpu;
+   unsigned long tfhar, tfhar_rd, tfiar, tfiar_rd;
+   cpu_set_t cpuset;
+
+   CPU_ZERO(&cpuset);
+   cpu = (unsigned long)in >> 1;
+   CPU_SET(cpu, &cpuset);
+   sched_setaffinity(0, sizeof(cpuset), &cpuset);
+
+   /* TFIAR: Last bit has to be high so userspace can read register */
+   tfiar = ((unsigned long)in) + 1;
+   tfiar += 2;
+   mtspr(SPRN_TFIAR, tfiar);
+
+   /* TFHAR: Last two bits are reserved */
+   tfhar = ((unsigned long)in);
+   tfhar &= ~0x3UL;
+   tfhar += 4;
+   mtspr(SPRN_TFHAR, tfhar);
+
+   for (i = 0; i < num_loops; i++) {
+   tfhar_rd = mfspr(SPRN_TFHAR);
+   tfiar_rd = mfspr(SPRN_TFIAR);
+   if ( (tfhar != tfhar_rd) || (tfiar != tfiar_rd) ) {
+   passed = 0;
+   return;
+   }
+   }
+   return;
+}
+
+void texasr(void *in)
+{
+   unsigned long i;
+   uint64_t result = 0;
+
+   for (i = 0; i < num_loops; i++) {
+   asm __volatile__(
+   "tbegin.;"
+   "beq3f ;"
+   "tabort. 0 ;"
+   "tend.;"
+
+   /* Abort handler */
+   "3: ;"
+   

[PATCH] selftests/powerpc: Add test to check if VSRs are corrupted

2015-12-08 Thread Rashmica Gupta
When a transaction is aborted, VSR values should rollback to the
checkpointed values before the transaction began. VSRs used elsewhere in
the kernel during a transaction, or while the transaction is suspended
should not affect the checkpointed values.

Signed-off-by: Rashmica Gupta 
---

Prior to the bug fix in "powerpc: Don't corrupt transactional state when
using FP/VMX in kernel", when VMX was requested by the kernel the .vr_state
(which held the checkpointed state of VSRs before the transaction) was
overwritten with the current state from outside the transation. Thus if the
transaction did not complete, the VSR values would be "rolled back" to
potentially incorrect values.

 tools/testing/selftests/powerpc/tm/.gitignore   |   1 +
 tools/testing/selftests/powerpc/tm/Makefile |   2 +-
 tools/testing/selftests/powerpc/tm/tm-vmxcopy.c | 104 
 3 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-vmxcopy.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 9bf6749550e3..b86c94ea462d 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -5,3 +5,4 @@ tm-signal-stack
 tm-fork
 tm-dscr
 tm-tar
+tm-vmxcopy
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index cd3d42a15601..fc9a5ed1aba2 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork tm-dscr 
tm-tar tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork tm-dscr 
tm-tar tm-vmxcopy tm-signal-stack
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-vmxcopy.c 
b/tools/testing/selftests/powerpc/tm/tm-vmxcopy.c
new file mode 100644
index ..288c9c3d0776
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-vmxcopy.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Original: Michael Neuling 4/12/2013
+ * Edited: Rashmica Gupta 4/12/2015
+ *
+ * See if the altivec state is leaked out of an aborted transaction due to
+ * kernel vmx copy loops.
+ *
+ * When the transaction aborts, VSR values should rollback to the values
+ * they held before the transaction commenced. Using VSRs while transaction
+ * is suspended should not affect the checkpointed values.
+ *
+ * (1) write A to a VSR
+ * (2) start transaction
+ * (3) suspend transaction
+ * (4) change the VSR to B
+ * (5) trigger kernel vmx copy loop
+ * (6) abort transaction
+ * (7) check that the VSR value is A
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+int test_vmxcopy()
+{
+   long double vecin = 1.3;
+   long double vecout;
+   unsigned long pgsize = getpagesize();
+   int i;
+   int fd;
+   int size = pgsize*16;
+   char tmpfile[] = "/tmp/page_faultXX";
+   char buf[pgsize];
+   char *a;
+   uint64_t aborted = 0;
+
+   SKIP_IF(!have_htm());
+
+   fd = mkstemp(tmpfile);
+   assert(fd >= 0);
+
+   memset(buf, 0, pgsize);
+   for (i = 0; i < size; i += pgsize)
+   assert(write(fd, buf, pgsize) == pgsize);
+
+   unlink(tmpfile);
+
+   a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+   assert(a != MAP_FAILED);
+
+   asm __volatile__(
+   "lxvd2x 40,0,%[vecinptr];"  /* set 40 to initial value*/
+   "tbegin.;"
+   "beq3f;"
+   "tsuspend.;"
+   "xxlxor 40,40,40;"  /* set 40 to 0 */
+   "std5, 0(%[map]);"  /* cause kernel vmx copy page */
+   "tabort. 0;"
+   "tresume.;"
+   "tend.;"
+   "li %[res], 0;"
+   "b  5f;"
+
+   /* Abort handler */
+   "3:;"
+   "li %[res], 1;"
+
+   "5:;"
+   "stxvd2x 40,0,%[vecoutptr];"
+   : [res]"=r"(aborted)
+   : [vecinptr]"r"(&vecin),
+ [vecoutptr]"r"(&vecout),
+ [map]"r"(a)
+   : "memory", "r0", "r3", "r4", "r5", "r6", "r7");
+
+   if (aborted && (vecin != vecout)){
+   printf("FAILED: vector state leaked on abort %f != %f\n",
+  (double)vecin, (double)vecout);
+   return 1;
+   }
+
+   munmap(a, size);
+
+   close(fd);
+
+   return 0;
+}
+
+
+int main(int argc, char *argv[]){
+
+   return test_harness(test_vmxcopy, "tm_vmxcopy");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v4] selftests/powerpc: Add test to check if TAR is corrupted

2015-12-02 Thread Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the
checkpointed value before the transaction began. The value written to the
TAR when the transaction is suspended should only remain there if the
transaction completes successfully.

Signed-off-by: Rashmica Gupta 
---

This must be run before tm-signal-stack as after this test is run a reboot
is required -- changed the order of the tests in the Makefile.

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-tar.c   | 92 +++
 3 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 76eae258feeb..9bf6749550e3 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -4,3 +4,4 @@ tm-signal-msr-resv
 tm-signal-stack
 tm-fork
 tm-dscr
+tm-tar
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index dc368f789afa..cd3d42a15601 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork tm-dscr 
tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork tm-dscr 
tm-tar tm-signal-stack
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tar.c 
b/tools/testing/selftests/powerpc/tm/tm-tar.c
new file mode 100644
index ..41873b5cb3b8
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tar.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the tar is corrupted.
+ * If the transaction is aborted, the TAR should be rolled back to the
+ * checkpointed value before the transaction began. The value written to
+ * TAR in suspended mode should only remain in TAR if the transaction
+ * completes.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_TAR   0x32f
+
+intnum_loops   = 1;
+
+int test_tar(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[tar], 7;" /* tar = 1 */
+   "tbegin.;"
+   "beq3f;"
+   "li 4, 0x7000;" /* Loop lots, to use time */
+   "2:;"   /* Start loop */
+   "li 7, 2;"
+   "mtspr  %[tar], 7;" /* tar = 2 */
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[tar], 7;" /* tar = 3 */
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   /* Transaction sucess! TAR should be 3 */
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 4;"  // res = 3|4 = 7
+   "b  4f;"
+
+   /* Abort handler. TAR should be rolled back to 1 */
+   "3:;"
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 8;"  // res = 1|8 = 9
+   "4:;"
+
+   : [res]"=r"(result)
+   : [tar]"i"(SPRN_TAR)
+  : "memory", "r0", "r4", "r7");
+
+   /* If result is anything else other than 7 or 9, the tar
+* value must have been corrupted. */
+   if ((result != 7) && (result != 9))
+   return 1;
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   /* A low number of iterations (eg 100) can cause a false pass */
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 1;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   return test_harness(test_tar, "tm_tar");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v3] selftests/powerpc: Add test to check is DSCR is corrupted.

2015-12-02 Thread Rashmica Gupta
If the transaction is aborted, the DSCR should be rolled back to the
checkpointed value before the transaction began. The value written to the
DSCR when transaction was suspended should only persist if the transaction
is successful.

Signed-off-by: Rashmica Gupta 
---

This must be run before tm-signal-stack as after this test is run a reboot
is required -- changed the order of the tests in the Makefile.

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-dscr.c  | 95 +++
 3 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-dscr.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index d0c7c97e9b13..76eae258feeb 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -3,3 +3,4 @@ tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
 tm-fork
+tm-dscr
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 56cbb3c839a1..dc368f789afa 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork 
tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork tm-dscr 
tm-signal-stack
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-dscr.c 
b/tools/testing/selftests/powerpc/tm/tm-dscr.c
new file mode 100644
index ..b4fc44945a4f
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-dscr.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the dscr is corrupted.
+ * If the transaction is aborted, the DSCR should be rolled back to the
+ * checkpointed value from before the transaction began. The value set to
+ * DSCR while the transaction was suspended should persist if the
+ * transaction succeeds.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_DSCR  0x3
+
+intnum_loops   = 1;
+
+int test_dscr(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[dscr], 7;"/* dscr = 1 */
+   "tbegin.;"
+   "beq3f;"
+   "li 4, 0x7000;" /* Loop lots, to use time */
+   "2:;"   /* Start loop */
+   "li 7, 2;"
+   "mtspr  %[dscr], 7;"/* dscr = 2 */
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[dscr], 7;"/* dscr = 3 */
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   /* Transaction sucess! DSCR should be 3 */
+   "mfspr  7, %[dscr];"
+   "ori%[res], 7, 4;"  /* res = 3|4 = 7 */
+   "b  4f;"
+
+   /* Abort handler.DSCR should be rolled back to 1 */
+   "3:;"
+   "mfspr  7, %[dscr];"
+   "ori%[res], 7, 8;"  /* res = 1|8 = 9 */
+   "4:;"
+
+   : [res]"=r"(result)
+   : [dscr]"i"(SPRN_DSCR)
+   : "memory", "r0", "r4", "r7");
+
+   /* If result is anything else other than 7 or 9, the dscr
+* value must have been corrupted. */
+   if ((result != 7) && (result != 9))
+   return 1;
+
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+
+   /* A low number of iterations (eg 100) can cause a false pass. */
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 1;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   return test_harness(test_dscr, "tm_dscr");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v3] selftests/powerpc: Add test for forking inside transaction

2015-12-02 Thread Rashmica Gupta
This test does a fork syscall inside a transaction. Basic sniff test to see
if we can enter the kernel during a transaction.

Signed-off-by: Rashmica Gupta 
---
This must be run before tm-signal-stack as after this test is run a reboot
is required -- changed the order of the tests in the Makefile.

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c  | 42 +++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index e6668217ccd0..d0c7c97e9b13 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -2,3 +2,4 @@ tm-resched-dscr
 tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
+tm-fork
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 578572a3700a..56cbb3c839a1 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-fork 
tm-signal-stack
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-fork.c 
b/tools/testing/selftests/powerpc/tm/tm-fork.c
new file mode 100644
index ..8d48579b7778
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-fork.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Edited: Rashmica Gupta, Nov 2015
+ *
+ * This test does a fork syscall inside a transaction. Basic sniff test
+ * to see if we can enter the kernel during a transaction.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "utils.h"
+#include "tm.h"
+
+int test_fork(void)
+{
+   SKIP_IF(!have_htm());
+
+   asm __volatile__(
+   "tbegin.;"
+   "blt1f; "
+   "li 0, 2;"  /* fork syscall */
+   "sc  ;"
+   "tend.;"
+   "1: ;"
+   : : : "memory", "r0");
+   /* If we reach here, we've passed.  Otherwise we've probably crashed
+* the kernel */
+
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   return test_harness(test_fork, "tm_fork");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v2] selftests/powerpc: Add test for forking inside transaction

2015-12-01 Thread Rashmica Gupta
This test does a fork syscall inside a transaction. Basic sniff test to see
if we can enter the kernel during a transaction.

Signed-off-by: Rashmica Gupta 
---
Updated description. No functional changes.

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c  | 42 +++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index e6668217ccd0..d0c7c97e9b13 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -2,3 +2,4 @@ tm-resched-dscr
 tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
+tm-fork
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 578572a3700a..f7d4727662aa 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-fork.c 
b/tools/testing/selftests/powerpc/tm/tm-fork.c
new file mode 100644
index ..8d48579b7778
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-fork.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Edited: Rashmica Gupta, Nov 2015
+ *
+ * This test does a fork syscall inside a transaction. Basic sniff test
+ * to see if we can enter the kernel during a transaction.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "utils.h"
+#include "tm.h"
+
+int test_fork(void)
+{
+   SKIP_IF(!have_htm());
+
+   asm __volatile__(
+   "tbegin.;"
+   "blt1f; "
+   "li 0, 2;"  /* fork syscall */
+   "sc  ;"
+   "tend.;"
+   "1: ;"
+   : : : "memory", "r0");
+   /* If we reach here, we've passed.  Otherwise we've probably crashed
+* the kernel */
+
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   return test_harness(test_fork, "tm_fork");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v2] selftests/powerpc: Add test to check is DSCR is corrupted.

2015-12-01 Thread Rashmica Gupta
If the transaction is aborted, the DSCR should be rolled back to the
checkpointed value before the transaction began. The value written to the
DSCR when transaction was suspended should only persist if the transaction
is successful.

Signed-off-by: Rashmica Gupta 
---
No functional changes. Fixed whitespace and styling issues.

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-dscr.c  | 95 +++
 3 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-dscr.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index d0c7c97e9b13..76eae258feeb 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -3,3 +3,4 @@ tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
 tm-fork
+tm-dscr
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index f7d4727662aa..59eec240339d 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-dscr.c 
b/tools/testing/selftests/powerpc/tm/tm-dscr.c
new file mode 100644
index ..b18360895496
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-dscr.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the DSCR is corrupted.
+ * If the transaction is aborted, the DSCR should be rolled back to the
+ * checkpointed value before the transaction began. The value set to DSCR
+ * while the transaction was suspended should only remain there if the
+ * transaction succeeds.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_DSCR  0x3
+
+intnum_loops   = 1;
+
+int test_dscr(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[dscr], 7;"/* dscr = 1 */
+   "tbegin.;"
+   "beq3f ;"
+   "li 4, 0x7000;" /* Loop lots, to use time */
+   "2:;"   /* Start loop */
+   "li 7, 2;"
+   "mtspr  %[dscr], 7;"/* dscr = 2 */
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[dscr], 7;"/* dscr = 3 */
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   /* Transaction sucess! DSCR should be 3 */
+   "mfspr  7, %[dscr];"
+   "ori%[res], 7, 4;"  /* res = 3|4 = 7 */
+   "b  4f;"
+
+   /* Abort handler.DSCR should be rolled back to 1 */
+   "3:;"
+   "mfspr  7, %[dscr];"
+   "ori%[res], 7, 8;"  /* res = 1|8 = 9 */
+   "4:;"
+
+   : [res]"=r"(result)
+   : [dscr]"i"(SPRN_DSCR)
+   : "memory", "r0", "r4", "r7");
+
+   /* If result is anything else other than 7 or 9, the dscr
+   * value must have been corrupted. */
+   if ((result != 7) && (result != 9))
+   return 1;
+
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+
+   /* A low number of iterations (eg 100) can cause a false pass */
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 0;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   test_harness(test_dscr, "tm_dscr");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v3] selftests/powerpc: Add test to check if TAR is corrupted

2015-12-01 Thread Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the
checkpointed value before the transaction began. The value written to the
TAR when the transaction is suspended should only remain there if the
transaction completes successfully.

Signed-off-by: Rashmica Gupta 
---
Added more explanation and fixed up styling issue. No functional
changes.

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-tar.c   | 92 +++
 3 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 76eae258feeb..9bf6749550e3 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -4,3 +4,4 @@ tm-signal-msr-resv
 tm-signal-stack
 tm-fork
 tm-dscr
+tm-tar
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 59eec240339d..ab2992f69b4c 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr tm-tar
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tar.c 
b/tools/testing/selftests/powerpc/tm/tm-tar.c
new file mode 100644
index ..732f518c95cf
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tar.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the tar is corrupted.
+ * If the transaction is aborted, the TAR should be rolled back to the
+ * checkpointed value before the transaction began. The value written to
+ * TAR in suspended mode should only remain in TAR if the transaction
+ * completes.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_TAR   0x32f
+
+intnum_loops   = 1;
+
+int test_tar(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[tar], 7;" /* tar = 1 */
+   "tbegin.;"
+   "beq3f;"
+   "li 4, 0x7000;" /* Loop lots, to use time */
+   "2:;"   /* Start loop */
+   "li 7, 2;"
+   "mtspr  %[tar], 7;" /* tar = 2 */
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[tar], 7;" /* tar = 3 */
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   /* Transaction sucess! TAR should be 3 */
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 4;"  // res = 3|4 = 7
+   "b  4f;"
+
+   /* Abort handler. TAR should be rolled back to 1 */
+   "3:;"
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 8;"  // res = 1|8 = 9
+   "4:;"
+
+   : [res]"=r"(result)
+   : [tar]"i"(SPRN_TAR)
+  : "memory", "r0", "r4", "r7");
+
+   /* If result is anything else other than 7 or 9, the tar
+* value must have been corrupted. */
+   if ((result != 7) && (result != 9))
+   return 1;
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   /* A low number of iterations (eg 100) can cause a false pass */
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 0;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   test_harness(test_tar, "tm_tar");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v2] selftests/powerpc: Add test to check if TAR is corrupted

2015-12-01 Thread Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the
checkpointed value before the transaction began.

Signed-off-by: Rashmica Gupta 
---
Somehow had a missing brace and extra whitespace. 

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-tar.c   | 89 +++
 3 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 76eae258feeb..9bf6749550e3 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -4,3 +4,4 @@ tm-signal-msr-resv
 tm-signal-stack
 tm-fork
 tm-dscr
+tm-tar
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 59eec240339d..ab2992f69b4c 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr tm-tar
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tar.c 
b/tools/testing/selftests/powerpc/tm/tm-tar.c
new file mode 100644
index ..6b7713f007a0
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tar.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the tar is corrupted.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_TAR   0x32f
+
+intnum_loops   = 1;
+
+int test_tar(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[tar], 7;" // tar = 1
+   "tbegin.;"
+   "beq3f;"
+   "li 4, 0x7000;" // Loop lots, to use time
+   "2:;"   // Start loop
+   "li 7, 2;"
+   "mtspr  %[tar], 7;" // tar = 2
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[tar], 7;" // tar = 3
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   // Transaction sucess! TAR should be 3.
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 4;"  // res = 3|4 = 7
+   "b  4f;"
+
+   // Abort handler. TAR should be rolled back to 1.
+   "3:;"
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 8;"  // res = 1|8 = 9
+   "4:;"
+
+   : [res]"=r"(result)
+   : [tar]"i"(SPRN_TAR)
+  : "memory", "r0", "r4", "r7");
+
+   // If result is anything else other than 7 or 9, the tar
+   // value must have been corrupted.
+   if ((result != 7) && (result != 9))
+   return 1;
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   // A low number of iterations (eg 100) can cause a false pass.
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 0;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   test_harness(test_tar, "tm_tar");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] selftests/powerpc: Add test to check if TAR is corrupted

2015-12-01 Thread Rashmica Gupta
If the transaction is aborted, the TAR should be rolled back to the
checkpointed value before the transaction began.

Signed-off-by: Rashmica Gupta 
---
To check this yourself, undo the changes from the patch "powerpc/tm: Fix
context switching TAR, PPR and DSCR SPRs".

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-tar.c   | 90 +++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-tar.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index 76eae258feeb..9bf6749550e3 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -4,3 +4,4 @@ tm-signal-msr-resv
 tm-signal-stack
 tm-fork
 tm-dscr
+tm-tar
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 59eec240339d..ab2992f69b4c 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr tm-tar
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-tar.c 
b/tools/testing/selftests/powerpc/tm/tm-tar.c
new file mode 100644
index ..22a0c3485412
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-tar.c
@@ -0,0 +1,90 @@
+/* 
+ * Copyright 2015, Michael Neuling, IBM Corp. 
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the tar is corrupted.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_TAR   0x32f
+
+intnum_loops   = 1;
+
+int test_tar(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[tar], 7;" // tar = 1
+   "tbegin.;"  
+   "beq3f;"
+   "li 4, 0x7000;" // Loop lots, to use time
+   "2:;"   // Start loop
+   "li 7, 2;"
+   "mtspr  %[tar], 7;" // tar = 2
+   "tsuspend.;"
+   "li 7, 3;"
+   "mtspr  %[tar], 7;" // tar = 3
+   "tresume.;"
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   // Transaction sucess! TAR should be 3.
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 4;"  // res = 3|4 = 7
+   "b  4f;"
+
+   // Abort handler. TAR should be rolled back to 1.
+   "3:;"
+   "mfspr  7, %[tar];"
+   "ori%[res], 7, 8;"  // res = 1|8 = 9
+   "4:;"
+
+   : [res]"=r"(result)
+   : [tar]"i"(SPRN_TAR)
+  : "memory", "r0", "r4", "r7");
+
+   // If result is anything else other than 7 or 9, the tar
+   // value must have been corrupted.
+   if ((result != 7) && (result != 9)) 
+   return 1;
+   
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+
+   // A low number of iterations (eg 100) can cause a false pass.
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 0;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   test_harness(test_tar, "tm_tar");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] selftests/powerpc: Add test to check is DSCR is corrupted.

2015-12-01 Thread Rashmica Gupta
If the transaction is aborted, the DSCR should be rolled back to the
checkpointed value before the transaction began.

Signed-off-by: Rashmica Gupta 
---
To check this yourself, undo the changes from the patch "powerpc/tm: Fix
context switching TAR, PPR and DSCR SPRs".

 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-dscr.c  | 91 +++
 3 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-dscr.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index d0c7c97e9b13..76eae258feeb 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -3,3 +3,4 @@ tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
 tm-fork
+tm-dscr
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index f7d4727662aa..59eec240339d 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork tm-dscr
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-dscr.c 
b/tools/testing/selftests/powerpc/tm/tm-dscr.c
new file mode 100644
index ..ac44e259c86d
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-dscr.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp. 
+ * Licensed under GPLv2.
+ * Original: Michael Neuling 19/7/2013
+ * Edited: Rashmica Gupta 01/12/2015
+ *
+ * Do some transactions, see if the dscr is corrupted. 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tm.h"
+#include "utils.h"
+
+#define SPRN_DSCR  0x3
+
+intnum_loops   = 1;
+
+int test_dscr(void)
+{
+   int i;
+
+   SKIP_IF(!have_htm());
+
+   for (i = 0; i < num_loops; i++)
+   {
+   uint64_t result = 0;
+   asm __volatile__(
+   "li 7, 1;"
+   "mtspr  %[dscr], 7;"// dscr = 1
+   "tbegin.;"
+   "beq3f ;"
+   "li 4, 0x7000;" // Loop lots, to use time
+   "2: ;"  // Start loop
+   "li 7, 2;"
+   "mtspr  %[dscr], 7;"// dscr = 2
+   "tsuspend.;"
+   "li 7, 3;"  
+   "mtspr  %[dscr], 7;"// dscr = 3
+   "tresume.;" 
+   "subi   4, 4, 1;"
+   "cmpdi  4, 0;"
+   "bne2b;"
+   "tend.;"
+
+   // Transaction sucess! DSCR should be 3.
+   "mfspr  7, %[dscr];" 
+   "ori%[res], 7, 4;"  // res = 3|4 = 7
+   "b  4f;"
+   
+   // Abort handler. DSCR should be rolled back to 1.
+   "3:;"   
+   "mfspr  7, %[dscr];"
+   "ori%[res], 7, 8;"  // res = 1|8 = 9
+   "4:;"
+
+   : [res]"=r"(result)
+   : [dscr]"i"(SPRN_DSCR)
+   : "memory", "r0", "r4", "r7");
+
+   // If result is anything else other than 7 or 9, the dscr
+   // value must have been corrupted.
+   if ((result != 7) && (result != 9))
+   return 1;
+   
+   }
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   
+   // A low number of iterations (eg 100) can cause a false pass.
+   if (argc > 1) {
+   if (strcmp(argv[1], "-h") == 0) {
+   printf("Syntax:\n\t%s []\n",
+  argv[0]);
+   return 0;
+   } else {
+   num_loops = atoi(argv[1]);
+   }
+   }
+
+   printf("Starting, %d loops\n", num_loops);
+
+   test_harness(test_dscr, "tm_dscr");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 2/3] selftests/powerpc: Add test for forking inside transaction

2015-12-01 Thread Rashmica
As far as I'm aware, the kernel used to crash when forking inside a 
transaction (see powerpc/tm: Fix crash when forking inside a 
transaction). So this is to check that the transaction aborts rather 
than your whole kernel crashing.


On 01/12/15 19:11, Anshuman Khandual wrote:

On 12/01/2015 10:38 AM, Rashmica Gupta wrote:

+int test_fork(void)
+{
+   SKIP_IF(!have_htm());
+
+   asm __volatile__(
+   "tbegin.;"
+   "blt1f; "
+   "li 0, 2;"  /* fork syscall */
+   "sc  ;"
+   "tend.;"
+   "1: ;"
+   : : : "memory", "r0");
+   /* If we reach here, we've passed.  Otherwise we've probably crashed
+* the kernel */

The transaction inside the parent process will abort. What
is expected inside the child process ? Why should the kernel
crash ?



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 3/3] selftests/powerpc: Add in check for TM

2015-11-30 Thread Rashmica Gupta
The resched-dscr test does not currently check for TM, so add in check.

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/tm-resched-dscr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c 
b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
index 88c46481e59b..8243558aac6c 100644
--- a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
+++ b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
@@ -38,6 +38,8 @@ int test_body(void)
 {
uint64_t rv, dscr1 = 1, dscr2, texasr;
 
+   SKIP_IF(!have_htm());
+
printf("Check DSCR TM context switch: ");
fflush(stdout);
for (;;) {
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 2/3] selftests/powerpc: Add test for forking inside transaction

2015-11-30 Thread Rashmica Gupta
This test does a fork syscall inside a transaction. Basic sniff test to see
if we can enter the kernel during a transaction.

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/.gitignore |  1 +
 tools/testing/selftests/powerpc/tm/Makefile   |  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c  | 41 +++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c

diff --git a/tools/testing/selftests/powerpc/tm/.gitignore 
b/tools/testing/selftests/powerpc/tm/.gitignore
index e6668217ccd0..d0c7c97e9b13 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -2,3 +2,4 @@ tm-resched-dscr
 tm-syscall
 tm-signal-msr-resv
 tm-signal-stack
+tm-fork
diff --git a/tools/testing/selftests/powerpc/tm/Makefile 
b/tools/testing/selftests/powerpc/tm/Makefile
index 578572a3700a..f7d4727662aa 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,4 +1,4 @@
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
+TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack 
tm-fork
 
 all: $(TEST_PROGS)
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-fork.c 
b/tools/testing/selftests/powerpc/tm/tm-fork.c
new file mode 100644
index ..f571a48a59a0
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-fork.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015, Michael Neuling, IBM Corp.
+ * Licensed under GPLv2.
+ *
+ * Edited: Rashmica Gupta, Nov 2015
+ *
+ * Fork inside a transaction
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "utils.h"
+#include "tm.h"
+
+int test_fork(void)
+{
+   SKIP_IF(!have_htm());
+
+   asm __volatile__(
+   "tbegin.;"
+   "blt1f; "
+   "li 0, 2;"  /* fork syscall */
+   "sc  ;"
+   "tend.;"
+   "1: ;"
+   : : : "memory", "r0");
+   /* If we reach here, we've passed.  Otherwise we've probably crashed
+* the kernel */
+
+   return 0;
+}
+
+int main(int argc, char *argv[])
+{
+   return test_harness(test_fork, "tm_fork");
+}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/3] selftests/powerpc: Standardise TM calls

2015-11-30 Thread Rashmica Gupta
Currently tbegin, tend etc are written as opcodes or asm instructions. So
standardise these to asm instructions.

Signed-off-by: Rashmica Gupta 
---
 tools/testing/selftests/powerpc/tm/tm-resched-dscr.c | 16 ++--
 tools/testing/selftests/powerpc/tm/tm-signal-stack.c |  4 ++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c 
b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
index 42d4c8caad81..88c46481e59b 100644
--- a/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
+++ b/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
@@ -29,12 +29,8 @@
 #include 
 
 #include "utils.h"
+#include "tm.h"
 
-#define TBEGIN  ".long 0x7C00051D ;"
-#define TEND".long 0x7C00055D ;"
-#define TCHECK  ".long 0x7C00059C ;"
-#define TSUSPEND".long 0x7C0005DD ;"
-#define TRESUME ".long 0x7C2005DD ;"
 #define SPRN_TEXASR 0x82
 #define SPRN_DSCR   0x03
 
@@ -52,13 +48,13 @@ int test_body(void)
"mtspr   %[sprn_dscr], 3;"
 
/* start and suspend a transaction */
-   TBEGIN
+   "tbegin.;"
"beq 1f;"
-   TSUSPEND
+   "tsuspend.;"
 
/* hard loop until the transaction becomes doomed */
"2: ;"
-   TCHECK
+   "tcheck 0;"
"bc  4, 0, 2b;"
 
/* record DSCR and TEXASR */
@@ -67,8 +63,8 @@ int test_body(void)
"mfspr   3, %[sprn_texasr];"
"std 3, %[texasr];"
 
-   TRESUME
-   TEND
+   "tresume.;"
+   "tend.;"
"li  %[rv], 0;"
"1: ;"
: [rv]"=r"(rv), [dscr2]"=m"(dscr2), [texasr]"=m"(texasr)
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c 
b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
index 82c29cb222dc..8ffd5cee7271 100644
--- a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
@@ -60,9 +60,9 @@ int tm_signal_stack()
exit(1);
asm volatile("li 1, 0 ;"/* stack ptr == NULL */
 "1:"
-".long 0x7C00051D ;"   /* tbegin */
+"tbegin.;"
 "beq 1b ;" /* retry forever */
-".long 0x7C0005DD ; ;" /* tsuspend */
+"tsuspend.;"   
 "ld 2, 0(1) ;" /* trigger segv" */
 : : : "memory");
 
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 0/3] selftests/powerpc: Transactional Memory

2015-11-30 Thread Rashmica Gupta
This is reliant on the following patch series:
- selftests/powerpc by Michael Ellerman 
- selftests/powerpc by Michael Neuling 
- powerpc/tm by Michael Neuling 

Rashmica Gupta (3):
  selftests/powerpc: Standardise TM calls
  selftests/powerpc: Add test for forking inside transaction
  selftests/powerpc: Add in check for TM

 tools/testing/selftests/powerpc/tm/.gitignore  |  1 +
 tools/testing/selftests/powerpc/tm/Makefile|  2 +-
 tools/testing/selftests/powerpc/tm/tm-fork.c   | 41 ++
 .../testing/selftests/powerpc/tm/tm-resched-dscr.c | 18 +-
 .../testing/selftests/powerpc/tm/tm-signal-stack.c |  4 +--
 5 files changed, 53 insertions(+), 13 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm-fork.c

-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[v2] powerpc/cell: Remove the Cell QPACE code

2015-11-30 Thread Rashmica Gupta
All users of QPACE have upgraded to QPACE2 so remove the Cell QPACE code.

Signed-off-by: Rashmica Gupta 
---
Also removed the reference to QPACE in the Documentation.

 Documentation/devicetree/bindings/serial/8250.txt |   1 -
 arch/powerpc/boot/Makefile|   2 -
 arch/powerpc/configs/ppc64_defconfig  |   1 -
 arch/powerpc/platforms/cell/Kconfig   |   5 -
 arch/powerpc/platforms/cell/Makefile  |   3 -
 arch/powerpc/platforms/cell/qpace_setup.c | 148 --
 6 files changed, 160 deletions(-)
 delete mode 100644 arch/powerpc/platforms/cell/qpace_setup.c

diff --git a/Documentation/devicetree/bindings/serial/8250.txt 
b/Documentation/devicetree/bindings/serial/8250.txt
index 91d5ab0e60fc..936ab5b87324 100644
--- a/Documentation/devicetree/bindings/serial/8250.txt
+++ b/Documentation/devicetree/bindings/serial/8250.txt
@@ -14,7 +14,6 @@ Required properties:
  tegra132, or tegra210.
- "nxp,lpc3220-uart"
- "ralink,rt2880-uart"
-   - "ibm,qpace-nwp-serial"
- "altr,16550-FIFO32"
- "altr,16550-FIFO64"
- "altr,16550-FIFO128"
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 99e4487248ff..61165101342c 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -113,7 +113,6 @@ src-plat-$(CONFIG_EPAPR_BOOT) += epapr.c epapr-wrapper.c
 src-plat-$(CONFIG_PPC_PSERIES) += pseries-head.S
 src-plat-$(CONFIG_PPC_POWERNV) += pseries-head.S
 src-plat-$(CONFIG_PPC_IBM_CELL_BLADE) += pseries-head.S
-src-plat-$(CONFIG_PPC_CELL_QPACE) += pseries-head.S
 
 src-wlib := $(sort $(src-wlib-y))
 src-plat := $(sort $(src-plat-y))
@@ -217,7 +216,6 @@ image-$(CONFIG_PPC_POWERNV) += zImage.pseries
 image-$(CONFIG_PPC_MAPLE)  += zImage.maple
 image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries
 image-$(CONFIG_PPC_PS3)+= dtbImage.ps3
-image-$(CONFIG_PPC_CELL_QPACE) += zImage.pseries
 image-$(CONFIG_PPC_CHRP)   += zImage.chrp
 image-$(CONFIG_PPC_EFIKA)  += zImage.chrp
 image-$(CONFIG_PPC_PMAC)   += zImage.pmac
diff --git a/arch/powerpc/configs/ppc64_defconfig 
b/arch/powerpc/configs/ppc64_defconfig
index 2c041b535a64..b041fb607376 100644
--- a/arch/powerpc/configs/ppc64_defconfig
+++ b/arch/powerpc/configs/ppc64_defconfig
@@ -36,7 +36,6 @@ CONFIG_PS3_ROM=m
 CONFIG_PS3_FLASH=m
 CONFIG_PS3_LPM=m
 CONFIG_PPC_IBM_CELL_BLADE=y
-CONFIG_PPC_CELL_QPACE=y
 CONFIG_RTAS_FLASH=m
 CONFIG_IBMEBUS=y
 CONFIG_CPU_FREQ_PMAC64=y
diff --git a/arch/powerpc/platforms/cell/Kconfig 
b/arch/powerpc/platforms/cell/Kconfig
index 429fc59d2a47..d9088f0b8fcc 100644
--- a/arch/powerpc/platforms/cell/Kconfig
+++ b/arch/powerpc/platforms/cell/Kconfig
@@ -33,11 +33,6 @@ config PPC_IBM_CELL_BLADE
select PPC_UDBG_16550
select UDBG_RTAS_CONSOLE
 
-config PPC_CELL_QPACE
-   bool "IBM Cell - QPACE"
-   depends on PPC64 && PPC_BOOK3S && CPU_BIG_ENDIAN
-   select PPC_CELL_COMMON
-
 config AXON_MSI
bool
depends on PPC_IBM_CELL_BLADE && PCI_MSI
diff --git a/arch/powerpc/platforms/cell/Makefile 
b/arch/powerpc/platforms/cell/Makefile
index 34699bddfddd..070edd1584cf 100644
--- a/arch/powerpc/platforms/cell/Makefile
+++ b/arch/powerpc/platforms/cell/Makefile
@@ -11,7 +11,6 @@ obj-$(CONFIG_PPC_IBM_CELL_POWERBUTTON)+= 
cbe_powerbutton.o
 
 ifeq ($(CONFIG_SMP),y)
 obj-$(CONFIG_PPC_CELL_NATIVE)  += smp.o
-obj-$(CONFIG_PPC_CELL_QPACE)   += smp.o
 endif
 
 # needed only when building loadable spufs.ko
@@ -27,5 +26,3 @@ obj-$(CONFIG_SPU_BASE)+= 
spu_callbacks.o spu_base.o \
 
 obj-$(CONFIG_AXON_MSI) += axon_msi.o
 
-# qpace setup
-obj-$(CONFIG_PPC_CELL_QPACE)   += qpace_setup.o
diff --git a/arch/powerpc/platforms/cell/qpace_setup.c 
b/arch/powerpc/platforms/cell/qpace_setup.c
deleted file mode 100644
index d328140dc6f5..
--- a/arch/powerpc/platforms/cell/qpace_setup.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- *  linux/arch/powerpc/platforms/cell/qpace_setup.c
- *
- *  Copyright (C) 1995  Linus Torvalds
- *  Adapted from 'alpha' version by Gary Thomas
- *  Modified by Cort Dougan (c...@cs.nmt.edu)
- *  Modified by PPC64 Team, IBM Corp
- *  Modified by Cell Team, IBM Deutschland Entwicklung GmbH
- *  Modified by Benjamin Krill , IBM Corp.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 

[PATCH] powerpc/cell: Remove the Cell QPACE code.

2015-11-25 Thread Rashmica Gupta
All users of QPACE have upgraded to QPACE2 so remove the Cell QPACE code.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/boot/Makefile|   2 -
 arch/powerpc/configs/ppc64_defconfig  |   1 -
 arch/powerpc/platforms/cell/Kconfig   |   5 -
 arch/powerpc/platforms/cell/Makefile  |   3 -
 arch/powerpc/platforms/cell/qpace_setup.c | 148 --
 5 files changed, 159 deletions(-)
 delete mode 100644 arch/powerpc/platforms/cell/qpace_setup.c

diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 99e4487248ff..61165101342c 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -113,7 +113,6 @@ src-plat-$(CONFIG_EPAPR_BOOT) += epapr.c epapr-wrapper.c
 src-plat-$(CONFIG_PPC_PSERIES) += pseries-head.S
 src-plat-$(CONFIG_PPC_POWERNV) += pseries-head.S
 src-plat-$(CONFIG_PPC_IBM_CELL_BLADE) += pseries-head.S
-src-plat-$(CONFIG_PPC_CELL_QPACE) += pseries-head.S
 
 src-wlib := $(sort $(src-wlib-y))
 src-plat := $(sort $(src-plat-y))
@@ -217,7 +216,6 @@ image-$(CONFIG_PPC_POWERNV) += zImage.pseries
 image-$(CONFIG_PPC_MAPLE)  += zImage.maple
 image-$(CONFIG_PPC_IBM_CELL_BLADE) += zImage.pseries
 image-$(CONFIG_PPC_PS3)+= dtbImage.ps3
-image-$(CONFIG_PPC_CELL_QPACE) += zImage.pseries
 image-$(CONFIG_PPC_CHRP)   += zImage.chrp
 image-$(CONFIG_PPC_EFIKA)  += zImage.chrp
 image-$(CONFIG_PPC_PMAC)   += zImage.pmac
diff --git a/arch/powerpc/configs/ppc64_defconfig 
b/arch/powerpc/configs/ppc64_defconfig
index 2c041b535a64..b041fb607376 100644
--- a/arch/powerpc/configs/ppc64_defconfig
+++ b/arch/powerpc/configs/ppc64_defconfig
@@ -36,7 +36,6 @@ CONFIG_PS3_ROM=m
 CONFIG_PS3_FLASH=m
 CONFIG_PS3_LPM=m
 CONFIG_PPC_IBM_CELL_BLADE=y
-CONFIG_PPC_CELL_QPACE=y
 CONFIG_RTAS_FLASH=m
 CONFIG_IBMEBUS=y
 CONFIG_CPU_FREQ_PMAC64=y
diff --git a/arch/powerpc/platforms/cell/Kconfig 
b/arch/powerpc/platforms/cell/Kconfig
index 429fc59d2a47..d9088f0b8fcc 100644
--- a/arch/powerpc/platforms/cell/Kconfig
+++ b/arch/powerpc/platforms/cell/Kconfig
@@ -33,11 +33,6 @@ config PPC_IBM_CELL_BLADE
select PPC_UDBG_16550
select UDBG_RTAS_CONSOLE
 
-config PPC_CELL_QPACE
-   bool "IBM Cell - QPACE"
-   depends on PPC64 && PPC_BOOK3S && CPU_BIG_ENDIAN
-   select PPC_CELL_COMMON
-
 config AXON_MSI
bool
depends on PPC_IBM_CELL_BLADE && PCI_MSI
diff --git a/arch/powerpc/platforms/cell/Makefile 
b/arch/powerpc/platforms/cell/Makefile
index 34699bddfddd..070edd1584cf 100644
--- a/arch/powerpc/platforms/cell/Makefile
+++ b/arch/powerpc/platforms/cell/Makefile
@@ -11,7 +11,6 @@ obj-$(CONFIG_PPC_IBM_CELL_POWERBUTTON)+= 
cbe_powerbutton.o
 
 ifeq ($(CONFIG_SMP),y)
 obj-$(CONFIG_PPC_CELL_NATIVE)  += smp.o
-obj-$(CONFIG_PPC_CELL_QPACE)   += smp.o
 endif
 
 # needed only when building loadable spufs.ko
@@ -27,5 +26,3 @@ obj-$(CONFIG_SPU_BASE)+= 
spu_callbacks.o spu_base.o \
 
 obj-$(CONFIG_AXON_MSI) += axon_msi.o
 
-# qpace setup
-obj-$(CONFIG_PPC_CELL_QPACE)   += qpace_setup.o
diff --git a/arch/powerpc/platforms/cell/qpace_setup.c 
b/arch/powerpc/platforms/cell/qpace_setup.c
deleted file mode 100644
index d328140dc6f5..
--- a/arch/powerpc/platforms/cell/qpace_setup.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- *  linux/arch/powerpc/platforms/cell/qpace_setup.c
- *
- *  Copyright (C) 1995  Linus Torvalds
- *  Adapted from 'alpha' version by Gary Thomas
- *  Modified by Cort Dougan (c...@cs.nmt.edu)
- *  Modified by PPC64 Team, IBM Corp
- *  Modified by Cell Team, IBM Deutschland Entwicklung GmbH
- *  Modified by Benjamin Krill , IBM Corp.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "interrupt.h"
-#include "pervasive.h"
-#include "ras.h"
-
-static void qpace_show_cpuinfo(struct seq_file *m)
-{
-   struct device_node *root;
-   const char *model = "";
-
-   root = of_find_node_by_path("/");
-   if (root)
-   model = of_get_property(root, "model", NULL);
-   seq_printf(m, "machine\t\t: CHRP %s\n", model);
-   of_node_put(root);
-}
-
-static void qpace_progress(char *s, unsigned short hex)
-{
-   printk("*** %04x : %s\n", hex, s ? s : "");
-}
-
-static const struct of_device_id qpace_bus_ids[] __initconst = {
-  

[PATCH v2] powerpc: Append linux_banner to exception information in xmon.

2015-11-24 Thread Rashmica Gupta
Currently if you are in xmon without an oops etc. to view the kernel
version you have to type "d $linux_banner" - not necessarily obvious. As
this is useful information, append to the output of "e" command.

Example output:
$mon> e
cpu 0x1: Vector: 0  at [c000f879ba80]
pc: c0081718: sysrq_handle_xmon+0x68/0x80
lr: c0081718: sysrq_handle_xmon+0x68/0x80
sp: c000f879bbe0
   msr: 80009033
  current = 0xc000f604d5c0
  paca= 0xcfdc0480   softe: 0irq_happened: 0x01
pid   = 2467, comm = bash
Linux version 4.4.0-rc2-8-gc51af91c3ab3-dirty (rashmica@circle) (gcc
version 5.1.1 20150629 (GCC) ) #45 SMP Wed Nov 25 10:25:12 AEDT 2015

Signed-off-by: Rashmica Gupta 
---
Added example output and word wrapping.

 arch/powerpc/xmon/xmon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index df05bd2fca07..6d3d9d031aea 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -1528,6 +1528,8 @@ static void excprint(struct pt_regs *fp)
 
if (trap == 0x700)
print_bug_trap(fp);
+
+   printf(linux_banner);
 }
 
 static void prregs(struct pt_regs *fp)
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc: Append linux_banner to exception information in xmon.

2015-11-24 Thread Rashmica Gupta
Currently if you are in xmon without an oops etc. to view the kernel version 
you have to type "d $linux_banner" - not necessarily obvious. As this is useful 
information, append to the output of "e" command.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/xmon/xmon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index df05bd2fca07..6d3d9d031aea 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -1528,6 +1528,8 @@ static void excprint(struct pt_regs *fp)
 
if (trap == 0x700)
print_bug_trap(fp);
+
+   printf(linux_banner);
 }
 
 static void prregs(struct pt_regs *fp)
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc: Fix xmon ml command to work with 64 bit values.

2015-11-24 Thread Rashmica Gupta
The ml command in xmon currently only works for 32-bit values and so fails
to find 64-bit values on a ppc64 machine. So change to work for 64-bit
values.

This is based off a patch by Josh Boyer.

Signed-off-by: Rashmica Gupta 
---

Based off this patch: http://patchwork.ozlabs.org/patch/90309/

 arch/powerpc/xmon/xmon.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 786bf01691c9..df05bd2fca07 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -184,6 +184,12 @@ extern void xmon_leave(void);
 #define GETWORD(v) (((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + 
(v)[3])
 #endif
 
+#if BITS_PER_LONG == 64
+#define GETLONG(v) (((unsigned long) GETWORD(v)) << 32 | GETWORD(v+4))
+#else
+#define GETLONG(v) GETWORD(v)
+#endif
+
 static char *help_string = "\
 Commands:\n\
   bshow breakpoints\n\
@@ -2447,14 +2453,15 @@ memdiffs(unsigned char *p1, unsigned char *p2, unsigned 
nb, unsigned maxpr)
printf("Total of %d differences\n", prt);
 }
 
-static unsigned mend;
-static unsigned mask;
+static unsigned long mend;
+static unsigned long mask;
 
 static void
 memlocate(void)
 {
-   unsigned a, n;
-   unsigned char val[4];
+   unsigned long a, n;
+   int size = sizeof(unsigned long);
+   unsigned char val[size];
 
last_cmd = "ml";
scanhex((void *)&mdest);
@@ -2470,10 +2477,10 @@ memlocate(void)
}
}
n = 0;
-   for (a = mdest; a < mend; a += 4) {
-   if (mread(a, val, 4) == 4
-   && ((GETWORD(val) ^ mval) & mask) == 0) {
-   printf("%.16x:  %.16x\n", a, GETWORD(val));
+   for (a = mdest; a < mend; a += size) {
+   if (mread(a, val, size) == size
+   && ((GETLONG(val) ^ mval) & mask) == 0){
+   printf("%.16lx:  %.16lx\n", a, GETLONG(val));
if (++n >= 10)
break;
}
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc: Add rN aliases to the pt_regs_offset table.

2015-11-20 Thread Rashmica Gupta
It is common practice with powerpc to use 'rN' to refer to register 'N'. However
when using the pt_regs_offset table we have to use 'gprN'.

So add aliases such that both 'rN' and 'gprN' can be used.

For example, we can currently do:
$ su -
$ echo "p:probe/sys_fchownat .sys_fchownat %gpr3:s32 +0(%gpr4):string %gpr5:s32
%gpr6:s32 %gpr7:s32" > /sys/kernel/debug/tracing/kprobe_events
$ echo 1 > /sys/kernel/debug/tracing/events/probe/sys_fchownat/enable
$ touch /tmp/foo
$ chown root /tmp/foo
$ echo 0 > /sys/kernel/debug/tracing/events/enable
$ cat /sys/kernel/debug/tracing/trace
   chown-5040  [001] d... 24800.047211: sys_fchownat:
(.SyS_fchownat+0x0/0x190) arg1=-100 arg2="foo" arg3=0 arg4=-1 arg5=0

Instead we'd like to be able to use:
$ echo "p:probe/sys_fchownat sys_fchownat %r3:s32 +0(%r4):string %r5:s32
%r6:s32 %r7:s32" > /sys/kernel/debug/tracing/kprobe_events

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/ptrace.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 737c0d0b53ac..30a03c03fe73 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -60,6 +60,7 @@ struct pt_regs_offset {
 #define STR(s) #s  /* convert to string */
 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
 #define GPR_OFFSET_NAME(num)   \
+   {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \
{.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
 #define REG_OFFSET_END {.name = NULL, .offset = 0}
 
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc: Standardise on NR_syscalls rather than __NR_syscalls.

2015-11-18 Thread Rashmica Gupta
Most architectures use NR_syscalls as the #define for the number of syscalls.

We use __NR_syscalls, and then define NR_syscalls as __NR_syscalls.

__NR_syscalls is not used outside arch code, whereas NR_syscalls is. So as
NR_syscalls must be defined and __NR_syscalls does not, replace __NR_syscalls
with NR_syscalls.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/include/asm/unistd.h| 3 +--
 arch/powerpc/include/asm/vdso_datapage.h | 2 +-
 arch/powerpc/kernel/systbl_chk.c | 2 +-
 arch/powerpc/kernel/systbl_chk.sh| 2 +-
 arch/powerpc/kernel/vdso.c   | 2 +-
 arch/powerpc/kernel/vdso32/datapage.S| 2 +-
 arch/powerpc/kernel/vdso64/datapage.S| 2 +-
 arch/powerpc/platforms/cell/spufs/run.c  | 2 +-
 8 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/unistd.h 
b/arch/powerpc/include/asm/unistd.h
index 6d8f8023ac27..05bf34296144 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ b/arch/powerpc/include/asm/unistd.h
@@ -12,10 +12,9 @@
 #include 
 
 
-#define __NR_syscalls  378
+#define NR_syscalls378
 
 #define __NR__exit __NR_exit
-#define NR_syscalls__NR_syscalls
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/powerpc/include/asm/vdso_datapage.h 
b/arch/powerpc/include/asm/vdso_datapage.h
index b73a8199f161..1afe90ade595 100644
--- a/arch/powerpc/include/asm/vdso_datapage.h
+++ b/arch/powerpc/include/asm/vdso_datapage.h
@@ -41,7 +41,7 @@
 #include 
 #include 
 
-#define SYSCALL_MAP_SIZE  ((__NR_syscalls + 31) / 32)
+#define SYSCALL_MAP_SIZE  ((NR_syscalls + 31) / 32)
 
 /*
  * So here is the ppc64 backward compatible version
diff --git a/arch/powerpc/kernel/systbl_chk.c b/arch/powerpc/kernel/systbl_chk.c
index 2384129f5893..55323a620cfe 100644
--- a/arch/powerpc/kernel/systbl_chk.c
+++ b/arch/powerpc/kernel/systbl_chk.c
@@ -57,4 +57,4 @@
 
 START_TABLE
 #include 
-END_TABLE __NR_syscalls
+END_TABLE NR_syscalls
diff --git a/arch/powerpc/kernel/systbl_chk.sh 
b/arch/powerpc/kernel/systbl_chk.sh
index 19415e7674a5..31b6e7c358ca 100644
--- a/arch/powerpc/kernel/systbl_chk.sh
+++ b/arch/powerpc/kernel/systbl_chk.sh
@@ -16,7 +16,7 @@ awk   'BEGIN { num = -1; }# Ignore the beginning of the 
file
/^START_TABLE/ { num = 0; next; }
/^END_TABLE/ {
if (num != $2) {
-   printf "__NR_syscalls (%s) is not one more than the 
last syscall (%s)\n",
+   printf "NR_syscalls (%s) is not one more than the last 
syscall (%s)\n",
$2, num - 1;
exit(1);
}
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index b457bfa28436..def1b8b5e6c1 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -671,7 +671,7 @@ static void __init vdso_setup_syscall_map(void)
extern unsigned long sys_ni_syscall;
 
 
-   for (i = 0; i < __NR_syscalls; i++) {
+   for (i = 0; i < NR_syscalls; i++) {
 #ifdef CONFIG_PPC64
if (sys_call_table[i*2] != sys_ni_syscall)
vdso_data->syscall_map_64[i >> 5] |=
diff --git a/arch/powerpc/kernel/vdso32/datapage.S 
b/arch/powerpc/kernel/vdso32/datapage.S
index 59cf5f452879..3745113fcc65 100644
--- a/arch/powerpc/kernel/vdso32/datapage.S
+++ b/arch/powerpc/kernel/vdso32/datapage.S
@@ -61,7 +61,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map)
addir3,r3,CFG_SYSCALL_MAP32
cmpli   cr0,r4,0
beqlr
-   li  r0,__NR_syscalls
+   li  r0,NR_syscalls
stw r0,0(r4)
crclr   cr0*4+so
blr
diff --git a/arch/powerpc/kernel/vdso64/datapage.S 
b/arch/powerpc/kernel/vdso64/datapage.S
index 2f01c4a0d8a0..184a6ba7f283 100644
--- a/arch/powerpc/kernel/vdso64/datapage.S
+++ b/arch/powerpc/kernel/vdso64/datapage.S
@@ -62,7 +62,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map)
cmpli   cr0,r4,0
crclr   cr0*4+so
beqlr
-   li  r0,__NR_syscalls
+   li  r0,NR_syscalls
stw r0,0(r4)
blr
   .cfi_endproc
diff --git a/arch/powerpc/platforms/cell/spufs/run.c 
b/arch/powerpc/platforms/cell/spufs/run.c
index 4ddf769a64e5..9f79004e6d6f 100644
--- a/arch/powerpc/platforms/cell/spufs/run.c
+++ b/arch/powerpc/platforms/cell/spufs/run.c
@@ -326,7 +326,7 @@ static int spu_process_callback(struct spu_context *ctx)
spu_ret = -ENOSYS;
npc += 4;
 
-   if (s.nr_ret < __NR_syscalls) {
+   if (s.nr_ret < NR_syscalls) {
spu_release(ctx);
/* do actual system call from here */
spu_ret = spu_sys_callback(&s);
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH] powerpc: Remove unused function trace_syscall()

2015-11-18 Thread Rashmica Gupta
This function has been unused since commit 14cf11af6cf6 ("powerpc: Merge enough
to start building in arch/powerpc."), so remove it.

Signed-off-by: Rashmica Gupta 
---
 arch/powerpc/kernel/traps.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 37de90f8a845..b6becc795bb5 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -1313,13 +1313,6 @@ void nonrecoverable_exception(struct pt_regs *regs)
die("nonrecoverable exception", regs, SIGKILL);
 }
 
-void trace_syscall(struct pt_regs *regs)
-{
-   printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld
%s\n",
-  current, task_pid_nr(current), regs->nip, regs->link, 
regs->gpr[0],
-  regs->ccr&0x1000?"Error=":"", regs->gpr[3], print_tainted());
-}
-
 void kernel_fp_unavailable_exception(struct pt_regs *regs)
 {
enum ctx_state prev_state = exception_enter();
-- 
2.5.0

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev