[PATCH] Input: elan_i2c - Extend Flash-Write delay for Elan touch pad

2017-09-21 Thread KT Liao
Original 20ms delay is a margin timing after a block writing
in FW update flow.

Sometimes it will cause fail during FW-updating if I2C timing delay.
We offten see this issue in rockchip's I2C host.

Extend the delay timing is the safest way to improve it.

Signed-off-by: KT Liao 
---
 drivers/input/mouse/elan_i2c_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 80172f2..4db376c 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -587,7 +587,7 @@ static int elan_i2c_write_fw_block(struct i2c_client 
*client,
}
 
/* Wait for F/W to update one page ROM data. */
-   msleep(20);
+   msleep(35);
 
error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val);
if (error) {
-- 
2.7.4



[PATCH] Input: elan_i2c - Extend Flash-Write delay for Elan touch pad

2017-09-21 Thread KT Liao
Original 20ms delay is a margin timing after a block writing
in FW update flow.

Sometimes it will cause fail during FW-updating if I2C timing delay.
We offten see this issue in rockchip's I2C host.

Extend the delay timing is the safest way to improve it.

Signed-off-by: KT Liao 
---
 drivers/input/mouse/elan_i2c_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 80172f2..4db376c 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -587,7 +587,7 @@ static int elan_i2c_write_fw_block(struct i2c_client 
*client,
}
 
/* Wait for F/W to update one page ROM data. */
-   msleep(20);
+   msleep(35);
 
error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val);
if (error) {
-- 
2.7.4



Re: [PATCH] pinctrl: intel: Mask interrupts on driver probe

2017-09-21 Thread Mika Westerberg
On Thu, Sep 21, 2017 at 02:20:03PM -0500, Kyle Roeschley wrote:
> Powering off the system on Apollo Lake does not clear the interrupt
> enable registers for the GPIOs. To avoid an interrupt storm on driver
> probe, clear all interrupt enables before enabling our interrupt line.

It is up to the BIOS to set the proper mask and program the pads
accordingly. Which platform and BIOS this is?

I would rather not do this because it might cause other problems.


Re: [PATCH] pinctrl: intel: Mask interrupts on driver probe

2017-09-21 Thread Mika Westerberg
On Thu, Sep 21, 2017 at 02:20:03PM -0500, Kyle Roeschley wrote:
> Powering off the system on Apollo Lake does not clear the interrupt
> enable registers for the GPIOs. To avoid an interrupt storm on driver
> probe, clear all interrupt enables before enabling our interrupt line.

It is up to the BIOS to set the proper mask and program the pads
accordingly. Which platform and BIOS this is?

I would rather not do this because it might cause other problems.


Re: [PATCH v4] ARM: dts: Add initial Pistachio i.mx6q board support.

2017-09-21 Thread Shawn Guo
On Sat, Sep 09, 2017 at 08:54:21PM +0800, Wig C wrote:
> From: YuanCheng Cheng 
> 
> Working items:
> 
> - 800MHz CPU
> - 2GB of RAM (DDR3)
> - 4GB of eMMC storage
> - 1T1R WiFi 2.4 GHz
> - Power management support
> - 1x 10/100/1000 Mbps Ethernet WAN port
> - 2x USB 2.0 Host
> - PCIe
> - HDMI/VGA/LVDS display
> - 1x UART for RS232/422/485
> - 2x UART for RS232
> - 1x UART for serial console
> - 1x CAN bus
> 
> Specification: http://nutsboard.org/pistachio
> 
> Signed-off-by: YuanCheng Cheng 

Applied, thanks.


Re: [PATCH v4] ARM: dts: Add initial Pistachio i.mx6q board support.

2017-09-21 Thread Shawn Guo
On Sat, Sep 09, 2017 at 08:54:21PM +0800, Wig C wrote:
> From: YuanCheng Cheng 
> 
> Working items:
> 
> - 800MHz CPU
> - 2GB of RAM (DDR3)
> - 4GB of eMMC storage
> - 1T1R WiFi 2.4 GHz
> - Power management support
> - 1x 10/100/1000 Mbps Ethernet WAN port
> - 2x USB 2.0 Host
> - PCIe
> - HDMI/VGA/LVDS display
> - 1x UART for RS232/422/485
> - 2x UART for RS232
> - 1x UART for serial console
> - 1x CAN bus
> 
> Specification: http://nutsboard.org/pistachio
> 
> Signed-off-by: YuanCheng Cheng 

Applied, thanks.


Re: [PATCH] arm64: dts: ls: Add optee node

2017-09-21 Thread Shawn Guo
On Sat, Sep 09, 2017 at 05:03:28AM +0530, Sumit Garg wrote:
> Add optee device tree node on ls1012a, ls1043a, ls1046a, ls1088a
> and ls208xa.
> 
> Signed-off-by: Sumit Garg 

Applied, thanks.


Re: [PATCH] arm64: dts: ls: Add optee node

2017-09-21 Thread Shawn Guo
On Sat, Sep 09, 2017 at 05:03:28AM +0530, Sumit Garg wrote:
> Add optee device tree node on ls1012a, ls1043a, ls1046a, ls1088a
> and ls208xa.
> 
> Signed-off-by: Sumit Garg 

Applied, thanks.


Re: [RFC][PATCH v2 0/7] printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers

2017-09-21 Thread Santosh Sivaraj
* Sergey Senozhatsky  wrote (on 2017-09-20 
16:29:02 +):

> Hello
> 
> RFC
> 
> On some arches C function pointers are indirect and point to
> a function descriptor, which contains the actual pointer to the code.
> This mostly doesn't matter, except for cases when people want to print
> out function pointers in symbolic format, because the usual '%pS/%ps'
> does not work on those arches as expected. That's the reason why we
> have '%pF/%pf', but since it's here because of a subtle ABI detail
> specific to some arches (ppc64/ia64/parisc64) it's easy to misuse
> '%pF/%pf' and '%pS/%ps' (see [1], for example).
> 
> This patch set attempts to move ia64/ppc64/parisc64 C function
> pointer ABI details out of printk() to arch code. Function dereference
> code now checks if a pointer belongs to a .opd ELF section and dereferences
> that pointer only if it does. The kernel and modules have their own .opd
> sections that's why I use two different ARCH functions: for kernel and
> for module pointer dereference.
> 
> I planned to remove dereference_function_descriptor() entirely,
> but then I discovered a bunch other uses cases (kgdbts, init/main.c,
> extable, etc.), so I decided to keep dereference_function_descriptor()
> around because the main point of this patch set is to deprecate %pF/%pf.
> But at the same time, I think I can go further and handle both kernel
> and module descriptor dereference in dereference_function_descriptor().
> We need a module pointer for module .opd check, so that will come at an
> extra cost of module lookup (may be there will some other issues along
> the way, haven't checked it).
> 
> Right now we've got:
> 
> - dereference_function_descriptor(addr)
> a generic (old) function. it simply attempts to dereference
> whatever pointer we give it.
> 
> - dereference_kernel_function_descriptor(addr)
> dereferences a kernel pointer if it's within the kernel's .opd
> section.
> 
> - dereference_module_function_descriptor(module, addr)
> dereference a module pointer if it's within the module's .opd
> section.
> 
> 
> *** A BIG NOTE ***
> I don't own ia64/ppc64/parisc64 hardware, so the patches are not
> tested. Sorry about that!

Tested patch series on ppc64 sucessfully.

You may add tested by to the series.

Tested-by: Santosh Sivaraj 

Thanks,
Santosh

> 
> Another note:
> I need to check what is BPF symbol lookup and do we need to
> do any dereference there.
> 
> v2:
> -- convert dereference_function_descriptor() to unsigned long
> -- fix kernel descriptor range checks (Helge)
> -- fix parisc module descriptor range check (Helge)
> -- fix ppc64 module range check
> -- add checkpatch patch
> 
> 
> Sergey Senozhatsky (7):
>   switch dereference_function_descriptor() to `unsigned long'
>   sections: split dereference_function_descriptor()
>   ia64: Add .opd based function descriptor dereference
>   powerpc64: Add .opd based function descriptor dereference
>   parisc64: Add .opd based function descriptor dereference
>   symbol lookup: use new kernel and module dereference functions
>   checkpatch: add pF/pf deprecation warning
> 
>  Documentation/printk-formats.txt  | 15 +--
>  arch/ia64/include/asm/sections.h  | 16 
>  arch/ia64/kernel/module.c | 13 +
>  arch/ia64/kernel/vmlinux.lds.S|  2 ++
>  arch/parisc/boot/compressed/vmlinux.lds.S |  2 ++
>  arch/parisc/include/asm/sections.h|  4 +++-
>  arch/parisc/kernel/module.c   | 17 +
>  arch/parisc/kernel/process.c  | 15 ---
>  arch/parisc/kernel/vmlinux.lds.S  |  2 ++
>  arch/parisc/mm/init.c |  4 ++--
>  arch/powerpc/include/asm/module.h |  3 +++
>  arch/powerpc/include/asm/sections.h   | 17 ++---
>  arch/powerpc/kernel/module_64.c   | 16 
>  arch/powerpc/kernel/vmlinux.lds.S |  2 ++
>  drivers/misc/kgdbts.c |  2 +-
>  include/asm-generic/sections.h|  8 ++--
>  include/linux/moduleloader.h  |  4 
>  init/main.c   |  2 +-
>  kernel/extable.c  |  2 +-
>  kernel/kallsyms.c |  1 +
>  kernel/module.c   |  9 -
>  lib/vsprintf.c|  5 +
>  scripts/checkpatch.pl |  6 --
>  23 files changed, 132 insertions(+), 35 deletions(-)

-- 


signature.asc
Description: PGP signature


Re: [RFC][PATCH v2 0/7] printk/ia64/ppc64/parisc64: let's deprecate %pF/%pf printk specifiers

2017-09-21 Thread Santosh Sivaraj
* Sergey Senozhatsky  wrote (on 2017-09-20 
16:29:02 +):

> Hello
> 
> RFC
> 
> On some arches C function pointers are indirect and point to
> a function descriptor, which contains the actual pointer to the code.
> This mostly doesn't matter, except for cases when people want to print
> out function pointers in symbolic format, because the usual '%pS/%ps'
> does not work on those arches as expected. That's the reason why we
> have '%pF/%pf', but since it's here because of a subtle ABI detail
> specific to some arches (ppc64/ia64/parisc64) it's easy to misuse
> '%pF/%pf' and '%pS/%ps' (see [1], for example).
> 
> This patch set attempts to move ia64/ppc64/parisc64 C function
> pointer ABI details out of printk() to arch code. Function dereference
> code now checks if a pointer belongs to a .opd ELF section and dereferences
> that pointer only if it does. The kernel and modules have their own .opd
> sections that's why I use two different ARCH functions: for kernel and
> for module pointer dereference.
> 
> I planned to remove dereference_function_descriptor() entirely,
> but then I discovered a bunch other uses cases (kgdbts, init/main.c,
> extable, etc.), so I decided to keep dereference_function_descriptor()
> around because the main point of this patch set is to deprecate %pF/%pf.
> But at the same time, I think I can go further and handle both kernel
> and module descriptor dereference in dereference_function_descriptor().
> We need a module pointer for module .opd check, so that will come at an
> extra cost of module lookup (may be there will some other issues along
> the way, haven't checked it).
> 
> Right now we've got:
> 
> - dereference_function_descriptor(addr)
> a generic (old) function. it simply attempts to dereference
> whatever pointer we give it.
> 
> - dereference_kernel_function_descriptor(addr)
> dereferences a kernel pointer if it's within the kernel's .opd
> section.
> 
> - dereference_module_function_descriptor(module, addr)
> dereference a module pointer if it's within the module's .opd
> section.
> 
> 
> *** A BIG NOTE ***
> I don't own ia64/ppc64/parisc64 hardware, so the patches are not
> tested. Sorry about that!

Tested patch series on ppc64 sucessfully.

You may add tested by to the series.

Tested-by: Santosh Sivaraj 

Thanks,
Santosh

> 
> Another note:
> I need to check what is BPF symbol lookup and do we need to
> do any dereference there.
> 
> v2:
> -- convert dereference_function_descriptor() to unsigned long
> -- fix kernel descriptor range checks (Helge)
> -- fix parisc module descriptor range check (Helge)
> -- fix ppc64 module range check
> -- add checkpatch patch
> 
> 
> Sergey Senozhatsky (7):
>   switch dereference_function_descriptor() to `unsigned long'
>   sections: split dereference_function_descriptor()
>   ia64: Add .opd based function descriptor dereference
>   powerpc64: Add .opd based function descriptor dereference
>   parisc64: Add .opd based function descriptor dereference
>   symbol lookup: use new kernel and module dereference functions
>   checkpatch: add pF/pf deprecation warning
> 
>  Documentation/printk-formats.txt  | 15 +--
>  arch/ia64/include/asm/sections.h  | 16 
>  arch/ia64/kernel/module.c | 13 +
>  arch/ia64/kernel/vmlinux.lds.S|  2 ++
>  arch/parisc/boot/compressed/vmlinux.lds.S |  2 ++
>  arch/parisc/include/asm/sections.h|  4 +++-
>  arch/parisc/kernel/module.c   | 17 +
>  arch/parisc/kernel/process.c  | 15 ---
>  arch/parisc/kernel/vmlinux.lds.S  |  2 ++
>  arch/parisc/mm/init.c |  4 ++--
>  arch/powerpc/include/asm/module.h |  3 +++
>  arch/powerpc/include/asm/sections.h   | 17 ++---
>  arch/powerpc/kernel/module_64.c   | 16 
>  arch/powerpc/kernel/vmlinux.lds.S |  2 ++
>  drivers/misc/kgdbts.c |  2 +-
>  include/asm-generic/sections.h|  8 ++--
>  include/linux/moduleloader.h  |  4 
>  init/main.c   |  2 +-
>  kernel/extable.c  |  2 +-
>  kernel/kallsyms.c |  1 +
>  kernel/module.c   |  9 -
>  lib/vsprintf.c|  5 +
>  scripts/checkpatch.pl |  6 --
>  23 files changed, 132 insertions(+), 35 deletions(-)

-- 


signature.asc
Description: PGP signature


Re: [PATCH v3 0/3] x86/fpu: prevent leaking FPU registers via invalid FPU state

2017-09-21 Thread Ingo Molnar

* Eric Biggers  wrote:

> From: Eric Biggers 
> 
> This series fixes the bug found by syzkaller where the ptrace syscall
> can be used to set invalid bits in a task's FPU state.  I also found
> that an equivalent bug was reachable using the sigreturn syscall, so the
> first patch fixes the bug in both cases.
> 
> The other two patches start validating the other parts of the
> xstate_header and make it so that invalid FPU states can no longer be
> abused to leak the FPU registers of other processes.
> 
> Changes since v2:
> - Use an exception handler to handle invalid FPU states
>   (suggested by Andy Lutomirski)
> - Check the size of xstate_header.reserved at build time
>   (suggested by Dave Hansen)
> 
> Eric Biggers (3):
>   x86/fpu: don't let userspace set bogus xcomp_bv
>   x86/fpu: tighten validation of user-supplied xstate_header
>   x86/fpu: reinitialize FPU registers if restoring FPU state fails
> 
>  arch/x86/include/asm/fpu/internal.h | 51 
> +++--
>  arch/x86/include/asm/fpu/xstate.h   | 25 ++
>  arch/x86/kernel/fpu/regset.c| 20 +++
>  arch/x86/kernel/fpu/signal.c| 15 ---
>  arch/x86/kernel/fpu/xstate.c| 27 
>  arch/x86/mm/extable.c   | 24 +
>  6 files changed, 94 insertions(+), 68 deletions(-)

Ok - could you please rebase these to to tip:master that is at:

git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master

In particular this has a WIP.x86/fpu branch with FPU fixes+changes queued up 
but 
not merged upstream (yet), which conflict with these changes. I'd like to merge 
them all together.

Thanks,

Ingo


Re: [PATCH v3 0/3] x86/fpu: prevent leaking FPU registers via invalid FPU state

2017-09-21 Thread Ingo Molnar

* Eric Biggers  wrote:

> From: Eric Biggers 
> 
> This series fixes the bug found by syzkaller where the ptrace syscall
> can be used to set invalid bits in a task's FPU state.  I also found
> that an equivalent bug was reachable using the sigreturn syscall, so the
> first patch fixes the bug in both cases.
> 
> The other two patches start validating the other parts of the
> xstate_header and make it so that invalid FPU states can no longer be
> abused to leak the FPU registers of other processes.
> 
> Changes since v2:
> - Use an exception handler to handle invalid FPU states
>   (suggested by Andy Lutomirski)
> - Check the size of xstate_header.reserved at build time
>   (suggested by Dave Hansen)
> 
> Eric Biggers (3):
>   x86/fpu: don't let userspace set bogus xcomp_bv
>   x86/fpu: tighten validation of user-supplied xstate_header
>   x86/fpu: reinitialize FPU registers if restoring FPU state fails
> 
>  arch/x86/include/asm/fpu/internal.h | 51 
> +++--
>  arch/x86/include/asm/fpu/xstate.h   | 25 ++
>  arch/x86/kernel/fpu/regset.c| 20 +++
>  arch/x86/kernel/fpu/signal.c| 15 ---
>  arch/x86/kernel/fpu/xstate.c| 27 
>  arch/x86/mm/extable.c   | 24 +
>  6 files changed, 94 insertions(+), 68 deletions(-)

Ok - could you please rebase these to to tip:master that is at:

git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master

In particular this has a WIP.x86/fpu branch with FPU fixes+changes queued up 
but 
not merged upstream (yet), which conflict with these changes. I'd like to merge 
them all together.

Thanks,

Ingo


[PATCH 1/2] kbuild: link-vmlinux.sh: simplify .version increment

2017-09-21 Thread Masahiro Yamada
Since commit 1f2bfbd00e46 ("kbuild: link of vmlinux moved to a
script"), it is easy to increment .version without using a temporary
file .old_version.

I do not see anybody who creates .tmp_version any more.  Probably
it is a left-over of commit 4e25d8bb9550fb ("[PATCH] kbuild: adjust
.version updating").  Just remove it.

Signed-off-by: Masahiro Yamada 
---

 Makefile|  2 +-
 scripts/link-vmlinux.sh | 15 +--
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 64cbc66..9e2781d 100644
--- a/Makefile
+++ b/Makefile
@@ -1278,7 +1278,7 @@ CLEAN_DIRS  += $(MODVERDIR)
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config usr/include include/generated  \
  arch/*/include/generated .tmp_objdiff
-MRPROPER_FILES += .config .config.old .version .old_version \
+MRPROPER_FILES += .config .config.old .version \
  Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
  signing_key.pem signing_key.priv signing_key.x509 \
  x509.genkey extra_certificates signing_key.x509.keyid \
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index e7b7eee..0cdb25b 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -187,10 +187,8 @@ sortextable()
 # Delete output files in case of error
 cleanup()
 {
-   rm -f .old_version
rm -f .tmp_System.map
rm -f .tmp_kallsyms*
-   rm -f .tmp_version
rm -f .tmp_vmlinux*
rm -f built-in.o
rm -f System.map
@@ -238,12 +236,12 @@ esac
 
 # Update version
 info GEN .version
-if [ ! -r .version ]; then
-   rm -f .version;
-   echo 1 >.version;
+if [ -r .version ]; then
+   VERSION=$(expr 0$(cat .version) + 1)
+   echo $VERSION > .version
 else
-   mv .version .old_version;
-   expr 0$(cat .old_version) + 1 >.version;
+   rm -f .version
+   echo 1 > .version
 fi;
 
 # final build of init/
@@ -331,6 +329,3 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then
exit 1
fi
 fi
-
-# We made a new kernel - delete old version file
-rm -f .old_version
-- 
2.7.4



[PATCH 1/2] kbuild: link-vmlinux.sh: simplify .version increment

2017-09-21 Thread Masahiro Yamada
Since commit 1f2bfbd00e46 ("kbuild: link of vmlinux moved to a
script"), it is easy to increment .version without using a temporary
file .old_version.

I do not see anybody who creates .tmp_version any more.  Probably
it is a left-over of commit 4e25d8bb9550fb ("[PATCH] kbuild: adjust
.version updating").  Just remove it.

Signed-off-by: Masahiro Yamada 
---

 Makefile|  2 +-
 scripts/link-vmlinux.sh | 15 +--
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 64cbc66..9e2781d 100644
--- a/Makefile
+++ b/Makefile
@@ -1278,7 +1278,7 @@ CLEAN_DIRS  += $(MODVERDIR)
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config usr/include include/generated  \
  arch/*/include/generated .tmp_objdiff
-MRPROPER_FILES += .config .config.old .version .old_version \
+MRPROPER_FILES += .config .config.old .version \
  Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
  signing_key.pem signing_key.priv signing_key.x509 \
  x509.genkey extra_certificates signing_key.x509.keyid \
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index e7b7eee..0cdb25b 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -187,10 +187,8 @@ sortextable()
 # Delete output files in case of error
 cleanup()
 {
-   rm -f .old_version
rm -f .tmp_System.map
rm -f .tmp_kallsyms*
-   rm -f .tmp_version
rm -f .tmp_vmlinux*
rm -f built-in.o
rm -f System.map
@@ -238,12 +236,12 @@ esac
 
 # Update version
 info GEN .version
-if [ ! -r .version ]; then
-   rm -f .version;
-   echo 1 >.version;
+if [ -r .version ]; then
+   VERSION=$(expr 0$(cat .version) + 1)
+   echo $VERSION > .version
 else
-   mv .version .old_version;
-   expr 0$(cat .old_version) + 1 >.version;
+   rm -f .version
+   echo 1 > .version
 fi;
 
 # final build of init/
@@ -331,6 +329,3 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then
exit 1
fi
 fi
-
-# We made a new kernel - delete old version file
-rm -f .old_version
-- 
2.7.4



[PATCH 2/2] kbuild: mkcompile_h: do not create .version

2017-09-21 Thread Masahiro Yamada
This script need not to create .version; it will be created by
scripts/link-vmlinux.sh later.  Clean-up the code slightly.

Signed-off-by: Masahiro Yamada 
---

 scripts/mkcompile_h | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
index fd8fdb9..f1ee4eb 100755
--- a/scripts/mkcompile_h
+++ b/scripts/mkcompile_h
@@ -27,12 +27,7 @@ LC_ALL=C
 export LC_ALL
 
 if [ -z "$KBUILD_BUILD_VERSION" ]; then
-   if [ -r .version ]; then
-   VERSION=`cat .version`
-   else
-   VERSION=0
-   echo 0 > .version
-   fi
+   VERSION=$(cat .version 2>/dev/null || echo 1)
 else
VERSION=$KBUILD_BUILD_VERSION
 fi
-- 
2.7.4



[PATCH 2/2] kbuild: mkcompile_h: do not create .version

2017-09-21 Thread Masahiro Yamada
This script need not to create .version; it will be created by
scripts/link-vmlinux.sh later.  Clean-up the code slightly.

Signed-off-by: Masahiro Yamada 
---

 scripts/mkcompile_h | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h
index fd8fdb9..f1ee4eb 100755
--- a/scripts/mkcompile_h
+++ b/scripts/mkcompile_h
@@ -27,12 +27,7 @@ LC_ALL=C
 export LC_ALL
 
 if [ -z "$KBUILD_BUILD_VERSION" ]; then
-   if [ -r .version ]; then
-   VERSION=`cat .version`
-   else
-   VERSION=0
-   echo 0 > .version
-   fi
+   VERSION=$(cat .version 2>/dev/null || echo 1)
 else
VERSION=$KBUILD_BUILD_VERSION
 fi
-- 
2.7.4



Re: [RFC PATCH 0/7] Fix year 2038 issue for sound subsystem

2017-09-21 Thread Baolin Wang
Hi Takashi,

On 22 September 2017 at 12:07, Takashi Sakamoto  wrote:
> Hi,
>
>
> On Sep 21 2017 15:18, Baolin Wang wrote:
>>
>> Since many structures will use timespec type variables to record time
>> stamp
>> in uapi/asound.h, which are not year 2038 safe on 32bit system. This
>> patchset
>> tries to introduce new structures removing timespec type to compatible
>> native
>> mode and compat mode.
>>
>> Moreover this patchset also converts the internal structrures to use
>> timespec64
>> type and related APIs.
>>
>> Baolin Wang (7):
>>sound: Replace timespec with timespec64
>>sound: core: Avoid using timespec for struct snd_pcm_status
>>sound: core: Avoid using timespec for struct snd_pcm_sync_ptr
>>sound: core: Avoid using timespec for struct snd_rawmidi_status
>>sound: core: Avoid using timespec for struct snd_timer_status
>>uapi: sound: Avoid using timespec for struct snd_ctl_elem_value
>>sound: core: Avoid using timespec for struct snd_timer_tread
>>
>>   include/sound/pcm.h   |  113 -
>>   include/sound/timer.h |4 +-
>>   include/uapi/sound/asound.h   |   15 +-
>>   sound/core/pcm.c  |   14 +-
>>   sound/core/pcm_compat.c   |  466
>> +
>>   sound/core/pcm_lib.c  |   33 +--
>>   sound/core/pcm_native.c   |  227 ++
>>   sound/core/rawmidi.c  |   74 +-
>>   sound/core/rawmidi_compat.c   |   90 +--
>>   sound/core/timer.c|  247 
>>   sound/core/timer_compat.c |   25 +-
>>   sound/pci/hda/hda_controller.c|   10 +-
>>   sound/soc/intel/skylake/skl-pcm.c |4 +-
>>   13 files changed, 1046 insertions(+), 276 deletions(-)
>
>
> I'm a minor Takashi in this subsystem and not those who you'd like to
> talk about this issue. But I have interests in it and would like to
> assist you, as long as I can do for it.

Thanks a lot.

>
> As a nitpicking, your patchset brings compilation error at
> configurations for x86, and x86-64 with x32 ABI support.
>
>
> ## x86-64 architecture and amd64 ABI support
> CONFIG_64BIT=y
> CONFIG_X86_64=y
>
> Success.
>
>
> ## x86-64 architecture and amd64/x32 ABI support
> CONFIG_64BIT=y
> CONFIG_X86_64=y
> CONFIG_X86_X32=y
>
> ```
> sound/core/timer_compat.c:124:54: error: array type has incomplete element
> type 'struct snd_timer_status32'
>   SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
> ```
>
> This error comes from a commit 1229cccbefe7 ('sound: core: Avoid using
> timespec for struct snd_timer_status').
>
> ```
> sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_compat':
> sound/core/pcm_compat.c:623:9: error: assignment from incompatible pointer
> type [-Werror=incompatible-pointer-types]
>   status = runtime->status;
>  ^
> sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_x32':
> sound/core/pcm_compat.c:711:9: error: assignment from incompatible pointer
> type [-Werror=incompatible-pointer-types]
>   status = runtime->status;
> ```
>
> This error comes from a commit 947c463adc00('sound: core: Avoid using
> timespec
> for struct snd_pcm_status').
>
>
> ## x86 architecture and i386 ABI support
> CONFIG_X86_32=y
>
> ```
> sound/core/pcm_native.c: In function 'snd_pcm_common_ioctl':
> sound/core/pcm_native.c:3065:2: error: duplicate case value
>   case SNDRV_PCM_IOCTL_SYNC_PTR64:
>   ^~~~
> sound/core/pcm_native.c:3062:2: error: previously used here
>   case SNDRV_PCM_IOCTL_SYNC_PTR32:
>
> ```
>
> This error comes from a commit c0513348a7b39 ('sound: core: Avoid using
> timespec for struct snd_pcm_sync_ptr').
>
>
> Your patchset brought conflicts to 'for-next' branch in a repository
> which Iwai-san maintains[1]. I rebased your patchset on a commit
> 729fbfc92a45 ('ALSA: line6: add support for POD HD DESKTOP') which is a HEAD
> of 'for-next' branch and pushed into my repository on github[2].
>
>
> I respect your work for this issue, however it's better to check whether
> your patchset is buildable or not on major configurations before
> posting.

Sorry for the building errors, since I can not build CONFIG_COMPAT
mode on my arm32 platform. But I will try to fix these build errors in
next version. This RFC patchset, I just want to show how to fix the
y2038 issue and to see if it is on the correct way. Sorry for the
building errors again.

>
> I note that at a development period for v4.5 kernel, ALSA developers
> (mainly Iwai-san) fixed x32 ABI compatibility bugs. Then I prepared for
> a rough set of test for ioctl command[3] to check his work. The set will
> partly help your work, I think (but it's really rough).

Ah, thanks.

>
> I need more time for reviewing. At least, this week is for recovery from
> my tough work to rewrite aplay[4].

Understood. Very appreciated for your comments.

>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
> [2] 

Re: [RFC PATCH 0/7] Fix year 2038 issue for sound subsystem

2017-09-21 Thread Baolin Wang
Hi Takashi,

On 22 September 2017 at 12:07, Takashi Sakamoto  wrote:
> Hi,
>
>
> On Sep 21 2017 15:18, Baolin Wang wrote:
>>
>> Since many structures will use timespec type variables to record time
>> stamp
>> in uapi/asound.h, which are not year 2038 safe on 32bit system. This
>> patchset
>> tries to introduce new structures removing timespec type to compatible
>> native
>> mode and compat mode.
>>
>> Moreover this patchset also converts the internal structrures to use
>> timespec64
>> type and related APIs.
>>
>> Baolin Wang (7):
>>sound: Replace timespec with timespec64
>>sound: core: Avoid using timespec for struct snd_pcm_status
>>sound: core: Avoid using timespec for struct snd_pcm_sync_ptr
>>sound: core: Avoid using timespec for struct snd_rawmidi_status
>>sound: core: Avoid using timespec for struct snd_timer_status
>>uapi: sound: Avoid using timespec for struct snd_ctl_elem_value
>>sound: core: Avoid using timespec for struct snd_timer_tread
>>
>>   include/sound/pcm.h   |  113 -
>>   include/sound/timer.h |4 +-
>>   include/uapi/sound/asound.h   |   15 +-
>>   sound/core/pcm.c  |   14 +-
>>   sound/core/pcm_compat.c   |  466
>> +
>>   sound/core/pcm_lib.c  |   33 +--
>>   sound/core/pcm_native.c   |  227 ++
>>   sound/core/rawmidi.c  |   74 +-
>>   sound/core/rawmidi_compat.c   |   90 +--
>>   sound/core/timer.c|  247 
>>   sound/core/timer_compat.c |   25 +-
>>   sound/pci/hda/hda_controller.c|   10 +-
>>   sound/soc/intel/skylake/skl-pcm.c |4 +-
>>   13 files changed, 1046 insertions(+), 276 deletions(-)
>
>
> I'm a minor Takashi in this subsystem and not those who you'd like to
> talk about this issue. But I have interests in it and would like to
> assist you, as long as I can do for it.

Thanks a lot.

>
> As a nitpicking, your patchset brings compilation error at
> configurations for x86, and x86-64 with x32 ABI support.
>
>
> ## x86-64 architecture and amd64 ABI support
> CONFIG_64BIT=y
> CONFIG_X86_64=y
>
> Success.
>
>
> ## x86-64 architecture and amd64/x32 ABI support
> CONFIG_64BIT=y
> CONFIG_X86_64=y
> CONFIG_X86_X32=y
>
> ```
> sound/core/timer_compat.c:124:54: error: array type has incomplete element
> type 'struct snd_timer_status32'
>   SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
> ```
>
> This error comes from a commit 1229cccbefe7 ('sound: core: Avoid using
> timespec for struct snd_timer_status').
>
> ```
> sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_compat':
> sound/core/pcm_compat.c:623:9: error: assignment from incompatible pointer
> type [-Werror=incompatible-pointer-types]
>   status = runtime->status;
>  ^
> sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_x32':
> sound/core/pcm_compat.c:711:9: error: assignment from incompatible pointer
> type [-Werror=incompatible-pointer-types]
>   status = runtime->status;
> ```
>
> This error comes from a commit 947c463adc00('sound: core: Avoid using
> timespec
> for struct snd_pcm_status').
>
>
> ## x86 architecture and i386 ABI support
> CONFIG_X86_32=y
>
> ```
> sound/core/pcm_native.c: In function 'snd_pcm_common_ioctl':
> sound/core/pcm_native.c:3065:2: error: duplicate case value
>   case SNDRV_PCM_IOCTL_SYNC_PTR64:
>   ^~~~
> sound/core/pcm_native.c:3062:2: error: previously used here
>   case SNDRV_PCM_IOCTL_SYNC_PTR32:
>
> ```
>
> This error comes from a commit c0513348a7b39 ('sound: core: Avoid using
> timespec for struct snd_pcm_sync_ptr').
>
>
> Your patchset brought conflicts to 'for-next' branch in a repository
> which Iwai-san maintains[1]. I rebased your patchset on a commit
> 729fbfc92a45 ('ALSA: line6: add support for POD HD DESKTOP') which is a HEAD
> of 'for-next' branch and pushed into my repository on github[2].
>
>
> I respect your work for this issue, however it's better to check whether
> your patchset is buildable or not on major configurations before
> posting.

Sorry for the building errors, since I can not build CONFIG_COMPAT
mode on my arm32 platform. But I will try to fix these build errors in
next version. This RFC patchset, I just want to show how to fix the
y2038 issue and to see if it is on the correct way. Sorry for the
building errors again.

>
> I note that at a development period for v4.5 kernel, ALSA developers
> (mainly Iwai-san) fixed x32 ABI compatibility bugs. Then I prepared for
> a rough set of test for ioctl command[3] to check his work. The set will
> partly help your work, I think (but it's really rough).

Ah, thanks.

>
> I need more time for reviewing. At least, this week is for recovery from
> my tough work to rewrite aplay[4].

Understood. Very appreciated for your comments.

>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
> [2] 

Re: [PATCH] fix unbalanced page refcounting in bio_map_user_iov

2017-09-21 Thread Vitaly Mayatskikh
Reproducer (needs SCSI disk):

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#define NR_IOS 1
#define NR_IOVECS 8
#define SG_IO 0x2285
 
int main(int argc, char *argv[])
{
int fd, i, j;
unsigned char *buf, *ptr, cdb[10];
sg_io_hdr_t io_hdr;
sg_iovec_t iovec[NR_IOVECS];
 
if (argc < 2) {
printf("Run: %s \n", argv[0]);
exit(1);
}
 
buf = ptr = memalign(4096, NR_IOS * NR_IOVECS * 512);
if (!buf) {
printf("can't alloc memory\n");
exit(1);
}
 
fd = open(argv[1], 0);
if (fd < 0) {
printf("open %s failed: %d (%s)\n", argv[1], errno, 
strerror(errno));
exit(1);
}
 
io_hdr.interface_id = 'S';
io_hdr.cmd_len = sizeof(cdb);
io_hdr.cmdp = cdb;
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
io_hdr.dxfer_len = 512 * NR_IOVECS;
io_hdr.dxferp = iovec;
io_hdr.iovec_count = NR_IOVECS;
 
cdb[0] = 0x28;  // READ10
cdb[8] = NR_IOVECS; // sectors
 
for (j = 0; j < NR_IOS; j++, ptr += 512) {
for (i = 0; i < NR_IOVECS; i++) {
iovec[i].iov_base = ptr;
iovec[i].iov_len = 512;
}
if (ioctl(fd, SG_IO, _hdr)) {
printf("IOCTL failed: %d (%s)\n", errno, 
strerror(errno));
exit(1);
}
}
 
free(buf);
close(fd);
return 0;
}


# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827  463601   0 1783568
Swap: 0   0   0
# ./sgio-leak /dev/sdd
# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827  853562   0 1783529
Swap: 0   0   0
[root@node-A ~]# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827  853628   0 1133561
Swap: 0   0   0
# ./sgio-leak /dev/sdd
# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827 1243589   0 1133523
Swap: 0   0   0

-- 
wbr, Vitaly


Re: [PATCH] fix unbalanced page refcounting in bio_map_user_iov

2017-09-21 Thread Vitaly Mayatskikh
Reproducer (needs SCSI disk):

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#define NR_IOS 1
#define NR_IOVECS 8
#define SG_IO 0x2285
 
int main(int argc, char *argv[])
{
int fd, i, j;
unsigned char *buf, *ptr, cdb[10];
sg_io_hdr_t io_hdr;
sg_iovec_t iovec[NR_IOVECS];
 
if (argc < 2) {
printf("Run: %s \n", argv[0]);
exit(1);
}
 
buf = ptr = memalign(4096, NR_IOS * NR_IOVECS * 512);
if (!buf) {
printf("can't alloc memory\n");
exit(1);
}
 
fd = open(argv[1], 0);
if (fd < 0) {
printf("open %s failed: %d (%s)\n", argv[1], errno, 
strerror(errno));
exit(1);
}
 
io_hdr.interface_id = 'S';
io_hdr.cmd_len = sizeof(cdb);
io_hdr.cmdp = cdb;
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
io_hdr.dxfer_len = 512 * NR_IOVECS;
io_hdr.dxferp = iovec;
io_hdr.iovec_count = NR_IOVECS;
 
cdb[0] = 0x28;  // READ10
cdb[8] = NR_IOVECS; // sectors
 
for (j = 0; j < NR_IOS; j++, ptr += 512) {
for (i = 0; i < NR_IOVECS; i++) {
iovec[i].iov_base = ptr;
iovec[i].iov_len = 512;
}
if (ioctl(fd, SG_IO, _hdr)) {
printf("IOCTL failed: %d (%s)\n", errno, 
strerror(errno));
exit(1);
}
}
 
free(buf);
close(fd);
return 0;
}


# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827  463601   0 1783568
Swap: 0   0   0
# ./sgio-leak /dev/sdd
# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827  853562   0 1783529
Swap: 0   0   0
[root@node-A ~]# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827  853628   0 1133561
Swap: 0   0   0
# ./sgio-leak /dev/sdd
# free -m
  totalusedfree  shared  buff/cache   available
Mem:   3827 1243589   0 1133523
Swap: 0   0   0

-- 
wbr, Vitaly


Re: [RFC PATCH v3 1/2] membarrier: Provide register expedited private command

2017-09-21 Thread Mathieu Desnoyers
- On Sep 21, 2017, at 11:30 PM, Boqun Feng boqun.f...@gmail.com wrote:

> On Fri, Sep 22, 2017 at 11:22:06AM +0800, Boqun Feng wrote:
>> Hi Mathieu,
>> 
>> On Tue, Sep 19, 2017 at 06:13:41PM -0400, Mathieu Desnoyers wrote:
>> > Provide a new command allowing processes to register their intent to use
>> > the private expedited command.
>> > 
>> > This allows PowerPC to skip the full memory barrier in switch_mm(), and
>> > only issue the barrier when scheduling into a task belonging to a
>> > process that has registered to use expedited private.
>> > 
>> > Processes are now required to register before using
>> > MEMBARRIER_CMD_PRIVATE_EXPEDITED, otherwise that command returns EPERM.
>> > 
>> 
>> Sorry I'm late for the party, but I couldn't stop thinking whether we
>> could avoid the register thing at all, because the registering makes
>> sys_membarrier() more complex(both for the interface and the
>> implementation). So how about we trade-off a little bit by taking
>> some(not all) the rq->locks?
>> 
>> The idea is in membarrier_private_expedited(), we go through all ->curr
>> on each CPU and
>> 
>> 1)   If it's a userspace task and its ->mm is matched, we send an ipi
>> 
>> 2)   If it's a kernel task, we skip
>> 
>>  (Because there will be a smp_mb() implied by mmdrop(), when it
>>  switchs to userspace task).
>> 
>> 3)   If it's a userspace task and its ->mm is not matched, we take
>>  the corresponding rq->lock and check rq->curr again, if its ->mm
>>  matched, we send an ipi, otherwise we do nothing.
>> 
>>  (Because if we observe rq->curr is not matched with rq->lock
>>  held, when a task having matched ->mm schedules in, the rq->lock
>>  pairing along with the smp_mb__after_spinlock() will guarantee
>>  it observes all memory ops before sys_membarrir()).
>> 
>> membarrier_private_expedited() will look like this if we choose this
>> way:
>> 
>> void membarrier_private_expedited()
>> {
>>  int cpu;
>>  bool fallback = false;
>>  cpumask_var_t tmpmask;
>>  struct rq_flags rf;
>> 
>> 
>>  if (num_online_cpus() == 1)
>>  return;
>> 
>>  smp_mb();
>> 
>>  if (!zalloc_cpumask_var(, GFP_NOWAIT)) {
>>  /* Fallback for OOM. */
>>  fallback = true;
>>  }
>> 
>>  cpus_read_lock();
>>  for_each_online_cpu(cpu) {
>>  struct task_struct *p;
>> 
>>  if (cpu == raw_smp_processor_id())
>>  continue;
>> 
>>  rcu_read_lock();
>>  p = task_rcu_dereference(_rq(cpu)->curr);
>> 
>>  if (!p) {
>>  rcu_read_unlock();
>>  continue;
>>  }
>> 
>>  if (p->mm == current->mm) {
>>  if (!fallback)
>>  __cpumask_set_cpu(cpu, tmpmask);
>>  else
>>  smp_call_function_single(cpu, ipi_mb, NULL, 1);
>>  }
>> 
>>  if (p->mm == current->mm || !p->mm) {
>>  rcu_read_unlock();
>>  continue;
>>  }
>> 
>>  rcu_read_unlock();
>>  
>>  /*
>>   * This should be a arch-specific code, as we don't
>>   * need it at else place other than some archs without
>>   * a smp_mb() in switch_mm() (i.e. powerpc)
>>   */
>>  rq_lock_irq(cpu_rq(cpu), );
>>  if (p->mm == current->mm) {
> 
> Oops, this one should be
> 
>   if (cpu_curr(cpu)->mm == current->mm)
> 
>>  if (!fallback)
>>  __cpumask_set_cpu(cpu, tmpmask);
>>  else
>>  smp_call_function_single(cpu, ipi_mb, NULL, 1);
> 
> , and this better be moved out of the lock rq->lock critical section.
> 
> Regards,
> Boqun
> 
>>  }
>>  rq_unlock_irq(cpu_rq(cpu), );
>>  }
>>  if (!fallback) {
>>  smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
>>  free_cpumask_var(tmpmask);
>>  }
>>  cpus_read_unlock();
>> 
>>  smp_mb();
>> }
>> 
>> Thoughts?

Hi Boqun,

The main concern Peter has with the runqueue locking approach
is interference with the scheduler by hitting all CPU's runqueue
locks repeatedly if someone performs membarrier system calls in
a short loop.

Just reading the rq->curr pointer does not generate as much
overhead as grabbing each rq lock.

Thanks,

Mathieu


>> 
>> Regards,
>> Boqun
>> 
> [...]

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


Re: [RFC PATCH v3 1/2] membarrier: Provide register expedited private command

2017-09-21 Thread Mathieu Desnoyers
- On Sep 21, 2017, at 11:30 PM, Boqun Feng boqun.f...@gmail.com wrote:

> On Fri, Sep 22, 2017 at 11:22:06AM +0800, Boqun Feng wrote:
>> Hi Mathieu,
>> 
>> On Tue, Sep 19, 2017 at 06:13:41PM -0400, Mathieu Desnoyers wrote:
>> > Provide a new command allowing processes to register their intent to use
>> > the private expedited command.
>> > 
>> > This allows PowerPC to skip the full memory barrier in switch_mm(), and
>> > only issue the barrier when scheduling into a task belonging to a
>> > process that has registered to use expedited private.
>> > 
>> > Processes are now required to register before using
>> > MEMBARRIER_CMD_PRIVATE_EXPEDITED, otherwise that command returns EPERM.
>> > 
>> 
>> Sorry I'm late for the party, but I couldn't stop thinking whether we
>> could avoid the register thing at all, because the registering makes
>> sys_membarrier() more complex(both for the interface and the
>> implementation). So how about we trade-off a little bit by taking
>> some(not all) the rq->locks?
>> 
>> The idea is in membarrier_private_expedited(), we go through all ->curr
>> on each CPU and
>> 
>> 1)   If it's a userspace task and its ->mm is matched, we send an ipi
>> 
>> 2)   If it's a kernel task, we skip
>> 
>>  (Because there will be a smp_mb() implied by mmdrop(), when it
>>  switchs to userspace task).
>> 
>> 3)   If it's a userspace task and its ->mm is not matched, we take
>>  the corresponding rq->lock and check rq->curr again, if its ->mm
>>  matched, we send an ipi, otherwise we do nothing.
>> 
>>  (Because if we observe rq->curr is not matched with rq->lock
>>  held, when a task having matched ->mm schedules in, the rq->lock
>>  pairing along with the smp_mb__after_spinlock() will guarantee
>>  it observes all memory ops before sys_membarrir()).
>> 
>> membarrier_private_expedited() will look like this if we choose this
>> way:
>> 
>> void membarrier_private_expedited()
>> {
>>  int cpu;
>>  bool fallback = false;
>>  cpumask_var_t tmpmask;
>>  struct rq_flags rf;
>> 
>> 
>>  if (num_online_cpus() == 1)
>>  return;
>> 
>>  smp_mb();
>> 
>>  if (!zalloc_cpumask_var(, GFP_NOWAIT)) {
>>  /* Fallback for OOM. */
>>  fallback = true;
>>  }
>> 
>>  cpus_read_lock();
>>  for_each_online_cpu(cpu) {
>>  struct task_struct *p;
>> 
>>  if (cpu == raw_smp_processor_id())
>>  continue;
>> 
>>  rcu_read_lock();
>>  p = task_rcu_dereference(_rq(cpu)->curr);
>> 
>>  if (!p) {
>>  rcu_read_unlock();
>>  continue;
>>  }
>> 
>>  if (p->mm == current->mm) {
>>  if (!fallback)
>>  __cpumask_set_cpu(cpu, tmpmask);
>>  else
>>  smp_call_function_single(cpu, ipi_mb, NULL, 1);
>>  }
>> 
>>  if (p->mm == current->mm || !p->mm) {
>>  rcu_read_unlock();
>>  continue;
>>  }
>> 
>>  rcu_read_unlock();
>>  
>>  /*
>>   * This should be a arch-specific code, as we don't
>>   * need it at else place other than some archs without
>>   * a smp_mb() in switch_mm() (i.e. powerpc)
>>   */
>>  rq_lock_irq(cpu_rq(cpu), );
>>  if (p->mm == current->mm) {
> 
> Oops, this one should be
> 
>   if (cpu_curr(cpu)->mm == current->mm)
> 
>>  if (!fallback)
>>  __cpumask_set_cpu(cpu, tmpmask);
>>  else
>>  smp_call_function_single(cpu, ipi_mb, NULL, 1);
> 
> , and this better be moved out of the lock rq->lock critical section.
> 
> Regards,
> Boqun
> 
>>  }
>>  rq_unlock_irq(cpu_rq(cpu), );
>>  }
>>  if (!fallback) {
>>  smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
>>  free_cpumask_var(tmpmask);
>>  }
>>  cpus_read_unlock();
>> 
>>  smp_mb();
>> }
>> 
>> Thoughts?

Hi Boqun,

The main concern Peter has with the runqueue locking approach
is interference with the scheduler by hitting all CPU's runqueue
locks repeatedly if someone performs membarrier system calls in
a short loop.

Just reading the rq->curr pointer does not generate as much
overhead as grabbing each rq lock.

Thanks,

Mathieu


>> 
>> Regards,
>> Boqun
>> 
> [...]

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


[PATCH v2] staging: greybus: light: Release memory obtained by kasprintf

2017-09-21 Thread Arvind Yadav
 - Free memory region, if gb_lights_channel_config is not successful.
 - No need to add check for gb_lights_channel_flash_config().

Signed-off-by: Arvind Yadav 
---
changes in v2:
- Subject line changed.
- add kfree in __gb_lights_led_unregister().
- No need to check return value of gb_lights_channel_flash_config().

 drivers/staging/greybus/light.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 3f4148c..bc1f8d2 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -926,6 +926,8 @@ static void __gb_lights_led_unregister(struct gb_channel 
*channel)
 
led_classdev_unregister(cdev);
channel->led = NULL;
+   kfree(cdev->name);
+   cdev->name = NULL;
 }
 
 static void gb_lights_channel_unregister(struct gb_channel *channel)
@@ -998,11 +1000,8 @@ static int gb_lights_channel_config(struct gb_light 
*light,
 
light->has_flash = true;
 
-   ret = gb_lights_channel_flash_config(channel);
-   if (ret < 0)
-   return ret;
+   return gb_lights_channel_flash_config(channel);
 
-   return ret;
 }
 
 static int gb_lights_light_config(struct gb_lights *glights, u8 id)
-- 
1.9.1



[PATCH v2] staging: greybus: light: Release memory obtained by kasprintf

2017-09-21 Thread Arvind Yadav
 - Free memory region, if gb_lights_channel_config is not successful.
 - No need to add check for gb_lights_channel_flash_config().

Signed-off-by: Arvind Yadav 
---
changes in v2:
- Subject line changed.
- add kfree in __gb_lights_led_unregister().
- No need to check return value of gb_lights_channel_flash_config().

 drivers/staging/greybus/light.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/light.c b/drivers/staging/greybus/light.c
index 3f4148c..bc1f8d2 100644
--- a/drivers/staging/greybus/light.c
+++ b/drivers/staging/greybus/light.c
@@ -926,6 +926,8 @@ static void __gb_lights_led_unregister(struct gb_channel 
*channel)
 
led_classdev_unregister(cdev);
channel->led = NULL;
+   kfree(cdev->name);
+   cdev->name = NULL;
 }
 
 static void gb_lights_channel_unregister(struct gb_channel *channel)
@@ -998,11 +1000,8 @@ static int gb_lights_channel_config(struct gb_light 
*light,
 
light->has_flash = true;
 
-   ret = gb_lights_channel_flash_config(channel);
-   if (ret < 0)
-   return ret;
+   return gb_lights_channel_flash_config(channel);
 
-   return ret;
 }
 
 static int gb_lights_light_config(struct gb_lights *glights, u8 id)
-- 
1.9.1



[PATCH] fix unbalanced page refcounting in bio_map_user_iov

2017-09-21 Thread Vitaly Mayatskikh
bio_map_user_iov and bio_unmap_user do unbalanced pages refcounting if
IO vector has small consecutive buffers belonging to the same page.
bio_add_pc_page merges them into one, but the page reference is never
dropped.

Signed-off-by: Vitaly Mayatskikh 

diff --git a/block/bio.c b/block/bio.c
index b38e962fa83e..10cd3b6bed27 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1383,6 +1383,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
offset = offset_in_page(uaddr);
for (j = cur_page; j < page_limit; j++) {
unsigned int bytes = PAGE_SIZE - offset;
+   unsigned short prev_bi_vcnt = bio->bi_vcnt;
 
if (len <= 0)
break;
@@ -1397,6 +1398,13 @@ struct bio *bio_map_user_iov(struct request_queue *q,
bytes)
break;
 
+   /*
+* check if vector was merged with previous
+* drop page reference if needed
+*/
+   if (bio->bi_vcnt == prev_bi_vcnt)
+   put_page(pages[j]);
+
len -= bytes;
offset = 0;
}

-- 
wbr, Vitaly


[PATCH] fix unbalanced page refcounting in bio_map_user_iov

2017-09-21 Thread Vitaly Mayatskikh
bio_map_user_iov and bio_unmap_user do unbalanced pages refcounting if
IO vector has small consecutive buffers belonging to the same page.
bio_add_pc_page merges them into one, but the page reference is never
dropped.

Signed-off-by: Vitaly Mayatskikh 

diff --git a/block/bio.c b/block/bio.c
index b38e962fa83e..10cd3b6bed27 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1383,6 +1383,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
offset = offset_in_page(uaddr);
for (j = cur_page; j < page_limit; j++) {
unsigned int bytes = PAGE_SIZE - offset;
+   unsigned short prev_bi_vcnt = bio->bi_vcnt;
 
if (len <= 0)
break;
@@ -1397,6 +1398,13 @@ struct bio *bio_map_user_iov(struct request_queue *q,
bytes)
break;
 
+   /*
+* check if vector was merged with previous
+* drop page reference if needed
+*/
+   if (bio->bi_vcnt == prev_bi_vcnt)
+   put_page(pages[j]);
+
len -= bytes;
offset = 0;
}

-- 
wbr, Vitaly


Re: Rough notes from sys_membarrier() lightning BoF

2017-09-21 Thread Michael Ellerman
Peter Zijlstra  writes:

> On Wed, Sep 20, 2017 at 06:13:50PM +, Mathieu Desnoyers wrote:
>
>> > Also, can you elaborate on the PPC issue?  PPC appears to track
>> > mm_cpumask more or less just like x86.  Is the issue just that this
>> > tracking has no implied barriers?  If so, how does TLB flush on ppc
>> > work?  It really does seem impressive to me that an architecture can
>> > efficiently support munmap() but not an expedited private membarrier.
>> 
>> I'll leave this question to the PPC experts :)
>
> IIRC PPC does not keep a tight mm_cpumask, it only sets bit, it never
> clears bits. The atomic op required to set bits does not imply any
> memory barrier on PPC.

Yep.

We do have a full barrier now when we set a bit, but not if the bit was
already set.

> TLB invalidation is a TLBI instruction, it sends TLBI broadcast packets
> over the interconnect, it doesn't require IPIs like x86.

Yep.

> The only optimization PPC does is that if the mm_cpumask has only a
> single bit set, it uses a TLBI instruction without broadcast, which is
> cheaper.

Yep.

We would like to trim the mm_cpumask, but it's one of those hairy
optimisations we have never quite found time to do.

I've been away for two weeks so I've not been able to keep up with the
membarrier discussions. Will try and page it back in next week.

cheers


Re: Rough notes from sys_membarrier() lightning BoF

2017-09-21 Thread Michael Ellerman
Peter Zijlstra  writes:

> On Wed, Sep 20, 2017 at 06:13:50PM +, Mathieu Desnoyers wrote:
>
>> > Also, can you elaborate on the PPC issue?  PPC appears to track
>> > mm_cpumask more or less just like x86.  Is the issue just that this
>> > tracking has no implied barriers?  If so, how does TLB flush on ppc
>> > work?  It really does seem impressive to me that an architecture can
>> > efficiently support munmap() but not an expedited private membarrier.
>> 
>> I'll leave this question to the PPC experts :)
>
> IIRC PPC does not keep a tight mm_cpumask, it only sets bit, it never
> clears bits. The atomic op required to set bits does not imply any
> memory barrier on PPC.

Yep.

We do have a full barrier now when we set a bit, but not if the bit was
already set.

> TLB invalidation is a TLBI instruction, it sends TLBI broadcast packets
> over the interconnect, it doesn't require IPIs like x86.

Yep.

> The only optimization PPC does is that if the mm_cpumask has only a
> single bit set, it uses a TLBI instruction without broadcast, which is
> cheaper.

Yep.

We would like to trim the mm_cpumask, but it's one of those hairy
optimisations we have never quite found time to do.

I've been away for two weeks so I've not been able to keep up with the
membarrier discussions. Will try and page it back in next week.

cheers


Re: [PATCH] ARM: mxs: constify platform_suspend_ops

2017-09-21 Thread Shawn Guo
On Wed, Aug 30, 2017 at 10:17:51PM +0530, Arvind Yadav wrote:
> platform_suspend_ops are not supposed to change at runtime.
> Functions suspend_set_ops working with const platform_suspend_ops.
> So mark the non-const structs as const.
> 
> Signed-off-by: Arvind Yadav 

Applied, thanks.


Re: [PATCH] ARM: mxs: constify platform_suspend_ops

2017-09-21 Thread Shawn Guo
On Wed, Aug 30, 2017 at 10:17:51PM +0530, Arvind Yadav wrote:
> platform_suspend_ops are not supposed to change at runtime.
> Functions suspend_set_ops working with const platform_suspend_ops.
> So mark the non-const structs as const.
> 
> Signed-off-by: Arvind Yadav 

Applied, thanks.


linux-next: Tree for Sep 22

2017-09-21 Thread Stephen Rothwell
Hi all,

Changes since 20170921:

The mips tree gained a conflict against the pci-current tree.

The net-next tree gained a build failure for which I reverted a commit.

The drm-misc tree gained conflicts against Linus' tree.

Non-merge commits (relative to Linus' tree): 1601
 1453 files changed, 55269 insertions(+), 17192 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc and an allmodconfig (with
CONFIG_BUILD_DOCSRC=n) for x86_64, a multi_v7_defconfig for arm and a
native build of tools/perf. After the final fixups (if any), I do an
x86_64 modules_install followed by builds for x86_64 allnoconfig,
powerpc allnoconfig (32 and 64 bit), ppc44x_defconfig, allyesconfig
and pseries_le_defconfig and i386, sparc and sparc64 defconfig. And
finally, a simple boot test of the powerpc pseries_le_defconfig kernel
in qemu.

Below is a summary of the state of the merge.

I am currently merging 267 trees (counting Linus' and 41 trees of bug
fix patches pending for the current merge release).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (4a704d6db0ee Merge tag 'kbuild-fixes-v4.14' of 
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild)
Merging fixes/master (820bf5c419e4 Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi)
Merging kbuild-current/fixes (25b080bd53f2 kbuild: rpm-pkg: fix version number 
handling)
Merging arc-current/for-curr (ef6c1bae4792 arc: remove redundant UTS_MACHINE 
define in arch/arc/Makefile)
Merging arm-current/fixes (746a272e4414 ARM: 8692/1: mm: abort uaccess retries 
upon fatal signal)
Merging m68k-current/for-linus (558d5ad276c9 m68k/mac: Avoid soft-lockup 
warning after mach_power_off)
Merging metag-fixes/fixes (b884a190afce metag/usercopy: Add missing fixups)
Merging powerpc-fixes/fixes (b537ca6fede6 powerpc/pseries: Fix parent_dn 
reference leak in add_dt_node())
Merging sparc/master (6470812e2226 Merge 
git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc)
Merging fscrypt-current/for-stable (42d97eb0ade3 fscrypt: fix renaming and 
linking special files)
Merging net/master (5d6b66c031ed Merge branch 'smc-bug-fixes')
Merging ipsec/master (23e9fcfef1f3 vti: fix NULL dereference in xfrm_input())
Merging netfilter/master (7f4f7dd4417d netfilter: ipset: ipset list may return 
wrong member count for set with timeout)
Merging ipvs/master (f7fb77fc1235 netfilter: nft_compat: check extension hook 
mask only if set)
Merging wireless-drivers/master (a715b3a0efe7 qtnfmac: cancel scans on wireless 
interface changes)
Merging mac80211/master (265698d7e613 nl80211: fix null-ptr dereference on 
invalid mesh configuration)
Merging sound-current/for-linus (0dcd020b7abb ALSA: usb-audio: Add sample rate 
quirk for Plantronics C310/C520-M)
Merging pci-current/for-linus (749aaf3372b8 PCI: endpoint: Use correct "end of 
test" interrupt)
Merging driver-core.current/driver-core-linus (850fdec8d2fd driver core: remove 
DRIVER_ATTR)
Merging tty.current/tty-linus (c91261437985 serial: sccnxp: Fix error handling 
in sccnxp_probe())
Merging usb.current/usb-linus (2e1c42391ff2 USB: core: harden 
cdc_parse_cdc_header)
Merging usb-gadget-fixes/fixes (7661ca09b2ff usb: gadget: dummy: fix 
nonsensical comparisons)
Merging usb-serial-fixes/usb-linus (c496ad835c31 USB: serial: cp210x: add 
support for ELV TFD500)
Merging usb-chipidea-fixes/ci-for-usb-stable (cbb22ebcfb99 usb: chipidea: core: 
check before accessing ci_role in ci_role_show)
Merging phy/fixes (2bd6bf03f4c1 Linux 4.14-rc1)
Merging staging.current/staging-linus (974d4d03fc02 staging: vchiq_2835_arm: 
Fix NULL ptr dereference in free_pagelist)
Merging char-misc.current/char-misc-linus (aad8d097c922 nvmem: add missing 
of_node_put() in of_nvmem_cell_get())
Merging input-current/for-linus (bbc8608755da Merge branch 'next' into 
for-linus)
Merging crypt

linux-next: Tree for Sep 22

2017-09-21 Thread Stephen Rothwell
Hi all,

Changes since 20170921:

The mips tree gained a conflict against the pci-current tree.

The net-next tree gained a build failure for which I reverted a commit.

The drm-misc tree gained conflicts against Linus' tree.

Non-merge commits (relative to Linus' tree): 1601
 1453 files changed, 55269 insertions(+), 17192 deletions(-)



I have created today's linux-next tree at
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
(patches at http://www.kernel.org/pub/linux/kernel/next/ ).  If you
are tracking the linux-next tree using git, you should not use "git pull"
to do so as that will try to merge the new linux-next release with the
old one.  You should use "git fetch" and checkout or reset to the new
master.

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc and an allmodconfig (with
CONFIG_BUILD_DOCSRC=n) for x86_64, a multi_v7_defconfig for arm and a
native build of tools/perf. After the final fixups (if any), I do an
x86_64 modules_install followed by builds for x86_64 allnoconfig,
powerpc allnoconfig (32 and 64 bit), ppc44x_defconfig, allyesconfig
and pseries_le_defconfig and i386, sparc and sparc64 defconfig. And
finally, a simple boot test of the powerpc pseries_le_defconfig kernel
in qemu.

Below is a summary of the state of the merge.

I am currently merging 267 trees (counting Linus' and 41 trees of bug
fix patches pending for the current merge release).

Stats about the size of the tree over time can be seen at
http://neuling.org/linux-next-size.html .

Status of my local build tests will be at
http://kisskb.ellerman.id.au/linux-next .  If maintainers want to give
advice about cross compilers/configs that work, we are always open to add
more builds.

Thanks to Randy Dunlap for doing many randconfig builds.  And to Paul
Gortmaker for triage and bug fixes.

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (4a704d6db0ee Merge tag 'kbuild-fixes-v4.14' of 
git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild)
Merging fixes/master (820bf5c419e4 Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi)
Merging kbuild-current/fixes (25b080bd53f2 kbuild: rpm-pkg: fix version number 
handling)
Merging arc-current/for-curr (ef6c1bae4792 arc: remove redundant UTS_MACHINE 
define in arch/arc/Makefile)
Merging arm-current/fixes (746a272e4414 ARM: 8692/1: mm: abort uaccess retries 
upon fatal signal)
Merging m68k-current/for-linus (558d5ad276c9 m68k/mac: Avoid soft-lockup 
warning after mach_power_off)
Merging metag-fixes/fixes (b884a190afce metag/usercopy: Add missing fixups)
Merging powerpc-fixes/fixes (b537ca6fede6 powerpc/pseries: Fix parent_dn 
reference leak in add_dt_node())
Merging sparc/master (6470812e2226 Merge 
git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc)
Merging fscrypt-current/for-stable (42d97eb0ade3 fscrypt: fix renaming and 
linking special files)
Merging net/master (5d6b66c031ed Merge branch 'smc-bug-fixes')
Merging ipsec/master (23e9fcfef1f3 vti: fix NULL dereference in xfrm_input())
Merging netfilter/master (7f4f7dd4417d netfilter: ipset: ipset list may return 
wrong member count for set with timeout)
Merging ipvs/master (f7fb77fc1235 netfilter: nft_compat: check extension hook 
mask only if set)
Merging wireless-drivers/master (a715b3a0efe7 qtnfmac: cancel scans on wireless 
interface changes)
Merging mac80211/master (265698d7e613 nl80211: fix null-ptr dereference on 
invalid mesh configuration)
Merging sound-current/for-linus (0dcd020b7abb ALSA: usb-audio: Add sample rate 
quirk for Plantronics C310/C520-M)
Merging pci-current/for-linus (749aaf3372b8 PCI: endpoint: Use correct "end of 
test" interrupt)
Merging driver-core.current/driver-core-linus (850fdec8d2fd driver core: remove 
DRIVER_ATTR)
Merging tty.current/tty-linus (c91261437985 serial: sccnxp: Fix error handling 
in sccnxp_probe())
Merging usb.current/usb-linus (2e1c42391ff2 USB: core: harden 
cdc_parse_cdc_header)
Merging usb-gadget-fixes/fixes (7661ca09b2ff usb: gadget: dummy: fix 
nonsensical comparisons)
Merging usb-serial-fixes/usb-linus (c496ad835c31 USB: serial: cp210x: add 
support for ELV TFD500)
Merging usb-chipidea-fixes/ci-for-usb-stable (cbb22ebcfb99 usb: chipidea: core: 
check before accessing ci_role in ci_role_show)
Merging phy/fixes (2bd6bf03f4c1 Linux 4.14-rc1)
Merging staging.current/staging-linus (974d4d03fc02 staging: vchiq_2835_arm: 
Fix NULL ptr dereference in free_pagelist)
Merging char-misc.current/char-misc-linus (aad8d097c922 nvmem: add missing 
of_node_put() in of_nvmem_cell_get())
Merging input-current/for-linus (bbc8608755da Merge branch 'next' into 
for-linus)
Merging crypt

[PATCH] staging: ccree: else is not generally useful after a break or return

2017-09-21 Thread sunil . m
From: Suniel Mahesh <suni...@techveda.org>

Fixes checkpatch warnings:

WARNING: else is not generally useful after a break or return

Signed-off-by: Suniel Mahesh <suni...@techveda.org>
---
Note:
- Patch was tested and built(ARCH=arm) on next-20170921.
  No build issues reported.
---
 drivers/staging/ccree/ssi_request_mgr.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/ccree/ssi_request_mgr.c 
b/drivers/staging/ccree/ssi_request_mgr.c
index daa5432..25eecbb 100644
--- a/drivers/staging/ccree/ssi_request_mgr.c
+++ b/drivers/staging/ccree/ssi_request_mgr.c
@@ -387,10 +387,9 @@ int send_request(
 */
wait_for_completion(_req->seq_compl);
return 0;
-   } else {
-   /* Operation still in process */
-   return -EINPROGRESS;
}
+   /* Operation still in process */
+   return -EINPROGRESS;
 }
 
 /*!
-- 
1.9.1



[PATCH] staging: ccree: else is not generally useful after a break or return

2017-09-21 Thread sunil . m
From: Suniel Mahesh 

Fixes checkpatch warnings:

WARNING: else is not generally useful after a break or return

Signed-off-by: Suniel Mahesh 
---
Note:
- Patch was tested and built(ARCH=arm) on next-20170921.
  No build issues reported.
---
 drivers/staging/ccree/ssi_request_mgr.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/ccree/ssi_request_mgr.c 
b/drivers/staging/ccree/ssi_request_mgr.c
index daa5432..25eecbb 100644
--- a/drivers/staging/ccree/ssi_request_mgr.c
+++ b/drivers/staging/ccree/ssi_request_mgr.c
@@ -387,10 +387,9 @@ int send_request(
 */
wait_for_completion(_req->seq_compl);
return 0;
-   } else {
-   /* Operation still in process */
-   return -EINPROGRESS;
}
+   /* Operation still in process */
+   return -EINPROGRESS;
 }
 
 /*!
-- 
1.9.1



[PATCH] ktest: take submenu into account

2017-09-21 Thread Satoru Takeuchi
grub-reboot selects the submenu's first menuentry (title is "1>0") rather than 
ktest's
menuentry (title is "2") by mistake.

===
$ sudo cat /boot/grub/grub.cfg  | grep -E "^menuentry|^submenu"
...
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os 
$menuentry_id_option '...' {
...
submenu 'Advanced options for Ubuntu' $menuentry_id_option '...' {
...
menuentry 'ktest' {
...
===

Correct it by taking submenu entries into account in get_grub2_index().

Signed-off-by: Satoru Takeuchi 
---
 tools/testing/ktest/ktest.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 0c8b61f..6cf135a 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -1821,7 +1821,7 @@ sub get_grub2_index {
$grub_number++;
$found = 1;
last;
-   } elsif (/^menuentry\s/) {
+   } elsif (/^menuentry\s|^submenu\s/) {
$grub_number++;
}
 }
-- 
2.7.4



[PATCH] ktest: take submenu into account

2017-09-21 Thread Satoru Takeuchi
grub-reboot selects the submenu's first menuentry (title is "1>0") rather than 
ktest's
menuentry (title is "2") by mistake.

===
$ sudo cat /boot/grub/grub.cfg  | grep -E "^menuentry|^submenu"
...
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os 
$menuentry_id_option '...' {
...
submenu 'Advanced options for Ubuntu' $menuentry_id_option '...' {
...
menuentry 'ktest' {
...
===

Correct it by taking submenu entries into account in get_grub2_index().

Signed-off-by: Satoru Takeuchi 
---
 tools/testing/ktest/ktest.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 0c8b61f..6cf135a 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -1821,7 +1821,7 @@ sub get_grub2_index {
$grub_number++;
$found = 1;
last;
-   } elsif (/^menuentry\s/) {
+   } elsif (/^menuentry\s|^submenu\s/) {
$grub_number++;
}
 }
-- 
2.7.4



[PATCH v4] dax: introduce CONFIG_DAX_DRIVER

2017-09-21 Thread Dan Williams
In support of allowing device-mapper to compile out idle/dead code when
there are no dax providers in the system, introduce the DAX_DRIVER
symbol. This is selected by all leaf drivers that device-mapper might be
layered on top. This allows device-mapper to conditionally 'select DAX'
only when a provider is present.

Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Gerald Schaefer 
Cc: Benjamin Herrenschmidt 
Cc: Mike Snitzer 
Cc: Bart Van Assche 
Signed-off-by: Dan Williams 
---
 arch/powerpc/platforms/Kconfig |1 +
 drivers/block/Kconfig  |1 +
 drivers/dax/Kconfig|4 +++-
 drivers/nvdimm/Kconfig |1 +
 drivers/s390/block/Kconfig |1 +
 5 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 4fd64d3f5c44..4561340c1f92 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -296,6 +296,7 @@ config AXON_RAM
tristate "Axon DDR2 memory device driver"
depends on PPC_IBM_CELL_BLADE && BLOCK
select DAX
+   select DAX_DRIVER
default m
help
  It registers one block device per Axon's DDR2 memory bank found
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 4a438b8abe27..5d4821c91a76 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -298,6 +298,7 @@ config BLK_DEV_SX8
 config BLK_DEV_RAM
tristate "RAM block device support"
select DAX if BLK_DEV_RAM_DAX
+   select DAX_DRIVER if BLK_DEV_RAM_DAX
---help---
  Saying Y here will allow you to use a portion of your RAM memory as
  a block device, so that you can make file systems on it, read and
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index b79aa8f7a497..9bf940eb9c06 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -1,3 +1,6 @@
+config DAX_DRIVER
+   bool
+
 menuconfig DAX
tristate "DAX: direct access to differentiated memory"
select SRCU
@@ -16,7 +19,6 @@ config DEV_DAX
  baseline memory pool.  Mappings of a /dev/daxX.Y device impose
  restrictions that make the mapping behavior deterministic.
 
-
 config DEV_DAX_PMEM
tristate "PMEM DAX: direct access to persistent memory"
depends on LIBNVDIMM && NVDIMM_DAX && DEV_DAX
diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig
index 5bdd499b5f4f..afe4018d76cf 100644
--- a/drivers/nvdimm/Kconfig
+++ b/drivers/nvdimm/Kconfig
@@ -21,6 +21,7 @@ config BLK_DEV_PMEM
tristate "PMEM: Persistent memory block device support"
default LIBNVDIMM
select DAX
+   select DAX_DRIVER
select ND_BTT if BTT
select ND_PFN if NVDIMM_PFN
help
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index 31f014b57bfc..3f563f2f33d6 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -15,6 +15,7 @@ config BLK_DEV_XPRAM
 config DCSSBLK
def_tristate m
select DAX
+   select DAX_DRIVER
prompt "DCSSBLK support"
depends on S390 && BLOCK
help



[PATCH v4] dax: introduce CONFIG_DAX_DRIVER

2017-09-21 Thread Dan Williams
In support of allowing device-mapper to compile out idle/dead code when
there are no dax providers in the system, introduce the DAX_DRIVER
symbol. This is selected by all leaf drivers that device-mapper might be
layered on top. This allows device-mapper to conditionally 'select DAX'
only when a provider is present.

Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: Martin Schwidefsky 
Cc: Heiko Carstens 
Cc: Gerald Schaefer 
Cc: Benjamin Herrenschmidt 
Cc: Mike Snitzer 
Cc: Bart Van Assche 
Signed-off-by: Dan Williams 
---
 arch/powerpc/platforms/Kconfig |1 +
 drivers/block/Kconfig  |1 +
 drivers/dax/Kconfig|4 +++-
 drivers/nvdimm/Kconfig |1 +
 drivers/s390/block/Kconfig |1 +
 5 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 4fd64d3f5c44..4561340c1f92 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -296,6 +296,7 @@ config AXON_RAM
tristate "Axon DDR2 memory device driver"
depends on PPC_IBM_CELL_BLADE && BLOCK
select DAX
+   select DAX_DRIVER
default m
help
  It registers one block device per Axon's DDR2 memory bank found
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 4a438b8abe27..5d4821c91a76 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -298,6 +298,7 @@ config BLK_DEV_SX8
 config BLK_DEV_RAM
tristate "RAM block device support"
select DAX if BLK_DEV_RAM_DAX
+   select DAX_DRIVER if BLK_DEV_RAM_DAX
---help---
  Saying Y here will allow you to use a portion of your RAM memory as
  a block device, so that you can make file systems on it, read and
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index b79aa8f7a497..9bf940eb9c06 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -1,3 +1,6 @@
+config DAX_DRIVER
+   bool
+
 menuconfig DAX
tristate "DAX: direct access to differentiated memory"
select SRCU
@@ -16,7 +19,6 @@ config DEV_DAX
  baseline memory pool.  Mappings of a /dev/daxX.Y device impose
  restrictions that make the mapping behavior deterministic.
 
-
 config DEV_DAX_PMEM
tristate "PMEM DAX: direct access to persistent memory"
depends on LIBNVDIMM && NVDIMM_DAX && DEV_DAX
diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig
index 5bdd499b5f4f..afe4018d76cf 100644
--- a/drivers/nvdimm/Kconfig
+++ b/drivers/nvdimm/Kconfig
@@ -21,6 +21,7 @@ config BLK_DEV_PMEM
tristate "PMEM: Persistent memory block device support"
default LIBNVDIMM
select DAX
+   select DAX_DRIVER
select ND_BTT if BTT
select ND_PFN if NVDIMM_PFN
help
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index 31f014b57bfc..3f563f2f33d6 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -15,6 +15,7 @@ config BLK_DEV_XPRAM
 config DCSSBLK
def_tristate m
select DAX
+   select DAX_DRIVER
prompt "DCSSBLK support"
depends on S390 && BLOCK
help



[PATCH v4 0/2] dax, dm: stop requiring dax for device-mapper

2017-09-21 Thread Dan Williams
Changes since v3 [1]:
* rebase on 4.14-rc1
* rewrite the changelog of patch2 to drop broken references to the
  "built-in portion of device-mapper" (Mike)

[1]: https://lists.01.org/pipermail/linux-nvdimm/2017-August/011545.html

---

Bart points out that the DAX core is unconditionally enabled if
device-mapper is enabled. Add some config machinery and stub routines to
allow device-mapper to build and run with CONFIG_DAX=n.

---

Dan Williams (2):
  dax: introduce CONFIG_DAX_DRIVER
  dm: allow device-mapper to operate without dax support


 arch/powerpc/platforms/Kconfig |1 +
 drivers/block/Kconfig  |1 +
 drivers/dax/Kconfig|4 +++-
 drivers/md/Kconfig |2 +-
 drivers/md/dm-linear.c |6 ++
 drivers/md/dm-stripe.c |6 ++
 drivers/md/dm.c|   10 ++
 drivers/nvdimm/Kconfig |1 +
 drivers/s390/block/Kconfig |1 +
 include/linux/dax.h|   30 --
 10 files changed, 50 insertions(+), 12 deletions(-)


[PATCH v4 0/2] dax, dm: stop requiring dax for device-mapper

2017-09-21 Thread Dan Williams
Changes since v3 [1]:
* rebase on 4.14-rc1
* rewrite the changelog of patch2 to drop broken references to the
  "built-in portion of device-mapper" (Mike)

[1]: https://lists.01.org/pipermail/linux-nvdimm/2017-August/011545.html

---

Bart points out that the DAX core is unconditionally enabled if
device-mapper is enabled. Add some config machinery and stub routines to
allow device-mapper to build and run with CONFIG_DAX=n.

---

Dan Williams (2):
  dax: introduce CONFIG_DAX_DRIVER
  dm: allow device-mapper to operate without dax support


 arch/powerpc/platforms/Kconfig |1 +
 drivers/block/Kconfig  |1 +
 drivers/dax/Kconfig|4 +++-
 drivers/md/Kconfig |2 +-
 drivers/md/dm-linear.c |6 ++
 drivers/md/dm-stripe.c |6 ++
 drivers/md/dm.c|   10 ++
 drivers/nvdimm/Kconfig |1 +
 drivers/s390/block/Kconfig |1 +
 include/linux/dax.h|   30 --
 10 files changed, 50 insertions(+), 12 deletions(-)


Re: [PATCH] Input: add support for the Samsung S6SY761 touchscreen

2017-09-21 Thread Andi Shyti
Hi Dmitry,

thanks for your review!

[...]

> > +static void s6sy761_report_coordinates(struct s6sy761_data *sdata, u8 
> > *event)
> > +{
> > +   u8 tid = ((event[0] & S6SY761_MASK_TID) >> 2) - 1;
> 
> Should we make sure that event[0] & S6SY761_MASK_TID is not 0?

I check event[0] already in s6sy761_handle_events (called by the
irq handler), if we get here event[0] is for sure positive...

[...]

> > +static void s6sy761_handle_events(struct s6sy761_data *sdata, u8 
> > left_event)
> > +{
> > +   int i;
> > +
> > +   for (i = 0; i < left_event; i++) {
> > +   u8 *event = >data[i * S6SY761_EVENT_SIZE];
> > +   u8 event_id = event[0] & S6SY761_MASK_EID;
> > +
> > +   if (!event[0])
> > +   return;
   
... exactly here.

'!event[0]' means also to me that there is nothing left,
therefore I can discard whatever is next (given that there is
something left).

> > +   switch (event_id) {
> > +
> > +   case S6SY761_EVENT_ID_COORDINATE:
> > +   s6sy761_handle_coordinates(sdata, event);
> > +   break;
> > +
> > +   case S6SY761_EVENT_ID_STATUS:
> > +   break;
> > +
> > +   default:
> > +   break;
> > +   }
> > +   }
> > +}

[...]

> > +static ssize_t s6sy761_sysfs_low_power_store(struct device *dev,
> > +   struct device_attribute *attr,
> > +   const char *buf, size_t len)
> > +{
> > +   struct s6sy761_data *sdata = dev_get_drvdata(dev);
> > +   unsigned long value;
> > +   s32 ret;
> > +   u8 new_status;
> > +
> > +   if (kstrtoul(buf, 0, ))
> > +   return -EINVAL;
> > +
> > +   /*
> > +* The device does not respond to read/write in low power,
> > +* it will enable only in case of external events (e.g. touch).
> > +* The i2c read will fail as expected if no external events occur
> > +*/
> 
> I am not quite sure how to parse this. Are you saying that the device in
> low power mode will wake up when touched? Then your runtime PM
> implementation seems incomplete.

I was startled as well when I saw this working. It cannot be in
the PM runtime because the device would freeze (unless is
touched). I don't know if it's a bug in the firmware or this is
how it meant to be.

> In any case, I'd rather we did not expose this state as a custom
> attribute.

I can remove it completely, indeed I don't see much use of it.

[...]

> > +   sdata->devid = buffer[1] << 8 | buffer[2];
> 
>   get_unaligned_be16()?

Thanks!

[...]

> > +   /* check if both max_x and max_y have a value */
> > +   if (unlikely(!sdata->prop.max_x || !sdata->prop.max_y))
> 
> This is not in hot path, we do not need unlikely() here.

OK, Thanks!

> > +   return -EINVAL;
> > +
> > +   /* if no tx channels defined, at least keep one */
> > +   sdata->tx_channel = !buffer[8] ? 1 : buffer[8];
> 
>   sdata->tx_channel = max(buffer[8], 1);

Thanks!

[...]

> > +static int s6sy761_probe(struct i2c_client *client,
> > +   const struct i2c_device_id *id)
> > +{

[...]

> > +   err = devm_request_threaded_irq(>dev, client->irq, NULL,
> > +   s6sy761_irq_handler,
> > +   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> > +   "s6sy761_irq", sdata);
> > +   if (err)
> > +   return err;
> > +
> > +   disable_irq(client->irq);
> 
> Can you request IRQ after allocating and setting up the input device?
> Then you do not need to check for its presence in the interrupt handler.

The reason I do it here is because the x and y are embedded in
the device itself. This means that I first need to enable the
device, read x and y and then register the input device.

At power up I might expect an interrupt coming, thus I need to
check if 'input' is not 'NULL'.

[...]

> > +   err = sysfs_create_group(>client->dev.kobj,
> > +_attribute_group);
> 
> We have devm_device_add_groups() now.

Thanks! I will patch also the other driver I sent, then (the
stmfts).

[...]

> Thanks.

Thank you!

Andi


Re: [PATCH] Input: add support for the Samsung S6SY761 touchscreen

2017-09-21 Thread Andi Shyti
Hi Dmitry,

thanks for your review!

[...]

> > +static void s6sy761_report_coordinates(struct s6sy761_data *sdata, u8 
> > *event)
> > +{
> > +   u8 tid = ((event[0] & S6SY761_MASK_TID) >> 2) - 1;
> 
> Should we make sure that event[0] & S6SY761_MASK_TID is not 0?

I check event[0] already in s6sy761_handle_events (called by the
irq handler), if we get here event[0] is for sure positive...

[...]

> > +static void s6sy761_handle_events(struct s6sy761_data *sdata, u8 
> > left_event)
> > +{
> > +   int i;
> > +
> > +   for (i = 0; i < left_event; i++) {
> > +   u8 *event = >data[i * S6SY761_EVENT_SIZE];
> > +   u8 event_id = event[0] & S6SY761_MASK_EID;
> > +
> > +   if (!event[0])
> > +   return;
   
... exactly here.

'!event[0]' means also to me that there is nothing left,
therefore I can discard whatever is next (given that there is
something left).

> > +   switch (event_id) {
> > +
> > +   case S6SY761_EVENT_ID_COORDINATE:
> > +   s6sy761_handle_coordinates(sdata, event);
> > +   break;
> > +
> > +   case S6SY761_EVENT_ID_STATUS:
> > +   break;
> > +
> > +   default:
> > +   break;
> > +   }
> > +   }
> > +}

[...]

> > +static ssize_t s6sy761_sysfs_low_power_store(struct device *dev,
> > +   struct device_attribute *attr,
> > +   const char *buf, size_t len)
> > +{
> > +   struct s6sy761_data *sdata = dev_get_drvdata(dev);
> > +   unsigned long value;
> > +   s32 ret;
> > +   u8 new_status;
> > +
> > +   if (kstrtoul(buf, 0, ))
> > +   return -EINVAL;
> > +
> > +   /*
> > +* The device does not respond to read/write in low power,
> > +* it will enable only in case of external events (e.g. touch).
> > +* The i2c read will fail as expected if no external events occur
> > +*/
> 
> I am not quite sure how to parse this. Are you saying that the device in
> low power mode will wake up when touched? Then your runtime PM
> implementation seems incomplete.

I was startled as well when I saw this working. It cannot be in
the PM runtime because the device would freeze (unless is
touched). I don't know if it's a bug in the firmware or this is
how it meant to be.

> In any case, I'd rather we did not expose this state as a custom
> attribute.

I can remove it completely, indeed I don't see much use of it.

[...]

> > +   sdata->devid = buffer[1] << 8 | buffer[2];
> 
>   get_unaligned_be16()?

Thanks!

[...]

> > +   /* check if both max_x and max_y have a value */
> > +   if (unlikely(!sdata->prop.max_x || !sdata->prop.max_y))
> 
> This is not in hot path, we do not need unlikely() here.

OK, Thanks!

> > +   return -EINVAL;
> > +
> > +   /* if no tx channels defined, at least keep one */
> > +   sdata->tx_channel = !buffer[8] ? 1 : buffer[8];
> 
>   sdata->tx_channel = max(buffer[8], 1);

Thanks!

[...]

> > +static int s6sy761_probe(struct i2c_client *client,
> > +   const struct i2c_device_id *id)
> > +{

[...]

> > +   err = devm_request_threaded_irq(>dev, client->irq, NULL,
> > +   s6sy761_irq_handler,
> > +   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> > +   "s6sy761_irq", sdata);
> > +   if (err)
> > +   return err;
> > +
> > +   disable_irq(client->irq);
> 
> Can you request IRQ after allocating and setting up the input device?
> Then you do not need to check for its presence in the interrupt handler.

The reason I do it here is because the x and y are embedded in
the device itself. This means that I first need to enable the
device, read x and y and then register the input device.

At power up I might expect an interrupt coming, thus I need to
check if 'input' is not 'NULL'.

[...]

> > +   err = sysfs_create_group(>client->dev.kobj,
> > +_attribute_group);
> 
> We have devm_device_add_groups() now.

Thanks! I will patch also the other driver I sent, then (the
stmfts).

[...]

> Thanks.

Thank you!

Andi


[PATCH] brd: prevent overflow caused by too large rd_size parameter

2017-09-21 Thread Satoru Takeuchi
The max value of rd_size parameter is ULONG_MAX from the following commit.

Commit 366f4aea649a65c3735d91b4409d84c771811290 ("brd: Switch rd_size
to unsigned long")

However, this parameter * 1024 will be set as inode->i_size corresponding
to brd devices and it's a signed value. To prevent overflow, this parameter
should be equal to or smaller than the max value of sector_t >> 11, 10 bits
are for 1024 and 1 bit is for sign bit.

Signed-off-by: Satoru Takeuchi 
---
 drivers/block/brd.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 104b71c..2b00e7d 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -546,6 +546,14 @@ static int __init brd_init(void)
 *  dynamically.
 */
 
+   /*
+* rd_size * 1024 will be set as its inode->i_size and it's a signed
+* value. So rd_size should be equal to or smaller than the max value
+* of sector_t >> 11, 10 bits are for 1024 and 1 bit is for sign bit.
+*/
+   if (rd_size >> (sizeof(sector_t) * 8 - 11))
+   return -EINVAL;
+
if (register_blkdev(RAMDISK_MAJOR, "ramdisk"))
return -EIO;
 
-- 
2.7.4



[PATCH] brd: prevent overflow caused by too large rd_size parameter

2017-09-21 Thread Satoru Takeuchi
The max value of rd_size parameter is ULONG_MAX from the following commit.

Commit 366f4aea649a65c3735d91b4409d84c771811290 ("brd: Switch rd_size
to unsigned long")

However, this parameter * 1024 will be set as inode->i_size corresponding
to brd devices and it's a signed value. To prevent overflow, this parameter
should be equal to or smaller than the max value of sector_t >> 11, 10 bits
are for 1024 and 1 bit is for sign bit.

Signed-off-by: Satoru Takeuchi 
---
 drivers/block/brd.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 104b71c..2b00e7d 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -546,6 +546,14 @@ static int __init brd_init(void)
 *  dynamically.
 */
 
+   /*
+* rd_size * 1024 will be set as its inode->i_size and it's a signed
+* value. So rd_size should be equal to or smaller than the max value
+* of sector_t >> 11, 10 bits are for 1024 and 1 bit is for sign bit.
+*/
+   if (rd_size >> (sizeof(sector_t) * 8 - 11))
+   return -EINVAL;
+
if (register_blkdev(RAMDISK_MAJOR, "ramdisk"))
return -EIO;
 
-- 
2.7.4



Re: [RFC PATCH 0/7] Fix year 2038 issue for sound subsystem

2017-09-21 Thread Takashi Sakamoto

Hi,

On Sep 21 2017 15:18, Baolin Wang wrote:

Since many structures will use timespec type variables to record time stamp
in uapi/asound.h, which are not year 2038 safe on 32bit system. This patchset
tries to introduce new structures removing timespec type to compatible native
mode and compat mode.

Moreover this patchset also converts the internal structrures to use timespec64
type and related APIs.

Baolin Wang (7):
   sound: Replace timespec with timespec64
   sound: core: Avoid using timespec for struct snd_pcm_status
   sound: core: Avoid using timespec for struct snd_pcm_sync_ptr
   sound: core: Avoid using timespec for struct snd_rawmidi_status
   sound: core: Avoid using timespec for struct snd_timer_status
   uapi: sound: Avoid using timespec for struct snd_ctl_elem_value
   sound: core: Avoid using timespec for struct snd_timer_tread

  include/sound/pcm.h   |  113 -
  include/sound/timer.h |4 +-
  include/uapi/sound/asound.h   |   15 +-
  sound/core/pcm.c  |   14 +-
  sound/core/pcm_compat.c   |  466 +
  sound/core/pcm_lib.c  |   33 +--
  sound/core/pcm_native.c   |  227 ++
  sound/core/rawmidi.c  |   74 +-
  sound/core/rawmidi_compat.c   |   90 +--
  sound/core/timer.c|  247 
  sound/core/timer_compat.c |   25 +-
  sound/pci/hda/hda_controller.c|   10 +-
  sound/soc/intel/skylake/skl-pcm.c |4 +-
  13 files changed, 1046 insertions(+), 276 deletions(-)


I'm a minor Takashi in this subsystem and not those who you'd like to
talk about this issue. But I have interests in it and would like to
assist you, as long as I can do for it.

As a nitpicking, your patchset brings compilation error at
configurations for x86, and x86-64 with x32 ABI support.


## x86-64 architecture and amd64 ABI support
CONFIG_64BIT=y
CONFIG_X86_64=y

Success.


## x86-64 architecture and amd64/x32 ABI support
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_X86_X32=y

```
sound/core/timer_compat.c:124:54: error: array type has incomplete 
element type 'struct snd_timer_status32'

  SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
```

This error comes from a commit 1229cccbefe7 ('sound: core: Avoid using 
timespec for struct snd_timer_status').


```
sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_compat':
sound/core/pcm_compat.c:623:9: error: assignment from incompatible 
pointer type [-Werror=incompatible-pointer-types]

  status = runtime->status;
 ^
sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_x32':
sound/core/pcm_compat.c:711:9: error: assignment from incompatible 
pointer type [-Werror=incompatible-pointer-types]

  status = runtime->status;
```

This error comes from a commit 947c463adc00('sound: core: Avoid using 
timespec

for struct snd_pcm_status').


## x86 architecture and i386 ABI support
CONFIG_X86_32=y

```
sound/core/pcm_native.c: In function 'snd_pcm_common_ioctl':
sound/core/pcm_native.c:3065:2: error: duplicate case value
  case SNDRV_PCM_IOCTL_SYNC_PTR64:
  ^~~~
sound/core/pcm_native.c:3062:2: error: previously used here
  case SNDRV_PCM_IOCTL_SYNC_PTR32:

```

This error comes from a commit c0513348a7b39 ('sound: core: Avoid using
timespec for struct snd_pcm_sync_ptr').


Your patchset brought conflicts to 'for-next' branch in a repository
which Iwai-san maintains[1]. I rebased your patchset on a commit 
729fbfc92a45 ('ALSA: line6: add support for POD HD DESKTOP') which is a 
HEAD of 'for-next' branch and pushed into my repository on github[2].



I respect your work for this issue, however it's better to check whether
your patchset is buildable or not on major configurations before
posting.


I note that at a development period for v4.5 kernel, ALSA developers
(mainly Iwai-san) fixed x32 ABI compatibility bugs. Then I prepared for
a rough set of test for ioctl command[3] to check his work. The set will
partly help your work, I think (but it's really rough).

I need more time for reviewing. At least, this week is for recovery from
my tough work to rewrite aplay[4].


[1] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
[2] https://github.com/takaswie/sound/tree/topic/year2038-rfc1
[3] https://github.com/takaswie/alsa-ioctl-test/
[4] [alsa-devel] [RFCv2][PATCH 00/38] alsa-utils: axfer: rewrite aplay
http://mailman.alsa-project.org/pipermail/alsa-devel/2017-September/125574.html

Thanks

Takashi Sakamoto


Re: [RFC PATCH 0/7] Fix year 2038 issue for sound subsystem

2017-09-21 Thread Takashi Sakamoto

Hi,

On Sep 21 2017 15:18, Baolin Wang wrote:

Since many structures will use timespec type variables to record time stamp
in uapi/asound.h, which are not year 2038 safe on 32bit system. This patchset
tries to introduce new structures removing timespec type to compatible native
mode and compat mode.

Moreover this patchset also converts the internal structrures to use timespec64
type and related APIs.

Baolin Wang (7):
   sound: Replace timespec with timespec64
   sound: core: Avoid using timespec for struct snd_pcm_status
   sound: core: Avoid using timespec for struct snd_pcm_sync_ptr
   sound: core: Avoid using timespec for struct snd_rawmidi_status
   sound: core: Avoid using timespec for struct snd_timer_status
   uapi: sound: Avoid using timespec for struct snd_ctl_elem_value
   sound: core: Avoid using timespec for struct snd_timer_tread

  include/sound/pcm.h   |  113 -
  include/sound/timer.h |4 +-
  include/uapi/sound/asound.h   |   15 +-
  sound/core/pcm.c  |   14 +-
  sound/core/pcm_compat.c   |  466 +
  sound/core/pcm_lib.c  |   33 +--
  sound/core/pcm_native.c   |  227 ++
  sound/core/rawmidi.c  |   74 +-
  sound/core/rawmidi_compat.c   |   90 +--
  sound/core/timer.c|  247 
  sound/core/timer_compat.c |   25 +-
  sound/pci/hda/hda_controller.c|   10 +-
  sound/soc/intel/skylake/skl-pcm.c |4 +-
  13 files changed, 1046 insertions(+), 276 deletions(-)


I'm a minor Takashi in this subsystem and not those who you'd like to
talk about this issue. But I have interests in it and would like to
assist you, as long as I can do for it.

As a nitpicking, your patchset brings compilation error at
configurations for x86, and x86-64 with x32 ABI support.


## x86-64 architecture and amd64 ABI support
CONFIG_64BIT=y
CONFIG_X86_64=y

Success.


## x86-64 architecture and amd64/x32 ABI support
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_X86_X32=y

```
sound/core/timer_compat.c:124:54: error: array type has incomplete 
element type 'struct snd_timer_status32'

  SNDRV_TIMER_IOCTL_STATUS32 = _IOW('T', 0x14, struct snd_timer_status32),
```

This error comes from a commit 1229cccbefe7 ('sound: core: Avoid using 
timespec for struct snd_timer_status').


```
sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_compat':
sound/core/pcm_compat.c:623:9: error: assignment from incompatible 
pointer type [-Werror=incompatible-pointer-types]

  status = runtime->status;
 ^
sound/core/pcm_compat.c: In function 'snd_pcm_ioctl_sync_ptr_x32':
sound/core/pcm_compat.c:711:9: error: assignment from incompatible 
pointer type [-Werror=incompatible-pointer-types]

  status = runtime->status;
```

This error comes from a commit 947c463adc00('sound: core: Avoid using 
timespec

for struct snd_pcm_status').


## x86 architecture and i386 ABI support
CONFIG_X86_32=y

```
sound/core/pcm_native.c: In function 'snd_pcm_common_ioctl':
sound/core/pcm_native.c:3065:2: error: duplicate case value
  case SNDRV_PCM_IOCTL_SYNC_PTR64:
  ^~~~
sound/core/pcm_native.c:3062:2: error: previously used here
  case SNDRV_PCM_IOCTL_SYNC_PTR32:

```

This error comes from a commit c0513348a7b39 ('sound: core: Avoid using
timespec for struct snd_pcm_sync_ptr').


Your patchset brought conflicts to 'for-next' branch in a repository
which Iwai-san maintains[1]. I rebased your patchset on a commit 
729fbfc92a45 ('ALSA: line6: add support for POD HD DESKTOP') which is a 
HEAD of 'for-next' branch and pushed into my repository on github[2].



I respect your work for this issue, however it's better to check whether
your patchset is buildable or not on major configurations before
posting.


I note that at a development period for v4.5 kernel, ALSA developers
(mainly Iwai-san) fixed x32 ABI compatibility bugs. Then I prepared for
a rough set of test for ioctl command[3] to check his work. The set will
partly help your work, I think (but it's really rough).

I need more time for reviewing. At least, this week is for recovery from
my tough work to rewrite aplay[4].


[1] https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
[2] https://github.com/takaswie/sound/tree/topic/year2038-rfc1
[3] https://github.com/takaswie/alsa-ioctl-test/
[4] [alsa-devel] [RFCv2][PATCH 00/38] alsa-utils: axfer: rewrite aplay
http://mailman.alsa-project.org/pipermail/alsa-devel/2017-September/125574.html

Thanks

Takashi Sakamoto


Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

2017-09-21 Thread Jason Wang



On 2017年09月21日 06:02, John Fastabend wrote:

On 09/19/2017 02:42 AM, Jason Wang wrote:

This patch tries to add XDP_REDIRECT for virtio-net. The changes are
not complex as we could use exist XDP_TX helpers for most of the
work. The rest is passing the XDP_TX to NAPI handler for implementing
batching.

Cc: John Fastabend 
Signed-off-by: Jason Wang 
---

[...]


@@ -678,12 +711,20 @@ static struct sk_buff *receive_mergeable(struct 
net_device *dev,
}
break;
case XDP_TX:
-   if (unlikely(!virtnet_xdp_xmit(vi, )))
+   if (unlikely(!__virtnet_xdp_xmit(vi, )))
trace_xdp_exception(vi->dev, xdp_prog, act);
+   else
+   *xdp_xmit = true;
if (unlikely(xdp_page != page))
goto err_xdp;
rcu_read_unlock();
goto xdp_xmit;
+   case XDP_REDIRECT:
+   err = xdp_do_redirect(dev, , xdp_prog);
+   if (err)
+   *xdp_xmit = true;

Is this a typo? Should above be

if (!err)
*xdp_xmit = true;

this would match the pattern in receive_small and also make more sense.


Right, will post a fix.




+   rcu_read_unlock();
+   goto xdp_xmit;
default:
bpf_warn_invalid_xdp_action(act);
case XDP_ABORTED:
@@ -788,7 +829,7 @@ static struct sk_buff *receive_mergeable(struct net_device 
*dev,
  }
  

[...]

Otherwise looks good to me thanks for doing this.

.John



Thanks for the reviewing.



Re: [PATCH net-next 3/3] virtio-net: support XDP_REDIRECT

2017-09-21 Thread Jason Wang



On 2017年09月21日 06:02, John Fastabend wrote:

On 09/19/2017 02:42 AM, Jason Wang wrote:

This patch tries to add XDP_REDIRECT for virtio-net. The changes are
not complex as we could use exist XDP_TX helpers for most of the
work. The rest is passing the XDP_TX to NAPI handler for implementing
batching.

Cc: John Fastabend 
Signed-off-by: Jason Wang 
---

[...]


@@ -678,12 +711,20 @@ static struct sk_buff *receive_mergeable(struct 
net_device *dev,
}
break;
case XDP_TX:
-   if (unlikely(!virtnet_xdp_xmit(vi, )))
+   if (unlikely(!__virtnet_xdp_xmit(vi, )))
trace_xdp_exception(vi->dev, xdp_prog, act);
+   else
+   *xdp_xmit = true;
if (unlikely(xdp_page != page))
goto err_xdp;
rcu_read_unlock();
goto xdp_xmit;
+   case XDP_REDIRECT:
+   err = xdp_do_redirect(dev, , xdp_prog);
+   if (err)
+   *xdp_xmit = true;

Is this a typo? Should above be

if (!err)
*xdp_xmit = true;

this would match the pattern in receive_small and also make more sense.


Right, will post a fix.




+   rcu_read_unlock();
+   goto xdp_xmit;
default:
bpf_warn_invalid_xdp_action(act);
case XDP_ABORTED:
@@ -788,7 +829,7 @@ static struct sk_buff *receive_mergeable(struct net_device 
*dev,
  }
  

[...]

Otherwise looks good to me thanks for doing this.

.John



Thanks for the reviewing.



[PATCH 1/2] vmbus: add per-channel sysfs info

2017-09-21 Thread kys
From: Stephen Hemminger 

This extends existing vmbus related sysfs structure to provide per-channel
state information. This is useful when diagnosing issues with multiple
queues in networking and storage.

The existing sysfs only displayed information about the primary
channel. The one place it reported multiple channels was the
channel_vp_mapping file which violated the sysfs convention
of one value per file.

Signed-off-by: Stephen Hemminger 
Signed-off-by: K. Y. Srinivasan 
---
 Documentation/ABI/stable/sysfs-bus-vmbus |  56 ++
 drivers/hv/channel_mgmt.c|  10 +-
 drivers/hv/hyperv_vmbus.h|   2 +
 drivers/hv/vmbus_drv.c   | 185 +--
 include/linux/hyperv.h   |   6 +
 5 files changed, 246 insertions(+), 13 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus 
b/Documentation/ABI/stable/sysfs-bus-vmbus
index 5d0125f7bcaf..0ebd8a1537a0 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -41,3 +41,59 @@ KernelVersion:   4.5
 Contact:   K. Y. Srinivasan 
 Description:   The 16 bit vendor ID of the device
 Users: tools/hv/lsvmbus and user level RDMA libraries
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/in_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Inbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/latency
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel signaling latency
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/out_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Outbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/pending
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel interrupt pending state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/read_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to read
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/write_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to write
+Users: Debuggig tools
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 624d815745e4..747887038992 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -350,7 +350,7 @@ static void free_channel(struct vmbus_channel *channel)
 {
tasklet_kill(>callback_event);
 
-   kfree_rcu(channel, rcu);
+   kobject_put(>kobj);
 }
 
 static void percpu_channel_enq(void *arg)
@@ -513,6 +513,14 @@ static void vmbus_process_offer(struct vmbus_channel 
*newchannel)
newchannel->state = CHANNEL_OPEN_STATE;
 
if (!fnew) {
+   struct hv_device *dev
+   = newchannel->primary_channel->device_obj;
+
+   if (vmbus_add_channel_kobj(dev, newchannel)) {
+   atomic_dec(_connection.offer_in_progress);
+   goto err_free_chan;
+   }
+
if (channel->sc_creation_callback != NULL)
channel->sc_creation_callback(newchannel);
return;
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 1b6a5e0dfa75..bfa2d0af4e1d 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -384,6 +384,8 @@ struct hv_device *vmbus_device_create(const uuid_le *type,
 
 int vmbus_device_register(struct hv_device *child_device_obj);
 void vmbus_device_unregister(struct hv_device *device_obj);
+int vmbus_add_channel_kobj(struct hv_device *device_obj,
+  struct vmbus_channel *channel);

[PATCH 1/2] vmbus: add per-channel sysfs info

2017-09-21 Thread kys
From: Stephen Hemminger 

This extends existing vmbus related sysfs structure to provide per-channel
state information. This is useful when diagnosing issues with multiple
queues in networking and storage.

The existing sysfs only displayed information about the primary
channel. The one place it reported multiple channels was the
channel_vp_mapping file which violated the sysfs convention
of one value per file.

Signed-off-by: Stephen Hemminger 
Signed-off-by: K. Y. Srinivasan 
---
 Documentation/ABI/stable/sysfs-bus-vmbus |  56 ++
 drivers/hv/channel_mgmt.c|  10 +-
 drivers/hv/hyperv_vmbus.h|   2 +
 drivers/hv/vmbus_drv.c   | 185 +--
 include/linux/hyperv.h   |   6 +
 5 files changed, 246 insertions(+), 13 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus 
b/Documentation/ABI/stable/sysfs-bus-vmbus
index 5d0125f7bcaf..0ebd8a1537a0 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -41,3 +41,59 @@ KernelVersion:   4.5
 Contact:   K. Y. Srinivasan 
 Description:   The 16 bit vendor ID of the device
 Users: tools/hv/lsvmbus and user level RDMA libraries
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/cpu
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   VCPU (sub)channel is affinitized to
+Users: tools/hv/lsvmbus and other debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/in_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Inbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/latency
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel signaling latency
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/out_mask
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Outbound channel signaling state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/pending
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Channel interrupt pending state
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/read_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to read
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/write_avail
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Bytes availabble to write
+Users: Debuggig tools
diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 624d815745e4..747887038992 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -350,7 +350,7 @@ static void free_channel(struct vmbus_channel *channel)
 {
tasklet_kill(>callback_event);
 
-   kfree_rcu(channel, rcu);
+   kobject_put(>kobj);
 }
 
 static void percpu_channel_enq(void *arg)
@@ -513,6 +513,14 @@ static void vmbus_process_offer(struct vmbus_channel 
*newchannel)
newchannel->state = CHANNEL_OPEN_STATE;
 
if (!fnew) {
+   struct hv_device *dev
+   = newchannel->primary_channel->device_obj;
+
+   if (vmbus_add_channel_kobj(dev, newchannel)) {
+   atomic_dec(_connection.offer_in_progress);
+   goto err_free_chan;
+   }
+
if (channel->sc_creation_callback != NULL)
channel->sc_creation_callback(newchannel);
return;
diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 1b6a5e0dfa75..bfa2d0af4e1d 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -384,6 +384,8 @@ struct hv_device *vmbus_device_create(const uuid_le *type,
 
 int vmbus_device_register(struct hv_device *child_device_obj);
 void vmbus_device_unregister(struct hv_device *device_obj);
+int vmbus_add_channel_kobj(struct hv_device *device_obj,
+  struct vmbus_channel *channel);
 
 struct vmbus_channel *relid2channel(u32 relid);
 
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 43160a2eafe0..c126d3937414 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -107,28 +107,30 @@ static void print_alias_name(struct hv_device 

[PATCH 2/2] Drivers: hv: vmbus: Expose per-channel interrupts and events counters

2017-09-21 Thread kys
From: Stephen Hemminger 

When investigating performance, it is useful to be able to look at
the number of host and guest events per-channel. This is equivalent
to per-device interrupt statistics.

Signed-off-by: Stephen Hemminger 
Signed-off-by: K. Y. Srinivasan 
---
 Documentation/ABI/stable/sysfs-bus-vmbus | 14 ++
 drivers/hv/connection.c  |  2 ++
 drivers/hv/vmbus_drv.c   | 18 ++
 include/linux/hyperv.h   |  4 
 4 files changed, 38 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus 
b/Documentation/ABI/stable/sysfs-bus-vmbus
index 0ebd8a1537a0..d4eca1717adb 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -97,3 +97,17 @@ KernelVersion:   4.14
 Contact:   Stephen Hemminger 
 Description:   Bytes availabble to write
 Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/events
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Number of times we have signaled the host
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/interrupts
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Number of times we have taken an interrupt (incoming)
+Users: Debuggig tools
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 59c11ff90d12..2bb0d03c5212 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -406,6 +406,8 @@ void vmbus_set_event(struct vmbus_channel *channel)
if (!channel->is_dedicated_interrupt)
vmbus_send_interrupt(child_relid);
 
+   ++channel->sig_events;
+
hv_do_hypercall(HVCALL_SIGNAL_EVENT, channel->sig_event, NULL);
 }
 EXPORT_SYMBOL_GPL(vmbus_set_event);
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index c126d3937414..88c4f5e98fc9 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -945,6 +945,8 @@ static void vmbus_chan_sched(struct hv_per_cpu_context 
*hv_cpu)
if (channel->rescind)
continue;
 
+   ++channel->interrupts;
+
switch (channel->callback_mode) {
case HV_CALL_ISR:
vmbus_channel_isr(channel);
@@ -1238,6 +1240,20 @@ static ssize_t channel_latency_show(const struct 
vmbus_channel *channel,
 }
 VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL);
 
+static ssize_t channel_interrupts_show(const struct vmbus_channel *channel, 
char *buf)
+{
+   return sprintf(buf, "%u\n", channel->interrupts);
+}
+VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL);
+
+static ssize_t channel_events_show(const struct vmbus_channel *channel, char 
*buf)
+{
+   return sprintf(buf, "%u\n", channel->sig_events);
+}
+VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL);
+
+
+
 static struct attribute *vmbus_chan_attrs[] = {
_attr_out_mask.attr,
_attr_in_mask.attr,
@@ -1246,6 +1262,8 @@ static struct attribute *vmbus_chan_attrs[] = {
_attr_cpu.attr,
_attr_pending.attr,
_attr_latency.attr,
+   _attr_interrupts.attr,
+   _attr_events.attr,
NULL
 };
 
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 91c88e0e771e..d7c85a475c46 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -731,6 +731,10 @@ struct vmbus_channel {
 
struct vmbus_close_msg close_msg;
 
+   /* Statistics */
+   unsigned intinterrupts; /* Host to Guest interrupts */
+   unsigned intsig_events; /* Guest to Host events */
+
/* Channel callback's invoked in softirq context */
struct tasklet_struct callback_event;
void (*onchannel_callback)(void *context);
-- 
2.14.1



[PATCH 2/2] Drivers: hv: vmbus: Expose per-channel interrupts and events counters

2017-09-21 Thread kys
From: Stephen Hemminger 

When investigating performance, it is useful to be able to look at
the number of host and guest events per-channel. This is equivalent
to per-device interrupt statistics.

Signed-off-by: Stephen Hemminger 
Signed-off-by: K. Y. Srinivasan 
---
 Documentation/ABI/stable/sysfs-bus-vmbus | 14 ++
 drivers/hv/connection.c  |  2 ++
 drivers/hv/vmbus_drv.c   | 18 ++
 include/linux/hyperv.h   |  4 
 4 files changed, 38 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-bus-vmbus 
b/Documentation/ABI/stable/sysfs-bus-vmbus
index 0ebd8a1537a0..d4eca1717adb 100644
--- a/Documentation/ABI/stable/sysfs-bus-vmbus
+++ b/Documentation/ABI/stable/sysfs-bus-vmbus
@@ -97,3 +97,17 @@ KernelVersion:   4.14
 Contact:   Stephen Hemminger 
 Description:   Bytes availabble to write
 Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/events
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Number of times we have signaled the host
+Users: Debuggig tools
+
+What:  /sys/bus/vmbus/devices/vmbus_*/channels/relid/interrupts
+Date:  September. 2017
+KernelVersion: 4.14
+Contact:   Stephen Hemminger 
+Description:   Number of times we have taken an interrupt (incoming)
+Users: Debuggig tools
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 59c11ff90d12..2bb0d03c5212 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -406,6 +406,8 @@ void vmbus_set_event(struct vmbus_channel *channel)
if (!channel->is_dedicated_interrupt)
vmbus_send_interrupt(child_relid);
 
+   ++channel->sig_events;
+
hv_do_hypercall(HVCALL_SIGNAL_EVENT, channel->sig_event, NULL);
 }
 EXPORT_SYMBOL_GPL(vmbus_set_event);
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index c126d3937414..88c4f5e98fc9 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -945,6 +945,8 @@ static void vmbus_chan_sched(struct hv_per_cpu_context 
*hv_cpu)
if (channel->rescind)
continue;
 
+   ++channel->interrupts;
+
switch (channel->callback_mode) {
case HV_CALL_ISR:
vmbus_channel_isr(channel);
@@ -1238,6 +1240,20 @@ static ssize_t channel_latency_show(const struct 
vmbus_channel *channel,
 }
 VMBUS_CHAN_ATTR(latency, S_IRUGO, channel_latency_show, NULL);
 
+static ssize_t channel_interrupts_show(const struct vmbus_channel *channel, 
char *buf)
+{
+   return sprintf(buf, "%u\n", channel->interrupts);
+}
+VMBUS_CHAN_ATTR(interrupts, S_IRUGO, channel_interrupts_show, NULL);
+
+static ssize_t channel_events_show(const struct vmbus_channel *channel, char 
*buf)
+{
+   return sprintf(buf, "%u\n", channel->sig_events);
+}
+VMBUS_CHAN_ATTR(events, S_IRUGO, channel_events_show, NULL);
+
+
+
 static struct attribute *vmbus_chan_attrs[] = {
_attr_out_mask.attr,
_attr_in_mask.attr,
@@ -1246,6 +1262,8 @@ static struct attribute *vmbus_chan_attrs[] = {
_attr_cpu.attr,
_attr_pending.attr,
_attr_latency.attr,
+   _attr_interrupts.attr,
+   _attr_events.attr,
NULL
 };
 
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 91c88e0e771e..d7c85a475c46 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -731,6 +731,10 @@ struct vmbus_channel {
 
struct vmbus_close_msg close_msg;
 
+   /* Statistics */
+   unsigned intinterrupts; /* Host to Guest interrupts */
+   unsigned intsig_events; /* Guest to Host events */
+
/* Channel callback's invoked in softirq context */
struct tasklet_struct callback_event;
void (*onchannel_callback)(void *context);
-- 
2.14.1



Re: [PATCH 2/5] nvmem: mtk-efuse: use stack for nvmem_config instead of malloc'ing it

2017-09-21 Thread Sean Wang
Hi, Masahiro

On Thu, 2017-09-21 at 11:09 +0900, Masahiro Yamada wrote:
> Hi Sean,
> 
> 
> 2017-09-21 1:32 GMT+09:00 Sean Wang :
> > Hi, Masahiro
> >
> > For maintainability, I felt it's better if we use the same way to
> > register nvmem as that most drivers does under nvmem usually using
> > static structure. Otherwise, they should also be changed to use the
> > one-time data in stack to avoid extra bytes to keep them.
> >
> > Sean
> 
> 
> Srinivas and I discussed the best practice for allocating nvmem_config.
> https://lkml.org/lkml/2017/9/11/4
> 
> From the discussion, static structure is possible only when
> the system has one instance of the device.
> 

thank you for your detailed explanation

> If you know this is the case for mediatek,
> yes, you can turn it into static,
> but it is not always possible.
> For example, Socionext SoCs have
> two banks of efuse devices.
> 

there should be only one instance of nvmem for mediatek soc, currently


> So, if we want to align the coding style for consistency,
> nvmem in stack is safe and efficient, I think.
> 
> 
> Moving one-time data into stack slightly
> reduces the kernel image size.
> 
> 

agreed on those statements, indeed bigger struct uart_8250_port is still
used on stack for configuring in a lot 8250 driver, so 

Acked-by: Sean Wang 






Re: [PATCH 2/5] nvmem: mtk-efuse: use stack for nvmem_config instead of malloc'ing it

2017-09-21 Thread Sean Wang
Hi, Masahiro

On Thu, 2017-09-21 at 11:09 +0900, Masahiro Yamada wrote:
> Hi Sean,
> 
> 
> 2017-09-21 1:32 GMT+09:00 Sean Wang :
> > Hi, Masahiro
> >
> > For maintainability, I felt it's better if we use the same way to
> > register nvmem as that most drivers does under nvmem usually using
> > static structure. Otherwise, they should also be changed to use the
> > one-time data in stack to avoid extra bytes to keep them.
> >
> > Sean
> 
> 
> Srinivas and I discussed the best practice for allocating nvmem_config.
> https://lkml.org/lkml/2017/9/11/4
> 
> From the discussion, static structure is possible only when
> the system has one instance of the device.
> 

thank you for your detailed explanation

> If you know this is the case for mediatek,
> yes, you can turn it into static,
> but it is not always possible.
> For example, Socionext SoCs have
> two banks of efuse devices.
> 

there should be only one instance of nvmem for mediatek soc, currently


> So, if we want to align the coding style for consistency,
> nvmem in stack is safe and efficient, I think.
> 
> 
> Moving one-time data into stack slightly
> reduces the kernel image size.
> 
> 

agreed on those statements, indeed bigger struct uart_8250_port is still
used on stack for configuring in a lot 8250 driver, so 

Acked-by: Sean Wang 






[PATCH 0/2] Drivers: hv: vmbus: Add additional per-channel sysfs info

2017-09-21 Thread kys
From: "K. Y. Srinivasan" 

Add additional per-channel sysfs information to help debug performance
issues.

Greg, please apply this patch-set to 4.15-rc1.

Stephen Hemminger (2):
  vmbus: add per-channel sysfs info
  Drivers: hv: vmbus: Expose per-channel interrupts and events counters

 Documentation/ABI/stable/sysfs-bus-vmbus |  70 +++
 drivers/hv/channel_mgmt.c|  10 +-
 drivers/hv/connection.c  |   2 +
 drivers/hv/hyperv_vmbus.h|   2 +
 drivers/hv/vmbus_drv.c   | 203 +--
 include/linux/hyperv.h   |  10 ++
 6 files changed, 284 insertions(+), 13 deletions(-)

-- 
2.14.1



[PATCH 0/2] Drivers: hv: vmbus: Add additional per-channel sysfs info

2017-09-21 Thread kys
From: "K. Y. Srinivasan" 

Add additional per-channel sysfs information to help debug performance
issues.

Greg, please apply this patch-set to 4.15-rc1.

Stephen Hemminger (2):
  vmbus: add per-channel sysfs info
  Drivers: hv: vmbus: Expose per-channel interrupts and events counters

 Documentation/ABI/stable/sysfs-bus-vmbus |  70 +++
 drivers/hv/channel_mgmt.c|  10 +-
 drivers/hv/connection.c  |   2 +
 drivers/hv/hyperv_vmbus.h|   2 +
 drivers/hv/vmbus_drv.c   | 203 +--
 include/linux/hyperv.h   |  10 ++
 6 files changed, 284 insertions(+), 13 deletions(-)

-- 
2.14.1



[PATCH v2 02/12] mtd: nand: denali: prefix detect_max_banks() with denali_

2017-09-21 Thread Masahiro Yamada
All functions in this driver are prefixed with denali_
except detect_max_banks().  Rename it for consistency.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index d847ae4..48193f9 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -81,7 +81,7 @@ static void denali_host_write(struct denali_nand_info *denali,
  * Use the configuration feature register to determine the maximum number of
  * banks that the hardware supports.
  */
-static void detect_max_banks(struct denali_nand_info *denali)
+static void denali_detect_max_banks(struct denali_nand_info *denali)
 {
uint32_t features = ioread32(denali->reg + FEATURES);
 
@@ -1115,7 +1115,7 @@ static void denali_hw_init(struct denali_nand_info 
*denali)
 * if this value is 0, just let it be.
 */
denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);
-   detect_max_banks(denali);
+   denali_detect_max_banks(denali);
iowrite32(0x0F, denali->reg + RB_PIN_ENABLED);
iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE);
 
-- 
2.7.4



[PATCH v2 02/12] mtd: nand: denali: prefix detect_max_banks() with denali_

2017-09-21 Thread Masahiro Yamada
All functions in this driver are prefixed with denali_
except detect_max_banks().  Rename it for consistency.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index d847ae4..48193f9 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -81,7 +81,7 @@ static void denali_host_write(struct denali_nand_info *denali,
  * Use the configuration feature register to determine the maximum number of
  * banks that the hardware supports.
  */
-static void detect_max_banks(struct denali_nand_info *denali)
+static void denali_detect_max_banks(struct denali_nand_info *denali)
 {
uint32_t features = ioread32(denali->reg + FEATURES);
 
@@ -1115,7 +1115,7 @@ static void denali_hw_init(struct denali_nand_info 
*denali)
 * if this value is 0, just let it be.
 */
denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES);
-   detect_max_banks(denali);
+   denali_detect_max_banks(denali);
iowrite32(0x0F, denali->reg + RB_PIN_ENABLED);
iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE);
 
-- 
2.7.4



[PATCH v2 09/12] mtd: nand: denali: use upper/lower_32_bits() macro for clean-up

2017-09-21 Thread Masahiro Yamada
I used (uint64_t) cast to avoid "right shift count >= width of type"
warning.   provides nice helpers to cater to it.
The code will be cleaner, and easier to understand.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 02ce310..e567ad9 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -469,10 +469,10 @@ static void denali_setup_dma64(struct denali_nand_info 
*denali,
  0x01002000 | (64 << 16) | (write << 8) | page_count);
 
/* 2. set memory low address */
-   denali_host_write(denali, mode, dma_addr);
+   denali_host_write(denali, mode, lower_32_bits(dma_addr));
 
/* 3. set memory high address */
-   denali_host_write(denali, mode, (uint64_t)dma_addr >> 32);
+   denali_host_write(denali, mode, upper_32_bits(dma_addr));
 }
 
 static void denali_setup_dma32(struct denali_nand_info *denali,
-- 
2.7.4



[PATCH v2 09/12] mtd: nand: denali: use upper/lower_32_bits() macro for clean-up

2017-09-21 Thread Masahiro Yamada
I used (uint64_t) cast to avoid "right shift count >= width of type"
warning.   provides nice helpers to cater to it.
The code will be cleaner, and easier to understand.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 02ce310..e567ad9 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -469,10 +469,10 @@ static void denali_setup_dma64(struct denali_nand_info 
*denali,
  0x01002000 | (64 << 16) | (write << 8) | page_count);
 
/* 2. set memory low address */
-   denali_host_write(denali, mode, dma_addr);
+   denali_host_write(denali, mode, lower_32_bits(dma_addr));
 
/* 3. set memory high address */
-   denali_host_write(denali, mode, (uint64_t)dma_addr >> 32);
+   denali_host_write(denali, mode, upper_32_bits(dma_addr));
 }
 
 static void denali_setup_dma32(struct denali_nand_info *denali,
-- 
2.7.4



[PATCH v2 07/12] mtd: nand: denali: use more FIELD_PREP / FIELD_GET where appropriate

2017-09-21 Thread Masahiro Yamada
In several places in this driver, the register fields are retrieved
as follows:

  val = reg & FOO_MASK;

Then, modified as follows:

  reg &= ~FOO_MASK;
  reg |= val;

This code relies on its shift is 0, which we will never know until
we check the definition of FOO_MASK.  Use FIELD_PREP / FIELD_GET
where appropriate.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 1525c4e..ca98015 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -88,7 +88,7 @@ static void denali_detect_max_banks(struct denali_nand_info 
*denali)
 {
uint32_t features = ioread32(denali->reg + FEATURES);
 
-   denali->max_banks = 1 << (features & FEATURES__N_BANKS);
+   denali->max_banks = 1 << FIELD_GET(FEATURES__N_BANKS, features);
 
/* the encoding changed from rev 5.0 to 5.1 */
if (denali->revision < 0x0501)
@@ -374,7 +374,7 @@ static int denali_hw_ecc_fixup(struct mtd_info *mtd,
return 0;
}
 
-   max_bitflips = ecc_cor & ECC_COR_INFO__MAX_ERRORS;
+   max_bitflips = FIELD_GET(ECC_COR_INFO__MAX_ERRORS, ecc_cor);
 
/*
 * The register holds the maximum of per-sector corrected bitflips.
@@ -985,7 +985,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + ACC_CLKS);
tmp &= ~ACC_CLKS__VALUE;
-   tmp |= acc_clks;
+   tmp |= FIELD_PREP(ACC_CLKS__VALUE, acc_clks);
iowrite32(tmp, denali->reg + ACC_CLKS);
 
/* tRWH -> RE_2_WE */
@@ -994,7 +994,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RE_2_WE);
tmp &= ~RE_2_WE__VALUE;
-   tmp |= re_2_we;
+   tmp |= FIELD_PREP(RE_2_WE__VALUE, re_2_we);
iowrite32(tmp, denali->reg + RE_2_WE);
 
/* tRHZ -> RE_2_RE */
@@ -1003,7 +1003,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RE_2_RE);
tmp &= ~RE_2_RE__VALUE;
-   tmp |= re_2_re;
+   tmp |= FIELD_PREP(RE_2_RE__VALUE, re_2_re);
iowrite32(tmp, denali->reg + RE_2_RE);
 
/* tWHR -> WE_2_RE */
@@ -1012,7 +1012,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + TWHR2_AND_WE_2_RE);
tmp &= ~TWHR2_AND_WE_2_RE__WE_2_RE;
-   tmp |= we_2_re;
+   tmp |= FIELD_PREP(TWHR2_AND_WE_2_RE__WE_2_RE, we_2_re);
iowrite32(tmp, denali->reg + TWHR2_AND_WE_2_RE);
 
/* tADL -> ADDR_2_DATA */
@@ -1026,8 +1026,8 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
addr_2_data = min_t(int, addr_2_data, addr_2_data_mask);
 
tmp = ioread32(denali->reg + TCWAW_AND_ADDR_2_DATA);
-   tmp &= ~addr_2_data_mask;
-   tmp |= addr_2_data;
+   tmp &= ~TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA;
+   tmp |= FIELD_PREP(TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA, addr_2_data);
iowrite32(tmp, denali->reg + TCWAW_AND_ADDR_2_DATA);
 
/* tREH, tWH -> RDWR_EN_HI_CNT */
@@ -1037,7 +1037,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RDWR_EN_HI_CNT);
tmp &= ~RDWR_EN_HI_CNT__VALUE;
-   tmp |= rdwr_en_hi;
+   tmp |= FIELD_PREP(RDWR_EN_HI_CNT__VALUE, rdwr_en_hi);
iowrite32(tmp, denali->reg + RDWR_EN_HI_CNT);
 
/* tRP, tWP -> RDWR_EN_LO_CNT */
@@ -1051,7 +1051,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RDWR_EN_LO_CNT);
tmp &= ~RDWR_EN_LO_CNT__VALUE;
-   tmp |= rdwr_en_lo;
+   tmp |= FIELD_PREP(RDWR_EN_LO_CNT__VALUE, rdwr_en_lo);
iowrite32(tmp, denali->reg + RDWR_EN_LO_CNT);
 
/* tCS, tCEA -> CS_SETUP_CNT */
@@ -1062,7 +1062,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + CS_SETUP_CNT);
tmp &= ~CS_SETUP_CNT__VALUE;
-   tmp |= cs_setup;
+   tmp |= FIELD_PREP(CS_SETUP_CNT__VALUE, cs_setup);
iowrite32(tmp, denali->reg + CS_SETUP_CNT);
 
return 0;
-- 
2.7.4



[PATCH v2 07/12] mtd: nand: denali: use more FIELD_PREP / FIELD_GET where appropriate

2017-09-21 Thread Masahiro Yamada
In several places in this driver, the register fields are retrieved
as follows:

  val = reg & FOO_MASK;

Then, modified as follows:

  reg &= ~FOO_MASK;
  reg |= val;

This code relies on its shift is 0, which we will never know until
we check the definition of FOO_MASK.  Use FIELD_PREP / FIELD_GET
where appropriate.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 1525c4e..ca98015 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -88,7 +88,7 @@ static void denali_detect_max_banks(struct denali_nand_info 
*denali)
 {
uint32_t features = ioread32(denali->reg + FEATURES);
 
-   denali->max_banks = 1 << (features & FEATURES__N_BANKS);
+   denali->max_banks = 1 << FIELD_GET(FEATURES__N_BANKS, features);
 
/* the encoding changed from rev 5.0 to 5.1 */
if (denali->revision < 0x0501)
@@ -374,7 +374,7 @@ static int denali_hw_ecc_fixup(struct mtd_info *mtd,
return 0;
}
 
-   max_bitflips = ecc_cor & ECC_COR_INFO__MAX_ERRORS;
+   max_bitflips = FIELD_GET(ECC_COR_INFO__MAX_ERRORS, ecc_cor);
 
/*
 * The register holds the maximum of per-sector corrected bitflips.
@@ -985,7 +985,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + ACC_CLKS);
tmp &= ~ACC_CLKS__VALUE;
-   tmp |= acc_clks;
+   tmp |= FIELD_PREP(ACC_CLKS__VALUE, acc_clks);
iowrite32(tmp, denali->reg + ACC_CLKS);
 
/* tRWH -> RE_2_WE */
@@ -994,7 +994,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RE_2_WE);
tmp &= ~RE_2_WE__VALUE;
-   tmp |= re_2_we;
+   tmp |= FIELD_PREP(RE_2_WE__VALUE, re_2_we);
iowrite32(tmp, denali->reg + RE_2_WE);
 
/* tRHZ -> RE_2_RE */
@@ -1003,7 +1003,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RE_2_RE);
tmp &= ~RE_2_RE__VALUE;
-   tmp |= re_2_re;
+   tmp |= FIELD_PREP(RE_2_RE__VALUE, re_2_re);
iowrite32(tmp, denali->reg + RE_2_RE);
 
/* tWHR -> WE_2_RE */
@@ -1012,7 +1012,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + TWHR2_AND_WE_2_RE);
tmp &= ~TWHR2_AND_WE_2_RE__WE_2_RE;
-   tmp |= we_2_re;
+   tmp |= FIELD_PREP(TWHR2_AND_WE_2_RE__WE_2_RE, we_2_re);
iowrite32(tmp, denali->reg + TWHR2_AND_WE_2_RE);
 
/* tADL -> ADDR_2_DATA */
@@ -1026,8 +1026,8 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
addr_2_data = min_t(int, addr_2_data, addr_2_data_mask);
 
tmp = ioread32(denali->reg + TCWAW_AND_ADDR_2_DATA);
-   tmp &= ~addr_2_data_mask;
-   tmp |= addr_2_data;
+   tmp &= ~TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA;
+   tmp |= FIELD_PREP(TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA, addr_2_data);
iowrite32(tmp, denali->reg + TCWAW_AND_ADDR_2_DATA);
 
/* tREH, tWH -> RDWR_EN_HI_CNT */
@@ -1037,7 +1037,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RDWR_EN_HI_CNT);
tmp &= ~RDWR_EN_HI_CNT__VALUE;
-   tmp |= rdwr_en_hi;
+   tmp |= FIELD_PREP(RDWR_EN_HI_CNT__VALUE, rdwr_en_hi);
iowrite32(tmp, denali->reg + RDWR_EN_HI_CNT);
 
/* tRP, tWP -> RDWR_EN_LO_CNT */
@@ -1051,7 +1051,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + RDWR_EN_LO_CNT);
tmp &= ~RDWR_EN_LO_CNT__VALUE;
-   tmp |= rdwr_en_lo;
+   tmp |= FIELD_PREP(RDWR_EN_LO_CNT__VALUE, rdwr_en_lo);
iowrite32(tmp, denali->reg + RDWR_EN_LO_CNT);
 
/* tCS, tCEA -> CS_SETUP_CNT */
@@ -1062,7 +1062,7 @@ static int denali_setup_data_interface(struct mtd_info 
*mtd, int chipnr,
 
tmp = ioread32(denali->reg + CS_SETUP_CNT);
tmp &= ~CS_SETUP_CNT__VALUE;
-   tmp |= cs_setup;
+   tmp |= FIELD_PREP(CS_SETUP_CNT__VALUE, cs_setup);
iowrite32(tmp, denali->reg + CS_SETUP_CNT);
 
return 0;
-- 
2.7.4



[PATCH v2 12/12] mtd: nand: denali: change the setup_dma choice into hook

2017-09-21 Thread Masahiro Yamada
The previous commit added some hooks into struct denali_nand_info,
so here is one more for clean-up.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 15 +--
 drivers/mtd/nand/denali.h |  2 ++
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 7c24983..0b268ec 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -519,15 +519,6 @@ static void denali_setup_dma32(struct denali_nand_info 
*denali,
denali->host_write(denali, mode | 0x14000, 0x2400);
 }
 
-static void denali_setup_dma(struct denali_nand_info *denali,
-dma_addr_t dma_addr, int page, int write)
-{
-   if (denali->caps & DENALI_CAP_DMA_64BIT)
-   denali_setup_dma64(denali, dma_addr, page, write);
-   else
-   denali_setup_dma32(denali, dma_addr, page, write);
-}
-
 static int denali_pio_read(struct denali_nand_info *denali, void *buf,
   size_t size, int page, int raw)
 {
@@ -619,7 +610,7 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
iowrite32(DMA_ENABLE__FLAG, denali->reg + DMA_ENABLE);
 
denali_reset_irq(denali);
-   denali_setup_dma(denali, dma_addr, page, write);
+   denali->setup_dma(denali, dma_addr, page, write);
 
irq_status = denali_wait_for_irq(denali, irq_mask);
if (!(irq_status & INTR__DMA_CMD_COMP))
@@ -1314,6 +1305,10 @@ int denali_init(struct denali_nand_info *denali)
if (denali->dma_avail) {
chip->options |= NAND_USE_BOUNCE_BUFFER;
chip->buf_align = 16;
+   if (denali->caps & DENALI_CAP_DMA_64BIT)
+   denali->setup_dma = denali_setup_dma64;
+   else
+   denali->setup_dma = denali_setup_dma32;
}
 
chip->bbt_options |= NAND_BBT_USE_FLASH;
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 3aeb272..2911066 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -321,6 +321,8 @@ struct denali_nand_info {
const struct nand_ecc_caps *ecc_caps;
u32 (*host_read)(struct denali_nand_info *denali, u32 addr);
void (*host_write)(struct denali_nand_info *denali, u32 addr, u32 data);
+   void (*setup_dma)(struct denali_nand_info *denali, dma_addr_t dma_addr,
+ int page, int write);
 };
 
 #define DENALI_CAP_HW_ECC_FIXUPBIT(0)
-- 
2.7.4



[PATCH v2 06/12] mtd: nand: denali: clean up macros with

2017-09-21 Thread Masahiro Yamada
All the register offsets and bitfield masks are defined in denali.h,
but the driver code ended up with additional crappy macros such as
MAKE_ECC_CORRECTION(), ECC_SECTOR(), etc.

The reason is apparent - accessing a register field requires mask and
shift pair.  The denali.h only provides mask.  However, defining both
is tedious.

 provides a convenient way to get register fields
only with a single shifted mask.  Now use it.

While I am here, I shortened some macros.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 25 +++--
 drivers/mtd/nand/denali.h | 13 +
 2 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 3cc56de..1525c4e 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -386,13 +387,6 @@ static int denali_hw_ecc_fixup(struct mtd_info *mtd,
return max_bitflips;
 }
 
-#define ECC_SECTOR(x)  (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12)
-#define ECC_BYTE(x)(((x) & ECC_ERROR_ADDRESS__OFFSET))
-#define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK)
-#define ECC_ERROR_UNCORRECTABLE(x) ((x) & ERR_CORRECTION_INFO__ERROR_TYPE)
-#define ECC_ERR_DEVICE(x)  (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8)
-#define ECC_LAST_ERR(x)((x) & 
ERR_CORRECTION_INFO__LAST_ERR_INFO)
-
 static int denali_sw_ecc_fixup(struct mtd_info *mtd,
   struct denali_nand_info *denali,
   unsigned long *uncor_ecc_flags, uint8_t *buf)
@@ -410,18 +404,20 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
 
do {
err_addr = ioread32(denali->reg + ECC_ERROR_ADDRESS);
-   err_sector = ECC_SECTOR(err_addr);
-   err_byte = ECC_BYTE(err_addr);
+   err_sector = FIELD_GET(ECC_ERROR_ADDRESS__SECTOR, err_addr);
+   err_byte = FIELD_GET(ECC_ERROR_ADDRESS__OFFSET, err_addr);
 
err_cor_info = ioread32(denali->reg + ERR_CORRECTION_INFO);
-   err_cor_value = ECC_CORRECTION_VALUE(err_cor_info);
-   err_device = ECC_ERR_DEVICE(err_cor_info);
+   err_cor_value = FIELD_GET(ERR_CORRECTION_INFO__BYTE,
+ err_cor_info);
+   err_device = FIELD_GET(ERR_CORRECTION_INFO__DEVICE,
+  err_cor_info);
 
/* reset the bitflip counter when crossing ECC sector */
if (err_sector != prev_sector)
bitflips = 0;
 
-   if (ECC_ERROR_UNCORRECTABLE(err_cor_info)) {
+   if (err_cor_info & ERR_CORRECTION_INFO__UNCOR) {
/*
 * Check later if this is a real ECC error, or
 * an erased sector.
@@ -451,7 +447,7 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
}
 
prev_sector = err_sector;
-   } while (!ECC_LAST_ERR(err_cor_info));
+   } while (!(err_cor_info & ERR_CORRECTION_INFO__LAST_ERR));
 
/*
 * Once handle all ecc errors, controller will trigger a
@@ -1351,7 +1347,8 @@ int denali_init(struct denali_nand_info *denali)
"chosen ECC settings: step=%d, strength=%d, bytes=%d\n",
chip->ecc.size, chip->ecc.strength, chip->ecc.bytes);
 
-   iowrite32(MAKE_ECC_CORRECTION(chip->ecc.strength, 1),
+   iowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD, 1) |
+ FIELD_PREP(ECC_CORRECTION__VALUE, chip->ecc.strength),
  denali->reg + ECC_CORRECTION);
iowrite32(mtd->erasesize / mtd->writesize,
  denali->reg + PAGES_PER_BLOCK);
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index dc3f970..73aad3a 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -114,9 +114,6 @@
 #define ECC_CORRECTION 0x1b0
 #define ECC_CORRECTION__VALUE  GENMASK(4, 0)
 #define ECC_CORRECTION__ERASE_THRESHOLDGENMASK(31, 16)
-#define MAKE_ECC_CORRECTION(val, thresh)   \
-   (((val) & (ECC_CORRECTION__VALUE)) | \
-   (((thresh) << 16) & (ECC_CORRECTION__ERASE_THRESHOLD)))
 
 #define READ_MODE  0x1c0
 #define READ_MODE__VALUE   GENMASK(3, 0)
@@ -258,13 +255,13 @@
 
 #define ECC_ERROR_ADDRESS  0x630
 #define ECC_ERROR_ADDRESS__OFFSET  GENMASK(11, 0)
-#define ECC_ERROR_ADDRESS__SECTOR_NR   GENMASK(15, 12)
+#define ECC_ERROR_ADDRESS__SECTOR  GENMASK(15, 12)
 
 #define ERR_CORRECTION_INFO0x640
-#define ERR_CORRECTION_INFO__BYTEMASK  

[PATCH v2 12/12] mtd: nand: denali: change the setup_dma choice into hook

2017-09-21 Thread Masahiro Yamada
The previous commit added some hooks into struct denali_nand_info,
so here is one more for clean-up.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 15 +--
 drivers/mtd/nand/denali.h |  2 ++
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 7c24983..0b268ec 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -519,15 +519,6 @@ static void denali_setup_dma32(struct denali_nand_info 
*denali,
denali->host_write(denali, mode | 0x14000, 0x2400);
 }
 
-static void denali_setup_dma(struct denali_nand_info *denali,
-dma_addr_t dma_addr, int page, int write)
-{
-   if (denali->caps & DENALI_CAP_DMA_64BIT)
-   denali_setup_dma64(denali, dma_addr, page, write);
-   else
-   denali_setup_dma32(denali, dma_addr, page, write);
-}
-
 static int denali_pio_read(struct denali_nand_info *denali, void *buf,
   size_t size, int page, int raw)
 {
@@ -619,7 +610,7 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
iowrite32(DMA_ENABLE__FLAG, denali->reg + DMA_ENABLE);
 
denali_reset_irq(denali);
-   denali_setup_dma(denali, dma_addr, page, write);
+   denali->setup_dma(denali, dma_addr, page, write);
 
irq_status = denali_wait_for_irq(denali, irq_mask);
if (!(irq_status & INTR__DMA_CMD_COMP))
@@ -1314,6 +1305,10 @@ int denali_init(struct denali_nand_info *denali)
if (denali->dma_avail) {
chip->options |= NAND_USE_BOUNCE_BUFFER;
chip->buf_align = 16;
+   if (denali->caps & DENALI_CAP_DMA_64BIT)
+   denali->setup_dma = denali_setup_dma64;
+   else
+   denali->setup_dma = denali_setup_dma32;
}
 
chip->bbt_options |= NAND_BBT_USE_FLASH;
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 3aeb272..2911066 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -321,6 +321,8 @@ struct denali_nand_info {
const struct nand_ecc_caps *ecc_caps;
u32 (*host_read)(struct denali_nand_info *denali, u32 addr);
void (*host_write)(struct denali_nand_info *denali, u32 addr, u32 data);
+   void (*setup_dma)(struct denali_nand_info *denali, dma_addr_t dma_addr,
+ int page, int write);
 };
 
 #define DENALI_CAP_HW_ECC_FIXUPBIT(0)
-- 
2.7.4



[PATCH v2 06/12] mtd: nand: denali: clean up macros with

2017-09-21 Thread Masahiro Yamada
All the register offsets and bitfield masks are defined in denali.h,
but the driver code ended up with additional crappy macros such as
MAKE_ECC_CORRECTION(), ECC_SECTOR(), etc.

The reason is apparent - accessing a register field requires mask and
shift pair.  The denali.h only provides mask.  However, defining both
is tedious.

 provides a convenient way to get register fields
only with a single shifted mask.  Now use it.

While I am here, I shortened some macros.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 25 +++--
 drivers/mtd/nand/denali.h | 13 +
 2 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 3cc56de..1525c4e 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -17,6 +17,7 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -386,13 +387,6 @@ static int denali_hw_ecc_fixup(struct mtd_info *mtd,
return max_bitflips;
 }
 
-#define ECC_SECTOR(x)  (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12)
-#define ECC_BYTE(x)(((x) & ECC_ERROR_ADDRESS__OFFSET))
-#define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK)
-#define ECC_ERROR_UNCORRECTABLE(x) ((x) & ERR_CORRECTION_INFO__ERROR_TYPE)
-#define ECC_ERR_DEVICE(x)  (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8)
-#define ECC_LAST_ERR(x)((x) & 
ERR_CORRECTION_INFO__LAST_ERR_INFO)
-
 static int denali_sw_ecc_fixup(struct mtd_info *mtd,
   struct denali_nand_info *denali,
   unsigned long *uncor_ecc_flags, uint8_t *buf)
@@ -410,18 +404,20 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
 
do {
err_addr = ioread32(denali->reg + ECC_ERROR_ADDRESS);
-   err_sector = ECC_SECTOR(err_addr);
-   err_byte = ECC_BYTE(err_addr);
+   err_sector = FIELD_GET(ECC_ERROR_ADDRESS__SECTOR, err_addr);
+   err_byte = FIELD_GET(ECC_ERROR_ADDRESS__OFFSET, err_addr);
 
err_cor_info = ioread32(denali->reg + ERR_CORRECTION_INFO);
-   err_cor_value = ECC_CORRECTION_VALUE(err_cor_info);
-   err_device = ECC_ERR_DEVICE(err_cor_info);
+   err_cor_value = FIELD_GET(ERR_CORRECTION_INFO__BYTE,
+ err_cor_info);
+   err_device = FIELD_GET(ERR_CORRECTION_INFO__DEVICE,
+  err_cor_info);
 
/* reset the bitflip counter when crossing ECC sector */
if (err_sector != prev_sector)
bitflips = 0;
 
-   if (ECC_ERROR_UNCORRECTABLE(err_cor_info)) {
+   if (err_cor_info & ERR_CORRECTION_INFO__UNCOR) {
/*
 * Check later if this is a real ECC error, or
 * an erased sector.
@@ -451,7 +447,7 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
}
 
prev_sector = err_sector;
-   } while (!ECC_LAST_ERR(err_cor_info));
+   } while (!(err_cor_info & ERR_CORRECTION_INFO__LAST_ERR));
 
/*
 * Once handle all ecc errors, controller will trigger a
@@ -1351,7 +1347,8 @@ int denali_init(struct denali_nand_info *denali)
"chosen ECC settings: step=%d, strength=%d, bytes=%d\n",
chip->ecc.size, chip->ecc.strength, chip->ecc.bytes);
 
-   iowrite32(MAKE_ECC_CORRECTION(chip->ecc.strength, 1),
+   iowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD, 1) |
+ FIELD_PREP(ECC_CORRECTION__VALUE, chip->ecc.strength),
  denali->reg + ECC_CORRECTION);
iowrite32(mtd->erasesize / mtd->writesize,
  denali->reg + PAGES_PER_BLOCK);
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index dc3f970..73aad3a 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -114,9 +114,6 @@
 #define ECC_CORRECTION 0x1b0
 #define ECC_CORRECTION__VALUE  GENMASK(4, 0)
 #define ECC_CORRECTION__ERASE_THRESHOLDGENMASK(31, 16)
-#define MAKE_ECC_CORRECTION(val, thresh)   \
-   (((val) & (ECC_CORRECTION__VALUE)) | \
-   (((thresh) << 16) & (ECC_CORRECTION__ERASE_THRESHOLD)))
 
 #define READ_MODE  0x1c0
 #define READ_MODE__VALUE   GENMASK(3, 0)
@@ -258,13 +255,13 @@
 
 #define ECC_ERROR_ADDRESS  0x630
 #define ECC_ERROR_ADDRESS__OFFSET  GENMASK(11, 0)
-#define ECC_ERROR_ADDRESS__SECTOR_NR   GENMASK(15, 12)
+#define ECC_ERROR_ADDRESS__SECTOR  GENMASK(15, 12)
 
 #define ERR_CORRECTION_INFO0x640
-#define ERR_CORRECTION_INFO__BYTEMASK  GENMASK(7, 0)
-#define 

[PATCH v2 08/12] mtd: nand: denali: clean up comments

2017-09-21 Thread Masahiro Yamada
This driver explains too much about what is apparent from the code.

Comments around basic APIs such as init_completion(), spin_lock_init(),
etc. seem unneeded lessons to kernel developers.
(With those comments dropped, denali_drv_init() is small enough,
so it has been merged into the probe function.)

Also, NAND driver developers should know the NAND init procedure, so
there is no need to explain nand_scan_ident/tail.

I removed FSF's address from the license blocks, and added simple
comments to struct members.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Add more comments to struct members

 drivers/mtd/nand/denali.c | 52 +--
 drivers/mtd/nand/denali.h | 24 +++-
 drivers/mtd/nand/denali_dt.c  |  1 -
 drivers/mtd/nand/denali_pci.c |  2 --
 4 files changed, 13 insertions(+), 66 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index ca98015..02ce310 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -10,11 +10,6 @@
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 
 #include 
@@ -64,10 +59,6 @@ MODULE_LICENSE("GPL");
  */
 #define DENALI_CLK_X_MULT  6
 
-/*
- * this macro allows us to convert from an MTD structure to our own
- * device context (denali) structure.
- */
 static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd)
 {
return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
@@ -450,9 +441,8 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
} while (!(err_cor_info & ERR_CORRECTION_INFO__LAST_ERR));
 
/*
-* Once handle all ecc errors, controller will trigger a
-* ECC_TRANSACTION_DONE interrupt, so here just wait for
-* a while for this interrupt
+* Once handle all ECC errors, controller will trigger an
+* ECC_TRANSACTION_DONE interrupt.
 */
irq_status = denali_wait_for_irq(denali, INTR__ECC_TRANSACTION_DONE);
if (!(irq_status & INTR__ECC_TRANSACTION_DONE))
@@ -613,7 +603,6 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
denali_reset_irq(denali);
denali_setup_dma(denali, dma_addr, page, write);
 
-   /* wait for operation to complete */
irq_status = denali_wait_for_irq(denali, irq_mask);
if (!(irq_status & INTR__DMA_CMD_COMP))
ret = -EIO;
@@ -1185,22 +1174,6 @@ static const struct mtd_ooblayout_ops 
denali_ooblayout_ops = {
.free = denali_ooblayout_free,
 };
 
-/* initialize driver data structures */
-static void denali_drv_init(struct denali_nand_info *denali)
-{
-   /*
-* the completion object will be used to notify
-* the callee that the interrupt is done
-*/
-   init_completion(>complete);
-
-   /*
-* the spinlock will be used to synchronize the ISR with any
-* element that might be access shared data (interrupt status)
-*/
-   spin_lock_init(>irq_lock);
-}
-
 static int denali_multidev_fixup(struct denali_nand_info *denali)
 {
struct nand_chip *chip = >nand;
@@ -1260,11 +1233,12 @@ int denali_init(struct denali_nand_info *denali)
 
mtd->dev.parent = denali->dev;
denali_hw_init(denali);
-   denali_drv_init(denali);
+
+   init_completion(>complete);
+   spin_lock_init(>irq_lock);
 
denali_clear_irq_all(denali);
 
-   /* Request IRQ after all the hardware initialization is finished */
ret = devm_request_irq(denali->dev, denali->irq, denali_isr,
   IRQF_SHARED, DENALI_NAND_NAME, denali);
if (ret) {
@@ -1282,7 +1256,6 @@ int denali_init(struct denali_nand_info *denali)
if (!mtd->name)
mtd->name = "denali-nand";
 
-   /* register the driver with the NAND core subsystem */
chip->select_chip = denali_select_chip;
chip->read_byte = denali_read_byte;
chip->write_byte = denali_write_byte;
@@ -1295,11 +1268,6 @@ int denali_init(struct denali_nand_info *denali)
if (denali->clk_x_rate)
chip->setup_data_interface = denali_setup_data_interface;
 
-   /*
-* scan for NAND devices attached to the controller
-* this is the first stage in a two step process to register
-* with the nand subsystem
-*/
ret = nand_scan_ident(mtd, denali->max_banks, NULL);
if (ret)
goto disable_irq;
@@ -1323,18 +1291,9 @@ int denali_init(struct denali_nand_info *denali)
chip->buf_align = 16;
}
 
-   /*
- 

[PATCH v2 08/12] mtd: nand: denali: clean up comments

2017-09-21 Thread Masahiro Yamada
This driver explains too much about what is apparent from the code.

Comments around basic APIs such as init_completion(), spin_lock_init(),
etc. seem unneeded lessons to kernel developers.
(With those comments dropped, denali_drv_init() is small enough,
so it has been merged into the probe function.)

Also, NAND driver developers should know the NAND init procedure, so
there is no need to explain nand_scan_ident/tail.

I removed FSF's address from the license blocks, and added simple
comments to struct members.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Add more comments to struct members

 drivers/mtd/nand/denali.c | 52 +--
 drivers/mtd/nand/denali.h | 24 +++-
 drivers/mtd/nand/denali_dt.c  |  1 -
 drivers/mtd/nand/denali_pci.c |  2 --
 4 files changed, 13 insertions(+), 66 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index ca98015..02ce310 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -10,11 +10,6 @@
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 
 #include 
@@ -64,10 +59,6 @@ MODULE_LICENSE("GPL");
  */
 #define DENALI_CLK_X_MULT  6
 
-/*
- * this macro allows us to convert from an MTD structure to our own
- * device context (denali) structure.
- */
 static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd)
 {
return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
@@ -450,9 +441,8 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
} while (!(err_cor_info & ERR_CORRECTION_INFO__LAST_ERR));
 
/*
-* Once handle all ecc errors, controller will trigger a
-* ECC_TRANSACTION_DONE interrupt, so here just wait for
-* a while for this interrupt
+* Once handle all ECC errors, controller will trigger an
+* ECC_TRANSACTION_DONE interrupt.
 */
irq_status = denali_wait_for_irq(denali, INTR__ECC_TRANSACTION_DONE);
if (!(irq_status & INTR__ECC_TRANSACTION_DONE))
@@ -613,7 +603,6 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
denali_reset_irq(denali);
denali_setup_dma(denali, dma_addr, page, write);
 
-   /* wait for operation to complete */
irq_status = denali_wait_for_irq(denali, irq_mask);
if (!(irq_status & INTR__DMA_CMD_COMP))
ret = -EIO;
@@ -1185,22 +1174,6 @@ static const struct mtd_ooblayout_ops 
denali_ooblayout_ops = {
.free = denali_ooblayout_free,
 };
 
-/* initialize driver data structures */
-static void denali_drv_init(struct denali_nand_info *denali)
-{
-   /*
-* the completion object will be used to notify
-* the callee that the interrupt is done
-*/
-   init_completion(>complete);
-
-   /*
-* the spinlock will be used to synchronize the ISR with any
-* element that might be access shared data (interrupt status)
-*/
-   spin_lock_init(>irq_lock);
-}
-
 static int denali_multidev_fixup(struct denali_nand_info *denali)
 {
struct nand_chip *chip = >nand;
@@ -1260,11 +1233,12 @@ int denali_init(struct denali_nand_info *denali)
 
mtd->dev.parent = denali->dev;
denali_hw_init(denali);
-   denali_drv_init(denali);
+
+   init_completion(>complete);
+   spin_lock_init(>irq_lock);
 
denali_clear_irq_all(denali);
 
-   /* Request IRQ after all the hardware initialization is finished */
ret = devm_request_irq(denali->dev, denali->irq, denali_isr,
   IRQF_SHARED, DENALI_NAND_NAME, denali);
if (ret) {
@@ -1282,7 +1256,6 @@ int denali_init(struct denali_nand_info *denali)
if (!mtd->name)
mtd->name = "denali-nand";
 
-   /* register the driver with the NAND core subsystem */
chip->select_chip = denali_select_chip;
chip->read_byte = denali_read_byte;
chip->write_byte = denali_write_byte;
@@ -1295,11 +1268,6 @@ int denali_init(struct denali_nand_info *denali)
if (denali->clk_x_rate)
chip->setup_data_interface = denali_setup_data_interface;
 
-   /*
-* scan for NAND devices attached to the controller
-* this is the first stage in a two step process to register
-* with the nand subsystem
-*/
ret = nand_scan_ident(mtd, denali->max_banks, NULL);
if (ret)
goto disable_irq;
@@ -1323,18 +1291,9 @@ int denali_init(struct denali_nand_info *denali)
chip->buf_align = 16;
}
 
-   /*
-* second stage of the 

[PATCH v2 11/12] mtd: nand: denali: support direct addressing mode

2017-09-21 Thread Masahiro Yamada
The Denali NAND IP core decodes the lower 28 bits of the slave address
to get the control information; bit[27:26]=mode, bit[25:24]=bank, etc.
This means 256MB address range must be allocated for this IP.  (Direct
Addressing)

For systems with address space limitation, the Denali IP provides an
optional module that translates the addressing - address and data are
latched by the registers in the translation module. (Indexed Addressing)

The addressing mode can be selected when the delivered RTL is configured,
and it can be read out from the FEATURES register.

Most of SoC vendors would choose Indexed Addressing to save the address
space, but Direct Addressing is possible as well, and it can be easily
supported by adding ->host_{read,write} hooks.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 109 +-
 drivers/mtd/nand/denali.h |   2 +
 2 files changed, 70 insertions(+), 41 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index ee688e0..7c24983 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -29,9 +29,9 @@ MODULE_LICENSE("GPL");
 
 #define DENALI_NAND_NAME"denali-nand"
 
-/* Host Data/Command Interface */
-#define DENALI_HOST_ADDR   0x00
-#define DENALI_HOST_DATA   0x10
+/* for Indexed Addressing */
+#define DENALI_INDEXED_CTRL0x00
+#define DENALI_INDEXED_DATA0x10
 
 #define DENALI_MAP00   (0 << 26)   /* direct access to buffer */
 #define DENALI_MAP01   (1 << 26)   /* read/write pages in PIO */
@@ -64,11 +64,39 @@ static inline struct denali_nand_info *mtd_to_denali(struct 
mtd_info *mtd)
return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
 }
 
-static void denali_host_write(struct denali_nand_info *denali,
- uint32_t addr, uint32_t data)
+/*
+ * Direct Addressing - the slave address forms the control information (command
+ * type, bank, block, and page address).  The slave data is the actual data to
+ * be transferred.  This mode requires 28 bits of address region allocated.
+ */
+static u32 denali_direct_read(struct denali_nand_info *denali, u32 addr)
+{
+   return ioread32(denali->host + addr);
+}
+
+static void denali_direct_write(struct denali_nand_info *denali, u32 addr,
+   u32 data)
+{
+   iowrite32(data, denali->host + addr);
+}
+
+/*
+ * Indexed Addressing - address translation module intervenes in passing the
+ * control information.  This mode reduces the required address range.  The
+ * control information and transferred data are latched by the registers in
+ * the translation module.
+ */
+static u32 denali_indexed_read(struct denali_nand_info *denali, u32 addr)
 {
-   iowrite32(addr, denali->host + DENALI_HOST_ADDR);
-   iowrite32(data, denali->host + DENALI_HOST_DATA);
+   iowrite32(addr, denali->host + DENALI_INDEXED_CTRL);
+   return ioread32(denali->host + DENALI_INDEXED_DATA);
+}
+
+static void denali_indexed_write(struct denali_nand_info *denali, u32 addr,
+u32 data)
+{
+   iowrite32(addr, denali->host + DENALI_INDEXED_CTRL);
+   iowrite32(data, denali->host + DENALI_INDEXED_DATA);
 }
 
 /*
@@ -205,52 +233,44 @@ static uint32_t denali_check_irq(struct denali_nand_info 
*denali)
 static void denali_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
+   u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali);
int i;
 
-   iowrite32(DENALI_MAP11_DATA | DENALI_BANK(denali),
- denali->host + DENALI_HOST_ADDR);
-
for (i = 0; i < len; i++)
-   buf[i] = ioread32(denali->host + DENALI_HOST_DATA);
+   buf[i] = denali->host_read(denali, addr);
 }
 
 static void denali_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
+   u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali);
int i;
 
-   iowrite32(DENALI_MAP11_DATA | DENALI_BANK(denali),
- denali->host + DENALI_HOST_ADDR);
-
for (i = 0; i < len; i++)
-   iowrite32(buf[i], denali->host + DENALI_HOST_DATA);
+   denali->host_write(denali, addr, buf[i]);
 }
 
 static void denali_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
+   u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali);
uint16_t *buf16 = (uint16_t *)buf;
int i;
 
-   iowrite32(DENALI_MAP11_DATA | DENALI_BANK(denali),
- denali->host + DENALI_HOST_ADDR);
-
for (i = 0; i < len / 2; i++)
-   buf16[i] = ioread32(denali->host + DENALI_HOST_DATA);
+   buf16[i] = denali->host_read(denali, addr);
 }
 
 static void 

[PATCH v2 11/12] mtd: nand: denali: support direct addressing mode

2017-09-21 Thread Masahiro Yamada
The Denali NAND IP core decodes the lower 28 bits of the slave address
to get the control information; bit[27:26]=mode, bit[25:24]=bank, etc.
This means 256MB address range must be allocated for this IP.  (Direct
Addressing)

For systems with address space limitation, the Denali IP provides an
optional module that translates the addressing - address and data are
latched by the registers in the translation module. (Indexed Addressing)

The addressing mode can be selected when the delivered RTL is configured,
and it can be read out from the FEATURES register.

Most of SoC vendors would choose Indexed Addressing to save the address
space, but Direct Addressing is possible as well, and it can be easily
supported by adding ->host_{read,write} hooks.

Signed-off-by: Masahiro Yamada 
---

Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 109 +-
 drivers/mtd/nand/denali.h |   2 +
 2 files changed, 70 insertions(+), 41 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index ee688e0..7c24983 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -29,9 +29,9 @@ MODULE_LICENSE("GPL");
 
 #define DENALI_NAND_NAME"denali-nand"
 
-/* Host Data/Command Interface */
-#define DENALI_HOST_ADDR   0x00
-#define DENALI_HOST_DATA   0x10
+/* for Indexed Addressing */
+#define DENALI_INDEXED_CTRL0x00
+#define DENALI_INDEXED_DATA0x10
 
 #define DENALI_MAP00   (0 << 26)   /* direct access to buffer */
 #define DENALI_MAP01   (1 << 26)   /* read/write pages in PIO */
@@ -64,11 +64,39 @@ static inline struct denali_nand_info *mtd_to_denali(struct 
mtd_info *mtd)
return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand);
 }
 
-static void denali_host_write(struct denali_nand_info *denali,
- uint32_t addr, uint32_t data)
+/*
+ * Direct Addressing - the slave address forms the control information (command
+ * type, bank, block, and page address).  The slave data is the actual data to
+ * be transferred.  This mode requires 28 bits of address region allocated.
+ */
+static u32 denali_direct_read(struct denali_nand_info *denali, u32 addr)
+{
+   return ioread32(denali->host + addr);
+}
+
+static void denali_direct_write(struct denali_nand_info *denali, u32 addr,
+   u32 data)
+{
+   iowrite32(data, denali->host + addr);
+}
+
+/*
+ * Indexed Addressing - address translation module intervenes in passing the
+ * control information.  This mode reduces the required address range.  The
+ * control information and transferred data are latched by the registers in
+ * the translation module.
+ */
+static u32 denali_indexed_read(struct denali_nand_info *denali, u32 addr)
 {
-   iowrite32(addr, denali->host + DENALI_HOST_ADDR);
-   iowrite32(data, denali->host + DENALI_HOST_DATA);
+   iowrite32(addr, denali->host + DENALI_INDEXED_CTRL);
+   return ioread32(denali->host + DENALI_INDEXED_DATA);
+}
+
+static void denali_indexed_write(struct denali_nand_info *denali, u32 addr,
+u32 data)
+{
+   iowrite32(addr, denali->host + DENALI_INDEXED_CTRL);
+   iowrite32(data, denali->host + DENALI_INDEXED_DATA);
 }
 
 /*
@@ -205,52 +233,44 @@ static uint32_t denali_check_irq(struct denali_nand_info 
*denali)
 static void denali_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
+   u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali);
int i;
 
-   iowrite32(DENALI_MAP11_DATA | DENALI_BANK(denali),
- denali->host + DENALI_HOST_ADDR);
-
for (i = 0; i < len; i++)
-   buf[i] = ioread32(denali->host + DENALI_HOST_DATA);
+   buf[i] = denali->host_read(denali, addr);
 }
 
 static void denali_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
+   u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali);
int i;
 
-   iowrite32(DENALI_MAP11_DATA | DENALI_BANK(denali),
- denali->host + DENALI_HOST_ADDR);
-
for (i = 0; i < len; i++)
-   iowrite32(buf[i], denali->host + DENALI_HOST_DATA);
+   denali->host_write(denali, addr, buf[i]);
 }
 
 static void denali_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
+   u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali);
uint16_t *buf16 = (uint16_t *)buf;
int i;
 
-   iowrite32(DENALI_MAP11_DATA | DENALI_BANK(denali),
- denali->host + DENALI_HOST_ADDR);
-
for (i = 0; i < len / 2; i++)
-   buf16[i] = ioread32(denali->host + DENALI_HOST_DATA);
+   buf16[i] = denali->host_read(denali, addr);
 }
 
 static void denali_write_buf16(struct mtd_info *mtd, const 

[PATCH v2 01/12] mtd: nand: denali: squash setup_ecc_for_xfer() helper into caller

2017-09-21 Thread Masahiro Yamada
The setup_ecc_for_xfer() is only called from denali_data_xfer().
This helper is small enough, so squash it into the caller.
This looks cleaner to me.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 22 +++---
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index aefdc83..d847ae4 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -208,24 +208,6 @@ static uint32_t denali_check_irq(struct denali_nand_info 
*denali)
return irq_status;
 }
 
-/*
- * This helper function setups the registers for ECC and whether or not
- * the spare area will be transferred.
- */
-static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en,
-   bool transfer_spare)
-{
-   int ecc_en_flag, transfer_spare_flag;
-
-   /* set ECC, transfer spare bits if needed */
-   ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0;
-   transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0;
-
-   /* Enable spare area/ECC per user's request. */
-   iowrite32(ecc_en_flag, denali->reg + ECC_ENABLE);
-   iowrite32(transfer_spare_flag, denali->reg + TRANSFER_SPARE_REG);
-}
-
 static void denali_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
@@ -659,7 +641,9 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
 static int denali_data_xfer(struct denali_nand_info *denali, void *buf,
size_t size, int page, int raw, int write)
 {
-   setup_ecc_for_xfer(denali, !raw, raw);
+   iowrite32(raw ? 0 : ECC_ENABLE__FLAG, denali->reg + ECC_ENABLE);
+   iowrite32(raw ? TRANSFER_SPARE_REG__FLAG : 0,
+ denali->reg + TRANSFER_SPARE_REG);
 
if (denali->dma_avail)
return denali_dma_xfer(denali, buf, size, page, raw, write);
-- 
2.7.4



[PATCH v2 01/12] mtd: nand: denali: squash setup_ecc_for_xfer() helper into caller

2017-09-21 Thread Masahiro Yamada
The setup_ecc_for_xfer() is only called from denali_data_xfer().
This helper is small enough, so squash it into the caller.
This looks cleaner to me.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 22 +++---
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index aefdc83..d847ae4 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -208,24 +208,6 @@ static uint32_t denali_check_irq(struct denali_nand_info 
*denali)
return irq_status;
 }
 
-/*
- * This helper function setups the registers for ECC and whether or not
- * the spare area will be transferred.
- */
-static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en,
-   bool transfer_spare)
-{
-   int ecc_en_flag, transfer_spare_flag;
-
-   /* set ECC, transfer spare bits if needed */
-   ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0;
-   transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0;
-
-   /* Enable spare area/ECC per user's request. */
-   iowrite32(ecc_en_flag, denali->reg + ECC_ENABLE);
-   iowrite32(transfer_spare_flag, denali->reg + TRANSFER_SPARE_REG);
-}
-
 static void denali_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
struct denali_nand_info *denali = mtd_to_denali(mtd);
@@ -659,7 +641,9 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
 static int denali_data_xfer(struct denali_nand_info *denali, void *buf,
size_t size, int page, int raw, int write)
 {
-   setup_ecc_for_xfer(denali, !raw, raw);
+   iowrite32(raw ? 0 : ECC_ENABLE__FLAG, denali->reg + ECC_ENABLE);
+   iowrite32(raw ? TRANSFER_SPARE_REG__FLAG : 0,
+ denali->reg + TRANSFER_SPARE_REG);
 
if (denali->dma_avail)
return denali_dma_xfer(denali, buf, size, page, raw, write);
-- 
2.7.4



[PATCH v2 03/12] mtd: nand: denali: consolidate include directives

2017-09-21 Thread Masahiro Yamada
Include necessary headers explicitly without relying on indirect
header inclusion.  Also, sort them alphabetically.

, ,  turned out bogus,
so removed.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 12 +++-
 drivers/mtd/nand/denali.h |  3 +++
 drivers/mtd/nand/denali_dt.c  |  3 ++-
 drivers/mtd/nand/denali_pci.c |  3 +++
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 48193f9..4daeb7f 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -16,14 +16,16 @@
  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  *
  */
-#include 
-#include 
+
+#include 
 #include 
-#include 
-#include 
-#include 
+#include 
+#include 
 #include 
+#include 
+#include 
 #include 
+#include 
 
 #include "denali.h"
 
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 9239e67..dc3f970 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -21,7 +21,10 @@
 #define __DENALI_H__
 
 #include 
+#include 
 #include 
+#include 
+#include 
 
 #define DEVICE_RESET   0x0
 #define DEVICE_RESET__BANK(bank)   BIT(bank)
diff --git a/drivers/mtd/nand/denali_dt.c b/drivers/mtd/nand/denali_dt.c
index 56e2e17..01e0100 100644
--- a/drivers/mtd/nand/denali_dt.c
+++ b/drivers/mtd/nand/denali_dt.c
@@ -12,15 +12,16 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  */
+
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
 
 #include "denali.h"
 
diff --git a/drivers/mtd/nand/denali_pci.c b/drivers/mtd/nand/denali_pci.c
index 81370c7..7d5600b 100644
--- a/drivers/mtd/nand/denali_pci.c
+++ b/drivers/mtd/nand/denali_pci.c
@@ -11,6 +11,9 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  */
+
+#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.7.4



[PATCH v2 05/12] mtd: nand: denali: slight clean up of denali_wait_for_irq()

2017-09-21 Thread Masahiro Yamada
This function has a local variable "irq_mask" and its value is
the same as denali->irq_mask.  Clean up the code a little.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index e7b25de..3cc56de 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -191,7 +191,7 @@ static uint32_t denali_wait_for_irq(struct denali_nand_info 
*denali,
msecs_to_jiffies(1000));
if (!time_left) {
dev_err(denali->dev, "timeout while waiting for irq 0x%x\n",
-   denali->irq_mask);
+   irq_mask);
return 0;
}
 
-- 
2.7.4



[PATCH v2 03/12] mtd: nand: denali: consolidate include directives

2017-09-21 Thread Masahiro Yamada
Include necessary headers explicitly without relying on indirect
header inclusion.  Also, sort them alphabetically.

, ,  turned out bogus,
so removed.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 12 +++-
 drivers/mtd/nand/denali.h |  3 +++
 drivers/mtd/nand/denali_dt.c  |  3 ++-
 drivers/mtd/nand/denali_pci.c |  3 +++
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 48193f9..4daeb7f 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -16,14 +16,16 @@
  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  *
  */
-#include 
-#include 
+
+#include 
 #include 
-#include 
-#include 
-#include 
+#include 
+#include 
 #include 
+#include 
+#include 
 #include 
+#include 
 
 #include "denali.h"
 
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 9239e67..dc3f970 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -21,7 +21,10 @@
 #define __DENALI_H__
 
 #include 
+#include 
 #include 
+#include 
+#include 
 
 #define DEVICE_RESET   0x0
 #define DEVICE_RESET__BANK(bank)   BIT(bank)
diff --git a/drivers/mtd/nand/denali_dt.c b/drivers/mtd/nand/denali_dt.c
index 56e2e17..01e0100 100644
--- a/drivers/mtd/nand/denali_dt.c
+++ b/drivers/mtd/nand/denali_dt.c
@@ -12,15 +12,16 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  */
+
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
 
 #include "denali.h"
 
diff --git a/drivers/mtd/nand/denali_pci.c b/drivers/mtd/nand/denali_pci.c
index 81370c7..7d5600b 100644
--- a/drivers/mtd/nand/denali_pci.c
+++ b/drivers/mtd/nand/denali_pci.c
@@ -11,6 +11,9 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  */
+
+#include 
+#include 
 #include 
 #include 
 #include 
-- 
2.7.4



[PATCH v2 05/12] mtd: nand: denali: slight clean up of denali_wait_for_irq()

2017-09-21 Thread Masahiro Yamada
This function has a local variable "irq_mask" and its value is
the same as denali->irq_mask.  Clean up the code a little.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index e7b25de..3cc56de 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -191,7 +191,7 @@ static uint32_t denali_wait_for_irq(struct denali_nand_info 
*denali,
msecs_to_jiffies(1000));
if (!time_left) {
dev_err(denali->dev, "timeout while waiting for irq 0x%x\n",
-   denali->irq_mask);
+   irq_mask);
return 0;
}
 
-- 
2.7.4



[PATCH v2 04/12] mtd: nand: denali: squash denali_enable_dma() helper into caller

2017-09-21 Thread Masahiro Yamada
This helper just sets/clears a flag of DMA_ENABLE register (with
register read-back, I do not know why it is necessary).

Move the register write code to the caller, and remove the helper.
It works for me without the register read-back.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 4daeb7f..e7b25de 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -465,13 +465,6 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
return max_bitflips;
 }
 
-/* programs the controller to either enable/disable DMA transfers */
-static void denali_enable_dma(struct denali_nand_info *denali, bool en)
-{
-   iowrite32(en ? DMA_ENABLE__FLAG : 0, denali->reg + DMA_ENABLE);
-   ioread32(denali->reg + DMA_ENABLE);
-}
-
 static void denali_setup_dma64(struct denali_nand_info *denali,
   dma_addr_t dma_addr, int page, int write)
 {
@@ -619,7 +612,7 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
ecc_err_mask = INTR__ECC_ERR;
}
 
-   denali_enable_dma(denali, true);
+   iowrite32(DMA_ENABLE__FLAG, denali->reg + DMA_ENABLE);
 
denali_reset_irq(denali);
denali_setup_dma(denali, dma_addr, page, write);
@@ -631,7 +624,8 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
else if (irq_status & ecc_err_mask)
ret = -EBADMSG;
 
-   denali_enable_dma(denali, false);
+   iowrite32(0, denali->reg + DMA_ENABLE);
+
dma_unmap_single(denali->dev, dma_addr, size, dir);
 
if (irq_status & INTR__ERASED_PAGE)
-- 
2.7.4



[PATCH v2 04/12] mtd: nand: denali: squash denali_enable_dma() helper into caller

2017-09-21 Thread Masahiro Yamada
This helper just sets/clears a flag of DMA_ENABLE register (with
register read-back, I do not know why it is necessary).

Move the register write code to the caller, and remove the helper.
It works for me without the register read-back.

Signed-off-by: Masahiro Yamada 
---

Changes in v2: None

 drivers/mtd/nand/denali.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 4daeb7f..e7b25de 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -465,13 +465,6 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,
return max_bitflips;
 }
 
-/* programs the controller to either enable/disable DMA transfers */
-static void denali_enable_dma(struct denali_nand_info *denali, bool en)
-{
-   iowrite32(en ? DMA_ENABLE__FLAG : 0, denali->reg + DMA_ENABLE);
-   ioread32(denali->reg + DMA_ENABLE);
-}
-
 static void denali_setup_dma64(struct denali_nand_info *denali,
   dma_addr_t dma_addr, int page, int write)
 {
@@ -619,7 +612,7 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
ecc_err_mask = INTR__ECC_ERR;
}
 
-   denali_enable_dma(denali, true);
+   iowrite32(DMA_ENABLE__FLAG, denali->reg + DMA_ENABLE);
 
denali_reset_irq(denali);
denali_setup_dma(denali, dma_addr, page, write);
@@ -631,7 +624,8 @@ static int denali_dma_xfer(struct denali_nand_info *denali, 
void *buf,
else if (irq_status & ecc_err_mask)
ret = -EBADMSG;
 
-   denali_enable_dma(denali, false);
+   iowrite32(0, denali->reg + DMA_ENABLE);
+
dma_unmap_single(denali->dev, dma_addr, size, dir);
 
if (irq_status & INTR__ERASED_PAGE)
-- 
2.7.4



[PATCH v2 00/12] mtd: nand: denali: more clean-ups

2017-09-21 Thread Masahiro Yamada

This series make the Denali driver even cleaner and more correct.


Masahiro Yamada (12):
  mtd: nand: denali: squash setup_ecc_for_xfer() helper into caller
  mtd: nand: denali: prefix detect_max_banks() with denali_
  mtd: nand: denali: consolidate include directives
  mtd: nand: denali: squash denali_enable_dma() helper into caller
  mtd: nand: denali: slight clean up of denali_wait_for_irq()
  mtd: nand: denali: clean up macros with 
  mtd: nand: denali: use more FIELD_PREP / FIELD_GET where appropriate
  mtd: nand: denali: clean up comments
  mtd: nand: denali: use upper/lower_32_bits() macro for clean-up
  mtd: nand: denali: remove unneeded init of ECC_ENABLE register
  mtd: nand: denali: support direct addressing mode
  mtd: nand: denali: change the setup_dma choice into hook

 drivers/mtd/nand/denali.c | 277 ++
 drivers/mtd/nand/denali.h |  44 +++
 drivers/mtd/nand/denali_dt.c  |   4 +-
 drivers/mtd/nand/denali_pci.c |   5 +-
 4 files changed, 141 insertions(+), 189 deletions(-)

-- 
2.7.4



[PATCH v2 10/12] mtd: nand: denali: remove unneeded init of ECC_ENABLE register

2017-09-21 Thread Masahiro Yamada
The ECC correction is properly enabled/disabled before the page
read/write.  There is no need to set up this at the beginning of
the probe.

Signed-off-by: Masahiro Yamada 
---

This patch may cause a conflict
unless  http://patchwork.ozlabs.org/patch/813125/ is applied first.


Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index e567ad9..ee688e0 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1101,8 +1101,6 @@ static void denali_hw_init(struct denali_nand_info 
*denali)
iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE);
 
iowrite32(0x, denali->reg + SPARE_AREA_MARKER);
-
-   iowrite32(1, denali->reg + ECC_ENABLE);
 }
 
 int denali_calc_ecc_bytes(int step_size, int strength)
-- 
2.7.4



[PATCH v2 00/12] mtd: nand: denali: more clean-ups

2017-09-21 Thread Masahiro Yamada

This series make the Denali driver even cleaner and more correct.


Masahiro Yamada (12):
  mtd: nand: denali: squash setup_ecc_for_xfer() helper into caller
  mtd: nand: denali: prefix detect_max_banks() with denali_
  mtd: nand: denali: consolidate include directives
  mtd: nand: denali: squash denali_enable_dma() helper into caller
  mtd: nand: denali: slight clean up of denali_wait_for_irq()
  mtd: nand: denali: clean up macros with 
  mtd: nand: denali: use more FIELD_PREP / FIELD_GET where appropriate
  mtd: nand: denali: clean up comments
  mtd: nand: denali: use upper/lower_32_bits() macro for clean-up
  mtd: nand: denali: remove unneeded init of ECC_ENABLE register
  mtd: nand: denali: support direct addressing mode
  mtd: nand: denali: change the setup_dma choice into hook

 drivers/mtd/nand/denali.c | 277 ++
 drivers/mtd/nand/denali.h |  44 +++
 drivers/mtd/nand/denali_dt.c  |   4 +-
 drivers/mtd/nand/denali_pci.c |   5 +-
 4 files changed, 141 insertions(+), 189 deletions(-)

-- 
2.7.4



[PATCH v2 10/12] mtd: nand: denali: remove unneeded init of ECC_ENABLE register

2017-09-21 Thread Masahiro Yamada
The ECC correction is properly enabled/disabled before the page
read/write.  There is no need to set up this at the beginning of
the probe.

Signed-off-by: Masahiro Yamada 
---

This patch may cause a conflict
unless  http://patchwork.ozlabs.org/patch/813125/ is applied first.


Changes in v2:
  - Newly added

 drivers/mtd/nand/denali.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index e567ad9..ee688e0 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -1101,8 +1101,6 @@ static void denali_hw_init(struct denali_nand_info 
*denali)
iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE);
 
iowrite32(0x, denali->reg + SPARE_AREA_MARKER);
-
-   iowrite32(1, denali->reg + ECC_ENABLE);
 }
 
 int denali_calc_ecc_bytes(int step_size, int strength)
-- 
2.7.4



Re: [PATCH net-next 01/10] net: hns3: Support for dynamically assigning tx buffer to TC

2017-09-21 Thread David Miller
From: Yunsheng Lin 
Date: Fri, 22 Sep 2017 09:57:31 +0800

> Hi, David
> 
> On 2017/9/22 9:41, David Miller wrote:
>> From: Yunsheng Lin 
>> Date: Thu, 21 Sep 2017 19:21:44 +0800
>> 
>>> @@ -1324,23 +1324,28 @@ static int hclge_alloc_vport(struct hclge_dev *hdev)
>>> return 0;
>>>  }
>>>  
>>> -static int  hclge_cmd_alloc_tx_buff(struct hclge_dev *hdev, u16 buf_size)
>>> +static int  hclge_cmd_alloc_tx_buff(struct hclge_dev *hdev)
>>>  {
>>>  /* TX buffer size is unit by 128 byte */
>>>  #define HCLGE_BUF_SIZE_UNIT_SHIFT  7
>>>  #define HCLGE_BUF_SIZE_UPDATE_EN_MSK   BIT(15)
>>> struct hclge_tx_buff_alloc *req;
>>> +   struct hclge_priv_buf *priv;
>>> struct hclge_desc desc;
>>> +   u32 buf_size;
>>> int ret;
>>> u8 i;
>>>  
>>> req = (struct hclge_tx_buff_alloc *)desc.data;
>>>  
>>> hclge_cmd_setup_basic_desc(, HCLGE_OPC_TX_BUFF_ALLOC, 0);
>>> -   for (i = 0; i < HCLGE_TC_NUM; i++)
>>> +   for (i = 0; i < HCLGE_TC_NUM; i++) {
>>> +   priv = >priv_buf[i];
>>> +   buf_size = priv->tx_buf_size;
>>> req->tx_pkt_buff[i] =
>>> cpu_to_le16((buf_size >> HCLGE_BUF_SIZE_UNIT_SHIFT) |
> 
> buf_size is used here

My bad, I misread the code.

Thanks.


Re: [PATCH net-next 01/10] net: hns3: Support for dynamically assigning tx buffer to TC

2017-09-21 Thread David Miller
From: Yunsheng Lin 
Date: Fri, 22 Sep 2017 09:57:31 +0800

> Hi, David
> 
> On 2017/9/22 9:41, David Miller wrote:
>> From: Yunsheng Lin 
>> Date: Thu, 21 Sep 2017 19:21:44 +0800
>> 
>>> @@ -1324,23 +1324,28 @@ static int hclge_alloc_vport(struct hclge_dev *hdev)
>>> return 0;
>>>  }
>>>  
>>> -static int  hclge_cmd_alloc_tx_buff(struct hclge_dev *hdev, u16 buf_size)
>>> +static int  hclge_cmd_alloc_tx_buff(struct hclge_dev *hdev)
>>>  {
>>>  /* TX buffer size is unit by 128 byte */
>>>  #define HCLGE_BUF_SIZE_UNIT_SHIFT  7
>>>  #define HCLGE_BUF_SIZE_UPDATE_EN_MSK   BIT(15)
>>> struct hclge_tx_buff_alloc *req;
>>> +   struct hclge_priv_buf *priv;
>>> struct hclge_desc desc;
>>> +   u32 buf_size;
>>> int ret;
>>> u8 i;
>>>  
>>> req = (struct hclge_tx_buff_alloc *)desc.data;
>>>  
>>> hclge_cmd_setup_basic_desc(, HCLGE_OPC_TX_BUFF_ALLOC, 0);
>>> -   for (i = 0; i < HCLGE_TC_NUM; i++)
>>> +   for (i = 0; i < HCLGE_TC_NUM; i++) {
>>> +   priv = >priv_buf[i];
>>> +   buf_size = priv->tx_buf_size;
>>> req->tx_pkt_buff[i] =
>>> cpu_to_le16((buf_size >> HCLGE_BUF_SIZE_UNIT_SHIFT) |
> 
> buf_size is used here

My bad, I misread the code.

Thanks.


Re: [PATCH] net: phy: Fix truncation of large IRQ numbers in phy_attached_print()

2017-09-21 Thread David Miller
From: Geert Uytterhoeven 
Date: Thu, 21 Sep 2017 13:27:02 +0200

> Given NR_IRQS is 2048 on sparc64, and even 32784 on alpha, 3 digits is
> not enough to represent interrupt numbers on all architectures.  Hence
> PHY interrupt numbers may be truncated during printing.
> 
> Increase the buffer size from 4 to 8 bytes to fix this.
> 
> Fixes: 5e369aefdce4818c ("net: stmmac: Delete dead code for MDIO 
> registration")
> Signed-off-by: Geert Uytterhoeven 

Applied.


Re: [PATCH] net: phy: Fix truncation of large IRQ numbers in phy_attached_print()

2017-09-21 Thread David Miller
From: Geert Uytterhoeven 
Date: Thu, 21 Sep 2017 13:27:02 +0200

> Given NR_IRQS is 2048 on sparc64, and even 32784 on alpha, 3 digits is
> not enough to represent interrupt numbers on all architectures.  Hence
> PHY interrupt numbers may be truncated during printing.
> 
> Increase the buffer size from 4 to 8 bytes to fix this.
> 
> Fixes: 5e369aefdce4818c ("net: stmmac: Delete dead code for MDIO 
> registration")
> Signed-off-by: Geert Uytterhoeven 

Applied.


[PATCH 3/4] rtc: mediatek: enhance the description for MediaTek PMIC based RTC

2017-09-21 Thread sean.wang
From: Sean Wang 

Give a better description for original MediaTek RTC driver as PMIC based
RTC in order to distinguish SoC based RTC. Also turning all words with
Mediatek to MediaTek here.

Cc: Eddie Huang 
Signed-off-by: Sean Wang 
---
 drivers/rtc/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4226295..4500f77 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1716,14 +1716,14 @@ config RTC_DRV_MEDIATEK
  will be called rtc-mediatek.
 
 config RTC_DRV_MT6397
-   tristate "Mediatek Real Time Clock driver"
+   tristate "MediaTek PMIC based RTC"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
help
- This selects the Mediatek(R) RTC driver. RTC is part of Mediatek
+ This selects the MediaTek(R) RTC driver. RTC is part of MediaTek
  MT6397 PMIC. You should enable MT6397 PMIC MFD before select
- Mediatek(R) RTC driver.
+ MediaTek(R) RTC driver.
 
- If you want to use Mediatek(R) RTC interface, select Y or M here.
+ If you want to use MediaTek(R) RTC interface, select Y or M here.
 
 config RTC_DRV_XGENE
tristate "APM X-Gene RTC"
-- 
2.7.4



[PATCH 3/4] rtc: mediatek: enhance the description for MediaTek PMIC based RTC

2017-09-21 Thread sean.wang
From: Sean Wang 

Give a better description for original MediaTek RTC driver as PMIC based
RTC in order to distinguish SoC based RTC. Also turning all words with
Mediatek to MediaTek here.

Cc: Eddie Huang 
Signed-off-by: Sean Wang 
---
 drivers/rtc/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4226295..4500f77 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1716,14 +1716,14 @@ config RTC_DRV_MEDIATEK
  will be called rtc-mediatek.
 
 config RTC_DRV_MT6397
-   tristate "Mediatek Real Time Clock driver"
+   tristate "MediaTek PMIC based RTC"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
help
- This selects the Mediatek(R) RTC driver. RTC is part of Mediatek
+ This selects the MediaTek(R) RTC driver. RTC is part of MediaTek
  MT6397 PMIC. You should enable MT6397 PMIC MFD before select
- Mediatek(R) RTC driver.
+ MediaTek(R) RTC driver.
 
- If you want to use Mediatek(R) RTC interface, select Y or M here.
+ If you want to use MediaTek(R) RTC interface, select Y or M here.
 
 config RTC_DRV_XGENE
tristate "APM X-Gene RTC"
-- 
2.7.4



[PATCH 0/4] rtc: mediatek: add support for SoC based RTC on MT7622

2017-09-21 Thread sean.wang
From: Sean Wang 

This patchset introduces support for MediaTek SoC based real time clock
(RTC) Currently, the driver is already tested successfully with hwclock
and wakealarm on MT7622 SoC. And it should also be workable on other
similar MediaTek SoCs. And patch 3 is a distinct patch used to distinguish
between either SoC based or PMIC based RTC to avoid confusion for the RTC
selection for the target SoC.

Sean Wang (4):
  dt-bindings: rtc: mediatek: add bindings for MediaTek SoC based RTC
  rtc: mediatek: add driver for RTC on MT7622 SoC
  rtc: mediatek: enhance the description for MediaTek PMIC based RTC
  rtc: mediatek: update MAINTAINERS entry with MediaTek RTC driver

 .../devicetree/bindings/rtc/rtc-mediatek.txt   |  21 ++
 MAINTAINERS|   3 +
 drivers/rtc/Kconfig|  18 +-
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-mediatek.c | 398 +
 5 files changed, 437 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
 create mode 100644 drivers/rtc/rtc-mediatek.c

-- 
2.7.4



[PATCH 2/4] rtc: mediatek: add driver for RTC on MT7622 SoC

2017-09-21 Thread sean.wang
From: Sean Wang 

This patch introduces the driver for the RTC on MT7622 SoC.

Signed-off-by: Sean Wang 
---
 drivers/rtc/Kconfig|  10 ++
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-mediatek.c | 398 +
 3 files changed, 409 insertions(+)
 create mode 100644 drivers/rtc/rtc-mediatek.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e0e58f3..4226295 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1705,6 +1705,16 @@ config RTC_DRV_MOXART
   This driver can also be built as a module. If so, the module
   will be called rtc-moxart
 
+config RTC_DRV_MEDIATEK
+   tristate "MediaTek SoC based RTC"
+   depends on ARCH_MEDIATEK || COMPILE_TEST
+   help
+ This enables support for the real time clock built in the MediaTek
+ SoCs.
+
+ This drive can also be built as a module. If so, the module
+ will be called rtc-mediatek.
+
 config RTC_DRV_MT6397
tristate "Mediatek Real Time Clock driver"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 7230014..ba0206a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_RTC_DRV_MOXART)+= rtc-moxart.o
 obj-$(CONFIG_RTC_DRV_MPC5121)  += rtc-mpc5121.o
 obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o
 obj-$(CONFIG_RTC_DRV_MSM6242)  += rtc-msm6242.o
+obj-$(CONFIG_RTC_DRV_MEDIATEK) += rtc-mediatek.o
 obj-$(CONFIG_RTC_DRV_MT6397)   += rtc-mt6397.o
 obj-$(CONFIG_RTC_DRV_MV)   += rtc-mv.o
 obj-$(CONFIG_RTC_DRV_MXC)  += rtc-mxc.o
diff --git a/drivers/rtc/rtc-mediatek.c b/drivers/rtc/rtc-mediatek.c
new file mode 100644
index 000..c6c06fe
--- /dev/null
+++ b/drivers/rtc/rtc-mediatek.c
@@ -0,0 +1,398 @@
+/*
+ * Driver for MediaTek SoC based RTC
+ *
+ * Copyright (C) 2017 Sean Wang 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_RTC_DEV KBUILD_MODNAME
+
+#define MTK_RTC_PWRCHK10x4
+#defineRTC_PWRCHK1_MAGIC   0xc6
+
+#define MTK_RTC_PWRCHK20x8
+#defineRTC_PWRCHK2_MAGIC   0x9a
+
+#define MTK_RTC_KEY0xc
+#defineRTC_KEY_MAGIC   0x59
+
+#define MTK_RTC_PROT1  0x10
+#defineRTC_PROT1_MAGIC 0xa3
+
+#define MTK_RTC_PROT2  0x14
+#defineRTC_PROT2_MAGIC 0x57
+
+#define MTK_RTC_PROT3  0x18
+#defineRTC_PROT3_MAGIC 0x67
+
+#define MTK_RTC_PROT4  0x1c
+#defineRTC_PROT4_MAGIC 0xd2
+
+#define MTK_RTC_CTL0x20
+#defineRTC_RC_STOP BIT(0)
+
+#define MTK_RTC_DEBNCE 0x2c
+#defineRTC_DEBNCE_MASK GENMASK(2, 0)
+
+#define MTK_RTC_INT0x30
+#define RTC_INT_AL_STA BIT(4)
+
+/* Ranges from 0x40 to 0x78 provide RTC time setup for year, month,
+ * day of month, day of week, hour, minute and second.
+ */
+#define MTK_RTC_TREG(_t, _f)   (0x40 + (0x4 * (_f)) + ((_t) * 0x20))
+
+#define MTK_RTC_AL_CTL 0x7c
+#defineRTC_AL_EN   BIT(0)
+#defineRTC_AL_ALL  GENMASK(7, 0)
+
+/* Types of the function the RTC provides are time counter and alarm. */
+enum {
+   MTK_TC,
+   MTK_AL
+};
+
+/* Indexes are used for the pointer to relevant registers in MTK_RTC_TREG */
+enum {
+   MTK_YEA,
+   MTK_MON,
+   MTK_DOM,
+   MTK_DOW,
+   MTK_HOU,
+   MTK_MIN,
+   MTK_SEC
+};
+
+struct mtk_rtc {
+   struct rtc_device *rtc;
+   void __iomem *base;
+   int irq;
+   struct clk *clk;
+};
+
+static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+   __raw_writel(val, rtc->base + reg);
+}
+
+static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg)
+{
+   return __raw_readl(rtc->base + reg);
+}
+
+static void mtk_rmw(struct mtk_rtc *rtc, u32 reg, u32 mask, u32 set)
+{
+   u32 val;
+
+   val = mtk_r32(rtc, reg);
+   val &= ~mask;
+   val |= set;
+   mtk_w32(rtc, reg, val);
+}
+
+static void mtk_set(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+   mtk_rmw(rtc, reg, 0, val);
+}
+
+static void mtk_clr(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+   mtk_rmw(rtc, reg, val, 0);
+}
+
+static void mtk_rtc_hw_init(struct mtk_rtc *hw)
+{
+   /* The setup of the init sequence is 

[PATCH 1/4] dt-bindings: rtc: mediatek: add bindings for MediaTek SoC based RTC

2017-09-21 Thread sean.wang
From: Sean Wang 

Add device-tree binding for MediaTek SoC based RTC

Cc: devicet...@vger.kernel.org
Signed-off-by: Sean Wang 
---
 .../devicetree/bindings/rtc/rtc-mediatek.txt| 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mediatek.txt

diff --git a/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt 
b/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
new file mode 100644
index 000..09fe8f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
@@ -0,0 +1,21 @@
+Device-Tree bindings for MediaTek SoC based RTC
+
+Required properties:
+- compatible   : Should be
+   "mediatek,mt7622-rtc", "mediatek,soc-rtc" : for MT7622 
SoC
+- reg  : Specifies base physical address and size of the registers;
+- interrupts   : Should contain the interrupt for RTC alarm;
+- clocks   : Specifies list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : Should contain "rtc" entries
+
+Example:
+
+rtc: rtc@10212800 {
+   compatible = "mediatek,mt7622-rtc",
+"mediatek,soc-rtc";
+   reg = <0 0x10212800 0 0x200>;
+   interrupts = ;
+   clocks = < CLK_TOP_RTC>;
+   clock-names = "rtc";
+};
-- 
2.7.4



[PATCH 0/4] rtc: mediatek: add support for SoC based RTC on MT7622

2017-09-21 Thread sean.wang
From: Sean Wang 

This patchset introduces support for MediaTek SoC based real time clock
(RTC) Currently, the driver is already tested successfully with hwclock
and wakealarm on MT7622 SoC. And it should also be workable on other
similar MediaTek SoCs. And patch 3 is a distinct patch used to distinguish
between either SoC based or PMIC based RTC to avoid confusion for the RTC
selection for the target SoC.

Sean Wang (4):
  dt-bindings: rtc: mediatek: add bindings for MediaTek SoC based RTC
  rtc: mediatek: add driver for RTC on MT7622 SoC
  rtc: mediatek: enhance the description for MediaTek PMIC based RTC
  rtc: mediatek: update MAINTAINERS entry with MediaTek RTC driver

 .../devicetree/bindings/rtc/rtc-mediatek.txt   |  21 ++
 MAINTAINERS|   3 +
 drivers/rtc/Kconfig|  18 +-
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-mediatek.c | 398 +
 5 files changed, 437 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
 create mode 100644 drivers/rtc/rtc-mediatek.c

-- 
2.7.4



[PATCH 2/4] rtc: mediatek: add driver for RTC on MT7622 SoC

2017-09-21 Thread sean.wang
From: Sean Wang 

This patch introduces the driver for the RTC on MT7622 SoC.

Signed-off-by: Sean Wang 
---
 drivers/rtc/Kconfig|  10 ++
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/rtc-mediatek.c | 398 +
 3 files changed, 409 insertions(+)
 create mode 100644 drivers/rtc/rtc-mediatek.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e0e58f3..4226295 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1705,6 +1705,16 @@ config RTC_DRV_MOXART
   This driver can also be built as a module. If so, the module
   will be called rtc-moxart
 
+config RTC_DRV_MEDIATEK
+   tristate "MediaTek SoC based RTC"
+   depends on ARCH_MEDIATEK || COMPILE_TEST
+   help
+ This enables support for the real time clock built in the MediaTek
+ SoCs.
+
+ This drive can also be built as a module. If so, the module
+ will be called rtc-mediatek.
+
 config RTC_DRV_MT6397
tristate "Mediatek Real Time Clock driver"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 7230014..ba0206a 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_RTC_DRV_MOXART)+= rtc-moxart.o
 obj-$(CONFIG_RTC_DRV_MPC5121)  += rtc-mpc5121.o
 obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o
 obj-$(CONFIG_RTC_DRV_MSM6242)  += rtc-msm6242.o
+obj-$(CONFIG_RTC_DRV_MEDIATEK) += rtc-mediatek.o
 obj-$(CONFIG_RTC_DRV_MT6397)   += rtc-mt6397.o
 obj-$(CONFIG_RTC_DRV_MV)   += rtc-mv.o
 obj-$(CONFIG_RTC_DRV_MXC)  += rtc-mxc.o
diff --git a/drivers/rtc/rtc-mediatek.c b/drivers/rtc/rtc-mediatek.c
new file mode 100644
index 000..c6c06fe
--- /dev/null
+++ b/drivers/rtc/rtc-mediatek.c
@@ -0,0 +1,398 @@
+/*
+ * Driver for MediaTek SoC based RTC
+ *
+ * Copyright (C) 2017 Sean Wang 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MTK_RTC_DEV KBUILD_MODNAME
+
+#define MTK_RTC_PWRCHK10x4
+#defineRTC_PWRCHK1_MAGIC   0xc6
+
+#define MTK_RTC_PWRCHK20x8
+#defineRTC_PWRCHK2_MAGIC   0x9a
+
+#define MTK_RTC_KEY0xc
+#defineRTC_KEY_MAGIC   0x59
+
+#define MTK_RTC_PROT1  0x10
+#defineRTC_PROT1_MAGIC 0xa3
+
+#define MTK_RTC_PROT2  0x14
+#defineRTC_PROT2_MAGIC 0x57
+
+#define MTK_RTC_PROT3  0x18
+#defineRTC_PROT3_MAGIC 0x67
+
+#define MTK_RTC_PROT4  0x1c
+#defineRTC_PROT4_MAGIC 0xd2
+
+#define MTK_RTC_CTL0x20
+#defineRTC_RC_STOP BIT(0)
+
+#define MTK_RTC_DEBNCE 0x2c
+#defineRTC_DEBNCE_MASK GENMASK(2, 0)
+
+#define MTK_RTC_INT0x30
+#define RTC_INT_AL_STA BIT(4)
+
+/* Ranges from 0x40 to 0x78 provide RTC time setup for year, month,
+ * day of month, day of week, hour, minute and second.
+ */
+#define MTK_RTC_TREG(_t, _f)   (0x40 + (0x4 * (_f)) + ((_t) * 0x20))
+
+#define MTK_RTC_AL_CTL 0x7c
+#defineRTC_AL_EN   BIT(0)
+#defineRTC_AL_ALL  GENMASK(7, 0)
+
+/* Types of the function the RTC provides are time counter and alarm. */
+enum {
+   MTK_TC,
+   MTK_AL
+};
+
+/* Indexes are used for the pointer to relevant registers in MTK_RTC_TREG */
+enum {
+   MTK_YEA,
+   MTK_MON,
+   MTK_DOM,
+   MTK_DOW,
+   MTK_HOU,
+   MTK_MIN,
+   MTK_SEC
+};
+
+struct mtk_rtc {
+   struct rtc_device *rtc;
+   void __iomem *base;
+   int irq;
+   struct clk *clk;
+};
+
+static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+   __raw_writel(val, rtc->base + reg);
+}
+
+static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg)
+{
+   return __raw_readl(rtc->base + reg);
+}
+
+static void mtk_rmw(struct mtk_rtc *rtc, u32 reg, u32 mask, u32 set)
+{
+   u32 val;
+
+   val = mtk_r32(rtc, reg);
+   val &= ~mask;
+   val |= set;
+   mtk_w32(rtc, reg, val);
+}
+
+static void mtk_set(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+   mtk_rmw(rtc, reg, 0, val);
+}
+
+static void mtk_clr(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+   mtk_rmw(rtc, reg, val, 0);
+}
+
+static void mtk_rtc_hw_init(struct mtk_rtc *hw)
+{
+   /* The setup of the init sequence is for allowing RTC got to work */
+   mtk_w32(hw, MTK_RTC_PWRCHK1, 

[PATCH 1/4] dt-bindings: rtc: mediatek: add bindings for MediaTek SoC based RTC

2017-09-21 Thread sean.wang
From: Sean Wang 

Add device-tree binding for MediaTek SoC based RTC

Cc: devicet...@vger.kernel.org
Signed-off-by: Sean Wang 
---
 .../devicetree/bindings/rtc/rtc-mediatek.txt| 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mediatek.txt

diff --git a/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt 
b/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
new file mode 100644
index 000..09fe8f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
@@ -0,0 +1,21 @@
+Device-Tree bindings for MediaTek SoC based RTC
+
+Required properties:
+- compatible   : Should be
+   "mediatek,mt7622-rtc", "mediatek,soc-rtc" : for MT7622 
SoC
+- reg  : Specifies base physical address and size of the registers;
+- interrupts   : Should contain the interrupt for RTC alarm;
+- clocks   : Specifies list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : Should contain "rtc" entries
+
+Example:
+
+rtc: rtc@10212800 {
+   compatible = "mediatek,mt7622-rtc",
+"mediatek,soc-rtc";
+   reg = <0 0x10212800 0 0x200>;
+   interrupts = ;
+   clocks = < CLK_TOP_RTC>;
+   clock-names = "rtc";
+};
-- 
2.7.4



[PATCH 4/4] rtc: mediatek: update MAINTAINERS entry with MediaTek RTC driver

2017-09-21 Thread sean.wang
From: Sean Wang 

I work for MediaTek on maintaining the MediaTek SoC based RTC driver for
the existing SoCs and keep adding support for the following SoCs in the
future.

Cc: Eddie Huang 
Signed-off-by: Sean Wang 
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2281af4..5142029 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1579,10 +1579,13 @@ F:  drivers/rtc/rtc-armada38x.c
 
 ARM/Mediatek RTC DRIVER
 M: Eddie Huang 
+M: Sean Wang 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 L: linux-media...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
+F: Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
 F: drivers/rtc/rtc-mt6397.c
+F: drivers/rtc/rtc-mediatek.c
 
 ARM/Mediatek SoC support
 M: Matthias Brugger 
-- 
2.7.4



[PATCH 4/4] rtc: mediatek: update MAINTAINERS entry with MediaTek RTC driver

2017-09-21 Thread sean.wang
From: Sean Wang 

I work for MediaTek on maintaining the MediaTek SoC based RTC driver for
the existing SoCs and keep adding support for the following SoCs in the
future.

Cc: Eddie Huang 
Signed-off-by: Sean Wang 
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2281af4..5142029 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1579,10 +1579,13 @@ F:  drivers/rtc/rtc-armada38x.c
 
 ARM/Mediatek RTC DRIVER
 M: Eddie Huang 
+M: Sean Wang 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 L: linux-media...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
+F: Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
 F: drivers/rtc/rtc-mt6397.c
+F: drivers/rtc/rtc-mediatek.c
 
 ARM/Mediatek SoC support
 M: Matthias Brugger 
-- 
2.7.4



Re: [RFC PATCH v3 1/2] membarrier: Provide register expedited private command

2017-09-21 Thread Boqun Feng
On Fri, Sep 22, 2017 at 11:22:06AM +0800, Boqun Feng wrote:
> Hi Mathieu,
> 
> On Tue, Sep 19, 2017 at 06:13:41PM -0400, Mathieu Desnoyers wrote:
> > Provide a new command allowing processes to register their intent to use
> > the private expedited command.
> > 
> > This allows PowerPC to skip the full memory barrier in switch_mm(), and
> > only issue the barrier when scheduling into a task belonging to a
> > process that has registered to use expedited private.
> > 
> > Processes are now required to register before using
> > MEMBARRIER_CMD_PRIVATE_EXPEDITED, otherwise that command returns EPERM.
> > 
> 
> Sorry I'm late for the party, but I couldn't stop thinking whether we
> could avoid the register thing at all, because the registering makes
> sys_membarrier() more complex(both for the interface and the
> implementation). So how about we trade-off a little bit by taking
> some(not all) the rq->locks?
> 
> The idea is in membarrier_private_expedited(), we go through all ->curr
> on each CPU and 
> 
> 1)If it's a userspace task and its ->mm is matched, we send an ipi
> 
> 2)If it's a kernel task, we skip
> 
>   (Because there will be a smp_mb() implied by mmdrop(), when it
>   switchs to userspace task).
> 
> 3)If it's a userspace task and its ->mm is not matched, we take
>   the corresponding rq->lock and check rq->curr again, if its ->mm
>   matched, we send an ipi, otherwise we do nothing.
> 
>   (Because if we observe rq->curr is not matched with rq->lock
>   held, when a task having matched ->mm schedules in, the rq->lock
>   pairing along with the smp_mb__after_spinlock() will guarantee
>   it observes all memory ops before sys_membarrir()).
> 
> membarrier_private_expedited() will look like this if we choose this
> way:
> 
> void membarrier_private_expedited()
> {
>   int cpu;
>   bool fallback = false;
>   cpumask_var_t tmpmask;
>   struct rq_flags rf;
> 
> 
>   if (num_online_cpus() == 1)
>   return;
> 
>   smp_mb();
> 
>   if (!zalloc_cpumask_var(, GFP_NOWAIT)) {
>   /* Fallback for OOM. */
>   fallback = true;
>   }
> 
>   cpus_read_lock();
>   for_each_online_cpu(cpu) {
>   struct task_struct *p;
> 
>   if (cpu == raw_smp_processor_id())
>   continue;
> 
>   rcu_read_lock();
>   p = task_rcu_dereference(_rq(cpu)->curr);
> 
>   if (!p) {
>   rcu_read_unlock();
>   continue;
>   }
> 
>   if (p->mm == current->mm) {
>   if (!fallback)
>   __cpumask_set_cpu(cpu, tmpmask);
>   else
>   smp_call_function_single(cpu, ipi_mb, NULL, 1);
>   }
> 
>   if (p->mm == current->mm || !p->mm) {
>   rcu_read_unlock();
>   continue;
>   }
> 
>   rcu_read_unlock();
>   
>   /*
>* This should be a arch-specific code, as we don't
>* need it at else place other than some archs without
>* a smp_mb() in switch_mm() (i.e. powerpc)
>*/
>   rq_lock_irq(cpu_rq(cpu), );
>   if (p->mm == current->mm) {

Oops, this one should be

if (cpu_curr(cpu)->mm == current->mm)

>   if (!fallback)
>   __cpumask_set_cpu(cpu, tmpmask);
>   else
>   smp_call_function_single(cpu, ipi_mb, NULL, 1);

, and this better be moved out of the lock rq->lock critical section.

Regards,
Boqun

>   }
>   rq_unlock_irq(cpu_rq(cpu), );
>   }
>   if (!fallback) {
>   smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
>   free_cpumask_var(tmpmask);
>   }
>   cpus_read_unlock();
> 
>   smp_mb();
> }
> 
> Thoughts?
> 
> Regards,
> Boqun
> 
[...]


signature.asc
Description: PGP signature


Re: [RFC PATCH v3 1/2] membarrier: Provide register expedited private command

2017-09-21 Thread Boqun Feng
On Fri, Sep 22, 2017 at 11:22:06AM +0800, Boqun Feng wrote:
> Hi Mathieu,
> 
> On Tue, Sep 19, 2017 at 06:13:41PM -0400, Mathieu Desnoyers wrote:
> > Provide a new command allowing processes to register their intent to use
> > the private expedited command.
> > 
> > This allows PowerPC to skip the full memory barrier in switch_mm(), and
> > only issue the barrier when scheduling into a task belonging to a
> > process that has registered to use expedited private.
> > 
> > Processes are now required to register before using
> > MEMBARRIER_CMD_PRIVATE_EXPEDITED, otherwise that command returns EPERM.
> > 
> 
> Sorry I'm late for the party, but I couldn't stop thinking whether we
> could avoid the register thing at all, because the registering makes
> sys_membarrier() more complex(both for the interface and the
> implementation). So how about we trade-off a little bit by taking
> some(not all) the rq->locks?
> 
> The idea is in membarrier_private_expedited(), we go through all ->curr
> on each CPU and 
> 
> 1)If it's a userspace task and its ->mm is matched, we send an ipi
> 
> 2)If it's a kernel task, we skip
> 
>   (Because there will be a smp_mb() implied by mmdrop(), when it
>   switchs to userspace task).
> 
> 3)If it's a userspace task and its ->mm is not matched, we take
>   the corresponding rq->lock and check rq->curr again, if its ->mm
>   matched, we send an ipi, otherwise we do nothing.
> 
>   (Because if we observe rq->curr is not matched with rq->lock
>   held, when a task having matched ->mm schedules in, the rq->lock
>   pairing along with the smp_mb__after_spinlock() will guarantee
>   it observes all memory ops before sys_membarrir()).
> 
> membarrier_private_expedited() will look like this if we choose this
> way:
> 
> void membarrier_private_expedited()
> {
>   int cpu;
>   bool fallback = false;
>   cpumask_var_t tmpmask;
>   struct rq_flags rf;
> 
> 
>   if (num_online_cpus() == 1)
>   return;
> 
>   smp_mb();
> 
>   if (!zalloc_cpumask_var(, GFP_NOWAIT)) {
>   /* Fallback for OOM. */
>   fallback = true;
>   }
> 
>   cpus_read_lock();
>   for_each_online_cpu(cpu) {
>   struct task_struct *p;
> 
>   if (cpu == raw_smp_processor_id())
>   continue;
> 
>   rcu_read_lock();
>   p = task_rcu_dereference(_rq(cpu)->curr);
> 
>   if (!p) {
>   rcu_read_unlock();
>   continue;
>   }
> 
>   if (p->mm == current->mm) {
>   if (!fallback)
>   __cpumask_set_cpu(cpu, tmpmask);
>   else
>   smp_call_function_single(cpu, ipi_mb, NULL, 1);
>   }
> 
>   if (p->mm == current->mm || !p->mm) {
>   rcu_read_unlock();
>   continue;
>   }
> 
>   rcu_read_unlock();
>   
>   /*
>* This should be a arch-specific code, as we don't
>* need it at else place other than some archs without
>* a smp_mb() in switch_mm() (i.e. powerpc)
>*/
>   rq_lock_irq(cpu_rq(cpu), );
>   if (p->mm == current->mm) {

Oops, this one should be

if (cpu_curr(cpu)->mm == current->mm)

>   if (!fallback)
>   __cpumask_set_cpu(cpu, tmpmask);
>   else
>   smp_call_function_single(cpu, ipi_mb, NULL, 1);

, and this better be moved out of the lock rq->lock critical section.

Regards,
Boqun

>   }
>   rq_unlock_irq(cpu_rq(cpu), );
>   }
>   if (!fallback) {
>   smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
>   free_cpumask_var(tmpmask);
>   }
>   cpus_read_unlock();
> 
>   smp_mb();
> }
> 
> Thoughts?
> 
> Regards,
> Boqun
> 
[...]


signature.asc
Description: PGP signature


Re: [RFC PATCH v3 1/2] membarrier: Provide register expedited private command

2017-09-21 Thread Boqun Feng
Hi Mathieu,

On Tue, Sep 19, 2017 at 06:13:41PM -0400, Mathieu Desnoyers wrote:
> Provide a new command allowing processes to register their intent to use
> the private expedited command.
> 
> This allows PowerPC to skip the full memory barrier in switch_mm(), and
> only issue the barrier when scheduling into a task belonging to a
> process that has registered to use expedited private.
> 
> Processes are now required to register before using
> MEMBARRIER_CMD_PRIVATE_EXPEDITED, otherwise that command returns EPERM.
> 

Sorry I'm late for the party, but I couldn't stop thinking whether we
could avoid the register thing at all, because the registering makes
sys_membarrier() more complex(both for the interface and the
implementation). So how about we trade-off a little bit by taking
some(not all) the rq->locks?

The idea is in membarrier_private_expedited(), we go through all ->curr
on each CPU and 

1)  If it's a userspace task and its ->mm is matched, we send an ipi

2)  If it's a kernel task, we skip

(Because there will be a smp_mb() implied by mmdrop(), when it
switchs to userspace task).

3)  If it's a userspace task and its ->mm is not matched, we take
the corresponding rq->lock and check rq->curr again, if its ->mm
matched, we send an ipi, otherwise we do nothing.

(Because if we observe rq->curr is not matched with rq->lock
held, when a task having matched ->mm schedules in, the rq->lock
pairing along with the smp_mb__after_spinlock() will guarantee
it observes all memory ops before sys_membarrir()).

membarrier_private_expedited() will look like this if we choose this
way:

void membarrier_private_expedited()
{
int cpu;
bool fallback = false;
cpumask_var_t tmpmask;
struct rq_flags rf;


if (num_online_cpus() == 1)
return;

smp_mb();

if (!zalloc_cpumask_var(, GFP_NOWAIT)) {
/* Fallback for OOM. */
fallback = true;
}

cpus_read_lock();
for_each_online_cpu(cpu) {
struct task_struct *p;

if (cpu == raw_smp_processor_id())
continue;

rcu_read_lock();
p = task_rcu_dereference(_rq(cpu)->curr);

if (!p) {
rcu_read_unlock();
continue;
}

if (p->mm == current->mm) {
if (!fallback)
__cpumask_set_cpu(cpu, tmpmask);
else
smp_call_function_single(cpu, ipi_mb, NULL, 1);
}

if (p->mm == current->mm || !p->mm) {
rcu_read_unlock();
continue;
}

rcu_read_unlock();

/*
 * This should be a arch-specific code, as we don't
 * need it at else place other than some archs without
 * a smp_mb() in switch_mm() (i.e. powerpc)
 */
rq_lock_irq(cpu_rq(cpu), );
if (p->mm == current->mm) {
if (!fallback)
__cpumask_set_cpu(cpu, tmpmask);
else
smp_call_function_single(cpu, ipi_mb, NULL, 1);
}
rq_unlock_irq(cpu_rq(cpu), );
}
if (!fallback) {
smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
free_cpumask_var(tmpmask);
}
cpus_read_unlock();

smp_mb();
}

Thoughts?

Regards,
Boqun

> Changes since v1:
> - Use test_ti_thread_flag(next, ...) instead of test_thread_flag() in
>   powerpc membarrier_arch_sched_in(), given that we want to specifically
>   check the next thread state.
> - Add missing ARCH_HAS_MEMBARRIER_HOOKS in Kconfig.
> - Use task_thread_info() to pass thread_info from task to
>   *_ti_thread_flag().
> 
> Changes since v2:
> - Move membarrier_arch_sched_in() call to finish_task_switch().
> - Check for NULL t->mm in membarrier_arch_fork().
> - Use membarrier_sched_in() in generic code, which invokes the
>   arch-specific membarrier_arch_sched_in(). This fixes allnoconfig
>   build on PowerPC.
> - Move asm/membarrier.h include under CONFIG_MEMBARRIER, fixing
>   allnoconfig build on PowerPC.
> - Build and runtime tested on PowerPC.
> 
> Signed-off-by: Mathieu Desnoyers 
> CC: Peter Zijlstra 
> CC: Paul E. McKenney 
> CC: Boqun Feng 
> CC: Andrew Hunter 
> CC: Maged Michael 
> CC: gro...@google.com
> CC: Avi Kivity 
> CC: Benjamin Herrenschmidt 
> CC: Paul Mackerras 
> CC: Michael 

Re: [RFC PATCH v3 1/2] membarrier: Provide register expedited private command

2017-09-21 Thread Boqun Feng
Hi Mathieu,

On Tue, Sep 19, 2017 at 06:13:41PM -0400, Mathieu Desnoyers wrote:
> Provide a new command allowing processes to register their intent to use
> the private expedited command.
> 
> This allows PowerPC to skip the full memory barrier in switch_mm(), and
> only issue the barrier when scheduling into a task belonging to a
> process that has registered to use expedited private.
> 
> Processes are now required to register before using
> MEMBARRIER_CMD_PRIVATE_EXPEDITED, otherwise that command returns EPERM.
> 

Sorry I'm late for the party, but I couldn't stop thinking whether we
could avoid the register thing at all, because the registering makes
sys_membarrier() more complex(both for the interface and the
implementation). So how about we trade-off a little bit by taking
some(not all) the rq->locks?

The idea is in membarrier_private_expedited(), we go through all ->curr
on each CPU and 

1)  If it's a userspace task and its ->mm is matched, we send an ipi

2)  If it's a kernel task, we skip

(Because there will be a smp_mb() implied by mmdrop(), when it
switchs to userspace task).

3)  If it's a userspace task and its ->mm is not matched, we take
the corresponding rq->lock and check rq->curr again, if its ->mm
matched, we send an ipi, otherwise we do nothing.

(Because if we observe rq->curr is not matched with rq->lock
held, when a task having matched ->mm schedules in, the rq->lock
pairing along with the smp_mb__after_spinlock() will guarantee
it observes all memory ops before sys_membarrir()).

membarrier_private_expedited() will look like this if we choose this
way:

void membarrier_private_expedited()
{
int cpu;
bool fallback = false;
cpumask_var_t tmpmask;
struct rq_flags rf;


if (num_online_cpus() == 1)
return;

smp_mb();

if (!zalloc_cpumask_var(, GFP_NOWAIT)) {
/* Fallback for OOM. */
fallback = true;
}

cpus_read_lock();
for_each_online_cpu(cpu) {
struct task_struct *p;

if (cpu == raw_smp_processor_id())
continue;

rcu_read_lock();
p = task_rcu_dereference(_rq(cpu)->curr);

if (!p) {
rcu_read_unlock();
continue;
}

if (p->mm == current->mm) {
if (!fallback)
__cpumask_set_cpu(cpu, tmpmask);
else
smp_call_function_single(cpu, ipi_mb, NULL, 1);
}

if (p->mm == current->mm || !p->mm) {
rcu_read_unlock();
continue;
}

rcu_read_unlock();

/*
 * This should be a arch-specific code, as we don't
 * need it at else place other than some archs without
 * a smp_mb() in switch_mm() (i.e. powerpc)
 */
rq_lock_irq(cpu_rq(cpu), );
if (p->mm == current->mm) {
if (!fallback)
__cpumask_set_cpu(cpu, tmpmask);
else
smp_call_function_single(cpu, ipi_mb, NULL, 1);
}
rq_unlock_irq(cpu_rq(cpu), );
}
if (!fallback) {
smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
free_cpumask_var(tmpmask);
}
cpus_read_unlock();

smp_mb();
}

Thoughts?

Regards,
Boqun

> Changes since v1:
> - Use test_ti_thread_flag(next, ...) instead of test_thread_flag() in
>   powerpc membarrier_arch_sched_in(), given that we want to specifically
>   check the next thread state.
> - Add missing ARCH_HAS_MEMBARRIER_HOOKS in Kconfig.
> - Use task_thread_info() to pass thread_info from task to
>   *_ti_thread_flag().
> 
> Changes since v2:
> - Move membarrier_arch_sched_in() call to finish_task_switch().
> - Check for NULL t->mm in membarrier_arch_fork().
> - Use membarrier_sched_in() in generic code, which invokes the
>   arch-specific membarrier_arch_sched_in(). This fixes allnoconfig
>   build on PowerPC.
> - Move asm/membarrier.h include under CONFIG_MEMBARRIER, fixing
>   allnoconfig build on PowerPC.
> - Build and runtime tested on PowerPC.
> 
> Signed-off-by: Mathieu Desnoyers 
> CC: Peter Zijlstra 
> CC: Paul E. McKenney 
> CC: Boqun Feng 
> CC: Andrew Hunter 
> CC: Maged Michael 
> CC: gro...@google.com
> CC: Avi Kivity 
> CC: Benjamin Herrenschmidt 
> CC: Paul Mackerras 
> CC: Michael Ellerman 
> CC: Dave Watson 
> CC: Alan Stern 
> CC: Will Deacon 
> CC: Andy Lutomirski 
> CC: linux-a...@vger.kernel.org
> ---
>  MAINTAINERS|  2 ++
>  arch/powerpc/Kconfig 

  1   2   3   4   5   6   7   8   9   10   >