[PATCH 13/13] KVM: PPC: Book3S HV: Treat POWER9 CPU threads as independent subcores

2016-11-17 Thread Paul Mackerras
With POWER9, each CPU thread has its own MMU context and can be
in the host or a guest independently of the other threads; there is
still however a restriction that all threads must use the same type
of address translation, either radix tree or hashed page table (HPT).

Since we only support HPT guests on a HPT host at this point, we
can treat the threads as being independent, and avoid all of the
work of coordinating the CPU threads.  To make this simpler, we
introduce a new threads_per_vcore() function that returns 1 on
POWER9 and threads_per_subcore on POWER7/8, and use that instead
of threads_per_subcore or threads_per_core in various places.

This also changes the value of the KVM_CAP_PPC_SMT capability on
POWER9 systems from 4 to 1, so that userspace will not try to
create VMs with multiple vcpus per vcore.  (If userspace did create
a VM that thought it was in an SMT mode, the VM might try to use
the msgsndp instruction, which will not work as expected.  In
future it may be possible to trap and emulate msgsndp in order to
allow VMs to think they are in an SMT mode, if only for the purpose
of allowing migration from POWER8 systems.)

With all this, we can now run guests on POWER9 as long as the host
is running with HPT translation.  Since userspace currently has no
way to request radix tree translation for the guest, the guest has
no choice but to use HPT translation.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv.c | 36 +---
 arch/powerpc/kvm/powerpc.c   | 11 +++
 2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index a1d2b5f..591ac84 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1569,6 +1569,20 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, 
u64 id,
return r;
 }
 
+/*
+ * On POWER9, threads are independent and can be in different partitions.
+ * Therefore we consider each thread to be a subcore.
+ * There is a restriction that all threads have to be in the same
+ * MMU mode (radix or HPT), unfortunately, but since we only support
+ * HPT guests on a HPT host so far, that isn't an impediment yet.
+ */
+static int threads_per_vcore(void)
+{
+   if (cpu_has_feature(CPU_FTR_ARCH_300))
+   return 1;
+   return threads_per_subcore;
+}
+
 static struct kvmppc_vcore *kvmppc_vcore_create(struct kvm *kvm, int core)
 {
struct kvmppc_vcore *vcore;
@@ -1583,7 +1597,7 @@ static struct kvmppc_vcore *kvmppc_vcore_create(struct 
kvm *kvm, int core)
init_swait_queue_head(>wq);
vcore->preempt_tb = TB_NIL;
vcore->lpcr = kvm->arch.lpcr;
-   vcore->first_vcpuid = core * threads_per_subcore;
+   vcore->first_vcpuid = core * threads_per_vcore();
vcore->kvm = kvm;
INIT_LIST_HEAD(>preempt_list);
 
@@ -1746,7 +1760,7 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct 
kvm *kvm,
int core;
struct kvmppc_vcore *vcore;
 
-   core = id / threads_per_subcore;
+   core = id / threads_per_vcore();
if (core >= KVM_MAX_VCORES)
goto out;
 
@@ -2336,6 +2350,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore 
*vc)
unsigned long cmd_bit, stat_bit;
int pcpu, thr;
int target_threads;
+   int controlled_threads;
 
/*
 * Remove from the list any threads that have a signal pending
@@ -2354,11 +2369,18 @@ static noinline void kvmppc_run_core(struct 
kvmppc_vcore *vc)
vc->preempt_tb = TB_NIL;
 
/*
+* Number of threads that we will be controlling: the same as
+* the number of threads per subcore, except on POWER9,
+* where it's 1 because the threads are (mostly) independent.
+*/
+   controlled_threads = threads_per_vcore();
+
+   /*
 * Make sure we are running on primary threads, and that secondary
 * threads are offline.  Also check if the number of threads in this
 * guest are greater than the current system threads per guest.
 */
-   if ((threads_per_core > 1) &&
+   if ((controlled_threads > 1) &&
((vc->num_threads > threads_per_subcore) || !on_primary_thread())) {
for_each_runnable_thread(i, vcpu, vc) {
vcpu->arch.ret = -EBUSY;
@@ -2374,7 +2396,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore 
*vc)
 */
init_core_info(_info, vc);
pcpu = smp_processor_id();
-   target_threads = threads_per_subcore;
+   target_threads = controlled_threads;
if (target_smt_mode && target_smt_mode < target_threads)
target_threads = target_smt_mode;
if (vc->num_threads < target_threads)
@@ -2410,7 +2432,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore 
*vc)
smp_wmb();
}
pcpu = smp_processor_id();
-   for 

[PATCH 12/13] KVM: PPC: Book3S HV: Use stop instruction rather than nap on POWER9

2016-11-17 Thread Paul Mackerras
POWER9 replaces the various power-saving mode instructions on POWER8
(doze, nap, sleep and rvwinkle) with a single "stop" instruction, plus
a register, PSSCR, which controls the depth of the power-saving mode.
This replaces the use of the nap instruction when threads are idle
during guest execution with the stop instruction, and adds code to
set PSSCR to a value which will allow an SMT mode switch while the
thread is idle (given that the core as a whole won't be idle in these
cases).

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 29 ++---
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index acae5c3..e9eaff4 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -501,17 +501,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
cmpwi   r0, 0
beq 57f
li  r3, (LPCR_PECEDH | LPCR_PECE0) >> 4
-   mfspr   r4, SPRN_LPCR
-   rlwimi  r4, r3, 4, (LPCR_PECEDP | LPCR_PECEDH | LPCR_PECE0 | LPCR_PECE1)
-   mtspr   SPRN_LPCR, r4
-   isync
-   std r0, HSTATE_SCRATCH0(r13)
-   ptesync
-   ld  r0, HSTATE_SCRATCH0(r13)
-1: cmpdr0, r0
-   bne 1b
-   nap
-   b   .
+   mfspr   r5, SPRN_LPCR
+   rlwimi  r5, r3, 4, (LPCR_PECEDP | LPCR_PECEDH | LPCR_PECE0 | LPCR_PECE1)
+   b   kvm_nap_sequence
 
 57:li  r0, 0
stbxr0, r3, r4
@@ -2256,6 +2248,17 @@ BEGIN_FTR_SECTION
ori r5, r5, LPCR_PECEDH
rlwimi  r5, r3, 0, LPCR_PECEDP
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
+
+kvm_nap_sequence:  /* desired LPCR value in r5 */
+BEGIN_FTR_SECTION
+   /*
+* PSSCR bits:  exit criterion = 1 (wakeup based on LPCR at sreset)
+*  enable state loss = 1 (allow SMT mode switch)
+*  requested level = 0 (just stop dispatching)
+*/
+   lis r3, (PSSCR_EC | PSSCR_ESL)@h
+   mtspr   SPRN_PSSCR, r3
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
mtspr   SPRN_LPCR,r5
isync
li  r0, 0
@@ -2264,7 +2267,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
ld  r0, HSTATE_SCRATCH0(r13)
 1: cmpdr0, r0
bne 1b
+BEGIN_FTR_SECTION
nap
+FTR_SECTION_ELSE
+   PPC_STOP
+ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300)
b   .
 
 33:mr  r4, r3
-- 
2.7.4



[PATCH 11/13] KVM: PPC: Book3S HV: Use OPAL XICS emulation on POWER9

2016-11-17 Thread Paul Mackerras
POWER9 includes a new interrupt controller, called XIVE, which is
quite different from the XICS interrupt controller on POWER7 and
POWER8 machines.  KVM-HV accesses the XICS directly in several places
in order to send and clear IPIs and handle interrupts from PCI
devices being passed through to the guest.

In order to make the transition to XIVE easier, OPAL firmware will
include an emulation of XICS on top of XIVE.  Access to the emulated
XICS is via OPAL calls.  The one complication is that the EOI
(end-of-interrupt) function can now return a value indicating that
another interrupt is pending; in this case, the XIVE will not signal
an interrupt in hardware to the CPU, and software is supposed to
acknowledge the new interrupt without waiting for another interrupt
to be delivered in hardware.

This adapts KVM-HV to use the OPAL calls on machines where there is
no XICS hardware.  When there is no XICS, we look for a device-tree
node with "ibm,opal-intc" in its compatible property, which is how
OPAL indicates that it provides XICS emulation.

In order to handle the EOI return value, kvmppc_read_intr() has
become kvmppc_read_one_intr(), with a boolean variable passed by
reference which can be set by the EOI functions to indicate that
another interrupt is pending.  The new kvmppc_read_intr() keeps
calling kvmppc_read_one_intr() until there are no more interrupts
to process.  The return value from kvmppc_read_intr() is the
largest non-zero value of the returns from kvmppc_read_one_intr().

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/include/asm/kvm_ppc.h   |  7 +++--
 arch/powerpc/kvm/book3s_hv.c | 28 +++--
 arch/powerpc/kvm/book3s_hv_builtin.c | 59 ++--
 arch/powerpc/kvm/book3s_hv_rm_xics.c | 23 ++
 4 files changed, 96 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index f6e4964..a5b94be 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -483,9 +483,10 @@ extern void kvmppc_xics_set_mapped(struct kvm *kvm, 
unsigned long guest_irq,
   unsigned long host_irq);
 extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
   unsigned long host_irq);
-extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, u32 xirr,
-struct kvmppc_irq_map *irq_map,
-struct kvmppc_passthru_irqmap *pimap);
+extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, __be32 xirr,
+   struct kvmppc_irq_map *irq_map,
+   struct kvmppc_passthru_irqmap *pimap,
+   bool *again);
 extern int h_ipi_redirect;
 #else
 static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index ace89df..a1d2b5f 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -55,6 +55,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -63,6 +65,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "book3s.h"
 
@@ -172,8 +175,12 @@ static bool kvmppc_ipi_thread(int cpu)
}
 
 #if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
-   if (cpu >= 0 && cpu < nr_cpu_ids && paca[cpu].kvm_hstate.xics_phys) {
-   xics_wake_cpu(cpu);
+   if (cpu >= 0 && cpu < nr_cpu_ids) {
+   if (paca[cpu].kvm_hstate.xics_phys) {
+   xics_wake_cpu(cpu);
+   return true;
+   }
+   opal_int_set_mfrr(get_hard_smp_processor_id(cpu), IPI_PRIORITY);
return true;
}
 #endif
@@ -3729,6 +3736,23 @@ static int kvmppc_book3s_init_hv(void)
if (r)
return r;
 
+   /*
+* We need a way of accessing the XICS interrupt controller,
+* either directly, via paca[cpu].kvm_hstate.xics_phys, or
+* indirectly, via OPAL.
+*/
+#ifdef CONFIG_SMP
+   if (!get_paca()->kvm_hstate.xics_phys) {
+   struct device_node *np;
+
+   np = of_find_compatible_node(NULL, NULL, "ibm,opal-intc");
+   if (!np) {
+   pr_err("KVM-HV: Cannot determine method for accessing 
XICS\n");
+   return -ENODEV;
+   }
+   }
+#endif
+
kvm_ops_hv.owner = THIS_MODULE;
kvmppc_hv_ops = _ops_hv;
 
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c 
b/arch/powerpc/kvm/book3s_hv_builtin.c
index 37ed045..a09c917 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define KVM_CMA_CHUNK_ORDER18
 
@@ -224,7 +225,11 @@ void 

[PATCH 10/13] KVM: PPC: Book3S HV: Use msgsnd for IPIs to other cores on POWER9

2016-11-17 Thread Paul Mackerras
On POWER9, the msgsnd instruction is able to send interrupts to
other cores, as well as other threads on the local core.  Since
msgsnd is generally simpler and faster than sending an IPI via the
XICS, we use msgsnd for all IPIs sent by KVM on POWER9.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv.c | 11 ++-
 arch/powerpc/kvm/book3s_hv_builtin.c | 10 --
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 8395a7f..ace89df 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -147,12 +147,21 @@ static inline struct kvm_vcpu 
*next_runnable_thread(struct kvmppc_vcore *vc,
 
 static bool kvmppc_ipi_thread(int cpu)
 {
+   unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
+
+   /* On POWER9 we can use msgsnd to IPI any cpu */
+   if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+   msg |= get_hard_smp_processor_id(cpu);
+   smp_mb();
+   __asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
+   return true;
+   }
+
/* On POWER8 for IPIs to threads in the same core, use msgsnd */
if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
preempt_disable();
if (cpu_first_thread_sibling(cpu) ==
cpu_first_thread_sibling(smp_processor_id())) {
-   unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
msg |= cpu_thread_in_core(cpu);
smp_mb();
__asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c 
b/arch/powerpc/kvm/book3s_hv_builtin.c
index 0c84d6b..37ed045 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -205,12 +205,18 @@ static inline void rm_writeb(unsigned long paddr, u8 val)
 void kvmhv_rm_send_ipi(int cpu)
 {
unsigned long xics_phys;
+   unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
 
-   /* On POWER8 for IPIs to threads in the same core, use msgsnd */
+   /* On POWER9 we can use msgsnd for any destination cpu. */
+   if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+   msg |= get_hard_smp_processor_id(cpu);
+   __asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
+   return;
+   }
+   /* On POWER8 for IPIs to threads in the same core, use msgsnd. */
if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
cpu_first_thread_sibling(cpu) ==
cpu_first_thread_sibling(raw_smp_processor_id())) {
-   unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
msg |= cpu_thread_in_core(cpu);
__asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
return;
-- 
2.7.4



[PATCH 09/13] KVM: PPC: Book3S HV: Adapt TLB invalidations to work on POWER9

2016-11-17 Thread Paul Mackerras
POWER9 adds new capabilities to the tlbie (TLB invalidate entry)
and tlbiel (local tlbie) instructions.  Both instructions get a
set of new parameters (RIC, PRS and R) which appear as bits in the
instruction word.  The tlbiel instruction now has a second register
operand, which contains a PID and/or LPID value if needed, and
should otherwise contain 0.

This adapts KVM-HV's usage of tlbie and tlbiel to work on POWER9
as well as older processors.  Since we only handle HPT guests so
far, we need RIC=0 PRS=0 R=0, which ends up with the same instruction
word as on previous processors, so we don't need to conditionally
execute different instructions depending on the processor.

The local flush on first entry to a guest in book3s_hv_rmhandlers.S
is a loop which depends on the number of TLB sets.  Rather than
using feature sections to set the number of iterations based on
which CPU we're on, we now work out this number at VM creation time
and store it in the kvm_arch struct.  That will make it possible to
get the number from the device tree in future, which will help with
compatibility with future processors.

Since mmu_partition_table_set_entry() does a global flush of the
whole LPID, we don't need to do the TLB flush on first entry to the
guest on each processor.  Therefore we don't set all bits in the
tlb_need_flush bitmap on VM startup on POWER9.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/include/asm/kvm_host.h |  1 +
 arch/powerpc/kernel/asm-offsets.c   |  1 +
 arch/powerpc/kvm/book3s_hv.c| 17 -
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 10 --
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |  8 ++--
 5 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 0d94608..ea78864 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -244,6 +244,7 @@ struct kvm_arch_memory_slot {
 struct kvm_arch {
unsigned int lpid;
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+   unsigned int tlb_sets;
unsigned long hpt_virt;
struct revmap_entry *revmap;
atomic64_t mmio_update;
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 494241b..b9c8386 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -487,6 +487,7 @@ int main(void)
 
/* book3s */
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+   DEFINE(KVM_TLB_SETS, offsetof(struct kvm, arch.tlb_sets));
DEFINE(KVM_SDR1, offsetof(struct kvm, arch.sdr1));
DEFINE(KVM_HOST_LPID, offsetof(struct kvm, arch.host_lpid));
DEFINE(KVM_HOST_LPCR, offsetof(struct kvm, arch.host_lpcr));
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 59e18dfb..8395a7f 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3260,8 +3260,11 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
 * Since we don't flush the TLB when tearing down a VM,
 * and this lpid might have previously been used,
 * make sure we flush on each core before running the new VM.
+* On POWER9, the tlbie in mmu_partition_table_set_entry()
+* does this flush for us.
 */
-   cpumask_setall(>arch.need_tlb_flush);
+   if (!cpu_has_feature(CPU_FTR_ARCH_300))
+   cpumask_setall(>arch.need_tlb_flush);
 
/* Start out with the default set of hcalls enabled */
memcpy(kvm->arch.enabled_hcalls, default_enabled_hcalls,
@@ -3287,6 +3290,17 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
kvm->arch.lpcr = lpcr;
 
/*
+* Work out how many sets the TLB has, for the use of
+* the TLB invalidation loop in book3s_hv_rmhandlers.S.
+*/
+   if (cpu_has_feature(CPU_FTR_ARCH_300))
+   kvm->arch.tlb_sets = 256;   /* POWER9 */
+   else if (cpu_has_feature(CPU_FTR_ARCH_207S))
+   kvm->arch.tlb_sets = 512;   /* POWER8 */
+   else
+   kvm->arch.tlb_sets = 128;   /* POWER7 */
+
+   /*
 * Track that we now have a HV mode VM active. This blocks secondary
 * CPU threads from coming online.
 */
@@ -3728,3 +3742,4 @@ module_exit(kvmppc_book3s_exit_hv);
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_MISCDEV(KVM_MINOR);
 MODULE_ALIAS("devname:kvm");
+
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c 
b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 1179e40..9ef3c4b 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -424,13 +424,18 @@ static void do_tlbies(struct kvm *kvm, unsigned long 
*rbvalues,
 {
long i;
 
+   /*
+* We use the POWER9 5-operand versions of tlbie and tlbiel here.
+* Since we are using RIC=0 PRS=0 R=0, and P7/P8 tlbiel ignores
+* the RS field, this is backwards-compatible with P7 and P8.
+*/
  

[PATCH 08/13] KVM: PPC: Book3S HV: Add new POWER9 guest-accessible SPRs

2016-11-17 Thread Paul Mackerras
This adds code to handle two new guest-accessible special-purpose
registers on POWER9: TIDR (thread ID register) and PSSCR (processor
stop status and control register).  They are context-switched
between host and guest, and the guest values can be read and set
via the one_reg interface.

The PSSCR contains some fields which are guest-accessible and some
which are only accessible in hypervisor mode.  We only allow the
guest-accessible fields to be read or set by userspace.

Signed-off-by: Paul Mackerras 
---
 Documentation/virtual/kvm/api.txt   |  2 ++
 arch/powerpc/include/asm/kvm_host.h |  2 ++
 arch/powerpc/include/uapi/asm/kvm.h |  4 
 arch/powerpc/kernel/asm-offsets.c   |  2 ++
 arch/powerpc/kvm/book3s_hv.c| 12 ++
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 39 +++--
 6 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 739db9a..40b2bfc 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2023,6 +2023,8 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_WORT  | 64
   PPC  | KVM_REG_PPC_SPRG9 | 64
   PPC  | KVM_REG_PPC_DBSR  | 32
+  PPC   | KVM_REG_PPC_TIDR  | 64
+  PPC   | KVM_REG_PPC_PSSCR | 64
   PPC   | KVM_REG_PPC_TM_GPR0   | 64
   ...
   PPC   | KVM_REG_PPC_TM_GPR31  | 64
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 20ef27d..0d94608 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -517,6 +517,8 @@ struct kvm_vcpu_arch {
ulong tcscr;
ulong acop;
ulong wort;
+   ulong tid;
+   ulong psscr;
ulong shadow_srr1;
 #endif
u32 vrsave; /* also USPRG0 */
diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
b/arch/powerpc/include/uapi/asm/kvm.h
index c93cf35..f0bae66 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -573,6 +573,10 @@ struct kvm_get_htab_header {
 #define KVM_REG_PPC_SPRG9  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xba)
 #define KVM_REG_PPC_DBSR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbb)
 
+/* POWER9 registers */
+#define KVM_REG_PPC_TIDR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbc)
+#define KVM_REG_PPC_PSSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbd)
+
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
  */
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index caec7bf..494241b 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -548,6 +548,8 @@ int main(void)
DEFINE(VCPU_TCSCR, offsetof(struct kvm_vcpu, arch.tcscr));
DEFINE(VCPU_ACOP, offsetof(struct kvm_vcpu, arch.acop));
DEFINE(VCPU_WORT, offsetof(struct kvm_vcpu, arch.wort));
+   DEFINE(VCPU_TID, offsetof(struct kvm_vcpu, arch.tid));
+   DEFINE(VCPU_PSSCR, offsetof(struct kvm_vcpu, arch.psscr));
DEFINE(VCORE_ENTRY_EXIT, offsetof(struct kvmppc_vcore, entry_exit_map));
DEFINE(VCORE_IN_GUEST, offsetof(struct kvmppc_vcore, in_guest));
DEFINE(VCORE_NAPPING_THREADS, offsetof(struct kvmppc_vcore, 
napping_threads));
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 5cbe3c3..59e18dfb 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1230,6 +1230,12 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, 
u64 id,
case KVM_REG_PPC_WORT:
*val = get_reg_val(id, vcpu->arch.wort);
break;
+   case KVM_REG_PPC_TIDR:
+   *val = get_reg_val(id, vcpu->arch.tid);
+   break;
+   case KVM_REG_PPC_PSSCR:
+   *val = get_reg_val(id, vcpu->arch.psscr);
+   break;
case KVM_REG_PPC_VPA_ADDR:
spin_lock(>arch.vpa_update_lock);
*val = get_reg_val(id, vcpu->arch.vpa.next_gpa);
@@ -1428,6 +1434,12 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, 
u64 id,
case KVM_REG_PPC_WORT:
vcpu->arch.wort = set_reg_val(id, *val);
break;
+   case KVM_REG_PPC_TIDR:
+   vcpu->arch.tid = set_reg_val(id, *val);
+   break;
+   case KVM_REG_PPC_PSSCR:
+   vcpu->arch.psscr = set_reg_val(id, *val) & PSSCR_GUEST_VIS;
+   break;
case KVM_REG_PPC_VPA_ADDR:
addr = set_reg_val(id, *val);
r = -EINVAL;
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index d422014..219a04f 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -523,6 +523,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  * 

[PATCH 07/13] KVM: PPC: Book3S HV: Adjust host/guest context switch for POWER9

2016-11-17 Thread Paul Mackerras
Some special-purpose registers that were present and accessible
by guests on POWER8 no longer exist on POWER9, so this adds
feature sections to ensure that we don't try to context-switch
them when going into or out of a guest on POWER9.  These are
all relatively obscure, rarely-used registers, but we had to
context-switch them on POWER8 to avoid creating a covert channel.
They are: SPMC1, SPMC2, MMCRS, CSIGR, TACR, TCSCR, and ACOP.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 50 -
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index dc25467..d422014 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -752,14 +752,16 @@ END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG)
 BEGIN_FTR_SECTION
ld  r5, VCPU_MMCR + 24(r4)
ld  r6, VCPU_SIER(r4)
+   mtspr   SPRN_MMCR2, r5
+   mtspr   SPRN_SIER, r6
+BEGIN_FTR_SECTION_NESTED(96)
lwz r7, VCPU_PMC + 24(r4)
lwz r8, VCPU_PMC + 28(r4)
ld  r9, VCPU_MMCR + 32(r4)
-   mtspr   SPRN_MMCR2, r5
-   mtspr   SPRN_SIER, r6
mtspr   SPRN_SPMC1, r7
mtspr   SPRN_SPMC2, r8
mtspr   SPRN_MMCRS, r9
+END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
mtspr   SPRN_MMCR0, r3
isync
@@ -815,20 +817,22 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
mtspr   SPRN_EBBHR, r8
ld  r5, VCPU_EBBRR(r4)
ld  r6, VCPU_BESCR(r4)
-   ld  r7, VCPU_CSIGR(r4)
-   ld  r8, VCPU_TACR(r4)
+   lwz r7, VCPU_GUEST_PID(r4)
+   ld  r8, VCPU_WORT(r4)
mtspr   SPRN_EBBRR, r5
mtspr   SPRN_BESCR, r6
-   mtspr   SPRN_CSIGR, r7
-   mtspr   SPRN_TACR, r8
+   mtspr   SPRN_PID, r7
+   mtspr   SPRN_WORT, r8
+BEGIN_FTR_SECTION
ld  r5, VCPU_TCSCR(r4)
ld  r6, VCPU_ACOP(r4)
-   lwz r7, VCPU_GUEST_PID(r4)
-   ld  r8, VCPU_WORT(r4)
+   ld  r7, VCPU_CSIGR(r4)
+   ld  r8, VCPU_TACR(r4)
mtspr   SPRN_TCSCR, r5
mtspr   SPRN_ACOP, r6
-   mtspr   SPRN_PID, r7
-   mtspr   SPRN_WORT, r8
+   mtspr   SPRN_CSIGR, r7
+   mtspr   SPRN_TACR, r8
+END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
 8:
 
/*
@@ -1343,20 +1347,22 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
std r8, VCPU_EBBHR(r9)
mfspr   r5, SPRN_EBBRR
mfspr   r6, SPRN_BESCR
-   mfspr   r7, SPRN_CSIGR
-   mfspr   r8, SPRN_TACR
+   mfspr   r7, SPRN_PID
+   mfspr   r8, SPRN_WORT
std r5, VCPU_EBBRR(r9)
std r6, VCPU_BESCR(r9)
-   std r7, VCPU_CSIGR(r9)
-   std r8, VCPU_TACR(r9)
+   stw r7, VCPU_GUEST_PID(r9)
+   std r8, VCPU_WORT(r9)
+BEGIN_FTR_SECTION
mfspr   r5, SPRN_TCSCR
mfspr   r6, SPRN_ACOP
-   mfspr   r7, SPRN_PID
-   mfspr   r8, SPRN_WORT
+   mfspr   r7, SPRN_CSIGR
+   mfspr   r8, SPRN_TACR
std r5, VCPU_TCSCR(r9)
std r6, VCPU_ACOP(r9)
-   stw r7, VCPU_GUEST_PID(r9)
-   std r8, VCPU_WORT(r9)
+   std r7, VCPU_CSIGR(r9)
+   std r8, VCPU_TACR(r9)
+END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
/*
 * Restore various registers to 0, where non-zero values
 * set by the guest could disrupt the host.
@@ -1365,12 +1371,14 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
mtspr   SPRN_IAMR, r0
mtspr   SPRN_CIABR, r0
mtspr   SPRN_DAWRX, r0
-   mtspr   SPRN_TCSCR, r0
mtspr   SPRN_WORT, r0
+BEGIN_FTR_SECTION
+   mtspr   SPRN_TCSCR, r0
/* Set MMCRS to 1<<31 to freeze and disable the SPMC counters */
li  r0, 1
sldir0, r0, 31
mtspr   SPRN_MMCRS, r0
+END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
 8:
 
/* Save and reset AMR and UAMOR before turning on the MMU */
@@ -1504,15 +1512,17 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
stw r8, VCPU_PMC + 20(r9)
 BEGIN_FTR_SECTION
mfspr   r5, SPRN_SIER
+   std r5, VCPU_SIER(r9)
+BEGIN_FTR_SECTION_NESTED(96)
mfspr   r6, SPRN_SPMC1
mfspr   r7, SPRN_SPMC2
mfspr   r8, SPRN_MMCRS
-   std r5, VCPU_SIER(r9)
stw r6, VCPU_PMC + 24(r9)
stw r7, VCPU_PMC + 28(r9)
std r8, VCPU_MMCR + 32(r9)
lis r4, 0x8000
mtspr   SPRN_MMCRS, r4
+END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 22:
/* Clear out SLB */
-- 
2.7.4



[PATCH 06/13] KVM: PPC: Book3S HV: Set partition table rather than SDR1 on POWER9

2016-11-17 Thread Paul Mackerras
On POWER9, the SDR1 register (hashed page table base address) is no
longer used, and instead the hardware reads the HPT base address
and size from the partition table.  The partition table entry also
contains the bits that specify the page size for the VRMA mapping,
which were previously in the LPCR.  The VPM0 bit of the LPCR is
now reserved; the processor now always uses the VRMA (virtual
real-mode area) mechanism for guest real-mode accesses in HPT mode,
and the RMO (real-mode offset) mechanism has been dropped.

When entering or exiting the guest, we now only have to set the
LPIDR (logical partition ID register), not the SDR1 register.
There is also no requirement now to transition via a reserved
LPID value.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv.c| 36 +++--
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 10 ++---
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 40b2b6d..5cbe3c3 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -54,6 +54,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -3024,6 +3025,22 @@ static void kvmppc_mmu_destroy_hv(struct kvm_vcpu *vcpu)
return;
 }
 
+static void kvmppc_setup_partition_table(struct kvm *kvm)
+{
+   unsigned long dw0, dw1;
+
+   /* PS field - page size for VRMA */
+   dw0 = ((kvm->arch.vrma_slb_v & SLB_VSID_L) >> 1) |
+   ((kvm->arch.vrma_slb_v & SLB_VSID_LP) << 1);
+   /* HTABSIZE and HTABORG fields */
+   dw0 |= kvm->arch.sdr1;
+
+   /* Second dword has GR=0; other fields are unused since UPRT=0 */
+   dw1 = 0;
+
+   mmu_partition_table_set_entry(kvm->arch.lpid, dw0, dw1);
+}
+
 static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
 {
int err = 0;
@@ -3075,17 +3092,20 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu 
*vcpu)
  psize == 0x100))
goto out_srcu;
 
-   /* Update VRMASD field in the LPCR */
senc = slb_pgsize_encoding(psize);
kvm->arch.vrma_slb_v = senc | SLB_VSID_B_1T |
(VRMA_VSID << SLB_VSID_SHIFT_1T);
-   /* the -4 is to account for senc values starting at 0x10 */
-   lpcr = senc << (LPCR_VRMASD_SH - 4);
-
/* Create HPTEs in the hash page table for the VRMA */
kvmppc_map_vrma(vcpu, memslot, porder);
 
-   kvmppc_update_lpcr(kvm, lpcr, LPCR_VRMASD);
+   /* Update VRMASD field in the LPCR */
+   if (!cpu_has_feature(CPU_FTR_ARCH_300)) {
+   /* the -4 is to account for senc values starting at 0x10 */
+   lpcr = senc << (LPCR_VRMASD_SH - 4);
+   kvmppc_update_lpcr(kvm, lpcr, LPCR_VRMASD);
+   } else {
+   kvmppc_setup_partition_table(kvm);
+   }
 
/* Order updates to kvm->arch.lpcr etc. vs. hpte_setup_done */
smp_wmb();
@@ -3235,7 +3255,8 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
memcpy(kvm->arch.enabled_hcalls, default_enabled_hcalls,
   sizeof(kvm->arch.enabled_hcalls));
 
-   kvm->arch.host_sdr1 = mfspr(SPRN_SDR1);
+   if (!cpu_has_feature(CPU_FTR_ARCH_300))
+   kvm->arch.host_sdr1 = mfspr(SPRN_SDR1);
 
/* Init LPCR for virtual RMA mode */
kvm->arch.host_lpid = mfspr(SPRN_LPID);
@@ -3248,6 +3269,9 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
/* On POWER8 turn on online bit to enable PURR/SPURR */
if (cpu_has_feature(CPU_FTR_ARCH_207S))
lpcr |= LPCR_ONL;
+   /* On POWER9, VPM0 bit is reserved (VPM0=1 behaviour is assumed) */
+   if (cpu_has_feature(CPU_FTR_ARCH_300))
+   lpcr &= ~LPCR_VPM0;
kvm->arch.lpcr = lpcr;
 
/*
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index c3c1d1b..dc25467 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -581,12 +581,14 @@ kvmppc_hv_entry:
ld  r9,VCORE_KVM(r5)/* pointer to struct kvm */
cmpwi   r6,0
bne 10f
-   ld  r6,KVM_SDR1(r9)
lwz r7,KVM_LPID(r9)
+BEGIN_FTR_SECTION
+   ld  r6,KVM_SDR1(r9)
li  r0,LPID_RSVD/* switch to reserved LPID */
mtspr   SPRN_LPID,r0
ptesync
mtspr   SPRN_SDR1,r6/* switch to partition page table */
+END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
mtspr   SPRN_LPID,r7
isync
 
@@ -1552,12 +1554,14 @@ kvmhv_switch_to_host:
beq 19f
 
/* Primary thread switches back to host partition */
-   ld  r6,KVM_HOST_SDR1(r4)
lwz r7,KVM_HOST_LPID(r4)
+BEGIN_FTR_SECTION
+   ld  r6,KVM_HOST_SDR1(r4)
li  r8,LPID_RSVD/* switch to reserved LPID */
mtspr   SPRN_LPID,r8
ptesync
-   

[PATCH 05/13] KVM: PPC: Book3S HV: Adapt to new HPTE format on POWER9

2016-11-17 Thread Paul Mackerras
This adapts the KVM-HV hashed page table (HPT) code to read and write
HPT entries in the new format defined in Power ISA v3.00 on POWER9
machines.  The new format moves the B (segment size) field from the
first doubleword to the second, and trims some bits from the AVA
(abbreviated virtual address) and ARPN (abbreviated real page number)
fields.  As far as possible, the conversion is done when reading or
writing the HPT entries, and the rest of the code continues to use
the old format.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c |  39 ++
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 101 +---
 2 files changed, 100 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 7755bd0..20a8e8e 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -314,7 +314,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu 
*vcpu, gva_t eaddr,
struct kvmppc_slb *slbe;
unsigned long slb_v;
unsigned long pp, key;
-   unsigned long v, gr;
+   unsigned long v, orig_v, gr;
__be64 *hptep;
int index;
int virtmode = vcpu->arch.shregs.msr & (data ? MSR_DR : MSR_IR);
@@ -339,10 +339,12 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu 
*vcpu, gva_t eaddr,
return -ENOENT;
}
hptep = (__be64 *)(kvm->arch.hpt_virt + (index << 4));
-   v = be64_to_cpu(hptep[0]) & ~HPTE_V_HVLOCK;
+   v = orig_v = be64_to_cpu(hptep[0]) & ~HPTE_V_HVLOCK;
+   if (cpu_has_feature(CPU_FTR_ARCH_300))
+   v = hpte_new_to_old_v(v, be64_to_cpu(hptep[1]));
gr = kvm->arch.revmap[index].guest_rpte;
 
-   unlock_hpte(hptep, v);
+   unlock_hpte(hptep, orig_v);
preempt_enable();
 
gpte->eaddr = eaddr;
@@ -440,6 +442,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 {
struct kvm *kvm = vcpu->kvm;
unsigned long hpte[3], r;
+   unsigned long hnow_v, hnow_r;
__be64 *hptep;
unsigned long mmu_seq, psize, pte_size;
unsigned long gpa_base, gfn_base;
@@ -488,6 +491,10 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
unlock_hpte(hptep, hpte[0]);
preempt_enable();
 
+   if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+   hpte[0] = hpte_new_to_old_v(hpte[0], hpte[1]);
+   hpte[1] = hpte_new_to_old_r(hpte[1]);
+   }
if (hpte[0] != vcpu->arch.pgfault_hpte[0] ||
hpte[1] != vcpu->arch.pgfault_hpte[1])
return RESUME_GUEST;
@@ -599,9 +606,14 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
preempt_disable();
while (!try_lock_hpte(hptep, HPTE_V_HVLOCK))
cpu_relax();
-   if ((be64_to_cpu(hptep[0]) & ~HPTE_V_HVLOCK) != hpte[0] ||
-   be64_to_cpu(hptep[1]) != hpte[1] ||
-   rev->guest_rpte != hpte[2])
+   hnow_v = be64_to_cpu(hptep[0]);
+   hnow_r = be64_to_cpu(hptep[1]);
+   if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+   hnow_v = hpte_new_to_old_v(hnow_v, hnow_r);
+   hnow_r = hpte_new_to_old_r(hnow_r);
+   }
+   if ((hnow_v & ~HPTE_V_HVLOCK) != hpte[0] || hnow_r != hpte[1] ||
+   rev->guest_rpte != hpte[2])
/* HPTE has been changed under us; let the guest retry */
goto out_unlock;
hpte[0] = (hpte[0] & ~HPTE_V_ABSENT) | HPTE_V_VALID;
@@ -632,6 +644,10 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
kvmppc_add_revmap_chain(kvm, rev, rmap, index, 0);
}
 
+   if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+   r = hpte_old_to_new_r(hpte[0], r);
+   hpte[0] = hpte_old_to_new_v(hpte[0]);
+   }
hptep[1] = cpu_to_be64(r);
eieio();
__unlock_hpte(hptep, hpte[0]);
@@ -1183,7 +1199,7 @@ static long record_hpte(unsigned long flags, __be64 *hptp,
unsigned long *hpte, struct revmap_entry *revp,
int want_valid, int first_pass)
 {
-   unsigned long v, r;
+   unsigned long v, r, hr;
unsigned long rcbits_unset;
int ok = 1;
int valid, dirty;
@@ -1210,6 +1226,11 @@ static long record_hpte(unsigned long flags, __be64 
*hptp,
while (!try_lock_hpte(hptp, HPTE_V_HVLOCK))
cpu_relax();
v = be64_to_cpu(hptp[0]);
+   hr = be64_to_cpu(hptp[1]);
+   if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+   v = hpte_new_to_old_v(v, hr);
+   hr = hpte_new_to_old_r(hr);
+   }
 
/* re-evaluate valid and dirty from synchronized HPTE value */
valid = !!(v & HPTE_V_VALID);
@@ -1217,8 +1238,8 

[PATCH 04/13] KVM: PPC: Book3S HV: Don't lose hardware R/C bit updates in H_PROTECT

2016-11-17 Thread Paul Mackerras
The hashed page table MMU in POWER processors can update the R
(reference) and C (change) bits in a HPTE at any time until the
HPTE has been invalidated and the TLB invalidation sequence has
completed.  In kvmppc_h_protect, which implements the H_PROTECT
hypercall, we read the HPTE, modify the second doubleword,
invalidate the HPTE in memory, do the TLB invalidation sequence,
and then write the modified value of the second doubleword back
to memory.  In doing so we could overwrite an R/C bit update done
by hardware between when we read the HPTE and when the TLB
invalidation completed.  To fix this we re-read the second
doubleword after the TLB invalidation and OR in the (possibly)
new values of R and C.  We can use an OR since hardware only ever
sets R and C, never clears them.

This race was found by code inspection.  In principle this bug could
cause occasional guest memory corruption under host memory pressure.

Fixes: a8606e20e41a ("KVM: PPC: Handle some PAPR hcalls in the kernel", 
2011-06-29)
Cc: sta...@vger.kernel.org # v3.19+
Signed-off-by: Paul Mackerras 
---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c 
b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 752451f3..02786b3 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -670,6 +670,8 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long 
flags,
  HPTE_V_ABSENT);
do_tlbies(kvm, , 1, global_invalidates(kvm, flags),
  true);
+   /* Don't lose R/C bit updates done by hardware */
+   r |= be64_to_cpu(hpte[1]) & (HPTE_R_R | HPTE_R_C);
hpte[1] = cpu_to_be64(r);
}
}
-- 
2.7.4



[PATCH 03/13] powerpc/powernv: Define real-mode versions of OPAL XICS accessors

2016-11-17 Thread Paul Mackerras
This defines real-mode versions of opal_int_get_xirr(), opal_int_eoi()
and opal_int_set_mfrr(), for use by KVM real-mode code.

It also exports opal_int_set_mfrr() so that the modular part of KVM
can use it to send IPIs.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/include/asm/opal.h| 3 +++
 arch/powerpc/platforms/powernv/opal-wrappers.S | 3 +++
 arch/powerpc/platforms/powernv/opal.c  | 2 ++
 3 files changed, 8 insertions(+)

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index e958b70..5c7db0f 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -220,9 +220,12 @@ int64_t opal_pci_set_power_state(uint64_t async_token, 
uint64_t id,
 int64_t opal_pci_poll2(uint64_t id, uint64_t data);
 
 int64_t opal_int_get_xirr(uint32_t *out_xirr, bool just_poll);
+int64_t opal_rm_int_get_xirr(__be32 *out_xirr, bool just_poll);
 int64_t opal_int_set_cppr(uint8_t cppr);
 int64_t opal_int_eoi(uint32_t xirr);
+int64_t opal_rm_int_eoi(uint32_t xirr);
 int64_t opal_int_set_mfrr(uint32_t cpu, uint8_t mfrr);
+int64_t opal_rm_int_set_mfrr(uint32_t cpu, uint8_t mfrr);
 int64_t opal_pci_tce_kill(uint64_t phb_id, uint32_t kill_type,
  uint32_t pe_num, uint32_t tce_size,
  uint64_t dma_addr, uint32_t npages);
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S 
b/arch/powerpc/platforms/powernv/opal-wrappers.S
index 44d2d84..3aa40f1 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -304,8 +304,11 @@ OPAL_CALL(opal_pci_get_presence_state, 
OPAL_PCI_GET_PRESENCE_STATE);
 OPAL_CALL(opal_pci_get_power_state,OPAL_PCI_GET_POWER_STATE);
 OPAL_CALL(opal_pci_set_power_state,OPAL_PCI_SET_POWER_STATE);
 OPAL_CALL(opal_int_get_xirr,   OPAL_INT_GET_XIRR);
+OPAL_CALL_REAL(opal_rm_int_get_xirr,   OPAL_INT_GET_XIRR);
 OPAL_CALL(opal_int_set_cppr,   OPAL_INT_SET_CPPR);
 OPAL_CALL(opal_int_eoi,OPAL_INT_EOI);
+OPAL_CALL_REAL(opal_rm_int_eoi,OPAL_INT_EOI);
 OPAL_CALL(opal_int_set_mfrr,   OPAL_INT_SET_MFRR);
+OPAL_CALL_REAL(opal_rm_int_set_mfrr,   OPAL_INT_SET_MFRR);
 OPAL_CALL(opal_pci_tce_kill,   OPAL_PCI_TCE_KILL);
 OPAL_CALL_REAL(opal_rm_pci_tce_kill,   OPAL_PCI_TCE_KILL);
diff --git a/arch/powerpc/platforms/powernv/opal.c 
b/arch/powerpc/platforms/powernv/opal.c
index 6c9a65b..b3b8930 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -896,3 +896,5 @@ EXPORT_SYMBOL_GPL(opal_leds_get_ind);
 EXPORT_SYMBOL_GPL(opal_leds_set_ind);
 /* Export this symbol for PowerNV Operator Panel class driver */
 EXPORT_SYMBOL_GPL(opal_write_oppanel_async);
+/* Export this for KVM */
+EXPORT_SYMBOL_GPL(opal_int_set_mfrr);
-- 
2.7.4



[PATCH 02/13] powerpc/64: Provide functions for accessing POWER9 partition table

2016-11-17 Thread Paul Mackerras
POWER9 requires the host to set up a partition table, which is a
table in memory indexed by logical partition ID (LPID) which
contains the pointers to page tables and process tables for the
host and each guest.

This factors out the initialization of the partition table into
a single function.  This code was previously duplicated between
hash_utils_64.c and pgtable-radix.c.

This provides a function for setting a partition table entry,
which is used in early MMU initialization, and will be used by
KVM whenever a guest is created.  This function includes a tlbie
instruction which will flush all TLB entries for the LPID and
all caches of the partition table entry for the LPID, across the
system.

This also moves a call to memblock_set_current_limit(), which was
in radix_init_partition_table(), but has nothing to do with the
partition table.  By analogy with the similar code for hash, the
call gets moved to near the end of radix__early_init_mmu().  It
now gets called when running as a guest, whereas previously it
would only be called if the kernel is running as the host.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/include/asm/mmu.h  |  5 +
 arch/powerpc/mm/hash_utils_64.c | 28 
 arch/powerpc/mm/pgtable-radix.c | 18 ++
 arch/powerpc/mm/pgtable_64.c| 33 +
 4 files changed, 48 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index e883683..060b40b 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -208,6 +208,11 @@ extern u64 ppc64_rma_size;
 /* Cleanup function used by kexec */
 extern void mmu_cleanup_all(void);
 extern void radix__mmu_cleanup_all(void);
+
+/* Functions for creating and updating partition table on POWER9 */
+extern void mmu_partition_table_init(void);
+extern void mmu_partition_table_set_entry(unsigned int lpid, unsigned long dw0,
+ unsigned long dw1);
 #endif /* CONFIG_PPC64 */
 
 struct mm_struct;
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 44d3c3a..b9a062f 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -792,37 +792,17 @@ static void update_hid_for_hash(void)
 static void __init hash_init_partition_table(phys_addr_t hash_table,
 unsigned long htab_size)
 {
-   unsigned long ps_field;
-   unsigned long patb_size = 1UL << PATB_SIZE_SHIFT;
+   mmu_partition_table_init();
 
/*
-* slb llp encoding for the page size used in VPM real mode.
-* We can ignore that for lpid 0
+* PS field (VRMA page size) is not used for LPID 0, hence set to 0.
+* For now, UPRT is 0 and we have no segment table.
 */
-   ps_field = 0;
htab_size =  __ilog2(htab_size) - 18;
-
-   BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 24), "Partition table size too 
large.");
-   partition_tb = __va(memblock_alloc_base(patb_size, patb_size,
-   MEMBLOCK_ALLOC_ANYWHERE));
-
-   /* Initialize the Partition Table with no entries */
-   memset((void *)partition_tb, 0, patb_size);
-   partition_tb->patb0 = cpu_to_be64(ps_field | hash_table | htab_size);
-   /*
-* FIXME!! This should be done via update_partition table
-* For now UPRT is 0 for us.
-*/
-   partition_tb->patb1 = 0;
+   mmu_partition_table_set_entry(0, hash_table | htab_size, 0);
pr_info("Partition table %p\n", partition_tb);
if (cpu_has_feature(CPU_FTR_POWER9_DD1))
update_hid_for_hash();
-   /*
-* update partition table control register,
-* 64 K size.
-*/
-   mtspr(SPRN_PTCR, __pa(partition_tb) | (PATB_SIZE_SHIFT - 12));
-
 }
 
 static void __init htab_initialize(void)
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index ed7bddc..186f1ad 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -177,23 +177,15 @@ static void __init radix_init_pgtable(void)
 
 static void __init radix_init_partition_table(void)
 {
-   unsigned long rts_field;
+   unsigned long rts_field, dw0;
 
+   mmu_partition_table_init();
rts_field = radix__get_tree_size();
+   dw0 = rts_field | __pa(init_mm.pgd) | RADIX_PGD_INDEX_SIZE | PATB_HR;
+   mmu_partition_table_set_entry(0, dw0, 0);
 
-   BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 24), "Partition table size too 
large.");
-   partition_tb = early_alloc_pgtable(1UL << PATB_SIZE_SHIFT);
-   partition_tb->patb0 = cpu_to_be64(rts_field | __pa(init_mm.pgd) |
- RADIX_PGD_INDEX_SIZE | PATB_HR);
pr_info("Initializing Radix MMU\n");
pr_info("Partition table %p\n", partition_tb);
-
-   

[PATCH 01/13] powerpc/64: Add some more SPRs and SPR bits for POWER9

2016-11-17 Thread Paul Mackerras
These definitions will be needed by KVM.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/include/asm/reg.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 9cd4e8c..df81411 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -153,6 +153,8 @@
 #define PSSCR_EC   0x0010 /* Exit Criterion */
 #define PSSCR_ESL  0x0020 /* Enable State Loss */
 #define PSSCR_SD   0x0040 /* Status Disable */
+#define PSSCR_PLS  0xf000 /* Power-saving Level Status */
+#define PSSCR_GUEST_VIS0xf3ff /* Guest-visible PSSCR 
fields */
 
 /* Floating Point Status and Control Register (FPSCR) Fields */
 #define FPSCR_FX   0x8000  /* FPU exception summary */
@@ -236,6 +238,7 @@
 #define SPRN_TEXASRU   0x83/* ''  ''  ''Upper 32  */
 #define   TEXASR_FS__MASK(63-36) /* TEXASR Failure Summary */
 #define SPRN_TFHAR 0x80/* Transaction Failure Handler Addr */
+#define SPRN_TIDR  144 /* Thread ID register */
 #define SPRN_CTRLF 0x088
 #define SPRN_CTRLT 0x098
 #define   CTRL_CT  0xc000  /* current thread */
@@ -294,6 +297,7 @@
 #define SPRN_HSRR1 0x13B   /* Hypervisor Save/Restore 1 */
 #define SPRN_LMRR  0x32D   /* Load Monitor Region Register */
 #define SPRN_LMSER 0x32E   /* Load Monitor Section Enable Register */
+#define SPRN_ASDR  0x330   /* Access segment descriptor register */
 #define SPRN_IC0x350   /* Virtual Instruction Count */
 #define SPRN_VTB   0x351   /* Virtual Time Base */
 #define SPRN_LDBAR 0x352   /* LD Base Address Register */
@@ -357,6 +361,7 @@
 #define LPCR_PECE2 ASM_CONST(0x1000)   /* machine 
check etc can cause exit */
 #define   LPCR_MER ASM_CONST(0x0800)   /* Mediated 
External Exception */
 #define   LPCR_MER_SH  11
+#define  LPCR_GTSE ASM_CONST(0x0400)   /* 
Guest Translation Shootdown Enable */
 #define   LPCR_TC  ASM_CONST(0x0200)   /* Translation 
control */
 #define   LPCR_LPES0x000c
 #define   LPCR_LPES0   ASM_CONST(0x0008)  /* LPAR Env 
selector 0 */
-- 
2.7.4



[PATCH 00/13] KVM: PPC: Support POWER9 guests

2016-11-17 Thread Paul Mackerras
This series of patches adds support to HV KVM for running KVM guests
on POWER9 systems.  This allows us to run KVM guests that use HPT
(hashed page table) address translation and know about the POWER9
processor.  With this, Suraj Jitindar Singh's recent patch series
"powerpc: add support for ISA v2.07 compat level" and suitable changes
to the user-mode driver will allow us to run guests on POWER9 in
POWER8 (or POWER7) compatibility mode.

For now we require the host to be in HPT mode (not radix).

This series of patches is based on v4.9-rc4 plus my patch "powerpc/64:
Simplify adaptation to new ISA v3.00 HPTE format" and Yongji Xie's
two-patch series "KVM: PPC: Book3S HV: Optimize for MMIO emulation".

Paul.
---
 Documentation/virtual/kvm/api.txt  |   2 +
 arch/powerpc/include/asm/kvm_host.h|   3 +
 arch/powerpc/include/asm/kvm_ppc.h |   7 +-
 arch/powerpc/include/asm/mmu.h |   5 +
 arch/powerpc/include/asm/opal.h|   3 +
 arch/powerpc/include/asm/reg.h |   5 +
 arch/powerpc/include/uapi/asm/kvm.h|   4 +
 arch/powerpc/kernel/asm-offsets.c  |   3 +
 arch/powerpc/kvm/book3s_64_mmu_hv.c|  39 +--
 arch/powerpc/kvm/book3s_hv.c   | 140 ++---
 arch/powerpc/kvm/book3s_hv_builtin.c   |  69 +---
 arch/powerpc/kvm/book3s_hv_rm_mmu.c| 113 ++--
 arch/powerpc/kvm/book3s_hv_rm_xics.c   |  23 ++--
 arch/powerpc/kvm/book3s_hv_rmhandlers.S| 132 ---
 arch/powerpc/kvm/powerpc.c |  11 +-
 arch/powerpc/mm/hash_utils_64.c|  28 +
 arch/powerpc/mm/pgtable-radix.c|  18 ++--
 arch/powerpc/mm/pgtable_64.c   |  33 ++
 arch/powerpc/platforms/powernv/opal-wrappers.S |   3 +
 arch/powerpc/platforms/powernv/opal.c  |   2 +
 20 files changed, 483 insertions(+), 160 deletions(-)



Re: [RFC PATCH 2/4] powerpc: kprobe: add arch specific blacklist

2016-11-17 Thread Masami Hiramatsu
On Fri, 18 Nov 2016 16:48:01 +1100
Michael Ellerman  wrote:

> "Naveen N. Rao"  writes:
> 
> > Add symbol to mark end of entry_*.S and use the same to blacklist all
> > addresses from kernel start (_stext) to entry code from kprobes. Much of
> > this code is early exception handling where we can't really take a trap.
> 
> I'm not sure about this. entry_*.S is actually a bit of jumble,
> especially the 64bit version. I've been wanting to split it up for a
> long time.
> 
> It doesn't actually contain any early exception handling. It does
> contain the common syscall handler, and the exception return paths, some
> of which should be black listed. And lots of other junk.
> 
> Also I'm not sure if it's guaranteed that there won't be other code
> between _stext and the end of entry, it's not handled explicitly in the
> linker script, it just tends to get linked early because it's in head-y.
> 
> So I think it would be better if we had a clearer picture of exactly
> what in this file we want to blacklist.

Fair enough.

OK, the purpose of the kprobe blacklist is to avoid crashing kernel
by putting kprobes in some critical area (critical for kprobes,
not what usually "critical region" means).

Since kprobes is using breakpoint(trap) exception, if there is another
kprobes(trap) on the path until kprobe_handler() handle it, the kernel
kicks same exception handler and fall into the recursive fault.
So the blacklist is used in kprobe to prohibit putting kprobes on such
functions for avoiding it.

So, we might be carefully choose the function for the blacklist.

BTW, Naveen, as far as I can see the kprobe implementation on ppc,
it still depends on exceptions_notify to handle trap. It is no more
recommended becuase notifier_call_chain involves too many unrelated
functions. I recommend you to callback kprobe_handler and
kprobe_post_handler directly from the trap handler as same as x86.

Unless that, kprobe_blacklist may not work.

Thank you,

-- 
Masami Hiramatsu 


fadump: a question about "ibm,configure-kernel-dump"

2016-11-17 Thread Liu ping fan
I have an ibm-p8-garrison machine. But I can not find a node
"ibm,configure-kernel-dump" under /proc/device-tree.  Does garrison
machine support fadump? And normally, which component in open-power
presents the "ibm,configure-kernel-dump" ?  I had though it was in
skiboot gitree or  garrison-xml gitree, but found nothing.

Can anyone give a help?
Thx


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

2016-11-17 Thread Aneesh Kumar K.V
Rashmica Gupta  writes:

> Useful to be able to dump the kernel hash page table to check
> which pages are hashed along with their sizes and other details.
>
> Add a debugfs file to check the hash page table. If radix is enabled
> (and so there is no hash page table) then this file doesn't exist. To
> use this the PPC_PTDUMP config option must be selected.
>
> Signed-off-by: Rashmica Gupta 

I completely missed this when it was sent to the list.

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

Re: [RFC PATCH 2/4] powerpc: kprobe: add arch specific blacklist

2016-11-17 Thread Michael Ellerman
"Naveen N. Rao"  writes:

> Add symbol to mark end of entry_*.S and use the same to blacklist all
> addresses from kernel start (_stext) to entry code from kprobes. Much of
> this code is early exception handling where we can't really take a trap.

I'm not sure about this. entry_*.S is actually a bit of jumble,
especially the 64bit version. I've been wanting to split it up for a
long time.

It doesn't actually contain any early exception handling. It does
contain the common syscall handler, and the exception return paths, some
of which should be black listed. And lots of other junk.

Also I'm not sure if it's guaranteed that there won't be other code
between _stext and the end of entry, it's not handled explicitly in the
linker script, it just tends to get linked early because it's in head-y.

So I think it would be better if we had a clearer picture of exactly
what in this file we want to blacklist.

cheers


[PATCH v3] powerpc/mm/radix: Invalidate ERAT on tlbiel for POWER9 DD1

2016-11-17 Thread Michael Neuling
On POWER9 DD1, when we do a local TLB invalidate we also need to explicitly
invalidate the ERAT.

Signed-off-by: Michael Neuling 
---
v3:
  - Now with added bike shedding
v2:
  - Remove unnecessary isyncs
---
 arch/powerpc/include/asm/ppc-opcode.h | 1 +
 arch/powerpc/mm/tlb-radix.c   | 4 
 2 files changed, 5 insertions(+)

diff --git a/arch/powerpc/include/asm/ppc-opcode.h 
b/arch/powerpc/include/asm/ppc-opcode.h
index 0132831b30..c56ea8c84a 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -460,5 +460,6 @@
 
 #define PPC_SLBIA(IH)  stringify_in_c(.long PPC_INST_SLBIA | \
   ((IH & 0x7) << 21))
+#define PPC_INVALIDATE_ERATPPC_SLBIA(7)
 
 #endif /* _ASM_POWERPC_PPC_OPCODE_H */
diff --git a/arch/powerpc/mm/tlb-radix.c b/arch/powerpc/mm/tlb-radix.c
index bda8c43be7..3493cf4e04 100644
--- a/arch/powerpc/mm/tlb-radix.c
+++ b/arch/powerpc/mm/tlb-radix.c
@@ -50,6 +50,8 @@ static inline void _tlbiel_pid(unsigned long pid, unsigned 
long ric)
for (set = 0; set < POWER9_TLB_SETS_RADIX ; set++) {
__tlbiel_pid(pid, set, ric);
}
+   if (cpu_has_feature(CPU_FTR_POWER9_DD1))
+   asm volatile(PPC_INVALIDATE_ERAT : : :"memory");
return;
 }
 
@@ -83,6 +85,8 @@ static inline void _tlbiel_va(unsigned long va, unsigned long 
pid,
asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
 : : "r"(rb), "i"(r), "i"(prs), "i"(ric), "r"(rs) : 
"memory");
asm volatile("ptesync": : :"memory");
+   if (cpu_has_feature(CPU_FTR_POWER9_DD1))
+   asm volatile(PPC_INVALIDATE_ERAT : : :"memory");
 }
 
 static inline void _tlbie_va(unsigned long va, unsigned long pid,
-- 
2.9.3



Re: [PATCH] powerpc/eeh: Refactor EEH PE reset functions

2016-11-17 Thread Russell Currey
On Fri, 2016-11-18 at 10:59 +1100, Gavin Shan wrote:
> On Thu, Nov 17, 2016 at 04:07:47PM +1100, Russell Currey wrote:
> > eeh_pe_reset and eeh_reset_pe are two different functions in the same
> > file which do mostly the same thing.  Not only is this confusing, but
> > potentially causes disrepancies in functionality, notably eeh_reset_pe
> > as it does not check return values for failure.
> > 
> 
> If possible, it'd better to keep them separate: one is used by powernv
> or pSeries. Another one is used by VFIO in virtualization path. Merging
> them increases the cost to maintain the code in future.

I disagree with that.  How does merging them make code maintenance harder? 
Instead of having two separate paths that do slightly different things, we can
have one path make use of the other, sharing a lot of code.

> 
> If you really want to merge them, it needs full testing to make sure it
> won't break the virtualization path. Otherwise, it all looks good.

This shouldn't affect the virtualization path, eeh_pe_reset() (which is called
by VFIO) remains unchanged.
> 
> > Refactor this into the following:
> > 
> > - eeh_pe_reset(): stays as is, performs a single operation, exported
> > - eeh_pe_reset_full(): new, full reset process that calls eeh_pe_reset()
> > - eeh_reset_pe(): removed and replaced by eeh_pe_reset_full()
> > - eeh_reset_pe_once(): removed
> > 
> > 
> > Signed-off-by: Russell Currey 
> > ---
> > I'm not sure if this should go to stable.  Apparently it fixes some bug by
> > checking returns, but I don't fully understand what the problem was or how
> > severe it is.  Andrew (on CC) should know more.
> > 
> > Also the diff for this looks awful, much easier to read when applied
> > ---
> > arch/powerpc/include/asm/ppc-pci.h |  2 +-
> > arch/powerpc/kernel/eeh.c  | 82 +---
> > --
> > arch/powerpc/kernel/eeh_driver.c   |  4 +-
> > 3 files changed, 40 insertions(+), 48 deletions(-)
> > 
> > diff --git a/arch/powerpc/include/asm/ppc-pci.h
> > b/arch/powerpc/include/asm/ppc-pci.h
> > index 0f73de0..7262880 100644
> > --- a/arch/powerpc/include/asm/ppc-pci.h
> > +++ b/arch/powerpc/include/asm/ppc-pci.h
> > @@ -53,7 +53,7 @@ void eeh_addr_cache_rmv_dev(struct pci_dev *dev);
> > struct eeh_dev *eeh_addr_cache_get_dev(unsigned long addr);
> > void eeh_slot_error_detail(struct eeh_pe *pe, int severity);
> > int eeh_pci_enable(struct eeh_pe *pe, int function);
> > -int eeh_reset_pe(struct eeh_pe *);
> > +int eeh_pe_reset_full(struct eeh_pe *pe);
> > void eeh_save_bars(struct eeh_dev *edev);
> > int rtas_write_config(struct pci_dn *, int where, int size, u32 val);
> > int rtas_read_config(struct pci_dn *, int where, int size, u32 *val);
> > diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
> > index f257316..ad743d3 100644
> > --- a/arch/powerpc/kernel/eeh.c
> > +++ b/arch/powerpc/kernel/eeh.c
> > @@ -808,76 +808,67 @@ static void *eeh_set_dev_freset(void *data, void
> > *flag)
> > }
> > 
> > /**
> > - * eeh_reset_pe_once - Assert the pci #RST line for 1/4 second
> > + * eeh_pe_reset_full - Complete a full reset process on the indicated PE
> >  * @pe: EEH PE
> >  *
> > - * Assert the PCI #RST line for 1/4 second.
> > + * This function executes a full reset procedure on a PE, including setting
> > + * the appropriate flags, performing a fundamental or hot reset, and then
> > + * deactivating the reset status.  It is designed to be used within the EEH
> > + * subsystem, as opposed to eeh_pe_reset which is exported to drivers and
> > + * only performs a single operation at a time.
> > + *
> > + * This function will attempt to reset a PE three times before failing.
> >  */
> > -static void eeh_reset_pe_once(struct eeh_pe *pe)
> > +int eeh_pe_reset_full(struct eeh_pe *pe)
> > {
> > +   int active_flags = (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
> > +   int reset_state = (EEH_PE_RESET | EEH_PE_CFG_BLOCKED);
> > +   int type = EEH_RESET_HOT;
> > unsigned int freset = 0;
> > +   int i, state, ret;
> > 
> > -   /* Determine type of EEH reset required for
> > -    * Partitionable Endpoint, a hot-reset (1)
> > -    * or a fundamental reset (3).
> > -    * A fundamental reset required by any device under
> > -    * Partitionable Endpoint trumps hot-reset.
> > +   /*
> > +    * Determine the type of reset to perform - hot or fundamental.
> > +    * Hot reset is the default operation, unless any device under the
> > +    * PE requires a fundamental reset.
> >  */
> > eeh_pe_dev_traverse(pe, eeh_set_dev_freset, );
> > 
> > if (freset)
> > -   eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
> > -   else
> > -   eeh_ops->reset(pe, EEH_RESET_HOT);
> > -
> > -   eeh_ops->reset(pe, EEH_RESET_DEACTIVATE);
> > -}
> > -
> > -/**
> > - * eeh_reset_pe - Reset the indicated PE
> > - * @pe: EEH PE
> > - *
> > - * This routine should be called to reset indicated device, including
> > - * PE. A PE might include multiple PCI 

Re: [PATCH] powerpc/xmon: Add support for dump in reverse

2016-11-17 Thread kbuild test robot
Hi Balbir,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.9-rc5 next-20161117]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Balbir-Singh/powerpc-xmon-Add-support-for-dump-in-reverse/20161118-081358
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-ppc64e_defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All errors (new ones prefixed by >>):

   arch/powerpc/xmon/xmon.c: In function 'prdump':
>> arch/powerpc/xmon/xmon.c:2431:10: error: 'idx' may be used uninitialized in 
>> this function [-Werror=maybe-uninitialized]
 idx -= 2;
 ^~~~
   cc1: all warnings being treated as errors

vim +/idx +2431 arch/powerpc/xmon/xmon.c

  2425  }
  2426  
  2427  if (m < nr) {
  2428  if (reverse) {
  2429  buf[idx + 1] = digithex(temp[m] 
% 16);
  2430  buf[idx] = digithex(temp[m] / 
16);
> 2431  idx -= 2;
  2432  } else
  2433  printf("%.2x", temp[m]);
  2434  } else

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH] powerpc/lib: Fix randconfig build failure in sstep.c

2016-11-17 Thread Michael Ellerman
Under some configs we need to explicitly include cpu_has_feature.h,
otherwise we fail with:

  arch/powerpc/lib/sstep.c:1992:7: error: implicit declaration of function 
'cpu_has_feature'

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/lib/sstep.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index b64287c6793f..9c78a9c102c3 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 extern char system_call_common[];
-- 
2.7.4



Re: [PATCH] powerpc/eeh: Refactor EEH PE reset functions

2016-11-17 Thread Gavin Shan
On Thu, Nov 17, 2016 at 04:07:47PM +1100, Russell Currey wrote:
>eeh_pe_reset and eeh_reset_pe are two different functions in the same
>file which do mostly the same thing.  Not only is this confusing, but
>potentially causes disrepancies in functionality, notably eeh_reset_pe
>as it does not check return values for failure.
>

If possible, it'd better to keep them separate: one is used by powernv
or pSeries. Another one is used by VFIO in virtualization path. Merging
them increases the cost to maintain the code in future.

If you really want to merge them, it needs full testing to make sure it
won't break the virtualization path. Otherwise, it all looks good.

>Refactor this into the following:
>
> - eeh_pe_reset(): stays as is, performs a single operation, exported
> - eeh_pe_reset_full(): new, full reset process that calls eeh_pe_reset()
> - eeh_reset_pe(): removed and replaced by eeh_pe_reset_full()
> - eeh_reset_pe_once(): removed
>
>
>Signed-off-by: Russell Currey 
>---
>I'm not sure if this should go to stable.  Apparently it fixes some bug by
>checking returns, but I don't fully understand what the problem was or how
>severe it is.  Andrew (on CC) should know more.
>
>Also the diff for this looks awful, much easier to read when applied
>---
> arch/powerpc/include/asm/ppc-pci.h |  2 +-
> arch/powerpc/kernel/eeh.c  | 82 +-
> arch/powerpc/kernel/eeh_driver.c   |  4 +-
> 3 files changed, 40 insertions(+), 48 deletions(-)
>
>diff --git a/arch/powerpc/include/asm/ppc-pci.h 
>b/arch/powerpc/include/asm/ppc-pci.h
>index 0f73de0..7262880 100644
>--- a/arch/powerpc/include/asm/ppc-pci.h
>+++ b/arch/powerpc/include/asm/ppc-pci.h
>@@ -53,7 +53,7 @@ void eeh_addr_cache_rmv_dev(struct pci_dev *dev);
> struct eeh_dev *eeh_addr_cache_get_dev(unsigned long addr);
> void eeh_slot_error_detail(struct eeh_pe *pe, int severity);
> int eeh_pci_enable(struct eeh_pe *pe, int function);
>-int eeh_reset_pe(struct eeh_pe *);
>+int eeh_pe_reset_full(struct eeh_pe *pe);
> void eeh_save_bars(struct eeh_dev *edev);
> int rtas_write_config(struct pci_dn *, int where, int size, u32 val);
> int rtas_read_config(struct pci_dn *, int where, int size, u32 *val);
>diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
>index f257316..ad743d3 100644
>--- a/arch/powerpc/kernel/eeh.c
>+++ b/arch/powerpc/kernel/eeh.c
>@@ -808,76 +808,67 @@ static void *eeh_set_dev_freset(void *data, void *flag)
> }
>
> /**
>- * eeh_reset_pe_once - Assert the pci #RST line for 1/4 second
>+ * eeh_pe_reset_full - Complete a full reset process on the indicated PE
>  * @pe: EEH PE
>  *
>- * Assert the PCI #RST line for 1/4 second.
>+ * This function executes a full reset procedure on a PE, including setting
>+ * the appropriate flags, performing a fundamental or hot reset, and then
>+ * deactivating the reset status.  It is designed to be used within the EEH
>+ * subsystem, as opposed to eeh_pe_reset which is exported to drivers and
>+ * only performs a single operation at a time.
>+ *
>+ * This function will attempt to reset a PE three times before failing.
>  */
>-static void eeh_reset_pe_once(struct eeh_pe *pe)
>+int eeh_pe_reset_full(struct eeh_pe *pe)
> {
>+  int active_flags = (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
>+  int reset_state = (EEH_PE_RESET | EEH_PE_CFG_BLOCKED);
>+  int type = EEH_RESET_HOT;
>   unsigned int freset = 0;
>+  int i, state, ret;
>
>-  /* Determine type of EEH reset required for
>-   * Partitionable Endpoint, a hot-reset (1)
>-   * or a fundamental reset (3).
>-   * A fundamental reset required by any device under
>-   * Partitionable Endpoint trumps hot-reset.
>+  /*
>+   * Determine the type of reset to perform - hot or fundamental.
>+   * Hot reset is the default operation, unless any device under the
>+   * PE requires a fundamental reset.
>*/
>   eeh_pe_dev_traverse(pe, eeh_set_dev_freset, );
>
>   if (freset)
>-  eeh_ops->reset(pe, EEH_RESET_FUNDAMENTAL);
>-  else
>-  eeh_ops->reset(pe, EEH_RESET_HOT);
>-
>-  eeh_ops->reset(pe, EEH_RESET_DEACTIVATE);
>-}
>-
>-/**
>- * eeh_reset_pe - Reset the indicated PE
>- * @pe: EEH PE
>- *
>- * This routine should be called to reset indicated device, including
>- * PE. A PE might include multiple PCI devices and sometimes PCI bridges
>- * might be involved as well.
>- */
>-int eeh_reset_pe(struct eeh_pe *pe)
>-{
>-  int flags = (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
>-  int i, state, ret;
>+  type = EEH_RESET_FUNDAMENTAL;
>
>-  /* Mark as reset and block config space */
>-  eeh_pe_state_mark(pe, EEH_PE_RESET | EEH_PE_CFG_BLOCKED);
>+  /* Mark the PE as in reset state and block config space accesses */
>+  eeh_pe_state_mark(pe, reset_state);
>
>-  /* Take three shots at resetting the bus */
>+  /* Make three attempts at resetting the bus */
>   

[PATCH] powerpc/xmon: Add support for dump in reverse

2016-11-17 Thread Balbir Singh

This patch adds support for dumping bytes in the reverse order of
what they are read in, effectively doing an endian swap on double words.

This makes it easy to debug on a little endian system

The output of "d" on a little endian system is

0:mon> d c0e8bd10
c0e8bd10 70bde8c0 84280024  |p(.$|

and with "dR"

0:mon> dR c0e8bd10
c0e8bd10 c0e8bd70 24002884  |p(.$|

The patch adds "dR" only for CONFIG_PPC64. A new function digithex
is introduced which helps convert a digit to char in hex. There are
other command line tools to do byte endian swap, but I find this
useful for debugging.

Signed-off-by: Balbir Singh 
---
 arch/powerpc/xmon/xmon.c | 58 ++--
 1 file changed, 51 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 7605455..0f4750c 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -120,7 +120,7 @@ static void byterev(unsigned char *, int);
 static void memex(void);
 static int bsesc(void);
 static void dump(void);
-static void prdump(unsigned long, long);
+static void prdump(unsigned long, long, int);
 static int ppc_inst_dump(unsigned long, long, int);
 static void dump_log_buf(void);
 
@@ -144,6 +144,7 @@ int skipbl(void);
 int scanhex(unsigned long *valp);
 static void scannl(void);
 static int hexdigit(int);
+static int digithex(int);
 void getstring(char *, int);
 static void flush_input(void);
 static int inchar(void);
@@ -220,6 +221,7 @@ Commands:\n\
 #endif
 #ifdef CONFIG_PPC64
   "\
+  dR   dump bytes in reverse (double words) \n\
   dp[#]dump paca for current cpu, or cpu #\n\
   dpa  dump paca for all possible cpus\n"
 #endif
@@ -2371,43 +2373,76 @@ dump(void)
xmon_rawdump(adrs, ndump);
adrs += ndump;
last_cmd = "dr\n";
+#ifdef CONFIG_PPC64
+   } else if (c == 'R') {
+   scanhex();
+   if (ndump == 0)
+   ndump = 64;
+   else if (ndump > MAX_DUMP)
+   ndump = MAX_DUMP;
+   prdump(adrs, ndump, 1);
+   adrs += ndump;
+   last_cmd = "dR\n";
+#endif
} else {
scanhex();
if (ndump == 0)
ndump = 64;
else if (ndump > MAX_DUMP)
ndump = MAX_DUMP;
-   prdump(adrs, ndump);
+   prdump(adrs, ndump, 0);
adrs += ndump;
last_cmd = "d\n";
}
 }
 
 static void
-prdump(unsigned long adrs, long ndump)
+prdump(unsigned long adrs, long ndump, int reverse)
 {
long n, m, c, r, nr;
unsigned char temp[16];
+   unsigned char buf[17];
+   int idx;
 
for (n = ndump; n > 0;) {
printf(REG, adrs);
putchar(' ');
r = n < 16? n: 16;
nr = mread(adrs, temp, r);
+
+   if (reverse) {
+   idx = 14;
+   buf[16] = '\0';
+   }
adrs += nr;
for (m = 0; m < r; ++m) {
-   if ((m & (sizeof(long) - 1)) == 0 && m > 0)
+   if ((m & (sizeof(long) - 1)) == 0 && m > 0) {
+   if (reverse) {
+   printf("%s", buf);
+   idx = 14;
+   }
putchar(' ');
-   if (m < nr)
-   printf("%.2x", temp[m]);
-   else
+   }
+
+   if (m < nr) {
+   if (reverse) {
+   buf[idx + 1] = digithex(temp[m] % 16);
+   buf[idx] = digithex(temp[m] / 16);
+   idx -= 2;
+   } else
+   printf("%.2x", temp[m]);
+   } else
printf("%s", fault_chars[fault_type]);
}
+
+   if (reverse)
+   printf("%s", buf);
for (; m < 16; ++m) {
if ((m & (sizeof(long) - 1)) == 0)
putchar(' ');
printf("  ");
}
+
printf("  |");
for (m = 0; m < r; ++m) {
if (m < nr) {
@@ -2893,6 +2928,15 @@ static int hexdigit(int c)
return EOF;
 }
 
+static int digithex(int c)
+{
+   if (c >= 0 && c <= 9)
+   return c + '0';
+   if (c >= 0xa && c <= 0xf)
+   return c + ('a' - 10);
+   return EOF;
+}
+
 void
 getstring(char *s, int size)
 {
-- 
2.5.5



[PATCH] powerpc/mm: Update POWER9 HID on secondaries too

2016-11-17 Thread Michael Neuling
From: "Aneesh Kumar K.V" 

We need to update the HID on secondaries for the selected MMU mode.

Fixes: ad410674f5606a ("powerpc/mm: Update the HID bit when switching from 
radix to hash")

Reported-by: Michael Neuling 
Signed-off-by: Aneesh Kumar K.V 
Signed-off-by: Michael Neuling 
---
 arch/powerpc/mm/hash_utils_64.c | 4 
 arch/powerpc/mm/pgtable-radix.c | 4 
 2 files changed, 8 insertions(+)

diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 44d3c3a38e..5503078090 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1029,6 +1029,10 @@ void hash__early_init_mmu_secondary(void)
 {
/* Initialize hash table for that CPU */
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
+
+   if (cpu_has_feature(CPU_FTR_POWER9_DD1))
+   update_hid_for_hash();
+
if (!cpu_has_feature(CPU_FTR_ARCH_300))
mtspr(SPRN_SDR1, _SDR1);
else
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index e93e38455d..9dfd3f1369 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -388,6 +388,10 @@ void radix__early_init_mmu_secondary(void)
 * update partition table control register and UPRT
 */
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
+
+   if (cpu_has_feature(CPU_FTR_POWER9_DD1))
+   update_hid_for_radix();
+
lpcr = mfspr(SPRN_LPCR);
mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR);
 
-- 
2.9.3



Re: [PATCH] powerpc/64: Fix setting of AIL in hypervisor mode

2016-11-17 Thread Michael Neuling
On Tue, 2016-11-15 at 15:28 +1100, Benjamin Herrenschmidt wrote:
> Commit d3cbff1b5 "powerpc: Put exception configuration in a common place"
> broke the setting of the AIL bit (which enables taking exceptions with
> the MMU still on) on all processors, moving it incorrectly to a function
> called only on the boot CPU. This was correct for the guest case but
> not when running in hypervisor mode.
> 
> This fixes it by partially reverting that commit, putting the setting
> back in cpu_ready_for_interrupts()
> 
> Signed-off-by: Benjamin Herrenschmidt 
> Fixes: d3cbff1b5 ("powerpc: Put exception configuration in a common place")
> CC: sta...@vger.kernel.org # v4.8+

Acked-By: Michael Neuling 

> ---
>  arch/powerpc/kernel/setup_64.c | 20 ++--
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
> index 7ac8e6e..ac75224 100644
> --- a/arch/powerpc/kernel/setup_64.c
> +++ b/arch/powerpc/kernel/setup_64.c
> @@ -226,17 +226,25 @@ static void __init configure_exceptions(void)
>   if (firmware_has_feature(FW_FEATURE_OPAL))
>   opal_configure_cores();
>  
> - /* Enable AIL if supported, and we are in hypervisor mode */
> - if (early_cpu_has_feature(CPU_FTR_HVMODE) &&
> - early_cpu_has_feature(CPU_FTR_ARCH_207S)) {
> - unsigned long lpcr = mfspr(SPRN_LPCR);
> - mtspr(SPRN_LPCR, lpcr | LPCR_AIL_3);
> - }
> + /* AIL on native is done in cpu_ready_for_interrupts */
>   }
>  }
>  
>  static void cpu_ready_for_interrupts(void)
>  {
> + /*
> +  * Enable AIL if supported, and we are in hypervisor mode. This
> +  * is called once for every processor.
> +  *
> +  * If we are not in hypervisor mode the job is done once for
> +  * the whole partition in configure_exceptions().
> +  */
> + if (early_cpu_has_feature(CPU_FTR_HVMODE) &&
> + early_cpu_has_feature(CPU_FTR_ARCH_207S)) {
> + unsigned long lpcr = mfspr(SPRN_LPCR);
> + mtspr(SPRN_LPCR, lpcr | LPCR_AIL_3);
> + }
> +
>   /* Set IR and DR in PACA MSR */
>   get_paca()->kernel_msr = MSR_KERNEL;
>  }
> 


Re: [PATCH 04/14] cxlflash: Avoid command room violation

2016-11-17 Thread Uma Krishnan

Thanks for catching this Matt. Looking into this. Will send out a V2.

On 11/17/2016 1:36 PM, Matthew R. Ochs wrote:

Hi Uma,

I do see a potential hang issue with this patch. See my comments below.


-matt


On Nov 15, 2016, at 5:14 PM, Uma Krishnan  wrote:

During test, a command room violation interrupt is occasionally seen
for the master context when the CXL flash devices are stressed.

After studying the code, there could be gaps in the way command room
value is being cached in cxlflash. When the cached command room is zero
the thread attempting to send becomes burdened with updating the cached
value with the actual value from the AFU. Today, this is handled with
an atomic set operation of the raw value read. Following the atomic
update, the thread proceeds to send.

This behavior is incorrect on two counts:

  - The update fails to take into account the current thread and its
consumption of one of the hardware commands.

  - The update does not take into account other threads also atomically
updating. Per design, a worker thread updates the cached value when
a send thread times out. By not performing an atomic compare/exchange,
the cached value can be incorrectly clobbered.

To correct these issues, the runtime updates of the cached command room
are updated to use atomic64_cmpxchg() and the send routine is updated to
take into account the current thread consuming a hardware command.

Signed-off-by: Uma Krishnan 
---
drivers/scsi/cxlflash/main.c | 16 ++--
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c
index 6d33d8c..1a32e8b 100644
--- a/drivers/scsi/cxlflash/main.c
+++ b/drivers/scsi/cxlflash/main.c
@@ -322,9 +322,10 @@ static int send_cmd(struct afu *afu, struct afu_cmd *cmd)
if (!newval) {


When this path is invoked, the current thread is consuming the last entry
available entry before the room must be read again. While the change
below is fine for circumstances where the hardware queue has room for
more than one command, consider a scenario where the queue has room
for only 1 command (the command that you just consumed via the atomic
but are not really consuming with a MMIO due to the revised goto).

In such a scenario this code would loop endlessly, bypassing the timeout
logic completely, until the read room reflected a value greater than 1.


do {
room = readq_be(>host_map->cmd_room);
-   atomic64_set(>room, room);
-   if (room)
-   goto write_ioarrin;
+   if (room) {
+   atomic64_cmpxchg(>room, 0, room);
+   goto retry;
+   }


If you instead fully consume the entry (goto write_ioarrin - similar as it was
before) and take into account the consumption when you update the cached
value (i.e.: cmpxchg(..., 0, room - 1) the scenario described above will not 
occur.






Re: [PATCH kernel v5 5/6] vfio/spapr: Reference mm in tce_container

2016-11-17 Thread Alex Williamson
On Thu, 17 Nov 2016 18:39:41 +1100
Alexey Kardashevskiy  wrote:

> On 11/11/16 23:32, Alexey Kardashevskiy wrote:
> > In some situations the userspace memory context may live longer than
> > the userspace process itself so if we need to do proper memory context
> > cleanup, we better have tce_container take a reference to mm_struct and
> > use it later when the process is gone (@current or @current->mm is NULL).
> > 
> > This references mm and stores the pointer in the container; this is done
> > in a new helper - tce_iommu_mm_set() - when one of the following happens:
> > - a container is enabled (IOMMU v1);
> > - a first attempt to pre-register memory is made (IOMMU v2);
> > - a DMA window is created (IOMMU v2).
> > The @mm stays referenced till the container is destroyed.
> > 
> > This replaces current->mm with container->mm everywhere except debug
> > prints.
> > 
> > This adds a check that current->mm is the same as the one stored in
> > the container to prevent userspace from making changes to a memory
> > context of other processes.
> > 
> > DMA map/unmap ioctls() do not check for @mm as they already check
> > for @enabled which is set after tce_iommu_mm_set() is called.
> > 
> > Signed-off-by: Alexey Kardashevskiy 
> > ---
> > Changes:
> > v5:
> > * postpone referencing of mm
> > 
> > v4:
> > * added check for container->mm!=current->mm in tce_iommu_ioctl()
> > for all ioctls and removed other redundand checks
> > ---
> >  drivers/vfio/vfio_iommu_spapr_tce.c | 159 
> > ++--
> >  1 file changed, 99 insertions(+), 60 deletions(-)
> > 
> > diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c 
> > b/drivers/vfio/vfio_iommu_spapr_tce.c
> > index 1c02498..9a81a7e 100644
> > --- a/drivers/vfio/vfio_iommu_spapr_tce.c
> > +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
> > @@ -31,49 +31,49 @@
> >  static void tce_iommu_detach_group(void *iommu_data,
> > struct iommu_group *iommu_group);
> >  
> > -static long try_increment_locked_vm(long npages)
> > +static long try_increment_locked_vm(struct mm_struct *mm, long npages)
> >  {
> > long ret = 0, locked, lock_limit;
> >  
> > -   if (!current || !current->mm)
> > -   return -ESRCH; /* process exited */
> > +   if (!mm)
> > +   return -EPERM;
> >  
> > if (!npages)
> > return 0;
> >  
> > -   down_write(>mm->mmap_sem);
> > -   locked = current->mm->locked_vm + npages;
> > +   down_write(>mmap_sem);
> > +   locked = mm->locked_vm + npages;
> > lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> > if (locked > lock_limit && !capable(CAP_IPC_LOCK))  
> 
> 
> 
> Oh boy. Now it seems I have to reference a task, not just mm (which I may
> not have to reference at all after all as the task reference should keep mm
> alive) as I missed the fact capable() and rlimit() are working with @current.
> 
> 
> Alex,
> 
> Is there anything else I should fix before posting v6? Thanks.

Nope, I was just hoping to see a R-b from David, you guys know the
spapr-tce iommu code far better than me.  Thanks,

Alex


Re: [PATCH 04/14] cxlflash: Avoid command room violation

2016-11-17 Thread Matthew R. Ochs
Hi Uma,

I do see a potential hang issue with this patch. See my comments below.


-matt
 
> On Nov 15, 2016, at 5:14 PM, Uma Krishnan  wrote:
> 
> During test, a command room violation interrupt is occasionally seen
> for the master context when the CXL flash devices are stressed.
> 
> After studying the code, there could be gaps in the way command room
> value is being cached in cxlflash. When the cached command room is zero
> the thread attempting to send becomes burdened with updating the cached
> value with the actual value from the AFU. Today, this is handled with
> an atomic set operation of the raw value read. Following the atomic
> update, the thread proceeds to send.
> 
> This behavior is incorrect on two counts:
> 
>   - The update fails to take into account the current thread and its
> consumption of one of the hardware commands.
> 
>   - The update does not take into account other threads also atomically
> updating. Per design, a worker thread updates the cached value when
> a send thread times out. By not performing an atomic compare/exchange,
> the cached value can be incorrectly clobbered.
> 
> To correct these issues, the runtime updates of the cached command room
> are updated to use atomic64_cmpxchg() and the send routine is updated to
> take into account the current thread consuming a hardware command.
> 
> Signed-off-by: Uma Krishnan 
> ---
> drivers/scsi/cxlflash/main.c | 16 ++--
> 1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c
> index 6d33d8c..1a32e8b 100644
> --- a/drivers/scsi/cxlflash/main.c
> +++ b/drivers/scsi/cxlflash/main.c
> @@ -322,9 +322,10 @@ static int send_cmd(struct afu *afu, struct afu_cmd *cmd)
>   if (!newval) {

When this path is invoked, the current thread is consuming the last entry
available entry before the room must be read again. While the change
below is fine for circumstances where the hardware queue has room for
more than one command, consider a scenario where the queue has room
for only 1 command (the command that you just consumed via the atomic
but are not really consuming with a MMIO due to the revised goto).

In such a scenario this code would loop endlessly, bypassing the timeout
logic completely, until the read room reflected a value greater than 1.

>   do {
>   room = readq_be(>host_map->cmd_room);
> - atomic64_set(>room, room);
> - if (room)
> - goto write_ioarrin;
> + if (room) {
> + atomic64_cmpxchg(>room, 0, room);
> + goto retry;
> + }

If you instead fully consume the entry (goto write_ioarrin - similar as it was
before) and take into account the consumption when you update the cached
value (i.e.: cmpxchg(..., 0, room - 1) the scenario described above will not 
occur.




Re: [PATCH 03/14] cxlflash: Improve context_reset() logic

2016-11-17 Thread Matthew R. Ochs
> On Nov 15, 2016, at 5:14 PM, Uma Krishnan  wrote:
> 
> Currently, the context reset routine waits for command room to
> be available before sending the reset request. Per review of the
> SISLite specification and clarifications from the CXL Flash AFU
> designers, this wait is unnecessary. The reset request can be
> sent anytime regardless of command room, so long as only a single
> reset request is active at any one point in time.
> 
> This commit simplifies the reset routine by removing the wait for
> command room. Additionally it adds a debug trace to help pinpoint
> hardware errors when a context reset does not complete.
> 
> Signed-off-by: Uma Krishnan 

Acked-by: Matthew R. Ochs 



Re: [PATCH 02/14] cxlflash: Fix crash in cxlflash_restore_luntable()

2016-11-17 Thread Matthew R. Ochs
> On Nov 15, 2016, at 5:14 PM, Uma Krishnan  wrote:
> 
> During test, the following crash was observed:
> 
> [34538.981505] Faulting instruction address: 0xd7c9c870
> cpu 0x9: Vector: 300 (Data Access) at [c007f1e8f590]
>pc: d7c9c870: cxlflash_restore_luntable+0x70/0x1d0 [cxlflash]
>lr: d7c9c84c: cxlflash_restore_luntable+0x4c/0x1d0 [cxlflash]
>sp: c007f1e8f810
>   msr: 90019033
>   dar: c0171d637438
> dsisr: 4000
>  current = 0xc007f1e43f90
>  paca= 0xc7b25100   softe: 0irq_happened: 0x01
>pid   = 493, comm = eehd
> enter ? for help
> [c007f1e8f8a0] d7c940b0 init_afu+0xd60/0x1200 [cxlflash]
> [c007f1e8f9a0] d7c945a8 cxlflash_pci_slot_reset+0x58/0xe0 
> [cxlflash]
> [c007f1e8fa20] d715f790 cxl_pci_slot_reset+0x230/0x340 [cxl]
> [c007f1e8fae0] c0040dd4 eeh_report_reset+0x144/0x180
> [c007f1e8fb20] c003f708 eeh_pe_dev_traverse+0x98/0x170
> [c007f1e8fbb0] c0041618 eeh_handle_normal_event+0x328/0x410
> [c007f1e8fc30] c0041db8 eeh_handle_event+0x178/0x330
> [c007f1e8fce0] c0042118 eeh_event_handler+0x1a8/0x1b0
> [c007f1e8fd80] c011420c kthread+0xec/0x100
> [c007f1e8fe30] c000a47c ret_from_kernel_thread+0x5c/0xe0
> 
> When superpipe mode is disabled for a LUN, the references for the
> local lun are deleted but the LUN is still identified as being present
> in the LUN table. This mismatched state can result in the above crash
> when the LUN table is restored during an error recovery operation.
> 
> To fix this issue, the local LUN information structure is updated to
> reflect the LUN is no longer in the LUN table once all references to
> the LUN are gone.
> 
> Signed-off-by: Uma Krishnan 

Acked-by: Matthew R. Ochs 



Re: [PATCH 01/14] cxlflash: Set sg_tablesize to 1 instead of SG_NONE

2016-11-17 Thread Matthew R. Ochs
> On Nov 15, 2016, at 5:13 PM, Uma Krishnan  wrote:
> 
> The following Oops is encountered when blk_mq is enabled with the
> cxlflash driver:
> 
> [ 2960.817172] Oops: Kernel access of bad area, sig: 11 [#5]
> [ 2960.817309] NIP  __blk_mq_run_hw_queue+0x278/0x4c0
> [ 2960.817313] LR __blk_mq_run_hw_queue+0x2bc/0x4c0
> [ 2960.817314] Call Trace:
> [ 2960.817320] __blk_mq_run_hw_queue+0x2bc/0x4c0 (unreliable)
> [ 2960.817324] blk_mq_run_hw_queue+0xd8/0x100
> [ 2960.817329] blk_mq_insert_requests+0x14c/0x1f0
> [ 2960.817333] blk_mq_flush_plug_list+0x150/0x190
> [ 2960.817338] blk_flush_plug_list+0x11c/0x2b0
> [ 2960.817344] blk_finish_plug+0x58/0x80
> [ 2960.817348] __do_page_cache_readahead+0x1c0/0x2e0
> [ 2960.817352] force_page_cache_readahead+0x68/0xd0
> [ 2960.817356] generic_file_read_iter+0x43c/0x6a0
> [ 2960.817359] blkdev_read_iter+0x68/0xa0
> [ 2960.817361] __vfs_read+0x11c/0x180
> [ 2960.817364] vfs_read+0xa4/0x1c0
> [ 2960.817366] SyS_read+0x6c/0x110
> [ 2960.817369] system_call+0x38/0xb4
> 
> The SCSI blk_mq stack assumes that sg_tablesize is always a non-zero
> value with scsi_mq_setup_tags() allocating tags using sg_tablesize.
> The cxlflash driver currently uses SG_NONE (0) for the sg_tablesize
> as the devices it supports are not capable of scatter gather. This
> mismatch of values results in the Oops above.
> 
> To resolve this issue, sg_tablesize for cxlflash can simply be set
> to 1, a value which satisfies the constraints in cxlflash and the
> lack of support of SG_NONE in SCSI blk_mq.
> 
> Signed-off-by: Uma Krishnan 

Acked-by: Matthew R. Ochs 



[PATCH 16/20] powerpc/sysfs: Convert to hotplug state machine

2016-11-17 Thread Sebastian Andrzej Siewior
Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.

The previous convention of keeping the files around until the CPU is dead
has not been preserved as there is no point to keep them available when the
cpu is going down. This makes the hotplug call symmetric.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Sebastian Andrzej Siewior 
---
 arch/powerpc/kernel/sysfs.c | 50 +
 1 file changed, 10 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index c4f1d1f7bae0..c1fb255a60d6 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -703,7 +703,7 @@ static struct device_attribute pa6t_attrs[] = {
 #endif /* HAS_PPC_PMC_PA6T */
 #endif /* HAS_PPC_PMC_CLASSIC */
 
-static void register_cpu_online(unsigned int cpu)
+static int register_cpu_online(unsigned int cpu)
 {
struct cpu *c = _cpu(cpu_devices, cpu);
struct device *s = >dev;
@@ -782,11 +782,12 @@ static void register_cpu_online(unsigned int cpu)
}
 #endif
cacheinfo_cpu_online(cpu);
+   return 0;
 }
 
-#ifdef CONFIG_HOTPLUG_CPU
-static void unregister_cpu_online(unsigned int cpu)
+static int unregister_cpu_online(unsigned int cpu)
 {
+#ifdef CONFIG_HOTPLUG_CPU
struct cpu *c = _cpu(cpu_devices, cpu);
struct device *s = >dev;
struct device_attribute *attrs, *pmc_attrs;
@@ -863,6 +864,8 @@ static void unregister_cpu_online(unsigned int cpu)
}
 #endif
cacheinfo_cpu_offline(cpu);
+#endif /* CONFIG_HOTPLUG_CPU */
+   return 0;
 }
 
 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
@@ -883,32 +886,6 @@ ssize_t arch_cpu_release(const char *buf, size_t count)
 }
 #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
 
-#endif /* CONFIG_HOTPLUG_CPU */
-
-static int sysfs_cpu_notify(struct notifier_block *self,
- unsigned long action, void *hcpu)
-{
-   unsigned int cpu = (unsigned int)(long)hcpu;
-
-   switch (action) {
-   case CPU_ONLINE:
-   case CPU_ONLINE_FROZEN:
-   register_cpu_online(cpu);
-   break;
-#ifdef CONFIG_HOTPLUG_CPU
-   case CPU_DEAD:
-   case CPU_DEAD_FROZEN:
-   unregister_cpu_online(cpu);
-   break;
-#endif
-   }
-   return NOTIFY_OK;
-}
-
-static struct notifier_block sysfs_cpu_nb = {
-   .notifier_call  = sysfs_cpu_notify,
-};
-
 static DEFINE_MUTEX(cpu_mutex);
 
 int cpu_add_dev_attr(struct device_attribute *attr)
@@ -1023,12 +1000,10 @@ static DEVICE_ATTR(physical_id, 0444, show_physical_id, 
NULL);
 
 static int __init topology_init(void)
 {
-   int cpu;
+   int cpu, r;
 
register_nodes();
 
-   cpu_notifier_register_begin();
-
for_each_possible_cpu(cpu) {
struct cpu *c = _cpu(cpu_devices, cpu);
 
@@ -1047,15 +1022,10 @@ static int __init topology_init(void)
 
device_create_file(>dev, _attr_physical_id);
}
-
-   if (cpu_online(cpu))
-   register_cpu_online(cpu);
}
-
-   __register_cpu_notifier(_cpu_nb);
-
-   cpu_notifier_register_done();
-
+   r = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powerpc/topology:online",
+ register_cpu_online, unregister_cpu_online);
+   WARN_ON(r < 0);
 #ifdef CONFIG_PPC64
sysfs_create_dscr_default();
 #endif /* CONFIG_PPC64 */
-- 
2.10.2



[PATCH] powerpc/pseries: Correct possible read beyond dlpar sysfs buffer

2016-11-17 Thread Nathan Fontenot
The pasrsing of data written to the dlpar file in sysfs does not correctly
account for the possibility of reading past the end of the buffer. The code
assumes that all pieces of the command witten to the sysfs file are present
in the form "   ".

Correct this by updating the buffer parsing code to make a local copy and
use the strsep() and sysfs_streq() routines to parse the buffer. This patch
also separates the parsing code into subroutines for each piece of the
command.

Signed-off-by: Nathan Fontenot 
---
 arch/powerpc/platforms/pseries/dlpar.c |  141 ++--
 1 file changed, 96 insertions(+), 45 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/dlpar.c 
b/arch/powerpc/platforms/pseries/dlpar.c
index 423e450..ec5d677 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -418,84 +418,135 @@ void queue_hotplug_event(struct pseries_hp_errorlog 
*hp_errlog,
}
 }
 
-static ssize_t dlpar_store(struct class *class, struct class_attribute *attr,
-  const char *buf, size_t count)
+static int dlpar_parse_resource(char **cmd, struct pseries_hp_errorlog 
*hp_elog)
 {
-   struct pseries_hp_errorlog *hp_elog;
-   struct completion hotplug_done;
-   const char *arg;
-   int rc;
+   char *arg;
 
-   hp_elog = kzalloc(sizeof(*hp_elog), GFP_KERNEL);
-   if (!hp_elog) {
-   rc = -ENOMEM;
-   goto dlpar_store_out;
-   }
+   arg = strsep(cmd, " ");
+   if (!arg)
+   return -EINVAL;
 
-   /* Parse out the request from the user, this will be in the form
-*
-*/
-   arg = buf;
-   if (!strncmp(arg, "memory", 6)) {
+   if (sysfs_streq(arg, "memory")) {
hp_elog->resource = PSERIES_HP_ELOG_RESOURCE_MEM;
-   arg += strlen("memory ");
-   } else if (!strncmp(arg, "cpu", 3)) {
+   } else if (sysfs_streq(arg, "cpu")) {
hp_elog->resource = PSERIES_HP_ELOG_RESOURCE_CPU;
-   arg += strlen("cpu ");
} else {
-   pr_err("Invalid resource specified: \"%s\"\n", buf);
-   rc = -EINVAL;
-   goto dlpar_store_out;
+   pr_err("Invalid resource specified.\n");
+   return -EINVAL;
}
 
-   if (!strncmp(arg, "add", 3)) {
+   return 0;
+}
+
+static int dlpar_parse_action(char **cmd, struct pseries_hp_errorlog *hp_elog)
+{
+   char *arg;
+
+   arg = strsep(cmd, " ");
+   if (!arg)
+   return -EINVAL;
+
+   if (sysfs_streq(arg, "add")) {
hp_elog->action = PSERIES_HP_ELOG_ACTION_ADD;
-   arg += strlen("add ");
-   } else if (!strncmp(arg, "remove", 6)) {
+   } else if (sysfs_streq(arg, "remove")) {
hp_elog->action = PSERIES_HP_ELOG_ACTION_REMOVE;
-   arg += strlen("remove ");
} else {
-   pr_err("Invalid action specified: \"%s\"\n", buf);
-   rc = -EINVAL;
-   goto dlpar_store_out;
+   pr_err("Invalid action specified.\n");
+   return -EINVAL;
}
 
-   if (!strncmp(arg, "index", 5)) {
-   u32 index;
+   return 0;
+}
 
+static int dlpar_parse_id_type(char **cmd, struct pseries_hp_errorlog *hp_elog)
+{
+   char *arg;
+   u32 count, index;
+
+   arg = strsep(cmd, " ");
+   if (!arg)
+   return -EINVAL;
+
+   if (sysfs_streq(arg, "index")) {
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_INDEX;
-   arg += strlen("index ");
+   arg = strsep(cmd, " ");
+   if (!arg) {
+   pr_err("No DRC Index specified.\n");
+   return -EINVAL;
+   }
+
if (kstrtou32(arg, 0, )) {
-   rc = -EINVAL;
-   pr_err("Invalid drc_index specified: \"%s\"\n", buf);
-   goto dlpar_store_out;
+   pr_err("Invalid DRC Index specified.\n");
+   return -EINVAL;
}
 
hp_elog->_drc_u.drc_index = cpu_to_be32(index);
-   } else if (!strncmp(arg, "count", 5)) {
-   u32 count;
-
+   } else if (sysfs_streq(arg, "count")) {
hp_elog->id_type = PSERIES_HP_ELOG_ID_DRC_COUNT;
-   arg += strlen("count ");
+   arg = strsep(cmd, " ");
+   if (!arg) {
+   pr_err("No DRC count specified.\n");
+   return -EINVAL;
+   }
+
if (kstrtou32(arg, 0, )) {
-   rc = -EINVAL;
-   pr_err("Invalid count specified: \"%s\"\n", buf);
-   goto dlpar_store_out;
+   pr_err("Invalid DRC count specified.\n");
+   return -EINVAL;
}
 

[PATCH] powerpc: Fix old style declaration GCC warnings

2016-11-17 Thread Tobias Klauser
Fix two [-Wold-style-declaration] GCC warnings by moving the inline
keyword before the return type.

Signed-off-by: Tobias Klauser 
---
 arch/powerpc/kernel/prom_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 88ac964f4858..05d2556ebb9f 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -461,14 +461,14 @@ static int __init prom_next_node(phandle *nodep)
}
 }
 
-static int inline prom_getprop(phandle node, const char *pname,
+static inline int prom_getprop(phandle node, const char *pname,
   void *value, size_t valuelen)
 {
return call_prom("getprop", 4, 1, node, ADDR(pname),
 (u32)(unsigned long) value, (u32) valuelen);
 }
 
-static int inline prom_getproplen(phandle node, const char *pname)
+static inline int prom_getproplen(phandle node, const char *pname)
 {
return call_prom("getproplen", 2, 1, node, ADDR(pname));
 }
-- 
2.11.0.rc0.7.gbe5a750




[PATCH] powerpc/mce: Remove unused but set variable

2016-11-17 Thread Tobias Klauser
Remove the unused but set variable srr1 in save_mce_event() to
fix the following GCC warning when building with 'W=1':

  arch/powerpc/kernel/mce.c:75:11: warning: variable 'srr1' set but not used 
[-Wunused-but-set-variable]

Signed-off-by: Tobias Klauser 
---
 arch/powerpc/kernel/mce.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index 5e7ece0fda9f..c6923ff45131 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -72,7 +72,6 @@ void save_mce_event(struct pt_regs *regs, long handled,
struct mce_error_info *mce_err,
uint64_t nip, uint64_t addr)
 {
-   uint64_t srr1;
int index = __this_cpu_inc_return(mce_nest_count) - 1;
struct machine_check_event *mce = this_cpu_ptr(_event[index]);
 
@@ -99,8 +98,6 @@ void save_mce_event(struct pt_regs *regs, long handled,
mce->disposition = MCE_DISPOSITION_NOT_RECOVERED;
mce->severity = MCE_SEV_ERROR_SYNC;
 
-   srr1 = regs->msr;
-
/*
 * Populate the mce error_type and type-specific error_type.
 */
-- 
2.11.0.rc0.7.gbe5a750




Re: [PATCH] powerpc: crypto/vmx: various build fixes

2016-11-17 Thread Herbert Xu
On Wed, Nov 16, 2016 at 08:41:46PM +0530, Naveen N. Rao wrote:
> First up, clean up the generated .S files properly on a 'make clean'.
> Secondly, force re-generation of these files when building for different
> endian-ness than what was built previously. Finally, generate the new
> files in the build tree, rather than the source tree.
> 
> Signed-off-by: Michael Ellerman 
> Signed-off-by: Naveen N. Rao 

Patch applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


[RFC PATCH 4/4] powerpc: mm/slb: blacklist symbols from kprobe

2016-11-17 Thread Naveen N. Rao
We can't really take a trap at this point. So, blacklist these symbols.

Reported-by: Anton Blanchard 
Signed-off-by: Naveen N. Rao 
---
 arch/powerpc/mm/slb_low.S | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/mm/slb_low.S b/arch/powerpc/mm/slb_low.S
index c1c7456..c2bae92 100644
--- a/arch/powerpc/mm/slb_low.S
+++ b/arch/powerpc/mm/slb_low.S
@@ -30,7 +30,7 @@
  * r9, r10, r11 are clobbered by this function
  * No other registers are examined or changed.
  */
-_GLOBAL(slb_allocate_realmode)
+_GLOBAL_NOKPROBE(slb_allocate_realmode)
/*
 * check for bad kernel/user address
 * (ea & ~REGION_MASK) >= PGTABLE_RANGE
@@ -59,7 +59,7 @@ _GLOBAL(slb_allocate_realmode)
/* Linear mapping encoding bits, the "li" instruction below will
 * be patched by the kernel at boot
 */
-_GLOBAL_SYM(slb_miss_kernel_load_linear)
+_GLOBAL_SYM_NOKPROBE(slb_miss_kernel_load_linear)
li  r11,0
/*
 * context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1
@@ -79,7 +79,7 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
/* Check virtual memmap region. To be patches at kernel boot */
cmpldi  cr0,r9,0xf
bne 1f
-_GLOBAL_SYM(slb_miss_kernel_load_vmemmap)
+_GLOBAL_SYM_NOKPROBE(slb_miss_kernel_load_vmemmap)
li  r11,0
b   6f
 1:
@@ -95,7 +95,7 @@ _GLOBAL_SYM(slb_miss_kernel_load_vmemmap)
b   6f
 5:
/* IO mapping */
-_GLOBAL_SYM(slb_miss_kernel_load_io)
+_GLOBAL_SYM_NOKPROBE(slb_miss_kernel_load_io)
li  r11,0
 6:
/*
@@ -203,7 +203,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
 7: ld  r10,PACASTABRR(r13)
addir10,r10,1
/* This gets soft patched on boot. */
-_GLOBAL_SYM(slb_compare_rr_to_size)
+_GLOBAL_SYM_NOKPROBE(slb_compare_rr_to_size)
cmpldi  r10,0
 
blt+4f
-- 
2.10.2



[RFC PATCH 3/4] powerpc: mm/slb: convert slb_low.S to use the new macros

2016-11-17 Thread Naveen N. Rao
Also convert slb_finish_load[_1T] to a local symbol as this doesn't need
to be globally visible.

Signed-off-by: Naveen N. Rao 
---
 arch/powerpc/mm/slb_low.S | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/mm/slb_low.S b/arch/powerpc/mm/slb_low.S
index e2974fc..c1c7456 100644
--- a/arch/powerpc/mm/slb_low.S
+++ b/arch/powerpc/mm/slb_low.S
@@ -59,8 +59,7 @@ _GLOBAL(slb_allocate_realmode)
/* Linear mapping encoding bits, the "li" instruction below will
 * be patched by the kernel at boot
 */
-.globl slb_miss_kernel_load_linear
-slb_miss_kernel_load_linear:
+_GLOBAL_SYM(slb_miss_kernel_load_linear)
li  r11,0
/*
 * context = (MAX_USER_CONTEXT) + ((ea >> 60) - 0xc) + 1
@@ -71,17 +70,16 @@ slb_miss_kernel_load_linear:
 
 
 BEGIN_FTR_SECTION
-   b   slb_finish_load
+   b   .Lslb_finish_load
 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
-   b   slb_finish_load_1T
+   b   .Lslb_finish_load_1T
 
 1:
 #ifdef CONFIG_SPARSEMEM_VMEMMAP
/* Check virtual memmap region. To be patches at kernel boot */
cmpldi  cr0,r9,0xf
bne 1f
-.globl slb_miss_kernel_load_vmemmap
-slb_miss_kernel_load_vmemmap:
+_GLOBAL_SYM(slb_miss_kernel_load_vmemmap)
li  r11,0
b   6f
 1:
@@ -97,8 +95,7 @@ slb_miss_kernel_load_vmemmap:
b   6f
 5:
/* IO mapping */
-.globl slb_miss_kernel_load_io
-slb_miss_kernel_load_io:
+_GLOBAL_SYM(slb_miss_kernel_load_io)
li  r11,0
 6:
/*
@@ -109,9 +106,9 @@ slb_miss_kernel_load_io:
addir9,r9,(MAX_USER_CONTEXT - 0xc + 1)@l
 
 BEGIN_FTR_SECTION
-   b   slb_finish_load
+   b   .Lslb_finish_load
 END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
-   b   slb_finish_load_1T
+   b   .Lslb_finish_load_1T
 
 0: /*
 * For userspace addresses, make sure this is region 0.
@@ -174,9 +171,9 @@ END_MMU_FTR_SECTION_IFCLR(MMU_FTR_1T_SEGMENT)
ld  r9,PACACONTEXTID(r13)
 BEGIN_FTR_SECTION
cmpldi  r10,0x1000
-   bge slb_finish_load_1T
+   bge .Lslb_finish_load_1T
 END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
-   b   slb_finish_load
+   b   .Lslb_finish_load
 
 8: /* invalid EA - return an error indication */
crset   4*cr0+eq/* indicate failure */
@@ -187,7 +184,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  *
  * r3 = EA, r9 = context, r10 = ESID, r11 = flags, clobbers r9, cr7 = <> 
PAGE_OFFSET
  */
-slb_finish_load:
+.Lslb_finish_load:
rldimi  r10,r9,ESID_BITS,0
ASM_VSID_SCRAMBLE(r10,r9,256M)
/*
@@ -206,8 +203,7 @@ slb_finish_load:
 7: ld  r10,PACASTABRR(r13)
addir10,r10,1
/* This gets soft patched on boot. */
-.globl slb_compare_rr_to_size
-slb_compare_rr_to_size:
+_GLOBAL_SYM(slb_compare_rr_to_size)
cmpldi  r10,0
 
blt+4f
@@ -256,7 +252,7 @@ slb_compare_rr_to_size:
  *
  * r3 = EA, r9 = context, r10 = ESID(256MB), r11 = flags, clobbers r9
  */
-slb_finish_load_1T:
+.Lslb_finish_load_1T:
srdir10,r10,(SID_SHIFT_1T - SID_SHIFT)  /* get 1T ESID */
rldimi  r10,r9,ESID_BITS_1T,0
ASM_VSID_SCRAMBLE(r10,r9,1T)
-- 
2.10.2



[RFC PATCH 2/4] powerpc: kprobe: add arch specific blacklist

2016-11-17 Thread Naveen N. Rao
Add symbol to mark end of entry_*.S and use the same to blacklist all
addresses from kernel start (_stext) to entry code from kprobes. Much of
this code is early exception handling where we can't really take a trap.

Reported-by: Anton Blanchard 
Signed-off-by: Naveen N. Rao 
---
 arch/powerpc/kernel/entry_32.S |  2 ++
 arch/powerpc/kernel/entry_64.S |  2 ++
 arch/powerpc/kernel/kprobes.c  | 10 ++
 3 files changed, 14 insertions(+)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 3841d74..de1ed6e 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -1410,3 +1410,5 @@ _GLOBAL(return_to_handler)
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
 
 #endif /* CONFIG_FUNCTION_TRACER */
+
+_GLOBAL_SYM(__entry_text_end)
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 6432d4b..f5f99920 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -1551,3 +1551,5 @@ _GLOBAL(return_to_handler)
blr
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
 #endif /* CONFIG_FUNCTION_TRACER */
+
+_GLOBAL_SYM(__entry_text_end)
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 9479d8e..b5173d6 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -36,12 +36,22 @@
 #include 
 #include 
 #include 
+#include 
 
 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
 DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
 
 struct kretprobe_blackpoint kretprobe_blacklist[] = {{NULL, NULL}};
 
+bool arch_within_kprobe_blacklist(unsigned long addr)
+{
+   /* The __kprobes marked functions and entry code must not be probed */
+   return (addr >= (unsigned long)__kprobes_text_start &&
+   addr < (unsigned long)__kprobes_text_end) ||
+  (addr >= (unsigned long)_stext &&
+   addr < (unsigned long)__entry_text_end);
+}
+
 int __kprobes arch_prepare_kprobe(struct kprobe *p)
 {
int ret = 0;
-- 
2.10.2



[RFC PATCH 1/4] powerpc: asm: introduce new macros for assembly globals

2016-11-17 Thread Naveen N. Rao
- Introduce _GLOBAL_SYM() for global symbols in assembly. This helps
reduce verbosity of assembly files.
- Introduce NOKPROBE variants of _GLOBAL() and _GLOBAL_SYM(). These are
used subsequently to blacklist certain assembly functions and symbols
from kprobe.
- Fix a small typo in kprobe comment and re-format it, to make it
clearer.

Signed-off-by: Naveen N. Rao 
---
 arch/powerpc/include/asm/ppc_asm.h | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index 025833b..2443545 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -254,13 +254,19 @@ GLUE(.,name):
 
 #endif
 
+#define _GLOBAL_SYM(name)  \
+   .globl name;\
+name:
+
 /*
  * __kprobes (the C annotation) puts the symbol into the .kprobes.text
  * section, which gets emitted at the end of regular text.
  *
  * _ASM_NOKPROBE_SYMBOL and NOKPROBE_SYMBOL just adds the symbol to
- * a blacklist. The former is for core kprobe functions/data, the
- * latter is for those that incdentially must be excluded from probing
+ * a blacklist.
+ *
+ * The former (__kprobes) is for core kprobe functions/data, the
+ * latter is for those that incidentally must be excluded from probing
  * and allows them to be linked at more optimal location within text.
  */
 #ifdef CONFIG_KPROBES
@@ -272,6 +278,15 @@ GLUE(.,name):
 #define _ASM_NOKPROBE_SYMBOL(entry)
 #endif
 
+#define _GLOBAL_NOKPROBE(name) \
+   _GLOBAL(name);  \
+   _ASM_NOKPROBE_SYMBOL(name)
+
+#define _GLOBAL_SYM_NOKPROBE(name) \
+   _GLOBAL_SYM(name);  \
+   _ASM_NOKPROBE_SYMBOL(name)
+
+
 #define FUNC_START(name)   _GLOBAL(name)
 #define FUNC_END(name)
 
-- 
2.10.2



[RFC PATCH 0/4] Blacklist powerpc exception vectors from kprobes

2016-11-17 Thread Naveen N. Rao
This is the beginning of work to come up with a more relevant kprobe
blacklist on powerpc. In this series, we primarily blacklist exception
vectors and kernel entry code.

Naveen N. Rao (4):
  powerpc: asm: introduce new macros for assembly globals
  powerpc: kprobe: add arch specific blacklist
  powerpc: mm/slb: convert slb_low.S to use the new macros
  powerpc: mm/slb: blacklist symbols from kprobe

 arch/powerpc/include/asm/ppc_asm.h | 19 +--
 arch/powerpc/kernel/entry_32.S |  2 ++
 arch/powerpc/kernel/entry_64.S |  2 ++
 arch/powerpc/kernel/kprobes.c  | 10 ++
 arch/powerpc/mm/slb_low.S  | 30 +-
 5 files changed, 44 insertions(+), 19 deletions(-)

-- 
2.10.2



Re: [PATCH] powerpc: crypto/vmx: various build fixes

2016-11-17 Thread Naveen N. Rao
On 2016/11/17 09:03PM, Herbert Xu wrote:
> On Thu, Nov 17, 2016 at 11:51:56AM +1100, Michael Ellerman wrote:
> > 
> > Crypto patches usually have a subject like:
> > 
> > crypto: vmx - Various build fixes

Ok.

> >
> > But maybe Herbert can fix it up for you when he applies this.
> 
> Sure I can fix it up.

Thanks,
- Naveen



Re: [RFC PATCH] of: base: add support to get machine model name

2016-11-17 Thread Arnd Bergmann
On Thursday, November 17, 2016 2:08:30 PM CET Sudeep Holla wrote:
> On 17/11/16 13:50, Arnd Bergmann wrote:
> > On Thursday, November 17, 2016 11:50:50 AM CET Sudeep Holla wrote:
> >> Currently platforms/drivers needing to get the machine model name are
> >> replicating the same snippet of code. In some case, the OF reference
> >> counting is either missing or incorrect.
> >>
> >> This patch adds support to read the machine model name either using
> >> the "model" or the "compatible" property in the device tree root node.
> >>
> >> Signed-off-by: Sudeep Holla 
> >
> > I like the idea. One small comment:
> >
> 
> Thanks. I prefer it as single patch but it can't be applied to any tree.
> Any suggestions on handling this patch to fix the warning in -next ?
> 
The patch that causes the warning is currently in the mmc tree, and I
don't think it would be good to have your entire patch in there too.

It's probably best to just fix the warning there now by adding another
open-coded copy of that function, and then apply your patch on top
for v4.11.

Arnd


Re: [RFC PATCH] of: base: add support to get machine model name

2016-11-17 Thread Sudeep Holla



On 17/11/16 14:13, Arnd Bergmann wrote:

On Thursday, November 17, 2016 2:08:30 PM CET Sudeep Holla wrote:

On 17/11/16 13:50, Arnd Bergmann wrote:

On Thursday, November 17, 2016 11:50:50 AM CET Sudeep Holla wrote:

Currently platforms/drivers needing to get the machine model name are
replicating the same snippet of code. In some case, the OF reference
counting is either missing or incorrect.

This patch adds support to read the machine model name either using
the "model" or the "compatible" property in the device tree root node.

Signed-off-by: Sudeep Holla 


I like the idea. One small comment:



Thanks. I prefer it as single patch but it can't be applied to any tree.
Any suggestions on handling this patch to fix the warning in -next ?


The patch that causes the warning is currently in the mmc tree, and I
don't think it would be good to have your entire patch in there too.

It's probably best to just fix the warning there now by adding another
open-coded copy of that function, and then apply your patch on top
for v4.11.


Sure, that's much simpler to deal with for now.

--
Regards,
Sudeep


Re: [RFC PATCH] of: base: add support to get machine model name

2016-11-17 Thread Sudeep Holla



On 17/11/16 13:50, Arnd Bergmann wrote:

On Thursday, November 17, 2016 11:50:50 AM CET Sudeep Holla wrote:

Currently platforms/drivers needing to get the machine model name are
replicating the same snippet of code. In some case, the OF reference
counting is either missing or incorrect.

This patch adds support to read the machine model name either using
the "model" or the "compatible" property in the device tree root node.

Signed-off-by: Sudeep Holla 


I like the idea. One small comment:



Thanks. I prefer it as single patch but it can't be applied to any tree.
Any suggestions on handling this patch to fix the warning in -next ?


+int of_machine_get_model_name(const char **model)
+{
+   int error;
+   struct device_node *root;
+
+   root = of_find_node_by_path("/");
+   if (!root)
+   return -EINVAL;


The global of_root variable points ot this already, and is defined
in the same file, so I think we can just skip the lookup.



Ah right, will fix it.

--
Regards,
Sudeep


Re: [RFC PATCH] of: base: add support to get machine model name

2016-11-17 Thread Arnd Bergmann
On Thursday, November 17, 2016 11:50:50 AM CET Sudeep Holla wrote:
> Currently platforms/drivers needing to get the machine model name are
> replicating the same snippet of code. In some case, the OF reference
> counting is either missing or incorrect.
> 
> This patch adds support to read the machine model name either using
> the "model" or the "compatible" property in the device tree root node.
> 
> Signed-off-by: Sudeep Holla 

I like the idea. One small comment:

> +int of_machine_get_model_name(const char **model)
> +{
> + int error;
> + struct device_node *root;
> +
> + root = of_find_node_by_path("/");
> + if (!root)
> + return -EINVAL;

The global of_root variable points ot this already, and is defined
in the same file, so I think we can just skip the lookup.

Arnd


Re: [PATCH] powerpc: crypto/vmx: various build fixes

2016-11-17 Thread Herbert Xu
On Thu, Nov 17, 2016 at 11:51:56AM +1100, Michael Ellerman wrote:
>
> But maybe Herbert can fix it up for you when he applies this.

Sure I can fix it up.

Cheers,
--
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: [RFT] powerpc: convert storcenter_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:30 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts storcenter_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/1aed61f9c9664cc7331079a66aba99

cheers


Re: [RFT] powerpc: convert pseries_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:29 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts pseries_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/80269fe4203432168dae6e49770d64

cheers


Re: [RFT] powerpc: convert ppc6xx_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:27 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts ppc6xx_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/7f10fe36369068341aff05c067a786

cheers


Re: [RFT] powerpc: convert ppc64e_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:26 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts ppc64e_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/4a0b4bfe0101901126dc4dba0ba904

cheers


Re: [RFT] powerpc: convert ppc64_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:25 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts ppc64_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/7ddf3db3d775d09da87f38ab39f261

cheers


Re: [RFT] powerpc: convert pmac32_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:24 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts pmac32_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/b0d3a074174138b7714533968be723

cheers


Re: [RFT] powerpc: convert maple_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:22 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts maple_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/c1f9d2938bd75c0245f640ad30d81e

cheers


Re: [RFT] powerpc: convert g5_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:21 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts g5_defconfig to use libata PATA drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/b10fd396376c9b1b1f5b0a3980b487

cheers


Re: [RFT] powerpc: convert chrp32_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:20 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts chrp32_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f22cc4d7bb268ffc585a5f8593138b

cheers


Re: [RFT] powerpc: convert cell_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:19 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts cell_defconfig to use libata PATA drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/8020c1220dd4ff324698668f067746

cheers


Re: [RFT] powerpc: convert amigaone_defconfig to use libata PATA drivers

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:18 UTC, Bartlomiej Zolnierkiewicz wrote:
> IDE subsystem has been deprecated since 2009 and the majority
> (if not all) of Linux distributions have switched to use
> libata for ATA support exclusively.  However there are still
> some users (mostly old or/and embedded non-x86 systems) that
> have not converted from using IDE subsystem to libata PATA
> drivers.  This doesn't seem to be good thing in the long-term
> for Linux as while there is less and less PATA systems left
> in use:
> 
> * testing efforts are divided between two subsystems
> 
> * having duplicate drivers for same hardware confuses users
> 
> This patch converts amigaone_defconfig to use libata PATA
> drivers.
> 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/67f6d66559930eddea06c6bfdaf0e5

cheers


Re: powerpc: disable IDE subsystem in pasemi_defconfig

2016-11-17 Thread Michael Ellerman
On Wed, 2016-03-02 at 15:50:23 UTC, Bartlomiej Zolnierkiewicz wrote:
> This patch disables deprecated IDE subsystem in pasemi_defconfig
> (no IDE host drivers are selected in this config so there is no valid
> reason to enable IDE subsystem itself).
> 
> Cc: Olof Johansson 
> Signed-off-by: Bartlomiej Zolnierkiewicz 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/23bf36cd120f97e85ce089c841197f

cheers


Re: powerpc/pseries: Move CMO code from plapr_wrappers.h to platforms/pseries

2016-11-17 Thread Michael Ellerman
On Mon, 2016-14-11 at 06:46:45 UTC, Michael Ellerman wrote:
> Currently there's some CMO (Cooperative Memory Overcommit) code, in
> plpar_wrappers.h. Some of it is #ifdef CONFIG_PSERIES and some of it
> isn't. The end result being if a file includes plpar_wrappers.h it won't
> build with CONFIG_PSERIES=n.
> 
> Fix it by moving the CMO code into platforms/pseries. The two hcall
> wrappers can just be moved into their only caller, cmm.c, and the
> accessors can go in pseries.h.
> 
> Note we need the accessors because cmm.c can be built as a module, so
> there needs to be a split between the built-in code vs the module, and
> that's achieved by using those accessors.
> 
> Signed-off-by: Michael Ellerman 

Applied to powerpc next.

https://git.kernel.org/powerpc/c/8f272a5dd6826f14e47110eccd37b6

cheers


Re: Fix a typo in radix encodings print

2016-11-17 Thread Michael Ellerman
On Sat, 2016-05-11 at 04:24:22 UTC, Balbir Singh wrote:
> Rename sift to shift
> 
> Signed-off-by: Balbir Singh 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/ac8d3818aab7e08332a79e42521182

cheers


Re: powerpc/mm: Correct process and partition table max size

2016-11-17 Thread Michael Ellerman
On Wed, 2016-09-11 at 05:36:33 UTC, Suraj Jitindar Singh wrote:
> Version 3.00 of the ISA states that the PATS (partition table size) field
> of the PTCR (partition table control register) and the PRTS (process table
> size) field of the partition table entry must both be less than or equal
> to 24. However the actual size of the partition and process tables is equal
> to 2 to the power of 12 plus the PATS and PRTS fields, respectively. This
> means that the max allowable size of each of these tables is 2^36 or 64GB
> for both.
> 
> Thus when checking the size shift for each we should be checking for values
> of greater than 36 instead of the current check for shifts larger than 24
> and 23.
> 
> Fixes: 2bfd65e45e877fb5704730244da67c748d28a1b8
> Signed-off-by: Suraj Jitindar Singh 
> Reviewed-by: Balbir Singh 
> Reviewed-by: Aneesh Kumar K.V 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/555c16328ae6d75a90e234eac9b519

cheers


Re: [v3,2/2] powerpc/mm: Dump hash table

2016-11-17 Thread Michael Ellerman
On Fri, 2016-27-05 at 05:49:00 UTC, Rashmica Gupta wrote:
> Useful to be able to dump the kernel hash page table to check
> which pages are hashed along with their sizes and other details.
> 
> Add a debugfs file to check the hash page table. If radix is enabled
> (and so there is no hash page table) then this file doesn't exist. To
> use this the PPC_PTDUMP config option must be selected.
> 
> Signed-off-by: Rashmica Gupta 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/1515ab932156257afd8a5864506dab

cheers


Re: [v15, 13/15] selftests/powerpc: Add ptrace tests for TM SPR registers

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:33:02 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for TM SPR registers. This
> also adds ptrace interface based helper functions related to TM
> SPR registers access.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/5bdac52f3c67e1262b1979081a362f

cheers


Re: [v15, 12/15] selftests/powerpc: Add ptrace tests for VSX, VMX registers in suspended TM

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:33:01 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for VSX, VMX registers
> inside suspended TM context.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/a18b55bf51b32136fb9c5190b1cbf8

cheers


Re: [v15, 11/15] selftests/powerpc: Add ptrace tests for VSX, VMX registers in TM

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:33:00 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for VSX, VMX registers
> inside TM context. This also adds ptrace interface based helper
> functions related to chckpointed VSX, VMX registers access.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/11508074c9a74a00df1aa6cfba81d1

cheers


Re: [v15, 10/15] selftests/powerpc: Add ptrace tests for VSX, VMX registers

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:59 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for VSX, VMX registers.
> This also adds ptrace interface based helper functions related
> to VSX, VMX registers access. This also adds some assembly
> helper functions related to VSX and VMX registers.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/0da535c0844b8f837670e0b9b3

cheers


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

2016-11-17 Thread Michael Ellerman
On Fri, 2016-27-05 at 05:48:59 UTC, Rashmica Gupta wrote:
> Useful to be able to dump the kernels page tables to check permissions
> and memory types - derived from arm64's implementation.
> 
> Add a debugfs file to check the page tables. To use this the PPC_PTDUMP
> config option must be selected.
> 
> Signed-off-by: Rashmica Gupta 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/8eb07b187000d48152c4ef97f075bd

cheers


Re: [v15, 09/15] selftests/powerpc: Add ptrace tests for TAR, PPR, DSCR in suspended TM

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:58 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for TAR, PPR, DSCR
> registers inside suspended TM context.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/01f7fdc7b90e5afc3fafa19da970ec

cheers


Re: [v15, 08/15] selftests/powerpc: Add ptrace tests for TAR, PPR, DSCR in TM

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:57 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for TAR, PPR, DSCR
> registers inside TM context. This also adds ptrace
> interface based helper functions related to checkpointed
> TAR, PPR, DSCR register access.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/fcf73a6bd9cb2b09045307e3ae8844

cheers


Re: [v15, 07/15] selftests/powerpc: Add ptrace tests for TAR, PPR, DSCR registers

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:56 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for TAR, PPR, DSCR
> registers. This also adds ptrace interface based helper
> functions related to TAR, PPR, DSCR register access.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/254dae59af6791f02bad50c70a1e5a

cheers

From jenkinsci-issues+bncbd2nvmgm7ucbbgf4w3aqkgqe7gri...@googlegroups.com Thu 
Nov 17 04:10:19 2016
Return-path: 

Envelope-to: archive+...@mail-archive.com
Delivery-date: Thu, 17 Nov 2016 04:10:19 -0800
Received: from cx-a.mxthunder.net ([108.60.195.213])
by mail-archive.com with esmtp (Exim 4.76)
(envelope-from 
)
id 1c7LWE-0005aT-TD
for archive+...@mail-archive.com; Thu, 17 Nov 2016 04:10:19 -0800
Received: by bolt10a.mxthunder.net (Postfix, from userid 12345)
id 3tKKgz5CVlz15Wdy; Thu, 17 Nov 2016 04:10:05 -0800 (PST)
Received: from mail-pg0-f59.google.com (mail-pg0-f59.google.com [74.125.83.59])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by bolt10a.mxthunder.net (Postfix) with ESMTPS id 3tKKgt0BmNz16cLR
for ; Thu, 17 Nov 2016 04:10:01 -0800 
(PST)
Received: by mail-pg0-f59.google.com with SMTP id 3sf98062624pgd.0
for ; Thu, 17 Nov 2016 04:10:01 -0800 
(PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlegroups.com; s=20120806;
h=sender:date:from:to:message-id:in-reply-to:references:subject
 :mime-version:x-original-sender:x-original-authentication-results
 :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
 :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
bh=zf543FN2JlPxcQVZGnattGcdsWVumfOMPMBp1zF3Af8=;
b=wSBn6TEerEAX5+dwcmdhDi9N9QNl14UPun7Usbv8NtQyg0qVAD4SqCw1ym7FzkQtRx
 m8r6RiJ4crdDTvA1Q2Md9ETlrfFfGReHJ0sl1faaLWS0GhEa5jXTIgq9ENai4QEZ2Lfw
 oZbxjEUZinz+PWAd6GiHOq8+zjjt4vloTgSSXSwd4xIJeV4XePAv6BOBQMJ3ivLcrpp2
 4lk1f7mK/moFt0hyCNKiwnla+M+m1EypyZfMBS3cPgx9JIWGtPmw29LQs76rFF+7dxj/
 2KiJeBhJpQGhII0XRBi7VhzzOokxJFg6WuIU7zx2oJO2El15j5dy06SfGa8SCZcYitAy
 aiew==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20130820;
h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to
 :references:subject:mime-version:x-original-sender
 :x-original-authentication-results:reply-to:precedence:mailing-list
 :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
 :list-subscribe:list-unsubscribe;
bh=zf543FN2JlPxcQVZGnattGcdsWVumfOMPMBp1zF3Af8=;
b=BI1pcSthsptIv2OgLOaWm913GNPmi4tNRzMmgCqgD9M4sCt0DD7mEmJYggQ5r01Udy
 zlshC2HQB+VtDUDjD3aA9drg4iYNCMMX+hfZODcfUUv8Q4Xz26iwPx9GSSidvtiMxqVy
 oV1j22ERQv03JOhi1eB0XYcHhL/Rp3SjEBO2VfKUUkSDWenRqo5IgTumuobiord0WWo6
 GyaaI1PrAMxCFHOlgRv+2CdFhGnP3o1tlhF1+Ydxet+lecakNIYcmLA12T9OpIiygEPU
 b1ur89jXIrSqjZiSoUvkYk/cyg7K48g/vdleQc2Ea/lJdJa2THYJUiWzjf7O5R7le8gT
 rdTg==
Sender: jenkinsci-iss...@googlegroups.com
X-Gm-Message-State: 
AKaTC03hIc3/YTDYP4OQyvfut5weleKG9S82U7kUe8dREEAjwgEKwQfd6rKAARCq3NX5aw==
X-Received: by 10.157.15.143 with SMTP id d15mr176761otd.2.1479384600955;
Thu, 17 Nov 2016 04:10:00 -0800 (PST)
X-BeenThere: jenkinsci-iss...@googlegroups.com
Received: by 10.157.9.183 with SMTP id q52ls3619597otd.22.gmail; Thu, 17 Nov
 2016 04:10:00 -0800 (PST)
X-Received: by 10.31.107.72 with SMTP id g69mr504281vkc.39.1479384600664;
Thu, 17 Nov 2016 04:10:00 -0800 (PST)
Received: from fraxinus.osuosl.org (smtp4.osuosl.org. [140.211.166.137])
by gmr-mx.google.com with ESMTPS id p14si729526pfl.0.2016.11.17.04.10.00
for 
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Thu, 17 Nov 2016 04:10:00 -0800 (PST)
Received-SPF: pass (google.com: domain of nore...@jenkins-ci.org designates 
140.211.166.137 as permitted sender) client-ip=140.211.166.137;
Received: from localhost (localhost [127.0.0.1])
by fraxinus.osuosl.org (Postfix) with ESMTP id 583F888114
for ; Thu, 17 Nov 2016 12:10:00 
+ (UTC)
X-Virus-Scanned: amavisd-new at osuosl.org
Received: from fraxinus.osuosl.org ([127.0.0.1])
by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id cAULCyyxYTgp for ;
Thu, 17 Nov 2016 12:10:00 + (UTC)
Received: from ade610a62fdf 

Re: [v15, 06/15] selftests/powerpc: Add ptrace tests for GPR/FPR registers in suspended TM

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:55 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for GPR/FPR registers
> inside suspended TM context.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/c7096dc0ee02ee7fd885c8010aad2c

cheers


Re: [v15, 05/15] selftests/powerpc: Add ptrace tests for GPR/FPR registers in TM

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:54 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for GPR/FPR registers
> inside TM context. This adds ptrace interface based helper
> functions related to checkpointed GPR/FPR access.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/509fcfe57b09637a80fe0fcacd052e

cheers


Re: [v15,03/15] selftests/powerpc: Add ptrace tests for EBB

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:52 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds ptrace interface test for EBB/PMU specific
> registers. This also adds some generic ptrace interface
> based helper functions to be used by other patches later
> on in the series.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/f666ad413db6f7fbfaeec6b11ed6f8

cheers


Re: [v15, 01/15] selftests/powerpc: Add more SPR numbers, TM & VMX instructions to 'reg.h'/'instructions.h'

2016-11-17 Thread Michael Ellerman
On Fri, 2016-30-09 at 02:32:50 UTC, Simon Guo wrote:
> From: Anshuman Khandual 
> 
> This patch adds SPR number for TAR, PPR, DSCR special
> purpose registers. It also adds TM, VSX, VMX related
> instructions which will then be used by patches later
> in the series.
> 
> Now that the new DSCR register definitions (SPRN_DSCR_PRIV and
> SPRN_DSCR) are defined outside this directory, use them instead.
> 
> Signed-off-by: Anshuman Khandual 
> Signed-off-by: Simon Guo 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/efe71a67b5aa89e0348ac862ca92a5

cheers


[RFC PATCH] of: base: add support to get machine model name

2016-11-17 Thread Sudeep Holla
Currently platforms/drivers needing to get the machine model name are
replicating the same snippet of code. In some case, the OF reference
counting is either missing or incorrect.

This patch adds support to read the machine model name either using
the "model" or the "compatible" property in the device tree root node.

Signed-off-by: Sudeep Holla 
---
 arch/arm/mach-imx/cpu.c   |  4 +---
 arch/arm/mach-mxs/mach-mxs.c  |  3 +--
 arch/mips/cavium-octeon/setup.c   | 12 ++--
 arch/mips/generic/proc.c  | 15 +++
 arch/sh/boards/of-generic.c   |  6 +-
 drivers/of/base.c | 34 ++
 drivers/soc/fsl/guts.c|  3 +--
 drivers/soc/renesas/renesas-soc.c |  4 +---
 include/linux/of.h|  6 ++
 9 files changed, 50 insertions(+), 37 deletions(-)

Hi,

While trying to fix a simple build warning(as below) in -next for fsl/guts.c,
I came across this code duplication in multiple places.

WARNING: modpost: Found 1 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'

With CONFIG_DEBUG_SECTION_MISMATCH enabled, the details are reported:

WARNING: vmlinux.o(.text+0x55d014): Section mismatch in reference from the
function fsl_guts_probe() to the function
.init.text:of_flat_dt_get_machine_name()
The function fsl_guts_probe() references
the function __init of_flat_dt_get_machine_name().
This is often because fsl_guts_probe lacks a __init
annotation or the annotation of of_flat_dt_get_machine_name is wrong.

I can split the patch if needed if people are OK with the idea.

Regards,
Sudeep

diff --git a/arch/arm/mach-imx/cpu.c b/arch/arm/mach-imx/cpu.c
index b3347d32349f..846f40008752 100644
--- a/arch/arm/mach-imx/cpu.c
+++ b/arch/arm/mach-imx/cpu.c
@@ -85,9 +85,7 @@ struct device * __init imx_soc_device_init(void)

soc_dev_attr->family = "Freescale i.MX";

-   root = of_find_node_by_path("/");
-   ret = of_property_read_string(root, "model", _dev_attr->machine);
-   of_node_put(root);
+   ret = of_machine_get_model_name(_dev_attr->machine);
if (ret)
goto free_soc;

diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index e4f21086b42b..ed9af3a894f0 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -391,8 +391,7 @@ static void __init mxs_machine_init(void)
if (!soc_dev_attr)
return;

-   root = of_find_node_by_path("/");
-   ret = of_property_read_string(root, "model", _dev_attr->machine);
+   ret = of_machine_get_model_name(_dev_attr->machine);
if (ret)
return;

diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c
index 9a2db1c013d9..2e2b1b5befa4 100644
--- a/arch/mips/cavium-octeon/setup.c
+++ b/arch/mips/cavium-octeon/setup.c
@@ -498,16 +498,8 @@ static void __init init_octeon_system_type(void)
char const *board_type;

board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
-   if (board_type == NULL) {
-   struct device_node *root;
-   int ret;
-
-   root = of_find_node_by_path("/");
-   ret = of_property_read_string(root, "model", _type);
-   of_node_put(root);
-   if (ret)
-   board_type = "Unsupported Board";
-   }
+   if (!board_type && of_machine_get_model_name(_type))
+   board_type = "Unsupported Board";

snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
 board_type, octeon_model_get_string(read_c0_prid()));
diff --git a/arch/mips/generic/proc.c b/arch/mips/generic/proc.c
index 42b33250a4a2..f7fc067bf908 100644
--- a/arch/mips/generic/proc.c
+++ b/arch/mips/generic/proc.c
@@ -10,20 +10,11 @@

 #include 

-#include 
-
 const char *get_system_type(void)
 {
const char *str;
-   int err;
-
-   err = of_property_read_string(of_root, "model", );
-   if (!err)
-   return str;
-
-   err = of_property_read_string_index(of_root, "compatible", 0, );
-   if (!err)
-   return str;

-   return "Unknown";
+   if (of_machine_get_model_name())
+   return "Unknown";
+   return str;
 }
diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c
index 1fb6d5714bae..938a14499298 100644
--- a/arch/sh/boards/of-generic.c
+++ b/arch/sh/boards/of-generic.c
@@ -135,11 +135,7 @@ static void __init sh_of_setup(char **cmdline_p)
board_time_init = sh_of_time_init;

sh_mv.mv_name = "Unknown SH model";
-   root = of_find_node_by_path("/");
-   if (root) {
-   of_property_read_string(root, "model", _mv.mv_name);
-   of_node_put(root);
-   }
+   of_machine_get_model_name(_mv.mv_name);

sh_of_smp_probe();
 }
diff --git a/drivers/of/base.c 

Re: [PATCH 1/2] soc: fsl: make it explicitly non-modular

2016-11-17 Thread Sudeep Holla



On 16/11/16 16:39, Sudeep Holla wrote:

The Kconfig currently controlling compilation of this code is:

drivers/soc/fsl/Kconfig:config FSL_GUTS
drivers/soc/fsl/Kconfig:   bool

...meaning that it currently is not being built as a module by anyone.

Lets remove the modular code that is essentially orphaned, so that
when reading the driver there is no doubt it is builtin-only.

Since module_init was not in use by this code, the init ordering
remains unchanged with this commit.

Cc: Scott Wood 
Cc: Yangbo Lu 
Cc: Arnd Bergmann 
Signed-off-by: Sudeep Holla 
---


I saw Paul Gortmaker had sent similar patch on Nov 15, so drop/ignore this.

--
Regards,
Sudeep


Re: [PATCH 0/2] powerpc: stack protector (-fstack-protector) support

2016-11-17 Thread Michael Ellerman
Denis Kirjanov  writes:

> On Friday, September 30, 2016, Christophe Leroy 
> wrote:
>
>> Add HAVE_CC_STACKPROTECTOR to powerpc. This is copied from ARM.
>>
>> Not tested on PPC64, compile ok with ppc64_
>
>
> Hi Christophe,
>
> are you going to test it on ppc64? If not, I can take it

Did you get around to testing it?

It seems to be working here:

  root@mpe-ubuntu-le:/sys/kernel/debug/provoke-crash# echo CORRUPT_STACK > 
DIRECT
  Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: 
c0671ed8
  
  CPU: 1 PID: 3835 Comm: bash Not tainted 
4.9.0-rc5-compiler_gcc-6.2.0-00075-gf41db6c7a3c8-dirty #464
  Call Trace:
  [c000dbf73a30] [c0541728] dump_stack+0xb8/0x100 (unreliable)
  
  [c000dbf73a70] [c0219ba8] panic+0x14c/0x320
  [c000dbf73b10] [c00c27ec] __stack_chk_fail+0x2c/0x30
  [c000dbf73b70] [c0671ed8] lkdtm_CORRUPT_STACK+0x88/0x90
  [c000dbf73bf0] [6161616161616161] 0x6161616161616161
  Rebooting in 10 seconds..


cheers


Re: [PATCH 1/2] powerpc: initial stack protector (-fstack-protector) support

2016-11-17 Thread Michael Ellerman
Christophe Leroy  writes:

> diff --git a/arch/powerpc/include/asm/stackprotector.h 
> b/arch/powerpc/include/asm/stackprotector.h
> new file mode 100644
> index 000..de00332
> --- /dev/null
> +++ b/arch/powerpc/include/asm/stackprotector.h
> @@ -0,0 +1,38 @@
> +/*
> + * GCC stack protector support.
> + *
> + * Stack protector works by putting predefined pattern at the start of
> + * the stack frame and verifying that it hasn't been overwritten when
> + * returning from the function.  The pattern is called stack canary
> + * and gcc expects it to be defined by a global variable called
> + * "__stack_chk_guard" on ARM.  This unfortunately means that on SMP
 ^
 PPC
 
> + * we cannot have a different canary value per task.
> + */
> +
> +#ifndef _ASM_STACKPROTECTOR_H
> +#define _ASM_STACKPROTECTOR_H 1

We usually just define it, not define it to 1.

> +
> +#include 
> +#include 
> +
> +extern unsigned long __stack_chk_guard;
> +
> +/*
> + * Initialize the stackprotector canary value.
> + *
> + * NOTE: this must only be called from functions that never return,
> + * and it must always be inlined.
> + */
> +static __always_inline void boot_init_stack_canary(void)
> +{
> + unsigned long canary;
> +
> + /* Try to get a semi random initial value. */
> + get_random_bytes(, sizeof(canary));
> + canary ^= LINUX_VERSION_CODE;

What about mixing in an mftb() as well ?

> diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
> index e59ed6a..4a62179 100644
> --- a/arch/powerpc/kernel/Makefile
> +++ b/arch/powerpc/kernel/Makefile
> @@ -19,6 +19,11 @@ CFLAGS_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
>  CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
>  CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
>  
> +# -fstack-protector triggers protection checks in this code,
> +# but it is being used too early to link to meaningful stack_chk logic.
> +nossp_flags := $(call cc-option, -fno-stack-protector)
> +CFLAGS_prom_init.o := $(nossp_flags)

We've already assigned to CFLAGS_prom_init.o so I think you should be
using += not := shouldn't you?

Also it could just be a single line:

CFLAGS_prom_init.o += $(call cc-option, -fno-stack-protector)


cheers


[PATCH v2 2/2] DT: i2c: W83793 is a trivial device

2016-11-17 Thread Florian Larysch
Signed-off-by: Florian Larysch 
---
 Documentation/devicetree/bindings/i2c/trivial-devices.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/i2c/trivial-devices.txt 
b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
index fbbad64..c65aff0 100644
--- a/Documentation/devicetree/bindings/i2c/trivial-devices.txt
+++ b/Documentation/devicetree/bindings/i2c/trivial-devices.txt
@@ -158,4 +158,5 @@ ti,tsc2003  I2C Touch-Screen Controller
 ti,tmp102  Low Power Digital Temperature Sensor with SMBUS/Two 
Wire Serial Interface
 ti,tmp103  Low Power Digital Temperature Sensor with SMBUS/Two 
Wire Serial Interface
 ti,tmp275  Digital Temperature Sensor
+winbond,w83793 Winbond/Nuvoton H/W Monitor
 winbond,wpct301i2c trusted platform module (TPM)
-- 
2.10.2



[PATCH v2 1/2] powerpc/dts: add device tree entry for W83793 on T4240RDB

2016-11-17 Thread Florian Larysch
The T4240RDB contains a W83793 hardware monitoring chip. Add a device
tree entry to make the driver attach to it, as the i2c-mpc bus driver
dropped support for class-based instantiation of devices a long time
ago.

Signed-off-by: Florian Larysch 
---
 arch/powerpc/boot/dts/fsl/t4240rdb.dts | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/boot/dts/fsl/t4240rdb.dts 
b/arch/powerpc/boot/dts/fsl/t4240rdb.dts
index cc0a264..8166c66 100644
--- a/arch/powerpc/boot/dts/fsl/t4240rdb.dts
+++ b/arch/powerpc/boot/dts/fsl/t4240rdb.dts
@@ -125,6 +125,10 @@
};
 
i2c@118000 {
+   hwmon@2f {
+   compatible = "winbond,w83793";
+   reg = <0x2f>;
+   };
eeprom@52 {
compatible = "at24,24c256";
reg = <0x52>;
-- 
2.10.2



[PATCH v2 0/2] T4240RBD: add device tree entry for W83793

2016-11-17 Thread Florian Larysch
v2:
 - Ordered DT nodes by address
 - Added an entry for the chip to the trivial-devices list

Florian Larysch (2):
  powerpc/dts: add device tree entry for W83793 on T4240RDB
  DT: i2c: W83793 is a trivial device

 Documentation/devicetree/bindings/i2c/trivial-devices.txt | 1 +
 arch/powerpc/boot/dts/fsl/t4240rdb.dts| 4 
 2 files changed, 5 insertions(+)

-- 
2.10.2



[PATCH] powerpc/mm: Update hid register on secondaries too

2016-11-17 Thread Aneesh Kumar K.V
We need to update on secondaries for the selected MMU mode.

Fixes: ad410674f5606a ("powerpc/mm: Update the HID bit when switching from 
radix to hash")

Reported-by: Michael Neuling 
Signed-off-by: Aneesh Kumar K.V 
---
 arch/powerpc/mm/hash_utils_64.c | 4 
 arch/powerpc/mm/pgtable-radix.c | 4 
 2 files changed, 8 insertions(+)

diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 44d3c3a38e3e..5503078090cd 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -1029,6 +1029,10 @@ void hash__early_init_mmu_secondary(void)
 {
/* Initialize hash table for that CPU */
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
+
+   if (cpu_has_feature(CPU_FTR_POWER9_DD1))
+   update_hid_for_hash();
+
if (!cpu_has_feature(CPU_FTR_ARCH_300))
mtspr(SPRN_SDR1, _SDR1);
else
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index 735be6821e90..2fc7336619b3 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -404,6 +404,10 @@ void radix__early_init_mmu_secondary(void)
 * update partition table control register and UPRT
 */
if (!firmware_has_feature(FW_FEATURE_LPAR)) {
+
+   if (cpu_has_feature(CPU_FTR_POWER9_DD1))
+   update_hid_for_radix();
+
lpcr = mfspr(SPRN_LPCR);
mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR);
 
-- 
2.10.2



[RFC] powerpc: xmon: Add address lookup for percpu symbols

2016-11-17 Thread Boqun Feng
Currently, in xmon, there is no obvious way to get an address for a
percpu symbol for a particular cpu. Having such an ability would be good
for debugging the system when percpu variables got involved.

Therefore, this patch introduces a new xmon command "lp" to lookup the
address for percpu symbols. Usage of "lp" is similar to "ls", except
that we could add a cpu number to choose the variable of which cpu we
want to lookup. If no cpu number is given, lookup for current cpu.

Signed-off-by: Boqun Feng 
---
 arch/powerpc/xmon/xmon.c | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 760545519a0b..3556966a29a5 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -229,6 +229,7 @@ Commands:\n\
   fflush cache\n\
   la   lookup symbol+offset of specified address\n\
   ls   lookup address of specified symbol\n\
+  lp s [#] lookup address of percpu symbol s for current cpu, or cpu #\n\
   mexamine/change memory\n\
   mm   move a block of memory\n\
   ms   set a block of memory\n\
@@ -2943,7 +2944,7 @@ static void
 symbol_lookup(void)
 {
int type = inchar();
-   unsigned long addr;
+   unsigned long addr, cpu, offset;
static char tmp[64];
 
switch (type) {
@@ -2967,6 +2968,31 @@ symbol_lookup(void)
catch_memory_errors = 0;
termch = 0;
break;
+   case 'p':
+   getstring(tmp, 64);
+   if (setjmp(bus_error_jmp) == 0) {
+   catch_memory_errors = 1;
+   sync();
+   addr = kallsyms_lookup_name(tmp);
+   sync();
+   }
+
+   if (scanhex() && cpu < num_possible_cpus())
+   offset = per_cpu_offset(cpu);
+   else {
+   offset = my_cpu_offset;
+   cpu = raw_smp_processor_id();
+   }
+
+   if (addr)
+   printf("%s for cpu 0x%lx: %lx\n", tmp, cpu,
+ addr + offset);
+   else
+   printf("Percpu symbol '%s' not found.\n", tmp);
+
+   catch_memory_errors = 0;
+   termch = 0;
+   break;
}
 }
 
-- 
2.10.1



[PATCH v4 12/15] scsi: fc: use bsg_job_done

2016-11-17 Thread Johannes Thumshirn
fc_bsg_jobdone() and bsg_job_done() are 1:1 copies now so use the bsg-lib one
instead of the FC private implementation.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
Acked-by: Tyrel Datwyler 
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  4 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  2 +-
 drivers/scsi/libfc/fc_lport.c|  4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 40 ++--
 drivers/scsi/qla2xxx/qla_bsg.c   | 44 
 drivers/scsi/scsi_transport_fc.c | 41 +++--
 include/scsi/scsi_transport_fc.h |  2 --
 8 files changed, 51 insertions(+), 88 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index f01b9a4..7331eea 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -893,7 +893,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
+   bsg_job_done(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index cdc25e6..a9a0016 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3179,7 +3179,7 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
return rc;
 error:
@@ -3555,7 +3555,7 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
 
return rc;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index f59b0a1..78b72c2 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1946,7 +1946,7 @@ static int ibmvfc_bsg_request(struct bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index c428ce3..2be7015 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1912,7 +1912,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->result = (PTR_ERR(fp) == -FC_EX_CLOSED) ?
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
@@ -1947,7 +1947,7 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
bsg_reply->reply_payload_rcv_len =
job->reply_payload.payload_len;
bsg_reply->result = 0;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
kfree(info);
}
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index b19ad9e..7dca4d6 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -645,7 +645,7 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   fc_bsg_jobdone(job, bsg_reply->result,
+   bsg_job_done(job, bsg_reply->result,
   bsg_reply->reply_payload_rcv_len);
}
return;
@@ -1138,7 +1138,7 @@ struct lpfc_dmabufext {
job->dd_data = NULL;
/* complete the job back to userspace */
spin_unlock_irqrestore(>ct_ev_lock, flags);
-   fc_bsg_jobdone(job, bsg_reply->result,
+   

[PATCH v4 02/15] scsi: don't use fc_bsg_job::request and fc_bsg_job::reply directly

2016-11-17 Thread Johannes Thumshirn
Don't use fc_bsg_job::request and fc_bsg_job::reply directly, but use
helper variables bsg_request and bsg_reply. This will be helpfull  when
transitioning to bsg-lib.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
---
 drivers/s390/scsi/zfcp_fc.c  |   9 +-
 drivers/scsi/bfa/bfad_bsg.c  |  40 +++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  22 ++--
 drivers/scsi/libfc/fc_lport.c|  23 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 199 ++---
 drivers/scsi/qla2xxx/qla_bsg.c   | 264 ++-
 drivers/scsi/qla2xxx/qla_iocb.c  |   5 +-
 drivers/scsi/qla2xxx/qla_isr.c   |  46 ---
 drivers/scsi/qla2xxx/qla_mr.c|  10 +-
 drivers/scsi/scsi_transport_fc.c |  55 
 10 files changed, 398 insertions(+), 275 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 237688a..4c4023f 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -900,8 +900,9 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
u32 preamble_word1;
u8 gs_type;
struct zfcp_adapter *adapter;
+   struct fc_bsg_request *bsg_request = job->request;
 
-   preamble_word1 = job->request->rqst_data.r_ct.preamble_word1;
+   preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
@@ -938,6 +939,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
struct fc_rport *rport = job->rport;
+   struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
 
@@ -949,7 +951,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
d_id = port->d_id;
put_device(>dev);
} else
-   d_id = ntoh24(job->request->rqst_data.h_els.port_id);
+   d_id = ntoh24(bsg_request->rqst_data.h_els.port_id);
 
els->handler = zfcp_fc_ct_els_job_handler;
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
@@ -983,6 +985,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
+   struct fc_bsg_request *bsg_request = job->request;
 
shost = job->rport ? rport_to_shost(job->rport) : job->shost;
adapter = (struct zfcp_adapter *)shost->hostdata[0];
@@ -994,7 +997,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
ct_els->resp = job->reply_payload.sg_list;
ct_els->handler_data = job;
 
-   switch (job->request->msgcode) {
+   switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
case FC_BSG_HST_ELS_NOLOGIN:
return zfcp_fc_exec_els_job(job, adapter);
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d1ad020..48366d8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3132,7 +3132,9 @@
 static int
 bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
 {
-   uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
+   struct fc_bsg_request *bsg_request = job->request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
struct bfad_im_port_s *im_port =
(struct bfad_im_port_s *) job->shost->hostdata[0];
struct bfad_s *bfad = im_port->bfad;
@@ -3175,8 +3177,8 @@
 
/* Fill the BSG job reply data */
job->reply_len = job->reply_payload.payload_len;
-   job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
-   job->reply->result = rc;
+   bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
+   bsg_reply->result = rc;
 
job->job_done(job);
return rc;
@@ -3184,9 +3186,9 @@
/* free the command buffer */
kfree(payload_kbuf);
 out:
-   job->reply->result = rc;
+   bsg_reply->result = rc;
job->reply_len = sizeof(uint32_t);
-   job->reply->reply_payload_rcv_len = 0;
+   bsg_reply->reply_payload_rcv_len = 0;
return rc;
 }
 
@@ -3362,18 +3364,20 @@ struct bfad_buf_info *
struct bfad_fcxp*drv_fcxp;
struct bfa_fcs_lport_s *fcs_port;
struct bfa_fcs_rport_s *fcs_rport;
-   uint32_t command_type = job->request->msgcode;
+   struct fc_bsg_request *bsg_request = bsg_request;
+   struct fc_bsg_reply *bsg_reply = job->reply;
+   uint32_t command_type = bsg_request->msgcode;
unsigned long flags;
struct bfad_buf_info *rsp_buf_info;
void *req_kbuf = NULL, *rsp_kbuf = NULL;
int rc = -EINVAL;
 
job->reply_len  = sizeof(uint32_t); /* Atleast uint32_t 

[PATCH v4 09/15] scsi: change FC drivers to use 'struct bsg_job'

2016-11-17 Thread Johannes Thumshirn
Change FC drivers to use 'struct bsg_job' from bsg-lib.h instead of 'struct
fc_bsg_job' from scsi_transport_fc.h and remove 'struct fc_bsg_job'.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
Acked-by: Tyrel Datwyler 
---
 drivers/s390/scsi/zfcp_ext.h |  4 +--
 drivers/s390/scsi/zfcp_fc.c  | 15 
 drivers/scsi/bfa/bfad_bsg.c  | 10 +++---
 drivers/scsi/bfa/bfad_im.h   |  4 +--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  9 ++---
 drivers/scsi/libfc/fc_lport.c| 10 +++---
 drivers/scsi/lpfc/lpfc_bsg.c | 76 
 drivers/scsi/lpfc/lpfc_crtn.h|  4 +--
 drivers/scsi/qla2xxx/qla_bsg.c   | 61 
 drivers/scsi/qla2xxx/qla_def.h   |  2 +-
 drivers/scsi/qla2xxx/qla_gbl.h   |  4 +--
 drivers/scsi/qla2xxx/qla_iocb.c  |  8 ++---
 drivers/scsi/qla2xxx/qla_isr.c   |  6 ++--
 drivers/scsi/qla2xxx/qla_mr.c|  5 +--
 drivers/scsi/scsi_transport_fc.c | 20 +--
 include/scsi/libfc.h |  2 +-
 include/scsi/scsi_transport_fc.h | 63 ++---
 17 files changed, 139 insertions(+), 164 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index c8fed9f..968a0ab 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -84,8 +84,8 @@ extern void zfcp_fc_enqueue_event(struct zfcp_adapter *,
 extern void zfcp_fc_wka_ports_force_offline(struct zfcp_fc_wka_ports *);
 extern int zfcp_fc_gs_setup(struct zfcp_adapter *);
 extern void zfcp_fc_gs_destroy(struct zfcp_adapter *);
-extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *);
-extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *);
+extern int zfcp_fc_exec_bsg_job(struct bsg_job *);
+extern int zfcp_fc_timeout_bsg_job(struct bsg_job *);
 extern void zfcp_fc_sym_name_update(struct work_struct *);
 extern unsigned int zfcp_fc_port_scan_backoff(void);
 extern void zfcp_fc_conditional_port_scan(struct zfcp_adapter *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index c751003..f01b9a4 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "zfcp_ext.h"
@@ -885,7 +886,7 @@ void zfcp_fc_sym_name_update(struct work_struct *work)
 
 static void zfcp_fc_ct_els_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fsf_ct_els *zfcp_ct_els = job->dd_data;
struct fc_bsg_reply *jr = job->reply;
 
@@ -895,7 +896,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
-static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
+static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct bsg_job *job)
 {
u32 preamble_word1;
u8 gs_type;
@@ -928,7 +929,7 @@ static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct 
fc_bsg_job *job)
 
 static void zfcp_fc_ct_job_handler(void *data)
 {
-   struct fc_bsg_job *job = data;
+   struct bsg_job *job = data;
struct zfcp_fc_wka_port *wka_port;
 
wka_port = zfcp_fc_job_wka_port(job);
@@ -937,7 +938,7 @@ static void zfcp_fc_ct_job_handler(void *data)
zfcp_fc_ct_els_job_handler(data);
 }
 
-static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_els_job(struct bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
@@ -960,7 +961,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
return zfcp_fsf_send_els(adapter, d_id, els, job->req->timeout / HZ);
 }
 
-static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
+static int zfcp_fc_exec_ct_job(struct bsg_job *job,
   struct zfcp_adapter *adapter)
 {
int ret;
@@ -983,7 +984,7 @@ static int zfcp_fc_exec_ct_job(struct fc_bsg_job *job,
return ret;
 }
 
-int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_exec_bsg_job(struct bsg_job *job)
 {
struct Scsi_Host *shost;
struct zfcp_adapter *adapter;
@@ -1013,7 +1014,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
}
 }
 
-int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *job)
+int zfcp_fc_timeout_bsg_job(struct bsg_job *job)
 {
/* hardware tracks timeout, reset bsg timeout to not interfere */
return -EAGAIN;
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index d3094270..cdc25e6 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3130,7 +3130,7 @@
 }
 
 static int
-bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
+bfad_im_bsg_vendor_request(struct bsg_job *job)
 {
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
@@ -3314,7 +3314,7 @@ 

[PATCH v4 05/15] scsi: fc: provide fc_bsg_to_rport() helper

2016-11-17 Thread Johannes Thumshirn
Provide fc_bsg_to_rport() helper that will become handy when we're moving
from struct fc_bsg_job to a plain struct bsg_job. Also move all LLDDs to use
the new helper.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
Acked-by: Tyrel Datwyler 
---
 drivers/s390/scsi/zfcp_fc.c  | 8 +---
 drivers/scsi/ibmvscsi/ibmvfc.c   | 2 +-
 drivers/scsi/libfc/fc_lport.c| 4 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 4 ++--
 drivers/scsi/qla2xxx/qla_bsg.c   | 4 ++--
 drivers/scsi/scsi_transport_fc.c | 3 ++-
 include/scsi/scsi_transport_fc.h | 5 +
 7 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 3937deb..c751003 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -901,12 +901,13 @@ static struct zfcp_fc_wka_port 
*zfcp_fc_job_wka_port(struct fc_bsg_job *job)
u8 gs_type;
struct zfcp_adapter *adapter;
struct fc_bsg_request *bsg_request = job->request;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct Scsi_Host *shost;
 
preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
-   shost = fc_bsg_to_shost(job);
+   shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *) shost->hostdata[0];
 
switch (gs_type) {
@@ -940,7 +941,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
struct zfcp_adapter *adapter)
 {
struct zfcp_fsf_ct_els *els = job->dd_data;
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct fc_bsg_request *bsg_request = job->request;
struct zfcp_port *port;
u32 d_id;
@@ -988,8 +989,9 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_adapter *adapter;
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
 
-   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
+   shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 02df1f1..4c73fc7 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1822,7 +1822,7 @@ static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, 
unsigned int port_id)
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
-   struct fc_rport *rport = job->rport;
+   struct fc_rport *rport = fc_bsg_to_rport(job);
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
union ibmvfc_iu rsp_iu;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 3e3afe6..5e24ca3 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2103,7 +2103,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
 
switch (bsg_request->msgcode) {
case FC_BSG_RPT_ELS:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
@@ -2113,7 +2113,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
break;
 
case FC_BSG_RPT_CT:
-   rport = job->rport;
+   rport = fc_bsg_to_rport(job);
if (!rport)
break;
 
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 45184ee..19847d7 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -386,7 +386,7 @@ struct lpfc_dmabufext {
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_reply *bsg_reply = job->reply;
struct ulp_bde64 *bpl = NULL;
@@ -660,7 +660,7 @@ struct lpfc_dmabufext {
 {
struct lpfc_vport *vport = shost_priv(fc_bsg_to_shost(job));
struct lpfc_hba *phba = vport->phba;
-   struct lpfc_rport_data *rdata = job->rport->dd_data;
+   struct lpfc_rport_data *rdata = fc_bsg_to_rport(job)->dd_data;
struct lpfc_nodelist *ndlp = rdata->pnode;
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index 109b852..917eafe 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ 

[PATCH v4 04/15] scsi: fc: provide fc_bsg_to_shost() helper

2016-11-17 Thread Johannes Thumshirn
Provide fc_bsg_to_shost() helper that will become handy when we're moving from
struct fc_bsg_job to a plain struct bsg_job. Also use this little helper in
the LLDDs.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
Acked-by: Tyrel Datwyler 
---
 drivers/s390/scsi/zfcp_fc.c  |  6 +++--
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++---
 drivers/scsi/ibmvscsi/ibmvfc.c   |  4 +--
 drivers/scsi/libfc/fc_lport.c|  2 +-
 drivers/scsi/lpfc/lpfc_bsg.c | 34 -
 drivers/scsi/qla2xxx/qla_bsg.c   | 54 
 drivers/scsi/scsi_transport_fc.c |  2 +-
 include/scsi/scsi_transport_fc.h |  5 
 8 files changed, 59 insertions(+), 54 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 87f6330..3937deb 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -901,11 +901,13 @@ static struct zfcp_fc_wka_port 
*zfcp_fc_job_wka_port(struct fc_bsg_job *job)
u8 gs_type;
struct zfcp_adapter *adapter;
struct fc_bsg_request *bsg_request = job->request;
+   struct Scsi_Host *shost;
 
preamble_word1 = bsg_request->rqst_data.r_ct.preamble_word1;
gs_type = (preamble_word1 & 0xff00) >> 24;
 
-   adapter = (struct zfcp_adapter *) job->shost->hostdata[0];
+   shost = fc_bsg_to_shost(job);
+   adapter = (struct zfcp_adapter *) shost->hostdata[0];
 
switch (gs_type) {
case FC_FST_ALIAS:
@@ -987,7 +989,7 @@ int zfcp_fc_exec_bsg_job(struct fc_bsg_job *job)
struct zfcp_fsf_ct_els *ct_els = job->dd_data;
struct fc_bsg_request *bsg_request = job->request;
 
-   shost = job->rport ? rport_to_shost(job->rport) : job->shost;
+   shost = job->rport ? rport_to_shost(job->rport) : fc_bsg_to_shost(job);
adapter = (struct zfcp_adapter *)shost->hostdata[0];
 
if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index e49a6c8..d3094270 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3135,8 +3135,7 @@
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
uint32_t vendor_cmd = bsg_request->rqst_data.h_vendor.vendor_cmd[0];
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
struct request_queue *request_q = job->req->q;
void *payload_kbuf;
@@ -3358,8 +3357,7 @@ struct bfad_buf_info *
 bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
 {
struct bfa_bsg_data *bsg_data;
-   struct bfad_im_port_s *im_port =
-   (struct bfad_im_port_s *) job->shost->hostdata[0];
+   struct bfad_im_port_s *im_port = shost_priv(fc_bsg_to_shost(job));
struct bfad_s *bfad = im_port->bfad;
bfa_bsg_fcpt_t *bsg_fcpt;
struct bfad_fcxp*drv_fcxp;
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 6070361..02df1f1 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1708,7 +1708,7 @@ static void ibmvfc_bsg_timeout_done(struct ibmvfc_event 
*evt)
  **/
 static int ibmvfc_bsg_timeout(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
unsigned long port_id = (unsigned long)job->dd_data;
struct ibmvfc_event *evt;
struct ibmvfc_tmf *tmf;
@@ -1821,7 +1821,7 @@ static int ibmvfc_bsg_plogi(struct ibmvfc_host *vhost, 
unsigned int port_id)
  **/
 static int ibmvfc_bsg_request(struct fc_bsg_job *job)
 {
-   struct ibmvfc_host *vhost = shost_priv(job->shost);
+   struct ibmvfc_host *vhost = shost_priv(fc_bsg_to_shost(job));
struct fc_rport *rport = job->rport;
struct ibmvfc_passthru_mad *mad;
struct ibmvfc_event *evt;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 8ea6e93..3e3afe6 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -2088,7 +2088,7 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
struct fc_bsg_request *bsg_request = job->request;
struct fc_bsg_reply *bsg_reply = job->reply;
struct request *rsp = job->req->next_rq;
-   struct Scsi_Host *shost = job->shost;
+   struct Scsi_Host *shost = fc_bsg_to_shost(job);
struct fc_lport *lport = shost_priv(shost);
struct fc_rport *rport;
struct fc_rport_priv *rdata;
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index 46f0b8f..45184ee 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -384,7 +384,7 @@ struct 

[PATCH v4 03/15] scsi: fc: Export fc_bsg_jobdone and use it in FC drivers

2016-11-17 Thread Johannes Thumshirn
Export fc_bsg_jobdone so drivers can use it directly instead of doing
the round-trip via struct fc_bsg_job::job_done() and use it in the LLDDs.
That way we can also unify the interfaces of fc_bsg_jobdone and bsg_job_done.

As we've converted all LLDDs over to use fc_bsg_jobdone() directly,
we can remove the function pointer from struct fc_bsg_job as well.

Signed-off-by: Johannes Thumshirn 
Reviewed-by: Hannes Reinecke 
Reviewed-by: Christoph Hellwig 
Acked-by: Tyrel Datwyler 
---
 drivers/s390/scsi/zfcp_fc.c  |  2 +-
 drivers/scsi/bfa/bfad_bsg.c  |  6 ++--
 drivers/scsi/ibmvscsi/ibmvfc.c   |  3 +-
 drivers/scsi/libfc/fc_lport.c|  6 ++--
 drivers/scsi/lpfc/lpfc_bsg.c | 71 +++-
 drivers/scsi/qla2xxx/qla_bsg.c   | 66 -
 drivers/scsi/scsi_transport_fc.c | 25 +++---
 include/scsi/scsi_transport_fc.h |  3 +-
 8 files changed, 119 insertions(+), 63 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 4c4023f..87f6330 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -892,7 +892,7 @@ static void zfcp_fc_ct_els_job_handler(void *data)
jr->reply_payload_rcv_len = job->reply_payload.payload_len;
jr->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
jr->result = zfcp_ct_els->status ? -EIO : 0;
-   job->job_done(job);
+   fc_bsg_jobdone(job, jr->result, jr->reply_payload_rcv_len);
 }
 
 static struct zfcp_fc_wka_port *zfcp_fc_job_wka_port(struct fc_bsg_job *job)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 48366d8..e49a6c8 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -3180,7 +3180,8 @@
bsg_reply->reply_payload_rcv_len = job->reply_payload.payload_len;
bsg_reply->result = rc;
 
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
return rc;
 error:
/* free the command buffer */
@@ -3556,7 +3557,8 @@ struct bfad_buf_info *
bsg_reply->result = rc;
 
if (rc == BFA_STATUS_OK)
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
 
return rc;
 }
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 7c17a7e..6070361 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1945,7 +1945,8 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(vhost->host->host_lock, flags);
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
rc = 0;
 out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 2de6093..8ea6e93 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1913,7 +1913,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
-ECONNABORTED : -ETIMEDOUT;
job->reply_len = sizeof(uint32_t);
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
return;
}
@@ -1948,7 +1949,8 @@ static void fc_lport_bsg_resp(struct fc_seq *sp, struct 
fc_frame *fp,
job->reply_payload.payload_len;
bsg_reply->result = 0;
job->state_flags |= FC_RQST_STATE_DONE;
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
kfree(info);
}
fc_frame_free(fp);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index f09a325..46f0b8f 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -371,7 +371,8 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -644,7 +645,8 @@ struct lpfc_dmabufext {
 
if (job) {
bsg_reply->result = rc;
-   job->job_done(job);
+   fc_bsg_jobdone(job, bsg_reply->result,
+  bsg_reply->reply_payload_rcv_len);
}
return;
 }
@@ -1136,7 +1138,8 @@ struct lpfc_dmabufext {
job->dd_data