[tip: core/rcu] torture: Make torture.sh throttle VERBOSE_TOROUT_*() for refscale

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: d97addc419e2b1cc1aba2ccc679373fbff7f2521
Gitweb:
https://git.kernel.org/tip/d97addc419e2b1cc1aba2ccc679373fbff7f2521
Author:Paul E. McKenney 
AuthorDate:Wed, 25 Nov 2020 20:49:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:44 -08:00

torture: Make torture.sh throttle VERBOSE_TOROUT_*() for refscale

This commit causes torture.sh to use the torture.verbose_sleep_frequency
kernel boot parameter to throttle verbose refscale output on large systems.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index e2c97f9..f2f9140 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -282,7 +282,7 @@ fi
 for prim in $primlist
 do
torture_bootargs="refscale.scale_type="$prim" 
refscale.nreaders=$HALF_ALLOTED_CPUS refscale.loops=1 refscale.holdoff=20 
torture.disable_onoff_at_boot"
-   torture_set "refscale-$prim" 
tools/testing/selftests/rcutorture/bin/kvm.sh --torture refscale --allcpus 
--duration 5 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --bootargs 
"verbose_batched=$VERBOSE_BATCH_CPUS" --trust-make
+   torture_set "refscale-$prim" 
tools/testing/selftests/rcutorture/bin/kvm.sh --torture refscale --allcpus 
--duration 5 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --bootargs 
"verbose_batched=$VERBOSE_BATCH_CPUS torture.verbose_sleep_frequency=8 
torture.verbose_sleep_duration=$VERBOSE_BATCH_CPUS" --trust-make
 done
 
 if test "$do_rcuscale" = yes


[tip: core/rcu] torture: Allow scenarios to be specified to torture.sh

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 8847bd4988321cbc66c94e9dfb05b401c50378a3
Gitweb:
https://git.kernel.org/tip/8847bd4988321cbc66c94e9dfb05b401c50378a3
Author:Paul E. McKenney 
AuthorDate:Fri, 27 Nov 2020 08:31:39 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:45 -08:00

torture: Allow scenarios to be specified to torture.sh

This commit adds --configs-rcutorture, --configs-locktorture, and
--configs-scftorture arguments to torture.sh, allowing the desired
set of scenarios to be passed to each.  The default for each has been
changed from a large-system-appropriate set to just CFLIST for each.
Users are encouraged to create scripts that provide appropriate settings
for their specific systems.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 46 +-
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index cf74123..f614011 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -30,6 +30,11 @@ then
VERBOSE_BATCH_CPUS=0
 fi
 
+# Configurations/scenarios.
+configs_rcutorture=
+configs_locktorture=
+configs_scftorture=
+
 # Default duration and apportionment.
 duration_base=10
 duration_rcutorture_frac=7
@@ -59,6 +64,9 @@ function doyesno () {
 
 usage () {
echo "Usage: $scriptname optional arguments:"
+   echo "   --configs-rcutorture \"config-file list w/ repeat factor 
(3*TINY01)\""
+   echo "   --configs-locktorture \"config-file list w/ repeat factor 
(10*LOCK01)\""
+   echo "   --configs-scftorture \"config-file list w/ repeat factor 
(2*CFLIST)\""
echo "   --doall"
echo "   --doallmodconfig / --do-no-allmodconfig"
echo "   --do-kasan / --do-no-kasan"
@@ -77,6 +85,21 @@ usage () {
 while test $# -gt 0
 do
case "$1" in
+   --config-rcutorture|--configs-rcutorture)
+   checkarg --configs-rcutorture "(list of config files)" "$#" 
"$2" '^[^/]\+$' '^--'
+   configs_rcutorture="$configs_rcutorture $2"
+   shift
+   ;;
+   --config-locktorture|--configs-locktorture)
+   checkarg --configs-locktorture "(list of config files)" "$#" 
"$2" '^[^/]\+$' '^--'
+   configs_locktorture="$configs_locktorture $2"
+   shift
+   ;;
+   --config-scftorture|--configs-scftorture)
+   checkarg --configs-scftorture "(list of config files)" "$#" 
"$2" '^[^/]\+$' '^--'
+   configs_scftorture="$configs_scftorture $2"
+   shift
+   ;;
--doall)
do_allmodconfig=yes
do_rcutorture=yes
@@ -155,18 +178,35 @@ T=/tmp/torture.sh.$$
 trap 'rm -rf $T' 0 2
 mkdir $T
 
+# Calculate rcutorture defaults and apportion time
+if test -z "$configs_rcutorture"
+then
+   configs_rcutorture=CFLIST
+fi
 duration_rcutorture=$((duration_base*duration_rcutorture_frac/10))
 if test "$duration_rcutorture" -eq 0
 then
echo " --- Zero time for rcutorture, disabling" | tee -a $T/log
do_rcutorture=no
 fi
+
+# Calculate locktorture defaults and apportion time
+if test -z "$configs_locktorture"
+then
+   configs_locktorture=CFLIST
+fi
 duration_locktorture=$((duration_base*duration_locktorture_frac/10))
 if test "$duration_locktorture" -eq 0
 then
echo " --- Zero time for locktorture, disabling" | tee -a $T/log
do_locktorture=no
 fi
+
+# Calculate scftorture defaults and apportion time
+if test -z "$configs_scftorture"
+then
+   configs_scftorture=CFLIST
+fi
 duration_scftorture=$((duration_base*duration_scftorture_frac/10))
 if test "$duration_scftorture" -eq 0
 then
@@ -268,19 +308,19 @@ fi
 if test "$do_rcutorture" = "yes"
 then
torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 
torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=3"
-   torture_set "rcutorture" tools/testing/selftests/rcutorture/bin/kvm.sh 
--allcpus --duration "$duration_rcutorture" --configs "TREE10 4*CFLIST" 
--trust-make
+   torture_set "rcutorture" tools/testing/selftests/rcutorture/bin/kvm.sh 
--allcpus --duration "$duration_rcutorture" --configs "$configs_rcutorture" 
--trust-make
 fi
 
 if test "$do_locktorture" = "yes"
 then
torture_bootargs="torture.disable_onoff_at_boot"
-   torture_set "locktorture" tools/testing/selftests/rcutorture/bin/kvm.sh 
--torture lock --allcpus --duration "$duration_locktorture" --configs 
"14*CFLIST" --trust-make
+   torture_set "locktorture" tools/testing/selftests/rcutorture/bin/kvm.sh 
--torture lock --allcpus --duration "$duration_locktorture" --configs 
"$configs_locktorture" --trust-make
 fi
 
 if test "$do_scftorture" = "yes"
 then
torture_boot

[tip: core/rcu] torture: Make torture.sh refuse to do zero-length runs

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c679d90b21b76319b4a6c719442b6a1ff124b88d
Gitweb:
https://git.kernel.org/tip/c679d90b21b76319b4a6c719442b6a1ff124b88d
Author:Paul E. McKenney 
AuthorDate:Thu, 26 Nov 2020 13:29:24 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:44 -08:00

torture: Make torture.sh refuse to do zero-length runs

This commit causes torture.sh to check for zero-length runs and to take
the cowardly option of refusing to run them, logging its cowardice for
later inspection.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 25 ++
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index f2f9140..43ef2c0 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -151,16 +151,29 @@ do
shift
 done
 
-duration_rcutorture=$((duration_base*duration_rcutorture_frac/10))
-# Need to sum remaining weights, and if duration weights to zero,
-# set do_no_rcutorture. @@@
-duration_locktorture=$((duration_base*duration_locktorture_frac/10))
-duration_scftorture=$((duration_base*duration_scftorture_frac/10))
-
 T=/tmp/torture.sh.$$
 trap 'rm -rf $T' 0 2
 mkdir $T
 
+duration_rcutorture=$((duration_base*duration_rcutorture_frac/10))
+if test "$duration_rcutorture" -eq 0
+then
+   echo " --- Zero time for rcutorture, disabling" | tee -a $T/log
+   do_rcutorture=no
+fi
+duration_locktorture=$((duration_base*duration_locktorture_frac/10))
+if test "$duration_locktorture" -eq 0
+then
+   echo " --- Zero time for locktorture, disabling" | tee -a $T/log
+   do_locktorture=no
+fi
+duration_scftorture=$((duration_base*duration_scftorture_frac/10))
+if test "$duration_scftorture" -eq 0
+then
+   echo " --- Zero time for scftorture, disabling" | tee -a $T/log
+   do_scftorture=no
+fi
+
 touch $T/failures
 touch $T/successes
 


[tip: core/rcu] torture: Add command and results directory to torture.sh log

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c66c0f94b345600aea881f6c4a1dac0ff5dd1aa8
Gitweb:
https://git.kernel.org/tip/c66c0f94b345600aea881f6c4a1dac0ff5dd1aa8
Author:Paul E. McKenney 
AuthorDate:Fri, 27 Nov 2020 09:04:22 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:45 -08:00

torture: Add command and results directory to torture.sh log

This commit adds the command and arguments to the torture.sh log file, and
also outputs the results directory.  This latter allows impatient users
to quickly find the results that are being generated by the current run.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index f614011..90ca736 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -174,10 +174,17 @@ do
shift
 done
 
+ds="`date +%Y.%m.%d-%H.%M.%S`-torture"
+startdate="`date`"
+starttime="`get_starttime`"
+
 T=/tmp/torture.sh.$$
 trap 'rm -rf $T' 0 2
 mkdir $T
 
+echo " --- " $scriptname $args | tee -a $T/log
+echo " --- Results directory: " $ds | tee -a $T/log
+
 # Calculate rcutorture defaults and apportion time
 if test -z "$configs_rcutorture"
 then
@@ -217,10 +224,6 @@ fi
 touch $T/failures
 touch $T/successes
 
-ds="`date +%Y.%m.%d-%H.%M.%S`-torture"
-startdate="`date`"
-starttime="`get_starttime`"
-
 # torture_one - Does a single kvm.sh run.
 #
 # Usage:


[tip: core/rcu] rcutorture: Make synctype[] and nsynctype be static global

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 18fbf307b7319af3725c36e16af6ae9f35a8699c
Gitweb:
https://git.kernel.org/tip/18fbf307b7319af3725c36e16af6ae9f35a8699c
Author:Paul E. McKenney 
AuthorDate:Mon, 16 Nov 2020 16:46:06 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:10 -08:00

rcutorture: Make synctype[] and nsynctype be static global

Full testing of the new SRCU polling API requires that the fake writers
also use it in order to test concurrent calls to all of the API members,
especially start_poll_synchronize_srcu().  This commit prepares the ground
for this by making the synctype[] and nsynctype variables be static
globals so that the rcu_torture_fakewriter() function can access them.
Initialization of these variables is moved from rcu_torture_writer()
to a new rcu_torture_write_types() function that is invoked from
rcu_torture_init() just before the first writer kthread is spawned.

Link: https://lore.kernel.org/rcu/20201112201547.gf3365...@moria.home.lan/
Reported-by: Kent Overstreet 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 62 +++-
 1 file changed, 36 insertions(+), 26 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 1930d92..0d257e2 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1062,37 +1062,18 @@ rcu_torture_fqs(void *arg)
return 0;
 }
 
+// Used by writers to randomly choose from the available grace-period
+// primitives.  The only purpose of the initialization is to size the array.
+static int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC, RTWS_COND_GET, 
RTWS_POLL_GET, RTWS_SYNC };
+static int nsynctypes;
+
 /*
- * RCU torture writer kthread.  Repeatedly substitutes a new structure
- * for that pointed to by rcu_torture_current, freeing the old structure
- * after a series of grace periods (the "pipeline").
+ * Determine which grace-period primitives are available.
  */
-static int
-rcu_torture_writer(void *arg)
+static void rcu_torture_write_types(void)
 {
-   bool boot_ended;
-   bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal();
-   unsigned long cookie;
-   int expediting = 0;
-   unsigned long gp_snap;
bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
bool gp_poll1 = gp_poll, gp_sync1 = gp_sync;
-   int i;
-   int idx;
-   int oldnice = task_nice(current);
-   struct rcu_torture *rp;
-   struct rcu_torture *old_rp;
-   static DEFINE_TORTURE_RANDOM(rand);
-   bool stutter_waited;
-   int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
-  RTWS_COND_GET, RTWS_POLL_GET, RTWS_SYNC };
-   int nsynctypes = 0;
-
-   VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
-   if (!can_expedite)
-   pr_alert("%s" TORTURE_FLAG
-" GP expediting controlled from boot/sysfs for %s.\n",
-torture_type, cur_ops->name);
 
/* Initialize synctype[] array.  If none set, take default. */
if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_poll1 && !gp_sync1)
@@ -1127,6 +1108,34 @@ rcu_torture_writer(void *arg)
} else if (gp_sync && !cur_ops->sync) {
pr_alert("%s: gp_sync without primitives.\n", __func__);
}
+}
+
+/*
+ * RCU torture writer kthread.  Repeatedly substitutes a new structure
+ * for that pointed to by rcu_torture_current, freeing the old structure
+ * after a series of grace periods (the "pipeline").
+ */
+static int
+rcu_torture_writer(void *arg)
+{
+   bool boot_ended;
+   bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal();
+   unsigned long cookie;
+   int expediting = 0;
+   unsigned long gp_snap;
+   int i;
+   int idx;
+   int oldnice = task_nice(current);
+   struct rcu_torture *rp;
+   struct rcu_torture *old_rp;
+   static DEFINE_TORTURE_RANDOM(rand);
+   bool stutter_waited;
+
+   VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
+   if (!can_expedite)
+   pr_alert("%s" TORTURE_FLAG
+" GP expediting controlled from boot/sysfs for %s.\n",
+torture_type, cur_ops->name);
if (WARN_ONCE(nsynctypes == 0,
  "rcu_torture_writer: No update-side primitives.\n")) {
/*
@@ -2889,6 +2898,7 @@ rcu_torture_init(void)
 
/* Start up the kthreads. */
 
+   rcu_torture_write_types();
firsterr = torture_create_kthread(rcu_torture_writer, NULL,
  writer_task);
if (firsterr)


[tip: core/rcu] torture: Compress KASAN vmlinux files

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: e3e1a99787fcf6297990c3b6cf53f5f6ef5aed60
Gitweb:
https://git.kernel.org/tip/e3e1a99787fcf6297990c3b6cf53f5f6ef5aed60
Author:Paul E. McKenney 
AuthorDate:Fri, 11 Dec 2020 14:03:39 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:03:46 -08:00

torture: Compress KASAN vmlinux files

The sizes of vmlinux files built with KASAN enabled can approach a full
gigabyte, which can result in disk overflow sooner rather than later.
Fortunately, the xz command compresses them by almost an order of
magnitude.  This commit therefore uses xz to compress vmlinux file built
by torture.sh with KASAN enabled.

However, xz is not the fastest thing in the world.  In fact, it is way
slower than rotating-rust mass storage.  This commit therefore also adds a
--compress-kasan-vmlinux argument to specify the degree of xz concurrency,
which defaults to using all available CPUs if there are that many files in
need of compression.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/torture.sh | 48 +-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh 
b/tools/testing/selftests/rcutorture/bin/torture.sh
index 0867f30..ad7525b 100755
--- a/tools/testing/selftests/rcutorture/bin/torture.sh
+++ b/tools/testing/selftests/rcutorture/bin/torture.sh
@@ -36,7 +36,8 @@ configs_locktorture=
 configs_scftorture=
 kcsan_kmake_args=
 
-# Default duration and apportionment.
+# Default compression, duration, and apportionment.
+compress_kasan_vmlinux="`identify_qemu_vcpus`"
 duration_base=10
 duration_rcutorture_frac=7
 duration_locktorture_frac=1
@@ -65,6 +66,7 @@ function doyesno () {
 
 usage () {
echo "Usage: $scriptname optional arguments:"
+   echo "   --compress-kasan-vmlinux concurrency"
echo "   --configs-rcutorture \"config-file list w/ repeat factor 
(3*TINY01)\""
echo "   --configs-locktorture \"config-file list w/ repeat factor 
(10*LOCK01)\""
echo "   --configs-scftorture \"config-file list w/ repeat factor 
(2*CFLIST)\""
@@ -87,6 +89,11 @@ usage () {
 while test $# -gt 0
 do
case "$1" in
+   --compress-kasan-vmlinux)
+   checkarg --compress-kasan-vmlinux "(concurrency level)" $# "$2" 
'^[0-9][0-9]*$' '^error'
+   compress_kasan_vmlinux=$2
+   shift
+   ;;
--config-rcutorture|--configs-rcutorture)
checkarg --configs-rcutorture "(list of config files)" "$#" 
"$2" '^[^/]\+$' '^--'
configs_rcutorture="$configs_rcutorture $2"
@@ -391,8 +398,45 @@ fi
 echo Started at $startdate, ended at `date`, duration `get_starttime_duration 
$starttime`. | tee -a $T/log
 echo Summary: Successes: $nsuccesses Failures: $nfailures. | tee -a $T/log
 tdir="`cat $T/successes $T/failures | head -1 | awk '{ print $NF }' | sed -e 
's,/[^/]\+/*$,,'`"
+if test -n "$tdir" && test $compress_kasan_vmlinux -gt 0
+then
+   # KASAN vmlinux files can approach 1GB in size, so compress them.
+   echo Looking for KASAN files to compress: `date` > "$tdir/log-xz" 2>&1
+   find "$tdir" -type d -name '*-kasan' -print > $T/xz-todo
+   ncompresses=0
+   batchno=1
+   if test -s $T/xz-todo
+   then
+   echo Size before compressing: `du -sh $tdir | awk '{ print $1 
}'` `date` 2>&1 | tee -a "$tdir/log-xz" | tee -a $T/log
+   for i in `cat $T/xz-todo`
+   do
+   echo Compressing vmlinux files in ${i}: `date` >> 
"$tdir/log-xz" 2>&1
+   for j in $i/*/vmlinux
+   do
+   xz "$j" >> "$tdir/log-xz" 2>&1 &
+   ncompresses=$((ncompresses+1))
+   if test $ncompresses -ge $compress_kasan_vmlinux
+   then
+   echo Waiting for batch $batchno of 
$ncompresses compressions `date` | tee -a "$tdir/log-xz" | tee -a $T/log
+   wait
+   ncompresses=0
+   batchno=$((batchno+1))
+   fi
+   done
+   done
+   if test $ncompresses -gt 0
+   then
+   echo Waiting for final batch $batchno of $ncompresses 
compressions `date` | tee -a "$tdir/log-xz" | tee -a $T/log
+   fi
+   wait
+   echo Size after compressing: `du -sh $tdir | awk '{ print $1 
}'` `date` 2>&1 | tee -a "$tdir/log-xz" | tee -a $T/log
+   echo Total duration `get_starttime_duration $starttime`. | tee 
-a $T/log
+   else
+   echo No compression needed: `date` >> "$tdir/log-xz" 2>&1
+   fi
+fi
 if test -n "$tdir"
 then
-   cp

[tip: core/rcu] rcutorture: Use torture_hrtimeout_jiffies() to avoid busy-waits

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: ea31fd9ca87399ac4e03cd6c215451fa7dc366e4
Gitweb:
https://git.kernel.org/tip/ea31fd9ca87399ac4e03cd6c215451fa7dc366e4
Author:Paul E. McKenney 
AuthorDate:Tue, 17 Nov 2020 11:32:54 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:19 -08:00

rcutorture: Use torture_hrtimeout_jiffies() to avoid busy-waits

Because rcu_torture_writer() and rcu_torture_fakewriter() predate
hrtimers, they do timer-wheel-decoupled timed waits by using the
timer-wheel-based schedule_timeout_interruptible() functions in
conjunction with a random udelay()-based wait.  This latter unnecessarily
burns CPU time, so this commit instead uses torture_hrtimeout_jiffies()
to decouple from the timer wheels without busy-waiting.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 26 +++---
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 03bdf67..9414e30 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1194,10 +1194,7 @@ rcu_torture_writer(void *arg)
case RTWS_COND_GET:
rcu_torture_writer_state = RTWS_COND_GET;
gp_snap = cur_ops->get_gp_state();
-   i = torture_random(&rand) % 16;
-   if (i != 0)
-   schedule_timeout_interruptible(i);
-   udelay(torture_random(&rand) % 1000);
+   torture_hrtimeout_jiffies(torture_random(&rand) 
% 16, &rand);
rcu_torture_writer_state = RTWS_COND_SYNC;
cur_ops->cond_sync(gp_snap);
rcu_torture_pipe_update(old_rp);
@@ -1206,12 +1203,9 @@ rcu_torture_writer(void *arg)
rcu_torture_writer_state = RTWS_POLL_GET;
gp_snap = cur_ops->start_gp_poll();
rcu_torture_writer_state = RTWS_POLL_WAIT;
-   while (!cur_ops->poll_gp_state(gp_snap)) {
-   i = torture_random(&rand) % 16;
-   if (i != 0)
-   
schedule_timeout_interruptible(i);
-   udelay(torture_random(&rand) % 1000);
-   }
+   while (!cur_ops->poll_gp_state(gp_snap))
+   
torture_hrtimeout_jiffies(torture_random(&rand) % 16,
+ &rand);
rcu_torture_pipe_update(old_rp);
break;
case RTWS_SYNC:
@@ -1290,7 +1284,6 @@ static int
 rcu_torture_fakewriter(void *arg)
 {
unsigned long gp_snap;
-   int i;
DEFINE_TORTURE_RANDOM(rand);
 
VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
@@ -1311,19 +1304,14 @@ rcu_torture_fakewriter(void *arg)
break;
case RTWS_COND_GET:
gp_snap = cur_ops->get_gp_state();
-   i = torture_random(&rand) % 16;
-   if (i != 0)
-   schedule_timeout_interruptible(i);
-   udelay(torture_random(&rand) % 1000);
+   torture_hrtimeout_jiffies(torture_random(&rand) 
% 16, &rand);
cur_ops->cond_sync(gp_snap);
break;
case RTWS_POLL_GET:
gp_snap = cur_ops->start_gp_poll();
while (!cur_ops->poll_gp_state(gp_snap)) {
-   i = torture_random(&rand) % 16;
-   if (i != 0)
-   
schedule_timeout_interruptible(i);
-   udelay(torture_random(&rand) % 1000);
+   
torture_hrtimeout_jiffies(torture_random(&rand) % 16,
+ &rand);
}
break;
case RTWS_SYNC:


[tip: core/rcu] torture: Clean up after torture-test CPU hotplugging

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 0b962c8fe0e5c72a252b236814a6b6e9df799061
Gitweb:
https://git.kernel.org/tip/0b962c8fe0e5c72a252b236814a6b6e9df799061
Author:Paul E. McKenney 
AuthorDate:Sat, 19 Dec 2020 07:05:58 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:22 -08:00

torture: Clean up after torture-test CPU hotplugging

This commit puts all CPUs back online at the end of a torture test,
and also unconditionally puts them online at the beginning of the test,
rather than just in the case of built-in tests.  This allows torture tests
to behave in a predictable manner, whether built-in or based on modules.

Signed-off-by: Paul E. McKenney 
---
 kernel/torture.c | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 93eeeb2..507a20b 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -292,6 +292,26 @@ bool torture_online(int cpu, long *n_onl_attempts, long 
*n_onl_successes,
 EXPORT_SYMBOL_GPL(torture_online);
 
 /*
+ * Get everything online at the beginning and ends of tests.
+ */
+static void torture_online_all(char *phase)
+{
+   int cpu;
+   int ret;
+
+   for_each_possible_cpu(cpu) {
+   if (cpu_online(cpu))
+   continue;
+   ret = add_cpu(cpu);
+   if (ret && verbose) {
+   pr_alert("%s" TORTURE_FLAG
+"%s: %s online %d: errno %d\n",
+__func__, phase, torture_type, cpu, ret);
+   }
+   }
+}
+
+/*
  * Execute random CPU-hotplug operations at the interval specified
  * by the onoff_interval.
  */
@@ -301,25 +321,12 @@ torture_onoff(void *arg)
int cpu;
int maxcpu = -1;
DEFINE_TORTURE_RANDOM(rand);
-   int ret;
 
VERBOSE_TOROUT_STRING("torture_onoff task started");
for_each_online_cpu(cpu)
maxcpu = cpu;
WARN_ON(maxcpu < 0);
-   if (!IS_MODULE(CONFIG_TORTURE_TEST)) {
-   for_each_possible_cpu(cpu) {
-   if (cpu_online(cpu))
-   continue;
-   ret = add_cpu(cpu);
-   if (ret && verbose) {
-   pr_alert("%s" TORTURE_FLAG
-"%s: Initial online %d: errno %d\n",
-__func__, torture_type, cpu, ret);
-   }
-   }
-   }
-
+   torture_online_all("Initial");
if (maxcpu == 0) {
VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is 
disabled");
goto stop;
@@ -347,6 +354,7 @@ torture_onoff(void *arg)
 
 stop:
torture_kthread_stopping("torture_onoff");
+   torture_online_all("Final");
return 0;
 }
 


[tip: core/rcu] torture: Throttle VERBOSE_TOROUT_*() output

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 8a67a20bf257ca378d6e5588fbe4382966395ac8
Gitweb:
https://git.kernel.org/tip/8a67a20bf257ca378d6e5588fbe4382966395ac8
Author:Paul E. McKenney 
AuthorDate:Wed, 25 Nov 2020 13:00:04 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:21 -08:00

torture: Throttle VERBOSE_TOROUT_*() output

This commit adds kernel boot parameters torture.verbose_sleep_frequency
and torture.verbose_sleep_duration, which allow VERBOSE_TOROUT_*() output
to be throttled with periodic sleeps on large systems.

Signed-off-by: Paul E. McKenney 
---
 Documentation/admin-guide/kernel-parameters.txt |  8 ++-
 include/linux/torture.h | 15 ++--
 kernel/torture.c| 20 -
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 3244f9e..18f3aa7 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5337,6 +5337,14 @@
are running concurrently, especially on systems
with rotating-rust storage.
 
+   torture.verbose_sleep_frequency= [KNL]
+   Specifies how many verbose printk()s should be
+   emitted between each sleep.  The default of zero
+   disables verbose-printk() sleeping.
+
+   torture.verbose_sleep_duration= [KNL]
+   Duration of each verbose-printk() sleep in jiffies.
+
tp720=  [HW,PS2]
 
tpm_suspend_pcr=[HW,TPM]
diff --git a/include/linux/torture.h b/include/linux/torture.h
index 32941f8..d62d13c 100644
--- a/include/linux/torture.h
+++ b/include/linux/torture.h
@@ -32,9 +32,20 @@
 #define TOROUT_STRING(s) \
pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
 #define VERBOSE_TOROUT_STRING(s) \
-   do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); 
} while (0)
+do {   
\
+   if (verbose) {  
\
+   verbose_torout_sleep(); 
\
+   pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s);   
\
+   }   
\
+} while (0)
 #define VERBOSE_TOROUT_ERRSTRING(s) \
-   do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, 
s); } while (0)
+do {   
\
+   if (verbose) {  
\
+   verbose_torout_sleep(); 
\
+   pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s);
\
+   }   
\
+} while (0)
+void verbose_torout_sleep(void);
 
 /* Definitions for online/offline exerciser. */
 typedef void torture_ofl_func(void);
diff --git a/kernel/torture.c b/kernel/torture.c
index 7ad5c96..93eeeb2 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -48,6 +48,12 @@ module_param(disable_onoff_at_boot, bool, 0444);
 static bool ftrace_dump_at_shutdown;
 module_param(ftrace_dump_at_shutdown, bool, 0444);
 
+static int verbose_sleep_frequency;
+module_param(verbose_sleep_frequency, int, 0444);
+
+static int verbose_sleep_duration = 1;
+module_param(verbose_sleep_duration, int, 0444);
+
 static char *torture_type;
 static int verbose;
 
@@ -58,6 +64,20 @@ static int verbose;
 static int fullstop = FULLSTOP_RMMOD;
 static DEFINE_MUTEX(fullstop_mutex);
 
+static atomic_t verbose_sleep_counter;
+
+/*
+ * Sleep if needed from VERBOSE_TOROUT*().
+ */
+void verbose_torout_sleep(void)
+{
+   if (verbose_sleep_frequency > 0 &&
+   verbose_sleep_duration > 0 &&
+   !(atomic_inc_return(&verbose_sleep_counter) % 
verbose_sleep_frequency))
+   schedule_timeout_uninterruptible(verbose_sleep_duration);
+}
+EXPORT_SYMBOL_GPL(verbose_torout_sleep);
+
 /*
  * Schedule a high-resolution-timer sleep in nanoseconds, with a 32-bit
  * nanosecond random fuzz.  This function and its friends desynchronize


[tip: core/rcu] torture: Maintain torture-specific set of CPUs-online books

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 1afb95fee0342b8d9e05b0433e8e44a6dfd7c4a3
Gitweb:
https://git.kernel.org/tip/1afb95fee0342b8d9e05b0433e8e44a6dfd7c4a3
Author:Paul E. McKenney 
AuthorDate:Sat, 19 Dec 2020 07:34:35 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:22 -08:00

torture: Maintain torture-specific set of CPUs-online books

The TREE01 rcutorture scenario intentionally creates confusion as to the
number of available CPUs by specifying the "maxcpus=8 nr_cpus=43" kernel
boot parameters.  This can disable rcutorture's load shedding, which
currently uses num_online_cpus(), which would count the extra 35 CPUs.
However, the rcutorture guest OS will be provisioned with only 8 CPUs,
which means that rcutorture will present full load even when all but one
of the original 8 CPUs are offline.  This can result in spurious errors
due to extreme overloading of that single remaining CPU.

This commit therefore keeps a separate set of books on the number of
usable online CPUs, so that torture_num_online_cpus() is used for load
shedding instead of num_online_cpus().  Note that initial sizing must
use num_online_cpus() because torture_num_online_cpus() will return
NR_CPUS until shortly after torture_onoff_init() is invoked.

Reported-by: Frederic Weisbecker 
[ paulmck: Apply feedback from kernel test robot. ]
Signed-off-by: Paul E. McKenney 
---
 include/linux/torture.h |  5 +
 kernel/rcu/rcutorture.c |  4 ++--
 kernel/torture.c| 16 
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/linux/torture.h b/include/linux/torture.h
index d62d13c..0910c58 100644
--- a/include/linux/torture.h
+++ b/include/linux/torture.h
@@ -48,6 +48,11 @@ do { 
\
 void verbose_torout_sleep(void);
 
 /* Definitions for online/offline exerciser. */
+#ifdef CONFIG_HOTPLUG_CPU
+int torture_num_online_cpus(void);
+#else /* #ifdef CONFIG_HOTPLUG_CPU */
+static inline int torture_num_online_cpus(void) { return 1; }
+#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
 typedef void torture_ofl_func(void);
 bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
 unsigned long *sum_offl, int *min_onl, int *max_onl);
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 76c8386..a816df4 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -1338,7 +1338,7 @@ static void rcu_torture_reader_do_mbchk(long myid, struct 
rcu_torture *rtp,
struct torture_random_state *trsp)
 {
unsigned long loops;
-   int noc = num_online_cpus();
+   int noc = torture_num_online_cpus();
int rdrchked;
int rdrchker;
struct rcu_torture_reader_check *rtrcp; // Me.
@@ -1658,7 +1658,7 @@ rcu_torture_reader(void *arg)
torture_hrtimeout_us(500, 1000, &rand);
lastsleep = jiffies + 10;
}
-   while (num_online_cpus() < mynumonline && !torture_must_stop())
+   while (torture_num_online_cpus() < mynumonline && 
!torture_must_stop())
schedule_timeout_interruptible(HZ / 5);
stutter_wait("rcu_torture_reader");
} while (!torture_must_stop());
diff --git a/kernel/torture.c b/kernel/torture.c
index 507a20b..01e336f 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -175,6 +175,19 @@ static unsigned long sum_online;
 static int min_online = -1;
 static int max_online;
 
+static int torture_online_cpus = NR_CPUS;
+
+/*
+ * Some torture testing leverages confusion as to the number of online
+ * CPUs.  This function returns the torture-testing view of this number,
+ * which allows torture tests to load-balance appropriately.
+ */
+int torture_num_online_cpus(void)
+{
+   return READ_ONCE(torture_online_cpus);
+}
+EXPORT_SYMBOL_GPL(torture_num_online_cpus);
+
 /*
  * Attempt to take a CPU offline.  Return false if the CPU is already
  * offline or if it is not subject to CPU-hotplug operations.  The
@@ -229,6 +242,8 @@ bool torture_offline(int cpu, long *n_offl_attempts, long 
*n_offl_successes,
*min_offl = delta;
if (*max_offl < delta)
*max_offl = delta;
+   WRITE_ONCE(torture_online_cpus, torture_online_cpus - 1);
+   WARN_ON_ONCE(torture_online_cpus <= 0);
}
 
return true;
@@ -285,6 +300,7 @@ bool torture_online(int cpu, long *n_onl_attempts, long 
*n_onl_successes,
*min_onl = delta;
if (*max_onl < delta)
*max_onl = delta;
+   WRITE_ONCE(torture_online_cpus, torture_online_cpus + 1);
}
 
return true;


[tip: core/rcu] rcutorture: Add rcutree.use_softirq=0 to RUDE01 and TASKS01

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: d945f797e483979bdeded76266c366f35929afb8
Gitweb:
https://git.kernel.org/tip/d945f797e483979bdeded76266c366f35929afb8
Author:Paul E. McKenney 
AuthorDate:Fri, 25 Dec 2020 07:40:48 -08:00
Committer: Paul E. McKenney 
CommitterDate: Tue, 12 Jan 2021 09:55:23 -08:00

rcutorture: Add rcutree.use_softirq=0 to RUDE01 and TASKS01

RCU's rcutree.use_softirq=0 kernel boot parameter substitutes the per-CPU
rcuc kthreads for softirq, which is used in real-time installations.
However, none of the rcutorture scenarios test this parameter.
This commit therefore adds rcutree.use_softirq=0 to the RUDE01 and
TASKS01 rcutorture scenarios, both of which indirectly exercise RCU.

Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/configs/rcu/RUDE01.boot  | 1 +
 tools/testing/selftests/rcutorture/configs/rcu/TASKS01.boot | 1 +
 2 files changed, 2 insertions(+)

diff --git a/tools/testing/selftests/rcutorture/configs/rcu/RUDE01.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/RUDE01.boot
index 9363708..932a079 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/RUDE01.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/RUDE01.boot
@@ -1 +1,2 @@
 rcutorture.torture_type=tasks-rude
+rcutree.use_softirq=0
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TASKS01.boot 
b/tools/testing/selftests/rcutorture/configs/rcu/TASKS01.boot
index cd2a188..22cdece 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TASKS01.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TASKS01.boot
@@ -1 +1,2 @@
 rcutorture.torture_type=tasks
+rcutree.use_softirq=0


[tip: core/rcu] tools/nolibc: Add the definition for dup()

2021-02-12 Thread tip-bot2 for Willy Tarreau
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: c261145abd2461f921ac44ad70c28778dda710f4
Gitweb:
https://git.kernel.org/tip/c261145abd2461f921ac44ad70c28778dda710f4
Author:Willy Tarreau 
AuthorDate:Thu, 21 Jan 2021 08:20:23 +01:00
Committer: Paul E. McKenney 
CommitterDate: Thu, 21 Jan 2021 10:06:44 -08:00

tools/nolibc: Add the definition for dup()

This commit adds the dup() function, which was omitted when sys_dup()
was defined.  This is a port of nolibc's upstream commit 47cc42a79c92
to the Linux kernel.

Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc")
Tested-by: Valentin Schneider 
Tested-by: Mark Rutland  [arm64]
Signed-off-by: Willy Tarreau 
Signed-off-by: Paul E. McKenney 
---
 tools/include/nolibc/nolibc.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index e61d36c..3115c64 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -1853,6 +1853,18 @@ int close(int fd)
 }
 
 static __attribute__((unused))
+int dup(int fd)
+{
+   int ret = sys_dup(fd);
+
+   if (ret < 0) {
+   SET_ERRNO(-ret);
+   ret = -1;
+   }
+   return ret;
+}
+
+static __attribute__((unused))
 int dup2(int old, int new)
 {
int ret = sys_dup2(old, new);


[tip: core/rcu] tools/nolibc: Implement fork() based on clone()

2021-02-12 Thread tip-bot2 for Willy Tarreau
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: be60ca41fbaa93bc8f92b24e34d8cc62af41300d
Gitweb:
https://git.kernel.org/tip/be60ca41fbaa93bc8f92b24e34d8cc62af41300d
Author:Willy Tarreau 
AuthorDate:Thu, 21 Jan 2021 08:20:26 +01:00
Committer: Paul E. McKenney 
CommitterDate: Thu, 21 Jan 2021 10:06:44 -08:00

tools/nolibc: Implement fork() based on clone()

Some archs such as arm64 do not have fork() and have to use clone()
instead.  This commit therefore makes fork() use clone() when
available. This requires including signal.h to get the definition of
SIGCHLD.  This is a port of nolibc's upstream commit d2dc42fd6149 to
the Linux kernel.

Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc")
Tested-by: Valentin Schneider 
Tested-by: Mark Rutland  [arm64]
Signed-off-by: Willy Tarreau 
Signed-off-by: Paul E. McKenney 
---
 tools/include/nolibc/nolibc.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 9209da8..fdd5524 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -271,6 +271,8 @@ struct stat {
 #define WEXITSTATUS(status)   (((status) & 0xff00) >> 8)
 #define WIFEXITED(status) (((status) & 0x7f) == 0)
 
+/* for SIGCHLD */
+#include 
 
 /* Below comes the architecture-specific code. For each architecture, we have
  * the syscall declarations and the _start code definition. This is the only
@@ -1529,7 +1531,15 @@ int sys_execve(const char *filename, char *const argv[], 
char *const envp[])
 static __attribute__((unused))
 pid_t sys_fork(void)
 {
+#ifdef __NR_clone
+   /* note: some archs only have clone() and not fork(). Different archs
+* have a different API, but most archs have the flags on first arg and
+* will not use the rest with no other flag.
+*/
+   return my_syscall5(__NR_clone, SIGCHLD, 0, 0, 0, 0);
+#else
return my_syscall0(__NR_fork);
+#endif
 }
 
 static __attribute__((unused))


[tip: core/rcu] tools/nolibc: Implement poll() based on ppoll()

2021-02-12 Thread tip-bot2 for Willy Tarreau
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 5b1c827ca3b349801e2faff4185118cfa74f94c6
Gitweb:
https://git.kernel.org/tip/5b1c827ca3b349801e2faff4185118cfa74f94c6
Author:Willy Tarreau 
AuthorDate:Thu, 21 Jan 2021 08:20:27 +01:00
Committer: Paul E. McKenney 
CommitterDate: Thu, 21 Jan 2021 10:06:44 -08:00

tools/nolibc: Implement poll() based on ppoll()

Some architectures like arm64 do not implement poll() and have to use
ppoll() instead. This commit therefore makes poll() use ppoll() when
available. This is a port of nolibc's upstream commit 800f75c13ede to
the Linux kernel.

Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc")
Tested-by: Valentin Schneider 
Tested-by: Mark Rutland  [arm64]
Signed-off-by: Willy Tarreau 
Signed-off-by: Paul E. McKenney 
---
 tools/include/nolibc/nolibc.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index fdd5524..833693f 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -1652,7 +1652,17 @@ int sys_pivot_root(const char *new, const char *old)
 static __attribute__((unused))
 int sys_poll(struct pollfd *fds, int nfds, int timeout)
 {
+#if defined(__NR_ppoll)
+   struct timespec t;
+
+   if (timeout >= 0) {
+   t.tv_sec  = timeout / 1000;
+   t.tv_nsec = (timeout % 1000) * 100;
+   }
+   return my_syscall4(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, 
NULL);
+#else
return my_syscall3(__NR_poll, fds, nfds, timeout);
+#endif
 }
 
 static __attribute__((unused))


[tip: core/rcu] rcutorture: Make object_debug also double call_rcu() heap object

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: edf7b8417834c89d00ef88355ea507b0b0a630ae
Gitweb:
https://git.kernel.org/tip/edf7b8417834c89d00ef88355ea507b0b0a630ae
Author:Paul E. McKenney 
AuthorDate:Wed, 02 Dec 2020 17:52:07 -08:00
Committer: Paul E. McKenney 
CommitterDate: Wed, 06 Jan 2021 17:17:21 -08:00

rcutorture: Make object_debug also double call_rcu() heap object

This commit provides a test for call_rcu() printing the allocation address
of a double-freed callback by double-freeing a callback allocated via
kmalloc().  However, this commit does not depend on any other commit.

Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/rcutorture.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 007595d..76c8386 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -2782,6 +2782,7 @@ static void rcu_test_debug_objects(void)
 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
struct rcu_head rh1;
struct rcu_head rh2;
+   struct rcu_head *rhp = kmalloc(sizeof(*rhp), GFP_KERNEL);
 
init_rcu_head_on_stack(&rh1);
init_rcu_head_on_stack(&rh2);
@@ -2794,6 +2795,10 @@ static void rcu_test_debug_objects(void)
local_irq_disable(); /* Make it harder to start a new grace period. */
call_rcu(&rh2, rcu_torture_leak_cb);
call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
+   if (rhp) {
+   call_rcu(rhp, rcu_torture_leak_cb);
+   call_rcu(rhp, rcu_torture_err_cb); /* Another duplicate 
callback. */
+   }
local_irq_enable();
rcu_read_unlock();
preempt_enable();


[tip: core/rcu] tools/nolibc: Fix position of -lgcc in the documented example

2021-02-12 Thread tip-bot2 for Willy Tarreau
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 3c6ce7a5363723a05bfe3ee03a8d4a9b66841ae4
Gitweb:
https://git.kernel.org/tip/3c6ce7a5363723a05bfe3ee03a8d4a9b66841ae4
Author:Willy Tarreau 
AuthorDate:Thu, 21 Jan 2021 08:20:31 +01:00
Committer: Paul E. McKenney 
CommitterDate: Thu, 21 Jan 2021 10:06:45 -08:00

tools/nolibc: Fix position of -lgcc in the documented example

The documentation header in the nolibc.h file provides an example command
line, but it places the -lgcc argument before the source files, which
can fail with libgcc.a (e.g. on ARM when uidiv is needed). This commit
therefore moves the -lgcc to the end of the command line, hopefully
before this example leaks into makefiles.  This is a port of nolibc's
upstream commit b5e282089223 to the Linux kernel.

Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc")
Tested-by: Valentin Schneider 
Tested-by: Mark Rutland  [arm64]
Signed-off-by: Willy Tarreau 
Signed-off-by: Paul E. McKenney 
---
 tools/include/nolibc/nolibc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 618acad..8b7a983 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -71,7 +71,7 @@
  *
  * A simple static executable may be built this way :
  *  $ gcc -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \
- *-static -include nolibc.h -lgcc -o hello hello.c
+ *-static -include nolibc.h -o hello hello.c -lgcc
  *
  * A very useful calling convention table may be found here :
  *  http://man7.org/linux/man-pages/man2/syscall.2.html


[tip: core/rcu] tools/rcutorture: Fix position of -lgcc in mkinitrd.sh

2021-02-12 Thread tip-bot2 for Willy Tarreau
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 26cec81415b1b2a2e8e36ef0b24cf5f26467aa61
Gitweb:
https://git.kernel.org/tip/26cec81415b1b2a2e8e36ef0b24cf5f26467aa61
Author:Willy Tarreau 
AuthorDate:Thu, 21 Jan 2021 08:48:08 +01:00
Committer: Paul E. McKenney 
CommitterDate: Thu, 21 Jan 2021 10:06:45 -08:00

tools/rcutorture: Fix position of -lgcc in mkinitrd.sh

The -lgcc command-line argument is placed poorly in the build options,
which can result in build failures, for exapmle, on ARM when uidiv()
is required.  This commit therefore places the -lgcc argument after the
source files.

Fixes: b94ec36896da ("rcutorture: Make use of nolibc when available")
Tested-by: Valentin Schneider 
Tested-by: Mark Rutland  [arm64]
Signed-off-by: Willy Tarreau 
Signed-off-by: Paul E. McKenney 
---
 tools/testing/selftests/rcutorture/bin/mkinitrd.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/rcutorture/bin/mkinitrd.sh 
b/tools/testing/selftests/rcutorture/bin/mkinitrd.sh
index 38e424d..70d62fd 100755
--- a/tools/testing/selftests/rcutorture/bin/mkinitrd.sh
+++ b/tools/testing/selftests/rcutorture/bin/mkinitrd.sh
@@ -70,7 +70,7 @@ if echo -e "#if 
__x86_64__||__i386__||__i486__||__i586__||__i686__" \
# architecture supported by nolibc
 ${CROSS_COMPILE}gcc -fno-asynchronous-unwind-tables -fno-ident \
-nostdlib -include ../../../../include/nolibc/nolibc.h \
-   -lgcc -s -static -Os -o init init.c
+   -s -static -Os -o init init.c -lgcc
 else
${CROSS_COMPILE}gcc -s -static -Os -o init init.c
 fi


[tip: core/rcu] mm: Make mem_dump_obj() handle vmalloc() memory

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 98f180837a896ecedf8f7e12af22b57f271d43c9
Gitweb:
https://git.kernel.org/tip/98f180837a896ecedf8f7e12af22b57f271d43c9
Author:Paul E. McKenney 
AuthorDate:Tue, 08 Dec 2020 16:13:57 -08:00
Committer: Paul E. McKenney 
CommitterDate: Fri, 22 Jan 2021 15:24:04 -08:00

mm: Make mem_dump_obj() handle vmalloc() memory

This commit adds vmalloc() support to mem_dump_obj().  Note that the
vmalloc_dump_obj() function combines the checking and dumping, in
contrast with the split between kmem_valid_obj() and kmem_dump_obj().
The reason for the difference is that the checking in the vmalloc()
case involves acquiring a global lock, and redundant acquisitions of
global locks should be avoided, even on not-so-fast paths.

Note that this change causes on-stack variables to be reported as
vmalloc() storage from kernel_clone() or similar, depending on the degree
of inlining that your compiler does.  This is likely more helpful than
the earlier "non-paged (local) memory".

Cc: Andrew Morton 
Cc: Joonsoo Kim 
Cc: 
Reported-by: Andrii Nakryiko 
Acked-by: Vlastimil Babka 
Tested-by: Naresh Kamboju 
Signed-off-by: Paul E. McKenney 
---
 include/linux/vmalloc.h |  6 ++
 mm/util.c   | 14 --
 mm/vmalloc.c| 12 
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 80c0181..c18f475 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -246,4 +246,10 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
 int register_vmap_purge_notifier(struct notifier_block *nb);
 int unregister_vmap_purge_notifier(struct notifier_block *nb);
 
+#ifdef CONFIG_MMU
+bool vmalloc_dump_obj(void *object);
+#else
+static inline bool vmalloc_dump_obj(void *object) { return false; }
+#endif
+
 #endif /* _LINUX_VMALLOC_H */
diff --git a/mm/util.c b/mm/util.c
index 92f23d2..5487022 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -996,18 +996,20 @@ int __weak memcmp_pages(struct page *page1, struct page 
*page2)
  */
 void mem_dump_obj(void *object)
 {
+   if (kmem_valid_obj(object)) {
+   kmem_dump_obj(object);
+   return;
+   }
+   if (vmalloc_dump_obj(object))
+   return;
if (!virt_addr_valid(object)) {
if (object == NULL)
pr_cont(" NULL pointer.\n");
else if (object == ZERO_SIZE_PTR)
pr_cont(" zero-size pointer.\n");
else
-   pr_cont(" non-paged (local) memory.\n");
-   return;
-   }
-   if (kmem_valid_obj(object)) {
-   kmem_dump_obj(object);
+   pr_cont(" non-paged memory.\n");
return;
}
-   pr_cont(" non-slab memory.\n");
+   pr_cont(" non-slab/vmalloc memory.\n");
 }
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 4d88fe5..c274ea4 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3448,6 +3448,18 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int 
nr_vms)
 }
 #endif /* CONFIG_SMP */
 
+bool vmalloc_dump_obj(void *object)
+{
+   struct vm_struct *vm;
+   void *objp = (void *)PAGE_ALIGN((unsigned long)object);
+
+   vm = find_vm_area(objp);
+   if (!vm)
+   return false;
+   pr_cont(" vmalloc allocated at %pS\n", vm->caller);
+   return true;
+}
+
 #ifdef CONFIG_PROC_FS
 static void *s_start(struct seq_file *m, loff_t *pos)
__acquires(&vmap_purge_lock)


[tip: core/rcu] percpu_ref: Dump mem_dump_obj() info upon reference-count underflow

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: 3375efeddf6972df47df26a5b5c643189bd3c02a
Gitweb:
https://git.kernel.org/tip/3375efeddf6972df47df26a5b5c643189bd3c02a
Author:Paul E. McKenney 
AuthorDate:Tue, 08 Dec 2020 14:43:43 -08:00
Committer: Paul E. McKenney 
CommitterDate: Fri, 22 Jan 2021 15:24:23 -08:00

percpu_ref: Dump mem_dump_obj() info upon reference-count underflow

Reference-count underflow for percpu_ref is detected in the RCU callback
percpu_ref_switch_to_atomic_rcu(), and the resulting warning does not
print anything allowing easy identification of which percpu_ref use
case is underflowing.  This is of course not normally a problem when
developing a new percpu_ref use case because it is most likely that
the problem resides in this new use case.  However, when deploying a
new kernel to a large set of servers, the underflow might well be a new
corner case in any of the old percpu_ref use cases.

This commit therefore calls mem_dump_obj() to dump out any additional
available information on the underflowing percpu_ref instance.

Cc: Ming Lei 
Cc: Jens Axboe 
Cc: Joonsoo Kim 
Reported-by: Andrii Nakryiko 
Tested-by: Naresh Kamboju 
Signed-off-by: Paul E. McKenney 
---
 lib/percpu-refcount.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index e59eda0..a1071cd 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -168,6 +169,7 @@ static void percpu_ref_switch_to_atomic_rcu(struct rcu_head 
*rcu)
struct percpu_ref_data, rcu);
struct percpu_ref *ref = data->ref;
unsigned long __percpu *percpu_count = percpu_count_ptr(ref);
+   static atomic_t underflows;
unsigned long count = 0;
int cpu;
 
@@ -191,9 +193,13 @@ static void percpu_ref_switch_to_atomic_rcu(struct 
rcu_head *rcu)
 */
atomic_long_add((long)count - PERCPU_COUNT_BIAS, &data->count);
 
-   WARN_ONCE(atomic_long_read(&data->count) <= 0,
- "percpu ref (%ps) <= 0 (%ld) after switching to atomic",
- data->release, atomic_long_read(&data->count));
+   if (WARN_ONCE(atomic_long_read(&data->count) <= 0,
+ "percpu ref (%ps) <= 0 (%ld) after switching to atomic",
+ data->release, atomic_long_read(&data->count)) &&
+   atomic_inc_return(&underflows) < 4) {
+   pr_err("%s(): percpu_ref underflow", __func__);
+   mem_dump_obj(data);
+   }
 
/* @ref is viewed as dead on all CPUs, send out switch confirmation */
percpu_ref_call_confirm_rcu(rcu);


[tip: core/rcu] mm: Make mem_dump_obj() handle NULL and zero-sized pointers

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: b70fa3b12fc8d2b870d1ac7fd44da89271eb8705
Gitweb:
https://git.kernel.org/tip/b70fa3b12fc8d2b870d1ac7fd44da89271eb8705
Author:Paul E. McKenney 
AuthorDate:Tue, 08 Dec 2020 15:26:22 -08:00
Committer: Paul E. McKenney 
CommitterDate: Fri, 22 Jan 2021 15:23:57 -08:00

mm: Make mem_dump_obj() handle NULL and zero-sized pointers

This commit makes mem_dump_obj() call out NULL and zero-sized pointers
specially instead of classifying them as non-paged memory.

Cc: Christoph Lameter 
Cc: Pekka Enberg 
Cc: David Rientjes 
Cc: Joonsoo Kim 
Cc: Andrew Morton 
Cc: 
Reported-by: Andrii Nakryiko 
Acked-by: Vlastimil Babka 
Tested-by: Naresh Kamboju 
Signed-off-by: Paul E. McKenney 
---
 mm/util.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index da46f9d..92f23d2 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -997,7 +997,12 @@ int __weak memcmp_pages(struct page *page1, struct page 
*page2)
 void mem_dump_obj(void *object)
 {
if (!virt_addr_valid(object)) {
-   pr_cont(" non-paged (local) memory.\n");
+   if (object == NULL)
+   pr_cont(" NULL pointer.\n");
+   else if (object == ZERO_SIZE_PTR)
+   pr_cont(" zero-size pointer.\n");
+   else
+   pr_cont(" non-paged (local) memory.\n");
return;
}
if (kmem_valid_obj(object)) {


[tip: core/rcu] rcu: Make call_rcu() print mem_dump_obj() info for double-freed callback

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: b4b7914a6a73fc169fd1ce2fcd78a1d83d9528a9
Gitweb:
https://git.kernel.org/tip/b4b7914a6a73fc169fd1ce2fcd78a1d83d9528a9
Author:Paul E. McKenney 
AuthorDate:Tue, 08 Dec 2020 13:45:49 -08:00
Committer: Paul E. McKenney 
CommitterDate: Fri, 22 Jan 2021 15:24:16 -08:00

rcu: Make call_rcu() print mem_dump_obj() info for double-freed callback

The debug-object double-free checks in __call_rcu() print out the
RCU callback function, which is usually sufficient to track down the
double free.  However, all uses of things like queue_rcu_work() will
have the same RCU callback function (rcu_work_rcufn() in this case),
so a diagnostic message for a double queue_rcu_work() needs more than
just the callback function.

This commit therefore calls mem_dump_obj() to dump out any additional
available information on the double-freed callback.

Cc: Christoph Lameter 
Cc: Pekka Enberg 
Cc: David Rientjes 
Cc: Joonsoo Kim 
Cc: Andrew Morton 
Cc: 
Reported-by: Andrii Nakryiko 
Tested-by: Naresh Kamboju 
Signed-off-by: Paul E. McKenney 
---
 kernel/rcu/tree.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 40e5e3d..84513c5 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -2941,6 +2941,7 @@ static void check_cb_ovld(struct rcu_data *rdp)
 static void
 __call_rcu(struct rcu_head *head, rcu_callback_t func)
 {
+   static atomic_t doublefrees;
unsigned long flags;
struct rcu_data *rdp;
bool was_alldone;
@@ -2954,8 +2955,10 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func)
 * Use rcu:rcu_callback trace event to find the previous
 * time callback was passed to __call_rcu().
 */
-   WARN_ONCE(1, "__call_rcu(): Double-freed CB %p->%pS()!!!\n",
- head, head->func);
+   if (atomic_inc_return(&doublefrees) < 4) {
+   pr_err("%s(): Double-freed CB %p->%pS()!!!  ", 
__func__, head, head->func);
+   mem_dump_obj(head);
+   }
WRITE_ONCE(head->func, rcu_leak_callback);
return;
}


[tip: core/rcu] mm: Make mem_obj_dump() vmalloc() dumps include start and length

2021-02-12 Thread tip-bot2 for Paul E. McKenney
The following commit has been merged into the core/rcu branch of tip:

Commit-ID: bd34dcd4120d7e358baac9c22ef1321bd0c22079
Gitweb:
https://git.kernel.org/tip/bd34dcd4120d7e358baac9c22ef1321bd0c22079
Author:Paul E. McKenney 
AuthorDate:Wed, 09 Dec 2020 15:15:27 -08:00
Committer: Paul E. McKenney 
CommitterDate: Fri, 22 Jan 2021 15:24:10 -08:00

mm: Make mem_obj_dump() vmalloc() dumps include start and length

This commit adds the starting address and number of pages to the vmalloc()
information dumped by way of vmalloc_dump_obj().

Cc: Andrew Morton 
Cc: Joonsoo Kim 
Cc: 
Reported-by: Andrii Nakryiko 
Suggested-by: Vlastimil Babka 
Acked-by: Vlastimil Babka 
Tested-by: Naresh Kamboju 
Signed-off-by: Paul E. McKenney 
---
 mm/vmalloc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index c274ea4..e3229ff 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3456,7 +3456,8 @@ bool vmalloc_dump_obj(void *object)
vm = find_vm_area(objp);
if (!vm)
return false;
-   pr_cont(" vmalloc allocated at %pS\n", vm->caller);
+   pr_cont(" %u-page vmalloc region starting at %#lx allocated at %pS\n",
+   vm->nr_pages, (unsigned long)vm->addr, vm->caller);
return true;
 }
 


Re: [RESEND RFC PATCH v2] arm64: Exposes support for 32-bit syscalls

2021-02-12 Thread Mark Brown
On Fri, Feb 12, 2021 at 11:30:41AM +, Steven Price wrote:
> On 11/02/2021 20:21, sonicadvan...@gmail.com wrote:

> > Why do we need compatibility layers?
> > There are ARMv8 CPUs that only support AArch64 but still need to run
> > AArch32 applications.
> > Cortex-A34/R82 and other cores are prime examples of this.
> > Additionally if a user is needing to run legacy 32-bit x86 software, it
> > needs the same compatibility layer.

> Unless I'm much mistaken QEMU's user mode already does this - admittedly I
> don't tend to run "legacy 32-bit x86 software".

Yes, this has been deployed on Debian for a long time - you can install
any combination of Debian architectures on a single system and it will
use qemu to run binaries that can't be supported natively by the
hardware.


signature.asc
Description: PGP signature


Re: [PATCH 4/4] perf report: Fix return value when loading PE DSO

2021-02-12 Thread Arnaldo Carvalho de Melo
Em Wed, Feb 10, 2021 at 02:18:02PM -0500, Nicholas Fraser escreveu:
> The first time dso__load() was called on a PE file it always returned -1
> error. This caused the first call to map__find_symbol() to always fail
> on a PE file so the first sample from each PE file always had symbol
> . Subsequent samples succeed however because the DSO is already
> loaded.
> 
> This fixes dso__load() to return 0 when successfully loading a DSO with
> libbfd.

You forgot to add this:

Fixes: eac9a4342e5447ca ("perf symbols: Try reading the symbol table with 
libbfd")

This helps, for instance, the sta...@kernel.org guys, since their
scripts will scrape this and find that it should also go to whatever
stable releases are based on:

  $ git tag --contains eac9a4342e5447ca | grep ^v[45].* | grep -v -- -rc
  v5.10
  $

Applied and added the Fixes tag,

- Arnaldo
 
> Signed-off-by: Nicholas Fraser 
> ---
>  tools/perf/util/symbol.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index aa9ae875b995..492c873713cc 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1861,8 +1861,10 @@ int dso__load(struct dso *dso, struct map *map)
>   if (nsexit)
>   nsinfo__mountns_enter(dso->nsinfo, &nsc);
>  
> - if (bfdrc == 0)
> + if (bfdrc == 0) {
> + ret = 0;
>   break;
> + }
>  
>   if (!is_reg || sirc < 0)
>   continue;
> -- 
> 2.30.0
> 

-- 

- Arnaldo


Re: [PATCH] spi: Skip zero-length transfers in spi_transfer_one_message()

2021-02-12 Thread Mark Brown
On Thu, Feb 11, 2021 at 07:08:20PM +0100, Nicolas Saenz Julienne wrote:

> - if (xfer->tx_buf || xfer->rx_buf) {
> + if ((xfer->tx_buf || xfer->rx_buf) && xfer->len) {

I think the issue here is more that some users were passing in buffers
with zero length transfers, the above check was already intended to
catch this case but was working on the assumption that if there was
nothing to transfer then no buffer would be provided.


signature.asc
Description: PGP signature


Re: [GIT PULL tip/core/rcu] RCU, LKMM, and KCSAN commits for v5.12

2021-02-12 Thread Ingo Molnar


* Paul E. McKenney  wrote:

> Hello, Ingo!
> 
> This pull request contains changes for RCU, KCSAN, LKMM, and nolibc.
> You can pull the entire group using branch for-mingo.  Or, if you prefer,
> you can pull them separately, using for-mingo-rcu to pull the RCU changes,
> for-mingo-kcsan to pull the KCSAN changes, for-mingo-lkmm to pull the
> LKMM changes, and for-mingo-nolibc to pull the noclib changes.
> 
> The changes are as follows:
> 
> 1.RCU updates (for-mingo-rcu):

> 4.Fixes to nolibc that allows it to run once again on ARMv8.
>   https://lore.kernel.org/lkml/20210121072031.23777-...@1wt.eu/

Pulled these two into tip:core/rcu - as nolibc's main (only?) usecase 
within the kernel is torture-testing.

> 2.Kernel concurrency sanitizer (KCSAN) updates from Marco Elver.
>   
> https://lore.kernel.org/lkml/20210106173323.GA23292@paulmck-ThinkPad-P72/

> 3.Linux-kernel memory model (LKMM) updates.
>   
> https://lore.kernel.org/lkml/20210106173548.GA23664@paulmck-ThinkPad-P72/

Pulled these two into tip:locking/core.

Thanks Paul!

Ingo


Re: [PATCH v13 6/7] arm64: mte: Report async tag faults before suspend

2021-02-12 Thread Lorenzo Pieralisi
On Fri, Feb 12, 2021 at 12:00:15PM +, Lorenzo Pieralisi wrote:
> On Thu, Feb 11, 2021 at 03:33:52PM +, Vincenzo Frascino wrote:
> > When MTE async mode is enabled TFSR_EL1 contains the accumulative
> > asynchronous tag check faults for EL1 and EL0.
> > 
> > During the suspend/resume operations the firmware might perform some
> > operations that could change the state of the register resulting in
> > a spurious tag check fault report.
> > 
> > Report asynchronous tag faults before suspend and clear the TFSR_EL1
> > register after resume to prevent this to happen.
> > 
> > Cc: Catalin Marinas 
> > Cc: Will Deacon 
> > Cc: Lorenzo Pieralisi 
> > Signed-off-by: Vincenzo Frascino 
> > ---
> >  arch/arm64/include/asm/mte.h |  4 
> >  arch/arm64/kernel/mte.c  | 20 
> >  arch/arm64/kernel/suspend.c  |  3 +++
> >  3 files changed, 27 insertions(+)
> > 
> > diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
> > index 43169b978cd3..33e88a470357 100644
> > --- a/arch/arm64/include/asm/mte.h
> > +++ b/arch/arm64/include/asm/mte.h
> > @@ -41,6 +41,7 @@ void mte_sync_tags(pte_t *ptep, pte_t pte);
> >  void mte_copy_page_tags(void *kto, const void *kfrom);
> >  void flush_mte_state(void);
> >  void mte_thread_switch(struct task_struct *next);
> > +void mte_suspend_enter(void);
> >  void mte_suspend_exit(void);
> >  long set_mte_ctrl(struct task_struct *task, unsigned long arg);
> >  long get_mte_ctrl(struct task_struct *task);
> > @@ -66,6 +67,9 @@ static inline void flush_mte_state(void)
> >  static inline void mte_thread_switch(struct task_struct *next)
> >  {
> >  }
> > +static inline void mte_suspend_enter(void)
> > +{
> > +}
> >  static inline void mte_suspend_exit(void)
> >  {
> >  }
> > diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> > index f5aa5bea6dfe..de905102245a 100644
> > --- a/arch/arm64/kernel/mte.c
> > +++ b/arch/arm64/kernel/mte.c
> > @@ -258,12 +258,32 @@ void mte_thread_switch(struct task_struct *next)
> > mte_check_tfsr_el1();
> >  }
> >  
> > +void mte_suspend_enter(void)
> > +{
> > +   if (!system_supports_mte())
> > +   return;
> > +
> > +   /*
> > +* The barriers are required to guarantee that the indirect writes
> > +* to TFSR_EL1 are synchronized before we report the state.
> > +*/
> > +   dsb(nsh);
> > +   isb();
> > +
> > +   /* Report SYS_TFSR_EL1 before suspend entry */
> > +   mte_check_tfsr_el1();
> > +}
> > +
> >  void mte_suspend_exit(void)
> >  {
> > if (!system_supports_mte())
> > return;
> >  
> > update_gcr_el1_excl(gcr_kernel_excl);
> > +
> > +   /* Clear SYS_TFSR_EL1 after suspend exit */
> > +   write_sysreg_s(0, SYS_TFSR_EL1);
> 
> AFAICS it is not needed, it is done already in __cpu_setup() (that is
> called by cpu_resume on return from cpu_suspend() from firmware).
> 
> However, I have a question. We are relying on context switch to set
> sctlr_el1_tfc0 right ? If that's the case, till the thread resuming from
> low power switches context we are running with SCTLR_EL1_TCF0 not
> reflecting the actual value.

Forget this, we obviously restore sctlr_el1 on resume (cpu_do_resume()).

With the line above removed:

Reviewed-by: Lorenzo Pieralisi 

> Just making sure that I understand it correctly, I need to check the
> resume from suspend-to-RAM path, it is something that came up with perf
> save/restore already in the past.
> 
> Lorenzo
> 
> > +
> >  }
> >  
> >  long set_mte_ctrl(struct task_struct *task, unsigned long arg)
> > diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c
> > index a67b37a7a47e..25a02926ad88 100644
> > --- a/arch/arm64/kernel/suspend.c
> > +++ b/arch/arm64/kernel/suspend.c
> > @@ -91,6 +91,9 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned 
> > long))
> > unsigned long flags;
> > struct sleep_stack_data state;
> >  
> > +   /* Report any MTE async fault before going to suspend */
> > +   mte_suspend_enter();
> > +
> > /*
> >  * From this point debug exceptions are disabled to prevent
> >  * updates to mdscr register (saved and restored along with
> > -- 
> > 2.30.0
> > 
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


Re: possible deadlock in start_this_handle (2)

2021-02-12 Thread Michal Hocko
On Fri 12-02-21 12:22:07, Matthew Wilcox wrote:
> On Fri, Feb 12, 2021 at 08:18:11PM +0900, Tetsuo Handa wrote:
> > On 2021/02/12 1:41, Michal Hocko wrote:
> > > But I suspect we have drifted away from the original issue. I thought
> > > that a simple check would help us narrow down this particular case and
> > > somebody messing up from the IRQ context didn't sound like a completely
> > > off.
> > > 
> > 
> >  From my experience at 
> > https://lkml.kernel.org/r/201409192053.ihj35462.jlomosoffvt...@i-love.sakura.ne.jp
> >  ,
> > I think we can replace direct PF_* manipulation with macros which do not 
> > receive "struct task_struct *" argument.
> > Since TASK_PFA_TEST()/TASK_PFA_SET()/TASK_PFA_CLEAR() are for manipulating 
> > PFA_* flags on a remote thread, we can
> > define similar ones for manipulating PF_* flags on current thread. Then, 
> > auditing dangerous users becomes easier.
> 
> No, nobody is manipulating another task's GFP flags.

Agreed. And nobody should be manipulating PF flags on remote tasks
either.

-- 
Michal Hocko
SUSE Labs


Re: [PATCH 3/4] perf archive: Fix filtering of empty build-ids

2021-02-12 Thread Arnaldo Carvalho de Melo
Em Wed, Feb 10, 2021 at 02:17:49PM -0500, Nicholas Fraser escreveu:
> A non-existent build-id used to be treated as all-zero SHA-1 hash.
> Build-ids are now variable width. A non-existent build-id is an empty
> string and "perf buildid-list" pads this with spaces.
> 
> This fixes "perf-archive" to skip missing build-ids by skipping lines
> that start with a padding space rather than with zeroes.
> 
> Signed-off-by: Nicholas Fraser 
> ---
>  tools/perf/perf-archive.sh | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/perf/perf-archive.sh b/tools/perf/perf-archive.sh
> index 0cfb3e2cefef..133f0eddbcc4 100644
> --- a/tools/perf/perf-archive.sh
> +++ b/tools/perf/perf-archive.sh
> @@ -20,9 +20,8 @@ else
>  fi
>  
>  BUILDIDS=$(mktemp /tmp/perf-archive-buildids.XX)
> -NOBUILDID=
>  
> -perf buildid-list -i $PERF_DATA --with-hits | grep -v "^$NOBUILDID " > 
> $BUILDIDS
> +perf buildid-list -i $PERF_DATA --with-hits | grep -v "^ " > $BUILDIDS
>  if [ ! -s $BUILDIDS ] ; then
>   echo "perf archive: no build-ids found"
>   rm $BUILDIDS || true

What should we do when using older files? We have to support both cases.

- Arnaldo


Re: linux-next: manual merge of the spi tree with the powerpc tree

2021-02-12 Thread Mark Brown
On Fri, Feb 12, 2021 at 03:31:42PM +1100, Stephen Rothwell wrote:

> BTW Mark: the author's address in 258ea99fe25a uses a non existent domain :-(

Ugh, I think that's something gone wrong with b4 :(  A bit late now to
try to fix it up.


signature.asc
Description: PGP signature


Re: [PATCH 2/4] perf report: Load PE files from debug cache only

2021-02-12 Thread Arnaldo Carvalho de Melo
Em Wed, Feb 10, 2021 at 02:17:38PM -0500, Nicholas Fraser escreveu:
> dso__load_bfd_symbols() attempts to load a DSO at its original path,
> then closes it and loads the file in the debug cache. This is incorrect.
> It should ignore the original file and work with only the debug cache.
> The original file may have changed or may not even exist, for example if
> the debug cache has been transferred to another machine via "perf
> archive".
> 
> This fix makes it only load the file in the debug cache.

Well this improves your current use case and only affects PE files, so I
am applying, but consider a slightly different workflow:

 1. perf record ./foo.exe
 2. perf report # works, finds the file in the ~/.debug cache, as stored
# by 'perf record'
 3. rm -rf ~/.debug # I need more space
 4. perf report # Fails, as it looks only in the ~/.debug cache, that
# was nuked


So at 4 it should look at the original pathname, and hope for the best.

All this is moot if we have something like a build-id in PE files,
where we can look in any order since we'll verify the unique ID to see
if it is the one we need, right?

- Arnaldo
 
> Signed-off-by: Nicholas Fraser 
> ---
>  tools/perf/util/symbol.c | 8 +---
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 64a039cbba1b..aa9ae875b995 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1569,7 +1569,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char 
> *debugfile)
>   u_int i;
>   u64 start, len;
>  
> - abfd = bfd_openr(dso->long_name, NULL);
> + abfd = bfd_openr(debugfile, NULL);
>   if (!abfd)
>   return -1;
>  
> @@ -1586,12 +1586,6 @@ int dso__load_bfd_symbols(struct dso *dso, const char 
> *debugfile)
>   if (section)
>   dso->text_offset = section->vma - section->filepos;
>  
> - bfd_close(abfd);
> -
> - abfd = bfd_openr(debugfile, NULL);
> - if (!abfd)
> - return -1;
> -
>   if (!bfd_check_format(abfd, bfd_object)) {
>   pr_debug2("%s: cannot read %s bfd file.\n", __func__,
> debugfile);
> -- 
> 2.30.0
> 

-- 

- Arnaldo


Re: [PATCH v2 1/3] misc/pvpanic: split-up generic and platform dependent code

2021-02-12 Thread kernel test robot
Hi Mihai,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linux/master]
[also build test WARNING on soc/for-next linus/master v5.11-rc7]
[cannot apply to char-misc/char-misc-testing next-20210211]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Mihai-Carabas/misc-pvpanic-split-up-generic-and-platform-dependent-code/20210212-181711
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
2ab38c17aac10bf55ab3efde4c4db3893d8691d2
config: i386-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
# 
https://github.com/0day-ci/linux/commit/17d14b4802b75b93f10e01153b0e395f6a638492
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Mihai-Carabas/misc-pvpanic-split-up-generic-and-platform-dependent-code/20210212-181711
git checkout 17d14b4802b75b93f10e01153b0e395f6a638492
# save the attached .config to linux build tree
make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> drivers/misc/pvpanic/pvpanic-common.c:47:6: warning: no previous prototype 
>> for 'pvpanic_probe' [-Wmissing-prototypes]
  47 | void pvpanic_probe(void __iomem *pbase)
 |  ^
>> drivers/misc/pvpanic/pvpanic-common.c:54:6: warning: no previous prototype 
>> for 'pvpanic_remove' [-Wmissing-prototypes]
  54 | void pvpanic_remove(void)
 |  ^~


vim +/pvpanic_probe +47 drivers/misc/pvpanic/pvpanic-common.c

46  
  > 47  void pvpanic_probe(void __iomem *pbase)
48  {
49  base = pbase;
50  atomic_notifier_chain_register(&panic_notifier_list,
51 &pvpanic_panic_nb);
52  }
53  
  > 54  void pvpanic_remove(void)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [patch 2/3] nohz: change signal tick dependency to wakeup CPUs of member tasks

2021-02-12 Thread Frederic Weisbecker
On Thu, Jan 28, 2021 at 05:21:36PM -0300, Marcelo Tosatti wrote:
> Rather than waking up all nohz_full CPUs on the system, only wakeup 
> the target CPUs of member threads of the signal.
> 
> Reduces interruptions to nohz_full CPUs.
> 
> Signed-off-by: Marcelo Tosatti 
> 
> Index: linux-2.6/kernel/time/tick-sched.c
> ===
> --- linux-2.6.orig/kernel/time/tick-sched.c
> +++ linux-2.6/kernel/time/tick-sched.c
> @@ -444,9 +444,20 @@ EXPORT_SYMBOL_GPL(tick_nohz_dep_clear_ta
>   * Set a per-taskgroup tick dependency. Posix CPU timers need this in order 
> to elapse
>   * per process timers.
>   */
> -void tick_nohz_dep_set_signal(struct signal_struct *sig, enum tick_dep_bits
> bit)

Why not keeping the signal struct as a parameter?

Thanks.


Re: [PATCH] Add the latency-collector to tools

2021-02-12 Thread Viktor.Rosendahl
On Thu, 2021-02-11 at 14:56 -0500, Steven Rostedt wrote:
> On Thu, 11 Feb 2021 17:17:42 +0100
> Viktor Rosendahl  wrote:
> 
> > It seems to work but I discovered during testing that it seems like newer
> > kernels have a tendency to lose some latencies in longer bursts. I guess
> > this
> > is likely to be another regression in the preemptirqsoff tracer.
> 
> Not sure what you mean by the above. I'd be interested in fixing it if is
> really a problem.


Sorry, my bad; I should have been more specific.

Yesterday, when I tested the latency-collector, I could see that there were
clear signs of missing latencies. I used preemptirq_delay_test to generate
bursts of 10 and never got any stack traces from the 10th latency (nor the 9th
or 8th). 

I think I used 2000us as a threshold and generated latencies of 3000us.

Also, sometimes, I could see that there were not enough (meaning 9) messages
like "printout skipped due to random delay" before a "randomly sleep for 1000 ms
before print", and then the stack trace would point to a latency from the
beginning of the burst, and not the last, as would be expected if the latency-
collector slept for 1000 ms.

I could see the problem also without the latency-collector, because if I
generated a burst of 10 and then checked /sys/kernel/tracing/trace, I would not
see the the stack trace from the 10th latency but from one of the earlier ones,
that is, I would for example see the preemptirqtest_2 function in the trace,
instead of preemptirqtest_9, as expected. IIRC, I sometimes saw
the reemptirqtest_0 function, indicating that only the first was captured and
the rest were lost.

However, for some reason I cannot reproduce the behavior now, allthough I use
exactly the same kernel.

Because humans are more often at fault than computers, I cannot deny the
possibility that I would have misconfigured something and it was all the result
of a faulty test.

I will let you know if come up with a way of reproducing this behavior later. I
cannot spend more time on it right now.

> 
> 
> 
> I didn't look too deeply at the rest, just skimmed it basically, and I
> tried it out.
> 
> I'm fine with pulling this into my queue, as it's just a tool and wont
> cause any other issues. I can move some of the files in scripts that deals
> with tracing into the tools/tracing directory too. Maybe this should be
> placed in a sub directory? tools/tracing/latency/ ?
> 
> Feel free to submit a proper patch (proper change log, etc).
> 

Ok, thanks, I think that I have incorporated all of your suggestions in the
patch that I already sent out earlier today.

best regards,

Viktor



Re: [PATCH v4 net-next 7/9] net: mscc: ocelot: use separate flooding PGID for broadcast

2021-02-12 Thread Vladimir Oltean
On Fri, Feb 12, 2021 at 03:05:29AM +0200, Vladimir Oltean wrote:
> From: Vladimir Oltean 
> 
> In preparation of offloading the bridge port flags which have
> independent settings for unknown multicast and for broadcast, we should
> also start reserving one destination Port Group ID for the flooding of
> broadcast packets, to allow configuring it individually.
> 
> Signed-off-by: Vladimir Oltean 
> Reviewed-by: Florian Fainelli 
> ---

After more testing with the ocelot-8021q tagger too, not just the
default NPI-based one, I noticed that I introduced a regression.

devlink-sb tells me that broadcast packets remain stuck in the ingress
queues of the front-panel ports instead of being forwarded to the CPU.
This is because I forgot this:

-[cut here]-
 drivers/net/dsa/ocelot/felix.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index 96d9d13c5ae0..2771560cef61 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -299,6 +299,7 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int 
cpu)
cpu_flood = ANA_PGID_PGID_PGID(BIT(ocelot->num_phys_ports));
ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_UC);
ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC);
+   ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC);
 
felix->dsa_8021q_ctx = kzalloc(sizeof(*felix->dsa_8021q_ctx),
   GFP_KERNEL);
-[cut here]-

If there is no other feedback on this series, can I send this as a
follow-up fixup? Thanks.


[PATCH][next] octeontx2-pf: Fix out-of-bounds read in otx2_get_fecparam()

2021-02-12 Thread Gustavo A. R. Silva
Code at line 967 implies that rsp->fwdata.supported_fec may be up to 4:

 967: if (rsp->fwdata.supported_fec <= FEC_MAX_INDEX)

If rsp->fwdata.supported_fec evaluates to 4, then there is an
out-of-bounds read at line 971 because fec is an array with
a maximum of 4 elements:

 954 const int fec[] = {
 955 ETHTOOL_FEC_OFF,
 956 ETHTOOL_FEC_BASER,
 957 ETHTOOL_FEC_RS,
 958 ETHTOOL_FEC_BASER | ETHTOOL_FEC_RS};
 959 #define FEC_MAX_INDEX 4

 971: fecparam->fec = fec[rsp->fwdata.supported_fec];

Fix this by properly indexing fec[] with rsp->fwdata.supported_fec - 1.
In this case the proper indexes 0 to 3 are used when
rsp->fwdata.supported_fec evaluates to a range of 1 to 4, correspondingly.

Fixes: d0cf9503e908 ("octeontx2-pf: ethtool fec mode support")
Addresses-Coverity-ID: 1501722 ("Out-of-bounds read")
Signed-off-by: Gustavo A. R. Silva 
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c 
b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
index 237e5d3321d4..f7e8ada32a26 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c
@@ -968,7 +968,7 @@ static int otx2_get_fecparam(struct net_device *netdev,
if (!rsp->fwdata.supported_fec)
fecparam->fec = ETHTOOL_FEC_NONE;
else
-   fecparam->fec = fec[rsp->fwdata.supported_fec];
+   fecparam->fec = fec[rsp->fwdata.supported_fec - 1];
}
return 0;
 }
-- 
2.27.0



Re: possible deadlock in start_this_handle (2)

2021-02-12 Thread Matthew Wilcox
On Fri, Feb 12, 2021 at 08:18:11PM +0900, Tetsuo Handa wrote:
> On 2021/02/12 1:41, Michal Hocko wrote:
> > But I suspect we have drifted away from the original issue. I thought
> > that a simple check would help us narrow down this particular case and
> > somebody messing up from the IRQ context didn't sound like a completely
> > off.
> > 
> 
>  From my experience at 
> https://lkml.kernel.org/r/201409192053.ihj35462.jlomosoffvt...@i-love.sakura.ne.jp
>  ,
> I think we can replace direct PF_* manipulation with macros which do not 
> receive "struct task_struct *" argument.
> Since TASK_PFA_TEST()/TASK_PFA_SET()/TASK_PFA_CLEAR() are for manipulating 
> PFA_* flags on a remote thread, we can
> define similar ones for manipulating PF_* flags on current thread. Then, 
> auditing dangerous users becomes easier.

No, nobody is manipulating another task's GFP flags.


Re: [PATCH v8 1/4] KEYS: trusted: Add generic trusted keys framework

2021-02-12 Thread Jarkko Sakkinen
On Thu, Feb 11, 2021 at 11:34:21AM +0100, Ahmad Fatoum wrote:
> Hello Jarkko,
> 
> On 10.02.21 18:00, Jarkko Sakkinen wrote:
> > On Tue, Nov 03, 2020 at 09:31:43PM +0530, Sumit Garg wrote:
> >> +  case Opt_new:
> >> +  key_len = payload->key_len;
> >> +  ret = static_call(trusted_key_get_random)(payload->key,
> >> +key_len);
> >> +  if (ret != key_len) {
> >> +  pr_info("trusted_key: key_create failed (%d)\n", ret);
> >> +  goto out;
> >> +  }
> > 
> > This repeats a regression in existing code, i.e. does not check
> > "ret < 0" condition. I noticed this now when I rebased the code
> > on top of my fixes.
> > 
> > I.e. it's fixed in my master branch, which caused a merge conflict,
> > and I found this.
> 
> Does that mean this series will go out for the next merge window?
> Can you point me where your git tree is, so I can rebase on top?

No I mean the bug that is propagated here is fixed in my master
branch, i.e. get_random() should check also '< 0' condition.

/Jarkko


Re: [PATCH] drivers: mmc: host: Retire MMC_GOLDFISH

2021-02-12 Thread Ulf Hansson
On Tue, 9 Feb 2021 at 20:09,  wrote:
>
> From: Roman Kiryanov 
>
> Android Studio Emulator no longer uses
> this driver.
>
> Signed-off-by: Roman Kiryanov 

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/Kconfig|   7 -
>  drivers/mmc/host/Makefile   |   1 -
>  drivers/mmc/host/android-goldfish.c | 545 
>  3 files changed, 553 deletions(-)
>  delete mode 100644 drivers/mmc/host/android-goldfish.c
>
> diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
> index 596f32637315..ad4678c9bac1 100644
> --- a/drivers/mmc/host/Kconfig
> +++ b/drivers/mmc/host/Kconfig
> @@ -608,13 +608,6 @@ config MMC_DAVINCI
>   If you have an DAVINCI board with a Multimedia Card slot,
>   say Y or M here.  If unsure, say N.
>
> -config MMC_GOLDFISH
> -   tristate "goldfish qemu Multimedia Card Interface support"
> -   depends on GOLDFISH || COMPILE_TEST
> -   help
> - This selects the Goldfish Multimedia card Interface emulation
> - found on the Goldfish Android virtual device emulation.
> -
>  config MMC_SPI
> tristate "MMC/SD/SDIO over SPI"
> depends on SPI_MASTER
> diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
> index 451c25fc2c69..7f97e97f7066 100644
> --- a/drivers/mmc/host/Makefile
> +++ b/drivers/mmc/host/Makefile
> @@ -34,7 +34,6 @@ obj-$(CONFIG_MMC_ATMELMCI)+= atmel-mci.o
>  obj-$(CONFIG_MMC_TIFM_SD)  += tifm_sd.o
>  obj-$(CONFIG_MMC_MVSDIO)   += mvsdio.o
>  obj-$(CONFIG_MMC_DAVINCI)   += davinci_mmc.o
> -obj-$(CONFIG_MMC_GOLDFISH) += android-goldfish.o
>  obj-$(CONFIG_MMC_SPI)  += mmc_spi.o
>  ifeq ($(CONFIG_OF),y)
>  obj-$(CONFIG_MMC_SPI)  += of_mmc_spi.o
> diff --git a/drivers/mmc/host/android-goldfish.c 
> b/drivers/mmc/host/android-goldfish.c
> deleted file mode 100644
> index e878fdf8f20a..
> --- a/drivers/mmc/host/android-goldfish.c
> +++ /dev/null
> @@ -1,545 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-only
> -/*
> - *  Copyright 2007, Google Inc.
> - *  Copyright 2012, Intel Inc.
> - *
> - *  based on omap.c driver, which was
> - *  Copyright (C) 2004 Nokia Corporation
> - *  Written by Tuukka Tikkanen and Juha Yrjölä 
> - *  Misc hacks here and there by Tony Lindgren 
> - *  Other hacks (DMA, SD, etc) by David Brownell
> - */
> -
> -#include 
> -#include 
> -#include 
> -
> -#include 
> -#include 
> -#include 
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -#include 
> -#include 
> -
> -#include 
> -#include 
> -
> -#define DRIVER_NAME "goldfish_mmc"
> -
> -#define BUFFER_SIZE   16384
> -
> -#define GOLDFISH_MMC_READ(host, addr)   (readl(host->reg_base + addr))
> -#define GOLDFISH_MMC_WRITE(host, addr, x)   (writel(x, host->reg_base + 
> addr))
> -
> -enum {
> -   /* status register */
> -   MMC_INT_STATUS  = 0x00,
> -   /* set this to enable IRQ */
> -   MMC_INT_ENABLE  = 0x04,
> -   /* set this to specify buffer address */
> -   MMC_SET_BUFFER  = 0x08,
> -
> -   /* MMC command number */
> -   MMC_CMD = 0x0C,
> -
> -   /* MMC argument */
> -   MMC_ARG = 0x10,
> -
> -   /* MMC response (or R2 bits 0 - 31) */
> -   MMC_RESP_0  = 0x14,
> -
> -   /* MMC R2 response bits 32 - 63 */
> -   MMC_RESP_1  = 0x18,
> -
> -   /* MMC R2 response bits 64 - 95 */
> -   MMC_RESP_2  = 0x1C,
> -
> -   /* MMC R2 response bits 96 - 127 */
> -   MMC_RESP_3  = 0x20,
> -
> -   MMC_BLOCK_LENGTH= 0x24,
> -   MMC_BLOCK_COUNT = 0x28,
> -
> -   /* MMC state flags */
> -   MMC_STATE   = 0x2C,
> -
> -   /* MMC_INT_STATUS bits */
> -
> -   MMC_STAT_END_OF_CMD = 1U << 0,
> -   MMC_STAT_END_OF_DATA= 1U << 1,
> -   MMC_STAT_STATE_CHANGE   = 1U << 2,
> -   MMC_STAT_CMD_TIMEOUT= 1U << 3,
> -
> -   /* MMC_STATE bits */
> -   MMC_STATE_INSERTED = 1U << 0,
> -   MMC_STATE_READ_ONLY= 1U << 1,
> -};
> -
> -/*
> - * Command types
> - */
> -#define OMAP_MMC_CMDTYPE_BC0
> -#define OMAP_MMC_CMDTYPE_BCR   1
> -#define OMAP_MMC_CMDTYPE_AC2
> -#define OMAP_MMC_CMDTYPE_ADTC  3
> -
> -
> -struct goldfish_mmc_host {
> -   struct mmc_request  *mrq;
> -   struct mmc_command  *cmd;
> -   struct mmc_data *data;
> -   struct device   *dev;
> -   unsigned char   id; /* 16xx chips have 2 MMC blocks */
> -   void*virt_base;
> -   unsigned intphys_base;
> -   int irq;
> -   unsigned char   bus_mode;
> -   unsigned

Re: [PATCH] mmc: omap-hsmmc: Simplify bool comparison

2021-02-12 Thread Ulf Hansson
On Mon, 8 Feb 2021 at 10:52, Jiapeng Chong
 wrote:
>
> Fix the following coccicheck warning:
>
> ./drivers/mmc/host/omap_hsmmc.c:297:6-25: WARNING: Comparison of 0/1 to
> bool variable.
>
> Reported-by: Abaci Robot 
> Signed-off-by: Jiapeng Chong 

I already have a patch for this:

https://patchwork.kernel.org/project/linux-mmc/patch/1610704281-11036-1-git-send-email-abaci-bug...@linux.alibaba.com/

Kind regards
Uffe


> ---
>  drivers/mmc/host/omap_hsmmc.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
> index aa9cc49..a59e9c3 100644
> --- a/drivers/mmc/host/omap_hsmmc.c
> +++ b/drivers/mmc/host/omap_hsmmc.c
> @@ -285,22 +285,22 @@ static int omap_hsmmc_set_pbias(struct omap_hsmmc_host 
> *host, bool power_on)
> return 0;
>
> if (power_on) {
> -   if (host->pbias_enabled == 0) {
> +   if (!host->pbias_enabled) {
> ret = regulator_enable(host->pbias);
> if (ret) {
> dev_err(host->dev, "pbias reg enable fail\n");
> return ret;
> }
> -   host->pbias_enabled = 1;
> +   host->pbias_enabled = true;
> }
> } else {
> -   if (host->pbias_enabled == 1) {
> +   if (host->pbias_enabled) {
> ret = regulator_disable(host->pbias);
> if (ret) {
> dev_err(host->dev, "pbias reg disable 
> fail\n");
> return ret;
> }
> -   host->pbias_enabled = 0;
> +   host->pbias_enabled = false;
> }
> }
>
> --
> 1.8.3.1
>


Re: [PATCH v2] mmc: mmc_test: use erase_arg for mmc_erase command

2021-02-12 Thread Ulf Hansson
On Tue, 9 Feb 2021 at 15:52,  wrote:
>
> From: Yann Gautier 
>
> Since [1], the erase argument for mmc_erase() function is saved in
> erase_arg field of card structure. It is preferable to use it instead of
> hard-coded MMC_SECURE_ERASE_ARG, which from eMMC 4.51 spec is not
> recommended:
> "6.6.16 Secure Erase
> NOTE Secure Erase is included for backwards compatibility. New system
> level implementations (based on v4.51 devices and beyond) should use
> Erase combined with Sanitize instead of secure erase."
>
> On STM32MP157C-EV1 board, embedding a THGBMDG5D1LBAIL eMMC, using
> MMC_ERASE command with MMC_SECURE_ERASE_ARG may stuck the STM32 SDMMC IP,
> if test 37 or test 38 are launched just after a write test, e.g. test 36.
> Using the default MMC_ERASE argument from framework with erase_arg,
> which default in our case to MMC_DISCARD_ARG does no more trig the
> issue.
>
>  [1] commit 01904ff77676 ("mmc: core: Calculate the discard arg only once")
>
> Signed-off-by: Yann Gautier 

Applied for next, and by adding Adrian's ack from the previous version, thanks!

Kind regards
Uffe


> ---
>
> Changes in v2:
> - Drop patch 1 from the previous series
> - Update comment
>
>  drivers/mmc/core/mmc_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/mmc_test.c b/drivers/mmc/core/mmc_test.c
> index 39a478874ca3..63524551a13a 100644
> --- a/drivers/mmc/core/mmc_test.c
> +++ b/drivers/mmc/core/mmc_test.c
> @@ -2110,7 +2110,7 @@ static int mmc_test_rw_multiple(struct mmc_test_card 
> *test,
> if (mmc_can_erase(test->card) &&
> tdata->prepare & MMC_TEST_PREP_ERASE) {
> ret = mmc_erase(test->card, dev_addr,
> -   size / 512, MMC_SECURE_ERASE_ARG);
> +   size / 512, test->card->erase_arg);
> if (ret)
> ret = mmc_erase(test->card, dev_addr,
> size / 512, MMC_ERASE_ARG);
> --
> 2.17.1
>


[PATCH v8 22/22] counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8

2021-02-12 Thread William Breathitt Gray
The LSI/CSI LS7266R1 chip provides programmable output via the FLG pins.
When interrupts are enabled on the ACCES 104-QUAD-8, they occur whenever
FLG1 is active. Four functions are available for the FLG1 signal: Carry,
Compare, Carry-Borrow, and Index.

Carry:
Interrupt generated on active low Carry signal. Carry
signal toggles every time the respective channel's
counter overflows.

Compare:
Interrupt generated on active low Compare signal.
Compare signal toggles every time respective channel's
preset register is equal to the respective channel's
counter.

Carry-Borrow:
Interrupt generated on active low Carry signal and
active low Borrow signal. Carry signal toggles every
time the respective channel's counter overflows. Borrow
signal toggles every time the respective channel's
counter underflows.

Index:
Interrupt generated on active high Index signal.

These four functions correspond respectivefly to the following four
Counter event types: COUNTER_EVENT_OVERFLOW, COUNTER_EVENT_THRESHOLD,
COUNTER_EVENT_OVERFLOW_UNDERFLOW, and COUNTER_EVENT_INDEX. Interrupts
push Counter events to event channel X, where 'X' is the respective
channel whose FLG1 activated.

This patch adds IRQ support for the ACCES 104-QUAD-8. The interrupt line
numbers for the devices may be configured via the irq array module
parameter.

Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 170 +--
 drivers/counter/Kconfig  |   6 +-
 2 files changed, 165 insertions(+), 11 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 2b47f9991acc..45090cd9f813 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -25,11 +26,15 @@ static unsigned int num_quad8;
 module_param_hw_array(base, uint, ioport, &num_quad8, 0);
 MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
 
+static unsigned int irq[max_num_isa_dev(QUAD8_EXTENT)];
+module_param_hw_array(irq, uint, irq, NULL, 0);
+MODULE_PARM_DESC(irq, "ACCES 104-QUAD-8 interrupt line numbers");
+
 #define QUAD8_NUM_COUNTERS 8
 
 /**
  * struct quad8 - device private data structure
- * @lock:  synchronization lock to prevent I/O race conditions
+ * @lock:  lock to prevent clobbering device states during R/W ops
  * @counter:   instance of the counter_device
  * @fck_prescaler: array of filter clock prescaler configurations
  * @preset:array of preset values
@@ -38,6 +43,8 @@ MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
  * @quadrature_scale:  array of quadrature mode scale configurations
  * @ab_enable: array of A and B inputs enable configurations
  * @preset_enable: array of set_to_preset_on_index attribute configurations
+ * @irq_trigger:   array of current IRQ trigger function configurations
+ * @next_irq_trigger:  array of next IRQ trigger function configurations
  * @synchronous_mode:  array of index function synchronous mode configurations
  * @index_polarity:array of index function polarity configurations
  * @cable_fault_enable:differential encoder cable status enable 
configurations
@@ -53,13 +60,17 @@ struct quad8 {
unsigned int quadrature_scale[QUAD8_NUM_COUNTERS];
unsigned int ab_enable[QUAD8_NUM_COUNTERS];
unsigned int preset_enable[QUAD8_NUM_COUNTERS];
+   unsigned int irq_trigger[QUAD8_NUM_COUNTERS];
+   unsigned int next_irq_trigger[QUAD8_NUM_COUNTERS];
unsigned int synchronous_mode[QUAD8_NUM_COUNTERS];
unsigned int index_polarity[QUAD8_NUM_COUNTERS];
unsigned int cable_fault_enable;
unsigned int base;
 };
 
+#define QUAD8_REG_INTERRUPT_STATUS 0x10
 #define QUAD8_REG_CHAN_OP 0x11
+#define QUAD8_REG_INDEX_INTERRUPT 0x12
 #define QUAD8_REG_INDEX_INPUT_LEVELS 0x16
 #define QUAD8_DIFF_ENCODER_CABLE_STATUS 0x17
 /* Borrow Toggle flip-flop */
@@ -92,8 +103,8 @@ struct quad8 {
 #define QUAD8_RLD_CNTR_OUT 0x10
 /* Transfer Preset Register LSB to FCK Prescaler */
 #define QUAD8_RLD_PRESET_PSC 0x18
-#define QUAD8_CHAN_OP_ENABLE_COUNTERS 0x00
 #define QUAD8_CHAN_OP_RESET_COUNTERS 0x01
+#define QUAD8_CHAN_OP_ENABLE_INTERRUPT_FUNC 0x04
 #define QUAD8_CMR_QUADRATURE_X1 0x08
 #define QUAD8_CMR_QUADRATURE_X2 0x10
 #define QUAD8_CMR_QUADRATURE_X4 0x18
@@ -380,13 +391,103 @@ static int quad8_action_read(struct counter_device 
*counter,
return 0;
 }
 
+enum {
+   QUAD8_EVENT_NONE = -1,
+   QUAD8_EVENT_CARRY = 0,
+   QUAD8_EVENT_COMPARE = 1,
+   QUAD8_EVENT_CARRY_BORROW = 2,
+   QUAD8_EVENT_INDEX = 3,
+};
+
+static int quad8_events_configure(struct c

Re: [PATCH v4 1/5] selftests/x86: Use getauxval() to simplify the code in sgx

2021-02-12 Thread Jarkko Sakkinen
On Mon, Feb 08, 2021 at 05:09:21PM -0700, Shuah Khan wrote:
> On 2/2/21 3:02 PM, Jarkko Sakkinen wrote:
> > On Mon, Feb 01, 2021 at 09:26:49PM +0800, Tianjia Zhang wrote:
> > > Simplify the sgx code implemntation by using library function
> > > getauxval() instead of a custom function to get the base address
> > > of vDSO.
> > > 
> > > Signed-off-by: Tianjia Zhang 
> > 
> > Reviewed-by: Jarkko Sakkinen 
> > 
> > This needs also ack from Shuah.
> > 
> 
> Looks good to me. Thank you.
> 
> Acked-by: Shuah Khan 
> 
> thanks,
> -- Shuah

Thank you.

/Jarkko


Re: [PATCH v3 3/5] x86/sgx: Optimize the free_cnt count in sgx_epc_section

2021-02-12 Thread Jarkko Sakkinen
On Thu, Feb 11, 2021 at 02:04:12PM +0800, Tianjia Zhang wrote:
> Hi,
> 
> Sorry for the late reply.
> 
> On 1/28/21 1:40 AM, Jarkko Sakkinen wrote:
> > I could bet some money that this does not bring any significant
> > performance gain.
> > 
> 
> Yes, this does not bring performance gains. This is not a change for
> performance, mainly to make the value of free_cnt look more accurate.
> 
> > On Sun, Jan 24, 2021 at 02:29:05PM +0800, Tianjia Zhang wrote:
> > > `section->free_cnt` represents the free page in sgx_epc_section,
> > > which is assigned once after initialization. In fact, just after the
> > > initialization is completed, the pages are in the `init_laundry_list`
> > > list and cannot be allocated. This needs to be recovered by EREMOVE
> > > of function sgx_sanitize_section() before it can be used as a page
> > > that can be allocated. The sgx_sanitize_section() will be called in
> > > the kernel thread ksgxd.
> > > 
> > > This patch moves the initialization of `section->free_cnt` from the
> > > initialization function `sgx_setup_epc_section()` to the function
> > > `sgx_sanitize_section()`, and then accumulates the count after the
> > 
> > Use single quotes instead of hyphens.
> > >> successful execution of EREMOVE. This seems to be more reasonable,
> > > free_cnt will also truly reflect the allocatable free pages in EPC.
> > > 
> > > Sined-off-by: Tianjia Zhang 
> > > Reviewed-by: Sean Christopherson 
> > > ---
> > >   arch/x86/kernel/cpu/sgx/main.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/x86/kernel/cpu/sgx/main.c 
> > > b/arch/x86/kernel/cpu/sgx/main.c
> > > index 4465912174fd..e455ec7b3449 100644
> > > --- a/arch/x86/kernel/cpu/sgx/main.c
> > > +++ b/arch/x86/kernel/cpu/sgx/main.c
> > > @@ -48,6 +48,7 @@ static void sgx_sanitize_section(struct sgx_epc_section 
> > > *section)
> > >   if (!ret) {
> > >   spin_lock(§ion->lock);
> > >   list_move(&page->list, §ion->page_list);
> > > + section->free_cnt++;
> > >   spin_unlock(§ion->lock);
> > 
> > Someone can try to allocate a page while sanitize process is in progress.
> > 
> > I think it is better to keep critical sections in the form that when you
> > leave from one, the global state is legit.
> > 
> 
> Do you mean to move the critical section to protect the entire while loop?
> Of course, this is also possible, sanitize is a process only needed for
> initialization, and the possibility of conflict is very small.
> 
> Best regards,
> Tianjia

The big picture of this change to me, to be frank is that it's completely
useless.

Please start with the picture.

/Jarkko


Re: [PATCH 1/6] fs: Add flag to file_system_type to indicate content is generated

2021-02-12 Thread Greg KH
On Fri, Feb 12, 2021 at 12:05:14PM +, Luis Henriques wrote:
> Greg KH  writes:
> 
> > On Fri, Feb 12, 2021 at 10:22:16AM +0200, Amir Goldstein wrote:
> >> On Fri, Feb 12, 2021 at 9:49 AM Greg KH  wrote:
> >> >
> >> > On Fri, Feb 12, 2021 at 12:44:00PM +0800, Nicolas Boichat wrote:
> >> > > Filesystems such as procfs and sysfs generate their content at
> >> > > runtime. This implies the file sizes do not usually match the
> >> > > amount of data that can be read from the file, and that seeking
> >> > > may not work as intended.
> >> > >
> >> > > This will be useful to disallow copy_file_range with input files
> >> > > from such filesystems.
> >> > >
> >> > > Signed-off-by: Nicolas Boichat 
> >> > > ---
> >> > > I first thought of adding a new field to struct file_operations,
> >> > > but that doesn't quite scale as every single file creation
> >> > > operation would need to be modified.
> >> >
> >> > Even so, you missed a load of filesystems in the kernel with this patch
> >> > series, what makes the ones you did mark here different from the
> >> > "internal" filesystems that you did not?
> >> >
> >> > This feels wrong, why is userspace suddenly breaking?  What changed in
> >> > the kernel that caused this?  Procfs has been around for a _very_ long
> >> > time :)
> >> 
> >> That would be because of (v5.3):
> >> 
> >> 5dae222a5ff0 vfs: allow copy_file_range to copy across devices
> >> 
> >> The intention of this change (series) was to allow server side copy
> >> for nfs and cifs via copy_file_range().
> >> This is mostly work by Dave Chinner that I picked up following requests
> >> from the NFS folks.
> >> 
> >> But the above change also includes this generic change:
> >> 
> >> -   /* this could be relaxed once a method supports cross-fs copies */
> >> -   if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb)
> >> -   return -EXDEV;
> >> -
> >> 
> >> The change of behavior was documented in the commit message.
> >> It was also documented in:
> >> 
> >> 88e75e2c5 copy_file_range.2: Kernel v5.3 updates
> >> 
> >> I think our rationale for the generic change was:
> >> "Why not? What could go wrong? (TM)"
> >> I am not sure if any workload really gained something from this
> >> kernel cross-fs CFR.
> >
> > Why not put that check back?
> >
> >> In retrospect, I think it would have been safer to allow cross-fs CFR
> >> only to the filesystems that implement ->{copy,remap}_file_range()...
> >
> > Why not make this change?  That seems easier and should fix this for
> > everyone, right?
> >
> >> Our option now are:
> >> - Restore the cross-fs restriction into generic_copy_file_range()
> >
> > Yes.
> >
> 
> Restoring this restriction will actually change the current cephfs CFR
> behaviour.  Since that commit we have allowed doing remote copies between
> different filesystems within the same ceph cluster.  See commit
> 6fd4e6348352 ("ceph: allow object copies across different filesystems in
> the same cluster").
> 
> Although I'm not aware of any current users for this scenario, the
> performance impact can actually be huge as it's the difference between
> asking the OSDs for copying a file and doing a full read+write on the
> client side.

Regression in performance is ok if it fixes a regression for things that
used to work just fine in the past :)

First rule, make it work.

thanks,

greg k-h


[PATCH v8 17/22] counter: Add character device interface

2021-02-12 Thread William Breathitt Gray
This patch introduces a character device interface for the Counter
subsystem. Device data is exposed through standard character device read
operations. Device data is gathered when a Counter event is pushed by
the respective Counter device driver. Configuration is handled via ioctl
operations on the respective Counter character device node.

Cc: David Lechner 
Cc: Gwendal Grignou 
Cc: Dan Carpenter 
Cc: Oleksij Rempel 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/Makefile |   2 +-
 drivers/counter/counter-chrdev.c | 496 +++
 drivers/counter/counter-chrdev.h |  16 +
 drivers/counter/counter-core.c   |  37 ++-
 include/linux/counter.h  |  45 +++
 include/uapi/linux/counter.h |  70 +
 6 files changed, 661 insertions(+), 5 deletions(-)
 create mode 100644 drivers/counter/counter-chrdev.c
 create mode 100644 drivers/counter/counter-chrdev.h

diff --git a/drivers/counter/Makefile b/drivers/counter/Makefile
index cbe1d06af6a9..c4870eb5b1dd 100644
--- a/drivers/counter/Makefile
+++ b/drivers/counter/Makefile
@@ -4,7 +4,7 @@
 #
 
 obj-$(CONFIG_COUNTER) += counter.o
-counter-y := counter-core.o counter-sysfs.o
+counter-y := counter-core.o counter-sysfs.o counter-chrdev.o
 
 obj-$(CONFIG_104_QUAD_8)   += 104-quad-8.o
 obj-$(CONFIG_STM32_TIMER_CNT)  += stm32-timer-cnt.o
diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
new file mode 100644
index ..16f02df7f73d
--- /dev/null
+++ b/drivers/counter/counter-chrdev.c
@@ -0,0 +1,496 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Generic Counter character device interface
+ * Copyright (C) 2020 William Breathitt Gray
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "counter-chrdev.h"
+
+struct counter_comp_node {
+   struct list_head l;
+   struct counter_component component;
+   struct counter_comp comp;
+   void *parent;
+};
+
+static ssize_t counter_chrdev_read(struct file *filp, char __user *buf,
+  size_t len, loff_t *f_ps)
+{
+   struct counter_device *const counter = filp->private_data;
+   int err;
+   unsigned int copied;
+
+   if (len < sizeof(struct counter_event))
+   return -EINVAL;
+
+   do {
+   if (kfifo_is_empty(&counter->events)) {
+   if (filp->f_flags & O_NONBLOCK)
+   return -EAGAIN;
+
+   err = wait_event_interruptible(counter->events_wait,
+   !kfifo_is_empty(&counter->events));
+   if (err < 0)
+   return err;
+   }
+
+   if (mutex_lock_interruptible(&counter->events_lock))
+   return -ERESTARTSYS;
+   err = kfifo_to_user(&counter->events, buf, len, &copied);
+   mutex_unlock(&counter->events_lock);
+   if (err < 0)
+   return err;
+   } while (!copied);
+
+   return copied;
+}
+
+static __poll_t counter_chrdev_poll(struct file *filp,
+   struct poll_table_struct *pollt)
+{
+   struct counter_device *const counter = filp->private_data;
+   __poll_t events = 0;
+
+   poll_wait(filp, &counter->events_wait, pollt);
+
+   if (!kfifo_is_empty(&counter->events))
+   events = EPOLLIN | EPOLLRDNORM;
+
+   return events;
+}
+
+static void counter_events_list_free(struct list_head *const events_list)
+{
+   struct counter_event_node *p, *n;
+   struct counter_comp_node *q, *o;
+
+   list_for_each_entry_safe(p, n, events_list, l) {
+   /* Free associated component nodes */
+   list_for_each_entry_safe(q, o, &p->comp_list, l) {
+   list_del(&q->l);
+   kfree(q);
+   }
+
+   /* Free event node */
+   list_del(&p->l);
+   kfree(p);
+   }
+}
+
+static int counter_set_event_node(struct counter_device *const counter,
+ struct counter_watch *const watch,
+ const struct counter_comp_node *const cfg)
+{
+   struct counter_event_node *event_node;
+   struct counter_comp_node *comp_node;
+
+   /* Search for event in the list */
+   list_for_each_entry(event_node, &counter->next_events_list, l)
+   if (event_node->event == watch->event &&
+   event_node->channel == watch->channel)
+   break;
+
+   /* If event is not already in the list */
+   if (&event_node->l == &counter->next_events_list) {
+   /* Allocate new event node */
+   event_node = kmalloc(sizeof(*event_node), GFP_ATOMIC);
+ 

[PATCH v8 21/22] counter: 104-quad-8: Replace mutex with spinlock

2021-02-12 Thread William Breathitt Gray
This patch replaces the mutex I/O lock with a spinlock. This is in
preparation for a subsequent patch adding IRQ support for 104-QUAD-8
devices; we can't sleep in an interrupt context, so we'll need to use a
spinlock instead.

Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 90 +---
 1 file changed, 53 insertions(+), 37 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 41fdbd228be3..2b47f9991acc 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define QUAD8_EXTENT 32
 
@@ -28,6 +29,7 @@ MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
 
 /**
  * struct quad8 - device private data structure
+ * @lock:  synchronization lock to prevent I/O race conditions
  * @counter:   instance of the counter_device
  * @fck_prescaler: array of filter clock prescaler configurations
  * @preset:array of preset values
@@ -42,7 +44,7 @@ MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
  * @base:  base port address of the device
  */
 struct quad8 {
-   struct mutex lock;
+   raw_spinlock_t lock;
struct counter_device counter;
unsigned int fck_prescaler[QUAD8_NUM_COUNTERS];
unsigned int preset[QUAD8_NUM_COUNTERS];
@@ -123,6 +125,7 @@ static int quad8_count_read(struct counter_device *counter,
unsigned int flags;
unsigned int borrow;
unsigned int carry;
+   unsigned long irqflags;
int i;
 
flags = inb(base_offset + 1);
@@ -132,7 +135,7 @@ static int quad8_count_read(struct counter_device *counter,
/* Borrow XOR Carry effectively doubles count range */
*val = (unsigned long)(borrow ^ carry) << 24;
 
-   mutex_lock(&priv->lock);
+   raw_spin_lock_irqsave(&priv->lock, irqflags);
 
/* Reset Byte Pointer; transfer Counter to Output Latch */
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP | QUAD8_RLD_CNTR_OUT,
@@ -141,7 +144,7 @@ static int quad8_count_read(struct counter_device *counter,
for (i = 0; i < 3; i++)
*val |= (unsigned long)inb(base_offset) << (8 * i);
 
-   mutex_unlock(&priv->lock);
+   raw_spin_unlock_irqrestore(&priv->lock, irqflags);
 
return 0;
 }
@@ -151,13 +154,14 @@ static int quad8_count_write(struct counter_device 
*counter,
 {
struct quad8 *const priv = counter->priv;
const int base_offset = priv->base + 2 * count->id;
+   unsigned long irqflags;
int i;
 
/* Only 24-bit values are supported */
if (val > 0xFF)
return -ERANGE;
 
-   mutex_lock(&priv->lock);
+   raw_spin_lock_irqsave(&priv->lock, irqflags);
 
/* Reset Byte Pointer */
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_BP, base_offset + 1);
@@ -182,7 +186,7 @@ static int quad8_count_write(struct counter_device *counter,
/* Reset Error flag */
outb(QUAD8_CTR_RLD | QUAD8_RLD_RESET_E, base_offset + 1);
 
-   mutex_unlock(&priv->lock);
+   raw_spin_unlock_irqrestore(&priv->lock, irqflags);
 
return 0;
 }
@@ -200,8 +204,9 @@ static int quad8_function_read(struct counter_device 
*counter,
 {
struct quad8 *const priv = counter->priv;
const int id = count->id;
+   unsigned long irqflags;
 
-   mutex_lock(&priv->lock);
+   raw_spin_lock_irqsave(&priv->lock, irqflags);
 
if (priv->quadrature_mode[id])
switch (priv->quadrature_scale[id]) {
@@ -218,7 +223,7 @@ static int quad8_function_read(struct counter_device 
*counter,
else
*function = COUNTER_FUNCTION_PULSE_DIRECTION;
 
-   mutex_unlock(&priv->lock);
+   raw_spin_unlock_irqrestore(&priv->lock, irqflags);
 
return 0;
 }
@@ -233,10 +238,11 @@ static int quad8_function_write(struct counter_device 
*counter,
unsigned int *const scale = priv->quadrature_scale + id;
unsigned int *const synchronous_mode = priv->synchronous_mode + id;
const int base_offset = priv->base + 2 * id + 1;
+   unsigned long irqflags;
unsigned int mode_cfg;
unsigned int idr_cfg;
 
-   mutex_lock(&priv->lock);
+   raw_spin_lock_irqsave(&priv->lock, irqflags);
 
mode_cfg = priv->count_mode[id] << 1;
idr_cfg = priv->index_polarity[id] << 1;
@@ -271,7 +277,7 @@ static int quad8_function_write(struct counter_device 
*counter,
break;
default:
/* should never reach this path */
-   mutex_unlock(&priv->lock);
+   raw_spin_unlock_irqrestore(&priv->lock, irqflags);
return -EINVAL;
}
}
@@ -279,7 +285,7 @@ static int quad8_function_write(struct counter_device 
*counter,
/* Load mode configuration to Counter M

[PATCH v8 20/22] counter: Implement events_queue_size sysfs attribute

2021-02-12 Thread William Breathitt Gray
The events_queue_size sysfs attribute provides a way for users to
dynamically configure the Counter events queue size for the Counter
character device interface. The size is in number of struct
counter_event data structures. The number of elements will be rounded-up
to a power of 2 due to a requirement of the kfifo_alloc function called
during reallocation of the queue.

Cc: Oleksij Rempel 
Signed-off-by: William Breathitt Gray 
---
 Documentation/ABI/testing/sysfs-bus-counter |  8 +++
 drivers/counter/counter-chrdev.c| 23 +++
 drivers/counter/counter-chrdev.h|  2 ++
 drivers/counter/counter-sysfs.c | 25 +
 4 files changed, 58 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-counter 
b/Documentation/ABI/testing/sysfs-bus-counter
index 847e96f19d19..f6cb2a8b08a7 100644
--- a/Documentation/ABI/testing/sysfs-bus-counter
+++ b/Documentation/ABI/testing/sysfs-bus-counter
@@ -212,6 +212,14 @@ Description:
both edges:
Any state transition.
 
+What:  /sys/bus/counter/devices/counterX/events_queue_size
+KernelVersion: 5.13
+Contact:   linux-...@vger.kernel.org
+Description:
+   Size of the Counter events queue in number of struct
+   counter_event data structures. The number of elements will be
+   rounded-up to a power of 2.
+
 What:  /sys/bus/counter/devices/counterX/name
 KernelVersion: 5.2
 Contact:   linux-...@vger.kernel.org
diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c
index 16f02df7f73d..53eea894e13f 100644
--- a/drivers/counter/counter-chrdev.c
+++ b/drivers/counter/counter-chrdev.c
@@ -375,6 +375,29 @@ void counter_chrdev_remove(struct counter_device *const 
counter)
cdev_del(&counter->chrdev);
 }
 
+int counter_chrdev_realloc_queue(struct counter_device *const counter,
+size_t queue_size)
+{
+   int err;
+   DECLARE_KFIFO_PTR(events, struct counter_event);
+   unsigned long flags;
+
+   /* Allocate new events queue */
+   err = kfifo_alloc(&events, queue_size, GFP_ATOMIC);
+   if (err)
+   return err;
+
+   raw_spin_lock_irqsave(&counter->events_list_lock, flags);
+
+   /* Swap in new events queue */
+   kfifo_free(&counter->events);
+   counter->events.kfifo = events.kfifo;
+
+   raw_spin_unlock_irqrestore(&counter->events_list_lock, flags);
+
+   return 0;
+}
+
 static int counter_get_data(struct counter_device *const counter,
const struct counter_comp_node *const comp_node,
u64 *const value)
diff --git a/drivers/counter/counter-chrdev.h b/drivers/counter/counter-chrdev.h
index cf5a318fe540..ff7fb0191852 100644
--- a/drivers/counter/counter-chrdev.h
+++ b/drivers/counter/counter-chrdev.h
@@ -12,5 +12,7 @@
 int counter_chrdev_add(struct counter_device *const counter,
   const dev_t counter_devt);
 void counter_chrdev_remove(struct counter_device *const counter);
+int counter_chrdev_realloc_queue(struct counter_device *const counter,
+size_t queue_size);
 
 #endif /* _COUNTER_CHRDEV_H_ */
diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
index 0cb3dba950bc..9abc821a3871 100644
--- a/drivers/counter/counter-sysfs.c
+++ b/drivers/counter/counter-sysfs.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 
+#include "counter-chrdev.h"
 #include "counter-sysfs.h"
 
 /**
@@ -737,12 +738,30 @@ static int counter_num_counts_read(struct counter_device 
*counter, u8 *val)
return 0;
 }
 
+static int counter_events_queue_size_read(struct counter_device *counter,
+ u64 *val)
+{
+   *val = counter->events.kfifo.mask + 1;
+   return 0;
+}
+
+static int counter_events_queue_size_write(struct counter_device *counter,
+  u64 val)
+{
+   return counter_chrdev_realloc_queue(counter, val);
+}
+
 static struct counter_comp counter_num_signals_comp =
COUNTER_COMP_DEVICE_U8("num_signals", counter_num_signals_read, NULL);
 
 static struct counter_comp counter_num_counts_comp =
COUNTER_COMP_DEVICE_U8("num_counts", counter_num_counts_read, NULL);
 
+static struct counter_comp counter_events_queue_size_comp =
+   COUNTER_COMP_DEVICE_U64("events_queue_size",
+   counter_events_queue_size_read,
+   counter_events_queue_size_write);
+
 static int counter_sysfs_attr_add(struct counter_device *const counter,
  struct counter_attribute_group *group)
 {
@@ -781,6 +800,12 @@ static int counter_sysfs_attr_add(struct counter_device 
*const counter,
if (err < 0)
return err;
 
+   /* Create num_counts attribute */
+   err = counter_attr_create(dev, group, &counter

[PATCH v8 19/22] counter: Implement extension*_name sysfs attributes

2021-02-12 Thread William Breathitt Gray
The Generic Counter chrdev interface expects users to supply extension
IDs in order to select extensions for requests. In order for users to
know what extension ID belongs to which extension this information must
be exposed. The extension*_name attribute provides a way for users to
discover what extension ID belongs to which extension by reading the
respective extension name for an extension ID.

Cc: David Lechner 
Cc: Gwendal Grignou 
Cc: Dan Carpenter 
Signed-off-by: William Breathitt Gray 
---
 Documentation/ABI/testing/sysfs-bus-counter |  9 
 drivers/counter/counter-sysfs.c | 51 +
 2 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-counter 
b/Documentation/ABI/testing/sysfs-bus-counter
index 6353f0a2f8f8..847e96f19d19 100644
--- a/Documentation/ABI/testing/sysfs-bus-counter
+++ b/Documentation/ABI/testing/sysfs-bus-counter
@@ -100,6 +100,15 @@ Description:
Read-only attribute that indicates whether excessive noise is
present at the channel Y counter inputs.
 
+What:  /sys/bus/counter/devices/counterX/countY/extensionZ_name
+What:  /sys/bus/counter/devices/counterX/extensionZ_name
+What:  /sys/bus/counter/devices/counterX/signalY/extensionZ_name
+KernelVersion: 5.13
+Contact:   linux-...@vger.kernel.org
+Description:
+   Read-only attribute that indicates the component name of
+   Extension Z.
+
 What:  /sys/bus/counter/devices/counterX/countY/function
 KernelVersion: 5.2
 Contact:   linux-...@vger.kernel.org
diff --git a/drivers/counter/counter-sysfs.c b/drivers/counter/counter-sysfs.c
index 52513a213cc5..0cb3dba950bc 100644
--- a/drivers/counter/counter-sysfs.c
+++ b/drivers/counter/counter-sysfs.c
@@ -494,6 +494,7 @@ static ssize_t counter_comp_name_show(struct device *dev,
 
 static int counter_name_attr_create(struct device *const dev,
struct counter_attribute_group *const group,
+   const char *const attr_name,
const char *const name)
 {
struct counter_attribute *counter_attr;
@@ -508,7 +509,7 @@ static int counter_name_attr_create(struct device *const 
dev,
 
/* Configure device attribute */
sysfs_attr_init(&counter_attr->dev_attr.attr);
-   counter_attr->dev_attr.attr.name = "name";
+   counter_attr->dev_attr.attr.name = attr_name;
counter_attr->dev_attr.attr.mode = 0444;
counter_attr->dev_attr.show = counter_comp_name_show;
 
@@ -519,6 +520,18 @@ static int counter_name_attr_create(struct device *const 
dev,
return 0;
 }
 
+static int counter_ext_name_attr_create(struct device *const dev,
+   struct counter_attribute_group *const group, const size_t i,
+   const char *const name)
+{
+   const char *attr_name;
+
+   attr_name = devm_kasprintf(dev, GFP_KERNEL, "extension%zu_name", i);
+   if (!attr_name)
+   return -ENOMEM;
+
+   return counter_name_attr_create(dev, group, attr_name, name);
+}
 
 static struct counter_comp counter_signal_comp = {
.type = COUNTER_COMP_SIGNAL_LEVEL,
@@ -534,6 +547,7 @@ static int counter_signal_attrs_create(struct 
counter_device *const counter,
int err;
struct counter_comp comp;
size_t i;
+   struct counter_comp *ext;
 
/* Create main Signal attribute */
comp = counter_signal_comp;
@@ -543,14 +557,19 @@ static int counter_signal_attrs_create(struct 
counter_device *const counter,
return err;
 
/* Create Signal name attribute */
-   err = counter_name_attr_create(dev, group, signal->name);
+   err = counter_name_attr_create(dev, group, "name", signal->name);
if (err < 0)
return err;
 
/* Create an attribute for each extension */
for (i = 0; i < signal->num_ext; i++) {
-   err = counter_attr_create(dev, group, signal->ext + i, scope,
- signal);
+   ext = signal->ext + i;
+
+   err = counter_attr_create(dev, group, ext, scope, signal);
+   if (err < 0)
+   return err;
+
+   err = counter_ext_name_attr_create(dev, group, i, ext->name);
if (err < 0)
return err;
}
@@ -636,6 +655,7 @@ static int counter_count_attrs_create(struct counter_device 
*const counter,
int err;
struct counter_comp comp;
size_t i;
+   struct counter_comp *ext;
 
/* Create main Count attribute */
comp = counter_count_comp;
@@ -646,7 +666,7 @@ static int counter_count_attrs_create(struct counter_device 
*const counter,
return err;
 
/* Create Count name attribute */
-   err = counter_name_attr_create(dev, group, count->name);
+   err = counter_name_attr_create(dev, g

[PATCH v8 18/22] docs: counter: Document character device interface

2021-02-12 Thread William Breathitt Gray
This patch adds high-level documentation about the Counter subsystem
character device interface.

Signed-off-by: William Breathitt Gray 
---
 Documentation/driver-api/generic-counter.rst  | 243 +++---
 .../userspace-api/ioctl/ioctl-number.rst  |   1 +
 2 files changed, 203 insertions(+), 41 deletions(-)

diff --git a/Documentation/driver-api/generic-counter.rst 
b/Documentation/driver-api/generic-counter.rst
index f6397218aa4c..3be109dc81bb 100644
--- a/Documentation/driver-api/generic-counter.rst
+++ b/Documentation/driver-api/generic-counter.rst
@@ -223,19 +223,6 @@ whether an input line is differential or single-ended) and 
instead focus
 on the core idea of what the data and process represent (e.g. position
 as interpreted from quadrature encoding data).
 
-Userspace Interface
-===
-
-Several sysfs attributes are generated by the Generic Counter interface,
-and reside under the /sys/bus/counter/devices/counterX directory, where
-counterX refers to the respective counter device. Please see
-Documentation/ABI/testing/sysfs-bus-counter for detailed
-information on each Generic Counter interface sysfs attribute.
-
-Through these sysfs attributes, programs and scripts may interact with
-the Generic Counter paradigm Counts, Signals, and Synapses of respective
-counter devices.
-
 Driver API
 ==
 
@@ -388,16 +375,16 @@ userspace interface components::
 / driver callbacks /
 ---
 |
-+---+
-|
-V
-++
-| Counter sysfs  |
-++
-| Translates to the  |
-| standard Counter   |
-| sysfs output   |
-++
++---+---+
+|   |
+V   V
+++  +-+
+| Counter sysfs  |  | Counter chrdev  |
+++  +-+
+| Translates to the  |  | Translates to the   |
+| standard Counter   |  | standard Counter|
+| sysfs output   |  | character device|
+++  +-+
 
 Thereafter, data can be transferred directly between the Counter device
 driver and Counter userspace interface::
@@ -428,23 +415,30 @@ driver and Counter userspace interface::
 / u64 /
 --
 |
-+---+
-|
-V
-++
-| Counter sysfs  |
-++
-| Translates to the  |
-| standard Counter   |
-| sysfs output   |
-||
-| Type: const char * |
-| Value: "42"|
-++
-|
- ---
-/ const char * /
----
++---+---+
+|   |
+V   V
+++  +-+
+| Counter sysfs  |  | Counter chrdev  |
+++  +-+
+| Translates to the  |  | Translates to the   |
+| standard Counter   |  | standard Counter|
+| sysfs output   |  | character device|
+||  |-|
+| Type: const char * |  | Type: u64   |
+| Value: "42"|  | Value: 42   |
+++  +-+
+|   |
+ --- ---
+/ const char * // struct counter_event /
+--- ---
+|   |
+|   V
+|   +---+
+|   | read  |
+|   +---+
+|   \ Count: 42 /
+|---
 |
 V
 +--+
@@ -453,7 +447,7 @@ driver and Counter userspace interface::
 \ Count: "42"  /
  --
 
-There are three primary components involved:
+There are four prima

[PATCH v8 16/22] counter: Move counter enums to uapi header

2021-02-12 Thread William Breathitt Gray
This is in preparation for a subsequent patch implementing a character
device interface for the Counter subsystem.

Signed-off-by: William Breathitt Gray 
---
 MAINTAINERS  |  1 +
 include/linux/counter.h  | 42 +--
 include/uapi/linux/counter.h | 56 
 3 files changed, 58 insertions(+), 41 deletions(-)
 create mode 100644 include/uapi/linux/counter.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 94a19606d947..5392112b3f19 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4543,6 +4543,7 @@ F:Documentation/ABI/testing/sysfs-bus-counter
 F: Documentation/driver-api/generic-counter.rst
 F: drivers/counter/
 F: include/linux/counter.h
+F: include/uapi/linux/counter.h
 
 CPMAC ETHERNET DRIVER
 M: Florian Fainelli 
diff --git a/include/linux/counter.h b/include/linux/counter.h
index 2f01e1fec857..2d544f58a79c 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct counter_device;
 struct counter_count;
@@ -27,47 +28,6 @@ enum counter_comp_type {
COUNTER_COMP_COUNT_MODE,
 };
 
-enum counter_scope {
-   COUNTER_SCOPE_DEVICE,
-   COUNTER_SCOPE_SIGNAL,
-   COUNTER_SCOPE_COUNT,
-};
-
-enum counter_count_direction {
-   COUNTER_COUNT_DIRECTION_FORWARD,
-   COUNTER_COUNT_DIRECTION_BACKWARD,
-};
-
-enum counter_count_mode {
-   COUNTER_COUNT_MODE_NORMAL,
-   COUNTER_COUNT_MODE_RANGE_LIMIT,
-   COUNTER_COUNT_MODE_NON_RECYCLE,
-   COUNTER_COUNT_MODE_MODULO_N,
-};
-
-enum counter_function {
-   COUNTER_FUNCTION_INCREASE,
-   COUNTER_FUNCTION_DECREASE,
-   COUNTER_FUNCTION_PULSE_DIRECTION,
-   COUNTER_FUNCTION_QUADRATURE_X1_A,
-   COUNTER_FUNCTION_QUADRATURE_X1_B,
-   COUNTER_FUNCTION_QUADRATURE_X2_A,
-   COUNTER_FUNCTION_QUADRATURE_X2_B,
-   COUNTER_FUNCTION_QUADRATURE_X4,
-};
-
-enum counter_signal_level {
-   COUNTER_SIGNAL_LEVEL_LOW,
-   COUNTER_SIGNAL_LEVEL_HIGH,
-};
-
-enum counter_synapse_action {
-   COUNTER_SYNAPSE_ACTION_NONE,
-   COUNTER_SYNAPSE_ACTION_RISING_EDGE,
-   COUNTER_SYNAPSE_ACTION_FALLING_EDGE,
-   COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
-};
-
 /**
  * struct counter_comp - Counter component node
  * @type:  Counter component data type
diff --git a/include/uapi/linux/counter.h b/include/uapi/linux/counter.h
new file mode 100644
index ..6113938a6044
--- /dev/null
+++ b/include/uapi/linux/counter.h
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Userspace ABI for Counter character devices
+ * Copyright (C) 2020 William Breathitt Gray
+ */
+#ifndef _UAPI_COUNTER_H_
+#define _UAPI_COUNTER_H_
+
+/* Component scope definitions */
+enum counter_scope {
+   COUNTER_SCOPE_DEVICE,
+   COUNTER_SCOPE_SIGNAL,
+   COUNTER_SCOPE_COUNT,
+};
+
+/* Count direction values */
+enum counter_count_direction {
+   COUNTER_COUNT_DIRECTION_FORWARD,
+   COUNTER_COUNT_DIRECTION_BACKWARD,
+};
+
+/* Count mode values */
+enum counter_count_mode {
+   COUNTER_COUNT_MODE_NORMAL,
+   COUNTER_COUNT_MODE_RANGE_LIMIT,
+   COUNTER_COUNT_MODE_NON_RECYCLE,
+   COUNTER_COUNT_MODE_MODULO_N,
+};
+
+/* Count function values */
+enum counter_function {
+   COUNTER_FUNCTION_INCREASE,
+   COUNTER_FUNCTION_DECREASE,
+   COUNTER_FUNCTION_PULSE_DIRECTION,
+   COUNTER_FUNCTION_QUADRATURE_X1_A,
+   COUNTER_FUNCTION_QUADRATURE_X1_B,
+   COUNTER_FUNCTION_QUADRATURE_X2_A,
+   COUNTER_FUNCTION_QUADRATURE_X2_B,
+   COUNTER_FUNCTION_QUADRATURE_X4,
+};
+
+/* Signal values */
+enum counter_signal_level {
+   COUNTER_SIGNAL_LEVEL_LOW,
+   COUNTER_SIGNAL_LEVEL_HIGH,
+};
+
+/* Action mode values */
+enum counter_synapse_action {
+   COUNTER_SYNAPSE_ACTION_NONE,
+   COUNTER_SYNAPSE_ACTION_RISING_EDGE,
+   COUNTER_SYNAPSE_ACTION_FALLING_EDGE,
+   COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
+};
+
+#endif /* _UAPI_COUNTER_H_ */
-- 
2.30.0



[PATCH v8 15/22] docs: counter: Update to reflect sysfs internalization

2021-02-12 Thread William Breathitt Gray
The Counter subsystem architecture and driver implementations have
changed in order to handle Counter sysfs interactions in a more
consistent way. This patch updates the Generic Counter interface
documentation to reflect the changes.

Signed-off-by: William Breathitt Gray 
---
 Documentation/ABI/testing/sysfs-bus-counter  |   9 +-
 Documentation/driver-api/generic-counter.rst | 243 ++-
 2 files changed, 185 insertions(+), 67 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-bus-counter 
b/Documentation/ABI/testing/sysfs-bus-counter
index 29f54484183f..6353f0a2f8f8 100644
--- a/Documentation/ABI/testing/sysfs-bus-counter
+++ b/Documentation/ABI/testing/sysfs-bus-counter
@@ -277,7 +277,14 @@ What:  
/sys/bus/counter/devices/counterX/signalY/signal
 KernelVersion: 5.2
 Contact:   linux-...@vger.kernel.org
 Description:
-   Signal data of Signal Y represented as a string.
+   Signal level state of Signal Y. The following signal level
+   states are available:
+
+   low:
+   Low level state.
+
+   high:
+   High level state.
 
 What:  /sys/bus/counter/devices/counterX/signalY/synchronous_mode
 KernelVersion: 5.2
diff --git a/Documentation/driver-api/generic-counter.rst 
b/Documentation/driver-api/generic-counter.rst
index 64fe7db080e5..f6397218aa4c 100644
--- a/Documentation/driver-api/generic-counter.rst
+++ b/Documentation/driver-api/generic-counter.rst
@@ -250,8 +250,8 @@ for defining a counter device.
 .. kernel-doc:: drivers/counter/counter.c
:export:
 
-Implementation
-==
+Driver Implementation
+=
 
 To support a counter device, a driver must first allocate the available
 Counter Signals via counter_signal structures. These Signals should
@@ -267,25 +267,61 @@ respective counter_count structure. These counter_count 
structures are
 set to the counts array member of an allocated counter_device structure
 before the Counter is registered to the system.
 
-Driver callbacks should be provided to the counter_device structure via
-a constant counter_ops structure in order to communicate with the
-device: to read and write various Signals and Counts, and to set and get
-the "action mode" and "function mode" for various Synapses and Counts
-respectively.
+Driver callbacks must be provided to the counter_device structure in
+order to communicate with the device: to read and write various Signals
+and Counts, and to set and get the "action mode" and "function mode" for
+various Synapses and Counts respectively.
 
 A defined counter_device structure may be registered to the system by
 passing it to the counter_register function, and unregistered by passing
 it to the counter_unregister function. Similarly, the
-devm_counter_register and devm_counter_unregister functions may be used
-if device memory-managed registration is desired.
-
-Extension sysfs attributes can be created for auxiliary functionality
-and data by passing in defined counter_device_ext, counter_count_ext,
-and counter_signal_ext structures. In these cases, the
-counter_device_ext structure is used for global/miscellaneous exposure
-and configuration of the respective Counter device, while the
-counter_count_ext and counter_signal_ext structures allow for auxiliary
-exposure and configuration of a specific Count or Signal respectively.
+devm_counter_register function may be used if device memory-managed
+registration is desired.
+
+The struct counter_comp structure is used to define counter extensions
+for Signals, Synapses, and Counts.
+
+The "type" member specifies the type of high-level data (e.g. BOOL,
+COUNT_DIRECTION, etc.) handled by this extension. The "``*_read``" and
+"``*_write``" members can then be set by the counter device driver with
+callbacks to handle that data using native C data types (i.e. u8, u64,
+etc.).
+
+Convenience macros such as ``COUNTER_COMP_COUNT_U64`` are provided for
+use by driver authors. In particular, driver authors are expected to use
+the provided macros for standard Counter subsystem attributes in order
+to maintain a consistent interface for userspace. For example, a counter
+device driver may define several standard attributes like so::
+
+struct counter_comp count_ext[] = {
+COUNTER_COMP_DIRECTION(count_direction_read),
+COUNTER_COMP_ENABLE(count_enable_read, count_enable_write),
+COUNTER_COMP_CEILING(count_ceiling_read, count_ceiling_write),
+};
+
+This makes it simple to see, add, and modify the attributes that are
+supported by this driver ("direction", "enable", and "ceiling") and to
+maintain this code without getting lost in a web of struct braces.
+
+Callbacks must match the function type expected for the respective
+component or extension. These function types are defined in the struct
+counter_comp structure as the "``*_read``" and "``*_write``" union
+m

[PATCH v8 14/22] counter: Update counter.h comments to reflect sysfs internalization

2021-02-12 Thread William Breathitt Gray
The Counter subsystem architecture and driver implementations have
changed in order to handle Counter sysfs interactions in a more
consistent way. This patch updates the Generic Counter interface
header file comments to reflect the changes.

Signed-off-by: William Breathitt Gray 
---
 drivers/counter/counter-core.c |  3 ++
 include/linux/counter.h| 72 +++---
 2 files changed, 35 insertions(+), 40 deletions(-)

diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c
index 1577a6562cad..bcf672e1fc0d 100644
--- a/drivers/counter/counter-core.c
+++ b/drivers/counter/counter-core.c
@@ -40,6 +40,9 @@ static struct bus_type counter_bus_type = {
  * This function registers a Counter to the system. A sysfs "counter" directory
  * will be created and populated with sysfs attributes correlating with the
  * Counter Signals, Synapses, and Counts respectively.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
  */
 int counter_register(struct counter_device *const counter)
 {
diff --git a/include/linux/counter.h b/include/linux/counter.h
index 76b0b06dd5db..2f01e1fec857 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -188,12 +188,10 @@ struct counter_comp {
 
 /**
  * struct counter_signal - Counter Signal node
- * @id:unique ID used to identify signal
- * @name:  device-specific Signal name; ideally, this should match the name
- * as it appears in the datasheet documentation
- * @ext:   optional array of Counter Signal extensions
- * @num_ext:   number of Counter Signal extensions specified in @ext
- * @priv:  optional private data supplied by driver
+ * @id:unique ID used to identify the Signal
+ * @name:  device-specific Signal name
+ * @ext:   optional array of Signal extensions
+ * @num_ext:   number of Signal extensions specified in @ext
  */
 struct counter_signal {
int id;
@@ -207,7 +205,7 @@ struct counter_signal {
  * struct counter_synapse - Counter Synapse node
  * @actions_list:  array of available action modes
  * @num_actions:   number of action modes specified in @actions_list
- * @signal:pointer to associated signal
+ * @signal:pointer to the associated Signal
  */
 struct counter_synapse {
const enum counter_synapse_action *actions_list;
@@ -218,17 +216,14 @@ struct counter_synapse {
 
 /**
  * struct counter_count - Counter Count node
- * @id:unique ID used to identify Count
- * @name:  device-specific Count name; ideally, this should match
- * the name as it appears in the datasheet documentation
- * @function:  index of current function mode
- * @functions_list:array available function modes
+ * @id:unique ID used to identify the Count
+ * @name:  device-specific Count name
+ * @functions_list:array of available function modes
  * @num_functions: number of function modes specified in @functions_list
- * @synapses:  array of synapses for initialization
- * @num_synapses:  number of synapses specified in @synapses
- * @ext:   optional array of Counter Count extensions
- * @num_ext:   number of Counter Count extensions specified in @ext
- * @priv:  optional private data supplied by driver
+ * @synapses:  array of Synapses for initialization
+ * @num_synapses:  number of Synapses specified in @synapses
+ * @ext:   optional array of Count extensions
+ * @num_ext:   number of Count extensions specified in @ext
  */
 struct counter_count {
int id;
@@ -246,29 +241,26 @@ struct counter_count {
 
 /**
  * struct counter_ops - Callbacks from driver
- * @signal_read:   optional read callback for Signal attribute. The read
- * level of the respective Signal should be passed back via
- * the level parameter.
- * @count_read:optional read callback for Count attribute. The 
read
- * value of the respective Count should be passed back via
- * the val parameter.
- * @count_write:   optional write callback for Count attribute. The write
- * value for the respective Count is passed in via the val
+ * @signal_read:   read callback for Signals. The read level of the
+ * respective Signal should be passed back via the level
+ * parameter.
+ * @count_read:read callback for Counts. The read value of the
+ * respective Count should be passed back via the value
  * parameter.
- * @function_get:  function to get the current count function mode. Returns
- * 0 on success and negative error code on error. The index
- * of the respective Count's returned function mode 

[PATCH v8 11/22] counter: Rename counter_signal_value to counter_signal_level

2021-02-12 Thread William Breathitt Gray
Signal values will always be levels so let's be explicit it about it to
make the intent of the code clear.

Cc: Syed Nayyar Waris 
Cc: Kamel Bouhara 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c|  5 +++--
 drivers/counter/counter.c   | 12 ++--
 drivers/counter/microchip-tcb-capture.c |  4 ++--
 include/linux/counter.h | 12 ++--
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index a2cabb028db0..ead0eeb6c846 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -97,7 +97,8 @@ struct quad8 {
 #define QUAD8_CMR_QUADRATURE_X4 0x18
 
 static int quad8_signal_read(struct counter_device *counter,
-   struct counter_signal *signal, enum counter_signal_value *val)
+struct counter_signal *signal,
+enum counter_signal_level *level)
 {
const struct quad8 *const priv = counter->priv;
unsigned int state;
@@ -109,7 +110,7 @@ static int quad8_signal_read(struct counter_device *counter,
state = inb(priv->base + QUAD8_REG_INDEX_INPUT_LEVELS)
& BIT(signal->id - 16);
 
-   *val = (state) ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW;
+   *level = (state) ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
 
return 0;
 }
diff --git a/drivers/counter/counter.c b/drivers/counter/counter.c
index 6a683d086008..cb92673552b5 100644
--- a/drivers/counter/counter.c
+++ b/drivers/counter/counter.c
@@ -289,9 +289,9 @@ struct counter_signal_unit {
struct counter_signal *signal;
 };
 
-static const char *const counter_signal_value_str[] = {
-   [COUNTER_SIGNAL_LOW] = "low",
-   [COUNTER_SIGNAL_HIGH] = "high"
+static const char *const counter_signal_level_str[] = {
+   [COUNTER_SIGNAL_LEVEL_LOW] = "low",
+   [COUNTER_SIGNAL_LEVEL_HIGH] = "high"
 };
 
 static ssize_t counter_signal_show(struct device *dev,
@@ -302,13 +302,13 @@ static ssize_t counter_signal_show(struct device *dev,
const struct counter_signal_unit *const component = devattr->component;
struct counter_signal *const signal = component->signal;
int err;
-   enum counter_signal_value val;
+   enum counter_signal_level level;
 
-   err = counter->ops->signal_read(counter, signal, &val);
+   err = counter->ops->signal_read(counter, signal, &level);
if (err)
return err;
 
-   return sprintf(buf, "%s\n", counter_signal_value_str[val]);
+   return sprintf(buf, "%s\n", counter_signal_level_str[level]);
 }
 
 struct counter_name_unit {
diff --git a/drivers/counter/microchip-tcb-capture.c 
b/drivers/counter/microchip-tcb-capture.c
index ee979b011012..f56c4e328018 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -158,7 +158,7 @@ static int mchp_tc_count_function_set(struct counter_device 
*counter,
 
 static int mchp_tc_count_signal_read(struct counter_device *counter,
 struct counter_signal *signal,
-enum counter_signal_value *val)
+enum counter_signal_level *lvl)
 {
struct mchp_tc_data *const priv = counter->priv;
bool sigstatus;
@@ -171,7 +171,7 @@ static int mchp_tc_count_signal_read(struct counter_device 
*counter,
else
sigstatus = (sr & ATMEL_TC_MTIOA);
 
-   *val = sigstatus ? COUNTER_SIGNAL_HIGH : COUNTER_SIGNAL_LOW;
+   *lvl = sigstatus ? COUNTER_SIGNAL_LEVEL_HIGH : COUNTER_SIGNAL_LEVEL_LOW;
 
return 0;
 }
diff --git a/include/linux/counter.h b/include/linux/counter.h
index 9dbd5df4cd34..79f5dcaf6ba0 100644
--- a/include/linux/counter.h
+++ b/include/linux/counter.h
@@ -290,16 +290,16 @@ struct counter_device_state {
const struct attribute_group **groups;
 };
 
-enum counter_signal_value {
-   COUNTER_SIGNAL_LOW = 0,
-   COUNTER_SIGNAL_HIGH
+enum counter_signal_level {
+   COUNTER_SIGNAL_LEVEL_LOW,
+   COUNTER_SIGNAL_LEVEL_HIGH,
 };
 
 /**
  * struct counter_ops - Callbacks from driver
  * @signal_read:   optional read callback for Signal attribute. The read
- * value of the respective Signal should be passed back via
- * the val parameter.
+ * level of the respective Signal should be passed back via
+ * the level parameter.
  * @count_read:optional read callback for Count attribute. The 
read
  * value of the respective Count should be passed back via
  * the val parameter.
@@ -324,7 +324,7 @@ enum counter_signal_value {
 struct counter_ops {
int (*signal_read)(struct counter_device *counter,
   struct counter_signal *signal,
-  enum counter_signal_value 

[PATCH v8 12/22] counter: Rename counter_count_function to counter_function

2021-02-12 Thread William Breathitt Gray
The phrase "Counter Count function" is verbose and unintentionally
implies that function is a Count extension. This patch adjusts the
Counter subsystem code to use the more direct "Counter function" phrase
to make the intent of this code clearer. The phrase "Count action" is
adjusted herein as well for the same reason.

Cc: Syed Nayyar Waris 
Cc: Patrick Havelange 
Cc: Kamel Bouhara 
Cc: Fabrice Gasnier 
Cc: Maxime Coquelin 
Cc: Alexandre Torgue 
Cc: David Lechner 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c| 62 +++---
 drivers/counter/counter.c   | 38 +++---
 drivers/counter/ftm-quaddec.c   | 23 -
 drivers/counter/microchip-tcb-capture.c | 44 
 drivers/counter/stm32-lptimer-cnt.c | 56 ++--
 drivers/counter/stm32-timer-cnt.c   | 68 -
 drivers/counter/ti-eqep.c   | 28 +-
 include/linux/counter.h | 20 
 8 files changed, 166 insertions(+), 173 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index ead0eeb6c846..eca3f6482719 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -187,18 +187,18 @@ static int quad8_count_write(struct counter_device 
*counter,
return 0;
 }
 
-enum quad8_count_function {
-   QUAD8_COUNT_FUNCTION_PULSE_DIRECTION = 0,
-   QUAD8_COUNT_FUNCTION_QUADRATURE_X1,
-   QUAD8_COUNT_FUNCTION_QUADRATURE_X2,
-   QUAD8_COUNT_FUNCTION_QUADRATURE_X4
+enum quad8_function {
+   QUAD8_FUNCTION_PULSE_DIRECTION = 0,
+   QUAD8_FUNCTION_QUADRATURE_X1,
+   QUAD8_FUNCTION_QUADRATURE_X2,
+   QUAD8_FUNCTION_QUADRATURE_X4
 };
 
-static const enum counter_count_function quad8_functions_list[] = {
-   [QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = 
COUNTER_COUNT_FUNCTION_PULSE_DIRECTION,
-   [QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = 
COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A,
-   [QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = 
COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A,
-   [QUAD8_COUNT_FUNCTION_QUADRATURE_X4] = 
COUNTER_COUNT_FUNCTION_QUADRATURE_X4
+static const enum counter_function quad8_functions_list[] = {
+   [QUAD8_FUNCTION_PULSE_DIRECTION] = COUNTER_FUNCTION_PULSE_DIRECTION,
+   [QUAD8_FUNCTION_QUADRATURE_X1] = COUNTER_FUNCTION_QUADRATURE_X1_A,
+   [QUAD8_FUNCTION_QUADRATURE_X2] = COUNTER_FUNCTION_QUADRATURE_X2_A,
+   [QUAD8_FUNCTION_QUADRATURE_X4] = COUNTER_FUNCTION_QUADRATURE_X4
 };
 
 static int quad8_function_get(struct counter_device *counter,
@@ -212,17 +212,17 @@ static int quad8_function_get(struct counter_device 
*counter,
if (priv->quadrature_mode[id])
switch (priv->quadrature_scale[id]) {
case 0:
-   *function = QUAD8_COUNT_FUNCTION_QUADRATURE_X1;
+   *function = QUAD8_FUNCTION_QUADRATURE_X1;
break;
case 1:
-   *function = QUAD8_COUNT_FUNCTION_QUADRATURE_X2;
+   *function = QUAD8_FUNCTION_QUADRATURE_X2;
break;
case 2:
-   *function = QUAD8_COUNT_FUNCTION_QUADRATURE_X4;
+   *function = QUAD8_FUNCTION_QUADRATURE_X4;
break;
}
else
-   *function = QUAD8_COUNT_FUNCTION_PULSE_DIRECTION;
+   *function = QUAD8_FUNCTION_PULSE_DIRECTION;
 
mutex_unlock(&priv->lock);
 
@@ -246,7 +246,7 @@ static int quad8_function_set(struct counter_device 
*counter,
mode_cfg = priv->count_mode[id] << 1;
idr_cfg = priv->index_polarity[id] << 1;
 
-   if (function == QUAD8_COUNT_FUNCTION_PULSE_DIRECTION) {
+   if (function == QUAD8_FUNCTION_PULSE_DIRECTION) {
*quadrature_mode = 0;
 
/* Quadrature scaling only available in quadrature mode */
@@ -262,15 +262,15 @@ static int quad8_function_set(struct counter_device 
*counter,
*quadrature_mode = 1;
 
switch (function) {
-   case QUAD8_COUNT_FUNCTION_QUADRATURE_X1:
+   case QUAD8_FUNCTION_QUADRATURE_X1:
*scale = 0;
mode_cfg |= QUAD8_CMR_QUADRATURE_X1;
break;
-   case QUAD8_COUNT_FUNCTION_QUADRATURE_X2:
+   case QUAD8_FUNCTION_QUADRATURE_X2:
*scale = 1;
mode_cfg |= QUAD8_CMR_QUADRATURE_X2;
break;
-   case QUAD8_COUNT_FUNCTION_QUADRATURE_X4:
+   case QUAD8_FUNCTION_QUADRATURE_X4:
*scale = 2;
mode_cfg |= QUAD8_CMR_QUADRATURE_X4;
break;
@@ -351,11 +351,11 @@ static int quad8_action_get(struct counter_device 
*counter,
 
/* Determine action mode based on current count function mode 

[PATCH v8 10/22] counter: Standardize to ERANGE for limit exceeded errors

2021-02-12 Thread William Breathitt Gray
ERANGE is a semantically better error code to return when an argument
value falls outside the supported limit range of a device.

Cc: Syed Nayyar Waris 
Cc: Fabrice Gasnier 
Cc: Maxime Coquelin 
Cc: Alexandre Torgue 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c| 6 +++---
 drivers/counter/stm32-lptimer-cnt.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 674263b4d2c4..a2cabb028db0 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -154,7 +154,7 @@ static int quad8_count_write(struct counter_device *counter,
 
/* Only 24-bit values are supported */
if (val > 0xFF)
-   return -EINVAL;
+   return -ERANGE;
 
mutex_lock(&priv->lock);
 
@@ -671,7 +671,7 @@ static ssize_t quad8_count_preset_write(struct 
counter_device *counter,
 
/* Only 24-bit values are supported */
if (preset > 0xFF)
-   return -EINVAL;
+   return -ERANGE;
 
mutex_lock(&priv->lock);
 
@@ -716,7 +716,7 @@ static ssize_t quad8_count_ceiling_write(struct 
counter_device *counter,
 
/* Only 24-bit values are supported */
if (ceiling > 0xFF)
-   return -EINVAL;
+   return -ERANGE;
 
mutex_lock(&priv->lock);
 
diff --git a/drivers/counter/stm32-lptimer-cnt.c 
b/drivers/counter/stm32-lptimer-cnt.c
index daf988e7b208..d5f9d580d06d 100644
--- a/drivers/counter/stm32-lptimer-cnt.c
+++ b/drivers/counter/stm32-lptimer-cnt.c
@@ -283,7 +283,7 @@ static ssize_t stm32_lptim_cnt_ceiling_write(struct 
counter_device *counter,
return ret;
 
if (ceiling > STM32_LPTIM_MAX_ARR)
-   return -EINVAL;
+   return -ERANGE;
 
priv->ceiling = ceiling;
 
-- 
2.30.0



[PATCH v8 09/22] counter: Return error code on invalid modes

2021-02-12 Thread William Breathitt Gray
Only a select set of modes (function, action, etc.) are valid for a
given device configuration. This patch ensures that invalid modes result
in a return -EINVAL. Such a situation should never occur in reality, but
it's good to define a default switch cases for the sake of making the
intent of the code clear.

Cc: Syed Nayyar Waris 
Cc: Kamel Bouhara 
Cc: Fabrice Gasnier 
Cc: Maxime Coquelin 
Cc: Alexandre Torgue 
Cc: David Lechner 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c| 10 ++
 drivers/counter/microchip-tcb-capture.c |  6 ++
 drivers/counter/stm32-lptimer-cnt.c | 10 ++
 drivers/counter/stm32-timer-cnt.c   |  3 +++
 drivers/counter/ti-eqep.c   |  3 +++
 5 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 9a96296b0625..674263b4d2c4 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -273,6 +273,10 @@ static int quad8_function_set(struct counter_device 
*counter,
*scale = 2;
mode_cfg |= QUAD8_CMR_QUADRATURE_X4;
break;
+   default:
+   /* should never reach this path */
+   mutex_unlock(&priv->lock);
+   return -EINVAL;
}
}
 
@@ -367,6 +371,9 @@ static int quad8_action_get(struct counter_device *counter,
case QUAD8_COUNT_FUNCTION_QUADRATURE_X4:
*action = QUAD8_SYNAPSE_ACTION_BOTH_EDGES;
break;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
 
return 0;
@@ -529,6 +536,9 @@ static int quad8_count_mode_set(struct counter_device 
*counter,
case COUNTER_COUNT_MODE_MODULO_N:
cnt_mode = 3;
break;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
 
mutex_lock(&priv->lock);
diff --git a/drivers/counter/microchip-tcb-capture.c 
b/drivers/counter/microchip-tcb-capture.c
index 710acc0a3704..ee979b011012 100644
--- a/drivers/counter/microchip-tcb-capture.c
+++ b/drivers/counter/microchip-tcb-capture.c
@@ -133,6 +133,9 @@ static int mchp_tc_count_function_set(struct counter_device 
*counter,
bmr |= ATMEL_TC_QDEN | ATMEL_TC_POSEN;
cmr |= ATMEL_TC_ETRGEDG_RISING | ATMEL_TC_ABETRG | ATMEL_TC_XC0;
break;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
 
regmap_write(priv->regmap, ATMEL_TC_BMR, bmr);
@@ -226,6 +229,9 @@ static int mchp_tc_count_action_set(struct counter_device 
*counter,
case MCHP_TC_SYNAPSE_ACTION_BOTH_EDGE:
edge = ATMEL_TC_ETRGEDG_BOTH;
break;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
 
return regmap_write_bits(priv->regmap,
diff --git a/drivers/counter/stm32-lptimer-cnt.c 
b/drivers/counter/stm32-lptimer-cnt.c
index 937439635d53..daf988e7b208 100644
--- a/drivers/counter/stm32-lptimer-cnt.c
+++ b/drivers/counter/stm32-lptimer-cnt.c
@@ -206,9 +206,10 @@ static int stm32_lptim_cnt_function_set(struct 
counter_device *counter,
priv->quadrature_mode = 1;
priv->polarity = STM32_LPTIM_SYNAPSE_ACTION_BOTH_EDGES;
return 0;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
-
-   return -EINVAL;
 }
 
 static ssize_t stm32_lptim_cnt_enable_read(struct counter_device *counter,
@@ -326,9 +327,10 @@ static int stm32_lptim_cnt_action_get(struct 
counter_device *counter,
case STM32_LPTIM_ENCODER_BOTH_EDGE:
*action = priv->polarity;
return 0;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
-
-   return -EINVAL;
 }
 
 static int stm32_lptim_cnt_action_set(struct counter_device *counter,
diff --git a/drivers/counter/stm32-timer-cnt.c 
b/drivers/counter/stm32-timer-cnt.c
index ef2a974a2f10..431a3d08ed6c 100644
--- a/drivers/counter/stm32-timer-cnt.c
+++ b/drivers/counter/stm32-timer-cnt.c
@@ -296,6 +296,9 @@ static int stm32_action_get(struct counter_device *counter,
/* counts up/down on both TI1FP1 and TI2FP2 edges */
*action = STM32_SYNAPSE_ACTION_BOTH_EDGES;
break;
+   default:
+   /* should never reach this path */
+   return -EINVAL;
}
 
return 0;
diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
index a60aee1a1a29..7844fdf78a97 100644
--- a/drivers/counter/ti-eqep.c
+++ b/drivers/counter/ti-eqep.c
@@ -192,6 +192,9 @@ static int ti_eqep_action_get(struct counter_device 
*counter,
bre

[PATCH v8 07/22] counter: 104-quad-8: Add const qualifier for actions_list array

2021-02-12 Thread William Breathitt Gray
The struct counter_synapse actions_list member expects a const enum
counter_synapse_action array. This patch adds the const qualifier to the
quad8_index_actions_list and quad8_synapse_actions_list to match
actions_list.

Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index af4e0503b074..9a96296b0625 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -305,12 +305,12 @@ enum quad8_synapse_action {
QUAD8_SYNAPSE_ACTION_BOTH_EDGES
 };
 
-static enum counter_synapse_action quad8_index_actions_list[] = {
+static const enum counter_synapse_action quad8_index_actions_list[] = {
[QUAD8_SYNAPSE_ACTION_NONE] = COUNTER_SYNAPSE_ACTION_NONE,
[QUAD8_SYNAPSE_ACTION_RISING_EDGE] = COUNTER_SYNAPSE_ACTION_RISING_EDGE
 };
 
-static enum counter_synapse_action quad8_synapse_actions_list[] = {
+static const enum counter_synapse_action quad8_synapse_actions_list[] = {
[QUAD8_SYNAPSE_ACTION_NONE] = COUNTER_SYNAPSE_ACTION_NONE,
[QUAD8_SYNAPSE_ACTION_RISING_EDGE] = COUNTER_SYNAPSE_ACTION_RISING_EDGE,
[QUAD8_SYNAPSE_ACTION_FALLING_EDGE] = 
COUNTER_SYNAPSE_ACTION_FALLING_EDGE,
-- 
2.30.0



[PATCH v8 08/22] counter: ftm-quaddec: Add const qualifier for actions_list array

2021-02-12 Thread William Breathitt Gray
The struct counter_synapse actions_list member expects a const enum
counter_synapse_action array. This patch adds the const qualifier to the
ftm_quaddec_synapse_actions to match actions_list.

Cc: Patrick Havelange 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/ftm-quaddec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c
index c2b3fdfd8b77..9371532406ca 100644
--- a/drivers/counter/ftm-quaddec.c
+++ b/drivers/counter/ftm-quaddec.c
@@ -162,7 +162,7 @@ enum ftm_quaddec_synapse_action {
FTM_QUADDEC_SYNAPSE_ACTION_BOTH_EDGES,
 };
 
-static enum counter_synapse_action ftm_quaddec_synapse_actions[] = {
+static const enum counter_synapse_action ftm_quaddec_synapse_actions[] = {
[FTM_QUADDEC_SYNAPSE_ACTION_BOTH_EDGES] =
COUNTER_SYNAPSE_ACTION_BOTH_EDGES
 };
-- 
2.30.0



[PATCH v8 06/22] counter: 104-quad-8: Add const qualifier for functions_list array

2021-02-12 Thread William Breathitt Gray
The struct counter_count functions_list member expects a const enum
counter_count_function array. This patch adds the const qualifier to the
quad8_functions_list to match functions_list.

Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 70383b792ec6..af4e0503b074 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -193,7 +193,7 @@ enum quad8_count_function {
QUAD8_COUNT_FUNCTION_QUADRATURE_X4
 };
 
-static enum counter_count_function quad8_count_functions_list[] = {
+static const enum counter_count_function quad8_functions_list[] = {
[QUAD8_COUNT_FUNCTION_PULSE_DIRECTION] = 
COUNTER_COUNT_FUNCTION_PULSE_DIRECTION,
[QUAD8_COUNT_FUNCTION_QUADRATURE_X1] = 
COUNTER_COUNT_FUNCTION_QUADRATURE_X1_A,
[QUAD8_COUNT_FUNCTION_QUADRATURE_X2] = 
COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A,
-- 
2.30.0



[PATCH v8 03/22] counter: 104-quad-8: Return error when invalid mode during ceiling_write

2021-02-12 Thread William Breathitt Gray
The 104-QUAD-8 only has two count modes where a ceiling value makes
sense: Range Limit and Modulo-N. Outside of these two modes, setting a
ceiling value is an invalid operation -- so let's report it as such by
returning -EINVAL.

Fixes: fc069262261c ("counter: 104-quad-8: Add lock guards - generic interface")
Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 9691f8612be8..f0608b21196a 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -714,13 +714,14 @@ static ssize_t quad8_count_ceiling_write(struct 
counter_device *counter,
switch (priv->count_mode[count->id]) {
case 1:
case 3:
+   mutex_unlock(&priv->lock);
quad8_preset_register_set(priv, count->id, ceiling);
-   break;
+   return len;
}
 
mutex_unlock(&priv->lock);
 
-   return len;
+   return -EINVAL;
 }
 
 static ssize_t quad8_count_preset_enable_read(struct counter_device *counter,
-- 
2.30.0



[PATCH v8 05/22] counter: 104-quad-8: Add const qualifiers for quad8_preset_register_set

2021-02-12 Thread William Breathitt Gray
Add some safety by qualifying the quad8_preset_register_set() function
parameters as const.

Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index 37551d3016de..70383b792ec6 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -632,8 +632,8 @@ static ssize_t quad8_count_preset_read(struct 
counter_device *counter,
return sprintf(buf, "%u\n", priv->preset[count->id]);
 }
 
-static void quad8_preset_register_set(struct quad8 *priv, int id,
- unsigned int preset)
+static void quad8_preset_register_set(struct quad8 *const priv, const int id,
+ const unsigned int preset)
 {
const unsigned int base_offset = priv->base + 2 * id;
int i;
-- 
2.30.0



[PATCH v8 04/22] counter: 104-quad-8: Annotate hardware config module parameter

2021-02-12 Thread William Breathitt Gray
When the kernel is running in secure boot mode, we lock down the kernel to
prevent userspace from modifying the running kernel image.  Whilst this
includes prohibiting access to things like /dev/mem, it must also prevent
access by means of configuring driver modules in such a way as to cause a
device to access or modify the kernel image.

To this end, annotate module_param* statements that refer to hardware
configuration and indicate for future reference what type of parameter they
specify.  The parameter parser in the core sees this information and can
skip such parameters with an error message if the kernel is locked down.
The module initialisation then runs as normal, but just sees whatever the
default values for those parameters is.

Note that we do still need to do the module initialisation because some
drivers have viable defaults set in case parameters aren't specified and
some drivers support automatic configuration (e.g. PNP or PCI) in addition
to manually coded parameters.

This patch annotates the 104-QUAD-8 driver.

Cc: Syed Nayyar Waris 
Signed-off-by: William Breathitt Gray 
---
 drivers/counter/104-quad-8.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c
index f0608b21196a..37551d3016de 100644
--- a/drivers/counter/104-quad-8.c
+++ b/drivers/counter/104-quad-8.c
@@ -21,7 +21,7 @@
 
 static unsigned int base[max_num_isa_dev(QUAD8_EXTENT)];
 static unsigned int num_quad8;
-module_param_array(base, uint, &num_quad8, 0);
+module_param_hw_array(base, uint, ioport, &num_quad8, 0);
 MODULE_PARM_DESC(base, "ACCES 104-QUAD-8 base addresses");
 
 #define QUAD8_NUM_COUNTERS 8
-- 
2.30.0



[PATCH v8 02/22] docs: counter: Fix spelling

2021-02-12 Thread William Breathitt Gray
"Miscellaneous" is the correct spelling.

Signed-off-by: William Breathitt Gray 
---
 Documentation/driver-api/generic-counter.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/driver-api/generic-counter.rst 
b/Documentation/driver-api/generic-counter.rst
index b02c52cd69d6..64fe7db080e5 100644
--- a/Documentation/driver-api/generic-counter.rst
+++ b/Documentation/driver-api/generic-counter.rst
@@ -307,7 +307,7 @@ Determining the type of extension to create is a matter of 
scope.
 
 * Device extensions are attributes that expose information/control
   non-specific to a particular Count or Signal. This is where you would
-  put your global features or other miscellanous functionality.
+  put your global features or other miscellaneous functionality.
 
   For example, if your device has an overtemp sensor, you can report the
   chip overheated via a device extension called "error_overtemp":
-- 
2.30.0



[PATCH v8 01/22] docs: counter: Consolidate Counter sysfs attributes documentation

2021-02-12 Thread William Breathitt Gray
Duplicate ABIs are not valid, so let's consolidate these sysfs
attributes into the main sysfs-bus-counter documentation file.

Cc: Patrick Havelange 
Signed-off-by: William Breathitt Gray 
---
 Documentation/ABI/testing/sysfs-bus-counter   | 76 ++-
 .../ABI/testing/sysfs-bus-counter-104-quad-8  | 61 ---
 .../ABI/testing/sysfs-bus-counter-ftm-quaddec | 16 
 MAINTAINERS   |  4 +-
 4 files changed, 75 insertions(+), 82 deletions(-)
 delete mode 100644 Documentation/ABI/testing/sysfs-bus-counter-104-quad-8
 delete mode 100644 Documentation/ABI/testing/sysfs-bus-counter-ftm-quaddec

diff --git a/Documentation/ABI/testing/sysfs-bus-counter 
b/Documentation/ABI/testing/sysfs-bus-counter
index 566bd99fe0a5..29f54484183f 100644
--- a/Documentation/ABI/testing/sysfs-bus-counter
+++ b/Documentation/ABI/testing/sysfs-bus-counter
@@ -57,6 +57,7 @@ Description:
 What:  /sys/bus/counter/devices/counterX/countY/count_mode_available
 What:  /sys/bus/counter/devices/counterX/countY/error_noise_available
 What:  /sys/bus/counter/devices/counterX/countY/function_available
+What:  /sys/bus/counter/devices/counterX/countY/prescaler_available
 What:  
/sys/bus/counter/devices/counterX/countY/signalZ_action_available
 KernelVersion: 5.2
 Contact:   linux-...@vger.kernel.org
@@ -154,6 +155,15 @@ Description:
Count Y. If possible, this should match the name of the
respective channel as it appears in the device datasheet.
 
+What:  /sys/bus/counter/devices/counterX/countY/prescaler
+KernelVersion: 5.2
+Contact:   linux-...@vger.kernel.org
+Description:
+   Configure the prescaler value associated with Count Y.
+   On the FlexTimer, the counter clock source passes through a
+   prescaler (i.e. a counter). This acts like a clock
+   divider.
+
 What:  /sys/bus/counter/devices/counterX/countY/preset
 KernelVersion: 5.2
 Contact:   linux-...@vger.kernel.org
@@ -215,11 +225,45 @@ Description:
Read-only attribute that indicates the total number of Signals
belonging to the Counter.
 
-What:  /sys/bus/counter/devices/counterX/signalY/signal
+What:  /sys/bus/counter/devices/counterX/signalY/cable_fault
+KernelVersion: 5.7
+Contact:   linux-...@vger.kernel.org
+Description:
+   Read-only attribute that indicates whether a differential
+   encoder cable fault (not connected or loose wires) is detected
+   for the respective channel of Signal Y. Valid attribute values
+   are boolean. Detection must first be enabled via the
+   corresponding cable_fault_enable attribute.
+
+What:  /sys/bus/counter/devices/counterX/signalY/cable_fault_enable
+KernelVersion: 5.7
+Contact:   linux-...@vger.kernel.org
+Description:
+   Whether detection of differential encoder cable faults for the
+   respective channel of Signal Y is enabled. Valid attribute
+   values are boolean.
+
+What:  /sys/bus/counter/devices/counterX/signalY/filter_clock_prescaler
+KernelVersion: 5.7
+Contact:   linux-...@vger.kernel.org
+Description:
+   Filter clock factor for input Signal Y. This prescaler value
+   affects the inputs of both quadrature pair signals.
+
+What:  /sys/bus/counter/devices/counterX/signalY/index_polarity
 KernelVersion: 5.2
 Contact:   linux-...@vger.kernel.org
 Description:
-   Signal data of Signal Y represented as a string.
+   Active level of index input Signal Y; irrelevant in
+   non-synchronous load mode.
+
+What:  
/sys/bus/counter/devices/counterX/signalY/index_polarity_available
+What:  
/sys/bus/counter/devices/counterX/signalY/synchronous_mode_available
+KernelVersion: 5.2
+Contact:   linux-...@vger.kernel.org
+Description:
+   Discrete set of available values for the respective Signal Y
+   configuration are listed in this file.
 
 What:  /sys/bus/counter/devices/counterX/signalY/name
 KernelVersion: 5.2
@@ -228,3 +272,31 @@ Description:
Read-only attribute that indicates the device-specific name of
Signal Y. If possible, this should match the name of the
respective signal as it appears in the device datasheet.
+
+What:  /sys/bus/counter/devices/counterX/signalY/signal
+KernelVersion: 5.2
+Contact:   linux-...@vger.kernel.org
+Description:
+   Signal data of Signal Y represented as a string.
+
+What:  /sys/bus/counter/devices/counterX/signalY/synchronous_mode
+KernelVersion: 5.2
+Contact:   linux-...@vger.kernel.org
+Description:
+   Configure the counter associated with Signal Y for
+   non-synchronous or synchronous load mode. Synchronous 

[PATCH v8 00/22] Introduce the Counter character device interface

2021-02-12 Thread William Breathitt Gray
Changes in v8:
 - Consolidated Counter sysfs ABI documentation to single file
 - Added events_queue_size sysfs attribute to allow users to dynamically
   resize the events queue
 - Fixed markup syntax and typos in generic-counter.rst
 - Improved documentation in include/uapi/linux/counter.h and friends
 - Renamed COUNTER_LOAD_WATCHES_IOCTL to COUNTER_ENABLE_EVENTS_IOCTL;
   Renamed COUNTER_CLEAR_WATCHES_IOCTL to COUNTER_DISABLE_EVENTS_IOCTL
 - Renamed the struct counter_event "errno" member to "status"
 - Dropped the "irq_trigger" 104-QUAD-8 sysfs attribute; this
   functionality now occurs implicitly via the Counter chrdev interface
 - Return -ERANGE where appropriate instead of -EINVAL
 - Simplified switch exit paths; return early when possible
 - Call devm_request_irq() before devm_counter_register() for 104-quad-8
 - Renamed devm_counter_unregister() to more apt devm_counter_release()
 - Use enum counter_scope for scope values in counter-sysfs.c
 - Use sysfs_emit() instead of sprintf() where appropriate
 - Renamed find_in_string_array() to more apt counter_find_enum()
 - Renamed *_action_get() and *_action_write() to *_action_read() and
   *_action_write() to match new naming convention of Counter callbacks
 - Use "Counter function" naming convention instead of "Counter count
   function" to avoid confusion about scope

I pulled out a lot of bits and pieces to their own patches; hopefully
that makes reviewing this patchset much simpler than before. This
patchset is also available on my personal public git repo for anyone who
wants a quick way to clone:
https://gitlab.com/vilhelmgray/iio/-/tree/counter_chrdev_v8

The patches preceding "counter: Internalize sysfs interface code" are
primarily cleanup and fixes that can be picked up and applied now to the
IIO tree if so desired. The "counter: Internalize sysfs interface code"
patch as well may be considered for pickup because it is relatively safe
and makes no changes to the userspace interface.

To summarize the main points of this patchset: there are no changes to
the existing Counter sysfs userspace interface; a Counter character
device interface is introduced that allows Counter events and associated
data to be read() by userspace; the events_configure() and
watch_validate() driver callbacks are introduced to support Counter
events; and IRQ support is added to the 104-QUAD-8 driver, serving as an
example of how to support the new Counter events functionality.

Something that should still be discussed: should the struct
counter_event "status" member be 8 bits or 32 bits wide? This member
will provide the return status (system error number) of an event
operation.

William Breathitt Gray (22):
  docs: counter: Consolidate Counter sysfs attributes documentation
  docs: counter: Fix spelling
  counter: 104-quad-8: Return error when invalid mode during
ceiling_write
  counter: 104-quad-8: Annotate hardware config module parameter
  counter: 104-quad-8: Add const qualifiers for
quad8_preset_register_set
  counter: 104-quad-8: Add const qualifier for functions_list array
  counter: 104-quad-8: Add const qualifier for actions_list array
  counter: ftm-quaddec: Add const qualifier for actions_list array
  counter: Return error code on invalid modes
  counter: Standardize to ERANGE for limit exceeded errors
  counter: Rename counter_signal_value to counter_signal_level
  counter: Rename counter_count_function to counter_function
  counter: Internalize sysfs interface code
  counter: Update counter.h comments to reflect sysfs internalization
  docs: counter: Update to reflect sysfs internalization
  counter: Move counter enums to uapi header
  counter: Add character device interface
  docs: counter: Document character device interface
  counter: Implement extension*_name sysfs attributes
  counter: Implement events_queue_size sysfs attribute
  counter: 104-quad-8: Replace mutex with spinlock
  counter: 104-quad-8: Add IRQ support for the ACCES 104-QUAD-8

 Documentation/ABI/testing/sysfs-bus-counter   |  100 +-
 .../ABI/testing/sysfs-bus-counter-104-quad-8  |   61 -
 .../ABI/testing/sysfs-bus-counter-ftm-quaddec |   16 -
 Documentation/driver-api/generic-counter.rst  |  426 -
 .../userspace-api/ioctl/ioctl-number.rst  |1 +
 MAINTAINERS   |6 +-
 drivers/counter/104-quad-8.c  |  751 +
 drivers/counter/Kconfig   |6 +-
 drivers/counter/Makefile  |1 +
 drivers/counter/counter-chrdev.c  |  519 ++
 drivers/counter/counter-chrdev.h  |   18 +
 drivers/counter/counter-core.c|  185 ++
 drivers/counter/counter-sysfs.c   |  889 ++
 drivers/counter/counter-sysfs.h   |   13 +
 drivers/counter/counter.c | 1496 -
 drivers/counter/ftm-quaddec.c |   69 +-
 drivers/counter/microchip-tcb-capture.c   |  105 +-
 drivers/counter/st

[PATCH v3 2/3] dt-bindings: pinctrl: Add binding for ZynqMP pinctrl driver

2021-02-12 Thread Sai Krishna Potthuri
Adding documentation and dt-bindings file which contains MIO pin
configuration defines for Xilinx ZynqMP pinctrl driver.

Signed-off-by: Sai Krishna Potthuri 
---
 .../bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml | 339 ++
 include/dt-bindings/pinctrl/pinctrl-zynqmp.h  |  19 +
 2 files changed, 358 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml
 create mode 100644 include/dt-bindings/pinctrl/pinctrl-zynqmp.h

diff --git a/Documentation/devicetree/bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml 
b/Documentation/devicetree/bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml
new file mode 100644
index ..0c1149706f8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml
@@ -0,0 +1,339 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/xlnx,zynqmp-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Xilinx ZynqMP Pinctrl
+
+maintainers:
+  - Sai Krishna Potthuri 
+  - Rajan Vaja 
+
+description: |
+  Please refer to pinctrl-bindings.txt in this directory for details of the
+  common pinctrl bindings used by client devices, including the meaning of the
+  phrase "pin configuration node".
+
+  ZynqMP's pin configuration nodes act as a container for an arbitrary number 
of
+  subnodes. Each of these subnodes represents some desired configuration for a
+  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, slew rate, etc.
+
+  Each configuration node can consist of multiple nodes describing the pinmux 
and
+  pinconf options. Those nodes can be pinmux nodes or pinconf nodes.
+
+  The name of each subnode is not important; all subnodes should be enumerated
+  and processed purely based on their content.
+
+properties:
+  compatible:
+const: xlnx,zynqmp-pinctrl
+
+patternProperties:
+  '^(.*-)?(default|gpio)$':
+type: object
+patternProperties:
+  '^mux':
+type: object
+description:
+  Pinctrl node's client devices use subnodes for pin muxes,
+  which in turn use below standard properties.
+$ref: pinmux-node.yaml#
+
+properties:
+  groups:
+description:
+  List of groups to select (either this or "pins" must be
+  specified), available groups for this subnode.
+items:
+  enum: [ethernet0_0_grp, ethernet1_0_grp, ethernet2_0_grp,
+ ethernet3_0_grp, gemtsu0_0_grp, gemtsu0_1_grp,
+ gemtsu0_2_grp, mdio0_0_grp, mdio1_0_grp,
+ mdio1_1_grp, mdio2_0_grp, mdio3_0_grp,
+ qspi0_0_grp, qspi_ss_0_grp, qspi_fbclk_0_grp,
+ spi0_0_grp, spi0_ss_0_grp, spi0_ss_1_grp,
+ spi0_ss_2_grp, spi0_1_grp, spi0_ss_3_grp,
+ spi0_ss_4_grp, spi0_ss_5_grp, spi0_2_grp,
+ spi0_ss_6_grp, spi0_ss_7_grp, spi0_ss_8_grp,
+ spi0_3_grp, spi0_ss_9_grp, spi0_ss_10_grp,
+ spi0_ss_11_grp, spi0_4_grp, spi0_ss_12_grp,
+ spi0_ss_13_grp, spi0_ss_14_grp, spi0_5_grp,
+ spi0_ss_15_grp, spi0_ss_16_grp, spi0_ss_17_grp,
+ spi1_0_grp, spi1_ss_0_grp, spi1_ss_1_grp,
+ spi1_ss_2_grp, spi1_1_grp, spi1_ss_3_grp,
+ spi1_ss_4_grp, spi1_ss_5_grp, spi1_2_grp,
+ spi1_ss_6_grp, spi1_ss_7_grp, spi1_ss_8_grp,
+ spi1_3_grp, spi1_ss_9_grp, spi1_ss_10_grp,
+ spi1_ss_11_grp, spi1_4_grp, spi1_ss_12_grp,
+ spi1_ss_13_grp, spi1_ss_14_grp, spi1_5_grp,
+ spi1_ss_15_grp, spi1_ss_16_grp, spi1_ss_17_grp,
+ sdio0_0_grp, sdio0_1_grp, sdio0_2_grp,
+ sdio0_3_grp, sdio0_4_grp, sdio0_5_grp,
+ sdio0_6_grp, sdio0_7_grp, sdio0_8_grp,
+ sdio0_9_grp, sdio0_10_grp, sdio0_11_grp,
+ sdio0_12_grp, sdio0_13_grp, sdio0_14_grp,
+ sdio0_15_grp, sdio0_16_grp, sdio0_17_grp,
+ sdio0_18_grp, sdio0_19_grp, sdio0_20_grp,
+ sdio0_21_grp, sdio0_22_grp, sdio0_23_grp,
+ sdio0_24_grp, sdio0_25_grp, sdio0_26_grp,
+ sdio0_27_grp, sdio0_28_grp, sdio0_29_grp,
+ sdio0_30_grp, sdio0_31_grp, sdio0_32_grp,
+ sdio0_pc_0_grp, sdio0_cd_0_grp, sdio0_wp_0_grp,
+ sdio0_pc_1_grp, sdio0_cd_1_grp, sdio0_wp_1_grp,
+ sdio0_pc_2_grp, sdio0_cd_2_grp, sdio0_wp_2_grp,
+ sdio1_0_grp, sdio1_1_grp, sdio1_2_grp,
+ sdio1_3_grp, sdio1_4_grp, sdio1_5_grp,
+ sdio1_6_grp, sdio1

Re: [PATCH ghak124 v3] audit: log nftables configuration change events

2021-02-12 Thread Phil Sutter
Hi,

On Thu, Feb 11, 2021 at 04:02:55PM -0500, Steve Grubb wrote:
> On Thursday, February 11, 2021 11:29:34 AM EST Paul Moore wrote:
> > > If I'm not mistaken, iptables emits a single audit log per table, ipset
> > > doesn't support audit at all. So I wonder how much audit logging is
> > > required at all (for certification or whatever reason). How much
> > > granularity is desired?
>  
>
> 
> > I believe the netfilter auditing was mostly a nice-to-have bit of
> > functionality to help add to the completeness of the audit logs, but I
> > could very easily be mistaken.  Richard put together those patches, he
> > can probably provide the background/motivation for the effort.
> 
> There are certifications which levy requirements on information flow control. 
> The firewall can decide if information should flow or be blocked. Information 
> flow decisions need to be auditable - which we have with the audit target. 

In nftables, this is realized via 'log level audit' statement.
Functionality should by all means be identical to that of xtables' AUDIT
target.

> That then swings in requirements on the configuration of the information flow 
> policy.
> 
> The requirements state a need to audit any management activity - meaning the 
> creation, modification, and/or deletion of a "firewall ruleset". Because it 
> talks constantly about a ruleset and then individual rules, I suspect only 1 
> summary event is needed to say something happened, who did it, and the 
> outcome. This would be in line with how selinux is treated: we have 1 summary 
> event for loading/modifying/unloading selinux policy.

So the central element are firewall rules for audit purposes and
NETFILTER_CFG notifications merely serve asserting changes to those
rules are noticed by the auditing system. Looking at xtables again, this
seems coherent: Any change causes the whole table blob to be replaced
(while others stay in place). So table replace/create is the most common
place for a change notification. In nftables, the most common one is
generation dump - all tables are treated as elements of the same
ruleset, not individually like in xtables.

Richard, assuming the above is correct, are you fine with reducing
nftables auditing to a single notification per transaction then? I guess
Florian sufficiently illustrated how this would be implemented.

> Hope this helps...

It does, thanks a lot for the information!

Thanks, Phil


[PATCH v3 3/3] pinctrl: Add Xilinx ZynqMP pinctrl driver support

2021-02-12 Thread Sai Krishna Potthuri
Adding pinctrl driver for Xilinx ZynqMP platform.
This driver queries pin information from firmware and registers
pin control accordingly.

Signed-off-by: Sai Krishna Potthuri 
---
 drivers/pinctrl/Kconfig  |   13 +
 drivers/pinctrl/Makefile |1 +
 drivers/pinctrl/pinctrl-zynqmp.c | 1031 ++
 3 files changed, 1045 insertions(+)
 create mode 100644 drivers/pinctrl/pinctrl-zynqmp.c

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index 815095326e2d..25d3c7208975 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -341,6 +341,19 @@ config PINCTRL_ZYNQ
help
  This selects the pinctrl driver for Xilinx Zynq.
 
+config PINCTRL_ZYNQMP
+   bool "Pinctrl driver for Xilinx ZynqMP"
+   depends on ARCH_ZYNQMP
+   select PINMUX
+   select GENERIC_PINCONF
+   help
+ This selects the pinctrl driver for Xilinx ZynqMP platform.
+ This driver will query the pin information from the firmware
+ and allow configuring the pins.
+ Configuration can include the mux function to select on those
+ pin(s)/group(s), and various pin configuration parameters
+ such as pull-up, slew rate, etc.
+
 config PINCTRL_INGENIC
bool "Pinctrl driver for the Ingenic JZ47xx SoCs"
default MACH_INGENIC
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
index f53933b2ff02..7e058739f0d5 100644
--- a/drivers/pinctrl/Makefile
+++ b/drivers/pinctrl/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_PINCTRL_TB10X)   += pinctrl-tb10x.o
 obj-$(CONFIG_PINCTRL_ST)   += pinctrl-st.o
 obj-$(CONFIG_PINCTRL_STMFX)+= pinctrl-stmfx.o
 obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o
+obj-$(CONFIG_PINCTRL_ZYNQMP)+= pinctrl-zynqmp.o
 obj-$(CONFIG_PINCTRL_INGENIC)  += pinctrl-ingenic.o
 obj-$(CONFIG_PINCTRL_RK805)+= pinctrl-rk805.o
 obj-$(CONFIG_PINCTRL_OCELOT)   += pinctrl-ocelot.o
diff --git a/drivers/pinctrl/pinctrl-zynqmp.c b/drivers/pinctrl/pinctrl-zynqmp.c
new file mode 100644
index ..ec0a5d0e22d5
--- /dev/null
+++ b/drivers/pinctrl/pinctrl-zynqmp.c
@@ -0,0 +1,1031 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ZynqMP pin controller
+ *
+ *  Copyright (C) 2020 Xilinx, Inc.
+ *
+ *  Sai Krishna Potthuri 
+ *  Rajan Vaja 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "core.h"
+#include "pinctrl-utils.h"
+
+#define ZYNQMP_PIN_PREFIX  "MIO"
+#define PINCTRL_GET_FUNC_NAME_RESP_LEN 16
+#define MAX_FUNC_NAME_LEN  16
+#define MAX_GROUP_PIN  50
+#define END_OF_FUNCTIONS   "END_OF_FUNCTIONS"
+#define NUM_GROUPS_PER_RESP6
+
+#define PINCTRL_GET_FUNC_GROUPS_RESP_LEN   12
+#define PINCTRL_GET_PIN_GROUPS_RESP_LEN12
+#define NA_GROUP   -1
+#define RESERVED_GROUP -2
+
+#define DRIVE_STRENGTH_2MA 2
+#define DRIVE_STRENGTH_4MA 4
+#define DRIVE_STRENGTH_8MA 8
+#define DRIVE_STRENGTH_12MA12
+
+/**
+ * struct zynqmp_pmux_function - a pinmux function
+ * @name:  Name of the pinmux function
+ * @groups:List of pingroups for this function
+ * @ngroups:   Number of entries in @groups
+ * @node:` Firmware node matching with for function
+ *
+ * This structure holds information about pin control function
+ * and function group names supporting that function.
+ */
+struct zynqmp_pmux_function {
+   char name[MAX_FUNC_NAME_LEN];
+   const char * const *groups;
+   unsigned int ngroups;
+};
+
+/**
+ * struct zynqmp_pinctrl - driver data
+ * @pctrl: Pinctrl device
+ * @groups:Pingroups
+ * @ngroups:   Number of @groups
+ * @funcs: Pinmux functions
+ * @nfuncs:Number of @funcs
+ *
+ * This struct is stored as driver data and used to retrieve
+ * information regarding pin control functions, groups and
+ * group pins.
+ */
+struct zynqmp_pinctrl {
+   struct pinctrl_dev *pctrl;
+   const struct zynqmp_pctrl_group *groups;
+   unsigned int ngroups;
+   const struct zynqmp_pmux_function *funcs;
+   unsigned int nfuncs;
+};
+
+/**
+ * struct zynqmp_pctrl_group - Pin control group info
+ * @name:  Group name
+ * @pins:  Group pin numbers
+ * @npins: Number of pins in group
+ */
+struct zynqmp_pctrl_group {
+   const char *name;
+   unsigned int pins[MAX_GROUP_PIN];
+   unsigned int npins;
+};
+
+/**
+ * enum zynqmp_pin_config_param - possible pin configuration parameters
+ * @PIN_CONFIG_IOSTANDARD: if the pin can select an IO standard,
+ * the argument to this parameter (on a
+ * custom format) tells the driver which
+ * alternative IO standard to use
+ */
+enum zynqmp_pin_config_param {
+   PIN_CONFIG_IOSTANDARD = PIN_CONFIG_END + 1,
+};
+
+static const struct pinconf_generic_p

[PATCH v3 1/3] firmware: xilinx: Add pinctrl support

2021-02-12 Thread Sai Krishna Potthuri
Adding pinctrl support to query platform specific information (pins)
from firmware.

Signed-off-by: Sai Krishna Potthuri 
Acked-by: Michal Simek 
---
 drivers/firmware/xilinx/zynqmp.c | 114 +++
 include/linux/firmware/xlnx-zynqmp.h |  90 +
 2 files changed, 204 insertions(+)

diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index efb8a66efc68..299c3d5a9ebd 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -784,6 +784,120 @@ int zynqmp_pm_fpga_get_status(u32 *value)
 }
 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
 
+/**
+ * zynqmp_pm_pinctrl_request - Request Pin from firmware
+ * @pin: Pin number to request
+ *
+ * This function requests pin from firmware.
+ *
+ * Return: Returns status, either success or error+reason.
+ */
+int zynqmp_pm_pinctrl_request(const u32 pin)
+{
+   return zynqmp_pm_invoke_fn(PM_PINCTRL_REQUEST, pin, 0, 0, 0, NULL);
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_request);
+
+/**
+ * zynqmp_pm_pinctrl_release - Inform firmware that Pin control is released
+ * @pin: Pin number to release
+ *
+ * This function release pin from firmware.
+ *
+ * Return: Returns status, either success or error+reason.
+ */
+int zynqmp_pm_pinctrl_release(const u32 pin)
+{
+   return zynqmp_pm_invoke_fn(PM_PINCTRL_RELEASE, pin, 0, 0, 0, NULL);
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_release);
+
+/**
+ * zynqmp_pm_pinctrl_get_function - Read function id set for the given pin
+ * @pin: Pin number
+ * @id: Buffer to store function ID
+ *
+ * This function provides the function currently set for the given pin.
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_pinctrl_get_function(const u32 pin, u32 *id)
+{
+   u32 ret_payload[PAYLOAD_ARG_CNT];
+   int ret;
+
+   if (!id)
+   return -EINVAL;
+
+   ret = zynqmp_pm_invoke_fn(PM_PINCTRL_GET_FUNCTION, pin, 0,
+ 0, 0, ret_payload);
+   *id = ret_payload[1];
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_function);
+
+/**
+ * zynqmp_pm_pinctrl_set_function - Set requested function for the pin
+ * @pin: Pin number
+ * @id: Function ID to set
+ *
+ * This function sets requested function for the given pin.
+ *
+ * Return: Returns status, either success or error+reason.
+ */
+int zynqmp_pm_pinctrl_set_function(const u32 pin, const u32 id)
+{
+   return zynqmp_pm_invoke_fn(PM_PINCTRL_SET_FUNCTION, pin, id,
+  0, 0, NULL);
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_function);
+
+/**
+ * zynqmp_pm_pinctrl_get_config - Get configuration parameter for the pin
+ * @pin: Pin number
+ * @param: Parameter to get
+ * @value: Buffer to store parameter value
+ *
+ * This function gets requested configuration parameter for the given pin.
+ *
+ * Return: Returns status, either success or error+reason.
+ */
+int zynqmp_pm_pinctrl_get_config(const u32 pin, const u32 param,
+u32 *value)
+{
+   u32 ret_payload[PAYLOAD_ARG_CNT];
+   int ret;
+
+   if (!value)
+   return -EINVAL;
+
+   ret = zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_GET, pin, param,
+ 0, 0, ret_payload);
+   *value = ret_payload[1];
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_config);
+
+/**
+ * zynqmp_pm_pinctrl_set_config - Set configuration parameter for the pin
+ * @pin: Pin number
+ * @param: Parameter to set
+ * @value: Parameter value to set
+ *
+ * This function sets requested configuration parameter for the given pin.
+ *
+ * Return: Returns status, either success or error+reason.
+ */
+int zynqmp_pm_pinctrl_set_config(const u32 pin, const u32 param,
+u32 value)
+{
+   return zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_SET, pin,
+  param, value, 0, NULL);
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_config);
+
 /**
  * zynqmp_pm_init_finalize() - PM call to inform firmware that the caller
  *master has initialized its own power management
diff --git a/include/linux/firmware/xlnx-zynqmp.h 
b/include/linux/firmware/xlnx-zynqmp.h
index 5968df82b991..75aa6a5afa28 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -74,6 +74,12 @@ enum pm_api_id {
PM_FPGA_LOAD,
PM_FPGA_GET_STATUS,
PM_GET_CHIPID = 24,
+   PM_PINCTRL_REQUEST = 28,
+   PM_PINCTRL_RELEASE = 29,
+   PM_PINCTRL_GET_FUNCTION = 30,
+   PM_PINCTRL_SET_FUNCTION = 31,
+   PM_PINCTRL_CONFIG_PARAM_GET = 32,
+   PM_PINCTRL_CONFIG_PARAM_SET = 33,
PM_IOCTL = 34,
PM_QUERY_DATA,
PM_CLOCK_ENABLE,
@@ -125,6 +131,12 @@ enum pm_query_id {
PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS,
PM_QID_CLOCK_GET_PARENTS,
PM_QID_CLOCK_GET_ATTRIBUTES,
+   PM_QID_PINCTRL_GE

[PATCH v3 0/3] Add ZynqMP pinctrl driver

2021-02-12 Thread Sai Krishna Potthuri
Add support for Xilinx ZynqMP pinctrl driver and also update the
Xilinx firmware driver to support pinctrl functionality.
This driver queries the pin information from the firmware and
allow configuring the pins as per the request.

changes in v3:
- Fixed binding doc comments from Rob.
- Used 'maxItems' for groups and pins properties.
- Updated commit subject and description to have
present tense statements.

changes in v2:
- Use pattern for pin names in yaml file.
- Updated to support multiple groups and pins.
- Added type ref for the vendor specific properties.
- Removed 'schmitt-cmos', instead used common properties.
- Removed macros for drive-strength property.

Sai Krishna Potthuri (3):
  firmware: xilinx: Add pinctrl support
  dt-bindings: pinctrl: Add binding for ZynqMP pinctrl driver
  pinctrl: Add Xilinx ZynqMP pinctrl driver support

 .../bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml |  339 ++
 drivers/firmware/xilinx/zynqmp.c  |  114 ++
 drivers/pinctrl/Kconfig   |   13 +
 drivers/pinctrl/Makefile  |1 +
 drivers/pinctrl/pinctrl-zynqmp.c  | 1031 +
 include/dt-bindings/pinctrl/pinctrl-zynqmp.h  |   19 +
 include/linux/firmware/xlnx-zynqmp.h  |   90 ++
 7 files changed, 1607 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/pinctrl/xlnx,zynqmp-pinctrl.yaml
 create mode 100644 drivers/pinctrl/pinctrl-zynqmp.c
 create mode 100644 include/dt-bindings/pinctrl/pinctrl-zynqmp.h

-- 
2.17.1



Re: [PATCH v6 1/3] lib/vsprintf: Add support for printing V4L2 and DRM fourccs

2021-02-12 Thread Petr Mladek
On Fri 2021-02-12 13:28:56, Sakari Ailus wrote:
> On Thu, Feb 11, 2021 at 06:14:28PM +0100, Petr Mladek wrote:
> > On Tue 2021-02-09 19:47:55, Sakari Ailus wrote:
> > > Hi Andy,
> > > 
> > > On Tue, Feb 09, 2021 at 11:58:40AM +0200, Andy Shevchenko wrote:
> > > > On Tue, Feb 09, 2021 at 11:20:32AM +0200, Sakari Ailus wrote:
> > > > > On Mon, Feb 08, 2021 at 10:43:30PM +0200, Andy Shevchenko wrote:
> > > > > > On Mon, Feb 8, 2021 at 10:11 PM Sakari Ailus
> > > > > >  wrote:
> > > > 
> > > > > > > +   %p4cc   BG12 little-endian (0x32314742)
> > > > > > 
> > > > > > This misses examples of the (strange) escaping cases and wiped
> > > > > > whitespaces to make sure everybody understands that 'D 12' will be 
> > > > > > the
> > > > > > same as 'D1 2' (side note: which I disagree on, perhaps something
> > > > > > should be added into documentation why).
> 
> I discussed this with Hans and we concluded spaces shouldn't be dropped.
> 
> Spaces can be present in the codes themselves in any case.

Great!

> > 
> > > > 
> > > > ...
> > > > 
> > > > > > > +static noinline_for_stack
> > > > > > > +char *fourcc_string(char *buf, char *end, const u32 *fourcc,
> > > > > > > +   struct printf_spec spec, const char *fmt)
> > > > > > > +{
> > > > > > 
> > > > > > > +   char output[sizeof("(xx)(xx)(xx)(xx) little-endian 
> > > > > > > (0x01234567)")];
> > > > > > 
> > > > > > Do we have any evidence / document / standard that the above format 
> > > > > > is
> > > > > > what people would find good? From existing practices (I consider 
> > > > > > other
> > > > > > printings elsewhere and users in this series) I find '(xx)' form for
> > > > > > hex numbers is weird. The standard practice is to use \xHH (without
> > > > > > parentheses).
> > > > > 
> > > > > Earlier in the review it was proposed that special handling of codes 
> > > > > below
> > > > > 32 should be added, which I did. Using the parentheses is apparently 
> > > > > an
> > > > > existing practice elsewhere.
> > > > 
> > > > Where? \xHH is quite well established format for escaping. Never heard 
> > > > about
> > > > '(xx)' variant before this very series.
> > 
> > What about using the same approach as drm_get_format_name()?
> > I mean printing '?' when the character is not printable.
> > The exact value is printed later anyway.
> > 
> > The advantage is that it will always printk 4 characters.
> 
> "?" can be expanded by the shell. We (me and Hans) both though a dot (".")
> would be good. These aren't going to be present in valid fourcc codes in
> any case.

The dot (".") looks fine to me.

Best Regards,
Petr


Re: [PATCH] arch: x86: entry: vdso: Fix the spelling postive to positive in the file vsgx.S

2021-02-12 Thread Jarkko Sakkinen
On Wed, Feb 10, 2021 at 02:16:10PM +0530, Bhaskar Chowdhury wrote:
> 
> 
> s/postive/positive/

A bit more verbose, please, e.g.:

"Fix spelling error in arch/x86/entry/vdso/vsgx.S: postive -> positive."

> Signed-off-by: Bhaskar Chowdhury 
> ---
>  arch/x86/entry/vdso/vsgx.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/entry/vdso/vsgx.S b/arch/x86/entry/vdso/vsgx.S
> index 86a0e94f68df..99dafac992e2 100644
> --- a/arch/x86/entry/vdso/vsgx.S
> +++ b/arch/x86/entry/vdso/vsgx.S
> @@ -137,7 +137,7 @@ SYM_FUNC_START(__vdso_sgx_enter_enclave)
> 
>   /*
>* If the return from callback is zero or negative, return immediately,
> -  * else re-execute ENCLU with the postive return value interpreted as
> +  * else re-execute ENCLU with the positive return value interpreted as
>* the requested ENCLU function.
>*/
>   cmp $0, %eax
> --
> 2.30.0
> 
> 



Acked-by: Jarkko Sakkinen 

/Jarkko


[PATCH v2 4/4] usb: typec: tps6598x: Add trace event for data status

2021-02-12 Thread Guido Günther
This is useful to debug DP negotiation and pin assignment even
when the firmware does all the work.

Signed-off-by: Guido Günther 
---
 drivers/usb/typec/tps6598x.c   | 12 ++-
 drivers/usb/typec/tps6598x.h   | 36 
 drivers/usb/typec/tps6598x_trace.h | 54 ++
 3 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
index 3e6ad3ba7fc8..a4ec8e56c2b9 100644
--- a/drivers/usb/typec/tps6598x.c
+++ b/drivers/usb/typec/tps6598x.c
@@ -36,6 +36,7 @@
 #define TPS_REG_CTRL_CONF  0x29
 #define TPS_REG_POWER_STATUS   0x3f
 #define TPS_REG_RX_IDENTITY_SOP0x48
+#define TPS_REG_DATA_STATUS0x5f
 
 /* TPS_REG_SYSTEM_CONF bits */
 #define TPS_SYSCONF_PORTINFO(c)((c) & 7)
@@ -408,7 +409,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
struct tps6598x *tps = data;
u64 event1;
u64 event2;
-   u32 status;
+   u32 status, data_status;
u16 pwr_status;
int ret;
 
@@ -438,6 +439,15 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
trace_tps6598x_power_status(pwr_status);
}
 
+   if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) {
+   ret = tps6598x_read32(tps, TPS_REG_DATA_STATUS, &data_status);
+   if (ret < 0) {
+   dev_err(tps->dev, "failed to read data status: %d\n", 
ret);
+   goto err_clear_ints;
+   }
+   trace_tps6598x_data_status(data_status);
+   }
+
/* Handle plug insert or removal */
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
if (status & TPS_STATUS_PLUG_PRESENT) {
diff --git a/drivers/usb/typec/tps6598x.h b/drivers/usb/typec/tps6598x.h
index 3f6503377678..1afc22ab4dbb 100644
--- a/drivers/usb/typec/tps6598x.h
+++ b/drivers/usb/typec/tps6598x.h
@@ -146,4 +146,40 @@
 #define TPS_POWER_STATUS_BC12_STATUS_CDP 2
 #define TPS_POWER_STATUS_BC12_STATUS_DCP 3
 
+/* TPS_REG_DATA_STATUS bits */
+#define TPS_DATA_STATUS_DATA_CONNECTION BIT(0)
+#define TPS_DATA_STATUS_UPSIDE_DOWN BIT(1)
+#define TPS_DATA_STATUS_ACTIVE_CABLEBIT(2)
+#define TPS_DATA_STATUS_USB2_CONNECTION BIT(4)
+#define TPS_DATA_STATUS_USB3_CONNECTION BIT(5)
+#define TPS_DATA_STATUS_USB3_GEN2   BIT(6)
+#define TPS_DATA_STATUS_USB_DATA_ROLE   BIT(7)
+#define TPS_DATA_STATUS_DP_CONNECTION   BIT(8)
+#define TPS_DATA_STATUS_DP_SINK BIT(9)
+#define TPS_DATA_STATUS_TBT_CONNECTION  BIT(16)
+#define TPS_DATA_STATUS_TBT_TYPEBIT(17)
+#define TPS_DATA_STATUS_OPTICAL_CABLE   BIT(18)
+#define TPS_DATA_STATUS_ACTIVE_LINK_TRAINBIT(20)
+#define TPS_DATA_STATUS_FORCE_LSX   BIT(23)
+#define TPS_DATA_STATUS_POWER_MISMATCH  BIT(24)
+
+#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK GENMASK(11, 10)
+#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) \
+   FIELD_GET(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK, (x))
+#define TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK   GENMASK(27, 25)
+#define TPS_DATA_STATUS_TBT_CABLE_SPEED   
FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK, (x))
+#define TPS_DATA_STATUS_TBT_CABLE_GEN_MASK GENMASK(29, 28)
+#define TPS_DATA_STATUS_TBT_CABLE_GEN 
FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_GEN_MASK, (x))
+
+/* Map data status to DP spec assignments */
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT(x) \
+   ((TPS_DATA_STATUS_DP_PIN_ASSIGNMENT(x) << 1) | \
+   FIELD_GET(TPS_DATA_STATUS_USB3_CONNECTION, (x)))
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_E0
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_FBIT(0)
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_CBIT(1)
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_D(BIT(1) | BIT(0))
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_ABIT(2)
+#define TPS_DATA_STATUS_DP_SPEC_PIN_ASSIGNMENT_B(BIT(2) | BIT(1))
+
 #endif /* __TPS6598X_H__ */
diff --git a/drivers/usb/typec/tps6598x_trace.h 
b/drivers/usb/typec/tps6598x_trace.h
index 78a5a6ca337b..38bfb2f04e46 100644
--- a/drivers/usb/typec/tps6598x_trace.h
+++ b/drivers/usb/typec/tps6598x_trace.h
@@ -152,6 +152,41 @@
{ TPS_POWER_STATUS_BC12_STATUS_CDP, "cdp" }, \
{ TPS_POWER_STATUS_BC12_STATUS_SDP, "sdp" })
 
+#define TPS_DATA_STATUS_FLAGS_MASK (GENMASK(31, 0) ^ 
(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK | \
+ 
TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK | \
+ 
TPS_DATA_STATUS_TBT_CABLE_GEN_MASK))
+
+#define show_data_status_flags(data_status) \
+   __print_flags(data_status & TPS_DATA_STATUS_FLAGS_MASK, "|", \
+   { TPS_DATA_STATUS_DATA_CONNECTION,  "DATA_CONNECTION" }, \
+   { TPS_DATA_STATUS_UPSIDE_DOWN,  "DATA_UPSI

[PATCH v2 2/4] usb: typec: tps6598x: Add trace event for status register

2021-02-12 Thread Guido Günther
This allows to trace status information which helps to debug problems
with role switching, etc.

Signed-off-by: Guido Günther 
---
 drivers/usb/typec/tps6598x.c   | 26 -
 drivers/usb/typec/tps6598x.h   | 66 +
 drivers/usb/typec/tps6598x_trace.h | 94 ++
 3 files changed, 171 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
index bc34b35e909f..559aa175f948 100644
--- a/drivers/usb/typec/tps6598x.c
+++ b/drivers/usb/typec/tps6598x.c
@@ -37,13 +37,6 @@
 #define TPS_REG_POWER_STATUS   0x3f
 #define TPS_REG_RX_IDENTITY_SOP0x48
 
-/* TPS_REG_STATUS bits */
-#define TPS_STATUS_PLUG_PRESENTBIT(0)
-#define TPS_STATUS_ORIENTATION BIT(4)
-#define TPS_STATUS_PORTROLE(s) (!!((s) & BIT(5)))
-#define TPS_STATUS_DATAROLE(s) (!!((s) & BIT(6)))
-#define TPS_STATUS_VCONN(s)(!!((s) & BIT(7)))
-
 /* TPS_REG_SYSTEM_CONF bits */
 #define TPS_SYSCONF_PORTINFO(c)((c) & 7)
 
@@ -258,9 +251,9 @@ static int tps6598x_connect(struct tps6598x *tps, u32 
status)
}
 
typec_set_pwr_opmode(tps->port, mode);
-   typec_set_pwr_role(tps->port, TPS_STATUS_PORTROLE(status));
-   typec_set_vconn_role(tps->port, TPS_STATUS_VCONN(status));
-   tps6598x_set_data_role(tps, TPS_STATUS_DATAROLE(status), true);
+   typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));
+   typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));
+   tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), true);
 
tps->partner = typec_register_partner(tps->port, &desc);
if (IS_ERR(tps->partner))
@@ -280,9 +273,10 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 
status)
typec_unregister_partner(tps->partner);
tps->partner = NULL;
typec_set_pwr_opmode(tps->port, TYPEC_PWR_MODE_USB);
-   typec_set_pwr_role(tps->port, TPS_STATUS_PORTROLE(status));
-   typec_set_vconn_role(tps->port, TPS_STATUS_VCONN(status));
-   tps6598x_set_data_role(tps, TPS_STATUS_DATAROLE(status), false);
+   typec_set_pwr_role(tps->port, TPS_STATUS_TO_TYPEC_PORTROLE(status));
+   typec_set_vconn_role(tps->port, TPS_STATUS_TO_TYPEC_VCONN(status));
+   tps6598x_set_data_role(tps, TPS_STATUS_TO_TYPEC_DATAROLE(status), 
false);
+
power_supply_changed(tps->psy);
 }
 
@@ -366,7 +360,7 @@ static int tps6598x_dr_set(struct typec_port *port, enum 
typec_data_role role)
if (ret)
goto out_unlock;
 
-   if (role != TPS_STATUS_DATAROLE(status)) {
+   if (role != TPS_STATUS_TO_TYPEC_DATAROLE(status)) {
ret = -EPROTO;
goto out_unlock;
}
@@ -396,7 +390,7 @@ static int tps6598x_pr_set(struct typec_port *port, enum 
typec_role role)
if (ret)
goto out_unlock;
 
-   if (role != TPS_STATUS_PORTROLE(status)) {
+   if (role != TPS_STATUS_TO_TYPEC_PORTROLE(status)) {
ret = -EPROTO;
goto out_unlock;
}
@@ -437,6 +431,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
dev_err(tps->dev, "%s: failed to read status\n", __func__);
goto err_clear_ints;
}
+   trace_tps6598x_status(status);
 
/* Handle plug insert or removal */
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
@@ -612,6 +607,7 @@ static int tps6598x_probe(struct i2c_client *client)
ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
if (ret < 0)
return ret;
+   trace_tps6598x_status(status);
 
ret = tps6598x_read32(tps, TPS_REG_SYSTEM_CONF, &conf);
if (ret < 0)
diff --git a/drivers/usb/typec/tps6598x.h b/drivers/usb/typec/tps6598x.h
index b83b8a6a1504..866fd1deb471 100644
--- a/drivers/usb/typec/tps6598x.h
+++ b/drivers/usb/typec/tps6598x.h
@@ -12,6 +12,72 @@
 #ifndef __TPS6598X_H__
 #define __TPS6598X_H__
 
+/* TPS_REG_STATUS bits */
+#define TPS_STATUS_PLUG_PRESENTBIT(0)
+#define TPS_STATUS_PLUG_UPSIDE_DOWNBIT(4)
+#define TPS_STATUS_PORTROLEBIT(5)
+#define TPS_STATUS_TO_TYPEC_PORTROLE(s) (!!((s) & TPS_STATUS_PORTROLE))
+#define TPS_STATUS_DATAROLEBIT(6)
+#define TPS_STATUS_TO_TYPEC_DATAROLE(s)(!!((s) & TPS_STATUS_DATAROLE))
+#define TPS_STATUS_VCONN   BIT(7)
+#define TPS_STATUS_TO_TYPEC_VCONN(s)   (!!((s) & TPS_STATUS_VCONN))
+#define TPS_STATUS_OVERCURRENT BIT(16)
+#define TPS_STATUS_GOTO_MIN_ACTIVE BIT(26)
+#define TPS_STATUS_BISTBIT(27)
+#define TPS_STATUS_HIGH_VOLAGE_WARNING BIT(28)
+#define TPS_STATUS_HIGH_LOW_VOLTAGE_WARNING BIT(29)
+
+#define TPS_STATUS_CONN_STATE_MASK GENMASK(3, 1)
+#define TPS_STATUS_CONN_STATE(x)   
FIELD_GET(TPS_STATUS_CONN_STATE_MASK, (x))
+#define TPS_STATUS_PP_5V0_SWITCH_MASK   

[PATCH v2 1/4] usb: typec: tps6598x: Add trace event for IRQ events

2021-02-12 Thread Guido Günther
Allow to get irq event information via the tracing framework.  This
allows to inspect USB-C negotiation at runtime.

Signed-off-by: Guido Günther 
---
 drivers/usb/typec/Makefile |  3 +
 drivers/usb/typec/tps6598x.c   |  9 ++-
 drivers/usb/typec/tps6598x.h   | 64 
 drivers/usb/typec/tps6598x_trace.h | 97 ++
 4 files changed, 170 insertions(+), 3 deletions(-)
 create mode 100644 drivers/usb/typec/tps6598x.h
 create mode 100644 drivers/usb/typec/tps6598x_trace.h

diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile
index d03b48c4b864..27aa12129190 100644
--- a/drivers/usb/typec/Makefile
+++ b/drivers/usb/typec/Makefile
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
+# define_trace.h needs to know how to find our header
+CFLAGS_tps6598x.o  := -I$(src)
+
 obj-$(CONFIG_TYPEC)+= typec.o
 typec-y:= class.o mux.o bus.o
 obj-$(CONFIG_TYPEC)+= altmodes/
diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
index 6e6ef6317523..bc34b35e909f 100644
--- a/drivers/usb/typec/tps6598x.c
+++ b/drivers/usb/typec/tps6598x.c
@@ -6,6 +6,8 @@
  * Author: Heikki Krogerus 
  */
 
+#include "tps6598x.h"
+
 #include 
 #include 
 #include 
@@ -15,6 +17,9 @@
 #include 
 #include 
 
+#define CREATE_TRACE_POINTS
+#include "tps6598x_trace.h"
+
 /* Register offsets */
 #define TPS_REG_VID0x00
 #define TPS_REG_MODE   0x03
@@ -32,9 +37,6 @@
 #define TPS_REG_POWER_STATUS   0x3f
 #define TPS_REG_RX_IDENTITY_SOP0x48
 
-/* TPS_REG_INT_* bits */
-#define TPS_REG_INT_PLUG_EVENT BIT(3)
-
 /* TPS_REG_STATUS bits */
 #define TPS_STATUS_PLUG_PRESENTBIT(0)
 #define TPS_STATUS_ORIENTATION BIT(4)
@@ -428,6 +430,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
dev_err(tps->dev, "%s: failed to read events\n", __func__);
goto err_unlock;
}
+   trace_tps6598x_irq(event1, event2);
 
ret = tps6598x_read32(tps, TPS_REG_STATUS, &status);
if (ret) {
diff --git a/drivers/usb/typec/tps6598x.h b/drivers/usb/typec/tps6598x.h
new file mode 100644
index ..b83b8a6a1504
--- /dev/null
+++ b/drivers/usb/typec/tps6598x.h
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Driver for TI TPS6598x USB Power Delivery controller family
+ *
+ * Copyright (C) 2017, Intel Corporation
+ * Author: Heikki Krogerus 
+ */
+
+#include 
+#include 
+
+#ifndef __TPS6598X_H__
+#define __TPS6598X_H__
+
+
+/* TPS_REG_INT_* bits */
+#define TPS_REG_INT_USER_VID_ALT_MODE_OTHER_VDMBIT_ULL(27+32)
+#define TPS_REG_INT_USER_VID_ALT_MODE_ATTN_VDM BIT_ULL(26+32)
+#define TPS_REG_INT_USER_VID_ALT_MODE_EXIT BIT_ULL(25+32)
+#define TPS_REG_INT_USER_VID_ALT_MODE_ENTERED  BIT_ULL(24+32)
+#define TPS_REG_INT_EXIT_MODES_COMPLETEBIT_ULL(20+32)
+#define TPS_REG_INT_DISCOVER_MODES_COMPLETEBIT_ULL(19+32)
+#define TPS_REG_INT_VDM_MSG_SENT   BIT_ULL(18+32)
+#define TPS_REG_INT_VDM_ENTERED_MODE   BIT_ULL(17+32)
+#define TPS_REG_INT_ERROR_UNABLE_TO_SOURCE BIT_ULL(14+32)
+#define TPS_REG_INT_SRC_TRANSITION BIT_ULL(10+32)
+#define TPS_REG_INT_ERROR_DISCHARGE_FAILED BIT_ULL(9+32)
+#define TPS_REG_INT_ERROR_MESSAGE_DATA BIT_ULL(7+32)
+#define TPS_REG_INT_ERROR_PROTOCOL_ERROR   BIT_ULL(6+32)
+#define TPS_REG_INT_ERROR_MISSING_GET_CAP_MESSAGE  BIT_ULL(4+32)
+#define TPS_REG_INT_ERROR_POWER_EVENT_OCCURRED BIT_ULL(3+32)
+#define TPS_REG_INT_ERROR_CAN_PROVIDE_PWR_LATERBIT_ULL(2+32)
+#define TPS_REG_INT_ERROR_CANNOT_PROVIDE_PWR   BIT_ULL(1+32)
+#define TPS_REG_INT_ERROR_DEVICE_INCOMPATIBLE  BIT_ULL(0+32)
+#define TPS_REG_INT_CMD2_COMPLETE  BIT(31)
+#define TPS_REG_INT_CMD1_COMPLETE  BIT(30)
+#define TPS_REG_INT_ADC_HIGH_THRESHOLD BIT(29)
+#define TPS_REG_INT_ADC_LOW_THRESHOLD  BIT(28)
+#define TPS_REG_INT_PD_STATUS_UPDATE   BIT(27)
+#define TPS_REG_INT_STATUS_UPDATE  BIT(26)
+#define TPS_REG_INT_DATA_STATUS_UPDATE BIT(25)
+#define TPS_REG_INT_POWER_STATUS_UPDATEBIT(24)
+#define TPS_REG_INT_PP_SWITCH_CHANGED  BIT(23)
+#define TPS_REG_INT_HIGH_VOLTAGE_WARNING   BIT(22)
+#define TPS_REG_INT_USB_HOST_PRESENT_NO_LONGER BIT(21)
+#define TPS_REG_INT_USB_HOST_PRESENT   BIT(20)
+#define TPS_REG_INT_GOTO_MIN_RECEIVED  BIT(19)
+#define TPS_REG_INT_PR_SWAP_REQUESTED  BIT(17)
+#define TPS_REG_INT_SINK_CAP_MESSAGE_READY BIT(15)
+#define TPS_REG_INT_SOURCE_CAP_MESSAGE_READY   BIT(14)
+#define TPS_REG_INT_NE

[PATCH v2 0/4] usb: typec: tps6598x: Add IRQ flag and register tracing

2021-02-12 Thread Guido Günther
This series adds tracing events for the chips IRQ and registers that are useful
to figure out the current data and power status. This came about since
diagnosing why a certain usb-c hub or dp-alt-mode adapter fails is hard with
the information in /sys/class/typec alone since this does not have a timeline
of events (and we don't want every typec user having to also buy a PD
analyzer). With this series debugging these kinds of things starts to become
fun:

   # echo 1 > /sys/kernel/debug/tracing/events/tps6598x/enable
   # cat /sys/kernel/debug/tracing/trace_pipe
   irq/79-0-003f-526 [003]    512.717871: tps6598x_irq: 
event1=PLUG_EVENT|DATA_STATUS_UPDATE|STATUS_UPDATE, event2=
   irq/79-0-003f-526 [003]    512.722408: tps6598x_status: conn: 
conn-Ra, pp_5v0: off, pp_hv: off, pp_ext: off, pp_cable: off, pwr-src: vin-3p3, 
vbus: vSafe0V, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE
   irq/79-0-003f-526 [003]    512.727127: tps6598x_data_status: 
DATA_CONNECTION|USB2_CONNECTION|USB3_CONNECTION
   irq/79-0-003f-526 [003]    512.769571: tps6598x_irq: 
event1=PP_SWITCH_CHANGED|STATUS_UPDATE, event2=
   irq/79-0-003f-526 [003]    512.773380: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: vSafe0V, usb-host: no, legacy: no, flags: 
PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    512.872450: tps6598x_irq: 
event1=POWER_STATUS_UPDATE|PD_STATUS_UPDATE, event2=
   irq/79-0-003f-526 [003]    512.876311: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: vSafe0V, usb-host: no, legacy: no, flags: 
PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    512.880237: tps6598x_power_status: conn: 
1, pwr-role: source, typec: usb, bc: sdp
   irq/79-0-003f-526 [003]    513.072682: tps6598x_irq: 
event1=STATUS_UPDATE, event2=
   irq/79-0-003f-526 [003]    513.076390: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: vSafe5V, usb-host: no, legacy: no, flags: 
PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    513.090676: tps6598x_irq: 
event1=ERROR_CANNOT_PROVIDE_PWR, event2=
   irq/79-0-003f-526 [003]    513.094368: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: vSafe5V, usb-host: no, legacy: no, flags: 
PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    513.109606: tps6598x_irq: 
event1=NEW_CONTRACT_AS_PROVIDER|POWER_STATUS_UPDATE|STATUS_UPDATE|SRC_TRANSITION,
 event2=
   irq/79-0-003f-526 [003]    513.113777: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    513.117475: tps6598x_power_status: conn: 
1, pwr-role: source, typec: pd, bc: sdp
   irq/79-0-003f-526 [003]    513.137469: tps6598x_irq: 
event1=VDM_RECEIVED, event2=
   irq/79-0-003f-526 [003]    513.141570: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    513.281926: tps6598x_irq: 
event1=VDM_RECEIVED, event2=
   irq/79-0-003f-526 [003]    513.285638: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    513.300515: tps6598x_irq: 
event1=VDM_RECEIVED|DATA_STATUS_UPDATE, event2=
   irq/79-0-003f-526 [003]    513.304226: tps6598x_status: conn: 
conn-Ra, pp_5v0: out, pp_hv: off, pp_ext: off, pp_cable: in, pwr-src: vin-3p3, 
vbus: pd, usb-host: no, legacy: no, flags: PLUG_PRESENT|PORTROLE|DATAROLE|VCONN
   irq/79-0-003f-526 [003]    513.308302: tps6598x_data_status: 
DATA_CONNECTION|USB2_CONNECTION|USB3_CONNECTION|DP_CONNECTION, DP pinout D

It should not impose any problems for firmwares that don't have IRQs for the
registers enabled. The trace will then just be missing those events.

Patch is against next-20210210.

changes from v1:
- Fix issues on 32bit arches and missing include spotted by kbuild
  (build testes on mips)



Guido Günther (4):
  usb: typec: tps6598x: Add trace event for IRQ events
  usb: typec: tps6598x: Add trace event for status register
  usb: typec: tps6598x: Add trace event for power status register
  usb: typec: tps6598x: Add trace event for data status

 drivers/usb/typec/Makefile |   3 +
 drivers/usb/typec/tps6598x.c   |  66 ---
 drivers/usb/typec/tps6598x.h   | 185 +++
 drivers/usb/typec/tps6598x_trace.h | 283 +

[PATCH v2 3/4] usb: typec: tps6598x: Add trace event for power status register

2021-02-12 Thread Guido Günther
Together with the PD status register this is vital for debugging power
negotiations at runtime.

Signed-off-by: Guido Günther 
---
 drivers/usb/typec/tps6598x.c   | 19 +--
 drivers/usb/typec/tps6598x.h   | 19 +++
 drivers/usb/typec/tps6598x_trace.h | 38 ++
 3 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
index 559aa175f948..3e6ad3ba7fc8 100644
--- a/drivers/usb/typec/tps6598x.c
+++ b/drivers/usb/typec/tps6598x.c
@@ -50,11 +50,6 @@ enum {
TPS_PORTINFO_SOURCE,
 };
 
-/* TPS_REG_POWER_STATUS bits */
-#define TPS_POWER_STATUS_CONNECTIONBIT(0)
-#define TPS_POWER_STATUS_SOURCESINKBIT(1)
-#define TPS_POWER_STATUS_PWROPMODE(p)  (((p) & GENMASK(3, 2)) >> 2)
-
 /* TPS_REG_RX_IDENTITY_SOP */
 struct tps6598x_rx_identity_reg {
u8 status;
@@ -414,6 +409,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
u64 event1;
u64 event2;
u32 status;
+   u16 pwr_status;
int ret;
 
mutex_lock(&tps->lock);
@@ -433,6 +429,15 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data)
}
trace_tps6598x_status(status);
 
+   if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) {
+   ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &pwr_status);
+   if (ret < 0) {
+   dev_err(tps->dev, "failed to read power status: %d\n", 
ret);
+   goto err_clear_ints;
+   }
+   trace_tps6598x_power_status(pwr_status);
+   }
+
/* Handle plug insert or removal */
if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) {
if (status & TPS_STATUS_PLUG_PRESENT) {
@@ -497,8 +502,8 @@ static int tps6598x_psy_get_online(struct tps6598x *tps,
if (ret < 0)
return ret;
 
-   if ((pwr_status & TPS_POWER_STATUS_CONNECTION) &&
-   (pwr_status & TPS_POWER_STATUS_SOURCESINK)) {
+   if (TPS_POWER_STATUS_CONNECTION(pwr_status) &&
+   TPS_POWER_STATUS_SOURCESINK(pwr_status)) {
val->intval = 1;
} else {
val->intval = 0;
diff --git a/drivers/usb/typec/tps6598x.h b/drivers/usb/typec/tps6598x.h
index 866fd1deb471..3f6503377678 100644
--- a/drivers/usb/typec/tps6598x.h
+++ b/drivers/usb/typec/tps6598x.h
@@ -127,4 +127,23 @@
 #define TPS_REG_INT_HARD_RESET BIT(1)
 #define TPS_REG_INT_PD_SOFT_RESET  BIT(0)
 
+/* TPS_REG_POWER_STATUS bits */
+#define TPS_POWER_STATUS_CONNECTION(x)  FIELD_GET(BIT(0), (x))
+#define TPS_POWER_STATUS_SOURCESINK(x) FIELD_GET(BIT(1), (x))
+#define TPS_POWER_STATUS_BC12_DET(x)   FIELD_GET(BIT(2), (x))
+
+#define TPS_POWER_STATUS_TYPEC_CURRENT_MASK GENMASK(3, 2)
+#define TPS_POWER_STATUS_PWROPMODE(p)  
FIELD_GET(TPS_POWER_STATUS_TYPEC_CURRENT_MASK, (p))
+#define TPS_POWER_STATUS_BC12_STATUS_MASK   GENMASK(6, 5)
+#define TPS_POWER_STATUS_BC12_STATUS(p)
FIELD_GET(TPS_POWER_STATUS_BC12_STATUS_MASK, (p))
+
+#define TPS_POWER_STATUS_TYPEC_CURRENT_USB 0
+#define TPS_POWER_STATUS_TYPEC_CURRENT_1A5 1
+#define TPS_POWER_STATUS_TYPEC_CURRENT_3A0 2
+#define TPS_POWER_STATUS_TYPEC_CURRENT_PD  3
+
+#define TPS_POWER_STATUS_BC12_STATUS_SDP 0
+#define TPS_POWER_STATUS_BC12_STATUS_CDP 2
+#define TPS_POWER_STATUS_BC12_STATUS_DCP 3
+
 #endif /* __TPS6598X_H__ */
diff --git a/drivers/usb/typec/tps6598x_trace.h 
b/drivers/usb/typec/tps6598x_trace.h
index e0677b9c5c53..78a5a6ca337b 100644
--- a/drivers/usb/typec/tps6598x_trace.h
+++ b/drivers/usb/typec/tps6598x_trace.h
@@ -134,6 +134,24 @@
  { TPS_STATUS_HIGH_VOLAGE_WARNING, "HIGH_VOLAGE_WARNING" 
}, \
  { TPS_STATUS_HIGH_LOW_VOLTAGE_WARNING, 
"HIGH_LOW_VOLTAGE_WARNING" })
 
+#define show_power_status_source_sink(power_status) \
+   __print_symbolic(TPS_POWER_STATUS_SOURCESINK(power_status), \
+   { 1, "sink" }, \
+   { 0, "source" })
+
+#define show_power_status_typec_status(power_status) \
+   __print_symbolic(TPS_POWER_STATUS_PWROPMODE(power_status), \
+   { TPS_POWER_STATUS_TYPEC_CURRENT_PD,  "pd" }, \
+   { TPS_POWER_STATUS_TYPEC_CURRENT_3A0, "3.0A" }, \
+   { TPS_POWER_STATUS_TYPEC_CURRENT_1A5, "1.5A" }, \
+   { TPS_POWER_STATUS_TYPEC_CURRENT_USB, "usb" })
+
+#define show_power_status_bc12_status(power_status) \
+   __print_symbolic(TPS_POWER_STATUS_BC12_STATUS(power_status), \
+   { TPS_POWER_STATUS_BC12_STATUS_DCP, "dcp" }, \
+   { TPS_POWER_STATUS_BC12_STATUS_CDP, "cdp" }, \
+   { TPS_POWER_STATUS_BC12_STATUS_SDP, "sdp" })
+
 TRACE_EVENT(tps6598x_irq,
TP_PROTO(u64 event1,
 u64 event2),
@@ -181,6 +199,26 @@ TRACE_EVENT(tps6598x_status,
)
 );
 
+TRACE_EVENT(tps6598x_power_status,
+   TP_PR

Re: [PATCH 1/6] fs: Add flag to file_system_type to indicate content is generated

2021-02-12 Thread Luis Henriques
Greg KH  writes:

> On Fri, Feb 12, 2021 at 10:22:16AM +0200, Amir Goldstein wrote:
>> On Fri, Feb 12, 2021 at 9:49 AM Greg KH  wrote:
>> >
>> > On Fri, Feb 12, 2021 at 12:44:00PM +0800, Nicolas Boichat wrote:
>> > > Filesystems such as procfs and sysfs generate their content at
>> > > runtime. This implies the file sizes do not usually match the
>> > > amount of data that can be read from the file, and that seeking
>> > > may not work as intended.
>> > >
>> > > This will be useful to disallow copy_file_range with input files
>> > > from such filesystems.
>> > >
>> > > Signed-off-by: Nicolas Boichat 
>> > > ---
>> > > I first thought of adding a new field to struct file_operations,
>> > > but that doesn't quite scale as every single file creation
>> > > operation would need to be modified.
>> >
>> > Even so, you missed a load of filesystems in the kernel with this patch
>> > series, what makes the ones you did mark here different from the
>> > "internal" filesystems that you did not?
>> >
>> > This feels wrong, why is userspace suddenly breaking?  What changed in
>> > the kernel that caused this?  Procfs has been around for a _very_ long
>> > time :)
>> 
>> That would be because of (v5.3):
>> 
>> 5dae222a5ff0 vfs: allow copy_file_range to copy across devices
>> 
>> The intention of this change (series) was to allow server side copy
>> for nfs and cifs via copy_file_range().
>> This is mostly work by Dave Chinner that I picked up following requests
>> from the NFS folks.
>> 
>> But the above change also includes this generic change:
>> 
>> -   /* this could be relaxed once a method supports cross-fs copies */
>> -   if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb)
>> -   return -EXDEV;
>> -
>> 
>> The change of behavior was documented in the commit message.
>> It was also documented in:
>> 
>> 88e75e2c5 copy_file_range.2: Kernel v5.3 updates
>> 
>> I think our rationale for the generic change was:
>> "Why not? What could go wrong? (TM)"
>> I am not sure if any workload really gained something from this
>> kernel cross-fs CFR.
>
> Why not put that check back?
>
>> In retrospect, I think it would have been safer to allow cross-fs CFR
>> only to the filesystems that implement ->{copy,remap}_file_range()...
>
> Why not make this change?  That seems easier and should fix this for
> everyone, right?
>
>> Our option now are:
>> - Restore the cross-fs restriction into generic_copy_file_range()
>
> Yes.
>

Restoring this restriction will actually change the current cephfs CFR
behaviour.  Since that commit we have allowed doing remote copies between
different filesystems within the same ceph cluster.  See commit
6fd4e6348352 ("ceph: allow object copies across different filesystems in
the same cluster").

Although I'm not aware of any current users for this scenario, the
performance impact can actually be huge as it's the difference between
asking the OSDs for copying a file and doing a full read+write on the
client side.

Cheers,
-- 
Luis


>> - Explicitly opt-out of CFR per-fs and/or per-file as Nicolas' patch does
>
> No.  That way lies constant auditing and someone being "vigilant" for
> the next 30+ years.  Which will not happen.
>
> thanks,
>
> greg k-h


Re: [PATCH v13 6/7] arm64: mte: Report async tag faults before suspend

2021-02-12 Thread Lorenzo Pieralisi
On Thu, Feb 11, 2021 at 03:33:52PM +, Vincenzo Frascino wrote:
> When MTE async mode is enabled TFSR_EL1 contains the accumulative
> asynchronous tag check faults for EL1 and EL0.
> 
> During the suspend/resume operations the firmware might perform some
> operations that could change the state of the register resulting in
> a spurious tag check fault report.
> 
> Report asynchronous tag faults before suspend and clear the TFSR_EL1
> register after resume to prevent this to happen.
> 
> Cc: Catalin Marinas 
> Cc: Will Deacon 
> Cc: Lorenzo Pieralisi 
> Signed-off-by: Vincenzo Frascino 
> ---
>  arch/arm64/include/asm/mte.h |  4 
>  arch/arm64/kernel/mte.c  | 20 
>  arch/arm64/kernel/suspend.c  |  3 +++
>  3 files changed, 27 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
> index 43169b978cd3..33e88a470357 100644
> --- a/arch/arm64/include/asm/mte.h
> +++ b/arch/arm64/include/asm/mte.h
> @@ -41,6 +41,7 @@ void mte_sync_tags(pte_t *ptep, pte_t pte);
>  void mte_copy_page_tags(void *kto, const void *kfrom);
>  void flush_mte_state(void);
>  void mte_thread_switch(struct task_struct *next);
> +void mte_suspend_enter(void);
>  void mte_suspend_exit(void);
>  long set_mte_ctrl(struct task_struct *task, unsigned long arg);
>  long get_mte_ctrl(struct task_struct *task);
> @@ -66,6 +67,9 @@ static inline void flush_mte_state(void)
>  static inline void mte_thread_switch(struct task_struct *next)
>  {
>  }
> +static inline void mte_suspend_enter(void)
> +{
> +}
>  static inline void mte_suspend_exit(void)
>  {
>  }
> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c
> index f5aa5bea6dfe..de905102245a 100644
> --- a/arch/arm64/kernel/mte.c
> +++ b/arch/arm64/kernel/mte.c
> @@ -258,12 +258,32 @@ void mte_thread_switch(struct task_struct *next)
>   mte_check_tfsr_el1();
>  }
>  
> +void mte_suspend_enter(void)
> +{
> + if (!system_supports_mte())
> + return;
> +
> + /*
> +  * The barriers are required to guarantee that the indirect writes
> +  * to TFSR_EL1 are synchronized before we report the state.
> +  */
> + dsb(nsh);
> + isb();
> +
> + /* Report SYS_TFSR_EL1 before suspend entry */
> + mte_check_tfsr_el1();
> +}
> +
>  void mte_suspend_exit(void)
>  {
>   if (!system_supports_mte())
>   return;
>  
>   update_gcr_el1_excl(gcr_kernel_excl);
> +
> + /* Clear SYS_TFSR_EL1 after suspend exit */
> + write_sysreg_s(0, SYS_TFSR_EL1);

AFAICS it is not needed, it is done already in __cpu_setup() (that is
called by cpu_resume on return from cpu_suspend() from firmware).

However, I have a question. We are relying on context switch to set
sctlr_el1_tfc0 right ? If that's the case, till the thread resuming from
low power switches context we are running with SCTLR_EL1_TCF0 not
reflecting the actual value.

Just making sure that I understand it correctly, I need to check the
resume from suspend-to-RAM path, it is something that came up with perf
save/restore already in the past.

Lorenzo

> +
>  }
>  
>  long set_mte_ctrl(struct task_struct *task, unsigned long arg)
> diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c
> index a67b37a7a47e..25a02926ad88 100644
> --- a/arch/arm64/kernel/suspend.c
> +++ b/arch/arm64/kernel/suspend.c
> @@ -91,6 +91,9 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
>   unsigned long flags;
>   struct sleep_stack_data state;
>  
> + /* Report any MTE async fault before going to suspend */
> + mte_suspend_enter();
> +
>   /*
>* From this point debug exceptions are disabled to prevent
>* updates to mdscr register (saved and restored along with
> -- 
> 2.30.0
> 


Re: [RFC PATCH 11/12] platform/x86: skeleton for oftree based board device initialization

2021-02-12 Thread Enrico Weigelt, metux IT consult

On 12.02.21 10:58, Linus Walleij wrote:

Hi,


I think Intel people often take the stance that the ACPI DSDT (or whatever)
needs to be fixed.


It should, actually board/firmware vendors should think more carefully
and do it right in the first place. But reality is different. And
firmware upgrade often is anything but easy (as soon as we leave the
field of average Joh Doe's home PC)


If the usecase is to explicitly work around deployed firmware that cannot
and will not be upgraded/fixed by describing the hardware using DT
instead, based on just the DMI ID then we should spell that out
explicitly.


Okay, maybe I should have stated this more clearly.

OTOH, the scope is also a little bit greater: certain external cards
that don't need much special handling for the card itself, just
enumerate devices (and connections between them) using existing drivers.

That's a pretty common scenario in industrial backplane systems, where
we have lots of different (even application specific) cards, usually
composed of standard chips, that can be identified by some ID, but
cannot describe themselves. We have to write lots of specific drivers
for them, usually just for instantiating existing drivers. (we rarely
see such code going towards mainline).

A similar case (mainlined) seems to be the RCAR display unit - they're
using dt overlays that are built into the driver and applied by it
based on the detected DU at runtime. RCAR seems to be a pure DT
platform, so that's an obvious move. APU2/3/4 is ACPI based, so I went
in a different direction - but I'm now investigating how to make DT
overlays work on an ACPI platform (eg. needs some initial nodes, ...)
In case that's successful, I'll rework my RFC to use overlays, and
it will become much smaller (my oftree core changes then won't be
necessary anymore).


It feels a bit like fixing a problem using a different hardware description
just because we can. Look in drivers/gpio/gpiolib-acpi.c
table gpiolib_acpi_quirks[]. It's just an example how this is fixed using
fine granular ACPI-specific mechanisms at several places in the kernel
instead of just tossing out the whole description and redoing it in
device tree.


I'm quite reluctant to put everything in there. Theoretically, for apu
case, I could prevent enumerating the incomplete gpios there, but the
actual driver setup still remains (certainly don't wanna put that into
such a global place). But the original problem of having to write so
much code for just instantiating generic drivers remains. And
distributing knowledge of certain devices over several places doesn't
feel like a good idea to me.


--mtx

--
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
i...@metux.net -- +49-151-27565287


[PATCH 7/7] arm64: dts: qcom: sm8350: Use enums for GCC

2021-02-12 Thread Vinod Koul
Now that we have GCC define, use the enums instead of numbers in the DTS

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350.dtsi | 91 ++--
 1 file changed, 46 insertions(+), 45 deletions(-)

diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi 
b/arch/arm64/boot/dts/qcom/sm8350.dtsi
index 6e366653eeab..d19ed7b5aae0 100644
--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -430,8 +431,8 @@ qupv3_id_1: geniqup@9c {
compatible = "qcom,geni-se-qup";
reg = <0x0 0x009c 0x0 0x6000>;
clock-names = "m-ahb", "s-ahb";
-   clocks = <&gcc 121>,
-<&gcc 122>;
+   clocks = <&gcc GCC_QUPV3_WRAP_0_M_AHB_CLK>,
+<&gcc GCC_QUPV3_WRAP_0_S_AHB_CLK>;
#address-cells = <2>;
#size-cells = <2>;
ranges;
@@ -441,7 +442,7 @@ uart2: serial@98c000 {
compatible = "qcom,geni-debug-uart";
reg = <0 0x0098c000 0 0x4000>;
clock-names = "se";
-   clocks = <&gcc 83>;
+   clocks = <&gcc GCC_QUPV3_WRAP0_S3_CLK>;
pinctrl-names = "default";
pinctrl-0 = <&qup_uart3_default_state>;
interrupts = ;
@@ -797,10 +798,10 @@ ufs_mem_hc: ufshc@1d84000 {
phy-names = "ufsphy";
lanes-per-direction = <2>;
#reset-cells = <1>;
-   resets = <&gcc 25>;
+   resets = <&gcc GCC_UFS_PHY_BCR>;
reset-names = "rst";
 
-   power-domains = <&gcc 3>;
+   power-domains = <&gcc UFS_PHY_GDSC>;
 
iommus = <&apps_smmu 0xe0 0x0>;
 
@@ -816,14 +817,14 @@ ufs_mem_hc: ufshc@1d84000 {
"rx_lane1_sync_clk";
clocks =
<&rpmhcc RPMH_CXO_CLK>,
-   <&gcc 155>,
-   <&gcc 16>,
-   <&gcc 154>,
-   <&gcc 170>,
+   <&gcc GCC_UFS_PHY_AXI_CLK>,
+   <&gcc GCC_AGGRE_UFS_PHY_AXI_CLK>,
+   <&gcc GCC_UFS_PHY_AHB_CLK>,
+   <&gcc GCC_UFS_PHY_UNIPRO_CORE_CLK>,
<&rpmhcc RPMH_CXO_CLK>,
-   <&gcc 168>,
-   <&gcc 164>,
-   <&gcc 166>;
+   <&gcc GCC_UFS_PHY_TX_SYMBOL_0_CLK>,
+   <&gcc GCC_UFS_PHY_RX_SYMBOL_0_CLK>,
+   <&gcc GCC_UFS_PHY_RX_SYMBOL_1_CLK>;
freq-table-hz =
<7500 3>,
<7500 3>,
@@ -847,7 +848,7 @@ ufs_mem_phy: phy@1d87000 {
clock-names = "ref",
  "ref_aux";
clocks = <&rpmhcc RPMH_CXO_CLK>,
-<&gcc 161>;
+<&gcc GCC_UFS_PHY_PHY_AUX_CLK>;
 
resets = <&ufs_mem_hc 0>;
reset-names = "ufsphy";
@@ -953,7 +954,7 @@ usb_1_hsphy: phy@88e3000 {
clocks = <&rpmhcc RPMH_CXO_CLK>;
clock-names = "ref";
 
-   resets = <&gcc 20>;
+   resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>;
};
 
usb_2_hsphy: phy@88e4000 {
@@ -966,7 +967,7 @@ usb_2_hsphy: phy@88e4000 {
clocks = <&rpmhcc RPMH_CXO_CLK>;
clock-names = "ref";
 
-   resets = <&gcc 21>;
+   resets = <&gcc GCC_QUSB2PHY_SEC_BCR>;
};
 
usb_1_qmpphy: phy-wrapper@88e9000 {
@@ -980,13 +981,13 @@ usb_1_qmpphy: phy-wrapper@88e9000 {
#size-cells = <2>;
ranges;
 
-   clocks = <&gcc 187>,
+   clocks = <&gcc GCC_USB3_PRIM_PHY_AUX_CLK>,
 <&rpmhcc RPMH_CXO_CLK>,
-<&gcc 189>;
+<&gcc GCC_USB3_PRIM_PHY_COM_AUX_CLK>;
clock-names = "aux", "ref_clk_src", "com_aux";
 
-   resets = <&gcc 28>,
-<&gcc 30>;
+   resets = <&gcc GCC_USB3_DP_PHY_PRIM_BCR>,
+

[PATCH 6/7] arm64: dts: qcom: sm8350-mtp: Enable remoteprocs

2021-02-12 Thread Vinod Koul
This enabled the four remoteprocs found in SM8350, audio, compute, modem
and sensor for MTP platform and adds firmware for them.

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350-mtp.dts | 20 
 1 file changed, 20 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8350-mtp.dts 
b/arch/arm64/boot/dts/qcom/sm8350-mtp.dts
index e544fe6b421f..98a517edd442 100644
--- a/arch/arm64/boot/dts/qcom/sm8350-mtp.dts
+++ b/arch/arm64/boot/dts/qcom/sm8350-mtp.dts
@@ -32,6 +32,11 @@ vph_pwr: vph-pwr-regulator {
};
 };
 
+&adsp {
+   status = "okay";
+   firmware-name = "qcom/sm8350/adsp.mbn";
+};
+
 &apps_rsc {
pm8350-rpmh-regulators {
compatible = "qcom,pm8350-rpmh-regulators";
@@ -265,10 +270,25 @@ vreg_l13c_3p0: ldo13 {
};
 };
 
+&cdsp {
+   status = "okay";
+   firmware-name = "qcom/sm8350/cdsp.mbn";
+};
+
+&mpss {
+   status = "okay";
+   firmware-name = "qcom/sm8350/modem.mbn";
+};
+
 &qupv3_id_1 {
status = "okay";
 };
 
+&slpi {
+   status = "okay";
+   firmware-name = "qcom/sm8350/slpi.mbn";
+};
+
 &tlmm {
gpio-reserved-ranges = <52 8>;
 };
-- 
2.26.2



[PATCH 5/7] arm64: dts: qcom: sm8350: Add remoteprocs

2021-02-12 Thread Vinod Koul
Add remoteproc nodes for the audio, compute and sensor cores, define
glink for each one.

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350.dtsi | 158 +++
 1 file changed, 158 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi 
b/arch/arm64/boot/dts/qcom/sm8350.dtsi
index 1ea72f30ea5a..6e366653eeab 100644
--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
@@ -562,6 +562,46 @@ tcsr_mutex: hwlock@1f4 {
#hwlock-cells = <1>;
};
 
+   mpss: remoteproc@408 {
+   compatible = "qcom,sm8350-mpss-pas";
+   reg = <0x0 0x0408 0x0 0x4040>;
+
+   interrupts-extended = <&intc GIC_SPI 264 
IRQ_TYPE_LEVEL_HIGH>,
+ <&smp2p_modem_in 0 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_modem_in 1 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_modem_in 2 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_modem_in 3 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_modem_in 7 
IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready", "handover",
+ "stop-ack", "shutdown-ack";
+
+   clocks = <&rpmhcc RPMH_CXO_CLK>;
+   clock-names = "xo";
+
+   power-domains = <&aoss_qmp AOSS_QMP_LS_MODEM>,
+   <&rpmhpd SM8350_CX>,
+   <&rpmhpd SM8350_MSS>;
+   power-domain-names = "load_state", "cx", "mss";
+
+   memory-region = <&pil_modem_mem>;
+
+   qcom,smem-states = <&smp2p_modem_out 0>;
+   qcom,smem-state-names = "stop";
+
+   status = "disabled";
+
+   glink-edge {
+   interrupts-extended = <&ipcc IPCC_CLIENT_MPSS
+
IPCC_MPROC_SIGNAL_GLINK_QMP
+
IRQ_TYPE_EDGE_RISING>;
+   mboxes = <&ipcc IPCC_CLIENT_MPSS
+   IPCC_MPROC_SIGNAL_GLINK_QMP>;
+   interrupts = ;
+   label = "modem";
+   qcom,remote-pid = <1>;
+   };
+   };
+
pdc: interrupt-controller@b22 {
compatible = "qcom,sm8350-pdc", "qcom,pdc";
reg = <0 0x0b22 0 0x3>, <0 0x17c000f0 0 0x60>;
@@ -824,6 +864,85 @@ ufs_mem_phy_lanes: lanes@1d87400 {
};
};
 
+   slpi: remoteproc@5c0 {
+   compatible = "qcom,sm8350-slpi-pas";
+   reg = <0 0x05c0 0 0x4000>;
+
+   interrupts-extended = <&pdc 9 IRQ_TYPE_LEVEL_HIGH>,
+ <&smp2p_slpi_in 0 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_slpi_in 1 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_slpi_in 2 
IRQ_TYPE_EDGE_RISING>,
+ <&smp2p_slpi_in 3 
IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+ "handover", "stop-ack";
+
+   clocks = <&rpmhcc RPMH_CXO_CLK>;
+   clock-names = "xo";
+
+   power-domains = <&aoss_qmp AOSS_QMP_LS_SLPI>,
+   <&rpmhpd SM8350_LCX>,
+   <&rpmhpd SM8350_LMX>;
+   power-domain-names = "load_state", "lcx", "lmx";
+
+   memory-region = <&pil_slpi_mem>;
+
+   qcom,smem-states = <&smp2p_slpi_out 0>;
+   qcom,smem-state-names = "stop";
+
+   status = "disabled";
+
+   glink-edge {
+   interrupts-extended = <&ipcc IPCC_CLIENT_SLPI
+
IPCC_MPROC_SIGNAL_GLINK_QMP
+
IRQ_TYPE_EDGE_RISING>;
+   mboxes = <&ipcc IPCC_CLIENT_SLPI
+   IPCC_MPROC_SIGNAL_GLINK_QMP>;
+
+   label = "slpi";
+   qcom,remote-pid = <3>;
+
+   };
+   };
+
+   cdsp: remoteproc@9890 {
+   compatible = "qcom,sm8350-cdsp-pas";
+   reg = <0 0

[PATCH 4/7] arm64: dts: qcom: sm8350: Add SMP2P nodes

2021-02-12 Thread Vinod Koul
SMP2P is used for interrupting and being interrupted about remoteproc
state changes related to the audio, compute, modem and sensor subsystems.

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350.dtsi | 96 
 1 file changed, 96 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi 
b/arch/arm64/boot/dts/qcom/sm8350.dtsi
index faa0d0a716e6..1ea72f30ea5a 100644
--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
@@ -304,6 +304,102 @@ smem: qcom,smem {
hwlocks = <&tcsr_mutex 3>;
};
 
+   smp2p-adsp {
+   compatible = "qcom,smp2p";
+   qcom,smem = <443>, <429>;
+   interrupts-extended = <&ipcc IPCC_CLIENT_LPASS
+IPCC_MPROC_SIGNAL_SMP2P
+IRQ_TYPE_EDGE_RISING>;
+   mboxes = <&ipcc IPCC_CLIENT_LPASS
+   IPCC_MPROC_SIGNAL_SMP2P>;
+
+   qcom,local-pid = <0>;
+   qcom,remote-pid = <2>;
+
+   smp2p_adsp_out: master-kernel {
+   qcom,entry-name = "master-kernel";
+   #qcom,smem-state-cells = <1>;
+   };
+
+   smp2p_adsp_in: slave-kernel {
+   qcom,entry-name = "slave-kernel";
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   };
+   };
+
+   smp2p-cdsp {
+   compatible = "qcom,smp2p";
+   qcom,smem = <94>, <432>;
+   interrupts-extended = <&ipcc IPCC_CLIENT_CDSP
+IPCC_MPROC_SIGNAL_SMP2P
+IRQ_TYPE_EDGE_RISING>;
+   mboxes = <&ipcc IPCC_CLIENT_CDSP
+   IPCC_MPROC_SIGNAL_SMP2P>;
+
+   qcom,local-pid = <0>;
+   qcom,remote-pid = <5>;
+
+   smp2p_cdsp_out: master-kernel {
+   qcom,entry-name = "master-kernel";
+   #qcom,smem-state-cells = <1>;
+   };
+
+   smp2p_cdsp_in: slave-kernel {
+   qcom,entry-name = "slave-kernel";
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   };
+   };
+
+   smp2p-modem {
+   compatible = "qcom,smp2p";
+   qcom,smem = <435>, <428>;
+   interrupts-extended = <&ipcc IPCC_CLIENT_MPSS
+IPCC_MPROC_SIGNAL_SMP2P
+IRQ_TYPE_EDGE_RISING>;
+   mboxes = <&ipcc IPCC_CLIENT_MPSS
+   IPCC_MPROC_SIGNAL_SMP2P>;
+
+   qcom,local-pid = <0>;
+   qcom,remote-pid = <1>;
+
+   smp2p_modem_out: master-kernel {
+   qcom,entry-name = "master-kernel";
+   #qcom,smem-state-cells = <1>;
+   };
+
+   smp2p_modem_in: slave-kernel {
+   qcom,entry-name = "slave-kernel";
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   };
+   };
+
+   smp2p-slpi {
+   compatible = "qcom,smp2p";
+   qcom,smem = <481>, <430>;
+   interrupts-extended = <&ipcc IPCC_CLIENT_SLPI
+IPCC_MPROC_SIGNAL_SMP2P
+IRQ_TYPE_EDGE_RISING>;
+   mboxes = <&ipcc IPCC_CLIENT_SLPI
+   IPCC_MPROC_SIGNAL_SMP2P>;
+
+   qcom,local-pid = <0>;
+   qcom,remote-pid = <3>;
+
+   smp2p_slpi_out: master-kernel {
+   qcom,entry-name = "master-kernel";
+   #qcom,smem-state-cells = <1>;
+   };
+
+   smp2p_slpi_in: slave-kernel {
+   qcom,entry-name = "slave-kernel";
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   };
+   };
+
soc: soc@0 {
#address-cells = <2>;
#size-cells = <2>;
-- 
2.26.2



[PATCH v3 6/6] platform/surface: aggregator_registry: Add HID subsystem devices

2021-02-12 Thread Maximilian Luz
Add HID subsystem (TC=0x15) devices. These devices need to be registered
for 7th-generation Surface models. On previous generations, these
devices are either provided as platform devices via ACPI (Surface Laptop
1 and 2) or implemented as standard USB device.

Signed-off-by: Maximilian Luz 
---
 .../surface/surface_aggregator_registry.c | 49 +++
 1 file changed, 49 insertions(+)

diff --git a/drivers/platform/surface/surface_aggregator_registry.c 
b/drivers/platform/surface/surface_aggregator_registry.c
index dc044d06828b..caee90d135c5 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -77,6 +77,48 @@ static const struct software_node ssam_node_bas_dtx = {
.parent = &ssam_node_root,
 };
 
+/* HID keyboard. */
+static const struct software_node ssam_node_hid_main_keyboard = {
+   .name = "ssam:01:15:02:01:00",
+   .parent = &ssam_node_root,
+};
+
+/* HID touchpad. */
+static const struct software_node ssam_node_hid_main_touchpad = {
+   .name = "ssam:01:15:02:03:00",
+   .parent = &ssam_node_root,
+};
+
+/* HID device instance 5 (unknown HID device). */
+static const struct software_node ssam_node_hid_main_iid5 = {
+   .name = "ssam:01:15:02:05:00",
+   .parent = &ssam_node_root,
+};
+
+/* HID keyboard (base hub). */
+static const struct software_node ssam_node_hid_base_keyboard = {
+   .name = "ssam:01:15:02:01:00",
+   .parent = &ssam_node_hub_base,
+};
+
+/* HID touchpad (base hub). */
+static const struct software_node ssam_node_hid_base_touchpad = {
+   .name = "ssam:01:15:02:03:00",
+   .parent = &ssam_node_hub_base,
+};
+
+/* HID device instance 5 (unknown HID device, base hub). */
+static const struct software_node ssam_node_hid_base_iid5 = {
+   .name = "ssam:01:15:02:05:00",
+   .parent = &ssam_node_hub_base,
+};
+
+/* HID device instance 6 (unknown HID device, base hub). */
+static const struct software_node ssam_node_hid_base_iid6 = {
+   .name = "ssam:01:15:02:06:00",
+   .parent = &ssam_node_hub_base,
+};
+
 /* Devices for Surface Book 2. */
 static const struct software_node *ssam_node_group_sb2[] = {
&ssam_node_root,
@@ -93,6 +135,10 @@ static const struct software_node *ssam_node_group_sb3[] = {
&ssam_node_bat_sb3base,
&ssam_node_tmp_pprof,
&ssam_node_bas_dtx,
+   &ssam_node_hid_base_keyboard,
+   &ssam_node_hid_base_touchpad,
+   &ssam_node_hid_base_iid5,
+   &ssam_node_hid_base_iid6,
NULL,
 };
 
@@ -116,6 +162,9 @@ static const struct software_node *ssam_node_group_sl3[] = {
&ssam_node_bat_ac,
&ssam_node_bat_main,
&ssam_node_tmp_pprof,
+   &ssam_node_hid_main_keyboard,
+   &ssam_node_hid_main_touchpad,
+   &ssam_node_hid_main_iid5,
NULL,
 };
 
-- 
2.30.1



[PATCH 3/7] arm64: dts: qcom: sm8350: Add rmtfs node

2021-02-12 Thread Vinod Koul
Add the rmtfs as a reserved memory node.

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi 
b/arch/arm64/boot/dts/qcom/sm8350.dtsi
index 0bf5cec3a2aa..faa0d0a716e6 100644
--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
@@ -257,6 +257,16 @@ pil_modem_mem: memory@8b80 {
no-map;
};
 
+   rmtfs_mem: memory@9b80 {
+   compatible = "qcom,rmtfs-mem";
+   reg = <0x0 0x9b80 0x0 0x28>;
+   no-map;
+
+   qcom,client-id = <1>;
+   qcom,vmid = <15>;
+   };
+
+
hyp_reserved_mem: memory@d000 {
reg = <0x0 0xd000 0x0 0x80>;
no-map;
-- 
2.26.2



[PATCH v3 5/6] platform/surface: aggregator_registry: Add DTX device

2021-02-12 Thread Maximilian Luz
Add the detachment system (DTX) SSAM device for the Surface Book 3. This
device is accessible under the base (TC=0x11) subsystem.

Signed-off-by: Maximilian Luz 
---
 drivers/platform/surface/surface_aggregator_registry.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/platform/surface/surface_aggregator_registry.c 
b/drivers/platform/surface/surface_aggregator_registry.c
index 33904613dd4b..dc044d06828b 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -71,6 +71,12 @@ static const struct software_node ssam_node_tmp_pprof = {
.parent = &ssam_node_root,
 };
 
+/* DTX / detachment-system device (Surface Book 3). */
+static const struct software_node ssam_node_bas_dtx = {
+   .name = "ssam:01:11:01:00:00",
+   .parent = &ssam_node_root,
+};
+
 /* Devices for Surface Book 2. */
 static const struct software_node *ssam_node_group_sb2[] = {
&ssam_node_root,
@@ -86,6 +92,7 @@ static const struct software_node *ssam_node_group_sb3[] = {
&ssam_node_bat_main,
&ssam_node_bat_sb3base,
&ssam_node_tmp_pprof,
+   &ssam_node_bas_dtx,
NULL,
 };
 
-- 
2.30.1



[PATCH 2/7] arm64: dts: qcom: sm8350: Add rpmhpd node

2021-02-12 Thread Vinod Koul
This adds RPMH power domain found in SM8350 SoC

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350.dtsi | 49 
 1 file changed, 49 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi 
b/arch/arm64/boot/dts/qcom/sm8350.dtsi
index b53744618102..0bf5cec3a2aa 100644
--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
@@ -591,6 +591,55 @@ rpmhcc: clock-controller {
clocks = <&xo_board>;
};
 
+   rpmhpd: power-controller {
+   compatible = "qcom,sm8350-rpmhpd";
+   #power-domain-cells = <1>;
+   operating-points-v2 = <&rpmhpd_opp_table>;
+
+   rpmhpd_opp_table: opp-table {
+   compatible = "operating-points-v2";
+
+   rpmhpd_opp_ret: opp1 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_min_svs: opp2 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_low_svs: opp3 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_svs: opp4 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_svs_l1: opp5 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_nom: opp6 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_nom_l1: opp7 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_nom_l2: opp8 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_turbo: opp9 {
+   opp-level = 
;
+   };
+
+   rpmhpd_opp_turbo_l1: opp10 {
+   opp-level = 
;
+   };
+   };
+   };
};
 
ufs_mem_hc: ufshc@1d84000 {
-- 
2.26.2



[PATCH 1/7] arm64: dts: qcom: sm8350: fix typo

2021-02-12 Thread Vinod Koul
Fix the typo s/Limaited/Limited

Signed-off-by: Vinod Koul 
---
 arch/arm64/boot/dts/qcom/sm8350.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi 
b/arch/arm64/boot/dts/qcom/sm8350.dtsi
index 188f4011352c..b53744618102 100644
--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: BSD-3-Clause
 /*
- * Copyright (c) 2020, Linaro Limaited
+ * Copyright (c) 2020, Linaro Limited
  */
 
 #include 
-- 
2.26.2



[PATCH 0/7] arm64: dts: qcom: sm8350: additional device support

2021-02-12 Thread Vinod Koul
This series fixes a typo, adds remoteproc nodes and enables them for MTP and
uses enums for GCC

This is v5.13 material and dependent on 20210204170907.63545-1-vk...@kernel.org

Vinod Koul (7):
  arm64: dts: qcom: sm8350: fix typo
  arm64: dts: qcom: sm8350: Add rpmhpd node
  arm64: dts: qcom: sm8350: Add rmtfs node
  arm64: dts: qcom: sm8350: Add SMP2P nodes
  arm64: dts: qcom: sm8350: Add remoteprocs
  arm64: dts: qcom: sm8350-mtp: Enable remoteprocs
  arm64: dts: qcom: sm8350: Use enums for GCC

 arch/arm64/boot/dts/qcom/sm8350-mtp.dts |  20 ++
 arch/arm64/boot/dts/qcom/sm8350.dtsi| 406 +---
 2 files changed, 380 insertions(+), 46 deletions(-)

-- 
2.26.2



[PATCH v3 4/6] platform/surface: aggregator_registry: Add platform profile device

2021-02-12 Thread Maximilian Luz
Add the SSAM platform profile device to the SSAM device registry. This
device is accessible under the thermal subsystem (TC=0x03) and needs to
be registered for all Surface models.

Signed-off-by: Maximilian Luz 
---
 .../surface/surface_aggregator_registry.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/platform/surface/surface_aggregator_registry.c 
b/drivers/platform/surface/surface_aggregator_registry.c
index cde279692842..33904613dd4b 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -65,9 +65,16 @@ static const struct software_node ssam_node_bat_sb3base = {
.parent = &ssam_node_hub_base,
 };
 
+/* Platform profile / performance-mode device. */
+static const struct software_node ssam_node_tmp_pprof = {
+   .name = "ssam:01:03:01:00:01",
+   .parent = &ssam_node_root,
+};
+
 /* Devices for Surface Book 2. */
 static const struct software_node *ssam_node_group_sb2[] = {
&ssam_node_root,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
@@ -78,18 +85,21 @@ static const struct software_node *ssam_node_group_sb3[] = {
&ssam_node_bat_ac,
&ssam_node_bat_main,
&ssam_node_bat_sb3base,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
 /* Devices for Surface Laptop 1. */
 static const struct software_node *ssam_node_group_sl1[] = {
&ssam_node_root,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
 /* Devices for Surface Laptop 2. */
 static const struct software_node *ssam_node_group_sl2[] = {
&ssam_node_root,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
@@ -98,6 +108,7 @@ static const struct software_node *ssam_node_group_sl3[] = {
&ssam_node_root,
&ssam_node_bat_ac,
&ssam_node_bat_main,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
@@ -106,18 +117,21 @@ static const struct software_node *ssam_node_group_slg1[] 
= {
&ssam_node_root,
&ssam_node_bat_ac,
&ssam_node_bat_main,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
 /* Devices for Surface Pro 5. */
 static const struct software_node *ssam_node_group_sp5[] = {
&ssam_node_root,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
 /* Devices for Surface Pro 6. */
 static const struct software_node *ssam_node_group_sp6[] = {
&ssam_node_root,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
@@ -126,6 +140,7 @@ static const struct software_node *ssam_node_group_sp7[] = {
&ssam_node_root,
&ssam_node_bat_ac,
&ssam_node_bat_main,
+   &ssam_node_tmp_pprof,
NULL,
 };
 
-- 
2.30.1



[PATCH v3 3/6] platform/surface: aggregator_registry: Add battery subsystem devices

2021-02-12 Thread Maximilian Luz
Add battery subsystem (TC=0x02) devices (battery and AC) to the SSAM
device registry. These devices need to be registered for 7th-generation
Surface models. On 5th- and 6th-generation models, these devices are
handled via the standard ACPI battery/AC interface, which in turn
accesses the same SSAM interface via the Surface ACPI Notify (SAN)
driver.

Signed-off-by: Maximilian Luz 
---
 .../surface/surface_aggregator_registry.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/drivers/platform/surface/surface_aggregator_registry.c 
b/drivers/platform/surface/surface_aggregator_registry.c
index 6c23d75a044c..cde279692842 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -47,6 +47,24 @@ static const struct software_node ssam_node_hub_base = {
.parent = &ssam_node_root,
 };
 
+/* AC adapter. */
+static const struct software_node ssam_node_bat_ac = {
+   .name = "ssam:01:02:01:01:01",
+   .parent = &ssam_node_root,
+};
+
+/* Primary battery. */
+static const struct software_node ssam_node_bat_main = {
+   .name = "ssam:01:02:01:01:00",
+   .parent = &ssam_node_root,
+};
+
+/* Secondary battery (Surface Book 3). */
+static const struct software_node ssam_node_bat_sb3base = {
+   .name = "ssam:01:02:02:01:00",
+   .parent = &ssam_node_hub_base,
+};
+
 /* Devices for Surface Book 2. */
 static const struct software_node *ssam_node_group_sb2[] = {
&ssam_node_root,
@@ -57,6 +75,9 @@ static const struct software_node *ssam_node_group_sb2[] = {
 static const struct software_node *ssam_node_group_sb3[] = {
&ssam_node_root,
&ssam_node_hub_base,
+   &ssam_node_bat_ac,
+   &ssam_node_bat_main,
+   &ssam_node_bat_sb3base,
NULL,
 };
 
@@ -75,12 +96,16 @@ static const struct software_node *ssam_node_group_sl2[] = {
 /* Devices for Surface Laptop 3. */
 static const struct software_node *ssam_node_group_sl3[] = {
&ssam_node_root,
+   &ssam_node_bat_ac,
+   &ssam_node_bat_main,
NULL,
 };
 
 /* Devices for Surface Laptop Go. */
 static const struct software_node *ssam_node_group_slg1[] = {
&ssam_node_root,
+   &ssam_node_bat_ac,
+   &ssam_node_bat_main,
NULL,
 };
 
@@ -99,6 +124,8 @@ static const struct software_node *ssam_node_group_sp6[] = {
 /* Devices for Surface Pro 7. */
 static const struct software_node *ssam_node_group_sp7[] = {
&ssam_node_root,
+   &ssam_node_bat_ac,
+   &ssam_node_bat_main,
NULL,
 };
 
-- 
2.30.1



[PATCH v3 2/6] platform/surface: aggregator_registry: Add base device hub

2021-02-12 Thread Maximilian Luz
The Surface Book 3 has a detachable base part. While the top part
(so-called clipboard) contains the CPU, touchscreen, and primary
battery, the base contains, among other things, a keyboard, touchpad,
and secondary battery.

Those devices do not react well to being accessed when the base part is
detached and should thus be removed and added in sync with the base. To
facilitate this, we introduce a virtual base device hub, which
automatically removes or adds the devices registered under it.

Signed-off-by: Maximilian Luz 
---

Changes in v3:
 - Fix use of lockdep_assert_held()

---
 .../surface/surface_aggregator_registry.c | 261 +-
 1 file changed, 260 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/surface/surface_aggregator_registry.c 
b/drivers/platform/surface/surface_aggregator_registry.c
index a051d941ad96..6c23d75a044c 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -11,9 +11,12 @@
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -38,6 +41,12 @@ static const struct software_node ssam_node_root = {
.name = "ssam_platform_hub",
 };
 
+/* Base device hub (devices attached to Surface Book 3 base). */
+static const struct software_node ssam_node_hub_base = {
+   .name = "ssam:00:00:02:00:00",
+   .parent = &ssam_node_root,
+};
+
 /* Devices for Surface Book 2. */
 static const struct software_node *ssam_node_group_sb2[] = {
&ssam_node_root,
@@ -47,6 +56,7 @@ static const struct software_node *ssam_node_group_sb2[] = {
 /* Devices for Surface Book 3. */
 static const struct software_node *ssam_node_group_sb3[] = {
&ssam_node_root,
+   &ssam_node_hub_base,
NULL,
 };
 
@@ -177,6 +187,230 @@ static int ssam_hub_add_devices(struct device *parent, 
struct ssam_controller *c
 }
 
 
+/* -- SSAM base-hub driver. - 
*/
+
+enum ssam_base_hub_state {
+   SSAM_BASE_HUB_UNINITIALIZED,
+   SSAM_BASE_HUB_CONNECTED,
+   SSAM_BASE_HUB_DISCONNECTED,
+};
+
+struct ssam_base_hub {
+   struct ssam_device *sdev;
+
+   struct mutex lock;  /* Guards state update checks and transitions. */
+   enum ssam_base_hub_state state;
+
+   struct ssam_event_notifier notif;
+};
+
+static SSAM_DEFINE_SYNC_REQUEST_R(ssam_bas_query_opmode, u8, {
+   .target_category = SSAM_SSH_TC_BAS,
+   .target_id   = 0x01,
+   .command_id  = 0x0d,
+   .instance_id = 0x00,
+});
+
+#define SSAM_BAS_OPMODE_TABLET 0x00
+#define SSAM_EVENT_BAS_CID_CONNECTION  0x0c
+
+static int ssam_base_hub_query_state(struct ssam_base_hub *hub, enum 
ssam_base_hub_state *state)
+{
+   u8 opmode;
+   int status;
+
+   status = ssam_retry(ssam_bas_query_opmode, hub->sdev->ctrl, &opmode);
+   if (status < 0) {
+   dev_err(&hub->sdev->dev, "failed to query base state: %d\n", 
status);
+   return status;
+   }
+
+   if (opmode != SSAM_BAS_OPMODE_TABLET)
+   *state = SSAM_BASE_HUB_CONNECTED;
+   else
+   *state = SSAM_BASE_HUB_DISCONNECTED;
+
+   return 0;
+}
+
+static ssize_t ssam_base_hub_state_show(struct device *dev, struct 
device_attribute *attr,
+   char *buf)
+{
+   struct ssam_base_hub *hub = dev_get_drvdata(dev);
+   bool connected;
+
+   mutex_lock(&hub->lock);
+   connected = hub->state == SSAM_BASE_HUB_CONNECTED;
+   mutex_unlock(&hub->lock);
+
+   return sysfs_emit(buf, "%d\n", connected);
+}
+
+static struct device_attribute ssam_base_hub_attr_state =
+   __ATTR(state, 0444, ssam_base_hub_state_show, NULL);
+
+static struct attribute *ssam_base_hub_attrs[] = {
+   &ssam_base_hub_attr_state.attr,
+   NULL,
+};
+
+const struct attribute_group ssam_base_hub_group = {
+   .attrs = ssam_base_hub_attrs,
+};
+
+static int __ssam_base_hub_update(struct ssam_base_hub *hub, enum 
ssam_base_hub_state new)
+{
+   struct fwnode_handle *node = dev_fwnode(&hub->sdev->dev);
+   int status = 0;
+
+   lockdep_assert_held(&hub->lock);
+
+   if (hub->state == new)
+   return 0;
+   hub->state = new;
+
+   if (hub->state == SSAM_BASE_HUB_CONNECTED)
+   status = ssam_hub_add_devices(&hub->sdev->dev, hub->sdev->ctrl, 
node);
+   else
+   ssam_hub_remove_devices(&hub->sdev->dev);
+
+   if (status)
+   dev_err(&hub->sdev->dev, "failed to update base-hub devices: 
%d\n", status);
+
+   return status;
+}
+
+static int ssam_base_hub_update(struct ssam_base_hub *hub)
+{
+   enum ssam_base_hub_state state;
+   int status;
+
+   mutex_lock(&hub->lock);
+
+   status = ssam_base_hub_query_state(hub, &state);
+   if (!status)
+   status = __ssam_base_hub_update(hub, state);
+
+   mutex_unlock(&hu

[PATCH v3 0/6] platform/surface: Add Surface Aggregator device registry

2021-02-12 Thread Maximilian Luz
The Surface System Aggregator Module (SSAM) subsystem provides various
functionalities, which are separated by spreading them across multiple
devices and corresponding drivers. Parts of that functionality / some of
those devices, however, can (as far as we currently know) not be
auto-detected by conventional means. While older (specifically 5th- and
6th-)generation models do advertise most of their functionality via
standard platform devices in ACPI, newer generations do not.

As we are currently also not aware of any feasible way to query said
functionalities dynamically, this poses a problem. There is, however, a
device in ACPI that seems to be used by Windows for identifying
different Surface models: The Windows Surface Integration Device (WSID).
This device seems to have a HID corresponding to the overall set of
functionalities SSAM provides for the associated model.

This series introduces a device registry based on software nodes and
device hubs to solve this problem. The registry is intended to contain
all required non-detectable information.

The platform hub driver is loaded against the WSID device and
instantiates and manages SSAM devices based on the information provided
by the registry for the given WSID HID of the Surface model. All new
devices created by this hub added as child devices to this hub.

In addition, a base hub is introduced to manage devices associated with
the detachable base part of the Surface Book 3, as this requires special
handling (i.e. devices need to be removed when the base is removed).
Again, all devices created by the base hub (i.e. associated with the
base) are added as child devices to this hub.

In total, this will yield the following device structure

  WSID
   |- SSAM device 1 (physical device)
   |- SSAM device 2 (physical device)
   |- SSAM device 3 (physical device)
   |- ...
   \- SSAM base hub (virtual device)
  |- SSAM base device 1 (physical device)
  |- SSAM base device 2 (physical device)
  |- ...

While software nodes seem to be well suited for this approach due to
extensibility, they still need to be hard-coded, so I'm open for ideas
on how this could be improved.

Changes in v2:
 - Fix Kconfig dependency

Changes in v3:
 - Fix use of lockdep_assert_held()

Maximilian Luz (6):
  platform/surface: Set up Surface Aggregator device registry
  platform/surface: aggregator_registry: Add base device hub
  platform/surface: aggregator_registry: Add battery subsystem devices
  platform/surface: aggregator_registry: Add platform profile device
  platform/surface: aggregator_registry: Add DTX device
  platform/surface: aggregator_registry: Add HID subsystem devices

 MAINTAINERS   |   1 +
 drivers/platform/surface/Kconfig  |  27 +
 drivers/platform/surface/Makefile |   1 +
 .../surface/surface_aggregator_registry.c | 641 ++
 4 files changed, 670 insertions(+)
 create mode 100644 drivers/platform/surface/surface_aggregator_registry.c

-- 
2.30.1



[PATCH v3 1/6] platform/surface: Set up Surface Aggregator device registry

2021-02-12 Thread Maximilian Luz
The Surface System Aggregator Module (SSAM) subsystem provides various
functionalities, which are separated by spreading them across multiple
devices and corresponding drivers. Parts of that functionality / some of
those devices, however, can (as far as we currently know) not be
auto-detected by conventional means. While older (specifically 5th- and
6th-)generation models do advertise most of their functionality via
standard platform devices in ACPI, newer generations do not.

As we are currently also not aware of any feasible way to query said
functionalities dynamically, this poses a problem. There is, however, a
device in ACPI that seems to be used by Windows for identifying
different Surface models: The Windows Surface Integration Device (WSID).
This device seems to have a HID corresponding to the overall set of
functionalities SSAM provides for the associated model.

This commit introduces a registry providing non-detectable device
information via software nodes. In addition, a SSAM platform hub driver
is introduced, which takes care of creating and managing the SSAM
devices specified in this registry. This approach allows for a
hierarchical setup akin to ACPI and is easily extendable, e.g. via
firmware node properties.

Note that this commit only provides the basis for the platform hub and
registry, and does not add any content to it. The registry will be
expanded in subsequent commits.

Signed-off-by: Maximilian Luz 
---

Changes in v2:
 - Fix Kconfig dependency

---
 MAINTAINERS   |   1 +
 drivers/platform/surface/Kconfig  |  27 ++
 drivers/platform/surface/Makefile |   1 +
 .../surface/surface_aggregator_registry.c | 284 ++
 4 files changed, 313 insertions(+)
 create mode 100644 drivers/platform/surface/surface_aggregator_registry.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4fcf3df517a8..000a82f59c76 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11826,6 +11826,7 @@ F:  Documentation/driver-api/surface_aggregator/
 F: drivers/platform/surface/aggregator/
 F: drivers/platform/surface/surface_acpi_notify.c
 F: drivers/platform/surface/surface_aggregator_cdev.c
+F: drivers/platform/surface/surface_aggregator_registry.c
 F: include/linux/surface_acpi_notify.h
 F: include/linux/surface_aggregator/
 F: include/uapi/linux/surface_aggregator/
diff --git a/drivers/platform/surface/Kconfig b/drivers/platform/surface/Kconfig
index 0847b2dc97bf..179b8c93d7fd 100644
--- a/drivers/platform/surface/Kconfig
+++ b/drivers/platform/surface/Kconfig
@@ -77,6 +77,33 @@ config SURFACE_AGGREGATOR_CDEV
  The provided interface is intended for debugging and development only,
  and should not be used otherwise.
 
+config SURFACE_AGGREGATOR_REGISTRY
+   tristate "Surface System Aggregator Module Device Registry"
+   depends on SURFACE_AGGREGATOR
+   depends on SURFACE_AGGREGATOR_BUS
+   help
+ Device-registry and device-hubs for Surface System Aggregator Module
+ (SSAM) devices.
+
+ Provides a module and driver which act as a device-registry for SSAM
+ client devices that cannot be detected automatically, e.g. via ACPI.
+ Such devices are instead provided via this registry and attached via
+ device hubs, also provided in this module.
+
+ Devices provided via this registry are:
+ - Platform profile (performance-/cooling-mode) device (5th- and later
+   generations).
+ - Battery/AC devices (7th-generation).
+ - HID input devices (7th-generation).
+
+ Select M (recommended) or Y here if you want support for the above
+ mentioned devices on the corresponding Surface models. Without this
+ module, the respective devices will not be instantiated and thus any
+ functionality provided by them will be missing, even when drivers for
+ these devices are present. In other words, this module only provides
+ the respective client devices. Drivers for these devices still need to
+ be selected via the other options.
+
 config SURFACE_GPE
tristate "Surface GPE/Lid Support Driver"
depends on DMI
diff --git a/drivers/platform/surface/Makefile 
b/drivers/platform/surface/Makefile
index 990424c5f0c9..80035ee540bf 100644
--- a/drivers/platform/surface/Makefile
+++ b/drivers/platform/surface/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_SURFACE_3_POWER_OPREGION)+= 
surface3_power.o
 obj-$(CONFIG_SURFACE_ACPI_NOTIFY)  += surface_acpi_notify.o
 obj-$(CONFIG_SURFACE_AGGREGATOR)   += aggregator/
 obj-$(CONFIG_SURFACE_AGGREGATOR_CDEV)  += surface_aggregator_cdev.o
+obj-$(CONFIG_SURFACE_AGGREGATOR_REGISTRY) += surface_aggregator_registry.o
 obj-$(CONFIG_SURFACE_GPE)  += surface_gpe.o
 obj-$(CONFIG_SURFACE_HOTPLUG)  += surface_hotplug.o
 obj-$(CONFIG_SURFACE_PRO3_BUTTON)  += surfacepro3_button.o
diff --git a/drivers/platf

Re: [Linuxarm] Re: [PATCH for next v1 1/2] gpio: omap: Replace raw_spin_lock_irqsave with raw_spin_lock in omap_gpio_irq_handler()

2021-02-12 Thread Grygorii Strashko




On 12/02/2021 13:29, Song Bao Hua (Barry Song) wrote:




-Original Message-
From: Andy Shevchenko [mailto:andy.shevche...@gmail.com]
Sent: Friday, February 12, 2021 11:57 PM
To: Song Bao Hua (Barry Song) 
Cc: Grygorii Strashko ; Arnd Bergmann
; luojiaxing ; Linus Walleij
; Santosh Shilimkar ; Kevin
Hilman ; open list:GPIO SUBSYSTEM
; linux-kernel@vger.kernel.org;
linux...@openeuler.org
Subject: Re: [Linuxarm] Re: [PATCH for next v1 1/2] gpio: omap: Replace
raw_spin_lock_irqsave with raw_spin_lock in omap_gpio_irq_handler()

On Fri, Feb 12, 2021 at 10:42:19AM +, Song Bao Hua (Barry Song) wrote:

From: Grygorii Strashko [mailto:grygorii.stras...@ti.com]
Sent: Friday, February 12, 2021 11:28 PM
On 12/02/2021 11:45, Arnd Bergmann wrote:

On Fri, Feb 12, 2021 at 6:05 AM Song Bao Hua (Barry Song)
 wrote:



Note. there is also generic_handle_irq() call inside.


So generic_handle_irq() is not safe to run in thread thus requires
an interrupt-disabled environment to run? If so, I'd rather this
irqsave moved into generic_handle_irq() rather than asking everyone
calling it to do irqsave.


In a preempt-rt kernel, interrupts are run in task context, so they clearly
should not be called with interrupts disabled, that would defeat the
purpose of making them preemptible.

generic_handle_irq() does need to run with in_irq()==true though,
but this should be set by the caller of the gpiochip's handler, and
it is not set by raw_spin_lock_irqsave().


It will produce warning from __handle_irq_event_percpu(), as this is IRQ
dispatcher
and generic_handle_irq() will call one of handle_level_irq or

handle_edge_irq.


The history behind this is commit 450fa54cfd66 ("gpio: omap: convert to

use

generic irq handler").

The resent related discussion:
https://lkml.org/lkml/2020/12/5/208


Ok, second thought. irqsave before generic_handle_irq() won't defeat
the purpose of preemption too much as the dispatched irq handlers by
gpiochip will run in their own threads but not in the thread of
gpiochip's handler.

so looks like this patch can improve by:
* move other raw_spin_lock_irqsave to raw_spin_lock;
* keep the raw_spin_lock_irqsave before generic_handle_irq() to mute
the warning in genirq.


Isn't the idea of irqsave is to prevent dead lock from the process context when
we get interrupt on the *same* CPU?


Anyway, gpiochip is more tricky as it is also a irq dispatcher. Moving
spin_lock_irq to spin_lock in the irq handler of non-irq dispatcher
driver is almost always correct.

But for gpiochip, would the below be true though it is almost alway true
for non-irq dispatcher?

1. While gpiochip's handler runs in hardIRQ, interrupts are disabled, so no more
interrupt on the same cpu -> No deadleak.

2. While gpiochip's handler runs in threads
* other non-threaded interrupts such as timer tick might come on same cpu,
but they are an irrelevant driver and thus they are not going to get the
lock gpiochip's handler has held. -> no deadlock.
* other devices attached to this gpiochip might get interrupts, since
gpiochip's handler is running in threads, raw_spin_lock can help avoid
messing up the critical data by two threads -> still no deadlock.


The worst RT case I can imagine is when gpio API is still called from hard IRQ 
context by some
other device driver - some toggling for example.
Note. RT or "threadirqs" does not mean gpiochip become sleepable.

In this case:
 threaded handler
   raw_spin_lock
IRQ from other device
  hard_irq handler
gpiod_x()
raw_spin_lock_irqsave() -- oops

But in general, what are the benefit of such changes at all, except better 
marking call context annotation,
so we are spending so much time on it?


--
Best regards,
grygorii


[v3] drm/msm/disp/dpu1: turn off vblank irqs aggressively in dpu

2021-02-12 Thread Kalyan Thota
From: Kalyan Thota 

Set the flag vblank_disable_immediate = true to turn off vblank irqs
immediately as soon as drm_vblank_put is requested so that there are
no irqs triggered during idle state. This will reduce cpu wakeups
and help in power saving.

To enable vblank_disable_immediate flag the underlying KMS driver
needs to support high precision vblank timestamping and also a
reliable way of providing vblank counter which is incrementing
at the leading edge of vblank.

This patch also brings in changes to support vblank_disable_immediate
requirement in dpu driver.

Changes in v1:
 - Specify reason to add vblank timestamp support. (Rob Clark)
 - Add changes to provide vblank counter from dpu driver.

Changes in v2:
 - Fix warn stack reported by Rob Clark with v2 patch

Signed-off-by: Kalyan Thota 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c| 80 +
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 28 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h | 11 
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c |  5 ++
 4 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
index d4662e8..9a80981 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c
@@ -65,6 +65,83 @@ static void dpu_crtc_destroy(struct drm_crtc *crtc)
kfree(dpu_crtc);
 }
 
+static struct drm_encoder *get_encoder_from_crtc(struct drm_crtc *crtc)
+{
+   struct drm_device *dev = crtc->dev;
+   struct drm_encoder *encoder;
+
+   drm_for_each_encoder(encoder, dev)
+   if (encoder->crtc == crtc)
+   return encoder;
+
+   return NULL;
+}
+
+static u32 dpu_crtc_get_vblank_counter(struct drm_crtc *crtc)
+{
+   struct drm_encoder *encoder;
+
+   encoder = get_encoder_from_crtc(crtc);
+   if (!encoder) {
+   DRM_ERROR("no encoder found for crtc %d\n", crtc->index);
+   return false;
+   }
+
+   return dpu_encoder_get_frame_count(encoder);
+}
+
+static bool dpu_crtc_get_scanout_position(struct drm_crtc *crtc,
+  bool in_vblank_irq,
+  int *vpos, int *hpos,
+  ktime_t *stime, ktime_t *etime,
+  const struct drm_display_mode *mode)
+{
+   unsigned int pipe = crtc->index;
+   struct drm_encoder *encoder;
+   int line, vsw, vbp, vactive_start, vactive_end, vfp_end;
+
+   encoder = get_encoder_from_crtc(crtc);
+   if (!encoder) {
+   DRM_ERROR("no encoder found for crtc %d\n", pipe);
+   return false;
+   }
+
+   vsw = mode->crtc_vsync_end - mode->crtc_vsync_start;
+   vbp = mode->crtc_vtotal - mode->crtc_vsync_end;
+
+   /*
+* the line counter is 1 at the start of the VSYNC pulse and VTOTAL at
+* the end of VFP. Translate the porch values relative to the line
+* counter positions.
+*/
+
+   vactive_start = vsw + vbp + 1;
+   vactive_end = vactive_start + mode->crtc_vdisplay;
+
+   /* last scan line before VSYNC */
+   vfp_end = mode->crtc_vtotal;
+
+   if (stime)
+   *stime = ktime_get();
+
+   line = dpu_encoder_get_linecount(encoder);
+
+   if (line < vactive_start)
+   line -= vactive_start;
+   else if (line > vactive_end)
+   line = line - vfp_end - vactive_start;
+   else
+   line -= vactive_start;
+
+   *vpos = line;
+   *hpos = 0;
+
+   if (etime)
+   *etime = ktime_get();
+
+   return true;
+}
+
 static void _dpu_crtc_setup_blend_cfg(struct dpu_crtc_mixer *mixer,
struct dpu_plane_state *pstate, struct dpu_format *format)
 {
@@ -1243,6 +1320,8 @@ static const struct drm_crtc_funcs dpu_crtc_funcs = {
.early_unregister = dpu_crtc_early_unregister,
.enable_vblank  = msm_crtc_enable_vblank,
.disable_vblank = msm_crtc_disable_vblank,
+   .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
+   .get_vblank_counter = dpu_crtc_get_vblank_counter,
 };
 
 static const struct drm_crtc_helper_funcs dpu_crtc_helper_funcs = {
@@ -1251,6 +1330,7 @@ static const struct drm_crtc_helper_funcs 
dpu_crtc_helper_funcs = {
.atomic_check = dpu_crtc_atomic_check,
.atomic_begin = dpu_crtc_atomic_begin,
.atomic_flush = dpu_crtc_atomic_flush,
+   .get_scanout_position = dpu_crtc_get_scanout_position,
 };
 
 /* initialize crtc */
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
index f7f5c25..fb6546c 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
@@ -425,6 +425,32 @@ int dpu_encoder_helper_unregister_irq(struct 
dpu_encoder_phys *phys_enc,
re

[PATCH] [v13] wireless: Initial driver submission for pureLiFi STA devices

2021-02-12 Thread Srinivasan Raju
This introduces the pureLiFi LiFi driver for LiFi-X, LiFi-XC
and LiFi-XL USB devices.

This driver implementation has been based on the zd1211rw driver.

Driver is based on 802.11 softMAC Architecture and uses
native 802.11 for configuration and management.

The driver is compiled and tested in ARM, x86 architectures and
compiled in powerpc architecture.

Signed-off-by: Srinivasan Raju 

---
v13
- Removed unused #defines
v12:
- Removed sysfs, procfs related code
- Addressed race condition bug
- Used macros instead of magic numbers in firmware.c
- Added copyright in all files
v11, v10:
- Addressed review comment on readability
- Changed firmware names to match products
v9:
- Addressed review comments on style and content defects
- Used kmemdup instead of alloc and memcpy
v7 , v8:
- Magic numbers removed and used IEEE80211 macors
- Other code style and timer function fixes (mod_timer)
v6:
- Code style fix patch from Joe Perches
v5:
- Code refactoring for clarity and redundnacy removal
- Fix warnings from kernel test robot
v4:
- Code refactoring based on kernel code guidelines
- Remove multi level macors and use kernel debug macros
v3:
- Code style fixes kconfig fix
v2:
- Driver submitted to wireless-next
- Code style fixes and copyright statement fix
v1:
- Driver submitted to staging
---
 MAINTAINERS   |5 +
 drivers/net/wireless/Kconfig  |1 +
 drivers/net/wireless/Makefile |1 +
 drivers/net/wireless/purelifi/Kconfig |   17 +
 drivers/net/wireless/purelifi/Makefile|2 +
 drivers/net/wireless/purelifi/plfxlc/Kconfig  |   13 +
 drivers/net/wireless/purelifi/plfxlc/Makefile |3 +
 drivers/net/wireless/purelifi/plfxlc/chip.c   |   96 ++
 drivers/net/wireless/purelifi/plfxlc/chip.h   |   84 ++
 .../net/wireless/purelifi/plfxlc/firmware.c   |  290 +
 drivers/net/wireless/purelifi/plfxlc/intf.h   |   41 +
 drivers/net/wireless/purelifi/plfxlc/mac.c|  876 ++
 drivers/net/wireless/purelifi/plfxlc/mac.h|  192 
 drivers/net/wireless/purelifi/plfxlc/usb.c| 1009 +
 drivers/net/wireless/purelifi/plfxlc/usb.h|  177 +++
 15 files changed, 2807 insertions(+)
 create mode 100644 drivers/net/wireless/purelifi/Kconfig
 create mode 100644 drivers/net/wireless/purelifi/Makefile
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/Kconfig
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/Makefile
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/chip.c
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/chip.h
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/firmware.c
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/intf.h
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/mac.c
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/mac.h
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/usb.c
 create mode 100644 drivers/net/wireless/purelifi/plfxlc/usb.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 5c1a6ba5ef26..3178ded0a91e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14199,6 +14199,11 @@ T: git git://linuxtv.org/media_tree.git
 F: Documentation/admin-guide/media/pulse8-cec.rst
 F: drivers/media/cec/usb/pulse8/
 
+PUREILIFI USB DRIVER
+M: Srinivasan Raju 
+S: Supported
+F: drivers/net/wireless/purelifi
+
 PVRUSB2 VIDEO4LINUX DRIVER
 M: Mike Isely 
 L: pvru...@isely.net   (subscribers-only)
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 7add2002ff4c..3a1f5ef3aa43 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -35,6 +35,7 @@ source "drivers/net/wireless/st/Kconfig"
 source "drivers/net/wireless/ti/Kconfig"
 source "drivers/net/wireless/zydas/Kconfig"
 source "drivers/net/wireless/quantenna/Kconfig"
+source "drivers/net/wireless/purelifi/Kconfig"
 
 config PCMCIA_RAYCS
tristate "Aviator/Raytheon 2.4GHz wireless support"
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 80b324499786..e9fc770026f0 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_WLAN_VENDOR_ST) += st/
 obj-$(CONFIG_WLAN_VENDOR_TI) += ti/
 obj-$(CONFIG_WLAN_VENDOR_ZYDAS) += zydas/
 obj-$(CONFIG_WLAN_VENDOR_QUANTENNA) += quantenna/
+obj-$(CONFIG_WLAN_VENDOR_PURELIFI) += purelifi/
 
 # 16-bit wireless PCMCIA client drivers
 obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
diff --git a/drivers/net/wireless/purelifi/Kconfig 
b/drivers/net/wireless/purelifi/Kconfig
new file mode 100644
index ..e39afec3dcae
--- /dev/null
+++ b/drivers/net/wireless/purelifi/Kconfig
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config WLAN_VENDOR_PURELIFI
+   bool "pureLiFi devices"
+   default y
+   help
+ If you have a pureLiFi device, say Y.
+
+ Note that the answer to this question doesn't directly affect the
+ kernel: saying N will j

Re: [PATCH 3/3] lib/vsprintf: make-printk-non-secret printks all addresses as unhashed

2021-02-12 Thread Petr Mladek
Hi,

I have realized that I did not comment the two ideas.

On Wed 2021-02-10 11:27:45, Timur Tabi wrote:
> 
> 
> On 2/10/21 7:41 AM, Petr Mladek wrote:
> > 
> > The option causes that vsprintf() will not hash pointers. Yes, it is
> > primary used by printk(). But it is used also in some other
> > interfaces, especially trace_printk(), seq_buf() API. The naked
> > pointers might appear more or less anywhere, including procfs,
> > sysfs, debugfs.
>
> Fair point.  Shouldn't calls to seq_buf_printf() (and any printk usage that
> always exists in the context of a user-space process) use %pK anyway?

seq_buf is a handy API that might be used for different purpose.
For example, it seems to be used ftrace where people might want
to see real pointers when debugging.

> Hmmm maybe vsprintf() should automatically replace %p with %pK if it
> detects a user-space context?

I am not sure if there is an easy and reliable way how to detect the
user-space context. On some architectures, it might be possible to
guess it by the address of the buffer. But it will not work when
the message is temporary printed into a local buffer and copied
later.

Let's keep it simple. Heuristics often become very complex over time.

Best Regards,
Petr


<    4   5   6   7   8   9   10   11   >