Re: [PATCH 18/19] KVM: PPC: Book3S HV: add passthrough support

2019-01-22 Thread Benjamin Herrenschmidt
On Tue, 2019-01-22 at 16:26 +1100, Paul Mackerras wrote:
> On Mon, Jan 07, 2019 at 08:10:05PM +0100, Cédric Le Goater wrote:
> > Clear the ESB pages from the VMA of the IRQ being pass through to the
> > guest and let the fault handler repopulate the VMA when the ESB pages
> > are accessed for an EOI or for a trigger.
> 
> Why do we want to do this?
> 
> I don't see any possible advantage to removing the PTEs from the
> userspace mapping.  You'll need to explain further.

Afaik bcs we change the mapping to point to the real HW irq ESB page
instead of the "IPI" that was there at VM init time.

Cedric, is that correct ?

Cheers,
Ben.




[PATCH] arch/powerpc/radix: Fix kernel crash with mremap

2019-01-22 Thread Aneesh Kumar K.V
With support for split pmd lock, we use pmd page pmd_huge_pte pointer to store
the deposited page table. In those config when we move page tables we need to
make sure we move the depoisted page table to the right pmd page. Otherwise this
can result in crash when we withdraw of deposited page table because we can find
the pmd_huge_pte NULL.

c04a1230 __split_huge_pmd+0x1070/0x1940
c04a0ff4 __split_huge_pmd+0xe34/0x1940 (unreliable)
c04a4000 vma_adjust_trans_huge+0x110/0x1c0
c042fe04 __vma_adjust+0x2b4/0x9b0
c04316e8 __split_vma+0x1b8/0x280
c043192c __do_munmap+0x13c/0x550
c0439390 sys_mremap+0x220/0x7e0
c000b488 system_call+0x5c/0x70

Fixes: 675d995297d4 ("powerpc/book3s64: Enable split pmd ptlock.")
Signed-off-by: Aneesh Kumar K.V 
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 22 +++-
 arch/powerpc/mm/pgtable-book3s64.c   | 22 
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h 
b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 92eaea164700..11703bfd3a63 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1258,21 +1258,13 @@ extern pmd_t pmdp_invalidate(struct vm_area_struct 
*vma, unsigned long address,
 
 #define pmd_move_must_withdraw pmd_move_must_withdraw
 struct spinlock;
-static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
-struct spinlock *old_pmd_ptl,
-struct vm_area_struct *vma)
-{
-   if (radix_enabled())
-   return false;
-   /*
-* Archs like ppc64 use pgtable to store per pmd
-* specific information. So when we switch the pmd,
-* we should also withdraw and deposit the pgtable
-*/
-   return true;
-}
-
-
+extern int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
+ struct spinlock *old_pmd_ptl,
+ struct vm_area_struct *vma);
+/*
+ * Hash translation mode use the deposited table to store hash pte
+ * slot information.
+ */
 #define arch_needs_pgtable_deposit arch_needs_pgtable_deposit
 static inline bool arch_needs_pgtable_deposit(void)
 {
diff --git a/arch/powerpc/mm/pgtable-book3s64.c 
b/arch/powerpc/mm/pgtable-book3s64.c
index 47c742f002ea..257baf342bff 100644
--- a/arch/powerpc/mm/pgtable-book3s64.c
+++ b/arch/powerpc/mm/pgtable-book3s64.c
@@ -425,3 +425,25 @@ void ptep_modify_prot_commit(struct vm_area_struct *vma, 
unsigned long addr,
  ptep, old_pte, pte);
set_pte_at(vma->vm_mm, addr, ptep, pte);
 }
+
+/* For hash translation mode, we use the deposited table to store
+ * store hash slot information and they are stored at PTRS_PER_PMD
+ * offset from related pmd location. Hence a pmd move requires
+ * deposit and withdraw.
+
+ * For radix translation with split pmd ptl, we store the deposited
+ * table in the pmd page. Hence if we have different pmd page we need
+ * to withdraw during pmd move.
+
+ * With hash we use deposited table always irrespective of anon or not.
+ * With radix we use deposited table only for anonymous mapping.
+ */
+int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
+  struct spinlock *old_pmd_ptl,
+  struct vm_area_struct *vma)
+{
+   if (radix_enabled())
+   return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma);
+
+   return true;
+}
-- 
2.20.1



Re: [PATCH kernel] vfio-pci/nvlink2: Fix ancient gcc warnings

2019-01-22 Thread Alex Williamson
Hi Geert,

The below patch comes about from the build regressions and improvements
list you've sent out, but something doesn't add up that we'd be testing
with an old compiler where initialization with { 0 } generates a
"missing braces around initialization" warning.  Is this really the
case or are we missing something here?  There's no harm that I can see
with Alexey's fix, but are these really just false positives from a
compiler bug that we should selectively ignore if the "fix" is less
clean?  Thanks,

Alex

On Wed, 23 Jan 2019 15:07:11 +1100
Alexey Kardashevskiy  wrote:

> Using the {0} construct as a generic initializer is perfectly fine in C,
> however due to a bug in old gcc there is a warning:
> 
>   + /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
> initialization for 'cap.header') [-Wmissing-braces]:  => 181:9
> 
> Since for whatever reason we still want to compile the modern kernel
> with such an old gcc without warnings, this changes the capabilities
> initialization.
> 
> The gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
> 
> Signed-off-by: Alexey Kardashevskiy 
> ---
>  drivers/vfio/pci/vfio_pci_nvlink2.c | 30 ++---
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_nvlink2.c 
> b/drivers/vfio/pci/vfio_pci_nvlink2.c
> index 054a2cf..91d945b 100644
> --- a/drivers/vfio/pci/vfio_pci_nvlink2.c
> +++ b/drivers/vfio/pci/vfio_pci_nvlink2.c
> @@ -178,11 +178,11 @@ static int vfio_pci_nvgpu_add_capability(struct 
> vfio_pci_device *vdev,
>   struct vfio_pci_region *region, struct vfio_info_cap *caps)
>  {
>   struct vfio_pci_nvgpu_data *data = region->data;
> - struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
> -
> - cap.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
> - cap.header.version = 1;
> - cap.tgt = data->gpu_tgt;
> + struct vfio_region_info_cap_nvlink2_ssatgt cap = {
> + .header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
> + .header.version = 1,
> + .tgt = data->gpu_tgt
> + };
>  
>   return vfio_info_add_capability(caps, &cap.header, sizeof(cap));
>  }
> @@ -365,18 +365,18 @@ static int vfio_pci_npu2_add_capability(struct 
> vfio_pci_device *vdev,
>   struct vfio_pci_region *region, struct vfio_info_cap *caps)
>  {
>   struct vfio_pci_npu2_data *data = region->data;
> - struct vfio_region_info_cap_nvlink2_ssatgt captgt = { 0 };
> - struct vfio_region_info_cap_nvlink2_lnkspd capspd = { 0 };
> + struct vfio_region_info_cap_nvlink2_ssatgt captgt = {
> + .header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
> + .header.version = 1,
> + .tgt = data->gpu_tgt
> + };
> + struct vfio_region_info_cap_nvlink2_lnkspd capspd = {
> + .header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD,
> + .header.version = 1,
> + .link_speed = data->link_speed
> + };
>   int ret;
>  
> - captgt.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
> - captgt.header.version = 1;
> - captgt.tgt = data->gpu_tgt;
> -
> - capspd.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD;
> - capspd.header.version = 1;
> - capspd.link_speed = data->link_speed;
> -
>   ret = vfio_info_add_capability(caps, &captgt.header, sizeof(captgt));
>   if (ret)
>   return ret;



[PATCH kernel] vfio-pci/nvlink2: Fix ancient gcc warnings

2019-01-22 Thread Alexey Kardashevskiy
Using the {0} construct as a generic initializer is perfectly fine in C,
however due to a bug in old gcc there is a warning:

  + /kisskb/src/drivers/vfio/pci/vfio_pci_nvlink2.c: warning: (near
initialization for 'cap.header') [-Wmissing-braces]:  => 181:9

Since for whatever reason we still want to compile the modern kernel
with such an old gcc without warnings, this changes the capabilities
initialization.

The gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

Signed-off-by: Alexey Kardashevskiy 
---
 drivers/vfio/pci/vfio_pci_nvlink2.c | 30 ++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/vfio/pci/vfio_pci_nvlink2.c 
b/drivers/vfio/pci/vfio_pci_nvlink2.c
index 054a2cf..91d945b 100644
--- a/drivers/vfio/pci/vfio_pci_nvlink2.c
+++ b/drivers/vfio/pci/vfio_pci_nvlink2.c
@@ -178,11 +178,11 @@ static int vfio_pci_nvgpu_add_capability(struct 
vfio_pci_device *vdev,
struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
struct vfio_pci_nvgpu_data *data = region->data;
-   struct vfio_region_info_cap_nvlink2_ssatgt cap = { 0 };
-
-   cap.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-   cap.header.version = 1;
-   cap.tgt = data->gpu_tgt;
+   struct vfio_region_info_cap_nvlink2_ssatgt cap = {
+   .header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+   .header.version = 1,
+   .tgt = data->gpu_tgt
+   };
 
return vfio_info_add_capability(caps, &cap.header, sizeof(cap));
 }
@@ -365,18 +365,18 @@ static int vfio_pci_npu2_add_capability(struct 
vfio_pci_device *vdev,
struct vfio_pci_region *region, struct vfio_info_cap *caps)
 {
struct vfio_pci_npu2_data *data = region->data;
-   struct vfio_region_info_cap_nvlink2_ssatgt captgt = { 0 };
-   struct vfio_region_info_cap_nvlink2_lnkspd capspd = { 0 };
+   struct vfio_region_info_cap_nvlink2_ssatgt captgt = {
+   .header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT,
+   .header.version = 1,
+   .tgt = data->gpu_tgt
+   };
+   struct vfio_region_info_cap_nvlink2_lnkspd capspd = {
+   .header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD,
+   .header.version = 1,
+   .link_speed = data->link_speed
+   };
int ret;
 
-   captgt.header.id = VFIO_REGION_INFO_CAP_NVLINK2_SSATGT;
-   captgt.header.version = 1;
-   captgt.tgt = data->gpu_tgt;
-
-   capspd.header.id = VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD;
-   capspd.header.version = 1;
-   capspd.link_speed = data->link_speed;
-
ret = vfio_info_add_capability(caps, &captgt.header, sizeof(captgt));
if (ret)
return ret;
-- 
2.17.1



Re: [PATCH v9 00/22] Re-use nvram module

2019-01-22 Thread Finn Thain
On Tue, 22 Jan 2019, Greg Kroah-Hartman wrote:

> On Tue, Jan 15, 2019 at 03:18:56PM +1100, Finn Thain wrote:
> > The "generic" NVRAM module, drivers/char/generic_nvram.c, implements a
> > /dev/nvram misc device. This module is used only by 32-bit PowerPC
> > platforms.
> > 
> > The RTC "CMOS" NVRAM module, drivers/char/nvram.c, also implements a
> > /dev/nvram misc device. This module is now used only by x86 and m68k
> > thanks to commit 3ba9faedc180 ("char: nvram: disable on ARM").
> > 
> > The "generic" module cannot be used by x86 or m68k platforms because it
> > cannot co-exist with the "CMOS" module. One reason for that is the
> > CONFIG_GENERIC_NVRAM kludge in drivers/char/Makefile. Another reason is
> > that automatically loading the appropriate module would be impossible
> > because only one module can provide the char-major-10-144 alias.
> > 
> > A multi-platform kernel binary needs a single, generic module. With this
> > patch series, drivers/char/nvram.c becomes more generic and some of the
> > arch-specific code gets moved under arch/. The nvram module is then
> > usable by all m68k, powerpc and x86 platforms.
> > 
> > This allows for removal of drivers/char/generic_nvram.c as well as a
> > duplicate in arch/powerpc/kernel/nvram_64.c. By reducing the number of
> > /dev/nvram char misc device implementations, the number of bugs and
> > inconsistencies is also reduced.
> > 
> > This approach reduces inconsistencies between PPC32 and PPC64 and also
> > between PPC_PMAC and MAC. A uniform API has benefits for userspace.
> > 
> > For example, some error codes for some ioctl calls become consistent
> > across PowerPC platforms. The uniform API can potentially benefit any
> > bootloader that works across the various platforms having XPRAM
> > (e.g. Emile).
> > 
> > This patch series was tested on Atari, Mac, PowerMac (both 32-bit and
> > 64-bit) and ThinkPad hardware. AFAIK, it has not yet been tested on
> > pSeries or CHRP.
> > 
> > I think there are two possible merge strategies for this patch series.
> > The char misc maintainer could take the entire series. Alternatively,
> > the m68k maintainer could take patches 1 thru 16 (though some of these
> > have nothing to do with m68k) and after those patches reach mainline
> > the powerpc maintainer could take 17 thru 22.
> 
> I just took the whole series, thanks for doing this, looks good.
> 

Thanks, Greg.

I haven't seen any acks from powerpc maintainers yet...

-- 

> greg k-h
> 


Re: [PATCH] PCI: Use of_node_name_eq for node name comparisons

2019-01-22 Thread Bjorn Helgaas
[+cc Michael B]

On Wed, Dec 05, 2018 at 01:50:34PM -0600, Rob Herring wrote:
> Convert string compares of DT node names to use of_node_name_eq helper
> instead. This removes direct access to the node name pointer.
> 
> Cc: Benjamin Herrenschmidt 
> Cc: Paul Mackerras 
> Cc: Michael Ellerman 
> Cc: Bjorn Helgaas 
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-...@vger.kernel.org
> Signed-off-by: Rob Herring 

I applied the pci/of.c change to pci/misc for v5.1, thanks!

I dropped the rpaphp_core.c part because there's another patch
in-flight [1] that touches the same code, and it would be easier if
Michael picked up this change and added it to his series.

Bjorn

[1] 
https://lore.kernel.org/lkml/20181214205120.16435.46952.st...@powerkvm6.aus.stglabs.ibm.com/

> ---
>  drivers/pci/hotplug/rpaphp_core.c | 2 +-
>  drivers/pci/of.c  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/rpaphp_core.c 
> b/drivers/pci/hotplug/rpaphp_core.c
> index bcd5d357ca23..7697d9c92b98 100644
> --- a/drivers/pci/hotplug/rpaphp_core.c
> +++ b/drivers/pci/hotplug/rpaphp_core.c
> @@ -354,7 +354,7 @@ int rpaphp_add_slot(struct device_node *dn)
>   const int *indexes, *names, *types, *power_domains;
>   char *name, *type;
>  
> - if (!dn->name || strcmp(dn->name, "pci"))
> + if (!of_node_name_eq(dn, "pci"))
>   return 0;
>  
>   /* If this is not a hotplug slot, return without doing anything. */
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 4c4217d0c3f1..3d32da15c215 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -113,7 +113,7 @@ struct device_node *of_pci_find_child_device(struct 
> device_node *parent,
>* a fake root for all functions of a multi-function
>* device we go down them as well.
>*/
> - if (!strcmp(node->name, "multifunc-device")) {
> + if (of_node_name_eq(node, "multifunc-device")) {
>   for_each_child_of_node(node, node2) {
>   if (__of_pci_pci_compare(node2, devfn)) {
>   of_node_put(node);
> -- 
> 2.19.1
> 


Re: [RFC 5/6] powerpc/pci/hotplug: Use common drcinfo parsing

2019-01-22 Thread Bjorn Helgaas
On Mon, Jan 14, 2019 at 06:28:57PM -0600, Bjorn Helgaas wrote:
> On Fri, Dec 14, 2018 at 02:51:31PM -0600, Michael Bringmann wrote:
> > The implementation of the pseries-specific drc info properties
> > is currently implemented in pseries-specific and non-pseries-specific
> > files.  This patch set uses a new implementation of the device-tree
> > parsing code for the properties.
> > 
> > This patch refactors parsing of the pseries-specific drc-info properties
> > out of rpaphp_core.c to use the common parser.  In the case where an
> > architecture does not use these properties, an __weak copy of the
> > function is provided with dummy return values.  Changes include creating
> > appropriate callback functions and passing callback-specific data
> > blocks into arch_find_drc_match.  All functions that were used just
> > to support the previous parsing implementation have been moved.
> > 
> > Signed-off-by: Michael Bringmann 
> 
> This is fine with me.  Any rpaphp_core.c maintainers want to comment?
> Tyrel?
> 
> $ ./scripts/get_maintainer.pl -f drivers/pci/hotplug/rpaphp_core.c
> Tyrel Datwyler  (supporter:IBM Power PCI Hotplug 
> Driver for RPA-compliant...)
> Benjamin Herrenschmidt  (supporter:LINUX FOR 
> POWERPC (32-BIT AND 64-BIT))
> Paul Mackerras  (supporter:LINUX FOR POWERPC (32-BIT AND 
> 64-BIT))
> Michael Ellerman  (supporter:LINUX FOR POWERPC (32-BIT 
> AND 64-BIT))

This looks like part of a larger series, but I only got this patch.  So I
assume you'll route this elsewhere along with the rest of the series.
Here's my ack if it's useful:

Acked-by: Bjorn Helgaas 

> > ---
> >  drivers/pci/hotplug/rpaphp_core.c |  232 
> > -
> >  1 file changed, 28 insertions(+), 204 deletions(-)
> > 
> > diff --git a/drivers/pci/hotplug/rpaphp_core.c 
> > b/drivers/pci/hotplug/rpaphp_core.c
> > index bcd5d35..9ad7384 100644
> > --- a/drivers/pci/hotplug/rpaphp_core.c
> > +++ b/drivers/pci/hotplug/rpaphp_core.c
> > @@ -154,182 +154,18 @@ static enum pci_bus_speed get_max_bus_speed(struct 
> > slot *slot)
> > return speed;
> >  }
> >  
> > -static int get_children_props(struct device_node *dn, const int 
> > **drc_indexes,
> > -   const int **drc_names, const int **drc_types,
> > -   const int **drc_power_domains)
> > -{
> > -   const int *indexes, *names, *types, *domains;
> > -
> > -   indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
> > -   names = of_get_property(dn, "ibm,drc-names", NULL);
> > -   types = of_get_property(dn, "ibm,drc-types", NULL);
> > -   domains = of_get_property(dn, "ibm,drc-power-domains", NULL);
> > -
> > -   if (!indexes || !names || !types || !domains) {
> > -   /* Slot does not have dynamically-removable children */
> > -   return -EINVAL;
> > -   }
> > -   if (drc_indexes)
> > -   *drc_indexes = indexes;
> > -   if (drc_names)
> > -   /* &drc_names[1] contains NULL terminated slot names */
> > -   *drc_names = names;
> > -   if (drc_types)
> > -   /* &drc_types[1] contains NULL terminated slot types */
> > -   *drc_types = types;
> > -   if (drc_power_domains)
> > -   *drc_power_domains = domains;
> > -
> > -   return 0;
> > -}
> > -
> > -
> >  /* Verify the existence of 'drc_name' and/or 'drc_type' within the
> > - * current node.  First obtain it's my-drc-index property.  Next,
> > - * obtain the DRC info from it's parent.  Use the my-drc-index for
> > - * correlation, and obtain/validate the requested properties.
> > + * current node.
> >   */
> >  
> > -static int rpaphp_check_drc_props_v1(struct device_node *dn, char 
> > *drc_name,
> > -   char *drc_type, unsigned int my_index)
> > -{
> > -   char *name_tmp, *type_tmp;
> > -   const int *indexes, *names;
> > -   const int *types, *domains;
> > -   int i, rc;
> > -
> > -   rc = get_children_props(dn->parent, &indexes, &names, &types, &domains);
> > -   if (rc < 0) {
> > -   return -EINVAL;
> > -   }
> > -
> > -   name_tmp = (char *) &names[1];
> > -   type_tmp = (char *) &types[1];
> > -
> > -   /* Iterate through parent properties, looking for my-drc-index */
> > -   for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
> > -   if ((unsigned int) indexes[i + 1] == my_index)
> > -   break;
> > -
> > -   name_tmp += (strlen(name_tmp) + 1);
> > -   type_tmp += (strlen(type_tmp) + 1);
> > -   }
> > -
> > -   if (((drc_name == NULL) || (drc_name && !strcmp(drc_name, name_tmp))) &&
> > -   ((drc_type == NULL) || (drc_type && !strcmp(drc_type, type_tmp
> > -   return 0;
> > -
> > -   return -EINVAL;
> > -}
> > -
> > -static int rpaphp_check_drc_props_v2(struct device_node *dn, char 
> > *drc_name,
> > -   char *drc_type, unsigned int my_index)
> > -{
> > -   struct property *info;
> > -   unsigned int entries;
> > -   struct of_drc_info drc;
> > -   const __be32 *value;
> > -   char cell_drc_name[MAX_DRC_NA

Re: [PATCH v13 00/10] powerpc: Switch to CONFIG_THREAD_INFO_IN_TASK

2019-01-22 Thread Christophe Leroy




Le 19/01/2019 à 11:23, Michael Ellerman a écrit :

Christophe Leroy  writes:


The purpose of this serie is to activate CONFIG_THREAD_INFO_IN_TASK which
moves the thread_info into task_struct.

Moving thread_info into task_struct has the following advantages:
- It protects thread_info from corruption in the case of stack
overflows.
- Its address is harder to determine if stack addresses are
leaked, making a number of attacks more difficult.

Changes since v12:
  - Patch 1: Taken comment from Mike (re-introduced the 'panic' in case 
memblock allocation fails in setup_64.c
  - Patch 1: Added alloc_stack() function in setup_32.c to also panic in case 
of allocation failure.


Hi Christophe,

I can't get this series to boot on qemu mac99. I'm getting eg:

[0.981514] NFS: Registering the id_resolver key type
[0.981752] Key type id_resolver registered
[0.981868] Key type id_legacy registered
[0.995711] Unrecoverable exception 0 at 0 (msr=0)
[0.996091] Oops: Unrecoverable exception, sig: 6 [#1]
[0.996314] BE PAGE_SIZE=4K MMU=Hash PowerMac
[0.996617] Modules linked in:
[0.996869] CPU: 0 PID: 416 Comm: modprobe Not tainted 
5.0.0-rc2-gcc-7.3.0-00043-g53f2de798792 #342
[0.997138] NIP:   LR:  CTR: 
[0.997309] REGS: ef237f50 TRAP:    Not tainted  
(5.0.0-rc2-gcc-7.3.0-00043-g53f2de798792)
[0.997508] MSR:   <>  CR:   XER: 
[0.997712]
[0.997712] GPR00:  ef238000     
 
[0.997712] GPR08:       
c006477c ef13d8c0
[0.997712] GPR16:       
 
[0.997712] GPR24:       
 
[0.998671] NIP []   (null)
[0.998774] LR []   (null)
[0.998895] Call Trace:
[0.999030] Instruction dump:
[0.999320]        

[0.999546]     6000   

[1.23] ---[ end trace 925ea3419844fe68 ]---


No such issue on my side. Do you have a ramdisk with anythink special or 
a special config ? I see your kernel is modprobing something, know what 
it is ?


Especially, what is the amount of memory in your config ? On my side 
there is 128M:


Memory: 120292K/131072K available (6116K kernel code, 572K rwdata, 2036K 
rodata,

 340K init, 191K bss, 10780K reserved, 0K cma-reserved, 0K highmem)
Kernel virtual memory layout:
  * 0xfffcf000..0xf000  : fixmap
  * 0xff80..0xffc0  : highmem PTEs
  * 0xfef36000..0xff80  : early ioremap
  * 0xc900..0xfef36000  : vmalloc & ioremap

This means the addresses in which your kernel faults are in vmalloc 
area. It's not normal I believe, is it ?


On my side it gives the following on qemu mac99 (I have no disk).

[...]
Initialise system trusted keyrings
workingset: timestamp_bits=30 max_order=15 bucket_order=0
NFS: Registering the id_resolver key type
Key type id_resolver registered
Key type id_legacy registered
Key type asymmetric registered
Asymmetric key parser 'x509' registered
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
io scheduler mq-deadline registered
io scheduler kyber registered
Using unsupported 800x600 (null) at 8100, depth=32, pitch=3200
Console: switching to colour frame buffer device 100x37
fb0: Open Firmware frame buffer device on /pci@f200/QEMU,VGA@e
Generic non-volatile memory driver v1.1
brd: module loaded
loop: module loaded
MacIO PCI driver attached to Keylargo chipset
Macintosh Cuda and Egret driver.
mesh: configured for synchronous 5 MB/s
st: Version 20160209, fixed bufsize 32768, s/g segs 256
Detected ADB keyboard, type ANSI.
input: ADB keyboard as /devices/virtual/input/input0
random: fast init done
input: ADB mouse as /devices/virtual/input/input1
pata-macio 0.0002:ata-3: Activating pata-macio chipset KeyLargo 
ATA-3, Apple

 bus ID 0
scsi host0: pata_macio
ata1: PATA max MWDMA2 irq 16
pata-macio 0.00021000:ata-3: Activating pata-macio chipset KeyLargo 
ATA-3, Apple

 bus ID 1
scsi host1: pata_macio
ata2: PATA max MWDMA2 irq 18
pcnet32: pcnet32.c:v1.35 21.Apr.2008 tsbog...@alpha.franken.de
PPP generic driver version 2.4.2
PPP Deflate Compression module registered
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci-pci: OHCI PCI platform driver
ohci-pci :00:0d.0: OHCI PCI host controller
ohci-pci :00:0d.0: new USB bus registered, assigned bus number 1
ohci-pci :00:0d.0: irq 28, io mem 0x8008
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 3 ports detected
usbcore: registered new interface driver appletouch
rtc-generic rtc-generic: registered as rtc0
APM Battery Driver
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
oprofile: using timer interrupt.
Initializing XFRM netlink socket
NET: Registered p

[PATCH 4/4] powerpc/livepatch: return -ERRNO values in save_stack_trace_tsk_reliable()

2019-01-22 Thread Joe Lawrence
To match its x86 counterpart, save_stack_trace_tsk_reliable() should
return -EINVAL in cases that it is currently returning 1.  No caller is
currently differentiating non-zero error codes, but let's keep the
arch-specific implementations consistent.

Signed-off-by: Joe Lawrence 
---
 arch/powerpc/kernel/stacktrace.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index 28c3c25755d7..cf31ce6c1f53 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -133,7 +133,7 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
 
if (sp < stack_page + sizeof(struct thread_struct) ||
sp > stack_end - STACK_FRAME_MIN_SIZE) {
-   return 1;
+   return -EINVAL;
}
 
for (firstframe = true; sp != stack_end;
@@ -143,16 +143,16 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
 
/* sanity check: ABI requires SP to be aligned 16 bytes. */
if (sp & 0xF)
-   return 1;
+   return -EINVAL;
 
newsp = stack[0];
/* Stack grows downwards; unwinder may only go up. */
if (newsp <= sp)
-   return 1;
+   return -EINVAL;
 
if (newsp != stack_end &&
newsp > stack_end - STACK_FRAME_MIN_SIZE) {
-   return 1; /* invalid backlink, too far up. */
+   return -EINVAL; /* invalid backlink, too far up. */
}
 
/*
@@ -166,13 +166,13 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
/* Mark stacktraces with exception frames as unreliable. */
if (sp <= stack_end - STACK_INT_FRAME_SIZE &&
stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
-   return 1;
+   return -EINVAL;
}
 
/* Examine the saved LR: it must point into kernel code. */
ip = stack[STACK_FRAME_LR_SAVE];
if (!__kernel_text_address(ip))
-   return 1;
+   return -EINVAL;
 
/*
 * FIXME: IMHO these tests do not belong in
@@ -185,7 +185,7 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
 * as unreliable.
 */
if (ip == (unsigned long)kretprobe_trampoline)
-   return 1;
+   return -EINVAL;
 #endif
 
if (trace->nr_entries >= trace->max_entries)
-- 
2.20.1



[PATCH 3/4] powerpc/livepatch: small cleanups in save_stack_trace_tsk_reliable()

2019-01-22 Thread Joe Lawrence
Mostly cosmetic changes:

- Group common stack pointer code at the top
- Simplify the first frame logic
- Code stackframe iteration into for...loop construct
- Check for trace->nr_entries overflow before adding any into the array

Suggested-by: Nicolai Stange 
Signed-off-by: Joe Lawrence 
---
 arch/powerpc/kernel/stacktrace.c | 40 +++-
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index 06688f4d557b..28c3c25755d7 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -95,20 +95,11 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
struct stack_trace *trace)
 {
unsigned long sp;
+   unsigned long newsp;
unsigned long stack_page = (unsigned long)task_stack_page(tsk);
unsigned long stack_end;
int graph_idx = 0;
-
-   /*
-* The last frame (unwinding first) may not yet have saved
-* its LR onto the stack.
-*/
-   int firstframe = 1;
-
-   if (tsk == current)
-   sp = current_stack_pointer();
-   else
-   sp = tsk->thread.ksp;
+   bool firstframe;
 
stack_end = stack_page + THREAD_SIZE;
if (!is_idle_task(tsk)) {
@@ -135,14 +126,20 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
stack_end -= STACK_FRAME_OVERHEAD;
}
 
+   if (tsk == current)
+   sp = current_stack_pointer();
+   else
+   sp = tsk->thread.ksp;
+
if (sp < stack_page + sizeof(struct thread_struct) ||
sp > stack_end - STACK_FRAME_MIN_SIZE) {
return 1;
}
 
-   for (;;) {
+   for (firstframe = true; sp != stack_end;
+firstframe = false, sp = newsp) {
unsigned long *stack = (unsigned long *) sp;
-   unsigned long newsp, ip;
+   unsigned long ip;
 
/* sanity check: ABI requires SP to be aligned 16 bytes. */
if (sp & 0xF)
@@ -163,10 +160,8 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
 * rest of the frame may be uninitialized, continue to
 * the next.
 */
-   if (firstframe) {
-   firstframe = 0;
-   goto next;
-   }
+   if (firstframe)
+   continue;
 
/* Mark stacktraces with exception frames as unreliable. */
if (sp <= stack_end - STACK_INT_FRAME_SIZE &&
@@ -193,19 +188,12 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
return 1;
 #endif
 
+   if (trace->nr_entries >= trace->max_entries)
+   return -E2BIG;
if (!trace->skip)
trace->entries[trace->nr_entries++] = ip;
else
trace->skip--;
-
-next:
-   if (newsp == stack_end)
-   break;
-
-   if (trace->nr_entries >= trace->max_entries)
-   return -E2BIG;
-
-   sp = newsp;
}
return 0;
 }
-- 
2.20.1



[PATCH 2/4] powerpc/livepatch: relax reliable stack tracer checks for first-frame

2019-01-22 Thread Joe Lawrence
The bottom-most stack frame (the first to be unwound) may be largely
uninitialized, for the "Power Architecture 64-Bit ELF V2 ABI" only
requires its backchain pointer to be set.

The reliable stack tracer should be careful when verifying this frame:
skip checks on STACK_FRAME_LR_SAVE and STACK_FRAME_MARKER offsets that
may contain uninitialized residual data.

Fixes: df78d3f61480 ("powerpc/livepatch: Implement reliable stack tracing for 
the consistency model")
Signed-off-by: Joe Lawrence 
---
 arch/powerpc/kernel/stacktrace.c | 32 
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index e2c50b55138f..06688f4d557b 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -84,6 +84,12 @@ save_stack_trace_regs(struct pt_regs *regs, struct 
stack_trace *trace)
 EXPORT_SYMBOL_GPL(save_stack_trace_regs);
 
 #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE
+/*
+ * This function returns an error if it detects any unreliable features of the
+ * stack.  Otherwise it guarantees that the stack trace is reliable.
+ *
+ * If the task is not 'current', the caller *must* ensure the task is inactive.
+ */
 int
 save_stack_trace_tsk_reliable(struct task_struct *tsk,
struct stack_trace *trace)
@@ -142,12 +148,6 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
if (sp & 0xF)
return 1;
 
-   /* Mark stacktraces with exception frames as unreliable. */
-   if (sp <= stack_end - STACK_INT_FRAME_SIZE &&
-   stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
-   return 1;
-   }
-
newsp = stack[0];
/* Stack grows downwards; unwinder may only go up. */
if (newsp <= sp)
@@ -158,11 +158,26 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
return 1; /* invalid backlink, too far up. */
}
 
+   /*
+* We can only trust the bottom frame's backlink, the
+* rest of the frame may be uninitialized, continue to
+* the next.
+*/
+   if (firstframe) {
+   firstframe = 0;
+   goto next;
+   }
+
+   /* Mark stacktraces with exception frames as unreliable. */
+   if (sp <= stack_end - STACK_INT_FRAME_SIZE &&
+   stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
+   return 1;
+   }
+
/* Examine the saved LR: it must point into kernel code. */
ip = stack[STACK_FRAME_LR_SAVE];
-   if (!firstframe && !__kernel_text_address(ip))
+   if (!__kernel_text_address(ip))
return 1;
-   firstframe = 0;
 
/*
 * FIXME: IMHO these tests do not belong in
@@ -183,6 +198,7 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
else
trace->skip--;
 
+next:
if (newsp == stack_end)
break;
 
-- 
2.20.1



[PATCH 1/4] powerpc/64s: Clear on-stack exception marker upon exception return

2019-01-22 Thread Joe Lawrence
From: Nicolai Stange 

The ppc64 specific implementation of the reliable stacktracer,
save_stack_trace_tsk_reliable(), bails out and reports an "unreliable
trace" whenever it finds an exception frame on the stack. Stack frames
are classified as exception frames if the STACK_FRAME_REGS_MARKER magic,
as written by exception prologues, is found at a particular location.

However, as observed by Joe Lawrence, it is possible in practice that
non-exception stack frames can alias with prior exception frames and thus,
that the reliable stacktracer can find a stale STACK_FRAME_REGS_MARKER on
the stack. It in turn falsely reports an unreliable stacktrace and blocks
any live patching transition to finish. Said condition lasts until the
stack frame is overwritten/initialized by function call or other means.

In principle, we could mitigate this by making the exception frame
classification condition in save_stack_trace_tsk_reliable() stronger:
in addition to testing for STACK_FRAME_REGS_MARKER, we could also take into
account that for all exceptions executing on the kernel stack
- their stack frames's backlink pointers always match what is saved
  in their pt_regs instance's ->gpr[1] slot and that
- their exception frame size equals STACK_INT_FRAME_SIZE, a value
  uncommonly large for non-exception frames.

However, while these are currently true, relying on them would make the
reliable stacktrace implementation more sensitive towards future changes in
the exception entry code. Note that false negatives, i.e. not detecting
exception frames, would silently break the live patching consistency model.

Furthermore, certain other places (diagnostic stacktraces, perf, xmon)
rely on STACK_FRAME_REGS_MARKER as well.

Make the exception exit code clear the on-stack STACK_FRAME_REGS_MARKER
for those exceptions running on the "normal" kernel stack and returning
to kernelspace: because the topmost frame is ignored by the reliable stack
tracer anyway, returns to userspace don't need to take care of clearing
the marker.

Furthermore, as I don't have the ability to test this on Book 3E or
32 bits, limit the change to Book 3S and 64 bits.

Finally, make the HAVE_RELIABLE_STACKTRACE Kconfig option depend on
PPC_BOOK3S_64 for documentation purposes. Before this patch, it depended
on PPC64 && CPU_LITTLE_ENDIAN and because CPU_LITTLE_ENDIAN implies
PPC_BOOK3S_64, there's no functional change here.

Fixes: df78d3f61480 ("powerpc/livepatch: Implement reliable stack tracing for 
the consistency model")
Reported-by: Joe Lawrence 
Signed-off-by: Nicolai Stange 
Signed-off-by: Joe Lawrence 
---
 arch/powerpc/Kconfig   | 2 +-
 arch/powerpc/kernel/entry_64.S | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2890d36eb531..73bf87b1d274 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -220,7 +220,7 @@ config PPC
select HAVE_PERF_USER_STACK_DUMP
select HAVE_RCU_TABLE_FREE  if SMP
select HAVE_REGS_AND_STACK_ACCESS_API
-   select HAVE_RELIABLE_STACKTRACE if PPC64 && CPU_LITTLE_ENDIAN
+   select HAVE_RELIABLE_STACKTRACE if PPC_BOOK3S_64 && 
CPU_LITTLE_ENDIAN
select HAVE_SYSCALL_TRACEPOINTS
select HAVE_VIRT_CPU_ACCOUNTING
select HAVE_IRQ_TIME_ACCOUNTING
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 435927f549c4..a2c168b395d2 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -1002,6 +1002,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
ld  r2,_NIP(r1)
mtspr   SPRN_SRR0,r2
 
+   /*
+* Leaving a stale exception_marker on the stack can confuse
+* the reliable stack unwinder later on. Clear it.
+*/
+   li  r2,0
+   std r2,STACK_FRAME_OVERHEAD-16(r1)
+
ld  r0,GPR0(r1)
ld  r2,GPR2(r1)
ld  r3,GPR3(r1)
-- 
2.20.1



[PATCH 0/4] powerpc/livepatch: reliable stack unwinder fixes

2019-01-22 Thread Joe Lawrence
This patchset fixes a false negative report (ie, unreliable) from the
ppc64 reliable stack unwinder, discussed here [1] when it may
inadvertently trip over a stale exception marker left on the stack.

The first two patches fix this bug.  Nicolai's change clears the marker
from the stack when an exception is finished.  The next patch modifies
the unwinder to only look for such on stack elements when the ABI
guarantees that they will actually be initialized.

The final two patches consist of code cleanups that Nicolai and I
spotted during the development of the fixes.

Testing included re-running the original test scenario (loading a
livepatch module on ppc64le) on a 5.0.0-rc2 kernel as well as a RHEL-7
backport.  I ran internal tests on the RHEL-7 backport and no new test
failures were introduced.  I believe that Nicolai has done the same
with respect to the first patch.

[1] 
https://lore.kernel.org/lkml/7f468285-b149-37e2-e782-c9e538b99...@redhat.com/

Joe Lawrence (3):
  powerpc/livepatch: relax reliable stack tracer checks for first-frame
  powerpc/livepatch: small cleanups in save_stack_trace_tsk_reliable()
  powerpc/livepatch: return -ERRNO values in
save_stack_trace_tsk_reliable()

Nicolai Stange (1):
  powerpc/64s: Clear on-stack exception marker upon exception return

 arch/powerpc/Kconfig |  2 +-
 arch/powerpc/kernel/entry_64.S   |  7 +++
 arch/powerpc/kernel/stacktrace.c | 74 +---
 3 files changed, 47 insertions(+), 36 deletions(-)

-- 
2.20.1



[PATCH v4 3/3] powerpc/32: Add KASAN support

2019-01-22 Thread Christophe Leroy
This patch adds KASAN support for PPC32.

Note that on book3s it will only work on the 603 because the other
ones use hash table and can therefore not share a single PTE table
covering the entire early KASAN shadow area.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/Kconfig |  1 +
 arch/powerpc/include/asm/book3s/32/pgtable.h |  2 +
 arch/powerpc/include/asm/kasan.h | 24 
 arch/powerpc/include/asm/nohash/32/pgtable.h |  2 +
 arch/powerpc/include/asm/ppc_asm.h   |  5 ++
 arch/powerpc/include/asm/setup.h |  5 ++
 arch/powerpc/include/asm/string.h| 14 +
 arch/powerpc/kernel/Makefile |  9 ++-
 arch/powerpc/kernel/early_32.c   |  1 +
 arch/powerpc/kernel/prom_init_check.sh   | 10 +++-
 arch/powerpc/kernel/setup-common.c   |  2 +
 arch/powerpc/kernel/setup_32.c   |  3 +
 arch/powerpc/lib/Makefile|  8 +++
 arch/powerpc/lib/copy_32.S   |  9 ++-
 arch/powerpc/mm/Makefile |  3 +
 arch/powerpc/mm/dump_linuxpagetables.c   |  8 +++
 arch/powerpc/mm/kasan_init.c | 86 
 arch/powerpc/mm/mem.c|  4 ++
 18 files changed, 190 insertions(+), 6 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kasan.h
 create mode 100644 arch/powerpc/mm/kasan_init.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2890d36eb531..11dcaa80d3ff 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -175,6 +175,7 @@ config PPC
select GENERIC_TIME_VSYSCALL
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_JUMP_LABEL
+   select HAVE_ARCH_KASAN  if PPC32
select HAVE_ARCH_KGDB
select HAVE_ARCH_MMAP_RND_BITS
select HAVE_ARCH_MMAP_RND_COMPAT_BITS   if COMPAT
diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
b/arch/powerpc/include/asm/book3s/32/pgtable.h
index 49d76adb9bc5..4543016f80ca 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -141,6 +141,8 @@ static inline bool pte_user(pte_t pte)
  */
 #ifdef CONFIG_HIGHMEM
 #define KVIRT_TOP  PKMAP_BASE
+#elif defined(CONFIG_KASAN)
+#define KVIRT_TOP  KASAN_SHADOW_START
 #else
 #define KVIRT_TOP  (0xfe00UL)  /* for now, could be FIXMAP_BASE ? */
 #endif
diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
new file mode 100644
index ..5d0088429b62
--- /dev/null
+++ b/arch/powerpc/include/asm/kasan.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_KASAN_H
+#define __ASM_KASAN_H
+
+#ifndef __ASSEMBLY__
+
+#include 
+#include 
+#include 
+
+#define KASAN_SHADOW_SCALE_SHIFT   3
+#define KASAN_SHADOW_SIZE  ((~0UL - PAGE_OFFSET + 1) >> 
KASAN_SHADOW_SCALE_SHIFT)
+
+#define KASAN_SHADOW_START (ALIGN_DOWN(FIXADDR_START - KASAN_SHADOW_SIZE, \
+   PGDIR_SIZE))
+#define KASAN_SHADOW_END   (KASAN_SHADOW_START + KASAN_SHADOW_SIZE)
+#define KASAN_SHADOW_OFFSET(KASAN_SHADOW_START - \
+(PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT))
+
+void kasan_early_init(void);
+void kasan_init(void);
+
+#endif
+#endif
diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h 
b/arch/powerpc/include/asm/nohash/32/pgtable.h
index bed433358260..b3b52f02be1a 100644
--- a/arch/powerpc/include/asm/nohash/32/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
@@ -71,6 +71,8 @@ extern int icache_44x_need_flush;
  */
 #ifdef CONFIG_HIGHMEM
 #define KVIRT_TOP  PKMAP_BASE
+#elif defined(CONFIG_KASAN)
+#define KVIRT_TOP  KASAN_SHADOW_START
 #else
 #define KVIRT_TOP  (0xfe00UL)  /* for now, could be FIXMAP_BASE ? */
 #endif
diff --git a/arch/powerpc/include/asm/ppc_asm.h 
b/arch/powerpc/include/asm/ppc_asm.h
index e0637730a8e7..8d5291c721fa 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -251,6 +251,11 @@ GLUE(.,name):
 
 #define _GLOBAL_TOC(name) _GLOBAL(name)
 
+#define KASAN_OVERRIDE(x, y) \
+   .weak x; \
+   .set x, y
+
+
 #endif
 
 /*
diff --git a/arch/powerpc/include/asm/setup.h b/arch/powerpc/include/asm/setup.h
index 65676e2325b8..da7768aa996a 100644
--- a/arch/powerpc/include/asm/setup.h
+++ b/arch/powerpc/include/asm/setup.h
@@ -74,6 +74,11 @@ static inline void setup_spectre_v2(void) {};
 #endif
 void do_btb_flush_fixups(void);
 
+#ifndef CONFIG_KASAN
+static inline void kasan_early_init(void) { }
+static inline void kasan_init(void) { }
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* _ASM_POWERPC_SETUP_H */
diff --git a/arch/powerpc/include/asm/string.h 
b/arch/powerpc/include/asm/string.h
index 1647de15a31e..64d44d4836b4 100644
--- a/arch/powerpc/include/asm/string.h
+++ b/arch/powerpc/include/asm/string.h
@@ -27,6 +27,20 @@ extern int memcmp(const void *,cons

[PATCH v4 2/3] powerpc/32: Move early_init() in a separate file

2019-01-22 Thread Christophe Leroy
In preparation of KASAN, move early_init() into a separate
file in order to allow deactivation of KASAN for that function.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/Makefile   |  2 +-
 arch/powerpc/kernel/early_32.c | 35 +++
 arch/powerpc/kernel/setup_32.c | 26 --
 3 files changed, 36 insertions(+), 27 deletions(-)
 create mode 100644 arch/powerpc/kernel/early_32.c

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index cb7f0bb9ee71..879b36602748 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -93,7 +93,7 @@ extra-y   += vmlinux.lds
 
 obj-$(CONFIG_RELOCATABLE)  += reloc_$(BITS).o
 
-obj-$(CONFIG_PPC32)+= entry_32.o setup_32.o
+obj-$(CONFIG_PPC32)+= entry_32.o setup_32.o early_32.o
 obj-$(CONFIG_PPC64)+= dma-iommu.o iommu.o
 obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_BOOTX_TEXT)   += btext.o
diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c
new file mode 100644
index ..b3e40d6d651c
--- /dev/null
+++ b/arch/powerpc/kernel/early_32.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Early init before relocation
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * We're called here very early in the boot.
+ *
+ * Note that the kernel may be running at an address which is different
+ * from the address that it was linked at, so we must use RELOC/PTRRELOC
+ * to access static data (including strings).  -- paulus
+ */
+notrace unsigned long __init early_init(unsigned long dt_ptr)
+{
+   unsigned long offset = reloc_offset();
+
+   /* First zero the BSS */
+   memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
+
+   /*
+* Identify the CPU type and fix up code sections
+* that depend on which cpu we have.
+*/
+   identify_cpu(offset, mfspr(SPRN_PVR));
+
+   apply_feature_fixups();
+
+   return KERNELBASE + offset;
+}
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 5e761eb16a6d..b46a9a33225b 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -63,32 +63,6 @@ EXPORT_SYMBOL(DMA_MODE_READ);
 EXPORT_SYMBOL(DMA_MODE_WRITE);
 
 /*
- * We're called here very early in the boot.
- *
- * Note that the kernel may be running at an address which is different
- * from the address that it was linked at, so we must use RELOC/PTRRELOC
- * to access static data (including strings).  -- paulus
- */
-notrace unsigned long __init early_init(unsigned long dt_ptr)
-{
-   unsigned long offset = reloc_offset();
-
-   /* First zero the BSS */
-   memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
-
-   /*
-* Identify the CPU type and fix up code sections
-* that depend on which cpu we have.
-*/
-   identify_cpu(offset, mfspr(SPRN_PVR));
-
-   apply_feature_fixups();
-
-   return KERNELBASE + offset;
-}
-
-
-/*
  * This is run before start_kernel(), the kernel has been relocated
  * and we are running with enough of the MMU enabled to have our
  * proper kernel virtual addresses
-- 
2.13.3



[PATCH v4 1/3] powerpc/mm: prepare kernel for KAsan on PPC32

2019-01-22 Thread Christophe Leroy
In kernel/cputable.c, explicitly use memcpy() in order
to allow GCC to replace it with __memcpy() when KASAN is
selected.

Since commit 400c47d81ca38 ("powerpc32: memset: only use dcbz once cache is
enabled"), memset() can be used before activation of the cache,
so no need to use memset_io() for zeroing the BSS.

Acked-by: Dmitry Vyukov 
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/cputable.c | 13 ++---
 arch/powerpc/kernel/setup_32.c |  6 ++
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 1eab54bc6ee9..cd12f362b61f 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -2147,7 +2147,11 @@ void __init set_cur_cpu_spec(struct cpu_spec *s)
struct cpu_spec *t = &the_cpu_spec;
 
t = PTRRELOC(t);
-   *t = *s;
+   /*
+* use memcpy() instead of *t = *s so that GCC replaces it
+* by __memcpy() when KASAN is active
+*/
+   memcpy(t, s, sizeof(*t));
 
*PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
 }
@@ -2161,8 +2165,11 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned 
long offset,
t = PTRRELOC(t);
old = *t;
 
-   /* Copy everything, then do fixups */
-   *t = *s;
+   /*
+* Copy everything, then do fixups. Use memcpy() instead of *t = *s
+* so that GCC replaces it by __memcpy() when KASAN is active
+*/
+   memcpy(t, s, sizeof(*t));
 
/*
 * If we are overriding a previous value derived from the real
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 947f904688b0..5e761eb16a6d 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -73,10 +73,8 @@ notrace unsigned long __init early_init(unsigned long dt_ptr)
 {
unsigned long offset = reloc_offset();
 
-   /* First zero the BSS -- use memset_io, some platforms don't have
-* caches on yet */
-   memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
-   __bss_stop - __bss_start);
+   /* First zero the BSS */
+   memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
 
/*
 * Identify the CPU type and fix up code sections
-- 
2.13.3



[PATCH v4 0/3] KASAN for powerpc/32

2019-01-22 Thread Christophe Leroy
This serie adds KASAN support to powerpc/32

Tested on nohash/32 (8xx) and book3s/32 (mpc832x ie 603)

Changes in v4:
- Comments from Andrey (DISABLE_BRANCH_PROFILING, Activation of reports)
- Proper initialisation of shadow area in kasan_init()
- Panic in case Hash table is required.
- Added comments in patch one to explain why *t = *s becomes memcpy(t, s, ...)
- Call of kasan_init_tags()

Changes in v3:
- Removed the printk() in kasan_early_init() to avoid build failure (see 
https://github.com/linuxppc/issues/issues/218)
- Added necessary changes in asm/book3s/32/pgtable.h to get it work on powerpc 
603 family
- Added a few KASAN_SANITIZE_xxx.o := n to successfully boot on powerpc 603 
family

Changes in v2:
- Rebased.
- Using __set_pte_at() to build the early table.
- Worked around and got rid of the patch adding asm/page.h in 
asm/pgtable-types.h
==> might be fixed independently but not needed for this serie.

For book3s/32 (not 603), it cannot work as is because due to HASHPTE flag, we
can't use the same pagetable for several PGD entries, and because Hash table
management is not not active early enough at the time being.

Christophe Leroy (3):
  powerpc/mm: prepare kernel for KAsan on PPC32
  powerpc/32: Move early_init() in a separate file
  powerpc/32: Add KASAN support

 arch/powerpc/Kconfig |  1 +
 arch/powerpc/include/asm/book3s/32/pgtable.h |  2 +
 arch/powerpc/include/asm/kasan.h | 24 
 arch/powerpc/include/asm/nohash/32/pgtable.h |  2 +
 arch/powerpc/include/asm/ppc_asm.h   |  5 ++
 arch/powerpc/include/asm/setup.h |  5 ++
 arch/powerpc/include/asm/string.h| 14 +
 arch/powerpc/kernel/Makefile | 11 +++-
 arch/powerpc/kernel/cputable.c   | 13 -
 arch/powerpc/kernel/early_32.c   | 36 
 arch/powerpc/kernel/prom_init_check.sh   | 10 +++-
 arch/powerpc/kernel/setup-common.c   |  2 +
 arch/powerpc/kernel/setup_32.c   | 31 +-
 arch/powerpc/lib/Makefile|  8 +++
 arch/powerpc/lib/copy_32.S   |  9 ++-
 arch/powerpc/mm/Makefile |  3 +
 arch/powerpc/mm/dump_linuxpagetables.c   |  8 +++
 arch/powerpc/mm/kasan_init.c | 86 
 arch/powerpc/mm/mem.c|  4 ++
 19 files changed, 236 insertions(+), 38 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kasan.h
 create mode 100644 arch/powerpc/kernel/early_32.c
 create mode 100644 arch/powerpc/mm/kasan_init.c

-- 
2.13.3



[PATCH] powerpc/traps: fix recoverability of machine check handling on book3s/32

2019-01-22 Thread Christophe Leroy
Looks like book3s/32 doesn't set RI on machine check, so
checking RI before calling die() will always be fatal
allthought this is not an issue in most cases.

Fixes: b96672dd840f ("powerpc: Machine check interrupt is a non-maskable 
interrupt")
Fixes: daf00ae71dad ("powerpc/traps: restore recoverability of machine_check 
interrupts")
Signed-off-by: Christophe Leroy 
Cc: sta...@vger.kernel.org
---
 arch/powerpc/kernel/traps.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 64936b60d521..c740f8bfccc9 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -763,15 +763,15 @@ void machine_check_exception(struct pt_regs *regs)
if (check_io_access(regs))
goto bail;
 
-   /* Must die if the interrupt is not recoverable */
-   if (!(regs->msr & MSR_RI))
-   nmi_panic(regs, "Unrecoverable Machine check");
-
if (!nested)
nmi_exit();
 
die("Machine check", regs, SIGBUS);
 
+   /* Must die if the interrupt is not recoverable */
+   if (!(regs->msr & MSR_RI))
+   nmi_panic(regs, "Unrecoverable Machine check");
+
return;
 
 bail:
-- 
2.13.3



[PATCH] powerpc/selftest: fix type of mftb() in null_syscall

2019-01-22 Thread Christophe Leroy
All callers of mftb() expect 'unsigned long', and the function itself
only returns lower part of the TB so it really is 'unsigned long'
not 'unsigned long long'

Signed-off-by: Christophe Leroy 
---
 tools/testing/selftests/powerpc/benchmarks/null_syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/benchmarks/null_syscall.c 
b/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
index ecc14d68e101..908de689a902 100644
--- a/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
+++ b/tools/testing/selftests/powerpc/benchmarks/null_syscall.c
@@ -25,7 +25,7 @@ unsigned long long clock_frequency;
 unsigned long long timebase_frequency;
 double timebase_multiplier;
 
-static inline unsigned long long mftb(void)
+static inline unsigned long mftb(void)
 {
unsigned long low;
 
-- 
2.13.3



[PATCH] powerpc/32: Fix CONFIG_VIRT_CPU_ACCOUNTING_NATIVE for 40x/booke

2019-01-22 Thread Christophe Leroy
40x/booke have another path to reach 3f from transfer_to_handler,
so ACCOUNT_CPU_USER_ENTRY() have to be moved there.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index c2b66fbbf7f0..0bcec062c4b8 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -185,12 +185,6 @@ transfer_to_handler:
addir12,r12,-1
stw r12,4(r11)
 #endif
-#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
-   CURRENT_THREAD_INFO(r9, r1)
-   tophys(r9, r9)
-   ACCOUNT_CPU_USER_ENTRY(r9, r11, r12)
-#endif
-
b   3f
 
 2: /* if from kernel, check interrupted DOZE/NAP mode and
@@ -208,9 +202,14 @@ transfer_to_handler:
bt- 31-TLF_NAPPING,4f
bt- 31-TLF_SLEEPING,7f
 #endif /* CONFIG_PPC_BOOK3S_32 || CONFIG_E500 */
+3:
+#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
+   CURRENT_THREAD_INFO(r9, r1)
+   tophys(r9, r9)
+   ACCOUNT_CPU_USER_ENTRY(r9, r11, r12)
+#endif
.globl transfer_to_handler_cont
 transfer_to_handler_cont:
-3:
mflrr9
lwz r11,0(r9)   /* virtual address of handler */
lwz r9,4(r9)/* where to go when done */
-- 
2.13.3



[PATCH] powerpc/32: Remove unneccessary MSR[RI] clearing for 8xx

2019-01-22 Thread Christophe Leroy
MSR[RI] has already been cleared a few lines above.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/entry_32.S | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 0768dfd8a64e..c2b66fbbf7f0 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -997,9 +997,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
.globl exc_exit_restart
 exc_exit_restart:
lwz r12,_NIP(r1)
-#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
-   mtspr   SPRN_NRI, r0
-#endif
mtspr   SPRN_SRR0,r12
mtspr   SPRN_SRR1,r9
REST_4GPRS(9, r1)
-- 
2.13.3



Re: [PATCH v3 0/4] Add NXP AUDMIX device and machine drivers

2019-01-22 Thread Viorel Suman
Hi Rob,

On Lu, 2019-01-21 at 09:23 -0600, Rob Herring wrote:
> On Fri, Jan 18, 2019 at 11:46:42AM -0800, Nicolin Chen wrote:
> > 
> > On Fri, Jan 18, 2019 at 01:16:24PM +, Viorel Suman wrote:
> > > 
> > > > 
> > > > > 
> > > > > 1. Moved "dais" node from machine driver DTS node to device
> > > > > driver
> > > > > DTS node
> > > > >   as suggested by Rob.
> > > > That was not what I suggested. You still have a virtual node
> > > > which
> > > > looks to me to be unnecessary.
> > > To me removing virtual node implies that AUDMIX machine driver
> > > (imx-
> > > audmix.c + virtual node) shall be removed and machine driver code
> > > merged into device driver (fsl_audmix.c + device node) - please
> > > let me
> > > know if my understanding is wrong.
> > We could use a non-DT configuration right? From the driver logic,
> > DT just registers a device corresponding to the machine driver so
> > that it can probe(). We could register one in fsl_audmix instead.
> > Please refer to how fsl_ssi registers the sound card device. The
> > machine driver can get audmix_np from the parent device pointer,
> > and I think that's all you need.
> Yes.

Thank you, sent V4 which implements the approach suggested by Nicolin.

> 
> > 
> > Or maybe someone else would provide a better way. But it'd work.
> Or the machine driver could create the audmix device. That probably 
> makes less sense, but either way there doesn't have to be a 1-1 
> correspondence of DT nodes and (platform) devices.
> 
> I'm not an ASoC expert, but why can't the machine driver just control
> the audmix directly (with DAIs as separate drivers)? Is the audmix
> ever going to a be a component for a different machine driver?
> 
> Rob

Currently I'm not aware of any information with regard to if audmix is
ever going to work with other DAIs than SAI. Howerver from audmix IP
block integration perspective the only requirement is that the input
DAI must be connected to audmix over I2S bus, possible DAI options are
SAI, ESAI, etc - I think the approach to mix both device and machine
drivers into a single entity is not the best way to go.

/Viorel

Re: [PATCH v3 0/4] Add NXP AUDMIX device and machine drivers

2019-01-22 Thread Viorel Suman
Hi Nicolin,

On Vi, 2019-01-18 at 11:46 -0800, Nicolin Chen wrote:
> On Fri, Jan 18, 2019 at 01:16:24PM +, Viorel Suman wrote:
> > 
> > > 
> > > > 
> > > > 1. Moved "dais" node from machine driver DTS node to device
> > > > driver
> > > > DTS node
> > > >   as suggested by Rob.
> > > That was not what I suggested. You still have a virtual node
> > > which
> > > looks to me to be unnecessary.
> > To me removing virtual node implies that AUDMIX machine driver
> > (imx-
> > audmix.c + virtual node) shall be removed and machine driver code
> > merged into device driver (fsl_audmix.c + device node) - please let
> > me
> > know if my understanding is wrong.
> We could use a non-DT configuration right? From the driver logic,
> DT just registers a device corresponding to the machine driver so
> that it can probe(). We could register one in fsl_audmix instead.
> Please refer to how fsl_ssi registers the sound card device. The
> machine driver can get audmix_np from the parent device pointer,
> and I think that's all you need.
> 
> Or maybe someone else would provide a better way. But it'd work.

Sent V4 - it implements the approach you suggested. Thank you for the
hint, works well indeed.

Regards,
Viorel



[PATCH v4 3/3] ASoC: fsl: Add Audio Mixer machine driver

2019-01-22 Thread Viorel Suman
This patch implements Audio Mixer machine driver for NXP iMX8 SOCs.
It connects together Audio Mixer and related SAI instances.

Signed-off-by: Viorel Suman 
---
 sound/soc/fsl/Kconfig  |   9 ++
 sound/soc/fsl/Makefile |   2 +
 sound/soc/fsl/imx-audmix.c | 327 +
 3 files changed, 338 insertions(+)
 create mode 100644 sound/soc/fsl/imx-audmix.c

diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 0af2e056..d87c842 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -303,6 +303,15 @@ config SND_SOC_FSL_ASOC_CARD
 CS4271, CS4272 and SGTL5000.
 Say Y if you want to add support for Freescale Generic ASoC Sound Card.
 
+config SND_SOC_IMX_AUDMIX
+   tristate "SoC Audio support for i.MX boards with AUDMIX"
+   select SND_SOC_FSL_AUDMIX
+   select SND_SOC_FSL_SAI
+   help
+ SoC Audio support for i.MX boards with Audio Mixer
+ Say Y if you want to add support for SoC audio on an i.MX board with
+ an Audio Mixer.
+
 endif # SND_IMX_SOC
 
 endmenu
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index 4172d5a..c0dd044 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -62,6 +62,7 @@ snd-soc-imx-es8328-objs := imx-es8328.o
 snd-soc-imx-sgtl5000-objs := imx-sgtl5000.o
 snd-soc-imx-spdif-objs := imx-spdif.o
 snd-soc-imx-mc13783-objs := imx-mc13783.o
+snd-soc-imx-audmix-objs := imx-audmix.o
 
 obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
 obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o
@@ -71,3 +72,4 @@ obj-$(CONFIG_SND_SOC_IMX_ES8328) += snd-soc-imx-es8328.o
 obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o
 obj-$(CONFIG_SND_SOC_IMX_SPDIF) += snd-soc-imx-spdif.o
 obj-$(CONFIG_SND_SOC_IMX_MC13783) += snd-soc-imx-mc13783.o
+obj-$(CONFIG_SND_SOC_IMX_AUDMIX) += snd-soc-imx-audmix.o
diff --git a/sound/soc/fsl/imx-audmix.c b/sound/soc/fsl/imx-audmix.c
new file mode 100644
index 000..72e37ca
--- /dev/null
+++ b/sound/soc/fsl/imx-audmix.c
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2017 NXP
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "fsl_sai.h"
+#include "fsl_audmix.h"
+
+struct imx_audmix {
+   struct platform_device *pdev;
+   struct snd_soc_card card;
+   struct platform_device *audmix_pdev;
+   struct platform_device *out_pdev;
+   struct clk *cpu_mclk;
+   int num_dai;
+   struct snd_soc_dai_link *dai;
+   int num_dai_conf;
+   struct snd_soc_codec_conf *dai_conf;
+   int num_dapm_routes;
+   struct snd_soc_dapm_route *dapm_routes;
+};
+
+static const u32 imx_audmix_rates[] = {
+   8000, 12000, 16000, 24000, 32000, 48000, 64000, 96000,
+};
+
+static const struct snd_pcm_hw_constraint_list imx_audmix_rate_constraints = {
+   .count = ARRAY_SIZE(imx_audmix_rates),
+   .list = imx_audmix_rates,
+};
+
+static int imx_audmix_fe_startup(struct snd_pcm_substream *substream)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct imx_audmix *priv = snd_soc_card_get_drvdata(rtd->card);
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct device *dev = rtd->card->dev;
+   unsigned long clk_rate = clk_get_rate(priv->cpu_mclk);
+   int ret;
+
+   if (clk_rate % 24576000 == 0) {
+   ret = snd_pcm_hw_constraint_list(runtime, 0,
+SNDRV_PCM_HW_PARAM_RATE,
+&imx_audmix_rate_constraints);
+   if (ret < 0)
+   return ret;
+   } else {
+   dev_warn(dev, "mclk may be not supported %lu\n", clk_rate);
+   }
+
+   ret = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS,
+  1, 8);
+   if (ret < 0)
+   return ret;
+
+   return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
+   FSL_AUDMIX_FORMATS);
+}
+
+static int imx_audmix_fe_hw_params(struct snd_pcm_substream *substream,
+  struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct device *dev = rtd->card->dev;
+   bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
+   unsigned int fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF;
+   u32 channels = params_channels(params);
+   int ret, dir;
+
+   /* For playback the AUDMIX is slave, and for record is master */
+   fmt |= tx ? SND_SOC_DAIFMT_CBS_CF

[PATCH v4 0/3] Add NXP AUDMIX device and machine drivers

2019-01-22 Thread Viorel Suman
The patchset adds NXP Audio Mixer (AUDMIX) device and machine
drivers and related DT bindings documentation.

Changes since V3:
1. Removed machine driver DT bindings documentation.
2. Trigger machine driver probe from device driver as suggested by Nicolin.

Changes since V2:
1. Moved "dais" node from machine driver DTS node to device driver DTS node
  as suggested by Rob.

Changes since V1:
1. Original patch split into distinct patches for the device driver and
  DT binding documentation.
2. Replaced AMIX with AUDMIX in both code and file names as it looks more
  RM-compliant.
3. Removed polarity control from CPU DAI driver as suggested by Nicolin.
4. Added machine driver and related DT binding documentation.

Viorel Suman (3):
  ASoC: fsl: Add Audio Mixer CPU DAI driver
  ASoC: add fsl_audmix DT binding documentation
  ASoC: fsl: Add Audio Mixer machine driver

 .../devicetree/bindings/sound/fsl,audmix.txt   |  54 ++
 sound/soc/fsl/Kconfig  |  16 +
 sound/soc/fsl/Makefile |   5 +
 sound/soc/fsl/fsl_audmix.c | 576 +
 sound/soc/fsl/fsl_audmix.h | 102 
 sound/soc/fsl/imx-audmix.c | 327 
 6 files changed, 1080 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/fsl,audmix.txt
 create mode 100644 sound/soc/fsl/fsl_audmix.c
 create mode 100644 sound/soc/fsl/fsl_audmix.h
 create mode 100644 sound/soc/fsl/imx-audmix.c

-- 
2.7.4



[PATCH v4 2/3] ASoC: add fsl_audmix DT binding documentation

2019-01-22 Thread Viorel Suman
Add the DT binding documentation for NXP Audio Mixer
CPU DAI driver.

Signed-off-by: Viorel Suman 
---
 .../devicetree/bindings/sound/fsl,audmix.txt   | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/fsl,audmix.txt

diff --git a/Documentation/devicetree/bindings/sound/fsl,audmix.txt 
b/Documentation/devicetree/bindings/sound/fsl,audmix.txt
new file mode 100644
index 000..45f807e
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/fsl,audmix.txt
@@ -0,0 +1,54 @@
+NXP Audio Mixer (AUDMIX).
+
+The Audio Mixer is a on-chip functional module that allows mixing of two
+audio streams into a single audio stream. Audio Mixer has two input serial
+audio interfaces. These are driven by two Synchronous Audio interface
+modules (SAI). Each input serial interface carries 8 audio channels in its
+frame in TDM manner. Mixer mixes audio samples of corresponding channels
+from two interfaces into a single sample. Before mixing, audio samples of
+two inputs can be attenuated based on configuration. The output of the
+Audio Mixer is also a serial audio interface. Like input interfaces it has
+the same TDM frame format. This output is used to drive the serial DAC TDM
+interface of audio codec and also sent to the external pins along with the
+receive path of normal audio SAI module for readback by the CPU.
+
+The output of Audio Mixer can be selected from any of the three streams
+ - serial audio input 1
+ - serial audio input 2
+ - mixed audio
+
+Mixing operation is independent of audio sample rate but the two audio
+input streams must have same audio sample rate with same number of channels
+in TDM frame to be eligible for mixing.
+
+Device driver required properties:
+=
+  - compatible : Compatible list, contains "fsl,imx8qm-audmix"
+
+  - reg: Offset and length of the register set for the 
device.
+
+  - clocks : Must contain an entry for each entry in clock-names.
+
+  - clock-names: Must include the "ipg" for register access.
+
+  - power-domains  : Must contain the phandle to AUDMIX power domain node
+
+  - dais   : Must contain a list of phandles to AUDMIX connected
+ DAIs. The current implementation requires two phandles
+ to SAI interfaces to be provided, the first SAI in the
+ list being used to route the AUDMIX output.
+
+  - model  : Must contain machine driver name which will configure
+ and instantiate the appropriate audio card.
+
+Device driver configuration example:
+==
+  audmix: audmix@5984 {
+compatible = "fsl,imx8qm-audmix";
+reg = <0x0 0x5984 0x0 0x1>;
+clocks = <&clk IMX8QXP_AUD_AUDMIX_IPG>;
+clock-names = "ipg";
+power-domains = <&pd_audmix>;
+dais = <&sai4>, <&sai5>;
+model = "imx-audmix";
+  };
-- 
2.7.4



[PATCH v4 1/3] ASoC: fsl: Add Audio Mixer CPU DAI driver

2019-01-22 Thread Viorel Suman
This patch implements Audio Mixer CPU DAI driver for NXP iMX8 SOCs.
The Audio Mixer is a on-chip functional module that allows mixing of
two audio streams into a single audio stream.

Audio Mixer datasheet is available here:
https://www.nxp.com/docs/en/reference-manual/IMX8DQXPRM.pdf

Signed-off-by: Viorel Suman 
---
 sound/soc/fsl/Kconfig  |   7 +
 sound/soc/fsl/Makefile |   3 +
 sound/soc/fsl/fsl_audmix.c | 576 +
 sound/soc/fsl/fsl_audmix.h | 102 
 4 files changed, 688 insertions(+)
 create mode 100644 sound/soc/fsl/fsl_audmix.c
 create mode 100644 sound/soc/fsl/fsl_audmix.h

diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 7b1d997..0af2e056 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -24,6 +24,13 @@ config SND_SOC_FSL_SAI
  This option is only useful for out-of-tree drivers since
  in-tree drivers select it automatically.
 
+config SND_SOC_FSL_AUDMIX
+   tristate "Audio Mixer (AUDMIX) module support"
+   select REGMAP_MMIO
+   help
+ Say Y if you want to add Audio Mixer (AUDMIX)
+ support for the NXP iMX CPUs.
+
 config SND_SOC_FSL_SSI
tristate "Synchronous Serial Interface module (SSI) support"
select SND_SOC_IMX_PCM_DMA if SND_IMX_SOC != n
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index 3c0ff31..4172d5a 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -12,6 +12,7 @@ snd-soc-p1022-rdk-objs := p1022_rdk.o
 obj-$(CONFIG_SND_SOC_P1022_RDK) += snd-soc-p1022-rdk.o
 
 # Freescale SSI/DMA/SAI/SPDIF Support
+snd-soc-fsl-audmix-objs := fsl_audmix.o
 snd-soc-fsl-asoc-card-objs := fsl-asoc-card.o
 snd-soc-fsl-asrc-objs := fsl_asrc.o fsl_asrc_dma.o
 snd-soc-fsl-sai-objs := fsl_sai.o
@@ -22,6 +23,8 @@ snd-soc-fsl-esai-objs := fsl_esai.o
 snd-soc-fsl-micfil-objs := fsl_micfil.o
 snd-soc-fsl-utils-objs := fsl_utils.o
 snd-soc-fsl-dma-objs := fsl_dma.o
+
+obj-$(CONFIG_SND_SOC_FSL_AUDMIX) += snd-soc-fsl-audmix.o
 obj-$(CONFIG_SND_SOC_FSL_ASOC_CARD) += snd-soc-fsl-asoc-card.o
 obj-$(CONFIG_SND_SOC_FSL_ASRC) += snd-soc-fsl-asrc.o
 obj-$(CONFIG_SND_SOC_FSL_SAI) += snd-soc-fsl-sai.o
diff --git a/sound/soc/fsl/fsl_audmix.c b/sound/soc/fsl/fsl_audmix.c
new file mode 100644
index 000..3356cb6
--- /dev/null
+++ b/sound/soc/fsl/fsl_audmix.c
@@ -0,0 +1,576 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * NXP AUDMIX ALSA SoC Digital Audio Interface (DAI) driver
+ *
+ * Copyright 2017 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "fsl_audmix.h"
+
+#define SOC_ENUM_SINGLE_S(xreg, xshift, xtexts) \
+   SOC_ENUM_SINGLE(xreg, xshift, ARRAY_SIZE(xtexts), xtexts)
+
+static const char
+   *tdm_sel[] = { "TDM1", "TDM2", },
+   *mode_sel[] = { "Disabled", "TDM1", "TDM2", "Mixed", },
+   *width_sel[] = { "16b", "18b", "20b", "24b", "32b", },
+   *endis_sel[] = { "Disabled", "Enabled", },
+   *updn_sel[] = { "Downward", "Upward", },
+   *mask_sel[] = { "Unmask", "Mask", };
+
+static const struct soc_enum fsl_audmix_enum[] = {
+/* FSL_AUDMIX_CTR enums */
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_MIXCLK_SHIFT, tdm_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_OUTSRC_SHIFT, mode_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_OUTWIDTH_SHIFT, width_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_MASKRTDF_SHIFT, mask_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_MASKCKDF_SHIFT, mask_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_SYNCMODE_SHIFT, endis_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_CTR, FSL_AUDMIX_CTR_SYNCSRC_SHIFT, tdm_sel),
+/* FSL_AUDMIX_ATCR0 enums */
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_ATCR0, 0, endis_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_ATCR0, 1, updn_sel),
+/* FSL_AUDMIX_ATCR1 enums */
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_ATCR1, 0, endis_sel),
+SOC_ENUM_SINGLE_S(FSL_AUDMIX_ATCR1, 1, updn_sel),
+};
+
+struct fsl_audmix_state {
+   u8 tdms;
+   u8 clk;
+   char msg[64];
+};
+
+static const struct fsl_audmix_state prms[4][4] = {{
+   /* DIS->DIS, do nothing */
+   { .tdms = 0, .clk = 0, .msg = "" },
+   /* DIS->TDM1*/
+   { .tdms = 1, .clk = 1, .msg = "DIS->TDM1: TDM1 not started!\n" },
+   /* DIS->TDM2*/
+   { .tdms = 2, .clk = 2, .msg = "DIS->TDM2: TDM2 not started!\n" },
+   /* DIS->MIX */
+   { .tdms = 3, .clk = 0, .msg = "DIS->MIX: Please start both TDMs!\n" }
+}, {   /* TDM1->DIS */
+   { .tdms = 1, .clk = 0, .msg = "TDM1->DIS: TDM1 not started!\n" },
+   /* TDM1->TDM1, do nothing */
+   { .tdms = 0, .clk = 0, .msg = "" },
+   /* TDM1->TDM2 */
+   { .tdms = 3, .clk = 2, .msg = "TDM1->TDM2: Please start both TDMs!\n" },
+   /* TDM1->MIX */
+   { .tdms = 3, .clk = 0, .msg = "TDM1->MIX: Please start both TDMs!\n" }
+}, {   /* TDM2->DIS */
+   { .tdms = 2, .clk = 0, .msg = "TDM2->DIS: TDM2 not started!\n" },
+   /* TDM2->TDM1 */
+   { .tdms = 3, .clk 

Re: [PATCH 4/4] powerpc/64s: Fix data interrupts vs d-side MCE reentrancy

2019-01-22 Thread kbuild test robot
Hi Nicholas,

I love your patch! Yet something to improve:

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

url:
https://github.com/0day-ci/linux/commits/Nicholas-Piggin/Fixes-for-3-separate-NMI-reentrancy-bugs/20190122-154328
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 8.2.0-11) 8.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.2.0 make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/kernel/exceptions-64s.S: Assembler messages:
>> arch/powerpc/kernel/exceptions-64s.S:625: Error: Fixed entry overflow
   arch/powerpc/kernel/exceptions-64s.S:625: Fatal error: .abort detected.  
Abandoning ship.

vim +625 arch/powerpc/kernel/exceptions-64s.S

80795e6cb Nicholas Piggin2016-09-21  616  
0ebc4cdaa Benjamin Herrenschmidt 2009-06-02  617  
1a6822d19 Nicholas Piggin2016-12-06  618  
EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
7cfab0bae Nicholas Piggin2019-01-22  619  SET_SCRATCH0(r13) 
/* save r13 */
7cfab0bae Nicholas Piggin2019-01-22  620  EXCEPTION_PROLOG_0(PACA_EXSLB)
7cfab0bae Nicholas Piggin2019-01-22  621  
EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
00038b16f Nicholas Piggin2019-01-22  622mfspr   r10,SPRN_DAR
00038b16f Nicholas Piggin2019-01-22  623std 
r10,PACA_EXGEN+EX_DAR(r13)
7cfab0bae Nicholas Piggin2019-01-22  624  
EXCEPTION_PROLOG_2(data_access_slb_common, EXC_STD)
1a6822d19 Nicholas Piggin2016-12-06 @625  EXC_REAL_END(data_access_slb, 
0x380, 0x80)
0ebc4cdaa Benjamin Herrenschmidt 2009-06-02  626  

:: The code at line 625 was first introduced by commit
:: 1a6822d194c3f627eeb6aaca6688a5d0a444663e powerpc/64s: Use (start, size) 
rather than (start, end) for exception handlers

:: TO: Nicholas Piggin 
:: CC: Michael Ellerman 

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


.config.gz
Description: application/gzip


Re: [PATCH v9 00/22] Re-use nvram module

2019-01-22 Thread Greg Kroah-Hartman
On Tue, Jan 15, 2019 at 03:18:56PM +1100, Finn Thain wrote:
> The "generic" NVRAM module, drivers/char/generic_nvram.c, implements a
> /dev/nvram misc device. This module is used only by 32-bit PowerPC
> platforms.
> 
> The RTC "CMOS" NVRAM module, drivers/char/nvram.c, also implements a
> /dev/nvram misc device. This module is now used only by x86 and m68k
> thanks to commit 3ba9faedc180 ("char: nvram: disable on ARM").
> 
> The "generic" module cannot be used by x86 or m68k platforms because it
> cannot co-exist with the "CMOS" module. One reason for that is the
> CONFIG_GENERIC_NVRAM kludge in drivers/char/Makefile. Another reason is
> that automatically loading the appropriate module would be impossible
> because only one module can provide the char-major-10-144 alias.
> 
> A multi-platform kernel binary needs a single, generic module. With this
> patch series, drivers/char/nvram.c becomes more generic and some of the
> arch-specific code gets moved under arch/. The nvram module is then
> usable by all m68k, powerpc and x86 platforms.
> 
> This allows for removal of drivers/char/generic_nvram.c as well as a
> duplicate in arch/powerpc/kernel/nvram_64.c. By reducing the number of
> /dev/nvram char misc device implementations, the number of bugs and
> inconsistencies is also reduced.
> 
> This approach reduces inconsistencies between PPC32 and PPC64 and also
> between PPC_PMAC and MAC. A uniform API has benefits for userspace.
> 
> For example, some error codes for some ioctl calls become consistent
> across PowerPC platforms. The uniform API can potentially benefit any
> bootloader that works across the various platforms having XPRAM
> (e.g. Emile).
> 
> This patch series was tested on Atari, Mac, PowerMac (both 32-bit and
> 64-bit) and ThinkPad hardware. AFAIK, it has not yet been tested on
> pSeries or CHRP.
> 
> I think there are two possible merge strategies for this patch series.
> The char misc maintainer could take the entire series. Alternatively,
> the m68k maintainer could take patches 1 thru 16 (though some of these
> have nothing to do with m68k) and after those patches reach mainline
> the powerpc maintainer could take 17 thru 22.

I just took the whole series, thanks for doing this, looks good.

greg k-h


Re: [PATCH v9 15/22] m68k: Dispatch nvram_ops calls to Atari or Mac functions

2019-01-22 Thread Greg Kroah-Hartman
On Tue, Jan 22, 2019 at 10:19:17AM +0100, Greg Kroah-Hartman wrote:
> On Tue, Jan 15, 2019 at 03:18:56PM +1100, Finn Thain wrote:
> > A multi-platform kernel binary has to decide at run-time how to dispatch
> > the arch_nvram_ops calls. Add a platform-independent arch_nvram_ops
> > struct for this, to replace the atari-specific one.
> > 
> > Enable CONFIG_HAVE_ARCH_NVRAM_OPS for Macs.
> > 
> > Acked-by: Geert Uytterhoeven 
> > Tested-by: Stan Johnson 
> > Signed-off-by: Finn Thain 
> > ---
> > Changed since v8:
> >  - Adopted nvram_read_bytes() and nvram_write_bytes() where possible.
> 
> This patch fails to apply to my tree, what did you make it against?
> 
> I tried against 5.0-rc1 :(
> 
> Can you rebase this series against the char-misc-next branch of my
> char-misc.git tree and resend so that I can apply the whole series?

Oops, nope, my fault, I missed some patches in this series, nevermind...

greg k-h


Re: [PATCH v9 15/22] m68k: Dispatch nvram_ops calls to Atari or Mac functions

2019-01-22 Thread Greg Kroah-Hartman
On Tue, Jan 15, 2019 at 03:18:56PM +1100, Finn Thain wrote:
> A multi-platform kernel binary has to decide at run-time how to dispatch
> the arch_nvram_ops calls. Add a platform-independent arch_nvram_ops
> struct for this, to replace the atari-specific one.
> 
> Enable CONFIG_HAVE_ARCH_NVRAM_OPS for Macs.
> 
> Acked-by: Geert Uytterhoeven 
> Tested-by: Stan Johnson 
> Signed-off-by: Finn Thain 
> ---
> Changed since v8:
>  - Adopted nvram_read_bytes() and nvram_write_bytes() where possible.

This patch fails to apply to my tree, what did you make it against?

I tried against 5.0-rc1 :(

Can you rebase this series against the char-misc-next branch of my
char-misc.git tree and resend so that I can apply the whole series?

thanks,

greg k-h