Re: [PATCH v4] powerpc: Avoid code patching freed init sections

2018-09-13 Thread Christophe LEROY




Le 14/09/2018 à 03:14, Michael Neuling a écrit :

This stops us from doing code patching in init sections after they've
been freed.

In this chain:
   kvm_guest_init() ->
 kvm_use_magic_page() ->
   fault_in_pages_readable() ->
 __get_user() ->
   __get_user_nocheck() ->
 barrier_nospec();

We have a code patching location at barrier_nospec() and
kvm_guest_init() is an init function. This whole chain gets inlined,
so when we free the init section (hence kvm_guest_init()), this code
goes away and hence should no longer be patched.

We seen this as userspace memory corruption when using a memory
checker while doing partition migration testing on powervm (this
starts the code patching post migration via
/sys/kernel/mobility/migration). In theory, it could also happen when
using /sys/kernel/debug/powerpc/barrier_nospec.

cc: sta...@vger.kernel.org # 4.13+
Signed-off-by: Michael Neuling 

---
For stable I've marked this as v4.13+ since that's when we refactored
code-patching.c but it could go back even further than that. In
reality though, I think we can only hit this since the first
spectre/meltdown changes.

v4:
  Feedback from Christophe Leroy:
- init_mem_free -> init_mem_is_free
- prlog %lx -> %px

v3:
  Add init_mem_free flag to avoid potential race.
  Feedback from Christophe Leroy:
- use init_section_contains()
- change order of init test for performance
- use pr_debug()
- remove blank line

v2:
   Print when we skip an address
---
  arch/powerpc/include/asm/setup.h | 1 +
  arch/powerpc/lib/code-patching.c | 6 ++
  arch/powerpc/mm/mem.c| 2 ++
  3 files changed, 9 insertions(+)

diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
index 1a951b0046..1fffbba8d6 100644
--- a/arch/powerpc/include/asm/setup.h
+++ b/arch/powerpc/include/asm/setup.h
@@ -9,6 +9,7 @@ extern void ppc_printk_progress(char *s, unsigned short hex);
  
  extern unsigned int rtas_data;

  extern unsigned long long memory_limit;
+extern bool init_mem_is_free;
  extern unsigned long klimit;
  extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
  
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c

index 850f3b8f4d..6ae2777c22 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -28,6 +28,12 @@ static int __patch_instruction(unsigned int *exec_addr, 
unsigned int instr,
  {
int err;
  
+	/* Make sure we aren't patching a freed init section */

+   if (init_mem_is_free && init_section_contains(exec_addr, 4)) {
+   pr_debug("Skipping init section patching addr: 0x%px\n", 
exec_addr);
+   return 0;
+   }
+
__put_user_size(instr, patch_addr, 4, err);
if (err)
return err;
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 5c8530d0c6..04ccb274a6 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -63,6 +63,7 @@
  #endif
  
  unsigned long long memory_limit;

+bool init_mem_is_free;
  
  #ifdef CONFIG_HIGHMEM

  pte_t *kmap_pte;
@@ -396,6 +397,7 @@ void free_initmem(void)
  {
ppc_md.progress = ppc_printk_progress;
mark_initmem_nx();
+   init_mem_is_free = true;
free_initmem_default(POISON_FREE_INITMEM);
  }
  



Reviewed-by: Christophe Leroy 


[PATCH 3/3] powerpc: avoid -mno-sched-epilog on GCC 4.9 and newer

2018-09-13 Thread Nicholas Piggin
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Makefile | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index be47cf8a0798..07d9dce7eda6 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -165,8 +165,12 @@ CC_FLAGS_FTRACE := -pg
 ifdef CONFIG_MPROFILE_KERNEL
 CC_FLAGS_FTRACE += -mprofile-kernel
 endif
-# Work around a gcc code-gen bug with -fno-omit-frame-pointer.
-CC_FLAGS_FTRACE+= -mno-sched-epilog
+# Work around gcc code-gen bugs with -pg / -fno-omit-frame-pointer in gcc <= 
4.8
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44199
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52828
+ifneq ($(cc-name),clang)
+CC_FLAGS_FTRACE+= $(call cc-ifversion, -lt, 0409, -mno-sched-epilog)
+endif
 endif
 
 CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call 
cc-option,-mcpu=$(CONFIG_TARGET_CPU))
-- 
2.18.0



[PATCH 2/3] powerpc: consolidate -mno-sched-epilog into FTRACE flags

2018-09-13 Thread Nicholas Piggin
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Makefile| 12 ++--
 arch/powerpc/kernel/Makefile |  8 
 arch/powerpc/kernel/trace/Makefile   |  2 +-
 arch/powerpc/platforms/powermac/Makefile |  2 +-
 arch/powerpc/xmon/Makefile   |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 2ecd0976914a..be47cf8a0798 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -160,8 +160,13 @@ else
 CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64
 endif
 
+ifdef CONFIG_FUNCTION_TRACER
+CC_FLAGS_FTRACE := -pg
 ifdef CONFIG_MPROFILE_KERNEL
-   CC_FLAGS_FTRACE := -pg -mprofile-kernel
+CC_FLAGS_FTRACE += -mprofile-kernel
+endif
+# Work around a gcc code-gen bug with -fno-omit-frame-pointer.
+CC_FLAGS_FTRACE+= -mno-sched-epilog
 endif
 
 CFLAGS-$(CONFIG_TARGET_CPU_BOOL) += $(call 
cc-option,-mcpu=$(CONFIG_TARGET_CPU))
@@ -229,11 +234,6 @@ ifdef CONFIG_6xx
 KBUILD_CFLAGS  += -mcpu=powerpc
 endif
 
-# Work around a gcc code-gen bug with -fno-omit-frame-pointer.
-ifdef CONFIG_FUNCTION_TRACER
-KBUILD_CFLAGS  += -mno-sched-epilog
-endif
-
 cpu-as-$(CONFIG_4xx)   += -Wa,-m405
 cpu-as-$(CONFIG_ALTIVEC)   += $(call as-option,-Wa$(comma)-maltivec)
 cpu-as-$(CONFIG_E200)  += -Wa,-me200
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 3b66f2c19c84..1e64cfe22a83 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -22,10 +22,10 @@ CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
-CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
-CFLAGS_REMOVE_prom_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
-CFLAGS_REMOVE_btext.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
-CFLAGS_REMOVE_prom.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_cputable.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_prom_init.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_btext.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_prom.o = $(CC_FLAGS_FTRACE)
 endif
 
 obj-y  := cputable.o ptrace.o syscalls.o \
diff --git a/arch/powerpc/kernel/trace/Makefile 
b/arch/powerpc/kernel/trace/Makefile
index d22d8bafb643..d868ba42032f 100644
--- a/arch/powerpc/kernel/trace/Makefile
+++ b/arch/powerpc/kernel/trace/Makefile
@@ -7,7 +7,7 @@ subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror
 
 ifdef CONFIG_FUNCTION_TRACER
 # do not trace tracer code
-CFLAGS_REMOVE_ftrace.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
 endif
 
 obj32-$(CONFIG_FUNCTION_TRACER)+= ftrace_32.o
diff --git a/arch/powerpc/platforms/powermac/Makefile 
b/arch/powerpc/platforms/powermac/Makefile
index f2839eed0f89..561a67d65e4d 100644
--- a/arch/powerpc/platforms/powermac/Makefile
+++ b/arch/powerpc/platforms/powermac/Makefile
@@ -3,7 +3,7 @@ CFLAGS_bootx_init.o += -fPIC
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
-CFLAGS_REMOVE_bootx_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_bootx_init.o = $(CC_FLAGS_FTRACE)
 endif
 
 obj-y  += pic.o setup.o time.o feature.o pci.o \
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index 1bc3abb237cd..93cc1f1b8b61 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -8,7 +8,7 @@ UBSAN_SANITIZE := n
 
 # Disable ftrace for the entire directory
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst -mno-sched-epilog,,$(subst 
$(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS)))
+KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
 ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
 
-- 
2.18.0



[PATCH 1/3] powerpc: remove old GCC version checks

2018-09-13 Thread Nicholas Piggin
GCC 4.6 is the minimum supported now.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Makefile | 31 ++-
 1 file changed, 2 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 11a1acba164a..2ecd0976914a 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -404,36 +404,9 @@ archprepare: checkbin
 # to stdout and these checks are run even on install targets.
 TOUT   := .tmp_gas_check
 
-# Check gcc and binutils versions:
-# - gcc-3.4 and binutils-2.14 are a fatal combination
-# - Require gcc 4.0 or above on 64-bit
-# - gcc-4.2.0 has issues compiling modules on 64-bit
+# Check toolchain versions:
+# - gcc-4.6 is the minimum kernel-wide version so nothing required.
 checkbin:
-   @if test "$(cc-name)" != "clang" \
-   && test "$(cc-version)" = "0304" ; then \
-   if ! /bin/echo mftb 5 | $(AS) -v -mppc -many -o $(TOUT) 
>/dev/null 2>&1 ; then \
-   echo -n '*** ${VERSION}.${PATCHLEVEL} kernels no longer 
build '; \
-   echo 'correctly with gcc-3.4 and your version of 
binutils.'; \
-   echo '*** Please upgrade your binutils or downgrade 
your gcc'; \
-   false; \
-   fi ; \
-   fi
-   @if test "$(cc-name)" != "clang" \
-   && test "$(cc-version)" -lt "0400" \
-   && test "x${CONFIG_PPC64}" = "xy" ; then \
-echo -n "Sorry, GCC v4.0 or above is required to build " ; \
-echo "the 64-bit powerpc kernel." ; \
-false ; \
-fi
-   @if test "$(cc-name)" != "clang" \
-   && test "$(cc-fullversion)" = "040200" \
-   && test "x${CONFIG_MODULES}${CONFIG_PPC64}" = "xyy" ; then \
-   echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \
-   echo 'kernel with modules enabled.' ; \
-   echo -n '*** Please use a different GCC version or ' ; \
-   echo 'disable kernel modules' ; \
-   false ; \
-   fi
@if test "x${CONFIG_CPU_LITTLE_ENDIAN}" = "xy" \
&& $(LD) --version | head -1 | grep ' 2\.24$$' >/dev/null ; then \
echo -n '*** binutils 2.24 miscompiles weak symbols ' ; \
-- 
2.18.0



[PATCH 0/3] -mno-sched-epilog removal

2018-09-13 Thread Nicholas Piggin
This removes -mno-sched-epilog on clang and gcc 4.9 and newer. Not
tested with old compilers though.

Nicholas Piggin (3):
  powerpc: remove old GCC version checks
  powerpc: consolidate -mno-sched-epilog into FTRACE flags
  powerpc: avoid -mno-sched-epilog on GCC 4.9 and newer

 arch/powerpc/Makefile| 47 ++--
 arch/powerpc/kernel/Makefile |  8 ++--
 arch/powerpc/kernel/trace/Makefile   |  2 +-
 arch/powerpc/platforms/powermac/Makefile |  2 +-
 arch/powerpc/xmon/Makefile   |  2 +-
 5 files changed, 19 insertions(+), 42 deletions(-)

-- 
2.18.0



Re: [PATCH v2 5/5] powerpc: Remove -mno-sched-epilog

2018-09-13 Thread Nicholas Piggin
On Fri, 14 Sep 2018 13:36:49 +0930
Joel Stanley  wrote:

> This effectively reverts 7563dc645853 ("powerpc: Work around gcc's
> -fno-omit-frame-pointer bug"), a workaround for a bug in GCC 4.1.3 when
> building 2.6.26 kernel.
> 
> The flag is not supported by clang, but reading the history of the
> bug[1] suggests it is no longer required by supported GCC versions, with
> GCC 4.6 now being the minimum.
> 
> [1] https://bugzilla.kernel.org/show_bug.cgi?id=11414
> Signed-off-by: Joel Stanley 
> ---
> Last time this was proposed there was an issue reported:
> 
>  https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-September/121214.html
> 
> If some machines still have an issue, we could instead wrap this in a
> flag check.

I don't think we can remove it completely because up to at least 4.6
maybe 4.8 has problems.

I have a few patches lying around I started looking at this... I'll
send them.

Thanks,
Nick


Re: [PATCH v4] powerpc: Avoid code patching freed init sections

2018-09-13 Thread Nicholas Piggin
On Fri, 14 Sep 2018 11:14:11 +1000
Michael Neuling  wrote:

> This stops us from doing code patching in init sections after they've
> been freed.
> 
> In this chain:
>   kvm_guest_init() ->
> kvm_use_magic_page() ->
>   fault_in_pages_readable() ->
>__get_user() ->
>  __get_user_nocheck() ->
>barrier_nospec();
> 
> We have a code patching location at barrier_nospec() and
> kvm_guest_init() is an init function. This whole chain gets inlined,
> so when we free the init section (hence kvm_guest_init()), this code
> goes away and hence should no longer be patched.
> 
> We seen this as userspace memory corruption when using a memory
> checker while doing partition migration testing on powervm (this
> starts the code patching post migration via
> /sys/kernel/mobility/migration). In theory, it could also happen when
> using /sys/kernel/debug/powerpc/barrier_nospec.
> 
> cc: sta...@vger.kernel.org # 4.13+
> Signed-off-by: Michael Neuling 
> 
> ---
> For stable I've marked this as v4.13+ since that's when we refactored
> code-patching.c but it could go back even further than that. In
> reality though, I think we can only hit this since the first
> spectre/meltdown changes.
> 
> v4:
>  Feedback from Christophe Leroy:
>- init_mem_free -> init_mem_is_free
>- prlog %lx -> %px
> 
> v3:
>  Add init_mem_free flag to avoid potential race.
>  Feedback from Christophe Leroy:
>- use init_section_contains()
>- change order of init test for performance
>- use pr_debug()
>- remove blank line
> 
> v2:
>   Print when we skip an address
> ---
>  arch/powerpc/include/asm/setup.h | 1 +
>  arch/powerpc/lib/code-patching.c | 6 ++
>  arch/powerpc/mm/mem.c| 2 ++
>  3 files changed, 9 insertions(+)
> 
> diff --git a/arch/powerpc/include/asm/setup.h 
> b/arch/powerpc/include/asm/setup.h
> index 1a951b0046..1fffbba8d6 100644
> --- a/arch/powerpc/include/asm/setup.h
> +++ b/arch/powerpc/include/asm/setup.h
> @@ -9,6 +9,7 @@ extern void ppc_printk_progress(char *s, unsigned short hex);
>  
>  extern unsigned int rtas_data;
>  extern unsigned long long memory_limit;
> +extern bool init_mem_is_free;
>  extern unsigned long klimit;
>  extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
>  
> diff --git a/arch/powerpc/lib/code-patching.c 
> b/arch/powerpc/lib/code-patching.c
> index 850f3b8f4d..6ae2777c22 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -28,6 +28,12 @@ static int __patch_instruction(unsigned int *exec_addr, 
> unsigned int instr,
>  {
>   int err;
>  
> + /* Make sure we aren't patching a freed init section */
> + if (init_mem_is_free && init_section_contains(exec_addr, 4)) {
> + pr_debug("Skipping init section patching addr: 0x%px\n", 
> exec_addr);
> + return 0;
> + }

What we should do is a whitelist, make sure it's only patching the
sections we want it to.

That's a bigger job when you consider modules and things too though,
so this looks good for now. Thanks,

Reviewed-by: Nicholas Piggin 


[PATCH v2 5/5] powerpc: Remove -mno-sched-epilog

2018-09-13 Thread Joel Stanley
This effectively reverts 7563dc645853 ("powerpc: Work around gcc's
-fno-omit-frame-pointer bug"), a workaround for a bug in GCC 4.1.3 when
building 2.6.26 kernel.

The flag is not supported by clang, but reading the history of the
bug[1] suggests it is no longer required by supported GCC versions, with
GCC 4.6 now being the minimum.

[1] https://bugzilla.kernel.org/show_bug.cgi?id=11414
Signed-off-by: Joel Stanley 
---
Last time this was proposed there was an issue reported:

 https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-September/121214.html

If some machines still have an issue, we could instead wrap this in a
flag check.
---
 arch/powerpc/Makefile| 5 -
 arch/powerpc/kernel/Makefile | 8 
 arch/powerpc/kernel/trace/Makefile   | 2 +-
 arch/powerpc/platforms/powermac/Makefile | 2 +-
 arch/powerpc/xmon/Makefile   | 2 +-
 5 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index a70639482053..ef8eca40ffef 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -229,11 +229,6 @@ ifdef CONFIG_6xx
 KBUILD_CFLAGS  += -mcpu=powerpc
 endif
 
-# Work around a gcc code-gen bug with -fno-omit-frame-pointer.
-ifdef CONFIG_FUNCTION_TRACER
-KBUILD_CFLAGS  += -mno-sched-epilog
-endif
-
 cpu-as-$(CONFIG_4xx)   += -Wa,-m405
 cpu-as-$(CONFIG_ALTIVEC)   += $(call as-option,-Wa$(comma)-maltivec)
 cpu-as-$(CONFIG_E200)  += -Wa,-me200
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 3b66f2c19c84..1e64cfe22a83 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -22,10 +22,10 @@ CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
-CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
-CFLAGS_REMOVE_prom_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
-CFLAGS_REMOVE_btext.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
-CFLAGS_REMOVE_prom.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_cputable.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_prom_init.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_btext.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_prom.o = $(CC_FLAGS_FTRACE)
 endif
 
 obj-y  := cputable.o ptrace.o syscalls.o \
diff --git a/arch/powerpc/kernel/trace/Makefile 
b/arch/powerpc/kernel/trace/Makefile
index d22d8bafb643..d868ba42032f 100644
--- a/arch/powerpc/kernel/trace/Makefile
+++ b/arch/powerpc/kernel/trace/Makefile
@@ -7,7 +7,7 @@ subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror
 
 ifdef CONFIG_FUNCTION_TRACER
 # do not trace tracer code
-CFLAGS_REMOVE_ftrace.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
 endif
 
 obj32-$(CONFIG_FUNCTION_TRACER)+= ftrace_32.o
diff --git a/arch/powerpc/platforms/powermac/Makefile 
b/arch/powerpc/platforms/powermac/Makefile
index f2839eed0f89..561a67d65e4d 100644
--- a/arch/powerpc/platforms/powermac/Makefile
+++ b/arch/powerpc/platforms/powermac/Makefile
@@ -3,7 +3,7 @@ CFLAGS_bootx_init.o += -fPIC
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
-CFLAGS_REMOVE_bootx_init.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_bootx_init.o = $(CC_FLAGS_FTRACE)
 endif
 
 obj-y  += pic.o setup.o time.o feature.o pci.o \
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index 1bc3abb237cd..93cc1f1b8b61 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -8,7 +8,7 @@ UBSAN_SANITIZE := n
 
 # Disable ftrace for the entire directory
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
-KBUILD_CFLAGS = $(subst -mno-sched-epilog,,$(subst 
$(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS)))
+KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
 
 ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
 
-- 
2.17.1



[PATCH v2 4/5] powerpc: Fix duplicate const clang warning in user access code

2018-09-13 Thread Joel Stanley
From: Anton Blanchard 

This re-applies b91c1e3e7a6f which was reverted in f2ca80905929
d466f6c5cac1 f84ed59a612d (powerpc/sparse: Constify the address pointer
...").

We see a large number of duplicate const errors in the user access
code when building with llvm/clang:

  include/linux/pagemap.h:576:8: warning: duplicate 'const' declaration 
specifier
  [-Wduplicate-decl-specifier]
ret = __get_user(c, uaddr);

The problem is we are doing const __typeof__(*(ptr)), which will hit the
warning if ptr is marked const.

Removing const does not seem to have any effect on GCC code generation.

Signed-off-by: Anton Blanchard 
Signed-off-by: Joel Stanley 
---
If we don't want to apply this, other options are suppressing the
warning, or wait for a fix to land in clang
(https://github.com/ClangBuiltLinux/linux/issues/52).
---
 arch/powerpc/include/asm/uaccess.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/uaccess.h 
b/arch/powerpc/include/asm/uaccess.h
index bac225bb7f64..15bea9a0f260 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -260,7 +260,7 @@ do {
\
 ({ \
long __gu_err;  \
__long_type(*(ptr)) __gu_val;   \
-   const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
+   __typeof__(*(ptr)) __user *__gu_addr = (ptr);   \
__chk_user_ptr(ptr);\
if (!is_kernel_addr((unsigned long)__gu_addr))  \
might_fault();  \
@@ -274,7 +274,7 @@ do {
\
 ({ \
long __gu_err = -EFAULT;\
__long_type(*(ptr)) __gu_val = 0;   \
-   const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
+   __typeof__(*(ptr)) __user *__gu_addr = (ptr);   \
might_fault();  \
if (access_ok(VERIFY_READ, __gu_addr, (size))) {\
barrier_nospec();   \
@@ -288,7 +288,7 @@ do {
\
 ({ \
long __gu_err;  \
__long_type(*(ptr)) __gu_val;   \
-   const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
+   __typeof__(*(ptr)) __user *__gu_addr = (ptr);   \
__chk_user_ptr(ptr);\
barrier_nospec();   \
__get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
-- 
2.17.1



[PATCH v2 3/5] powerpc/boot: Ensure _zimage_start is a weak symbol

2018-09-13 Thread Joel Stanley
When building with clang crt0's _zimage_start is not marked weak, which
breaks the build when linking the kernel image:

 $ objdump -t arch/powerpc/boot/crt0.o |grep _zimage_start$
 0058 g   .text   _zimage_start

 ld: arch/powerpc/boot/wrapper.a(crt0.o): in function '_zimage_start':
 (.text+0x58): multiple definition of '_zimage_start';
 arch/powerpc/boot/pseries-head.o:(.text+0x0): first defined here

Clang requires the .weak directive to appear after the symbol is
declared. The binutils manual says:

 This directive sets the weak attribute on the comma separated list of
 symbol names. If the symbols do not already exist, they will be
 created.

So it appears this is different with clang. The only reference I could
see for this was an OpenBSD mailing list post[1].

Changing it to be after the declaration fixes building with Clang, and
still works with GCC.

 $ objdump -t arch/powerpc/boot/crt0.o |grep _zimage_start$
 0058  w  .text  _zimage_start

Reported to clang as https://bugs.llvm.org/show_bug.cgi?id=38921

[1] https://groups.google.com/forum/#!topic/fa.openbsd.tech/PAgKKen2YCY

Signed-off-by: Joel Stanley 
---
v2: Add comment explaining this is a workaround for clang. I have also
opened a clang bug to see if they plan on changing behaviour
---
 arch/powerpc/boot/crt0.S | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/boot/crt0.S b/arch/powerpc/boot/crt0.S
index e453e011d7e7..4e32bd251b99 100644
--- a/arch/powerpc/boot/crt0.S
+++ b/arch/powerpc/boot/crt0.S
@@ -47,8 +47,10 @@ p_end:   .long   _end
 p_pstack:  .long   _platform_stack_top
 #endif
 
-   .weak   _zimage_start
.globl  _zimage_start
+   /* Clang appears to require the .weak directive to be after the symbol
+* is defined. See https://bugs.llvm.org/show_bug.cgi?id=38921  */
+   .weak   _zimage_start
 _zimage_start:
.globl  _zimage_start_lib
 _zimage_start_lib:
-- 
2.17.1



[PATCH v2 2/5] powerpc/boot: Fix crt0.S syntax for clang

2018-09-13 Thread Joel Stanley
Clang's assembler does not like the syntax of the cmpdi:

 arch/powerpc/boot/crt0.S:168:22: error: unexpected modifier on variable 
reference
 cmpdi   12,RELACOUNT@l
  ^
 arch/powerpc/boot/crt0.S:168:11: error: unknown operand
 cmpdi   12,RELACOUNT@l
   ^
Enclosing RELACOUNT in () makes it is happy. Tested with GCC 8 and Clang
8 (trunk).

Reported to clang as https://bugs.llvm.org/show_bug.cgi?id=38945

Signed-off-by: Joel Stanley 
---
v2: Fix for !powerpc64 too, add bug link to commit message
---
 arch/powerpc/boot/crt0.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/boot/crt0.S b/arch/powerpc/boot/crt0.S
index dcf2f15e6797..e453e011d7e7 100644
--- a/arch/powerpc/boot/crt0.S
+++ b/arch/powerpc/boot/crt0.S
@@ -80,7 +80,7 @@ p_base:   mflrr10 /* r10 now points to 
runtime addr of p_base */
lwz r9,4(r12)   /* get RELA pointer in r9 */
b   12f
 11:addis   r8,r8,(-RELACOUNT)@ha
-   cmpwi   r8,RELACOUNT@l
+   cmpwi   r8,(RELACOUNT)@l
bne 12f
lwz r0,4(r12)   /* get RELACOUNT value in r0 */
 12:addir12,r12,8
@@ -165,7 +165,7 @@ p_base: mflrr10 /* r10 now points to 
runtime addr of p_base */
ld  r13,8(r11)   /* get RELA pointer in r13 */
b   11f
 10:addis   r12,r12,(-RELACOUNT)@ha
-   cmpdi   r12,RELACOUNT@l
+   cmpdi   r12,(RELACOUNT)@l
bne 11f
ld  r8,8(r11)   /* get RELACOUNT value in r8 */
 11:addir11,r11,16
-- 
2.17.1



[PATCH v2 1/5] powerpc/Makefiles: Fix clang/llvm build

2018-09-13 Thread Joel Stanley
From: Anton Blanchard 

Commit 15a3204d24a3 ("powerpc/64s: Set assembler machine type to POWER4")
passes -mpower4 to the assembler. We have more recent instructions in our
assembly files, but gas permits them. The clang/llvm integrated assembler
is more strict, and we get a build failure.

Fix this by calling the assembler with -mcpu=power8 if as supports it,
else fall back to power4.

Suggested-by: Nicholas Piggin 
Signed-off-by: Anton Blanchard 
Signed-off-by: Joel Stanley 
---
 arch/powerpc/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 11a1acba164a..a70639482053 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -238,7 +238,7 @@ cpu-as-$(CONFIG_4xx)+= -Wa,-m405
 cpu-as-$(CONFIG_ALTIVEC)   += $(call as-option,-Wa$(comma)-maltivec)
 cpu-as-$(CONFIG_E200)  += -Wa,-me200
 cpu-as-$(CONFIG_E500)  += -Wa,-me500
-cpu-as-$(CONFIG_PPC_BOOK3S_64) += -Wa,-mpower4
+cpu-as-$(CONFIG_PPC_BOOK3S_64) += $(call 
as-option,-Wa$(comma)-mpower8,-Wa$(comma)-mpower4)
 cpu-as-$(CONFIG_PPC_E500MC)+= $(call as-option,-Wa$(comma)-me500mc)
 
 KBUILD_AFLAGS += $(cpu-as-y)
-- 
2.17.1



[PATCH v2 0/5] powerpc: Clang build fixes

2018-09-13 Thread Joel Stanley
v2 rolls up all of the fixes I have into the one series, and adds a few
more fixes.

With a one patch[1] on top of clang master I can build and boot a
powernv kernel. Note that we can't build altivec code using clang
yet[2], hence disabling MD_RAID456.

$ make ARCH=powerpc powernv_defconfig
$ ./scripts/config -d BTRFS_FS -d MD_RAID456
$ make CC=clang-8 CLANG_TRIPLE=powerpc64le-linux-gnu -j128

The build is very noisy as the ftrace recordmcount build step is not
picking up -Qunused-arguments.

$ qemu-system-ppc64 -M powernv -m 3G -nographic -kernel zImage.epapr \
 -L ~/skiboot/ -initrd ~/rootfs.cpio.xz

Linux version 4.19.0-rc3-5-g7f51dcdecc6b (joel@ozrom3) (clang version 8.0.0 
(trunk 342199)) #5 SMP Fri Sep 14 13:28:57 ACST 2018

I have discovered Nick D's clangBuiltLinux issue tracker[3] and will be
updating that as we find and fix issues.

[1] https://reviews.llvm.org/D50965
[2] https://bugs.llvm.org/show_bug.cgi?id=38887
[3] https://github.com/clangBuiltLinux/linux/issues

Anton Blanchard (2):
  powerpc/Makefiles: Fix clang/llvm build
  powerpc: Fix duplicate const clang warning in user access code

Joel Stanley (3):
  powerpc/boot: Fix crt0.S syntax for clang
  powerpc/boot: Ensure _zimage_start is a weak symbol
  powerpc: Remove -mno-sched-epilog

 arch/powerpc/Makefile| 7 +--
 arch/powerpc/boot/crt0.S | 8 +---
 arch/powerpc/include/asm/uaccess.h   | 6 +++---
 arch/powerpc/kernel/Makefile | 8 
 arch/powerpc/kernel/trace/Makefile   | 2 +-
 arch/powerpc/platforms/powermac/Makefile | 2 +-
 arch/powerpc/xmon/Makefile   | 2 +-
 7 files changed, 16 insertions(+), 19 deletions(-)

-- 
2.17.1



[PATCH] PowerPC/VDSO: Correct call frame information

2018-09-13 Thread Alan Modra
Call Frame Information is used by gdb for back-traces and inserting
breakpoints on function return for the "finish" command.  This failed
when inside __kernel_clock_gettime.  More concerning than difficulty
debugging is that CFI is also used by stack frame unwinding code to
implement exceptions.  If you have an app that needs to handle
asynchronous exceptions for some reason, and you are unlucky enough to
get one inside the VDSO time functions, your app will crash.

What's wrong:  There is control flow in __kernel_clock_gettime that
reaches label 99 without saving lr in r12.  CFI info however is
interpreted by the unwinder without reference to control flow: It's a
simple matter of "Execute all the CFI opcodes up to the current
address".  That means the unwinder thinks r12 contains the return
address at label 99.  Disabuse it of that notion by resetting CFI for
the return address at label 99.

Note that the ".cfi_restore lr" could have gone anywhere from the
"mtlr r12" a few instructions earlier to the instruction at label 99.
I put the CFI as late as possible, because in general that's best
practice (and if possible grouped with other CFI in order to reduce
the number of CFI opcodes executed when unwinding).  Using r12 as the
return address is perfectly fine after the "mtlr r12" since r12 on
that code path still contains the return address.

__get_datapage also has a CFI error.  That function temporarily saves
lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
use of r0 means the CFI at that point isn't correct, as r0 no longer
contains the return address.  Fix that too.

Signed-off-by: Alan Modra 
Tested-by: Reza Arbab 

diff --git a/arch/powerpc/kernel/vdso32/datapage.S 
b/arch/powerpc/kernel/vdso32/datapage.S
index 3745113fcc65..2a7eb5452aba 100644
--- a/arch/powerpc/kernel/vdso32/datapage.S
+++ b/arch/powerpc/kernel/vdso32/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
mtlrr0
addir3, r3, __kernel_datapage_offset-data_page_branch
lwz r0,0(r3)
+  .cfi_restore lr
add r3,r0,r3
blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S 
b/arch/powerpc/kernel/vdso32/gettimeofday.S
index 769c2624e0a6..1e0bc5955a40 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 */
 99:
li  r0,__NR_clock_gettime
+  .cfi_restore lr
sc
blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/datapage.S 
b/arch/powerpc/kernel/vdso64/datapage.S
index abf17feffe40..bf9668691511 100644
--- a/arch/powerpc/kernel/vdso64/datapage.S
+++ b/arch/powerpc/kernel/vdso64/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
mtlrr0
addir3, r3, __kernel_datapage_offset-data_page_branch
lwz r0,0(r3)
+  .cfi_restore lr
add r3,r0,r3
blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S 
b/arch/powerpc/kernel/vdso64/gettimeofday.S
index c002adcc694c..a4ed9edfd5f0 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -169,6 +169,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 */
 99:
li  r0,__NR_clock_gettime
+  .cfi_restore lr
sc
blr
   .cfi_endproc

-- 
Alan Modra
Australia Development Lab, IBM


Re: [PATCH] Correct PowerPC VDSO call frame info

2018-09-13 Thread Reza Arbab

On Fri, Sep 14, 2018 at 08:57:04AM +0930, Alan Modra wrote:

There is control flow in __kernel_clock_gettime that reaches label 99
without saving lr in r12.  CFI info however is interpreted by the
unwinder without reference to control flow: It's a simple matter of
"Execute all the CFI opcodes up to the current address".  That means
the unwinder thinks r12 contains the return address at label 99.
Disabuse it of that notion by resetting CFI for the return address at
label 99.


Thanks for this! It looks like v2 will just be a commit log change, so 
feel free to carry over my


Tested-by: Reza Arbab 

--
Reza Arbab



Re: [PATCH 1/2] powerpc/boot: Fix crt0.S syntax for clang

2018-09-13 Thread Joel Stanley
On Tue, 11 Sep 2018 at 21:02, Segher Boessenkool
 wrote:
>
> On Mon, Sep 10, 2018 at 06:57:13PM +1000, Joel Stanley wrote:
> > Clang's assembler does not like the syntax of the cmpdi:
> >
> >  arch/powerpc/boot/crt0.S:168:22: error: unexpected modifier on variable 
> > reference
> >  cmpdi   12,RELACOUNT@l
> >   ^
> >  arch/powerpc/boot/crt0.S:168:11: error: unknown operand
> >  cmpdi   12,RELACOUNT@l
> >^
> > Enclosing RELACOUNT in () makes it is happy. Tested with GCC 8 and Clang
> > 8 (trunk).
>
> Is clang going to fix this?  You also might want to add a comment that
> this is a workaround for that broken assembler.

I am not sure that we need a comment, it doesn't look too out of place
compared to the other uses of wrapping symbols in ().

I did open a bug against clang though in the hope that they can fix
the behaviour:

 https://bugs.llvm.org/show_bug.cgi?id=38945

Cheers,

Joel


[PATCH v4] powerpc/64s: reimplement book3s idle code in C

2018-09-13 Thread Nicholas Piggin
Reimplement Book3S idle code in C, moving POWER7/8/9 implementation
speific HV idle code to the powernv platform code.

Book3S assembly stubs are kept in common code and used only to save
the stack frame and non-volatile GPRs before executing architected
idle instructions, and restoring the stack and reloading GPRs then
returning to C after waking from idle.

The complex logic dealing with threads and subcores, locking, SPRs,
HMIs, timebase resync, etc., is all done in C which makes it more
maintainable.

This is not a strict translation to C code, there are some
significant differences:

- Idle wakeup no longer uses the ->cpu_restore call to reinit SPRs,
  but saves and restores them itself.

- The optimisation where EC=ESL=0 idle modes did not have to save GPRs
  or change MSR is restored, because it's now simple to do. ESL=1
  sleeps that do not lose GPRs can use this optimization too.

- KVM secondary entry and cede is now more of a call/return style
  rather than branchy. nap_state_lost is not required because KVM
  always returns via NVGPR restoring path.

Reviewed-by: Gautham R. Shenoy 
Signed-off-by: Nicholas Piggin 

- P9 restores some of the PMU SPRs, but not others, and P8 only zeroes
  them. There are improvmets to be made to SPR save restore policies and
  documentation, but this first pass tries to keep things as they were.

Left to do:
- Test actual POWER7 hardware.

- KVM could use more review, it's pretty tricky. Not sure if what
  I'm doing with the emergency stack is kosher. But it runs pretty fine
  here with a POWER8 SMP+SMT guest. Possible to streamline
  KVM cede code now that idle function saves nv gprs for us?

Since RFC v1:
- Now tested and working with POWER9 hash and radix.
- KVM support added. This took a bit of work to untangle and might
  still have some issues, but POWER9 seems to work including hash on
  radix with dependent threads mode.
- This snowballed a bit because of KVM and other details making it
  not feasible to leave POWER7/8 code alone. That's only half done
  at the moment.
- So far this trades about 800 lines of asm for 500 of C. With POWER7/8
  support done it might be another hundred or so lines of C.

Since RFC v2:
- Fixed deep state SLB reloading
- Now tested and working with POWER8.
- Accounted for most feedback.

Since RFC v3:
- Rebased to powerpc merge + idle state bugfix
- Split SLB flush/restore code out and shared with MCE code (pseries
  MCE patches can also use).
- More testing on POWER8 including KVM with secondaries.
- Performance testing looks good. EC=ESL=0 is about 5% faster, other
  stop states look a little faster too.
- Adjusted SPR saving to handler POWER7, haven't tested it.

Since submission v1:
- More review comments from Gautham.
- Rename isa3_ to isa300_ prefix.
- Tinkered with some comments, copyright notice, changelog.
- Cede and regular idle do not go via KVM secondary wakeup code path,
  so hwthread_state stores and barriers can be simplified, and some
  KVM code paths simplified a little.

Since v2:
- Rebase, SLB reload patch has been merged.
- More testing. Tested machine check idle wakeup path with mambo stepping
  through instructions.

Since v3:
- Build fixes caught by CI
---
 arch/powerpc/include/asm/cpuidle.h   |   19 +-
 arch/powerpc/include/asm/paca.h  |   38 +-
 arch/powerpc/include/asm/processor.h |9 +-
 arch/powerpc/include/asm/reg.h   |7 +-
 arch/powerpc/kernel/asm-offsets.c|   18 -
 arch/powerpc/kernel/dt_cpu_ftrs.c|   21 +-
 arch/powerpc/kernel/exceptions-64s.S |   17 +-
 arch/powerpc/kernel/idle_book3s.S| 1012 +++---
 arch/powerpc/kernel/setup-common.c   |4 +-
 arch/powerpc/kvm/book3s_hv_rmhandlers.S  |   86 +-
 arch/powerpc/platforms/powernv/idle.c|  828 ++
 arch/powerpc/platforms/powernv/subcore.c |2 +-
 arch/powerpc/xmon/xmon.c |   24 +-
 13 files changed, 880 insertions(+), 1205 deletions(-)

diff --git a/arch/powerpc/include/asm/cpuidle.h 
b/arch/powerpc/include/asm/cpuidle.h
index 43e5f31fe64d..9844b3ded187 100644
--- a/arch/powerpc/include/asm/cpuidle.h
+++ b/arch/powerpc/include/asm/cpuidle.h
@@ -27,10 +27,11 @@
  * the THREAD_WINKLE_BITS are set, which indicate which threads have not
  * yet woken from the winkle state.
  */
-#define PNV_CORE_IDLE_LOCK_BIT 0x1000
+#define NR_PNV_CORE_IDLE_LOCK_BIT  28
+#define PNV_CORE_IDLE_LOCK_BIT (1ULL << 
NR_PNV_CORE_IDLE_LOCK_BIT)
 
+#define PNV_CORE_IDLE_WINKLE_COUNT_SHIFT   16
 #define PNV_CORE_IDLE_WINKLE_COUNT 0x0001
-#define PNV_CORE_IDLE_WINKLE_COUNT_ALL_BIT 0x0008
 #define PNV_CORE_IDLE_WINKLE_COUNT_BITS0x000F
 #define PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT 8
 #define PNV_CORE_IDLE_THREAD_WINKLE_BITS   0xFF00
@@ -68,16 +69,6 @@
 #define ERR_DEEP_STATE_ESL_MISMATCH-2
 
 #ifndef __ASSEMBLY__
-/* Additional SPRs that need to be 

[PATCH v4] powerpc: Avoid code patching freed init sections

2018-09-13 Thread Michael Neuling
This stops us from doing code patching in init sections after they've
been freed.

In this chain:
  kvm_guest_init() ->
kvm_use_magic_page() ->
  fault_in_pages_readable() ->
 __get_user() ->
   __get_user_nocheck() ->
 barrier_nospec();

We have a code patching location at barrier_nospec() and
kvm_guest_init() is an init function. This whole chain gets inlined,
so when we free the init section (hence kvm_guest_init()), this code
goes away and hence should no longer be patched.

We seen this as userspace memory corruption when using a memory
checker while doing partition migration testing on powervm (this
starts the code patching post migration via
/sys/kernel/mobility/migration). In theory, it could also happen when
using /sys/kernel/debug/powerpc/barrier_nospec.

cc: sta...@vger.kernel.org # 4.13+
Signed-off-by: Michael Neuling 

---
For stable I've marked this as v4.13+ since that's when we refactored
code-patching.c but it could go back even further than that. In
reality though, I think we can only hit this since the first
spectre/meltdown changes.

v4:
 Feedback from Christophe Leroy:
   - init_mem_free -> init_mem_is_free
   - prlog %lx -> %px

v3:
 Add init_mem_free flag to avoid potential race.
 Feedback from Christophe Leroy:
   - use init_section_contains()
   - change order of init test for performance
   - use pr_debug()
   - remove blank line

v2:
  Print when we skip an address
---
 arch/powerpc/include/asm/setup.h | 1 +
 arch/powerpc/lib/code-patching.c | 6 ++
 arch/powerpc/mm/mem.c| 2 ++
 3 files changed, 9 insertions(+)

diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
index 1a951b0046..1fffbba8d6 100644
--- a/arch/powerpc/include/asm/setup.h
+++ b/arch/powerpc/include/asm/setup.h
@@ -9,6 +9,7 @@ extern void ppc_printk_progress(char *s, unsigned short hex);
 
 extern unsigned int rtas_data;
 extern unsigned long long memory_limit;
+extern bool init_mem_is_free;
 extern unsigned long klimit;
 extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
 
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 850f3b8f4d..6ae2777c22 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -28,6 +28,12 @@ static int __patch_instruction(unsigned int *exec_addr, 
unsigned int instr,
 {
int err;
 
+   /* Make sure we aren't patching a freed init section */
+   if (init_mem_is_free && init_section_contains(exec_addr, 4)) {
+   pr_debug("Skipping init section patching addr: 0x%px\n", 
exec_addr);
+   return 0;
+   }
+
__put_user_size(instr, patch_addr, 4, err);
if (err)
return err;
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 5c8530d0c6..04ccb274a6 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -63,6 +63,7 @@
 #endif
 
 unsigned long long memory_limit;
+bool init_mem_is_free;
 
 #ifdef CONFIG_HIGHMEM
 pte_t *kmap_pte;
@@ -396,6 +397,7 @@ void free_initmem(void)
 {
ppc_md.progress = ppc_printk_progress;
mark_initmem_nx();
+   init_mem_is_free = true;
free_initmem_default(POISON_FREE_INITMEM);
 }
 
-- 
2.17.1



Re: [PATCH] MAINTAINERS: Add PPC contacts for PCI core error handling

2018-09-13 Thread Sam Bobroff
On Thu, Sep 13, 2018 at 12:26:55PM +1000, Russell Currey wrote:
> On Wed, 2018-09-12 at 11:58 -0500, Bjorn Helgaas wrote:
> > On Wed, Sep 12, 2018 at 11:55:26AM -0500, Bjorn Helgaas wrote:
> > > From: Bjorn Helgaas 
> > > 
> > > The original PCI error recovery functionality was for the powerpc-specific
> > > IBM EEH feature.  PCIe subsequently added some similar features, including
> > > AER and DPC, that can be used on any architecture.
> > > 
> > > We want the generic PCI core error handling support to work with all of
> > > these features.  Driver error recovery callbacks should be independent of
> > > which feature the platform provides.
> > > 
> > > Add the generic PCI core error recovery files to the powerpc EEH
> > > MAINTAINERS entry so the powerpc folks will be copied on changes to the
> > > generic PCI error handling strategy.
> > 
> > I really want to make sure the powerpc folks are plugged into any PCI core
> > error handling discussions.  Please let me know if there's a better way
> > than this patch, or if there are other people who should be added.
> 
> I think this patch is definitely a good idea.
> 
> Alongside this (whether you want to include it in your patch or not, Bjorn),
> Sam Bobroff should replace myself as maintainer.  He's been very active in 
> fixing,
> reworking and reviewing in EEH land and will probably do a better job of 
> keeping
> his finger on the pulse of the generic PCI error handling code than I did.
> 
> - Russell

That's fine with me. You can add me or let me know if I should send a
patch.

Sam.

> 
> > 
> > > Signed-off-by: Bjorn Helgaas 
> > > ---
> > >  MAINTAINERS |4 
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > index 7e10ba65bfe4..d6699597fd89 100644
> > > --- a/MAINTAINERS
> > > +++ b/MAINTAINERS
> > > @@ -11202,6 +11202,10 @@ PCI ENHANCED ERROR HANDLING (EEH) FOR POWERPC
> > >  M:   Russell Currey 
> > >  L:   linuxppc-dev@lists.ozlabs.org
> > >  S:   Supported
> > > +F:   Documentation/PCI/pci-error-recovery.txt
> > > +F:   drivers/pci/pcie/aer.c
> > > +F:   drivers/pci/pcie/dpc.c
> > > +F:   drivers/pci/pcie/err.c
> > >  F:   Documentation/powerpc/eeh-pci-error-recovery.txt
> > >  F:   arch/powerpc/kernel/eeh*.c
> > >  F:   arch/powerpc/platforms/*/eeh*.c
> > > 
> 


signature.asc
Description: PGP signature


Re: [PATCH] Correct PowerPC VDSO call frame info

2018-09-13 Thread Michael Neuling
Alan,

Thanks for the patch... A few minor comments...

> Re: [PATCH] Correct PowerPC VDSO call frame info

Our convention is to add powerpc: to the start. ie

  [PATCH] powerpc: Correct VDSO call frame info

or even: 

  [PATCH] powerpc/vdso: Correct call frame info


On Fri, 2018-09-14 at 08:57 +0930, Alan Modra wrote:
> There is control flow in __kernel_clock_gettime that reaches label 99
> without saving lr in r12.  CFI info however is interpreted by the
> unwinder without reference to control flow: It's a simple matter of
> "Execute all the CFI opcodes up to the current address".  That means
> the unwinder thinks r12 contains the return address at label 99.
> Disabuse it of that notion by resetting CFI for the return address at
> label 99.

Can you expand on CFI == Call Frame Information in the commit message.  Not a
common term for us mere kernel developers?

> Note that the ".cfi_restore lr" could have gone anywhere from the
> "mtlr r12" a few instructions earlier to the instruction at label 99.
> I put the CFI as late as possible, because in general that's best
> practice (and if possible grouped with other CFI in order to reduce
> the number of CFI opcodes executed when unwinding).  Using r12 as the
> return address is perfectly fine after the "mtlr r12" since r12 on
> that code path still contains the return address.
> 
> __get_datapage also has a CFI error.  That function temporarily saves
> lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
> use of r0 means the CFI at that point isn't correct, as r0 no longer
> contains the return address.  Fix that too.

Can you describe the problem this fixes at a high level?  ie This fixes doing a
stack unwind with gdb when in __kernel_clock_gettime.

Mikey

> Signed-off-by: Alan Modra 
> 
> diff --git a/arch/powerpc/kernel/vdso32/datapage.S
> b/arch/powerpc/kernel/vdso32/datapage.S
> index 3745113fcc65..2a7eb5452aba 100644
> --- a/arch/powerpc/kernel/vdso32/datapage.S
> +++ b/arch/powerpc/kernel/vdso32/datapage.S
> @@ -37,6 +37,7 @@ data_page_branch:
>   mtlrr0
>   addir3, r3, __kernel_datapage_offset-data_page_branch
>   lwz r0,0(r3)
> +  .cfi_restore lr
>   add r3,r0,r3
>   blr
>.cfi_endproc
> diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S
> b/arch/powerpc/kernel/vdso32/gettimeofday.S
> index 769c2624e0a6..1e0bc5955a40 100644
> --- a/arch/powerpc/kernel/vdso32/gettimeofday.S
> +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
> @@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
>*/
>  99:
>   li  r0,__NR_clock_gettime
> +  .cfi_restore lr
>   sc
>   blr
>.cfi_endproc
> diff --git a/arch/powerpc/kernel/vdso64/datapage.S
> b/arch/powerpc/kernel/vdso64/datapage.S
> index abf17feffe40..bf9668691511 100644
> --- a/arch/powerpc/kernel/vdso64/datapage.S
> +++ b/arch/powerpc/kernel/vdso64/datapage.S
> @@ -37,6 +37,7 @@ data_page_branch:
>   mtlrr0
>   addir3, r3, __kernel_datapage_offset-data_page_branch
>   lwz r0,0(r3)
> +  .cfi_restore lr
>   add r3,r0,r3
>   blr
>.cfi_endproc
> diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S
> b/arch/powerpc/kernel/vdso64/gettimeofday.S
> index c002adcc694c..a4ed9edfd5f0 100644
> --- a/arch/powerpc/kernel/vdso64/gettimeofday.S
> +++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
> @@ -169,6 +169,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
>*/
>  99:
>   li  r0,__NR_clock_gettime
> +  .cfi_restore lr
>   sc
>   blr
>.cfi_endproc
> 


[PATCH] Correct PowerPC VDSO call frame info

2018-09-13 Thread Alan Modra
There is control flow in __kernel_clock_gettime that reaches label 99
without saving lr in r12.  CFI info however is interpreted by the
unwinder without reference to control flow: It's a simple matter of
"Execute all the CFI opcodes up to the current address".  That means
the unwinder thinks r12 contains the return address at label 99.
Disabuse it of that notion by resetting CFI for the return address at
label 99.

Note that the ".cfi_restore lr" could have gone anywhere from the
"mtlr r12" a few instructions earlier to the instruction at label 99.
I put the CFI as late as possible, because in general that's best
practice (and if possible grouped with other CFI in order to reduce
the number of CFI opcodes executed when unwinding).  Using r12 as the
return address is perfectly fine after the "mtlr r12" since r12 on
that code path still contains the return address.

__get_datapage also has a CFI error.  That function temporarily saves
lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
use of r0 means the CFI at that point isn't correct, as r0 no longer
contains the return address.  Fix that too.

Signed-off-by: Alan Modra 

diff --git a/arch/powerpc/kernel/vdso32/datapage.S 
b/arch/powerpc/kernel/vdso32/datapage.S
index 3745113fcc65..2a7eb5452aba 100644
--- a/arch/powerpc/kernel/vdso32/datapage.S
+++ b/arch/powerpc/kernel/vdso32/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
mtlrr0
addir3, r3, __kernel_datapage_offset-data_page_branch
lwz r0,0(r3)
+  .cfi_restore lr
add r3,r0,r3
blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S 
b/arch/powerpc/kernel/vdso32/gettimeofday.S
index 769c2624e0a6..1e0bc5955a40 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 */
 99:
li  r0,__NR_clock_gettime
+  .cfi_restore lr
sc
blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/datapage.S 
b/arch/powerpc/kernel/vdso64/datapage.S
index abf17feffe40..bf9668691511 100644
--- a/arch/powerpc/kernel/vdso64/datapage.S
+++ b/arch/powerpc/kernel/vdso64/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
mtlrr0
addir3, r3, __kernel_datapage_offset-data_page_branch
lwz r0,0(r3)
+  .cfi_restore lr
add r3,r0,r3
blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S 
b/arch/powerpc/kernel/vdso64/gettimeofday.S
index c002adcc694c..a4ed9edfd5f0 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -169,6 +169,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 */
 99:
li  r0,__NR_clock_gettime
+  .cfi_restore lr
sc
blr
   .cfi_endproc

-- 
Alan Modra
Australia Development Lab, IBM


[PATCH 3/3] scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4

2018-09-13 Thread Rob Herring
Major changes are I2C and SPI bus checks, YAML output format (for
future validation), some new libfdt functions, and more libfdt
validation of dtbs.

The YAML addition adds an optional dependency on libyaml. pkg-config is
used to test for it and pkg-config became a kconfig dependency in 4.18.

This adds the following commits from upstream:

c86da84d30e4 Add support for YAML encoded output
361b5e7d8067 Make type_marker_length helper public
bfbfab047e45 pylibfdt: Add a means to add and delete notes
9005f4108e7c pylibfdt: Allow delprop() to return errors
b94c056b137e Make valgrind optional
fd06c54d4711 tests: Better testing of dtc -I fs mode
c3f50c9a86d9 tests: Allow dtbs_equal_unordered to ignore mem reserves
0ac9fdee37c7 dtc: trivial '-I fs -O dts' test
0fd1c8c783f3 pylibfdt: fdt_get_mem_rsv returns 2 uint64_t values
04853cad18f4 pylibfdt: Don't incorrectly / unnecessarily override uint64_t 
typemap
9619c8619c37 Kill bogus TYPE_BLOB marker type
ac68ff92ae20 parser: add TYPE_STRING marker to path references
90a190eb04d9 checks: add SPI bus checks
53a1bd546905 checks: add I2C bus checks
88f18909db73 dtc: Bump version to v1.4.7
85bce8b2f06d tests: Correction to vg_prepare_blob()
57f7f9e7bc7c tests: Don't call memcmp() with NULL arguments
c12b2b0c20eb libfdt: fdt_address_cells() and fdt_size_cells()
3fe0eeda0b7f livetree: Set phandle properties type to uint32
853649acceba pylibfdt: Support the sequential-write interface
9b0e4fe26093 tests: Improve fdt_resize() tests
1087504bb3e8 libfdt: Add necessary header padding in fdt_create()
c72fa777e613 libfdt: Copy the struct region in fdt_resize()
32b9c6130762 Preserve datatype markers when emitting dts format
6dcb8ba408ec libfdt: Add helpers for accessing unaligned words
42607f21d43e tests: Fix incorrect check name 'prop_name_chars'
9d78c33bf8a1 tests: fix grep for checks error messages
b770f3d1c13f pylibfdt: Support setting the name of a node
2f0d07e678e0 pylibfdt: Add functions to set and get properties as strings
354d3dc55939 pylibfdt: Update the bytearray size with pack()
3c374d46acce pylibfdt: Allow reading integer values from properties
49d32ce40bb4 pylibfdt: Use an unsigned type for fdt32_t
481246a0c13a pylibfdt: Avoid accessing the internal _fdt member in tests
9aafa33d99ed pylibfdt: Add functions to update properties
5a598671fdbf pylibfdt: Support device-tree creation/expansion
483e170625e1 pylibfdt: Add support for reading the memory reserve map
29bb05aa4200 pylibfdt: Add support for the rest of the header functions
582a7159a5d0 pylibfdt: Add support for fdt_next_node()
f0f8c9169819 pylibfdt: Reorder functions to match libfdt.h
64a69d123935 pylibfdt: Return string instead of bytearray from getprop()
4d09a83420df fdtput: Add documentation
e617cbe1bd67 fdtget: Add documentation
180a93924014 Use  format specifiers in a bunch of places we should
b9af3b396576 scripts/dtc: Fixed format mismatch in fprintf
4b8fcc3d015c libfdt: Add fdt_check_full() function
c14223fb2292 tests: Use valgrind client requests for better checking
5b67d2b955a3 tests: Better handling of valgrind errors saving blobs
e2556aaeb506 tests: Remove unused #define
fb9c6abddaa8 Use size_t for blob lengths in utilfdt_read*
0112fda03bf6 libfdt: Add fdt_header_size()
6473a21d8bfe Consolidate utilfdt_read_len() variants
d5db5382c5e5 libfdt: Safer access to memory reservations
719d582e98ec libfdt: Propagate name errors in fdt_getprop_by_offset()
70166d62a27f libfdt: Safer access to strings section
eb890c0f77dc libfdt: Make fdt_check_header() more thorough
899d6fad93f3 libfdt: Improve sequential write state checking
04b5b4062ccd libfdt: Clean up header checking functions
44d3efedc816 Preserve datatype information when parsing dts
f0be81bd8de0 Make Property a subclass of bytearray
24b1f3f064d4 pylibfdt: Add a method to access the device tree directly

Signed-off-by: Rob Herring 
---
As usual, this generated from a script copying from upstream dtc. The 
only part here that's not is dtc/Makefile.


 scripts/dtc/Makefile |   7 +
 scripts/dtc/Makefile.dtc |   4 +
 scripts/dtc/checks.c | 143 
 scripts/dtc/data.c   |   4 +-
 scripts/dtc/dtc-parser.y |  16 +-
 scripts/dtc/dtc.c|  11 ++
 scripts/dtc/dtc.h|  13 ++
 scripts/dtc/flattree.c   |   2 +-
 scripts/dtc/libfdt/fdt.c |  81 -
 scripts/dtc/libfdt/fdt_addresses.c   |  35 ++--
 scripts/dtc/libfdt/fdt_overlay.c |   6 +-
 scripts/dtc/libfdt/fdt_ro.c  | 199 ++---
 scripts/dtc/libfdt/fdt_rw.c  |  28 +--
 scripts/dtc/libfdt/fdt_sw.c  | 109 +---
 scripts/dtc/libfdt/libfdt.h  |  76 -
 scripts/dtc/libfdt/libfdt_env.h  |   1 +
 scripts/dtc/libfdt/libfdt_internal.h |   5 +-
 scripts/dtc/livetree.c   |  12 +-
 scripts/dtc/treesource.c | 225 ++--
 scripts/dtc/util.c   |  23 +--
 

[PATCH 2/3] scripts/dtc: Add yamltree.c to dtc sources

2018-09-13 Thread Rob Herring
dtc has a new source file, yamltree.c, that needs to be copied when
syncing dtc sources.

Signed-off-by: Rob Herring 
---
 scripts/dtc/update-dtc-source.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/dtc/update-dtc-source.sh b/scripts/dtc/update-dtc-source.sh
index 1a009fd195d0..7dd29a0362b8 100755
--- a/scripts/dtc/update-dtc-source.sh
+++ b/scripts/dtc/update-dtc-source.sh
@@ -32,7 +32,7 @@ DTC_UPSTREAM_PATH=`pwd`/../dtc
 DTC_LINUX_PATH=`pwd`/scripts/dtc
 
 DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c 
srcpos.c \
-   srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \
+   srcpos.h treesource.c util.c util.h version_gen.h yamltree.c 
Makefile.dtc \
dtc-lexer.l dtc-parser.y"
 LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
-- 
2.17.1



[PATCH 1/3] libfdt: Ensure INT_MAX is defined in libfdt_env.h

2018-09-13 Thread Rob Herring
The next update of libfdt has a new dependency on INT_MAX. Update the
instances of libfdt_env.h in the kernel to either include the necessary
header with the definition or define it locally.

Cc: Russell King 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Rob Herring 
---
 arch/arm/boot/compressed/libfdt_env.h | 2 ++
 arch/powerpc/boot/libfdt_env.h| 2 ++
 include/linux/libfdt_env.h| 1 +
 3 files changed, 5 insertions(+)

diff --git a/arch/arm/boot/compressed/libfdt_env.h 
b/arch/arm/boot/compressed/libfdt_env.h
index 07437816e098..b36c0289a308 100644
--- a/arch/arm/boot/compressed/libfdt_env.h
+++ b/arch/arm/boot/compressed/libfdt_env.h
@@ -6,6 +6,8 @@
 #include 
 #include 
 
+#define INT_MAX((int)(~0U>>1))
+
 typedef __be16 fdt16_t;
 typedef __be32 fdt32_t;
 typedef __be64 fdt64_t;
diff --git a/arch/powerpc/boot/libfdt_env.h b/arch/powerpc/boot/libfdt_env.h
index 2a0c8b1bf147..2abc8e83b95e 100644
--- a/arch/powerpc/boot/libfdt_env.h
+++ b/arch/powerpc/boot/libfdt_env.h
@@ -5,6 +5,8 @@
 #include 
 #include 
 
+#define INT_MAX((int)(~0U>>1))
+
 #include "of.h"
 
 typedef unsigned long uintptr_t;
diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
index c6ac1fe7ec68..edb0f0c30904 100644
--- a/include/linux/libfdt_env.h
+++ b/include/linux/libfdt_env.h
@@ -2,6 +2,7 @@
 #ifndef LIBFDT_ENV_H
 #define LIBFDT_ENV_H
 
+#include   /* For INT_MAX */
 #include 
 
 #include 
-- 
2.17.1



Re: [PATCH] watchdog: mpc8xxx: provide boot status

2018-09-13 Thread Guenter Roeck
On Thu, Sep 13, 2018 at 08:07:21AM +, Christophe Leroy wrote:
> mpc8xxx watchdog driver supports the following platforms:
> - mpc8xx
> - mpc83xx
> - mpc86xx
> 
> Those three platforms have a 32 bits register which provides the
> reason of the last boot, including whether it was caused by the
> watchdog.
> 
> mpc8xx: Register RSR, bit SWRS (bit 3)
> mpc83xx: Register RSR, bit SWRS (bit 28)
> mpc86xx: Register RSTRSCR, bit WDT_RR (bit 11)
> 
> This patch maps the register as defined in the device tree and updates
> wdt.bootstatus based on the value of the watchdog related bit. Then
> the information can be retrieved via the WDIOC_GETBOOTSTATUS ioctl.
> 
> Hereunder is an exemple of devicetree for mpc8xx,

example

> the Reset Status Register being at offset 0x288:
> 
>   WDT: watchdog@0 {
>   compatible = "fsl,mpc823-wdt";
>   reg = <0x0 0x10 0x288 0x4>;

This isn't documented anywhere, and no one wil know how to use it.
So far that was grandfathered in, but with more complex usage
it really needs to be documented.

>   };
> 
> On the mpc83xx, RSR is at offset 0x910
> On the mpc86xx, RSTRSCR is at offset 0xe0094
> 
> Suggested-by: Radu Rendec 
> Tested-by: Christophe Leroy  # On mpc885
> Signed-off-by: Christophe Leroy 
> ---
>  drivers/watchdog/mpc8xxx_wdt.c | 22 ++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
> index aca2d6323f8a..2951a485a6b4 100644
> --- a/drivers/watchdog/mpc8xxx_wdt.c
> +++ b/drivers/watchdog/mpc8xxx_wdt.c
> @@ -49,10 +49,12 @@ struct mpc8xxx_wdt {
>  struct mpc8xxx_wdt_type {
>   int prescaler;
>   bool hw_enabled;
> + u32 rsr_mask;
>  };
>  
>  struct mpc8xxx_wdt_ddata {
>   struct mpc8xxx_wdt __iomem *base;
> + u32 __iomem *rsr;
>   struct watchdog_device wdd;
>   spinlock_t lock;
>   u16 swtc;
> @@ -137,6 +139,7 @@ static int mpc8xxx_wdt_probe(struct platform_device 
> *ofdev)
>   struct mpc8xxx_wdt_ddata *ddata;
>   u32 freq = fsl_get_sys_freq();
>   bool enabled;
> + struct device *dev = >dev;

If you introduce this variable, please use it everywhere
in the function.

>  
>   wdt_type = of_device_get_match_data(>dev);
>   if (!wdt_type)
> @@ -160,6 +163,22 @@ static int mpc8xxx_wdt_probe(struct platform_device 
> *ofdev)
>   return -ENODEV;
>   }
>  
> + res = platform_get_resource(ofdev, IORESOURCE_MEM, 1);
> + ddata->rsr = devm_ioremap_resource(dev, res);
> + if (IS_ERR(ddata->rsr)) {
> + dev_info(dev, "Could not map reset status register");

Please, no such message. It would start to show up everywhere unless
devicetree files are updated, which likely won't happen. Then we get
bogged down by people asking where this message suddenly comes from.

> + } else {
> + u32 rsr_v = in_be32(ddata->rsr);
> + bool status = rsr_v & wdt_type->rsr_mask;
> +
> + ddata->wdd.bootstatus = status ? WDIOF_CARDRESET : 0;
> +  /* clear reset status bits related to watchdog time */
> + out_be32(ddata->rsr, wdt_type->rsr_mask);
> +
> + dev_info(dev, "Last boot was %s by watchdog (RSR = 0x%8.8x)\n",
> +  status ? "caused" : "not caused", rsr_v);

The hex value of RSR may be interesting for developers, but not for users.
Please drop.

Also, "caused" is redundant. Add it to the base string and add "not "
when needed.

> + }
> +
>   spin_lock_init(>lock);
>  
>   ddata->wdd.info = _wdt_info,
> @@ -216,6 +235,7 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
>   .compatible = "mpc83xx_wdt",
>   .data = &(struct mpc8xxx_wdt_type) {
>   .prescaler = 0x1,
> + .rsr_mask = BIT(3), /* RSR Bit 28 */

The comment is quite useless. How does BIT(3) match RSR bit 28 ?
I am sure it is because the HW manual counts bits the other way,
but here it is just confusing and thus doesn't add value unless
you provide additional context.

>   },
>   },
>   {
> @@ -223,6 +243,7 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
>   .data = &(struct mpc8xxx_wdt_type) {
>   .prescaler = 0x1,
>   .hw_enabled = true,
> + .rsr_mask = BIT(20), /* RSTRSCR Bit 11 */
>   },
>   },
>   {
> @@ -230,6 +251,7 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
>   .data = &(struct mpc8xxx_wdt_type) {
>   .prescaler = 0x800,
>   .hw_enabled = true,
> + .rsr_mask = BIT(28), /* RSR Bit 3 */
>   },
>   },
>   {},
> -- 
> 2.13.3
> 


Re: [PATCH v2 02/24] drivers/video/fbdev: use ioremap_wc/wt() instead of __ioremap()

2018-09-13 Thread Bartlomiej Zolnierkiewicz


On 09/12/2018 05:58 PM, Christophe Leroy wrote:
> _PAGE_NO_CACHE is a platform specific flag. In addition, this flag
> is misleading because one would think it requests a noncached page
> whereas a noncached page is _PAGE_NO_CACHE | _PAGE_GUARDED
> 
> _PAGE_NO_CACHE alone means write combined noncached page, so lets
> use ioremap_wc() instead.
> 
> _PAGE_WRITETHRU is also platform specific flag. Use ioremap_wt()
> instead.
> 
> Signed-off-by: Christophe Leroy 

After reading patch #1 this one LGTM.

Acked-by: Bartlomiej Zolnierkiewicz 

> ---
>  drivers/video/fbdev/chipsfb.c|  3 +--
>  drivers/video/fbdev/controlfb.c  |  5 +
>  drivers/video/fbdev/platinumfb.c |  5 +
>  drivers/video/fbdev/valkyriefb.c | 12 ++--
>  4 files changed, 9 insertions(+), 16 deletions(-)

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R Institute Poland
Samsung Electronics


Re: [PATCH v3 6/9] kbuild: consolidate Devicetree dtb build rules

2018-09-13 Thread Geert Uytterhoeven
Hi Yamada-san,

On Wed, Sep 12, 2018 at 3:02 AM Masahiro Yamada
 wrote:
> 2018-09-12 0:40 GMT+09:00 Rob Herring :
> > On Mon, Sep 10, 2018 at 10:04 AM Rob Herring  wrote:
> >> There is nothing arch specific about building dtb files other than their
> >> location under /arch/*/boot/dts/. Keeping each arch aligned is a pain.
> >> The dependencies and supported targets are all slightly different.
> >> Also, a cross-compiler for each arch is needed, but really the host
> >> compiler preprocessor is perfectly fine for building dtbs. Move the
> >> build rules to a common location and remove the arch specific ones. This
> >> is done in a single step to avoid warnings about overriding rules.
> >>
> >> The build dependencies had been a mixture of 'scripts' and/or 'prepare'.
> >> These pull in several dependencies some of which need a target compiler
> >> (specifically devicetable-offsets.h) and aren't needed to build dtbs.
> >> All that is really needed is dtc, so adjust the dependencies to only be
> >> dtc.
> >>
> >> This change enables support 'dtbs_install' on some arches which were
> >> missing the target.
> >
> > [...]
> >
> >> @@ -1215,6 +1215,33 @@ kselftest-merge:
> >> $(srctree)/tools/testing/selftests/*/config
> >> +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
> >>
> >> +# 
> >> ---
> >> +# Devicetree files
> >> +
> >> +ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
> >> +dtstree := arch/$(SRCARCH)/boot/dts
> >> +endif
> >> +
> >> +ifdef CONFIG_OF_EARLY_FLATTREE
> >
> > This can be true when dtstree is unset. So this line should be this
> > instead to fix the 0-day reported error:
> >
> > ifneq ($(dtstree),)
> >
> >> +
> >> +%.dtb : scripts_dtc
> >> +   $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
> >> +
> >> +PHONY += dtbs dtbs_install
> >> +dtbs: scripts_dtc
> >> +   $(Q)$(MAKE) $(build)=$(dtstree)
> >> +
> >> +dtbs_install: dtbs
> >> +   $(Q)$(MAKE) $(dtbinst)=$(dtstree)
> >> +
> >> +all: dtbs
> >> +
> >> +endif
>
>
> Ah, right.
> Even x86 can enable OF and OF_UNITTEST.
>
>
>
> Another solution might be,
> guard it by 'depends on ARCH_SUPPORTS_OF'.
>
>
>
> This is actually what ACPI does.
>
> menuconfig ACPI
> bool "ACPI (Advanced Configuration and Power Interface) Support"
> depends on ARCH_SUPPORTS_ACPI
>  ...

ACPI is a real platform feature, as it depends on firmware.

CONFIG_OF can be enabled, and DT overlays can be loaded, on any platform,
even if it has ACPI ;-)

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH 4.18 124/197] powerpc/platforms/85xx: fix t1042rdb_diu.c build errors & warning

2018-09-13 Thread Greg Kroah-Hartman
4.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Randy Dunlap 

[ Upstream commit f5daf77a55ef0e695cc90c440ed6503073ac5e07 ]

Fix build errors and warnings in t1042rdb_diu.c by adding header files
and MODULE_LICENSE().

../arch/powerpc/platforms/85xx/t1042rdb_diu.c:152:1: warning: data definition 
has no type or storage class
 early_initcall(t1042rdb_diu_init);
../arch/powerpc/platforms/85xx/t1042rdb_diu.c:152:1: error: type defaults to 
'int' in declaration of 'early_initcall' [-Werror=implicit-int]
../arch/powerpc/platforms/85xx/t1042rdb_diu.c:152:1: warning: parameter names 
(without types) in function declaration

and
WARNING: modpost: missing MODULE_LICENSE() in 
arch/powerpc/platforms/85xx/t1042rdb_diu.o

Signed-off-by: Randy Dunlap 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Scott Wood 
Cc: Kumar Gala 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Michael Ellerman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/powerpc/platforms/85xx/t1042rdb_diu.c |4 
 1 file changed, 4 insertions(+)

--- a/arch/powerpc/platforms/85xx/t1042rdb_diu.c
+++ b/arch/powerpc/platforms/85xx/t1042rdb_diu.c
@@ -9,8 +9,10 @@
  * option) any later version.
  */
 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -150,3 +152,5 @@ static int __init t1042rdb_diu_init(void
 }
 
 early_initcall(t1042rdb_diu_init);
+
+MODULE_LICENSE("GPL");




[PATCH 4.14 074/115] powerpc/platforms/85xx: fix t1042rdb_diu.c build errors & warning

2018-09-13 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Randy Dunlap 

[ Upstream commit f5daf77a55ef0e695cc90c440ed6503073ac5e07 ]

Fix build errors and warnings in t1042rdb_diu.c by adding header files
and MODULE_LICENSE().

../arch/powerpc/platforms/85xx/t1042rdb_diu.c:152:1: warning: data definition 
has no type or storage class
 early_initcall(t1042rdb_diu_init);
../arch/powerpc/platforms/85xx/t1042rdb_diu.c:152:1: error: type defaults to 
'int' in declaration of 'early_initcall' [-Werror=implicit-int]
../arch/powerpc/platforms/85xx/t1042rdb_diu.c:152:1: warning: parameter names 
(without types) in function declaration

and
WARNING: modpost: missing MODULE_LICENSE() in 
arch/powerpc/platforms/85xx/t1042rdb_diu.o

Signed-off-by: Randy Dunlap 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Scott Wood 
Cc: Kumar Gala 
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Michael Ellerman 
Signed-off-by: Sasha Levin 
Signed-off-by: Greg Kroah-Hartman 
---
 arch/powerpc/platforms/85xx/t1042rdb_diu.c |4 
 1 file changed, 4 insertions(+)

--- a/arch/powerpc/platforms/85xx/t1042rdb_diu.c
+++ b/arch/powerpc/platforms/85xx/t1042rdb_diu.c
@@ -9,8 +9,10 @@
  * option) any later version.
  */
 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -150,3 +152,5 @@ static int __init t1042rdb_diu_init(void
 }
 
 early_initcall(t1042rdb_diu_init);
+
+MODULE_LICENSE("GPL");




Re: [PATCH v2 02/24] drivers/video/fbdev: use ioremap_wc/wt() instead of __ioremap()

2018-09-13 Thread Daniel Vetter
On Wed, Sep 12, 2018 at 03:58:17PM +, Christophe Leroy wrote:
> _PAGE_NO_CACHE is a platform specific flag. In addition, this flag
> is misleading because one would think it requests a noncached page
> whereas a noncached page is _PAGE_NO_CACHE | _PAGE_GUARDED
> 
> _PAGE_NO_CACHE alone means write combined noncached page, so lets
> use ioremap_wc() instead.
> 
> _PAGE_WRITETHRU is also platform specific flag. Use ioremap_wt()
> instead.
> 
> Signed-off-by: Christophe Leroy 

I wondered why this all showed up in my gfx inbox, then spotted this patch
here.

I trust you way more on the _PAGE_ flags than me, but this looks
reasonable.

Acked-by: Daniel Vetter 

> ---
>  drivers/video/fbdev/chipsfb.c|  3 +--
>  drivers/video/fbdev/controlfb.c  |  5 +
>  drivers/video/fbdev/platinumfb.c |  5 +
>  drivers/video/fbdev/valkyriefb.c | 12 ++--
>  4 files changed, 9 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/video/fbdev/chipsfb.c b/drivers/video/fbdev/chipsfb.c
> index f103665cad43..40182ed85648 100644
> --- a/drivers/video/fbdev/chipsfb.c
> +++ b/drivers/video/fbdev/chipsfb.c
> @@ -27,7 +27,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  
>  #ifdef CONFIG_PMAC_BACKLIGHT
>  #include 
> @@ -401,7 +400,7 @@ static int chipsfb_pci_init(struct pci_dev *dp, const 
> struct pci_device_id *ent)
>  #endif /* CONFIG_PMAC_BACKLIGHT */
>  
>  #ifdef CONFIG_PPC
> - p->screen_base = __ioremap(addr, 0x20, _PAGE_NO_CACHE);
> + p->screen_base = ioremap_wc(addr, 0x20);
>  #else
>   p->screen_base = ioremap(addr, 0x20);
>  #endif
> diff --git a/drivers/video/fbdev/controlfb.c b/drivers/video/fbdev/controlfb.c
> index 8d14b29aafea..9cb0ef7ac29e 100644
> --- a/drivers/video/fbdev/controlfb.c
> +++ b/drivers/video/fbdev/controlfb.c
> @@ -48,9 +48,7 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
> -#include 
>  #include 
>  
>  #include "macmodes.h"
> @@ -715,8 +713,7 @@ static int __init control_of_init(struct device_node *dp)
>   goto error_out;
>   }
>   /* map at most 8MB for the frame buffer */
> - p->frame_buffer = __ioremap(p->frame_buffer_phys, 0x80,
> - _PAGE_WRITETHRU);
> + p->frame_buffer = ioremap_wt(p->frame_buffer_phys, 0x80);
>  
>   if (!p->control_regs_phys ||
>   !request_mem_region(p->control_regs_phys, p->control_regs_size,
> diff --git a/drivers/video/fbdev/platinumfb.c 
> b/drivers/video/fbdev/platinumfb.c
> index 377d3399a3ad..bf6b7fb83cf4 100644
> --- a/drivers/video/fbdev/platinumfb.c
> +++ b/drivers/video/fbdev/platinumfb.c
> @@ -32,9 +32,7 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
> -#include 
>  
>  #include "macmodes.h"
>  #include "platinumfb.h"
> @@ -577,8 +575,7 @@ static int platinumfb_probe(struct platform_device* odev)
>  
>   /* frame buffer - map only 4MB */
>   pinfo->frame_buffer_phys = pinfo->rsrc_fb.start;
> - pinfo->frame_buffer = __ioremap(pinfo->rsrc_fb.start, 0x40,
> - _PAGE_WRITETHRU);
> + pinfo->frame_buffer = ioremap_wt(pinfo->rsrc_fb.start, 0x40);
>   pinfo->base_frame_buffer = pinfo->frame_buffer;
>  
>   /* registers */
> diff --git a/drivers/video/fbdev/valkyriefb.c 
> b/drivers/video/fbdev/valkyriefb.c
> index 275fb98236d3..d51c3a8009cb 100644
> --- a/drivers/video/fbdev/valkyriefb.c
> +++ b/drivers/video/fbdev/valkyriefb.c
> @@ -54,13 +54,11 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #ifdef CONFIG_MAC
>  #include 
>  #else
>  #include 
>  #endif
> -#include 
>  
>  #include "macmodes.h"
>  #include "valkyriefb.h"
> @@ -318,7 +316,7 @@ static void __init valkyrie_choose_mode(struct 
> fb_info_valkyrie *p)
>  int __init valkyriefb_init(void)
>  {
>   struct fb_info_valkyrie *p;
> - unsigned long frame_buffer_phys, cmap_regs_phys, flags;
> + unsigned long frame_buffer_phys, cmap_regs_phys;
>   int err;
>   char *option = NULL;
>  
> @@ -337,7 +335,6 @@ int __init valkyriefb_init(void)
>   /* Hardcoded addresses... welcome to 68k Macintosh country :-) */
>   frame_buffer_phys = 0xf900;
>   cmap_regs_phys = 0x50f24000;
> - flags = IOMAP_NOCACHE_SER; /* IOMAP_WRITETHROUGH?? */
>  #else /* ppc (!CONFIG_MAC) */
>   {
>   struct device_node *dp;
> @@ -354,7 +351,6 @@ int __init valkyriefb_init(void)
>  
>   frame_buffer_phys = r.start;
>   cmap_regs_phys = r.start + 0x304000;
> - flags = _PAGE_WRITETHRU;
>   }
>  #endif /* ppc (!CONFIG_MAC) */
>  
> @@ -369,7 +365,11 @@ int __init valkyriefb_init(void)
>   }
>   p->total_vram = 0x10;
>   p->frame_buffer_phys = frame_buffer_phys;
> - p->frame_buffer = __ioremap(frame_buffer_phys, p->total_vram, flags);
> +#ifdef CONFIG_MAC
> + p->frame_buffer = ioremap_nocache(frame_buffer_phys, p->total_vram);
> +#else
> + p->frame_buffer = 

[PATCH 2/2] s390/pci: handle function enumeration after sriov enablement

2018-09-13 Thread Sebastian Ott
Implement add_vfs|del_vfs callbacks as empty functions. VF
creation will be triggered by the hotplug code.

Signed-off-by: Sebastian Ott 
---
 arch/s390/pci/pci.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 9381d5d98156..2ba2cbfaa091 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -785,6 +785,15 @@ static void zpci_remove_bus(struct pci_bus *bus)
kfree(zdev);
 }
 
+static int zpci_add_vfs(struct pci_dev *pdev, u16 num_vfs)
+{
+   return 0;
+}
+
+static void zpci_del_vfs(struct pci_dev *pdev)
+{
+}
+
 static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
struct pci_ops *ops, void *sysdata, struct list_head *resources)
 {
@@ -801,6 +810,8 @@ static struct pci_bus *pci_scan_root_bus(struct device 
*parent, int bus,
bridge->busnr = bus;
bridge->ops = ops;
bridge->remove_bus = zpci_remove_bus;
+   bridge->add_vfs = zpci_add_vfs;
+   bridge->del_vfs = zpci_del_vfs;
 
error = pci_scan_root_bus_bridge(bridge);
if (error < 0)
-- 
2.13.4



[PATCH 1/2] pci: provide add_vfs/del_vfs callbacks

2018-09-13 Thread Sebastian Ott
Provide callbacks that can be used by PCI host bridge implementations
to override the behavior of the generic vf detection and device
creation code.

Signed-off-by: Sebastian Ott 
---
 drivers/pci/iov.c   | 51 +++
 include/linux/pci.h |  2 ++
 2 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 0f04ae648cf1..b2ddfe30c5d8 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -251,6 +251,41 @@ int __weak pcibios_sriov_disable(struct pci_dev *pdev)
return 0;
 }
 
+static int pcibios_sriov_add_vfs(struct pci_dev *dev, u16 num_vfs)
+{
+   struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus);
+   unsigned int i;
+   int rc;
+
+   if (bridge->add_vfs)
+   return bridge->add_vfs(dev, num_vfs);
+
+   for (i = 0; i < num_vfs; i++) {
+   rc = pci_iov_add_virtfn(dev, i);
+   if (rc)
+   goto failed;
+   }
+   return 0;
+failed:
+   while (i--)
+   pci_iov_remove_virtfn(dev, i);
+
+   return rc;
+}
+
+static void pcibios_sriov_del_vfs(struct pci_dev *dev)
+{
+   struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus);
+   struct pci_sriov *iov = dev->sriov;
+   int i;
+
+   if (bridge->del_vfs)
+   return bridge->del_vfs(dev);
+
+   for (i = 0; i < iov->num_VFs; i++)
+   pci_iov_remove_virtfn(dev, i);
+}
+
 static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
 {
int rc;
@@ -336,21 +371,15 @@ static int sriov_enable(struct pci_dev *dev, int 
nr_virtfn)
msleep(100);
pci_cfg_access_unlock(dev);
 
-   for (i = 0; i < initial; i++) {
-   rc = pci_iov_add_virtfn(dev, i);
-   if (rc)
-   goto failed;
-   }
+   rc = pcibios_sriov_add_vfs(dev, initial);
+   if (rc)
+   goto err_pcibios;
 
kobject_uevent(>dev.kobj, KOBJ_CHANGE);
iov->num_VFs = nr_virtfn;
 
return 0;
 
-failed:
-   while (i--)
-   pci_iov_remove_virtfn(dev, i);
-
 err_pcibios:
iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
pci_cfg_access_lock(dev);
@@ -369,14 +398,12 @@ static int sriov_enable(struct pci_dev *dev, int 
nr_virtfn)
 
 static void sriov_disable(struct pci_dev *dev)
 {
-   int i;
struct pci_sriov *iov = dev->sriov;
 
if (!iov->num_VFs)
return;
 
-   for (i = 0; i < iov->num_VFs; i++)
-   pci_iov_remove_virtfn(dev, i);
+   pcibios_sriov_del_vfs(dev);
 
iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
pci_cfg_access_lock(dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 680b6bcd0b97..bf99ae98ecb5 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -475,6 +475,8 @@ struct pci_host_bridge {
int (*free_irq)(struct pci_dev *);
void (*add_bus)(struct pci_bus *);
void (*remove_bus)(struct pci_bus *);
+   int (*add_vfs)(struct pci_dev *dev, u16 num_vfs);
+   void (*del_vfs)(struct pci_dev *dev);
void*release_data;
struct msi_controller *msi;
unsigned intignore_reset_delay:1;   /* For entire hierarchy */
-- 
2.13.4



Re: [PATCH 0/2] sriov enablement on s390

2018-09-13 Thread Sebastian Ott
On Wed, 12 Sep 2018, Bjorn Helgaas wrote:
> [+cc Arnd, powerpc folks]
> 
> On Wed, Sep 12, 2018 at 02:34:09PM +0200, Sebastian Ott wrote:
> > Hello Bjorn,
> > 
> > On s390 we currently handle SRIOV within firmware. Which means
> > that the PF is under firmware control and not visible to operating
> > systems. SRIOV enablement happens within firmware and VFs are
> > passed through to logical partitions.
> > 
> > I'm working on a new mode were the PF is under operating system
> > control (including SRIOV enablement). However we still need
> > firmware support to access the VFs. The way this is supposed
> > to work is that when firmware traps the SRIOV enablement it
> > will present machine checks to the logical partition that
> > triggered the SRIOV enablement and provide the VFs via hotplug
> > events.
> > 
> > The problem I'm faced with is that the VF detection code in
> > sriov_enable leads to unusable functions in s390.
> 
> We're moving away from the weak function implementation style.  Can
> you take a look at Arnd's work here, which uses pci_host_bridge
> callbacks instead?
> 
>   https://lkml.kernel.org/r/20180817102645.3839621-1-a...@arndb.de
> 
> I cc'd some powerpc folks because they also have a fair amount of
> arch-specific SR-IOV code that might one day move in this direction.

Rebased to Arnd's pci-probe-rework branch.

Sebastian Ott (2):
  pci: provide add_vfs/del_vfs callbacks
  s390/pci: handle function enumeration after sriov enablement

 arch/s390/pci/pci.c | 11 +++
 drivers/pci/iov.c   | 51 +++
 include/linux/pci.h |  2 ++
 3 files changed, 52 insertions(+), 12 deletions(-)

-- 
2.13.4



Re: [PATCH] MAINTAINERS: Add PPC contacts for PCI core error handling

2018-09-13 Thread Oliver
On Thu, Sep 13, 2018 at 6:35 PM, Benjamin Herrenschmidt
 wrote:
> On Wed, 2018-09-12 at 11:58 -0500, Bjorn Helgaas wrote:
>> > Add the generic PCI core error recovery files to the powerpc EEH
>> > MAINTAINERS entry so the powerpc folks will be copied on changes to the
>> > generic PCI error handling strategy.
>>
>> I really want to make sure the powerpc folks are plugged into any PCI core
>> error handling discussions.  Please let me know if there's a better way
>> than this patch, or if there are other people who should be added.
>
> Sounds good. Oliver, you want to be looped in as well ?

Sure, putting all of EEH on Sam is probably not a nice thing to do.

> Cheers,
> Ben.
>
>


Re: [PATCH v2 03/17] compat_ioctl: use correct compat_ptr() translation in drivers

2018-09-13 Thread Felipe Balbi
Arnd Bergmann  writes:

> A handful of drivers all have a trivial wrapper around their ioctl
> handler, but don't call the compat_ptr() conversion function at the
> moment. In practice this does not matter, since none of them are used
> on the s390 architecture and for all other architectures, compat_ptr()
> does not do anything, but using the new generic_compat_ioctl_ptrarg
> helper makes it more correct in theory, and simplifies the code.
>
> Signed-off-by: Arnd Bergmann 

Acked-by: Felipe Balbi 

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH] MAINTAINERS: Add PPC contacts for PCI core error handling

2018-09-13 Thread Benjamin Herrenschmidt
On Wed, 2018-09-12 at 11:58 -0500, Bjorn Helgaas wrote:
> > Add the generic PCI core error recovery files to the powerpc EEH
> > MAINTAINERS entry so the powerpc folks will be copied on changes to the
> > generic PCI error handling strategy.
> 
> I really want to make sure the powerpc folks are plugged into any PCI core
> error handling discussions.  Please let me know if there's a better way
> than this patch, or if there are other people who should be added.

Sounds good. Oliver, you want to be looped in as well ?

Cheers,
Ben.




Re: MPC83xx reset status register (RSR, offset 0x910)

2018-09-13 Thread Christophe LEROY




Le 11/09/2018 à 00:17, Radu Rendec a écrit :

Hi,

On Mon, 2018-09-10 at 07:37 +0200, Christophe Leroy wrote:

Le 10/09/2018 à 01:13, Radu Rendec a écrit :


I'm using U-boot as well, but it's just not configured to read or clear
the RSR. I'm curious: if U-boot reads/clears the RSR in your case, how
do you make the initial value available to user space programs running
under Linux?


I'm surprised. When looking at U-boot code, I don't see any way to
configure that. It seems just do by default in function cpu_init_f():

https://elixir.bootlin.com/u-boot/v2018.07/source/arch/powerpc/cpu/mpc83xx/cpu_init.c#L217

 /* RSR - Reset Status Register - clear all status (4.6.1.3) */
 gd->arch.reset_status = __raw_readl(>reset.rsr);
 __raw_writel(~(RSR_RES), >reset.rsr);


I'm working as a contractor in a large embedded project, so I don't know
all the bits and pieces. I just checked the U-boot code. Whoever was
maintaining it, "configured" it by commenting out the __raw_writel()
that clears the register :)

Probably the reason was specifically to be able to read it from Linux,
but unfortunately the guy is not here any more to ask him.

It may make more sense to read it from U-boot, but (1) the value must
still be passed to Linux somehow and (2) in my case, I would prefer not
to touch U-boot.


Do you know any user space program in Linux that needs this value ?


I don't know of any "standard" program that needs it. In the project I'm
working on, there are multiple peripherals on the board and initialization
is slightly different when the reset line is physically asserted vs. a
soft CPU reset. Besides, we need to show the reset reason to the user.

I guess in the embedded world this is a fairly common use case, so
perhaps others can benefit from that if I fix it in a way that can be
pushed upstream.


Thank you very much for the patches. Is there any chance they can be
submitted upstream?


I see no problem submitting them upstream, but are they really worth it
? Adding Michael in copy to get his opinion.


I guess it's worth if they are changed to make the value available to
the kernel and user space rather than just decoding/printing it, for the
reasons I mentioned above.

The MPC83xx also has a watchdog and the kernel driver (mpc8xxx_wdt.c)
could also be improved to support the WDIOC_GETBOOTSTATUS ioctl and
properly report if the system rebooted due to a watchdog.


Very good idea.

I just submitted a patch for that. Please look at it.
I'm sure any driver which needs reset status information can do the same.

If we want to do something more central, maybe we should look at what 
was done on ARM:


https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=04fef228fb00

Christophe





I tried to look for something similar on other platforms or architectures,
but couldn't find anything.


I believe furst thing is to identify some app needing such an
information, then we'll be able to investigate how to handle it.


Well, I guess I explained my reasons and use case. If there is any
interest in that, I will gladly implement it in a way that makes sense
to upstream. Let's see what Michael thinks.

Thanks,
Radu Rendec



[PATCH] watchdog: mpc8xxx: provide boot status

2018-09-13 Thread Christophe Leroy
mpc8xxx watchdog driver supports the following platforms:
- mpc8xx
- mpc83xx
- mpc86xx

Those three platforms have a 32 bits register which provides the
reason of the last boot, including whether it was caused by the
watchdog.

mpc8xx: Register RSR, bit SWRS (bit 3)
mpc83xx: Register RSR, bit SWRS (bit 28)
mpc86xx: Register RSTRSCR, bit WDT_RR (bit 11)

This patch maps the register as defined in the device tree and updates
wdt.bootstatus based on the value of the watchdog related bit. Then
the information can be retrieved via the WDIOC_GETBOOTSTATUS ioctl.

Hereunder is an exemple of devicetree for mpc8xx,
the Reset Status Register being at offset 0x288:

WDT: watchdog@0 {
compatible = "fsl,mpc823-wdt";
reg = <0x0 0x10 0x288 0x4>;
};

On the mpc83xx, RSR is at offset 0x910
On the mpc86xx, RSTRSCR is at offset 0xe0094

Suggested-by: Radu Rendec 
Tested-by: Christophe Leroy  # On mpc885
Signed-off-by: Christophe Leroy 
---
 drivers/watchdog/mpc8xxx_wdt.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index aca2d6323f8a..2951a485a6b4 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -49,10 +49,12 @@ struct mpc8xxx_wdt {
 struct mpc8xxx_wdt_type {
int prescaler;
bool hw_enabled;
+   u32 rsr_mask;
 };
 
 struct mpc8xxx_wdt_ddata {
struct mpc8xxx_wdt __iomem *base;
+   u32 __iomem *rsr;
struct watchdog_device wdd;
spinlock_t lock;
u16 swtc;
@@ -137,6 +139,7 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
struct mpc8xxx_wdt_ddata *ddata;
u32 freq = fsl_get_sys_freq();
bool enabled;
+   struct device *dev = >dev;
 
wdt_type = of_device_get_match_data(>dev);
if (!wdt_type)
@@ -160,6 +163,22 @@ static int mpc8xxx_wdt_probe(struct platform_device *ofdev)
return -ENODEV;
}
 
+   res = platform_get_resource(ofdev, IORESOURCE_MEM, 1);
+   ddata->rsr = devm_ioremap_resource(dev, res);
+   if (IS_ERR(ddata->rsr)) {
+   dev_info(dev, "Could not map reset status register");
+   } else {
+   u32 rsr_v = in_be32(ddata->rsr);
+   bool status = rsr_v & wdt_type->rsr_mask;
+
+   ddata->wdd.bootstatus = status ? WDIOF_CARDRESET : 0;
+/* clear reset status bits related to watchdog time */
+   out_be32(ddata->rsr, wdt_type->rsr_mask);
+
+   dev_info(dev, "Last boot was %s by watchdog (RSR = 0x%8.8x)\n",
+status ? "caused" : "not caused", rsr_v);
+   }
+
spin_lock_init(>lock);
 
ddata->wdd.info = _wdt_info,
@@ -216,6 +235,7 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
.compatible = "mpc83xx_wdt",
.data = &(struct mpc8xxx_wdt_type) {
.prescaler = 0x1,
+   .rsr_mask = BIT(3), /* RSR Bit 28 */
},
},
{
@@ -223,6 +243,7 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
.data = &(struct mpc8xxx_wdt_type) {
.prescaler = 0x1,
.hw_enabled = true,
+   .rsr_mask = BIT(20), /* RSTRSCR Bit 11 */
},
},
{
@@ -230,6 +251,7 @@ static const struct of_device_id mpc8xxx_wdt_match[] = {
.data = &(struct mpc8xxx_wdt_type) {
.prescaler = 0x800,
.hw_enabled = true,
+   .rsr_mask = BIT(28), /* RSR Bit 3 */
},
},
{},
-- 
2.13.3