Re: mount.nfs: Protocol error after upgrade to linux/master

2019-03-15 Thread Kees Cook
On Fri, Mar 15, 2019 at 10:24 PM Kees Cook  wrote:
>
> On Fri, Mar 15, 2019 at 4:54 PM Jakub Kicinski
>  wrote:
> >
> > On Fri, 15 Mar 2019 12:01:05 -0700, Jakub Kicinski wrote:
> > > On Fri, 15 Mar 2019 11:05:55 -0700, Jakub Kicinski wrote:
> > > > Hi,
> > > >
> > > > I just upgraded from:
> > > >
> > > > commit a3b1933d34d5bb26d7503752e3528315a9e28339 (net)
> > > > Merge: c6873d18cb4a 24319258660a
> > > > Author: David S. Miller 
> > > > Date:   Mon Mar 11 16:22:49 2019 -0700
> > > >
> > > > to
> > > >
> > > > commit 3b319ee220a8795406852a897299dbdfc1b09911
> > > > Merge: 9352ca585b2a b6e88119f1ed
> > > > Author: Linus Torvalds 
> > > > Date:   Thu Mar 14 10:48:14 2019 -0700
> > > >
> > > > and I'm seeing:
> > > >
> > > > # mount /home/
> > > > mount.nfs: Protocol error
> > > >
> > > > No errors in dmesg, please let me know if it's a known problem or what
> > > > other info could be of use.
> > >
> > > Hm.. I tried to bisect but reverting to that commit doesn't help.
> > >
> > > Looks like the server responds with:
> > >
> > >   ICMP parameter problem - octet 22, length 80
> > >
> > > pointing at some IP options (type 134)...
> >
> > Okay, figured it out, it's the commit 13e735c0e953 ("LSM: Introduce
> > CONFIG_LSM") and all the related changes in security/
> >
> > I did olddefconfig and it changed my security module from apparmor to
> > smack silently.  smack must be slapping those IP options on by default.
> >
> > Pretty awful user experience, and a non-zero chance that users who
> > upgrade their kernels will miss this and end up with the wrong security
> > module...
>
> I wonder if we can add some kind of logic to Kconfig to retain the old
> CONFIG_DEFAULT_SECURITY and include it as the first legacy-major LSM
> listed in CONFIG_LSM?
>
> Like, but the old selector back in, but mark is as "soon to be
> entirely replaced with CONFIG_LSM" and then make CONFIG_LSM's default
> be 
> "yama,loadpin,safesetid,integrity,$(CONFIG_DEFAULT_SECURITY),selinux,smack,tomoyo,apparmor"
> ? Duplicates are ignored...

This would initialize a default order from the earlier Kconfig items:

diff --git a/security/Kconfig b/security/Kconfig
index 1d6463fb1450..e3813b5c6824 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -239,8 +239,40 @@ source "security/safesetid/Kconfig"

 source "security/integrity/Kconfig"

+choice
+   prompt "First legacy-major LSM to be initialized"
+   default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX
+   default DEFAULT_SECURITY_SMACK if SECURITY_SMACK
+   default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO
+   default DEFAULT_SECURITY_APPARMOR if SECURITY_APPARMOR
+   default DEFAULT_SECURITY_DAC
+
+   help
+ Select the legacy-major security module that will be initialize
+ first. Overridden by non-default CONFIG_LSM.
+
+   config DEFAULT_SECURITY_SELINUX
+   bool "SELinux" if SECURITY_SELINUX=y
+
+   config DEFAULT_SECURITY_SMACK
+   bool "Simplified Mandatory Access Control" if SECURITY_SMACK=y
+
+   config DEFAULT_SECURITY_TOMOYO
+   bool "TOMOYO" if SECURITY_TOMOYO=y
+
+   config DEFAULT_SECURITY_APPARMOR
+   bool "AppArmor" if SECURITY_APPARMOR=y
+
+   config DEFAULT_SECURITY_DAC
+   bool "Unix Discretionary Access Controls"
+
+endchoice
+
 config LSM
string "Ordered list of enabled LSMs"
+   default
"yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor" if
DEFAULT_SECURITY_SMACK
+   default
"yama,loadpin,safesetid,integrity,tomoyo,selinux,smack,apparmor" if
DEFAULT_SECURITY_TOMOYO
+   default
"yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo" if
DEFAULT_SECURITY_APPARMOR
default "yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor"
help
  A comma-separated list of LSMs, in initialization order.

(I don't see a way to include an earlier config string in a new
default.) Thoughts?

-- 
Kees Cook


Re: mount.nfs: Protocol error after upgrade to linux/master

2019-03-15 Thread Kees Cook
On Fri, Mar 15, 2019 at 4:54 PM Jakub Kicinski
 wrote:
>
> On Fri, 15 Mar 2019 12:01:05 -0700, Jakub Kicinski wrote:
> > On Fri, 15 Mar 2019 11:05:55 -0700, Jakub Kicinski wrote:
> > > Hi,
> > >
> > > I just upgraded from:
> > >
> > > commit a3b1933d34d5bb26d7503752e3528315a9e28339 (net)
> > > Merge: c6873d18cb4a 24319258660a
> > > Author: David S. Miller 
> > > Date:   Mon Mar 11 16:22:49 2019 -0700
> > >
> > > to
> > >
> > > commit 3b319ee220a8795406852a897299dbdfc1b09911
> > > Merge: 9352ca585b2a b6e88119f1ed
> > > Author: Linus Torvalds 
> > > Date:   Thu Mar 14 10:48:14 2019 -0700
> > >
> > > and I'm seeing:
> > >
> > > # mount /home/
> > > mount.nfs: Protocol error
> > >
> > > No errors in dmesg, please let me know if it's a known problem or what
> > > other info could be of use.
> >
> > Hm.. I tried to bisect but reverting to that commit doesn't help.
> >
> > Looks like the server responds with:
> >
> >   ICMP parameter problem - octet 22, length 80
> >
> > pointing at some IP options (type 134)...
>
> Okay, figured it out, it's the commit 13e735c0e953 ("LSM: Introduce
> CONFIG_LSM") and all the related changes in security/
>
> I did olddefconfig and it changed my security module from apparmor to
> smack silently.  smack must be slapping those IP options on by default.
>
> Pretty awful user experience, and a non-zero chance that users who
> upgrade their kernels will miss this and end up with the wrong security
> module...

I wonder if we can add some kind of logic to Kconfig to retain the old
CONFIG_DEFAULT_SECURITY and include it as the first legacy-major LSM
listed in CONFIG_LSM?

Like, but the old selector back in, but mark is as "soon to be
entirely replaced with CONFIG_LSM" and then make CONFIG_LSM's default
be 
"yama,loadpin,safesetid,integrity,$(CONFIG_DEFAULT_SECURITY),selinux,smack,tomoyo,apparmor"
? Duplicates are ignored...

-- 
Kees Cook


[PATCH 3/4] PM / core: Introduce ASYNC_RESUME_FUNC() helper macro

2019-03-15 Thread Yangtao Li
The async_resume_noirq, async_resume_early, async_resume functions
are basically the same. As we have seen:

static void async_xxx(void *data, async_cookie_t cookie)
{
struct device *dev = (struct device *)data;
int error;

error = device_xxx(dev, pm_transition, true);
if (error)
pm_dev_err(dev, pm_transition, " async", error);
put_device(dev);
}

The ASYNC_RESUME_FUNC() helper macro can decrease code duplication.

Signed-off-by: Yangtao Li 
---
 drivers/base/power/main.c | 46 +--
 1 file changed, 15 insertions(+), 31 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 6026bda5e787..d512bee9d9ca 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -728,18 +728,21 @@ static int __func(struct device *dev) 
\
return __device_ ## __name(dev, pm_transition, false);  \
 }
 
-static void async_resume_noirq(void *data, async_cookie_t cookie)
-{
-   struct device *dev = (struct device *)data;
-   int error;
-
-   error = device_resume_noirq(dev, pm_transition, true);
-   if (error)
-   pm_dev_err(dev, pm_transition, " async", error);
-
-   put_device(dev);
+#define ASYNC_RESUME_FUNC(__func, __name)  \
+static void __func(void *data, async_cookie_t cookie)  \
+{  \
+   struct device *dev = (struct device *)data; \
+   int error;  \
+   \
+   error = device_ ## __name(dev, pm_transition, true);\
+   if (error)  \
+   pm_dev_err(dev, pm_transition, " async", error);\
+   \
+   put_device(dev);\
 }
 
+ASYNC_RESUME_FUNC(async_resume_noirq, resume_noirq);
+
 void dpm_noirq_resume_devices(pm_message_t state)
 {
struct device *dev;
@@ -876,17 +879,7 @@ static int device_resume_early(struct device *dev, 
pm_message_t state, bool asyn
return error;
 }
 
-static void async_resume_early(void *data, async_cookie_t cookie)
-{
-   struct device *dev = (struct device *)data;
-   int error;
-
-   error = device_resume_early(dev, pm_transition, true);
-   if (error)
-   pm_dev_err(dev, pm_transition, " async", error);
-
-   put_device(dev);
-}
+ASYNC_RESUME_FUNC(async_resume_early, resume_early);
 
 /**
  * dpm_resume_early - Execute "early resume" callbacks for all devices.
@@ -1035,16 +1028,7 @@ static int device_resume(struct device *dev, 
pm_message_t state, bool async)
return error;
 }
 
-static void async_resume(void *data, async_cookie_t cookie)
-{
-   struct device *dev = (struct device *)data;
-   int error;
-
-   error = device_resume(dev, pm_transition, true);
-   if (error)
-   pm_dev_err(dev, pm_transition, " async", error);
-   put_device(dev);
-}
+ASYNC_RESUME_FUNC(async_resume, resume);
 
 /**
  * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
-- 
2.17.0



[PATCH 4/4] PM / core: Introduce ASYNC_SUSPEND_FUNC() helper macro

2019-03-15 Thread Yangtao Li
The async_suspend_noirq, async_suspend_late, async_suspend functions
are basically the same. As we have seen:

static void async_xxx(void *data, async_cookie_t cookie)
{
struct device *dev = (struct device *)data;
int error;

error = __device_xxx(dev, pm_transition, true);
if (error) {
dpm_save_failed_dev(dev_name(dev));
pm_dev_err(dev, pm_transition, " async", error);
}

put_device(dev);
}

The ASYNC_SUSPEND_FUNC() helper macro can decrease code duplication.

Signed-off-by: Yangtao Li 
---
 drivers/base/power/main.c | 55 ---
 1 file changed, 16 insertions(+), 39 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index d512bee9d9ca..3882dc5fee9f 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1348,20 +1348,22 @@ static int __device_suspend_noirq(struct device *dev, 
pm_message_t state, bool a
return error;
 }
 
-static void async_suspend_noirq(void *data, async_cookie_t cookie)
-{
-   struct device *dev = (struct device *)data;
-   int error;
-
-   error = __device_suspend_noirq(dev, pm_transition, true);
-   if (error) {
-   dpm_save_failed_dev(dev_name(dev));
-   pm_dev_err(dev, pm_transition, " async", error);
-   }
-
-   put_device(dev);
+#define ASYNC_SUSPEND_FUNC(__func, __name) \
+static void __func(void *data, async_cookie_t cookie)  \
+{  \
+   struct device *dev = (struct device *)data; \
+   int error;  \
+   \
+   error = __device_ ## __name(dev, pm_transition, true);  \
+   if (error) {\
+   dpm_save_failed_dev(dev_name(dev)); \
+   pm_dev_err(dev, pm_transition, " async", error);\
+   }   \
+   \
+   put_device(dev);\
 }
 
+ASYNC_SUSPEND_FUNC(async_suspend_noirq, suspend_noirq);
 DEVICE_SUSPEND_FUNC(device_suspend_noirq, suspend_noirq);
 
 void dpm_noirq_begin(void)
@@ -1542,19 +1544,7 @@ static int __device_suspend_late(struct device *dev, 
pm_message_t state, bool as
return error;
 }
 
-static void async_suspend_late(void *data, async_cookie_t cookie)
-{
-   struct device *dev = (struct device *)data;
-   int error;
-
-   error = __device_suspend_late(dev, pm_transition, true);
-   if (error) {
-   dpm_save_failed_dev(dev_name(dev));
-   pm_dev_err(dev, pm_transition, " async", error);
-   }
-   put_device(dev);
-}
-
+ASYNC_SUSPEND_FUNC(async_suspend_late, suspend_late);
 DEVICE_SUSPEND_FUNC(device_suspend_late, suspend_late);
 
 /**
@@ -1796,20 +1786,7 @@ static int __device_suspend(struct device *dev, 
pm_message_t state, bool async)
return error;
 }
 
-static void async_suspend(void *data, async_cookie_t cookie)
-{
-   struct device *dev = (struct device *)data;
-   int error;
-
-   error = __device_suspend(dev, pm_transition, true);
-   if (error) {
-   dpm_save_failed_dev(dev_name(dev));
-   pm_dev_err(dev, pm_transition, " async", error);
-   }
-
-   put_device(dev);
-}
-
+ASYNC_SUSPEND_FUNC(async_suspend, suspend);
 DEVICE_SUSPEND_FUNC(device_suspend, suspend);
 
 /**
-- 
2.17.0



[PATCH 1/4] PM / core: Introduce dpm_async_fn() helper

2019-03-15 Thread Yangtao Li
When we want to execute device pm functions asynchronously, we'll
do the following for the device:

  1) reinit_completion(>power.completion);
  2) Check if the device enables asynchronous suspend.
  3) If necessary, execute the corresponding function asynchronously.

There are a lot of such repeated operations here, in fact we can avoid
this. So introduce dpm_async_fn() to have better code readability and
reuse.

And use this function to do some cleanup.

Signed-off-by: Yangtao Li 
---
 drivers/base/power/main.c | 62 +++
 1 file changed, 23 insertions(+), 39 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index eddb54057ed6..cb44bb6b2b66 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -706,6 +706,19 @@ static bool is_async(struct device *dev)
&& !pm_trace_is_enabled();
 }
 
+static bool dpm_async_fn(struct device *dev, async_func_t func)
+{
+   reinit_completion(>power.completion);
+
+   if (is_async(dev)) {
+   get_device(dev);
+   async_schedule(func, dev);
+   return true;
+   }
+
+   return false;
+}
+
 static void async_resume_noirq(void *data, async_cookie_t cookie)
 {
struct device *dev = (struct device *)data;
@@ -732,13 +745,8 @@ void dpm_noirq_resume_devices(pm_message_t state)
 * in case the starting of async threads is
 * delayed by non-async resuming devices.
 */
-   list_for_each_entry(dev, _noirq_list, power.entry) {
-   reinit_completion(>power.completion);
-   if (is_async(dev)) {
-   get_device(dev);
-   async_schedule_dev(async_resume_noirq, dev);
-   }
-   }
+   list_for_each_entry(dev, _noirq_list, power.entry)
+   dpm_async_fn(dev, async_resume_noirq);
 
while (!list_empty(_noirq_list)) {
dev = to_device(dpm_noirq_list.next);
@@ -889,13 +897,8 @@ void dpm_resume_early(pm_message_t state)
 * in case the starting of async threads is
 * delayed by non-async resuming devices.
 */
-   list_for_each_entry(dev, _late_early_list, power.entry) {
-   reinit_completion(>power.completion);
-   if (is_async(dev)) {
-   get_device(dev);
-   async_schedule_dev(async_resume_early, dev);
-   }
-   }
+   list_for_each_entry(dev, _late_early_list, power.entry)
+   dpm_async_fn(dev, async_resume_early);
 
while (!list_empty(_late_early_list)) {
dev = to_device(dpm_late_early_list.next);
@@ -1053,13 +1056,8 @@ void dpm_resume(pm_message_t state)
pm_transition = state;
async_error = 0;
 
-   list_for_each_entry(dev, _suspended_list, power.entry) {
-   reinit_completion(>power.completion);
-   if (is_async(dev)) {
-   get_device(dev);
-   async_schedule_dev(async_resume, dev);
-   }
-   }
+   list_for_each_entry(dev, _suspended_list, power.entry)
+   dpm_async_fn(dev, async_resume);
 
while (!list_empty(_suspended_list)) {
dev = to_device(dpm_suspended_list.next);
@@ -1373,13 +1371,9 @@ static void async_suspend_noirq(void *data, 
async_cookie_t cookie)
 
 static int device_suspend_noirq(struct device *dev)
 {
-   reinit_completion(>power.completion);
-
-   if (is_async(dev)) {
-   get_device(dev);
-   async_schedule_dev(async_suspend_noirq, dev);
+   if (dpm_async_fn(dev, async_suspend_noirq))
return 0;
-   }
+
return __device_suspend_noirq(dev, pm_transition, false);
 }
 
@@ -1576,13 +1570,8 @@ static void async_suspend_late(void *data, 
async_cookie_t cookie)
 
 static int device_suspend_late(struct device *dev)
 {
-   reinit_completion(>power.completion);
-
-   if (is_async(dev)) {
-   get_device(dev);
-   async_schedule_dev(async_suspend_late, dev);
+   if (dpm_async_fn(dev, async_suspend_late))
return 0;
-   }
 
return __device_suspend_late(dev, pm_transition, false);
 }
@@ -1842,13 +1831,8 @@ static void async_suspend(void *data, async_cookie_t 
cookie)
 
 static int device_suspend(struct device *dev)
 {
-   reinit_completion(>power.completion);
-
-   if (is_async(dev)) {
-   get_device(dev);
-   async_schedule_dev(async_suspend, dev);
+   if (dpm_async_fn(dev, async_suspend))
return 0;
-   }
 
return __device_suspend(dev, pm_transition, false);
 }
-- 
2.17.0



[PATCH 2/4] PM / core: Introduce DEVICE_SUSPEND_FUNC() helper macro

2019-03-15 Thread Yangtao Li
The devices_suspend_noirq, device_suspend_late, device_suspen functions
are basically the same. As we have seen:

static int device_xxx(struct device *dev)
{
   if (dpm_async_fn(dev, async_xxx))
   return 0;

   return __device_xxx(dev, pm_transition, false);
}

The DEVICE_SUSPEND_FUNC() helper macro can decrease
code duplication.

Signed-off-by: Yangtao Li 
---
 drivers/base/power/main.c | 33 -
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index cb44bb6b2b66..6026bda5e787 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -719,6 +719,15 @@ static bool dpm_async_fn(struct device *dev, async_func_t 
func)
return false;
 }
 
+#define DEVICE_SUSPEND_FUNC(__func, __name)\
+static int __func(struct device *dev)  \
+{  \
+   if (dpm_async_fn(dev, async_ ## __name))\
+   return 0;   \
+   \
+   return __device_ ## __name(dev, pm_transition, false);  \
+}
+
 static void async_resume_noirq(void *data, async_cookie_t cookie)
 {
struct device *dev = (struct device *)data;
@@ -1369,13 +1378,7 @@ static void async_suspend_noirq(void *data, 
async_cookie_t cookie)
put_device(dev);
 }
 
-static int device_suspend_noirq(struct device *dev)
-{
-   if (dpm_async_fn(dev, async_suspend_noirq))
-   return 0;
-
-   return __device_suspend_noirq(dev, pm_transition, false);
-}
+DEVICE_SUSPEND_FUNC(device_suspend_noirq, suspend_noirq);
 
 void dpm_noirq_begin(void)
 {
@@ -1568,13 +1571,7 @@ static void async_suspend_late(void *data, 
async_cookie_t cookie)
put_device(dev);
 }
 
-static int device_suspend_late(struct device *dev)
-{
-   if (dpm_async_fn(dev, async_suspend_late))
-   return 0;
-
-   return __device_suspend_late(dev, pm_transition, false);
-}
+DEVICE_SUSPEND_FUNC(device_suspend_late, suspend_late);
 
 /**
  * dpm_suspend_late - Execute "late suspend" callbacks for all devices.
@@ -1829,13 +1826,7 @@ static void async_suspend(void *data, async_cookie_t 
cookie)
put_device(dev);
 }
 
-static int device_suspend(struct device *dev)
-{
-   if (dpm_async_fn(dev, async_suspend))
-   return 0;
-
-   return __device_suspend(dev, pm_transition, false);
-}
+DEVICE_SUSPEND_FUNC(device_suspend, suspend);
 
 /**
  * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices.
-- 
2.17.0



[PATCH 0/4] PM / core: Introduce some helper for better Code reuse

2019-03-15 Thread Yangtao Li
This patch set introduces some functions and macros that help reduce
code duplication.

Yangtao Li (4):
  PM / core: Introduce dpm_async_fn() helper
  PM / core: Introduce DEVICE_SUSPEND_FUNC() helper macro
  PM / core: Introduce ASYNC_RESUME_FUNC() helper macro
  PM / core: Introduce ASYNC_SUSPEND_FUNC() helper macro

 drivers/base/power/main.c | 182 --
 1 file changed, 59 insertions(+), 123 deletions(-)

-- 
2.17.0



[PATCH v2 0/5] lib/sort & lib/list_sort: faster and smaller

2019-03-15 Thread George Spelvin
v1->v2: Various spelling, naming and code style cleanups.
Generally positive and no negative responses to the
goals and algorithms used.

I'm running these patches, with CONFIG_TEST_SORT and
CONFIG_TEST_LIST_SORT, on the machine I'm sending this from.
I have tweaked the comments further, but I have verified
the compiled object code is identical to a snapshot I took
when I rebooted.

As far as I'm concerned, this is ready to be merged.
As there is no owner in MAINTAINERS, I was thinking of
sending it via AKPM, like the recent lib/lzo changes.
Andrew, is that okay with you?

Because CONFIG_RETPOLINE has made indirect calls much more expensive,
I thought I'd try to reduce the number made by the library sort
functions.

The first three patches apply to lib/sort.c.

Patch #1 is a simple optimization.  The built-in swap has special cases
for aligned 4- and 8-byte objects.  But those are almost never used;
most calls to sort() work on larger structures, which fall back to the
byte-at-a-time loop.  This generalizes them to aligned *multiples* of 4
and 8 bytes.  (If nothing else, it saves an awful lot of energy by not
thrashing the store buffers as much.)

Patch #2 grabs a juicy piece of low-hanging fruit.  I agree that
nice simple solid heapsort is preferable to more complex algorithms
(sorry, Andrey), but it's possible to implement heapsort with far fewer
comparisons (50% asymptotically, 25-40% reduction for realistic sizes)
than the way it's been done up to now.  And with some care, the code
ends up smaller, as well.  This is the "big win" patch.

Patch #3 adds the same sort of indirect call bypass that has been added
to the net code of late.  The great majority of the callers use the
builtin swap functions, so replace the indirect call to sort_func with a
(highly preditable) series of if() statements.  Rather surprisingly,
this decreased code size, as the swap functions were inlined and their
prologue & epilogue code eliminated.

lib/list_sort.c is a bit trickier, as merge sort is already close to
optimal, and we don't want to introduce triumphs of theory over
practicality like the Ford-Johnson merge-insertion sort.

Patch #4, without changing the algorithm, chops 32% off the code size and
removes the part[MAX_LIST_LENGTH+1] pointer array (and the corresponding
upper limit on efficiently sortable input size).

Patch #5 improves the algorithm.  The previous code is already optimal
for power-of-two (or slightly smaller) size inputs, but when the input
size is just over a power of 2, there's a very unbalanced final merge.

There are, in the literature, several algorithms which solve this, but
they all depend on the "breadth-first" merge order which was replaced
by commit 835cc0c8477f with a more cache-friendly "depth-first" order.
Some hard thinking came up with a depth-first algorithm which defers
merges as little as possible while avoiding bad merges.  This saves
0.2*n compares, averaged over all sizes.

The code size increase is minimal (64 bytes on x86-64, reducing the net
savings to 26%), but the comments expanded significantly to document
the clever algorithm.


TESTING NOTES: I have some ugly user-space benchmarking code
which I used for testing before moving this code into the kernel.
Shout if you want a copy.

I'm running this code right now, with CONFIG_TEST_SORT and
CONFIG_TEST_LIST_SORT, but I confess I haven't rebooted since
the last round of minor edits to quell checkpatch.  I figure there
will be at least one round of comments and final testing.

George Spelvin (5):
  lib/sort: Make swap functions more generic
  lib/sort: Use more efficient bottom-up heapsort variant
  lib/sort: Avoid indirect calls to built-in swap
  lib/list_sort: Simplify and remove MAX_LIST_LENGTH_BITS
  lib/list_sort: Optimize number of calls to comparison function

 include/linux/list_sort.h |   1 +
 lib/list_sort.c   | 244 +-
 lib/sort.c| 266 +-
 3 files changed, 387 insertions(+), 124 deletions(-)

-- 
2.20.1



[PATCH v4 12/12] dts: hi3660: Add support for usb on Hikey960

2019-03-15 Thread Yu Chen
This patch adds support for usb on Hikey960.

Cc: Chunfeng Yun 
Cc: Wei Xu 
Cc: Rob Herring 
Cc: Mark Rutland 
Cc: linux-arm-ker...@lists.infradead.org
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v2:
* Remove device_type property.
* Add property "usb-role-switch".
v3:
* Make node "usb_phy" a subnode of usb3_otg_bc register.
* Remove property "typec-vbus-enable-val" of hisi_hikey_usb.
v4:
* Remove property "hisilicon,usb3-otg-bc-syscon" of usb-phy.
---
---
 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 53 
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 74 +++
 2 files changed, 127 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts 
b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
index e035cf195b19..d4e11c56b250 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
model = "HiKey960";
@@ -196,6 +197,26 @@
method = "smc";
};
};
+
+   hisi_hikey_usb: hisi_hikey_usb {
+   compatible = "hisilicon,hikey960_usb";
+   typec-vbus-gpios = < 2 GPIO_ACTIVE_HIGH>;
+   otg-switch-gpios = < 6 GPIO_ACTIVE_HIGH>;
+   hub-vdd33-en-gpios = < 6 GPIO_ACTIVE_HIGH>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_pmx_func>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   hikey_usb_ep: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_role_switch_notify>;
+   };
+   };
+   };
+
 };
 
 /*
@@ -526,6 +547,38 @@
  {
status = "okay";
 
+   rt1711h: rt1711h@4e {
+   compatible = "richtek,rt1711h";
+   reg = <0x4e>;
+   status = "ok";
+   interrupt-parent = <>;
+   interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_cfg_func>;
+
+   usb_con: connector {
+   compatible = "usb-c-connector";
+   label = "USB-C";
+   data-role = "dual";
+   power-role = "dual";
+   try-power-role = "sink";
+   source-pdos = ;
+   sink-pdos = ;
+   op-sink-microwatt = <1000>;
+   };
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   rt1711h_ep: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <_role_switch>;
+   };
+   };
+   };
+
adv7533: adv7533@39 {
status = "ok";
compatible = "adi,adv7533";
diff --git a/arch/arm64/boot/dts/hisilicon/hi3660.dtsi 
b/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
index 2f19e0e5b7cf..77f7a191f0fd 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
@@ -355,6 +355,12 @@
#clock-cells = <1>;
};
 
+   pmctrl: pmctrl@fff31000 {
+   compatible = "hisilicon,hi3660-pmctrl", "syscon";
+   reg = <0x0 0xfff31000 0x0 0x1000>;
+   #clock-cells = <1>;
+   };
+
pmuctrl: crg_ctrl@fff34000 {
compatible = "hisilicon,hi3660-pmuctrl", "syscon";
reg = <0x0 0xfff34000 0x0 0x1000>;
@@ -1134,5 +1140,73 @@
};
};
};
+
+   usb3_otg_bc: usb3_otg_bc@ff20 {
+   compatible = "syscon", "simple-mfd";
+   reg = <0x0 0xff20 0x0 0x1000>;
+
+   usb_phy: usb-phy {
+   compatible = "hisilicon,hi3660-usb-phy";
+   #phy-cells = <0>;
+   hisilicon,pericrg-syscon = <_ctrl>;
+   hisilicon,pctrl-syscon = <>;
+   hisilicon,usb3-otg-bc-syscon = <_otg_bc>;
+   hisilicon,eye-diagram-param = <0x22466e4>;
+   };
+   };
+
+   usb3: hisi_dwc3 {
+   compatible = "hisilicon,hi3660-dwc3";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   clocks = <_ctrl HI3660_CLK_ABB_USB>,
+<_ctrl HI3660_ACLK_GATE_USB3OTG>;
+   clock-names = "clk_usb3phy_ref", 

[PATCH v4 03/12] usb: dwc3: dwc3-of-simple: Add support for dwc3 of Hisilicon Soc Platform

2019-03-15 Thread Yu Chen
This patch adds support for the poweron and shutdown of dwc3 core
on Hisilicon Soc Platform.

Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Cc: John Stultz 
Signed-off-by: Yu Chen 
---
 drivers/usb/dwc3/dwc3-of-simple.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-of-simple.c 
b/drivers/usb/dwc3/dwc3-of-simple.c
index 4c2771c5e727..0ed09d876542 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -98,7 +98,8 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 * Some controllers need to toggle the usb3-otg reset before trying to
 * initialize the PHY, otherwise the PHY times out.
 */
-   if (of_device_is_compatible(np, "rockchip,rk3399-dwc3"))
+   if (of_device_is_compatible(np, "rockchip,rk3399-dwc3") ||
+   of_device_is_compatible(np, "hisilicon,hi3660-dwc3"))
simple->need_reset = true;
 
if (of_device_is_compatible(np, "amlogic,meson-axg-dwc3") ||
@@ -243,6 +244,7 @@ static const struct of_device_id of_dwc3_simple_match[] = {
{ .compatible = "amlogic,meson-axg-dwc3" },
{ .compatible = "amlogic,meson-gxl-dwc3" },
{ .compatible = "allwinner,sun50i-h6-dwc3" },
+   { .compatible = "hisilicon,hi3660-dwc3" },
{ /* Sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
-- 
2.15.0-rc2



[PATCH v4 01/12] dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY

2019-03-15 Thread Yu Chen
This patch adds binding documentation for supporting the hi3660 usb
phy on boards like the HiKey960.

Cc: Rob Herring 
Cc: Mark Rutland 
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v1:
* Fix some format error as suggested by Rob.
v2:
* Change hi3660 usb PHY to hi3660 USB PHY
v3:
* Make device node a subnode of usb3_otg_bc register.
v4:
* Remove "hisilicon,usb3-otg-bc-syscon" property
---
---
 .../devicetree/bindings/phy/phy-hi3660-usb3.txt| 26 ++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt 
b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
new file mode 100644
index ..e88ba7d92dcb
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
@@ -0,0 +1,26 @@
+Hisilicon hi3660 USB PHY
+---
+
+Required properties:
+- compatible: should be "hisilicon,hi3660-usb-phy"
+- #phy-cells: must be 0
+- hisilicon,pericrg-syscon: phandle of syscon used to control phy.
+- hisilicon,pctrl-syscon: phandle of syscon used to control phy.
+- hisilicon,eye-diagram-param: parameter set for phy
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+This is a subnode of usb3_otg_bc register node.
+
+Example:
+   usb3_otg_bc: usb3_otg_bc@ff20 {
+   compatible = "syscon", "simple-mfd";
+   reg = <0x0 0xff20 0x0 0x1000>;
+
+   usb-phy {
+   compatible = "hisilicon,hi3660-usb-phy";
+   #phy-cells = <0>;
+   hisilicon,pericrg-syscon = <_ctrl>;
+   hisilicon,pctrl-syscon = <>;
+   hisilicon,eye-diagram-param = <0x22466e4>;
+   };
+   };
-- 
2.15.0-rc2



[PATCH v2 4/5] lib/list_sort: Simplify and remove MAX_LIST_LENGTH_BITS

2019-03-15 Thread George Spelvin
Rather than a fixed-size array of pending sorted runs, use the ->prev
links to keep track of things.  This reduces stack usage, eliminates
some ugly overflow handling, and reduces the code size.

Also:
* merge() no longer needs to handle NULL inputs, so simplify.
* The same applies to merge_and_restore_back_links(), which is renamed
  to the less ponderous merge_final().  (It's a static helper function,
  so we don't need a super-descriptive name; comments will do.)
* Document the actual return value requirements on the (*cmp)()
  function; some callers are already using this feature.

x86-64 code size 1086 -> 739 bytes (-347)

(Yes, I see checkpatch complaining about no space after comma in
"__attribute__((nonnull(2,3,4,5)))".  Checkpatch is wrong.)

Signed-off-by: George Spelvin 
Acked-by: Andrey Abramov 
Feedback-from: Rasmus Villemoes 
Feedback-from: Andy Shevchenko 
Feedback-from: Geert Uytterhoeven 
---
 include/linux/list_sort.h |   1 +
 lib/list_sort.c   | 169 --
 2 files changed, 109 insertions(+), 61 deletions(-)

diff --git a/include/linux/list_sort.h b/include/linux/list_sort.h
index ba79956e848d..20f178c24e9d 100644
--- a/include/linux/list_sort.h
+++ b/include/linux/list_sort.h
@@ -6,6 +6,7 @@
 
 struct list_head;
 
+__attribute__((nonnull(2,3)))
 void list_sort(void *priv, struct list_head *head,
   int (*cmp)(void *priv, struct list_head *a,
  struct list_head *b));
diff --git a/lib/list_sort.c b/lib/list_sort.c
index 85759928215b..fc807dd60a51 100644
--- a/lib/list_sort.c
+++ b/lib/list_sort.c
@@ -7,33 +7,47 @@
 #include 
 #include 
 
-#define MAX_LIST_LENGTH_BITS 20
+/*
+ * By declaring the compare function with the __pure attribute, we give
+ * the compiler more opportunity to optimize.  Ideally, we'd use this in
+ * the prototype of list_sort(), but that would involve a lot of churn
+ * at all call sites, so just cast the function pointer passed in.
+ */
+typedef int __pure __attribute__((nonnull(2,3))) (*cmp_func)(void *,
+   struct list_head const *, struct list_head const *);
 
 /*
  * Returns a list organized in an intermediate format suited
  * to chaining of merge() calls: null-terminated, no reserved or
  * sentinel head node, "prev" links not maintained.
  */
-static struct list_head *merge(void *priv,
-   int (*cmp)(void *priv, struct list_head *a,
-   struct list_head *b),
+__attribute__((nonnull(2,3,4)))
+static struct list_head *merge(void *priv, cmp_func cmp,
struct list_head *a, struct list_head *b)
 {
-   struct list_head head, *tail = 
+   struct list_head *head, **tail = 
 
-   while (a && b) {
+   for (;;) {
/* if equal, take 'a' -- important for sort stability */
-   if ((*cmp)(priv, a, b) <= 0) {
-   tail->next = a;
+   if (cmp(priv, a, b) <= 0) {
+   *tail = a;
+   tail = >next;
a = a->next;
+   if (!a) {
+   *tail = b;
+   break;
+   }
} else {
-   tail->next = b;
+   *tail = b;
+   tail = >next;
b = b->next;
+   if (!b) {
+   *tail = a;
+   break;
+   }
}
-   tail = tail->next;
}
-   tail->next = a?:b;
-   return head.next;
+   return head;
 }
 
 /*
@@ -43,44 +57,52 @@ static struct list_head *merge(void *priv,
  * prev-link restoration pass, or maintaining the prev links
  * throughout.
  */
-static void merge_and_restore_back_links(void *priv,
-   int (*cmp)(void *priv, struct list_head *a,
-   struct list_head *b),
-   struct list_head *head,
-   struct list_head *a, struct list_head *b)
+__attribute__((nonnull(2,3,4,5)))
+static void merge_final(void *priv, cmp_func cmp, struct list_head *head,
+   struct list_head *a, struct list_head *b)
 {
struct list_head *tail = head;
u8 count = 0;
 
-   while (a && b) {
+   for (;;) {
/* if equal, take 'a' -- important for sort stability */
-   if ((*cmp)(priv, a, b) <= 0) {
+   if (cmp(priv, a, b) <= 0) {
tail->next = a;
a->prev = tail;
+   tail = a;
a = a->next;
+   if (!a)
+   break;
} else {
tail->next = b;
b->prev = tail;
+   tail = b;
 

[PATCH] regulator: as3722: Remove *rdevs[] from struct as3722_regulators

2019-03-15 Thread Axel Lin
Current code is using devm_regulator_register() so it is not necessary
to save as3722_regs->rdevs[id] for clean up.
The *rdevs[] is not used now, remove it.

Signed-off-by: Axel Lin 
---
 drivers/regulator/as3722-regulator.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/regulator/as3722-regulator.c 
b/drivers/regulator/as3722-regulator.c
index 66337e12719b..26f2951c1dac 100644
--- a/drivers/regulator/as3722-regulator.c
+++ b/drivers/regulator/as3722-regulator.c
@@ -81,7 +81,6 @@ struct as3722_regulator_config_data {
 struct as3722_regulators {
struct device *dev;
struct as3722 *as3722;
-   struct regulator_dev *rdevs[AS3722_REGULATOR_ID_MAX];
struct regulator_desc desc[AS3722_REGULATOR_ID_MAX];
struct as3722_regulator_config_data
reg_config_data[AS3722_REGULATOR_ID_MAX];
@@ -929,7 +928,6 @@ static int as3722_regulator_probe(struct platform_device 
*pdev)
return ret;
}
 
-   as3722_regs->rdevs[id] = rdev;
if (reg_config->ext_control) {
ret = regulator_enable_regmap(rdev);
if (ret < 0) {
-- 
2.17.1



[PATCH v2 3/5] lib/sort: Avoid indirect calls to built-in swap

2019-03-15 Thread George Spelvin
Similar to what's being done in the net code, this takes advantage of
the fact that most invocations use only a few common swap functions, and
replaces indirect calls to them with (highly predictable) conditional
branches.  (The downside, of course, is that if you *do* use a custom
swap function, there are a few extra predicted branches on the code path.)

This actually *shrinks* the x86-64 code, because it inlines the various
swap functions inside do_swap, eliding function prologues & epilogues.

x86-64 code size 767 -> 703 bytes (-64)

Signed-off-by: George Spelvin 
Acked-by: Andrey Abramov 
---
 lib/sort.c | 51 ---
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/lib/sort.c b/lib/sort.c
index 0d24d0c5c0fc..50855ea8c262 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -54,10 +54,8 @@ static bool is_aligned(const void *base, size_t size, 
unsigned char align)
  * subtract (since the intervening mov instructions don't alter the flags).
  * Gcc 8.1.0 doesn't have that problem.
  */
-static void swap_words_32(void *a, void *b, int size)
+static void swap_words_32(void *a, void *b, size_t n)
 {
-   size_t n = (unsigned int)size;
-
do {
u32 t = *(u32 *)(a + (n -= 4));
*(u32 *)(a + n) = *(u32 *)(b + n);
@@ -80,10 +78,8 @@ static void swap_words_32(void *a, void *b, int size)
  * but it's possible to have 64-bit loads without 64-bit pointers (e.g.
  * x32 ABI).  Are there any cases the kernel needs to worry about?
  */
-static void swap_words_64(void *a, void *b, int size)
+static void swap_words_64(void *a, void *b, size_t n)
 {
-   size_t n = (unsigned int)size;
-
do {
 #ifdef CONFIG_64BIT
u64 t = *(u64 *)(a + (n -= 8));
@@ -109,10 +105,8 @@ static void swap_words_64(void *a, void *b, int size)
  *
  * This is the fallback if alignment doesn't allow using larger chunks.
  */
-static void swap_bytes(void *a, void *b, int size)
+static void swap_bytes(void *a, void *b, size_t n)
 {
-   size_t n = (unsigned int)size;
-
do {
char t = ((char *)a)[--n];
((char *)a)[n] = ((char *)b)[n];
@@ -120,6 +114,33 @@ static void swap_bytes(void *a, void *b, int size)
} while (n);
 }
 
+typedef void (*swap_func_t)(void *a, void *b, int size);
+
+/*
+ * The values are arbitrary as long as they can't be confused with
+ * a pointer, but small integers make for the smallest compare
+ * instructions.
+ */
+#define SWAP_WORDS_64 (swap_func_t)0
+#define SWAP_WORDS_32 (swap_func_t)1
+#define SWAP_BYTES(swap_func_t)2
+
+/*
+ * The function pointer is last to make tail calls most efficient if the
+ * compiler decides not to inline this function.
+ */
+static void do_swap(void *a, void *b, size_t size, swap_func_t swap_func)
+{
+   if (swap_func == SWAP_WORDS_64)
+   swap_words_64(a, b, size);
+   else if (swap_func == SWAP_WORDS_32)
+   swap_words_32(a, b, size);
+   else if (swap_func == SWAP_BYTES)
+   swap_bytes(a, b, size);
+   else
+   swap_func(a, b, (int)size);
+}
+
 /**
  * parent - given the offset of the child, find the offset of the parent.
  * @i: the offset of the heap element whose parent is sought.  Non-zero.
@@ -157,7 +178,7 @@ static size_t parent(size_t i, unsigned int lsbit, size_t 
size)
  * This function does a heapsort on the given array.  You may provide
  * a swap_func function if you need to do something more than a memory
  * copy (e.g. fix up pointers or auxiliary data), but the built-in swap
- * isn't usually a bottleneck.
+ * avoids a slow retpoline and so is significantly faster.
  *
  * Sorting time is O(n log n) both on average and worst-case. While
  * quicksort is slightly faster on average, it suffers from exploitable
@@ -177,11 +198,11 @@ void sort(void *base, size_t num, size_t size,
 
if (!swap_func) {
if (is_aligned(base, size, 8))
-   swap_func = swap_words_64;
+   swap_func = SWAP_WORDS_64;
else if (is_aligned(base, size, 4))
-   swap_func = swap_words_32;
+   swap_func = SWAP_WORDS_32;
else
-   swap_func = swap_bytes;
+   swap_func = SWAP_BYTES;
}
 
/*
@@ -197,7 +218,7 @@ void sort(void *base, size_t num, size_t size,
if (a)  /* Building heap: sift down --a */
a -= size;
else if (n -= size) /* Sorting: Extract root to --n */
-   swap_func(base, base + n, size);
+   do_swap(base, base + n, size, swap_func);
else/* Sort complete */
break;
 
@@ -224,7 +245,7 @@ void sort(void *base, size_t num, size_t size,
c = b;  /* Where "a" belongs */
while 

[PATCH v2 1/5] lib/sort: Make swap functions more generic

2019-03-15 Thread George Spelvin
Rather than having special-case swap functions for 4- and 8-byte objects,
special-case aligned multiples of 4 or 8 bytes.  This speeds up most
users of sort() by avoiding fallback to the byte copy loop.

Despite what commit ca96ab859ab4 ("lib/sort: Add 64 bit swap function")
claims, very few users of sort() sort pointers (or pointer-sized
objects); most sort structures containing at least two words.
(E.g. drivers/acpi/fan.c:acpi_fan_get_fps() sorts an array of 40-byte
struct acpi_fan_fps.)

The functions also got renamed to reflect the fact that they support
multiple words.  In the great tradition of bikeshedding, the names were
by far the most contentious issue during review of this patch series.

x86-64 code size 872 -> 886 bytes (+14)

Signed-off-by: George Spelvin 
Acked-by: Andrey Abramov 
Feedback-from: Andy Shevchenko 
Feedback-from: Rasmus Villemoes 
Feedback-from: Geert Uytterhoeven 
---
 lib/sort.c | 135 +
 1 file changed, 105 insertions(+), 30 deletions(-)

diff --git a/lib/sort.c b/lib/sort.c
index d6b7a202b0b6..ec79eac85e21 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -11,35 +11,108 @@
 #include 
 #include 
 
-static int alignment_ok(const void *base, int align)
+/**
+ * is_aligned - is this pointer & size okay for word-wide copying?
+ * @base: pointer to data
+ * @size: size of each element
+ * @align: required aignment (typically 4 or 8)
+ *
+ * Returns true if elements can be copied using word loads and stores.
+ * The size must be a multiple of the alignment, and the base address must
+ * be if we do not have CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.
+ *
+ * For some reason, gcc doesn't know to optimize "if (a & mask || b & mask)"
+ * to "if ((a | b) & mask)", so we do that by hand.
+ */
+__attribute_const__ __always_inline
+static bool is_aligned(const void *base, size_t size, unsigned char align)
 {
-   return IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ||
-   ((unsigned long)base & (align - 1)) == 0;
+   unsigned char lsbits = (unsigned char)size;
+
+   (void)base;
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+   lsbits |= (unsigned char)(uintptr_t)base;
+#endif
+   return (lsbits & (align - 1)) == 0;
 }
 
-static void u32_swap(void *a, void *b, int size)
+/**
+ * swap_words_32 - swap two elements in 32-bit chunks
+ * @a, @b: pointers to the elements
+ * @size: element size (must be a multiple of 4)
+ *
+ * Exchange the two objects in memory.  This exploits base+index addressing,
+ * which basically all CPUs have, to minimize loop overhead computations.
+ *
+ * For some reason, on x86 gcc 7.3.0 adds a redundant test of n at the
+ * bottom of the loop, even though the zero flag is stil valid from the
+ * subtract (since the intervening mov instructions don't alter the flags).
+ * Gcc 8.1.0 doesn't have that problem.
+ */
+static void swap_words_32(void *a, void *b, int size)
 {
-   u32 t = *(u32 *)a;
-   *(u32 *)a = *(u32 *)b;
-   *(u32 *)b = t;
-}
-
-static void u64_swap(void *a, void *b, int size)
-{
-   u64 t = *(u64 *)a;
-   *(u64 *)a = *(u64 *)b;
-   *(u64 *)b = t;
-}
-
-static void generic_swap(void *a, void *b, int size)
-{
-   char t;
+   size_t n = (unsigned int)size;
 
do {
-   t = *(char *)a;
-   *(char *)a++ = *(char *)b;
-   *(char *)b++ = t;
-   } while (--size > 0);
+   u32 t = *(u32 *)(a + (n -= 4));
+   *(u32 *)(a + n) = *(u32 *)(b + n);
+   *(u32 *)(b + n) = t;
+   } while (n);
+}
+
+/**
+ * swap_words_64 - swap two elements in 64-bit chunks
+ * @a, @b: pointers to the elements
+ * @size: element size (must be a multiple of 8)
+ *
+ * Exchange the two objects in memory.  This exploits base+index
+ * addressing, which basically all CPUs have, to minimize loop overhead
+ * computations.
+ *
+ * We'd like to use 64-bit loads if possible.  If they're not, emulating
+ * one requires base+index+4 addressing which x86 has but most other
+ * processors do not.  If CONFIG_64BIT, we definitely have 64-bit loads,
+ * but it's possible to have 64-bit loads without 64-bit pointers (e.g.
+ * x32 ABI).  Are there any cases the kernel needs to worry about?
+ */
+static void swap_words_64(void *a, void *b, int size)
+{
+   size_t n = (unsigned int)size;
+
+   do {
+#ifdef CONFIG_64BIT
+   u64 t = *(u64 *)(a + (n -= 8));
+   *(u64 *)(a + n) = *(u64 *)(b + n);
+   *(u64 *)(b + n) = t;
+#else
+   /* Use two 32-bit transfers to avoid base+index+4 addressing */
+   u32 t = *(u32 *)(a + (n -= 4));
+   *(u32 *)(a + n) = *(u32 *)(b + n);
+   *(u32 *)(b + n) = t;
+
+   t = *(u32 *)(a + (n -= 4));
+   *(u32 *)(a + n) = *(u32 *)(b + n);
+   *(u32 *)(b + n) = t;
+#endif
+   } while (n);
+}
+
+/**
+ * swap_bytes - swap two elements a byte at a time
+ * @a, @b: 

[PATCH v2 2/5] lib/sort: Use more efficient bottom-up heapsort variant

2019-03-15 Thread George Spelvin
This uses fewer comparisons than the previous code (approaching half
as many for large random inputs), but produces identical results;
it actually performs the exact same series of swap operations.

Specifically, it reduces the average number of compares from
2*n*log2(n) - 3*n + o(n)  to  n*log2(n) + 0.37*n + o(n).

This is still 1.63*n worse than glibc qsort() which manages
n*log2(n) - 1.26*n, but at least the leading coefficient is correct.

Standard heapsort, when sifting down, performs two comparisons
per level: one to find the greater child, and a second to see
if the current node should be exchanged with that child.

Bottom-up heapsort observes that it's better to postpone the second
comparison and search for the leaf where -infinity would be sent
to, then search back *up* for the current node's destination.

Since sifting down usually proceeds to the leaf level (that's where
half the nodes are), this does O(1) second comparisons rather
than log2(n).  That saves a lot of (expensive since Spectre)
indirect function calls.

The one time it's worse than the previous code is if there are
large numbers of duplicate keys, when the top-down algorithm is
O(n) and bottom-up is O(n log n).  For distinct keys, it's provably
always better, doing 1.5*n*log2(n) + O(n) in the worst case.

(The code is not significantly more complex.  This patch also
merges the heap-building and -extracting sift-down loops,
resulting in a net code size savings.)

x86-64 code size 885 -> 767 bytes (-118)

(I see the checkpatch complaint about "else if (n -= size)".
The alternative is significantly uglier.)

Signed-off-by: George Spelvin 
Acked-by: Andrey Abramov 
---
 lib/sort.c | 110 ++---
 1 file changed, 80 insertions(+), 30 deletions(-)

diff --git a/lib/sort.c b/lib/sort.c
index ec79eac85e21..0d24d0c5c0fc 100644
--- a/lib/sort.c
+++ b/lib/sort.c
@@ -1,8 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * A fast, small, non-recursive O(nlog n) sort for the Linux kernel
+ * A fast, small, non-recursive O(n log n) sort for the Linux kernel
  *
- * Jan 23 2005  Matt Mackall 
+ * This performs n*log2(n) + 0.37*n + o(n) comparisons on average,
+ * and 1.5*n*log2(n) + O(n) in the (very contrived) worst case.
+ *
+ * Glibc qsort() manages n*log2(n) - 1.26*n for random inputs (1.63*n
+ * better) at the expense of stack usage and much larger code to avoid
+ * quicksort's O(n^2) worst case.
  */
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -15,7 +20,7 @@
  * is_aligned - is this pointer & size okay for word-wide copying?
  * @base: pointer to data
  * @size: size of each element
- * @align: required aignment (typically 4 or 8)
+ * @align: required alignment (typically 4 or 8)
  *
  * Returns true if elements can be copied using word loads and stores.
  * The size must be a multiple of the alignment, and the base address must
@@ -115,6 +120,32 @@ static void swap_bytes(void *a, void *b, int size)
} while (n);
 }
 
+/**
+ * parent - given the offset of the child, find the offset of the parent.
+ * @i: the offset of the heap element whose parent is sought.  Non-zero.
+ * @lsbit: a precomputed 1-bit mask, equal to "size & -size"
+ * @size: size of each element
+ *
+ * In terms of array indexes, the parent of element j = @i/@size is simply
+ * (j-1)/2.  But when working in byte offsets, we can't use implicit
+ * truncation of integer divides.
+ *
+ * Fortunately, we only need one bit of the quotient, not the full divide.
+ * @size has a least significant bit.  That bit will be clear if @i is
+ * an even multiple of @size, and set if it's an odd multiple.
+ *
+ * Logically, we're doing "if (i & lsbit) i -= size;", but since the
+ * branch is unpredictable, it's done with a bit of clever branch-free
+ * code instead.
+ */
+__attribute_const__ __always_inline
+static size_t parent(size_t i, unsigned int lsbit, size_t size)
+{
+   i -= size;
+   i -= size & -(i & lsbit);
+   return i / 2;
+}
+
 /**
  * sort - sort an array of elements
  * @base: pointer to data to sort
@@ -129,17 +160,20 @@ static void swap_bytes(void *a, void *b, int size)
  * isn't usually a bottleneck.
  *
  * Sorting time is O(n log n) both on average and worst-case. While
- * qsort is about 20% faster on average, it suffers from exploitable
+ * quicksort is slightly faster on average, it suffers from exploitable
  * O(n*n) worst-case behavior and extra memory requirements that make
  * it less suitable for kernel use.
  */
-
 void sort(void *base, size_t num, size_t size,
  int (*cmp_func)(const void *, const void *),
  void (*swap_func)(void *, void *, int size))
 {
/* pre-scale counters for performance */
-   int i = (num/2 - 1) * size, n = num * size, c, r;
+   size_t n = num * size, a = (num/2) * size;
+   const unsigned int lsbit = size & -size;  /* Used to find parent */
+
+   if (!a) /* num < 2 || size == 0 */
+   return;
 
if 

[PATCH v2 5/5] lib/list_sort: Optimize number of calls to comparison function

2019-03-15 Thread George Spelvin
CONFIG_RETPOLINE has severely degraded indirect function call
performance, so it's worth putting some effort into reducing
the number of times cmp() is called.

This patch avoids badly unbalanced merges on unlucky input sizes.
It slightly increases the code size, but saves an average of 0.2*n
calls to cmp().

x86-64 code size 739 -> 803 bytes (+64)

Unfortunately, there's not a lot of low-hanging fruit in a merge
sort; it already performs only n*log2(n) - K*n + O(1) compares.
The leading coefficient is already at the theoretical limit (log2(n!)
corresponds to K=1.4427), so we're fighting over the linear term, and
the best mergesort can do is K=1.2645, achieved when n is a power of 2.

The differences between mergesort variants appear when n is *not*
a power of 2; K is a function of the fractional part of log2(n).
Top-down mergesort does best of all, achieving a minimum K=1.2408, and
an average (over all sizes) K=1.248.  However, that requires knowing
the number of entries to be sorted ahead of time, and making a full
pass over the input to count it conflicts with a second performance
goal, which is cache blocking.

Obviously, we have to read the entire list into L1 cache at some point,
and performance is best if it fits.  But if it doesn't fit, each full
pass over the input causes a cache miss per element, which is undesirable.

While textbooks explain bottom-up mergesort as a succession of merging
passes, practical implementations do merging in depth-first order:
as soon as two lists of the same size are available, they are merged.
This allows as many merge passes as possible to fit into L1; only the
final few merges force cache misses.

This cache-friendly depth-first merge order depends on us merging the
beginning of the input as much as possible before we've even seen the
end of the input (and thus know its size).

The simple eager merge pattern causes bad performance when n is just
over a power of 2.  If n=1028, the final merge is between 1024- and
4-element lists, which is wasteful of comparisons.  (This is actually
worse on average than n=1025, because a 1204:1 merge will, on average,
end after 512 compares, while 1024:4 will walk 4/5 of the list.)

Because of this, bottom-up mergesort achieves K < 0.5 for such sizes,
and has an average (over all sizes) K of around 1.  (My experiments
show K=1.01, while theory predicts K=0.965.)

There are "worst-case optimal" variants of bottom-up mergesort which
avoid this bad performance, but the algorithms given in the literature,
such as queue-mergesort and boustrodephonic mergesort, depend on the
breadth-first multi-pass structure that we are trying to avoid.

This implementation is as eager as possible while ensuring that all merge
passes are at worst 1:2 unbalanced.  This achieves the same average
K=1.207 as queue-mergesort, which is 0.2*n better then bottom-up, and
only 0.04*n behind top-down mergesort.

Specifically, defers merging two lists of size 2^k until it is known
that there are 2^k additional inputs following.  This ensures that the
final uneven merges triggered by reaching the end of the input will be
at worst 2:1.  This will avoid cache misses as long as 3*2^k elements
fit into the cache.

(I confess to being more than a little bit proud of how clean this
code turned out.  It took a lot of thinking, but the resultant inner
loop is very simple and efficient.)

Refs:
  Bottom-up Mergesort: A Detailed Analysis
  Wolfgang Panny, Helmut Prodinger
  Algorithmica 14(4):340--354, October 1995
  https://doi.org/10.1007/BF01294131
  https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.6.5260

  The cost distribution of queue-mergesort, optimal mergesorts, and
  power-of-two rules
  Wei-Mei Chen, Hsien-Kuei Hwang, Gen-Huey Chen
  Journal of Algorithms 30(2); Pages 423--448, February 1999
  https://doi.org/10.1006/jagm.1998.0986
  https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.5380

  Queue-Mergesort
  Mordecai J. Golin, Robert Sedgewick
  Information Processing Letters, 48(5):253--259, 10 December 1993
  https://doi.org/10.1016/0020-0190(93)90088-q
  https://sci-hub.tw/10.1016/0020-0190(93)90088-Q

Signed-off-by: George Spelvin 
Acked-by: Andrey Abramov 
Feedback-from: Rasmus Villemoes 
---
 lib/list_sort.c | 115 ++--
 1 file changed, 92 insertions(+), 23 deletions(-)

diff --git a/lib/list_sort.c b/lib/list_sort.c
index fc807dd60a51..623a9158ac8a 100644
--- a/lib/list_sort.c
+++ b/lib/list_sort.c
@@ -113,11 +113,6 @@ static void merge_final(void *priv, cmp_func cmp, struct 
list_head *head,
  * @head: the list to sort
  * @cmp: the elements comparison function
  *
- * This function implements a bottom-up merge sort, which has O(nlog(n))
- * complexity.  We use depth-first order to take advantage of cacheing.
- * (E.g. when we get to the fourth element, we immediately merge the
- * first two 2-element lists.)
- *
  * The comparison funtion @cmp must return > 0 if @a should sort after
  * @b ("@a > 

Re: [PATCH 4/5] lib/list_sort: Simplify and remove MAX_LIST_LENGTH_BITS

2019-03-15 Thread George Spelvin
Indeed, thanks to everyone who commented.  The extra conceptual
complexity and reduced readbility is Just Not Worth It.

v2 (and final, as far as I'm concerned) follows.


[PATCH] PM / core: fix kerneldoc comment for device_pm_wait_for_dev

2019-03-15 Thread Yangtao Li
Rearrange comment to make the comment style consistent, the previous
function parameters are described first.

Signed-off-by: Yangtao Li 
---
 drivers/base/power/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 0cff68bd7b4b..eddb54057ed6 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -2069,8 +2069,8 @@ EXPORT_SYMBOL_GPL(__suspend_report_result);
 
 /**
  * device_pm_wait_for_dev - Wait for suspend/resume of a device to complete.
- * @dev: Device to wait for.
  * @subordinate: Device that needs to wait for @dev.
+ * @dev: Device to wait for.
  */
 int device_pm_wait_for_dev(struct device *subordinate, struct device *dev)
 {
-- 
2.17.0



[PATCH] PM / core: fix kerneldoc comment for dpm_watchdog_handler()

2019-03-15 Thread Yangtao Li
This brings the kernel doc in line with the function signature.

Signed-off-by: Yangtao Li 
---
 drivers/base/power/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index f80d298de3fa..0cff68bd7b4b 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -478,7 +478,7 @@ struct dpm_watchdog {
 
 /**
  * dpm_watchdog_handler - Driver suspend / resume watchdog handler.
- * @data: Watchdog object address.
+ * @t: The timer that pm watchdog depends on.
  *
  * Called when a driver has timed out suspending or resuming.
  * There's not much we can do here to recover so panic() to
-- 
2.17.0



Re: Staging status of speakup

2019-03-15 Thread Greg Kroah-Hartman
On Fri, Mar 15, 2019 at 01:01:27PM +, Okash Khawaja wrote:
> Hi,
> 
> We have made progress on the items in TODO file of speakup driver in
> staging directory and wanted to get some clarity on the remaining
> items. Below is a summary of status of each item along with the quotes
> from TODO file.
> 
> 1. "The first issue has to do with the way speakup communicates
> with serial ports.  Currently, we communicate directly with the hardware
> ports. This however conflicts with the standard serial port drivers,
> which poses various problems. This is also not working for modern
> hardware such as PCI-based serial ports.  Also, there is not a way we
> can communicate with USB devices.  The current serial port handling
> code is in serialio.c in this directory."
> 
> Drivers for all external synths now use TTY to communcate with the
> devices. Only ones still using direct communication with hardware ports
> are internal synths: acntpc, decpc, dtlk and keypc. These are typically
> ISA cards and generally hardware which is difficult to make work. We
> can leave these in staging.

Ok, that's fine.

> 2. "Some places are currently using in_atomic() because speakup
> functions are called in various contexts, and a couple of things can't
> happen in these cases. Pushing work to some worker thread would
> probably help, as was already done for the serial port driving part."
> 
> There aren't any uses of in_atomic anymore. Commit d7500135802c
> "Staging: speakup: Move pasting into a work item" was the last one that
> removed such uses.

Great, let's remove that todo item then.

> 3. "There is a duplication of the selection functions in selections.c.
> These functions should get exported from drivers/char/selection.c
> (clear_selection notably) and used from there instead."
> 
> This is yet to be done. I guess drivers/char/selection.c is now under
> drivers/tty/vt/selection.c.

Yes, someone should update the todo item :)

> 4. "The kobjects may have to move to a more proper place in /sys.The
> discussion on lkml resulted to putting speech synthesizers in the
> "speech" class, and the speakup screen reader itself
> into /sys/class/vtconsole/vtcon0/speakup, the nasty path being handled
> by userland tools."
> 
> Although this makes logical sense, the change will mean changing
> interface with userspace and hence the user space tools. I tried to
> search the lkml discussion but couldn't find it. It will be good to
> know your thoughts on this.

I don't remember, sorry.  I can review the kobject/sysfs usage if you
think it is "good enough" now and see if I find anything objectionable.

> Finally there is an issue where text in output buffer sometimes gets
> garbled on SMP systems, but we can continue working on it after the
> driver is moved out of staging, if that's okay. Basically we need a
> reproducer of this issue.
> 
> In addition to above, there are likely code style issues which will
> need to be fixed.
> 
> We are very keen to get speakup out of staging both, for settling the
> driver but also for getting included in distros which build only the
> mainline drivers.

That's great, I am glad to see this happen.  How about work on the
selection thing and then I can review the kobject stuff in a few weeks,
and then we can start moving things for 5.2?

thanks,

greg k-h


Re: [PATCHv8 00/10] Heterogenous memory node attributes

2019-03-15 Thread Greg Kroah-Hartman
On Fri, Mar 15, 2019 at 11:50:57AM -0600, Keith Busch wrote:
> Hi Greg,
> 
> Just wanted to check with you on how we may proceed with this series.
> The main feature is exporting new sysfs attributes through driver core,
> so I think it makes most sense to go through you unless you'd prefer
> this go through a different route.
> 
> The proposed interface has been pretty stable for a while now, and we've
> received reviews, acks and tests on all patches. Please let me know if
> there is anything else you'd like to see from this series, or if you
> just need more time to get around to this.

I can't do anything with patches until after -rc1 is out, sorry.  Once
that happens I'll work to dig through my pending queue and will review
these then.

thanks,

greg k-h


[PATCH v5 11/11] staging: iio: ad7780: add device tree binding

2019-03-15 Thread Renato Lui Geh

Adds a device tree binding for the ad7780 driver.

Signed-off-by: Renato Lui Geh 
---
.../bindings/iio/adc/adi,ad7780.txt   | 48 +++
1 file changed, 48 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt

diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt 
b/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt
new file mode 100644
index ..440e52555349
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt
@@ -0,0 +1,48 @@
+* Analog Devices AD7170/AD7171/AD7780/AD7781
+
+Data sheets:
+
+- AD7170:
+   * 
https://www.analog.com/media/en/technical-documentation/data-sheets/AD7170.pdf
+- AD7171:
+   * 
https://www.analog.com/media/en/technical-documentation/data-sheets/AD7171.pdf
+- AD7780:
+   * 
https://www.analog.com/media/en/technical-documentation/data-sheets/ad7780.pdf
+- AD7781:
+   * 
https://www.analog.com/media/en/technical-documentation/data-sheets/AD7781.pdf
+
+Required properties:
+
+- compatible: should be one of
+   * "adi,ad7170"
+   * "adi,ad7171"
+   * "adi,ad7780"
+   * "adi,ad7781"
+- reg: spi chip select number for the device
+- vref-supply: the regulator supply for the ADC reference voltage
+
+Optional properties:
+
+- powerdown-gpios:  must be the device tree identifier of the PDRST pin. If
+   specified, it will be asserted during driver probe. As the
+   line is active high, it should be marked GPIO_ACTIVE_HIGH.
+- adi,gain-gpios:   must be the device tree identifier of the GAIN pin. Only 
for
+   the ad778x chips. If specified, it will be asserted during
+   driver probe. As the line is active low, it should be marked
+   GPIO_ACTIVE_LOW.
+- adi,filter-gpios: must be the device tree identifier of the FILTER pin. Only
+   for the ad778x chips. If specified, it will be asserted
+   during driver probe. As the line is active low, it should be
+   marked GPIO_ACTIVE_LOW.
+
+Example:
+
+adc@0 {
+   compatible =  "adi,ad7780";
+   reg = <0>;
+   vref-supply = <_supply>
+
+   powerdown-gpios  = < 12 GPIO_ACTIVE_HIGH>;
+   adi,gain-gpios   = <  5 GPIO_ACTIVE_LOW>;
+   adi,filter-gpios = < 15 GPIO_ACTIVE_LOW>;
+};
--
2.21.0



[PATCH v5 10/11] staging: iio: ad7780: moving ad7780 out of staging

2019-03-15 Thread Renato Lui Geh

Move ad7780 ADC driver out of staging and into the mainline.

The ad7780 is a sigma-delta analog to digital converter. This driver provides
reading voltage values and status bits from both the ad778x and ad717x series.
Its interface also allows writing on the FILTER and GAIN GPIO pins on the
ad778x.

Signed-off-by: Renato Lui Geh 
Signed-off-by: Giuliano Belinassi 
Co-developed-by: Giuliano Belinassi 
---
Changes in v3:
- Changes unrelated to moving the driver to main tree were resent as
  individual patches
Changes in v4:
- Removed line warning it was safe to build the ad7780 driver by
  default

drivers/iio/adc/Kconfig  |  12 +
drivers/iio/adc/Makefile |   1 +
drivers/iio/adc/ad7780.c | 376 +++
drivers/staging/iio/adc/Kconfig  |  13 --
drivers/staging/iio/adc/Makefile |   1 -
drivers/staging/iio/adc/ad7780.c | 376 ---
6 files changed, 389 insertions(+), 390 deletions(-)
create mode 100644 drivers/iio/adc/ad7780.c
delete mode 100644 drivers/staging/iio/adc/ad7780.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index f3cc7a31bce5..6b36a45bd09f 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -108,6 +108,18 @@ config AD7766
  To compile this driver as a module, choose M here: the module will be
  called ad7766.

+config AD7780
+   tristate "Analog Devices AD7780 and similar ADCs driver"
+   depends on SPI
+   depends on GPIOLIB || COMPILE_TEST
+   select AD_SIGMA_DELTA
+   help
+ Say yes here to build support for Analog Devices AD7170, AD7171,
+ AD7780 and AD7781 SPI analog to digital converters (ADC).
+
+ To compile this driver as a module, choose M here: the
+ module will be called ad7780.
+
config AD7791
tristate "Analog Devices AD7791 ADC driver"
depends on SPI
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index ea5031348052..b48852157115 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o
obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o
obj-$(CONFIG_AD7606) += ad7606.o
obj-$(CONFIG_AD7766) += ad7766.o
+obj-$(CONFIG_AD7780) += ad7780.o
obj-$(CONFIG_AD7791) += ad7791.o
obj-$(CONFIG_AD7793) += ad7793.o
obj-$(CONFIG_AD7887) += ad7887.o
diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c
new file mode 100644
index ..23b731a92e32
--- /dev/null
+++ b/drivers/iio/adc/ad7780.c
@@ -0,0 +1,376 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver
+ *
+ * Copyright 2011 Analog Devices Inc.
+ * Copyright 2019 Renato Lui Geh
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define AD7780_RDY BIT(7)
+#define AD7780_FILTER  BIT(6)
+#define AD7780_ERR BIT(5)
+#define AD7780_ID1 BIT(4)
+#define AD7780_ID0 BIT(3)
+#define AD7780_GAINBIT(2)
+
+#define AD7170_ID  0
+#define AD7171_ID  1
+#define AD7780_ID  1
+#define AD7781_ID  0
+
+#define AD7780_ID_MASK (AD7780_ID0 | AD7780_ID1)
+
+#define AD7780_PATTERN_GOOD1
+#define AD7780_PATTERN_MASKGENMASK(1, 0)
+
+#define AD7170_PATTERN_GOOD5
+#define AD7170_PATTERN_MASKGENMASK(2, 0)
+
+#define AD7780_GAIN_MIDPOINT   64
+#define AD7780_FILTER_MIDPOINT 13350
+
+static const unsigned int ad778x_gain[2]  = { 1, 128 };
+static const unsigned int ad778x_odr_avail[2] = { 1, 16700 };
+
+struct ad7780_chip_info {
+   struct iio_chan_specchannel;
+   unsigned intpattern_mask;
+   unsigned intpattern;
+   boolis_ad778x;
+};
+
+struct ad7780_state {
+   const struct ad7780_chip_info   *chip_info;
+   struct regulator*reg;
+   struct gpio_desc*powerdown_gpio;
+   struct gpio_desc*gain_gpio;
+   struct gpio_desc*filter_gpio;
+   unsigned intgain;
+   unsigned intodr;
+   unsigned intint_vref_mv;
+
+   struct ad_sigma_delta sd;
+};
+
+enum ad7780_supported_device_ids {
+   ID_AD7170,
+   ID_AD7171,
+   ID_AD7780,
+   ID_AD7781,
+};
+
+static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd)
+{
+   return container_of(sd, struct ad7780_state, sd);
+}
+
+static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta,
+  enum ad_sigma_delta_mode mode)
+{
+   struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
+   unsigned int val;
+
+   switch (mode) {
+   case AD_SD_MODE_SINGLE:
+   case AD_SD_MODE_CONTINUOUS:
+   val = 1;
+  

[PATCH v5 08/11] staging: iio: ad7780: add SPDX identifier

2019-03-15 Thread Renato Lui Geh

Add SPDX identifier (GPL-2.0) to the AD7780 driver.

Signed-off-by: Renato Lui Geh 
---
drivers/staging/iio/adc/ad7780.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 568c5b4472ff..ff61ffa0da9f 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
/*
 * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver
 *
 * Copyright 2011 Analog Devices Inc.
- *
- * Licensed under the GPL-2.
 */

#include 
--
2.21.0



[PATCH v5 09/11] staging: iio: ad7780: add new copyright holder

2019-03-15 Thread Renato Lui Geh

This patch adds a new copyright holder to the ad7780 driver.

Signed-off-by: Renato Lui Geh 
---
drivers/staging/iio/adc/ad7780.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index ff61ffa0da9f..23b731a92e32 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -3,6 +3,7 @@
 * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver
 *
 * Copyright 2011 Analog Devices Inc.
+ * Copyright 2019 Renato Lui Geh
 */

#include 
--
2.21.0



[PATCH v5 07/11] staging: iio: ad7780: move regulator to after GPIO init

2019-03-15 Thread Renato Lui Geh

To maintain consistency between ad7780_probe and ad7780_remove orders,
regulator initialization has been moved to after GPIO initializations.

Signed-off-by: Renato Lui Geh 
---
drivers/staging/iio/adc/ad7780.c | 20 ++--
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 977b381c1260..568c5b4472ff 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -295,16 +295,6 @@ static int ad7780_probe(struct spi_device *spi)

ad_sd_init(>sd, indio_dev, spi, _sigma_delta_info);

-   st->reg = devm_regulator_get(>dev, "avdd");
-   if (IS_ERR(st->reg))
-   return PTR_ERR(st->reg);
-
-   ret = regulator_enable(st->reg);
-   if (ret) {
-   dev_err(>dev, "Failed to enable specified AVdd supply\n");
-   return ret;
-   }
-
st->chip_info =
_chip_info_tbl[spi_get_device_id(spi)->driver_data];

@@ -321,6 +311,16 @@ static int ad7780_probe(struct spi_device *spi)
if (ret)
goto error_cleanup_buffer_and_trigger;

+   st->reg = devm_regulator_get(>dev, "avdd");
+   if (IS_ERR(st->reg))
+   return PTR_ERR(st->reg);
+
+   ret = regulator_enable(st->reg);
+   if (ret) {
+   dev_err(>dev, "Failed to enable specified AVdd supply\n");
+   return ret;
+   }
+
ret = ad_sd_setup_buffer_and_trigger(indio_dev);
if (ret)
goto error_disable_reg;
--
2.21.0



[PATCH v5 06/11] staging:iio:ad7780: add chip ID values and mask

2019-03-15 Thread Renato Lui Geh

The ad7780 supports both the ad778x and ad717x families. Each chip has
a corresponding ID. This patch provides a mask for extracting ID values
from the status bits and also macros for the correct values for the
ad7170, ad7171, ad7780 and ad7781.

Signed-off-by: Renato Lui Geh 
---
Changes in v5:
- Put AD7780_ID{0,1} back

drivers/staging/iio/adc/ad7780.c | 6 ++
1 file changed, 6 insertions(+)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 94cb60c327d0..977b381c1260 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -30,6 +30,12 @@
#define AD7780_ID0  BIT(3)
#define AD7780_GAIN BIT(2)

+#define AD7170_ID  0
+#define AD7171_ID  1
+#define AD7780_ID  1
+#define AD7781_ID  0
+
+#define AD7780_ID_MASK (AD7780_ID0 | AD7780_ID1)

#define AD7780_PATTERN_GOOD 1
#define AD7780_PATTERN_MASK GENMASK(1, 0)
--
2.21.0



[PATCH v5 05/11] staging: iio: ad7780: set pattern values and masks directly

2019-03-15 Thread Renato Lui Geh

The AD7780 driver contains status pattern bits designed for checking
whether serial transfers have been correctly performed. Pattern macros
were previously generated through bit fields. This patch sets good
pattern values directly and masks through GENMASK.

Signed-off-by: Renato Lui Geh 
---
drivers/staging/iio/adc/ad7780.c | 20 +---
1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 8ff74427d975..94cb60c327d0 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -17,6 +17,7 @@
#include 
#include 
#include 
+#include 

#include 
#include 
@@ -28,16 +29,13 @@
#define AD7780_ID1  BIT(4)
#define AD7780_ID0  BIT(3)
#define AD7780_GAIN BIT(2)
-#define AD7780_PAT1BIT(1)
-#define AD7780_PAT0BIT(0)

-#define AD7780_PATTERN (AD7780_PAT0)
-#define AD7780_PATTERN_MASK(AD7780_PAT0 | AD7780_PAT1)

-#define AD7170_PAT2BIT(2)
+#define AD7780_PATTERN_GOOD1
+#define AD7780_PATTERN_MASKGENMASK(1, 0)

-#define AD7170_PATTERN (AD7780_PAT0 | AD7170_PAT2)
-#define AD7170_PATTERN_MASK(AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2)
+#define AD7170_PATTERN_GOOD5
+#define AD7170_PATTERN_MASKGENMASK(2, 0)

#define AD7780_GAIN_MIDPOINT64
#define AD7780_FILTER_MIDPOINT  13350
@@ -209,25 +207,25 @@ static const struct ad_sigma_delta_info 
ad7780_sigma_delta_info = {
static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
[ID_AD7170] = {
.channel = AD7170_CHANNEL(12, 24),
-   .pattern = AD7170_PATTERN,
+   .pattern = AD7170_PATTERN_GOOD,
.pattern_mask = AD7170_PATTERN_MASK,
.is_ad778x = false,
},
[ID_AD7171] = {
.channel = AD7170_CHANNEL(16, 24),
-   .pattern = AD7170_PATTERN,
+   .pattern = AD7170_PATTERN_GOOD,
.pattern_mask = AD7170_PATTERN_MASK,
.is_ad778x = false,
},
[ID_AD7780] = {
.channel = AD7780_CHANNEL(24, 32),
-   .pattern = AD7780_PATTERN,
+   .pattern = AD7780_PATTERN_GOOD,
.pattern_mask = AD7780_PATTERN_MASK,
.is_ad778x = true,
},
[ID_AD7781] = {
.channel = AD7780_CHANNEL(20, 32),
-   .pattern = AD7780_PATTERN,
+   .pattern = AD7780_PATTERN_GOOD,
.pattern_mask = AD7780_PATTERN_MASK,
.is_ad778x = true,
},
--
2.21.0



[PATCH v5 04/11] staging: iio: ad7780: add filter reading to ad778x

2019-03-15 Thread Renato Lui Geh

This patch adds the new feature of reading the filter odr value for
ad778x chips. This value is stored in the chip's state struct whenever a
read or write call is performed on the chip's driver.

This feature requires sharing SAMP_FREQ. Since the ad717x does not have
a filter option, the driver only shares the relevant info mask for the
ad778x family.

Signed-off-by: Renato Lui Geh 
---
Changes in v4:
- As mentioned in the previous patch, this was originally as part of
  the 'add gain & filter gpio support' patch
Changes in v5:
- Moved ad778x_odr_avail declaration from GPIO patch to this one

drivers/staging/iio/adc/ad7780.c | 18 ++
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index fbcc0d3345ca..8ff74427d975 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -42,7 +42,8 @@
#define AD7780_GAIN_MIDPOINT64
#define AD7780_FILTER_MIDPOINT  13350

-static const unsigned int ad778x_gain[2] = { 1, 128 };
+static const unsigned int ad778x_gain[2]  = { 1, 128 };
+static const unsigned int ad778x_odr_avail[2] = { 1, 16700 };

struct ad7780_chip_info {
struct iio_chan_specchannel;
@@ -58,6 +59,7 @@ struct ad7780_state {
struct gpio_desc*gain_gpio;
struct gpio_desc*filter_gpio;
unsigned intgain;
+   unsigned intodr;
unsigned intint_vref_mv;

struct ad_sigma_delta sd;
@@ -120,6 +122,9 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OFFSET:
*val = -(1 << (chan->scan_type.realbits - 1));
return IIO_VAL_INT;
+   case IIO_CHAN_INFO_SAMP_FREQ:
+   *val = st->odr;
+   return IIO_VAL_INT;
default:
break;
}
@@ -162,6 +167,7 @@ static int ad7780_write_raw(struct iio_dev *indio_dev,
val = 0;
else
val = 1;
+   st->odr = ad778x_odr_avail[val];
gpiod_set_value(st->filter_gpio, val);
break;
default:
@@ -181,8 +187,10 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta 
*sigma_delta,
((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
return -EIO;

-   if (chip_info->is_ad778x)
+   if (chip_info->is_ad778x) {
st->gain = ad778x_gain[raw_sample & AD7780_GAIN];
+   st->odr = ad778x_odr_avail[raw_sample & AD7780_FILTER];
+   }

return 0;
}
@@ -194,17 +202,19 @@ static const struct ad_sigma_delta_info 
ad7780_sigma_delta_info = {
};

#define AD7780_CHANNEL(bits, wordsize) \
+   AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits)
+#define AD7170_CHANNEL(bits, wordsize) \
AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, wordsize - bits)

static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
[ID_AD7170] = {
-   .channel = AD7780_CHANNEL(12, 24),
+   .channel = AD7170_CHANNEL(12, 24),
.pattern = AD7170_PATTERN,
.pattern_mask = AD7170_PATTERN_MASK,
.is_ad778x = false,
},
[ID_AD7171] = {
-   .channel = AD7780_CHANNEL(16, 24),
+   .channel = AD7170_CHANNEL(16, 24),
.pattern = AD7170_PATTERN,
.pattern_mask = AD7170_PATTERN_MASK,
.is_ad778x = false,
--
2.21.0



[PATCH v5 03/11] staging: iio: ad7780: add gain reading to ad778x

2019-03-15 Thread Renato Lui Geh

This patch adds a new functionality of reading gain values from the
ad778x chips. This value is stored in the chip's state struct and is
updated whenever a read or write call is performed on the driver.

Signed-off-by: Renato Lui Geh 
---
drivers/staging/iio/adc/ad7780.c | 5 +
1 file changed, 5 insertions(+)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index f4cd7bc3e02f..fbcc0d3345ca 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -42,6 +42,8 @@
#define AD7780_GAIN_MIDPOINT64
#define AD7780_FILTER_MIDPOINT  13350

+static const unsigned int ad778x_gain[2] = { 1, 128 };
+
struct ad7780_chip_info {
struct iio_chan_specchannel;
unsigned intpattern_mask;
@@ -179,6 +181,9 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta 
*sigma_delta,
((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
return -EIO;

+   if (chip_info->is_ad778x)
+   st->gain = ad778x_gain[raw_sample & AD7780_GAIN];
+
return 0;
}

--
2.21.0



[PATCH v5 02/11] staging: iio: ad7780: add missing switch default case

2019-03-15 Thread Renato Lui Geh

This patch simply adds a missing switch default case in read_raw.

Signed-off-by: Renato Lui Geh 
---
drivers/staging/iio/adc/ad7780.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index 07e5e35c92a3..f4cd7bc3e02f 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -118,6 +118,8 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OFFSET:
*val = -(1 << (chan->scan_type.realbits - 1));
return IIO_VAL_INT;
+   default:
+   break;
}

return -EINVAL;
--
2.21.0



[PATCH v5 01/11] staging: iio: ad7780: add gain & filter gpio support

2019-03-15 Thread Renato Lui Geh

Previously, the AD7780 driver only supported gpio for the 'powerdown'
pin. This commit adds suppport for the 'gain' and 'filter' pin.

Signed-off-by: Renato Lui Geh 
Signed-off-by: Giuliano Belinassi 
Co-developed-by: Giuliano Belinassi 
---
Changes in v3:
- Renamed ad7780_chip_info's filter to odr
- Renamed ad778x_filter to ad778x_odr_avail
- Changed vref variable from unsigned int to unsigned long long to avoid
  overflow
- Removed unnecessary AD_SD_CHANNEL macro
Changes in v4:
- Removed useless macro
- Added default case for switch to suppress warning
- Removed chunks belonging to filter reading, adding these as a
  patch for itself
Changes in v5:
- ad778x_odr_avail moved to filter patch
- Split gain reading to its own patch
- Init GPIOs in a separate function

drivers/staging/iio/adc/ad7780.c | 114 ++-
1 file changed, 96 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index c4a85789c2db..07e5e35c92a3 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -39,6 +39,9 @@
#define AD7170_PATTERN  (AD7780_PAT0 | AD7170_PAT2)
#define AD7170_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2)

+#define AD7780_GAIN_MIDPOINT   64
+#define AD7780_FILTER_MIDPOINT 13350
+
struct ad7780_chip_info {
struct iio_chan_specchannel;
unsigned intpattern_mask;
@@ -50,7 +53,10 @@ struct ad7780_state {
const struct ad7780_chip_info   *chip_info;
struct regulator*reg;
struct gpio_desc*powerdown_gpio;
-   unsigned intgain;
+   struct gpio_desc*gain_gpio;
+   struct gpio_desc*filter_gpio;
+   unsigned intgain;
+   unsigned intint_vref_mv;

struct ad_sigma_delta sd;
};
@@ -104,8 +110,10 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
voltage_uv = regulator_get_voltage(st->reg);
if (voltage_uv < 0)
return voltage_uv;
-   *val = (voltage_uv / 1000) * st->gain;
+   voltage_uv /= 1000;
+   *val = voltage_uv * st->gain;
*val2 = chan->scan_type.realbits - 1;
+   st->int_vref_mv = voltage_uv;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_OFFSET:
*val = -(1 << (chan->scan_type.realbits - 1));
@@ -115,6 +123,50 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
return -EINVAL;
}

+static int ad7780_write_raw(struct iio_dev *indio_dev,
+   struct iio_chan_spec const *chan,
+   int val,
+   int val2,
+   long m)
+{
+   struct ad7780_state *st = iio_priv(indio_dev);
+   const struct ad7780_chip_info *chip_info = st->chip_info;
+   unsigned long long vref;
+   unsigned int full_scale, gain;
+
+   if (!chip_info->is_ad778x)
+   return -EINVAL;
+
+   switch (m) {
+   case IIO_CHAN_INFO_SCALE:
+   if (val != 0)
+   return -EINVAL;
+
+   vref = st->int_vref_mv * 100LL;
+   full_scale = 1 << (chip_info->channel.scan_type.realbits - 1);
+   gain = DIV_ROUND_CLOSEST(vref, full_scale);
+   gain = DIV_ROUND_CLOSEST(gain, val2);
+   st->gain = gain;
+   if (gain < AD7780_GAIN_MIDPOINT)
+   gain = 0;
+   else
+   gain = 1;
+   gpiod_set_value(st->gain_gpio, gain);
+   break;
+   case IIO_CHAN_INFO_SAMP_FREQ:
+   if (1000*val + val2/1000 < AD7780_FILTER_MIDPOINT)
+   val = 0;
+   else
+   val = 1;
+   gpiod_set_value(st->filter_gpio, val);
+   break;
+   default:
+   break;
+   }
+
+   return 0;
+}
+
static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta,
 unsigned int raw_sample)
{
@@ -125,13 +177,6 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta 
*sigma_delta,
((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
return -EIO;

-   if (chip_info->is_ad778x) {
-   if (raw_sample & AD7780_GAIN)
-   st->gain = 1;
-   else
-   st->gain = 128;
-   }
-
return 0;
}

@@ -173,8 +218,47 @@ static const struct ad7780_chip_info 
ad7780_chip_info_tbl[] = {

static const struct iio_info ad7780_info = {
.read_raw = ad7780_read_raw,
+   .write_raw = ad7780_write_raw,
};

+static int ad7780_init_gpios(struct device *dev, struct ad7780_state *st)
+{
+   int ret;
+
+   st->powerdown_gpio = devm_gpiod_get_optional(dev,
+   

[PATCH v5 00/11] staging: iio: ad7780: move out of staging

2019-03-15 Thread Renato Lui Geh

This series of patches contains the following:
- Adds user input for the 'gain' and 'filter' GPIO pins for the ad778x
  family chips;
- Missing switch default case tidy up;
- Gain reading for the ad778x;
- Filter reading for the ad778x;
- Sets pattern macro values and mask for PATTERN status bits;
- Adds ID values for the ad7170, ad7171, ad7780 and ad7781 for ID
  status bits checking;
- Moves regulator initialization to after GPIO init to maintain
  consistency between probe and remove;
- Copyright edits, adding SPDX identifier and new copyright holder;
- Moves the ad7780 driver out of staging to the mainline;
- Adds device tree binding for the ad7780 driver.

Renato Lui Geh (11):
 staging: iio: ad7780: add gain & filter gpio support
 staging: iio: ad7780: add missing switch default case
 staging: iio: ad7780: add gain reading to ad778x
 staging: iio: ad7780: add filter reading to ad778x
 staging: iio: ad7780: set pattern values and masks directly
 staging:iio:ad7780: add chip ID values and mask
 staging: iio: ad7780: move regulator to after GPIO init
 staging: iio: ad7780: add SPDX identifier
 staging: iio: ad7780: add new copyright holder
 staging: iio: ad7780: moving ad7780 out of staging
 staging: iio: ad7780: add device tree binding

Changelog:
*v3
- SPDX and regulator init as patches
- Renamed filter to odr and ad778x_filter to ad778x_odr_avail
- Removed unnecessary regulator disabling
- Removed unnecessary AD_SD_CHANNEL macro
- Changed unsigned int to unsigned long long to avoid overflow
*v4
- Split gain & filter patch into two, with the new commit adding only
  filter reading
- Changed pattern values to direct values, and added pattern mask
- Added ID values and mask
- Added new copyright holder
- Added device tree binding to the ad7780 driver
*v5
- Tidy ups
- Gain reading split from "gain & filter gpio support" commit to its
  own separate patch
- ad778x_odr_avail moved to more appropriate patch
- Init GPIOs in a separate function
- Raise error when ad717x tries to perform a write operation

.../bindings/iio/adc/adi,ad7780.txt   |  48 +++
drivers/iio/adc/Kconfig   |  12 +
drivers/iio/adc/Makefile  |   1 +
drivers/iio/adc/ad7780.c  | 376 ++
drivers/staging/iio/adc/Kconfig   |  13 -
drivers/staging/iio/adc/Makefile  |   1 -
drivers/staging/iio/adc/ad7780.c  | 277 -
7 files changed, 437 insertions(+), 291 deletions(-)
create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt
create mode 100644 drivers/iio/adc/ad7780.c
delete mode 100644 drivers/staging/iio/adc/ad7780.c

--
2.21.0



[syzbot? printk?] no WARN_ON() messages printed before "Kernel panic - not syncing: panic_on_warn set ..."

2019-03-15 Thread Tetsuo Handa
Hello.

I found a corrupted report at 
https://syzkaller.appspot.com/text?tag=CrashLog=17c6b82b20 .

The panic() was caused by by WARN_ON() from generic_make_request_checks(), but 
there
was no printk() messages from WARN_ON(). Moreover, there was no printk() 
messages
for (at least) nearly one minute despite syzbot's testing likely generates 
constant
printk() messages. Unfortunately, since the report was truncated due to size 
limit,
we can't check when was the last time prink() succeeded writing messages to 
consoles.

--
14:27:02 executing program 1:
(...snipped...)
14:28:00 executing program 3:
(...snipped...)
[  974.068065][T22281] Kernel panic - not syncing: panic_on_warn set ...
[  974.085454][T22281] CPU: 1 PID: 22281 Comm: syz-executor.1 Not tainted 
5.0.0+ #23
[  974.093121][T22281] Hardware name: Google Google Compute Engine/Google 
Compute Engine, BIOS Google 01/01/2011
[  974.103193][T22281] Call Trace:
[  974.106513][T22281]  dump_stack+0x172/0x1f0
[  974.110893][T22281]  ? generic_make_request_checks+0x1be0/0x2160
[  974.117235][T22281]  panic+0x2cb/0x65c
[  974.121434][T22281]  ? __warn_printk+0xf3/0xf3
[  974.126064][T22281]  ? generic_make_request_checks+0x1ca3/0x2160
[  974.132257][T22281]  ? __sanitizer_cov_trace_const_cmp4+0x16/0x20
[  974.138521][T22281]  ? __warn.cold+0x5/0x45
[  974.142877][T22281]  ? __warn+0xe8/0x1d0
[  974.146978][T22281]  ? generic_make_request_checks+0x1ca3/0x2160
[  974.153171][T22281]  __warn.cold+0x20/0x45
[  974.157483][T22281]  ? vprintk_emit+0x1ce/0x6d0
[  974.162202][T22281]  ? generic_make_request_checks+0x1ca3/0x2160
[  974.168403][T22281]  report_bug+0x263/0x2b0
[  974.172847][T22281]  do_error_trap+0x11b/0x200
[  974.177646][T22281]  do_invalid_op+0x37/0x50
[  974.182329][T22281]  ? generic_make_request_checks+0x1ca3/0x2160
[  974.188951][T22281]  invalid_op+0x14/0x20
[  974.193142][T22281] RIP: 0010:generic_make_request_checks+0x1ca3/0x2160
--

Is it possible that the reason there was no printk() messages is that
someone kept printing messages to console from userspace such that
console_trylock() from printk() was not able to succeed for (at least)
nearly one minute?


Re: [GIT] SMB3 Fixes and debugging improvements

2019-03-15 Thread pr-tracker-bot
The pull request you sent on Fri, 15 Mar 2019 18:39:21 -0500:

> git://git.samba.org/sfrench/cifs-2.6.git tags/5.1-rc-smb3

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/9c7dc824d9a48f98b4ee20041e865d97bc73a626

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


[PATCH] regulator: da9052: Include linux/of.h to fix build warning for of_match_ptr

2019-03-15 Thread Axel Lin
Remove #ifdef CONFIG_OF guard so linux/of.h will be included when
!CONFIG_OF. This fixes build warnings when !CONFIG_OF.

Reported-by: kbuild test robot 
Signed-off-by: Axel Lin 
---
 drivers/regulator/da9052-regulator.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/regulator/da9052-regulator.c 
b/drivers/regulator/da9052-regulator.c
index cefa3558236d..d272cd040f79 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -19,10 +19,8 @@
 #include 
 #include 
 #include 
-#ifdef CONFIG_OF
 #include 
 #include 
-#endif
 
 #include 
 #include 
-- 
2.17.1



Re: [GIT PULL] AFS fixes and other bits

2019-03-15 Thread Linus Torvalds
On Fri, Mar 15, 2019 at 4:41 PM David Howells  wrote:
>
> Here's a set of fixes and other bits for AFS to improve the life of desktop
> applications such as firefox.

I pulled, and immediately unpulled.

The thing hasn't even seen a compiler, and when you *do* show the code
to a compiler, said compiler correctly warns about
afs_do_silly_unlink() potentially returning an uninitialized variable.

And yes, it's _trivially_ and obviously uninitialized.

Feel free to submit this for 5.2 after it has actually seen testing.
But this late in the 5.1 merge window, I'm no longer interested in
totally untested new crap. It clearly wasn't ready before the merge
window, and it clearly isn't ready *now*.

Much too late to try to fix this up,

  Linus


You should read will before reply, Honourable Barrister Aziz Dake..

2019-03-15 Thread Aziz Dake
Attn: Sir/Madam

I am Honourable Barrister Aziz the personal resident Attorney here in
Burkina Faso to Late Mr. Muammar Muhammad Abu Minyar al-Gaddafi of
Libya c. 1942 – 20 October 2011.

My client Late Mr. Muammar Muhammad Abu Minyar al-Gaddafi c. 1942 – 20
October 2011, was having a deposit sum of {thirty million four Hundred
thousand united state dollars} only ($30.4M USD) with a security
finance firm affiliated with African development bank here in Burkina
Faso.

With the above explanation’s I want to move this money from Burkina
Faso to your country, affidavit on your name, but note that this is a
deal between me and you and should not be related to anybody until the
deal is over for security reasons, please if interested reply as soon
as possible.

Thanks,
Honourable Barrister Aziz Dake.


Re: [PATCH v2 3/5] gpio: use new gpio_set_config() helper in more places

2019-03-15 Thread Guenter Roeck
On Thu, Feb 07, 2019 at 05:28:57PM +0100, Thomas Petazzoni wrote:
> As suggested by Linus Walleij, let's use the new gpio_set_config()
> helper in gpiod_set_debounce() and gpiod_set_transitory().
> 
> Signed-off-by: Thomas Petazzoni 
> ---
>  drivers/gpio/gpiolib.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index cf8a4402fef1..9762a836fec9 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2762,7 +2762,7 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned 
> debounce)
>   }
>  
>   config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
> - return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
> + return gpio_set_config(chip, gpio_chip_hwgpio(desc), config);

Are you sure this is correct ? This patch results in a number of tracebacks
in mainline. Reverting it fixes the problem.

gpio_set_config() seems to pack config, but it is already packed above.
That seems a bit suspicious.

>  }
>  EXPORT_SYMBOL_GPL(gpiod_set_debounce);
>  
> @@ -2799,7 +2799,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool 
> transitory)
>   packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
> !transitory);
>   gpio = gpio_chip_hwgpio(desc);
> - rc = chip->set_config(chip, gpio, packed);
> + rc = gpio_set_config(chip, gpio, packed);

Same here.

Guenter

---
Bisect log:

# bad: [f261c4e529dac5608a604d3dd3ae1cd2adf23c89] Merge branch 'akpm' (patches 
from Andrew)
# good: [1c163f4c7b3f621efff9b28a47abb36f7378d783] Linux 5.0
git bisect start 'HEAD' 'v5.0'
# good: [45763bf4bc1ebdf8eb95697607e1fd042a3e1221] Merge tag 
'char-misc-5.1-rc1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc
git bisect good 45763bf4bc1ebdf8eb95697607e1fd042a3e1221
# good: [cf2e8c544cd3b33e9e403b7b72404c221bf888d1] Merge tag 'mfd-next-5.1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
git bisect good cf2e8c544cd3b33e9e403b7b72404c221bf888d1
# bad: [d6075262969321bcb5d795de25595fc2a141ac02] Merge tag 'nios2-v5.1-rc1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/lftan/nios2
git bisect bad d6075262969321bcb5d795de25595fc2a141ac02
# bad: [96a6de1a541c86e9e67b9c310c14db4099bd1cbc] Merge tag 'media/v5.1-1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
git bisect bad 96a6de1a541c86e9e67b9c310c14db4099bd1cbc
# bad: [d1cae94871330cb9f5fdcea34529abf7917e682e] Merge tag 'fscrypt-for-linus' 
of git://git.kernel.org/pub/scm/fs/fscrypt/fscrypt
git bisect bad d1cae94871330cb9f5fdcea34529abf7917e682e
# bad: [80201fe175cbf7f3e372f53eba0a881a702ad926] Merge tag 
'for-5.1/block-20190302' of git://git.kernel.dk/linux-block
git bisect bad 80201fe175cbf7f3e372f53eba0a881a702ad926
# bad: [4221b807d1f73c03d22543416d303b60a5d1ef31] Merge tag 
'for-5.1/libata-20190301' of git://git.kernel.dk/linux-block
git bisect bad 4221b807d1f73c03d22543416d303b60a5d1ef31
# bad: [8fab3d713ca36bf4ad4dadec0bf38f5e70b8999d] Merge tag 
'gpio-v5.1-updates-for-linus' of 
git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into devel
git bisect bad 8fab3d713ca36bf4ad4dadec0bf38f5e70b8999d
# good: [b868db94a6a704755a33a362cfcf4625abdda115] gpio: tqmx86: Add GPIO from 
for this IO controller
git bisect good b868db94a6a704755a33a362cfcf4625abdda115
# good: [5340f23df8fe27a270af3fa1a93cd07293d23dd9] gpio: sprd: Add missing 
break in switch statement
git bisect good 5340f23df8fe27a270af3fa1a93cd07293d23dd9
# bad: [7f2f787c10596f486644d730a0a23e78abe8cbe0] gpio: pcf857x: Simpify 
wake-up handling
git bisect bad 7f2f787c10596f486644d730a0a23e78abe8cbe0
# bad: [6581eaf0e890756e093e2f44916edb5e7e6558ca] gpio: use new 
gpio_set_config() helper in more places
git bisect bad 6581eaf0e890756e093e2f44916edb5e7e6558ca
# good: [71479789851bdd9d56cd9e82892b0a3bee0a4c2a] gpio: rename 
gpio_set_drive_single_ended() to gpio_set_config()
git bisect good 71479789851bdd9d56cd9e82892b0a3bee0a4c2a
# first bad commit: [6581eaf0e890756e093e2f44916edb5e7e6558ca] gpio: use new 
gpio_set_config() helper in more places

Sample traceback:

[   15.965307] [ cut here ]
[   15.965655] WARNING: CPU: 0 PID: 1 at drivers/gpio/gpio-aspeed.c:834 
unregister_allocated_timer+0x60/0x98
[   15.965884] No timer allocated to offset 125
[   15.966177] CPU: 0 PID: 1 Comm: swapper Not tainted 
5.0.0-11515-g3b319ee220a8 #1
[   15.966360] Hardware name: Generic DT based system
[   15.966586] Backtrace: 
[   15.966815] [<80106f9c>] (dump_backtrace) from [<80107248>] 
(show_stack+0x20/0x24)
[   15.967112]  r7:0009 r6: r5:80bed4a0 r4:878a1c74
[   15.967704] [<80107228>] (show_stack) from [<8093f830>] 
(dump_stack+0x20/0x28)
[   15.967925] [<8093f810>] (dump_stack) from [<801147c8>] (__warn+0xf0/0x118)
[   15.968133] [<801146d8>] (__warn) from [<80114844>] 
(warn_slowpath_fmt+0x54/0x74)
[   15.968370]  r9:0001 r8:6113 

Re: [GIT PULL RESEND] pidfd changes for v5.1-rc1

2019-03-15 Thread Joel Fernandes
On Tue, Mar 12, 2019 at 6:53 AM Christian Brauner  wrote:
>
> Hi Linus,
>
> This is a resend of the pull request for the pidfd_send_signal() syscall
> which I sent last Tuesday. I'm not sure whether you just wanted to take a
> closer look.
>
> The following changes since commit f17b5f06cb92ef2250513a1e154c47b78df07d40:
>
>   Linux 5.0-rc4 (2019-01-27 15:18:05 -0800)
>
> are available in the Git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git 
> tags/pidfd-v5.1-rc1
>
> The patchset introduces the ability to use file descriptors from proc/
> as stable handles on struct pid. Even if a pid is recycled the handle will
> not change. For a start these fds can be used to send signals to the
> processes they refer to.

Joel from the Android team here. This will solve a long standing issue we
have with Android's low memory killer daemon (lmkd) where the killing of
a PID is racy with the traditional signal delivery methods. With this new API,
we can kill things correctly in a race free way. I hope this will get merged
soon and I look forward to further developing on top of this (such as
for support knowing when something was killed and waiting for it reliably -
right now we have a very suboptimal 100ms periodic polling loop to
check for process death, whichslows down how fast we can kill processes to
reclaim their memory).

thanks,

- Joel


>
> With the ability to use /proc/ fds as stable handles on struct pid we
> can fix a long-standing issue where after a process has exited its pid can
> be reused by another process. If a caller sends a signal to a reused pid it
> will end up signaling the wrong process.
> With this patchset we enable a variety of use cases. One obvious example is
> that we can now safely delegate an important part of process management -
> sending signals - to processes other than the parent of a given process by
> sending file descriptors around via scm rights and not fearing that the
> given process will have been recycled in the meantime.
> It also allows for easy testing whether a given process is still alive or
> not by sending signal 0 to a pidfd which is quite handy.
> There has been some interest in this feature e.g. from systems management
> (systemd, glibc) and container managers. I have requested and gotten
> comments from glibc to make sure that this syscall is suitable for their
> needs as well. In the future I expect it to take on most other pid-based
> signal syscalls. But such features are left for the future once they are
> needed.
>
> The patchset has been sitting in linux-next for quite a while and has
> not caused any issues. It comes with selftests which verify basic
> functionality and also test that a recycled pid cannot be signaled via a
> pidfd.
>
> Jon has written about a prior version of this patchset. It should cover the
> basic functionality since not a lot has changed since then:
>
> https://lwn.net/Articles/773459/
>
> The commit message for the syscall itself is extensively documenting the
> syscall, including it's functionality and extensibility.
>
> /* Merge conflict and sycall number coordination */
> Please note, there will be a merge conflict between the Jens' io_uring
> patch set in the block tree and this tree. To minimize its impact Arnd
> worked with Jens and me to coordinate syscall numbers in advance.
> pidfd_send_signal() takes 424 and Jens' patchset took 425 to 427.
>
> /* Separate tree on kernel.org */
> At the beginning of last merge cycle it was suggested to move this patchset
> into a separate tree on kernel.org as there will be more work coming that
> will be extending the use of file descriptors for processes. The tree was
> announced in January:
>
> https://lore.kernel.org/lkml/20190108234722.bojj5bqowluty...@brauner.io/
>
> The pidfd tree is located on kernel.org
>
> https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/
>
> and it's for-next branch is already tracked by Stephen in linux-next since
> the beginning of the 5.0 development cycle. I'm prepared to deal with any
> fallouts coming from this work going forward.
>
> The only thing that has changed recently in these patches was the addition
> of two more Acked-by/Reviewed-by from  David Howells and tglx after the
> last round of reviews.
>
> Please consider pulling these changes from the signed pidfd-v5.1-rc1 tag.
>
> Thanks!
> Christian
>
> 
> pidfd patches for v5.1-rc1
>
> 
> Christian Brauner (2):
>   signal: add pidfd_send_signal() syscall
>   selftests: add tests for pidfd_send_signal()
>
>  arch/x86/entry/syscalls/syscall_32.tbl |   1 +
>  arch/x86/entry/syscalls/syscall_64.tbl |   1 +
>  fs/proc/base.c |   9 +
>  include/linux/proc_fs.h|   6 +
>  include/linux/syscalls.h   |   3 +
>  include/uapi/asm-generic/unistd.h  

Re: Staging status of speakup

2019-03-15 Thread Chris Brannon
Okash Khawaja  writes:

> Finally there is an issue where text in output buffer sometimes gets
> garbled on SMP systems, but we can continue working on it after the
> driver is moved out of staging, if that's okay. Basically we need a
> reproducer of this issue.

What kind of reproducer do you need here?  It's straightforward to
reproduce in casual use, at least with a software synthesizer.  I don't
know whether it affects hardware synths.

-- Chris


[PATCH] dt-bindings: Require child nodes type to be 'object'

2019-03-15 Thread Rob Herring
A node is always an object (aka a dictionary), so make that explicit for
child node schemas.

A meta-schema update will enforce having 'type' specified.

Cc: Mark Rutland 
Cc: Thomas Gleixner 
Cc: Jason Cooper 
Cc: Marc Zyngier 
Cc: Daniel Lezcano 
Signed-off-by: Rob Herring 
---
 Documentation/devicetree/bindings/arm/cpus.yaml  | 1 +
 .../devicetree/bindings/interrupt-controller/arm,gic.yaml| 1 +
 Documentation/devicetree/bindings/timer/arm,arch_timer_mmio.yaml | 1 +
 3 files changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/arm/cpus.yaml 
b/Documentation/devicetree/bindings/arm/cpus.yaml
index 298c17b327c6..de30466a399d 100644
--- a/Documentation/devicetree/bindings/arm/cpus.yaml
+++ b/Documentation/devicetree/bindings/arm/cpus.yaml
@@ -67,6 +67,7 @@ properties:
 
 patternProperties:
   '^cpu@[0-9a-f]+$':
+type: object
 properties:
   device_type:
 const: cpu
diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml 
b/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
index 758fbd7128e7..54838d4ea44c 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
+++ b/Documentation/devicetree/bindings/interrupt-controller/arm,gic.yaml
@@ -129,6 +129,7 @@ required:
 
 patternProperties:
   "^v2m@[0-9a-f]+$":
+type: object
 description: |
   * GICv2m extension for MSI/MSI-x support (Optional)
 
diff --git a/Documentation/devicetree/bindings/timer/arm,arch_timer_mmio.yaml 
b/Documentation/devicetree/bindings/timer/arm,arch_timer_mmio.yaml
index c4ab59550fc2..b3f0fe96ff0d 100644
--- a/Documentation/devicetree/bindings/timer/arm,arch_timer_mmio.yaml
+++ b/Documentation/devicetree/bindings/timer/arm,arch_timer_mmio.yaml
@@ -59,6 +59,7 @@ properties:
 
 patternProperties:
   '^frame@[0-9a-z]*$':
+type: object
 description: A timer node has up to 8 frame sub-nodes, each with the 
following properties.
 properties:
   frame-number:
-- 
2.19.1



Re: mount.nfs: Protocol error after upgrade to linux/master

2019-03-15 Thread Jakub Kicinski
On Fri, 15 Mar 2019 12:01:05 -0700, Jakub Kicinski wrote:
> On Fri, 15 Mar 2019 11:05:55 -0700, Jakub Kicinski wrote:
> > Hi,
> > 
> > I just upgraded from:
> > 
> > commit a3b1933d34d5bb26d7503752e3528315a9e28339 (net)
> > Merge: c6873d18cb4a 24319258660a
> > Author: David S. Miller 
> > Date:   Mon Mar 11 16:22:49 2019 -0700
> > 
> > to
> > 
> > commit 3b319ee220a8795406852a897299dbdfc1b09911
> > Merge: 9352ca585b2a b6e88119f1ed
> > Author: Linus Torvalds 
> > Date:   Thu Mar 14 10:48:14 2019 -0700
> > 
> > and I'm seeing:
> > 
> > # mount /home/
> > mount.nfs: Protocol error
> > 
> > No errors in dmesg, please let me know if it's a known problem or what
> > other info could be of use.  
> 
> Hm.. I tried to bisect but reverting to that commit doesn't help.  
> 
> Looks like the server responds with:
> 
>   ICMP parameter problem - octet 22, length 80
> 
> pointing at some IP options (type 134)...

Okay, figured it out, it's the commit 13e735c0e953 ("LSM: Introduce
CONFIG_LSM") and all the related changes in security/

I did olddefconfig and it changed my security module from apparmor to
smack silently.  smack must be slapping those IP options on by default.

Pretty awful user experience, and a non-zero chance that users who
upgrade their kernels will miss this and end up with the wrong security
module...


Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread hpa
On March 15, 2019 4:47:01 PM PDT, Matthias Kaehlcke  wrote:
>On Fri, Mar 15, 2019 at 03:12:08PM -0700, h...@zytor.com wrote:
>> On March 15, 2019 3:06:37 PM PDT, Nick Desaulniers
> wrote:
>> >On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke 
>> >wrote:
>> >>
>> >> The compiler may emit calls to __lshrti3 from the compiler runtime
>> >> library, which results in undefined references:
>> >>
>> >> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
>> >>   include/linux/math64.h:186: undefined reference to `__lshrti3'
>> >
>> >Looks like Clang will emit this at -Oz (but not -O2):
>> >https://godbolt.org/z/w1_2YC
>> >
>> >>
>> >> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
>> >
>> >Has it changed since? If so why not a newer version of libgcc_s?
>> >
>> >>
>> >> Include the function for x86 builds with clang, which is the
>> >> environment where the above error was observed.
>> >>
>> >> Signed-off-by: Matthias Kaehlcke 
>> >> ---
>> >>  arch/x86/Kconfig   |  1 +
>> >>  include/linux/libgcc.h | 16 
>> >>  lib/Kconfig|  3 +++
>> >>  lib/Makefile   |  1 +
>> >>  lib/lshrti3.c  | 31 +++
>> >>  5 files changed, 52 insertions(+)
>> >>  create mode 100644 lib/lshrti3.c
>> >>
>> >> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> >> index c1f9b3cf437c..a5e0d923845d 100644
>> >> --- a/arch/x86/Kconfig
>> >> +++ b/arch/x86/Kconfig
>> >> @@ -105,6 +105,7 @@ config X86
>> >> select GENERIC_IRQ_PROBE
>> >> select GENERIC_IRQ_RESERVATION_MODE
>> >> select GENERIC_IRQ_SHOW
>> >> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
>> >> select GENERIC_PENDING_IRQ  if SMP
>> >> select GENERIC_SMP_IDLE_THREAD
>> >> select GENERIC_STRNCPY_FROM_USER
>> >> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
>> >> index 32e1e0f4b2d0..a71036471838 100644
>> >> --- a/include/linux/libgcc.h
>> >> +++ b/include/linux/libgcc.h
>> >> @@ -22,15 +22,26 @@
>> >>  #include 
>> >>
>> >>  typedef int word_type __attribute__ ((mode (__word__)));
>> >> +typedef int TItype __attribute__ ((mode (TI)));
>> >
>> >Well that's an interesting new compiler attribute.
>>
>>https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
>> >Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
>> >typedef int TItype __mode(TI);
>> >
>> >>
>> >>  #ifdef __BIG_ENDIAN
>> >>  struct DWstruct {
>> >> int high, low;
>> >>  };
>> >> +
>> >> +struct DWstruct128 {
>> >> +   long long high, low;
>> >> +};
>> >> +
>> >>  #elif defined(__LITTLE_ENDIAN)
>> >>  struct DWstruct {
>> >> int low, high;
>> >>  };
>> >> +
>> >> +struct DWstruct128 {
>> >> +   long long low, high;
>> >> +};
>> >> +
>> >>  #else
>> >>  #error I feel sick.
>> >>  #endif
>> >> @@ -40,4 +51,9 @@ typedef union {
>> >> long long ll;
>> >>  } DWunion;
>> >>
>> >> +typedef union {
>> >> +   struct DWstruct128 s;
>> >> +   TItype ll;
>> >> +} DWunion128;
>> >> +
>> >>  #endif /* __ASM_LIBGCC_H */
>> >> diff --git a/lib/Kconfig b/lib/Kconfig
>> >> index a9e56539bd11..369e10259ea6 100644
>> >> --- a/lib/Kconfig
>> >> +++ b/lib/Kconfig
>> >> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
>> >>  config GENERIC_LIB_LSHRDI3
>> >> bool
>> >>
>> >> +config GENERIC_LIB_LSHRTI3
>> >> +   bool
>> >> +
>> >>  config GENERIC_LIB_MULDI3
>> >> bool
>> >>
>> >> diff --git a/lib/Makefile b/lib/Makefile
>> >> index 4e066120a0d6..42648411f451 100644
>> >> --- a/lib/Makefile
>> >> +++ b/lib/Makefile
>> >> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
>> >>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
>> >> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
>> >>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
>> >> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
>> >> new file mode 100644
>> >> index ..2d2123bb3030
>> >> --- /dev/null
>> >> +++ b/lib/lshrti3.c
>> >> @@ -0,0 +1,31 @@
>> >> +// SPDX-License-Identifier: GPL-2.0
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +long long __lshrti3(long long u, word_type b)
>> >> +{
>> >> +   DWunion128 uu, w;
>> >> +   word_type bm;
>> >> +
>> >> +   if (b == 0)
>> >> +   return u;
>> >> +
>> >> +   uu.ll = u;
>> >> +   bm = 64 - b;
>> >> +
>> >> +   if (bm <= 0) {
>> >> +   w.s.high = 0;
>> >> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
>> >> +   } else {
>> >> +   const unsigned long long carries =
>> >> +   (unsigned long long) uu.s.high << bm;
>> >> +   w.s.high = (unsigned long long) uu.s.high >> b;
>> >> +   w.s.low = ((unsigned long long) 

Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread hpa
On March 15, 2019 4:34:10 PM PDT, Matthias Kaehlcke  wrote:
>Hi Peter,
>
>On Fri, Mar 15, 2019 at 03:08:57PM -0700, h...@zytor.com wrote:
>> On March 15, 2019 3:06:37 PM PDT, Nick Desaulniers
> wrote:
>> >On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke 
>> >wrote:
>> >>
>> >> The compiler may emit calls to __lshrti3 from the compiler runtime
>> >> library, which results in undefined references:
>> >>
>> >> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
>> >>   include/linux/math64.h:186: undefined reference to `__lshrti3'
>> >
>> >Looks like Clang will emit this at -Oz (but not -O2):
>> >https://godbolt.org/z/w1_2YC
>> >
>> >>
>> >> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
>> >
>> >Has it changed since? If so why not a newer version of libgcc_s?
>> >
>> >>
>> >> Include the function for x86 builds with clang, which is the
>> >> environment where the above error was observed.
>> >>
>> >> Signed-off-by: Matthias Kaehlcke 
>> >> ---
>> >>  arch/x86/Kconfig   |  1 +
>> >>  include/linux/libgcc.h | 16 
>> >>  lib/Kconfig|  3 +++
>> >>  lib/Makefile   |  1 +
>> >>  lib/lshrti3.c  | 31 +++
>> >>  5 files changed, 52 insertions(+)
>> >>  create mode 100644 lib/lshrti3.c
>> >>
>> >> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> >> index c1f9b3cf437c..a5e0d923845d 100644
>> >> --- a/arch/x86/Kconfig
>> >> +++ b/arch/x86/Kconfig
>> >> @@ -105,6 +105,7 @@ config X86
>> >> select GENERIC_IRQ_PROBE
>> >> select GENERIC_IRQ_RESERVATION_MODE
>> >> select GENERIC_IRQ_SHOW
>> >> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
>> >> select GENERIC_PENDING_IRQ  if SMP
>> >> select GENERIC_SMP_IDLE_THREAD
>> >> select GENERIC_STRNCPY_FROM_USER
>> >> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
>> >> index 32e1e0f4b2d0..a71036471838 100644
>> >> --- a/include/linux/libgcc.h
>> >> +++ b/include/linux/libgcc.h
>> >> @@ -22,15 +22,26 @@
>> >>  #include 
>> >>
>> >>  typedef int word_type __attribute__ ((mode (__word__)));
>> >> +typedef int TItype __attribute__ ((mode (TI)));
>> >
>> >Well that's an interesting new compiler attribute.
>>
>>https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
>> >Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
>> >typedef int TItype __mode(TI);
>> >
>> >>
>> >>  #ifdef __BIG_ENDIAN
>> >>  struct DWstruct {
>> >> int high, low;
>> >>  };
>> >> +
>> >> +struct DWstruct128 {
>> >> +   long long high, low;
>> >> +};
>> >> +
>> >>  #elif defined(__LITTLE_ENDIAN)
>> >>  struct DWstruct {
>> >> int low, high;
>> >>  };
>> >> +
>> >> +struct DWstruct128 {
>> >> +   long long low, high;
>> >> +};
>> >> +
>> >>  #else
>> >>  #error I feel sick.
>> >>  #endif
>> >> @@ -40,4 +51,9 @@ typedef union {
>> >> long long ll;
>> >>  } DWunion;
>> >>
>> >> +typedef union {
>> >> +   struct DWstruct128 s;
>> >> +   TItype ll;
>> >> +} DWunion128;
>> >> +
>> >>  #endif /* __ASM_LIBGCC_H */
>> >> diff --git a/lib/Kconfig b/lib/Kconfig
>> >> index a9e56539bd11..369e10259ea6 100644
>> >> --- a/lib/Kconfig
>> >> +++ b/lib/Kconfig
>> >> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
>> >>  config GENERIC_LIB_LSHRDI3
>> >> bool
>> >>
>> >> +config GENERIC_LIB_LSHRTI3
>> >> +   bool
>> >> +
>> >>  config GENERIC_LIB_MULDI3
>> >> bool
>> >>
>> >> diff --git a/lib/Makefile b/lib/Makefile
>> >> index 4e066120a0d6..42648411f451 100644
>> >> --- a/lib/Makefile
>> >> +++ b/lib/Makefile
>> >> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
>> >>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
>> >> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
>> >>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
>> >>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
>> >> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
>> >> new file mode 100644
>> >> index ..2d2123bb3030
>> >> --- /dev/null
>> >> +++ b/lib/lshrti3.c
>> >> @@ -0,0 +1,31 @@
>> >> +// SPDX-License-Identifier: GPL-2.0
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +long long __lshrti3(long long u, word_type b)
>> >> +{
>> >> +   DWunion128 uu, w;
>> >> +   word_type bm;
>> >> +
>> >> +   if (b == 0)
>> >> +   return u;
>> >> +
>> >> +   uu.ll = u;
>> >> +   bm = 64 - b;
>> >> +
>> >> +   if (bm <= 0) {
>> >> +   w.s.high = 0;
>> >> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
>> >> +   } else {
>> >> +   const unsigned long long carries =
>> >> +   (unsigned long long) uu.s.high << bm;
>> >> +   w.s.high = (unsigned long long) uu.s.high >> b;
>> >> +   w.s.low = ((unsigned 

Re: [GIT] SMB3 Fixes and debugging improvements

2019-03-15 Thread Steve French
Previous pull request text was truncated (last 25 lines of text
missing), resending.

Please pull the following changes since commit
f261c4e529dac5608a604d3dd3ae1cd2adf23c89:

  Merge branch 'akpm' (patches from Andrew) (2019-03-14 15:10:10 -0700)

are available in the Git repository at:

  git://git.samba.org/sfrench/cifs-2.6.git tags/5.1-rc-smb3

for you to fetch changes up to bc31d0cdcfbadb6258b45db97e93b1c83822ba33:

  CIFS: fix POSIX lock leak and invalid ptr deref (2019-03-14 19:32:36 -0500)


- Various additional dynamic tracing tracepoints
- Debugging improvements (including ability to query the server via
SMB3 fsctl from userspace tools which can help with stats and
debugging)
- One minor performance improvement (root directory inode caching)
- Crediting (SMB3 flow control) fixes
- Some cleanup (docs and to mknod)
- Important fixes: one to smb3 implementation of fallocate zero range
(which fixes three xfstests) and a POSIX lock fix

Aurelien Aptel (2):
  CIFS: make mknod() an smb_version_op
  CIFS: fix POSIX lock leak and invalid ptr deref

Ronnie Sahlberg (11):
  cifs: change wait_for_free_request() to take flags as argument
  cifs: pass flags down into wait_for_free_credits()
  cifs: wait_for_free_credits() make it possible to wait for >=1 credits
  cifs: prevent starvation in wait_for_free_credits for
multi-credit requests
  cifs: add a timeout argument to wait_for_free_credits
  cifs: simplify how we handle credits in compound_send_recv()
  cifs: cache FILE_ALL_INFO for the shared root handle
  cifs: add SMB2_ioctl_init/free helpers to be used with compounding
  cifs: fix smb3_zero_range so it can expand the file-size when required
  cifs: fix incorrect handling of smb2_set_sparse() return in
smb3_simple_falloc
  SMB3: Allow SMB3 FSCTL queries to be sent to server from tools

Steve French (9):
  smb3: display security information in /proc/fs/cifs/DebugData
more accurately
  smb3: add dynamic tracepoint for timeout waiting for credits
  smb3: display volume serial number for shares in /proc/fs/cifs/DebugData
  smb3: Add dynamic trace points for various compounded smb3 ops
  smb3: add dynamic tracepoints for simple fallocate and zero range
  SMB3: passthru query info doesn't check for SMB3 FSCTL passthru
  cifs: remove unused value pointed out by Coverity
  cifs: minor documentation updates
  smb2: fix typo in definition of a few error flags

 Documentation/filesystems/cifs/TODO |   3 +-
 Documentation/filesystems/cifs/cifs.txt |  34 +++
 fs/cifs/cifs_debug.c|  11 +++-
 fs/cifs/cifs_ioctl.h|   3 +
 fs/cifs/cifsglob.h  |  16 -
 fs/cifs/connect.c   |   4 --
 fs/cifs/dir.c   | 107 +
 fs/cifs/file.c  |  14 -
 fs/cifs/smb1ops.c   | 126
+++
 fs/cifs/smb2inode.c |  87 ---
 fs/cifs/smb2ops.c   | 423
--
 fs/cifs/smb2pdu.c   | 145
++---
 fs/cifs/smb2pdu.h   |   7 +++
 fs/cifs/smb2proto.h |   7 +++
 fs/cifs/smb2status.h|   6 +-
 fs/cifs/trace.h | 124
++
 fs/cifs/transport.c | 226
+
 17 files changed, 981 insertions(+), 362 deletions(-)

On Fri, Mar 15, 2019 at 6:39 PM Steve French  wrote:
>
> Please pull the following changes since commit
> f261c4e529dac5608a604d3dd3ae1cd2adf23c89:
>
>   Merge branch 'akpm' (patches from Andrew) (2019-03-14 15:10:10 -0700)
>
> are available in the Git repository at:
>
>   git://git.samba.org/sfrench/cifs-2.6.git tags/5.1-rc-smb3
>
> for you to fetch changes up to bc31d0cdcfbadb6258b45db97e93b1c83822ba33:
>
>   CIFS: fix POSIX lock leak and invalid ptr deref (2019-03-14 19:32:36 -0500)
>
> 
> - Various additional dynamic tracing tracepoints
> - Debugging improvements (including ability to query the server via
> SMB3 fsctl from userspace tools which can help with stats and
> debugging)
> - One minor performance improvement (root directory inode caching)
> - Crediting (SMB3 flow control) fixes
> - Some cleanup (docs and to mknod)
> - Important fixes: one to smb3 implementation of fallocate zero range
> (which fixes three xfstests) and a POSIX lock fix
> 

Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread Matthias Kaehlcke
On Fri, Mar 15, 2019 at 03:12:08PM -0700, h...@zytor.com wrote:
> On March 15, 2019 3:06:37 PM PDT, Nick Desaulniers  
> wrote:
> >On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke 
> >wrote:
> >>
> >> The compiler may emit calls to __lshrti3 from the compiler runtime
> >> library, which results in undefined references:
> >>
> >> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
> >>   include/linux/math64.h:186: undefined reference to `__lshrti3'
> >
> >Looks like Clang will emit this at -Oz (but not -O2):
> >https://godbolt.org/z/w1_2YC
> >
> >>
> >> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
> >
> >Has it changed since? If so why not a newer version of libgcc_s?
> >
> >>
> >> Include the function for x86 builds with clang, which is the
> >> environment where the above error was observed.
> >>
> >> Signed-off-by: Matthias Kaehlcke 
> >> ---
> >>  arch/x86/Kconfig   |  1 +
> >>  include/linux/libgcc.h | 16 
> >>  lib/Kconfig|  3 +++
> >>  lib/Makefile   |  1 +
> >>  lib/lshrti3.c  | 31 +++
> >>  5 files changed, 52 insertions(+)
> >>  create mode 100644 lib/lshrti3.c
> >>
> >> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> >> index c1f9b3cf437c..a5e0d923845d 100644
> >> --- a/arch/x86/Kconfig
> >> +++ b/arch/x86/Kconfig
> >> @@ -105,6 +105,7 @@ config X86
> >> select GENERIC_IRQ_PROBE
> >> select GENERIC_IRQ_RESERVATION_MODE
> >> select GENERIC_IRQ_SHOW
> >> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
> >> select GENERIC_PENDING_IRQ  if SMP
> >> select GENERIC_SMP_IDLE_THREAD
> >> select GENERIC_STRNCPY_FROM_USER
> >> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
> >> index 32e1e0f4b2d0..a71036471838 100644
> >> --- a/include/linux/libgcc.h
> >> +++ b/include/linux/libgcc.h
> >> @@ -22,15 +22,26 @@
> >>  #include 
> >>
> >>  typedef int word_type __attribute__ ((mode (__word__)));
> >> +typedef int TItype __attribute__ ((mode (TI)));
> >
> >Well that's an interesting new compiler attribute.
> >https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
> >Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
> >typedef int TItype __mode(TI);
> >
> >>
> >>  #ifdef __BIG_ENDIAN
> >>  struct DWstruct {
> >> int high, low;
> >>  };
> >> +
> >> +struct DWstruct128 {
> >> +   long long high, low;
> >> +};
> >> +
> >>  #elif defined(__LITTLE_ENDIAN)
> >>  struct DWstruct {
> >> int low, high;
> >>  };
> >> +
> >> +struct DWstruct128 {
> >> +   long long low, high;
> >> +};
> >> +
> >>  #else
> >>  #error I feel sick.
> >>  #endif
> >> @@ -40,4 +51,9 @@ typedef union {
> >> long long ll;
> >>  } DWunion;
> >>
> >> +typedef union {
> >> +   struct DWstruct128 s;
> >> +   TItype ll;
> >> +} DWunion128;
> >> +
> >>  #endif /* __ASM_LIBGCC_H */
> >> diff --git a/lib/Kconfig b/lib/Kconfig
> >> index a9e56539bd11..369e10259ea6 100644
> >> --- a/lib/Kconfig
> >> +++ b/lib/Kconfig
> >> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
> >>  config GENERIC_LIB_LSHRDI3
> >> bool
> >>
> >> +config GENERIC_LIB_LSHRTI3
> >> +   bool
> >> +
> >>  config GENERIC_LIB_MULDI3
> >> bool
> >>
> >> diff --git a/lib/Makefile b/lib/Makefile
> >> index 4e066120a0d6..42648411f451 100644
> >> --- a/lib/Makefile
> >> +++ b/lib/Makefile
> >> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
> >>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
> >>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
> >>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
> >> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
> >>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
> >>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
> >>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
> >> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
> >> new file mode 100644
> >> index ..2d2123bb3030
> >> --- /dev/null
> >> +++ b/lib/lshrti3.c
> >> @@ -0,0 +1,31 @@
> >> +// SPDX-License-Identifier: GPL-2.0
> >> +
> >> +#include 
> >> +#include 
> >> +
> >> +long long __lshrti3(long long u, word_type b)
> >> +{
> >> +   DWunion128 uu, w;
> >> +   word_type bm;
> >> +
> >> +   if (b == 0)
> >> +   return u;
> >> +
> >> +   uu.ll = u;
> >> +   bm = 64 - b;
> >> +
> >> +   if (bm <= 0) {
> >> +   w.s.high = 0;
> >> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
> >> +   } else {
> >> +   const unsigned long long carries =
> >> +   (unsigned long long) uu.s.high << bm;
> >> +   w.s.high = (unsigned long long) uu.s.high >> b;
> >> +   w.s.low = ((unsigned long long) uu.s.low >> b) |
> >carries;
> >> +   }
> >> +
> >> +   return w.ll;
> >> +}
> >> +#ifndef BUILD_VDSO
> >> +EXPORT_SYMBOL(__lshrti3);
> >> +#endif
> >
> >I don't think you want this.  Maybe that was 

[GIT PULL] AFS fixes and other bits

2019-03-15 Thread David Howells
Hi Linus,

Here's a set of fixes and other bits for AFS to improve the life of desktop
applications such as firefox.  It makes the following improvements/fixes:

 (1) Fix file locking to allow fine-grained locking, as required by firefox
 and sqlite, with the caveat that you can't get a partial write lock on
 a file if you first get a partial read lock on it as the AFS protocol
 only supports whole-file locks.

 [At some point I need to look at how best to emulate OpenAFS's
 behaviour whereby all partial locks are just granted without reference
 to the kernel lock - maybe with some sort of mount parameter to enable
 it.]

 (2) Fix the way the server lock, once obtained, is distributed to the
 local processes waiting for it, thereby making sure they wait if they
 can't be immediately granted a local lock.

 (3) Fix the nonappearance of afs locks in /proc/locks.

 (4) Fix the handling of asynchronous file lock RPC operation failure on
 files that get deleted whilst the lock is being extended or released.

 (5) Implement silly-rename.

 (6) Fix the file lock expiry calculation to be based on the time the set-
 or extend-lock reply is seen (packet timestamp) rather than by the
 time at which we've done processing the operation (wallclock time) to
 allow for delays in processing.

 (7) Split the synchronous wait out of the client call dispatcher to make
 it possible to convert synchronous calls into async calls in the event
 of a signal.

The series also:

 (1) Adds/modifies a number of tracepoints, mostly related to file locking
 and silly rename.

 (2) Provides a more comprehensive data dump in the event that a directory
 content check fails.

David
---
The following changes since commit ebc551f2b8f905eca0e25c476c1e5c098cd92103:

  Merge tag 'nfsd-5.1' of git://linux-nfs.org/~bfields/linux (2019-03-12 
15:06:54 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git 
tags/afs-fixes-20190315

for you to fetch changes up to 78cf74c367eb608e8a15167da5aeae2c8abed902:

  afs: Add more tracepoints (2019-03-15 22:06:31 +)


AFS fixes


David Howells (10):
  afs: Split wait from afs_make_call()
  afs: Calculate lock extend timer from set/extend reply reception
  afs: Fix AFS file locking to allow fine grained locks
  afs: Further fix file locking
  afs: Add file locking tracepoints
  afs: Improve dir check failure reports
  afs: Handle lock rpc ops failing on a file that got deleted
  afs: Add directory reload tracepoint
  afs: Implement sillyrename for unlink and rename
  afs: Add more tracepoints

 fs/afs/Makefile|   1 +
 fs/afs/dir.c   | 161 +++--
 fs/afs/dir_silly.c | 239 +++
 fs/afs/flock.c | 569 +++--
 fs/afs/fs_probe.c  |  13 +-
 fs/afs/fsclient.c  |  92 +---
 fs/afs/inode.c |   2 +
 fs/afs/internal.h  |  25 +-
 fs/afs/rxrpc.c |  33 ++-
 fs/afs/super.c |   5 +-
 fs/afs/vl_probe.c  |  14 +-
 fs/afs/vlclient.c  |  26 ++-
 fs/afs/yfsclient.c |  72 --
 include/linux/fs.h |   1 +
 include/trace/events/afs.h | 348 ++-
 15 files changed, 1258 insertions(+), 343 deletions(-)
 create mode 100644 fs/afs/dir_silly.c



Re: [PATCH] staging: octeon-usb octeon-hcd: Fix several typos.

2019-03-15 Thread Aaro Koskinen
Hi,

On Sat, Mar 09, 2019 at 03:18:27PM -0300, Laura Lazzati wrote:
> I found that the comments had several typos such as "aenable", "internaly" 
> and some others.
> I fixed them all.
> 
> Signed-off-by: Laura Lazzati 

I spotted one more typo that could be fixed as well:

> @@ -1797,7 +1797,7 @@ union cvmx_usbnx_usbp_ctl_status {
>*  This is a test signal. When the USB Core is
>*  powered up (not in Susned Mode), an automatic
   ^^

Should be "Suspend".

A.


[GIT] SMB3 Fixes and debugging improvements

2019-03-15 Thread Steve French
Please pull the following changes since commit
f261c4e529dac5608a604d3dd3ae1cd2adf23c89:

  Merge branch 'akpm' (patches from Andrew) (2019-03-14 15:10:10 -0700)

are available in the Git repository at:

  git://git.samba.org/sfrench/cifs-2.6.git tags/5.1-rc-smb3

for you to fetch changes up to bc31d0cdcfbadb6258b45db97e93b1c83822ba33:

  CIFS: fix POSIX lock leak and invalid ptr deref (2019-03-14 19:32:36 -0500)


- Various additional dynamic tracing tracepoints
- Debugging improvements (including ability to query the server via
SMB3 fsctl from userspace tools which can help with stats and
debugging)
- One minor performance improvement (root directory inode caching)
- Crediting (SMB3 flow control) fixes
- Some cleanup (docs and to mknod)
- Important fixes: one to smb3 implementation of fallocate zero range
(which fixes three xfstests) and a POSIX lock fix

Aurelien Aptel (2):
  CIFS: make mknod() an smb_version_op
  CIFS: fix POSIX lock leak and invalid ptr deref

Ronnie Sahlberg (11):
  cifs: change wait_for_free_request() to take flags as argument
  cifs: pass flags down into wait_for_free_credits()
  cifs: wait_for_free_credits() make it possible to wait for >=1 credits
  cifs: prevent starvation in wait_for_free_credits for
multi-credit requests
  cifs: add a timeout argument to wait_for_free_credits
  cifs: simplify how we handle credits in compound_send_recv()
  cifs: cache FILE_ALL_INFO for the shared root handle
  cifs: add SMB2_ioctl_init/free helpers to be used with compounding
  cifs: fix smb3_zero_range so it can expand the file-size when required
  cifs: fix incorrect handling of smb2_set_sparse() return in
smb3_simple_falloc
  SMB3: Allow SMB3 FSCTL queries to be sent to server from tools

Steve French (9):
  smb3: display security information in /proc/fs/cifs/DebugData
more accurately
  smb3: add dynamic tracepoint for timeout waiting for credits
  smb3: display volume serial number for shares in /proc/fs/cifs/DebugData
  smb3: Add dynamic trace points for various compounded smb3 ops
  smb3: add dynamic tracepoints for simple fallocate and zero range
  SMB3: passthru query info doesn't check for SMB3 FSCTL passthru
  cifs: remove unused value pointed out by Coverity
  cifs: minor documentation updates
  smb2: fix typo in definition of a few error flags


-- 
Thanks,

Steve


Re: [PATCH v4 06/10] dt-bindings: sdm845-pinctrl: add wakeup interrupt parent for GPIO

2019-03-15 Thread Rob Herring
On Wed, Mar 13, 2019 at 03:18:40PM -0600, Lina Iyer wrote:
> SDM845 SoC has an always-on interrupt controller (PDC) with select GPIO
> routed to the PDC as interrupts that can be used to wake the system up
> from deep low power modes and suspend.
> 
> Cc: devicet...@vger.kernel.org
> Signed-off-by: Lina Iyer 
> ---
>  .../devicetree/bindings/pinctrl/qcom,sdm845-pinctrl.txt| 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

I still don't love this being specific to wake-up, but don't have a 
better suggestion. One nit, otherwise:

Reviewed-by: Rob Herring 

> 
> diff --git 
> a/Documentation/devicetree/bindings/pinctrl/qcom,sdm845-pinctrl.txt 
> b/Documentation/devicetree/bindings/pinctrl/qcom,sdm845-pinctrl.txt
> index 665aadb5ea28..f0fedbc5d41a 100644
> --- a/Documentation/devicetree/bindings/pinctrl/qcom,sdm845-pinctrl.txt
> +++ b/Documentation/devicetree/bindings/pinctrl/qcom,sdm845-pinctrl.txt
> @@ -29,6 +29,11 @@ SDM845 platform.
>   Definition: must be 2. Specifying the pin number and flags, as defined
>   in 
>  
> +- wakeup-parent:
> + Usage: optional
> + Value type: 
> + Definition: A phandle to the wakeup interrupt controller for the SoC.
> +
>  - gpio-controller:
>   Usage: required
>   Value type: 
> @@ -53,7 +58,6 @@ pin, a group, or a list of pins or groups. This 
> configuration can include the
>  mux function to select on those pin(s)/group(s), and various pin 
> configuration
>  parameters, such as pull-up, drive strength, etc.
>  
> -
>  PIN CONFIGURATION NODES:
>  
>  The name of each subnode is not important; all subnodes should be enumerated
> @@ -160,6 +164,7 @@ Example:
>   #gpio-cells = <2>;
>   interrupt-controller;
>   #interrupt-cells = <2>;
> + wake-parent = <_intc>;

wakeup-parent

>  
>   qup9_active: qup9-active {
>   mux {
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 


[PATCH] tracing: Kernel access to ftrace instances

2019-03-15 Thread Divya Indi
Ftrace provides the feature “instances” that provides the capability to
create multiple Ftrace ring buffers. However, currently these buffers
are created/accessed via userspace only. The kernel APIs providing these
features are not exported, hence cannot be used by other kernel
components.

This patch aims to extend this infrastructure to provide the
flexibility to create/log/remove/ enable-disable existing trace events
to these buffers from within the kernel.

Signed-off-by: Divya Indi 
---
 kernel/trace/trace.c| 72 +
 kernel/trace/trace_events.c |  1 +
 2 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index c4238b4..a5e7e51 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2878,6 +2878,7 @@ void trace_printk_init_buffers(void)
if (global_trace.trace_buffer.buffer)
tracing_start_cmdline_record();
 }
+EXPORT_SYMBOL_GPL(trace_printk_init_buffers);
 
 void trace_printk_start_comm(void)
 {
@@ -3038,6 +3039,7 @@ int trace_array_printk(struct trace_array *tr,
va_end(ap);
return ret;
 }
+EXPORT_SYMBOL_GPL(trace_array_printk);
 
 __printf(3, 4)
 int trace_array_printk_buf(struct ring_buffer *buffer,
@@ -7832,7 +7834,7 @@ static void update_tracer_options(struct trace_array *tr)
mutex_unlock(_types_lock);
 }
 
-static int instance_mkdir(const char *name)
+struct trace_array *trace_array_create(const char *name)
 {
struct trace_array *tr;
int ret;
@@ -7896,7 +7898,7 @@ static int instance_mkdir(const char *name)
mutex_unlock(_types_lock);
mutex_unlock(_mutex);
 
-   return 0;
+   return tr;
 
  out_free_tr:
free_trace_buffers(tr);
@@ -7908,33 +7910,21 @@ static int instance_mkdir(const char *name)
mutex_unlock(_types_lock);
mutex_unlock(_mutex);
 
-   return ret;
+   return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(trace_array_create);
 
+static int instance_mkdir(const char *name)
+{
+   return PTR_ERR_OR_ZERO(trace_array_create(name));
 }
 
-static int instance_rmdir(const char *name)
+static int __remove_instance(struct trace_array *tr)
 {
-   struct trace_array *tr;
-   int found = 0;
-   int ret;
int i;
-
-   mutex_lock(_mutex);
-   mutex_lock(_types_lock);
-
-   ret = -ENODEV;
-   list_for_each_entry(tr, _trace_arrays, list) {
-   if (tr->name && strcmp(tr->name, name) == 0) {
-   found = 1;
-   break;
-   }
-   }
-   if (!found)
-   goto out_unlock;
-
-   ret = -EBUSY;
+   
if (tr->ref || (tr->current_trace && tr->current_trace->ref))
-   goto out_unlock;
+   return -EBUSY;
 
list_del(>list);
 
@@ -7961,9 +7951,41 @@ static int instance_rmdir(const char *name)
kfree(tr->name);
kfree(tr);
 
-   ret = 0;
+   return 0;
+}
 
- out_unlock:
+int trace_array_destroy(struct trace_array *tr)
+{
+   int ret;
+
+   mutex_lock(_mutex);
+   mutex_lock(_types_lock);
+
+   ret = __remove_instance(tr);
+
+   mutex_unlock(_types_lock);
+   mutex_unlock(_mutex);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(trace_array_destroy);
+   
+static int instance_rmdir(const char *name)
+{
+   struct trace_array *tr;
+   int ret;
+
+   mutex_lock(_mutex);
+   mutex_lock(_types_lock);
+
+   ret = -ENODEV;
+   list_for_each_entry(tr, _trace_arrays, list) {
+   if (tr->name && strcmp(tr->name, name) == 0) {
+   ret = __remove_instance(tr);
+   break;
+   }
+   }
+   
mutex_unlock(_types_lock);
mutex_unlock(_mutex);
 
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 5b3b0c3..81c038e 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -832,6 +832,7 @@ static int ftrace_set_clr_event(struct trace_array *tr, 
char *buf, int set)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(ftrace_set_clr_event);
 
 /**
  * trace_set_clr_event - enable or disable an event
-- 
1.8.3.1



[RFC] Kernel access to Ftrace instances.

2019-03-15 Thread Divya Indi
[PATCH] tracing: Kernel access to ftrace instances.

Please review the patch that follows. Below are some details providing
the goal and justification for the patch.

===

Goal:

Ftrace provides the feature “instances” that provides the capability to
create multiple Ftrace ring buffers. However, currently these buffers
are created/accessed via userspace only. The kernel APIs providing these
features are not exported, hence cannot be used by other kernel
components. We want to extend this infrastructure to provide the
flexibility to create/log/remove/ enable-disable existing trace events
to these buffers from within the kernel.


Justification:

 1. We need module-specific/use-case specific ring buffers (apart
from the global trace buffer) to avoid overwrite by other components.
Hence, the need to use Ftrace "instances".

 2. Flexibility to add additional logging to these module-specific
buffers via ksplice/live patch - Having a trace_printk counterpart for
these additional ring buffers.

 3. Most often certain issues and events can be best monitored
within kernel.

 4. Time sensitivity - We need the capability to dynamically enable
and disable tracing from within kernel to extract relevant debugging
info for the right time-window.


Example:

When the kernel detects an unexpected event such as connection drop (Eg:
RDS/NFS connection drops), we need the capability to enable specific
event tracing to capture relevant info during reconnect. This event
tracing will help us diagnose issues that occur during reconnect like
RCA longer reconnect times. In such cases we also want to disable the
tracing  at the right moment and capture a snapshot from within kernel
to make sure we have the relevant diagnostics data and nothing is
overwritten or lost.


Note: The additional logging is not part of the kernel. We intend to
only provide the flexibility to add the logging as part of diagnostics
via ksplice/live-patch on need-basis.


Please find below the compilation of APIs to be introduced or exported as is.


We propose adding two new functions:

1. struct trace_array *trace_array_create(const char *name);
2. int trace_array_destroy(struct trace_array *tr);


In addition, we need to export functions:

3. int trace_array_printk(struct trace_array *tr, unsigned long ip,
 const char *fmt, ...);
4. int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
5. void trace_printk_init_buffers(void);


To workaround the redundancy due to the newly introduced APIs, we propose the
following restructuring -

1. Move the contents of instance_mkdir to the new API.
static int instance_mkdir(const char *name)
{
 return PTR_ERR_OR_ZERO(trace_array_create(name));
}

2. Introduce internal static function: __remove_instance(struct trace_array *tr)
This will be almost similar to old instance_rmdir which
identified the trace_array to be removed based on the name.

Modify existing API to use the internal function:
static int instance_rmdir(const char *name)
{
 struct trace_array *tr;
 int err = -ENODEV;

 mutex_lock(_mutex);
 mutex_lock(_types_lock);

 list_for_each_entry(tr, _trace_arrays, list) {
 if (tr->name && strcmp(tr->name, name) == 0) {
 err = __remove_instance(tr);
 break;
 }
 }

 mutex_unlock(_types_lock);
 mutex_unlock(_mutex);

 return err;
}

New API to be exported:
int trace_array_destroy(struct trace_array *tr)
{
 int err;

 mutex_lock(_mutex);
 mutex_lock(_types_lock);
 err = __remove_instance(tr);
 mutex_unlock(_types_lock);
 mutex_unlock(_mutex);

 return err;
}



Thanks,
Divya 


Re: [PATCH v4 1/4] dt: lm3532: Add lm3532 dt doc and update ti_lmu doc

2019-03-15 Thread Rob Herring
On Wed, Mar 13, 2019 at 07:32:46AM -0500, Dan Murphy wrote:
> Add the lm3532 device tree documentation.
> Remove lm3532 device tree reference from the ti_lmu devicetree
> documentation.
> 
> With the addition of the dedicated lm3532 documentation the device
> can be removed from the ti_lmu.txt.
> 
> The reason for this is that the lm3532 dt documentation now defines
> the ability to control LED output strings against different control
> banks or groups multiple strings to be controlled by a single control
> bank.
> 
> Another addition was for ALS lighting control and configuration.  The
> LM3532 has a feature that can take in the ALS reading from 2 separate
> ALS devices and adjust the brightness on the strings that are configured
> to support this feature.
> 
> Finally the device specific properties were moved to the parent node as these
> properties are not control bank configurable.  These include the runtime ramp
> and the ALS configuration.
> 
> Signed-off-by: Dan Murphy 
> ---
> 
> v4 - Appended "ti," to TI specific properties, add enable gpio documentation,
> removed an example, moved ramp to optional parent properties - 
> https://lore.kernel.org/patchwork/patch/1050122/
> 
> v3 - No changes - https://lore.kernel.org/patchwork/patch/1049026/
> v2 - Fixed ramp-up and ramp-down properties, removed hard coded property 
> values,
> added ranges for variable properties, I did not change the label - 
> https://lore.kernel.org/patchwork/patch/1048805/
> 
> 
>  .../devicetree/bindings/leds/leds-lm3532.txt  | 101 ++
>  .../devicetree/bindings/mfd/ti-lmu.txt|  20 
>  2 files changed, 101 insertions(+), 20 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/leds/leds-lm3532.txt
> 
> diff --git a/Documentation/devicetree/bindings/leds/leds-lm3532.txt 
> b/Documentation/devicetree/bindings/leds/leds-lm3532.txt
> new file mode 100644
> index ..ba793ef9b3b6
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/leds/leds-lm3532.txt
> @@ -0,0 +1,101 @@
> +* Texas Instruments - lm3532 White LED driver with ambient light sensing
> +capability.
> +
> +The LM3532 provides the 3 high-voltage, low-side current sinks. The device is
> +programmable over an I2C-compatible interface and has independent
> +current control for all three channels. The adaptive current regulation
> +method allows for different LED currents in each current sink thus allowing
> +for a wide variety of backlight and keypad applications.
> +
> +The main features of the LM3532 include dual ambient light sensor inputs
> +each with 32 internal voltage setting resistors, 8-bit logarithmic and linear
> +brightness control, dual external PWM brightness control inputs, and up to
> +1000:1 dimming ratio with programmable fade in and fade out settings.
> +
> +Required properties:
> + - compatible : "ti,lm3532"
> + - reg : I2C slave address
> + - #address-cells : 1
> + - #size-cells : 0
> +
> +Optional properties:
> + - enable-gpios : gpio pin to enable (active high)/disable the device.
> + Range for ramp settings: 8us - 65536us

This should be after the 2 ramp properties.

With that,

Reviewed-by: Rob Herring 
 
> + - ramp-up-us - The Run time ramp rates/step are from one current
> +set-point to another after the device has reached its
> +initial target set point from turn-on
> + - ramp-down-us - The Run time ramp rates/step are from one current
> +  set-point to another after the device has reached its
> +  initial target set point from turn-on


Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread Matthias Kaehlcke
Hi Peter,

On Fri, Mar 15, 2019 at 03:08:57PM -0700, h...@zytor.com wrote:
> On March 15, 2019 3:06:37 PM PDT, Nick Desaulniers  
> wrote:
> >On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke 
> >wrote:
> >>
> >> The compiler may emit calls to __lshrti3 from the compiler runtime
> >> library, which results in undefined references:
> >>
> >> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
> >>   include/linux/math64.h:186: undefined reference to `__lshrti3'
> >
> >Looks like Clang will emit this at -Oz (but not -O2):
> >https://godbolt.org/z/w1_2YC
> >
> >>
> >> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
> >
> >Has it changed since? If so why not a newer version of libgcc_s?
> >
> >>
> >> Include the function for x86 builds with clang, which is the
> >> environment where the above error was observed.
> >>
> >> Signed-off-by: Matthias Kaehlcke 
> >> ---
> >>  arch/x86/Kconfig   |  1 +
> >>  include/linux/libgcc.h | 16 
> >>  lib/Kconfig|  3 +++
> >>  lib/Makefile   |  1 +
> >>  lib/lshrti3.c  | 31 +++
> >>  5 files changed, 52 insertions(+)
> >>  create mode 100644 lib/lshrti3.c
> >>
> >> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> >> index c1f9b3cf437c..a5e0d923845d 100644
> >> --- a/arch/x86/Kconfig
> >> +++ b/arch/x86/Kconfig
> >> @@ -105,6 +105,7 @@ config X86
> >> select GENERIC_IRQ_PROBE
> >> select GENERIC_IRQ_RESERVATION_MODE
> >> select GENERIC_IRQ_SHOW
> >> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
> >> select GENERIC_PENDING_IRQ  if SMP
> >> select GENERIC_SMP_IDLE_THREAD
> >> select GENERIC_STRNCPY_FROM_USER
> >> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
> >> index 32e1e0f4b2d0..a71036471838 100644
> >> --- a/include/linux/libgcc.h
> >> +++ b/include/linux/libgcc.h
> >> @@ -22,15 +22,26 @@
> >>  #include 
> >>
> >>  typedef int word_type __attribute__ ((mode (__word__)));
> >> +typedef int TItype __attribute__ ((mode (TI)));
> >
> >Well that's an interesting new compiler attribute.
> >https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
> >Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
> >typedef int TItype __mode(TI);
> >
> >>
> >>  #ifdef __BIG_ENDIAN
> >>  struct DWstruct {
> >> int high, low;
> >>  };
> >> +
> >> +struct DWstruct128 {
> >> +   long long high, low;
> >> +};
> >> +
> >>  #elif defined(__LITTLE_ENDIAN)
> >>  struct DWstruct {
> >> int low, high;
> >>  };
> >> +
> >> +struct DWstruct128 {
> >> +   long long low, high;
> >> +};
> >> +
> >>  #else
> >>  #error I feel sick.
> >>  #endif
> >> @@ -40,4 +51,9 @@ typedef union {
> >> long long ll;
> >>  } DWunion;
> >>
> >> +typedef union {
> >> +   struct DWstruct128 s;
> >> +   TItype ll;
> >> +} DWunion128;
> >> +
> >>  #endif /* __ASM_LIBGCC_H */
> >> diff --git a/lib/Kconfig b/lib/Kconfig
> >> index a9e56539bd11..369e10259ea6 100644
> >> --- a/lib/Kconfig
> >> +++ b/lib/Kconfig
> >> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
> >>  config GENERIC_LIB_LSHRDI3
> >> bool
> >>
> >> +config GENERIC_LIB_LSHRTI3
> >> +   bool
> >> +
> >>  config GENERIC_LIB_MULDI3
> >> bool
> >>
> >> diff --git a/lib/Makefile b/lib/Makefile
> >> index 4e066120a0d6..42648411f451 100644
> >> --- a/lib/Makefile
> >> +++ b/lib/Makefile
> >> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
> >>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
> >>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
> >>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
> >> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
> >>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
> >>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
> >>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
> >> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
> >> new file mode 100644
> >> index ..2d2123bb3030
> >> --- /dev/null
> >> +++ b/lib/lshrti3.c
> >> @@ -0,0 +1,31 @@
> >> +// SPDX-License-Identifier: GPL-2.0
> >> +
> >> +#include 
> >> +#include 
> >> +
> >> +long long __lshrti3(long long u, word_type b)
> >> +{
> >> +   DWunion128 uu, w;
> >> +   word_type bm;
> >> +
> >> +   if (b == 0)
> >> +   return u;
> >> +
> >> +   uu.ll = u;
> >> +   bm = 64 - b;
> >> +
> >> +   if (bm <= 0) {
> >> +   w.s.high = 0;
> >> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
> >> +   } else {
> >> +   const unsigned long long carries =
> >> +   (unsigned long long) uu.s.high << bm;
> >> +   w.s.high = (unsigned long long) uu.s.high >> b;
> >> +   w.s.low = ((unsigned long long) uu.s.low >> b) |
> >carries;
> >> +   }
> >> +
> >> +   return w.ll;
> >> +}
> >> +#ifndef BUILD_VDSO
> >> +EXPORT_SYMBOL(__lshrti3);
> >> +#endif
> >
> >I don't think you want this.  Maybe 

Re: [PATCH v1 0/3] perf: Support a new coresum event qualifier

2019-03-15 Thread Jin, Yao




On 3/16/2019 7:26 AM, Andi Kleen wrote:

Yes, the coresum's behavior is similar as --per-core option, just supports
at the event level. I'm OK with calling it 'per-core'.

For example,
perf stat -e cpu/event=0,umask=0x3,per-core=1/


Please use percore, the - would need to be escaped in metric expressions.

-Andi



Oh, yes, thanks for reminding. Will use 'percore' in next version.

Thanks
Jin Yao


Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread Matthias Kaehlcke
On Fri, Mar 15, 2019 at 03:06:37PM -0700, 'Nick Desaulniers' via Clang Built 
Linux wrote:
> On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke  wrote:
> >
> > The compiler may emit calls to __lshrti3 from the compiler runtime
> > library, which results in undefined references:
> >
> > arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
> >   include/linux/math64.h:186: undefined reference to `__lshrti3'
> 
> Looks like Clang will emit this at -Oz (but not -O2):
> https://godbolt.org/z/w1_2YC
> 
> >
> > Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
> 
> Has it changed since? If so why not a newer version of libgcc_s?

Our compiler folks who maintain this gcc version dug this up for
me. In the gcc sources there is no direct implementation of __lshrti3,
I was told it is somehow derived from __lshrdi3.

> > Include the function for x86 builds with clang, which is the
> > environment where the above error was observed.
> >
> > Signed-off-by: Matthias Kaehlcke 
> > ---
> >  arch/x86/Kconfig   |  1 +
> >  include/linux/libgcc.h | 16 
> >  lib/Kconfig|  3 +++
> >  lib/Makefile   |  1 +
> >  lib/lshrti3.c  | 31 +++
> >  5 files changed, 52 insertions(+)
> >  create mode 100644 lib/lshrti3.c
> >
> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> > index c1f9b3cf437c..a5e0d923845d 100644
> > --- a/arch/x86/Kconfig
> > +++ b/arch/x86/Kconfig
> > @@ -105,6 +105,7 @@ config X86
> > select GENERIC_IRQ_PROBE
> > select GENERIC_IRQ_RESERVATION_MODE
> > select GENERIC_IRQ_SHOW
> > +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
> > select GENERIC_PENDING_IRQ  if SMP
> > select GENERIC_SMP_IDLE_THREAD
> > select GENERIC_STRNCPY_FROM_USER
> > diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
> > index 32e1e0f4b2d0..a71036471838 100644
> > --- a/include/linux/libgcc.h
> > +++ b/include/linux/libgcc.h
> > @@ -22,15 +22,26 @@
> >  #include 
> >
> >  typedef int word_type __attribute__ ((mode (__word__)));
> > +typedef int TItype __attribute__ ((mode (TI)));
> 
> Well that's an interesting new compiler attribute.
> https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
> Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
> typedef int TItype __mode(TI);

ok

> >  #ifdef __BIG_ENDIAN
> >  struct DWstruct {
> > int high, low;
> >  };
> > +
> > +struct DWstruct128 {
> > +   long long high, low;
> > +};
> > +
> >  #elif defined(__LITTLE_ENDIAN)
> >  struct DWstruct {
> > int low, high;
> >  };
> > +
> > +struct DWstruct128 {
> > +   long long low, high;
> > +};
> > +
> >  #else
> >  #error I feel sick.
> >  #endif
> > @@ -40,4 +51,9 @@ typedef union {
> > long long ll;
> >  } DWunion;
> >
> > +typedef union {
> > +   struct DWstruct128 s;
> > +   TItype ll;
> > +} DWunion128;
> > +
> >  #endif /* __ASM_LIBGCC_H */
> > diff --git a/lib/Kconfig b/lib/Kconfig
> > index a9e56539bd11..369e10259ea6 100644
> > --- a/lib/Kconfig
> > +++ b/lib/Kconfig
> > @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
> >  config GENERIC_LIB_LSHRDI3
> > bool
> >
> > +config GENERIC_LIB_LSHRTI3
> > +   bool
> > +
> >  config GENERIC_LIB_MULDI3
> > bool
> >
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 4e066120a0d6..42648411f451 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
> >  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
> >  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
> >  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
> > +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
> >  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
> >  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
> >  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
> > diff --git a/lib/lshrti3.c b/lib/lshrti3.c
> > new file mode 100644
> > index ..2d2123bb3030
> > --- /dev/null
> > +++ b/lib/lshrti3.c
> > @@ -0,0 +1,31 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include 
> > +#include 
> > +
> > +long long __lshrti3(long long u, word_type b)

This signature matches with the gcc documentation
(https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html),
however the gcc implementation of the function has 128-bit values as
input/output, so I guess to meet gcc's expectations the 'long long's
need to be changed to TItype.

> > +{
> > +   DWunion128 uu, w;
> > +   word_type bm;
> > +
> > +   if (b == 0)
> > +   return u;
> > +
> > +   uu.ll = u;
> > +   bm = 64 - b;
> > +
> > +   if (bm <= 0) {
> > +   w.s.high = 0;
> > +   w.s.low = (unsigned long long) uu.s.high >> -bm;
> > +   } else {
> > +   const unsigned long long carries =
> > +   (unsigned long long) uu.s.high << bm;
> > +   w.s.high = (unsigned long 

[GIT PULL] AFS fixes and other bits

2019-03-15 Thread David Howells
Hi Linus,

Here's a set of fixes and other bits for AFS to improve the life of desktop
applications such as firefox.  It makes the following improvements/fixes:

 (1) Fix file locking to allow fine-grained locking, as required by firefox
 and sqlite, with the caveat that you can't get a partial write lock on
 a file if you first get a partial read lock on it as the AFS protocol
 only supports whole-file locks.

 [At some point I need to look at how best to emulate OpenAFS's
 behaviour whereby all partial locks are just granted without reference
 to the kernel lock - maybe with some sort of mount parameter to enable
 it.]

 (2) Fix the way the server lock, once obtained, is distributed to the
 local processes waiting for it, thereby making sure they wait if they
 can't be immediately granted a local lock.

 (3) Fix the nonappearance of afs locks in /proc/locks.

 (4) Fix the handling of asynchronous file lock RPC operation failure on
 files that get deleted whilst the lock is being extended or released.

 (5) Implement silly-rename.

 (6) Fix the file lock expiry calculation to be based on the time the set-
 or extend-lock reply is seen (packet timestamp) rather than by the
 time at which we've done processing the operation (wallclock time) to
 allow for delays in processing.

 (7) Split the synchronous wait out of the client call dispatcher to make
 it possible to convert synchronous calls into async calls in the event
 of a signal.

The series also:

 (1) Adds/modifies a number of tracepoints, mostly related to file locking
 and silly rename.

 (2) Provides a more comprehensive data dump in the event that a directory
 content check fails.

David
---
The following changes since commit ebc551f2b8f905eca0e25c476c1e5c098cd92103:

  Merge tag 'nfsd-5.1' of git://linux-nfs.org/~bfields/linux (2019-03-12 
15:06:54 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git 
tags/afs-fixes-20190315

for you to fetch changes up to 78cf74c367eb608e8a15167da5aeae2c8abed902:

  afs: Add more tracepoints (2019-03-15 22:06:31 +)


AFS fixes


David Howells (10):
  afs: Split wait from afs_make_call()
  afs: Calculate lock extend timer from set/extend reply reception
  afs: Fix AFS file locking to allow fine grained locks
  afs: Further fix file locking
  afs: Add file locking tracepoints
  afs: Improve dir check failure reports
  afs: Handle lock rpc ops failing on a file that got deleted
  afs: Add directory reload tracepoint
  afs: Implement sillyrename for unlink and rename
  afs: Add more tracepoints

 fs/afs/Makefile|   1 +
 fs/afs/dir.c   | 161 +++--
 fs/afs/dir_silly.c | 239 +++
 fs/afs/flock.c | 569 +++--
 fs/afs/fs_probe.c  |  13 +-
 fs/afs/fsclient.c  |  92 +---
 fs/afs/inode.c |   2 +
 fs/afs/internal.h  |  25 +-
 fs/afs/rxrpc.c |  33 ++-
 fs/afs/super.c |   5 +-
 fs/afs/vl_probe.c  |  14 +-
 fs/afs/vlclient.c  |  26 ++-
 fs/afs/yfsclient.c |  72 --
 include/linux/fs.h |   1 +
 include/trace/events/afs.h | 348 ++-
 15 files changed, 1258 insertions(+), 343 deletions(-)
 create mode 100644 fs/afs/dir_silly.c


Re: [PATCH v1 0/3] perf: Support a new coresum event qualifier

2019-03-15 Thread Andi Kleen
> Yes, the coresum's behavior is similar as --per-core option, just supports
> at the event level. I'm OK with calling it 'per-core'.
> 
> For example,
> perf stat -e cpu/event=0,umask=0x3,per-core=1/

Please use percore, the - would need to be escaped in metric expressions.

-Andi


Re: [PATCH v5 03/12] dt-bindings: mtd: ingenic: Use standard ecc-engine property

2019-03-15 Thread Rob Herring
On Wed, 13 Mar 2019 23:22:50 +0100, Paul Cercueil wrote:
> The 'ingenic,bch-controller' property is now deprecated and the
> 'ecc-engine' property should be used instead.
> 
> Signed-off-by: Paul Cercueil 
> ---
> 
> Notes:
> v5: New patch
> 
>  Documentation/devicetree/bindings/mtd/ingenic,jz4780-nand.txt | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 

Reviewed-by: Rob Herring 


Re: [PATCH 3/3] RISC-V: Allow booting kernel from any 4KB aligned address

2019-03-15 Thread Anup Patel
On Fri, Mar 15, 2019 at 9:52 PM Anup Patel  wrote:
>
> On Fri, Mar 15, 2019 at 9:28 PM Mike Rapoport  wrote:
> >
> > On Thu, Mar 14, 2019 at 11:28:32PM +0530, Anup Patel wrote:
> > > On Thu, Mar 14, 2019 at 12:23 PM Mike Rapoport  wrote:
> > > >
> > > > On Thu, Mar 14, 2019 at 02:36:01AM +0530, Anup Patel wrote:
> > > > > On Thu, Mar 14, 2019 at 12:01 AM Mike Rapoport  
> > > > > wrote:
> > > > > >
> > > > > > On Tue, Mar 12, 2019 at 10:08:22PM +, Anup Patel wrote:
> > > > > > > Currently, we have to boot RISCV64 kernel from a 2MB aligned 
> > > > > > > physical
> > > > > > > address and RISCV32 kernel from a 4MB aligned physical address. 
> > > > > > > This
> > > > > > > constraint is because initial pagetable setup (i.e. setup_vm()) 
> > > > > > > maps
> > > > > > > entire RAM using hugepages (i.e. 2MB for 3-level pagetable and 
> > > > > > > 4MB for
> > > > > > > 2-level pagetable).
> > > > > > >
> > > > > > > Further, the above booting contraint also results in memory 
> > > > > > > wastage
> > > > > > > because if we boot kernel from some  address (which is not 
> > > > > > > same as
> > > > > > > RAM start address) then RISCV kernel will map PAGE_OFFSET virtual 
> > > > > > > address
> > > > > > > lineraly to  physical address and memory between RAM start 
> > > > > > > and 
> > > > > > > will be reserved/unusable.
> > > > > > >
> > > > > > > For example, RISCV64 kernel booted from 0x8020 will waste 2MB 
> > > > > > > of RAM
> > > > > > > and RISCV32 kernel booted from 0x8040 will waste 4MB of RAM.
> > > > > > >
> > > > > > > This patch re-writes the initial pagetable setup code to allow 
> > > > > > > booting
> > > > > > > RISV32 and RISCV64 kernel from any 4KB (i.e. PAGE_SIZE) aligned 
> > > > > > > address.
> > > > > > >
> > > > > > > To achieve this:
> > > > > > > 1. We map kernel, dtb and only some amount of RAM (few MBs) using 
> > > > > > > 4KB
> > > > > > >mappings in setup_vm() (called from head.S)
> > > > > > > 2. Once we reach paging_init() (called from setup_arch()) after
> > > > > > >memblock setup, we map all available memory banks using 4KB
> > > > > > >mappings and memblock APIs.
> > > > > >
> > > > > > I'm not really familiar with RISC-V, but my guess would be that 
> > > > > > you'd get
> > > > > > worse TLB performance with 4KB mappings. Not mentioning the amount 
> > > > > > of
> > > > > > memory required for the page table itself.
> > > > >
> > > > > I agree we will see a hit in TLB performance due to 4KB mappings.
> > > > >
> > > > > To address this we can create, 2MB (or 4MB on 32bit system) mappings
> > > > > whenever load_pa is aligned to it otherwise we prefer 4KB mappings. 
> > > > > In other
> > > > > words, we create bigger mappings whenever possible and fallback to 4KB
> > > > > mappings when not possible.
> > > > >
> > > > > This way if kernel is booted from 2MB (or 4MB) aligned address then 
> > > > > we will
> > > > > see good TLB performance for kernel addresses. Also, users are still 
> > > > > free to
> > > > > boot Linux RISC-V kernel from any 4KB aligned address.
> > > > >
> > > > > Of course, we will have to document this as part of Linux RISC-V 
> > > > > booting
> > > > > requirements under Documentation/ (which does not exist currently).
> > > > >
> > > > > >
> > > > > > If the only goal is to utilize the physical memory below the 
> > > > > > kernel, it
> > > > > > simply should not be reserved at the first place, something like:
> > > > >
> > > > > Well, our goal was two-fold:
> > > > >
> > > > > 1. We wanted to unify boot-time alignment requirements for 32bit and
> > > > > 64bit RISC-V systems
> > > >
> > > > Can't they both start from 4MB aligned address provided the memory below
> > > > the kernel can be freed?
> > >
> > > Yes, they can both start from 4MB aligned address.
> > >
> > > >
> > > > > 2. Save memory by allowing users to place kernel just after the 
> > > > > runtime
> > > > > firmware at starting of RAM.
> > > >
> > > > If the firmware should be alive after kernel boot, it's memory is the 
> > > > only
> > > > part that should be reserved below the kernel. Otherwise, the entire 
> > > > region
> > > >  -  can be free.
> > > >
> > > > Using 4K pages for the swapper_pg_dir is quite a change and I'm not
> > > > convinced its really justified.
> > >
> > > I understand your concern about TLB performance and more page
> > > tables.
> > >
> > > Not just 2MB/4MB mappings, we should be able to create even 1GB
> > > mappings as well for good TLB performance.
> > >
> > > I suggest we should use best possible mapping size (4KB, 2MB, or
> > > 1GB) based on alignment of kernel load address. This way users can
> > > boot from any 4KB aligned address and setup_vm() will try to use
> > > biggest possible mapping size.
> > >
> > > For example, If the kernel load address is aligned to 2MB then we 2MB
> > > mappings bigger mappings and use fewer page tables. Same thing
> > > possible for 1GB mappings as well.
> >
> > I still don't get 

Re: [PATCH v2 0/4] Patches to allow consistent mmc / mmcblk numbering w/ device tree

2019-03-15 Thread Doug Anderson
Hi,

On Fri, Mar 15, 2019 at 4:00 PM Marek Vasut  wrote:
>
> > Completely agree here - we need a dt solution that allows us to
> > specify ordering.
>
> Nope, ordering would be a policy and does not describe hardware, thus it
> shouldn't be in the DT. Use UUID or PARTUUID, they apply both to raw FS
> (fsuuid) and to partitions (part uuid). Linux kernel can mount FS using
> PARTUUID, to support UUID you need initramfs.

Two thoughts about that:

1. Some amount of policy is allowed in device tree.  At some point in
time there was a big discussion about the need for a separate "config
tree" that was totally parallel to the device tree so we could put
policy stuff in that.  Nobody wanted that and (as I recall) it was
agreed that in some cases policy could go there if that policy
expressed policy that was the generic intent of how the board ought to
be run.  I believe this is how things like the assigned-clocks is
justified.

2. In some cases this number does describe the hardware.  You look at
the hardware reference manual and see that there are 3 MMC
controllers: 0, 1, and 2.  In such cases it seems like it's an OK
description of the hardware to encode this info into the DTS.

...from what I recall, one big objection is for SoCs that didn't just
have numbers for their controllers.  AKA I think some SoCs might call
their controllers the "eMMC" controller, the "SD" controller, and the
"SDIO" controller.  They may be nearly the same hardware, but perhaps
the SoC allows for a GPIO interrupt on the SDIO controller and perhaps
the eMMC controller exposes the strobe line or has an 8-bit wide
datapath.  In this case making up numbers does become a bit more
arbitrary and folks didn't like it.

IIRC there was general consensus that it'd be OK to somehow specify a
string (AKA non-numeric) name for different SD controllers.  I don't
have pointers to that conversation offhand and it's possible I
imagined it.


-Doug


Re: [PATCH v5 1/3] dt-bindings: phy: Add Stingray USB PHY binding document

2019-03-15 Thread Rob Herring
On Tue, Mar 12, 2019 at 09:36:19PM +0530, Srinath Mannam wrote:
> Add DT binding document for Stingray USB PHY.
> 
> Signed-off-by: Srinath Mannam 
> ---
>  .../bindings/phy/brcm,stingray-usb-phy.txt | 40 
> ++
>  1 file changed, 40 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt
> 
> diff --git a/Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt 
> b/Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt
> new file mode 100644
> index 000..51c3d73
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/brcm,stingray-usb-phy.txt
> @@ -0,0 +1,40 @@
> +Broadcom Stingray USB PHY
> +
> +Required properties:
> + - compatible : should be one of the listed compatibles
> + - "brcm,sr-usb-combo-phy" is combo PHY has two PHYs, one SS and one HS.
> + - "brcm,sr-usb-hs-phy" is a single HS PHY.
> + - reg: offset and length of the PHY blocks registers

> + - address-cells: should be 1
> + - size-cells: should be 0

These can be dropped now. With that,

Reviewed-by: Rob Herring 

> + - #phy-cells:
> +   - Must be 1 for brcm,sr-usb-combo-phy as it expects one argument to 
> indicate
> + the PHY number of two PHYs. 0 for HS PHY and 1 for SS PHY.
> +   - Must be 0 for brcm,sr-usb-hs-phy.
> +
> +Refer to phy/phy-bindings.txt for the generic PHY binding properties
> +
> +Example:
> + usbphy0: usb-phy@0 {
> + compatible = "brcm,sr-usb-combo-phy";
> + reg = <0x 0x100>;
> + #address-cells = <1>;
> + #size-cells = <0>;
> + #phy-cells = <1>;
> + };
> +
> + usbphy1: usb-phy@1 {
> + compatible = "brcm,sr-usb-combo-phy";
> + reg = <0x0001 0x100>,
> + #address-cells = <1>;
> + #size-cells = <0>;
> + #phy-cells = <1>;
> + };
> +
> + usbphy2: usb-phy@2 {
> + compatible = "brcm,sr-usb-hs-phy";
> + reg = <0x0002 0x100>,
> + #address-cells = <1>;
> + #size-cells = <0>;
> + #phy-cells = <0>;
> + };
> -- 
> 2.7.4
> 


Re: [PATCH] x86/vdso: include generic __lshrdi3 in 32-bit vDSO

2019-03-15 Thread hpa
On March 15, 2019 3:29:06 PM PDT, Matthias Kaehlcke  wrote:
>Hi Nick,
>
>On Fri, Mar 15, 2019 at 02:31:09PM -0700, 'Nick Desaulniers' via Clang
>Built Linux wrote:
>> On Fri, Mar 15, 2019 at 12:54 PM Matthias Kaehlcke 
>wrote:
>> >
>> > Building the 32-bit vDSO with a recent clang version fails due
>> > to undefined symbols:
>> >
>> > arch/x86/entry/vdso/vdso32.so.dbg: undefined symbols found
>> >
>> > The undefined symbol in this case is __lshrdi3, which is part of
>> > the compiler runtime library, however the vDSO isn't linked against
>> > this library.
>> >
>> > Include the kernel version of __lshrdi3 in the 32-bit vDSO build.
>> 
>> __lshrdi3 is used for "logical shift right double-word by int" (best
>> guess), so anywhere there's a right shift of a u64.  Looks like
>> there's a few of these in arch/x86/entry/vdso/, so it's legal for the
>> compiler to emit this libcall.  Do you know which function
>> specifically in the .so has a relocation referencing __lshrdi3
>> specifically?
>
>It's the right shifts in do_realtime() and do_monotonic().
>
>> Is there a config I can set to reproduce this, in order to help
>> test?
>
>I encountered it with a Chrome OS specific configuration, but a
>defconfig should do. Note that you probably need a development version
>of clang to reproduce this.
>
>> >
>> > Signed-off-by: Matthias Kaehlcke 
>> > ---
>> >  arch/x86/entry/vdso/Makefile | 7 ++-
>> >  lib/lshrdi3.c| 4 +++-
>> >  2 files changed, 9 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/arch/x86/entry/vdso/Makefile
>b/arch/x86/entry/vdso/Makefile
>> > index 5bfe2243a08f..7517cd87e10b 100644
>> > --- a/arch/x86/entry/vdso/Makefile
>> > +++ b/arch/x86/entry/vdso/Makefile
>> > @@ -144,6 +144,7 @@ KBUILD_CFLAGS_32 += $(call cc-option,
>-fno-stack-protector)
>> >  KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
>> >  KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
>> >  KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
>> > +KBUILD_CFLAGS_32 += -DBUILD_VDSO
>> >
>> >  ifdef CONFIG_RETPOLINE
>> >  ifneq ($(RETPOLINE_VDSO_CFLAGS),)
>> > @@ -153,12 +154,16 @@ endif
>> >
>> >  $(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
>> >
>> > +$(obj)/vdso32/lshrdi3.o: $(srctree)/lib/lshrdi3.c FORCE
>> > +   $(call if_changed_rule,cc_o_c)
>> 
>> + Masahiro to help look at this part (I don't understand this part
>> of kbuild).
>
>I bluntly stole that from arch/x86/purgatory/Makefile , which does
>something similar.
>
>> 
>> > +
>> >  $(obj)/vdso32.so.dbg: FORCE \
>> >   $(obj)/vdso32/vdso32.lds \
>> >   $(obj)/vdso32/vclock_gettime.o \
>> >   $(obj)/vdso32/note.o \
>> >   $(obj)/vdso32/system_call.o \
>> > - $(obj)/vdso32/sigreturn.o
>> > + $(obj)/vdso32/sigreturn.o \
>> > + $(obj)/vdso32/lshrdi3.o
>> > $(call if_changed,vdso)
>> >
>> >  #
>> > diff --git a/lib/lshrdi3.c b/lib/lshrdi3.c
>> > index 99cfa5721f2d..8a4fc6bcf3a4 100644
>> > --- a/lib/lshrdi3.c
>> > +++ b/lib/lshrdi3.c
>> > @@ -16,7 +16,7 @@
>> >   * to the Free Software Foundation, Inc.
>> >   */
>> >
>> > -#include 
>> > +#include 
>> 
>> Is this a simple cleanup, or?
>
>The vDSO build is unhappy when modules.h draws in a whole bunch of
>other kernel headers and export.h is all that's need. It seemed
>reasonable to do the 'cleanup' in this patch since we touch it anyway
>to place EXPORT_SYMBOL within an #ifdef.
>
>> >  #include 
>> >
>> >  long long notrace __lshrdi3(long long u, word_type b)
>> > @@ -42,4 +42,6 @@ long long notrace __lshrdi3(long long u,
>word_type b)
>> >
>> > return w.ll;
>> >  }
>> > +#ifndef BUILD_VDSO
>> >  EXPORT_SYMBOL(__lshrdi3);
>> > +#endif
>> 
>> Compilers (GCC and Clang) will always assume their runtime has these
>> helper functions; whether or not they emit libcalls vs inline
>routines
>> is implementation defined.  So I agree with this patch; I just would
>> like to help confirm/test it.
>
>Thanks for your help!
>
>Matthias

Note: it is also probably no reason to use -Os/-Oz for the vdso.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: [PATCH net] net: phy: Don't assume loopback is supported

2019-03-15 Thread Heiner Kallweit
On 14.03.2019 11:37, Jose Abreu wrote:
> Some PHYs may not support loopback mode so we need to check if register
> is read-only.
> 
As I read Clause 22 this is a mandatory feature, the related bit is
specified as R/W. Do you have an actual example of a PHY w/o loopback
mode that doesn't allow to change this bit?

> Fixes: f0f9b4ed2338 ("net: phy: Add phy loopback support in net phy 
> framework")
> Signed-off-by: Jose Abreu 
> Cc: Andrew Lunn 
> Cc: Florian Fainelli 
> Cc: "David S. Miller" 
> Cc: Joao Pinto 
> ---
>  drivers/net/phy/phy_device.c | 20 ++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 49fdd1ee798e..a749639d98c3 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1918,8 +1918,24 @@ EXPORT_SYMBOL(genphy_resume);
>  
>  int genphy_loopback(struct phy_device *phydev, bool enable)
>  {
> - return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
> -   enable ? BMCR_LOOPBACK : 0);
> + int ret;
> +
> + ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
> +  enable ? BMCR_LOOPBACK : 0);
> + if (ret < 0)
> + return ret;
> +
> + ret = phy_read(phydev, MII_BMCR);
> + if (ret < 0)
> + return ret;
> +
> + if (enable) {
> + if (ret & BMCR_LOOPBACK)
> + return 0;
> + return -EOPNOTSUPP;
> + }
> +
> + return 0;
>  }
>  EXPORT_SYMBOL(genphy_loopback);
>  
> 



Re: [PATCH v2 0/4] Patches to allow consistent mmc / mmcblk numbering w/ device tree

2019-03-15 Thread Tim Harvey
Tim Harvey - Principal Software EngineerGateworks Corporation -
http://www.gateworks.com/3026 S. Higuera St. San Luis Obispo CA
93401805-781-2000
On Fri, Mar 15, 2019 at 4:00 PM Marek Vasut  wrote:
>
> On 3/15/19 10:52 PM, Tim Harvey wrote:
> > Tim Harvey - Principal Software EngineerGateworks Corporation -
> > http://www.gateworks.com/3026 S. Higuera St. San Luis Obispo CA
> > 93401805-781-2000
> > On Tue, Mar 5, 2019 at 4:39 AM Måns Rullgård  wrote:
> >>
> >> Douglas Anderson  writes:
> >>
> >>> This series picks patches from various different places to produce what
> >>> I consider the best solution to getting consistent mmc and mmcblk
> >>> ordering.
> >>>
> >>> Why consistent ordering and why not just use UUIDs?  IMHO consistent
> >>> ordering solves a few different problems:
> >>>
> >>> 1. For poor, feeble-minded humans like me, have sane numbering for
> >>>devices helps a lot.  When grepping through dmesg it's terribly handy
> >>>if a given SDMMC device has a consistent number.  I know that I can
> >>>do "dmesg | grep mmc0" or "dmesg | grep mmcblk0" to find info about
> >>>the eMMC.  I know that I can do "dmesg | grep mmc1" to find info
> >>>about the SD card slot.  I don't want it to matter which one probed
> >>>first, I don't want it to matter if I'm working on a variant of the
> >>>hardware that has the SD card slot disabled, and I don't want to care
> >>>what my boot device was.  Worrying about what device number I got
> >>>increases my cognitive load.
> >>>
> >>> 2. There are cases where it's not trivially easy during development to
> >>>use the UUID.  Specifically I work a lot with coreboot / depthcharge
> >>>as a BIOS.  When configured properly, that BIOS has a nice feature to
> >>>allow you to fetch the kernel and kernel command line from TFTP by
> >>>pressing Ctrl-N.  In this particular case the BIOS doesn't actually
> >>>know which disk I'd like for my root filesystem, so it's not so easy
> >>>for it to put the right UUID into the command line.  For this
> >>>purpose, knowing that "mmcblk0" will always refer to eMMC is handy.
> >>>
> >>> Changes in v2:
> >>> - Rebased atop mmc-next
> >>> - Stat dynamic allocation after fixed allocation; thanks Wolfram!
> >>> - rk3288 patch new for v2
> >>>
> >>> Douglas Anderson (1):
> >>>   ARM: dts: rockchip: Add mmc aliases for rk3288 platform
> >>>
> >>> Jaehoon Chung (1):
> >>>   Documentation: mmc: Document mmc aliases
> >>>
> >>> Stefan Agner (2):
> >>>   mmc: read mmc alias from device tree
> >>>   mmc: use SD/MMC host ID for block device name ID
> >>>
> >>>  Documentation/devicetree/bindings/mmc/mmc.txt | 11 +++
> >>>  arch/arm/boot/dts/rk3288.dtsi |  4 
> >>>  drivers/mmc/card/block.c  |  2 +-
> >>>  drivers/mmc/core/host.c   | 17 -
> >>>  4 files changed, 32 insertions(+), 2 deletions(-)
> >>
> >> Did anyone ever come up with an acceptable solution for this?  After
> >> three years, I'm getting tired of rebasing these patches onto every new
> >> kernel.
> >>
> >> UUIDs or similar are NOT an option for multiple reasons:
> >>
> >> - We have two rootfs partitions for ping-pong updates, so simply
> >>   referring to "the thing with ID foo" doesn't work.
> >>
> >> - Installing said updates needs direct access the device/partition,
> >>   which may not even have a filesystem.
> >>
> >> - The u-boot environment is stored in an eMMC "boot" partition, and
> >>   userspace needs to know where to find it.
> >>
> >> I'm sure I'm not the only one in a similar situation.
> >>
> >> Russel, feel free to shout abuse at me.  I don't care, but it makes you
> >> look stupid.
> >>
> >
> > Completely agree here - we need a dt solution that allows us to
> > specify ordering.
>
> Nope, ordering would be a policy and does not describe hardware, thus it
> shouldn't be in the DT. Use UUID or PARTUUID, they apply both to raw FS
> (fsuuid) and to partitions (part uuid). Linux kernel can mount FS using
> PARTUUID, to support UUID you need initramfs.

Marek,

Sure... a 'policy' decision would be which bootable device to boot
from but the issue I see that needs solving is for the vendor to be
able to describe via dt what devices are bootable for MMC (an SDIO
wifi device is not bootable yet a eMMC/microSD is).

Isn't this exactly the same issue as what the stdout-path specifies in
the chosen node? Modern SoC's have multiple UART's yet boot firmware
needs to know which one is the serial console just like boot firmware
should be able to figure out what device or devices are bootable.

Perhaps we can add a 'bootdev-path' in the chosen node?

Regards,

Tim


Re: [PATCH v2 0/4] Patches to allow consistent mmc / mmcblk numbering w/ device tree

2019-03-15 Thread Marek Vasut
On 3/15/19 10:52 PM, Tim Harvey wrote:
> Tim Harvey - Principal Software EngineerGateworks Corporation -
> http://www.gateworks.com/3026 S. Higuera St. San Luis Obispo CA
> 93401805-781-2000
> On Tue, Mar 5, 2019 at 4:39 AM Måns Rullgård  wrote:
>>
>> Douglas Anderson  writes:
>>
>>> This series picks patches from various different places to produce what
>>> I consider the best solution to getting consistent mmc and mmcblk
>>> ordering.
>>>
>>> Why consistent ordering and why not just use UUIDs?  IMHO consistent
>>> ordering solves a few different problems:
>>>
>>> 1. For poor, feeble-minded humans like me, have sane numbering for
>>>devices helps a lot.  When grepping through dmesg it's terribly handy
>>>if a given SDMMC device has a consistent number.  I know that I can
>>>do "dmesg | grep mmc0" or "dmesg | grep mmcblk0" to find info about
>>>the eMMC.  I know that I can do "dmesg | grep mmc1" to find info
>>>about the SD card slot.  I don't want it to matter which one probed
>>>first, I don't want it to matter if I'm working on a variant of the
>>>hardware that has the SD card slot disabled, and I don't want to care
>>>what my boot device was.  Worrying about what device number I got
>>>increases my cognitive load.
>>>
>>> 2. There are cases where it's not trivially easy during development to
>>>use the UUID.  Specifically I work a lot with coreboot / depthcharge
>>>as a BIOS.  When configured properly, that BIOS has a nice feature to
>>>allow you to fetch the kernel and kernel command line from TFTP by
>>>pressing Ctrl-N.  In this particular case the BIOS doesn't actually
>>>know which disk I'd like for my root filesystem, so it's not so easy
>>>for it to put the right UUID into the command line.  For this
>>>purpose, knowing that "mmcblk0" will always refer to eMMC is handy.
>>>
>>> Changes in v2:
>>> - Rebased atop mmc-next
>>> - Stat dynamic allocation after fixed allocation; thanks Wolfram!
>>> - rk3288 patch new for v2
>>>
>>> Douglas Anderson (1):
>>>   ARM: dts: rockchip: Add mmc aliases for rk3288 platform
>>>
>>> Jaehoon Chung (1):
>>>   Documentation: mmc: Document mmc aliases
>>>
>>> Stefan Agner (2):
>>>   mmc: read mmc alias from device tree
>>>   mmc: use SD/MMC host ID for block device name ID
>>>
>>>  Documentation/devicetree/bindings/mmc/mmc.txt | 11 +++
>>>  arch/arm/boot/dts/rk3288.dtsi |  4 
>>>  drivers/mmc/card/block.c  |  2 +-
>>>  drivers/mmc/core/host.c   | 17 -
>>>  4 files changed, 32 insertions(+), 2 deletions(-)
>>
>> Did anyone ever come up with an acceptable solution for this?  After
>> three years, I'm getting tired of rebasing these patches onto every new
>> kernel.
>>
>> UUIDs or similar are NOT an option for multiple reasons:
>>
>> - We have two rootfs partitions for ping-pong updates, so simply
>>   referring to "the thing with ID foo" doesn't work.
>>
>> - Installing said updates needs direct access the device/partition,
>>   which may not even have a filesystem.
>>
>> - The u-boot environment is stored in an eMMC "boot" partition, and
>>   userspace needs to know where to find it.
>>
>> I'm sure I'm not the only one in a similar situation.
>>
>> Russel, feel free to shout abuse at me.  I don't care, but it makes you
>> look stupid.
>>
> 
> Completely agree here - we need a dt solution that allows us to
> specify ordering.

Nope, ordering would be a policy and does not describe hardware, thus it
shouldn't be in the DT. Use UUID or PARTUUID, they apply both to raw FS
(fsuuid) and to partitions (part uuid). Linux kernel can mount FS using
PARTUUID, to support UUID you need initramfs.

> I support a variety of IMX6 boards where for PCB routing reasons the
> bootable MMC device is not always the first sdhc (sometimes the first
> one is an SDIO radio for example). It seems ridiculous that I can't
> handle this with:
> 
> aliases {
> mmc0 =  /* MMC boot device */
> mmc1 =  /* SDIO radio */
> };
> 
> I see the imx6q-dhcom-som added in
> 52c7a088badd665a09ca9307ffa91e88d5686a7d re-defines the default
> imx6qdl.dtsi mmc0-mmc3 aiases but I don't see any handling of this in
> code anywhere - am I missing something?
> 
> Marek, why did you change the alias ordering for imx6q-dhcom-som.dtsi?
> (maybe your carrying around a patch to make this useful?)

Nope, likely a cleanup remnant which can be dropped.

> +   aliases {
> +   mmc0 = 
> +   mmc1 = 
> +   mmc2 = 
> +   mmc3 = 
> +   };
> 
> Regards,
> 
> Tim
> 


-- 
Best regards,
Marek Vasut


[PATCH 08/10] afs: Add directory reload tracepoint

2019-03-15 Thread David Howells
Add a tracepoint (afs_reload_dir) to indicate when a directory is being
reloaded.

Signed-off-by: David Howells 
---

 fs/afs/dir.c   |1 +
 include/trace/events/afs.h |   17 +
 2 files changed, 18 insertions(+)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 378a96a1116e..be5d2f932b77 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -309,6 +309,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode 
*dvnode, struct key *key)
goto error;
 
if (!test_bit(AFS_VNODE_DIR_VALID, >flags)) {
+   trace_afs_reload_dir(dvnode);
ret = afs_fetch_data(dvnode, key, req);
if (ret < 0)
goto error_unlock;
diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h
index 21b896fabb2f..8da9dd5bc2b6 100644
--- a/include/trace/events/afs.h
+++ b/include/trace/events/afs.h
@@ -947,6 +947,23 @@ TRACE_EVENT(afs_flock_op,
  __entry->from, __entry->len, __entry->flags)
);
 
+TRACE_EVENT(afs_reload_dir,
+   TP_PROTO(struct afs_vnode *vnode),
+
+   TP_ARGS(vnode),
+
+   TP_STRUCT__entry(
+   __field_struct(struct afs_fid,  fid )
+),
+
+   TP_fast_assign(
+   __entry->fid = vnode->fid;
+  ),
+
+   TP_printk("%llx:%llx:%x",
+ __entry->fid.vid, __entry->fid.vnode, __entry->fid.unique)
+   );
+
 #endif /* _TRACE_AFS_H */
 
 /* This part must be outside protection */



[PATCH 07/10] afs: Handle lock rpc ops failing on a file that got deleted

2019-03-15 Thread David Howells
Holding a file lock on an AFS file does not prevent it from being deleted
on the server, so we need to handle an error resulting from that when we
try setting, extending or releasing a lock.

Fix this by adding a "deleted" lock state and cancelling the lock extension
process for that file and aborting all waiters for the lock.

Fixes: 0fafdc9f888b ("afs: Fix file locking")
Reported-by: Jonathan Billings 
Signed-off-by: David Howells 
---

 fs/afs/flock.c |   62 ++--
 fs/afs/internal.h  |1 +
 include/trace/events/afs.h |7 -
 3 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index 2237ab4ea111..08b06f53a375 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -157,6 +157,28 @@ static void afs_next_locker(struct afs_vnode *vnode, int 
error)
_leave("");
 }
 
+/*
+ * Kill off all waiters in the the pending lock queue due to the vnode being
+ * deleted.
+ */
+static void afs_kill_lockers_enoent(struct afs_vnode *vnode)
+{
+   struct file_lock *p;
+
+   afs_set_lock_state(vnode, AFS_VNODE_LOCK_DELETED);
+
+   while (!list_empty(>pending_locks)) {
+   p = list_entry(vnode->pending_locks.next,
+  struct file_lock, fl_u.afs.link);
+   list_del_init(>fl_u.afs.link);
+   p->fl_u.afs.state = -ENOENT;
+   wake_up(>fl_wait);
+   }
+
+   key_put(vnode->lock_key);
+   vnode->lock_key = NULL;
+}
+
 /*
  * Get a lock on a file
  */
@@ -278,13 +300,19 @@ void afs_lock_work(struct work_struct *work)
/* attempt to release the server lock; if it fails, we just
 * wait 5 minutes and it'll expire anyway */
ret = afs_release_lock(vnode, vnode->lock_key);
-   if (ret < 0)
+   if (ret < 0) {
+   trace_afs_flock_ev(vnode, NULL, afs_flock_release_fail,
+  ret);
printk(KERN_WARNING "AFS:"
   " Failed to release lock on {%llx:%llx} error 
%d\n",
   vnode->fid.vid, vnode->fid.vnode, ret);
+   }
 
spin_lock(>lock);
-   afs_next_locker(vnode, 0);
+   if (ret == -ENOENT)
+   afs_kill_lockers_enoent(vnode);
+   else
+   afs_next_locker(vnode, 0);
spin_unlock(>lock);
return;
 
@@ -304,12 +332,21 @@ void afs_lock_work(struct work_struct *work)
ret = afs_extend_lock(vnode, key); /* RPC */
key_put(key);
 
-   if (ret < 0)
+   if (ret < 0) {
+   trace_afs_flock_ev(vnode, NULL, afs_flock_extend_fail,
+  ret);
pr_warning("AFS: Failed to extend lock on {%llx:%llx} 
error %d\n",
   vnode->fid.vid, vnode->fid.vnode, ret);
+   }
 
spin_lock(>lock);
 
+   if (ret == -ENOENT) {
+   afs_kill_lockers_enoent(vnode);
+   spin_unlock(>lock);
+   return;
+   }
+
if (vnode->lock_state != AFS_VNODE_LOCK_EXTENDING)
goto again;
afs_set_lock_state(vnode, AFS_VNODE_LOCK_GRANTED);
@@ -333,6 +370,11 @@ void afs_lock_work(struct work_struct *work)
spin_unlock(>lock);
return;
 
+   case AFS_VNODE_LOCK_DELETED:
+   afs_kill_lockers_enoent(vnode);
+   spin_unlock(>lock);
+   return;
+
default:
/* Looks like a lock request was withdrawn. */
spin_unlock(>lock);
@@ -435,6 +477,10 @@ static int afs_do_setlk(struct file *file, struct 
file_lock *fl)
spin_lock(>lock);
list_add_tail(>fl_u.afs.link, >pending_locks);
 
+   ret = -ENOENT;
+   if (vnode->lock_state == AFS_VNODE_LOCK_DELETED)
+   goto error_unlock;
+
/* If we've already got a lock on the server then try to move to having
 * the VFS grant the requested lock.  Note that this means that other
 * clients may get starved out.
@@ -489,6 +535,13 @@ static int afs_do_setlk(struct file *file, struct 
file_lock *fl)
afs_next_locker(vnode, ret);
goto error_unlock;
 
+   case -ENOENT:
+   fl->fl_u.afs.state = ret;
+   trace_afs_flock_ev(vnode, fl, afs_flock_fail_other, ret);
+   list_del_init(>fl_u.afs.link);
+   afs_kill_lockers_enoent(vnode);
+   goto error_unlock;
+
default:
fl->fl_u.afs.state = ret;
trace_afs_flock_ev(vnode, fl, afs_flock_fail_other, ret);
@@ -638,6 +691,9 @@ static int afs_do_getlk(struct file *file, struct 

[PATCH 05/10] afs: Add file locking tracepoints

2019-03-15 Thread David Howells
Add two tracepoints for monitoring AFS file locking.  Firstly, add one that
follows the operational part:

echo 1 >/sys/kernel/debug/tracing/events/afs/afs_flock_op/enable

And add a second that more follows the event-driven part:

echo 1 >/sys/kernel/debug/tracing/events/afs/afs_flock_ev/enable

Individual file_lock structs seen by afs are tagged with debugging IDs that
are displayed in the trace log to make it easier to see what's going on,
especially as setting the first lock always seems to involve copying the
file_lock twice.

Signed-off-by: David Howells 
---

 fs/afs/flock.c |   72 +++---
 include/linux/fs.h |1 
 include/trace/events/afs.h |  146 
 3 files changed, 209 insertions(+), 10 deletions(-)

diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index c022a7bd3d29..2237ab4ea111 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -32,6 +32,8 @@ static inline void afs_set_lock_state(struct afs_vnode 
*vnode, enum afs_lock_sta
vnode->lock_state = state;
 }
 
+static atomic_t afs_file_lock_debug_id;
+
 /*
  * if the callback is broken on this vnode, then the lock may now be available
  */
@@ -45,6 +47,7 @@ void afs_lock_may_be_available(struct afs_vnode *vnode)
spin_lock(>lock);
if (vnode->lock_state == AFS_VNODE_LOCK_WAITING_FOR_CB)
afs_next_locker(vnode, 0);
+   trace_afs_flock_ev(vnode, NULL, afs_flock_callback_break, 0);
spin_unlock(>lock);
 }
 
@@ -78,6 +81,7 @@ void afs_lock_op_done(struct afs_call *call)
 
if (call->error == 0) {
spin_lock(>lock);
+   trace_afs_flock_ev(vnode, NULL, afs_flock_timestamp, 0);
vnode->locked_at = call->reply_time;
afs_schedule_lock_extension(vnode);
spin_unlock(>lock);
@@ -100,6 +104,7 @@ static void afs_grant_locks(struct afs_vnode *vnode)
 
list_move_tail(>fl_u.afs.link, >granted_locks);
p->fl_u.afs.state = AFS_LOCK_GRANTED;
+   trace_afs_flock_op(vnode, p, afs_flock_op_grant);
wake_up(>fl_wait);
}
 }
@@ -142,9 +147,11 @@ static void afs_next_locker(struct afs_vnode *vnode, int 
error)
if (next) {
afs_set_lock_state(vnode, AFS_VNODE_LOCK_SETTING);
next->fl_u.afs.state = AFS_LOCK_YOUR_TRY;
+   trace_afs_flock_op(vnode, next, afs_flock_op_wake);
wake_up(>fl_wait);
} else {
afs_set_lock_state(vnode, AFS_VNODE_LOCK_NONE);
+   trace_afs_flock_ev(vnode, NULL, afs_flock_no_lockers, 0);
}
 
_leave("");
@@ -264,8 +271,8 @@ void afs_lock_work(struct work_struct *work)
_debug("wstate %u for %p", vnode->lock_state, vnode);
switch (vnode->lock_state) {
case AFS_VNODE_LOCK_NEED_UNLOCK:
-   _debug("unlock");
afs_set_lock_state(vnode, AFS_VNODE_LOCK_UNLOCKING);
+   trace_afs_flock_ev(vnode, NULL, afs_flock_work_unlocking, 0);
spin_unlock(>lock);
 
/* attempt to release the server lock; if it fails, we just
@@ -291,6 +298,7 @@ void afs_lock_work(struct work_struct *work)
 
key = key_get(vnode->lock_key);
afs_set_lock_state(vnode, AFS_VNODE_LOCK_EXTENDING);
+   trace_afs_flock_ev(vnode, NULL, afs_flock_work_extending, 0);
spin_unlock(>lock);
 
ret = afs_extend_lock(vnode, key); /* RPC */
@@ -349,6 +357,7 @@ static void afs_defer_unlock(struct afs_vnode *vnode)
cancel_delayed_work(>lock_work);
 
afs_set_lock_state(vnode, AFS_VNODE_LOCK_NEED_UNLOCK);
+   trace_afs_flock_ev(vnode, NULL, afs_flock_defer_unlock, 0);
queue_delayed_work(afs_lock_manager, >lock_work, 0);
}
 }
@@ -421,6 +430,8 @@ static int afs_do_setlk(struct file *file, struct file_lock 
*fl)
if (ret < 0)
return ret;
 
+   trace_afs_flock_op(vnode, fl, afs_flock_op_set_lock);
+
spin_lock(>lock);
list_add_tail(>fl_u.afs.link, >pending_locks);
 
@@ -457,7 +468,7 @@ static int afs_do_setlk(struct file *file, struct file_lock 
*fl)
 * though we don't wait for the reply (it's not too bad a problem - the
 * lock will expire in 5 mins anyway).
 */
-   _debug("not locked");
+   trace_afs_flock_ev(vnode, fl, afs_flock_try_to_lock, 0);
vnode->lock_key = key_get(key);
vnode->lock_type = type;
afs_set_lock_state(vnode, AFS_VNODE_LOCK_SETTING);
@@ -473,12 +484,14 @@ static int afs_do_setlk(struct file *file, struct 
file_lock *fl)
case -EPERM:
case -EACCES:
fl->fl_u.afs.state = ret;
+   trace_afs_flock_ev(vnode, fl, afs_flock_fail_perm, ret);
list_del_init(>fl_u.afs.link);
afs_next_locker(vnode, ret);

Re: [PATCH v1 2/3] perf stat: Support coresum event qualifier

2019-03-15 Thread Jin, Yao




On 3/15/2019 9:34 PM, Jiri Olsa wrote:

On Sat, Mar 16, 2019 at 12:04:15AM +0800, Jin Yao wrote:

SNIP


+static void print_counter_aggrdata(struct perf_stat_config *config,
+  struct perf_evsel *counter, int s,
+  char *prefix, bool metric_only,
+  bool *first)
+{
+   struct aggr_data ad;
+   FILE *output = config->output;
+   u64 ena, run, val;
+   int id, nr;
+   double uval;
+
+   ad.id = id = config->aggr_map->map[s];
+   ad.val = ad.ena = ad.run = 0;
+   ad.nr = 0;
+   if (!collect_data(config, counter, aggr_cb, ))
+   return;
+
+   nr = ad.nr;
+   ena = ad.ena;
+   run = ad.run;
+   val = ad.val;
+   if (*first && metric_only) {
+   *first = false;
+   aggr_printout(config, counter, id, nr);
+   }
+   if (prefix && !metric_only)
+   fprintf(output, "%s", prefix);
+
+   uval = val * counter->scale;
+   printout(config, id, nr, counter, uval, prefix,
+run, ena, 1.0, _stat);
+   if (!metric_only)
+   fputc('\n', output);
+}


plese put the factoring out of print_counter_aggrdata function
into separate patch

thanks,
jirka




OK!

Thanks
Jin Yao


+
  static void print_aggr(struct perf_stat_config *config,
   struct perf_evlist *evlist,
   char *prefix)
@@ -606,9 +649,7 @@ static void print_aggr(struct perf_stat_config *config,
bool metric_only = config->metric_only;
FILE *output = config->output;
struct perf_evsel *counter;
-   int s, id, nr;
-   double uval;
-   u64 ena, run, val;
+   int s;
bool first;
  
  	if (!(config->aggr_map || config->aggr_get_id))

@@ -621,36 +662,16 @@ static void print_aggr(struct perf_stat_config *config,
 * Without each counter has its own line.
 */
for (s = 0; s < config->aggr_map->nr; s++) {
-   struct aggr_data ad;
if (prefix && metric_only)
fprintf(output, "%s", prefix);
  
-		ad.id = id = config->aggr_map->map[s];

first = true;
evlist__for_each_entry(evlist, counter) {
if (is_duration_time(counter))
continue;
-
-   ad.val = ad.ena = ad.run = 0;
-   ad.nr = 0;
-   if (!collect_data(config, counter, aggr_cb, ))
-   continue;
-   nr = ad.nr;
-   ena = ad.ena;
-   run = ad.run;
-   val = ad.val;
-   if (first && metric_only) {
-   first = false;
-   aggr_printout(config, counter, id, nr);
-   }
-   if (prefix && !metric_only)
-   fprintf(output, "%s", prefix);
-
-   uval = val * counter->scale;
-   printout(config, id, nr, counter, uval, prefix,
-run, ena, 1.0, _stat);
-   if (!metric_only)
-   fputc('\n', output);
+   print_counter_aggrdata(config, counter, s,
+  prefix, metric_only,
+  );


SNIP



[PATCH 09/10] afs: Implement sillyrename for unlink and rename

2019-03-15 Thread David Howells
Implement sillyrename for AFS unlink and rename, using the NFS variant
implementation as a basis.

Note that the asynchronous file locking extender/releaser has to be
notified with a state change to stop it complaining if there's a race
between that and the actual file deletion.

A tracepoint, afs_silly_rename, is also added to note the silly rename and
the cleanup.  The afs_edit_dir tracepoint is given some extra reason
indicators and the afs_flock_ev tracepoint is given a silly-delete file
lock cancellation indicator.

Signed-off-by: David Howells 
---

 fs/afs/Makefile|1 
 fs/afs/dir.c   |  116 -
 fs/afs/dir_silly.c |  239 
 fs/afs/flock.c |2 
 fs/afs/inode.c |2 
 fs/afs/internal.h  |   10 ++
 fs/afs/super.c |4 +
 include/trace/events/afs.h |   34 ++
 8 files changed, 395 insertions(+), 13 deletions(-)
 create mode 100644 fs/afs/dir_silly.c

diff --git a/fs/afs/Makefile b/fs/afs/Makefile
index 0738e2bf5193..cbf31f6cd177 100644
--- a/fs/afs/Makefile
+++ b/fs/afs/Makefile
@@ -13,6 +13,7 @@ kafs-y := \
cmservice.o \
dir.o \
dir_edit.o \
+   dir_silly.o \
dynroot.o \
file.o \
flock.o \
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index be5d2f932b77..6c8523501639 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -26,6 +26,7 @@ static int afs_dir_open(struct inode *inode, struct file 
*file);
 static int afs_readdir(struct file *file, struct dir_context *ctx);
 static int afs_d_revalidate(struct dentry *dentry, unsigned int flags);
 static int afs_d_delete(const struct dentry *dentry);
+static void afs_d_iput(struct dentry *dentry, struct inode *inode);
 static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name, 
int nlen,
  loff_t fpos, u64 ino, unsigned dtype);
 static int afs_lookup_filldir(struct dir_context *ctx, const char *name, int 
nlen,
@@ -85,6 +86,7 @@ const struct dentry_operations afs_fs_dentry_operations = {
.d_delete   = afs_d_delete,
.d_release  = afs_d_release,
.d_automount= afs_d_automount,
+   .d_iput = afs_d_iput,
 };
 
 struct afs_lookup_one_cookie {
@@ -1083,6 +1085,16 @@ static int afs_d_delete(const struct dentry *dentry)
return 1;
 }
 
+/*
+ * Clean up sillyrename files on dentry removal.
+ */
+static void afs_d_iput(struct dentry *dentry, struct inode *inode)
+{
+   if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
+   afs_silly_iput(dentry, inode);
+   iput(inode);
+}
+
 /*
  * handle dentry release
  */
@@ -1225,6 +1237,12 @@ static int afs_rmdir(struct inode *dir, struct dentry 
*dentry)
goto error_key;
}
 
+   if (vnode) {
+   ret = down_write_killable(>rmdir_lock);
+   if (ret < 0)
+   goto error_key;
+   }
+
ret = -ERESTARTSYS;
if (afs_begin_vnode_operation(, dvnode, key)) {
while (afs_select_fileserver()) {
@@ -1243,6 +1261,8 @@ static int afs_rmdir(struct inode *dir, struct dentry 
*dentry)
}
}
 
+   if (vnode)
+   up_write(>rmdir_lock);
 error_key:
key_put(key);
 error:
@@ -1259,9 +1279,9 @@ static int afs_rmdir(struct inode *dir, struct dentry 
*dentry)
  * However, if we didn't have a callback promise outstanding, or it was
  * outstanding on a different server, then it won't break it either...
  */
-static int afs_dir_remove_link(struct dentry *dentry, struct key *key,
-  unsigned long d_version_before,
-  unsigned long d_version_after)
+int afs_dir_remove_link(struct dentry *dentry, struct key *key,
+   unsigned long d_version_before,
+   unsigned long d_version_after)
 {
bool dir_valid;
int ret = 0;
@@ -1308,6 +1328,7 @@ static int afs_unlink(struct inode *dir, struct dentry 
*dentry)
struct afs_vnode *dvnode = AFS_FS_I(dir), *vnode = NULL;
struct key *key;
unsigned long d_version = (unsigned long)dentry->d_fsdata;
+   bool need_rehash = false;
u64 data_version = dvnode->status.data_version;
int ret;
 
@@ -1331,6 +1352,21 @@ static int afs_unlink(struct inode *dir, struct dentry 
*dentry)
goto error_key;
}
 
+   spin_lock(>d_lock);
+   if (vnode && d_count(dentry) > 1) {
+   spin_unlock(>d_lock);
+   /* Start asynchronous writeout of the inode */
+   write_inode_now(d_inode(dentry), 0);
+   ret = afs_sillyrename(dvnode, vnode, dentry, key);
+   goto error_key;
+   }
+   if (!d_unhashed(dentry)) {
+   /* Prevent a race with RCU lookup. */
+   __d_drop(dentry);
+   need_rehash = true;
+   }

[PATCH 04/10] afs: Further fix file locking

2019-03-15 Thread David Howells
Further fix the file locking in the afs filesystem client in a number of
ways, including:

 (1) Don't submit the operation to obtain a lock from the server in a work
 queue context, but rather do it in the process context of whoever
 issued the requesting system call.

 (2) The owner of the file_lock struct at the front of the pending_locks
 queue now owns right to talk to the server.

 (3) Write locks can be instantly granted if they don't overlap with any
 other locks *and* we have a write lock on the server.

 (4) In the event of an authentication/permission error, all other matching
 pending locks requests are also immediately aborted.

 (5) Properly use VFS core locks_lock_file_wait() to distribute the server
 lock amongst local client locks, including waiting for the lock to
 become available.

Test with:

sqlite3 /afs/.../scratch/billings.sqlite <
Signed-off-by: David Howells 
---

 fs/afs/flock.c |  388 
 1 file changed, 194 insertions(+), 194 deletions(-)

diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index 6919f53ed4ad..c022a7bd3d29 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -13,9 +13,11 @@
 
 #define AFS_LOCK_GRANTED   0
 #define AFS_LOCK_PENDING   1
+#define AFS_LOCK_YOUR_TRY  2
 
 struct workqueue_struct *afs_lock_manager;
 
+static void afs_next_locker(struct afs_vnode *vnode, int error);
 static void afs_fl_copy_lock(struct file_lock *new, struct file_lock *fl);
 static void afs_fl_release_private(struct file_lock *fl);
 
@@ -24,6 +26,12 @@ static const struct file_lock_operations afs_lock_ops = {
.fl_release_private = afs_fl_release_private,
 };
 
+static inline void afs_set_lock_state(struct afs_vnode *vnode, enum 
afs_lock_state state)
+{
+   _debug("STATE %u -> %u", vnode->lock_state, state);
+   vnode->lock_state = state;
+}
+
 /*
  * if the callback is broken on this vnode, then the lock may now be available
  */
@@ -31,7 +39,13 @@ void afs_lock_may_be_available(struct afs_vnode *vnode)
 {
_enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
 
-   queue_delayed_work(afs_lock_manager, >lock_work, 0);
+   if (vnode->lock_state != AFS_VNODE_LOCK_WAITING_FOR_CB)
+   return;
+
+   spin_lock(>lock);
+   if (vnode->lock_state == AFS_VNODE_LOCK_WAITING_FOR_CB)
+   afs_next_locker(vnode, 0);
+   spin_unlock(>lock);
 }
 
 /*
@@ -75,22 +89,65 @@ void afs_lock_op_done(struct afs_call *call)
  * first lock in the queue is itself a readlock)
  * - the caller must hold the vnode lock
  */
-static void afs_grant_locks(struct afs_vnode *vnode, struct file_lock *fl)
+static void afs_grant_locks(struct afs_vnode *vnode)
 {
struct file_lock *p, *_p;
+   bool exclusive = (vnode->lock_type == AFS_LOCK_WRITE);
 
-   list_move_tail(>fl_u.afs.link, >granted_locks);
-   if (fl->fl_type == F_RDLCK) {
-   list_for_each_entry_safe(p, _p, >pending_locks,
-fl_u.afs.link) {
-   if (p->fl_type == F_RDLCK) {
-   p->fl_u.afs.state = AFS_LOCK_GRANTED;
-   list_move_tail(>fl_u.afs.link,
-  >granted_locks);
-   wake_up(>fl_wait);
-   }
+   list_for_each_entry_safe(p, _p, >pending_locks, fl_u.afs.link) {
+   if (!exclusive && p->fl_type == F_WRLCK)
+   continue;
+
+   list_move_tail(>fl_u.afs.link, >granted_locks);
+   p->fl_u.afs.state = AFS_LOCK_GRANTED;
+   wake_up(>fl_wait);
+   }
+}
+
+/*
+ * If an error is specified, reject every pending lock that matches the
+ * authentication and type of the lock we failed to get.  If there are any
+ * remaining lockers, try to wake up one of them to have a go.
+ */
+static void afs_next_locker(struct afs_vnode *vnode, int error)
+{
+   struct file_lock *p, *_p, *next = NULL;
+   struct key *key = vnode->lock_key;
+   unsigned int fl_type = F_RDLCK;
+
+   _enter("");
+
+   if (vnode->lock_type == AFS_LOCK_WRITE)
+   fl_type = F_WRLCK;
+
+   list_for_each_entry_safe(p, _p, >pending_locks, fl_u.afs.link) {
+   if (error &&
+   p->fl_type == fl_type &&
+   afs_file_key(p->fl_file) == key) {
+   list_del_init(>fl_u.afs.link);
+   p->fl_u.afs.state = error;
+   wake_up(>fl_wait);
}
+
+   /* Select the next locker to hand off to. */
+   if (next &&
+   (next->fl_type == F_WRLCK || p->fl_type == F_RDLCK))
+   continue;
+   next = p;
}
+
+   vnode->lock_key = NULL;
+   key_put(key);
+
+   if (next) {
+   afs_set_lock_state(vnode, 

[PATCH 06/10] afs: Improve dir check failure reports

2019-03-15 Thread David Howells
Improve the content of directory check failure reports from:

kAFS: afs_dir_check_page(6d57): bad magic 1/2 is 

to dump more information about the individual blocks in a directory page.

Signed-off-by: David Howells 
---

 fs/afs/dir.c |   38 ++
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 8a2562e3a316..378a96a1116e 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -159,6 +159,38 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, 
struct page *page,
return false;
 }
 
+/*
+ * Check the contents of a directory that we've just read.
+ */
+static bool afs_dir_check_pages(struct afs_vnode *dvnode, struct afs_read *req)
+{
+   struct afs_xdr_dir_page *dbuf;
+   unsigned int i, j, qty = PAGE_SIZE / sizeof(union afs_xdr_dir_block);
+
+   for (i = 0; i < req->nr_pages; i++)
+   if (!afs_dir_check_page(dvnode, req->pages[i], req->actual_len))
+   goto bad;
+   return true;
+
+bad:
+   pr_warn("DIR %llx:%llx f=%llx l=%llx al=%llx r=%llx\n",
+   dvnode->fid.vid, dvnode->fid.vnode,
+   req->file_size, req->len, req->actual_len, req->remain);
+   pr_warn("DIR %llx %x %x %x\n",
+   req->pos, req->index, req->nr_pages, req->offset);
+
+   for (i = 0; i < req->nr_pages; i++) {
+   dbuf = kmap(req->pages[i]);
+   for (j = 0; j < qty; j++) {
+   union afs_xdr_dir_block *block = >blocks[j];
+
+   pr_warn("[%02x] %32phN\n", i * qty + j, block);
+   }
+   kunmap(req->pages[i]);
+   }
+   return false;
+}
+
 /*
  * open an AFS directory file
  */
@@ -288,10 +320,8 @@ static struct afs_read *afs_read_dir(struct afs_vnode 
*dvnode, struct key *key)
 
/* Validate the data we just read. */
ret = -EIO;
-   for (i = 0; i < req->nr_pages; i++)
-   if (!afs_dir_check_page(dvnode, req->pages[i],
-   req->actual_len))
-   goto error_unlock;
+   if (!afs_dir_check_pages(dvnode, req))
+   goto error_unlock;
 
// TODO: Trim excess pages
 



[PATCH 01/10] afs: Split wait from afs_make_call()

2019-03-15 Thread David Howells
Split the call to afs_wait_for_call_to_complete() from afs_make_call() to
make it easier to handle asynchronous calls and to make it easier to
convert a synchronous call to an asynchronous one in future, for instance
when someone tries to interrupt an operation by pressing Ctrl-C.

Signed-off-by: David Howells 
---

 fs/afs/fs_probe.c  |   13 +
 fs/afs/fsclient.c  |   78 +---
 fs/afs/internal.h  |   12 +---
 fs/afs/rxrpc.c |   33 +++---
 fs/afs/vl_probe.c  |   14 +
 fs/afs/vlclient.c  |   26 ++---
 fs/afs/yfsclient.c |   54 
 7 files changed, 139 insertions(+), 91 deletions(-)

diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c
index 3a9eaec06756..5d3abde52a0f 100644
--- a/fs/afs/fs_probe.c
+++ b/fs/afs/fs_probe.c
@@ -141,8 +141,8 @@ static int afs_do_probe_fileserver(struct afs_net *net,
struct afs_addr_cursor ac = {
.index = 0,
};
+   struct afs_call *call;
bool in_progress = false;
-   int err;
 
_enter("%pU", >uuid);
 
@@ -156,12 +156,13 @@ static int afs_do_probe_fileserver(struct afs_net *net,
server->probe.rtt = UINT_MAX;
 
for (ac.index = 0; ac.index < ac.alist->nr_addrs; ac.index++) {
-   err = afs_fs_get_capabilities(net, server, , key, 
server_index,
- true);
-   if (err == -EINPROGRESS)
+   call = afs_fs_get_capabilities(net, server, , key, 
server_index);
+   if (!IS_ERR(call)) {
+   afs_put_call(call);
in_progress = true;
-   else
-   afs_prioritise_error(_e, err, ac.abort_code);
+   } else {
+   afs_prioritise_error(_e, PTR_ERR(call), ac.abort_code);
+   }
}
 
if (!in_progress)
diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index ca08c83168f5..2ff19ebda666 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -468,7 +468,9 @@ int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, 
struct afs_volsync *volsy
call->cb_break = fc->cb_break;
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -660,7 +662,8 @@ static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, 
struct afs_read *req)
call->cb_break = fc->cb_break;
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -707,7 +710,8 @@ int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct 
afs_read *req)
call->cb_break = fc->cb_break;
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -827,7 +831,8 @@ int afs_fs_create(struct afs_fs_cursor *fc,
 
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -922,7 +927,8 @@ int afs_fs_remove(struct afs_fs_cursor *fc, struct 
afs_vnode *vnode,
 
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -1014,7 +1020,8 @@ int afs_fs_link(struct afs_fs_cursor *fc, struct 
afs_vnode *vnode,
 
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -1128,7 +1135,8 @@ int afs_fs_symlink(struct afs_fs_cursor *fc,
 
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, >fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -1246,7 +1254,8 @@ int afs_fs_rename(struct afs_fs_cursor *fc,
 
afs_use_fs_server(call, fc->cbi);
trace_afs_make_fs_call(call, _dvnode->fid);
-   return afs_make_call(>ac, call, GFP_NOFS, false);
+   afs_make_call(>ac, call, GFP_NOFS);
+   return afs_wait_for_call_to_complete(call, >ac);
 }
 
 /*
@@ -1350,7 +1359,8 @@ static int afs_fs_store_data64(struct 

[PATCH 00/10] AFS fixes

2019-03-15 Thread David Howells


Here's a set of bits and fixes for AFS to improve the life of desktop
applications such as firefox.  It makes the following improvements:

 (1) Allows fine-grained locking, as required by firefox and sqlite, with
 the caveat that you can't get a partial write lock on a file if you
 first get a partial read lock on it as the AFS protocol only supports
 whole-file locks.

 At some point I need to look at emulating OpenAFS's behaviour whereby
 all partial locks are just granted.

 (2) Makes processes requesting locks actually wait to get a lock where we
 have an appropriate server lock, but there's a conflicting server
 lock.

 (3) Makes locks appear in /proc/locks.

 (4) Handles asynchronous file lock RPC operation failure on files that get
 deleted whilst the lock is being extended or released.

 (5) Implements silly-rename so that locked files that are in use continue
 to exist if they get released or unlinked.

 (6) Lock expiry is now based on the time the set- or extend-lock reply is
 seen (packet timestamp) rather than by the time at which we've done
 processing the operation (wallclock time).

It also adds/modifies tracepoints to log:

 (1) File locking operations and events.

 (2) Directory content reload.

 (3) Silly rename.

 (4) Lookups.

 (5) Mounts (get_tree).

 (6) The afs_make_fs_call tracepoint is split to give two new variants that
 allow one or two names to be included in the log (such as the filename
 given to FS.MakeDir).

 (7) The afs_edit_dir tracepoint is given a larger name and this is
 surrounded by quotes when displayed.

This also provides a more comprehensive data dump in the event that a
directory content check fails.

The patches can be found here:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git
tag afs-fixes-20190315

David
---
David Howells (10):
  afs: Split wait from afs_make_call()
  afs: Calculate lock extend timer from set/extend reply reception
  afs: Fix AFS file locking to allow fine grained locks
  afs: Further fix file locking
  afs: Add file locking tracepoints
  afs: Improve dir check failure reports
  afs: Handle lock rpc ops failing on a file that got deleted
  afs: Add directory reload tracepoint
  afs: Implement sillyrename for unlink and rename
  afs: Add more tracepoints


 fs/afs/Makefile|1 
 fs/afs/dir.c   |  161 +++-
 fs/afs/dir_silly.c |  239 ++
 fs/afs/flock.c |  569 +++-
 fs/afs/fs_probe.c  |   13 +
 fs/afs/fsclient.c  |   92 +--
 fs/afs/inode.c |2 
 fs/afs/internal.h  |   25 ++
 fs/afs/rxrpc.c |   33 +--
 fs/afs/super.c |5 
 fs/afs/vl_probe.c  |   14 +
 fs/afs/vlclient.c  |   26 +-
 fs/afs/yfsclient.c |   72 --
 include/linux/fs.h |1 
 include/trace/events/afs.h |  348 +++
 15 files changed, 1258 insertions(+), 343 deletions(-)
 create mode 100644 fs/afs/dir_silly.c



Re: [PATCH v1 0/3] perf: Support a new coresum event qualifier

2019-03-15 Thread Jin, Yao




On 3/15/2019 9:34 PM, Jiri Olsa wrote:

On Sat, Mar 16, 2019 at 12:04:13AM +0800, Jin Yao wrote:

The coresum event qualifier which sums up the event counts for both
hardware threads in a core. For example,

perf stat -e cpu/event=0,umask=0x3,coresum=1/,cpu/event=0,umask=0x3/

In this example, we count the event 'ref-cycles' per-core and per-CPU in
one perf stat command-line.

We can already support per-core counting with --per-core, but it's
often useful to do this together with other metrics that are collected
per CPU (per hardware thread). So this patch series supports this
per-core counting on a event level.


seems useful, but perhaps we should follow the --per-core option
we already have and call it 'per-core' instead of coresum

jirka



Yes, the coresum's behavior is similar as --per-core option, just 
supports at the event level. I'm OK with calling it 'per-core'.


For example,
perf stat -e cpu/event=0,umask=0x3,per-core=1/

Thanks
Jin Yao



Jin Yao (3):
   perf: Add a coresum event qualifier
   perf stat: Support coresum event qualifier
   perf test: Add a simple test for term coresum

  tools/perf/Documentation/perf-stat.txt |   4 ++
  tools/perf/builtin-stat.c  |  21 +++
  tools/perf/tests/parse-events.c|  10 ++-
  tools/perf/util/evsel.c|   2 +
  tools/perf/util/evsel.h|   3 +
  tools/perf/util/parse-events.c |  27 +
  tools/perf/util/parse-events.h |   1 +
  tools/perf/util/parse-events.l |   1 +
  tools/perf/util/stat-display.c | 108 -
  tools/perf/util/stat.c |   8 ++-
  10 files changed, 151 insertions(+), 34 deletions(-)

--
2.7.4



[PATCH 03/10] afs: Fix AFS file locking to allow fine grained locks

2019-03-15 Thread David Howells
Fix AFS file locking to allow fine grained locks as some applications, such
as firefox, won't work if they can't take such locks on certain state files
- thereby preventing the use of kAFS to distribute a home directory.

Note that this cannot be made completely functional as the protocol only
has provision for whole-file locks, so there exists the possibility of a
process deadlocking itself by getting a partial read-lock on a file first
and then trying to get a non-overlapping write-lock - but we got the
server's read lock with the first lock, so we're now stuck.

OpenAFS solves this by just granting any partial-range lock directly
without consulting the server - and hoping there's no remote collision.  I
want to implement that in a separate patch and it requires a bit more
thought.

Fixes: 8d6c554126b8 ("AFS: implement file locking")
Reported-by: Jonathan Billings 
Signed-off-by: David Howells 
---

 fs/afs/flock.c |   23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index 8b02f0056d54..6919f53ed4ad 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -458,10 +458,6 @@ static int afs_do_setlk(struct file *file, struct 
file_lock *fl)
 
_enter("{%llx:%llu},%u", vnode->fid.vid, vnode->fid.vnode, fl->fl_type);
 
-   /* only whole-file locks are supported */
-   if (fl->fl_start != 0 || fl->fl_end != OFFSET_MAX)
-   return -EINVAL;
-
fl->fl_ops = _lock_ops;
INIT_LIST_HEAD(>fl_u.afs.link);
fl->fl_u.afs.state = AFS_LOCK_PENDING;
@@ -613,10 +609,6 @@ static int afs_do_unlk(struct file *file, struct file_lock 
*fl)
/* Flush all pending writes before doing anything with locks. */
vfs_fsync(file, 0);
 
-   /* only whole-file unlocks are supported */
-   if (fl->fl_start != 0 || fl->fl_end != OFFSET_MAX)
-   return -EINVAL;
-
ret = posix_lock_file(file, fl, NULL);
_leave(" = %d [%u]", ret, vnode->lock_state);
return ret;
@@ -644,12 +636,15 @@ static int afs_do_getlk(struct file *file, struct 
file_lock *fl)
goto error;
 
lock_count = READ_ONCE(vnode->status.lock_count);
-   if (lock_count > 0)
-   fl->fl_type = F_RDLCK;
-   else
-   fl->fl_type = F_WRLCK;
-   fl->fl_start = 0;
-   fl->fl_end = OFFSET_MAX;
+   if (lock_count != 0) {
+   if (lock_count > 0)
+   fl->fl_type = F_RDLCK;
+   else
+   fl->fl_type = F_WRLCK;
+   fl->fl_start = 0;
+   fl->fl_end = OFFSET_MAX;
+   fl->fl_pid = 0;
+   }
}
 
ret = 0;



[PATCH 02/10] afs: Calculate lock extend timer from set/extend reply reception

2019-03-15 Thread David Howells
Record the timestamp on the first reply DATA packet received in response to
a set- or extend-lock operation, then use this to calculate the time
remaining till the lock expires rather than using whatever time the
requesting process wakes up and finishes processing the operation as a
base.

Signed-off-by: David Howells 
---

 fs/afs/flock.c |   30 --
 fs/afs/fsclient.c  |4 
 fs/afs/internal.h  |2 ++
 fs/afs/yfsclient.c |4 
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/fs/afs/flock.c b/fs/afs/flock.c
index e432bd27a2e7..8b02f0056d54 100644
--- a/fs/afs/flock.c
+++ b/fs/afs/flock.c
@@ -40,8 +40,34 @@ void afs_lock_may_be_available(struct afs_vnode *vnode)
  */
 static void afs_schedule_lock_extension(struct afs_vnode *vnode)
 {
-   queue_delayed_work(afs_lock_manager, >lock_work,
-  AFS_LOCKWAIT * HZ / 2);
+   ktime_t expires_at, now, duration;
+   u64 duration_j;
+
+   expires_at = ktime_add_ms(vnode->locked_at, AFS_LOCKWAIT * 1000 / 2);
+   now = ktime_get_real();
+   duration = ktime_sub(expires_at, now);
+   if (duration <= 0)
+   duration_j = 0;
+   else
+   duration_j = nsecs_to_jiffies(ktime_to_ns(duration));
+
+   queue_delayed_work(afs_lock_manager, >lock_work, duration_j);
+}
+
+/*
+ * In the case of successful completion of a lock operation, record the time
+ * the reply appeared and start the lock extension timer.
+ */
+void afs_lock_op_done(struct afs_call *call)
+{
+   struct afs_vnode *vnode = call->reply[0];
+
+   if (call->error == 0) {
+   spin_lock(>lock);
+   vnode->locked_at = call->reply_time;
+   afs_schedule_lock_extension(vnode);
+   spin_unlock(>lock);
+   }
 }
 
 /*
diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index 2ff19ebda666..b9cf9dc1a9b7 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -1845,6 +1845,7 @@ static const struct afs_call_type afs_RXFSSetLock = {
.name   = "FS.SetLock",
.op = afs_FS_SetLock,
.deliver= afs_deliver_fs__lock,
+   .done   = afs_lock_op_done,
.destructor = afs_flat_call_destructor,
 };
 
@@ -1855,6 +1856,7 @@ static const struct afs_call_type afs_RXFSExtendLock = {
.name   = "FS.ExtendLock",
.op = afs_FS_ExtendLock,
.deliver= afs_deliver_fs__lock,
+   .done   = afs_lock_op_done,
.destructor = afs_flat_call_destructor,
 };
 
@@ -1889,6 +1891,7 @@ int afs_fs_set_lock(struct afs_fs_cursor *fc, 
afs_lock_type_t type)
 
call->key = fc->key;
call->reply[0] = vnode;
+   call->want_reply_time = true;
 
/* marshall the parameters */
bp = call->request;
@@ -1925,6 +1928,7 @@ int afs_fs_extend_lock(struct afs_fs_cursor *fc)
 
call->key = fc->key;
call->reply[0] = vnode;
+   call->want_reply_time = true;
 
/* marshall the parameters */
bp = call->request;
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 1530d7e9e7a9..37a5ba550846 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -639,6 +639,7 @@ struct afs_vnode {
struct list_headgranted_locks;  /* locks granted on this file */
struct delayed_work lock_work;  /* work to be done in locking */
struct key  *lock_key;  /* Key to be used in lock ops */
+   ktime_t locked_at;  /* Time at which lock obtained 
*/
enum afs_lock_state lock_state : 8;
afs_lock_type_t lock_type : 8;
 
@@ -907,6 +908,7 @@ extern void afs_put_read(struct afs_read *);
  */
 extern struct workqueue_struct *afs_lock_manager;
 
+extern void afs_lock_op_done(struct afs_call *);
 extern void afs_lock_work(struct work_struct *);
 extern void afs_lock_may_be_available(struct afs_vnode *);
 extern int afs_lock(struct file *, int, struct file_lock *);
diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c
index 40b1f19d1018..41afc53a7df7 100644
--- a/fs/afs/yfsclient.c
+++ b/fs/afs/yfsclient.c
@@ -1801,6 +1801,7 @@ static const struct afs_call_type yfs_RXYFSSetLock = {
.name   = "YFS.SetLock",
.op = yfs_FS_SetLock,
.deliver= yfs_deliver_fs__lock,
+   .done   = afs_lock_op_done,
.destructor = afs_flat_call_destructor,
 };
 
@@ -1811,6 +1812,7 @@ static const struct afs_call_type yfs_RXYFSExtendLock = {
.name   = "YFS.ExtendLock",
.op = yfs_FS_ExtendLock,
.deliver= yfs_deliver_fs__lock,
+   .done   = afs_lock_op_done,
.destructor = afs_flat_call_destructor,
 };
 
@@ -1847,6 +1849,7 @@ int yfs_fs_set_lock(struct afs_fs_cursor *fc, 
afs_lock_type_t type)
 
call->key = fc->key;
call->reply[0] = vnode;
+   

[PATCH 10/10] afs: Add more tracepoints

2019-03-15 Thread David Howells
Add four more tracepoints:

 (1) afs_make_fs_call1 - Split from afs_make_fs_call but takes a filename
 to log also.

 (2) afs_make_fs_call2 - Like the above but takes two filenames to log.

 (3) afs_lookup - Log the result of doing a successful lookup, including a
 negative result (fid 0:0).

 (4) afs_get_tree - Log the set up of a volume for mounting.

It also extends the name buffer on the afs_edit_dir tracepoint to 24 chars
and puts quotes around the filename in the text representation.

Signed-off-by: David Howells 
---

 fs/afs/dir.c   |6 ++
 fs/afs/fsclient.c  |   10 ++-
 fs/afs/super.c |1 
 fs/afs/yfsclient.c |   14 ++--
 include/trace/events/afs.h |  146 +++-
 5 files changed, 161 insertions(+), 16 deletions(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 6c8523501639..8e3be31f94ce 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -908,8 +908,12 @@ static struct dentry *afs_lookup(struct inode *dir, struct 
dentry *dentry,
(void *)(unsigned long)dvnode->status.data_version;
}
d = d_splice_alias(inode, dentry);
-   if (!IS_ERR_OR_NULL(d))
+   if (!IS_ERR_OR_NULL(d)) {
d->d_fsdata = dentry->d_fsdata;
+   trace_afs_lookup(dvnode, >d_name, inode ? AFS_FS_I(inode) : 
0);
+   } else {
+   trace_afs_lookup(dvnode, >d_name, inode ? 
AFS_FS_I(inode) : 0);
+   }
return d;
 }
 
diff --git a/fs/afs/fsclient.c b/fs/afs/fsclient.c
index b9cf9dc1a9b7..b61ac50ed04a 100644
--- a/fs/afs/fsclient.c
+++ b/fs/afs/fsclient.c
@@ -830,7 +830,7 @@ int afs_fs_create(struct afs_fs_cursor *fc,
*bp++ = 0; /* segment size */
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -926,7 +926,7 @@ int afs_fs_remove(struct afs_fs_cursor *fc, struct 
afs_vnode *vnode,
}
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -1019,7 +1019,7 @@ int afs_fs_link(struct afs_fs_cursor *fc, struct 
afs_vnode *vnode,
*bp++ = htonl(vnode->fid.unique);
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -1134,7 +1134,7 @@ int afs_fs_symlink(struct afs_fs_cursor *fc,
*bp++ = 0; /* segment size */
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -1253,7 +1253,7 @@ int afs_fs_rename(struct afs_fs_cursor *fc,
}
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, _dvnode->fid);
+   trace_afs_make_fs_call2(call, _dvnode->fid, orig_name, new_name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
diff --git a/fs/afs/super.c b/fs/afs/super.c
index 6438849a75c4..ce85ae61f12d 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -550,6 +550,7 @@ static int afs_get_tree(struct fs_context *fc)
}
 
fc->root = dget(sb->s_root);
+   trace_afs_get_tree(as->cell, as->volume);
_leave(" = 0 [%p]", sb);
return 0;
 
diff --git a/fs/afs/yfsclient.c b/fs/afs/yfsclient.c
index 41afc53a7df7..0f2c6b915cbe 100644
--- a/fs/afs/yfsclient.c
+++ b/fs/afs/yfsclient.c
@@ -809,7 +809,7 @@ int yfs_fs_create_file(struct afs_fs_cursor *fc,
yfs_check_req(call, bp);
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -873,7 +873,7 @@ int yfs_fs_make_dir(struct afs_fs_cursor *fc,
yfs_check_req(call, bp);
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -964,7 +964,7 @@ int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct 
afs_vnode *vnode,
yfs_check_req(call, bp);
 
afs_use_fs_server(call, fc->cbi);
-   trace_afs_make_fs_call(call, >fid);
+   trace_afs_make_fs_call1(call, >fid, name);
afs_make_call(>ac, call, GFP_NOFS);
return afs_wait_for_call_to_complete(call, >ac);
 }
@@ -1052,7 +1052,7 @@ int yfs_fs_remove(struct 

Re: [PATCH] MIPS: Remove custom MIPS32 __kernel_fsid_t type

2019-03-15 Thread Paul Burton
Hello,

Paul Burton wrote:
> For MIPS32 kernels we have a custom definition of __kernel_fsid_t. This
> differs from the asm-generic version used by all other architectures &
> MIPS64 in one way - it declares the val field as an array of long,
> rather than an array of int. Since int & long have identical size &
> alignment when targeting MIPS32 anyway, this makes little sense.
> 
> Beyond the pointlessness this causes problems for code which prints
> entries from the val array, for example the fanotify_encode_fid()
> function [1]. If such code uses a format specified suited to an int then
> it encounters compiler warnings when building for MIPS32, such as:
> 
> In file included from include/linux/kernel.h:14:0,
> from include/linux/list.h:9,
> from include/linux/preempt.h:11,
> from include/linux/spinlock.h:51,
> from include/linux/fdtable.h:11,
> from fs/notify/fanotify/fanotify.c:3:
> fs/notify/fanotify/fanotify.c: In function 'fanotify_encode_fid':
> include/linux/kern_levels.h:5:18: warning: format '%x' expects argument
> of type 'unsigned int', but argument 2 has type 'long int' [-Wformat=]
> 
> Remove the custom __kernel_fsid_t definition & make use of the
> asm-generic version which will have an identical layout in memory
> anyway, in order to remove the inconsistency with other architectures.
> 
> One possible regression this could cause if is any code is attempting to
> print entries from the val array with a long-sized format specifier, in
> which case it would begin seeing compiler warnings when built against
> kernel headers including this change. Since such code is exceedingly
> rare, and would have to be MIPS32-specific to expect a long, this seems
> to be a problem that it's extremely unlikely anyone will encounter.
> 
> [1] 
> https://lore.kernel.org/linux-mips/CAOQ4uxiEkczB7PNCXegFC-eYb9zAGaio_o=oghajhfd7eav...@mail.gmail.com/T/#mb43103277c79ef06b884359209e817db1c136140
> 
> Signed-off-by: Paul Burton 
> Cc: Amir Goldstein 
> Cc: Arnd Bergmann 
> Cc: Jan Kara 
> Cc: linux-a...@vger.kernel.org
> Cc: linux-m...@vger.kernel.org

Applied to mips-fixes.

Thanks,
Paul

[ This message was auto-generated; if you believe anything is incorrect
  then please email paul.bur...@mips.com to report it. ]


Re: [PATCH] security: inode: fix a missing check for securityfs_create_file

2019-03-15 Thread Tetsuo Handa
On 2019/03/16 6:00, Kangjie Lu wrote:
> securityfs_create_file  may fail. The fix checks its status and
> returns the error code upstream if it fails.

Failure in __init functions of vmlinux means that the system failed
before the global /sbin/init process starts. There is little value
with continuing the boot process. Calling panic() or BUG_ON() will
be OK, for the userspace will be get confused by lack of that file
even if we continued without securityfs entry in /proc/filesystems .

> 
> Signed-off-by: Kangjie Lu 
> 
> ---
> Return the exact error code upstream.
> ---
>  security/inode.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/security/inode.c b/security/inode.c
> index b7772a9b315e..667f8b15027d 100644
> --- a/security/inode.c
> +++ b/security/inode.c
> @@ -339,6 +339,11 @@ static int __init securityfs_init(void)
>  #ifdef CONFIG_SECURITY
>   lsm_dentry = securityfs_create_file("lsm", 0444, NULL, NULL,
>   _ops);
> + if (IS_ERR(lsm_dentry)) {
> + unregister_filesystem(_type);
> + sysfs_remove_mount_point(kernel_kobj, "security");
> + return PTR_ERR(lsm_dentry);
> + }
>  #endif
>   return 0;
>  }
> 



Re: [PATCH] x86/vdso: include generic __lshrdi3 in 32-bit vDSO

2019-03-15 Thread Matthias Kaehlcke
Hi Nick,

On Fri, Mar 15, 2019 at 02:31:09PM -0700, 'Nick Desaulniers' via Clang Built 
Linux wrote:
> On Fri, Mar 15, 2019 at 12:54 PM Matthias Kaehlcke  wrote:
> >
> > Building the 32-bit vDSO with a recent clang version fails due
> > to undefined symbols:
> >
> > arch/x86/entry/vdso/vdso32.so.dbg: undefined symbols found
> >
> > The undefined symbol in this case is __lshrdi3, which is part of
> > the compiler runtime library, however the vDSO isn't linked against
> > this library.
> >
> > Include the kernel version of __lshrdi3 in the 32-bit vDSO build.
> 
> __lshrdi3 is used for "logical shift right double-word by int" (best
> guess), so anywhere there's a right shift of a u64.  Looks like
> there's a few of these in arch/x86/entry/vdso/, so it's legal for the
> compiler to emit this libcall.  Do you know which function
> specifically in the .so has a relocation referencing __lshrdi3
> specifically?

It's the right shifts in do_realtime() and do_monotonic().

> Is there a config I can set to reproduce this, in order to help
> test?

I encountered it with a Chrome OS specific configuration, but a
defconfig should do. Note that you probably need a development version
of clang to reproduce this.

> >
> > Signed-off-by: Matthias Kaehlcke 
> > ---
> >  arch/x86/entry/vdso/Makefile | 7 ++-
> >  lib/lshrdi3.c| 4 +++-
> >  2 files changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
> > index 5bfe2243a08f..7517cd87e10b 100644
> > --- a/arch/x86/entry/vdso/Makefile
> > +++ b/arch/x86/entry/vdso/Makefile
> > @@ -144,6 +144,7 @@ KBUILD_CFLAGS_32 += $(call cc-option, 
> > -fno-stack-protector)
> >  KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
> >  KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
> >  KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
> > +KBUILD_CFLAGS_32 += -DBUILD_VDSO
> >
> >  ifdef CONFIG_RETPOLINE
> >  ifneq ($(RETPOLINE_VDSO_CFLAGS),)
> > @@ -153,12 +154,16 @@ endif
> >
> >  $(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
> >
> > +$(obj)/vdso32/lshrdi3.o: $(srctree)/lib/lshrdi3.c FORCE
> > +   $(call if_changed_rule,cc_o_c)
> 
> + Masahiro to help look at this part (I don't understand this part
> of kbuild).

I bluntly stole that from arch/x86/purgatory/Makefile , which does
something similar.

> 
> > +
> >  $(obj)/vdso32.so.dbg: FORCE \
> >   $(obj)/vdso32/vdso32.lds \
> >   $(obj)/vdso32/vclock_gettime.o \
> >   $(obj)/vdso32/note.o \
> >   $(obj)/vdso32/system_call.o \
> > - $(obj)/vdso32/sigreturn.o
> > + $(obj)/vdso32/sigreturn.o \
> > + $(obj)/vdso32/lshrdi3.o
> > $(call if_changed,vdso)
> >
> >  #
> > diff --git a/lib/lshrdi3.c b/lib/lshrdi3.c
> > index 99cfa5721f2d..8a4fc6bcf3a4 100644
> > --- a/lib/lshrdi3.c
> > +++ b/lib/lshrdi3.c
> > @@ -16,7 +16,7 @@
> >   * to the Free Software Foundation, Inc.
> >   */
> >
> > -#include 
> > +#include 
> 
> Is this a simple cleanup, or?

The vDSO build is unhappy when modules.h draws in a whole bunch of
other kernel headers and export.h is all that's need. It seemed
reasonable to do the 'cleanup' in this patch since we touch it anyway
to place EXPORT_SYMBOL within an #ifdef.

> >  #include 
> >
> >  long long notrace __lshrdi3(long long u, word_type b)
> > @@ -42,4 +42,6 @@ long long notrace __lshrdi3(long long u, word_type b)
> >
> > return w.ll;
> >  }
> > +#ifndef BUILD_VDSO
> >  EXPORT_SYMBOL(__lshrdi3);
> > +#endif
> 
> Compilers (GCC and Clang) will always assume their runtime has these
> helper functions; whether or not they emit libcalls vs inline routines
> is implementation defined.  So I agree with this patch; I just would
> like to help confirm/test it.

Thanks for your help!

Matthias


Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread hpa
On March 15, 2019 3:06:37 PM PDT, Nick Desaulniers  
wrote:
>On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke 
>wrote:
>>
>> The compiler may emit calls to __lshrti3 from the compiler runtime
>> library, which results in undefined references:
>>
>> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
>>   include/linux/math64.h:186: undefined reference to `__lshrti3'
>
>Looks like Clang will emit this at -Oz (but not -O2):
>https://godbolt.org/z/w1_2YC
>
>>
>> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
>
>Has it changed since? If so why not a newer version of libgcc_s?
>
>>
>> Include the function for x86 builds with clang, which is the
>> environment where the above error was observed.
>>
>> Signed-off-by: Matthias Kaehlcke 
>> ---
>>  arch/x86/Kconfig   |  1 +
>>  include/linux/libgcc.h | 16 
>>  lib/Kconfig|  3 +++
>>  lib/Makefile   |  1 +
>>  lib/lshrti3.c  | 31 +++
>>  5 files changed, 52 insertions(+)
>>  create mode 100644 lib/lshrti3.c
>>
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index c1f9b3cf437c..a5e0d923845d 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -105,6 +105,7 @@ config X86
>> select GENERIC_IRQ_PROBE
>> select GENERIC_IRQ_RESERVATION_MODE
>> select GENERIC_IRQ_SHOW
>> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
>> select GENERIC_PENDING_IRQ  if SMP
>> select GENERIC_SMP_IDLE_THREAD
>> select GENERIC_STRNCPY_FROM_USER
>> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
>> index 32e1e0f4b2d0..a71036471838 100644
>> --- a/include/linux/libgcc.h
>> +++ b/include/linux/libgcc.h
>> @@ -22,15 +22,26 @@
>>  #include 
>>
>>  typedef int word_type __attribute__ ((mode (__word__)));
>> +typedef int TItype __attribute__ ((mode (TI)));
>
>Well that's an interesting new compiler attribute.
>https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
>Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
>typedef int TItype __mode(TI);
>
>>
>>  #ifdef __BIG_ENDIAN
>>  struct DWstruct {
>> int high, low;
>>  };
>> +
>> +struct DWstruct128 {
>> +   long long high, low;
>> +};
>> +
>>  #elif defined(__LITTLE_ENDIAN)
>>  struct DWstruct {
>> int low, high;
>>  };
>> +
>> +struct DWstruct128 {
>> +   long long low, high;
>> +};
>> +
>>  #else
>>  #error I feel sick.
>>  #endif
>> @@ -40,4 +51,9 @@ typedef union {
>> long long ll;
>>  } DWunion;
>>
>> +typedef union {
>> +   struct DWstruct128 s;
>> +   TItype ll;
>> +} DWunion128;
>> +
>>  #endif /* __ASM_LIBGCC_H */
>> diff --git a/lib/Kconfig b/lib/Kconfig
>> index a9e56539bd11..369e10259ea6 100644
>> --- a/lib/Kconfig
>> +++ b/lib/Kconfig
>> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
>>  config GENERIC_LIB_LSHRDI3
>> bool
>>
>> +config GENERIC_LIB_LSHRTI3
>> +   bool
>> +
>>  config GENERIC_LIB_MULDI3
>> bool
>>
>> diff --git a/lib/Makefile b/lib/Makefile
>> index 4e066120a0d6..42648411f451 100644
>> --- a/lib/Makefile
>> +++ b/lib/Makefile
>> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
>>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
>>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
>>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
>> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
>>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
>>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
>>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
>> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
>> new file mode 100644
>> index ..2d2123bb3030
>> --- /dev/null
>> +++ b/lib/lshrti3.c
>> @@ -0,0 +1,31 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +#include 
>> +#include 
>> +
>> +long long __lshrti3(long long u, word_type b)
>> +{
>> +   DWunion128 uu, w;
>> +   word_type bm;
>> +
>> +   if (b == 0)
>> +   return u;
>> +
>> +   uu.ll = u;
>> +   bm = 64 - b;
>> +
>> +   if (bm <= 0) {
>> +   w.s.high = 0;
>> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
>> +   } else {
>> +   const unsigned long long carries =
>> +   (unsigned long long) uu.s.high << bm;
>> +   w.s.high = (unsigned long long) uu.s.high >> b;
>> +   w.s.low = ((unsigned long long) uu.s.low >> b) |
>carries;
>> +   }
>> +
>> +   return w.ll;
>> +}
>> +#ifndef BUILD_VDSO
>> +EXPORT_SYMBOL(__lshrti3);
>> +#endif
>
>I don't think you want this.  Maybe that was carried over from
>https://lkml.org/lkml/2019/3/15/669
>by accident?  The above linkage error mentions arch/x86/kvm/x86.o
>which I wouldn't expect to be linked into the VDSO image?

Or just "u64"...
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: [GIT PULL] KVM changes for 5.1 merge window

2019-03-15 Thread pr-tracker-bot
The pull request you sent on Fri, 15 Mar 2019 22:07:42 +0100:

> https://git.kernel.org/pub/scm/virt/kvm/kvm.git tags/for-linus

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/636deed6c0bc137a7c4f4a97ae1fcf0ad75323da

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread hpa
On March 15, 2019 3:06:37 PM PDT, Nick Desaulniers  
wrote:
>On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke 
>wrote:
>>
>> The compiler may emit calls to __lshrti3 from the compiler runtime
>> library, which results in undefined references:
>>
>> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
>>   include/linux/math64.h:186: undefined reference to `__lshrti3'
>
>Looks like Clang will emit this at -Oz (but not -O2):
>https://godbolt.org/z/w1_2YC
>
>>
>> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).
>
>Has it changed since? If so why not a newer version of libgcc_s?
>
>>
>> Include the function for x86 builds with clang, which is the
>> environment where the above error was observed.
>>
>> Signed-off-by: Matthias Kaehlcke 
>> ---
>>  arch/x86/Kconfig   |  1 +
>>  include/linux/libgcc.h | 16 
>>  lib/Kconfig|  3 +++
>>  lib/Makefile   |  1 +
>>  lib/lshrti3.c  | 31 +++
>>  5 files changed, 52 insertions(+)
>>  create mode 100644 lib/lshrti3.c
>>
>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> index c1f9b3cf437c..a5e0d923845d 100644
>> --- a/arch/x86/Kconfig
>> +++ b/arch/x86/Kconfig
>> @@ -105,6 +105,7 @@ config X86
>> select GENERIC_IRQ_PROBE
>> select GENERIC_IRQ_RESERVATION_MODE
>> select GENERIC_IRQ_SHOW
>> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
>> select GENERIC_PENDING_IRQ  if SMP
>> select GENERIC_SMP_IDLE_THREAD
>> select GENERIC_STRNCPY_FROM_USER
>> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
>> index 32e1e0f4b2d0..a71036471838 100644
>> --- a/include/linux/libgcc.h
>> +++ b/include/linux/libgcc.h
>> @@ -22,15 +22,26 @@
>>  #include 
>>
>>  typedef int word_type __attribute__ ((mode (__word__)));
>> +typedef int TItype __attribute__ ((mode (TI)));
>
>Well that's an interesting new compiler attribute.
>https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
>Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
>typedef int TItype __mode(TI);
>
>>
>>  #ifdef __BIG_ENDIAN
>>  struct DWstruct {
>> int high, low;
>>  };
>> +
>> +struct DWstruct128 {
>> +   long long high, low;
>> +};
>> +
>>  #elif defined(__LITTLE_ENDIAN)
>>  struct DWstruct {
>> int low, high;
>>  };
>> +
>> +struct DWstruct128 {
>> +   long long low, high;
>> +};
>> +
>>  #else
>>  #error I feel sick.
>>  #endif
>> @@ -40,4 +51,9 @@ typedef union {
>> long long ll;
>>  } DWunion;
>>
>> +typedef union {
>> +   struct DWstruct128 s;
>> +   TItype ll;
>> +} DWunion128;
>> +
>>  #endif /* __ASM_LIBGCC_H */
>> diff --git a/lib/Kconfig b/lib/Kconfig
>> index a9e56539bd11..369e10259ea6 100644
>> --- a/lib/Kconfig
>> +++ b/lib/Kconfig
>> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
>>  config GENERIC_LIB_LSHRDI3
>> bool
>>
>> +config GENERIC_LIB_LSHRTI3
>> +   bool
>> +
>>  config GENERIC_LIB_MULDI3
>> bool
>>
>> diff --git a/lib/Makefile b/lib/Makefile
>> index 4e066120a0d6..42648411f451 100644
>> --- a/lib/Makefile
>> +++ b/lib/Makefile
>> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
>>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
>>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
>>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
>> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
>>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
>>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
>>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
>> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
>> new file mode 100644
>> index ..2d2123bb3030
>> --- /dev/null
>> +++ b/lib/lshrti3.c
>> @@ -0,0 +1,31 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +#include 
>> +#include 
>> +
>> +long long __lshrti3(long long u, word_type b)
>> +{
>> +   DWunion128 uu, w;
>> +   word_type bm;
>> +
>> +   if (b == 0)
>> +   return u;
>> +
>> +   uu.ll = u;
>> +   bm = 64 - b;
>> +
>> +   if (bm <= 0) {
>> +   w.s.high = 0;
>> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
>> +   } else {
>> +   const unsigned long long carries =
>> +   (unsigned long long) uu.s.high << bm;
>> +   w.s.high = (unsigned long long) uu.s.high >> b;
>> +   w.s.low = ((unsigned long long) uu.s.low >> b) |
>carries;
>> +   }
>> +
>> +   return w.ll;
>> +}
>> +#ifndef BUILD_VDSO
>> +EXPORT_SYMBOL(__lshrti3);
>> +#endif
>
>I don't think you want this.  Maybe that was carried over from
>https://lkml.org/lkml/2019/3/15/669
>by accident?  The above linkage error mentions arch/x86/kvm/x86.o
>which I wouldn't expect to be linked into the VDSO image?

If we compile with the default ABI we can simply link with libgcc; with 
-mregparm=3 all versions of gcc are broken.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: [GIT PULL] UML updates for 5.1-rc1

2019-03-15 Thread pr-tracker-bot
The pull request you sent on Tue, 12 Mar 2019 16:14:04 +0100:

> git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.git for-linus-5.1-rc1

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/6c83d0d5eb62846b8591884e246ab67d70b651ef

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc

2019-03-15 Thread Nick Desaulniers
On Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke  wrote:
>
> The compiler may emit calls to __lshrti3 from the compiler runtime
> library, which results in undefined references:
>
> arch/x86/kvm/x86.o: In function `mul_u64_u64_shr':
>   include/linux/math64.h:186: undefined reference to `__lshrti3'

Looks like Clang will emit this at -Oz (but not -O2):
https://godbolt.org/z/w1_2YC

>
> Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2).

Has it changed since? If so why not a newer version of libgcc_s?

>
> Include the function for x86 builds with clang, which is the
> environment where the above error was observed.
>
> Signed-off-by: Matthias Kaehlcke 
> ---
>  arch/x86/Kconfig   |  1 +
>  include/linux/libgcc.h | 16 
>  lib/Kconfig|  3 +++
>  lib/Makefile   |  1 +
>  lib/lshrti3.c  | 31 +++
>  5 files changed, 52 insertions(+)
>  create mode 100644 lib/lshrti3.c
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index c1f9b3cf437c..a5e0d923845d 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -105,6 +105,7 @@ config X86
> select GENERIC_IRQ_PROBE
> select GENERIC_IRQ_RESERVATION_MODE
> select GENERIC_IRQ_SHOW
> +   select GENERIC_LIB_LSHRTI3  if CC_IS_CLANG
> select GENERIC_PENDING_IRQ  if SMP
> select GENERIC_SMP_IDLE_THREAD
> select GENERIC_STRNCPY_FROM_USER
> diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h
> index 32e1e0f4b2d0..a71036471838 100644
> --- a/include/linux/libgcc.h
> +++ b/include/linux/libgcc.h
> @@ -22,15 +22,26 @@
>  #include 
>
>  typedef int word_type __attribute__ ((mode (__word__)));
> +typedef int TItype __attribute__ ((mode (TI)));

Well that's an interesting new compiler attribute.
https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do
Please use `__mode(TI)` from include/linux/compiler_attributes.h ex.
typedef int TItype __mode(TI);

>
>  #ifdef __BIG_ENDIAN
>  struct DWstruct {
> int high, low;
>  };
> +
> +struct DWstruct128 {
> +   long long high, low;
> +};
> +
>  #elif defined(__LITTLE_ENDIAN)
>  struct DWstruct {
> int low, high;
>  };
> +
> +struct DWstruct128 {
> +   long long low, high;
> +};
> +
>  #else
>  #error I feel sick.
>  #endif
> @@ -40,4 +51,9 @@ typedef union {
> long long ll;
>  } DWunion;
>
> +typedef union {
> +   struct DWstruct128 s;
> +   TItype ll;
> +} DWunion128;
> +
>  #endif /* __ASM_LIBGCC_H */
> diff --git a/lib/Kconfig b/lib/Kconfig
> index a9e56539bd11..369e10259ea6 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3
>  config GENERIC_LIB_LSHRDI3
> bool
>
> +config GENERIC_LIB_LSHRTI3
> +   bool
> +
>  config GENERIC_LIB_MULDI3
> bool
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 4e066120a0d6..42648411f451 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o
>  obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
>  obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o
>  obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
> +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o
>  obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
>  obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
>  obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
> diff --git a/lib/lshrti3.c b/lib/lshrti3.c
> new file mode 100644
> index ..2d2123bb3030
> --- /dev/null
> +++ b/lib/lshrti3.c
> @@ -0,0 +1,31 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include 
> +#include 
> +
> +long long __lshrti3(long long u, word_type b)
> +{
> +   DWunion128 uu, w;
> +   word_type bm;
> +
> +   if (b == 0)
> +   return u;
> +
> +   uu.ll = u;
> +   bm = 64 - b;
> +
> +   if (bm <= 0) {
> +   w.s.high = 0;
> +   w.s.low = (unsigned long long) uu.s.high >> -bm;
> +   } else {
> +   const unsigned long long carries =
> +   (unsigned long long) uu.s.high << bm;
> +   w.s.high = (unsigned long long) uu.s.high >> b;
> +   w.s.low = ((unsigned long long) uu.s.low >> b) | carries;
> +   }
> +
> +   return w.ll;
> +}
> +#ifndef BUILD_VDSO
> +EXPORT_SYMBOL(__lshrti3);
> +#endif

I don't think you want this.  Maybe that was carried over from
https://lkml.org/lkml/2019/3/15/669
by accident?  The above linkage error mentions arch/x86/kvm/x86.o
which I wouldn't expect to be linked into the VDSO image?
-- 
Thanks,
~Nick Desaulniers


Re: [PATCH 06/11] arm64: dts: meson-g12a-x96-max: add regulators

2019-03-15 Thread Martin Blumenstingl
Hi Neil and Guillaume,

On Mon, Mar 11, 2019 at 11:04 AM Neil Armstrong  wrote:
>
> From: Guillaume La Roque 
>
> Add system regulators for the X96 Max Set-Top-Box.
the hint from the "meson-g12a-sei510: add regulators" patch would be
great here as well:
  Still missing
  * VDD_EE (0.8V - PWM controlled)
  * VDD_CPU(PWM controlled)
  * VDDQ1_5

I'm not sure whether this board also has VDDQ1_5 though, but VDD_EE
and VDD_CPU should be very similar (or even identical)

>
> Signed-off-by: Guillaume La Roque 
> Signed-off-by: Neil Armstrong 
> ---
>  .../boot/dts/amlogic/meson-g12a-x96-max.dts   | 65 +++
>  1 file changed, 65 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/amlogic/meson-g12a-x96-max.dts 
> b/arch/arm64/boot/dts/amlogic/meson-g12a-x96-max.dts
> index 0edbd00b358f..21e5de48613e 100644
> --- a/arch/arm64/boot/dts/amlogic/meson-g12a-x96-max.dts
> +++ b/arch/arm64/boot/dts/amlogic/meson-g12a-x96-max.dts
> @@ -21,6 +21,71 @@
> device_type = "memory";
> reg = <0x0 0x0 0x0 0x4000>;
> };
> +
> +   flash_1v8: regulator-flash_1v8 {
> +   compatible = "regulator-fixed";
> +   regulator-name = "FLASH_1V8";
> +   regulator-min-microvolt = <180>;
> +   regulator-max-microvolt = <180>;
> +   vin-supply = <_3v3>;
> +   regulator-always-on;
> +   };
> +
> +   main_12v: regulator-main_12v {
> +   compatible = "regulator-fixed";
> +   regulator-name = "12V";
> +   regulator-min-microvolt = <1200>;
> +   regulator-max-microvolt = <1200>;
> +   regulator-always-on;
> +   };
mine has a 5V DC in. can you please check this on your board?


Regards
Martin


Re: [GIT PULL] UML updates for 5.1-rc1

2019-03-15 Thread Linus Torvalds
On Fri, Mar 15, 2019 at 3:01 PM Richard Weinberger
 wrote:
>
> *kind ping* to make sure this PR is not lost. :-)
> I guess you skipped this one too after the git.infradead.org outage.

Right you are. Thanks for the ping,

Linus


Re: [PATCH 04/11] arm64: dts: meson-g12a-u200: add regulators

2019-03-15 Thread Martin Blumenstingl
Hi Neil,

On Mon, Mar 11, 2019 at 10:57 AM Neil Armstrong  wrote:
>
> From: Jerome Brunet 
>
> Add system regulators for the S905D2 U200 reference design.
I find the hint in the meson-g12a-sei510 regulators patch very good:
  Still missing
  * VDD_EE (0.8V - PWM controlled)
  * VDD_CPU(PWM controlled)
  * VDDQ1_5

VDD_EE and VDD_CPU are *probably* going to be very similar across all
boards (Meson8b uses two slightly different PWM regulators on all
boards supported by mainline, but the basic concept is always the
same)
I'm not sure if VDDQ1_5 is specific to the SEI510 board though.

> Signed-off-by: Jerome Brunet 
> Signed-off-by: Neil Armstrong 
> ---
>  .../boot/dts/amlogic/meson-g12a-u200.dts  | 79 +++
>  1 file changed, 79 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/amlogic/meson-g12a-u200.dts 
> b/arch/arm64/boot/dts/amlogic/meson-g12a-u200.dts
> index f2afd0bf3e28..17696f356ff2 100644
> --- a/arch/arm64/boot/dts/amlogic/meson-g12a-u200.dts
> +++ b/arch/arm64/boot/dts/amlogic/meson-g12a-u200.dts
> @@ -14,13 +14,92 @@
> aliases {
> serial0 = _AO;
> };
> +
> chosen {
> stdout-path = "serial0:115200n8";
> };
> +
> memory@0 {
> device_type = "memory";
> reg = <0x0 0x0 0x0 0x4000>;
> };
there are two unrelated whitespace changes above.
please clean them up if you have to re-send this for whatever reason


Regards
Martin


Re: [GIT PULL] UML updates for 5.1-rc1

2019-03-15 Thread Richard Weinberger
On Tue, Mar 12, 2019 at 4:14 PM Richard Weinberger  wrote:
>
> Linus,
>
> The following changes since commit 1c163f4c7b3f621efff9b28a47abb36f7378d783:
>
>   Linux 5.0 (2019-03-03 15:21:29 -0800)
>
> are available in the Git repository at:
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml.git for-linus-5.1-rc1
>
> for you to fetch changes up to aea05eb56e47046de1e5b508d40931dca969f1e5:
>
>   um: Fix for a possible OOPS in ubd initialization (2019-03-06 22:39:18 
> +0100)
>
> 
> This pull request contains updates for UML:
>
> - Bugfix for the UML block device driver
>
> 
> Anton Ivanov (1):
>   um: Fix for a possible OOPS in ubd initialization
>
> YueHaibing (1):
>   um: Remove duplicated include from vector_user.c
>
>  arch/um/drivers/ubd_kern.c| 6 +++---
>  arch/um/drivers/vector_user.c | 3 ---
>  2 files changed, 3 insertions(+), 6 deletions(-)

*kind ping* to make sure this PR is not lost. :-)
I guess you skipped this one too after the git.infradead.org outage.

-- 
Thanks,
//richard


[PATCH 1/2] iio: light: vcnl4000 add support for the VCNL4040 proximity and light sensor

2019-03-15 Thread Angus Ainslie (Purism)
The VCNL4040 is almost identical to the VCNL4200 as far as register
layout goes but just need to check a different ID register location.

This does change the initialization sequence of the VCNL4200 to use word
writes instead of byte writes. The VCNL4200 datasheet says that word read
and writes should be used to access the registers but I don't have a 4200
to test with. The VCNL4040 doesn't initialize properly with the byte
writes.

devicetree hooks were also added.

Signed-off-by: Angus Ainslie (Purism) 
---
 drivers/iio/light/vcnl4000.c | 89 ++--
 1 file changed, 76 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 04fd0d4b6f19..6e1f02aa6696 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -10,13 +10,14 @@
  *
  * IIO driver for:
  *   VCNL4000/10/20 (7-bit I2C slave address 0x13)
+ *   VCNL4040 (7-bit I2C slave address 0x60)
  *   VCNL4200 (7-bit I2C slave address 0x51)
  *
  * TODO:
  *   allow to adjust IR current
  *   proximity threshold and event handling
  *   periodic ALS/proximity measurement (VCNL4010/20)
- *   interrupts (VCNL4010/20, VCNL4200)
+ *   interrupts (VCNL4010/20/40, VCNL4200)
  */
 
 #include 
@@ -30,6 +31,7 @@
 #define VCNL4000_DRV_NAME "vcnl4000"
 #define VCNL4000_PROD_ID   0x01
 #define VCNL4010_PROD_ID   0x02 /* for VCNL4020, VCNL4010 */
+#define VCNL4040_PROD_ID   0x86
 #define VCNL4200_PROD_ID   0x58
 
 #define VCNL4000_COMMAND   0x80 /* Command register */
@@ -49,6 +51,8 @@
 #define VCNL4200_AL_DATA   0x09 /* Ambient light data */
 #define VCNL4200_DEV_ID0x0e /* Device ID, slave address and 
version */
 
+#define VCNL4040_DEV_ID0x0c /* Device ID, slave address and 
version */
+
 /* Bit masks for COMMAND register */
 #define VCNL4000_AL_RDYBIT(6) /* ALS data ready? */
 #define VCNL4000_PS_RDYBIT(5) /* proximity data ready? */
@@ -58,6 +62,7 @@
 enum vcnl4000_device_ids {
VCNL4000,
VCNL4010,
+   VCNL4040,
VCNL4200,
 };
 
@@ -90,6 +95,7 @@ static const struct i2c_device_id vcnl4000_id[] = {
{ "vcnl4000", VCNL4000 },
{ "vcnl4010", VCNL4010 },
{ "vcnl4020", VCNL4010 },
+   { "vcnl4040", VCNL4040 },
{ "vcnl4200", VCNL4200 },
{ }
 };
@@ -128,31 +134,56 @@ static int vcnl4000_init(struct vcnl4000_data *data)
 
 static int vcnl4200_init(struct vcnl4000_data *data)
 {
-   int ret;
+   int ret, id;
 
ret = i2c_smbus_read_word_data(data->client, VCNL4200_DEV_ID);
if (ret < 0)
return ret;
 
-   if ((ret & 0xff) != VCNL4200_PROD_ID)
-   return -ENODEV;
+   id = ret & 0xff;
+
+   if (id != VCNL4200_PROD_ID) {
+   ret = i2c_smbus_read_word_data(data->client, VCNL4040_DEV_ID);
+   if (ret < 0)
+   return ret;
+
+   id = ret & 0xff;
+
+   if (id != VCNL4040_PROD_ID)
+   return -ENODEV;
+
+   }
+
+   dev_dbg(>client->dev, "device id 0x%x", id);
 
data->rev = (ret >> 8) & 0xf;
 
/* Set defaults and enable both channels */
-   ret = i2c_smbus_write_byte_data(data->client, VCNL4200_AL_CONF, 0x00);
+   ret = i2c_smbus_write_word_data(data->client, VCNL4200_AL_CONF, 0x00);
if (ret < 0)
return ret;
-   ret = i2c_smbus_write_byte_data(data->client, VCNL4200_PS_CONF1, 0x00);
+   ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, 0x00);
if (ret < 0)
return ret;
 
+   switch (id) {
+   case VCNL4200_PROD_ID:
+   /* Integration time is 50ms, but the experiments */
+   /* show 54ms in total. */
+   data->vcnl4200_al.sampling_rate = ktime_set(0, 54000 * 1000);
+   data->vcnl4200_ps.sampling_rate = ktime_set(0, 4200 * 1000);
+   break;
+   case VCNL4040_PROD_ID:
+   /* Integration time is 80ms, add 10ms. */
+   data->vcnl4200_al.sampling_rate = ktime_set(0, 10 * 1000);
+   data->vcnl4200_ps.sampling_rate = ktime_set(0, 10 * 1000);
+   break;
+   }
+
data->al_scale = 24000;
data->vcnl4200_al.reg = VCNL4200_AL_DATA;
data->vcnl4200_ps.reg = VCNL4200_PS_DATA;
-   /* Integration time is 50ms, but the experiments show 54ms in total. */
-   data->vcnl4200_al.sampling_rate = ktime_set(0, 54000 * 1000);
-   data->vcnl4200_ps.sampling_rate = ktime_set(0, 4200 * 1000);
+
data->vcnl4200_al.last_measurement = ktime_set(0, 0);
data->vcnl4200_ps.last_measurement = ktime_set(0, 0);
mutex_init(>vcnl4200_al.lock);
@@ -194,8 +225,11 @@ static int vcnl4000_measure(struct vcnl4000_data *data, u8 
req_mask,
 
ret = i2c_smbus_read_i2c_block_data(data->client,
data_reg, sizeof(buf), (u8 *) 

[PATCH 0/2] Add a VCNL4040 light and proximity driver

2019-03-15 Thread Angus Ainslie (Purism)
Extend the Vishay VCNL40x0/4200 driver to work with the VCNL4040
chip.

Angus Ainslie (Purism) (2):
  iio: light: vcnl4000 add support for the VCNL4040 proximity and light
sensor
  dt-bindings: iio: light: Document the VCNL4xx0 device tree bindings

 .../bindings/iio/light/vcnl4xx0.txt   | 15 
 drivers/iio/light/vcnl4000.c  | 89 ---
 2 files changed, 91 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/light/vcnl4xx0.txt

-- 
2.17.1



[PATCH 2/2] dt-bindings: iio: light: Document the VCNL4xx0 device tree bindings

2019-03-15 Thread Angus Ainslie (Purism)
devicetree hooks where added to the VCNL4xx0 light and proximity
sensor driver.

Signed-off-by: Angus Ainslie (Purism) 
---
 .../devicetree/bindings/iio/light/vcnl4xx0.txt| 15 +++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/light/vcnl4xx0.txt

diff --git a/Documentation/devicetree/bindings/iio/light/vcnl4xx0.txt 
b/Documentation/devicetree/bindings/iio/light/vcnl4xx0.txt
new file mode 100644
index ..d61cf3c121c3
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/light/vcnl4xx0.txt
@@ -0,0 +1,15 @@
+VISHAY VCNL4xx0 -  Ambient Light and proximity sensor
+
+This driver supports the VCNL4000/10/20/40 and VCNL4200
+
+Required properties:
+
+   -compatible: should be "vishay,vcnl4000" or "vishay,vcnl4040"
+   -reg: I2C address of the sensor, should be 0x60
+
+Example:
+
+light-sensor@60 {
+   compatible = "vishay,vcnl4040";
+   reg = <0x60>;
+};
-- 
2.17.1



Re: [PATCH 10/11] arm64: dts: meson-g12a-u200: Enable USB

2019-03-15 Thread Martin Blumenstingl
On Mon, Mar 11, 2019 at 10:58 AM Neil Armstrong  wrote:
>
> Enable the USB2 OTG and USB3 Host ports on the S905D2 Reference Design.
>
> Signed-off-by: Neil Armstrong 
I have no details on the U200 board (whether it has a micro USB OTG
port, etc.) but this looks sane so:
Acked-by: Martin Blumenstingl 


Re: [PATCH v2 0/4] Patches to allow consistent mmc / mmcblk numbering w/ device tree

2019-03-15 Thread Tim Harvey
Tim Harvey - Principal Software EngineerGateworks Corporation -
http://www.gateworks.com/3026 S. Higuera St. San Luis Obispo CA
93401805-781-2000
On Tue, Mar 5, 2019 at 4:39 AM Måns Rullgård  wrote:
>
> Douglas Anderson  writes:
>
> > This series picks patches from various different places to produce what
> > I consider the best solution to getting consistent mmc and mmcblk
> > ordering.
> >
> > Why consistent ordering and why not just use UUIDs?  IMHO consistent
> > ordering solves a few different problems:
> >
> > 1. For poor, feeble-minded humans like me, have sane numbering for
> >devices helps a lot.  When grepping through dmesg it's terribly handy
> >if a given SDMMC device has a consistent number.  I know that I can
> >do "dmesg | grep mmc0" or "dmesg | grep mmcblk0" to find info about
> >the eMMC.  I know that I can do "dmesg | grep mmc1" to find info
> >about the SD card slot.  I don't want it to matter which one probed
> >first, I don't want it to matter if I'm working on a variant of the
> >hardware that has the SD card slot disabled, and I don't want to care
> >what my boot device was.  Worrying about what device number I got
> >increases my cognitive load.
> >
> > 2. There are cases where it's not trivially easy during development to
> >use the UUID.  Specifically I work a lot with coreboot / depthcharge
> >as a BIOS.  When configured properly, that BIOS has a nice feature to
> >allow you to fetch the kernel and kernel command line from TFTP by
> >pressing Ctrl-N.  In this particular case the BIOS doesn't actually
> >know which disk I'd like for my root filesystem, so it's not so easy
> >for it to put the right UUID into the command line.  For this
> >purpose, knowing that "mmcblk0" will always refer to eMMC is handy.
> >
> > Changes in v2:
> > - Rebased atop mmc-next
> > - Stat dynamic allocation after fixed allocation; thanks Wolfram!
> > - rk3288 patch new for v2
> >
> > Douglas Anderson (1):
> >   ARM: dts: rockchip: Add mmc aliases for rk3288 platform
> >
> > Jaehoon Chung (1):
> >   Documentation: mmc: Document mmc aliases
> >
> > Stefan Agner (2):
> >   mmc: read mmc alias from device tree
> >   mmc: use SD/MMC host ID for block device name ID
> >
> >  Documentation/devicetree/bindings/mmc/mmc.txt | 11 +++
> >  arch/arm/boot/dts/rk3288.dtsi |  4 
> >  drivers/mmc/card/block.c  |  2 +-
> >  drivers/mmc/core/host.c   | 17 -
> >  4 files changed, 32 insertions(+), 2 deletions(-)
>
> Did anyone ever come up with an acceptable solution for this?  After
> three years, I'm getting tired of rebasing these patches onto every new
> kernel.
>
> UUIDs or similar are NOT an option for multiple reasons:
>
> - We have two rootfs partitions for ping-pong updates, so simply
>   referring to "the thing with ID foo" doesn't work.
>
> - Installing said updates needs direct access the device/partition,
>   which may not even have a filesystem.
>
> - The u-boot environment is stored in an eMMC "boot" partition, and
>   userspace needs to know where to find it.
>
> I'm sure I'm not the only one in a similar situation.
>
> Russel, feel free to shout abuse at me.  I don't care, but it makes you
> look stupid.
>

Completely agree here - we need a dt solution that allows us to
specify ordering.

I support a variety of IMX6 boards where for PCB routing reasons the
bootable MMC device is not always the first sdhc (sometimes the first
one is an SDIO radio for example). It seems ridiculous that I can't
handle this with:

aliases {
mmc0 =  /* MMC boot device */
mmc1 =  /* SDIO radio */
};

I see the imx6q-dhcom-som added in
52c7a088badd665a09ca9307ffa91e88d5686a7d re-defines the default
imx6qdl.dtsi mmc0-mmc3 aiases but I don't see any handling of this in
code anywhere - am I missing something?

Marek, why did you change the alias ordering for imx6q-dhcom-som.dtsi?
(maybe your carrying around a patch to make this useful?)

+   aliases {
+   mmc0 = 
+   mmc1 = 
+   mmc2 = 
+   mmc3 = 
+   };

Regards,

Tim


Re: [PATCH 11/11] arm64: dts: meson-g12a-x96-max: Enable USB

2019-03-15 Thread Martin Blumenstingl
Hi Neil,

On Mon, Mar 11, 2019 at 10:58 AM Neil Armstrong  wrote:
[...]
> + {
> +   status = "okay";
> +};
your patch description states that this enables the "USB host ports"
but dwc2 is only used for peripheral mode (meaning: dr_mode =
"peripheral" or dr_mode = "otg").
do we still need to enable dwc2 in a host-only configuration?


Regards
Martin


Re: [PATCH net-next] selftests: bpf: modify urandom_read and link it non-statically

2019-03-15 Thread Ivan Vecera


- Stanislav Fomichev  wrote:
> On 03/15, Ivan Vecera wrote:
> > On 15. 03. 19 21:08, Stanislav Fomichev wrote:
> > > On 03/15, Ivan Vecera wrote:
> > > > After some experiences I found that urandom_read does not need to be
> > > > linked statically. When the 'read' syscall call is moved to separate
> > > > non-inlined function then bpf_get_stackid() is able to find
> > > > the executable in stack trace and extract its build_id from it.
> > > But why? Do you have some problems with it being linked statically?
> > > 
> > Dependency... you don't need to install static glibc to compile the bpf
> > samples. Shared libc is available everytime.
> Oh, the distros that do -devel _and_ -static packages :-)
> 
> So your patch essentially adds a call, that leaves a trace on the stack
> with our build-id. I guess that works as well.

Without that additional call this does not work and build_id selftest fails.

I.


  1   2   3   4   5   >