RE: [PATCH 5/6] pci: layerscape: Add the EP mode support.

2018-11-05 Thread Xiaowei Bao
Hi Kishon,

-Original Message-
From: Kishon Vijay Abraham I  
Sent: 2018年11月6日 14:07
To: Xiaowei Bao ; bhelg...@google.com; robh...@kernel.org; 
mark.rutl...@arm.com; shawn...@kernel.org; Leo Li ; 
lorenzo.pieral...@arm.com; a...@arndb.de; gre...@linuxfoundation.org; M.h. Lian 
; Mingkai Hu ; Roy Zang 
; kstew...@linuxfoundation.org; 
cyrille.pitc...@free-electrons.com; pombreda...@nexb.com; 
shawn@rock-chips.com; linux-...@vger.kernel.org; 
devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
Cc: Jiafei Pan 
Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.

(Removed Niklas as mails to him is bouncing)

Hi,

Please fix your email client. Refer Documentation/process/email-clients.rst

On 05/11/18 2:45 PM, Xiaowei Bao wrote:
> 
> 
> -Original Message-
> From: Kishon Vijay Abraham I 
> Sent: 2018年11月5日 16:57
> To: Xiaowei Bao ; bhelg...@google.com; 
> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
> gre...@linuxfoundation.org; M.h. Lian ; Mingkai 
> Hu ; Roy Zang ; 
> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
> pombreda...@nexb.com; shawn@rock-chips.com; 
> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
> Cc: Jiafei Pan 
> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
> 
> Hi,
> 
> On 31/10/18 4:08 PM, Xiaowei Bao wrote:
>>
>>
>> -Original Message-
>> From: Kishon Vijay Abraham I 
>> Sent: 2018年10月31日 12:15
>> To: Xiaowei Bao ; bhelg...@google.com;
>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li
>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>> gre...@linuxfoundation.org; M.h. Lian ; 
>> Mingkai Hu ; Roy Zang ; 
>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>> pombreda...@nexb.com; shawn@rock-chips.com; 
>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>> Cc: Jiafei Pan 
>> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>
>> Hi,
>>
>> On 31/10/18 8:03 AM, Xiaowei Bao wrote:
>>>
>>>
>>> -Original Message-
>>> From: Xiaowei Bao
>>> Sent: 2018年10月26日 17:19
>>> To: 'Kishon Vijay Abraham I' ; bhelg...@google.com;
>>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo 
>>> robh+Li
>>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>>> gre...@linuxfoundation.org; M.h. Lian ; 
>>> Mingkai Hu ; Roy Zang ; 
>>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>>> pombreda...@nexb.com; shawn@rock-chips.com; 
>>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>>> Cc: Jiafei Pan 
>>> Subject: RE: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>>
>>>
>>>
>>> -Original Message-
>>> From: Kishon Vijay Abraham I 
>>> Sent: 2018年10月26日 13:29
>>> To: Xiaowei Bao ; bhelg...@google.com;
>>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo 
>>> robh+Li
>>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>>> gre...@linuxfoundation.org; M.h. Lian ; 
>>> Mingkai Hu ; Roy Zang ; 
>>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>>> pombreda...@nexb.com; shawn@rock-chips.com; 
>>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>>> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>>
>>> Hi,
>>>
>>> On Thursday 25 October 2018 04:39 PM, Xiaowei Bao wrote:
 Add the PCIe EP mode support for layerscape platform.

 Signed-off-by: Xiaowei Bao 
 ---
  drivers/pci/controller/dwc/Makefile|2 +-
  drivers/pci/controller/dwc/pci-layerscape-ep.c |  161
 
  2 files changed, 162 insertions(+), 1 deletions(-)  create mode
 100644 drivers/pci/controller/dwc/pci-layerscape-ep.c

 diff --git a/drivers/pci/controller/dwc/Makefile
 b/drivers/pci/controller/dwc/Makefile
 index 5d2ce72..b26d617 100644
 --- a/drivers/pci/controller/dwc/Makefile
 +++ b/drivers/pci/controller/dwc/Makefile
 @@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
  obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
  obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
  obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
 -obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
 +obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o 
 +pci-layerscape-ep.o
  obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
>>>

Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.

2018-11-05 Thread Kishon Vijay Abraham I
(Removed Niklas as mails to him is bouncing)

Hi,

Please fix your email client. Refer Documentation/process/email-clients.rst

On 05/11/18 2:45 PM, Xiaowei Bao wrote:
> 
> 
> -Original Message-
> From: Kishon Vijay Abraham I  
> Sent: 2018年11月5日 16:57
> To: Xiaowei Bao ; bhelg...@google.com; 
> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
> gre...@linuxfoundation.org; M.h. Lian ; Mingkai Hu 
> ; Roy Zang ; 
> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
> pombreda...@nexb.com; shawn@rock-chips.com; niklas.cas...@axis.com; 
> linux-...@vger.kernel.org; devicet...@vger.kernel.org; 
> linux-ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; 
> linuxppc-dev@lists.ozlabs.org
> Cc: Jiafei Pan 
> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
> 
> Hi,
> 
> On 31/10/18 4:08 PM, Xiaowei Bao wrote:
>>
>>
>> -Original Message-
>> From: Kishon Vijay Abraham I 
>> Sent: 2018年10月31日 12:15
>> To: Xiaowei Bao ; bhelg...@google.com; 
>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>> gre...@linuxfoundation.org; M.h. Lian ; Mingkai 
>> Hu ; Roy Zang ; 
>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
>> pombreda...@nexb.com; shawn@rock-chips.com; 
>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>> Cc: Jiafei Pan 
>> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>
>> Hi,
>>
>> On 31/10/18 8:03 AM, Xiaowei Bao wrote:
>>>
>>>
>>> -Original Message-
>>> From: Xiaowei Bao
>>> Sent: 2018年10月26日 17:19
>>> To: 'Kishon Vijay Abraham I' ; bhelg...@google.com;
>>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li
>>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>>> gre...@linuxfoundation.org; M.h. Lian ; 
>>> Mingkai Hu ; Roy Zang ; 
>>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>>> pombreda...@nexb.com; shawn@rock-chips.com; 
>>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>>> Cc: Jiafei Pan 
>>> Subject: RE: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>>
>>>
>>>
>>> -Original Message-
>>> From: Kishon Vijay Abraham I 
>>> Sent: 2018年10月26日 13:29
>>> To: Xiaowei Bao ; bhelg...@google.com;
>>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li
>>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>>> gre...@linuxfoundation.org; M.h. Lian ; 
>>> Mingkai Hu ; Roy Zang ; 
>>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>>> pombreda...@nexb.com; shawn@rock-chips.com; 
>>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>>> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>>
>>> Hi,
>>>
>>> On Thursday 25 October 2018 04:39 PM, Xiaowei Bao wrote:
 Add the PCIe EP mode support for layerscape platform.

 Signed-off-by: Xiaowei Bao 
 ---
  drivers/pci/controller/dwc/Makefile|2 +-
  drivers/pci/controller/dwc/pci-layerscape-ep.c |  161
 
  2 files changed, 162 insertions(+), 1 deletions(-)  create mode
 100644 drivers/pci/controller/dwc/pci-layerscape-ep.c

 diff --git a/drivers/pci/controller/dwc/Makefile
 b/drivers/pci/controller/dwc/Makefile
 index 5d2ce72..b26d617 100644
 --- a/drivers/pci/controller/dwc/Makefile
 +++ b/drivers/pci/controller/dwc/Makefile
 @@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
  obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
  obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
  obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
 -obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
 +obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o 
 +pci-layerscape-ep.o
  obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
  obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
  obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o diff --git 
 a/drivers/pci/controller/dwc/pci-layerscape-ep.c
 b/drivers/pci/controller/dwc/pci-layerscape-ep.c
 new file mode 100644
 index 000..3b33bbc
 --- /dev/null
 +++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c
 @@ -0,0 +1,161 @@
 +// SPDX-License-Identifier: GPL-2.0
 +/*
 + * PCIe controller EP driver for Freescale Layerscape SoCs
 + *
 + * Copyright (C) 2018 NXP Semiconductor.
 + *
 + * Author: Xiaowei Bao   */
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#

Re: [PATCH -next 0/3] Add support for fast mremap

2018-11-05 Thread Joel Fernandes
On Sun, Nov 04, 2018 at 12:56:48AM -0600, William Kucharski wrote:
> 
> 
> > On Nov 3, 2018, at 12:32 PM, Joel Fernandes  wrote:
> > 
> > Looks like more architectures don't define set_pmd_at. I am thinking the
> > easiest way forward is to just do the following, instead of defining
> > set_pmd_at for every architecture that doesn't care about it. Thoughts?
> > 
> > diff --git a/mm/mremap.c b/mm/mremap.c
> > index 7cf6b0943090..31ad64dcdae6 100644
> > --- a/mm/mremap.c
> > +++ b/mm/mremap.c
> > @@ -281,7 +281,8 @@ unsigned long move_page_tables(struct vm_area_struct 
> > *vma,
> > split_huge_pmd(vma, old_pmd, old_addr);
> > if (pmd_trans_unstable(old_pmd))
> > continue;
> > -   } else if (extent == PMD_SIZE && 
> > IS_ENABLED(CONFIG_HAVE_MOVE_PMD)) {
> > +   } else if (extent == PMD_SIZE) {
> > +#ifdef CONFIG_HAVE_MOVE_PMD
> > /*
> >  * If the extent is PMD-sized, try to speed the move by
> >  * moving at the PMD level if possible.
> > @@ -296,6 +297,7 @@ unsigned long move_page_tables(struct vm_area_struct 
> > *vma,
> > drop_rmap_locks(vma);
> > if (moved)
> > continue;
> > +#endif
> > }
> > 
> > if (pte_alloc(new_vma->vm_mm, new_pmd))
> > 
> 
> That seems reasonable as there are going to be a lot of architectures that 
> never have
> mappings at the PMD level.

Ok, I will do it like this and resend.

> Have you thought about what might be needed to extend this paradigm to be 
> able to
> perform remaps at the PUD level, given many architectures already support 
> PUD-mapped
> pages?
> 

I have thought about this. I believe it is doable in the future. Off the top
I don't see an issue doing it, and it will also reduce the number of flushes.

thanks,

- Joel



[PATCH v2 1/2] kbuild: add -no-integrated-as Clang option unconditionally

2018-11-05 Thread Masahiro Yamada
We are still a way off the Clang's integrated assembler support for
the kernel. Hence, -no-integrated-as is mandatory to build the kernel
with Clang. If you had an ancient version of Clang that does not
recognize this option, you would not be able to compile the kernel
anyway.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - New patch

 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 93315eb..da11700 100644
--- a/Makefile
+++ b/Makefile
@@ -497,8 +497,8 @@ CLANG_GCC_TC:= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
 KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_CFLAGS += $(call cc-option, -no-integrated-as)
-KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
+KBUILD_CFLAGS += -no-integrated-as
+KBUILD_AFLAGS += -no-integrated-as
 endif
 
 RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern 
-mindirect-branch-register
-- 
2.7.4



[PATCH v2 2/2] kbuild: consolidate Clang compiler flags

2018-11-05 Thread Masahiro Yamada
Collect basic Clang options such as --target, --prefix, --gcc-toolchain,
-no-integrated-as into a single variable CLANG_FLAGS so that it can be
easily reused in other parts of Makefile.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
 - Use := flavor instead of = because $(CLANG_FLAGS) is expanded soon anyway

 Makefile | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index da11700..e173a73 100644
--- a/Makefile
+++ b/Makefile
@@ -487,18 +487,17 @@ endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
-CLANG_TARGET   := --target=$(notdir $(CROSS_COMPILE:%-=%))
+CLANG_FLAGS:= --target=$(notdir $(CROSS_COMPILE:%-=%))
 GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
-CLANG_PREFIX   := --prefix=$(GCC_TOOLCHAIN_DIR)
+CLANG_FLAGS+= --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
 endif
 ifneq ($(GCC_TOOLCHAIN),)
-CLANG_GCC_TC   := --gcc-toolchain=$(GCC_TOOLCHAIN)
+CLANG_FLAGS+= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
-KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) $(CLANG_PREFIX)
-KBUILD_CFLAGS += -no-integrated-as
-KBUILD_AFLAGS += -no-integrated-as
+CLANG_FLAGS+= -no-integrated-as
+KBUILD_CFLAGS  += $(CLANG_FLAGS)
+KBUILD_AFLAGS  += $(CLANG_FLAGS)
 endif
 
 RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern 
-mindirect-branch-register
-- 
2.7.4



Build regressions/improvements in v4.20-rc1 (sound/pci/hda/patch_ca0132.c)

2018-11-05 Thread Randy Dunlap
On 11/5/18 2:12 PM, Geert Uytterhoeven wrote:
> On Mon, Nov 5, 2018 at 11:07 PM Geert Uytterhoeven  
> wrote:
>> Below is the list of build error/warning regressions/improvements in
>> v4.20-rc1[1] compared to v4.19[2].
>>
>> Summarized:
>>   - build errors: +3/-0
>>   - build warnings: +449/-2712
>>
>> Happy fixing! ;-)
>>
>> Thanks to the linux-next team for providing the build service.
>>
>> [1] 
>> http://kisskb.ellerman.id.au/kisskb/branch/linus/head/651022382c7f8da46cb4872a545ee1da6d097d2a/
>>  (all 240 configs)
>> [2] 
>> http://kisskb.ellerman.id.au/kisskb/branch/linus/head/84df9525b0c27f3ebc2ebb1864fa62a97fdedb7d/
>>  (all 240 configs)
>>
>>
>> *** ERRORS ***
>>
>>   + /kisskb/src/sound/pci/hda/patch_ca0132.c: error: implicit declaration of 
>> function 'pci_iomap' [-Werror=implicit-function-declaration]:  => 8799:3
> 
> sh4-all{mod,yes}config
> 
> Looks like d9b84a15892c0233 ("ALSA: hda: Fix implicit definition of
> pci_iomap() on SH")
> is not sufficient?

Different problem.  This is about "select":

config SND_SOC_ALL_CODECS
tristate "Build all ASoC CODEC drivers"

That enables (sets):
select SND_SOC_HDAC_HDA
which selects SND_HDA even though CONFIG_PCI is not enabled.

After SND_HDA is selected (above), the Kconfig symbols in
sound/pci/hda/Kconfig are available for enabling, so
SND_HDA_CODEC_CA0132 is enabled but will not build.


One simple solution (but possibly too naive) is:

---
 sound/soc/codecs/Kconfig |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- lnx-420-rc1.orig/sound/soc/codecs/Kconfig
+++ lnx-420-rc1/sound/soc/codecs/Kconfig
@@ -82,7 +82,7 @@ config SND_SOC_ALL_CODECS
select SND_SOC_ES7241
select SND_SOC_GTM601
select SND_SOC_HDAC_HDMI
-   select SND_SOC_HDAC_HDA
+   select SND_SOC_HDAC_HDA if PCI
select SND_SOC_ICS43432
select SND_SOC_INNO_RK3036
select SND_SOC_ISABELLE if I2C




-- 
~Randy


Re: [PATCH 0/2] poewrpc/Boot: Fix cross compiling with clang

2018-11-05 Thread Joel Stanley
On Tue, 6 Nov 2018 at 09:07, Nick Desaulniers  wrote:
>
> On Sun, Nov 4, 2018 at 3:11 PM Joel Stanley  wrote:
> >
> > Hello,
> >
> > These patches allow clang to cross-compile the powerpc boot wrapper.
> > The boot wrapper constructs it's own compiler flags as it may not be
> > built for the same arch as the kernel.
>
> Hi Joel, thanks for the series!  I'm just curious, how does the boot
> wrapper run on a different arch than the kernel?

The kernel can have a ppc32 boot wrapper for a ppc64 kernel. There's
some rationale in the boot wrapper's Makefile:

 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/boot/Makefile#n10

Cheers,

Joel


Re: [PATCH] powerpc/fadump: Change to use DEFINE_SHOW_ATTRIBUTE macro

2018-11-05 Thread David Gibson
On Mon, Nov 05, 2018 at 10:01:19AM -0500, Yangtao Li wrote:
> Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
> 
> Signed-off-by: Yangtao Li 

Reviewed-by: David Gibson 

> ---
>  arch/powerpc/kernel/fadump.c | 12 +---
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
> index a711d22339ea..2df5e04b5afc 100644
> --- a/arch/powerpc/kernel/fadump.c
> +++ b/arch/powerpc/kernel/fadump.c
> @@ -1531,17 +1531,7 @@ static struct kobj_attribute fadump_register_attr = 
> __ATTR(fadump_registered,
>   0644, fadump_register_show,
>   fadump_register_store);
>  
> -static int fadump_region_open(struct inode *inode, struct file *file)
> -{
> - return single_open(file, fadump_region_show, inode->i_private);
> -}
> -
> -static const struct file_operations fadump_region_fops = {
> - .open= fadump_region_open,
> - .read= seq_read,
> - .llseek  = seq_lseek,
> - .release = single_release,
> -};
> +DEFINE_SHOW_ATTRIBUTE(fadump_region);
>  
>  static void fadump_init_files(void)
>  {

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [PATCH 2/2 v3] clk: qoriq: add more compatibles strings

2018-11-05 Thread Stephen Boyd
Quoting Yuantian Tang (2018-10-30 23:57:36)
> Add more SoC compatible strings to support more chips.
> 
> Signed-off-by: Yuantian Tang 
> ---

Acked-by: Stephen Boyd 



Re: [PATCH] powerpc/32: Avoid unsupported flags with clang

2018-11-05 Thread Segher Boessenkool
On Mon, Nov 05, 2018 at 02:48:49PM +1100, Michael Ellerman wrote:
> Joel Stanley  writes:
> > When building for ppc32 with clang these flags are unsupported:
> >
> >   -ffixed-r2 and -mmultiple

> > -CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 $(MULTIPLEWORD)
> > +ifndef CONFIG_CC_IS_CLANG
> > +#CFLAGS-$(CONFIG_PPC32):= -ffixed-r2 $(MULTIPLEWORD)
> > +endif
> 
> I think using cc-option with a comment would be nicer, you could avoid
> the ifdef and it would also future-proof it against the option either
> appearing in a future clang or disappearing in a future gcc.

These options will never be removed, lol.  -ffixed- is ancient and
generic, and -mmultiple is useful so not in any danger, and besides, we
would leave the command line option even if the feature is gone.

> eg ~=:
> 
> # Clang doesn't need or support -ffixed-r2
> CFLAGS-$(CONFIG_PPC32)+= $(cc-option,-ffixed-r2)

This option changes the ABI.  The compiler had better handle it!  If it
doesn't, the only safe cause of action is to fail loudly.

If LLVM always makes r2 fixed, it is better to special-case it here.
(Even better would be to fix the compiler, of course).


Segher


Re: [PATCH 0/2] poewrpc/Boot: Fix cross compiling with clang

2018-11-05 Thread Nick Desaulniers
On Sun, Nov 4, 2018 at 3:11 PM Joel Stanley  wrote:
>
> Hello,
>
> These patches allow clang to cross-compile the powerpc boot wrapper.
> The boot wrapper constructs it's own compiler flags as it may not be
> built for the same arch as the kernel.

Hi Joel, thanks for the series!  I'm just curious, how does the boot
wrapper run on a different arch than the kernel?

>
> The powerpc64le kernel builds natively with clang and with this patch it
> can cross compile too.
>
> Joel Stanley (2):
>   Makefile: Export clang toolchain variables
>   powerpc/boot: Set target when cross-compiling for clang
>
>  Makefile   | 3 +++
>  arch/powerpc/boot/Makefile | 7 +++
>  2 files changed, 10 insertions(+)
>
> --
> 2.19.1
>


-- 
Thanks,
~Nick Desaulniers


Re: [PATCHv2 3/6] PCI: layerscape: Add the EP mode support

2018-11-05 Thread Rob Herring
On Mon,  5 Nov 2018 16:46:50 +0800, Xiaowei Bao wrote:
> Add the EP mode support.
> 
> Signed-off-by: Xiaowei Bao 
> ---
> v2:
>  - Add the SoC specific compatibles.
> 
>  .../devicetree/bindings/pci/layerscape-pci.txt |3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 

Reviewed-by: Rob Herring 


Re: Build regressions/improvements in v4.20-rc1

2018-11-05 Thread Geert Uytterhoeven
On Mon, Nov 5, 2018 at 11:07 PM Geert Uytterhoeven  wrote:
> Below is the list of build error/warning regressions/improvements in
> v4.20-rc1[1] compared to v4.19[2].
>
> Summarized:
>   - build errors: +3/-0
>   - build warnings: +449/-2712
>
> Happy fixing! ;-)
>
> Thanks to the linux-next team for providing the build service.
>
> [1] 
> http://kisskb.ellerman.id.au/kisskb/branch/linus/head/651022382c7f8da46cb4872a545ee1da6d097d2a/
>  (all 240 configs)
> [2] 
> http://kisskb.ellerman.id.au/kisskb/branch/linus/head/84df9525b0c27f3ebc2ebb1864fa62a97fdedb7d/
>  (all 240 configs)
>
>
> *** ERRORS ***
>
> 3 error regressions:
>   + /kisskb/src/arch/s390/kernel/nospec-branch.c: error: macro "memcpy" 
> passed 6 arguments, but takes just 3:  => 130:61

s390-all{mod,yes}config

>   + /kisskb/src/sound/pci/hda/patch_ca0132.c: error: implicit declaration of 
> function 'pci_iomap' [-Werror=implicit-function-declaration]:  => 8799:3

sh4-all{mod,yes}config

Looks like d9b84a15892c0233 ("ALSA: hda: Fix implicit definition of
pci_iomap() on SH")
is not sufficient?

>   + {standard input}: Error: Unrecognized opcode: `slbfee.':  => 89, 37

powerpc-all{mod,yes}config

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


Re: [PATCH v6 00/18] of: overlay: validation checks, subsequent fixes

2018-11-05 Thread Frank Rowand
Hi Michael, Ben, Paul,

Do you know if anyone has tried this series on PowerPC?

Thanks,

-Frank


On 11/5/18 11:24 AM, Rob Herring wrote:
> On Mon, Nov 5, 2018 at 9:26 AM  wrote:
>>
>> From: Frank Rowand 
>>
>> Add checks to (1) overlay apply process and (2) memory freeing
>> triggered by overlay release.  The checks are intended to detect
>> possible memory leaks and invalid overlays.
>>
>> The checks revealed bugs in existing code.  Fixed the bugs.
>>
>> While fixing bugs, noted other issues, which are fixed in
>> separate patches.
>>
>> *  Powerpc folks: I was not able to test the patches that
>> *  directly impact Powerpc systems that use dynamic
>> *  devicetree.  Please review that code carefully and
>> *  test.  The specific patches are: 03/16, 04/16, 07/16
> 
> I'm waiting for this to happen. Send me a pull req when it does or
> when you give up waiting for a response.
> 
> Rob
> 



Re: [PATCH 2/2 v3] clk: qoriq: add more compatibles strings

2018-11-05 Thread Rob Herring
On Wed, 31 Oct 2018 14:57:36 +0800, Yuantian Tang wrote:
> Add more SoC compatible strings to support more chips.
> 
> Signed-off-by: Yuantian Tang 
> ---
> v3:
>   - undo deleting old bindings
>   - split the dts and driver to different patchset
> 
>  .../devicetree/bindings/clock/qoriq-clock.txt  |6 ++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 

Reviewed-by: Rob Herring 


Re: [PATCH v11 10/26] mm: protect VMA modifications using VMA sequence count

2018-11-05 Thread Laurent Dufour

Le 05/11/2018 à 08:04, vinayak menon a écrit :

Hi Laurent,

On Thu, May 17, 2018 at 4:37 PM Laurent Dufour
 wrote:


The VMA sequence count has been introduced to allow fast detection of
VMA modification when running a page fault handler without holding
the mmap_sem.

This patch provides protection against the VMA modification done in :
 - madvise()
 - mpol_rebind_policy()
 - vma_replace_policy()
 - change_prot_numa()
 - mlock(), munlock()
 - mprotect()
 - mmap_region()
 - collapse_huge_page()
 - userfaultd registering services

In addition, VMA fields which will be read during the speculative fault
path needs to be written using WRITE_ONCE to prevent write to be split
and intermediate values to be pushed to other CPUs.

Signed-off-by: Laurent Dufour 
---
  fs/proc/task_mmu.c |  5 -
  fs/userfaultfd.c   | 17 +
  mm/khugepaged.c|  3 +++
  mm/madvise.c   |  6 +-
  mm/mempolicy.c | 51 ++-
  mm/mlock.c | 13 -
  mm/mmap.c  | 22 +-
  mm/mprotect.c  |  4 +++-
  mm/swap_state.c|  8 ++--
  9 files changed, 89 insertions(+), 40 deletions(-)

  struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask,
 struct vm_fault *vmf)
@@ -665,9 +669,9 @@ static inline void swap_ra_clamp_pfn(struct vm_area_struct 
*vma,
  unsigned long *start,
  unsigned long *end)
  {
-   *start = max3(lpfn, PFN_DOWN(vma->vm_start),
+   *start = max3(lpfn, PFN_DOWN(READ_ONCE(vma->vm_start)),
   PFN_DOWN(faddr & PMD_MASK));
-   *end = min3(rpfn, PFN_DOWN(vma->vm_end),
+   *end = min3(rpfn, PFN_DOWN(READ_ONCE(vma->vm_end)),
 PFN_DOWN((faddr & PMD_MASK) + PMD_SIZE));
  }

--
2.7.4



I have got a crash on 4.14 kernel with speculative page faults enabled
and here is my analysis of the problem.
The issue was reported only once.


Hi Vinayak,

Thanks for reporting this.



[23409.303395]  el1_da+0x24/0x84
[23409.303400]  __radix_tree_lookup+0x8/0x90
[23409.303407]  find_get_entry+0x64/0x14c
[23409.303410]  pagecache_get_page+0x5c/0x27c
[23409.303416]  __read_swap_cache_async+0x80/0x260
[23409.303420]  swap_vma_readahead+0x264/0x37c
[23409.303423]  swapin_readahead+0x5c/0x6c
[23409.303428]  do_swap_page+0x128/0x6e4
[23409.303431]  handle_pte_fault+0x230/0xca4
[23409.303435]  __handle_speculative_fault+0x57c/0x7c8
[23409.303438]  do_page_fault+0x228/0x3e8
[23409.303442]  do_translation_fault+0x50/0x6c
[23409.303445]  do_mem_abort+0x5c/0xe0
[23409.303447]  el0_da+0x20/0x24

Process A accesses address ADDR (part of VMA A) and that results in a
translation fault.
Kernel enters __handle_speculative_fault to fix the fault.
Process A enters do_swap_page->swapin_readahead->swap_vma_readahead
from speculative path.
During this time, another process B which shares the same mm, does a
mprotect from another CPU which follows
mprotect_fixup->__split_vma, and it splits VMA A into VMAs A and B.
After the split, ADDR falls into VMA B, but process A is still using
VMA A.
Now ADDR is greater than VMA_A->vm_start and VMA_A->vm_end.
swap_vma_readahead->swap_ra_info uses start and end of vma to
calculate ptes and nr_pte, which goes wrong due to this and finally
resulting in wrong "entry" passed to
swap_vma_readahead->__read_swap_cache_async, and in turn causing
invalid swapper_space
being passed to __read_swap_cache_async->find_get_page, causing an abort.

The fix I have tried is to cache vm_start and vm_end also in vmf and
use it in swap_ra_clamp_pfn. Let me know your thoughts on this. I can
send
the patch I am a using if you feel that is the right thing to do.


I think the best would be to don't do swap readahead during the 
speculatvive page fault. If the page is found in the swap cache, that's 
fine, but otherwise, we should f	allback to the regular page fault.


The attached -untested- patch is doing this, if you want to give it a 
try. I'll review that for the next series.


Thanks,
Laurent.
From 056afafb0bccea6a356f80f4253ffcd3ef4a1f8d Mon Sep 17 00:00:00 2001
From: Laurent Dufour 
Date: Mon, 5 Nov 2018 18:43:01 +0100
Subject: [PATCH] mm: don't do swap readahead during speculative page fault

Vinayak Menon faced a panic because one thread was page faulting a page in
swap, while another one was mprotecting a part of the VMA leading to a VMA
split.
This raise a panic in swap_vma_readahead() because the VMA's boundaries
were not more matching the faulting address.

To avoid this, if the page is not found in the swap, the speculative page
fault is aborted to retry a regular page fault.

Signed-off-by: Laurent Dufour 
---
 mm/memory.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index 9dd5ffeb1f7e..720dc9a1b99f 100644
--- a/mm/memory.c
+++ b

Re: [PATCH v11 00/26] Speculative page faults

2018-11-05 Thread Laurent Dufour

Le 05/11/2018 à 11:42, Balbir Singh a écrit :

On Thu, May 17, 2018 at 01:06:07PM +0200, Laurent Dufour wrote:

This is a port on kernel 4.17 of the work done by Peter Zijlstra to handle
page fault without holding the mm semaphore [1].

The idea is to try to handle user space page faults without holding the
mmap_sem. This should allow better concurrency for massively threaded


Question -- I presume mmap_sem (rw_semaphore implementation tested against)
was qrwlock?


I don't think so, this series doesn't change the mmap_sem definition so 
it still belongs to the 'struct rw_semaphore'.


Laurent.



[PATCH] powerpc/fadump: Change to use DEFINE_SHOW_ATTRIBUTE macro

2018-11-05 Thread Yangtao Li
Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.

Signed-off-by: Yangtao Li 
---
 arch/powerpc/kernel/fadump.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index a711d22339ea..2df5e04b5afc 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -1531,17 +1531,7 @@ static struct kobj_attribute fadump_register_attr = 
__ATTR(fadump_registered,
0644, fadump_register_show,
fadump_register_store);
 
-static int fadump_region_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, fadump_region_show, inode->i_private);
-}
-
-static const struct file_operations fadump_region_fops = {
-   .open= fadump_region_open,
-   .read= seq_read,
-   .llseek  = seq_lseek,
-   .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(fadump_region);
 
 static void fadump_init_files(void)
 {
-- 
2.17.0



[PATCH] KVM: PPC: Book3S HV: Change to use DEFINE_SHOW_ATTRIBUTE macro

2018-11-05 Thread Yangtao Li
Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.

Signed-off-by: Yangtao Li 
---
 arch/powerpc/kvm/book3s_xics.c | 12 +---
 arch/powerpc/kvm/book3s_xive.c | 12 +---
 2 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_xics.c b/arch/powerpc/kvm/book3s_xics.c
index b8356cdc0c04..8fdc8eb77039 100644
--- a/arch/powerpc/kvm/book3s_xics.c
+++ b/arch/powerpc/kvm/book3s_xics.c
@@ -1017,17 +1017,7 @@ static int xics_debug_show(struct seq_file *m, void 
*private)
return 0;
 }
 
-static int xics_debug_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, xics_debug_show, inode->i_private);
-}
-
-static const struct file_operations xics_debug_fops = {
-   .open = xics_debug_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(xics_debug);
 
 static void xics_debugfs_init(struct kvmppc_xics *xics)
 {
diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c
index 30c2eb766954..57ef1502a52c 100644
--- a/arch/powerpc/kvm/book3s_xive.c
+++ b/arch/powerpc/kvm/book3s_xive.c
@@ -1905,17 +1905,7 @@ static int xive_debug_show(struct seq_file *m, void 
*private)
return 0;
 }
 
-static int xive_debug_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, xive_debug_show, inode->i_private);
-}
-
-static const struct file_operations xive_debug_fops = {
-   .open = xive_debug_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(xive_debug);
 
 static void xive_debugfs_init(struct kvmppc_xive *xive)
 {
-- 
2.17.0



[PATCH] ASoC: fsl_ssi: Change to use DEFINE_SHOW_ATTRIBUTE macro

2018-11-05 Thread Yangtao Li
Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.

Signed-off-by: Yangtao Li 
---
 sound/soc/fsl/fsl_ssi_dbg.c | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/sound/soc/fsl/fsl_ssi_dbg.c b/sound/soc/fsl/fsl_ssi_dbg.c
index 1255dfe19eef..6f6294149476 100644
--- a/sound/soc/fsl/fsl_ssi_dbg.c
+++ b/sound/soc/fsl/fsl_ssi_dbg.c
@@ -124,17 +124,7 @@ static int fsl_ssi_stats_show(struct seq_file *s, void 
*unused)
return 0;
 }
 
-static int fsl_ssi_stats_open(struct inode *inode, struct file *file)
-{
-   return single_open(file, fsl_ssi_stats_show, inode->i_private);
-}
-
-static const struct file_operations fsl_ssi_stats_ops = {
-   .open = fsl_ssi_stats_open,
-   .read = seq_read,
-   .llseek = seq_lseek,
-   .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(fsl_ssi_stats);
 
 int fsl_ssi_debugfs_create(struct fsl_ssi_dbg *ssi_dbg, struct device *dev)
 {
@@ -144,7 +134,7 @@ int fsl_ssi_debugfs_create(struct fsl_ssi_dbg *ssi_dbg, 
struct device *dev)
 
ssi_dbg->dbg_stats = debugfs_create_file("stats", 0444,
 ssi_dbg->dbg_dir, ssi_dbg,
-&fsl_ssi_stats_ops);
+&fsl_ssi_stats_fops);
if (!ssi_dbg->dbg_stats) {
debugfs_remove(ssi_dbg->dbg_dir);
return -ENOMEM;
-- 
2.17.0



Re: [PATCH v6 00/18] of: overlay: validation checks, subsequent fixes

2018-11-05 Thread Rob Herring
On Mon, Nov 5, 2018 at 9:26 AM  wrote:
>
> From: Frank Rowand 
>
> Add checks to (1) overlay apply process and (2) memory freeing
> triggered by overlay release.  The checks are intended to detect
> possible memory leaks and invalid overlays.
>
> The checks revealed bugs in existing code.  Fixed the bugs.
>
> While fixing bugs, noted other issues, which are fixed in
> separate patches.
>
> *  Powerpc folks: I was not able to test the patches that
> *  directly impact Powerpc systems that use dynamic
> *  devicetree.  Please review that code carefully and
> *  test.  The specific patches are: 03/16, 04/16, 07/16

I'm waiting for this to happen. Send me a pull req when it does or
when you give up waiting for a response.

Rob


Re: [PATCH v08 0/5] powerpc/hotplug: Update affinity for migrated CPUs

2018-11-05 Thread Michael Bringmann
On 10/29/2018 02:51 PM, Michal Suchánek wrote:
> On Sun, 29 Jul 2018 08:18:34 -0500
> Michael Bringmann  wrote:
> 
>> The migration of LPARs across Power systems affects many attributes
>> including that of the associativity of CPUs.  The patches in this
>> set execute when a system is coming up fresh upon a migration target.
>> They are intended to,
>>
>> * Recognize changes to the associativity of CPUs recorded in internal
>>   data structures when compared to the latest copies in the device
>> tree.
>> * Generate calls to other code layers to reset the data structures
>>   related to associativity of the CPUs.
>> * Re-register the 'changed' entities into the target system.
>>   Re-registration of CPUs mostly entails acting as if they have been
>>   newly hot-added into the target system.
>>
>> Signed-off-by: Michael Bringmann 
>>
> Hello,
> 
> what is the status of this patchset other than it no longer applies?

The current PowerPC systems already perform remove_processor /
add_processor operations during migration events that subsume
the necessary affinity changes.  This patchset was overkill,
so we pulled it.

Memory affinity on the other hand does need intervention, and that
patchset has been posted.  I was just about to ping Michael Ellerman
about the status from his end.
 
> 
> Thanks
> 
> Michal

Thanks.
Michael

-- 
Michael W. Bringmann
Linux Technology Center
IBM Corporation
Tie-Line  363-5196
External: (512) 286-5196
Cell:   (512) 466-0650
m...@linux.vnet.ibm.com



[PATCH v6 18/18] of: unittest: initialize args before calling of_*parse_*()

2018-11-05 Thread frowand . list
From: Frank Rowand 

Callers of of_irq_parse_one() blindly use the pointer args.np
without checking whether of_irq_parse_one() had an error and
thus did not set the value of args.np.  Initialize args to
zero so that using the format "%pOF" to show the value of
args.np will show "(null)" when of_irq_parse_one() has an
error.  This prevents the dereference of a random value.

Make the same fix for callers of of_parse_phandle_with_args()
and of_parse_phandle_with_args_map().

Reported-by: Guenter Roeck 
Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/unittest.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index fe01c5869b0f..9a10a48eb6a1 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -379,6 +379,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
for (i = 0; i < 8; i++) {
bool passed = true;
 
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list",
"#phandle-cells", i, &args);
 
@@ -432,6 +433,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
}
 
/* Check for missing list property */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list-missing",
"#phandle-cells", 0, &args);
unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
@@ -440,6 +442,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
 
/* Check for missing cells property */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list",
"#phandle-cells-missing", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -448,6 +451,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
 
/* Check for bad phandle in list */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle",
"#phandle-cells", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -456,6 +460,7 @@ static void __init of_unittest_parse_phandle_with_args(void)
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
 
/* Check for incorrectly formed argument list */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args(np, "phandle-list-bad-args",
"#phandle-cells", 1, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -506,6 +511,7 @@ static void __init 
of_unittest_parse_phandle_with_args_map(void)
for (i = 0; i < 8; i++) {
bool passed = true;
 
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list",
"phandle", i, &args);
 
@@ -563,21 +569,25 @@ static void __init 
of_unittest_parse_phandle_with_args_map(void)
}
 
/* Check for missing list property */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list-missing",
"phandle", 0, &args);
unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc);
 
/* Check for missing cells,map,mask property */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list",
"phandle-missing", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
 
/* Check for bad phandle in list */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle",
"phandle", 0, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
 
/* Check for incorrectly formed argument list */
+   memset(&args, 0, sizeof(args));
rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args",
"phandle", 1, &args);
unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
@@ -787,7 +797,7 @@ static void __init of_unittest_parse_interrupts(void)
for (i = 0; i < 4; i++) {
bool passed = true;
 
-   args.args_count = 0;
+   memset(&args, 0, sizeof(args));
rc = of_irq_parse_one(np, i, &args);
 
passed &= !rc;
@@ -808,7 +818,7 @@ static void __init of_unittest_parse_interrupts(void)
for (i = 0; i < 4; i++) {

[PATCH v6 17/18] of: unittest: find overlays[] entry by name instead of index

2018-11-05 Thread frowand . list
From: Frank Rowand 

One accessor of overlays[] was using a hard coded index value to
find the correct array entry instead of searching for the entry
containing the correct name.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/unittest.c | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index d625a91a7f60..fe01c5869b0f 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2192,7 +2192,7 @@ struct overlay_info {
 OVERLAY_INFO_EXTERN(overlay_bad_phandle);
 OVERLAY_INFO_EXTERN(overlay_bad_symbol);
 
-/* order of entries is hard-coded into users of overlays[] */
+/* entries found by name */
 static struct overlay_info overlays[] = {
OVERLAY_INFO(overlay_base, -),
OVERLAY_INFO(overlay, 0),
@@ -2215,7 +2215,8 @@ struct overlay_info {
OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL),
OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
-   {}
+   /* end marker */
+   {.dtb_begin = NULL, .dtb_end = NULL, .expected_result = 0, .name = NULL}
 };
 
 static struct device_node *overlay_base_root;
@@ -2245,6 +2246,19 @@ void __init unittest_unflatten_overlay_base(void)
u32 data_size;
void *new_fdt;
u32 size;
+   int found = 0;
+   const char *overlay_name = "overlay_base";
+
+   for (info = overlays; info && info->name; info++) {
+   if (!strcmp(overlay_name, info->name)) {
+   found = 1;
+   break;
+   }
+   }
+   if (!found) {
+   pr_err("no overlay data for %s\n", overlay_name);
+   return;
+   }
 
info = &overlays[0];
 
@@ -2292,11 +2306,10 @@ static int __init overlay_data_apply(const char 
*overlay_name, int *overlay_id)
 {
struct overlay_info *info;
int found = 0;
-   int k;
int ret;
u32 size;
 
-   for (k = 0, info = overlays; info && info->name; info++, k++) {
+   for (info = overlays; info && info->name; info++) {
if (!strcmp(overlay_name, info->name)) {
found = 1;
break;
-- 
Frank Rowand 



[PATCH v6 16/18] of: unittest: allow base devicetree to have symbol metadata

2018-11-05 Thread frowand . list
From: Frank Rowand 

The overlay metadata nodes in the FDT created from testcases.dts
are not handled properly.

The __fixups__ and __local_fixups__ node were added to the live
devicetree, but should not be.

Only the first property in the /__symbols__ node was added to the
live devicetree if the live devicetree already contained a
/__symbols node.  All of the node's properties must be added.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/unittest.c | 43 +++
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 14838b21ec6a..d625a91a7f60 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1071,20 +1071,44 @@ static void __init of_unittest_platform_populate(void)
  * of np into dup node (present in live tree) and
  * updates parent of children of np to dup.
  *
- * @np:node already present in live tree
+ * @np:node whose properties are being added to the live tree
  * @dup:   node present in live tree to be updated
  */
 static void update_node_properties(struct device_node *np,
struct device_node *dup)
 {
struct property *prop;
+   struct property *save_next;
struct device_node *child;
-
-   for_each_property_of_node(np, prop)
-   of_add_property(dup, prop);
+   int ret;
 
for_each_child_of_node(np, child)
child->parent = dup;
+
+   /*
+* "unittest internal error: unable to add testdata property"
+*
+*If this message reports a property in node '/__symbols__' then
+*the respective unittest overlay contains a label that has the
+*same name as a label in the live devicetree.  The label will
+*be in the live devicetree only if the devicetree source was
+*compiled with the '-@' option.  If you encounter this error,
+*please consider renaming __all__ of the labels in the unittest
+*overlay dts files with an odd prefix that is unlikely to be
+*used in a real devicetree.
+*/
+
+   /*
+* open code for_each_property_of_node() because of_add_property()
+* sets prop->next to NULL
+*/
+   for (prop = np->properties; prop != NULL; prop = save_next) {
+   save_next = prop->next;
+   ret = of_add_property(dup, prop);
+   if (ret)
+   pr_err("unittest internal error: unable to add testdata 
property %pOF/%s",
+  np, prop->name);
+   }
 }
 
 /**
@@ -1093,18 +1117,23 @@ static void update_node_properties(struct device_node 
*np,
  *
  * @np:Node to attach to live tree
  */
-static int attach_node_and_children(struct device_node *np)
+static void attach_node_and_children(struct device_node *np)
 {
struct device_node *next, *dup, *child;
unsigned long flags;
const char *full_name;
 
full_name = kasprintf(GFP_KERNEL, "%pOF", np);
+
+   if (!strcmp(full_name, "/__local_fixups__") ||
+   !strcmp(full_name, "/__fixups__"))
+   return;
+
dup = of_find_node_by_path(full_name);
kfree(full_name);
if (dup) {
update_node_properties(np, dup);
-   return 0;
+   return;
}
 
child = np->child;
@@ -1125,8 +1154,6 @@ static int attach_node_and_children(struct device_node 
*np)
attach_node_and_children(child);
child = next;
}
-
-   return 0;
 }
 
 /**
-- 
Frank Rowand 



[PATCH v6 15/18] of: overlay: set node fields from properties when add new overlay node

2018-11-05 Thread frowand . list
From: Frank Rowand 

Overlay nodes added by add_changeset_node() do not have the node
fields name, phandle, and type set.

The node passed to __of_attach_node() when the add node changeset
entry is processed does not contain any properties.  The node's
properties are located in add property changeset entries that will
be processed after the add node changeset is applied.

Set the node's fields in the node contained in the add node
changeset entry and do not set them to incorrect values in
add_changeset_node().

A visible symptom that is fixed by this patch is the names of nodes
added by overlays that have an entry in /sys/bus/platform/drivers/*/
will contain the unit-address but the node-name will be ,  for
example, "fc4ab000.".  After applying the patch the name, in
this example, for node restart@fc4ab000 is "fc4ab000.restart".

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/dynamic.c | 27 ++-
 drivers/of/overlay.c | 29 -
 2 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index beea792debb6..43e1ccb9c387 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -205,15 +205,24 @@ static void __of_attach_node(struct device_node *np)
const __be32 *phandle;
int sz;
 
-   np->name = __of_get_property(np, "name", NULL) ? : "";
-   np->type = __of_get_property(np, "device_type", NULL) ? : "";
-
-   phandle = __of_get_property(np, "phandle", &sz);
-   if (!phandle)
-   phandle = __of_get_property(np, "linux,phandle", &sz);
-   if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle)
-   phandle = __of_get_property(np, "ibm,phandle", &sz);
-   np->phandle = (phandle && (sz >= 4)) ? be32_to_cpup(phandle) : 0;
+   if (!of_node_check_flag(np, OF_OVERLAY)) {
+   np->name = __of_get_property(np, "name", NULL);
+   np->type = __of_get_property(np, "device_type", NULL);
+   if (!np->name)
+   np->name = "";
+   if (!np->type)
+   np->type = "";
+
+   phandle = __of_get_property(np, "phandle", &sz);
+   if (!phandle)
+   phandle = __of_get_property(np, "linux,phandle", &sz);
+   if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle)
+   phandle = __of_get_property(np, "ibm,phandle", &sz);
+   if (phandle && (sz >= 4))
+   np->phandle = be32_to_cpup(phandle);
+   else
+   np->phandle = 0;
+   }
 
np->child = NULL;
np->sibling = np->parent->child;
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 184cc2c4a931..2b5ac43a5690 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -307,10 +307,11 @@ static int add_changeset_property(struct 
overlay_changeset *ovcs,
int ret = 0;
bool check_for_non_overlay_node = false;
 
-   if (!of_prop_cmp(overlay_prop->name, "name") ||
-   !of_prop_cmp(overlay_prop->name, "phandle") ||
-   !of_prop_cmp(overlay_prop->name, "linux,phandle"))
-   return 0;
+   if (target->in_livetree)
+   if (!of_prop_cmp(overlay_prop->name, "name") ||
+   !of_prop_cmp(overlay_prop->name, "phandle") ||
+   !of_prop_cmp(overlay_prop->name, "linux,phandle"))
+   return 0;
 
if (target->in_livetree)
prop = of_find_property(target->np, overlay_prop->name, NULL);
@@ -330,6 +331,10 @@ static int add_changeset_property(struct overlay_changeset 
*ovcs,
 
if (!prop) {
check_for_non_overlay_node = true;
+   if (!target->in_livetree) {
+   new_prop->next = target->np->deadprops;
+   target->np->deadprops = new_prop;
+   }
ret = of_changeset_add_property(&ovcs->cset, target->np,
new_prop);
} else if (!of_prop_cmp(prop->name, "#address-cells")) {
@@ -400,9 +405,10 @@ static int add_changeset_node(struct overlay_changeset 
*ovcs,
struct target *target, struct device_node *node)
 {
const char *node_kbasename;
+   const __be32 *phandle;
struct device_node *tchild;
struct target target_child;
-   int ret = 0;
+   int ret = 0, size;
 
node_kbasename = kbasename(node->full_name);
 
@@ -416,6 +422,19 @@ static int add_changeset_node(struct overlay_changeset 
*ovcs,
return -ENOMEM;
 
tchild->parent = target->np;
+   tchild->name = __of_get_property(node, "name", NULL);
+   tchild->type = __of_get_property(node, "device_type", NULL);
+
+   if (!tchild->name)
+   tchild->name = "";
+   if (!tchild->type)
+   

[PATCH v6 14/18] of: unittest: remove unused of_unittest_apply_overlay() argument

2018-11-05 Thread frowand . list
From: Frank Rowand 

Argument unittest_nr is not used in of_unittest_apply_overlay(),
remove it.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/unittest.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index f0139d1e8b63..14838b21ec6a 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -1433,8 +1433,7 @@ static void of_unittest_destroy_tracked_overlays(void)
} while (defers > 0);
 }
 
-static int __init of_unittest_apply_overlay(int overlay_nr, int unittest_nr,
-   int *overlay_id)
+static int __init of_unittest_apply_overlay(int overlay_nr, int *overlay_id)
 {
const char *overlay_name;
 
@@ -1467,7 +1466,7 @@ static int __init of_unittest_apply_overlay_check(int 
overlay_nr,
}
 
ovcs_id = 0;
-   ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
+   ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
if (ret != 0) {
/* of_unittest_apply_overlay already called unittest() */
return ret;
@@ -1503,7 +1502,7 @@ static int __init 
of_unittest_apply_revert_overlay_check(int overlay_nr,
 
/* apply the overlay */
ovcs_id = 0;
-   ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id);
+   ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id);
if (ret != 0) {
/* of_unittest_apply_overlay already called unittest() */
return ret;
-- 
Frank Rowand 



[PATCH v6 13/18] of: overlay: check prevents multiple fragments touching same property

2018-11-05 Thread frowand . list
From: Frank Rowand 

Add test case of two fragments updating the same property.  After
adding the test case, the system hangs at end of boot, after
after slub stack dumps from kfree() in crypto modprobe code.

Multiple overlay fragments adding, modifying, or deleting the same
property is not supported.  Add check to detect the attempt and fail
the overlay apply.

Before this patch, the first fragment error would terminate
processing.  Allow fragment checking to proceed and report all
of the fragment errors before terminating the overlay apply. This
is not a hot path, thus not a performance issue (the error is not
transient and requires fixing the overlay before attempting to
apply it again).

After applying this patch, the devicetree unittest messages will
include:

   OF: overlay: ERROR: multiple fragments add, update, and/or delete property 
/testcase-data-2/substation@100/motor-1/rpm_avail

   ...

   ### dt-test ### end of unittest - 212 passed, 0 failed

The check to detect two fragments updating the same property is
folded into the patch that created the test case to maintain
bisectability.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/overlay.c   | 118 ++---
 drivers/of/unittest-data/Makefile  |   1 +
 .../of/unittest-data/overlay_bad_add_dup_prop.dts  |  24 +
 drivers/of/unittest-data/overlay_base.dts  |   1 +
 drivers/of/unittest.c  |   5 +
 5 files changed, 112 insertions(+), 37 deletions(-)
 create mode 100644 drivers/of/unittest-data/overlay_bad_add_dup_prop.dts

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 8af8115bd36e..184cc2c4a931 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -508,52 +508,96 @@ static int build_changeset_symbols_node(struct 
overlay_changeset *ovcs,
return 0;
 }
 
+static int find_dup_cset_node_entry(struct overlay_changeset *ovcs,
+   struct of_changeset_entry *ce_1)
+{
+   struct of_changeset_entry *ce_2;
+   char *fn_1, *fn_2;
+   int node_path_match;
+
+   if (ce_1->action != OF_RECONFIG_ATTACH_NODE &&
+   ce_1->action != OF_RECONFIG_DETACH_NODE)
+   return 0;
+
+   ce_2 = ce_1;
+   list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) {
+   if ((ce_2->action != OF_RECONFIG_ATTACH_NODE &&
+ce_2->action != OF_RECONFIG_DETACH_NODE) ||
+   of_node_cmp(ce_1->np->full_name, ce_2->np->full_name))
+   continue;
+
+   fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
+   fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
+   node_path_match = !strcmp(fn_1, fn_2);
+   kfree(fn_1);
+   kfree(fn_2);
+   if (node_path_match) {
+   pr_err("ERROR: multiple fragments add and/or delete 
node %pOF\n",
+  ce_1->np);
+   return -EINVAL;
+   }
+   }
+
+   return 0;
+}
+
+static int find_dup_cset_prop(struct overlay_changeset *ovcs,
+   struct of_changeset_entry *ce_1)
+{
+   struct of_changeset_entry *ce_2;
+   char *fn_1, *fn_2;
+   int node_path_match;
+
+   if (ce_1->action != OF_RECONFIG_ADD_PROPERTY &&
+   ce_1->action != OF_RECONFIG_REMOVE_PROPERTY &&
+   ce_1->action != OF_RECONFIG_UPDATE_PROPERTY)
+   return 0;
+
+   ce_2 = ce_1;
+   list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) {
+   if ((ce_2->action != OF_RECONFIG_ADD_PROPERTY &&
+ce_2->action != OF_RECONFIG_REMOVE_PROPERTY &&
+ce_2->action != OF_RECONFIG_UPDATE_PROPERTY) ||
+   of_node_cmp(ce_1->np->full_name, ce_2->np->full_name))
+   continue;
+
+   fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
+   fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
+   node_path_match = !strcmp(fn_1, fn_2);
+   kfree(fn_1);
+   kfree(fn_2);
+   if (node_path_match &&
+   !of_prop_cmp(ce_1->prop->name, ce_2->prop->name)) {
+   pr_err("ERROR: multiple fragments add, update, and/or 
delete property %pOF/%s\n",
+  ce_1->np, ce_1->prop->name);
+   return -EINVAL;
+   }
+   }
+
+   return 0;
+}
+
 /**
- * check_changeset_dup_add_node() - changeset validation: duplicate add node
+ * changeset_dup_entry_check() - check for duplicate entries
  * @ovcs:  Overlay changeset
  *
- * Check changeset @ovcs->cset for multiple add node entries for the same
- * node.
+ * Check changeset @ovcs->cset for multiple {add or delete} node entries for
+ * the same node or duplicate {add, delete, or update} properties entries
+ * for the same property.
  *
- * Returns 0 on success, -EN

[PATCH v6 12/18] of: overlay: check prevents multiple fragments add or delete same node

2018-11-05 Thread frowand . list
From: Frank Rowand 

Multiple overlay fragments adding or deleting the same node is not
supported.  Replace code comment of such, with check to detect the
attempt and fail the overlay apply.

Devicetree unittest where multiple fragments added the same node was
added in the previous patch in the series.  After applying this patch
the unittest messages will no longer include:

   Duplicate name in motor-1, renamed to "controller#1"
   OF: overlay: of_overlay_apply() err=0
   ### dt-test ### of_overlay_fdt_apply() expected -22, ret=0, 
overlay_bad_add_dup_node
   ### dt-test ### FAIL of_unittest_overlay_high_level():2419 Adding overlay 
'overlay_bad_add_dup_node' failed

   ...

   ### dt-test ### end of unittest - 210 passed, 1 failed

but will instead include:

   OF: overlay: ERROR: multiple overlay fragments add and/or delete node 
/testcase-data-2/substation@100/motor-1/controller

   ...

   ### dt-test ### end of unittest - 211 passed, 0 failed

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---

checkpatch errors "line over 80 characters" and "Too many leading tabs"
are ok, they will be fixed later in this series

 drivers/of/overlay.c | 58 
 1 file changed, 49 insertions(+), 9 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index c8f88b0836a3..8af8115bd36e 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -392,14 +392,6 @@ static int add_changeset_property(struct overlay_changeset 
*ovcs,
  *   a live devicetree created from Open Firmware.
  *
  * NOTE_2: Multiple mods of created nodes not supported.
- *   If more than one fragment contains a node that does not already exist
- *   in the live tree, then for each fragment of_changeset_attach_node()
- *   will add a changeset entry to add the node.  When the changeset is
- *   applied, __of_attach_node() will attach the node twice (once for
- *   each fragment).  At this point the device tree will be corrupted.
- *
- *   TODO: add integrity check to ensure that multiple fragments do not
- * create the same node.
  *
  * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
  * invalid @overlay.
@@ -517,6 +509,54 @@ static int build_changeset_symbols_node(struct 
overlay_changeset *ovcs,
 }
 
 /**
+ * check_changeset_dup_add_node() - changeset validation: duplicate add node
+ * @ovcs:  Overlay changeset
+ *
+ * Check changeset @ovcs->cset for multiple add node entries for the same
+ * node.
+ *
+ * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if
+ * invalid overlay in @ovcs->fragments[].
+ */
+static int check_changeset_dup_add_node(struct overlay_changeset *ovcs)
+{
+   struct of_changeset_entry *ce_1, *ce_2;
+   char *fn_1, *fn_2;
+   int name_match;
+
+   list_for_each_entry(ce_1, &ovcs->cset.entries, node) {
+
+   if (ce_1->action == OF_RECONFIG_ATTACH_NODE ||
+   ce_1->action == OF_RECONFIG_DETACH_NODE) {
+
+   ce_2 = ce_1;
+   list_for_each_entry_continue(ce_2, &ovcs->cset.entries, 
node) {
+   if (ce_2->action == OF_RECONFIG_ATTACH_NODE ||
+   ce_2->action == OF_RECONFIG_DETACH_NODE) {
+   /* inexpensive name compare */
+   if (!of_node_cmp(ce_1->np->full_name,
+   ce_2->np->full_name)) {
+   /* expensive full path name 
compare */
+   fn_1 = kasprintf(GFP_KERNEL, 
"%pOF", ce_1->np);
+   fn_2 = kasprintf(GFP_KERNEL, 
"%pOF", ce_2->np);
+   name_match = !strcmp(fn_1, 
fn_2);
+   kfree(fn_1);
+   kfree(fn_2);
+   if (name_match) {
+   pr_err("ERROR: multiple 
overlay fragments add and/or delete node %pOF\n",
+  ce_1->np);
+   return -EINVAL;
+   }
+   }
+   }
+   }
+   }
+   }
+
+   return 0;
+}
+
+/**
  * build_changeset() - populate overlay changeset in @ovcs from 
@ovcs->fragments
  * @ovcs:  Overlay changeset
  *
@@ -571,7 +611,7 @@ static int build_changeset(struct overlay_changeset *ovcs)
}
}
 
-   return 0;
+   return check_changeset_dup_add_node(ovcs);
 }
 
 /*
-- 
Frank Rowand 



[PATCH v6 11/18] of: overlay: test case of two fragments adding same node

2018-11-05 Thread frowand . list
From: Frank Rowand 

Multiple overlay fragments adding or deleting the same node is not
supported.  An attempt to do so results in an incorrect devicetree.
The node name will be munged for the second add.

After adding this patch, the unittest messages will show:

   Duplicate name in motor-1, renamed to "controller#1"
   OF: overlay: of_overlay_apply() err=0
   ### dt-test ### of_overlay_fdt_apply() expected -22, ret=0, 
overlay_bad_add_dup_node
   ### dt-test ### FAIL of_unittest_overlay_high_level():2419 Adding overlay 
'overlay_bad_add_dup_node' failed

   ...

   ### dt-test ### end of unittest - 210 passed, 1 failed

The incorrect (munged) node name "controller#1" can be seen in the
/proc filesystem:

   $ pwd
   /proc/device-tree/testcase-data-2/substation@100/motor-1
   $ ls
   compatiblecontrollercontroller#1  name  phandle   spin
   $ ls controller
   power_bus
   $ ls controller#1
   power_bus_emergency

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/unittest-data/Makefile  |  1 +
 .../of/unittest-data/overlay_bad_add_dup_node.dts  | 28 ++
 drivers/of/unittest.c  |  5 
 3 files changed, 34 insertions(+)
 create mode 100644 drivers/of/unittest-data/overlay_bad_add_dup_node.dts

diff --git a/drivers/of/unittest-data/Makefile 
b/drivers/of/unittest-data/Makefile
index 013d85e694c6..166dbdbfd1c5 100644
--- a/drivers/of/unittest-data/Makefile
+++ b/drivers/of/unittest-data/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \
overlay_12.dtb.o \
overlay_13.dtb.o \
overlay_15.dtb.o \
+   overlay_bad_add_dup_node.dtb.o \
overlay_bad_phandle.dtb.o \
overlay_bad_symbol.dtb.o \
overlay_base.dtb.o
diff --git a/drivers/of/unittest-data/overlay_bad_add_dup_node.dts 
b/drivers/of/unittest-data/overlay_bad_add_dup_node.dts
new file mode 100644
index ..145dfc3b1024
--- /dev/null
+++ b/drivers/of/unittest-data/overlay_bad_add_dup_node.dts
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0
+/dts-v1/;
+/plugin/;
+
+/*
+ * &electric_1/motor-1 and &spin_ctrl_1 are the same node:
+ *   /testcase-data-2/substation@100/motor-1
+ *
+ * Thus the new node "controller" in each fragment will
+ * result in an attempt to add the same node twice.
+ * This will result in an error and the overlay apply
+ * will fail.
+ */
+
+&electric_1 {
+
+   motor-1 {
+   controller {
+   power_bus = < 0x1 0x2 >;
+   };
+   };
+};
+
+&spin_ctrl_1 {
+   controller {
+   power_bus_emergency = < 0x101 0x102 >;
+   };
+};
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 49ae2aa744d6..f82edf829f43 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -2161,6 +2161,7 @@ struct overlay_info {
 OVERLAY_INFO_EXTERN(overlay_12);
 OVERLAY_INFO_EXTERN(overlay_13);
 OVERLAY_INFO_EXTERN(overlay_15);
+OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node);
 OVERLAY_INFO_EXTERN(overlay_bad_phandle);
 OVERLAY_INFO_EXTERN(overlay_bad_symbol);
 
@@ -2183,6 +2184,7 @@ struct overlay_info {
OVERLAY_INFO(overlay_12, 0),
OVERLAY_INFO(overlay_13, 0),
OVERLAY_INFO(overlay_15, 0),
+   OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL),
OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
{}
@@ -2430,6 +2432,9 @@ static __init void of_unittest_overlay_high_level(void)
unittest(overlay_data_apply("overlay", NULL),
 "Adding overlay 'overlay' failed\n");
 
+   unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL),
+"Adding overlay 'overlay_bad_add_dup_node' failed\n");
+
unittest(overlay_data_apply("overlay_bad_phandle", NULL),
 "Adding overlay 'overlay_bad_phandle' failed\n");
 
-- 
Frank Rowand 



[PATCH v6 10/18] of: overlay: make all pr_debug() and pr_err() messages unique

2018-11-05 Thread frowand . list
From: Frank Rowand 

Make overlay.c debug and error messages unique so that they can be
unambiguously found by grep.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/overlay.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 72bf00adb9c8..c8f88b0836a3 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -507,7 +507,7 @@ static int build_changeset_symbols_node(struct 
overlay_changeset *ovcs,
for_each_property_of_node(overlay_symbols_node, prop) {
ret = add_changeset_property(ovcs, target, prop, 1);
if (ret) {
-   pr_debug("Failed to apply prop @%pOF/%s, err=%d\n",
+   pr_debug("Failed to apply symbols prop @%pOF/%s, 
err=%d\n",
 target->np, prop->name, ret);
return ret;
}
@@ -551,7 +551,8 @@ static int build_changeset(struct overlay_changeset *ovcs)
ret = build_changeset_next_level(ovcs, &target,
 fragment->overlay);
if (ret) {
-   pr_debug("apply failed '%pOF'\n", fragment->target);
+   pr_debug("fragment apply failed '%pOF'\n",
+fragment->target);
return ret;
}
}
@@ -564,7 +565,8 @@ static int build_changeset(struct overlay_changeset *ovcs)
ret = build_changeset_symbols_node(ovcs, &target,
   fragment->overlay);
if (ret) {
-   pr_debug("apply failed '%pOF'\n", fragment->target);
+   pr_debug("symbols fragment apply failed '%pOF'\n",
+fragment->target);
return ret;
}
}
@@ -873,7 +875,7 @@ static int of_overlay_apply(const void *fdt, struct 
device_node *tree,
 
ret = __of_changeset_apply_notify(&ovcs->cset);
if (ret)
-   pr_err("overlay changeset entry notify error %d\n", ret);
+   pr_err("overlay apply changeset entry notify error %d\n", ret);
/* notify failure is not fatal, continue */
 
list_add_tail(&ovcs->ovcs_list, &ovcs_list);
@@ -1132,7 +1134,7 @@ int of_overlay_remove(int *ovcs_id)
 
ret = __of_changeset_revert_notify(&ovcs->cset);
if (ret)
-   pr_err("overlay changeset entry notify error %d\n", ret);
+   pr_err("overlay remove changeset entry notify error %d\n", ret);
/* notify failure is not fatal, continue */
 
*ovcs_id = 0;
-- 
Frank Rowand 



[PATCH v6 09/18] of: overlay: validate overlay properties #address-cells and #size-cells

2018-11-05 Thread frowand . list
From: Frank Rowand 

If overlay properties #address-cells or #size-cells are already in
the live devicetree for any given node, then the values in the
overlay must match the values in the live tree.

If the properties are already in the live tree then there is no
need to create a changeset entry to add them since they must
have the same value.  This reduces the memory used by the
changeset and eliminates a possible memory leak.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/overlay.c | 32 +---
 include/linux/of.h   |  6 ++
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 15be3da34fef..72bf00adb9c8 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -287,7 +287,12 @@ static struct property *dup_and_fixup_symbol_prop(
  * @target may be either in the live devicetree or in a new subtree that
  * is contained in the changeset.
  *
- * Some special properties are not updated (no error returned).
+ * Some special properties are not added or updated (no error returned):
+ * "name", "phandle", "linux,phandle".
+ *
+ * Properties "#address-cells" and "#size-cells" are not updated if they
+ * are already in the live tree, but if present in the live tree, the values
+ * in the overlay must match the values in the live tree.
  *
  * Update of property in symbols node is not allowed.
  *
@@ -300,6 +305,7 @@ static int add_changeset_property(struct overlay_changeset 
*ovcs,
 {
struct property *new_prop = NULL, *prop;
int ret = 0;
+   bool check_for_non_overlay_node = false;
 
if (!of_prop_cmp(overlay_prop->name, "name") ||
!of_prop_cmp(overlay_prop->name, "phandle") ||
@@ -322,12 +328,32 @@ static int add_changeset_property(struct 
overlay_changeset *ovcs,
if (!new_prop)
return -ENOMEM;
 
-   if (!prop)
+   if (!prop) {
+   check_for_non_overlay_node = true;
ret = of_changeset_add_property(&ovcs->cset, target->np,
new_prop);
-   else
+   } else if (!of_prop_cmp(prop->name, "#address-cells")) {
+   if (!of_prop_val_eq(prop, new_prop)) {
+   pr_err("ERROR: changing value of #address-cells is not 
allowed in %pOF\n",
+  target->np);
+   ret = -EINVAL;
+   }
+   } else if (!of_prop_cmp(prop->name, "#size-cells")) {
+   if (!of_prop_val_eq(prop, new_prop)) {
+   pr_err("ERROR: changing value of #size-cells is not 
allowed in %pOF\n",
+  target->np);
+   ret = -EINVAL;
+   }
+   } else {
+   check_for_non_overlay_node = true;
ret = of_changeset_update_property(&ovcs->cset, target->np,
   new_prop);
+   }
+
+   if (check_for_non_overlay_node &&
+   !of_node_check_flag(target->np, OF_OVERLAY))
+   pr_err("WARNING: memory leak will occur if overlay removed, 
property: %pOF/%s\n",
+  target->np, new_prop->name);
 
if (ret) {
kfree(new_prop->name);
diff --git a/include/linux/of.h b/include/linux/of.h
index 5dd9ff480397..f247a3f557e0 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -990,6 +990,12 @@ static inline int of_map_rid(struct device_node *np, u32 
rid,
 #define of_node_cmp(s1, s2)strcasecmp((s1), (s2))
 #endif
 
+static inline int of_prop_val_eq(struct property *p1, struct property *p2)
+{
+   return p1->length == p2->length &&
+  !memcmp(p1->value, p2->value, (size_t)p1->length);
+}
+
 #if defined(CONFIG_OF) && defined(CONFIG_NUMA)
 extern int of_node_to_nid(struct device_node *np);
 #else
-- 
Frank Rowand 



[PATCH v6 08/18] of: overlay: reorder fields in struct fragment

2018-11-05 Thread frowand . list
From: Frank Rowand 

Order the fields of struct fragment in the same order as
struct of_overlay_notify_data.  The order in struct fragment is
not significant.  If both structs are ordered the same then when
examining the data in a debugger or dump the human involved does
not have to remember which context they are examining.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/overlay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 9808aae4621a..15be3da34fef 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -49,8 +49,8 @@ struct target {
  * @overlay:   pointer to the __overlay__ node
  */
 struct fragment {
-   struct device_node *target;
struct device_node *overlay;
+   struct device_node *target;
 };
 
 /**
-- 
Frank Rowand 



[PATCH v6 07/18] of: dynamic: change type of of_{at, de}tach_node() to void

2018-11-05 Thread frowand . list
From: Frank Rowand 

of_attach_node() and of_detach_node() always return zero, so
their return value is meaningless.  Change their type to void
and fix all callers to ignore return value.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 arch/powerpc/platforms/pseries/dlpar.c| 13 ++---
 arch/powerpc/platforms/pseries/reconfig.c |  6 +-
 drivers/of/dynamic.c  |  9 ++---
 include/linux/of.h|  4 ++--
 4 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/dlpar.c 
b/arch/powerpc/platforms/pseries/dlpar.c
index 17958043e7f7..7c5a6f8fe9c1 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -242,15 +242,9 @@ struct device_node *dlpar_configure_connector(__be32 
drc_index,
 
 int dlpar_attach_node(struct device_node *dn, struct device_node *parent)
 {
-   int rc;
-
dn->parent = parent;
 
-   rc = of_attach_node(dn);
-   if (rc) {
-   printk(KERN_ERR "Failed to add device node %pOF\n", dn);
-   return rc;
-   }
+   of_attach_node(dn);
 
return 0;
 }
@@ -258,7 +252,6 @@ int dlpar_attach_node(struct device_node *dn, struct 
device_node *parent)
 int dlpar_detach_node(struct device_node *dn)
 {
struct device_node *child;
-   int rc;
 
child = of_get_next_child(dn, NULL);
while (child) {
@@ -266,9 +259,7 @@ int dlpar_detach_node(struct device_node *dn)
child = of_get_next_child(dn, child);
}
 
-   rc = of_detach_node(dn);
-   if (rc)
-   return rc;
+   of_detach_node(dn);
 
of_node_put(dn);
 
diff --git a/arch/powerpc/platforms/pseries/reconfig.c 
b/arch/powerpc/platforms/pseries/reconfig.c
index 0e0208117e77..0b72098da454 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -47,11 +47,7 @@ static int pSeries_reconfig_add_node(const char *path, 
struct property *proplist
goto out_err;
}
 
-   err = of_attach_node(np);
-   if (err) {
-   printk(KERN_ERR "Failed to add device node %s\n", path);
-   goto out_err;
-   }
+   of_attach_node(np);
 
of_node_put(np->parent);
 
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 146681540487..beea792debb6 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -224,7 +224,7 @@ static void __of_attach_node(struct device_node *np)
 /**
  * of_attach_node() - Plug a device node into the tree and global list.
  */
-int of_attach_node(struct device_node *np)
+void of_attach_node(struct device_node *np)
 {
struct of_reconfig_data rd;
unsigned long flags;
@@ -241,8 +241,6 @@ int of_attach_node(struct device_node *np)
mutex_unlock(&of_mutex);
 
of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd);
-
-   return 0;
 }
 
 void __of_detach_node(struct device_node *np)
@@ -273,11 +271,10 @@ void __of_detach_node(struct device_node *np)
 /**
  * of_detach_node() - "Unplug" a node from the device tree.
  */
-int of_detach_node(struct device_node *np)
+void of_detach_node(struct device_node *np)
 {
struct of_reconfig_data rd;
unsigned long flags;
-   int rc = 0;
 
memset(&rd, 0, sizeof(rd));
rd.dn = np;
@@ -291,8 +288,6 @@ int of_detach_node(struct device_node *np)
mutex_unlock(&of_mutex);
 
of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd);
-
-   return rc;
 }
 EXPORT_SYMBOL_GPL(of_detach_node);
 
diff --git a/include/linux/of.h b/include/linux/of.h
index 664cd5573ae2..5dd9ff480397 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -410,8 +410,8 @@ extern int of_alias_get_alias_list(const struct 
of_device_id *matches,
 #define OF_RECONFIG_REMOVE_PROPERTY0x0004
 #define OF_RECONFIG_UPDATE_PROPERTY0x0005
 
-extern int of_attach_node(struct device_node *);
-extern int of_detach_node(struct device_node *);
+extern void of_attach_node(struct device_node *np);
+extern void of_detach_node(struct device_node *np);
 
 #define of_match_ptr(_ptr) (_ptr)
 
-- 
Frank Rowand 



[PATCH v6 06/18] of: overlay: do not duplicate properties from overlay for new nodes

2018-11-05 Thread frowand . list
From: Frank Rowand 

When allocating a new node, add_changeset_node() was duplicating the
properties from the respective node in the overlay instead of
allocating a node with no properties.

When this patch is applied the errors reported by the devictree
unittest from patch "of: overlay: add tests to validate kfrees from
overlay removal" will no longer occur.  These error messages are of
the form:

   "OF: ERROR: ..."

and the unittest results will change from:

   ### dt-test ### end of unittest - 203 passed, 7 failed

to

   ### dt-test ### end of unittest - 210 passed, 0 failed

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/overlay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 6fd8e6145e10..9808aae4621a 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -393,7 +393,7 @@ static int add_changeset_node(struct overlay_changeset 
*ovcs,
break;
 
if (!tchild) {
-   tchild = __of_node_dup(node, node_kbasename);
+   tchild = __of_node_dup(NULL, node_kbasename);
if (!tchild)
return -ENOMEM;
 
-- 
Frank Rowand 



[PATCH v6 05/18] of: overlay: use prop add changeset entry for property in new nodes

2018-11-05 Thread frowand . list
From: Frank Rowand 

The changeset entry 'update property' was used for new properties in
an overlay instead of 'add property'.

The decision of whether to use 'update property' was based on whether
the property already exists in the subtree where the node is being
spliced into.  At the top level of creating a changeset describing the
overlay, the target node is in the live devicetree, so checking whether
the property exists in the target node returns the correct result.
As soon as the changeset creation algorithm recurses into a new node,
the target is no longer in the live devicetree, but is instead in the
detached overlay tree, thus all properties are incorrectly found to
already exist in the target.

This fix will expose another devicetree bug that will be fixed
in the following patch in the series.

When this patch is applied the errors reported by the devictree
unittest will change, and the unittest results will change from:

   ### dt-test ### end of unittest - 210 passed, 0 failed

to

   ### dt-test ### end of unittest - 203 passed, 7 failed

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---

Changes since v5:
  - update for context change from a613b26a50136 "of: Convert to using
%pOFn instead of device_node.name"

 drivers/of/overlay.c | 112 ++-
 1 file changed, 74 insertions(+), 38 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 7613f7d680c7..6fd8e6145e10 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -24,6 +24,26 @@
 #include "of_private.h"
 
 /**
+ * struct target - info about current target node as recursing through overlay
+ * @np:node where current level of overlay will be 
applied
+ * @in_livetree:   @np is a node in the live devicetree
+ *
+ * Used in the algorithm to create the portion of a changeset that describes
+ * an overlay fragment, which is a devicetree subtree.  Initially @np is a node
+ * in the live devicetree where the overlay subtree is targeted to be grafted
+ * into.  When recursing to the next level of the overlay subtree, the target
+ * also recurses to the next level of the live devicetree, as long as overlay
+ * subtree node also exists in the live devicetree.  When a node in the overlay
+ * subtree does not exist at the same level in the live devicetree, target->np
+ * points to a newly allocated node, and all subsequent targets in the subtree
+ * will be newly allocated nodes.
+ */
+struct target {
+   struct device_node *np;
+   bool in_livetree;
+};
+
+/**
  * struct fragment - info about fragment nodes in overlay expanded device tree
  * @target:target of the overlay operation
  * @overlay:   pointer to the __overlay__ node
@@ -72,8 +92,7 @@ static int devicetree_corrupt(void)
 }
 
 static int build_changeset_next_level(struct overlay_changeset *ovcs,
-   struct device_node *target_node,
-   const struct device_node *overlay_node);
+   struct target *target, const struct device_node *overlay_node);
 
 /*
  * of_resolve_phandles() finds the largest phandle in the live tree.
@@ -257,14 +276,17 @@ static struct property *dup_and_fixup_symbol_prop(
 /**
  * add_changeset_property() - add @overlay_prop to overlay changeset
  * @ovcs:  overlay changeset
- * @target_node:   where to place @overlay_prop in live tree
+ * @target:where @overlay_prop will be placed
  * @overlay_prop:  property to add or update, from overlay tree
  * @is_symbols_prop:   1 if @overlay_prop is from node "/__symbols__"
  *
- * If @overlay_prop does not already exist in @target_node, add changeset entry
- * to add @overlay_prop in @target_node, else add changeset entry to update
+ * If @overlay_prop does not already exist in live devicetree, add changeset
+ * entry to add @overlay_prop in @target, else add changeset entry to update
  * value of @overlay_prop.
  *
+ * @target may be either in the live devicetree or in a new subtree that
+ * is contained in the changeset.
+ *
  * Some special properties are not updated (no error returned).
  *
  * Update of property in symbols node is not allowed.
@@ -273,20 +295,22 @@ static struct property *dup_and_fixup_symbol_prop(
  * invalid @overlay.
  */
 static int add_changeset_property(struct overlay_changeset *ovcs,
-   struct device_node *target_node,
-   struct property *overlay_prop,
+   struct target *target, struct property *overlay_prop,
bool is_symbols_prop)
 {
struct property *new_prop = NULL, *prop;
int ret = 0;
 
-   prop = of_find_property(target_node, overlay_prop->name, NULL);
-
if (!of_prop_cmp(overlay_prop->name, "name") ||
!of_prop_cmp(overlay_prop->name, "phandle") ||
!of_prop_cmp(overlay_prop->name, "linux,phandle"))
return 0;
 
+   if (target->in_livetree)
+   prop = of_find_property(target->np

[PATCH v6 04/18] powerpc/pseries: add of_node_put() in dlpar_detach_node()

2018-11-05 Thread frowand . list
From: Frank Rowand 

"of: overlay: add missing of_node_get() in __of_attach_node_sysfs"
added a missing of_node_get() to __of_attach_node_sysfs().  This
results in a refcount imbalance for nodes attached with
dlpar_attach_node().  The calling sequence from dlpar_attach_node()
to __of_attach_node_sysfs() is:

   dlpar_attach_node()
  of_attach_node()
 __of_attach_node_sysfs()

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---

* UNTESTED.  I need people with the affected PowerPC systems
*(systems that dynamically allocate and deallocate
*devicetree nodes) to test this patch.

 arch/powerpc/platforms/pseries/dlpar.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/dlpar.c 
b/arch/powerpc/platforms/pseries/dlpar.c
index 7625546caefd..17958043e7f7 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -270,6 +270,8 @@ int dlpar_detach_node(struct device_node *dn)
if (rc)
return rc;
 
+   of_node_put(dn);
+
return 0;
 }
 
-- 
Frank Rowand 



[PATCH v6 03/18] of: overlay: add missing of_node_get() in __of_attach_node_sysfs

2018-11-05 Thread frowand . list
From: Frank Rowand 

There is a matching of_node_put() in __of_detach_node_sysfs()

Remove misleading comment from function header comment for
of_detach_node().

This patch may result in memory leaks from code that directly calls
the dynamic node add and delete functions directly instead of
using changesets.

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---

This patch should result in powerpc systems that dynamically
allocate a node, then later deallocate the node to have a
memory leak when the node is deallocated.

The next patch in the series will fix the leak.

 drivers/of/dynamic.c | 3 ---
 drivers/of/kobj.c| 4 +++-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index 12c3f9a15e94..146681540487 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -272,9 +272,6 @@ void __of_detach_node(struct device_node *np)
 
 /**
  * of_detach_node() - "Unplug" a node from the device tree.
- *
- * The caller must hold a reference to the node.  The memory associated with
- * the node is not freed until its refcount goes to zero.
  */
 int of_detach_node(struct device_node *np)
 {
diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
index 7a0a18980b98..c72eef988041 100644
--- a/drivers/of/kobj.c
+++ b/drivers/of/kobj.c
@@ -133,6 +133,9 @@ int __of_attach_node_sysfs(struct device_node *np)
}
if (!name)
return -ENOMEM;
+
+   of_node_get(np);
+
rc = kobject_add(&np->kobj, parent, "%s", name);
kfree(name);
if (rc)
@@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np)
kobject_del(&np->kobj);
}
 
-   /* finally remove the kobj_init ref */
of_node_put(np);
 }
-- 
Frank Rowand 



[PATCH v6 02/18] of: overlay: add missing of_node_put() after add new node to changeset

2018-11-05 Thread frowand . list
From: Frank Rowand 

The refcount of a newly added overlay node decrements to one
(instead of zero) when the overlay changeset is destroyed.  This
change will cause the final decrement be to zero.

After applying this patch, new validation warnings will be
reported from the devicetree unittest during boot due to
a pre-existing devicetree bug.  The warnings will be similar to:

  OF: ERROR: memory leak before free overlay changeset,  
/testcase-data/overlay-node/test-bus/test-unittest4

This pre-existing devicetree bug will also trigger a WARN_ONCE() from
refcount_sub_and_test_checked() when an overlay changeset is
destroyed without having first been applied.  This scenario occurs
when an error in the overlay is detected during the overlay changeset
creation:

  WARNING: CPU: 0 PID: 1 at lib/refcount.c:187 
refcount_sub_and_test_checked+0xa8/0xbc
  refcount_t: underflow; use-after-free.

  (unwind_backtrace) from (show_stack+0x10/0x14)
  (show_stack) from (dump_stack+0x6c/0x8c)
  (dump_stack) from (__warn+0xdc/0x104)
  (__warn) from (warn_slowpath_fmt+0x44/0x6c)
  (warn_slowpath_fmt) from (refcount_sub_and_test_checked+0xa8/0xbc)
  (refcount_sub_and_test_checked) from (kobject_put+0x24/0x208)
  (kobject_put) from (of_changeset_destroy+0x2c/0xb4)
  (of_changeset_destroy) from (free_overlay_changeset+0x1c/0x9c)
  (free_overlay_changeset) from (of_overlay_remove+0x284/0x2cc)
  (of_overlay_remove) from 
(of_unittest_apply_revert_overlay_check.constprop.4+0xf8/0x1e8)
  (of_unittest_apply_revert_overlay_check.constprop.4) from 
(of_unittest_overlay+0x960/0xed8)
  (of_unittest_overlay) from (of_unittest+0x1cc4/0x2138)
  (of_unittest) from (do_one_initcall+0x4c/0x28c)
  (do_one_initcall) from (kernel_init_freeable+0x29c/0x378)
  (kernel_init_freeable) from (kernel_init+0x8/0x110)
  (kernel_init) from (ret_from_fork+0x14/0x2c)

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/overlay.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index f5fc8859a7ee..7613f7d680c7 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -379,7 +379,9 @@ static int add_changeset_node(struct overlay_changeset 
*ovcs,
if (ret)
return ret;
 
-   return build_changeset_next_level(ovcs, tchild, node);
+   ret = build_changeset_next_level(ovcs, tchild, node);
+   of_node_put(tchild);
+   return ret;
}
 
if (node->phandle && tchild->phandle)
-- 
Frank Rowand 



[PATCH v6 01/18] of: overlay: add tests to validate kfrees from overlay removal

2018-11-05 Thread frowand . list
From: Frank Rowand 

Add checks:
  - attempted kfree due to refcount reaching zero before overlay
is removed
  - properties linked to an overlay node when the node is removed
  - node refcount > one during node removal in a changeset destroy,
if the node was created by the changeset

After applying this patch, several validation warnings will be
reported from the devicetree unittest during boot due to
pre-existing devicetree bugs. The warnings will be similar to:

  OF: ERROR: of_node_release(), unexpected properties in 
/testcase-data/overlay-node/test-bus/test-unittest11
  OF: ERROR: memory leak, expected refcount 1 instead of 2, 
of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay 
node /testcase-data-2/substation@100/
  hvac-medium-2

Tested-by: Alan Tull 
Signed-off-by: Frank Rowand 
---
 drivers/of/dynamic.c | 29 +
 drivers/of/overlay.c |  1 +
 include/linux/of.h   | 15 ++-
 3 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index f4f8ed9b5454..12c3f9a15e94 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -330,6 +330,25 @@ void of_node_release(struct kobject *kobj)
if (!of_node_check_flag(node, OF_DYNAMIC))
return;
 
+   if (of_node_check_flag(node, OF_OVERLAY)) {
+
+   if (!of_node_check_flag(node, OF_OVERLAY_FREE_CSET)) {
+   /* premature refcount of zero, do not free memory */
+   pr_err("ERROR: memory leak before free overlay 
changeset,  %pOF\n",
+  node);
+   return;
+   }
+
+   /*
+* If node->properties non-empty then properties were added
+* to this node either by different overlay that has not
+* yet been removed, or by a non-overlay mechanism.
+*/
+   if (node->properties)
+   pr_err("ERROR: %s(), unexpected properties in %pOF\n",
+  __func__, node);
+   }
+
property_list_free(node->properties);
property_list_free(node->deadprops);
 
@@ -434,6 +453,16 @@ struct device_node *__of_node_dup(const struct device_node 
*np,
 
 static void __of_changeset_entry_destroy(struct of_changeset_entry *ce)
 {
+   if (ce->action == OF_RECONFIG_ATTACH_NODE &&
+   of_node_check_flag(ce->np, OF_OVERLAY)) {
+   if (kref_read(&ce->np->kobj.kref) > 1) {
+   pr_err("ERROR: memory leak, expected refcount 1 instead 
of %d, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach 
overlay node %pOF\n",
+  kref_read(&ce->np->kobj.kref), ce->np);
+   } else {
+   of_node_set_flag(ce->np, OF_OVERLAY_FREE_CSET);
+   }
+   }
+
of_node_put(ce->np);
list_del(&ce->node);
kfree(ce);
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 42b1f73ac5f6..f5fc8859a7ee 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -373,6 +373,7 @@ static int add_changeset_node(struct overlay_changeset 
*ovcs,
return -ENOMEM;
 
tchild->parent = target_node;
+   of_node_set_flag(tchild, OF_OVERLAY);
 
ret = of_changeset_attach_node(&ovcs->cset, tchild);
if (ret)
diff --git a/include/linux/of.h b/include/linux/of.h
index a5aee3c438ad..664cd5573ae2 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -138,11 +138,16 @@ static inline void of_node_put(struct device_node *node) 
{ }
 extern struct device_node *of_stdout;
 extern raw_spinlock_t devtree_lock;
 
-/* flag descriptions (need to be visible even when !CONFIG_OF) */
-#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
-#define OF_DETACHED2 /* node has been detached from the device tree */
-#define OF_POPULATED   3 /* device already created for the node */
-#define OF_POPULATED_BUS   4 /* of_platform_populate recursed to children 
of this node */
+/*
+ * struct device_node flag descriptions
+ * (need to be visible even when !CONFIG_OF)
+ */
+#define OF_DYNAMIC 1 /* (and properties) allocated via kmalloc */
+#define OF_DETACHED2 /* detached from the device tree */
+#define OF_POPULATED   3 /* device already created */
+#define OF_POPULATED_BUS   4 /* platform bus created for children */
+#define OF_OVERLAY 5 /* allocated for an overlay */
+#define OF_OVERLAY_FREE_CSET   6 /* in overlay cset being freed */
 
 #define OF_BAD_ADDR((u64)-1)
 
-- 
Frank Rowand 



[PATCH v6 00/18] of: overlay: validation checks, subsequent fixes

2018-11-05 Thread frowand . list
From: Frank Rowand 

Add checks to (1) overlay apply process and (2) memory freeing
triggered by overlay release.  The checks are intended to detect
possible memory leaks and invalid overlays.

The checks revealed bugs in existing code.  Fixed the bugs.

While fixing bugs, noted other issues, which are fixed in
separate patches.

*  Powerpc folks: I was not able to test the patches that
*  directly impact Powerpc systems that use dynamic
*  devicetree.  Please review that code carefully and
*  test.  The specific patches are: 03/16, 04/16, 07/16

FPGA folks:

  I made the validation checks that should result in an
  invalid live devicetree report "ERROR" and cause the overlay apply
  to fail.

  I made the memory leak validation tests report "WARNING" and allow
  the overlay apply to complete successfully.  Please let me know
  if you encounter the warnings.  There are at least two paths
  forward to deal with the cases that trigger the warning: (1) change
  the warning to an error and fail the overlay apply, or (2) find a
  way to detect the potential memory leaks and free the memory
  appropriately.

ALL people:

  The validations do _not_ address another major concern I have with
  releasing overlays, which is use after free errors.

Changes since v5:
  - move from 4.19-rc1 to 4.20-rc1
  - all patches: add tested-by Alan Tull
  - 05/18: update for context change from commit a613b26a50136 ("of:
Convert to using %pOFn instead of device_node.name")

Changes since v4:
  - 01/18: make error message format consistent, error first, path last
  - 09/18: create of_prop_val_eq() and change open code to use it
  - 09/18: remove extra blank lines

Changes since v3:
  - 01/18: Add expected value of refcount for destroy cset entry error.  Also
explain the cause of the error.

  - 09/18: for errors of an overlay changing the value of #size-cells or
#address-cells, return -EINVAL so that overlay apply will fail
  - 09/18: for errors of an overlay changing the value of #size-cells or
#address-cells, make the message more direct.
Old message:
  OF: overlay: ERROR: overlay and/or live tree #size-cells invalid in node 
/soc/base_fpga_region
New message:
  OF: overlay: ERROR: changing value of /soc/base_fpga_region/#size-cells 
not allowed

  - 13/18: Update patch comment header to state that this patch modifies the
previous patch to not return immediately on fragment error and
explain this is not a performance issue.
  - 13/18: remove redundant "overlay" from two error messages.  "OF: overlay:"
is already present in pr_fmt()

Changes since v2:

  - 13/18: Use continue to reduce indentation in find_dup_cset_node_entry()
and find_dup_cset_prop()

Changes since v1:

  - move patch 16/16 to 17/18
  - move patch 15/16 to 18/18
  - new patch 15/18
  - new patch 16/18

  - 05/18: add_changeset_node() header comment: incorrect comment for @target

  - 18/18: add same fix for of_parse_phandle_with_args()
  - 18/18: add same fix for of_parse_phandle_with_args_map()

Frank Rowand (18):
  of: overlay: add tests to validate kfrees from overlay removal
  of: overlay: add missing of_node_put() after add new node to changeset
  of: overlay: add missing of_node_get() in __of_attach_node_sysfs
  powerpc/pseries: add of_node_put() in dlpar_detach_node()
  of: overlay: use prop add changeset entry for property in new nodes
  of: overlay: do not duplicate properties from overlay for new nodes
  of: dynamic: change type of of_{at,de}tach_node() to void
  of: overlay: reorder fields in struct fragment
  of: overlay: validate overlay properties #address-cells and
#size-cells
  of: overlay: make all pr_debug() and pr_err() messages unique
  of: overlay: test case of two fragments adding same node
  of: overlay: check prevents multiple fragments add or delete same node
  of: overlay: check prevents multiple fragments touching same property
  of: unittest: remove unused of_unittest_apply_overlay() argument
  of: overlay: set node fields from properties when add new overlay node
  of: unittest: allow base devicetree to have symbol metadata
  of: unittest: find overlays[] entry by name instead of index
  of: unittest: initialize args before calling of_*parse_*()

 arch/powerpc/platforms/pseries/dlpar.c |  15 +-
 arch/powerpc/platforms/pseries/reconfig.c  |   6 +-
 drivers/of/dynamic.c   |  68 +++--
 drivers/of/kobj.c  |   4 +-
 drivers/of/overlay.c   | 292 -
 drivers/of/unittest-data/Makefile  |   2 +
 .../of/unittest-data/overlay_bad_add_dup_node.dts  |  28 ++
 .../of/unittest-data/overlay_bad_add_dup_prop.dts  |  24 ++
 drivers/of/unittest-data/overlay_base.dts  |   1 +
 drivers/of/unittest.c  |  96 +--
 include/linux/of.h |  25 +-
 11 files changed, 439 insertions(+), 1

Re: System not booting since dm changes? (was Linux 4.20-rc1)

2018-11-05 Thread Jens Axboe
On 11/5/18 7:35 AM, Satheesh Rajendran wrote:
> On Mon, Nov 05, 2018 at 08:51:57AM -0500, Mike Snitzer wrote:
>> On Mon, Nov 05 2018 at  5:25am -0500,
>> Michael Ellerman  wrote:
>>
>>> Linus Torvalds  writes:
>>> ...
 Mike Snitzer (1):
 device mapper updates
>>>
>>> Hi Mike,
>>>
>>> Replying here because I can't find the device-mapper pull or the patch
>>> in question on LKML. I guess I should be subscribed to dm-devel.
>>>
>>> We have a box that doesn't boot any more, bisect points at one of:
>>>
>>>   cef6f55a9fb4 Mike Snitzer   dm table: require that request-based DM 
>>> be layered on blk-mq devices 
>>>   953923c09fe8 Mike Snitzer   dm: rename DM_TYPE_MQ_REQUEST_BASED to 
>>> DM_TYPE_REQUEST_BASED 
>>>   6a23e05c2fe3 Jens Axboe dm: remove legacy request-based IO path 
>>>
>>>
>>> It's a Power8 system running Rawhide, it does have multipath, but I'm
>>> told it was setup by the Fedora installer, ie. nothing fancy.
>>>
>>> The symptom is the system can't find its root filesystem and drops into
>>> the initramfs shell. The dmesg includes a bunch of errors like below:
>>>
>>>   [   43.263460] localhost multipathd[1344]: sdb: fail to get serial
>>>   [   43.268762] localhost multipathd[1344]: mpatha: failed in domap for 
>>> addition of new path sdb
>>>   [   43.268762] localhost multipathd[1344]: uevent trigger error
>>>   [   43.282065] localhost kernel: device-mapper: table: table load 
>>> rejected: not all devices are blk-mq request-stackable
>> ...
>>>
>>> Any ideas what's going wrong here?
>>
>> "table load rejected: not all devices are blk-mq request-stackable"
>> speaks to the fact that you aren't using blk-mq for scsi (aka scsi-mq).
>>
>> You need to use scsi_mod.use_blk_mq=Y on the kernel commandline (or set
>> CONFIG_SCSI_MQ_DEFAULT in your kernel config)
> 
> Thanks Mike!, above solution worked and the system booted fine now:-)

This quirk will go away for the next kernel, fwiw, since the non-mq
path for SCSI will be dropped as well.

-- 
Jens Axboe



Re: System not booting since dm changes? (was Linux 4.20-rc1)

2018-11-05 Thread Satheesh Rajendran
On Mon, Nov 05, 2018 at 08:51:57AM -0500, Mike Snitzer wrote:
> On Mon, Nov 05 2018 at  5:25am -0500,
> Michael Ellerman  wrote:
> 
> > Linus Torvalds  writes:
> > ...
> > > Mike Snitzer (1):
> > > device mapper updates
> > 
> > Hi Mike,
> > 
> > Replying here because I can't find the device-mapper pull or the patch
> > in question on LKML. I guess I should be subscribed to dm-devel.
> > 
> > We have a box that doesn't boot any more, bisect points at one of:
> > 
> >   cef6f55a9fb4 Mike Snitzer   dm table: require that request-based DM 
> > be layered on blk-mq devices 
> >   953923c09fe8 Mike Snitzer   dm: rename DM_TYPE_MQ_REQUEST_BASED to 
> > DM_TYPE_REQUEST_BASED 
> >   6a23e05c2fe3 Jens Axboe dm: remove legacy request-based IO path 
> > 
> > 
> > It's a Power8 system running Rawhide, it does have multipath, but I'm
> > told it was setup by the Fedora installer, ie. nothing fancy.
> > 
> > The symptom is the system can't find its root filesystem and drops into
> > the initramfs shell. The dmesg includes a bunch of errors like below:
> > 
> >   [   43.263460] localhost multipathd[1344]: sdb: fail to get serial
> >   [   43.268762] localhost multipathd[1344]: mpatha: failed in domap for 
> > addition of new path sdb
> >   [   43.268762] localhost multipathd[1344]: uevent trigger error
> >   [   43.282065] localhost kernel: device-mapper: table: table load 
> > rejected: not all devices are blk-mq request-stackable
> ...
> >
> > Any ideas what's going wrong here?
> 
> "table load rejected: not all devices are blk-mq request-stackable"
> speaks to the fact that you aren't using blk-mq for scsi (aka scsi-mq).
> 
> You need to use scsi_mod.use_blk_mq=Y on the kernel commandline (or set
> CONFIG_SCSI_MQ_DEFAULT in your kernel config)

Thanks Mike!, above solution worked and the system booted fine now:-)

# uname -r
4.20.0-rc1+
# cat /proc/cmdline 
root=/dev/mapper/fedora_ltc--test--ci2-root ro 
rd.lvm.lv=fedora_ltc-test-ci2/root rd.lvm.lv=fedora_ltc-test-ci2/swap 
scsi_mod.use_blk_mq=Y

CONFIG_SCSI_MQ_DEFAULT kernel was not set in my kernel config, will set in 
future runs.

Thanks Michael!

Regards,
-Satheesh.

> 
> Mike
> 



Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-05 Thread Peter Zijlstra
On Fri, Nov 02, 2018 at 07:19:15PM +0300, Andrey Ryabinin wrote:
> UBSAN warns about signed overflows despite -fno-strict-overflow if gcc 
> version is < 8.
> I have learned recently that UBSAN in GCC 8 ignores signed overflows if 
> -fno-strict-overflow of fwrapv is used.
> 
> $ cat signed_overflow.c 
> #include 
> 
> __attribute__((noinline))
> int foo(int a, int b)
> {
> return a+b;

 s/+/< }
> 
> int main(void)
> {
> int a = 0x7fff;
> int b = 2;
> printf("%d\n", foo(a,b));
> return 0;
> }

It also seem to affect 'shift':

peterz@hirez:~/tmp$ gcc -fsanitize=signed-integer-overflow,shift overflow.c ; 
./a.out
overflow.c:6:11: runtime error: left shift of 2147483647 by 2 places cannot be 
represented in type 'int'
-4
peterz@hirez:~/tmp$ gcc -fsanitize=signed-integer-overflow,shift -fwrapv 
overflow.c ; ./a.out
-4


Re: System not booting since dm changes? (was Linux 4.20-rc1)

2018-11-05 Thread Mike Snitzer
On Mon, Nov 05 2018 at  5:25am -0500,
Michael Ellerman  wrote:

> Linus Torvalds  writes:
> ...
> > Mike Snitzer (1):
> > device mapper updates
> 
> Hi Mike,
> 
> Replying here because I can't find the device-mapper pull or the patch
> in question on LKML. I guess I should be subscribed to dm-devel.
> 
> We have a box that doesn't boot any more, bisect points at one of:
> 
>   cef6f55a9fb4 Mike Snitzer   dm table: require that request-based DM be 
> layered on blk-mq devices 
>   953923c09fe8 Mike Snitzer   dm: rename DM_TYPE_MQ_REQUEST_BASED to 
> DM_TYPE_REQUEST_BASED 
>   6a23e05c2fe3 Jens Axboe dm: remove legacy request-based IO path 
> 
> 
> It's a Power8 system running Rawhide, it does have multipath, but I'm
> told it was setup by the Fedora installer, ie. nothing fancy.
> 
> The symptom is the system can't find its root filesystem and drops into
> the initramfs shell. The dmesg includes a bunch of errors like below:
> 
>   [   43.263460] localhost multipathd[1344]: sdb: fail to get serial
>   [   43.268762] localhost multipathd[1344]: mpatha: failed in domap for 
> addition of new path sdb
>   [   43.268762] localhost multipathd[1344]: uevent trigger error
>   [   43.282065] localhost kernel: device-mapper: table: table load rejected: 
> not all devices are blk-mq request-stackable
...
>
> Any ideas what's going wrong here?

"table load rejected: not all devices are blk-mq request-stackable"
speaks to the fact that you aren't using blk-mq for scsi (aka scsi-mq).

You need to use scsi_mod.use_blk_mq=Y on the kernel commandline (or set
CONFIG_SCSI_MQ_DEFAULT in your kernel config)

Mike


Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.

2018-11-05 Thread Kishon Vijay Abraham I
Hi,

On 31/10/18 4:08 PM, Xiaowei Bao wrote:
> 
> 
> -Original Message-
> From: Kishon Vijay Abraham I  
> Sent: 2018年10月31日 12:15
> To: Xiaowei Bao ; bhelg...@google.com; 
> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
> gre...@linuxfoundation.org; M.h. Lian ; Mingkai Hu 
> ; Roy Zang ; 
> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
> pombreda...@nexb.com; shawn@rock-chips.com; niklas.cas...@axis.com; 
> linux-...@vger.kernel.org; devicet...@vger.kernel.org; 
> linux-ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org; 
> linuxppc-dev@lists.ozlabs.org
> Cc: Jiafei Pan 
> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
> 
> Hi,
> 
> On 31/10/18 8:03 AM, Xiaowei Bao wrote:
>>
>>
>> -Original Message-
>> From: Xiaowei Bao
>> Sent: 2018年10月26日 17:19
>> To: 'Kishon Vijay Abraham I' ; bhelg...@google.com; 
>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>> gre...@linuxfoundation.org; M.h. Lian ; Mingkai 
>> Hu ; Roy Zang ; 
>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
>> pombreda...@nexb.com; shawn@rock-chips.com; 
>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>> Cc: Jiafei Pan 
>> Subject: RE: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>
>>
>>
>> -Original Message-
>> From: Kishon Vijay Abraham I 
>> Sent: 2018年10月26日 13:29
>> To: Xiaowei Bao ; bhelg...@google.com; 
>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>> gre...@linuxfoundation.org; M.h. Lian ; Mingkai 
>> Hu ; Roy Zang ; 
>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
>> pombreda...@nexb.com; shawn@rock-chips.com; 
>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>
>> Hi,
>>
>> On Thursday 25 October 2018 04:39 PM, Xiaowei Bao wrote:
>>> Add the PCIe EP mode support for layerscape platform.
>>>
>>> Signed-off-by: Xiaowei Bao 
>>> ---
>>>  drivers/pci/controller/dwc/Makefile|2 +-
>>>  drivers/pci/controller/dwc/pci-layerscape-ep.c |  161
>>> 
>>>  2 files changed, 162 insertions(+), 1 deletions(-)  create mode
>>> 100644 drivers/pci/controller/dwc/pci-layerscape-ep.c
>>>
>>> diff --git a/drivers/pci/controller/dwc/Makefile
>>> b/drivers/pci/controller/dwc/Makefile
>>> index 5d2ce72..b26d617 100644
>>> --- a/drivers/pci/controller/dwc/Makefile
>>> +++ b/drivers/pci/controller/dwc/Makefile
>>> @@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
>>>  obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
>>>  obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
>>>  obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
>>> -obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
>>> +obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o pci-layerscape-ep.o
>>>  obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
>>>  obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
>>>  obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o diff --git 
>>> a/drivers/pci/controller/dwc/pci-layerscape-ep.c
>>> b/drivers/pci/controller/dwc/pci-layerscape-ep.c
>>> new file mode 100644
>>> index 000..3b33bbc
>>> --- /dev/null
>>> +++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c
>>> @@ -0,0 +1,161 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +/*
>>> + * PCIe controller EP driver for Freescale Layerscape SoCs
>>> + *
>>> + * Copyright (C) 2018 NXP Semiconductor.
>>> + *
>>> + * Author: Xiaowei Bao   */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#include "pcie-designware.h"
>>> +
>>> +#define PCIE_DBI2_OFFSET   0x1000  /* DBI2 base address*/
>>
>> The base address should come from dt.
>>> +
>>> +struct ls_pcie_ep {
>>> +   struct dw_pcie  *pci;
>>> +};
>>> +
>>> +#define to_ls_pcie_ep(x)   dev_get_drvdata((x)->dev)
>>> +
>>> +static bool ls_pcie_is_bridge(struct ls_pcie_ep *pcie) {
>>> +   struct dw_pcie *pci = pcie->pci;
>>> +   u32 header_type;
>>> +
>>> +   header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
>>> +   header_type &= 0x7f;
>>> +
>>> +   return header_type == PCI_HEADER_TYPE_BRIDGE; }
>>> +
>>> +static int ls_pcie_establish_link(struct dw_pcie *pci) {
>>> +   return 0;
>>> +}
>>
>> There should be some way by which EP should tell RC that it is not 
>> configured yet. Are there no bits to control LTSSM state initialization or 
>> Configuration retry status enabling?
>> [Xiaowei Bao] There have not bits to control LTSSM state to tell the 

Re: [PATCH v11 00/26] Speculative page faults

2018-11-05 Thread Balbir Singh
On Thu, May 17, 2018 at 01:06:07PM +0200, Laurent Dufour wrote:
> This is a port on kernel 4.17 of the work done by Peter Zijlstra to handle
> page fault without holding the mm semaphore [1].
> 
> The idea is to try to handle user space page faults without holding the
> mmap_sem. This should allow better concurrency for massively threaded

Question -- I presume mmap_sem (rw_semaphore implementation tested against)
was qrwlock?

Balbir Singh.


Re: [RFC PATCH] lib: Introduce generic __cmpxchg_u64() and use it where needed

2018-11-05 Thread Peter Zijlstra
On Fri, Nov 02, 2018 at 07:19:15PM +0300, Andrey Ryabinin wrote:

> UBSAN warns about signed overflows despite -fno-strict-overflow if gcc
> version is < 8.  I have learned recently that UBSAN in GCC 8 ignores
> signed overflows if -fno-strict-overflow of fwrapv is used.

Ah, good.

> We can always just drop -fsanitize=signed-integer-overflow if it considered 
> too noisy.

I think that is the most consistent beahviour. signed overflow is not UB
in the kernel.

> Although it did catch some real bugs.

If we want an over/under-flow checker, then that should be a separate
plugin and not specific to signed or unsigned.


System not booting since dm changes? (was Linux 4.20-rc1)

2018-11-05 Thread Michael Ellerman
Linus Torvalds  writes:
...
> Mike Snitzer (1):
> device mapper updates

Hi Mike,

Replying here because I can't find the device-mapper pull or the patch
in question on LKML. I guess I should be subscribed to dm-devel.

We have a box that doesn't boot any more, bisect points at one of:

  cef6f55a9fb4 Mike Snitzer   dm table: require that request-based DM be 
layered on blk-mq devices 
  953923c09fe8 Mike Snitzer   dm: rename DM_TYPE_MQ_REQUEST_BASED to 
DM_TYPE_REQUEST_BASED 
  6a23e05c2fe3 Jens Axboe dm: remove legacy request-based IO path 


It's a Power8 system running Rawhide, it does have multipath, but I'm
told it was setup by the Fedora installer, ie. nothing fancy.

The symptom is the system can't find its root filesystem and drops into
the initramfs shell. The dmesg includes a bunch of errors like below:

  [   43.263460] localhost multipathd[1344]: sdb: fail to get serial
  [   43.268762] localhost multipathd[1344]: mpatha: failed in domap for 
addition of new path sdb
  [   43.268762] localhost multipathd[1344]: uevent trigger error
  [   43.282065] localhost kernel: device-mapper: table: table load rejected: 
not all devices are blk-mq request-stackable
  [   43.282096] localhost kernel: device-mapper: table: unable to determine 
table type
  [   43.275898] localhost multipathd[1344]: sdd: fail to get serial
  [   43.282597] localhost multipathd[1344]: mpatha: failed in domap for 
addition of new path sdd
  [   43.282642] localhost multipathd[1344]: uevent trigger error
  [   43.286540] localhost multipathd[1344]: sdc: fail to get serial
  [   43.296366] localhost kernel: device-mapper: table: table load rejected: 
not all devices are blk-mq request-stackable
  [   43.296392] localhost kernel: device-mapper: table: unable to determine 
table type
  [   43.292218] localhost multipathd[1344]: mpathb: failed in domap for 
addition of new path sdc
  [   43.292218] localhost multipathd[1344]: uevent trigger error
  [   43.306193] localhost kernel: device-mapper: table: table load rejected: 
not all devices are blk-mq request-stackable
  [   43.306212] localhost kernel: device-mapper: table: unable to determine 
table type
  [  150.523303] localhost dracut-initqueue[1325]: Warning: dracut-initqueue 
timeout - starting timeout scripts


There's more info here if you want it:
  https://github.com/linuxppc/linux/issues/203


Any ideas what's going wrong here?

cheers


RE: [PATCH 5/6] pci: layerscape: Add the EP mode support.

2018-11-05 Thread Xiaowei Bao


-Original Message-
From: Kishon Vijay Abraham I  
Sent: 2018年11月5日 16:57
To: Xiaowei Bao ; bhelg...@google.com; robh...@kernel.org; 
mark.rutl...@arm.com; shawn...@kernel.org; Leo Li ; 
lorenzo.pieral...@arm.com; a...@arndb.de; gre...@linuxfoundation.org; M.h. Lian 
; Mingkai Hu ; Roy Zang 
; kstew...@linuxfoundation.org; 
cyrille.pitc...@free-electrons.com; pombreda...@nexb.com; 
shawn@rock-chips.com; niklas.cas...@axis.com; linux-...@vger.kernel.org; 
devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
Cc: Jiafei Pan 
Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.

Hi,

On 31/10/18 4:08 PM, Xiaowei Bao wrote:
> 
> 
> -Original Message-
> From: Kishon Vijay Abraham I 
> Sent: 2018年10月31日 12:15
> To: Xiaowei Bao ; bhelg...@google.com; 
> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li 
> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
> gre...@linuxfoundation.org; M.h. Lian ; Mingkai 
> Hu ; Roy Zang ; 
> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com; 
> pombreda...@nexb.com; shawn@rock-chips.com; 
> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
> Cc: Jiafei Pan 
> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
> 
> Hi,
> 
> On 31/10/18 8:03 AM, Xiaowei Bao wrote:
>>
>>
>> -Original Message-
>> From: Xiaowei Bao
>> Sent: 2018年10月26日 17:19
>> To: 'Kishon Vijay Abraham I' ; bhelg...@google.com;
>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li
>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>> gre...@linuxfoundation.org; M.h. Lian ; 
>> Mingkai Hu ; Roy Zang ; 
>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>> pombreda...@nexb.com; shawn@rock-chips.com; 
>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>> Cc: Jiafei Pan 
>> Subject: RE: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>
>>
>>
>> -Original Message-
>> From: Kishon Vijay Abraham I 
>> Sent: 2018年10月26日 13:29
>> To: Xiaowei Bao ; bhelg...@google.com;
>> robh...@kernel.org; mark.rutl...@arm.com; shawn...@kernel.org; Leo Li
>> ; lorenzo.pieral...@arm.com; a...@arndb.de; 
>> gre...@linuxfoundation.org; M.h. Lian ; 
>> Mingkai Hu ; Roy Zang ; 
>> kstew...@linuxfoundation.org; cyrille.pitc...@free-electrons.com;
>> pombreda...@nexb.com; shawn@rock-chips.com; 
>> niklas.cas...@axis.com; linux-...@vger.kernel.org; 
>> devicet...@vger.kernel.org; linux-ker...@vger.kernel.org; 
>> linux-arm-ker...@lists.infradead.org; linuxppc-dev@lists.ozlabs.org
>> Subject: Re: [PATCH 5/6] pci: layerscape: Add the EP mode support.
>>
>> Hi,
>>
>> On Thursday 25 October 2018 04:39 PM, Xiaowei Bao wrote:
>>> Add the PCIe EP mode support for layerscape platform.
>>>
>>> Signed-off-by: Xiaowei Bao 
>>> ---
>>>  drivers/pci/controller/dwc/Makefile|2 +-
>>>  drivers/pci/controller/dwc/pci-layerscape-ep.c |  161
>>> 
>>>  2 files changed, 162 insertions(+), 1 deletions(-)  create mode
>>> 100644 drivers/pci/controller/dwc/pci-layerscape-ep.c
>>>
>>> diff --git a/drivers/pci/controller/dwc/Makefile
>>> b/drivers/pci/controller/dwc/Makefile
>>> index 5d2ce72..b26d617 100644
>>> --- a/drivers/pci/controller/dwc/Makefile
>>> +++ b/drivers/pci/controller/dwc/Makefile
>>> @@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
>>>  obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
>>>  obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
>>>  obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
>>> -obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
>>> +obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o 
>>> +pci-layerscape-ep.o
>>>  obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
>>>  obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
>>>  obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o diff --git 
>>> a/drivers/pci/controller/dwc/pci-layerscape-ep.c
>>> b/drivers/pci/controller/dwc/pci-layerscape-ep.c
>>> new file mode 100644
>>> index 000..3b33bbc
>>> --- /dev/null
>>> +++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c
>>> @@ -0,0 +1,161 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +/*
>>> + * PCIe controller EP driver for Freescale Layerscape SoCs
>>> + *
>>> + * Copyright (C) 2018 NXP Semiconductor.
>>> + *
>>> + * Author: Xiaowei Bao   */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#include "pcie-designware.h"
>>> +
>>> +#define PCIE_DBI2_OFFSET   0x1000  /* DBI2 base address*/
>>
>> The base address should come from dt.
>>> +
>>> +struct ls_pcie_ep {
>>> +   struct dw_pcie  *pci;
>>> +};
>>> +
>>> +#define to_ls_pcie_ep(x)

[PATCH] powerpc: Add some documentation of ISA versions

2018-11-05 Thread Michael Ellerman
Add some documentation on which CPU versions map to which ISA
versions. This is all publicly available information, some of it
already in the kernel source, but it's much nicer to have it all in
one place.

Signed-off-by: Michael Ellerman 
---
 Documentation/powerpc/isa-versions.rst | 74 ++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/powerpc/isa-versions.rst

Please send corrections if you notice anything wrong.

Also happy to take patches to add other CPUs and other features, this is
just a start.

diff --git a/Documentation/powerpc/isa-versions.rst 
b/Documentation/powerpc/isa-versions.rst
new file mode 100644
index ..812e20cc898c
--- /dev/null
+++ b/Documentation/powerpc/isa-versions.rst
@@ -0,0 +1,74 @@
+CPU to ISA Version Mapping
+==
+
+Mapping of some CPU versions to relevant ISA versions.
+
+= 
+CPU   Architecture version
+= 
+Power9Power ISA v3.0B
+Power8Power ISA v2.07
+Power7Power ISA v2.06
+Power6Power ISA v2.05
+PA6T  Power ISA v2.04
+Cell PPU  - Power ISA v2.02 with some minor exceptions
+  - Plus Altivec/VMX ~= 2.03
+Power5++  Power ISA v2.04 (no VMX)
+Power5+   Power ISA v2.03
+Power5- PowerPC User Instruction Set Architecture Book I v2.02
+  - PowerPC Virtual Environment Architecture Book II v2.02
+  - PowerPC Operating Environment Architecture Book III v2.02
+PPC970- PowerPC User Instruction Set Architecture Book I v2.01
+  - PowerPC Virtual Environment Architecture Book II v2.01
+  - PowerPC Operating Environment Architecture Book III v2.01
+  - Plus Altivec/VMX ~= 2.03
+= 
+
+
+Key Features
+
+
+== ==
+CPUVMX (aka. Altivec)
+== ==
+Power9 Yes
+Power8 Yes
+Power7 Yes
+Power6 Yes
+PA6T   Yes
+Cell PPU   Yes
+Power5++   No
+Power5+No
+Power5 No
+PPC970 Yes
+== ==
+
+== 
+CPUVSX
+== 
+Power9 Yes
+Power8 Yes
+Power7 Yes
+Power6 No
+PA6T   No
+Cell PPU   No
+Power5++   No
+Power5+No
+Power5 No
+PPC970 No
+== 
+
+== 
+CPUTransactional Memory
+== 
+Power9 Yes (* see transactional_memory.txt)
+Power8 Yes
+Power7 No
+Power6 No
+PA6T   No
+Cell PPU   No
+Power5++   No
+Power5+No
+Power5 No
+PPC970 No
+== 
-- 
2.17.2



[PATCHv2 6/6] misc: pci_endpoint_test: Add the layerscape EP device support

2018-11-05 Thread Xiaowei Bao
Add the layerscape EP device support in pci_endpoint_test driver.

Signed-off-by: Xiaowei Bao 
---
v2:
 - no change

 drivers/misc/pci_endpoint_test.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 896e2df..744d10c 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -788,6 +788,8 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)
 static const struct pci_device_id pci_endpoint_test_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x) },
{ PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x) },
+   /* 0x81c0: The device id of ls1046a in NXP. */
+   { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x81c0) },
{ PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 0xedda) },
{ }
 };
-- 
1.7.1



[PATCHv2 5/6] pci: layerscape: Add the EP mode support.

2018-11-05 Thread Xiaowei Bao
Add the PCIe EP mode support for layerscape platform.

Signed-off-by: Xiaowei Bao 
---
v2:
 - remove the EP mode check function.

 drivers/pci/controller/dwc/Makefile|2 +-
 drivers/pci/controller/dwc/pci-layerscape-ep.c |  147 
 2 files changed, 148 insertions(+), 1 deletions(-)
 create mode 100644 drivers/pci/controller/dwc/pci-layerscape-ep.c

diff --git a/drivers/pci/controller/dwc/Makefile 
b/drivers/pci/controller/dwc/Makefile
index 5d2ce72..b26d617 100644
--- a/drivers/pci/controller/dwc/Makefile
+++ b/drivers/pci/controller/dwc/Makefile
@@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o
 obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
 obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
 obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
-obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
+obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o pci-layerscape-ep.o
 obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
 obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
 obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o
diff --git a/drivers/pci/controller/dwc/pci-layerscape-ep.c 
b/drivers/pci/controller/dwc/pci-layerscape-ep.c
new file mode 100644
index 000..289618b
--- /dev/null
+++ b/drivers/pci/controller/dwc/pci-layerscape-ep.c
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PCIe controller EP driver for Freescale Layerscape SoCs
+ *
+ * Copyright (C) 2018 NXP Semiconductor.
+ *
+ * Author: Xiaowei Bao 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "pcie-designware.h"
+
+#define PCIE_DBI2_OFFSET   0x1000  /* DBI2 base address*/
+
+struct ls_pcie_ep {
+   struct dw_pcie  *pci;
+};
+
+#define to_ls_pcie_ep(x)   dev_get_drvdata((x)->dev)
+
+static int ls_pcie_establish_link(struct dw_pcie *pci)
+{
+   return 0;
+}
+
+static const struct dw_pcie_ops ls_pcie_ep_ops = {
+   .start_link = ls_pcie_establish_link,
+};
+
+static const struct of_device_id ls_pcie_ep_of_match[] = {
+   { .compatible = "fsl,ls-pcie-ep",},
+   { },
+};
+
+static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
+{
+   struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+   struct pci_epc *epc = ep->epc;
+   enum pci_barno bar;
+
+   for (bar = BAR_0; bar <= BAR_5; bar++)
+   dw_pcie_ep_reset_bar(pci, bar);
+
+   epc->features |= EPC_FEATURE_NO_LINKUP_NOTIFIER;
+}
+
+static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
+ enum pci_epc_irq_type type, u16 interrupt_num)
+{
+   struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+
+   switch (type) {
+   case PCI_EPC_IRQ_LEGACY:
+   return dw_pcie_ep_raise_legacy_irq(ep, func_no);
+   case PCI_EPC_IRQ_MSI:
+   return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
+   case PCI_EPC_IRQ_MSIX:
+   return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
+   default:
+   dev_err(pci->dev, "UNKNOWN IRQ type\n");
+   }
+
+   return 0;
+}
+
+static struct dw_pcie_ep_ops pcie_ep_ops = {
+   .ep_init = ls_pcie_ep_init,
+   .raise_irq = ls_pcie_ep_raise_irq,
+};
+
+static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
+   struct platform_device *pdev)
+{
+   struct dw_pcie *pci = pcie->pci;
+   struct device *dev = pci->dev;
+   struct dw_pcie_ep *ep;
+   struct resource *res;
+   int ret;
+
+   ep = &pci->ep;
+   ep->ops = &pcie_ep_ops;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space");
+   if (!res)
+   return -EINVAL;
+
+   ep->phys_base = res->start;
+   ep->addr_size = resource_size(res);
+
+   ret = dw_pcie_ep_init(ep);
+   if (ret) {
+   dev_err(dev, "failed to initialize endpoint\n");
+   return ret;
+   }
+
+   return 0;
+}
+
+static int __init ls_pcie_ep_probe(struct platform_device *pdev)
+{
+   struct device *dev = &pdev->dev;
+   struct dw_pcie *pci;
+   struct ls_pcie_ep *pcie;
+   struct resource *dbi_base;
+   int ret;
+
+   pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
+   if (!pcie)
+   return -ENOMEM;
+
+   pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
+   if (!pci)
+   return -ENOMEM;
+
+   dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
+   pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
+   if (IS_ERR(pci->dbi_base))
+   return PTR_ERR(pci->dbi_base);
+
+   pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
+   pci->dev = dev;
+   pci->ops = &ls_pcie_ep_ops;
+   pcie->pci = pci;
+
+   platform_set_drvdata(pdev, pcie);
+
+   ret = ls_add_pcie_ep(pcie, pdev);
+
+   return ret;
+}
+
+static struct platform_driver ls_pcie_ep_driver = {
+   .driver = {
+   

[PATCHv2 4/6] arm64: dts: Add the PCIE EP node in dts

2018-11-05 Thread Xiaowei Bao
Add the PCIE EP node in dts for ls1046a.

Signed-off-by: Xiaowei Bao 
---
v2:
 - Add the SoC specific compatibles. 

 arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi |   32 
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
index 64d334c..544b3e5 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
@@ -655,6 +655,17 @@
status = "disabled";
};
 
+   pcie_ep@340 {
+   compatible = "fsl,ls1046a-pcie-ep","fsl,ls-pcie-ep";
+   reg = <0x00 0x0340 0x0 0x0010
+   0x40 0x 0x8 0x>;
+   reg-names = "regs", "addr_space";
+   num-ib-windows = <6>;
+   num-ob-windows = <6>;
+   num-lanes = <2>;
+   status = "disabled";
+   };
+
pcie@350 {
compatible = "fsl,ls1046a-pcie", "snps,dw-pcie";
reg = <0x00 0x0350 0x0 0x0010   /* controller 
registers */
@@ -681,6 +692,17 @@
status = "disabled";
};
 
+   pcie_ep@350 {
+   compatible = "fsl,ls1046a-pcie-ep","fsl,ls-pcie-ep";
+   reg = <0x00 0x0350 0x0 0x0010
+   0x48 0x 0x8 0x>;
+   reg-names = "regs", "addr_space";
+   num-ib-windows = <6>;
+   num-ob-windows = <6>;
+   num-lanes = <2>;
+   status = "disabled";
+   };
+
pcie@360 {
compatible = "fsl,ls1046a-pcie", "snps,dw-pcie";
reg = <0x00 0x0360 0x0 0x0010   /* controller 
registers */
@@ -707,6 +729,16 @@
status = "disabled";
};
 
+   pcie_ep@360 {
+   compatible = "fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep";
+   reg = <0x00 0x0360 0x0 0x0010
+   0x50 0x 0x8 0x>;
+   reg-names = "regs", "addr_space";
+   num-ib-windows = <6>;
+   num-ob-windows = <6>;
+   num-lanes = <2>;
+   status = "disabled";
+   };
};
 
reserved-memory {
-- 
1.7.1



[PATCHv2 3/6] PCI: layerscape: Add the EP mode support

2018-11-05 Thread Xiaowei Bao
Add the EP mode support.

Signed-off-by: Xiaowei Bao 
---
v2:
 - Add the SoC specific compatibles.

 .../devicetree/bindings/pci/layerscape-pci.txt |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/Documentation/devicetree/bindings/pci/layerscape-pci.txt 
b/Documentation/devicetree/bindings/pci/layerscape-pci.txt
index 66df1e8..9c090c7 100644
--- a/Documentation/devicetree/bindings/pci/layerscape-pci.txt
+++ b/Documentation/devicetree/bindings/pci/layerscape-pci.txt
@@ -13,12 +13,15 @@ information.
 
 Required properties:
 - compatible: should contain the platform identifier such as:
+  RC mode:
 "fsl,ls1021a-pcie", "snps,dw-pcie"
 "fsl,ls2080a-pcie", "fsl,ls2085a-pcie", "snps,dw-pcie"
 "fsl,ls2088a-pcie"
 "fsl,ls1088a-pcie"
 "fsl,ls1046a-pcie"
 "fsl,ls1012a-pcie"
+  EP mode:
+"fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep"
 - reg: base addresses and lengths of the PCIe controller register blocks.
 - interrupts: A list of interrupt outputs of the controller. Must contain an
   entry for each entry in the interrupt-names property.
-- 
1.7.1



[PATCHv2 2/6] ARM: dts: ls1021a: Add the status property disable PCIe

2018-11-05 Thread Xiaowei Bao
Add the status property disable the PCIe, the property will be enable
by bootloader.

Signed-off-by: Xiaowei Bao 
---
v2:
 - no change

 arch/arm/boot/dts/ls1021a.dtsi |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi
index bdd6e66..b769e0e 100644
--- a/arch/arm/boot/dts/ls1021a.dtsi
+++ b/arch/arm/boot/dts/ls1021a.dtsi
@@ -736,6 +736,7 @@
< 0 0 2 &gic GIC_SPI 188 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic GIC_SPI 190 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic GIC_SPI 192 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
pcie@350 {
@@ -759,6 +760,7 @@
< 0 0 2 &gic GIC_SPI 189 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic GIC_SPI 191 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic GIC_SPI 193 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
can0: can@2a7 {
-- 
1.7.1



[PATCHv2 1/6] arm64: dts: Add the status property disable PCIe

2018-11-05 Thread Xiaowei Bao
From: Bao Xiaowei 

Add the status property disable the PCIe, the property will be enable
by bootloader.

Signed-off-by: Bao Xiaowei 
---
v2:
 - no change

 arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi |1 +
 arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi |3 +++
 arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi |3 +++
 arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi |3 +++
 arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi |4 
 5 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi
index 5da732f..21f2b3b 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1012a.dtsi
@@ -496,6 +496,7 @@
< 0 0 2 &gic 0 111 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic 0 112 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic 0 113 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
};
 
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
index 3fed504..760d510 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1043a.dtsi
@@ -683,6 +683,7 @@
< 0 0 2 &gic 0 111 0x4>,
< 0 0 3 &gic 0 112 0x4>,
< 0 0 4 &gic 0 113 0x4>;
+   status = "disabled";
};
 
pcie@350 {
@@ -708,6 +709,7 @@
< 0 0 2 &gic 0 121 0x4>,
< 0 0 3 &gic 0 122 0x4>,
< 0 0 4 &gic 0 123 0x4>;
+   status = "disabled";
};
 
pcie@360 {
@@ -733,6 +735,7 @@
< 0 0 2 &gic 0 155 0x4>,
< 0 0 3 &gic 0 156 0x4>,
< 0 0 4 &gic 0 157 0x4>;
+   status = "disabled";
};
};
 
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
index 51cbd50..64d334c 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi
@@ -652,6 +652,7 @@
< 0 0 2 &gic GIC_SPI 110 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic GIC_SPI 110 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic GIC_SPI 110 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
pcie@350 {
@@ -677,6 +678,7 @@
< 0 0 2 &gic GIC_SPI 120 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic GIC_SPI 120 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic GIC_SPI 120 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
pcie@360 {
@@ -702,6 +704,7 @@
< 0 0 2 &gic GIC_SPI 154 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic GIC_SPI 154 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic GIC_SPI 154 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
};
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi 
b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
index a07f612..9deb9cb 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi
@@ -533,6 +533,7 @@
< 0 0 2 &gic 0 0 0 110 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic 0 0 0 111 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic 0 0 0 112 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
pcie@350 {
@@ -557,6 +558,7 @@
< 0 0 2 &gic 0 0 0 115 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic 0 0 0 116 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic 0 0 0 117 
IRQ_TYPE_LEVEL_HIGH>;
+   status = "disabled";
};
 
pcie@360 {
@@ -581,6 +583,7 @@
< 0 0 2 &gic 0 0 0 120 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 3 &gic 0 0 0 121 
IRQ_TYPE_LEVEL_HIGH>,
< 0 0 4 &gic 0 0 0 122 
IRQ_T