Re: [PATCH -v6 13/13] futex: futex_lock_pi() vs PREEMPT_RT_FULL

2017-04-07 Thread Mike Galbraith
On Fri, 2017-04-07 at 19:26 -0700, Darren Hart wrote:

> I would like to see more testing because... well... futexes. But, we don't 
> have
> a futex torture suite yet, but that is something I'm hoping to be looking into
> in the near future. What testing we do have available has passed between my
> futex selftests, the LTP suite, the pi_stress, and the RT runs by Sebastian.

Ditto, tip-rt shows no signs of trouble.


Re: [PATCH -v6 13/13] futex: futex_lock_pi() vs PREEMPT_RT_FULL

2017-04-07 Thread Mike Galbraith
On Fri, 2017-04-07 at 19:26 -0700, Darren Hart wrote:

> I would like to see more testing because... well... futexes. But, we don't 
> have
> a futex torture suite yet, but that is something I'm hoping to be looking into
> in the near future. What testing we do have available has passed between my
> futex selftests, the LTP suite, the pi_stress, and the RT runs by Sebastian.

Ditto, tip-rt shows no signs of trouble.


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Andy Lutomirski
On Fri, Apr 7, 2017 at 9:21 PM, Daniel Micay  wrote:
>>> Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP))
>>> somewhere sensible should make those "leaks" visible fast -- and their
>>> exploitation impossible, i.e. fail hard.
>>
>> The leaks surely exist and now we'll just add an exploitable BUG.
>
> That didn't seem to matter for landing a rewrite of KSTACKOVERFLOW
> with a bunch of *known* DoS bugs dealt with in grsecurity and those
> were known issues that were unfixed for no apparent reason other than
> keeping egos intact. It looks like there are still some left...
>
> In that case, there also wasn't a security/performance advantage.

This is wildly off topic, but I think it's worth answering anyway
because there's an important point here:

grsecurity and PaX are great projects.  They have a lot of good ideas,
and they're put together quite nicely.  The upstream kernel should
*not* do things differently from they way they are in grsecurity/PaX
just because it wants to be different.  Conversely, the upstream
kernel should not do things the same way as PaX just to be more like
PaX.

Keep in mind that the upstream kernel and grsecurity/PaX operate under
different constraints.  The upstream kernel tries to keep itself clean
and to make tree-wide updates rather that keeping compatibility stuff
around.  PaX and grsecurity presumably want to retain some degree of
simplicity when porting to newer upstream versions.

In the context of virtually mapped stacks / KSTACKOVERFLOW, this
naturally leads to different solutions.  The upstream kernel had a
bunch of buggy drivers that played badly with virtually mapped stacks.
grsecurity sensibly went for the approach where the buggy drivers kept
working.  The upstream kernel went for the approach of fixing the
drivers rather than keeping a compatibility workaround.  Different
constraints, different solutions.

The point being that, if someone sends a patch to the x86 entry code
that's justified by "be like PaX" or by "be different than PaX",
that's not okay.  It needs a real justification that stands on its
own.

In the case of rare writes or pax_open_kernel [1] or whatever we want
to call it, CR3 would work without arch-specific code, and CR0 would
not.  That's an argument for CR3 that would need to be countered by
something.  (Sure, avoiding leaks either way might need arch changes.
OTOH, a *randomized* CR3-based approach might not have as much of a
leak issue to begin with.)

[1] Contrary to popular belief, I don't sit around reading grsecurity
code or config options, so I really don't know what this thing is
called.


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Andy Lutomirski
On Fri, Apr 7, 2017 at 9:21 PM, Daniel Micay  wrote:
>>> Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP))
>>> somewhere sensible should make those "leaks" visible fast -- and their
>>> exploitation impossible, i.e. fail hard.
>>
>> The leaks surely exist and now we'll just add an exploitable BUG.
>
> That didn't seem to matter for landing a rewrite of KSTACKOVERFLOW
> with a bunch of *known* DoS bugs dealt with in grsecurity and those
> were known issues that were unfixed for no apparent reason other than
> keeping egos intact. It looks like there are still some left...
>
> In that case, there also wasn't a security/performance advantage.

This is wildly off topic, but I think it's worth answering anyway
because there's an important point here:

grsecurity and PaX are great projects.  They have a lot of good ideas,
and they're put together quite nicely.  The upstream kernel should
*not* do things differently from they way they are in grsecurity/PaX
just because it wants to be different.  Conversely, the upstream
kernel should not do things the same way as PaX just to be more like
PaX.

Keep in mind that the upstream kernel and grsecurity/PaX operate under
different constraints.  The upstream kernel tries to keep itself clean
and to make tree-wide updates rather that keeping compatibility stuff
around.  PaX and grsecurity presumably want to retain some degree of
simplicity when porting to newer upstream versions.

In the context of virtually mapped stacks / KSTACKOVERFLOW, this
naturally leads to different solutions.  The upstream kernel had a
bunch of buggy drivers that played badly with virtually mapped stacks.
grsecurity sensibly went for the approach where the buggy drivers kept
working.  The upstream kernel went for the approach of fixing the
drivers rather than keeping a compatibility workaround.  Different
constraints, different solutions.

The point being that, if someone sends a patch to the x86 entry code
that's justified by "be like PaX" or by "be different than PaX",
that's not okay.  It needs a real justification that stands on its
own.

In the case of rare writes or pax_open_kernel [1] or whatever we want
to call it, CR3 would work without arch-specific code, and CR0 would
not.  That's an argument for CR3 that would need to be countered by
something.  (Sure, avoiding leaks either way might need arch changes.
OTOH, a *randomized* CR3-based approach might not have as much of a
leak issue to begin with.)

[1] Contrary to popular belief, I don't sit around reading grsecurity
code or config options, so I really don't know what this thing is
called.


Re: Random guest crashes since 5c34d002dcc7 ("virtio_pci: use shared interrupts for virtqueues")

2017-04-07 Thread Mike Galbraith
On Fri, 2017-04-07 at 21:56 +0300, Michael S. Tsirkin wrote:

> OK. test3 and test4 are now pushed: test3 should fix your hang,
> test4 is trying to fix a crash reported independently.

test3 does not fix the post hibernate hang business that I can easily
reproduce, those are NFS, and at least as old as 4.4.  Host/guest,
dunno, put 4.4 on both, guest hangs intermittently.

[] __rpc_wait_for_completion_task+0x30/0x30 [sunrpc]
[] rpc_wait_bit_killable+0x1e/0xb0 [sunrpc]
[] __rpc_wait_for_completion_task+0x30/0x30 [sunrpc]
[] autoremove_wake_function+0x50/0x50
[] call_decode+0x850/0x850 [sunrpc]
[] call_decode+0x850/0x850 [sunrpc]
[] __rpc_execute+0x14e/0x440 [sunrpc]
[] ktime_get+0x35/0xa0
[] rpc_run_task+0x120/0x170 [sunrpc]
[] nfs4_call_sync_sequence+0x56/0x80 [nfsv4]
[] _nfs4_proc_getattr+0xb0/0xc0 [nfsv4]
[] path_lookupat+0xd2/0x100
[] nfs4_proc_getattr+0x5c/0xe0 [nfsv4]
[] __nfs_revalidate_inode+0xa0/0x300 [nfs]
[] nfs_getattr+0x95/0x250 [nfs]
[] vfs_statx+0x7b/0xc0
[] SYSC_newstat+0x20/0x40
[] entry_SYSCALL_64_fastpath+0x1a/0xa9
[] 0x

I noted no _other_ misbehavior in either kernel, w/wo threadirqs.

-Mike


Re: Random guest crashes since 5c34d002dcc7 ("virtio_pci: use shared interrupts for virtqueues")

2017-04-07 Thread Mike Galbraith
On Fri, 2017-04-07 at 21:56 +0300, Michael S. Tsirkin wrote:

> OK. test3 and test4 are now pushed: test3 should fix your hang,
> test4 is trying to fix a crash reported independently.

test3 does not fix the post hibernate hang business that I can easily
reproduce, those are NFS, and at least as old as 4.4.  Host/guest,
dunno, put 4.4 on both, guest hangs intermittently.

[] __rpc_wait_for_completion_task+0x30/0x30 [sunrpc]
[] rpc_wait_bit_killable+0x1e/0xb0 [sunrpc]
[] __rpc_wait_for_completion_task+0x30/0x30 [sunrpc]
[] autoremove_wake_function+0x50/0x50
[] call_decode+0x850/0x850 [sunrpc]
[] call_decode+0x850/0x850 [sunrpc]
[] __rpc_execute+0x14e/0x440 [sunrpc]
[] ktime_get+0x35/0xa0
[] rpc_run_task+0x120/0x170 [sunrpc]
[] nfs4_call_sync_sequence+0x56/0x80 [nfsv4]
[] _nfs4_proc_getattr+0xb0/0xc0 [nfsv4]
[] path_lookupat+0xd2/0x100
[] nfs4_proc_getattr+0x5c/0xe0 [nfsv4]
[] __nfs_revalidate_inode+0xa0/0x300 [nfs]
[] nfs_getattr+0x95/0x250 [nfs]
[] vfs_statx+0x7b/0xc0
[] SYSC_newstat+0x20/0x40
[] entry_SYSCALL_64_fastpath+0x1a/0xa9
[] 0x

I noted no _other_ misbehavior in either kernel, w/wo threadirqs.

-Mike


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Andy Lutomirski
On Fri, Apr 7, 2017 at 12:58 PM, PaX Team  wrote:
> On 7 Apr 2017 at 9:14, Andy Lutomirski wrote:
>
>> On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause  
>> wrote:
>> > On 7 April 2017 at 15:14, Thomas Gleixner  wrote:
>> >> On Fri, 7 Apr 2017, Mathias Krause wrote:
>> > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP))
>> > somewhere sensible should make those "leaks" visible fast -- and their
>> > exploitation impossible, i.e. fail hard.
>>
>> The leaks surely exist and now we'll just add an exploitable BUG.
>
> can you please share those leaks that 'surely exist' and CC oss-security
> while at it?

I meant in the patchset here, not in grsecurity.  grsecurity (on very,
very brief inspection) seems to read cr0 and fix it up in
pax_enter_kernel.

>>
>> Then someone who cares about performance can benchmark the CR0.WP
>> approach against it and try to argue that it's a good idea.  This
>> benchmark should wait until I'm done with my PCID work, because PCID
>> is going to make use_mm() a whole heck of a lot faster.
>
> in my measurements switching PCID is hovers around 230 cycles for snb-ivb
> and 200-220 for hsw-skl whereas cr0 writes are around 230-240 cycles. there's
> of course a whole lot more impact for switching address spaces so it'll never
> be fast enough to beat cr0.wp.
>

If I'm reading this right, you're saying that a non-flushing CR3 write
is about the same cost as a CR0.WP write.  If so, then why should CR0
be preferred over the (arch-neutral) CR3 approach?  And why would
switching address spaces obviously be much slower?  There'll be a very
small number of TLB fills needed for the actual protected access.

--Andy


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Andy Lutomirski
On Fri, Apr 7, 2017 at 12:58 PM, PaX Team  wrote:
> On 7 Apr 2017 at 9:14, Andy Lutomirski wrote:
>
>> On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause  
>> wrote:
>> > On 7 April 2017 at 15:14, Thomas Gleixner  wrote:
>> >> On Fri, 7 Apr 2017, Mathias Krause wrote:
>> > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP))
>> > somewhere sensible should make those "leaks" visible fast -- and their
>> > exploitation impossible, i.e. fail hard.
>>
>> The leaks surely exist and now we'll just add an exploitable BUG.
>
> can you please share those leaks that 'surely exist' and CC oss-security
> while at it?

I meant in the patchset here, not in grsecurity.  grsecurity (on very,
very brief inspection) seems to read cr0 and fix it up in
pax_enter_kernel.

>>
>> Then someone who cares about performance can benchmark the CR0.WP
>> approach against it and try to argue that it's a good idea.  This
>> benchmark should wait until I'm done with my PCID work, because PCID
>> is going to make use_mm() a whole heck of a lot faster.
>
> in my measurements switching PCID is hovers around 230 cycles for snb-ivb
> and 200-220 for hsw-skl whereas cr0 writes are around 230-240 cycles. there's
> of course a whole lot more impact for switching address spaces so it'll never
> be fast enough to beat cr0.wp.
>

If I'm reading this right, you're saying that a non-flushing CR3 write
is about the same cost as a CR0.WP write.  If so, then why should CR0
be preferred over the (arch-neutral) CR3 approach?  And why would
switching address spaces obviously be much slower?  There'll be a very
small number of TLB fills needed for the actual protected access.

--Andy


[PATCH V8 5/5] PCI/ASPM: move link_state cleanup to bridge remove

2017-04-07 Thread Sinan Kaya
For endpoints, change pcie_aspm_exit_link_state() so it cleans up
the device's own state and disables ASPM if necessary, but doesn't
remove the parent's link_state.

For bridges, change pcie_aspm_exit_link_state() so it frees the
bridge's own link_state.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 20 +++-
 drivers/pci/remove.c|  3 +--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index c7da087..d99fa3f 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -972,6 +972,21 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
struct pci_dev *parent = pdev->bus->self;
struct pcie_link_state *link, *root, *parent_link;
 
+   if (pdev->has_secondary_link) {
+   link = pdev->link_state;
+   down_read(_bus_sem);
+   mutex_lock(_lock);
+
+   list_del(>sibling);
+   list_del(>link);
+
+   /* Clock PM is for endpoint device */
+   free_link_state(link);
+   mutex_unlock(_lock);
+   up_read(_bus_sem);
+   return;
+   }
+
if (!parent || !parent->link_state)
return;
 
@@ -990,11 +1005,6 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
 
/* All functions are removed, so just disable ASPM for the link */
pcie_config_aspm_link(link, 0);
-   list_del(>sibling);
-   list_del(>link);
-   /* Clock PM is for endpoint device */
-   free_link_state(link);
-
/* Recheck latencies and configure upstream links */
if (parent_link) {
pcie_update_aspm_capable(root);
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 73a03d3..7e14ebd 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -25,8 +25,7 @@ static void pci_stop_dev(struct pci_dev *dev)
dev->is_added = 0;
}
 
-   if (dev->bus->self)
-   pcie_aspm_exit_link_state(dev);
+   pcie_aspm_exit_link_state(dev);
 }
 
 static void pci_destroy_dev(struct pci_dev *dev)
-- 
1.9.1



[PATCH V8 4/5] PCI/ASPM: save power on values during bridge init

2017-04-07 Thread Sinan Kaya
Now that we added a hook to be called from device_add, save the
default values from the HW registers early in the boot for further
reuse during hot device add/remove operations.

If the link is down during boot, assume that we want to enable L0s
and L1 following hotplug insertion as well as L1SS if supported.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index e33f84b..c7da087 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -505,8 +505,10 @@ static void pcie_aspm_cap_init(struct pcie_link_state 
*link, int blacklist)
 */
if (dwreg.support & upreg.support & PCIE_LINK_STATE_L0S)
link->aspm_support |= ASPM_STATE_L0S;
-   if (dwreg.enabled & PCIE_LINK_STATE_L0S)
+   if (dwreg.enabled & PCIE_LINK_STATE_L0S) {
link->aspm_enabled |= ASPM_STATE_L0S_UP;
+   link->aspm_default |= ASPM_STATE_L0S_UP;
+   }
if (upreg.enabled & PCIE_LINK_STATE_L0S)
link->aspm_enabled |= ASPM_STATE_L0S_DW;
link->latency_up.l0s = calc_l0s_latency(upreg.latency_encoding_l0s);
@@ -542,9 +544,6 @@ static void pcie_aspm_cap_init(struct pcie_link_state 
*link, int blacklist)
if (link->aspm_support & ASPM_STATE_L1SS)
aspm_calc_l1ss_info(link, , );
 
-   /* Save default state */
-   link->aspm_default = link->aspm_enabled;
-
/* Setup initial capable state. Will be updated later */
link->aspm_capable = link->aspm_support;
/*
@@ -835,11 +834,38 @@ static int pci_aspm_init_downstream(struct pci_dev *pdev)
 static int pci_aspm_init_upstream(struct pci_dev *pdev)
 {
struct pcie_link_state *link;
+   struct aspm_register_info upreg;
+   u16 lnk_status;
+   bool ret;
 
link = alloc_pcie_link_state(pdev);
if (!link)
return -ENOMEM;
 
+   pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, _status);
+   ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
+
+   if (ret) {
+   pcie_get_aspm_reg(pdev, );
+   if (upreg.enabled & PCIE_LINK_STATE_L0S)
+   link->aspm_default |= ASPM_STATE_L0S_DW;
+   if (upreg.enabled & PCIE_LINK_STATE_L1)
+   link->aspm_default |= ASPM_STATE_L1;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_1)
+   link->aspm_default |= ASPM_STATE_L1_1;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_2)
+   link->aspm_default |= ASPM_STATE_L1_2;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_1)
+   link->aspm_default |= ASPM_STATE_L1_1_PCIPM;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_2)
+   link->aspm_default |= ASPM_STATE_L1_2_PCIPM;
+   } else {
+   if (!pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_L1SS))
+   link->aspm_default = ASPM_STATE_L0S | ASPM_STATE_L1;
+   else
+   link->aspm_default = ASPM_STATE_ALL;
+   }
+
return 0;
 }
 
-- 
1.9.1



[PATCH V8 5/5] PCI/ASPM: move link_state cleanup to bridge remove

2017-04-07 Thread Sinan Kaya
For endpoints, change pcie_aspm_exit_link_state() so it cleans up
the device's own state and disables ASPM if necessary, but doesn't
remove the parent's link_state.

For bridges, change pcie_aspm_exit_link_state() so it frees the
bridge's own link_state.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 20 +++-
 drivers/pci/remove.c|  3 +--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index c7da087..d99fa3f 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -972,6 +972,21 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
struct pci_dev *parent = pdev->bus->self;
struct pcie_link_state *link, *root, *parent_link;
 
+   if (pdev->has_secondary_link) {
+   link = pdev->link_state;
+   down_read(_bus_sem);
+   mutex_lock(_lock);
+
+   list_del(>sibling);
+   list_del(>link);
+
+   /* Clock PM is for endpoint device */
+   free_link_state(link);
+   mutex_unlock(_lock);
+   up_read(_bus_sem);
+   return;
+   }
+
if (!parent || !parent->link_state)
return;
 
@@ -990,11 +1005,6 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
 
/* All functions are removed, so just disable ASPM for the link */
pcie_config_aspm_link(link, 0);
-   list_del(>sibling);
-   list_del(>link);
-   /* Clock PM is for endpoint device */
-   free_link_state(link);
-
/* Recheck latencies and configure upstream links */
if (parent_link) {
pcie_update_aspm_capable(root);
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 73a03d3..7e14ebd 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -25,8 +25,7 @@ static void pci_stop_dev(struct pci_dev *dev)
dev->is_added = 0;
}
 
-   if (dev->bus->self)
-   pcie_aspm_exit_link_state(dev);
+   pcie_aspm_exit_link_state(dev);
 }
 
 static void pci_destroy_dev(struct pci_dev *dev)
-- 
1.9.1



[PATCH V8 4/5] PCI/ASPM: save power on values during bridge init

2017-04-07 Thread Sinan Kaya
Now that we added a hook to be called from device_add, save the
default values from the HW registers early in the boot for further
reuse during hot device add/remove operations.

If the link is down during boot, assume that we want to enable L0s
and L1 following hotplug insertion as well as L1SS if supported.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index e33f84b..c7da087 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -505,8 +505,10 @@ static void pcie_aspm_cap_init(struct pcie_link_state 
*link, int blacklist)
 */
if (dwreg.support & upreg.support & PCIE_LINK_STATE_L0S)
link->aspm_support |= ASPM_STATE_L0S;
-   if (dwreg.enabled & PCIE_LINK_STATE_L0S)
+   if (dwreg.enabled & PCIE_LINK_STATE_L0S) {
link->aspm_enabled |= ASPM_STATE_L0S_UP;
+   link->aspm_default |= ASPM_STATE_L0S_UP;
+   }
if (upreg.enabled & PCIE_LINK_STATE_L0S)
link->aspm_enabled |= ASPM_STATE_L0S_DW;
link->latency_up.l0s = calc_l0s_latency(upreg.latency_encoding_l0s);
@@ -542,9 +544,6 @@ static void pcie_aspm_cap_init(struct pcie_link_state 
*link, int blacklist)
if (link->aspm_support & ASPM_STATE_L1SS)
aspm_calc_l1ss_info(link, , );
 
-   /* Save default state */
-   link->aspm_default = link->aspm_enabled;
-
/* Setup initial capable state. Will be updated later */
link->aspm_capable = link->aspm_support;
/*
@@ -835,11 +834,38 @@ static int pci_aspm_init_downstream(struct pci_dev *pdev)
 static int pci_aspm_init_upstream(struct pci_dev *pdev)
 {
struct pcie_link_state *link;
+   struct aspm_register_info upreg;
+   u16 lnk_status;
+   bool ret;
 
link = alloc_pcie_link_state(pdev);
if (!link)
return -ENOMEM;
 
+   pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, _status);
+   ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
+
+   if (ret) {
+   pcie_get_aspm_reg(pdev, );
+   if (upreg.enabled & PCIE_LINK_STATE_L0S)
+   link->aspm_default |= ASPM_STATE_L0S_DW;
+   if (upreg.enabled & PCIE_LINK_STATE_L1)
+   link->aspm_default |= ASPM_STATE_L1;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_1)
+   link->aspm_default |= ASPM_STATE_L1_1;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_ASPM_L1_2)
+   link->aspm_default |= ASPM_STATE_L1_2;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_1)
+   link->aspm_default |= ASPM_STATE_L1_1_PCIPM;
+   if (upreg.l1ss_ctl1 & PCI_L1SS_CTL1_PCIPM_L1_2)
+   link->aspm_default |= ASPM_STATE_L1_2_PCIPM;
+   } else {
+   if (!pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_L1SS))
+   link->aspm_default = ASPM_STATE_L0S | ASPM_STATE_L1;
+   else
+   link->aspm_default = ASPM_STATE_ALL;
+   }
+
return 0;
 }
 
-- 
1.9.1



[PATCH V8 2/5] PCI/ASPM: split pci_aspm_init() into two

2017-04-07 Thread Sinan Kaya
Split pci_aspm_init() body into pci_aspm_init_upstream()
and pci_aspm_init_downstream() for bridge and endpoint
specific code behavior.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index dc36717..a80d64b 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -826,6 +826,16 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
return link;
 }
 
+static int pci_aspm_init_downstream(struct pci_dev *pdev)
+{
+   return 0;
+}
+
+static int pci_aspm_init_upstream(struct pci_dev *pdev)
+{
+   return 0;
+}
+
 /*
  * pci_aspm_init: Initiate PCI express link state.
  * It is called from device_add for every single pci device.
@@ -833,7 +843,10 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
  */
 int pci_aspm_init(struct pci_dev *pdev)
 {
-   return 0;
+   if (!pdev->has_secondary_link)
+   return pci_aspm_init_downstream(pdev);
+
+   return pci_aspm_init_upstream(pdev);
 }
 
 /*
-- 
1.9.1



[PATCH V8 2/5] PCI/ASPM: split pci_aspm_init() into two

2017-04-07 Thread Sinan Kaya
Split pci_aspm_init() body into pci_aspm_init_upstream()
and pci_aspm_init_downstream() for bridge and endpoint
specific code behavior.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index dc36717..a80d64b 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -826,6 +826,16 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
return link;
 }
 
+static int pci_aspm_init_downstream(struct pci_dev *pdev)
+{
+   return 0;
+}
+
+static int pci_aspm_init_upstream(struct pci_dev *pdev)
+{
+   return 0;
+}
+
 /*
  * pci_aspm_init: Initiate PCI express link state.
  * It is called from device_add for every single pci device.
@@ -833,7 +843,10 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
  */
 int pci_aspm_init(struct pci_dev *pdev)
 {
-   return 0;
+   if (!pdev->has_secondary_link)
+   return pci_aspm_init_downstream(pdev);
+
+   return pci_aspm_init_upstream(pdev);
 }
 
 /*
-- 
1.9.1



[PATCH V8 3/5] PCI/ASPM: add init hook to device_add

2017-04-07 Thread Sinan Kaya
For bridges, have pcie_aspm_init_link_state() allocate a link_state,
regardless of whether it currently has any children.

pcie_aspm_init_link_state(): Called for bridges (upstream end of
link) after all children have been enumerated.  No longer needs to
check aspm_support_enabled or pdev->has_secondary_link or the VIA
quirk: pci_aspm_init() already checked that stuff, so we only need
to check pdev->link_state here.

Now that we are calling alloc_pcie_link_state() from pci_aspm_init()
, get rid of pci_function_0 function and detect downstream link in
pci_aspm_init_upstream() instead when the function number is 0.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 72 -
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index a80d64b..e33f84b 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -422,20 +422,6 @@ static void pcie_aspm_check_latency(struct pci_dev 
*endpoint)
}
 }
 
-/*
- * The L1 PM substate capability is only implemented in function 0 in a
- * multi function device.
- */
-static struct pci_dev *pci_function_0(struct pci_bus *linkbus)
-{
-   struct pci_dev *child;
-
-   list_for_each_entry(child, >devices, bus_list)
-   if (PCI_FUNC(child->devfn) == 0)
-   return child;
-   return NULL;
-}
-
 /* Calculate L1.2 PM substate timing parameters */
 static void aspm_calc_l1ss_info(struct pcie_link_state *link,
struct aspm_register_info *upreg,
@@ -798,7 +784,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct 
pci_dev *pdev)
INIT_LIST_HEAD(>children);
INIT_LIST_HEAD(>link);
link->pdev = pdev;
-   link->downstream = pci_function_0(pdev->subordinate);
 
/*
 * Root Ports and PCI/PCI-X to PCIe Bridges are roots of PCIe
@@ -828,11 +813,33 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
 
 static int pci_aspm_init_downstream(struct pci_dev *pdev)
 {
+   struct pcie_link_state *link;
+   struct pci_dev *parent;
+
+   /*
+* The L1 PM substate capability is only implemented in function 0 in a
+* multi function device.
+*/
+   if (PCI_FUNC(pdev->devfn) != 0)
+   return -EINVAL;
+
+   parent = pdev->bus->self;
+   if (!parent)
+   return -EINVAL;
+
+   link = parent->link_state;
+   link->downstream = pdev;
return 0;
 }
 
 static int pci_aspm_init_upstream(struct pci_dev *pdev)
 {
+   struct pcie_link_state *link;
+
+   link = alloc_pcie_link_state(pdev);
+   if (!link)
+   return -ENOMEM;
+
return 0;
 }
 
@@ -843,6 +850,17 @@ static int pci_aspm_init_upstream(struct pci_dev *pdev)
  */
 int pci_aspm_init(struct pci_dev *pdev)
 {
+   if (!aspm_support_enabled)
+   return 0;
+
+   if (!pci_is_pcie(pdev))
+   return -EINVAL;
+
+   /* VIA has a strange chipset, root port is under a bridge */
+   if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT &&
+   pdev->bus->self)
+   return 0;
+
if (!pdev->has_secondary_link)
return pci_aspm_init_downstream(pdev);
 
@@ -859,33 +877,16 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
struct pcie_link_state *link;
int blacklist = !!pcie_aspm_sanity_check(pdev);
 
-   if (!aspm_support_enabled)
-   return;
-
-   if (pdev->link_state)
-   return;
-
-   /*
-* We allocate pcie_link_state for the component on the upstream
-* end of a Link, so there's nothing to do unless this device has a
-* Link on its secondary side.
-*/
-   if (!pdev->has_secondary_link)
-   return;
-
-   /* VIA has a strange chipset, root port is under a bridge */
-   if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT &&
-   pdev->bus->self)
+   if (!pdev->link_state)
return;
 
+   link = pdev->link_state;
down_read(_bus_sem);
if (list_empty(>subordinate->devices))
goto out;
 
mutex_lock(_lock);
-   link = alloc_pcie_link_state(pdev);
-   if (!link)
-   goto unlock;
+
/*
 * Setup initial ASPM state. Note that we need to configure
 * upstream links also because capable state of them can be
@@ -910,7 +911,6 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
pcie_set_clkpm(link, policy_to_clkpm_state(link));
}
 
-unlock:
mutex_unlock(_lock);
 out:
up_read(_bus_sem);
-- 
1.9.1



[PATCH V8 1/5] PCI/ASPM: introduce pci_aspm_init() and add to pci_init_capabilities()

2017-04-07 Thread Sinan Kaya
We need a callback from pci_init_capabilities function for every
single new PCI device that is currently being added.

pci_aspm_init() will be used to save the power on state of the HW.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 10 ++
 drivers/pci/probe.c |  3 +++
 include/linux/pci.h |  2 ++
 3 files changed, 15 insertions(+)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 1dfa10c..dc36717 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -827,6 +827,16 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
 }
 
 /*
+ * pci_aspm_init: Initiate PCI express link state.
+ * It is called from device_add for every single pci device.
+ * @pdev: all pci devices
+ */
+int pci_aspm_init(struct pci_dev *pdev)
+{
+   return 0;
+}
+
+/*
  * pcie_aspm_init_link_state: Initiate PCI express link state.
  * It is called after the pcie and its children devices are scanned.
  * @pdev: the root port or switch downstream port
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index dfc9a27..1e19364 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1847,6 +1847,9 @@ static void pci_init_capabilities(struct pci_dev *dev)
 
/* Advanced Error Reporting */
pci_aer_init(dev);
+
+   /* Active State Power Management */
+   pci_aspm_init(dev);
 }
 
 /*
diff --git a/include/linux/pci.h b/include/linux/pci.h
index eb3da1a..8828dd7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1396,8 +1396,10 @@ static inline int pci_irq_get_node(struct pci_dev *pdev, 
int vec)
 
 #ifdef CONFIG_PCIEASPM
 bool pcie_aspm_support_enabled(void);
+int pci_aspm_init(struct pci_dev *pdev);
 #else
 static inline bool pcie_aspm_support_enabled(void) { return false; }
+static inline int pci_aspm_init(struct pci_dev *pdev) { return -ENODEV; }
 #endif
 
 #ifdef CONFIG_PCIEAER
-- 
1.9.1



[PATCH V8 3/5] PCI/ASPM: add init hook to device_add

2017-04-07 Thread Sinan Kaya
For bridges, have pcie_aspm_init_link_state() allocate a link_state,
regardless of whether it currently has any children.

pcie_aspm_init_link_state(): Called for bridges (upstream end of
link) after all children have been enumerated.  No longer needs to
check aspm_support_enabled or pdev->has_secondary_link or the VIA
quirk: pci_aspm_init() already checked that stuff, so we only need
to check pdev->link_state here.

Now that we are calling alloc_pcie_link_state() from pci_aspm_init()
, get rid of pci_function_0 function and detect downstream link in
pci_aspm_init_upstream() instead when the function number is 0.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 72 -
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index a80d64b..e33f84b 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -422,20 +422,6 @@ static void pcie_aspm_check_latency(struct pci_dev 
*endpoint)
}
 }
 
-/*
- * The L1 PM substate capability is only implemented in function 0 in a
- * multi function device.
- */
-static struct pci_dev *pci_function_0(struct pci_bus *linkbus)
-{
-   struct pci_dev *child;
-
-   list_for_each_entry(child, >devices, bus_list)
-   if (PCI_FUNC(child->devfn) == 0)
-   return child;
-   return NULL;
-}
-
 /* Calculate L1.2 PM substate timing parameters */
 static void aspm_calc_l1ss_info(struct pcie_link_state *link,
struct aspm_register_info *upreg,
@@ -798,7 +784,6 @@ static struct pcie_link_state *alloc_pcie_link_state(struct 
pci_dev *pdev)
INIT_LIST_HEAD(>children);
INIT_LIST_HEAD(>link);
link->pdev = pdev;
-   link->downstream = pci_function_0(pdev->subordinate);
 
/*
 * Root Ports and PCI/PCI-X to PCIe Bridges are roots of PCIe
@@ -828,11 +813,33 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
 
 static int pci_aspm_init_downstream(struct pci_dev *pdev)
 {
+   struct pcie_link_state *link;
+   struct pci_dev *parent;
+
+   /*
+* The L1 PM substate capability is only implemented in function 0 in a
+* multi function device.
+*/
+   if (PCI_FUNC(pdev->devfn) != 0)
+   return -EINVAL;
+
+   parent = pdev->bus->self;
+   if (!parent)
+   return -EINVAL;
+
+   link = parent->link_state;
+   link->downstream = pdev;
return 0;
 }
 
 static int pci_aspm_init_upstream(struct pci_dev *pdev)
 {
+   struct pcie_link_state *link;
+
+   link = alloc_pcie_link_state(pdev);
+   if (!link)
+   return -ENOMEM;
+
return 0;
 }
 
@@ -843,6 +850,17 @@ static int pci_aspm_init_upstream(struct pci_dev *pdev)
  */
 int pci_aspm_init(struct pci_dev *pdev)
 {
+   if (!aspm_support_enabled)
+   return 0;
+
+   if (!pci_is_pcie(pdev))
+   return -EINVAL;
+
+   /* VIA has a strange chipset, root port is under a bridge */
+   if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT &&
+   pdev->bus->self)
+   return 0;
+
if (!pdev->has_secondary_link)
return pci_aspm_init_downstream(pdev);
 
@@ -859,33 +877,16 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
struct pcie_link_state *link;
int blacklist = !!pcie_aspm_sanity_check(pdev);
 
-   if (!aspm_support_enabled)
-   return;
-
-   if (pdev->link_state)
-   return;
-
-   /*
-* We allocate pcie_link_state for the component on the upstream
-* end of a Link, so there's nothing to do unless this device has a
-* Link on its secondary side.
-*/
-   if (!pdev->has_secondary_link)
-   return;
-
-   /* VIA has a strange chipset, root port is under a bridge */
-   if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT &&
-   pdev->bus->self)
+   if (!pdev->link_state)
return;
 
+   link = pdev->link_state;
down_read(_bus_sem);
if (list_empty(>subordinate->devices))
goto out;
 
mutex_lock(_lock);
-   link = alloc_pcie_link_state(pdev);
-   if (!link)
-   goto unlock;
+
/*
 * Setup initial ASPM state. Note that we need to configure
 * upstream links also because capable state of them can be
@@ -910,7 +911,6 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
pcie_set_clkpm(link, policy_to_clkpm_state(link));
}
 
-unlock:
mutex_unlock(_lock);
 out:
up_read(_bus_sem);
-- 
1.9.1



[PATCH V8 1/5] PCI/ASPM: introduce pci_aspm_init() and add to pci_init_capabilities()

2017-04-07 Thread Sinan Kaya
We need a callback from pci_init_capabilities function for every
single new PCI device that is currently being added.

pci_aspm_init() will be used to save the power on state of the HW.

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=194895
Signed-off-by: Sinan Kaya 
---
 drivers/pci/pcie/aspm.c | 10 ++
 drivers/pci/probe.c |  3 +++
 include/linux/pci.h |  2 ++
 3 files changed, 15 insertions(+)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 1dfa10c..dc36717 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -827,6 +827,16 @@ static struct pcie_link_state 
*alloc_pcie_link_state(struct pci_dev *pdev)
 }
 
 /*
+ * pci_aspm_init: Initiate PCI express link state.
+ * It is called from device_add for every single pci device.
+ * @pdev: all pci devices
+ */
+int pci_aspm_init(struct pci_dev *pdev)
+{
+   return 0;
+}
+
+/*
  * pcie_aspm_init_link_state: Initiate PCI express link state.
  * It is called after the pcie and its children devices are scanned.
  * @pdev: the root port or switch downstream port
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index dfc9a27..1e19364 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1847,6 +1847,9 @@ static void pci_init_capabilities(struct pci_dev *dev)
 
/* Advanced Error Reporting */
pci_aer_init(dev);
+
+   /* Active State Power Management */
+   pci_aspm_init(dev);
 }
 
 /*
diff --git a/include/linux/pci.h b/include/linux/pci.h
index eb3da1a..8828dd7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1396,8 +1396,10 @@ static inline int pci_irq_get_node(struct pci_dev *pdev, 
int vec)
 
 #ifdef CONFIG_PCIEASPM
 bool pcie_aspm_support_enabled(void);
+int pci_aspm_init(struct pci_dev *pdev);
 #else
 static inline bool pcie_aspm_support_enabled(void) { return false; }
+static inline int pci_aspm_init(struct pci_dev *pdev) { return -ENODEV; }
 #endif
 
 #ifdef CONFIG_PCIEAER
-- 
1.9.1



I have something to discuss with you

2017-04-07 Thread Rosita
Hello my dear
My name is Rosita I have something to discuss with you please if you
don't mind you can reply me,(rositaadi...@yahoo.com)so that we can
discuss it in full, i will wait for your reply thank you,from Rosita


I have something to discuss with you

2017-04-07 Thread Rosita
Hello my dear
My name is Rosita I have something to discuss with you please if you
don't mind you can reply me,(rositaadi...@yahoo.com)so that we can
discuss it in full, i will wait for your reply thank you,from Rosita


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Daniel Micay
>> Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP))
>> somewhere sensible should make those "leaks" visible fast -- and their
>> exploitation impossible, i.e. fail hard.
>
> The leaks surely exist and now we'll just add an exploitable BUG.

That didn't seem to matter for landing a rewrite of KSTACKOVERFLOW
with a bunch of *known* DoS bugs dealt with in grsecurity and those
were known issues that were unfixed for no apparent reason other than
keeping egos intact. It looks like there are still some left...

In that case, there also wasn't a security/performance advantage.


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Daniel Micay
>> Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP))
>> somewhere sensible should make those "leaks" visible fast -- and their
>> exploitation impossible, i.e. fail hard.
>
> The leaks surely exist and now we'll just add an exploitable BUG.

That didn't seem to matter for landing a rewrite of KSTACKOVERFLOW
with a bunch of *known* DoS bugs dealt with in grsecurity and those
were known issues that were unfixed for no apparent reason other than
keeping egos intact. It looks like there are still some left...

In that case, there also wasn't a security/performance advantage.


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Daniel Micay
> Not too late to rename it. Scoped write? I think it makes change to

s/change/sense/


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Daniel Micay
> Not too late to rename it. Scoped write? I think it makes change to

s/change/sense/


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Daniel Micay
> I probably chose the wrong name for this feature (write rarely).
> That's _usually_ true, but "sensitive_write()" was getting rather
> long. The things that we need to protect with this are certainly stuff
> that doesn't get much writing, but some things are just plain
> sensitive (like page tables) and we should still try to be as fast as
> possible with them.

Not too late to rename it. Scoped write? I think it makes change to
use a different API than PaX for portability too, but not a different
x86 implementation. It's quite important to limit the writes to the
calling thread and it needs to perform well to be introduced widely.

> I'm all for a general case for the infrastructure (as Andy and Mark
> has mentioned), but I don't want to get into the situation where
> people start refusing to use it because it's "too slow" (for example,
> see refcount_t vs net-dev right now).

Meanwhile, the PaX implementation has improved to avoid the issues
that were brought up while only introducing a single always-predicted
(due to code placement) branch on the overflow flag. That seems to
have gone unnoticed upstream, where there's now a much slower
implementation that's not more secure, and is blocked from
introduction in areas where it's most needed based on the performance.
Not to mention that it's opt-in... which is never going to work.


Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap()

2017-04-07 Thread Daniel Micay
> I probably chose the wrong name for this feature (write rarely).
> That's _usually_ true, but "sensitive_write()" was getting rather
> long. The things that we need to protect with this are certainly stuff
> that doesn't get much writing, but some things are just plain
> sensitive (like page tables) and we should still try to be as fast as
> possible with them.

Not too late to rename it. Scoped write? I think it makes change to
use a different API than PaX for portability too, but not a different
x86 implementation. It's quite important to limit the writes to the
calling thread and it needs to perform well to be introduced widely.

> I'm all for a general case for the infrastructure (as Andy and Mark
> has mentioned), but I don't want to get into the situation where
> people start refusing to use it because it's "too slow" (for example,
> see refcount_t vs net-dev right now).

Meanwhile, the PaX implementation has improved to avoid the issues
that were brought up while only introducing a single always-predicted
(due to code placement) branch on the overflow flag. That seems to
have gone unnoticed upstream, where there's now a much slower
implementation that's not more secure, and is blocked from
introduction in areas where it's most needed based on the performance.
Not to mention that it's opt-in... which is never going to work.


Re: [PATCH 2/2] gpio: arizona: Add support for GPIOs that need to be maintained

2017-04-07 Thread kbuild test robot
Hi Charles,

[auto build test ERROR on gpio/for-next]
[also build test ERROR on v4.11-rc5 next-20170407]
[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/Charles-Keepax/mfd-arizona-Add-GPIO-maintain-state-flag/20170408-19
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 
for-next
config: x86_64-randconfig-x009-201714 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/gpio/gpio-arizona.c: In function 'arizona_gpio_direction_in':
>> drivers/gpio/gpio-arizona.c:44:3: error: implicit declaration of function 
>> 'pm_runtime_mark_last_busy' [-Werror=implicit-function-declaration]
  pm_runtime_mark_last_busy(chip->parent);
  ^
>> drivers/gpio/gpio-arizona.c:45:3: error: implicit declaration of function 
>> 'pm_runtime_put_autosuspend' [-Werror=implicit-function-declaration]
  pm_runtime_put_autosuspend(chip->parent);
  ^~
   drivers/gpio/gpio-arizona.c: In function 'arizona_gpio_set':
>> drivers/gpio/gpio-arizona.c:93:9: error: implicit declaration of function 
>> 'pm_runtime_get_sync' [-Werror=implicit-function-declaration]
  ret = pm_runtime_get_sync(chip->parent);
^~~
>> drivers/gpio/gpio-arizona.c:96:11: warning: 'return' with a value, in 
>> function returning void
   return ret;
  ^~~
   drivers/gpio/gpio-arizona.c:82:13: note: declared here
static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int 
value)
^~~~
   drivers/gpio/gpio-arizona.c: In function 'arizona_gpio_probe':
>> drivers/gpio/gpio-arizona.c:185:2: error: implicit declaration of function 
>> 'pm_runtime_enable' [-Werror=implicit-function-declaration]
 pm_runtime_enable(>dev);
 ^
   cc1: some warnings being treated as errors

vim +/pm_runtime_mark_last_busy +44 drivers/gpio/gpio-arizona.c

38  int status = arizona_gpio->status[offset];
39  
40  status &= (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT);
41  if (status == (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT)) {
42  arizona_gpio->status[offset] &= 
~ARIZONA_GP_STATE_OUTPUT;
43  
  > 44  pm_runtime_mark_last_busy(chip->parent);
  > 45  pm_runtime_put_autosuspend(chip->parent);
46  }
47  
48  return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + 
offset,
49ARIZONA_GPN_DIR, ARIZONA_GPN_DIR);
50  }
51  
52  static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
53  {
54  struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
55  struct arizona *arizona = arizona_gpio->arizona;
56  unsigned int val;
57  int ret;
58  
59  ret = regmap_read(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, 
);
60  if (ret < 0)
61  return ret;
62  
63  if (val & ARIZONA_GPN_LVL)
64  return 1;
65  else
66  return 0;
67  }
68  
69  static int arizona_gpio_direction_out(struct gpio_chip *chip,
70   unsigned offset, int value)
71  {
72  struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
73  struct arizona *arizona = arizona_gpio->arizona;
74  
75  if (value)
76  value = ARIZONA_GPN_LVL;
77  
78  return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + 
offset,
79ARIZONA_GPN_DIR | ARIZONA_GPN_LVL, 
value);
80  }
81  
82  static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, 
int value)
83  {
84  struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
85  struct arizona *arizona = arizona_gpio->arizona;
86  int status = arizona_gpio->status[offset];
87  int ret;
88  
89  status &= (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT);
90  if (status == ARIZONA_GP_MAINTAIN) {
91  arizona_gpio->status[offset] |= ARIZONA_GP_STATE_OUTPUT;
92  
  > 93  ret = pm_runtime_get_sync(chip->parent);
94  if (ret < 0) {
95  dev_err(chip->parent, "Failed to resume: %d\n", 
ret);
  > 96  return ret;
97  

Re: [PATCH 2/2] gpio: arizona: Add support for GPIOs that need to be maintained

2017-04-07 Thread kbuild test robot
Hi Charles,

[auto build test ERROR on gpio/for-next]
[also build test ERROR on v4.11-rc5 next-20170407]
[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/Charles-Keepax/mfd-arizona-Add-GPIO-maintain-state-flag/20170408-19
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 
for-next
config: x86_64-randconfig-x009-201714 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers/gpio/gpio-arizona.c: In function 'arizona_gpio_direction_in':
>> drivers/gpio/gpio-arizona.c:44:3: error: implicit declaration of function 
>> 'pm_runtime_mark_last_busy' [-Werror=implicit-function-declaration]
  pm_runtime_mark_last_busy(chip->parent);
  ^
>> drivers/gpio/gpio-arizona.c:45:3: error: implicit declaration of function 
>> 'pm_runtime_put_autosuspend' [-Werror=implicit-function-declaration]
  pm_runtime_put_autosuspend(chip->parent);
  ^~
   drivers/gpio/gpio-arizona.c: In function 'arizona_gpio_set':
>> drivers/gpio/gpio-arizona.c:93:9: error: implicit declaration of function 
>> 'pm_runtime_get_sync' [-Werror=implicit-function-declaration]
  ret = pm_runtime_get_sync(chip->parent);
^~~
>> drivers/gpio/gpio-arizona.c:96:11: warning: 'return' with a value, in 
>> function returning void
   return ret;
  ^~~
   drivers/gpio/gpio-arizona.c:82:13: note: declared here
static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int 
value)
^~~~
   drivers/gpio/gpio-arizona.c: In function 'arizona_gpio_probe':
>> drivers/gpio/gpio-arizona.c:185:2: error: implicit declaration of function 
>> 'pm_runtime_enable' [-Werror=implicit-function-declaration]
 pm_runtime_enable(>dev);
 ^
   cc1: some warnings being treated as errors

vim +/pm_runtime_mark_last_busy +44 drivers/gpio/gpio-arizona.c

38  int status = arizona_gpio->status[offset];
39  
40  status &= (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT);
41  if (status == (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT)) {
42  arizona_gpio->status[offset] &= 
~ARIZONA_GP_STATE_OUTPUT;
43  
  > 44  pm_runtime_mark_last_busy(chip->parent);
  > 45  pm_runtime_put_autosuspend(chip->parent);
46  }
47  
48  return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + 
offset,
49ARIZONA_GPN_DIR, ARIZONA_GPN_DIR);
50  }
51  
52  static int arizona_gpio_get(struct gpio_chip *chip, unsigned offset)
53  {
54  struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
55  struct arizona *arizona = arizona_gpio->arizona;
56  unsigned int val;
57  int ret;
58  
59  ret = regmap_read(arizona->regmap, ARIZONA_GPIO1_CTRL + offset, 
);
60  if (ret < 0)
61  return ret;
62  
63  if (val & ARIZONA_GPN_LVL)
64  return 1;
65  else
66  return 0;
67  }
68  
69  static int arizona_gpio_direction_out(struct gpio_chip *chip,
70   unsigned offset, int value)
71  {
72  struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
73  struct arizona *arizona = arizona_gpio->arizona;
74  
75  if (value)
76  value = ARIZONA_GPN_LVL;
77  
78  return regmap_update_bits(arizona->regmap, ARIZONA_GPIO1_CTRL + 
offset,
79ARIZONA_GPN_DIR | ARIZONA_GPN_LVL, 
value);
80  }
81  
82  static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, 
int value)
83  {
84  struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip);
85  struct arizona *arizona = arizona_gpio->arizona;
86  int status = arizona_gpio->status[offset];
87  int ret;
88  
89  status &= (ARIZONA_GP_MAINTAIN | ARIZONA_GP_STATE_OUTPUT);
90  if (status == ARIZONA_GP_MAINTAIN) {
91  arizona_gpio->status[offset] |= ARIZONA_GP_STATE_OUTPUT;
92  
  > 93  ret = pm_runtime_get_sync(chip->parent);
94  if (ret < 0) {
95  dev_err(chip->parent, "Failed to resume: %d\n", 
ret);
  > 96  return ret;
97  

Re: [PATCH 2/2] gpio: arizona: Add support for GPIOs that need to be maintained

2017-04-07 Thread kbuild test robot
Hi Charles,

[auto build test ERROR on gpio/for-next]
[also build test ERROR on v4.11-rc5 next-20170407]
[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/Charles-Keepax/mfd-arizona-Add-GPIO-maintain-state-flag/20170408-19
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 
for-next
config: x86_64-randconfig-x003-201714 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_direction_in':
   drivers//gpio/gpio-arizona.c:44:3: error: implicit declaration of function 
'pm_runtime_mark_last_busy' [-Werror=implicit-function-declaration]
  pm_runtime_mark_last_busy(chip->parent);
  ^
   drivers//gpio/gpio-arizona.c:45:3: error: implicit declaration of function 
'pm_runtime_put_autosuspend' [-Werror=implicit-function-declaration]
  pm_runtime_put_autosuspend(chip->parent);
  ^~
   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_set':
   drivers//gpio/gpio-arizona.c:93:9: error: implicit declaration of function 
'pm_runtime_get_sync' [-Werror=implicit-function-declaration]
  ret = pm_runtime_get_sync(chip->parent);
^~~
   drivers//gpio/gpio-arizona.c:96:11: warning: 'return' with a value, in 
function returning void
   return ret;
  ^~~
   drivers//gpio/gpio-arizona.c:82:13: note: declared here
static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int 
value)
^~~~
   In file included from include/linux/linkage.h:4:0,
from include/linux/kernel.h:6,
from drivers//gpio/gpio-arizona.c:15:
   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_of_xlate':
>> drivers//gpio/gpio-arizona.c:115:33: error: 'struct gpio_chip' has no member 
>> named 'of_gpio_n_cells'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
^
   include/linux/compiler.h:160:30: note: in definition of macro '__trace_if'
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^~~~
>> drivers//gpio/gpio-arizona.c:115:2: note: in expansion of macro 'if'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
 ^~
>> drivers//gpio/gpio-arizona.c:115:33: error: 'struct gpio_chip' has no member 
>> named 'of_gpio_n_cells'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
^
   include/linux/compiler.h:160:42: note: in definition of macro '__trace_if'
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^~~~
>> drivers//gpio/gpio-arizona.c:115:2: note: in expansion of macro 'if'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
 ^~
>> drivers//gpio/gpio-arizona.c:115:33: error: 'struct gpio_chip' has no member 
>> named 'of_gpio_n_cells'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
^
   include/linux/compiler.h:171:16: note: in definition of macro '__trace_if'
  __r = !!(cond); \
   ^~~~
>> drivers//gpio/gpio-arizona.c:115:2: note: in expansion of macro 'if'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
 ^~
   drivers//gpio/gpio-arizona.c: At top level:
>> drivers//gpio/gpio-arizona.c:138:2: error: unknown field 'of_xlate' 
>> specified in initializer
 .of_xlate  = arizona_gpio_of_xlate,
 ^
>> drivers//gpio/gpio-arizona.c:138:15: error: initialization from incompatible 
>> pointer type [-Werror=incompatible-pointer-types]
 .of_xlate  = arizona_gpio_of_xlate,
  ^
   drivers//gpio/gpio-arizona.c:138:15: note: (near initialization for 
'template_chip.read_reg')
>> drivers//gpio/gpio-arizona.c:139:2: error: unknown field 'of_gpio_n_cells' 
>> specified in initializer
 .of_gpio_n_cells = 2,
 ^
>> drivers//gpio/gpio-arizona.c:139:21: warning: initialization makes pointer 
>> from integer without a cast [-Wint-conversion]
 .of_gpio_n_cells = 2,
^
   drivers//gpio/gpio-arizona.c:139:21: note: (near initialization for 
'template_chip.write_reg')
   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_probe':
   drivers//gpio/gpio-arizona.c:185:2: error: implicit declaration of function 
'pm_runtime_enable' [-Werror=implicit-function-declaration]
 pm_runtime_enable(>dev);
 ^
   cc1: some warnings being treated as errors

vim +115 drivers//gpio/gpio-arizona.c

 9   *  under  th

Re: [PATCH 2/2] gpio: arizona: Add support for GPIOs that need to be maintained

2017-04-07 Thread kbuild test robot
Hi Charles,

[auto build test ERROR on gpio/for-next]
[also build test ERROR on v4.11-rc5 next-20170407]
[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/Charles-Keepax/mfd-arizona-Add-GPIO-maintain-state-flag/20170408-19
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git 
for-next
config: x86_64-randconfig-x003-201714 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_direction_in':
   drivers//gpio/gpio-arizona.c:44:3: error: implicit declaration of function 
'pm_runtime_mark_last_busy' [-Werror=implicit-function-declaration]
  pm_runtime_mark_last_busy(chip->parent);
  ^
   drivers//gpio/gpio-arizona.c:45:3: error: implicit declaration of function 
'pm_runtime_put_autosuspend' [-Werror=implicit-function-declaration]
  pm_runtime_put_autosuspend(chip->parent);
  ^~
   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_set':
   drivers//gpio/gpio-arizona.c:93:9: error: implicit declaration of function 
'pm_runtime_get_sync' [-Werror=implicit-function-declaration]
  ret = pm_runtime_get_sync(chip->parent);
^~~
   drivers//gpio/gpio-arizona.c:96:11: warning: 'return' with a value, in 
function returning void
   return ret;
  ^~~
   drivers//gpio/gpio-arizona.c:82:13: note: declared here
static void arizona_gpio_set(struct gpio_chip *chip, unsigned offset, int 
value)
^~~~
   In file included from include/linux/linkage.h:4:0,
from include/linux/kernel.h:6,
from drivers//gpio/gpio-arizona.c:15:
   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_of_xlate':
>> drivers//gpio/gpio-arizona.c:115:33: error: 'struct gpio_chip' has no member 
>> named 'of_gpio_n_cells'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
^
   include/linux/compiler.h:160:30: note: in definition of macro '__trace_if'
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^~~~
>> drivers//gpio/gpio-arizona.c:115:2: note: in expansion of macro 'if'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
 ^~
>> drivers//gpio/gpio-arizona.c:115:33: error: 'struct gpio_chip' has no member 
>> named 'of_gpio_n_cells'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
^
   include/linux/compiler.h:160:42: note: in definition of macro '__trace_if'
 if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
 ^~~~
>> drivers//gpio/gpio-arizona.c:115:2: note: in expansion of macro 'if'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
 ^~
>> drivers//gpio/gpio-arizona.c:115:33: error: 'struct gpio_chip' has no member 
>> named 'of_gpio_n_cells'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
^
   include/linux/compiler.h:171:16: note: in definition of macro '__trace_if'
  __r = !!(cond); \
   ^~~~
>> drivers//gpio/gpio-arizona.c:115:2: note: in expansion of macro 'if'
 if (gpiospec->args_count < chip->of_gpio_n_cells)
 ^~
   drivers//gpio/gpio-arizona.c: At top level:
>> drivers//gpio/gpio-arizona.c:138:2: error: unknown field 'of_xlate' 
>> specified in initializer
 .of_xlate  = arizona_gpio_of_xlate,
 ^
>> drivers//gpio/gpio-arizona.c:138:15: error: initialization from incompatible 
>> pointer type [-Werror=incompatible-pointer-types]
 .of_xlate  = arizona_gpio_of_xlate,
  ^
   drivers//gpio/gpio-arizona.c:138:15: note: (near initialization for 
'template_chip.read_reg')
>> drivers//gpio/gpio-arizona.c:139:2: error: unknown field 'of_gpio_n_cells' 
>> specified in initializer
 .of_gpio_n_cells = 2,
 ^
>> drivers//gpio/gpio-arizona.c:139:21: warning: initialization makes pointer 
>> from integer without a cast [-Wint-conversion]
 .of_gpio_n_cells = 2,
^
   drivers//gpio/gpio-arizona.c:139:21: note: (near initialization for 
'template_chip.write_reg')
   drivers//gpio/gpio-arizona.c: In function 'arizona_gpio_probe':
   drivers//gpio/gpio-arizona.c:185:2: error: implicit declaration of function 
'pm_runtime_enable' [-Werror=implicit-function-declaration]
 pm_runtime_enable(>dev);
 ^
   cc1: some warnings being treated as errors

vim +115 drivers//gpio/gpio-arizona.c

 9   *  under  th

Re: [PATCH v2 04/10] mm: make the try_to_munlock void function

2017-04-07 Thread alexander . levin
On Wed, Mar 15, 2017 at 02:24:47PM +0900, Minchan Kim wrote:
> try_to_munlock returns SWAP_MLOCK if the one of VMAs mapped
> the page has VM_LOCKED flag. In that time, VM set PG_mlocked to
> the page if the page is not pte-mapped THP which cannot be
> mlocked, either.
> 
> With that, __munlock_isolated_page can use PageMlocked to check
> whether try_to_munlock is successful or not without relying on
> try_to_munlock's retval. It helps to make try_to_unmap/try_to_unmap_one
> simple with upcoming patches.
> 
> Cc: Vlastimil Babka <vba...@suse.cz>
> Acked-by: Kirill A. Shutemov <kirill.shute...@linux.intel.com>
> Signed-off-by: Minchan Kim <minc...@kernel.org>

Hey Minchan,

I seem to be hitting one of those newly added BUG_ONs with trinity:

[   21.017404] page:ea000307a300 count:10 mapcount:7 
mapping:88010083f3a8 index:0x131
[   21.019974] flags: 
0x1fffc1c001d(locked|referenced|uptodate|dirty|swapbacked|unevictable|mlocked)
  [   21.022806] raw: 
01fffc1c001d 88010083f3a8 0131 000a0006 
  [   21.023974] raw: 
dead0100 dead0200  880109838008
[   21.026098] page dumped because: VM_BUG_ON_PAGE(PageMlocked(page))
[   21.026903] page->mem_cgroup:880109838008
  [ 
  21.027505] page allocated via order 0, migratetype Movable, gfp_mask 
0x14200ca(GFP_HIGHUSER_MOVABLE)
[   21.028783] save_stack_trace (arch/x86/kernel/stacktrace.c:60) 
[   21.029362] save_stack (./arch/x86/include/asm/current.h:14 
mm/kasan/kasan.c:50)
   [   21.029859] __set_page_owner (mm/page_owner.c:178)

 [   21.030414] get_page_from_freelist 
(./include/linux/page_owner.h:30 mm/page_alloc.c:1742 mm/page_alloc.c:1750 
mm/page_alloc.c:3097)[   21.031071] 
__alloc_pages_nodemask (mm/page_alloc.c:4011)   
   [   21.031716] 
alloc_pages_vma (./include/linux/mempolicy.h:77 ./include/linux/mempolicy.h:82 
mm/mempolicy.c:2024)[   21.032307] 
shmem_alloc_page (mm/shmem.c:1389 mm/shmem.c:1444)  
   [   21.032881] 
shmem_getpage_gfp (mm/shmem.c:1474 mm/shmem.c:1753) 
   [   21.033488] 
shmem_fault (mm/shmem.c:1987)   
   [   21.034055] 
__do_fault (mm/memory.c:3012)   
   [   21.034568] 
__handle_mm_fault (mm/memory.c:3449 mm/memory.c:3497 mm/memory.c:3723 
mm/memory.c:3841)[   
21.035192] handle_mm_fault (mm/memory.c:3878)   
  [   
21.035772] __do_page_fault (arch/x86/mm/fault.c:1446)   
  [   
21.037148] do_page_fault (arch/x86/mm/fault.c:1508 
./include/linux/context_tracking_state.h:30 
./include/linux/context_tracking.h:63 arch/x86/mm/fault.c:1509) 
[   21.037657] do_async_page_fault (./arch/x86/include/asm/traps.h:82 
arch/x86/kernel/kvm.c:264) 
[   21.038266] async_page_fault (arch/x86/entry/entry_64.S:1011) 
[   21.038901] [ cut here ]
[   21.039546] kernel BUG at mm/rmap.c:1560!
[   21.040126] invalid opcode:  [#1] SMP DEBUG_PAGEALLOC KASAN
[   21.040910] Modules linked in:
[   21.041345] CPU: 6 PID: 1317 Comm: trinity-c62 Tainted: GW   
4.11.0-rc5-next-20170407 #7
[   21.042761] task: 8801067d3e40 task.stack: 8800c06d
[   21.043572] RIP: 0010:try_to_munlock (??:?) 
[   21.044639] RSP: 0018:8800c06d71a0 EFLAGS: 00010296
[   21.045330] RAX:  RBX: 1100180dae36 RCX: 
[   21.046289] RDX:  RSI: 0086 RDI: ed00180dae28
[   21.047225] RBP: 8800c06d7358 R08: 1639 R09: 6c7561665f656761
[   21.048982] R10: ea000307a31c R11: 303378302f383278 R12: 8800c06d7330
[   21.049823] R13: ea000307a300 R14: 8800c06d72d0 R15: ea000307a300
[   21.050647] FS:  7f4ab05a7700() GS:880109d8() 
knlGS:
[   21.051574] CS:  0010 DS:  ES:  CR

Re: [PATCH v2 04/10] mm: make the try_to_munlock void function

2017-04-07 Thread alexander . levin
On Wed, Mar 15, 2017 at 02:24:47PM +0900, Minchan Kim wrote:
> try_to_munlock returns SWAP_MLOCK if the one of VMAs mapped
> the page has VM_LOCKED flag. In that time, VM set PG_mlocked to
> the page if the page is not pte-mapped THP which cannot be
> mlocked, either.
> 
> With that, __munlock_isolated_page can use PageMlocked to check
> whether try_to_munlock is successful or not without relying on
> try_to_munlock's retval. It helps to make try_to_unmap/try_to_unmap_one
> simple with upcoming patches.
> 
> Cc: Vlastimil Babka 
> Acked-by: Kirill A. Shutemov 
> Signed-off-by: Minchan Kim 

Hey Minchan,

I seem to be hitting one of those newly added BUG_ONs with trinity:

[   21.017404] page:ea000307a300 count:10 mapcount:7 
mapping:88010083f3a8 index:0x131
[   21.019974] flags: 
0x1fffc1c001d(locked|referenced|uptodate|dirty|swapbacked|unevictable|mlocked)
  [   21.022806] raw: 
01fffc1c001d 88010083f3a8 0131 000a0006 
  [   21.023974] raw: 
dead0100 dead0200  880109838008
[   21.026098] page dumped because: VM_BUG_ON_PAGE(PageMlocked(page))
[   21.026903] page->mem_cgroup:880109838008
  [ 
  21.027505] page allocated via order 0, migratetype Movable, gfp_mask 
0x14200ca(GFP_HIGHUSER_MOVABLE)
[   21.028783] save_stack_trace (arch/x86/kernel/stacktrace.c:60) 
[   21.029362] save_stack (./arch/x86/include/asm/current.h:14 
mm/kasan/kasan.c:50)
   [   21.029859] __set_page_owner (mm/page_owner.c:178)

 [   21.030414] get_page_from_freelist 
(./include/linux/page_owner.h:30 mm/page_alloc.c:1742 mm/page_alloc.c:1750 
mm/page_alloc.c:3097)[   21.031071] 
__alloc_pages_nodemask (mm/page_alloc.c:4011)   
   [   21.031716] 
alloc_pages_vma (./include/linux/mempolicy.h:77 ./include/linux/mempolicy.h:82 
mm/mempolicy.c:2024)[   21.032307] 
shmem_alloc_page (mm/shmem.c:1389 mm/shmem.c:1444)  
   [   21.032881] 
shmem_getpage_gfp (mm/shmem.c:1474 mm/shmem.c:1753) 
   [   21.033488] 
shmem_fault (mm/shmem.c:1987)   
   [   21.034055] 
__do_fault (mm/memory.c:3012)   
   [   21.034568] 
__handle_mm_fault (mm/memory.c:3449 mm/memory.c:3497 mm/memory.c:3723 
mm/memory.c:3841)[   
21.035192] handle_mm_fault (mm/memory.c:3878)   
  [   
21.035772] __do_page_fault (arch/x86/mm/fault.c:1446)   
  [   
21.037148] do_page_fault (arch/x86/mm/fault.c:1508 
./include/linux/context_tracking_state.h:30 
./include/linux/context_tracking.h:63 arch/x86/mm/fault.c:1509) 
[   21.037657] do_async_page_fault (./arch/x86/include/asm/traps.h:82 
arch/x86/kernel/kvm.c:264) 
[   21.038266] async_page_fault (arch/x86/entry/entry_64.S:1011) 
[   21.038901] [ cut here ]
[   21.039546] kernel BUG at mm/rmap.c:1560!
[   21.040126] invalid opcode:  [#1] SMP DEBUG_PAGEALLOC KASAN
[   21.040910] Modules linked in:
[   21.041345] CPU: 6 PID: 1317 Comm: trinity-c62 Tainted: GW   
4.11.0-rc5-next-20170407 #7
[   21.042761] task: 8801067d3e40 task.stack: 8800c06d
[   21.043572] RIP: 0010:try_to_munlock (??:?) 
[   21.044639] RSP: 0018:8800c06d71a0 EFLAGS: 00010296
[   21.045330] RAX:  RBX: 1100180dae36 RCX: 
[   21.046289] RDX:  RSI: 0086 RDI: ed00180dae28
[   21.047225] RBP: 8800c06d7358 R08: 1639 R09: 6c7561665f656761
[   21.048982] R10: ea000307a31c R11: 303378302f383278 R12: 8800c06d7330
[   21.049823] R13: ea000307a300 R14: 8800c06d72d0 R15: ea000307a300
[   21.050647] FS:  7f4ab05a7700() GS:880109d8() 
knlGS:
[   21.051574] CS:  0010 DS:  ES:  CR0: 80050033
[   21.052246] CR2: 7f4aafdebfc0 CR3: c069f000 CR4: 

Re: [PATCH 11/24] uswsusp: Disable when the kernel is locked down

2017-04-07 Thread poma
On 06.04.2017 22:25, Jiri Kosina wrote:
> On Thu, 6 Apr 2017, Rafael J. Wysocki wrote:
> 
> Your swap partition may be located on an NVDIMM or be encrypted.

 An NVDIMM should be considered the same as any other persistent storage.

 It may be encrypted, but where's the key stored, how easy is it to retrieve
 and does the swapout code know this?

> Isn't this a bit overly drastic?

 Perhaps, but if it's on disk and it's not encrypted, then maybe not.
>>>
>>> Right.
>>>
>>> Swap encryption is not mandatory and I'm not sure how the hibernate
>>> code can verify whether or not it is in use.
>>
>> BTW, SUSE has patches adding secure boot support to the hibernate code
>> and Jiri promised me to post them last year even. :-)
> 
> Oh, thanks for a friendly ping :) Adding Joey Lee to CC.
> 

Rafael J., are you talking about HIBERNATE_VERIFICATION ?

Ref.
https://github.com/joeyli/linux-s4sign/commits/s4sign-hmac-v2-v4.2-rc8
https://lkml.org/lkml/2015/8/11/47
https://bugzilla.redhat.com/show_bug.cgi?id=1330335



Re: [PATCH 11/24] uswsusp: Disable when the kernel is locked down

2017-04-07 Thread poma
On 06.04.2017 22:25, Jiri Kosina wrote:
> On Thu, 6 Apr 2017, Rafael J. Wysocki wrote:
> 
> Your swap partition may be located on an NVDIMM or be encrypted.

 An NVDIMM should be considered the same as any other persistent storage.

 It may be encrypted, but where's the key stored, how easy is it to retrieve
 and does the swapout code know this?

> Isn't this a bit overly drastic?

 Perhaps, but if it's on disk and it's not encrypted, then maybe not.
>>>
>>> Right.
>>>
>>> Swap encryption is not mandatory and I'm not sure how the hibernate
>>> code can verify whether or not it is in use.
>>
>> BTW, SUSE has patches adding secure boot support to the hibernate code
>> and Jiri promised me to post them last year even. :-)
> 
> Oh, thanks for a friendly ping :) Adding Joey Lee to CC.
> 

Rafael J., are you talking about HIBERNATE_VERIFICATION ?

Ref.
https://github.com/joeyli/linux-s4sign/commits/s4sign-hmac-v2-v4.2-rc8
https://lkml.org/lkml/2015/8/11/47
https://bugzilla.redhat.com/show_bug.cgi?id=1330335



Re: [PATCH -v6 13/13] futex: futex_lock_pi() vs PREEMPT_RT_FULL

2017-04-07 Thread Darren Hart
On Wed, Mar 22, 2017 at 11:36:00AM +0100, Peter Zijlstra wrote:
> When PREEMPT_RT_FULL does the spinlock -> rt_mutex substitution the PI
> chain code will (falsely) report a deadlock and BUG.
> 
> The problem is that we hold hb->lock (now an rt_mutex) while doing
> task_blocks_on_rt_mutex on the futex's pi_state::rtmutex. This, when
> interleaved just right with futex_unlock_pi() leads it to believe we
> have an AB-BA deadlock.
> 
>   Task1 (holds rt_mutex,  Task2 (does FUTEX_LOCK_PI)
>  does FUTEX_UNLOCK_PI)
> 
>   lock hb->lock
>   lock rt_mutex (as per start_proxy)
>   lock hb->lock
> 
> Which is a trivial AB-BA.
> 
> It is not an actual deadlock, because we won't be holding hb->lock by
> the time we actually block on rt_mutex, but the chainwalk code doesn't
> know that.
> 
> To avoid this problem, do the same thing we do in futex_unlock_pi()
> and drop hb->lock after acquiring wait_lock. This still fully
> serializes against futex_unlock_pi(), since adding to the wait_list
> does the very same lock dance, and removing it holds both locks.
> 
> Reported-by: Sebastian Andrzej Siewior 
> Suggested-by: Thomas Gleixner 
> Tested-by: Sebastian Andrzej Siewior 
> Signed-off-by: Peter Zijlstra (Intel) 

I have gone through each of these carefully, and while I'm not naive enough to
say "there are no possible locking problems", each of Peter's claims were
supported by my review. I went down a number of paths which concerned me, but
eventually they each proved not to be a problem, and it was impressive to see
the knot of locks loosen and come free in the last few patches. That's a really
nice piece of work Peter.

I've made several comments on the comment blocks and commit messages to clarify
things where I think they would have saved me time or were inconsistent. I've
only made one code change recommendation iirc, which was the simple type
declaration of a new uval from int to u32.

I would like to see more testing because... well... futexes. But, we don't have
a futex torture suite yet, but that is something I'm hoping to be looking into
in the near future. What testing we do have available has passed between my
futex selftests, the LTP suite, the pi_stress, and the RT runs by Sebastian.

Peter, I presume there will be a v7 with the u32 change and hopefully a couple
text updates?

Thanks,

-- 
Darren Hart
VMware Open Source Technology Center


Re: [PATCH -v6 13/13] futex: futex_lock_pi() vs PREEMPT_RT_FULL

2017-04-07 Thread Darren Hart
On Wed, Mar 22, 2017 at 11:36:00AM +0100, Peter Zijlstra wrote:
> When PREEMPT_RT_FULL does the spinlock -> rt_mutex substitution the PI
> chain code will (falsely) report a deadlock and BUG.
> 
> The problem is that we hold hb->lock (now an rt_mutex) while doing
> task_blocks_on_rt_mutex on the futex's pi_state::rtmutex. This, when
> interleaved just right with futex_unlock_pi() leads it to believe we
> have an AB-BA deadlock.
> 
>   Task1 (holds rt_mutex,  Task2 (does FUTEX_LOCK_PI)
>  does FUTEX_UNLOCK_PI)
> 
>   lock hb->lock
>   lock rt_mutex (as per start_proxy)
>   lock hb->lock
> 
> Which is a trivial AB-BA.
> 
> It is not an actual deadlock, because we won't be holding hb->lock by
> the time we actually block on rt_mutex, but the chainwalk code doesn't
> know that.
> 
> To avoid this problem, do the same thing we do in futex_unlock_pi()
> and drop hb->lock after acquiring wait_lock. This still fully
> serializes against futex_unlock_pi(), since adding to the wait_list
> does the very same lock dance, and removing it holds both locks.
> 
> Reported-by: Sebastian Andrzej Siewior 
> Suggested-by: Thomas Gleixner 
> Tested-by: Sebastian Andrzej Siewior 
> Signed-off-by: Peter Zijlstra (Intel) 

I have gone through each of these carefully, and while I'm not naive enough to
say "there are no possible locking problems", each of Peter's claims were
supported by my review. I went down a number of paths which concerned me, but
eventually they each proved not to be a problem, and it was impressive to see
the knot of locks loosen and come free in the last few patches. That's a really
nice piece of work Peter.

I've made several comments on the comment blocks and commit messages to clarify
things where I think they would have saved me time or were inconsistent. I've
only made one code change recommendation iirc, which was the simple type
declaration of a new uval from int to u32.

I would like to see more testing because... well... futexes. But, we don't have
a futex torture suite yet, but that is something I'm hoping to be looking into
in the near future. What testing we do have available has passed between my
futex selftests, the LTP suite, the pi_stress, and the RT runs by Sebastian.

Peter, I presume there will be a v7 with the u32 change and hopefully a couple
text updates?

Thanks,

-- 
Darren Hart
VMware Open Source Technology Center


Re: [PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Deepa Dinamani
>> - trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
>> + trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu 
>> ts:%lld.%09ld",
>>field->seqnum,
>>field->duration,
>>field->outer_duration,
>> -  field->timestamp.tv_sec,
>> +  (long long)field->timestamp.tv_sec,
>
> Refresh my memory. We need the cast because on 64 bit boxes
> timestamp.tv_sec is just a long?

This is only required until we change the definition of timespec64.
Right now it is defined as

#if __BITS_PER_LONG == 64
# define timespec64 timespec
#else
struct timespec64 {
time64_t tv_sec;
long tv_nsec;
};
#endif

And timespec.tv_sec is just long int on 64 bit machines.
This is why we need the cast now.

We will probably change this and only define __kernel_timespec instead
of timespec, leaving only one definition of timespec64.
At that time, we will not need this.

-Deepa


Re: [PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Deepa Dinamani
>> - trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
>> + trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu 
>> ts:%lld.%09ld",
>>field->seqnum,
>>field->duration,
>>field->outer_duration,
>> -  field->timestamp.tv_sec,
>> +  (long long)field->timestamp.tv_sec,
>
> Refresh my memory. We need the cast because on 64 bit boxes
> timestamp.tv_sec is just a long?

This is only required until we change the definition of timespec64.
Right now it is defined as

#if __BITS_PER_LONG == 64
# define timespec64 timespec
#else
struct timespec64 {
time64_t tv_sec;
long tv_nsec;
};
#endif

And timespec.tv_sec is just long int on 64 bit machines.
This is why we need the cast now.

We will probably change this and only define __kernel_timespec instead
of timespec, leaving only one definition of timespec64.
At that time, we will not need this.

-Deepa


Re: XTS Crypto Not Found In /proc/crypto Even After Compiled for 4.10.1.

2017-04-07 Thread Herbert Xu
On Thu, Apr 06, 2017 at 05:54:14PM +0800, Herbert Xu wrote:
> On Mon, Mar 13, 2017 at 07:06:01PM +0200, Krzysztof Kozlowski wrote:
> >
> > I bisected this to commit f1c131b45410 ("crypto: xts - Convert to
> > skcipher"). The s5p-sss driver stays the same... but the xts changes and
> > as a result we have a NULL pointer dereference (actually of value
> > 0004):
> > [   18.930195] Unable to handle kernel NULL pointer dereference at virtual 
> > address 0004
> > ...
> > [   18.972325] [] (post_crypt) from [] 
> > (decrypt_done+0x4c/0x54)
> > [   18.972343] [] (decrypt_done) from [] 
> > (s5p_aes_interrupt+0x1bc/0x208)
> > [   18.972360] [] (s5p_aes_interrupt) from [] 
> > (irq_thread_fn+0x1c/0x54)
> > 
> > Any hints?
> 
> I haven't found any smoking guns, but the locking between the
> tasklet and the IRQ routine looks suspect.  First of all the
> tasklet is modifying the dev structure without holding any locks.

I think I see the problem.  Could you please try this patch and
let me know if it fixes the crash?

---8<---
Subject: crypto: xts - Fix use-after-free on EINPROGRESS

When we get an EINPROGRESS completion in xts, we will end up marking
the request as done and freeing it.  This then blows up when the
request is really completed as we've already freed the memory.

Fixes: f1c131b45410 ("crypto: xts - Convert to skcipher")
Cc: 
Reported-by: Nathan Royce 
Reported-by: Krzysztof Kozlowski 
Signed-off-by: Herbert Xu 

diff --git a/crypto/xts.c b/crypto/xts.c
index e197e64..d86c11a 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -286,6 +286,13 @@ static void encrypt_done(struct crypto_async_request 
*areq, int err)
struct rctx *rctx;
 
rctx = skcipher_request_ctx(req);
+
+   if (err == -EINPROGRESS) {
+   if (rctx->left != req->cryptlen)
+   return;
+   goto out;
+   }
+
subreq = >subreq;
subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
 
@@ -293,6 +300,7 @@ static void encrypt_done(struct crypto_async_request *areq, 
int err)
if (rctx->left)
return;
 
+out:
skcipher_request_complete(req, err);
 }
 
@@ -330,6 +338,13 @@ static void decrypt_done(struct crypto_async_request 
*areq, int err)
struct rctx *rctx;
 
rctx = skcipher_request_ctx(req);
+
+   if (err == -EINPROGRESS) {
+   if (rctx->left != req->cryptlen)
+   return;
+   goto out;
+   }
+
subreq = >subreq;
subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
 
@@ -337,6 +352,7 @@ static void decrypt_done(struct crypto_async_request *areq, 
int err)
if (rctx->left)
return;
 
+out:
skcipher_request_complete(req, err);
 }
 
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


Re: XTS Crypto Not Found In /proc/crypto Even After Compiled for 4.10.1.

2017-04-07 Thread Herbert Xu
On Thu, Apr 06, 2017 at 05:54:14PM +0800, Herbert Xu wrote:
> On Mon, Mar 13, 2017 at 07:06:01PM +0200, Krzysztof Kozlowski wrote:
> >
> > I bisected this to commit f1c131b45410 ("crypto: xts - Convert to
> > skcipher"). The s5p-sss driver stays the same... but the xts changes and
> > as a result we have a NULL pointer dereference (actually of value
> > 0004):
> > [   18.930195] Unable to handle kernel NULL pointer dereference at virtual 
> > address 0004
> > ...
> > [   18.972325] [] (post_crypt) from [] 
> > (decrypt_done+0x4c/0x54)
> > [   18.972343] [] (decrypt_done) from [] 
> > (s5p_aes_interrupt+0x1bc/0x208)
> > [   18.972360] [] (s5p_aes_interrupt) from [] 
> > (irq_thread_fn+0x1c/0x54)
> > 
> > Any hints?
> 
> I haven't found any smoking guns, but the locking between the
> tasklet and the IRQ routine looks suspect.  First of all the
> tasklet is modifying the dev structure without holding any locks.

I think I see the problem.  Could you please try this patch and
let me know if it fixes the crash?

---8<---
Subject: crypto: xts - Fix use-after-free on EINPROGRESS

When we get an EINPROGRESS completion in xts, we will end up marking
the request as done and freeing it.  This then blows up when the
request is really completed as we've already freed the memory.

Fixes: f1c131b45410 ("crypto: xts - Convert to skcipher")
Cc: 
Reported-by: Nathan Royce 
Reported-by: Krzysztof Kozlowski 
Signed-off-by: Herbert Xu 

diff --git a/crypto/xts.c b/crypto/xts.c
index e197e64..d86c11a 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -286,6 +286,13 @@ static void encrypt_done(struct crypto_async_request 
*areq, int err)
struct rctx *rctx;
 
rctx = skcipher_request_ctx(req);
+
+   if (err == -EINPROGRESS) {
+   if (rctx->left != req->cryptlen)
+   return;
+   goto out;
+   }
+
subreq = >subreq;
subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
 
@@ -293,6 +300,7 @@ static void encrypt_done(struct crypto_async_request *areq, 
int err)
if (rctx->left)
return;
 
+out:
skcipher_request_complete(req, err);
 }
 
@@ -330,6 +338,13 @@ static void decrypt_done(struct crypto_async_request 
*areq, int err)
struct rctx *rctx;
 
rctx = skcipher_request_ctx(req);
+
+   if (err == -EINPROGRESS) {
+   if (rctx->left != req->cryptlen)
+   return;
+   goto out;
+   }
+
subreq = >subreq;
subreq->base.flags &= CRYPTO_TFM_REQ_MAY_BACKLOG;
 
@@ -337,6 +352,7 @@ static void decrypt_done(struct crypto_async_request *areq, 
int err)
if (rctx->left)
return;
 
+out:
skcipher_request_complete(req, err);
 }
 
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


[PATCH] ARM: dts: stm32f7: add STM32f769I & stm32f746 discovery board support

2017-04-07 Thread Vikas Manocha
Stm32f769I & stm32f746 are MCUs of stm32f7 family. Here are the major
spces of the two boards:

stm32f769I discovery board:
- Cortex-M7 core @216MHz
- 2MB mcu internal flash
- 512KB internal sram
- 16MB sdram memory
- 64MB qspi flash memory
- 4 inch wvga LCD-TFT Display

stm32f746 discovery board:
- Cortex-M7 core @216MHz
- 1MB mcu internal flash
- 320KB internal sram
- 8MB sdram memory
- 16MB qspi flash memory
- 4.3 inch 480x272 LCD-TFT display

Signed-off-by: Vikas Manocha 
---
 arch/arm/boot/dts/Makefile|   2 +
 arch/arm/boot/dts/stm32f746-disco.dts | 101 ++
 arch/arm/boot/dts/stm32f746.dtsi  |   2 +-
 arch/arm/boot/dts/stm32f769-disco.dts | 101 ++
 4 files changed, 205 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/dts/stm32f746-disco.dts
 create mode 100644 arch/arm/boot/dts/stm32f769-disco.dts

diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 0118084..a119f74 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -763,6 +763,8 @@ dtb-$(CONFIG_ARCH_STI) += \
 dtb-$(CONFIG_ARCH_STM32)+= \
stm32f429-disco.dtb \
stm32f469-disco.dtb \
+   stm32f746-disco.dtb \
+   stm32f769-disco.dtb \
stm32429i-eval.dtb \
stm32746g-eval.dtb
 dtb-$(CONFIG_MACH_SUN4I) += \
diff --git a/arch/arm/boot/dts/stm32f746-disco.dts 
b/arch/arm/boot/dts/stm32f746-disco.dts
new file mode 100644
index 000..c0e313f
--- /dev/null
+++ b/arch/arm/boot/dts/stm32f746-disco.dts
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2017 - Vikas MANOCHA 
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+#include "stm32f746.dtsi"
+#include 
+
+/ {
+   model = "STMicroelectronics STM32F746-DISCO board";
+   compatible = "st,stm32f746-disco", "st,stm32f746";
+
+   chosen {
+   bootargs = "root=/dev/ram";
+   stdout-path = "serial0:115200n8";
+   };
+
+   memory {
+   reg = <0xC000 0x80>;
+   };
+
+   aliases {
+   serial0 = 
+   };
+
+};
+
+_hse {
+   clock-frequency = <2500>;
+};
+
+ {
+   usart1_pins: usart1@0   {
+   pins1 {
+   pinmux = ;
+   bias-disable;
+   drive-push-pull;
+   slew-rate = <2>;
+   };
+   pins2 {
+   pinmux = ;
+   bias-disable;
+   };
+   };
+
+   qspi_pins: qspi@0 {
+   pins {
+   pinmux = ,
+  ,
+  ,
+  ,
+  ,
+  ;
+   slew-rate = <2>;
+   };
+   };
+};
+
+ {
+   pinctrl-0 = <_pins>;
+   pinctrl-names = 

[PATCH] ARM: dts: stm32f7: add STM32f769I & stm32f746 discovery board support

2017-04-07 Thread Vikas Manocha
Stm32f769I & stm32f746 are MCUs of stm32f7 family. Here are the major
spces of the two boards:

stm32f769I discovery board:
- Cortex-M7 core @216MHz
- 2MB mcu internal flash
- 512KB internal sram
- 16MB sdram memory
- 64MB qspi flash memory
- 4 inch wvga LCD-TFT Display

stm32f746 discovery board:
- Cortex-M7 core @216MHz
- 1MB mcu internal flash
- 320KB internal sram
- 8MB sdram memory
- 16MB qspi flash memory
- 4.3 inch 480x272 LCD-TFT display

Signed-off-by: Vikas Manocha 
---
 arch/arm/boot/dts/Makefile|   2 +
 arch/arm/boot/dts/stm32f746-disco.dts | 101 ++
 arch/arm/boot/dts/stm32f746.dtsi  |   2 +-
 arch/arm/boot/dts/stm32f769-disco.dts | 101 ++
 4 files changed, 205 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/dts/stm32f746-disco.dts
 create mode 100644 arch/arm/boot/dts/stm32f769-disco.dts

diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 0118084..a119f74 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -763,6 +763,8 @@ dtb-$(CONFIG_ARCH_STI) += \
 dtb-$(CONFIG_ARCH_STM32)+= \
stm32f429-disco.dtb \
stm32f469-disco.dtb \
+   stm32f746-disco.dtb \
+   stm32f769-disco.dtb \
stm32429i-eval.dtb \
stm32746g-eval.dtb
 dtb-$(CONFIG_MACH_SUN4I) += \
diff --git a/arch/arm/boot/dts/stm32f746-disco.dts 
b/arch/arm/boot/dts/stm32f746-disco.dts
new file mode 100644
index 000..c0e313f
--- /dev/null
+++ b/arch/arm/boot/dts/stm32f746-disco.dts
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2017 - Vikas MANOCHA 
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+#include "stm32f746.dtsi"
+#include 
+
+/ {
+   model = "STMicroelectronics STM32F746-DISCO board";
+   compatible = "st,stm32f746-disco", "st,stm32f746";
+
+   chosen {
+   bootargs = "root=/dev/ram";
+   stdout-path = "serial0:115200n8";
+   };
+
+   memory {
+   reg = <0xC000 0x80>;
+   };
+
+   aliases {
+   serial0 = 
+   };
+
+};
+
+_hse {
+   clock-frequency = <2500>;
+};
+
+ {
+   usart1_pins: usart1@0   {
+   pins1 {
+   pinmux = ;
+   bias-disable;
+   drive-push-pull;
+   slew-rate = <2>;
+   };
+   pins2 {
+   pinmux = ;
+   bias-disable;
+   };
+   };
+
+   qspi_pins: qspi@0 {
+   pins {
+   pinmux = ,
+  ,
+  ,
+  ,
+  ,
+  ;
+   slew-rate = <2>;
+   };
+   };
+};
+
+ {
+   pinctrl-0 = <_pins>;
+   pinctrl-names = "default";
+   status = "okay";
+};
diff --git 

Re: [PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Steven Rostedt
On Fri,  7 Apr 2017 17:57:00 -0700
Deepa Dinamani  wrote:

> struct timespec is not y2038 safe on 32 bit machines
> and needs to be replaced by struct timespec64
> in order to represent times beyond year 2038 on such
> machines.
> 
> Fix all the timestamp representation in struct trace_hwlat
> and all the corresponding implementations.
> 

> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 02a4aeb..08f9bab 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -4,7 +4,6 @@
>   * Copyright (C) 2008 Red Hat Inc, Steven Rostedt 
>   *
>   */
> -
>  #include 
>  #include 
>  #include 
> @@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
> flags,
>  
>   trace_assign_type(field, entry);
>  
> - trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
> + trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
>field->seqnum,
>field->duration,
>field->outer_duration,
> -  field->timestamp.tv_sec,
> +  (long long)field->timestamp.tv_sec,

Refresh my memory. We need the cast because on 64 bit boxes
timestamp.tv_sec is just a long?

Other than that.

Reviewed-by: Steven Rostedt (VMware) 

-- Steve

>field->timestamp.tv_nsec);
>  
>   if (field->nmi_count) {
> @@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int 
> flags,
>  
>   trace_assign_type(field, iter->ent);
>  
> - trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
> + trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
>field->duration,
>field->outer_duration,
> -  field->timestamp.tv_sec,
> +  (long long)field->timestamp.tv_sec,
>field->timestamp.tv_nsec,
>field->seqnum);
>  



Re: [PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Steven Rostedt
On Fri,  7 Apr 2017 17:57:00 -0700
Deepa Dinamani  wrote:

> struct timespec is not y2038 safe on 32 bit machines
> and needs to be replaced by struct timespec64
> in order to represent times beyond year 2038 on such
> machines.
> 
> Fix all the timestamp representation in struct trace_hwlat
> and all the corresponding implementations.
> 

> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 02a4aeb..08f9bab 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -4,7 +4,6 @@
>   * Copyright (C) 2008 Red Hat Inc, Steven Rostedt 
>   *
>   */
> -
>  #include 
>  #include 
>  #include 
> @@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
> flags,
>  
>   trace_assign_type(field, entry);
>  
> - trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
> + trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
>field->seqnum,
>field->duration,
>field->outer_duration,
> -  field->timestamp.tv_sec,
> +  (long long)field->timestamp.tv_sec,

Refresh my memory. We need the cast because on 64 bit boxes
timestamp.tv_sec is just a long?

Other than that.

Reviewed-by: Steven Rostedt (VMware) 

-- Steve

>field->timestamp.tv_nsec);
>  
>   if (field->nmi_count) {
> @@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int 
> flags,
>  
>   trace_assign_type(field, iter->ent);
>  
> - trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
> + trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
>field->duration,
>field->outer_duration,
> -  field->timestamp.tv_sec,
> +  (long long)field->timestamp.tv_sec,
>field->timestamp.tv_nsec,
>field->seqnum);
>  



[PATCH v4 06/10] soc: mediatek: avoid using fixed spm power status defines

2017-04-07 Thread Mars Cheng
Use variables to replace fixed defines since the offset
of the status of spm power might be different for some chips

Signed-off-by: Mars Cheng 
Signed-off-by: Kevin-CW Chen 
---
 drivers/soc/mediatek/mtk-scpsys.c |   33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/soc/mediatek/mtk-scpsys.c 
b/drivers/soc/mediatek/mtk-scpsys.c
index beb7916..eadbf0d 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -107,21 +107,28 @@ struct scp_domain {
struct regulator *supply;
 };
 
+struct scp_ctrl_reg {
+   int pwr_sta_offs;
+   int pwr_sta2nd_offs;
+};
+
 struct scp {
struct scp_domain *domains;
struct genpd_onecell_data pd_data;
struct device *dev;
void __iomem *base;
struct regmap *infracfg;
+   struct scp_ctrl_reg ctrl_reg;
 };
 
 static int scpsys_domain_is_on(struct scp_domain *scpd)
 {
struct scp *scp = scpd->scp;
 
-   u32 status = readl(scp->base + SPM_PWR_STATUS) & scpd->data->sta_mask;
-   u32 status2 = readl(scp->base + SPM_PWR_STATUS_2ND) &
-   scpd->data->sta_mask;
+   u32 status = readl(scp->base + scp->ctrl_reg.pwr_sta_offs) &
+   scpd->data->sta_mask;
+   u32 status2 = readl(scp->base + scp->ctrl_reg.pwr_sta2nd_offs) &
+   scpd->data->sta_mask;
 
/*
 * A domain is on when both status bits are set. If only one is set
@@ -346,7 +353,8 @@ static void init_clks(struct platform_device *pdev, struct 
clk **clk)
 }
 
 static struct scp *init_scp(struct platform_device *pdev,
-   const struct scp_domain_data *scp_domain_data, int num)
+   const struct scp_domain_data *scp_domain_data, int num,
+   struct scp_ctrl_reg *scp_ctrl_reg)
 {
struct genpd_onecell_data *pd_data;
struct resource *res;
@@ -358,6 +366,9 @@ static struct scp *init_scp(struct platform_device *pdev,
if (!scp)
return ERR_PTR(-ENOMEM);
 
+   scp->ctrl_reg.pwr_sta_offs = scp_ctrl_reg->pwr_sta_offs;
+   scp->ctrl_reg.pwr_sta2nd_offs = scp_ctrl_reg->pwr_sta2nd_offs;
+
scp->dev = >dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -556,8 +567,13 @@ static void mtk_register_power_domains(struct 
platform_device *pdev,
 static int __init scpsys_probe_mt2701(struct platform_device *pdev)
 {
struct scp *scp;
+   struct scp_ctrl_reg scp_reg;
 
-   scp = init_scp(pdev, scp_domain_data_mt2701, NUM_DOMAINS_MT2701);
+   scp_reg.pwr_sta_offs = SPM_PWR_STATUS;
+   scp_reg.pwr_sta2nd_offs = SPM_PWR_STATUS_2ND;
+
+   scp = init_scp(pdev, scp_domain_data_mt2701, NUM_DOMAINS_MT2701,
+  _reg);
if (IS_ERR(scp))
return PTR_ERR(scp);
 
@@ -667,8 +683,13 @@ static int __init scpsys_probe_mt8173(struct 
platform_device *pdev)
struct scp *scp;
struct genpd_onecell_data *pd_data;
int ret;
+   struct scp_ctrl_reg scp_reg;
+
+   scp_reg.pwr_sta_offs = SPM_PWR_STATUS;
+   scp_reg.pwr_sta2nd_offs = SPM_PWR_STATUS_2ND;
 
-   scp = init_scp(pdev, scp_domain_data_mt8173, NUM_DOMAINS_MT8173);
+   scp = init_scp(pdev, scp_domain_data_mt8173, NUM_DOMAINS_MT8173,
+  _reg);
if (IS_ERR(scp))
return PTR_ERR(scp);
 
-- 
1.7.9.5



[PATCH v4 06/10] soc: mediatek: avoid using fixed spm power status defines

2017-04-07 Thread Mars Cheng
Use variables to replace fixed defines since the offset
of the status of spm power might be different for some chips

Signed-off-by: Mars Cheng 
Signed-off-by: Kevin-CW Chen 
---
 drivers/soc/mediatek/mtk-scpsys.c |   33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/soc/mediatek/mtk-scpsys.c 
b/drivers/soc/mediatek/mtk-scpsys.c
index beb7916..eadbf0d 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -107,21 +107,28 @@ struct scp_domain {
struct regulator *supply;
 };
 
+struct scp_ctrl_reg {
+   int pwr_sta_offs;
+   int pwr_sta2nd_offs;
+};
+
 struct scp {
struct scp_domain *domains;
struct genpd_onecell_data pd_data;
struct device *dev;
void __iomem *base;
struct regmap *infracfg;
+   struct scp_ctrl_reg ctrl_reg;
 };
 
 static int scpsys_domain_is_on(struct scp_domain *scpd)
 {
struct scp *scp = scpd->scp;
 
-   u32 status = readl(scp->base + SPM_PWR_STATUS) & scpd->data->sta_mask;
-   u32 status2 = readl(scp->base + SPM_PWR_STATUS_2ND) &
-   scpd->data->sta_mask;
+   u32 status = readl(scp->base + scp->ctrl_reg.pwr_sta_offs) &
+   scpd->data->sta_mask;
+   u32 status2 = readl(scp->base + scp->ctrl_reg.pwr_sta2nd_offs) &
+   scpd->data->sta_mask;
 
/*
 * A domain is on when both status bits are set. If only one is set
@@ -346,7 +353,8 @@ static void init_clks(struct platform_device *pdev, struct 
clk **clk)
 }
 
 static struct scp *init_scp(struct platform_device *pdev,
-   const struct scp_domain_data *scp_domain_data, int num)
+   const struct scp_domain_data *scp_domain_data, int num,
+   struct scp_ctrl_reg *scp_ctrl_reg)
 {
struct genpd_onecell_data *pd_data;
struct resource *res;
@@ -358,6 +366,9 @@ static struct scp *init_scp(struct platform_device *pdev,
if (!scp)
return ERR_PTR(-ENOMEM);
 
+   scp->ctrl_reg.pwr_sta_offs = scp_ctrl_reg->pwr_sta_offs;
+   scp->ctrl_reg.pwr_sta2nd_offs = scp_ctrl_reg->pwr_sta2nd_offs;
+
scp->dev = >dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -556,8 +567,13 @@ static void mtk_register_power_domains(struct 
platform_device *pdev,
 static int __init scpsys_probe_mt2701(struct platform_device *pdev)
 {
struct scp *scp;
+   struct scp_ctrl_reg scp_reg;
 
-   scp = init_scp(pdev, scp_domain_data_mt2701, NUM_DOMAINS_MT2701);
+   scp_reg.pwr_sta_offs = SPM_PWR_STATUS;
+   scp_reg.pwr_sta2nd_offs = SPM_PWR_STATUS_2ND;
+
+   scp = init_scp(pdev, scp_domain_data_mt2701, NUM_DOMAINS_MT2701,
+  _reg);
if (IS_ERR(scp))
return PTR_ERR(scp);
 
@@ -667,8 +683,13 @@ static int __init scpsys_probe_mt8173(struct 
platform_device *pdev)
struct scp *scp;
struct genpd_onecell_data *pd_data;
int ret;
+   struct scp_ctrl_reg scp_reg;
+
+   scp_reg.pwr_sta_offs = SPM_PWR_STATUS;
+   scp_reg.pwr_sta2nd_offs = SPM_PWR_STATUS_2ND;
 
-   scp = init_scp(pdev, scp_domain_data_mt8173, NUM_DOMAINS_MT8173);
+   scp = init_scp(pdev, scp_domain_data_mt8173, NUM_DOMAINS_MT8173,
+  _reg);
if (IS_ERR(scp))
return PTR_ERR(scp);
 
-- 
1.7.9.5



Re: [PATCH -v6 12/13] futex: futex_unlock_pi() determinism

2017-04-07 Thread Darren Hart
On Wed, Mar 22, 2017 at 11:35:59AM +0100, Peter Zijlstra wrote:
> The problem with returning -EAGAIN when the waiter state mismatches is
> that it becomes very hard to proof a bounded execution time on the

prove

> operation. And seeing that this is a RT operation, this is somewhat

an RT

> important.
> 
> While in practise; given the previous patch; it will be very unlikely

Heh, that's not what semicolons are for ;-) Commas here, or a parenthetical.

> to ever really take more than one or two rounds, proving so becomes
> rather hard.
> 
> However, now that modifying wait_list is done while holding both
> hb->lock and wait_lock, we can avoid the scenario entirely if we
> acquire wait_lock while still holding hb-lock. Doing a hand-over,
> without leaving a hole.

Nice :)

-- 
Darren Hart
VMware Open Source Technology Center


[PATCH v4 08/10] dt-bindings: mediatek: add MT6797 power dt-bindings

2017-04-07 Thread Mars Cheng
This adds power dt-bindings for MT6797

Signed-off-by: Mars Cheng 
Signed-off-by: Kevin-CW Chen 
---
 .../devicetree/bindings/soc/mediatek/scpsys.txt|6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt 
b/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt
index 16fe94d..b1d165b 100644
--- a/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt
+++ b/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt
@@ -9,11 +9,14 @@ domain control.
 
 The driver implements the Generic PM domain bindings described in
 power/power_domain.txt. It provides the power domains defined in
-include/dt-bindings/power/mt8173-power.h and mt2701-power.h.
+- include/dt-bindings/power/mt8173-power.h
+- include/dt-bindings/power/mt6797-power.h
+- include/dt-bindings/power/mt2701-power.h
 
 Required properties:
 - compatible: Should be one of:
- "mediatek,mt2701-scpsys"
+   - "mediatek,mt6797-scpsys"
- "mediatek,mt8173-scpsys"
 - #power-domain-cells: Must be 1
 - reg: Address range of the SCPSYS unit
@@ -22,6 +25,7 @@ Required properties:
   These are clocks which hardware needs to be
   enabled before enabling certain power domains.
Required clocks for MT2701: "mm", "mfg", "ethif"
+   Required clocks for MT6797: "mm", "mfg", "vdec"
Required clocks for MT8173: "mm", "mfg", "venc", "venc_lt"
 
 Optional properties:
-- 
1.7.9.5



Re: [PATCH -v6 12/13] futex: futex_unlock_pi() determinism

2017-04-07 Thread Darren Hart
On Wed, Mar 22, 2017 at 11:35:59AM +0100, Peter Zijlstra wrote:
> The problem with returning -EAGAIN when the waiter state mismatches is
> that it becomes very hard to proof a bounded execution time on the

prove

> operation. And seeing that this is a RT operation, this is somewhat

an RT

> important.
> 
> While in practise; given the previous patch; it will be very unlikely

Heh, that's not what semicolons are for ;-) Commas here, or a parenthetical.

> to ever really take more than one or two rounds, proving so becomes
> rather hard.
> 
> However, now that modifying wait_list is done while holding both
> hb->lock and wait_lock, we can avoid the scenario entirely if we
> acquire wait_lock while still holding hb-lock. Doing a hand-over,
> without leaving a hole.

Nice :)

-- 
Darren Hart
VMware Open Source Technology Center


[PATCH v4 08/10] dt-bindings: mediatek: add MT6797 power dt-bindings

2017-04-07 Thread Mars Cheng
This adds power dt-bindings for MT6797

Signed-off-by: Mars Cheng 
Signed-off-by: Kevin-CW Chen 
---
 .../devicetree/bindings/soc/mediatek/scpsys.txt|6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt 
b/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt
index 16fe94d..b1d165b 100644
--- a/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt
+++ b/Documentation/devicetree/bindings/soc/mediatek/scpsys.txt
@@ -9,11 +9,14 @@ domain control.
 
 The driver implements the Generic PM domain bindings described in
 power/power_domain.txt. It provides the power domains defined in
-include/dt-bindings/power/mt8173-power.h and mt2701-power.h.
+- include/dt-bindings/power/mt8173-power.h
+- include/dt-bindings/power/mt6797-power.h
+- include/dt-bindings/power/mt2701-power.h
 
 Required properties:
 - compatible: Should be one of:
- "mediatek,mt2701-scpsys"
+   - "mediatek,mt6797-scpsys"
- "mediatek,mt8173-scpsys"
 - #power-domain-cells: Must be 1
 - reg: Address range of the SCPSYS unit
@@ -22,6 +25,7 @@ Required properties:
   These are clocks which hardware needs to be
   enabled before enabling certain power domains.
Required clocks for MT2701: "mm", "mfg", "ethif"
+   Required clocks for MT6797: "mm", "mfg", "vdec"
Required clocks for MT8173: "mm", "mfg", "venc", "venc_lt"
 
 Optional properties:
-- 
1.7.9.5



[PATCH v4 07/10] soc: mediatek: add vdec item for scpsys

2017-04-07 Thread Mars Cheng
for some chips, there is vdec item in scpsys, this patch adds it.

Signed-off-by: Mars Cheng 
---
 drivers/soc/mediatek/mtk-scpsys.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/soc/mediatek/mtk-scpsys.c 
b/drivers/soc/mediatek/mtk-scpsys.c
index eadbf0d..a8ba800 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -71,6 +71,7 @@ enum clk_id {
CLK_VENC,
CLK_VENC_LT,
CLK_ETHIF,
+   CLK_VDEC,
CLK_MAX,
 };
 
@@ -81,6 +82,7 @@ enum clk_id {
"venc",
"venc_lt",
"ethif",
+   "vdec",
NULL,
 };
 
-- 
1.7.9.5



[PATCH v4 07/10] soc: mediatek: add vdec item for scpsys

2017-04-07 Thread Mars Cheng
for some chips, there is vdec item in scpsys, this patch adds it.

Signed-off-by: Mars Cheng 
---
 drivers/soc/mediatek/mtk-scpsys.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/soc/mediatek/mtk-scpsys.c 
b/drivers/soc/mediatek/mtk-scpsys.c
index eadbf0d..a8ba800 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -71,6 +71,7 @@ enum clk_id {
CLK_VENC,
CLK_VENC_LT,
CLK_ETHIF,
+   CLK_VDEC,
CLK_MAX,
 };
 
@@ -81,6 +82,7 @@ enum clk_id {
"venc",
"venc_lt",
"ethif",
+   "vdec",
NULL,
 };
 
-- 
1.7.9.5



[PATCH v4 09/10] soc: mediatek: add MT6797 scpsys support

2017-04-07 Thread Mars Cheng
This adds scpsys support for MT6797

Signed-off-by: Mars Cheng 
Signed-off-by: Kevin-CW Chen 
---
 drivers/soc/mediatek/mtk-scpsys.c|  114 ++
 include/dt-bindings/power/mt6797-power.h |   30 
 2 files changed, 144 insertions(+)
 create mode 100644 include/dt-bindings/power/mt6797-power.h

diff --git a/drivers/soc/mediatek/mtk-scpsys.c 
b/drivers/soc/mediatek/mtk-scpsys.c
index a8ba800..ceb2cc4 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -21,6 +21,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #define SPM_VDE_PWR_CON0x0210
@@ -585,6 +586,116 @@ static int __init scpsys_probe_mt2701(struct 
platform_device *pdev)
 }
 
 /*
+ * MT6797 power domain support
+ */
+
+static const struct scp_domain_data scp_domain_data_mt6797[] = {
+   [MT6797_POWER_DOMAIN_VDEC] = {
+   .name = "vdec",
+   .sta_mask = BIT(7),
+   .ctl_offs = 0x300,
+   .sram_pdn_bits = GENMASK(8, 8),
+   .sram_pdn_ack_bits = GENMASK(12, 12),
+   .clk_id = {CLK_VDEC},
+   },
+   [MT6797_POWER_DOMAIN_VENC] = {
+   .name = "venc",
+   .sta_mask = BIT(21),
+   .ctl_offs = 0x304,
+   .sram_pdn_bits = GENMASK(11, 8),
+   .sram_pdn_ack_bits = GENMASK(15, 12),
+   .clk_id = {CLK_NONE},
+   },
+   [MT6797_POWER_DOMAIN_ISP] = {
+   .name = "isp",
+   .sta_mask = BIT(5),
+   .ctl_offs = 0x308,
+   .sram_pdn_bits = GENMASK(9, 8),
+   .sram_pdn_ack_bits = GENMASK(13, 12),
+   .clk_id = {CLK_NONE},
+   },
+   [MT6797_POWER_DOMAIN_MM] = {
+   .name = "mm",
+   .sta_mask = BIT(3),
+   .ctl_offs = 0x30C,
+   .sram_pdn_bits = GENMASK(8, 8),
+   .sram_pdn_ack_bits = GENMASK(12, 12),
+   .clk_id = {CLK_MM},
+   .bus_prot_mask = (BIT(1) | BIT(2)),
+   },
+   [MT6797_POWER_DOMAIN_AUDIO] = {
+   .name = "audio",
+   .sta_mask = BIT(24),
+   .ctl_offs = 0x314,
+   .sram_pdn_bits = GENMASK(11, 8),
+   .sram_pdn_ack_bits = GENMASK(15, 12),
+   .clk_id = {CLK_NONE},
+   },
+   [MT6797_POWER_DOMAIN_MFG_ASYNC] = {
+   .name = "mfg_async",
+   .sta_mask = BIT(13),
+   .ctl_offs = 0x334,
+   .sram_pdn_bits = 0,
+   .sram_pdn_ack_bits = 0,
+   .clk_id = {CLK_MFG},
+   },
+   [MT6797_POWER_DOMAIN_MJC] = {
+   .name = "mjc",
+   .sta_mask = BIT(20),
+   .ctl_offs = 0x310,
+   .sram_pdn_bits = GENMASK(8, 8),
+   .sram_pdn_ack_bits = GENMASK(12, 12),
+   .clk_id = {CLK_NONE},
+   },
+};
+
+#define NUM_DOMAINS_MT6797 ARRAY_SIZE(scp_domain_data_mt6797)
+#define SPM_PWR_STATUS_MT6797  0x0180
+#define SPM_PWR_STATUS_2ND_MT6797  0x0184
+
+static int __init scpsys_probe_mt6797(struct platform_device *pdev)
+{
+   struct scp *scp;
+   struct genpd_onecell_data *pd_data;
+   int ret;
+   struct scp_ctrl_reg scp_reg;
+
+   scp_reg.pwr_sta_offs = SPM_PWR_STATUS_MT6797;
+   scp_reg.pwr_sta2nd_offs = SPM_PWR_STATUS_2ND_MT6797;
+
+   scp = init_scp(pdev, scp_domain_data_mt6797, NUM_DOMAINS_MT6797,
+  _reg);
+   if (IS_ERR(scp))
+   return PTR_ERR(scp);
+
+   mtk_register_power_domains(pdev, scp, NUM_DOMAINS_MT6797);
+
+   pd_data = >pd_data;
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+
pd_data->domains[MT6797_POWER_DOMAIN_VDEC]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+pd_data->domains[MT6797_POWER_DOMAIN_ISP]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+
pd_data->domains[MT6797_POWER_DOMAIN_VENC]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+pd_data->domains[MT6797_POWER_DOMAIN_MJC]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   return 0;
+}
+
+/*
  * MT8173 power domain support
  */
 
@@ -721,6 +832,9 @@ static int __init scpsys_probe_mt8173(struct 
platform_device *pdev)

[PATCH v4 09/10] soc: mediatek: add MT6797 scpsys support

2017-04-07 Thread Mars Cheng
This adds scpsys support for MT6797

Signed-off-by: Mars Cheng 
Signed-off-by: Kevin-CW Chen 
---
 drivers/soc/mediatek/mtk-scpsys.c|  114 ++
 include/dt-bindings/power/mt6797-power.h |   30 
 2 files changed, 144 insertions(+)
 create mode 100644 include/dt-bindings/power/mt6797-power.h

diff --git a/drivers/soc/mediatek/mtk-scpsys.c 
b/drivers/soc/mediatek/mtk-scpsys.c
index a8ba800..ceb2cc4 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -21,6 +21,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #define SPM_VDE_PWR_CON0x0210
@@ -585,6 +586,116 @@ static int __init scpsys_probe_mt2701(struct 
platform_device *pdev)
 }
 
 /*
+ * MT6797 power domain support
+ */
+
+static const struct scp_domain_data scp_domain_data_mt6797[] = {
+   [MT6797_POWER_DOMAIN_VDEC] = {
+   .name = "vdec",
+   .sta_mask = BIT(7),
+   .ctl_offs = 0x300,
+   .sram_pdn_bits = GENMASK(8, 8),
+   .sram_pdn_ack_bits = GENMASK(12, 12),
+   .clk_id = {CLK_VDEC},
+   },
+   [MT6797_POWER_DOMAIN_VENC] = {
+   .name = "venc",
+   .sta_mask = BIT(21),
+   .ctl_offs = 0x304,
+   .sram_pdn_bits = GENMASK(11, 8),
+   .sram_pdn_ack_bits = GENMASK(15, 12),
+   .clk_id = {CLK_NONE},
+   },
+   [MT6797_POWER_DOMAIN_ISP] = {
+   .name = "isp",
+   .sta_mask = BIT(5),
+   .ctl_offs = 0x308,
+   .sram_pdn_bits = GENMASK(9, 8),
+   .sram_pdn_ack_bits = GENMASK(13, 12),
+   .clk_id = {CLK_NONE},
+   },
+   [MT6797_POWER_DOMAIN_MM] = {
+   .name = "mm",
+   .sta_mask = BIT(3),
+   .ctl_offs = 0x30C,
+   .sram_pdn_bits = GENMASK(8, 8),
+   .sram_pdn_ack_bits = GENMASK(12, 12),
+   .clk_id = {CLK_MM},
+   .bus_prot_mask = (BIT(1) | BIT(2)),
+   },
+   [MT6797_POWER_DOMAIN_AUDIO] = {
+   .name = "audio",
+   .sta_mask = BIT(24),
+   .ctl_offs = 0x314,
+   .sram_pdn_bits = GENMASK(11, 8),
+   .sram_pdn_ack_bits = GENMASK(15, 12),
+   .clk_id = {CLK_NONE},
+   },
+   [MT6797_POWER_DOMAIN_MFG_ASYNC] = {
+   .name = "mfg_async",
+   .sta_mask = BIT(13),
+   .ctl_offs = 0x334,
+   .sram_pdn_bits = 0,
+   .sram_pdn_ack_bits = 0,
+   .clk_id = {CLK_MFG},
+   },
+   [MT6797_POWER_DOMAIN_MJC] = {
+   .name = "mjc",
+   .sta_mask = BIT(20),
+   .ctl_offs = 0x310,
+   .sram_pdn_bits = GENMASK(8, 8),
+   .sram_pdn_ack_bits = GENMASK(12, 12),
+   .clk_id = {CLK_NONE},
+   },
+};
+
+#define NUM_DOMAINS_MT6797 ARRAY_SIZE(scp_domain_data_mt6797)
+#define SPM_PWR_STATUS_MT6797  0x0180
+#define SPM_PWR_STATUS_2ND_MT6797  0x0184
+
+static int __init scpsys_probe_mt6797(struct platform_device *pdev)
+{
+   struct scp *scp;
+   struct genpd_onecell_data *pd_data;
+   int ret;
+   struct scp_ctrl_reg scp_reg;
+
+   scp_reg.pwr_sta_offs = SPM_PWR_STATUS_MT6797;
+   scp_reg.pwr_sta2nd_offs = SPM_PWR_STATUS_2ND_MT6797;
+
+   scp = init_scp(pdev, scp_domain_data_mt6797, NUM_DOMAINS_MT6797,
+  _reg);
+   if (IS_ERR(scp))
+   return PTR_ERR(scp);
+
+   mtk_register_power_domains(pdev, scp, NUM_DOMAINS_MT6797);
+
+   pd_data = >pd_data;
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+
pd_data->domains[MT6797_POWER_DOMAIN_VDEC]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+pd_data->domains[MT6797_POWER_DOMAIN_ISP]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+
pd_data->domains[MT6797_POWER_DOMAIN_VENC]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   ret = pm_genpd_add_subdomain(pd_data->domains[MT6797_POWER_DOMAIN_MM],
+pd_data->domains[MT6797_POWER_DOMAIN_MJC]);
+   if (ret && IS_ENABLED(CONFIG_PM))
+   dev_err(>dev, "Failed to add subdomain: %d\n", ret);
+
+   return 0;
+}
+
+/*
  * MT8173 power domain support
  */
 
@@ -721,6 +832,9 @@ static int __init scpsys_probe_mt8173(struct 
platform_device *pdev)
.compatible = "mediatek,mt2701-scpsys",
 

[PATCH v4 04/10] clk: mediatek: add mt6797 clock IDs

2017-04-07 Thread Mars Cheng
Signed-off-by: Mars Cheng 
---
 include/dt-bindings/clock/mt6797-clk.h |  281 
 1 file changed, 281 insertions(+)
 create mode 100644 include/dt-bindings/clock/mt6797-clk.h

diff --git a/include/dt-bindings/clock/mt6797-clk.h 
b/include/dt-bindings/clock/mt6797-clk.h
new file mode 100644
index 000..e48aa47
--- /dev/null
+++ b/include/dt-bindings/clock/mt6797-clk.h
@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Kevin Chen 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _DT_BINDINGS_CLK_MT6797_H
+#define _DT_BINDINGS_CLK_MT6797_H
+
+/* TOPCKGEN */
+#defineCLK_TOP_MUX_ULPOSC_AXI_CK_MUX_PRE   1
+#defineCLK_TOP_MUX_ULPOSC_AXI_CK_MUX   2
+#defineCLK_TOP_MUX_AXI 3
+#defineCLK_TOP_MUX_MEM 4
+#defineCLK_TOP_MUX_DDRPHYCFG   5
+#defineCLK_TOP_MUX_MM  6
+#defineCLK_TOP_MUX_PWM 7
+#defineCLK_TOP_MUX_VDEC8
+#defineCLK_TOP_MUX_VENC9
+#defineCLK_TOP_MUX_MFG 10
+#defineCLK_TOP_MUX_CAMTG   11
+#defineCLK_TOP_MUX_UART12
+#defineCLK_TOP_MUX_SPI 13
+#defineCLK_TOP_MUX_ULPOSC_SPI_CK_MUX   14
+#defineCLK_TOP_MUX_USB20   15
+#defineCLK_TOP_MUX_MSDC50_0_HCLK   16
+#defineCLK_TOP_MUX_MSDC50_017
+#defineCLK_TOP_MUX_MSDC30_118
+#defineCLK_TOP_MUX_MSDC30_219
+#defineCLK_TOP_MUX_AUDIO   20
+#defineCLK_TOP_MUX_AUD_INTBUS  21
+#defineCLK_TOP_MUX_PMICSPI 22
+#defineCLK_TOP_MUX_SCP 23
+#defineCLK_TOP_MUX_ATB 24
+#defineCLK_TOP_MUX_MJC 25
+#defineCLK_TOP_MUX_DPI026
+#defineCLK_TOP_MUX_AUD_1   27
+#defineCLK_TOP_MUX_AUD_2   28
+#defineCLK_TOP_MUX_SSUSB_TOP_SYS   29
+#defineCLK_TOP_MUX_SPM 30
+#defineCLK_TOP_MUX_BSI_SPI 31
+#defineCLK_TOP_MUX_AUDIO_H 32
+#defineCLK_TOP_MUX_ANC_MD3233
+#defineCLK_TOP_MUX_MFG_52M 34
+#defineCLK_TOP_SYSPLL_CK   35
+#defineCLK_TOP_SYSPLL_D2   36
+#defineCLK_TOP_SYSPLL1_D2  37
+#defineCLK_TOP_SYSPLL1_D4  38
+#defineCLK_TOP_SYSPLL1_D8  39
+#defineCLK_TOP_SYSPLL1_D16 40
+#defineCLK_TOP_SYSPLL_D3   41
+#defineCLK_TOP_SYSPLL_D3_D342
+#defineCLK_TOP_SYSPLL2_D2  43
+#defineCLK_TOP_SYSPLL2_D4  44
+#defineCLK_TOP_SYSPLL2_D8  45
+#defineCLK_TOP_SYSPLL_D5   46
+#defineCLK_TOP_SYSPLL3_D2  47
+#defineCLK_TOP_SYSPLL3_D4  48
+#defineCLK_TOP_SYSPLL_D7   49
+#defineCLK_TOP_SYSPLL4_D2  50
+#defineCLK_TOP_SYSPLL4_D4  51
+#defineCLK_TOP_UNIVPLL_CK  52
+#defineCLK_TOP_UNIVPLL_D7  53
+#defineCLK_TOP_UNIVPLL_D26 54
+#defineCLK_TOP_SSUSB_PHY_48M_CK55
+#defineCLK_TOP_USB_PHY48M_CK   56
+#defineCLK_TOP_UNIVPLL_D2  57
+#defineCLK_TOP_UNIVPLL1_D2 58
+#defineCLK_TOP_UNIVPLL1_D4 59
+#defineCLK_TOP_UNIVPLL1_D8 60
+#defineCLK_TOP_UNIVPLL_D3  61
+#defineCLK_TOP_UNIVPLL2_D2 62
+#defineCLK_TOP_UNIVPLL2_D4 63
+#defineCLK_TOP_UNIVPLL2_D8 64
+#defineCLK_TOP_UNIVPLL_D5  65
+#defineCLK_TOP_UNIVPLL3_D2 66
+#define

[PATCH v4 04/10] clk: mediatek: add mt6797 clock IDs

2017-04-07 Thread Mars Cheng
Signed-off-by: Mars Cheng 
---
 include/dt-bindings/clock/mt6797-clk.h |  281 
 1 file changed, 281 insertions(+)
 create mode 100644 include/dt-bindings/clock/mt6797-clk.h

diff --git a/include/dt-bindings/clock/mt6797-clk.h 
b/include/dt-bindings/clock/mt6797-clk.h
new file mode 100644
index 000..e48aa47
--- /dev/null
+++ b/include/dt-bindings/clock/mt6797-clk.h
@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Kevin Chen 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _DT_BINDINGS_CLK_MT6797_H
+#define _DT_BINDINGS_CLK_MT6797_H
+
+/* TOPCKGEN */
+#defineCLK_TOP_MUX_ULPOSC_AXI_CK_MUX_PRE   1
+#defineCLK_TOP_MUX_ULPOSC_AXI_CK_MUX   2
+#defineCLK_TOP_MUX_AXI 3
+#defineCLK_TOP_MUX_MEM 4
+#defineCLK_TOP_MUX_DDRPHYCFG   5
+#defineCLK_TOP_MUX_MM  6
+#defineCLK_TOP_MUX_PWM 7
+#defineCLK_TOP_MUX_VDEC8
+#defineCLK_TOP_MUX_VENC9
+#defineCLK_TOP_MUX_MFG 10
+#defineCLK_TOP_MUX_CAMTG   11
+#defineCLK_TOP_MUX_UART12
+#defineCLK_TOP_MUX_SPI 13
+#defineCLK_TOP_MUX_ULPOSC_SPI_CK_MUX   14
+#defineCLK_TOP_MUX_USB20   15
+#defineCLK_TOP_MUX_MSDC50_0_HCLK   16
+#defineCLK_TOP_MUX_MSDC50_017
+#defineCLK_TOP_MUX_MSDC30_118
+#defineCLK_TOP_MUX_MSDC30_219
+#defineCLK_TOP_MUX_AUDIO   20
+#defineCLK_TOP_MUX_AUD_INTBUS  21
+#defineCLK_TOP_MUX_PMICSPI 22
+#defineCLK_TOP_MUX_SCP 23
+#defineCLK_TOP_MUX_ATB 24
+#defineCLK_TOP_MUX_MJC 25
+#defineCLK_TOP_MUX_DPI026
+#defineCLK_TOP_MUX_AUD_1   27
+#defineCLK_TOP_MUX_AUD_2   28
+#defineCLK_TOP_MUX_SSUSB_TOP_SYS   29
+#defineCLK_TOP_MUX_SPM 30
+#defineCLK_TOP_MUX_BSI_SPI 31
+#defineCLK_TOP_MUX_AUDIO_H 32
+#defineCLK_TOP_MUX_ANC_MD3233
+#defineCLK_TOP_MUX_MFG_52M 34
+#defineCLK_TOP_SYSPLL_CK   35
+#defineCLK_TOP_SYSPLL_D2   36
+#defineCLK_TOP_SYSPLL1_D2  37
+#defineCLK_TOP_SYSPLL1_D4  38
+#defineCLK_TOP_SYSPLL1_D8  39
+#defineCLK_TOP_SYSPLL1_D16 40
+#defineCLK_TOP_SYSPLL_D3   41
+#defineCLK_TOP_SYSPLL_D3_D342
+#defineCLK_TOP_SYSPLL2_D2  43
+#defineCLK_TOP_SYSPLL2_D4  44
+#defineCLK_TOP_SYSPLL2_D8  45
+#defineCLK_TOP_SYSPLL_D5   46
+#defineCLK_TOP_SYSPLL3_D2  47
+#defineCLK_TOP_SYSPLL3_D4  48
+#defineCLK_TOP_SYSPLL_D7   49
+#defineCLK_TOP_SYSPLL4_D2  50
+#defineCLK_TOP_SYSPLL4_D4  51
+#defineCLK_TOP_UNIVPLL_CK  52
+#defineCLK_TOP_UNIVPLL_D7  53
+#defineCLK_TOP_UNIVPLL_D26 54
+#defineCLK_TOP_SSUSB_PHY_48M_CK55
+#defineCLK_TOP_USB_PHY48M_CK   56
+#defineCLK_TOP_UNIVPLL_D2  57
+#defineCLK_TOP_UNIVPLL1_D2 58
+#defineCLK_TOP_UNIVPLL1_D4 59
+#defineCLK_TOP_UNIVPLL1_D8 60
+#defineCLK_TOP_UNIVPLL_D3  61
+#defineCLK_TOP_UNIVPLL2_D2 62
+#defineCLK_TOP_UNIVPLL2_D4 63
+#defineCLK_TOP_UNIVPLL2_D8 64
+#defineCLK_TOP_UNIVPLL_D5  65
+#defineCLK_TOP_UNIVPLL3_D2 66
+#defineCLK_TOP_UNIVPLL3_D4 67
+#define

[PATCH v4 01/10] dt-bindings: mediatek: Add bindings for mediatek MT6797 Platform

2017-04-07 Thread Mars Cheng
This adds dt-binding documentation for Mediatek MT6797. Only
include very basic items, gic, uart timer and cpu.

Signed-off-by: Mars Cheng 
Acked-by: Rob Herring 
---
 Documentation/devicetree/bindings/arm/mediatek.txt |4 
 .../interrupt-controller/mediatek,sysirq.txt   |1 +
 .../devicetree/bindings/serial/mtk-uart.txt|1 +
 3 files changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/mediatek.txt 
b/Documentation/devicetree/bindings/arm/mediatek.txt
index c860b24..2d3344d 100644
--- a/Documentation/devicetree/bindings/arm/mediatek.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek.txt
@@ -12,6 +12,7 @@ compatible: Must contain one of
"mediatek,mt6592"
"mediatek,mt6755"
"mediatek,mt6795"
+   "mediatek,mt6797"
"mediatek,mt7623"
"mediatek,mt8127"
"mediatek,mt8135"
@@ -38,6 +39,9 @@ Supported boards:
 - Evaluation board for MT6795(Helio X10):
 Required root node properties:
   - compatible = "mediatek,mt6795-evb", "mediatek,mt6795";
+- Evaluation board for MT6797(Helio X20):
+Required root node properties:
+  - compatible = "mediatek,mt6797-evb", "mediatek,mt6797";
 - Evaluation board for MT7623:
 Required root node properties:
   - compatible = "mediatek,mt7623-evb", "mediatek,mt7623";
diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt 
b/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
index 40bf9b9..04e162a 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
@@ -9,6 +9,7 @@ Required properties:
"mediatek,mt8135-sysirq"
"mediatek,mt8127-sysirq"
"mediatek,mt6795-sysirq"
+   "mediatek,mt6797-sysirq"
"mediatek,mt6755-sysirq"
"mediatek,mt6592-sysirq"
"mediatek,mt6589-sysirq"
diff --git a/Documentation/devicetree/bindings/serial/mtk-uart.txt 
b/Documentation/devicetree/bindings/serial/mtk-uart.txt
index 0015c72..5b8513d 100644
--- a/Documentation/devicetree/bindings/serial/mtk-uart.txt
+++ b/Documentation/devicetree/bindings/serial/mtk-uart.txt
@@ -8,6 +8,7 @@ Required properties:
   * "mediatek,mt6589-uart" for MT6589 compatible UARTS
   * "mediatek,mt6755-uart" for MT6755 compatible UARTS
   * "mediatek,mt6795-uart" for MT6795 compatible UARTS
+  * "mediatek,mt6797-uart" for MT6797 compatible UARTS
   * "mediatek,mt7623-uart" for MT7623 compatible UARTS
   * "mediatek,mt8127-uart" for MT8127 compatible UARTS
   * "mediatek,mt8135-uart" for MT8135 compatible UARTS
-- 
1.7.9.5



[PATCH v4 01/10] dt-bindings: mediatek: Add bindings for mediatek MT6797 Platform

2017-04-07 Thread Mars Cheng
This adds dt-binding documentation for Mediatek MT6797. Only
include very basic items, gic, uart timer and cpu.

Signed-off-by: Mars Cheng 
Acked-by: Rob Herring 
---
 Documentation/devicetree/bindings/arm/mediatek.txt |4 
 .../interrupt-controller/mediatek,sysirq.txt   |1 +
 .../devicetree/bindings/serial/mtk-uart.txt|1 +
 3 files changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/mediatek.txt 
b/Documentation/devicetree/bindings/arm/mediatek.txt
index c860b24..2d3344d 100644
--- a/Documentation/devicetree/bindings/arm/mediatek.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek.txt
@@ -12,6 +12,7 @@ compatible: Must contain one of
"mediatek,mt6592"
"mediatek,mt6755"
"mediatek,mt6795"
+   "mediatek,mt6797"
"mediatek,mt7623"
"mediatek,mt8127"
"mediatek,mt8135"
@@ -38,6 +39,9 @@ Supported boards:
 - Evaluation board for MT6795(Helio X10):
 Required root node properties:
   - compatible = "mediatek,mt6795-evb", "mediatek,mt6795";
+- Evaluation board for MT6797(Helio X20):
+Required root node properties:
+  - compatible = "mediatek,mt6797-evb", "mediatek,mt6797";
 - Evaluation board for MT7623:
 Required root node properties:
   - compatible = "mediatek,mt7623-evb", "mediatek,mt7623";
diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt 
b/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
index 40bf9b9..04e162a 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/mediatek,sysirq.txt
@@ -9,6 +9,7 @@ Required properties:
"mediatek,mt8135-sysirq"
"mediatek,mt8127-sysirq"
"mediatek,mt6795-sysirq"
+   "mediatek,mt6797-sysirq"
"mediatek,mt6755-sysirq"
"mediatek,mt6592-sysirq"
"mediatek,mt6589-sysirq"
diff --git a/Documentation/devicetree/bindings/serial/mtk-uart.txt 
b/Documentation/devicetree/bindings/serial/mtk-uart.txt
index 0015c72..5b8513d 100644
--- a/Documentation/devicetree/bindings/serial/mtk-uart.txt
+++ b/Documentation/devicetree/bindings/serial/mtk-uart.txt
@@ -8,6 +8,7 @@ Required properties:
   * "mediatek,mt6589-uart" for MT6589 compatible UARTS
   * "mediatek,mt6755-uart" for MT6755 compatible UARTS
   * "mediatek,mt6795-uart" for MT6795 compatible UARTS
+  * "mediatek,mt6797-uart" for MT6797 compatible UARTS
   * "mediatek,mt7623-uart" for MT7623 compatible UARTS
   * "mediatek,mt8127-uart" for MT8127 compatible UARTS
   * "mediatek,mt8135-uart" for MT8135 compatible UARTS
-- 
1.7.9.5



[PATCH v4 02/10] arm64: dts: mediatek: add mt6797 support

2017-04-07 Thread Mars Cheng
This adds basic chip support for MT6797 SoC.

Signed-off-by: Mars Cheng 
---
 arch/arm64/boot/dts/mediatek/Makefile   |1 +
 arch/arm64/boot/dts/mediatek/mt6797-evb.dts |   36 ++
 arch/arm64/boot/dts/mediatek/mt6797.dtsi|  182 +++
 3 files changed, 219 insertions(+)
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797-evb.dts
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797.dtsi

diff --git a/arch/arm64/boot/dts/mediatek/Makefile 
b/arch/arm64/boot/dts/mediatek/Makefile
index 9fbfd32..015eb07 100644
--- a/arch/arm64/boot/dts/mediatek/Makefile
+++ b/arch/arm64/boot/dts/mediatek/Makefile
@@ -1,5 +1,6 @@
 dtb-$(CONFIG_ARCH_MEDIATEK) += mt6755-evb.dtb
 dtb-$(CONFIG_ARCH_MEDIATEK) += mt6795-evb.dtb
+dtb-$(CONFIG_ARCH_MEDIATEK) += mt6797-evb.dtb
 dtb-$(CONFIG_ARCH_MEDIATEK) += mt8173-evb.dtb
 
 always := $(dtb-y)
diff --git a/arch/arm64/boot/dts/mediatek/mt6797-evb.dts 
b/arch/arm64/boot/dts/mediatek/mt6797-evb.dts
new file mode 100644
index 000..c79109c
--- /dev/null
+++ b/arch/arm64/boot/dts/mediatek/mt6797-evb.dts
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Mars.C 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/dts-v1/;
+#include "mt6797.dtsi"
+
+/ {
+   model = "MediaTek MT6797 Evaluation Board";
+   compatible = "mediatek,mt6797-evb", "mediatek,mt6797";
+
+   aliases {
+   serial0 = 
+   };
+
+   memory@4000 {
+   device_type = "memory";
+   reg = <0 0x4000 0 0x1e80>;
+   };
+
+   chosen {};
+};
+
+ {
+   status = "okay";
+};
diff --git a/arch/arm64/boot/dts/mediatek/mt6797.dtsi 
b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
new file mode 100644
index 000..cf4529e
--- /dev/null
+++ b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Mars.C 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+
+/ {
+   compatible = "mediatek,mt6797";
+   interrupt-parent = <>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+
+   psci {
+   compatible = "arm,psci-0.2";
+   method = "smc";
+   };
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   cpu0: cpu@0 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x000>;
+   };
+
+   cpu1: cpu@1 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x001>;
+   };
+
+   cpu2: cpu@2 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x002>;
+   };
+
+   cpu3: cpu@3 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x003>;
+   };
+
+   cpu4: cpu@100 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x100>;
+   };
+
+   cpu5: cpu@101 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x101>;
+   };
+
+   cpu6: cpu@102 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x102>;
+   };
+
+   cpu7: cpu@103 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+ 

[PATCH v4 05/10] clk: mediatek: add clk support for MT6797

2017-04-07 Thread Mars Cheng
From: Kevin-CW Chen 

Add MT6797 clock support, include topckgen, apmixedsys, infracfg
and subsystem clocks

Signed-off-by: Kevin-CW Chen 
Signed-off-by: Mars Cheng 
Tested-by: Matthias Brugger 
Acked-by: Stephen Boyd 
---
 drivers/clk/mediatek/Kconfig   |   32 ++
 drivers/clk/mediatek/Makefile  |5 +
 drivers/clk/mediatek/clk-mt6797-img.c  |   76 
 drivers/clk/mediatek/clk-mt6797-mm.c   |  136 ++
 drivers/clk/mediatek/clk-mt6797-vdec.c |   93 +
 drivers/clk/mediatek/clk-mt6797-venc.c |   78 
 drivers/clk/mediatek/clk-mt6797.c  |  714 
 7 files changed, 1134 insertions(+)
 create mode 100644 drivers/clk/mediatek/clk-mt6797-img.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-mm.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-vdec.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-venc.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797.c

diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index a01ef78..28739a9 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -50,6 +50,38 @@ config COMMON_CLK_MT2701_BDPSYS
---help---
  This driver supports Mediatek MT2701 bdpsys clocks.
 
+config COMMON_CLK_MT6797
+   bool "Clock driver for Mediatek MT6797"
+   depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST
+   select COMMON_CLK_MEDIATEK
+   default ARCH_MEDIATEK && ARM64
+   ---help---
+ This driver supports Mediatek MT6797 basic clocks.
+
+config COMMON_CLK_MT6797_MMSYS
+   bool "Clock driver for Mediatek MT6797 mmsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 mmsys clocks.
+
+config COMMON_CLK_MT6797_IMGSYS
+   bool "Clock driver for Mediatek MT6797 imgsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 imgsys clocks.
+
+config COMMON_CLK_MT6797_VDECSYS
+   bool "Clock driver for Mediatek MT6797 vdecsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 vdecsys clocks.
+
+config COMMON_CLK_MT6797_VENCSYS
+   bool "Clock driver for Mediatek MT6797 vencsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 vencsys clocks.
+
 config COMMON_CLK_MT8135
bool "Clock driver for Mediatek MT8135"
depends on (ARCH_MEDIATEK && ARM) || COMPILE_TEST
diff --git a/drivers/clk/mediatek/Makefile b/drivers/clk/mediatek/Makefile
index 19ae7ef..5c3afb8 100644
--- a/drivers/clk/mediatek/Makefile
+++ b/drivers/clk/mediatek/Makefile
@@ -1,5 +1,10 @@
 obj-$(CONFIG_COMMON_CLK_MEDIATEK) += clk-mtk.o clk-pll.o clk-gate.o 
clk-apmixed.o
 obj-$(CONFIG_RESET_CONTROLLER) += reset.o
+obj-$(CONFIG_COMMON_CLK_MT6797) += clk-mt6797.o
+obj-$(CONFIG_COMMON_CLK_MT6797_IMGSYS) += clk-mt6797-img.o
+obj-$(CONFIG_COMMON_CLK_MT6797_MMSYS) += clk-mt6797-mm.o
+obj-$(CONFIG_COMMON_CLK_MT6797_VDECSYS) += clk-mt6797-vdec.o
+obj-$(CONFIG_COMMON_CLK_MT6797_VENCSYS) += clk-mt6797-venc.o
 obj-$(CONFIG_COMMON_CLK_MT2701) += clk-mt2701.o
 obj-$(CONFIG_COMMON_CLK_MT2701_BDPSYS) += clk-mt2701-bdp.o
 obj-$(CONFIG_COMMON_CLK_MT2701_ETHSYS) += clk-mt2701-eth.o
diff --git a/drivers/clk/mediatek/clk-mt6797-img.c 
b/drivers/clk/mediatek/clk-mt6797-img.c
new file mode 100644
index 000..94cc480
--- /dev/null
+++ b/drivers/clk/mediatek/clk-mt6797-img.c
@@ -0,0 +1,76 @@
+/* Copyright (c) 2017 MediaTek Inc.
+ * Author: Kevin Chen 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+
+#include "clk-mtk.h"
+#include "clk-gate.h"
+
+static const struct mtk_gate_regs img_cg_regs = {
+   .set_ofs = 0x0004,
+   .clr_ofs = 0x0008,
+   .sta_ofs = 0x,
+};
+
+#define GATE_IMG(_id, _name, _parent, _shift) {\
+   .id = _id,  \
+   .name = _name,  \
+   .parent_name = _parent, \
+   .regs = _cg_regs,   \
+   .shift = _shift,\
+   .ops = _clk_gate_ops_setclr,\
+   }
+
+static const struct mtk_gate img_clks[] = {
+   GATE_IMG(CLK_IMG_FDVT, "img_fdvt", "mm_sel", 11),
+   GATE_IMG(CLK_IMG_DPE, "img_dpe", "mm_sel", 10),
+   GATE_IMG(CLK_IMG_DIP, 

[PATCH v4 00/10] Add Basic SoC support for MT6797

2017-04-07 Thread Mars Cheng
This patch set adds basic SoC support for mediatek's first 10-core
chip, X20, also known as MT6797.

- based on 4.11-rc1
- support common clk framework
- apply patches about intpol just accepted to get full feature support:
http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008371.html
http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008375.html
http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008373.html

Changes since v3:
- since intpol patches accepted in v3, remove them
- clk ID header separated from original clk driver submit
- clean up clk driver, including unnecessary header and fields in structure

Changes since v2:
- prevent uncessary #intpol-bases for mtk-sysirq
- add fast path for mtk-sysirq set_type when introducing multiple bases
- add acked-by and tested-by
- remove wrong usage for timer node

Changes since v1:
- add multiple base addresses support, v1 only allow 2 bases
- clean up clk driver

Kevin-CW Chen (2):
  dt-bindings: arm: mediatek: document clk bindings for MT6797
  clk: mediatek: add clk support for MT6797

Mars Cheng (8):
  dt-bindings: mediatek: Add bindings for mediatek MT6797 Platform
  arm64: dts: mediatek: add mt6797 support
  clk: mediatek: add mt6797 clock IDs
  soc: mediatek: avoid using fixed spm power status defines
  soc: mediatek: add vdec item for scpsys
  dt-bindings: mediatek: add MT6797 power dt-bindings
  soc: mediatek: add MT6797 scpsys support
  arm64: dts: mediatek: add clk and scp nodes for MT6797

 Documentation/devicetree/bindings/arm/mediatek.txt |4 +
 .../bindings/arm/mediatek/mediatek,apmixedsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,imgsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,infracfg.txt|1 +
 .../bindings/arm/mediatek/mediatek,mmsys.txt   |1 +
 .../bindings/arm/mediatek/mediatek,topckgen.txt|1 +
 .../bindings/arm/mediatek/mediatek,vdecsys.txt |1 +
 .../bindings/arm/mediatek/mediatek,vencsys.txt |3 +-
 .../interrupt-controller/mediatek,sysirq.txt   |1 +
 .../devicetree/bindings/serial/mtk-uart.txt|1 +
 .../devicetree/bindings/soc/mediatek/scpsys.txt|6 +-
 arch/arm64/boot/dts/mediatek/Makefile  |1 +
 arch/arm64/boot/dts/mediatek/mt6797-evb.dts|   36 +
 arch/arm64/boot/dts/mediatek/mt6797.dtsi   |  245 +++
 drivers/clk/mediatek/Kconfig   |   32 +
 drivers/clk/mediatek/Makefile  |5 +
 drivers/clk/mediatek/clk-mt6797-img.c  |   76 +++
 drivers/clk/mediatek/clk-mt6797-mm.c   |  136 
 drivers/clk/mediatek/clk-mt6797-vdec.c |   93 +++
 drivers/clk/mediatek/clk-mt6797-venc.c |   78 +++
 drivers/clk/mediatek/clk-mt6797.c  |  714 
 drivers/soc/mediatek/mtk-scpsys.c  |  149 +++-
 include/dt-bindings/clock/mt6797-clk.h |  281 
 include/dt-bindings/power/mt6797-power.h   |   30 +
 24 files changed, 1889 insertions(+), 8 deletions(-)
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797-evb.dts
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797.dtsi
 create mode 100644 drivers/clk/mediatek/clk-mt6797-img.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-mm.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-vdec.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-venc.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797.c
 create mode 100644 include/dt-bindings/clock/mt6797-clk.h
 create mode 100644 include/dt-bindings/power/mt6797-power.h

--
1.7.9.5


[PATCH v4 02/10] arm64: dts: mediatek: add mt6797 support

2017-04-07 Thread Mars Cheng
This adds basic chip support for MT6797 SoC.

Signed-off-by: Mars Cheng 
---
 arch/arm64/boot/dts/mediatek/Makefile   |1 +
 arch/arm64/boot/dts/mediatek/mt6797-evb.dts |   36 ++
 arch/arm64/boot/dts/mediatek/mt6797.dtsi|  182 +++
 3 files changed, 219 insertions(+)
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797-evb.dts
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797.dtsi

diff --git a/arch/arm64/boot/dts/mediatek/Makefile 
b/arch/arm64/boot/dts/mediatek/Makefile
index 9fbfd32..015eb07 100644
--- a/arch/arm64/boot/dts/mediatek/Makefile
+++ b/arch/arm64/boot/dts/mediatek/Makefile
@@ -1,5 +1,6 @@
 dtb-$(CONFIG_ARCH_MEDIATEK) += mt6755-evb.dtb
 dtb-$(CONFIG_ARCH_MEDIATEK) += mt6795-evb.dtb
+dtb-$(CONFIG_ARCH_MEDIATEK) += mt6797-evb.dtb
 dtb-$(CONFIG_ARCH_MEDIATEK) += mt8173-evb.dtb
 
 always := $(dtb-y)
diff --git a/arch/arm64/boot/dts/mediatek/mt6797-evb.dts 
b/arch/arm64/boot/dts/mediatek/mt6797-evb.dts
new file mode 100644
index 000..c79109c
--- /dev/null
+++ b/arch/arm64/boot/dts/mediatek/mt6797-evb.dts
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Mars.C 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/dts-v1/;
+#include "mt6797.dtsi"
+
+/ {
+   model = "MediaTek MT6797 Evaluation Board";
+   compatible = "mediatek,mt6797-evb", "mediatek,mt6797";
+
+   aliases {
+   serial0 = 
+   };
+
+   memory@4000 {
+   device_type = "memory";
+   reg = <0 0x4000 0 0x1e80>;
+   };
+
+   chosen {};
+};
+
+ {
+   status = "okay";
+};
diff --git a/arch/arm64/boot/dts/mediatek/mt6797.dtsi 
b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
new file mode 100644
index 000..cf4529e
--- /dev/null
+++ b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2017 MediaTek Inc.
+ * Author: Mars.C 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+
+/ {
+   compatible = "mediatek,mt6797";
+   interrupt-parent = <>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+
+   psci {
+   compatible = "arm,psci-0.2";
+   method = "smc";
+   };
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   cpu0: cpu@0 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x000>;
+   };
+
+   cpu1: cpu@1 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x001>;
+   };
+
+   cpu2: cpu@2 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x002>;
+   };
+
+   cpu3: cpu@3 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x003>;
+   };
+
+   cpu4: cpu@100 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x100>;
+   };
+
+   cpu5: cpu@101 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x101>;
+   };
+
+   cpu6: cpu@102 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x102>;
+   };
+
+   cpu7: cpu@103 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a53";
+   enable-method = "psci";
+   reg = <0x103>;
+   };
+
+   cpu8: cpu@200 {
+

[PATCH v4 05/10] clk: mediatek: add clk support for MT6797

2017-04-07 Thread Mars Cheng
From: Kevin-CW Chen 

Add MT6797 clock support, include topckgen, apmixedsys, infracfg
and subsystem clocks

Signed-off-by: Kevin-CW Chen 
Signed-off-by: Mars Cheng 
Tested-by: Matthias Brugger 
Acked-by: Stephen Boyd 
---
 drivers/clk/mediatek/Kconfig   |   32 ++
 drivers/clk/mediatek/Makefile  |5 +
 drivers/clk/mediatek/clk-mt6797-img.c  |   76 
 drivers/clk/mediatek/clk-mt6797-mm.c   |  136 ++
 drivers/clk/mediatek/clk-mt6797-vdec.c |   93 +
 drivers/clk/mediatek/clk-mt6797-venc.c |   78 
 drivers/clk/mediatek/clk-mt6797.c  |  714 
 7 files changed, 1134 insertions(+)
 create mode 100644 drivers/clk/mediatek/clk-mt6797-img.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-mm.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-vdec.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-venc.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797.c

diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index a01ef78..28739a9 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -50,6 +50,38 @@ config COMMON_CLK_MT2701_BDPSYS
---help---
  This driver supports Mediatek MT2701 bdpsys clocks.
 
+config COMMON_CLK_MT6797
+   bool "Clock driver for Mediatek MT6797"
+   depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST
+   select COMMON_CLK_MEDIATEK
+   default ARCH_MEDIATEK && ARM64
+   ---help---
+ This driver supports Mediatek MT6797 basic clocks.
+
+config COMMON_CLK_MT6797_MMSYS
+   bool "Clock driver for Mediatek MT6797 mmsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 mmsys clocks.
+
+config COMMON_CLK_MT6797_IMGSYS
+   bool "Clock driver for Mediatek MT6797 imgsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 imgsys clocks.
+
+config COMMON_CLK_MT6797_VDECSYS
+   bool "Clock driver for Mediatek MT6797 vdecsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 vdecsys clocks.
+
+config COMMON_CLK_MT6797_VENCSYS
+   bool "Clock driver for Mediatek MT6797 vencsys"
+   depends on COMMON_CLK_MT6797
+   ---help---
+ This driver supports Mediatek MT6797 vencsys clocks.
+
 config COMMON_CLK_MT8135
bool "Clock driver for Mediatek MT8135"
depends on (ARCH_MEDIATEK && ARM) || COMPILE_TEST
diff --git a/drivers/clk/mediatek/Makefile b/drivers/clk/mediatek/Makefile
index 19ae7ef..5c3afb8 100644
--- a/drivers/clk/mediatek/Makefile
+++ b/drivers/clk/mediatek/Makefile
@@ -1,5 +1,10 @@
 obj-$(CONFIG_COMMON_CLK_MEDIATEK) += clk-mtk.o clk-pll.o clk-gate.o 
clk-apmixed.o
 obj-$(CONFIG_RESET_CONTROLLER) += reset.o
+obj-$(CONFIG_COMMON_CLK_MT6797) += clk-mt6797.o
+obj-$(CONFIG_COMMON_CLK_MT6797_IMGSYS) += clk-mt6797-img.o
+obj-$(CONFIG_COMMON_CLK_MT6797_MMSYS) += clk-mt6797-mm.o
+obj-$(CONFIG_COMMON_CLK_MT6797_VDECSYS) += clk-mt6797-vdec.o
+obj-$(CONFIG_COMMON_CLK_MT6797_VENCSYS) += clk-mt6797-venc.o
 obj-$(CONFIG_COMMON_CLK_MT2701) += clk-mt2701.o
 obj-$(CONFIG_COMMON_CLK_MT2701_BDPSYS) += clk-mt2701-bdp.o
 obj-$(CONFIG_COMMON_CLK_MT2701_ETHSYS) += clk-mt2701-eth.o
diff --git a/drivers/clk/mediatek/clk-mt6797-img.c 
b/drivers/clk/mediatek/clk-mt6797-img.c
new file mode 100644
index 000..94cc480
--- /dev/null
+++ b/drivers/clk/mediatek/clk-mt6797-img.c
@@ -0,0 +1,76 @@
+/* Copyright (c) 2017 MediaTek Inc.
+ * Author: Kevin Chen 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+
+#include "clk-mtk.h"
+#include "clk-gate.h"
+
+static const struct mtk_gate_regs img_cg_regs = {
+   .set_ofs = 0x0004,
+   .clr_ofs = 0x0008,
+   .sta_ofs = 0x,
+};
+
+#define GATE_IMG(_id, _name, _parent, _shift) {\
+   .id = _id,  \
+   .name = _name,  \
+   .parent_name = _parent, \
+   .regs = _cg_regs,   \
+   .shift = _shift,\
+   .ops = _clk_gate_ops_setclr,\
+   }
+
+static const struct mtk_gate img_clks[] = {
+   GATE_IMG(CLK_IMG_FDVT, "img_fdvt", "mm_sel", 11),
+   GATE_IMG(CLK_IMG_DPE, "img_dpe", "mm_sel", 10),
+   GATE_IMG(CLK_IMG_DIP, "img_dip", "mm_sel", 6),
+   GATE_IMG(CLK_IMG_LARB6, "img_larb6", "mm_sel", 0),
+};
+
+static const struct of_device_id of_match_clk_mt6797_img[] = {
+   

[PATCH v4 00/10] Add Basic SoC support for MT6797

2017-04-07 Thread Mars Cheng
This patch set adds basic SoC support for mediatek's first 10-core
chip, X20, also known as MT6797.

- based on 4.11-rc1
- support common clk framework
- apply patches about intpol just accepted to get full feature support:
http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008371.html
http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008375.html
http://lists.infradead.org/pipermail/linux-mediatek/2017-March/008373.html

Changes since v3:
- since intpol patches accepted in v3, remove them
- clk ID header separated from original clk driver submit
- clean up clk driver, including unnecessary header and fields in structure

Changes since v2:
- prevent uncessary #intpol-bases for mtk-sysirq
- add fast path for mtk-sysirq set_type when introducing multiple bases
- add acked-by and tested-by
- remove wrong usage for timer node

Changes since v1:
- add multiple base addresses support, v1 only allow 2 bases
- clean up clk driver

Kevin-CW Chen (2):
  dt-bindings: arm: mediatek: document clk bindings for MT6797
  clk: mediatek: add clk support for MT6797

Mars Cheng (8):
  dt-bindings: mediatek: Add bindings for mediatek MT6797 Platform
  arm64: dts: mediatek: add mt6797 support
  clk: mediatek: add mt6797 clock IDs
  soc: mediatek: avoid using fixed spm power status defines
  soc: mediatek: add vdec item for scpsys
  dt-bindings: mediatek: add MT6797 power dt-bindings
  soc: mediatek: add MT6797 scpsys support
  arm64: dts: mediatek: add clk and scp nodes for MT6797

 Documentation/devicetree/bindings/arm/mediatek.txt |4 +
 .../bindings/arm/mediatek/mediatek,apmixedsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,imgsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,infracfg.txt|1 +
 .../bindings/arm/mediatek/mediatek,mmsys.txt   |1 +
 .../bindings/arm/mediatek/mediatek,topckgen.txt|1 +
 .../bindings/arm/mediatek/mediatek,vdecsys.txt |1 +
 .../bindings/arm/mediatek/mediatek,vencsys.txt |3 +-
 .../interrupt-controller/mediatek,sysirq.txt   |1 +
 .../devicetree/bindings/serial/mtk-uart.txt|1 +
 .../devicetree/bindings/soc/mediatek/scpsys.txt|6 +-
 arch/arm64/boot/dts/mediatek/Makefile  |1 +
 arch/arm64/boot/dts/mediatek/mt6797-evb.dts|   36 +
 arch/arm64/boot/dts/mediatek/mt6797.dtsi   |  245 +++
 drivers/clk/mediatek/Kconfig   |   32 +
 drivers/clk/mediatek/Makefile  |5 +
 drivers/clk/mediatek/clk-mt6797-img.c  |   76 +++
 drivers/clk/mediatek/clk-mt6797-mm.c   |  136 
 drivers/clk/mediatek/clk-mt6797-vdec.c |   93 +++
 drivers/clk/mediatek/clk-mt6797-venc.c |   78 +++
 drivers/clk/mediatek/clk-mt6797.c  |  714 
 drivers/soc/mediatek/mtk-scpsys.c  |  149 +++-
 include/dt-bindings/clock/mt6797-clk.h |  281 
 include/dt-bindings/power/mt6797-power.h   |   30 +
 24 files changed, 1889 insertions(+), 8 deletions(-)
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797-evb.dts
 create mode 100644 arch/arm64/boot/dts/mediatek/mt6797.dtsi
 create mode 100644 drivers/clk/mediatek/clk-mt6797-img.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-mm.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-vdec.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797-venc.c
 create mode 100644 drivers/clk/mediatek/clk-mt6797.c
 create mode 100644 include/dt-bindings/clock/mt6797-clk.h
 create mode 100644 include/dt-bindings/power/mt6797-power.h

--
1.7.9.5


[PATCH v4 03/10] dt-bindings: arm: mediatek: document clk bindings for MT6797

2017-04-07 Thread Mars Cheng
From: Kevin-CW Chen 

This patch adds the binding documentation for apmixedsys, imgsys,
infracfg, mmsys, topckgen, vdecsys and vencsys for MT6797.

Signed-off-by: Kevin-CW Chen 
Signed-off-by: Mars Cheng 
Acked-by: Rob Herring 
---
 .../bindings/arm/mediatek/mediatek,apmixedsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,imgsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,infracfg.txt|1 +
 .../bindings/arm/mediatek/mediatek,mmsys.txt   |1 +
 .../bindings/arm/mediatek/mediatek,topckgen.txt|1 +
 .../bindings/arm/mediatek/mediatek,vdecsys.txt |1 +
 .../bindings/arm/mediatek/mediatek,vencsys.txt |3 ++-
 7 files changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt
index cb0054a..cd977db 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-apmixedsys"
+   - "mediatek,mt6797-apmixedsys"
- "mediatek,mt8135-apmixedsys"
- "mediatek,mt8173-apmixedsys"
 - #clock-cells: Must be 1
diff --git a/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt
index f6a9166..047b11a 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-imgsys", "syscon"
+   - "mediatek,mt6797-imgsys", "syscon"
- "mediatek,mt8173-imgsys", "syscon"
 - #clock-cells: Must be 1
 
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt
index 1620ec2..58d58e2 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt
@@ -8,6 +8,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-infracfg", "syscon"
+   - "mediatek,mt6797-infracfg", "syscon"
- "mediatek,mt8135-infracfg", "syscon"
- "mediatek,mt8173-infracfg", "syscon"
 - #clock-cells: Must be 1
diff --git a/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
index 67dd2e4..70529e0 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-mmsys", "syscon"
+   - "mediatek,mt6797-mmsys", "syscon"
- "mediatek,mt8173-mmsys", "syscon"
 - #clock-cells: Must be 1
 
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt
index 9f2fe78..ec93ecb 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-topckgen"
+   - "mediatek,mt6797-topckgen"
- "mediatek,mt8135-topckgen"
- "mediatek,mt8173-topckgen"
 - #clock-cells: Must be 1
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt
index 2440f73..d150104 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-vdecsys", "syscon"
+   - "mediatek,mt6797-vdecsys", "syscon"
- "mediatek,mt8173-vdecsys", "syscon"
 - #clock-cells: Must be 1
 
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt
index 5bb2866..8a93be6 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt
@@ -5,7 +5,8 @@ The Mediatek vencsys controller provides various clocks to the 
system.
 
 Required Properties:
 
-- compatible: Should be:
+- compatible: Should be one of:
+   - "mediatek,mt6797-vencsys", "syscon"
- "mediatek,mt8173-vencsys", "syscon"
 - #clock-cells: Must be 1
 
-- 
1.7.9.5



[PATCH v4 03/10] dt-bindings: arm: mediatek: document clk bindings for MT6797

2017-04-07 Thread Mars Cheng
From: Kevin-CW Chen 

This patch adds the binding documentation for apmixedsys, imgsys,
infracfg, mmsys, topckgen, vdecsys and vencsys for MT6797.

Signed-off-by: Kevin-CW Chen 
Signed-off-by: Mars Cheng 
Acked-by: Rob Herring 
---
 .../bindings/arm/mediatek/mediatek,apmixedsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,imgsys.txt  |1 +
 .../bindings/arm/mediatek/mediatek,infracfg.txt|1 +
 .../bindings/arm/mediatek/mediatek,mmsys.txt   |1 +
 .../bindings/arm/mediatek/mediatek,topckgen.txt|1 +
 .../bindings/arm/mediatek/mediatek,vdecsys.txt |1 +
 .../bindings/arm/mediatek/mediatek,vencsys.txt |3 ++-
 7 files changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt
index cb0054a..cd977db 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,apmixedsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-apmixedsys"
+   - "mediatek,mt6797-apmixedsys"
- "mediatek,mt8135-apmixedsys"
- "mediatek,mt8173-apmixedsys"
 - #clock-cells: Must be 1
diff --git a/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt
index f6a9166..047b11a 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,imgsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-imgsys", "syscon"
+   - "mediatek,mt6797-imgsys", "syscon"
- "mediatek,mt8173-imgsys", "syscon"
 - #clock-cells: Must be 1
 
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt
index 1620ec2..58d58e2 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,infracfg.txt
@@ -8,6 +8,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-infracfg", "syscon"
+   - "mediatek,mt6797-infracfg", "syscon"
- "mediatek,mt8135-infracfg", "syscon"
- "mediatek,mt8173-infracfg", "syscon"
 - #clock-cells: Must be 1
diff --git a/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
index 67dd2e4..70529e0 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,mmsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-mmsys", "syscon"
+   - "mediatek,mt6797-mmsys", "syscon"
- "mediatek,mt8173-mmsys", "syscon"
 - #clock-cells: Must be 1
 
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt
index 9f2fe78..ec93ecb 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,topckgen.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-topckgen"
+   - "mediatek,mt6797-topckgen"
- "mediatek,mt8135-topckgen"
- "mediatek,mt8173-topckgen"
 - #clock-cells: Must be 1
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt
index 2440f73..d150104 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vdecsys.txt
@@ -7,6 +7,7 @@ Required Properties:
 
 - compatible: Should be one of:
- "mediatek,mt2701-vdecsys", "syscon"
+   - "mediatek,mt6797-vdecsys", "syscon"
- "mediatek,mt8173-vdecsys", "syscon"
 - #clock-cells: Must be 1
 
diff --git 
a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt 
b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt
index 5bb2866..8a93be6 100644
--- a/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt
+++ b/Documentation/devicetree/bindings/arm/mediatek/mediatek,vencsys.txt
@@ -5,7 +5,8 @@ The Mediatek vencsys controller provides various clocks to the 
system.
 
 Required Properties:
 
-- compatible: Should be:
+- compatible: Should be one of:
+   - "mediatek,mt6797-vencsys", "syscon"
- "mediatek,mt8173-vencsys", "syscon"
 - #clock-cells: Must be 1
 
-- 
1.7.9.5



[PATCH v4 10/10] arm64: dts: mediatek: add clk and scp nodes for MT6797

2017-04-07 Thread Mars Cheng
This adds clk and scp nodes for MT6797

Signed-off-by: Mars Cheng 
---
 arch/arm64/boot/dts/mediatek/mt6797.dtsi |   71 --
 1 file changed, 67 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt6797.dtsi 
b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
index cf4529e..3512c8e 100644
--- a/arch/arm64/boot/dts/mediatek/mt6797.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
@@ -11,6 +11,8 @@
  * GNU General Public License for more details.
  */
 
+#include 
+#include 
 #include 
 #include 
 
@@ -123,6 +125,35 @@
 ;
};
 
+   topckgen: topckgen@1000 {
+   compatible = "mediatek,mt6797-topckgen";
+   reg = <0 0x1000 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   infrasys: infracfg_ao@10001000 {
+   compatible = "mediatek,mt6797-infracfg", "syscon";
+   reg = <0 0x10001000 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   scpsys: scpsys@10006000 {
+   compatible = "mediatek,mt6797-scpsys";
+   #power-domain-cells = <1>;
+   reg = <0 0x10006000 0 0x1000>;
+   clocks = < CLK_TOP_MUX_MFG>,
+< CLK_TOP_MUX_MM>,
+< CLK_TOP_MUX_VDEC>;
+   clock-names = "mfg", "mm", "vdec";
+   infracfg = <>;
+   };
+
+   apmixedsys: apmixed@1000c000 {
+   compatible = "mediatek,mt6797-apmixedsys";
+   reg = <0 0x1000c000 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
sysirq: intpol-controller@10200620 {
compatible = "mediatek,mt6797-sysirq",
 "mediatek,mt6577-sysirq";
@@ -138,7 +169,9 @@
 "mediatek,mt6577-uart";
reg = <0 0x11002000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART0>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
@@ -147,7 +180,9 @@
 "mediatek,mt6577-uart";
reg = <0 0x11003000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART1>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
@@ -156,7 +191,9 @@
 "mediatek,mt6577-uart";
reg = <0 0x11004000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART2>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
@@ -165,10 +202,36 @@
 "mediatek,mt6577-uart";
reg = <0 0x11005000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART3>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
+   mmsys: mmsys_config@1400 {
+   compatible = "mediatek,mt6797-mmsys", "syscon";
+   reg = <0 0x1400 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   imgsys: imgsys_config@1500  {
+   compatible = "mediatek,mt6797-imgsys", "syscon";
+   reg = <0 0x1500 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   vdecsys: vdec_gcon@1600 {
+   compatible = "mediatek,mt6797-vdecsys", "syscon";
+   reg = <0 0x1600 0 0x1>;
+   #clock-cells = <1>;
+   };
+
+   vencsys: venc_gcon@1700 {
+   compatible = "mediatek,mt6797-vencsys", "syscon";
+   reg = <0 0x1700 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
gic: interrupt-controller@1900 {
compatible = "arm,gic-v3";
#interrupt-cells = <3>;
-- 
1.7.9.5



[PATCH v4 10/10] arm64: dts: mediatek: add clk and scp nodes for MT6797

2017-04-07 Thread Mars Cheng
This adds clk and scp nodes for MT6797

Signed-off-by: Mars Cheng 
---
 arch/arm64/boot/dts/mediatek/mt6797.dtsi |   71 --
 1 file changed, 67 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt6797.dtsi 
b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
index cf4529e..3512c8e 100644
--- a/arch/arm64/boot/dts/mediatek/mt6797.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
@@ -11,6 +11,8 @@
  * GNU General Public License for more details.
  */
 
+#include 
+#include 
 #include 
 #include 
 
@@ -123,6 +125,35 @@
 ;
};
 
+   topckgen: topckgen@1000 {
+   compatible = "mediatek,mt6797-topckgen";
+   reg = <0 0x1000 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   infrasys: infracfg_ao@10001000 {
+   compatible = "mediatek,mt6797-infracfg", "syscon";
+   reg = <0 0x10001000 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   scpsys: scpsys@10006000 {
+   compatible = "mediatek,mt6797-scpsys";
+   #power-domain-cells = <1>;
+   reg = <0 0x10006000 0 0x1000>;
+   clocks = < CLK_TOP_MUX_MFG>,
+< CLK_TOP_MUX_MM>,
+< CLK_TOP_MUX_VDEC>;
+   clock-names = "mfg", "mm", "vdec";
+   infracfg = <>;
+   };
+
+   apmixedsys: apmixed@1000c000 {
+   compatible = "mediatek,mt6797-apmixedsys";
+   reg = <0 0x1000c000 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
sysirq: intpol-controller@10200620 {
compatible = "mediatek,mt6797-sysirq",
 "mediatek,mt6577-sysirq";
@@ -138,7 +169,9 @@
 "mediatek,mt6577-uart";
reg = <0 0x11002000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART0>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
@@ -147,7 +180,9 @@
 "mediatek,mt6577-uart";
reg = <0 0x11003000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART1>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
@@ -156,7 +191,9 @@
 "mediatek,mt6577-uart";
reg = <0 0x11004000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART2>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
@@ -165,10 +202,36 @@
 "mediatek,mt6577-uart";
reg = <0 0x11005000 0 0x400>;
interrupts = ;
-   clocks = <>;
+   clocks = < CLK_INFRA_UART3>,
+< CLK_INFRA_AP_DMA>;
+   clock-names = "baud", "bus";
status = "disabled";
};
 
+   mmsys: mmsys_config@1400 {
+   compatible = "mediatek,mt6797-mmsys", "syscon";
+   reg = <0 0x1400 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   imgsys: imgsys_config@1500  {
+   compatible = "mediatek,mt6797-imgsys", "syscon";
+   reg = <0 0x1500 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
+   vdecsys: vdec_gcon@1600 {
+   compatible = "mediatek,mt6797-vdecsys", "syscon";
+   reg = <0 0x1600 0 0x1>;
+   #clock-cells = <1>;
+   };
+
+   vencsys: venc_gcon@1700 {
+   compatible = "mediatek,mt6797-vencsys", "syscon";
+   reg = <0 0x1700 0 0x1000>;
+   #clock-cells = <1>;
+   };
+
gic: interrupt-controller@1900 {
compatible = "arm,gic-v3";
#interrupt-cells = <3>;
-- 
1.7.9.5



[PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines
and needs to be replaced by struct timespec64
in order to represent times beyond year 2038 on such
machines.

Fix all the timestamp representation in struct trace_hwlat
and all the corresponding implementations.

Signed-off-by: Deepa Dinamani 
---
 kernel/trace/trace_entries.h |  6 +++---
 kernel/trace/trace_hwlat.c   | 14 +++---
 kernel/trace/trace_output.c  |  9 -
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index c203ac4..adcdbbe 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -348,14 +348,14 @@ FTRACE_ENTRY(hwlat, hwlat_entry,
__field(u64,duration)
__field(u64,outer_duration  )
__field(u64,nmi_total_ts)
-   __field_struct( struct timespec,timestamp   )
-   __field_desc(   long,   timestamp,  tv_sec  )
+   __field_struct( struct timespec64,  timestamp   )
+   __field_desc(   s64,timestamp,  tv_sec  )
__field_desc(   long,   timestamp,  tv_nsec )
__field(unsigned int,   nmi_count   )
__field(unsigned int,   seqnum  )
),
 
-   
F_printk("cnt:%u\tts:%010lu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
+   
F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
 __entry->seqnum,
 __entry->tv_sec,
 __entry->tv_nsec,
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 21ea6ae..d7c8e4e 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -79,12 +79,12 @@ static u64 last_tracing_thresh = DEFAULT_LAT_THRESHOLD * 
NSEC_PER_USEC;
 
 /* Individual latency samples are stored here when detected. */
 struct hwlat_sample {
-   u64 seqnum; /* unique sequence */
-   u64 duration;   /* delta */
-   u64 outer_duration; /* delta (outer loop) */
-   u64 nmi_total_ts;   /* Total time spent in NMIs */
-   struct timespec timestamp;  /* wall time */
-   int nmi_count;  /* # NMIs during this sample */
+   u64 seqnum; /* unique sequence */
+   u64 duration;   /* delta */
+   u64 outer_duration; /* delta (outer loop) */
+   u64 nmi_total_ts;   /* Total time spent in NMIs */
+   struct timespec64   timestamp;  /* wall time */
+   int nmi_count;  /* # NMIs during this sample */
 };
 
 /* keep the global state somewhere. */
@@ -250,7 +250,7 @@ static int get_sample(void)
s.seqnum = hwlat_data.count;
s.duration = sample;
s.outer_duration = outer_sample;
-   s.timestamp = CURRENT_TIME;
+   ktime_get_real_ts64();
s.nmi_total_ts = nmi_total_ts;
s.nmi_count = nmi_count;
trace_hwlat_sample();
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 02a4aeb..08f9bab 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt 
  *
  */
-
 #include 
 #include 
 #include 
@@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
flags,
 
trace_assign_type(field, entry);
 
-   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
+   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
 field->seqnum,
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec);
 
if (field->nmi_count) {
@@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int flags,
 
trace_assign_type(field, iter->ent);
 
-   trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
+   trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec,
 field->seqnum);
 
-- 
2.7.4



[PATCH 02/12] trace: Make trace_hwlat timestamp y2038 safe

2017-04-07 Thread Deepa Dinamani
struct timespec is not y2038 safe on 32 bit machines
and needs to be replaced by struct timespec64
in order to represent times beyond year 2038 on such
machines.

Fix all the timestamp representation in struct trace_hwlat
and all the corresponding implementations.

Signed-off-by: Deepa Dinamani 
---
 kernel/trace/trace_entries.h |  6 +++---
 kernel/trace/trace_hwlat.c   | 14 +++---
 kernel/trace/trace_output.c  |  9 -
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index c203ac4..adcdbbe 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -348,14 +348,14 @@ FTRACE_ENTRY(hwlat, hwlat_entry,
__field(u64,duration)
__field(u64,outer_duration  )
__field(u64,nmi_total_ts)
-   __field_struct( struct timespec,timestamp   )
-   __field_desc(   long,   timestamp,  tv_sec  )
+   __field_struct( struct timespec64,  timestamp   )
+   __field_desc(   s64,timestamp,  tv_sec  )
__field_desc(   long,   timestamp,  tv_nsec )
__field(unsigned int,   nmi_count   )
__field(unsigned int,   seqnum  )
),
 
-   
F_printk("cnt:%u\tts:%010lu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
+   
F_printk("cnt:%u\tts:%010llu.%010lu\tinner:%llu\touter:%llunmi-ts:%llu\tnmi-count:%u\n",
 __entry->seqnum,
 __entry->tv_sec,
 __entry->tv_nsec,
diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 21ea6ae..d7c8e4e 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -79,12 +79,12 @@ static u64 last_tracing_thresh = DEFAULT_LAT_THRESHOLD * 
NSEC_PER_USEC;
 
 /* Individual latency samples are stored here when detected. */
 struct hwlat_sample {
-   u64 seqnum; /* unique sequence */
-   u64 duration;   /* delta */
-   u64 outer_duration; /* delta (outer loop) */
-   u64 nmi_total_ts;   /* Total time spent in NMIs */
-   struct timespec timestamp;  /* wall time */
-   int nmi_count;  /* # NMIs during this sample */
+   u64 seqnum; /* unique sequence */
+   u64 duration;   /* delta */
+   u64 outer_duration; /* delta (outer loop) */
+   u64 nmi_total_ts;   /* Total time spent in NMIs */
+   struct timespec64   timestamp;  /* wall time */
+   int nmi_count;  /* # NMIs during this sample */
 };
 
 /* keep the global state somewhere. */
@@ -250,7 +250,7 @@ static int get_sample(void)
s.seqnum = hwlat_data.count;
s.duration = sample;
s.outer_duration = outer_sample;
-   s.timestamp = CURRENT_TIME;
+   ktime_get_real_ts64();
s.nmi_total_ts = nmi_total_ts;
s.nmi_count = nmi_count;
trace_hwlat_sample();
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 02a4aeb..08f9bab 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -4,7 +4,6 @@
  * Copyright (C) 2008 Red Hat Inc, Steven Rostedt 
  *
  */
-
 #include 
 #include 
 #include 
@@ -1161,11 +1160,11 @@ trace_hwlat_print(struct trace_iterator *iter, int 
flags,
 
trace_assign_type(field, entry);
 
-   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%ld.%09ld",
+   trace_seq_printf(s, "#%-5u inner/outer(us): %4llu/%-5llu ts:%lld.%09ld",
 field->seqnum,
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec);
 
if (field->nmi_count) {
@@ -1195,10 +1194,10 @@ trace_hwlat_raw(struct trace_iterator *iter, int flags,
 
trace_assign_type(field, iter->ent);
 
-   trace_seq_printf(s, "%llu %lld %ld %09ld %u\n",
+   trace_seq_printf(s, "%llu %lld %lld %09ld %u\n",
 field->duration,
 field->outer_duration,
-field->timestamp.tv_sec,
+(long long)field->timestamp.tv_sec,
 field->timestamp.tv_nsec,
 field->seqnum);
 
-- 
2.7.4



[PATCH 09/12] lustre: Replace CURRENT_TIME macro

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time() for filesystem times, and ktime_get_*
functions for others.

struct timespec is also not y2038 safe.
Retain timespec for timestamp representation here as lustre
uses it internally everywhere.
These references will be changed to use struct timespec64
in a separate patch.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. current_time() is also planned to be transitioned
to y2038 safe behavior along with this change.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

Signed-off-by: Deepa Dinamani 
---
 drivers/staging/lustre/lustre/llite/llite_lib.c | 6 +++---
 drivers/staging/lustre/lustre/osc/osc_io.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c 
b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 7b80040..2b4b6b9 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -1472,17 +1472,17 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr 
*attr, bool hsm_import)
 
/* We mark all of the fields "set" so MDS/OST does not re-set them */
if (attr->ia_valid & ATTR_CTIME) {
-   attr->ia_ctime = CURRENT_TIME;
+   attr->ia_ctime = current_time(inode);
attr->ia_valid |= ATTR_CTIME_SET;
}
if (!(attr->ia_valid & ATTR_ATIME_SET) &&
(attr->ia_valid & ATTR_ATIME)) {
-   attr->ia_atime = CURRENT_TIME;
+   attr->ia_atime = current_time(inode);
attr->ia_valid |= ATTR_ATIME_SET;
}
if (!(attr->ia_valid & ATTR_MTIME_SET) &&
(attr->ia_valid & ATTR_MTIME)) {
-   attr->ia_mtime = CURRENT_TIME;
+   attr->ia_mtime = current_time(inode);
attr->ia_valid |= ATTR_MTIME_SET;
}
 
diff --git a/drivers/staging/lustre/lustre/osc/osc_io.c 
b/drivers/staging/lustre/lustre/osc/osc_io.c
index f991bee..cbab800 100644
--- a/drivers/staging/lustre/lustre/osc/osc_io.c
+++ b/drivers/staging/lustre/lustre/osc/osc_io.c
@@ -216,7 +216,7 @@ static int osc_io_submit(const struct lu_env *env,
struct cl_object *obj = ios->cis_obj;
 
cl_object_attr_lock(obj);
-   attr->cat_mtime = LTIME_S(CURRENT_TIME);
+   attr->cat_mtime = ktime_get_real_seconds();
attr->cat_ctime = attr->cat_mtime;
cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
cl_object_attr_unlock(obj);
@@ -256,7 +256,7 @@ static void osc_page_touch_at(const struct lu_env *env,
   kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
   loi->loi_lvb.lvb_size);
 
-   attr->cat_ctime = LTIME_S(CURRENT_TIME);
+   attr->cat_ctime = ktime_get_real_seconds();
attr->cat_mtime = attr->cat_ctime;
valid = CAT_MTIME | CAT_CTIME;
if (kms > loi->loi_kms) {
-- 
2.7.4



[PATCH 05/12] fs: ufs: Use ktime_get_real_ts64() for birthtime

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
Replace it with ktime_get_real_ts64().
Inode time formats are already 64 bit long and
accommodates time64_t.

Signed-off-by: Deepa Dinamani 
---
 fs/ufs/ialloc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 9774555..d1dd8cc 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -176,6 +176,7 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
struct ufs_cg_private_info * ucpi;
struct ufs_cylinder_group * ucg;
struct inode * inode;
+   struct timespec64 ts;
unsigned cg, bit, i, j, start;
struct ufs_inode_info *ufsi;
int err = -ENOSPC;
@@ -323,8 +324,9 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
lock_buffer(bh);
ufs2_inode = (struct ufs2_inode *)bh->b_data;
ufs2_inode += ufs_inotofsbo(inode->i_ino);
-   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, CURRENT_TIME.tv_sec);
-   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, 
CURRENT_TIME.tv_nsec);
+   ktime_get_real_ts64();
+   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, ts.tv_sec);
+   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, ts.tv_nsec);
mark_buffer_dirty(bh);
unlock_buffer(bh);
if (sb->s_flags & MS_SYNCHRONOUS)
-- 
2.7.4



[PATCH 09/12] lustre: Replace CURRENT_TIME macro

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time() for filesystem times, and ktime_get_*
functions for others.

struct timespec is also not y2038 safe.
Retain timespec for timestamp representation here as lustre
uses it internally everywhere.
These references will be changed to use struct timespec64
in a separate patch.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. current_time() is also planned to be transitioned
to y2038 safe behavior along with this change.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

Signed-off-by: Deepa Dinamani 
---
 drivers/staging/lustre/lustre/llite/llite_lib.c | 6 +++---
 drivers/staging/lustre/lustre/osc/osc_io.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c 
b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 7b80040..2b4b6b9 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -1472,17 +1472,17 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr 
*attr, bool hsm_import)
 
/* We mark all of the fields "set" so MDS/OST does not re-set them */
if (attr->ia_valid & ATTR_CTIME) {
-   attr->ia_ctime = CURRENT_TIME;
+   attr->ia_ctime = current_time(inode);
attr->ia_valid |= ATTR_CTIME_SET;
}
if (!(attr->ia_valid & ATTR_ATIME_SET) &&
(attr->ia_valid & ATTR_ATIME)) {
-   attr->ia_atime = CURRENT_TIME;
+   attr->ia_atime = current_time(inode);
attr->ia_valid |= ATTR_ATIME_SET;
}
if (!(attr->ia_valid & ATTR_MTIME_SET) &&
(attr->ia_valid & ATTR_MTIME)) {
-   attr->ia_mtime = CURRENT_TIME;
+   attr->ia_mtime = current_time(inode);
attr->ia_valid |= ATTR_MTIME_SET;
}
 
diff --git a/drivers/staging/lustre/lustre/osc/osc_io.c 
b/drivers/staging/lustre/lustre/osc/osc_io.c
index f991bee..cbab800 100644
--- a/drivers/staging/lustre/lustre/osc/osc_io.c
+++ b/drivers/staging/lustre/lustre/osc/osc_io.c
@@ -216,7 +216,7 @@ static int osc_io_submit(const struct lu_env *env,
struct cl_object *obj = ios->cis_obj;
 
cl_object_attr_lock(obj);
-   attr->cat_mtime = LTIME_S(CURRENT_TIME);
+   attr->cat_mtime = ktime_get_real_seconds();
attr->cat_ctime = attr->cat_mtime;
cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
cl_object_attr_unlock(obj);
@@ -256,7 +256,7 @@ static void osc_page_touch_at(const struct lu_env *env,
   kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
   loi->loi_lvb.lvb_size);
 
-   attr->cat_ctime = LTIME_S(CURRENT_TIME);
+   attr->cat_ctime = ktime_get_real_seconds();
attr->cat_mtime = attr->cat_ctime;
valid = CAT_MTIME | CAT_CTIME;
if (kms > loi->loi_kms) {
-- 
2.7.4



[PATCH 05/12] fs: ufs: Use ktime_get_real_ts64() for birthtime

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
Replace it with ktime_get_real_ts64().
Inode time formats are already 64 bit long and
accommodates time64_t.

Signed-off-by: Deepa Dinamani 
---
 fs/ufs/ialloc.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 9774555..d1dd8cc 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -176,6 +176,7 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
struct ufs_cg_private_info * ucpi;
struct ufs_cylinder_group * ucg;
struct inode * inode;
+   struct timespec64 ts;
unsigned cg, bit, i, j, start;
struct ufs_inode_info *ufsi;
int err = -ENOSPC;
@@ -323,8 +324,9 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)
lock_buffer(bh);
ufs2_inode = (struct ufs2_inode *)bh->b_data;
ufs2_inode += ufs_inotofsbo(inode->i_ino);
-   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, CURRENT_TIME.tv_sec);
-   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, 
CURRENT_TIME.tv_nsec);
+   ktime_get_real_ts64();
+   ufs2_inode->ui_birthtime = cpu_to_fs64(sb, ts.tv_sec);
+   ufs2_inode->ui_birthnsec = cpu_to_fs32(sb, ts.tv_nsec);
mark_buffer_dirty(bh);
unlock_buffer(bh);
if (sb->s_flags & MS_SYNCHRONOUS)
-- 
2.7.4



[PATCH 10/12] apparmorfs: Replace CURRENT_TIME with current_time()

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time().

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. current_time() is also planned to be transitioned
to y2038 safe behavior along with this change.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

Signed-off-by: Deepa Dinamani 
---
 security/apparmor/apparmorfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index be0b498..4f6ac9d 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -1357,7 +1357,7 @@ static int aa_mk_null_file(struct dentry *parent)
 
inode->i_ino = get_next_ino();
inode->i_mode = S_IFCHR | S_IRUGO | S_IWUGO;
-   inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+   inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO,
   MKDEV(MEM_MAJOR, 3));
d_instantiate(dentry, inode);
-- 
2.7.4



[PATCH 10/12] apparmorfs: Replace CURRENT_TIME with current_time()

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time().

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. current_time() is also planned to be transitioned
to y2038 safe behavior along with this change.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

Signed-off-by: Deepa Dinamani 
---
 security/apparmor/apparmorfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index be0b498..4f6ac9d 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -1357,7 +1357,7 @@ static int aa_mk_null_file(struct dentry *parent)
 
inode->i_ino = get_next_ino();
inode->i_mode = S_IFCHR | S_IRUGO | S_IWUGO;
-   inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+   inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
init_special_inode(inode, S_IFCHR | S_IRUGO | S_IWUGO,
   MKDEV(MEM_MAJOR, 3));
d_instantiate(dentry, inode);
-- 
2.7.4



[PATCH 07/12] fs: btrfs: Use ktime_get_real_ts for root ctime

2017-04-07 Thread Deepa Dinamani
btrfs_root_item maintains the ctime for root updates.
This is not part of vfs_inode.

Since current_time() uses struct inode* as an argument
as Linus suggested, this cannot be used to update root
times unless, we modify the signature to use inode.

Since btrfs uses nanosecond time granularity, it can also
use ktime_get_real_ts directly to obtain timestamp for
the root. It is necessary to use the timespec time api
here because the same btrfs_set_stack_timespec_*() apis
are used for vfs inode times as well. These can be
transitioned to using timespec64 when btrfs internally
changes to use timespec64 as well.

Signed-off-by: Deepa Dinamani 
Acked-by: David Sterba 
Reviewed-by: Arnd Bergmann 
---
 fs/btrfs/root-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index a08224e..7d6bc30 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -501,8 +501,9 @@ void btrfs_update_root_times(struct btrfs_trans_handle 
*trans,
 struct btrfs_root *root)
 {
struct btrfs_root_item *item = >root_item;
-   struct timespec ct = current_fs_time(root->fs_info->sb);
+   struct timespec ct;
 
+   ktime_get_real_ts();
spin_lock(>root_item_lock);
btrfs_set_root_ctransid(item, trans->transid);
btrfs_set_stack_timespec_sec(>ctime, ct.tv_sec);
-- 
2.7.4



[PATCH 07/12] fs: btrfs: Use ktime_get_real_ts for root ctime

2017-04-07 Thread Deepa Dinamani
btrfs_root_item maintains the ctime for root updates.
This is not part of vfs_inode.

Since current_time() uses struct inode* as an argument
as Linus suggested, this cannot be used to update root
times unless, we modify the signature to use inode.

Since btrfs uses nanosecond time granularity, it can also
use ktime_get_real_ts directly to obtain timestamp for
the root. It is necessary to use the timespec time api
here because the same btrfs_set_stack_timespec_*() apis
are used for vfs inode times as well. These can be
transitioned to using timespec64 when btrfs internally
changes to use timespec64 as well.

Signed-off-by: Deepa Dinamani 
Acked-by: David Sterba 
Reviewed-by: Arnd Bergmann 
---
 fs/btrfs/root-tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index a08224e..7d6bc30 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -501,8 +501,9 @@ void btrfs_update_root_times(struct btrfs_trans_handle 
*trans,
 struct btrfs_root *root)
 {
struct btrfs_root_item *item = >root_item;
-   struct timespec ct = current_fs_time(root->fs_info->sb);
+   struct timespec ct;
 
+   ktime_get_real_ts();
spin_lock(>root_item_lock);
btrfs_set_root_ctransid(item, trans->transid);
btrfs_set_stack_timespec_sec(>ctime, ct.tv_sec);
-- 
2.7.4



[PATCH 11/12] time: Delete CURRENT_TIME_SEC and CURRENT_TIME

2017-04-07 Thread Deepa Dinamani
All uses of CURRENT_TIME_SEC and CURRENT_TIME macros have
been replaced by other time functions. These macros are
also not y2038 safe.
And, all their use cases can be fulfilled by y2038 safe
ktime_get_* variants.

Signed-off-by: Deepa Dinamani 
Acked-by: John Stultz 
Reviewed-by: Arnd Bergmann 
---
 include/linux/time.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 23f0f5c..c0543f5 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -151,9 +151,6 @@ static inline bool timespec_inject_offset_valid(const 
struct timespec *ts)
return true;
 }
 
-#define CURRENT_TIME   (current_kernel_time())
-#define CURRENT_TIME_SEC   ((struct timespec) { get_seconds(), 0 })
-
 /* Some architectures do not supply their own clocksource.
  * This is mainly the case in architectures that get their
  * inter-tick times by reading the counter on their interval
-- 
2.7.4



[PATCH 11/12] time: Delete CURRENT_TIME_SEC and CURRENT_TIME

2017-04-07 Thread Deepa Dinamani
All uses of CURRENT_TIME_SEC and CURRENT_TIME macros have
been replaced by other time functions. These macros are
also not y2038 safe.
And, all their use cases can be fulfilled by y2038 safe
ktime_get_* variants.

Signed-off-by: Deepa Dinamani 
Acked-by: John Stultz 
Reviewed-by: Arnd Bergmann 
---
 include/linux/time.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 23f0f5c..c0543f5 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -151,9 +151,6 @@ static inline bool timespec_inject_offset_valid(const 
struct timespec *ts)
return true;
 }
 
-#define CURRENT_TIME   (current_kernel_time())
-#define CURRENT_TIME_SEC   ((struct timespec) { get_seconds(), 0 })
-
 /* Some architectures do not supply their own clocksource.
  * This is mainly the case in architectures that get their
  * inter-tick times by reading the counter on their interval
-- 
2.7.4



[PATCH 12/12] time: Delete current_fs_time() function

2017-04-07 Thread Deepa Dinamani
All uses of the current_fs_time() function have been
replaced by other time interfaces.

And, its use cases can be fulfilled by current_time()
or ktime_get_* variants.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 include/linux/fs.h |  1 -
 kernel/time/time.c | 14 --
 2 files changed, 15 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index f1d7347..cce6c57 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1430,7 +1430,6 @@ static inline void i_gid_write(struct inode *inode, gid_t 
gid)
inode->i_gid = make_kgid(inode->i_sb->s_user_ns, gid);
 }
 
-extern struct timespec current_fs_time(struct super_block *sb);
 extern struct timespec current_time(struct inode *inode);
 
 /*
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..cf69cca 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -230,20 +230,6 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
 }
 
-/**
- * current_fs_time - Return FS time
- * @sb: Superblock.
- *
- * Return the current time truncated to the time granularity supported by
- * the fs.
- */
-struct timespec current_fs_time(struct super_block *sb)
-{
-   struct timespec now = current_kernel_time();
-   return timespec_trunc(now, sb->s_time_gran);
-}
-EXPORT_SYMBOL(current_fs_time);
-
 /*
  * Convert jiffies to milliseconds and back.
  *
-- 
2.7.4



[PATCH 12/12] time: Delete current_fs_time() function

2017-04-07 Thread Deepa Dinamani
All uses of the current_fs_time() function have been
replaced by other time interfaces.

And, its use cases can be fulfilled by current_time()
or ktime_get_* variants.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 include/linux/fs.h |  1 -
 kernel/time/time.c | 14 --
 2 files changed, 15 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index f1d7347..cce6c57 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1430,7 +1430,6 @@ static inline void i_gid_write(struct inode *inode, gid_t 
gid)
inode->i_gid = make_kgid(inode->i_sb->s_user_ns, gid);
 }
 
-extern struct timespec current_fs_time(struct super_block *sb);
 extern struct timespec current_time(struct inode *inode);
 
 /*
diff --git a/kernel/time/time.c b/kernel/time/time.c
index 25bdd25..cf69cca 100644
--- a/kernel/time/time.c
+++ b/kernel/time/time.c
@@ -230,20 +230,6 @@ SYSCALL_DEFINE1(adjtimex, struct timex __user *, txc_p)
return copy_to_user(txc_p, , sizeof(struct timex)) ? -EFAULT : ret;
 }
 
-/**
- * current_fs_time - Return FS time
- * @sb: Superblock.
- *
- * Return the current time truncated to the time granularity supported by
- * the fs.
- */
-struct timespec current_fs_time(struct super_block *sb)
-{
-   struct timespec now = current_kernel_time();
-   return timespec_trunc(now, sb->s_time_gran);
-}
-EXPORT_SYMBOL(current_fs_time);
-
 /*
  * Convert jiffies to milliseconds and back.
  *
-- 
2.7.4



[PATCH 08/12] fs: ubifs: Replace CURRENT_TIME_SEC with current_time

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME_SEC is not y2038 safe. current_time() will
be transitioned to use 64 bit time along with vfs in a
separate patch.
There is no plan to transition CURRENT_TIME_SEC to use
y2038 safe time interfaces.

current_time() returns timestamps according to the
granularities set in the inode's super_block.
The granularity check to call current_fs_time() or
CURRENT_TIME_SEC is not required.

Use current_time() directly to update inode timestamp.
Use timespec_trunc during file system creation, before
the first inode is created.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 fs/ubifs/dir.c   | 12 ++--
 fs/ubifs/file.c  | 12 ++--
 fs/ubifs/ioctl.c |  2 +-
 fs/ubifs/misc.h  | 10 --
 fs/ubifs/sb.c| 14 ++
 fs/ubifs/xattr.c |  6 +++---
 6 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 30825d88..8510d79 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -121,7 +121,7 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct 
inode *dir,
 
inode_init_owner(inode, dir, mode);
inode->i_mtime = inode->i_atime = inode->i_ctime =
-ubifs_current_time(inode);
+current_time(inode);
inode->i_mapping->nrpages = 0;
 
switch (mode & S_IFMT) {
@@ -750,7 +750,7 @@ static int ubifs_link(struct dentry *old_dentry, struct 
inode *dir,
lock_2_inodes(dir, inode);
inc_nlink(inode);
ihold(inode);
-   inode->i_ctime = ubifs_current_time(inode);
+   inode->i_ctime = current_time(inode);
dir->i_size += sz_change;
dir_ui->ui_size = dir->i_size;
dir->i_mtime = dir->i_ctime = inode->i_ctime;
@@ -823,7 +823,7 @@ static int ubifs_unlink(struct inode *dir, struct dentry 
*dentry)
}
 
lock_2_inodes(dir, inode);
-   inode->i_ctime = ubifs_current_time(dir);
+   inode->i_ctime = current_time(dir);
drop_nlink(inode);
dir->i_size -= sz_change;
dir_ui->ui_size = dir->i_size;
@@ -927,7 +927,7 @@ static int ubifs_rmdir(struct inode *dir, struct dentry 
*dentry)
}
 
lock_2_inodes(dir, inode);
-   inode->i_ctime = ubifs_current_time(dir);
+   inode->i_ctime = current_time(dir);
clear_nlink(inode);
drop_nlink(dir);
dir->i_size -= sz_change;
@@ -1405,7 +1405,7 @@ static int do_rename(struct inode *old_dir, struct dentry 
*old_dentry,
 * Like most other Unix systems, set the @i_ctime for inodes on a
 * rename.
 */
-   time = ubifs_current_time(old_dir);
+   time = current_time(old_dir);
old_inode->i_ctime = time;
 
/* We must adjust parent link count when renaming directories */
@@ -1578,7 +1578,7 @@ static int ubifs_xrename(struct inode *old_dir, struct 
dentry *old_dentry,
 
lock_4_inodes(old_dir, new_dir, NULL, NULL);
 
-   time = ubifs_current_time(old_dir);
+   time = current_time(old_dir);
fst_inode->i_ctime = time;
snd_inode->i_ctime = time;
old_dir->i_mtime = old_dir->i_ctime = time;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index d9ae86f..2cda3d6 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1196,7 +1196,7 @@ static int do_truncation(struct ubifs_info *c, struct 
inode *inode,
mutex_lock(>ui_mutex);
ui->ui_size = inode->i_size;
/* Truncation changes inode [mc]time */
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
/* Other attributes may be changed at the same time as well */
do_attr_changes(inode, attr);
err = ubifs_jnl_truncate(c, inode, old_size, new_size);
@@ -1243,7 +1243,7 @@ static int do_setattr(struct ubifs_info *c, struct inode 
*inode,
mutex_lock(>ui_mutex);
if (attr->ia_valid & ATTR_SIZE) {
/* Truncation changes inode [mc]time */
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
/* 'truncate_setsize()' changed @i_size, update @ui_size */
ui->ui_size = inode->i_size;
}
@@ -1420,7 +1420,7 @@ int ubifs_update_time(struct inode *inode, struct 
timespec *time,
  */
 static int update_mctime(struct inode *inode)
 {
-   struct timespec now = ubifs_current_time(inode);
+   struct timespec now = current_time(inode);
struct ubifs_inode *ui = ubifs_inode(inode);
struct ubifs_info *c = inode->i_sb->s_fs_info;
 
@@ -1434,7 +1434,7 @@ static int update_mctime(struct inode *inode)
return err;
 
mutex_lock(>ui_mutex);
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
release = ui->dirty;
  

[PATCH 08/12] fs: ubifs: Replace CURRENT_TIME_SEC with current_time

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME_SEC is not y2038 safe. current_time() will
be transitioned to use 64 bit time along with vfs in a
separate patch.
There is no plan to transition CURRENT_TIME_SEC to use
y2038 safe time interfaces.

current_time() returns timestamps according to the
granularities set in the inode's super_block.
The granularity check to call current_fs_time() or
CURRENT_TIME_SEC is not required.

Use current_time() directly to update inode timestamp.
Use timespec_trunc during file system creation, before
the first inode is created.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 fs/ubifs/dir.c   | 12 ++--
 fs/ubifs/file.c  | 12 ++--
 fs/ubifs/ioctl.c |  2 +-
 fs/ubifs/misc.h  | 10 --
 fs/ubifs/sb.c| 14 ++
 fs/ubifs/xattr.c |  6 +++---
 6 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 30825d88..8510d79 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -121,7 +121,7 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct 
inode *dir,
 
inode_init_owner(inode, dir, mode);
inode->i_mtime = inode->i_atime = inode->i_ctime =
-ubifs_current_time(inode);
+current_time(inode);
inode->i_mapping->nrpages = 0;
 
switch (mode & S_IFMT) {
@@ -750,7 +750,7 @@ static int ubifs_link(struct dentry *old_dentry, struct 
inode *dir,
lock_2_inodes(dir, inode);
inc_nlink(inode);
ihold(inode);
-   inode->i_ctime = ubifs_current_time(inode);
+   inode->i_ctime = current_time(inode);
dir->i_size += sz_change;
dir_ui->ui_size = dir->i_size;
dir->i_mtime = dir->i_ctime = inode->i_ctime;
@@ -823,7 +823,7 @@ static int ubifs_unlink(struct inode *dir, struct dentry 
*dentry)
}
 
lock_2_inodes(dir, inode);
-   inode->i_ctime = ubifs_current_time(dir);
+   inode->i_ctime = current_time(dir);
drop_nlink(inode);
dir->i_size -= sz_change;
dir_ui->ui_size = dir->i_size;
@@ -927,7 +927,7 @@ static int ubifs_rmdir(struct inode *dir, struct dentry 
*dentry)
}
 
lock_2_inodes(dir, inode);
-   inode->i_ctime = ubifs_current_time(dir);
+   inode->i_ctime = current_time(dir);
clear_nlink(inode);
drop_nlink(dir);
dir->i_size -= sz_change;
@@ -1405,7 +1405,7 @@ static int do_rename(struct inode *old_dir, struct dentry 
*old_dentry,
 * Like most other Unix systems, set the @i_ctime for inodes on a
 * rename.
 */
-   time = ubifs_current_time(old_dir);
+   time = current_time(old_dir);
old_inode->i_ctime = time;
 
/* We must adjust parent link count when renaming directories */
@@ -1578,7 +1578,7 @@ static int ubifs_xrename(struct inode *old_dir, struct 
dentry *old_dentry,
 
lock_4_inodes(old_dir, new_dir, NULL, NULL);
 
-   time = ubifs_current_time(old_dir);
+   time = current_time(old_dir);
fst_inode->i_ctime = time;
snd_inode->i_ctime = time;
old_dir->i_mtime = old_dir->i_ctime = time;
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index d9ae86f..2cda3d6 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -1196,7 +1196,7 @@ static int do_truncation(struct ubifs_info *c, struct 
inode *inode,
mutex_lock(>ui_mutex);
ui->ui_size = inode->i_size;
/* Truncation changes inode [mc]time */
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
/* Other attributes may be changed at the same time as well */
do_attr_changes(inode, attr);
err = ubifs_jnl_truncate(c, inode, old_size, new_size);
@@ -1243,7 +1243,7 @@ static int do_setattr(struct ubifs_info *c, struct inode 
*inode,
mutex_lock(>ui_mutex);
if (attr->ia_valid & ATTR_SIZE) {
/* Truncation changes inode [mc]time */
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
/* 'truncate_setsize()' changed @i_size, update @ui_size */
ui->ui_size = inode->i_size;
}
@@ -1420,7 +1420,7 @@ int ubifs_update_time(struct inode *inode, struct 
timespec *time,
  */
 static int update_mctime(struct inode *inode)
 {
-   struct timespec now = ubifs_current_time(inode);
+   struct timespec now = current_time(inode);
struct ubifs_inode *ui = ubifs_inode(inode);
struct ubifs_info *c = inode->i_sb->s_fs_info;
 
@@ -1434,7 +1434,7 @@ static int update_mctime(struct inode *inode)
return err;
 
mutex_lock(>ui_mutex);
-   inode->i_mtime = inode->i_ctime = ubifs_current_time(inode);
+   inode->i_mtime = inode->i_ctime = current_time(inode);
release = ui->dirty;
mark_inode_dirty_sync(inode);
   

[PATCH 04/12] fs: ceph: CURRENT_TIME with ktime_get_real_ts()

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
The macro will be deleted and all the references to it
will be replaced by ktime_get_* apis.

struct timespec is also not y2038 safe.
Retain timespec for timestamp representation here as ceph
uses it internally everywhere.
These references will be changed to use struct timespec64
in a separate patch.

The current_fs_time() api is being changed to use vfs
struct inode* as an argument instead of struct super_block*.

Set the new mds client request r_stamp field using
ktime_get_real_ts() instead of using current_fs_time().

Also, since r_stamp is used as mtime on the server, use
timespec_trunc() to truncate the timestamp, using the right
granularity from the superblock.

This api will be transitioned to be y2038 safe along
with vfs.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 drivers/block/rbd.c   | 2 +-
 fs/ceph/mds_client.c  | 4 +++-
 net/ceph/messenger.c  | 6 --
 net/ceph/osd_client.c | 4 ++--
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 517838b..77204da 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1922,7 +1922,7 @@ static void rbd_osd_req_format_write(struct 
rbd_obj_request *obj_request)
 {
struct ceph_osd_request *osd_req = obj_request->osd_req;
 
-   osd_req->r_mtime = CURRENT_TIME;
+   ktime_get_real_ts(_req->r_mtime);
osd_req->r_data_offset = obj_request->offset;
 }
 
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index c681762..1d3fa90 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1666,6 +1666,7 @@ struct ceph_mds_request *
 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)
 {
struct ceph_mds_request *req = kzalloc(sizeof(*req), GFP_NOFS);
+   struct timespec ts;
 
if (!req)
return ERR_PTR(-ENOMEM);
@@ -1684,7 +1685,8 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, 
int op, int mode)
init_completion(>r_safe_completion);
INIT_LIST_HEAD(>r_unsafe_item);
 
-   req->r_stamp = current_fs_time(mdsc->fsc->sb);
+   ktime_get_real_ts();
+   req->r_stamp = timespec_trunc(ts, mdsc->fsc->sb->s_time_gran);
 
req->r_op = op;
req->r_direct_mode = mode;
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index f76bb33..5766a6c 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1386,8 +1386,9 @@ static void prepare_write_keepalive(struct 
ceph_connection *con)
dout("prepare_write_keepalive %p\n", con);
con_out_kvec_reset(con);
if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) {
-   struct timespec now = CURRENT_TIME;
+   struct timespec now;
 
+   ktime_get_real_ts();
con_out_kvec_add(con, sizeof(tag_keepalive2), _keepalive2);
ceph_encode_timespec(>out_temp_keepalive2, );
con_out_kvec_add(con, sizeof(con->out_temp_keepalive2),
@@ -3176,8 +3177,9 @@ bool ceph_con_keepalive_expired(struct ceph_connection 
*con,
 {
if (interval > 0 &&
(con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2)) {
-   struct timespec now = CURRENT_TIME;
+   struct timespec now;
struct timespec ts;
+   ktime_get_real_ts();
jiffies_to_timespec(interval, );
ts = timespec_add(con->last_keepalive_ack, ts);
return timespec_compare(, ) >= 0;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index e15ea9e..242d7c0 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -3574,7 +3574,7 @@ ceph_osdc_watch(struct ceph_osd_client *osdc,
ceph_oid_copy(>t.base_oid, oid);
ceph_oloc_copy(>t.base_oloc, oloc);
lreq->t.flags = CEPH_OSD_FLAG_WRITE;
-   lreq->mtime = CURRENT_TIME;
+   ktime_get_real_ts(>mtime);
 
lreq->reg_req = alloc_linger_request(lreq);
if (!lreq->reg_req) {
@@ -3632,7 +3632,7 @@ int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
ceph_oid_copy(>r_base_oid, >t.base_oid);
ceph_oloc_copy(>r_base_oloc, >t.base_oloc);
req->r_flags = CEPH_OSD_FLAG_WRITE;
-   req->r_mtime = CURRENT_TIME;
+   ktime_get_real_ts(>r_mtime);
osd_req_op_watch_init(req, 0, lreq->linger_id,
  CEPH_OSD_WATCH_OP_UNWATCH);
 
-- 
2.7.4



[PATCH 04/12] fs: ceph: CURRENT_TIME with ktime_get_real_ts()

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME is not y2038 safe.
The macro will be deleted and all the references to it
will be replaced by ktime_get_* apis.

struct timespec is also not y2038 safe.
Retain timespec for timestamp representation here as ceph
uses it internally everywhere.
These references will be changed to use struct timespec64
in a separate patch.

The current_fs_time() api is being changed to use vfs
struct inode* as an argument instead of struct super_block*.

Set the new mds client request r_stamp field using
ktime_get_real_ts() instead of using current_fs_time().

Also, since r_stamp is used as mtime on the server, use
timespec_trunc() to truncate the timestamp, using the right
granularity from the superblock.

This api will be transitioned to be y2038 safe along
with vfs.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 drivers/block/rbd.c   | 2 +-
 fs/ceph/mds_client.c  | 4 +++-
 net/ceph/messenger.c  | 6 --
 net/ceph/osd_client.c | 4 ++--
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 517838b..77204da 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1922,7 +1922,7 @@ static void rbd_osd_req_format_write(struct 
rbd_obj_request *obj_request)
 {
struct ceph_osd_request *osd_req = obj_request->osd_req;
 
-   osd_req->r_mtime = CURRENT_TIME;
+   ktime_get_real_ts(_req->r_mtime);
osd_req->r_data_offset = obj_request->offset;
 }
 
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index c681762..1d3fa90 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1666,6 +1666,7 @@ struct ceph_mds_request *
 ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode)
 {
struct ceph_mds_request *req = kzalloc(sizeof(*req), GFP_NOFS);
+   struct timespec ts;
 
if (!req)
return ERR_PTR(-ENOMEM);
@@ -1684,7 +1685,8 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, 
int op, int mode)
init_completion(>r_safe_completion);
INIT_LIST_HEAD(>r_unsafe_item);
 
-   req->r_stamp = current_fs_time(mdsc->fsc->sb);
+   ktime_get_real_ts();
+   req->r_stamp = timespec_trunc(ts, mdsc->fsc->sb->s_time_gran);
 
req->r_op = op;
req->r_direct_mode = mode;
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index f76bb33..5766a6c 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1386,8 +1386,9 @@ static void prepare_write_keepalive(struct 
ceph_connection *con)
dout("prepare_write_keepalive %p\n", con);
con_out_kvec_reset(con);
if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) {
-   struct timespec now = CURRENT_TIME;
+   struct timespec now;
 
+   ktime_get_real_ts();
con_out_kvec_add(con, sizeof(tag_keepalive2), _keepalive2);
ceph_encode_timespec(>out_temp_keepalive2, );
con_out_kvec_add(con, sizeof(con->out_temp_keepalive2),
@@ -3176,8 +3177,9 @@ bool ceph_con_keepalive_expired(struct ceph_connection 
*con,
 {
if (interval > 0 &&
(con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2)) {
-   struct timespec now = CURRENT_TIME;
+   struct timespec now;
struct timespec ts;
+   ktime_get_real_ts();
jiffies_to_timespec(interval, );
ts = timespec_add(con->last_keepalive_ack, ts);
return timespec_compare(, ) >= 0;
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index e15ea9e..242d7c0 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -3574,7 +3574,7 @@ ceph_osdc_watch(struct ceph_osd_client *osdc,
ceph_oid_copy(>t.base_oid, oid);
ceph_oloc_copy(>t.base_oloc, oloc);
lreq->t.flags = CEPH_OSD_FLAG_WRITE;
-   lreq->mtime = CURRENT_TIME;
+   ktime_get_real_ts(>mtime);
 
lreq->reg_req = alloc_linger_request(lreq);
if (!lreq->reg_req) {
@@ -3632,7 +3632,7 @@ int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
ceph_oid_copy(>r_base_oid, >t.base_oid);
ceph_oloc_copy(>r_base_oloc, >t.base_oloc);
req->r_flags = CEPH_OSD_FLAG_WRITE;
-   req->r_mtime = CURRENT_TIME;
+   ktime_get_real_ts(>r_mtime);
osd_req_op_watch_init(req, 0, lreq->linger_id,
  CEPH_OSD_WATCH_OP_UNWATCH);
 
-- 
2.7.4



[PATCH 03/12] fs: cifs: Replace CURRENT_TIME by other appropriate apis

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time() for filesystem times, and ktime_get_*
functions for authentication timestamps and timezone
calculations.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

The inode timestamps read from the server are assumed
to have correct granularity and range.

The patch also assumes that the difference between server and
client times lie in the range INT_MIN..INT_MAX. This is valid
because this is the difference between current times between
server and client, and the largest timezone difference is in the
range of one day.

All cifs timestamps currently use timespec representation internally.
Authentication and timezone timestamps can also be transitioned into
using timespec64 when all other timestamps for cifs is transitioned
to use timespec64.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 fs/cifs/cifsencrypt.c |  4 +++-
 fs/cifs/cifssmb.c | 10 +-
 fs/cifs/inode.c   | 28 +++-
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 058ac9b..68abbb0 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -478,6 +478,7 @@ find_timestamp(struct cifs_ses *ses)
unsigned char *blobptr;
unsigned char *blobend;
struct ntlmssp2_name *attrptr;
+   struct timespec ts;
 
if (!ses->auth_key.len || !ses->auth_key.response)
return 0;
@@ -502,7 +503,8 @@ find_timestamp(struct cifs_ses *ses)
blobptr += attrsize; /* advance attr value */
}
 
-   return cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
+   ktime_get_real_ts();
+   return cpu_to_le64(cifs_UnixTimeToNT(ts));
 }
 
 static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 0669506..2f279b7 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -478,14 +478,14 @@ decode_lanman_negprot_rsp(struct TCP_Server_Info *server, 
NEGOTIATE_RSP *pSMBr)
 * this requirement.
 */
int val, seconds, remain, result;
-   struct timespec ts, utc;
-   utc = CURRENT_TIME;
+   struct timespec ts;
+   unsigned long utc = ktime_get_real_seconds();
ts = cnvrtDosUnixTm(rsp->SrvTime.Date,
rsp->SrvTime.Time, 0);
cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n",
-(int)ts.tv_sec, (int)utc.tv_sec,
-(int)(utc.tv_sec - ts.tv_sec));
-   val = (int)(utc.tv_sec - ts.tv_sec);
+(int)ts.tv_sec, (int)utc,
+(int)(utc - ts.tv_sec));
+   val = (int)(utc - ts.tv_sec);
seconds = abs(val);
result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ;
remain = seconds % MIN_TZ_ADJ;
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index b261db3..c3b2fa0 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -322,9 +322,9 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct 
super_block *sb)
fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU;
fattr->cf_uid = cifs_sb->mnt_uid;
fattr->cf_gid = cifs_sb->mnt_gid;
-   fattr->cf_atime = CURRENT_TIME;
-   fattr->cf_ctime = CURRENT_TIME;
-   fattr->cf_mtime = CURRENT_TIME;
+   ktime_get_real_ts(>cf_mtime);
+   fattr->cf_mtime = timespec_trunc(fattr->cf_mtime, sb->s_time_gran);
+   fattr->cf_atime = fattr->cf_ctime = fattr->cf_mtime;
fattr->cf_nlink = 2;
fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL;
 }
@@ -586,9 +586,10 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const 
unsigned char *path,
 /* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
 static void
 cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
-  struct cifs_sb_info *cifs_sb, bool adjust_tz,
+  struct super_block *sb, bool adjust_tz,
   bool symlink)
 {
+   struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 
memset(fattr, 0, sizeof(*fattr));
@@ -598,8 +599,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, 
FILE_ALL_INFO *info,
 
if (info->LastAccessTime)
fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
-   else
-   fattr->cf_atime = CURRENT_TIME;
+   else {
+   ktime_get_real_ts(>cf_atime);
+   fattr->cf_atime = timespec_trunc(fattr->cf_atime, 
sb->s_time_gran);
+   }
 
fattr->cf_ctime = 

[PATCH 03/12] fs: cifs: Replace CURRENT_TIME by other appropriate apis

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME macro is not y2038 safe on 32 bit systems.

The patch replaces all the uses of CURRENT_TIME by
current_time() for filesystem times, and ktime_get_*
functions for authentication timestamps and timezone
calculations.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe.

CURRENT_TIME macro will be deleted before merging the
aforementioned change.

The inode timestamps read from the server are assumed
to have correct granularity and range.

The patch also assumes that the difference between server and
client times lie in the range INT_MIN..INT_MAX. This is valid
because this is the difference between current times between
server and client, and the largest timezone difference is in the
range of one day.

All cifs timestamps currently use timespec representation internally.
Authentication and timezone timestamps can also be transitioned into
using timespec64 when all other timestamps for cifs is transitioned
to use timespec64.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 fs/cifs/cifsencrypt.c |  4 +++-
 fs/cifs/cifssmb.c | 10 +-
 fs/cifs/inode.c   | 28 +++-
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 058ac9b..68abbb0 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -478,6 +478,7 @@ find_timestamp(struct cifs_ses *ses)
unsigned char *blobptr;
unsigned char *blobend;
struct ntlmssp2_name *attrptr;
+   struct timespec ts;
 
if (!ses->auth_key.len || !ses->auth_key.response)
return 0;
@@ -502,7 +503,8 @@ find_timestamp(struct cifs_ses *ses)
blobptr += attrsize; /* advance attr value */
}
 
-   return cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
+   ktime_get_real_ts();
+   return cpu_to_le64(cifs_UnixTimeToNT(ts));
 }
 
 static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 0669506..2f279b7 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -478,14 +478,14 @@ decode_lanman_negprot_rsp(struct TCP_Server_Info *server, 
NEGOTIATE_RSP *pSMBr)
 * this requirement.
 */
int val, seconds, remain, result;
-   struct timespec ts, utc;
-   utc = CURRENT_TIME;
+   struct timespec ts;
+   unsigned long utc = ktime_get_real_seconds();
ts = cnvrtDosUnixTm(rsp->SrvTime.Date,
rsp->SrvTime.Time, 0);
cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n",
-(int)ts.tv_sec, (int)utc.tv_sec,
-(int)(utc.tv_sec - ts.tv_sec));
-   val = (int)(utc.tv_sec - ts.tv_sec);
+(int)ts.tv_sec, (int)utc,
+(int)(utc - ts.tv_sec));
+   val = (int)(utc - ts.tv_sec);
seconds = abs(val);
result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ;
remain = seconds % MIN_TZ_ADJ;
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index b261db3..c3b2fa0 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -322,9 +322,9 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct 
super_block *sb)
fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU;
fattr->cf_uid = cifs_sb->mnt_uid;
fattr->cf_gid = cifs_sb->mnt_gid;
-   fattr->cf_atime = CURRENT_TIME;
-   fattr->cf_ctime = CURRENT_TIME;
-   fattr->cf_mtime = CURRENT_TIME;
+   ktime_get_real_ts(>cf_mtime);
+   fattr->cf_mtime = timespec_trunc(fattr->cf_mtime, sb->s_time_gran);
+   fattr->cf_atime = fattr->cf_ctime = fattr->cf_mtime;
fattr->cf_nlink = 2;
fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL;
 }
@@ -586,9 +586,10 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const 
unsigned char *path,
 /* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
 static void
 cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
-  struct cifs_sb_info *cifs_sb, bool adjust_tz,
+  struct super_block *sb, bool adjust_tz,
   bool symlink)
 {
+   struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 
memset(fattr, 0, sizeof(*fattr));
@@ -598,8 +599,10 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, 
FILE_ALL_INFO *info,
 
if (info->LastAccessTime)
fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
-   else
-   fattr->cf_atime = CURRENT_TIME;
+   else {
+   ktime_get_real_ts(>cf_atime);
+   fattr->cf_atime = timespec_trunc(fattr->cf_atime, 
sb->s_time_gran);
+   }
 
fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);

[PATCH 06/12] audit: Use timespec64 to represent audit timestamps

2017-04-07 Thread Deepa Dinamani
struct timespec is not y2038 safe.
Audit timestamps are recorded in string format into
an audit buffer for a given context.
These mark the entry timestamps for the syscalls.
Use y2038 safe struct timespec64 to represent the times.
The log strings can handle this transition as strings can
hold upto 1024 characters.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
Acked-by: Paul Moore 
Acked-by: Richard Guy Briggs 
---
 include/linux/audit.h |  4 ++--
 kernel/audit.c| 10 +-
 kernel/audit.h|  2 +-
 kernel/auditsc.c  |  6 +++---
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 6fdfefc..f830508 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -332,7 +332,7 @@ static inline void audit_ptrace(struct task_struct *t)
/* Private API (for audit.c only) */
 extern unsigned int audit_serial(void);
 extern int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial);
+ struct timespec64 *t, unsigned int *serial);
 extern int audit_set_loginuid(kuid_t loginuid);
 
 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
@@ -511,7 +511,7 @@ static inline void __audit_seccomp(unsigned long syscall, 
long signr, int code)
 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
 { }
 static inline int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial)
+ struct timespec64 *t, unsigned int *serial)
 {
return 0;
 }
diff --git a/kernel/audit.c b/kernel/audit.c
index 2f4964c..fcbf377 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1625,10 +1625,10 @@ unsigned int audit_serial(void)
 }
 
 static inline void audit_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
-   *t = CURRENT_TIME;
+   ktime_get_real_ts64(t);
*serial = audit_serial();
}
 }
@@ -1652,7 +1652,7 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
 int type)
 {
struct audit_buffer *ab;
-   struct timespec t;
+   struct timespec64 t;
unsigned int uninitialized_var(serial);
 
if (audit_initialized != AUDIT_INITIALIZED)
@@ -1705,8 +1705,8 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
}
 
audit_get_stamp(ab->ctx, , );
-   audit_log_format(ab, "audit(%lu.%03lu:%u): ",
-t.tv_sec, t.tv_nsec/100, serial);
+   audit_log_format(ab, "audit(%llu.%03lu:%u): ",
+(unsigned long long)t.tv_sec, t.tv_nsec/100, 
serial);
 
return ab;
 }
diff --git a/kernel/audit.h b/kernel/audit.h
index 0f1cf6d..cdf96f4 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -112,7 +112,7 @@ struct audit_context {
enum audit_statestate, current_state;
unsigned intserial; /* serial number for record */
int major;  /* syscall number */
-   struct timespec ctime;  /* time of syscall entry */
+   struct timespec64   ctime;  /* time of syscall entry */
unsigned long   argv[4];/* syscall arguments */
longreturn_code;/* syscall return code */
u64 prio;
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index e59ffc7..a2d9217 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1532,7 +1532,7 @@ void __audit_syscall_entry(int major, unsigned long a1, 
unsigned long a2,
return;
 
context->serial = 0;
-   context->ctime  = CURRENT_TIME;
+   ktime_get_real_ts64(>ctime);
context->in_syscall = 1;
context->current_state  = state;
context->ppid   = 0;
@@ -1941,13 +1941,13 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
 /**
  * auditsc_get_stamp - get local copies of audit_context values
  * @ctx: audit_context for the task
- * @t: timespec to store time recorded in the audit_context
+ * @t: timespec64 to store time recorded in the audit_context
  * @serial: serial value that is recorded in the audit_context
  *
  * Also sets the context as auditable.
  */
 int auditsc_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx->in_syscall)
return 0;
-- 
2.7.4



[PATCH 06/12] audit: Use timespec64 to represent audit timestamps

2017-04-07 Thread Deepa Dinamani
struct timespec is not y2038 safe.
Audit timestamps are recorded in string format into
an audit buffer for a given context.
These mark the entry timestamps for the syscalls.
Use y2038 safe struct timespec64 to represent the times.
The log strings can handle this transition as strings can
hold upto 1024 characters.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
Acked-by: Paul Moore 
Acked-by: Richard Guy Briggs 
---
 include/linux/audit.h |  4 ++--
 kernel/audit.c| 10 +-
 kernel/audit.h|  2 +-
 kernel/auditsc.c  |  6 +++---
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 6fdfefc..f830508 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -332,7 +332,7 @@ static inline void audit_ptrace(struct task_struct *t)
/* Private API (for audit.c only) */
 extern unsigned int audit_serial(void);
 extern int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial);
+ struct timespec64 *t, unsigned int *serial);
 extern int audit_set_loginuid(kuid_t loginuid);
 
 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
@@ -511,7 +511,7 @@ static inline void __audit_seccomp(unsigned long syscall, 
long signr, int code)
 static inline void audit_seccomp(unsigned long syscall, long signr, int code)
 { }
 static inline int auditsc_get_stamp(struct audit_context *ctx,
- struct timespec *t, unsigned int *serial)
+ struct timespec64 *t, unsigned int *serial)
 {
return 0;
 }
diff --git a/kernel/audit.c b/kernel/audit.c
index 2f4964c..fcbf377 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -1625,10 +1625,10 @@ unsigned int audit_serial(void)
 }
 
 static inline void audit_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
-   *t = CURRENT_TIME;
+   ktime_get_real_ts64(t);
*serial = audit_serial();
}
 }
@@ -1652,7 +1652,7 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
 int type)
 {
struct audit_buffer *ab;
-   struct timespec t;
+   struct timespec64 t;
unsigned int uninitialized_var(serial);
 
if (audit_initialized != AUDIT_INITIALIZED)
@@ -1705,8 +1705,8 @@ struct audit_buffer *audit_log_start(struct audit_context 
*ctx, gfp_t gfp_mask,
}
 
audit_get_stamp(ab->ctx, , );
-   audit_log_format(ab, "audit(%lu.%03lu:%u): ",
-t.tv_sec, t.tv_nsec/100, serial);
+   audit_log_format(ab, "audit(%llu.%03lu:%u): ",
+(unsigned long long)t.tv_sec, t.tv_nsec/100, 
serial);
 
return ab;
 }
diff --git a/kernel/audit.h b/kernel/audit.h
index 0f1cf6d..cdf96f4 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -112,7 +112,7 @@ struct audit_context {
enum audit_statestate, current_state;
unsigned intserial; /* serial number for record */
int major;  /* syscall number */
-   struct timespec ctime;  /* time of syscall entry */
+   struct timespec64   ctime;  /* time of syscall entry */
unsigned long   argv[4];/* syscall arguments */
longreturn_code;/* syscall return code */
u64 prio;
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index e59ffc7..a2d9217 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -1532,7 +1532,7 @@ void __audit_syscall_entry(int major, unsigned long a1, 
unsigned long a2,
return;
 
context->serial = 0;
-   context->ctime  = CURRENT_TIME;
+   ktime_get_real_ts64(>ctime);
context->in_syscall = 1;
context->current_state  = state;
context->ppid   = 0;
@@ -1941,13 +1941,13 @@ EXPORT_SYMBOL_GPL(__audit_inode_child);
 /**
  * auditsc_get_stamp - get local copies of audit_context values
  * @ctx: audit_context for the task
- * @t: timespec to store time recorded in the audit_context
+ * @t: timespec64 to store time recorded in the audit_context
  * @serial: serial value that is recorded in the audit_context
  *
  * Also sets the context as auditable.
  */
 int auditsc_get_stamp(struct audit_context *ctx,
-  struct timespec *t, unsigned int *serial)
+  struct timespec64 *t, unsigned int *serial)
 {
if (!ctx->in_syscall)
return 0;
-- 
2.7.4



[PATCH 01/12] fs: f2fs: Use ktime_get_real_seconds for sit_info times

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME_SEC is not y2038 safe.

Replace use of CURRENT_TIME_SEC with ktime_get_real_seconds
in segment timestamps used by GC algorithm including the
segment mtime timestamps.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 fs/f2fs/segment.c | 2 +-
 fs/f2fs/segment.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 010324c..0531500 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2678,7 +2678,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
sit_i->dirty_sentries = 0;
sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK;
sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time);
-   sit_i->mounted_time = CURRENT_TIME_SEC.tv_sec;
+   sit_i->mounted_time = ktime_get_real_seconds();
mutex_init(_i->sentry_lock);
return 0;
 }
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 57e36c1..156afc3 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -692,8 +692,9 @@ static inline void set_to_next_sit(struct sit_info *sit_i, 
unsigned int start)
 static inline unsigned long long get_mtime(struct f2fs_sb_info *sbi)
 {
struct sit_info *sit_i = SIT_I(sbi);
-   return sit_i->elapsed_time + CURRENT_TIME_SEC.tv_sec -
-   sit_i->mounted_time;
+   time64_t now = ktime_get_real_seconds();
+
+   return sit_i->elapsed_time + now - sit_i->mounted_time;
 }
 
 static inline void set_summary(struct f2fs_summary *sum, nid_t nid,
-- 
2.7.4



[PATCH 01/12] fs: f2fs: Use ktime_get_real_seconds for sit_info times

2017-04-07 Thread Deepa Dinamani
CURRENT_TIME_SEC is not y2038 safe.

Replace use of CURRENT_TIME_SEC with ktime_get_real_seconds
in segment timestamps used by GC algorithm including the
segment mtime timestamps.

Signed-off-by: Deepa Dinamani 
Reviewed-by: Arnd Bergmann 
---
 fs/f2fs/segment.c | 2 +-
 fs/f2fs/segment.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 010324c..0531500 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2678,7 +2678,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
sit_i->dirty_sentries = 0;
sit_i->sents_per_block = SIT_ENTRY_PER_BLOCK;
sit_i->elapsed_time = le64_to_cpu(sbi->ckpt->elapsed_time);
-   sit_i->mounted_time = CURRENT_TIME_SEC.tv_sec;
+   sit_i->mounted_time = ktime_get_real_seconds();
mutex_init(_i->sentry_lock);
return 0;
 }
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 57e36c1..156afc3 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -692,8 +692,9 @@ static inline void set_to_next_sit(struct sit_info *sit_i, 
unsigned int start)
 static inline unsigned long long get_mtime(struct f2fs_sb_info *sbi)
 {
struct sit_info *sit_i = SIT_I(sbi);
-   return sit_i->elapsed_time + CURRENT_TIME_SEC.tv_sec -
-   sit_i->mounted_time;
+   time64_t now = ktime_get_real_seconds();
+
+   return sit_i->elapsed_time + now - sit_i->mounted_time;
 }
 
 static inline void set_summary(struct f2fs_summary *sum, nid_t nid,
-- 
2.7.4



[PATCH 00/12] Delete CURRENT_TIME, CURRENT_TIME_SEC and current_fs_time

2017-04-07 Thread Deepa Dinamani
The series contains the last unmerged uses of CURRENT_TIME,
CURRENT_TIME_SEC, and current_fs_time().
The series also deletes these apis.

All the patches except [PATCH 9/12] and [PATCH 10/12] are resend patches.
These patches fix new instances of CURRENT_TIME.
cifs and ceph patches have been squashed so that we have one patch per
filesystem.

We want to get these merged onto 4.12 release so that I can post the series
that changes vfs timestamps to use 64 bits for 4.13 release.

I'm proposing these to be merged through Andrew's tree.

Filesystem maintainers, please let Andrew know if you will be picking up
the patch in your trees.

Let me know if anybody has other preferences for merging.

Deepa Dinamani (12):
  fs: f2fs: Use ktime_get_real_seconds for sit_info times
  trace: Make trace_hwlat timestamp y2038 safe
  fs: cifs: Replace CURRENT_TIME by other appropriate apis
  fs: ceph: CURRENT_TIME with ktime_get_real_ts()
  fs: ufs: Use ktime_get_real_ts64() for birthtime
  audit: Use timespec64 to represent audit timestamps
  fs: btrfs: Use ktime_get_real_ts for root ctime
  fs: ubifs: Replace CURRENT_TIME_SEC with current_time
  lustre: Replace CURRENT_TIME macro
  apparmorfs: Replace CURRENT_TIME with current_time()
  time: Delete CURRENT_TIME_SEC and CURRENT_TIME
  time: Delete current_fs_time() function

 drivers/block/rbd.c |  2 +-
 drivers/staging/lustre/lustre/llite/llite_lib.c |  6 +++---
 drivers/staging/lustre/lustre/osc/osc_io.c  |  4 ++--
 fs/btrfs/root-tree.c|  3 ++-
 fs/ceph/mds_client.c|  4 +++-
 fs/cifs/cifsencrypt.c   |  4 +++-
 fs/cifs/cifssmb.c   | 10 -
 fs/cifs/inode.c | 28 +
 fs/f2fs/segment.c   |  2 +-
 fs/f2fs/segment.h   |  5 +++--
 fs/ubifs/dir.c  | 12 +--
 fs/ubifs/file.c | 12 +--
 fs/ubifs/ioctl.c|  2 +-
 fs/ubifs/misc.h | 10 -
 fs/ubifs/sb.c   | 14 +
 fs/ubifs/xattr.c|  6 +++---
 fs/ufs/ialloc.c |  6 --
 include/linux/audit.h   |  4 ++--
 include/linux/fs.h  |  1 -
 include/linux/time.h|  3 ---
 kernel/audit.c  | 10 -
 kernel/audit.h  |  2 +-
 kernel/auditsc.c|  6 +++---
 kernel/time/time.c  | 14 -
 kernel/trace/trace_entries.h|  6 +++---
 kernel/trace/trace_hwlat.c  | 14 ++---
 kernel/trace/trace_output.c |  9 
 net/ceph/messenger.c|  6 --
 net/ceph/osd_client.c   |  4 ++--
 security/apparmor/apparmorfs.c  |  2 +-
 30 files changed, 100 insertions(+), 111 deletions(-)

-- 
2.7.4



[PATCH 00/12] Delete CURRENT_TIME, CURRENT_TIME_SEC and current_fs_time

2017-04-07 Thread Deepa Dinamani
The series contains the last unmerged uses of CURRENT_TIME,
CURRENT_TIME_SEC, and current_fs_time().
The series also deletes these apis.

All the patches except [PATCH 9/12] and [PATCH 10/12] are resend patches.
These patches fix new instances of CURRENT_TIME.
cifs and ceph patches have been squashed so that we have one patch per
filesystem.

We want to get these merged onto 4.12 release so that I can post the series
that changes vfs timestamps to use 64 bits for 4.13 release.

I'm proposing these to be merged through Andrew's tree.

Filesystem maintainers, please let Andrew know if you will be picking up
the patch in your trees.

Let me know if anybody has other preferences for merging.

Deepa Dinamani (12):
  fs: f2fs: Use ktime_get_real_seconds for sit_info times
  trace: Make trace_hwlat timestamp y2038 safe
  fs: cifs: Replace CURRENT_TIME by other appropriate apis
  fs: ceph: CURRENT_TIME with ktime_get_real_ts()
  fs: ufs: Use ktime_get_real_ts64() for birthtime
  audit: Use timespec64 to represent audit timestamps
  fs: btrfs: Use ktime_get_real_ts for root ctime
  fs: ubifs: Replace CURRENT_TIME_SEC with current_time
  lustre: Replace CURRENT_TIME macro
  apparmorfs: Replace CURRENT_TIME with current_time()
  time: Delete CURRENT_TIME_SEC and CURRENT_TIME
  time: Delete current_fs_time() function

 drivers/block/rbd.c |  2 +-
 drivers/staging/lustre/lustre/llite/llite_lib.c |  6 +++---
 drivers/staging/lustre/lustre/osc/osc_io.c  |  4 ++--
 fs/btrfs/root-tree.c|  3 ++-
 fs/ceph/mds_client.c|  4 +++-
 fs/cifs/cifsencrypt.c   |  4 +++-
 fs/cifs/cifssmb.c   | 10 -
 fs/cifs/inode.c | 28 +
 fs/f2fs/segment.c   |  2 +-
 fs/f2fs/segment.h   |  5 +++--
 fs/ubifs/dir.c  | 12 +--
 fs/ubifs/file.c | 12 +--
 fs/ubifs/ioctl.c|  2 +-
 fs/ubifs/misc.h | 10 -
 fs/ubifs/sb.c   | 14 +
 fs/ubifs/xattr.c|  6 +++---
 fs/ufs/ialloc.c |  6 --
 include/linux/audit.h   |  4 ++--
 include/linux/fs.h  |  1 -
 include/linux/time.h|  3 ---
 kernel/audit.c  | 10 -
 kernel/audit.h  |  2 +-
 kernel/auditsc.c|  6 +++---
 kernel/time/time.c  | 14 -
 kernel/trace/trace_entries.h|  6 +++---
 kernel/trace/trace_hwlat.c  | 14 ++---
 kernel/trace/trace_output.c |  9 
 net/ceph/messenger.c|  6 --
 net/ceph/osd_client.c   |  4 ++--
 security/apparmor/apparmorfs.c  |  2 +-
 30 files changed, 100 insertions(+), 111 deletions(-)

-- 
2.7.4



Re: [PATCH -v6 11/13] futex: Rework futex_lock_pi() to use rt_mutex_*_proxy_lock()

2017-04-07 Thread Darren Hart
On Wed, Mar 22, 2017 at 11:35:58AM +0100, Peter Zijlstra wrote:
> By changing futex_lock_pi() to use rt_mutex_*_proxy_lock() we arrive
> at a point where all wait_list modifications are done under both
> hb->lock and wait_lock.
> 
> This closes the obvious interleave pattern between futex_lock_pi() and
> futex_unlock_pi(), but not entirely so. See below:
> 
> Before:
> 
> futex_lock_pi()   futex_unlock_pi()
>   unlock hb->lock
> 
> lock hb->lock
> unlock hb->lock
> 
> lock rt_mutex->wait_lock
> unlock rt_mutex_wait_lock
>   -EAGAIN
> 
>   lock rt_mutex->wait_lock
>   list_add
>   unlock rt_mutex->wait_lock
> 
>   schedule()
> 
>   lock rt_mutex->wait_lock
>   list_del
>   unlock rt_mutex->wait_lock
> 
> 
>   -EAGAIN
> 
>   lock hb->lock
> 
> 
> After:
> 
> futex_lock_pi()   futex_unlock_pi()
> 
>   lock hb->lock
>   lock rt_mutex->wait_lock
>   list_add
>   unlock rt_mutex->wait_lock
>   unlock hb->lock
> 
>   schedule()
> lock hb->lock
> unlock hb->lock
>   lock hb->lock
>   lock rt_mutex->wait_lock
>   list_del
>   unlock rt_mutex->wait_lock
> 
> lock rt_mutex->wait_lock
> unlock rt_mutex_wait_lock

Underscore to dereference:rt_mutex->wait_lock

>   -EAGAIN
> 
>   unlock hb->lock
> 
> 
> It does however solve the earlier starvation/live-lock scenario which
> got introduced with the -EAGAIN since unlike the before scenario;
> where the -EAGAIN happens while futex_unlock_pi() doesn't hold any
> locks; in the after scenario it happens while futex_unlock_pi()

I think you mean futex_lock_pi() here --^
And possibly in the previous reference, although both are true.

> actually holds a lock, and then we can serialize on that lock.
> 
> Signed-off-by: Peter Zijlstra (Intel) 
> ---
>  kernel/futex.c  |   70 
> +++-
>  kernel/locking/rtmutex.c|   13 ---
>  kernel/locking/rtmutex_common.h |1 
>  3 files changed, 48 insertions(+), 36 deletions(-)
> 
> Index: linux-2.6/kernel/futex.c

...

> @@ -2587,6 +2592,7 @@ static int futex_lock_pi(u32 __user *uad

...

> +no_block:
> + /*
>* Fixup the pi_state owner and possibly acquire the lock if we
>* haven't already.
>*/

Deleted a bunch of commentary about the following comment and the code to follow
(which shows up just below this point). Turns out it isn't wrong... it's just
really complex. This snippet used to be self contained within the first if
block, and now the connection to the comment is less direct. I didn't come up
with a better way to say it though so just noting this here in case you or
someone else has a better idea.


/*
 * If fixup_owner() faulted and was unable to handle the fault, unlock
 * it and return the fault to userspace.
 */
if (ret && (rt_mutex_owner(_state->pi_mutex) == current)) {
pi_state = q.pi_state;
get_pi_state(pi_state);
}

/* Unqueue and drop the lock */
unqueue_me_pi();

if (pi_state) {
rt_mutex_futex_unlock(_state->pi_mutex);
put_pi_state(pi_state);
}

-- 
Darren Hart
VMware Open Source Technology Center


Re: [PATCH -v6 11/13] futex: Rework futex_lock_pi() to use rt_mutex_*_proxy_lock()

2017-04-07 Thread Darren Hart
On Wed, Mar 22, 2017 at 11:35:58AM +0100, Peter Zijlstra wrote:
> By changing futex_lock_pi() to use rt_mutex_*_proxy_lock() we arrive
> at a point where all wait_list modifications are done under both
> hb->lock and wait_lock.
> 
> This closes the obvious interleave pattern between futex_lock_pi() and
> futex_unlock_pi(), but not entirely so. See below:
> 
> Before:
> 
> futex_lock_pi()   futex_unlock_pi()
>   unlock hb->lock
> 
> lock hb->lock
> unlock hb->lock
> 
> lock rt_mutex->wait_lock
> unlock rt_mutex_wait_lock
>   -EAGAIN
> 
>   lock rt_mutex->wait_lock
>   list_add
>   unlock rt_mutex->wait_lock
> 
>   schedule()
> 
>   lock rt_mutex->wait_lock
>   list_del
>   unlock rt_mutex->wait_lock
> 
> 
>   -EAGAIN
> 
>   lock hb->lock
> 
> 
> After:
> 
> futex_lock_pi()   futex_unlock_pi()
> 
>   lock hb->lock
>   lock rt_mutex->wait_lock
>   list_add
>   unlock rt_mutex->wait_lock
>   unlock hb->lock
> 
>   schedule()
> lock hb->lock
> unlock hb->lock
>   lock hb->lock
>   lock rt_mutex->wait_lock
>   list_del
>   unlock rt_mutex->wait_lock
> 
> lock rt_mutex->wait_lock
> unlock rt_mutex_wait_lock

Underscore to dereference:rt_mutex->wait_lock

>   -EAGAIN
> 
>   unlock hb->lock
> 
> 
> It does however solve the earlier starvation/live-lock scenario which
> got introduced with the -EAGAIN since unlike the before scenario;
> where the -EAGAIN happens while futex_unlock_pi() doesn't hold any
> locks; in the after scenario it happens while futex_unlock_pi()

I think you mean futex_lock_pi() here --^
And possibly in the previous reference, although both are true.

> actually holds a lock, and then we can serialize on that lock.
> 
> Signed-off-by: Peter Zijlstra (Intel) 
> ---
>  kernel/futex.c  |   70 
> +++-
>  kernel/locking/rtmutex.c|   13 ---
>  kernel/locking/rtmutex_common.h |1 
>  3 files changed, 48 insertions(+), 36 deletions(-)
> 
> Index: linux-2.6/kernel/futex.c

...

> @@ -2587,6 +2592,7 @@ static int futex_lock_pi(u32 __user *uad

...

> +no_block:
> + /*
>* Fixup the pi_state owner and possibly acquire the lock if we
>* haven't already.
>*/

Deleted a bunch of commentary about the following comment and the code to follow
(which shows up just below this point). Turns out it isn't wrong... it's just
really complex. This snippet used to be self contained within the first if
block, and now the connection to the comment is less direct. I didn't come up
with a better way to say it though so just noting this here in case you or
someone else has a better idea.


/*
 * If fixup_owner() faulted and was unable to handle the fault, unlock
 * it and return the fault to userspace.
 */
if (ret && (rt_mutex_owner(_state->pi_mutex) == current)) {
pi_state = q.pi_state;
get_pi_state(pi_state);
}

/* Unqueue and drop the lock */
unqueue_me_pi();

if (pi_state) {
rt_mutex_futex_unlock(_state->pi_mutex);
put_pi_state(pi_state);
}

-- 
Darren Hart
VMware Open Source Technology Center


[PATCH v2 5/5] perf tools: Refactor the code to strip command name with {l,r}trim()

2017-04-07 Thread Taeung Song
After reading command name from /proc//status,
use ltrim() and rtrim() to strip command name, not using
just while loop, isspace() and etc.

Cc: David Ahern 
Cc: Don Zickus 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Signed-off-by: Taeung Song 
---
 tools/perf/util/event.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 76b9c6b..8255a26 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -106,7 +106,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, 
size_t len,
int fd;
size_t size = 0;
ssize_t n;
-   char *nl, *name, *tgids, *ppids;
+   char *name, *tgids, *ppids;
 
*tgid = -1;
*ppid = -1;
@@ -134,14 +134,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, 
size_t len,
 
if (name) {
name += 5;  /* strlen("Name:") */
-
-   while (*name && isspace(*name))
-   ++name;
-
-   nl = strchr(name, '\n');
-   if (nl)
-   *nl = '\0';
-
+   name = rtrim(ltrim(name));
size = strlen(name);
if (size >= len)
size = len - 1;
-- 
2.7.4



[PATCH v2 5/5] perf tools: Refactor the code to strip command name with {l,r}trim()

2017-04-07 Thread Taeung Song
After reading command name from /proc//status,
use ltrim() and rtrim() to strip command name, not using
just while loop, isspace() and etc.

Cc: David Ahern 
Cc: Don Zickus 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Signed-off-by: Taeung Song 
---
 tools/perf/util/event.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 76b9c6b..8255a26 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -106,7 +106,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, 
size_t len,
int fd;
size_t size = 0;
ssize_t n;
-   char *nl, *name, *tgids, *ppids;
+   char *name, *tgids, *ppids;
 
*tgid = -1;
*ppid = -1;
@@ -134,14 +134,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, 
size_t len,
 
if (name) {
name += 5;  /* strlen("Name:") */
-
-   while (*name && isspace(*name))
-   ++name;
-
-   nl = strchr(name, '\n');
-   if (nl)
-   *nl = '\0';
-
+   name = rtrim(ltrim(name));
size = strlen(name);
if (size >= len)
size = len - 1;
-- 
2.7.4



[PATCH v2 4/5] perf pmu: Refactor wordwrap() with ltrim()

2017-04-07 Thread Taeung Song
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Signed-off-by: Taeung Song 
---
 tools/perf/util/pmu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 362051e..11c7525 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1148,8 +1148,7 @@ static void wordwrap(char *s, int start, int max, int 
corr)
break;
s += wlen;
column += n;
-   while (isspace(*s))
-   s++;
+   s = ltrim(s);
}
 }
 
-- 
2.7.4



[PATCH v2 4/5] perf pmu: Refactor wordwrap() with ltrim()

2017-04-07 Thread Taeung Song
Cc: Andi Kleen 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Signed-off-by: Taeung Song 
---
 tools/perf/util/pmu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 362051e..11c7525 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1148,8 +1148,7 @@ static void wordwrap(char *s, int start, int max, int 
corr)
break;
s += wlen;
column += n;
-   while (isspace(*s))
-   s++;
+   s = ltrim(s);
}
 }
 
-- 
2.7.4



  1   2   3   4   5   6   7   8   9   10   >