Re: compiling master.

2016-11-02 Thread Naveen N. Rao
On 2016/11/03 03:55PM, Nicholas Piggin wrote:
> On Wed, 2 Nov 2016 13:49:39 +0300
> Denis Kirjanov  wrote:
> 
> > Hi guys,
> > 
> > compiling ppc head with bunch of asm errors on power8 box (gcc version 
> > 4.8.3 )
> > checked commit log but found nothing special. Looks like it's asm issue?
> > Has anybody seen that?
> > 
> > arch/powerpc/kernel/exceptions-64s.S: Assembler messages:
> > arch/powerpc/kernel/exceptions-64s.S:421: Error: operand out of range
> > (0x8680 is not between 0x and
> > 0x)
> 
> Hey, thanks for the report. It's likely due to the exception vectors rewrite,
> and yes it's an assembler issue (what's your binutils version?). Your errors
> look like they're coming from LOAD_HANDLER(). For some reason it seems to be
> interpreting the immediate as signed, or the actual calculation ends up being
> negative, neither of which should happen.
> 
> It might take a bit of trial and error, and the assembler doesn't give a lot
> of good options to debug it, so if I can reproduce it here with your bintuils
> version it will be helpful.

I saw this issue when trying to do a BE build on RHEL 7.1. The below
fixes this for me and it indeed looks like an issue with the assembler.
Interestingly, the same assembler version on RHEL 7.1 LE does not throw
these errors.

[root@rhel71be linux]# gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-8)

[root@rhel71be linux]# as --version
GNU assembler version 2.23.52.0.1-26.el7 20130226


Signed-off-by: Naveen N. Rao 
---
 arch/powerpc/include/asm/exception-64s.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/exception-64s.h 
b/arch/powerpc/include/asm/exception-64s.h
index 2e4e7d8..9b7b302 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -91,7 +91,7 @@
  */
 #define LOAD_HANDLER(reg, label)   \
ld  reg,PACAKBASE(r13); /* get high part of &label */   \
-   ori reg,reg,(FIXED_SYMBOL_ABS_ADDR(label))@l;
+   ori reg,reg,((FIXED_SYMBOL_ABS_ADDR(label)) & 0x);
 
 /* Exception register prefixes */
 #define EXC_HV H
-- 
2.10.1



Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Shreyas B. Prabhu
On Thu, Nov 3, 2016 at 2:17 AM, Nicholas Piggin  wrote:
> On Thu, 3 Nov 2016 01:56:46 -0400
> "Shreyas B. Prabhu"  wrote:
>
>> On Thu, Nov 3, 2016 at 1:21 AM, Nicholas Piggin  wrote:
>> > On Wed, 2 Nov 2016 14:15:48 +0530
>> > Gautham R Shenoy  wrote:
>> >
>> >> Hi Nick,
>> >>
>> >> On Wed, Nov 02, 2016 at 07:36:24PM +1100, Nicholas Piggin wrote:
>> >> >
>> >> > Okay, I'll work with that. What's the best way to make a P8 do
>> >> > winkle sleeps?
>> >>
>> >> From the userspace, offlining the CPUs of the core will put them to
>> >> winkle.
>> >
>> > Thanks for this. Hum, that r13 manipulation throughout the idle
>> > and exception code is a bit interesting. I'll do the minimal patch
>> > for 4.9, but what's the reason not to just use the winkle state
>> > in the PACA rather than storing it into HSPRG0 bit, can you (or
>> > Shreyas) explain?
>> >
>> Hi Nick,
>>
>> Before deep winkle, checking SRR1's wakeup bits (Bits 46:47) was enough to
>> figure out which idle state we are waking up from. But in P8, SRR1's wakeup
>> bits aren't enough since bits 46:47 are 0b11 for both fast sleep and
>> deep winkle.
>> So to distinguish bw fastsleep and deep winkle, we use the current 
>> HSPRG0/PORE
>> trick. We program the PORE engine (which is used for state restore when 
>> waking
>> up from deep winkle) to restore HSPRG0 with the last bit set (we do this in
>> pnv_save_sprs_for_winkle()). R13 bit manipulation in pnv_restore_hyp_resource
>> is related to this.
>
> Right, I didn't realize how that exactly worked until I had to go read
> the code just now. It's a neat little trick. I'm wondering can we use 
> PACA_THREAD_IDLE_STATE==PNV_THREAD_WINKLE for this instead? It would just
> make the early PACA usage in the exception handlers able to use more common
> code.
>

PACA_THREAD_IDLE_STATE will have what was 'requested'. It may not be the
state we are waking up from. For example, if 7 threads of the core execute
winkle instruction while 1 thread of the same core executes sleep. Here
the core only enters sleep whereas PACA_THREAD_IDLE_STATE for the 7 threads
will have PNV_THREAD_WINKLE.

Thanks,
Shreyas


Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Nicholas Piggin
On Thu, 3 Nov 2016 01:56:46 -0400
"Shreyas B. Prabhu"  wrote:

> On Thu, Nov 3, 2016 at 1:21 AM, Nicholas Piggin  wrote:
> > On Wed, 2 Nov 2016 14:15:48 +0530
> > Gautham R Shenoy  wrote:
> >  
> >> Hi Nick,
> >>
> >> On Wed, Nov 02, 2016 at 07:36:24PM +1100, Nicholas Piggin wrote:  
> >> >
> >> > Okay, I'll work with that. What's the best way to make a P8 do
> >> > winkle sleeps?  
> >>
> >> From the userspace, offlining the CPUs of the core will put them to
> >> winkle.  
> >
> > Thanks for this. Hum, that r13 manipulation throughout the idle
> > and exception code is a bit interesting. I'll do the minimal patch
> > for 4.9, but what's the reason not to just use the winkle state
> > in the PACA rather than storing it into HSPRG0 bit, can you (or
> > Shreyas) explain?
> >  
> Hi Nick,
> 
> Before deep winkle, checking SRR1's wakeup bits (Bits 46:47) was enough to
> figure out which idle state we are waking up from. But in P8, SRR1's wakeup
> bits aren't enough since bits 46:47 are 0b11 for both fast sleep and
> deep winkle.
> So to distinguish bw fastsleep and deep winkle, we use the current HSPRG0/PORE
> trick. We program the PORE engine (which is used for state restore when waking
> up from deep winkle) to restore HSPRG0 with the last bit set (we do this in
> pnv_save_sprs_for_winkle()). R13 bit manipulation in pnv_restore_hyp_resource
> is related to this.

Right, I didn't realize how that exactly worked until I had to go read
the code just now. It's a neat little trick. I'm wondering can we use 
PACA_THREAD_IDLE_STATE==PNV_THREAD_WINKLE for this instead? It would just
make the early PACA usage in the exception handlers able to use more common
code.

Thanks,
Nick


Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Shreyas B. Prabhu
On Thu, Nov 3, 2016 at 1:21 AM, Nicholas Piggin  wrote:
> On Wed, 2 Nov 2016 14:15:48 +0530
> Gautham R Shenoy  wrote:
>
>> Hi Nick,
>>
>> On Wed, Nov 02, 2016 at 07:36:24PM +1100, Nicholas Piggin wrote:
>> >
>> > Okay, I'll work with that. What's the best way to make a P8 do
>> > winkle sleeps?
>>
>> From the userspace, offlining the CPUs of the core will put them to
>> winkle.
>
> Thanks for this. Hum, that r13 manipulation throughout the idle
> and exception code is a bit interesting. I'll do the minimal patch
> for 4.9, but what's the reason not to just use the winkle state
> in the PACA rather than storing it into HSPRG0 bit, can you (or
> Shreyas) explain?
>
Hi Nick,

Before deep winkle, checking SRR1's wakeup bits (Bits 46:47) was enough to
figure out which idle state we are waking up from. But in P8, SRR1's wakeup
bits aren't enough since bits 46:47 are 0b11 for both fast sleep and
deep winkle.
So to distinguish bw fastsleep and deep winkle, we use the current HSPRG0/PORE
trick. We program the PORE engine (which is used for state restore when waking
up from deep winkle) to restore HSPRG0 with the last bit set (we do this in
pnv_save_sprs_for_winkle()). R13 bit manipulation in pnv_restore_hyp_resource
is related to this.

Thanks,
Shreyas


[PATCH v2] powerpc: EX_TABLE macro for exception tables

2016-11-02 Thread Michael Ellerman
From: Nicholas Piggin 

This macro is taken from s390, and allows more flexibility in
changing exception table format.

mpe: Put it in ppc_asm.h and only define one version using stringinfy_in_c().
Add some empty definitions and headers to keep the selftests happy.
Add some missing .previouses in fsl_rio.c and tsi108_pci.c.

Signed-off-by: Nicholas Piggin 
Signed-off-by: Michael Ellerman 
---
 arch/powerpc/include/asm/futex.h   |  14 +-
 arch/powerpc/include/asm/io.h  |  19 +-
 arch/powerpc/include/asm/ppc_asm.h |  10 +
 arch/powerpc/include/asm/uaccess.h |  25 +-
 arch/powerpc/include/asm/word-at-a-time.h  |   6 +-
 arch/powerpc/lib/checksum_32.S |  47 ++--
 arch/powerpc/lib/checksum_64.S |  20 +-
 arch/powerpc/lib/copy_32.S |  55 ++---
 arch/powerpc/lib/copyuser_64.S | 271 ++---
 arch/powerpc/lib/copyuser_power7.S |  20 +-
 arch/powerpc/lib/ldstfp.S  |  24 +-
 arch/powerpc/lib/sstep.c   |  15 +-
 arch/powerpc/lib/string.S  |  11 +-
 arch/powerpc/lib/string_64.S   |  16 +-
 arch/powerpc/sysdev/fsl_rio.c  |   6 +-
 arch/powerpc/sysdev/tsi108_pci.c   |   6 +-
 .../selftests/powerpc/copyloops/asm/ppc_asm.h  |   2 +
 .../selftests/powerpc/primitives/asm/firmware.h|   0
 .../selftests/powerpc/primitives/asm/ppc_asm.h |   1 +
 .../selftests/powerpc/primitives/asm/processor.h   |   0
 .../selftests/powerpc/primitives/linux/stringify.h |   0
 21 files changed, 241 insertions(+), 327 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/primitives/asm/firmware.h
 create mode 12 tools/testing/selftests/powerpc/primitives/asm/ppc_asm.h
 create mode 100644 tools/testing/selftests/powerpc/primitives/asm/processor.h
 create mode 100644 tools/testing/selftests/powerpc/primitives/linux/stringify.h

diff --git a/arch/powerpc/include/asm/futex.h b/arch/powerpc/include/asm/futex.h
index 2a9cf845473b..eaada6c92344 100644
--- a/arch/powerpc/include/asm/futex.h
+++ b/arch/powerpc/include/asm/futex.h
@@ -23,10 +23,8 @@
 "4:li  %1,%3\n" \
"b  3b\n" \
".previous\n" \
-   ".section __ex_table,\"a\"\n" \
-   ".align 3\n" \
-   PPC_LONG "1b,4b,2b,4b\n" \
-   ".previous" \
+   EX_TABLE(1b, 4b) \
+   EX_TABLE(2b, 4b) \
: "=&r" (oldval), "=&r" (ret) \
: "b" (uaddr), "i" (-EFAULT), "r" (oparg) \
: "cr0", "memory")
@@ -104,11 +102,9 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 "3:.section .fixup,\"ax\"\n\
 4: li  %0,%6\n\
b   3b\n\
-   .previous\n\
-   .section __ex_table,\"a\"\n\
-   .align 3\n\
-   " PPC_LONG "1b,4b,2b,4b\n\
-   .previous" \
+   .previous\n"
+   EX_TABLE(1b, 4b)
+   EX_TABLE(2b, 4b)
 : "+r" (ret), "=&r" (prev), "+m" (*uaddr)
 : "r" (uaddr), "r" (oldval), "r" (newval), "i" (-EFAULT)
 : "cc", "memory");
diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index f6fda8482f60..5ed292431b5b 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -33,6 +33,7 @@ extern struct pci_dev *isa_bridge_pcidev;
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -458,13 +459,10 @@ static inline unsigned int name(unsigned int port)
\
"5: li  %0,-1\n"\
"   b   4b\n"   \
".previous\n"   \
-   ".section __ex_table,\"a\"\n"   \
-   "   .align  2\n"\
-   "   .long   0b,5b\n"\
-   "   .long   1b,5b\n"\
-   "   .long   2b,5b\n"\
-   "   .long   3b,5b\n"\
-   ".previous" \
+   EX_TABLE(0b, 5b)\
+   EX_TABLE(1b, 5b)\
+   EX_TABLE(2b, 5b)\
+   EX_TABLE(3b, 5b)\
: "=&r" (x) \
: "r" (port + _IO_BASE) \
: "memory");\
@@ -479,11 +477,8 @@ static inline void name(unsigned int val, unsigned int 
port) \
"0:" op " %0,0,%1\n"\
"1: sync\n" \
"2:\n"  \
-   ".section __ex_table,\"a\"\n"   \
-   "   .align  2\n"\
-   "   .long   0b,2b\n"\
-   "   .long   1

Re: [PATCH 1/3] powerpc: Emulation support for load/store instructions on LE

2016-11-02 Thread Ravi Bangoria


On Thursday 03 November 2016 02:34 AM, Anton Blanchard wrote:
> Hi Ravi,
>
>> emulate_step() uses a number of underlying kernel functions that were
>> initially not enabled for LE. This has been rectified since. So, fix
>> emulate_step() for LE for the corresponding instructions.
> Thanks. Should this be queued up for stable?

Thanks Anton. Yes, this should go in stable.

-Ravi



[PATCH 1/4] powerpc/64: Make exception table clearer in __copy_tofrom_user_base

2016-11-02 Thread Paul Mackerras
This aims to make the generation of exception table entries for the
loads and stores in __copy_tofrom_user_base clearer and easier to
verify.  Instead of having a series of local labels on the loads
and stores, with a series of corresponding labels later for the
exception handlers, we now use macros to generate exception table
entries at the point of each load and store that could potentially
trap.  We do this with the macros extable, lex (load exception),
and stex (store exception).  These macros are used right before
the load or store to which they apply.

Some complexity is introduced by the fact that we have some more work
to do after hitting an exception.  After an exception on a load, we
need to clear the rest of the destination buffer (if possible), and
then return the number of bytes not copied.  After an exception on a
store, we only need to return the number of bytes not copied.  In
either case, the fixup code uses r3 as the current pointer into the
destination buffer, that is, the address of the first byte of the
destination that has not been modified.  However, at various points
in the copy loops, r3 can be 4, 8, 16 or 24 bytes behind that point.

To express this offset in an understandable way, we define a symbol
r3_offset which is updated at various points so that it equal to the
difference between the address of the first unmodified byte of the
destination and the value at r3.  (In fact it only needs to be
accurate at the point of each lex or stex macro invocation.)

The rules for updating r3_offset are as follows:

* It starts out at 0
* An addi r3,r3,N instruction decreases r3_offset by N
* A store instruction (stb, sth, stw, std) to N(r3)
  increases r3_offset by the width of the store (1, 2, 4, 8)
* A store with update instruction (stbu, sthu, stwu, stdu) to N(r3)
  sets r3_offset to the width of the store.

There is some trickiness to the way that the lex and stex macros and
the associated exception handlers work.  I would have liked to use
the current value of r3_offset in the name of the symbol used as
the exception handler, as in "extable .Lld_exc_$(r3_offset)" and then
have symbols .Lld_exc_0, .Lld_exc_8, .Lld_exc_16 etc. corresponding
to the offsets that needed to be added to r3.  However, I couldn't
see a way to do that with gas.

Instead, the exception handler address is .Lld_exc - r3_offset or
.Lst_exc - r3_offset, that is, the distance ahead of .Lld_exc/.Lst_exc
that we start executing is equal to the amount that we need to add to
r3.  This works because r3_offset is always a small multiple of 4,
and our instructions are 4 bytes long.  This means that before
.Lld_exc and .Lst_exc, we have a sequence of instructions that
increments r3 by 4, 8, 16 or 24 depending on where we start.  The
sequence increments r3 by 4 per instruction (on average).

We also replace the exception table for the 4k copy loop by a
macro per load or store.  These loads and stores all use exactly
the same exception handler, which simply resets the argument registers
r3, r4 and r5 to there original values and re-does the whole copy
using the slower loop.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/lib/copyuser_64.S | 579 +
 1 file changed, 239 insertions(+), 340 deletions(-)

diff --git a/arch/powerpc/lib/copyuser_64.S b/arch/powerpc/lib/copyuser_64.S
index 60386b2..1c5247c 100644
--- a/arch/powerpc/lib/copyuser_64.S
+++ b/arch/powerpc/lib/copyuser_64.S
@@ -18,6 +18,36 @@
 #define sHd sld/* Shift towards high-numbered address. */
 #endif
 
+/*
+ * These macros are used to generate exception table entries.
+ * The exception handlers below use the original arguments
+ * (stored on the stack) and the point where we're up to in
+ * the destination buffer, i.e. the address of the first
+ * unmodified byte.  Generally r3 points into the destination
+ * buffer, but the first unmodified byte is at a variable
+ * offset from r3.  In the code below, the symbol r3_offset
+ * is set to indicate the current offset at each point in
+ * the code.  This offset is then used as a negative offset
+ * from the exception handler code, and those instructions
+ * before the exception handlers are addi instructions that
+ * adjust r3 to point to the correct place.
+ */
+   .macro  extable handler
+100:
+   .section __ex_table,"a"
+   .align 3
+   .llong 100b,\handler
+   .previous
+   .endm
+
+   .macro  lex /* exception handler for load */
+   extable .Lld_exc - r3_offset
+   .endm
+
+   .macro  stex/* exception handler for store */
+   extable .Lst_exc - r3_offset
+   .endm
+
.align  7
 _GLOBAL_TOC(__copy_tofrom_user)
 BEGIN_FTR_SECTION
@@ -26,7 +56,7 @@ FTR_SECTION_ELSE
b   __copy_tofrom_user_power7
 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_VMX_COPY)
 _GLOBAL(__copy_tofrom_user_base)
-   /* first check for a whole page copy on a page boundary */
+   /* first check for a 4kB co

[PATCH 4/4] powerpc/64: Copy as much as possible in __copy_tofrom_user

2016-11-02 Thread Paul Mackerras
In __copy_tofrom_user, if we encounter an exception on a store, we
stop copying and return the number of bytes not copied.  However,
if the store is wider than one byte and is to an unaligned address,
it is possible that the store operand overlaps a page boundary
and the exception occurred on the latter part of the store operand,
meaning that it would be possible to copy a few more bytes.  Since
copy_to_user is generally expected to copy as much as possible,
it would be better to copy those extra few bytes.  This adds code
to do that.  Since this edge case is not performance-critical,
the code has been written to be compact rather than as fast as
possible.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/lib/copyuser_64.S | 29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/lib/copyuser_64.S b/arch/powerpc/lib/copyuser_64.S
index 668d816..c479256 100644
--- a/arch/powerpc/lib/copyuser_64.S
+++ b/arch/powerpc/lib/copyuser_64.S
@@ -409,8 +409,8 @@ stex;   stb r0,0(r3)
 99:blr
 
 /*
- * exception handlers for stores: we just need to work
- * out how many bytes weren't copied
+ * exception handlers for stores: we need to work out how many bytes
+ * weren't copied, and we may need to copy some more.
  * Note that the number of bytes of instructions for adjusting r3 needs
  * to equal the amount of the adjustment, due to the trick of using
  * .Lst_exc - r3_offset as the handler address.
@@ -430,10 +430,27 @@ stex; stb r0,0(r3)
/* adjust by 4 */
addir3,r3,4
 .Lst_exc:
-   ld  r6,-24(r1)
-   ld  r5,-8(r1)
-   add r6,r6,r5
-   subfr3,r3,r6/* #bytes not copied in r3 */
+   ld  r6,-24(r1)  /* original destination pointer */
+   ld  r4,-16(r1)  /* original source pointer */
+   ld  r5,-8(r1)   /* original number of bytes */
+   add r7,r6,r5
+   /*
+* If the destination pointer isn't 8-byte aligned,
+* we may have got the exception as a result of a
+* store that overlapped a page boundary, so we may be
+* able to copy a few more bytes.
+*/
+17:andi.   r0,r3,7
+   beq 19f
+   subfr8,r6,r3/* #bytes copied */
+   extable 19f
+   lbzxr0,r8,r4
+   extable 19f
+   stb r0,0(r3)
+   addir3,r3,1
+   cmpld   r3,r7
+   blt 17b
+19:subfr3,r3,r7/* #bytes not copied in r3 */
blr
 
 /*
-- 
2.10.1



[PATCH 3/4] selftests/powerpc/64: Test exception cases in copy_tofrom_user

2016-11-02 Thread Paul Mackerras
From: Michael Ellerman 

This adds a set of test cases to test the behaviour of
copy_tofrom_user when exceptions are encountered accessing the
source or destination.  Currently, copy_tofrom_user does not always
copy as many bytes as possible when an exception occurs on a store
to the destination, and that is reflected in failures in these tests.

Based on a test program from Anton Blanchard.

[pau...@ozlabs.org - test all three paths, wrote commit description]

Signed-off-by: Paul Mackerras 
---
 tools/testing/selftests/powerpc/copyloops/Makefile |  11 +-
 .../selftests/powerpc/copyloops/asm/ppc_asm.h  |  22 +---
 .../powerpc/copyloops/copy_tofrom_user_reference.S |  24 +
 .../selftests/powerpc/copyloops/exc_validate.c | 117 +
 tools/testing/selftests/powerpc/copyloops/stubs.S  |  19 
 5 files changed, 173 insertions(+), 20 deletions(-)
 create mode 100644 
tools/testing/selftests/powerpc/copyloops/copy_tofrom_user_reference.S
 create mode 100644 tools/testing/selftests/powerpc/copyloops/exc_validate.c
 create mode 100644 tools/testing/selftests/powerpc/copyloops/stubs.S

diff --git a/tools/testing/selftests/powerpc/copyloops/Makefile 
b/tools/testing/selftests/powerpc/copyloops/Makefile
index 1b351c3..feb7bf1 100644
--- a/tools/testing/selftests/powerpc/copyloops/Makefile
+++ b/tools/testing/selftests/powerpc/copyloops/Makefile
@@ -10,9 +10,10 @@ ASFLAGS = $(CFLAGS)
 TEST_PROGS :=  copyuser_64_t0 copyuser_64_t1 copyuser_64_t2 \
copyuser_p7_t0 copyuser_p7_t1 \
memcpy_64_t0 memcpy_64_t1 memcpy_64_t2 \
-   memcpy_p7_t0 memcpy_p7_t1
+   memcpy_p7_t0 memcpy_p7_t1 \
+   copyuser_64_exc_t0 copyuser_64_exc_t1 copyuser_64_exc_t2
 
-EXTRA_SOURCES := validate.c ../harness.c
+EXTRA_SOURCES := validate.c ../harness.c stubs.S
 
 all: $(TEST_PROGS)
 
@@ -37,6 +38,12 @@ memcpy_p7_t%:memcpy_power7.S $(EXTRA_SOURCES)
-D COPY_LOOP=test_memcpy_power7 \
-D SELFTEST_CASE=$(subst memcpy_p7_t,,$@) -o $@ $^
 
+copyuser_64_exc_t%: copyuser_64.S exc_validate.c ../harness.c \
+   copy_tofrom_user_reference.S stubs.S
+   $(CC) $(CPPFLAGS) $(CFLAGS) \
+   -D COPY_LOOP=test___copy_tofrom_user_base \
+   -D SELFTEST_CASE=$(subst copyuser_64_exc_t,,$@) -o $@ $^
+
 include ../../lib.mk
 
 clean:
diff --git a/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h 
b/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
index 7eb0cd6..03f10f1 100644
--- a/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
+++ b/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
@@ -1,3 +1,5 @@
+#ifndef __SELFTESTS_POWERPC_PPC_ASM_H
+#define __SELFTESTS_POWERPC_PPC_ASM_H
 #include 
 
 #define CONFIG_ALTIVEC
@@ -25,24 +27,6 @@
 
 #define PPC_MTOCRF(A, B)   mtocrf A, B
 
-FUNC_START(enter_vmx_usercopy)
-   li  r3,1
-   blr
-
-FUNC_START(exit_vmx_usercopy)
-   li  r3,0
-   blr
-
-FUNC_START(enter_vmx_copy)
-   li  r3,1
-   blr
-
-FUNC_START(exit_vmx_copy)
-   blr
-
-FUNC_START(__copy_tofrom_user_base)
-   blr
-
 #define BEGIN_FTR_SECTION  .if test_feature
 #define FTR_SECTION_ELSE   .else
 #define ALT_FTR_SECTION_END_IFCLR(x)   .endif
@@ -53,3 +37,5 @@ FUNC_START(__copy_tofrom_user_base)
 
 /* Default to taking the first of any alternative feature sections */
 test_feature = 1
+
+#endif /* __SELFTESTS_POWERPC_PPC_ASM_H */
diff --git 
a/tools/testing/selftests/powerpc/copyloops/copy_tofrom_user_reference.S 
b/tools/testing/selftests/powerpc/copyloops/copy_tofrom_user_reference.S
new file mode 100644
index 000..3363b86
--- /dev/null
+++ b/tools/testing/selftests/powerpc/copyloops/copy_tofrom_user_reference.S
@@ -0,0 +1,24 @@
+#include 
+
+_GLOBAL(copy_tofrom_user_reference)
+   cmpdi   r5,0
+   beq 4f
+
+   mtctr   r5
+
+1: lbz r6,0(r4)
+2: stb r6,0(r3)
+   addir3,r3,1
+   addir4,r4,1
+   bdnz1b
+
+3: mfctr   r3
+   blr
+
+4: mr  r3,r5
+   blr
+
+.section __ex_table,"a"
+   .llong  1b,3b
+   .llong  2b,3b
+.text
diff --git a/tools/testing/selftests/powerpc/copyloops/exc_validate.c 
b/tools/testing/selftests/powerpc/copyloops/exc_validate.c
new file mode 100644
index 000..72e7830
--- /dev/null
+++ b/tools/testing/selftests/powerpc/copyloops/exc_validate.c
@@ -0,0 +1,117 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern char __start___ex_table[];
+extern char __stop___ex_table[];
+
+#if defined(__powerpc64__)
+#define UCONTEXT_NIA(UC)   (UC)->uc_mcontext.gp_regs[PT_NIP]
+#elif defined(__powerpc__)
+#define UCONTEXT_NIA(UC)   (UC)->uc_mcontext.uc_regs->gregs[PT_NIP]
+#else
+#error implement UCONTEXT_NIA
+#endif
+
+static void segv_handler(int signr, siginfo_t *info, void *ptr)
+{
+   ucontext_t *uc = (ucontext_t *)ptr;
+   unsigned long addr = (unsigned long)info->si_

[PATCH 2/4] selftests/powerpc/64: Test all paths through copy routines

2016-11-02 Thread Paul Mackerras
The hand-coded assembler 64-bit copy routines include feature sections
that select one code path or another depending on which CPU we are
executing on.  The self-tests for these copy routines end up testing
just one path.  This adds a mechanism for selecting any desired code
path at compile time, and makes 2 or 3 versions of each test, each
using a different code path, so as to cover all the possible paths.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/lib/copyuser_64.S |  7 +
 arch/powerpc/lib/copyuser_power7.S | 21 ---
 arch/powerpc/lib/memcpy_64.S   |  9 +--
 arch/powerpc/lib/memcpy_power7.S   | 22 
 tools/testing/selftests/powerpc/copyloops/Makefile | 30 +-
 .../selftests/powerpc/copyloops/asm/ppc_asm.h  | 21 ---
 6 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/arch/powerpc/lib/copyuser_64.S b/arch/powerpc/lib/copyuser_64.S
index 1c5247c..668d816 100644
--- a/arch/powerpc/lib/copyuser_64.S
+++ b/arch/powerpc/lib/copyuser_64.S
@@ -10,6 +10,11 @@
 #include 
 #include 
 
+#ifndef SELFTEST_CASE
+/* 0 == most CPUs, 1 == POWER6, 2 == Cell */
+#define SELFTEST_CASE  0
+#endif
+
 #ifdef __BIG_ENDIAN__
 #define sLd sld/* Shift towards low-numbered address. */
 #define sHd srd/* Shift towards high-numbered address. */
@@ -77,6 +82,7 @@ _GLOBAL(__copy_tofrom_user_base)
  * At the time of writing the only CPU that has this combination of bits
  * set is Power6.
  */
+test_feature = (SELFTEST_CASE == 1)
 BEGIN_FTR_SECTION
nop
 FTR_SECTION_ELSE
@@ -86,6 +92,7 @@ ALT_FTR_SECTION_END(CPU_FTR_UNALIGNED_LD_STD | 
CPU_FTR_CP_USE_DCBTZ, \
 .Ldst_aligned:
addir3,r3,-16
 r3_offset = 16
+test_feature = (SELFTEST_CASE == 0)
 BEGIN_FTR_SECTION
andi.   r0,r4,7
bne .Lsrc_unaligned
diff --git a/arch/powerpc/lib/copyuser_power7.S 
b/arch/powerpc/lib/copyuser_power7.S
index da0c568..b2f7211 100644
--- a/arch/powerpc/lib/copyuser_power7.S
+++ b/arch/powerpc/lib/copyuser_power7.S
@@ -19,6 +19,11 @@
  */
 #include 
 
+#ifndef SELFTEST_CASE
+/* 0 == don't use VMX, 1 == use VMX */
+#define SELFTEST_CASE  0
+#endif
+
 #ifdef __BIG_ENDIAN__
 #define LVS(VRT,RA,RB) lvslVRT,RA,RB
 #define VPERM(VRT,VRA,VRB,VRC) vperm   VRT,VRA,VRB,VRC
@@ -92,7 +97,6 @@
 
 
 _GLOBAL(__copy_tofrom_user_power7)
-#ifdef CONFIG_ALTIVEC
cmpldi  r5,16
cmpldi  cr1,r5,4096
 
@@ -101,16 +105,11 @@ _GLOBAL(__copy_tofrom_user_power7)
std r5,-STACKFRAMESIZE+STK_REG(R29)(r1)
 
blt .Lshort_copy
-   bgt cr1,.Lvmx_copy
-#else
-   cmpldi  r5,16
 
-   std r3,-STACKFRAMESIZE+STK_REG(R31)(r1)
-   std r4,-STACKFRAMESIZE+STK_REG(R30)(r1)
-   std r5,-STACKFRAMESIZE+STK_REG(R29)(r1)
-
-   blt .Lshort_copy
-#endif
+test_feature = SELFTEST_CASE
+BEGIN_FTR_SECTION
+   bgt cr1,.Lvmx_copy
+END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC_COMP)
 
 .Lnonvmx_copy:
/* Get the source 8B aligned */
@@ -290,8 +289,8 @@ err1;   stb r0,0(r3)
addir1,r1,STACKFRAMESIZE
b   .Lnonvmx_copy
 
-#ifdef CONFIG_ALTIVEC
 .Lvmx_copy:
+#ifdef CONFIG_ALTIVEC
mflrr0
std r0,16(r1)
stdur1,-STACKFRAMESIZE(r1)
diff --git a/arch/powerpc/lib/memcpy_64.S b/arch/powerpc/lib/memcpy_64.S
index f4d6088..ea363ad 100644
--- a/arch/powerpc/lib/memcpy_64.S
+++ b/arch/powerpc/lib/memcpy_64.S
@@ -10,6 +10,11 @@
 #include 
 #include 
 
+#ifndef SELFTEST_CASE
+/* For big-endian, 0 == most CPUs, 1 == POWER6, 2 == Cell */
+#define SELFTEST_CASE  0
+#endif
+
.align  7
 _GLOBAL_TOC(memcpy)
 BEGIN_FTR_SECTION
@@ -19,9 +24,7 @@ BEGIN_FTR_SECTION
std r3,-STACKFRAMESIZE+STK_REG(R31)(r1) /* save destination 
pointer for return value */
 #endif
 FTR_SECTION_ELSE
-#ifndef SELFTEST
b   memcpy_power7
-#endif
 ALT_FTR_SECTION_END_IFCLR(CPU_FTR_VMX_COPY)
 #ifdef __LITTLE_ENDIAN__
/* dumb little-endian memcpy that will get replaced at runtime */
@@ -45,6 +48,7 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_VMX_COPY)
cleared.
At the time of writing the only CPU that has this combination of bits
set is Power6. */
+test_feature = (SELFTEST_CASE == 1)
 BEGIN_FTR_SECTION
nop
 FTR_SECTION_ELSE
@@ -53,6 +57,7 @@ ALT_FTR_SECTION_END(CPU_FTR_UNALIGNED_LD_STD | 
CPU_FTR_CP_USE_DCBTZ, \
 CPU_FTR_UNALIGNED_LD_STD)
 .Ldst_aligned:
addir3,r3,-16
+test_feature = (SELFTEST_CASE == 0)
 BEGIN_FTR_SECTION
andi.   r0,r4,7
bne .Lsrc_unaligned
diff --git a/arch/powerpc/lib/memcpy_power7.S b/arch/powerpc/lib/memcpy_power7.S
index 786234f..c4f4e3b 100644
--- a/arch/powerpc/lib/memcpy_power7.S
+++ b/arch/powerpc/lib/memcpy_power7.S
@@ -19,7 +19,10 @@
  */
 #include 
 
-_GLOBAL(memcpy_power7)
+#ifndef SELFTEST_CASE
+/* 0 == don't use VMX, 1 == use VMX */
+#define SELFT

Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Nicholas Piggin
On Wed, 2 Nov 2016 14:15:48 +0530
Gautham R Shenoy  wrote:

> Hi Nick,
> 
> On Wed, Nov 02, 2016 at 07:36:24PM +1100, Nicholas Piggin wrote:
> > 
> > Okay, I'll work with that. What's the best way to make a P8 do
> > winkle sleeps?  
> 
> From the userspace, offlining the CPUs of the core will put them to
> winkle.

Thanks for this. Hum, that r13 manipulation throughout the idle
and exception code is a bit interesting. I'll do the minimal patch
for 4.9, but what's the reason not to just use the winkle state
in the PACA rather than storing it into HSPRG0 bit, can you (or
Shreyas) explain?

Thanks,
Nick


[PATCH 2/2] powerpc/64: Use optimized checksum routines on little-endian

2016-11-02 Thread Paul Mackerras
Currently we have optimized hand-coded assembly checksum routines
for big-endian 64-bit systems, but for little-endian we use the
generic C routines.  This modifies the optimized routines to work
for little-endian.  With this, we no longer need to enable
CONFIG_GENERIC_CSUM.  This also fixes a couple of comments
in checksum_64.S so they accurately reflect what the associated
instruction does.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/Kconfig|  2 +-
 arch/powerpc/include/asm/checksum.h |  4 
 arch/powerpc/lib/Makefile   |  2 --
 arch/powerpc/lib/checksum_64.S  | 12 ++--
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 65fba4c..514e6dd 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -164,7 +164,7 @@ config PPC
select HAVE_KERNEL_GZIP
 
 config GENERIC_CSUM
-   def_bool CPU_LITTLE_ENDIAN
+   def_bool n
 
 config EARLY_PRINTK
bool
diff --git a/arch/powerpc/include/asm/checksum.h 
b/arch/powerpc/include/asm/checksum.h
index c16c6f8..5f8297b 100644
--- a/arch/powerpc/include/asm/checksum.h
+++ b/arch/powerpc/include/asm/checksum.h
@@ -72,7 +72,11 @@ static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 
daddr,
 
s += (__force u32)saddr;
s += (__force u32)daddr;
+#ifdef __BIG_ENDIAN
s += proto + len;
+#else
+   s += (proto + len) << 8;
+#endif
return (__force __wsum) from64to32(s);
 #else
 __asm__("\n\
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 309361e8..0e649d7 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -21,9 +21,7 @@ obj64-y   += copypage_64.o copyuser_64.o usercopy_64.o 
mem_64.o hweight_64.o \
 obj64-$(CONFIG_SMP)+= locks.o
 obj64-$(CONFIG_ALTIVEC)+= vmx-helper.o
 
-ifeq ($(CONFIG_GENERIC_CSUM),)
 obj-y  += checksum_$(BITS).o checksum_wrappers.o
-endif
 
 obj-$(CONFIG_PPC_EMULATE_SSTEP)+= sstep.o ldstfp.o
 
diff --git a/arch/powerpc/lib/checksum_64.S b/arch/powerpc/lib/checksum_64.S
index fd91766..4dd2761 100644
--- a/arch/powerpc/lib/checksum_64.S
+++ b/arch/powerpc/lib/checksum_64.S
@@ -36,7 +36,7 @@ _GLOBAL(__csum_partial)
 * work to calculate the correct checksum, we ignore that case
 * and take the potential slowdown of unaligned loads.
 */
-   rldicl. r6,r3,64-1,64-2 /* r6 = (r3 & 0x3) >> 1 */
+   rldicl. r6,r3,64-1,64-2 /* r6 = (r3 >> 1) & 0x3 */
beq .Lcsum_aligned
 
li  r7,4
@@ -168,8 +168,12 @@ _GLOBAL(__csum_partial)
beq .Lcsum_finish
 
lbz r6,0(r3)
+#ifdef __BIG_ENDIAN
sldir9,r6,8 /* Pad the byte out to 16 bits */
adder0,r0,r9
+#else
+   adder0,r0,r6
+#endif
 
 .Lcsum_finish:
addze   r0,r0   /* add in final carry */
@@ -236,7 +240,7 @@ _GLOBAL(csum_partial_copy_generic)
 * If the source and destination are relatively unaligned we only
 * align the source. This keeps things simple.
 */
-   rldicl. r6,r3,64-1,64-2 /* r6 = (r3 & 0x3) >> 1 */
+   rldicl. r6,r3,64-1,64-2 /* r6 = (r3 >> 1) & 0x3 */
beq .Lcopy_aligned
 
li  r9,4
@@ -398,8 +402,12 @@ dstnr; sth r6,0(r4)
beq .Lcopy_finish
 
 srcnr; lbz r6,0(r3)
+#ifdef __BIG_ENDIAN
sldir9,r6,8 /* Pad the byte out to 16 bits */
adder0,r0,r9
+#else
+   adder0,r0,r6
+#endif
 dstnr; stb r6,0(r4)
 
 .Lcopy_finish:
-- 
2.10.1



[PATCH 1/2] powerpc/64: Fix checksum folding in csum_tcpudp_nofold and ip_fast_csum_nofold

2016-11-02 Thread Paul Mackerras
These functions compute an IP checksum by computing a 64-bit sum and
folding it to 32 bits (the "nofold" in their names refers to folding
down to 16 bits).  However, doing (u32) (s + (s >> 32)) is not
sufficient to fold a 64-bit sum to 32 bits correctly.  The addition
can produce a carry out from bit 31, which needs to be added in to
the sum to produce the correct result.

To fix this, we copy the from64to32() function from lib/checksum.c
and use that.

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

diff --git a/arch/powerpc/include/asm/checksum.h 
b/arch/powerpc/include/asm/checksum.h
index ee655ed..c16c6f8 100644
--- a/arch/powerpc/include/asm/checksum.h
+++ b/arch/powerpc/include/asm/checksum.h
@@ -53,19 +53,27 @@ static inline __sum16 csum_fold(__wsum sum)
return (__force __sum16)(~((__force u32)sum + tmp) >> 16);
 }
 
+static inline u32 from64to32(u64 x)
+{
+   /* add up 32-bit and 32-bit for 32+c bit */
+   x = (x & 0x) + (x >> 32);
+   /* add up carry.. */
+   x = (x & 0x) + (x >> 32);
+   return (u32)x;
+}
+
 static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
  unsigned short len,
  unsigned short proto,
  __wsum sum)
 {
 #ifdef __powerpc64__
-   unsigned long s = (__force u32)sum;
+   u64 s = (__force u32)sum;
 
s += (__force u32)saddr;
s += (__force u32)daddr;
s += proto + len;
-   s += (s >> 32);
-   return (__force __wsum) s;
+   return (__force __wsum) from64to32(s);
 #else
 __asm__("\n\
addc %0,%0,%1 \n\
@@ -127,8 +135,7 @@ static inline __wsum ip_fast_csum_nofold(const void *iph, 
unsigned int ihl)
 
for (i = 0; i < ihl - 1; i++, ptr++)
s += *ptr;
-   s += (s >> 32);
-   return (__force __wsum)s;
+   return (__force __wsum)from64to32(s);
 #else
__wsum sum, tmp;
 
-- 
2.10.1



Re: compiling master.

2016-11-02 Thread Nicholas Piggin
On Wed, 2 Nov 2016 13:49:39 +0300
Denis Kirjanov  wrote:

> Hi guys,
> 
> compiling ppc head with bunch of asm errors on power8 box (gcc version 4.8.3 )
> checked commit log but found nothing special. Looks like it's asm issue?
> Has anybody seen that?
> 
> arch/powerpc/kernel/exceptions-64s.S: Assembler messages:
> arch/powerpc/kernel/exceptions-64s.S:421: Error: operand out of range
> (0x8680 is not between 0x and
> 0x)

Hey, thanks for the report. It's likely due to the exception vectors rewrite,
and yes it's an assembler issue (what's your binutils version?). Your errors
look like they're coming from LOAD_HANDLER(). For some reason it seems to be
interpreting the immediate as signed, or the actual calculation ends up being
negative, neither of which should happen.

It might take a bit of trial and error, and the assembler doesn't give a lot
of good options to debug it, so if I can reproduce it here with your bintuils
version it will be helpful.

Thanks,
Nick


[PATCH 2/2] selftests/powerpc: Fail load_unaligned_zeropad on miscompare

2016-11-02 Thread Michael Ellerman
If the result returned by load_unaligned_zeropad() doesn't match what we
expect we should fail the test!

Signed-off-by: Michael Ellerman 
---
 tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c 
b/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
index cf7a4a114a90..cd7af4e1b65a 100644
--- a/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
+++ b/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
@@ -118,8 +118,10 @@ static int do_one_test(char *p, int page_offset)
 
got = load_unaligned_zeropad(p);
 
-   if (should != got)
+   if (should != got) {
printf("offset %u load_unaligned_zeropad returned 0x%lx, should 
be 0x%lx\n", page_offset, got, should);
+   return 1;
+   }
 
return 0;
 }
-- 
2.7.4



[PATCH 1/2] selftests/powerpc: Abort load_unaligned_zeropad on unhandled SEGV

2016-11-02 Thread Michael Ellerman
If the load unaligned zeropad test takes a SEGV which can't be handled,
we increment segv_error, print the offending NIP and then return without
taking any further action. In almost all cases this means we'll just
take the SEGV again, and loop eternally spamming the console.

Instead just abort(), it's a fatal error in the test. The test harness
will notice that the child died and print a nice message for us.

Signed-off-by: Michael Ellerman 
---
 tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git 
a/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c 
b/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
index 6cae06117b55..cf7a4a114a90 100644
--- a/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
+++ b/tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c
@@ -73,7 +73,6 @@ extern char __stop___ex_table[];
 #error implement UCONTEXT_NIA
 #endif
 
-static int segv_error;
 
 static void segv_handler(int signr, siginfo_t *info, void *ptr)
 {
@@ -95,7 +94,7 @@ static void segv_handler(int signr, siginfo_t *info, void 
*ptr)
}
 
printf("No exception table match for NIA %lx ADDR %lx\n", *ip, addr);
-   segv_error++;
+   abort();
 }
 
 static void setup_segv_handler(void)
@@ -145,8 +144,6 @@ static int test_body(void)
for (i = 0; i < page_size; i++)
FAIL_IF(do_one_test(mem_region+i, i));
 
-   FAIL_IF(segv_error);
-
return 0;
 }
 
-- 
2.7.4



[PATCH] powerpc/module: Add support for R_PPC64_REL32 relocations

2016-11-02 Thread Michael Ellerman
We haven't seen these before, but the soon to be merged relative
exception tables support causes them to be generated.

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/module_64.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 183368e008cf..bb1807184bad 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -652,6 +652,11 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
*location = value - (unsigned long)location;
break;
 
+   case R_PPC64_REL32:
+   /* 32 bits relative (used by relative exception tables) 
*/
+   *(u32 *)location = value - (unsigned long)location;
+   break;
+
case R_PPC64_TOCSAVE:
/*
 * Marker reloc indicates we don't have to save r2.
-- 
2.7.4



Re: [PATCH] Fix loading of module radeonfb on PowerMac

2016-11-02 Thread Benjamin Herrenschmidt
On Wed, 2016-11-02 at 11:28 +0100, Mathieu Malaterre wrote:
> 
> This has been working great so far for `radeon.ko`, so I assumed I
> could shamelessly copy the behavior over to `radeonfb.ko`.
> 
> The original reference I found was from Benjamin Herrenschmidt here:
> https://lists.freedesktop.org/archives/dri-devel/2010-August/002907.h
> tml
> 
> I am of course willing to try something else, but I would need some
> guidance.

I missed your original patch but yes, the basic idea is that we kick
out offb when the "real" driver loads.

Cheers,
Ben.



Re: [PATCH] powerpc/configs: Turn on PPC crypto implementations in the server defconfigs

2016-11-02 Thread Nicholas Piggin
On Wed,  2 Nov 2016 21:06:17 +1100
Michael Ellerman  wrote:

> These are the PPC optimised versions of various crypto algorithms, so we
> should turn them on by default to get test coverage.

Looks good, thanks for that.



Re: [PATCH 1/4] cputime/powerpc: remove cputime_last_delta global variable

2016-11-02 Thread Paul Mackerras
On Mon, Oct 31, 2016 at 01:36:26PM +0100, Stanislaw Gruszka wrote:
> Since commit:
> 
> cf9efce0ce313 ("powerpc: Account time using timebase rather than PURR")
> 
> cputime_last_delta is not initialized to other value than 0, hence it's
> not used except zero check and cputime_to_scaled() just returns
> the argument.
> 
> Signed-off-by: Stanislaw Gruszka 

Yes, I should have removed them in that commit.  We don't want to do
any scaling in the places where cputime_to_scaled() is used.

Acked-by: Paul Mackerras 


Re: [PATCH 2/4] cputime/powerpc: remove cputime_to_scaled()

2016-11-02 Thread Paul Mackerras
On Mon, Oct 31, 2016 at 01:36:27PM +0100, Stanislaw Gruszka wrote:
> Currently cputime_to_scaled() just return it's argument on
> all implementations, we don't need to call this function.
> 
> Signed-off-by: Stanislaw Gruszka 

Looks OK to me.

Reviewed-by: Paul Mackerras 


Re: [PATCH kernel v4 4/4] powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown

2016-11-02 Thread Paul Mackerras
On Wed, Nov 02, 2016 at 01:44:03PM +1100, Alexey Kardashevskiy wrote:
> On 31/10/16 15:23, David Gibson wrote:
[...]
> > 
> > Um.. yeah.. that's not really ok.  Prohibiting overlapping
> > registrations on the same container is reasonable enough.  Having a
> > container not be able to register memory because some completely
> > different container has registered something overlapping is getting
> > very ugly.
> 
> I am lost here. Does this mean the patches cannot go upstream?
> 
> Also how would I implement overlapping if we are not teaching KVM about
> VFIO containers? The mm list has a counter of how many times each memory
> region was mapped via TCE (and this prevents unregistration), and if we
> want overlapping regions - a "mapped" counter of which one would I update
> in real mode (where I only have a user address and a LIOBN)?

The patches fix a real bug, where we run out of memory to run VMs.

The patches don't change the interface, and don't introduce the
constraint that is being discussed here (that the regions being
registered may not overlap unless they are identical to a previously
registered region).  That constraint is already present in the
upstream code.

They do change the behaviour when you use a container fd from a
different process from the one which opened the fd, but that is not
something that worked in any meaningful way before anyway.

So David, do you still see any reason why the patches should not be
accepted?

Regards,
Paul.


Re: [PATCH net-next] ibmveth: v1 calculate correct gso_size and set gso_type

2016-11-02 Thread Brian King
On 10/27/2016 10:26 AM, Eric Dumazet wrote:
> On Wed, 2016-10-26 at 11:09 +1100, Jon Maxwell wrote:
>> We recently encountered a bug where a few customers using ibmveth on the 
>> same LPAR hit an issue where a TCP session hung when large receive was
>> enabled. Closer analysis revealed that the session was stuck because the 
>> one side was advertising a zero window repeatedly.
>>
>> We narrowed this down to the fact the ibmveth driver did not set gso_size 
>> which is translated by TCP into the MSS later up the stack. The MSS is 
>> used to calculate the TCP window size and as that was abnormally large, 
>> it was calculating a zero window, even although the sockets receive buffer 
>> was completely empty. 
>>
>> We were able to reproduce this and worked with IBM to fix this. Thanks Tom 
>> and Marcelo for all your help and review on this.
>>
>> The patch fixes both our internal reproduction tests and our customers tests.
>>
>> Signed-off-by: Jon Maxwell 
>> ---
>>  drivers/net/ethernet/ibm/ibmveth.c | 20 
>>  1 file changed, 20 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/ibm/ibmveth.c 
>> b/drivers/net/ethernet/ibm/ibmveth.c
>> index 29c05d0..c51717e 100644
>> --- a/drivers/net/ethernet/ibm/ibmveth.c
>> +++ b/drivers/net/ethernet/ibm/ibmveth.c
>> @@ -1182,6 +1182,8 @@ static int ibmveth_poll(struct napi_struct *napi, int 
>> budget)
>>  int frames_processed = 0;
>>  unsigned long lpar_rc;
>>  struct iphdr *iph;
>> +bool large_packet = 0;
>> +u16 hdr_len = ETH_HLEN + sizeof(struct tcphdr);
>>  
>>  restart_poll:
>>  while (frames_processed < budget) {
>> @@ -1236,10 +1238,28 @@ static int ibmveth_poll(struct napi_struct *napi, 
>> int budget)
>>  iph->check = 0;
>>  iph->check = 
>> ip_fast_csum((unsigned char *)iph, iph->ihl);
>>  adapter->rx_large_packets++;
>> +large_packet = 1;
>>  }
>>  }
>>  }
>>  
>> +if (skb->len > netdev->mtu) {
>> +iph = (struct iphdr *)skb->data;
>> +if (be16_to_cpu(skb->protocol) == ETH_P_IP &&
>> +iph->protocol == IPPROTO_TCP) {
>> +hdr_len += sizeof(struct iphdr);
>> +skb_shinfo(skb)->gso_type = 
>> SKB_GSO_TCPV4;
>> +skb_shinfo(skb)->gso_size = netdev->mtu 
>> - hdr_len;
>> +} else if (be16_to_cpu(skb->protocol) == 
>> ETH_P_IPV6 &&
>> +   iph->protocol == IPPROTO_TCP) {
>> +hdr_len += sizeof(struct ipv6hdr);
>> +skb_shinfo(skb)->gso_type = 
>> SKB_GSO_TCPV6;
>> +skb_shinfo(skb)->gso_size = netdev->mtu 
>> - hdr_len;
>> +}
>> +if (!large_packet)
>> +adapter->rx_large_packets++;
>> +}
>> +
>>  
> 
> This might break forwarding and PMTU discovery.
> 
> You force gso_size to device mtu, regardless of real MSS used by the TCP
> sender.
> 
> Don't you have the MSS provided in RX descriptor, instead of guessing
> the value ?

We've had some further discussions on this with the Virtual I/O Server (VIOS)
development team. The large receive aggregation in the VIOS (AIX based) is 
actually
being done by software in the VIOS. What they may be able to do is when 
performing
this aggregation, they could look at the packet lengths of all the packets being
aggregated and take the largest packet size within the aggregation unit, minus 
the
header length and return that to the virtual ethernet client which we could 
then stuff
into gso_size. They are currently assessing how feasible this would be to do 
and whether
it would impact other bits of the code. However, assuming this does end up 
being an option,
would this address the concerns here or is that going to break something else 
I'm
not thinking of?

Unfortunately, I don't think we'd have a good way to get gso_segs set correctly 
as I don't
see how that would get passed back up the interface.

Thanks,

Brian


-- 
Brian King
Power Linux I/O
IBM Linux Technology Center



Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

2016-11-02 Thread Martin Schwidefsky
On Wed, 2 Nov 2016 10:38:20 +0100
Stanislaw Gruszka  wrote:

> On Wed, Nov 02, 2016 at 10:11:22AM +0100, Christian Borntraeger wrote:
> > On 10/31/2016 01:36 PM, Stanislaw Gruszka wrote:
> > > Only s390 and powerpc have hardware facilities allowing to measure
> > > cputimes scaled by frequency. On all other architectures
> > > utimescaled/stimescaled are equal to utime/stime (however they are
> > > accounted separately).
> > > 
> > > Patch remove {u,s}timescaled accounting on all architectures except
> > > powerpc and s390, where those values are explicitly accounted on proper
> > > places.
> > 
> > If we remove it everywhere else (and assuming that there are no users then)
> > I aks myself if we should remove this as well from s390.
> 
> There is one user of scaled cputimes values, it is taskstats (to users
> space are exported ac_utimescaled, ac_stimescaled and
> cpu_scaled_run_real_total which is calculated based on scaled times).
> However on other than powerpc and s390 architectures scaled times are
> equal to normal times (this is also true for older powerpc's without
> SPURR/PURR registers).

The taskstats interface is the only user of the scaled cputime that
I am aware of. It is hard to say how valuable the information is.
Without the scaled number in the taskstats inferface you have no means
to detect if your workload has been affected by a another SMT thread
running on the same core.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.



Re: [PATCH 1/3] powerpc: Emulation support for load/store instructions on LE

2016-11-02 Thread Anton Blanchard
Hi Ravi,

> emulate_step() uses a number of underlying kernel functions that were
> initially not enabled for LE. This has been rectified since. So, fix
> emulate_step() for LE for the corresponding instructions.

Thanks. Should this be queued up for stable?

Anton

> Reported-by: Anton Blanchard 
> Signed-off-by: Ravi Bangoria 
> ---
>  arch/powerpc/lib/sstep.c | 20 
>  1 file changed, 20 deletions(-)
> 
> diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
> index 3362299..6ca3b90 100644
> --- a/arch/powerpc/lib/sstep.c
> +++ b/arch/powerpc/lib/sstep.c
> @@ -1807,8 +1807,6 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) goto instr_done;
>  
>   case LARX:
> - if (regs->msr & MSR_LE)
> - return 0;
>   if (op.ea & (size - 1))
>   break;  /* can't handle
> misaligned */ err = -EFAULT;
> @@ -1832,8 +1830,6 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) goto ldst_done;
>  
>   case STCX:
> - if (regs->msr & MSR_LE)
> - return 0;
>   if (op.ea & (size - 1))
>   break;  /* can't handle
> misaligned */ err = -EFAULT;
> @@ -1859,8 +1855,6 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) goto ldst_done;
>  
>   case LOAD:
> - if (regs->msr & MSR_LE)
> - return 0;
>   err = read_mem(®s->gpr[op.reg], op.ea, size,
> regs); if (!err) {
>   if (op.type & SIGNEXT)
> @@ -1872,8 +1866,6 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) 
>  #ifdef CONFIG_PPC_FPU
>   case LOAD_FP:
> - if (regs->msr & MSR_LE)
> - return 0;
>   if (size == 4)
>   err = do_fp_load(op.reg, do_lfs, op.ea,
> size, regs); else
> @@ -1882,15 +1874,11 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) #endif
>  #ifdef CONFIG_ALTIVEC
>   case LOAD_VMX:
> - if (regs->msr & MSR_LE)
> - return 0;
>   err = do_vec_load(op.reg, do_lvx, op.ea & ~0xfUL,
> regs); goto ldst_done;
>  #endif
>  #ifdef CONFIG_VSX
>   case LOAD_VSX:
> - if (regs->msr & MSR_LE)
> - return 0;
>   err = do_vsx_load(op.reg, do_lxvd2x, op.ea, regs);
>   goto ldst_done;
>  #endif
> @@ -1913,8 +1901,6 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) goto instr_done;
>  
>   case STORE:
> - if (regs->msr & MSR_LE)
> - return 0;
>   if ((op.type & UPDATE) && size == sizeof(long) &&
>   op.reg == 1 && op.update_reg == 1 &&
>   !(regs->msr & MSR_PR) &&
> @@ -1927,8 +1913,6 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) 
>  #ifdef CONFIG_PPC_FPU
>   case STORE_FP:
> - if (regs->msr & MSR_LE)
> - return 0;
>   if (size == 4)
>   err = do_fp_store(op.reg, do_stfs, op.ea,
> size, regs); else
> @@ -1937,15 +1921,11 @@ int __kprobes emulate_step(struct pt_regs
> *regs, unsigned int instr) #endif
>  #ifdef CONFIG_ALTIVEC
>   case STORE_VMX:
> - if (regs->msr & MSR_LE)
> - return 0;
>   err = do_vec_store(op.reg, do_stvx, op.ea & ~0xfUL,
> regs); goto ldst_done;
>  #endif
>  #ifdef CONFIG_VSX
>   case STORE_VSX:
> - if (regs->msr & MSR_LE)
> - return 0;
>   err = do_vsx_store(op.reg, do_stxvd2x, op.ea, regs);
>   goto ldst_done;
>  #endif



[PATCH net-next v6 09/10] arch/powerpc: Enable FSL_FMAN

2016-11-02 Thread Madalin Bucur
Signed-off-by: Madalin Bucur 
---
 arch/powerpc/configs/dpaa.config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/configs/dpaa.config b/arch/powerpc/configs/dpaa.config
index f124ee1..9ad9bc0 100644
--- a/arch/powerpc/configs/dpaa.config
+++ b/arch/powerpc/configs/dpaa.config
@@ -1,2 +1,3 @@
 CONFIG_FSL_DPAA=y
 CONFIG_FSL_PAMU=y
+CONFIG_FSL_FMAN=y
-- 
2.1.0



[PATCH net-next v6 10/10] arch/powerpc: Enable dpaa_eth

2016-11-02 Thread Madalin Bucur
Signed-off-by: Madalin Bucur 
---
 arch/powerpc/configs/dpaa.config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/configs/dpaa.config b/arch/powerpc/configs/dpaa.config
index 9ad9bc0..2fe76f5 100644
--- a/arch/powerpc/configs/dpaa.config
+++ b/arch/powerpc/configs/dpaa.config
@@ -1,3 +1,4 @@
 CONFIG_FSL_DPAA=y
 CONFIG_FSL_PAMU=y
 CONFIG_FSL_FMAN=y
+CONFIG_FSL_DPAA_ETH=y
-- 
2.1.0



[PATCH net-next v6 08/10] arch/powerpc: Enable FSL_PAMU

2016-11-02 Thread Madalin Bucur
Signed-off-by: Madalin Bucur 
---
 arch/powerpc/configs/dpaa.config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/configs/dpaa.config b/arch/powerpc/configs/dpaa.config
index efa99c0..f124ee1 100644
--- a/arch/powerpc/configs/dpaa.config
+++ b/arch/powerpc/configs/dpaa.config
@@ -1 +1,2 @@
 CONFIG_FSL_DPAA=y
+CONFIG_FSL_PAMU=y
-- 
2.1.0



[PATCH net-next v6 07/10] dpaa_eth: add trace points

2016-11-02 Thread Madalin Bucur
Add trace points on the hot processing path.

Signed-off-by: Ruxandra Ioana Radulescu 
---
 drivers/net/ethernet/freescale/dpaa/Makefile   |   1 +
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |  15 +++
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.h |   1 +
 .../net/ethernet/freescale/dpaa/dpaa_eth_trace.h   | 141 +
 4 files changed, 158 insertions(+)
 create mode 100644 drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h

diff --git a/drivers/net/ethernet/freescale/dpaa/Makefile 
b/drivers/net/ethernet/freescale/dpaa/Makefile
index bfb03d4..7db50bc 100644
--- a/drivers/net/ethernet/freescale/dpaa/Makefile
+++ b/drivers/net/ethernet/freescale/dpaa/Makefile
@@ -9,3 +9,4 @@ ccflags-y += -I$(FMAN)
 obj-$(CONFIG_FSL_DPAA_ETH) += fsl_dpa.o
 
 fsl_dpa-objs += dpaa_eth.o dpaa_ethtool.o dpaa_eth_sysfs.o
+CFLAGS_dpaa_eth.o := -I$(src)
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 045b23b..9d240b7 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -59,6 +59,12 @@
 #include "mac.h"
 #include "dpaa_eth.h"
 
+/* CREATE_TRACE_POINTS only needs to be defined once. Other dpaa files
+ * using trace events only need to #include 
+ */
+#define CREATE_TRACE_POINTS
+#include "dpaa_eth_trace.h"
+
 static int debug = -1;
 module_param(debug, int, S_IRUGO);
 MODULE_PARM_DESC(debug, "Module/Driver verbosity level (0=none,...,16=all)");
@@ -1918,6 +1924,9 @@ static inline int dpaa_xmit(struct dpaa_priv *priv,
if (fd->bpid == FSL_DPAA_BPID_INV)
fd->cmd |= qman_fq_fqid(priv->conf_fqs[queue]);
 
+   /* Trace this Tx fd */
+   trace_dpaa_tx_fd(priv->net_dev, egress_fq, fd);
+
for (i = 0; i < DPAA_ENQUEUE_RETRIES; i++) {
err = qman_enqueue(egress_fq, fd);
if (err != -EBUSY)
@@ -2152,6 +2161,9 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct 
qman_portal *portal,
if (!dpaa_bp)
return qman_cb_dqrr_consume;
 
+   /* Trace the Rx fd */
+   trace_dpaa_rx_fd(net_dev, fq, &dq->fd);
+
percpu_priv = this_cpu_ptr(priv->percpu_priv);
percpu_stats = &percpu_priv->stats;
 
@@ -2248,6 +2260,9 @@ static enum qman_cb_dqrr_result conf_dflt_dqrr(struct 
qman_portal *portal,
net_dev = ((struct dpaa_fq *)fq)->net_dev;
priv = netdev_priv(net_dev);
 
+   /* Trace the fd */
+   trace_dpaa_tx_conf_fd(net_dev, fq, &dq->fd);
+
percpu_priv = this_cpu_ptr(priv->percpu_priv);
 
if (dpaa_eth_napi_schedule(percpu_priv, portal))
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
index 44323e2..1f9aebf 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
@@ -37,6 +37,7 @@
 
 #include "fman.h"
 #include "mac.h"
+#include "dpaa_eth_trace.h"
 
 #define DPAA_ETH_TXQ_NUM   NR_CPUS
 
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h
new file mode 100644
index 000..409c1dc
--- /dev/null
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_trace.h
@@ -0,0 +1,141 @@
+/* Copyright 2013-2015 Freescale Semiconductor Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ * * Neither the name of Freescale Semiconductor nor the
+ *  names of its contributors may be used to endorse or promote products
+ *  derived from this software without specific prior written permission.
+ *
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) A

[PATCH net-next v6 06/10] dpaa_eth: add sysfs exports

2016-11-02 Thread Madalin Bucur
Export Frame Queue and Buffer Pool IDs through sysfs.

Signed-off-by: Madalin Bucur 
---
 drivers/net/ethernet/freescale/dpaa/Makefile   |   2 +-
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |   4 +
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.h |   4 +
 .../net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c   | 165 +
 4 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c

diff --git a/drivers/net/ethernet/freescale/dpaa/Makefile 
b/drivers/net/ethernet/freescale/dpaa/Makefile
index 43a4cfd..bfb03d4 100644
--- a/drivers/net/ethernet/freescale/dpaa/Makefile
+++ b/drivers/net/ethernet/freescale/dpaa/Makefile
@@ -8,4 +8,4 @@ ccflags-y += -I$(FMAN)
 
 obj-$(CONFIG_FSL_DPAA_ETH) += fsl_dpa.o
 
-fsl_dpa-objs += dpaa_eth.o dpaa_ethtool.o
+fsl_dpa-objs += dpaa_eth.o dpaa_ethtool.o dpaa_eth_sysfs.o
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 3deb240..045b23b 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -2692,6 +2692,8 @@ static int dpaa_eth_probe(struct platform_device *pdev)
if (err < 0)
goto netdev_init_failed;
 
+   dpaa_eth_sysfs_init(&net_dev->dev);
+
netif_info(priv, probe, net_dev, "Probed interface %s\n",
   net_dev->name);
 
@@ -2737,6 +2739,8 @@ static int dpaa_remove(struct platform_device *pdev)
 
priv = netdev_priv(net_dev);
 
+   dpaa_eth_sysfs_remove(dev);
+
dev_set_drvdata(dev, NULL);
unregister_netdev(net_dev);
 
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
index 711fb06..44323e2 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
@@ -177,4 +177,8 @@ struct dpaa_priv {
 
 /* from dpaa_ethtool.c */
 extern const struct ethtool_ops dpaa_ethtool_ops;
+
+/* from dpaa_eth_sysfs.c */
+void dpaa_eth_sysfs_remove(struct device *dev);
+void dpaa_eth_sysfs_init(struct device *dev);
 #endif /* __DPAA_H */
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c
new file mode 100644
index 000..93f0251
--- /dev/null
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c
@@ -0,0 +1,165 @@
+/* Copyright 2008-2016 Freescale Semiconductor Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ * * Neither the name of Freescale Semiconductor nor the
+ *  names of its contributors may be used to endorse or promote products
+ *  derived from this software without specific prior written permission.
+ *
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include "dpaa_eth.h"
+#include "mac.h"
+
+static ssize_t dpaa_eth_show_addr(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+   struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
+   struct mac_device *mac_dev = priv->mac_dev;
+
+   if (mac_dev)
+   return sprintf(buf, "%llx",
+   (unsigned long long)mac_dev->res->start);
+   else
+   return sprintf(buf, "none");
+}
+
+static ssize_t dpaa_eth_show_fqids(struct device *dev,
+  struct device_attribute *attr, char *buf)
+{
+   struct dpaa_priv *priv = netdev_priv(to_net_de

[PATCH net-next v6 05/10] dpaa_eth: add ethtool statistics

2016-11-02 Thread Madalin Bucur
Add a series of counters to be exported through ethtool:
- add detailed counters for reception errors;
- add detailed counters for QMan enqueue reject events;
- count the number of fragmented skbs received from the stack;
- count all frames received on the Tx confirmation path;
- add congestion group statistics;
- count the number of interrupts for each CPU.

Signed-off-by: Ioana Ciornei 
Signed-off-by: Madalin Bucur 
---
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |  54 +-
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.h |  33 
 drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c | 199 +
 3 files changed, 284 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 681abf1..3deb240 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -755,10 +755,15 @@ static void dpaa_eth_cgscn(struct qman_portal *qm, struct 
qman_cgr *cgr,
struct dpaa_priv *priv = (struct dpaa_priv *)container_of(cgr,
struct dpaa_priv, cgr_data.cgr);
 
-   if (congested)
+   if (congested) {
+   priv->cgr_data.congestion_start_jiffies = jiffies;
netif_tx_stop_all_queues(priv->net_dev);
-   else
+   priv->cgr_data.cgr_congested_count++;
+   } else {
+   priv->cgr_data.congested_jiffies +=
+   (jiffies - priv->cgr_data.congestion_start_jiffies);
netif_tx_wake_all_queues(priv->net_dev);
+   }
 }
 
 static int dpaa_eth_cgr_init(struct dpaa_priv *priv)
@@ -1273,6 +1278,37 @@ static void dpaa_fd_release(const struct net_device 
*net_dev,
dpaa_bman_release(dpaa_bp, &bmb, 1);
 }
 
+static void count_ern(struct dpaa_percpu_priv *percpu_priv,
+ const union qm_mr_entry *msg)
+{
+   switch (msg->ern.rc & QM_MR_RC_MASK) {
+   case QM_MR_RC_CGR_TAILDROP:
+   percpu_priv->ern_cnt.cg_tdrop++;
+   break;
+   case QM_MR_RC_WRED:
+   percpu_priv->ern_cnt.wred++;
+   break;
+   case QM_MR_RC_ERROR:
+   percpu_priv->ern_cnt.err_cond++;
+   break;
+   case QM_MR_RC_ORPWINDOW_EARLY:
+   percpu_priv->ern_cnt.early_window++;
+   break;
+   case QM_MR_RC_ORPWINDOW_LATE:
+   percpu_priv->ern_cnt.late_window++;
+   break;
+   case QM_MR_RC_FQ_TAILDROP:
+   percpu_priv->ern_cnt.fq_tdrop++;
+   break;
+   case QM_MR_RC_ORPWINDOW_RETIRED:
+   percpu_priv->ern_cnt.fq_retired++;
+   break;
+   case QM_MR_RC_ORP_ZERO:
+   percpu_priv->ern_cnt.orp_zero++;
+   break;
+   }
+}
+
 /* Turn on HW checksum computation for this outgoing frame.
  * If the current protocol is not something we support in this regard
  * (or if the stack has already computed the SW checksum), we do nothing.
@@ -1937,6 +1973,7 @@ static int dpaa_start_xmit(struct sk_buff *skb, struct 
net_device *net_dev)
likely(skb_shinfo(skb)->nr_frags < DPAA_SGT_MAX_ENTRIES)) {
/* Just create a S/G fd based on the skb */
err = skb_to_sg_fd(priv, skb, &fd);
+   percpu_priv->tx_frag_skbuffs++;
} else {
/* If the egress skb contains more fragments than we support
 * we have no choice but to linearize it ourselves.
@@ -1973,6 +2010,15 @@ static void dpaa_rx_error(struct net_device *net_dev,
 
percpu_priv->stats.rx_errors++;
 
+   if (fd->status & FM_FD_ERR_DMA)
+   percpu_priv->rx_errors.dme++;
+   if (fd->status & FM_FD_ERR_PHYSICAL)
+   percpu_priv->rx_errors.fpe++;
+   if (fd->status & FM_FD_ERR_SIZE)
+   percpu_priv->rx_errors.fse++;
+   if (fd->status & FM_FD_ERR_PRS_HDR_ERR)
+   percpu_priv->rx_errors.phe++;
+
dpaa_fd_release(net_dev, fd);
 }
 
@@ -2028,6 +2074,8 @@ static void dpaa_tx_conf(struct net_device *net_dev,
percpu_priv->stats.tx_errors++;
}
 
+   percpu_priv->tx_confirm++;
+
skb = dpaa_cleanup_tx_fd(priv, fd);
 
consume_skb(skb);
@@ -2042,6 +2090,7 @@ static inline int dpaa_eth_napi_schedule(struct 
dpaa_percpu_priv *percpu_priv,
 
percpu_priv->np.p = portal;
napi_schedule(&percpu_priv->np.napi);
+   percpu_priv->in_interrupt++;
return 1;
}
return 0;
@@ -2225,6 +2274,7 @@ static void egress_ern(struct qman_portal *portal,
 
percpu_priv->stats.tx_dropped++;
percpu_priv->stats.tx_fifo_errors++;
+   count_ern(percpu_priv, msg);
 
skb = dpaa_cleanup_tx_fd(priv, fd);
dev_kfree_skb_any(skb);
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
index d6a

[PATCH net-next v6 04/10] dpaa_eth: add ethtool functionality

2016-11-02 Thread Madalin Bucur
Add support for basic ethtool operations.

Signed-off-by: Madalin Bucur 
---
 drivers/net/ethernet/freescale/dpaa/Makefile   |   2 +-
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c |   2 +
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.h |   3 +
 drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c | 218 +
 4 files changed, 224 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c

diff --git a/drivers/net/ethernet/freescale/dpaa/Makefile 
b/drivers/net/ethernet/freescale/dpaa/Makefile
index fc76029..43a4cfd 100644
--- a/drivers/net/ethernet/freescale/dpaa/Makefile
+++ b/drivers/net/ethernet/freescale/dpaa/Makefile
@@ -8,4 +8,4 @@ ccflags-y += -I$(FMAN)
 
 obj-$(CONFIG_FSL_DPAA_ETH) += fsl_dpa.o
 
-fsl_dpa-objs += dpaa_eth.o
+fsl_dpa-objs += dpaa_eth.o dpaa_ethtool.o
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 5e8c3df..681abf1 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -242,6 +242,8 @@ static int dpaa_netdev_init(struct net_device *net_dev,
memcpy(net_dev->perm_addr, mac_addr, net_dev->addr_len);
memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len);
 
+   net_dev->ethtool_ops = &dpaa_ethtool_ops;
+
net_dev->needed_headroom = priv->tx_headroom;
net_dev->watchdog_timeo = msecs_to_jiffies(tx_timeout);
 
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
index fe98e08..d6ab335 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
@@ -141,4 +141,7 @@ struct dpaa_priv {
struct dpaa_buffer_layout buf_layout[2];
u16 rx_headroom;
 };
+
+/* from dpaa_ethtool.c */
+extern const struct ethtool_ops dpaa_ethtool_ops;
 #endif /* __DPAA_H */
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
new file mode 100644
index 000..f97f563
--- /dev/null
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
@@ -0,0 +1,218 @@
+/* Copyright 2008-2016 Freescale Semiconductor, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ * * Neither the name of Freescale Semiconductor nor the
+ *  names of its contributors may be used to endorse or promote products
+ *  derived from this software without specific prior written permission.
+ *
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+
+#include "dpaa_eth.h"
+#include "mac.h"
+
+static int dpaa_get_settings(struct net_device *net_dev,
+struct ethtool_cmd *et_cmd)
+{
+   int err;
+
+   if (!net_dev->phydev) {
+   netdev_dbg(net_dev, "phy device not initialized\n");
+   return 0;
+   }
+
+   err = phy_ethtool_gset(net_dev->phydev, et_cmd);
+
+   return err;
+}
+
+static int dpaa_set_settings(struct net_device *net_dev,
+struct ethtool_cmd *et_cmd)
+{
+   int err;
+
+   if (!net_dev->phydev) {
+   netdev_err(net_dev, "phy device not initialized\n");
+   return -ENODEV;
+   }
+
+   err = phy_ethtool_sset(net_dev->phydev, et_cmd);
+   if (err < 0)
+   netdev_err(net_dev, "phy_ethtool_sset() = %d\n", err);
+
+   return err;
+}
+
+static void dpaa_get_drvinfo(struct net_device *

[PATCH net-next v6 03/10] dpaa_eth: add option to use one buffer pool set

2016-11-02 Thread Madalin Bucur
Signed-off-by: Madalin Bucur 
---
 drivers/net/ethernet/freescale/dpaa/Kconfig|  6 ++
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 23 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/net/ethernet/freescale/dpaa/Kconfig 
b/drivers/net/ethernet/freescale/dpaa/Kconfig
index 670e039..308fc21 100644
--- a/drivers/net/ethernet/freescale/dpaa/Kconfig
+++ b/drivers/net/ethernet/freescale/dpaa/Kconfig
@@ -18,4 +18,10 @@ config FSL_DPAA_ETH_FRIENDLY_IF_NAME
  The DPAA Ethernet netdevices are created for each FMan port available
  on a certain board. Enable this to get interface names derived from
  the underlying FMan hardware for a simple identification.
+config FSL_DPAA_ETH_COMMON_BPOOL
+   bool "Use a common buffer pool set for all the interfaces"
+   ---help---
+ The DPAA Ethernet netdevices require buffer pools for storing the 
buffers
+ used by the FMan hardware for reception. One can use a single buffer 
pool
+ set for all interfaces or a dedicated buffer pool set for each 
interface.
 endif # FSL_DPAA_ETH
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 55e89b7..5e8c3df 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -158,6 +158,11 @@ struct fm_port_fqs {
struct dpaa_fq *rx_errq;
 };
 
+#ifdef CONFIG_FSL_DPAA_ETH_COMMON_BPOOL
+/* These bpools are shared by all the dpaa interfaces */
+static u8 dpaa_common_bpids[DPAA_BPS_NUM];
+#endif
+
 /* All the dpa bps in use at any moment */
 static struct dpaa_bp *dpaa_bp_array[BM_MAX_NUM_OF_POOLS];
 
@@ -2527,6 +2532,12 @@ static int dpaa_eth_probe(struct platform_device *pdev)
for (i = 0; i < DPAA_BPS_NUM; i++) {
int err;
 
+#ifdef CONFIG_FSL_DPAA_ETH_COMMON_BPOOL
+   /* if another interface probed the bps reuse those */
+   dpaa_bps[i] = (dpaa_common_bpids[i] != FSL_DPAA_BPID_INV) ?
+   dpaa_bpid2pool(dpaa_common_bpids[i]) : NULL;
+   if (!dpaa_bps[i]) {
+#endif
dpaa_bps[i] = dpaa_bp_alloc(dev);
if (IS_ERR(dpaa_bps[i]))
return PTR_ERR(dpaa_bps[i]);
@@ -2542,6 +2553,11 @@ static int dpaa_eth_probe(struct platform_device *pdev)
priv->dpaa_bps[i] = NULL;
goto bp_create_failed;
}
+#ifdef CONFIG_FSL_DPAA_ETH_COMMON_BPOOL
+   }
+   dpaa_common_bpids[i] = dpaa_bps[i]->bpid;
+   dpaa_bps[i] = (dpaa_bpid2pool(dpaa_common_bpids[i]));
+#endif
priv->dpaa_bps[i] = dpaa_bps[i];
}
 
@@ -2716,6 +2732,13 @@ static int __init dpaa_load(void)
dpaa_rx_extra_headroom = fman_get_rx_extra_headroom();
dpaa_max_frm = fman_get_max_frm();
 
+#ifdef CONFIG_FSL_DPAA_ETH_COMMON_BPOOL
+   /* set initial invalid values, first interface probe will set correct
+* values that will be shared by the other interfaces
+*/
+   memset(dpaa_common_bpids, FSL_DPAA_BPID_INV, sizeof(dpaa_common_bpids));
+#endif
+
err = platform_driver_register(&dpaa_driver);
if (err < 0)
pr_err("Error, platform_driver_register() = %d\n", err);
-- 
2.1.0



[PATCH net-next v6 02/10] dpaa_eth: add support for DPAA Ethernet

2016-11-02 Thread Madalin Bucur
This introduces the Freescale Data Path Acceleration Architecture
(DPAA) Ethernet driver (dpaa_eth) that builds upon the DPAA QMan,
BMan, PAMU and FMan drivers to deliver Ethernet connectivity on
the Freescale DPAA QorIQ platforms.

Signed-off-by: Madalin Bucur 
---
 drivers/net/ethernet/freescale/Kconfig |2 +
 drivers/net/ethernet/freescale/Makefile|1 +
 drivers/net/ethernet/freescale/dpaa/Kconfig|   21 +
 drivers/net/ethernet/freescale/dpaa/Makefile   |   11 +
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 2739 
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.h |  144 ++
 6 files changed, 2918 insertions(+)
 create mode 100644 drivers/net/ethernet/freescale/dpaa/Kconfig
 create mode 100644 drivers/net/ethernet/freescale/dpaa/Makefile
 create mode 100644 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
 create mode 100644 drivers/net/ethernet/freescale/dpaa/dpaa_eth.h

diff --git a/drivers/net/ethernet/freescale/Kconfig 
b/drivers/net/ethernet/freescale/Kconfig
index d1ca45f..aa3f615 100644
--- a/drivers/net/ethernet/freescale/Kconfig
+++ b/drivers/net/ethernet/freescale/Kconfig
@@ -93,4 +93,6 @@ config GIANFAR
  and MPC86xx family of chips, the eTSEC on LS1021A and the FEC
  on the 8540.
 
+source "drivers/net/ethernet/freescale/dpaa/Kconfig"
+
 endif # NET_VENDOR_FREESCALE
diff --git a/drivers/net/ethernet/freescale/Makefile 
b/drivers/net/ethernet/freescale/Makefile
index cbe21dc..4a13115 100644
--- a/drivers/net/ethernet/freescale/Makefile
+++ b/drivers/net/ethernet/freescale/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o
 ucc_geth_driver-objs := ucc_geth.o ucc_geth_ethtool.o
 
 obj-$(CONFIG_FSL_FMAN) += fman/
+obj-$(CONFIG_FSL_DPAA_ETH) += dpaa/
diff --git a/drivers/net/ethernet/freescale/dpaa/Kconfig 
b/drivers/net/ethernet/freescale/dpaa/Kconfig
new file mode 100644
index 000..670e039
--- /dev/null
+++ b/drivers/net/ethernet/freescale/dpaa/Kconfig
@@ -0,0 +1,21 @@
+menuconfig FSL_DPAA_ETH
+   tristate "DPAA Ethernet"
+   depends on FSL_SOC && FSL_DPAA && FSL_FMAN
+   select PHYLIB
+   select FSL_FMAN_MAC
+   ---help---
+ Data Path Acceleration Architecture Ethernet driver,
+ supporting the Freescale QorIQ chips.
+ Depends on Freescale Buffer Manager and Queue Manager
+ driver and Frame Manager Driver.
+
+if FSL_DPAA_ETH
+
+config FSL_DPAA_ETH_FRIENDLY_IF_NAME
+   bool "Use fmX-macY names for the DPAA interfaces"
+   default y
+   ---help---
+ The DPAA Ethernet netdevices are created for each FMan port available
+ on a certain board. Enable this to get interface names derived from
+ the underlying FMan hardware for a simple identification.
+endif # FSL_DPAA_ETH
diff --git a/drivers/net/ethernet/freescale/dpaa/Makefile 
b/drivers/net/ethernet/freescale/dpaa/Makefile
new file mode 100644
index 000..fc76029
--- /dev/null
+++ b/drivers/net/ethernet/freescale/dpaa/Makefile
@@ -0,0 +1,11 @@
+#
+# Makefile for the Freescale DPAA Ethernet controllers
+#
+
+# Include FMan headers
+FMAN= $(srctree)/drivers/net/ethernet/freescale/fman
+ccflags-y += -I$(FMAN)
+
+obj-$(CONFIG_FSL_DPAA_ETH) += fsl_dpa.o
+
+fsl_dpa-objs += dpaa_eth.o
diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
new file mode 100644
index 000..55e89b7
--- /dev/null
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -0,0 +1,2739 @@
+/* Copyright 2008 - 2016 Freescale Semiconductor Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ * * Neither the name of Freescale Semiconductor nor the
+ *  names of its contributors may be used to endorse or promote products
+ *  derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT

[PATCH net-next v6 01/10] devres: add devm_alloc_percpu()

2016-11-02 Thread Madalin Bucur
Introduce managed counterparts for alloc_percpu() and free_percpu().
Add devm_alloc_percpu() and devm_free_percpu() into the managed
interfaces list.

Signed-off-by: Madalin Bucur 
---
 Documentation/driver-model/devres.txt |  4 +++
 drivers/base/devres.c | 66 +++
 include/linux/device.h| 19 ++
 3 files changed, 89 insertions(+)

diff --git a/Documentation/driver-model/devres.txt 
b/Documentation/driver-model/devres.txt
index 1670708..ca9d1eb 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -332,6 +332,10 @@ MEM
 MFD
  devm_mfd_add_devices()
 
+PER-CPU MEM
+  devm_alloc_percpu()
+  devm_free_percpu()
+
 PCI
   pcim_enable_device() : after success, all PCI ops become managed
   pcim_pin_device(): keep PCI device enabled after release
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 8fc654f..71d5770 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "base.h"
 
@@ -985,3 +986,68 @@ void devm_free_pages(struct device *dev, unsigned long 
addr)
   &devres));
 }
 EXPORT_SYMBOL_GPL(devm_free_pages);
+
+static void devm_percpu_release(struct device *dev, void *pdata)
+{
+   void __percpu *p;
+
+   p = *(void __percpu **)pdata;
+   free_percpu(p);
+}
+
+static int devm_percpu_match(struct device *dev, void *data, void *p)
+{
+   struct devres *devr = container_of(data, struct devres, data);
+
+   return *(void **)devr->data == p;
+}
+
+/**
+ * __devm_alloc_percpu - Resource-managed alloc_percpu
+ * @dev: Device to allocate per-cpu memory for
+ * @size: Size of per-cpu memory to allocate
+ * @align: Alignment of per-cpu memory to allocate
+ *
+ * Managed alloc_percpu. Per-cpu memory allocated with this function is
+ * automatically freed on driver detach.
+ *
+ * RETURNS:
+ * Pointer to allocated memory on success, NULL on failure.
+ */
+void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
+   size_t align)
+{
+   void *p;
+   void __percpu *pcpu;
+
+   pcpu = __alloc_percpu(size, align);
+   if (!pcpu)
+   return NULL;
+
+   p = devres_alloc(devm_percpu_release, sizeof(void *), GFP_KERNEL);
+   if (!p) {
+   free_percpu(pcpu);
+   return NULL;
+   }
+
+   *(void __percpu **)p = pcpu;
+
+   devres_add(dev, p);
+
+   return pcpu;
+}
+EXPORT_SYMBOL_GPL(__devm_alloc_percpu);
+
+/**
+ * devm_free_percpu - Resource-managed free_percpu
+ * @dev: Device this memory belongs to
+ * @pdata: Per-cpu memory to free
+ *
+ * Free memory allocated with devm_alloc_percpu().
+ */
+void devm_free_percpu(struct device *dev, void __percpu *pdata)
+{
+   WARN_ON(devres_destroy(dev, devm_percpu_release, devm_percpu_match,
+  (void *)pdata));
+}
+EXPORT_SYMBOL_GPL(devm_free_percpu);
diff --git a/include/linux/device.h b/include/linux/device.h
index bc41e87..043ffce 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -698,6 +698,25 @@ static inline int devm_add_action_or_reset(struct device 
*dev,
return ret;
 }
 
+/**
+ * devm_alloc_percpu - Resource-managed alloc_percpu
+ * @dev: Device to allocate per-cpu memory for
+ * @type: Type to allocate per-cpu memory for
+ *
+ * Managed alloc_percpu. Per-cpu memory allocated with this function is
+ * automatically freed on driver detach.
+ *
+ * RETURNS:
+ * Pointer to allocated memory on success, NULL on failure.
+ */
+#define devm_alloc_percpu(dev, type)  \
+   (typeof(type) __percpu *)__devm_alloc_percpu(dev, sizeof(type), \
+__alignof__(type))
+
+void __percpu *__devm_alloc_percpu(struct device *dev, size_t size,
+  size_t align);
+void devm_free_percpu(struct device *dev, void __percpu *pdata);
+
 struct device_dma_parameters {
/*
 * a low level driver may set these to teach IOMMU code about
-- 
2.1.0



[PATCH net-next v6 00/10] dpaa_eth: Add the QorIQ DPAA Ethernet driver

2016-11-02 Thread Madalin Bucur
This patch series adds the Ethernet driver for the Freescale
QorIQ Data Path Acceleration Architecture (DPAA).

This version includes changes following the feedback received
on previous versions from Eric Dumazet, Bob Cochran, Joe Perches,
Paul Bolle, Joakim Tjernlund, Scott Wood, David Miller - thank you.

Together with the driver a managed version of alloc_percpu
is provided that simplifies the release of per-CPU memory.

The Freescale DPAA architecture consists in a series of hardware
blocks that support the Ethernet connectivity. The Ethernet driver
depends upon the following drivers that are currently in the Linux
kernel:
 - Peripheral Access Memory Unit (PAMU)
drivers/iommu/fsl_*
 - Frame Manager (FMan) added in v4.4
drivers/net/ethernet/freescale/fman
 - Queue Manager (QMan), Buffer Manager (BMan) added in v4.9-rc1
drivers/soc/fsl/qbman

dpaa_eth interfaces mapping to FMan MACs:

  dpaa_eth   /eth0\ ...   /ethN\
  driver|  | |  |
  -      ---      -
   -Ports  / Tx  Rx \.../ Tx  Rx \
  FMan|  | |  |
   -MACs  |   MAC0   | |   MACN   |
 /   dtsec0   \  ...  /   dtsecN   \ (or tgec)
/  \ /  \(or memac)
  -  --  ---  --  -
  FMan, FMan Port, FMan SP, FMan MURAM drivers
  -
  FMan HW blocks: MURAM, MACs, Ports, SP
  -

dpaa_eth relation to QMan, FMan:
  
  dpaa_eth   /eth0\
  driver/  \
  -   -^-   -^-   -^-   ----
  QMan driver / \   / \   / \  \   /  | BMan|
 |Rx | |Rx | |Tx | |Tx |  | driver  |
  -  |Dfl| |Err| |Cnf| |FQs|  | |
  QMan HW|FQ | |FQ | |FQ | |   |  | |
 /   \ /   \ /   \  \ /   | |
  -   ---   ---   ---   -v--
|FMan QMI | |
| FMan HW   FMan BMI  | BMan HW |
  ---   

where the acronyms used above (and in the code) are:
DPAA = Data Path Acceleration Architecture
FMan = DPAA Frame Manager
QMan = DPAA Queue Manager
BMan = DPAA Buffers Manager
QMI = QMan interface in FMan
BMI = BMan interface in FMan
FMan SP = FMan Storage Profiles
MURAM = Multi-user RAM in FMan
FQ = QMan Frame Queue
Rx Dfl FQ = default reception FQ
Rx Err FQ = Rx error frames FQ
Tx Cnf FQ = Tx confirmation FQ
Tx FQs = transmission frame queues
dtsec = datapath three speed Ethernet controller (10/100/1000 Mbps)
tgec = ten gigabit Ethernet controller (10 Gbps)
memac = multirate Ethernet MAC (10/100/1000/1)

Changes from v5:
 - adapt to the latest Q/BMan drivers API
 - use build_skb() on Rx path instead of buffer pool refill path
 - proper support for multiple buffer pools
 - align function, variable names, code cleanup
 - driver file structure cleanup

Changes from v4:
 - addressed feedback from Scott Wood and Joe Perches
 - fixed spelling
 - fixed leak of uninitialized stack to userspace
 - fix prints
 - replace raw_cpu_ptr() with this_cpu_ptr()
 - remove _s from the end of structure names
 - remove underscores at start of functions, goto labels
 - remove likely in error paths
 - use container_of() instead of open casts
 - remove priv from the driver name
 - move return type on same line with function name
 - drop DPA_READ_SKB_PTR/DPA_WRITE_SKB_PTR

Changes from v3:
 - removed bogus delay and comment in .ndo_stop implementation
 - addressed minor issues reported by David Miller

Changes from v2:
 - removed debugfs, moved exports to ethtool statistics
 - removed congestion groups Kconfig params

Changes from v1:
 - bpool level Kconfig options removed
 - print format using pr_fmt, cleaned up prints
 - __hot/__cold removed
 - gratuitous unlikely() removed
 - code style aligned, consistent spacing for declarations
 - comment formatting

The changes are also available in the public git repository at
git://git.freescale.com/ppc/upstream/linux.git on the branch dpaa_eth-next.

Madalin Bucur (10):
  devres: add devm_alloc_percpu()
  dpaa_eth: add support for DPAA Ethernet
  dpaa_eth: add option to use one buffer pool set
  dpaa_eth: add ethtool functionality
  dpaa_eth: add ethtool statistics
  dpaa_eth: add sysfs exports
  dpaa_eth: add trace points
  arch/powerpc: Enable FSL_PAMU
  arch/powerpc: Enable FSL_FMAN
  arch/powerpc: Enable dpaa_eth

 Documentation/driver-model/devres.txt  |4 +
 arch/powerpc/configs/dpaa.config   |3 +
 drivers/base/devres.c  |   66 +
 drivers/net/ethernet/freescale/Kconfig |2 +
 drivers/net/ethernet/freescale/Makefile|1 +
 drivers/net/ethernet/freescale/d

Re: [PATCH] cxl: Fix error handling

2016-11-02 Thread Jim Davis
On Wed, Nov 2, 2016 at 4:12 AM, Michael Ellerman  wrote:
> Jim Davis  writes:
>
>> On Sun, Oct 30, 2016 at 10:37 PM, Michael Ellerman  
>> wrote:
>>> More here:
>>>
>>> https://github.com/linuxppc/linux/wiki/Building-powerpc-kernels
>>
>> Cool; the little-endian build worked fine, but
>
> Yay, thanks for trying.
>
>> jim@krebstar:~/linux-rc$ make ARCH=powerpc
>> CROSS_COMPILE=powerpc64-linux-gnu- vmlinux
>> make: powerpc64-linux-gnu-gcc: Command not found
>> make: powerpc64-linux-gnu-gcc: Command not found
>> scripts/kconfig/conf  --silentoldconfig Kconfig
>> make: powerpc64-linux-gnu-gcc: Command not found

But I cleverly tried to run the Fedora command on Ubuntu... when I run
the right command for Ubuntu, the build worked just fine.  D'oh!

Nit: make distclean missed a few files

jim@krebstar:~/linux-rc$ make distclean; git clean -fdx
  CLEAN   .
  CLEAN   drivers/tty/vt
  CLEAN   drivers/video/logo
  CLEAN   firmware
  CLEAN   kernel
  CLEAN   lib
  CLEAN   usr
  CLEAN   .tmp_versions
  CLEAN   scripts/basic
  CLEAN   scripts/dtc
  CLEAN   scripts/genksyms
  CLEAN   scripts/kconfig
  CLEAN   scripts/mod
  CLEAN   scripts
  CLEAN   include/config include/generated arch/powerpc/include/generated
  CLEAN   .config .version Module.symvers
Removing arch/powerpc/kernel/systbl_chk.i
Removing arch/powerpc/kernel/vdso32/vdso32.lds
Removing arch/powerpc/kernel/vdso32/vdso32.so
Removing arch/powerpc/kernel/vdso32/vdso32.so.dbg
Removing arch/powerpc/kernel/vdso64/vdso64.lds
Removing arch/powerpc/kernel/vdso64/vdso64.so
Removing arch/powerpc/kernel/vdso64/vdso64.so.dbg
Removing arch/powerpc/kernel/vmlinux.lds

-- 
Jim


[mm PATCH v2 18/26] arch/powerpc: Add option to skip DMA sync as a part of mapping

2016-11-02 Thread Alexander Duyck
This change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to
avoid invoking cache line invalidation if the driver will just handle it
via a sync_for_cpu or sync_for_device call.

Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Alexander Duyck 
---
 arch/powerpc/kernel/dma.c |9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index e64a601..6877e3f 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -203,6 +203,10 @@ static int dma_direct_map_sg(struct device *dev, struct 
scatterlist *sgl,
for_each_sg(sgl, sg, nents, i) {
sg->dma_address = sg_phys(sg) + get_dma_offset(dev);
sg->dma_length = sg->length;
+
+   if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
+   continue;
+
__dma_sync_page(sg_page(sg), sg->offset, sg->length, direction);
}
 
@@ -235,7 +239,10 @@ static inline dma_addr_t dma_direct_map_page(struct device 
*dev,
 unsigned long attrs)
 {
BUG_ON(dir == DMA_NONE);
-   __dma_sync_page(page, offset, size, dir);
+
+   if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
+   __dma_sync_page(page, offset, size, dir);
+
return page_to_phys(page) + offset + get_dma_offset(dev);
 }
 



Re: [PATCH] cxl: Fix memory allocation failure test

2016-11-02 Thread Frederic Barrat



Le 30/10/2016 à 20:35, Christophe JAILLET a écrit :

'cxl_context_alloc()' does not return an error pointer. It is just a
shortcut for a call to 'kzalloc' with 'sizeof(struct cxl_context)' as the
size parameter.

So its return value should be compared with NULL.
While fixing it, simplify a bit the code.

Signed-off-by: Christophe JAILLET 
---



Acked-by: Frederic Barrat 



Re: [PATCH] cxl: Fix error handling

2016-11-02 Thread Frederic Barrat



Le 30/10/2016 à 22:40, Christophe JAILLET a écrit :

'cxl_dev_context_init()' returns an error pointer in case of error, not
NULL. So test it with IS_ERR.

Signed-off-by: Christophe JAILLET 
---



Thanks for the 3 patches!

Acked-by: Frederic Barrat 



Re: [PATCH] cxl: Fix error handling

2016-11-02 Thread Frederic Barrat



Le 30/10/2016 à 22:34, Christophe JAILLET a écrit :

'cxl_dev_context_init()' returns an error pointer in case of error, not
NULL. So test it with IS_ERR.

Signed-off-by: Christophe JAILLET 



Acked-by: Frederic Barrat 



Re: [PATCH] Fix loading of module radeonfb on PowerMac

2016-11-02 Thread Lennart Sorensen
On Wed, Nov 02, 2016 at 10:28:55AM +0200, Tomi Valkeinen wrote:
> On 08/10/16 15:09, Mathieu Malaterre wrote:
> > When the linux kernel is build with (typical kernel ship with Debian
> > installer):
> > 
> > CONFIG_FB_OF=y
> > CONFIG_VT_HW_CONSOLE_BINDING=y
> > CONFIG_FB_RADEON=m
> > 
> > The offb driver takes precedence over module radeonfb. It is then
> > impossible to load the module, error reported is:
> > 
> > [   96.551486] radeonfb :00:10.0: enabling device (0006 -> 0007)
> > [   96.551526] radeonfb :00:10.0: BAR 0: can't reserve [mem 
> > 0x9800-0x9fff pref]
> > [   96.551531] radeonfb (:00:10.0): cannot request region 0.
> > [   96.551545] radeonfb: probe of :00:10.0 failed with error -16
> > 
> > This patch reproduce the behavior of the module radeon, so as to make it
> > possible to load radeonfb when offb is first loaded.
> > 
> > It should be noticed that `offb_destroy` is never called which explain the
> > need to skip error detection on the radeon side.
> 
> Why is that? It sounds rather bad if two drivers claim the same resources.

My understanding from reading through the console code is that you only
call destroy when the driver isn't in use anymore, and that doesn't
happen until something else takes over the console, which can't happen
until the new driver is active, which can't happen because the resources
are already claimed by the old driver.

PCs might be able to drop back to text console, but powerpc doesn't have
one of those so offb stays active until something else takes over the
console job it seems.

The radeon driver doesn't reserve resources, it just uses them.
This seems to be the case of quite a few drivers.

-- 
Len Sorensen


[PATCH 5/5] powerpc/oops: Fix remaining pr_cont() issues

2016-11-02 Thread Michael Ellerman
Now that we print SOFTE first, it's clear that the rest of these lines
need to be continuations, so use pr_cont().

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/process.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 84d334527fcd..ea6fe2ea4a6f 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1349,17 +1349,19 @@ void show_regs(struct pt_regs * regs)
 #ifdef CONFIG_PPC64
printk("SOFTE: %ld ", regs->softe);
if ((regs->trap != 0xc00) && cpu_has_feature(CPU_FTR_CFAR))
-   printk("CFAR: "REG" ", regs->orig_gpr3);
+   pr_cont("CFAR: "REG" ", regs->orig_gpr3);
 #endif
if (trap == 0x200 || trap == 0x300 || trap == 0x600)
 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
-   printk("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
+   pr_cont("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
 #else
-   printk("DAR: "REG" DSISR: %08lx ", regs->dar, regs->dsisr);
+   pr_cont("DAR: "REG" DSISR: %08lx ", regs->dar, regs->dsisr);
 #endif
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
-   if (MSR_TM_ACTIVE(regs->msr))
-   printk("\nPACATMSCRATCH: %016llx ", get_paca()->tm_scratch);
+   if (MSR_TM_ACTIVE(regs->msr)) {
+   pr_cont("\n");
+   printk("PACATMSCRATCH: %016llx ", get_paca()->tm_scratch);
+   }
 #endif
 
for (i = 0;  i < 32;  i++) {
-- 
2.7.4



[PATCH 4/5] powerpc/oops: Move printing of SOFTE before CFAR

2016-11-02 Thread Michael Ellerman
Now that KERN_CONT is required to do continuation lines properly, our
oops output is messed up.

But as the code is currently written we can't actually use pr_cont()
correctly, because some of the output may or may not be a continuation
line, depending on what was printed previously.

So move the printing of SOFTE up, so that we always have a line to
continue (at least on 64-bit). While we're at it, pull the CFAR logic
inside the #ifdef PPC64, CFAR is 64-bit only.

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/process.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 3898e381556f..84d334527fcd 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1346,17 +1346,17 @@ void show_regs(struct pt_regs * regs)
print_msr_bits(regs->msr);
printk("  CR: %08lx  XER: %08lx\n", regs->ccr, regs->xer);
trap = TRAP(regs);
+#ifdef CONFIG_PPC64
+   printk("SOFTE: %ld ", regs->softe);
if ((regs->trap != 0xc00) && cpu_has_feature(CPU_FTR_CFAR))
printk("CFAR: "REG" ", regs->orig_gpr3);
+#endif
if (trap == 0x200 || trap == 0x300 || trap == 0x600)
 #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
printk("DEAR: "REG" ESR: "REG" ", regs->dar, regs->dsisr);
 #else
printk("DAR: "REG" DSISR: %08lx ", regs->dar, regs->dsisr);
 #endif
-#ifdef CONFIG_PPC64
-   printk("SOFTE: %ld ", regs->softe);
-#endif
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
if (MSR_TM_ACTIVE(regs->msr))
printk("\nPACATMSCRATCH: %016llx ", get_paca()->tm_scratch);
-- 
2.7.4



[PATCH 3/5] powerpc/oops: Fix printing of GPRs since KERN_CONT changes

2016-11-02 Thread Michael Ellerman
Since the KERN_CONT changes our print out of the GPRs is messed up:

GPR04:
0001 c0155810
 0001

GPR08: 0007

Fix it for now by using pr_cont().

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/process.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 38f85d7a1e06..3898e381556f 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1363,13 +1363,15 @@ void show_regs(struct pt_regs * regs)
 #endif
 
for (i = 0;  i < 32;  i++) {
-   if ((i % REGS_PER_LINE) == 0)
-   printk("\nGPR%02d: ", i);
-   printk(REG " ", regs->gpr[i]);
+   if ((i % REGS_PER_LINE) == 0) {
+   pr_cont("\n");
+   printk("GPR%02d: ", i);
+   }
+   pr_cont(REG " ", regs->gpr[i]);
if (i == LAST_VOLATILE && !FULL_REGS(regs))
break;
}
-   printk("\n");
+   pr_cont("\n");
 #ifdef CONFIG_KALLSYMS
/*
 * Lookup NIP late so we have the best change of getting the
-- 
2.7.4



[PATCH 2/5] powerpc/oops: Fix missing pr_cont()s in print_msr_bits() et. al.

2016-11-02 Thread Michael Ellerman
Since the KERN_CONT changes these are being horribly split across lines,
for example:

MSR: 80009033 <
SF,EE
,ME,IR
,DR,RI
,LE>

So fix it by using pr_cont() where appropriate.

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/process.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 621d9b23df72..38f85d7a1e06 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1282,7 +1282,7 @@ static void print_bits(unsigned long val, struct regbit 
*bits, const char *sep)
 
for (; bits->bit; ++bits)
if (val & bits->bit) {
-   printk("%s%s", s, bits->name);
+   pr_cont("%s%s", s, bits->name);
s = sep;
}
 }
@@ -1305,9 +1305,9 @@ static void print_tm_bits(unsigned long val)
  *   T: Transactional  (bit 34)
  */
if (val & (MSR_TM | MSR_TS_S | MSR_TS_T)) {
-   printk(",TM[");
+   pr_cont(",TM[");
print_bits(val, msr_tm_bits, "");
-   printk("]");
+   pr_cont("]");
}
 }
 #else
@@ -1316,10 +1316,10 @@ static void print_tm_bits(unsigned long val) {}
 
 static void print_msr_bits(unsigned long val)
 {
-   printk("<");
+   pr_cont("<");
print_bits(val, msr_bits, ",");
print_tm_bits(val);
-   printk(">");
+   pr_cont(">");
 }
 
 #ifdef CONFIG_PPC64
-- 
2.7.4



[PATCH 1/5] powerpc/oops: Fix missing KERN_CONT in show_stack()

2016-11-02 Thread Michael Ellerman
Previously we got away with printing the stack trace in multiple pieces
and it usually looked right.  But since commit 4bcc595ccd80 ("printk:
reinstate KERN_CONT for printing continuation lines"), KERN_CONT is now
required when printing continuation lines.

Signed-off-by: Michael Ellerman 
---
 arch/powerpc/kernel/process.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index ce6dc61b15b2..621d9b23df72 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1900,14 +1900,14 @@ void show_stack(struct task_struct *tsk, unsigned long 
*stack)
printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
if ((ip == rth) && curr_frame >= 0) {
-   printk(" (%pS)",
+   pr_cont(" (%pS)",
   (void 
*)current->ret_stack[curr_frame].ret);
curr_frame--;
}
 #endif
if (firstframe)
-   printk(" (unreliable)");
-   printk("\n");
+   pr_cont(" (unreliable)");
+   pr_cont("\n");
}
firstframe = 0;
 
-- 
2.7.4



Re: [PATCH] cxl: Fix error handling

2016-11-02 Thread Michael Ellerman
Jim Davis  writes:

> On Sun, Oct 30, 2016 at 10:37 PM, Michael Ellerman  
> wrote:
>> More here:
>>
>> https://github.com/linuxppc/linux/wiki/Building-powerpc-kernels
>
> Cool; the little-endian build worked fine, but

Yay, thanks for trying.

> jim@krebstar:~/linux-rc$ make ARCH=powerpc
> CROSS_COMPILE=powerpc64-linux-gnu- vmlinux
> make: powerpc64-linux-gnu-gcc: Command not found
> make: powerpc64-linux-gnu-gcc: Command not found
> scripts/kconfig/conf  --silentoldconfig Kconfig
> make: powerpc64-linux-gnu-gcc: Command not found

Ah sorry.

> This is on Ubuntu 16.04; there's a /usr/bin/powerpc64le-linux-gnu-gcc
> from installing gcc-powerpc64le-linux-gnu, and a
> /usr/bin/powerpc-linux-gnu-gcc from installing gcc-powerpc-linux-gnu,
> but no /usr/bin/powerpc64-linux-gnu-gcc.

It's the powerpc-linux-gnu-gcc one.

That is a 32 and 64-bit compiler, it's 32-bit by default, but the kernel
Makefiles will pass -m64 appropriately.

You can actually build a single compiler that builds 32/64-bit BE, and
64-bit LE, but the distros don't do that for whatever reason.

cheers


compiling master.

2016-11-02 Thread Denis Kirjanov
Hi guys,

compiling ppc head with bunch of asm errors on power8 box (gcc version 4.8.3 )
checked commit log but found nothing special. Looks like it's asm issue?
Has anybody seen that?

arch/powerpc/kernel/exceptions-64s.S: Assembler messages:
arch/powerpc/kernel/exceptions-64s.S:421: Error: operand out of range
(0x8680 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:663: Error: operand out of range
(0x8b00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:671: Error: operand out of range
(0x8c80 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:708: Error: operand out of range
(0x8e00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:721: Error: operand out of range
(0x8e00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:137: Error: operand out of range
(0x8000 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:471: Error: operand out of range
(0x8700 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:517: Error: operand out of range
(0x8a00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:548: Error: operand out of range
(0x8880 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:580: Error: operand out of range
(0x8a00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:703: Error: operand out of range
(0x8e00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:728: Error: operand out of range
(0x8f80 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:748: Error: operand out of range
(0x9100 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:760: Error: operand out of range
(0x9280 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:793: Error: operand out of range
(0x9480 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:799: Error: operand out of range
(0x9600 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:805: Error: operand out of range
(0x9780 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:815: Error: operand out of range
(0x9900 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:911: Error: operand out of range
(0x9a80 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:1130: Error: operand out of range
(0xad80 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:1152: Error: operand out of range
(0xaf00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:1243: Error: operand out of range
(0xb080 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:149: Error: operand out of range
(0x8000 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:229: Error: operand out of range
(0x8380 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:241: Error: operand out of range
(0x8680 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:264: Error: operand out of range
(0x8180 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:916: Error: operand out of range
(0x9c00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:932: Error: operand out of range
(0x9d80 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:938: Error: operand out of range
(0x9f00 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:950: Error: operand out of range
(0xa080 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:1005: Error: operand out of range
(0xa200 is not between 0x and
0x)
arch/powerpc/kernel/exceptions-64s.S:1015: Error: operand out of range
(0xa380 is not between 0x and
0x)
arch/powerpc/k

Re: [PATCH 3/3] powerpc: emulate_step test for load/store instructions

2016-11-02 Thread Naveen N. Rao
On 2016/11/02 02:23PM, Ravi Bangoria wrote:
> Add new selftest that test emulate_step for Normal, Floating Point,
> Vector and Vector Scalar - load/store instructions. Test should run
> at boot time if CONFIG_KPROBES_SANITY_TEST and CONFIG_PPC64 is set.
> 
> Sample log:
> 
>   [0.762063] emulate_step smoke test: start.
>   [0.762219] emulate_step smoke test: ld : PASS
>   [0.762434] emulate_step smoke test: lwz: PASS
>   [0.762653] emulate_step smoke test: lwzx   : PASS
>   [0.762867] emulate_step smoke test: std: PASS
>   [0.763082] emulate_step smoke test: ldarx / stdcx. : PASS
>   [0.763302] emulate_step smoke test: lfsx   : PASS
>   [0.763514] emulate_step smoke test: stfsx  : PASS
>   [0.763727] emulate_step smoke test: lfdx   : PASS
>   [0.763942] emulate_step smoke test: stfdx  : PASS
>   [0.764134] emulate_step smoke test: lvx: PASS
>   [0.764349] emulate_step smoke test: stvx   : PASS
>   [0.764575] emulate_step smoke test: lxvd2x : PASS
>   [0.764788] emulate_step smoke test: stxvd2x: PASS
>   [0.764997] emulate_step smoke test: complete.
> 
> Signed-off-by: Ravi Bangoria 
> ---
>  arch/powerpc/include/asm/sstep.h |   8 +
>  arch/powerpc/kernel/kprobes.c|   2 +
>  arch/powerpc/lib/Makefile|   4 +
>  arch/powerpc/lib/test_emulate_step.c | 439 
> +++
>  4 files changed, 453 insertions(+)
>  create mode 100644 arch/powerpc/lib/test_emulate_step.c
> 
> diff --git a/arch/powerpc/include/asm/sstep.h 
> b/arch/powerpc/include/asm/sstep.h
> index d3a42cc..d6d3630 100644
> --- a/arch/powerpc/include/asm/sstep.h
> +++ b/arch/powerpc/include/asm/sstep.h
> @@ -87,3 +87,11 @@ struct instruction_op {
> 
>  extern int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
>unsigned int instr);
> +
> +#if defined(CONFIG_KPROBES_SANITY_TEST) && defined(CONFIG_PPC64)
> +void test_emulate_step(void);
> +#else
> +static inline void test_emulate_step(void)
> +{
> +}
> +#endif
> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
> index e785cc9..01d8002 100644
> --- a/arch/powerpc/kernel/kprobes.c
> +++ b/arch/powerpc/kernel/kprobes.c
> @@ -544,6 +544,8 @@ int __kprobes longjmp_break_handler(struct kprobe *p, 
> struct pt_regs *regs)
> 
>  int __init arch_init_kprobes(void)
>  {
> + test_emulate_step();
> +
>   return register_kprobe(&trampoline_p);
>  }
> 
> diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
> index 309361e8..7d046ca 100644
> --- a/arch/powerpc/lib/Makefile
> +++ b/arch/powerpc/lib/Makefile
> @@ -35,3 +35,7 @@ obj-$(CONFIG_ALTIVEC)   += xor_vmx.o
>  CFLAGS_xor_vmx.o += -maltivec $(call cc-option,-mabi=altivec)
> 
>  obj-$(CONFIG_PPC64) += $(obj64-y)
> +
> +ifeq ($(CONFIG_PPC64), y)
> +obj-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o
> +endif
> diff --git a/arch/powerpc/lib/test_emulate_step.c 
> b/arch/powerpc/lib/test_emulate_step.c
> new file mode 100644
> index 000..887d1db
> --- /dev/null
> +++ b/arch/powerpc/lib/test_emulate_step.c
> @@ -0,0 +1,439 @@
> +/*
> + * test_emulate_step.c - simple sanity test for emulate_step load/store
> + *instructions
> + *
> + * Copyright IBM Corp. 2016
> + *
> + * This program is free software;  you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
> + * the GNU General Public License for more details.
> + */
> +
> +#define pr_fmt(fmt) "emulate_step smoke test: " fmt
> +
> +#include 
> +#include 
> +#include 
> +
> +#define IMM_L(i) ((uintptr_t)(i) & 0x)
> +
> +/*
> + * Defined with TEST_ prefix so it does not conflict with other
> + * definitions.
> + */
> +#define TEST_LD(r, base, i)  (PPC_INST_LD | ___PPC_RT(r) |   \
> + ___PPC_RA(base) | IMM_L(i))
> +#define TEST_LWZ(r, base, i) (PPC_INST_LWZ | ___PPC_RT(r) |  \
> + ___PPC_RA(base) | IMM_L(i))
> +#define TEST_LWZX(t, a, b)   (PPC_INST_LWZX | ___PPC_RT(t) | \
> + ___PPC_RA(a) | ___PPC_RB(b))
> +#define TEST_STD(r, base, i) (PPC_INST_STD | ___PPC_RS(r) |  \
> + ___PPC_RA(base) | ((i) & 0xfffc))
> +#define TEST_LDARX(t, a, b, eh)  (PPC_INST_LDARX | ___PPC_RT(t) |
> \
> + ___PPC_RA(a) | ___PPC_RB(b) |   \
> + __PPC_EH(eh))
> +#def

Re: [PATCH] Fix loading of module radeonfb on PowerMac

2016-11-02 Thread Mathieu Malaterre
Tomi,

On Wed, Nov 2, 2016 at 9:28 AM, Tomi Valkeinen  wrote:
> On 08/10/16 15:09, Mathieu Malaterre wrote:
>> When the linux kernel is build with (typical kernel ship with Debian
>> installer):
>>
>> CONFIG_FB_OF=y
>> CONFIG_VT_HW_CONSOLE_BINDING=y
>> CONFIG_FB_RADEON=m
>>
>> The offb driver takes precedence over module radeonfb. It is then
>> impossible to load the module, error reported is:
>>
>> [   96.551486] radeonfb :00:10.0: enabling device (0006 -> 0007)
>> [   96.551526] radeonfb :00:10.0: BAR 0: can't reserve [mem 
>> 0x9800-0x9fff pref]
>> [   96.551531] radeonfb (:00:10.0): cannot request region 0.
>> [   96.551545] radeonfb: probe of :00:10.0 failed with error -16
>>
>> This patch reproduce the behavior of the module radeon, so as to make it
>> possible to load radeonfb when offb is first loaded.
>>
>> It should be noticed that `offb_destroy` is never called which explain the
>> need to skip error detection on the radeon side.
>
> Why is that? It sounds rather bad if two drivers claim the same resources.

This has been working great so far for `radeon.ko`, so I assumed I
could shamelessly copy the behavior over to `radeonfb.ko`.

The original reference I found was from Benjamin Herrenschmidt here:
https://lists.freedesktop.org/archives/dri-devel/2010-August/002907.html

I am of course willing to try something else, but I would need some guidance.

Thanks much.


[PATCH] powerpc/configs: Turn on PPC crypto implementations in the server defconfigs

2016-11-02 Thread Michael Ellerman
These are the PPC optimised versions of various crypto algorithms, so we
should turn them on by default to get test coverage.

Suggested-by: Nicholas Piggin 
Signed-off-by: Michael Ellerman 
---
 arch/powerpc/configs/powernv_defconfig | 3 +++
 arch/powerpc/configs/ppc64_defconfig   | 3 +++
 arch/powerpc/configs/pseries_defconfig | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/arch/powerpc/configs/powernv_defconfig 
b/arch/powerpc/configs/powernv_defconfig
index d98b6eb3254f..39223dcca60e 100644
--- a/arch/powerpc/configs/powernv_defconfig
+++ b/arch/powerpc/configs/powernv_defconfig
@@ -300,6 +300,8 @@ CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_CCM=m
 CONFIG_CRYPTO_PCBC=m
 CONFIG_CRYPTO_HMAC=y
+CONFIG_CRYPT_CRC32C_VPMSUM=m
+CONFIG_CRYPTO_MD5_PPC=m
 CONFIG_CRYPTO_MICHAEL_MIC=m
 CONFIG_CRYPTO_TGR192=m
 CONFIG_CRYPTO_WP512=m
@@ -308,6 +310,7 @@ CONFIG_CRYPTO_BLOWFISH=m
 CONFIG_CRYPTO_CAST6=m
 CONFIG_CRYPTO_KHAZAD=m
 CONFIG_CRYPTO_SALSA20=m
+CONFIG_CRYPTO_SHA1_PPC=m
 CONFIG_CRYPTO_SERPENT=m
 CONFIG_CRYPTO_TEA=m
 CONFIG_CRYPTO_TWOFISH=m
diff --git a/arch/powerpc/configs/ppc64_defconfig 
b/arch/powerpc/configs/ppc64_defconfig
index 58a98d40086f..d3f1e2c23d90 100644
--- a/arch/powerpc/configs/ppc64_defconfig
+++ b/arch/powerpc/configs/ppc64_defconfig
@@ -335,6 +335,8 @@ CONFIG_PPC_EARLY_DEBUG=y
 CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_PCBC=m
 CONFIG_CRYPTO_HMAC=y
+CONFIG_CRYPT_CRC32C_VPMSUM=m
+CONFIG_CRYPTO_MD5_PPC=m
 CONFIG_CRYPTO_MICHAEL_MIC=m
 CONFIG_CRYPTO_TGR192=m
 CONFIG_CRYPTO_WP512=m
@@ -343,6 +345,7 @@ CONFIG_CRYPTO_BLOWFISH=m
 CONFIG_CRYPTO_CAST6=m
 CONFIG_CRYPTO_KHAZAD=m
 CONFIG_CRYPTO_SALSA20=m
+CONFIG_CRYPTO_SHA1_PPC=m
 CONFIG_CRYPTO_SERPENT=m
 CONFIG_CRYPTO_TEA=m
 CONFIG_CRYPTO_TWOFISH=m
diff --git a/arch/powerpc/configs/pseries_defconfig 
b/arch/powerpc/configs/pseries_defconfig
index 8a3bc016b732..56069b80e2fb 100644
--- a/arch/powerpc/configs/pseries_defconfig
+++ b/arch/powerpc/configs/pseries_defconfig
@@ -302,6 +302,8 @@ CONFIG_XMON=y
 CONFIG_CRYPTO_TEST=m
 CONFIG_CRYPTO_PCBC=m
 CONFIG_CRYPTO_HMAC=y
+CONFIG_CRYPT_CRC32C_VPMSUM=m
+CONFIG_CRYPTO_MD5_PPC=m
 CONFIG_CRYPTO_MICHAEL_MIC=m
 CONFIG_CRYPTO_TGR192=m
 CONFIG_CRYPTO_WP512=m
@@ -310,6 +312,7 @@ CONFIG_CRYPTO_BLOWFISH=m
 CONFIG_CRYPTO_CAST6=m
 CONFIG_CRYPTO_KHAZAD=m
 CONFIG_CRYPTO_SALSA20=m
+CONFIG_CRYPTO_SHA1_PPC=m
 CONFIG_CRYPTO_SERPENT=m
 CONFIG_CRYPTO_TEA=m
 CONFIG_CRYPTO_TWOFISH=m
-- 
2.7.4



Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

2016-11-02 Thread Stanislaw Gruszka
On Wed, Nov 02, 2016 at 10:11:22AM +0100, Christian Borntraeger wrote:
> On 10/31/2016 01:36 PM, Stanislaw Gruszka wrote:
> > Only s390 and powerpc have hardware facilities allowing to measure
> > cputimes scaled by frequency. On all other architectures
> > utimescaled/stimescaled are equal to utime/stime (however they are
> > accounted separately).
> > 
> > Patch remove {u,s}timescaled accounting on all architectures except
> > powerpc and s390, where those values are explicitly accounted on proper
> > places.
> 
> If we remove it everywhere else (and assuming that there are no users then)
> I aks myself if we should remove this as well from s390.

There is one user of scaled cputimes values, it is taskstats (to users
space are exported ac_utimescaled, ac_stimescaled and
cpu_scaled_run_real_total which is calculated based on scaled times).
However on other than powerpc and s390 architectures scaled times are
equal to normal times (this is also true for older powerpc's without
SPURR/PURR registers).

Stanislaw


Re: [PATCH 3/4] cputime/powerpc/s390: make scaled cputime arch specific

2016-11-02 Thread Christian Borntraeger
On 10/31/2016 01:36 PM, Stanislaw Gruszka wrote:
> Only s390 and powerpc have hardware facilities allowing to measure
> cputimes scaled by frequency. On all other architectures
> utimescaled/stimescaled are equal to utime/stime (however they are
> accounted separately).
> 
> Patch remove {u,s}timescaled accounting on all architectures except
> powerpc and s390, where those values are explicitly accounted on proper
> places.

If we remove it everywhere else (and assuming that there are no users then)
I aks myself if we should remove this as well from s390.

We already had to optimize this because the initial code caused some
regressions (commit f341b8dff9 s390/vtime: limit MT scaling value updates).
The code still adds a multiply and a divide to do_account_vtime (and 2
multiplies and 2 divides into vtime_account_irq_enter) which is still
noticeable in perf annotate for switch intense workload.

Martin are you aware of any user of that values?

> 
> Signed-off-by: Stanislaw Gruszka 
> ---
>  arch/ia64/kernel/time.c |4 +-
>  arch/powerpc/Kconfig|1 +
>  arch/powerpc/kernel/time.c  |6 +++-
>  arch/s390/Kconfig   |1 +
>  arch/s390/kernel/vtime.c|9 --
>  include/linux/kernel_stat.h |4 +-
>  include/linux/sched.h   |   23 
>  kernel/fork.c   |2 +
>  kernel/sched/cputime.c  |   61 ++
>  9 files changed, 50 insertions(+), 61 deletions(-)
> 
> diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
> index 6f892b9..021f44a 100644
> --- a/arch/ia64/kernel/time.c
> +++ b/arch/ia64/kernel/time.c
> @@ -68,7 +68,7 @@ void vtime_account_user(struct task_struct *tsk)
> 
>   if (ti->ac_utime) {
>   delta_utime = cycle_to_cputime(ti->ac_utime);
> - account_user_time(tsk, delta_utime, delta_utime);
> + account_user_time(tsk, delta_utime);
>   ti->ac_utime = 0;
>   }
>  }
> @@ -112,7 +112,7 @@ void vtime_account_system(struct task_struct *tsk)
>  {
>   cputime_t delta = vtime_delta(tsk);
> 
> - account_system_time(tsk, 0, delta, delta);
> + account_system_time(tsk, 0, delta);
>  }
>  EXPORT_SYMBOL_GPL(vtime_account_system);
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 65fba4c..c7f120a 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -160,6 +160,7 @@ config PPC
>   select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
>   select GENERIC_CPU_AUTOPROBE
>   select HAVE_VIRT_CPU_ACCOUNTING
> + select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE
>   select HAVE_ARCH_HARDENED_USERCOPY
>   select HAVE_KERNEL_GZIP
> 
> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
> index 8105198..be9751f 100644
> --- a/arch/powerpc/kernel/time.c
> +++ b/arch/powerpc/kernel/time.c
> @@ -358,7 +358,8 @@ void vtime_account_system(struct task_struct *tsk)
>   unsigned long delta, sys_scaled, stolen;
> 
>   delta = vtime_delta(tsk, &sys_scaled, &stolen);
> - account_system_time(tsk, 0, delta, sys_scaled);
> + account_system_time(tsk, 0, delta);
> + tsk->stimescaled += sys_scaled;
>   if (stolen)
>   account_steal_time(stolen);
>  }
> @@ -391,7 +392,8 @@ void vtime_account_user(struct task_struct *tsk)
>   acct->user_time = 0;
>   acct->user_time_scaled = 0;
>   acct->utime_sspurr = 0;
> - account_user_time(tsk, utime, utimescaled);
> + account_user_time(tsk, utime);
> + tsk->utimescaled += utimescaled;
>  }
> 
>  #ifdef CONFIG_PPC32
> diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
> index 426481d..028f97b 100644
> --- a/arch/s390/Kconfig
> +++ b/arch/s390/Kconfig
> @@ -171,6 +171,7 @@ config S390
>   select SYSCTL_EXCEPTION_TRACE
>   select TTY
>   select VIRT_CPU_ACCOUNTING
> + select ARCH_HAS_SCALED_CPUTIME
>   select VIRT_TO_BUS
>   select HAVE_NMI
> 
> diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
> index 856e30d..90eeb7c 100644
> --- a/arch/s390/kernel/vtime.c
> +++ b/arch/s390/kernel/vtime.c
> @@ -137,8 +137,10 @@ static int do_account_vtime(struct task_struct *tsk, int 
> hardirq_offset)
>   user_scaled = (user_scaled * mult) / div;
>   system_scaled = (system_scaled * mult) / div;
>   }
> - account_user_time(tsk, user, user_scaled);
> - account_system_time(tsk, hardirq_offset, system, system_scaled);
> + account_user_time(tsk, user);
> + tsk->utimescaled += user_scaled;
> + account_system_time(tsk, hardirq_offset, system)
> + tsk->stimescaled += system_scaled;
> 
>   steal = S390_lowcore.steal_timer;
>   if ((s64) steal > 0) {
> @@ -202,7 +204,8 @@ void vtime_account_irq_enter(struct task_struct *tsk)
> 
>   system_scaled = (system_scaled * mult) / div;
>   }
> - account_system_time(tsk, 0, system, system_scaled);
> + account_system_time(tsk, 0, system);
> +

[PATCH 3/3] powerpc: emulate_step test for load/store instructions

2016-11-02 Thread Ravi Bangoria
Add new selftest that test emulate_step for Normal, Floating Point,
Vector and Vector Scalar - load/store instructions. Test should run
at boot time if CONFIG_KPROBES_SANITY_TEST and CONFIG_PPC64 is set.

Sample log:

  [0.762063] emulate_step smoke test: start.
  [0.762219] emulate_step smoke test: ld : PASS
  [0.762434] emulate_step smoke test: lwz: PASS
  [0.762653] emulate_step smoke test: lwzx   : PASS
  [0.762867] emulate_step smoke test: std: PASS
  [0.763082] emulate_step smoke test: ldarx / stdcx. : PASS
  [0.763302] emulate_step smoke test: lfsx   : PASS
  [0.763514] emulate_step smoke test: stfsx  : PASS
  [0.763727] emulate_step smoke test: lfdx   : PASS
  [0.763942] emulate_step smoke test: stfdx  : PASS
  [0.764134] emulate_step smoke test: lvx: PASS
  [0.764349] emulate_step smoke test: stvx   : PASS
  [0.764575] emulate_step smoke test: lxvd2x : PASS
  [0.764788] emulate_step smoke test: stxvd2x: PASS
  [0.764997] emulate_step smoke test: complete.

Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/include/asm/sstep.h |   8 +
 arch/powerpc/kernel/kprobes.c|   2 +
 arch/powerpc/lib/Makefile|   4 +
 arch/powerpc/lib/test_emulate_step.c | 439 +++
 4 files changed, 453 insertions(+)
 create mode 100644 arch/powerpc/lib/test_emulate_step.c

diff --git a/arch/powerpc/include/asm/sstep.h b/arch/powerpc/include/asm/sstep.h
index d3a42cc..d6d3630 100644
--- a/arch/powerpc/include/asm/sstep.h
+++ b/arch/powerpc/include/asm/sstep.h
@@ -87,3 +87,11 @@ struct instruction_op {
 
 extern int analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 unsigned int instr);
+
+#if defined(CONFIG_KPROBES_SANITY_TEST) && defined(CONFIG_PPC64)
+void test_emulate_step(void);
+#else
+static inline void test_emulate_step(void)
+{
+}
+#endif
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index e785cc9..01d8002 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -544,6 +544,8 @@ int __kprobes longjmp_break_handler(struct kprobe *p, 
struct pt_regs *regs)
 
 int __init arch_init_kprobes(void)
 {
+   test_emulate_step();
+
return register_kprobe(&trampoline_p);
 }
 
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 309361e8..7d046ca 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -35,3 +35,7 @@ obj-$(CONFIG_ALTIVEC) += xor_vmx.o
 CFLAGS_xor_vmx.o += -maltivec $(call cc-option,-mabi=altivec)
 
 obj-$(CONFIG_PPC64) += $(obj64-y)
+
+ifeq ($(CONFIG_PPC64), y)
+obj-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o
+endif
diff --git a/arch/powerpc/lib/test_emulate_step.c 
b/arch/powerpc/lib/test_emulate_step.c
new file mode 100644
index 000..887d1db
--- /dev/null
+++ b/arch/powerpc/lib/test_emulate_step.c
@@ -0,0 +1,439 @@
+/*
+ * test_emulate_step.c - simple sanity test for emulate_step load/store
+ *  instructions
+ *
+ * Copyright IBM Corp. 2016
+ *
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ */
+
+#define pr_fmt(fmt) "emulate_step smoke test: " fmt
+
+#include 
+#include 
+#include 
+
+#define IMM_L(i)   ((uintptr_t)(i) & 0x)
+
+/*
+ * Defined with TEST_ prefix so it does not conflict with other
+ * definitions.
+ */
+#define TEST_LD(r, base, i)(PPC_INST_LD | ___PPC_RT(r) |   \
+   ___PPC_RA(base) | IMM_L(i))
+#define TEST_LWZ(r, base, i)   (PPC_INST_LWZ | ___PPC_RT(r) |  \
+   ___PPC_RA(base) | IMM_L(i))
+#define TEST_LWZX(t, a, b) (PPC_INST_LWZX | ___PPC_RT(t) | \
+   ___PPC_RA(a) | ___PPC_RB(b))
+#define TEST_STD(r, base, i)   (PPC_INST_STD | ___PPC_RS(r) |  \
+   ___PPC_RA(base) | ((i) & 0xfffc))
+#define TEST_LDARX(t, a, b, eh)(PPC_INST_LDARX | ___PPC_RT(t) |
\
+   ___PPC_RA(a) | ___PPC_RB(b) |   \
+   __PPC_EH(eh))
+#define TEST_STDCX(s, a, b)(PPC_INST_STDCX | ___PPC_RS(s) |\
+   ___PPC_RA(a) | ___PPC_RB(b))
+#define TEST_LFSX(t, a, b) (PPC_INST_LFSX | ___PPC_RT(t) | \
+   ___PPC_RA(a)

[PATCH 2/3] powerpc: Add encoding for couple of load/store instructions

2016-11-02 Thread Ravi Bangoria
These encodings will be used in subsequent patch that test
emulate_step for load/store instructions.

Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/include/asm/ppc-opcode.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/powerpc/include/asm/ppc-opcode.h 
b/arch/powerpc/include/asm/ppc-opcode.h
index 0132831..a17a09a 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -284,6 +284,13 @@
 #define PPC_INST_BRANCH_COND   0x4080
 #define PPC_INST_LBZCIX0x7c0006aa
 #define PPC_INST_STBCIX0x7c0007aa
+#define PPC_INST_LWZX  0x7c2e
+#define PPC_INST_LFSX  0x7c00042e
+#define PPC_INST_STFSX 0x7c00052e
+#define PPC_INST_LFDX  0x7c0004ae
+#define PPC_INST_STFDX 0x7c0005ae
+#define PPC_INST_LVX   0x7cce
+#define PPC_INST_STVX  0x7c0001ce
 
 /* macros to insert fields into opcodes */
 #define ___PPC_RA(a)   (((a) & 0x1f) << 16)
-- 
1.8.3.1



[PATCH 1/3] powerpc: Emulation support for load/store instructions on LE

2016-11-02 Thread Ravi Bangoria
emulate_step() uses a number of underlying kernel functions that were
initially not enabled for LE. This has been rectified since. So, fix
emulate_step() for LE for the corresponding instructions.

Reported-by: Anton Blanchard 
Signed-off-by: Ravi Bangoria 
---
 arch/powerpc/lib/sstep.c | 20 
 1 file changed, 20 deletions(-)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 3362299..6ca3b90 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -1807,8 +1807,6 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned 
int instr)
goto instr_done;
 
case LARX:
-   if (regs->msr & MSR_LE)
-   return 0;
if (op.ea & (size - 1))
break;  /* can't handle misaligned */
err = -EFAULT;
@@ -1832,8 +1830,6 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned 
int instr)
goto ldst_done;
 
case STCX:
-   if (regs->msr & MSR_LE)
-   return 0;
if (op.ea & (size - 1))
break;  /* can't handle misaligned */
err = -EFAULT;
@@ -1859,8 +1855,6 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned 
int instr)
goto ldst_done;
 
case LOAD:
-   if (regs->msr & MSR_LE)
-   return 0;
err = read_mem(®s->gpr[op.reg], op.ea, size, regs);
if (!err) {
if (op.type & SIGNEXT)
@@ -1872,8 +1866,6 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned 
int instr)
 
 #ifdef CONFIG_PPC_FPU
case LOAD_FP:
-   if (regs->msr & MSR_LE)
-   return 0;
if (size == 4)
err = do_fp_load(op.reg, do_lfs, op.ea, size, regs);
else
@@ -1882,15 +1874,11 @@ int __kprobes emulate_step(struct pt_regs *regs, 
unsigned int instr)
 #endif
 #ifdef CONFIG_ALTIVEC
case LOAD_VMX:
-   if (regs->msr & MSR_LE)
-   return 0;
err = do_vec_load(op.reg, do_lvx, op.ea & ~0xfUL, regs);
goto ldst_done;
 #endif
 #ifdef CONFIG_VSX
case LOAD_VSX:
-   if (regs->msr & MSR_LE)
-   return 0;
err = do_vsx_load(op.reg, do_lxvd2x, op.ea, regs);
goto ldst_done;
 #endif
@@ -1913,8 +1901,6 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned 
int instr)
goto instr_done;
 
case STORE:
-   if (regs->msr & MSR_LE)
-   return 0;
if ((op.type & UPDATE) && size == sizeof(long) &&
op.reg == 1 && op.update_reg == 1 &&
!(regs->msr & MSR_PR) &&
@@ -1927,8 +1913,6 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned 
int instr)
 
 #ifdef CONFIG_PPC_FPU
case STORE_FP:
-   if (regs->msr & MSR_LE)
-   return 0;
if (size == 4)
err = do_fp_store(op.reg, do_stfs, op.ea, size, regs);
else
@@ -1937,15 +1921,11 @@ int __kprobes emulate_step(struct pt_regs *regs, 
unsigned int instr)
 #endif
 #ifdef CONFIG_ALTIVEC
case STORE_VMX:
-   if (regs->msr & MSR_LE)
-   return 0;
err = do_vec_store(op.reg, do_stvx, op.ea & ~0xfUL, regs);
goto ldst_done;
 #endif
 #ifdef CONFIG_VSX
case STORE_VSX:
-   if (regs->msr & MSR_LE)
-   return 0;
err = do_vsx_store(op.reg, do_stxvd2x, op.ea, regs);
goto ldst_done;
 #endif
-- 
1.8.3.1



[PATCH 0/3] powerpc: Emulation support for load/store instructions on LE

2016-11-02 Thread Ravi Bangoria
emulate_step is the basic infrastructure which is used by number of other
kernel infrastructures like kprobe, hw-breakpoint(data breakpoint) etc.
In case of kprobe, enabling emulation of load/store instructions will
speedup the execution of probed instruction. In case of kernel-space
breakpoint, causative instruction is first get emulated before executing
user registered handler. If emulation fails, hw-breakpoint is disabled
with error. As emulate_step does not support load/store instructions on
LE, kernel-space hw-breakpoint infrastructure is broken on LE.

emulate_step() uses a number of underlying kernel functions that were
initially not enabled for LE. This has been rectified since. So, fix
emulate_step() for LE for the corresponding instructions.

Also add selftest which will run at boot if CONFIG_KPROBES_SANITY_TEST
and CONFIG_PPC64 is set.

Changes w.r.t. RFC:
  - Enable emulation support for all types of (Normal, Floating Point,
Vector and Vector Scalar) load/store instructions.
  - Introduce selftest to test emulate_step for load/store instructions.

Ravi Bangoria (3):
  powerpc: Emulation support for load/store instructions on LE
  powerpc: Add encoding for couple of load/store instructions
  powerpc: emulate_step test for load/store instructions

 arch/powerpc/include/asm/ppc-opcode.h |   7 +
 arch/powerpc/include/asm/sstep.h  |   8 +
 arch/powerpc/kernel/kprobes.c |   2 +
 arch/powerpc/lib/Makefile |   4 +
 arch/powerpc/lib/sstep.c  |  20 --
 arch/powerpc/lib/test_emulate_step.c  | 439 ++
 6 files changed, 460 insertions(+), 20 deletions(-)
 create mode 100644 arch/powerpc/lib/test_emulate_step.c

-- 
1.8.3.1



Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Gautham R Shenoy
Hi Nick,

On Wed, Nov 02, 2016 at 07:36:24PM +1100, Nicholas Piggin wrote:
> 
> Okay, I'll work with that. What's the best way to make a P8 do
> winkle sleeps?

>From the userspace, offlining the CPUs of the core will put them to
winkle.

> 
> Thanks,
> Nick
> 
--
Thanks and Regards
gautham.



Re: [PATCH v2 2/3] cpuidle:powernv: Add helper function to populate powernv idle states.

2016-11-02 Thread Gautham R Shenoy
Hi Oliver,

Thanks for reviewing the patch!

On Tue, Nov 01, 2016 at 07:32:58PM +1100, Oliver O'Halloran wrote:
> On Thu, Oct 27, 2016 at 7:35 PM, Gautham R. Shenoy
>  wrote:
> > From: "Gautham R. Shenoy" 
> >
> > In the current code for powernv_add_idle_states, there is a lot of code
> > duplication while initializing an idle state in powernv_states table.
> >
> > Add an inline helper function to populate the powernv_states[] table for
> > a given idle state. Invoke this for populating the "Nap", "Fastsleep"
> > and the stop states in powernv_add_idle_states.
> >
> > Signed-off-by: Gautham R. Shenoy 
> > ---
> >  drivers/cpuidle/cpuidle-powernv.c | 82 
> > +++
> >  include/linux/cpuidle.h   |  1 +
> >  2 files changed, 49 insertions(+), 34 deletions(-)
> >
> > diff --git a/drivers/cpuidle/cpuidle-powernv.c 
> > b/drivers/cpuidle/cpuidle-powernv.c
> > index 7fe442c..11b22b9 100644
> > --- a/drivers/cpuidle/cpuidle-powernv.c
> > +++ b/drivers/cpuidle/cpuidle-powernv.c
> > @@ -167,6 +167,28 @@ static int powernv_cpuidle_driver_init(void)
> > return 0;
> >  }
> >
> > +static inline void add_powernv_state(int index, const char *name,
> > +unsigned int flags,
> > +int (*idle_fn)(struct cpuidle_device *,
> > +   struct cpuidle_driver *,
> > +   int),
> > +unsigned int target_residency,
> > +unsigned int exit_latency,
> > +u64 psscr_val)
> > +{
> > +   strncpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);
> > +   strncpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);
> 
> If the supplied name is equal to CPUIDLE_NAME_LEN then strncpy() won't
> terminate the string. The least annoying fix is to memset() the whole
> structure to zero and set n to CPUIDLE_NAME_LEN - 1.

I will change this to use strlcpy as Paul suggested in the reply.

> 
> > +   powernv_states[index].flags = flags;
> > +   powernv_states[index].target_residency = target_residency;
> > +   powernv_states[index].exit_latency = exit_latency;
> > +   powernv_states[index].enter = idle_fn;
> > +
> > +   if (idle_fn != stop_loop)
> > +   return;
> 
> This can probably be deleted. The nap/sleep loops don't look at the
> psscr setting and you've passed in a dummy value of zero anyway.

The subsequent patch adds the missing bits to the psscr_val if we are
running on the older firmware. But in any case, as you rightly pointed
out we don't use psscr_table in nap/sleep loops. So this can go.

> 
> > +
> > +   stop_psscr_table[index] = psscr_val;
> > +}
> > +
> >  static int powernv_add_idle_states(void)
> >  {
> > struct device_node *power_mgt;
> > @@ -236,6 +258,7 @@ static int powernv_add_idle_states(void)
> > "ibm,cpu-idle-state-residency-ns", residency_ns, 
> > dt_idle_states);
> >
> > for (i = 0; i < dt_idle_states; i++) {
> > +   unsigned int exit_latency, target_residency;
> > /*
> >  * If an idle state has exit latency beyond
> >  * POWERNV_THRESHOLD_LATENCY_NS then don't use it
> > @@ -244,27 +267,30 @@ static int powernv_add_idle_states(void)
> > if (latency_ns[i] > POWERNV_THRESHOLD_LATENCY_NS)
> > continue;
> >
> > +   exit_latency = ((unsigned int)latency_ns[i]) / 1000;
> > +   target_residency = (!rc) ? ((unsigned int)residency_ns[i]) 
> > : 0;
> > +   /*
> > +* Firmware passes residency values in ns.
> > +* cpuidle expects it in us.
> > +*/
> > +   target_residency /= 1000;
> > +
> > /*
> >  * Cpuidle accepts exit_latency and target_residency in us.
> 
> This comment says the same thing as the one above.

Will clean this up to reflect the state of the code.

> 
> >  * Use default target_residency values if f/w does not 
> > expose it.
> >  */
> > if (flags[i] & OPAL_PM_NAP_ENABLED) {
> > +   target_residency = 100;
> 
> Hmm, the above comment says that we should only use the default value
> for target_residency if firmware hasn't provided a value. Is there a
> reason we always use the hard coded value?

Ah, good catch! I should be setting target_residency to the default
value only if it is not set by the firmware. Will fix this.


> 
> > /* Add NAP state */
> > -   strcpy(powernv_states[nr_idle_states].name, "Nap");
> > -   strcpy(powernv_states[nr_idle_states].desc, "Nap");
> > -   powernv_states[nr_idle_states].flags = 0;
> > -   powernv_stat

Re: [PATCH] Fix loading of module radeonfb on PowerMac

2016-11-02 Thread Tomi Valkeinen
On 08/10/16 15:09, Mathieu Malaterre wrote:
> When the linux kernel is build with (typical kernel ship with Debian
> installer):
> 
> CONFIG_FB_OF=y
> CONFIG_VT_HW_CONSOLE_BINDING=y
> CONFIG_FB_RADEON=m
> 
> The offb driver takes precedence over module radeonfb. It is then
> impossible to load the module, error reported is:
> 
> [   96.551486] radeonfb :00:10.0: enabling device (0006 -> 0007)
> [   96.551526] radeonfb :00:10.0: BAR 0: can't reserve [mem 
> 0x9800-0x9fff pref]
> [   96.551531] radeonfb (:00:10.0): cannot request region 0.
> [   96.551545] radeonfb: probe of :00:10.0 failed with error -16
> 
> This patch reproduce the behavior of the module radeon, so as to make it
> possible to load radeonfb when offb is first loaded.
> 
> It should be noticed that `offb_destroy` is never called which explain the
> need to skip error detection on the radeon side.

Why is that? It sounds rather bad if two drivers claim the same resources.

 Tomi



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Nicholas Piggin
On Wed, 2 Nov 2016 13:54:43 +0530
Mahesh J Salgaonkar  wrote:

> On 2016-11-02 17:57:01 Wed, Nicholas Piggin wrote:
> > On Wed, 2 Nov 2016 11:34:59 +0530
> > Mahesh Jagannath Salgaonkar  wrote:
> >   
> > > On 10/13/2016 07:47 AM, Nicholas Piggin wrote:  
> > > > This patch does a couple of things. First of all, powernv immediately
> > > > explodes when running a relocated kernel, because the system reset
> > > > exception for handling sleeps does not do correct relocated branches.
> > > > 
> > > > Secondly, the sleep handling code trashes the condition and cfar
> > > > registers, which we would like to preserve for debugging purposes (for
> > > > non-sleep case exception).
> > > > 
> > > > This patch changes the exception to use the standard format that saves
> > > > registers before any tests or branches are made. It adds the test for
> > > > idle-wakeup as an "extra" to break out of the normal exception path.
> > > > Then it branches to a relocated idle handler that calls the various
> > > > idle handling functions.
> > > > 
> > > > After this patch, POWER8 CPU simulator now boots powernv kernel that is
> > > > running at non-zero.
> > > > 
> > > > Cc: Balbir Singh 
> > > > Cc: Shreyas B. Prabhu 
> > > > Cc: Gautham R. Shenoy 
> > > > Signed-off-by: Nicholas Piggin 
> > > > ---
> > > >  arch/powerpc/include/asm/exception-64s.h | 16 ++
> > > >  arch/powerpc/kernel/exceptions-64s.S | 50 
> > > > ++--
> > > >  2 files changed, 45 insertions(+), 21 deletions(-)
> > > > 
> > > > diff --git a/arch/powerpc/include/asm/exception-64s.h 
> > > > b/arch/powerpc/include/asm/exception-64s.h
> > > > index 2e4e7d8..84d49b1 100644
> > > > --- a/arch/powerpc/include/asm/exception-64s.h
> > > > +++ b/arch/powerpc/include/asm/exception-64s.h
> > > > @@ -93,6 +93,10 @@
> > > > ld  reg,PACAKBASE(r13); /* get high part of &label */   
> > > > \
> > > > ori reg,reg,(FIXED_SYMBOL_ABS_ADDR(label))@l;
> > > > 
> > > > +#define __LOAD_HANDLER(reg, label) 
> > > > \
> > > > +   ld  reg,PACAKBASE(r13); 
> > > > \
> > > > +   ori reg,reg,(ABS_ADDR(label))@l;
> > > > +
> > > >  /* Exception register prefixes */
> > > >  #define EXC_HV H
> > > >  #define EXC_STD
> > > > @@ -208,6 +212,18 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
> > > >  #define kvmppc_interrupt kvmppc_interrupt_pr
> > > >  #endif
> > > > 
> > > > +#ifdef CONFIG_RELOCATABLE
> > > > +#define BRANCH_TO_COMMON(reg, label)   
> > > > \
> > > > +   __LOAD_HANDLER(reg, label); 
> > > > \
> > > > +   mtctr   reg;
> > > > \
> > > > +   bctr
> > > > +
> > > > +#else
> > > > +#define BRANCH_TO_COMMON(reg, label)   
> > > > \
> > > > +   b   label
> > > > +
> > > > +#endif
> > > > +
> > > >  #define __KVM_HANDLER_PROLOG(area, n)  
> > > > \
> > > > BEGIN_FTR_SECTION_NESTED(947)   
> > > > \
> > > > ld  r10,area+EX_CFAR(r13);  
> > > > \
> > > > diff --git a/arch/powerpc/kernel/exceptions-64s.S 
> > > > b/arch/powerpc/kernel/exceptions-64s.S
> > > > index 08992f8..e680e84 100644
> > > > --- a/arch/powerpc/kernel/exceptions-64s.S
> > > > +++ b/arch/powerpc/kernel/exceptions-64s.S
> > > > @@ -95,19 +95,35 @@ __start_interrupts:
> > > >  /* No virt vectors corresponding with 0x0..0x100 */
> > > >  EXC_VIRT_NONE(0x4000, 0x4100)
> > > > 
> > > > -EXC_REAL_BEGIN(system_reset, 0x100, 0x200)
> > > > -   SET_SCRATCH0(r13)
> > > > +
> > > >  #ifdef CONFIG_PPC_P7_NAP
> > > > -BEGIN_FTR_SECTION
> > > > -   /* Running native on arch 2.06 or later, check if we are
> > > > -* waking up from nap/sleep/winkle.
> > > > +   /*
> > > > +* If running native on arch 2.06 or later, check if we are 
> > > > waking up
> > > > +* from nap/sleep/winkle, and branch to idle handler.
> > > >  */
> > > > -   mfspr   r13,SPRN_SRR1
> > > > -   rlwinm. r13,r13,47-31,30,31
> > > > -   beq 9f
> > > > +#define IDLETEST(n)
> > > > \
> > > > +   BEGIN_FTR_SECTION ; 
> > > > \
> > > > +   mfspr   r10,SPRN_SRR1 ; 
> > > > \
> > > > +   rlwinm. r10,r10,47-31,30,31 ;   
> > > > \
> > > > +   beq-1f ;
> > > > \
> > > > +   cmpwi   cr3,r10,2 ; 
> > > > \
> > > > +   BRANCH_TO_COMMON(r10, system_reset_idle_common) ;   
> > > > \
> > > > +1: 
> > > > \
> > > > +   E

Re: [PATCH] powerpc/64s: relocation, register save fixes for system reset interrupt

2016-11-02 Thread Mahesh J Salgaonkar
On 2016-11-02 17:57:01 Wed, Nicholas Piggin wrote:
> On Wed, 2 Nov 2016 11:34:59 +0530
> Mahesh Jagannath Salgaonkar  wrote:
> 
> > On 10/13/2016 07:47 AM, Nicholas Piggin wrote:
> > > This patch does a couple of things. First of all, powernv immediately
> > > explodes when running a relocated kernel, because the system reset
> > > exception for handling sleeps does not do correct relocated branches.
> > > 
> > > Secondly, the sleep handling code trashes the condition and cfar
> > > registers, which we would like to preserve for debugging purposes (for
> > > non-sleep case exception).
> > > 
> > > This patch changes the exception to use the standard format that saves
> > > registers before any tests or branches are made. It adds the test for
> > > idle-wakeup as an "extra" to break out of the normal exception path.
> > > Then it branches to a relocated idle handler that calls the various
> > > idle handling functions.
> > > 
> > > After this patch, POWER8 CPU simulator now boots powernv kernel that is
> > > running at non-zero.
> > > 
> > > Cc: Balbir Singh 
> > > Cc: Shreyas B. Prabhu 
> > > Cc: Gautham R. Shenoy 
> > > Signed-off-by: Nicholas Piggin 
> > > ---
> > >  arch/powerpc/include/asm/exception-64s.h | 16 ++
> > >  arch/powerpc/kernel/exceptions-64s.S | 50 
> > > ++--
> > >  2 files changed, 45 insertions(+), 21 deletions(-)
> > > 
> > > diff --git a/arch/powerpc/include/asm/exception-64s.h 
> > > b/arch/powerpc/include/asm/exception-64s.h
> > > index 2e4e7d8..84d49b1 100644
> > > --- a/arch/powerpc/include/asm/exception-64s.h
> > > +++ b/arch/powerpc/include/asm/exception-64s.h
> > > @@ -93,6 +93,10 @@
> > >   ld  reg,PACAKBASE(r13); /* get high part of &label */   \
> > >   ori reg,reg,(FIXED_SYMBOL_ABS_ADDR(label))@l;
> > > 
> > > +#define __LOAD_HANDLER(reg, label)   
> > > \
> > > + ld  reg,PACAKBASE(r13); \
> > > + ori reg,reg,(ABS_ADDR(label))@l;
> > > +
> > >  /* Exception register prefixes */
> > >  #define EXC_HV   H
> > >  #define EXC_STD
> > > @@ -208,6 +212,18 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
> > >  #define kvmppc_interrupt kvmppc_interrupt_pr
> > >  #endif
> > > 
> > > +#ifdef CONFIG_RELOCATABLE
> > > +#define BRANCH_TO_COMMON(reg, label) 
> > > \
> > > + __LOAD_HANDLER(reg, label); \
> > > + mtctr   reg;\
> > > + bctr
> > > +
> > > +#else
> > > +#define BRANCH_TO_COMMON(reg, label) 
> > > \
> > > + b   label
> > > +
> > > +#endif
> > > +
> > >  #define __KVM_HANDLER_PROLOG(area, n)
> > > \
> > >   BEGIN_FTR_SECTION_NESTED(947)   \
> > >   ld  r10,area+EX_CFAR(r13);  \
> > > diff --git a/arch/powerpc/kernel/exceptions-64s.S 
> > > b/arch/powerpc/kernel/exceptions-64s.S
> > > index 08992f8..e680e84 100644
> > > --- a/arch/powerpc/kernel/exceptions-64s.S
> > > +++ b/arch/powerpc/kernel/exceptions-64s.S
> > > @@ -95,19 +95,35 @@ __start_interrupts:
> > >  /* No virt vectors corresponding with 0x0..0x100 */
> > >  EXC_VIRT_NONE(0x4000, 0x4100)
> > > 
> > > -EXC_REAL_BEGIN(system_reset, 0x100, 0x200)
> > > - SET_SCRATCH0(r13)
> > > +
> > >  #ifdef CONFIG_PPC_P7_NAP
> > > -BEGIN_FTR_SECTION
> > > - /* Running native on arch 2.06 or later, check if we are
> > > -  * waking up from nap/sleep/winkle.
> > > + /*
> > > +  * If running native on arch 2.06 or later, check if we are waking up
> > > +  * from nap/sleep/winkle, and branch to idle handler.
> > >*/
> > > - mfspr   r13,SPRN_SRR1
> > > - rlwinm. r13,r13,47-31,30,31
> > > - beq 9f
> > > +#define IDLETEST(n)  
> > > \
> > > + BEGIN_FTR_SECTION ; \
> > > + mfspr   r10,SPRN_SRR1 ; \
> > > + rlwinm. r10,r10,47-31,30,31 ;   \
> > > + beq-1f ;\
> > > + cmpwi   cr3,r10,2 ; \
> > > + BRANCH_TO_COMMON(r10, system_reset_idle_common) ;   \
> > > +1:   
> > > \
> > > + END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
> > > +#else
> > > +#define IDLETEST NOTEST
> > > +#endif
> > > 
> > > - cmpwi   cr3,r13,2
> > > - GET_PACA(r13)
> > > +EXC_REAL_BEGIN(system_reset, 0x100, 0x200)
> > > + SET_SCRATCH0(r13)
> > > + EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
> > > +  IDLETEST, 0x100)  
> > 
> > Very sorry for late review. On arch 2.07 and less if we wakeup from
> > winkle then last bit of HSPGR0 would be set to 1. Hence before we access
> > paca we need