Re: [PATCH v2 4/7] CMDLINE: powerpc: convert to generic builtin command line

2021-03-08 Thread Christophe Leroy




Le 09/03/2021 à 01:02, Daniel Walker a écrit :

This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
  arch/powerpc/Kconfig| 37 +
  arch/powerpc/kernel/prom.c  |  1 +
  arch/powerpc/kernel/prom_init.c | 35 ++-
  3 files changed, 23 insertions(+), 50 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 107bb4319e0e..276b06d5c961 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -167,6 +167,7 @@ config PPC
select EDAC_SUPPORT
select GENERIC_ATOMIC64 if PPC32
select GENERIC_CLOCKEVENTS_BROADCASTif SMP
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
@@ -906,42 +907,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

-   string "Initial kernel command string"
-   default ""
-   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.
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
  config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index ae3c41730367..96d0a01be1b4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -27,6 +27,7 @@
  #include 
  #include 
  #include 
+#include 


Why is this needed in prom.c ?


  #include 
  #include 
  #include 
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index e9d4eb6144e1..657241534d69 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -27,6 +27,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -242,15 +243,6 @@ static int __init prom_strcmp(const char *cs, const char 
*ct)
return 0;
  }
  
-static char __init *prom_strcpy(char *dest, const char *src)

-{
-   char *tmp = dest;
-
-   while ((*dest++ = *src++) != '\0')
-   /* nothing */;
-   return tmp;
-}
-


This game with prom_strcpy() should go a separate preceeding patch.

Also, it looks like checkpatch.pl recommends to use strscpy() instead of 
strlcpy().


  static int __init prom_strncmp(const char *cs, const char *ct, size_t count)
  {
unsigned char c1, c2;
@@ -276,6 +268,20 @@ static size_t __init prom_strlen(const char *s)
return sc - s;
  }
  
+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;
+}
+
+
  static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
  {
const unsigned char *su1, *su2;
@@ -304,6 +310,7 @@ static char __init *prom_strstr(const char *s1, const char 
*s2)
return NULL;
  }
  
+#ifdef GENERIC_CMDLINE_NEED_STRLCAT

  static size_t __init prom_strlcat(char *dest, const char *src, size_t count)
  {
size_t dsize = prom_strlen(dest);
@@ -323,6 +330,7 @@ static size_t __init prom_strlcat(char *dest, const char 
*src, size_t count)
return res;
  
  }

+#endif
  
  #ifdef CONFIG_PPC_PSERIES

  static int __init prom_strtobool(const char *s, bool *res)
@@ -775,12 +783,11 @@ static void __init early_cmdline_parse(void)
prom_cmd_line[0] = 0;
p = pr

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

2021-03-08 Thread Christophe Leroy




Le 09/03/2021 à 01:02, Daniel Walker a écrit :

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.


If you do that in a separate patch, you loose bisectability.

I think it would have been better to do things in a different way, more or less 
like I did in my series:
1/ Provide GENERIC cmdline at the same functionnality level as what is spread in the different 
architectures

2/ Convert architectures to the generic with least churn.
3/ Add new features to the generic



The bash 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_BOOL=y\nCONFIG_CMDLINE_PREPEND=/g' 
$1/.config


This is not correct.

By default, on powerpc the provided command line is used only if the bootloader 
doesn't provide one.

Otherwise:
- the builtin command line is appended to the one provided by the bootloader if 
CONFIG_CMDLINE_EXTEND is selected
- the builtin command line replaces to the one provided by the bootloader if CONFIG_CMDLINE_FORCE is 
selected




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
Signed-off-by: Daniel Walker 
---
  arch/powerpc/configs/44x/fsp2_defconfig   | 33 +--
  arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
  arch/powerpc/configs/44x/warp_defconfig   | 17 +-
  arch/powerpc/configs/holly_defconfig  | 13 
  arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
  arch/powerpc/configs/skiroot_defconfig| 12 +++
  arch/powerpc/configs/storcenter_defconfig | 18 --
  7 files changed, 66 insertions(+), 75 deletions(-)

diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index 30845ce0885a..4993db054589 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,24 +11,25 @@ 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="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
@@ -47,14 +46,12 @@ CONFIG_MTD=y
  CONFIG_MTD_BLOCK=y
  CONFIG_MTD_JEDECPROBE=y
  CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_PHYSMAP_OF=y
  CONFIG_BLK_DEV_RAM=y
  CONFIG_BLK_DEV_RAM_SIZE=35000
  # CONFIG_SCSI_PROC_FS is not set
  CONFIG_BLK_DEV_SD=y
  # CONFIG_SCSI_LOWLEVEL is not set
  CONFIG_ATA=y
-# CONFIG_SATA_PMP is not set
  # CONFIG_ATA_SFF is not set
  CONFIG_NETDEVICES=y
  CONFIG_BONDING=m
@@ -63,7 +60,6 @@ CONFIG_IBM_EMAC=m
  # CONFIG_SERIO is not set
  # CONFIG_VT is not set
  # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVMEM is not set
  CONFIG_SERIAL_8250=y
  CONFIG_SERIAL_8250_CONSOLE=y
  CONFIG_SERIAL_8250_NR_UARTS=32
@@ -72,6 +68,7 @@ CONFIG_SERIAL_8250_EXTENDED=y
  CONFIG_SERIAL_8250_SHARE_IRQ=y
  CONFIG_SERIAL_OF_PLATFORM=y
  # CONFIG_HW_RANDOM is not set
+# CONFIG_DEVMEM is not set
  CONFIG_I2C=y
  CONFIG_I2C_IBM_IIC=y
  CONFIG_PTP_1588_CLOCK=y
@@ -107,6 +104,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
@@ -114,9 +117,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 2c3834eebca3..b8d97061517a 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,20 +5,22 @@ CONFIG_BLK_DEV_INITRD=y
  CONFIG_EXP

Re: [PATCH v2 2/7] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-08 Thread Christophe Leroy




Le 09/03/2021 à 01:02, Daniel Walker a écrit :

It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
  drivers/of/fdt.c | 12 
  1 file changed, 12 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index feb0f2d67fc5..e25240d84632 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #include   /* for COMMAND_LINE_SIZE */

  #include 
@@ -1050,6 +1051,16 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
  
  	/* Retrieve command line */

p = of_get_flat_dt_prop(node, "bootargs", &l);
+
+#ifdef CONFIG_GENERIC_CMDLINE
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   (l > 0 ? p : NULL), /* This is sanity checking */
+   COMMAND_LINE_SIZE);


I don't think the comment is needed.
Without the comment, it should fit on a single line, would be better for 
readability and grepability.


+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
  
@@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,

strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
  #endif
  #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
  
  	pr_debug("Command line is: %s\n", (char *)data);
  



Christophe


Re: [PATCH v2 1/7] CMDLINE: add generic builtin command line

2021-03-08 Thread Christophe Leroy




Le 09/03/2021 à 01:02, Daniel Walker a écrit :

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.


Same comment as in v1: The above is not correct for powerpc.



The code in this commit unifies the 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.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
  include/linux/cmdline.h | 89 +
  init/Kconfig| 68 +++
  2 files changed, 157 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 ..00929b6e49e6
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+#define GENERIC_CMDLINE_NEED_STRLCAT
+/*
+ * 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.
+ * @cmdline_strlcpy: point to a compatible strlcpy
+ * @cmdline_strlcat: point to a compatible strlcat
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   if (src != dest && src != NULL) {
+   cmdline_strlcpy(dest, " ", length);
+   cmdline_strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)


This test can probably be avoided. if CONFIG_CMDLINE_APPEND is empty, it will add a space at the end 
of dest, that's harmless.



+   cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {


Same. Keep it simple. Provide tmp all the time, have only one logic.


+   cmdline_strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   cmdline_strlcat(tmp, dest, length);
+   cmdline_strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
 \
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
cmdline_strlcpy, cmdline_strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
 \
+   __cmdline_add_builtin(dest, src, NULL, length, cmdline_strlcpy, 
cmdline_strlcat);   \
+   }   
\


No need to micro-optimise this, you can provide cmdline_tmp_space all the time and only keep on leg 
of the if/elseif



+}
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_custom(dest, src, length, __initdata, strlcpy, 
strlcat)
+
+#else /* CONFIG_CMDLINE_OVERRIDE */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))


Argh ! So the same function as different semantics whether CONFIG_CMDLINE_OVERRIDE and/or 
CONFIG_CMDLINE_BOOL is selected ? It means the architecture will have to know it as well in order to 
call it right ? That looks like micro-optimisation, I think it is not worth it.




+{
+   cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, 
length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(d

[PATCH] powerpc/64s: Use symbolic macros for function entry encoding

2021-03-08 Thread Michael Ellerman
In ppc_function_entry() we look for a specific set of instructions by
masking the instructions and comparing with a known value. Currently
those known values are just literal hex values, and we recently
discovered one of them was wrong.

Instead construct the values using the existing constants we have for
defining various fields of instructions.

Suggested-by: Christophe Leroy 
Signed-off-by: Michael Ellerman 
---
 arch/powerpc/include/asm/code-patching.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/code-patching.h 
b/arch/powerpc/include/asm/code-patching.h
index d5b3c3bb95b4..f1d029bf906e 100644
--- a/arch/powerpc/include/asm/code-patching.h
+++ b/arch/powerpc/include/asm/code-patching.h
@@ -73,9 +73,10 @@ void __patch_exception(int exc, unsigned long addr);
 #endif
 
 #define OP_RT_RA_MASK  0xUL
-#define LIS_R2 0x3c40UL
-#define ADDIS_R2_R12   0x3c4cUL
-#define ADDI_R2_R2 0x3842UL
+#define LIS_R2 (PPC_INST_ADDIS | __PPC_RT(R2))
+#define ADDIS_R2_R12   (PPC_INST_ADDIS | __PPC_RT(R2) | __PPC_RA(R12))
+#define ADDI_R2_R2 (PPC_INST_ADDI  | __PPC_RT(R2) | __PPC_RA(R2))
+
 
 static inline unsigned long ppc_function_entry(void *func)
 {
-- 
2.25.1



Re: [PATCH v2 7/7] CMDLINE: x86: convert to generic builtin command line

2021-03-08 Thread Ard Biesheuvel
On Tue, 9 Mar 2021 at 01:03, Daniel Walker  wrote:
>
> This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
> option.
>
> Cc: xe-linux-exter...@cisco.com
> Signed-off-by: Ruslan Ruslichenko 
> Signed-off-by: Ruslan Bilovol 
> Signed-off-by: Daniel Walker 
> ---
>  arch/x86/Kconfig| 44 +
>  arch/x86/kernel/setup.c | 18 ++
>  drivers/firmware/efi/libstub/x86-stub.c |  2 +-
>  3 files changed, 4 insertions(+), 60 deletions(-)
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 21f851179ff0..3950f9bf9855 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -115,6 +115,7 @@ config X86
> select EDAC_SUPPORT
> select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
> X86_LOCAL_APIC)
> select GENERIC_CLOCKEVENTS_MIN_ADJUST
> +   select GENERIC_CMDLINE
> select GENERIC_CMOS_UPDATE
> select GENERIC_CPU_AUTOPROBE
> select GENERIC_CPU_VULNERABILITIES
> @@ -2368,49 +2369,6 @@ choice
>
>  endchoice
>
> -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
> - boot arguments in CONFIG_CMDLINE.
> -
> - Systems with fully functional boot loaders (i.e. non-embedded)
> - should leave this option set to 'N'.
> -
> -config CMDLINE
> -   string "Built-in kernel command string"
> -   depends on CMDLINE_BOOL
> -   default ""
> -   help
> - Enter arguments here that should be compiled into the kernel
> - image and used at boot time.  If the boot loader provides a
> - command line at boot time, it is appended to this string to
> - form the full kernel command line, when the system boots.
> -
> - However, you can use the CONFIG_CMDLINE_OVERRIDE option to
> - change this behavior.
> -
> - In most cases, the command line (whether built-in or provided
> - by the boot loader) should specify the device for the root
> - file system.
> -
> -config CMDLINE_OVERRIDE
> -   bool "Built-in command line overrides boot loader arguments"
> -   depends on CMDLINE_BOOL && CMDLINE != ""
> -   help
> - Set this option to 'Y' to have the kernel ignore the boot loader
> - command line, and use ONLY the built-in command line.
> -
> - This is used to work around broken boot loaders.  This should
> - be set to 'N' under normal conditions.
> -
>  config MODIFY_LDT_SYSCALL
> bool "Enable the LDT (local descriptor table)" if EXPERT
> default y
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index 740f3bdb3f61..e748c3e5c1ae 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -48,6 +48,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  /*
>   * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
> @@ -162,9 +163,6 @@ unsigned long saved_video_mode;
>  #define RAMDISK_LOAD_FLAG  0x4000
>
>  static char __initdata command_line[COMMAND_LINE_SIZE];
> -#ifdef CONFIG_CMDLINE_BOOL
> -static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
> -#endif
>
>  #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
>  struct edd edd;
> @@ -884,19 +882,7 @@ void __init setup_arch(char **cmdline_p)
> bss_resource.start = __pa_symbol(__bss_start);
> bss_resource.end = __pa_symbol(__bss_stop)-1;
>
> -#ifdef CONFIG_CMDLINE_BOOL
> -#ifdef CONFIG_CMDLINE_OVERRIDE
> -   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
> -#else
> -   if (builtin_cmdline[0]) {
> -   /* append boot loader cmdline to builtin */
> -   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
> -   strlcat(builtin_cmdline, boot_command_line, 
> COMMAND_LINE_SIZE);
> -   strlcpy(boot_command_line, builtin_cmdline, 
> COMMAND_LINE_SIZE);
> -   }
> -#endif
> -#endif
> -
> +   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
> strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
> *cmdline_p = command_line;
>
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
> b/drivers/firmware/efi/libstub/x86-stub.c
> index f14c4ff5839f..9538c9d4a0bc 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -736,7 +736,7 @@ unsigned long efi_main(efi_handle_t handle,
> }
>
>  #ifdef CONFIG_CMDLINE_BOOL

Does this CMDLINE_BOOL check need to be dropped as well?


[PATCH] powerpc/vdso32: Add missing _restgpr_31_x to fix build failure

2021-03-08 Thread Christophe Leroy
With some defconfig including CONFIG_CC_OPTIMIZE_FOR_SIZE,
(for instance mvme5100_defconfig and ps3_defconfig), gcc 5
generates a call to _restgpr_31_x.

Until recently it went unnoticed, but
commit 42ed6d56ade2 ("powerpc/vdso: Block R_PPC_REL24 relocations")
made it rise to the surface.

Provide that function (copied from lib/crtsavres.S) in
gettimeofday.S

Fixes: ab037dd87a2f ("powerpc/vdso: Switch VDSO to generic C implementation.")
Signed-off-by: Christophe Leroy 
---
I don't know if there is a way to tell GCC not to emit that call, because at 
the end we get more instructions than needed.
---
 arch/powerpc/kernel/vdso32/gettimeofday.S | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S 
b/arch/powerpc/kernel/vdso32/gettimeofday.S
index a6e29f880e0e..d21d08140a5e 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -65,3 +65,14 @@ V_FUNCTION_END(__kernel_clock_getres)
 V_FUNCTION_BEGIN(__kernel_time)
cvdso_call_time __c_kernel_time
 V_FUNCTION_END(__kernel_time)
+
+/* Routines for restoring integer registers, called by the compiler.  */
+/* Called with r11 pointing to the stack header word of the caller of the */
+/* function, just beyond the end of the integer restore area.  */
+_GLOBAL(_restgpr_31_x)
+_GLOBAL(_rest32gpr_31_x)
+   lwz r0,4(r11)
+   lwz r31,-4(r11)
+   mtlrr0
+   mr  r1,r11
+   blr
-- 
2.25.0



Re: Errant readings on LM81 with T2080 SoC

2021-03-08 Thread Guenter Roeck
On 3/8/21 8:36 PM, Chris Packham wrote:
> 
> On 9/03/21 11:10 am, Chris Packham wrote:
>>
>> On 8/03/21 5:59 pm, Guenter Roeck wrote:
>>> On 3/7/21 8:37 PM, Chris Packham wrote:
>>> [ ... ]
> That's from -ENXIO which is used in only one place in i2c-mpc.c. I'll
> enable some debug and see what we get.
 For the errant readings there was nothing abnormal reported by the 
 driver.

 For the "No such device or address" I saw "mpc-i2c ffe119000.i2c: No
 RXAK" which matches up with the -ENXIO return.

>>> Id suggest to check the time until not busy and stop in mpc_xfer().
>>> Those hot loops are unusual, and may well mess up the code especially
>>> if preempt is enabled.
>> Reworking those loops seems to have had a positive result. I'll do a 
>> bit more testing and hopefully get a patch out later today.
> D'oh my "fix" was to replace the cond_reshed() with msleep(10) which did 
> "fix" the problem but made every i2c read slow. I didn't notice when 
> testing just the lm81 but as soon as I booted the system with more i2c 
> devices I saw stupidly slow boot times.

msleep() is indeed a bad idea. You'd want something like usleep_range()
with increasing timeout. Like start with a few uS and double the sleep time
with each iteration (eg 4-8 / 8-16 / 16-32 / 32-64 / ...).

Guenter


PowerPC64 future proof kernel toc, revised

2021-03-08 Thread Alan Modra
This patch future-proofs the kernel against linker changes that might
put the toc pointer at some location other than .got+0x8000, by
replacing __toc_start+0x8000 with __toc_ptr throughout.  __toc_ptr
is set from the symbol .TOC. emitted by ld on a final link, falling
back to .got+0x8000 for older ld that doesn't provide .TOC.  If the
kernel's idea of the toc pointer doesn't agree with the linker, bad
things happen.

prom_init.c code relocating its toc is also changed so that a symbolic
__prom_init_toc_start toc-pointer relative address is calculated
rather than assuming that it is always at toc-pointer - 0x8000.  The
length calculations loading values from the toc are also avoided.
It's a little incestuous to do that with unreloc_toc picking up
adjusted values (which is fine in practice, they both adjust by the
same amount if all goes well).

I've also changed the way .got is aligned in vmlinux.lds and
zImage.lds, mostly so that dumping out section info by objdump or
readelf plainly shows the alignment is 256.  This linker script
feature was added 2005-09-27, available in FSF binutils releases from
2.17 onwards.  Should be safe to use in the kernel, I think.

Finally, put *(.got) before the prom_init.o entry which only needs
*(.toc), so that the GOT header goes in the correct place.  I don't
believe this makes any difference for the kernel as it would for
dynamic objects being loaded by ld.so.  That change is just to stop
lusers who blindly copy kernel scripts being led astray.  Of course,
this change needs the prom_init.c changes.

Some notes on .toc and .got.

.toc is a compiler generated section of addresses.  .got is a linker
generated section of addresses, generally built when the linker sees
R_*_*GOT* relocations.  In the case of powerpc64 ld.bfd, there are
multiple generated .got sections, one per input object file.  So you
can somewhat reasonably write in a linker script an input section
statement like *prom_init.o(.got .toc) to mean "the .got and .toc
section for files matching *prom_init.o".  On other architectures that
doesn't make sense, because the linker generally has just one .got
section.  Even on powerpc64, note well that the GOT entries for
prom_init.o may be merged with GOT entries from other objects.  That
means that if prom_init.o references, say, _end via some GOT
relocation, and some other object also references _end via a GOT
relocation, the GOT entry for _end may be in the range
__prom_init_toc_start to __prom_init_toc_end and if the kernel does
something special to GOT/TOC entries in that range then the value of
_end as seen by objects other than prom_init.o will be affected.  On
the other hand the GOT entry for _end may not be in the range
__prom_init_toc_start to __prom_init_toc_end.  Which way it turns out
is deterministic but a detail of linker operation that should not be
relied on.

A feature of ld.bfd is that input .toc (and .got) sections matching
one linker input section statement may be sorted, to put entries used
by small-model code first, near the toc base.  This is why scripts for
powerpc64 normally use *(.got .toc) rather than *(.got) *(.toc), since
the first form allows more freedom to sort.

Another feature of ld.bfd is that indirect addressing sequences using
the GOT/TOC may be edited by the linker to relative addressing.  In
many cases relative addressing would be emitted by gcc for
-mcmodel=medium if you appropriately decorate variable declarations
with non-default visibility.


diff --git a/arch/powerpc/boot/crt0.S b/arch/powerpc/boot/crt0.S
index 1d83966f5ef6..8397af058650 100644
--- a/arch/powerpc/boot/crt0.S
+++ b/arch/powerpc/boot/crt0.S
@@ -28,7 +28,7 @@ p_etext:  .8byte  _etext
 p_bss_start:   .8byte  __bss_start
 p_end: .8byte  _end
 
-p_toc: .8byte  __toc_start + 0x8000 - p_base
+p_toc: .8byte  __toc_ptr - p_base
 p_dyn: .8byte  __dynamic_start - p_base
 p_rela:.8byte  __rela_dyn_start - p_base
 p_prom:.8byte  0
diff --git a/arch/powerpc/boot/zImage.lds.S b/arch/powerpc/boot/zImage.lds.S
index d6f072865627..35654cbcd294 100644
--- a/arch/powerpc/boot/zImage.lds.S
+++ b/arch/powerpc/boot/zImage.lds.S
@@ -36,13 +36,11 @@ SECTIONS
   }
 
 #ifdef CONFIG_PPC64_BOOT_WRAPPER
-  . = ALIGN(256);
-  .got :
+  .got : ALIGN(256)
   {
-__toc_start = .;
-*(.got)
-*(.toc)
+*(.got .toc)
   }
+  __toc_ptr = DEFINED (.TOC.) ? .TOC. : ADDR (.got) + 0x8000;
 #endif
 
   .hash : { *(.hash) }
diff --git a/arch/powerpc/include/asm/sections.h 
b/arch/powerpc/include/asm/sections.h
index 324d7b298ec3..4c3e84a2a073 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -49,13 +49,13 @@ static inline int in_kernel_text(unsigned long addr)
 static inline unsigned long kernel_toc_addr(void)
 {
/* Defined by the linker, see vmlinux.lds.S */
-   extern unsigned long __toc_start;
+   extern unsigned long __toc_ptr;
 
/*
 * The TOC 

Re: Errant readings on LM81 with T2080 SoC

2021-03-08 Thread Chris Packham

On 9/03/21 11:10 am, Chris Packham wrote:
>
> On 8/03/21 5:59 pm, Guenter Roeck wrote:
>> On 3/7/21 8:37 PM, Chris Packham wrote:
>> [ ... ]
 That's from -ENXIO which is used in only one place in i2c-mpc.c. I'll
 enable some debug and see what we get.
>>> For the errant readings there was nothing abnormal reported by the 
>>> driver.
>>>
>>> For the "No such device or address" I saw "mpc-i2c ffe119000.i2c: No
>>> RXAK" which matches up with the -ENXIO return.
>>>
>> Id suggest to check the time until not busy and stop in mpc_xfer().
>> Those hot loops are unusual, and may well mess up the code especially
>> if preempt is enabled.
> Reworking those loops seems to have had a positive result. I'll do a 
> bit more testing and hopefully get a patch out later today.
D'oh my "fix" was to replace the cond_reshed() with msleep(10) which did 
"fix" the problem but made every i2c read slow. I didn't notice when 
testing just the lm81 but as soon as I booted the system with more i2c 
devices I saw stupidly slow boot times.
>>   Also, are you using interrupts or polling in
>> your system ? The interrupt handler looks a bit odd, with "Read again
>> to allow register to stabilise".
>>
>> Do you have fsl,timeout set in the devicetree properties and, if so,
>> have you played with it ?
>>
>> Other than that, the only other real idea I have would be to monitor
>> the i2c bus.
>>
>> Guenter

Re: [PATCH 0/6] mm: some config cleanups

2021-03-08 Thread Anshuman Khandual
On 3/8/21 12:11 PM, Anshuman Khandual wrote:
> This series contains config cleanup patches which reduces code duplication
> across platforms and also improves maintainability. There is no functional
> change intended with this series. This has been boot tested on arm64 but
> only build tested on some other platforms.
> 
> This applies on 5.12-rc2
> 
> Cc: x...@kernel.org
> Cc: linux-i...@vger.kernel.org
> Cc: linux-s...@vger.kernel.org
> Cc: linux-snps-...@lists.infradead.org
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-m...@vger.kernel.org
> Cc: linux-par...@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-ri...@lists.infradead.org
> Cc: linux...@vger.kernel.org
> Cc: linux-fsde...@vger.kernel.org
> Cc: linux...@kvack.org
> Cc: linux-ker...@vger.kernel.org
> 
> Anshuman Khandual (6):
>   mm: Generalize ARCH_HAS_CACHE_LINE_SIZE
>   mm: Generalize SYS_SUPPORTS_HUGETLBFS (rename as ARCH_SUPPORTS_HUGETLBFS)
>   mm: Generalize ARCH_ENABLE_MEMORY_[HOTPLUG|HOTREMOVE]
>   mm: Drop redundant ARCH_ENABLE_[HUGEPAGE|THP]_MIGRATION
>   mm: Drop redundant ARCH_ENABLE_SPLIT_PMD_PTLOCK
>   mm: Drop redundant HAVE_ARCH_TRANSPARENT_HUGEPAGE

Seems like there was a problem during the email because some patches
might not have hit the mailing list. Although git send-email never
really reported any problem. Not sure what happened here.

https://patchwork.kernel.org/project/linux-mm/list/?series=443619
https://lore.kernel.org/linux-mm/1615185706-24342-1-git-send-email-anshuman.khand...@arm.com/

Will probably resend the series.

- Anshuman


[PATCH 3/3] powerpc/qspinlock: Use generic smp_cond_load_relaxed

2021-03-08 Thread Davidlohr Bueso
49a7d46a06c3 (powerpc: Implement smp_cond_load_relaxed()) added
busy-waiting pausing with a preferred SMT priority pattern, lowering
the priority (reducing decode cycles) during the whole loop slowpath.

However, data shows that while this pattern works well with simple
spinlocks, queued spinlocks benefit more being kept in medium priority,
with a cpu_relax() instead, being a low+medium combo on powerpc.

Data is from three benchmarks on a Power9: 9008-22L 64 CPUs with
2 sockets and 8 threads per core.

1. locktorture.

This is data for the lowest and most artificial/pathological level,
with increasing thread counts pounding on the lock. Metrics are total
ops/minute. Despite some small hits in the 4-8 range, scenarios are
either neutral or favorable to this patch.

+=+==+==+===+
| # tasks | vanilla  | dirty| %diff |
+=+==+==+===+
| 2   | 46718565 | 48751350 | 4.35  |
+-+--+--+---+
| 4   | 51740198 | 50369082 | -2.65 |
+-+--+--+---+
| 8   | 63756510 | 62568821 | -1.86 |
+-+--+--+---+
| 16  | 67824531 | 70966546 | 4.63  |
+-+--+--+---+
| 32  | 53843519 | 61155508 | 13.58 |
+-+--+--+---+
| 64  | 53005778 | 53104412 | 0.18  |
+-+--+--+---+
| 128 | 53331980 | 54606910 | 2.39  |
+=+==+==+===+

2. sockperf (tcp throughput)

Here a client will do one-way throughput tests to a localhost server, with
increasing message sizes, dealing with the sk_lock. This patch shows to put
the performance of the qspinlock back to par with that of the simple lock:

 simple-spinlock   vanilla  dirty
Hmean 1473.50 (   0.00%)   54.44 * -25.93%*   73.45 * 
-0.07%*
Hmean 100  654.47 (   0.00%)  385.61 * -41.08%*  771.43 * 
17.87%*
Hmean 300 2719.39 (   0.00%) 2181.67 * -19.77%* 2666.50 * 
-1.94%*
Hmean 500 4400.59 (   0.00%) 3390.77 * -22.95%* 4322.14 * 
-1.78%*
Hmean 850 6726.21 (   0.00%) 5264.03 * -21.74%* 6863.12 * 2.04%*

3. dbench (tmpfs)

Configured to run with up to ncpusx8 clients, it shows both latency and
throughput metrics. For the latency, with the exception of the 64 case,
there is really nothing to go by:
 vanilladirty
Amean latency-1  1.67 (   0.00%)1.67 *   0.09%*
Amean latency-2  2.15 (   0.00%)2.08 *   3.36%*
Amean latency-4  2.50 (   0.00%)2.56 *  -2.27%*
Amean latency-8  2.49 (   0.00%)2.48 *   0.31%*
Amean latency-16 2.69 (   0.00%)2.72 *  -1.37%*
Amean latency-32 2.96 (   0.00%)3.04 *  -2.60%*
Amean latency-64 7.78 (   0.00%)8.17 *  -5.07%*
Amean latency-512  186.91 (   0.00%)  186.41 *   0.27%*

For the dbench4 Throughput (misleading but traditional) there's a small
but rather constant improvement:

 vanilladirty
Hmean 1849.13 (   0.00%)  851.51 *   0.28%*
Hmean 2   1664.03 (   0.00%) 1663.94 *  -0.01%*
Hmean 4   3073.70 (   0.00%) 3104.29 *   1.00%*
Hmean 8   5624.02 (   0.00%) 5694.16 *   1.25%*
Hmean 16  9169.49 (   0.00%) 9324.43 *   1.69%*
Hmean 32 11969.37 (   0.00%)12127.09 *   1.32%*
Hmean 64 15021.12 (   0.00%)15243.14 *   1.48%*
Hmean 51214891.27 (   0.00%)15162.11 *   1.82%*

Measuring the dbench4 Per-VFS Operation latency, shows some very minor
differences within the noise level, around the 0-1% ranges.

Signed-off-by: Davidlohr Bueso 
---
 arch/powerpc/include/asm/barrier.h | 16 
 1 file changed, 16 deletions(-)

diff --git a/arch/powerpc/include/asm/barrier.h 
b/arch/powerpc/include/asm/barrier.h
index aecfde829d5d..7ae29cfb06c0 100644
--- a/arch/powerpc/include/asm/barrier.h
+++ b/arch/powerpc/include/asm/barrier.h
@@ -80,22 +80,6 @@ do { 
\
___p1;  \
 })
 
-#ifdef CONFIG_PPC64
-#define smp_cond_load_relaxed(ptr, cond_expr) ({   \
-   typeof(ptr) __PTR = (ptr);  \
-   __unqual_scalar_typeof(*ptr) VAL;   \
-   VAL = READ_ONCE(*__PTR);\
-   if (unlikely(!(cond_expr))) {   \
-   spin_begin();   \
-   do {\
-   VAL = READ_ONCE(*__PTR);\
-   } while (!(cond_expr)); \
-   spin_end(); 

[PATCH 2/3] powerpc/spinlock: Unserialize spin_is_locked

2021-03-08 Thread Davidlohr Bueso
c6f5d02b6a0f (locking/spinlocks/arm64: Remove smp_mb() from
arch_spin_is_locked()) made it pretty official that the call
semantics do not imply any sort of barriers, and any user that
gets creative must explicitly do any serialization.

This creativity, however, is nowadays pretty limited:

1. spin_unlock_wait() has been removed from the kernel in favor
of a lock/unlock combo. Furthermore, queued spinlocks have now
for a number of years no longer relied on _Q_LOCKED_VAL for the
call, but any non-zero value to indicate a locked state. There
were cases where the delayed locked store could lead to breaking
mutual exclusion with crossed locking; such as with sysv ipc and
netfilter being the most extreme.

2. The auditing Andrea did in verified that remaining spin_is_locked()
no longer rely on such semantics. Most callers just use it to assert
a lock is taken, in a debug nature. The only user that gets cute is
NOLOCK qdisc, as of:

   96009c7d500e (sched: replace __QDISC_STATE_RUNNING bit with a spin lock)

... which ironically went in the next day after c6f5d02b6a0f. This
change replaces test_bit() with spin_is_locked() to know whether
to take the busylock heuristic to reduce contention on the main
qdisc lock. So any races against spin_is_locked() for archs that
use LL/SC for spin_lock() will be benign and not break any mutual
exclusion; furthermore, both the seqlock and busylock have the same
scope.

Cc: parri.and...@gmail.com
Cc: pab...@redhat.com
Signed-off-by: Davidlohr Bueso 
---
 arch/powerpc/include/asm/qspinlock.h   | 12 
 arch/powerpc/include/asm/simple_spinlock.h |  3 +--
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/powerpc/include/asm/qspinlock.h 
b/arch/powerpc/include/asm/qspinlock.h
index 3ce1a0bee4fe..b052b0624816 100644
--- a/arch/powerpc/include/asm/qspinlock.h
+++ b/arch/powerpc/include/asm/qspinlock.h
@@ -44,18 +44,6 @@ static __always_inline void queued_spin_lock(struct 
qspinlock *lock)
 }
 #define queued_spin_lock queued_spin_lock
 
-static __always_inline int queued_spin_is_locked(struct qspinlock *lock)
-{
-   /*
-* This barrier was added to simple spinlocks by commit 51d7d5205d338,
-* but it should now be possible to remove it, asm arm64 has done with
-* commit c6f5d02b6a0f.
-*/
-   smp_mb();
-   return atomic_read(&lock->val);
-}
-#define queued_spin_is_locked queued_spin_is_locked
-
 #ifdef CONFIG_PARAVIRT_SPINLOCKS
 #define SPIN_THRESHOLD (1<<15) /* not tuned */
 
diff --git a/arch/powerpc/include/asm/simple_spinlock.h 
b/arch/powerpc/include/asm/simple_spinlock.h
index 3e87258f73b1..1b935396522a 100644
--- a/arch/powerpc/include/asm/simple_spinlock.h
+++ b/arch/powerpc/include/asm/simple_spinlock.h
@@ -38,8 +38,7 @@ static __always_inline int 
arch_spin_value_unlocked(arch_spinlock_t lock)
 
 static inline int arch_spin_is_locked(arch_spinlock_t *lock)
 {
-   smp_mb();
-   return !arch_spin_value_unlocked(*lock);
+   return !arch_spin_value_unlocked(READ_ONCE(*lock));
 }
 
 /*
-- 
2.26.2



[PATCH 1/3] powerpc/spinlock: Define smp_mb__after_spinlock only once

2021-03-08 Thread Davidlohr Bueso
Instead of both queued and simple spinlocks doing it. Move
it into the arch's spinlock.h.

Signed-off-by: Davidlohr Bueso 
---
 arch/powerpc/include/asm/qspinlock.h   | 2 --
 arch/powerpc/include/asm/simple_spinlock.h | 3 ---
 arch/powerpc/include/asm/spinlock.h| 3 +++
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/qspinlock.h 
b/arch/powerpc/include/asm/qspinlock.h
index b752d34517b3..3ce1a0bee4fe 100644
--- a/arch/powerpc/include/asm/qspinlock.h
+++ b/arch/powerpc/include/asm/qspinlock.h
@@ -44,8 +44,6 @@ static __always_inline void queued_spin_lock(struct qspinlock 
*lock)
 }
 #define queued_spin_lock queued_spin_lock
 
-#define smp_mb__after_spinlock()   smp_mb()
-
 static __always_inline int queued_spin_is_locked(struct qspinlock *lock)
 {
/*
diff --git a/arch/powerpc/include/asm/simple_spinlock.h 
b/arch/powerpc/include/asm/simple_spinlock.h
index 9c3c30534333..3e87258f73b1 100644
--- a/arch/powerpc/include/asm/simple_spinlock.h
+++ b/arch/powerpc/include/asm/simple_spinlock.h
@@ -282,7 +282,4 @@ static inline void arch_write_unlock(arch_rwlock_t *rw)
 #define arch_read_relax(lock)  rw_yield(lock)
 #define arch_write_relax(lock) rw_yield(lock)
 
-/* See include/linux/spinlock.h */
-#define smp_mb__after_spinlock()   smp_mb()
-
 #endif /* _ASM_POWERPC_SIMPLE_SPINLOCK_H */
diff --git a/arch/powerpc/include/asm/spinlock.h 
b/arch/powerpc/include/asm/spinlock.h
index 6ec72282888d..bd75872a6334 100644
--- a/arch/powerpc/include/asm/spinlock.h
+++ b/arch/powerpc/include/asm/spinlock.h
@@ -10,6 +10,9 @@
 #include 
 #endif
 
+/* See include/linux/spinlock.h */
+#define smp_mb__after_spinlock()   smp_mb()
+
 #ifndef CONFIG_PARAVIRT_SPINLOCKS
 static inline void pv_spinlocks_init(void) { }
 #endif
-- 
2.26.2



[PATCH 0/3] powerpc/qspinlock: Some tuning updates

2021-03-08 Thread Davidlohr Bueso
Hi,

A few updates while going through the powerpc port of the qspinlock.

Patches 1 and 2 are straightforward, while patch 3 can be considered
more of an rfc as I've only tested on a single machine, and there
could be an alternative way if it doesn't end up being nearly a
universal performance win.

Thanks!

Davidlohr Bueso (3):
  powerpc/spinlock: Define smp_mb__after_spinlock only once
  powerpc/spinlock: Unserialize spin_is_locked
  powerpc/qspinlock: Use generic smp_cond_load_relaxed

 arch/powerpc/include/asm/barrier.h | 16 
 arch/powerpc/include/asm/qspinlock.h   | 14 --
 arch/powerpc/include/asm/simple_spinlock.h |  6 +-
 arch/powerpc/include/asm/spinlock.h|  3 +++
 4 files changed, 4 insertions(+), 35 deletions(-)

--
2.26.2



Re: [PATCH] KVM: PPC: Book3S HV: Do not expose HFSCR sanitisation to nested hypervisor

2021-03-08 Thread Michael Ellerman
Fabiano Rosas  writes:
> Nicholas Piggin  writes:
>
>> Excerpts from Fabiano Rosas's message of March 6, 2021 9:10 am:
>>> As one of the arguments of the H_ENTER_NESTED hypercall, the nested
>>> hypervisor (L1) prepares a structure containing the values of various
>>> hypervisor-privileged registers with which it wants the nested guest
>>> (L2) to run. Since the nested HV runs in supervisor mode it needs the
>>> host to write to these registers.
>>> 
>>> To stop a nested HV manipulating this mechanism and using a nested
>>> guest as a proxy to access a facility that has been made unavailable
>>> to it, we have a routine that sanitises the values of the HV registers
>>> before copying them into the nested guest's vcpu struct.
>>> 
>>> However, when coming out of the guest the values are copied as they
>>> were back into L1 memory, which means that any sanitisation we did
>>> during guest entry will be exposed to L1 after H_ENTER_NESTED returns.
>>> 
>>> This is not a problem by itself, but in the case of the Hypervisor
>>> Facility Status and Control Register (HFSCR), we use the intersection
>>> between L2 hfscr bits and L1 hfscr bits. That means that L1 could use
>>> this to indirectly read the (hv-privileged) value from its vcpu
>>> struct.
>>> 
>>> This patch fixes this by making sure that L1 only gets back the bits
>>> that are necessary for regular functioning.
>>
>> The general idea of restricting exposure of HV privileged bits, but
>> for the case of HFSCR a guest can probe the HFCR anyway by testing which 
>> facilities are available (and presumably an HV may need some way to know
>> what features are available for it to advertise to its own guests), so
>> is this necessary? Perhaps a comment would be sufficient.
>
> Well, I'd be happy to force them through the arduous path then =); and
> there are features that are emulated by the HV which L1 would not be
> able to probe.
>
> I think we should implement a mechanism that stops all leaks now, rather
> than having to ponder about this every time we touch an hv_reg in that
> structure. I'm not too worried about HFSCR specifically.
>
> Let me think about this some more and see if I can make it more generic,
> I realise that sticking the saved_hfscr on the side is not the most
> elegant approach.

Yeah that would be good.

I don't really like the patch as it is, ie. having to pass *saved_hfscr
and so on.

But in general I agree that we should avoid leaking details across
boundaries, even if we don't think they are particularly sensitive.

cheers


Re: [PATCH v2 0/7] Generic Command Line changes

2021-03-08 Thread Randy Dunlap
On 3/8/21 3:53 PM, Daniel Walker wrote:
> This fixed some problem identified in my last release. I made updates
> based on comments from Christophe Leroy.
> 
> I added scripted updates to the defconfig file for mips and powerpc.
> This is required in order to maintain the status quo for those platforms
> which used the prior builtin command line system.
> 
> These were tested on all effected architectures.
> 
> Daniel Walker (7):
>   CMDLINE: add generic builtin command line
>   CMDLINE: drivers: of: ifdef out cmdline section
>   powerpc: convert config files to generic cmdline
>   CMDLINE: powerpc: convert to generic builtin command line
>   mips: convert config files to generic cmdline
>   CMDLINE: mips: convert to generic builtin command line
>   CMDLINE: x86: convert to generic builtin command line
> 


Hi Daniel,

These patches (1 - 7) should be sent as a Reply-to patch #0.

In .gitconfig, could you use
thread = true

or use --thread on the command line?

HTH.
thanks.
-- 
~Randy



Re: [PATCH v3 02/41] KVM: PPC: Book3S HV: Prevent radix guests from setting LPCR[TC]

2021-03-08 Thread Nicholas Piggin
Excerpts from Fabiano Rosas's message of March 9, 2021 1:47 am:
> Nicholas Piggin  writes:
> 
>> This bit only applies to hash partitions.
>>
>> Signed-off-by: Nicholas Piggin 
>> ---
>>  arch/powerpc/kvm/book3s_hv.c| 6 --
>>  arch/powerpc/kvm/book3s_hv_nested.c | 2 +-
>>  2 files changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>> index c40eeb20be39..2e29b96ef775 100644
>> --- a/arch/powerpc/kvm/book3s_hv.c
>> +++ b/arch/powerpc/kvm/book3s_hv.c
>> @@ -1666,10 +1666,12 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, 
>> u64 new_lpcr,
>>
>>  /*
>>   * Userspace can only modify DPFD (default prefetch depth),
>> - * ILE (interrupt little-endian) and TC (translation control).
>> + * ILE (interrupt little-endian) and TC (translation control) if HPT.
>>   * On POWER8 and POWER9 userspace can also modify AIL (alt. interrupt 
>> loc.).
>>   */
>> -mask = LPCR_DPFD | LPCR_ILE | LPCR_TC;
>> +mask = LPCR_DPFD | LPCR_ILE;
>> +if (!kvm_is_radix(kvm))
>> +mask |= LPCR_TC;
> 
> I think in theory there is a possibility that userspace sets the LPCR
> while we running Radix and then calls the KVM_PPC_CONFIGURE_V3_MMU ioctl
> right after to switch to HPT. I'm not sure if that would make sense but
> maybe it's something to consider...

Oh actually it is an issue for the later AIL patch I think.

So LPCR will have to be filtered again when switching MMU mode.

Good catch, I'll add something for that.

Thanks,
Nick

> 
>>  if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
>>  mask |= LPCR_AIL;
>>  /* LPCR[AIL]=1/2 is disallowed */
>> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c 
>> b/arch/powerpc/kvm/book3s_hv_nested.c
>> index b496079e02f7..0e6cf650cbfe 100644
>> --- a/arch/powerpc/kvm/book3s_hv_nested.c
>> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
>> @@ -141,7 +141,7 @@ static void sanitise_hv_regs(struct kvm_vcpu *vcpu, 
>> struct hv_guest_state *hr)
>>   * Don't let L1 change LPCR bits for the L2 except these:
>>   * Keep this in sync with kvmppc_set_lpcr.
>>   */
>> -mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_LD | LPCR_LPES | LPCR_MER;
>> +mask = LPCR_DPFD | LPCR_ILE | LPCR_LD | LPCR_LPES | LPCR_MER;
>>  /* LPCR[AIL]=1/2 is disallowed */
>>  if ((hr->lpcr & LPCR_AIL) && (hr->lpcr & LPCR_AIL) != LPCR_AIL_3)
>>  hr->lpcr &= ~LPCR_AIL;
> 


Re: [PATCH v3 01/41] KVM: PPC: Book3S HV: Disallow LPCR[AIL] to be set to 1 or 2

2021-03-08 Thread Nicholas Piggin
Excerpts from Fabiano Rosas's message of March 9, 2021 1:26 am:
> Nicholas Piggin  writes:
> 
>> These are already disallowed by H_SET_MODE from the guest, also disallow
>> these by updating LPCR directly.
>>
>> AIL modes can affect the host interrupt behaviour while the guest LPCR
>> value is set, so filter it here too.
>>
>> Suggested-by: Fabiano Rosas 
>> Signed-off-by: Nicholas Piggin 
>> ---
>>  arch/powerpc/kvm/book3s_hv.c| 11 +--
>>  arch/powerpc/kvm/book3s_hv_nested.c |  7 +--
>>  2 files changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
>> index 13bad6bf4c95..c40eeb20be39 100644
>> --- a/arch/powerpc/kvm/book3s_hv.c
>> +++ b/arch/powerpc/kvm/book3s_hv.c
>> @@ -803,7 +803,10 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, 
>> unsigned long mflags,
>>  vcpu->arch.dawrx1 = value2;
>>  return H_SUCCESS;
>>  case H_SET_MODE_RESOURCE_ADDR_TRANS_MODE:
>> -/* KVM does not support mflags=2 (AIL=2) */
>> +/*
>> + * KVM does not support mflags=2 (AIL=2) and AIL=1 is reserved.
>> + * Keep this in synch with kvmppc_set_lpcr.
>> + */
>>  if (mflags != 0 && mflags != 3)
>>  return H_UNSUPPORTED_FLAG_START;
>>  return H_TOO_HARD;
>> @@ -1667,8 +1670,12 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, 
>> u64 new_lpcr,
>>   * On POWER8 and POWER9 userspace can also modify AIL (alt. interrupt 
>> loc.).
>>   */
>>  mask = LPCR_DPFD | LPCR_ILE | LPCR_TC;
>> -if (cpu_has_feature(CPU_FTR_ARCH_207S))
>> +if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
>>  mask |= LPCR_AIL;
>> +/* LPCR[AIL]=1/2 is disallowed */
>> +if ((new_lpcr & LPCR_AIL) && (new_lpcr & LPCR_AIL) != 
>> LPCR_AIL_3)
>> +new_lpcr &= ~LPCR_AIL;
>> +}
>>  /*
>>   * On POWER9, allow userspace to enable large decrementer for the
>>   * guest, whether or not the host has it enabled.
>> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c 
>> b/arch/powerpc/kvm/book3s_hv_nested.c
>> index 2fe1fea4c934..b496079e02f7 100644
>> --- a/arch/powerpc/kvm/book3s_hv_nested.c
>> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
>> @@ -139,9 +139,12 @@ static void sanitise_hv_regs(struct kvm_vcpu *vcpu, 
>> struct hv_guest_state *hr)
> 
> We're missing the patch that moves the lpcr setting into
> sanitise_hv_regs.

Oh yes sorry, mistyped the format-patch command.

>>  
>>  /*
>>   * Don't let L1 change LPCR bits for the L2 except these:
>> + * Keep this in sync with kvmppc_set_lpcr.
>>   */
>> -mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_AIL | LPCR_LD |
>> -LPCR_LPES | LPCR_MER;
>> +mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_LD | LPCR_LPES | LPCR_MER;
> 
> I think this line's change belongs in patch 33 doesn't it? Otherwise you
> are clearing a bit below that is not present in the mask so it would
> never be used anyway.

Ah yes, thank you. Will fix.

> 
>> +/* LPCR[AIL]=1/2 is disallowed */
>> +if ((hr->lpcr & LPCR_AIL) && (hr->lpcr & LPCR_AIL) != LPCR_AIL_3)
>> +hr->lpcr &= ~LPCR_AIL;
>>  hr->lpcr = (vc->lpcr & ~mask) | (hr->lpcr & mask);
>>  
>>  /*
> 


Re: [PATCH] KVM: PPC: Book3S HV: Do not expose HFSCR sanitisation to nested hypervisor

2021-03-08 Thread Nicholas Piggin
Excerpts from Fabiano Rosas's message of March 9, 2021 1:04 am:
> Nicholas Piggin  writes:
> 
>> Excerpts from Fabiano Rosas's message of March 6, 2021 9:10 am:
>>> As one of the arguments of the H_ENTER_NESTED hypercall, the nested
>>> hypervisor (L1) prepares a structure containing the values of various
>>> hypervisor-privileged registers with which it wants the nested guest
>>> (L2) to run. Since the nested HV runs in supervisor mode it needs the
>>> host to write to these registers.
>>> 
>>> To stop a nested HV manipulating this mechanism and using a nested
>>> guest as a proxy to access a facility that has been made unavailable
>>> to it, we have a routine that sanitises the values of the HV registers
>>> before copying them into the nested guest's vcpu struct.
>>> 
>>> However, when coming out of the guest the values are copied as they
>>> were back into L1 memory, which means that any sanitisation we did
>>> during guest entry will be exposed to L1 after H_ENTER_NESTED returns.
>>> 
>>> This is not a problem by itself, but in the case of the Hypervisor
>>> Facility Status and Control Register (HFSCR), we use the intersection
>>> between L2 hfscr bits and L1 hfscr bits. That means that L1 could use
>>> this to indirectly read the (hv-privileged) value from its vcpu
>>> struct.
>>> 
>>> This patch fixes this by making sure that L1 only gets back the bits
>>> that are necessary for regular functioning.
>>
>> The general idea of restricting exposure of HV privileged bits, but
>> for the case of HFSCR a guest can probe the HFCR anyway by testing which 
>> facilities are available (and presumably an HV may need some way to know
>> what features are available for it to advertise to its own guests), so
>> is this necessary? Perhaps a comment would be sufficient.
>>
> 
> Well, I'd be happy to force them through the arduous path then =);

That's not a very satisifying justification.

> and
> there are features that are emulated by the HV which L1 would not be
> able to probe.

It should be able to trivially by measuring timing.

> 
> I think we should implement a mechanism that stops all leaks now, rather
> than having to ponder about this every time we touch an hv_reg in that
> structure.

This does not follow. There is already a "leak" via a timing or faulting 
side channel, so by definition we can't stop all leaks just by filtering 
the register value.

So what we need to do first I think is define what the threat is. What 
is the problem with the L1 knowing what the HFSCR is? If we can identify
a threat then we would appear to have much bigger problems. If not, then
this change can not be justified on the basis of security AFAIKS.

> I'm not too worried about HFSCR specifically.

HFSCR is pretty special because its behaviour makes it quite trivial to
extrapolate. It also has the fault cause bits in it that aren't being
sanitised either so that would have to be thought about.

> Let me think about this some more and see if I can make it more generic,
> I realise that sticking the saved_hfscr on the side is not the most
> elegant approach.

I would say returning an error from the hcall if the caller tries to 
enable an HFSCR bit that it's not allowed to would be the easiest
approach. At least then a well meaning but optimistic guest won't try
to enable and advertise missing features to its nested guests and have
them crash strangely, rather it would just stop up front.

I don't think trying to obscure HFSCR in general will ever be possible 
though.

Thanks,
Nick


[powerpc:next-test] BUILD SUCCESS 91de4cae55e214bfd8695e4ef9990ced34959e9a

2021-03-08 Thread kernel test robot
defconfig
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
x86_64   randconfig-a006-20210308
x86_64   randconfig-a001-20210308
x86_64   randconfig-a004-20210308
x86_64   randconfig-a002-20210308
x86_64   randconfig-a005-20210308
x86_64   randconfig-a003-20210308
i386 randconfig-a005-20210308
i386 randconfig-a003-20210308
i386 randconfig-a002-20210308
i386 randconfig-a006-20210308
i386 randconfig-a004-20210308
i386 randconfig-a001-20210308
i386 randconfig-a016-20210308
i386 randconfig-a012-20210308
i386 randconfig-a014-20210308
i386 randconfig-a013-20210308
i386 randconfig-a011-20210308
i386 randconfig-a015-20210308
riscvnommu_k210_defconfig
riscvallyesconfig
riscvnommu_virt_defconfig
riscv allnoconfig
riscv   defconfig
riscv  rv32_defconfig
riscvallmodconfig
x86_64   allyesconfig
x86_64rhel-7.6-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  rhel-8.3-kbuiltin
x86_64  kexec

clang tested configs:
x86_64   randconfig-a013-20210308
x86_64   randconfig-a016-20210308
x86_64   randconfig-a015-20210308
x86_64   randconfig-a014-20210308
x86_64   randconfig-a011-20210308
x86_64   randconfig-a012-20210308

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


[powerpc:merge] BUILD SUCCESS 67f76911b6d44cea4c783271c9633d1414bce4fb

2021-03-08 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git 
merge
branch HEAD: 67f76911b6d44cea4c783271c9633d1414bce4fb  Automatic merge of 
'master' into merge (2021-03-08 10:21)

elapsed time: 727m

configs tested: 127
configs skipped: 2

The following configs have been built successfully.
More configs may be tested in the coming days.

gcc tested configs:
arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
powerpc akebono_defconfig
sh  polaris_defconfig
sh  rsk7264_defconfig
powerpc mpc832x_mds_defconfig
arm  pcm027_defconfig
powerpc skiroot_defconfig
mipsworkpad_defconfig
sh  sdk7780_defconfig
shedosk7760_defconfig
powerpc  g5_defconfig
csky alldefconfig
powerpc  mpc885_ads_defconfig
nds32alldefconfig
pariscgeneric-32bit_defconfig
sh  lboxre2_defconfig
sh  rsk7203_defconfig
sh   se7619_defconfig
powerpccell_defconfig
arm   corgi_defconfig
arm eseries_pxa_defconfig
arm rpc_defconfig
armmvebu_v7_defconfig
powerpc stx_gp3_defconfig
sparcallyesconfig
sh espt_defconfig
m68k  sun3x_defconfig
sparc   sparc64_defconfig
mips  maltasmvp_eva_defconfig
m68k   m5208evb_defconfig
arm   imx_v6_v7_defconfig
arm ezx_defconfig
armtrizeps4_defconfig
h8300   h8s-sim_defconfig
powerpc  mgcoge_defconfig
sh sh03_defconfig
mips   capcella_defconfig
xtensa  audio_kc705_defconfig
sh   se7705_defconfig
arm bcm2835_defconfig
armkeystone_defconfig
mipsgpr_defconfig
armneponset_defconfig
arm   aspeed_g5_defconfig
sh  sdk7786_defconfig
arm   u8500_defconfig
mips mpc30x_defconfig
mips  decstation_64_defconfig
sh   se7721_defconfig
mips tb0219_defconfig
powerpc mpc8272_ads_defconfig
shecovec24-romimage_defconfig
armhisi_defconfig
ia64zx1_defconfig
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68k allmodconfig
m68kdefconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
nds32   defconfig
nios2allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
s390 allmodconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparc   defconfig
i386   tinyconfig
i386defconfig
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
x86_64   randconfig-a006-20210308
x86_64   randconfig-a001-20210308
x86_64   randconfig-a004-20210308
x86_64   randconfig-a002-20210308
x86_64   randconfig-a005-20210308
x86_64   randconfig-a003-20210308
i386 randconfig-a005-20210308
i386 randconfig-a003-20210308
i386 randconfig-a002-20210308
i386 randconfig-a006-202

[PATCH v2 7/7] CMDLINE: x86: convert to generic builtin command line

2021-03-08 Thread Daniel Walker
This updates the x86 code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/x86/Kconfig| 44 +
 arch/x86/kernel/setup.c | 18 ++
 drivers/firmware/efi/libstub/x86-stub.c |  2 +-
 3 files changed, 4 insertions(+), 60 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 21f851179ff0..3950f9bf9855 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -115,6 +115,7 @@ config X86
select EDAC_SUPPORT
select GENERIC_CLOCKEVENTS_BROADCASTif X86_64 || (X86_32 && 
X86_LOCAL_APIC)
select GENERIC_CLOCKEVENTS_MIN_ADJUST
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES
@@ -2368,49 +2369,6 @@ choice
 
 endchoice
 
-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
- boot arguments in CONFIG_CMDLINE.
-
- Systems with fully functional boot loaders (i.e. non-embedded)
- should leave this option set to 'N'.
-
-config CMDLINE
-   string "Built-in kernel command string"
-   depends on CMDLINE_BOOL
-   default ""
-   help
- Enter arguments here that should be compiled into the kernel
- image and used at boot time.  If the boot loader provides a
- command line at boot time, it is appended to this string to
- form the full kernel command line, when the system boots.
-
- However, you can use the CONFIG_CMDLINE_OVERRIDE option to
- change this behavior.
-
- In most cases, the command line (whether built-in or provided
- by the boot loader) should specify the device for the root
- file system.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides boot loader arguments"
-   depends on CMDLINE_BOOL && CMDLINE != ""
-   help
- Set this option to 'Y' to have the kernel ignore the boot loader
- command line, and use ONLY the built-in command line.
-
- This is used to work around broken boot loaders.  This should
- be set to 'N' under normal conditions.
-
 config MODIFY_LDT_SYSCALL
bool "Enable the LDT (local descriptor table)" if EXPERT
default y
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 740f3bdb3f61..e748c3e5c1ae 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -162,9 +163,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG  0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -884,19 +882,7 @@ void __init setup_arch(char **cmdline_p)
bss_resource.start = __pa_symbol(__bss_start);
bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-   if (builtin_cmdline[0]) {
-   /* append boot loader cmdline to builtin */
-   strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-   strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   }
-#endif
-#endif
-
+   cmdline_add_builtin(boot_command_line, NULL, COMMAND_LINE_SIZE);
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
 
diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
b/drivers/firmware/efi/libstub/x86-stub.c
index f14c4ff5839f..9538c9d4a0bc 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -736,7 +736,7 @@ unsigned long efi_main(efi_handle_t handle,
}
 
 #ifdef CONFIG_CMDLINE_BOOL
-   status = efi_parse_options(CONFIG_CMDLINE);
+   status = efi_parse_options(CONFIG_CMDLINE_PREPEND " " 
CONFIG_CMDLINE_APPEND);
if (status != EFI_SUCCESS) {
efi_err("Failed to parse options\n");
goto fail;
-- 
2.25.1



[PATCH v2 6/7] CMDLINE: mips: convert to generic builtin command line

2021-03-08 Thread Daniel Walker
This updates the mips code to use the CONFIG_GENERIC_CMDLINE
option.

This deletes the option for MIPS_CMDLINE_BUILTIN_EXTEND
and replaces the functionality with generic code.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/mips/Kconfig|  4 +---
 arch/mips/Kconfig.debug  | 44 
 arch/mips/kernel/setup.c | 36 
 3 files changed, 5 insertions(+), 79 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 0a17bedf4f0d..7c07b3bca9fc 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -23,6 +23,7 @@ config MIPS
select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
select CPU_PM if CPU_IDLE
select GENERIC_ATOMIC64 if !64BIT
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_GETTIMEOFDAY
@@ -3171,9 +3172,6 @@ choice
config MIPS_CMDLINE_FROM_BOOTLOADER
bool "Bootloader kernel arguments if available"
 
-   config MIPS_CMDLINE_BUILTIN_EXTEND
-   depends on CMDLINE_BOOL
-   bool "Extend builtin kernel arguments with bootloader arguments"
 endchoice
 
 endmenu
diff --git a/arch/mips/Kconfig.debug b/arch/mips/Kconfig.debug
index 7a8d94cdd493..b5a099c74eb6 100644
--- a/arch/mips/Kconfig.debug
+++ b/arch/mips/Kconfig.debug
@@ -30,50 +30,6 @@ config EARLY_PRINTK_8250
 config USE_GENERIC_EARLY_PRINTK_8250
bool
 
-config CMDLINE_BOOL
-   bool "Built-in kernel command line"
-   help
- For most systems, it is firmware or second stage bootloader that
- by default specifies the kernel command line options.  However,
- it might be necessary or advantageous to either override the
- default kernel command line or add a few extra options to it.
- For such cases, this option allows you to hardcode your own
- command line options directly into the kernel.  For that, you
- should choose 'Y' here, and fill in the extra boot arguments
- in CONFIG_CMDLINE.
-
- The built-in options will be concatenated to the default command
- line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
- command line will be ignored and replaced by the built-in string.
-
- Most MIPS systems will normally expect 'N' here and rely upon
- the command line from the firmware or the second-stage bootloader.
-
-config CMDLINE
-   string "Default kernel command string"
-   depends on CMDLINE_BOOL
-   help
- On some platforms, there is currently no way for the boot loader to
- pass arguments to the kernel.  For these platforms, and for the cases
- when you want to add some extra options to the command line or ignore
- the default command line, you can supply some command-line options at
- build time by entering them here.  In other cases you can specify
- kernel args so that you don't have to set them up in board prom
- initialization routines.
-
- For more information, see the CMDLINE_BOOL and CMDLINE_OVERRIDE
- options.
-
-config CMDLINE_OVERRIDE
-   bool "Built-in command line overrides firmware arguments"
-   depends on CMDLINE_BOOL
-   help
- By setting this option to 'Y' you will have your kernel ignore
- command line arguments from firmware or second stage bootloader.
- Instead, the built-in command line will be used exclusively.
-
- Normally, you will choose 'N' here.
-
 config SB1XXX_CORELIS
bool "Corelis Debugger"
depends on SIBYTE_SB1xxx_SOC
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 7e1f8e277437..8ce763e03792 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -67,12 +68,6 @@ EXPORT_SYMBOL(mips_machtype);
 static char __initdata command_line[COMMAND_LINE_SIZE];
 char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
 
-#ifdef CONFIG_CMDLINE_BOOL
-static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE;
-#else
-static const char builtin_cmdline[] __initconst = "";
-#endif
-
 /*
  * mips_io_port_base is the begin of the address space to which x86 style
  * I/O ports are mapped.
@@ -546,27 +541,7 @@ static void __init bootcmdline_init(void)
 {
bool dt_bootargs = false;
 
-   /*
-* If CMDLINE_OVERRIDE is enabled then initializing the command line is
-* trivial - we simply use the built-in command line unconditionally &
-* unmodified.
-*/
-   if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
-   strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-   return;
-   }
-
-   /*
-* If the user specified a built-in command line &
-

[PATCH v2 5/7] mips: convert config files to generic cmdline

2021-03-08 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 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_BOOL=y\nCONFIG_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
Signed-off-by: Daniel Walker 
---
 arch/mips/configs/ar7_defconfig|  9 ++---
 arch/mips/configs/bcm47xx_defconfig|  8 
 arch/mips/configs/bcm63xx_defconfig| 15 +--
 arch/mips/configs/bmips_be_defconfig   | 11 ---
 arch/mips/configs/bmips_stb_defconfig  | 11 ---
 arch/mips/configs/capcella_defconfig   | 11 ++-
 arch/mips/configs/ci20_defconfig   | 10 --
 arch/mips/configs/cu1000-neo_defconfig | 10 --
 arch/mips/configs/cu1830-neo_defconfig | 10 --
 arch/mips/configs/e55_defconfig|  4 ++--
 arch/mips/configs/generic_defconfig|  6 ++
 arch/mips/configs/gpr_defconfig| 18 +++---
 arch/mips/configs/loongson3_defconfig  | 13 ++---
 arch/mips/configs/mpc30x_defconfig |  7 ++-
 arch/mips/configs/tb0219_defconfig |  7 ++-
 arch/mips/configs/tb0226_defconfig |  7 ++-
 arch/mips/configs/tb0287_defconfig |  7 ++-
 arch/mips/configs/workpad_defconfig| 11 ---
 18 files changed, 54 insertions(+), 121 deletions(-)

diff --git a/arch/mips/configs/ar7_defconfig b/arch/mips/configs/ar7_defconfig
index cf9c6329b807..c09470aa672f 100644
--- a/arch/mips/configs/ar7_defconfig
+++ b/arch/mips/configs/ar7_defconfig
@@ -12,6 +12,8 @@ CONFIG_EXPERT=y
 # CONFIG_VM_EVENT_COUNTERS is not set
 # CONFIG_COMPAT_BRK is not set
 CONFIG_SLAB=y
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="rootfstype=squashfs,jffs2"
 CONFIG_AR7=y
 CONFIG_HZ_100=y
 CONFIG_KEXEC=y
@@ -32,9 +34,6 @@ CONFIG_IP_ROUTE_MULTIPATH=y
 CONFIG_IP_ROUTE_VERBOSE=y
 CONFIG_IP_MROUTE=y
 CONFIG_SYN_COOKIES=y
-# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
-# CONFIG_INET_XFRM_MODE_TUNNEL is not set
-# CONFIG_INET_XFRM_MODE_BEET is not set
 # CONFIG_INET_DIAG is not set
 CONFIG_TCP_CONG_ADVANCED=y
 # CONFIG_TCP_CONG_BIC is not set
@@ -43,7 +42,6 @@ CONFIG_TCP_CONG_WESTWOOD=y
 # CONFIG_TCP_CONG_HTCP is not set
 # CONFIG_IPV6 is not set
 CONFIG_NETFILTER=y
-# CONFIG_BRIDGE_NETFILTER is not set
 CONFIG_NF_CONNTRACK=m
 CONFIG_NF_CONNTRACK_MARK=y
 CONFIG_NF_CONNTRACK_FTP=m
@@ -117,8 +115,5 @@ CONFIG_JFFS2_SUMMARY=y
 CONFIG_JFFS2_COMPRESSION_OPTIONS=y
 CONFIG_SQUASHFS=y
 # CONFIG_CRYPTO_HW is not set
-# CONFIG_ENABLE_MUST_CHECK is not set
 CONFIG_STRIP_ASM_SYMS=y
 CONFIG_DEBUG_FS=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="rootfstype=squashfs,jffs2"
diff --git a/arch/mips/configs/bcm47xx_defconfig 
b/arch/mips/configs/bcm47xx_defconfig
index 91ce75edbfb4..69a965bb2dd9 100644
--- a/arch/mips/configs/bcm47xx_defconfig
+++ b/arch/mips/configs/bcm47xx_defconfig
@@ -4,8 +4,9 @@ CONFIG_BLK_DEV_INITRD=y
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_EMBEDDED=y
 CONFIG_SLAB=y
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="console=ttyS0,115200"
 CONFIG_BCM47XX=y
-CONFIG_PCI=y
 # CONFIG_SUSPEND is not set
 CONFIG_MODULES=y
 CONFIG_MODULE_UNLOAD=y
@@ -32,6 +33,7 @@ CONFIG_NET_SCH_FQ_CODEL=y
 CONFIG_HAMRADIO=y
 CONFIG_CFG80211=y
 CONFIG_MAC80211=y
+CONFIG_PCI=y
 CONFIG_MTD=y
 CONFIG_MTD_BCM47XX_PARTS=y
 CONFIG_MTD_BLOCK=y
@@ -75,7 +77,5 @@ CONFIG_PRINTK_TIME=y
 CONFIG_DEBUG_INFO=y
 CONFIG_DEBUG_INFO_REDUCED=y
 CONFIG_STRIP_ASM_SYMS=y
-CONFIG_DEBUG_FS=y
 CONFIG_MAGIC_SYSRQ=y
-CONFIG_CMDLINE_BOOL=y
-CONFIG_CMDLINE="console=ttyS0,115200"
+CONFIG_DEBUG_FS=y
diff --git a/arch/mips/configs/bcm63xx_defconfig 
b/arch/mips/configs/bcm63xx_defconfig
index 861f680184b9..6791e48b2d7d 100644
--- a/arch/mips/configs/bcm63xx_defconfig
+++ b/arch/mips/configs/bcm63xx_defconfig
@@ -11,27 +11,26 @@ CONFIG_EXPERT=y
 # CONFIG_AIO is not set
 # CONFIG_VM_EVENT_COUNTERS is not set
 # CONFIG_SLUB_DEBUG is not set
+CONFIG_CMDLINE_BOOL=y
+CONFIG_CMDLINE_PREPEND="console=ttyS0,115200"
 CONFIG_BCM63XX=y
 CONFIG_BCM63XX_CPU_6338=y
 CONFIG_BCM63XX_CPU_6345=y
 CONFIG_BCM63XX_CPU_6348=y
 CONFIG_BCM63XX_CPU_6358=y
 # CONFIG_SECCOMP is not set
-CONFIG_PCI=y
-CONFIG_PCCARD=y
-CONFIG_PCMCIA_BCM63XX=y
 # CONFIG_BLK_DEV_BSG is not set
 CONFIG_NET=y
 CONFIG_UNIX=y
 CONFIG_INET=y
-# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
-# CONFIG_INET_XFRM_MODE_TUNNEL is not set
-# CONFIG_INET_XFRM_MODE_BEET is not set
 # CONFIG_INET_DIAG is not set
 # CONFIG_IPV6 is not set
 CONFIG_CFG80211=y
 CONFIG_NL80211_TESTMODE=y
 CONFIG_MAC80211=y
+CONFIG_PCI=y
+CONFIG_PCCARD=y
+CONFIG_PCMCIA_BCM63XX=y
 # CONFIG_STANDALONE is not set
 # CONFIG_PREVENT_FIRMWARE_BUILD is not set
 CONFIG_MTD=y
@@ -50,8 +49,6 @@ CONFIG_B43=y
 # CONFIG_SERIO is

[PATCH v2 4/7] CMDLINE: powerpc: convert to generic builtin command line

2021-03-08 Thread Daniel Walker
This updates the powerpc code to use the CONFIG_GENERIC_CMDLINE
option.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 arch/powerpc/Kconfig| 37 +
 arch/powerpc/kernel/prom.c  |  1 +
 arch/powerpc/kernel/prom_init.c | 35 ++-
 3 files changed, 23 insertions(+), 50 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 107bb4319e0e..276b06d5c961 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -167,6 +167,7 @@ config PPC
select EDAC_SUPPORT
select GENERIC_ATOMIC64 if PPC32
select GENERIC_CLOCKEVENTS_BROADCASTif SMP
+   select GENERIC_CMDLINE
select GENERIC_CMOS_UPDATE
select GENERIC_CPU_AUTOPROBE
select GENERIC_CPU_VULNERABILITIES  if PPC_BARRIER_NOSPEC
@@ -906,42 +907,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
-   string "Initial kernel command string"
-   default ""
-   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.
-
-choice
-   prompt "Kernel command line type" if CMDLINE != ""
-   default CMDLINE_FROM_BOOTLOADER
-
-config CMDLINE_FROM_BOOTLOADER
-   bool "Use bootloader kernel arguments if available"
-   help
- Uses the command-line options passed by the boot loader. If
- the boot loader doesn't provide any, the default kernel command
- string provided in CMDLINE will be used.
-
-config CMDLINE_EXTEND
-   bool "Extend bootloader kernel arguments"
-   help
- The command-line arguments provided by the boot loader will be
- appended to the default kernel command string.
-
-config CMDLINE_FORCE
-   bool "Always use the default kernel command string"
-   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.
-
-endchoice
-
 config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index ae3c41730367..96d0a01be1b4 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index e9d4eb6144e1..657241534d69 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -242,15 +243,6 @@ static int __init prom_strcmp(const char *cs, const char 
*ct)
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;
@@ -276,6 +268,20 @@ static size_t __init prom_strlen(const char *s)
return sc - s;
 }
 
+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;
+}
+
+
 static int __init prom_memcmp(const void *cs, const void *ct, size_t count)
 {
const unsigned char *su1, *su2;
@@ -304,6 +310,7 @@ static char __init *prom_strstr(const char *s1, const char 
*s2)
return NULL;
 }
 
+#ifdef GENERIC_CMDLINE_NEED_STRLCAT
 static size_t __init prom_strlcat(char *dest, const char *src, size_t count)
 {
size_t dsize = prom_strlen(dest);
@@ -323,6 +330,7 @@ static size_t __init prom_strlcat(char *dest, const char 
*src, size_t count)
return res;
 
 }
+#endif
 
 #ifdef CONFIG_PPC_PSERIES
 static int __init prom_strtobool(const char *s, bool *res)
@@ -775,12 +783,11 @@ static void __init early_cmdline_parse(void)
prom_cmd_line[0] = 0;
p = prom_cmd_line;
 
-   if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && (long)prom.chosen > 0)
+   if ((long)prom.chosen > 0)
l = prom_getprop(prom.chosen, "bootargs", p, 
COMMAND_LINE_SIZE-1);
 
-   if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || l <= 0 || p[0] == '\0')
-

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

2021-03-08 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 bash 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_BOOL=y\nCONFIG_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
Signed-off-by: Daniel Walker 
---
 arch/powerpc/configs/44x/fsp2_defconfig   | 33 +--
 arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 17 +-
 arch/powerpc/configs/holly_defconfig  | 13 
 arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
 arch/powerpc/configs/skiroot_defconfig| 12 +++
 arch/powerpc/configs/storcenter_defconfig | 18 --
 7 files changed, 66 insertions(+), 75 deletions(-)

diff --git a/arch/powerpc/configs/44x/fsp2_defconfig 
b/arch/powerpc/configs/44x/fsp2_defconfig
index 30845ce0885a..4993db054589 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,24 +11,25 @@ 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="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
@@ -47,14 +46,12 @@ CONFIG_MTD=y
 CONFIG_MTD_BLOCK=y
 CONFIG_MTD_JEDECPROBE=y
 CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_PHYSMAP_OF=y
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_SIZE=35000
 # CONFIG_SCSI_PROC_FS is not set
 CONFIG_BLK_DEV_SD=y
 # CONFIG_SCSI_LOWLEVEL is not set
 CONFIG_ATA=y
-# CONFIG_SATA_PMP is not set
 # CONFIG_ATA_SFF is not set
 CONFIG_NETDEVICES=y
 CONFIG_BONDING=m
@@ -63,7 +60,6 @@ CONFIG_IBM_EMAC=m
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_8250_NR_UARTS=32
@@ -72,6 +68,7 @@ CONFIG_SERIAL_8250_EXTENDED=y
 CONFIG_SERIAL_8250_SHARE_IRQ=y
 CONFIG_SERIAL_OF_PLATFORM=y
 # CONFIG_HW_RANDOM is not set
+# CONFIG_DEVMEM is not set
 CONFIG_I2C=y
 CONFIG_I2C_IBM_IIC=y
 CONFIG_PTP_1588_CLOCK=y
@@ -107,6 +104,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
@@ -114,9 +117,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 2c3834eebca3..b8d97061517a 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,20 +5,22 @@ 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="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
@@ -34,7 +34,6 @@ CONFIG_MTD=y
 CONFIG_MTD_BLOCK=y
 CONFIG_MTD_JEDECPROBE=y
 CONFIG_MTD_CFI_AMDSTD=y
-CONFIG_MTD_PHYSMAP_OF=y
 CONFIG_BLK_DEV_RAM=y
 CONFIG_BLK_DEV_RAM_SIZE=35000
 # CONFIG_INPUT is not set
@@ -57,13 +56,13 @@ CONFIG_PROC_KCORE=y

[PATCH v2 2/7] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-08 Thread Daniel Walker
It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index feb0f2d67fc5..e25240d84632 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1050,6 +1051,16 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", &l);
+
+#ifdef CONFIG_GENERIC_CMDLINE
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   (l > 0 ? p : NULL), /* This is sanity checking */
+   COMMAND_LINE_SIZE);
+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
@@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.1



[PATCH v2 0/7] Generic Command Line changes

2021-03-08 Thread Daniel Walker
This fixed some problem identified in my last release. I made updates
based on comments from Christophe Leroy.

I added scripted updates to the defconfig file for mips and powerpc.
This is required in order to maintain the status quo for those platforms
which used the prior builtin command line system.

These were tested on all effected architectures.

Daniel Walker (7):
  CMDLINE: add generic builtin command line
  CMDLINE: drivers: of: ifdef out cmdline section
  powerpc: convert config files to generic cmdline
  CMDLINE: powerpc: convert to generic builtin command line
  mips: convert config files to generic cmdline
  CMDLINE: mips: convert to generic builtin command line
  CMDLINE: x86: convert to generic builtin command line

 arch/mips/Kconfig |  4 +-
 arch/mips/Kconfig.debug   | 44 -
 arch/mips/configs/ar7_defconfig   |  9 +-
 arch/mips/configs/bcm47xx_defconfig   |  8 +-
 arch/mips/configs/bcm63xx_defconfig   | 15 ++--
 arch/mips/configs/bmips_be_defconfig  | 11 +--
 arch/mips/configs/bmips_stb_defconfig | 11 +--
 arch/mips/configs/capcella_defconfig  | 11 +--
 arch/mips/configs/ci20_defconfig  | 10 +--
 arch/mips/configs/cu1000-neo_defconfig| 10 +--
 arch/mips/configs/cu1830-neo_defconfig| 10 +--
 arch/mips/configs/e55_defconfig   |  4 +-
 arch/mips/configs/generic_defconfig   |  6 +-
 arch/mips/configs/gpr_defconfig   | 18 +---
 arch/mips/configs/loongson3_defconfig | 13 +--
 arch/mips/configs/mpc30x_defconfig|  7 +-
 arch/mips/configs/tb0219_defconfig|  7 +-
 arch/mips/configs/tb0226_defconfig|  7 +-
 arch/mips/configs/tb0287_defconfig|  7 +-
 arch/mips/configs/workpad_defconfig   | 11 +--
 arch/mips/kernel/setup.c  | 36 +---
 arch/powerpc/Kconfig  | 37 +---
 arch/powerpc/configs/44x/fsp2_defconfig   | 33 ---
 arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 17 ++--
 arch/powerpc/configs/holly_defconfig  | 13 +--
 arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
 arch/powerpc/configs/skiroot_defconfig| 12 ++-
 arch/powerpc/configs/storcenter_defconfig | 18 ++--
 arch/powerpc/kernel/prom.c|  1 +
 arch/powerpc/kernel/prom_init.c   | 35 +---
 arch/x86/Kconfig  | 44 +
 arch/x86/kernel/setup.c   | 18 +---
 drivers/firmware/efi/libstub/x86-stub.c   |  2 +-
 drivers/of/fdt.c  | 12 +++
 include/linux/cmdline.h   | 89 +++
 init/Kconfig  | 68 ++
 37 files changed, 321 insertions(+), 385 deletions(-)
 create mode 100644 include/linux/cmdline.h

-- 
2.25.1



[PATCH v2 1/7] CMDLINE: add generic builtin command line

2021-03-08 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 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.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 89 +
 init/Kconfig| 68 +++
 2 files changed, 157 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 ..00929b6e49e6
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+#define GENERIC_CMDLINE_NEED_STRLCAT
+/*
+ * 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.
+ * @cmdline_strlcpy: point to a compatible strlcpy
+ * @cmdline_strlcat: point to a compatible strlcat
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   if (src != dest && src != NULL) {
+   cmdline_strlcpy(dest, " ", length);
+   cmdline_strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   cmdline_strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   cmdline_strlcat(tmp, dest, length);
+   cmdline_strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
\
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
cmdline_strlcpy, cmdline_strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
\
+   __cmdline_add_builtin(dest, src, NULL, length, cmdline_strlcpy, 
cmdline_strlcat);   \
+   }   
\
+}
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_custom(dest, src, length, __initdata, strlcpy, 
strlcat)
+
+#else /* CONFIG_CMDLINE_OVERRIDE */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, 
length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, src, length) \
+   __cmdline_add_builtin_custom(dest, src, length, strlcpy)
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else /* !CONFIG_GENERIC_CMDLINE || !CONFIG_CMDLINE_BOOL */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   if (src != NULL)
+   cmdline_strlcpy(dest, src, length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, 

[PATCH v2 2/7] CMDLINE: drivers: of: ifdef out cmdline section

2021-03-08 Thread Daniel Walker
It looks like there's some seepage of cmdline stuff into
the generic device tree code. This conflicts with the
generic cmdline implementation so I remove it in the case
when that's enabled.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Ruslichenko 
Signed-off-by: Daniel Walker 
---
 drivers/of/fdt.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index feb0f2d67fc5..e25240d84632 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include   /* for COMMAND_LINE_SIZE */
 #include 
@@ -1050,6 +1051,16 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
 
/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", &l);
+
+#ifdef CONFIG_GENERIC_CMDLINE
+   /*
+* The builtin command line will be added here, or it can override
+* with the DT bootargs.
+*/
+   cmdline_add_builtin(data,
+   (l > 0 ? p : NULL), /* This is sanity checking */
+   COMMAND_LINE_SIZE);
+#else
if (p != NULL && l > 0)
strlcpy(data, p, min(l, COMMAND_LINE_SIZE));
 
@@ -1070,6 +1081,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, 
const char *uname,
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif /* CONFIG_CMDLINE */
+#endif /* CONFIG_GENERIC_CMDLINE */
 
pr_debug("Command line is: %s\n", (char *)data);
 
-- 
2.25.1



[PATCH v2 1/7] CMDLINE: add generic builtin command line

2021-03-08 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 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.

Cc: xe-linux-exter...@cisco.com
Signed-off-by: Ruslan Bilovol 
Signed-off-by: Daniel Walker 
---
 include/linux/cmdline.h | 89 +
 init/Kconfig| 68 +++
 2 files changed, 157 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 ..00929b6e49e6
--- /dev/null
+++ b/include/linux/cmdline.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CMDLINE_H
+#define _LINUX_CMDLINE_H
+
+/*
+ *
+ * Copyright (C) 2006,2021. Cisco Systems, Inc.
+ *
+ * Generic Append/Prepend cmdline support.
+ */
+
+#if defined(CONFIG_GENERIC_CMDLINE) && defined(CONFIG_CMDLINE_BOOL)
+
+#ifndef CONFIG_CMDLINE_OVERRIDE
+#define GENERIC_CMDLINE_NEED_STRLCAT
+/*
+ * 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.
+ * @cmdline_strlcpy: point to a compatible strlcpy
+ * @cmdline_strlcat: point to a compatible strlcat
+ */
+static inline void
+__cmdline_add_builtin(char *dest, const char *src, char *tmp, unsigned long 
length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size),
+   size_t (*cmdline_strlcat)(char *dest, const char *src, size_t 
count))
+{
+   if (src != dest && src != NULL) {
+   cmdline_strlcpy(dest, " ", length);
+   cmdline_strlcat(dest, src, length);
+   }
+
+   if (sizeof(CONFIG_CMDLINE_APPEND) > 1)
+   cmdline_strlcat(dest, " " CONFIG_CMDLINE_APPEND, length);
+
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {
+   cmdline_strlcpy(tmp, CONFIG_CMDLINE_PREPEND " ", length);
+   cmdline_strlcat(tmp, dest, length);
+   cmdline_strlcpy(dest, tmp, length);
+   }
+}
+
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+{  
\
+   if (sizeof(CONFIG_CMDLINE_PREPEND) > 1) {   
\
+   static label char cmdline_tmp_space[length];
\
+   __cmdline_add_builtin(dest, src, cmdline_tmp_space, length, 
cmdline_strlcpy, cmdline_strlcat);  \
+   } else if (sizeof(CONFIG_CMDLINE_APPEND) > 1) { 
\
+   __cmdline_add_builtin(dest, src, NULL, length, cmdline_strlcpy, 
cmdline_strlcat);   \
+   }   
\
+}
+#define cmdline_add_builtin(dest, src, length) \
+   cmdline_add_builtin_custom(dest, src, length, __initdata, strlcpy, 
strlcat)
+
+#else /* CONFIG_CMDLINE_OVERRIDE */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   cmdline_strlcpy(dest, CONFIG_CMDLINE_PREPEND " " CONFIG_CMDLINE_APPEND, 
length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, src, length) \
+   __cmdline_add_builtin_custom(dest, src, length, strlcpy)
+#endif /* !CONFIG_CMDLINE_OVERRIDE */
+
+#else /* !CONFIG_GENERIC_CMDLINE || !CONFIG_CMDLINE_BOOL */
+
+static inline void
+__cmdline_add_builtin_custom(char *dest, const char *src, unsigned long length,
+   size_t (*cmdline_strlcpy)(char *dest, const char *src, size_t 
size))
+{
+   if (src != NULL)
+   cmdline_strlcpy(dest, src, length);
+}
+#define cmdline_add_builtin_custom(dest, src, length, label, cmdline_strlcpy, 
cmdline_strlcat) \
+   __cmdline_add_builtin_custom(dest, src, length, cmdline_strlcpy)
+#define cmdline_add_builtin(dest, 

[PATCH v2 0/7] Generic Command Line changes

2021-03-08 Thread Daniel Walker
This fixed some problem identified in my last release. I made updates
based on comments from Christophe Leroy.

I added scripted updates to the defconfig file for mips and powerpc.
This is required in order to maintain the status quo for those platforms
which used the prior builtin command line system.

These were tested on all effected architectures.

Daniel Walker (7):
  CMDLINE: add generic builtin command line
  CMDLINE: drivers: of: ifdef out cmdline section
  powerpc: convert config files to generic cmdline
  CMDLINE: powerpc: convert to generic builtin command line
  mips: convert config files to generic cmdline
  CMDLINE: mips: convert to generic builtin command line
  CMDLINE: x86: convert to generic builtin command line

 arch/mips/Kconfig |  4 +-
 arch/mips/Kconfig.debug   | 44 -
 arch/mips/configs/ar7_defconfig   |  9 +-
 arch/mips/configs/bcm47xx_defconfig   |  8 +-
 arch/mips/configs/bcm63xx_defconfig   | 15 ++--
 arch/mips/configs/bmips_be_defconfig  | 11 +--
 arch/mips/configs/bmips_stb_defconfig | 11 +--
 arch/mips/configs/capcella_defconfig  | 11 +--
 arch/mips/configs/ci20_defconfig  | 10 +--
 arch/mips/configs/cu1000-neo_defconfig| 10 +--
 arch/mips/configs/cu1830-neo_defconfig| 10 +--
 arch/mips/configs/e55_defconfig   |  4 +-
 arch/mips/configs/generic_defconfig   |  6 +-
 arch/mips/configs/gpr_defconfig   | 18 +---
 arch/mips/configs/loongson3_defconfig | 13 +--
 arch/mips/configs/mpc30x_defconfig|  7 +-
 arch/mips/configs/tb0219_defconfig|  7 +-
 arch/mips/configs/tb0226_defconfig|  7 +-
 arch/mips/configs/tb0287_defconfig|  7 +-
 arch/mips/configs/workpad_defconfig   | 11 +--
 arch/mips/kernel/setup.c  | 36 +---
 arch/powerpc/Kconfig  | 37 +---
 arch/powerpc/configs/44x/fsp2_defconfig   | 33 ---
 arch/powerpc/configs/44x/iss476-smp_defconfig | 25 +++---
 arch/powerpc/configs/44x/warp_defconfig   | 17 ++--
 arch/powerpc/configs/holly_defconfig  | 13 +--
 arch/powerpc/configs/mvme5100_defconfig   | 23 ++---
 arch/powerpc/configs/skiroot_defconfig| 12 ++-
 arch/powerpc/configs/storcenter_defconfig | 18 ++--
 arch/powerpc/kernel/prom.c|  1 +
 arch/powerpc/kernel/prom_init.c   | 35 +---
 arch/x86/Kconfig  | 44 +
 arch/x86/kernel/setup.c   | 18 +---
 drivers/firmware/efi/libstub/x86-stub.c   |  2 +-
 drivers/of/fdt.c  | 12 +++
 include/linux/cmdline.h   | 89 +++
 init/Kconfig  | 68 ++
 37 files changed, 321 insertions(+), 385 deletions(-)
 create mode 100644 include/linux/cmdline.h

-- 
2.25.1



Re: Errant readings on LM81 with T2080 SoC

2021-03-08 Thread Guenter Roeck
On Mon, Mar 08, 2021 at 08:27:30PM +, Chris Packham wrote:
[ ... ]
> > Other than that, the only other real idea I have would be to monitor
> > the i2c bus.
> I am in the fortunate position of being able to go into the office and 
> even happen to have the expensive scope at the moment. Now I just need 
> to find a tame HW engineer so I don't burn myself trying to attach the 
> probes.
> 
A bit unrelated, but you can get scopes connected through usb which are
quite low-cost (like in the $100 range) and good enough for i2c testing.

Guenter


Re: Errant readings on LM81 with T2080 SoC

2021-03-08 Thread Chris Packham

On 8/03/21 5:59 pm, Guenter Roeck wrote:
> On 3/7/21 8:37 PM, Chris Packham wrote:
> [ ... ]
>>> That's from -ENXIO which is used in only one place in i2c-mpc.c. I'll
>>> enable some debug and see what we get.
>> For the errant readings there was nothing abnormal reported by the driver.
>>
>> For the "No such device or address" I saw "mpc-i2c ffe119000.i2c: No
>> RXAK" which matches up with the -ENXIO return.
>>
> Id suggest to check the time until not busy and stop in mpc_xfer().
> Those hot loops are unusual, and may well mess up the code especially
> if preempt is enabled.
Reworking those loops seems to have had a positive result. I'll do a bit 
more testing and hopefully get a patch out later today.
>   Also, are you using interrupts or polling in
> your system ? The interrupt handler looks a bit odd, with "Read again
> to allow register to stabilise".
>
> Do you have fsl,timeout set in the devicetree properties and, if so,
> have you played with it ?
>
> Other than that, the only other real idea I have would be to monitor
> the i2c bus.
>
> Guenter

Re: Errant readings on LM81 with T2080 SoC

2021-03-08 Thread Chris Packham

On 8/03/21 5:59 pm, Guenter Roeck wrote:
> On 3/7/21 8:37 PM, Chris Packham wrote:
> [ ... ]
>>> That's from -ENXIO which is used in only one place in i2c-mpc.c. I'll
>>> enable some debug and see what we get.
>> For the errant readings there was nothing abnormal reported by the driver.
>>
>> For the "No such device or address" I saw "mpc-i2c ffe119000.i2c: No
>> RXAK" which matches up with the -ENXIO return.
>>
> Id suggest to check the time until not busy and stop in mpc_xfer().
> Those hot loops are unusual, and may well mess up the code especially
> if preempt is enabled. Also, are you using interrupts or polling in
> your system ?
I'm using interrupts but I see the same issue if I comment out the 
interrupts in the dtsi file (i.e. force it to use polling).
> The interrupt handler looks a bit odd, with "Read again
> to allow register to stabilise".

Yeah that stuck out to me too. The code in question predates git, I went 
spelunking in history.git and the "Read again" seems to be in the 
initial version[0]. I did try to alter the interrupt handler so that it 
only does one read but that didn't seem to change anything.

> Do you have fsl,timeout set in the devicetree properties and, if so,
> have you played with it ?
Haven't got it set but I'll have a go at tweaking it.
> Other than that, the only other real idea I have would be to monitor
> the i2c bus.
I am in the fortunate position of being able to go into the office and 
even happen to have the expensive scope at the moment. Now I just need 
to find a tame HW engineer so I don't burn myself trying to attach the 
probes.

-- 

[0] - 
https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=11b3235dc04a306f6a9ba14c1ab621b2d54f2c56



Re: [PATCH v2 2/8] powerpc/xive: Introduce an IPI interrupt domain

2021-03-08 Thread Greg Kurz
On Wed, 3 Mar 2021 18:48:51 +0100
Cédric Le Goater  wrote:

> The IPI interrupt is a special case of the XIVE IRQ domain. When
> mapping and unmapping the interrupts in the Linux interrupt number
> space, the HW interrupt number 0 (XIVE_IPI_HW_IRQ) is checked to
> distinguish the IPI interrupt from other interrupts of the system.
> 
> Simplify the XIVE interrupt domain by introducing a specific domain
> for the IPI.
> 
> Signed-off-by: Cédric Le Goater 
> ---

Nice !

Reviewed-by: Greg Kurz 

>  arch/powerpc/sysdev/xive/common.c | 51 +--
>  1 file changed, 22 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/common.c 
> b/arch/powerpc/sysdev/xive/common.c
> index b8e456da28aa..e7783760d278 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -63,6 +63,8 @@ static const struct xive_ops *xive_ops;
>  static struct irq_domain *xive_irq_domain;
>  
>  #ifdef CONFIG_SMP
> +static struct irq_domain *xive_ipi_irq_domain;
> +
>  /* The IPIs all use the same logical irq number */
>  static u32 xive_ipi_irq;
>  #endif
> @@ -1067,20 +1069,32 @@ static struct irq_chip xive_ipi_chip = {
>   .irq_unmask = xive_ipi_do_nothing,
>  };
>  
> +/*
> + * IPIs are marked per-cpu. We use separate HW interrupts under the
> + * hood but associated with the same "linux" interrupt
> + */
> +static int xive_ipi_irq_domain_map(struct irq_domain *h, unsigned int virq,
> +irq_hw_number_t hw)
> +{
> + irq_set_chip_and_handler(virq, &xive_ipi_chip, handle_percpu_irq);
> + return 0;
> +}
> +
> +static const struct irq_domain_ops xive_ipi_irq_domain_ops = {
> + .map = xive_ipi_irq_domain_map,
> +};
> +
>  static void __init xive_request_ipi(void)
>  {
>   unsigned int virq;
>  
> - /*
> -  * Initialization failed, move on, we might manage to
> -  * reach the point where we display our errors before
> -  * the system falls appart
> -  */
> - if (!xive_irq_domain)
> + xive_ipi_irq_domain = irq_domain_add_linear(NULL, 1,
> + &xive_ipi_irq_domain_ops, 
> NULL);
> + if (WARN_ON(xive_ipi_irq_domain == NULL))
>   return;
>  
>   /* Initialize it */
> - virq = irq_create_mapping(xive_irq_domain, XIVE_IPI_HW_IRQ);
> + virq = irq_create_mapping(xive_ipi_irq_domain, XIVE_IPI_HW_IRQ);
>   xive_ipi_irq = virq;
>  
>   WARN_ON(request_irq(virq, xive_muxed_ipi_action,
> @@ -1178,19 +1192,6 @@ static int xive_irq_domain_map(struct irq_domain *h, 
> unsigned int virq,
>*/
>   irq_clear_status_flags(virq, IRQ_LEVEL);
>  
> -#ifdef CONFIG_SMP
> - /* IPIs are special and come up with HW number 0 */
> - if (hw == XIVE_IPI_HW_IRQ) {
> - /*
> -  * IPIs are marked per-cpu. We use separate HW interrupts under
> -  * the hood but associated with the same "linux" interrupt
> -  */
> - irq_set_chip_and_handler(virq, &xive_ipi_chip,
> -  handle_percpu_irq);
> - return 0;
> - }
> -#endif
> -
>   rc = xive_irq_alloc_data(virq, hw);
>   if (rc)
>   return rc;
> @@ -1202,15 +1203,7 @@ static int xive_irq_domain_map(struct irq_domain *h, 
> unsigned int virq,
>  
>  static void xive_irq_domain_unmap(struct irq_domain *d, unsigned int virq)
>  {
> - struct irq_data *data = irq_get_irq_data(virq);
> - unsigned int hw_irq;
> -
> - /* XXX Assign BAD number */
> - if (!data)
> - return;
> - hw_irq = (unsigned int)irqd_to_hwirq(data);
> - if (hw_irq != XIVE_IPI_HW_IRQ)
> - xive_irq_free_data(virq);
> + xive_irq_free_data(virq);
>  }
>  
>  static int xive_irq_domain_xlate(struct irq_domain *h, struct device_node 
> *ct,



Re: [PATCH] net: wan: fix error return code of uhdlc_init()

2021-03-08 Thread patchwork-bot+netdevbpf
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Sun,  7 Mar 2021 01:12:56 -0800 you wrote:
> When priv->rx_skbuff or priv->tx_skbuff is NULL, no error return code of
> uhdlc_init() is assigned.
> To fix this bug, ret is assigned with -ENOMEM in these cases.
> 
> Reported-by: TOTE Robot 
> Signed-off-by: Jia-Ju Bai 
> 
> [...]

Here is the summary with links:
  - net: wan: fix error return code of uhdlc_init()
https://git.kernel.org/netdev/net/c/62765d39553c

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




Re: [PATCH next v4 00/15] printk: remove logbuf_lock

2021-03-08 Thread Petr Mladek
On Wed 2021-03-03 16:34:19, Petr Mladek wrote:
> On Wed 2021-03-03 11:15:13, John Ogness wrote:
> > Hello,
> > 
> > Here is v4 of a series to remove @logbuf_lock, exposing the
> > ringbuffer locklessly to both readers and writers. v3 is
> > here [0].
> 
> The series look ready. I am going to push it into printk/linux.git
> the following week unless anyone speaks against it in the meantime.

The series is committed in printk/linux.git, branch printk-rework.

Best Regards,
Petr


Re: [PATCH v2 4/8] powerpc/xive: Simplify xive_core_debug_show()

2021-03-08 Thread Cédric Le Goater
On 3/8/21 7:07 PM, Greg Kurz wrote:
> On Wed, 3 Mar 2021 18:48:53 +0100
> Cédric Le Goater  wrote:
> 
>> Now that the IPI interrupt has its own domain, the checks on the HW
>> interrupt number XIVE_IPI_HW_IRQ and on the chip can be replaced by a
>> check on the domain.
>>
>> Signed-off-by: Cédric Le Goater 
>> ---
> 
> Shouldn't this have the following tags ?
> 
> Reported-by: kernel test robot 
> Reported-by: Dan Carpenter 
> Fixes: 930914b7d528 ("powerpc/xive: Add a debugfs file to dump internal XIVE 
> state")

The next patch has because it removes the useless check on irq_data.
 
C.

> 
> Anyway,
> 
> Reviewed-by: Greg Kurz 
> 
>>  arch/powerpc/sysdev/xive/common.c | 18 --
>>  1 file changed, 4 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/powerpc/sysdev/xive/common.c 
>> b/arch/powerpc/sysdev/xive/common.c
>> index 678680531d26..7581cb12bb53 100644
>> --- a/arch/powerpc/sysdev/xive/common.c
>> +++ b/arch/powerpc/sysdev/xive/common.c
>> @@ -1579,17 +1579,14 @@ static void xive_debug_show_cpu(struct seq_file *m, 
>> int cpu)
>>  seq_puts(m, "\n");
>>  }
>>  
>> -static void xive_debug_show_irq(struct seq_file *m, u32 hw_irq, struct 
>> irq_data *d)
>> +static void xive_debug_show_irq(struct seq_file *m, struct irq_data *d)
>>  {
>> -struct irq_chip *chip = irq_data_get_irq_chip(d);
>> +unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
>>  int rc;
>>  u32 target;
>>  u8 prio;
>>  u32 lirq;
>>  
>> -if (!is_xive_irq(chip))
>> -return;
>> -
>>  rc = xive_ops->get_irq_config(hw_irq, &target, &prio, &lirq);
>>  if (rc) {
>>  seq_printf(m, "IRQ 0x%08x : no config rc=%d\n", hw_irq, rc);
>> @@ -1627,16 +1624,9 @@ static int xive_core_debug_show(struct seq_file *m, 
>> void *private)
>>  
>>  for_each_irq_desc(i, desc) {
>>  struct irq_data *d = irq_desc_get_irq_data(desc);
>> -unsigned int hw_irq;
>> -
>> -if (!d)
>> -continue;
>> -
>> -hw_irq = (unsigned int)irqd_to_hwirq(d);
>>  
>> -/* IPIs are special (HW number 0) */
>> -if (hw_irq != XIVE_IPI_HW_IRQ)
>> -xive_debug_show_irq(m, hw_irq, d);
>> +if (d->domain == xive_irq_domain)
>> +xive_debug_show_irq(m, d);
>>  }
>>  return 0;
>>  }
> 



Re: [PATCH v2 4/8] powerpc/xive: Simplify xive_core_debug_show()

2021-03-08 Thread Greg Kurz
On Wed, 3 Mar 2021 18:48:53 +0100
Cédric Le Goater  wrote:

> Now that the IPI interrupt has its own domain, the checks on the HW
> interrupt number XIVE_IPI_HW_IRQ and on the chip can be replaced by a
> check on the domain.
> 
> Signed-off-by: Cédric Le Goater 
> ---

Shouldn't this have the following tags ?

Reported-by: kernel test robot 
Reported-by: Dan Carpenter 
Fixes: 930914b7d528 ("powerpc/xive: Add a debugfs file to dump internal XIVE 
state")


Anyway,

Reviewed-by: Greg Kurz 

>  arch/powerpc/sysdev/xive/common.c | 18 --
>  1 file changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/common.c 
> b/arch/powerpc/sysdev/xive/common.c
> index 678680531d26..7581cb12bb53 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -1579,17 +1579,14 @@ static void xive_debug_show_cpu(struct seq_file *m, 
> int cpu)
>   seq_puts(m, "\n");
>  }
>  
> -static void xive_debug_show_irq(struct seq_file *m, u32 hw_irq, struct 
> irq_data *d)
> +static void xive_debug_show_irq(struct seq_file *m, struct irq_data *d)
>  {
> - struct irq_chip *chip = irq_data_get_irq_chip(d);
> + unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
>   int rc;
>   u32 target;
>   u8 prio;
>   u32 lirq;
>  
> - if (!is_xive_irq(chip))
> - return;
> -
>   rc = xive_ops->get_irq_config(hw_irq, &target, &prio, &lirq);
>   if (rc) {
>   seq_printf(m, "IRQ 0x%08x : no config rc=%d\n", hw_irq, rc);
> @@ -1627,16 +1624,9 @@ static int xive_core_debug_show(struct seq_file *m, 
> void *private)
>  
>   for_each_irq_desc(i, desc) {
>   struct irq_data *d = irq_desc_get_irq_data(desc);
> - unsigned int hw_irq;
> -
> - if (!d)
> - continue;
> -
> - hw_irq = (unsigned int)irqd_to_hwirq(d);
>  
> - /* IPIs are special (HW number 0) */
> - if (hw_irq != XIVE_IPI_HW_IRQ)
> - xive_debug_show_irq(m, hw_irq, d);
> + if (d->domain == xive_irq_domain)
> + xive_debug_show_irq(m, d);
>   }
>   return 0;
>  }



Re: [PATCH v2 3/8] powerpc/xive: Remove useless check on XIVE_IPI_HW_IRQ

2021-03-08 Thread Greg Kurz
On Wed, 3 Mar 2021 18:48:52 +0100
Cédric Le Goater  wrote:

> The IPI interrupt has its own domain now. Testing the HW interrupt
> number is not needed anymore.
> 
> Signed-off-by: Cédric Le Goater 
> ---

Reviewed-by: Greg Kurz 

>  arch/powerpc/sysdev/xive/common.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/common.c 
> b/arch/powerpc/sysdev/xive/common.c
> index e7783760d278..678680531d26 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -1396,13 +1396,12 @@ static void xive_flush_cpu_queue(unsigned int cpu, 
> struct xive_cpu *xc)
>   struct irq_desc *desc = irq_to_desc(irq);
>   struct irq_data *d = irq_desc_get_irq_data(desc);
>   struct xive_irq_data *xd;
> - unsigned int hw_irq = (unsigned int)irqd_to_hwirq(d);
>  
>   /*
>* Ignore anything that isn't a XIVE irq and ignore
>* IPIs, so can just be dropped.
>*/
> - if (d->domain != xive_irq_domain || hw_irq == XIVE_IPI_HW_IRQ)
> + if (d->domain != xive_irq_domain)
>   continue;
>  
>   /*



Re: [PATCH v3 20/41] KVM: PPC: Book3S HV P9: Move setting HDEC after switching to guest LPCR

2021-03-08 Thread Fabiano Rosas
Nicholas Piggin  writes:

> LPCR[HDICE]=0 suppresses hypervisor decrementer exceptions on some
> processors, so it must be enabled before HDEC is set.
>
> Rather than set it in the host LPCR then setting HDEC, move the HDEC
> update to after the guest MMU context (including LPCR) is loaded.
> There shouldn't be much concern with delaying HDEC by some 10s or 100s
> of nanoseconds by setting it a bit later.
>
> Signed-off-by: Nicholas Piggin 

Reviewed-by: Fabiano Rosas 

> ---
>  arch/powerpc/kvm/book3s_hv.c | 19 +++
>  1 file changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 1f2ba8955c6a..ffde1917ab68 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -3505,20 +3505,9 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu 
> *vcpu, u64 time_limit,
>   host_dawrx1 = mfspr(SPRN_DAWRX1);
>   }
>
> - /*
> -  * P8 and P9 suppress the HDEC exception when LPCR[HDICE] = 0,
> -  * so set HDICE before writing HDEC.
> -  */
> - mtspr(SPRN_LPCR, kvm->arch.host_lpcr | LPCR_HDICE);
> - isync();
> -
>   hdec = time_limit - mftb();
> - if (hdec < 0) {
> - mtspr(SPRN_LPCR, kvm->arch.host_lpcr);
> - isync();
> + if (hdec < 0)
>   return BOOK3S_INTERRUPT_HV_DECREMENTER;
> - }
> - mtspr(SPRN_HDEC, hdec);
>
>   if (vc->tb_offset) {
>   u64 new_tb = mftb() + vc->tb_offset;
> @@ -3564,6 +3553,12 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu 
> *vcpu, u64 time_limit,
>
>   switch_mmu_to_guest_radix(kvm, vcpu, lpcr);
>
> + /*
> +  * P9 suppresses the HDEC exception when LPCR[HDICE] = 0,
> +  * so set guest LPCR (with HDICE) before writing HDEC.
> +  */
> + mtspr(SPRN_HDEC, hdec);
> +
>   mtspr(SPRN_SRR0, vcpu->arch.shregs.srr0);
>   mtspr(SPRN_SRR1, vcpu->arch.shregs.srr1);


Re: [PATCH v2 1/8] powerpc/xive: Use cpu_to_node() instead of ibm,chip-id property

2021-03-08 Thread Greg Kurz
On Wed, 3 Mar 2021 18:48:50 +0100
Cédric Le Goater  wrote:

> The 'chip_id' field of the XIVE CPU structure is used to choose a
> target for a source located on the same chip when possible. This field
> is assigned on the PowerNV platform using the "ibm,chip-id" property
> on pSeries under KVM when NUMA nodes are defined but it is undefined

This sentence seems to have a syntax problem... like it is missing an
'and' before 'on pSeries'.

> under PowerVM. The XIVE source structure has a similar field
> 'src_chip' which is only assigned on the PowerNV platform.
> 
> cpu_to_node() returns a compatible value on all platforms, 0 being the
> default node. It will also give us the opportunity to set the affinity
> of a source on pSeries when we can localize them.
> 

IIUC this relies on the fact that the NUMA node id is == to chip id
on PowerNV, i.e. xc->chip_id which is passed to OPAL remain stable
with this change.

On the other hand, you have the pSeries case under PowerVM that
doesn't xc->chip_id, which isn't passed to any hcall AFAICT. It
looks like the chip id is only used for localization purpose in
this case, right ?

In this case, what about doing this change for pSeries only,
somewhere in spapr.c ?

> Signed-off-by: Cédric Le Goater 
> ---
>  arch/powerpc/sysdev/xive/common.c | 7 +--
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/xive/common.c 
> b/arch/powerpc/sysdev/xive/common.c
> index 595310e056f4..b8e456da28aa 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -1335,16 +1335,11 @@ static int xive_prepare_cpu(unsigned int cpu)
>  
>   xc = per_cpu(xive_cpu, cpu);
>   if (!xc) {
> - struct device_node *np;
> -
>   xc = kzalloc_node(sizeof(struct xive_cpu),
> GFP_KERNEL, cpu_to_node(cpu));
>   if (!xc)
>   return -ENOMEM;
> - np = of_get_cpu_node(cpu, NULL);
> - if (np)
> - xc->chip_id = of_get_ibm_chip_id(np);
> - of_node_put(np);
> + xc->chip_id = cpu_to_node(cpu);
>   xc->hw_ipi = XIVE_BAD_IRQ;
>  
>   per_cpu(xive_cpu, cpu) = xc;



Re: [PATCH] ASoC: fsl_xcvr: Use devm_platform_ioremap_resource_byname() to simplify code

2021-03-08 Thread Mark Brown
On Tue, 2 Mar 2021 20:50:02 +0800, Tang Bin wrote:
> In this function, devm_platform_ioremap_resource_byname() should be
> suitable to simplify code.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: fsl_xcvr: Use devm_platform_ioremap_resource_byname() to simplify 
code
  commit: c5f48a78e0cb950eb821af36b8790b794cc745b1

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


Re: [PATCH v3 02/41] KVM: PPC: Book3S HV: Prevent radix guests from setting LPCR[TC]

2021-03-08 Thread Fabiano Rosas
Nicholas Piggin  writes:

> This bit only applies to hash partitions.
>
> Signed-off-by: Nicholas Piggin 
> ---
>  arch/powerpc/kvm/book3s_hv.c| 6 --
>  arch/powerpc/kvm/book3s_hv_nested.c | 2 +-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index c40eeb20be39..2e29b96ef775 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -1666,10 +1666,12 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, 
> u64 new_lpcr,
>
>   /*
>* Userspace can only modify DPFD (default prefetch depth),
> -  * ILE (interrupt little-endian) and TC (translation control).
> +  * ILE (interrupt little-endian) and TC (translation control) if HPT.
>* On POWER8 and POWER9 userspace can also modify AIL (alt. interrupt 
> loc.).
>*/
> - mask = LPCR_DPFD | LPCR_ILE | LPCR_TC;
> + mask = LPCR_DPFD | LPCR_ILE;
> + if (!kvm_is_radix(kvm))
> + mask |= LPCR_TC;

I think in theory there is a possibility that userspace sets the LPCR
while we running Radix and then calls the KVM_PPC_CONFIGURE_V3_MMU ioctl
right after to switch to HPT. I'm not sure if that would make sense but
maybe it's something to consider...

>   if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
>   mask |= LPCR_AIL;
>   /* LPCR[AIL]=1/2 is disallowed */
> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c 
> b/arch/powerpc/kvm/book3s_hv_nested.c
> index b496079e02f7..0e6cf650cbfe 100644
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -141,7 +141,7 @@ static void sanitise_hv_regs(struct kvm_vcpu *vcpu, 
> struct hv_guest_state *hr)
>* Don't let L1 change LPCR bits for the L2 except these:
>* Keep this in sync with kvmppc_set_lpcr.
>*/
> - mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_LD | LPCR_LPES | LPCR_MER;
> + mask = LPCR_DPFD | LPCR_ILE | LPCR_LD | LPCR_LPES | LPCR_MER;
>   /* LPCR[AIL]=1/2 is disallowed */
>   if ((hr->lpcr & LPCR_AIL) && (hr->lpcr & LPCR_AIL) != LPCR_AIL_3)
>   hr->lpcr &= ~LPCR_AIL;


Re: [PATCH v3 01/41] KVM: PPC: Book3S HV: Disallow LPCR[AIL] to be set to 1 or 2

2021-03-08 Thread Fabiano Rosas
Nicholas Piggin  writes:

> These are already disallowed by H_SET_MODE from the guest, also disallow
> these by updating LPCR directly.
>
> AIL modes can affect the host interrupt behaviour while the guest LPCR
> value is set, so filter it here too.
>
> Suggested-by: Fabiano Rosas 
> Signed-off-by: Nicholas Piggin 
> ---
>  arch/powerpc/kvm/book3s_hv.c| 11 +--
>  arch/powerpc/kvm/book3s_hv_nested.c |  7 +--
>  2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 13bad6bf4c95..c40eeb20be39 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -803,7 +803,10 @@ static int kvmppc_h_set_mode(struct kvm_vcpu *vcpu, 
> unsigned long mflags,
>   vcpu->arch.dawrx1 = value2;
>   return H_SUCCESS;
>   case H_SET_MODE_RESOURCE_ADDR_TRANS_MODE:
> - /* KVM does not support mflags=2 (AIL=2) */
> + /*
> +  * KVM does not support mflags=2 (AIL=2) and AIL=1 is reserved.
> +  * Keep this in synch with kvmppc_set_lpcr.
> +  */
>   if (mflags != 0 && mflags != 3)
>   return H_UNSUPPORTED_FLAG_START;
>   return H_TOO_HARD;
> @@ -1667,8 +1670,12 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 
> new_lpcr,
>* On POWER8 and POWER9 userspace can also modify AIL (alt. interrupt 
> loc.).
>*/
>   mask = LPCR_DPFD | LPCR_ILE | LPCR_TC;
> - if (cpu_has_feature(CPU_FTR_ARCH_207S))
> + if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
>   mask |= LPCR_AIL;
> + /* LPCR[AIL]=1/2 is disallowed */
> + if ((new_lpcr & LPCR_AIL) && (new_lpcr & LPCR_AIL) != 
> LPCR_AIL_3)
> + new_lpcr &= ~LPCR_AIL;
> + }
>   /*
>* On POWER9, allow userspace to enable large decrementer for the
>* guest, whether or not the host has it enabled.
> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c 
> b/arch/powerpc/kvm/book3s_hv_nested.c
> index 2fe1fea4c934..b496079e02f7 100644
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -139,9 +139,12 @@ static void sanitise_hv_regs(struct kvm_vcpu *vcpu, 
> struct hv_guest_state *hr)

We're missing the patch that moves the lpcr setting into
sanitise_hv_regs.

>  
>   /*
>* Don't let L1 change LPCR bits for the L2 except these:
> +  * Keep this in sync with kvmppc_set_lpcr.
>*/
> - mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_AIL | LPCR_LD |
> - LPCR_LPES | LPCR_MER;
> + mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_LD | LPCR_LPES | LPCR_MER;

I think this line's change belongs in patch 33 doesn't it? Otherwise you
are clearing a bit below that is not present in the mask so it would
never be used anyway.

> + /* LPCR[AIL]=1/2 is disallowed */
> + if ((hr->lpcr & LPCR_AIL) && (hr->lpcr & LPCR_AIL) != LPCR_AIL_3)
> + hr->lpcr &= ~LPCR_AIL;
>   hr->lpcr = (vc->lpcr & ~mask) | (hr->lpcr & mask);
>  
>   /*


Re: [PATCH] KVM: PPC: Book3S HV: Do not expose HFSCR sanitisation to nested hypervisor

2021-03-08 Thread Fabiano Rosas
Nicholas Piggin  writes:

> Excerpts from Fabiano Rosas's message of March 6, 2021 9:10 am:
>> As one of the arguments of the H_ENTER_NESTED hypercall, the nested
>> hypervisor (L1) prepares a structure containing the values of various
>> hypervisor-privileged registers with which it wants the nested guest
>> (L2) to run. Since the nested HV runs in supervisor mode it needs the
>> host to write to these registers.
>> 
>> To stop a nested HV manipulating this mechanism and using a nested
>> guest as a proxy to access a facility that has been made unavailable
>> to it, we have a routine that sanitises the values of the HV registers
>> before copying them into the nested guest's vcpu struct.
>> 
>> However, when coming out of the guest the values are copied as they
>> were back into L1 memory, which means that any sanitisation we did
>> during guest entry will be exposed to L1 after H_ENTER_NESTED returns.
>> 
>> This is not a problem by itself, but in the case of the Hypervisor
>> Facility Status and Control Register (HFSCR), we use the intersection
>> between L2 hfscr bits and L1 hfscr bits. That means that L1 could use
>> this to indirectly read the (hv-privileged) value from its vcpu
>> struct.
>> 
>> This patch fixes this by making sure that L1 only gets back the bits
>> that are necessary for regular functioning.
>
> The general idea of restricting exposure of HV privileged bits, but
> for the case of HFSCR a guest can probe the HFCR anyway by testing which 
> facilities are available (and presumably an HV may need some way to know
> what features are available for it to advertise to its own guests), so
> is this necessary? Perhaps a comment would be sufficient.
>

Well, I'd be happy to force them through the arduous path then =); and
there are features that are emulated by the HV which L1 would not be
able to probe.

I think we should implement a mechanism that stops all leaks now, rather
than having to ponder about this every time we touch an hv_reg in that
structure. I'm not too worried about HFSCR specifically.

Let me think about this some more and see if I can make it more generic,
I realise that sticking the saved_hfscr on the side is not the most
elegant approach.

> Thanks,
> Nick
>
>> 
>> Signed-off-by: Fabiano Rosas 
>> ---
>>  arch/powerpc/kvm/book3s_hv_nested.c | 22 +-
>>  1 file changed, 17 insertions(+), 5 deletions(-)
>> 
>> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c 
>> b/arch/powerpc/kvm/book3s_hv_nested.c
>> index 0cd0e7aad588..860004f46e08 100644
>> --- a/arch/powerpc/kvm/book3s_hv_nested.c
>> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
>> @@ -98,12 +98,20 @@ static void byteswap_hv_regs(struct hv_guest_state *hr)
>>  }
>>  
>>  static void save_hv_return_state(struct kvm_vcpu *vcpu, int trap,
>> - struct hv_guest_state *hr)
>> + struct hv_guest_state *hr, u64 saved_hfscr)
>>  {
>>  struct kvmppc_vcore *vc = vcpu->arch.vcore;
>>  
>> +/*
>> + * During sanitise_hv_regs() we used HFSCR bits from L1 state
>> + * to restrict what the L2 state is allowed to be. Since L1 is
>> + * not allowed to read this SPR, do not include these
>> + * modifications in the return state.
>> + */
>> +hr->hfscr = ((~HFSCR_INTR_CAUSE & saved_hfscr) |
>> + (HFSCR_INTR_CAUSE & vcpu->arch.hfscr));
>> +
>>  hr->dpdes = vc->dpdes;
>> -hr->hfscr = vcpu->arch.hfscr;
>>  hr->purr = vcpu->arch.purr;
>>  hr->spurr = vcpu->arch.spurr;
>>  hr->ic = vcpu->arch.ic;
>> @@ -132,12 +140,14 @@ static void save_hv_return_state(struct kvm_vcpu 
>> *vcpu, int trap,
>>  }
>>  }
>>  
>> -static void sanitise_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state 
>> *hr)
>> +static void sanitise_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state 
>> *hr,
>> + u64 *saved_hfscr)
>>  {
>>  /*
>>   * Don't let L1 enable features for L2 which we've disabled for L1,
>>   * but preserve the interrupt cause field.
>>   */
>> +*saved_hfscr = hr->hfscr;
>>  hr->hfscr &= (HFSCR_INTR_CAUSE | vcpu->arch.hfscr);
>>  
>>  /* Don't let data address watchpoint match in hypervisor state */
>> @@ -272,6 +282,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
>>  u64 hdec_exp;
>>  s64 delta_purr, delta_spurr, delta_ic, delta_vtb;
>>  u64 mask;
>> +u64 hfscr;
>>  unsigned long lpcr;
>>  
>>  if (vcpu->kvm->arch.l1_ptcr == 0)
>> @@ -324,7 +335,8 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
>>  mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_AIL | LPCR_LD |
>>  LPCR_LPES | LPCR_MER;
>>  lpcr = (vc->lpcr & ~mask) | (l2_hv.lpcr & mask);
>> -sanitise_hv_regs(vcpu, &l2_hv);
>> +
>> +sanitise_hv_regs(vcpu, &l2_hv, &hfscr);
>>  restore_hv_regs(vcpu, &l2_hv);
>>  
>>  vcpu->arch.ret = RESUME_GUEST;
>> @@ -345,7 +357,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
>>  delta

Re: [PATCH v1 12/15] powerpc/uaccess: Refactor get/put_user() and __get/put_user()

2021-03-08 Thread Christian König
The radeon warning is trivial to fix, going to send out a patch in a few 
moments.


Regards,
Christian.

Am 08.03.21 um 13:14 schrieb Christophe Leroy:

+Evgeniy for W1 Dallas
+Alex & Christian for RADEON

Le 07/03/2021 à 11:23, kernel test robot a écrit :

Hi Christophe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on v5.12-rc2 next-20210305]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: 
https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-Cleanup-of-uaccess-h/20210226-015715
base: 
https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next

config: powerpc-randconfig-s031-20210307 (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce:
 wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross 
-O ~/bin/make.cross

 chmod +x ~/bin/make.cross
 # apt-get install sparse
 # sparse version: v0.6.3-245-gacc5c298-dirty
 # 
https://github.com/0day-ci/linux/commit/449bdbf978936e67e4919be8be0eec3e490a65e2

 git remote add linux-review https://github.com/0day-ci/linux
 git fetch --no-tags linux-review 
Christophe-Leroy/powerpc-Cleanup-of-uaccess-h/20210226-015715

 git checkout 449bdbf978936e67e4919be8be0eec3e490a65e2
 # save the attached .config to linux build tree
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 
make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=powerpc


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



The mentioned patch is not the source of the problem, it only allows 
to spot it.


Christophe




"sparse warnings: (new ones prefixed by >>)"
drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: sparse: incorrect 
type in initializer (different address spaces) @@ expected char 
[noderef] __user *_pu_addr @@ got char *buf @@
    drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: expected char 
[noderef] __user *_pu_addr

    drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: got char *buf
drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: sparse: incorrect 
type in initializer (different address spaces) @@ expected char 
const [noderef] __user *_gu_addr @@ got char const *buf @@
    drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: expected char 
const [noderef] __user *_gu_addr
    drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: got char const 
*buf

--
    drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: cast 
removes address space '__user' of expression
    drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: cast 
removes address space '__user' of expression
drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: 
incorrect type in initializer (different address spaces) @@ 
expected unsigned int [noderef] __user *_pu_addr @@ got 
unsigned int [usertype] * @@
    drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: expected 
unsigned int [noderef] __user *_pu_addr
    drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: got 
unsigned int [usertype] *
    drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: cast 
removes address space '__user' of expression


vim +342 drivers/w1/slaves/w1_ds28e04.c

fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  338
fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  339  static ssize_t 
crccheck_show(struct device *dev, struct device_attribute *attr,
fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21 340   
char *buf)

fbf7f7b4e2ae40 Markus Franke  2012-05-26  341  {
fbf7f7b4e2ae40 Markus Franke  2012-05-26 @342  if 
(put_user(w1_enable_crccheck + 0x30, buf))

fbf7f7b4e2ae40 Markus Franke  2012-05-26  343 return -EFAULT;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  344
fbf7f7b4e2ae40 Markus Franke  2012-05-26  345  return 
sizeof(w1_enable_crccheck);

fbf7f7b4e2ae40 Markus Franke  2012-05-26  346  }
fbf7f7b4e2ae40 Markus Franke  2012-05-26  347
fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  348  static ssize_t 
crccheck_store(struct device *dev, struct device_attribute *attr,
fbf7f7b4e2ae40 Markus Franke  2012-05-26 349    
const char *buf, size_t count)

fbf7f7b4e2ae40 Markus Franke  2012-05-26  350  {
fbf7f7b4e2ae40 Markus Franke  2012-05-26  351  char val;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  352
fbf7f7b4e2ae40 Markus Franke  2012-05-26  353  if (count != 1 
|| !buf)

fbf7f7b4e2ae40 Markus Franke  2012-05-26  354 return -EINVAL;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  355
fbf7f7b4e2ae40 Markus Franke  2012-05-26 @356  if 
(get_user(val, buf))

fbf7f7b4e2ae40 Markus Franke  2012-05-26  357 return -EFAULT;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  358
fbf7f7b4e2ae40 Markus Franke  

Re: [PATCH v1 12/15] powerpc/uaccess: Refactor get/put_user() and __get/put_user()

2021-03-08 Thread Christophe Leroy

+Evgeniy for W1 Dallas
+Alex & Christian for RADEON

Le 07/03/2021 à 11:23, kernel test robot a écrit :

Hi Christophe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on v5.12-rc2 next-20210305]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-Cleanup-of-uaccess-h/20210226-015715
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-randconfig-s031-20210307 (attached as .config)
compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce:
 wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
 chmod +x ~/bin/make.cross
 # apt-get install sparse
 # sparse version: v0.6.3-245-gacc5c298-dirty
 # 
https://github.com/0day-ci/linux/commit/449bdbf978936e67e4919be8be0eec3e490a65e2
 git remote add linux-review https://github.com/0day-ci/linux
 git fetch --no-tags linux-review 
Christophe-Leroy/powerpc-Cleanup-of-uaccess-h/20210226-015715
 git checkout 449bdbf978936e67e4919be8be0eec3e490a65e2
 # save the attached .config to linux build tree
 COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 
CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=powerpc

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



The mentioned patch is not the source of the problem, it only allows to spot it.

Christophe




"sparse warnings: (new ones prefixed by >>)"

drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: sparse: incorrect type in 
initializer (different address spaces) @@ expected char [noderef] __user 
*_pu_addr @@ got char *buf @@

drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: expected char [noderef] 
__user *_pu_addr
drivers/w1/slaves/w1_ds28e04.c:342:13: sparse: got char *buf

drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: sparse: incorrect type in 
initializer (different address spaces) @@ expected char const [noderef] 
__user *_gu_addr @@ got char const *buf @@

drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: expected char const 
[noderef] __user *_gu_addr
drivers/w1/slaves/w1_ds28e04.c:356:13: sparse: got char const *buf
--
drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: cast removes 
address space '__user' of expression
drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: cast removes 
address space '__user' of expression

drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: incorrect type in 
initializer (different address spaces) @@ expected unsigned int [noderef] 
__user *_pu_addr @@ got unsigned int [usertype] * @@

drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: expected unsigned 
int [noderef] __user *_pu_addr
drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: got unsigned int 
[usertype] *
drivers/gpu/drm/radeon/radeon_ttm.c:933:21: sparse: sparse: cast removes 
address space '__user' of expression

vim +342 drivers/w1/slaves/w1_ds28e04.c

fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  338
fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  339  static ssize_t 
crccheck_show(struct device *dev, struct device_attribute *attr,
fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  340
char *buf)
fbf7f7b4e2ae40 Markus Franke  2012-05-26  341  {
fbf7f7b4e2ae40 Markus Franke  2012-05-26 @342   if 
(put_user(w1_enable_crccheck + 0x30, buf))
fbf7f7b4e2ae40 Markus Franke  2012-05-26  343   return -EFAULT;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  344
fbf7f7b4e2ae40 Markus Franke  2012-05-26  345   return 
sizeof(w1_enable_crccheck);
fbf7f7b4e2ae40 Markus Franke  2012-05-26  346  }
fbf7f7b4e2ae40 Markus Franke  2012-05-26  347
fa33a65a9cf7e2 Greg Kroah-Hartman 2013-08-21  348  static ssize_t 
crccheck_store(struct device *dev, struct device_attribute *attr,
fbf7f7b4e2ae40 Markus Franke  2012-05-26  349 
const char *buf, size_t count)
fbf7f7b4e2ae40 Markus Franke  2012-05-26  350  {
fbf7f7b4e2ae40 Markus Franke  2012-05-26  351   char val;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  352
fbf7f7b4e2ae40 Markus Franke  2012-05-26  353   if (count != 1 || !buf)
fbf7f7b4e2ae40 Markus Franke  2012-05-26  354   return -EINVAL;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  355
fbf7f7b4e2ae40 Markus Franke  2012-05-26 @356   if (get_user(val, buf))
fbf7f7b4e2ae40 Markus Franke  2012-05-26  357   return -EFAULT;
fbf7f7b4e2ae40 Markus Franke  2012-05-26  358
fbf7f7b4e2ae40 Markus Franke  2012-05-26  359   /* convert to decimal */
fbf7f7b4e2ae40 Markus Franke  2012-05

Re: [PATCH] powerpc: Fix instruction encoding for lis in ppc_function_entry()

2021-03-08 Thread Naveen N. Rao
On 2021/03/05 12:37PM, Christophe Leroy wrote:
> 
> 
> Le 04/03/2021 à 03:04, Naveen N. Rao a écrit :
> > 'lis r2,N' is 'addis r2,0,N' and the instruction encoding in the macro
> > LIS_R2 is incorrect (it currently maps to 'addis 0,r2,N'). Fix the same.
> > 
> > Fixes: c71b7eff426fa7 ("powerpc: Add ABIv2 support to ppc_function_entry")
> > Reported-by: Jiri Olsa 
> > Signed-off-by: Naveen N. Rao 
> > ---
> >   arch/powerpc/include/asm/code-patching.h | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/powerpc/include/asm/code-patching.h 
> > b/arch/powerpc/include/asm/code-patching.h
> > index eacc9102c2515c..d5b3c3bb95b400 100644
> > --- a/arch/powerpc/include/asm/code-patching.h
> > +++ b/arch/powerpc/include/asm/code-patching.h
> > @@ -73,7 +73,7 @@ void __patch_exception(int exc, unsigned long addr);
> >   #endif
> >   #define OP_RT_RA_MASK 0xUL
> > -#define LIS_R2 0x3c02UL
> > +#define LIS_R2 0x3c40UL
> >   #define ADDIS_R2_R12  0x3c4cUL
> >   #define ADDI_R2_R20x3842UL
> 
> That probably goes beyond the scope of this patch, but it would be more
> readable and less error prone to use macros defined in ppc-opcode.h just
> like kernel/module_64.c does for instance:
> 
> #define LIS_R2(PPC_INST_ADDIS | __PPC_RT(R2))
> #define ADDIS_R2_R12  (PPC_INST_ADDIS | __PPC_RT(R2) | __PPC_RA(R12))
> #define ADDI_R2_R2(PPC_INST_ADDI | __PPC_RT(R2) | __PPC_RA(R2))

Good point. While that would have made it harder to spot the error, it 
probably would have avoided the error in the first place.

Your change looks good to me.

Thanks,
Naveen



[RFC PATCH 7/7] powerpc/64e/interrupt: Use new interrupt context tracking scheme

2021-03-08 Thread Nicholas Piggin
With the new interrupt exit code, context tracking can be managed
more precisely, so remove the last of the 64e workarounds and switch
to the new context tracking code already used by 64s.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/interrupt.h | 28 
 arch/powerpc/kernel/interrupt.c  | 12 
 2 files changed, 40 deletions(-)

diff --git a/arch/powerpc/include/asm/interrupt.h 
b/arch/powerpc/include/asm/interrupt.h
index a57db901c16d..79c4f5596704 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -10,9 +10,6 @@
 #include 
 
 struct interrupt_state {
-#ifdef CONFIG_PPC_BOOK3E_64
-   enum ctx_state ctx_state;
-#endif
 };
 
 static inline void booke_restore_dbcr0(void)
@@ -33,9 +30,7 @@ static inline void interrupt_enter_prepare(struct pt_regs 
*regs, struct interrup
if (irq_soft_mask_set_return(IRQS_ALL_DISABLED) == IRQS_ENABLED)
trace_hardirqs_off();
local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
-#endif
 
-#ifdef CONFIG_PPC_BOOK3S_64
if (user_mode(regs)) {
CT_WARN_ON(ct_state() != CONTEXT_USER);
user_exit_irqoff();
@@ -51,12 +46,6 @@ static inline void interrupt_enter_prepare(struct pt_regs 
*regs, struct interrup
CT_WARN_ON(ct_state() != CONTEXT_KERNEL);
}
 #endif
-
-#ifdef CONFIG_PPC_BOOK3E_64
-   state->ctx_state = exception_enter();
-   if (user_mode(regs))
-   account_cpu_user_entry();
-#endif
 }
 
 /*
@@ -75,23 +64,6 @@ static inline void interrupt_enter_prepare(struct pt_regs 
*regs, struct interrup
  */
 static inline void interrupt_exit_prepare(struct pt_regs *regs, struct 
interrupt_state *state)
 {
-#ifdef CONFIG_PPC_BOOK3E_64
-   exception_exit(state->ctx_state);
-#endif
-
-   /*
-* Book3S exits to user via interrupt_exit_user_prepare(), which does
-* context tracking, which is a cleaner way to handle PREEMPT=y
-* and avoid context entry/exit in e.g., preempt_schedule_irq()),
-* which is likely to be where the core code wants to end up.
-*
-* The above comment explains why we can't do the
-*
-* if (user_mode(regs))
-* user_exit_irqoff();
-*
-* sequence here.
-*/
 }
 
 static inline void interrupt_async_enter_prepare(struct pt_regs *regs, struct 
interrupt_state *state)
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 44b62a97f021..02ba5afc6fb0 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -228,10 +228,6 @@ static notrace void booke_load_dbcr0(void)
 #endif
 }
 
-/* temporary hack for context tracking, removed in later patch */
-#include 
-asmlinkage __visible void __sched schedule_user(void);
-
 /*
  * This should be called after a syscall returns, with r3 the return value
  * from the syscall. If this function returns non-zero, the system call
@@ -291,11 +287,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long 
r3,
while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {
local_irq_enable();
if (ti_flags & _TIF_NEED_RESCHED) {
-#ifdef CONFIG_PPC_BOOK3E_64
-   schedule_user();
-#else
schedule();
-#endif
} else {
/*
 * SIGPENDING must restore signal handler function
@@ -391,11 +383,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct 
pt_regs *regs, unsigned
while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {
local_irq_enable(); /* returning to user: may enable */
if (ti_flags & _TIF_NEED_RESCHED) {
-#ifdef CONFIG_PPC_BOOK3E_64
-   schedule_user();
-#else
schedule();
-#endif
} else {
if (ti_flags & _TIF_SIGPENDING)
ret |= _TIF_RESTOREALL;
-- 
2.23.0



[RFC PATCH 6/7] powerpc/64e/interrupt: handle bad_page_fault in C

2021-03-08 Thread Nicholas Piggin
With non-volatile registers saved on interrupt, bad_page_fault
can now be called by do_page_fault.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/exceptions-64e.S | 6 --
 arch/powerpc/mm/fault.c  | 4 ++--
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index eef8b5bc3cc8..d9151f3ae35d 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -962,12 +962,6 @@ storage_fault_common:
ld  r14,PACA_EXGEN+EX_R14(r13)
ld  r15,PACA_EXGEN+EX_R15(r13)
bl  do_page_fault
-   cmpdi   r3,0
-   bne-1f
-   b   interrupt_return
-   mr  r4,r3
-   addir3,r1,STACK_FRAME_OVERHEAD
-   bl  __bad_page_fault
b   interrupt_return
 
 /*
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index bb368257b55c..f271715a1c0a 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -552,11 +552,11 @@ static long __do_page_fault(struct pt_regs *regs)
if (likely(entry)) {
instruction_pointer_set(regs, extable_fixup(entry));
return 0;
-   } else if (IS_ENABLED(CONFIG_PPC_BOOK3S_64)) {
+   } else if (IS_ENABLED(CONFIG_PPC64)) {
__bad_page_fault(regs, err);
return 0;
} else {
-   /* 32 and 64e handle the bad page fault in asm */
+   /* 32-bit handles the bad page fault in asm */
return err;
}
 }
-- 
2.23.0



[RFC PATCH 5/7] KVM: PPC: Remove RECONCILE_IRQ_STATE from guest exit

2021-03-08 Thread Nicholas Piggin
Change KVM to keep the irq soft-mask state hard disabled when entering
the guest, to avoid "reconciling" the state when exiting the guest.

IRQ tracing still has to be updated so host irqs are disabled when the
guest is exited, but this is now done in C, similarly to Book3S HV.

[ I don't have BookE or PR KVM setup to actually test this, it's not
  so important as the 64e conversion to new interrupt code, but it
  would be nice if we can get rid of this reconciling from asm entirely ]
---
 arch/powerpc/include/asm/irqflags.h   | 58 ---
 arch/powerpc/include/asm/kvm_ppc.h| 22 --
 arch/powerpc/kvm/book3s_pr.c  |  8 +++-
 arch/powerpc/kvm/booke.c  |  9 -
 arch/powerpc/kvm/bookehv_interrupts.S |  9 -
 5 files changed, 13 insertions(+), 93 deletions(-)

diff --git a/arch/powerpc/include/asm/irqflags.h 
b/arch/powerpc/include/asm/irqflags.h
index 1a6c1ce17735..47d46712928a 100644
--- a/arch/powerpc/include/asm/irqflags.h
+++ b/arch/powerpc/include/asm/irqflags.h
@@ -11,64 +11,6 @@
  */
 #include 
 
-#else
-#ifdef CONFIG_TRACE_IRQFLAGS
-#ifdef CONFIG_IRQSOFF_TRACER
-/*
- * Since the ftrace irqsoff latency trace checks CALLER_ADDR1,
- * which is the stack frame here, we need to force a stack frame
- * in case we came from user space.
- */
-#define TRACE_WITH_FRAME_BUFFER(func)  \
-   mflrr0; \
-   stdur1, -STACK_FRAME_OVERHEAD(r1);  \
-   std r0, 16(r1); \
-   stdur1, -STACK_FRAME_OVERHEAD(r1);  \
-   bl func;\
-   ld  r1, 0(r1);  \
-   ld  r1, 0(r1);
-#else
-#define TRACE_WITH_FRAME_BUFFER(func)  \
-   bl func;
-#endif
-
-/*
- * These are calls to C code, so the caller must be prepared for volatiles to
- * be clobbered.
- */
-#define TRACE_ENABLE_INTS  TRACE_WITH_FRAME_BUFFER(trace_hardirqs_on)
-#define TRACE_DISABLE_INTS TRACE_WITH_FRAME_BUFFER(trace_hardirqs_off)
-
-/*
- * This is used by assembly code to soft-disable interrupts first and
- * reconcile irq state.
- *
- * NB: This may call C code, so the caller must be prepared for volatiles to
- * be clobbered.
- */
-#define RECONCILE_IRQ_STATE(__rA, __rB)\
-   lbz __rA,PACAIRQSOFTMASK(r13);  \
-   lbz __rB,PACAIRQHAPPENED(r13);  \
-   andi.   __rA,__rA,IRQS_DISABLED;\
-   li  __rA,IRQS_DISABLED; \
-   ori __rB,__rB,PACA_IRQ_HARD_DIS;\
-   stb __rB,PACAIRQHAPPENED(r13);  \
-   bne 44f;\
-   stb __rA,PACAIRQSOFTMASK(r13);  \
-   TRACE_DISABLE_INTS; \
-44:
-
-#else
-#define TRACE_ENABLE_INTS
-#define TRACE_DISABLE_INTS
-
-#define RECONCILE_IRQ_STATE(__rA, __rB)\
-   lbz __rA,PACAIRQHAPPENED(r13);  \
-   li  __rB,IRQS_DISABLED; \
-   ori __rA,__rA,PACA_IRQ_HARD_DIS;\
-   stb __rB,PACAIRQSOFTMASK(r13);  \
-   stb __rA,PACAIRQHAPPENED(r13)
-#endif
 #endif
 
 #endif
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 8aacd76bb702..749c5cadc883 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -996,28 +996,6 @@ static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, 
int nr, u32 val)
   vcpu->arch.shared->sr[nr] = cpu_to_le32(val);
 }
 
-/*
- * Please call after prepare_to_enter. This function puts the lazy ee and irq
- * disabled tracking state back to normal mode, without actually enabling
- * interrupts.
- */
-static inline void kvmppc_fix_ee_before_entry(void)
-{
-   trace_hardirqs_on();
-
-#ifdef CONFIG_PPC64
-   /*
-* To avoid races, the caller must have gone directly from having
-* interrupts fully-enabled to hard-disabled.
-*/
-   WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);
-
-   /* Only need to enable IRQs by hard enabling them after this */
-   local_paca->irq_happened = 0;
-   irq_soft_mask_set(IRQS_ENABLED);
-#endif
-}
-
 static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int 
rb)
 {
ulong ea;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 913944dc3620..40f1f4e207bc 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1157,6 +1157,8 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned 
int exit_nr)
int r = RESUME_HOST;
int s;
 
+   trace_hardirqs_on();
+
vcpu->stat.sum_exits++;
 
run->exit_reason = KVM_EXIT_UNKNOWN;
@@ -1460,7 +1462,7 @@ int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned 
int exit_nr)
r = s;
else {
/* interrupts now hard-disabled */
-   kvmppc_fix_ee_before_entry();
+  

[RFC PATCH 4/7] powerpc/64e/interrupt: reconcile irq soft-mask state in C

2021-03-08 Thread Nicholas Piggin
Use existing 64s interrupt entry wrapper code to reconcile irqs in C.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/interrupt.h |  7 ++---
 arch/powerpc/kernel/entry_64.S   | 18 ++--
 arch/powerpc/kernel/exceptions-64e.S | 42 +---
 3 files changed, 12 insertions(+), 55 deletions(-)

diff --git a/arch/powerpc/include/asm/interrupt.h 
b/arch/powerpc/include/asm/interrupt.h
index aedfba29e43a..a57db901c16d 100644
--- a/arch/powerpc/include/asm/interrupt.h
+++ b/arch/powerpc/include/asm/interrupt.h
@@ -29,14 +29,13 @@ static inline void booke_restore_dbcr0(void)
 
 static inline void interrupt_enter_prepare(struct pt_regs *regs, struct 
interrupt_state *state)
 {
-   /*
-* Book3E reconciles irq soft mask in asm
-*/
-#ifdef CONFIG_PPC_BOOK3S_64
+#ifdef CONFIG_PPC64
if (irq_soft_mask_set_return(IRQS_ALL_DISABLED) == IRQS_ENABLED)
trace_hardirqs_off();
local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
+#endif
 
+#ifdef CONFIG_PPC_BOOK3S_64
if (user_mode(regs)) {
CT_WARN_ON(ct_state() != CONTEXT_USER);
user_exit_irqoff();
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 555b3d0a3f38..03727308d8cc 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -117,13 +117,12 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
 
/*
-* RECONCILE_IRQ_STATE without calling trace_hardirqs_off(), which
-* would clobber syscall parameters. Also we always enter with IRQs
-* enabled and nothing pending. system_call_exception() will call
-* trace_hardirqs_off().
-*
-* scv enters with MSR[EE]=1, so don't set PACA_IRQ_HARD_DIS. The
-* entry vector already sets PACAIRQSOFTMASK to IRQS_ALL_DISABLED.
+* scv enters with MSR[EE]=1 and is immediately considered soft-masked.
+* The entry vector already sets PACAIRQSOFTMASK to IRQS_ALL_DISABLED,
+* and interrupts may be masked and pending already.
+* system_call_exception() will call trace_hardirqs_off() which means
+* interrupts could already have been blocked before trace_hardirqs_off,
+* but this is the best we can do.
 */
 
/* Calling convention has r9 = orig r0, r10 = regs */
@@ -288,9 +287,8 @@ END_BTB_FLUSH_SECTION
std r11,-16(r10)/* "regshere" marker */
 
/*
-* RECONCILE_IRQ_STATE without calling trace_hardirqs_off(), which
-* would clobber syscall parameters. Also we always enter with IRQs
-* enabled and nothing pending. system_call_exception() will call
+* We always enter kernel from userspace with irq soft-mask enabled and
+* nothing pending. system_call_exception() will call
 * trace_hardirqs_off().
 */
li  r11,IRQS_ALL_DISABLED
diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index 1bb4e9b37748..eef8b5bc3cc8 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -63,9 +63,6 @@
ld  reg, (SPECIAL_EXC_##name * 8 + SPECIAL_EXC_FRAME_OFFS)(r1)
 
 special_reg_save:
-   lbz r9,PACAIRQHAPPENED(r13)
-   RECONCILE_IRQ_STATE(r3,r4)
-
/*
 * We only need (or have stack space) to save this stuff if
 * we interrupted the kernel.
@@ -437,28 +434,6 @@ exc_##n##_common:  
\
 #define EXCEPTION_COMMON_DBG(n) \
EXCEPTION_COMMON_LVL(n, SPRN_SPRG_DBG_SCRATCH, PACA_EXDBG)
 
-/*
- * This is meant for exceptions that don't immediately hard-enable.  We
- * set a bit in paca->irq_happened to ensure that a subsequent call to
- * arch_local_irq_restore() will properly hard-enable and avoid the
- * fast-path, and then reconcile irq state.
- */
-#define INTS_DISABLE   RECONCILE_IRQ_STATE(r3,r4)
-
-/*
- * This is called by exceptions that don't use INTS_DISABLE (that did not
- * touch irq indicators in the PACA).  This will restore MSR:EE to it's
- * previous value
- *
- * XXX In the long run, we may want to open-code it in order to separate the
- * load from the wrtee, thus limiting the latency caused by the dependency
- * but at this point, I'll favor code clarity until we have a near to final
- * implementation
- */
-#define INTS_RESTORE_HARD  \
-   ld  r11,_MSR(r1);   \
-   wrtee   r11;
-
 /* XXX FIXME: Restore r14/r15 when necessary */
 #define BAD_STACK_TRAMPOLINE(n)
\
 exc_##n##_bad_stack:   \
@@ -507,7 +482,6 @@ exc_##n##_bad_stack:
\
START_EXCEPTION(label); \
  

[RFC PATCH 3/7] powerpc/64e/interrupt: use new interrupt return

2021-03-08 Thread Nicholas Piggin
Update the new C and asm interrupt return code to account for some 64e
quirks, switch over to use it, and delete the old cruft that was moved
to 64e-only after 64s was converted.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/asm-prototypes.h |   2 -
 arch/powerpc/kernel/entry_64.S|   9 +-
 arch/powerpc/kernel/exceptions-64e.S  | 321 ++
 arch/powerpc/kernel/interrupt.c   |  26 +-
 arch/powerpc/kernel/irq.c |  76 -
 5 files changed, 51 insertions(+), 383 deletions(-)

diff --git a/arch/powerpc/include/asm/asm-prototypes.h 
b/arch/powerpc/include/asm/asm-prototypes.h
index 939f3c94c8f3..1c7b75834e04 100644
--- a/arch/powerpc/include/asm/asm-prototypes.h
+++ b/arch/powerpc/include/asm/asm-prototypes.h
@@ -77,8 +77,6 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct 
pt_regs *regs, unsign
 long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
  u32 len_high, u32 len_low);
 long sys_switch_endian(void);
-notrace unsigned int __check_irq_replay(void);
-void notrace restore_interrupts(void);
 
 /* prom_init (OpenFirmware) */
 unsigned long __init prom_init(unsigned long r3, unsigned long r4,
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 853534b2ae2e..555b3d0a3f38 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -632,7 +632,6 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
addir1,r1,SWITCH_FRAME_SIZE
blr
 
-#ifdef CONFIG_PPC_BOOK3S
/*
 * If MSR EE/RI was never enabled, IRQs not reconciled, NVGPRs not
 * touched, no exit work created, then this can be used.
@@ -644,6 +643,7 @@ _ASM_NOKPROBE_SYMBOL(fast_interrupt_return)
kuap_check_amr r3, r4
ld  r5,_MSR(r1)
andi.   r0,r5,MSR_PR
+#ifdef CONFIG_PPC_BOOK3S
bne .Lfast_user_interrupt_return_amr
kuap_kernel_restore r3, r4
andi.   r0,r5,MSR_RI
@@ -652,6 +652,10 @@ _ASM_NOKPROBE_SYMBOL(fast_interrupt_return)
addir3,r1,STACK_FRAME_OVERHEAD
bl  unrecoverable_exception
b   . /* should not get here */
+#else
+   bne .Lfast_user_interrupt_return
+   b   .Lfast_kernel_interrupt_return
+#endif
 
.balign IFETCH_ALIGN_BYTES
.globl interrupt_return
@@ -665,8 +669,10 @@ _ASM_NOKPROBE_SYMBOL(interrupt_return)
cmpdi   r3,0
bne-.Lrestore_nvgprs
 
+#ifdef CONFIG_PPC_BOOK3S
 .Lfast_user_interrupt_return_amr:
kuap_user_restore r3, r4
+#endif
 .Lfast_user_interrupt_return:
ld  r11,_NIP(r1)
ld  r12,_MSR(r1)
@@ -775,7 +781,6 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
 
RFI_TO_KERNEL
b   .   /* prevent speculative execution */
-#endif /* CONFIG_PPC_BOOK3S */
 
 #ifdef CONFIG_PPC_RTAS
 /*
diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index da78eb6ab92f..1bb4e9b37748 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -139,7 +139,8 @@ ret_from_level_except:
ld  r3,_MSR(r1)
andi.   r3,r3,MSR_PR
beq 1f
-   b   ret_from_except
+   REST_NVGPRS(r1)
+   b   interrupt_return
 1:
 
LOAD_REG_ADDR(r11,extlb_level_exc)
@@ -208,7 +209,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
/*
 * Restore PACAIRQHAPPENED rather than setting it based on
 * the return MSR[EE], since we could have interrupted
-* __check_irq_replay() or other inconsistent transitory
+* interrupt replay or other inconsistent transitory
 * states that must remain that way.
 */
SPECIAL_EXC_LOAD(r10,IRQHAPPENED)
@@ -511,7 +512,7 @@ exc_##n##_bad_stack:
\
CHECK_NAPPING();\
addir3,r1,STACK_FRAME_OVERHEAD; \
bl  hdlr;   \
-   b   ret_from_except_lite;
+   b   interrupt_return
 
 /* This value is used to mark exception frames on the stack. */
.section".toc","aw"
@@ -623,7 +624,8 @@ __end_interrupts:
addir3,r1,STACK_FRAME_OVERHEAD
ld  r14,PACA_EXGEN+EX_R14(r13)
bl  program_check_exception
-   b   ret_from_except
+   REST_NVGPRS(r1)
+   b   interrupt_return
 
 /* Floating Point Unavailable Interrupt */
START_EXCEPTION(fp_unavailable);
@@ -635,11 +637,11 @@ __end_interrupts:
andi.   r0,r12,MSR_PR;
beq-1f
bl  load_up_fpu
-   b   fast_exception_return
+   b   fast_interrupt_return
 1: INTS_DISABLE
addir3,r1,STACK_FRAME_OVERHEAD
bl  kernel_fp_unavailable_exception
-   b   ret_from_except
+   b   inter

[RFC PATCH 2/7] powerpc/64e/interrupt: always save nvgprs on interrupt

2021-03-08 Thread Nicholas Piggin
In order to use the C interrupt return, nvgprs must always be saved.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/include/asm/ptrace.h|  9 +
 arch/powerpc/kernel/entry_64.S   | 13 -
 arch/powerpc/kernel/exceptions-64e.S | 27 +++
 3 files changed, 4 insertions(+), 45 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 1499e928ea6a..c8afed82d484 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -186,18 +186,11 @@ static inline void regs_set_return_value(struct pt_regs 
*regs, unsigned long rc)
((struct pt_regs *)((unsigned long)task_stack_page(current) + 
THREAD_SIZE) - 1)
 
 #ifdef __powerpc64__
-#ifdef CONFIG_PPC_BOOK3S
 #define TRAP_FLAGS_MASK0x10
 #define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
 #define FULL_REGS(regs)true
 #define SET_FULL_REGS(regs)do { } while (0)
-#else
-#define TRAP_FLAGS_MASK0x11
-#define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
-#define FULL_REGS(regs)(((regs)->trap & 1) == 0)
-#define SET_FULL_REGS(regs)((regs)->trap &= ~1)
-#endif
-#define CHECK_FULL_REGS(regs)  BUG_ON(!FULL_REGS(regs))
+#define CHECK_FULL_REGS(regs)  do { } while (0)
 #define NV_REG_POISON  0xdeadbeefdeadbeefUL
 #else
 /*
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 6c4d9e276c4d..853534b2ae2e 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -417,19 +417,6 @@ _GLOBAL(ret_from_kernel_thread)
li  r3,0
b   .Lsyscall_exit
 
-#ifdef CONFIG_PPC_BOOK3E
-/* Save non-volatile GPRs, if not already saved. */
-_GLOBAL(save_nvgprs)
-   ld  r11,_TRAP(r1)
-   andi.   r0,r11,1
-   beqlr-
-   SAVE_NVGPRS(r1)
-   clrrdi  r0,r11,1
-   std r0,_TRAP(r1)
-   blr
-_ASM_NOKPROBE_SYMBOL(save_nvgprs);
-#endif
-
 #ifdef CONFIG_PPC_BOOK3S_64
 
 #define FLUSH_COUNT_CACHE  \
diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index e8eb9992a270..da78eb6ab92f 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -417,14 +417,15 @@ exc_##n##_common: 
\
std r6,_LINK(r1);   \
std r7,_CTR(r1);\
std r8,_XER(r1);\
-   li  r3,(n)+1;   /* indicate partial regs in trap */ \
+   li  r3,(n); /* indicate partial regs in trap */ \
std r9,0(r1);   /* store stack frame back link */   \
std r10,_CCR(r1);   /* store orig CR in stackframe */   \
std r9,GPR1(r1);/* store stack frame back link */   \
std r11,SOFTE(r1);  /* and save it to stackframe */ \
std r12,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */   \
std r3,_TRAP(r1);   /* set trap number  */  \
-   std r0,RESULT(r1);  /* clear regs->result */
+   std r0,RESULT(r1);  /* clear regs->result */\
+   SAVE_NVGPRS(r1);
 
 #define EXCEPTION_COMMON(n) \
EXCEPTION_COMMON_LVL(n, SPRN_SPRG_GEN_SCRATCH, PACA_EXGEN)
@@ -561,7 +562,6 @@ __end_interrupts:
CRIT_EXCEPTION_PROLOG(0x100, BOOKE_INTERRUPT_CRITICAL,
  PROLOG_ADDITION_NONE)
EXCEPTION_COMMON_CRIT(0x100)
-   bl  save_nvgprs
bl  special_reg_save
CHECK_NAPPING();
addir3,r1,STACK_FRAME_OVERHEAD
@@ -573,7 +573,6 @@ __end_interrupts:
MC_EXCEPTION_PROLOG(0x000, BOOKE_INTERRUPT_MACHINE_CHECK,
PROLOG_ADDITION_NONE)
EXCEPTION_COMMON_MC(0x000)
-   bl  save_nvgprs
bl  special_reg_save
CHECK_NAPPING();
addir3,r1,STACK_FRAME_OVERHEAD
@@ -623,7 +622,6 @@ __end_interrupts:
std r14,_DSISR(r1)
addir3,r1,STACK_FRAME_OVERHEAD
ld  r14,PACA_EXGEN+EX_R14(r13)
-   bl  save_nvgprs
bl  program_check_exception
b   ret_from_except
 
@@ -639,7 +637,6 @@ __end_interrupts:
bl  load_up_fpu
b   fast_exception_return
 1: INTS_DISABLE
-   bl  save_nvgprs
addir3,r1,STACK_FRAME_OVERHEAD
bl  kernel_fp_unavailable_exception
b   ret_from_except
@@ -661,7 +658,6 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 #endif
INTS_DISABLE
-   bl  save_nvgprs
addir3,r1,STACK_FRAME_OVERHEAD
bl  altivec_unavailable_exception
b   ret_from_except
@@ -673,7 +669,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 

[RFC PATCH 1/7] powerpc/syscall: switch user_exit_irqoff and trace_hardirqs_off order

2021-03-08 Thread Nicholas Piggin
user_exit_irqoff() -> __context_tracking_exit -> vtime_user_exit
warns in __seqprop_assert due to lockdep thinking preemption is enabled
because trace_hardirqs_off() has not yet been called.

Switch the order of these two calls, which matches their ordering in
interrupt_enter_prepare.

Fixes: 5f0b6ac3905f ("powerpc/64/syscall: Reconcile interrupts")
Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/kernel/interrupt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 2ef3c4051bb9..38ee41f8844a 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -34,11 +34,11 @@ notrace long system_call_exception(long r3, long r4, long 
r5,
if (IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG))
BUG_ON(irq_soft_mask_return() != IRQS_ALL_DISABLED);
 
+   trace_hardirqs_off(); /* finish reconciling */
+
CT_WARN_ON(ct_state() == CONTEXT_KERNEL);
user_exit_irqoff();
 
-   trace_hardirqs_off(); /* finish reconciling */
-
if (!IS_ENABLED(CONFIG_BOOKE) && !IS_ENABLED(CONFIG_40x))
BUG_ON(!(regs->msr & MSR_RI));
BUG_ON(!(regs->msr & MSR_PR));
-- 
2.23.0



[PATCH] powerpc: fix inverted SET_FULL_REGS bitop

2021-03-08 Thread Nicholas Piggin
This bit operation was inverted and set the low bit rather than cleared
it, breaking the ability to ptrace non-volatile GPRs after exec. Fix.

Fixes: feb9df3462e68 ("powerpc/64s: Always has full regs, so remove remnant 
checks")
Signed-off-by: Nicholas Piggin 
---
Well this is embarrassing. Condition flags should be represented by the
bit set, rather than bit clear. That would have made the mistake obvious
even at a glance.

In this case, this stuff is going away soon so I won't bother to change
it around.

Thanks,
Nick

 arch/powerpc/include/asm/ptrace.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 975ba260006a..1499e928ea6a 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -195,7 +195,7 @@ static inline void regs_set_return_value(struct pt_regs 
*regs, unsigned long rc)
 #define TRAP_FLAGS_MASK0x11
 #define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
 #define FULL_REGS(regs)(((regs)->trap & 1) == 0)
-#define SET_FULL_REGS(regs)((regs)->trap |= 1)
+#define SET_FULL_REGS(regs)((regs)->trap &= ~1)
 #endif
 #define CHECK_FULL_REGS(regs)  BUG_ON(!FULL_REGS(regs))
 #define NV_REG_POISON  0xdeadbeefdeadbeefUL
@@ -210,7 +210,7 @@ static inline void regs_set_return_value(struct pt_regs 
*regs, unsigned long rc)
 #define TRAP_FLAGS_MASK0x1F
 #define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
 #define FULL_REGS(regs)(((regs)->trap & 1) == 0)
-#define SET_FULL_REGS(regs)((regs)->trap |= 1)
+#define SET_FULL_REGS(regs)((regs)->trap &= ~1)
 #define IS_CRITICAL_EXC(regs)  (((regs)->trap & 2) != 0)
 #define IS_MCHECK_EXC(regs)(((regs)->trap & 4) != 0)
 #define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
-- 
2.23.0



[RFC PATCH 0/7] Move 64e to new interrupt return code

2021-03-08 Thread Nicholas Piggin
Time to finally try removing the remaining old cruft left over
from the big interrupt return rewrite in C.

This series will clash lightly with Christophe's one to switch
ppc32 over. His should go in first because it's a lot bigger
and more mature at this stage. I will rebase this series on top
of his at some point but at the moment it's just based on upstream.

Patch 1 should go in as a fix, patch 5 is not required for this
series I'll drop it from non-rfc series and send it separately (it's
not tested at the moment).

Thanks,
Nick

Nicholas Piggin (7):
  powerpc/syscall: switch user_exit_irqoff and trace_hardirqs_off order
  powerpc/64e/interrupt: always save nvgprs on interrupt
  powerpc/64e/interrupt: use new interrupt return
  powerpc/64e/interrupt: reconcile irq soft-mask state in C
  KVM: PPC: Remove RECONCILE_IRQ_STATE from guest exit
  powerpc/64e/interrupt: handle bad_page_fault in C
  powerpc/64e/interrupt: Use new interrupt context tracking scheme

 arch/powerpc/include/asm/asm-prototypes.h |   2 -
 arch/powerpc/include/asm/interrupt.h  |  31 +-
 arch/powerpc/include/asm/irqflags.h   |  58 
 arch/powerpc/include/asm/kvm_ppc.h|  22 --
 arch/powerpc/include/asm/ptrace.h |   9 +-
 arch/powerpc/kernel/entry_64.S|  40 +--
 arch/powerpc/kernel/exceptions-64e.S  | 394 ++
 arch/powerpc/kernel/interrupt.c   |  18 +-
 arch/powerpc/kernel/irq.c |  76 -
 arch/powerpc/kvm/book3s_pr.c  |   8 +-
 arch/powerpc/kvm/booke.c  |   9 +-
 arch/powerpc/kvm/bookehv_interrupts.S |   9 -
 arch/powerpc/mm/fault.c   |   4 +-
 13 files changed, 69 insertions(+), 611 deletions(-)

-- 
2.23.0



[PATCH] powerpc: fix inverted SET_FULL_REGS bitop

2021-03-08 Thread Nicholas Piggin
This bit operation was inverted and set the low bit rather than cleared
it, breaking the ability to ptrace non-volatile GPRs after exec. Fix.

Fixes: feb9df3462e68 ("powerpc/64s: Always has full regs, so remove remnant 
checks")
Signed-off-by: Nicholas Piggin 
---
Well this is embarrassing. Condition flags should be represented by the
bit set, rather than bit clear. That would have made the mistake obvious
even at a glance.

In this case, this stuff is going away soon so I won't bother to change
it around.

Thanks,
Nick

 arch/powerpc/include/asm/ptrace.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/ptrace.h 
b/arch/powerpc/include/asm/ptrace.h
index 975ba260006a..1499e928ea6a 100644
--- a/arch/powerpc/include/asm/ptrace.h
+++ b/arch/powerpc/include/asm/ptrace.h
@@ -195,7 +195,7 @@ static inline void regs_set_return_value(struct pt_regs 
*regs, unsigned long rc)
 #define TRAP_FLAGS_MASK0x11
 #define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
 #define FULL_REGS(regs)(((regs)->trap & 1) == 0)
-#define SET_FULL_REGS(regs)((regs)->trap |= 1)
+#define SET_FULL_REGS(regs)((regs)->trap &= ~1)
 #endif
 #define CHECK_FULL_REGS(regs)  BUG_ON(!FULL_REGS(regs))
 #define NV_REG_POISON  0xdeadbeefdeadbeefUL
@@ -210,7 +210,7 @@ static inline void regs_set_return_value(struct pt_regs 
*regs, unsigned long rc)
 #define TRAP_FLAGS_MASK0x1F
 #define TRAP(regs) ((regs)->trap & ~TRAP_FLAGS_MASK)
 #define FULL_REGS(regs)(((regs)->trap & 1) == 0)
-#define SET_FULL_REGS(regs)((regs)->trap |= 1)
+#define SET_FULL_REGS(regs)((regs)->trap &= ~1)
 #define IS_CRITICAL_EXC(regs)  (((regs)->trap & 2) != 0)
 #define IS_MCHECK_EXC(regs)(((regs)->trap & 4) != 0)
 #define IS_DEBUG_EXC(regs) (((regs)->trap & 8) != 0)
-- 
2.23.0



Re: [PATCH v5 05/22] powerpc/irq: Add helper to set regs->softe

2021-03-08 Thread Nicholas Piggin
Excerpts from Christophe Leroy's message of March 5, 2021 6:54 pm:
> 
> 
> Le 09/02/2021 à 08:49, Nicholas Piggin a écrit :
>> Excerpts from Christophe Leroy's message of February 9, 2021 4:18 pm:
>>>
>>>
>>> Le 09/02/2021 à 02:11, Nicholas Piggin a écrit :
 Excerpts from Christophe Leroy's message of February 9, 2021 1:10 am:
> regs->softe doesn't exist on PPC32.
>
> Add irq_soft_mask_regs_set_state() helper to set regs->softe.
> This helper will void on PPC32.
>
> Signed-off-by: Christophe Leroy 
> ---

 You could do the same with the kuap_ functions to change some ifdefs
 to IS_ENABLED.

 That's just my preference but if you prefer this way I guess that's
 okay.

>>>
>>>
>>> That's also my preference on the long term.
>>>
>>> Here it is ephemeral, I have a follow up series implementing interrupt 
>>> exit/entry in C and getting
>>> rid of all the assembly kuap hence getting rid of those ifdefs.
>> 
>> I thought it might have been because you hate ifdef more tha most :)
>>   
>>> The issue I see when using IS_ENABLED() is that you have to indent to the 
>>> right, then you interfere
>>> with the file history and 'git blame'
>> 
>> Valid point if it's just going to indent back the other way in your next
>> series.
>> 
>>> Thanks for reviewing my series and looking forward to your feedback on my 
>>> series on the interrupt
>>> entry/exit that I will likely release later today.
>> 
>> Cool, I'm eager to see them.
>> 
> 
> Hi Nick, have you been able to look at it ?
> 
> https://patchwork.ozlabs.org/project/linuxppc-dev/cover/cover.1612864003.git.christophe.le...@csgroup.eu/

Hi Christophe,

I had a look at it, it's mostly ppc32 code which I don't know well but 
it looks like a very nice cleanup and it's good to be sharing the C
code here. All the common code changes look fine to me.

I'll take a closer look if you can rebase and repost the series I need 
to create a tree and base 64e conversion on top of yours as they touch
the same common places.

Thanks,
Nick


Re: [PATCH 6/6] mm: Drop redundant HAVE_ARCH_TRANSPARENT_HUGEPAGE

2021-03-08 Thread Arnd Bergmann
On Mon, Mar 8, 2021 at 7:41 AM Anshuman Khandual
 wrote:
>
> HAVE_ARCH_TRANSPARENT_HUGEPAGE has duplicate definitions on platforms that
> subscribe it. Drop these reduntant definitions and instead just select it
> on applicable platforms.
>
> Cc: Vineet Gupta 
> Cc: Russell King 
> Cc: Arnd Bergmann 
> Cc: linux-snps-...@lists.infradead.org
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-ker...@vger.kernel.org
> Signed-off-by: Anshuman Khandual 

Acked-by: Arnd Bergmann 


Re: [PATCH] KVM: PPC: Book3S HV: Do not expose HFSCR sanitisation to nested hypervisor

2021-03-08 Thread Nicholas Piggin
Excerpts from Fabiano Rosas's message of March 6, 2021 9:10 am:
> As one of the arguments of the H_ENTER_NESTED hypercall, the nested
> hypervisor (L1) prepares a structure containing the values of various
> hypervisor-privileged registers with which it wants the nested guest
> (L2) to run. Since the nested HV runs in supervisor mode it needs the
> host to write to these registers.
> 
> To stop a nested HV manipulating this mechanism and using a nested
> guest as a proxy to access a facility that has been made unavailable
> to it, we have a routine that sanitises the values of the HV registers
> before copying them into the nested guest's vcpu struct.
> 
> However, when coming out of the guest the values are copied as they
> were back into L1 memory, which means that any sanitisation we did
> during guest entry will be exposed to L1 after H_ENTER_NESTED returns.
> 
> This is not a problem by itself, but in the case of the Hypervisor
> Facility Status and Control Register (HFSCR), we use the intersection
> between L2 hfscr bits and L1 hfscr bits. That means that L1 could use
> this to indirectly read the (hv-privileged) value from its vcpu
> struct.
> 
> This patch fixes this by making sure that L1 only gets back the bits
> that are necessary for regular functioning.

The general idea of restricting exposure of HV privileged bits, but
for the case of HFSCR a guest can probe the HFCR anyway by testing which 
facilities are available (and presumably an HV may need some way to know
what features are available for it to advertise to its own guests), so
is this necessary? Perhaps a comment would be sufficient.

Thanks,
Nick

> 
> Signed-off-by: Fabiano Rosas 
> ---
>  arch/powerpc/kvm/book3s_hv_nested.c | 22 +-
>  1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c 
> b/arch/powerpc/kvm/book3s_hv_nested.c
> index 0cd0e7aad588..860004f46e08 100644
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -98,12 +98,20 @@ static void byteswap_hv_regs(struct hv_guest_state *hr)
>  }
>  
>  static void save_hv_return_state(struct kvm_vcpu *vcpu, int trap,
> -  struct hv_guest_state *hr)
> +  struct hv_guest_state *hr, u64 saved_hfscr)
>  {
>   struct kvmppc_vcore *vc = vcpu->arch.vcore;
>  
> + /*
> +  * During sanitise_hv_regs() we used HFSCR bits from L1 state
> +  * to restrict what the L2 state is allowed to be. Since L1 is
> +  * not allowed to read this SPR, do not include these
> +  * modifications in the return state.
> +  */
> + hr->hfscr = ((~HFSCR_INTR_CAUSE & saved_hfscr) |
> +  (HFSCR_INTR_CAUSE & vcpu->arch.hfscr));
> +
>   hr->dpdes = vc->dpdes;
> - hr->hfscr = vcpu->arch.hfscr;
>   hr->purr = vcpu->arch.purr;
>   hr->spurr = vcpu->arch.spurr;
>   hr->ic = vcpu->arch.ic;
> @@ -132,12 +140,14 @@ static void save_hv_return_state(struct kvm_vcpu *vcpu, 
> int trap,
>   }
>  }
>  
> -static void sanitise_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state 
> *hr)
> +static void sanitise_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state 
> *hr,
> +  u64 *saved_hfscr)
>  {
>   /*
>* Don't let L1 enable features for L2 which we've disabled for L1,
>* but preserve the interrupt cause field.
>*/
> + *saved_hfscr = hr->hfscr;
>   hr->hfscr &= (HFSCR_INTR_CAUSE | vcpu->arch.hfscr);
>  
>   /* Don't let data address watchpoint match in hypervisor state */
> @@ -272,6 +282,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
>   u64 hdec_exp;
>   s64 delta_purr, delta_spurr, delta_ic, delta_vtb;
>   u64 mask;
> + u64 hfscr;
>   unsigned long lpcr;
>  
>   if (vcpu->kvm->arch.l1_ptcr == 0)
> @@ -324,7 +335,8 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
>   mask = LPCR_DPFD | LPCR_ILE | LPCR_TC | LPCR_AIL | LPCR_LD |
>   LPCR_LPES | LPCR_MER;
>   lpcr = (vc->lpcr & ~mask) | (l2_hv.lpcr & mask);
> - sanitise_hv_regs(vcpu, &l2_hv);
> +
> + sanitise_hv_regs(vcpu, &l2_hv, &hfscr);
>   restore_hv_regs(vcpu, &l2_hv);
>  
>   vcpu->arch.ret = RESUME_GUEST;
> @@ -345,7 +357,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
>   delta_spurr = vcpu->arch.spurr - l2_hv.spurr;
>   delta_ic = vcpu->arch.ic - l2_hv.ic;
>   delta_vtb = vc->vtb - l2_hv.vtb;
> - save_hv_return_state(vcpu, vcpu->arch.trap, &l2_hv);
> + save_hv_return_state(vcpu, vcpu->arch.trap, &l2_hv, hfscr);
>  
>   /* restore L1 state */
>   vcpu->arch.nested = NULL;
> -- 
> 2.29.2
> 
>