Re: [PATCH 2/2] powerpc/kvm: Remove comment related to moving PMU code to perf subsystem

2022-07-12 Thread Nicholas Piggin
Excerpts from Kajol Jain's message of July 11, 2022 1:49 pm:
> Commit aabcaf6ae2a0 ("KVM: PPC: Book3S HV P9: Move host OS save/restore
> functions to  built-in") added a comment in switch_pmu_to_guest
> function, indicating possibility of moving PMU handling code
> to perf subsystem. But perf subsystem code compilation depends upon
> the enablement of CONFIG_PERF_EVENTS whereas, kvm code don't have
> any dependency on this config.
> Patch remove this comment as switch_pmu_to_guest functionality is
> needed even if perf subsystem is disabled.
> 
> Signed-off-by: Kajol Jain 

Does the host PMU state need to be saved/restored if we don't have
PERF_EVENTS enabled? Guest yes, but host maybe could become a no-op?

Thanks,
Nick

> ---
>  arch/powerpc/kvm/book3s_hv_p9_perf.c | 6 --
>  1 file changed, 6 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv_p9_perf.c 
> b/arch/powerpc/kvm/book3s_hv_p9_perf.c
> index da3135cab9ea..44d24cca3df1 100644
> --- a/arch/powerpc/kvm/book3s_hv_p9_perf.c
> +++ b/arch/powerpc/kvm/book3s_hv_p9_perf.c
> @@ -44,12 +44,6 @@ void switch_pmu_to_guest(struct kvm_vcpu *vcpu,
>  
>   /* Save host */
>   if (ppc_get_pmu_inuse()) {
> - /*
> -  * It might be better to put PMU handling (at least for the
> -  * host) in the perf subsystem because it knows more about what
> -  * is being used.
> -  */
> -
>   /* POWER9, POWER10 do not implement HPMC or SPMC */
>  
>   host_os_sprs->mmcr0 = mfspr(SPRN_MMCR0);
> -- 
> 2.27.0
> 
> 


Re: [PATCH 1/2] powerpc/kvm: Move pmu code in kvm folder to separate file for power9 and later platforms

2022-07-12 Thread Nicholas Piggin
Excerpts from Kajol Jain's message of July 11, 2022 1:49 pm:
> File book3s_hv_p9_entry.c in powerpc/kvm folder consists of functions
> like freeze_pmu, switch_pmu_to_guest and switch_pmu_to_host which are
> specific to Performance Monitoring Unit(PMU) for power9 and later
> platforms.
> 
> For better maintenance, moving pmu related code from
> book3s_hv_p9_entry.c to a new file called book3s_hv_p9_perf.c,
> without any logic change.
> Also make corresponding changes in the Makefile to include
> book3s_hv_p9_perf.c during compilation.


> +
> + if (ppc_get_pmu_inuse()) {
> + mtspr(SPRN_PMC1, host_os_sprs->pmc1);
> + mtspr(SPRN_PMC2, host_os_sprs->pmc2);
> + mtspr(SPRN_PMC3, host_os_sprs->pmc3);
> + mtspr(SPRN_PMC4, host_os_sprs->pmc4);
> + mtspr(SPRN_PMC5, host_os_sprs->pmc5);
> + mtspr(SPRN_PMC6, host_os_sprs->pmc6);
> + mtspr(SPRN_MMCR1, host_os_sprs->mmcr1);
> + mtspr(SPRN_MMCR2, host_os_sprs->mmcr2);
> + mtspr(SPRN_SDAR, host_os_sprs->sdar);
> + mtspr(SPRN_SIAR, host_os_sprs->siar);
> + mtspr(SPRN_SIER, host_os_sprs->sier1);
> +
> + if (cpu_has_feature(CPU_FTR_ARCH_31)) {
> + mtspr(SPRN_MMCR3, host_os_sprs->mmcr3);
> + mtspr(SPRN_SIER2, host_os_sprs->sier2);
> + mtspr(SPRN_SIER3, host_os_sprs->sier3);
> + }
> +
> + /* Set MMCRA then MMCR0 last */
> + mtspr(SPRN_MMCRA, host_os_sprs->mmcra);
> + mtspr(SPRN_MMCR0, host_os_sprs->mmcr0);
> + isync();
> + }
> +}
> +EXPORT_SYMBOL_GPL(switch_pmu_to_host);
> 

I'm still thinking these parts of the code in particular that do the 
host PMU save/restore could be handled by calls into perf subsystem.  In 
some cases it doesn't need to save SPRs because it can recreate them or 
is not using them. Maybe it's not so simple.

Either way, I'm fine with this move to stat with.

Reviewed-by: Nicholas Piggin 


oob read in do_adb_query function

2022-07-12 Thread sohu0106



In do_adb_query function of drivers/macintosh/adb.c, req->data is copy form 
userland. the  parameter "req->data[2]" is Missing check, the array size of 
adb_handler[] is 16, so "adb_handler[req->data[2]].original_address" and 
"adb_handler[req->data[2]].handler_id" will lead to oob read.
 


diff --git a/adb.c b/adb.c_patch
index 73b3961..8a5604b 100644
--- a/adb.c
+++ b/adb.c_patch
@@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)


        switch(req->data[1]) {
        case ADB_QUERY_GETDEVINFO:
-               if (req->nbytes < 3)
+               if (req->nbytes < 3 || req->data[2] > 16)
                        break;
                mutex_lock(_handler_mutex);
                req->reply[0] = adb_handler[req-

Re: oob read in do_adb_query function

2022-07-12 Thread Benjamin Herrenschmidt
On Wed, 2022-07-13 at 09:54 +0800, sohu0106 wrote:
> 
> 
> In do_adb_query function of drivers/macintosh/adb.c, req->data is
> copy form userland. the  parameter "req->data[2]" is Missing check,
> the array size of adb_handler[] is 16, so "adb_handler[req-
> >data[2]].original_address" and "adb_handler[req-
> >data[2]].handler_id" will lead to oob read.

Thanks ! Can you send this with a proper Signed-off-by so we can apply
directly ?

Cheers,
Ben.
> 
> 
> diff --git a/adb.c b/adb.c_patch
> index 73b3961..8a5604b 100644
> --- a/adb.c
> +++ b/adb.c_patch
> @@ -647,7 +647,7 @@ do_adb_query(struct adb_request *req)
> 
> 
> switch(req->data[1]) {
> case ADB_QUERY_GETDEVINFO:
> -   if (req->nbytes < 3)
> +   if (req->nbytes < 3 || req->data[2] > 16)
> break;
> mutex_lock(_handler_mutex);
> req->reply[0] = adb_handler[req-



[PATCH 1/2] powerpc/pseries: define driver for Platform KeyStore

2022-07-12 Thread Nayna Jain
PowerVM provides an isolated Platform Keystore(PKS) storage allocation
for each LPAR with individually managed access controls to store
sensitive information securely. It provides a new set of hypervisor
calls for Linux kernel to access PKS storage.

Define PLPKS driver using H_CALL interface to access PKS storage.

Signed-off-by: Nayna Jain 
---
 arch/powerpc/include/asm/hvcall.h |   9 +
 arch/powerpc/include/asm/plpks.h  |  90 
 arch/powerpc/platforms/pseries/Kconfig|  13 +
 arch/powerpc/platforms/pseries/Makefile   |   2 +
 arch/powerpc/platforms/pseries/plpks/Makefile |   7 +
 arch/powerpc/platforms/pseries/plpks/plpks.c  | 509 ++
 6 files changed, 630 insertions(+)
 create mode 100644 arch/powerpc/include/asm/plpks.h
 create mode 100644 arch/powerpc/platforms/pseries/plpks/Makefile
 create mode 100644 arch/powerpc/platforms/pseries/plpks/plpks.c

diff --git a/arch/powerpc/include/asm/hvcall.h 
b/arch/powerpc/include/asm/hvcall.h
index d92a20a85395..24b661b0717c 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -97,6 +97,7 @@
 #define H_OP_MODE  -73
 #define H_COP_HW   -74
 #define H_STATE-75
+#define H_IN_USE   -77
 #define H_UNSUPPORTED_FLAG_START   -256
 #define H_UNSUPPORTED_FLAG_END -511
 #define H_MULTI_THREADS_ACTIVE -9005
@@ -321,6 +322,14 @@
 #define H_SCM_UNBIND_ALL0x3FC
 #define H_SCM_HEALTH0x400
 #define H_SCM_PERFORMANCE_STATS 0x418
+#define H_PKS_GET_CONFIG   0x41C
+#define H_PKS_SET_PASSWORD 0x420
+#define H_PKS_GEN_PASSWORD 0x424
+#define H_PKS_WRITE_OBJECT 0x42C
+#define H_PKS_GEN_KEY  0x430
+#define H_PKS_READ_OBJECT  0x434
+#define H_PKS_REMOVE_OBJECT0x438
+#define H_PKS_CONFIRM_OBJECT_FLUSHED   0x43C
 #define H_RPT_INVALIDATE   0x448
 #define H_SCM_FLUSH0x44C
 #define H_GET_ENERGY_SCALE_INFO0x450
diff --git a/arch/powerpc/include/asm/plpks.h b/arch/powerpc/include/asm/plpks.h
new file mode 100644
index ..cf60e53e1f15
--- /dev/null
+++ b/arch/powerpc/include/asm/plpks.h
@@ -0,0 +1,90 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2022 IBM Corporation
+ * Author: Nayna Jain 
+ *
+ * Platform keystore for pseries LPAR(PLPKS).
+ */
+
+#ifndef _PSERIES_PLPKS_H
+#define _PSERIES_PLPKS_H
+
+#include 
+#include 
+
+#define OSSECBOOTAUDIT 0x4000
+#define OSSECBOOTENFORCE 0x2000
+#define WORLDREADABLE 0x0800
+#define SIGNEDUPDATE 0x0100
+
+#define PLPKS_VAR_LINUX0x01
+#define PLPKS_VAR_COMMON   0x04
+
+struct plpks_var {
+   char *component;
+   u8 os;
+   u8 *name;
+   u16 namelen;
+   u32 policy;
+   u16 datalen;
+   u8 *data;
+};
+
+struct plpks_var_name {
+   u16 namelen;
+   u8  *name;
+};
+
+struct plpks_var_name_list {
+   u32 varcount;
+   struct plpks_var_name varlist[];
+};
+
+struct plpks_config {
+   u8 version;
+   u8 flags;
+   u32 rsvd0;
+   u16 maxpwsize;
+   u16 maxobjlabelsize;
+   u16 maxobjsize;
+   u32 totalsize;
+   u32 usedspace;
+   u32 supportedpolicies;
+   u64 rsvd1;
+} __packed;
+
+/**
+ * Successful return from this API  implies PKS is available.
+ * This is used to initialize kernel driver and user interfaces.
+ */
+struct plpks_config *plpks_get_config(void);
+
+/**
+ * Writes the specified var and its data to PKS.
+ * Any caller of PKS driver should present a valid component type for
+ * their variable.
+ */
+int plpks_write_var(struct plpks_var var);
+
+/**
+ * Removes the specified var and its data from PKS.
+ */
+int plpks_remove_var(char *component, u8 varos,
+struct plpks_var_name vname);
+
+/**
+ * Returns the data for the specified os variable.
+ */
+int plpks_read_os_var(struct plpks_var *var);
+
+/**
+ * Returns the data for the specified firmware variable.
+ */
+int plpks_read_fw_var(struct plpks_var *var);
+
+/**
+ * Returns the data for the specified bootloader variable.
+ */
+int plpks_read_bootloader_var(struct plpks_var *var);
+
+#endif
diff --git a/arch/powerpc/platforms/pseries/Kconfig 
b/arch/powerpc/platforms/pseries/Kconfig
index f7fd91d153a4..de6efe5d18c2 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -142,6 +142,19 @@ config IBMEBUS
help
  Bus device driver for GX bus based adapters.
 
+config PSERIES_PLPKS
+   depends on PPC_PSERIES
+   tristate "Support for the Platform Key Storage"
+   help
+ PowerVM provides an isolated Platform Keystore(PKS) storage
+ allocation for each LPAR with individually managed access
+ controls to store sensitive information securely. It can be
+ used to store asymmetric public keys or secrets as required
+ by different usecases. Select this config to enable
+ operating system interface to hypervisor to access this 

[PATCH 2/2] powerpc/pseries: kernel interfaces to PLPKS platform driver

2022-07-12 Thread Nayna Jain
From: Greg Joyce 

Add platform specific interfaces arch_read_variable() and
arch_variable() to allow platform agnostic access to platform
variable stores.

Signed-off-by: Greg Joyce 
---
 arch/powerpc/platforms/pseries/plpks/Makefile |   1 +
 .../platforms/pseries/plpks/plpks_arch_ops.c  | 163 ++
 2 files changed, 164 insertions(+)
 create mode 100644 arch/powerpc/platforms/pseries/plpks/plpks_arch_ops.c

diff --git a/arch/powerpc/platforms/pseries/plpks/Makefile 
b/arch/powerpc/platforms/pseries/plpks/Makefile
index e651ace920db..3e9ce6f16575 100644
--- a/arch/powerpc/platforms/pseries/plpks/Makefile
+++ b/arch/powerpc/platforms/pseries/plpks/Makefile
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_PSERIES_PLPKS)  += plpks.o
+obj-$(CONFIG_PSERIES_PLPKS)  += plpks_arch_ops.o
diff --git a/arch/powerpc/platforms/pseries/plpks/plpks_arch_ops.c 
b/arch/powerpc/platforms/pseries/plpks/plpks_arch_ops.c
new file mode 100644
index ..11cd03da08b7
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/plpks/plpks_arch_ops.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * POWER platform keystore
+ * Copyright (C) 2022 IBM Corporation
+ *
+ * This pseries platform device driver provides access to
+ * variables stored in platform keystore.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * variable structure that contains all SED data
+ */
+struct plpks_sed_object_data {
+   u_char version;
+   u_char pad1[7];
+   u_long authority;
+   u_long range;
+   u_int  key_len;
+   u_char key[32];
+};
+
+/*
+ * ext_type values
+ * 00no extension exists
+ * 01-1F common
+ * 20-3F AIX
+ * 40-5F Linux
+ * 60-7F IBMi
+ */
+
+/*
+ * This extension is optional for version 1 sed_object_data
+ */
+struct sed_object_extension {
+   u8 ext_type;
+   u8 rsvd[3];
+   u8 ext_data[64];
+};
+
+#define PKS_SED_OBJECT_DATA_V1  1
+#define PKS_SED_MANGLED_LABEL   "/default/pri"
+#define PLPKS_SED_COMPONENT "sed-opal"
+#define PLPKS_SED_POLICYWORLDREADABLE
+#define PLPKS_SED_OS_COMMON 4
+
+#ifndef CONFIG_BLK_SED_OPAL
+#defineOPAL_AUTH_KEY   ""
+#endif
+
+/*
+ * Read the variable data from PKS given the label
+ */
+int arch_read_variable(enum arch_variable_type type, char *varname,
+  void *varbuf, u_int *varlen)
+{
+   struct plpks_var var;
+   struct plpks_sed_object_data *data;
+   u_int offset = 0;
+   char *buf = (char *)varbuf;
+   int ret;
+
+   var.name = varname;
+   var.namelen = strlen(varname);
+   var.policy = PLPKS_SED_POLICY;
+   var.os = PLPKS_SED_OS_COMMON;
+   var.data = NULL;
+   var.datalen = 0;
+
+   switch (type) {
+   case ARCH_VAR_OPAL_KEY:
+   var.component = PLPKS_SED_COMPONENT;
+   if (strcmp(OPAL_AUTH_KEY, varname) == 0) {
+   var.name = PKS_SED_MANGLED_LABEL;
+   var.namelen = strlen(varname);
+   }
+   offset = offsetof(struct plpks_sed_object_data, key);
+   break;
+   case ARCH_VAR_OTHER:
+   var.component = "";
+   break;
+   }
+
+   ret = plpks_read_os_var();
+   if (ret != 0)
+   return ret;
+
+   if (offset > var.datalen)
+   offset = 0;
+
+   switch (type) {
+   case ARCH_VAR_OPAL_KEY:
+   data = (struct plpks_sed_object_data *)var.data;
+   *varlen = data->key_len;
+   break;
+   case ARCH_VAR_OTHER:
+   *varlen = var.datalen;
+   break;
+   }
+
+   if (var.data) {
+   memcpy(varbuf, var.data + offset, var.datalen - offset);
+   buf[*varlen] = '\0';
+   kfree(var.data);
+   }
+
+   return 0;
+}
+
+/*
+ * Write the variable data to PKS given the label
+ */
+int arch_write_variable(enum arch_variable_type type, char *varname,
+   void *varbuf, u_int varlen)
+{
+   struct plpks_var var;
+   struct plpks_sed_object_data data;
+   struct plpks_var_name vname;
+
+   var.name = varname;
+   var.namelen = strlen(varname);
+   var.policy = PLPKS_SED_POLICY;
+   var.os = PLPKS_SED_OS_COMMON;
+   var.datalen = varlen;
+   var.data = varbuf;
+
+   switch (type) {
+   case ARCH_VAR_OPAL_KEY:
+   var.component = PLPKS_SED_COMPONENT;
+   if (strcmp(OPAL_AUTH_KEY, varname) == 0) {
+   var.name = PKS_SED_MANGLED_LABEL;
+   var.namelen = strlen(varname);
+   }
+   var.datalen = sizeof(struct plpks_sed_object_data);
+   var.data = (u8 *)
+
+   /* initialize SED object */
+   data.version = PKS_SED_OBJECT_DATA_V1;
+   data.authority = 

[PATCH 0/2] Provide PowerVM LPAR Platform KeyStore driver for Self Encrypting Drives

2022-07-12 Thread Nayna Jain
PowerVM provides an isolated Platform KeyStore(PKS)[1] storage allocation
for each partition(LPAR) with individually managed access controls to store
sensitive information securely. The Linux Kernel can access this storage by
interfacing with the hypervisor using a new set of hypervisor calls. 

This storage can be used for multiple purposes. The current two usecases
are:

1. Guest Secure Boot on PowerVM[2]
2. Self Encrypting Drives(SED) on PowerVM[3]

Initially, the PowerVM LPAR Platform KeyStore(PLPKS) driver was defined
as part of RFC patches which included the user interface design for guest
secure boot[2]. While this interface is still in progress, the same driver
is also required for Self Encrypting Drives(SED) support. For this reason,
the driver is being split from the patchset[1] and is now separately posted
with SED arch-specific code.

This patchset provides driver for PowerVM LPAR Platform KeyStore and also
arch-specific code for SED to make use of it.

The patch series[3] is pre-requisite to build Patch 2/2. The PLPKS
driver can be built of its own.

[1]https://community.ibm.com/community/user/power/blogs/chris-engel1/2020/11/20/powervm-introduces-the-platform-keystore
[2]https://lore.kernel.org/linuxppc-dev/20220622215648.96723-1-na...@linux.ibm.com/
[3]https://lore.kernel.org/keyrings/20220706023935.875994-1-gjo...@linux.vnet.ibm.com/T/#mc32b51991bf825ec6f90af010998ec7cd2b9624a

Greg Joyce (1):
  powerpc/pseries: kernel interfaces to PLPKS platform driver

Nayna Jain (1):
  powerpc/pseries: define driver for Platform KeyStore

 arch/powerpc/include/asm/hvcall.h |   9 +
 arch/powerpc/include/asm/plpks.h  |  90 
 arch/powerpc/platforms/pseries/Kconfig|  13 +
 arch/powerpc/platforms/pseries/Makefile   |   2 +
 arch/powerpc/platforms/pseries/plpks/Makefile |   8 +
 arch/powerpc/platforms/pseries/plpks/plpks.c  | 509 ++
 .../platforms/pseries/plpks/plpks_arch_ops.c  | 163 ++
 7 files changed, 794 insertions(+)
 create mode 100644 arch/powerpc/include/asm/plpks.h
 create mode 100644 arch/powerpc/platforms/pseries/plpks/Makefile
 create mode 100644 arch/powerpc/platforms/pseries/plpks/plpks.c
 create mode 100644 arch/powerpc/platforms/pseries/plpks/plpks_arch_ops.c

-- 
2.27.0


RE: [REPOST PATCH] ndtest: Cleanup all of blk namespace specific code

2022-07-12 Thread Dan Williams
Shivaprasad G Bhat wrote:
> With the nd_namespace_blk and nd_blk_region infrastructures being removed,
> the ndtest still has some references to the old code. So the
> compilation fails as below,
> 
> ../tools/testing/nvdimm/test/ndtest.c:204:25: error: 
> ‘ND_DEVICE_NAMESPACE_BLK’ undeclared here (not in a function); did you mean 
> ‘ND_DEVICE_NAMESPACE_IO’?
>   204 | .type = ND_DEVICE_NAMESPACE_BLK,
>   | ^~~
>   | ND_DEVICE_NAMESPACE_IO
> ../tools/testing/nvdimm/test/ndtest.c: In function ‘ndtest_create_region’:
> ../tools/testing/nvdimm/test/ndtest.c:630:17: error: ‘ndbr_desc’ undeclared 
> (first use in this function); did you mean ‘ndr_desc’?
>   630 | ndbr_desc.enable = ndtest_blk_region_enable;
>   | ^
>   | ndr_desc
> ../tools/testing/nvdimm/test/ndtest.c:630:17: note: each undeclared 
> identifier is reported only once for each function it appears in
> ../tools/testing/nvdimm/test/ndtest.c:630:36: error: 
> ‘ndtest_blk_region_enable’ undeclared (first use in this function)
>   630 | ndbr_desc.enable = ndtest_blk_region_enable;
>   |^~~~
> ../tools/testing/nvdimm/test/ndtest.c:631:35: error: ‘ndtest_blk_do_io’ 
> undeclared (first use in this function); did you mean ‘ndtest_blk_mmio’?
>   631 | ndbr_desc.do_io = ndtest_blk_do_io;
>   |   ^~~~
>   |   ndtest_blk_mmio
> 
> The current patch removes the specific code to cleanup all obsolete
> references.
> 
> Signed-off-by: Shivaprasad G Bhat 

Looks good, applied.



Re: [PATCH 2/2] cxl: Fix a memory leak in an error handling path

2022-07-12 Thread Andrew Donnellan
On Mon, 2022-07-11 at 21:14 +0200, Christophe JAILLET wrote:
> A bitmap_zalloc() must be balanced by a corresponding bitmap_free()
> in the
> error handling path of afu_allocate_irqs().
> 
> Signed-off-by: Christophe JAILLET 

Thanks for catching this.

Acked-by: Andrew Donnellan 

> ---
> The error handling path should be done in the reversed order but it
> should
> work as-is.
> ---
>  drivers/misc/cxl/irq.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/misc/cxl/irq.c b/drivers/misc/cxl/irq.c
> index 0ce91d99aead..b730e022a48e 100644
> --- a/drivers/misc/cxl/irq.c
> +++ b/drivers/misc/cxl/irq.c
> @@ -349,6 +349,7 @@ int afu_allocate_irqs(struct cxl_context *ctx,
> u32 count)
>  
>  out:
> cxl_ops->release_irq_ranges(>irqs, ctx->afu->adapter);
> +   bitmap_free(ctx->irq_bitmap);
> afu_irq_name_free(ctx);
> return -ENOMEM;
>  }




Re: [PATCH 1/2] cxl: Use the bitmap API to allocate bitmaps

2022-07-12 Thread Andrew Donnellan
On Mon, 2022-07-11 at 21:14 +0200, Christophe JAILLET wrote:
> Use bitmap_zalloc()/bitmap_free() instead of hand-writing them.
> 
> It is less verbose and it improves the semantic.
> 
> Signed-off-by: Christophe JAILLET 

Thanks!

Acked-by: Andrew Donnellan 

> ---
>  drivers/misc/cxl/context.c | 2 +-
>  drivers/misc/cxl/guest.c   | 2 +-
>  drivers/misc/cxl/irq.c | 3 +--
>  drivers/misc/cxl/of.c  | 5 ++---
>  4 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
> index e627b4056623..acaa44809c58 100644
> --- a/drivers/misc/cxl/context.c
> +++ b/drivers/misc/cxl/context.c
> @@ -331,7 +331,7 @@ static void reclaim_ctx(struct rcu_head *rcu)
> __free_page(ctx->ff_page);
> ctx->sstp = NULL;
>  
> -   kfree(ctx->irq_bitmap);
> +   bitmap_free(ctx->irq_bitmap);
>  
> /* Drop ref to the afu device taken during cxl_context_init
> */
> cxl_afu_put(ctx->afu);
> diff --git a/drivers/misc/cxl/guest.c b/drivers/misc/cxl/guest.c
> index 3321c014913c..375f692ae9d6 100644
> --- a/drivers/misc/cxl/guest.c
> +++ b/drivers/misc/cxl/guest.c
> @@ -1053,7 +1053,7 @@ static void free_adapter(struct cxl *adapter)
> if (adapter->guest->irq_avail) {
> for (i = 0; i < adapter->guest->irq_nranges;
> i++) {
> cur = >guest->irq_avail[i];
> -   kfree(cur->bitmap);
> +   bitmap_free(cur->bitmap);
> }
> kfree(adapter->guest->irq_avail);
> }
> diff --git a/drivers/misc/cxl/irq.c b/drivers/misc/cxl/irq.c
> index 5f0e2dcebb34..0ce91d99aead 100644
> --- a/drivers/misc/cxl/irq.c
> +++ b/drivers/misc/cxl/irq.c
> @@ -319,8 +319,7 @@ int afu_allocate_irqs(struct cxl_context *ctx,
> u32 count)
> }
>  
> ctx->irq_count = count;
> -   ctx->irq_bitmap = kcalloc(BITS_TO_LONGS(count),
> - sizeof(*ctx->irq_bitmap),
> GFP_KERNEL);
> +   ctx->irq_bitmap = bitmap_zalloc(count, GFP_KERNEL);
> if (!ctx->irq_bitmap)
> goto out;
>  
> diff --git a/drivers/misc/cxl/of.c b/drivers/misc/cxl/of.c
> index 1cfecba42d01..25ce725035e7 100644
> --- a/drivers/misc/cxl/of.c
> +++ b/drivers/misc/cxl/of.c
> @@ -308,8 +308,7 @@ static int read_adapter_irq_config(struct cxl
> *adapter, struct device_node *np)
> cur = >guest->irq_avail[i];
> cur->offset = be32_to_cpu(ranges[i * 2]);
> cur->range  = be32_to_cpu(ranges[i * 2 + 1]);
> -   cur->bitmap = kcalloc(BITS_TO_LONGS(cur->range),
> -   sizeof(*cur->bitmap), GFP_KERNEL);
> +   cur->bitmap = bitmap_zalloc(cur->range, GFP_KERNEL);
> if (cur->bitmap == NULL)
> goto err;
> if (cur->offset < adapter->guest->irq_base_offset)
> @@ -326,7 +325,7 @@ static int read_adapter_irq_config(struct cxl
> *adapter, struct device_node *np)
>  err:
> for (i--; i >= 0; i--) {
> cur = >guest->irq_avail[i];
> -   kfree(cur->bitmap);
> +   bitmap_free(cur->bitmap);
> }
> kfree(adapter->guest->irq_avail);
> adapter->guest->irq_avail = NULL;




Re: [PATCH 1/2] powerpc: add BookS wait opcode macro

2022-07-12 Thread Segher Boessenkool
Hi!

On Mon, Jul 11, 2022 at 01:11:27PM +1000, Nicholas Piggin wrote:
> The wait instruction has a different encoding between BookE and BookS.
> Add the BookS variant.

>  #define PPC_RAW_WAIT(w)  (0x7c7c | __PPC_WC(w))
> +#define PPC_RAW_WAIT_BOOKS(w, p) (0x7c3c | __PPC_WC(w) | __PPC_PL(p))

The embedded extensions are no longer part of the PowerPC architecture,
so wouldn't it be a better way forward to rename the existing one,
instead?  A bit more work now, but less in the future :-)


Segher


Re: [PATCH v4 4/4] pseries/mobility: set NMI watchdog factor during LPM

2022-07-12 Thread Randy Dunlap
Hi--

On 7/12/22 07:32, Laurent Dufour wrote:
> During a LPM, while the memory transfer is in progress on the arrival side,
> some latencies is generated when accessing not yet transferred pages on the

 are

> arrival side. Thus, the NMI watchdog may be triggered too frequently, which
> increases the risk to hit a NMI interrupt in a bad place in the kernel,

an NMI

> leading to a kernel panic.
> 
> Disabling the Hard Lockup Watchdog until the memory transfer could be a too
> strong work around, some users would want this timeout to be eventually
> triggered if the system is hanging even during LPM.
> 
> Introduce a new sysctl variable nmi_watchdog_factor. It allows to apply
> a factor to the NMI watchdog timeout during a LPM. Just before the CPU are

  an LPM.the CPU is

> stopped for the switchover sequence, the NMI watchdog timer is set to
>  watchdog_tresh + factor%

   watchdog_thresh

> 
> A value of 0 has no effect. The default value is 200, meaning that the NMI
> watchdog is set to 30s during LPM (based on a 10s watchdog_tresh value).

watchdog_thresh

> Once the memory transfer is achieved, the factor is reset to 0.
> 
> Setting this value to a high number is like disabling the NMI watchdog
> during a LPM.

 an LPM.

> 
> Reviewed-by: Nicholas Piggin 
> Signed-off-by: Laurent Dufour 
> ---
>  Documentation/admin-guide/sysctl/kernel.rst | 12 ++
>  arch/powerpc/platforms/pseries/mobility.c   | 43 +
>  2 files changed, 55 insertions(+)
> 
> diff --git a/Documentation/admin-guide/sysctl/kernel.rst 
> b/Documentation/admin-guide/sysctl/kernel.rst
> index ddccd1077462..0bb0b7f27e96 100644
> --- a/Documentation/admin-guide/sysctl/kernel.rst
> +++ b/Documentation/admin-guide/sysctl/kernel.rst
> @@ -592,6 +592,18 @@ to the guest kernel command line (see
>  Documentation/admin-guide/kernel-parameters.rst).
>  

This entire block should be in kernel-parameters.txt, not .rst,
and it should be formatted like everything else in the .txt file.

>  
> +nmi_watchdog_factor (PPC only)
> +==
> +
> +Factor apply to to the NMI watchdog timeout (only when ``nmi_watchdog`` is

   Factor to apply to the NMI

> +set to 1). This factor represents the percentage added to
> +``watchdog_thresh`` when calculating the NMI watchdog timeout during a

 during an

> +LPM. The soft lockup timeout is not impacted.
> +
> +A value of 0 means no change. The default value is 200 meaning the NMI
> +watchdog is set to 30s (based on ``watchdog_thresh`` equal to 10).
> +
> +
>  numa_balancing
>  ==
>  


-- 
~Randy


[REPOST PATCH] ndtest: Cleanup all of blk namespace specific code

2022-07-12 Thread Shivaprasad G Bhat
With the nd_namespace_blk and nd_blk_region infrastructures being removed,
the ndtest still has some references to the old code. So the
compilation fails as below,

../tools/testing/nvdimm/test/ndtest.c:204:25: error: ‘ND_DEVICE_NAMESPACE_BLK’ 
undeclared here (not in a function); did you mean ‘ND_DEVICE_NAMESPACE_IO’?
  204 | .type = ND_DEVICE_NAMESPACE_BLK,
  | ^~~
  | ND_DEVICE_NAMESPACE_IO
../tools/testing/nvdimm/test/ndtest.c: In function ‘ndtest_create_region’:
../tools/testing/nvdimm/test/ndtest.c:630:17: error: ‘ndbr_desc’ undeclared 
(first use in this function); did you mean ‘ndr_desc’?
  630 | ndbr_desc.enable = ndtest_blk_region_enable;
  | ^
  | ndr_desc
../tools/testing/nvdimm/test/ndtest.c:630:17: note: each undeclared identifier 
is reported only once for each function it appears in
../tools/testing/nvdimm/test/ndtest.c:630:36: error: ‘ndtest_blk_region_enable’ 
undeclared (first use in this function)
  630 | ndbr_desc.enable = ndtest_blk_region_enable;
  |^~~~
../tools/testing/nvdimm/test/ndtest.c:631:35: error: ‘ndtest_blk_do_io’ 
undeclared (first use in this function); did you mean ‘ndtest_blk_mmio’?
  631 | ndbr_desc.do_io = ndtest_blk_do_io;
  |   ^~~~
  |   ndtest_blk_mmio

The current patch removes the specific code to cleanup all obsolete
references.

Signed-off-by: Shivaprasad G Bhat 
---
Changelog:
Repost of v1:
Link - 
https://patchwork.kernel.org/project/linux-nvdimm/patch/165025395730.2821159.14794984437851867426.st...@lep8c.aus.stglabs.ibm.com/
No changes.

 tools/testing/nvdimm/test/ndtest.c |   77 
 1 file changed, 77 deletions(-)

diff --git a/tools/testing/nvdimm/test/ndtest.c 
b/tools/testing/nvdimm/test/ndtest.c
index 4d1a947367f9..01ceb98c15a0 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -134,39 +134,6 @@ static struct ndtest_mapping region1_mapping[] = {
},
 };

-static struct ndtest_mapping region2_mapping[] = {
-   {
-   .dimm = 0,
-   .position = 0,
-   .start = 0,
-   .size = DIMM_SIZE,
-   },
-};
-
-static struct ndtest_mapping region3_mapping[] = {
-   {
-   .dimm = 1,
-   .start = 0,
-   .size = DIMM_SIZE,
-   }
-};
-
-static struct ndtest_mapping region4_mapping[] = {
-   {
-   .dimm = 2,
-   .start = 0,
-   .size = DIMM_SIZE,
-   }
-};
-
-static struct ndtest_mapping region5_mapping[] = {
-   {
-   .dimm = 3,
-   .start = 0,
-   .size = DIMM_SIZE,
-   }
-};
-
 static struct ndtest_region bus0_regions[] = {
{
.type = ND_DEVICE_NAMESPACE_PMEM,
@@ -182,34 +149,6 @@ static struct ndtest_region bus0_regions[] = {
.size = DIMM_SIZE * 2,
.range_index = 2,
},
-   {
-   .type = ND_DEVICE_NAMESPACE_BLK,
-   .num_mappings = ARRAY_SIZE(region2_mapping),
-   .mapping = region2_mapping,
-   .size = DIMM_SIZE,
-   .range_index = 3,
-   },
-   {
-   .type = ND_DEVICE_NAMESPACE_BLK,
-   .num_mappings = ARRAY_SIZE(region3_mapping),
-   .mapping = region3_mapping,
-   .size = DIMM_SIZE,
-   .range_index = 4,
-   },
-   {
-   .type = ND_DEVICE_NAMESPACE_BLK,
-   .num_mappings = ARRAY_SIZE(region4_mapping),
-   .mapping = region4_mapping,
-   .size = DIMM_SIZE,
-   .range_index = 5,
-   },
-   {
-   .type = ND_DEVICE_NAMESPACE_BLK,
-   .num_mappings = ARRAY_SIZE(region5_mapping),
-   .mapping = region5_mapping,
-   .size = DIMM_SIZE,
-   .range_index = 6,
-   },
 };

 static struct ndtest_mapping region6_mapping[] = {
@@ -501,21 +440,6 @@ static int ndtest_create_region(struct ndtest_priv *p,
nd_set->altcookie = nd_set->cookie1;
ndr_desc->nd_set = nd_set;

-   if (region->type == ND_DEVICE_NAMESPACE_BLK) {
-   mappings[0].start = 0;
-   mappings[0].size = DIMM_SIZE;
-   mappings[0].nvdimm = p->config->dimms[ndimm].nvdimm;
-
-   ndr_desc->mapping = [0];
-   ndr_desc->num_mappings = 1;
-   ndr_desc->num_lanes = 1;
-   ndbr_desc.enable = ndtest_blk_region_enable;
-   ndbr_desc.do_io = ndtest_blk_do_io;
-   region->region = nvdimm_blk_region_create(p->bus, ndr_desc);
-
-   goto done;
-   }
-
for (i = 0; i 

[PATCH v4 4/4] pseries/mobility: set NMI watchdog factor during LPM

2022-07-12 Thread Laurent Dufour
During a LPM, while the memory transfer is in progress on the arrival side,
some latencies is generated when accessing not yet transferred pages on the
arrival side. Thus, the NMI watchdog may be triggered too frequently, which
increases the risk to hit a NMI interrupt in a bad place in the kernel,
leading to a kernel panic.

Disabling the Hard Lockup Watchdog until the memory transfer could be a too
strong work around, some users would want this timeout to be eventually
triggered if the system is hanging even during LPM.

Introduce a new sysctl variable nmi_watchdog_factor. It allows to apply
a factor to the NMI watchdog timeout during a LPM. Just before the CPU are
stopped for the switchover sequence, the NMI watchdog timer is set to
 watchdog_tresh + factor%

A value of 0 has no effect. The default value is 200, meaning that the NMI
watchdog is set to 30s during LPM (based on a 10s watchdog_tresh value).
Once the memory transfer is achieved, the factor is reset to 0.

Setting this value to a high number is like disabling the NMI watchdog
during a LPM.

Reviewed-by: Nicholas Piggin 
Signed-off-by: Laurent Dufour 
---
 Documentation/admin-guide/sysctl/kernel.rst | 12 ++
 arch/powerpc/platforms/pseries/mobility.c   | 43 +
 2 files changed, 55 insertions(+)

diff --git a/Documentation/admin-guide/sysctl/kernel.rst 
b/Documentation/admin-guide/sysctl/kernel.rst
index ddccd1077462..0bb0b7f27e96 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -592,6 +592,18 @@ to the guest kernel command line (see
 Documentation/admin-guide/kernel-parameters.rst).
 
 
+nmi_watchdog_factor (PPC only)
+==
+
+Factor apply to to the NMI watchdog timeout (only when ``nmi_watchdog`` is
+set to 1). This factor represents the percentage added to
+``watchdog_thresh`` when calculating the NMI watchdog timeout during a
+LPM. The soft lockup timeout is not impacted.
+
+A value of 0 means no change. The default value is 200 meaning the NMI
+watchdog is set to 30s (based on ``watchdog_thresh`` equal to 10).
+
+
 numa_balancing
 ==
 
diff --git a/arch/powerpc/platforms/pseries/mobility.c 
b/arch/powerpc/platforms/pseries/mobility.c
index 6297467072e6..78535a0791f9 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -48,6 +48,39 @@ struct update_props_workarea {
 #define MIGRATION_SCOPE(1)
 #define PRRN_SCOPE -2
 
+#ifdef CONFIG_PPC_WATCHDOG
+static unsigned int nmi_wd_factor = 200;
+
+#ifdef CONFIG_SYSCTL
+static struct ctl_table nmi_wd_factor_ctl_table[] = {
+   {
+   .procname   = "nmi_watchdog_factor",
+   .data   = _wd_factor,
+   .maxlen = sizeof(int),
+   .mode   = 0644,
+   .proc_handler   = proc_douintvec_minmax,
+   },
+   {}
+};
+static struct ctl_table nmi_wd_factor_sysctl_root[] = {
+   {
+   .procname   = "kernel",
+   .mode   = 0555,
+   .child  = nmi_wd_factor_ctl_table,
+   },
+   {}
+};
+
+static int __init register_nmi_wd_factor_sysctl(void)
+{
+   register_sysctl_table(nmi_wd_factor_sysctl_root);
+
+   return 0;
+}
+device_initcall(register_nmi_wd_factor_sysctl);
+#endif /* CONFIG_SYSCTL */
+#endif /* CONFIG_PPC_WATCHDOG */
+
 static int mobility_rtas_call(int token, char *buf, s32 scope)
 {
int rc;
@@ -702,13 +735,20 @@ static int pseries_suspend(u64 handle)
 static int pseries_migrate_partition(u64 handle)
 {
int ret;
+   unsigned int factor = 0;
 
+#ifdef CONFIG_PPC_WATCHDOG
+   factor = nmi_wd_factor;
+#endif
ret = wait_for_vasi_session_suspending(handle);
if (ret)
return ret;
 
vas_migration_handler(VAS_SUSPEND);
 
+   if (factor)
+   watchdog_nmi_set_timeout_pct(factor);
+
ret = pseries_suspend(handle);
if (ret == 0) {
post_mobility_fixup();
@@ -722,6 +762,9 @@ static int pseries_migrate_partition(u64 handle)
} else
pseries_cancel_migration(handle, ret);
 
+   if (factor)
+   watchdog_nmi_set_timeout_pct(0);
+
vas_migration_handler(VAS_RESUME);
 
return ret;
-- 
2.37.0



[PATCH v4 2/4] watchdog: export lockup_detector_reconfigure

2022-07-12 Thread Laurent Dufour
In some circumstances it may be interesting to reconfigure the watchdog
from inside the kernel.

On PowerPC, this may helpful before and after a LPAR migration (LPM) is
initiated, because it implies some latencies, watchdog, and especially NMI
watchdog is expected to be triggered during this operation. Reconfiguring
the watchdog with a factor, would prevent it to happen too frequently
during LPM.

Rename lockup_detector_reconfigure() as __lockup_detector_reconfigure() and
create a new function lockup_detector_reconfigure() calling
__lockup_detector_reconfigure() under the protection of watchdog_mutex.

Cc: Christoph Hellwig 
Signed-off-by: Laurent Dufour 
---
 include/linux/nmi.h |  2 ++
 kernel/watchdog.c   | 21 -
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/include/linux/nmi.h b/include/linux/nmi.h
index 750c7f395ca9..f700ff2df074 100644
--- a/include/linux/nmi.h
+++ b/include/linux/nmi.h
@@ -122,6 +122,8 @@ int watchdog_nmi_probe(void);
 int watchdog_nmi_enable(unsigned int cpu);
 void watchdog_nmi_disable(unsigned int cpu);
 
+void lockup_detector_reconfigure(void);
+
 /**
  * touch_nmi_watchdog - restart NMI watchdog timeout.
  *
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 20a7a55e62b6..90e6c41d5e33 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -541,7 +541,7 @@ int lockup_detector_offline_cpu(unsigned int cpu)
return 0;
 }
 
-static void lockup_detector_reconfigure(void)
+static void __lockup_detector_reconfigure(void)
 {
cpus_read_lock();
watchdog_nmi_stop();
@@ -561,6 +561,13 @@ static void lockup_detector_reconfigure(void)
__lockup_detector_cleanup();
 }
 
+void lockup_detector_reconfigure(void)
+{
+   mutex_lock(_mutex);
+   __lockup_detector_reconfigure();
+   mutex_unlock(_mutex);
+}
+
 /*
  * Create the watchdog infrastructure and configure the detector(s).
  */
@@ -577,13 +584,13 @@ static __init void lockup_detector_setup(void)
return;
 
mutex_lock(_mutex);
-   lockup_detector_reconfigure();
+   __lockup_detector_reconfigure();
softlockup_initialized = true;
mutex_unlock(_mutex);
 }
 
 #else /* CONFIG_SOFTLOCKUP_DETECTOR */
-static void lockup_detector_reconfigure(void)
+void __lockup_detector_reconfigure(void)
 {
cpus_read_lock();
watchdog_nmi_stop();
@@ -591,9 +598,13 @@ static void lockup_detector_reconfigure(void)
watchdog_nmi_start();
cpus_read_unlock();
 }
+static inline void lockup_detector_reconfigure(void)
+{
+   __lockup_detector_reconfigure();
+}
 static inline void lockup_detector_setup(void)
 {
-   lockup_detector_reconfigure();
+   __lockup_detector_reconfigure();
 }
 #endif /* !CONFIG_SOFTLOCKUP_DETECTOR */
 
@@ -633,7 +644,7 @@ static void proc_watchdog_update(void)
 {
/* Remove impossible cpus to keep sysctl output clean. */
cpumask_and(_cpumask, _cpumask, cpu_possible_mask);
-   lockup_detector_reconfigure();
+   __lockup_detector_reconfigure();
 }
 
 /*
-- 
2.37.0



[PATCH v4 3/4] powerpc/watchdog: introduce a NMI watchdog's factor

2022-07-12 Thread Laurent Dufour
Introduce a factor which would apply to the NMI watchdog timeout.

This factor is a percentage added to the watchdog_tresh value. The value is
set under the watchdog_mutex protection and lockup_detector_reconfigure()
is called to recompute wd_panic_timeout_tb.

Once the factor is set, it remains until it is set back to 0, which means
no impact.

Reviewed-by: Nicholas Piggin 
Signed-off-by: Laurent Dufour 
---
 arch/powerpc/include/asm/nmi.h |  2 ++
 arch/powerpc/kernel/watchdog.c | 21 -
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/nmi.h b/arch/powerpc/include/asm/nmi.h
index ea0e487f87b1..c3c7adef74de 100644
--- a/arch/powerpc/include/asm/nmi.h
+++ b/arch/powerpc/include/asm/nmi.h
@@ -5,8 +5,10 @@
 #ifdef CONFIG_PPC_WATCHDOG
 extern void arch_touch_nmi_watchdog(void);
 long soft_nmi_interrupt(struct pt_regs *regs);
+void watchdog_nmi_set_timeout_pct(u64 pct);
 #else
 static inline void arch_touch_nmi_watchdog(void) {}
+static inline void watchdog_nmi_set_timeout_pct(u64 pct) {}
 #endif
 
 #ifdef CONFIG_NMI_IPI
diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c
index 7d28b9553654..5d903e63f932 100644
--- a/arch/powerpc/kernel/watchdog.c
+++ b/arch/powerpc/kernel/watchdog.c
@@ -91,6 +91,10 @@ static cpumask_t wd_smp_cpus_pending;
 static cpumask_t wd_smp_cpus_stuck;
 static u64 wd_smp_last_reset_tb;
 
+#ifdef CONFIG_PPC_PSERIES
+static u64 wd_timeout_pct;
+#endif
+
 /*
  * Try to take the exclusive watchdog action / NMI IPI / printing lock.
  * wd_smp_lock must be held. If this fails, we should return and wait
@@ -527,7 +531,13 @@ static int stop_watchdog_on_cpu(unsigned int cpu)
 
 static void watchdog_calc_timeouts(void)
 {
-   wd_panic_timeout_tb = watchdog_thresh * ppc_tb_freq;
+   u64 threshold = watchdog_thresh;
+
+#ifdef CONFIG_PPC_PSERIES
+   threshold += (READ_ONCE(wd_timeout_pct) * threshold) / 100;
+#endif
+
+   wd_panic_timeout_tb = threshold * ppc_tb_freq;
 
/* Have the SMP detector trigger a bit later */
wd_smp_panic_timeout_tb = wd_panic_timeout_tb * 3 / 2;
@@ -570,3 +580,12 @@ int __init watchdog_nmi_probe(void)
}
return 0;
 }
+
+#ifdef CONFIG_PPC_PSERIES
+void watchdog_nmi_set_timeout_pct(u64 pct)
+{
+   pr_info("Set the NMI watchdog timeout factor to %llu%%\n", pct);
+   WRITE_ONCE(wd_timeout_pct, pct);
+   lockup_detector_reconfigure();
+}
+#endif
-- 
2.37.0



[PATCH v4 0/4] Extending NMI watchdog during LPM

2022-07-12 Thread Laurent Dufour
When a partition is transferred, once it arrives at the destination node,
the partition is active but much of its memory must be transferred from the
start node.

It depends on the activity in the partition, but the more CPU the partition
has, the more memory to be transferred is likely to be. This causes latency
when accessing pages that need to be transferred, and often, for large
partitions, it triggers the NMI watchdog.

The NMI watchdog causes the CPU stack to dump where it appears to be
stuck. In this case, it does not bring much information since it can happen
during any memory access of the kernel.

In addition, the NMI interrupt mechanism is not secure and can generate a
dump system in the event that the interruption is taken while MSR[RI]=0.

Depending on the LPAR size and load, it may be interesting to extend the
NMI watchdog timer during the LPM.

That's configurable through sysctl with the new introduced variable
(specific to powerpc) nmi_watchdog_factor. This value represents the
percentage added to watchdog_tresh to set the NMI watchdog timeout during a
LPM.

Changes in v4 (no functional changes in this version):
 - Patch 1/4 :fix typo and add a comment in pseries_migrate_partition()
 - Patch 3/4: rename new variables and functions as Nick requested.
 - Patch 4/4: rename the called new function

v2:
https://lore.kernel.org/linuxppc-dev/121217bb-6a34-8ccb-9819-f82806d6f...@linux.ibm.com/

Laurent Dufour (4):
  powerpc/mobility: wait for memory transfer to complete
  watchdog: export lockup_detector_reconfigure
  powerpc/watchdog: introduce a NMI watchdog's factor
  pseries/mobility: set NMI watchdog factor during LPM

 Documentation/admin-guide/sysctl/kernel.rst | 12 +++
 arch/powerpc/include/asm/nmi.h  |  2 +
 arch/powerpc/kernel/watchdog.c  | 21 -
 arch/powerpc/platforms/pseries/mobility.c   | 91 -
 include/linux/nmi.h |  2 +
 kernel/watchdog.c   | 21 +++--
 6 files changed, 141 insertions(+), 8 deletions(-)

-- 
2.37.0



[PATCH v4 1/4] powerpc/mobility: wait for memory transfer to complete

2022-07-12 Thread Laurent Dufour
In pseries_migration_partition(), loop until the memory transfer is
complete. This way the calling drmgr process will not exit earlier,
allowing callbacks to be run only once the migration is fully completed.

If reading the VASI state is done after the hypervisor has completed the
migration, the HCALL is returning H_PARAMETER. We can safely assume that
the memory transfer is achieved if this happens.

This will also allow to manage the NMI watchdog state in the next commits.

Reviewed-by: Nathan Lynch 
Reviewed-by: Nicholas Piggin 
Signed-off-by: Laurent Dufour 
---
 arch/powerpc/platforms/pseries/mobility.c | 48 ++-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/mobility.c 
b/arch/powerpc/platforms/pseries/mobility.c
index 78f3f74c7056..6297467072e6 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -427,6 +427,43 @@ static int wait_for_vasi_session_suspending(u64 handle)
return ret;
 }
 
+static void wait_for_vasi_session_completed(u64 handle)
+{
+   unsigned long state = 0;
+   int ret;
+
+   pr_info("waiting for memory transfer to complete...\n");
+
+   /*
+* Wait for transition from H_VASI_RESUMED to H_VASI_COMPLETED.
+*/
+   while (true) {
+   ret = poll_vasi_state(handle, );
+
+   /*
+* If the memory transfer is already complete and the migration
+* has been cleaned up by the hypervisor, H_PARAMETER is return,
+* which is translate in EINVAL by poll_vasi_state().
+*/
+   if (ret == -EINVAL || (!ret && state == H_VASI_COMPLETED)) {
+   pr_info("memory transfer completed.\n");
+   break;
+   }
+
+   if (ret) {
+   pr_err("H_VASI_STATE return error (%d)\n", ret);
+   break;
+   }
+
+   if (state != H_VASI_RESUMED) {
+   pr_err("unexpected H_VASI_STATE result %lu\n", state);
+   break;
+   }
+
+   msleep(500);
+   }
+}
+
 static void prod_single(unsigned int target_cpu)
 {
long hvrc;
@@ -673,9 +710,16 @@ static int pseries_migrate_partition(u64 handle)
vas_migration_handler(VAS_SUSPEND);
 
ret = pseries_suspend(handle);
-   if (ret == 0)
+   if (ret == 0) {
post_mobility_fixup();
-   else
+   /*
+* Wait until the memory transfer is complete, so that the user
+* space process returns from the syscall after the transfer is
+* complete. This allows the user hooks to be executed at the
+* right time.
+*/
+   wait_for_vasi_session_completed(handle);
+   } else
pseries_cancel_migration(handle, ret);
 
vas_migration_handler(VAS_RESUME);
-- 
2.37.0



Re: [PATCH] powerpc: e500: Fix compilation with gcc e500 compiler

2022-07-12 Thread Segher Boessenkool
On Tue, Jul 12, 2022 at 09:22:12AM +, Christophe Leroy wrote:
> Le 11/07/2022 à 23:48, Segher Boessenkool a écrit :
> > I believe the eieio instruction is disabled on some e500 models, because
> > it does not work correctly, so EIEIO_EN=1 cannot work, something like
> > that?
> 
> Don't know.
> 
> It is also disabled on 405 and 440.

BookE does not have the eieio insn.  Instead, it reuses the same opcode
for mbar, which has similar but different semantics.

e500 has that EIEIO_EN thing which makes the insn behave like eieio.

> That's new with GCC 12.

Yup.  In the past we used -many, but that just hides problems in the
best case, and causes more problems itself :-(

There are many mnemonics that cause a different instruction to be
emitted on different targets, and that causes a lot of wasted time
trying to find and fix the problems this causes.

If you hit any remaining problems related to this, please let me know!


Segher


Re: [PATCH v6 4/6] tpm: of: Make of-tree specific function commonly available

2022-07-12 Thread Stefan Berger




On 7/11/22 18:04, Mimi Zohar wrote:

Hi Stefan,

On Thu, 2022-07-07 at 13:20 -0400, Stefan Berger wrote:

-   /*
-* For both vtpm/tpm, firmware has log addr and log size in big
-* endian format. But in case of vtpm, there is a method called
-* sml-handover which is run during kernel init even before
-* device tree is setup. This sml-handover function takes care
-* of endianness and writes to sml-base and sml-size in little
-* endian format. For this reason, vtpm doesn't need conversion
-* but physical tpm needs the conversion.
-*/


This comment is dropped.  Perhaps not in such detail, but shouldn't a
comment or function description exist in the new function.


I am adding back the comment in v7.



Otherwise,
Reviewed-by: Mimi Zohar 

thanks,

Mimi


___
kexec mailing list
ke...@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH v3 3/4] powerpc/watchdog: introduce a NMI watchdog's factor

2022-07-12 Thread Laurent Dufour
Le 12/07/2022 à 03:42, Nicholas Piggin a écrit :
> Excerpts from Laurent Dufour's message of June 27, 2022 11:53 pm:
>> Introduce a factor which would apply to the NMI watchdog timeout.
>>
>> This factor is a percentage added to the watchdog_tresh value. The value is
>> set under the watchdog_mutex protection and lockup_detector_reconfigure()
>> is called to recompute wd_panic_timeout_tb.
>>
>> Once the factor is set, it remains until it is set back to 0, which means
>> no impact.
> 
> Looks okay. We could worry about making it more generic or nicer if
> another user came along.
> 
> Could you make the naming a bit more self documenting? 
> watchdog_nmi_set_timeout_pct(), maybe? Does the wd really care
> that it is for LPM in particular?

You're right, the name should not mention lpm.
For my information, what does "pct" stand for?

> 
> Variables and parameters could have a _pct suffix too.

I'll do that.

> 
> Otherwise
> 
> Reviewed-by: Nicholas Piggin 
> 
>>
>> Signed-off-by: Laurent Dufour 
>> ---
>>  arch/powerpc/include/asm/nmi.h |  2 ++
>>  arch/powerpc/kernel/watchdog.c | 21 -
>>  2 files changed, 22 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/include/asm/nmi.h b/arch/powerpc/include/asm/nmi.h
>> index ea0e487f87b1..7d6a8d9b0543 100644
>> --- a/arch/powerpc/include/asm/nmi.h
>> +++ b/arch/powerpc/include/asm/nmi.h
>> @@ -5,8 +5,10 @@
>>  #ifdef CONFIG_PPC_WATCHDOG
>>  extern void arch_touch_nmi_watchdog(void);
>>  long soft_nmi_interrupt(struct pt_regs *regs);
>> +void watchdog_nmi_set_lpm_factor(u64 factor);
>>  #else
>>  static inline void arch_touch_nmi_watchdog(void) {}
>> +static inline void watchdog_nmi_set_lpm_factor(u64 factor) {}
>>  #endif
>>  
>>  #ifdef CONFIG_NMI_IPI
>> diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c
>> index 7d28b9553654..80851b228f71 100644
>> --- a/arch/powerpc/kernel/watchdog.c
>> +++ b/arch/powerpc/kernel/watchdog.c
>> @@ -91,6 +91,10 @@ static cpumask_t wd_smp_cpus_pending;
>>  static cpumask_t wd_smp_cpus_stuck;
>>  static u64 wd_smp_last_reset_tb;
>>  
>> +#ifdef CONFIG_PPC_PSERIES
>> +static u64 wd_factor;
>> +#endif
>> +
>>  /*
>>   * Try to take the exclusive watchdog action / NMI IPI / printing lock.
>>   * wd_smp_lock must be held. If this fails, we should return and wait
>> @@ -527,7 +531,13 @@ static int stop_watchdog_on_cpu(unsigned int cpu)
>>  
>>  static void watchdog_calc_timeouts(void)
>>  {
>> -wd_panic_timeout_tb = watchdog_thresh * ppc_tb_freq;
>> +u64 threshold = watchdog_thresh;
>> +
>> +#ifdef CONFIG_PPC_PSERIES
>> +threshold += (READ_ONCE(wd_factor) * threshold) / 100;
>> +#endif
>> +
>> +wd_panic_timeout_tb = threshold * ppc_tb_freq;
>>  
>>  /* Have the SMP detector trigger a bit later */
>>  wd_smp_panic_timeout_tb = wd_panic_timeout_tb * 3 / 2;
>> @@ -570,3 +580,12 @@ int __init watchdog_nmi_probe(void)
>>  }
>>  return 0;
>>  }
>> +
>> +#ifdef CONFIG_PPC_PSERIES
>> +void watchdog_nmi_set_lpm_factor(u64 factor)
>> +{
>> +pr_info("Set the NMI watchdog factor to %llu%%\n", factor);
>> +WRITE_ONCE(wd_factor, factor);
>> +lockup_detector_reconfigure();
>> +}
>> +#endif
>> -- 
>> 2.36.1
>>
>>



Re: [PATCH v3 4/4] pseries/mobility: set NMI watchdog factor during LPM

2022-07-12 Thread Laurent Dufour
Le 12/07/2022 à 03:46, Nicholas Piggin a écrit :
> Excerpts from Laurent Dufour's message of June 27, 2022 11:53 pm:
>> During a LPM, while the memory transfer is in progress on the arrival side,
>> some latencies is generated when accessing not yet transferred pages on the
>> arrival side. Thus, the NMI watchdog may be triggered too frequently, which
>> increases the risk to hit a NMI interrupt in a bad place in the kernel,
>> leading to a kernel panic.
>>
>> Disabling the Hard Lockup Watchdog until the memory transfer could be a too
>> strong work around, some users would want this timeout to be eventually
>> triggered if the system is hanging even during LPM.
>>
>> Introduce a new sysctl variable nmi_watchdog_factor. It allows to apply
>> a factor to the NMI watchdog timeout during a LPM. Just before the CPU are
>> stopped for the switchover sequence, the NMI watchdog timer is set to
>>  watchdog_tresh + factor%
>>
>> A value of 0 has no effect. The default value is 200, meaning that the NMI
>> watchdog is set to 30s during LPM (based on a 10s watchdog_tresh value).
>> Once the memory transfer is achieved, the factor is reset to 0.
>>
>> Setting this value to a high number is like disabling the NMI watchdog
>> during a LPM.
>>
>> Signed-off-by: Laurent Dufour 
>> ---
>>  Documentation/admin-guide/sysctl/kernel.rst | 12 ++
>>  arch/powerpc/platforms/pseries/mobility.c   | 43 +
>>  2 files changed, 55 insertions(+)
>>
>> diff --git a/Documentation/admin-guide/sysctl/kernel.rst 
>> b/Documentation/admin-guide/sysctl/kernel.rst
>> index ddccd1077462..0bb0b7f27e96 100644
>> --- a/Documentation/admin-guide/sysctl/kernel.rst
>> +++ b/Documentation/admin-guide/sysctl/kernel.rst
>> @@ -592,6 +592,18 @@ to the guest kernel command line (see
>>  Documentation/admin-guide/kernel-parameters.rst).
>>  
>>  
>> +nmi_watchdog_factor (PPC only)
>> +==
>> +
>> +Factor apply to to the NMI watchdog timeout (only when ``nmi_watchdog`` is
>> +set to 1). This factor represents the percentage added to
>> +``watchdog_thresh`` when calculating the NMI watchdog timeout during a
>> +LPM. The soft lockup timeout is not impacted.
> 
> Could "LPM" or "mobility" be a bit more prominent in the parameter name
> and documentation? Something else might want to add a factor as well,
> one day.

In the V2 version, Nathan suggested "making the user-visible
name more generic (e.g. "nmi_watchdog_factor") in case it makes sense to
apply this to other contexts in the future."

So I made the change to a more generic name. I think this is a good option
since the documentation is explicit about the LPM particular case.
If in the future this factor needs to apply during an other operation that
name will be generic enough.

Do you agree ?

> 
> Otherwise the code looks okay.
> 
> Reviewed-by: Nicholas Piggin 
> 
>> +
>> +A value of 0 means no change. The default value is 200 meaning the NMI
>> +watchdog is set to 30s (based on ``watchdog_thresh`` equal to 10).
>> +
>> +
>>  numa_balancing
>>  ==
>>  
>> diff --git a/arch/powerpc/platforms/pseries/mobility.c 
>> b/arch/powerpc/platforms/pseries/mobility.c
>> index 907a779074d6..649155faafc2 100644
>> --- a/arch/powerpc/platforms/pseries/mobility.c
>> +++ b/arch/powerpc/platforms/pseries/mobility.c
>> @@ -48,6 +48,39 @@ struct update_props_workarea {
>>  #define MIGRATION_SCOPE (1)
>>  #define PRRN_SCOPE -2
>>  
>> +#ifdef CONFIG_PPC_WATCHDOG
>> +static unsigned int nmi_wd_factor = 200;
>> +
>> +#ifdef CONFIG_SYSCTL
>> +static struct ctl_table nmi_wd_factor_ctl_table[] = {
>> +{
>> +.procname   = "nmi_watchdog_factor",
>> +.data   = _wd_factor,
>> +.maxlen = sizeof(int),
>> +.mode   = 0644,
>> +.proc_handler   = proc_douintvec_minmax,
>> +},
>> +{}
>> +};
>> +static struct ctl_table nmi_wd_factor_sysctl_root[] = {
>> +{
>> +.procname   = "kernel",
>> +.mode   = 0555,
>> +.child  = nmi_wd_factor_ctl_table,
>> +},
>> +{}
>> +};
>> +
>> +static int __init register_nmi_wd_factor_sysctl(void)
>> +{
>> +register_sysctl_table(nmi_wd_factor_sysctl_root);
>> +
>> +return 0;
>> +}
>> +device_initcall(register_nmi_wd_factor_sysctl);
>> +#endif /* CONFIG_SYSCTL */
>> +#endif /* CONFIG_PPC_WATCHDOG */
>> +
>>  static int mobility_rtas_call(int token, char *buf, s32 scope)
>>  {
>>  int rc;
>> @@ -702,13 +735,20 @@ static int pseries_suspend(u64 handle)
>>  static int pseries_migrate_partition(u64 handle)
>>  {
>>  int ret;
>> +unsigned int factor = 0;
>>  
>> +#ifdef CONFIG_PPC_WATCHDOG
>> +factor = nmi_wd_factor;
>> +#endif
>>  ret = wait_for_vasi_session_suspending(handle);
>>  if (ret)
>>  return ret;
>>  
>>  vas_migration_handler(VAS_SUSPEND);
>>  
>> +if (factor)
>> +watchdog_nmi_set_lpm_factor(factor);
>> +

Re: [PATCH v3 1/4] powerpc/mobility: wait for memory transfer to complete

2022-07-12 Thread Laurent Dufour
Le 12/07/2022 à 03:33, Nicholas Piggin a écrit :
> Excerpts from Laurent Dufour's message of June 27, 2022 11:53 pm:
>> In pseries_migration_partition(), loop until the memory transfer is
>> complete. This way the calling drmgr process will not exit earlier,
>> allowing callbacks to be run only once the migration is fully completed.
>>
>> If reading the VASI state is done after the hypervisor has completed the
>> migration, the HCALL is returning H_PARAMETER. We can safely assume that
>> the memory transfer is achieved if this happens.
>>
>> This will also allow to manage the NMI watchdog state in the next commits.
>>
>> Reviewed-by: Nathan Lynch 
>> Signed-off-by: Laurent Dufour 
>> ---
>>  arch/powerpc/platforms/pseries/mobility.c | 42 +--
>>  1 file changed, 40 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/powerpc/platforms/pseries/mobility.c 
>> b/arch/powerpc/platforms/pseries/mobility.c
>> index 78f3f74c7056..907a779074d6 100644
>> --- a/arch/powerpc/platforms/pseries/mobility.c
>> +++ b/arch/powerpc/platforms/pseries/mobility.c
>> @@ -427,6 +427,43 @@ static int wait_for_vasi_session_suspending(u64 handle)
>>  return ret;
>>  }
>>  
>> +static void wait_for_vasi_session_completed(u64 handle)
>> +{
>> +unsigned long state = 0;
>> +int ret;
>> +
>> +pr_info("waiting for memory transfert to complete...\n");
> 
> ^ extra t (also below)

I tried to push one French word, but you caught it ;)
Will fix that and the other ones.

>> +
>> +/*
>> + * Wait for transition from H_VASI_RESUMED to H_VASI_COMPLETED.
>> + */
>> +while (true) {
>> +ret = poll_vasi_state(handle, );
>> +
>> +/*
>> + * If the memory transfer is already complete and the migration
>> + * has been cleaned up by the hypervisor, H_PARAMETER is return,
>> + * which is translate in EINVAL by poll_vasi_state().
>> + */
>> +if (ret == -EINVAL || (!ret && state == H_VASI_COMPLETED)) {
>> +pr_info("memory transfert completed.\n");
>> +break;
>> +}
>> +
>> +if (ret) {
>> +pr_err("H_VASI_STATE return error (%d)\n", ret);
>> +break;
>> +}
>> +
>> +if (state != H_VASI_RESUMED) {
>> +pr_err("unexpected H_VASI_STATE result %lu\n", state);
>> +break;
>> +}
>> +
>> +msleep(500);
> 
> Is 500 specified anywhere? Another caller uses 1000, and the other one 
> uses some backoff interval starting at 1ms...

This is a bit empiric, the idea is to wait for the overall memory transfer
to be done. There is no real need to interact immediately after the
operation is terminated, so I pick that value to not make too many Hcalls
just for that. From the test I did, that seems to be a reasonable choice.

> 
>> +}
>> +}
>> +
>>  static void prod_single(unsigned int target_cpu)
>>  {
>>  long hvrc;
>> @@ -673,9 +710,10 @@ static int pseries_migrate_partition(u64 handle)
>>  vas_migration_handler(VAS_SUSPEND);
>>  
>>  ret = pseries_suspend(handle);
>> -if (ret == 0)
>> +if (ret == 0) {
>>  post_mobility_fixup();
>> -else
>> +wait_for_vasi_session_completed(handle);
> 
> If this wasn't required until later patches, maybe a comment about why 
> it's here? Could call it wait_for_migration() or similar too.
> 
> Looks okay though from my basic reading of PAPR.
> 
> Reviewed-by: Nicholas Piggin 

Thanks Nick for reviewing this series.

> 
>> +} else
>>  pseries_cancel_migration(handle, ret);
>>  
>>  vas_migration_handler(VAS_RESUME);
>> -- 
>> 2.36.1
>>
>>



Re: [PATCH v3 0/4] Extending NMI watchdog during LPM

2022-07-12 Thread Laurent Dufour
Le 12/07/2022 à 03:21, Nicholas Piggin a écrit :
> Excerpts from Laurent Dufour's message of June 27, 2022 11:53 pm:
>> When a partition is transferred, once it arrives at the destination node,
>> the partition is active but much of its memory must be transferred from the
>> start node.
>>
>> It depends on the activity in the partition, but the more CPU the partition
>> has, the more memory to be transferred is likely to be. This causes latency
>> when accessing pages that need to be transferred, and often, for large
>> partitions, it triggers the NMI watchdog.
> 
> Importantly, it can require page in of code that runs with irqs 
> disabled, which is unlike a guest normally runs under PowerVM
> (but it can under KVM) which is why we enabled the watchdog under
> PowerVM but not KVM. So, okay it makes sense to mak an exception
> for this case.

On PowerVM, irqs disabled code may trigger multiple page in of data, which
is generating latencies too. Furthermore, the hypervisor is currently not
prioritizing page in operation based on the faulting CPU state. So the
kernel may have to wait for user page in operations to last.

> Thanks,
> Nick
> 
>> The NMI watchdog causes the CPU stack to dump where it appears to be
>> stuck. In this case, it does not bring much information since it can happen
>> during any memory access of the kernel.
>>
>> In addition, the NMI interrupt mechanism is not secure and can generate a
>> dump system in the event that the interruption is taken while MSR[RI]=0.
>>
>> Depending on the LPAR size and load, it may be interesting to extend the
>> NMI watchdog timer during the LPM.
>>
>> That's configurable through sysctl with the new introduced variable
>> (specific to powerpc) nmi_watchdog_factor. This value represents the
>> percentage added to watchdog_tresh to set the NMI watchdog timeout during a
>> LPM.
>>
>> Changes in v3:
>>  - don't export watchdog_mutex
>>  - fix a comment in mobilty.c, wait_for_vasi_session_completed()
>>  - fix a build issue when !CONFIG_PPC_WATCHDOG
>>  - rework some printk and rename the sysctl variable.
>>
>> v2:
>> https://lore.kernel.org/all/20220614135414.37746-1-lduf...@linux.ibm.com/
>>
>> Laurent Dufour (4):
>>   powerpc/mobility: wait for memory transfer to complete
>>   watchdog: export lockup_detector_reconfigure
>>   powerpc/watchdog: introduce a NMI watchdog's factor
>>   pseries/mobility: set NMI watchdog factor during LPM
>>
>>  Documentation/admin-guide/sysctl/kernel.rst | 12 +++
>>  arch/powerpc/include/asm/nmi.h  |  2 +
>>  arch/powerpc/kernel/watchdog.c  | 21 -
>>  arch/powerpc/platforms/pseries/mobility.c   | 85 -
>>  include/linux/nmi.h |  2 +
>>  kernel/watchdog.c   | 21 +++--
>>  6 files changed, 135 insertions(+), 8 deletions(-)
>>
>> -- 
>> 2.36.1
>>
>>



Re: [PATCH] powerpc: e500: Fix compilation with gcc e500 compiler

2022-07-12 Thread Christophe Leroy


Le 11/07/2022 à 23:48, Segher Boessenkool a écrit :
> Hi!
> 
> On Mon, Jul 11, 2022 at 05:32:09PM +, Christophe Leroy wrote:
>> Le 11/07/2022 à 18:14, Segher Boessenkool a écrit :
  CC  arch/powerpc/kernel/irq.o
 {standard input}: Assembler messages:
 {standard input}:3535: Error: unrecognized opcode: `wrteei'
 {standard input}:5608: Error: unrecognized opcode: `wrteei'
>>>
>>> What -mcpu= did it use here?
>>
>> -mcpu=powerpc64
>>
>>> wrteei is not a PowerPC insn (it is BookE, instead), so it is not
>>> recognised without an appropriate -mcpu=.
>>>
 If I select the e5500 (without altivec) or e6500 I get:

  CC  arch/powerpc/kernel/io.o
 {standard input}: Assembler messages:
 {standard input}:381: Error: unrecognized opcode: `eieio'
>>>
>>> Same question.  eieio is a base PowerPC instruction, so this one is
>>> "interesting" :-)
>>
>> -mcpu=e500mc64 (for e5500)
>> -mcpu=e6500 (for e6500)
>>
>> I had to replace 'eieio' instruction by 'mbar' instruction.
> 
> I saw some patches fly by...  you have it all fixed with that?

Yes it fixed all build failures with GCC 12.


> 
>> Seems like binutils added 'eieio' to e500 in 2010 via commit
>> e01d869a3be, but it seems it is only for the 85xx, not for the others.
> 
> I believe the eieio instruction is disabled on some e500 models, because
> it does not work correctly, so EIEIO_EN=1 cannot work, something like
> that?

Don't know.

It is also disabled on 405 and 440.

That's new with GCC 12.

Christophe

Re: [PATCH v2 3/4] powerpc: Remove asm/prom.h from asm/mpc52xx.h and asm/pci.h

2022-07-12 Thread Yujie Liu

Hi Christophe,

Thanks for your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on mkp-scsi/for-next jejb-scsi/for-next linus/master 
v5.19-rc5 next-20220707]
[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#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Christophe-Leroy/video-fbdev-offb-Include-missing-linux-platform_device-h/20220707-222906
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-randconfig-s032-20220707 
(https://download.01.org/0day-ci/archive/20220708/202207080257.3ftiq7ck-...@intel.com/config)
compiler: powerpc-linux-gcc (GCC) 11.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.4-39-gce1a6720-dirty
# 
https://github.com/intel-lab-lkp/linux/commit/0e553b9abdcfd7c1f63b072e9d9280ce759c0c3c
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Christophe-Leroy/video-fbdev-offb-Include-missing-linux-platform_device-h/20220707-222906
git checkout 0e553b9abdcfd7c1f63b072e9d9280ce759c0c3c
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross C=1 
CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=powerpc 
SHELL=/bin/bash arch/powerpc/kernel/

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

All warnings (new ones prefixed by >>):

>> arch/powerpc/kernel/prom.c:891:5: warning: no previous prototype for 
'of_get_ibm_chip_id' [-Wmissing-prototypes]
 891 | int of_get_ibm_chip_id(struct device_node *np)
 | ^~


vim +/of_get_ibm_chip_id +891 arch/powerpc/kernel/prom.c

b27652dd2174df1 Kevin Hao  2013-12-24  871
9b6b563c0d2d25e Paul Mackerras 2005-10-06  872  /***
9b6b563c0d2d25e Paul Mackerras 2005-10-06  873   *
9b6b563c0d2d25e Paul Mackerras 2005-10-06  874   * New implementation of the OF 
"find" APIs, return a refcounted
9b6b563c0d2d25e Paul Mackerras 2005-10-06  875   * object, call 
of_node_put() when done.  The device tree and list
9b6b563c0d2d25e Paul Mackerras 2005-10-06  876   * are protected by a 
rw_lock.
9b6b563c0d2d25e Paul Mackerras 2005-10-06  877   *
9b6b563c0d2d25e Paul Mackerras 2005-10-06  878   * Note that property 
management will need some locking as well,
9b6b563c0d2d25e Paul Mackerras 2005-10-06  879   * this isn't dealt 
with yet.
9b6b563c0d2d25e Paul Mackerras 2005-10-06  880   *
9b6b563c0d2d25e Paul Mackerras 2005-10-06  881   ***/
9b6b563c0d2d25e Paul Mackerras 2005-10-06  882
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  883  /**
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  884   * of_get_ibm_chip_id - Returns 
the IBM "chip-id" of a device
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  885   * @np: device node of 
the device
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  886   *
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  887   * This looks for a property 
"ibm,chip-id" in the node or any
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  888   * of its parents and 
returns its content, or -1 if it cannot
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  889   * be found.
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  890   */
b37193b71846858 Benjamin Herrenschmidt 2013-07-15 @891  int 
of_get_ibm_chip_id(struct device_node *np)
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  892  {
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  893  of_node_get(np);
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  894  while (np) {
1856f50c66dff0a Christophe Jaillet 2015-10-16  895  u32 
chip_id;
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  896
1856f50c66dff0a Christophe Jaillet 2015-10-16  897  /*
1856f50c66dff0a Christophe Jaillet 2015-10-16  898   * 
Skiboot may produce memory nodes that contain more than one
1856f50c66dff0a Christophe Jaillet 2015-10-16  899   * cell 
in chip-id, we only read the first one here.
1856f50c66dff0a Christophe Jaillet 2015-10-16  900   */
1856f50c66dff0a Christophe Jaillet 2015-10-16  901  if 
(!of_property_read_u32(np, "ibm,chip-id", _id)) {
b37193b71846858 Benjamin Herrenschmidt 2013-07-15  902  
of_node_put(np);
1856f50c66dff0a Christophe Jaillet 2015-10-16  903  
return chip_id;
b37193b71846858 Benjamin