Re: [RFC PATCH 03/12] powerpc/prom_init: Add the ESM call to prom_init

2019-06-28 Thread Thiago Jung Bauermann


Hello Alexey,

Thanks for reviewing this patch!

Alexey Kardashevskiy  writes:

> On 21/05/2019 14:49, Thiago Jung Bauermann wrote:
>> @@ -1707,6 +1723,43 @@ static void __init prom_close_stdin(void)
>>  }
>>  }
>>  
>> +#ifdef CONFIG_PPC_SVM
>> +static int prom_rtas_os_term_hcall(uint64_t args)
>
>
> This is just an rtas hcall, nothing special about "os-term".

Sorry, unfortunately I don't understand how we're treating os-term
especially. Do you mean that we should inline this function directly
into prom_rtas_os_term()?

>> +{
>> +register uint64_t arg1 asm("r3") = 0xf000;
>> +register uint64_t arg2 asm("r4") = args;
>> +
>> +asm volatile("sc 1\n" : "=r" (arg1) :
>> +"r" (arg1),
>> +"r" (arg2) :);
>> +return arg1;
>> +}
>> +
>> +static struct rtas_args __prombss os_term_args;
>> +
>> +static void __init prom_rtas_os_term(char *str)
>> +{
>> +phandle rtas_node;
>> +__be32 val;
>> +u32 token;
>> +
>> +prom_printf("%s: start...\n", __func__);
>> +rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas"));
>> +prom_printf("rtas_node: %x\n", rtas_node);
>> +if (!PHANDLE_VALID(rtas_node))
>> +return;
>> +
>> +val = 0;
>> +prom_getprop(rtas_node, "ibm,os-term", , sizeof(val));
>> +token = be32_to_cpu(val);
>> +prom_printf("ibm,os-term: %x\n", token);
>> +if (token == 0)
>> +prom_panic("Could not get token for ibm,os-term\n");
>> +os_term_args.token = cpu_to_be32(token);
>> +prom_rtas_os_term_hcall((uint64_t)_term_args);
>> +}
>> +#endif /* CONFIG_PPC_SVM */
>> +
>>  /*
>>   * Allocate room for and instantiate RTAS
>>   */

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


[PATCH v4 7/8] KVM: PPC: Ultravisor: Enter a secure guest

2019-06-28 Thread Claudio Carvalho
From: Sukadev Bhattiprolu 

To enter a secure guest, we have to go through the ultravisor, therefore
we do a ucall when we are entering a secure guest.

This change is needed for any sort of entry to the secure guest from the
hypervisor, whether it is a return from an hcall, a return from a
hypervisor interrupt, or the first time that a secure guest vCPU is run.

If we are returning from an hcall, the results are already in the
appropriate registers R3:12, except for R3, R6 and R7. R3 has the status
of the reflected hcall, therefore we move it to R0 for the ultravisor and
set R3 to the UV_RETURN ucall number. R6,7 were used as temporary
registers, hence we restore them.

Have fast_guest_return check the kvm_arch.secure_guest field so that a
new CPU enters UV when started (in response to a RTAS start-cpu call).

Thanks to input from Paul Mackerras, Ram Pai and Mike Anderson.

Signed-off-by: Sukadev Bhattiprolu 
[ Pass SRR1 in r11 for UV_RETURN, fix kvmppc_msr_interrupt to preserve
  the MSR_S bit ]
Signed-off-by: Paul Mackerras 
[ Fix UV_RETURN ucall number and arch.secure_guest check ]
Signed-off-by: Ram Pai 
[ Save the actual R3 in R0 for the ultravisor and use R3 for the
  UV_RETURN ucall number. Update commit message and ret_to_ultra comment ]
Signed-off-by: Claudio Carvalho 
---
 arch/powerpc/include/asm/kvm_host.h   |  1 +
 arch/powerpc/include/asm/ultravisor-api.h |  1 +
 arch/powerpc/kernel/asm-offsets.c |  1 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   | 40 +++
 4 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 013c76a0a03e..184becb62ea4 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -294,6 +294,7 @@ struct kvm_arch {
cpumask_t cpu_in_guest;
u8 radix;
u8 fwnmi_enabled;
+   u8 secure_guest;
bool threads_indep;
bool nested_enable;
pgd_t *pgtable;
diff --git a/arch/powerpc/include/asm/ultravisor-api.h 
b/arch/powerpc/include/asm/ultravisor-api.h
index 141940771add..7c4d0b4ced12 100644
--- a/arch/powerpc/include/asm/ultravisor-api.h
+++ b/arch/powerpc/include/asm/ultravisor-api.h
@@ -19,5 +19,6 @@
 
 /* opcodes */
 #define UV_WRITE_PATE  0xF104
+#define UV_RETURN  0xF11C
 
 #endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 8e02444e9d3d..44742724513e 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -508,6 +508,7 @@ int main(void)
OFFSET(KVM_VRMA_SLB_V, kvm, arch.vrma_slb_v);
OFFSET(KVM_RADIX, kvm, arch.radix);
OFFSET(KVM_FWNMI, kvm, arch.fwnmi_enabled);
+   OFFSET(KVM_SECURE_GUEST, kvm, arch.secure_guest);
OFFSET(VCPU_DSISR, kvm_vcpu, arch.shregs.dsisr);
OFFSET(VCPU_DAR, kvm_vcpu, arch.shregs.dar);
OFFSET(VCPU_VPA, kvm_vcpu, arch.vpa.pinned_addr);
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index cffb365d9d02..89813ca987c2 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Sign-extend HDEC if not on POWER9 */
 #define EXTEND_HDEC(reg)   \
@@ -1092,16 +1093,12 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
 
ld  r5, VCPU_LR(r4)
-   ld  r6, VCPU_CR(r4)
mtlrr5
-   mtcrr6
 
ld  r1, VCPU_GPR(R1)(r4)
ld  r2, VCPU_GPR(R2)(r4)
ld  r3, VCPU_GPR(R3)(r4)
ld  r5, VCPU_GPR(R5)(r4)
-   ld  r6, VCPU_GPR(R6)(r4)
-   ld  r7, VCPU_GPR(R7)(r4)
ld  r8, VCPU_GPR(R8)(r4)
ld  r9, VCPU_GPR(R9)(r4)
ld  r10, VCPU_GPR(R10)(r4)
@@ -1119,10 +1116,38 @@ BEGIN_FTR_SECTION
mtspr   SPRN_HDSISR, r0
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
 
+   ld  r6, VCPU_KVM(r4)
+   lbz r7, KVM_SECURE_GUEST(r6)
+   cmpdi   r7, 0
+   bne ret_to_ultra
+
+   lwz r6, VCPU_CR(r4)
+   mtcrr6
+
+   ld  r7, VCPU_GPR(R7)(r4)
+   ld  r6, VCPU_GPR(R6)(r4)
ld  r0, VCPU_GPR(R0)(r4)
ld  r4, VCPU_GPR(R4)(r4)
HRFI_TO_GUEST
b   .
+/*
+ * We are entering a secure guest, so we have to invoke the ultravisor to do
+ * that. If we are returning from a hcall, the results are already in the
+ * appropriate registers R3:12, except for R3, R6 and R7. R3 has the status of
+ * the reflected hcall, therefore we move it to R0 for the ultravisor and set
+ * R3 to the UV_RETURN ucall number. R6,7 were used as temporary registers
+ * above, hence we restore them.
+ */
+ret_to_ultra:
+   lwz r6, VCPU_CR(r4)
+   mtcrr6
+   mfspr   r11, SPRN_SRR1
+   mr  r0, r3
+   

[PATCH v4 8/8] KVM: PPC: Ultravisor: Check for MSR_S during hv_reset_msr

2019-06-28 Thread Claudio Carvalho
From: Michael Anderson 

 - Check for MSR_S so that kvmppc_set_msr will include it. Prior to this
   change return to guest would not have the S bit set.

 - Patch based on comment from Paul Mackerras 

Signed-off-by: Michael Anderson 
Signed-off-by: Claudio Carvalho 
Acked-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index ab3d484c5e2e..ab62a66f9b4e 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -295,6 +295,7 @@ static void kvmppc_mmu_book3s_64_hv_reset_msr(struct 
kvm_vcpu *vcpu)
msr |= MSR_TS_S;
else
msr |= vcpu->arch.shregs.msr & MSR_TS_MASK;
+   msr |= vcpu->arch.shregs.msr & MSR_S;
kvmppc_set_msr(vcpu, msr);
 }
 
-- 
2.20.1



[PATCH v4 6/8] KVM: PPC: Ultravisor: Restrict LDBAR access

2019-06-28 Thread Claudio Carvalho
When the ultravisor firmware is available, it takes control over the
LDBAR register. In this case, thread-imc updates and save/restore
operations on the LDBAR register are handled by ultravisor.

Signed-off-by: Claudio Carvalho 
Reviewed-by: Ram Pai 
Reviewed-by: Ryan Grimm 
Acked-by: Madhavan Srinivasan 
Acked-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   | 2 ++
 arch/powerpc/platforms/powernv/idle.c | 6 --
 arch/powerpc/platforms/powernv/opal-imc.c | 4 
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index f9b2620fbecd..cffb365d9d02 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -375,8 +375,10 @@ BEGIN_FTR_SECTION
mtspr   SPRN_RPR, r0
ld  r0, KVM_SPLIT_PMMAR(r6)
mtspr   SPRN_PMMAR, r0
+BEGIN_FW_FTR_SECTION_NESTED(70)
ld  r0, KVM_SPLIT_LDBAR(r6)
mtspr   SPRN_LDBAR, r0
+END_FW_FTR_SECTION_NESTED(FW_FEATURE_ULTRAVISOR, 0, 70)
isync
 FTR_SECTION_ELSE
/* On P9 we use the split_info for coordinating LPCR changes */
diff --git a/arch/powerpc/platforms/powernv/idle.c 
b/arch/powerpc/platforms/powernv/idle.c
index 77f2e0a4ee37..5593a2d55959 100644
--- a/arch/powerpc/platforms/powernv/idle.c
+++ b/arch/powerpc/platforms/powernv/idle.c
@@ -679,7 +679,8 @@ static unsigned long power9_idle_stop(unsigned long psscr, 
bool mmu_on)
sprs.ptcr   = mfspr(SPRN_PTCR);
sprs.rpr= mfspr(SPRN_RPR);
sprs.tscr   = mfspr(SPRN_TSCR);
-   sprs.ldbar  = mfspr(SPRN_LDBAR);
+   if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))
+   sprs.ldbar  = mfspr(SPRN_LDBAR);
 
sprs_saved = true;
 
@@ -762,7 +763,8 @@ static unsigned long power9_idle_stop(unsigned long psscr, 
bool mmu_on)
mtspr(SPRN_PTCR,sprs.ptcr);
mtspr(SPRN_RPR, sprs.rpr);
mtspr(SPRN_TSCR,sprs.tscr);
-   mtspr(SPRN_LDBAR,   sprs.ldbar);
+   if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))
+   mtspr(SPRN_LDBAR,   sprs.ldbar);
 
if (pls >= pnv_first_tb_loss_level) {
/* TB loss */
diff --git a/arch/powerpc/platforms/powernv/opal-imc.c 
b/arch/powerpc/platforms/powernv/opal-imc.c
index 1b6932890a73..5fe2d4526cbc 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -254,6 +254,10 @@ static int opal_imc_counters_probe(struct platform_device 
*pdev)
bool core_imc_reg = false, thread_imc_reg = false;
u32 type;
 
+   /* Disable IMC devices, when Ultravisor is enabled. */
+   if (firmware_has_feature(FW_FEATURE_ULTRAVISOR))
+   return -EACCES;
+
/*
 * Check whether this is kdump kernel. If yes, force the engines to
 * stop and return.
-- 
2.20.1



[PATCH v4 5/8] KVM: PPC: Ultravisor: Restrict flush of the partition tlb cache

2019-06-28 Thread Claudio Carvalho
From: Ram Pai 

Ultravisor is responsible for flushing the tlb cache, since it manages
the PATE entries. Hence skip tlb flush, if the ultravisor firmware is
available.

Signed-off-by: Ram Pai 
Signed-off-by: Claudio Carvalho 
---
 arch/powerpc/mm/book3s64/pgtable.c | 33 +-
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/mm/book3s64/pgtable.c 
b/arch/powerpc/mm/book3s64/pgtable.c
index 224c5c7c2e3d..bc8eb2bf9810 100644
--- a/arch/powerpc/mm/book3s64/pgtable.c
+++ b/arch/powerpc/mm/book3s64/pgtable.c
@@ -224,6 +224,23 @@ void __init mmu_partition_table_init(void)
powernv_set_nmmu_ptcr(ptcr);
 }
 
+static void flush_partition(unsigned int lpid, unsigned long dw0)
+{
+   if (dw0 & PATB_HR) {
+   asm volatile(PPC_TLBIE_5(%0, %1, 2, 0, 1) : :
+"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
+   asm volatile(PPC_TLBIE_5(%0, %1, 2, 1, 1) : :
+"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
+   trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 1);
+   } else {
+   asm volatile(PPC_TLBIE_5(%0, %1, 2, 0, 0) : :
+"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
+   trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 0);
+   }
+   /* do we need fixup here ?*/
+   asm volatile("eieio; tlbsync; ptesync" : : : "memory");
+}
+
 static void __mmu_partition_table_set_entry(unsigned int lpid,
unsigned long dw0,
unsigned long dw1)
@@ -238,20 +255,8 @@ static void __mmu_partition_table_set_entry(unsigned int 
lpid,
 * The type of flush (hash or radix) depends on what the previous
 * use of this partition ID was, not the new use.
 */
-   asm volatile("ptesync" : : : "memory");
-   if (old & PATB_HR) {
-   asm volatile(PPC_TLBIE_5(%0,%1,2,0,1) : :
-"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
-   asm volatile(PPC_TLBIE_5(%0,%1,2,1,1) : :
-"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
-   trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 1);
-   } else {
-   asm volatile(PPC_TLBIE_5(%0,%1,2,0,0) : :
-"r" (TLBIEL_INVAL_SET_LPID), "r" (lpid));
-   trace_tlbie(lpid, 0, TLBIEL_INVAL_SET_LPID, lpid, 2, 0, 0);
-   }
-   /* do we need fixup here ?*/
-   asm volatile("eieio; tlbsync; ptesync" : : : "memory");
+   if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))
+   flush_partition(lpid, old);
 }
 
 void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
-- 
2.20.1



[PATCH v4 4/8] KVM: PPC: Ultravisor: Use UV_WRITE_PATE ucall to register a PATE

2019-06-28 Thread Claudio Carvalho
From: Michael Anderson 

When running under an ultravisor, the ultravisor controls the real
partition table and has it in secure memory where the hypervisor can't
access it, and therefore we (the HV) have to do a ucall whenever we want
to update an entry.

The HV still keeps a copy of its view of the partition table in normal
memory so that the nest MMU can access it.

Both partition tables will have PATE entries for HV and normal virtual
machines.

Suggested-by: Ryan Grimm 
Signed-off-by: Michael Anderson 
Signed-off-by: Madhavan Srinivasan 
Signed-off-by: Ram Pai 
[ Write the pate in HV's table before doing that in UV's ]
Signed-off-by: Claudio Carvalho 
---
 arch/powerpc/include/asm/ultravisor-api.h |  5 +++-
 arch/powerpc/include/asm/ultravisor.h | 14 ++
 arch/powerpc/mm/book3s64/hash_utils.c |  3 +-
 arch/powerpc/mm/book3s64/pgtable.c| 34 +--
 arch/powerpc/mm/book3s64/radix_pgtable.c  |  9 --
 5 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/ultravisor-api.h 
b/arch/powerpc/include/asm/ultravisor-api.h
index 49e766adabc7..141940771add 100644
--- a/arch/powerpc/include/asm/ultravisor-api.h
+++ b/arch/powerpc/include/asm/ultravisor-api.h
@@ -15,6 +15,9 @@
 #define U_SUCCESS  H_SUCCESS
 #define U_FUNCTION H_FUNCTION
 #define U_PARAMETERH_PARAMETER
+#define U_PERMISSION   H_PERMISSION
 
-#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
+/* opcodes */
+#define UV_WRITE_PATE  0xF104
 
+#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
diff --git a/arch/powerpc/include/asm/ultravisor.h 
b/arch/powerpc/include/asm/ultravisor.h
index a78a2dacfd0b..996c1efd6c6d 100644
--- a/arch/powerpc/include/asm/ultravisor.h
+++ b/arch/powerpc/include/asm/ultravisor.h
@@ -12,6 +12,8 @@
 
 #if !defined(__ASSEMBLY__)
 
+#include 
+
 /* Internal functions */
 extern int early_init_dt_scan_ultravisor(unsigned long node, const char *uname,
 int depth, void *data);
@@ -28,8 +30,20 @@ extern int early_init_dt_scan_ultravisor(unsigned long node, 
const char *uname,
  */
 #if defined(CONFIG_PPC_POWERNV)
 long ucall(unsigned long opcode, unsigned long *retbuf, ...);
+#else
+static long ucall(unsigned long opcode, unsigned long *retbuf, ...)
+{
+   return U_NOT_AVAILABLE;
+}
 #endif
 
+static inline int uv_register_pate(u64 lpid, u64 dw0, u64 dw1)
+{
+   unsigned long retbuf[UCALL_BUFSIZE];
+
+   return ucall(UV_WRITE_PATE, retbuf, lpid, dw0, dw1);
+}
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_ULTRAVISOR_H */
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c 
b/arch/powerpc/mm/book3s64/hash_utils.c
index 1ff451892d7f..220a4e133240 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -1080,9 +1080,10 @@ void hash__early_init_mmu_secondary(void)
 
if (!cpu_has_feature(CPU_FTR_ARCH_300))
mtspr(SPRN_SDR1, _SDR1);
-   else
+   else if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))
mtspr(SPRN_PTCR,
  __pa(partition_tb) | (PATB_SIZE_SHIFT - 12));
+
}
/* Initialize SLB */
slb_initialize();
diff --git a/arch/powerpc/mm/book3s64/pgtable.c 
b/arch/powerpc/mm/book3s64/pgtable.c
index ad3dd977c22d..224c5c7c2e3d 100644
--- a/arch/powerpc/mm/book3s64/pgtable.c
+++ b/arch/powerpc/mm/book3s64/pgtable.c
@@ -16,6 +16,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -206,12 +208,25 @@ void __init mmu_partition_table_init(void)
 * 64 K size.
 */
ptcr = __pa(partition_tb) | (PATB_SIZE_SHIFT - 12);
-   mtspr(SPRN_PTCR, ptcr);
+   /*
+* If ultravisor is available, it is responsible for creating and
+* managing partition table
+*/
+   if (!firmware_has_feature(FW_FEATURE_ULTRAVISOR))
+   mtspr(SPRN_PTCR, ptcr);
+
+   /*
+* Since nestMMU cannot access secure memory. Create
+* and manage our own partition table. This table
+* contains entries for nonsecure and hypervisor
+* partition.
+*/
powernv_set_nmmu_ptcr(ptcr);
 }
 
-void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
-  unsigned long dw1)
+static void __mmu_partition_table_set_entry(unsigned int lpid,
+   unsigned long dw0,
+   unsigned long dw1)
 {
unsigned long old = be64_to_cpu(partition_tb[lpid].patb0);
 
@@ -238,6 +253,19 @@ void mmu_partition_table_set_entry(unsigned int lpid, 
unsigned long dw0,
/* do we need fixup here ?*/
asm volatile("eieio; tlbsync; ptesync" : : : "memory");
 }
+
+void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
+ unsigned long 

[PATCH v4 3/8] KVM: PPC: Ultravisor: Add generic ultravisor call handler

2019-06-28 Thread Claudio Carvalho
From: Ram Pai 

Add the ucall() function, which can be used to make ultravisor calls
with varied number of in and out arguments. Ultravisor calls can be made
from the host or guests.

This copies the implementation of plpar_hcall().

Signed-off-by: Ram Pai 
[ Change ucall.S to not save CR, rename and move headers, build ucall.S
  if CONFIG_PPC_POWERNV set, use R3 for the ucall number and add some
  comments in the code ]
Signed-off-by: Claudio Carvalho 
---
 arch/powerpc/include/asm/ultravisor-api.h | 20 +++
 arch/powerpc/include/asm/ultravisor.h | 20 +++
 arch/powerpc/kernel/Makefile  |  2 +-
 arch/powerpc/kernel/ucall.S   | 30 +++
 arch/powerpc/kernel/ultravisor.c  |  4 +++
 5 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/include/asm/ultravisor-api.h
 create mode 100644 arch/powerpc/kernel/ucall.S

diff --git a/arch/powerpc/include/asm/ultravisor-api.h 
b/arch/powerpc/include/asm/ultravisor-api.h
new file mode 100644
index ..49e766adabc7
--- /dev/null
+++ b/arch/powerpc/include/asm/ultravisor-api.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Ultravisor API.
+ *
+ * Copyright 2019, IBM Corporation.
+ *
+ */
+#ifndef _ASM_POWERPC_ULTRAVISOR_API_H
+#define _ASM_POWERPC_ULTRAVISOR_API_H
+
+#include 
+
+/* Return codes */
+#define U_NOT_AVAILABLEH_NOT_AVAILABLE
+#define U_SUCCESS  H_SUCCESS
+#define U_FUNCTION H_FUNCTION
+#define U_PARAMETERH_PARAMETER
+
+#endif /* _ASM_POWERPC_ULTRAVISOR_API_H */
+
diff --git a/arch/powerpc/include/asm/ultravisor.h 
b/arch/powerpc/include/asm/ultravisor.h
index e5009b0d84ea..a78a2dacfd0b 100644
--- a/arch/powerpc/include/asm/ultravisor.h
+++ b/arch/powerpc/include/asm/ultravisor.h
@@ -8,8 +8,28 @@
 #ifndef _ASM_POWERPC_ULTRAVISOR_H
 #define _ASM_POWERPC_ULTRAVISOR_H
 
+#include 
+
+#if !defined(__ASSEMBLY__)
+
 /* Internal functions */
 extern int early_init_dt_scan_ultravisor(unsigned long node, const char *uname,
 int depth, void *data);
 
+/* API functions */
+#define UCALL_BUFSIZE 4
+/**
+ * ucall: Make a powerpc ultravisor call.
+ * @opcode: The ultravisor call to make.
+ * @retbuf: Buffer to store up to 4 return arguments in.
+ *
+ * This call supports up to 6 arguments and 4 return arguments. Use
+ * UCALL_BUFSIZE to size the return argument buffer.
+ */
+#if defined(CONFIG_PPC_POWERNV)
+long ucall(unsigned long opcode, unsigned long *retbuf, ...);
+#endif
+
+#endif /* !__ASSEMBLY__ */
+
 #endif /* _ASM_POWERPC_ULTRAVISOR_H */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index f0caa302c8c0..f28baccc0a79 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -154,7 +154,7 @@ endif
 
 obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
-obj-$(CONFIG_PPC_POWERNV)  += ultravisor.o
+obj-$(CONFIG_PPC_POWERNV)  += ultravisor.o ucall.o
 
 # Disable GCOV, KCOV & sanitizers in odd or sensitive code
 GCOV_PROFILE_prom_init.o := n
diff --git a/arch/powerpc/kernel/ucall.S b/arch/powerpc/kernel/ucall.S
new file mode 100644
index ..1678f6eb7230
--- /dev/null
+++ b/arch/powerpc/kernel/ucall.S
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Generic code to perform an ultravisor call.
+ *
+ * Copyright 2019, IBM Corporation.
+ *
+ */
+#include 
+
+/*
+ * This function is based on the plpar_hcall()
+ */
+_GLOBAL_TOC(ucall)
+   std r4,STK_PARAM(R4)(r1)/* Save ret buffer */
+   mr  r4,r5
+   mr  r5,r6
+   mr  r6,r7
+   mr  r7,r8
+   mr  r8,r9
+   mr  r9,r10
+
+   sc 2/* Invoke the ultravisor */
+
+   ld  r12,STK_PARAM(R4)(r1)
+   std r4,  0(r12)
+   std r5,  8(r12)
+   std r6, 16(r12)
+   std r7, 24(r12)
+
+   blr /* Return r3 = status */
diff --git a/arch/powerpc/kernel/ultravisor.c b/arch/powerpc/kernel/ultravisor.c
index dc6021f63c97..02ddf79a9522 100644
--- a/arch/powerpc/kernel/ultravisor.c
+++ b/arch/powerpc/kernel/ultravisor.c
@@ -8,10 +8,14 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
 
+/* in ucall.S */
+EXPORT_SYMBOL_GPL(ucall);
+
 int __init early_init_dt_scan_ultravisor(unsigned long node, const char *uname,
 int depth, void *data)
 {
-- 
2.20.1



[PATCH v4 1/8] KVM: PPC: Ultravisor: Introduce the MSR_S bit

2019-06-28 Thread Claudio Carvalho
From: Sukadev Bhattiprolu 

The ultravisor processor mode is introduced in POWER platforms that
supports the Protected Execution Facility (PEF). Ultravisor is higher
privileged than hypervisor mode.

In PEF enabled platforms, the MSR_S bit is used to indicate if the
thread is in secure state. With the MSR_S bit, the privilege state of
the thread is now determined by MSR_S, MSR_HV and MSR_PR, as follows:

S   HV  PR
---
0   x   1   problem
1   0   1   problem
x   x   0   privileged
x   1   0   hypervisor
1   1   0   ultravisor
1   1   1   reserved

The hypervisor doesn't (and can't) run with the MSR_S bit set, but a
secure guest and the ultravisor firmware do.

Signed-off-by: Sukadev Bhattiprolu 
Signed-off-by: Ram Pai 
[ Update the commit message ]
Signed-off-by: Claudio Carvalho 
---
 arch/powerpc/include/asm/reg.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 10caa145f98b..39b4c0a519f5 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -38,6 +38,7 @@
 #define MSR_TM_LG  32  /* Trans Mem Available */
 #define MSR_VEC_LG 25  /* Enable AltiVec */
 #define MSR_VSX_LG 23  /* Enable VSX */
+#define MSR_S_LG   22  /* Secure VM bit */
 #define MSR_POW_LG 18  /* Enable Power Management */
 #define MSR_WE_LG  18  /* Wait State Enable */
 #define MSR_TGPR_LG17  /* TLB Update registers in use */
@@ -71,11 +72,13 @@
 #define MSR_SF __MASK(MSR_SF_LG)   /* Enable 64 bit mode */
 #define MSR_ISF__MASK(MSR_ISF_LG)  /* Interrupt 64b mode 
valid on 630 */
 #define MSR_HV __MASK(MSR_HV_LG)   /* Hypervisor state */
+#define MSR_S  __MASK(MSR_S_LG)/* Secure state */
 #else
 /* so tests for these bits fail on 32-bit */
 #define MSR_SF 0
 #define MSR_ISF0
 #define MSR_HV 0
+#define MSR_S  0
 #endif
 
 /*
-- 
2.20.1



[PATCH v4 0/8] kvmppc: Paravirtualize KVM to support ultravisor

2019-06-28 Thread Claudio Carvalho
POWER platforms that supports the Protected Execution Facility (PEF)
introduce features that combine hardware facilities and firmware to
enable secure virtual machines. That includes a new processor mode
(ultravisor mode) and the ultravisor firmware.

In PEF enabled systems, the ultravisor firmware runs at a privilege
level above the hypervisor and also takes control over some system
resources. The hypervisor, though, can make system calls to access these
resources. Such system calls, a.k.a. ucalls, are handled by the
ultravisor firmware.

The processor allows part of the system memory to be configured as
secure memory, and introduces a a new mode, called secure mode, where
any software entity in that mode can access secure memory. The
hypervisor doesn't (and can't) run in secure mode, but a secure guest
and the ultravisor firmware do.

This patch set adds support for ultravisor calls and do some preparation
for running secure guests.

---
Changelog:
---

v3->v4:

- Patch "KVM: PPC: Ultravisor: Add PPC_UV config option":
  - Moved to the patchset "kvmppc: HMM driver to manage pages of secure
guest" v5 that will be posted by Bharata Rao.

- Patch "powerpc: Introduce FW_FEATURE_ULTRAVISOR":
  - Changed to depend only on CONFIG_PPC_POWERNV.

- Patch "KVM: PPC: Ultravisor: Add generic ultravisor call handler":
  - Fixed whitespaces in ucall.S and in ultravisor-api.h.
  - Changed to depend only on CONFIG_PPC_POWERNV.
  - Changed the ucall wrapper to pass the ucall number in R3.

- Patch "KVM: PPC: Ultravisor: Use UV_WRITE_PATE ucall to register a
  PATE:
  - Changed to depend only on CONFIG_PPC_POWERNV.

- Patch "KVM: PPC: Ultravisor: Restrict LDBAR access":
  - Fixed comment in opal-imc.c to be "Disable IMC devices, when
Ultravisor is enabled.
  - Fixed signed-off-by.

- Patch "KVM: PPC: Ultravisor: Enter a secure guest":
  - Changed the UV_RETURN assembly call to save the actual R3 in
R0 for the ultravisor and pass the UV_RETURN call number in R3.

- Patch "KVM: PPC: Ultravisor: Check for MSR_S during hv_reset_msr":
  - Fixed commit message.

- Rebased to powerpc/next.

v2->v3:

- Squashed patches:
  - "KVM: PPC: Ultravisor: Return to UV for hcalls from SVM"
  - "KVM: PPC: Book3S HV: Fixed for running secure guests"
- Renamed patch from/to:
  - "KVM: PPC: Ultravisor: Return to UV for hcalls from SVM"
  - "KVM: PPC: Ultravisor: Enter a secure guest
- Rebased
- Addressed comments from Paul Mackerras
  - Dropped ultravisor checks made in power8 code
  - Updated the commit message for:
   "KVM: PPC: Ultravisor: Enter a secure guest"
- Addressed comments from Maddy
  - Dropped imc-pmu.c changes
- Changed opal-imc.c to fail the probe when the ultravisor is enabled
- Fixed "ucall defined but not used" issue when CONFIG_PPC_UV not set 

v1->v2:

- Addressed comments from Paul Mackerras:
  - Write the pate in HV's table before doing that in UV's
  - Renamed and better documented the ultravisor header files. Also added
all possible return codes for each ucall
  - Updated the commit message that introduces the MSR_S bit 
  - Moved ultravisor.c and ucall.S to arch/powerpc/kernel
  - Changed ucall.S to not save CR
- Rebased
- Changed the patches order
- Updated several commit messages
- Added FW_FEATURE_ULTRAVISOR to enable use of firmware_has_feature()
- Renamed CONFIG_PPC_KVM_UV to CONFIG_PPC_UV and used it to ifdef the ucall
  handler and the code that populates the powerpc_firmware_features for 
  ultravisor
- Exported the ucall symbol. KVM may be built as module.
- Restricted LDBAR access if the ultravisor firmware is available
- Dropped patches:
  - "[PATCH 06/13] KVM: PPC: Ultravisor: UV_RESTRICTED_SPR_WRITE ucall"
  - "[PATCH 07/13] KVM: PPC: Ultravisor: UV_RESTRICTED_SPR_READ ucall"
  - "[PATCH 08/13] KVM: PPC: Ultravisor: fix mtspr and mfspr"
- Squashed patches:
  - "[PATCH 09/13] KVM: PPC: Ultravisor: Return to UV for hcalls from SVM"
  - "[PATCH 13/13] KVM: PPC: UV: Have fast_guest_return check secure_guest"

Claudio Carvalho (2):
  powerpc: Introduce FW_FEATURE_ULTRAVISOR
  KVM: PPC: Ultravisor: Restrict LDBAR access

Michael Anderson (2):
  KVM: PPC: Ultravisor: Use UV_WRITE_PATE ucall to register a PATE
  KVM: PPC: Ultravisor: Check for MSR_S during hv_reset_msr

Ram Pai (2):
  KVM: PPC: Ultravisor: Add generic ultravisor call handler
  KVM: PPC: Ultravisor: Restrict flush of the partition tlb cache

Sukadev Bhattiprolu (2):
  KVM: PPC: Ultravisor: Introduce the MSR_S bit
  KVM: PPC: Ultravisor: Enter a secure guest

 arch/powerpc/include/asm/firmware.h   |  5 +-
 arch/powerpc/include/asm/kvm_host.h   |  1 +
 arch/powerpc/include/asm/reg.h|  3 ++
 arch/powerpc/include/asm/ultravisor-api.h | 24 +
 arch/powerpc/include/asm/ultravisor.h | 49 +
 arch/powerpc/kernel/Makefile  |  1 +
 arch/powerpc/kernel/asm-offsets.c |  1 +
 arch/powerpc/kernel/prom.c|  4 ++
 arch/powerpc/kernel/ucall.S   | 30 

[PATCH v4 2/8] powerpc: Introduce FW_FEATURE_ULTRAVISOR

2019-06-28 Thread Claudio Carvalho
This feature tells if the ultravisor firmware is available to handle
ucalls.

Signed-off-by: Claudio Carvalho 
[ Device node name to "ibm,ultravisor" ]
Signed-off-by: Michael Anderson 
---
 arch/powerpc/include/asm/firmware.h   |  5 +++--
 arch/powerpc/include/asm/ultravisor.h | 15 +++
 arch/powerpc/kernel/Makefile  |  1 +
 arch/powerpc/kernel/prom.c|  4 
 arch/powerpc/kernel/ultravisor.c  | 24 
 5 files changed, 47 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/include/asm/ultravisor.h
 create mode 100644 arch/powerpc/kernel/ultravisor.c

diff --git a/arch/powerpc/include/asm/firmware.h 
b/arch/powerpc/include/asm/firmware.h
index 00bc42d95679..43b48c4d3ca9 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -54,6 +54,7 @@
 #define FW_FEATURE_DRC_INFOASM_CONST(0x0008)
 #define FW_FEATURE_BLOCK_REMOVE ASM_CONST(0x0010)
 #define FW_FEATURE_PAPR_SCMASM_CONST(0x0020)
+#define FW_FEATURE_ULTRAVISOR  ASM_CONST(0x0040)
 
 #ifndef __ASSEMBLY__
 
@@ -72,9 +73,9 @@ enum {
FW_FEATURE_TYPE1_AFFINITY | FW_FEATURE_PRRN |
FW_FEATURE_HPT_RESIZE | FW_FEATURE_DRMEM_V2 |
FW_FEATURE_DRC_INFO | FW_FEATURE_BLOCK_REMOVE |
-   FW_FEATURE_PAPR_SCM,
+   FW_FEATURE_PAPR_SCM | FW_FEATURE_ULTRAVISOR,
FW_FEATURE_PSERIES_ALWAYS = 0,
-   FW_FEATURE_POWERNV_POSSIBLE = FW_FEATURE_OPAL,
+   FW_FEATURE_POWERNV_POSSIBLE = FW_FEATURE_OPAL | FW_FEATURE_ULTRAVISOR,
FW_FEATURE_POWERNV_ALWAYS = 0,
FW_FEATURE_PS3_POSSIBLE = FW_FEATURE_LPAR | FW_FEATURE_PS3_LV1,
FW_FEATURE_PS3_ALWAYS = FW_FEATURE_LPAR | FW_FEATURE_PS3_LV1,
diff --git a/arch/powerpc/include/asm/ultravisor.h 
b/arch/powerpc/include/asm/ultravisor.h
new file mode 100644
index ..e5009b0d84ea
--- /dev/null
+++ b/arch/powerpc/include/asm/ultravisor.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Ultravisor definitions
+ *
+ * Copyright 2019, IBM Corporation.
+ *
+ */
+#ifndef _ASM_POWERPC_ULTRAVISOR_H
+#define _ASM_POWERPC_ULTRAVISOR_H
+
+/* Internal functions */
+extern int early_init_dt_scan_ultravisor(unsigned long node, const char *uname,
+int depth, void *data);
+
+#endif /* _ASM_POWERPC_ULTRAVISOR_H */
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 0ea6c4aa3a20..f0caa302c8c0 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -154,6 +154,7 @@ endif
 
 obj-$(CONFIG_EPAPR_PARAVIRT)   += epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)+= kvm.o kvm_emul.o
+obj-$(CONFIG_PPC_POWERNV)  += ultravisor.o
 
 # Disable GCOV, KCOV & sanitizers in odd or sensitive code
 GCOV_PROFILE_prom_init.o := n
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 4221527b082f..67a2c1b39252 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -59,6 +59,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -706,6 +707,9 @@ void __init early_init_devtree(void *params)
 #ifdef CONFIG_PPC_POWERNV
/* Some machines might need OPAL info for debugging, grab it now. */
of_scan_flat_dt(early_init_dt_scan_opal, NULL);
+
+   /* Scan tree for ultravisor feature */
+   of_scan_flat_dt(early_init_dt_scan_ultravisor, NULL);
 #endif
 
 #ifdef CONFIG_FA_DUMP
diff --git a/arch/powerpc/kernel/ultravisor.c b/arch/powerpc/kernel/ultravisor.c
new file mode 100644
index ..dc6021f63c97
--- /dev/null
+++ b/arch/powerpc/kernel/ultravisor.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Ultravisor high level interfaces
+ *
+ * Copyright 2019, IBM Corporation.
+ *
+ */
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+int __init early_init_dt_scan_ultravisor(unsigned long node, const char *uname,
+int depth, void *data)
+{
+   if (depth != 1 || strcmp(uname, "ibm,ultravisor") != 0)
+   return 0;
+
+   powerpc_firmware_features |= FW_FEATURE_ULTRAVISOR;
+   pr_debug("Ultravisor detected!\n");
+   return 1;
+}
-- 
2.20.1



Re: [PATCH] powerpc/rtas: Fix hang in race against concurrent cpu offline

2019-06-28 Thread Juliet Kim


On 6/26/19 6:51 PM, Nathan Lynch wrote:
> Hi Juliet,
>
> Juliet Kim  writes:
>> On 6/25/19 12:29 PM, Nathan Lynch wrote:
>>> Juliet Kim  writes:
 However, that fix failed to notify Hypervisor that the LPM attempted
 had been abandoned which results in a system hang.
>>> It is surprising to me that leaving a migration unterminated would cause
>>> Linux to hang. Can you explain more about how that happens?
>>>
>> PHYP will block further requests(next partition migration, dlpar etc) while
>> it's in suspending state. That would have a follow-on effect on the HMC and
>> potentially this and other partitions.
> I can believe that operations on _this LPAR_ would be blocked by the
> platform and/or management console while the migration remains
> unterminated, but the OS should not be able to perpetrate a denial of
> service on other partitions or the management console simply by botching
> the LPM protocol. If it can, that's not Linux's bug to fix.
>
>
 Fix this by sending a signal PHYP to cancel the migration, so that PHYP
 can stop waiting, and clean up the migration.
>>> This is well-spotted and rtas_ibm_suspend_me() needs to signal
>>> cancellation in several error paths. But I don't agree that this is one
>>> of them: this race is going to be a temporary condition in any
>>> production setting, and retrying would allow the migration to
>>> succeed.
>> If LPM and CPU offine requests conflict with one another, it might be better
>> to let them fail and let the customer decide which he prefers.
> Hmm I don't think so. When (if ever) this happens in production it would
> be the result of an unlucky race with a power management daemon or
> similar, not a conscious decision of the administrator in the moment.
>
Guessing that a production race would only be against power mgmt is maybe
reasonable.  But we have an actual failure case where the race was against
an explicit offline request, and that's a legitimate/supported thing for
a customer to do.

>> IBM i cancels migration if the other OS components/operations veto
>> migration. It’s consistent with other OS behavior for LPM.
> But this situation isn't really like that. If we were to have a real
> veto mechanism, it would only make sense to have it run as early as
> possible, before the platform has done a bunch of work. This benign,
> recoverable race is occurring right before we complete the migration,
> which at this point has been copying state to the destination for
> minutes or hours. It doesn't make sense to error out like this.

Let me clarify that the cancellation is occurring in the phase preparing
for migration.It would be even better if it runs before LPM is allowed to make
a start. But that's what a long-term solution might look like.

> As I mentioned earlier though, it does make sense to signal a
> cancellation for these less-recoverable error conditions in
> rtas_ibm_suspend_me():
>
> - rtas_online_cpus_mask() failure
> - alloc_cpumask_var() failure
> - the atomic_read() != 0 case after returning from the IPI


Re: [PATCH v2] powerpc/pseries: Fix maximum memory value

2019-06-28 Thread Nathan Lynch
"Naveen N. Rao"  writes:
> Nathan Lynch wrote:
>> It would likely help with review and future maintenance if the semantics
>> and intended use of the MaxMem field are made a little more
>> explicit. For example, is it supposed to include persistent memory?
>> Perhaps a follow-up patch could address this. Or maybe I'm overthinking
>> it.
>
> This was primarily aimed to replicate what AIX lparstat does and 
> documentation (*) just says:
>
>   Maximum Memory
>   Maximum possible amount of Memory.
>
> I think this mirrors the maximum memory value set in the LPAR profile, 
> and this provides a way to obtain that value from within the LPAR.
>
> This doesn't necessarily answer your question, but that's at least the 
> reference.
>
> (*) 
> https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds3/lparstat.htm

Thanks for the reference. Consider my concern withdrawn.


Re: [PATCH v2] powerpc/pseries: Fix maximum memory value

2019-06-28 Thread Naveen N. Rao

Nathan Lynch wrote:

Aravinda Prasad  writes:

Calculating the maximum memory based on the number of lmbs
and lmb size does not account for the RMA region. Hence
use memory_hotplug_max(), which already accounts for the
RMA region, to fetch the maximum memory value. Thanks to
Nathan Lynch for suggesting the memory_hotplug_max()
function.


Well, I hope I haven't led you astray... will it give you the desired
result on a kernel configured without memory hotplug support, booted in
an LPAR with some huge pages configured?

If so, then
Acked-by: Nathan Lynch 

It would likely help with review and future maintenance if the semantics
and intended use of the MaxMem field are made a little more
explicit. For example, is it supposed to include persistent memory?
Perhaps a follow-up patch could address this. Or maybe I'm overthinking
it.


This was primarily aimed to replicate what AIX lparstat does and 
documentation (*) just says:


 Maximum Memory
 Maximum possible amount of Memory.

I think this mirrors the maximum memory value set in the LPAR profile, 
and this provides a way to obtain that value from within the LPAR.


This doesn't necessarily answer your question, but that's at least the 
reference.


(*) 
https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds3/lparstat.htm


- Naveen




Re: [PATCH v2] powerpc/pseries: Fix maximum memory value

2019-06-28 Thread Nathan Lynch
Aravinda Prasad  writes:
> Calculating the maximum memory based on the number of lmbs
> and lmb size does not account for the RMA region. Hence
> use memory_hotplug_max(), which already accounts for the
> RMA region, to fetch the maximum memory value. Thanks to
> Nathan Lynch for suggesting the memory_hotplug_max()
> function.

Well, I hope I haven't led you astray... will it give you the desired
result on a kernel configured without memory hotplug support, booted in
an LPAR with some huge pages configured?

If so, then
Acked-by: Nathan Lynch 

It would likely help with review and future maintenance if the semantics
and intended use of the MaxMem field are made a little more
explicit. For example, is it supposed to include persistent memory?
Perhaps a follow-up patch could address this. Or maybe I'm overthinking
it.



Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

2019-06-28 Thread Andreas Schwab
On Jun 28 2019, Christophe Leroy  wrote:

> Le 28/06/2019 à 18:36, Andreas Schwab a écrit :
>> On Jun 28 2019, Christophe Leroy  wrote:
>>
>>> diff --git a/arch/powerpc/include/uapi/asm/ptrace.h 
>>> b/arch/powerpc/include/uapi/asm/ptrace.h
>>> index f5f1ccc740fc..37d7befbb8dc 100644
>>> --- a/arch/powerpc/include/uapi/asm/ptrace.h
>>> +++ b/arch/powerpc/include/uapi/asm/ptrace.h
>>> @@ -43,12 +43,11 @@ struct pt_regs
>>> unsigned long link;
>>> unsigned long xer;
>>> unsigned long ccr;
>>> -#ifdef __powerpc64__
>>> -   unsigned long softe;/* Soft enabled/disabled */
>>> -#else
>>> -   unsigned long mq;   /* 601 only (not used at present) */
>>> +   union {
>>> +   unsigned long softe;/* Soft enabled/disabled */
>>> +   unsigned long mq;   /* 601 only (not used at present) */
>>> /* Used on APUS to hold IPL value. */
>>> -#endif
>>> +   };
>>
>> Anonymous unions are a C11 feature.
>>
>
> Is that a problem ?

Yes, this is a UAPI header.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

2019-06-28 Thread Christophe Leroy




Le 28/06/2019 à 18:36, Andreas Schwab a écrit :

On Jun 28 2019, Christophe Leroy  wrote:


diff --git a/arch/powerpc/include/uapi/asm/ptrace.h 
b/arch/powerpc/include/uapi/asm/ptrace.h
index f5f1ccc740fc..37d7befbb8dc 100644
--- a/arch/powerpc/include/uapi/asm/ptrace.h
+++ b/arch/powerpc/include/uapi/asm/ptrace.h
@@ -43,12 +43,11 @@ struct pt_regs
unsigned long link;
unsigned long xer;
unsigned long ccr;
-#ifdef __powerpc64__
-   unsigned long softe;/* Soft enabled/disabled */
-#else
-   unsigned long mq;   /* 601 only (not used at present) */
+   union {
+   unsigned long softe;/* Soft enabled/disabled */
+   unsigned long mq;   /* 601 only (not used at present) */
/* Used on APUS to hold IPL value. */
-#endif
+   };


Anonymous unions are a C11 feature.



Is that a problem ?

Kernel has a minimum GCC requirement of version 4.6, doesn't 4.6 support 
C11 ?


Christophe


Re: [RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

2019-06-28 Thread Andreas Schwab
On Jun 28 2019, Christophe Leroy  wrote:

> diff --git a/arch/powerpc/include/uapi/asm/ptrace.h 
> b/arch/powerpc/include/uapi/asm/ptrace.h
> index f5f1ccc740fc..37d7befbb8dc 100644
> --- a/arch/powerpc/include/uapi/asm/ptrace.h
> +++ b/arch/powerpc/include/uapi/asm/ptrace.h
> @@ -43,12 +43,11 @@ struct pt_regs
>   unsigned long link;
>   unsigned long xer;
>   unsigned long ccr;
> -#ifdef __powerpc64__
> - unsigned long softe;/* Soft enabled/disabled */
> -#else
> - unsigned long mq;   /* 601 only (not used at present) */
> + union {
> + unsigned long softe;/* Soft enabled/disabled */
> + unsigned long mq;   /* 601 only (not used at present) */
>   /* Used on APUS to hold IPL value. */
> -#endif
> + };

Anonymous unions are a C11 feature.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


[PATCH] powerpc/hw_breakpoint: move instruction stepping out of hw_breakpoint_handler()

2019-06-28 Thread Christophe Leroy
On 8xx, breakpoints stop after executing the instruction, so
stepping/emulation is not needed. Move it into a sub-function and
remove the #ifdefs.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/hw_breakpoint.c | 60 -
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kernel/hw_breakpoint.c 
b/arch/powerpc/kernel/hw_breakpoint.c
index a293a53b4365..a94142e729bf 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -198,15 +198,43 @@ void thread_change_pc(struct task_struct *tsk, struct 
pt_regs *regs)
 /*
  * Handle debug exception notifications.
  */
+static bool stepping_handler(struct pt_regs *regs, struct perf_event *bp,
+unsigned long addr)
+{
+   int stepped;
+   unsigned int instr;
+
+   /* Do not emulate user-space instructions, instead single-step them */
+   if (user_mode(regs)) {
+   current->thread.last_hit_ubp = bp;
+   regs->msr |= MSR_SE;
+   return false;
+   }
+
+   stepped = 0;
+   instr = 0;
+   if (!__get_user_inatomic(instr, (unsigned int *)regs->nip))
+   stepped = emulate_step(regs, instr);
+
+   /*
+* emulate_step() could not execute it. We've failed in reliably
+* handling the hw-breakpoint. Unregister it and throw a warning
+* message to let the user know about it.
+*/
+   if (!stepped) {
+   WARN(1, "Unable to handle hardware breakpoint. Breakpoint at "
+   "0x%lx will be disabled.", addr);
+   perf_event_disable_inatomic(bp);
+   return false;
+   }
+   return true;
+}
+
 int hw_breakpoint_handler(struct die_args *args)
 {
int rc = NOTIFY_STOP;
struct perf_event *bp;
struct pt_regs *regs = args->regs;
-#ifndef CONFIG_PPC_8xx
-   int stepped = 1;
-   unsigned int instr;
-#endif
struct arch_hw_breakpoint *info;
unsigned long dar = regs->dar;
 
@@ -251,32 +279,10 @@ int hw_breakpoint_handler(struct die_args *args)
  (dar - bp->attr.bp_addr < bp->attr.bp_len)))
info->type |= HW_BRK_TYPE_EXTRANEOUS_IRQ;
 
-#ifndef CONFIG_PPC_8xx
-   /* Do not emulate user-space instructions, instead single-step them */
-   if (user_mode(regs)) {
-   current->thread.last_hit_ubp = bp;
-   regs->msr |= MSR_SE;
+   if (!IS_ENABLED(CONFIG_PPC_8xx) && !stepping_handler(regs, bp, 
info->address))
goto out;
-   }
-
-   stepped = 0;
-   instr = 0;
-   if (!__get_user_inatomic(instr, (unsigned int *) regs->nip))
-   stepped = emulate_step(regs, instr);
 
/*
-* emulate_step() could not execute it. We've failed in reliably
-* handling the hw-breakpoint. Unregister it and throw a warning
-* message to let the user know about it.
-*/
-   if (!stepped) {
-   WARN(1, "Unable to handle hardware breakpoint. Breakpoint at "
-   "0x%lx will be disabled.", info->address);
-   perf_event_disable_inatomic(bp);
-   goto out;
-   }
-#endif
-   /*
 * As a policy, the callback is invoked in a 'trigger-after-execute'
 * fashion
 */
-- 
2.13.3



[RFC PATCH v2 12/12] powerpc/ptrace: move ptrace_triggered() into hw_breakpoint.c

2019-06-28 Thread Christophe Leroy
ptrace_triggered() is declared in asm/hw_breakpoint.h and
only needed when CONFIG_HW_BREAKPOINT is set, so move it
into hw_breakpoint.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/hw_breakpoint.c | 16 
 arch/powerpc/kernel/ptrace/ptrace.c | 18 --
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/kernel/hw_breakpoint.c 
b/arch/powerpc/kernel/hw_breakpoint.c
index a293a53b4365..b71d3837d673 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -367,6 +367,22 @@ void hw_breakpoint_pmu_read(struct perf_event *bp)
/* TODO */
 }
 
+void ptrace_triggered(struct perf_event *bp,
+ struct perf_sample_data *data, struct pt_regs *regs)
+{
+   struct perf_event_attr attr;
+
+   /*
+* Disable the breakpoint request here since ptrace has defined a
+* one-shot behaviour for breakpoint exceptions in PPC64.
+* The SIGTRAP signal is generated automatically for us in do_dabr().
+* We don't have to do anything about that here
+*/
+   attr = bp->attr;
+   attr.disabled = true;
+   modify_user_hw_breakpoint(bp, );
+}
+
 bool dawr_force_enable;
 EXPORT_SYMBOL_GPL(dawr_force_enable);
 
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c 
b/arch/powerpc/kernel/ptrace/ptrace.c
index 31e8c5a9171e..b85998b159d7 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -50,24 +50,6 @@
 
 #include 
 
-#ifdef CONFIG_HAVE_HW_BREAKPOINT
-void ptrace_triggered(struct perf_event *bp,
- struct perf_sample_data *data, struct pt_regs *regs)
-{
-   struct perf_event_attr attr;
-
-   /*
-* Disable the breakpoint request here since ptrace has defined a
-* one-shot behaviour for breakpoint exceptions in PPC64.
-* The SIGTRAP signal is generated automatically for us in do_dabr().
-* We don't have to do anything about that here
-*/
-   attr = bp->attr;
-   attr.disabled = true;
-   modify_user_hw_breakpoint(bp, );
-}
-#endif /* CONFIG_HAVE_HW_BREAKPOINT */
-
 /*
  * Called by kernel/ptrace.c when detaching..
  *
-- 
2.13.3



[RFC PATCH v2 11/12] powerpc/ptrace: create ppc_gethwdinfo()

2019-06-28 Thread Christophe Leroy
Create ippc_gethwdinfo() to handle PPC_PTRACE_GETHWDBGINFO and
reduce ifdef mess

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/ptrace-adv.c   | 15 +++
 arch/powerpc/kernel/ptrace/ptrace-decl.h  |  1 +
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 20 +++
 arch/powerpc/kernel/ptrace/ptrace.c   | 32 +--
 4 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace/ptrace-adv.c 
b/arch/powerpc/kernel/ptrace/ptrace-adv.c
index dcc765940344..f5f334484ebc 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-adv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-adv.c
@@ -83,6 +83,21 @@ void user_disable_single_step(struct task_struct *task)
clear_tsk_thread_flag(task, TIF_SINGLESTEP);
 }
 
+void ppc_gethwdinfo(struct ppc_debug_info *dbginfo)
+{
+   dbginfo->version = 1;
+   dbginfo->num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
+   dbginfo->num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
+   dbginfo->num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
+   dbginfo->data_bp_alignment = 4;
+   dbginfo->sizeof_condition = 4;
+   dbginfo->features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
+   PPC_DEBUG_FEATURE_INSN_BP_MASK;
+   if (IS_ENABLED(CONFIG_PPC_ADV_DEBUG_DAC_RANGE))
+   dbginfo->features |= PPC_DEBUG_FEATURE_DATA_BP_RANGE |
+PPC_DEBUG_FEATURE_DATA_BP_MASK;
+}
+
 int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
unsigned long __user *datalp)
 {
diff --git a/arch/powerpc/kernel/ptrace/ptrace-decl.h 
b/arch/powerpc/kernel/ptrace/ptrace-decl.h
index 4b4b6a1d508a..3c8a81999292 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-decl.h
+++ b/arch/powerpc/kernel/ptrace/ptrace-decl.h
@@ -176,6 +176,7 @@ int tm_cgpr32_set(struct task_struct *target, const struct 
user_regset *regset,
 extern const struct user_regset_view user_ppc_native_view;
 
 /* ptrace-(no)adv */
+void ppc_gethwdinfo(struct ppc_debug_info *dbginfo);
 int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
unsigned long __user *datalp);
 int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned 
long data);
diff --git a/arch/powerpc/kernel/ptrace/ptrace-noadv.c 
b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
index 985cca136f85..426fedd7ab6c 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-noadv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
@@ -64,6 +64,26 @@ void user_disable_single_step(struct task_struct *task)
clear_tsk_thread_flag(task, TIF_SINGLESTEP);
 }
 
+void ppc_gethwdinfo(struct ppc_debug_info *dbginfo)
+{
+   dbginfo->version = 1;
+   dbginfo->num_instruction_bps = 0;
+   if (ppc_breakpoint_available())
+   dbginfo->num_data_bps = 1;
+   else
+   dbginfo->num_data_bps = 0;
+   dbginfo->num_condition_regs = 0;
+   dbginfo->data_bp_alignment = sizeof(long);
+   dbginfo->sizeof_condition = 0;
+   if (IS_ENABLED(CONFIG_HAVE_HW_BREAKPOINT)) {
+   dbginfo->features = PPC_DEBUG_FEATURE_DATA_BP_RANGE;
+   if (dawr_enabled())
+   dbginfo->features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR;
+   } else {
+   dbginfo->features = 0;
+   }
+}
+
 int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
unsigned long __user *datalp)
 {
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c 
b/arch/powerpc/kernel/ptrace/ptrace.c
index e789afae6f56..31e8c5a9171e 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -159,37 +159,7 @@ long arch_ptrace(struct task_struct *child, long request,
case PPC_PTRACE_GETHWDBGINFO: {
struct ppc_debug_info dbginfo;
 
-   dbginfo.version = 1;
-#ifdef CONFIG_PPC_ADV_DEBUG_REGS
-   dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
-   dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
-   dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
-   dbginfo.data_bp_alignment = 4;
-   dbginfo.sizeof_condition = 4;
-   dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
-  PPC_DEBUG_FEATURE_INSN_BP_MASK;
-#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
-   dbginfo.features |=
-  PPC_DEBUG_FEATURE_DATA_BP_RANGE |
-  PPC_DEBUG_FEATURE_DATA_BP_MASK;
-#endif
-#else /* !CONFIG_PPC_ADV_DEBUG_REGS */
-   dbginfo.num_instruction_bps = 0;
-   if (ppc_breakpoint_available())
-   dbginfo.num_data_bps = 1;
-   else
-   dbginfo.num_data_bps = 0;
-   dbginfo.num_condition_regs = 0;
-   dbginfo.data_bp_alignment = sizeof(long);
-   

[RFC PATCH v2 09/12] powerpc/ptrace: split out ADV_DEBUG_REGS related functions.

2019-06-28 Thread Christophe Leroy
Move ADV_DEBUG_REGS functions out of ptrace.c, into
ptrace-adv.c and ptrace-noadv.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/Makefile   |   4 +
 arch/powerpc/kernel/ptrace/ptrace-adv.c   | 487 ++
 arch/powerpc/kernel/ptrace/ptrace-decl.h  |   5 +
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 258 
 arch/powerpc/kernel/ptrace/ptrace.c   | 652 --
 5 files changed, 754 insertions(+), 652 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-adv.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-noadv.c

diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
index 7addc5994bb9..e9d97c2d063e 100644
--- a/arch/powerpc/kernel/ptrace/Makefile
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -14,3 +14,7 @@ endif
 obj-$(CONFIG_ALTIVEC)  += ptrace-altivec.o
 obj-$(CONFIG_SPE)  += ptrace-spe.o
 obj-$(CONFIG_PPC_TRANSACTIONAL_MEM)+= ptrace-tm.o
+obj-$(CONFIG_PPC_ADV_DEBUG_REGS)   += ptrace-adv.o
+ifneq ($(CONFIG_PPC_ADV_DEBUG_REGS),y)
+obj-y  += ptrace-noadv.o
+endif
diff --git a/arch/powerpc/kernel/ptrace/ptrace-adv.c 
b/arch/powerpc/kernel/ptrace/ptrace-adv.c
new file mode 100644
index ..86e71fa6c5c8
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-adv.c
@@ -0,0 +1,487 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#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 
+#include 
+#include 
+#include 
+
+#include 
+
+void user_enable_single_step(struct task_struct *task)
+{
+   struct pt_regs *regs = task->thread.regs;
+
+   if (regs != NULL) {
+   task->thread.debug.dbcr0 &= ~DBCR0_BT;
+   task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC;
+   regs->msr |= MSR_DE;
+   }
+   set_tsk_thread_flag(task, TIF_SINGLESTEP);
+}
+
+void user_enable_block_step(struct task_struct *task)
+{
+   struct pt_regs *regs = task->thread.regs;
+
+   if (regs != NULL) {
+   task->thread.debug.dbcr0 &= ~DBCR0_IC;
+   task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT;
+   regs->msr |= MSR_DE;
+   }
+   set_tsk_thread_flag(task, TIF_SINGLESTEP);
+}
+
+void user_disable_single_step(struct task_struct *task)
+{
+   struct pt_regs *regs = task->thread.regs;
+
+   if (regs != NULL) {
+   /*
+* The logic to disable single stepping should be as
+* simple as turning off the Instruction Complete flag.
+* And, after doing so, if all debug flags are off, turn
+* off DBCR0(IDM) and MSR(DE)  Torez
+*/
+   task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT);
+   /*
+* Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
+*/
+   if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
+   task->thread.debug.dbcr1)) {
+   /*
+* All debug events were off.
+*/
+   task->thread.debug.dbcr0 &= ~DBCR0_IDM;
+   regs->msr &= ~MSR_DE;
+   }
+   }
+   clear_tsk_thread_flag(task, TIF_SINGLESTEP);
+}
+
+int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned 
long data)
+{
+   /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
+*  For embedded processors we support one DAC and no IAC's at the
+*  moment.
+*/
+   if (addr > 0)
+   return -EINVAL;
+
+   /* The bottom 3 bits in dabr are flags */
+   if ((data & ~0x7UL) >= TASK_SIZE)
+   return -EIO;
+
+   /* As described above, it was assumed 3 bits were passed with the data
+*  address, but we will assume only the mode bits will be passed
+*  as to not cause alignment restrictions for DAC-based processors.
+*/
+
+   /* DAC's hold the whole address without any mode flags */
+   task->thread.debug.dac1 = data & ~0x3UL;
+
+   if (task->thread.debug.dac1 == 0) {
+   dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
+   if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
+   task->thread.debug.dbcr1)) {
+   task->thread.regs->msr &= ~MSR_DE;
+   task->thread.debug.dbcr0 &= ~DBCR0_IDM;
+   }
+   return 0;
+   }
+
+   /* Read or Write bits must be set */
+
+   if (!(data & 0x3UL))
+   return -EINVAL;
+
+   /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
+  

[RFC PATCH v2 07/12] powerpc/ptrace: split out TRANSACTIONAL_MEM related functions.

2019-06-28 Thread Christophe Leroy
Move TRANSACTIONAL_MEM functions out of ptrace.c, into
ptrace-tm.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/Makefile  |   1 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h |  89 +++
 arch/powerpc/kernel/ptrace/ptrace-tm.c   | 879 +
 arch/powerpc/kernel/ptrace/ptrace.c  | 915 +--
 4 files changed, 971 insertions(+), 913 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-tm.c

diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
index f87eadf6e072..2d7f5f301536 100644
--- a/arch/powerpc/kernel/ptrace/Makefile
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -13,3 +13,4 @@ obj-y += ptrace-novsx.o
 endif
 obj-$(CONFIG_ALTIVEC)  += ptrace-altivec.o
 obj-$(CONFIG_SPE)  += ptrace-spe.o
+obj-$(CONFIG_PPC_TRANSACTIONAL_MEM)+= ptrace-tm.o
diff --git a/arch/powerpc/kernel/ptrace/ptrace-decl.h 
b/arch/powerpc/kernel/ptrace/ptrace-decl.h
index 8a362f97f1d6..8d076818f1de 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-decl.h
+++ b/arch/powerpc/kernel/ptrace/ptrace-decl.h
@@ -1,5 +1,27 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
+/*
+ * Set of msr bits that gdb can change on behalf of a process.
+ */
+#ifdef CONFIG_PPC_ADV_DEBUG_REGS
+#define MSR_DEBUGCHANGE0
+#else
+#define MSR_DEBUGCHANGE(MSR_SE | MSR_BE)
+#endif
+
+/*
+ * Max register writeable via put_reg
+ */
+#ifdef CONFIG_PPC32
+#define PT_MAX_PUT_REG PT_MQ
+#else
+#define PT_MAX_PUT_REG PT_CCR
+#endif
+
+#define TVSO(f)(offsetof(struct thread_vr_state, f))
+#define TFSO(f)(offsetof(struct thread_fp_state, f))
+#define TSO(f) (offsetof(struct thread_struct, f))
+
 /* ptrace-(no)vsx */
 
 int fpr_get(struct task_struct *target, const struct user_regset *regset,
@@ -37,8 +59,75 @@ int evr_set(struct task_struct *target, const struct 
user_regset *regset,
 
 /* ptrace */
 
+int gpr32_get_common(struct task_struct *target,
+const struct user_regset *regset,
+unsigned int pos, unsigned int count,
+   void *kbuf, void __user *ubuf,
+   unsigned long *regs);
+int gpr32_set_common(struct task_struct *target,
+const struct user_regset *regset,
+unsigned int pos, unsigned int count,
+const void *kbuf, const void __user *ubuf,
+unsigned long *regs);
+
+/* ptrace-tm */
+
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 void flush_tmregs_to_thread(struct task_struct *tsk);
 #else
 static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
 #endif
+
+int tm_cgpr_active(struct task_struct *target, const struct user_regset 
*regset);
+int tm_cgpr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int tm_cgpr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+int tm_cfpr_active(struct task_struct *target, const struct user_regset 
*regset);
+int tm_cfpr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int tm_cfpr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+int tm_cvmx_active(struct task_struct *target, const struct user_regset 
*regset);
+int tm_cvmx_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int tm_cvmx_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+int tm_cvsx_active(struct task_struct *target, const struct user_regset 
*regset);
+int tm_cvsx_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int tm_cvsx_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+int tm_spr_active(struct task_struct *target, const struct user_regset 
*regset);
+int tm_spr_get(struct task_struct *target, const struct user_regset *regset,
+  unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int tm_spr_set(struct task_struct *target, const struct user_regset *regset,
+  unsigned int pos, unsigned int count,
+  const void *kbuf, const void __user *ubuf);
+int tm_tar_active(struct task_struct *target, const struct user_regset 

[RFC PATCH v2 05/12] powerpc/ptrace: split out ALTIVEC related functions.

2019-06-28 Thread Christophe Leroy
Move CONFIG_ALTIVEC functions out of ptrace.c, into
ptrace-altivec.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/Makefile |   1 +
 arch/powerpc/kernel/ptrace/ptrace-altivec.c | 151 
 arch/powerpc/kernel/ptrace/ptrace-decl.h|   9 ++
 arch/powerpc/kernel/ptrace/ptrace.c | 124 ---
 4 files changed, 161 insertions(+), 124 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-altivec.c

diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
index 238c27189078..522e6fd0b5b8 100644
--- a/arch/powerpc/kernel/ptrace/Makefile
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_VSX) += ptrace-vsx.o
 ifneq ($(CONFIG_VSX),y)
 obj-y  += ptrace-novsx.o
 endif
+obj-$(CONFIG_ALTIVEC)  += ptrace-altivec.o
diff --git a/arch/powerpc/kernel/ptrace/ptrace-altivec.c 
b/arch/powerpc/kernel/ptrace/ptrace-altivec.c
new file mode 100644
index ..0cb749164269
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-altivec.c
@@ -0,0 +1,151 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#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 
+#include 
+#include 
+#include 
+
+/*
+ * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
+ * The transfer totals 34 quadword.  Quadwords 0-31 contain the
+ * corresponding vector registers.  Quadword 32 contains the vscr as the
+ * last word (offset 12) within that quadword.  Quadword 33 contains the
+ * vrsave as the first word (offset 0) within the quadword.
+ *
+ * This definition of the VMX state is compatible with the current PPC32
+ * ptrace interface.  This allows signal handling and ptrace to use the
+ * same structures.  This also simplifies the implementation of a bi-arch
+ * (combined (32- and 64-bit) gdb.
+ */
+
+int vr_active(struct task_struct *target, const struct user_regset *regset)
+{
+   flush_altivec_to_thread(target);
+   return target->thread.used_vr ? regset->n : 0;
+}
+
+/*
+ * Regardless of transactions, 'vr_state' holds the current running
+ * value of all the VMX registers and 'ckvr_state' holds the last
+ * checkpointed value of all the VMX registers for the current
+ * transaction to fall back on in case it aborts.
+ *
+ * Userspace interface buffer layout:
+ *
+ * struct data {
+ * vector128   vr[32];
+ * vector128   vscr;
+ * vector128   vrsave;
+ * };
+ */
+int vr_get(struct task_struct *target, const struct user_regset *regset,
+  unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf)
+{
+   int ret;
+
+   flush_altivec_to_thread(target);
+
+   BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
+offsetof(struct thread_vr_state, vr[32]));
+
+   ret = user_regset_copyout(, , , ,
+ >thread.vr_state, 0,
+ 33 * sizeof(vector128));
+   if (!ret) {
+   /*
+* Copy out only the low-order word of vrsave.
+*/
+   int start, end;
+   union {
+   elf_vrreg_t reg;
+   u32 word;
+   } vrsave;
+   memset(, 0, sizeof(vrsave));
+
+   vrsave.word = target->thread.vrsave;
+
+   start = 33 * sizeof(vector128);
+   end = start + sizeof(vrsave);
+   ret = user_regset_copyout(, , , , ,
+ start, end);
+   }
+
+   return ret;
+}
+
+/*
+ * Regardless of transactions, 'vr_state' holds the current running
+ * value of all the VMX registers and 'ckvr_state' holds the last
+ * checkpointed value of all the VMX registers for the current
+ * transaction to fall back on in case it aborts.
+ *
+ * Userspace interface buffer layout:
+ *
+ * struct data {
+ * vector128   vr[32];
+ * vector128   vscr;
+ * vector128   vrsave;
+ * };
+ */
+int vr_set(struct task_struct *target, const struct user_regset *regset,
+  unsigned int pos, unsigned int count,
+  const void *kbuf, const void __user *ubuf)
+{
+   int ret;
+
+   flush_altivec_to_thread(target);
+
+   BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
+offsetof(struct thread_vr_state, vr[32]));
+
+   ret = user_regset_copyin(, , , ,
+>thread.vr_state, 0,
+33 * sizeof(vector128));
+   if (!ret && count > 0) {
+   /*
+* We use only the first word of vrsave.
+*/
+   int start, end;
+   union {
+   

[RFC PATCH v2 10/12] powerpc/ptrace: create ptrace_get_debugreg()

2019-06-28 Thread Christophe Leroy
Create ptrace_get_debugreg() to handle PTRACE_GET_DEBUGREG and
reduce ifdef mess

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/ptrace-adv.c   |  9 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h  |  2 ++
 arch/powerpc/kernel/ptrace/ptrace-noadv.c | 13 +
 arch/powerpc/kernel/ptrace/ptrace.c   | 18 ++
 4 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace/ptrace-adv.c 
b/arch/powerpc/kernel/ptrace/ptrace-adv.c
index 86e71fa6c5c8..dcc765940344 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-adv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-adv.c
@@ -83,6 +83,15 @@ void user_disable_single_step(struct task_struct *task)
clear_tsk_thread_flag(task, TIF_SINGLESTEP);
 }
 
+int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
+   unsigned long __user *datalp)
+{
+   /* We only support one DABR and no IABRS at the moment */
+   if (addr > 0)
+   return -EINVAL;
+   return put_user(child->thread.debug.dac1, datalp);
+}
+
 int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned 
long data)
 {
/* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
diff --git a/arch/powerpc/kernel/ptrace/ptrace-decl.h 
b/arch/powerpc/kernel/ptrace/ptrace-decl.h
index bdba09a87aea..4b4b6a1d508a 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-decl.h
+++ b/arch/powerpc/kernel/ptrace/ptrace-decl.h
@@ -176,6 +176,8 @@ int tm_cgpr32_set(struct task_struct *target, const struct 
user_regset *regset,
 extern const struct user_regset_view user_ppc_native_view;
 
 /* ptrace-(no)adv */
+int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
+   unsigned long __user *datalp);
 int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned 
long data);
 long ppc_set_hwdebug(struct task_struct *child, struct ppc_hw_breakpoint 
*bp_info);
 long ppc_del_hwdebug(struct task_struct *child, long data);
diff --git a/arch/powerpc/kernel/ptrace/ptrace-noadv.c 
b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
index 7db330c94538..985cca136f85 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-noadv.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-noadv.c
@@ -64,6 +64,19 @@ void user_disable_single_step(struct task_struct *task)
clear_tsk_thread_flag(task, TIF_SINGLESTEP);
 }
 
+int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
+   unsigned long __user *datalp)
+{
+   unsigned long dabr_fake;
+
+   /* We only support one DABR and no IABRS at the moment */
+   if (addr > 0)
+   return -EINVAL;
+   dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
+(child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
+   return put_user(dabr_fake, datalp);
+}
+
 int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, unsigned 
long data)
 {
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c 
b/arch/powerpc/kernel/ptrace/ptrace.c
index 377e0e541d5f..e789afae6f56 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -211,23 +211,9 @@ long arch_ptrace(struct task_struct *child, long request,
break;
}
 
-   case PTRACE_GET_DEBUGREG: {
-#ifndef CONFIG_PPC_ADV_DEBUG_REGS
-   unsigned long dabr_fake;
-#endif
-   ret = -EINVAL;
-   /* We only support one DABR and no IABRS at the moment */
-   if (addr > 0)
-   break;
-#ifdef CONFIG_PPC_ADV_DEBUG_REGS
-   ret = put_user(child->thread.debug.dac1, datalp);
-#else
-   dabr_fake = ((child->thread.hw_brk.address & 
(~HW_BRK_TYPE_DABR)) |
-(child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
-   ret = put_user(dabr_fake, datalp);
-#endif
+   case PTRACE_GET_DEBUGREG:
+   ret = ptrace_get_debugreg(child, addr, datalp);
break;
-   }
 
case PTRACE_SET_DEBUGREG:
ret = ptrace_set_debugreg(child, addr, data);
-- 
2.13.3



[RFC PATCH v2 06/12] powerpc/ptrace: split out SPE related functions.

2019-06-28 Thread Christophe Leroy
Move CONFIG_SPE functions out of ptrace.c, into
ptrace-spe.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/Makefile  |  1 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h |  9 
 arch/powerpc/kernel/ptrace/ptrace-spe.c  | 92 
 arch/powerpc/kernel/ptrace/ptrace.c  | 66 ---
 4 files changed, 102 insertions(+), 66 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-spe.c

diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
index 522e6fd0b5b8..f87eadf6e072 100644
--- a/arch/powerpc/kernel/ptrace/Makefile
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -12,3 +12,4 @@ ifneq ($(CONFIG_VSX),y)
 obj-y  += ptrace-novsx.o
 endif
 obj-$(CONFIG_ALTIVEC)  += ptrace-altivec.o
+obj-$(CONFIG_SPE)  += ptrace-spe.o
diff --git a/arch/powerpc/kernel/ptrace/ptrace-decl.h 
b/arch/powerpc/kernel/ptrace/ptrace-decl.h
index 0f9282cb52fc..8a362f97f1d6 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-decl.h
+++ b/arch/powerpc/kernel/ptrace/ptrace-decl.h
@@ -26,6 +26,15 @@ int vr_set(struct task_struct *target, const struct 
user_regset *regset,
   unsigned int pos, unsigned int count,
   const void *kbuf, const void __user *ubuf);
 
+/* ptrace-spe */
+
+int evr_active(struct task_struct *target, const struct user_regset *regset);
+int evr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int evr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+
 /* ptrace */
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
diff --git a/arch/powerpc/kernel/ptrace/ptrace-spe.c 
b/arch/powerpc/kernel/ptrace/ptrace-spe.c
new file mode 100644
index ..b286fdf20feb
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-spe.c
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#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 
+#include 
+#include 
+#include 
+
+/*
+ * For get_evrregs/set_evrregs functions 'data' has the following layout:
+ *
+ * struct {
+ *   u32 evr[32];
+ *   u64 acc;
+ *   u32 spefscr;
+ * }
+ */
+
+int evr_active(struct task_struct *target, const struct user_regset *regset)
+{
+   flush_spe_to_thread(target);
+   return target->thread.used_spe ? regset->n : 0;
+}
+
+int evr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf)
+{
+   int ret;
+
+   flush_spe_to_thread(target);
+
+   ret = user_regset_copyout(, , , ,
+ >thread.evr,
+ 0, sizeof(target->thread.evr));
+
+   BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
+offsetof(struct thread_struct, spefscr));
+
+   if (!ret)
+   ret = user_regset_copyout(, , , ,
+ >thread.acc,
+ sizeof(target->thread.evr), -1);
+
+   return ret;
+}
+
+int evr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf)
+{
+   int ret;
+
+   flush_spe_to_thread(target);
+
+   ret = user_regset_copyin(, , , ,
+>thread.evr,
+0, sizeof(target->thread.evr));
+
+   BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
+offsetof(struct thread_struct, spefscr));
+
+   if (!ret)
+   ret = user_regset_copyin(, , , ,
+>thread.acc,
+sizeof(target->thread.evr), -1);
+
+   return ret;
+}
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c 
b/arch/powerpc/kernel/ptrace/ptrace.c
index 198ccbfce544..711cccdc14e4 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -415,72 +415,6 @@ static int gpr_set(struct task_struct *target, const 
struct user_regset *regset,
return ret;
 }
 
-#ifdef CONFIG_SPE
-
-/*
- * For get_evrregs/set_evrregs functions 'data' has the following layout:
- *
- * struct {
- *   u32 evr[32];
- *   u64 acc;
- *   u32 spefscr;
- * }
- */
-
-static int evr_active(struct task_struct *target,
- const struct user_regset *regset)
-{
-   flush_spe_to_thread(target);
-   return target->thread.used_spe ? regset->n : 0;
-}
-
-static int evr_get(struct task_struct 

[RFC PATCH v2 08/12] powerpc/ptrace: move register viewing functions out of ptrace.c

2019-06-28 Thread Christophe Leroy
Create a dedicated ptrace-view.c file.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/Makefile  |   4 +-
 arch/powerpc/kernel/ptrace/ptrace-decl.h |  43 ++
 arch/powerpc/kernel/ptrace/ptrace-view.c | 953 ++
 arch/powerpc/kernel/ptrace/ptrace.c  | 960 ---
 4 files changed, 998 insertions(+), 962 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-view.c

diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
index 2d7f5f301536..7addc5994bb9 100644
--- a/arch/powerpc/kernel/ptrace/Makefile
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -3,9 +3,9 @@
 # Makefile for the linux kernel.
 #
 
-CFLAGS_ptrace.o+= -DUTS_MACHINE='"$(UTS_MACHINE)"'
+CFLAGS_ptrace-view.o   += -DUTS_MACHINE='"$(UTS_MACHINE)"'
 
-obj-y  += ptrace.o
+obj-y  += ptrace.o ptrace-view.o
 obj-$(CONFIG_PPC64)+= ptrace32.o
 obj-$(CONFIG_VSX)  += ptrace-vsx.o
 ifneq ($(CONFIG_VSX),y)
diff --git a/arch/powerpc/kernel/ptrace/ptrace-decl.h 
b/arch/powerpc/kernel/ptrace/ptrace-decl.h
index 8d076818f1de..e12f6615fc1d 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-decl.h
+++ b/arch/powerpc/kernel/ptrace/ptrace-decl.h
@@ -22,6 +22,45 @@
 #define TFSO(f)(offsetof(struct thread_fp_state, f))
 #define TSO(f) (offsetof(struct thread_struct, f))
 
+/*
+ * These are our native regset flavors.
+ */
+enum powerpc_regset {
+   REGSET_GPR,
+   REGSET_FPR,
+#ifdef CONFIG_ALTIVEC
+   REGSET_VMX,
+#endif
+#ifdef CONFIG_VSX
+   REGSET_VSX,
+#endif
+#ifdef CONFIG_SPE
+   REGSET_SPE,
+#endif
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+   REGSET_TM_CGPR, /* TM checkpointed GPR registers */
+   REGSET_TM_CFPR, /* TM checkpointed FPR registers */
+   REGSET_TM_CVMX, /* TM checkpointed VMX registers */
+   REGSET_TM_CVSX, /* TM checkpointed VSX registers */
+   REGSET_TM_SPR,  /* TM specific SPR registers */
+   REGSET_TM_CTAR, /* TM checkpointed TAR register */
+   REGSET_TM_CPPR, /* TM checkpointed PPR register */
+   REGSET_TM_CDSCR,/* TM checkpointed DSCR register */
+#endif
+#ifdef CONFIG_PPC64
+   REGSET_PPR, /* PPR register */
+   REGSET_DSCR,/* DSCR register */
+#endif
+#ifdef CONFIG_PPC_BOOK3S_64
+   REGSET_TAR, /* TAR register */
+   REGSET_EBB, /* EBB registers */
+   REGSET_PMR, /* Performance Monitor Registers */
+#endif
+#ifdef CONFIG_PPC_MEM_KEYS
+   REGSET_PKEY,/* AMR register */
+#endif
+};
+
 /* ptrace-(no)vsx */
 
 int fpr_get(struct task_struct *target, const struct user_regset *regset,
@@ -131,3 +170,7 @@ int tm_cgpr32_get(struct task_struct *target, const struct 
user_regset *regset,
 int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,
  unsigned int pos, unsigned int count,
  const void *kbuf, const void __user *ubuf);
+
+/* ptrace-view */
+
+extern const struct user_regset_view user_ppc_native_view;
diff --git a/arch/powerpc/kernel/ptrace/ptrace-view.c 
b/arch/powerpc/kernel/ptrace/ptrace-view.c
new file mode 100644
index ..d24050e503da
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-view.c
@@ -0,0 +1,953 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#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 
+#include 
+#include 
+#include 
+
+#include 
+
+struct pt_regs_offset {
+   const char *name;
+   int 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}
+
+static const struct pt_regs_offset regoffset_table[] = {
+   GPR_OFFSET_NAME(0),
+   GPR_OFFSET_NAME(1),
+   GPR_OFFSET_NAME(2),
+   GPR_OFFSET_NAME(3),
+   GPR_OFFSET_NAME(4),
+   GPR_OFFSET_NAME(5),
+   GPR_OFFSET_NAME(6),
+   GPR_OFFSET_NAME(7),
+   GPR_OFFSET_NAME(8),
+   GPR_OFFSET_NAME(9),
+   GPR_OFFSET_NAME(10),
+   GPR_OFFSET_NAME(11),
+   GPR_OFFSET_NAME(12),
+   GPR_OFFSET_NAME(13),
+   GPR_OFFSET_NAME(14),
+   GPR_OFFSET_NAME(15),
+   GPR_OFFSET_NAME(16),
+   GPR_OFFSET_NAME(17),
+   GPR_OFFSET_NAME(18),
+   GPR_OFFSET_NAME(19),
+   GPR_OFFSET_NAME(20),
+   GPR_OFFSET_NAME(21),
+   GPR_OFFSET_NAME(22),
+   

[RFC PATCH v2 02/12] powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64

2019-06-28 Thread Christophe Leroy
Drop a bunch of #ifdefs CONFIG_PPC64 that are not vital.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/ptrace.h  |  9 -
 arch/powerpc/include/uapi/asm/ptrace.h | 12 
 arch/powerpc/kernel/ptrace/ptrace.c| 24 +++-
 3 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index faa5a338ac5a..1506a9c61d50 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -36,11 +36,10 @@ struct pt_regs
unsigned long link;
unsigned long xer;
unsigned long ccr;
-#ifdef CONFIG_PPC64
-   unsigned long softe;
-#else
-   unsigned long mq;
-#endif
+   union {
+   unsigned long softe;
+   unsigned long mq;
+   };
unsigned long trap;
unsigned long dar;
unsigned long dsisr;
diff --git a/arch/powerpc/include/uapi/asm/ptrace.h 
b/arch/powerpc/include/uapi/asm/ptrace.h
index f5f1ccc740fc..37d7befbb8dc 100644
--- a/arch/powerpc/include/uapi/asm/ptrace.h
+++ b/arch/powerpc/include/uapi/asm/ptrace.h
@@ -43,12 +43,11 @@ struct pt_regs
unsigned long link;
unsigned long xer;
unsigned long ccr;
-#ifdef __powerpc64__
-   unsigned long softe;/* Soft enabled/disabled */
-#else
-   unsigned long mq;   /* 601 only (not used at present) */
+   union {
+   unsigned long softe;/* Soft enabled/disabled */
+   unsigned long mq;   /* 601 only (not used at present) */
/* Used on APUS to hold IPL value. */
-#endif
+   };
unsigned long trap; /* Reason for being here */
/* N.B. for critical exceptions on 4xx, the dar and dsisr
   fields are overloaded to hold srr0 and srr1. */
@@ -105,11 +104,8 @@ struct pt_regs
 #define PT_LNK 36
 #define PT_XER 37
 #define PT_CCR 38
-#ifndef __powerpc64__
 #define PT_MQ  39
-#else
 #define PT_SOFTE 39
-#endif
 #define PT_TRAP40
 #define PT_DAR 41
 #define PT_DSISR 42
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c 
b/arch/powerpc/kernel/ptrace/ptrace.c
index 684b0b315c32..0afb223c4d57 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -113,11 +113,8 @@ static const struct pt_regs_offset regoffset_table[] = {
REG_OFFSET_NAME(link),
REG_OFFSET_NAME(xer),
REG_OFFSET_NAME(ccr),
-#ifdef CONFIG_PPC64
REG_OFFSET_NAME(softe),
-#else
REG_OFFSET_NAME(mq),
-#endif
REG_OFFSET_NAME(trap),
REG_OFFSET_NAME(dar),
REG_OFFSET_NAME(dsisr),
@@ -289,17 +286,15 @@ int ptrace_get_reg(struct task_struct *task, int regno, 
unsigned long *data)
if (regno == PT_DSCR)
return get_user_dscr(task, data);
 
-#ifdef CONFIG_PPC64
/*
 * softe copies paca->irq_soft_mask variable state. Since irq_soft_mask 
is
 * no more used as a flag, lets force usr to alway see the softe value 
as 1
 * which means interrupts are not soft disabled.
 */
-   if (regno == PT_SOFTE) {
+   if (IS_ENABLED(CONFIG_PPC64) && regno == PT_SOFTE) {
*data = 1;
return  0;
}
-#endif
 
regs_max = sizeof(struct user_pt_regs) / sizeof(unsigned long);
if (regno < regs_max) {
@@ -2013,7 +2008,6 @@ static const struct user_regset_view user_ppc_native_view 
= {
.regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
 };
 
-#ifdef CONFIG_PPC64
 #include 
 
 static int gpr32_get_common(struct task_struct *target,
@@ -2287,14 +2281,11 @@ static const struct user_regset_view 
user_ppc_compat_view = {
.name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
.regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
 };
-#endif /* CONFIG_PPC64 */
 
 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 {
-#ifdef CONFIG_PPC64
-   if (test_tsk_thread_flag(task, TIF_32BIT))
+   if (IS_ENABLED(CONFIG_PPC64) && test_tsk_thread_flag(task, TIF_32BIT))
return _ppc_compat_view;
-#endif
return _ppc_native_view;
 }
 
@@ -3081,11 +3072,7 @@ long arch_ptrace(struct task_struct *child, long request,
else
dbginfo.num_data_bps = 0;
dbginfo.num_condition_regs = 0;
-#ifdef CONFIG_PPC64
-   dbginfo.data_bp_alignment = 8;
-#else
-   dbginfo.data_bp_alignment = 4;
-#endif
+   dbginfo.data_bp_alignment = sizeof(long);
dbginfo.sizeof_condition = 0;
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE;
@@ -3322,12 +3309,10 

[RFC PATCH v2 00/12] Reduce ifdef mess in ptrace

2019-06-28 Thread Christophe Leroy
The purpose of this series is to reduce the amount of #ifdefs
in ptrace.c

This is a first try. Most of it is done, there are still some #ifdefs that
could go away.

Please comment and tell whether it is worth continuing in that direction.

v2:
- Fixed several build failures. Now builts cleanly on kisskb, see 
http://kisskb.ellerman.id.au/kisskb/head/840e53cf913d6096dd60181a085f102c85d6e526/
- Droped last patch which is not related to ptrace and can be applies 
independently.

Christophe Leroy (12):
  powerpc: move ptrace into a subdirectory.
  powerpc/ptrace: drop unnecessary #ifdefs CONFIG_PPC64
  powerpc/ptrace: drop PARAMETER_SAVE_AREA_OFFSET
  powerpc/ptrace: split out VSX related functions.
  powerpc/ptrace: split out ALTIVEC related functions.
  powerpc/ptrace: split out SPE related functions.
  powerpc/ptrace: split out TRANSACTIONAL_MEM related functions.
  powerpc/ptrace: move register viewing functions out of ptrace.c
  powerpc/ptrace: split out ADV_DEBUG_REGS related functions.
  powerpc/ptrace: create ptrace_get_debugreg()
  powerpc/ptrace: create ppc_gethwdinfo()
  powerpc/ptrace: move ptrace_triggered() into hw_breakpoint.c

 arch/powerpc/include/asm/ptrace.h   |9 +-
 arch/powerpc/include/uapi/asm/ptrace.h  |   12 +-
 arch/powerpc/kernel/Makefile|7 +-
 arch/powerpc/kernel/hw_breakpoint.c |   16 +
 arch/powerpc/kernel/ptrace.c| 3402 ---
 arch/powerpc/kernel/ptrace/Makefile |   20 +
 arch/powerpc/kernel/ptrace/ptrace-adv.c |  511 
 arch/powerpc/kernel/ptrace/ptrace-altivec.c |  151 ++
 arch/powerpc/kernel/ptrace/ptrace-decl.h|  184 ++
 arch/powerpc/kernel/ptrace/ptrace-noadv.c   |  291 +++
 arch/powerpc/kernel/ptrace/ptrace-novsx.c   |   83 +
 arch/powerpc/kernel/ptrace/ptrace-spe.c |   92 +
 arch/powerpc/kernel/ptrace/ptrace-tm.c  |  879 +++
 arch/powerpc/kernel/ptrace/ptrace-view.c|  953 
 arch/powerpc/kernel/ptrace/ptrace-vsx.c |  177 ++
 arch/powerpc/kernel/ptrace/ptrace.c |  430 
 arch/powerpc/kernel/{ => ptrace}/ptrace32.c |0
 17 files changed, 3798 insertions(+), 3419 deletions(-)
 delete mode 100644 arch/powerpc/kernel/ptrace.c
 create mode 100644 arch/powerpc/kernel/ptrace/Makefile
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-adv.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-altivec.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-decl.h
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-noadv.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-novsx.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-spe.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-tm.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-view.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-vsx.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace.c
 rename arch/powerpc/kernel/{ => ptrace}/ptrace32.c (100%)

-- 
2.13.3



[RFC PATCH v2 04/12] powerpc/ptrace: split out VSX related functions.

2019-06-28 Thread Christophe Leroy
Move CONFIG_VSX functions out of ptrace.c, into
ptrace-vsx.c and ptrace-novsx.c

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/Makefile   |   4 +
 arch/powerpc/kernel/ptrace/ptrace-decl.h  |  26 +
 arch/powerpc/kernel/ptrace/ptrace-novsx.c |  83 ++
 arch/powerpc/kernel/ptrace/ptrace-vsx.c   | 177 ++
 arch/powerpc/kernel/ptrace/ptrace.c   | 175 +
 5 files changed, 293 insertions(+), 172 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-decl.h
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-novsx.c
 create mode 100644 arch/powerpc/kernel/ptrace/ptrace-vsx.c

diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
index 02fb28eb3b55..238c27189078 100644
--- a/arch/powerpc/kernel/ptrace/Makefile
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -7,3 +7,7 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'
 
 obj-y  += ptrace.o
 obj-$(CONFIG_PPC64)+= ptrace32.o
+obj-$(CONFIG_VSX)  += ptrace-vsx.o
+ifneq ($(CONFIG_VSX),y)
+obj-y  += ptrace-novsx.o
+endif
diff --git a/arch/powerpc/kernel/ptrace/ptrace-decl.h 
b/arch/powerpc/kernel/ptrace/ptrace-decl.h
new file mode 100644
index ..764df4ee9362
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-decl.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* ptrace-(no)vsx */
+
+int fpr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int fpr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+
+/* ptrace-vsx */
+
+int vsr_active(struct task_struct *target, const struct user_regset *regset);
+int vsr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user 
*ubuf);
+int vsr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf);
+
+/* ptrace */
+
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+void flush_tmregs_to_thread(struct task_struct *tsk);
+#else
+static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
+#endif
diff --git a/arch/powerpc/kernel/ptrace/ptrace-novsx.c 
b/arch/powerpc/kernel/ptrace/ptrace-novsx.c
new file mode 100644
index ..55fbbb4aa9d7
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-novsx.c
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#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 
+#include 
+#include 
+#include 
+
+#include 
+
+/*
+ * Regardless of transactions, 'fp_state' holds the current running
+ * value of all FPR registers and 'ckfp_state' holds the last checkpointed
+ * value of all FPR registers for the current transaction.
+ *
+ * Userspace interface buffer layout:
+ *
+ * struct data {
+ * u64 fpr[32];
+ * u64 fpscr;
+ * };
+ */
+int fpr_get(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf)
+{
+   BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
+offsetof(struct thread_fp_state, fpr[32]));
+
+   flush_fp_to_thread(target);
+
+   return user_regset_copyout(, , , ,
+  >thread.fp_state, 0, -1);
+}
+
+/*
+ * Regardless of transactions, 'fp_state' holds the current running
+ * value of all FPR registers and 'ckfp_state' holds the last checkpointed
+ * value of all FPR registers for the current transaction.
+ *
+ * Userspace interface buffer layout:
+ *
+ * struct data {
+ * u64 fpr[32];
+ * u64 fpscr;
+ * };
+ *
+ */
+int fpr_set(struct task_struct *target, const struct user_regset *regset,
+   unsigned int pos, unsigned int count,
+   const void *kbuf, const void __user *ubuf)
+{
+   BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
+offsetof(struct thread_fp_state, fpr[32]));
+
+   flush_fp_to_thread(target);
+
+   return user_regset_copyin(, , , ,
+ >thread.fp_state, 0, -1);
+}
diff --git a/arch/powerpc/kernel/ptrace/ptrace-vsx.c 
b/arch/powerpc/kernel/ptrace/ptrace-vsx.c
new file mode 100644
index ..1d94210cdf63
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/ptrace-vsx.c
@@ -0,0 +1,177 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

[RFC PATCH v2 01/12] powerpc: move ptrace into a subdirectory.

2019-06-28 Thread Christophe Leroy
In order to allow splitting of ptrace depending on the
different CONFIG_ options, create a subdirectory dedicated to
ptrace and move ptrace.c and ptrace32.c into it.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/Makefile| 7 +++
 arch/powerpc/kernel/ptrace/Makefile | 9 +
 arch/powerpc/kernel/{ => ptrace}/ptrace.c   | 0
 arch/powerpc/kernel/{ => ptrace}/ptrace32.c | 0
 4 files changed, 12 insertions(+), 4 deletions(-)
 create mode 100644 arch/powerpc/kernel/ptrace/Makefile
 rename arch/powerpc/kernel/{ => ptrace}/ptrace.c (100%)
 rename arch/powerpc/kernel/{ => ptrace}/ptrace32.c (100%)

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 0ea6c4aa3a20..c522464fa56a 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -3,8 +3,6 @@
 # Makefile for the linux kernel.
 #
 
-CFLAGS_ptrace.o+= -DUTS_MACHINE='"$(UTS_MACHINE)"'
-
 # Disable clang warning for using setjmp without setjmp.h header
 CFLAGS_crash.o += $(call cc-disable-warning, builtin-requires-header)
 
@@ -43,15 +41,16 @@ CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING
 CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING
 endif
 
-obj-y  := cputable.o ptrace.o syscalls.o \
+obj-y  := cputable.o syscalls.o \
   irq.o align.o signal_32.o pmc.o vdso.o \
   process.o systbl.o idle.o \
   signal.o sysfs.o cacheinfo.o time.o \
   prom.o traps.o setup-common.o \
   udbg.o misc.o io.o misc_$(BITS).o \
   of_platform.o prom_parse.o
+obj-y  += ptrace/
 obj-$(CONFIG_PPC64)+= setup_64.o sys_ppc32.o \
-  signal_64.o ptrace32.o \
+  signal_64.o \
   paca.o nvram_64.o firmware.o
 obj-$(CONFIG_VDSO32)   += vdso32/
 obj-$(CONFIG_PPC_WATCHDOG) += watchdog.o
diff --git a/arch/powerpc/kernel/ptrace/Makefile 
b/arch/powerpc/kernel/ptrace/Makefile
new file mode 100644
index ..02fb28eb3b55
--- /dev/null
+++ b/arch/powerpc/kernel/ptrace/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the linux kernel.
+#
+
+CFLAGS_ptrace.o+= -DUTS_MACHINE='"$(UTS_MACHINE)"'
+
+obj-y  += ptrace.o
+obj-$(CONFIG_PPC64)+= ptrace32.o
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace/ptrace.c
similarity index 100%
rename from arch/powerpc/kernel/ptrace.c
rename to arch/powerpc/kernel/ptrace/ptrace.c
diff --git a/arch/powerpc/kernel/ptrace32.c 
b/arch/powerpc/kernel/ptrace/ptrace32.c
similarity index 100%
rename from arch/powerpc/kernel/ptrace32.c
rename to arch/powerpc/kernel/ptrace/ptrace32.c
-- 
2.13.3



[RFC PATCH v2 03/12] powerpc/ptrace: drop PARAMETER_SAVE_AREA_OFFSET

2019-06-28 Thread Christophe Leroy
PARAMETER_SAVE_AREA_OFFSET is not used, drop it.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/ptrace/ptrace.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace/ptrace.c 
b/arch/powerpc/kernel/ptrace/ptrace.c
index 0afb223c4d57..cc8efcb404d6 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -48,16 +48,6 @@
 #define CREATE_TRACE_POINTS
 #include 
 
-/*
- * The parameter save area on the stack is used to store arguments being passed
- * to callee function and is located at fixed offset from stack pointer.
- */
-#ifdef CONFIG_PPC32
-#define PARAMETER_SAVE_AREA_OFFSET 24  /* bytes */
-#else /* CONFIG_PPC32 */
-#define PARAMETER_SAVE_AREA_OFFSET 48  /* bytes */
-#endif
-
 struct pt_regs_offset {
const char *name;
int offset;
-- 
2.13.3



[PATCH v3] powerpc/setup_64: fix -Wempty-body warnings

2019-06-28 Thread Qian Cai
At the beginning of setup_64.c, it has,

  #ifdef DEBUG
  #define DBG(fmt...) udbg_printf(fmt)
  #else
  #define DBG(fmt...)
  #endif

where DBG() could be compiled away, and generate warnings,

arch/powerpc/kernel/setup_64.c: In function 'initialize_cache_info':
arch/powerpc/kernel/setup_64.c:579:49: warning: suggest braces around
empty body in an 'if' statement [-Wempty-body]
DBG("Argh, can't find dcache properties !\n");
 ^
arch/powerpc/kernel/setup_64.c:582:49: warning: suggest braces around
empty body in an 'if' statement [-Wempty-body]
DBG("Argh, can't find icache properties !\n");

Fix it by using the no_printk() macro, and make sure that format and
argument are always verified by the compiler.

Suggested-by: Tyrel Datwyler 
Suggested-by: Joe Perches 
Signed-off-by: Qian Cai 
---

v3: Use no_printk() macro, and make sure that format and argument are always
verified by the compiler using a more generic form ##__VA_ARGS__ per Joe.

v2: Fix it by using a NOP while loop per Tyrel.

 arch/powerpc/kernel/setup_64.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 44b4c432a273..cea933a43f0a 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -69,9 +69,9 @@
 #include "setup.h"
 
 #ifdef DEBUG
-#define DBG(fmt...) udbg_printf(fmt)
+#define DBG(fmt, ...) udbg_printf(fmt, ##__VA_ARGS__)
 #else
-#define DBG(fmt...)
+#define DBG(fmt, ...) no_printk(fmt, ##__VA_ARGS__)
 #endif
 
 int spinning_secondaries;
-- 
1.8.3.1



Re: power9 NUMA crash while reading debugfs imc_cmd

2019-06-28 Thread Qian Cai
On Fri, 2019-06-28 at 17:19 +0530, Anju T Sudhakar wrote:
> On 6/28/19 9:04 AM, Qian Cai wrote:
> > 
> > > On Jun 27, 2019, at 11:12 PM, Michael Ellerman  
> > > wrote:
> > > 
> > > Qian Cai  writes:
> > > > Read of debugfs imc_cmd file for a memory-less node will trigger a crash
> > > > below
> > > > on this power9 machine which has the following NUMA layout.
> > > 
> > > What type of machine is it?
> > 
> > description: PowerNV
> > product: 8335-GTH (ibm,witherspoon)
> > vendor: IBM
> > width: 64 bits
> > capabilities: smp powernv opal
> 
> 
> Hi Qian Cai,
> 
> Could you please try with this patch: 
> https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-June/192803.html
> 
> and see if the issue is resolved?

It works fine.

Just feel a bit silly that a node without CPU and memory is still online by
default during boot at the first place on powerpc, but that is probably a
different issue. For example,

# numactl -H
available: 6 nodes (0,8,252-255)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63
node 0 size: 126801 MB
node 0 free: 123199 MB
node 8 cpus: 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
node 8 size: 130811 MB
node 8 free: 128436 MB
node 252 cpus:
node 252 size: 0 MB
node 252 free: 0 MB
node 253 cpus:
node 253 size: 0 MB
node 253 free: 0 MB
node 254 cpus:
node 254 size: 0 MB
node 254 free: 0 MB
node 255 cpus:
node 255 size: 0 MB
node 255 free: 0 MB
node distances:
node   0   8  252  253  254  255 
  0:  10  40  80  80  80  80 
  8:  40  10  80  80  80  80 
 252:  80  80  10  80  80  80 
 253:  80  80  80  10  80  80 
 254:  80  80  80  80  10  80 
 255:  80  80  80  80  80  10 

# cat /sys/devices/system/node/online 
0,8,252-255





[PATCH 18/39] docs: admin-guide: add kdump documentation into it

2019-06-28 Thread Mauro Carvalho Chehab
The Kdump documentation describes procedures with admins use
in order to solve issues on their systems.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/admin-guide/bug-hunting.rst| 4 ++--
 Documentation/admin-guide/index.rst  | 1 +
 Documentation/{ => admin-guide}/kdump/gdbmacros.txt  | 0
 Documentation/{ => admin-guide}/kdump/index.rst  | 1 -
 Documentation/{ => admin-guide}/kdump/kdump.rst  | 0
 Documentation/{ => admin-guide}/kdump/vmcoreinfo.rst | 0
 Documentation/admin-guide/kernel-parameters.txt  | 6 +++---
 Documentation/powerpc/firmware-assisted-dump.rst | 2 +-
 Documentation/translations/zh_CN/oops-tracing.txt| 4 ++--
 Documentation/watchdog/hpwdt.rst | 2 +-
 MAINTAINERS  | 2 +-
 arch/arm/Kconfig | 2 +-
 arch/arm64/Kconfig   | 2 +-
 arch/sh/Kconfig  | 2 +-
 arch/x86/Kconfig | 4 ++--
 15 files changed, 16 insertions(+), 16 deletions(-)
 rename Documentation/{ => admin-guide}/kdump/gdbmacros.txt (100%)
 rename Documentation/{ => admin-guide}/kdump/index.rst (97%)
 rename Documentation/{ => admin-guide}/kdump/kdump.rst (100%)
 rename Documentation/{ => admin-guide}/kdump/vmcoreinfo.rst (100%)

diff --git a/Documentation/admin-guide/bug-hunting.rst 
b/Documentation/admin-guide/bug-hunting.rst
index b761aa2a51d2..44b8a4edd348 100644
--- a/Documentation/admin-guide/bug-hunting.rst
+++ b/Documentation/admin-guide/bug-hunting.rst
@@ -90,9 +90,9 @@ the disk is not available then you have three options:
 run a null modem to a second machine and capture the output there
 using your favourite communication program.  Minicom works well.
 
-(3) Use Kdump (see Documentation/kdump/kdump.rst),
+(3) Use Kdump (see Documentation/admin-guide/kdump/kdump.rst),
 extract the kernel ring buffer from old memory with using dmesg
-gdbmacro in Documentation/kdump/gdbmacros.txt.
+gdbmacro in Documentation/admin-guide/kdump/gdbmacros.txt.
 
 Finding the bug's location
 --
diff --git a/Documentation/admin-guide/index.rst 
b/Documentation/admin-guide/index.rst
index 9899b78dbe50..65e821a03aca 100644
--- a/Documentation/admin-guide/index.rst
+++ b/Documentation/admin-guide/index.rst
@@ -39,6 +39,7 @@ problems and bugs in particular.
ramoops
dynamic-debug-howto
init
+   kdump/index
perf/index
 
 This is the beginning of a section with information of interest to
diff --git a/Documentation/kdump/gdbmacros.txt 
b/Documentation/admin-guide/kdump/gdbmacros.txt
similarity index 100%
rename from Documentation/kdump/gdbmacros.txt
rename to Documentation/admin-guide/kdump/gdbmacros.txt
diff --git a/Documentation/kdump/index.rst 
b/Documentation/admin-guide/kdump/index.rst
similarity index 97%
rename from Documentation/kdump/index.rst
rename to Documentation/admin-guide/kdump/index.rst
index 2b17fcf6867a..8e2ebd0383cd 100644
--- a/Documentation/kdump/index.rst
+++ b/Documentation/admin-guide/kdump/index.rst
@@ -1,4 +1,3 @@
-:orphan:
 
 
 Documentation for Kdump - The kexec-based Crash Dumping Solution
diff --git a/Documentation/kdump/kdump.rst 
b/Documentation/admin-guide/kdump/kdump.rst
similarity index 100%
rename from Documentation/kdump/kdump.rst
rename to Documentation/admin-guide/kdump/kdump.rst
diff --git a/Documentation/kdump/vmcoreinfo.rst 
b/Documentation/admin-guide/kdump/vmcoreinfo.rst
similarity index 100%
rename from Documentation/kdump/vmcoreinfo.rst
rename to Documentation/admin-guide/kdump/vmcoreinfo.rst
diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index e38b96d061f4..9b535c0e22f3 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -708,14 +708,14 @@
[KNL, x86_64] select a region under 4G first, and
fall back to reserve region above 4G when '@offset'
hasn't been specified.
-   See Documentation/kdump/kdump.rst for further details.
+   See Documentation/admin-guide/kdump/kdump.rst for 
further details.
 
crashkernel=range1:size1[,range2:size2,...][@offset]
[KNL] Same as above, but depends on the memory
in the running system. The syntax of range is
start-[end] where start and end are both
a memory unit (amount[KMG]). See also
-   Documentation/kdump/kdump.rst for an example.
+   Documentation/admin-guide/kdump/kdump.rst for an 
example.
 
crashkernel=size[KMG],high
[KNL, x86_64] range could be above 4G. Allow kernel
@@ -1207,7 +1207,7 @@

[PATCH 13/39] docs: add arch doc directories to the index

2019-06-28 Thread Mauro Carvalho Chehab
Now that several arch documents were converted to ReST,
add their indexes to Documentation/index.rst and remove the
:orphan:  from them.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/arm/index.rst |  2 --
 Documentation/arm64/index.rst   |  2 --
 Documentation/ia64/index.rst|  2 --
 Documentation/index.rst | 10 ++
 Documentation/m68k/index.rst|  2 +-
 Documentation/powerpc/index.rst |  2 +-
 Documentation/riscv/index.rst   |  2 --
 Documentation/s390/index.rst|  2 --
 Documentation/sparc/index.rst   |  2 --
 Documentation/xtensa/index.rst  |  2 +-
 10 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/Documentation/arm/index.rst b/Documentation/arm/index.rst
index bd316d1a1802..9c2f781f4685 100644
--- a/Documentation/arm/index.rst
+++ b/Documentation/arm/index.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 
 ARM Architecture
 
diff --git a/Documentation/arm64/index.rst b/Documentation/arm64/index.rst
index 018b7836ecb7..96b696ba4e6c 100644
--- a/Documentation/arm64/index.rst
+++ b/Documentation/arm64/index.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 ==
 ARM64 Architecture
 ==
diff --git a/Documentation/ia64/index.rst b/Documentation/ia64/index.rst
index a3e3052ad6e2..ef99475f672b 100644
--- a/Documentation/ia64/index.rst
+++ b/Documentation/ia64/index.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 ==
 IA-64 Architecture
 ==
diff --git a/Documentation/index.rst b/Documentation/index.rst
index 95db26bf2899..f898def833f4 100644
--- a/Documentation/index.rst
+++ b/Documentation/index.rst
@@ -118,7 +118,17 @@ implementation.
:maxdepth: 2
 
sh/index
+   arm/index
+   arm64/index
+   ia64/index
+   m68k/index
+   powerpc/index
+   riscv/index
+   s390/index
+   sh/index
+   sparc/index
x86/index
+   xtensa/index
 
 Filesystem Documentation
 
diff --git a/Documentation/m68k/index.rst b/Documentation/m68k/index.rst
index f3273ec075c3..3a5ba7fe1703 100644
--- a/Documentation/m68k/index.rst
+++ b/Documentation/m68k/index.rst
@@ -1,4 +1,4 @@
-:orphan:
+.. SPDX-License-Identifier: GPL-2.0
 
 =
 m68k Architecture
diff --git a/Documentation/powerpc/index.rst b/Documentation/powerpc/index.rst
index 1ff17268db46..549b1cdd77ae 100644
--- a/Documentation/powerpc/index.rst
+++ b/Documentation/powerpc/index.rst
@@ -1,4 +1,4 @@
-:orphan:
+.. SPDX-License-Identifier: GPL-2.0
 
 ===
 powerpc
diff --git a/Documentation/riscv/index.rst b/Documentation/riscv/index.rst
index c4b906d9b5a7..e3ca0922a8c2 100644
--- a/Documentation/riscv/index.rst
+++ b/Documentation/riscv/index.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 ===
 RISC-V architecture
 ===
diff --git a/Documentation/s390/index.rst b/Documentation/s390/index.rst
index 1a914da2a07b..4602312909d3 100644
--- a/Documentation/s390/index.rst
+++ b/Documentation/s390/index.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 =
 s390 Architecture
 =
diff --git a/Documentation/sparc/index.rst b/Documentation/sparc/index.rst
index 91f7d6643dd5..71cff621f243 100644
--- a/Documentation/sparc/index.rst
+++ b/Documentation/sparc/index.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 ==
 Sparc Architecture
 ==
diff --git a/Documentation/xtensa/index.rst b/Documentation/xtensa/index.rst
index 5a24e365e35f..52fa04eb39a3 100644
--- a/Documentation/xtensa/index.rst
+++ b/Documentation/xtensa/index.rst
@@ -1,4 +1,4 @@
-:orphan:
+.. SPDX-License-Identifier: GPL-2.0
 
 ===
 Xtensa Architecture
-- 
2.21.0



[PATCH 32/39] docs: serial: move it to the driver-api

2019-06-28 Thread Mauro Carvalho Chehab
The contents of this directory is mostly driver-api stuff.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/driver-api/index.rst   | 1 +
 Documentation/{ => driver-api}/serial/cyclades_z.rst | 0
 Documentation/{ => driver-api}/serial/driver.rst | 2 +-
 Documentation/{ => driver-api}/serial/index.rst  | 2 +-
 Documentation/{ => driver-api}/serial/moxa-smartio.rst   | 0
 Documentation/{ => driver-api}/serial/n_gsm.rst  | 0
 Documentation/{ => driver-api}/serial/rocket.rst | 0
 Documentation/{ => driver-api}/serial/serial-iso7816.rst | 0
 Documentation/{ => driver-api}/serial/serial-rs485.rst   | 0
 Documentation/{ => driver-api}/serial/tty.rst| 0
 MAINTAINERS  | 6 +++---
 drivers/tty/Kconfig  | 4 ++--
 drivers/tty/serial/ucc_uart.c| 2 +-
 include/linux/serial_core.h  | 2 +-
 14 files changed, 10 insertions(+), 9 deletions(-)
 rename Documentation/{ => driver-api}/serial/cyclades_z.rst (100%)
 rename Documentation/{ => driver-api}/serial/driver.rst (99%)
 rename Documentation/{ => driver-api}/serial/index.rst (90%)
 rename Documentation/{ => driver-api}/serial/moxa-smartio.rst (100%)
 rename Documentation/{ => driver-api}/serial/n_gsm.rst (100%)
 rename Documentation/{ => driver-api}/serial/rocket.rst (100%)
 rename Documentation/{ => driver-api}/serial/serial-iso7816.rst (100%)
 rename Documentation/{ => driver-api}/serial/serial-rs485.rst (100%)
 rename Documentation/{ => driver-api}/serial/tty.rst (100%)

diff --git a/Documentation/driver-api/index.rst 
b/Documentation/driver-api/index.rst
index f44a3140f95d..d6f532c8d824 100644
--- a/Documentation/driver-api/index.rst
+++ b/Documentation/driver-api/index.rst
@@ -88,6 +88,7 @@ available subsections can be seen below.
pti_intel_mid
pwm
rfkill
+   serial/index
sgi-ioc4
sm501
smsc_ece1099
diff --git a/Documentation/serial/cyclades_z.rst 
b/Documentation/driver-api/serial/cyclades_z.rst
similarity index 100%
rename from Documentation/serial/cyclades_z.rst
rename to Documentation/driver-api/serial/cyclades_z.rst
diff --git a/Documentation/serial/driver.rst 
b/Documentation/driver-api/serial/driver.rst
similarity index 99%
rename from Documentation/serial/driver.rst
rename to Documentation/driver-api/serial/driver.rst
index 4537119bf624..31bd4e16fb1f 100644
--- a/Documentation/serial/driver.rst
+++ b/Documentation/driver-api/serial/driver.rst
@@ -311,7 +311,7 @@ hardware.
This call must not sleep
 
   set_ldisc(port,termios)
-   Notifier for discipline change. See Documentation/serial/tty.rst.
+   Notifier for discipline change. See 
Documentation/driver-api/serial/tty.rst.
 
Locking: caller holds tty_port->mutex
 
diff --git a/Documentation/serial/index.rst 
b/Documentation/driver-api/serial/index.rst
similarity index 90%
rename from Documentation/serial/index.rst
rename to Documentation/driver-api/serial/index.rst
index d0ba22ea23bf..33ad10d05b26 100644
--- a/Documentation/serial/index.rst
+++ b/Documentation/driver-api/serial/index.rst
@@ -1,4 +1,4 @@
-:orphan:
+.. SPDX-License-Identifier: GPL-2.0
 
 ==
 Support for Serial devices
diff --git a/Documentation/serial/moxa-smartio.rst 
b/Documentation/driver-api/serial/moxa-smartio.rst
similarity index 100%
rename from Documentation/serial/moxa-smartio.rst
rename to Documentation/driver-api/serial/moxa-smartio.rst
diff --git a/Documentation/serial/n_gsm.rst 
b/Documentation/driver-api/serial/n_gsm.rst
similarity index 100%
rename from Documentation/serial/n_gsm.rst
rename to Documentation/driver-api/serial/n_gsm.rst
diff --git a/Documentation/serial/rocket.rst 
b/Documentation/driver-api/serial/rocket.rst
similarity index 100%
rename from Documentation/serial/rocket.rst
rename to Documentation/driver-api/serial/rocket.rst
diff --git a/Documentation/serial/serial-iso7816.rst 
b/Documentation/driver-api/serial/serial-iso7816.rst
similarity index 100%
rename from Documentation/serial/serial-iso7816.rst
rename to Documentation/driver-api/serial/serial-iso7816.rst
diff --git a/Documentation/serial/serial-rs485.rst 
b/Documentation/driver-api/serial/serial-rs485.rst
similarity index 100%
rename from Documentation/serial/serial-rs485.rst
rename to Documentation/driver-api/serial/serial-rs485.rst
diff --git a/Documentation/serial/tty.rst 
b/Documentation/driver-api/serial/tty.rst
similarity index 100%
rename from Documentation/serial/tty.rst
rename to Documentation/driver-api/serial/tty.rst
diff --git a/MAINTAINERS b/MAINTAINERS
index 055db86fdd77..856db8015edd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10723,7 +10723,7 @@ F:  include/uapi/linux/meye.h
 MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD
 M: Jiri Slaby 
 S: Maintained
-F: Documentation/serial/moxa-smartio.rst
+F: 

[PATCH 22/39] docs: ocxl.rst: add it to the uAPI book

2019-06-28 Thread Mauro Carvalho Chehab
The content of this file is user-faced.

Signed-off-by: Mauro Carvalho Chehab 
---
 Documentation/{ => userspace-api}/accelerators/ocxl.rst | 2 --
 Documentation/userspace-api/index.rst   | 1 +
 MAINTAINERS | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
 rename Documentation/{ => userspace-api}/accelerators/ocxl.rst (99%)

diff --git a/Documentation/accelerators/ocxl.rst 
b/Documentation/userspace-api/accelerators/ocxl.rst
similarity index 99%
rename from Documentation/accelerators/ocxl.rst
rename to Documentation/userspace-api/accelerators/ocxl.rst
index b1cea19a90f5..14cefc020e2d 100644
--- a/Documentation/accelerators/ocxl.rst
+++ b/Documentation/userspace-api/accelerators/ocxl.rst
@@ -1,5 +1,3 @@
-:orphan:
-
 
 OpenCAPI (Open Coherent Accelerator Processor Interface)
 
diff --git a/Documentation/userspace-api/index.rst 
b/Documentation/userspace-api/index.rst
index a3233da7fa88..ad494da40009 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -20,6 +20,7 @@ place where this information is gathered.
seccomp_filter
unshare
spec_ctrl
+   accelerators/ocxl
 
 .. only::  subproject and html
 
diff --git a/MAINTAINERS b/MAINTAINERS
index 29d1498ad39d..f723371dccd0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11483,7 +11483,7 @@ F:  arch/powerpc/include/asm/pnv-ocxl.h
 F: drivers/misc/ocxl/
 F: include/misc/ocxl*
 F: include/uapi/misc/ocxl.h
-F: Documentation/accelerators/ocxl.rst
+F: Documentation/userspace-api/accelerators/ocxl.rst
 
 OMAP AUDIO SUPPORT
 M: Peter Ujfalusi 
-- 
2.21.0



[PATCH 05/43] docs: powerpc: convert docs to ReST and rename to *.rst

2019-06-28 Thread Mauro Carvalho Chehab
Convert docs to ReST and add them to the arch-specific
book.

The conversion here was trivial, as almost every file there
was already using an elegant format close to ReST standard.

The changes were mostly to mark literal blocks and add a few
missing section title identifiers.

One note with regards to "--": on Sphinx, this can't be used
to identify a list, as it will format it badly. This can be
used, however, to identify a long hyphen - and "---" is an
even longer one.

At its new index.rst, let's add a :orphan: while this is not linked to
the main index.rst file, in order to avoid build warnings.

Signed-off-by: Mauro Carvalho Chehab 
Acked-by: Andrew Donnellan  # cxl
---
 Documentation/PCI/pci-error-recovery.rst  |  23 ++-
 .../{bootwrapper.txt => bootwrapper.rst}  |  28 +++-
 .../{cpu_families.txt => cpu_families.rst}|  23 +--
 .../{cpu_features.txt => cpu_features.rst}|   6 +-
 Documentation/powerpc/{cxl.txt => cxl.rst}|  46 --
 .../powerpc/{cxlflash.txt => cxlflash.rst}|  10 +-
 .../{DAWR-POWER9.txt => dawr-power9.rst}  |  15 +-
 Documentation/powerpc/{dscr.txt => dscr.rst}  |  18 +-
 ...ecovery.txt => eeh-pci-error-recovery.rst} | 108 ++--
 ...ed-dump.txt => firmware-assisted-dump.rst} | 117 +++--
 Documentation/powerpc/{hvcs.txt => hvcs.rst}  | 108 ++--
 Documentation/powerpc/index.rst   |  34 
 Documentation/powerpc/isa-versions.rst|  15 +-
 .../powerpc/{mpc52xx.txt => mpc52xx.rst}  |  12 +-
 ...nv.txt => pci_iov_resource_on_powernv.rst} |  15 +-
 .../powerpc/{pmu-ebb.txt => pmu-ebb.rst}  |   1 +
 Documentation/powerpc/ptrace.rst  | 156 ++
 Documentation/powerpc/ptrace.txt  | 151 -
 .../{qe_firmware.txt => qe_firmware.rst}  |  37 +++--
 .../{syscall64-abi.txt => syscall64-abi.rst}  |  29 ++--
 ...al_memory.txt => transactional_memory.rst} |  45 ++---
 MAINTAINERS   |   6 +-
 arch/powerpc/kernel/exceptions-64s.S  |   2 +-
 drivers/soc/fsl/qe/qe.c   |   2 +-
 drivers/tty/hvc/hvcs.c|   2 +-
 include/soc/fsl/qe/qe.h   |   2 +-
 26 files changed, 584 insertions(+), 427 deletions(-)
 rename Documentation/powerpc/{bootwrapper.txt => bootwrapper.rst} (93%)
 rename Documentation/powerpc/{cpu_families.txt => cpu_families.rst} (95%)
 rename Documentation/powerpc/{cpu_features.txt => cpu_features.rst} (97%)
 rename Documentation/powerpc/{cxl.txt => cxl.rst} (95%)
 rename Documentation/powerpc/{cxlflash.txt => cxlflash.rst} (98%)
 rename Documentation/powerpc/{DAWR-POWER9.txt => dawr-power9.rst} (95%)
 rename Documentation/powerpc/{dscr.txt => dscr.rst} (91%)
 rename Documentation/powerpc/{eeh-pci-error-recovery.txt => 
eeh-pci-error-recovery.rst} (82%)
 rename Documentation/powerpc/{firmware-assisted-dump.txt => 
firmware-assisted-dump.rst} (80%)
 rename Documentation/powerpc/{hvcs.txt => hvcs.rst} (91%)
 create mode 100644 Documentation/powerpc/index.rst
 rename Documentation/powerpc/{mpc52xx.txt => mpc52xx.rst} (91%)
 rename Documentation/powerpc/{pci_iov_resource_on_powernv.txt => 
pci_iov_resource_on_powernv.rst} (97%)
 rename Documentation/powerpc/{pmu-ebb.txt => pmu-ebb.rst} (99%)
 create mode 100644 Documentation/powerpc/ptrace.rst
 delete mode 100644 Documentation/powerpc/ptrace.txt
 rename Documentation/powerpc/{qe_firmware.txt => qe_firmware.rst} (95%)
 rename Documentation/powerpc/{syscall64-abi.txt => syscall64-abi.rst} (82%)
 rename Documentation/powerpc/{transactional_memory.txt => 
transactional_memory.rst} (93%)

diff --git a/Documentation/PCI/pci-error-recovery.rst 
b/Documentation/PCI/pci-error-recovery.rst
index 83db42092935..acc21ecca322 100644
--- a/Documentation/PCI/pci-error-recovery.rst
+++ b/Documentation/PCI/pci-error-recovery.rst
@@ -403,7 +403,7 @@ That is, the recovery API only requires that:
 .. note::
 
Implementation details for the powerpc platform are discussed in
-   the file Documentation/powerpc/eeh-pci-error-recovery.txt
+   the file Documentation/powerpc/eeh-pci-error-recovery.rst
 
As of this writing, there is a growing list of device drivers with
patches implementing error recovery. Not all of these patches are in
@@ -422,3 +422,24 @@ That is, the recovery API only requires that:
- drivers/net/cxgb3
- drivers/net/s2io.c
- drivers/net/qlge
+
+>>> As of this writing, there is a growing list of device drivers with
+>>> patches implementing error recovery. Not all of these patches are in
+>>> mainline yet. These may be used as "examples":
+>>>
+>>> drivers/scsi/ipr
+>>> drivers/scsi/sym53c8xx_2
+>>> drivers/scsi/qla2xxx
+>>> drivers/scsi/lpfc
+>>> drivers/next/bnx2.c
+>>> drivers/next/e100.c
+>>> drivers/net/e1000
+>>> drivers/net/e1000e
+>>> drivers/net/ixgb
+>>> drivers/net/ixgbe
+>>> drivers/net/cxgb3
+>>> drivers/net/s2io.c
+>>> drivers/net/qlge
+
+The End
+---
diff --git 

Re: power9 NUMA crash while reading debugfs imc_cmd

2019-06-28 Thread Anju T Sudhakar



On 6/28/19 9:04 AM, Qian Cai wrote:



On Jun 27, 2019, at 11:12 PM, Michael Ellerman  wrote:

Qian Cai  writes:

Read of debugfs imc_cmd file for a memory-less node will trigger a crash below
on this power9 machine which has the following NUMA layout.

What type of machine is it?

description: PowerNV
product: 8335-GTH (ibm,witherspoon)
vendor: IBM
width: 64 bits
capabilities: smp powernv opal



Hi Qian Cai,

Could you please try with this patch: 
https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-June/192803.html


and see if the issue is resolved?


Thanks,

Anju




[PATCH] powerpc/imc: Dont create debugfs files for cpu-less nodes

2019-06-28 Thread Anju T Sudhakar
From: Madhavan Srinivasan 

Commit <684d984038aa> ('powerpc/powernv: Add debugfs interface for imc-mode
and imc') added debugfs interface for the nest imc pmu devices to support
changing of different ucode modes. Primarily adding this capability for
debug. But when doing so, the code did not consider the case of cpu-less
nodes. So when reading the _cmd_ or _mode_ file of a cpu-less node
will create this crash.

[ 1139.415461][ T5301] Faulting instruction address: 0xc00d0d58
[ 1139.415492][ T5301] Oops: Kernel access of bad area, sig: 11 [#1]
[ 1139.415509][ T5301] LE PAGE_SIZE=64K MMU=Radix MMU=Hash SMP NR_CPUS=256
DEBUG_PAGEALLOC NUMA PowerNV
[ 1139.415542][ T5301] Modules linked in: i2c_opal i2c_core ip_tables x_tables
xfs sd_mod bnx2x mdio ahci libahci tg3 libphy libata firmware_class dm_mirror
dm_region_hash dm_log dm_mod
[ 1139.415595][ T5301] CPU: 67 PID: 5301 Comm: cat Not tainted 5.2.0-rc6-next-
20190627+ #19
[ 1139.415634][ T5301] NIP:  c00d0d58 LR: c049aa18 
CTR:c00d0d50
[ 1139.415675][ T5301] REGS: c00020194548f9e0 TRAP: 0300   Not tainted  
(5.2.0-rc6-next-20190627+)
[ 1139.415705][ T5301] MSR:  90009033   
CR:28022822  XER: 
[ 1139.415777][ T5301] CFAR: c049aa14 DAR: 0003fc08 
DSISR:4000 IRQMASK: 0
[ 1139.415777][ T5301] GPR00: c049aa18 c00020194548fc70 
c16f8b03fc08
[ 1139.415777][ T5301] GPR04: c00020194548fcd0  
14884e7300011eaa
[ 1139.415777][ T5301] GPR08: 7eea5a52 c00d0d50 

[ 1139.415777][ T5301] GPR12: c00d0d50 c000201fff7f8c00 

[ 1139.415777][ T5301] GPR16: 000d 7fffeb0c3368 

[ 1139.415777][ T5301] GPR20:   
0002
[ 1139.415777][ T5301] GPR24:   
000200010ec9
[ 1139.415777][ T5301] GPR28: c00020194548fdf0 c00020049a584ef8 
c00020049a584ea8
[ 1139.416116][ T5301] NIP [c00d0d58] imc_mem_get+0x8/0x20
[ 1139.416143][ T5301] LR [c049aa18] simple_attr_read+0x118/0x170
[ 1139.416158][ T5301] Call Trace:
[ 1139.416182][ T5301] [c00020194548fc70] 
[c049a970]simple_attr_read+0x70/0x170 (unreliable)
[ 1139.416255][ T5301] [c00020194548fd10] 
[c054385c]debugfs_attr_read+0x6c/0xb0
[ 1139.416305][ T5301] [c00020194548fd60] [c0454c1c]__vfs_read+0x3c/0x70
[ 1139.416363][ T5301] [c00020194548fd80] [c0454d0c] vfs_read+0xbc/0x1a0
[ 1139.416392][ T5301] [c00020194548fdd0] [c045519c]ksys_read+0x7c/0x140
[ 1139.416434][ T5301] [c00020194548fe20] 
[c000b108]system_call+0x5c/0x70
[ 1139.416473][ T5301] Instruction dump:
[ 1139.416511][ T5301] 4e800020 6000 7c0802a6 6000 7c801d28 3860 
4e800020 6000
[ 1139.416572][ T5301] 6000 6000 7c0802a6 6000 <7d201c28> 3860 
f924 4e800020
[ 1139.416636][ T5301] ---[ end trace c44d1fb4ace04784 ]---
[ 1139.520686][ T5301]
[ 1140.520820][ T5301] Kernel panic - not syncing: Fatal exception

Patch adds a check to avoid creation of these files to cpu-less nodes.

Fixes: 684d984038aa ('powerpc/powernv: Add debugfs interface for imc-mode and 
imc')
Reported-by: Qian Cai 
Signed-off-by: Madhavan Srinivasan 
Signed-off-by: Anju T Sudhakar 
---
 arch/powerpc/platforms/powernv/opal-imc.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/opal-imc.c 
b/arch/powerpc/platforms/powernv/opal-imc.c
index 186109bdd41b..12c8964a2f9c 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -56,6 +57,7 @@ static void export_imc_mode_and_cmd(struct device_node *node,
int chip = 0, nid;
char mode[16], cmd[16];
u32 cb_offset;
+   const struct cpumask *l_cpumask;
 
imc_debugfs_parent = debugfs_create_dir("imc", powerpc_debugfs_root);
 
@@ -70,6 +72,14 @@ static void export_imc_mode_and_cmd(struct device_node *node,
cb_offset = IMC_CNTL_BLK_OFFSET;
 
for_each_node(nid) {
+   /*
+* Since these are related to nest pmu,
+* create only if the node has any cpu in it.
+*/
+   l_cpumask = cpumask_of_node(nid);
+   if (cpumask_empty(l_cpumask))
+   continue;
+
loc = (u64)(pmu_ptr->mem_info[chip].vbase) + cb_offset;
imc_mode_addr = (u64 *)(loc + IMC_CNTL_BLK_MODE_OFFSET);
sprintf(mode, "imc_mode_%d", nid);
-- 
2.20.1



Re: [PATCH v2 27/27] sound: ppc: remove unneeded memset after dma_alloc_coherent

2019-06-28 Thread Christophe Leroy




Le 28/06/2019 à 11:11, Fuqian Huang a écrit :

The merge commit log tells (dma-mapping: zero memory returned from
dma_alloc_* and deprecating the dma_zalloc_coherent).
I used this commit just want to say that dma_alloc_coherent  has
zeroed the allocated memory.
Sorry for this mistake.

Maybe this commit 518a2f1925c3("dma-mapping: zero memory returned from
dma_alloc_*") is correct.


Yes that looks appropriate. And it confirms it was already done on 
powerpc, as that patch doesn't include any change in powerpc arch.


Christophe



Christophe Leroy  於 2019年6月28日週五 下午4:59寫道:





Le 28/06/2019 à 04:50, Fuqian Huang a écrit :

In commit af7ddd8a627c
("Merge tag 'dma-mapping-4.21' of 
git://git.infradead.org/users/hch/dma-mapping"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.


You are refering to a merge commit, is that correct ?

I can't see anything related in that commit, can you please pinpoint it ?

As far as I can see, on powerpc the memory has always been zeroized
(since 2005 at least).

Christophe



Signed-off-by: Fuqian Huang 
---
   sound/ppc/pmac.c | 1 -
   1 file changed, 1 deletion(-)

diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 1b11e53f6a62..1ab12f4f8631 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -56,7 +56,6 @@ static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, struct 
pmac_dbdma *rec, i
   if (rec->space == NULL)
   return -ENOMEM;
   rec->size = size;
- memset(rec->space, 0, rsize);
   rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space);
   rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - (char 
*)rec->space);




Re: [alsa-devel] [PATCH v2 27/27] sound: ppc: remove unneeded memset after dma_alloc_coherent

2019-06-28 Thread Takashi Iwai
On Fri, 28 Jun 2019 11:11:08 +0200,
Fuqian Huang wrote:
> 
> The merge commit log tells (dma-mapping: zero memory returned from
> dma_alloc_* and deprecating the dma_zalloc_coherent).
> I used this commit just want to say that dma_alloc_coherent  has
> zeroed the allocated memory.
> Sorry for this mistake.
> 
> Maybe this commit 518a2f1925c3("dma-mapping: zero memory returned from
> dma_alloc_*") is correct.

Are you going to resubmit v3 patchset?  If the correction is specific
to this patch, I can correct the description in my side, too...


thanks,

Takashi

> 
> Christophe Leroy  於 2019年6月28日週五 下午4:59寫道:
> 
> >
> >
> >
> > Le 28/06/2019 à 04:50, Fuqian Huang a écrit :
> > > In commit af7ddd8a627c
> > > ("Merge tag 'dma-mapping-4.21' of 
> > > git://git.infradead.org/users/hch/dma-mapping"),
> > > dma_alloc_coherent has already zeroed the memory.
> > > So memset is not needed.
> >
> > You are refering to a merge commit, is that correct ?
> >
> > I can't see anything related in that commit, can you please pinpoint it ?
> >
> > As far as I can see, on powerpc the memory has always been zeroized
> > (since 2005 at least).
> >
> > Christophe
> >
> > >
> > > Signed-off-by: Fuqian Huang 
> > > ---
> > >   sound/ppc/pmac.c | 1 -
> > >   1 file changed, 1 deletion(-)
> > >
> > > diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
> > > index 1b11e53f6a62..1ab12f4f8631 100644
> > > --- a/sound/ppc/pmac.c
> > > +++ b/sound/ppc/pmac.c
> > > @@ -56,7 +56,6 @@ static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, 
> > > struct pmac_dbdma *rec, i
> > >   if (rec->space == NULL)
> > >   return -ENOMEM;
> > >   rec->size = size;
> > > - memset(rec->space, 0, rsize);
> > >   rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space);
> > >   rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - 
> > > (char *)rec->space);
> > >
> > >
> ___
> Alsa-devel mailing list
> alsa-de...@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel


Re: [PATCH 41/87] sound: ppc: remove memset after dma_alloc_coherent

2019-06-28 Thread Takashi Iwai
On Fri, 28 Jun 2019 10:54:34 +0200,
Takashi Iwai wrote:
> 
> On Fri, 28 Jun 2019 10:53:14 +0200,
> Christophe Leroy wrote:
> > 
> > 
> > 
> > Le 28/06/2019 à 10:48, Takashi Iwai a écrit :
> > > On Thu, 27 Jun 2019 19:40:17 +0200,
> > > Fuqian Huang wrote:
> > >>
> > >> In commit af7ddd8a627c
> > >> ("Merge tag 'dma-mapping-4.21' of 
> > >> git://git.infradead.org/users/hch/dma-mapping"),
> > >> dma_alloc_coherent has already zeroed the memory.
> > >> So memset is not needed.
> > >>
> > >> Signed-off-by: Fuqian Huang 
> > >
> > > Applied, thanks.
> > >
> > 
> > Euh ... looks like a v2 of this series was sent out.
> 
> OK, then I take back.  Luckily, the tree wasn't pushed out yet.
> Thanks for the quick notice.

... and this turned out to be because of our mail server change.
Now I'm going to review & take v2 patches.


Takashi


Re: [PATCH v2 27/27] sound: ppc: remove unneeded memset after dma_alloc_coherent

2019-06-28 Thread Fuqian Huang
The merge commit log tells (dma-mapping: zero memory returned from
dma_alloc_* and deprecating the dma_zalloc_coherent).
I used this commit just want to say that dma_alloc_coherent  has
zeroed the allocated memory.
Sorry for this mistake.

Maybe this commit 518a2f1925c3("dma-mapping: zero memory returned from
dma_alloc_*") is correct.

Christophe Leroy  於 2019年6月28日週五 下午4:59寫道:

>
>
>
> Le 28/06/2019 à 04:50, Fuqian Huang a écrit :
> > In commit af7ddd8a627c
> > ("Merge tag 'dma-mapping-4.21' of 
> > git://git.infradead.org/users/hch/dma-mapping"),
> > dma_alloc_coherent has already zeroed the memory.
> > So memset is not needed.
>
> You are refering to a merge commit, is that correct ?
>
> I can't see anything related in that commit, can you please pinpoint it ?
>
> As far as I can see, on powerpc the memory has always been zeroized
> (since 2005 at least).
>
> Christophe
>
> >
> > Signed-off-by: Fuqian Huang 
> > ---
> >   sound/ppc/pmac.c | 1 -
> >   1 file changed, 1 deletion(-)
> >
> > diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
> > index 1b11e53f6a62..1ab12f4f8631 100644
> > --- a/sound/ppc/pmac.c
> > +++ b/sound/ppc/pmac.c
> > @@ -56,7 +56,6 @@ static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, 
> > struct pmac_dbdma *rec, i
> >   if (rec->space == NULL)
> >   return -ENOMEM;
> >   rec->size = size;
> > - memset(rec->space, 0, rsize);
> >   rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space);
> >   rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - (char 
> > *)rec->space);
> >
> >


Re: [PATCH v2 27/27] sound: ppc: remove unneeded memset after dma_alloc_coherent

2019-06-28 Thread Christophe Leroy




Le 28/06/2019 à 04:50, Fuqian Huang a écrit :

In commit af7ddd8a627c
("Merge tag 'dma-mapping-4.21' of 
git://git.infradead.org/users/hch/dma-mapping"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.


You are refering to a merge commit, is that correct ?

I can't see anything related in that commit, can you please pinpoint it ?

As far as I can see, on powerpc the memory has always been zeroized 
(since 2005 at least).


Christophe



Signed-off-by: Fuqian Huang 
---
  sound/ppc/pmac.c | 1 -
  1 file changed, 1 deletion(-)

diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 1b11e53f6a62..1ab12f4f8631 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -56,7 +56,6 @@ static int snd_pmac_dbdma_alloc(struct snd_pmac *chip, struct 
pmac_dbdma *rec, i
if (rec->space == NULL)
return -ENOMEM;
rec->size = size;
-   memset(rec->space, 0, rsize);
rec->cmds = (void __iomem *)DBDMA_ALIGN(rec->space);
rec->addr = rec->dma_base + (unsigned long)((char *)rec->cmds - (char 
*)rec->space);
  



Re: [PATCH 41/87] sound: ppc: remove memset after dma_alloc_coherent

2019-06-28 Thread Takashi Iwai
On Fri, 28 Jun 2019 10:53:14 +0200,
Christophe Leroy wrote:
> 
> 
> 
> Le 28/06/2019 à 10:48, Takashi Iwai a écrit :
> > On Thu, 27 Jun 2019 19:40:17 +0200,
> > Fuqian Huang wrote:
> >>
> >> In commit af7ddd8a627c
> >> ("Merge tag 'dma-mapping-4.21' of 
> >> git://git.infradead.org/users/hch/dma-mapping"),
> >> dma_alloc_coherent has already zeroed the memory.
> >> So memset is not needed.
> >>
> >> Signed-off-by: Fuqian Huang 
> >
> > Applied, thanks.
> >
> 
> Euh ... looks like a v2 of this series was sent out.

OK, then I take back.  Luckily, the tree wasn't pushed out yet.
Thanks for the quick notice.


Takashi


Re: [PATCH 41/87] sound: ppc: remove memset after dma_alloc_coherent

2019-06-28 Thread Christophe Leroy




Le 28/06/2019 à 10:48, Takashi Iwai a écrit :

On Thu, 27 Jun 2019 19:40:17 +0200,
Fuqian Huang wrote:


In commit af7ddd8a627c
("Merge tag 'dma-mapping-4.21' of 
git://git.infradead.org/users/hch/dma-mapping"),
dma_alloc_coherent has already zeroed the memory.
So memset is not needed.

Signed-off-by: Fuqian Huang 


Applied, thanks.



Euh ... looks like a v2 of this series was sent out.

Christophe


Re: [PATCH 41/87] sound: ppc: remove memset after dma_alloc_coherent

2019-06-28 Thread Takashi Iwai
On Thu, 27 Jun 2019 19:40:17 +0200,
Fuqian Huang wrote:
> 
> In commit af7ddd8a627c
> ("Merge tag 'dma-mapping-4.21' of 
> git://git.infradead.org/users/hch/dma-mapping"),
> dma_alloc_coherent has already zeroed the memory.
> So memset is not needed.
> 
> Signed-off-by: Fuqian Huang 

Applied, thanks.


Takashi


Re: [PATCH v2 4/7] powerpc/ftrace: Additionally nop out the preceding mflr with -mprofile-kernel

2019-06-28 Thread Nicholas Piggin
Naveen N. Rao's on June 27, 2019 9:23 pm:
> With -mprofile-kernel, gcc emits 'mflr r0', followed by 'bl _mcount' to
> enable function tracing and profiling. So far, with dynamic ftrace, we
> used to only patch out the branch to _mcount(). However, mflr is
> executed by the branch unit that can only execute one per cycle on
> POWER9 and shared with branches, so it would be nice to avoid it where
> possible.
> 
> We cannot simply nop out the mflr either. When enabling function
> tracing, there can be a race if tracing is enabled when some thread was
> interrupted after executing a nop'ed out mflr. In this case, the thread
> would execute the now-patched-in branch to _mcount() without having
> executed the preceding mflr.
> 
> To solve this, we now enable function tracing in 2 steps: patch in the
> mflr instruction, use 'smp_call_function(isync);
> synchronize_rcu_tasks()' to ensure all existing threads make progress,
> and then patch in the branch to _mcount(). We override
> ftrace_replace_code() with a powerpc64 variant for this purpose.

I think this seems like a reasonable sequence that will work on our
hardware, although technically outside the ISA as specified maybe
we should add a feature bit or at least comment for it.

It would be kind of nice to not put this stuff directly in the 
ftrace code, but rather in the function patching subsystem.

I think it would be too expensive to just make a runtime variant of
patch_instruction that always does the SMP isync, but possibly a
patch_instruction_sync() or something that we say ensures no
processor is running code that has been patched away.

Thanks,
Nick



[PATCH v2] powerpc/pseries: Fix maximum memory value

2019-06-28 Thread Aravinda Prasad
Calculating the maximum memory based on the number of lmbs
and lmb size does not account for the RMA region. Hence
use memory_hotplug_max(), which already accounts for the
RMA region, to fetch the maximum memory value. Thanks to
Nathan Lynch for suggesting the memory_hotplug_max()
function.

Fixes: 772b039fd9a7: ("powerpc/pseries: Export maximum memory value")
Signed-off-by: Aravinda Prasad 
---
 arch/powerpc/platforms/pseries/lparcfg.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/lparcfg.c 
b/arch/powerpc/platforms/pseries/lparcfg.c
index e33e8bc..010a41f 100644
--- a/arch/powerpc/platforms/pseries/lparcfg.c
+++ b/arch/powerpc/platforms/pseries/lparcfg.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -33,7 +34,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "pseries.h"
 
@@ -435,7 +435,7 @@ static void maxmem_data(struct seq_file *m)
 {
unsigned long maxmem = 0;
 
-   maxmem += drmem_info->n_lmbs * drmem_info->lmb_size;
+   maxmem += memory_hotplug_max();
maxmem += hugetlb_total_pages() * PAGE_SIZE;
 
seq_printf(m, "MaxMem=%ld\n", maxmem);



[PATCH kernel] powerpc/powernv: Fix stale iommu table base after VFIO

2019-06-28 Thread Alexey Kardashevskiy
The powernv platform uses @dma_iommu_ops for non-bypass DMA. These ops
need an iommu_table pointer which is stored in
dev->archdata.iommu_table_base. It is initialized during
pcibios_setup_device() which handles boot time devices. However when
a device is taken from the system in order to pass it through, the default
IOMMU table is destroyed but the pointer in a device is not updated;
also when a device is returned back to the system, a new table pointer
is not stored in dev->archdata.iommu_table_base either. So when a just
returned device tries using IOMMU, it crashes on accessing stale
iommu_table or its members.

This calls set_iommu_table_base() when the default window is created.
Note it used to be there before but was wrongly removed (see "fixes").
It did not appear before as these days most devices simply use bypass.

This adds set_iommu_table_base(NULL) when a device is taken from
the system to make it clear that IOMMU DMA cannot be used past that point.

Fixes: c4e9d3c1e65a ("powerpc/powernv/pseries: Rework device adding to IOMMU 
groups")
Signed-off-by: Alexey Kardashevskiy 
---

This needs to be applied before
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=110810
(discovered while testing this on POWER8)
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 10cc42b9e541..0f72c7484824 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2456,6 +2456,14 @@ static long pnv_pci_ioda2_setup_default_config(struct 
pnv_ioda_pe *pe)
if (!pnv_iommu_bypass_disabled)
pnv_pci_ioda2_set_bypass(pe, true);
 
+   /*
+* Set table base for the case of IOMMU DMA use. Usually this is done
+* from dma_dev_setup() which is not called when a device is returned
+* from VFIO so do it here.
+*/
+   if (pe->pdev)
+   set_iommu_table_base(>pdev->dev, tbl);
+
return 0;
 }
 
@@ -2543,6 +2551,8 @@ static void pnv_ioda2_take_ownership(struct 
iommu_table_group *table_group)
pnv_pci_ioda2_unset_window(>table_group, 0);
if (pe->pbus)
pnv_ioda_setup_bus_dma(pe, pe->pbus);
+   else if (pe->pdev)
+   set_iommu_table_base(>pdev->dev, NULL);
iommu_tce_table_put(tbl);
 }
 
-- 
2.17.1



[PATCH 5/5] powerpc/64s/exception: simplify hmi control flow

2019-06-28 Thread Nicholas Piggin
Branch to the relocated 0xc000 address early (still in real mode), to
simplify subsequent branches. Have the virt mode handler avoid just
'windup' and redo the exception from scratch, rather than branching
back to the trampoline.

Rearrange the stack setup instruction location to match the system
reset handler (e.g., right before EXCEPTION_PROLOG_COMMON).

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 26 ++
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 23aba27b2f59..a91541956aa0 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -260,17 +260,6 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
mtctr   reg;\
bctr
 
-#ifdef CONFIG_RELOCATABLE
-#define BRANCH_LINK_TO_FAR(label)  \
-   __LOAD_FAR_HANDLER(r12, label); \
-   mtctr   r12;\
-   bctrl
-
-#else
-#define BRANCH_LINK_TO_FAR(label)  \
-   bl  label
-#endif
-
 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
 /*
@@ -1713,22 +1702,26 @@ EXC_REAL_BEGIN(hmi_exception, 0xe60, 0x20)
EXCEPTION_PROLOG_0 PACA_EXGEN
b   hmi_exception_early
 EXC_REAL_END(hmi_exception, 0xe60, 0x20)
-__TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
 EXC_VIRT_NONE(0x4e60, 0x20)
 TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
 TRAMP_REAL_BEGIN(hmi_exception_early)
EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0xe60, 0, 0, 0
+   mfctr   r10 /* save ctr, even for !RELOCATABLE */
+   BRANCH_TO_C000(r11, hmi_exception_early_common)
+
+EXC_COMMON_BEGIN(hmi_exception_early_common)
+   mtctr   r10 /* Restore ctr */
+   mfspr   r11,SPRN_HSRR0  /* Save HSRR0 */
+   mfspr   r12,SPRN_HSRR1  /* Save HSRR1 */
mr  r10,r1  /* Save r1 */
ld  r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
subir1,r1,INT_FRAME_SIZE/* alloc stack frame*/
-   mfspr   r11,SPRN_HSRR0  /* Save HSRR0 */
-   mfspr   r12,SPRN_HSRR1  /* Save HSRR1 */
EXCEPTION_PROLOG_COMMON_1()
/* We don't touch AMR here, we never go to virtual mode */
EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
EXCEPTION_PROLOG_COMMON_3(0xe60)
addir3,r1,STACK_FRAME_OVERHEAD
-   BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI 
*/
+   bl  hmi_exception_realmode
cmpdi   cr0,r3,0
bne 1f
 
@@ -1742,7 +1735,8 @@ TRAMP_REAL_BEGIN(hmi_exception_early)
 */
EXCEPTION_RESTORE_REGS EXC_HV
EXCEPTION_PROLOG_0 PACA_EXGEN
-   b   tramp_real_hmi_exception
+   EXCEPTION_PROLOG_1 EXC_HV, PACA_EXGEN, 1, 0xe60, 0, 0, IRQS_DISABLED
+   EXCEPTION_PROLOG_2_REAL hmi_exception_common, EXC_HV, 1
 
 EXC_COMMON_BEGIN(hmi_exception_common)
EXCEPTION_COMMON(PACA_EXGEN, 0xe60)
-- 
2.20.1



[PATCH 4/5] powerpc/64s/exception: hmi remove special case macro

2019-06-28 Thread Nicholas Piggin
No code change.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 16 
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 89ea4f3b07cb..23aba27b2f59 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -519,11 +519,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
  *
  * There can be combinations, e.g., EXC_VIRT_OOL_MASKABLE_HV
  *
- * The one unusual case is __EXC_REAL_OOL_HV_DIRECT, which is
- * an OOL vector that branches to a specified handler rather than the usual
- * trampoline that goes to common. It, and other underscore macros, should
- * be used with care.
- *
  * KVM handlers come in the following verieties:
  * TRAMP_KVM
  * TRAMP_KVM_SKIP
@@ -614,12 +609,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
__EXC_REAL_OOL_MASKABLE(name, start, size); \
__TRAMP_REAL_OOL_MASKABLE(name, start, bitmask)
 
-#define __EXC_REAL_OOL_HV_DIRECT(name, start, size, handler)   \
-   EXC_REAL_BEGIN(name, start, size);  \
-   EXCEPTION_PROLOG_0 PACA_EXGEN ; \
-   b   handler;\
-   EXC_REAL_END(name, start, size)
-
 #define __EXC_REAL_OOL_HV(name, start, size)   \
__EXC_REAL_OOL(name, start, size)
 
@@ -1720,7 +1709,10 @@ EXC_COMMON(emulation_assist_common, 0xe40, 
emulation_assist_interrupt)
  * first, and then eventaully from there to the trampoline to get into virtual
  * mode.
  */
-__EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
+EXC_REAL_BEGIN(hmi_exception, 0xe60, 0x20)
+   EXCEPTION_PROLOG_0 PACA_EXGEN
+   b   hmi_exception_early
+EXC_REAL_END(hmi_exception, 0xe60, 0x20)
 __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
 EXC_VIRT_NONE(0x4e60, 0x20)
 TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
-- 
2.20.1



[PATCH 3/5] powerpc/64s/exception: sreset move trampoline ahead of common code

2019-06-28 Thread Nicholas Piggin
Follow convention and move tramp ahead of common.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 4b33aadd142c..89ea4f3b07cb 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -884,6 +884,18 @@ TRAMP_REAL_BEGIN(system_reset_idle_wake)
BRANCH_TO_C000(r12, idle_return_gpr_loss)
 #endif
 
+#ifdef CONFIG_PPC_PSERIES
+/*
+ * Vectors for the FWNMI option.  Share common code.
+ */
+TRAMP_REAL_BEGIN(system_reset_fwnmi)
+   /* See comment at system_reset exception, don't turn on RI */
+   EXCEPTION_PROLOG_0 PACA_EXNMI
+   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXNMI, 0, 0x100, 0, 0, 0
+   EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
+
+#endif /* CONFIG_PPC_PSERIES */
+
 EXC_COMMON_BEGIN(system_reset_common)
/*
 * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
@@ -941,18 +953,6 @@ EXC_COMMON_BEGIN(system_reset_common)
EXCEPTION_RESTORE_REGS EXC_STD
RFI_TO_USER_OR_KERNEL
 
-#ifdef CONFIG_PPC_PSERIES
-/*
- * Vectors for the FWNMI option.  Share common code.
- */
-TRAMP_REAL_BEGIN(system_reset_fwnmi)
-   /* See comment at system_reset exception, don't turn on RI */
-   EXCEPTION_PROLOG_0 PACA_EXNMI
-   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXNMI, 0, 0x100, 0, 0, 0
-   EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
-
-#endif /* CONFIG_PPC_PSERIES */
-
 
 EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
/* This is moved out of line as it can be patched by FW, but
-- 
2.20.1



[PATCH 2/5] powerpc/64s/exception: optimise system_reset for idle, clean up non-idle case

2019-06-28 Thread Nicholas Piggin
The idle wake up code in the system reset interrupt is not very
optimal. There are two requirements: perform idle wake up quickly;
and save everything including CFAR for non-idle interrupts, with
no performance requirement.

The problem with placing the idle test in the middle of the handler
and using the normal handler code to save CFAR, is that it's quite
costly (e.g., mfcfar is serialising, speculative workarounds get
applied, SRR1 has to be reloaded, etc). It also prevents the standard
interrupt handler boilerplate being used.

This pain can be avoided by using a dedicated idle interrupt handler
at the start of the interrupt handler, which restores all registers
back to the way they were in case it was not an idle wake up. CFAR
is preserved without saving it before the non-idle case by making that
the fall-through, and idle is a taken branch.

Performance seems to be in the noise, but possibly around 0.5% faster,
the executed instructions certainly look better. The bigger benefit is
being able to drop in standard interrupt handlers after the idle code,
which helps with subsequent cleanup and consolidation.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64s.S | 69 +++-
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 9aafe86193db..4b33aadd142c 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -256,7 +256,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
  * load KBASE for a slight optimisation.
  */
 #define BRANCH_TO_C000(reg, label) \
-   __LOAD_HANDLER(reg, label); \
+   __LOAD_FAR_HANDLER(reg, label); \
mtctr   reg;\
bctr
 
@@ -822,15 +822,6 @@ EXC_VIRT_NONE(0x4000, 0x100)
 
 
 EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
-   EXCEPTION_PROLOG_0 PACA_EXNMI
-
-   /* This is EXCEPTION_PROLOG_1 with the idle feature section added */
-   OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_PPR, r9, CPU_FTR_HAS_PPR)
-   OPT_SAVE_REG_TO_PACA(PACA_EXNMI+EX_CFAR, r10, CPU_FTR_CFAR)
-   INTERRUPT_TO_KERNEL
-   SAVE_CTR(r10, PACA_EXNMI)
-   mfcrr9
-
 #ifdef CONFIG_PPC_P7_NAP
/*
 * If running native on arch 2.06 or later, check if we are waking up
@@ -838,43 +829,59 @@ EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
 * bits 46:47. A non-0 value indicates that we are coming from a power
 * saving state. The idle wakeup handler initially runs in real mode,
 * but we branch to the 0xc000... address so we can turn on relocation
-* with mtmsr.
+* with mtmsrd later, after SPRs are restored.
+*
+* Careful to minimise cost for the fast path (idle wakeup) while
+* also avoiding clobbering CFAR for the debug path (non-idle).
+*
+* For the idle wake case volatile registers can be clobbered, which
+* is why we use those initially. If it turns out to not be an idle
+* wake, carefully put everything back the way it was, so we can use
+* common exception macros to handle it.
 */
 BEGIN_FTR_SECTION
-   mfspr   r10,SPRN_SRR1
-   rlwinm. r10,r10,47-31,30,31
-   beq-1f
-   cmpwi   cr1,r10,2
+   SET_SCRATCH0(r13)
+   GET_PACA(r13)
+   std r3,PACA_EXNMI+0*8(r13)
+   std r4,PACA_EXNMI+1*8(r13)
+   std r5,PACA_EXNMI+2*8(r13)
mfspr   r3,SPRN_SRR1
-   bltlr   cr1 /* no state loss, return to idle caller */
-   BRANCH_TO_C000(r10, system_reset_idle_common)
-1:
+   mfocrf  r4,0x80
+   rlwinm. r5,r3,47-31,30,31
+   bne+system_reset_idle_wake
+   /* Not powersave wakeup. Restore regs for regular interrupt handler. */
+   mtocrf  0x80,r4
+   ld  r3,PACA_EXNMI+0*8(r13)
+   ld  r4,PACA_EXNMI+1*8(r13)
+   ld  r5,PACA_EXNMI+2*8(r13)
+   GET_SCRATCH0(r13)
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 #endif
 
-   KVMTEST EXC_STD 0x100
-   std r11,PACA_EXNMI+EX_R11(r13)
-   std r12,PACA_EXNMI+EX_R12(r13)
-   GET_SCRATCH0(r10)
-   std r10,PACA_EXNMI+EX_R13(r13)
-
+   EXCEPTION_PROLOG_0 PACA_EXNMI
+   EXCEPTION_PROLOG_1 EXC_STD, PACA_EXNMI, 1, 0x100, 0, 0, 0
EXCEPTION_PROLOG_2_REAL system_reset_common, EXC_STD, 0
/*
 * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
 * being used, so a nested NMI exception would corrupt it.
+*
+* In theory, we should not enable relocation here if it was disabled
+* in SRR1, because the MMU may not be configured to support it (e.g.,
+* SLB may have been cleared). In practice, there should only be a few
+* small windows where that's the case, and sreset is considered to
+

[PATCH 1/5] powerpc/64s/exception: remove bad stack branch

2019-06-28 Thread Nicholas Piggin
The bad stack test in interrupt handlers has a few problems. For
performance it is taken in the common case, which is a fetch bubble
and a waste of i-cache.

For code development and maintainence, it requires yet another stack
frame setup routine, and that constrains all exception handlers to
follow the same register save pattern which inhibits future
optimisation.

Remove the test/branch and replace it with a trap. Teach the program
check handler to use the emergency stack for this case.

This does not result in quite so nice a message, however the SRR0 and
SRR1 of the crashed interrupt can be seen in r11 and r12, as is the
original r1 (adjusted by INT_FRAME_SIZE). These are the most important
parts to debugging the issue.

The original r9-12 and cr0 is lost, which is the main downside.

  kernel BUG at linux/arch/powerpc/kernel/exceptions-64s.S:847!
  Oops: Exception in kernel mode, sig: 5 [#1]
  BE SMP NR_CPUS=2048 NUMA PowerNV
  Modules linked in:
  CPU: 0 PID: 1 Comm: swapper/0 Not tainted
  NIP:  c0009108 LR: c0cadbcc CTR: c00090f0
  REGS: c000fffcbd70 TRAP: 0700   Not tainted
  MSR:  90021032   CR: 28222448  XER: 2004
  CFAR: c0009100 IRQMASK: 0
  GPR00: 003d fd00 c18cfb00 c000f02b3166
  GPR04: fffd 0007 fffb 0030
  GPR08: 0037 28222448  c0ca8de0
  GPR12: 92009032 c1ae c0010a00 
  GPR16:    
  GPR20: c000f00322c0 c0f85200 0004 
  GPR24: fffe   000a
  GPR28:   c000f02b391c c000f02b3167
  NIP [c0009108] decrementer_common+0x18/0x160
  LR [c0cadbcc] .vsnprintf+0x3ec/0x4f0
  Call Trace:
  Instruction dump:
  996d098a 994d098b 38610070 480246ed 48005518 6000 3820 718a4000
  7c2a0b78 3821fd00 41c20008 e82d0970 <0981fd00> f92101a0 f9610170 f9810178

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/exception-64s.h |  7 --
 arch/powerpc/include/asm/paca.h  |  2 +
 arch/powerpc/kernel/asm-offsets.c|  2 +
 arch/powerpc/kernel/exceptions-64s.S | 96 
 arch/powerpc/xmon/xmon.c |  2 +
 5 files changed, 22 insertions(+), 87 deletions(-)

diff --git a/arch/powerpc/include/asm/exception-64s.h 
b/arch/powerpc/include/asm/exception-64s.h
index 2e919253a075..33f4f72eb035 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -44,13 +44,6 @@
  */
 #define MAX_MCE_DEPTH  4
 
-/*
- * EX_R3 is only used by the bad_stack handler. bad_stack reloads and
- * saves DAR from SPRN_DAR, and EX_DAR is not used. So EX_R3 can overlap
- * with EX_DAR.
- */
-#define EX_R3  EX_DAR
-
 #ifdef __ASSEMBLY__
 
 #define STF_ENTRY_BARRIER_SLOT \
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 9bd2326bef6f..e3cc9eb9204d 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -166,7 +166,9 @@ struct paca_struct {
u64 kstack; /* Saved Kernel stack addr */
u64 saved_r1;   /* r1 save for RTAS calls or PM or EE=0 
*/
u64 saved_msr;  /* MSR saved here by enter_rtas */
+#ifdef CONFIG_PPC_BOOK3E
u16 trap_save;  /* Used when bad stack is encountered */
+#endif
u8 irq_soft_mask;   /* mask for irq soft masking */
u8 irq_happened;/* irq happened while soft-disabled */
u8 irq_work_pending;/* IRQ_WORK interrupt while 
soft-disable */
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 31dc7e64cbfc..4ccb6b3a7fbd 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -266,7 +266,9 @@ int main(void)
OFFSET(ACCOUNT_STARTTIME_USER, paca_struct, accounting.starttime_user);
OFFSET(ACCOUNT_USER_TIME, paca_struct, accounting.utime);
OFFSET(ACCOUNT_SYSTEM_TIME, paca_struct, accounting.stime);
+#ifdef CONFIG_PPC_BOOK3E
OFFSET(PACA_TRAP_SAVE, paca_struct, trap_save);
+#endif
OFFSET(PACA_SPRG_VDSO, paca_struct, sprg_vdso);
 #else /* CONFIG_PPC64 */
 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index 0857c696480c..9aafe86193db 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -411,14 +411,8 @@ END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);
   \
subir1,r1,INT_FRAME_SIZE;   /* alloc frame on kernel stack  */ \
beq-1f; 

[PATCH 0/5] rework bad stack, sreset, hmi handling

2019-06-28 Thread Nicholas Piggin
These are some significant changes to generated code here, again
with the aim of simplifying and improving code sharing.

Patches 1, 2-3, and 4-5 are independent in case any run into problems.

Last big thing to do is machine check I'll try to send out tonight.
After that we can start more unwinding of macros.

[ BTW, the end game here is that each handler should be able to more or
  less specify _what_ it wants to do in macro flags, and the generation
  that takes care of _how_ will mostly be in a single place. e.g.,
  Rather than some magic combination of EXCEPTION_, it will just
  specify that it wants an early realmode handler with an alternate stack. ]

Nicholas Piggin (5):
  powerpc/64s/exception: remove bad stack branch
  powerpc/64s/exception: optimise system_reset for idle, clean up
non-idle case
  powerpc/64s/exception: sreset move trampoline ahead of common code
  powerpc/64s/exception: hmi remove special case macro
  powerpc/64s/exception: simplify hmi control flow

 arch/powerpc/include/asm/exception-64s.h |   7 -
 arch/powerpc/include/asm/paca.h  |   2 +
 arch/powerpc/kernel/asm-offsets.c|   2 +
 arch/powerpc/kernel/exceptions-64s.S | 231 ---
 arch/powerpc/xmon/xmon.c |   2 +
 5 files changed, 86 insertions(+), 158 deletions(-)

-- 
2.20.1