[PATCH V3] ASoC: fsl_asrc: add constraint for the asrc of older version

2019-03-01 Thread S.j. Wang
There is a constraint for the channel number setting on the
asrc of older version (e.g. imx35), the channel number should
be even, odd number isn't valid.

So add this constraint when the asrc of older version is used.

Acked-by: Nicolin Chen 
Signed-off-by: Shengjiu Wang 
---
Changes in v3
- fix comments with Nicolin's review

 sound/soc/fsl/fsl_asrc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 528e8b108422..0b937924d2e4 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -445,6 +445,19 @@ struct dma_chan *fsl_asrc_get_dma_channel(struct 
fsl_asrc_pair *pair, bool dir)
 }
 EXPORT_SYMBOL_GPL(fsl_asrc_get_dma_channel);
 
+static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
+
+   /* Odd channel number is not valid for older ASRC (channel_bits==3) */
+   if (asrc_priv->channel_bits == 3)
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_CHANNELS, 2);
+
+   return 0;
+}
+
 static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream,
  struct snd_pcm_hw_params *params,
  struct snd_soc_dai *dai)
@@ -539,6 +552,7 @@ static int fsl_asrc_dai_trigger(struct snd_pcm_substream 
*substream, int cmd,
 }
 
 static const struct snd_soc_dai_ops fsl_asrc_dai_ops = {
+   .startup  = fsl_asrc_dai_startup,
.hw_params= fsl_asrc_dai_hw_params,
.hw_free  = fsl_asrc_dai_hw_free,
.trigger  = fsl_asrc_dai_trigger,
-- 
1.9.1



RE: [PATCH V2] ASoC: fsl_asrc: add constraint for the asrc of older version

2019-03-01 Thread S.j. Wang
Hi

> On Fri, Mar 01, 2019 at 08:37:08AM +, S.j. Wang wrote:
> > There is constraint for the channel number setting on the
> 
> nit: "a constraint"
> 
> > asrc of older version (e.g. imx35), the channel number should be even,
> > odd number isn't valid.
> 
> > +static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
> > +   struct snd_soc_dai *dai)
> > +{
> > +   struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
> > +
> > +   /* channel_bits = 3 means older version on imx35*/
> 
> Space between '5' and '*'. And better to make it clear:
> 
>   /* Odd channel number is not valid for older ASRC (channel_bits==3)
> */
> 
> > +   if (asrc_priv->channel_bits == 3)
> > +   snd_pcm_hw_constraint_step(substream->runtime, 0,
> > +
> SNDRV_PCM_HW_PARAM_CHANNELS, 2);
> 
> For your next version,
> 
> Acked-by: Nicolin Chen 

Ok, thanks, will send v3.

> 
> Cheers


RE: [alsa-devel] [PATCH] ASoC: cs42xx8: Remove S32_LE in format list

2019-03-01 Thread S.j. Wang
Hi

> On 3/1/19 12:32 AM, S.j. Wang wrote:
> > This case is covered by S24_LE I think.  The S32_LE means the data is
> > 32bit and slot width Is 32bit, this is not in data sheet.
> 
> The problem is that if you have 32-bit samples in your audio file, and you
> want to play them, then software (e.g. alsalib) will need to convert the
> audio to 24-bit before sending it to hardware.  This is unnecessary because
> the hardware can "convert" the sample to 24-bit automatically by ignoring
> the lower 8 bits.
> 
> I think a lot of codecs do this already.

Ok. Thanks for reviewing, I will drop this patch.

Best regards
Wang shengjiu


Re: [PATCH 2/5] ocxl: Clean up printf formats

2019-03-01 Thread Joe Perches
On Wed, 2019-02-27 at 15:57 +1100, Alastair D'Silva wrote:
> From: Alastair D'Silva 
> 
> Use %# instead of using a literal '0x'

  I think it's better not to change this unless
the compilation unit already uses a mix of styles.

Overall, the kernel uses "0x%" over "%#"
by ~8:1

$ git grep -P '0x%\d*[hl]*x' | wc -l
27654
$ git grep -P '%#\d*[hl]*x' | wc -l
3454

> diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
[]
> @@ -178,9 +178,9 @@ static int read_dvsec_vendor(struct pci_dev *dev)
>   pci_read_config_dword(dev, pos + OCXL_DVSEC_VENDOR_DLX_VERS, );
>  
>   dev_dbg(>dev, "Vendor specific DVSEC:\n");
> - dev_dbg(>dev, "  CFG version = 0x%x\n", cfg);
> - dev_dbg(>dev, "  TLX version = 0x%x\n", tlx);
> - dev_dbg(>dev, "  DLX version = 0x%x\n", dlx);
> + dev_dbg(>dev, "  CFG version = %#x\n", cfg);
> + dev_dbg(>dev, "  TLX version = %#x\n", tlx);
> + dev_dbg(>dev, "  DLX version = %#x\n", dlx);
[...]



Re: PROBLEM: monotonic clock going backwards on ppc64

2019-03-01 Thread Thomas Gleixner
On Sat, 2 Mar 2019, Michael Ellerman wrote:
> > The problem seems to be in vDSO code in 
> > arch/powerpc/kernel/vdso64/gettimeofday.S.
> 
> You're right, the wall-to-monotonic offset (wtom_clock_sec) is a signed
> 32-bit value, so that seems like it's going to have problems.
> 
> If I do `date -s 2037-1-1` I see:
> 
> [   26.024061] update_vsyscall: tk->wall_to_monotonic.tv_sec -2114341175
> [   26.042633] update_vsyscall: vdso_data->wtom_clock_sec-2114341175
> 
> Which looks sane.
> 
> But then 2040-1-1 shows:
> 
> [   32.617020] update_vsyscall: tk->wall_to_monotonic.tv_sec -2208949168
> [   32.632642] update_vsyscall: vdso_data->wtom_clock_sec 2086018128
> 
> ie. the larger negative offset has overflowed and become positive.
> 
> But then when we go back to 2037 we get a negative offset again and
> monotonic time appears to go backward and things are unhappy.
> 
> I don't know this code well, but the patch below *appears* to work. I'll
> have a closer look on Monday.

Looks about right. The core hands in the 64bit offset already.

Thanks,

tglx




[PULL REQUEST] powerpc generic command line

2019-03-01 Thread Daniel Walker
Here are the generic command line changes for powerpc. 

These changes have been in linux-next for two cycles, with few problems 
reported.
It's also been used at Cisco Systems, Inc. in production products for many many
years with no problems.

Please pull these changes.


The following changes since commit ccda4af0f4b92f7b4c308d3acc262f4a7e3affad:

  Linux 4.20-rc2 (2018-11-11 17:12:31 -0600)

are available in the git repository at:

  https://github.com/daniel-walker/cisco-linux.git for-powerpc

for you to fetch changes up to 5d4514a9c291ecf19b0626695161673d35e5d549:

  powerpc: convert config files to generic cmdline (2018-11-16 07:32:26 -0800)


Daniel Walker (3):
  add generic builtin command line
  powerpc: convert to generic builtin command line
  powerpc: convert config files to generic cmdline

 arch/powerpc/Kconfig  | 23 +
 arch/powerpc/configs/44x/fsp2_defconfig   | 29 ++-
 arch/powerpc/configs/44x/iss476-smp_defconfig | 24 -
 arch/powerpc/configs/44x/warp_defconfig   | 12 ++---
 arch/powerpc/configs/holly_defconfig  | 12 ++---
 arch/powerpc/configs/mvme5100_defconfig   | 25 +-
 arch/powerpc/configs/skiroot_defconfig| 48 +-
 arch/powerpc/configs/storcenter_defconfig | 15 +++---
 arch/powerpc/kernel/prom.c|  4 ++
 arch/powerpc/kernel/prom_init.c   |  8 +--
 arch/powerpc/kernel/prom_init_check.sh|  2 +-
 include/linux/cmdline.h   | 72 +++
 init/Kconfig  | 69 +
 13 files changed, 231 insertions(+), 112 deletions(-)
 create mode 100644 include/linux/cmdline.h


[PATCH 1/3] add generic builtin command line

2019-03-01 Thread Daniel Walker
This code allows architectures to use a generic builtin command line.
The state of the builtin command line options across architecture is
diverse. On x86 and mips they have pretty much the same code and the
code prepends the builtin command line onto the boot loader provided
one. On powerpc there is only a builtin override and nothing else.

The code in this commit unifies the mips and x86 code into a generic
header file under the CONFIG_GENERIC_CMDLINE option. When this
option is enabled the architecture can call the cmdline_add_builtin()
to add the builtin command line.

[maksym.kok...@globallogic.com: fix cmdline_add_builtin() macro]
Cc: Daniel Walker 
Cc: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
Signed-off-by: Maksym Kokhan 
---
 include/linux/cmdline.h | 72 +
 init/Kconfig| 69 +++
 2 files changed, 141 insertions(+)
 create mode 100644 include/linux/cmdline.h

diff --git a/include/linux/cmdline.h b/include/linux/cmdline.h
new file mode 100644
index ..126fa52f55d2
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,72 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2015. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+/*
+ * This function will append or prepend a builtin command line to the command
+ * line provided by the bootloader. Kconfig options can be used to alter
+ * the behavior of this builtin command line.
+ * @dest: The destination of the final appended/prepended string
+ * @src: The starting string or NULL if there isn't one.
+ * @tmp: temporary space used for prepending
+ * @length: the maximum length of the strings above.
+ */
+static inline void
+_cmdline_add_builtin(char *dest, char *src, char *tmp, unsigned long length)
+{
+   if (src != dest && src != NULL) {
+   strlcpy(dest, " ", length);
+   strlcat(dest, src, length);
+   }
+
+   strlcat(dest, " ", length);
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   strlcat(dest, CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   strlcpy(tmp, CONFIG_CMDLINE_PREPEND, length);
+   strlcat(tmp, " ", length);
+   strlcat(tmp, dest, length);
+   strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_section(dest, src, length, section)\
+{  \
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   \
+   static char cmdline_tmp_space[length] section;  \
+   _cmdline_add_builtin(dest, src, cmdline_tmp_space, length); \
+   } else {\
+   _cmdline_add_builtin(dest, src, NULL, length);  \
+   }   \
+}
+#else
+#define cmdline_add_builtin_section(dest, src, length, section)   \
+{ \
+   strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND,\
+   length);   \
+}
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else
+#define cmdline_add_builtin_section(dest, src, length, section) {  \
+   if (src != NULL)   \
+   strlcpy(dest, src, length);\
+}
+#endif /* CONFIG_GENERIC_CMDLINE */
+
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_section(dest, src, length, __initdata)
+
+#endif /* _LINUX_CMDLINE_H */
diff --git a/init/Kconfig b/init/Kconfig
index a4112e95724a..b59e856511e1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1775,6 +1775,75 @@ config PROFILING
 config TRACEPOINTS
bool
 
+config GENERIC_CMDLINE
+   bool
+
+if GENERIC_CMDLINE
+
+config CMDLINE_BOOL
+   bool "Built-in kernel command line"
+   help
+ Allow for specifying boot arguments to the kernel at
+ build time.  On some systems (e.g. embedded ones), it is
+ necessary or convenient to provide some or all of the
+ kernel boot arguments with the kernel itself (that is,
+ to not rely on the boot loader to provide them.)
+
+ To compile command line arguments into the kernel,
+ set this option to 'Y', then fill in the
+ the boot arguments in CONFIG_CMDLINE.
+
+ Systems with fully functional boot loaders (i.e. non-embedded)
+ should leave this option set to 'N'.
+
+config CMDLINE_APPEND
+   string "Built-in kernel 

[PATCH 2/3] powerpc: convert to generic builtin command line

2019-03-01 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

[maksym.kok...@globallogic.com: add strlcat to prom_init_check.sh
whitelist]
Cc: Daniel Walker 
Cc: Daniel Walker 
Cc: xe-linux-exter...@cisco.com
Signed-off-by: Daniel Walker 
Signed-off-by: Maksym Kokhan 
---
 arch/powerpc/Kconfig   | 23 +--
 arch/powerpc/kernel/prom.c |  4 
 arch/powerpc/kernel/prom_init.c|  8 
 arch/powerpc/kernel/prom_init_check.sh |  2 +-
 4 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 8be31261aec8..6321b2a0b87b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -172,6 +172,7 @@ config PPC
select GENERIC_STRNCPY_FROM_USER
select GENERIC_STRNLEN_USER
select GENERIC_TIME_VSYSCALL
+   select GENERIC_CMDLINE
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_JUMP_LABEL
select HAVE_ARCH_KGDB
@@ -777,28 +778,6 @@ config PPC_DENORMALISATION
  Add support for handling denormalisation of single precision
  values.  Useful for bare metal only.  If unsure say Y here.
 
-config CMDLINE_BOOL
-   bool "Default bootloader kernel arguments"
-
-config CMDLINE
-   string "Initial kernel command string"
-   depends on CMDLINE_BOOL
-   default "console=ttyS0,9600 console=tty0 root=/dev/sda2"
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel. For these platforms, you can supply
- some command-line options at build time by entering them here.  In
- most cases you will need to specify the root device here.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- Always use the default kernel command string, even if the boot
- loader passes other arguments to the kernel.
- This is useful if you cannot or don't want to change the
- command-line options your boot loader passes to the kernel.
-
 config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index fe758cedb93f..d78b1d6fe1c8 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -716,6 +717,9 @@ void __init early_init_devtree(void *params)
 */
of_scan_flat_dt(early_init_dt_scan_chosen_ppc, boot_command_line);
 
+   /* append and prepend any arguments built into the kernel. */
+   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
+
/* Scan memory nodes and rebuild MEMBLOCKs */
of_scan_flat_dt(early_init_dt_scan_root, NULL);
of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index f33ff4163a51..e8e9fca22470 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -637,11 +638,10 @@ static void __init early_cmdline_parse(void)
p = prom_cmd_line;
if ((long)prom.chosen > 0)
l = prom_getprop(prom.chosen, "bootargs", p, 
COMMAND_LINE_SIZE-1);
-#ifdef CONFIG_CMDLINE
+
if (l <= 0 || p[0] == '\0') /* dbl check */
-   strlcpy(prom_cmd_line,
-   CONFIG_CMDLINE, sizeof(prom_cmd_line));
-#endif /* CONFIG_CMDLINE */
+   cmdline_add_builtin_section(prom_cmd_line, NULL, 
sizeof(prom_cmd_line), __prombss);
+
prom_printf("command line: %s\n", prom_cmd_line);
 
 #ifdef CONFIG_PPC64
diff --git a/arch/powerpc/kernel/prom_init_check.sh 
b/arch/powerpc/kernel/prom_init_check.sh
index 667df97d2595..ab2acc8d8b5a 100644
--- a/arch/powerpc/kernel/prom_init_check.sh
+++ b/arch/powerpc/kernel/prom_init_check.sh
@@ -18,7 +18,7 @@
 
 WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush
 _end enter_prom memcpy memset reloc_offset __secondary_hold
-__secondary_hold_acknowledge __secondary_hold_spinloop __start
+__secondary_hold_acknowledge __secondary_hold_spinloop __start strlcat
 strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224
 reloc_got2 kernstart_addr memstart_addr linux_banner _stext
 __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC."
-- 
2.14.1



[PATCH 3/3] powerpc: convert config files to generic cmdline

2019-03-01 Thread Daniel Walker
This is a scripted mass convert of the config files to use
the new generic cmdline. There is a bit of a trim effect here.
It would seems that some of the config haven't been trimmed in
a while.

The script used to convert is as follows,

if [[ -z "$1" || -z "$2" ]]; then
echo "Two arguments are needed."
exit 1
fi
mkdir $1
cp $2 $1/.config
sed -i 's/CONFIG_CMDLINE=/CONFIG_CMDLINE_PREPEND=/g' $1/.config
make ARCH=$1 O=$1 olddefconfig
make ARCH=$1 O=$1 savedefconfig
cp $1/defconfig $2
rm -Rf $1

Cc: xe-linux-exter...@cisco.com
Cc: Daniel Walker 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/configs/44x/fsp2_defconfig   | 29 
 arch/powerpc/configs/44x/iss476-smp_defconfig | 24 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 12 +++
 arch/powerpc/configs/holly_defconfig  | 12 +++
 arch/powerpc/configs/mvme5100_defconfig   | 25 +++---
 arch/powerpc/configs/skiroot_defconfig| 48 +--
 arch/powerpc/configs/storcenter_defconfig | 15 -
 7 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index bae6b26bcfba..bafea495c9b8 100644
--- a/arch/powerpc/configs/44x/fsp2_defconfig
+++ b/arch/powerpc/configs/44x/fsp2_defconfig
@@ -1,8 +1,6 @@
-CONFIG_44x=y
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 # CONFIG_CROSS_MEMORY_ATTACH is not set
-# CONFIG_FHANDLE is not set
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_IKCONFIG=y
@@ -13,25 +11,26 @@ CONFIG_BLK_DEV_INITRD=y
 # CONFIG_RD_XZ is not set
 # CONFIG_RD_LZO is not set
 # CONFIG_RD_LZ4 is not set
+# CONFIG_FHANDLE is not set
 CONFIG_KALLSYMS_ALL=y
 CONFIG_BPF_SYSCALL=y
 CONFIG_EMBEDDED=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="ip=on rw"
+CONFIG_44x=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_FSP2=y
 CONFIG_476FPE_ERR46=y
-CONFIG_SWIOTLB=y
 CONFIG_KEXEC=y
 CONFIG_CRASH_DUMP=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="ip=on rw"
 # CONFIG_SUSPEND is not set
 # CONFIG_PCI is not set
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -112,6 +111,12 @@ CONFIG_NFS_V3_ACL=y
 CONFIG_NFS_V4=y
 CONFIG_ROOT_NFS=y
 CONFIG_NLS_DEFAULT="n"
+CONFIG_CRYPTO_CBC=y
+CONFIG_CRYPTO_ECB=y
+CONFIG_CRYPTO_PCBC=y
+CONFIG_CRYPTO_MD5=y
+CONFIG_CRYPTO_DES=y
+# CONFIG_CRYPTO_HW is not set
 CONFIG_XZ_DEC=y
 CONFIG_PRINTK_TIME=y
 CONFIG_MESSAGE_LOGLEVEL_DEFAULT=3
@@ -119,9 +124,3 @@ CONFIG_DYNAMIC_DEBUG=y
 CONFIG_DEBUG_INFO=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DETECT_HUNG_TASK=y
-CONFIG_CRYPTO_CBC=y
-CONFIG_CRYPTO_ECB=y
-CONFIG_CRYPTO_PCBC=y
-CONFIG_CRYPTO_MD5=y
-CONFIG_CRYPTO_DES=y
-# CONFIG_CRYPTO_HW is not set
diff --git a/arch/powerpc/configs/44x/iss476-smp_defconfig 
b/arch/powerpc/configs/44x/iss476-smp_defconfig
index d24bfa6ecd62..775b25178714 100644
--- a/arch/powerpc/configs/44x/iss476-smp_defconfig
+++ b/arch/powerpc/configs/44x/iss476-smp_defconfig
@@ -1,5 +1,3 @@
-CONFIG_44x=y
-CONFIG_SMP=y
 CONFIG_SYSVIPC=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_LOG_BUF_SHIFT=14
@@ -7,21 +5,23 @@ CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_PROFILING=y
-CONFIG_OPROFILE=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="root=/dev/issblk0"
+CONFIG_44x=y
+CONFIG_SMP=y
 CONFIG_PPC_47x=y
 # CONFIG_EBONY is not set
 CONFIG_ISS4xx=y
 CONFIG_HZ_100=y
 CONFIG_MATH_EMULATION=y
 CONFIG_IRQ_ALL_CPUS=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="root=/dev/issblk0"
 # CONFIG_PCI is not set
 CONFIG_ADVANCED_OPTIONS=y
 CONFIG_DYNAMIC_MEMSTART=y
+CONFIG_OPROFILE=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_PACKET=y
 CONFIG_UNIX=y
@@ -62,13 +62,13 @@ CONFIG_PROC_KCORE=y
 CONFIG_TMPFS=y
 CONFIG_CRAMFS=y
 # CONFIG_NETWORK_FILESYSTEMS is not set
-CONFIG_DEBUG_INFO=y
-CONFIG_MAGIC_SYSRQ=y
-CONFIG_DETECT_HUNG_TASK=y
-CONFIG_PPC_EARLY_DEBUG=y
 CONFIG_CRYPTO_CBC=y
 CONFIG_CRYPTO_ECB=y
 CONFIG_CRYPTO_PCBC=y
 CONFIG_CRYPTO_MD5=y
 CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_HW is not set
+CONFIG_DEBUG_INFO=y
+CONFIG_MAGIC_SYSRQ=y
+CONFIG_DETECT_HUNG_TASK=y
+CONFIG_PPC_EARLY_DEBUG=y
diff --git a/arch/powerpc/configs/44x/warp_defconfig 
b/arch/powerpc/configs/44x/warp_defconfig
index 6c02f53271cd..4b76897e323f 100644
--- a/arch/powerpc/configs/44x/warp_defconfig
+++ b/arch/powerpc/configs/44x/warp_defconfig
@@ -1,4 +1,3 @@
-CONFIG_44x=y
 CONFIG_LOCALVERSION="-pika"
 # CONFIG_LOCALVERSION_AUTO is not set
 CONFIG_SYSVIPC=y
@@ -7,16 +6,17 @@ CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
 CONFIG_BLK_DEV_INITRD=y
 CONFIG_EXPERT=y
-CONFIG_MODULES=y
-CONFIG_MODULE_UNLOAD=y
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="ip=on"
+CONFIG_44x=y
 

[PATCH] powerpc: remote save_stack_trace_tsk_reliable export

2019-03-01 Thread Joe Lawrence
As tglx points out, there are no in-tree module users of
save_stack_trace_tsk_reliable() and its x86 counterpart is not exported,
so remove the powerpc symbol export.

Suggested-by: Thomas Gleixner 
Signed-off-by: Joe Lawrence 
---
 arch/powerpc/kernel/stacktrace.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c
index e2c50b55138f..42c587de21a9 100644
--- a/arch/powerpc/kernel/stacktrace.c
+++ b/arch/powerpc/kernel/stacktrace.c
@@ -193,7 +193,6 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk,
}
return 0;
 }
-EXPORT_SYMBOL_GPL(save_stack_trace_tsk_reliable);
 #endif /* CONFIG_HAVE_RELIABLE_STACKTRACE */
 
 #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_NMI_IPI)
-- 
2.20.1



Re: [PATCH V2] ASoC: fsl_asrc: add constraint for the asrc of older version

2019-03-01 Thread Nicolin Chen
On Fri, Mar 01, 2019 at 08:37:08AM +, S.j. Wang wrote:
> There is constraint for the channel number setting on the

nit: "a constraint"

> asrc of older version (e.g. imx35), the channel number should
> be even, odd number isn't valid.

> +static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
> + struct snd_soc_dai *dai)
> +{
> + struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
> +
> + /* channel_bits = 3 means older version on imx35*/

Space between '5' and '*'. And better to make it clear:

/* Odd channel number is not valid for older ASRC (channel_bits==3) */

> + if (asrc_priv->channel_bits == 3)
> + snd_pcm_hw_constraint_step(substream->runtime, 0,
> +SNDRV_PCM_HW_PARAM_CHANNELS, 2);

For your next version,

Acked-by: Nicolin Chen 

Cheers


Re: [PATCH v4 4/4] hugetlb: allow to free gigantic pages regardless of the configuration

2019-03-01 Thread Mike Kravetz
On 3/1/19 5:21 AM, Alexandre Ghiti wrote:
> On 03/01/2019 07:25 AM, Alex Ghiti wrote:
>> On 2/28/19 5:26 PM, Mike Kravetz wrote:
>>> On 2/28/19 12:23 PM, Dave Hansen wrote:
 On 2/28/19 11:50 AM, Mike Kravetz wrote:
> On 2/28/19 11:13 AM, Dave Hansen wrote:
>>> +if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) {
>>> +spin_lock(_lock);
>>> +if (count > persistent_huge_pages(h)) {
>>> +spin_unlock(_lock);
>>> +return -EINVAL;
>>> +}
>>> +goto decrease_pool;
>>> +}
>> This choice confuses me.  The "Decrease the pool size" code already
>> works and the code just falls through to it after skipping all the
>> "Increase the pool size" code.
>>
>> Why did did you need to add this case so early?  Why not just let it
>> fall through like before?
> I assume you are questioning the goto, right?  You are correct in that
> it is unnecessary and we could just fall through.
 Yeah, it just looked odd to me.
> 
>> I'd rather avoid useless checks when we already know they won't
>> be met and I think that makes the code more understandable.
>>
>> But that's up to you for the next version.

I too find some value in the goto.  It tells me this !CONFIG_CONTIG_ALLOC
case is special and we are skipping the normal checks.  But, removing the
goto is not a requirement for me.

> However, I wonder if we might want to consider a wacky condition that the
> above check would prevent.  Consider a system/configuration with 5 
> gigantic
...
>>
>> If I may, I think that this is the kind of info the user wants to have and 
>> we should
>> return an error when it is not possible to allocate runtime huge pages.
>> I already noticed that if someone asks for 10 huge pages, and only 5 are 
>> allocated,
>> no error is returned to the user and I found that surprising.

Upon further thought, let's not consider this wacky permanent -> surplus ->
permanent case.  I just can't see it being an actual use case.

IIUC, that 'no error' behavior is somewhat expected.  I seem to recall previous
discussions about changing with the end result to leave as is.

 @@ -2428,7 +2442,9 @@ static ssize_t __nr_hugepages_store_common(bool 
 obey_mempolicy,
   } else
   nodes_allowed = _states[N_MEMORY];
   -h->max_huge_pages = set_max_huge_pages(h, count, nodes_allowed);
 +err = set_max_huge_pages(h, count, nodes_allowed);
 +if (err)
 +goto out;
 if (nodes_allowed != _states[N_MEMORY])
   NODEMASK_FREE(nodes_allowed);
>>> Do note that I beleive there is a bug the above change.  The code after
>>> the out label is:
>>>
>>> out:
>>>  NODEMASK_FREE(nodes_allowed);
>>>  return err;
>>> }
>>>
>>> With the new goto, we need the same
>>> if (nodes_allowed != _states[N_MEMORY]) before NODEMASK_FREE().
>>>
>>> Sorry, I missed this in previous versions.
>>
>> Oh right, I'm really sorry I missed that, thank you for noticing.

This is the only issue I have with the code in hugetlb.c.  For me, the
goto can stay or go.  End result is the same.
-- 
Mike Kravetz


[PATCH RFC v4 8/9] powerpc/powernv/pci: Hook up the writes to PCI_SECONDARY_BUS register

2019-03-01 Thread Sergey Miroshnichenko
Writing a new value to the PCI_SECONDARY_BUS register of the bridge means
that its children will become addressable on another address (new B in BDF)
or even un-addressable if the secondary bus is set to zero.

On PowerNV, device PEs are heavily BDF-dependent, so they must be updated
on every such change of its address.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/platforms/powernv/pci.c | 118 ++-
 1 file changed, 116 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci.c 
b/arch/powerpc/platforms/powernv/pci.c
index 73c2d0aed996..52ce717a7905 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -722,13 +722,127 @@ int pnv_pci_cfg_read(struct pci_dn *pdn,
where, size, val);
 }
 
+static void invalidate_children_pes(struct pci_dn *pdn)
+{
+   struct pnv_phb *phb = pdn->phb->private_data;
+   struct pci_dn *child;
+   bool found_pe = false;
+   int pe_num;
+   int pe_bus;
+
+   list_for_each_entry(child, >child_list, list) {
+   struct pnv_ioda_pe *pe = (child->pe_number != IODA_INVALID_PE) ?
+   >ioda.pe_array[child->pe_number] :
+   NULL;
+
+   if (!child->busno)
+   continue;
+
+   if ((child->class_code >> 8) == PCI_CLASS_BRIDGE_PCI)
+   invalidate_children_pes(child);
+
+   if (pe) {
+   u8 rid_bus = (pe->rid >> 8) & 0xff;
+
+   if (rid_bus) {
+   pe_num = child->pe_number;
+   pe_bus = rid_bus;
+   found_pe = true;
+   }
+
+   pe->rid &= 0xff;
+   }
+
+   child->busno = 0;
+   }
+
+   if (found_pe) {
+   u16 rid = pe_bus << 8;
+
+   opal_pci_set_pe(phb->opal_id, pe_num, rid, 7, 0, 0, 
OPAL_UNMAP_PE);
+   }
+}
+
+static u8 pre_hook_new_sec_bus(struct pci_dn *pdn, u8 new_secondary_bus)
+{
+   u32 old_secondary_bus = 0;
+
+   if ((pdn->class_code >> 8) != PCI_CLASS_BRIDGE_PCI)
+   return 0;
+
+   pnv_pci_cfg_read(pdn, PCI_SECONDARY_BUS, 1, _secondary_bus);
+   old_secondary_bus &= 0xff;
+
+   if (old_secondary_bus != new_secondary_bus)
+   invalidate_children_pes(pdn);
+
+   return old_secondary_bus;
+}
+
+static void update_children_pes(struct pci_dn *pdn, u8 new_secondary_bus)
+{
+   struct pnv_phb *phb = pdn->phb->private_data;
+   struct pci_dn *child;
+   bool found_pe = false;
+   int pe_num;
+
+   if (!new_secondary_bus)
+   return;
+
+   list_for_each_entry(child, >child_list, list) {
+   struct pnv_ioda_pe *pe = (child->pe_number != IODA_INVALID_PE) ?
+   >ioda.pe_array[child->pe_number] :
+   NULL;
+
+   if (child->busno)
+   continue;
+
+   child->busno = new_secondary_bus;
+
+   if (pe) {
+   pe->rid |= (child->busno << 8);
+   pe_num = child->pe_number;
+   found_pe = true;
+   }
+   }
+
+   if (found_pe) {
+   u16 rid = new_secondary_bus << 8;
+
+   opal_pci_set_pe(phb->opal_id, pe_num, rid, 7, 0, 0, 
OPAL_MAP_PE);
+   }
+}
+
+static void post_hook_new_sec_bus(struct pci_dn *pdn, u8 new_secondary_bus)
+{
+   if ((pdn->class_code >> 8) != PCI_CLASS_BRIDGE_PCI)
+   return;
+
+   update_children_pes(pdn, new_secondary_bus);
+}
+
 int pnv_pci_cfg_write(struct pci_dn *pdn,
  int where, int size, u32 val)
 {
struct pnv_phb *phb = pdn->phb->private_data;
+   u8 old_secondary_bus = 0, new_secondary_bus = 0;
+   int rc;
+
+   if (where == PCI_SECONDARY_BUS) {
+   new_secondary_bus = val & 0xff;
+   old_secondary_bus = pre_hook_new_sec_bus(pdn, 
new_secondary_bus);
+   } else if (where == PCI_PRIMARY_BUS && size > 1) {
+   new_secondary_bus = (val >> 8) & 0xff;
+   old_secondary_bus = pre_hook_new_sec_bus(pdn, 
new_secondary_bus);
+   }
 
-   return pnv_pci_cfg_write_raw(phb->opal_id, pdn->busno, pdn->devfn,
-where, size, val);
+   rc = pnv_pci_cfg_write_raw(phb->opal_id, pdn->busno, pdn->devfn,
+  where, size, val);
+
+   if (new_secondary_bus && old_secondary_bus != new_secondary_bus)
+   post_hook_new_sec_bus(pdn, new_secondary_bus);
+
+   return rc;
 }
 
 #if CONFIG_EEH
-- 
2.20.1



[PATCH RFC v4 9/9] powerpc/powernv/pci: Enable reassigning the bus numbers

2019-03-01 Thread Sergey Miroshnichenko
When the pci=realloc command line switch is enabled (which should only be
set when working on on top of the skiboot with the "core/pci: Sync VFs and
the changes of bdfns between the firmware and the OS" patch serie applied),
PowerNV will not depend on PCIe topology info from DT anymore.

This makes possible to re-enumerate the fabric, assign the new bus numbers
and switch from the pnv_php module to the standard pciehp driver for PCIe
hotplug functionality.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/kernel/pci_dn.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index b1dc788865b9..b823c4177184 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -601,3 +601,15 @@ static void pci_dev_pdn_setup(struct pci_dev *pdev)
pdev->dev.archdata.pci_data = pdn;
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, pci_dev_pdn_setup);
+
+char * __init pcibios_setup(char *str)
+{
+   if (!strncmp(str, "realloc=", 8)) {
+   if (!strncmp(str + 8, "on", 2))
+   pci_add_flags(PCI_REASSIGN_ALL_BUS);
+   } else if (!strncmp(str, "realloc", 7)) {
+   pci_add_flags(PCI_REASSIGN_ALL_BUS);
+   }
+
+   return str;
+}
-- 
2.20.1



[PATCH RFC v4 6/9] powerpc/pci/IOV: Add support for runtime enabling the VFs

2019-03-01 Thread Sergey Miroshnichenko
When called within pcibios_sriov_enable(), the pci_sriov_get_totalvfs(pdev)
returns zero, because the device is yet preparing to enable the VFs.

With this patch it becomes possible to enable VFs via sysfs "sriov_numvfs"
on PowerNV.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/include/asm/pci-bridge.h |  2 +-
 arch/powerpc/kernel/pci_dn.c  | 27 ++-
 arch/powerpc/platforms/powernv/pci-ioda.c |  2 +-
 arch/powerpc/platforms/pseries/pci.c  |  2 +-
 4 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/pci-bridge.h 
b/arch/powerpc/include/asm/pci-bridge.h
index aee4fcc24990..8a30c48caa3e 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -225,7 +225,7 @@ struct pci_dn {
 extern struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,
   int devfn);
 extern struct pci_dn *pci_get_pdn(struct pci_dev *pdev);
-extern struct pci_dn *add_dev_pci_data(struct pci_dev *pdev);
+extern struct pci_dn *add_dev_pci_data(struct pci_dev *pdev, int num_vfs);
 extern void remove_dev_pci_data(struct pci_dev *pdev);
 extern struct pci_dn *pci_add_device_node_info(struct pci_controller *hose,
   struct device_node *dn);
diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index ed1aab424e91..1b1a6198eb28 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -229,18 +229,19 @@ static struct pci_dn *create_pdn(struct pci_dev *pdev, 
struct pci_dn *parent)
return pdn;
 }
 
-struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
+struct pci_dn *add_dev_pci_data(struct pci_dev *pdev, int num_vfs)
 {
 #ifdef CONFIG_PCI_IOV
struct pci_dn *parent, *pdn;
int i;
 
+   pdn = pci_get_pdn(pdev);
+
/* Only support IOV for now */
if (!pdev->is_physfn)
-   return pci_get_pdn(pdev);
+   return pdn;
 
/* Check if VFs have been populated */
-   pdn = pci_get_pdn(pdev);
if (!pdn || (pdn->flags & PCI_DN_FLAG_IOV_VF))
return NULL;
 
@@ -249,28 +250,34 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)
if (!parent)
return NULL;
 
-   for (i = 0; i < pci_sriov_get_totalvfs(pdev); i++) {
+   for (i = 0; i < num_vfs; i++) {
struct eeh_dev *edev __maybe_unused;
+   struct pci_dn *vpdn;
 
-   pdn = add_one_dev_pci_data(parent, i,
-  pci_iov_virtfn_bus(pdev, i),
-  pci_iov_virtfn_devfn(pdev, i));
-   if (!pdn) {
+   vpdn = add_one_dev_pci_data(parent, i,
+   pci_iov_virtfn_bus(pdev, i),
+   pci_iov_virtfn_devfn(pdev, i));
+   if (!vpdn) {
dev_warn(>dev, "%s: Cannot create firmware data 
for VF#%d\n",
 __func__, i);
return NULL;
}
 
+   vpdn->vendor_id = pdn->vendor_id;
+   vpdn->device_id = pdn->device_id;
+   vpdn->class_code = pdn->class_code;
+   vpdn->pci_ext_config_space = 0;
+
 #ifdef CONFIG_EEH
/* Create the EEH device for the VF */
-   edev = eeh_dev_init(pdn);
+   edev = eeh_dev_init(vpdn);
BUG_ON(!edev);
edev->physfn = pdev;
 #endif /* CONFIG_EEH */
}
 #endif /* CONFIG_PCI_IOV */
 
-   return pci_get_pdn(pdev);
+   return pdn;
 }
 
 void remove_dev_pci_data(struct pci_dev *pdev)
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 0631e8196dad..371e60c824d7 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1728,7 +1728,7 @@ int pnv_pcibios_sriov_disable(struct pci_dev *pdev)
 int pnv_pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
 {
/* Allocate PCI data */
-   add_dev_pci_data(pdev);
+   add_dev_pci_data(pdev, num_vfs);
 
return pnv_pci_sriov_enable(pdev, num_vfs);
 }
diff --git a/arch/powerpc/platforms/pseries/pci.c 
b/arch/powerpc/platforms/pseries/pci.c
index 37a77e57893e..054e8bf5d5d3 100644
--- a/arch/powerpc/platforms/pseries/pci.c
+++ b/arch/powerpc/platforms/pseries/pci.c
@@ -205,7 +205,7 @@ int pseries_pci_sriov_enable(struct pci_dev *pdev, u16 
num_vfs)
 int pseries_pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
 {
/* Allocate PCI data */
-   add_dev_pci_data(pdev);
+   add_dev_pci_data(pdev, num_vfs);
return pseries_pci_sriov_enable(pdev, num_vfs);
 }
 
-- 
2.20.1



[PATCH RFC v4 7/9] powerpc/pci: Don't rely on DT is the PCI_REASSIGN_ALL_BUS is set

2019-03-01 Thread Sergey Miroshnichenko
If supported by the platform, endpoint's pci_dn can be created dynamically,
without need to wait for DT updates from the firmware.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/kernel/pci_dn.c | 6 --
 arch/powerpc/platforms/powernv/eeh-powernv.c | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index 1b1a6198eb28..b1dc788865b9 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -561,8 +561,10 @@ void pci_devs_phb_init_dynamic(struct pci_controller *phb)
phb->pci_data = pdn;
}
 
-   /* Update dn->phb ptrs for new phb and children devices */
-   pci_traverse_device_nodes(dn, add_pdn, phb);
+   if (!pci_has_flag(PCI_REASSIGN_ALL_BUS)) {
+   /* Update dn->phb ptrs for new phb and children devices */
+   pci_traverse_device_nodes(dn, add_pdn, phb);
+   }
 }
 
 /** 
diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c 
b/arch/powerpc/platforms/powernv/eeh-powernv.c
index f38078976c5d..40feff2653a0 100644
--- a/arch/powerpc/platforms/powernv/eeh-powernv.c
+++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
@@ -47,7 +47,7 @@ void pnv_pcibios_bus_add_device(struct pci_dev *pdev)
 {
struct pci_dn *pdn = pci_get_pdn(pdev);
 
-   if (!pdev->is_virtfn)
+   if (!pci_has_flag(PCI_REASSIGN_ALL_BUS) && !pdev->is_virtfn)
return;
 
/*
-- 
2.20.1



[PATCH RFC v4 4/9] powerpc/pci: Reduce code duplication in pci_add_device_node_info

2019-03-01 Thread Sergey Miroshnichenko
It is possible now to allocate and fill a new pdn with add_one_dev_pci_data

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/kernel/pci_dn.c | 38 +++-
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index 67ccd7be8344..ed1aab424e91 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -159,15 +159,10 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn 
*parent,
 {
struct pci_dn *pdn;
 
-   /* Except PHB, we always have the parent */
-   if (!parent)
-   return NULL;
-
pdn = kzalloc(sizeof(*pdn), GFP_KERNEL);
if (!pdn)
return NULL;
 
-   pdn->phb = parent->phb;
pdn->parent = parent;
pdn->busno = busno;
pdn->devfn = devfn;
@@ -177,7 +172,10 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn 
*parent,
pdn->pe_number = IODA_INVALID_PE;
INIT_LIST_HEAD(>child_list);
INIT_LIST_HEAD(>list);
-   list_add_tail(>list, >child_list);
+   if (parent) {
+   pdn->phb = parent->phb;
+   list_add_tail(>list, >child_list);
+   }
 
return pdn;
 }
@@ -346,25 +344,29 @@ struct pci_dn *pci_add_device_node_info(struct 
pci_controller *hose,
const __be32 *regs;
struct device_node *parent;
struct pci_dn *pdn;
+   int busno = 0, devfn = 0;
 #ifdef CONFIG_EEH
struct eeh_dev *edev;
 #endif
 
-   pdn = kzalloc(sizeof(*pdn), GFP_KERNEL);
-   if (pdn == NULL)
-   return NULL;
-   dn->data = pdn;
-   pdn->phb = hose;
-   pdn->pe_number = IODA_INVALID_PE;
regs = of_get_property(dn, "reg", NULL);
if (regs) {
u32 addr = of_read_number(regs, 1);
 
/* First register entry is addr (00BBSS00)  */
-   pdn->busno = (addr >> 16) & 0xff;
-   pdn->devfn = (addr >> 8) & 0xff;
+   busno = (addr >> 16) & 0xff;
+   devfn = (addr >> 8) & 0xff;
}
 
+   parent = of_get_parent(dn);
+   pdn = add_one_dev_pci_data(parent ? PCI_DN(parent) : NULL,
+  0, busno, devfn);
+   if (!pdn)
+   return NULL;
+
+   dn->data = pdn;
+   pdn->phb = hose;
+
/* vendor/device IDs and class code */
regs = of_get_property(dn, "vendor-id", NULL);
pdn->vendor_id = regs ? of_read_number(regs, 1) : 0;
@@ -385,14 +387,6 @@ struct pci_dn *pci_add_device_node_info(struct 
pci_controller *hose,
}
 #endif
 
-   /* Attach to parent node */
-   INIT_LIST_HEAD(>child_list);
-   INIT_LIST_HEAD(>list);
-   parent = of_get_parent(dn);
-   pdn->parent = parent ? PCI_DN(parent) : NULL;
-   if (pdn->parent)
-   list_add_tail(>list, >parent->child_list);
-
return pdn;
 }
 EXPORT_SYMBOL_GPL(pci_add_device_node_info);
-- 
2.20.1



[PATCH RFC v4 5/9] powerpc/powernv/ioda: Fix using uninitialized IOMMU group

2019-03-01 Thread Sergey Miroshnichenko
Otherwise there will be a NULL pointer dereferencing in iommu_add_device()
later during activating a newly created VF.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index 3b8b21a70196..0631e8196dad 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1593,6 +1593,9 @@ static void pnv_ioda_setup_vf_PE(struct pci_dev *pdev, 
u16 num_vfs)
 
pnv_pci_ioda2_setup_dma_pe(phb, pe);
 #ifdef CONFIG_IOMMU_API
+   iommu_register_group(>table_group,
+pe->phb->hose->global_number,
+pe->pe_number);
pnv_ioda_setup_bus_iommu_group(pe, >table_group, NULL);
 #endif
}
-- 
2.20.1



[PATCH RFC v4 0/9] powerpc/powernv/pci: Make hotplug self-sufficient, independent of FW and DT

2019-03-01 Thread Sergey Miroshnichenko
This patchset allows switching from the pnv_php module to the standard
pciehp driver for PCIe hotplug functionality, if the platform supports it:
PowerNV working on on top of the skiboot with the "core/pci: Sync VFs and
the changes of bdfns between the firmware and the OS" patch serie applied.

The feature is activated by the "pci=realloc" command line argument.

The goal is ability to hotplug bridges full of devices in the future. The
"Movable BARs" [1] is a platform-independent part of our work in this. The
final part will be movable bus numbers to support inserting a bridge in the
middle of an existing PCIe tree.

Tested on POWER8 PowerNV+PHB3 ppc64le (our Vesnin server) with:
 - the pciehp driver active;
 - the pnv_php driver disabled;
 - The "pci=realloc" argument is passed;
 - surprise hotplug of an NVME disk works;
 - controlled hotplug of a network card with SR-IOV works;
 - activating of SR-IOV on a network card works;
 - [with extra patches] manually initiated (via sysfs) rescan has found
   and turned on a hotplugged bridge;
 - Without "pci=realloc" works just as before.

Changes since v3 [2]:
 - Subject changed;
 - Don't disable EEH during rescan anymore - instead just unfreeze the
   target buses deliberately;
 - Add synchronization with the firmware when changing the PCIe topology;
 - Fixed for VFs;
 - Code cleanup.

Changes since v2:
 - Don't reassign bus numbers on PowerNV by default (to retain the default
   behavior), but only when pci=realloc is passed;
 - Less code affected;
 - pci_add_device_node_info is refactored with add_one_dev_pci_data;
 - Minor code cleanup.

Changes since v1:
 - Fixed build for ppc64le and ppc64be when CONFIG_PCI_IOV is disabled;
 - Fixed build for ppc64e when CONFIG_EEH is disabled;
 - Fixed code style warnings.

[1] https://www.spinics.net/lists/linux-pci/msg79995.html
[2] https://lists.ozlabs.org/pipermail/linuxppc-dev/2018-September/178053.html

Sergey Miroshnichenko (9):
  powerpc/pci: Access PCI config space directly w/o pci_dn
  powerpc/powernv/pci: Suppress an EEH error when reading an empty slot
  powerpc/pci: Create pci_dn on demand
  powerpc/pci: Reduce code duplication in pci_add_device_node_info
  powerpc/powernv/ioda: Fix using uninitialized IOMMU group
  powerpc/pci/IOV: Add support for runtime enabling the VFs
  powerpc/pci: Don't rely on DT is the PCI_REASSIGN_ALL_BUS is set
  powerpc/powernv/pci: Hook up the writes to PCI_SECONDARY_BUS register
  powerpc/powernv/pci: Enable reassigning the bus numbers

 arch/powerpc/include/asm/pci-bridge.h|   2 +-
 arch/powerpc/include/asm/ppc-pci.h   |   1 +
 arch/powerpc/kernel/pci_dn.c | 164 +++
 arch/powerpc/kernel/rtas_pci.c   |  97 ++---
 arch/powerpc/platforms/powernv/eeh-powernv.c |   2 +-
 arch/powerpc/platforms/powernv/pci-ioda.c|   5 +-
 arch/powerpc/platforms/powernv/pci.c | 208 +--
 arch/powerpc/platforms/pseries/pci.c |   2 +-
 8 files changed, 381 insertions(+), 100 deletions(-)

-- 
2.20.1



[PATCH RFC v4 2/9] powerpc/powernv/pci: Suppress an EEH error when reading an empty slot

2019-03-01 Thread Sergey Miroshnichenko
Reading an empty slot returns all ones, which triggers a false
EEH error event on PowerNV. This patch unfreezes the bus where
it has happened.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/include/asm/ppc-pci.h   |  1 +
 arch/powerpc/kernel/pci_dn.c |  2 +-
 arch/powerpc/platforms/powernv/pci.c | 34 
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc-pci.h 
b/arch/powerpc/include/asm/ppc-pci.h
index f67da277d652..737393c54f58 100644
--- a/arch/powerpc/include/asm/ppc-pci.h
+++ b/arch/powerpc/include/asm/ppc-pci.h
@@ -40,6 +40,7 @@ void *traverse_pci_dn(struct pci_dn *root,
  void *(*fn)(struct pci_dn *, void *),
  void *data);
 extern void pci_devs_phb_init_dynamic(struct pci_controller *phb);
+struct pci_dn *pci_bus_to_pdn(struct pci_bus *bus);
 
 /* From rtas_pci.h */
 extern void init_pci_config_tokens (void);
diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index ab147a1909c8..341ed71250f1 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -40,7 +40,7 @@
  * one of PF's bridge. For other devices, their firmware
  * data is linked to that of their bridge.
  */
-static struct pci_dn *pci_bus_to_pdn(struct pci_bus *bus)
+struct pci_dn *pci_bus_to_pdn(struct pci_bus *bus)
 {
struct pci_bus *pbus;
struct device_node *dn;
diff --git a/arch/powerpc/platforms/powernv/pci.c 
b/arch/powerpc/platforms/powernv/pci.c
index 3260250d2029..73c2d0aed996 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -761,6 +761,21 @@ static inline pnv_pci_cfg_check(struct pci_dn *pdn)
 }
 #endif /* CONFIG_EEH */
 
+static int get_bus_pe_number(struct pci_bus *bus)
+{
+   struct pci_dn *pdn = pci_bus_to_pdn(bus);
+   struct pci_dn *child;
+
+   if (!pdn)
+   return IODA_INVALID_PE;
+
+   list_for_each_entry(child, >child_list, list)
+   if (child->pe_number != IODA_INVALID_PE)
+   return child->pe_number;
+
+   return IODA_INVALID_PE;
+}
+
 static int pnv_pci_read_config(struct pci_bus *bus,
   unsigned int devfn,
   int where, int size, u32 *val)
@@ -769,12 +784,23 @@ static int pnv_pci_read_config(struct pci_bus *bus,
struct pci_controller *hose = pci_bus_to_host(bus);
struct pnv_phb *phb = hose->private_data;
int ret;
+   u32 empty_val = 0x;
 
-   *val = 0x;
+   *val = empty_val;
pdn = pci_get_pdn_by_devfn(bus, devfn);
-   if (!pdn)
-   return pnv_pci_cfg_read_raw(phb->opal_id, bus->number, devfn,
-   where, size, val);
+   if (!pdn) {
+   int pe_number = get_bus_pe_number(bus);
+
+   ret = pnv_pci_cfg_read_raw(phb->opal_id, bus->number, devfn,
+  where, size, val);
+
+   if (!ret && (*val == empty_val) && phb->unfreeze_pe)
+   phb->unfreeze_pe(phb, (pe_number == IODA_INVALID_PE) ?
+0xff : pe_number,
+OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
+
+   return ret;
+   }
 
if (!pnv_pci_cfg_check(pdn))
return PCIBIOS_DEVICE_NOT_FOUND;
-- 
2.20.1



[PATCH RFC v4 1/9] powerpc/pci: Access PCI config space directly w/o pci_dn

2019-03-01 Thread Sergey Miroshnichenko
To fetch an updated DT for the newly hotplugged device, OS must explicitly
request it from the firmware via the pnv_php driver.

If pnv_php wasn't triggered/loaded, it is still possible to discover new
devices if PCIe I/O will not stop in absence of the pci_dn structure.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/kernel/rtas_pci.c   | 97 +++-
 arch/powerpc/platforms/powernv/pci.c | 64 --
 2 files changed, 109 insertions(+), 52 deletions(-)

diff --git a/arch/powerpc/kernel/rtas_pci.c b/arch/powerpc/kernel/rtas_pci.c
index c2b148b1634a..f675b5ecb5bc 100644
--- a/arch/powerpc/kernel/rtas_pci.c
+++ b/arch/powerpc/kernel/rtas_pci.c
@@ -55,10 +55,26 @@ static inline int config_access_valid(struct pci_dn *dn, 
int where)
return 0;
 }
 
-int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
+static int rtas_read_raw_config(unsigned long buid, int busno, unsigned int 
devfn,
+   int where, int size, u32 *val)
 {
int returnval = -1;
-   unsigned long buid, addr;
+   unsigned long addr = rtas_config_addr(busno, devfn, where);
+   int ret;
+
+   if (buid) {
+   ret = rtas_call(ibm_read_pci_config, 4, 2, ,
+   addr, BUID_HI(buid), BUID_LO(buid), size);
+   } else {
+   ret = rtas_call(read_pci_config, 2, 2, , addr, size);
+   }
+   *val = returnval;
+
+   return ret;
+}
+
+int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
+{
int ret;
 
if (!pdn)
@@ -71,16 +87,8 @@ int rtas_read_config(struct pci_dn *pdn, int where, int 
size, u32 *val)
return PCIBIOS_SET_FAILED;
 #endif
 
-   addr = rtas_config_addr(pdn->busno, pdn->devfn, where);
-   buid = pdn->phb->buid;
-   if (buid) {
-   ret = rtas_call(ibm_read_pci_config, 4, 2, ,
-   addr, BUID_HI(buid), BUID_LO(buid), size);
-   } else {
-   ret = rtas_call(read_pci_config, 2, 2, , addr, size);
-   }
-   *val = returnval;
-
+   ret = rtas_read_raw_config(pdn->phb->buid, pdn->busno, pdn->devfn,
+  where, size, val);
if (ret)
return PCIBIOS_DEVICE_NOT_FOUND;
 
@@ -98,18 +106,44 @@ static int rtas_pci_read_config(struct pci_bus *bus,
 
pdn = pci_get_pdn_by_devfn(bus, devfn);
 
-   /* Validity of pdn is checked in here */
-   ret = rtas_read_config(pdn, where, size, val);
-   if (*val == EEH_IO_ERROR_VALUE(size) &&
-   eeh_dev_check_failure(pdn_to_eeh_dev(pdn)))
-   return PCIBIOS_DEVICE_NOT_FOUND;
+   if (pdn) {
+   /* Validity of pdn is checked in here */
+   ret = rtas_read_config(pdn, where, size, val);
+
+   if (*val == EEH_IO_ERROR_VALUE(size) &&
+   eeh_dev_check_failure(pdn_to_eeh_dev(pdn)))
+   ret = PCIBIOS_DEVICE_NOT_FOUND;
+   } else {
+   struct pci_controller *phb = pci_bus_to_host(bus);
+
+   ret = rtas_read_raw_config(phb->buid, bus->number, devfn,
+  where, size, val);
+   }
 
return ret;
 }
 
+static int rtas_write_raw_config(unsigned long buid, int busno, unsigned int 
devfn,
+int where, int size, u32 val)
+{
+   unsigned long addr = rtas_config_addr(busno, devfn, where);
+   int ret;
+
+   if (buid) {
+   ret = rtas_call(ibm_write_pci_config, 5, 1, NULL, addr,
+   BUID_HI(buid), BUID_LO(buid), size, (ulong)val);
+   } else {
+   ret = rtas_call(write_pci_config, 3, 1, NULL, addr, size, 
(ulong)val);
+   }
+
+   if (ret)
+   return PCIBIOS_DEVICE_NOT_FOUND;
+
+   return PCIBIOS_SUCCESSFUL;
+}
+
 int rtas_write_config(struct pci_dn *pdn, int where, int size, u32 val)
 {
-   unsigned long buid, addr;
int ret;
 
if (!pdn)
@@ -122,15 +156,8 @@ int rtas_write_config(struct pci_dn *pdn, int where, int 
size, u32 val)
return PCIBIOS_SET_FAILED;
 #endif
 
-   addr = rtas_config_addr(pdn->busno, pdn->devfn, where);
-   buid = pdn->phb->buid;
-   if (buid) {
-   ret = rtas_call(ibm_write_pci_config, 5, 1, NULL, addr,
-   BUID_HI(buid), BUID_LO(buid), size, (ulong) val);
-   } else {
-   ret = rtas_call(write_pci_config, 3, 1, NULL, addr, size, 
(ulong)val);
-   }
-
+   ret = rtas_write_raw_config(pdn->phb->buid, pdn->busno, pdn->devfn,
+   where, size, val);
if (ret)
return PCIBIOS_DEVICE_NOT_FOUND;
 
@@ -141,12 +168,20 @@ static int rtas_pci_write_config(struct pci_bus *bus,
 unsigned int devfn,
 int where, int size, u32 val)
 {
-   struct 

[PATCH RFC v4 3/9] powerpc/pci: Create pci_dn on demand

2019-03-01 Thread Sergey Miroshnichenko
If a struct pci_dn hasn't yet been created for the PCIe device (there was
no DT node for it), allocate this structure and fill with info read from
the device directly.

Signed-off-by: Sergey Miroshnichenko 
---
 arch/powerpc/kernel/pci_dn.c | 79 
 1 file changed, 72 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index 341ed71250f1..67ccd7be8344 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -33,6 +33,8 @@
 #include 
 #include 
 
+static struct pci_dn *create_pdn(struct pci_dev *pdev, struct pci_dn *parent);
+
 /*
  * The function is used to find the firmware data of one
  * specific PCI device, which is attached to the indicated
@@ -65,6 +67,9 @@ struct pci_dn *pci_bus_to_pdn(struct pci_bus *bus)
dn = pci_bus_to_OF_node(pbus);
pdn = dn ? PCI_DN(dn) : NULL;
 
+   if (!pdn && pbus->self)
+   pdn = pbus->self->dev.archdata.pci_data;
+
return pdn;
 }
 
@@ -74,10 +79,13 @@ struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,
struct device_node *dn = NULL;
struct pci_dn *parent, *pdn;
struct pci_dev *pdev = NULL;
+   bool pdev_found = false;
 
/* Fast path: fetch from PCI device */
list_for_each_entry(pdev, >devices, bus_list) {
if (pdev->devfn == devfn) {
+   pdev_found = true;
+
if (pdev->dev.archdata.pci_data)
return pdev->dev.archdata.pci_data;
 
@@ -86,6 +94,9 @@ struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,
}
}
 
+   if (!pdev_found)
+   pdev = NULL;
+
/* Fast path: fetch from device node */
pdn = dn ? PCI_DN(dn) : NULL;
if (pdn)
@@ -98,9 +109,12 @@ struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,
 
list_for_each_entry(pdn, >child_list, list) {
if (pdn->busno == bus->number &&
-pdn->devfn == devfn)
-return pdn;
-}
+   pdn->devfn == devfn) {
+   if (pdev)
+   pdev->dev.archdata.pci_data = pdn;
+   return pdn;
+   }
+   }
 
return NULL;
 }
@@ -130,14 +144,15 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)
 
list_for_each_entry(pdn, >child_list, list) {
if (pdn->busno == pdev->bus->number &&
-   pdn->devfn == pdev->devfn)
+   pdn->devfn == pdev->devfn) {
+   pdev->dev.archdata.pci_data = pdn;
return pdn;
+   }
}
 
-   return NULL;
+   return create_pdn(pdev, parent);
 }
 
-#ifdef CONFIG_PCI_IOV
 static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,
   int vf_index,
   int busno, int devfn)
@@ -156,7 +171,9 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn 
*parent,
pdn->parent = parent;
pdn->busno = busno;
pdn->devfn = devfn;
+   #ifdef CONFIG_PCI_IOV
pdn->vf_index = vf_index;
+   #endif /* CONFIG_PCI_IOV */
pdn->pe_number = IODA_INVALID_PE;
INIT_LIST_HEAD(>child_list);
INIT_LIST_HEAD(>list);
@@ -164,7 +181,55 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn 
*parent,
 
return pdn;
 }
-#endif
+
+static struct pci_dn *create_pdn(struct pci_dev *pdev, struct pci_dn *parent)
+{
+   struct pci_dn *pdn = NULL;
+
+   if (!parent)
+   return NULL;
+
+   pdn = add_one_dev_pci_data(parent, 0, pdev->bus->busn_res.start, 
pdev->devfn);
+   dev_info(>dev, "Create a new pdn for devfn %2x\n", pdev->devfn / 
8);
+
+   if (pdn) {
+   #ifdef CONFIG_EEH
+   struct eeh_dev *edev;
+   #endif /* CONFIG_EEH */
+   u32 class_code;
+   u16 device_id;
+   u16 vendor_id;
+
+   #ifdef CONFIG_EEH
+   edev = eeh_dev_init(pdn);
+   if (!edev) {
+   kfree(pdn);
+   dev_err(>dev, "%s: Failed to allocate edev\n", 
__func__);
+   return NULL;
+   }
+   #endif /* CONFIG_EEH */
+
+   pci_bus_read_config_word(pdev->bus, pdev->devfn,
+PCI_VENDOR_ID, _id);
+   pdn->vendor_id = vendor_id;
+
+   pci_bus_read_config_word(pdev->bus, pdev->devfn,
+PCI_DEVICE_ID, _id);
+   pdn->device_id = device_id;
+
+   pci_bus_read_config_dword(pdev->bus, pdev->devfn,
+ PCI_CLASS_REVISION, _code);
+   class_code >>= 8;
+   pdn->class_code = class_code;
+
+   

Re: [alsa-devel] [PATCH] ASoC: cs42xx8: Remove S32_LE in format list

2019-03-01 Thread Timur Tabi

On 3/1/19 12:32 AM, S.j. Wang wrote:

This case is covered by S24_LE I think.  The S32_LE means the data is 32bit and 
slot width
Is 32bit, this is not in data sheet.


The problem is that if you have 32-bit samples in your audio file, and 
you want to play them, then software (e.g. alsalib) will need to convert 
the audio to 24-bit before sending it to hardware.  This is unnecessary 
because the hardware can "convert" the sample to 24-bit automatically by 
ignoring the lower 8 bits.


I think a lot of codecs do this already.


[PATCH v2] powerpc/mm: fix "section_base" set but not used

2019-03-01 Thread Qian Cai
The commit 24b6d4164348 ("mm: pass the vmem_altmap to vmemmap_free")
removed a line in vmemmap_free(),

altmap = to_vmem_altmap((unsigned long) section_base);

but left a variable no longer used.

arch/powerpc/mm/init_64.c: In function 'vmemmap_free':
arch/powerpc/mm/init_64.c:277:16: error: variable 'section_base' set but
not used [-Werror=unused-but-set-variable]

Signed-off-by: Qian Cai 
---

v2: improve the commit message.

 arch/powerpc/mm/init_64.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index a5091c034747..a4c155af1597 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -274,7 +274,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long 
end,
 
for (; start < end; start += page_size) {
unsigned long nr_pages, addr;
-   struct page *section_base;
struct page *page;
 
/*
@@ -290,7 +289,6 @@ void __ref vmemmap_free(unsigned long start, unsigned long 
end,
continue;
 
page = pfn_to_page(addr >> PAGE_SHIFT);
-   section_base = pfn_to_page(vmemmap_section_start(start));
nr_pages = 1 << page_order;
base_pfn = PHYS_PFN(addr);
 
-- 
2.17.2 (Apple Git-113)



Re: [PATCH v4 4/4] hugetlb: allow to free gigantic pages regardless of the configuration

2019-03-01 Thread Alexandre Ghiti

On 03/01/2019 02:33 PM, Vlastimil Babka wrote:

On 3/1/19 2:21 PM, Alexandre Ghiti wrote:

I collected mistakes here: domain name expired and no mailing list added :)
Really sorry about that, I missed the whole discussion (if any).
Could someone forward it to me (if any) ? Thanks !

Bounced you David and Mike's discussion (4 messages total). AFAICS that
was all.


Thank you Vlastimil, I got them.

Thanks,


Re: [PATCH v4 4/4] hugetlb: allow to free gigantic pages regardless of the configuration

2019-03-01 Thread Vlastimil Babka
On 3/1/19 2:21 PM, Alexandre Ghiti wrote:
> I collected mistakes here: domain name expired and no mailing list added :)
> Really sorry about that, I missed the whole discussion (if any).
> Could someone forward it to me (if any) ? Thanks !

Bounced you David and Mike's discussion (4 messages total). AFAICS that
was all.


Re: PROBLEM: monotonic clock going backwards on ppc64

2019-03-01 Thread Jakub Drnec
Hi,

>> Decreasing the realtime clock across the y2k38 threshold is one reliable way 
>> to reproduce.
>> Allegedly this can also happen just by running ntpd, I have not managed to 
>> reproduce that other
>> than booting with rtc at >2038 and then running ntp.

> Isn't it the expected behavior. Here is what I see for powermac:
>...gives us a time in the documented 1904..2040 year range. I decided not

This (or some related issue involving monotonic time going wonky) surfaced on a 
system running 4.5 kernel with sane clock values running ntpd. It may not be 
limited to setting the clock beyond 2038, that is just a convenient way to 
reproduce something visibly wrong.

If the "ntpd-related monotonic" issue is separate from what I reported, I did 
not find anything in the commit history that looks likely to have fixed that, 
so I think that is still a thing.

Another way of looking at the issue is that when you set the clock beyond 2038 
(or the mystery ntpd thing happens), vdso and syscall versions of clock_gettime 
start reporting wildly different values for CLOCK_MONOTONIC. If someone manages 
to somehow interlace calls to those two assuming they are consistent, crazy 
bugs will ensue...

Regards,
Jakub


Re: PROBLEM: monotonic clock going backwards on ppc64

2019-03-01 Thread Michael Ellerman
Hi Jakub,

[Cc += Timekeeping maintainers]

"Jakub Drnec"  writes:
> Hi all,
>
> I think I observed a potential problem, is this the correct place to report 
> it? (CC me, not on list)
>
> [1.] One line summary: monotonic clock can be made to decrease on ppc64
> [2.] Full description:
> Setting the realtime clock can sometimes make the monotonic clock go back by 
> over a hundred years.
> Decreasing the realtime clock across the y2k38 threshold is one reliable way 
> to reproduce.
> Allegedly this can also happen just by running ntpd, I have not managed to 
> reproduce that other
> than booting with rtc at >2038 and then running ntp.
> When this happens, anything with timers (e.g. openjdk) breaks rather badly.

Thanks for the report.

> The problem seems to be in vDSO code in 
> arch/powerpc/kernel/vdso64/gettimeofday.S.

You're right, the wall-to-monotonic offset (wtom_clock_sec) is a signed
32-bit value, so that seems like it's going to have problems.

If I do `date -s 2037-1-1` I see:

[   26.024061] update_vsyscall: tk->wall_to_monotonic.tv_sec -2114341175
[   26.042633] update_vsyscall: vdso_data->wtom_clock_sec-2114341175

Which looks sane.

But then 2040-1-1 shows:

[   32.617020] update_vsyscall: tk->wall_to_monotonic.tv_sec -2208949168
[   32.632642] update_vsyscall: vdso_data->wtom_clock_sec 2086018128

ie. the larger negative offset has overflowed and become positive.

But then when we go back to 2037 we get a negative offset again and
monotonic time appears to go backward and things are unhappy.

I don't know this code well, but the patch below *appears* to work. I'll
have a closer look on Monday.

cheers


diff --git a/arch/powerpc/include/asm/vdso_datapage.h 
b/arch/powerpc/include/asm/vdso_datapage.h
index 1afe90ade595..139133ec21d5 100644
--- a/arch/powerpc/include/asm/vdso_datapage.h
+++ b/arch/powerpc/include/asm/vdso_datapage.h
@@ -82,7 +82,7 @@ struct vdso_data {
__u32 icache_block_size;/* L1 i-cache block size */
__u32 dcache_log_block_size;/* L1 d-cache log block size */
__u32 icache_log_block_size;/* L1 i-cache log block size */
-   __s32 wtom_clock_sec;   /* Wall to monotonic clock */
+   __s64 wtom_clock_sec;   /* Wall to monotonic clock */
__s32 wtom_clock_nsec;
struct timespec stamp_xtime;/* xtime as at tb_orig_stamp */
__u32 stamp_sec_fraction;   /* fractional seconds of stamp_xtime */
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S 
b/arch/powerpc/kernel/vdso64/gettimeofday.S
index a4ed9edfd5f0..1f324c28705b 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -92,7 +92,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 * At this point, r4,r5 contain our sec/nsec values.
 */
 
-   lwa r6,WTOM_CLOCK_SEC(r3)
+   ld  r6,WTOM_CLOCK_SEC(r3)
lwa r9,WTOM_CLOCK_NSEC(r3)
 
/* We now have our result in r6,r9. We create a fake dependency
@@ -125,7 +125,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
bne cr6,75f
 
/* CLOCK_MONOTONIC_COARSE */
-   lwa r6,WTOM_CLOCK_SEC(r3)
+   ld  r6,WTOM_CLOCK_SEC(r3)
lwa r9,WTOM_CLOCK_NSEC(r3)
 
/* check if counter has updated */


> [3.] Keywords: gettimeofday, ppc64, vdso
> [4.] Kernel information
> [4.1.] Kernel version: any (tested on 4.19)
> [4.2.] Kernel .config file: any
> [5.] Most recent kernel version which did not have the bug: not a regression
> [6.] Output of Oops..: not applicable
> [7.] Example program which triggers the problem
> --- testcase.c
> #include 
> #include 
> #include 
> #include 
>
> long get_time() {
>   struct timespec tp;
>   if (clock_gettime(CLOCK_MONOTONIC, ) != 0) {
> perror("clock_gettime failed");
> exit(1);
>   }
>   long result = tp.tv_sec + tp.tv_nsec / 10;
>   return result;
> }
>
> int main() {
>   printf("monitoring monotonic clock...\n");
>   long last = get_time();
>   while(1) {
> long now = get_time();
> if (now < last) {
>   printf("clock went backwards by %ld seconds!\n",
> last - now);
> }
> last = now;
> sleep(1);
>   }
>   return 0;
> }
> ---
> when running
> # date -s 2040-1-1
> # date -s 2037-1-1
> program outputs: clock went backwards by 4294967295 seconds!
>
> [8.] Environment: any ppc64, currently reproducing on qemu-system-ppc64le 
> running debian unstable
> [X.] Other notes, patches, fixes, workarounds:
> The problem seems to be in vDSO code in 
> arch/powerpc/kernel/vdso64/gettimeofday.S.
> (possibly because some values used in the calculation are only 32 bit?)
> Slightly silly workaround: 
> nuke the "cmpwi cr1,r3,CLOCK_MONOTONIC" in __kernel_clock_gettime
> Now it always goes through the syscall fallback which does not have the same 
> problem.
>
> Regards,
> Jakub Drnec


Re: [PATCH v4 4/4] hugetlb: allow to free gigantic pages regardless of the configuration

2019-03-01 Thread Alexandre Ghiti

On 03/01/2019 07:25 AM, Alex Ghiti wrote:

On 2/28/19 5:26 PM, Mike Kravetz wrote:

On 2/28/19 12:23 PM, Dave Hansen wrote:

On 2/28/19 11:50 AM, Mike Kravetz wrote:

On 2/28/19 11:13 AM, Dave Hansen wrote:
+    if (hstate_is_gigantic(h) && 
!IS_ENABLED(CONFIG_CONTIG_ALLOC)) {

+    spin_lock(_lock);
+    if (count > persistent_huge_pages(h)) {
+    spin_unlock(_lock);
+    return -EINVAL;
+    }
+    goto decrease_pool;
+    }

This choice confuses me.  The "Decrease the pool size" code already
works and the code just falls through to it after skipping all the
"Increase the pool size" code.

Why did did you need to add this case so early?  Why not just let it
fall through like before?

I assume you are questioning the goto, right?  You are correct in that
it is unnecessary and we could just fall through.

Yeah, it just looked odd to me.


(Dave I do not receive your answers, I don't know why).


I collected mistakes here: domain name expired and no mailing list added :)
Really sorry about that, I missed the whole discussion (if any).
Could someone forward it to me (if any) ? Thanks !


I'd rather avoid useless checks when we already know they won't
be met and I think that makes the code more understandable.

But that's up to you for the next version.

Thanks


However, I wonder if we might want to consider a wacky condition 
that the
above check would prevent.  Consider a system/configuration with 5 
gigantic
pages allocated at boot time.  Also CONFIG_CONTIG_ALLOC is not 
enabled, so

it is not possible to allocate gigantic pages after boot.

Suppose the admin decreased the number of gigantic pages to 3.  
However, all

gigantic pages were in use.  So, 2 gigantic pages are now 'surplus'.
h->nr_huge_pages == 5 and h->surplus_huge_pages == 2, so
persistent_huge_pages() == 3.

Now suppose the admin wanted to increase the number of gigantic 
pages to 5.

The above check would prevent this.  However, we do not need to really
'allocate' two gigantic pages.  We can simply convert the surplus 
pages.


I admit this is a wacky condition.  The ability to 'free' gigantic 
pages
at runtime if !CONFIG_CONTIG_ALLOC makes it possible.  I don't 
necessairly

think we should consider this.  hugetlbfs code just makes me think of
wacky things. :)

I think you're saying that the newly-added check is overly-restrictive.
  If we "fell through" like I was suggesting we would get better 
behavior.

At first, I did not think it overly restrictive.  But, I believe we can
just eliminate that check for gigantic pages.  If 
!CONFIG_CONTIG_ALLOC and
this is a request to allocate more gigantic pages, 
alloc_pool_huge_page()

should return NULL.

The only potential issue I see is that in the past we have returned 
EINVAL

if !CONFIG_CONTIG_ALLOC and someone attempted to increase the pool size.
Now, we will not increase the pool and will not return an error.  Not 
sure

if that is an acceptable change in user behavior.


If I may, I think that this is the kind of info the user wants to have 
and we should

return an error when it is not possible to allocate runtime huge pages.
I already noticed that if someone asks for 10 huge pages, and only 5 
are allocated,

no error is returned to the user and I found that surprising.



If we go down this path, then we could remove this change as well:


I agree that in that path, we do not need the following change neither.



@@ -2428,7 +2442,9 @@ static ssize_t 
__nr_hugepages_store_common(bool obey_mempolicy,

  } else
  nodes_allowed = _states[N_MEMORY];
  -    h->max_huge_pages = set_max_huge_pages(h, count, nodes_allowed);
+    err = set_max_huge_pages(h, count, nodes_allowed);
+    if (err)
+    goto out;
    if (nodes_allowed != _states[N_MEMORY])
  NODEMASK_FREE(nodes_allowed);

Do note that I beleive there is a bug the above change.  The code after
the out label is:

out:
 NODEMASK_FREE(nodes_allowed);
 return err;
}

With the new goto, we need the same
if (nodes_allowed != _states[N_MEMORY]) before NODEMASK_FREE().

Sorry, I missed this in previous versions.


Oh right, I'm really sorry I missed that, thank you for noticing.





[PATCH] powerpc/64s: Fix unrelocated interrupt trampoline address test

2019-03-01 Thread Nicholas Piggin
The recent commit got this test wrong, it declared the assembler
symbols the wrong way, and also used the wrong symbol name
(xxx_start rather than start_xxx, see asm/head-64.h).

Fixes: ccd477028a ("powerpc/64s: Fix HV NMI vs HV interrupt recoverability 
test")
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/asm-prototypes.h | 8 
 arch/powerpc/include/asm/sections.h   | 7 +++
 arch/powerpc/kernel/exceptions-64s.S  | 8 
 arch/powerpc/kernel/traps.c   | 9 +
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/asm-prototypes.h 
b/arch/powerpc/include/asm/asm-prototypes.h
index 0f8326644fa4..1d911f68a23b 100644
--- a/arch/powerpc/include/asm/asm-prototypes.h
+++ b/arch/powerpc/include/asm/asm-prototypes.h
@@ -51,14 +51,6 @@ int exit_vmx_usercopy(void);
 int enter_vmx_ops(void);
 void *exit_vmx_ops(void *dest);
 
-/* Exceptions */
-#ifdef CONFIG_PPC_POWERNV
-extern unsigned long real_trampolines_start;
-extern unsigned long real_trampolines_end;
-extern unsigned long virt_trampolines_start;
-extern unsigned long virt_trampolines_end;
-#endif
-
 /* Traps */
 long machine_check_early(struct pt_regs *regs);
 long hmi_exception_realmode(struct pt_regs *regs);
diff --git a/arch/powerpc/include/asm/sections.h 
b/arch/powerpc/include/asm/sections.h
index e335a8f846af..4a1664a8658d 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -17,6 +17,13 @@ extern char __end_interrupts[];
 extern char __prom_init_toc_start[];
 extern char __prom_init_toc_end[];
 
+#ifdef CONFIG_PPC_POWERNV
+extern char start_real_trampolines[];
+extern char end_real_trampolines[];
+extern char start_virt_trampolines[];
+extern char end_virt_trampolines[];
+#endif
+
 static inline int in_kernel_text(unsigned long addr)
 {
if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
diff --git a/arch/powerpc/kernel/exceptions-64s.S 
b/arch/powerpc/kernel/exceptions-64s.S
index d2e9fc968655..6f0057566a80 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -70,10 +70,10 @@ OPEN_FIXED_SECTION(virt_vectors,0x4000, 0x5900)
 OPEN_FIXED_SECTION(virt_trampolines,0x5900, 0x7000)
 
 #ifdef CONFIG_PPC_POWERNV
-   .globl real_trampolines_start
-   .globl real_trampolines_end
-   .globl virt_trampolines_start
-   .globl virt_trampolines_end
+   .globl start_real_trampolines
+   .globl end_real_trampolines
+   .globl start_virt_trampolines
+   .globl end_virt_trampolines
 #endif
 
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 12b54908c15d..ee7c6cb876ba 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -426,12 +426,13 @@ void hv_nmi_check_nonrecoverable(struct pt_regs *regs)
goto nonrecoverable;
if ((nip >= 0xf80 && nip < 0xfa0) || (nip >= 0x4f80 && nip < 0x4fa0))
goto nonrecoverable;
+
/* Trampoline code runs un-relocated so subtract kbase. */
-   if (nip >= real_trampolines_start - kbase &&
-   nip < real_trampolines_end - kbase)
+   if (nip >= (unsigned long)(start_real_trampolines - kbase) &&
+   nip < (unsigned long)(end_real_trampolines - kbase))
goto nonrecoverable;
-   if (nip >= virt_trampolines_start - kbase &&
-   nip < virt_trampolines_end - kbase)
+   if (nip >= (unsigned long)(start_virt_trampolines - kbase) &&
+   nip < (unsigned long)(end_virt_trampolines - kbase))
goto nonrecoverable;
return;
 
-- 
2.18.0



Re: [PATCH] ASoC: fsl_asrc: add protection for the asrc of older version

2019-03-01 Thread Mark Brown
On Fri, Mar 01, 2019 at 06:55:25AM +, S.j. Wang wrote:

> > Alternatively, I feel instead of error-out at here, should we add a HW
> > constraint or at least fence it off at the beginning of the hw_params()? 
> > This
> > is actually nothing specific to the pair-request function but a hardware
> > constraint.

> How about add constraint in startup?
> static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
>struct snd_soc_dai *dai)
> {
>struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
> 
>if (asrc_priv->channel_bits == 3) {
>snd_pcm_hw_constraint_step(substream->runtime, 0,
>   SNDRV_PCM_HW_PARAM_CHANNELS, 2);
>}
> 
>return 0;
> }

Yes, that's definitely good - the general idea is that we should never
need to return an error from hw_params() as the constraints code will
have filtered out any invalid configurations before they get that far.


signature.asc
Description: PGP signature


[PATCH v9 11/11] powerpc/32s: set up an early static hash table for KASAN.

2019-03-01 Thread Christophe Leroy
KASAN requires early activation of hash table, before memblock()
functions are available.

This patch implements an early hash_table statically defined in
__initdata.

During early boot, a single page table is used.

For hash32, when doing the final init, one page table is allocated
for each PGD entry because of the _PAGE_HASHPTE flag which can't be
common to several virt pages. This is done after memblock get
available but before switching to the final hash table, otherwise
there are issues with TLB flushing due to the shared entries.

For hash32, the zero shadow page gets mapped with PAGE_READONLY instead
of PAGE_KERNEL_RO, because the PP bits don't provide a RO kernel, so
PAGE_KERNEL_RO is equivalent to PAGE_KERNEL. By using PAGE_READONLY,
the page is RO for both kernel and user, but this is not a security issue
as it contains only zeroes.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/kasan.h  |  1 +
 arch/powerpc/kernel/head_32.S | 43 ++---
 arch/powerpc/mm/kasan/kasan_init_32.c | 51 ++-
 arch/powerpc/mm/mmu_decl.h|  1 +
 4 files changed, 79 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
index 74a4ba9fb8a3..c9fe0369a8fc 100644
--- a/arch/powerpc/include/asm/kasan.h
+++ b/arch/powerpc/include/asm/kasan.h
@@ -29,6 +29,7 @@
 
 #ifdef CONFIG_KASAN
 void kasan_early_init(void);
+void kasan_mmu_init(void);
 void kasan_init(void);
 #else
 static inline void kasan_init(void) { }
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index e644aab2cf5b..7f7fbdd73b79 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -160,6 +160,10 @@ __after_mmu_off:
bl  flush_tlbs
 
bl  initial_bats
+   bl  load_segment_registers
+#ifdef CONFIG_KASAN
+   bl  early_hash_table
+#endif
 #if defined(CONFIG_BOOTX_TEXT)
bl  setup_disp_bat
 #endif
@@ -205,7 +209,7 @@ __after_mmu_off:
  */
 turn_on_mmu:
mfmsr   r0
-   ori r0,r0,MSR_DR|MSR_IR
+   ori r0,r0,MSR_DR|MSR_IR|MSR_RI
mtspr   SPRN_SRR1,r0
lis r0,start_here@h
ori r0,r0,start_here@l
@@ -881,11 +885,24 @@ _ENTRY(__restore_cpu_setup)
blr
 #endif /* !defined(CONFIG_PPC_BOOK3S_32) */
 
-
 /*
  * Load stuff into the MMU.  Intended to be called with
  * IR=0 and DR=0.
  */
+#ifdef CONFIG_KASAN
+early_hash_table:
+   sync/* Force all PTE updates to finish */
+   isync
+   tlbia   /* Clear all TLB entries */
+   sync/* wait for tlbia/tlbie to finish */
+   TLBSYNC /* ... on all CPUs */
+   /* Load the SDR1 register (hash table base & size) */
+   lis r6, early_hash - PAGE_OFFSET@h
+   ori r6, r6, 3   /* 256kB table */
+   mtspr   SPRN_SDR1, r6
+   blr
+#endif
+
 load_up_mmu:
sync/* Force all PTE updates to finish */
isync
@@ -897,14 +914,6 @@ load_up_mmu:
tophys(r6,r6)
lwz r6,_SDR1@l(r6)
mtspr   SPRN_SDR1,r6
-   li  r0,16   /* load up segment register values */
-   mtctr   r0  /* for context 0 */
-   lis r3,0x2000   /* Ku = 1, VSID = 0 */
-   li  r4,0
-3: mtsrin  r3,r4
-   addir3,r3,0x111 /* increment VSID */
-   addis   r4,r4,0x1000/* address of next segment */
-   bdnz3b
 
 /* Load the BAT registers with the values set up by MMU_init.
MMU_init takes care of whether we're on a 601 or not. */
@@ -926,6 +935,17 @@ BEGIN_MMU_FTR_SECTION
 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
blr
 
+load_segment_registers:
+   li  r0, 16  /* load up segment register values */
+   mtctr   r0  /* for context 0 */
+   lis r3, 0x2000  /* Ku = 1, VSID = 0 */
+   li  r4, 0
+3: mtsrin  r3, r4
+   addir3, r3, 0x111   /* increment VSID */
+   addis   r4, r4, 0x1000  /* address of next segment */
+   bdnz3b
+   blr
+
 /*
  * This is where the main kernel code starts.
  */
@@ -961,6 +981,9 @@ start_here:
bl  __save_cpu_setup
bl  MMU_init
 BEGIN_MMU_FTR_SECTION
+#ifdef CONFIG_KASAN
+   bl  kasan_mmu_init
+#endif
bl  MMU_init_hw_patch
 END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
 
diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c 
b/arch/powerpc/mm/kasan/kasan_init_32.c
index cc788917ce38..f6dbc537c051 100644
--- a/arch/powerpc/mm/kasan/kasan_init_32.c
+++ b/arch/powerpc/mm/kasan/kasan_init_32.c
@@ -39,7 +39,10 @@ static int kasan_init_shadow_page_tables(unsigned long 
k_start, unsigned long k_
 
if (!new)
return -ENOMEM;
-   kasan_populate_pte(new, PAGE_KERNEL_RO);
+   if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))

[PATCH v9 10/11] powerpc/32s: move hash code patching out of MMU_init_hw()

2019-03-01 Thread Christophe Leroy
For KASAN, hash table handling will be activated early for
accessing to KASAN shadow areas.

In order to avoid any modification of the hash functions while
they are still used with the early hash table, the code patching
is moved out of MMU_init_hw() and put close to the big-bang switch
to the final hash table.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/head_32.S |  3 +++
 arch/powerpc/mm/mmu_decl.h|  1 +
 arch/powerpc/mm/ppc_mmu_32.c  | 36 ++--
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index 02229c005853..e644aab2cf5b 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -960,6 +960,9 @@ start_here:
bl  machine_init
bl  __save_cpu_setup
bl  MMU_init
+BEGIN_MMU_FTR_SECTION
+   bl  MMU_init_hw_patch
+END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
 
 /*
  * Go back to running unmapped so we can load up new values
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index 74ff61dabcb1..d726ff776054 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -130,6 +130,7 @@ extern void wii_memory_fixups(void);
  */
 #ifdef CONFIG_PPC32
 extern void MMU_init_hw(void);
+void MMU_init_hw_patch(void);
 unsigned long mmu_mapin_ram(unsigned long base, unsigned long top);
 #endif
 
diff --git a/arch/powerpc/mm/ppc_mmu_32.c b/arch/powerpc/mm/ppc_mmu_32.c
index 2d5b0d50fb31..38c0e28c21e1 100644
--- a/arch/powerpc/mm/ppc_mmu_32.c
+++ b/arch/powerpc/mm/ppc_mmu_32.c
@@ -39,6 +39,7 @@
 struct hash_pte *Hash, *Hash_end;
 unsigned long Hash_size, Hash_mask;
 unsigned long _SDR1;
+static unsigned int hash_mb, hash_mb2;
 
 struct ppc_bat BATS[8][2]; /* 8 pairs of IBAT, DBAT */
 
@@ -308,7 +309,6 @@ void hash_preload(struct mm_struct *mm, unsigned long ea,
  */
 void __init MMU_init_hw(void)
 {
-   unsigned int hmask, mb, mb2;
unsigned int n_hpteg, lg_n_hpteg;
 
if (!mmu_has_feature(MMU_FTR_HPTE_TABLE))
@@ -349,20 +349,30 @@ void __init MMU_init_hw(void)
   (unsigned long long)(total_memory >> 20), Hash_size >> 10, Hash);
 
 
-   /*
-* Patch up the instructions in hashtable.S:create_hpte
-*/
-   if ( ppc_md.progress ) ppc_md.progress("hash:patch", 0x345);
Hash_mask = n_hpteg - 1;
-   hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
-   mb2 = mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg;
+   hash_mb2 = hash_mb = 32 - LG_HPTEG_SIZE - lg_n_hpteg;
if (lg_n_hpteg > 16)
-   mb2 = 16 - LG_HPTEG_SIZE;
+   hash_mb2 = 16 - LG_HPTEG_SIZE;
+}
+
+void __init MMU_init_hw_patch(void)
+{
+   unsigned int hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
 
+   if (ppc_md.progress)
+   ppc_md.progress("hash:patch", 0x345);
+   if (ppc_md.progress)
+   ppc_md.progress("hash:done", 0x205);
+
+   /* WARNING: Make sure nothing can trigger a KASAN check past this point 
*/
+
+   /*
+* Patch up the instructions in hashtable.S:create_hpte
+*/
modify_instruction_site(__hash_page_A0, 0x,
((unsigned int)Hash - PAGE_OFFSET) >> 16);
-   modify_instruction_site(__hash_page_A1, 0x7c0, mb << 6);
-   modify_instruction_site(__hash_page_A2, 0x7c0, mb2 << 6);
+   modify_instruction_site(__hash_page_A1, 0x7c0, hash_mb << 6);
+   modify_instruction_site(__hash_page_A2, 0x7c0, hash_mb2 << 6);
modify_instruction_site(__hash_page_B, 0x, hmask);
modify_instruction_site(__hash_page_C, 0x, hmask);
 
@@ -371,11 +381,9 @@ void __init MMU_init_hw(void)
 */
modify_instruction_site(__flush_hash_A0, 0x,
((unsigned int)Hash - PAGE_OFFSET) >> 16);
-   modify_instruction_site(__flush_hash_A1, 0x7c0, mb << 6);
-   modify_instruction_site(__flush_hash_A2, 0x7c0, mb2 << 6);
+   modify_instruction_site(__flush_hash_A1, 0x7c0, hash_mb << 6);
+   modify_instruction_site(__flush_hash_A2, 0x7c0, hash_mb2 << 6);
modify_instruction_site(__flush_hash_B, 0x, hmask);
-
-   if ( ppc_md.progress ) ppc_md.progress("hash:done", 0x205);
 }
 
 void setup_initial_memory_limit(phys_addr_t first_memblock_base,
-- 
2.13.3



[PATCH v9 07/11] powerpc/32: prepare shadow area for KASAN

2019-03-01 Thread Christophe Leroy
This patch prepares a shadow area for KASAN.

The shadow area will be at the top of the kernel virtual
memory space above the fixmap area and will occupy one
eighth of the total kernel virtual memory space.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/Kconfig.debug|  5 +
 arch/powerpc/include/asm/fixmap.h |  5 +
 arch/powerpc/include/asm/kasan.h  | 16 
 arch/powerpc/mm/mem.c |  4 
 arch/powerpc/mm/ptdump/ptdump.c   |  8 
 5 files changed, 38 insertions(+)

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 4e00cb0a5464..61febbbdd02b 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -366,3 +366,8 @@ config PPC_FAST_ENDIAN_SWITCH
 depends on DEBUG_KERNEL && PPC_BOOK3S_64
 help
  If you're unsure what this is, say N.
+
+config KASAN_SHADOW_OFFSET
+   hex
+   depends on KASAN
+   default 0xe000
diff --git a/arch/powerpc/include/asm/fixmap.h 
b/arch/powerpc/include/asm/fixmap.h
index b9fbed84ddca..0cfc365d814b 100644
--- a/arch/powerpc/include/asm/fixmap.h
+++ b/arch/powerpc/include/asm/fixmap.h
@@ -22,7 +22,12 @@
 #include 
 #endif
 
+#ifdef CONFIG_KASAN
+#include 
+#define FIXADDR_TOP(KASAN_SHADOW_START - PAGE_SIZE)
+#else
 #define FIXADDR_TOP((unsigned long)(-PAGE_SIZE))
+#endif
 
 /*
  * Here we define all the compile-time 'special' virtual
diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
index c3161b8fc017..8dc1e3819171 100644
--- a/arch/powerpc/include/asm/kasan.h
+++ b/arch/powerpc/include/asm/kasan.h
@@ -12,4 +12,20 @@
 #define EXPORT_SYMBOL_KASAN(fn)EXPORT_SYMBOL(fn)
 #endif
 
+#ifndef __ASSEMBLY__
+
+#include 
+
+#define KASAN_SHADOW_SCALE_SHIFT   3
+
+#define KASAN_SHADOW_OFFSETASM_CONST(CONFIG_KASAN_SHADOW_OFFSET)
+
+#define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \
+(PAGE_OFFSET >> KASAN_SHADOW_SCALE_SHIFT))
+
+#define KASAN_SHADOW_END   0UL
+
+#define KASAN_SHADOW_SIZE  (KASAN_SHADOW_END - KASAN_SHADOW_START)
+
+#endif /* __ASSEMBLY */
 #endif
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index f6787f90e158..4e7fa4eb2dd3 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -309,6 +309,10 @@ void __init mem_init(void)
mem_init_print_info(NULL);
 #ifdef CONFIG_PPC32
pr_info("Kernel virtual memory layout:\n");
+#ifdef CONFIG_KASAN
+   pr_info("  * 0x%08lx..0x%08lx  : kasan shadow mem\n",
+   KASAN_SHADOW_START, KASAN_SHADOW_END);
+#endif
pr_info("  * 0x%08lx..0x%08lx  : fixmap\n", FIXADDR_START, FIXADDR_TOP);
 #ifdef CONFIG_HIGHMEM
pr_info("  * 0x%08lx..0x%08lx  : highmem PTEs\n",
diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c
index 37138428ab55..812ed680024f 100644
--- a/arch/powerpc/mm/ptdump/ptdump.c
+++ b/arch/powerpc/mm/ptdump/ptdump.c
@@ -101,6 +101,10 @@ static struct addr_marker address_markers[] = {
{ 0,"Fixmap start" },
{ 0,"Fixmap end" },
 #endif
+#ifdef CONFIG_KASAN
+   { 0,"kasan shadow mem start" },
+   { 0,"kasan shadow mem end" },
+#endif
{ -1,   NULL },
 };
 
@@ -322,6 +326,10 @@ static void populate_markers(void)
 #endif
address_markers[i++].start_address = FIXADDR_START;
address_markers[i++].start_address = FIXADDR_TOP;
+#ifdef CONFIG_KASAN
+   address_markers[i++].start_address = KASAN_SHADOW_START;
+   address_markers[i++].start_address = KASAN_SHADOW_END;
+#endif
 #endif /* CONFIG_PPC64 */
 }
 
-- 
2.13.3



[PATCH v9 09/11] powerpc/32: Add KASAN support

2019-03-01 Thread Christophe Leroy
This patch adds KASAN support for PPC32. The following patch
will add an early activation of hash table for book3s. Until
then, a warning will be raised if trying to use KASAN on an
hash 6xx.

To support KASAN, this patch initialises that MMU mapings for
accessing to the KASAN shadow area defined in a previous patch.

An early mapping is set as soon as the kernel code has been
relocated at its definitive place.

Then the definitive mapping is set once paging is initialised.

For modules, the shadow area is allocated at module_alloc().

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/Kconfig  |   1 +
 arch/powerpc/include/asm/kasan.h  |   7 ++
 arch/powerpc/kernel/head_32.S |   3 +
 arch/powerpc/kernel/head_40x.S|   3 +
 arch/powerpc/kernel/head_44x.S|   3 +
 arch/powerpc/kernel/head_8xx.S|   3 +
 arch/powerpc/kernel/head_fsl_booke.S  |   3 +
 arch/powerpc/kernel/setup-common.c|   3 +
 arch/powerpc/mm/Makefile  |   1 +
 arch/powerpc/mm/kasan/Makefile|   5 ++
 arch/powerpc/mm/kasan/kasan_init_32.c | 152 ++
 11 files changed, 184 insertions(+)
 create mode 100644 arch/powerpc/mm/kasan/Makefile
 create mode 100644 arch/powerpc/mm/kasan/kasan_init_32.c

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 652c25260838..8d6108c83299 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -172,6 +172,7 @@ config PPC
select GENERIC_TIME_VSYSCALL
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_JUMP_LABEL
+   select HAVE_ARCH_KASAN  if PPC32
select HAVE_ARCH_KGDB
select HAVE_ARCH_MMAP_RND_BITS
select HAVE_ARCH_MMAP_RND_COMPAT_BITS   if COMPAT
diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
index 8dc1e3819171..74a4ba9fb8a3 100644
--- a/arch/powerpc/include/asm/kasan.h
+++ b/arch/powerpc/include/asm/kasan.h
@@ -27,5 +27,12 @@
 
 #define KASAN_SHADOW_SIZE  (KASAN_SHADOW_END - KASAN_SHADOW_START)
 
+#ifdef CONFIG_KASAN
+void kasan_early_init(void);
+void kasan_init(void);
+#else
+static inline void kasan_init(void) { }
+#endif
+
 #endif /* __ASSEMBLY */
 #endif
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index ce6a972f2584..02229c005853 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -952,6 +952,9 @@ start_here:
  * Do early platform-specific initialization,
  * and set up the MMU.
  */
+#ifdef CONFIG_KASAN
+   bl  kasan_early_init
+#endif
li  r3,0
mr  r4,r31
bl  machine_init
diff --git a/arch/powerpc/kernel/head_40x.S b/arch/powerpc/kernel/head_40x.S
index a9c934f2319b..efa219d2136e 100644
--- a/arch/powerpc/kernel/head_40x.S
+++ b/arch/powerpc/kernel/head_40x.S
@@ -848,6 +848,9 @@ start_here:
 /*
  * Decide what sort of machine this is and initialize the MMU.
  */
+#ifdef CONFIG_KASAN
+   bl  kasan_early_init
+#endif
li  r3,0
mr  r4,r31
bl  machine_init
diff --git a/arch/powerpc/kernel/head_44x.S b/arch/powerpc/kernel/head_44x.S
index 37117ab11584..34a5df827b38 100644
--- a/arch/powerpc/kernel/head_44x.S
+++ b/arch/powerpc/kernel/head_44x.S
@@ -203,6 +203,9 @@ _ENTRY(_start);
 /*
  * Decide what sort of machine this is and initialize the MMU.
  */
+#ifdef CONFIG_KASAN
+   bl  kasan_early_init
+#endif
li  r3,0
mr  r4,r31
bl  machine_init
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 03c73b4c6435..d25adb6ef235 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -853,6 +853,9 @@ start_here:
 /*
  * Decide what sort of machine this is and initialize the MMU.
  */
+#ifdef CONFIG_KASAN
+   bl  kasan_early_init
+#endif
li  r3,0
mr  r4,r31
bl  machine_init
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index 1881127682e9..0fc38eb957b7 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -275,6 +275,9 @@ set_ivor:
 /*
  * Decide what sort of machine this is and initialize the MMU.
  */
+#ifdef CONFIG_KASAN
+   bl  kasan_early_init
+#endif
mr  r3,r30
mr  r4,r31
bl  machine_init
diff --git a/arch/powerpc/kernel/setup-common.c 
b/arch/powerpc/kernel/setup-common.c
index e7534f306c8e..3c6c5a43901e 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -67,6 +67,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "setup.h"
 
@@ -865,6 +866,8 @@ static void smp_setup_pacas(void)
  */
 void __init setup_arch(char **cmdline_p)
 {
+   kasan_init();
+
*cmdline_p = boot_command_line;
 
/* Set a half-reasonable default so udelay does something sensible */
diff --git a/arch/powerpc/mm/Makefile 

[PATCH v9 08/11] powerpc: disable KASAN instrumentation on early/critical files.

2019-03-01 Thread Christophe Leroy
All files containing functions run before kasan_early_init() is called
must have KASAN instrumentation disabled.

For those file, branch profiling also have to be disabled otherwise
each if () generates a call to ftrace_likely_update().

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/Makefile | 12 
 arch/powerpc/lib/Makefile|  8 
 arch/powerpc/mm/Makefile |  6 ++
 arch/powerpc/platforms/powermac/Makefile |  6 ++
 arch/powerpc/purgatory/Makefile  |  3 +++
 arch/powerpc/xmon/Makefile   |  1 +
 6 files changed, 36 insertions(+)

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 45e47752b692..0ea6c4aa3a20 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -31,6 +31,18 @@ CFLAGS_REMOVE_btext.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_prom.o = $(CC_FLAGS_FTRACE)
 endif
 
+KASAN_SANITIZE_early_32.o := n
+KASAN_SANITIZE_cputable.o := n
+KASAN_SANITIZE_prom_init.o := n
+KASAN_SANITIZE_btext.o := n
+
+ifdef CONFIG_KASAN
+CFLAGS_early_32.o += -DDISABLE_BRANCH_PROFILING
+CFLAGS_cputable.o += -DDISABLE_BRANCH_PROFILING
+CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING
+CFLAGS_btext.o += -DDISABLE_BRANCH_PROFILING
+endif
+
 obj-y  := cputable.o ptrace.o syscalls.o \
   irq.o align.o signal_32.o pmc.o vdso.o \
   process.o systbl.o idle.o \
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 47a4de434c22..c55f9c27bf79 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -8,6 +8,14 @@ ccflags-$(CONFIG_PPC64):= $(NO_MINIMAL_TOC)
 CFLAGS_REMOVE_code-patching.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_feature-fixups.o = $(CC_FLAGS_FTRACE)
 
+KASAN_SANITIZE_code-patching.o := n
+KASAN_SANITIZE_feature-fixups.o := n
+
+ifdef CONFIG_KASAN
+CFLAGS_code-patching.o += -DDISABLE_BRANCH_PROFILING
+CFLAGS_feature-fixups.o += -DDISABLE_BRANCH_PROFILING
+endif
+
 obj-y += alloc.o code-patching.o feature-fixups.o
 
 ifndef CONFIG_KASAN
diff --git a/arch/powerpc/mm/Makefile b/arch/powerpc/mm/Makefile
index d52ec118e09d..240d73dce6bb 100644
--- a/arch/powerpc/mm/Makefile
+++ b/arch/powerpc/mm/Makefile
@@ -7,6 +7,12 @@ ccflags-$(CONFIG_PPC64):= $(NO_MINIMAL_TOC)
 
 CFLAGS_REMOVE_slb.o = $(CC_FLAGS_FTRACE)
 
+KASAN_SANITIZE_ppc_mmu_32.o := n
+
+ifdef CONFIG_KASAN
+CFLAGS_ppc_mmu_32.o+= -DDISABLE_BRANCH_PROFILING
+endif
+
 obj-y  := fault.o mem.o pgtable.o mmap.o \
   init_$(BITS).o pgtable_$(BITS).o \
   init-common.o mmu_context.o drmem.o
diff --git a/arch/powerpc/platforms/powermac/Makefile 
b/arch/powerpc/platforms/powermac/Makefile
index 923bfb340433..859efbacdf06 100644
--- a/arch/powerpc/platforms/powermac/Makefile
+++ b/arch/powerpc/platforms/powermac/Makefile
@@ -2,6 +2,12 @@
 CFLAGS_bootx_init.o+= -fPIC
 CFLAGS_bootx_init.o+= $(call cc-option, -fno-stack-protector)
 
+KASAN_SANITIZE_bootx_init.o := n
+
+ifdef CONFIG_KASAN
+CFLAGS_bootx_init.o+= -DDISABLE_BRANCH_PROFILING
+endif
+
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
 CFLAGS_REMOVE_bootx_init.o = $(CC_FLAGS_FTRACE)
diff --git a/arch/powerpc/purgatory/Makefile b/arch/powerpc/purgatory/Makefile
index 4314ba5baf43..7c6d8b14f440 100644
--- a/arch/powerpc/purgatory/Makefile
+++ b/arch/powerpc/purgatory/Makefile
@@ -1,4 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
+
+KASAN_SANITIZE := n
+
 targets += trampoline.o purgatory.ro kexec-purgatory.c
 
 LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined
diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
index 3050f9323254..f142570ad860 100644
--- a/arch/powerpc/xmon/Makefile
+++ b/arch/powerpc/xmon/Makefile
@@ -7,6 +7,7 @@ subdir-ccflags-y := $(call cc-disable-warning, 
builtin-requires-header)
 GCOV_PROFILE := n
 KCOV_INSTRUMENT := n
 UBSAN_SANITIZE := n
+KASAN_SANITIZE := n
 
 # Disable ftrace for the entire directory
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
-- 
2.13.3



[PATCH v9 06/11] powerpc/32: make KVIRT_TOP dependent on FIXMAP_START

2019-03-01 Thread Christophe Leroy
When we add KASAN shadow area, KVIRT_TOP can't be anymore fixed
at 0xfe00.

This patch uses FIXADDR_START to define KVIRT_TOP.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/book3s/32/pgtable.h | 13 ++---
 arch/powerpc/include/asm/nohash/32/pgtable.h | 13 ++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h 
b/arch/powerpc/include/asm/book3s/32/pgtable.h
index aa8406b8f7ba..838de59f6754 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -134,15 +134,24 @@ static inline bool pte_user(pte_t pte)
 #define PGDIR_MASK (~(PGDIR_SIZE-1))
 
 #define USER_PTRS_PER_PGD  (TASK_SIZE / PGDIR_SIZE)
+
+#ifndef __ASSEMBLY__
+
+int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
+
+#endif /* !__ASSEMBLY__ */
+
 /*
  * This is the bottom of the PKMAP area with HIGHMEM or an arbitrary
  * value (for now) on others, from where we can start layout kernel
  * virtual space that goes below PKMAP and FIXMAP
  */
+#include 
+
 #ifdef CONFIG_HIGHMEM
 #define KVIRT_TOP  PKMAP_BASE
 #else
-#define KVIRT_TOP  (0xfe00UL)  /* for now, could be FIXMAP_BASE ? */
+#define KVIRT_TOP  FIXADDR_START
 #endif
 
 /*
@@ -373,8 +382,6 @@ static inline void __ptep_set_access_flags(struct 
vm_area_struct *vma,
 #define __pte_to_swp_entry(pte)((swp_entry_t) { pte_val(pte) 
>> 3 })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val << 3 })
 
-int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
-
 /* Generic accessors to PTE bits */
 static inline int pte_write(pte_t pte) { return !!(pte_val(pte) & 
_PAGE_RW);}
 static inline int pte_read(pte_t pte)  { return 1; }
diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h 
b/arch/powerpc/include/asm/nohash/32/pgtable.h
index bed433358260..0284f8f5305f 100644
--- a/arch/powerpc/include/asm/nohash/32/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
@@ -64,15 +64,24 @@ extern int icache_44x_need_flush;
 #define pgd_ERROR(e) \
pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
 
+#ifndef __ASSEMBLY__
+
+int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
+
+#endif /* !__ASSEMBLY__ */
+
+
 /*
  * This is the bottom of the PKMAP area with HIGHMEM or an arbitrary
  * value (for now) on others, from where we can start layout kernel
  * virtual space that goes below PKMAP and FIXMAP
  */
+#include 
+
 #ifdef CONFIG_HIGHMEM
 #define KVIRT_TOP  PKMAP_BASE
 #else
-#define KVIRT_TOP  (0xfe00UL)  /* for now, could be FIXMAP_BASE ? */
+#define KVIRT_TOP  FIXADDR_START
 #endif
 
 /*
@@ -379,8 +388,6 @@ static inline int pte_young(pte_t pte)
 #define __pte_to_swp_entry(pte)((swp_entry_t) { pte_val(pte) 
>> 3 })
 #define __swp_entry_to_pte(x)  ((pte_t) { (x).val << 3 })
 
-int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
-
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_POWERPC_NOHASH_32_PGTABLE_H */
-- 
2.13.3



[PATCH v9 05/11] powerpc/32: use memset() instead of memset_io() to zero BSS

2019-03-01 Thread Christophe Leroy
Since commit 400c47d81ca38 ("powerpc32: memset: only use dcbz once cache is
enabled"), memset() can be used before activation of the cache,
so no need to use memset_io() for zeroing the BSS.

Acked-by: Dmitry Vyukov 
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/early_32.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c
index cf3cdd81dc47..3482118ffe76 100644
--- a/arch/powerpc/kernel/early_32.c
+++ b/arch/powerpc/kernel/early_32.c
@@ -21,8 +21,8 @@ notrace unsigned long __init early_init(unsigned long dt_ptr)
 {
unsigned long offset = reloc_offset();
 
-   /* First zero the BSS -- use memset_io, some platforms don't have 
caches on yet */
-   memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, __bss_stop - 
__bss_start);
+   /* First zero the BSS */
+   memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start);
 
/*
 * Identify the CPU type and fix up code sections
-- 
2.13.3



[PATCH v9 01/11] powerpc/32: Move early_init() in a separate file

2019-03-01 Thread Christophe Leroy
In preparation of KASAN, move early_init() into a separate
file in order to allow deactivation of KASAN for that function.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/Makefile   |  2 +-
 arch/powerpc/kernel/early_32.c | 36 
 arch/powerpc/kernel/setup_32.c | 28 
 3 files changed, 37 insertions(+), 29 deletions(-)
 create mode 100644 arch/powerpc/kernel/early_32.c

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index cddadccf551d..45e47752b692 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -93,7 +93,7 @@ extra-y   += vmlinux.lds
 
 obj-$(CONFIG_RELOCATABLE)  += reloc_$(BITS).o
 
-obj-$(CONFIG_PPC32)+= entry_32.o setup_32.o
+obj-$(CONFIG_PPC32)+= entry_32.o setup_32.o early_32.o
 obj-$(CONFIG_PPC64)+= dma-iommu.o iommu.o
 obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_BOOTX_TEXT)   += btext.o
diff --git a/arch/powerpc/kernel/early_32.c b/arch/powerpc/kernel/early_32.c
new file mode 100644
index ..cf3cdd81dc47
--- /dev/null
+++ b/arch/powerpc/kernel/early_32.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Early init before relocation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * We're called here very early in the boot.
+ *
+ * Note that the kernel may be running at an address which is different
+ * from the address that it was linked at, so we must use RELOC/PTRRELOC
+ * to access static data (including strings).  -- paulus
+ */
+notrace unsigned long __init early_init(unsigned long dt_ptr)
+{
+   unsigned long offset = reloc_offset();
+
+   /* First zero the BSS -- use memset_io, some platforms don't have 
caches on yet */
+   memset_io((void __iomem *)PTRRELOC(&__bss_start), 0, __bss_stop - 
__bss_start);
+
+   /*
+* Identify the CPU type and fix up code sections
+* that depend on which cpu we have.
+*/
+   identify_cpu(offset, mfspr(SPRN_PVR));
+
+   apply_feature_fixups();
+
+   return KERNELBASE + offset;
+}
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 1f0b7629c1a6..3f0d51b4b2f5 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -63,34 +63,6 @@ EXPORT_SYMBOL(DMA_MODE_READ);
 EXPORT_SYMBOL(DMA_MODE_WRITE);
 
 /*
- * We're called here very early in the boot.
- *
- * Note that the kernel may be running at an address which is different
- * from the address that it was linked at, so we must use RELOC/PTRRELOC
- * to access static data (including strings).  -- paulus
- */
-notrace unsigned long __init early_init(unsigned long dt_ptr)
-{
-   unsigned long offset = reloc_offset();
-
-   /* First zero the BSS -- use memset_io, some platforms don't have
-* caches on yet */
-   memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
-   __bss_stop - __bss_start);
-
-   /*
-* Identify the CPU type and fix up code sections
-* that depend on which cpu we have.
-*/
-   identify_cpu(offset, mfspr(SPRN_PVR));
-
-   apply_feature_fixups();
-
-   return KERNELBASE + offset;
-}
-
-
-/*
  * This is run before start_kernel(), the kernel has been relocated
  * and we are running with enough of the MMU enabled to have our
  * proper kernel virtual addresses
-- 
2.13.3



[PATCH v9 00/11] KASAN for powerpc/32

2019-03-01 Thread Christophe Leroy
This series adds KASAN support to powerpc/32

Tested on nohash/32 (8xx) and book3s/32 (mpc832x ie 603).
Boot tested on qemu mac99

Changes in v9:
- Fixed fixmap IMMR alignment issue on 8xx with KASAN enabled.
- Set up final shadow page tables before switching to the final hash table on 
hash32
- Using PAGE_READONLY instead of PAGE_KERNEL_RO on hash32
- Use flash_tlb_kernel_range() instead of flash_tlb_mm() which doesn't work for 
kernel on some subarches.
- use __set_pte_at() instead of pte_update() to install final page tables

Changes in v8:
- Fixed circular issue between pgtable.h and fixmap.h
- Added missing includes in ppc64 string files
- Fixed kasan string related macro names for ppc64.
- Fixed most checkpatch messages
- build tested on kisskb 
(http://kisskb.ellerman.id.au/kisskb/head/6e65827de2fe71d21682dafd9084ed2cc6e06d4f/)
- moved CONFIG_KASAN_SHADOW_OFFSET in Kconfig.debug

Changes in v7:
- split in several smaller patches
- prom_init now has its own string functions
- full deactivation of powerpc-optimised string functions when KASAN is active
- shadow area now at a fixed place on very top of kernel virtual space.
- Early static hash table for hash book3s/32.
- Full support of both inline and outline instrumentation for both hash and 
nohash ppc32
- Earlier full activation of kasan.

Changes in v6:
- Fixed oops on module loading (due to access to RO shadow zero area).
- Added support for hash book3s/32, thanks to Daniel's patch to differ KASAN 
activation.
- Reworked handling of optimised string functions (dedicated patch for it)
- Reordered some files to ease adding of book3e/64 support.

Changes in v5:
- Added KASAN_SHADOW_OFFSET in Makefile, otherwise we fallback to KASAN_MINIMAL
and some stuff like stack instrumentation is not performed
- Moved calls to kasan_early_init() in head.S because stack instrumentation
in machine_init was performed before the call to kasan_early_init()
- Mapping kasan_early_shadow_page RW in kasan_early_init() and
remaping RO later in kasan_init()
- Allocating a big memblock() for shadow area, falling back to PAGE_SIZE blocks 
in case of failure.

Changes in v4:
- Comments from Andrey (DISABLE_BRANCH_PROFILING, Activation of reports)
- Proper initialisation of shadow area in kasan_init()
- Panic in case Hash table is required.
- Added comments in patch one to explain why *t = *s becomes memcpy(t, s, ...)
- Call of kasan_init_tags()

Changes in v3:
- Removed the printk() in kasan_early_init() to avoid build failure (see 
https://github.com/linuxppc/issues/issues/218)
- Added necessary changes in asm/book3s/32/pgtable.h to get it work on powerpc 
603 family
- Added a few KASAN_SANITIZE_xxx.o := n to successfully boot on powerpc 603 
family

Changes in v2:
- Rebased.
- Using __set_pte_at() to build the early table.
- Worked around and got rid of the patch adding asm/page.h in 
asm/pgtable-types.h
==> might be fixed independently but not needed for this serie.

Christophe Leroy (11):
  powerpc/32: Move early_init() in a separate file
  powerpc: prepare string/mem functions for KASAN
  powerpc/prom_init: don't use string functions from lib/
  powerpc/mm: don't use direct assignation during early boot.
  powerpc/32: use memset() instead of memset_io() to zero BSS
  powerpc/32: make KVIRT_TOP dependent on FIXMAP_START
  powerpc/32: prepare shadow area for KASAN
  powerpc: disable KASAN instrumentation on early/critical files.
  powerpc/32: Add KASAN support
  powerpc/32s: move hash code patching out of MMU_init_hw()
  powerpc/32s: set up an early static hash table for KASAN.

 arch/powerpc/Kconfig |   1 +
 arch/powerpc/Kconfig.debug   |   5 +
 arch/powerpc/include/asm/book3s/32/pgtable.h |  13 +-
 arch/powerpc/include/asm/fixmap.h|   5 +
 arch/powerpc/include/asm/kasan.h |  39 +
 arch/powerpc/include/asm/nohash/32/pgtable.h |  13 +-
 arch/powerpc/include/asm/string.h|  32 +++-
 arch/powerpc/kernel/Makefile |  14 +-
 arch/powerpc/kernel/cputable.c   |  13 +-
 arch/powerpc/kernel/early_32.c   |  36 +
 arch/powerpc/kernel/head_32.S|  49 --
 arch/powerpc/kernel/head_40x.S   |   3 +
 arch/powerpc/kernel/head_44x.S   |   3 +
 arch/powerpc/kernel/head_8xx.S   |   3 +
 arch/powerpc/kernel/head_fsl_booke.S |   3 +
 arch/powerpc/kernel/prom_init.c  | 213 +--
 arch/powerpc/kernel/prom_init_check.sh   |  12 +-
 arch/powerpc/kernel/setup-common.c   |   3 +
 arch/powerpc/kernel/setup_32.c   |  28 
 arch/powerpc/lib/Makefile|  19 ++-
 arch/powerpc/lib/copy_32.S   |  15 +-
 arch/powerpc/lib/mem_64.S|  11 +-
 arch/powerpc/lib/memcpy_64.S |   5 +-
 arch/powerpc/mm/Makefile |   7 +
 arch/powerpc/mm/kasan/Makefile   |   5 +
 

[PATCH v9 03/11] powerpc/prom_init: don't use string functions from lib/

2019-03-01 Thread Christophe Leroy
When KASAN is active, the string functions in lib/ are doing the
KASAN checks. This is too early for prom_init.

This patch implements dedicated string functions for prom_init,
which will be compiled in with KASAN disabled.

Size of prom_init before the patch:
   textdata bss dec hex filename
  12060 4886960   195084c34 arch/powerpc/kernel/prom_init.o

Size of prom_init after the patch:
   textdata bss dec hex filename
  12460 4886960   199084dc4 arch/powerpc/kernel/prom_init.o

This increases the size of prom_init a bit, but as prom_init is
in __init section, it is freed after boot anyway.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/prom_init.c| 213 ++---
 arch/powerpc/kernel/prom_init_check.sh |   2 +-
 2 files changed, 173 insertions(+), 42 deletions(-)

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index f33ff4163a51..56d5639ab082 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -224,6 +224,137 @@ static bool  __prombss rtas_has_query_cpu_stopped;
 #define PHANDLE_VALID(p)   ((p) != 0 && (p) != PROM_ERROR)
 #define IHANDLE_VALID(i)   ((i) != 0 && (i) != PROM_ERROR)
 
+/* Copied from lib/string.c and lib/kstrtox.c */
+
+static int __init prom_strcmp(const char *cs, const char *ct)
+{
+   unsigned char c1, c2;
+
+   while (1) {
+   c1 = *cs++;
+   c2 = *ct++;
+   if (c1 != c2)
+   return c1 < c2 ? -1 : 1;
+   if (!c1)
+   break;
+   }
+   return 0;
+}
+
+static char __init *prom_strcpy(char *dest, const char *src)
+{
+   char *tmp = dest;
+
+   while ((*dest++ = *src++) != '\0')
+   /* nothing */;
+   return tmp;
+}
+
+static int __init prom_strncmp(const char *cs, const char *ct, size_t count)
+{
+   unsigned char c1, c2;
+
+   while (count) {
+   c1 = *cs++;
+   c2 = *ct++;
+   if (c1 != c2)
+   return c1 < c2 ? -1 : 1;
+   if (!c1)
+   break;
+   count--;
+   }
+   return 0;
+}
+
+static size_t __init prom_strlen(const char *s)
+{
+   const char *sc;
+
+   for (sc = s; *sc != '\0'; ++sc)
+   /* nothing */;
+   return sc - s;
+}
+
+static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
+{
+   const unsigned char *su1, *su2;
+   int res = 0;
+
+   for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
+   if ((res = *su1 - *su2) != 0)
+   break;
+   return res;
+}
+
+static char __init *prom_strstr(const char *s1, const char *s2)
+{
+   size_t l1, l2;
+
+   l2 = prom_strlen(s2);
+   if (!l2)
+   return (char *)s1;
+   l1 = prom_strlen(s1);
+   while (l1 >= l2) {
+   l1--;
+   if (!prom_memcmp(s1, s2, l2))
+   return (char *)s1;
+   s1++;
+   }
+   return NULL;
+}
+
+#ifdef CONFIG_CMDLINE
+static size_t __init prom_strlcpy(char *dest, const char *src, size_t size)
+{
+   size_t ret = prom_strlen(src);
+
+   if (size) {
+   size_t len = (ret >= size) ? size - 1 : ret;
+   memcpy(dest, src, len);
+   dest[len] = '\0';
+   }
+   return ret;
+}
+#endif
+
+#ifdef CONFIG_PPC_PSERIES
+static int __init prom_strtobool(const char *s, bool *res)
+{
+   if (!s)
+   return -EINVAL;
+
+   switch (s[0]) {
+   case 'y':
+   case 'Y':
+   case '1':
+   *res = true;
+   return 0;
+   case 'n':
+   case 'N':
+   case '0':
+   *res = false;
+   return 0;
+   case 'o':
+   case 'O':
+   switch (s[1]) {
+   case 'n':
+   case 'N':
+   *res = true;
+   return 0;
+   case 'f':
+   case 'F':
+   *res = false;
+   return 0;
+   default:
+   break;
+   }
+   default:
+   break;
+   }
+
+   return -EINVAL;
+}
+#endif
 
 /* This is the one and *ONLY* place where we actually call open
  * firmware.
@@ -555,7 +686,7 @@ static int __init prom_setprop(phandle node, const char 
*nodename,
add_string(, tohex((u32)(unsigned long) value));
add_string(, tohex(valuelen));
add_string(, tohex(ADDR(pname)));
-   add_string(, tohex(strlen(pname)));
+   add_string(, tohex(prom_strlen(pname)));
add_string(, "property");
*p = 0;
return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd);
@@ -639,25 +770,25 @@ static void __init early_cmdline_parse(void)
l = prom_getprop(prom.chosen, "bootargs", p, 

[PATCH v9 02/11] powerpc: prepare string/mem functions for KASAN

2019-03-01 Thread Christophe Leroy
CONFIG_KASAN implements wrappers for memcpy() memmove() and memset()
Those wrappers are doing the verification then call respectively
__memcpy() __memmove() and __memset(). The arches are therefore
expected to rename their optimised functions that way.

For files on which KASAN is inhibited, #defines are used to allow
them to directly call optimised versions of the functions without
going through the KASAN wrappers.

See commit 393f203f5fd5 ("x86_64: kasan: add interceptors for
memset/memmove/memcpy functions") for details.

Other string / mem functions do not (yet) have kasan wrappers,
we therefore have to fallback to the generic versions when
KASAN is active, otherwise KASAN checks will be skipped.

Signed-off-by: Christophe Leroy 
---
 arch/powerpc/include/asm/kasan.h   | 15 +++
 arch/powerpc/include/asm/string.h  | 32 +---
 arch/powerpc/kernel/prom_init_check.sh | 10 +-
 arch/powerpc/lib/Makefile  | 11 ---
 arch/powerpc/lib/copy_32.S | 15 +--
 arch/powerpc/lib/mem_64.S  | 11 +++
 arch/powerpc/lib/memcpy_64.S   |  5 +++--
 7 files changed, 80 insertions(+), 19 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kasan.h

diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h
new file mode 100644
index ..c3161b8fc017
--- /dev/null
+++ b/arch/powerpc/include/asm/kasan.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_KASAN_H
+#define __ASM_KASAN_H
+
+#ifdef CONFIG_KASAN
+#define _GLOBAL_KASAN(fn)  .weak fn ; _GLOBAL(__##fn) ; _GLOBAL(fn)
+#define _GLOBAL_TOC_KASAN(fn)  .weak fn ; _GLOBAL_TOC(__##fn) ; _GLOBAL_TOC(fn)
+#define EXPORT_SYMBOL_KASAN(fn)EXPORT_SYMBOL(__##fn) ; 
EXPORT_SYMBOL(fn)
+#else
+#define _GLOBAL_KASAN(fn)  _GLOBAL(fn)
+#define _GLOBAL_TOC_KASAN(fn)  _GLOBAL_TOC(fn)
+#define EXPORT_SYMBOL_KASAN(fn)EXPORT_SYMBOL(fn)
+#endif
+
+#endif
diff --git a/arch/powerpc/include/asm/string.h 
b/arch/powerpc/include/asm/string.h
index 1647de15a31e..9bf6dffb4090 100644
--- a/arch/powerpc/include/asm/string.h
+++ b/arch/powerpc/include/asm/string.h
@@ -4,14 +4,17 @@
 
 #ifdef __KERNEL__
 
+#ifndef CONFIG_KASAN
 #define __HAVE_ARCH_STRNCPY
 #define __HAVE_ARCH_STRNCMP
+#define __HAVE_ARCH_MEMCHR
+#define __HAVE_ARCH_MEMCMP
+#define __HAVE_ARCH_MEMSET16
+#endif
+
 #define __HAVE_ARCH_MEMSET
 #define __HAVE_ARCH_MEMCPY
 #define __HAVE_ARCH_MEMMOVE
-#define __HAVE_ARCH_MEMCMP
-#define __HAVE_ARCH_MEMCHR
-#define __HAVE_ARCH_MEMSET16
 #define __HAVE_ARCH_MEMCPY_FLUSHCACHE
 
 extern char * strcpy(char *,const char *);
@@ -27,7 +30,27 @@ extern int memcmp(const void *,const void *,__kernel_size_t);
 extern void * memchr(const void *,int,__kernel_size_t);
 extern void * memcpy_flushcache(void *,const void *,__kernel_size_t);
 
+void *__memset(void *s, int c, __kernel_size_t count);
+void *__memcpy(void *to, const void *from, __kernel_size_t n);
+void *__memmove(void *to, const void *from, __kernel_size_t n);
+
+#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
+/*
+ * For files that are not instrumented (e.g. mm/slub.c) we
+ * should use not instrumented version of mem* functions.
+ */
+#define memcpy(dst, src, len) __memcpy(dst, src, len)
+#define memmove(dst, src, len) __memmove(dst, src, len)
+#define memset(s, c, n) __memset(s, c, n)
+
+#ifndef __NO_FORTIFY
+#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */
+#endif
+
+#endif
+
 #ifdef CONFIG_PPC64
+#ifndef CONFIG_KASAN
 #define __HAVE_ARCH_MEMSET32
 #define __HAVE_ARCH_MEMSET64
 
@@ -49,8 +72,11 @@ static inline void *memset64(uint64_t *p, uint64_t v, 
__kernel_size_t n)
 {
return __memset64(p, v, n * 8);
 }
+#endif
 #else
+#ifndef CONFIG_KASAN
 #define __HAVE_ARCH_STRLEN
+#endif
 
 extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
 #endif
diff --git a/arch/powerpc/kernel/prom_init_check.sh 
b/arch/powerpc/kernel/prom_init_check.sh
index 667df97d2595..181fd10008ef 100644
--- a/arch/powerpc/kernel/prom_init_check.sh
+++ b/arch/powerpc/kernel/prom_init_check.sh
@@ -16,8 +16,16 @@
 # If you really need to reference something from prom_init.o add
 # it to the list below:
 
+grep "^CONFIG_KASAN=y$" .config >/dev/null
+if [ $? -eq 0 ]
+then
+   MEM_FUNCS="__memcpy __memset"
+else
+   MEM_FUNCS="memcpy memset"
+fi
+
 WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush
-_end enter_prom memcpy memset reloc_offset __secondary_hold
+_end enter_prom $MEM_FUNCS reloc_offset __secondary_hold
 __secondary_hold_acknowledge __secondary_hold_spinloop __start
 strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224
 reloc_got2 kernstart_addr memstart_addr linux_banner _stext
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 79396e184bca..47a4de434c22 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -8,9 +8,14 @@ 

[PATCH v9 04/11] powerpc/mm: don't use direct assignation during early boot.

2019-03-01 Thread Christophe Leroy
In kernel/cputable.c, explicitly use memcpy() instead of *y = *x;
This will allow GCC to replace it with __memcpy() when KASAN is
selected.

Acked-by: Dmitry Vyukov 
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/kernel/cputable.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 1eab54bc6ee9..cd12f362b61f 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -2147,7 +2147,11 @@ void __init set_cur_cpu_spec(struct cpu_spec *s)
struct cpu_spec *t = _cpu_spec;
 
t = PTRRELOC(t);
-   *t = *s;
+   /*
+* use memcpy() instead of *t = *s so that GCC replaces it
+* by __memcpy() when KASAN is active
+*/
+   memcpy(t, s, sizeof(*t));
 
*PTRRELOC(_cpu_spec) = _cpu_spec;
 }
@@ -2161,8 +2165,11 @@ static struct cpu_spec * __init setup_cpu_spec(unsigned 
long offset,
t = PTRRELOC(t);
old = *t;
 
-   /* Copy everything, then do fixups */
-   *t = *s;
+   /*
+* Copy everything, then do fixups. Use memcpy() instead of *t = *s
+* so that GCC replaces it by __memcpy() when KASAN is active
+*/
+   memcpy(t, s, sizeof(*t));
 
/*
 * If we are overriding a previous value derived from the real
-- 
2.13.3



Re: DMA & POWER8

2019-03-01 Thread Илья Кузнецов

I'm sorry for previous email content without greeting.

A bit more description… We are working on enabling RDMA over PCIe NTB on
OpenPOWER using https://github.com/ntrdma project. During initialization 
dma_request_channel() founds no available channels. We also found that there no 
channels at all in dma_device_list. This is probably powerpc specific problem.

Could someone explain if that is hardware limitation or arch specific part
should be changed?

Ben, a while ago you answered regarding DMA master on POWER8, may be you have 
idea here also?


Thank you in advance!

Илья Кузнецов  wrote on Ср [2019-фев-27 18:57:02 +0300]:

We're trying to use Slave-DMA API of the DMA Engine in the linux kernel on
POWER8 OpenPOWER platform. And we discovered that dma_request_channel() always 
fails.
Does it mean that Turismo hardware does not support Slave-DMA? Or DMA
subsystem in the linux kernel needs to be fixed, doesn't it?


[PATCH V2] ASoC: fsl_asrc: add constraint for the asrc of older version

2019-03-01 Thread S.j. Wang
There is constraint for the channel number setting on the
asrc of older version (e.g. imx35), the channel number should
be even, odd number isn't valid.

So add this constraint when the asrc of older version is used.

Signed-off-by: Shengjiu Wang 
---
changes in v2
- switch to add constraint in startup function

 sound/soc/fsl/fsl_asrc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 528e8b108422..31494f225037 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -445,6 +445,19 @@ struct dma_chan *fsl_asrc_get_dma_channel(struct 
fsl_asrc_pair *pair, bool dir)
 }
 EXPORT_SYMBOL_GPL(fsl_asrc_get_dma_channel);
 
+static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
+
+   /* channel_bits = 3 means older version on imx35*/
+   if (asrc_priv->channel_bits == 3)
+   snd_pcm_hw_constraint_step(substream->runtime, 0,
+  SNDRV_PCM_HW_PARAM_CHANNELS, 2);
+
+   return 0;
+}
+
 static int fsl_asrc_dai_hw_params(struct snd_pcm_substream *substream,
  struct snd_pcm_hw_params *params,
  struct snd_soc_dai *dai)
@@ -539,6 +552,7 @@ static int fsl_asrc_dai_trigger(struct snd_pcm_substream 
*substream, int cmd,
 }
 
 static const struct snd_soc_dai_ops fsl_asrc_dai_ops = {
+   .startup  = fsl_asrc_dai_startup,
.hw_params= fsl_asrc_dai_hw_params,
.hw_free  = fsl_asrc_dai_hw_free,
.trigger  = fsl_asrc_dai_trigger,
-- 
1.9.1



RE: [PATCH] ASoC: fsl_asrc: add protection for the asrc of older version

2019-03-01 Thread S.j. Wang
Hi

> 
> On Fri, Mar 01, 2019 at 06:55:25AM +, S.j. Wang wrote:
> 
> > > Alternatively, I feel instead of error-out at here, should we add a
> > > HW constraint or at least fence it off at the beginning of the
> > > hw_params()? This is actually nothing specific to the pair-request
> > > function but a hardware constraint.
> >
> > How about add constraint in startup?
> > static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
> >struct snd_soc_dai *dai) {
> >struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
> >
> >if (asrc_priv->channel_bits == 3) {
> >snd_pcm_hw_constraint_step(substream->runtime, 0,
> >   SNDRV_PCM_HW_PARAM_CHANNELS, 2);
> >}
> >
> >return 0;
> > }
> 
> Yea, that looks good to me. Better to have a line of comments to tell that
> "bits==3" means older version -- maybe we should have something much
> more clear than using channel_bits but it is fine for now since they only
> differ here.

Ok , will send v2.


Re: [PATCH] ASoC: fsl_asrc: add protection for the asrc of older version

2019-03-01 Thread Nicolin Chen
On Fri, Mar 01, 2019 at 06:55:25AM +, S.j. Wang wrote:

> > Alternatively, I feel instead of error-out at here, should we add a HW
> > constraint or at least fence it off at the beginning of the hw_params()? 
> > This
> > is actually nothing specific to the pair-request function but a hardware
> > constraint.
> 
> How about add constraint in startup?
> static int fsl_asrc_dai_startup(struct snd_pcm_substream *substream,
>struct snd_soc_dai *dai)
> {
>struct fsl_asrc *asrc_priv = snd_soc_dai_get_drvdata(dai);
> 
>if (asrc_priv->channel_bits == 3) {
>snd_pcm_hw_constraint_step(substream->runtime, 0,
>   SNDRV_PCM_HW_PARAM_CHANNELS, 2);
>}
> 
>return 0;
> }

Yea, that looks good to me. Better to have a line of comments
to tell that "bits==3" means older version -- maybe we should
have something much more clear than using channel_bits but it
is fine for now since they only differ here.


Re: [PATCH] KVM: PPC: powerpc: Add count cache flush parameters to kvmppc_get_cpu_char()

2019-03-01 Thread Paul Mackerras
On Fri, Mar 01, 2019 at 05:52:51PM +1100, Michael Ellerman wrote:
> Suraj Jitindar Singh  writes:
> 
> > Add KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST &
> > KVM_PPC_CPU_BEHAV_FLUSH_COUNT_CACHE to the characteristics returned from
> > the H_GET_CPU_CHARACTERISTICS H-CALL, as queried from either the
> > hypervisor or the device tree.
> >
> > Signed-off-by: Suraj Jitindar Singh 
> > ---
> >  arch/powerpc/include/uapi/asm/kvm.h |  2 ++
> >  arch/powerpc/kvm/powerpc.c  | 18 ++
> >  2 files changed, 16 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> > index b90a7d154180..a99dcac91e50 100644
> > --- a/arch/powerpc/kvm/powerpc.c
> > +++ b/arch/powerpc/kvm/powerpc.c
> > @@ -2251,12 +2253,16 @@ static int kvmppc_get_cpu_char(struct 
> > kvm_ppc_cpu_char *cp)
> > if (have_fw_feat(fw_features, "enabled",
> >  "fw-count-cache-disabled"))
> > cp->character |= KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS;
> > +   if (have_fw_feat(fw_features, "enabled",
> > +"fw-count-cache-flush-bcctr2,0,0"))
> 
> I don't think there's any reason KVM needs to be querying the device
> tree directly, is there?
> 
> Can't it just use the security flags (security_features.h), that are
> initialised by the powernv platform code based on the device tree.

My recollection is that the security flags didn't have all the
information we need.  It's possible that's no longer true.

I merged the patch and sent a pull request to Paolo; using the same
pattern as the existing code made it a low-risk patch and I wanted to
get it in for 5.1.  For 5.2 we can look at changing it over if you
like.

Paul.