Re: [PATCH] powerpc/powernv/cpuidle: Pass correct drv->cpumask for registration

2017-03-18 Thread Benjamin Herrenschmidt
On Fri, 2017-03-17 at 23:35 +0530, Vaidyanathan Srinivasan wrote:
> +   /*
> +    * On PowerNV platform cpu_present may be less that cpu_possible
> +    * in cases where firmware detects the cpu, but it is not available
> +    * for OS.  Such CPUs are not hotplugable at runtime on PowerNV
> +    * platform and hence sysfs files are not created for those.
> +    * Generic topology_init() would skip creating sysfs directories
> +    * for cpus that are not present and not hotplugable later at
> +    * runtime.
> +    *
> + 

I wouldn't assume that they can't later be hotplugged. We need that fix
now as it's hitting machines today but we'll need to improve all that
code and the topology code to deal with hotplugging gracefully.

Cheers,
Ben.



Re: [PATCH kernel] KVM: PPC: Add MMIO emulation for stdx (store doubleword indexed)

2017-03-18 Thread Benjamin Herrenschmidt
On Fri, 2017-03-17 at 23:11 +1100, Alexey Kardashevskiy wrote:
> On 17/03/17 19:31, Alexey Kardashevskiy wrote:
> > This adds missing stdx emulation which allow Mellanox driver from
> > recent kernels work when MMIO emulation is enforced in the
> > userspace.
> 
> 
> btw what would its load counterpart? Load Doubleword Indexed - ldx
> RT,RA,RB?

Yes.

Do we also do the more "classic" ld/std ?

Cheers,
Ben.

> 
> > 
> > Signed-off-by: Alexey Kardashevskiy 
> > ---
> >  arch/powerpc/include/asm/ppc-opcode.h | 1 +
> >  arch/powerpc/kvm/emulate_loadstore.c  | 6 ++
> >  2 files changed, 7 insertions(+)
> > 
> > diff --git a/arch/powerpc/include/asm/ppc-opcode.h
> > b/arch/powerpc/include/asm/ppc-opcode.h
> > index e7d6d86563ee..ca1bbe49590b 100644
> > --- a/arch/powerpc/include/asm/ppc-opcode.h
> > +++ b/arch/powerpc/include/asm/ppc-opcode.h
> > @@ -92,6 +92,7 @@
> >  #define OP_31_XOP_TRAP_64   68
> >  #define OP_31_XOP_DCBF  86
> >  #define OP_31_XOP_LBZX  87
> > +#define OP_31_XOP_STDX  149
> >  #define OP_31_XOP_STWX  151
> >  #define OP_31_XOP_STBX  215
> >  #define OP_31_XOP_LBZUX 119
> > diff --git a/arch/powerpc/kvm/emulate_loadstore.c
> > b/arch/powerpc/kvm/emulate_loadstore.c
> > index 6d3c0ee1d744..9fdbeb8ea86c 100644
> > --- a/arch/powerpc/kvm/emulate_loadstore.c
> > +++ b/arch/powerpc/kvm/emulate_loadstore.c
> > @@ -82,6 +82,12 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu
> > *vcpu)
> >     kvmppc_set_gpr(vcpu, ra, vcpu-
> > >arch.vaddr_accessed);
> >     break;
> >  
> > +   case OP_31_XOP_STDX:
> > +   emulated = kvmppc_handle_store(run, vcpu,
> > +      kvmppc_get_
> > gpr(vcpu, rs),
> > +   8, 1);
> > +   break;
> > +
> >     case OP_31_XOP_STWX:
> >     emulated = kvmppc_handle_store(run, vcpu,
> >        kvmppc_get_
> > gpr(vcpu, rs),
> > 
> 
> 



[PATCH] cpuidle: Validate cpu_dev in cpuidle_add_sysfs

2017-03-18 Thread Vaidyanathan Srinivasan
If a given cpu is not in cpu_present and cpu hotplug
is disabled, arch can skip setting up the cpu_dev.

Arch cpuidle driver should pass correct cpu mask
for registration, but failing to do so by the driver
causes error to propagate and crash like this:

[   30.076045] Unable to handle kernel paging request for data at address 
0x0048
[   30.076100] Faulting instruction address: 0xc07b2f30
cpu 0x4d: Vector: 300 (Data Access) at [c03feb18b670]
pc: c07b2f30: kobject_get+0x20/0x70
lr: c07b3c94: kobject_add_internal+0x54/0x3f0
sp: c03feb18b8f0
   msr: 90009033
   dar: 48
 dsisr: 4000
  current = 0xc03fd2ed8300
  paca= 0xcfbab500   softe: 0irq_happened: 0x01
pid   = 1, comm = swapper/0
Linux version 4.11.0-rc2-svaidy+ (sv@sagarika) (gcc version 6.2.0
20161005 (Ubuntu 6.2.0-5ubuntu12) ) #10 SMP Sun Mar 19 00:08:09 IST 2017
enter ? for help
[c03feb18b960] c07b3c94 kobject_add_internal+0x54/0x3f0
[c03feb18b9f0] c07b43a4 kobject_init_and_add+0x64/0xa0
[c03feb18ba70] c0e284f4 cpuidle_add_sysfs+0xb4/0x130
[c03feb18baf0] c0e26038 cpuidle_register_device+0x118/0x1c0
[c03feb18bb30] c0e26c48 cpuidle_register+0x78/0x120
[c03feb18bbc0] c168fd9c powernv_processor_idle_init+0x110/0x1c4
[c03feb18bc40] c000cff8 do_one_initcall+0x68/0x1d0
[c03feb18bd00] c16242f4 kernel_init_freeable+0x280/0x360
[c03feb18bdc0] c000d864 kernel_init+0x24/0x160
[c03feb18be30] c000b4e8 ret_from_kernel_thread+0x5c/0x74

Validating cpu_dev fixes the crash and reports correct error message like:

[   30.163506] Failed to register cpuidle device for cpu136
[   30.173329] Registration of powernv driver failed.

Signed-off-by: Vaidyanathan Srinivasan 
---
 drivers/cpuidle/sysfs.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index c5adc8c..19dcf32 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -615,6 +615,18 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev)
struct device *cpu_dev = get_cpu_device((unsigned long)dev->cpu);
int error;
 
+   /*
+* Return if cpu_device is not setup for this cpu.
+* This could happen if arch did not setup cpu_device
+* since this cpu is not in cpu_present mask and
+* driver did not send correct cpu mask at registration.
+* Without this check we would end up passing bogus
+* value for _dev->kobj in kobject_init_and_add()
+*/
+
+   if (!cpu_dev)
+   return -ENODEV;
+
kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
if (!kdev)
return -ENOMEM;
-- 
2.9.3



Re: [PATCH] powerpc/pasemi, cbe: Do not process decremeter or external wakeup from powersave

2017-03-18 Thread Nicholas Piggin
On Fri, 17 Mar 2017 15:43:22 +0100
Christian Zigotzky  wrote:

> Nicholas Piggin  writes:
> 
>  > Hi,
>  >
>  > I would like to start using a dedicated stack for system reset interrupt
>  > and treat it as a Linux nmi, which makes it tricky to call complex
>  > interrupt handlers directly from the system reset trap handler.
>  >
>  > So I would like to remove the decrementer and external handler calls from
>  > Cell and Pasemi platforms' system reset handler. I think we can just
>  > remove them if they can be handled when they re-fire as normal   
> interrupts?
>  > At the moment I don't have environments set up to test if this works.  
> 
> 
> It works fine with my AmigaOne X1000. (Nemo board with a P.A. Semi  
> PA6T-1682M CPU)

Thanks for testing, that's very useful. I will add your tested-by line
for the pasemi part of the patch.

Thanks,
Nick


Re: [PATCH] powerpc/powernv/cpuidle: Pass correct drv->cpumask for registration

2017-03-18 Thread Vaidyanathan Srinivasan
* Michael Neuling  [2017-03-18 16:28:02]:

> Vaidy,
> 
> Thanks for fixing this.
> 
> > drv->cpumask defaults to cpu_possible_mask in __cpuidle_driver_init().
> > This breaks cpuidle on powernv where sysfs files are not created for
> > cpus in cpu_possible_mask that cannot be hot-added.
> 
> I think I prefer the longer description below than this.

[PATCH] powerpc/powernv/cpuidle: Pass correct drv->cpumask for

drv->cpumask defaults to cpu_possible_mask in __cpuidle_driver_init().
This breaks cpuidle on powernv where sysfs files are not created for
cpus in cpu_possible_mask that cannot be hot-added.

On powernv platform cpu_present could be less than cpu_possible
in cases where firmware detects the cpu, but it is not available
for OS.  Such cpus are not hotplugable at runtime on powernv and
hence we skip creating sysfs files for these cpus.

Trying cpuidle_register_device() on cpu without sysfs node will
cause crash like:

cpu 0xf: Vector: 380 (Data SLB Access) at [c00ff1503490]
pc: c022c8bc: string+0x34/0x60
lr: c022ed78: vsnprintf+0x284/0x42c
sp: c00ff1503710
   msr: 90009033
   dar: 60006000
  current = 0xc00ff148
  paca= 0xcfe82d00   softe: 0irq_happened: 0x01
pid   = 1, comm = swapper/8
Linux version 4.11.0-rc2 (sv@sagarika) (gcc version 4.9.4 (Buildroot 
2017.02-4-gc28573e) ) #15 SMP Fri Mar 17 19:32:02 IST 2017
enter ? for help
[link register   ] c022ed78 vsnprintf+0x284/0x42c
[c00ff1503710] c022ebb8 vsnprintf+0xc4/0x42c (unreliable)
[c00ff1503800] c022ef40 vscnprintf+0x20/0x44
[c00ff1503830] c00ab61c vprintk_emit+0x94/0x2cc
[c00ff15038a0] c00acc9c vprintk_func+0x60/0x74
[c00ff15038c0] c0619694 printk+0x38/0x4c
[c00ff15038e0] c0224950 kobject_get+0x40/0x60
[c00ff1503950] c022507c kobject_add_internal+0x60/0x2c4
[c00ff15039e0] c0225350 kobject_init_and_add+0x70/0x78
[c00ff1503a60] c053c288 cpuidle_add_sysfs+0x9c/0xe0
[c00ff1503ae0] c053aeac cpuidle_register_device+0xd4/0x12c
[c00ff1503b30] c053b108 cpuidle_register+0x98/0xcc
[c00ff1503bc0] c085eaf0 powernv_processor_idle_init+0x140/0x1e0
[c00ff1503c60] c000cd60 do_one_initcall+0xc0/0x15c
[c00ff1503d20] c0833e84 kernel_init_freeable+0x1a0/0x25c
[c00ff1503dc0] c000d478 kernel_init+0x24/0x12c
[c00ff1503e30] c000b564 ret_from_kernel_thread+0x5c/0x78

This patch fixes the issue by passing correct cpumask from
powernv-cpuidle driver.
 
> > This patch fixes the issue by passing correct cpumask from
> > powernv-cpuidle driver.
> 
> Any reason the correct fix isn't to change __cpuidle_driver_init() to use
> present mask?  Seems like any arch where present < possible is going to hit
> this.

How to handle the sysfs nodes for cpus that are not in cpu_present
mask is upto the arch/platform.  During init, arch can choose to
create sysfs nodes for cpu's that are not in present mask, which can
be later hot-added and then onlined.  In which case cpuidle driver
should register for such cpus as well.

The decision to allow a cpu to become available in cpu_present mask at
runtime and handle the sysfs nodes are upto the arch/platform and not
to be hard coded in generic driver.  The generic cpuidle would like to
register for all possible cpus if the arch driver does not override
it.

--Vaidy