Re: [RFC PATCH v4 11/12] powerpc: Add a Kconfig and a function to set new soft_enabled mask

2016-09-07 Thread Nicholas Piggin
On Mon, 5 Sep 2016 22:48:00 +0530
Madhavan Srinivasan  wrote:

> On Monday 29 August 2016 07:11 AM, Nicholas Piggin wrote:
> > On Mon, 29 Aug 2016 00:07:27 +0530
> > Madhavan Srinivasan  wrote:
> >  
> >> New Kconfig is added "CONFIG_IRQ_DEBUG_SUPPORT" to add a warn_on
> >> to alert the usage of soft_irq_set_mask() for disabling lower
> >> bitmask interrupts.
> >>
> >> Have also moved the code under the CONFIG_TRACE_IRQFLAGS in
> >> arch_local_irq_restore() to new Kconfig as suggested.
> >>
> >> Patch also adds a new soft_irq_set_mask() to update paca->soft_enabled.
> >>
> >> Signed-off-by: Madhavan Srinivasan 
> >> ---
> >>   arch/powerpc/Kconfig  |  4 
> >>   arch/powerpc/include/asm/hw_irq.h | 17 +
> >>   arch/powerpc/kernel/irq.c |  4 ++--
> >>   3 files changed, 23 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> >> index 927d2ab2ce08..878f05925340 100644
> >> --- a/arch/powerpc/Kconfig
> >> +++ b/arch/powerpc/Kconfig
> >> @@ -51,6 +51,10 @@ config TRACE_IRQFLAGS_SUPPORT
> >>bool
> >>default y
> >>   
> >> +config IRQ_DEBUG_SUPPORT
> >> +  bool
> >> +  default n
> >> +
> >>   config LOCKDEP_SUPPORT
> >>bool
> >>default y
> >> diff --git a/arch/powerpc/include/asm/hw_irq.h 
> >> b/arch/powerpc/include/asm/hw_irq.h
> >> index 415734c07cfa..9f71559ce868 100644
> >> --- a/arch/powerpc/include/asm/hw_irq.h
> >> +++ b/arch/powerpc/include/asm/hw_irq.h
> >> @@ -81,6 +81,23 @@ static inline unsigned long arch_local_irq_disable(void)
> >>return flags;
> >>   }
> >>   
> >> +static inline unsigned long soft_irq_set_mask(int value)
> >> +{
> >> +  unsigned long flags, zero;
> >> +
> >> +#ifdef CONFIG_IRQ_DEBUG_SUPPORT
> >> +  WARN_ON(value <= IRQ_DISABLE_MASK_LINUX);
> >> +#endif
> >> +  asm volatile(
> >> +  "li %1,%3; lbz %0,%2(13); stb %1,%2(13)"
> >> +  : "=r" (flags), "=" (zero)
> >> +  : "i" (offsetof(struct paca_struct, soft_enabled)),\
> >> +   "i" (value)
> >> +  : "memory");
> >> +
> >> +  return flags;
> >> +}  
> > One other thing, if we have:
> >
> > local_irq_save(flags);  // disable LINUX mask -> LINUX
> > local_irq_and_pmu_save(flags);  // disable PMU   mask -> LINUX|PMU
> > local_irq_and_pmu_restore(flags);   // enable  PMU   mask -> LINUX
> > local_irq_restore(flags);   // enable  LINUX mask -> NONE
> >
> > Then the nested code that re-enables PMUs will not replay PMU interrupt
> > until the outer irq is re-enabled. I don't *think* this is a problem,
> > but it probably should be commented.
> >
> > Which brings us to arch_local_irq_restore() (from another patch):
> >
> >
> > @@ -208,7 +209,7 @@ notrace void arch_local_irq_restore(unsigned long en)
> >
> > /* Write the new soft-enabled value */
> > set_soft_enabled(en);
> > -   if (!en)
> > +   if (en == IRQ_DISABLE_MASK_LINUX)
> > return;
> > /*
> >  * From this point onward, we can take interrupts, preempt,
> >
> > I think this is a bit buggy for some cases of nested disables. For the
> > above it is okay, but if we have:
> >
> > local_irq_and_pmu_save(flags);
> > local_irq_and_pmu_save(flags);
> > local_irq_and_pmu_restore(flags);
> > local_irq_and_pmu_restore(flags);
> >
> >
> > The first restore will restore LINUX|PMU mask, which will not be caught
> > by this check.
> >
> > Testing instead for non-zero (any IRQ bits masked) should work. We should
> > probably also add an IRQ_DEBUG_SUPPORT check to ensure LINUX bit is always
> > one of the outer-most bits to be cleared (theoretically we could support  
> 
> Just sent out the newer version of the patchset with most of the 
> comments addressed.

Thanks, I'm just having a look through it.


> But I am not sure about this comment. IIUC, will something like this 
> will do?
> 
> diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
> index a02c6a3bc6fa..af0c08aefbcf 100644
> --- a/arch/powerpc/kernel/irq.c
> +++ b/arch/powerpc/kernel/irq.c
> @@ -209,6 +209,11 @@ notrace void arch_local_irq_restore(unsigned long en)
>  unsigned char irq_happened;
>  unsigned int replay;
> 
> +#ifdef CONFIG_IRQ_DEBUG_SUPPORT
> +   WARN_ONCE (en & (en & local_paca->soft_enabled),
> +  "soft_enabled transition to Unsupported state\n");
> +#endif
> +
>  /* Write the new soft-enabled value */
>  set_soft_enabled(en);

We want to make sure no new bits are set

  WARN_ON(en & ~local_paca->soft_enabled)

My other suggestion was just to ensure the LINUX bit is enabled last:

  WARN_ON(en & local_paca->soft_enabled & ~IRQ_DISABLE_MASK_LINUX)

Thanks,
Nick


Re: [PATCH v2] hwrng: pasemi_rng.c: Migrate to managed API

2016-09-07 Thread Herbert Xu
On Sun, Sep 04, 2016 at 11:43:08PM +0530, PrasannaKumar Muralidharan wrote:
> Use devm_ioremap and devm_hwrng_register instead of ioremap and
> hwrng_register. This removes unregistering and error handling code.
> 
> Changes in v2:
> Remove hardcoded resource size in ioremap, use resource struct obtained
> by calling platform_get_resource.
> 
> Removing hardcoded resource size was suggested by LABBE Corentin.
> 
> CC: Darren Stevens 
> 
> Suggested-by: LABBE Corentin 
> Signed-off-by: PrasannaKumar Muralidharan 

Patch applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: Kexec regression in next-20160906

2016-09-07 Thread Russell King - ARM Linux
On Tue, Sep 06, 2016 at 08:33:20PM -0300, Thiago Jung Bauermann wrote:
> Thanks for reporting the problem and finding the commit that caused it.
> The only thing in commit 5c01cdd2d4bc which can affect kexec_load is the 
> fact that struct kexec_segment has a new member.
> 
> This is probably breaking the ABI on ARM, then. I verified that kexec_load 
> kept working on ppc64le with a kexec binary compiled with the original 
> struct kexec_segment definition, but apparently I got lucky.

That _will_ definitely break the ABI on ARM, and pretty much all
32-bit architectures.  It's a silly thing to do, and I'm really
surprised that it passed through review without being spotted.

The reason you "got lucky" with ppc64le is that there was probably
padding in the structure, and you happened to place your new member
in that padding, so the structure size didn't change.

For 32-bit architectures, there will be no padding - both the pointers
and size_t members will be 32-bit, and will be naturally aligned, and
hence there will be no padding.  Any addition to the structure will
change the size of the structure.

Any change to a UAPI header needs to be carefully considered and
questioned as it is always a potential userspace breakage - and in
the kernel, we're supposed to be doing our up-most to avoid
breaking userspace.

It's not like it was in the old days when we didn't have the UAPI
seperate - today, we can find these things by looking at the patch
diffstat and seeing whether any file in "uapi" is touched.  That
should be the trigger for a really in-depth review of the change.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.


[PATCH 3/3] arch/powerpc : Enable optprobes support in powerpc

2016-09-07 Thread Anju T Sudhakar
Mark optprobe 'ok' for powerpc

Signed-off-by: Anju T Sudhakar 
---
 Documentation/features/debug/optprobes/arch-support.txt | 2 +-
 arch/powerpc/Kconfig| 1 +
 arch/powerpc/kernel/Makefile| 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/features/debug/optprobes/arch-support.txt 
b/Documentation/features/debug/optprobes/arch-support.txt
index b8999d8..45bc99d 100644
--- a/Documentation/features/debug/optprobes/arch-support.txt
+++ b/Documentation/features/debug/optprobes/arch-support.txt
@@ -27,7 +27,7 @@
 |   nios2: | TODO |
 |openrisc: | TODO |
 |  parisc: | TODO |
-| powerpc: | TODO |
+| powerpc: |  ok  |
 |s390: | TODO |
 |   score: | TODO |
 |  sh: | TODO |
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index a5e0b47..136ca35 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -104,6 +104,7 @@ config PPC
select HAVE_IOREMAP_PROT
select HAVE_EFFICIENT_UNALIGNED_ACCESS if !CPU_LITTLE_ENDIAN
select HAVE_KPROBES
+   select HAVE_OPTPROBES
select HAVE_ARCH_KGDB
select HAVE_KRETPROBES
select HAVE_ARCH_TRACEHOOK
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index fe4c075..33667d3 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -98,6 +98,7 @@ endif
 obj-$(CONFIG_BOOTX_TEXT)   += btext.o
 obj-$(CONFIG_SMP)  += smp.o
 obj-$(CONFIG_KPROBES)  += kprobes.o
+obj-$(CONFIG_OPTPROBES)+= optprobes.o optprobes_head.o
 obj-$(CONFIG_UPROBES)  += uprobes.o
 obj-$(CONFIG_PPC_UDBG_16550)   += legacy_serial.o udbg_16550.o
 obj-$(CONFIG_STACKTRACE)   += stacktrace.o
-- 
2.7.4



Re: [PATCH kernel 14/15] vfio/spapr_tce: Export container API for external users

2016-09-07 Thread Alexey Kardashevskiy
On 29/08/16 23:27, David Gibson wrote:
> On Mon, Aug 29, 2016 at 04:35:15PM +1000, Alexey Kardashevskiy wrote:
>> On 18/08/16 10:22, Alexey Kardashevskiy wrote:
>>> On 17/08/16 13:17, David Gibson wrote:
 On Fri, Aug 12, 2016 at 09:22:01AM -0600, Alex Williamson wrote:
> On Fri, 12 Aug 2016 15:46:01 +1000
> David Gibson  wrote:
>
>> On Wed, Aug 10, 2016 at 10:46:30AM -0600, Alex Williamson wrote:
>>> On Wed, 10 Aug 2016 15:37:17 +1000
>>> Alexey Kardashevskiy  wrote:
>>>   
 On 09/08/16 22:16, Alex Williamson wrote:  
> On Tue, 9 Aug 2016 15:19:39 +1000
> Alexey Kardashevskiy  wrote:
> 
>> On 09/08/16 02:43, Alex Williamson wrote:
>>> On Wed,  3 Aug 2016 18:40:55 +1000
>>> Alexey Kardashevskiy  wrote:
>>>   
 This exports helpers which are needed to keep a VFIO container in
 memory while there are external users such as KVM.

 Signed-off-by: Alexey Kardashevskiy 
 ---
  drivers/vfio/vfio.c | 30 
 ++
  drivers/vfio/vfio_iommu_spapr_tce.c | 16 +++-
  include/linux/vfio.h|  6 ++
  3 files changed, 51 insertions(+), 1 deletion(-)

 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
 index d1d70e0..baf6a9c 100644
 --- a/drivers/vfio/vfio.c
 +++ b/drivers/vfio/vfio.c
 @@ -1729,6 +1729,36 @@ long vfio_external_check_extension(struct 
 vfio_group *group, unsigned long arg)
  EXPORT_SYMBOL_GPL(vfio_external_check_extension);
  
  /**
 + * External user API for containers, exported by symbols to be 
 linked
 + * dynamically.
 + *
 + */
 +struct vfio_container *vfio_container_get_ext(struct file *filep)
 +{
 +  struct vfio_container *container = filep->private_data;
 +
 +  if (filep->f_op != _fops)
 +  return ERR_PTR(-EINVAL);
 +
 +  vfio_container_get(container);
 +
 +  return container;
 +}
 +EXPORT_SYMBOL_GPL(vfio_container_get_ext);
 +
 +void vfio_container_put_ext(struct vfio_container *container)
 +{
 +  vfio_container_put(container);
 +}
 +EXPORT_SYMBOL_GPL(vfio_container_put_ext);
 +
 +void *vfio_container_get_iommu_data_ext(struct vfio_container 
 *container)
 +{
 +  return container->iommu_data;
 +}
 +EXPORT_SYMBOL_GPL(vfio_container_get_iommu_data_ext);
 +
 +/**
   * Sub-module support
   */
  /*
 diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c 
 b/drivers/vfio/vfio_iommu_spapr_tce.c
 index 3594ad3..fceea3d 100644
 --- a/drivers/vfio/vfio_iommu_spapr_tce.c
 +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
 @@ -1331,6 +1331,21 @@ const struct vfio_iommu_driver_ops 
 tce_iommu_driver_ops = {
.detach_group   = tce_iommu_detach_group,
  };
  
 +struct iommu_table *vfio_container_spapr_tce_table_get_ext(void 
 *iommu_data,
 +  u64 offset)
 +{
 +  struct tce_container *container = iommu_data;
 +  struct iommu_table *tbl = NULL;
 +
 +  if (tce_iommu_find_table(container, offset, ) < 0)
 +  return NULL;
 +
 +  iommu_table_get(tbl);
 +
 +  return tbl;
 +}
 +EXPORT_SYMBOL_GPL(vfio_container_spapr_tce_table_get_ext);
 +
  static int __init tce_iommu_init(void)
  {
return vfio_register_iommu_driver(_iommu_driver_ops);
 @@ -1348,4 +1363,3 @@ MODULE_VERSION(DRIVER_VERSION);
  MODULE_LICENSE("GPL v2");
  MODULE_AUTHOR(DRIVER_AUTHOR);
  MODULE_DESCRIPTION(DRIVER_DESC);
 -
 diff --git a/include/linux/vfio.h b/include/linux/vfio.h
 index 0ecae0b..1c2138a 100644
 --- a/include/linux/vfio.h
 +++ b/include/linux/vfio.h
 @@ -91,6 +91,12 @@ extern void vfio_group_put_external_user(struct 
 vfio_group *group);
  extern int vfio_external_user_iommu_id(struct vfio_group *group);
  extern long vfio_external_check_extension(struct vfio_group 
 *group,

[PATCH] tty/serial : Add I2C support to Max310x driver (linux-3.8.13)

2016-09-07 Thread MeghanSaitwal

MAX3107/8 chip supports both SPI and I2C protocol. Currently, max310x
driver support only SPI protocol. This patch adds I2C support to the
driver. With I2C support, we have added bulk read/write functionality
which can be enabled using BULK_RW_ENABLE variable.

Signed-off-by: Meghan Saitwal 
meghansait...@eaton.com
Tested-by: Devidas Kalane 
devidaskal...@eaton.com
Suggested-by: Ashwin Patwekar 
ashwinpatwe...@eaton.com
drivers/tty/serial/Kconfig   |   38 +++-
drivers/tty/serial/Makefile  |2
drivers/tty/serial/max310x.c |  268 +++--
3 files changed, 254 insertions(+), 54 deletions(-)

diff -purN a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
--- a/drivers/tty/serial/Kconfig  2016-09-01 12:05:32.092474214 +0530
+++ b/drivers/tty/serial/Kconfig   2016-09-01 12:11:12.938507208 
+0530
@@ -276,19 +276,45 @@ config SERIAL_MAX3100
   help
 MAX3100 chip support

+config SERIAL_MAX310X_CORE
+ tristate
+
config SERIAL_MAX310X
-  bool "MAX310X support"
-  depends on SPI
+ tristate "MAX310X support"
+ depends on (SPI && !I2C) || I2C
   select SERIAL_CORE
-  select REGMAP_SPI if SPI
-  default n
   help
 This selects support for an advanced UART from Maxim (Dallas).
 Supported ICs are MAX3107, MAX3108.
 Each IC contains 128 words each of receive and transmit FIFO
-that can be controlled through I2C or high-speed SPI.
+   that can be controlled through I2C or high-speed SPI.
+   Select SPI or I2C bus using options below.
+
+config SERIAL_MAX310X_SPI
+ bool "MAX310x for spi interface"
+ depends on SERIAL_MAX310X
+ depends on SPI
+ select SERIAL_MAX310X_CORE if SERIAL_MAX310X
+ select REGMAP_SPI if SPI
+ default y
+ help
+Enable MAX310x driver on SPI bus,
+If required say y, and say n to spi if not required,
+Enabled by default to support oldconfig.
+You must select at least one bus for the driver to be built.
+
+config SERIAL_MAX310X_I2C
+ bool "MAX310x for I2C interface"
+ depends on SERIAL_MAX310X
+ depends on I2C
+ select SERIAL_MAX310XX_CORE if SERIAL_MAX310X
+ select REGMAP_I2C if I2C
+ help
+Enable MAX310x driver on I2C bus,
+If required say y, and say n to i2c if not required,
+This is additional support to existing driver.
+You must select at least one bus for the driver to be built.

-Say Y here if you want to support this ICs.

 config SERIAL_DZ
   bool "DECstation DZ serial driver"
diff -purN a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
--- a/drivers/tty/serial/Makefile   2016-09-01 12:07:31.815485804 
+0530
+++ b/drivers/tty/serial/Makefile2016-09-01 12:11:40.576509884 +0530
@@ -28,7 +28,7 @@ obj-$(CONFIG_SERIAL_BFIN) += bfin_uart.o
obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
obj-$(CONFIG_SERIAL_SAMSUNG) += samsung.o
obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
-obj-$(CONFIG_SERIAL_MAX310X) += max310x.o
+obj-$(CONFIG_SERIAL_MAX310X_CORE) += max310x.o
obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o
obj-$(CONFIG_SERIAL_MUX) += mux.o
obj-$(CONFIG_SERIAL_68328) += 68328serial.o
diff -purN a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
--- a/drivers/tty/serial/max310x.c2013-05-12 02:27:46.0 
+0530
+++ b/drivers/tty/serial/max310x.c 2016-08-12 10:22:40.0 +0530
@@ -25,8 +25,11 @@
#include 
#include 
#include 
+#include 
#include 

+#define BULK_RW_ENABLE  0
+
#define MAX310X_MAJOR 204
#define MAX310X_MINOR 209

@@ -272,6 +275,8 @@ struct max310x_port {
   const char   *name;
   int   uartclk;

+ unsigned charbuf[MAX310X_FIFO_SIZE];
+
   unsigned int   nr_gpio;
#ifdef CONFIG_GPIOLIB
   struct gpio_chipgpio;
@@ -459,7 +464,7 @@ static int max310x_set_ref_clk(struct ma

 static void max310x_handle_rx(struct max310x_port *s, unsigned int rxlen)
{
-  unsigned int sts = 0, ch = 0, flag;
+ unsigned int sts = 0, ch = 0, flag, bytes_read, i;
   struct tty_struct *tty = tty_port_tty_get(>port.state->port);

if (!tty)
@@ -473,7 +478,64 @@ static void max310x_handle_rx(struct max

dev_dbg(s->port.dev, "RX Len = %u\n", rxlen);

- 

Re: [PATCH v4 3/5] PCI: Do not disable memory decoding in pci_reassigndev_resource_alignment()

2016-09-07 Thread Yongji Xie

On 2016/9/7 0:56, Bjorn Helgaas wrote:


On Fri, Aug 12, 2016 at 01:42:24PM +0800, Yongji Xie wrote:

We should not disable memory decoding when we reassign alignment
in pci_reassigndev_resource_alignment(). It's meaningless and
have some side effects. For example, we found it would break
this kind of P2P bridge:

0001:02:02.0 PCI bridge: PLX Technology, Inc. PEX 8718 16-Lane,
5-Port PCI Express Gen 3 (8.0 GT/s) Switch (rev aa)

I doubt that turning memory decode off breaks this bridge.  I can
believe that it could cause a problem, but I doubt it would be
specific to this bridge.


I found that disabling memory decoding would not break
this kind of bridge.

However, it would cause some problems if we have a
VGA device using "vgaarb" driver behind the bridge.

The driver didn't call something like pci_enable_device()
when it is loaded or initialized. So when the driver issued
memory access to the VGA device, the access cannot be
supported by the bridge because its memory decoding is
still disabled.

Maybe we should drop this patch and try to fix the driver.

Thanks,
Yongji


I also don't think it's meaningless.  After your patch, we throw away
our knowledge of what the BAR contains when we set "r->start = 0".
But if you leave memory decoding enabled, the device will still
respond at whatever address the BAR contains.  That seems like a
problem.


And it may also potentially break the PCI devices with mmio_always_on
bit set.

Besides, disabling memory decoding is not expected in some fixup
function such as fixup_vga(). The fixup_vga() read PCI_COMMAND_MEMORY
to know whether the devices has been initialized by the firmware or
not. Disabling memory decoding would cause the one initialized by
firmware may not be set as the default VGA device when more than one
graphics adapter is present.

Signed-off-by: Yongji Xie 
---
  drivers/pci/pci.c |8 +---
  1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b8357d7..caa0894 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5046,7 +5046,6 @@ void pci_reassigndev_resource_alignment(struct pci_dev 
*dev)
int i;
struct resource *r;
resource_size_t align, size;
-   u16 command;
  
  	/*

 * VF BARs are RO zero according to SR-IOV spec 3.4.1.11. Their
@@ -5069,12 +5068,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev 
*dev)
return;
}
  
-	dev_info(>dev,

-   "Disabling memory decoding and releasing memory resources.\n");
-   pci_read_config_word(dev, PCI_COMMAND, );
-   command &= ~PCI_COMMAND_MEMORY;
-   pci_write_config_word(dev, PCI_COMMAND, command);
-
+   dev_info(>dev, "Releasing memory resources.\n");
for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) {
r = >resource[i];
if (!(r->flags & IORESOURCE_MEM))
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html





[PATCH 0/3] OPTPROBES for powerpc

2016-09-07 Thread Anju T Sudhakar
This is the patchset of the kprobes jump optimization
(a.k.a OPTPROBES)for powerpc. Kprobe being an inevitable tool
for kernel developers, enhancing the performance of kprobe has
got much importance.

Currently kprobes inserts a trap instruction to probe a running kernel.
Jump optimization allows kprobes to replace the trap with a branch,
reducing the probe overhead drastically.

In this series, conditional branch instructions are not considered for
optimization as they have to be assessed carefully in SMP systems.


Performance:
=
An optimized kprobe in powerpc is 1.05 to 4.7 times faster than a kprobe.

Example:

Placed a probe at an offset 0x50 in _do_fork().
*Time Diff here is, difference in time before hitting the probe and
after the probed instruction. mftb() is employed in kernel/fork.c for
this purpose.

# echo 0 > /proc/sys/debug/kprobes-optimization
Kprobes globally unoptimized
[  233.607120] Time Diff = 0x1f0
[  233.608273] Time Diff = 0x1ee
[  233.609228] Time Diff = 0x203
[  233.610400] Time Diff = 0x1ec
[  233.611335] Time Diff = 0x200
[  233.612552] Time Diff = 0x1f0
[  233.613386] Time Diff = 0x1ee
[  233.614547] Time Diff = 0x212
[  233.615570] Time Diff = 0x206
[  233.616819] Time Diff = 0x1f3
[  233.617773] Time Diff = 0x1ec
[  233.618944] Time Diff = 0x1fb
[  233.619879] Time Diff = 0x1f0
[  233.621066] Time Diff = 0x1f9
[  233.621999] Time Diff = 0x283
[  233.623281] Time Diff = 0x24d
[  233.624172] Time Diff = 0x1ea
[  233.625381] Time Diff = 0x1f0
[  233.626358] Time Diff = 0x200
[  233.627572] Time Diff = 0x1ed

# echo 1 > /proc/sys/debug/kprobes-optimization
Kprobes globally optimized
[   70.797075] Time Diff = 0x103
[   70.799102] Time Diff = 0x181
[   70.801861] Time Diff = 0x15e
[   70.803466] Time Diff = 0xf0
[   70.804348] Time Diff = 0xd0
[   70.805653] Time Diff = 0xad
[   70.806477] Time Diff = 0xe0
[   70.807725] Time Diff = 0xbe
[   70.808541] Time Diff = 0xc3
[   70.810191] Time Diff = 0xc7
[   70.811007] Time Diff = 0xc0
[   70.812629] Time Diff = 0xc0
[   70.813640] Time Diff = 0xda
[   70.814915] Time Diff = 0xbb
[   70.815726] Time Diff = 0xc4
[   70.816955] Time Diff = 0xc0
[   70.817778] Time Diff = 0xcd
[   70.818999] Time Diff = 0xcd
[   70.820099] Time Diff = 0xcb
[   70.821333] Time Diff = 0xf0

Implementation:
===

The trap instruction is replaced by a branch to a detour buffer. To address
the limitation of branch instruction in power architecture detour buffer
slot is allocated from a reserved area . This will ensure that the branch
is within ?? 32 MB range. Patch 2/3 furnishes this. The current kprobes
insn caches allocate memory area for insn slots with module_alloc(). This
will always be beyond ?? 32MB range.

The detour buffer contains a call to optimized_callback() which in turn
call the pre_handler(). Once the pre-handler is run, the original
instruction is emulated from the detour buffer itself. Also the detour
buffer is equipped with a branch back to the normal work flow after the
probed instruction is emulated. Before preparing optimization, Kprobes
inserts original(breakpoint instruction)kprobe on the specified address.
So, even if the kprobe is not possible to be optimized, it just uses a
normal kprobe.

Limitations:
==
- Number of probes which can be optimized is limited by the size of the
  area reserved.
- Currently instructions which can be emulated are the only candidates for
  optimization.
- Conditional branch instructions are not optimized.
- Probes on kernel module region are not considered for optimization now.

RFC patchset for optprobes: https://lkml.org/lkml/2016/5/31/375
https://lkml.org/lkml/2016/5/31/376
https://lkml.org/lkml/2016/5/31/377
https://lkml.org/lkml/2016/5/31/378 

Changes from RFC-v3 :

- Optimization for kporbe(in case of branch instructions) is limited to
  unconditional branch instructions only, since the conditional
  branches are to be assessed carefully in SMP systems.
- create_return_branch() is omitted.
- Comments by Masami are addressed.
 

Anju T Sudhakar (3):
  arch/powerpc : Add detour buffer support for optprobes
  arch/powerpc : optprobes for powerpc core
  arch/powerpc : Enable optprobes support in powerpc

 .../features/debug/optprobes/arch-support.txt  |   2 +-
 arch/powerpc/Kconfig   |   1 +
 arch/powerpc/include/asm/kprobes.h |  24 ++
 arch/powerpc/include/asm/sstep.h   |   1 +
 arch/powerpc/kernel/Makefile   |   1 +
 arch/powerpc/kernel/optprobes.c| 329 +
 arch/powerpc/kernel/optprobes_head.S   | 119 
 arch/powerpc/lib/sstep.c   |  21 ++
 8 files changed, 497 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/kernel/optprobes.c
 create mode 100644 arch/powerpc/kernel/optprobes_head.S

-- 
2.7.4



[PATCH 2/3] arch/powerpc : optprobes for powerpc core

2016-09-07 Thread Anju T Sudhakar
Instructions which can be emulated are suppliants for optimization.
Before optimization ensure that the address range between the detour
buffer allocated and the instruction being probed is within ?? 32MB.

Signed-off-by: Anju T Sudhakar 
---
 arch/powerpc/include/asm/sstep.h |   1 +
 arch/powerpc/kernel/optprobes.c  | 329 +++
 arch/powerpc/lib/sstep.c |  21 +++
 3 files changed, 351 insertions(+)
 create mode 100644 arch/powerpc/kernel/optprobes.c

diff --git a/arch/powerpc/include/asm/sstep.h b/arch/powerpc/include/asm/sstep.h
index d3a42cc..cd5f6ab 100644
--- a/arch/powerpc/include/asm/sstep.h
+++ b/arch/powerpc/include/asm/sstep.h
@@ -25,6 +25,7 @@ struct pt_regs;
 
 /* Emulate instructions that cause a transfer of control. */
 extern int emulate_step(struct pt_regs *regs, unsigned int instr);
+extern int optprobe_conditional_branch_check(unsigned int instr);
 
 enum instruction_type {
COMPUTE,/* arith/logical/CR op, etc. */
diff --git a/arch/powerpc/kernel/optprobes.c b/arch/powerpc/kernel/optprobes.c
new file mode 100644
index 000..7983d07
--- /dev/null
+++ b/arch/powerpc/kernel/optprobes.c
@@ -0,0 +1,329 @@
+/*
+ * Code for Kernel probes Jump optimization.
+ *
+ * Copyright 2016, Anju T, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DEFINE_INSN_CACHE_OPS(ppc_optinsn)
+
+#define TMPL_CALL_HDLR_IDX \
+   (optprobe_template_call_handler - optprobe_template_entry)
+#define TMPL_EMULATE_IDX   \
+   (optprobe_template_call_emulate - optprobe_template_entry)
+#define TMPL_RET_IDX   \
+   (optprobe_template_ret - optprobe_template_entry)
+#define TMPL_KP_IDX\
+   (optprobe_template_kp_addr - optprobe_template_entry)
+#define TMPL_OP1_IDX   \
+   (optprobe_template_op_address1 - optprobe_template_entry)
+#define TMPL_INSN_IDX  \
+   (optprobe_template_insn - optprobe_template_entry)
+#define TMPL_END_IDX   \
+   (optprobe_template_end - optprobe_template_entry)
+
+static bool insn_page_in_use;
+
+static void *__ppc_alloc_insn_page(void)
+{
+   if (insn_page_in_use)
+   return NULL;
+   insn_page_in_use = true;
+   return _slot;
+}
+
+static void __ppc_free_insn_page(void *page __maybe_unused)
+{
+   insn_page_in_use = false;
+}
+
+struct kprobe_insn_cache kprobe_ppc_optinsn_slots = {
+   .mutex = __MUTEX_INITIALIZER(kprobe_ppc_optinsn_slots.mutex),
+   .pages = LIST_HEAD_INIT(kprobe_ppc_optinsn_slots.pages),
+   /* insn_size initialized later */
+   .alloc = __ppc_alloc_insn_page,
+   .free = __ppc_free_insn_page,
+   .nr_garbage = 0,
+};
+
+kprobe_opcode_t *ppc_get_optinsn_slot(struct optimized_kprobe *op)
+{
+   /*
+* The insn slot is allocated from the reserved
+* area(ie _slot).We are not optimizing probes
+* at module_addr now.
+*/
+   if (is_kernel_addr((unsigned long)op->kp.addr))
+   return get_ppc_optinsn_slot();
+   return NULL;
+}
+
+static void ppc_free_optinsn_slot(struct optimized_kprobe *op)
+{
+   if (!op->optinsn.insn)
+   return;
+   if (is_kernel_addr((unsigned long)op->kp.addr))
+   free_ppc_optinsn_slot(op->optinsn.insn, 0);
+}
+
+static unsigned long can_optimize(struct kprobe *p)
+{
+   struct pt_regs *regs;
+   unsigned int instr;
+
+   /*
+* Not optimizing the kprobe placed by
+* kretprobe during boot time
+*/
+   if (p->addr == (kprobe_opcode_t *)_trampoline)
+   return 0;
+
+   regs = kmalloc(sizeof(*regs), GFP_KERNEL);
+   if (!regs)
+   return -ENOMEM;
+   memset(regs, 0, sizeof(struct pt_regs));
+   memcpy(regs, current_pt_regs(), sizeof(struct pt_regs));
+   regs->nip = (unsigned long)p->addr;
+   instr = *p->ainsn.insn;
+
+   /* Ensure the instruction can be emulated */
+   if (emulate_step(regs, instr) != 1)
+   return 0;
+   /* Conditional branches are not optimized */
+   if (optprobe_conditional_branch_check(instr) != 1)
+   return 0;
+   return regs->nip;
+}
+
+static void
+optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
+{
+   struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
+   unsigned long flags;
+
+   local_irq_save(flags);
+
+   if (kprobe_running()) {
+   kprobes_inc_nmissed_count(>kp);
+   } else {
+   __this_cpu_write(current_kprobe, >kp);
+   kcb->kprobe_status = KPROBE_HIT_ACTIVE;
+   opt_pre_handler(>kp, regs);
+   

Re: [PATCH v4 0/5] kexec_file: Add buffer hand-over for the next kernel

2016-09-07 Thread Eric W. Biederman
Thiago Jung Bauermann  writes:

> Hello,
>
> The purpose of this new version of the series is to fix a small issue that
> I found, which is that the kernel doesn't remove the memory reservation
> for the hand-over buffer it received from the previous kernel in the
> device tree it sets up for the next kernel. The result is that for each
> successive kexec, a stale hand-over buffer is left behind, wasting memory.
>
> This is fixed by changes to kexec_free_handover_buffer and
> setup_handover_buffer in patch 2. The other change is to fix checkpatch
> warnings in the last patch.

This is fundamentally broken.  You do not increase the integrity of a
system by dropping integrity checks.

No. No. No. No.

Nacked-by: "Eric W. Biederman" 

Eric


Re: [PATCH v4 0/5] kexec_file: Add buffer hand-over for the next kernel

2016-09-07 Thread Eric W. Biederman
ebied...@xmission.com (Eric W. Biederman) writes:

> Thiago Jung Bauermann  writes:
>
>> Hello,
>>
>> The purpose of this new version of the series is to fix a small issue that
>> I found, which is that the kernel doesn't remove the memory reservation
>> for the hand-over buffer it received from the previous kernel in the
>> device tree it sets up for the next kernel. The result is that for each
>> successive kexec, a stale hand-over buffer is left behind, wasting memory.
>>
>> This is fixed by changes to kexec_free_handover_buffer and
>> setup_handover_buffer in patch 2. The other change is to fix checkpatch
>> warnings in the last patch.
>
> This is fundamentally broken.  You do not increase the integrity of a
> system by dropping integrity checks.
>
> No. No. No. No.
>
> Nacked-by: "Eric W. Biederman" 

To be constructive the way we have handled similiar situations in the
past (hotplu memory) is to call kexec_load again.

Eric


Re: [PATCH v6 0/7] perf: Cross arch annotate + few miscellaneous fixes

2016-09-07 Thread Ravi Bangoria
Hello,

Any update on this?

-Ravi

On Friday 19 August 2016 06:29 PM, Ravi Bangoria wrote:
> Currently Perf annotate support code navigation (branches and calls)
> only when run on the same architecture where perf.data was recorded.
> But, for example, record on powerpc server and annotate on client's
> x86 desktop is not supported.
>
> This patchset enables cross arch annotate. Currently I've used x86
> and arm instructions which are already available and added support
> for powerpc.
>
> Additionally this patch series also contains few other related fixes.
>
> Patches are prepared on top of acme/perf/core and tested it with x86
> and powerpc only.
>
> Note for arm:
> I don't have arm test machine. As suggested by Russell in one of the
> review comment, I've copied all instructions from default table to
> arm table. This way it want break tool on arm but cleanup is needed
> for x86 specific instructions added in arm table.
>
> Example:
>
>   Record on powerpc:
>   $ ./perf record -a
>
>   Report -> Annotate on x86:
>   $ ./perf report -i perf.data.powerpc --vmlinux vmlinux.powerpc
>
> Changes in v6:
>   - Instead of adding only those instructions defined in #ifdef __arm__,
> add all instructions from default table to arm table.
>
> v5 link:
>   https://lkml.org/lkml/2016/8/19/35
>
> Naveen N. Rao (1):
>   perf annotate: Add support for powerpc
>
> Ravi Bangoria (6):
>   perf: Define macro for normalized arch names
>   perf annotate: Add cross arch annotate support
>   perf annotate: Do not ignore call instruction with indirect target
>   perf annotate: Show raw form for jump instruction with indirect target
>   perf annotate: Support jump instruction with target as second operand
>   perf annotate: Fix jump target outside of function address range
>
>  tools/perf/arch/common.c   |  36 ++--
>  tools/perf/arch/common.h   |  11 ++
>  tools/perf/builtin-top.c   |   2 +-
>  tools/perf/ui/browsers/annotate.c  |   8 +-
>  tools/perf/ui/gtk/annotate.c   |   2 +-
>  tools/perf/util/annotate.c | 330 
> +++--
>  tools/perf/util/annotate.h |  10 +-
>  tools/perf/util/unwind-libunwind.c |   4 +-
>  8 files changed, 327 insertions(+), 76 deletions(-)
>



[PATCH 1/3] arch/powerpc : Add detour buffer support for optprobes

2016-09-07 Thread Anju T Sudhakar
Detour buffer contains instructions to create an in memory pt_regs.
After the execution of prehandler a call is made for instruction emulation.
The NIP is decided after the probed instruction is executed. Hence a branch
instruction is created to the NIP returned by emulate_step().

Instruction slot for detour buffer is allocated from the reserved area.
For the time being 64KB is reserved in memory for this purpose.

Signed-off-by: Anju T Sudhakar 
---
 arch/powerpc/include/asm/kprobes.h   |  24 +++
 arch/powerpc/kernel/optprobes_head.S | 119 +++
 2 files changed, 143 insertions(+)
 create mode 100644 arch/powerpc/kernel/optprobes_head.S

diff --git a/arch/powerpc/include/asm/kprobes.h 
b/arch/powerpc/include/asm/kprobes.h
index 2c9759bd..2109ce03 100644
--- a/arch/powerpc/include/asm/kprobes.h
+++ b/arch/powerpc/include/asm/kprobes.h
@@ -38,7 +38,25 @@ struct pt_regs;
 struct kprobe;
 
 typedef ppc_opcode_t kprobe_opcode_t;
+
+extern kprobe_opcode_t optinsn_slot;
+/* Optinsn template address */
+extern kprobe_opcode_t optprobe_template_entry[];
+extern kprobe_opcode_t optprobe_template_call_handler[];
+extern kprobe_opcode_t optprobe_template_call_emulate[];
+extern kprobe_opcode_t optprobe_template_ret[];
+extern kprobe_opcode_t optprobe_template_insn[];
+extern kprobe_opcode_t optprobe_template_kp_addr[];
+extern kprobe_opcode_t optprobe_template_op_address1[];
+extern kprobe_opcode_t optprobe_template_end[];
+
 #define MAX_INSN_SIZE 1
+#define MAX_OPTIMIZED_LENGTH   4
+#define MAX_OPTINSN_SIZE   \
+   (((unsigned long)_template_end -   \
+   (unsigned long)_template_entry) /  \
+   sizeof(kprobe_opcode_t))
+#define RELATIVEJUMP_SIZE  4
 
 #ifdef PPC64_ELF_ABI_v2
 /* PPC64 ABIv2 needs local entry point */
@@ -124,6 +142,12 @@ struct kprobe_ctlblk {
struct prev_kprobe prev_kprobe;
 };
 
+struct arch_optimized_insn {
+   kprobe_opcode_t copied_insn[1];
+   /* detour buffer */
+   kprobe_opcode_t *insn;
+};
+
 extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
 extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
diff --git a/arch/powerpc/kernel/optprobes_head.S 
b/arch/powerpc/kernel/optprobes_head.S
new file mode 100644
index 000..73db1df
--- /dev/null
+++ b/arch/powerpc/kernel/optprobes_head.S
@@ -0,0 +1,119 @@
+/*
+ * Code to prepare detour buffer for optprobes in Kernel.
+ *
+ * Copyright 2016, Anju T, IBM Corp.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+
+#defineOPT_SLOT_SIZE   65536
+
+.balign2
+.global optinsn_slot
+optinsn_slot:
+   /* Reserve an area to allocate slots for detour buffer */
+   .space  OPT_SLOT_SIZE
+
+/* Create an in-memory pt_regs */
+.global optprobe_template_entry
+optprobe_template_entry:
+   stdur1,-INT_FRAME_SIZE(r1)
+   SAVE_GPR(0,r1)
+   /* Save the previous SP into stack */
+   addir0,r1,INT_FRAME_SIZE
+   std r0,GPR1(r1)
+   SAVE_10GPRS(2,r1)
+   SAVE_10GPRS(12,r1)
+   SAVE_10GPRS(22,r1)
+   /* Save SPRS */
+   mfmsr   r5
+   std r5,_MSR(r1)
+   li  r5,0
+   std r5,ORIG_GPR3(r1)
+   std r5,_TRAP(r1)
+   std r5,RESULT(r1)
+   mfctr   r5
+   std r5,_CTR(r1)
+   mflrr5
+   std r5,_LINK(r1)
+   mfspr   r5,SPRN_XER
+   std r5,_XER(r1)
+   mfcrr5
+   std r5,_CCR(r1)
+   lbz r5,PACASOFTIRQEN(r13)
+   std r5,SOFTE(r1)
+   mfdar   r5
+   std r5,_DAR(r1)
+   mfdsisr r5
+   std r5,_DSISR(r1)
+
+/* Save p->addr into stack */
+.global optprobe_template_kp_addr
+optprobe_template_kp_addr:
+   nop
+   nop
+   nop
+   nop
+   nop
+   std r3,_NIP(r1)
+
+/* Pass parameters for optimized_callback */
+.global optprobe_template_op_address1
+optprobe_template_op_address1:
+   nop
+   nop
+   nop
+   nop
+   nop
+   addir4,r1,STACK_FRAME_OVERHEAD
+
+/* Branch to optimized_callback() */
+.global optprobe_template_call_handler
+optprobe_template_call_handler:
+   nop
+   /* Pass parameters for instruction emulation */
+   addir3,r1,STACK_FRAME_OVERHEAD
+.global optprobe_template_insn
+optprobe_template_insn:
+   nop
+   nop
+
+/* Branch to instruction emulation  */
+.global optprobe_template_call_emulate
+optprobe_template_call_emulate:
+   nop
+   /* Restore the registers */
+   ld  r5,_MSR(r1)
+   mtmsr   r5
+   ld  r5,_CTR(r1)
+   mtctr   r5
+   ld  r5,_LINK(r1)
+   mtlrr5

Re: [PATCH 1/6] cxlflash: Scan host only after the port is ready for I/O

2016-09-07 Thread Matthew R. Ochs
> On Sep 2, 2016, at 3:38 PM, Uma Krishnan  wrote:
> 
> When a port link is established, the AFU sends a 'link up' interrupt.
> After the link is up, corresponding initialization steps are performed
> on the card. Following that, when the card is ready for I/O, the AFU
> sends 'login succeeded' interrupt. Today, cxlflash invokes
> scsi_scan_host() upon receipt of both interrupts.
> 
> SCSI commands sent to the port prior to the 'login succeeded' interrupt
> will fail with 'port not available' error. This is not desirable.
> Moreover, when async_scan is active for the host, subsequent scan calls
> are terminated with error. Due to this, the scsi_scan_host() call
> performed after 'login succeeded' interrupt could portentially return
> error and the devices may not be scanned properly.
> 
> To avoid this problem, scsi_scan_host() should be called only after the
> 'login succeeded' interrupt.
> 
> Signed-off-by: Uma Krishna 

Acked-by: Matthew R. Ochs 



[PATCH] ASoC: constify snd_pcm_ops structures

2016-09-07 Thread Julia Lawall
Check for snd_pcm_ops structures that are only stored in the ops field of a
snd_soc_platform_driver structure or passed as the third argument to
snd_pcm_set_ops.  The corresponding field or parameter is declared const,
so snd_pcm_ops structures that have this property can be declared as const
also.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// 
@r disable optional_qualifier@
identifier i;
position p;
@@
static struct snd_pcm_ops i@p = { ... };

@ok1@
identifier r.i;
struct snd_soc_platform_driver e;
position p;
@@
e.ops = @p;

@ok2@
identifier r.i;
expression e1, e2;
position p;
@@
snd_pcm_set_ops(e1, e2, @p)

@bad@
position p != {r.p,ok1.p,ok2.p};
identifier r.i;
struct snd_pcm_ops e;
@@
e@i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
 struct snd_pcm_ops i = { ... };
// 

Signed-off-by: Julia Lawall 

---
 sound/soc/amd/acp-pcm-dma.c  |2 +-
 sound/soc/atmel/atmel-pcm-pdc.c  |2 +-
 sound/soc/codecs/rt5514-spi.c|2 +-
 sound/soc/fsl/fsl_asrc_dma.c |2 +-
 sound/soc/intel/atom/sst-mfld-platform-pcm.c |2 +-
 sound/soc/intel/haswell/sst-haswell-pcm.c|2 +-
 sound/soc/intel/skylake/skl-pcm.c|2 +-
 sound/soc/kirkwood/kirkwood-dma.c|2 +-
 sound/soc/qcom/lpass-platform.c  |2 +-
 sound/soc/soc-utils.c|2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/sound/soc/intel/haswell/sst-haswell-pcm.c 
b/sound/soc/intel/haswell/sst-haswell-pcm.c
index 3154525..9e4094e 100644
--- a/sound/soc/intel/haswell/sst-haswell-pcm.c
+++ b/sound/soc/intel/haswell/sst-haswell-pcm.c
@@ -871,7 +871,7 @@ out:
return ret;
 }
 
-static struct snd_pcm_ops hsw_pcm_ops = {
+static const struct snd_pcm_ops hsw_pcm_ops = {
.open   = hsw_pcm_open,
.close  = hsw_pcm_close,
.ioctl  = snd_pcm_lib_ioctl,
diff --git a/sound/soc/atmel/atmel-pcm-pdc.c b/sound/soc/atmel/atmel-pcm-pdc.c
index da861b4..91b7069 100644
--- a/sound/soc/atmel/atmel-pcm-pdc.c
+++ b/sound/soc/atmel/atmel-pcm-pdc.c
@@ -381,7 +381,7 @@ static int atmel_pcm_close(struct snd_pcm_substream 
*substream)
return 0;
 }
 
-static struct snd_pcm_ops atmel_pcm_ops = {
+static const struct snd_pcm_ops atmel_pcm_ops = {
.open   = atmel_pcm_open,
.close  = atmel_pcm_close,
.ioctl  = snd_pcm_lib_ioctl,
diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index a144c14..e2ff538 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -372,7 +372,7 @@ static int lpass_platform_pcmops_mmap(struct 
snd_pcm_substream *substream,
runtime->dma_bytes);
 }
 
-static struct snd_pcm_ops lpass_platform_pcm_ops = {
+static const struct snd_pcm_ops lpass_platform_pcm_ops = {
.open   = lpass_platform_pcmops_open,
.ioctl  = snd_pcm_lib_ioctl,
.hw_params  = lpass_platform_pcmops_hw_params,
diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c
index 77ff8eb..09103aa 100644
--- a/sound/soc/codecs/rt5514-spi.c
+++ b/sound/soc/codecs/rt5514-spi.c
@@ -236,7 +236,7 @@ static snd_pcm_uframes_t rt5514_spi_pcm_pointer(
return bytes_to_frames(runtime, rt5514_dsp->dma_offset);
 }
 
-static struct snd_pcm_ops rt5514_spi_pcm_ops = {
+static const struct snd_pcm_ops rt5514_spi_pcm_ops = {
.open   = rt5514_spi_pcm_open,
.hw_params  = rt5514_spi_hw_params,
.hw_free= rt5514_spi_hw_free,
diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c
index d1fb035..504c7cd 100644
--- a/sound/soc/amd/acp-pcm-dma.c
+++ b/sound/soc/amd/acp-pcm-dma.c
@@ -897,7 +897,7 @@ static int acp_dma_close(struct snd_pcm_substream 
*substream)
return 0;
 }
 
-static struct snd_pcm_ops acp_dma_ops = {
+static const struct snd_pcm_ops acp_dma_ops = {
.open = acp_dma_open,
.close = acp_dma_close,
.ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c 
b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
index 52ed434..25c6d87 100644
--- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
@@ -670,7 +670,7 @@ static snd_pcm_uframes_t sst_platform_pcm_pointer
return str_info->buffer_ptr;
 }
 
-static struct snd_pcm_ops sst_platform_ops = {
+static const struct snd_pcm_ops sst_platform_ops = {
.open = sst_platform_open,
.ioctl = snd_pcm_lib_ioctl,
.trigger = sst_platform_pcm_trigger,
diff --git a/sound/soc/intel/skylake/skl-pcm.c 
b/sound/soc/intel/skylake/skl-pcm.c
index 77bfd40..86c125f 100644
--- a/sound/soc/intel/skylake/skl-pcm.c
+++ b/sound/soc/intel/skylake/skl-pcm.c
@@ -1093,7 +1093,7 @@ static int 

Re: [PATCH] soc: fsl/qe: fix gpio save_regs functions

2016-09-07 Thread Linus Walleij
On Tue, Sep 6, 2016 at 12:52 AM, Christophe Leroy
 wrote:

> of_mm_gpiochip_add_data() calls mm_gc->save_regs() before
> setting the data. Therefore ->save_regs() cannot use
> gpiochip_get_data()
>
> An Oops is encountered without this fix.
>
> fixes: 1e714e54b5ca5 ("powerpc: qe_lib-gpio: use gpiochip data pointer")
> Signed-off-by: Christophe Leroy 
> Cc: 

Aha sorry for my regular screwups. :(
Reviewed-by: Linus Walleij 

Yours,
Linus Walleij


Re: [PATCH 2/6] cxlflash: Remove the device cleanly in the system shutdown path

2016-09-07 Thread Matthew R. Ochs
> On Sep 2, 2016, at 3:39 PM, Uma Krishnan  wrote:
> 
> Commit 704c4b0ddc03 ("cxlflash: Shutdown notify support for CXL Flash
> cards") was recently introduced to notify the AFU when a system is going
> down. Due to the position of the cxlflash driver in the device stack,
> cxlflash devices are _always_ removed during a reboot/shutdown. This can
> lead to a crash if the cxlflash shutdown hook is invoked _after_ the
> shutdown hook for the owning virtual PHB. Furthermore, the current
> implementation of shutdown/remove hooks for cxlflash are not tolerant to
> being invoked when the device is not enabled. This can also lead to a
> crash in situations where the remove hook is invoked after the device has
> been removed via the vPHBs shutdown hook. An example of this scenario
> would be an EEH reset failure while a reboot/shutdown is in progress.
> 
> To solve both problems, the shutdown hook for cxlflash is updated to
> simply remove the device. This path already includes the AFU notification
> and thus this solution will continue to perform the original intent. At
> the same time, the remove hook is updated to protect against being
> called when the device is not enabled.
> 
> Fixes: 704c4b0ddc03 ("cxlflash: Shutdown notify support for CXL Flash
> cards")
> Signed-off-by: Uma Krishna 

Acked-by: Matthew R. Ochs 



Re: [PATCH] powernv: Restore SPRs correctly upon wake up from hypervisor state loss

2016-09-07 Thread Shreyas B. Prabhu
Hi Gautham,

Thanks for fixing this.

On Wed, Sep 7, 2016 at 1:16 AM, Gautham R. Shenoy
 wrote:
> From: "Gautham R. Shenoy" 
>
> pnv_wakeup_tb_loss function currently expects the cr4 to be "eq" if
> the CPU is waking up from a complete hypervisor state loss. Hence, it
> currently restores the SPR contents only if cr4 is "eq".
>
> However, after the commit bcef83a00dc4 ("powerpc/powernv: Add platform
> support for stop instruction"), on ISA_V300 CPUs, the function
> pnv_restore_hyp_resource sets cr4 to contain the result of the
> comparison between state the CPU has woken up and the first deepest
> stop state before calling pnv_wakeup_tb_loss.
>
> Thus if the CPU woke up from a state that is deeper than the first
> deepest stop state, cr4 have "gt" set and hence, pnv_wakeup_tb_loss
> will fail to restore the SPRs on waking up from such a state.
>
> Fix the code in pnv_wakeup_tb_loss to restore the SPR states when cr4 is
> "eq" or "gt".
>
> Fixes: Commit bcef83a00dc4 ("powerpc/powernv: Add platform support for
> stop instruction")
>
> Cc: Vaidyanathan Srinivasan 
> Cc: Michael Neuling 
> Cc: Michael Ellerman 
> Cc: Shreyas B. Prabhu 
> Signed-off-by: Gautham R. Shenoy 
> ---

Reviewed-by: Shreyas B. Prabhu 


Thanks,
Shreyas


Re: [PATCH] ALSA: squash lines for simple wrapper functions

2016-09-07 Thread Takashi Iwai
On Tue, 06 Sep 2016 13:41:19 +0200,
Masahiro Yamada wrote:
> 
> Remove unneeded variables and assignments.
> 
> Signed-off-by: Masahiro Yamada 

Applied, thanks.


Takashi

> ---
> 
>  sound/aoa/fabrics/layout.c  |  7 +--
>  sound/pci/asihpi/hpifunc.c  |  7 ++-
>  sound/pci/ctxfi/ctvmem.c|  6 +-
>  sound/pci/emu10k1/p16v.c| 16 
>  sound/pci/ice1712/ice1724.c |  4 +---
>  sound/ppc/snd_ps3.c |  4 +---
>  sound/soc/intel/baytrail/sst-baytrail-ipc.c | 12 +++-
>  7 files changed, 13 insertions(+), 43 deletions(-)
> 
> diff --git a/sound/aoa/fabrics/layout.c b/sound/aoa/fabrics/layout.c
> index 8f71f7e..b6ba091 100644
> --- a/sound/aoa/fabrics/layout.c
> +++ b/sound/aoa/fabrics/layout.c
> @@ -1161,12 +1161,7 @@ static struct soundbus_driver aoa_soundbus_driver = {
>  
>  static int __init aoa_fabric_layout_init(void)
>  {
> - int err;
> -
> - err = soundbus_register_driver(_soundbus_driver);
> - if (err)
> - return err;
> - return 0;
> + return soundbus_register_driver(_soundbus_driver);
>  }
>  
>  static void __exit aoa_fabric_layout_exit(void)
> diff --git a/sound/pci/asihpi/hpifunc.c b/sound/pci/asihpi/hpifunc.c
> index 510e56c..f9b5764 100644
> --- a/sound/pci/asihpi/hpifunc.c
> +++ b/sound/pci/asihpi/hpifunc.c
> @@ -2323,11 +2323,8 @@ u16 hpi_sample_clock_get_source_index(u32 h_control, 
> u16 *pw_source_index)
>  u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
>   u32 *prate)
>  {
> - u16 err;
> - err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
> - index, 0, prate);
> -
> - return err;
> + return hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
> +  index, 0, prate);
>  }
>  
>  u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
> diff --git a/sound/pci/ctxfi/ctvmem.c b/sound/pci/ctxfi/ctvmem.c
> index 419306e..520e19b 100644
> --- a/sound/pci/ctxfi/ctvmem.c
> +++ b/sound/pci/ctxfi/ctvmem.c
> @@ -166,11 +166,7 @@ static void ct_vm_unmap(struct ct_vm *vm, struct 
> ct_vm_block *block)
>  static dma_addr_t
>  ct_get_ptp_phys(struct ct_vm *vm, int index)
>  {
> - dma_addr_t addr;
> -
> - addr = (index >= CT_PTP_NUM) ? ~0UL : vm->ptp[index].addr;
> -
> - return addr;
> + return (index >= CT_PTP_NUM) ? ~0UL : vm->ptp[index].addr;
>  }
>  
>  int ct_vm_create(struct ct_vm **rvm, struct pci_dev *pci)
> diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
> index 3c60b43..87f6622 100644
> --- a/sound/pci/emu10k1/p16v.c
> +++ b/sound/pci/emu10k1/p16v.c
> @@ -300,37 +300,29 @@ static int snd_p16v_pcm_open_capture(struct 
> snd_pcm_substream *substream)
>  static int snd_p16v_pcm_hw_params_playback(struct snd_pcm_substream 
> *substream,
> struct snd_pcm_hw_params *hw_params)
>  {
> - int result;
> - result = snd_pcm_lib_malloc_pages(substream,
> + return snd_pcm_lib_malloc_pages(substream,
>   params_buffer_bytes(hw_params));
> - return result;
>  }
>  
>  /* hw_params callback */
>  static int snd_p16v_pcm_hw_params_capture(struct snd_pcm_substream 
> *substream,
> struct snd_pcm_hw_params *hw_params)
>  {
> - int result;
> - result = snd_pcm_lib_malloc_pages(substream,
> + return snd_pcm_lib_malloc_pages(substream,
>   params_buffer_bytes(hw_params));
> - return result;
>  }
>  
>  
>  /* hw_free callback */
>  static int snd_p16v_pcm_hw_free_playback(struct snd_pcm_substream *substream)
>  {
> - int result;
> - result = snd_pcm_lib_free_pages(substream);
> - return result;
> + return snd_pcm_lib_free_pages(substream);
>  }
>  
>  /* hw_free callback */
>  static int snd_p16v_pcm_hw_free_capture(struct snd_pcm_substream *substream)
>  {
> - int result;
> - result = snd_pcm_lib_free_pages(substream);
> - return result;
> + return snd_pcm_lib_free_pages(substream);
>  }
>  
>  
> diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
> index 0b22c00..4731e9c 100644
> --- a/sound/pci/ice1712/ice1724.c
> +++ b/sound/pci/ice1712/ice1724.c
> @@ -620,9 +620,7 @@ static const unsigned int stdclock_rate_list[16] = {
>  
>  static unsigned int stdclock_get_rate(struct snd_ice1712 *ice)
>  {
> - unsigned int rate;
> - rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
> - return rate;
> + return stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
>  }
>  
>  static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate)
> diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
> index 3682425..b84d7d3 100644
> --- a/sound/ppc/snd_ps3.c
> +++ b/sound/ppc/snd_ps3.c
> @@ -564,9 +564,7 @@ static int 

[PATCH v2 3/3] powerpc/mm: Speed up computation of base and actual page size for a HPTE

2016-09-07 Thread Paul Mackerras
This replaces a 2-D search through an array with a simple 8-bit table
lookup for determining the actual and/or base page size for a HPT entry.

The encoding in the second doubleword of the HPTE is designed to encode
the actual and base page sizes without using any more bits than would be
needed for a 4k page number, by using between 1 and 8 low-order bits of
the RPN (real page number) field to encode the page sizes.  A single
"large page" bit in the first doubleword indicates that these low-order
bits are to be interpreted like this.

We can determine the page sizes by using the low-order 8 bits of the RPN
to look up a 256-entry table.  For actual page sizes less than 1MB, some
of the upper bits of these 8 bits are going to be real address bits, but
we can cope with that by replicating the entries for those smaller page
sizes.

While we're at it, let's move the hpte_page_size() and hpte_base_page_size()
functions from a KVM-specific header to a header for 64-bit HPT systems,
since this computation doesn't have anything specifically to do with KVM.

Signed-off-by: Paul Mackerras 
---
v2: added more comments as suggested by Aneesh

 arch/powerpc/include/asm/book3s/64/mmu-hash.h | 37 
 arch/powerpc/include/asm/kvm_book3s_64.h  | 87 +++
 arch/powerpc/include/asm/mmu.h|  1 +
 arch/powerpc/mm/hash_native_64.c  | 42 +
 arch/powerpc/mm/hash_utils_64.c   | 55 +
 5 files changed, 102 insertions(+), 120 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h 
b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
index 287a656..e407af2 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
@@ -245,6 +245,43 @@ static inline int segment_shift(int ssize)
 }
 
 /*
+ * This array is indexed by the LP field of the HPTE second dword.
+ * Since this field may contain some RPN bits, some entries are
+ * replicated so that we get the same value irrespective of RPN.
+ * The top 4 bits are the page size index (MMU_PAGE_*) for the
+ * actual page size, the bottom 4 bits are the base page size.
+ */
+extern u8 hpte_page_sizes[1 << LP_BITS];
+
+static inline unsigned long __hpte_page_size(unsigned long h, unsigned long l,
+bool is_base_size)
+{
+   unsigned int i, lp;
+
+   if (!(h & HPTE_V_LARGE))
+   return 1ul << 12;
+
+   /* Look at the 8 bit LP value */
+   lp = (l >> LP_SHIFT) & ((1 << LP_BITS) - 1);
+   i = hpte_page_sizes[lp];
+   if (!i)
+   return 0;
+   if (!is_base_size)
+   i >>= 4;
+   return 1ul << mmu_psize_defs[i & 0xf].shift;
+}
+
+static inline unsigned long hpte_page_size(unsigned long h, unsigned long l)
+{
+   return __hpte_page_size(h, l, 0);
+}
+
+static inline unsigned long hpte_base_page_size(unsigned long h, unsigned long 
l)
+{
+   return __hpte_page_size(h, l, 1);
+}
+
+/*
  * The current system page and segment sizes
  */
 extern int mmu_kernel_ssize;
diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h 
b/arch/powerpc/include/asm/kvm_book3s_64.h
index 88d17b4..4ffd5a1 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -20,6 +20,8 @@
 #ifndef __ASM_KVM_BOOK3S_64_H__
 #define __ASM_KVM_BOOK3S_64_H__
 
+#include 
+
 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
 static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get(struct kvm_vcpu 
*vcpu)
 {
@@ -97,56 +99,20 @@ static inline void __unlock_hpte(__be64 *hpte, unsigned 
long hpte_v)
hpte[0] = cpu_to_be64(hpte_v);
 }
 
-static inline int __hpte_actual_psize(unsigned int lp, int psize)
-{
-   int i, shift;
-   unsigned int mask;
-
-   /* start from 1 ignoring MMU_PAGE_4K */
-   for (i = 1; i < MMU_PAGE_COUNT; i++) {
-
-   /* invalid penc */
-   if (mmu_psize_defs[psize].penc[i] == -1)
-   continue;
-   /*
-* encoding bits per actual page size
-*PTE LP actual page size
-* rrrz >=8KB
-* rrzz >=16KB
-* rzzz >=32KB
-*  >=64KB
-* ...
-*/
-   shift = mmu_psize_defs[i].shift - LP_SHIFT;
-   if (shift > LP_BITS)
-   shift = LP_BITS;
-   mask = (1 << shift) - 1;
-   if ((lp & mask) == mmu_psize_defs[psize].penc[i])
-   return i;
-   }
-   return -1;
-}
-
 static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
 unsigned long pte_index)
 {
-   int b_psize = MMU_PAGE_4K, a_psize = MMU_PAGE_4K;
+   int i, b_psize = MMU_PAGE_4K, a_psize = MMU_PAGE_4K;