Re: [PATCH v1 1/1] misc: IBM Virtual Management Channel Driver

2018-04-25 Thread Linus Walleij
I don't know why I'm included in review of this driver, but why
not :) it is good to include people.

Thanks for your patch! It looks exciting and complicated,
I like that kind of stuff.

On Mon, Apr 23, 2018 at 4:46 PM, Bryant G. Ly
 wrote:

> This driver is a logical device which provides an
> interface between the hypervisor and a management
> partition.

Please indicate what this management partition is to
be used for, i.e. the intended use case.

> This driver is to be used for the POWER Virtual
> Management Channel Virtual Adapter on the PowerVM
> platform.

Is that virtualization on the PowerPC platform?

> It provides both request/response and
> async message support through the /dev/ibmvmc node.

Is that a character or block device?
I guess block, but it's nice to have some specifics
in the commit message.

> diff --git a/Documentation/misc-devices/ibmvmc.txt 
> b/Documentation/misc-devices/ibmvmc.txt

The document suffers a bit from internal lingo, so it's be great
if you improve it a bit with a style that will be welcoming for newcomers
who have no idea what you are talking about.

I will point out some items below.

> +Description
> +===
> +
> +The Virtual Management Channel (VMC) is a logical device which provides an
> +interface between the hypervisor and a management partition.

What kind of interface? A bitstream? Message passing interface?
Marshalling of structs? Some specifics would be great.

> This
> +management partition is intended to provide an alternative to HMC-based
> +system management.

Please expand the acronym HMC for the newcomer so we do not need
to look it up, or it looks like the document is only for people who already
know everything about virtualization specifics.

> In the management partition, a Novalink application
> +exists

Is Novalink some kind of product name? In that case, can it be
instead described with some neutral technology name and state
Novalink as an examplf of this type of technology?

> which enables a system administrator to configure the system’s
> +partitioning characteristics

Exemplify "partitioning characteristics", with a sentence in this
vein: "partitioning characteristics such as FOO, BAR and BAZ".

> via a command line interface (CLI) or
> +Representational State Transfer Application (REST).

I understand what CLI is but what is a representational state
transfer application? Is that a fancy name for a GUI application
doing the same thing as a CLI program would do?

> You can also manage the
> +server by using PowerVC

There was PowerVM now there is PowerVC. What are those things
really? PowerVM I guess is virtual machine on PowerPC? What is
PowerVC? Virtual client (guest) in the PowerVM?

This kind of lingo makes the document a hard read for me.

> or other OpenStack solution.

I heard about OpenStack. I have a vague idea about what it is,
do you mean "other virtualization concepts"?

> Support for
> +conventional HMC management of the system may still be provided on a
> +system; however, when an HMC is attached to the system, the VMC
> +interface is disabled by the hypervisor.

The VMC acronym is expanded below, instead expand it at first
instance. The same for HMC (hypervisor management channel I guess?
it is never really explained.)

> +NovaLink runs on a Linux logical partition on a POWER8 or newer processor-
> +based server that is virtualized by PowerVM.

So this information needs to be in the top of the document.

> System configuration,
> +maintenance, and control functions which traditionally require an HMC can
> +be implemented in the Novalink using a combination of HMC to hypervisor
> +interfaces and existing operating system methods. This tool provides

What tool? It is unclear what tool we are referring to here.
A command line tool? A technology? etc.

> a
> +subset of the functions implemented by the HMC and enables basic partition
> +configuration. The set of HMC to hypervisor messages

This makes me think that probably the "h" in HMC stands for "hypervisor"
so now I start to puzzle things together. But it's nicer if you just expand
the acronym the first time you use it.

> supported by the
> +Novalink component

I still haven't figured out what that is, in practice.

> are passed to the hypervisor over a VMC interface, which
> +is defined below.

Maybe some illustration of how HMC, Novalink and VMC work
together would be appropriate?

> +Virtual Management Channel (VMC)
> +A logical device, called the virtual management channel (VMC), is defined
> +for communicating between the Novalink application and the hypervisor.


So is "Novalink" some specific application, as in a proprietary
piece of software or something?

I'm still confused.

> +This device, similar to a VSCSI server device,

What is that acronym now, I get completely confused.

> is presented to a designated
> +management partition as a virtual device and is only presented when the
> +system is not HMC managed.
> +This communication device borrows aspects fro

[PATCH V2] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Shilpasri G Bhat
gpstate_timer_handler() uses synchronous smp_call to set the pstate
on the requested core. This causes the below hard lockup:

[c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
(unreliable)
[c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
[c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
[c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
[c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
[c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
[c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
[c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
[c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
[c03fe566b760] [c0009014] decrementer_common+0x114/0x120
-- interrupt: 901 at doorbell_global_ipi+0x34/0x50
LR = arch_send_call_function_ipi_mask+0x120/0x130
[c03fe566ba50] [c004876c]
arch_send_call_function_ipi_mask+0x4c/0x130
[c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
[c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
[c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
[c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
[c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
[c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
[c03fe566be30] [c000b184] system_call+0x58/0x6c

One way to avoid this is removing the smp-call. We can ensure that the timer
always runs on one of the policy-cpus. If the timer gets migrated to a
cpu outside the policy then re-queue it back on the policy->cpus. This way
we can get rid of the smp-call which was being used to set the pstate
on the policy->cpus.

Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer as 
pinned)
Cc: [4.8+]
Reported-by: Nicholas Piggin 
Reported-by: Pridhiviraj Paidipeddi 
Signed-off-by: Shilpasri G Bhat 
---
Changes from V1:
- Remove smp_call in the pstate handler.

 drivers/cpufreq/powernv-cpufreq.c | 23 ---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c 
b/drivers/cpufreq/powernv-cpufreq.c
index 71f8682..dc8ffb5 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -679,6 +679,25 @@ void gpstate_timer_handler(struct timer_list *t)
 
if (!spin_trylock(&gpstates->gpstate_lock))
return;
+   /*
+* If the timer has migrated to the different cpu then bring
+* it back to one of the policy->cpus
+*/
+   if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
+   /*
+* Timer should be deleted if policy is inactive.
+* If policy is active then re-queue on one of the
+* policy->cpus.
+*/
+   if (!cpumask_empty(policy->cpus)) {
+   gpstates->timer.expires = jiffies +
+   msecs_to_jiffies(1);
+   add_timer_on(&gpstates->timer,
+   cpumask_first(policy->cpus));
+   }
+   spin_unlock(&gpstates->gpstate_lock);
+   return;
+   }
 
/*
 * If PMCR was last updated was using fast_swtich then
@@ -718,10 +737,8 @@ void gpstate_timer_handler(struct timer_list *t)
if (gpstate_idx != gpstates->last_lpstate_idx)
queue_gpstate_timer(gpstates);
 
+   set_pstate(&freq_data);
spin_unlock(&gpstates->gpstate_lock);
-
-   /* Timer may get migrated to a different cpu on cpu hot unplug */
-   smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
 }
 
 /*
-- 
1.8.3.1



Re: [PATCH V2] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Viresh Kumar
On 25-04-18, 14:32, Shilpasri G Bhat wrote:
> gpstate_timer_handler() uses synchronous smp_call to set the pstate
> on the requested core. This causes the below hard lockup:
> 
> [c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
> (unreliable)
> [c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
> [c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
> [c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
> [c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
> [c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
> [c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
> [c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
> [c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
> [c03fe566b760] [c0009014] decrementer_common+0x114/0x120
> -- interrupt: 901 at doorbell_global_ipi+0x34/0x50
> LR = arch_send_call_function_ipi_mask+0x120/0x130
> [c03fe566ba50] [c004876c]
> arch_send_call_function_ipi_mask+0x4c/0x130
> [c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
> [c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
> [c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
> [c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
> [c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
> [c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
> [c03fe566be30] [c000b184] system_call+0x58/0x6c
> 
> One way to avoid this is removing the smp-call. We can ensure that the timer
> always runs on one of the policy-cpus. If the timer gets migrated to a
> cpu outside the policy then re-queue it back on the policy->cpus. This way
> we can get rid of the smp-call which was being used to set the pstate
> on the policy->cpus.
> 
> Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer as 
> pinned)
> Cc: [4.8+]
> Reported-by: Nicholas Piggin 
> Reported-by: Pridhiviraj Paidipeddi 
> Signed-off-by: Shilpasri G Bhat 
> ---
> Changes from V1:
> - Remove smp_call in the pstate handler.
> 
>  drivers/cpufreq/powernv-cpufreq.c | 23 ---
>  1 file changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/powernv-cpufreq.c 
> b/drivers/cpufreq/powernv-cpufreq.c
> index 71f8682..dc8ffb5 100644
> --- a/drivers/cpufreq/powernv-cpufreq.c
> +++ b/drivers/cpufreq/powernv-cpufreq.c
> @@ -679,6 +679,25 @@ void gpstate_timer_handler(struct timer_list *t)
>  
>   if (!spin_trylock(&gpstates->gpstate_lock))
>   return;
> + /*
> +  * If the timer has migrated to the different cpu then bring
> +  * it back to one of the policy->cpus
> +  */
> + if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
> + /*
> +  * Timer should be deleted if policy is inactive.
> +  * If policy is active then re-queue on one of the
> +  * policy->cpus.
> +  */

This looks racy. Shouldn't you guarantee that the timer is already
removed in a synchronous way before de-activating the policy ?

> + if (!cpumask_empty(policy->cpus)) {
> + gpstates->timer.expires = jiffies +
> + msecs_to_jiffies(1);
> + add_timer_on(&gpstates->timer,
> + cpumask_first(policy->cpus));
> + }
> + spin_unlock(&gpstates->gpstate_lock);
> + return;
> + }
>  
>   /*
>* If PMCR was last updated was using fast_swtich then
> @@ -718,10 +737,8 @@ void gpstate_timer_handler(struct timer_list *t)
>   if (gpstate_idx != gpstates->last_lpstate_idx)
>   queue_gpstate_timer(gpstates);
>  
> + set_pstate(&freq_data);
>   spin_unlock(&gpstates->gpstate_lock);
> -
> - /* Timer may get migrated to a different cpu on cpu hot unplug */
> - smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
>  }
>  
>  /*
> -- 
> 1.8.3.1

-- 
viresh


Re: [PATCH 2/3] powerpc/powernv: Fix OPAL RTC driver OPAL_BUSY loops

2018-04-25 Thread Alexandre Belloni
On 25/04/2018 13:28:27+1000, Michael Ellerman wrote:
> Alexandre Belloni  writes:
> > On 10/04/2018 23:01:36+1000, Nicholas Piggin wrote:
> >> On Tue, 10 Apr 2018 14:07:28 +0200
> >> Alexandre Belloni  wrote:
> >> > > Fixes   ("powerpc/powernv: Add RTC and NVRAM support plus RTAS 
> >> > > fallbacks"
> >> > > Cc: Benjamin Herrenschmidt 
> >> > > Cc: linux-...@vger.kernel.org
> >> > > Signed-off-by: Nicholas Piggin 
> >> > > ---
> >> > >  arch/powerpc/platforms/powernv/opal-rtc.c |  8 +++--
> >> > >  drivers/rtc/rtc-opal.c| 37 
> >> > > ++-  
> >> > 
> >> > From what I understand, the changes in those files are fairly
> >> > independent, they should probably be separated to ease merging.
> >> 
> >> I'm happy to do that. It's using the same firmware call, so I thought
> >> a single patch would be fine. But I guess the boot call can be
> >> dropped from this patch because it does not  not solve the problem
> >> described in the changelog.
> >> 
> >> Would you be happy for the driver change to be merged via the powerpc
> >> tree? The code being fixed here came from the same original patch as
> >> a similar issue being fixed in the OPAL NVRAM driver so it might be
> >> easier that way.
> >
> > Ok then, just add my
> >
> > Acked-by: Alexandre Belloni 
> >
> > and let it go through the powerpc tree.
> 
> Thanks.
> 
> It's still mostly an rtc patch by lines changed, so I changed the
> subject to:
> 
>   rtc: opal: Fix OPAL RTC driver OPAL_BUSY loops
> 

Great, thanks!


-- 
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com


Re: [PATCH V2] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Shilpasri G Bhat
Hi,

On 04/25/2018 02:47 PM, Viresh Kumar wrote:
> On 25-04-18, 14:32, Shilpasri G Bhat wrote:
>> gpstate_timer_handler() uses synchronous smp_call to set the pstate
>> on the requested core. This causes the below hard lockup:
>>
>> [c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
>> (unreliable)
>> [c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
>> [c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
>> [c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
>> [c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
>> [c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
>> [c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
>> [c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
>> [c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
>> [c03fe566b760] [c0009014] decrementer_common+0x114/0x120
>> -- interrupt: 901 at doorbell_global_ipi+0x34/0x50
>> LR = arch_send_call_function_ipi_mask+0x120/0x130
>> [c03fe566ba50] [c004876c]
>> arch_send_call_function_ipi_mask+0x4c/0x130
>> [c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
>> [c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
>> [c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
>> [c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
>> [c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
>> [c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
>> [c03fe566be30] [c000b184] system_call+0x58/0x6c
>>
>> One way to avoid this is removing the smp-call. We can ensure that the timer
>> always runs on one of the policy-cpus. If the timer gets migrated to a
>> cpu outside the policy then re-queue it back on the policy->cpus. This way
>> we can get rid of the smp-call which was being used to set the pstate
>> on the policy->cpus.
>>
>> Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer 
>> as pinned)
>> Cc: [4.8+]
>> Reported-by: Nicholas Piggin 
>> Reported-by: Pridhiviraj Paidipeddi 
>> Signed-off-by: Shilpasri G Bhat 
>> ---
>> Changes from V1:
>> - Remove smp_call in the pstate handler.
>>
>>  drivers/cpufreq/powernv-cpufreq.c | 23 ---
>>  1 file changed, 20 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/cpufreq/powernv-cpufreq.c 
>> b/drivers/cpufreq/powernv-cpufreq.c
>> index 71f8682..dc8ffb5 100644
>> --- a/drivers/cpufreq/powernv-cpufreq.c
>> +++ b/drivers/cpufreq/powernv-cpufreq.c
>> @@ -679,6 +679,25 @@ void gpstate_timer_handler(struct timer_list *t)
>>  
>>  if (!spin_trylock(&gpstates->gpstate_lock))
>>  return;
>> +/*
>> + * If the timer has migrated to the different cpu then bring
>> + * it back to one of the policy->cpus
>> + */
>> +if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
>> +/*
>> + * Timer should be deleted if policy is inactive.
>> + * If policy is active then re-queue on one of the
>> + * policy->cpus.
>> + */
> 
> This looks racy. Shouldn't you guarantee that the timer is already
> removed in a synchronous way before de-activating the policy ?
> 

The timer is deleted in driver->stop_cpu(). So we ensure to remove the timer
before de-activating the policy.


>> +if (!cpumask_empty(policy->cpus)) {

So are you suggesting to remove ^^ the check for active policy here?
(I put that as a safety check.)

Thanks and Regards,
Shilpa

>> +gpstates->timer.expires = jiffies +
>> +msecs_to_jiffies(1);
>> +add_timer_on(&gpstates->timer,
>> +cpumask_first(policy->cpus));
>> +}
>> +spin_unlock(&gpstates->gpstate_lock);
>> +return;
>> +}
>>  
>>  /*
>>   * If PMCR was last updated was using fast_swtich then
>> @@ -718,10 +737,8 @@ void gpstate_timer_handler(struct timer_list *t)
>>  if (gpstate_idx != gpstates->last_lpstate_idx)
>>  queue_gpstate_timer(gpstates);
>>  
>> +set_pstate(&freq_data);
>>  spin_unlock(&gpstates->gpstate_lock);
>> -
>> -/* Timer may get migrated to a different cpu on cpu hot unplug */
>> -smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
>>  }
>>  
>>  /*
>> -- 
>> 1.8.3.1
> 



Re: [PATCH V2] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Viresh Kumar
On 25-04-18, 15:32, Shilpasri G Bhat wrote:
> Hi,
> 
> On 04/25/2018 02:47 PM, Viresh Kumar wrote:
> > On 25-04-18, 14:32, Shilpasri G Bhat wrote:
> >> gpstate_timer_handler() uses synchronous smp_call to set the pstate
> >> on the requested core. This causes the below hard lockup:
> >>
> >> [c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
> >> (unreliable)
> >> [c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
> >> [c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
> >> [c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
> >> [c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
> >> [c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
> >> [c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
> >> [c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
> >> [c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
> >> [c03fe566b760] [c0009014] decrementer_common+0x114/0x120
> >> -- interrupt: 901 at doorbell_global_ipi+0x34/0x50
> >> LR = arch_send_call_function_ipi_mask+0x120/0x130
> >> [c03fe566ba50] [c004876c]
> >> arch_send_call_function_ipi_mask+0x4c/0x130
> >> [c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
> >> [c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
> >> [c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
> >> [c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
> >> [c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
> >> [c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
> >> [c03fe566be30] [c000b184] system_call+0x58/0x6c
> >>
> >> One way to avoid this is removing the smp-call. We can ensure that the 
> >> timer
> >> always runs on one of the policy-cpus. If the timer gets migrated to a
> >> cpu outside the policy then re-queue it back on the policy->cpus. This way
> >> we can get rid of the smp-call which was being used to set the pstate
> >> on the policy->cpus.
> >>
> >> Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer 
> >> as pinned)
> >> Cc: [4.8+]
> >> Reported-by: Nicholas Piggin 
> >> Reported-by: Pridhiviraj Paidipeddi 
> >> Signed-off-by: Shilpasri G Bhat 
> >> ---
> >> Changes from V1:
> >> - Remove smp_call in the pstate handler.
> >>
> >>  drivers/cpufreq/powernv-cpufreq.c | 23 ---
> >>  1 file changed, 20 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/drivers/cpufreq/powernv-cpufreq.c 
> >> b/drivers/cpufreq/powernv-cpufreq.c
> >> index 71f8682..dc8ffb5 100644
> >> --- a/drivers/cpufreq/powernv-cpufreq.c
> >> +++ b/drivers/cpufreq/powernv-cpufreq.c
> >> @@ -679,6 +679,25 @@ void gpstate_timer_handler(struct timer_list *t)
> >>  
> >>if (!spin_trylock(&gpstates->gpstate_lock))
> >>return;
> >> +  /*
> >> +   * If the timer has migrated to the different cpu then bring
> >> +   * it back to one of the policy->cpus
> >> +   */
> >> +  if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
> >> +  /*
> >> +   * Timer should be deleted if policy is inactive.
> >> +   * If policy is active then re-queue on one of the
> >> +   * policy->cpus.
> >> +   */
> > 
> > This looks racy. Shouldn't you guarantee that the timer is already
> > removed in a synchronous way before de-activating the policy ?
> > 
> 
> The timer is deleted in driver->stop_cpu(). So we ensure to remove the timer
> before de-activating the policy.
> 
> 
> >> +  if (!cpumask_empty(policy->cpus)) {
> 
> So are you suggesting to remove ^^ the check for active policy here?
> (I put that as a safety check.)

Either you are sure or you are not, and you don't need a safety check
if you are sure :)

-- 
viresh


[PATCH V3] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Shilpasri G Bhat
gpstate_timer_handler() uses synchronous smp_call to set the pstate
on the requested core. This causes the below hard lockup:

[c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
(unreliable)
[c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
[c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
[c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
[c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
[c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
[c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
[c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
[c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
[c03fe566b760] [c0009014] decrementer_common+0x114/0x120
-- interrupt: 901 at doorbell_global_ipi+0x34/0x50
LR = arch_send_call_function_ipi_mask+0x120/0x130
[c03fe566ba50] [c004876c]
arch_send_call_function_ipi_mask+0x4c/0x130
[c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
[c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
[c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
[c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
[c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
[c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
[c03fe566be30] [c000b184] system_call+0x58/0x6c

One way to avoid this is removing the smp-call. We can ensure that the timer
always runs on one of the policy-cpus. If the timer gets migrated to a
cpu outside the policy then re-queue it back on the policy->cpus. This way
we can get rid of the smp-call which was being used to set the pstate
on the policy->cpus.

Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer as 
pinned)
Cc: [4.8+]
Reported-by: Nicholas Piggin 
Reported-by: Pridhiviraj Paidipeddi 
Signed-off-by: Shilpasri G Bhat 
---
Changes from V2:
- Remove the check for active policy while requeing the migrated timer
Changes from V1:
- Remove smp_call in the pstate handler.

 drivers/cpufreq/powernv-cpufreq.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c 
b/drivers/cpufreq/powernv-cpufreq.c
index 71f8682..e368e1f 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -679,6 +679,16 @@ void gpstate_timer_handler(struct timer_list *t)
 
if (!spin_trylock(&gpstates->gpstate_lock))
return;
+   /*
+* If the timer has migrated to the different cpu then bring
+* it back to one of the policy->cpus
+*/
+   if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
+   gpstates->timer.expires = jiffies + msecs_to_jiffies(1);
+   add_timer_on(&gpstates->timer, cpumask_first(policy->cpus));
+   spin_unlock(&gpstates->gpstate_lock);
+   return;
+   }
 
/*
 * If PMCR was last updated was using fast_swtich then
@@ -718,10 +728,8 @@ void gpstate_timer_handler(struct timer_list *t)
if (gpstate_idx != gpstates->last_lpstate_idx)
queue_gpstate_timer(gpstates);
 
+   set_pstate(&freq_data);
spin_unlock(&gpstates->gpstate_lock);
-
-   /* Timer may get migrated to a different cpu on cpu hot unplug */
-   smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
 }
 
 /*
-- 
1.8.3.1



[PATCH v3 1/2] cxl: Set the PBCQ Tunnel BAR register when enabling capi mode

2018-04-25 Thread Philippe Bergheaud
Skiboot used to set the default Tunnel BAR register value when capi mode
was enabled. This approach was ok for the cxl driver, but prevented other
drivers from choosing different values.

Skiboot versions > 5.11 will not set the default value any longer. This
patch modifies the cxl driver to set/reset the Tunnel BAR register when
entering/exiting the cxl mode, with pnv_pci_set_tunnel_bar().

Signed-off-by: Philippe Bergheaud 
Reviewed-by: Christophe Lombard 
---
v2: Restrict tunnel bar setting to power9.
Do not fail cxl_configure_adapter() on tunnel bar setting error.
Log an info message instead, and continue configuring capi mode.

v3: No change.
---
 drivers/misc/cxl/pci.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 83f1d08058fc..355c789406f7 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -1742,6 +1742,10 @@ static int cxl_configure_adapter(struct cxl *adapter, 
struct pci_dev *dev)
/* Required for devices using CAPP DMA mode, harmless for others */
pci_set_master(dev);
 
+   if (cxl_is_power9())
+   if (pnv_pci_set_tunnel_bar(dev, 0x0002E000ull, 1))
+   dev_info(&dev->dev, "Tunneled operations 
unsupported\n");
+
if ((rc = pnv_phb_to_cxl_mode(dev, adapter->native->sl_ops->capi_mode)))
goto err;
 
@@ -1768,6 +1772,8 @@ static void cxl_deconfigure_adapter(struct cxl *adapter)
 {
struct pci_dev *pdev = to_pci_dev(adapter->dev.parent);
 
+   if (cxl_is_power9())
+   pnv_pci_set_tunnel_bar(pdev, 0x0002E000ull, 0);
cxl_native_release_psl_err_irq(adapter);
cxl_unmap_adapter_regs(adapter);
 
-- 
2.16.3



[PATCH v3 2/2] cxl: Report the tunneled operations status

2018-04-25 Thread Philippe Bergheaud
Failure to synchronize the tunneled operations does not prevent
the initialization of the cxl card. This patch reports the tunneled
operations status via /sys.

Signed-off-by: Philippe Bergheaud 
---
v3: Added this patch to report the tunneled operations status.
---
 drivers/misc/cxl/cxl.h   |  1 +
 drivers/misc/cxl/pci.c   |  7 ++-
 drivers/misc/cxl/sysfs.c | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index a4c9c8297a6d..918d4fb742d1 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -717,6 +717,7 @@ struct cxl {
bool perst_select_user;
bool perst_same_image;
bool psl_timebase_synced;
+   bool tunneled_ops_supported;
 
/*
 * number of contexts mapped on to this card. Possible values are:
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 355c789406f7..008f50a0c465 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -1742,9 +1742,14 @@ static int cxl_configure_adapter(struct cxl *adapter, 
struct pci_dev *dev)
/* Required for devices using CAPP DMA mode, harmless for others */
pci_set_master(dev);
 
-   if (cxl_is_power9())
+   adapter->tunneled_ops_supported = false;
+
+   if (cxl_is_power9()) {
if (pnv_pci_set_tunnel_bar(dev, 0x0002E000ull, 1))
dev_info(&dev->dev, "Tunneled operations 
unsupported\n");
+   else
+   adapter->tunneled_ops_supported = true;
+   }
 
if ((rc = pnv_phb_to_cxl_mode(dev, adapter->native->sl_ops->capi_mode)))
goto err;
diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c
index 95285b7f636f..4b5a4c5d3c01 100644
--- a/drivers/misc/cxl/sysfs.c
+++ b/drivers/misc/cxl/sysfs.c
@@ -78,6 +78,15 @@ static ssize_t psl_timebase_synced_show(struct device 
*device,
return scnprintf(buf, PAGE_SIZE, "%i\n", adapter->psl_timebase_synced);
 }
 
+static ssize_t tunneled_ops_supported_show(struct device *device,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct cxl *adapter = to_cxl_adapter(device);
+
+   return scnprintf(buf, PAGE_SIZE, "%i\n", 
adapter->tunneled_ops_supported);
+}
+
 static ssize_t reset_adapter_store(struct device *device,
   struct device_attribute *attr,
   const char *buf, size_t count)
@@ -183,6 +192,7 @@ static struct device_attribute adapter_attrs[] = {
__ATTR_RO(base_image),
__ATTR_RO(image_loaded),
__ATTR_RO(psl_timebase_synced),
+   __ATTR_RO(tunneled_ops_supported),
__ATTR_RW(load_image_on_perst),
__ATTR_RW(perst_reloads_same_image),
__ATTR(reset, S_IWUSR, NULL, reset_adapter_store),
-- 
2.16.3



Re: [PATCH V3] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Nicholas Piggin
On Wed, 25 Apr 2018 16:29:31 +0530
Shilpasri G Bhat  wrote:

> gpstate_timer_handler() uses synchronous smp_call to set the pstate
> on the requested core. This causes the below hard lockup:
> 
> [c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
> (unreliable)
> [c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
> [c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
> [c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
> [c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
> [c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
> [c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
> [c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
> [c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
> [c03fe566b760] [c0009014] decrementer_common+0x114/0x120
> -- interrupt: 901 at doorbell_global_ipi+0x34/0x50
> LR = arch_send_call_function_ipi_mask+0x120/0x130
> [c03fe566ba50] [c004876c]
> arch_send_call_function_ipi_mask+0x4c/0x130
> [c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
> [c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
> [c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
> [c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
> [c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
> [c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
> [c03fe566be30] [c000b184] system_call+0x58/0x6c
> 
> One way to avoid this is removing the smp-call. We can ensure that the timer
> always runs on one of the policy-cpus. If the timer gets migrated to a
> cpu outside the policy then re-queue it back on the policy->cpus. This way
> we can get rid of the smp-call which was being used to set the pstate
> on the policy->cpus.
> 
> Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer as 
> pinned)
> Cc: [4.8+]
> Reported-by: Nicholas Piggin 
> Reported-by: Pridhiviraj Paidipeddi 
> Signed-off-by: Shilpasri G Bhat 

Thanks, this looks good to me. I don't know the code though, so

Acked-by: Nicholas Piggin 

> ---
> Changes from V2:
> - Remove the check for active policy while requeing the migrated timer
> Changes from V1:
> - Remove smp_call in the pstate handler.
> 
>  drivers/cpufreq/powernv-cpufreq.c | 14 +++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/powernv-cpufreq.c 
> b/drivers/cpufreq/powernv-cpufreq.c
> index 71f8682..e368e1f 100644
> --- a/drivers/cpufreq/powernv-cpufreq.c
> +++ b/drivers/cpufreq/powernv-cpufreq.c
> @@ -679,6 +679,16 @@ void gpstate_timer_handler(struct timer_list *t)
>  
>   if (!spin_trylock(&gpstates->gpstate_lock))
>   return;

I still think it would be good to do something about the trylock failure.
It may be rare, but if it happens it could stop the timer and lead to
some rare unpredictable behaviour? Not for this patch, but while you're
looking at the code it would be good to consider it. Just queueing up
another timer seems like it should be enough.

> + /*
> +  * If the timer has migrated to the different cpu then bring
> +  * it back to one of the policy->cpus
> +  */
> + if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
> + gpstates->timer.expires = jiffies + msecs_to_jiffies(1);
> + add_timer_on(&gpstates->timer, cpumask_first(policy->cpus));
> + spin_unlock(&gpstates->gpstate_lock);
> + return;
> + }

Really small nitpick, but you could use cpumask_any there.

Thanks,
Nick


>  
>   /*
>* If PMCR was last updated was using fast_swtich then
> @@ -718,10 +728,8 @@ void gpstate_timer_handler(struct timer_list *t)
>   if (gpstate_idx != gpstates->last_lpstate_idx)
>   queue_gpstate_timer(gpstates);
>  
> + set_pstate(&freq_data);
>   spin_unlock(&gpstates->gpstate_lock);
> -
> - /* Timer may get migrated to a different cpu on cpu hot unplug */
> - smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
>  }


[PATCH v2] powerpc: Fix smp_send_stop NMI IPI handling

2018-04-25 Thread Nicholas Piggin
The NMI IPI handler for a receiving CPU increments nmi_ipi_busy_count
over the handler function call, which causes later smp_send_nmi_ipi()
callers to spin until the call is finished.

The smp_send_stop function never returns, so the busy count is never
decremeted, which can cause the system to hang in some cases. For
example panic() will call smp_send_stop early on, then later in the
reboot path, pnv_restart will call smp_send_stop again, which hangs.

Fix this by adding a special case to the smp_send_stop handler to
decrement the busy count, because it will never return.

Fixes: 6bed3237624e3 ("powerpc: use NMI IPI for smp_send_stop")
Reported-by: Abdul Haleem 
Signed-off-by: Nicholas Piggin 
---
Changes since v1:
- Reduce #ifdef spaghetti suggested by mpe

 arch/powerpc/kernel/smp.c | 36 +---
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index e16ec7b3b427..41d42c2f88d4 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -566,10 +566,35 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct 
pt_regs *))
 #endif
 
 #ifdef CONFIG_NMI_IPI
-static void stop_this_cpu(struct pt_regs *regs)
-#else
+static void nmi_stop_this_cpu(struct pt_regs *regs)
+{
+   /*
+* This is a special case because it never returns, so the NMI IPI
+* handling would never mark it as done, which makes any later
+* smp_send_nmi_ipi() call spin forever. Mark it done now.
+*
+* IRQs are already hard disabled by the smp_handle_nmi_ipi.
+*/
+   nmi_ipi_lock();
+   nmi_ipi_busy_count--;
+   nmi_ipi_unlock();
+
+   /* Remove this CPU */
+   set_cpu_online(smp_processor_id(), false);
+
+   spin_begin();
+   while (1)
+   spin_cpu_relax();
+}
+
+void smp_send_stop(void)
+{
+   smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, nmi_stop_this_cpu, 100);
+}
+
+#else /* CONFIG_NMI_IPI */
+
 static void stop_this_cpu(void *dummy)
-#endif
 {
/* Remove this CPU */
set_cpu_online(smp_processor_id(), false);
@@ -582,12 +607,9 @@ static void stop_this_cpu(void *dummy)
 
 void smp_send_stop(void)
 {
-#ifdef CONFIG_NMI_IPI
-   smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, stop_this_cpu, 100);
-#else
smp_call_function(stop_this_cpu, NULL, 0);
-#endif
 }
+#endif /* CONFIG_NMI_IPI */
 
 struct thread_info *current_set[NR_CPUS];
 
-- 
2.17.0



[PATCH 00/11] KVM: PPC: reconstruct mmio emulation with analyse_instr()

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

We already have analyse_instr() which analyzes instructions for the instruction
type, size, addtional flags, etc. What kvmppc_emulate_loadstore() did is somehow
duplicated and it will be good to utilize analyse_instr() to reconstruct the
code. The advantage is that the code logic will be shared and more clean to be 
maintained.

This patch series reconstructs kvmppc_emulate_loadstore() for various load/store
instructions. 

The testcase locates at:
https://github.com/justdoitqd/publicFiles/blob/master/test_mmio.c

- Tested at both PR/HV KVM. 
- Also tested with little endian host & big endian guest.

Tested instruction list: 
lbz lbzu lbzx ld ldbrx
ldu ldx lfd lfdu lfdx
lfiwax lfiwzx lfs lfsu lfsx
lha lhau lhax lhbrx lhz
lhzu lhzx lvx lwax lwbrx
lwz lwzu lwzx lxsdx lxsiwax
lxsiwzx lxsspx lxvd2x lxvdsx lxvw4x
stb stbu stbx std stdbrx
stdu stdx stfd stfdu stfdx
stfiwx stfs stfsx sth sthbrx
sthu sthx stvx stw stwbrx
stwu stwx stxsdx stxsiwx stxsspx
stxvd2x stxvw4x

Simon Guo (11):
  KVM: PPC: add pt_regs into kvm_vcpu_arch and move vcpu->arch.gpr[]
into it
  KVM: PPC: mov nip/ctr/lr/xer registers to pt_regs in kvm_vcpu_arch
  KVM: PPC: Fix a mmio_host_swabbed uninitialized usage issue when VMX
store
  KVM: PPC: fix incorrect element_size for stxsiwx in analyse_instr
  KVM: PPC: add GPR RA update skeleton for MMIO emulation
  KVM: PPC: add KVMPPC_VSX_COPY_WORD_LOAD_DUMP type support for mmio
emulation
  KVM: PPC: reconstruct non-SIMD LOAD/STORE instruction mmio emulation
with analyse_intr() input
  KVM: PPC: add giveup_ext() hook for PPC KVM ops
  KVM: PPC: reconstruct LOAD_FP/STORE_FP instruction mmio emulation with
analyse_intr() input
  KVM: PPC: reconstruct LOAD_VMX/STORE_VMX instruction mmio emulation
with analyse_intr() input
  KVM: PPC: reconstruct LOAD_VSX/STORE_VSX instruction mmio emulation
with analyse_intr() input

 arch/powerpc/include/asm/kvm_book3s.h|  20 +-
 arch/powerpc/include/asm/kvm_book3s_64.h |  20 +-
 arch/powerpc/include/asm/kvm_booke.h |  20 +-
 arch/powerpc/include/asm/kvm_host.h  |   9 +-
 arch/powerpc/include/asm/kvm_ppc.h   |   2 +
 arch/powerpc/include/asm/sstep.h |   2 +-
 arch/powerpc/kernel/asm-offsets.c|  22 +-
 arch/powerpc/kvm/book3s_32_mmu.c |   2 +-
 arch/powerpc/kvm/book3s_64_vio_hv.c  |   2 +-
 arch/powerpc/kvm/book3s_hv.c |  11 +-
 arch/powerpc/kvm/book3s_hv_builtin.c |   6 +-
 arch/powerpc/kvm/book3s_hv_rm_mmu.c  |  15 +-
 arch/powerpc/kvm/book3s_hv_rm_xics.c |   2 +-
 arch/powerpc/kvm/book3s_hv_tm.c  |  10 +-
 arch/powerpc/kvm/book3s_hv_tm_builtin.c  |  10 +-
 arch/powerpc/kvm/book3s_pr.c |  73 +--
 arch/powerpc/kvm/book3s_xive_template.c  |   4 +-
 arch/powerpc/kvm/booke.c |  41 +-
 arch/powerpc/kvm/booke_emulate.c |   6 +-
 arch/powerpc/kvm/e500_emulate.c  |   6 +-
 arch/powerpc/kvm/e500_mmu.c  |   2 +-
 arch/powerpc/kvm/emulate_loadstore.c | 734 +--
 arch/powerpc/kvm/powerpc.c   |  53 ++-
 arch/powerpc/lib/sstep.c |   2 +-
 24 files changed, 407 insertions(+), 667 deletions(-)

-- 
1.8.3.1



[PATCH 02/11] KVM: PPC: mov nip/ctr/lr/xer registers to pt_regs in kvm_vcpu_arch

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

This patch moves nip/ctr/lr/xer registers from scattered places in
kvm_vcpu_arch to pt_regs structure.

cr register is "unsigned long" in pt_regs and u32 in vcpu->arch.
It will need more consideration and may move in later patches.

Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/kvm_book3s.h| 16 ++---
 arch/powerpc/include/asm/kvm_book3s_64.h | 20 
 arch/powerpc/include/asm/kvm_booke.h | 20 
 arch/powerpc/include/asm/kvm_host.h  |  4 
 arch/powerpc/kernel/asm-offsets.c| 20 
 arch/powerpc/kvm/book3s_32_mmu.c |  2 +-
 arch/powerpc/kvm/book3s_hv.c |  6 ++---
 arch/powerpc/kvm/book3s_hv_tm.c  | 10 
 arch/powerpc/kvm/book3s_hv_tm_builtin.c  | 10 
 arch/powerpc/kvm/book3s_pr.c | 16 ++---
 arch/powerpc/kvm/booke.c | 41 +---
 arch/powerpc/kvm/booke_emulate.c |  6 ++---
 arch/powerpc/kvm/e500_emulate.c  |  2 +-
 arch/powerpc/kvm/e500_mmu.c  |  2 +-
 14 files changed, 87 insertions(+), 88 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index 9de4127..d39d608 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -293,42 +293,42 @@ static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
 
 static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, ulong val)
 {
-   vcpu->arch.xer = val;
+   vcpu->arch.regs.xer = val;
 }
 
 static inline ulong kvmppc_get_xer(struct kvm_vcpu *vcpu)
 {
-   return vcpu->arch.xer;
+   return vcpu->arch.regs.xer;
 }
 
 static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
 {
-   vcpu->arch.ctr = val;
+   vcpu->arch.regs.ctr = val;
 }
 
 static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
 {
-   return vcpu->arch.ctr;
+   return vcpu->arch.regs.ctr;
 }
 
 static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
 {
-   vcpu->arch.lr = val;
+   vcpu->arch.regs.link = val;
 }
 
 static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
 {
-   return vcpu->arch.lr;
+   return vcpu->arch.regs.link;
 }
 
 static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
 {
-   vcpu->arch.pc = val;
+   vcpu->arch.regs.nip = val;
 }
 
 static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
 {
-   return vcpu->arch.pc;
+   return vcpu->arch.regs.nip;
 }
 
 static inline u64 kvmppc_get_msr(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h 
b/arch/powerpc/include/asm/kvm_book3s_64.h
index c424e44..dc435a5 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -483,15 +483,15 @@ static inline u64 sanitize_msr(u64 msr)
 static inline void copy_from_checkpoint(struct kvm_vcpu *vcpu)
 {
vcpu->arch.cr  = vcpu->arch.cr_tm;
-   vcpu->arch.xer = vcpu->arch.xer_tm;
-   vcpu->arch.lr  = vcpu->arch.lr_tm;
-   vcpu->arch.ctr = vcpu->arch.ctr_tm;
+   vcpu->arch.regs.xer = vcpu->arch.xer_tm;
+   vcpu->arch.regs.link  = vcpu->arch.lr_tm;
+   vcpu->arch.regs.ctr = vcpu->arch.ctr_tm;
vcpu->arch.amr = vcpu->arch.amr_tm;
vcpu->arch.ppr = vcpu->arch.ppr_tm;
vcpu->arch.dscr = vcpu->arch.dscr_tm;
vcpu->arch.tar = vcpu->arch.tar_tm;
-   memcpy(vcpu->arch.gpr, vcpu->arch.gpr_tm,
-  sizeof(vcpu->arch.gpr));
+   memcpy(vcpu->arch.regs.gpr, vcpu->arch.gpr_tm,
+  sizeof(vcpu->arch.regs.gpr));
vcpu->arch.fp  = vcpu->arch.fp_tm;
vcpu->arch.vr  = vcpu->arch.vr_tm;
vcpu->arch.vrsave = vcpu->arch.vrsave_tm;
@@ -500,15 +500,15 @@ static inline void copy_from_checkpoint(struct kvm_vcpu 
*vcpu)
 static inline void copy_to_checkpoint(struct kvm_vcpu *vcpu)
 {
vcpu->arch.cr_tm  = vcpu->arch.cr;
-   vcpu->arch.xer_tm = vcpu->arch.xer;
-   vcpu->arch.lr_tm  = vcpu->arch.lr;
-   vcpu->arch.ctr_tm = vcpu->arch.ctr;
+   vcpu->arch.xer_tm = vcpu->arch.regs.xer;
+   vcpu->arch.lr_tm  = vcpu->arch.regs.link;
+   vcpu->arch.ctr_tm = vcpu->arch.regs.ctr;
vcpu->arch.amr_tm = vcpu->arch.amr;
vcpu->arch.ppr_tm = vcpu->arch.ppr;
vcpu->arch.dscr_tm = vcpu->arch.dscr;
vcpu->arch.tar_tm = vcpu->arch.tar;
-   memcpy(vcpu->arch.gpr_tm, vcpu->arch.gpr,
-  sizeof(vcpu->arch.gpr));
+   memcpy(vcpu->arch.gpr_tm, vcpu->arch.regs.gpr,
+  sizeof(vcpu->arch.regs.gpr));
vcpu->arch.fp_tm  = vcpu->arch.fp;
vcpu->arch.vr_tm  = vcpu->arch.vr;
vcpu->arch.vrsave_tm = vcpu->arch.vrsave;
diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index bc6e29e..d513e3e 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -36,12 +36,12 @@
 
 static inline void kvm

[PATCH 01/11] KVM: PPC: add pt_regs into kvm_vcpu_arch and move vcpu->arch.gpr[] into it

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

Current regs are scattered at kvm_vcpu_arch structure and it will
be more neat to organize them into pt_regs structure.

Also it will enable reconstruct MMIO emulation code with
analyse_instr() later.

Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/kvm_book3s.h   |  4 +--
 arch/powerpc/include/asm/kvm_host.h |  2 +-
 arch/powerpc/kernel/asm-offsets.c   |  4 +--
 arch/powerpc/kvm/book3s_64_vio_hv.c |  2 +-
 arch/powerpc/kvm/book3s_hv_builtin.c|  6 ++--
 arch/powerpc/kvm/book3s_hv_rm_mmu.c | 15 -
 arch/powerpc/kvm/book3s_hv_rm_xics.c|  2 +-
 arch/powerpc/kvm/book3s_pr.c| 56 -
 arch/powerpc/kvm/book3s_xive_template.c |  4 +--
 arch/powerpc/kvm/e500_emulate.c |  4 +--
 10 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index 4c02a73..9de4127 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -273,12 +273,12 @@ static inline struct kvmppc_vcpu_book3s *to_book3s(struct 
kvm_vcpu *vcpu)
 
 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
 {
-   vcpu->arch.gpr[num] = val;
+   vcpu->arch.regs.gpr[num] = val;
 }
 
 static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
 {
-   return vcpu->arch.gpr[num];
+   return vcpu->arch.regs.gpr[num];
 }
 
 static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 17498e9..1c93d82 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -486,7 +486,7 @@ struct kvm_vcpu_arch {
struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
 #endif
 
-   ulong gpr[32];
+   struct pt_regs regs;
 
struct thread_fp_state fp;
 
diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 6bee65f..e8a78a5 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -425,7 +425,7 @@ int main(void)
OFFSET(VCPU_HOST_STACK, kvm_vcpu, arch.host_stack);
OFFSET(VCPU_HOST_PID, kvm_vcpu, arch.host_pid);
OFFSET(VCPU_GUEST_PID, kvm_vcpu, arch.pid);
-   OFFSET(VCPU_GPRS, kvm_vcpu, arch.gpr);
+   OFFSET(VCPU_GPRS, kvm_vcpu, arch.regs.gpr);
OFFSET(VCPU_VRSAVE, kvm_vcpu, arch.vrsave);
OFFSET(VCPU_FPRS, kvm_vcpu, arch.fp.fpr);
 #ifdef CONFIG_ALTIVEC
@@ -438,7 +438,7 @@ int main(void)
OFFSET(VCPU_TAR, kvm_vcpu, arch.tar);
 #endif
OFFSET(VCPU_CR, kvm_vcpu, arch.cr);
-   OFFSET(VCPU_PC, kvm_vcpu, arch.pc);
+   OFFSET(VCPU_PC, kvm_vcpu, arch.nip);
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
OFFSET(VCPU_MSR, kvm_vcpu, arch.shregs.msr);
OFFSET(VCPU_SRR0, kvm_vcpu, arch.shregs.srr0);
diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c 
b/arch/powerpc/kvm/book3s_64_vio_hv.c
index 6651f73..bdd872a 100644
--- a/arch/powerpc/kvm/book3s_64_vio_hv.c
+++ b/arch/powerpc/kvm/book3s_64_vio_hv.c
@@ -571,7 +571,7 @@ long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long 
liobn,
page = stt->pages[idx / TCES_PER_PAGE];
tbl = (u64 *)page_address(page);
 
-   vcpu->arch.gpr[4] = tbl[idx % TCES_PER_PAGE];
+   vcpu->arch.regs.gpr[4] = tbl[idx % TCES_PER_PAGE];
 
return H_SUCCESS;
 }
diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c 
b/arch/powerpc/kvm/book3s_hv_builtin.c
index de18299..2b12758 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -211,9 +211,9 @@ long kvmppc_h_random(struct kvm_vcpu *vcpu)
 
/* Only need to do the expensive mfmsr() on radix */
if (kvm_is_radix(vcpu->kvm) && (mfmsr() & MSR_IR))
-   r = powernv_get_random_long(&vcpu->arch.gpr[4]);
+   r = powernv_get_random_long(&vcpu->arch.regs.gpr[4]);
else
-   r = powernv_get_random_real_mode(&vcpu->arch.gpr[4]);
+   r = powernv_get_random_real_mode(&vcpu->arch.regs.gpr[4]);
if (r)
return H_SUCCESS;
 
@@ -562,7 +562,7 @@ unsigned long kvmppc_rm_h_xirr_x(struct kvm_vcpu *vcpu)
 {
if (!kvmppc_xics_enabled(vcpu))
return H_TOO_HARD;
-   vcpu->arch.gpr[5] = get_tb();
+   vcpu->arch.regs.gpr[5] = get_tb();
if (xive_enabled()) {
if (is_rm())
return xive_rm_h_xirr(vcpu);
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c 
b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index e1c083f..3d3ce7a 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -418,7 +418,8 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long 
flags,
long pte_index, unsigned long pteh, unsigned long ptel)
 {
return kvmppc_do_h_enter(vcpu->kvm, flags, pte_index, pteh, ptel,
-vc

[PATCH 03/11] KVM: PPC: Fix a mmio_host_swabbed uninitialized usage issue when VMX store

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

When KVM emulates VMX store, it will invoke kvmppc_get_vmx_data() to
retrieve VMX reg val. kvmppc_get_vmx_data() will check mmio_host_swabbed
to decide which double word of vr[] to be used. But the
mmio_host_swabbed can be uninitiazed during VMX store procedure:

kvmppc_emulate_loadstore
\- kvmppc_handle_store128_by2x64
\- kvmppc_get_vmx_data

This patch corrects this by using kvmppc_need_byteswap() to choose
double word of vr[] and initialized mmio_host_swabbed to avoid invisble
trouble.

Signed-off-by: Simon Guo 
---
 arch/powerpc/kvm/emulate_loadstore.c | 1 +
 arch/powerpc/kvm/powerpc.c   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index a382e15..b8a3aef 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -111,6 +111,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
vcpu->arch.mmio_sp64_extend = 0;
vcpu->arch.mmio_sign_extend = 0;
vcpu->arch.mmio_vmx_copy_nums = 0;
+   vcpu->arch.mmio_host_swabbed = 0;
 
switch (get_op(inst)) {
case 31:
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 4e38764..bef27b1 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -1374,7 +1374,7 @@ static inline int kvmppc_get_vmx_data(struct kvm_vcpu 
*vcpu, int rs, u64 *val)
if (di > 1)
return -1;
 
-   if (vcpu->arch.mmio_host_swabbed)
+   if (kvmppc_need_byteswap(vcpu))
di = 1 - di;
 
w0 = vrs.u[di * 2];
-- 
1.8.3.1



[PATCH 04/11] KVM: PPC: fix incorrect element_size for stxsiwx in analyse_instr

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

stwsiwx will place contents of word element 1 of VSR into word
storage of EA. So the element size of stwsiwx should be 4.

This patch correct the size from 8 to 4.

Signed-off-by: Simon Guo 
---
 arch/powerpc/lib/sstep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c
index 34d68f1..151d484 100644
--- a/arch/powerpc/lib/sstep.c
+++ b/arch/powerpc/lib/sstep.c
@@ -2178,7 +2178,7 @@ int analyse_instr(struct instruction_op *op, const struct 
pt_regs *regs,
case 140:   /* stxsiwx */
op->reg = rd | ((instr & 1) << 5);
op->type = MKOP(STORE_VSX, 0, 4);
-   op->element_size = 8;
+   op->element_size = 4;
break;
 
case 268:   /* lxvx */
-- 
1.8.3.1



[PATCH 05/11] KVM: PPC: add GPR RA update skeleton for MMIO emulation

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

To optimize kvm emulation code with analyse_instr, adds new
mmio_update_ra flag to aid with GPR RA update.

This patch arms RA update at load/store emulation path for both
qemu mmio emulation or coalesced mmio emulation.

Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/kvm_host.h  |  2 ++
 arch/powerpc/kvm/emulate_loadstore.c |  1 +
 arch/powerpc/kvm/powerpc.c   | 17 +
 3 files changed, 20 insertions(+)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 2d87768..1c7da00 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -673,6 +673,8 @@ struct kvm_vcpu_arch {
u8 mmio_sign_extend;
/* conversion between single and double precision */
u8 mmio_sp64_extend;
+   u8 mmio_ra; /* GPR as ra to be updated with EA */
+   u8 mmio_update_ra;
/*
 * Number of simulations for vsx.
 * If we use 2*8bytes to simulate 1*16bytes,
diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index b8a3aef..90b9692 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -111,6 +111,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
vcpu->arch.mmio_sp64_extend = 0;
vcpu->arch.mmio_sign_extend = 0;
vcpu->arch.mmio_vmx_copy_nums = 0;
+   vcpu->arch.mmio_update_ra = 0;
vcpu->arch.mmio_host_swabbed = 0;
 
switch (get_op(inst)) {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index bef27b1..f7fd68f 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -,6 +,12 @@ static int __kvmppc_handle_load(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
 
if (!ret) {
kvmppc_complete_mmio_load(vcpu, run);
+   if (vcpu->arch.mmio_update_ra) {
+   kvmppc_set_gpr(vcpu, vcpu->arch.mmio_ra,
+   vcpu->arch.vaddr_accessed);
+   vcpu->arch.mmio_update_ra = 0;
+   }
+
vcpu->mmio_needed = 0;
return EMULATE_DONE;
}
@@ -1215,6 +1221,12 @@ int kvmppc_handle_store(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
if (!ret) {
vcpu->mmio_needed = 0;
+   if (vcpu->arch.mmio_update_ra) {
+   kvmppc_set_gpr(vcpu, vcpu->arch.mmio_ra,
+   vcpu->arch.vaddr_accessed);
+   vcpu->arch.mmio_update_ra = 0;
+   }
+
return EMULATE_DONE;
}
 
@@ -1581,6 +1593,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, 
struct kvm_run *run)
}
}
 #endif
+   if (vcpu->arch.mmio_update_ra) {
+   kvmppc_set_gpr(vcpu, vcpu->arch.mmio_ra,
+   vcpu->arch.vaddr_accessed);
+   vcpu->arch.mmio_update_ra = 0;
+   }
} else if (vcpu->arch.osi_needed) {
u64 *gprs = run->osi.gprs;
int i;
-- 
1.8.3.1



[PATCH 06/11] KVM: PPC: add KVMPPC_VSX_COPY_WORD_LOAD_DUMP type support for mmio emulation

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

Some VSX instruction like lxvwsx will splat word into VSR. This patch
adds VSX copy type KVMPPC_VSX_COPY_WORD_LOAD_DUMP to support this.

Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/kvm_host.h |  1 +
 arch/powerpc/kvm/powerpc.c  | 23 +++
 2 files changed, 24 insertions(+)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 1c7da00..db7e25d 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -454,6 +454,7 @@ struct mmio_hpte_cache {
 #define KVMPPC_VSX_COPY_WORD   1
 #define KVMPPC_VSX_COPY_DWORD  2
 #define KVMPPC_VSX_COPY_DWORD_LOAD_DUMP3
+#define KVMPPC_VSX_COPY_WORD_LOAD_DUMP 4
 
 struct openpic;
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index f7fd68f..17f0315 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -907,6 +907,26 @@ static inline void kvmppc_set_vsr_dword_dump(struct 
kvm_vcpu *vcpu,
}
 }
 
+static inline void kvmppc_set_vsr_word_dump(struct kvm_vcpu *vcpu,
+   u32 gpr)
+{
+   union kvmppc_one_reg val;
+   int index = vcpu->arch.io_gpr & KVM_MMIO_REG_MASK;
+
+   if (vcpu->arch.mmio_vsx_tx_sx_enabled) {
+   val.vsx32val[0] = gpr;
+   val.vsx32val[1] = gpr;
+   val.vsx32val[2] = gpr;
+   val.vsx32val[3] = gpr;
+   VCPU_VSX_VR(vcpu, index) = val.vval;
+   } else {
+   val.vsx32val[0] = gpr;
+   val.vsx32val[1] = gpr;
+   VCPU_VSX_FPR(vcpu, index, 0) = val.vsxval[0];
+   VCPU_VSX_FPR(vcpu, index, 1) = val.vsxval[0];
+   }
+}
+
 static inline void kvmppc_set_vsr_word(struct kvm_vcpu *vcpu,
u32 gpr32)
 {
@@ -1061,6 +1081,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu 
*vcpu,
else if (vcpu->arch.mmio_vsx_copy_type ==
KVMPPC_VSX_COPY_DWORD_LOAD_DUMP)
kvmppc_set_vsr_dword_dump(vcpu, gpr);
+   else if (vcpu->arch.mmio_vsx_copy_type ==
+   KVMPPC_VSX_COPY_WORD_LOAD_DUMP)
+   kvmppc_set_vsr_word_dump(vcpu, gpr);
break;
 #endif
 #ifdef CONFIG_ALTIVEC
-- 
1.8.3.1



[PATCH 07/11] KVM: PPC: reconstruct non-SIMD LOAD/STORE instruction mmio emulation with analyse_intr() input

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

This patch reconstructs non-SIMD LOAD/STORE instruction MMIO emulation
with analyse_intr() input. It utilizes the BYTEREV/UPDATE/SIGNEXT
properties exported by analyse_instr() and invokes
kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.

It also move CACHEOP type handling into the skeleton.

instruction_type within sstep.h is renamed to avoid conflict with
kvm_ppc.h.

Suggested-by: Paul Mackerras 
Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/sstep.h |   2 +-
 arch/powerpc/kvm/emulate_loadstore.c | 282 +++
 2 files changed, 51 insertions(+), 233 deletions(-)

diff --git a/arch/powerpc/include/asm/sstep.h b/arch/powerpc/include/asm/sstep.h
index ab9d849..0a1a312 100644
--- a/arch/powerpc/include/asm/sstep.h
+++ b/arch/powerpc/include/asm/sstep.h
@@ -23,7 +23,7 @@
 #define IS_RFID(instr) (((instr) & 0xfc0007fe) == 0x4c24)
 #define IS_RFI(instr)  (((instr) & 0xfc0007fe) == 0x4c64)
 
-enum instruction_type {
+enum analyse_instruction_type {
COMPUTE,/* arith/logical/CR op, etc. */
LOAD,   /* load and store types need to be contiguous */
LOAD_MULTI,
diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index 90b9692..aaaf872 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -31,9 +31,12 @@
 #include 
 #include 
 #include 
+#include 
 #include "timing.h"
 #include "trace.h"
 
+int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
+ unsigned int instr);
 #ifdef CONFIG_PPC_FPU
 static bool kvmppc_check_fp_disabled(struct kvm_vcpu *vcpu)
 {
@@ -84,8 +87,9 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
struct kvm_run *run = vcpu->run;
u32 inst;
int ra, rs, rt;
-   enum emulation_result emulated;
+   enum emulation_result emulated = EMULATE_FAIL;
int advance = 1;
+   struct instruction_op op;
 
/* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
@@ -114,144 +118,64 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
vcpu->arch.mmio_update_ra = 0;
vcpu->arch.mmio_host_swabbed = 0;
 
-   switch (get_op(inst)) {
-   case 31:
-   switch (get_xop(inst)) {
-   case OP_31_XOP_LWZX:
-   emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
-   break;
-
-   case OP_31_XOP_LWZUX:
-   emulated = kvmppc_handle_load(run, vcpu, rt, 4, 1);
-   kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed);
-   break;
-
-   case OP_31_XOP_LBZX:
-   emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
-   break;
+   emulated = EMULATE_FAIL;
+   vcpu->arch.regs.msr = vcpu->arch.shared->msr;
+   vcpu->arch.regs.ccr = vcpu->arch.cr;
+   if (analyse_instr(&op, &vcpu->arch.regs, inst) == 0) {
+   int type = op.type & INSTR_TYPE_MASK;
+   int size = GETSIZE(op.type);
 
-   case OP_31_XOP_LBZUX:
-   emulated = kvmppc_handle_load(run, vcpu, rt, 1, 1);
-   kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed);
-   break;
+   switch (type) {
+   case LOAD:  {
+   int instr_byte_swap = op.type & BYTEREV;
 
-   case OP_31_XOP_STDX:
-   emulated = kvmppc_handle_store(run, vcpu,
-   kvmppc_get_gpr(vcpu, rs), 8, 1);
-   break;
+   if (op.type & UPDATE) {
+   vcpu->arch.mmio_ra = op.update_reg;
+   vcpu->arch.mmio_update_ra = 1;
+   }
 
-   case OP_31_XOP_STDUX:
-   emulated = kvmppc_handle_store(run, vcpu,
-   kvmppc_get_gpr(vcpu, rs), 8, 1);
-   kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed);
-   break;
-
-   case OP_31_XOP_STWX:
-   emulated = kvmppc_handle_store(run, vcpu,
-   kvmppc_get_gpr(vcpu, rs), 4, 1);
-   break;
-
-   case OP_31_XOP_STWUX:
-   emulated = kvmppc_handle_store(run, vcpu,
-   kvmppc_get_gpr(vcpu, rs), 4, 1);
-   kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed);
-   break;
-
-   case OP_31_XOP_STBX:
-   emulated = kvmppc_handle_store(run, vcpu,
-   kvmppc_get_gpr(vcpu, rs), 1, 1);
-   break;
-
-   case OP_

[PATCH 08/11] KVM: PPC: add giveup_ext() hook for PPC KVM ops

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

Currently HV will save math regs(FP/VEC/VSX) when trap into host. But
PR KVM will only save math regs when qemu task switch out of CPU.

To emulate FP/VEC/VSX load, PR KVM need to flush math regs firstly and
then be able to update saved VCPU FPR/VEC/VSX area reasonably.

This patch adds the giveup_ext() to KVM ops (an empty one for HV KVM)
and kvmppc_complete_mmio_load() can invoke that hook to flush math
regs accordingly.

Math regs flush is also necessary for STORE, which will be covered
in later patch within this patch series.

Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/kvm_ppc.h | 1 +
 arch/powerpc/kvm/book3s_hv.c   | 5 +
 arch/powerpc/kvm/book3s_pr.c   | 1 +
 arch/powerpc/kvm/powerpc.c | 9 +
 4 files changed, 16 insertions(+)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index abe7032..b265538 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -324,6 +324,7 @@ struct kvmppc_ops {
int (*get_rmmu_info)(struct kvm *kvm, struct kvm_ppc_rmmu_info *info);
int (*set_smt_mode)(struct kvm *kvm, unsigned long mode,
unsigned long flags);
+   void (*giveup_ext)(struct kvm_vcpu *vcpu, ulong msr);
 };
 
 extern struct kvmppc_ops *kvmppc_hv_ops;
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 5b875ba..7eb5507 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2084,6 +2084,10 @@ static int kvmhv_set_smt_mode(struct kvm *kvm, unsigned 
long smt_mode,
return err;
 }
 
+static void kvmhv_giveup_ext(struct kvm_vcpu *vcpu, ulong msr)
+{
+}
+
 static void unpin_vpa(struct kvm *kvm, struct kvmppc_vpa *vpa)
 {
if (vpa->pinned_addr)
@@ -4398,6 +4402,7 @@ static int kvmhv_configure_mmu(struct kvm *kvm, struct 
kvm_ppc_mmuv3_cfg *cfg)
.configure_mmu = kvmhv_configure_mmu,
.get_rmmu_info = kvmhv_get_rmmu_info,
.set_smt_mode = kvmhv_set_smt_mode,
+   .giveup_ext = kvmhv_giveup_ext,
 };
 
 static int kvm_init_subcore_bitmap(void)
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 67061d3..be26636 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1782,6 +1782,7 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp,
 #ifdef CONFIG_PPC_BOOK3S_64
.hcall_implemented = kvmppc_hcall_impl_pr,
 #endif
+   .giveup_ext = kvmppc_giveup_ext,
 };
 
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 17f0315..e724601 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -1061,6 +1061,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu 
*vcpu,
kvmppc_set_gpr(vcpu, vcpu->arch.io_gpr, gpr);
break;
case KVM_MMIO_REG_FPR:
+   if (!is_kvmppc_hv_enabled(vcpu->kvm))
+   vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu, MSR_FP);
+
VCPU_FPR(vcpu, vcpu->arch.io_gpr & KVM_MMIO_REG_MASK) = gpr;
break;
 #ifdef CONFIG_PPC_BOOK3S
@@ -1074,6 +1077,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu 
*vcpu,
 #endif
 #ifdef CONFIG_VSX
case KVM_MMIO_REG_VSX:
+   if (!is_kvmppc_hv_enabled(vcpu->kvm))
+   vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu, MSR_VSX);
+
if (vcpu->arch.mmio_vsx_copy_type == KVMPPC_VSX_COPY_DWORD)
kvmppc_set_vsr_dword(vcpu, gpr);
else if (vcpu->arch.mmio_vsx_copy_type == KVMPPC_VSX_COPY_WORD)
@@ -1088,6 +1094,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu 
*vcpu,
 #endif
 #ifdef CONFIG_ALTIVEC
case KVM_MMIO_REG_VMX:
+   if (!is_kvmppc_hv_enabled(vcpu->kvm))
+   vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu, MSR_VEC);
+
kvmppc_set_vmx_dword(vcpu, gpr);
break;
 #endif
-- 
1.8.3.1



[PATCH 09/11] KVM: PPC: reconstruct LOAD_FP/STORE_FP instruction mmio emulation with analyse_intr() input

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

This patch reconstructs LOAD_FP/STORE_FP instruction MMIO emulation with
analyse_intr() input. It utilizes the FPCONV/UPDATE properties exported by
analyse_instr() and invokes kvmppc_handle_load(s)/kvmppc_handle_store()
accordingly.

The FP regs need to be flushed so that the right FP reg vals can be read
from vcpu->arch.fpr.

Suggested-by: Paul Mackerras 
Signed-off-by: Simon Guo 
---
 arch/powerpc/kvm/emulate_loadstore.c | 199 ---
 1 file changed, 42 insertions(+), 157 deletions(-)

diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index aaaf872..2dbdf9a 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -143,6 +143,23 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
 
break;
}
+#ifdef CONFIG_PPC_FPU
+   case LOAD_FP:
+   if (kvmppc_check_fp_disabled(vcpu))
+   return EMULATE_DONE;
+
+   if (op.type & UPDATE) {
+   vcpu->arch.mmio_ra = op.update_reg;
+   vcpu->arch.mmio_update_ra = 1;
+   }
+
+   if (op.type & FPCONV)
+   vcpu->arch.mmio_sp64_extend = 1;
+
+   emulated = kvmppc_handle_load(run, vcpu,
+   KVM_MMIO_REG_FPR|op.reg, size, 1);
+   break;
+#endif
case STORE:
if (op.type & UPDATE) {
vcpu->arch.mmio_ra = op.update_reg;
@@ -155,6 +172,31 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
emulated = kvmppc_handle_store(run, vcpu, op.val,
size, 1);
break;
+#ifdef CONFIG_PPC_FPU
+   case STORE_FP:
+   if (kvmppc_check_fp_disabled(vcpu))
+   return EMULATE_DONE;
+
+   /* if it is PR KVM, the FP/VEC/VSX registers need to
+* be flushed so that kvmppc_handle_store() can read
+* actual VMX vals from vcpu->arch.
+*/
+   if (!is_kvmppc_hv_enabled(vcpu->kvm))
+   vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu,
+   MSR_FP);
+
+   if (op.type & UPDATE) {
+   vcpu->arch.mmio_ra = op.update_reg;
+   vcpu->arch.mmio_update_ra = 1;
+   }
+
+   if (op.type & FPCONV)
+   vcpu->arch.mmio_sp64_extend = 1;
+
+   emulated = kvmppc_handle_store(run, vcpu,
+   VCPU_FPR(vcpu, op.reg), size, 1);
+   break;
+#endif
case CACHEOP:
/* Do nothing. The guest is performing dcbi because
 * hardware DMA is not snooped by the dcache, but
@@ -176,93 +218,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
switch (get_op(inst)) {
case 31:
switch (get_xop(inst)) {
-#ifdef CONFIG_PPC_FPU
-   case OP_31_XOP_LFSX:
-   if (kvmppc_check_fp_disabled(vcpu))
-   return EMULATE_DONE;
-   vcpu->arch.mmio_sp64_extend = 1;
-   emulated = kvmppc_handle_load(run, vcpu,
-   KVM_MMIO_REG_FPR|rt, 4, 1);
-   break;
-
-   case OP_31_XOP_LFSUX:
-   if (kvmppc_check_fp_disabled(vcpu))
-   return EMULATE_DONE;
-   vcpu->arch.mmio_sp64_extend = 1;
-   emulated = kvmppc_handle_load(run, vcpu,
-   KVM_MMIO_REG_FPR|rt, 4, 1);
-   kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed);
-   break;
-
-   case OP_31_XOP_LFDX:
-   if (kvmppc_check_fp_disabled(vcpu))
-   return EMULATE_DONE;
-   emulated = kvmppc_handle_load(run, vcpu,
-   KVM_MMIO_REG_FPR|rt, 8, 1);
-   break;
-
-   case OP_31_XOP_LFDUX:
-   if (kvmppc_check_fp_disabled(vcpu))
-   return EMULATE_DONE;
-   emulated = kvmppc_handle_load(run, vcpu,
-   KVM_MMIO_REG_FPR|rt, 8, 1);
-   kvmppc_set_gpr(vcpu, ra, vcpu->arch.vaddr_accessed);
-   break;
-
-   case OP_31_XOP_LFIWAX:
-   if (kvmppc_check_fp_disabled(vcpu))
- 

[PATCH 10/11] KVM: PPC: reconstruct LOAD_VMX/STORE_VMX instruction mmio emulation with analyse_intr() input

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

This patch reconstructs LOAD_VMX/STORE_VMX instruction MMIO emulation with
analyse_intr() input. When emulating the store, the VMX reg will need to
be flushed so that the right reg val can be retrieved before writing to
IO MEM.

Suggested-by: Paul Mackerras 
Signed-off-by: Simon Guo 
---
 arch/powerpc/include/asm/kvm_ppc.h   |  1 +
 arch/powerpc/kvm/emulate_loadstore.c | 73 +---
 arch/powerpc/kvm/powerpc.c   |  2 +-
 3 files changed, 53 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index b265538..eeb00de 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -83,6 +83,7 @@ extern int kvmppc_handle_vsx_load(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
int is_default_endian, int mmio_sign_extend);
 extern int kvmppc_handle_load128_by2x64(struct kvm_run *run,
struct kvm_vcpu *vcpu, unsigned int rt, int is_default_endian);
+extern int kvmppc_get_vmx_data(struct kvm_vcpu *vcpu, int rs, u64 *val);
 extern int kvmppc_handle_store128_by2x64(struct kvm_run *run,
struct kvm_vcpu *vcpu, unsigned int rs, int is_default_endian);
 extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index 2dbdf9a..0bfee2f 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -160,6 +160,27 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
KVM_MMIO_REG_FPR|op.reg, size, 1);
break;
 #endif
+#ifdef CONFIG_ALTIVEC
+   case LOAD_VMX:
+   if (kvmppc_check_altivec_disabled(vcpu))
+   return EMULATE_DONE;
+
+   /* VMX access will need to be size aligned */
+   vcpu->arch.vaddr_accessed &= ~((unsigned long)size - 1);
+   vcpu->arch.paddr_accessed &= ~((unsigned long)size - 1);
+
+   if (size == 16) {
+   vcpu->arch.mmio_vmx_copy_nums = 2;
+   emulated = kvmppc_handle_load128_by2x64(run,
+   vcpu, KVM_MMIO_REG_VMX|op.reg,
+   1);
+   } else if (size <= 8)
+   emulated = kvmppc_handle_load(run, vcpu,
+   KVM_MMIO_REG_VMX|op.reg,
+   size, 1);
+
+   break;
+#endif
case STORE:
if (op.type & UPDATE) {
vcpu->arch.mmio_ra = op.update_reg;
@@ -197,6 +218,36 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
VCPU_FPR(vcpu, op.reg), size, 1);
break;
 #endif
+#ifdef CONFIG_ALTIVEC
+   case STORE_VMX:
+   if (kvmppc_check_altivec_disabled(vcpu))
+   return EMULATE_DONE;
+
+   /* VMX access will need to be size aligned */
+   vcpu->arch.vaddr_accessed &= ~((unsigned long)size - 1);
+   vcpu->arch.paddr_accessed &= ~((unsigned long)size - 1);
+
+   /* if it is PR KVM, the FP/VEC/VSX registers need to
+* be flushed so that kvmppc_handle_store() can read
+* actual VMX vals from vcpu->arch.
+*/
+   if (!is_kvmppc_hv_enabled(vcpu->kvm))
+   vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu,
+   MSR_VEC);
+
+   if (size == 16) {
+   vcpu->arch.mmio_vmx_copy_nums = 2;
+   emulated = kvmppc_handle_store128_by2x64(run,
+   vcpu, op.reg, 1);
+   } else if (size <= 8) {
+   u64 val;
+
+   kvmppc_get_vmx_data(vcpu, op.reg, &val);
+   emulated = kvmppc_handle_store(run, vcpu,
+   val, size, 1);
+   }
+   break;
+#endif
case CACHEOP:
/* Do nothing. The guest is performing dcbi because
 * hardware DMA is not snooped by the dcache, but
@@ -354,28 +405,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
break;
 #endif /* CONFIG_VSX */
 
-#ifdef CONFIG_ALTIVEC
-   case OP_31_XOP_LVX:
-   if (kvmppc_check_altivec_disabled(vcpu))
-   

[PATCH 11/11] KVM: PPC: reconstruct LOAD_VSX/STORE_VSX instruction mmio emulation with analyse_intr() input

2018-04-25 Thread wei . guo . simon
From: Simon Guo 

This patch reconstructs LOAD_VSX/STORE_VSX instruction MMIO emulation with
analyse_intr() input. It utilizes VSX_FPCONV/VSX_SPLAT/SIGNEXT exported
by analyse_instr() and handle accordingly.

When emulating VSX store, the VSX reg will need to be flushed so that
the right reg val can be retrieved before writing to IO MEM.

Suggested-by: Paul Mackerras 
Signed-off-by: Simon Guo 
---
 arch/powerpc/kvm/emulate_loadstore.c | 256 ++-
 1 file changed, 101 insertions(+), 155 deletions(-)

diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index 0bfee2f..bbd2f58 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -181,6 +181,54 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
 
break;
 #endif
+#ifdef CONFIG_VSX
+   case LOAD_VSX: {
+   int io_size_each;
+
+   if (op.vsx_flags & VSX_CHECK_VEC) {
+   if (kvmppc_check_altivec_disabled(vcpu))
+   return EMULATE_DONE;
+   } else {
+   if (kvmppc_check_vsx_disabled(vcpu))
+   return EMULATE_DONE;
+   }
+
+   if (op.vsx_flags & VSX_FPCONV)
+   vcpu->arch.mmio_sp64_extend = 1;
+
+   if (op.element_size == 8)  {
+   if (op.vsx_flags & VSX_SPLAT)
+   vcpu->arch.mmio_vsx_copy_type =
+   KVMPPC_VSX_COPY_DWORD_LOAD_DUMP;
+   else
+   vcpu->arch.mmio_vsx_copy_type =
+   KVMPPC_VSX_COPY_DWORD;
+   } else if (op.element_size == 4) {
+   if (op.vsx_flags & VSX_SPLAT)
+   vcpu->arch.mmio_vsx_copy_type =
+   KVMPPC_VSX_COPY_WORD_LOAD_DUMP;
+   else
+   vcpu->arch.mmio_vsx_copy_type =
+   KVMPPC_VSX_COPY_WORD;
+   } else
+   break;
+
+   if (size < op.element_size) {
+   /* precision convert case: lxsspx, etc */
+   vcpu->arch.mmio_vsx_copy_nums = 1;
+   io_size_each = size;
+   } else { /* lxvw4x, lxvd2x, etc */
+   vcpu->arch.mmio_vsx_copy_nums =
+   size/op.element_size;
+   io_size_each = op.element_size;
+   }
+
+   emulated = kvmppc_handle_vsx_load(run, vcpu,
+   KVM_MMIO_REG_VSX|op.reg, io_size_each,
+   1, op.type & SIGNEXT);
+   break;
+   }
+#endif
case STORE:
if (op.type & UPDATE) {
vcpu->arch.mmio_ra = op.update_reg;
@@ -248,6 +296,59 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
}
break;
 #endif
+#ifdef CONFIG_VSX
+   case STORE_VSX: {
+   /* io length for each mmio emulation */
+   int io_size_each;
+
+   if (op.vsx_flags & VSX_CHECK_VEC) {
+   if (kvmppc_check_altivec_disabled(vcpu))
+   return EMULATE_DONE;
+   } else {
+   if (kvmppc_check_vsx_disabled(vcpu))
+   return EMULATE_DONE;
+   }
+
+   /* if it is PR KVM, the FP/VEC/VSX registers need to
+* be flushed so that kvmppc_handle_store() can read
+* actual VMX vals from vcpu->arch.
+*/
+   if (!is_kvmppc_hv_enabled(vcpu->kvm))
+   vcpu->kvm->arch.kvm_ops->giveup_ext(vcpu,
+   MSR_VSX);
+
+   if (op.vsx_flags & VSX_FPCONV)
+   vcpu->arch.mmio_sp64_extend = 1;
+
+   /* stxsiwx has a special vsx_offset */
+   if ((get_op(inst) == 31) &&
+   (get_xop(inst) == OP_31_XOP_STXSIWX))
+   vcpu->arch.mmio_vsx_offset = 1;
+
+   if (op.element_size == 8)
+   vcpu->arch.mmio_vsx_copy_type =
+  

Re: [PATCH v1 1/1] misc: IBM Virtual Management Channel Driver

2018-04-25 Thread kbuild test robot
Hi Bryant,

I love your patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on v4.17-rc2 next-20180424]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Bryant-G-Ly/misc-IBM-Virtual-Management-Channel-Driver/20180424-060306
config: powerpc64-allyesconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc64 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers//misc/ibmvmc.c: In function 'ibmvmc_probe':
>> drivers//misc/ibmvmc.c:2133:5: warning: 'rc' may be used uninitialized in 
>> this function [-Wmaybe-uninitialized]
 if (rc == H_RESOURCE)
^
   drivers//misc/ibmvmc.c:2111:6: note: 'rc' was declared here
 int rc;
 ^~

vim +/rc +2133 drivers//misc/ibmvmc.c

  2097  
  2098  /**
  2099   * ibmvmc_init_crq_queue - Init CRQ Queue
  2100   *
  2101   * @adapter:crq_server_adapter struct
  2102   *
  2103   * Return:
  2104   *  0 - Success
  2105   *  Non-zero - Failure
  2106   */
  2107  static int ibmvmc_init_crq_queue(struct crq_server_adapter *adapter)
  2108  {
  2109  struct vio_dev *vdev = to_vio_dev(adapter->dev);
  2110  struct crq_queue *queue = &adapter->queue;
  2111  int rc;
  2112  int retrc;
  2113  
  2114  queue->msgs = (struct ibmvmc_crq_msg 
*)get_zeroed_page(GFP_KERNEL);
  2115  
  2116  if (!queue->msgs)
  2117  goto malloc_failed;
  2118  
  2119  queue->size = PAGE_SIZE / sizeof(*queue->msgs);
  2120  
  2121  queue->msg_token = dma_map_single(adapter->dev, queue->msgs,
  2122queue->size * 
sizeof(*queue->msgs),
  2123DMA_BIDIRECTIONAL);
  2124  
  2125  if (dma_mapping_error(adapter->dev, queue->msg_token))
  2126  goto map_failed;
  2127  
  2128  retrc = plpar_hcall_norets(H_REG_CRQ,
  2129 vdev->unit_address,
  2130 queue->msg_token, PAGE_SIZE);
  2131  retrc = rc;
  2132  
> 2133  if (rc == H_RESOURCE)
  2134  rc = ibmvmc_reset_crq_queue(adapter);
  2135  
  2136  if (rc == 2) {
  2137  dev_warn(adapter->dev, "Partner adapter not ready\n");
  2138  retrc = 0;
  2139  } else if (rc != 0) {
  2140  dev_err(adapter->dev, "Error %d opening adapter\n", rc);
  2141  goto reg_crq_failed;
  2142  }
  2143  
  2144  queue->cur = 0;
  2145  spin_lock_init(&queue->lock);
  2146  
  2147  tasklet_init(&adapter->work_task, ibmvmc_task, (unsigned 
long)adapter);
  2148  
  2149  if (request_irq(vdev->irq,
  2150  ibmvmc_handle_event,
  2151  0, "ibmvmc", (void *)adapter) != 0) {
  2152  dev_err(adapter->dev, "couldn't register irq 0x%x\n",
  2153  vdev->irq);
  2154  goto req_irq_failed;
  2155  }
  2156  
  2157  rc = vio_enable_interrupts(vdev);
  2158  if (rc != 0) {
  2159  dev_err(adapter->dev, "Error %d enabling 
interrupts!!!\n", rc);
  2160  goto req_irq_failed;
  2161  }
  2162  
  2163  return retrc;
  2164  
  2165  req_irq_failed:
  2166  /* Cannot have any work since we either never got our IRQ 
registered,
  2167   * or never got interrupts enabled
  2168   */
  2169  tasklet_kill(&adapter->work_task);
  2170  h_free_crq(vdev->unit_address);
  2171  reg_crq_failed:
  2172  dma_unmap_single(adapter->dev,
  2173   queue->msg_token,
  2174   queue->size * sizeof(*queue->msgs), 
DMA_BIDIRECTIONAL);
  2175  map_failed:
  2176  free_page((unsigned long)queue->msgs);
  2177  malloc_failed:
  2178  return -ENOMEM;
  2179  }
  2180  

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


.config.gz
Description: application/gzip


[PATCH] powerpc: Fix deadlock with multiple calls to smp_send_stop

2018-04-25 Thread Nicholas Piggin
smp_send_stop can lock up the IPI path for any subsequent calls,
because the receiving CPUs spin in their handler function. This
started becoming a problem with the addition of an smp_send_stop
call in the reboot path, because panics can reboot after doing
their own smp_send_stop.

The NMI IPI handler for a receiving CPU increments nmi_ipi_busy_count
over the handler function call, which causes the next
smp_send_nmi_ipi() caller to spin. Fix this by adding a special case
to the smp_send_stop handler to decrement the busy count, because it
will never return.

The smp_call_function path (used when !CONFIG_NMI_IPI) suffers from
a similar deadlock. This is fixed by having smp_send_stop only ever
do the smp_call_function once. This is a bit less robust, because
any other use of smp_call_function after smp_send_stop could deadlock,
but that hasn't been a problem before. Fixing that would take a bit
more code.

Fixes: f2748bdfe1573 ("powerpc/powernv: Always stop secondaries before 
reboot/shutdown")
Reported-by: Abdul Haleem 
Signed-off-by: Nicholas Piggin 
---

This supersedes "[PATCH v2] powerpc: Fix smp_send_stop NMI IPI
handling". I got the root cause for that wrong, and missed the
non-NMI case that is also affected.

 arch/powerpc/kernel/smp.c | 49 +--
 1 file changed, 42 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index e16ec7b3b427..9ca7148b5881 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -566,10 +566,35 @@ void crash_send_ipi(void (*crash_ipi_callback)(struct 
pt_regs *))
 #endif
 
 #ifdef CONFIG_NMI_IPI
-static void stop_this_cpu(struct pt_regs *regs)
-#else
+static void nmi_stop_this_cpu(struct pt_regs *regs)
+{
+   /*
+* This is a special case because it never returns, so the NMI IPI
+* handling would never mark it as done, which makes any later
+* smp_send_nmi_ipi() call spin forever. Mark it done now.
+*
+* IRQs are already hard disabled by the smp_handle_nmi_ipi.
+*/
+   nmi_ipi_lock();
+   nmi_ipi_busy_count--;
+   nmi_ipi_unlock();
+
+   /* Remove this CPU */
+   set_cpu_online(smp_processor_id(), false);
+
+   spin_begin();
+   while (1)
+   spin_cpu_relax();
+}
+
+void smp_send_stop(void)
+{
+   smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, nmi_stop_this_cpu, 100);
+}
+
+#else /* CONFIG_NMI_IPI */
+
 static void stop_this_cpu(void *dummy)
-#endif
 {
/* Remove this CPU */
set_cpu_online(smp_processor_id(), false);
@@ -582,12 +607,22 @@ static void stop_this_cpu(void *dummy)
 
 void smp_send_stop(void)
 {
-#ifdef CONFIG_NMI_IPI
-   smp_send_nmi_ipi(NMI_IPI_ALL_OTHERS, stop_this_cpu, 100);
-#else
+   static bool stopped = false;
+
+   /*
+* Prevent waiting on csd lock from a previous smp_send_stop.
+* This is racy, but in general callers try to do the right
+* thing and only fire off one smp_send_stop (e.g., see
+* kernel/panic.c)
+*/
+   if (stopped)
+   return;
+
+   stopped = true;
+
smp_call_function(stop_this_cpu, NULL, 0);
-#endif
 }
+#endif /* CONFIG_NMI_IPI */
 
 struct thread_info *current_set[NR_CPUS];
 
-- 
2.17.0



[PATCH] powerpc/xics: add missing of_node_put() in error path

2018-04-25 Thread YueHaibing
The device node obtained with of_find_compatible_node() should be
released by calling of_node_put().  But it was not released when
of_get_property() failed.

Signed-off-by: YueHaibing 
---
 arch/powerpc/sysdev/xics/xics-common.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/sysdev/xics/xics-common.c 
b/arch/powerpc/sysdev/xics/xics-common.c
index 77e864d..e54a9e6 100644
--- a/arch/powerpc/sysdev/xics/xics-common.c
+++ b/arch/powerpc/sysdev/xics/xics-common.c
@@ -448,7 +448,10 @@ static void __init xics_get_server_size(void)
return;
isize = of_get_property(np, "ibm,interrupt-server#-size", NULL);
if (!isize)
+   {
+   of_node_put(np);
return;
+   }
xics_interrupt_server_size = be32_to_cpu(*isize);
of_node_put(np);
 }
-- 
2.7.0




[GIT PULL, PATCH v4 00/16] y2038: IPC system call conversion

2018-04-25 Thread Arnd Bergmann
Hi Thomas,

This is a small update to last week's patch series, I hope I
have worked out all the remaining issues now. If nothing else
comes up, please pull into tip for 4.18. The commits are
based on top of what you already pulled into timers/core, so
you can either add these to the same branch or to a different
one.

I'll be away for three weeks starting on Sunday, so if new
issues get found, I won't be able to address them until I get
back home. I'll post another set of simpler syscall patches for
review after this, and there is at last a fourth set of those
that are not ready yet, but is available for preview at [3],
which also contains unrelated y2038 patches for random
subsystems.

  Arnd


The following changes since commit 01909974b41036a6a8d3907c66cc7b41c9a73da9:

  time: Change nanosleep to safe __kernel_* types (2018-04-19 13:32:03 +0200)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git y2038-ipc

for you to fetch changes up to 5dc0b1529d21b54aad4098874e334a52027fd16d:

  y2038: ipc: Redirect ipc(SEMTIMEDOP, ...) to compat_ksys_semtimedop 
(2018-04-20 16:20:30 +0200)


y2038: IPC system call conversion

This is a follow-up to Deepa's work on the timekeeping system calls,
providing a y2038-safe syscall API for SYSVIPC. It uses a combination
of two strategies:

For sys_msgctl, sys_semctl and sys_shmctl, I do not introduce a completely
new set of replacement system calls, but instead extend the existing
ones to return data in the reserved fields of the normal data structure.

This should be completely transparent to any existing user space, and
only after the 32-bit time_t wraps, it will make a difference in the
returned data.

libc implementations will consequently have to provide their own data
structures when they move to 64-bit time_t, and convert the structures
in user space from the ones returned by the kernel.

In contrast, mq_timedsend, mq_timedreceive and and semtimedop all do
need to change because having a libc redefine the timespec type
breaks the ABI, so with this series there will be two separate entry
points for 32-bit architectures.

There are three cases here:

- little-endian architectures (except powerpc and mips) can use
  the normal layout and just cast the data structure to the user space
  type that contains 64-bit numbers.

- parisc and sparc can do the same thing with big-endian user space

- little-endian powerpc and most big-endian architectures have
  to flip the upper and lower 32-bit halves of the time_t value in memory,
  but can otherwise keep using the normal layout

- mips and big-endian xtensa need to be more careful because
  they are not consistent in their definitions, and they have to provide
  custom libc implementations for the system calls to use 64-bit time_t.


Changes to v3:
- reworked x86 portion after discovering an old bug, submitted
  a fix for that separately.
- use consistent types in asm-generic based on feedback from
  Jeffrey Walton

Changes to v2:
- added patches for mq_timedsend, mq_timedreceive and and semtimedop
  system calls
- add asm-generic/compat.h changes to prepare for actually using those
  on 32-bit.
- fix 'make headers_install' as reported by Heiko Carstens
- fix MIPS build as reported by build bot
- Cc everyone on all patches as originally intended, not just on the
  cover letter.

Changes to v1 [1]:
- Rebased to the latest kernel (4.17-rc)
- Dropped changes for removed architectures
- Simplified the IPC code changes, based on prior work from
  both Deepa and Eric
- Fixed a few bugs that I found during rebasing, in parcular the
  sparc version was incorrect.


[1] https://lkml.org/lkml/2015/5/20/605
[2] https://lwn.net/Articles/751676/
[3] git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git y2038-next



Arnd Bergmann (16):
  y2038: asm-generic: Extend sysvipc data structures
  y2038: x86: Extend sysvipc data structures
  y2038: alpha: Remove unneeded ipc uapi header files
  y2038: ia64: Remove unneeded ipc uapi header files
  y2038: s390: Remove unneeded ipc uapi header files
  y2038: arm64: Extend sysvipc compat data structures
  y2038: mips: Extend sysvipc data structures
  y2038: parisc: Extend sysvipc data structures
  y2038: sparc: Extend sysvipc data structures
  y2038: powerpc: Extend sysvipc data structures
  y2038: xtensa: Extend sysvipc data structures
  y2038: ipc: Use ktime_get_real_seconds consistently
  y2038: ipc: Report long times to user space
  y2038: ipc: Use __kernel_timespec
  y2038: ipc: Enable COMPAT_32BIT_TIME
  y2038: ipc: Redirect ipc(SEMTIMEDOP, ...) to compat_ksys_semtimedop

Cc: linux-...@vger.kernel.org
Cc: linux-a...@vger.kernel.org
Cc: libc-al...@sourceware.org
Cc: t...@linut

[PATCH v4 01/16] y2038: asm-generic: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
Most architectures now use the asm-generic copy of the sysvipc data
structures (msqid64_ds, semid64_ds, shmid64_ds), which use 32-bit
__kernel_time_t on 32-bit architectures but have padding behind them to
allow extending the type to 64-bit.

Unfortunately, that fails on all big-endian architectures, which have the
padding on the wrong side. As so many of them get it wrong, we decided to
not bother even trying to fix it up when we introduced the asm-generic
copy. Instead we always use the padding word now to provide the upper
32 bits of the seconds value, regardless of the endianess.

A libc implementation on a typical big-endian system can deal with
this by providing its own copy of the structure definition to user
space, and swapping the two 32-bit words before returning from the
semctl/shmctl/msgctl system calls.

Note that msqid64_ds and shmid64_ds were broken on x32 since commit
f4b4aae18288 ("x86/headers/uapi: Fix __BITS_PER_LONG value for x32
builds"). I have sent a separate fix for that, but as we no longer
have to worry about x32 here, I no longer worry about x32 here and
use 'unsigned long' instead of __kernel_ulong_t.

Signed-off-by: Arnd Bergmann 
---
 include/uapi/asm-generic/msgbuf.h | 27 +-
 include/uapi/asm-generic/sembuf.h | 26 +++--
 include/uapi/asm-generic/shmbuf.h | 41 +++
 3 files changed, 49 insertions(+), 45 deletions(-)

diff --git a/include/uapi/asm-generic/msgbuf.h 
b/include/uapi/asm-generic/msgbuf.h
index fb306ebdb36f..9fe4881557cb 100644
--- a/include/uapi/asm-generic/msgbuf.h
+++ b/include/uapi/asm-generic/msgbuf.h
@@ -18,31 +18,30 @@
  * On big-endian systems, the padding is in the wrong place.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
  */
 
 struct msqid64_ds {
struct ipc64_perm msg_perm;
+#if __BITS_PER_LONG == 64
__kernel_time_t msg_stime;  /* last msgsnd time */
-#if __BITS_PER_LONG != 64
-   unsigned long   __unused1;
-#endif
__kernel_time_t msg_rtime;  /* last msgrcv time */
-#if __BITS_PER_LONG != 64
-   unsigned long   __unused2;
-#endif
__kernel_time_t msg_ctime;  /* last change time */
-#if __BITS_PER_LONG != 64
-   unsigned long   __unused3;
+#else
+   unsigned long   msg_stime;  /* last msgsnd time */
+   unsigned long   msg_stime_high;
+   unsigned long   msg_rtime;  /* last msgrcv time */
+   unsigned long   msg_rtime_high;
+   unsigned long   msg_ctime;  /* last change time */
+   unsigned long   msg_ctime_high;
 #endif
-   __kernel_ulong_t msg_cbytes;/* current number of bytes on queue */
-   __kernel_ulong_t msg_qnum;  /* number of messages in queue */
-   __kernel_ulong_t msg_qbytes;/* max number of bytes on queue */
+   unsigned long   msg_cbytes; /* current number of bytes on queue */
+   unsigned long   msg_qnum;   /* number of messages in queue */
+   unsigned longmsg_qbytes;/* max number of bytes on queue */
__kernel_pid_t msg_lspid;   /* pid of last msgsnd */
__kernel_pid_t msg_lrpid;   /* last receive pid */
-   __kernel_ulong_t __unused4;
-   __kernel_ulong_t __unused5;
+   unsigned long__unused4;
+   unsigned long__unused5;
 };
 
 #endif /* __ASM_GENERIC_MSGBUF_H */
diff --git a/include/uapi/asm-generic/sembuf.h 
b/include/uapi/asm-generic/sembuf.h
index cbf9cfe977d6..0bae010f1b64 100644
--- a/include/uapi/asm-generic/sembuf.h
+++ b/include/uapi/asm-generic/sembuf.h
@@ -13,23 +13,29 @@
  * everyone just ended up making identical copies without specific
  * optimizations, so we may just as well all use the same one.
  *
- * 64 bit architectures typically define a 64 bit __kernel_time_t,
+ * 64 bit architectures use a 64-bit __kernel_time_t here, while
+ * 32 bit architectures have a pair of unsigned long values.
  * so they do not need the first two padding words.
- * On big-endian systems, the padding is in the wrong place.
  *
- * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
- * - 2 miscellaneous 32-bit values
+ * On big-endian systems, the padding is in the wrong place for
+ * historic reasons, so user space has to reconstruct a time_t
+ * value using
+ *
+ * user_semid_ds.sem_otime = kernel_semid64_ds.sem_otime +
+ * ((long long)kernel_semid64_ds.sem_otime_high << 32)
+ *
+ * Pad space is left for 2 miscellaneous 32-bit values
  */
 struct semid64_ds {
struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#if __BITS_PER_LONG == 64
__kernel_time_t sem_otime;  /* last semop time */
-#if __BITS_PER_LONG != 64
-   unsigned long   __unused1;
-#endif
__kernel_time_t sem_ctime;  /* last change time */
-#if __BITS_PER_LONG != 64
-   unsigned long   __unused2;
+#else
+   unsigned long   sem_otime;  /* last semop time */
+   un

[PATCH v4 08/16] y2038: parisc: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
parisc, uses a nonstandard variation of the generic sysvipc
data structures, intended to have the padding moved around
so it can deal with big-endian 32-bit user space that has
64-bit time_t.

Unlike most architectures, parisc actually succeeded in
defining this right for big-endian CPUs, but as everyone else
got it wrong, we just use the same hack everywhere.

This takes just take the same approach here that we have for
the asm-generic headers and adds separate 32-bit fields for the
upper halves of the timestamps, to let libc deal with the mess
in user space.

Signed-off-by: Arnd Bergmann 
---
 arch/parisc/include/asm/compat.h  | 32 
 arch/parisc/include/uapi/asm/msgbuf.h | 33 -
 arch/parisc/include/uapi/asm/sembuf.h | 16 
 arch/parisc/include/uapi/asm/shmbuf.h | 19 ---
 4 files changed, 48 insertions(+), 52 deletions(-)

diff --git a/arch/parisc/include/asm/compat.h b/arch/parisc/include/asm/compat.h
index 0cdfec8857bd..ab8a54771507 100644
--- a/arch/parisc/include/asm/compat.h
+++ b/arch/parisc/include/asm/compat.h
@@ -138,10 +138,10 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   unsigned int __unused1;
-   compat_time_t sem_otime;
-   unsigned int __unused2;
-   compat_time_t sem_ctime;
+   unsigned int sem_otime_high;
+   unsigned int sem_otime;
+   unsigned int sem_ctime_high;
+   unsigned int sem_ctime;
compat_ulong_t sem_nsems;
compat_ulong_t __unused3;
compat_ulong_t __unused4;
@@ -149,12 +149,12 @@ struct compat_semid64_ds {
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
-   unsigned int __unused1;
-   compat_time_t msg_stime;
-   unsigned int __unused2;
-   compat_time_t msg_rtime;
-   unsigned int __unused3;
-   compat_time_t msg_ctime;
+   unsigned int msg_stime_high;
+   unsigned int msg_stime;
+   unsigned int msg_rtime_high;
+   unsigned int msg_rtime;
+   unsigned int msg_ctime_high;
+   unsigned int msg_ctime;
compat_ulong_t msg_cbytes;
compat_ulong_t msg_qnum;
compat_ulong_t msg_qbytes;
@@ -166,12 +166,12 @@ struct compat_msqid64_ds {
 
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
-   unsigned int __unused1;
-   compat_time_t shm_atime;
-   unsigned int __unused2;
-   compat_time_t shm_dtime;
-   unsigned int __unused3;
-   compat_time_t shm_ctime;
+   unsigned int shm_atime_high;
+   unsigned int shm_atime;
+   unsigned int shm_dtime_high;
+   unsigned int shm_dtime;
+   unsigned int shm_ctime_high;
+   unsigned int shm_ctime;
unsigned int __unused4;
compat_size_t shm_segsz;
compat_pid_t shm_cpid;
diff --git a/arch/parisc/include/uapi/asm/msgbuf.h 
b/arch/parisc/include/uapi/asm/msgbuf.h
index b48b810e626b..6a2e9ab2ef8d 100644
--- a/arch/parisc/include/uapi/asm/msgbuf.h
+++ b/arch/parisc/include/uapi/asm/msgbuf.h
@@ -10,31 +10,30 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
  */
 
 struct msqid64_ds {
struct ipc64_perm msg_perm;
-#if __BITS_PER_LONG != 64
-   unsigned int   __pad1;
-#endif
+#if __BITS_PER_LONG == 64
__kernel_time_t msg_stime;  /* last msgsnd time */
-#if __BITS_PER_LONG != 64
-   unsigned int   __pad2;
-#endif
__kernel_time_t msg_rtime;  /* last msgrcv time */
-#if __BITS_PER_LONG != 64
-   unsigned int   __pad3;
-#endif
__kernel_time_t msg_ctime;  /* last change time */
-   unsigned long msg_cbytes;   /* current number of bytes on queue */
-   unsigned long msg_qnum; /* number of messages in queue */
-   unsigned long msg_qbytes;   /* max number of bytes on queue */
-   __kernel_pid_t msg_lspid;   /* pid of last msgsnd */
-   __kernel_pid_t msg_lrpid;   /* last receive pid */
-   unsigned long __unused1;
-   unsigned long __unused2;
+#else
+   unsigned long   msg_stime_high;
+   unsigned long   msg_stime;  /* last msgsnd time */
+   unsigned long   msg_rtime_high;
+   unsigned long   msg_rtime;  /* last msgrcv time */
+   unsigned long   msg_ctime_high;
+   unsigned long   msg_ctime;  /* last change time */
+#endif
+   unsigned long   msg_cbytes; /* current number of bytes on queue */
+   unsigned long   msg_qnum;   /* number of messages in queue */
+   unsigned long   msg_qbytes; /* max number of bytes on queue */
+   __kernel_pid_t  msg_lspid;  /* pid of last msgsnd */
+   __kernel_pid_t  msg_lrpid;  /* last receive pid */
+   unsigned long   __unused1;
+   unsigned long   __unused2;
 };
 
 #endif /* _PARISC_MSGBUF_H */
diff --git a/arch/parisc/include/uapi/asm/sembuf.h 
b/

[PATCH v4 09/16] y2038: sparc: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
sparc, uses a nonstandard variation of the generic sysvipc
data structures, intended to have the padding moved around
so it can deal with big-endian 32-bit user space that has
64-bit time_t.

Unlike most architectures, sparc actually succeeded in
defining this right for big-endian CPUs, but as everyone else
got it wrong, we just use the same hack everywhere.

This takes just take the same approach here that we have for
the asm-generic headers and adds separate 32-bit fields for the
upper halves of the timestamps, to let libc deal with the mess
in user space.

Signed-off-by: Arnd Bergmann 
---
 arch/sparc/include/asm/compat.h  | 32 
 arch/sparc/include/uapi/asm/msgbuf.h | 22 +-
 arch/sparc/include/uapi/asm/sembuf.h | 16 +++-
 arch/sparc/include/uapi/asm/shmbuf.h | 21 +
 4 files changed, 41 insertions(+), 50 deletions(-)

diff --git a/arch/sparc/include/asm/compat.h b/arch/sparc/include/asm/compat.h
index 1910c44521e3..4eb51d2dae98 100644
--- a/arch/sparc/include/asm/compat.h
+++ b/arch/sparc/include/asm/compat.h
@@ -192,10 +192,10 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   unsigned int__pad1;
-   compat_time_t   sem_otime;
-   unsigned int__pad2;
-   compat_time_t   sem_ctime;
+   unsigned intsem_otime_high;
+   unsigned intsem_otime;
+   unsigned intsem_ctime_high;
+   unsigned intsem_ctime;
u32 sem_nsems;
u32 __unused1;
u32 __unused2;
@@ -203,12 +203,12 @@ struct compat_semid64_ds {
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
-   unsigned int__pad1;
-   compat_time_t   msg_stime;
-   unsigned int__pad2;
-   compat_time_t   msg_rtime;
-   unsigned int__pad3;
-   compat_time_t   msg_ctime;
+   unsigned intmsg_stime_high;
+   unsigned intmsg_stime;
+   unsigned intmsg_rtime_high;
+   unsigned intmsg_rtime;
+   unsigned intmsg_ctime_high;
+   unsigned intmsg_ctime;
unsigned intmsg_cbytes;
unsigned intmsg_qnum;
unsigned intmsg_qbytes;
@@ -220,12 +220,12 @@ struct compat_msqid64_ds {
 
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
-   unsigned int__pad1;
-   compat_time_t   shm_atime;
-   unsigned int__pad2;
-   compat_time_t   shm_dtime;
-   unsigned int__pad3;
-   compat_time_t   shm_ctime;
+   unsigned intshm_atime_high;
+   unsigned intshm_atime;
+   unsigned intshm_dtime_high;
+   unsigned intshm_dtime;
+   unsigned intshm_ctime_high;
+   unsigned intshm_ctime;
compat_size_t   shm_segsz;
compat_pid_tshm_cpid;
compat_pid_tshm_lpid;
diff --git a/arch/sparc/include/uapi/asm/msgbuf.h 
b/arch/sparc/include/uapi/asm/msgbuf.h
index b601c4f4d956..ffc46c211d6d 100644
--- a/arch/sparc/include/uapi/asm/msgbuf.h
+++ b/arch/sparc/include/uapi/asm/msgbuf.h
@@ -8,25 +8,22 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
  */
-
-#if defined(__sparc__) && defined(__arch64__)
-# define PADDING(x)
-#else
-# define PADDING(x) unsigned int x;
-#endif
-
-
 struct msqid64_ds {
struct ipc64_perm msg_perm;
-   PADDING(__pad1)
+#if defined(__sparc__) && defined(__arch64__)
__kernel_time_t msg_stime;  /* last msgsnd time */
-   PADDING(__pad2)
__kernel_time_t msg_rtime;  /* last msgrcv time */
-   PADDING(__pad3)
__kernel_time_t msg_ctime;  /* last change time */
+#else
+   unsigned long msg_stime_high;
+   unsigned long msg_stime;/* last msgsnd time */
+   unsigned long msg_rtime_high;
+   unsigned long msg_rtime;/* last msgrcv time */
+   unsigned long msg_ctime_high;
+   unsigned long msg_ctime;/* last change time */
+#endif
unsigned long  msg_cbytes;  /* current number of bytes on queue */
unsigned long  msg_qnum;/* number of messages in queue */
unsigned long  msg_qbytes;  /* max number of bytes on queue */
@@ -35,5 +32,4 @@ struct msqid64_ds {
unsigned long  __unused1;
unsigned long  __unused2;
 };
-#undef PADDING
 #endif /* _SPARC_MSGBUF_H */
diff --git a/arch/sparc/include/uapi/asm/sembuf.h 
b/arch/sparc/include/uapi/asm/sembuf.h
index f49b0ffa0ab8..f3d309c2e1cd 100644
--- a/arch/sparc/include/uapi/asm/sembuf.h
+++ b/arch/sparc/include/uapi/asm/sembuf.h
@@ -8,25 +8,23 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
  */
-#if defined(__sparc__) && defined(__arch64__)
-# define PADDING(x)
-#else
-# define PADDING(x) unsigned in

[PATCH v4 11/16] y2038: xtensa: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
xtensa, uses a nonstandard variation of the generic sysvipc
data structures, intended to have the padding moved around
so it can deal with big-endian 32-bit user space that has
64-bit time_t.

xtensa tries hard to define the structures so they work
in both big-endian and little-endian systems with padding
on the right side.
However, they only succeeded for for two of the three structures,
and their struct shmid64_ds ended up being defined in two
identical copies, and the big-endian one is wrong.

This takes just take the same approach here that we have for
the asm-generic headers and adds separate 32-bit fields for the
upper halves of the timestamps, to let libc deal with the mess
in user space.

Signed-off-by: Arnd Bergmann 
---
 arch/xtensa/include/uapi/asm/msgbuf.h | 25 ---
 arch/xtensa/include/uapi/asm/sembuf.h | 17 
 arch/xtensa/include/uapi/asm/shmbuf.h | 37 ---
 3 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/arch/xtensa/include/uapi/asm/msgbuf.h 
b/arch/xtensa/include/uapi/asm/msgbuf.h
index 36e2e103ca38..d6915e9f071c 100644
--- a/arch/xtensa/include/uapi/asm/msgbuf.h
+++ b/arch/xtensa/include/uapi/asm/msgbuf.h
@@ -7,7 +7,6 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
  *
  * This file is subject to the terms and conditions of the GNU General
@@ -21,19 +20,19 @@
 struct msqid64_ds {
struct ipc64_perm msg_perm;
 #ifdef __XTENSA_EB__
-   unsigned int__unused1;
-   __kernel_time_t msg_stime;  /* last msgsnd time */
-   unsigned int__unused2;
-   __kernel_time_t msg_rtime;  /* last msgrcv time */
-   unsigned int__unused3;
-   __kernel_time_t msg_ctime;  /* last change time */
+   unsigned long  msg_stime_high;
+   unsigned long  msg_stime;   /* last msgsnd time */
+   unsigned long  msg_rtime_high;
+   unsigned long  msg_rtime;   /* last msgrcv time */
+   unsigned long  msg_ctime_high;
+   unsigned long  msg_ctime;   /* last change time */
 #elif defined(__XTENSA_EL__)
-   __kernel_time_t msg_stime;  /* last msgsnd time */
-   unsigned int__unused1;
-   __kernel_time_t msg_rtime;  /* last msgrcv time */
-   unsigned int__unused2;
-   __kernel_time_t msg_ctime;  /* last change time */
-   unsigned int__unused3;
+   unsigned long  msg_stime;   /* last msgsnd time */
+   unsigned long  msg_stime_high;
+   unsigned long  msg_rtime;   /* last msgrcv time */
+   unsigned long  msg_rtime_high;
+   unsigned long  msg_ctime;   /* last change time */
+   unsigned long  msg_ctime_high;
 #else
 # error processor byte order undefined!
 #endif
diff --git a/arch/xtensa/include/uapi/asm/sembuf.h 
b/arch/xtensa/include/uapi/asm/sembuf.h
index f61b6331a10c..09f348d643f1 100644
--- a/arch/xtensa/include/uapi/asm/sembuf.h
+++ b/arch/xtensa/include/uapi/asm/sembuf.h
@@ -14,7 +14,6 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
  *
  */
@@ -27,15 +26,15 @@
 struct semid64_ds {
struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
 #ifdef __XTENSA_EL__
-   __kernel_time_t sem_otime;  /* last semop time */
-   unsigned long   __unused1;
-   __kernel_time_t sem_ctime;  /* last change time */
-   unsigned long   __unused2;
+   unsigned long   sem_otime;  /* last semop time */
+   unsigned long   sem_otime_high;
+   unsigned long   sem_ctime;  /* last change time */
+   unsigned long   sem_ctime_high;
 #else
-   unsigned long   __unused1;
-   __kernel_time_t sem_otime;  /* last semop time */
-   unsigned long   __unused2;
-   __kernel_time_t sem_ctime;  /* last change time */
+   unsigned long   sem_otime_high;
+   unsigned long   sem_otime;  /* last semop time */
+   unsigned long   sem_ctime_high;
+   unsigned long   sem_ctime;  /* last change time */
 #endif
unsigned long   sem_nsems;  /* no. of semaphores in array */
unsigned long   __unused3;
diff --git a/arch/xtensa/include/uapi/asm/shmbuf.h 
b/arch/xtensa/include/uapi/asm/shmbuf.h
index 26550bdc8430..554a57a6a90f 100644
--- a/arch/xtensa/include/uapi/asm/shmbuf.h
+++ b/arch/xtensa/include/uapi/asm/shmbuf.h
@@ -4,10 +4,10 @@
  *
  * The shmid64_ds structure for Xtensa architecture.
  * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
+ * between kernel and user space, but the padding is on the wrong
+ * side for big-endian xtensa, for historic reasons.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit 

[PATCH v4 02/16] y2038: x86: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
This extends the x86 copy of the sysvipc data structures to deal with
32-bit user space that has 64-bit time_t and wants to see timestamps
beyond 2038.

Fortunately, x86 has padding for this purpose in all the data structures,
so we can just add extra fields. With msgid64_ds and shmid64_ds, the
data structure is identical to the asm-generic version, which we have
already extended.

For some reason however, the 64-bit version of semid64_ds ended up with
extra padding, so I'm implementing the same approach as the asm-generic
version here, by using separate fields for the upper and lower halves
of the two timestamps.

Signed-off-by: Arnd Bergmann 
---
 arch/x86/include/asm/compat.h  | 32 
 arch/x86/include/uapi/asm/sembuf.h | 11 ++-
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
index 7cd314b71c51..fb97cf7c4137 100644
--- a/arch/x86/include/asm/compat.h
+++ b/arch/x86/include/asm/compat.h
@@ -134,10 +134,10 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   compat_time_t  sem_otime;
-   compat_ulong_t __unused1;
-   compat_time_t  sem_ctime;
-   compat_ulong_t __unused2;
+   compat_ulong_t sem_otime;
+   compat_ulong_t sem_otime_high;
+   compat_ulong_t sem_ctime;
+   compat_ulong_t sem_ctime_high;
compat_ulong_t sem_nsems;
compat_ulong_t __unused3;
compat_ulong_t __unused4;
@@ -145,12 +145,12 @@ struct compat_semid64_ds {
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
-   compat_time_t  msg_stime;
-   compat_ulong_t __unused1;
-   compat_time_t  msg_rtime;
-   compat_ulong_t __unused2;
-   compat_time_t  msg_ctime;
-   compat_ulong_t __unused3;
+   compat_ulong_t msg_stime;
+   compat_ulong_t msg_stime_high;
+   compat_ulong_t msg_rtime;
+   compat_ulong_t msg_rtime_high;
+   compat_ulong_t msg_ctime;
+   compat_ulong_t msg_ctime_high;
compat_ulong_t msg_cbytes;
compat_ulong_t msg_qnum;
compat_ulong_t msg_qbytes;
@@ -163,12 +163,12 @@ struct compat_msqid64_ds {
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
compat_size_t  shm_segsz;
-   compat_time_t  shm_atime;
-   compat_ulong_t __unused1;
-   compat_time_t  shm_dtime;
-   compat_ulong_t __unused2;
-   compat_time_t  shm_ctime;
-   compat_ulong_t __unused3;
+   compat_ulong_t shm_atime;
+   compat_ulong_t shm_atime_high;
+   compat_ulong_t shm_dtime;
+   compat_ulong_t shm_dtime_high;
+   compat_ulong_t shm_ctime;
+   compat_ulong_t shm_ctime_high;
compat_pid_t   shm_cpid;
compat_pid_t   shm_lpid;
compat_ulong_t shm_nattch;
diff --git a/arch/x86/include/uapi/asm/sembuf.h 
b/arch/x86/include/uapi/asm/sembuf.h
index cabd7476bd6c..89de6cd9f0a7 100644
--- a/arch/x86/include/uapi/asm/sembuf.h
+++ b/arch/x86/include/uapi/asm/sembuf.h
@@ -8,15 +8,24 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
  * - 2 miscellaneous 32-bit values
+ *
+ * x86_64 and x32 incorrectly added padding here, so the structures
+ * are still incompatible with the padding on x86.
  */
 struct semid64_ds {
struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
+#ifdef __i386__
+   unsigned long   sem_otime;  /* last semop time */
+   unsigned long   sem_otime_high;
+   unsigned long   sem_ctime;  /* last change time */
+   unsigned long   sem_ctime_high;
+#else
__kernel_time_t sem_otime;  /* last semop time */
__kernel_ulong_t __unused1;
__kernel_time_t sem_ctime;  /* last change time */
__kernel_ulong_t __unused2;
+#endif
__kernel_ulong_t sem_nsems; /* no. of semaphores in array */
__kernel_ulong_t __unused3;
__kernel_ulong_t __unused4;
-- 
2.9.0



[PATCH v4 12/16] y2038: ipc: Use ktime_get_real_seconds consistently

2018-04-25 Thread Arnd Bergmann
In some places, we still used get_seconds() instead of
ktime_get_real_seconds(), and I'm changing the remaining ones now to
all use ktime_get_real_seconds() so we use the full available range for
timestamps instead of overflowing the 'unsigned long' return value in
year 2106 on 32-bit kernels.

Signed-off-by: Arnd Bergmann 
---
 ipc/msg.c | 6 +++---
 ipc/sem.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/ipc/msg.c b/ipc/msg.c
index 56fd1c73eedc..574f76c9a2ff 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -758,7 +758,7 @@ static inline int pipelined_send(struct msg_queue *msq, 
struct msg_msg *msg,
WRITE_ONCE(msr->r_msg, ERR_PTR(-E2BIG));
} else {
ipc_update_pid(&msq->q_lrpid, 
task_pid(msr->r_tsk));
-   msq->q_rtime = get_seconds();
+   msq->q_rtime = ktime_get_real_seconds();
 
wake_q_add(wake_q, msr->r_tsk);
WRITE_ONCE(msr->r_msg, msg);
@@ -859,7 +859,7 @@ static long do_msgsnd(int msqid, long mtype, void __user 
*mtext,
}
 
ipc_update_pid(&msq->q_lspid, task_tgid(current));
-   msq->q_stime = get_seconds();
+   msq->q_stime = ktime_get_real_seconds();
 
if (!pipelined_send(msq, msg, &wake_q)) {
/* no one is waiting for this message, enqueue it */
@@ -1087,7 +1087,7 @@ static long do_msgrcv(int msqid, void __user *buf, size_t 
bufsz, long msgtyp, in
 
list_del(&msg->m_list);
msq->q_qnum--;
-   msq->q_rtime = get_seconds();
+   msq->q_rtime = ktime_get_real_seconds();
ipc_update_pid(&msq->q_lrpid, task_tgid(current));
msq->q_cbytes -= msg->m_ts;
atomic_sub(msg->m_ts, &ns->msg_bytes);
diff --git a/ipc/sem.c b/ipc/sem.c
index 06be75d9217a..c6a8a971769d 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -104,7 +104,7 @@ struct sem {
/* that alter the semaphore */
struct list_head pending_const; /* pending single-sop operations */
/* that do not alter the semaphore*/
-   time_t  sem_otime;  /* candidate for sem_otime */
+   time64_t sem_otime; /* candidate for sem_otime */
 } cacheline_aligned_in_smp;
 
 /* One sem_array data structure for each set of semaphores in the system. */
@@ -984,10 +984,10 @@ static int update_queue(struct sem_array *sma, int 
semnum, struct wake_q_head *w
 static void set_semotime(struct sem_array *sma, struct sembuf *sops)
 {
if (sops == NULL) {
-   sma->sems[0].sem_otime = get_seconds();
+   sma->sems[0].sem_otime = ktime_get_real_seconds();
} else {
sma->sems[sops[0].sem_num].sem_otime =
-   get_seconds();
+   ktime_get_real_seconds();
}
 }
 
-- 
2.9.0



[PATCH v4 13/16] y2038: ipc: Report long times to user space

2018-04-25 Thread Arnd Bergmann
The shmid64_ds/semid64_ds/msqid64_ds data structures have been extended
to contain extra fields for storing the upper bits of the time stamps,
this patch does the other half of the job and and fills the new fields on
32-bit architectures as well as 32-bit tasks running on a 64-bit kernel
in compat mode.

There should be no change for native 64-bit tasks.

Signed-off-by: Arnd Bergmann 
---
 ipc/msg.c | 14 +++---
 ipc/sem.c | 14 +++---
 ipc/shm.c | 14 +++---
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/ipc/msg.c b/ipc/msg.c
index 574f76c9a2ff..3b6545302598 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -537,6 +537,11 @@ static int msgctl_stat(struct ipc_namespace *ns, int msqid,
p->msg_stime  = msq->q_stime;
p->msg_rtime  = msq->q_rtime;
p->msg_ctime  = msq->q_ctime;
+#ifndef CONFIG_64BIT
+   p->msg_stime_high = msq->q_stime >> 32;
+   p->msg_rtime_high = msq->q_rtime >> 32;
+   p->msg_ctime_high = msq->q_ctime >> 32;
+#endif
p->msg_cbytes = msq->q_cbytes;
p->msg_qnum   = msq->q_qnum;
p->msg_qbytes = msq->q_qbytes;
@@ -646,9 +651,12 @@ static int copy_compat_msqid_to_user(void __user *buf, 
struct msqid64_ds *in,
struct compat_msqid64_ds v;
memset(&v, 0, sizeof(v));
to_compat_ipc64_perm(&v.msg_perm, &in->msg_perm);
-   v.msg_stime = in->msg_stime;
-   v.msg_rtime = in->msg_rtime;
-   v.msg_ctime = in->msg_ctime;
+   v.msg_stime  = lower_32_bits(in->msg_stime);
+   v.msg_stime_high = upper_32_bits(in->msg_stime);
+   v.msg_rtime  = lower_32_bits(in->msg_rtime);
+   v.msg_rtime_high = upper_32_bits(in->msg_rtime);
+   v.msg_ctime  = lower_32_bits(in->msg_ctime);
+   v.msg_ctime_high = upper_32_bits(in->msg_ctime);
v.msg_cbytes = in->msg_cbytes;
v.msg_qnum = in->msg_qnum;
v.msg_qbytes = in->msg_qbytes;
diff --git a/ipc/sem.c b/ipc/sem.c
index c6a8a971769d..8935cd8cf166 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1214,6 +1214,7 @@ static int semctl_stat(struct ipc_namespace *ns, int 
semid,
 int cmd, struct semid64_ds *semid64)
 {
struct sem_array *sma;
+   time64_t semotime;
int id = 0;
int err;
 
@@ -1257,8 +1258,13 @@ static int semctl_stat(struct ipc_namespace *ns, int 
semid,
}
 
kernel_to_ipc64_perm(&sma->sem_perm, &semid64->sem_perm);
-   semid64->sem_otime = get_semotime(sma);
+   semotime = get_semotime(sma);
+   semid64->sem_otime = semotime;
semid64->sem_ctime = sma->sem_ctime;
+#ifndef CONFIG_64BIT
+   semid64->sem_otime_high = semotime >> 32;
+   semid64->sem_ctime_high = sma->sem_ctime >> 32;
+#endif
semid64->sem_nsems = sma->sem_nsems;
 
ipc_unlock_object(&sma->sem_perm);
@@ -1704,8 +1710,10 @@ static int copy_compat_semid_to_user(void __user *buf, 
struct semid64_ds *in,
struct compat_semid64_ds v;
memset(&v, 0, sizeof(v));
to_compat_ipc64_perm(&v.sem_perm, &in->sem_perm);
-   v.sem_otime = in->sem_otime;
-   v.sem_ctime = in->sem_ctime;
+   v.sem_otime  = lower_32_bits(in->sem_otime);
+   v.sem_otime_high = upper_32_bits(in->sem_otime);
+   v.sem_ctime  = lower_32_bits(in->sem_ctime);
+   v.sem_ctime_high = upper_32_bits(in->sem_ctime);
v.sem_nsems = in->sem_nsems;
return copy_to_user(buf, &v, sizeof(v));
} else {
diff --git a/ipc/shm.c b/ipc/shm.c
index 3cf48988d68c..0075990338f4 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1002,6 +1002,11 @@ static int shmctl_stat(struct ipc_namespace *ns, int 
shmid,
tbuf->shm_atime = shp->shm_atim;
tbuf->shm_dtime = shp->shm_dtim;
tbuf->shm_ctime = shp->shm_ctim;
+#ifndef CONFIG_64BIT
+   tbuf->shm_atime_high = shp->shm_atim >> 32;
+   tbuf->shm_dtime_high = shp->shm_dtim >> 32;
+   tbuf->shm_ctime_high = shp->shm_ctim >> 32;
+#endif
tbuf->shm_cpid  = pid_vnr(shp->shm_cprid);
tbuf->shm_lpid  = pid_vnr(shp->shm_lprid);
tbuf->shm_nattch = shp->shm_nattch;
@@ -1233,9 +1238,12 @@ static int copy_compat_shmid_to_user(void __user *buf, 
struct shmid64_ds *in,
struct compat_shmid64_ds v;
memset(&v, 0, sizeof(v));
to_compat_ipc64_perm(&v.shm_perm, &in->shm_perm);
-   v.shm_atime = in->shm_atime;
-   v.shm_dtime = in->shm_dtime;
-   v.shm_ctime = in->shm_ctime;
+   v.shm_atime  = lower_32_bits(in->shm_atime);
+   v.shm_atime_high = upper_32_bits(in->shm_atime);
+   v.shm_dtime  = lower_32_bits(in->shm_dtime);
+   v.shm_dtime_high = upper_32_bits(in->shm_dtime);
+   v.shm_ctime  

[PATCH v4 03/16] y2038: alpha: Remove unneeded ipc uapi header files

2018-04-25 Thread Arnd Bergmann
The alpha ipcbuf/msgbuf/sembuf/shmbuf header files are all identical
to the version from asm-generic.

This patch removes the files and replaces them with 'generic-y'
statements as part of the y2038 series. Since there is no 32-bit
syscall support for alpha, we don't need the other changes, but
it's good to have clean this up anyway.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/include/uapi/asm/Kbuild   |  4 
 arch/alpha/include/uapi/asm/ipcbuf.h |  2 --
 arch/alpha/include/uapi/asm/msgbuf.h | 28 --
 arch/alpha/include/uapi/asm/sembuf.h | 23 -
 arch/alpha/include/uapi/asm/shmbuf.h | 39 
 5 files changed, 4 insertions(+), 92 deletions(-)
 delete mode 100644 arch/alpha/include/uapi/asm/ipcbuf.h
 delete mode 100644 arch/alpha/include/uapi/asm/msgbuf.h
 delete mode 100644 arch/alpha/include/uapi/asm/sembuf.h
 delete mode 100644 arch/alpha/include/uapi/asm/shmbuf.h

diff --git a/arch/alpha/include/uapi/asm/Kbuild 
b/arch/alpha/include/uapi/asm/Kbuild
index 9afaba5e5503..1a5b75310cf4 100644
--- a/arch/alpha/include/uapi/asm/Kbuild
+++ b/arch/alpha/include/uapi/asm/Kbuild
@@ -2,4 +2,8 @@
 include include/uapi/asm-generic/Kbuild.asm
 
 generic-y += bpf_perf_event.h
+generic-y += ipcbuf.h
+generic-y += msgbuf.h
 generic-y += poll.h
+generic-y += sembuf.h
+generic-y += shmbuf.h
diff --git a/arch/alpha/include/uapi/asm/ipcbuf.h 
b/arch/alpha/include/uapi/asm/ipcbuf.h
deleted file mode 100644
index 90d6445a14df..
--- a/arch/alpha/include/uapi/asm/ipcbuf.h
+++ /dev/null
@@ -1,2 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#include 
diff --git a/arch/alpha/include/uapi/asm/msgbuf.h 
b/arch/alpha/include/uapi/asm/msgbuf.h
deleted file mode 100644
index 8c5d4d8c1b16..
--- a/arch/alpha/include/uapi/asm/msgbuf.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ALPHA_MSGBUF_H
-#define _ALPHA_MSGBUF_H
-
-/* 
- * The msqid64_ds structure for alpha architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 2 miscellaneous 64-bit values
- */
-
-struct msqid64_ds {
-   struct ipc64_perm msg_perm;
-   __kernel_time_t msg_stime;  /* last msgsnd time */
-   __kernel_time_t msg_rtime;  /* last msgrcv time */
-   __kernel_time_t msg_ctime;  /* last change time */
-   unsigned long  msg_cbytes;  /* current number of bytes on queue */
-   unsigned long  msg_qnum;/* number of messages in queue */
-   unsigned long  msg_qbytes;  /* max number of bytes on queue */
-   __kernel_pid_t msg_lspid;   /* pid of last msgsnd */
-   __kernel_pid_t msg_lrpid;   /* last receive pid */
-   unsigned long  __unused1;
-   unsigned long  __unused2;
-};
-
-#endif /* _ALPHA_MSGBUF_H */
diff --git a/arch/alpha/include/uapi/asm/sembuf.h 
b/arch/alpha/include/uapi/asm/sembuf.h
deleted file mode 100644
index f28ffa668b2f..
--- a/arch/alpha/include/uapi/asm/sembuf.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ALPHA_SEMBUF_H
-#define _ALPHA_SEMBUF_H
-
-/* 
- * The semid64_ds structure for alpha architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 2 miscellaneous 64-bit values
- */
-
-struct semid64_ds {
-   struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
-   __kernel_time_t sem_otime;  /* last semop time */
-   __kernel_time_t sem_ctime;  /* last change time */
-   unsigned long   sem_nsems;  /* no. of semaphores in array */
-   unsigned long   __unused1;
-   unsigned long   __unused2;
-};
-
-#endif /* _ALPHA_SEMBUF_H */
diff --git a/arch/alpha/include/uapi/asm/shmbuf.h 
b/arch/alpha/include/uapi/asm/shmbuf.h
deleted file mode 100644
index 7e041ca2eb40..
--- a/arch/alpha/include/uapi/asm/shmbuf.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ALPHA_SHMBUF_H
-#define _ALPHA_SHMBUF_H
-
-/* 
- * The shmid64_ds structure for alpha architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 2 miscellaneous 64-bit values
- */
-
-struct shmid64_ds {
-   struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
-   __kernel_time_t shm_atime;  /* last attach time */
-   __kernel_time_t shm_dtime;  /* last detach time */
-   __kernel_time_t shm_ctime;  /* last change time */
-   __kernel_pid_t  shm_cpid;   /* pid of creator */
-   __kerne

[PATCH v4 04/16] y2038: ia64: Remove unneeded ipc uapi header files

2018-04-25 Thread Arnd Bergmann
The ia64 ipcbuf/msgbuf/sembuf/shmbuf header files are all identical
to the version from asm-generic.

This patch removes the files and replaces them with 'generic-y'
statements as part of the y2038 changes. While ia64 no longer has
a compat mode and doesn't need the file any more, it seem nicer
to clean this up anyway.

Signed-off-by: Arnd Bergmann 
---
 arch/ia64/include/uapi/asm/Kbuild   |  4 
 arch/ia64/include/uapi/asm/ipcbuf.h |  2 --
 arch/ia64/include/uapi/asm/msgbuf.h | 28 --
 arch/ia64/include/uapi/asm/sembuf.h | 23 --
 arch/ia64/include/uapi/asm/shmbuf.h | 39 -
 5 files changed, 4 insertions(+), 92 deletions(-)
 delete mode 100644 arch/ia64/include/uapi/asm/ipcbuf.h
 delete mode 100644 arch/ia64/include/uapi/asm/msgbuf.h
 delete mode 100644 arch/ia64/include/uapi/asm/sembuf.h
 delete mode 100644 arch/ia64/include/uapi/asm/shmbuf.h

diff --git a/arch/ia64/include/uapi/asm/Kbuild 
b/arch/ia64/include/uapi/asm/Kbuild
index c0527cfc48f0..3982e673e967 100644
--- a/arch/ia64/include/uapi/asm/Kbuild
+++ b/arch/ia64/include/uapi/asm/Kbuild
@@ -2,5 +2,9 @@
 include include/uapi/asm-generic/Kbuild.asm
 
 generic-y += bpf_perf_event.h
+generic-y += ipcbuf.h
 generic-y += kvm_para.h
+generic-y += msgbuf.h
 generic-y += poll.h
+generic-y += sembuf.h
+generic-y += shmbuf.h
diff --git a/arch/ia64/include/uapi/asm/ipcbuf.h 
b/arch/ia64/include/uapi/asm/ipcbuf.h
deleted file mode 100644
index 90d6445a14df..
--- a/arch/ia64/include/uapi/asm/ipcbuf.h
+++ /dev/null
@@ -1,2 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#include 
diff --git a/arch/ia64/include/uapi/asm/msgbuf.h 
b/arch/ia64/include/uapi/asm/msgbuf.h
deleted file mode 100644
index aa25df92d9dc..
--- a/arch/ia64/include/uapi/asm/msgbuf.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ASM_IA64_MSGBUF_H
-#define _ASM_IA64_MSGBUF_H
-
-/*
- * The msqid64_ds structure for IA-64 architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 2 miscellaneous 64-bit values
- */
-
-struct msqid64_ds {
-   struct ipc64_perm msg_perm;
-   __kernel_time_t msg_stime;  /* last msgsnd time */
-   __kernel_time_t msg_rtime;  /* last msgrcv time */
-   __kernel_time_t msg_ctime;  /* last change time */
-   unsigned long  msg_cbytes;  /* current number of bytes on queue */
-   unsigned long  msg_qnum;/* number of messages in queue */
-   unsigned long  msg_qbytes;  /* max number of bytes on queue */
-   __kernel_pid_t msg_lspid;   /* pid of last msgsnd */
-   __kernel_pid_t msg_lrpid;   /* last receive pid */
-   unsigned long  __unused1;
-   unsigned long  __unused2;
-};
-
-#endif /* _ASM_IA64_MSGBUF_H */
diff --git a/arch/ia64/include/uapi/asm/sembuf.h 
b/arch/ia64/include/uapi/asm/sembuf.h
deleted file mode 100644
index 6ed058760afc..
--- a/arch/ia64/include/uapi/asm/sembuf.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ASM_IA64_SEMBUF_H
-#define _ASM_IA64_SEMBUF_H
-
-/*
- * The semid64_ds structure for IA-64 architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 2 miscellaneous 64-bit values
- */
-
-struct semid64_ds {
-   struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
-   __kernel_time_t sem_otime;  /* last semop time */
-   __kernel_time_t sem_ctime;  /* last change time */
-   unsigned long   sem_nsems;  /* no. of semaphores in array */
-   unsigned long   __unused1;
-   unsigned long   __unused2;
-};
-
-#endif /* _ASM_IA64_SEMBUF_H */
diff --git a/arch/ia64/include/uapi/asm/shmbuf.h 
b/arch/ia64/include/uapi/asm/shmbuf.h
deleted file mode 100644
index 6ef57cb70dee..
--- a/arch/ia64/include/uapi/asm/shmbuf.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ASM_IA64_SHMBUF_H
-#define _ASM_IA64_SHMBUF_H
-
-/*
- * The shmid64_ds structure for IA-64 architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 2 miscellaneous 64-bit values
- */
-
-struct shmid64_ds {
-   struct ipc64_perm   shm_perm;   /* operation perms */
-   size_t  shm_segsz;  /* size of segment (bytes) */
-   __kernel_time_t shm_atime;  /* last attach time */
-   __kernel_time_t shm_dtime;  /* last detach time */
-   __kernel_time_t shm_ctime;  /* last change time */
-   __kernel_pid_t  shm_cpid;   /* pid of creator */
-  

[PATCH v4 10/16] y2038: powerpc: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
powerpc, uses a nonstandard variation of the generic sysvipc
data structures, intended to have the padding moved around
so it can deal with big-endian 32-bit user space that has
64-bit time_t.

powerpc has the same definition as parisc and sparc, but now also
supports little-endian mode, which is now wrong because the
padding is made for big-endian user space.

This takes just take the same approach here that we have for
the asm-generic headers and adds separate 32-bit fields for the
upper halves of the timestamps, to let libc deal with the mess
in user space.

Signed-off-by: Arnd Bergmann 
---
 arch/powerpc/include/asm/compat.h  | 32 
 arch/powerpc/include/uapi/asm/msgbuf.h | 18 +-
 arch/powerpc/include/uapi/asm/sembuf.h | 14 +++---
 arch/powerpc/include/uapi/asm/shmbuf.h | 19 ---
 4 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/arch/powerpc/include/asm/compat.h 
b/arch/powerpc/include/asm/compat.h
index b4773c81f7d5..85c8af2bb272 100644
--- a/arch/powerpc/include/asm/compat.h
+++ b/arch/powerpc/include/asm/compat.h
@@ -162,10 +162,10 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   unsigned int __unused1;
-   compat_time_t sem_otime;
-   unsigned int __unused2;
-   compat_time_t sem_ctime;
+   unsigned int sem_otime_high;
+   unsigned int sem_otime;
+   unsigned int sem_ctime_high;
+   unsigned int sem_ctime;
compat_ulong_t sem_nsems;
compat_ulong_t __unused3;
compat_ulong_t __unused4;
@@ -173,12 +173,12 @@ struct compat_semid64_ds {
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
-   unsigned int __unused1;
-   compat_time_t msg_stime;
-   unsigned int __unused2;
-   compat_time_t msg_rtime;
-   unsigned int __unused3;
-   compat_time_t msg_ctime;
+   unsigned int msg_stime_high;
+   unsigned int msg_stime;
+   unsigned int msg_rtime_high;
+   unsigned int msg_rtime;
+   unsigned int msg_ctime_high;
+   unsigned int msg_ctime;
compat_ulong_t msg_cbytes;
compat_ulong_t msg_qnum;
compat_ulong_t msg_qbytes;
@@ -190,12 +190,12 @@ struct compat_msqid64_ds {
 
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
-   unsigned int __unused1;
-   compat_time_t shm_atime;
-   unsigned int __unused2;
-   compat_time_t shm_dtime;
-   unsigned int __unused3;
-   compat_time_t shm_ctime;
+   unsigned int shm_atime_high;
+   unsigned int shm_atime;
+   unsigned int shm_dtime_high;
+   unsigned int shm_dtime;
+   unsigned int shm_ctime_high;
+   unsigned int shm_ctime;
unsigned int __unused4;
compat_size_t shm_segsz;
compat_pid_t shm_cpid;
diff --git a/arch/powerpc/include/uapi/asm/msgbuf.h 
b/arch/powerpc/include/uapi/asm/msgbuf.h
index 65beb0942500..2b1b37797a47 100644
--- a/arch/powerpc/include/uapi/asm/msgbuf.h
+++ b/arch/powerpc/include/uapi/asm/msgbuf.h
@@ -10,18 +10,18 @@
 
 struct msqid64_ds {
struct ipc64_perm msg_perm;
-#ifndef __powerpc64__
-   unsigned int__unused1;
-#endif
+#ifdef __powerpc64__
__kernel_time_t msg_stime;  /* last msgsnd time */
-#ifndef __powerpc64__
-   unsigned int__unused2;
-#endif
__kernel_time_t msg_rtime;  /* last msgrcv time */
-#ifndef __powerpc64__
-   unsigned int__unused3;
-#endif
__kernel_time_t msg_ctime;  /* last change time */
+#else
+   unsigned long  msg_stime_high;
+   unsigned long  msg_stime;   /* last msgsnd time */
+   unsigned long  msg_rtime_high;
+   unsigned long  msg_rtime;   /* last msgrcv time */
+   unsigned long  msg_ctime_high;
+   unsigned long  msg_ctime;   /* last change time */
+#endif
unsigned long  msg_cbytes;  /* current number of bytes on queue */
unsigned long  msg_qnum;/* number of messages in queue */
unsigned long  msg_qbytes;  /* max number of bytes on queue */
diff --git a/arch/powerpc/include/uapi/asm/sembuf.h 
b/arch/powerpc/include/uapi/asm/sembuf.h
index 8f393d60f02d..3f60946f77e3 100644
--- a/arch/powerpc/include/uapi/asm/sembuf.h
+++ b/arch/powerpc/include/uapi/asm/sembuf.h
@@ -15,20 +15,20 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
- * - 2 miscellaneous 32-bit values
+ * - 2 miscellaneous 32/64-bit values
  */
 
 struct semid64_ds {
struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
 #ifndef __powerpc64__
-   unsigned long   __unused1;
-#endif
+   unsigned long   sem_otime_high;
+   unsigned long   sem_otime;  /* last semop time */
+   unsigned long   sem_ctime_high;
+   unsigned long   sem_ctime;  /* last change time */
+#else
__kernel_time_t sem_otime;  /* last semop time */
-#ifnd

[PATCH v4 16/16] y2038: ipc: Redirect ipc(SEMTIMEDOP, ...) to compat_ksys_semtimedop

2018-04-25 Thread Arnd Bergmann
32-bit architectures implementing 64BIT_TIME and COMPAT_32BIT_TIME
need to have the traditional semtimedop() behavior with 32-bit timestamps
for sys_ipc() by calling compat_ksys_semtimedop(), while those that
are not yet converted need to keep using ksys_semtimedop() like
64-bit architectures do.

Note that I chose to not implement a new SEMTIMEDOP64 function that
corresponds to the new sys_semtimedop() with 64-bit timeouts. The reason
here is that sys_ipc() should no longer be used for new system calls,
and libc should just call the semtimedop syscall directly.

One open question remain to whether we want to completely avoid the
sys_ipc() system call for architectures that do not yet have all the
individual calls as they get converted to 64-bit time_t. Doing that
would require adding several extra system calls on m68k, mips, powerpc,
s390, sh, sparc, and x86-32.

Signed-off-by: Arnd Bergmann 
---
 ipc/syscall.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/ipc/syscall.c b/ipc/syscall.c
index 77a883ef2eca..65d405f1ba0c 100644
--- a/ipc/syscall.c
+++ b/ipc/syscall.c
@@ -30,9 +30,14 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, 
unsigned long, second,
return ksys_semtimedop(first, (struct sembuf __user *)ptr,
   second, NULL);
case SEMTIMEDOP:
-   return ksys_semtimedop(first, (struct sembuf __user *)ptr,
-  second,
-  (const struct timespec __user *)fifth);
+   if (IS_ENABLED(CONFIG_64BIT) || !IS_ENABLED(CONFIG_64BIT_TIME))
+   return ksys_semtimedop(first, ptr, second,
+   (const struct __kernel_timespec __user *)fifth);
+   else if (IS_ENABLED(CONFIG_COMPAT_32BIT_TIME))
+   return compat_ksys_semtimedop(first, ptr, second,
+   (const struct compat_timespec __user *)fifth);
+   else
+   return -ENOSYS;
 
case SEMGET:
return ksys_semget(first, second, third);
@@ -130,6 +135,8 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, 
second,
/* struct sembuf is the same on 32 and 64bit :)) */
return ksys_semtimedop(first, compat_ptr(ptr), second, NULL);
case SEMTIMEDOP:
+   if (!IS_ENABLED(CONFIG_COMPAT_32BIT_TIME))
+   return -ENOSYS;
return compat_ksys_semtimedop(first, compat_ptr(ptr), second,
compat_ptr(fifth));
case SEMGET:
-- 
2.9.0



[PATCH v4 15/16] y2038: ipc: Enable COMPAT_32BIT_TIME

2018-04-25 Thread Arnd Bergmann
Three ipc syscalls (mq_timedsend, mq_timedreceive and and semtimedop)
take a timespec argument. After we move 32-bit architectures over to
useing 64-bit time_t based syscalls, we need seperate entry points for
the old 32-bit based interfaces.

This changes the #ifdef guards for the existing 32-bit compat syscalls
to check for CONFIG_COMPAT_32BIT_TIME instead, which will then be
enabled on all existing 32-bit architectures.

Signed-off-by: Arnd Bergmann 
---
 ipc/mqueue.c | 80 +++-
 ipc/sem.c|  3 ++-
 ipc/util.h   |  2 +-
 3 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 9610afcfa2e5..c0d58f390c3b 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -1420,6 +1420,47 @@ COMPAT_SYSCALL_DEFINE4(mq_open, const char __user *, 
u_name,
return do_mq_open(u_name, oflag, mode, p);
 }
 
+COMPAT_SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,
+  const struct compat_sigevent __user *, u_notification)
+{
+   struct sigevent n, *p = NULL;
+   if (u_notification) {
+   if (get_compat_sigevent(&n, u_notification))
+   return -EFAULT;
+   if (n.sigev_notify == SIGEV_THREAD)
+   n.sigev_value.sival_ptr = 
compat_ptr(n.sigev_value.sival_int);
+   p = &n;
+   }
+   return do_mq_notify(mqdes, p);
+}
+
+COMPAT_SYSCALL_DEFINE3(mq_getsetattr, mqd_t, mqdes,
+  const struct compat_mq_attr __user *, u_mqstat,
+  struct compat_mq_attr __user *, u_omqstat)
+{
+   int ret;
+   struct mq_attr mqstat, omqstat;
+   struct mq_attr *new = NULL, *old = NULL;
+
+   if (u_mqstat) {
+   new = &mqstat;
+   if (get_compat_mq_attr(new, u_mqstat))
+   return -EFAULT;
+   }
+   if (u_omqstat)
+   old = &omqstat;
+
+   ret = do_mq_getsetattr(mqdes, new, old);
+   if (ret || !old)
+   return ret;
+
+   if (put_compat_mq_attr(old, u_omqstat))
+   return -EFAULT;
+   return 0;
+}
+#endif
+
+#ifdef CONFIG_COMPAT_32BIT_TIME
 static int compat_prepare_timeout(const struct compat_timespec __user *p,
   struct timespec64 *ts)
 {
@@ -1459,45 +1500,6 @@ COMPAT_SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes,
}
return do_mq_timedreceive(mqdes, u_msg_ptr, msg_len, u_msg_prio, p);
 }
-
-COMPAT_SYSCALL_DEFINE2(mq_notify, mqd_t, mqdes,
-  const struct compat_sigevent __user *, u_notification)
-{
-   struct sigevent n, *p = NULL;
-   if (u_notification) {
-   if (get_compat_sigevent(&n, u_notification))
-   return -EFAULT;
-   if (n.sigev_notify == SIGEV_THREAD)
-   n.sigev_value.sival_ptr = 
compat_ptr(n.sigev_value.sival_int);
-   p = &n;
-   }
-   return do_mq_notify(mqdes, p);
-}
-
-COMPAT_SYSCALL_DEFINE3(mq_getsetattr, mqd_t, mqdes,
-  const struct compat_mq_attr __user *, u_mqstat,
-  struct compat_mq_attr __user *, u_omqstat)
-{
-   int ret;
-   struct mq_attr mqstat, omqstat;
-   struct mq_attr *new = NULL, *old = NULL;
-
-   if (u_mqstat) {
-   new = &mqstat;
-   if (get_compat_mq_attr(new, u_mqstat))
-   return -EFAULT;
-   }
-   if (u_omqstat)
-   old = &omqstat;
-
-   ret = do_mq_getsetattr(mqdes, new, old);
-   if (ret || !old)
-   return ret;
-
-   if (put_compat_mq_attr(old, u_omqstat))
-   return -EFAULT;
-   return 0;
-}
 #endif
 
 static const struct inode_operations mqueue_dir_inode_operations = {
diff --git a/ipc/sem.c b/ipc/sem.c
index b951e25ba2db..cfd94d48a9aa 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -70,6 +70,7 @@
  *   The worst-case behavior is nevertheless O(N^2) for N wakeups.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -2193,7 +2194,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf 
__user *, tsops,
return ksys_semtimedop(semid, tsops, nsops, timeout);
 }
 
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_COMPAT_32BIT_TIME
 long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
unsigned int nsops,
const struct compat_timespec __user *timeout)
diff --git a/ipc/util.h b/ipc/util.h
index 975c6de2df9d..0aba3230d007 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -265,10 +265,10 @@ long ksys_shmdt(char __user *shmaddr);
 long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf);
 
 /* for CONFIG_ARCH_WANT_OLD_COMPAT_IPC */
-#ifdef CONFIG_COMPAT
 long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
unsigned int nsops,
const struct compat_timespec __user *timeout);
+#ifdef CONFIG_COMPAT
 long compat_ksys_s

[PATCH v4 14/16] y2038: ipc: Use __kernel_timespec

2018-04-25 Thread Arnd Bergmann
This is a preparatation for changing over __kernel_timespec to 64-bit
times, which involves assigning new system call numbers for mq_timedsend(),
mq_timedreceive() and semtimedop() for compatibility with future y2038
proof user space.

The existing ABIs will remain available through compat code.

Signed-off-by: Arnd Bergmann 
---
 include/linux/syscalls.h | 6 +++---
 ipc/mqueue.c | 6 +++---
 ipc/sem.c| 4 ++--
 ipc/util.h   | 2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index c9a2a2601852..b92cb79d38c3 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -680,8 +680,8 @@ asmlinkage long sys_sysinfo(struct sysinfo __user *info);
 /* ipc/mqueue.c */
 asmlinkage long sys_mq_open(const char __user *name, int oflag, umode_t mode, 
struct mq_attr __user *attr);
 asmlinkage long sys_mq_unlink(const char __user *name);
-asmlinkage long sys_mq_timedsend(mqd_t mqdes, const char __user *msg_ptr, 
size_t msg_len, unsigned int msg_prio, const struct timespec __user 
*abs_timeout);
-asmlinkage long sys_mq_timedreceive(mqd_t mqdes, char __user *msg_ptr, size_t 
msg_len, unsigned int __user *msg_prio, const struct timespec __user 
*abs_timeout);
+asmlinkage long sys_mq_timedsend(mqd_t mqdes, const char __user *msg_ptr, 
size_t msg_len, unsigned int msg_prio, const struct __kernel_timespec __user 
*abs_timeout);
+asmlinkage long sys_mq_timedreceive(mqd_t mqdes, char __user *msg_ptr, size_t 
msg_len, unsigned int __user *msg_prio, const struct __kernel_timespec __user 
*abs_timeout);
 asmlinkage long sys_mq_notify(mqd_t mqdes, const struct sigevent __user 
*notification);
 asmlinkage long sys_mq_getsetattr(mqd_t mqdes, const struct mq_attr __user 
*mqstat, struct mq_attr __user *omqstat);
 
@@ -698,7 +698,7 @@ asmlinkage long sys_semget(key_t key, int nsems, int 
semflg);
 asmlinkage long sys_semctl(int semid, int semnum, int cmd, unsigned long arg);
 asmlinkage long sys_semtimedop(int semid, struct sembuf __user *sops,
unsigned nsops,
-   const struct timespec __user *timeout);
+   const struct __kernel_timespec __user *timeout);
 asmlinkage long sys_semop(int semid, struct sembuf __user *sops,
unsigned nsops);
 
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index a808f29d4c5a..9610afcfa2e5 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -691,7 +691,7 @@ static void __do_notify(struct mqueue_inode_info *info)
wake_up(&info->wait_q);
 }
 
-static int prepare_timeout(const struct timespec __user *u_abs_timeout,
+static int prepare_timeout(const struct __kernel_timespec __user 
*u_abs_timeout,
   struct timespec64 *ts)
 {
if (get_timespec64(ts, u_abs_timeout))
@@ -1128,7 +1128,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user 
*u_msg_ptr,
 
 SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
size_t, msg_len, unsigned int, msg_prio,
-   const struct timespec __user *, u_abs_timeout)
+   const struct __kernel_timespec __user *, u_abs_timeout)
 {
struct timespec64 ts, *p = NULL;
if (u_abs_timeout) {
@@ -1142,7 +1142,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char 
__user *, u_msg_ptr,
 
 SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
size_t, msg_len, unsigned int __user *, u_msg_prio,
-   const struct timespec __user *, u_abs_timeout)
+   const struct __kernel_timespec __user *, u_abs_timeout)
 {
struct timespec64 ts, *p = NULL;
if (u_abs_timeout) {
diff --git a/ipc/sem.c b/ipc/sem.c
index 8935cd8cf166..b951e25ba2db 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -2176,7 +2176,7 @@ static long do_semtimedop(int semid, struct sembuf __user 
*tsops,
 }
 
 long ksys_semtimedop(int semid, struct sembuf __user *tsops,
-unsigned int nsops, const struct timespec __user *timeout)
+unsigned int nsops, const struct __kernel_timespec __user 
*timeout)
 {
if (timeout) {
struct timespec64 ts;
@@ -2188,7 +2188,7 @@ long ksys_semtimedop(int semid, struct sembuf __user 
*tsops,
 }
 
 SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
-   unsigned int, nsops, const struct timespec __user *, timeout)
+   unsigned int, nsops, const struct __kernel_timespec __user *, 
timeout)
 {
return ksys_semtimedop(semid, tsops, nsops, timeout);
 }
diff --git a/ipc/util.h b/ipc/util.h
index acc5159e96d0..975c6de2df9d 100644
--- a/ipc/util.h
+++ b/ipc/util.h
@@ -251,7 +251,7 @@ static inline int compat_ipc_parse_version(int *cmd)
 /* for __ARCH_WANT_SYS_IPC */
 long ksys_semtimedop(int semid, struct sembuf __user *tsops,
 unsigned int nsops,
-const s

[PATCH v4 05/16] y2038: s390: Remove unneeded ipc uapi header files

2018-04-25 Thread Arnd Bergmann
The s390 msgbuf/sembuf/shmbuf header files are all identical to the
version from asm-generic.

This patch removes the files and replaces them with 'generic-y'
statements, to avoid having to modify each copy when we extend sysvipc
to deal with 64-bit time_t in 32-bit user space.

Note that unlike alpha and ia64, the ipcbuf.h header file is slightly
different here, so I'm leaving the private copy.

To deal with 32-bit compat tasks, we also have to adapt the definitions
of compat_{shm,sem,msg}id_ds to match the changes to the respective
asm-generic files.

Acked-by: Heiko Carstens 
Signed-off-by: Arnd Bergmann 
---
 arch/s390/include/asm/compat.h  | 32 
 arch/s390/include/uapi/asm/Kbuild   |  3 +++
 arch/s390/include/uapi/asm/msgbuf.h | 38 
 arch/s390/include/uapi/asm/sembuf.h | 30 ---
 arch/s390/include/uapi/asm/shmbuf.h | 49 -
 5 files changed, 19 insertions(+), 133 deletions(-)
 delete mode 100644 arch/s390/include/uapi/asm/msgbuf.h
 delete mode 100644 arch/s390/include/uapi/asm/sembuf.h
 delete mode 100644 arch/s390/include/uapi/asm/shmbuf.h

diff --git a/arch/s390/include/asm/compat.h b/arch/s390/include/asm/compat.h
index 501aaff85304..97db2fba546a 100644
--- a/arch/s390/include/asm/compat.h
+++ b/arch/s390/include/asm/compat.h
@@ -232,10 +232,10 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   compat_time_t  sem_otime;
-   compat_ulong_t __pad1;
-   compat_time_t  sem_ctime;
-   compat_ulong_t __pad2;
+   compat_ulong_t sem_otime;
+   compat_ulong_t sem_otime_high;
+   compat_ulong_t sem_ctime;
+   compat_ulong_t sem_ctime_high;
compat_ulong_t sem_nsems;
compat_ulong_t __unused1;
compat_ulong_t __unused2;
@@ -243,12 +243,12 @@ struct compat_semid64_ds {
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
-   compat_time_t   msg_stime;
-   compat_ulong_t __pad1;
-   compat_time_t   msg_rtime;
-   compat_ulong_t __pad2;
-   compat_time_t   msg_ctime;
-   compat_ulong_t __pad3;
+   compat_ulong_t msg_stime;
+   compat_ulong_t msg_stime_high;
+   compat_ulong_t msg_rtime;
+   compat_ulong_t msg_rtime_high;
+   compat_ulong_t msg_ctime;
+   compat_ulong_t msg_ctime_high;
compat_ulong_t msg_cbytes;
compat_ulong_t msg_qnum;
compat_ulong_t msg_qbytes;
@@ -261,12 +261,12 @@ struct compat_msqid64_ds {
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
compat_size_t  shm_segsz;
-   compat_time_t  shm_atime;
-   compat_ulong_t __pad1;
-   compat_time_t  shm_dtime;
-   compat_ulong_t __pad2;
-   compat_time_t  shm_ctime;
-   compat_ulong_t __pad3;
+   compat_ulong_t shm_atime;
+   compat_ulong_t shm_atime_high;
+   compat_ulong_t shm_dtime;
+   compat_ulong_t shm_dtime_high;
+   compat_ulong_t shm_ctime;
+   compat_ulong_t shm_ctime_high;
compat_pid_t   shm_cpid;
compat_pid_t   shm_lpid;
compat_ulong_t shm_nattch;
diff --git a/arch/s390/include/uapi/asm/Kbuild 
b/arch/s390/include/uapi/asm/Kbuild
index faef3f7e8353..e364873e0d10 100644
--- a/arch/s390/include/uapi/asm/Kbuild
+++ b/arch/s390/include/uapi/asm/Kbuild
@@ -9,9 +9,12 @@ generic-y += errno.h
 generic-y += fcntl.h
 generic-y += ioctl.h
 generic-y += mman.h
+generic-y += msgbuf.h
 generic-y += param.h
 generic-y += poll.h
 generic-y += resource.h
+generic-y += sembuf.h
+generic-y += shmbuf.h
 generic-y += sockios.h
 generic-y += swab.h
 generic-y += termbits.h
diff --git a/arch/s390/include/uapi/asm/msgbuf.h 
b/arch/s390/include/uapi/asm/msgbuf.h
deleted file mode 100644
index 604f847cd68c..
--- a/arch/s390/include/uapi/asm/msgbuf.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _S390_MSGBUF_H
-#define _S390_MSGBUF_H
-
-/* 
- * The msqid64_ds structure for S/390 architecture.
- * Note extra padding because this structure is passed back and forth
- * between kernel and user space.
- *
- * Pad space is left for:
- * - 64-bit time_t to solve y2038 problem
- * - 2 miscellaneous 32-bit values
- */
-
-struct msqid64_ds {
-   struct ipc64_perm msg_perm;
-   __kernel_time_t msg_stime;  /* last msgsnd time */
-#ifndef __s390x__
-   unsigned long   __unused1;
-#endif /* ! __s390x__ */
-   __kernel_time_t msg_rtime;  /* last msgrcv time */
-#ifndef __s390x__
-   unsigned long   __unused2;
-#endif /* ! __s390x__ */
-   __kernel_time_t msg_ctime;  /* last change time */
-#ifndef __s390x__
-   unsigned long   __unused3;
-#endif /* ! __s390x__ */
-   unsigned long  msg_cbytes;  /* current number of bytes on queue */
-   unsigned long  msg_qnum;/* number of messages in queue */
-   unsigned long  msg_qbytes;  /* max number of b

[PATCH v4 07/16] y2038: mips: Extend sysvipc data structures

2018-04-25 Thread Arnd Bergmann
MIPS is the weirdest case for sysvipc, because each of the
three data structures is done differently:

* msqid64_ds has padding in the right place so we could in theory
  extend this one to just have 64-bit values instead of time_t.
  As this does not work for most of the other combinations,
  we just handle it in the common manner though.

* semid64_ds has no padding for 64-bit time_t, but has two reserved
  'long' fields, which are sufficient to extend the sem_otime
  and sem_ctime fields to 64 bit. In order to do this, the libc
  implementation will have to copy the data into another structure
  that has the fields in a different order. MIPS is the only
  architecture with this problem, so this is best done in MIPS
  specific libc code.

* shmid64_ds is slightly worse than that, because it has three
  time_t fields but only two unused 32-bit words. As a workaround,
  we extend each field only by 16 bits, ending up with 48-bit
  timestamps that user space again has to work around by itself.

The compat versions of the data structures are changed in the
same way.

Signed-off-by: Arnd Bergmann 
---
 arch/mips/include/asm/compat.h  | 40 ++
 arch/mips/include/uapi/asm/msgbuf.h | 57 -
 arch/mips/include/uapi/asm/sembuf.h | 15 --
 arch/mips/include/uapi/asm/shmbuf.h | 23 +--
 4 files changed, 94 insertions(+), 41 deletions(-)

diff --git a/arch/mips/include/asm/compat.h b/arch/mips/include/asm/compat.h
index 3e548ee99a2f..78675f19440f 100644
--- a/arch/mips/include/asm/compat.h
+++ b/arch/mips/include/asm/compat.h
@@ -37,9 +37,11 @@ typedef struct {
 typedef s32compat_timer_t;
 typedef s32compat_key_t;
 
+typedef s16compat_short_t;
 typedef s32compat_int_t;
 typedef s32compat_long_t;
 typedef s64compat_s64;
+typedef u16compat_ushort_t;
 typedef u32compat_uint_t;
 typedef u32compat_ulong_t;
 typedef u64compat_u64;
@@ -157,35 +159,35 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   compat_time_t   sem_otime;
-   compat_time_t   sem_ctime;
+   compat_ulong_t  sem_otime;
+   compat_ulong_t  sem_ctime;
compat_ulong_t  sem_nsems;
-   compat_ulong_t  __unused1;
-   compat_ulong_t  __unused2;
+   compat_ulong_t  sem_otime_high;
+   compat_ulong_t  sem_ctime_high;
 };
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
 #ifndef CONFIG_CPU_LITTLE_ENDIAN
-   compat_ulong_t  __unused1;
+   compat_ulong_t  msg_stime_high;
 #endif
-   compat_time_t   msg_stime;
+   compat_ulong_t  msg_stime;
 #ifdef CONFIG_CPU_LITTLE_ENDIAN
-   compat_ulong_t  __unused1;
+   compat_ulong_t  msg_stime_high;
 #endif
 #ifndef CONFIG_CPU_LITTLE_ENDIAN
-   compat_ulong_t  __unused2;
+   compat_ulong_t  msg_rtime_high;
 #endif
-   compat_time_t   msg_rtime;
+   compat_ulong_t  msg_rtime;
 #ifdef CONFIG_CPU_LITTLE_ENDIAN
-   compat_ulong_t  __unused2;
+   compat_ulong_t  msg_rtime_high;
 #endif
 #ifndef CONFIG_CPU_LITTLE_ENDIAN
-   compat_ulong_t  __unused3;
+   compat_ulong_t  msg_ctime_high;
 #endif
-   compat_time_t   msg_ctime;
+   compat_ulong_t  msg_ctime;
 #ifdef CONFIG_CPU_LITTLE_ENDIAN
-   compat_ulong_t  __unused3;
+   compat_ulong_t  msg_ctime_high;
 #endif
compat_ulong_t  msg_cbytes;
compat_ulong_t  msg_qnum;
@@ -199,14 +201,16 @@ struct compat_msqid64_ds {
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
compat_size_t   shm_segsz;
-   compat_time_t   shm_atime;
-   compat_time_t   shm_dtime;
-   compat_time_t   shm_ctime;
+   compat_ulong_t  shm_atime;
+   compat_ulong_t  shm_dtime;
+   compat_ulong_t  shm_ctime;
compat_pid_tshm_cpid;
compat_pid_tshm_lpid;
compat_ulong_t  shm_nattch;
-   compat_ulong_t  __unused1;
-   compat_ulong_t  __unused2;
+   compat_ushort_t shm_atime_high;
+   compat_ushort_t shm_dtime_high;
+   compat_ushort_t shm_ctime_high;
+   compat_ushort_t __unused2;
 };
 
 /* MIPS has unusual order of fields in stack_t */
diff --git a/arch/mips/include/uapi/asm/msgbuf.h 
b/arch/mips/include/uapi/asm/msgbuf.h
index eb4d0f9d7364..46aa15b13e4e 100644
--- a/arch/mips/include/uapi/asm/msgbuf.h
+++ b/arch/mips/include/uapi/asm/msgbuf.h
@@ -9,33 +9,15 @@
  * between kernel and user space.
  *
  * Pad space is left for:
- * - extension of time_t to 64-bit on 32-bitsystem to solve the y2038 problem
  * - 2 miscellaneous unsigned long values
  */
 
+#if defined(__mips64)
 struct msqid64_ds {
struct ipc64_perm msg_perm;
-#if !defined(__mips64) && defined(__MIPSEB__)
-   unsigned long   __unused1;
-#endif
__kernel_time_t msg_stime;  /* last msgsnd time */
-#if !defined(__mips64) && defined(__MIPSE

[PATCH v4 06/16] y2038: arm64: Extend sysvipc compat data structures

2018-04-25 Thread Arnd Bergmann
Both 32-bit amd 64-bit ARM use the asm-generic header files for their
sysvipc data structures, so no special care is needed to make those
work beyond y2038, with the one exception of compat mode: Since there
is no asm-generic definition of the compat mode IPC structures, ARM64
provides its own copy, and we make those match the changes in the native
asm-generic header files.

There is sufficient padding in these data structures to extend all
timestamps to 64 bit, but on big-endian ARM kernels, the padding
is in the wrong place, so the C library has to ensure it reassembles
a 64-bit time_t correctly.

Signed-off-by: Arnd Bergmann 
---
 arch/arm64/include/asm/compat.h | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index 0030f79808b3..1a037b94eba1 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -181,10 +181,10 @@ struct compat_ipc64_perm {
 
 struct compat_semid64_ds {
struct compat_ipc64_perm sem_perm;
-   compat_time_t  sem_otime;
-   compat_ulong_t __unused1;
-   compat_time_t  sem_ctime;
-   compat_ulong_t __unused2;
+   compat_ulong_t sem_otime;
+   compat_ulong_t sem_otime_high;
+   compat_ulong_t sem_ctime;
+   compat_ulong_t sem_ctime_high;
compat_ulong_t sem_nsems;
compat_ulong_t __unused3;
compat_ulong_t __unused4;
@@ -192,12 +192,12 @@ struct compat_semid64_ds {
 
 struct compat_msqid64_ds {
struct compat_ipc64_perm msg_perm;
-   compat_time_t  msg_stime;
-   compat_ulong_t __unused1;
-   compat_time_t  msg_rtime;
-   compat_ulong_t __unused2;
-   compat_time_t  msg_ctime;
-   compat_ulong_t __unused3;
+   compat_ulong_t msg_stime;
+   compat_ulong_t msg_stime_high;
+   compat_ulong_t msg_rtime;
+   compat_ulong_t msg_rtime_high;
+   compat_ulong_t msg_ctime;
+   compat_ulong_t msg_ctime_high;
compat_ulong_t msg_cbytes;
compat_ulong_t msg_qnum;
compat_ulong_t msg_qbytes;
@@ -210,12 +210,12 @@ struct compat_msqid64_ds {
 struct compat_shmid64_ds {
struct compat_ipc64_perm shm_perm;
compat_size_t  shm_segsz;
-   compat_time_t  shm_atime;
-   compat_ulong_t __unused1;
-   compat_time_t  shm_dtime;
-   compat_ulong_t __unused2;
-   compat_time_t  shm_ctime;
-   compat_ulong_t __unused3;
+   compat_ulong_t shm_atime;
+   compat_ulong_t shm_atime_high;
+   compat_ulong_t shm_dtime;
+   compat_ulong_t shm_dtime_high;
+   compat_ulong_t shm_ctime;
+   compat_ulong_t shm_ctime_high;
compat_pid_t   shm_cpid;
compat_pid_t   shm_lpid;
compat_ulong_t shm_nattch;
-- 
2.9.0



[PATCH v2 0/1] misc: IBM Virtual Management Channel Driver (VMC)

2018-04-25 Thread Bryant G. Ly
Steven Royer had previously attempted to upstream this
driver two years ago, but never got the chance to address
the concerns from Greg Kroah-Hartman.

The thread with the initial upstream is:
https://lkml.org/lkml/2016/2/16/918

I have addressed the following:

Version 1:
- Documentation
- Use of dev_dbg instead of pr_dbg
- Change to misc class
- Fixed memory barrier usages
- Addressed styling, checkpatch, renaming of functions
- General fixes to the driver to make it more inline with
  existing upstream drivers.

Version 2:
- Changed Documentation from .rst to .txt and addressed
  small changes in documentation per request from Randy.
- Clarified Documentation based upon Linus Walleij's
  comments
- Fixed kbuild warning in regards to unititialized use of
  rc

Bryant G. Ly (1):
  misc: IBM Virtual Management Channel Driver (VMC)

 Documentation/ioctl/ioctl-number.txt  |1 +
 Documentation/misc-devices/ibmvmc.rst |  226 +++
 MAINTAINERS   |6 +
 arch/powerpc/include/asm/hvcall.h |1 +
 drivers/misc/Kconfig  |   14 +
 drivers/misc/Makefile |1 +
 drivers/misc/ibmvmc.c | 2418 +
 drivers/misc/ibmvmc.h |  209 +++
 8 files changed, 2876 insertions(+)
 create mode 100644 Documentation/misc-devices/ibmvmc.rst
 create mode 100644 drivers/misc/ibmvmc.c
 create mode 100644 drivers/misc/ibmvmc.h

-- 
2.7.2



[PATCH v2 1/1] misc: IBM Virtual Management Channel Driver (VMC)

2018-04-25 Thread Bryant G. Ly
This driver is a logical device which provides an
interface between the hypervisor and a management
partition. This interface is like a message
passing interface. This management partition
is intended to provide an alternative to HMC-based
system management.

VMC enables the Management LPAR to provide basic
logical partition functions:
- Logical Partition Configuration
- Boot, start, and stop actions for individual
  partitions
- Display of partition status
- Management of virtual Ethernet
- Management of virtual Storage
- Basic system management

This driver is to be used for the POWER Virtual
Management Channel Virtual Adapter on the PowerPC
platform. It provides a character device which
allows for both request/response and async message
support through the /dev/ibmvmc node.

Signed-off-by: Bryant G. Ly 
Reviewed-by: Steven Royer 
Reviewed-by: Adam Reznechek 
Reviewed-by: Randy Dunlap 
Tested-by: Taylor Jakobson 
Tested-by: Brad Warrum 
Cc: Greg Kroah-Hartman 
Cc: Arnd Bergmann 
Cc: Benjamin Herrenschmidt 
Cc: Michael Ellerman 
---
 Documentation/ioctl/ioctl-number.txt  |1 +
 Documentation/misc-devices/ibmvmc.rst |  226 +++
 MAINTAINERS   |6 +
 arch/powerpc/include/asm/hvcall.h |1 +
 drivers/misc/Kconfig  |   14 +
 drivers/misc/Makefile |1 +
 drivers/misc/ibmvmc.c | 2418 +
 drivers/misc/ibmvmc.h |  209 +++
 8 files changed, 2876 insertions(+)
 create mode 100644 Documentation/misc-devices/ibmvmc.rst
 create mode 100644 drivers/misc/ibmvmc.c
 create mode 100644 drivers/misc/ibmvmc.h

diff --git a/Documentation/ioctl/ioctl-number.txt 
b/Documentation/ioctl/ioctl-number.txt
index 84bb74d..9851cee 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -329,6 +329,7 @@ Code  Seq#(hex) Include FileComments
 0xCA   80-BF   uapi/scsi/cxlflash_ioctl.h
 0xCB   00-1F   CBM serial IEC bus  in development:


+0xCC   00-0F   drivers/misc/ibmvmc.hpseries VMC driver
 0xCD   01  linux/reiserfs_fs.h
 0xCF   02  fs/cifs/ioctl.c
 0xDB   00-0F   drivers/char/mwave/mwavepub.h
diff --git a/Documentation/misc-devices/ibmvmc.rst 
b/Documentation/misc-devices/ibmvmc.rst
new file mode 100644
index 000..46ded79
--- /dev/null
+++ b/Documentation/misc-devices/ibmvmc.rst
@@ -0,0 +1,226 @@
+.. SPDX-License-Identifier: GPL-2.0+
+==
+IBM Virtual Management Channel Kernel Driver (IBMVMC)
+==
+
+:Authors:
+   Dave Engebretsen ,
+   Adam Reznechek ,
+   Steven Royer ,
+   Bryant G. Ly ,
+
+Introduction
+
+
+Note: Knowledge of virtualization technology is required to understand
+this document.
+
+A good reference document would be:
+
+https://openpowerfoundation.org/wp-content/uploads/2016/05/LoPAPR_DRAFT_v11_24March2016_cmt1.pdf
+
+The Virtual Management Channel (VMC) is a logical device which provides an
+interface between the hypervisor and a management partition. This interface
+is like a message passing interface. This management partition is intended
+to provide an alternative to systems that use a Hardware Management
+Console (HMC) - based system management.
+
+The primary hardware management solution that is developed by IBM relies
+on an appliance server named the Hardware Management Console (HMC),
+packaged as an external tower or rack-mounted personal computer. In a
+Power Systems environment, a single HMC can manage multiple POWER
+processor-based systems.
+
+Management Application
+--
+
+In the management partition, a management application exists which enables
+a system administrator to configure the system’s partitioning
+characteristics via a command line interface (CLI) or Representational
+State Transfer Application (REST API's).
+
+The management application runs on a Linux logical partition on a
+POWER8 or newer processor-based server that is virtualized by PowerVM.
+System configuration, maintenance, and control functions which
+traditionally require an HMC can be implemented in the management
+application using a combination of HMC to hypervisor interfaces and
+existing operating system methods. This tool provides a subset of the
+functions implemented by the HMC and enables basic partition configuration.
+The set of HMC to hypervisor messages supported by the management
+application component are passed to the hypervisor over a VMC interface,
+which is defined below.
+
+The VMC enables the management partition to provide basic partitioning
+functions:
+
+- Logical Partitioning Configuration
+- Start, and stop actions for individual partitions
+- Display of partition status
+- Management of virtual Ethernet
+- Management of virtual Storage
+- Basic system management
+
+Virtual

Re: [PATCH 5/6 v2] bus: fsl-mc: supoprt dma configure for devices on fsl-mc bus

2018-04-25 Thread kbuild test robot
Hi Nipun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.17-rc2 next-20180424]
[cannot apply to iommu/next glikely/devicetree/next]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nipun-Gupta/Support-for-fsl-mc-bus-and-its-devices-in-SMMU/20180418-034931
config: powerpc64-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc64 

All errors (new ones prefixed by >>):

   drivers/bus/fsl-mc/fsl-mc-bus.c: In function 'fsl_mc_dma_configure':
>> drivers/bus/fsl-mc/fsl-mc-bus.c:137:9: error: too many arguments to function 
>> 'of_dma_configure'
 return of_dma_configure(dev, dma_dev->of_node, 0);
^~~~
   In file included from drivers/bus/fsl-mc/fsl-mc-bus.c:13:0:
   include/linux/of_device.h:58:5: note: declared here
int of_dma_configure(struct device *dev, struct device_node *np);
^~~~
   drivers/bus/fsl-mc/fsl-mc-bus.c: At top level:
>> drivers/bus/fsl-mc/fsl-mc-bus.c:161:3: error: 'struct bus_type' has no 
>> member named 'dma_configure'
 .dma_configure  = fsl_mc_dma_configure,
  ^

vim +/of_dma_configure +137 drivers/bus/fsl-mc/fsl-mc-bus.c

   129  
   130  static int fsl_mc_dma_configure(struct device *dev)
   131  {
   132  struct device *dma_dev = dev;
   133  
   134  while (dev_is_fsl_mc(dma_dev))
   135  dma_dev = dma_dev->parent;
   136  
 > 137  return of_dma_configure(dev, dma_dev->of_node, 0);
   138  }
   139  
   140  static ssize_t modalias_show(struct device *dev, struct 
device_attribute *attr,
   141   char *buf)
   142  {
   143  struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
   144  
   145  return sprintf(buf, "fsl-mc:v%08Xd%s\n", 
mc_dev->obj_desc.vendor,
   146 mc_dev->obj_desc.type);
   147  }
   148  static DEVICE_ATTR_RO(modalias);
   149  
   150  static struct attribute *fsl_mc_dev_attrs[] = {
   151  &dev_attr_modalias.attr,
   152  NULL,
   153  };
   154  
   155  ATTRIBUTE_GROUPS(fsl_mc_dev);
   156  
   157  struct bus_type fsl_mc_bus_type = {
   158  .name = "fsl-mc",
   159  .match = fsl_mc_bus_match,
   160  .uevent = fsl_mc_bus_uevent,
 > 161  .dma_configure  = fsl_mc_dma_configure,
   162  .dev_groups = fsl_mc_dev_groups,
   163  };
   164  EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
   165  

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


.config.gz
Description: application/gzip


Re: [PATCH V3] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Viresh Kumar
On 25-04-18, 16:29, Shilpasri G Bhat wrote:
> gpstate_timer_handler() uses synchronous smp_call to set the pstate
> on the requested core. This causes the below hard lockup:
> 
> [c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
> (unreliable)
> [c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
> [c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
> [c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
> [c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
> [c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
> [c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
> [c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
> [c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
> [c03fe566b760] [c0009014] decrementer_common+0x114/0x120
> -- interrupt: 901 at doorbell_global_ipi+0x34/0x50
> LR = arch_send_call_function_ipi_mask+0x120/0x130
> [c03fe566ba50] [c004876c]
> arch_send_call_function_ipi_mask+0x4c/0x130
> [c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
> [c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
> [c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
> [c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
> [c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
> [c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
> [c03fe566be30] [c000b184] system_call+0x58/0x6c
> 
> One way to avoid this is removing the smp-call. We can ensure that the timer
> always runs on one of the policy-cpus. If the timer gets migrated to a
> cpu outside the policy then re-queue it back on the policy->cpus. This way
> we can get rid of the smp-call which was being used to set the pstate
> on the policy->cpus.
> 
> Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer as 
> pinned)
> Cc: [4.8+]
> Reported-by: Nicholas Piggin 
> Reported-by: Pridhiviraj Paidipeddi 
> Signed-off-by: Shilpasri G Bhat 
> ---
> Changes from V2:
> - Remove the check for active policy while requeing the migrated timer
> Changes from V1:
> - Remove smp_call in the pstate handler.

Acked-by: Viresh Kumar 

-- 
viresh


Re: [PATCH V3] cpufreq: powernv: Fix the hardlockup by synchronus smp_call in timer interrupt

2018-04-25 Thread Vaidyanathan Srinivasan
* Shilpa Bhat  [2018-04-25 16:29:31]:

> gpstate_timer_handler() uses synchronous smp_call to set the pstate
> on the requested core. This causes the below hard lockup:
> 
> [c03fe566b320] [c01d5340] smp_call_function_single+0x110/0x180 
> (unreliable)
> [c03fe566b390] [c01d55e0] smp_call_function_any+0x180/0x250
> [c03fe566b3f0] [c0acd3e8] gpstate_timer_handler+0x1e8/0x580
> [c03fe566b4a0] [c01b46b0] call_timer_fn+0x50/0x1c0
> [c03fe566b520] [c01b4958] expire_timers+0x138/0x1f0
> [c03fe566b590] [c01b4bf8] run_timer_softirq+0x1e8/0x270
> [c03fe566b630] [c0d0d6c8] __do_softirq+0x158/0x3e4
> [c03fe566b710] [c0114be8] irq_exit+0xe8/0x120
> [c03fe566b730] [c0024d0c] timer_interrupt+0x9c/0xe0
> [c03fe566b760] [c0009014] decrementer_common+0x114/0x120
> -- interrupt: 901 at doorbell_global_ipi+0x34/0x50
> LR = arch_send_call_function_ipi_mask+0x120/0x130
> [c03fe566ba50] [c004876c]
> arch_send_call_function_ipi_mask+0x4c/0x130
> [c03fe566ba90] [c01d59f0] smp_call_function_many+0x340/0x450
> [c03fe566bb00] [c0075f18] pmdp_invalidate+0x98/0xe0
> [c03fe566bb30] [c03a1120] change_huge_pmd+0xe0/0x270
> [c03fe566bba0] [c0349278] change_protection_range+0xb88/0xe40
> [c03fe566bcf0] [c03496c0] mprotect_fixup+0x140/0x340
> [c03fe566bdb0] [c0349a74] SyS_mprotect+0x1b4/0x350
> [c03fe566be30] [c000b184] system_call+0x58/0x6c
> 
> One way to avoid this is removing the smp-call. We can ensure that the timer
> always runs on one of the policy-cpus. If the timer gets migrated to a
> cpu outside the policy then re-queue it back on the policy->cpus. This way
> we can get rid of the smp-call which was being used to set the pstate
> on the policy->cpus.
> 
> Fixes: 7bc54b652f13 (timers, cpufreq/powernv: Initialize the gpstate timer as 
> pinned)
> Cc: [4.8+]
> Reported-by: Nicholas Piggin 
> Reported-by: Pridhiviraj Paidipeddi 
> Signed-off-by: Shilpasri G Bhat 
> ---
> Changes from V2:
> - Remove the check for active policy while requeing the migrated timer
> Changes from V1:
> - Remove smp_call in the pstate handler.
> 
>  drivers/cpufreq/powernv-cpufreq.c | 14 +++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/powernv-cpufreq.c 
> b/drivers/cpufreq/powernv-cpufreq.c
> index 71f8682..e368e1f 100644
> --- a/drivers/cpufreq/powernv-cpufreq.c
> +++ b/drivers/cpufreq/powernv-cpufreq.c
> @@ -679,6 +679,16 @@ void gpstate_timer_handler(struct timer_list *t)
> 
>   if (!spin_trylock(&gpstates->gpstate_lock))
>   return;
> + /*
> +  * If the timer has migrated to the different cpu then bring
> +  * it back to one of the policy->cpus
> +  */
> + if (!cpumask_test_cpu(raw_smp_processor_id(), policy->cpus)) {
> + gpstates->timer.expires = jiffies + msecs_to_jiffies(1);
> + add_timer_on(&gpstates->timer, cpumask_first(policy->cpus));
> + spin_unlock(&gpstates->gpstate_lock);
> + return;
> + }
> 
>   /*
>* If PMCR was last updated was using fast_swtich then
> @@ -718,10 +728,8 @@ void gpstate_timer_handler(struct timer_list *t)
>   if (gpstate_idx != gpstates->last_lpstate_idx)
>   queue_gpstate_timer(gpstates);
> 
> + set_pstate(&freq_data);
>   spin_unlock(&gpstates->gpstate_lock);
> -
> - /* Timer may get migrated to a different cpu on cpu hot unplug */
> - smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);
>  }

Fix looks good. 

Acked-by: Vaidyanathan Srinivasan 




Re: OOM killer invoked while still one forth of mem is available

2018-04-25 Thread Christophe LEROY



Le 25/04/2018 à 21:57, David Rientjes a écrit :

On Tue, 24 Apr 2018, christophe leroy wrote:


Hi

Allthough there is still about one forth of memory available (7976kB
among 32MB), oom-killer is invoked and makes a victim.

What could be the reason and how could it be solved ?

[   54.400754] S99watchdogd-ap invoked oom-killer:
gfp_mask=0x27000c0(GFP_KERNEL_ACCOUNT|__GFP_NOTRACK), nodemask=0,
order=1, oom_score_adj=0
[   54.400815] CPU: 0 PID: 777 Comm: S99watchdogd-ap Not tainted
4.9.85-local-knld-998 #5
[   54.400830] Call Trace:
[   54.400910] [c1ca5d10] [c0327d28] dump_header.isra.4+0x54/0x17c
(unreliable)
[   54.400998] [c1ca5d50] [c0079d88] oom_kill_process+0xc4/0x414
[   54.401067] [c1ca5d90] [c007a5c8] out_of_memory+0x35c/0x37c
[   54.401220] [c1ca5dc0] [c007d68c] __alloc_pages_nodemask+0x8ec/0x9a8
[   54.401318] [c1ca5e70] [c00169d4] copy_process.isra.9.part.10+0xdc/0x10d0
[   54.401398] [c1ca5f00] [c0017b30] _do_fork+0xcc/0x2a8
[   54.401473] [c1ca5f40] [c000a660] ret_from_syscall+0x0/0x38


Looks like this is because the allocation is order-1, likely the
allocation of a struct task_struct for a new process on fork.


I'm not sure I understand what you mean. The allocation is order 1, yes, 
does it explains why OOM killer is invoked ?




I'm interested in your platform, though, with 512KB and 8MB hugepages.
Could you send the .config and also describe the system a bit more?  How
many cpus are there and does this always happen?


It is a home made board designed 15 years ago. There is only one CPU and 
there is 32 Mbytes of DRAM on the board. The processor is a MPC866 
(powerpc 8xx family). Its MMU supports 4 page sizes (4k, 16k, 512k and 8M).
Yes the problem always happens, it happens when the watchdogd get 
started, at the end of the startup, and there is always approx 8Mbytes 
available at that time.


We are running a 4.9.x kernel, with commit 4b91428699477 from 4.10 
backported on it.


See .config below

Christophe

#
# Automatically generated file; DO NOT EDIT.
# Linux/powerpc 4.9.85 Kernel Configuration
#
# CONFIG_PPC64 is not set

#
# Processor support
#
# CONFIG_PPC_BOOK3S_32 is not set
# CONFIG_PPC_85xx is not set
CONFIG_PPC_8xx=y
# CONFIG_40x is not set
# CONFIG_44x is not set
# CONFIG_E200 is not set
CONFIG_8xx=y
CONFIG_PPC_8xx_PERF_EVENT=y
CONFIG_PPC_MMU_NOHASH=y
# CONFIG_PPC_MM_SLICES is not set
CONFIG_NOT_COHERENT_CACHE=y
# CONFIG_PPC_DOORBELL is not set
CONFIG_VDSO32=y
CONFIG_CPU_BIG_ENDIAN=y
CONFIG_PPC32=y
CONFIG_32BIT=y
# CONFIG_ARCH_PHYS_ADDR_T_64BIT is not set
# CONFIG_ARCH_DMA_ADDR_T_64BIT is not set
CONFIG_MMU=y
# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
# CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK is not set
CONFIG_NR_IRQS=512
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_TRACE_IRQFLAGS_SUPPORT=y
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_ARCH_HAS_ILOG2_U32=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_ARCH_HAS_DMA_SET_COHERENT_MASK=y
CONFIG_PPC=y
# CONFIG_GENERIC_CSUM is not set
CONFIG_EARLY_PRINTK=y
CONFIG_PANIC_TIMEOUT=180
CONFIG_GENERIC_NVRAM=y
CONFIG_SCHED_OMIT_FRAME_POINTER=y
# CONFIG_ARCH_MAY_HAVE_PC_FDC is not set
# CONFIG_PPC_UDBG_16550 is not set
# CONFIG_GENERIC_TBSYNC is not set
CONFIG_AUDIT_ARCH=y
CONFIG_GENERIC_BUG=y
# CONFIG_EPAPR_BOOT is not set
CONFIG_DEFAULT_UIMAGE=y
CONFIG_ARCH_HIBERNATION_POSSIBLE=y
# CONFIG_PPC_DCR_NATIVE is not set
# CONFIG_PPC_DCR_MMIO is not set
CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
CONFIG_ARCH_SUPPORTS_UPROBES=y
CONFIG_PPC_EMULATE_SSTEP=y
CONFIG_PGTABLE_LEVELS=2
CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
CONFIG_IRQ_WORK=y

#
# General setup
#
CONFIG_BROKEN_ON_SMP=y
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_CROSS_COMPILE="ppc-linux-"
# CONFIG_COMPILE_TEST is not set
CONFIG_LOCALVERSION="-s3k-dev"
CONFIG_LOCALVERSION_AUTO=y
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_KERNEL_GZIP=y
CONFIG_DEFAULT_HOSTNAME="(none)"
CONFIG_SYSVIPC=y
CONFIG_SYSVIPC_SYSCTL=y
# CONFIG_POSIX_MQUEUE is not set
CONFIG_CROSS_MEMORY_ATTACH=y
# CONFIG_FHANDLE is not set
# CONFIG_USELIB is not set
# CONFIG_AUDIT is not set
CONFIG_HAVE_ARCH_AUDITSYSCALL=y

#
# IRQ subsystem
#
CONFIG_GENERIC_IRQ_SHOW=y
CONFIG_GENERIC_IRQ_SHOW_LEVEL=y
CONFIG_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN_DEBUG=y
CONFIG_IRQ_FORCED_THREADING=y
CONFIG_SPARSE_IRQ=y
CONFIG_GENERIC_TIME_VSYSCALL_OLD=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_GENERIC_CMOS_UPDATE=y

#
# Timers subsystem
#
CONFIG_TICK_ONESHOT=y
CONFIG_HZ_PERIODIC=y
# CONFIG_NO_HZ_IDLE is not set
# CONFIG_NO_HZ is not set
CONFIG_HIGH_RES_TIMERS=y

#
# CPU/Task time and stats accounting
#
CONFIG_VIRT_CPU_ACCOUNTING=y
# CONFIG_TICK_CPU_ACCOUNTING is not set
CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y
# CONFIG_BSD_PROCESS_ACCT is not set
# CONFIG_TASKSTATS is not set

#
# RCU Subsystem
#
CONFIG_PREEMPT_RCU=y
# CONFIG_RCU_EXPERT is not set
CONFIG_SRCU=y
# CONFIG_TASKS_RCU is not set
CONFIG_RCU_STALL_COMMON=y
# CONFIG_TREE_RCU_TRACE is not set
# CONFIG_RCU_EXPEDITE_BOOT is not set
# CONFIG_BUILD_BIN2C is not set
# CONFIG_IKCONFIG is not set
CONFIG_LOG_BUF_SHI

[PATCH] powerpc: Add NVDIMM to powernv_defconfig

2018-04-25 Thread Michael Neuling
This enables greater testing NVDIMMs as it becomes more
prevalent. This is also the minimal required to enable persistent
memory in mambo.

This adds 100KB to the kernel text and 170KB to the vmlinux

Signed-off-by: Michael Neuling 
---
 arch/powerpc/configs/powernv_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/configs/powernv_defconfig 
b/arch/powerpc/configs/powernv_defconfig
index 9e92aa6a52..0f94b7dc11 100644
--- a/arch/powerpc/configs/powernv_defconfig
+++ b/arch/powerpc/configs/powernv_defconfig
@@ -238,6 +238,8 @@ CONFIG_RTC_CLASS=y
 CONFIG_RTC_DRV_GENERIC=y
 CONFIG_VIRTIO_PCI=m
 CONFIG_VIRTIO_BALLOON=m
+CONFIG_LIBNVDIMM=y
+# CONFIG_ND_BLK is not set
 CONFIG_EXT2_FS=y
 CONFIG_EXT2_FS_XATTR=y
 CONFIG_EXT2_FS_POSIX_ACL=y
-- 
2.14.1



[PATCH] powerpc: paste - Mask XERSO bit in CR

2018-04-25 Thread Haren Myneni

NX can set 3rd bit in CR register for XER[SO] (Summation overflow)
which is not used for paste return value. So. mask this bit to get
proper return status.

Signed-off-by: Haren Myneni 

diff --git a/arch/powerpc/platforms/powernv/copy-paste.h 
b/arch/powerpc/platforms/powernv/copy-paste.h
index c9a5036..82392e3 100644
--- a/arch/powerpc/platforms/powernv/copy-paste.h
+++ b/arch/powerpc/platforms/powernv/copy-paste.h
@@ -9,7 +9,8 @@
 #include 
 
 #define CR0_SHIFT  28
-#define CR0_MASK   0xF
+#define CR0_MASK   0xE /* 3rd bit undefined or set for XER[SO] */
+
 /*
  * Copy/paste instructions:
  *