Re: [PATCH] powerpc: Mark variable `cpumsr` as unused

2018-11-07 Thread Mathieu Malaterre
On Thu, Nov 8, 2018 at 7:09 AM Christophe Leroy  wrote:
>
>
>
> On 11/07/2018 08:26 PM, Mathieu Malaterre wrote:
> > Add gcc attribute unused for `cpumsr` variable.
> >
> > Fix warnings treated as errors with W=1:
> >
> >arch/powerpc/kernel/process.c:231:16: error: variable ‘cpumsr’ set but 
> > not used [-Werror=unused-but-set-variable]
> >arch/powerpc/kernel/process.c:296:16: error: variable ‘cpumsr’ set but 
> > not used [-Werror=unused-but-set-variable]
> >
> > Signed-off-by: Mathieu Malaterre 
>
> I don't think this is the good way to fix that. This problem was
> introduced by commit 5c784c8414fb ("powerpc/tm: Remove
> msr_tm_active()"). That commit should be reverted and fixed.

I see, it makes sense.

> That commit should have removed the macro and kept the inline function.

Breno, what do you think ?

> Christophe
>
> > ---
> >   arch/powerpc/kernel/process.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
> > index 96f34730010f..b9f1a2408738 100644
> > --- a/arch/powerpc/kernel/process.c
> > +++ b/arch/powerpc/kernel/process.c
> > @@ -228,7 +228,7 @@ EXPORT_SYMBOL_GPL(flush_fp_to_thread);
> >
> >   void enable_kernel_fp(void)
> >   {
> > - unsigned long cpumsr;
> > + unsigned long cpumsr __maybe_unused;
> >
> >   WARN_ON(preemptible());
> >
> > @@ -293,7 +293,7 @@ EXPORT_SYMBOL(giveup_altivec);
> >
> >   void enable_kernel_altivec(void)
> >   {
> > - unsigned long cpumsr;
> > + unsigned long cpumsr __maybe_unused;
> >
> >   WARN_ON(preemptible());
> >
> >


Re: [PATCH kernel 2/3] vfio_pci: Allow regions to add own capabilities

2018-11-07 Thread Alexey Kardashevskiy


On 08/11/2018 17:21, David Gibson wrote:
> On Mon, Oct 15, 2018 at 08:42:32PM +1100, Alexey Kardashevskiy wrote:
>> VFIO regions already support region capabilities with a limited set of
>> fields. However the subdriver might have to report to the userspace
>> additional bits.
>>
>> This adds an add_capability() hook to vfio_pci_regops.
>>
>> This is aiming Witherspoon POWER9 machines which have multiple
>> interconnected NVIDIA V100 GPUs with coherent RAM; each GPU's RAM
>> is mapped to a system bus and to each of GPU internal system bus and
>> the GPUs use this for DMA routing as DMA trafic can go via any
>> of many NVLink2 (GPU-GPU or GPU-CPU) or even stay local within a
>> GPU.
> 
> This description doesn't really make clear how per-region capabilities
> are relevant to these devices.


I am confused. This patch just adds a hook, and the device specifics are
explained in the next patch where they are used...


> 
>>
>> Signed-off-by: Alexey Kardashevskiy 
>> ---
>>
>> This is based on top of "vfio_pci: Allow mapping extra regions"
>> ---
>>  drivers/vfio/pci/vfio_pci_private.h | 3 +++
>>  drivers/vfio/pci/vfio_pci.c | 6 ++
>>  2 files changed, 9 insertions(+)
>>
>> diff --git a/drivers/vfio/pci/vfio_pci_private.h 
>> b/drivers/vfio/pci/vfio_pci_private.h
>> index 86aab05..93c1738 100644
>> --- a/drivers/vfio/pci/vfio_pci_private.h
>> +++ b/drivers/vfio/pci/vfio_pci_private.h
>> @@ -62,6 +62,9 @@ struct vfio_pci_regops {
>>  int (*mmap)(struct vfio_pci_device *vdev,
>>  struct vfio_pci_region *region,
>>  struct vm_area_struct *vma);
>> +int (*add_capability)(struct vfio_pci_device *vdev,
>> +  struct vfio_pci_region *region,
>> +  struct vfio_info_cap *caps);
>>  };
>>  
>>  struct vfio_pci_region {
>> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
>> index 7923314..4a3b93e 100644
>> --- a/drivers/vfio/pci/vfio_pci.c
>> +++ b/drivers/vfio/pci/vfio_pci.c
>> @@ -759,6 +759,12 @@ static long vfio_pci_ioctl(void *device_data,
>>  if (ret)
>>  return ret;
>>  
>> +if (vdev->region[i].ops->add_capability) {
>> +ret = vdev->region[i].ops->add_capability(vdev,
>> +>region[i], );
>> +if (ret)
>> +return ret;
>> +}
>>  }
>>  }
>>  
> 

-- 
Alexey



signature.asc
Description: OpenPGP digital signature


Re: [PATCH kernel 2/3] vfio_pci: Allow regions to add own capabilities

2018-11-07 Thread David Gibson
On Mon, Oct 15, 2018 at 08:42:32PM +1100, Alexey Kardashevskiy wrote:
> VFIO regions already support region capabilities with a limited set of
> fields. However the subdriver might have to report to the userspace
> additional bits.
> 
> This adds an add_capability() hook to vfio_pci_regops.
> 
> This is aiming Witherspoon POWER9 machines which have multiple
> interconnected NVIDIA V100 GPUs with coherent RAM; each GPU's RAM
> is mapped to a system bus and to each of GPU internal system bus and
> the GPUs use this for DMA routing as DMA trafic can go via any
> of many NVLink2 (GPU-GPU or GPU-CPU) or even stay local within a
> GPU.

This description doesn't really make clear how per-region capabilities
are relevant to these devices.

> 
> Signed-off-by: Alexey Kardashevskiy 
> ---
> 
> This is based on top of "vfio_pci: Allow mapping extra regions"
> ---
>  drivers/vfio/pci/vfio_pci_private.h | 3 +++
>  drivers/vfio/pci/vfio_pci.c | 6 ++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_private.h 
> b/drivers/vfio/pci/vfio_pci_private.h
> index 86aab05..93c1738 100644
> --- a/drivers/vfio/pci/vfio_pci_private.h
> +++ b/drivers/vfio/pci/vfio_pci_private.h
> @@ -62,6 +62,9 @@ struct vfio_pci_regops {
>   int (*mmap)(struct vfio_pci_device *vdev,
>   struct vfio_pci_region *region,
>   struct vm_area_struct *vma);
> + int (*add_capability)(struct vfio_pci_device *vdev,
> +   struct vfio_pci_region *region,
> +   struct vfio_info_cap *caps);
>  };
>  
>  struct vfio_pci_region {
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 7923314..4a3b93e 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -759,6 +759,12 @@ static long vfio_pci_ioctl(void *device_data,
>   if (ret)
>   return ret;
>  
> + if (vdev->region[i].ops->add_capability) {
> + ret = vdev->region[i].ops->add_capability(vdev,
> + >region[i], );
> + if (ret)
> + return ret;
> + }
>   }
>   }
>  

-- 
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] net/wan/fsl_ucc_hdlc: add BQL support

2018-11-07 Thread David Miller
From: Mathias Thore 
Date: Wed,  7 Nov 2018 09:09:45 +0100

> Add byte queue limits support in the fsl_ucc_hdlc driver.
> 
> Signed-off-by: Mathias Thore 

Applied to net-next.


Re: [PATCH kernel 1/2] powerpc/pseries: Remove IOMMU API support for non-LPAR systems

2018-11-07 Thread David Gibson
On Thu, Oct 18, 2018 at 06:52:42PM +1100, Alexey Kardashevskiy wrote:
> The pci_dma_bus_setup_pSeries and pci_dma_dev_setup_pSeries hooks are
> registered for the pseries platform which does not have FW_FEATURE_LPAR;
> these would be pre-powernv platforms which we never supported PCI pass
> through for anyway so remove it.
> 
> Signed-off-by: Alexey Kardashevskiy 

Reviewed-by: David Gibson 

> ---
> 
> Propably should remove all pseries-but-not-lpar code.
> ---
>  arch/powerpc/platforms/pseries/iommu.c | 9 ++---
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/iommu.c 
> b/arch/powerpc/platforms/pseries/iommu.c
> index cf90582..eae2578 100644
> --- a/arch/powerpc/platforms/pseries/iommu.c
> +++ b/arch/powerpc/platforms/pseries/iommu.c
> @@ -648,7 +648,6 @@ static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
>   iommu_table_setparms(pci->phb, dn, tbl);
>   tbl->it_ops = _table_pseries_ops;
>   iommu_init_table(tbl, pci->phb->node);
> - iommu_register_group(pci->table_group, pci_domain_nr(bus), 0);
>  
>   /* Divide the rest (1.75GB) among the children */
>   pci->phb->dma_window_size = 0x8000ul;
> @@ -759,10 +758,7 @@ static void pci_dma_dev_setup_pSeries(struct pci_dev 
> *dev)
>   iommu_table_setparms(phb, dn, tbl);
>   tbl->it_ops = _table_pseries_ops;
>   iommu_init_table(tbl, phb->node);
> - iommu_register_group(PCI_DN(dn)->table_group,
> - pci_domain_nr(phb->bus), 0);
>   set_iommu_table_base(>dev, tbl);
> - iommu_add_device(>dev);
>   return;
>   }
>  
> @@ -773,11 +769,10 @@ static void pci_dma_dev_setup_pSeries(struct pci_dev 
> *dev)
>   while (dn && PCI_DN(dn) && PCI_DN(dn)->table_group == NULL)
>   dn = dn->parent;
>  
> - if (dn && PCI_DN(dn)) {
> + if (dn && PCI_DN(dn))
>   set_iommu_table_base(>dev,
>   PCI_DN(dn)->table_group->tables[0]);
> - iommu_add_device(>dev);
> - } else
> + else
>   printk(KERN_WARNING "iommu: Device %s has no iommu table\n",
>  pci_name(dev));
>  }

-- 
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 kernel 2/2] powerpc/powernv/pseries: Rework device adding to IOMMU groups

2018-11-07 Thread David Gibson
On Thu, Oct 18, 2018 at 06:52:43PM +1100, Alexey Kardashevskiy wrote:
> The powernv platform registers IOMMU groups and adds devices to them
> from the pci_controller_ops::setup_bridge() hook except one case when
> virtual functions (SRIOV VFs) are added from a bus notifier.
> 
> The pseries platform registers IOMMU groups from
> the pci_controller_ops::dma_bus_setup() hook and adds devices from
> the pci_controller_ops::dma_dev_setup() hook. The very same bus notifier
> used for powernv does not add devices for pseries though as
> __of_scan_bus() adds devices first, then it does the bus/dev DMA setup.
> 
> Both platforms use iommu_add_device() which takes a device and expects
> it to have a valid IOMMU table struct with an iommu_table_group pointer
> which in turn points the iommu_group struct (which represents
> an IOMMU group). Although the helper seems easy to use, it relies on
> some pre-existing device configuration and associated data structures
> which it does not really need.
> 
> This simplifies iommu_add_device() to take the table_group pointer
> directly. Pseries already has a table_group pointer handy and the bus
> notified is not used anyway. For powernv, this copies the existing bus
> notifier, makes it work for powernv only which means an easy way of
> getting to the table_group pointer. This was tested on VFs but should
> also support physical PCI hotplug.
> 
> Since iommu_add_device() receives the table_group pointer directly,
> pseries does not do TCE cache invalidation (the hypervisor does) nor
> allow multiple groups per a VFIO container (in other words sharing
> an IOMMU table between partitionable endpoints), this removes
> iommu_table_group_link from pseries.
> 
> Signed-off-by: Alexey Kardashevskiy 

Reviewed-by: David Gibson 

> ---
>  arch/powerpc/include/asm/iommu.h  | 12 +++
>  arch/powerpc/kernel/iommu.c   | 58 
> ++-
>  arch/powerpc/platforms/powernv/pci-ioda.c | 10 +-
>  arch/powerpc/platforms/powernv/pci.c  | 43 ++-
>  arch/powerpc/platforms/pseries/iommu.c| 46 
>  5 files changed, 74 insertions(+), 95 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/iommu.h 
> b/arch/powerpc/include/asm/iommu.h
> index 726f07b..39bee10 100644
> --- a/arch/powerpc/include/asm/iommu.h
> +++ b/arch/powerpc/include/asm/iommu.h
> @@ -220,9 +220,9 @@ struct iommu_table_group {
>  
>  extern void iommu_register_group(struct iommu_table_group *table_group,
>int pci_domain_number, unsigned long pe_num);
> -extern int iommu_add_device(struct device *dev);
> +extern int iommu_add_device(struct iommu_table_group *table_group,
> + struct device *dev);
>  extern void iommu_del_device(struct device *dev);
> -extern int __init tce_iommu_bus_notifier_init(void);
>  extern long iommu_tce_xchg(struct mm_struct *mm, struct iommu_table *tbl,
>   unsigned long entry, unsigned long *hpa,
>   enum dma_data_direction *direction);
> @@ -233,7 +233,8 @@ static inline void iommu_register_group(struct 
> iommu_table_group *table_group,
>  {
>  }
>  
> -static inline int iommu_add_device(struct device *dev)
> +static inline int iommu_add_device(struct iommu_table_group *table_group,
> + struct device *dev)
>  {
>   return 0;
>  }
> @@ -241,11 +242,6 @@ static inline int iommu_add_device(struct device *dev)
>  static inline void iommu_del_device(struct device *dev)
>  {
>  }
> -
> -static inline int __init tce_iommu_bus_notifier_init(void)
> -{
> -return 0;
> -}
>  #endif /* !CONFIG_IOMMU_API */
>  
>  int dma_iommu_mapping_error(struct device *dev, dma_addr_t dma_addr);
> diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
> index 47d75c5..fb14fbf 100644
> --- a/arch/powerpc/kernel/iommu.c
> +++ b/arch/powerpc/kernel/iommu.c
> @@ -1094,11 +1094,8 @@ void iommu_release_ownership(struct iommu_table *tbl)
>  }
>  EXPORT_SYMBOL_GPL(iommu_release_ownership);
>  
> -int iommu_add_device(struct device *dev)
> +int iommu_add_device(struct iommu_table_group *table_group, struct device 
> *dev)
>  {
> - struct iommu_table *tbl;
> - struct iommu_table_group_link *tgl;
> -
>   /*
>* The sysfs entries should be populated before
>* binding IOMMU group. If sysfs entries isn't
> @@ -1114,32 +,10 @@ int iommu_add_device(struct device *dev)
>   return -EBUSY;
>   }
>  
> - tbl = get_iommu_table_base(dev);
> - if (!tbl) {
> - pr_debug("%s: Skipping device %s with no tbl\n",
> -  __func__, dev_name(dev));
> - return 0;
> - }
> -
> - tgl = list_first_entry_or_null(>it_group_list,
> - struct iommu_table_group_link, next);
> - if (!tgl) {
> - pr_debug("%s: Skipping device %s with no group\n",
> -  __func__, dev_name(dev));
> - return 0;
> - }

Re: [PATCH kernel 4/5] powerpc/powernv/npu: Factor out OPAL calls from context manipulation

2018-11-07 Thread David Gibson
On Mon, Oct 15, 2018 at 08:33:00PM +1100, Alexey Kardashevskiy wrote:
> At the moment the NPU context init/destroy code calls OPAL. The init
> handler in OPAL configures the NPU to pass ATS requests to nested MMU,
> the destroy handler does nothing besides sanity checks.
> 
> Since the init handler programs the NPU with a wildcard for LPID/PID,
> this can be done at the point where a GPU is mapped to an LPAR; it also
> makes calling opal_npu_destroy_context() unnecessary in this context
> (this will change with VFIO later though).

I think this wants a bit more explanation.  It certainly makes me
nervous removing the destroy_context calls with nothing replacing
them.

> Also, the pnv_npu2_init() helper does not really need to call OPAL as
> well as it inialized an NPU structure and does not interact with GPU or
> NPU at that moment.
> 
> This moves OPAL calls to a separate helper. With this change, the API
> for GPUs does not do any OPAL calls and therefore can be used by both
> pseries and powernv platforms. The new pnv_npu2_map_lpar_phb() helper
> should be called on powernv only as it does OPAL calls and it takes
> an MSR mask which NPU adds to ATS requests so nested MMU knows what
> translations are permitted; the VFIO/KVM will not set MSR_HV.
> 
> This removes the check for FW_FEATURE_OPAL as pnv_npu2_init_context/
> pnv_npu2_release_context/pnv_npu2_init do not call OPAL anymore.
> 
> Signed-off-by: Alexey Kardashevskiy 
> ---
>  arch/powerpc/include/asm/pci.h|   1 +
>  arch/powerpc/platforms/powernv/pci.h  |   2 +-
>  arch/powerpc/platforms/powernv/npu-dma.c  | 100 
> +++---
>  arch/powerpc/platforms/powernv/pci-ioda.c |   7 ++-
>  4 files changed, 57 insertions(+), 53 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
> index 1a96075..f196df6 100644
> --- a/arch/powerpc/include/asm/pci.h
> +++ b/arch/powerpc/include/asm/pci.h
> @@ -130,5 +130,6 @@ extern void pcibios_scan_phb(struct pci_controller *hose);
>  extern struct pci_dev *pnv_pci_get_gpu_dev(struct pci_dev *npdev);
>  extern struct pci_dev *pnv_pci_get_npu_dev(struct pci_dev *gpdev, int index);
>  extern void pnv_npu2_devices_init(void);
> +extern int pnv_npu2_init(struct pci_controller *hose);
>  
>  #endif /* __ASM_POWERPC_PCI_H */
> diff --git a/arch/powerpc/platforms/powernv/pci.h 
> b/arch/powerpc/platforms/powernv/pci.h
> index 3b7617d..ca2ce4b 100644
> --- a/arch/powerpc/platforms/powernv/pci.h
> +++ b/arch/powerpc/platforms/powernv/pci.h
> @@ -224,7 +224,7 @@ extern long pnv_npu_set_window(struct pnv_ioda_pe *npe, 
> int num,
>  extern long pnv_npu_unset_window(struct pnv_ioda_pe *npe, int num);
>  extern void pnv_npu_take_ownership(struct pnv_ioda_pe *npe);
>  extern void pnv_npu_release_ownership(struct pnv_ioda_pe *npe);
> -extern int pnv_npu2_init(struct pnv_phb *phb);
> +extern void pnv_npu2_map_lpar_phb(struct pnv_phb *nphb, unsigned long msr);
>  
>  /* pci-ioda-tce.c */
>  #define POWERNV_IOMMU_DEFAULT_LEVELS 1
> diff --git a/arch/powerpc/platforms/powernv/npu-dma.c 
> b/arch/powerpc/platforms/powernv/npu-dma.c
> index cb2b4f9..677f30a 100644
> --- a/arch/powerpc/platforms/powernv/npu-dma.c
> +++ b/arch/powerpc/platforms/powernv/npu-dma.c
> @@ -762,7 +762,6 @@ struct npu_context *pnv_npu2_init_context(struct pci_dev 
> *gpdev,
>   u32 nvlink_index;
>   struct device_node *nvlink_dn;
>   struct mm_struct *mm = current->mm;
> - struct pnv_phb *nphb;
>   struct npu *npu;
>   struct npu_context *npu_context;
>  
> @@ -772,9 +771,6 @@ struct npu_context *pnv_npu2_init_context(struct pci_dev 
> *gpdev,
>*/
>   struct pci_dev *npdev = pnv_pci_get_npu_dev(gpdev, 0);
>  
> - if (!firmware_has_feature(FW_FEATURE_OPAL))
> - return ERR_PTR(-ENODEV);
> -
>   if (!npdev)
>   /* No nvlink associated with this GPU device */
>   return ERR_PTR(-ENODEV);
> @@ -792,22 +788,9 @@ struct npu_context *pnv_npu2_init_context(struct pci_dev 
> *gpdev,
>   return ERR_PTR(-EINVAL);
>   }
>  
> - nphb = pci_bus_to_host(npdev->bus)->private_data;
>   npu = npdev_to_npu(npdev);
>  
>   /*
> -  * Setup the NPU context table for a particular GPU. These need to be
> -  * per-GPU as we need the tables to filter ATSDs when there are no
> -  * active contexts on a particular GPU. It is safe for these to be
> -  * called concurrently with destroy as the OPAL call takes appropriate
> -  * locks and refcounts on init/destroy.
> -  */
> - rc = opal_npu_init_context(nphb->opal_id, mm->context.id,
> flags,

AFAICT this was the only use of 'flags' in this function, so it should
be removed from the signature, no?

> - PCI_DEVID(gpdev->bus->number, gpdev->devfn));
> - if (rc < 0)
> - return ERR_PTR(-ENOSPC);
> -
> - /*
>* We store the npu pci device so we can more easily get at the
>* 

Re: [PATCH kernel 1/3] vfio_pci: Allow mapping extra regions

2018-11-07 Thread David Gibson
On Mon, Oct 15, 2018 at 08:42:31PM +1100, Alexey Kardashevskiy wrote:
65;5402;1c> So far we only allowed mapping of MMIO BARs to the userspace. 
However
> there there are GPUs with on-board coherent RAM accessible via side
> channels which we also want to map to the userspace. The first client
> for this is NVIDIA V100 GPU with NVLink2 direct links to a POWER9
> NPU-enabled CPU; such GPUs have 16GB RAM which is coherently mapped
> to the system address space, we are going to export these as an extra
> PCI region.
> 
> We already support extra PCI regions and this adds support for mapping
> them to the userspace.
> 
> Signed-off-by: Alexey Kardashevskiy 

Reviewed-by: David Gibson 

> ---
> Changes:
> v2:
> * reverted one of mistakenly removed error checks
> ---
>  drivers/vfio/pci/vfio_pci_private.h | 3 +++
>  drivers/vfio/pci/vfio_pci.c | 8 
>  2 files changed, 11 insertions(+)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_private.h 
> b/drivers/vfio/pci/vfio_pci_private.h
> index cde3b5d..86aab05 100644
> --- a/drivers/vfio/pci/vfio_pci_private.h
> +++ b/drivers/vfio/pci/vfio_pci_private.h
> @@ -59,6 +59,9 @@ struct vfio_pci_regops {
> size_t count, loff_t *ppos, bool iswrite);
>   void(*release)(struct vfio_pci_device *vdev,
>  struct vfio_pci_region *region);
> + int (*mmap)(struct vfio_pci_device *vdev,
> + struct vfio_pci_region *region,
> + struct vm_area_struct *vma);
>  };
>  
>  struct vfio_pci_region {
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index d9af440..7923314 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -1126,6 +1126,14 @@ static int vfio_pci_mmap(void *device_data, struct 
> vm_area_struct *vma)
>   return -EINVAL;
>   if ((vma->vm_flags & VM_SHARED) == 0)
>   return -EINVAL;
> + if (index >= VFIO_PCI_NUM_REGIONS) {
> + int regnum = index - VFIO_PCI_NUM_REGIONS;
> + struct vfio_pci_region *region = vdev->region + regnum;
> +
> + if (region && region->ops && region->ops->mmap)
> + return region->ops->mmap(vdev, region, vma);
> + return -EINVAL;
> + }
>   if (index >= VFIO_PCI_ROM_REGION_INDEX)
>   return -EINVAL;
>   if (!vdev->bar_mmap_supported[index])

-- 
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] powerpc: Mark variable `cpumsr` as unused

2018-11-07 Thread Christophe Leroy




On 11/07/2018 08:26 PM, Mathieu Malaterre wrote:

Add gcc attribute unused for `cpumsr` variable.

Fix warnings treated as errors with W=1:

   arch/powerpc/kernel/process.c:231:16: error: variable ‘cpumsr’ set but not 
used [-Werror=unused-but-set-variable]
   arch/powerpc/kernel/process.c:296:16: error: variable ‘cpumsr’ set but not 
used [-Werror=unused-but-set-variable]

Signed-off-by: Mathieu Malaterre 


I don't think this is the good way to fix that. This problem was 
introduced by commit 5c784c8414fb ("powerpc/tm: Remove 
msr_tm_active()"). That commit should be reverted and fixed.


That commit should have removed the macro and kept the inline function.

Christophe


---
  arch/powerpc/kernel/process.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 96f34730010f..b9f1a2408738 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -228,7 +228,7 @@ EXPORT_SYMBOL_GPL(flush_fp_to_thread);
  
  void enable_kernel_fp(void)

  {
-   unsigned long cpumsr;
+   unsigned long cpumsr __maybe_unused;
  
  	WARN_ON(preemptible());
  
@@ -293,7 +293,7 @@ EXPORT_SYMBOL(giveup_altivec);
  
  void enable_kernel_altivec(void)

  {
-   unsigned long cpumsr;
+   unsigned long cpumsr __maybe_unused;
  
  	WARN_ON(preemptible());
  



Re: [PATCH kernel] powerpc/powernv/ioda1: Remove dead code for a single device PE

2018-11-07 Thread Alexey Kardashevskiy
Ping?


On 16/10/2018 13:30, Alexey Kardashevskiy wrote:
> At the moment PNV_IODA_PE_DEV is only used for NPU PEs which are not
> present on IODA1 machines (i.e. POWER7) so let's remove a piece of
> dead code.
> 
> Signed-off-by: Alexey Kardashevskiy 
> ---
> 
> We might actually want to get rid of the entire IODA1 there.
> ---
>  arch/powerpc/platforms/powernv/pci-ioda.c | 10 +-
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
> b/arch/powerpc/platforms/powernv/pci-ioda.c
> index cde7102..78b61f0 100644
> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> @@ -2367,15 +2367,7 @@ static void pnv_pci_ioda1_setup_dma_pe(struct pnv_phb 
> *phb,
>   pe->table_group.tce32_size = tbl->it_size << tbl->it_page_shift;
>   iommu_init_table(tbl, phb->hose->node);
>  
> - if (pe->flags & PNV_IODA_PE_DEV) {
> - /*
> -  * Setting table base here only for carrying iommu_group
> -  * further down to let iommu_add_device() do the job.
> -  * pnv_pci_ioda_dma_dev_setup will override it later anyway.
> -  */
> - set_iommu_table_base(>pdev->dev, tbl);
> - iommu_add_device(>pdev->dev);
> - } else if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL))
> + if (pe->flags & (PNV_IODA_PE_BUS | PNV_IODA_PE_BUS_ALL))
>   pnv_ioda_setup_bus_dma(pe, pe->pbus, true);
>  
>   return;
> 

-- 
Alexey


[linuxppc-dev][PATCH] powerpc: mm: numa: Suppress "VPHN is not supported. Disabling polling" prints

2018-11-07 Thread sathnaga
From: Satheesh Rajendran 

When VPHN function is not supported and during cpu hotplug event, kernel
prints message 'VPHN function not supported. Disabling polling...'.
Currently it prints on every hotplug event, it floods dmesg
when a KVM guest tries to hotplug huge number of vcpus,
let's just print once and suppress further kernel prints.

Signed-off-by: Satheesh Rajendran 
---
 arch/powerpc/mm/numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 0c7e05d89244..844cc7347ebd 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1180,7 +1180,7 @@ static long vphn_get_associativity(unsigned long cpu,
 
switch (rc) {
case H_FUNCTION:
-   printk(KERN_INFO
+   printk_once(KERN_INFO
"VPHN is not supported. Disabling polling...\n");
stop_topology_update();
break;
-- 
2.17.0



[PATCH] powerpc: Add KVM guest defconfig

2018-11-07 Thread sathnaga
From: Satheesh Rajendran 

This patch adds new defconfig options for powerpc KVM guest
and guest.config with additional config symbols enabled,
which is to build kernel to boot without initramfs and can be used
as place holder for guest specific additional config symbols in future.

Signed-off-by: Michael Ellerman 
Signed-off-by: Satheesh Rajendran 
---
 arch/powerpc/Makefile |  8 
 arch/powerpc/configs/guest.config | 14 ++
 2 files changed, 22 insertions(+)
 create mode 100644 arch/powerpc/configs/guest.config

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 8a2ce14d68d0..0bff8bd82ed5 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -317,6 +317,14 @@ PHONY += ppc64le_defconfig
 ppc64le_defconfig:
$(call merge_into_defconfig,ppc64_defconfig,le)
 
+PHONY += ppc64le_guest_defconfig
+ppc64le_guest_defconfig:
+   $(call merge_into_defconfig,ppc64_defconfig,le guest)
+
+PHONY += ppc64_guest_defconfig
+ppc64_guest_defconfig:
+   $(call merge_into_defconfig,ppc64_defconfig,be guest)
+
 PHONY += powernv_be_defconfig
 powernv_be_defconfig:
$(call merge_into_defconfig,powernv_defconfig,be)
diff --git a/arch/powerpc/configs/guest.config 
b/arch/powerpc/configs/guest.config
new file mode 100644
index ..a5eb8b904058
--- /dev/null
+++ b/arch/powerpc/configs/guest.config
@@ -0,0 +1,14 @@
+CONFIG_VIRTIO_BLK=y
+CONFIG_VIRTIO_BLK_SCSI=y
+CONFIG_SCSI_VIRTIO=y
+CONFIG_VIRTIO_NET=y
+CONFIG_NET_FAILOVER=y
+CONFIG_VIRTIO_CONSOLE=y
+CONFIG_VIRTIO=y
+CONFIG_VIRTIO_PCI=y
+CONFIG_KVM_GUEST=y
+CONFIG_EPAPR_PARAVIRT=y
+CONFIG_XFS_FS=y
+CONFIG_VIRTIO_BALLOON=y
+CONFIG_VHOST_NET=y
+CONFIG_VHOST=y
-- 
2.17.2



Re: [PATCH] Documentation: fix spelling mistake, EACCESS -> EACCES

2018-11-07 Thread Jeremy Kerr

Hi Jon,


Signed-off-by: Colin Ian King 
---
  Documentation/filesystems/spufs.txt | 2 +-
  Documentation/gpu/drm-uapi.rst  | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)


Applied, thanks.

This is the first patch to spufs.txt since 2006...I wonder if that stuff
is being used by anybody...


Anyone who is using the vector processors on the Cell BE processors will
be using it. However, that hardware is becoming pretty rare now.

We'll want to remove the spufs bits if/when we drop support for the cell
platforms (IBM QSxx, PS3, celleb). mpe: any ides on that? Do you have a 
policy for dropping platform support?


Cheers,


Jeremy


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

2018-11-07 Thread Michael Ellerman
Frank Rowand  writes:
> On 11/7/18 4:08 AM, Michael Ellerman wrote:
>> frowand.l...@gmail.com writes:
>> 
>>> From: Frank Rowand 
>>>
>>> of_attach_node() and of_detach_node() always return zero, so
>>> their return value is meaningless.
>> 
>> But should they always return zero?
>> 
>> At least __of_attach_node_sysfs() can fail in several ways.
>
> Sigh.  And of_reconfig_notify() can fail.  And at one point in the
> history the return value of of_reconfig_notify() was returned by
> of_attach_node() if of_reconfig_notify() failed.
>
>> And there's also this in __of_detach_node() which should probably be
>> returning an error:
>> 
>>  if (WARN_ON(of_node_check_flag(np, OF_DETACHED)))
>>  return;
>> 
>> 
>> Seems to me we should instead be fixing these to propagate errors,
>> rather than hiding them?
>
> The history of how of_attach_node() stopped propagating errors is
> a bit more complex than I want to dig into at the moment.  So I'll
> drop this patch from the series and add investigating this onto
> my todo list.  I suspect that the result of investigating will be
> that error return values should not be ignored in of_attach_node()
> and of_detach_node(), but should instead be propagated to the
> callers, as you suggest.

Thanks.

cheers


Re: [PATCH] Documentation: fix spelling mistake, EACCESS -> EACCES

2018-11-07 Thread Jonathan Corbet
On Fri, 26 Oct 2018 18:25:49 +0100
Colin King  wrote:

> Trivial fix to a spelling mistake of the error access name EACCESS,
> rename to EACCES
> 
> Signed-off-by: Colin Ian King 
> ---
>  Documentation/filesystems/spufs.txt | 2 +-
>  Documentation/gpu/drm-uapi.rst  | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.  

This is the first patch to spufs.txt since 2006...I wonder if that stuff
is being used by anybody...

jon


Re: KVM: PPC: Move and undef TRACE_INCLUDE_PATH/FILE

2018-11-07 Thread Michael Ellerman
On Wed, 2018-11-07 at 01:49:34 UTC, Scott Wood wrote:
> TRACE_INCLUDE_PATH and TRACE_INCLUDE_FILE are used by
> , so like that #include, they should
> be outside #ifdef protection.
> 
> They also need to be #undefed before defining, in case multiple trace
> headers are included by the same C file.  This became the case on
> book3e after commit cf4a6085151a ("powerpc/mm: Add missing tracepoint for
> tlbie"), leading to the following build error:
> 
>CC  arch/powerpc/kvm/powerpc.o
> In file included from arch/powerpc/kvm/powerpc.c:51:0:
> arch/powerpc/kvm/trace.h:9:0: error: "TRACE_INCLUDE_PATH" redefined
> [-Werror]
>   #define TRACE_INCLUDE_PATH .
>   ^
> In file included from arch/powerpc/kvm/../mm/mmu_decl.h:25:0,
>   from arch/powerpc/kvm/powerpc.c:48:
> ./arch/powerpc/include/asm/trace.h:224:0: note: this is the location of
> the previous definition
>   #define TRACE_INCLUDE_PATH asm
>   ^
> cc1: all warnings being treated as errors
> 
> Reported-by: Christian Zigotzky 
> Signed-off-by: Scott Wood 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/28c5bcf74fa07c25d5bd118d127192

cheers


Re: [1/3] powerpc/mm/64s: Consolidate SLB assertions

2018-11-07 Thread Michael Ellerman
On Tue, 2018-11-06 at 12:37:07 UTC, Michael Ellerman wrote:
> The code for assert_slb_exists() and assert_slb_notexists() is almost
> identical, except for the polarity of the WARN_ON(). In a future patch
> we'll need to modify this code, so consolidate it now into a single
> function.
> 
> Signed-off-by: Michael Ellerman 

Series applied to powerpc fixes.

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

cheers


Re: powerpc/npu-dma: Remove NPU DMA ops

2018-11-07 Thread Michael Ellerman
On Tue, 2018-10-30 at 11:02:03 UTC, Alistair Popple wrote:
> The NPU IOMMU is setup to mirror the parent PCIe device IOMMU
> setup. Therefore it does not make sense to call dma operations such as
> dma_map_page, etc. directly on these devices. The existing dma-ops
> simply print a warning if they are ever called, however this is
> unnecessary and the warnings are likely to go unnoticed.
> 
> It is instead simpler to remove these operations and let the generic
> DMA code print warnings (eg. via a NULL pointer deref) in cases of
> buggy drivers attempting dma operations on NVLink devices.
> 
> Signed-off-by: Alistair Popple 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/3182215dd0b2120fb942ed88430cfb

cheers


[PATCH] lkdtm: print real addresses

2018-11-07 Thread Christophe Leroy
Today, when doing a lkdtm test before the readiness of the
random generator, (ptrval) is printed instead of the address
at which it perform the fault:

[ 1597.337030] lkdtm: Performing direct entry EXEC_USERSPACE
[ 1597.337142] lkdtm: attempting ok execution at (ptrval)
[ 1597.337398] lkdtm: attempting bad execution at (ptrval)
[ 1597.337460] kernel tried to execute user page (77858000) -exploit attempt? 
(uid: 0)
[ 1597.344769] Unable to handle kernel paging request for instruction fetch
[ 1597.351392] Faulting instruction address: 0x77858000
[ 1597.356312] Oops: Kernel access of bad area, sig: 11 [#1]

If the lkdtm test is done later on, it prints an hashed address.

In both cases this is pointless. The purpose of the test is to
ensure the kernel generates an Oops at the expected address,
so real addresses needs to be printed. This patch fixes that.

Signed-off-by: Christophe Leroy 
---
 drivers/misc/lkdtm/perms.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c
index 53b85c9d16b8..fa54add6375a 100644
--- a/drivers/misc/lkdtm/perms.c
+++ b/drivers/misc/lkdtm/perms.c
@@ -47,7 +47,7 @@ static noinline void execute_location(void *dst, bool write)
 {
void (*func)(void) = dst;
 
-   pr_info("attempting ok execution at %p\n", do_nothing);
+   pr_info("attempting ok execution at %px\n", do_nothing);
do_nothing();
 
if (write == CODE_WRITE) {
@@ -55,7 +55,7 @@ static noinline void execute_location(void *dst, bool write)
flush_icache_range((unsigned long)dst,
   (unsigned long)dst + EXEC_SIZE);
}
-   pr_info("attempting bad execution at %p\n", func);
+   pr_info("attempting bad execution at %px\n", func);
func();
 }
 
@@ -66,14 +66,14 @@ static void execute_user_location(void *dst)
/* Intentionally crossing kernel/user memory boundary. */
void (*func)(void) = dst;
 
-   pr_info("attempting ok execution at %p\n", do_nothing);
+   pr_info("attempting ok execution at %px\n", do_nothing);
do_nothing();
 
copied = access_process_vm(current, (unsigned long)dst, do_nothing,
   EXEC_SIZE, FOLL_WRITE);
if (copied < EXEC_SIZE)
return;
-   pr_info("attempting bad execution at %p\n", func);
+   pr_info("attempting bad execution at %px\n", func);
func();
 }
 
@@ -82,7 +82,7 @@ void lkdtm_WRITE_RO(void)
/* Explicitly cast away "const" for the test. */
unsigned long *ptr = (unsigned long *)
 
-   pr_info("attempting bad rodata write at %p\n", ptr);
+   pr_info("attempting bad rodata write at %px\n", ptr);
*ptr ^= 0xabcd1234;
 }
 
@@ -100,7 +100,7 @@ void lkdtm_WRITE_RO_AFTER_INIT(void)
return;
}
 
-   pr_info("attempting bad ro_after_init write at %p\n", ptr);
+   pr_info("attempting bad ro_after_init write at %px\n", ptr);
*ptr ^= 0xabcd1234;
 }
 
@@ -112,7 +112,7 @@ void lkdtm_WRITE_KERN(void)
size = (unsigned long)do_overwritten - (unsigned long)do_nothing;
ptr = (unsigned char *)do_overwritten;
 
-   pr_info("attempting bad %zu byte write at %p\n", size, ptr);
+   pr_info("attempting bad %zu byte write at %px\n", size, ptr);
memcpy(ptr, (unsigned char *)do_nothing, size);
flush_icache_range((unsigned long)ptr, (unsigned long)(ptr + size));
 
@@ -185,11 +185,11 @@ void lkdtm_ACCESS_USERSPACE(void)
 
ptr = (unsigned long *)user_addr;
 
-   pr_info("attempting bad read at %p\n", ptr);
+   pr_info("attempting bad read at %px\n", ptr);
tmp = *ptr;
tmp += 0xc0dec0de;
 
-   pr_info("attempting bad write at %p\n", ptr);
+   pr_info("attempting bad write at %px\n", ptr);
*ptr = tmp;
 
vm_munmap(user_addr, PAGE_SIZE);
-- 
2.13.3



[PATCH] powerpc: Mark variable `cpumsr` as unused

2018-11-07 Thread Mathieu Malaterre
Add gcc attribute unused for `cpumsr` variable.

Fix warnings treated as errors with W=1:

  arch/powerpc/kernel/process.c:231:16: error: variable ‘cpumsr’ set but not 
used [-Werror=unused-but-set-variable]
  arch/powerpc/kernel/process.c:296:16: error: variable ‘cpumsr’ set but not 
used [-Werror=unused-but-set-variable]

Signed-off-by: Mathieu Malaterre 
---
 arch/powerpc/kernel/process.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 96f34730010f..b9f1a2408738 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -228,7 +228,7 @@ EXPORT_SYMBOL_GPL(flush_fp_to_thread);
 
 void enable_kernel_fp(void)
 {
-   unsigned long cpumsr;
+   unsigned long cpumsr __maybe_unused;
 
WARN_ON(preemptible());
 
@@ -293,7 +293,7 @@ EXPORT_SYMBOL(giveup_altivec);
 
 void enable_kernel_altivec(void)
 {
-   unsigned long cpumsr;
+   unsigned long cpumsr __maybe_unused;
 
WARN_ON(preemptible());
 
-- 
2.11.0



Re: [alsa-devel] [PATCH] ASoC: fsl_ssi: Change to use DEFINE_SHOW_ATTRIBUTE macro

2018-11-07 Thread Fabio Estevam
On Wed, Nov 7, 2018 at 4:57 PM Yangtao Li  wrote:
>
> Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
>
> Signed-off-by: Yangtao Li 

Reviewed-by: Fabio Estevam 


Re: [PATCH] selftests/powerpc: Fix wild_bctr test to work on BE

2018-11-07 Thread Segher Boessenkool
Hi!

On Wed, Nov 07, 2018 at 09:17:23PM +1100, Michael Ellerman wrote:
> The selftest I recently added to test branching to an out-of-bounds
> NIP doesn't work on big endian. It does fail but not in the right way.
> That is it SEGVs trying to load from the opd at BAD_NIP, but it never
> gets as far as branching to BAD_NIP.
> 
> To fix it we need to create an opd which is reachable but which holds
> the bad address.


> +#ifdef __BIG_ENDIAN__

Maybe you should test for _CALL_AIXDESC instead?  It is more directly
what you want to know, and it even works correctly in all cases ;-)


Segher


Re: [RFC PATCH v1 5/6] powerpc/mm: Add a framework for Kernel Userspace Access Protection

2018-11-07 Thread Christophe LEROY




Le 07/11/2018 à 17:56, Christophe Leroy a écrit :

This patch implements a framework for Kernel Userspace Access Protection.

Then subarches will have to possibility to provide their own implementation
by providing setup_kuap(), and lock/unlock_user_rd/wr_access

We separate read and write accesses because some subarches like
book3s32 might only support write access protection.

Signed-off-by: Christophe Leroy 


Note that many parts of this patch comes from Russel's serie. Thanks.


---
  Documentation/admin-guide/kernel-parameters.txt |  2 +-
  arch/powerpc/include/asm/futex.h|  4 +++
  arch/powerpc/include/asm/mmu.h  |  6 
  arch/powerpc/include/asm/uaccess.h  | 44 -
  arch/powerpc/lib/checksum_wrappers.c|  4 +++
  arch/powerpc/mm/fault.c | 17 +++---
  arch/powerpc/mm/init-common.c   | 10 ++
  arch/powerpc/platforms/Kconfig.cputype  | 12 +++
  8 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 1103549363bb..0d059b141ff8 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2792,7 +2792,7 @@
noexec=on: enable non-executable mappings (default)
noexec=off: disable non-executable mappings
  
-	nosmap		[X86]

+   nosmap  [X86,PPC]
Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor.
  
diff --git a/arch/powerpc/include/asm/futex.h b/arch/powerpc/include/asm/futex.h

index 94542776a62d..bd58be09f1e8 100644
--- a/arch/powerpc/include/asm/futex.h
+++ b/arch/powerpc/include/asm/futex.h
@@ -35,6 +35,7 @@ static inline int arch_futex_atomic_op_inuser(int op, int 
oparg, int *oval,
  {
int oldval = 0, ret;
  
+	unlock_user_wr_access();

pagefault_disable();
  
  	switch (op) {

@@ -62,6 +63,7 @@ static inline int arch_futex_atomic_op_inuser(int op, int 
oparg, int *oval,
if (!ret)
*oval = oldval;
  
+	lock_user_wr_access();

return ret;
  }
  
@@ -75,6 +77,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,

if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
return -EFAULT;
  
+	unlock_user_wr_access();

  __asm__ __volatile__ (
  PPC_ATOMIC_ENTRY_BARRIER
  "1: lwarx   %1,0,%3 # futex_atomic_cmpxchg_inatomic\n\
@@ -95,6 +98,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
  : "cc", "memory");
  
  	*uval = prev;

+   lock_user_wr_access();
  return ret;
  }
  
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h

index cf92f2a813a8..5631a906af55 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -276,6 +276,12 @@ void setup_kuep(bool disabled);
  static inline void setup_kuep(bool disabled) { }
  #endif
  
+#ifdef CONFIG_PPC_KUAP

+void setup_kuap(bool disabled);
+#else
+static inline void setup_kuap(bool disabled) { }
+#endif
+
  #endif /* !__ASSEMBLY__ */
  
  /* The kernel use the constants below to index in the page sizes array.

diff --git a/arch/powerpc/include/asm/uaccess.h 
b/arch/powerpc/include/asm/uaccess.h
index 15bea9a0f260..2f3625cbfcee 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -6,6 +6,7 @@
  #include 
  #include 
  #include 
+#include 
  
  /*

   * The fs value determines whether argument validity checking should be
@@ -62,6 +63,13 @@ static inline int __access_ok(unsigned long addr, unsigned 
long size,
  
  #endif
  
+#ifndef CONFIG_PPC_KUAP

+static inline void unlock_user_rd_access(void) { }
+static inline void lock_user_rd_access(void) { }
+static inline void unlock_user_wr_access(void) { }
+static inline void lock_user_wr_access(void) { }
+#endif
+
  #define access_ok(type, addr, size)   \
(__chk_user_ptr(addr),  \
 __access_ok((__force unsigned long)(addr), (size), get_fs()))
@@ -141,6 +149,7 @@ extern long __put_user_bad(void);
  #define __put_user_size(x, ptr, size, retval) \
  do {  \
retval = 0; \
+   unlock_user_wr_access();\
switch (size) { \
  case 1: __put_user_asm(x, ptr, retval, "stb"); break;   \
  case 2: __put_user_asm(x, ptr, retval, "sth"); break;   \
@@ -148,6 +157,7 @@ do {
\
  case 8: __put_user_asm2(x, ptr, retval); break;   \
  default: __put_user_bad();\
} 

[RFC PATCH v1 6/6] powerpc/8xx: Add Kernel Userspace Access Protection

2018-11-07 Thread Christophe Leroy
This patch adds Kernel Userspace Access Protection on the 8xx.

When a page is RO or RW, it is set RO or RW for Key 0 and NA
for Key 1.

Up to now, the User group is defined with Key 0 for both User and
Supervisor.

By changing the group to Key 0 for User and Key 1 for Supervisor,
this patch prevents the Kernel from being able to access user data.

At exception entry, the kernel saves SPRN_MD_AP in the regs struct,
and reapply the protection. At exception exit it restore SPRN_MD_AP
with the value it had on exception entry.

For the time being, the unused mq field of pt_regs struct is used for
that.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/mmu-8xx.h   |  7 +++
 arch/powerpc/include/asm/nohash/32/pte-8xx.h | 23 +++
 arch/powerpc/kernel/asm-offsets.c|  1 +
 arch/powerpc/kernel/entry_32.S   | 19 +++
 arch/powerpc/kernel/process.c|  2 +-
 arch/powerpc/mm/8xx_mmu.c| 10 ++
 arch/powerpc/platforms/Kconfig.cputype   |  1 +
 7 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/mmu-8xx.h 
b/arch/powerpc/include/asm/mmu-8xx.h
index 53dbf0788fce..bab8568def50 100644
--- a/arch/powerpc/include/asm/mmu-8xx.h
+++ b/arch/powerpc/include/asm/mmu-8xx.h
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _ASM_POWERPC_MMU_8XX_H_
 #define _ASM_POWERPC_MMU_8XX_H_
+
 /*
  * PPC8xx support
  */
@@ -120,6 +121,12 @@
  */
 #define MD_APG_INIT0x
 
+/*
+ * 0 => No user => 01 (all accesses performed according to page definition)
+ * 1 => User => 10 (all accesses performed according to swaped page definition)
+ */
+#define MD_APG_KUAP0x
+
 /* The effective page number register.  When read, contains the information
  * about the last instruction TLB miss.  When MD_RPN is written, bits in
  * this register are used to create the TLB entry.
diff --git a/arch/powerpc/include/asm/nohash/32/pte-8xx.h 
b/arch/powerpc/include/asm/nohash/32/pte-8xx.h
index 6bfe041ef59d..f1ec7cf949d5 100644
--- a/arch/powerpc/include/asm/nohash/32/pte-8xx.h
+++ b/arch/powerpc/include/asm/nohash/32/pte-8xx.h
@@ -135,6 +135,29 @@ static inline pte_t pte_mkhuge(pte_t pte)
 }
 
 #define pte_mkhuge pte_mkhuge
+
+#ifdef CONFIG_PPC_KUAP
+static inline void lock_user_wr_access(void)
+{
+   mtspr(SPRN_MD_AP, MD_APG_KUAP);
+}
+
+static inline void unlock_user_wr_access(void)
+{
+   mtspr(SPRN_MD_AP, MD_APG_INIT);
+}
+
+static inline void lock_user_rd_access(void)
+{
+   mtspr(SPRN_MD_AP, MD_APG_KUAP);
+}
+
+static inline void unlock_user_rd_access(void)
+{
+   mtspr(SPRN_MD_AP, MD_APG_INIT);
+}
+#endif
+
 #endif
 
 #endif /* __KERNEL__ */
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 9ffc72ded73a..da2f5d011ddb 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -320,6 +320,7 @@ int main(void)
 */
STACK_PT_REGS_OFFSET(_DEAR, dar);
STACK_PT_REGS_OFFSET(_ESR, dsisr);
+   STACK_PT_REGS_OFFSET(_MQ, mq);
 #else /* CONFIG_PPC64 */
STACK_PT_REGS_OFFSET(SOFTE, softe);
STACK_PT_REGS_OFFSET(_PPR, ppr);
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 77decded1175..7fd9dc16dd48 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -155,6 +155,13 @@ transfer_to_handler:
mfspr   r2,SPRN_XER
stw r12,_CTR(r11)
stw r2,_XER(r11)
+#ifdef CONFIG_PPC_KUAP
+   mfspr   r2, SPRN_MD_AP
+   stw r2, _MQ(r11)
+   lis r2, MD_APG_KUAP@h
+   ori r2, r2, MD_APG_KUAP@l
+   mtspr   SPRN_MD_AP, r2
+#endif
mfspr   r12,SPRN_SPRG_THREAD
addir2,r12,-THREAD
tovirt(r2,r2)   /* set r2 to current */
@@ -447,6 +454,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
mtlrr4
mtcrr5
lwz r7,_NIP(r1)
+#ifdef CONFIG_PPC_KUAP
+   lwz r2, _MQ(r1)
+   mtspr   SPRN_MD_AP, r2
+#endif
lwz r2,GPR2(r1)
lwz r1,GPR1(r1)
 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
@@ -745,6 +756,10 @@ fast_exception_return:
mtcrr10
lwz r10,_LINK(r11)
mtlrr10
+#ifdef CONFIG_PPC_KUAP
+   lwz r10, _MQ(r11)
+   mtspr   SPRN_MD_AP, r10
+#endif
REST_GPR(10, r11)
 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
mtspr   SPRN_NRI, r0
@@ -997,6 +1012,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
.globl exc_exit_restart
 exc_exit_restart:
lwz r12,_NIP(r1)
+#ifdef CONFIG_PPC_KUAP
+   lwz r10, _MQ(r1)
+   mtspr   SPRN_MD_AP, r10
+#endif
 #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
mtspr   SPRN_NRI, r0
 #endif
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 96f34730010f..bbec29bda4cb 

[RFC PATCH v1 5/6] powerpc/mm: Add a framework for Kernel Userspace Access Protection

2018-11-07 Thread Christophe Leroy
This patch implements a framework for Kernel Userspace Access Protection.

Then subarches will have to possibility to provide their own implementation
by providing setup_kuap(), and lock/unlock_user_rd/wr_access

We separate read and write accesses because some subarches like
book3s32 might only support write access protection.

Signed-off-by: Christophe Leroy 
---
 Documentation/admin-guide/kernel-parameters.txt |  2 +-
 arch/powerpc/include/asm/futex.h|  4 +++
 arch/powerpc/include/asm/mmu.h  |  6 
 arch/powerpc/include/asm/uaccess.h  | 44 -
 arch/powerpc/lib/checksum_wrappers.c|  4 +++
 arch/powerpc/mm/fault.c | 17 +++---
 arch/powerpc/mm/init-common.c   | 10 ++
 arch/powerpc/platforms/Kconfig.cputype  | 12 +++
 8 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 1103549363bb..0d059b141ff8 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2792,7 +2792,7 @@
noexec=on: enable non-executable mappings (default)
noexec=off: disable non-executable mappings
 
-   nosmap  [X86]
+   nosmap  [X86,PPC]
Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor.
 
diff --git a/arch/powerpc/include/asm/futex.h b/arch/powerpc/include/asm/futex.h
index 94542776a62d..bd58be09f1e8 100644
--- a/arch/powerpc/include/asm/futex.h
+++ b/arch/powerpc/include/asm/futex.h
@@ -35,6 +35,7 @@ static inline int arch_futex_atomic_op_inuser(int op, int 
oparg, int *oval,
 {
int oldval = 0, ret;
 
+   unlock_user_wr_access();
pagefault_disable();
 
switch (op) {
@@ -62,6 +63,7 @@ static inline int arch_futex_atomic_op_inuser(int op, int 
oparg, int *oval,
if (!ret)
*oval = oldval;
 
+   lock_user_wr_access();
return ret;
 }
 
@@ -75,6 +77,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
return -EFAULT;
 
+   unlock_user_wr_access();
 __asm__ __volatile__ (
 PPC_ATOMIC_ENTRY_BARRIER
 "1: lwarx   %1,0,%3 # futex_atomic_cmpxchg_inatomic\n\
@@ -95,6 +98,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
 : "cc", "memory");
 
*uval = prev;
+   lock_user_wr_access();
 return ret;
 }
 
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index cf92f2a813a8..5631a906af55 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -276,6 +276,12 @@ void setup_kuep(bool disabled);
 static inline void setup_kuep(bool disabled) { }
 #endif
 
+#ifdef CONFIG_PPC_KUAP
+void setup_kuap(bool disabled);
+#else
+static inline void setup_kuap(bool disabled) { }
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 /* The kernel use the constants below to index in the page sizes array.
diff --git a/arch/powerpc/include/asm/uaccess.h 
b/arch/powerpc/include/asm/uaccess.h
index 15bea9a0f260..2f3625cbfcee 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * The fs value determines whether argument validity checking should be
@@ -62,6 +63,13 @@ static inline int __access_ok(unsigned long addr, unsigned 
long size,
 
 #endif
 
+#ifndef CONFIG_PPC_KUAP
+static inline void unlock_user_rd_access(void) { }
+static inline void lock_user_rd_access(void) { }
+static inline void unlock_user_wr_access(void) { }
+static inline void lock_user_wr_access(void) { }
+#endif
+
 #define access_ok(type, addr, size)\
(__chk_user_ptr(addr),  \
 __access_ok((__force unsigned long)(addr), (size), get_fs()))
@@ -141,6 +149,7 @@ extern long __put_user_bad(void);
 #define __put_user_size(x, ptr, size, retval)  \
 do {   \
retval = 0; \
+   unlock_user_wr_access();\
switch (size) { \
  case 1: __put_user_asm(x, ptr, retval, "stb"); break; \
  case 2: __put_user_asm(x, ptr, retval, "sth"); break; \
@@ -148,6 +157,7 @@ do {
\
  case 8: __put_user_asm2(x, ptr, retval); break;   \
  default: __put_user_bad();\
}   \
+   lock_user_wr_access();  \
 } while (0)
 
 #define 

[RFC PATCH v1 4/6] powerpc/8xx: Add Kernel Userspace Execution Prevention

2018-11-07 Thread Christophe Leroy
This patch adds Kernel Userspace Execution Prevention on the 8xx.

When a page is Executable, it is set Executable for Key 0 and NX
for Key 1.

Up to now, the User group is defined with Key 0 for both User and
Supervisor.

By changing the group to Key 0 for User and Key 1 for Supervisor,
this patch prevents the Kernel from being able to execute user code.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/mmu-8xx.h |  6 ++
 arch/powerpc/mm/8xx_mmu.c  | 10 ++
 arch/powerpc/platforms/Kconfig.cputype |  1 +
 3 files changed, 17 insertions(+)

diff --git a/arch/powerpc/include/asm/mmu-8xx.h 
b/arch/powerpc/include/asm/mmu-8xx.h
index fa05aa566ece..53dbf0788fce 100644
--- a/arch/powerpc/include/asm/mmu-8xx.h
+++ b/arch/powerpc/include/asm/mmu-8xx.h
@@ -41,6 +41,12 @@
  */
 #define MI_APG_INIT0x
 
+/*
+ * 0 => No user => 01 (all accesses performed according to page definition)
+ * 1 => User => 10 (all accesses performed according to swaped page definition)
+ */
+#define MI_APG_KUEP0x
+
 /* The effective page number register.  When read, contains the information
  * about the last instruction TLB miss.  When MI_RPN is written, bits in
  * this register are used to create the TLB entry.
diff --git a/arch/powerpc/mm/8xx_mmu.c b/arch/powerpc/mm/8xx_mmu.c
index 01b7f5107c3a..597d3bd2d9b5 100644
--- a/arch/powerpc/mm/8xx_mmu.c
+++ b/arch/powerpc/mm/8xx_mmu.c
@@ -194,3 +194,13 @@ void flush_instruction_cache(void)
mtspr(SPRN_IC_CST, IDC_INVALL);
isync();
 }
+
+void setup_kuep(bool disabled)
+{
+   if (disabled)
+   return;
+
+   pr_warn("Activating Kernel Userspace Execution Prevention\n");
+
+   mtspr(SPRN_MI_AP, MI_APG_KUEP);
+}
diff --git a/arch/powerpc/platforms/Kconfig.cputype 
b/arch/powerpc/platforms/Kconfig.cputype
index 70830cb3c18a..bbcae320324c 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -33,6 +33,7 @@ config PPC_8xx
bool "Freescale 8xx"
select FSL_SOC
select SYS_SUPPORTS_HUGETLBFS
+   select PPC_HAVE_KUEP
 
 config 40x
bool "AMCC 40x"
-- 
2.13.3



[RFC PATCH v1 3/6] powerpc: Add skeleton for Kernel Userspace Execution Prevention

2018-11-07 Thread Christophe Leroy
This patch adds a skeleton for Kernel Userspace Execution Prevention.

Then subarches implementing it have to define CONFIG_PPC_HAVE_KUEP
and provide setup_kuep() function.

Signed-off-by: Christophe Leroy 
---
 Documentation/admin-guide/kernel-parameters.txt |  2 +-
 arch/powerpc/include/asm/mmu.h  |  6 ++
 arch/powerpc/mm/fault.c |  3 ++-
 arch/powerpc/mm/init-common.c   | 11 +++
 arch/powerpc/platforms/Kconfig.cputype  | 12 
 5 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 81d1d5a74728..1103549363bb 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2796,7 +2796,7 @@
Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor.
 
-   nosmep  [X86]
+   nosmep  [X86,PPC]
Disable SMEP (Supervisor Mode Execution Prevention)
even if it is supported by processor.
 
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 39c51dcba8f4..cf92f2a813a8 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -270,6 +270,12 @@ static inline u16 get_mm_addr_key(struct mm_struct *mm, 
unsigned long address)
 
 void setup_kup(void);
 
+#ifdef CONFIG_PPC_KUEP
+void setup_kuep(bool disabled);
+#else
+static inline void setup_kuep(bool disabled) { }
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 /* The kernel use the constants below to index in the page sizes array.
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 50e5c790d11e..e57bd46cf25b 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -230,8 +230,9 @@ static bool bad_kernel_fault(bool is_exec, unsigned long 
error_code,
if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT |
  DSISR_PROTFAULT))) {
printk_ratelimited(KERN_CRIT "kernel tried to execute"
-  " exec-protected page (%lx) -"
+  " %s page (%lx) -"
   "exploit attempt? (uid: %d)\n",
+  address >= TASK_SIZE ? "exec-protected" : 
"user",
   address, from_kuid(_user_ns,
  current_uid()));
}
diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index e469814e8290..89c8bd58509e 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -25,8 +25,19 @@
 #include 
 #include 
 
+static bool disable_kuep = !IS_ENABLED(CONFIG_PPC_KUEP);
+
+static int __init parse_nosmep(char *p)
+{
+   disable_kuep = true;
+   pr_warn("Disabling Kernel Userspace Execution Prevention\n");
+   return 0;
+}
+early_param("nosmep", parse_nosmep);
+
 void setup_kup(void)
 {
+   setup_kuep(disable_kuep);
 }
 
 static void pgd_ctor(void *addr)
diff --git a/arch/powerpc/platforms/Kconfig.cputype 
b/arch/powerpc/platforms/Kconfig.cputype
index f4e2c5729374..70830cb3c18a 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -351,6 +351,18 @@ config PPC_RADIX_MMU_DEFAULT
 
  If you're unsure, say Y.
 
+config PPC_HAVE_KUEP
+   bool
+
+config PPC_KUEP
+   bool "Kernel Userspace Execution Prevention"
+   depends on PPC_HAVE_KUEP
+   default y
+   help
+ Enable support for Kernel Userspace Execution Prevention (KUEP)
+
+ If you're unsure, say Y.
+
 config ARCH_ENABLE_HUGEPAGE_MIGRATION
def_bool y
depends on PPC_BOOK3S_64 && HUGETLB_PAGE && MIGRATION
-- 
2.13.3



[PATCH v1 1/6] powerpc/mm: Fix reporting of kernel execute faults on the 8xx

2018-11-07 Thread Christophe Leroy
On the 8xx, no-execute is set via PPP bits in the PTE. Therefore
a no-exec fault generates DSISR_PROTFAULT error bits,
not DSISR_NOEXEC_OR_G.

This patch adds DSISR_PROTFAULT in the test mask.

Fixes: d3ca587404b3 ("powerpc/mm: Fix reporting of kernel execute faults")
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/mm/fault.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 1697e903bbf2..50e5c790d11e 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -226,7 +226,9 @@ static int mm_fault_error(struct pt_regs *regs, unsigned 
long addr,
 static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
 unsigned long address)
 {
-   if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT))) {
+   /* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on 
others */
+   if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT |
+ DSISR_PROTFAULT))) {
printk_ratelimited(KERN_CRIT "kernel tried to execute"
   " exec-protected page (%lx) -"
   "exploit attempt? (uid: %d)\n",
-- 
2.13.3



[RFC PATCH v1 2/6] powerpc: Add framework for Kernel Userspace Protection

2018-11-07 Thread Christophe Leroy
This patch adds a skeleton for Kernel Userspace Protection
functionnalities like Kernel Userspace Access Protection and
Kernel Userspace Execution Prevention

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/mmu.h | 2 ++
 arch/powerpc/kernel/setup_64.c | 1 +
 arch/powerpc/mm/init-common.c  | 4 
 arch/powerpc/mm/init_32.c  | 2 ++
 4 files changed, 9 insertions(+)

diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index eb20eb3b8fb0..39c51dcba8f4 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -268,6 +268,8 @@ static inline u16 get_mm_addr_key(struct mm_struct *mm, 
unsigned long address)
 }
 #endif /* CONFIG_PPC_MEM_KEYS */
 
+void setup_kup(void);
+
 #endif /* !__ASSEMBLY__ */
 
 /* The kernel use the constants below to index in the page sizes array.
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 2a51e4cc8246..4e21b10ff38d 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -372,6 +372,7 @@ void __init early_setup(unsigned long dt_ptr)
 */
btext_map();
 #endif /* CONFIG_PPC_EARLY_DEBUG_BOOTX */
+   setup_kup();
 }
 
 #ifdef CONFIG_SMP
diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 2b656e67f2ea..e469814e8290 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -25,6 +25,10 @@
 #include 
 #include 
 
+void setup_kup(void)
+{
+}
+
 static void pgd_ctor(void *addr)
 {
memset(addr, 0, PGD_TABLE_SIZE);
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 3e59e5d64b01..4012ee6f0754 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -182,6 +182,8 @@ void __init MMU_init(void)
btext_unmap();
 #endif
 
+   setup_kup();
+
/* Shortly after that, the entire linear mapping will be available */
memblock_set_current_limit(lowmem_end_addr);
 }
-- 
2.13.3



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

2018-11-07 Thread Frank Rowand
On 11/7/18 4:09 AM, Michael Ellerman wrote:
> Frank Rowand  writes:
> 
>> Hi Michael, Ben, Paul,
>>
>> Do you know if anyone has tried this series on PowerPC?
> 
> I have. No obvious breakage.
> 
> My test does a loop of adding and removing multiple CPUs multiple times,
> and in the past that has uncovered refcounting bugs. So I don't think
> we're leaking any with this series applied.
> 
> I used the tracepoint patch to keep an eye on the refcounts :)
> 
>   https://patchwork.ozlabs.org/patch/751602/
> 
> 
> I'm happy for this series to go into linux-next where it should get some
> more testing.
> 
> cheers
> 

Thanks for the reviews and testing.

-Frank


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

2018-11-07 Thread Frank Rowand
On 11/7/18 4:23 AM, Michael Ellerman wrote:
> frowand.l...@gmail.com writes:
> 
>> From: Frank Rowand 
>>
>> "of: overlay: add missing of_node_get() in __of_attach_node_sysfs"
> 
> It would be clearer if you said 'The previous commit "of: overlay ..."

Will fix.


>> 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.
> 
> This looks OK to me in light of the previous patch.
> 
> Acked-by: Michael Ellerman 
> 
> It also means dlpar_detach_node() is again behaving as described in the
> comment to of_detach_node().
> 
> It would be good to make mention of:
> 
>   Fixes: 68baf692c435 ("powerpc/pseries: Fix of_node_put() underflow during 
> DLPAR remove")
> 
> Which removed an of_node_put() in the exact same place for different
> reasons.

OK.

-Frank

> 
> cheers
> 
>> 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 
> 



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

2018-11-07 Thread Frank Rowand
On 11/7/18 4:14 AM, Michael Ellerman wrote:
> frowand.l...@gmail.com writes:
> 
>> 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 seems sensible to me. I guess we could argue about whether the
> sysfs code needs its own reference, but it certainly doesn't hurt that
> it does, as long as it's handled symmetrically - which it is now.
> 
> Acked-by: Michael Ellerman  (powerpc)
> 
>> ---
>>
>> 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.
> 
> I think this should go in the changelog, it's useful information that we
> don't want to lose track of once this is applied.

Will do.

-Frank

> 
> Either that or we actually squash the two patches together when applying
> to avoid the bisection break.
> 
> cheers
> 
>>  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(>kobj, parent, "%s", name);
>>  kfree(name);
>>  if (rc)
>> @@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np)
>>  kobject_del(>kobj);
>>  }
>>  
>> -/* finally remove the kobj_init ref */
>>  of_node_put(np);
>>  }
>> -- 
>> Frank Rowand 
> 



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

2018-11-07 Thread Frank Rowand
On 11/7/18 4:08 AM, Michael Ellerman wrote:
> frowand.l...@gmail.com writes:
> 
>> From: Frank Rowand 
>>
>> of_attach_node() and of_detach_node() always return zero, so
>> their return value is meaningless.
> 
> But should they always return zero?
> 
> At least __of_attach_node_sysfs() can fail in several ways.

Sigh.  And of_reconfig_notify() can fail.  And at one point in the
history the return value of of_reconfig_notify() was returned by
of_attach_node() if of_reconfig_notify() failed.


> And there's also this in __of_detach_node() which should probably be
> returning an error:
> 
>   if (WARN_ON(of_node_check_flag(np, OF_DETACHED)))
>   return;
> 
> 
> Seems to me we should instead be fixing these to propagate errors,
> rather than hiding them?

The history of how of_attach_node() stopped propagating errors is
a bit more complex than I want to dig into at the moment.  So I'll
drop this patch from the series and add investigating this onto
my todo list.  I suspect that the result of investigating will be
that error return values should not be ignored in of_attach_node()
and of_detach_node(), but should instead be propagated to the
callers, as you suggest.

-Frank

> 
> cheers
> 



Re: [PATCH] KVM: PPC: Move and undef TRACE_INCLUDE_PATH/FILE

2018-11-07 Thread Naveen N. Rao

Scott Wood wrote:

TRACE_INCLUDE_PATH and TRACE_INCLUDE_FILE are used by
, so like that #include, they should
be outside #ifdef protection.

They also need to be #undefed before defining, in case multiple trace
headers are included by the same C file.  This became the case on
book3e after commit cf4a6085151a ("powerpc/mm: Add missing tracepoint for
tlbie"), leading to the following build error:

   CC  arch/powerpc/kvm/powerpc.o
In file included from arch/powerpc/kvm/powerpc.c:51:0:
arch/powerpc/kvm/trace.h:9:0: error: "TRACE_INCLUDE_PATH" redefined
[-Werror]
  #define TRACE_INCLUDE_PATH .
  ^
In file included from arch/powerpc/kvm/../mm/mmu_decl.h:25:0,
  from arch/powerpc/kvm/powerpc.c:48:
./arch/powerpc/include/asm/trace.h:224:0: note: this is the location of
the previous definition
  #define TRACE_INCLUDE_PATH asm
  ^
cc1: all warnings being treated as errors

Reported-by: Christian Zigotzky 
Signed-off-by: Scott Wood 
---
 arch/powerpc/kvm/trace.h   | 8 ++--
 arch/powerpc/kvm/trace_booke.h | 9 +++--
 arch/powerpc/kvm/trace_hv.h| 9 +++--
 arch/powerpc/kvm/trace_pr.h| 9 +++--
 4 files changed, 27 insertions(+), 8 deletions(-)


Thanks for getting to this. Apart from a small nit below, for this 
patch:

Reviewed-by: Naveen N. Rao 



diff --git a/arch/powerpc/kvm/trace.h b/arch/powerpc/kvm/trace.h
index 491b0f715d6b..ea1d7c808319 100644
--- a/arch/powerpc/kvm/trace.h
+++ b/arch/powerpc/kvm/trace.h
@@ -6,8 +6,6 @@

 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm
-#define TRACE_INCLUDE_PATH .
-#define TRACE_INCLUDE_FILE trace


The convention is to also have the TRACE_SYSTEM macro defined outside 
and before the header #ifdef. So, that would be good to do as part of 
this cleanup as well. If not, I can send a patch later.


Thanks,
Naveen




[PATCH trivial] powerpc: Typo s/use use/use/

2018-11-07 Thread Geert Uytterhoeven
Signed-off-by: Geert Uytterhoeven 
---
 arch/powerpc/include/asm/nohash/32/pte-40x.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/nohash/32/pte-40x.h 
b/arch/powerpc/include/asm/nohash/32/pte-40x.h
index 661f4599f2fc54a7..12c6811e344bc5ea 100644
--- a/arch/powerpc/include/asm/nohash/32/pte-40x.h
+++ b/arch/powerpc/include/asm/nohash/32/pte-40x.h
@@ -33,7 +33,7 @@
  *   is cleared in the TLB miss handler before the TLB entry is loaded.
  * - All other bits of the PTE are loaded into TLBLO without
  *   modification, leaving us only the bits 20, 21, 24, 25, 26, 30 for
- *   software PTE bits.  We actually use use bits 21, 24, 25, and
+ *   software PTE bits.  We actually use bits 21, 24, 25, and
  *   30 respectively for the software bits: ACCESSED, DIRTY, RW, and
  *   PRESENT.
  */
-- 
2.17.1



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

2018-11-07 Thread Michael Ellerman
frowand.l...@gmail.com writes:

> From: Frank Rowand 
>
> "of: overlay: add missing of_node_get() in __of_attach_node_sysfs"

It would be clearer if you said 'The previous commit "of: overlay ..."

> 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.

This looks OK to me in light of the previous patch.

Acked-by: Michael Ellerman 

It also means dlpar_detach_node() is again behaving as described in the
comment to of_detach_node().

It would be good to make mention of:

  Fixes: 68baf692c435 ("powerpc/pseries: Fix of_node_put() underflow during 
DLPAR remove")

Which removed an of_node_put() in the exact same place for different
reasons.

cheers

> 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 


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

2018-11-07 Thread Michael Ellerman
frowand.l...@gmail.com writes:

> 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 seems sensible to me. I guess we could argue about whether the
sysfs code needs its own reference, but it certainly doesn't hurt that
it does, as long as it's handled symmetrically - which it is now.

Acked-by: Michael Ellerman  (powerpc)

> ---
>
> 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.

I think this should go in the changelog, it's useful information that we
don't want to lose track of once this is applied.

Either that or we actually squash the two patches together when applying
to avoid the bisection break.

cheers

>  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(>kobj, parent, "%s", name);
>   kfree(name);
>   if (rc)
> @@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np)
>   kobject_del(>kobj);
>   }
>  
> - /* finally remove the kobj_init ref */
>   of_node_put(np);
>  }
> -- 
> Frank Rowand 


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

2018-11-07 Thread Michael Ellerman
Frank Rowand  writes:

> Hi Michael, Ben, Paul,
>
> Do you know if anyone has tried this series on PowerPC?

I have. No obvious breakage.

My test does a loop of adding and removing multiple CPUs multiple times,
and in the past that has uncovered refcounting bugs. So I don't think
we're leaking any with this series applied.

I used the tracepoint patch to keep an eye on the refcounts :)

  https://patchwork.ozlabs.org/patch/751602/


I'm happy for this series to go into linux-next where it should get some
more testing.

cheers


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

2018-11-07 Thread Michael Ellerman
frowand.l...@gmail.com writes:

> From: Frank Rowand 
>
> of_attach_node() and of_detach_node() always return zero, so
> their return value is meaningless.

But should they always return zero?

At least __of_attach_node_sysfs() can fail in several ways.

And there's also this in __of_detach_node() which should probably be
returning an error:

if (WARN_ON(of_node_check_flag(np, OF_DETACHED)))
return;


Seems to me we should instead be fixing these to propagate errors,
rather than hiding them?

cheers


Re: [PATCH 12/24] powerpc/mm: Fix reporting of kernel execute faults

2018-11-07 Thread Benjamin Herrenschmidt
On Wed, 2018-11-07 at 09:35 +0100, Christophe LEROY wrote:
> Hi Ben,
> 
> I have an issue on the 8xx with this change

Ah ouch...

 .../...
  
> > +/* Is this a bad kernel fault ? */
> > +static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
> > +unsigned long address)
> > +{
> > +   if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT))) {
> 
> Do you mind if we had DSISR_PROTFAULT here as well ?

Off the top of my mind, I don't see a problem with that... but it would
definitely require an explanation comment.

> > +   printk_ratelimited(KERN_CRIT "kernel tried to execute"
> > +  " exec-protected page (%lx) -"
> > +  "exploit attempt? (uid: %d)\n",
> > +  address, from_kuid(_user_ns,
> > + current_uid()));
> > +   }
> > +   return is_exec || (address >= TASK_SIZE);
> > +}
> > +
> >   /*
> >* Define the correct "is_write" bit in error_code based
> >* on the processor family
> > @@ -252,7 +266,7 @@ static int __do_page_fault(struct pt_regs *regs, 
> > unsigned long address,
> >  * The kernel should never take an execute fault nor should it
> >  * take a page fault to a kernel address.
> >  */
> > -   if (!is_user && (is_exec || (address >= TASK_SIZE)))
> > +   if (unlikely(!is_user && bad_kernel_fault(is_exec, error_code, 
> > address)))
> > return SIGSEGV;
> >   
> > /* We restore the interrupt state now */
> > @@ -491,11 +505,6 @@ static int __do_page_fault(struct pt_regs *regs, 
> > unsigned long address,
> > return 0;
> > }
> >   
> > -   if (is_exec && (error_code & DSISR_PROTFAULT))
> > -   printk_ratelimited(KERN_CRIT "kernel tried to execute 
> > NX-protected"
> > -  " page (%lx) - exploit attempt? (uid: %d)\n",
> > -  address, from_kuid(_user_ns, 
> > current_uid()));
> > -
> > return SIGSEGV;
> >   }
> >   NOKPROBE_SYMBOL(__do_page_fault);
> > 



[PATCH] selftests/powerpc: Fix wild_bctr test to work on BE

2018-11-07 Thread Michael Ellerman
The selftest I recently added to test branching to an out-of-bounds
NIP doesn't work on big endian. It does fail but not in the right way.
That is it SEGVs trying to load from the opd at BAD_NIP, but it never
gets as far as branching to BAD_NIP.

To fix it we need to create an opd which is reachable but which holds
the bad address.

Fixes: b7683fc66eba ("selftests/powerpc: Add a test of wild bctr")
Signed-off-by: Michael Ellerman 
---
 tools/testing/selftests/powerpc/mm/wild_bctr.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/mm/wild_bctr.c 
b/tools/testing/selftests/powerpc/mm/wild_bctr.c
index 1b0e9e9a2ddc..dda314bb59dd 100644
--- a/tools/testing/selftests/powerpc/mm/wild_bctr.c
+++ b/tools/testing/selftests/powerpc/mm/wild_bctr.c
@@ -105,6 +105,20 @@ static void dump_regs(void)
}
 }
 
+#ifdef __BIG_ENDIAN__
+struct opd {
+   unsigned long ip;
+   unsigned long toc;
+   unsigned long env;
+};
+static struct opd bad_opd = {
+   .ip = BAD_NIP,
+};
+#define BAD_FUNC (_opd)
+#else
+#define BAD_FUNC BAD_NIP
+#endif
+
 int test_wild_bctr(void)
 {
int (*func_ptr)(void);
@@ -133,7 +147,7 @@ int test_wild_bctr(void)
 
poison_regs();
 
-   func_ptr = (int (*)(void))BAD_NIP;
+   func_ptr = (int (*)(void))BAD_FUNC;
func_ptr();
 
FAIL_IF(1); /* we didn't segv? */
-- 
2.17.2



Re: [alsa-devel] Build regressions/improvements in v4.20-rc1 (sound/pci/hda/patch_ca0132.c)

2018-11-07 Thread Takashi Iwai
On Wed, 07 Nov 2018 09:44:25 +0100,
Geert Uytterhoeven wrote:
> 
> Hi Iwai-san,
> 
> On Tue, Nov 6, 2018 at 5:18 PM Takashi Iwai  wrote:
> > On Tue, 06 Nov 2018 02:04:47 +0100,
> > Randy Dunlap wrote:
> > >
> > > 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.
> >
> > Actually it is OK to enable CONFIG_SND_HDA_CODEC_CA0132 without
> > CONFIG_PCI.  IIRC, there was a system like that, too.
> > The commit above should have covered the build failure on SH, but
> > apparently isn't enough for some arch setups, as it seems.
> >
> > The cause is clear now: pci_iomap() is defined in
> > asm-generic/pci_iomap.h only when CONFIG_GENERIC_PCI_IOMAP is
> > defined.  Including asm/io.h doesn't help unless CONFIG_PCI is set.
> >
> > Below is a quick fix for this.
> >
> >
> > thanks,
> >
> > Takashi
> >
> > -- 8< --
> >
> > From: Takashi Iwai 
> > Subject: [PATCH] ALSA: hda/ca0132 - Yet more fix on build breakage without 
> > PCI
> >  support
> >
> > The recent change in CA0132 codec driver for supporting more
> > Creative boards includes the pci_iomap() call to get the extra
> > register accesses.  This is supposed to work on all archs and setups,
> > by the implicit assumption that every arch would provide a dummy
> > function returning NULL when no PCI is available.  But the reality
> > bites, of course; as Geert's regular build test shows, some configs
> > (at least SH4 without CONFIG_PCI) leads to a build error due to the
> > implicit function declaration.
> >
> > So this is another attempt to fix the issue: now we add an ifdef
> > CONFIG_PCI line, so that pci_iomap() won't be called unless PCI is
> > really usable.  This should fall back to the standard quirk again with
> > a warning.
> >
> > Fixes: d9b84a15892c0233 ("ALSA: hda: Fix implicit definition of pci_iomap() 
> > on SH")
> > Reported-by: Geert Uytterhoeven 
> > Cc: 
> > Signed-off-by: Takashi Iwai 
> 
> Thanks for your patch!
> 
> > --- a/sound/pci/hda/patch_ca0132.c
> > +++ b/sound/pci/hda/patch_ca0132.c
> > @@ -8796,7 +8796,13 @@ static int patch_ca0132(struct hda_codec *codec)
> > }
> >
> > if (spec->use_pci_mmio) {
> > +   /*
> > +* ifdef below needed due to lack of pci_iomap() decleration
> > +* for some archs when no PCI is defined
> > +*/
> > +#ifdef CONFIG_PCI
> > spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
> > +#endif
> 
> I'm sorry, but that is not a proper fix.
> This should be fixed in the SH-specific code, to behave like other
> architectures.

OK, this is the thing I didn't want to go deeply, as the problem is
messy...

The top of iceberg is that asm/pci_iomap.h defines the dummy function
of pci_iomap() only when CONFIG_PCI=n && CONFIG_GENERIC_PCI_IOMAP=y.
This has been so for long time since the commit 97a29d59fc22
[PARISC] fix compile break caused by iomap: make IOPORT/PCI
mapping function s conditional

Before that point, the header defined pci_iomap() and pci_ioumap()
whenever CONFIG_PCi=n.

And, looking at other arch codes, most of them define
CONFIG_GENERIC_PCI_IOMAP no matter whether CONFIG_PCI is set or not.
Actually this is supposedly OK, as the generic code (lib/pci_iomap.c)
contains a large ifdef CONFIG_PCI in it, so essentially it's empty
when CONFIG_PCI=n.

So, one possible fix would be to convert all fallout archs (alpha,
powerpc and sh) to define always CONFIG_GENERIC_PCI_IOMAP.  I'm not
100% sure whether this is safe, but we may try.

Another fix would be to revert the commit 97a29d59fc22, and let
asm/pci_iomap.h providing the dummy 

Re: [alsa-devel] Build regressions/improvements in v4.20-rc1 (sound/pci/hda/patch_ca0132.c)

2018-11-07 Thread Geert Uytterhoeven
Hi Iwai-san,

On Tue, Nov 6, 2018 at 5:18 PM Takashi Iwai  wrote:
> On Tue, 06 Nov 2018 02:04:47 +0100,
> Randy Dunlap wrote:
> >
> > 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.
>
> Actually it is OK to enable CONFIG_SND_HDA_CODEC_CA0132 without
> CONFIG_PCI.  IIRC, there was a system like that, too.
> The commit above should have covered the build failure on SH, but
> apparently isn't enough for some arch setups, as it seems.
>
> The cause is clear now: pci_iomap() is defined in
> asm-generic/pci_iomap.h only when CONFIG_GENERIC_PCI_IOMAP is
> defined.  Including asm/io.h doesn't help unless CONFIG_PCI is set.
>
> Below is a quick fix for this.
>
>
> thanks,
>
> Takashi
>
> -- 8< --
>
> From: Takashi Iwai 
> Subject: [PATCH] ALSA: hda/ca0132 - Yet more fix on build breakage without PCI
>  support
>
> The recent change in CA0132 codec driver for supporting more
> Creative boards includes the pci_iomap() call to get the extra
> register accesses.  This is supposed to work on all archs and setups,
> by the implicit assumption that every arch would provide a dummy
> function returning NULL when no PCI is available.  But the reality
> bites, of course; as Geert's regular build test shows, some configs
> (at least SH4 without CONFIG_PCI) leads to a build error due to the
> implicit function declaration.
>
> So this is another attempt to fix the issue: now we add an ifdef
> CONFIG_PCI line, so that pci_iomap() won't be called unless PCI is
> really usable.  This should fall back to the standard quirk again with
> a warning.
>
> Fixes: d9b84a15892c0233 ("ALSA: hda: Fix implicit definition of pci_iomap() 
> on SH")
> Reported-by: Geert Uytterhoeven 
> Cc: 
> Signed-off-by: Takashi Iwai 

Thanks for your patch!

> --- a/sound/pci/hda/patch_ca0132.c
> +++ b/sound/pci/hda/patch_ca0132.c
> @@ -8796,7 +8796,13 @@ static int patch_ca0132(struct hda_codec *codec)
> }
>
> if (spec->use_pci_mmio) {
> +   /*
> +* ifdef below needed due to lack of pci_iomap() decleration
> +* for some archs when no PCI is defined
> +*/
> +#ifdef CONFIG_PCI
> spec->mem_base = pci_iomap(codec->bus->pci, 2, 0xC20);
> +#endif

I'm sorry, but that is not a proper fix.
This should be fixed in the SH-specific code, to behave like other
architectures.

> if (spec->mem_base == NULL) {
> codec_warn(codec, "pci_iomap failed! Setting quirk to 
> QUIRK_NONE.");
> spec->quirk = QUIRK_NONE;

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 12/24] powerpc/mm: Fix reporting of kernel execute faults

2018-11-07 Thread Christophe LEROY

Hi Ben,

I have an issue on the 8xx with this change

Le 19/07/2017 à 06:49, Benjamin Herrenschmidt a écrit :

We currently test for is_exec and DSISR_PROTFAULT but that doesn't
make sense as this is the wrong error bit to test for an execute
permission failure.


On the 8xx, on an exec permission failure, this is the correct BIT, see 
below extract from reference manual:


Note that only one of bits 1, 3, and 4 will be set.
1 1 if the translation of an attempted access is not in the translation 
tables. Otherwise 0

3 1 if the fetch access was to guarded memory when MSR[IR] = 1. Otherwise 0
4 1 if the access is not permitted by the protection mechanism; otherwise 0.

So on the 8xx, bit 3 is not DSISR_NOEXEC_OR_G but only DSISR_G.
When the PPP bits are set to No-Execute, we really get bit 4 that is 
DSISR_PROTFAULT.




In fact, we had code that would return early if we had an exec
fault in kernel mode so I think that was just dead code anyway.

Finally the location of that test is awkward and prevents further
simplifications.

So instead move that test into a helper along with the existing
early test for kernel exec faults and out of range accesses,
and put it all in a "bad_kernel_fault()" helper. While at it
test the correct error bits.

Signed-off-by: Benjamin Herrenschmidt 
---
  arch/powerpc/mm/fault.c | 21 +++--
  1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index e8d6acc888c5..aead07cf8a5b 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -180,6 +180,20 @@ static int mm_fault_error(struct pt_regs *regs, unsigned 
long addr, int fault)
return MM_FAULT_CONTINUE;
  }
  
+/* Is this a bad kernel fault ? */

+static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
+unsigned long address)
+{
+   if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT))) {


Do you mind if we had DSISR_PROTFAULT here as well ?

Christophe


+   printk_ratelimited(KERN_CRIT "kernel tried to execute"
+  " exec-protected page (%lx) -"
+  "exploit attempt? (uid: %d)\n",
+  address, from_kuid(_user_ns,
+ current_uid()));
+   }
+   return is_exec || (address >= TASK_SIZE);
+}
+
  /*
   * Define the correct "is_write" bit in error_code based
   * on the processor family
@@ -252,7 +266,7 @@ static int __do_page_fault(struct pt_regs *regs, unsigned 
long address,
 * The kernel should never take an execute fault nor should it
 * take a page fault to a kernel address.
 */
-   if (!is_user && (is_exec || (address >= TASK_SIZE)))
+   if (unlikely(!is_user && bad_kernel_fault(is_exec, error_code, 
address)))
return SIGSEGV;
  
  	/* We restore the interrupt state now */

@@ -491,11 +505,6 @@ static int __do_page_fault(struct pt_regs *regs, unsigned 
long address,
return 0;
}
  
-	if (is_exec && (error_code & DSISR_PROTFAULT))

-   printk_ratelimited(KERN_CRIT "kernel tried to execute 
NX-protected"
-  " page (%lx) - exploit attempt? (uid: %d)\n",
-  address, from_kuid(_user_ns, 
current_uid()));
-
return SIGSEGV;
  }
  NOKPROBE_SYMBOL(__do_page_fault);



[PATCH] net/wan/fsl_ucc_hdlc: add BQL support

2018-11-07 Thread Mathias Thore
Add byte queue limits support in the fsl_ucc_hdlc driver.

Signed-off-by: Mathias Thore 
---
 drivers/net/wan/fsl_ucc_hdlc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
index 4d6409605207..7a42336c8af8 100644
--- a/drivers/net/wan/fsl_ucc_hdlc.c
+++ b/drivers/net/wan/fsl_ucc_hdlc.c
@@ -391,6 +391,7 @@ static netdev_tx_t ucc_hdlc_tx(struct sk_buff *skb, struct 
net_device *dev)
dev_kfree_skb(skb);
return -ENOMEM;
}
+   netdev_sent_queue(dev, skb->len);
spin_lock_irqsave(>lock, flags);
 
/* Start from the next BD that should be filled */
@@ -447,6 +448,8 @@ static int hdlc_tx_done(struct ucc_hdlc_private *priv)
 {
/* Start from the next BD that should be filled */
struct net_device *dev = priv->ndev;
+   unsigned int bytes_sent = 0;
+   int howmany = 0;
struct qe_bd *bd;   /* BD pointer */
u16 bd_status;
int tx_restart = 0;
@@ -474,6 +477,8 @@ static int hdlc_tx_done(struct ucc_hdlc_private *priv)
skb = priv->tx_skbuff[priv->skb_dirtytx];
if (!skb)
break;
+   howmany++;
+   bytes_sent += skb->len;
dev->stats.tx_packets++;
memset(priv->tx_buffer +
   (be32_to_cpu(bd->buf) - priv->dma_tx_addr),
@@ -501,6 +506,7 @@ static int hdlc_tx_done(struct ucc_hdlc_private *priv)
if (tx_restart)
hdlc_tx_restart(priv);
 
+   netdev_completed_queue(dev, howmany, bytes_sent);
return 0;
 }
 
@@ -721,6 +727,7 @@ static int uhdlc_open(struct net_device *dev)
priv->hdlc_busy = 1;
netif_device_attach(priv->ndev);
napi_enable(>napi);
+   netdev_reset_queue(dev);
netif_start_queue(dev);
hdlc_open(dev);
}
@@ -812,6 +819,7 @@ static int uhdlc_close(struct net_device *dev)
 
free_irq(priv->ut_info->uf_info.irq, priv);
netif_stop_queue(dev);
+   netdev_reset_queue(dev);
priv->hdlc_busy = 0;
 
return 0;
-- 
2.18.1